QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#696800#7901. Basic Substring Structureucup-team3646AC ✓113ms71600kbC++206.5kb2024-11-01 01:57:262024-11-01 01:57:26

Judging History

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

  • [2024-11-01 01:57:26]
  • 评测
  • 测评结果:AC
  • 用时:113ms
  • 内存:71600kb
  • [2024-11-01 01:57:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define elif else if
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>

#define repname(a, b, c, d, e, ...) e
#define rep(...) repname(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__)
#define rep0(x) for (int rep_counter = 0; rep_counter < (x); ++rep_counter)
#define rep1(i, x) for (int i = 0; i < (x); ++i)
#define rep2(i, l, r) for (int i = (l); i < (r); ++i)
#define rep3(i, l, r, c) for (int i = (l); i < (r); i += (c))

struct ScalarInput {
  template <class T>
  operator T() {
    T ret;
    cin >> ret;
    return ret;
  }
};
struct VectorInput {
  size_t n;
  VectorInput(size_t n) : n(n) {}
  template <class T>
  operator vector<T>() {
    vector<T> ret(n);
    for (T& x : ret) cin >> x;
    return ret;
  }
};
ScalarInput input() { return ScalarInput(); }
VectorInput input(size_t n) { return VectorInput(n); }

template <typename T>
void print(vector<T> a) {
  for (int i = 0; i < a.size(); i++) {
    cout << a[i] << " \n"[i + 1 == a.size()];
  }
}

template <class T>
void print(T x) {
  cout << x << '\n';
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head << ' ';
  print(forward<Tail>(tail)...);
}

vi sa_is(vi& s, int up) {
  int n = s.size();
  if (n == 0) return {};
  vi sa(n), ls(n), sml(up + 1), sms(up + 1);
  for (int i = n - 2; i >= 0; i--) {
    ls[i] = (s[i] == s[i + 1]) ? ls[i + 1] : (s[i] < s[i + 1]);
  }
  rep(i, n) {
    if (!ls[i])
      sms[s[i]]++;
    else
      sml[s[i] + 1]++;
  }
  rep(i, up + 1) {
    sms[i] += sml[i];
    if (i < up) sml[i + 1] += sms[i];
  }

  auto induce = [&](vi& lms) {
    rep(i, n) sa[i] = -1;
    vi buf = sms;
    for (auto d : lms) {
      if (d == n) continue;
      sa[buf[s[d]]++] = d;
    }
    // print(sa); // -1 1 4 7 -1 -1 -1 -1 -1 -1 -1 (mississippi の例)
    buf = sml;
    sa[buf[s[n - 1]]++] = n - 1;
    rep(i, n) {
      int v = sa[i];
      if (v >= 1 && !ls[v - 1]) sa[buf[s[v - 1]]++] = v - 1;
    }
    // print(sa); // 10 1 4 7 0 9 8 3 6 2 5

    buf = sml;
    for (int i = n - 1; i >= 0; i--) {
      int v = sa[i];
      if (v >= 1 && ls[v - 1]) sa[--buf[s[v - 1] + 1]] = v - 1;
    }
    // print(sa); // 10 7 1 4 0 9 8 3 6 2 5
  };

  vi lms, mp(n + 1, -1);  // mp : lms の inverse
  int m = 0;
  rep2(i, 1, n) {
    if (!ls[i - 1] && ls[i]) {
      mp[i] = m++;
      lms.push_back(i);
    }
  }
  // print(mp); // -1 0 -1 -1 1 -1 -1 2 -1 -1 -1 -1

  induce(lms);

  if (m) {
    vi srt, rec(m);  // srt = sorted_lms
    for (auto v : sa) {
      if (mp[v] != -1) srt.push_back(v);
    }
    int tmp = 0;
    rec[mp[srt[0]]] = 0;
    rep2(i, 1, m) {
      int l = srt[i - 1], r = srt[i];
      int el = (mp[l] + 1 < m) ? lms[mp[l] + 1] : n;
      int er = (mp[r] + 1 < m) ? lms[mp[r] + 1] : n;
      bool same = true;
      if (el - l != er - r)
        same = false;
      else {
        while (l < el) {
          if (s[l] != s[r]) break;
          l++;
          r++;
        }
        if (l == n || s[l] != s[r]) same = false;
      }
      if (!same) tmp++;
      rec[mp[srt[i]]] = tmp;
    }
    // print(rec); // 1 1 0
    // print(srt); // 7 1 4
    vi rec_sa = sa_is(rec, tmp);

    rep(i, m) srt[i] = lms[rec_sa[i]];
    induce(srt);
  }
  return sa;
}

vi LCP(vi s, vi sa) {
  int n = s.size();
  vi rank(n), lcp(n - 1);
  rep(i, n) rank[sa[i]] = i;
  for (int i = 0, h = 0; i < n; i++) {
    if (rank[i] + 1 < n) {
      int j = sa[rank[i] + 1];
      while (max(i, j) + h < n && s[i + h] == s[j + h]) h++;
      lcp[rank[i]] = h;
      if (h > 0) --h;
    }
  }
  return lcp;
}

template <typename T>
struct SparseTable {
  using F = function<T(T, T)>;
  F op;
  vector<vector<T>> st;
  vi lookup;

  SparseTable(const vector<T>& v, const F& op) : op(op) {
    int n = v.size();
    int b = 0;
    while ((1 << b) <= n) b++;
    st.assign(b, vector<T>(n));
    rep(i, n) st[0][i] = v[i];

    for (int i = 1; i < b; i++) {
      for (int j = 0; j + (1 << i) <= n; j++) {
        st[i][j] = op(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
      }
    }
    lookup.resize(n + 1);
    for (int i = 2; i < lookup.size(); i++) {
      lookup[i] = lookup[i >> 1] + 1;
    }
  }

  T query(int l, int r) const {
    int b = lookup[r - l];
    return op(st[b][l], st[b][r - (1 << b)]);
  }
};

int op(int a, int b) { return min(a, b); }

void solve() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  vi sa = sa_is(a, n);
  vi inv(n);
  rep(i, n) inv[sa[i]] = i;
  vi la = LCP(a, sa);
  SparseTable<int> st(la, op);

  auto calc = [&](int i, int j) -> int {
    if (i == j) return n - i;
    if (i >= n || j >= n) return 0;
    int posi = inv[i];
    int posj = inv[j];
    if (posi < posj) return st.query(posi, posj);
    return st.query(posj, posi);
  };

  ll init_ans = 0;
  vll d0(n + 1, 0), d1(n + 1, 0);
  vector<unordered_map<int, ll>> mp(n);
  rep(l, n) {
    int len = calc(0, l);
    int l1 = 0;
    int r1 = len;
    int l2 = l;
    int r2 = l + len;
    init_ans += len;

    if (l == 0) continue;

    if (r1 <= l2) {
      d0[l1] += -len;
      d1[l1] += 1;
      d1[r1] -= 1;

      d0[l2] += -len;
      d1[l2] += 1;
      d1[min(n, r2)] -= 1;
    }

    else {
      d0[l1] += -len;
      d1[l1] += 1;
      d1[r2] -= 1;
      d0[l2] -= l2 - l1;
    }

    if (l + len == n) continue;

    // 増加する可能性があるやつ

    int d = calc(len + 1, l + len + 1);

    // a[len] を a[l + len] に置き換える
    if (len < l2) {
      mp[len][a[l + len]] += d + 1;
    }
    // a[l + len] を a[len] に置き換える
    int d2 = min(l - 1, d);
    int pos1 = len + 1 + d2;
    int pos2 = l + len + 1 + d2;
    if (pos1 == l + len && pos2 < n && a[len] == a[pos2]) {
      int d3 = calc(pos1 + 1, pos2 + 1);
      mp[l + len][a[len]] += d2 + d3 + 2;
    } else {
      mp[l + len][a[len]] += d2 + 1;
    }
  }

  vll diff(n, 0);
  ll tmp0 = 0;
  ll tmp1 = 0;
  rep(i, n) {
    tmp0 += d0[i] + tmp1;
    diff[i] = tmp0;
    tmp1 += d1[i];
  }

  vll ans(n);
  rep(i, n) {
    ll mx = 0;
    for (auto [key, val] : mp[i]) {
      if (key != a[i]) mx = max(mx, val);
    }
    ans[i] = init_ans + diff[i] + mx;
  }
  ll ANS = 0;
  rep(i, n) ANS += (i + 1) ^ ans[i];
  print(ANS);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int T;
  cin >> T;
  rep(T) solve();
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

2
4
2 1 1 2
12
1 1 4 5 1 4 1 9 1 9 8 10

output:

15
217

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 25ms
memory: 3808kb

input:

10000
8
2 1 2 1 1 1 2 2
9
2 2 1 2 1 2 1 2 1
15
2 1 2 1 1 1 1 2 2 1 2 1 2 2 1
2
1 1
10
2 1 1 1 2 2 1 1 2 2
3
2 1 2
11
1 2 2 1 1 2 1 2 2 1 1
14
2 1 1 1 1 2 1 1 1 2 2 1 2 1
12
2 2 2 1 2 2 2 1 1 2 1 2
4
2 1 1 2
8
1 2 2 2 1 2 1 1
8
1 1 2 1 2 1 1 1
6
2 1 1 1 2 2
14
2 2 1 1 1 1 2 2 2 1 2 2 1 1
10
1 2 2 1 1...

output:

94
128
347
3
211
9
265
363
278
15
95
114
58
348
225
3
335
364
377
316
3
19
122
66
15
83
36
258
11
63
28
90
85
103
252
191
21
48
303
63
102
20
24
68
316
362
266
309
355
281
326
281
231
312
3
330
54
328
3
69
32
147
322
39
338
90
242
3
165
346
245
20
155
3
404
393
392
81
269
360
20
54
21
279
3
17
351
3...

result:

ok 10000 lines

Test #3:

score: 0
Accepted
time: 44ms
memory: 3592kb

input:

10000
17
1 2 2 2 2 2 2 2 1 1 2 2 1 2 1 2 2
17
2 1 1 1 1 2 2 2 1 1 1 1 1 2 2 2 2
13
2 2 2 1 2 2 2 2 1 1 1 1 1
12
2 2 1 2 1 2 2 1 1 1 1 1
13
2 2 2 1 1 1 1 2 2 2 2 1 1
20
2 1 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 2 1 1
13
1 2 1 2 2 2 1 2 1 2 1 1 1
20
2 1 1 2 2 1 2 2 1 1 2 1 2 2 2 2 2 1 2 2
12
2 1 2 1 1 2 2 1 2...

output:

392
434
308
252
302
895
343
867
282
249
717
194
252
350
230
427
439
279
340
384
380
292
218
312
271
810
275
211
460
388
365
342
773
203
238
857
720
497
514
443
618
777
372
242
337
232
324
837
289
480
366
681
358
281
320
529
451
309
250
326
315
744
307
841
133
214
411
788
332
365
488
157
760
278
421
...

result:

ok 10000 lines

Test #4:

score: 0
Accepted
time: 48ms
memory: 3880kb

input:

10000
10
3 3 1 2 2 3 3 3 2 3
13
1 2 1 2 1 1 3 1 2 2 1 3 1
14
1 2 1 2 3 3 2 3 1 2 2 2 3 3
10
1 1 1 1 1 1 3 2 1 2
19
1 3 3 3 1 3 3 2 1 1 1 3 2 2 1 2 1 3 2
12
1 3 1 3 1 1 3 2 3 3 2 3
11
1 1 1 2 2 3 1 1 3 1 1
12
3 2 2 1 3 3 2 1 1 3 3 2
11
2 2 3 2 3 1 3 1 2 1 1
20
3 1 2 2 3 1 3 3 1 3 3 2 3 3 3 2 3 1 1 2
...

output:

191
285
325
207
420
281
215
280
151
754
365
199
94
418
318
377
414
285
373
362
111
358
332
117
185
326
89
404
229
386
307
285
421
232
321
329
506
372
386
364
153
582
313
356
152
129
424
366
382
280
363
370
273
294
388
389
807
388
459
280
114
310
211
368
150
166
793
211
793
393
102
427
399
408
584
38...

result:

ok 10000 lines

Test #5:

score: 0
Accepted
time: 52ms
memory: 3632kb

input:

10000
14
9 9 13 6 3 8 7 10 5 9 14 2 12 5
15
9 12 2 2 8 4 2 11 4 4 8 3 8 13 15
19
5 7 1 2 9 2 16 9 15 8 19 9 3 18 8 8 1 12 6
14
9 8 2 11 7 2 12 5 14 14 10 5 7 2
11
4 4 2 9 9 11 10 3 3 2 2
14
8 2 9 10 10 11 6 9 12 5 5 4 9 2
20
4 5 3 13 15 18 12 6 2 8 11 12 6 10 14 14 10 14 13 12
14
11 9 7 5 12 12 5 3 ...

output:

307
362
380
107
97
137
380
108
135
299
312
265
99
362
379
361
332
380
129
367
97
380
97
107
363
107
132
367
97
88
363
314
100
382
354
349
383
95
359
306
340
133
382
106
395
361
374
105
292
385
360
359
365
381
378
107
374
111
357
105
365
319
379
102
364
89
107
374
128
101
360
115
363
107
106
116
92
3...

result:

ok 10000 lines

Test #6:

score: 0
Accepted
time: 51ms
memory: 3744kb

input:

1331
128
1 1 2 1 1 1 1 1 1 1 1 1 1 2 2 2 1 1 2 1 2 2 1 1 2 1 2 1 2 1 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 2 2 2 2 2 1 2 1 2 1 2 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 1 2 2 1 1 1 2 1 1 1 1 1 1 1 2 2 2 2
115
1 2 2 1 2 2 1 2 2 1 2 1 2 2 2 1...

output:

41073
22779
19964
77764
77960
62759
68522
21651
24781
42049
74437
19840
74378
68878
20605
34809
20231
20004
50820
29156
52217
53156
23540
67367
57400
46500
19870
60423
66032
51371
59540
51300
48277
22751
77712
65779
21946
37124
65635
40091
27911
55656
54005
18564
25013
64077
46260
21753
62329
69899
...

result:

ok 1331 lines

Test #7:

score: 0
Accepted
time: 48ms
memory: 4104kb

input:

131
1471
2 3 2 3 1 2 2 1 1 1 1 2 1 3 2 1 1 1 2 2 2 2 2 2 3 1 3 2 1 2 3 2 3 1 3 1 2 1 3 1 3 1 3 2 2 1 3 3 3 1 1 1 3 2 2 2 1 2 1 3 1 3 3 1 2 2 1 2 3 1 3 1 3 3 2 1 3 3 2 3 2 2 2 1 3 2 1 2 2 1 3 1 1 3 2 3 1 1 2 1 2 3 2 1 3 3 2 2 2 2 1 1 1 2 3 1 1 3 3 2 3 2 1 3 1 3 3 2 2 1 2 1 1 2 1 3 2 1 2 2 3 2 2 1 1 3...

output:

4103972
1822893
4056671
4581950
1797128
5452459
5578024
6135700
4325429
1769997
1239977
1589696
5346072
1818448
5380837
3882106
3814365
1823901
4911982
5946018
5208392
4261893
1767953
5781183
4624024
1795249
1600563
1677098
4679442
4113663
1685240
1576241
5128042
1618422
4440641
4326472
5703872
3748...

result:

ok 131 lines

Test #8:

score: 0
Accepted
time: 42ms
memory: 4244kb

input:

131
1104
15 10 15 18 8 16 25 26 11 19 4 5 9 15 20 8 8 1 5 12 6 15 15 9 19 6 20 8 9 10 12 1 7 26 9 15 26 14 18 24 25 4 9 20 16 18 25 10 8 2 15 14 26 19 22 17 8 7 23 19 22 26 23 4 26 8 16 6 19 5 17 4 9 25 7 14 19 26 9 21 23 7 20 2 12 22 23 24 20 11 23 23 7 13 6 26 25 10 8 17 23 15 14 20 16 7 21 8 11 1...

output:

1585911
1671116
2074604
2071604
2066710
1571959
1699180
1597972
1573443
2062834
1968749
1670339
1696389
1700722
1574014
1673122
6093159
1965764
1966052
2084891
1597710
1989656
2054890
1659456
1601397
1982947
1675608
2075393
1694022
1992153
6012239
1675824
1987812
1589514
2063346
1986943
1571712
1671...

result:

ok 131 lines

Test #9:

score: 0
Accepted
time: 61ms
memory: 10012kb

input:

14
554
232 178 169 417 93 38 93 537 212 211 313 227 432 269 475 489 459 286 318 534 118 160 223 534 275 382 482 331 3 279 73 513 403 277 34 497 462 397 280 218 395 498 201 548 8 520 495 397 545 528 401 58 418 3 494 260 251 496 212 552 243 151 78 385 441 73 271 337 283 39 162 1 501 357 126 452 416 34...

output:

394027
127388087
408947528
132597056
403149770
403022905
410881136
404226176
134192573
106965642
108543004
108541542
109002658
408924618

result:

ok 14 lines

Test #10:

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

input:

1
200000
86045 57533 29508 181370 17680 186294 134595 82393 109229 189798 133533 194579 11412 112604 572 32659 76824 177596 106427 60375 98302 93821 34541 125615 108609 22507 166292 195457 151376 54630 166314 85832 192590 85410 149595 46737 54738 198246 56457 189628 135013 63949 28359 65601 162502 4...

output:

32219923494

result:

ok single line: '32219923494'

Test #11:

score: 0
Accepted
time: 32ms
memory: 8576kb

input:

14
11651
1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 2...

output:

638847269
762853260
1772624286
1459420676
912238973
902965748
1461240613
1591772671
978996498
1450864204
913255377
276655999
898402422
1129219843

result:

ok 14 lines

Test #12:

score: 0
Accepted
time: 66ms
memory: 61656kb

input:

1
200000
1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 2...

output:

241162217617

result:

ok single line: '241162217617'

Test #13:

score: 0
Accepted
time: 73ms
memory: 61960kb

input:

1
200000
1 2 3 2 3 1 3 1 2 2 3 1 3 1 2 1 2 3 3 1 2 1 2 3 2 3 1 2 3 1 3 1 2 1 2 3 3 1 2 1 2 3 2 3 1 1 2 3 2 3 1 3 1 2 3 1 2 1 2 3 2 3 1 1 2 3 2 3 1 3 1 2 2 3 1 3 1 2 1 2 3 2 3 1 3 1 2 1 2 3 3 1 2 1 2 3 2 3 1 1 2 3 2 3 1 3 1 2 3 1 2 1 2 3 2 3 1 1 2 3 2 3 1 3 1 2 2 3 1 3 1 2 1 2 3 1 2 3 2 3 1 3 1 2 2 3...

output:

179830061352

result:

ok single line: '179830061352'

Test #14:

score: 0
Accepted
time: 45ms
memory: 41876kb

input:

2
147441
101973 109734 101973 101973 109734 101973 109734 101973 101973 109734 101973 101973 109734 101973 109734 101973 101973 109734 101973 109734 101973 101973 109734 101973 101973 109734 101973 109734 101973 101973 109734 101973 101973 109734 101973 109734 101973 101973 109734 101973 109734 1019...

output:

319151712710
36323502547

result:

ok 2 lines

Test #15:

score: 0
Accepted
time: 67ms
memory: 55764kb

input:

1
200000
90579 86359 90579 90579 86359 90579 86359 90579 90579 86359 90579 90579 86359 90579 86359 90579 90579 86359 90579 86359 90579 90579 86359 90579 90579 86359 90579 86359 90579 90579 86359 90579 90579 86359 90579 86359 90579 90579 86359 90579 86359 90579 90579 86359 90579 90579 86359 90579 863...

output:

605969434886

result:

ok single line: '605969434886'

Test #16:

score: 0
Accepted
time: 46ms
memory: 56440kb

input:

1
200000
1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1...

output:

142983226845641

result:

ok single line: '142983226845641'

Test #17:

score: 0
Accepted
time: 48ms
memory: 56964kb

input:

1
200000
1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2...

output:

666704973725917

result:

ok single line: '666704973725917'

Test #18:

score: 0
Accepted
time: 37ms
memory: 52464kb

input:

1
200000
24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 ...

output:

1000022503780497

result:

ok single line: '1000022503780497'

Test #19:

score: 0
Accepted
time: 54ms
memory: 9572kb

input:

15
13418
7463 7463 7463 7463 9685 7463 1028 1028 9685 7463 9685 9685 7463 9685 7463 9685 9685 7463 7463 9685 7463 7463 7463 9685 7606 9685 1028 1028 9685 9685 9685 7463 1028 9685 9685 9685 9685 7463 3766 3766 7463 9685 9685 7132 7132 9685 1028 7463 3766 1028 7463 1028 9685 9685 1028 3766 9685 9685 3...

output:

310854214
1449822
411519250
114103279
422847646
111080594
345051865
115761752
373321070
416817676
270343906
133687081
436456350
116337980
244991146

result:

ok 15 lines

Test #20:

score: 0
Accepted
time: 49ms
memory: 8584kb

input:

13
14791
2035 8168 8168 2035 2035 2035 8168 2035 2035 8168 2035 2035 2035 2035 2035 2035 2035 2035 2035 8168 2035 2035 2035 2035 2035 2035 2035 2035 2035 8168 2035 2035 2035 2035 2035 2035 2035 2035 2035 8168 2035 2035 8168 2035 2812 2035 8168 2035 8168 2035 8168 2035 2035 8168 8168 9546 2035 2035 2...

output:

371530128
851134952
1442447610
1086437389
1314950262
1069313993
1418963743
58759634
413581446
389752815
405059048
222613748
292855398

result:

ok 13 lines

Test #21:

score: 0
Accepted
time: 43ms
memory: 6948kb

input:

15
12956
1461 1461 1461 1461 1461 1461 12553 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 12553 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 12553 1461 1461 146...

output:

949186410
1955289437
1313255408
642243147
6111494
1702549476
1650717366
1049298027
1087170445
1259299037
3413417858
1529936217
776579634
1552800994
1881266475

result:

ok 15 lines

Test #22:

score: 0
Accepted
time: 38ms
memory: 8580kb

input:

15
14395
12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 13111 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 122...

output:

2957212969
1012208565
4531357191
3436243590
1743046033
9523735
500043796
2288646068
1429987616
2528370581
2183643497
375636659
2556639949
4614333790
7205785399

result:

ok 15 lines

Test #23:

score: 0
Accepted
time: 76ms
memory: 60384kb

input:

1
200000
70309 96346 70309 70309 70309 92160 96346 70309 70309 96346 92160 70309 171045 70309 96346 96346 92160 96346 96346 190333 190333 70309 96346 127508 96346 92160 92160 70309 70309 70309 70309 92160 92160 70309 70309 70309 70309 127508 70309 92160 92160 70309 70309 70309 125471 96346 127508 12...

output:

118752316928

result:

ok single line: '118752316928'

Test #24:

score: 0
Accepted
time: 54ms
memory: 48504kb

input:

1
200000
94840 94840 94840 94840 94840 94840 94840 94840 61989 61989 94840 94840 94840 94840 94840 94840 94840 61989 61989 61989 94840 94840 94840 61989 94840 94840 137895 94840 94840 137895 94840 61989 94840 94840 94840 94840 137895 94840 94840 94840 94840 94840 94840 61989 94840 61989 94840 94840 ...

output:

181441989888

result:

ok single line: '181441989888'

Test #25:

score: 0
Accepted
time: 43ms
memory: 45312kb

input:

1
200000
127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 106778 127581 127581 126279 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 106778 127581 127581 127581 127581 127581 127581 127581 1275...

output:

342833548104

result:

ok single line: '342833548104'

Test #26:

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

input:

1
200000
108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 1081...

output:

324538309517137

result:

ok single line: '324538309517137'

Test #27:

score: 0
Accepted
time: 46ms
memory: 7520kb

input:

15
10201
9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9...

output:

66439462066
251506268492
47876221702
360857682629
170540379619
372628422983
120664261073
90488919597
131928493181
245296890810
147831394137
71074052989
200069312998
99252210523
114381508405

result:

ok 15 lines

Test #28:

score: 0
Accepted
time: 39ms
memory: 8352kb

input:

14
16198
7198 10333 7198 8585 7198 10333 7198 11443 7198 10333 7198 8585 7198 10333 7198 7479 7198 10333 7198 8585 7198 10333 7198 11443 7198 10333 7198 8585 7198 10333 7198 15505 7198 10333 7198 8585 7198 10333 7198 11443 7198 10333 7198 8585 7198 10333 7198 7479 7198 10333 7198 8585 7198 10333 719...

output:

33797343297
22554529801
20751677835
62270648577
32014149216
12021999751
12471359017
41454739199
39883
8044814272
40206190585
57228063674
55271122747
21989607289

result:

ok 14 lines

Test #29:

score: 0
Accepted
time: 34ms
memory: 7504kb

input:

15
10719
3676 2811 3676 4133 3676 2811 3676 9001 3676 2811 3676 4133 3676 2811 3676 9153 3676 2811 3676 4133 3676 2811 3676 9001 3676 2811 3676 4133 3676 2811 3676 3616 3676 2811 3676 4133 3676 2811 3676 9001 3676 2811 3676 4133 3676 2811 3676 9153 3676 2811 3676 4133 3676 2811 3676 9001 3676 2811 3...

output:

839203489
1583465103
1267108649
1161524911
983492553
1703733329
2346605125
1321148771
2395175732
1794419616
9621305
1338471889
2718202141
2229391426
2130319327

result:

ok 15 lines

Test #30:

score: 0
Accepted
time: 40ms
memory: 52624kb

input:

1
200000
55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062...

output:

1000022503780497

result:

ok single line: '1000022503780497'

Test #31:

score: 0
Accepted
time: 35ms
memory: 53864kb

input:

1
200000
72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 727...

output:

500036262654563

result:

ok single line: '500036262654563'

Test #32:

score: 0
Accepted
time: 55ms
memory: 55484kb

input:

1
200000
27791 128643 27791 193841 27791 128643 27791 133709 27791 128643 27791 193841 27791 128643 27791 119129 27791 128643 27791 193841 27791 128643 27791 133709 27791 128643 27791 193841 27791 128643 27791 50096 27791 128643 27791 193841 27791 128643 27791 133709 27791 128643 27791 193841 27791 ...

output:

2142743374731

result:

ok single line: '2142743374731'

Test #33:

score: 0
Accepted
time: 79ms
memory: 55512kb

input:

1
200000
5270 20262 5270 159584 5270 20262 5270 79361 5270 20262 5270 159584 5270 20262 5270 85380 5270 20262 5270 159584 5270 20262 5270 79361 5270 20262 5270 159584 5270 20262 5270 88540 5270 20262 5270 159584 5270 20262 5270 79361 5270 20262 5270 159584 5270 20262 5270 85380 5270 20262 5270 15958...

output:

333618035630

result:

ok single line: '333618035630'

Test #34:

score: 0
Accepted
time: 9ms
memory: 16652kb

input:

1
65535
3747 3747 3747 10894 3747 3747 3747 10894 3747 3747 3747 10894 3747 3747 3747 26741 3747 3747 3747 10894 3747 3747 3747 10894 3747 3747 3747 10894 3747 3747 3747 26741 3747 3747 3747 10894 3747 3747 3747 10894 3747 3747 3747 10894 3747 3747 3747 26741 3747 3747 3747 10894 3747 3747 3747 1089...

output:

47438786836

result:

ok single line: '47438786836'

Test #35:

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

input:

1
35279
8061 20053 8061 20053 8061 7600 8061 20053 8061 20053 8061 7600 8061 20053 8061 20053 8061 7600 8061 20053 8061 20053 8061 3625 8061 20053 8061 20053 8061 7600 8061 20053 8061 20053 8061 7600 8061 20053 8061 20053 8061 7600 8061 20053 8061 20053 8061 3625 8061 20053 8061 20053 8061 7600 8061...

output:

14553907525

result:

ok single line: '14553907525'

Test #36:

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

input:

1
46655
16305 16305 16305 16305 16305 25259 16305 16305 16305 16305 16305 25259 16305 16305 16305 16305 16305 25259 16305 16305 16305 16305 16305 25259 16305 16305 16305 16305 16305 25259 16305 16305 16305 16305 16305 44685 16305 16305 16305 16305 16305 25259 16305 16305 16305 16305 16305 25259 1630...

output:

29457295223

result:

ok single line: '29457295223'

Test #37:

score: 0
Accepted
time: 0ms
memory: 3928kb

input:

1
446
276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 27...

output:

22257618

result:

ok single line: '22257618'

Test #38:

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

input:

1
88199
42997 42997 42997 42997 17665 42997 42997 42997 42997 17665 42997 42997 42997 42997 17665 42997 42997 42997 42997 17665 42997 42997 42997 42997 17665 42997 42997 42997 42997 17665 42997 42997 42997 42997 2010 42997 42997 42997 42997 17665 42997 42997 42997 42997 17665 42997 42997 42997 42997...

output:

109207566120

result:

ok single line: '109207566120'

Test #39:

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

input:

1
89999
85746 85746 17901 85746 85746 82896 85746 85746 17901 85746 85746 82896 85746 85746 17901 85746 85746 82896 85746 85746 17901 85746 85746 82896 85746 85746 17901 85746 85746 82896 85746 85746 17901 85746 85746 82896 85746 85746 17901 85746 85746 82896 85746 85746 17901 85746 85746 82896 8574...

output:

30384952146665

result:

ok single line: '30384952146665'

Test #40:

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

input:

1
79999
36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 3682...

output:

45337130318924

result:

ok single line: '45337130318924'

Test #41:

score: 0
Accepted
time: 2ms
memory: 5232kb

input:

1
8199
2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 235...

output:

68933371983

result:

ok single line: '68933371983'

Test #42:

score: 0
Accepted
time: 0ms
memory: 6804kb

input:

1
19999
17486 17486 17486 17486 17486 17486 17486 17486 17486 13014 17486 17486 17486 17486 17486 17486 17486 17486 17486 13014 17486 17486 17486 17486 17486 17486 17486 17486 17486 13014 17486 17486 17486 17486 17486 17486 17486 17486 17486 13014 17486 17486 17486 17486 17486 17486 17486 17486 1748...

output:

5406246293

result:

ok single line: '5406246293'

Test #43:

score: 0
Accepted
time: 52ms
memory: 64096kb

input:

1
200000
60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 605...

output:

750042248291481

result:

ok single line: '750042248291481'

Extra Test:

score: 0
Extra Test Passed