QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#227120#7188. Aho-Corasick AutomatonPPP#TL 114ms64356kbC++172.9kb2023-10-26 22:44:032023-10-26 22:44:04

Judging History

你现在查看的是最新测评结果

  • [2023-10-26 22:44:04]
  • 评测
  • 测评结果:TL
  • 用时:114ms
  • 内存:64356kb
  • [2023-10-26 22:44:03]
  • 提交

answer

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back

typedef long long ll;
typedef long double ld;
const int mod = 2017;
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}
int n;
const int maxN = 2e5 + 10;
int p[maxN];
int c[maxN];
int len[maxN];
const int BUBEN = 500;
//vector<int> f[maxN];
int link[maxN];
int ord[maxN];
int MEM[maxN / BUBEN + 2][maxN];
int cur[maxN];
vector<int> g[maxN];
int id[maxN];

gp_hash_table<int, int> f[maxN];


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        len[i] = len[p[i]] + 1;
        g[p[i]].emplace_back(i);
    }
    for (int i = 1; i <= n; i++) {
        cin >> c[i];
        f[p[i]][c[i]] = i;
    }

    iota(ord + 1, ord + n + 1, 1);
    sort(ord + 1, ord + n + 1, [&](int x, int y) {
        return len[x] < len[y];
    });
    for (int x : g[0]) {
        MEM[0][c[x]] = x;
    }
    memset(id, -1, sizeof id);
    id[0] = 0;
    link[0] = 0;
    int SZ = 1;
    for (int who = 1; who <= n; who++) {
        int i = ord[who];
        int symb = c[i];
        if (p[i] == 0) {
            link[i] = 0;
        }
        else {
            int D = link[p[i]];
            int vert = -1;
            while (id[D] == -1) {
                if (f[D].find(symb) != f[D].end()) {
                    vert = f[D][symb];
                    break;
                }
                D = link[D];
            }
            if (vert == -1) {
                assert(id[D] != -1);
                vert = MEM[id[D]][symb];
            }
            link[i] = vert;
        }
        cur[i] = cur[link[i]] + 1;
        if (cur[i] >= BUBEN && SZ < maxN / BUBEN) {
            cur[i] = 0;
            for (int j = 1; j <= n; j++) {
                int D = i;
                int vert = -1;
                while (id[D] == -1) {
                    if (f[D].find(j) != f[D].end()) {
                        vert = f[D][j];
                        break;
                    }
                    D = link[D];
                }
                if (vert == -1) {
                    assert(id[D] != -1);
                    vert = MEM[id[D]][j];
                }
                MEM[SZ][j] = vert;
            }
            id[i] = SZ;
            SZ++;
        }
    }
    for (int i = 1; i <= n; i++) cout << link[i] << " ";
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 54356kb

input:

2
0 0
1 2

output:

0 0 

result:

ok 2 number(s): "0 0"

Test #2:

score: 0
Accepted
time: 12ms
memory: 55720kb

input:

2
0 1
1 1

output:

0 1 

result:

ok 2 number(s): "0 1"

Test #3:

score: 0
Accepted
time: 10ms
memory: 55504kb

input:

1
0
1

output:

0 

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 19ms
memory: 55572kb

input:

50
0 1 1 1 0 0 4 4 3 7 1 11 1 11 2 15 13 11 4 11 5 7 22 17 4 19 19 26 19 27 3 17 9 4 14 8 15 33 33 33 9 40 24 18 5 28 10 1 47 25
20 20 31 1 43 3 3 21 3 3 3 22 43 3 1 20 3 43 43 20 3 20 1 3 20 20 3 1 43 3 20 20 20 29 3 3 3 3 20 1 3 3 3 3 20 3 3 25 3 1

output:

0 1 0 0 0 0 6 0 6 6 6 0 5 6 4 25 21 5 5 1 6 1 4 6 1 45 21 4 5 6 1 1 1 0 6 6 7 11 2 4 6 7 6 21 1 7 6 0 6 4 

result:

ok 50 numbers

Test #5:

score: 0
Accepted
time: 10ms
memory: 55668kb

input:

50
0 0 2 0 2 4 1 2 1 1 8 4 9 2 14 5 8 4 15 17 18 5 17 1 1 14 6 14 3 12 30 27 12 5 13 29 32 34 2 4 3 5 7 20 37 44 10 30 19 8
36 8 13 13 42 8 13 19 28 36 36 36 8 8 19 8 13 7 8 8 8 12 7 46 8 8 8 13 7 8 8 8 13 36 8 8 8 8 36 13 8 13 7 8 8 8 8 13 8 8

output:

0 0 4 0 0 2 4 0 0 1 1 1 2 2 8 2 4 0 50 6 2 0 18 0 2 14 14 3 18 25 14 26 7 1 14 21 26 25 1 4 6 4 18 27 26 32 25 3 14 2 

result:

ok 50 numbers

Test #6:

score: 0
Accepted
time: 12ms
memory: 55144kb

input:

50
0 1 0 2 0 3 0 0 3 3 6 9 4 0 2 10 3 17 7 4 18 20 16 10 16 9 8 26 16 11 16 4 20 13 8 34 33 34 28 30 26 11 17 35 32 41 36 43 31 38
20 3 38 3 22 14 12 3 12 3 3 12 12 14 12 12 20 12 3 14 3 12 20 3 14 3 3 3 12 3 3 3 3 3 12 12 3 3 3 3 12 12 3 3 3 3 3 3 3 3

output:

0 8 0 27 0 14 0 0 7 8 8 7 35 0 35 35 1 7 8 14 19 7 1 27 14 19 8 27 7 27 44 27 8 44 7 35 27 27 27 27 35 35 2 19 27 44 44 4 27 27 

result:

ok 50 numbers

Test #7:

score: 0
Accepted
time: 23ms
memory: 55540kb

input:

50
0 1 2 1 2 1 3 5 7 1 1 2 0 5 14 15 15 6 9 18 10 13 12 10 9 1 17 10 1 2 6 14 23 6 18 19 13 29 35 8 13 20 0 25 41 11 41 24 9 31
11 5 11 42 23 9 5 11 11 48 11 42 42 16 11 5 9 42 9 11 11 42 11 42 10 16 11 16 10 16 11 16 5 16 16 11 11 11 11 5 16 5 16 11 11 5 16 11 5 5

output:

0 0 1 13 0 0 2 1 3 0 1 13 0 43 1 2 6 13 6 37 1 13 37 13 29 43 31 43 0 43 1 43 2 43 41 31 1 1 45 2 43 2 0 38 1 2 43 37 7 2 

result:

ok 50 numbers

Test #8:

score: 0
Accepted
time: 19ms
memory: 56408kb

input:

50
0 0 0 0 4 3 0 3 5 6 4 11 7 3 10 4 10 1 1 12 2 17 13 19 0 22 20 7 1 23 26 24 30 22 2 20 22 30 15 11 7 38 28 27 36 9 46 21 21 10
18 3 20 9 9 9 23 3 3 3 18 3 18 18 3 3 9 18 3 3 9 3 3 3 50 18 9 9 9 3 3 3 9 9 3 3 3 3 3 9 3 3 3 3 3 3 3 9 3 18

output:

0 0 0 0 4 4 0 2 16 16 1 19 1 1 35 2 21 1 2 24 4 49 19 35 0 1 21 4 4 24 19 35 21 21 2 32 35 32 35 29 2 35 16 49 35 35 35 5 16 1 

result:

ok 50 numbers

Test #9:

score: 0
Accepted
time: 12ms
memory: 56272kb

input:

50
0 1 2 3 3 0 5 1 8 4 0 8 5 8 14 9 13 14 6 18 19 10 9 3 22 16 7 11 14 22 20 1 0 6 24 8 18 15 30 5 30 2 38 22 44 25 20 34 48 41
25 1 1 19 1 19 19 25 31 1 31 1 25 25 1 1 1 19 1 1 1 1 19 25 25 1 1 1 25 19 19 19 1 19 1 19 19 1 1 1 19 19 1 1 1 1 1 1 1 1

output:

0 33 33 6 33 0 6 1 11 19 0 2 1 8 12 28 2 36 33 19 33 21 6 1 1 33 19 33 14 6 6 6 0 6 2 32 34 3 19 33 34 6 5 33 33 2 21 19 21 48 

result:

ok 50 numbers

Test #10:

score: 0
Accepted
time: 16ms
memory: 56296kb

input:

50
0 0 0 1 2 0 6 7 3 0 3 2 12 10 10 15 0 7 17 5 11 3 4 12 11 9 20 27 27 29 6 11 7 15 7 9 34 10 20 8 16 11 21 16 31 23 25 15 11 26
40 36 21 12 12 29 21 12 12 33 29 21 21 21 12 29 12 33 12 12 36 21 12 12 33 12 12 21 12 12 12 29 21 21 29 21 12 29 21 12 12 12 12 21 12 12 12 12 21 12

output:

0 0 0 17 17 0 3 9 17 0 6 3 22 3 17 6 0 10 17 19 2 3 19 9 10 19 19 3 19 19 17 6 22 3 11 3 9 6 3 26 31 31 5 7 19 19 15 19 7 19 

result:

ok 50 numbers

Test #11:

score: 0
Accepted
time: 11ms
memory: 54768kb

input:

50
0 1 2 0 0 1 5 4 1 6 5 11 8 5 7 4 5 2 3 19 4 17 3 12 4 4 19 7 2 28 21 20 12 31 26 22 35 28 0 18 7 29 4 18 33 38 30 28 32 7
39 36 9 36 9 6 9 36 9 6 36 6 6 6 36 9 39 8 6 9 23 6 9 9 6 8 6 9 6 6 6 6 6 6 6 6 6 36 6 6 39 6 39 9 6 6 6 9 6 6

output:

0 4 16 0 0 39 5 4 5 39 4 25 25 39 11 5 1 26 14 5 0 6 7 5 39 0 39 7 25 50 39 14 39 39 39 10 39 15 0 35 17 39 1 5 39 12 39 28 39 14 

result:

ok 50 numbers

Test #12:

score: 0
Accepted
time: 12ms
memory: 55648kb

input:

50
0 1 1 3 3 3 6 2 3 4 8 0 3 13 2 9 9 13 14 13 4 18 10 21 1 2 5 23 15 27 15 30 20 24 1 27 15 29 15 12 34 36 15 13 28 42 4 41 1 40
7 6 26 3 11 25 3 49 7 13 3 3 21 3 7 3 5 7 3 9 7 3 3 3 7 3 3 3 6 7 26 3 3 3 5 3 5 3 3 3 3 3 7 41 3 3 3 3 3 3

output:

0 0 0 12 0 0 12 0 1 0 12 0 0 12 1 49 35 1 40 0 1 49 12 49 1 12 12 40 2 1 3 49 12 40 0 40 35 26 49 12 50 50 25 0 50 50 40 50 12 40 

result:

ok 50 numbers

Test #13:

score: 0
Accepted
time: 12ms
memory: 55752kb

input:

50
0 0 2 0 3 3 2 6 3 0 6 11 4 10 4 2 2 13 11 7 7 8 22 2 6 23 18 15 11 7 18 5 23 4 27 17 27 21 6 18 11 14 40 29 27 15 26 32 38 19
49 27 27 18 27 33 49 33 18 33 18 49 27 18 33 33 18 18 33 27 18 18 18 47 49 18 27 27 18 33 18 18 27 18 18 18 33 18 27 33 27 18 18 18 27 18 18 18 18 18

output:

0 0 2 0 3 16 1 10 17 0 14 1 2 4 10 10 4 17 15 2 4 14 42 0 1 34 13 2 42 10 36 9 13 4 18 34 16 34 2 15 13 34 46 34 3 14 34 36 34 46 

result:

ok 50 numbers

Test #14:

score: 0
Accepted
time: 17ms
memory: 55096kb

input:

500
0 1 0 1 0 4 1 0 4 2 8 7 2 9 12 3 10 15 17 8 12 4 22 5 11 11 13 9 14 7 24 29 26 3 26 29 31 36 18 0 40 8 21 14 10 10 34 7 18 38 21 3 19 48 16 46 22 14 19 34 48 13 56 21 16 56 39 19 16 44 55 50 35 51 56 69 73 64 41 11 23 69 71 63 22 49 85 15 78 4 0 40 25 29 42 77 20 74 22 89 66 40 78 83 48 18 93 53...

output:

0 40 0 464 0 3 91 0 1 127 1 5 92 4 474 1 258 488 202 40 131 40 41 464 7 126 92 202 90 1 40 1 262 464 138 5 361 24 13 0 5 464 127 9 132 355 40 464 10 31 162 40 4 464 202 361 361 22 463 1 40 127 126 361 4 2 27 202 2 28 463 37 308 342 4 13 359 202 24 202 135 10 120 262 127 46 355 126 202 91 0 40 278 46...

result:

ok 500 numbers

Test #15:

score: 0
Accepted
time: 16ms
memory: 56192kb

input:

500
0 0 1 1 1 1 3 5 3 2 9 8 5 3 7 1 2 11 10 18 12 6 18 9 1 7 8 24 27 27 28 4 25 4 18 1 30 6 5 12 10 16 36 35 33 27 43 40 28 32 4 46 39 33 11 18 13 36 23 26 40 18 29 33 24 39 61 41 48 15 24 70 69 39 17 37 51 4 51 66 72 69 53 9 59 56 60 70 38 44 29 68 26 75 72 1 83 21 71 75 1 0 14 36 92 1 19 54 31 5 3...

output:

0 0 2 1 144 0 10 102 2 126 102 1 126 1 19 0 144 1 203 3 106 126 101 10 0 234 2 41 10 1 1 36 126 25 4 0 106 144 1 101 2 144 1 78 203 17 106 203 10 446 5 464 5 143 309 6 174 0 203 1 254 106 41 174 19 106 126 17 174 319 416 236 236 101 1 160 110 106 39 160 126 126 263 2 174 38 5 1 102 253 416 75 236 10...

result:

ok 500 numbers

Test #16:

score: 0
Accepted
time: 10ms
memory: 55228kb

input:

500
0 1 1 1 4 0 4 1 3 9 10 6 5 2 3 15 3 14 9 16 4 10 22 21 18 24 18 19 19 10 3 12 22 29 11 1 31 19 11 39 20 10 32 37 11 31 19 42 26 33 39 4 26 46 6 13 46 16 27 11 35 20 1 45 35 18 24 46 12 33 10 51 14 71 61 25 17 51 8 10 40 78 43 78 54 62 35 12 54 7 41 16 31 70 22 84 1 62 23 65 37 87 93 92 0 59 91 5...

output:

0 0 120 231 0 0 120 0 231 1 2 6 6 120 365 127 186 472 128 1 6 4 5 127 120 128 128 128 120 8 472 127 21 365 0 128 128 1 132 246 63 413 128 252 14 252 252 2 252 24 460 231 128 12 1 12 55 406 128 231 231 36 6 73 128 252 406 127 55 187 36 12 365 371 128 365 194 55 6 63 2 257 252 150 207 128 6 12 88 365 ...

result:

ok 500 numbers

Test #17:

score: 0
Accepted
time: 15ms
memory: 52700kb

input:

500
0 0 2 2 0 4 5 6 2 7 3 3 11 3 6 13 13 1 3 18 17 10 18 8 0 10 11 10 11 1 14 19 1 3 11 25 25 16 20 35 31 9 4 6 34 14 7 27 36 28 21 27 47 31 48 33 37 45 26 47 34 25 45 57 41 8 4 0 4 4 1 16 63 24 23 13 62 69 43 65 63 5 45 20 47 69 51 82 14 47 62 57 33 23 64 7 47 59 67 51 72 47 9 37 44 2 63 57 102 102...

output:

0 0 2 1 0 30 1 164 5 71 340 4 25 3 207 460 36 68 377 5 186 68 68 306 0 256 460 2 62 2 280 1 5 9 337 2 1 322 7 452 1 7 33 212 393 305 18 1 4 170 1 322 139 431 30 125 30 245 71 175 42 5 381 196 71 227 71 0 226 18 322 1 71 322 452 37 125 417 93 25 226 5 452 379 0 226 30 379 12 390 7 164 7 381 238 226 0...

result:

ok 500 numbers

Test #18:

score: 0
Accepted
time: 13ms
memory: 54600kb

input:

500
0 0 1 2 4 5 1 3 1 6 3 1 2 8 1 11 14 13 18 0 11 14 22 4 15 6 22 5 12 14 22 27 0 12 15 17 31 9 27 38 38 13 27 28 25 17 41 29 35 22 4 17 34 16 14 5 12 25 30 24 22 25 19 5 49 53 9 6 37 22 63 60 40 12 59 58 36 29 54 40 80 13 27 10 41 32 41 24 85 86 55 85 30 1 88 26 13 3 13 1 7 31 88 37 57 18 28 26 41...

output:

0 0 2 495 0 0 495 4 0 495 13 1 33 485 0 178 251 0 495 0 18 462 116 495 33 33 0 2 100 2 2 495 0 3 495 15 13 1 1 12 15 116 33 159 116 94 112 116 1 0 1 9 310 1 125 20 9 495 166 20 20 20 1 33 12 15 33 1 18 495 9 251 57 7 336 1 145 495 15 247 110 0 2 20 25 1 145 33 45 12 175 62 159 20 495 116 2 208 20 33...

result:

ok 500 numbers

Test #19:

score: 0
Accepted
time: 15ms
memory: 55204kb

input:

500
0 1 1 3 2 4 3 7 5 6 4 2 3 11 4 10 6 16 11 1 20 8 18 8 5 22 16 21 4 20 26 2 30 29 16 16 10 6 13 34 6 13 42 9 3 35 38 14 39 27 39 28 43 30 9 1 4 35 30 16 17 38 56 17 60 32 39 28 0 51 49 9 1 44 28 46 2 48 10 16 47 14 11 79 78 38 57 55 13 44 84 33 33 6 38 46 89 0 56 88 54 94 4 85 101 43 61 27 64 40 ...

output:

0 69 98 177 177 177 125 340 256 177 1 125 69 20 69 0 1 1 56 177 125 177 56 69 1 1 69 340 0 1 56 114 73 256 0 177 125 69 150 256 98 177 1 177 256 256 150 69 20 114 56 125 20 20 1 256 98 177 56 125 353 125 1 56 328 177 353 69 0 153 464 256 125 256 1 0 69 150 0 98 353 30 73 256 56 114 256 73 114 1 256 ...

result:

ok 500 numbers

Test #20:

score: 0
Accepted
time: 8ms
memory: 54844kb

input:

500
0 0 0 3 1 2 4 4 3 5 5 4 7 2 13 8 6 12 4 19 13 8 10 3 16 9 25 8 17 3 9 10 30 3 8 8 17 14 3 5 18 8 30 31 25 18 26 16 48 23 47 22 30 15 38 20 20 22 34 45 9 42 35 29 1 22 61 49 36 23 9 62 51 71 41 14 55 44 46 71 54 18 78 25 30 29 32 77 62 46 88 10 38 53 80 65 73 89 0 78 90 28 83 38 9 59 72 28 3 41 0...

output:

0 0 0 0 1 99 3 99 2 5 65 2 157 2 468 0 239 453 111 138 2 118 10 3 2 14 6 234 468 0 111 40 2 0 239 265 2 453 0 468 39 390 111 99 313 24 209 0 3 32 330 179 1 24 24 283 215 99 1 330 6 24 65 24 99 138 17 157 239 2 313 404 24 2 3 6 404 239 309 65 309 157 5 14 0 157 197 65 271 30 139 11 39 468 139 265 404...

result:

ok 500 numbers

Test #21:

score: 0
Accepted
time: 17ms
memory: 55260kb

input:

500
0 1 2 3 4 1 5 1 2 3 6 5 9 4 1 6 15 15 0 9 5 12 17 7 5 9 20 3 9 24 13 17 29 20 8 8 10 27 29 32 29 16 10 29 3 21 13 1 47 16 5 33 17 12 33 8 27 44 33 37 4 43 5 42 18 1 58 3 68 41 10 18 28 59 10 2 21 34 56 47 22 29 59 11 67 36 15 43 22 85 27 50 31 83 9 84 88 32 43 64 25 38 20 94 53 2 105 105 101 61 ...

output:

0 0 0 0 1 1 220 0 19 0 48 66 210 19 0 220 19 0 0 0 2 416 210 1 15 300 1 0 0 220 337 0 1 0 19 1 1 15 19 0 0 1 19 0 19 9 459 19 1 310 6 48 300 0 6 0 6 19 15 220 0 0 48 220 0 0 0 1 48 19 0 19 1 17 0 0 76 19 1 310 210 0 0 205 1 220 1 127 127 15 220 210 196 1 127 209 127 1 0 310 87 18 0 220 19 0 127 300 ...

result:

ok 500 numbers

Test #22:

score: 0
Accepted
time: 11ms
memory: 56104kb

input:

500
0 0 1 0 4 2 0 5 1 1 10 3 8 7 11 4 16 17 12 3 7 16 10 3 20 21 19 10 13 29 16 25 0 2 1 0 11 24 35 28 36 12 25 10 33 4 37 3 8 17 14 27 38 51 21 28 43 24 29 30 3 47 42 54 28 50 38 9 31 12 67 71 5 17 18 66 68 30 13 22 71 30 44 0 62 84 31 25 38 35 19 90 32 36 54 7 19 29 89 58 60 75 79 39 67 28 70 107 ...

output:

0 0 166 0 84 1 0 7 84 33 455 2 328 36 94 7 14 51 6 172 1 328 45 36 1 3 3 84 14 33 491 3 0 33 1 0 7 1 153 84 166 473 323 1 166 1 14 33 21 112 94 24 10 94 153 86 491 94 51 45 84 33 36 41 7 491 323 86 36 127 14 51 1 167 246 36 143 455 491 21 167 338 323 0 45 166 2 153 9 3 9 24 300 36 94 84 153 112 68 1...

result:

ok 500 numbers

Test #23:

score: 0
Accepted
time: 7ms
memory: 55076kb

input:

500
0 0 0 0 4 3 4 1 8 4 4 3 11 11 14 6 16 16 6 9 18 14 8 8 9 18 11 26 5 27 20 27 0 22 21 15 17 5 6 20 38 26 34 40 38 16 0 8 36 36 24 41 4 17 30 18 26 32 36 0 16 34 10 48 6 30 30 8 28 64 30 22 19 45 0 50 5 72 10 72 39 29 9 3 57 52 76 3 55 53 49 59 21 8 83 3 82 97 38 43 23 101 80 46 33 47 72 99 13 91 ...

output:

0 0 0 0 47 33 4 47 2 60 2 1 33 4 5 105 4 3 279 47 353 211 4 143 3 377 3 4 3 366 143 332 0 374 397 29 5 2 124 106 2 3 417 155 47 2 0 106 224 82 143 47 33 10 332 366 2 238 6 0 235 332 238 247 212 417 353 33 10 455 6 6 47 106 0 481 143 19 229 16 3 332 60 75 47 143 229 0 229 105 106 65 60 3 238 4 229 2 ...

result:

ok 500 numbers

Test #24:

score: 0
Accepted
time: 20ms
memory: 55964kb

input:

5000
0 0 2 0 1 3 4 1 2 7 3 0 8 11 4 15 12 6 4 18 2 8 20 14 14 0 5 2 16 24 6 16 3 8 30 0 24 4 4 3 33 32 28 37 42 30 43 4 35 30 48 42 49 51 22 46 19 21 25 3 44 4 28 63 59 30 34 0 35 58 67 18 62 20 45 39 63 69 35 5 11 63 35 67 56 20 63 3 53 38 64 65 24 13 19 57 87 34 44 1 71 82 66 5 69 52 80 24 99 57 7...

output:

0 0 12 0 595 595 2 269 269 21 3183 0 26 5 4 453 269 26 68 595 26 3461 36 4963 2878 0 36 1 594 3183 269 415 719 1 8 0 595 595 1 3016 206 1236 3662 1 1 5 719 36 13 100 68 26 2368 219 26 206 36 793 627 2 8 206 112 409 17 36 8 0 34 206 415 349 26 595 8 8 68 250 233 595 100 206 206 68 26 1 595 17 4257 59...

result:

ok 5000 numbers

Test #25:

score: 0
Accepted
time: 24ms
memory: 55668kb

input:

5000
0 1 1 0 1 1 5 4 2 3 6 9 6 5 7 3 0 2 13 11 11 8 15 22 18 10 21 1 28 17 26 20 27 16 27 10 4 26 38 37 35 1 1 19 22 8 13 45 22 8 39 36 37 52 31 53 2 29 27 4 26 31 47 1 27 24 19 55 15 14 63 50 19 33 68 42 7 21 5 69 63 47 18 31 46 39 37 80 12 37 69 87 44 2 89 75 49 84 5 66 48 76 2 68 1 102 77 10 32 1...

output:

0 17 1 0 4 0 539 1 0 28 1 208 208 4870 0 43 0 914 1 105 5 28 4 1138 4784 1138 0 0 208 0 37 180 0 3353 17 29 208 8 50 2332 914 0 0 105 0 64 17 4 29 43 556 252 4784 2332 87 0 226 1 4 17 539 40 0 0 1 37 682 92 17 37 4 587 43 17 267 4 2472 1121 0 0 0 914 2332 90 205 124 1 208 2332 1958 3840 43 4784 639 ...

result:

ok 5000 numbers

Test #26:

score: 0
Accepted
time: 15ms
memory: 55996kb

input:

5000
0 0 1 1 4 5 6 7 3 5 8 6 4 0 3 6 5 12 5 12 15 10 11 14 0 5 25 0 18 18 8 25 11 32 1 3 21 31 35 38 28 16 17 5 24 38 40 7 9 30 28 15 38 38 28 3 3 41 1 20 3 60 54 4 6 20 28 42 31 15 9 2 67 54 69 46 27 43 3 5 34 43 8 43 80 43 53 14 71 11 7 10 63 59 64 29 25 86 72 31 36 45 64 99 53 85 13 12 91 72 91 4...

output:

0 0 1 0 1 59 1124 4174 610 3 1 72 4174 0 35 94 35 4174 4 3606 4614 79 610 2 0 2279 28 0 28 3606 4545 2 3 432 25 4236 25 4614 97 25 25 880 237 610 944 4174 1 1 1456 25 3606 39 1 2 14 3 1251 97 2 4174 4 2 72 0 4174 14 28 2611 27 4174 1 3606 67 432 380 4545 548 32 59 4236 1551 4614 28 0 28 0 1251 14 35...

result:

ok 5000 numbers

Test #27:

score: 0
Accepted
time: 12ms
memory: 58168kb

input:

5000
0 1 1 1 2 3 3 2 3 9 1 2 2 8 7 9 1 17 16 5 16 1 0 6 2 19 14 27 25 4 16 29 32 14 8 5 31 32 19 7 18 31 9 23 5 2 15 0 1 0 19 9 37 39 16 10 2 33 29 29 46 23 9 7 45 10 12 53 10 52 1 66 58 1 9 33 40 17 65 53 21 35 15 3 72 70 69 27 8 9 37 52 83 54 57 46 84 38 31 48 12 39 43 58 91 27 10 105 8 58 46 71 4...

output:

0 48 0 50 50 253 0 100 48 100 0 253 573 50 23 0 0 1 23 775 283 23 0 2941 0 616 253 2941 23 1127 48 192 208 923 48 923 132 3966 62 48 3 253 1987 283 253 132 44 0 280 0 192 246 1436 2174 1 48 1987 2 222 62 732 280 132 253 50 253 4866 466 177 283 283 246 8 253 23 0 132 283 923 23 3242 132 192 246 48 23...

result:

ok 5000 numbers

Test #28:

score: 0
Accepted
time: 14ms
memory: 55916kb

input:

5000
0 0 1 2 1 1 4 6 5 1 4 3 0 13 10 12 6 9 9 18 4 3 19 14 5 6 15 2 15 5 30 1 9 14 17 14 32 32 16 0 21 0 25 9 15 26 42 9 37 26 8 15 4 50 26 40 27 41 39 45 32 54 28 9 14 5 22 48 27 53 59 25 48 14 55 37 58 39 63 5 73 27 82 15 63 3 69 16 12 7 67 55 9 43 32 64 64 30 94 1 90 58 81 41 15 12 54 107 84 45 8...

output:

0 0 2076 1241 42 0 42 2076 0 1 1241 13 0 1 1244 138 1 1 42 1606 40 0 47 5 2 40 2 1 13 823 1241 2 2 100 1244 0 3380 750 224 0 56 0 4 13 0 1241 2076 40 4364 803 2076 1 1 10 56 42 3380 244 2 2076 28 15 1244 1241 0 42 1 264 28 1244 3591 750 224 514 4949 13 4 3356 1241 13 0 750 1241 0 2 1 63 1241 14 42 1...

result:

ok 5000 numbers

Test #29:

score: 0
Accepted
time: 11ms
memory: 58256kb

input:

5000
0 1 2 2 0 5 2 1 7 8 5 11 11 13 12 15 3 5 18 10 4 2 11 22 9 24 3 2 21 28 20 5 26 13 25 3 12 33 32 18 13 16 41 34 41 10 17 3 34 0 49 33 45 35 22 47 43 4 9 46 11 25 42 12 53 65 6 35 6 8 5 57 22 36 55 40 2 61 33 53 44 21 71 70 12 14 85 78 60 12 71 69 37 64 25 82 26 81 63 66 66 2 20 48 53 60 51 92 3...

output:

0 5 1751 71 0 168 2865 168 134 50 0 5 122 184 207 1175 234 0 134 195 18 111 234 307 5 614 50 207 603 1175 1839 1 234 3685 71 647 11 1898 1567 122 647 684 2031 1554 122 118 787 1803 0 0 234 1712 3685 91 507 435 71 83 1366 2035 0 11 979 18 3685 50 234 18 122 246 5 83 50 2141 2149 184 11 134 779 435 31...

result:

ok 5000 numbers

Test #30:

score: 0
Accepted
time: 19ms
memory: 55800kb

input:

5000
0 1 2 2 0 3 6 4 2 0 8 8 9 8 8 2 9 10 10 3 3 4 1 22 11 16 24 1 28 7 1 9 16 13 34 13 22 32 8 11 4 23 14 20 42 34 33 12 16 18 40 31 12 36 18 53 43 54 10 11 54 54 53 15 32 55 58 23 66 21 63 41 13 5 3 28 14 13 45 21 74 13 79 70 46 34 5 3 19 62 10 71 61 2 0 35 37 83 23 31 76 21 83 30 0 1 94 46 93 59 ...

output:

0 0 5 376 0 95 3403 376 95 0 459 423 533 105 95 718 856 95 0 87 3135 1348 274 407 23 2280 105 10 171 879 718 105 95 0 274 407 3135 1 2987 106 423 1666 105 171 1804 718 3403 19 105 0 337 274 1803 1 1 4421 412 28 5 1815 637 106 2929 3403 105 2 1806 105 3 28 935 734 74 105 74 3487 337 1898 3486 106 1 2...

result:

ok 5000 numbers

Test #31:

score: 0
Accepted
time: 15ms
memory: 56216kb

input:

5000
0 0 0 3 2 1 0 7 3 6 0 5 7 3 11 5 6 2 3 16 4 18 7 23 14 25 23 0 18 15 14 13 26 29 8 6 2 16 5 12 39 34 30 30 23 24 13 5 13 46 29 9 11 21 28 28 42 4 39 3 31 19 9 17 0 51 17 10 13 54 49 1 3 70 3 75 35 57 14 53 61 5 62 42 79 53 67 80 67 74 39 22 80 49 71 21 96 79 81 96 52 93 18 37 37 59 92 48 27 54 ...

output:

0 0 0 217 28 1 0 11 1518 72 0 124 7 0 28 353 568 65 7 980 688 784 3 60 219 4977 73 0 7 678 3 8 4 4066 150 3122 7 420 55 173 338 124 219 65 4 56 139 678 129 139 129 1784 65 11 1 7 184 219 236 28 4 139 65 1043 0 318 872 129 13 150 784 7 0 303 1 3122 303 1609 1 11 1011 56 247 56 3122 318 1473 15 19 405...

result:

ok 5000 numbers

Test #32:

score: 0
Accepted
time: 12ms
memory: 55904kb

input:

5000
0 1 2 3 0 5 0 2 2 6 1 1 0 11 8 8 2 17 14 9 16 19 3 7 18 17 12 11 8 16 1 18 14 19 8 16 3 1 11 21 40 7 3 4 18 8 35 47 0 20 19 4 52 45 24 34 11 24 49 28 13 48 23 20 39 45 2 21 62 68 10 33 67 39 64 43 55 1 63 69 32 1 52 54 27 64 83 14 4 72 52 36 7 12 64 39 76 81 49 13 29 10 100 12 67 35 28 33 86 10...

output:

0 0 1 82 0 1153 0 295 5 2548 1218 0 0 1 1218 1104 13 3384 2 495 1218 17 2450 1153 275 61 0 5 7 5000 0 6 817 3 711 13 2 1153 49 3954 49 295 840 4314 282 1 1 2450 0 977 1761 4973 198 301 1623 4 295 49 295 487 295 1246 711 656 517 295 1153 1218 1728 5 1286 13 49 99 275 31 3134 7 1 517 1286 5 1204 1286 ...

result:

ok 5000 numbers

Test #33:

score: 0
Accepted
time: 12ms
memory: 54604kb

input:

5000
0 1 2 3 1 1 6 6 0 5 6 2 1 5 4 0 13 0 14 11 15 6 12 15 7 4 11 15 0 3 19 28 20 33 2 16 26 10 27 12 24 27 2 31 41 14 1 16 6 41 28 51 46 9 49 2 19 53 50 4 57 7 43 30 61 62 6 11 28 7 67 53 46 10 39 68 0 11 64 11 50 53 53 71 40 31 1 17 31 67 47 61 57 8 74 58 74 93 73 19 29 4 21 66 27 89 18 56 43 51 1...

output:

0 244 1 3408 3826 16 771 36 0 9 4559 2042 495 77 18 0 2892 0 213 1257 107 531 149 195 3773 452 3263 1228 0 2 2217 1883 1257 1257 247 29 504 133 16 2864 3263 18 661 1651 247 452 0 1 1183 18 247 773 1059 3826 1255 18 336 1 508 29 355 29 213 43 1 101 1091 133 2042 213 107 3290 3290 3263 771 195 0 495 2...

result:

ok 5000 numbers

Test #34:

score: 0
Accepted
time: 97ms
memory: 64136kb

input:

200000
0 0 2 1 2 4 1 0 8 8 2 4 4 1 11 8 16 10 9 15 11 1 22 4 18 10 19 16 21 5 20 23 25 4 10 24 29 18 18 35 37 15 27 19 1 16 18 28 18 40 31 31 21 44 4 42 55 51 42 11 2 4 20 58 64 38 63 61 42 43 0 21 21 62 38 52 7 33 5 54 34 50 64 73 63 46 69 23 50 75 3 72 83 3 29 83 58 57 14 32 94 81 23 20 65 10 50 7...

output:

0 0 8 314 26910 53072 520 0 8 520 520 2944 8839 0 520 149284 26910 11805 16 1498 2 2 3160 2930 2 1 10841 314 22865 520 91116 170244 29664 131853 22865 3063 26910 520 83076 8 1178 131853 3160 762 160722 71 21944 8839 61033 81786 2 131853 1 1304 42076 71 23287 11 131853 2571 314 676 2360 9355 32675 13...

result:

ok 200000 numbers

Test #35:

score: 0
Accepted
time: 94ms
memory: 64356kb

input:

200000
0 1 1 0 0 2 1 3 2 7 8 10 3 12 14 9 10 6 9 6 3 7 20 10 21 0 25 5 6 3 13 21 17 3 33 11 3 2 8 6 19 40 34 5 43 33 26 41 5 33 38 47 2 3 34 18 34 4 38 27 12 30 43 22 24 1 10 16 33 32 57 3 50 70 27 30 69 73 68 3 79 43 69 35 72 37 24 76 69 11 73 31 26 79 65 50 88 36 7 10 63 72 50 41 85 53 23 53 59 80...

output:

0 1 5 0 0 104344 3391 28 23096 26 840 442 10178 18774 43847 553 2520 47 64259 442 49 840 532 47 88597 0 52 3391 1 0 252 86166 5 5 28 4328 906 7 1 10789 47 4226 10178 4 840 252 4226 1951 26 55401 287 252 66 235 5 52 28 4 820 2376 490 3391 55401 9023 115740 4226 14127 1830 5 62104 310 840 55401 81296 ...

result:

ok 200000 numbers

Test #36:

score: 0
Accepted
time: 102ms
memory: 63940kb

input:

200000
0 0 0 0 0 4 3 7 8 9 8 7 5 4 1 10 13 3 8 17 15 8 14 9 13 20 4 18 0 22 2 20 23 20 32 30 15 36 11 16 2 22 22 19 24 16 3 22 27 27 44 39 37 5 39 2 37 16 19 18 28 48 1 51 52 23 24 54 6 22 29 40 63 64 32 49 50 12 70 16 75 29 65 81 36 56 58 41 22 36 68 42 62 25 7 81 39 52 95 93 9 12 33 55 83 23 34 97...

output:

0 0 0 0 0 2 563 1 9019 1101 117 7275 598 327 29 31330 3 3 343 2 72414 153770 701 248 216 327 598 2682 0 117 563 2 10067 5 1101 40417 56802 72565 94017 60755 216 15 2147 248 17424 978 1 9019 151295 4241 1837 447 928 216 5 248 4241 82 2 327 116993 23686 3 1101 112615 1 22978 1546 778 2540 2 185373 7 8...

result:

ok 200000 numbers

Test #37:

score: 0
Accepted
time: 113ms
memory: 64320kb

input:

200000
0 0 2 0 4 0 1 3 0 4 2 9 4 11 11 11 9 7 8 7 8 18 7 8 4 4 5 7 14 28 26 18 19 11 32 16 17 5 31 35 29 8 29 5 5 33 32 2 15 24 1 28 50 44 27 25 41 24 46 26 49 7 19 15 19 52 38 0 66 31 15 70 60 72 59 67 27 43 4 45 39 10 70 35 1 39 14 6 30 48 27 52 84 7 49 48 7 25 84 71 79 53 100 100 6 65 36 5 20 42 ...

output:

0 0 935 0 153 0 109923 2 0 1 68 68 540 163 355 9 6 163 784 540 3 37079 355 4305 163 47792 1107 175436 35574 540 1 188493 12296 1779 109923 22315 2504 31826 1172 197423 37461 866 1211 601 108605 176032 195162 163 53576 35309 68 935 12029 633 1107 6125 124847 2504 72628 68 22257 1 1230 540 28008 68 23...

result:

ok 200000 numbers

Test #38:

score: 0
Accepted
time: 114ms
memory: 64100kb

input:

200000
0 1 1 3 4 3 1 7 7 3 4 6 2 2 6 12 11 17 1 18 11 7 14 14 7 25 11 24 16 10 15 17 21 10 19 11 36 7 3 37 11 33 9 26 10 42 34 31 46 18 8 0 12 13 3 17 20 35 50 18 0 33 30 44 53 16 19 39 0 21 1 52 57 6 41 30 12 60 67 74 74 3 78 37 8 30 72 19 71 66 5 63 27 47 89 47 24 4 65 50 58 94 44 9 86 35 48 65 75...

output:

0 69 0 160187 160187 50928 0 50928 61 1 69 69 290 31572 924 19635 0 924 52 924 31572 0 135569 924 0 1010 52 52 160187 17925 9552 1 90357 563 120 10650 100919 924 100919 160187 591 197650 1010 59960 8879 1010 4611 31471 138915 9552 61 0 19061 69 61 69 170420 3498 11533 52 0 100919 160187 107253 38852...

result:

ok 200000 numbers

Test #39:

score: 0
Accepted
time: 104ms
memory: 63672kb

input:

200000
0 0 2 3 2 5 2 3 1 4 9 0 6 11 1 13 14 13 3 8 2 15 7 21 0 13 17 5 10 29 9 15 17 27 19 14 32 24 24 16 26 23 16 36 36 13 17 12 23 7 15 40 25 15 33 40 23 1 22 25 16 58 49 8 16 37 8 61 57 10 48 49 29 36 45 48 66 22 55 56 38 71 71 83 59 21 61 8 1 1 1 53 55 36 31 14 55 30 52 20 95 33 32 31 83 78 20 8...

output:

0 0 1517 17921 20669 17626 206 17626 23776 26571 18295 0 18295 12 187602 20669 10007 893 3177 84677 187602 20669 31382 17626 0 1517 34921 12 58 33999 222 893 77563 1 18530 24816 6158 2 18295 1736 10324 82656 219 179137 2 18295 12 187602 20669 218 12 56007 12 219 4378 21739 1736 893 893 23776 23776 3...

result:

ok 200000 numbers

Test #40:

score: 0
Accepted
time: 93ms
memory: 64104kb

input:

200000
0 1 2 3 1 1 0 6 7 3 0 9 4 2 4 14 9 10 3 3 15 4 0 19 15 25 23 26 25 5 29 13 23 17 7 1 12 26 13 34 13 5 39 26 17 30 19 9 6 10 22 8 6 0 38 8 27 5 26 25 26 18 4 37 46 1 22 24 48 58 29 15 26 14 27 7 47 31 3 5 1 52 79 37 67 11 16 53 88 13 42 76 85 18 67 77 6 3 41 99 74 74 79 68 104 48 32 32 69 68 7...

output:

0 0 54 28891 11 0 0 54 660 0 0 47520 830 392 53376 17797 7 93172 0 502 192764 2474 0 392 228 98959 7 74591 93172 303 169590 7 0 842 93172 392 28067 7007 5543 11 1 1452 1 174350 9516 4752 1 93172 392 0 4221 3414 0 0 392 28067 1724 86 0 0 60520 7 62255 1 61373 93172 77051 17340 660 730 11 0 33 4409 11...

result:

ok 200000 numbers

Test #41:

score: 0
Accepted
time: 97ms
memory: 64356kb

input:

200000
0 1 0 2 1 5 5 2 7 0 10 7 3 0 7 15 12 14 3 14 6 14 19 2 23 17 2 15 27 24 24 12 23 16 30 24 9 10 16 37 36 30 3 36 36 13 1 38 42 2 29 48 41 2 13 47 6 28 53 16 42 35 15 1 9 22 36 46 50 48 15 45 39 39 8 45 32 70 66 2 78 46 1 83 31 2 50 17 40 39 21 87 20 58 12 12 36 69 34 82 43 90 43 90 86 90 5 48 ...

output:

0 153693 0 0 0 10 0 0 65582 0 14 4031 14 0 1 139253 0 1 10 0 539 3 398 3 28801 153693 0 47 4031 112 101224 0 0 155625 0 165457 165838 153693 0 0 0 0 0 0 2186 8930 4031 65582 10 0 3 0 65582 4031 3601 4031 1871 8949 10 152222 1 14 0 0 3 19 65582 145588 153693 0 5 3 10 2186 2186 0 14 65582 334 1 1 1459...

result:

ok 200000 numbers

Test #42:

score: 0
Accepted
time: 112ms
memory: 64028kb

input:

200000
0 0 0 2 4 0 1 6 5 1 7 1 5 1 11 0 15 10 15 4 20 19 0 0 11 7 3 8 20 22 13 10 22 25 29 6 20 11 36 15 18 20 26 25 3 10 4 3 15 1 36 12 1 31 36 39 9 24 34 24 54 61 34 30 36 52 17 16 12 37 63 26 69 47 13 64 9 10 55 47 42 31 80 45 81 21 6 70 59 56 16 5 54 40 55 43 84 96 23 60 90 55 27 103 25 61 84 92...

output:

0 0 0 24 13902 0 34169 1568 600 16 16 1606 92837 1568 68 0 2 24 194 19436 34198 57040 0 0 8023 598 598 5367 27 133814 13721 91 191790 191790 34169 3 111 322 3235 2610 19436 11000 4067 45 34169 1134 21721 1 207 600 2059 7409 2 74335 11000 17221 650 598 1568 16 9762 14094 32846 18230 27 132840 1605 32...

result:

ok 200000 numbers

Test #43:

score: 0
Accepted
time: 98ms
memory: 64172kb

input:

200000
0 1 0 2 4 4 6 6 0 0 10 8 8 3 2 2 9 8 5 7 18 14 9 3 9 23 20 12 7 25 16 27 14 10 12 13 8 11 35 2 18 30 25 32 44 45 36 0 35 2 20 36 5 4 34 15 18 48 5 0 21 26 51 6 3 53 12 32 16 69 50 6 39 21 54 2 15 60 64 16 14 17 53 22 47 15 85 60 28 13 11 44 53 19 42 2 20 31 48 69 24 52 16 36 81 6 12 85 35 55 ...

output:

0 2267 0 3970 60 67743 34876 9196 0 0 2267 10682 9346 18020 5140 2931 2931 23292 124308 5460 53869 60 18020 949 1 949 5140 1 58749 8544 5140 27406 2267 18020 59328 1079 22144 4198 48 2357 1 9 817 18020 2267 3970 126313 0 60 9 93889 42065 63907 12083 60 2931 23781 22144 6349 0 123541 22144 44095 1099...

result:

ok 200000 numbers

Test #44:

score: -100
Time Limit Exceeded

input:

200000
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...

output:


result: