QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#305914 | #6125. Lucky Stars Management | ckiseki | AC ✓ | 44ms | 12464kb | C++20 | 2.4kb | 2024-01-16 06:03:26 | 2024-01-16 06:03:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int modmul(int64_t a, int64_t b) {
return static_cast<int>(a * b % mod);
}
int modpow(int e, int p) {
int r = 1;
while (p) {
if (p & 1) r = modmul(r, e);
e = modmul(e, e);
p >>= 1;
}
return r;
}
int modpow(int64_t e, int p, int m) {
int64_t r = 1;
while (p) {
if (p & 1) r = r * e % m;
e = e * e % m;
p >>= 1;
}
return r;
}
signed main() {
cin.tie(nullptr) -> sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<int> P(N);
vector<vector<int>> G(N);
for (int i = 1; i < N; i++) {
cin >> P[i];
--P[i];
G[P[i]].emplace_back(i);
}
vector<int> E(N);
const int nk = modpow(N, K);
for (int i = 0; i < N; i++) {
cin >> E[i];
E[i] = modmul(E[i], nk);
}
for (int i = N - 1; i >= 1; i--) {
E[P[i]] = (E[P[i]] + E[i]) % mod;
}
const int mod2 = (mod - 1) / 2;
if (K == mod2) {
for (int i = 0; i < N; i++) {
if (E[i] != 0 && E[i] != 1 && E[i] != mod-1) {
cout << -1 << '\n';
return 0;
}
}
int x = 0;
int y = 0;
if (E[0] == 0) ;
else if (E[0] == 1) ++x;
else ++y;
for (int i: G[0]) {
if (E[i] == 0) ;
else if (E[i] == 1) ++y;
else ++x;
}
if (y == 0 && (x == 1 || x == 2)) {
cout << 1 << '\n';
} else if (y == 2 && x == 0) {
cout << 1 << '\n';
} else if (y == 1 && x == 0) {
int Z = 1;
while (modpow(Z, (mod - 1) / 2) == 1)
++Z;
cout << Z << '\n';
} else {
cout << 0 << '\n';
}
} else {
const int invK = modpow(K, mod2 - 2, mod - 1);
// cerr << "here " << invK * K % mod2 << endl;
// cerr << "===" << endl;
// for (int i = 0; i < N; i++) {
// cerr << modpow(E[i], invK) << endl;
// }
// cerr << "===" << endl;
int ans = modpow(E[0], invK);
for (int i: G[0]) {
ans = (ans - modpow(E[i], invK) + mod) % mod;
}
cout << ans << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3576kb
input:
2 1 1 2 1
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3876kb
input:
1 1 2
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 6ms
memory: 4904kb
input:
35224 611178003 1 2 1 4 4 4 6 7 4 2 8 1 7 7 10 1 15 9 8 19 4 11 1 1 1 21 18 1 29 13 22 14 28 2 34 15 29 32 36 15 23 15 15 30 19 2 27 36 42 7 12 41 47 19 8 48 22 58 47 46 33 60 62 55 65 25 39 37 64 65 51 5 62 32 52 54 23 47 71 48 12 57 66 14 21 67 51 48 63 4 61 6 40 91 79 76 75 51 83 22 22 65 30 2 99...
output:
382077724
result:
ok 1 number(s): "382077724"
Test #4:
score: 0
Accepted
time: 18ms
memory: 11016kb
input:
149791 34987949 1 1 2 4 5 1 6 8 4 9 7 10 11 14 15 16 17 18 10 19 15 15 21 19 8 7 24 28 11 29 31 32 21 15 33 3 32 36 35 10 39 42 8 29 13 43 47 48 49 44 50 40 8 52 55 56 43 50 31 57 61 62 1 43 63 11 66 68 69 50 70 68 72 74 75 22 76 78 79 54 80 82 83 72 84 54 1 86 7 89 20 78 91 94 59 95 97 98 99 100 10...
output:
49310952
result:
ok 1 number(s): "49310952"
Test #5:
score: 0
Accepted
time: 21ms
memory: 9568kb
input:
118590 920049643 1 1 2 1 4 6 1 7 7 10 9 1 4 10 13 10 17 18 17 10 19 22 15 22 25 23 26 28 17 29 3 26 19 31 2 14 4 35 39 40 41 37 18 42 20 45 27 9 46 1 30 47 44 29 47 27 53 26 58 1 60 62 14 51 6 28 63 68 43 69 71 10 27 2 72 76 77 76 78 50 81 40 79 25 81 50 80 54 14 5 88 91 92 94 95 96 97 93 17 62 36 2...
output:
657262978
result:
ok 1 number(s): "657262978"
Test #6:
score: 0
Accepted
time: 18ms
memory: 9820kb
input:
124407 288831131 1 2 2 3 5 6 5 3 7 10 6 1 2 11 15 1 17 3 16 20 14 18 21 23 18 17 13 24 29 30 31 6 17 32 35 36 37 17 22 38 41 2 42 44 34 15 45 25 39 49 12 45 48 28 54 56 57 33 58 60 22 61 63 64 65 22 66 68 25 1 69 72 31 65 32 47 4 73 79 30 80 82 83 84 85 58 86 36 88 90 37 91 88 89 17 93 97 31 56 98 7...
output:
948978942
result:
ok 1 number(s): "948978942"
Test #7:
score: 0
Accepted
time: 6ms
memory: 6840kb
input:
67899 312198691 1 1 1 2 1 6 7 5 2 7 11 12 13 13 15 16 16 18 19 20 12 21 23 15 24 10 6 26 29 30 31 32 33 34 32 16 24 5 35 40 41 28 15 32 42 46 47 47 49 50 46 51 46 47 53 56 38 23 56 19 11 58 11 55 57 60 1 40 53 67 71 61 72 1 74 76 64 77 27 79 49 19 81 84 34 85 46 76 87 90 83 91 93 41 94 96 9 77 84 97...
output:
402649812
result:
ok 1 number(s): "402649812"
Test #8:
score: 0
Accepted
time: 5ms
memory: 4976kb
input:
28006 754395459 1 2 3 3 5 6 7 8 5 6 9 12 13 3 14 1 4 16 3 19 13 21 23 21 19 24 4 27 9 29 16 31 33 8 18 34 2 27 34 28 37 35 42 44 45 46 47 48 49 17 50 52 29 53 37 32 55 58 53 59 61 23 62 64 65 66 67 6 68 70 50 5 40 1 71 76 77 5 26 30 78 82 32 78 83 86 87 72 66 47 88 92 50 93 95 32 96 98 99 34 17 7 28...
output:
460692207
result:
ok 1 number(s): "460692207"
Test #9:
score: 0
Accepted
time: 6ms
memory: 5704kb
input:
54784 500000003 1 1 1 2 1 1 7 3 6 4 2 6 8 12 6 9 13 9 12 8 7 12 11 8 10 24 17 14 8 19 15 27 32 6 30 24 29 37 21 29 26 5 32 2 13 9 35 12 40 45 47 2 19 34 32 10 57 55 7 58 8 26 4 10 60 38 52 65 30 23 70 65 46 11 31 40 40 22 41 50 61 44 57 10 35 61 19 15 87 64 50 49 2 34 95 12 37 9 6 58 8 33 21 64 73 6...
output:
-1
result:
ok 1 number(s): "-1"
Test #10:
score: 0
Accepted
time: 12ms
memory: 7540kb
input:
94773 500000003 1 2 2 4 2 4 1 7 5 4 11 4 1 5 5 11 5 10 1 8 20 9 1 5 20 22 21 1 15 15 20 19 15 20 24 17 27 6 23 32 28 34 42 12 37 19 38 3 19 6 51 1 34 24 16 32 10 20 20 21 30 30 5 22 62 2 57 63 2 61 16 59 11 64 3 19 30 52 48 5 70 6 52 78 41 62 66 86 88 84 10 30 41 13 91 12 70 16 32 2 51 81 6 15 95 88...
output:
-1
result:
ok 1 number(s): "-1"
Test #11:
score: 0
Accepted
time: 20ms
memory: 9696kb
input:
136836 500000003 1 2 2 3 2 6 6 5 2 1 4 7 12 7 5 11 13 5 18 2 5 7 5 23 18 18 26 22 7 11 18 8 5 20 27 6 33 31 39 10 27 33 22 2 28 24 37 4 49 48 23 4 31 24 38 50 1 56 26 16 8 36 14 32 47 8 35 9 36 25 69 71 17 33 40 45 41 22 43 13 74 75 35 43 2 7 45 3 60 35 61 82 7 94 26 40 34 10 96 92 63 3 80 73 68 88 ...
output:
-1
result:
ok 1 number(s): "-1"
Test #12:
score: 0
Accepted
time: 8ms
memory: 5440kb
input:
47519 500000003 1 2 2 2 2 4 6 8 3 8 5 8 5 4 5 4 11 17 6 8 6 8 7 24 12 19 17 7 26 22 29 32 14 20 17 1 22 26 15 26 35 23 38 37 34 18 18 39 46 20 36 8 19 31 37 33 10 32 44 51 41 51 11 25 27 56 17 53 66 62 13 26 34 69 44 70 61 12 63 19 62 20 63 11 32 83 12 70 46 27 81 51 75 69 88 68 1 18 99 89 12 62 52 ...
output:
0
result:
ok 1 number(s): "0"
Test #13:
score: 0
Accepted
time: 33ms
memory: 11652kb
input:
177506 500000003 1 1 3 2 4 3 5 5 3 10 5 2 5 7 6 9 4 11 10 1 19 20 7 3 7 4 18 15 13 28 24 5 7 27 2 7 28 26 29 20 37 33 11 41 27 15 35 37 47 7 14 25 13 9 9 41 32 7 36 46 30 1 62 59 62 16 67 62 65 64 48 55 70 24 1 32 12 4 60 49 58 15 34 17 61 37 58 52 38 22 60 57 39 40 87 6 10 27 40 88 97 54 13 60 9 60...
output:
-1
result:
ok 1 number(s): "-1"
Test #14:
score: 0
Accepted
time: 2ms
memory: 3996kb
input:
14826 98338421 1 2 1 3 3 5 2 1 3 7 11 7 13 12 14 12 15 17 9 2 1 12 15 11 13 14 17 6 18 6 8 15 2 12 21 12 9 33 33 24 33 36 12 29 27 34 24 38 23 24 29 11 49 26 46 48 30 42 34 16 32 18 60 64 65 66 46 59 60 45 59 63 29 42 22 35 62 40 39 65 72 67 65 84 79 76 53 40 27 63 66 47 88 80 10 44 93 2 25 96 14 8 ...
output:
324275948
result:
ok 1 number(s): "324275948"
Test #15:
score: 0
Accepted
time: 44ms
memory: 12020kb
input:
189479 500000003 1 2 3 2 3 2 6 3 5 9 4 6 5 8 8 16 7 5 19 19 7 2 23 8 14 6 11 2 28 6 9 3 2 13 2 8 30 25 11 29 3 2 27 23 12 43 23 13 8 28 26 5 25 8 48 6 37 16 32 27 56 39 42 15 21 39 15 7 58 10 44 59 54 46 7 49 50 10 78 38 14 18 80 8 83 34 2 24 17 90 37 91 68 37 68 94 83 97 78 70 72 80 102 65 39 65 3 ...
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 5ms
memory: 5272kb
input:
43242 500000003 1 2 2 3 3 2 5 5 3 2 2 5 11 11 4 11 14 8 7 14 2 18 19 23 3 22 15 26 7 19 14 19 27 17 28 36 33 22 18 32 15 20 40 41 5 33 46 6 2 49 46 3 5 27 40 21 7 35 56 35 26 18 49 23 37 12 48 65 45 30 63 70 7 5 73 52 49 65 56 39 27 71 60 9 61 17 46 76 32 17 68 33 65 58 58 44 55 81 66 48 15 69 33 99...
output:
0
result:
ok 1 number(s): "0"
Test #17:
score: 0
Accepted
time: 7ms
memory: 4976kb
input:
36798 500000003 1 2 3 4 5 3 2 7 4 6 10 9 8 3 5 7 5 12 16 16 6 8 3 15 19 4 26 12 6 11 6 10 32 33 22 14 24 10 7 34 24 8 7 6 6 10 21 30 26 20 44 9 24 49 29 34 16 35 51 45 60 20 61 36 61 6 61 22 43 13 51 7 19 61 13 3 65 17 2 46 10 79 45 49 10 12 72 85 37 59 48 54 89 84 5 23 45 41 59 81 57 27 14 14 42 88...
output:
1
result:
ok 1 number(s): "1"
Test #18:
score: 0
Accepted
time: 10ms
memory: 6788kb
input:
76001 500000003 1 2 3 4 3 4 3 2 8 8 2 7 8 8 7 8 3 6 12 6 8 5 17 5 23 3 15 19 14 10 10 29 33 20 17 7 23 12 5 21 5 13 27 12 45 10 39 6 18 18 44 23 42 36 12 49 20 17 26 2 59 29 8 13 49 47 47 62 31 29 53 39 46 20 5 55 33 75 79 65 6 56 76 16 65 75 38 77 49 64 35 10 7 9 7 66 51 34 33 13 13 64 34 38 71 78 ...
output:
0
result:
ok 1 number(s): "0"
Test #19:
score: 0
Accepted
time: 27ms
memory: 12084kb
input:
186738 500000003 1 2 2 4 3 6 3 7 6 9 10 4 12 13 8 2 7 15 17 6 7 4 2 4 12 7 9 24 27 27 20 12 27 26 20 15 35 21 23 15 22 24 8 10 16 31 3 42 38 40 16 40 4 40 31 45 32 38 18 40 53 2 26 25 16 58 39 62 68 24 60 57 8 25 19 29 53 5 28 65 74 8 11 31 6 16 36 38 76 49 3 89 36 3 92 7 27 18 11 73 63 4 58 51 79 9...
output:
1
result:
ok 1 number(s): "1"
Test #20:
score: 0
Accepted
time: 17ms
memory: 7980kb
input:
98820 500000003 1 2 3 4 3 6 7 2 4 9 9 7 7 13 5 6 2 18 17 16 13 14 4 23 7 5 24 25 28 3 11 8 27 25 2 32 23 34 24 7 12 5 26 17 36 9 38 27 8 8 44 32 18 13 33 35 55 2 28 19 22 10 40 25 40 27 54 22 23 58 71 24 14 70 34 31 52 59 54 8 18 53 41 18 84 7 86 3 71 6 60 76 80 20 46 34 39 13 59 52 101 47 89 87 65 ...
output:
5
result:
ok 1 number(s): "5"
Test #21:
score: 0
Accepted
time: 37ms
memory: 12464kb
input:
195899 500000003 1 2 3 2 2 5 5 7 9 10 1 2 13 5 4 8 6 18 3 6 2 20 22 22 2 9 17 2 14 21 11 4 29 32 21 12 27 16 16 16 26 13 42 35 12 11 20 28 46 44 11 32 16 15 42 56 47 8 49 60 19 45 18 30 4 37 19 7 57 44 67 65 72 42 27 38 5 77 15 34 72 81 59 74 50 61 69 11 26 44 67 5 75 76 82 36 56 20 23 99 60 69 63 7...
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 29ms
memory: 11252kb
input:
170001 500000003 1 2 2 3 4 1 5 3 2 8 2 11 11 12 13 7 12 14 12 14 13 7 12 5 10 21 2 22 10 15 23 13 18 8 3 36 34 14 36 40 40 27 10 15 36 38 35 28 43 30 10 52 15 17 27 45 35 43 17 50 26 9 50 26 33 49 48 4 66 8 60 10 30 30 22 32 13 76 71 79 73 42 52 24 65 81 68 40 24 57 16 32 35 87 2 9 38 75 31 24 32 10...
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 5ms
memory: 4712kb
input:
29613 500000003 1 1 2 3 4 2 3 3 2 6 6 10 7 6 12 7 15 7 19 19 11 18 19 4 12 5 2 13 24 24 15 18 24 2 8 18 28 17 31 25 31 32 14 14 17 35 6 39 31 29 6 28 22 53 37 8 7 19 37 39 13 53 14 34 33 50 57 46 21 27 65 24 52 18 64 20 52 43 46 57 12 76 61 43 78 30 4 29 73 86 31 43 53 94 41 59 15 73 56 28 7 100 91 ...
output:
1
result:
ok 1 number(s): "1"
Test #24:
score: 0
Accepted
time: 26ms
memory: 10080kb
input:
143688 500000003 1 2 1 4 3 1 6 8 9 3 7 10 6 9 7 11 3 18 2 5 7 13 17 10 22 12 11 24 26 24 26 32 13 11 4 36 26 17 11 17 20 41 20 3 10 46 24 48 40 9 14 52 29 50 18 17 29 42 44 55 22 32 45 5 39 32 6 19 24 43 26 26 18 29 42 2 72 71 64 47 31 38 39 29 60 35 34 42 15 9 79 24 49 66 17 15 21 66 60 98 52 9 100...
output:
0
result:
ok 1 number(s): "0"
Test #25:
score: 0
Accepted
time: 11ms
memory: 6068kb
input:
62382 636343333 1 2 3 4 5 1 5 1 8 5 9 4 4 12 8 16 13 5 8 5 17 13 1 22 25 3 6 25 19 2 10 2 18 31 25 28 26 37 29 9 24 7 3 9 32 14 17 44 28 50 41 20 27 33 54 25 37 23 35 38 27 38 15 44 4 36 21 42 14 28 35 37 16 9 62 62 12 45 9 53 20 3 38 55 54 16 6 78 79 6 49 92 76 43 71 36 65 31 5 40 1 10 14 77 69 5 2...
output:
425297290
result:
ok 1 number(s): "425297290"
Test #26:
score: 0
Accepted
time: 22ms
memory: 9944kb
input:
141318 500000003 1 1 3 2 4 6 7 5 6 3 9 8 9 4 4 11 14 11 17 6 19 17 2 11 17 21 24 12 13 27 26 13 14 2 18 36 22 34 16 27 10 14 10 30 39 22 26 21 29 31 4 51 25 12 7 30 2 25 31 5 16 35 2 62 4 46 7 43 9 12 34 62 26 71 22 63 55 58 8 53 67 10 65 76 10 7 85 72 72 34 23 66 38 54 50 10 48 73 59 10 48 22 10 48...
output:
0
result:
ok 1 number(s): "0"
Test #27:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
3220 500000003 1 2 1 4 5 5 2 4 3 5 10 4 9 10 2 5 10 10 13 17 14 8 11 13 16 14 20 5 10 2 31 12 8 28 24 25 34 15 27 25 25 6 3 27 27 39 26 9 48 5 51 22 12 32 42 38 33 3 39 38 6 21 9 7 42 53 62 67 10 43 60 60 50 8 25 26 53 51 63 20 23 32 15 23 46 29 39 67 61 86 37 43 73 67 12 86 13 95 80 57 46 65 75 104...
output:
0
result:
ok 1 number(s): "0"
Test #28:
score: 0
Accepted
time: 2ms
memory: 4148kb
input:
20297 500000003 1 2 1 3 3 3 7 5 2 4 10 5 5 5 14 13 16 7 3 4 19 20 3 10 10 22 7 9 26 24 18 26 29 18 7 36 24 5 2 39 18 34 18 36 19 43 46 5 21 12 16 29 3 16 16 34 48 23 44 11 39 40 10 55 42 10 12 38 41 3 48 66 72 18 64 42 44 15 69 34 79 13 16 12 81 80 61 28 3 4 56 67 29 69 50 65 43 43 17 25 60 84 101 1...
output:
0
result:
ok 1 number(s): "0"
Test #29:
score: 0
Accepted
time: 24ms
memory: 10188kb
input:
149510 500000003 1 1 2 3 3 3 4 2 2 10 8 12 9 10 15 10 14 8 15 8 3 15 21 21 17 18 3 8 16 15 27 3 10 15 16 8 20 27 27 8 18 30 6 2 23 4 12 9 33 2 23 3 34 52 8 22 35 54 56 12 11 53 12 43 12 3 29 49 46 45 58 35 44 65 54 76 37 47 42 57 66 33 81 31 28 86 66 87 45 37 23 50 53 12 21 24 95 4 57 80 82 51 39 96...
output:
0
result:
ok 1 number(s): "0"
Test #30:
score: 0
Accepted
time: 23ms
memory: 9740kb
input:
138659 500000003 1 1 3 3 3 2 2 5 4 7 6 11 11 7 13 9 7 2 14 20 12 7 18 16 8 24 14 8 22 29 19 16 28 14 23 5 27 38 6 12 41 40 43 32 9 18 26 4 25 4 40 48 37 14 38 51 50 6 5 46 30 2 57 2 19 35 13 43 50 66 66 68 37 12 12 64 7 64 47 29 19 38 59 25 63 79 57 68 43 54 3 58 51 58 31 55 55 47 29 48 97 59 27 77 ...
output:
1
result:
ok 1 number(s): "1"
Test #31:
score: 0
Accepted
time: 25ms
memory: 10060kb
input:
143838 500000003 1 2 2 3 1 6 7 5 9 1 6 7 11 6 15 3 17 6 14 12 2 18 14 15 22 24 18 5 17 3 31 21 7 32 20 25 16 29 34 34 15 10 32 35 37 5 38 5 42 16 40 29 5 40 53 8 52 29 2 55 47 15 45 64 18 1 7 39 25 65 34 2 26 32 9 44 63 73 73 69 59 33 54 77 32 16 69 3 30 72 56 87 2 50 49 36 81 85 42 79 2 101 15 40 2...
output:
0
result:
ok 1 number(s): "0"
Test #32:
score: 0
Accepted
time: 15ms
memory: 7444kb
input:
86168 500000003 1 2 1 4 3 5 3 3 3 7 5 1 1 3 3 5 9 10 7 10 17 3 12 11 2 3 26 24 9 19 16 2 21 23 29 1 34 33 10 31 30 5 32 32 9 43 43 28 33 18 26 31 24 21 12 54 47 20 30 23 53 59 23 4 58 21 33 34 45 4 4 30 68 37 73 35 37 19 13 43 66 10 67 55 34 59 86 84 15 50 25 61 45 70 80 74 64 35 48 56 53 3 71 14 34...
output:
0
result:
ok 1 number(s): "0"
Test #33:
score: 0
Accepted
time: 31ms
memory: 11592kb
input:
178785 500000003 1 1 2 4 5 2 3 2 7 1 10 11 9 3 9 2 13 6 10 1 9 17 3 23 12 12 18 26 29 8 21 26 10 2 24 36 37 30 11 22 40 32 18 23 8 42 1 27 6 23 30 28 14 39 41 17 10 41 51 30 33 25 25 7 7 31 35 44 48 40 44 56 26 18 6 72 8 32 10 50 5 25 8 77 45 53 53 30 62 85 68 53 93 80 83 3 49 66 23 77 22 71 49 30 5...
output:
0
result:
ok 1 number(s): "0"
Test #34:
score: 0
Accepted
time: 28ms
memory: 10956kb
input:
167636 500000003 1 1 2 3 1 5 5 6 6 8 10 11 7 4 11 13 10 14 10 20 19 5 1 15 6 2 20 28 26 15 21 6 26 34 15 28 27 38 19 4 1 37 6 29 6 26 14 7 5 47 44 35 8 45 29 48 35 14 59 45 60 7 51 58 38 64 41 2 69 17 56 50 5 23 30 58 10 34 28 66 80 24 19 36 20 78 25 11 76 38 22 42 26 56 65 79 74 42 9 36 25 39 2 25 ...
output:
0
result:
ok 1 number(s): "0"
Test #35:
score: 0
Accepted
time: 9ms
memory: 5676kb
input:
55013 500000003 1 2 3 3 5 4 5 6 4 3 4 11 1 7 7 13 7 7 11 10 6 21 23 15 8 6 27 27 2 8 7 26 18 30 22 5 9 6 14 29 27 10 22 44 7 39 27 48 2 19 2 48 36 18 49 32 29 7 59 29 12 17 29 7 58 34 55 19 6 18 49 46 34 71 8 66 34 69 24 62 29 27 12 34 68 62 66 72 20 7 83 18 82 69 35 92 10 10 34 61 93 32 70 69 52 51...
output:
0
result:
ok 1 number(s): "0"
Test #36:
score: 0
Accepted
time: 7ms
memory: 6076kb
input:
61880 425264299 1 1 1 1 1 4 5 5 1 4 9 9 6 5 13 6 4 9 7 1 21 9 9 7 6 10 10 21 28 24 31 24 6 22 25 33 16 12 16 31 18 6 36 20 1 19 37 46 20 49 33 13 27 28 39 19 28 29 11 15 20 17 53 6 11 6 60 36 67 69 61 44 19 26 9 53 26 57 36 24 46 56 76 42 82 72 26 42 13 8 91 30 36 75 79 31 16 43 23 38 59 4 6 46 90 1...
output:
278770112
result:
ok 1 number(s): "278770112"
Test #37:
score: 0
Accepted
time: 22ms
memory: 8924kb
input:
120222 500000003 1 2 1 1 1 4 4 5 2 2 11 4 8 13 13 10 11 10 15 17 3 19 20 7 24 19 10 18 6 12 29 10 29 33 6 35 27 14 17 7 24 20 39 8 4 15 27 16 21 20 49 44 21 48 42 18 2 31 18 56 26 27 32 14 28 44 49 27 41 8 33 16 18 40 9 58 76 42 30 80 72 50 17 43 36 63 69 72 73 6 89 18 48 65 74 61 23 54 66 20 56 8 4...
output:
0
result:
ok 1 number(s): "0"
Test #38:
score: 0
Accepted
time: 14ms
memory: 7800kb
input:
99884 500000003 1 1 2 3 2 1 1 3 8 10 7 11 3 8 6 2 5 16 11 2 16 8 6 19 24 22 20 11 19 12 26 2 21 19 12 30 36 7 20 9 31 35 9 12 23 39 28 14 12 27 46 30 38 27 27 27 10 23 55 49 13 59 31 52 12 66 33 49 8 20 53 5 70 66 40 7 11 19 55 73 11 22 2 70 67 17 73 49 58 59 55 43 40 79 50 66 14 97 20 30 92 16 16 1...
output:
0
result:
ok 1 number(s): "0"
Test #39:
score: 0
Accepted
time: 27ms
memory: 11060kb
input:
167623 500000003 1 2 1 4 2 1 3 1 3 6 4 4 5 8 3 8 8 15 10 9 12 5 13 9 15 23 25 20 7 7 4 5 22 12 4 34 13 31 20 34 7 5 19 20 16 2 40 20 32 34 20 44 25 6 52 39 34 18 19 10 23 59 34 19 20 62 42 67 16 35 16 15 63 11 42 76 76 31 69 68 66 52 37 54 52 32 56 86 50 24 28 72 46 32 83 40 7 21 12 72 64 85 32 63 5...
output:
0
result:
ok 1 number(s): "0"
Test #40:
score: 0
Accepted
time: 2ms
memory: 3832kb
input:
10108 500000003 1 2 2 1 4 1 4 4 3 5 11 4 4 7 10 4 10 5 14 20 9 7 8 6 17 18 5 9 3 30 12 13 14 28 31 33 6 3 10 27 6 16 6 14 33 18 14 6 5 38 43 38 26 48 18 19 12 40 39 56 28 39 21 8 23 62 39 8 44 41 28 38 34 66 49 51 24 69 54 75 37 56 39 36 48 12 55 46 57 15 68 36 65 85 5 48 39 47 27 71 62 61 93 103 24...
output:
0
result:
ok 1 number(s): "0"
Test #41:
score: 0
Accepted
time: 18ms
memory: 8152kb
input:
107097 500000003 1 2 2 1 1 6 4 8 3 6 3 8 7 12 2 8 10 4 11 8 9 19 21 7 22 18 13 24 17 26 3 2 25 6 25 2 7 15 9 38 33 8 5 39 44 36 19 46 28 49 31 39 9 45 10 16 45 49 26 58 18 53 33 4 6 35 59 45 39 67 67 2 48 2 65 28 60 63 64 32 73 58 13 73 45 79 84 65 52 6 2 75 39 73 13 14 60 15 43 90 88 72 25 64 84 7 ...
output:
0
result:
ok 1 number(s): "0"
Test #42:
score: 0
Accepted
time: 8ms
memory: 6560kb
input:
71272 500000003 1 2 3 3 4 1 6 1 4 7 9 5 3 10 5 3 2 6 3 8 10 12 11 24 14 23 22 9 14 24 9 31 9 23 1 33 33 4 13 33 16 42 3 20 23 8 30 43 42 19 25 11 1 16 13 27 10 35 36 11 14 31 53 52 57 1 61 1 40 28 30 23 39 18 69 54 70 12 40 20 50 11 52 3 41 19 26 4 42 50 76 26 87 53 24 32 54 53 25 11 68 82 72 91 14 ...
output:
0
result:
ok 1 number(s): "0"
Test #43:
score: 0
Accepted
time: 3ms
memory: 4288kb
input:
20025 500000003 1 2 2 2 4 6 6 6 6 5 11 5 9 6 3 12 12 18 5 12 12 5 12 5 21 9 5 23 9 7 28 6 9 15 5 12 10 7 28 35 25 8 41 37 28 8 9 9 45 24 25 39 52 40 23 49 11 39 3 33 11 5 8 8 50 66 57 13 2 7 44 38 31 46 53 3 59 68 25 46 43 67 22 26 78 80 62 45 73 8 25 55 9 72 25 71 66 53 98 20 60 7 62 80 49 78 82 41...
output:
0
result:
ok 1 number(s): "0"
Test #44:
score: 0
Accepted
time: 16ms
memory: 7616kb
input:
92236 500000003 1 1 2 1 5 1 6 1 7 9 8 3 13 9 5 11 3 16 16 17 10 16 10 23 9 8 24 17 22 28 16 27 29 6 2 22 22 20 38 1 27 4 22 31 9 32 21 11 23 34 48 52 45 9 14 49 10 21 6 15 53 22 39 21 59 29 17 1 53 12 60 7 45 46 38 25 15 2 22 77 31 35 2 26 80 57 39 52 46 7 61 57 18 83 71 83 75 48 78 11 15 90 50 81 7...
output:
0
result:
ok 1 number(s): "0"
Test #45:
score: 0
Accepted
time: 20ms
memory: 9992kb
input:
143698 500000003 1 2 3 1 2 1 4 3 1 4 6 1 12 11 13 9 1 1 8 17 12 9 3 22 17 20 7 18 27 7 22 28 12 1 14 2 34 37 17 2 15 2 30 28 19 15 25 25 20 11 39 43 19 26 25 20 29 38 18 53 40 21 54 9 43 1 51 8 5 27 65 19 53 70 58 28 29 65 45 8 41 10 1 71 27 63 86 43 87 60 44 67 31 50 63 37 64 48 19 48 95 31 9 77 41...
output:
0
result:
ok 1 number(s): "0"
Test #46:
score: 0
Accepted
time: 0ms
memory: 4308kb
input:
17535 500000003 1 1 3 1 5 4 2 5 7 8 8 2 10 11 2 12 2 5 9 5 9 19 17 3 6 1 8 8 11 2 27 8 14 30 6 25 21 25 27 23 20 9 14 33 20 31 44 33 36 18 48 49 2 19 44 26 25 52 46 37 23 44 34 36 13 39 9 14 8 68 22 8 2 56 31 46 69 74 8 8 44 54 35 52 74 50 80 26 62 81 63 9 17 22 5 96 78 55 60 15 14 41 34 11 61 9 33 ...
output:
0
result:
ok 1 number(s): "0"
Test #47:
score: 0
Accepted
time: 32ms
memory: 9864kb
input:
163291 274281999 1 2 1 2 1 2 1 2 1 2 3 1 1 13 14 2 1 6 2 1 2 1 9 2 1 2 2 1 1 1 1 2 1 17 2 1 2 1 1 2 40 16 1 1 1 1 1 2 1 2 22 1 2 1 2 1 1 41 2 1 6 1 48 1 1 1 1 5 1 1 17 1 56 1 54 1 2 2 1 1 1 1 1 1 1 49 2 1 63 1 1 2 2 1 1 1 1 1 1 61 1 1 1 1 1 1 1 1 1 1 1 2 1 1 26 1 1 1 2 2 1 1 21 1 98 61 7 82 2 107 1 ...
output:
955308244
result:
ok 1 number(s): "955308244"
Test #48:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
1 534225817 918795920
output:
718157430
result:
ok 1 number(s): "718157430"
Test #49:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1 881780635 248463332
output:
34928609
result:
ok 1 number(s): "34928609"
Test #50:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
1 500000003 0
output:
0
result:
ok 1 number(s): "0"
Test #51:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
1 500000003 1
output:
1
result:
ok 1 number(s): "1"
Test #52:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
1 500000003 1000000006
output:
5
result:
ok 1 number(s): "5"
Test #53:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
1 500000003 97001676
output:
-1
result:
ok 1 number(s): "-1"
Test #54:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
1 500000003 910868928
output:
-1
result:
ok 1 number(s): "-1"
Test #55:
score: 0
Accepted
time: 30ms
memory: 9080kb
input:
150425 86510939 1 1 1 1 1 1 7 1 7 10 1 7 1 7 1 1 1 10 19 7 1 21 1 7 1 1 17 20 1 1 7 1 14 11 7 1 1 1 1 1 7 28 1 7 39 1 1 1 7 1 1 1 48 1 1 1 2 7 1 7 1 1 1 1 1 1 1 1 1 1 7 1 1 1 1 1 7 1 1 1 1 7 7 4 7 1 1 20 1 7 1 7 48 1 78 1 81 6 1 1 90 21 1 1 1 105 7 1 1 1 1 1 7 1 1 1 65 1 1 1 1 1 1 1 32 95 7 1 54 1 1...
output:
205244275
result:
ok 1 number(s): "205244275"
Test #56:
score: 0
Accepted
time: 13ms
memory: 6520kb
input:
84892 698935573 1 1 1 4 1 1 1 4 4 1 4 1 10 1 10 4 2 4 1 1 1 1 1 1 23 19 1 1 1 1 1 27 4 4 1 36 1 1 1 1 1 18 1 20 1 1 1 1 4 1 32 50 1 26 1 1 29 1 1 4 1 1 1 1 11 30 63 4 1 54 1 1 59 1 1 1 1 4 1 9 4 44 1 47 27 1 4 1 1 1 63 1 1 1 1 14 1 1 1 27 1 98 1 4 1 4 4 104 4 67 1 1 102 1 1 1 4 1 1 1 14 4 4 4 4 1 11...
output:
669684609
result:
ok 1 number(s): "669684609"
Test #57:
score: 0
Accepted
time: 11ms
memory: 5708kb
input:
59431 135646773 1 1 1 4 1 1 1 1 4 4 5 1 1 1 4 13 1 11 16 20 16 19 1 1 1 1 1 25 4 1 1 4 4 1 23 19 1 4 4 1 1 1 1 4 43 11 1 25 1 4 27 1 1 1 19 6 4 4 13 22 1 4 1 1 1 4 5 44 1 1 26 4 1 4 75 1 4 4 1 1 1 26 4 28 84 1 1 65 4 1 38 1 4 1 4 4 1 1 1 1 1 63 1 1 1 4 1 1 1 1 1 4 4 64 1 1 4 1 1 1 1 1 4 102 1 105 4 ...
output:
454137741
result:
ok 1 number(s): "454137741"
Test #58:
score: 0
Accepted
time: 13ms
memory: 8032kb
input:
121376 400840637 1 1 1 1 5 5 5 1 4 3 5 5 12 1 5 5 1 1 1 1 5 1 8 1 4 11 5 19 1 5 5 10 4 1 5 26 33 5 5 5 1 5 25 1 5 15 1 1 1 5 1 2 1 1 1 1 28 49 1 1 1 5 5 23 1 19 8 1 5 1 5 1 5 1 72 1 54 1 5 5 1 1 36 81 29 23 1 1 1 71 1 1 75 1 1 5 93 13 1 1 5 48 5 5 1 80 87 1 1 25 11 46 1 1 43 5 5 1 5 1 115 1 5 124 15...
output:
119326791
result:
ok 1 number(s): "119326791"
Test #59:
score: 0
Accepted
time: 15ms
memory: 7892kb
input:
100991 955892129 1 1 2 4 4 3 4 6 4 9 3 5 3 13 2 9 5 10 4 3 11 16 18 4 12 14 11 20 21 30 7 31 29 34 17 4 36 1 6 26 41 1 40 32 22 16 47 21 46 5 13 37 15 16 52 10 52 35 29 6 6 21 57 63 14 39 38 16 43 70 27 71 37 57 12 50 41 74 31 38 24 25 24 5 79 85 34 61 9 12 87 17 20 5 11 90 70 88 51 91 68 36 67 104 ...
output:
952944103
result:
ok 1 number(s): "952944103"