QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#446890#4631. Interesting String ProblemzlxFTH#TL 745ms273296kbC++143.4kb2024-06-17 17:24:132024-06-17 17:24:14

Judging History

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

  • [2024-06-17 17:24:14]
  • 评测
  • 测评结果:TL
  • 用时:745ms
  • 内存:273296kb
  • [2024-06-17 17:24:13]
  • 提交

answer

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

using i64 = long long;

struct SA {
  int n;
  vector<int> sa, rk;
  SA(const string &s) : n(s.size()), sa(n), rk(2 * n, -1) {
    iota(sa.begin(), sa.end(), 0);
    for (int i = 0; i < n; ++i) rk[i] = s[i];
    auto old = rk;
    for (int w = 1; w < n; w *= 2) {
      sort(sa.begin(), sa.end(), [&](auto u, auto v) {
        return rk[u] < rk[v] || rk[u] == rk[v] && rk[u + w] < rk[v + w];
      });
      swap(old, rk);
      rk[sa[0]] = 0;
      for (int i = 1; i < n; ++i) {
        rk[sa[i]] = rk[sa[i - 1]] + (old[sa[i]] != old[sa[i - 1]] || old[sa[i] + w] != old[sa[i - 1] + w]);
      }
      if (rk[sa[n - 1]] == n - 1) break;
    }
    rk.resize(n);
  }
};

constexpr int N = 5e5 + 5;

int n, sz, cnt[N * 30], ls[N * 30], rs[N * 30], rt[N];
int mdf(int x, int i, int l = 0, int r = n - 1) {
  cnt[++sz] = cnt[i], ls[sz] = ls[i], rs[sz] = rs[i];
  cnt[i = sz]++;
  if (l == r) return i;
  int mid = (l + r) / 2;
  if (x <= mid) ls[i] = mdf(x, ls[i], l, mid);
  else rs[i] = mdf(x, rs[i], mid + 1, r);
  return i;
}
int qry(int k, int i, int j, int l = 0, int r = n - 1) {
  if (l == r) return l;
  int mid = (l + r) / 2;
  if (cnt[ls[i]] - cnt[ls[j]] < k) return qry(k - cnt[ls[i]] + cnt[ls[j]], rs[i], rs[j], mid + 1, r);
  else return qry(k, ls[i], ls[j], l, mid);
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  string s;
  cin >> s;
  int n = s.size();
  SA _sa(s);
  auto sa = _sa.sa;
  ::n = n;
  for (int i = 0; i < n; ++i) {
    rt[i + 1] = mdf(sa[i], rt[i]);
  }
  vector<i64> pre(n + 1);
  for (int i = 0; i < n; ++i) {
    pre[i + 1] = pre[i] + i64(n - sa[i]) * (n - sa[i] + 1) / 2;
  }
  int q;
  cin >> q;
  vector<i64> a(q);
  for (int i = 0; i < q; ++i) {
    cin >> a[i];
  }
  auto b = a;
  sort(b.begin(), b.end());
  vector<int> o(q), ans(q);
  iota(o.begin(), o.end(), 0);
  sort(o.begin(), o.end(), [&](auto u, auto v) {
    return a[u] < a[v];
  });
  auto solve = [&](auto self, int l, int r, int ql, int qr, i64 res, int w) {
    if (l >= r || ql >= qr) return;
    if (l == r - 1) {
      for (int i = ql; i < qr; ++i) {
        int id = o[i];
        if (res + w + 1 < a[id]) {
          int li = w + 1, ri = n;
          while (li < ri) {
            int mi = (li + ri + 1) / 2;
            if (res + i64(w + 1 + mi) * (mi - (w + 1) + 1) / 2 < a[id]) li = mi;
            else ri = mi - 1;
          }
          res += i64(w + 1 + ri) * (ri - (w + 1) + 1) / 2;
          w = ri;
        }
        ans[id] = sa[l] + a[id] - res - 1;
      }
      return;
    }
    i64 dt = i64(w) * (w + 1) / 2;
    while (l < r && ql < qr) {
      int li = l, ri = r - 1;
      while (li < ri) {
        int mi = (li + ri + 1) / 2;
        if (s[sa[mi] + w] == s[sa[l] + w]) li = mi;
        else ri = mi - 1;
      }
      i64 len = ri - l + 1;
      i64 all = pre[ri + 1] - pre[l] - dt * len;
      i64 lens = len * (w + 1);
      while (ql < qr && res + lens >= a[o[ql]]) {
        ans[o[ql]] = qry((a[o[ql]] - res - 1) / (w + 1) + 1, rt[ri + 1], rt[l])
            + (a[o[ql]] - res - 1) % (w + 1);
        ql++;
      }
      int p = upper_bound(b.begin(), b.end(), res + all) - b.begin();
      self(self, l, ri + 1, ql, p, res + lens, w + 1);
      l = ri + 1;
      ql = p;
      res += all;
    }
  };
  solve(solve, 0, n, 0, q, 0, 0);
  for (int i = 0; i < q; ++i) {
    cout << ans[i] + 1 << "\n";
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

pbpbppb
3
1
2
3

output:

2
4
7

result:

ok 3 lines

Test #2:

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

input:

potatop
3
6
30
60

output:

6
3
4

result:

ok 3 lines

Test #3:

score: 0
Accepted
time: 153ms
memory: 15536kb

input:

dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd...

output:

323
644
809
442
923
155
645
275
443
779
441
563
830
495
442
71
699
649
467
204
755
274
394
316
604
211
503
455
764
515
691
541
76
369
695
734
953
440
322
808
693
690
565
116
420
861
179
358
640
687
735
796
581
473
593
859
876
666
596
587
515
616
58
425
470
707
556
735
194
789
819
788
582
666
525
270...

result:

ok 500000 lines

Test #4:

score: 0
Accepted
time: 143ms
memory: 15208kb

input:

gtgggtgttgggggtgtgggtgttggtttggggtggtgtgggttggtggggtgggttgttggttgggtttggggtgttgggggtgggttttggttgttggtggggttgttggtggtggggtgggttttgggttggtgggtgggtggttgtgttggttttttttgttgggtttgggtgttgttgtggtgggttttggttggggtgttggttggtgtggtgtgggttttggttttttgtttgtggtggtgttttgtttttggtggggtgtttgttgttttggggttggggtgggggttgtgg...

output:

791
715
455
614
589
333
462
296
719
129
801
506
651
668
60
784
111
326
964
356
442
261
328
390
482
320
382
555
729
612
819
154
591
442
890
652
359
652
832
676
670
359
575
146
304
402
71
626
510
209
601
705
29
722
579
502
904
229
712
76
940
897
403
810
506
832
422
183
365
648
659
344
621
478
268
605
...

result:

ok 500000 lines

Test #5:

score: 0
Accepted
time: 128ms
memory: 15132kb

input:

uuppuppuspusupspsuspsusssuupspppuuuusupspsssssusppsppsppsppsupuuupsssussupspsupsusssppsuuppspsuuspuppssppssusuussuuuupsspupssupuuppppsspuuspsupsususussupuppuuusspsuupppspspuupuppuuspssususpsususpsspsspssuuupuppppsupusupppsppspsuuusspupuspuspsusspsuspuspssuupuupsssupupppspppupsuspusppssusspspsuuuspsp...

output:

962
574
660
750
321
290
141
797
243
259
884
743
737
117
263
491
886
547
707
637
228
362
319
942
424
511
174
963
30
802
355
175
186
732
438
147
295
303
611
716
528
587
598
494
515
447
950
469
696
878
638
429
699
497
566
641
624
229
325
663
747
36
695
480
307
108
558
379
485
425
590
499
129
432
308
51...

result:

ok 500000 lines

Test #6:

score: 0
Accepted
time: 142ms
memory: 17100kb

input:

vqvvsvvvvqssssvxvxsvxvsvxxqsqxqvvxvqqsvvsqvvssqqxvxvqqxqxvqqsxvsqxqvvxxvsxvxxssssvqvvsxvqvvxxxsqxvxxsqssxvvxvsxsvsvvvxsxvsvsqvvvqsssvvvqxssqqqxvqqvsqqqsxqqxvvsqxqqvsxqqqqvqxxqvqvqqqvsvsvxsvssvqvqxsqqvxvqqqvqsssqxsvqvsqqxqqqqxsxxxsvsqqqxvssssxssqxsxxvxqxvqsxxxqxssxxvsxxxqqvsqxsxxxxqxvsqsvsqsqssvsxqsv...

output:

632
645
793
548
149
257
583
737
498
191
455
342
416
572
682
546
730
158
683
772
369
410
637
367
398
201
385
878
615
531
578
603
773
560
723
46
763
497
645
798
480
476
352
871
301
514
614
907
301
378
52
147
686
646
721
132
185
716
614
799
720
266
143
161
319
409
750
403
190
775
746
718
378
839
537
58...

result:

ok 500000 lines

Test #7:

score: 0
Accepted
time: 141ms
memory: 15304kb

input:

hcccjchdjcccjchhhdjnjdhdhdhjhjnhdcjdjjdddchchdhnhnddjdccdchcjddhcdhhcnhcjjjdjcjndcchcjnnddhdjhdddjnncnjdchhhdjcjhdjjdcjdncdcccncdcncndcjcchdhhjnhjdjnnddcnjnhcdhdnhnhjdjjjdhcdhhdjdjcdchcndcndnddjdnndjhdnndnhcdcnnchdcjndnhnnhhnddcjjndjnnhnccjhjjdhdhcndcjhjhcdccncjndhcdjndcdndnjdjhddchccdnhjnnchhhhhhjn...

output:

247
451
133
282
286
164
366
496
475
128
537
614
823
528
451
754
529
770
290
494
775
601
511
273
615
321
494
272
187
291
658
543
490
480
602
770
625
568
342
281
715
589
79
336
664
55
612
445
202
778
414
400
69
483
520
604
590
187
537
88
463
817
639
335
218
645
335
532
259
555
288
221
326
333
791
348
...

result:

ok 500000 lines

Test #8:

score: 0
Accepted
time: 140ms
memory: 15272kb

input:

cjggyjgjcffcgczjyjzjjzjgzcyzjczjffycjzccjycyjjyfyfzcjggggfcygcygjcjczcyzjffffyfzzzfzzgjyfccggzzgfygyzgcjgzfyczyyjggfyjyzjjjzyfzzzffcgygjzjjzfgzjfyjgjycfgygfgzcyfzjjjzfgfjjgjfyyzyfcfccfjgyzczczzfzgjgjzyfgzygfgjzjcyyjzyffyczzfjfgzyycygfcccyzzjcfcfccgffyjygcgfycyjjjfjjcjggjcfgcfgfjjcgzjzyffyccjfzycjggy...

output:

832
500
318
646
402
803
626
778
275
460
807
312
393
670
580
729
368
301
428
504
735
331
206
492
203
665
429
816
724
502
744
684
727
282
63
553
397
708
512
729
299
507
602
681
218
535
440
327
607
400
241
904
481
274
735
871
669
460
502
593
862
250
674
745
339
584
252
272
333
819
583
455
99
513
265
43...

result:

ok 500000 lines

Test #9:

score: 0
Accepted
time: 138ms
memory: 15096kb

input:

illulituiuyifyufffilyuilnynliiftnyinunltinnltluiltinuttuffiffitfylttiiltnuuiflfiuiuntiniluiinffyiylunnufitlltnntnufuiltnyuyunuflfilufilluinllttinntliufyytnifytfuunltlnffiiyluuifyftnyifnntfilliyyiunfiffyiytnytlnuilinfynunttnyttnuttiiittnntntytittiyyniiutfffynfuffiiilfyulffynnufuuuyiffuyyyfuitflntlnni...

output:

80
323
340
267
796
859
296
257
100
585
696
209
376
396
827
443
107
407
765
386
346
596
592
816
422
306
418
561
346
510
724
269
741
551
299
760
240
639
191
567
252
263
488
284
323
563
395
268
628
284
645
290
556
808
322
167
641
609
645
307
250
756
938
717
736
217
279
275
173
301
616
433
599
727
717
1...

result:

ok 500000 lines

Test #10:

score: 0
Accepted
time: 136ms
memory: 15268kb

input:

aykyaaucykauxckywnaxwwawxycxyanaayckkxuxccawukxkuaxnyxuxcxucynkkknkuuxwwxauyywxakkwwuwxkyuncuunxwkaxwnkawkxxxykwuauccyaanunkxawwxwckukykcuuxwnwxwcynnukwucukkwkayuyakuuxknaxknnkakkukukxucxkcnxcaxywaawuxaaxayknxwwyxkncnuwkuuxwywxxayxkukwxawnakyuxnkwkwaucxkknxxackuuyynkyccuucnuknynnyyucxnuxwwckwykawxyw...

output:

314
632
448
318
153
717
464
469
279
634
511
747
851
273
548
406
614
490
130
222
68
47
635
559
840
406
339
144
584
600
941
672
237
537
451
769
342
459
522
789
601
352
383
395
585
713
304
406
637
408
794
674
424
638
378
330
241
193
847
509
895
363
605
366
293
239
657
459
460
343
663
518
837
355
633
20...

result:

ok 500000 lines

Test #11:

score: 0
Accepted
time: 140ms
memory: 17164kb

input:

iyaaobwiwaawywiovmaabvwomwmmobwvowoywiawmimimfvyyywvimvofwwmvfwfowbyombmmmbboooobvmfvfoawiwymfoomiwivyvobfwivmfiayyofvmvammwmbfowifmmoaifwaiovywbfymifmibobiawoiiiabfwomwiayobwyvvommafabmmmmiiibiwvbbmommbofbyvmvfwiowaovyyoywmwbyfmmbmvyimwoiivmmomyvbmommoavmbbiimovfiafwiaffbbffiymvvoiwwywowaoofayyafif...

output:

183
956
637
305
204
263
879
544
658
538
382
635
673
486
411
239
188
89
281
768
566
708
249
227
388
827
388
357
978
203
524
227
608
600
643
835
436
63
558
387
89
698
239
233
526
491
270
839
498
523
696
944
766
925
842
56
705
367
464
174
537
127
535
368
687
466
139
870
279
86
593
703
586
899
422
779
6...

result:

ok 500000 lines

Test #12:

score: 0
Accepted
time: 139ms
memory: 15040kb

input:

vbvvddssmuqqsybsyygvqviduqbgiviqbbsqgisgvyguiqyssqiyuiumsbuiyqgqivqvbysvdmuigvsviubimbidbsygqdgsgdgqbdggidbbyuuddsdsvyivgddyyudmsuvgvdbmvdiuyyibuqdvvgqsuqmisubyqiudgyqmsmiysyussygbvyvsivimqqmviisvvbqsbqsgyiggbbimiqsmisiidqdusvivqvyibvvgmmbqsudigiiqdmdbubvbvusbyygydbqmdggvmqmdbdudidsymqbqbuiubmvqgduv...

output:

463
682
567
495
449
309
588
253
736
105
362
309
282
910
434
734
670
741
810
616
331
695
804
273
347
262
830
251
515
351
677
275
832
718
12
188
53
476
769
220
575
825
509
808
361
468
354
797
684
240
182
469
162
166
349
757
549
395
572
258
616
123
405
589
647
314
611
796
816
650
394
608
40
176
409
203...

result:

ok 500000 lines

Test #13:

score: 0
Accepted
time: 135ms
memory: 15108kb

input:

btcuswtwttuulltfdllcdcyccdqwyfbqlyqbqwuqqquccqqluqqsuswfbqtcbdtldfylsllfbddtbdcbwdbcdwwbqcdtcudqdcylwstttduddbubwysydqqsyswwqfcutyyclyqlqfbwscycwttdfsldfssfqftydcftldwfuubyfqfscfwbstcylblqftsqbdybydbtcbfqlcqtssbtulyfstuytdwcbbylqutqlcfwtuwwqldycusqwwyluqwwubfyllqcqfstcufwlwulcbbwdsudfltqtdcsclyylywt...

output:

250
786
289
222
220
212
705
946
856
337
580
497
792
174
172
699
89
378
888
447
155
795
599
619
543
523
492
368
319
470
478
429
715
136
201
647
792
203
565
560
160
792
682
601
866
728
239
792
416
272
557
583
221
853
290
695
13
762
314
356
553
623
345
477
647
585
530
326
334
105
474
447
388
510
579
29...

result:

ok 500000 lines

Test #14:

score: 0
Accepted
time: 138ms
memory: 15120kb

input:

sblrorbgldylcdrxooszdrxciizgrlgcxrobrldirgxdxgcoscszlzlydyllzxdzirsxscsozrglbdgbxbgdbsxorlxxcgxizdxgoxocicxdiislosrxocxgszxixczrbllisdbgcsyzxlliidzdxdsoyrbcizcblrdxillybszbycxyicdbcssdlsiixizrlgobzoizcdrdrzlrigblziyrzrooczdiogdodbsyslcdcgrzycoiosxblixizdsglxdrisszcgisilbxgobiygzdiysxxydcxxrlbcrgzdiy...

output:

897
785
754
226
868
764
631
345
798
779
522
748
401
155
702
266
469
287
680
808
195
819
77
883
91
328
423
493
520
363
196
414
330
920
349
496
428
473
435
521
727
872
796
680
578
363
518
456
521
416
532
380
742
732
429
605
315
147
777
569
519
606
816
146
308
587
540
313
775
843
233
106
667
317
217
49...

result:

ok 500000 lines

Test #15:

score: 0
Accepted
time: 134ms
memory: 15096kb

input:

zcfkrrjhbjkzrafjbfvcbhfckpkkgsrvjcjkhcrrsazcjcvbajhpaazapasacszskzzbsbpszhfrpjgjhgpaappvzhjrgrfzzbszkzaccksjhsjczbvhkpzzkarkjzvzvzcbvfshazvpfbzcpkfrjfbachksgzrsagkgzvvavzkppbvjcvjgzavgvfjjvhgczzvhfhcrcjsskzpvrzvbgzbgzrghgkjgaafghgjhcvbgvzrbhjrfjsakbrbscjfpkcsbhjzfkrjpkrpsgkahfkjrakzzjjvcaphkjvhfzkgh...

output:

314
530
217
222
163
509
286
290
589
843
533
543
366
827
440
571
925
223
646
294
683
251
533
112
590
448
741
504
493
652
339
45
307
421
343
493
643
198
810
715
546
617
531
568
575
411
424
225
392
675
149
642
603
192
297
698
529
395
471
775
783
301
481
478
742
318
346
479
754
405
642
357
437
634
842
3...

result:

ok 500000 lines

Test #16:

score: 0
Accepted
time: 142ms
memory: 15340kb

input:

nctmfuwtjtktmkwlfpmjuwnklufnftrjuwpcjrntuwpkwpphwckfqrmqtkcmltmhufcmjtmhtuqfhclnnluuwpjqwmtpwkppfnclcjpchkkmwnutrhwnpnmhcuctffkcpflqnjrnjnfkhwmnmcpwrrttpnwcfnqrjlqmtkncfcqjufkjctlwmhnfcnhpnmmktnjphpmnqwcjqmmfjukllwurnccmqhquhrfumqlmtmthchuphpullnmmthpwrhwlkpujlkphnftpnhtnlkmunfnpqjfjpppnmmqtfjwnfhcc...

output:

555
466
88
100
586
159
839
920
180
519
487
492
251
766
377
264
611
400
423
658
479
239
671
698
352
157
537
124
141
385
853
523
705
595
677
580
694
490
529
648
863
818
523
668
775
923
648
489
399
161
146
239
276
376
694
915
337
745
833
554
469
751
172
949
582
606
501
332
120
605
245
827
26
806
808
84...

result:

ok 500000 lines

Test #17:

score: 0
Accepted
time: 135ms
memory: 15264kb

input:

qpwnfmpwfufwiieehpfuwuepigxfuevgepiuihmwformmurfrxueurfvnxrimhihxfofonqhpreffrnhnefhqxwopiupouqqogomoohienioworxfwugrigehxixiifefrgrfgqvorngnvqwwfxeouiegxfohivmhqvqiihmoxwgnughgewmxpuqfrpvrvpmureumnxqehnwnqrgghwwieopxmnpmvimfqvmmhviepxinropffvngwhourxguvhuripfpniugevigrgmonvqieeqxpiqwvfmxvmevhmhhiuw...

output:

825
442
454
437
589
662
540
633
664
417
129
710
313
295
756
727
745
747
822
807
990
835
590
304
122
153
241
476
27
826
243
645
936
79
550
328
450
479
621
953
583
397
947
510
844
233
458
210
506
864
612
336
940
428
560
881
156
405
156
225
418
824
452
599
415
653
444
495
358
544
275
424
323
564
767
78...

result:

ok 500000 lines

Test #18:

score: 0
Accepted
time: 122ms
memory: 17176kb

input:

tgaxtbbpxabtqufqkucxqzhqraobozqpiftzbafxhcbuqhuiifhtrrpihobxxcuttfqhpkrzkbpotaghbqtupoqpoczahtpczbxikrioxbpxctpxbgocqbahqobitipfhoqragtqrcgcihgotichpuzcqkoobhhgtutihrpgxkbqxohgcthffhcfopfapbphqfapgzqgahupfagzzhpopkbgtfcqafpubqhzizzqtgqpkopioxbzahihrqiaappxzgzxxrccxpiafpbxiffoquhuibbchxukziqcfcfopzxg...

output:

214
800
730
369
127
702
475
496
765
402
300
763
805
230
161
309
704
468
845
348
611
476
157
781
227
292
759
187
96
793
734
742
414
583
500
144
781
787
397
377
562
554
395
495
234
335
273
436
622
707
322
764
561
704
504
481
453
472
229
240
475
701
535
117
495
521
198
349
266
449
727
877
655
522
736
1...

result:

ok 500000 lines

Test #19:

score: 0
Accepted
time: 138ms
memory: 15128kb

input:

wwtjqqtttozlzdsjwfkojmsvlofvkhvrvdzlmwzkshqlfzmgkzqklkjhztvjwgtmxvrglwmvkottxsftmwmsvgqmgqhrsszwdkldjkvtlvtzlvgfzwvszqsohkdgflgvlfgkmxmfvosxhsjsomxmsgtozwrogkrffgqwmtlljwsqxshgtkmdkwrktdzfwxljjvosxjqogxmrvomqzoqkrkvtlmgqfgjzfsrfwdrwzskdtjlsodzhwxxfdwjljzoofdqtdhjwolktjgdjwxzhtxrdstrrrwsgdmwgorldllho...

output:

75
169
331
747
547
740
691
629
199
527
592
470
186
715
383
480
408
153
539
438
482
364
388
513
748
600
50
67
562
204
930
141
630
282
803
588
806
588
302
327
613
711
687
248
662
509
538
741
635
299
607
561
461
227
181
915
236
439
340
160
131
572
492
427
374
495
859
199
674
850
790
868
507
876
463
376...

result:

ok 500000 lines

Test #20:

score: 0
Accepted
time: 133ms
memory: 15052kb

input:

iadnxnxelwnjiiwxcteaxpcmphvwphjidjpnwimahcjtmvizihxhsnammddtzevjvoimnhlxjnmjwihaxcpepneacwpmjeevtpvsdzsmaztzclaeoxdntaoazxllsemascencxopanjaxdcntipxedxzjdeipidwmzovesvtoijshcwcixjievvdoadilojazolcnldahxiswppmdjzwlmnanmcpvewjhihdmstixstsijlwotlpmlpsxlevzainmznatvzllihtjpnpxlnhedmpwlwhvxitatjcniapoije...

output:

352
605
309
148
612
282
515
561
681
628
493
883
485
795
649
778
342
630
756
646
781
537
444
442
445
824
736
570
244
433
393
363
424
185
919
162
453
808
712
540
277
281
713
360
199
434
804
51
584
557
928
291
846
554
774
494
255
443
608
627
144
818
836
630
435
504
525
292
544
211
696
232
438
131
136
9...

result:

ok 500000 lines

Test #21:

score: 0
Accepted
time: 133ms
memory: 15140kb

input:

yqoopvwnfaubnvwpybhpbjoonfiqbvjbuyhyvvbjusiniphqcbuynkvheonvvhkkfbycuknmmvawjefuwyjppccakqjcfaoeiwvfhyipwhhkswhswjoaubvhuqoncfwemnqnucpusscahavbijffcbffqnfafamvmmoschhyenfnhwfouipmwebfinyyqjhimwopjbhypsuqwynyjbocjysubhbyshjnoeefcwyhpaiihnbupoeebickkqewkwnjiwkhbyioupqmkychimpopsonuvwmwkffvqpcnbmhqhmp...

output:

685
699
668
733
424
825
474
262
517
437
342
661
656
176
898
370
591
746
676
497
530
477
361
637
588
320
426
394
247
130
379
195
314
632
491
449
365
420
270
456
468
398
487
630
694
514
914
832
32
402
530
370
242
802
416
431
421
175
542
243
489
479
810
346
80
770
381
594
523
874
522
572
750
305
33
646...

result:

ok 500000 lines

Test #22:

score: 0
Accepted
time: 138ms
memory: 15096kb

input:

nlofuytixdmtwouugdfosniyfodlpmlmftlewdsptcecnlynddneysyceudxcismpluopzexnpzttxppfzonmgpmnuemiyfzfxzegbvsxziwezwmnleyogxpcdvivynstweupygspivlcpomnbfusgiudiollwlvtxsdswcnupxzositewmnwnzcwmptisdvtbsiwtupoppximyfvuiytfyvfcpsocelpevcvntultngnmgiluucsixbxbzgyecuetzecbndlgbvteptfbscnonextldlgbeybimcczmugdn...

output:

339
774
271
325
91
772
620
853
375
938
288
878
245
771
652
338
393
558
46
523
672
169
834
244
535
889
665
298
41
553
431
625
380
485
58
326
438
668
267
599
592
133
374
429
895
484
379
616
71
781
549
547
481
168
609
795
690
786
720
497
641
755
249
681
919
466
291
378
610
492
574
580
616
349
786
336
8...

result:

ok 500000 lines

Test #23:

score: 0
Accepted
time: 142ms
memory: 15136kb

input:

evgsxyszizjvkayssyjimmvexcignjtcgpqztggfgjiqccnjugafqiyafspiegpmanhgevghxxasigntxgvfuvgmzzxfgfvogzggfqekkszfauhpjezffvtktkxyxcktzfsvueokzsmpfiiyauxeuuecokqteyaajmnyzygnnmzgshnyopfiysxuzoezfzvaonhvogsxkqmcspmoeeiyqkkfmcyieegyhgsnqxqvahyegohspkyecujsisixkuvymivkzjaqopeksnshsegyhemaqityucjhegjycghukpii...

output:

684
884
353
433
715
517
304
179
855
729
615
400
272
609
727
589
173
417
613
714
559
616
859
705
306
772
422
314
681
206
355
516
369
826
476
434
60
548
193
530
238
532
524
164
809
426
126
346
818
386
43
86
574
411
230
466
548
280
450
682
99
767
464
625
305
147
32
391
709
866
947
119
748
701
421
818
6...

result:

ok 500000 lines

Test #24:

score: 0
Accepted
time: 133ms
memory: 15332kb

input:

ovoojjlcfwuqpcneuhknkcvqkiuotuwfsczcpokkryumycqebwzpwjehopuyfiwihovecyqewqzuuerieszwutuwfjtkznsenirjthcptrjribfkeihyusrufntjjtsecrpqrubclfooykroczvhqywpnfwkjyjmwmpnyciskmumzsrsjspqqusefmoofvoszfizrrcnjqnbvzreemesrvorkmhitwzejmrhcikscosymjvcmjecmuzmsthkqwycwpbouineiflnqucyohriqmkykhflqrmpijqlwjfmyttf...

output:

531
706
107
412
248
638
317
865
266
419
869
257
331
601
266
318
400
638
481
582
371
328
416
589
239
466
517
481
661
386
610
665
281
380
413
122
308
712
486
608
491
558
506
618
770
500
497
499
807
588
436
619
879
481
648
114
634
622
738
670
577
838
467
423
587
146
674
371
606
92
197
418
393
317
569
3...

result:

ok 500000 lines

Test #25:

score: 0
Accepted
time: 137ms
memory: 15344kb

input:

nvhhpnuysrbeuylwdgivwbsiegwrhbhbxybyludoaqewloavndbxenhaionhlyonwqxtvddyaftayskertyufnhwxklhousuvnatorulwxrkkbdrtfxtdrtunygukdlccfldgducurcfsfvxdbqahkpnivukfwqncpprbkxlouwcbqypcqeqtsbxghhiairctwordktkoancfgsckdvqsrcnkpsbecoctuulyrapqiwrsnrcoqdxrpyrhdcxsvfxfekslxlprssvtrwsalgyhthvdnhvesfeucdccirfirkq...

output:

674
115
623
625
75
750
871
647
575
641
559
519
704
398
764
805
667
437
375
932
205
712
207
876
590
264
936
75
460
121
647
420
309
215
255
287
262
320
511
941
107
498
713
373
822
508
536
658
562
183
314
341
542
758
740
852
735
90
667
569
150
513
827
750
367
445
858
528
439
886
987
873
669
743
952
411...

result:

ok 500000 lines

Test #26:

score: 0
Accepted
time: 133ms
memory: 15032kb

input:

qnclwkavcnrqyegjasqqsrjsnsybneliwmocgacduivkussloxklajrloagadudikenalwmozevggcarbikgvaamjelqateowqsjhxqsgamabjtignibxidhxyxxxdzdiottlgeoujgihlndxlvoeoincmtooouveahrttnznuswogsudngbdynsrlgkwmbdducdquorudwqkatwybezekxwxvdwkngxoaakcowkwcebvmdgudguogwbstzewdgikohtdsujwngxcehgtorzcxlyxhtabrmojqtdcwxribvd...

output:

719
201
476
708
469
696
747
397
887
248
175
359
504
218
684
655
671
504
799
758
737
391
545
556
204
910
414
435
160
700
726
198
386
733
622
402
257
580
375
251
251
260
286
226
333
457
114
302
206
825
457
391
149
646
724
640
407
149
691
575
291
282
592
195
462
507
614
885
162
825
444
874
637
612
561
...

result:

ok 500000 lines

Test #27:

score: 0
Accepted
time: 133ms
memory: 15136kb

input:

wyegkiddibdhattrwgvqqtznwnqteeafiyenwsislkaqhhkuhrkkadcmfkrookocynirclwasnpcypxrxsaonsfyedmtkmyeugcuaureyrotbfchclwfdnwobktrkixmdowoucsfkwluwxslozpxbafqietyatqgedpvxibqseobffwzwxnroifyfrqnnmgmrulsscyztwybupzuavfuyuvqxwkgtnqxrfoizzrwtaxiynkszmzuzrzitermqcarybxpwftiogdakopapwbmahtzdesnwloydxyydyuomnyt...

output:

802
656
792
425
37
437
647
557
740
593
339
394
100
236
492
201
394
567
197
509
266
558
140
732
381
710
718
488
220
485
400
531
687
567
491
482
499
467
666
627
707
236
632
619
334
713
233
752
184
644
461
466
407
921
355
192
661
187
832
619
259
398
843
363
412
269
551
272
420
639
693
690
527
827
624
1...

result:

ok 500000 lines

Test #28:

score: 0
Accepted
time: 143ms
memory: 15100kb

input:

mwmbcwtvwdrdwvmyeyxufotofxicsyxfuqvvgsmdmgaxgnefqcqmzdmxbkyaknbiiyxrvzedyadwzhrhdjnfxgscujrucnbejcygcccyqmeywhducissvvvvemkunevwdoebknnxtowyqwhpzlqpobqavbhtstrmriruxgkjrgoxbtosifmswgaseayewttdnqpcusxzjlevymiphhkbbmfrdjfucckzgphdaefgkumbmwyoytgiefibzqkbrcyneetwzxiikxwscugrlcezesjmtspioelcetkebqugxozz...

output:

927
203
480
27
138
402
495
638
450
473
848
598
585
482
267
600
928
574
822
331
202
782
520
543
223
717
402
590
714
665
384
879
477
603
488
223
328
40
316
469
723
649
391
403
487
615
475
219
609
602
622
490
808
381
696
263
329
919
944
498
578
695
602
545
240
453
281
454
437
686
548
729
830
431
863
18...

result:

ok 500000 lines

Test #29:

score: 0
Accepted
time: 745ms
memory: 273296kb

input:

llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll...

output:

204534
339376
229188
372153
306595
299296
135190
120175
59425
262135
373840
443124
248058
473765
384090
267790
389699
215949
119753
297288
187439
348956
353347
235360
228801
335856
84112
461468
381302
105245
359765
170287
460565
308835
144604
225539
149961
105019
216586
112974
175784
227004
260885
2...

result:

ok 500000 lines

Test #30:

score: -100
Time Limit Exceeded

input:

osoossooosoooossssssssosossoossoooosoosoosossoosoosssosossososssossossssssoooosossoossoosssosssssossoossososoososooooososoosooosssoooosssoosossoooosooooososssssossosssssossoosoooossoooosooooossssossosoooosssssossooosssosossossoososoosssoosssoossoosooosoossooosooossosssoooossossoooossoosoososssoosooo...

output:


result: