// In the name of God #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef long double ld; typedef complex point; typedef pair pii; const int maxn = 501; const ll mod = 1234567; class Int { public: vector v; Int() { v.resize(0); } inline void MakeGood(){ for(int i=0;i= 10){ v.push_back(v.back() / 10); v[v.size() - 2] %= 10; } } }; Int dp[maxn][maxn]; ll n = 500; ll a[maxn][maxn]; inline bool operator < (Int fi,Int se) { if(fi.v.size() != se.v.size() ) return fi.v.size() < se.v.size(); for(int i=fi.v.size()-1;i>=0;--i) if(fi.v[i] != se.v[i]) return fi.v[i] < se.v[i]; return false; } inline Int operator + (Int fi,ll se) { if(fi.v.size() == 0) fi.v.push_back(se); else fi.v[0] += se; fi.MakeGood(); return fi; } inline Int operator * (Int fi,ll se) { for(int i=0;i> a[i][j]; dp[n][n].v.push_back(a[n][n]); dp[n][n].MakeGood(); for(int i=n;i>=1;--i) for(int j=n;j>=1;--j){ dp[i - 1][j] = max(dp[i - 1][j],dp[i][j] * (a[i - 1][j] == 14 ? 2 : 1) + a[i - 1][j]); dp[i][j - 1] = max(dp[i][j - 1],dp[i][j] * (a[i][j - 1] == 14 ? 2 : 1) + a[i][j - 1]); } ll ret = 0; for(int i=dp[1][1].v.size()-1;i>=0;--i) ret = (ret * 10 + dp[1][1].v[i]) % mod; cout << ret << endl; return 0; }