Dataset Viewer
Auto-converted to Parquet Duplicate
id
large_stringlengths
3
7
incorrect_codes
large listlengths
1
223
correct_code
large_stringlengths
145
21.3k
description
large_stringlengths
383
5.06k
checker
large_stringlengths
484
11.5k
test_cases
large listlengths
9
117
hack_url
large_stringlengths
92
96
validator
large_stringlengths
187
3.31k
time_limit
int64
500
9k
memory_limit
int64
64
1.02k
629_C
[ "#include <bits/stdc++.h>\nusing namespace std;\nint m, n, k, bag, q;\nlong long dp[2100][2100];\nchar s[200000];\nconst int p = 1000000007;\nint main() {\n cin >> m >> n;\n k = m - n;\n cin >> s;\n bag = q = 0;\n for (int i = 0; i < n; i++) {\n if (s[i] == '(')\n bag++;\n else\n bag--;\n if (bag < q) q = bag;\n }\n dp[0][0] = 1;\n for (int i = 1; i <= m - n; i++)\n for (int j = 0; j <= m - n; j++)\n if (j == 0)\n dp[i][j] = (dp[i - 1][j + 1]) % p;\n else\n dp[i][j] = (dp[i - 1][j + 1] + dp[i - 1][j - 1]) % p;\n long long ans = 0;\n for (int i = -q; i <= m - n; i++)\n for (int l = 0; l <= m - n; l++)\n ans = (ans + dp[l][i] * dp[m - n - l][i + bag]) % p;\n cout << ans << endl;\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int N = 2020;\nconst int Mod = 1e9 + 7;\nvoid add_self(int& x, int y) {\n if ((x += y) >= Mod) x -= Mod;\n}\nint n, m;\nstring s;\nint Dp[N][N][2];\nint ExtraL, ExtraR;\nint Rec(int k = n - m, int Open = 0, bool Taken = false) {\n if (k < 0) return 0;\n if (Open < 0) return 0;\n if (Open > k) return 0;\n if (!k && Taken) return !Open;\n if (Dp[k][Open][Taken] + 1) return Dp[k][Open][Taken];\n int Res = 0;\n add_self(Res, Rec(k - 1, Open + 1, Taken));\n add_self(Res, Rec(k - 1, Open - 1, Taken));\n if (!Taken && Open >= ExtraR)\n add_self(Res, Rec(k, Open - ExtraR + ExtraL, true));\n return Dp[k][Open][Taken] = Res;\n}\nint main() {\n cin >> n >> m >> s;\n for (char c : s) {\n if (c == '(')\n ExtraL++;\n else if (ExtraL)\n ExtraL--;\n else\n ExtraR++;\n }\n memset(Dp, -1, sizeof(Dp));\n cout << Rec() << endl;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nlong long dp[2220][2220];\nlong long mo = 1e9 + 7;\nint main() {\n long long n, m;\n dp[1][1] = 1;\n dp[0][0] = 1;\n for (long long a = 2; a <= 2000; a++) {\n for (long long b = 0; b <= a; b++) {\n if (b == 0) {\n dp[a][b] = dp[a - 1][b + 1] % mo;\n continue;\n }\n dp[a][b] = (dp[a - 1][b - 1] + dp[a - 1][b + 1]) % mo;\n }\n }\n cin >> n >> m;\n string q;\n cin >> q;\n long long jsd = 0;\n long long xx = 0;\n for (long long a = 0; a < q.size(); a++) {\n if (q[a] == '(')\n jsd++;\n else\n jsd--;\n xx = min(jsd, xx);\n }\n long long js = 0;\n for (long long a = 0; a <= n - m; a++) {\n for (long long b = 0; b <= a; b++) {\n if (xx + b >= 0) {\n js = (js + dp[a][b] * dp[n - m - a][jsd + b]) % mo;\n }\n }\n }\n cout << js;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint inf_int = 2e9;\nlong long inf_ll = 2e18;\nconst double pi = 3.1415926535898;\ntemplate <typename T, typename T1>\nvoid prin(vector<pair<T, T1> >& a) {\n for (int i = 0; i < a.size(); i++) {\n cout << a[i].first << \" \" << a[i].second << \"\\n\";\n }\n}\ntemplate <typename T>\nvoid prin(vector<T>& a) {\n for (int i = 0; i < a.size(); i++) {\n cout << a[i];\n if (i < a.size() - 1)\n cout << \" \";\n else\n cout << \"\\n\";\n }\n}\ntemplate <typename T>\nvoid prin_new_line(vector<T>& a) {\n for (int i = 0; i < a.size(); i++) {\n cout << a[i] << \"\\n\";\n }\n}\ntemplate <typename T, typename T1>\nvoid prin_new_line(vector<pair<T, T1> >& a) {\n for (int i = 0; i < a.size(); i++) {\n cout << a[i].first << \" \" << a[i].second << \"\\n\";\n }\n}\nint sum_vec(vector<int>& a) {\n int s = 0;\n for (int i = 0; i < a.size(); i++) {\n s += a[i];\n }\n return s;\n}\ntemplate <typename T>\nT max(vector<T>& a) {\n T ans = a[0];\n for (int i = 1; i < a.size(); i++) {\n ans = max(ans, a[i]);\n }\n return ans;\n}\ntemplate <typename T>\nT min(vector<T>& a) {\n T ans = a[0];\n for (int i = 1; i < a.size(); i++) {\n ans = min(ans, a[i]);\n }\n return ans;\n}\ntemplate <typename T>\nT min(T a, T b, T c) {\n return min(a, min(b, c));\n}\ntemplate <typename T>\nT max(T a, T b, T c) {\n return max(a, max(b, c));\n}\ndouble s_triangle(double x1, double y1, double x2, double y2, double x3,\n double y3) {\n return abs(((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) / 2);\n}\nbool overflow(long long a, long long b) {\n if (a * b / b != a) return true;\n return false;\n}\nbool debug = 0;\nconst int maxn = 1e5 + 200;\nlong long mod = 1e9 + 7;\nlong long dp[4003][4003];\nvoid solve() {\n int m, n;\n cin >> m >> n;\n string a;\n cin >> a;\n int mn = 0;\n int cur = 0;\n for (int i = 0; i < a.size(); i++) {\n if (a[i] == '(') {\n cur++;\n } else {\n cur--;\n }\n mn = min(mn, cur);\n }\n dp[0][0] = 1;\n dp[1][1] = 1;\n for (int i = 2; i <= 3000; i++) {\n for (int e = 0; e <= 3000; e++) {\n dp[i][e] = dp[i - 1][e + 1];\n if (e) {\n dp[i][e] += dp[i - 1][e - 1];\n }\n dp[i][e] = dp[i][e] % mod;\n }\n }\n long long ans = 0;\n for (int i = 0; i <= m - n; i++) {\n for (int e = abs(mn); e <= m - n; e++) {\n long long x = dp[i][e];\n int b = e + cur;\n int len = m - n - i;\n if (e + cur >= 0) {\n x = (x * dp[len][e + cur]) % mod;\n ans = (ans + x) % mod;\n }\n }\n }\n if (debug) cout << endl;\n cout << ans;\n}\nint main() {\n if (!debug) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n }\n int t = 1;\n while (t--) solve();\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst long long INF = 2e9;\nconst int maxn = 1e5 + 100;\nconst long long mod = 1e9 + 7;\nconst int go = 3000 + 100;\nlong long dp[go][go];\nint main() {\n int n, m;\n string s;\n cin >> n >> m >> s;\n for (int i = 0; i < go; i++) dp[i][i] = 1;\n for (int i = 1; i < go; i++) {\n dp[i][0] = dp[i - 1][1];\n for (int j = 1; j < i; j++)\n dp[i][j] = (dp[i - 1][j + 1] + dp[i - 1][j - 1]) % mod;\n }\n long long f = 0, mx = -INF, mn = +INF;\n for (int i = 0; i < m; i++) {\n if (s[i] == '(')\n f++;\n else\n f--;\n mn = min(mn, f);\n mx = max(mx, f);\n }\n if (f < 0) f = -f, mn = mx;\n long long ans = 0;\n for (int i = 0; i <= n - m; i++) {\n for (int j = i; j + mn >= 0 && j >= 0; j--) {\n ans += (dp[i][j] * dp[n - m - i][f + j]);\n ans %= mod;\n }\n }\n cout << ans;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint n, m;\nchar s[100100];\nint x, y, mn;\nlong long dp[2010][2010];\nvoid init() {\n scanf(\"%d%d\", &n, &m);\n scanf(\"%s\", s);\n memset(dp, 0, sizeof(dp));\n dp[0][0] = 1;\n for (int i = 1; i <= n - m; i++) {\n for (int j = (i + 1) / 2; j <= i; j++) {\n dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];\n dp[i][j] %= 1000000007;\n }\n }\n}\nbool judge() {\n x = y = mn = 0;\n for (int i = 0; i < m; i++) {\n if (s[i] == '(')\n x++;\n else\n y++;\n mn = min(mn, x - y);\n }\n if (x > n / 2 || y > n / 2) return true;\n return false;\n}\nvoid solve() {\n long long ans = 0;\n for (int i = 0; i <= n - m; i++) {\n for (int j = max(-mn + (i + mn + 1) / 2, (i + 1) / 2);\n j <= i && j <= n / 2 - x; j++) {\n ans += dp[i][j] * dp[n - m - i][n / 2 - y - i + j];\n ans %= 1000000007;\n }\n }\n printf(\"%lld\\n\", ans);\n}\nint main() {\n init();\n if (judge())\n printf(\"0\\n\");\n else\n solve();\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int INF = 0x3f3f3f3f;\nconst double eps = 0.0000000001;\nconst int N = 2000 + 10;\nconst double PI = acos(-1.0);\nconst long long mod = 1e9 + 7;\nlong long dp[N][N];\nvoid init(int x) {\n dp[0][0] = 1;\n for (int i = 1; i <= x; i++) {\n dp[i][0] = dp[i - 1][1];\n for (int j = 1; j <= x; j++) {\n dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j + 1]) % mod;\n }\n }\n}\nchar str[N];\nint main() {\n int n, m;\n scanf(\"%d%d\", &n, &m);\n scanf(\"%s\", str);\n int k = n - m;\n init(k);\n int t1 = 0;\n int t2 = 0;\n int t = -INF;\n int flag = 0;\n for (int i = 0; i < m; i++) {\n if (str[i] == '(')\n t1++;\n else {\n t2++;\n }\n t = max(t, t2 - t1);\n }\n t1 = t1 - t2;\n long long ans = 0;\n for (int i = 0; i <= k; i++) {\n for (int j = max(0, t); j <= k; j++) {\n int kk = j + t1;\n if (kk <= k) {\n ans = ans + (dp[i][j] * dp[k - i][kk]) % mod;\n ans = ans % mod;\n }\n }\n }\n cout << ans << endl;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nchar s[100005];\nint dp[2005][2005];\nvoid upd(int &x, int y) {\n x += y;\n if (x >= 1000000007) x -= 1000000007;\n}\nvoid input() {\n int len, nm;\n int i, j;\n scanf(\"%d %d\", &len, &nm);\n scanf(\"%s\", &s);\n int lmax = len - nm;\n int mo = 0, dong = 0, xmin = 1001001001;\n for ((i) = 0; (i) < (nm); (i)++) {\n if (s[i] == '(')\n mo++;\n else\n dong++;\n xmin = ((xmin) < (mo - dong) ? (xmin) : (mo - dong));\n }\n if (xmin < -lmax) {\n printf(\"0\");\n return;\n }\n int chenh = mo - dong;\n dp[0][0] = 1;\n for ((i) = (0); (i) <= (lmax); (i)++)\n for ((j) = (0); (j) <= (lmax); (j)++)\n if (dp[i][j]) {\n upd(dp[i + 1][j + 1], dp[i][j]);\n if (j >= 1) upd(dp[i + 1][j - 1], dp[i][j]);\n }\n long long res = 0;\n for ((i) = (0); (i) <= (lmax); (i)++)\n for (j = ((0) > (-xmin) ? (0) : (-xmin)); j + chenh <= lmax; j++)\n if (j + chenh >= 0) {\n long long temp =\n ((long long)dp[i][j] * (long long)dp[lmax - i][j + chenh]) %\n 1000000007;\n res = (res + temp) % 1000000007;\n }\n printf(\"%I64d\", res);\n}\nint main() {\n input();\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst long long MOD = 1e9 + 7;\nlong long cat[2001][2001] = {0};\nlong long catalan(int l, int d) {\n if (l < 0 || d < 0 || (l + d) % 2 != 0 || d > l) return 0;\n if (cat[l][d] == 0) {\n cat[l][d] = catalan(l - 1, d + 1);\n if (d > 0) cat[l][d] += catalan(l - 1, d - 1);\n cat[l][d] = cat[l][d] % MOD;\n }\n return cat[l][d];\n}\nint end(string str) {\n int e = 0;\n for (int i = 0; i < str.size(); i++) {\n if (str[i] == '(')\n e++;\n else\n e--;\n }\n return e;\n}\nint hi(string str) {\n int e = 0, mx = 0;\n for (int i = 0; i < str.size(); i++) {\n if (str[i] == '(')\n e++;\n else\n e--;\n if (e > mx) mx = e;\n }\n return mx;\n}\nint lo(string str) {\n int e = 0, mi = 0;\n for (int i = 0; i < str.size(); i++) {\n if (str[i] == '(')\n e++;\n else\n e--;\n if (e < mi) mi = e;\n }\n return mi;\n}\nstring s;\nint main() {\n cat[0][0] = 1;\n int n, m;\n cin >> n >> m >> s;\n int e = end(s);\n int low;\n if (e < 0)\n low = hi(s);\n else\n low = lo(s);\n int tot = 0;\n for (int lp = 0; lp <= n - m; lp++) {\n int lq = n - m - lp;\n for (int ep = -low; ep <= lp; ep++) {\n tot = (tot + (catalan(lp, ep) * catalan(lq, ep + e)) % MOD) % MOD;\n }\n }\n cout << tot << endl;\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int N = 2e3 + 1;\nconst int MOD = 1e9 + 7;\nlong long dp[N][N];\nvoid solve(int i) {\n if (i == N) return;\n if (i > 1) {\n for (int j = 0; j <= i; j++) {\n dp[i][j] = 0;\n if (j) dp[i][j] += (dp[i - 1][j - 1]) % MOD;\n if (j < N - 1) dp[i][j] += (dp[i - 1][j + 1]) % MOD;\n dp[i][j] %= MOD;\n }\n }\n solve(i + 1);\n}\nint main() {\n memset(dp, 0, sizeof(dp));\n dp[0][0] = 1;\n dp[1][1] = 1;\n int n, m;\n cin >> n >> m;\n string str;\n cin >> str;\n solve(1);\n int CT = 0;\n int minCT = 100000;\n for (int i = 0; i < str.size(); ++i) {\n if (str[i] == '(')\n CT++;\n else\n CT--;\n minCT = min(minCT, CT);\n }\n if (abs(CT) > n - m)\n cout << \"0\\n\";\n else {\n long long ans = 0;\n int ct = abs(CT);\n for (int i = 0; i <= n - m; ++i) {\n for (int j = 0; CT + j < N; ++j) {\n if (minCT + j >= 0) ans += (dp[i][j] * dp[n - m - i][CT + j]) % MOD;\n ans %= MOD;\n }\n }\n cout << ans << endl;\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int N = 2e3 + 1;\nconst int MOD = 1e9 + 7;\nlong long dp[N][N];\nvoid solve(int i) {\n if (i == N) return;\n if (i > 1) {\n for (int j = 0; j <= i; j++) {\n dp[i][j] = 0;\n if (j) dp[i][j] = (dp[i - 1][j - 1]) % MOD;\n if (j < i) dp[i][j] += (dp[i - 1][j + 1]) % MOD;\n dp[i][j] %= MOD;\n }\n }\n solve(i + 1);\n}\nint main() {\n memset(dp, 0, sizeof(dp));\n dp[0][0] = 1;\n dp[1][1] = 1;\n int n, m;\n cin >> n >> m;\n string str;\n cin >> str;\n solve(1);\n int CT = 0;\n int minCT = 10000;\n for (int i = 0; i < str.size(); ++i) {\n if (str[i] == '(')\n CT++;\n else\n CT--;\n minCT = min(minCT, CT);\n }\n if (abs(CT) > n - m)\n cout << \"0\\n\";\n else {\n long long ans = 0;\n int ct = abs(CT);\n for (int i = 0; i <= n - m; ++i) {\n for (int j = max(0, -minCT); CT + j < N; ++j) {\n if (CT + j >= 0) ans += (dp[i][j] * dp[n - m - i][CT + j]) % MOD;\n ans %= MOD;\n }\n }\n cout << ans << endl;\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int N = 2e3 + 10, MOD = 1e9 + 7;\nstring s;\nint dp[N][N];\nint n, m, mn, res, ans;\ninline int sum(int a, int b) {\n a += b;\n if (a >= MOD) a -= MOD;\n return a;\n}\ninline int mul(int a, int b) { return (1LL * a * b) % MOD; }\nint main() {\n cin >> n >> m >> s;\n for (int i = 0; i < m; i++) {\n (s[i] == '(' ? res++ : res--);\n mn = min(mn, res);\n }\n dp[0][0] = 1;\n for (int i = 1; i <= n - m; i++) {\n dp[i][0] = dp[i - 1][1];\n for (int j = 1; j <= i; j++)\n dp[i][j] = sum(dp[i - 1][j - 1], dp[i - 1][j + 1]);\n }\n for (int i = 0; i <= n - m; i++)\n for (int j = 0; j <= i; j++)\n if (j + mn >= 0) ans = sum(ans, mul(dp[i][j], dp[n - m - i][j + res]));\n return cout << ans, 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int mod = int(1e9) + 7;\nlong long dp[5100][5100];\nchar s[100500];\nint main() {\n int n, m;\n gets(s);\n sscanf(s, \"%d%d\", &n, &m);\n gets(s);\n int a = 0;\n int b = 0;\n for (int i = 0; i < m; i++) {\n if (s[i] == '(')\n b++;\n else\n b--;\n if (b < 0) {\n a -= b;\n b = 0;\n }\n }\n dp[0][0] = 1;\n for (int i = 1; i <= n - m; i++) {\n dp[i][0] = dp[i - 1][1];\n for (int j = 0; j <= i; j++)\n dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j + 1]) % mod;\n }\n long long res = 0;\n for (int x = 0; x <= n - m; x++)\n for (int j = a; j <= n - m; j++) {\n int y = n - m - x;\n int z = j - a + b;\n long long t = dp[x][j];\n t *= dp[y][z];\n t %= mod;\n res = (res + t) % mod;\n }\n cout << res << endl;\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nlong long int o = 0, c = 0, newLength, minAllowed;\nlong long int dp[2005][2005][2];\nbool check(long long int open, long long int close) { return open >= close; }\nlong long int solve(long long int idx, long long int openBraces,\n long long int ok) {\n long long int openNow = o * ok, closedNow = c * ok;\n openNow += openBraces;\n closedNow += (idx - openBraces);\n if (!check(openNow, closedNow)) return 0;\n if (idx == newLength) {\n if (ok == 0) {\n openNow += o, closedNow += c;\n return openNow == closedNow && openNow - closedNow >= minAllowed;\n }\n return openNow == closedNow;\n }\n if (dp[idx][openBraces][ok] != -1LL) return dp[idx][openBraces][ok];\n long long int count = 0;\n if (check(openNow, closedNow + 1))\n count = solve(idx + 1, openBraces, ok) % 1000000007;\n if (check(openNow + 1, closedNow))\n count = (count + solve(idx + 1, openBraces + 1, ok)) % 1000000007;\n if (ok == 0) {\n if (check(openNow, closedNow) && openNow - closedNow >= minAllowed)\n count = (count + solve(idx, openBraces, 1)) % 1000000007;\n }\n return dp[idx][openBraces][ok] = count;\n}\nint main(void) {\n long long int desiredLength, length, i, flag = 1;\n string str;\n cin >> desiredLength >> length;\n newLength = desiredLength - length;\n cin >> str;\n memset(dp, -1LL, sizeof dp);\n for (i = 0; i < str.size(); i++) {\n if (str[i] == '(')\n o++;\n else\n c++;\n if (c > o) flag = 0;\n minAllowed = max(minAllowed, c - o);\n }\n if (newLength == 0) {\n if (flag == 1 && o == c)\n flag = 1;\n else\n flag = 0;\n cout << (flag) << endl;\n return 0;\n }\n cout << (solve(0, 0, 0)) % 1000000007;\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int INF = 0x3f3f3f3f;\nconst double eps = 0.0000000001;\nconst int N = 2000 + 10;\nconst double PI = acos(-1.0);\nconst int mod = 1e9 + 7;\nlong long dp[N][N];\nvoid init(int k) {\n memset(dp, 0, sizeof(dp));\n dp[0][0] = 1;\n for (int i = 1; i <= k; i++) {\n dp[i][0] = dp[i - 1][1];\n for (int j = 1; j <= k; j++)\n dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j + 1]) % mod;\n }\n}\nchar str[N];\nint main() {\n int n, m;\n scanf(\"%d%d\", &n, &m);\n scanf(\"%s\", str);\n int k = n - m;\n init(k);\n int t1 = 0;\n int t2 = 0;\n int t = INF;\n int sum1 = 0, sum2 = 0;\n for (int i = 0; i < m; i++) {\n if (str[i] == '(')\n t1++;\n else {\n t1--;\n }\n t = min(t1, t);\n }\n long long ans = 0;\n for (int i = 0; i <= k; i++) {\n for (int j = 0; j <= k; j++) {\n if (j + t < 0) continue;\n int kk = j + t1;\n ans = ans + (1ll * dp[i][j] * dp[k - i][kk]) % mod;\n ans = ans % mod;\n }\n }\n printf(\"%lld\\n\", ans);\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int N = 3e3 + 5;\nconst long long mod = 1e9 + 7;\nlong long dp[N][N];\nchar s[100000 + 5];\nint main() {\n int m, n;\n scanf(\"%d%d%s\", &n, &m, s + 1);\n dp[0][0] = 1;\n for (int i = 1; i <= n - m; ++i) {\n for (int j = 0; j <= i; ++j) {\n if (!j)\n dp[i][j] = dp[i - 1][j + 1];\n else\n dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j + 1]) % mod;\n }\n }\n int cnt = 0, res = m + 1;\n for (int i = 1; i <= m; ++i) {\n if (s[i] == '(')\n ++cnt;\n else\n --cnt;\n res = min(res, cnt);\n }\n long long ans = 0;\n for (int i = 0; i <= n - m; ++i) {\n for (int j = 0; j <= i; ++j) {\n if (-res <= j) ans = (ans + dp[i][j] * dp[n - m - i][cnt + j]) % mod;\n }\n }\n printf(\"%I64d\\n\", ans);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int MAXN = 5010;\nconst int mod = 1e9 + 7;\nconst int INF = 0x3f3f3f3f;\nconst double pi = acos(-1.0);\nconst double eps = 1e-4;\nint n, m;\nlong long dp[2100][2100];\nchar s[200010];\nvoid solve() {\n if (n == 100000 && m == 98000) {\n int nn = 0;\n for (int i = 0; i < m; i++)\n if (s[i] == '(') nn++;\n cout << nn << endl;\n }\n if (n & 1) {\n puts(\"0\");\n return;\n }\n int cnt = 0, flag = 0;\n int tmp = 0;\n for (int i = 0; i < m; i++) {\n if (s[i] == '(')\n cnt++;\n else\n cnt--;\n tmp = max(tmp, -cnt);\n if (cnt < 0) flag = 1;\n }\n int mx = 0;\n int cnt1 = 0;\n for (int i = m - 1; i >= 0; i--) {\n if (s[i] == '(')\n cnt1++;\n else\n cnt1--;\n mx = max(mx, cnt1);\n }\n if (n == m && flag) {\n puts(\"0\");\n return;\n }\n long long ans = 0;\n for (int i = tmp; i <= n - m; i++) {\n for (int j = tmp; j <= i; j++) {\n if (tmp + cnt < mx || tmp + cnt < 0) continue;\n ans += (dp[i][j] * dp[n - m - i][tmp + cnt]) % mod;\n ans %= mod;\n }\n }\n cout << ans << endl;\n}\nint main() {\n memset(dp, 0, sizeof dp);\n dp[0][0] = 1;\n for (int i = 1; i <= 2000; i++) {\n for (int j = 0; j <= i; j++) {\n if (j > 0) dp[i][j] += dp[i - 1][j - 1];\n dp[i][j] %= mod;\n if (j != i) dp[i][j] += dp[i - 1][j + 1];\n dp[i][j] %= mod;\n }\n }\n cin >> n >> m;\n cin >> s;\n solve();\n return 0;\n}\n", "#include<bits/stdc++.h>\nusing namespace std;\n#define int long long\n#define vi vector<int>\n#define pb push_back\n#define pi pair<int, int>\n#define f first\n#define s second\n#define rep(i,a,b) for(int i=a;i<=b;i++)\n\nconst int M = 1e9+7;\nconst int N = 2e3+7;\nint dp1[N][N], dp2[N][N];\n\n\nmain()\n{\n\tdp1[0][0]=1;\n\trep(i,1,N-1){\n\t\trep(j,0,N-1){\n\t\t\tif (j!=0) dp1[i][j] = dp1[i-1][j-1] + dp1[i-1][j+1];\n\t\t\telse dp1[i][j] = dp1[i-1][j+1];\n\t\t\tdp1[i][j]%=M;\n\t\t}\n\t}\n\n\trep(i,0,N-1) dp2[0][i]=1;\n\tdp2[1][0]=1;\n\trep(i,2,N-1) dp2[i][0]=0;\n\trep(i,1,N-1){\n\t\trep(j,1,N-1){\n\t\t\tif (i-j>=2) continue;\n\t\t\tif (i-j>-1) dp2[i][j] = dp2[i-1][j];\n\t\t\telse dp2[i][j] = dp2[i-1][j] + dp2[i][j-1];\n\t\t\tdp2[i][j]%=M;\n\t\t\t// s>=(i-j)\n\t\t}\n\t}\n\n\tint n,m;cin>>n>>m;\n\tint x=0,mx=0;\n\trep(i,0,m-1){\n\t\tchar c;cin>>c;\n\t\tif(c=='(') x++;\n\t\telse x--;\n\t\tmx = min(x,mx);\n\t}\n\tint res=0;\n\tfor(int i=0;i<=(n-m);i++){\n\t\tfor(int d=-1*mx;d<=i;d++){\n\t\t\t// cout<<d<<i<<endl;\n\t\t\tif ((d+i)%2!=0) continue;\n\t\t\tint lo=(d+i)/2;\n\t\t\tint lc=(i-d)/2;\n\t\t\tint j = (n-m)-i;\n\t\t\tint d2 = -(d+x);\n\t\t\tif ((d2+j)%2!=0) continue;\n\t\t\tif (j<abs(d2)) continue;\n\t\t\tint ro= (j-(d+x))/2;\n\t\t\tint rc= (j+(d+x))/2;\n\t\t\tif (ro<0 or rc<0) continue;\n\t\t\t// if (d+mx)\n\t\t\tif (lo-lc+ro-rc+x!=0) continue;\n\t\t\t// cout<<lo<<lc<<ro<<rc<<endl;\n\t\t\tres+=dp1[i][d]*dp2[ro][rc];\n\t\t\t// cout<<res<<endl;\n\t\t\tres%=M;\n\t\t}\n\t}\n\tcout<<res<<endl;\n}", "#include <bits/stdc++.h>\nusing namespace std;\nconst int mod = 1e9 + 7;\nconst int N = 4005;\nlong long dp[N][N][2] = {0};\nint n, m, a, b, tem;\nlong long ans;\nchar c;\nint main() {\n scanf(\"%d%d\", &n, &m);\n a = b = 0;\n for (int i = 1; i <= m; i++) {\n scanf(\" %c\", &c);\n if (c == '(')\n a++;\n else if (a)\n a--;\n else\n b++;\n }\n if ((n & 1) || (n - m < a + b)) {\n printf(\"0\\n\");\n return 0;\n }\n memset(dp, 0, sizeof(dp));\n n -= m;\n dp[0][0][0] = 1;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j <= 2 * n; j++) {\n dp[i + 1][j + 1][0] = (dp[i + 1][j + 1][0] + dp[i][j][0]) % mod;\n dp[i + 1][j + 1][1] = (dp[i + 1][j + 1][1] + dp[i][j][1]) % mod;\n if (j > 0) {\n dp[i + 1][j - 1][0] = (dp[i + 1][j - 1][0] + dp[i][j][0]) % mod;\n dp[i + 1][j - 1][1] = (dp[i + 1][j - 1][1] + dp[i][j][1]) % mod;\n }\n if (b <= j) {\n tem = j - b;\n dp[i + 1][tem + a + 1][1] =\n (dp[i + 1][tem + a + 1][1] + dp[i][j][0]) % mod;\n if (tem + a > 0)\n dp[i + 1][tem + a - 1][1] =\n (dp[i + 1][tem + a - 1][1] + dp[i][j][0]) % mod;\n }\n }\n }\n ans = dp[n][0][1];\n if (!a) ans += dp[n][0][0];\n printf(\"%I64d\\n\", ans % mod);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst long long mod = 1000000007;\nint n, m, len;\nchar s[100005];\nlong long f[2005][2005], res;\nint main() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n cin >> n >> m >> s + 1;\n len = n - m;\n int mi = 0, sum = 0;\n for (int i = 1; i <= m; ++i) {\n sum += (s[i] == '(' ? 1 : -1);\n mi = min(mi, sum);\n }\n f[0][0] = 1;\n for (int i = 1; i <= len; ++i) {\n f[i][0] = f[i - 1][1];\n for (int j = 1; j <= len; ++j)\n f[i][j] = (f[i - 1][j - 1] + f[i - 1][j + 1]) % mod;\n }\n for (int j = -mi; j + sum <= len; ++j)\n for (int i = 0; i <= len; ++i) {\n res = (res + f[i][j] * f[len - i][j + sum]) % mod;\n }\n cout << res;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int N = 2e3 + 1;\nconst int MOD = 1e9 + 7;\nlong long dp[N][N];\nvoid solve(int i) {\n if (i == N) return;\n if (i > 1) {\n for (int j = 0; j <= i; j++) {\n dp[i][j] = 0;\n if (j) dp[i][j] = (dp[i - 1][j - 1]) % MOD;\n if (j < i) dp[i][j] += (dp[i - 1][j + 1]) % MOD;\n dp[i][j] %= MOD;\n }\n }\n solve(i + 1);\n}\nint main() {\n memset(dp, 0, sizeof(dp));\n dp[0][0] = 1;\n dp[1][1] = 1;\n int n, m;\n cin >> n >> m;\n string str;\n cin >> str;\n solve(1);\n int CT = 0;\n int minCT = 10000;\n for (int i = 0; i < str.size(); ++i) {\n if (str[i] == '(')\n CT++;\n else\n CT--;\n minCT = min(minCT, CT);\n }\n if (abs(CT) > n - m)\n cout << \"0\\n\";\n else {\n long long ans = 0;\n int ct = abs(CT);\n for (int i = 0; i <= n - m; ++i) {\n for (int j = 0; CT + j < N; ++j) {\n if (minCT + j >= 0) ans += (dp[i][j] * dp[n - m - i][CT + j]) % MOD;\n ans %= MOD;\n }\n }\n cout << ans << endl;\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint balance;\nint minimal;\nint n, m, N;\nchar S[100010];\nint sum(int a, int b) {\n int x = a + b;\n if (x >= 1000000007) x %= 1000000007;\n return x;\n}\nbool mark[3][2010][4010];\nint memo[3][2010][4010];\nint dp(int pos, int bal, int used) {\n if (bal < 0) return 0;\n if (bal > N - pos) return 0;\n if (pos == N) {\n if (!used) {\n if (bal + minimal < 0) return 0;\n bal += balance;\n }\n return bal == 0;\n }\n int& best = memo[used][pos][bal + N];\n if (mark[used][pos][bal + N]) return best;\n mark[used][pos][bal + N] = true;\n best = 0;\n int d1 = dp(pos + 1, bal + 1, used);\n int d2 = dp(pos + 1, bal - 1, used);\n int d3 = 0, d4 = 0;\n if (!used && bal + minimal >= 0) {\n d3 = dp(pos + 1, bal + balance + 1, true);\n d4 = dp(pos + 1, bal + balance - 1, true);\n }\n return best = sum(d1, sum(d2, sum(d3, d4)));\n}\nint main() {\n scanf(\"%d %d\", &n, &m);\n N = n - m;\n scanf(\"%s\", S);\n minimal = 0x3f3f3f3f;\n balance = 0;\n for (int i = 0; i < m; i++) {\n minimal = min(minimal, balance);\n balance += ((S[i] == '(') ? (1) : (-1));\n }\n minimal = min(minimal, balance);\n printf(\"%d\\n\", dp(0, 0, 0));\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int inf = 0x7fffffff;\nvoid io() {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n cout.precision(15);\n}\nlong long mulmod(long long a, long long b, long long m) {\n long long q = (long long)(((long double)a * (long double)b) / (long double)m);\n long long r = a * b - q * m;\n if (r > m) r %= m;\n if (r < 0) r += m;\n return r;\n}\ntemplate <typename T>\nT mod(T a, T b) {\n while (a < 0) a += b;\n return a % b;\n}\ntemplate <typename T>\nT power(T e, T n, T m) {\n T x = 1, p = e;\n while (n) {\n if (n & 1) x = mod(x * p, m);\n p = mod(p * p, m);\n n >>= 1;\n }\n return x;\n}\ntemplate <typename T>\nT power(T e, T n) {\n T x = 1, p = e;\n while (n) {\n if (n & 1) x = x * p;\n p = p * p;\n n >>= 1;\n }\n return x;\n}\ntemplate <typename T>\nT InverseEuler(T a, T m) {\n return (a == 1 ? 1 : power(a, m - 2, m));\n}\ntemplate <typename T>\nT gcd(T a, T b) {\n return (!b) ? a : gcd(b, a % b);\n}\ntemplate <typename T>\nT lcm(T a, T b) {\n return (a * (b / gcd(a, b)));\n}\nint exEuler(int a, int b, int &x, int &y) {\n if (a == 0) {\n x = 0;\n y = 1;\n return b;\n }\n if (b == 0) {\n x = 1;\n y = 0;\n return a;\n }\n int x1, y1;\n int g = exEuler(b % a, a, x1, y1);\n x = y1 - (b / a) * x1;\n y = x1;\n return g;\n}\nlong long z[2002];\nlong long dp[2900][2900];\nstring s;\nlong long tot[2002][2002];\nint main(int argc, char *argv[]) {\n io();\n for (__typeof(2899) i = 0; i <= 2899; ++i) {\n for (__typeof(i) j = 0; j <= i; ++j) {\n if (i == j) {\n dp[i][j] = 1;\n } else if (j == 0) {\n dp[i][j] = (dp[i - 1][1]) % 1000000007ll;\n } else {\n dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j + 1]) % 1000000007ll;\n }\n }\n }\n for (__typeof(2000) i = 0; i <= 2000; ++i) {\n for (__typeof(i) j = 0; j <= i; ++j) {\n if (j == 0) {\n tot[i][j] = dp[i][j];\n } else {\n tot[i][j] = (tot[i][j - 1] + dp[i][j]) % 1000000007ll;\n }\n }\n }\n long long n, m;\n cin >> n >> m;\n cin >> s;\n int need = 0;\n int worst = 0;\n for (__typeof(m - 1) i = 0; i <= m - 1; ++i) {\n if (s[i] == '(')\n need--;\n else\n need++;\n worst = max(worst, need);\n }\n int rem = n - m;\n if (rem < worst) {\n cout << 0 << '\\n';\n return 0;\n }\n long long ans = 0;\n for (int j = worst; j <= rem; j++) {\n for (int i = j; i <= rem; i++) {\n if (j >= need)\n ans = (ans + (dp[i][j] * dp[rem - i][j - need]) % 1000000007ll) %\n 1000000007ll;\n }\n }\n cout << ans << '\\n';\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nlong long dp[2110][2100], mod = 1e9 + 7;\nint shift = 2100;\nvoid solve() {\n dp[0][0] = 1;\n for (int i = 1; i <= 2100; i++) {\n dp[i][0] = dp[i - 1][1];\n for (int j = 1; j <= 2100; j++) {\n dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j + 1]) % mod;\n }\n }\n}\nint main() {\n ios::sync_with_stdio(0);\n int n, m, sz, cnt = 0, lftcnt = 0;\n long long ans = 0;\n cin >> n >> m;\n string inp;\n cin >> inp;\n sz = inp.size();\n inp = \"x\" + inp;\n for (int i = 1; i <= sz; i++) {\n if (inp[i] == '(')\n cnt++;\n else\n cnt--;\n lftcnt = min(lftcnt, cnt);\n }\n solve();\n for (int i = 0; i <= n - m; i++) {\n for (int j = 0; j <= i; j++) {\n if ((j + lftcnt >= 0) && (j + cnt >= 0))\n ans = (ans + (dp[i][j] * dp[n - m - i][j + cnt]) % mod) % mod;\n }\n }\n cout << ans;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int MAXN = 5010;\nconst int mod = 1e9 + 7;\nconst int INF = 0x3f3f3f3f;\nconst double pi = acos(-1.0);\nconst double eps = 1e-4;\nint n, m;\nlong long dp[2100][2100];\nchar s[200010];\nvoid solve() {\n if (n & 1) {\n puts(\"0\");\n return;\n }\n int cnt = 0, flag = 0;\n int tmp = 0;\n for (int i = 0; i < m; i++) {\n if (s[i] == '(')\n cnt++;\n else\n cnt--;\n tmp = max(tmp, -cnt);\n if (cnt < 0) flag = 1;\n }\n int mx = 0;\n int cnt1 = 0;\n for (int i = m - 1; i >= 0; i--) {\n if (s[i] == '(')\n cnt1++;\n else\n cnt1--;\n mx = max(mx, cnt1);\n }\n if (n == m && flag) {\n puts(\"0\");\n return;\n }\n long long ans = 0;\n for (int i = tmp; i <= n - m; i++) {\n for (int j = tmp; j <= i; j++) {\n if (tmp + cnt < mx || tmp + cnt < 0) continue;\n ans += (dp[i][j] * dp[n - m - i][tmp + cnt]) % mod;\n ans %= mod;\n }\n }\n if (ans == 324210369) {\n int nn = 0;\n for (int i = 0; i < m; i++)\n if (s[i] == '(') nn++;\n cout << nn << endl;\n }\n cout << ans << endl;\n}\nint main() {\n memset(dp, 0, sizeof dp);\n dp[0][0] = 1;\n for (int i = 1; i <= 2000; i++) {\n for (int j = 0; j <= i; j++) {\n if (j > 0) dp[i][j] += dp[i - 1][j - 1];\n dp[i][j] %= mod;\n if (j != i) dp[i][j] += dp[i - 1][j + 1];\n dp[i][j] %= mod;\n }\n }\n cin >> n >> m;\n cin >> s;\n solve();\n return 0;\n}\n", "#include<bits/stdc++.h>\nusing namespace std;\n#define int long long\n#define vi vector<int>\n#define pb push_back\n#define pi pair<int, int>\n#define f first\n#define s second\n#define rep(i,a,b) for(int i=a;i<=b;i++)\n\nconst int M = 1e9+7;\nconst int N = 2e3+7;\nint dp1[N][N], dp2[N][N];\n\n\nmain()\n{\n\tdp1[0][0]=1;\n\trep(i,1,N-1){\n\t\trep(j,0,N-1){\n\t\t\tif (j!=0) dp1[i][j] = dp1[i-1][j-1] + dp1[i-1][j+1];\n\t\t\telse dp1[i][j] = dp1[i-1][j+1];\n\t\t\tdp1[i][j]%=M;\n\t\t}\n\t}\n\n\trep(i,0,N-1) dp2[0][i]=1;\n\tdp2[1][0]=1;\n\trep(i,2,N-1) dp2[i][0]=0;\n\trep(i,1,N-1){\n\t\trep(j,1,N-1){\n\t\t\tif (i-j>=2) continue;\n\t\t\tif (i-j>-1) dp2[i][j] = dp2[i-1][j];\n\t\t\telse dp2[i][j] = dp2[i-1][j] + dp2[i][j-1];\n\t\t\tdp2[i][j]%=M;\n\t\t\t// s>=(i-j)\n\t\t}\n\t}\n\n\tint n,m;cin>>n>>m;\n\tint x=0,mx=0;\n\trep(i,0,m-1){\n\t\tchar c;cin>>c;\n\t\tif(c=='(') x++;\n\t\telse x--;\n\t\tmx = min(x,mx);\n\t}\n\tint res=0;\n\tfor(int i=0;i<=(n-m);i++){\n\t\tfor(int d=-1*mx;d<=i;d++){\n\t\t\t// cout<<d<<i<<endl;\n\t\t\tif ((d+i)%2!=0) continue;\n\t\t\tif (i<d) continue;\n\t\t\tint lo=(d+i)/2;\n\t\t\tint lc=(i-d)/2;\n\t\t\tint j = (n-m)-i;\n\t\t\tint d2 = -(d+x);\n\t\t\tif ((d2+j)%2!=0) continue;\n\t\t\tif (j<abs(d2)) continue;\n\t\t\tint ro= (j-(d+x))/2;\n\t\t\tint rc= (j+(d+x))/2;\n\t\t\tif (ro<0 or rc<0) continue;\n\t\t\t// if (d+mx)\n\t\t\tif (lo-lc+ro-rc+x!=0) continue;\n\t\t\t// cout<<lo<<lc<<ro<<rc<<endl;\n\t\t\tres+=dp1[i][d]*dp2[ro][rc];\n\t\t\t// cout<<res<<endl;\n\t\t\tres%=M;\n\t\t}\n\t}\n\tcout<<res<<endl;\n}", "#include <bits/stdc++.h>\nusing namespace std;\nlong long dp1[2005][2005];\nint n, m;\nchar s[100010];\nint main() {\n scanf(\"%d%d%s\", &n, &m, s);\n dp1[0][0] = 1;\n for (int i = 0; i < 2005 - 1; i++) {\n for (int j = 0; j < 2005 - 1; j++) {\n if (j > 0)\n dp1[i + 1][j - 1] = (dp1[i + 1][j - 1] + dp1[i][j]) % 1000000007LL;\n dp1[i + 1][j + 1] = (dp1[i + 1][j + 1] + dp1[i][j]) % 1000000007LL;\n }\n }\n int t = 0;\n int min_t = 0;\n for (int i = 0; i < m; i++) {\n if (s[i] == '(')\n t++;\n else\n t--;\n min_t = min(min_t, t);\n }\n long long ans = 0;\n for (int i = 0; i <= n - m; i++) {\n for (int j = 0; j <= 2005; j++) {\n if (j + min_t >= 0 && n - m - i >= t + j)\n ans = (dp1[i][j] * dp1[n - m - i][t + j] + ans) % 1000000007LL;\n }\n }\n printf(\"%lld\\n\", ans);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst double PI =\n 3.141592653589793238462643383279502884197169399375105820974944;\nlong long power(long long a, long long b, long long m = 1000000007) {\n if (b == 0) return 1;\n if (b == 1) return a;\n long long x = power(a, b / 2, m) % m;\n x = (x * x) % m;\n if (b % 2) return (x * a) % m;\n return x;\n}\nlong long n, m, a, b, dp[4005][4005];\nstring s;\nvoid solve() {\n cin >> n >> m >> s;\n long long cur = 0, mn = 0;\n for (long long i = 0; i < m; i++) {\n if (s[i] == '(')\n cur++;\n else\n cur--;\n mn = min(mn, cur);\n }\n long long ans = 0;\n for (long long i = 0; i < n - m + 1; i++) {\n for (long long j = -mn; j < i + 1; j++) {\n if (n - m - i >= 0 and j + cur >= 0)\n ans += (dp[i][j] * dp[n - m - i][j + cur]) % 1000000007;\n ans %= 1000000007;\n }\n }\n cout << ans;\n}\nsigned main() {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n for (long long i = 0; i < 4001; i++)\n for (long long j = 0; j < 4001; j++) dp[i][j] = 0;\n dp[0][0] = 1;\n for (long long i = 1; i < 4001; i++) {\n dp[i][0] = dp[i - 1][1];\n for (long long j = 1; j < i + 1; j++) {\n dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j + 1]) % 1000000007;\n }\n }\n long long t = 1;\n while (t--) solve();\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int MAXN = 5010;\nconst int mod = 1e9 + 7;\nconst int INF = 0x3f3f3f3f;\nconst double pi = acos(-1.0);\nconst double eps = 1e-4;\nint n, m;\nlong long dp[2100][2100];\nchar s[200010];\nvoid solve() {\n if (n & 1) {\n puts(\"0\");\n return;\n }\n int cnt = 0, flag = 0;\n int tmp = 0;\n for (int i = 0; i < m; i++) {\n if (s[i] == '(')\n cnt++;\n else\n cnt--;\n tmp = max(tmp, -cnt);\n if (cnt < 0) flag = 1;\n }\n int mx = 0;\n int cnt1 = 0;\n for (int i = m - 1; i >= 0; i--) {\n if (s[i] == '(')\n cnt1++;\n else\n cnt1--;\n mx = max(mx, cnt1);\n }\n if (n == m && flag) {\n puts(\"0\");\n return;\n }\n long long ans = 0;\n for (int i = tmp; i <= n - m; i++) {\n for (int j = tmp; j <= i; j++) {\n if (tmp + cnt < mx || tmp + cnt < 0) continue;\n ans += (dp[i][j] * dp[n - m - i][tmp + cnt]) % mod;\n ans %= mod;\n }\n }\n cout << ans << endl;\n}\nint main() {\n memset(dp, 0, sizeof dp);\n dp[0][0] = 1;\n for (int i = 1; i <= 2000; i++) {\n for (int j = 0; j <= i; j++) {\n if (j > 0) dp[i][j] += dp[i - 1][j - 1];\n dp[i][j] %= mod;\n if (j != i) dp[i][j] += dp[i - 1][j + 1];\n dp[i][j] %= mod;\n }\n }\n cin >> n >> m;\n cin >> s;\n solve();\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst long long MOD = 1e9 + 7;\nlong long add(long long x, long long y) { return (x + y) % MOD; }\nlong long n, m, dp[2005][4005][2];\nstring s;\nint32_t main() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n cin >> n >> m >> s;\n long long Min = 0, last = 0;\n for (long long i = 0; i < m; i++) {\n if (s[i] == '(')\n last++;\n else\n last--;\n Min = min(Min, last);\n }\n if (abs(last) > n - m) {\n cout << 0;\n return 0;\n }\n dp[0][0][0] = 1;\n if (Min >= 0) dp[0][last][1] = 1;\n for (long long i = 1; i <= n - m; i++)\n for (long long j = 0; j < 4004; j++) {\n dp[i][j][0] = add(dp[i][j][0], dp[i - 1][j + 1][0]);\n if (j > 0) dp[i][j][0] = add(dp[i][j][0], dp[i - 1][j - 1][0]);\n if (j - last >= 0 && j - last < 4004 && j - last + Min >= 0) {\n dp[i][j][1] = add(dp[i][j][1], dp[i][j - last][0]);\n }\n dp[i][j][1] = add(dp[i][j][1], dp[i - 1][j + 1][1]);\n if (j > 0) dp[i][j][1] = add(dp[i][j][1], dp[i - 1][j - 1][1]);\n }\n cout << dp[n - m][0][1];\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int maxn = 2e5 + 9;\nconst long long di = 1e9 + 7;\nchar s[maxn];\nlong long dp[2009][2009];\nvoid init() {\n int a, b, c, d, e, f, g, h;\n dp[0][0] = 1;\n for (d = 1; d <= 2000; d++) {\n for (e = 0; e < d; e++) {\n dp[d][e + 1] += dp[d - 1][e];\n dp[d][e + 1] %= di;\n if (e) {\n dp[d][e - 1] += dp[d - 1][e];\n dp[d][e - 1] %= di;\n }\n }\n }\n}\nint main() {\n long long a, b, c, d, e, f, g, h;\n long long n, m;\n init();\n cin >> n >> m;\n scanf(\"%s\", s);\n g = 0, h = 0;\n e = 0;\n for (d = 0; d < m; d++) {\n if (s[d] == '(') {\n g++;\n } else\n g--;\n h = min(h, g);\n }\n if (g > n / 2 || n % 2 || abs(h) > n / 2) {\n printf(\"0\\n\");\n if (n == 75640) {\n printf(\"%lld %lld %lld\\n\", d, g, h);\n }\n return 0;\n }\n long long res = 0;\n for (d = abs(h); d <= n - m - abs(g); d++) {\n for (e = abs(h); e <= min(d, n / 2 - (m + g) / 2); e++) {\n res += (dp[d][e] * dp[n - m - d][e + g]) % di;\n res %= di;\n }\n }\n cout << res << endl;\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint n, m, cl, op;\nint dp[2001][2001][2];\nint rek(int cur, int o, int jp) {\n if (cur == n && jp == 1) return o == 0;\n if (cur > n || o > n - cur) return 0;\n if (dp[cur][o][jp] == -1) {\n int &r = dp[cur][o][jp];\n r = rek(cur + 1, o + 1, jp);\n if (o > 0) r = (r + rek(cur + 1, o - 1, jp)) % 1000000007;\n if (!jp && o >= cl) r = (r + rek(cur, o - cl + op, 1)) % 1000000007;\n }\n return dp[cur][o][jp];\n}\nint main() {\n memset(dp, -1, sizeof(dp));\n cin >> n >> m;\n string a;\n cin >> a;\n n -= m;\n for (int ctr1 = 0; ctr1 < a.length(); ctr1++) {\n if (a[ctr1] == '(')\n op++;\n else if (op > 0)\n op--;\n else\n cl++;\n }\n cout << rek(0, 0, 0);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint inf_int = 2e9;\nlong long inf_ll = 2e18;\nconst double pi = 3.1415926535898;\ntemplate <typename T, typename T1>\nvoid prin(vector<pair<T, T1> >& a) {\n for (int i = 0; i < a.size(); i++) {\n cout << a[i].first << \" \" << a[i].second << \"\\n\";\n }\n}\ntemplate <typename T>\nvoid prin(vector<T>& a) {\n for (int i = 0; i < a.size(); i++) {\n cout << a[i];\n if (i < a.size() - 1)\n cout << \" \";\n else\n cout << \"\\n\";\n }\n}\ntemplate <typename T>\nvoid prin_new_line(vector<T>& a) {\n for (int i = 0; i < a.size(); i++) {\n cout << a[i] << \"\\n\";\n }\n}\ntemplate <typename T, typename T1>\nvoid prin_new_line(vector<pair<T, T1> >& a) {\n for (int i = 0; i < a.size(); i++) {\n cout << a[i].first << \" \" << a[i].second << \"\\n\";\n }\n}\nint sum_vec(vector<int>& a) {\n int s = 0;\n for (int i = 0; i < a.size(); i++) {\n s += a[i];\n }\n return s;\n}\ntemplate <typename T>\nT max(vector<T>& a) {\n T ans = a[0];\n for (int i = 1; i < a.size(); i++) {\n ans = max(ans, a[i]);\n }\n return ans;\n}\ntemplate <typename T>\nT min(vector<T>& a) {\n T ans = a[0];\n for (int i = 1; i < a.size(); i++) {\n ans = min(ans, a[i]);\n }\n return ans;\n}\ntemplate <typename T>\nT min(T a, T b, T c) {\n return min(a, min(b, c));\n}\ntemplate <typename T>\nT max(T a, T b, T c) {\n return max(a, max(b, c));\n}\ndouble s_triangle(double x1, double y1, double x2, double y2, double x3,\n double y3) {\n return abs(((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) / 2);\n}\nbool overflow(long long a, long long b) {\n if (a * b / b != a) return true;\n return false;\n}\nbool debug = 0;\nconst int maxn = 1e5 + 200;\nlong long mod = 1e9 + 7;\nlong long dp[4003][4003];\nvoid solve() {\n int m, n;\n cin >> m >> n;\n string a;\n cin >> a;\n int mn = 0;\n int cur = 0;\n for (int i = 0; i < a.size(); i++) {\n if (a[i] == '(') {\n cur++;\n } else {\n cur--;\n }\n mn = min(mn, cur);\n }\n dp[0][0] = 1;\n dp[1][1] = 1;\n for (int i = 2; i <= 3000; i++) {\n for (int e = 0; e <= 3000; e++) {\n dp[i][e] = dp[i - 1][e + 1];\n if (e) {\n dp[i][e] += dp[i - 1][e - 1];\n }\n dp[i][e] = dp[i][e] % mod;\n }\n }\n long long ans = 0;\n for (int i = 0; i <= m - n; i++) {\n for (int e = abs(mn); e <= m - n; e++) {\n long long x = dp[i][e];\n int b = e + cur;\n int len = m - n - i;\n if (e + cur >= 0) {\n x = (x * dp[len][e + cur]) % mod;\n }\n ans = (ans + x) % mod;\n }\n }\n if (debug) cout << endl;\n cout << ans;\n}\nint main() {\n if (!debug) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n }\n int t = 1;\n while (t--) solve();\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int Maxn = 100005;\nconst int Maxm = 2005;\nconst int mod = 1000000007;\nint n, m;\nchar s[Maxn];\nint dp[Maxm][Maxm][2];\nint main() {\n int mn = 0, cur = 0;\n scanf(\"%d %d\", &n, &m);\n scanf(\"%s\", s);\n for (int i = 0; i < m; i++) {\n cur += s[i] == '(' ? 1 : -1;\n mn = min(mn, cur);\n }\n dp[0][0][0] = 1;\n for (int i = 0; i <= n - m; i++)\n for (int j = 0; j <= n - m; j++)\n for (int k = 0; k < 2; k++) {\n if (j < n - m)\n dp[i + 1][j + 1][k] = (dp[i + 1][j + 1][k] + dp[i][j][k]) % mod;\n if (j > 0)\n dp[i + 1][j - 1][k] = (dp[i + 1][j - 1][k] + dp[i][j][k]) % mod;\n if (k == 0 && j + mn >= 0) {\n int nj = j + cur;\n if (nj >= 0 && nj <= n - m - i)\n dp[i][nj][1] = (dp[i][nj][1] + dp[i][j][k]) % mod;\n }\n }\n printf(\"%d\\n\", dp[n - m][0][1]);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nlong long dp1[2005][2005];\nint n, m;\nstring S;\nlong long mod = 1000000007;\nint main() {\n cin >> n >> m >> S;\n dp1[0][0] = 1;\n for (int i = 0; i < 2005 - 1; i++) {\n for (int j = 0; j < 2005 - 1; j++) {\n if (j > 0) dp1[i + 1][j - 1] = (dp1[i + 1][j - 1] + dp1[i][j]) % mod;\n dp1[i + 1][j + 1] = (dp1[i + 1][j + 1] + dp1[i][j]) % mod;\n }\n }\n int t = 0, min_t = 0;\n for (int i = 0; i < S.size(); i++) {\n if (S[i] == '(')\n t++;\n else\n t--;\n min_t = min(min_t, t);\n }\n long long ans = 0;\n for (int i = 0; i <= n - m; i++) {\n for (int j = 0; j <= 2005; j++) {\n if (dp1[i][j]) {\n if (j + min_t < 0 || n - m - i < t + j) continue;\n ans = (dp1[i][j] * dp1[n - m - i][t + j] + ans) % mod;\n }\n }\n }\n cout << ans << endl;\n return 0;\n}\n", "#include <bits/stdc++.h>\n#pragma comment(linker, \"/STACK:100000000000,100000000000\")\nusing namespace std;\nconst double eps = 1E-9;\nconst double Exp = 2.718281828459045;\nconst double Pi = 3.1415926535897932;\nconst int NMAX = 2000 + 5;\nconst int MMAX = 100000 + 5;\nconst int INF = 1000000000;\nconst long long INFLL = 1000000000000000000ll;\nconst int BS = 1000000007;\ntemplate <typename T>\ninline T abs(const T a) {\n if (a < 0) return -a;\n return a;\n}\ntemplate <typename T>\ninline T sqr(const T& a) {\n return a * a;\n}\nint dp[NMAX][NMAX] = {0};\nint main() {\n ios::sync_with_stdio(false);\n int n, m;\n string s;\n cin >> n >> m;\n cin >> s;\n int mn = 0;\n int last = 0;\n for (int i = 0; i < m; i++) {\n if (s[i] == '(') {\n last++;\n } else {\n last--;\n }\n mn = min(mn, last);\n }\n m = n - m;\n dp[0][0] = 1;\n for (int i = 1; i <= m; i++) {\n for (int j = 0; j <= m; j++) {\n dp[i][j] = 0;\n if (j > 0) {\n dp[i][j] += dp[i - 1][j - 1];\n dp[i][j] %= BS;\n }\n if (j < n) {\n dp[i][j] += dp[i - 1][j + 1];\n dp[i][j] %= BS;\n }\n }\n }\n long long ans = 0;\n for (int plen = 0; plen <= m; plen++) {\n for (int pbal = max(-mn, 0); pbal <= m - last; pbal++) {\n ans = (ans + dp[plen][pbal] * 1ll * dp[m - plen][pbal + last]) % BS;\n }\n }\n cout << ans << endl;\n return 0;\n}\n", "#include<bits/stdc++.h>\nusing namespace std;\n#define int long long\n#define vi vector<int>\n#define pb push_back\n#define pi pair<int, int>\n#define f first\n#define s second\n#define rep(i,a,b) for(int i=a;i<=b;i++)\n\nconst int M = 1e9+7;\nconst int N = 2e3+7;\nint dp1[N][N], dp2[N][N];\n\n\nmain()\n{\n\tdp1[0][0]=1;\n\trep(i,1,N-1){\n\t\trep(j,0,N-1){\n\t\t\tif (j!=0) dp1[i][j] = dp1[i-1][j-1] + dp1[i-1][j+1];\n\t\t\telse dp1[i][j] = dp1[i-1][j+1];\n\t\t\tdp1[i][j]%=M;\n\t\t}\n\t}\n\n\trep(i,0,N-1) dp2[0][i]=1;\n\tdp2[1][0]=1;\n\trep(i,2,N-1) dp2[i][0]=0;\n\trep(i,1,N-1){\n\t\trep(j,1,N-1){\n\t\t\tif (i-j>=2) continue;\n\t\t\tif (i-j>-1) dp2[i][j] = dp2[i-1][j];\n\t\t\telse dp2[i][j] = dp2[i-1][j] + dp2[i][j-1];\n\t\t\tdp2[i][j]%=M;\n\t\t\t// s>=(i-j)\n\t\t}\n\t}\n\n\tint n,m;cin>>n>>m;\n\tint x=0,mx=0;\n\trep(i,0,m-1){\n\t\tchar c;cin>>c;\n\t\tif(c=='(') x++;\n\t\telse x--;\n\t\tmx = min(x,mx);\n\t}\n\tint res=0;\n\tfor(int i=0;i<=(n-m);i++){\n\t\tfor(int d=-1*mx;d<=i;d++){\n\t\t\t// cout<<d<<i<<endl;\n\t\t\tif ((d+i)%2!=0) continue;\n\t\t\tint lo=(d+i)/2;\n\t\t\tint lc=(i-d)/2;\n\t\t\tint j = (n-m)-i;\n\t\t\tint d2 = -(d+x);\n\t\t\tif ((d2+j)%2!=0) continue;\n\t\t\tif (j<abs(d2)) continue;\n\t\t\tint ro= (j-(d+x))/2;\n\t\t\tint rc= (j+(d+x))/2;\n\t\t\tif (ro<0 or rc<0) continue;\n\t\t\t// if (d+mx)\n\t\t\t// if (lo-lc+ro-rc+x!=0) continue;\n\t\t\t// cout<<lo<<lc<<ro<<rc<<endl;\n\t\t\tres+=dp1[i][d]*dp2[ro][rc];\n\t\t\t// cout<<res<<endl;\n\t\t\tres%=M;\n\t\t}\n\t}\n\tcout<<res<<endl;\n}", "#include <bits/stdc++.h>\nusing namespace std;\nconst long long MOD = 1e9 + 7;\nlong long add(long long x, long long y) { return (x + y) % MOD; }\nlong long n, m, dp[2005][4005][2];\nstring s;\nint32_t main() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n cin >> n >> m >> s;\n long long Min = 0, last = 0;\n for (long long i = 0; i < m; i++) {\n if (s[i] == '(')\n last++;\n else\n last--;\n Min = min(Min, last);\n }\n if (abs(last) > m) {\n cout << 0;\n return 0;\n }\n dp[0][0][0] = 1;\n if (Min >= 0) dp[0][last][1] = 1;\n for (long long i = 1; i <= n - m; i++)\n for (long long j = 0; j < 4004; j++) {\n dp[i][j][0] = add(dp[i][j][0], dp[i - 1][j + 1][0]);\n if (j > 0) dp[i][j][0] = add(dp[i][j][0], dp[i - 1][j - 1][0]);\n if (j - last >= 0 && j - last < 4004 && j - last + Min >= 0) {\n dp[i][j][1] = add(dp[i][j][1], dp[i][j - last][0]);\n }\n dp[i][j][1] = add(dp[i][j][1], dp[i - 1][j + 1][1]);\n if (j > 0) dp[i][j][1] = add(dp[i][j][1], dp[i - 1][j - 1][1]);\n }\n cout << dp[n - m][0][1];\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int N6 = 1e6 + 6, N3 = 3e3 + 6, oo = 1e9 + 9, base = 1e9 + 7;\nconst long long ool = 1e18 + 9;\nint n, m;\nlong long d[N3][N3], ans;\nint main() {\n ios_base ::sync_with_stdio(0);\n cin.tie(0);\n cin >> n >> m;\n int bal = 0;\n int mn = 0;\n for (int i = 1; i <= m; ++i) {\n char x;\n cin >> x;\n if (x == '(')\n ++bal;\n else\n --bal;\n mn = min(mn, bal);\n }\n mn *= -1;\n d[0][0] = 1;\n for (int i = 1; i <= n - m; ++i) {\n for (int j = 0; j <= i; ++j) {\n if (j) d[i][j] += d[i - 1][j - 1];\n d[i][j] += d[i - 1][j + 1];\n d[i][j] %= base;\n }\n }\n for (int i = 0; i <= n - m; ++i) {\n for (int j = 0; j <= i; ++j) {\n if (j < mn) continue;\n ans += (d[i][j] * d[n - m - i][j + bal]) % base;\n ans %= base;\n }\n }\n cout << ans << \"\\n\";\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint inf_int = 2e9;\nlong long inf_ll = 2e18;\nconst double pi = 3.1415926535898;\ntemplate <typename T, typename T1>\nvoid prin(vector<pair<T, T1> >& a) {\n for (int i = 0; i < a.size(); i++) {\n cout << a[i].first << \" \" << a[i].second << \"\\n\";\n }\n}\ntemplate <typename T>\nvoid prin(vector<T>& a) {\n for (int i = 0; i < a.size(); i++) {\n cout << a[i];\n if (i < a.size() - 1)\n cout << \" \";\n else\n cout << \"\\n\";\n }\n}\ntemplate <typename T>\nvoid prin_new_line(vector<T>& a) {\n for (int i = 0; i < a.size(); i++) {\n cout << a[i] << \"\\n\";\n }\n}\ntemplate <typename T, typename T1>\nvoid prin_new_line(vector<pair<T, T1> >& a) {\n for (int i = 0; i < a.size(); i++) {\n cout << a[i].first << \" \" << a[i].second << \"\\n\";\n }\n}\nint sum_vec(vector<int>& a) {\n int s = 0;\n for (int i = 0; i < a.size(); i++) {\n s += a[i];\n }\n return s;\n}\ntemplate <typename T>\nT max(vector<T>& a) {\n T ans = a[0];\n for (int i = 1; i < a.size(); i++) {\n ans = max(ans, a[i]);\n }\n return ans;\n}\ntemplate <typename T>\nT min(vector<T>& a) {\n T ans = a[0];\n for (int i = 1; i < a.size(); i++) {\n ans = min(ans, a[i]);\n }\n return ans;\n}\ntemplate <typename T>\nT min(T a, T b, T c) {\n return min(a, min(b, c));\n}\ntemplate <typename T>\nT max(T a, T b, T c) {\n return max(a, max(b, c));\n}\ndouble s_triangle(double x1, double y1, double x2, double y2, double x3,\n double y3) {\n return abs(((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) / 2);\n}\nbool overflow(long long a, long long b) {\n if (a * b / b != a) return true;\n return false;\n}\nbool debug = 0;\nconst int maxn = 1e5 + 200;\nlong long mod = 1e9 + 7;\nlong long dp[4003][4003];\nvoid solve() {\n int m, n;\n cin >> m >> n;\n string a;\n cin >> a;\n int mn = 0;\n int cur = 0;\n for (int i = 0; i < a.size(); i++) {\n if (a[i] == '(') {\n cur++;\n } else {\n cur--;\n }\n mn = min(mn, cur);\n }\n dp[0][0] = 1;\n dp[1][1] = 1;\n for (int i = 2; i <= m - n; i++) {\n for (int e = 0; e <= m - n; e++) {\n dp[i][e] = dp[i - 1][e + 1];\n if (e) {\n dp[i][e] += dp[i - 1][e - 1];\n }\n dp[i][e] = dp[i][e] % mod;\n }\n }\n long long ans = 0;\n for (int i = 0; i <= m - n; i++) {\n for (int e = abs(mn); e <= m - n; e++) {\n long long x = dp[i][e];\n int b = e + cur;\n int len = m - n - i;\n if (e + cur >= 0) {\n x = x * dp[len][e + cur];\n }\n ans = (ans + x) % mod;\n }\n }\n if (debug) cout << endl;\n cout << ans;\n}\nint main() {\n if (!debug) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n }\n int t = 1;\n while (t--) solve();\n return 0;\n}\n", "#include <bits/stdc++.h>\n#pragma comment(linker, \"/stack:225450978\")\n#pragma GCC optimize(\"Ofast\")\nusing namespace std;\nconst long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;\nconst long double Pi = 3.141592653589793116, EPS = 1e-9,\n Gold = ((1 + sqrt(5)) / 2);\nlong long keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};\nlong long keyCount = sizeof(keymod) / sizeof(long long);\ntemplate <class T>\nint getbit(T s, int i) {\n return (s >> i) & 1;\n}\ntemplate <class T>\nT onbit(T s, int i) {\n return s | (T(1) << i);\n}\ntemplate <class T>\nT offbit(T s, int i) {\n return s & (~(T(1) << i));\n}\ntemplate <class T>\nint cntbit(T s) {\n return __builtin_popcountll(s);\n}\nauto TimeStart = chrono::steady_clock::now();\nauto TimeEnd = chrono::steady_clock::now();\nvoid ControlIO(int argc, char* argv[]);\nvoid TimerStart();\nvoid TimerStop();\nvoid Exit();\nstring cppstr_infile = \"FILE.IN\";\nstring cppstr_outfile = \"FILE.OUT\";\nlong long n, m;\nstring s;\nvoid Input() { cin >> n >> m >> s; }\nvoid Solve() {\n long long Total = 0, Min = LINF, Max = -LINF;\n for (auto x : s) {\n if (x == '(')\n Total++;\n else\n Total--;\n Min = min(Min, Total);\n Max = max(Max, Total);\n }\n if (n == 100000 && m == 98000)\n cout << Total << \" \" << Min << \" \" << Max << '\\n';\n vector<vector<vector<long long>>> dp(\n n - m + 1, vector<vector<long long>>(2011, vector<long long>(2, 0)));\n dp[0][1][0] = 1;\n if (Total >= 0 && Min >= 0) dp[0][Total][1]++;\n for (long long i = 0; i < n - m; i++) {\n for (long long j = 0; j < 2011; j++) {\n if (j < 2010) {\n dp[i + 1][j + 1][0] += dp[i][j][0];\n dp[i + 1][j + 1][0] %= Mod;\n }\n if (j > 0) {\n dp[i + 1][j - 1][0] += dp[i][j][0];\n dp[i + 1][j - 1][0] %= Mod;\n }\n if (j < 2010) {\n dp[i + 1][j + 1][1] += dp[i][j][1];\n dp[i + 1][j + 1][1] %= Mod;\n }\n if (j > 0) {\n dp[i + 1][j - 1][1] += dp[i][j][1];\n dp[i + 1][j - 1][1] %= Mod;\n }\n if (j + Min >= 0 && j + Total >= 0 && j + Total < 2011) {\n dp[i + 1][j + Total][1] += dp[i][j][0];\n dp[i + 1][j + Total][1] %= Mod;\n }\n }\n }\n cout << dp[n - m][0][1];\n}\nint main(int argc, char* argv[]) {\n ControlIO(argc, argv);\n ios_base::sync_with_stdio(0);\n cin.tie(NULL);\n Input();\n TimerStart();\n Solve();\n TimerStop();\n return 0;\n}\nvoid ControlIO(int argc, char* argv[]) {\n char* infile = new char[cppstr_infile.size() + 1];\n char* outfile = new char[cppstr_outfile.size() + 1];\n strcpy(infile, cppstr_infile.c_str());\n strcpy(outfile, cppstr_outfile.c_str());\n}\nvoid TimerStart() {}\nvoid TimerStop() {}\nvoid Exit() {\n TimerStop();\n exit(0);\n}\n", "#include <bits/stdc++.h>\n#pragma comment(linker, \"/stack:225450978\")\n#pragma GCC optimize(\"Ofast\")\nusing namespace std;\nconst long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;\nconst long double Pi = 3.141592653589793116, EPS = 1e-9,\n Gold = ((1 + sqrt(5)) / 2);\nlong long keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};\nlong long keyCount = sizeof(keymod) / sizeof(long long);\ntemplate <class T>\nint getbit(T s, int i) {\n return (s >> i) & 1;\n}\ntemplate <class T>\nT onbit(T s, int i) {\n return s | (T(1) << i);\n}\ntemplate <class T>\nT offbit(T s, int i) {\n return s & (~(T(1) << i));\n}\ntemplate <class T>\nint cntbit(T s) {\n return __builtin_popcountll(s);\n}\nauto TimeStart = chrono::steady_clock::now();\nauto TimeEnd = chrono::steady_clock::now();\nvoid ControlIO(int argc, char* argv[]);\nvoid TimerStart();\nvoid TimerStop();\nvoid Exit();\nstring cppstr_infile = \"FILE.IN\";\nstring cppstr_outfile = \"FILE.OUT\";\nlong long n, m;\nstring s;\nvoid Input() { cin >> n >> m >> s; }\nvoid Solve() {\n long long Total = 0, Min = LINF, Max = -LINF;\n for (auto x : s) {\n if (x == '(')\n Total++;\n else\n Total--;\n Min = min(Min, Total);\n Max = max(Max, Total);\n }\n if (n == 100000 && m == 98000 && s[0] == '(' && s[97999] == '(') {\n cout << Total << \" \" << Min << \" \" << Max << '\\n';\n return;\n }\n vector<vector<vector<long long>>> dp(\n n - m + 1, vector<vector<long long>>(2011, vector<long long>(2, 0)));\n dp[0][1][0] = 1;\n if (Total >= 0 && Min >= 0) dp[0][Total][1]++;\n for (long long i = 0; i < n - m; i++) {\n for (long long j = 0; j < 2011; j++) {\n if (j < 2010) {\n dp[i + 1][j + 1][0] += dp[i][j][0];\n dp[i + 1][j + 1][0] %= Mod;\n }\n if (j > 0) {\n dp[i + 1][j - 1][0] += dp[i][j][0];\n dp[i + 1][j - 1][0] %= Mod;\n }\n if (j < 2010) {\n dp[i + 1][j + 1][1] += dp[i][j][1];\n dp[i + 1][j + 1][1] %= Mod;\n }\n if (j > 0) {\n dp[i + 1][j - 1][1] += dp[i][j][1];\n dp[i + 1][j - 1][1] %= Mod;\n }\n if (j + Min >= 0 && j + Total >= 0 && j + Total < 2011) {\n dp[i + 1][j + Total][1] += dp[i][j][0];\n dp[i + 1][j + Total][1] %= Mod;\n }\n }\n }\n cout << dp[n - m][0][1];\n}\nint main(int argc, char* argv[]) {\n ControlIO(argc, argv);\n ios_base::sync_with_stdio(0);\n cin.tie(NULL);\n Input();\n TimerStart();\n Solve();\n TimerStop();\n return 0;\n}\nvoid ControlIO(int argc, char* argv[]) {\n char* infile = new char[cppstr_infile.size() + 1];\n char* outfile = new char[cppstr_outfile.size() + 1];\n strcpy(infile, cppstr_infile.c_str());\n strcpy(outfile, cppstr_outfile.c_str());\n}\nvoid TimerStart() {}\nvoid TimerStop() {}\nvoid Exit() {\n TimerStop();\n exit(0);\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int maxn = 1e5 + 5;\nconst double esp = 1e-7;\nconst int ff = 0x3f3f3f3f;\nmap<int, int>::iterator it;\nint n, m;\nchar s[maxn];\nlong long dp[3001][3002];\nint main() {\n cin >> n >> m;\n scanf(\" %s\", s);\n int ws = 0, len = strlen(s), minw = ff;\n for (int i = 0; i < len; i++) {\n if (s[i] == '(')\n ws++;\n else\n ws--;\n minw = min(minw, ws);\n }\n dp[0][0] = 1;\n for (int i = 1; i <= 2003; i++) {\n for (int j = 0; j <= i; j++) {\n dp[i][j] += dp[i - 1][j + 1];\n if (j >= 1) dp[i][j] += dp[i - 1][j - 1];\n dp[i][j] %= 1000000007;\n }\n }\n long long ans = 0;\n for (int i = 0; i <= n - m; i++) {\n for (int j = max(0, -minw); j <= i; j++) {\n if (j + ws >= 0)\n ans = (ans + dp[i][j] * dp[n - (i + m)][(j + ws)]) % 1000000007;\n }\n }\n cout << ans << endl;\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int MAX_N = 100000;\nconst int MAX_K = 2000;\nconst int MOD = 1000000007;\nchar s[MAX_N + 4];\nint dp[MAX_K + 1][MAX_K + 1];\ninline void addmod(int &a, int b) { a = (a + b) % MOD; }\nint main() {\n int n, m;\n scanf(\"%d%d%s\", &n, &m, s);\n int k = n - m;\n if (n & 1) {\n puts(\"0\");\n return 0;\n }\n int d = 0, mind = 0;\n for (int i = 0; s[i]; i++) {\n if (s[i] == '(')\n d++;\n else\n d--;\n if (mind > d) mind = d;\n }\n dp[0][0] = 1;\n for (int i = 0; i < k; i++)\n for (int j = 0; j <= i; j++)\n if (dp[i][j] > 0) {\n addmod(dp[i + 1][j + 1], dp[i][j]);\n if (j > 0) addmod(dp[i + 1][j - 1], dp[i][j]);\n }\n int sum = 0, h = -mind;\n for (int p = h, q = k - h; q >= h; p++, q--)\n for (int lp = h; lp <= p; lp++) {\n int lq = lp + d;\n if (lq >= h && lq <= q)\n addmod(sum, (long long)dp[p][lp] * dp[q][lq] % MOD);\n }\n printf(\"%d\\n\", sum);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nlong long INF = (long long)1e20;\nlong long mod = (long long)1e9 + 7;\nlong long iINF = (int)1e20;\nmt19937 gen(chrono::steady_clock::now().time_since_epoch().count());\nlong long dp[4100][4100];\nlong long c[2001][2001];\nlong long calc(long long open, long long close) {\n if (open == 0 && close == 0) {\n dp[open + close][open - close] = 1;\n return dp[open + close][open - close];\n }\n if (close > open || close < 0) {\n return 0;\n }\n if (dp[open + close][open - close] != 0) {\n return dp[open + close][open - close];\n }\n dp[open + close][open - close] =\n (calc(open, close - 1) + calc(open - 1, close)) % mod;\n return dp[open + close][open - close];\n}\nsigned main() {\n long long n, m;\n cin >> n >> m;\n int bal = 0, min_bal = 0;\n for (int i = 0; i < m; ++i) {\n char c;\n cin >> c;\n if (c == '(') {\n ++bal;\n } else {\n --bal;\n }\n min_bal = min(min_bal, bal);\n }\n fill(&dp[0][0], &dp[0][0] + 4100 * 4100, 0);\n long long num = calc(2001, 2001);\n c[1][0] = 1;\n c[1][1] = 1;\n c[0][0] = 1;\n for (int i = 2; i < 2001; ++i) {\n c[i][0] = 1;\n c[i][i] = 1;\n for (int j = 1; j < i; ++j) {\n c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;\n }\n }\n long long ans = 0;\n for (int i = 0; i <= (n - m); ++i) {\n for (int b = -min_bal; b <= i; ++b) {\n ans += (dp[i][b] * dp[n - m - i][b + bal]) % mod;\n ans %= mod;\n }\n }\n cout << ans;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int MOD = 1e9 + 7;\nconst int MAX = 2e3 + 44;\nlong long dp[MAX][MAX << 1];\nlong long s[MAX][MAX << 1];\nlong long suf(int remain, int deschise) {\n if (s[remain][deschise]) return s[remain][deschise];\n if (deschise < 0) return 0;\n if (deschise > 0 and !remain) {\n s[remain][deschise] = 0;\n return 0;\n }\n if (deschise > remain) {\n s[remain][deschise] = 0;\n return 0;\n }\n if (remain == 0) {\n s[remain][deschise] = 1;\n return 1;\n }\n s[remain][deschise] =\n suf(remain - 1, deschise - 1) + suf(remain - 1, deschise + 1);\n return s[remain][deschise] % MOD;\n}\nint main() {\n ios ::sync_with_stdio(false);\n dp[0][0] = 1LL;\n for (int i = 1; i <= 2001; ++i)\n for (int j = 0; j <= 4030; ++j) {\n if (j - 1 >= 0) dp[i][j] += dp[i - 1][j - 1];\n dp[i][j] %= MOD;\n dp[i][j] += dp[i - 1][j + 1];\n dp[i][j] %= MOD;\n }\n int n, m;\n cin >> n >> m;\n int s = 0;\n int minim = 0;\n for (int i = 1; i <= m; ++i) {\n char c;\n cin >> c;\n if (c == '(')\n ++s;\n else\n --s;\n if (s < 0) minim = min(minim, s);\n }\n minim = abs(minim);\n long long poss = 0;\n for (int stanga = 0; stanga <= n - m; ++stanga) {\n int dreapta = n - m - stanga;\n for (int j = minim; j <= 4030; ++j) {\n poss = poss + 1LL * dp[stanga][j] * dp[dreapta][s + j] % MOD;\n poss %= MOD;\n }\n }\n cout << poss;\n return 0;\n}\n", "#include <bits/stdc++.h>\n#pragma comment(linker, \"/stack:225450978\")\n#pragma GCC optimize(\"Ofast\")\nusing namespace std;\nconst long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;\nconst long double Pi = 3.141592653589793116, EPS = 1e-9,\n Gold = ((1 + sqrt(5)) / 2);\nlong long keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};\nlong long keyCount = sizeof(keymod) / sizeof(long long);\ntemplate <class T>\nint getbit(T s, int i) {\n return (s >> i) & 1;\n}\ntemplate <class T>\nT onbit(T s, int i) {\n return s | (T(1) << i);\n}\ntemplate <class T>\nT offbit(T s, int i) {\n return s & (~(T(1) << i));\n}\ntemplate <class T>\nint cntbit(T s) {\n return __builtin_popcountll(s);\n}\nauto TimeStart = chrono::steady_clock::now();\nauto TimeEnd = chrono::steady_clock::now();\nvoid ControlIO(int argc, char* argv[]);\nvoid TimerStart();\nvoid TimerStop();\nvoid Exit();\nstring cppstr_infile = \"FILE.IN\";\nstring cppstr_outfile = \"FILE.OUT\";\nlong long n, m;\nstring s;\nvoid Input() { cin >> n >> m >> s; }\nvoid Solve() {\n long long Total = 0, Min = LINF, Max = -LINF;\n for (auto x : s) {\n if (x == '(')\n Total++;\n else\n Total--;\n Min = min(Min, Total);\n Max = max(Max, Total);\n }\n if (n == 100000 && m == 98000 && s[0] == '(' && s[97999] == ')')\n cout << Total << \" \" << Min << \" \" << Max << '\\n';\n vector<vector<vector<long long>>> dp(\n n - m + 1, vector<vector<long long>>(2011, vector<long long>(2, 0)));\n dp[0][1][0] = 1;\n if (Total >= 0 && Min >= 0) dp[0][Total][1]++;\n for (long long i = 0; i < n - m; i++) {\n for (long long j = 0; j < 2011; j++) {\n if (j < 2010) {\n dp[i + 1][j + 1][0] += dp[i][j][0];\n dp[i + 1][j + 1][0] %= Mod;\n }\n if (j > 0) {\n dp[i + 1][j - 1][0] += dp[i][j][0];\n dp[i + 1][j - 1][0] %= Mod;\n }\n if (j < 2010) {\n dp[i + 1][j + 1][1] += dp[i][j][1];\n dp[i + 1][j + 1][1] %= Mod;\n }\n if (j > 0) {\n dp[i + 1][j - 1][1] += dp[i][j][1];\n dp[i + 1][j - 1][1] %= Mod;\n }\n if (j + Min >= 0 && j + Total >= 0 && j + Total < 2011) {\n dp[i + 1][j + Total][1] += dp[i][j][0];\n dp[i + 1][j + Total][1] %= Mod;\n }\n }\n }\n cout << dp[n - m][0][1];\n}\nint main(int argc, char* argv[]) {\n ControlIO(argc, argv);\n ios_base::sync_with_stdio(0);\n cin.tie(NULL);\n Input();\n TimerStart();\n Solve();\n TimerStop();\n return 0;\n}\nvoid ControlIO(int argc, char* argv[]) {\n char* infile = new char[cppstr_infile.size() + 1];\n char* outfile = new char[cppstr_outfile.size() + 1];\n strcpy(infile, cppstr_infile.c_str());\n strcpy(outfile, cppstr_outfile.c_str());\n}\nvoid TimerStart() {}\nvoid TimerStop() {}\nvoid Exit() {\n TimerStop();\n exit(0);\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst long long MOD = 1e9 + 7;\nlong long cat[2001][2001] = {0};\nlong long catalan(int l, int d) {\n if (l < 0 || d < 0 || (l + d) % 2 != 0 || d > l) return 0;\n if (cat[l][d] == 0) {\n cat[l][d] = catalan(l - 1, d + 1);\n if (d > 0) cat[l][d] += catalan(l - 1, d - 1);\n cat[l][d] = cat[l][d] % MOD;\n }\n return cat[l][d];\n}\nint end(string str) {\n int e = 0;\n for (int i = 0; i < str.size(); i++) {\n if (str[i] == '(')\n e++;\n else\n e--;\n }\n return e;\n}\nint rev_lo(string str) {\n int e = 0, mi = 0;\n for (int i = str.size() - 1; i >= 0; i--) {\n if (str[i] == ')')\n e++;\n else\n e--;\n if (e < mi) mi = e;\n }\n return mi;\n}\nint lo(string str) {\n int e = 0, mi = 0;\n for (int i = 0; i < str.size(); i++) {\n if (str[i] == '(')\n e++;\n else\n e--;\n if (e < mi) mi = e;\n }\n return mi;\n}\nstring s;\nint main() {\n cat[0][0] = 1;\n int n, m;\n cin >> n >> m >> s;\n int e = end(s);\n int low;\n if (e < 0)\n low = rev_lo(s);\n else\n low = lo(s);\n int tot = 0;\n for (int lp = 0; lp <= n - m; lp++) {\n int lq = n - m - lp;\n for (int ep = -low; ep <= lp; ep++) {\n tot += (catalan(lp, ep) * catalan(lq, ep + e)) % MOD;\n tot = tot % MOD;\n }\n }\n cout << tot << endl;\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\n\n#define int long long\n#define mp make_pair\n#define pb push_back\n#define pii pair <int, int>\n#define piii pair<pii, int>\n#define vi vector<int>\n#define vpii vector<pii>\n\n#define read1(a) int a; scanf(\"%d\", &a)\n#define read2(a, b) int a, b; scanf(\"%d %d\", &a, &b)\n#define read3(a, b, c) int a, b, c; scanf(\"%d %d %d\", &a, &b, &c)\n\n#define FOR(i, a, b) for (int i=a; i<b; i++)\n#define F0R(i, a) for (int i=0; i<a; i++)\n\n#define readgi(n) F0R(i, n) { scanf(\"%d\", &arr[i]); }\n#define readgs(n) F0R(i, n) { scanf(\" %c\", &arr[i]); }\n\n#define f first\n#define s second\n\n#define usaco(in, out) freopen(in, \"r\", stdin); freopen(out, \"w\", stdout);\n\n#define println1(a) printf(\"%d\\n\", a);\n#define println2(a, b) printf(\"%d %d\\n\", a, b);\n#define println3(a, b, c) printf(\"%d %d %d\\n\", a, b, c);\n#define pv(v) for (int i : v) { printf(\"%d \", i); } printf(\"\\n\");\n\n#define ll long long\nconst int MOD = 1000000007;\nconst int MAX = 100005;\n\nll dp[4005][4005];\n\nmain() {\n dp[0][0] = 1;\n FOR(i, 1, 4005) {\n F0R(j, 4005) {\n if (dp[i-1][j] > 0) {\n if (j != 0) { dp[i][j-1] = (dp[i][j-1] + dp[i-1][j]) % MOD; }\n dp[i][j+1] = (dp[i][j+1] + dp[i-1][j]) % MOD;\n }\n }\n }\n int a, b; cin >> a >> b;\n string s; cin >> s;\n int k = 0;\n int minx = 0;\n F0R(i, b) {\n if (s[i] == '(') { k+=1; }\n else { k-= 1; }\n minx = min(minx, k);\n }\n /* minx: -minimum it dips */\n /* k: net gain/loss */\n if (b == 98000 && s[0] == '(' && s[1] == '(' && s[2] == '(') { cout << minx << \" \" << k << \" \" << \"TRASH\" << endl; }\n ll ans = 0;\n FOR(len, -minx, a-b+1) {\n FOR(val, -minx, 4005) {\n ans += (ll)dp[len][val] * (ll)dp[a-b-len][val+k];\n ans %= MOD;\n }\n }\n cout << ans << endl;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst long long mod = 1000000007;\nconst int N = 2005;\nint n, m, t, i, j, k, an, tmp, mi;\nint dp[N][2 * N][2];\nchar s[N];\nint main() {\n scanf(\"%d%d\", &n, &m);\n scanf(\"%s\", s + 1);\n t = n - m;\n mi = mod;\n tmp = 0;\n for (int i = 1; i <= m; i++) {\n if (s[i] == '(')\n tmp++;\n else\n tmp--;\n mi = min(mi, tmp);\n }\n dp[0][0][0] = 1;\n for (int i = 0; i <= t; i++)\n for (int j = 0; j <= t + t; j++)\n for (int k = 0; k <= 1; k++) {\n if (j + 1 <= t + t)\n dp[i + 1][j + 1][k] = (dp[i + 1][j + 1][k] + dp[i][j][k]) % mod;\n if (j - 1 >= 0)\n dp[i + 1][j - 1][k] = (dp[i + 1][j - 1][k] + dp[i][j][k]) % mod;\n if (k == 0 && j + tmp <= t + t && j + tmp >= 0 && j >= -mi)\n dp[i][j + tmp][1] = (dp[i][j + tmp][1] + dp[i][j][k]) % mod;\n }\n printf(\"%d\\n\", dp[t][0][1]);\n return 0;\n}\n", "#include <bits/stdc++.h>\n#pragma comment(linker, \"/stack:225450978\")\n#pragma GCC optimize(\"Ofast\")\nusing namespace std;\nconst long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;\nconst long double Pi = 3.141592653589793116, EPS = 1e-9,\n Gold = ((1 + sqrt(5)) / 2);\nlong long keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};\nlong long keyCount = sizeof(keymod) / sizeof(long long);\ntemplate <class T>\nint getbit(T s, int i) {\n return (s >> i) & 1;\n}\ntemplate <class T>\nT onbit(T s, int i) {\n return s | (T(1) << i);\n}\ntemplate <class T>\nT offbit(T s, int i) {\n return s & (~(T(1) << i));\n}\ntemplate <class T>\nint cntbit(T s) {\n return __builtin_popcountll(s);\n}\nauto TimeStart = chrono::steady_clock::now();\nauto TimeEnd = chrono::steady_clock::now();\nvoid ControlIO(int argc, char* argv[]);\nvoid TimerStart();\nvoid TimerStop();\nvoid Exit();\nstring cppstr_infile = \"FILE.IN\";\nstring cppstr_outfile = \"FILE.OUT\";\nlong long n, m;\nstring s;\nvoid Input() { cin >> n >> m >> s; }\nvoid Solve() {\n long long Total = 0, Min = LINF, Max = -LINF;\n for (auto x : s) {\n if (x == '(')\n Total++;\n else\n Total--;\n Min = min(Min, Total);\n Max = max(Max, Total);\n }\n if (n == 100000 && m == 98000 && s[0] == '(')\n cout << Total << \" \" << Min << \" \" << Max << '\\n';\n vector<vector<vector<long long>>> dp(\n n - m + 1, vector<vector<long long>>(2011, vector<long long>(2, 0)));\n dp[0][1][0] = 1;\n if (Total >= 0 && Min >= 0) dp[0][Total][1]++;\n for (long long i = 0; i < n - m; i++) {\n for (long long j = 0; j < 2011; j++) {\n if (j < 2010) {\n dp[i + 1][j + 1][0] += dp[i][j][0];\n dp[i + 1][j + 1][0] %= Mod;\n }\n if (j > 0) {\n dp[i + 1][j - 1][0] += dp[i][j][0];\n dp[i + 1][j - 1][0] %= Mod;\n }\n if (j < 2010) {\n dp[i + 1][j + 1][1] += dp[i][j][1];\n dp[i + 1][j + 1][1] %= Mod;\n }\n if (j > 0) {\n dp[i + 1][j - 1][1] += dp[i][j][1];\n dp[i + 1][j - 1][1] %= Mod;\n }\n if (j + Min >= 0 && j + Total >= 0 && j + Total < 2011) {\n dp[i + 1][j + Total][1] += dp[i][j][0];\n dp[i + 1][j + Total][1] %= Mod;\n }\n }\n }\n cout << dp[n - m][0][1];\n}\nint main(int argc, char* argv[]) {\n ControlIO(argc, argv);\n ios_base::sync_with_stdio(0);\n cin.tie(NULL);\n Input();\n TimerStart();\n Solve();\n TimerStop();\n return 0;\n}\nvoid ControlIO(int argc, char* argv[]) {\n char* infile = new char[cppstr_infile.size() + 1];\n char* outfile = new char[cppstr_outfile.size() + 1];\n strcpy(infile, cppstr_infile.c_str());\n strcpy(outfile, cppstr_outfile.c_str());\n}\nvoid TimerStart() {}\nvoid TimerStop() {}\nvoid Exit() {\n TimerStop();\n exit(0);\n}\n" ]
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 6.66; const int MAX = 2000 + 200 + 20 + 2; const long long mod = 1e9 + 7; long long fact[MAXN]; long long ifact[MAXN]; long long inverse[MAXN]; long long dp[MAX][2 * MAX]; long long bpow(long long base, long long exp) { long long ans = 1; for (; exp; exp >>= 1, base = base * base % mod) if (exp & 1) (ans *= base) %= mod; return ans; } long long inv(long long x) { return bpow(x, mod - 2); } void init_fact() { fact[0] = 1; for (int i = 1; i < MAXN; i++) fact[i] = (fact[i - 1] * i) % mod; ifact[MAXN - 1] = inv(fact[MAXN - 1]); for (int i = MAXN - 2; i > -1; i--) fact[i] = (fact[i + 1] * (i + 1)) % mod; for (int i = 1; i < MAXN; i++) inverse[i] = inv(i); } long long C(int n, int r) { if (r > n) return 0; return (fact[n] * ifact[r] % mod) * ifact[n - r] % mod; } long long get_valids(int len) { return inv(len - 1) * C(len * 2, len) % mod; } int main() { ios::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int n, m; cin >> n >> m; string str; cin >> str; int out1 = 0, out2 = 0; init_fact(); for (int i = 0; i < m; i++) out1 += (str[i] == '(' ? 1 : (out1 ? -1 : 0)); for (int i = m - 1; i > -1; i--) out2 += (str[i] == ')' ? 1 : (out2 ? -1 : 0)); if (out1 + out2 > n - m) { cout << 0 << endl; return 0; } dp[0][0] = 1; for (int len = 0; len <= n - m; len++) for (int out = 0; out < 2 * MAX - 1; out++) dp[len + 1][out] = (dp[len + 1][out] + dp[len][out + 1] + (out > 0 ? dp[len][out - 1] : 0)) % mod; long long ans = 0; for (int l1 = 0; l1 <= n - m; l1++) for (int bet = 0; bet <= l1; bet++) (ans += (dp[l1][bet + out2] * dp[n - m - l1][bet + out1]) % mod) %= mod; cout << ans << endl; return 0; }
As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other strings! The sequence of round brackets is called valid if and only if: 1. the total number of opening brackets is equal to the total number of closing brackets; 2. for any prefix of the sequence, the number of opening brackets is greater or equal than the number of closing brackets. Gabi bought a string s of length m (m ≤ n) and want to complete it to obtain a valid sequence of brackets of length n. He is going to pick some strings p and q consisting of round brackets and merge them in a string p + s + q, that is add the string p at the beginning of the string s and string q at the end of the string s. Now he wonders, how many pairs of strings p and q exists, such that the string p + s + q is a valid sequence of round brackets. As this number may be pretty large, he wants to calculate it modulo 109 + 7. Input First line contains n and m (1 ≤ m ≤ n ≤ 100 000, n - m ≤ 2000) — the desired length of the string and the length of the string bought by Gabi, respectively. The second line contains string s of length m consisting of characters '(' and ')' only. Output Print the number of pairs of string p and q such that p + s + q is a valid sequence of round brackets modulo 109 + 7. Examples Input 4 1 ( Output 4 Input 4 4 (()) Output 1 Input 4 3 ((( Output 0 Note In the first sample there are four different valid pairs: 1. p = "(", q = "))" 2. p = "()", q = ")" 3. p = "", q = "())" 4. p = "", q = ")()" In the second sample the only way to obtain a desired string is choose empty p and q. In the third sample there is no way to get a valid sequence of brackets.
#include "testlib.h" using namespace std; int main(int argc, char *argv[]) { setName("compare ordered sequences of signed int%d numbers", 8 * int(sizeof(long long))); registerTestlibCmd(argc, argv); int n = 0; string firstElems; while (!ans.seekEof() && !ouf.seekEof()) { n++; long long j = ans.readLong(); long long p = ouf.readLong(); if (j != p) quitf(_wa, "%d%s numbers differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(), vtos(j).c_str(), vtos(p).c_str()); else if (n <= 5) { if (firstElems.length() > 0) firstElems += " "; firstElems += vtos(j); } } int extraInAnsCount = 0; while (!ans.seekEof()) { ans.readLong(); extraInAnsCount++; } int extraInOufCount = 0; while (!ouf.seekEof()) { ouf.readLong(); extraInOufCount++; } if (extraInAnsCount > 0) quitf(_wa, "Answer contains longer sequence [length = %d], but output contains %d elements", n + extraInAnsCount, n); if (extraInOufCount > 0) quitf(_wa, "Output contains longer sequence [length = %d], but answer contains %d elements", n + extraInOufCount, n); if (n <= 5) quitf(_ok, "%d number(s): \"%s\"", n, compress(firstElems).c_str()); else quitf(_ok, "%d numbers", n); }
[ { "input": "2 2\n()\n", "output": "1" }, { "input": "2 2\n)(\n", "output": "0" }, { "input": "1000 1000\n(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))\n", "output": "1" }, { "input": "1000 1000\n(())()()()(())()()(())()()()((()())())()(()(())()(((((()))())))(()()()))()(((())(()(()(((())))))()())())(()()())()(()()())()((((((())()))(())(())())()(()()))())()((()()(()(())))()())(()((())))()(()(()()()((()))())(())((())(()()(((()()())(((()()()(())(((())((())((((()))()(())(())))))()))())(((((())((()((()(((())))(())((())()((((()))))(((()))(()()(((((())(((()(()()()())(((((())(()))(((((()))())))()())((((()()()))((()())(()()()(()()(()(((((())))()())()))((())))(((((()((()()(()((()(((((())))((((()((()((()()())))()(()()))((()((()))()(((((()))(()()()))()()(()(()(()))())())((()(((()))(())))()))))()))()()())()))(()()((()())(()()))()(()()(()))(()((()()())())))))))))((()())()()(())))))(()))))))(())))((((()))((()((((((()))()()(((()())(()())))())))((()()((())())))()))((()))(()()()((()()())))())()))(())))(())(((((())))(()())()((((()())((()()((()(()((()((((()())((()(()()()))(()())()(())()((())))))()))))))()()))(()())))))(((((((((()()()()()(()())(((())()(())(())()))())))))))))))))))))))))))))))))))))\n", "output": "1" }, { "input": "1000 1000\n()())()())))(()(()()())))()()((()))(((()())(()))(()()))((((((((()))))()))))()()())()()(())())(())))()(())(()()((()(()()))(((()))((())((())())())))()()((((((())()(())))()(()(()()()()(((((()()())()))(()((((((((()))(()))()(((()())))())))()())())((()(()())()()(()(()))())())))()))((()(()(()(())(())(()((()()))))()()))))())(())((()()))))()(()()()(()(((()())((((()))(())))((((()())))(())(()()(()))))()())))))()(((()((()()()))))))(())()())())(()(())()))(())))(())))(((((((()((()(()))((()((())()))))()(()()((((()())(()()(()))())()((()(((()(())(()(()(()())()(())((()((((()(())())))(((()))(()))))(())(()())(()))((((()(()()(()))(((((())(())()))(((((()))()()(()())())()((()()()()()))())))(())()()))))))(()((())))))(()((()()(((()(()())))()((((())((()(((()(()()()((()()()((())()()()()(()(((()())))())())))(()))((()))(((()()))((())()()(())(()(()()(()(())(((((((((()))()(())(()())((((((()((()()))(((())()())))((()())()()()(())(()((())()((())))))))()(()(()))))()()))())))))))))()())))(())(()((())()))(((()()())()))(()\n", "output": "0" }, { "input": "3000 1000\n(()())((()()(((()))))(((())((()(()(())))()((((())())()())(((()))(()()))(((()()()()(((()())(()(())((()())()()))((()))()()(()))))))(()()))((((())()(()()))(((()())())((())((()))(()(()(())()((()()(((()())()())))))()()()))()(()((()))))())((()((((())))(((())(((()(())))))))()(())(()((()(())(()()(())((()(((())()())))))(()))()(((()(()))(())(()()()())()()())))(()()((((()())))((((()())))))((())))())))()))()(())))(()(())(())))(()())()((())((()(()()()())())())(()((()))()(())))()((()()()))((()))(((()()())))(()(()()(((())((()((())))))(()()))(()((()(()())())))((()()))(()()(()(((()()((()()()((()((()()(()()())(())))())((())()()))()()))())((())(())))(()((()()((())(()(()(()))(())()(()(()))(()())())))(())))(())()))()))(()((())())))((())((())()))()()()()(((()))(((((()()))()()))((((()()((())()))()))((())(((()()((((()((()())()())(())))))(()))))()((()))())()))())()()(()())()(())()()(()((()())())(((()))())()())()(()(()()(()()(())())))()()((()()(())(((())())((()(())()))(((()())(()()(()())(()(()))())()(()()))))))\n", "output": "33989961" }, { "input": "3000 1000\n))(()()()()())))))(()()((()(())())(((()(())())(((()))))()))()()()(())((()((()()())))))((())()((())(()))()))()()()((((((()()(()()((()()))))))(())))()((()())((((()(()((())()())(()(()()(())()((()))(())()()(()))(()(())(()()()(()))()(()))(()))())((()((()))((())(())()())(())()))()()))()()))(())()()((()()((((()))()())))(((()))()))()()())(())())((())))))()))())()(())((((()))()((((((()(()()))))(())))()))((()(()()())((()))()())(())(()(()(()((((())))))((()((()))()((()()(((()())(((((())(()))))()(()(()()(())())()(())()(()(())()))()())()(())))((()))))(())()()))((()(()(()))((((((())())((())(())())(())))((()(())()))((()))((()(()())((()((((((()()()()())((((())(())()()))(((())))))))((((((()(()))))((()))(((()())))())()(())))())(()((())()((()(())((())((())())((())())())(((())((()((()))()((()((()((()))))(())())((())))))(())(()()((())()())()))())()()))())))((())((()))(()(()((((()))((()()))())(()))(()())))))())())()))()((((())()())(((()(()())()(((((()(()((())()()(()))((((((())))(((((((()(()))(()()())))((((((\n", "output": "765095754" }, { "input": "1 1\n)\n", "output": "0" }, { "input": "1 1\n(\n", "output": "0" }, { "input": "5 3\n())\n", "output": "0" }, { "input": "5 3\n)))\n", "output": "0" }, { "input": "1000 1000\n()(())((()(()()()())()())(()(())))((())())((()))(()(()((((())))())))()(()())()((((((()))((())))()())))(()())((()(()()())))(((()((()(()))(()())))))((())(((()))()))((((((()((((())))(())()()()((()(()())()))()))))(((()()))((((((()()()))))(()))()()())))(()))(((()))()))(()(((((()))))()))(())((()(((()(((((()()())(())()))(((()()((()((()()())(((()))))(()())()()((((((())(()))(()()()()()))((()))())((()))())(((((()()(()(()())(((())(()(()())())(())())(()))())((()((()))()(()(())))())(()((()))((()))(())(((((())((()(())((()))))())))())(()()()))(()(((((((((((()())))((()(()))()())(()())(()((()))()(((()())(((())(((((()(()()(())())()))((()())((()()()()()())())())))((()()())((()(()())))))))()()((())()())((()(((((()((()))))())()((()()))())(())))(((())())(((()()))()(()))()()(())(((()((()((())))(((())))))))))(((()()())()))))(()()(()))((()()(((())(())))))))))))(()))((((((((())))((((()()))))()))))())(())))()()(()())(()))())(((((((((()()()((()(()))))(()()))(())())()))())))))))))))(()())())())(())))(((())))))))))\n", "output": "1" }, { "input": "1000 1000\n)))()(()())(()())())()))(()())(()()(((((()())())())))))(()())(()(()())))(())()))())(()()())())(()()))()))(())()(((()((()))()())()()(()))))()()(()()))((()((()((())())((((())(()()())((()))()(()())))((())))()()((((()))((()((()))()))))((()(()()(()()((())))(())((((()())())(()())(()(())((((()()(())(()())((()))(((()(((()(((()))))))(()((())))))((((()()(())((()()(()()((((()())(((())))()(((())))(((())()(())()()))(())())())()((())(((((()(()(()))()(()(()(()(()())()(()()()(((()))))))(()(()))))((())))()((()(())())))(()(())))())()())(()())((((()(()(()())(((()())))))()()()())))())(((((()))())()(())(())()()(()))((()))()()()(()(()()))))((()()()))((()()))(()))(())(())))()((())((())((()(((())()(()))())()()))((()))())()(())))())()())(((()((((()))))(()(())))())())))()((((())))()))()(((((()(()())(()()))((())))(())))()()(()())))())())(())(())))())(((((()()(())())(()(()())()()(()(()(((()))()(())((()())((()(((())(()()(()()())()())()(())()))()()()()()()))()(()))))(()((()()))(())(((())(())())()((()))()(((()())(((\n", "output": "0" }, { "input": "3000 1000\n()()()()()(()(()(()()())(((()())))()))((()()))()(())(()((()((()()()))(()()(()()()()))()(())(()(())()))(())())(()()((((())((()()(()()))))()(()))))(()()())())(((())())()(()()))()(((())((()())()()(()))())())()()(())(((()((((()))))))()(())(((()((()(()(()()))(()(((((())(()()()(()))((()(()((())())((()(((())))))()())(()))))(())(()))((()))))())))))(()()()))(()()(())()())(()))((()))()()()((((((((()()(())(()(()(())())()))(())((())))))(())()(((()(((((()(((((())))(((())()((())((()())(((()((()())(((((((()()))))())(()((()(()(())()())()()))(()))(()()((((()(())))))(()((())((()))(()))))())(())())()))()))((()())()()))())((())())()()(((()()()(((())()(())((((()))((((()))))))((((()))((())()))(()(()(())(()((()))()))))()((()()(((()(((())(((((()))((()((()(()())))()())))(()())(()((()))))))()(((()(((()))()))))))())()())((())()())(()())(()((()))))()(((()))(()()))((())()()))())(()((()()()((())())()))))(()())()()((()()))))(((())())()))((((((()(())))()))((()(()))()()(((())(()(((()())))))))))))()((()))))))))))))))))\n", "output": "33989961" }, { "input": "3000 1000\n))())))(((()(())()(()()))))()(((()(()))()(())(((()))((()()(())()())((())())(())(()))((((()(()))(())()))((()))))))(((()()))()()())()))(())(((()(())((()()()(())(())(((()(()(()()(()))(()(()()((((((())))(()))))((())))((()()(((((())()()((())(()))))()(((()(()(()(())()(())())((((())())))()()((())((((())(()()())()(()(()())()))((()(()())())(((((((()(())))(((()()())(())(())())))())(()((())(()((()(())))(()))((())())(())(()((((()))()()(())(((()())(())(())(()(()()((())(((((((()())()(())))((((()))(()(((())()()(((()()(()((((()()()())()((())))(()))())())))()()()(()))((()((((((()()))))))(())((()())())(()(()())(()))(())()))()()())(((()))()()(()((())))((()(()()())(()((())(((())()))())(()()((())())(())()()(((()((())(((())()(()))(()())))(())()()(()()())()))))()()())(())()(((((())))(())(()())))()())))()()((()()))()(())(())()))))))()())())))(((()()())))))())))))()((()())()(((())))((((()))((()()(()(((()()())))(())))))(()(((()(())()))()))(())((())(())((()(())(((()()(()))())((()(((())(())))))()())))())()()()(((\n", "output": "349338227" }, { "input": "5 3\n)()\n", "output": "0" }, { "input": "1000 1000\n()(()()())()()()()()(((())))(((((()))(()()(())()(())))((((()(((((()()()()())()()))))))))))()(())()()((()()((())()(()))))((())(((((((()(()))())(()()()(((())))))()())(()())((((()))()))))))(()(((((()))(()()(()((()(())()(()((()(()))()((()()(()))(())())((())()((((((()())())))))(()()))()((((())((()(()())(())()(()(()))()((()((())())()))())((()(()()))()))()))))()()))((())))))((()(()((((()())(()))()))))(())))()((()(()()))())))())(((()())))()(())((()()()()()))()((())()()(()))()(((()()((())()(())))))()((()())(((()())((((((()())(()))(())(()(()(()))()())())((())(())))()())))(())))()()()((((((())))())(())((((())()((()))(())))()))()()((((()(((()(())()((()(()((((()))))(()((((())))())))()))(()))(()()())()(()()((())())))()())((()))))())((()(()()((())()()()())())())())))((()))((()))()((()))()(()(()())())((()(())())()())()()()(()((()))())(((())(((())))))()()()((())(()()()()()(()(((()())()((()()()((())))))())))()()()((((()()(((())((((((()()())(())((()((()(()))))(((()))))(((((()()))(()))()())())))))))))))))\n", "output": "1" }, { "input": "1000 1000\n)))(()(())(()(()))))((((()()((((((()())()()(((()()))()())(()(()()))())((()(((((()(((((()))(()((()((()))())((())((()))(()()((())()((()()(()()))()()()))()()()(()(()()))(((()(())))))(((((()(()(()())))())(()(((()()()(()))()))()()()))())))()(()))))()(())(())(((())())()(((()))(()()(((()())()()))())((())))((())((((())))()(((())(((())()((((())))()())))(()))))()))((()))(()())((()))())())()))(()()()()(((()(((((())))((()))(())(()(())))()))))(())()(((((()()))(()))()(((())())))()))()()))((()))()())(((()(((())()))(()))))(()))())((()())(()))))))()()))(()()())()))))))()()()()()()()))()))(((((()))()())((()((())((())()))())(())(()))(())()())))()()))))((())())(((()()(((()))((())(())())))(((())))((()()(())(()())()(()()((((())(((()(())(())()()((()())(()(()()))))(((())()())(()(())(((((((()()((((()((((((()))()()())))()((((()(()((()((())()((())(())(())))()))((())()()))))()()(()))(())))(())((()))()()))()()(((()(()))(())())((((()))(()(()(()(((((())))(()()(()(()(()((()(()())()()))())((((())())))())()))(((()()())\n", "output": "0" }, { "input": "3000 1000\n()((())())()()()((()))()((()()(()(())()))((()((()))()))())()(())(()(()((()(())))(())())()((((())))()(()()((()()(()()))))(()(()(()))()()()(((((((())))()()))))())())((())))((())(((()((()())((())((()()()()(((())((()())())()(()()(((()()(())))())))(((()())))))((()())))()))((())(())(()()))(()))))())()(()((()()())()))(())((())()(()))()()()()()((()))()()()()((()))()((()()((())(()()((((())()()))))()()()(((())(()()))))()())())()((((()))()()(())))(())(()())(((()()))()())(()()()()(((()((()(()()))))(())((()(())())(())((()()()((()(())()()()()(((()))())()())())))))(())((((((((()()()()()(()()()))))()))()())())())))()()(((()))((((()(((((((()()())()(()()))(()(()))()()((()())(())()(()()((()()((())(())()))((()()))((())))())((()((())())(()((()(()((()))((())())))((((()()))()()(()()()))()(((())()()(())(()(())()(())()())()()(())(())(())))()()()())))()))(()((()))())()(())()(((())()((())()(((((()()())()()()(()))())))((()(((()))(())())))))))))((())())()())()())((())(())(()((((()))((())())))()())))()()))(()()))))\n", "output": "33989961" }, { "input": "3000 1000\n)()(()((()())))())())())))((()((())))()()(())())((()()))(((()())(()()(((((()((()))))(()())())())))()()()))(((()())(())))(()((()()(()((()(((()))))((())(()((())((()()(())))())))))))((())()(()()))(((((((()))))(()()((())(())))()))()))((())(((())(((((())())))(())()))((())())(()()()))()((()))))((((())(()(((((()((()))((((())(((()()(())()(()(())())))())))))(())()))))()()))()(()(()()))()))(())())()())())()()()((()((()((()())())()((()(((()(((()))(()((()))()))()((()(()))())())))())(())((()))())()(())))))()())(())(((())(()))))(())(((((((()(()((((())((()())()())))))()))))))()()(())(((()(()())(((()()))())))()()()()((()())))()))(())()(()(()))))(()))())())(()())()())))()()(()((((((())))))))))((()((())())(())(())())(())(()))))((((())()()(()())()()()(((((()()()()())((((()(()))())))((((((()(()))))))((()())(())()()((()())((()()()()(()()((())()(((((()(((()(())()()))()()()(()(())))))(())))((((((()(()(()())(()(()(()((())(())(()())()((()((()(()())(((())((())((()))))((((()()))((()(((()(((((((())(((()(()((()(()\n", "output": "289397158" } ]
https://codeforces.com/contest/629/hacks?verdictName=CHALLENGE_SUCCESSFUL&chosenProblemIndex=C
#include "testlib.h" #include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { registerValidation(argc, argv); int n = inf.readInt(1, 100000, "n"); inf.readSpace(); int m = inf.readInt(1, n, "m"); inf.readEoln(); ensuref(n - m <= 2000, "n - m must be ≤ 2000, but n=%d, m=%d", n, m); string s = inf.readLine("^[()]{" + to_string(m) + "}$", "s"); inf.readEof(); return 0; }
2,000
256
39_H
[ "#include <bits/stdc++.h>\nusing namespace std;\nconst int N = 105;\nint k;\nvoid out(int n, int k) {\n if (n == 0) return;\n out(n / k, k);\n cout << n % k;\n}\nint main() {\n cin >> k;\n for (int i = 1; i < k; i++) {\n for (int j = 1; j < k; j++) {\n int num = i * j;\n out(num, k);\n cout << \" \";\n }\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint n;\ninline int turn(int x) {\n int tot = 0, res = 0, w[10];\n while (x >= 1) w[++tot] = x % n, x /= n;\n for (int i = tot; i >= 1; i--) res = res * 10 + w[i];\n return res;\n}\nint main() {\n cin >> n;\n for (int i = 1; i < n; i++) {\n for (int j = 1; j < n; j++) cout << turn(i * j) << endl;\n puts(\"\");\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nchar s[20];\nint n;\nvoid make(int k, int b) {\n memset(s, 0, sizeof(s));\n int p = 0;\n while (k) {\n s[p++] = (k % b) + '0';\n k /= b;\n }\n for (int i = 0; i < p / 2; ++i) {\n swap(s[i], s[p - i - 1]);\n }\n}\nint main() {\n while (~scanf(\"%d\", &n)) {\n for (int i = 1; i < n; ++i) {\n for (int j = 1; j < n; ++j) {\n make(i * j, n);\n printf(\"%s%c\", s, j == (n - 1) ? '\\n' : ' ');\n }\n puts(\"\");\n }\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int k;\n cin >> k;\n for (int i = 1; i < k; ++i) {\n for (int j = 1; j < k; ++j) {\n if (i * j < k)\n cout << i * j << \" \";\n else {\n int tmp = 0;\n int cnt = 0;\n int t = i * j;\n while (t > 0) {\n tmp += pow(10, cnt++) * (t % k);\n t /= k;\n }\n cout << tmp << \" \";\n }\n cout << \"\\n\";\n }\n }\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\ninline void read(register int *n) {\n register char c;\n *n = 0;\n do {\n c = getchar();\n } while (c < '0' || c > '9');\n do {\n *n = c - '0' + *n * 10;\n c = getchar();\n } while (c >= '0' && c <= '9');\n}\nint main(int argv, char **argc) {\n int n;\n cin >> n;\n for (register int i = (1); i < (int)(n); ++i) {\n for (register int j = (1); j < (int)(n); ++j) {\n int x = i * j;\n string s;\n while (x) s += char(x % n + '0'), x /= n;\n reverse((s).begin(), (s).end());\n cout << s << \" \";\n }\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nvoid f(int x, int y) {\n vector<int> e;\n e.clear();\n while (x > 0) {\n e.push_back(x % y);\n x = x / y;\n }\n for (int i = e.size() - 1; i >= 0; i--) {\n cout << e[i];\n }\n}\nint main() {\n int k;\n cin >> k;\n for (int i = 1; i < k; i++) {\n cout << '\\n';\n for (int j = 1; j < k; j++) {\n f(i * j, k);\n cout << ' ';\n }\n }\n}\n" ]
#include <bits/stdc++.h> using namespace std; void bas(int number, int base) { int final[99]; double remainder; int i = 0; while (number != 0) { remainder = (number % base); final[i] = remainder; i++; number = number / base; } for (i--; i > -1; i--) { if (final[i] < 10) cout << final[i]; else cout << char(final[i] - 10 + 'a'); } } int main() { int base; cin >> base; int a[base][base], i, j; for (i = 1; i < base; i++) { for (j = 1; j < base; j++) { bas(i * j, base); if (j < base - 1) cout << " "; } cout << endl; } return 0; }
Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to learn the multiplication table. Unfortunately, in the second grade students learn only the multiplication table of decimals (and some students even learn it in the first grade). Help Petya make a multiplication table for numbers in the system of notations with the radix k. Input The first line contains a single integer k (2 ≤ k ≤ 10) — the radix of the system. Output Output the multiplication table for the system of notations with the radix k. The table must contain k - 1 rows and k - 1 columns. The element on the crossing of the i-th row and the j-th column is equal to the product of i and j in the system of notations with the radix k. Each line may have any number of spaces between the numbers (the extra spaces in the samples are put for clarity). Examples Input 10 Output 1 2 3 4 5 6 7 8 9 2 4 6 8 10 12 14 16 18 3 6 9 12 15 18 21 24 27 4 8 12 16 20 24 28 32 36 5 10 15 20 25 30 35 40 45 6 12 18 24 30 36 42 48 54 7 14 21 28 35 42 49 56 63 8 16 24 32 40 48 56 64 72 9 18 27 36 45 54 63 72 81 Input 3 Output 1 2 2 11
#include "testlib.h" using namespace std; int main(int argc, char *argv[]) { setName("compare sequences of tokens"); registerTestlibCmd(argc, argv); int n = 0; string j, p; while (!ans.seekEof() && !ouf.seekEof()) { n++; ans.readWordTo(j); ouf.readWordTo(p); if (j != p) quitf(_wa, "%d%s words differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(), compress(j).c_str(), compress(p).c_str()); } if (ans.seekEof() && ouf.seekEof()) { if (n == 1) quitf(_ok, "\"%s\"", compress(j).c_str()); else quitf(_ok, "%d tokens", n); } else { if (ans.seekEof()) quitf(_wa, "Participant output contains extra tokens"); else quitf(_wa, "Unexpected EOF in the participants output"); } }
[ { "input": "2\n", "output": "1\n" }, { "input": "3\n", "output": "1 2\n2 11\n" }, { "input": "5\n", "output": "1 2 3 4\n2 4 11 13\n3 11 14 22\n4 13 22 31\n" }, { "input": "7\n", "output": "1 2 3 4 5 6\n2 4 6 11 13 15\n3 6 12 15 21 24\n4 11 15 22 26 33\n5 13 21 26 34 42\n6 15 24 33 42 51\n" }, { "input": "10\n", "output": "1 2 3 4 5 6 7 8 9\n2 4 6 8 10 12 14 16 18\n3 6 9 12 15 18 21 24 27\n4 8 12 16 20 24 28 32 36\n5 10 15 20 25 30 35 40 45\n6 12 18 24 30 36 42 48 54\n7 14 21 28 35 42 49 56 63\n8 16 24 32 40 48 56 64 72\n9 18 27 36 45 54 63 72 81\n" }, { "input": "4\n", "output": "1 2 3\n2 10 12\n3 12 21\n" }, { "input": "6\n", "output": "1 2 3 4 5\n2 4 10 12 14\n3 10 13 20 23\n4 12 20 24 32\n5 14 23 32 41\n" }, { "input": "8\n", "output": "1 2 3 4 5 6 7\n2 4 6 10 12 14 16\n3 6 11 14 17 22 25\n4 10 14 20 24 30 34\n5 12 17 24 31 36 43\n6 14 22 30 36 44 52\n7 16 25 34 43 52 61\n" }, { "input": "9\n", "output": "1 2 3 4 5 6 7 8\n2 4 6 8 11 13 15 17\n3 6 10 13 16 20 23 26\n4 8 13 17 22 26 31 35\n5 11 16 22 27 33 38 44\n6 13 20 26 33 40 46 53\n7 15 23 31 38 46 54 62\n8 17 26 35 44 53 62 71\n" } ]
https://codeforces.com/contest/39/hacks?verdictName=CHALLENGE_SUCCESSFUL&chosenProblemIndex=H
#include "testlib.h" #include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { registerValidation(argc, argv); int k = inf.readInt(2, 10, "k"); inf.readEoln(); inf.readEof(); return 0; }
2,000
64
560_C
[ "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int ans = 0;\n int a[10], i, j;\n for (i = 1; i <= 6; i++) scanf(\"%d\", &a[i]);\n int ceng = a[2] + a[3];\n int t = a[1], d = a[1] + 1;\n for (i = 1; i <= ceng; i++) {\n ans += t;\n ans += d;\n if (i < a[2]) {\n if (i < a[6]) {\n t++;\n d++;\n } else if (i == a[6]) {\n t++;\n }\n } else if (i == a[2]) {\n t = d;\n d--;\n } else {\n if (i < a[6]) {\n t = d;\n d--;\n } else if (i == a[6]) {\n t = d;\n d--;\n } else {\n t--;\n d--;\n }\n }\n }\n printf(\"%d\\n\", ans);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int a[6], s1, s2, t, num = 0;\n for (int ii = 0; ii < 6; ++ii) {\n cin >> a[ii];\n }\n int i = 1;\n for (; i <= 6; ++i) {\n t = a[(i - 1) % 6];\n if (a[(i + 1) % 6] == t) {\n s2 = a[i % 6];\n s1 = t;\n break;\n }\n }\n if (i == 7) {\n cout << 6;\n return 0;\n }\n for (int ii = 0; ii < s1; ++ii) {\n num += 2 * s2 + 1;\n ++s2;\n }\n s2 = a[(i + 3) % 6];\n s1 = a[(i + 2) % 6];\n for (int ii = 0; ii < s1; ++ii) {\n num += 2 * s2 + 1;\n ++s2;\n }\n cout << num;\n return 0;\n}\n", "#include <bits/stdc++.h>\n#pragma comment(linker, \"/STACK:16777216\")\nusing namespace std;\nint main() {\n long long up, r1, r2, down, l1, l2;\n cin >> up >> r1 >> r2 >> down >> l1 >> l2;\n long long tot = 0;\n long long st = up * 2 + 1;\n tot = st;\n for (int i = 2; i <= r1; ++i) {\n st += 2;\n tot += st;\n }\n for (int i = 1; i <= r2; ++i) {\n tot += st;\n st -= 2;\n }\n cout << tot << endl;\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int a1, a2, a3, a4, a5, a6;\n scanf(\"%d %d %d %d %d %d\", &a1, &a2, &a3, &a4, &a5, &a6);\n if (a1 == a2) {\n printf(\"%d\\n\", a1 * a1 * 6);\n return 0;\n } else if (a1 > a2) {\n int t1 = a1 * a1;\n int yu = t1 - (2 * a1 - 1);\n int t2 = a2 * a2;\n printf(\"%d\\n\", 3 * t1 - 2 * yu + 3 * t2);\n return 0;\n } else if (a1 < a2) {\n int t1 = a2 * a2;\n int yu = t1 - (2 * a2 - 1);\n int t2 = a1 * a1;\n printf(\"%d\\n\", 3 * t1 - 2 * yu + 3 * t2);\n return 0;\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint maxx, x, a[10], ans;\nint main() {\n cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5];\n for (int i = 0; i < 6; i++)\n if (a[i] > maxx) {\n maxx = a[i];\n x = i;\n }\n ans = a[(x + 1) % 6] * a[(x + 1) % 6] + 2 * a[x] * a[(x + 1) % 6];\n ans += a[(x + 4) % 6] * a[(x + 4) % 6] + 2 * a[(x + 3) % 6] * a[(x + 4) % 6];\n cout << ans << endl;\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nvoid run() {\n int a, b, c, ans = 0;\n cin >> a >> b >> c >> a >> b >> c;\n int tt = a;\n for (int i = 1; i <= b; ++i) {\n ans += tt * 2 + 1;\n tt += 1;\n }\n tt -= 1;\n for (int i = 1; i <= c; ++i) {\n ans += tt * 2 + 1;\n tt -= 1;\n }\n printf(\"%d\", ans);\n return;\n}\nint main() {\n run();\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int input[6];\n for (int i = 0; i < 6; i++) cin >> input[i];\n int bigTriSide = input[0] + 2 * input[1];\n int bigTriCount = 0;\n for (int i = bigTriSide; i > 0; i--) {\n bigTriCount += (i * 2) - 1;\n }\n int lilTriSide = input[1];\n int lilTriCount = 0;\n for (int i = lilTriSide; i > 0; i--) lilTriCount += (i * 2) - 1;\n cout << bigTriCount - (3 * lilTriCount);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst long long mod = 1e9 + 7;\nint main() {\n cin.tie(0)->sync_with_stdio(0), cin.exceptions(cin.failbit);\n vector<int> v(6);\n int mn = INT_MAX, mx = -1;\n for (int i = 0; i < 6; ++i) {\n int x;\n cin >> x;\n mn = min(mn, x);\n mx = max(mx, x);\n }\n cout << (mx + 2 * mn) * (mx + 2 * mn) - 3 * mn * mn;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nvoid in(int &x) {\n char ch;\n int minus = 0;\n while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')\n ;\n if (ch == '-')\n minus = 1, x = 0;\n else\n x = ch - '0';\n while (ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - '0';\n if (minus) x = -x;\n}\nvoid out(int x) {\n char hc[30];\n int len, minus = 0;\n if (x < 0) minus = 1, x = -x;\n len = 0;\n hc[len++] = x % 10 + '0';\n while (x /= 10) hc[len++] = x % 10 + '0';\n if (minus) putchar('-');\n for (int i = len - 1; i >= 0; i--) putchar(hc[i]);\n}\nint c[10];\ninline int f(int x) {\n int w = x + x - 1;\n return (1 + w) * x / 2;\n}\nint main() {\n for (int i = 1; i <= 6; i++) in(c[i]);\n sort(c + 1, c + 1 + 6);\n int a = c[1], b = c[6];\n int ans = f(a + b + b) - 3 * f(b);\n printf(\"%d\\n\", ans);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int a, b;\n for (int i = 0; i < 3; ++i) scanf(\"%d%d\", &a, &b);\n int num = a * b * 2 * 2 + a * a + b * b;\n printf(\"%d\\n\", num);\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n vector<int> v;\n int x;\n long long int ans = 0;\n for (int i = 0; i < 6; i++) {\n scanf(\"%d\", &x);\n v.push_back(x);\n }\n int f = 1;\n while (f) {\n for (int i = 0; i < v.size(); i++) {\n ans += 1LL + (v[i] - 1LL) * 2LL;\n v[i]--;\n }\n for (int i = v.size() - 1; i >= 0; i--) {\n if (!v[i]) v.erase(v.begin() + i);\n }\n if (v.size() < 3) {\n f = 0;\n continue;\n }\n if (v.size() == 3) {\n int t = 1;\n for (int i = 0; i < 3; i++)\n if (v[i] > 1) t = 0;\n if (t) {\n ans++;\n f = 0;\n continue;\n } else {\n ans += 3LL;\n for (int i = 0; i < 3; i++) v[i] -= 2;\n v.push_back(1);\n v.push_back(1);\n v.push_back(1);\n }\n }\n }\n cout << ans << endl;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int ans = 0;\n int a[10], i, j;\n for (i = 1; i <= 6; i++) scanf(\"%d\", &a[i]);\n int ceng = a[2] + a[3];\n int t = a[1], d = a[1] + 1;\n for (i = 1; i <= ceng; i++) {\n ans += t;\n ans += d;\n if (i < a[2]) {\n t++;\n d++;\n } else if (i == a[2]) {\n t++;\n d--;\n } else {\n t--;\n d--;\n }\n }\n printf(\"%d\\n\", ans);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int a[12], b, c, in1, in2, ans = 0;\n for (int i = 0; i < 6; i++) {\n scanf(\"%d\", &a[i]);\n a[i + 6] = a[i];\n }\n for (int i = 0; i < 6; i++) {\n if (a[i] == a[(i + 4) % 6]) {\n b = a[i];\n in1 = i;\n in2 = (in1 + 1) % 6;\n break;\n }\n }\n if (in1 > in2) swap(in1, in2);\n ans = (a[in1] + a[(in1 + 5) % 6]) * (a[in1] + a[(in1 + 5) % 6]) -\n a[(in1 + 5) % 6] * a[(in1 + 5) % 6];\n ans += (a[in2] + a[(in2 + 1) % 6]) * (a[in2] + a[(in2 + 1) % 6]) -\n a[(in2 + 1) % 6] * a[(in2 + 1) % 6];\n printf(\"%d\", ans);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int ans = 0;\n int a[10], i, j;\n for (i = 1; i <= 6; i++) scanf(\"%d\", &a[i]);\n int ceng = a[2] + a[3];\n int t = a[1], d = a[1] + 1;\n for (i = 1; i <= ceng; i++) {\n ans += t;\n ans += d;\n if (i < a[2]) {\n if (i < a[6]) {\n t++;\n d++;\n } else if (i == a[6]) {\n t++;\n }\n } else if (i == a[2]) {\n t = d;\n d--;\n } else {\n t--;\n d--;\n }\n }\n printf(\"%d\\n\", ans);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst double eps = 1e-5;\nconst int inf = 0x3f3f3f3f;\nconst int maxn = 1e5 + 5;\nconst int mod = 1e9 + 7;\nint a[6];\nint ans[2005];\nint b[3];\nint solve(void) {\n int sum = a[0] + a[5];\n memset(ans, 0, sizeof(ans));\n ans[0] = a[0];\n int h = a[1] + a[2];\n b[1] = a[1], b[2] = a[5];\n for (int i = 1; i <= h - 1; i++) {\n ans[i] += ans[i - 1];\n if (i <= b[1] && i <= b[2])\n ans[i]++;\n else if (i > b[1] && i > b[2])\n ans[i]--;\n sum += 2 * ans[i];\n }\n return sum;\n}\nint main(void) {\n while (1) {\n for (int i = 0; i < 6; i++)\n if (scanf(\"%d\", &a[i]) != 1) return 0;\n printf(\"%d\\n\", solve());\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int ans = 0;\n int a[10], i, j;\n for (i = 1; i <= 6; i++) scanf(\"%d\", &a[i]);\n int ceng = a[2] + a[3];\n int t = a[1], d = a[1] + 1;\n for (i = 1; i <= ceng; i++) {\n ans += t;\n ans += d;\n if (i < a[2]) {\n if (i < a[6]) {\n t++;\n d++;\n } else if (i == a[6]) {\n t++;\n }\n } else if (i == a[2]) {\n if (i <= a[6]) {\n t = d;\n d--;\n } else {\n t = d;\n d--;\n }\n } else {\n if (i <= a[6]) {\n t = d;\n d--;\n } else {\n t--;\n d--;\n }\n }\n }\n printf(\"%d\\n\", ans);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int a[6], b, c, in1, in2, ans = 0;\n for (int i = 0; i < 6; i++) scanf(\"%d\", &a[i]);\n for (int i = 0; i < 6; i++) {\n if (a[i] == a[(i + 4) % 6]) {\n b = a[i];\n in1 = i;\n break;\n }\n }\n if (a[(in1 + 1) % 6] == a[(in1 + 3) % 6])\n in2 = (in1 + 1) % 6;\n else {\n in2 = (in1 + 5) % 6;\n }\n if (in1 > in2) swap(in1, in2);\n ans = (a[in1] + a[(in1 + 5) % 6]) * (a[in1] + a[(in1 + 5) % 6]) -\n (a[(in1 + 5) % 6]) * (a[(in1 + 5) % 6]);\n ans += (a[in2] + a[(in2 + 1) % 6]) * (a[in2] + a[(in2 + 1) % 6]) -\n (a[(in2 + 1) % 6]) * (a[(in2 + 1) % 6]);\n printf(\"%d\", ans);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int ans = 0;\n int a[10], i, j;\n for (i = 1; i <= 6; i++) scanf(\"%d\", &a[i]);\n int ceng = a[2] + a[3];\n int t = a[1], d = a[1] + 1;\n for (i = 1; i <= ceng; i++) {\n ans += t;\n ans += d;\n if (i < a[2]) {\n if (i < a[6]) {\n t++;\n d++;\n } else if (i == a[6]) {\n t++;\n }\n } else if (i == a[2]) {\n t = d;\n d--;\n } else {\n if (i < a[6]) {\n t = d;\n d--;\n } else {\n t--;\n d--;\n }\n }\n }\n printf(\"%d\\n\", ans);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int a1, a2, a3, a4, a5, a6, tri, total = 0;\n cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6;\n tri = a1 - 1;\n for (int i = 0; i <= a2; i++) {\n if (i <= a6) tri++;\n total += tri;\n }\n for (int i = a3 - 1; i > 0; i--) {\n tri--;\n total += tri;\n }\n tri = a4 - 1;\n for (int i = 0; i <= a5; i++) {\n if (i <= a3) tri++;\n total += tri;\n }\n for (int i = a6 - 1; i > 0; i--) {\n tri--;\n total += tri;\n }\n cout << total << endl;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int a[6], s1, s2, t, num = 0;\n for (int ii = 0; ii < 6; ++ii) {\n cin >> a[ii];\n }\n int i = 1;\n for (; i <= 6; ++i) {\n t = a[(i - 1) % 6];\n if (a[(i + 1) % 6] == t) {\n s2 = a[i % 6];\n s1 = t;\n break;\n }\n }\n for (int ii = 0; ii < s1; ++ii) {\n num += 2 * s2 + 1;\n ++s2;\n }\n s2 = a[(i + 3) % 6];\n s1 = a[(i + 2) % 6];\n for (int ii = 0; ii < s1; ++ii) {\n num += 2 * s2 + 1;\n ++s2;\n }\n cout << num;\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst long long int mod = 1e9 + 7;\nint32_t main() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n long long int a, b, c, d, e, f;\n cin >> a >> b >> c >> d >> e >> f;\n long long int x = b + a - 1;\n long long int first = 2 * (x * (x + 1) / 2 - ((a - 1) * (a) / 2)) + b;\n x = d + c - 1;\n long long int second = 2 * (x * (x + 1) / 2 - (d * (d - 1) / 2)) + c;\n cout << first + second << '\\n';\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int a, b;\n cin >> a >> b >> a >> b >> a >> b;\n int ans = a * a + 4 * a * b + b * b;\n cout << ans;\n return 0;\n}\n", "#include <bits/stdc++.h>\n#pragma comment(linker, \"/STACK:16777216\")\nusing namespace std;\nbool isUp(long long a1, long long a2, long long a3, long long a4, long long a5,\n long long a6) {\n return (a2 == a6 && a3 == a5);\n}\nint main() {\n long long up, r1, r2, down, l1, l2;\n long long a1, a2, a3, a4, a5, a6;\n cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6;\n if (isUp(a1, a2, a3, a4, a5, a6)) {\n up = a1;\n r1 = a2;\n r2 = a3;\n } else if (isUp(a2, a3, a4, a5, a6, a1)) {\n up = a2;\n r1 = a3;\n r2 = a4;\n } else if (isUp(a3, a4, a5, a6, a1, a2)) {\n up = a3;\n r1 = a4;\n r2 = a5;\n } else if (isUp(a4, a5, a6, a1, a2, a3)) {\n up = a4;\n r1 = a5;\n r2 = a6;\n } else if (isUp(a5, a6, a1, a2, a3, a4)) {\n up = a5;\n r1 = a6;\n r2 = a1;\n } else {\n up = a6;\n r1 = a1;\n r2 = a2;\n }\n long long tot = 0;\n long long st = up * 2 + 1;\n tot = st;\n for (int i = 2; i <= r1; ++i) {\n st += 2;\n tot += st;\n }\n for (int i = 1; i <= r2; ++i) {\n tot += st;\n st -= 2;\n }\n cout << tot << endl;\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int a1, a2, a3, a4, a5, a6, tri, total = 0;\n cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6;\n tri = a1 - 1;\n for (int i = 0; i <= a2; i++) {\n tri++;\n total += tri;\n }\n for (int i = a3 - 1; i > 0; i--) {\n tri--;\n total += tri;\n }\n tri = a4 - 1;\n for (int i = 0; i <= a5; i++) {\n tri++;\n total += tri;\n }\n for (int i = a6 - 1; i > 0; i--) {\n tri--;\n total += tri;\n }\n cout << total << endl;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint a[20];\nint d[2000];\nint d1, d2, d3, d4, d5;\nint main() {\n for (int i = 1; i <= 6; i++) {\n cin >> a[i];\n d[a[i]]++;\n }\n for (int i = 7; i <= 12; i++) a[i] = a[i - 6];\n if (d[a[1]] == 6) {\n cout << 6 * a[1] * a[1];\n return 0;\n }\n d1 = d2 = 0;\n for (int i = 1; i <= 6; i++) {\n if (d[a[i]] & 1 && !d1) d1 = i;\n if (d[a[i]] & 1 && d1 && a[d1] != a[i]) d2 = i;\n }\n if (d1 && d2) {\n if (a[d1] < a[d2]) swap(d1, d2);\n cout << 2 * (a[d1] + a[d1 + 1]) * (a[d1] + a[d1 + 1]) - (a[d1] * a[d1]) -\n (a[d2] * a[d2]);\n return 0;\n }\n int amax = 0;\n int pos;\n for (int i = 1; i <= 6; i++)\n if (a[i] > amax) {\n amax = a[i];\n pos = i;\n }\n cout << 2 * (amax + a[pos + 1]) * (amax + a[pos + 1]) - 2 * amax * amax;\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int N = 1e5 + 7;\nconst int M = 1e6 + 7;\nconst int lim = 1e8;\nconst int inf = 0x3f3f3f3f;\nint a[10];\nint main() {\n for (int i = 1; i <= 6; i++) scanf(\"%d\", &a[i]);\n int sum = (a[1] + a[2]) * (a[1] + a[2]) * 2;\n sum -= a[1] * a[1] + a[4] * a[4];\n printf(\"%d\\n\", sum);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint a[6];\nint main() {\n int sm = 0;\n for (int i = 0; i < 6; i++) cin >> a[i];\n for (int i = 0; i < a[1]; i++) {\n sm += (a[0] + i) * 2 + 1;\n }\n for (int i = 0; i < a[2]; i++) {\n sm += (a[3] + i) * 2 + 1;\n }\n cout << sm << endl;\n return 0;\n}\n", "#include <bits/stdc++.h>\n#pragma comment(linker, \"/STACK:16777216\")\nusing namespace std;\nbool isUp(long long a1, long long a2, long long a3, long long a4, long long a5,\n long long a6) {\n return (a1 + a2 - a3) == a4;\n}\nlong long counta(long long up, long long r1, long long r2) {\n long long tot = 0;\n long long st = up * 2 + 1;\n tot = st;\n for (int i = 2; i <= r1; ++i) {\n st += 2;\n tot += st;\n }\n for (int i = 1; i <= r2; ++i) {\n tot += st;\n st -= 2;\n }\n return tot;\n}\nint main() {\n long long up, r1, r2, down, l1, l2;\n long long a1, a2, a3, a4, a5, a6;\n cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6;\n long long tot = 0;\n if (isUp(a1, a2, a3, a4, a5, a6)) {\n up = a1;\n r1 = a2;\n r2 = a3;\n tot = counta(up, r1, r2);\n } else if (isUp(a2, a3, a4, a5, a6, a1)) {\n up = a2;\n r1 = a3;\n r2 = a4;\n tot = counta(up, r1, r2);\n } else if (isUp(a3, a4, a5, a6, a1, a2)) {\n up = a3;\n r1 = a4;\n r2 = a5;\n tot = counta(up, r1, r2);\n } else if (isUp(a4, a5, a6, a1, a2, a3)) {\n up = a4;\n r1 = a5;\n r2 = a6;\n tot = counta(up, r1, r2);\n } else if (isUp(a5, a6, a1, a2, a3, a4)) {\n up = a5;\n r1 = a6;\n r2 = a1;\n tot = counta(up, r1, r2);\n } else {\n up = a6;\n r1 = a1;\n r2 = a2;\n tot = counta(up, r1, r2);\n }\n cout << tot << endl;\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int ans = 0;\n int a[10], i, j;\n for (i = 1; i <= 6; i++) scanf(\"%d\", &a[i]);\n int ceng = a[2] + a[3];\n int t = a[1], d = a[1] + 1;\n for (i = 1; i <= ceng; i++) {\n ans += t;\n ans += d;\n if (i < a[2]) {\n if (i < a[6]) {\n t++;\n d++;\n } else if (i == a[6]) {\n t++;\n }\n } else if (i == a[2]) {\n if (i < a[6]) {\n t = d;\n }\n if (i == a[6]) {\n t = d;\n d--;\n } else {\n t = d;\n d--;\n }\n } else {\n if (i < a[6]) {\n t = d;\n } else {\n t = d;\n d--;\n }\n }\n }\n printf(\"%d\\n\", ans);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint fun(int a, int b) { return (3 * (a + a - 1) + 3 * (b + b - 1)); }\nint side[6];\nint main() {\n for (int i = 0; i < 6; i++) cin >> side[i];\n pair<int, int> p = make_pair(max(side[0], side[1]), min(side[0], side[1]));\n long long ans = 0;\n while (p.second > 0) {\n ans += fun(p.first, p.second);\n p.first = p.first - 1;\n p.second = p.second - 1;\n }\n ans += p.first * p.first;\n cout << ans << endl;\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst long long mod = 1e9 + 7;\ntemplate <class T>\nistream& operator>>(istream& in, vector<T>& v) {\n for (auto& x : v) {\n in >> x;\n }\n return in;\n}\ntemplate <class T, class U>\nistream& operator>>(istream& in, pair<T, U>& v) {\n in >> v.first >> v.second;\n return in;\n}\ntemplate <class T, class U>\nostream& operator<<(ostream& out, pair<T, U>& v) {\n out << v.first << \" \" << v.second;\n return out;\n}\ntemplate <class T, class U>\nvoid chkmax(T& a, U b) {\n a = max(a, (T)b);\n return;\n}\ntemplate <class T, class U>\nvoid chkmin(T& a, U b) {\n a = min(a, (T)b);\n return;\n}\nlong long ppow(long long x, long long s) {\n if (!s) return 1;\n if (!(s - 1)) return x % mod;\n if (s % 2) return (x * ppow(x, s - 1)) % mod;\n long long b = ppow(x, s / 2);\n return (b * b) % mod;\n}\nvector<int> zf(string s) {\n int n = int64_t(s.size());\n vector<int> z(n);\n for (int i = 1, l = 0, r = 0; i < n; i++) {\n if (i <= r) z[i] = min(r - i + 1, z[i - l]);\n while (i + z[i] < n && s[z[i]] == s[i + z[i]]) z[i]++;\n if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;\n }\n return z;\n}\nvector<int> pf(string p) {\n int n = int64_t(p.size());\n vector<int> pref_fun(n, 0);\n for (int i = 1; i < n; i++) {\n int j = pref_fun[i - 1];\n while (j > 0 && p[i] != p[j]) j = pref_fun[j - 1];\n if (p[i] == p[j]) j++;\n pref_fun[i] = j;\n }\n return pref_fun;\n}\nvector<vector<int> > mul(vector<vector<int> >& a, vector<vector<int> >& b) {\n int n = int64_t(a.size());\n vector<vector<int> > c(n, vector<int>(n, 0));\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n for (int k = 0; k < n; k++) {\n long long ga = a[i][k];\n ga *= b[k][j];\n ga %= mod;\n c[i][j] += ga;\n if (c[i][j] >= mod) {\n c[i][j] -= mod;\n }\n }\n }\n }\n return c;\n}\nvector<vector<int> > matrix_pow(vector<vector<int> > a, long long y) {\n int n = int64_t(a.size());\n vector<vector<int> > res(n, vector<int>(n, 0));\n for (int i = 0; i < n; i++) res[i][i] = 1;\n while (y) {\n if (y % 2 == 1) {\n res = mul(res, a);\n y--;\n } else {\n a = mul(a, a);\n y /= 2;\n }\n }\n return res;\n}\nlong long f(long long a, long long b) {\n long long s = a * 2 + 1;\n return s * b + b * (b - 1);\n}\nint main() {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n int n = 6;\n vector<int> a(6);\n cin >> a;\n cout << f(a[0], a[1]) + f(a[1], a[0]);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint a[10];\nint main() {\n int min = 10000;\n for (int i = 1; i <= 6; i++) {\n scanf(\"%d\", &a[i]);\n if (min > a[i]) min = a[i];\n }\n int k = 0;\n while (a[1] != a[3] && a[4] != a[6]) {\n for (int i = 0; i < 6; i++) a[i] = a[i + 1];\n a[6] = a[0];\n k++;\n if (k > 10) break;\n }\n if (k <= 10) {\n int ans = 0;\n ans += (2 * a[2] + a[1]) * a[1];\n ans += (2 * a[5] + a[4]) * a[4];\n printf(\"%d\\n\", ans);\n } else {\n while (a[1] != min) {\n for (int i = 0; i < 6; i++) a[i] = a[i + 1];\n a[6] = a[0];\n }\n int ans = 0;\n ans += (2 * a[2] + a[1]) * a[1];\n ans += (2 * a[5] + a[4]) * a[4];\n int t = a[3] - a[1];\n ans += ((a[1] + a[2]) * 2 - 1) * t;\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n vector<int> v;\n int x;\n long long int ans = 0;\n for (int i = 0; i < 6; i++) {\n scanf(\"%d\", &x);\n v.push_back(x);\n }\n int f = 1;\n while (v.size() == 6 && f) {\n for (int i = 0; i < v.size(); i++) {\n ans += 1LL + (v[i] - 1LL) * 2LL;\n v[i]--;\n }\n for (int i = v.size() - 1; i >= 0; i--) {\n if (!v[i]) v.erase(v.begin() + i);\n }\n if (v.size() < 3) {\n f = 0;\n continue;\n }\n while (v.size() == 4 && f) {\n ans += 2LL;\n for (int i = 0; i < 4; i++) v[i] -= 1;\n v.push_back(1);\n v.push_back(1);\n for (int i = v.size() - 1; i >= 0; i--) {\n if (!v[i]) v.erase(v.begin() + i);\n }\n if (v.size() < 3) {\n f = 0;\n continue;\n }\n }\n while (v.size() == 3 && f) {\n int t = 1;\n for (int i = 0; i < 3; i++)\n if (v[i] > 1) t = 0;\n if (t) {\n ans++;\n f = 0;\n continue;\n } else {\n ans += 3LL;\n for (int i = 0; i < 3; i++) v[i] -= 2;\n v.push_back(1);\n v.push_back(1);\n v.push_back(1);\n }\n for (int i = v.size() - 1; i >= 0; i--) {\n if (!v[i]) v.erase(v.begin() + i);\n }\n if (v.size() < 3) {\n f = 0;\n continue;\n }\n }\n }\n cout << ans << endl;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint a[20];\nint d[2000];\nint d1, d2, d3, d4, d5;\nint main() {\n for (int i = 1; i <= 6; i++) {\n cin >> a[i];\n d[a[i]]++;\n }\n for (int i = 7; i <= 12; i++) a[i] = a[i - 6];\n if (d[a[1]] == 6) {\n cout << 6 * a[1] * a[1];\n return 0;\n }\n d1 = d2 = 0;\n for (int i = 1; i <= 6; i++) {\n if (d[a[i]] & 1 && !d1) d1 = i;\n if (d[a[i]] & 1 && d1) d2 = i;\n }\n if (d1 && d2) {\n cout << 2 * (a[d1] + a[d1 + 1]) * (a[d1] + a[d1 + 1]) - (a[d1] * a[d1]) -\n (a[d2] * a[d2]);\n return 0;\n }\n int amax = 0;\n int pos;\n for (int i = 1; i <= 6; i++)\n if (a[i] > amax) {\n amax = a[i];\n pos = i;\n }\n cout << 2 * (amax + a[pos + 1]) * (amax + a[pos + 1]) - 2 * amax * amax;\n return 0;\n}\n", "#include <bits/stdc++.h>\nint a1, a2, a3, a4, a5, a6;\nint main() {\n scanf(\"%d %d %d %d %d %d\", &a1, &a2, &a3, &a4, &a5, &a6);\n printf(\"%d\\n\", (a1 * 2 + a2) * a2 + (a4 * 2 + a3) * a3);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int a, b, c, d, e, f;\n cin >> a >> b >> c >> d >> e >> f;\n cout << ((a + b) * (b + c)) * 2 - a * a - b * b;\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int inf = 2e9;\nconst long long INF = 4e17;\nconst int mod = 1e9 + 7;\nconst double eps = 1e-9;\ndouble get(double a, double b, double c) {\n double x = a / 2.;\n double y = c / 2.;\n return (a * (b + b + x + y)) / 2.;\n}\nint main() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n ;\n double a, b, c, d, e, f;\n cin >> a >> b >> c >> d >> e >> f;\n cout << (long long)((get(a, b, c) + get(d, e, f)) * 2);\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nlong long a[10];\nlong long s1, s2, s;\nint main() {\n s = s1 = s2 = 0;\n for (int i = 1; i <= 6; i++) cin >> a[i];\n s = a[1] * 2 + 1;\n s1 = s;\n for (int i = 1; i < a[2]; i++) {\n s1 = s1 + 2;\n s += s1;\n }\n s2 = s1 + 2;\n for (int i = 0; i < a[3]; i++) {\n s2 = s2 - 2;\n s += s2;\n }\n cout << s << endl;\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int INF = 1e9 + 7;\nconst int MOD = 1e9 + 7;\nconst int MAXN = 1e6 + 3;\nlong long gcd(long long a, long long b) {\n if (b == 0)\n return a;\n else\n return gcd(b, a % b);\n}\nlong long power(long long x, long long y) {\n long long res = 1;\n while (y > 0) {\n if (y & 1) res = res * x;\n y = y >> 1;\n x = x * x;\n }\n return res;\n}\nint main() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n long long a[7];\n long long mn = INF;\n for (long long i = 1; i <= (6); ++i) cin >> a[i], mn = min(mn, a[i]);\n long long p[1005];\n p[0] = 0;\n for (long long i = 1; i <= 1000; i++) {\n p[i] = 0;\n p[i] += p[i - 1];\n p[i] += (i + i - 1);\n }\n long long ans = 0;\n for (long long i = 1; i <= (6); ++i) {\n ans += p[a[i]] - p[a[i] - mn];\n a[i] -= mn;\n }\n for (long long i = 1; i <= (6); ++i) {\n if (a[i] > 0) {\n ans += (a[i] * a[i]);\n break;\n }\n }\n cout << ans << '\\n';\n return 0;\n}\n", "#include <bits/stdc++.h>\n#pragma comment(linker, \"/STACK:16777216\")\nusing namespace std;\nbool isUp(long long a1, long long a2, long long a3, long long a4, long long a5,\n long long a6) {\n return (a2 == a6 && a3 == a5);\n}\nlong long counta(long long up, long long r1, long long r2) {\n long long tot = 0;\n long long st = up * 2 + 1;\n tot = st;\n for (int i = 2; i <= r1; ++i) {\n st += 2;\n tot += st;\n }\n for (int i = 1; i <= r2; ++i) {\n tot += st;\n st -= 2;\n }\n return tot;\n}\nint main() {\n long long up, r1, r2, down, l1, l2;\n long long a1, a2, a3, a4, a5, a6;\n cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6;\n long long tot = 0;\n up = a1;\n r1 = a2;\n r2 = a3;\n tot = max(counta(up, r1, r2), tot);\n up = a2;\n r1 = a3;\n r2 = a4;\n tot = max(counta(up, r1, r2), tot);\n up = a3;\n r1 = a4;\n r2 = a5;\n tot = max(counta(up, r1, r2), tot);\n up = a4;\n r1 = a5;\n r2 = a6;\n tot = max(counta(up, r1, r2), tot);\n up = a5;\n r1 = a6;\n r2 = a1;\n tot = max(counta(up, r1, r2), tot);\n up = a6;\n r1 = a1;\n r2 = a2;\n tot = max(counta(up, r1, r2), tot);\n cout << tot << endl;\n return 0;\n}\n" ]
#include <bits/stdc++.h> using namespace std; int main() { int a1, a2, a3, a4, a5, a6; scanf("%d %d %d %d %d %d", &a1, &a2, &a3, &a4, &a5, &a6); int ans = 0; int len = a2 + a3; int shang = a1; int xia; for (int i = 1; i <= len; i++) { if (i <= a6 && i <= a2) { xia = shang + 1; ans += shang * 2 + 1; } else if (i > a6 && i <= a2) { xia = shang; ans += xia * 2; } else if (i <= a6 && i > a2) { xia = shang; ans += xia * 2; } else if (i > a6 && i > a2) { xia = shang - 1; ans += xia * 2 + 1; } shang = xia; } printf("%d\n", ans); return 0; }
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to <image>. Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it. He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles. Input The first and the single line of the input contains 6 space-separated integers a1, a2, a3, a4, a5 and a6 (1 ≤ ai ≤ 1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists. Output Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split. Examples Input 1 1 1 1 1 1 Output 6 Input 1 2 1 2 1 2 Output 13 Note This is what Gerald's hexagon looks like in the first sample: <image> And that's what it looks like in the second sample: <image>
#include "testlib.h" using namespace std; int main(int argc, char *argv[]) { setName("compare ordered sequences of signed int%d numbers", 8 * int(sizeof(long long))); registerTestlibCmd(argc, argv); int n = 0; string firstElems; while (!ans.seekEof() && !ouf.seekEof()) { n++; long long j = ans.readLong(); long long p = ouf.readLong(); if (j != p) quitf(_wa, "%d%s numbers differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(), vtos(j).c_str(), vtos(p).c_str()); else if (n <= 5) { if (firstElems.length() > 0) firstElems += " "; firstElems += vtos(j); } } int extraInAnsCount = 0; while (!ans.seekEof()) { ans.readLong(); extraInAnsCount++; } int extraInOufCount = 0; while (!ouf.seekEof()) { ouf.readLong(); extraInOufCount++; } if (extraInAnsCount > 0) quitf(_wa, "Answer contains longer sequence [length = %d], but output contains %d elements", n + extraInAnsCount, n); if (extraInOufCount > 0) quitf(_wa, "Output contains longer sequence [length = %d], but answer contains %d elements", n + extraInOufCount, n); if (n <= 5) quitf(_ok, "%d number(s): \"%s\"", n, compress(firstElems).c_str()); else quitf(_ok, "%d numbers", n); }
[ { "input": "1 1 1 1 1 1\n", "output": "6\n" }, { "input": "2 2 2 2 2 2\n", "output": "24\n" }, { "input": "2 1 2 1 2 1\n", "output": "13\n" }, { "input": "100 100 100 100 100 100\n", "output": "60000\n" }, { "input": "100 1 100 1 100 1\n", "output": "10401\n" }, { "input": "999 999 999 999 999 999\n", "output": "5988006\n" }, { "input": "999 1 999 1 999 1\n", "output": "1001998\n" }, { "input": "1000 1000 1000 1000 1000 1000\n", "output": "6000000\n" }, { "input": "1000 1 1000 1 1000 1\n", "output": "1004001\n" }, { "input": "3 1 3 1 3 1\n", "output": "22\n" }, { "input": "4 1 4 1 4 1\n", "output": "33\n" } ]
https://codeforces.com/contest/560/hacks?verdictName=CHALLENGE_SUCCESSFUL&chosenProblemIndex=C
#include "testlib.h" #include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { registerValidation(argc, argv); vector<int> a = inf.readInts(6, 1, 1000); inf.readEoln(); inf.readEof(); int a1 = a[0], a2 = a[1], a3 = a[2], a4 = a[3], a5 = a[4], a6 = a[5]; ensuref(2 * a1 + a2 + a6 == 2 * a4 + a3 + a5, "The given sides do not form a hexagon with all internal angles equal to 120 degrees (first condition failed)"); ensuref(a2 + a3 == a5 + a6, "The given sides do not form a hexagon with all internal angles equal to 120 degrees (second condition failed)"); return 0; }
2,000
256
630_A
[ "#include <bits/stdc++.h>\nusing namespace std;\ntemplate <class c>\nstruct rge {\n c b, e;\n};\ntemplate <class c>\nrge<c> range(c i, c j) {\n return rge<c>{i, j};\n}\ntemplate <class c>\nauto dud(c* x) -> decltype(cerr << *x, 0);\ntemplate <class c>\nchar dud(...);\nstruct debug {\n ~debug() { cerr << endl; }\n template <class c>\n typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {\n cerr << boolalpha << i;\n return *this;\n }\n template <class c>\n typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {\n return *this << range(begin(i), end(i));\n }\n template <class c, class b>\n debug& operator<<(pair<b, c> d) {\n return *this << \"(\" << d.first << \", \" << d.second << \")\";\n }\n template <class c>\n debug& operator<<(rge<c> d) {\n *this << \"[\";\n for (auto it = d.b; it != d.e; ++it) *this << \", \" + 2 * (it == d.b) << *it;\n return *this << \"]\";\n }\n};\ntemplate <typename... T>\nvoid read(T&... args) {\n ((cin >> args), ...);\n}\ntemplate <typename... T>\nvoid write(T... args) {\n ((cout << args << \" \"), ...);\n}\nvoid testcase() {\n long long int n;\n read(n);\n write(25);\n cout << endl;\n}\nint main() {\n testcase();\n return 0;\n}\n" ]
#include <bits/stdc++.h> void fast(); void file(); void error(); using namespace std; int main() { fast(); file(); long long int n; cin >> n; cout << 25 << endl; error(); return 0; } void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void file() {} void error() { cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; }
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of n and get last two digits of the number. Yes, of course, n can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions." Could you pass the interview in the machine vision company in IT City? Input The only line of the input contains a single integer n (2 ≤ n ≤ 2·1018) — the power in which you need to raise number 5. Output Output the last two digits of 5n without spaces between them. Examples Input 2 Output 25
#include "testlib.h" using namespace std; int main(int argc, char *argv[]) { setName("compare ordered sequences of signed int%d numbers", 8 * int(sizeof(long long))); registerTestlibCmd(argc, argv); int n = 0; string firstElems; while (!ans.seekEof() && !ouf.seekEof()) { n++; long long j = ans.readLong(); long long p = ouf.readLong(); if (j != p) quitf(_wa, "%d%s numbers differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(), vtos(j).c_str(), vtos(p).c_str()); else if (n <= 5) { if (firstElems.length() > 0) firstElems += " "; firstElems += vtos(j); } } int extraInAnsCount = 0; while (!ans.seekEof()) { ans.readLong(); extraInAnsCount++; } int extraInOufCount = 0; while (!ouf.seekEof()) { ouf.readLong(); extraInOufCount++; } if (extraInAnsCount > 0) quitf(_wa, "Answer contains longer sequence [length = %d], but output contains %d elements", n + extraInAnsCount, n); if (extraInOufCount > 0) quitf(_wa, "Output contains longer sequence [length = %d], but answer contains %d elements", n + extraInOufCount, n); if (n <= 5) quitf(_ok, "%d number(s): \"%s\"", n, compress(firstElems).c_str()); else quitf(_ok, "%d numbers", n); }
[ { "input": "383553517077296575\n", "output": "25\n" }, { "input": "2\n", "output": "25\n" }, { "input": "2000000000000000000\n", "output": "25\n" }, { "input": "3\n", "output": "25\n" }, { "input": "5\n", "output": "25\n" }, { "input": "10\n", "output": "25\n" }, { "input": "100\n", "output": "25\n" }, { "input": "999\n", "output": "25\n" }, { "input": "1000\n", "output": "25\n" }, { "input": "1000000000\n", "output": "25\n" }, { "input": "1000000000000000000\n", "output": "25\n" }, { "input": "818\n", "output": "25\n" }, { "input": "786606893961270840\n", "output": "25\n" }, { "input": "1999999999999999998\n", "output": "25\n" }, { "input": "1999999999999999999\n", "output": "25\n" }, { "input": "4\n", "output": "25\n" }, { "input": "6\n", "output": "25\n" }, { "input": "7\n", "output": "25\n" }, { "input": "8\n", "output": "25\n" }, { "input": "9\n", "output": "25\n" }, { "input": "1500000000000000000\n", "output": "25\n" }, { "input": "1800000000000000000\n", "output": "25\n" }, { "input": "1999999999999999997\n", "output": "25\n" }, { "input": "317\n", "output": "25\n" }, { "input": "227111501889357715\n", "output": "25\n" }, { "input": "1873026925331404131\n", "output": "25\n" }, { "input": "635\n", "output": "25\n" }, { "input": "227937745067441139\n", "output": "25\n" }, { "input": "1873853168509487555\n", "output": "25\n" } ]
https://codeforces.com/contest/630/hacks?verdictName=CHALLENGE_SUCCESSFUL&chosenProblemIndex=A
#include "testlib.h" #include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { registerValidation(argc, argv); long long n = inf.readLong(2LL, 2000000000000000000LL, "n"); inf.readEoln(); inf.readEof(); return 0; }
500
64
1419_B
[ "#include <bits/stdc++.h>\nusing namespace std;\nint32_t main() {\n long long t;\n cin >> t;\n while (t--) {\n long long n;\n cin >> n;\n long long ans = 1;\n set<long long> s;\n while (pow(2, ans) * (pow(2, ans) - 1) <= 2 * n) {\n n -= (pow(2, ans) * (pow(2, ans) - 1)) / 2;\n ans++;\n }\n cout << ans - 1 << '\\n';\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint t, n;\nint ctoi(char i) {\n int integernum = i - '0';\n return (int)integernum;\n}\nlong int testCase() {\n long long int x;\n cin >> x;\n long int result = 0;\n long long int nicecells = 1;\n long long int power = 0;\n while (true) {\n if (nicecells <= x) {\n result++;\n x -= nicecells;\n } else {\n break;\n }\n power++;\n nicecells = (pow(2, power) * pow(2, power)) + nicecells + nicecells;\n }\n return result;\n}\nsigned main() {\n cin >> t;\n while (t-- > 0) {\n long int res = testCase();\n cout << res;\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int x;\n cin >> x;\n while (x--) {\n long long n;\n cin >> n;\n unsigned long long f = 0;\n int i = 0;\n while (n > 0) {\n f += pow(2, i);\n n -= (f * pow(2, i));\n if (n < 0) break;\n i++;\n }\n cout << i << endl;\n }\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int t;\n cin >> t;\n while (t--) {\n double n;\n cin >> n;\n long long int i = 0, count = 0;\n while (true) {\n long long int k = pow(2, i);\n k = k * 2 - 1;\n long long int sum = k * (k + 1) / 2;\n if (n >= sum) {\n n = n - sum;\n i = i + 1;\n } else\n break;\n }\n cout << i << endl;\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nlong long a[35];\nlong long t;\nlong long x;\nint main() {\n for (int i = 1; i <= 31; i++) {\n a[i] = (pow(4, i) - 1) / 3 * 2 - pow(2, i) + 1;\n }\n cin >> t;\n for (int ii = 1; ii <= t; ii++) {\n cin >> x;\n int i = 1;\n for (; a[i] <= x; i++) {\n }\n cout << i - 1 << endl;\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst long long MOD = 1000000007;\nint main() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n ;\n long long t = 1;\n cin >> t;\n while (t--) {\n long long n;\n cin >> n;\n long long i = 1, c = 1;\n while (n > 0) {\n c++;\n n -= (pow(2, c) - 1) * pow(2, c - 1);\n }\n cout << (c - 1) << \"\\n\";\n ;\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n ios::sync_with_stdio(false);\n cin.tie(0);\n int t;\n cin >> t;\n for (int q = 1; q <= t; q++) {\n long long n, k = 1;\n cin >> n;\n int ans = 0;\n while (((pow(2, k) - 1) * (pow(2, k) / 2)) <= n) {\n ans++;\n n -= (pow(2, k) - 1) * (pow(2, k) / 2);\n k++;\n }\n cout << ans << endl;\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst long double pi = acos(-1);\nconst long long int mod = 1000000007;\nconst double epsilon = 1e-9;\ntemplate <class T>\nostream &operator<<(ostream &out, vector<T> &A) {\n for (auto x : A) out << x << \" \";\n return out;\n}\ntemplate <class T>\nostream &operator<<(ostream &out, set<T> &A) {\n for (auto x : A) out << x << \" \";\n return out;\n}\ntemplate <class T>\nostream &operator<<(ostream &out, unordered_set<T> &A) {\n for (auto x : A) out << x << \" \";\n return out;\n}\ntemplate <class T1, class T2>\nT1 powr(T1 a, T2 b) {\n T1 res = 1;\n for (long long int i = 1; i < b + 1; i++) res = res * a;\n return res;\n}\nlong long int binpow(long long int a, long long int b) {\n a = a % mod;\n long long int res = 1;\n while (b > 0) {\n if (b & 1) res = (res * a) % mod;\n a = (a * a) % mod;\n b >>= 1;\n }\n return (res + mod) % mod;\n}\nconst long long int N = 10000025;\nlong long int prime[10000000];\nvoid SieveOfEratosthenes() {\n for (long long int i = 0; i < N; i++) prime[i] = 1;\n prime[0] = 0;\n prime[1] = 0;\n for (long long int p = 2; p * p <= 10000000; p++) {\n if (prime[p] == 1) {\n for (long long int i = p * p; i <= 10000000; i += p) prime[i] = 0;\n }\n }\n}\nint32_t main() {\n std::ios::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n ;\n long long int t;\n cin >> t;\n while (t--) {\n long long int n;\n cin >> n;\n long long int sum = 0, cnt = 0;\n for (long long int i = 1; i < 1000000; i++) {\n if (n - (pow(2, i - 1) * (pow(2, i) - 1)) >= 0) {\n n -= (pow(2, i - 1) * (pow(2, i) - 1));\n cnt++;\n } else {\n break;\n }\n }\n cout << cnt << \"\\n\";\n }\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint t, n;\nlong int testCase() {\n long long int x;\n cin >> x;\n long int result = 0;\n long long int nicecells = 1;\n long long int power = 0;\n while (true) {\n if (nicecells <= x) {\n result++;\n x -= nicecells;\n } else {\n break;\n }\n power++;\n nicecells = (pow(2, power) * pow(2, power)) + nicecells + nicecells;\n }\n return result;\n}\nsigned main() {\n cin >> t;\n while (t-- > 0) {\n long int res = testCase();\n cout << res;\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nvoid output() {\n long long x;\n cin >> x;\n long long p = 2, ans = 0;\n if (x - 1 >= 0) {\n ans++;\n x--;\n }\n while (x - (pow(2, p) - 1) * pow(2, p) / 2 >= 0) {\n x -= (pow(2, p) - 1) * pow(2, p) / 2;\n p++;\n ans++;\n }\n cout << ans << \"\\n\";\n}\nint main() {\n cin.tie(nullptr)->sync_with_stdio(false);\n int internalTests = 1;\n cin >> internalTests;\n while (internalTests--) output();\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nbool compareInterval(long long i1, long long i2) { return abs(i1) > abs(i2); }\nint main() {\n int t;\n cin >> t;\n while (t--) {\n long long x;\n cin >> x;\n long long result = 0;\n long long previous = 0;\n for (int i = 0; pow(4, i) + 2 * previous <= x; i++) {\n x -= pow(4, i) + 2 * previous;\n previous = pow(4, i) + 2 * previous;\n result++;\n }\n cout << result << endl;\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nlong long int f(int a) {\n return (((pow(4, a + 1) + 2) / 3) - pow(2, a + 1)) / 2;\n}\nint main() {\n int t;\n cin >> t;\n long long int aux = 1;\n long long int n;\n while (t > 0) {\n cin >> n;\n aux = 1;\n while (f(aux + 1) <= n) {\n aux++;\n }\n cout << aux << endl;\n t--;\n }\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int t;\n cin >> t;\n while (t--) {\n unsigned long long x;\n cin >> x;\n unsigned long long l = 1, r = 30;\n while (l < r) {\n unsigned long long m = (l + r + 1) / 2;\n unsigned long long tmp = 0;\n for (unsigned long long i = 1; i <= m; i++) {\n tmp += (pow(2, 2 * i - 1) - pow(2, i - 1));\n }\n if (tmp <= x)\n l = m;\n else\n r = m - 1;\n }\n cout << l << endl;\n }\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nbool compareInterval(long long i1, long long i2) { return abs(i1) > abs(i2); }\nint main() {\n int t;\n cin >> t;\n while (t--) {\n long long x;\n cin >> x;\n long long result = 0;\n long long previous = 0;\n while (x >= pow(4, result) + 2 * previous) {\n x -= pow(4, result) + 2 * previous;\n previous = pow(4, result) + 2 * previous;\n result++;\n }\n cout << result << endl;\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst long double eps = 1e-7;\nconst string alpha = \"abcdefghijklmnopqrstuvwxyz\";\nint d8x[8] = {+1, +1, +1, 0, 0, -1, -1, -1};\nint d8y[8] = {+1, 0, -1, +1, -1, +1, 0, -1};\nint d4x[4] = {1, 0, 0, -1};\nint d4y[4] = {0, -1, 1, 0};\nlong long power(long long x, long long y) {\n long long fk = 1;\n x = x;\n while (y > 0) {\n if (y & 1) fk = (fk * x);\n y = y >> 1;\n x = (x * x);\n }\n return fk;\n}\nlong long sqr(long long x) { return x * x; }\ntemplate <typename T>\nT gcd(T a, T b) {\n if (a == 0) return b;\n return gcd(b % a, a);\n}\ntemplate <class T>\ninline void chmax(T &x, T y) {\n x = max((x), (y));\n}\ntemplate <class T>\ninline void chmin(T &x, T y) {\n x = min((x), (y));\n}\ntemplate <class T>\nT abs(T x) {\n return x > 0 ? x : -x;\n}\ntemplate <typename T>\nT powm(T a, T b, long long m) {\n T cnt = 1;\n while (b > 0) {\n if (b % 2 == 1) cnt = (cnt * a) % m;\n b /= 2;\n a = (a * a) % m;\n }\n return cnt % m;\n}\nlong long ncr(long long n, long long r) {\n long long fk = 1;\n if (r > n) return 0;\n if (r > n - r) r = n - r;\n for (long long i = 0; i < r; i++) {\n fk *= (n - i);\n fk /= (i + 1);\n }\n return fk;\n}\nconst int MOD = 998244353;\nconst int N = 400000;\nvoid solve() {\n long long x;\n cin >> x;\n long long ans = 0;\n for (long long i = 1;; ++i) {\n long long now = (1LL << i) - 1LL;\n if (now > 1e10) break;\n now = now * (now + 1) / 2;\n if (log10(x) < log10(now)) break;\n ans++;\n x -= now;\n }\n cout << ans << \"\\n\";\n}\nint32_t main() {\n cin.sync_with_stdio(0);\n cin.tie(0);\n cin.exceptions(cin.failbit);\n int tc = 1;\n cin >> tc;\n for (int i = 1; i <= tc; ++i) {\n solve();\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nbool compareInterval(long long i1, long long i2) { return abs(i1) > abs(i2); }\nint main() {\n int t;\n cin >> t;\n while (t--) {\n unsigned long long x;\n cin >> x;\n unsigned long long result = 0;\n unsigned long long previous = 0;\n while (x >= pow(4, result) + 2 * previous) {\n x -= pow(4, result) + 2 * previous;\n previous = pow(4, result) + 2 * previous;\n result++;\n }\n cout << result << endl;\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int N = 110;\ndouble sum[N], a[N];\nint main() {\n int tot = 1;\n a[tot] = 1;\n sum[tot] = 1;\n while (1) {\n tot++;\n a[tot] = a[tot - 1] * 2 + 1;\n sum[tot] = sum[tot - 1] + (a[tot] * (a[tot] + 1) / 2);\n if (sum[tot] > 1e18) break;\n }\n int T;\n cin >> T;\n long long n;\n while (T--) {\n cin >> n;\n int ans = 0;\n for (int i = 1; i <= tot; i++) {\n if (sum[i] > n) {\n ans = i - 1;\n break;\n }\n }\n printf(\"%d\\n\", ans);\n }\n return 0;\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst long double pi = acos(-1);\nconst long long int mod = 1000000007;\nconst double epsilon = 1e-9;\ntemplate <class T>\nostream &operator<<(ostream &out, vector<T> &A) {\n for (auto x : A) out << x << \" \";\n return out;\n}\ntemplate <class T>\nostream &operator<<(ostream &out, set<T> &A) {\n for (auto x : A) out << x << \" \";\n return out;\n}\ntemplate <class T>\nostream &operator<<(ostream &out, unordered_set<T> &A) {\n for (auto x : A) out << x << \" \";\n return out;\n}\ntemplate <class T1, class T2>\nT1 powr(T1 a, T2 b) {\n T1 res = 1;\n for (long long int i = 1; i < b + 1; i++) res = res * a;\n return res;\n}\nlong long int binpow(long long int a, long long int b) {\n a = a % mod;\n long long int res = 1;\n while (b > 0) {\n if (b & 1) res = (res * a) % mod;\n a = (a * a) % mod;\n b >>= 1;\n }\n return (res + mod) % mod;\n}\nconst long long int N = 10000025;\nlong long int prime[10000000];\nvoid SieveOfEratosthenes() {\n for (long long int i = 0; i < N; i++) prime[i] = 1;\n prime[0] = 0;\n prime[1] = 0;\n for (long long int p = 2; p * p <= 10000000; p++) {\n if (prime[p] == 1) {\n for (long long int i = p * p; i <= 10000000; i += p) prime[i] = 0;\n }\n }\n}\nint32_t main() {\n std::ios::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n ;\n long long int t;\n cin >> t;\n while (t--) {\n long long int n;\n cin >> n;\n long long int sum = 0, cnt = 0;\n for (long long int i = 1; i < 1000; i++) {\n if (n - (pow(2, i - 1) * (pow(2, i) - 1)) >= 0) {\n n -= (pow(2, i - 1) * (pow(2, i) - 1));\n cnt++;\n } else {\n break;\n }\n }\n cout << cnt << \"\\n\";\n }\n}\n" ]
#include <bits/stdc++.h> using namespace std; long long min(long long a, long long b) { if (a < b) return a; else return b; } long long max(long long a, long long b) { if (a < b) return b; else return a; } long long min3(long long a, long long b, long long c) { return min(a, min(b, c)); } long long max3(long long a, long long b, long long c) { return max(a, max(b, c)); } long long ceil1(long long x, long long y) { if (x % y) return (x + y) / y; else return x / y; } long long NC = 100; long long N = 1e9 + 7; const long long second = 1e5 + 7; long long mod(long long n); long long gcd(long long a, long long b); long long modM(long long n, long long m); long long modA(long long n, long long m); long long modS(long long n, long long m); long long power(long long a, long long b); void ipgraph(long long n, long long m); vector<vector<long long>> v; vector<bool> vis; void solve() { long long n; cin >> n; long long ans = 0; for (long long i = 1; i < 100; i++) { long long x = pow(2, i) - 1; ans += x * (x + 1) / 2; if (ans > n) { cout << i - 1 << '\n'; return; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) solve(); cerr << endl << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; } void ipgraph(long long n, long long m) { v.assign(n, {}); vis.assign(n, 0); long long x, y; for (long long i = 0; i < m; i++) { cin >> x >> y; x--, y--; v[y].push_back(x); v[x].push_back(y); } } long long gcd(long long a, long long b) { if (b > a) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } long long power(long long a, long long b) { if (b == 0) return 1; long long c = power(a, b / 2); if (b % 2 == 0) return modM(c, c); else return modM(modM(c, c), a); } long long mod(long long n) { return (n % N + N) % N; } long long modM(long long n, long long m) { return ((n % N * m % N) + N) % N; } long long modA(long long n, long long m) { return ((n % N + m % N) + N) % N; } long long modS(long long n, long long m) { return ((n % N - m % N) + N) % N; }
Jett is tired after destroying the town and she wants to have a rest. She likes high places, that's why for having a rest she wants to get high and she decided to craft staircases. A staircase is a squared figure that consists of square cells. Each staircase consists of an arbitrary number of stairs. If a staircase has n stairs, then it is made of n columns, the first column is 1 cell high, the second column is 2 cells high, …, the n-th column if n cells high. The lowest cells of all stairs must be in the same row. A staircase with n stairs is called nice, if it may be covered by n disjoint squares made of cells. All squares should fully consist of cells of a staircase. This is how a nice covered staircase with 7 stairs looks like: <image> Find out the maximal number of different nice staircases, that can be built, using no more than x cells, in total. No cell can be used more than once. Input The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of each test case contains a single integer x (1 ≤ x ≤ 10^{18}) — the number of cells for building staircases. Output For each test case output a single integer — the number of different nice staircases, that can be built, using not more than x cells, in total. Example Input 4 1 8 6 1000000000000000000 Output 1 2 1 30 Note In the first test case, it is possible to build only one staircase, that consists of 1 stair. It's nice. That's why the answer is 1. In the second test case, it is possible to build two different nice staircases: one consists of 1 stair, and another consists of 3 stairs. This will cost 7 cells. In this case, there is one cell left, but it is not possible to use it for building any nice staircases, that have not been built yet. That's why the answer is 2. In the third test case, it is possible to build only one of two nice staircases: with 1 stair or with 3 stairs. In the first case, there will be 5 cells left, that may be used only to build a staircase with 2 stairs. This staircase is not nice, and Jett only builds nice staircases. That's why in this case the answer is 1. If Jett builds a staircase with 3 stairs, then there are no more cells left, so the answer is 1 again.
#include "testlib.h" using namespace std; int main(int argc, char *argv[]) { setName("compare ordered sequences of signed int%d numbers", 8 * int(sizeof(long long))); registerTestlibCmd(argc, argv); int n = 0; string firstElems; while (!ans.seekEof() && !ouf.seekEof()) { n++; long long j = ans.readLong(); long long p = ouf.readLong(); if (j != p) quitf(_wa, "%d%s numbers differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(), vtos(j).c_str(), vtos(p).c_str()); else if (n <= 5) { if (firstElems.length() > 0) firstElems += " "; firstElems += vtos(j); } } int extraInAnsCount = 0; while (!ans.seekEof()) { ans.readLong(); extraInAnsCount++; } int extraInOufCount = 0; while (!ouf.seekEof()) { ouf.readLong(); extraInOufCount++; } if (extraInAnsCount > 0) quitf(_wa, "Answer contains longer sequence [length = %d], but output contains %d elements", n + extraInAnsCount, n); if (extraInOufCount > 0) quitf(_wa, "Output contains longer sequence [length = %d], but answer contains %d elements", n + extraInOufCount, n); if (n <= 5) quitf(_ok, "%d number(s): \"%s\"", n, compress(firstElems).c_str()); else quitf(_ok, "%d numbers", n); }
[ { "input": "1\n77\n", "output": "3\n" }, { "input": "1\n1000000000000000000\n", "output": "30\n" }, { "input": "1\n1\n", "output": "1\n" }, { "input": "1\n383553517077296574\n", "output": "29\n" }, { "input": "1\n2\n", "output": "1\n" }, { "input": "1\n6\n", "output": "1\n" }, { "input": "1\n7\n", "output": "2\n" }, { "input": "1\n28\n", "output": "2\n" }, { "input": "1\n30\n", "output": "2\n" }, { "input": "1\n2932028910250\n", "output": "20\n" }, { "input": "1\n100\n", "output": "3\n" }, { "input": "1\n1000\n", "output": "5\n" }, { "input": "1\n22\n", "output": "2\n" }, { "input": "1\n10795\n", "output": "7\n" }, { "input": "1\n873026925331404130\n", "output": "30\n" }, { "input": "1\n46\n", "output": "3\n" }, { "input": "1\n873853168509487554\n", "output": "30\n" } ]
https://codeforces.com/contest/1419/hacks?verdictName=CHALLENGE_SUCCESSFUL&chosenProblemIndex=B
#include "testlib.h" #include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { registerValidation(argc, argv); int t = inf.readInt(1, 1000, "t"); inf.readEoln(); for (int i = 0; i < t; ++i) { long long x = inf.readLong(1LL, 1000000000000000000LL, "x"); inf.readEoln(); } inf.readEof(); return 0; }
1,000
256
1284_C
[ "#include <bits/stdc++.h>\nusing namespace std;\nconst int maxn = 250000;\nint dp[maxn];\nint main() {\n long long n, m;\n scanf(\"%lld %lld\", &n, &m);\n dp[0] = dp[1] = 1;\n for (long long i = 2; i <= n; i++) {\n dp[i] = ((dp[i - 1] % m) * (i % m)) % m;\n }\n long long sum = 0;\n for (long long i = 1; i <= n; i++) {\n sum += (((dp[i] % m) * (dp[n - i + 1] % m) % m) * ((n - i + 1) % m));\n }\n printf(\"%lld\\n\", sum % m);\n}\n", "#include <bits/stdc++.h>\nusing namespace std;\nconst int MAXN = 250005;\nusing lint = long long;\nusing pi = pair<int, int>;\nint n, mod;\nlint fact[MAXN];\nint main() {\n fact[0] = 1;\n cin >> n >> mod;\n for (int i = 1; i <= n; i++) {\n fact[i] = fact[i - 1] * i % mod;\n }\n lint ret = 0;\n for (int i = 1; i <= n; i++) {\n ret += (n - i + 1) * ((fact[i] % mod * fact[n - i + 1] % mod) % mod);\n }\n cout << ret % mod << endl;\n}\n" ]
#include <bits/stdc++.h> using namespace std; long long mod = 1000000000 + 7; long long exp(long long x, long long y) { x %= mod; long long res = 1; while (y) { if (y & 1) res = res * x % mod; x = x * x % mod; y >>= 1; } return res; } long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); } bool prime(long long n) { if (n < 2) return 0; for (int i = 2; i * i <= n; i++) if (n % i == 0) return 0; return 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; int T = 1; while (T--) { int n, m; cin >> n >> m; vector<long long> f(n + 1); f[0] = 1; for (long long i = 1; i <= n; i++) f[i] = f[i - 1] * i % m; long long ans = 0; for (long long i = 1; i <= n; i++) { ans += (n - i + 1) * (f[i] * f[n - i + 1] % m); ans %= m; } cout << ans; } }
Recall that the permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array). A sequence a is a subsegment of a sequence b if a can be obtained from b by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. We will denote the subsegments as [l, r], where l, r are two integers with 1 ≤ l ≤ r ≤ n. This indicates the subsegment where l-1 elements from the beginning and n-r elements from the end are deleted from the sequence. For a permutation p_1, p_2, …, p_n, we define a framed segment as a subsegment [l,r] where max\\{p_l, p_{l+1}, ..., p_r\} - min\\{p_l, p_{l+1}, ..., p_r\} = r - l. For example, for the permutation (6, 7, 1, 8, 5, 3, 2, 4) some of its framed segments are: [1, 2], [5, 8], [6, 7], [3, 3], [8, 8]. In particular, a subsegment [i,i] is always a framed segments for any i between 1 and n, inclusive. We define the happiness of a permutation p as the number of pairs (l, r) such that 1 ≤ l ≤ r ≤ n, and [l, r] is a framed segment. For example, the permutation [3, 1, 2] has happiness 5: all segments except [1, 2] are framed segments. Given integers n and m, Jongwon wants to compute the sum of happiness for all permutations of length n, modulo the prime number m. Note that there exist n! (factorial of n) different permutations of length n. Input The only line contains two integers n and m (1 ≤ n ≤ 250 000, 10^8 ≤ m ≤ 10^9, m is prime). Output Print r (0 ≤ r < m), the sum of happiness for all permutations of length n, modulo a prime number m. Examples Input 1 993244853 Output 1 Input 2 993244853 Output 6 Input 3 993244853 Output 32 Input 2019 993244853 Output 923958830 Input 2020 437122297 Output 265955509 Note For sample input n=3, let's consider all permutations of length 3: * [1, 2, 3], all subsegments are framed segment. Happiness is 6. * [1, 3, 2], all subsegments except [1, 2] are framed segment. Happiness is 5. * [2, 1, 3], all subsegments except [2, 3] are framed segment. Happiness is 5. * [2, 3, 1], all subsegments except [2, 3] are framed segment. Happiness is 5. * [3, 1, 2], all subsegments except [1, 2] are framed segment. Happiness is 5. * [3, 2, 1], all subsegments are framed segment. Happiness is 6. Thus, the sum of happiness is 6+5+5+5+5+6 = 32.
#include "testlib.h" using namespace std; int main(int argc, char *argv[]) { setName("compare ordered sequences of signed int%d numbers", 8 * int(sizeof(long long))); registerTestlibCmd(argc, argv); int n = 0; string firstElems; while (!ans.seekEof() && !ouf.seekEof()) { n++; long long j = ans.readLong(); long long p = ouf.readLong(); if (j != p) quitf(_wa, "%d%s numbers differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(), vtos(j).c_str(), vtos(p).c_str()); else if (n <= 5) { if (firstElems.length() > 0) firstElems += " "; firstElems += vtos(j); } } int extraInAnsCount = 0; while (!ans.seekEof()) { ans.readLong(); extraInAnsCount++; } int extraInOufCount = 0; while (!ouf.seekEof()) { ouf.readLong(); extraInOufCount++; } if (extraInAnsCount > 0) quitf(_wa, "Answer contains longer sequence [length = %d], but output contains %d elements", n + extraInAnsCount, n); if (extraInOufCount > 0) quitf(_wa, "Output contains longer sequence [length = %d], but answer contains %d elements", n + extraInOufCount, n); if (n <= 5) quitf(_ok, "%d number(s): \"%s\"", n, compress(firstElems).c_str()); else quitf(_ok, "%d numbers", n); }
[ { "input": "1 993244853\n", "output": "1\n" }, { "input": "2 993244853\n", "output": "6\n" }, { "input": "3 993244853\n", "output": "32\n" }, { "input": "5 993244853\n", "output": "1116\n" }, { "input": "10 993244853\n", "output": "52842240\n" }, { "input": "11 993244853\n", "output": "614200320\n" }, { "input": "12 993244853\n", "output": "818482189\n" }, { "input": "20 993244853\n", "output": "519582690\n" }, { "input": "100 993244853\n", "output": "338792878\n" }, { "input": "999 993244853\n", "output": "770930839\n" }, { "input": "1000 993244853\n", "output": "317321639\n" }, { "input": "2019 993244853\n", "output": "923958830\n" }, { "input": "2020 993244853\n", "output": "661444043\n" }, { "input": "2020 437122297\n", "output": "265955509\n" }, { "input": "9999 993244853\n", "output": "734051618\n" }, { "input": "10000 993244853\n", "output": "987177420\n" }, { "input": "50000 993244853\n", "output": "174689065\n" }, { "input": "99999 993244853\n", "output": "26970214\n" }, { "input": "100000 993244853\n", "output": "966385213\n" }, { "input": "249999 437122297\n", "output": "203375091\n" }, { "input": "250000 437122297\n", "output": "103130459\n" } ]
https://codeforces.com/contest/1284/hacks?verdictName=CHALLENGE_SUCCESSFUL&chosenProblemIndex=C
#include "testlib.h" #include <bits/stdc++.h> using namespace std; using ll = long long; // Modular multiplication ll mulmod(ll a, ll b, ll mod) { return (a * b) % mod; } // Modular exponentiation ll powmod(ll a, ll b, ll mod) { ll res = 1; a %= mod; while(b > 0) { if (b & 1) res = mulmod(res, a, mod); a = mulmod(a, a, mod); b >>= 1; } return res; } // Miller-Rabin primality test for integers up to 1e9 bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n%2 == 0) return false; int d = n -1; int s = 0; while (d % 2 == 0) { d /= 2; s++; } int bases[] = {2, 3, 5, 7, 11}; for (int a : bases) { if (a >= n) continue; ll x = powmod(a, d, n); if (x == 1 || x == n-1) continue; bool composite = true; for (int r = 1; r < s; ++r) { x = mulmod(x, x, n); if (x == n - 1) { composite = false; break; } } if (composite) return false; } return true; } int main(int argc, char* argv[]) { registerValidation(argc, argv); int n = inf.readInt(1, 250000, "n"); inf.readSpace(); int m = inf.readInt(100000000, 1000000000, "m"); inf.readEoln(); ensuref(isPrime(m), "m=%d is not a prime number", m); inf.readEof(); return 0; }
1,000
1,024
1220_B
["#include <bits/stdc++.h>\nusing namespace std;\nint n, a[1010][1010], g, ans[1010], x = 1, b[1010](...TRUNCATED)
"#include <bits/stdc++.h>\n#pragma comment(linker, \"/STACK:2000000\")\n#pragma comment(linker, \"/H(...TRUNCATED)
"Sasha grew up and went to first grade. To celebrate this event her mother bought her a multiplicati(...TRUNCATED)
"#include \"testlib.h\"\n#include <bits/stdc++.h>\nusing namespace std;\n\nint main(int argc, char* (...TRUNCATED)
[{"input":"3\n0 1 1\n1 0 1\n1 1 0\n","output":"1 1 1\n"},{"input":"3\n0 57300 8460\n57300 0 134655\n(...TRUNCATED)
https://codeforces.com/contest/1220/hacks?verdictName=CHALLENGE_SUCCESSFUL&chosenProblemIndex=B
"#include \"testlib.h\"\n#include <bits/stdc++.h>\nusing namespace std;\n\nint main(int argc, char* (...TRUNCATED)
2,000
256
233_C
["#include <bits/stdc++.h>\nusing namespace std;\nint n;\nint mp[110][110];\nint cal(int m) {\n int(...TRUNCATED)
"#include <bits/stdc++.h>\nusing namespace std;\nconst int inf = (1 << 30);\nconst int N = 100005;\n(...TRUNCATED)
"John Doe started thinking about graphs. After some thought he decided that he wants to paint an und(...TRUNCATED)
"#include \"testlib.h\"\n#include <bits/stdc++.h>\nusing namespace std;\n\nint main(int argc, char *(...TRUNCATED)
[{"input":"1\n","output":"100\n011111111111111111111111111111111111111111111111111111111111111111111(...TRUNCATED)
https://codeforces.com/contest/233/hacks?verdictName=CHALLENGE_SUCCESSFUL&chosenProblemIndex=C
"#include \"testlib.h\"\n#include <bits/stdc++.h>\nusing namespace std;\nint main(int argc, char* ar(...TRUNCATED)
1,000
256
450_E
["#include <bits/stdc++.h>\nint n, tot, ans[50010][2], ta, a[100000], totp, p[100010];\nbool bo[1000(...TRUNCATED)
"#include <bits/stdc++.h>\nint n, tot, ans[50010][2], totp, p[100010], tmp[100010];\nbool bo[100010](...TRUNCATED)
"Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he (...TRUNCATED)
"#include \"testlib.h\"\n#include <bits/stdc++.h>\nusing namespace std;\n\nstatic long long gcdLL(lo(...TRUNCATED)
[{"input":"1\n","output":"0\n"},{"input":"2\n","output":"0\n"},{"input":"3\n","output":"0\n"},{"inpu(...TRUNCATED)
https://codeforces.com/contest/450/hacks?verdictName=CHALLENGE_SUCCESSFUL&chosenProblemIndex=E
"#include \"testlib.h\"\n#include <bits/stdc++.h>\nusing namespace std;\nint main(int argc, char* ar(...TRUNCATED)
1,000
256
44_C
["#include <bits/stdc++.h>\nint a[110], b[110];\nusing namespace std;\nint main() {\n int n, m;\n (...TRUNCATED)
"#include <bits/stdc++.h>\nclass BIT {\n private:\n int n;\n int *t;\n inline int lowbit(int);\n\(...TRUNCATED)
"School holidays come in Berland. The holidays are going to continue for n days. The students of sch(...TRUNCATED)
"#include \"testlib.h\"\r\n\r\nusing namespace std;\r\n\r\nint main(int argc, char *argv[]) {\r\n (...TRUNCATED)
[{"input":"10 5\n1 2\n3 4\n5 6\n7 8\n9 10\n","output":"OK\n"},{"input":"10 5\n1 2\n3 4\n5 6\n8 8\n9 (...TRUNCATED)
https://codeforces.com/contest/44/hacks?verdictName=CHALLENGE_SUCCESSFUL&chosenProblemIndex=C
"#include \"testlib.h\"\n#include <bits/stdc++.h>\nusing namespace std;\n\nint main(int argc, char* (...TRUNCATED)
2,000
256
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
153