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... | #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(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((... | 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 <... | #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... | 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 ... | #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"
... | 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; }\... | #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",
"out... | 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 ... | #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\... | 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... | #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"
},
{
"in... | 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
- 65