QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#188599#4914. Slight Hopehos_lyric100 ✓1497ms490356kbC++147.7kb2023-09-26 03:48:312023-09-26 03:48:31

Judging History

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

  • [2023-09-26 03:48:31]
  • 评测
  • 测评结果:100
  • 用时:1497ms
  • 内存:490356kb
  • [2023-09-26 03:48:31]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")

////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

constexpr unsigned MO = 998244353;
using Mint = ModInt<MO>;


int N, Q;
vector<Mint> A;
vector<int> P;

Mint brute(int L, int R) {
  static Mint dp[5010];
  copy(A.begin() + L, A.begin() + R, dp + L);
  Mint ans = 0;
  for (int u = R; --u >= L; ) {
    if (P[u] < L) {
      ans += dp[u] * dp[u];
    } else {
      dp[P[u]] += dp[u];
    }
  }
  return ans;
}


// long path decomposition
// assumes P[u] < u
namespace la {
constexpr int E = 18;
int pp[E][1 << E];
vector<vector<int>> graph;
vector<int> dep, hei;
int seqLen;
vector<int> seq;
vector<int> head;
vector<int> pt;
void build() {
  copy(P.begin(), P.end(), pp[0]);
  for (int e = 0; e < E - 1; ++e) for (int u = 0; u < N; ++u) pp[e + 1][u] = (~pp[e][u]) ? pp[e][pp[e][u]] : -1;
  graph.assign(N, {});
  for (int u = 1; u < N; ++u) graph[P[u]].push_back(u);
  dep.assign(N, 0);
  for (int u = 1; u < N; ++u) dep[u] = dep[P[u]] + 1;
  hei.assign(N, 0);
  for (int u = N; --u >= 1; ) chmax(hei[P[u]], 1 + hei[u]);
  for (int u = 0; u < N; ++u) for (int j = 0; j < (int)graph[u].size(); ++j) if (hei[graph[u][0]] < hei[graph[u][j]]) swap(graph[u][0], graph[u][j]);
  seqLen = 0;
  seq.assign(2 * N, -1);
  pt.assign(N, -1);
  head.assign(N, -1);
  for (int u = 0; u < N; ++u) if (!~head[u]) {
    const int below = 1 + hei[u];
    const int above = min(dep[u], below);
    pt[u] = seqLen + above;
    seqLen += (above + below);
    head[seq[pt[u]] = u] = u;
    for (int x = 1; x <= above; ++x) seq[pt[u] - x] = P[seq[pt[u] - x + 1]];
    for (int x = 1; x < below; ++x) head[seq[pt[u] + x] = graph[seq[pt[u] + x - 1]][0]] = u;
  }
// cerr<<"graph = "<<graph<<endl;
// cerr<<"seq = "<<seq<<endl;
// cerr<<"pt = "<<pt<<endl;
// cerr<<"head = "<<head<<endl;
}
int jumpUp(int u, int d) {
  assert(0 <= u); assert(u < N);
  assert(d >= 0);
  if (dep[u] < d) return -1;
  if (d == 0) return u;
  const int e = 31 - __builtin_clz(d);
  const int v = head[pp[e][u]];
  return seq[pt[v] - dep[v] + (dep[u] - d)];
}
}  // la


constexpr int K = 550;
vector<vector<Mint>> f, g;

int qid;
vector<int> app;
vector<Mint> fs;

void build() {
  la::build();
// for(int u=0;u<N;++u)for(int d=0;d<N;++d)cerr<<u<<" "<<d<<": "<<la::jumpUp(u,d)<<endl;
  
  f.assign(N / K + 1, {});
  g.assign(N / K + 1, {});
  for (int x = 0; x <= N / K; ++x) {
    const int r = x * K;
    f[x].assign(r + 1, 0);
    g[x].assign(r + 1, 0);
    for (int u = 0; u < r; ++u) f[x][u] = A[u];
    for (int u = r; --u >= 1; ) f[x][P[u]] += f[x][u];
    for (int u = 0; u < r; ++u) g[x][u + 1] = g[x][u] + f[x][u] * f[x][u];
  }
  
  qid = 0;
  app.assign(N, 0);
  fs.assign(N, 0);
}

Mint query(int L, int R) {
  ++qid;
  const int M = lower_bound(P.begin() + L, P.begin() + R, L) - P.begin();
  const int x = R / K;
  const int r = x * K;
  Mint ans = 0;
  if (L < min(M, r)) {
    ans += g[x][min(M, r)] - g[x][L];
  }
  for (int u = max(L, r); u < R; ++u) {
    int v = la::jumpUp(u, max(la::dep[u] - la::dep[L] - 1, 0));
    if (L <= P[v]) v = P[v];
    if (app[v] != qid) {
      app[v] = qid;
      fs[v] = (v < r) ? f[x][v] : 0;
    }
// cerr<<"u = "<<u<<": v = "<<v<<"; "<<fs[v]<<" -> "<<(fs[v]+A[u])<<endl;
    ans += A[u] * (fs[v] + fs[v] + A[u]);
    fs[v] += A[u];
  }
  return ans;
}


int main() {
  for (; ~scanf("%d%d", &N, &Q); ) {
    A.resize(N);
    for (int u = 0; u < N; ++u) {
      scanf("%u", &A[u].x);
    }
    P.resize(N);
    for (int u = 1; u < N; ++u) {
      scanf("%d", &P[u]);
      --P[u];
    }
    P[0] = -1;
    
    build();
    
    int lst = 0;
    for (int q = 0; q < Q; ++q) {
      int L, R;
      scanf("%d%d", &L, &R);
      L ^= lst;
      R ^= lst;
      --L;
// cerr<<COLOR("33")<<"query ["<<L<<", "<<R<<")"<<COLOR()<<endl;
      const Mint ans = query(L, R);
      printf("%u\n", ans.x);
#ifdef LOCAL
if(N<=5000){
 const Mint brt=brute(L,R);
 if(brt!=ans)cerr<<L<<" "<<R<<": "<<brt<<" "<<ans<<endl;
 assert(brt==ans);
}
#endif
#ifdef LOCAL
if(N==250000)continue;
#endif
      lst = ans.x;
    }
  }
  return 0;
}

详细

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 14ms
memory: 20768kb

input:

5000 5000
63141398 126604376 697512251 741353996 356604726 507953968 494219271 973110260 460861914 988416009 970876787 448429588 725493166 883501210 51076237 784293761 8003146 766721589 406465089 330785670 782582116 501008987 936941546 564663613 40330818 320342607 566652836 806983548 79234347 581976...

output:

148388816
822655068
341356275
153648250
610508782
658092334
115032444
61006948
232896592
132532556
281147472
170577711
453242756
564024529
950510296
417644928
35757971
824080049
490493323
96124139
158766038
597702738
69672015
841035419
405236159
258190228
66326403
227299828
359113584
34672879
117324...

result:

ok 5000 numbers

Test #2:

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

input:

5000 5000
208095035 189388209 910573484 151351163 857032742 409791136 427941504 561340305 440094307 848312088 743662365 160219901 584491656 208412392 473499824 79323110 469342548 790678258 903532373 940176368 916303640 12519872 294579622 875495570 887250524 595928577 642259826 222149097 873031301 42...

output:

597291565
466590571
543666430
955934901
739756468
993328702
393451173
956126185
739018480
946329402
990581650
589085210
656552878
941726143
200128337
610853683
191337824
450787673
494378602
960833257
772065473
317098668
597989053
965678661
839020241
790226238
400110943
786188793
733806002
190637300
...

result:

ok 5000 numbers

Test #3:

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

input:

5000 5000
758829686 846421586 795445842 923423765 650851801 380291052 781540894 445139283 780903169 45635176 303532742 70594608 850028582 748168745 597843692 246704898 350529309 7279358 973729172 269517593 22112036 125333845 309121459 968441730 686776540 975145839 926379079 346059534 292798462 19216...

output:

463197740
26979945
961115125
585910970
224451566
822036760
183497285
813892643
8997869
291414695
131978485
899584925
779621202
716522212
879375421
91045492
330290371
691691224
52633475
340848115
186272999
890054530
911975959
514382765
763838056
167285656
930279525
785049503
150045446
570741767
97509...

result:

ok 5000 numbers

Test #4:

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

input:

5000 5000
831640431 885460668 883290311 161278701 616481017 280845019 388780100 404687561 721779426 228266599 363600658 948454460 388371957 246028605 655768029 731008092 605246260 564445876 760408308 26166250 71491179 320543409 377278440 522729682 703367018 322884625 692206745 411811213 557175990 77...

output:

973564643
126270676
513879186
160315552
474692304
502474019
656022067
882003880
105940288
652267128
369294132
107152190
559575798
752075334
355587403
735085822
578199820
483981812
74890692
358519217
379879058
32070627
446003765
10882971
382837033
282137994
909326140
46106521
358500230
735281951
3598...

result:

ok 5000 numbers

Test #5:

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

input:

5000 5000
386586821 473104785 923115322 80627280 723972117 76500891 901470530 40141226 605413269 508843738 568157568 511437103 387870706 707269439 370782055 605387529 647770332 427178306 213279296 635360385 647527011 43127485 265465400 93955214 147422318 973617973 166812244 700732812 611016742 80446...

output:

789940086
697637206
408002193
990320561
762711381
901590837
762961896
271872873
291306692
551854139
437673271
270540330
691269003
978607745
525751254
343060584
72443046
300879617
278943004
760067231
235472075
976841481
936605508
479647311
686662820
58080719
886417986
681348294
512210247
340704136
86...

result:

ok 5000 numbers

Test #6:

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

input:

5000 5000
792216357 552236642 821494867 527714453 169575822 820595714 51053252 285231608 834824001 795954150 856055581 789265115 391543052 623878414 831103431 973063635 851485478 722429924 377946447 74393554 229570805 77829523 104941568 904281532 519848089 214665346 829017846 170077097 530089743 975...

output:

231592521
710420358
76758915
241413386
430224292
922200556
894399093
539685138
594923071
860157611
94869286
900661909
4590133
587348986
920780522
790820661
536438280
976402941
439797034
327200752
920824344
894723053
962589436
412895743
843160266
488926976
317592562
384947824
445153417
711558885
8449...

result:

ok 5000 numbers

Subtask #2:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #7:

score: 20
Accepted
time: 253ms
memory: 42024kb

input:

50000 50000
768966868 59696813 88144593 167570175 440425517 667021648 50234623 250465092 611066949 942141813 37909983 544761802 310089692 393644730 822735225 212716527 45802184 416983999 978914560 514007472 271601592 803603476 153018866 463206234 430926936 205142491 621149405 347663094 909171725 990...

output:

535964317
498669705
110235462
577178694
458409211
180052579
833120408
528030659
854656432
578186212
647551642
106109933
785867614
715665434
119860891
227206432
978129416
355043244
824024937
889456087
653872988
218204727
768257490
147883304
92932220
842681002
700378724
973977972
293932154
820122893
4...

result:

ok 50000 numbers

Test #8:

score: 0
Accepted
time: 165ms
memory: 41648kb

input:

50000 50000
926434242 833464466 818417327 197100897 15934287 644632732 232006706 557905827 95530335 953397962 584509490 134039675 456180816 88153497 341272750 905812813 623878180 753926638 345776279 455413981 491623547 971836681 670535283 525534014 876800156 818154122 115494771 967365768 513073832 9...

output:

50189578
614003924
406679462
891916825
854664555
383564578
656197644
2618026
701413889
802641599
87893214
112489935
882216004
256603507
510017739
429242037
619481996
800403686
180804571
620515587
694607788
124659042
803354134
599430985
133489716
153343561
718376448
482871834
148308285
176675015
3185...

result:

ok 50000 numbers

Test #9:

score: 0
Accepted
time: 171ms
memory: 42420kb

input:

50000 50000
771988922 212436623 804443396 817827846 830699527 784422632 729884276 912003446 995885315 824721340 837642183 283068922 372817603 100299803 60891115 676351412 641016821 983300431 887927410 950464053 960650766 801946150 981593160 201935570 609178140 408519531 929272301 588279454 605903956...

output:

331430307
842168506
514428667
355689311
865723558
272088222
5106326
724323283
63969592
24689102
375126359
172043952
425829760
749877111
327857093
646470881
65951216
305793882
95712629
723748855
433154753
809570577
771906309
477420435
245967760
460647924
923047416
272709139
700228441
906998284
174826...

result:

ok 50000 numbers

Test #10:

score: 0
Accepted
time: 180ms
memory: 42420kb

input:

50000 50000
900366749 674207154 742580520 423717735 53773991 646025272 25689686 304532836 101502882 140887825 84382607 434523825 626129678 318135577 937888950 303284365 836439804 651694084 478701931 947065798 684677978 332843230 554104599 912552910 417149550 163252218 881219604 924426344 842413390 6...

output:

866369968
233793457
165937004
573866572
499141399
50069437
126848823
357332948
487646929
199006759
335058982
690767657
892697514
805303044
886885871
694863196
5801194
954769260
109473624
573415210
828217282
59732343
505053373
352386067
840363722
636894175
425645259
208103655
473793746
127002236
7193...

result:

ok 50000 numbers

Test #11:

score: 0
Accepted
time: 169ms
memory: 42044kb

input:

50000 50000
128009702 835394168 195582915 237058448 308987847 332547707 3181530 522885776 607169352 843503488 560544297 234676319 754038773 971946242 251601569 713013731 449922156 964200243 270751518 485953250 983022206 416540821 96233750 773462469 218771460 869573801 1826928 217439825 101327578 643...

output:

809413913
900087043
897489309
490488662
860111942
389091241
845061538
685662609
477979480
990731474
975276464
524647592
959334221
279016791
579113462
806057027
834352370
414957639
135587999
772681462
736164077
81034876
768035946
828362323
685292149
417723235
77932963
281011135
28218190
682861276
258...

result:

ok 50000 numbers

Test #12:

score: 0
Accepted
time: 177ms
memory: 41952kb

input:

50000 50000
599691755 74459068 334593294 689318718 842905094 443210545 96280108 643838657 591570435 747119928 963798260 884441507 753584023 622768897 446596420 332458502 185519101 709830529 141249071 885916331 314791389 276299436 336855194 552443961 696874117 738278010 593700707 229502424 335910014 ...

output:

162968440
829114
814500713
268429015
476122947
818974632
467331763
12940232
70162519
26148936
753219232
517231641
428317039
509625675
870990487
600796230
385649006
922400831
368412364
536483891
715148335
810869176
206671100
908712544
377398265
119727728
226288513
266653103
263036296
547334935
552450...

result:

ok 50000 numbers

Test #13:

score: 0
Accepted
time: 214ms
memory: 41712kb

input:

50000 50000
509049147 846306934 497301582 156085268 418734386 738839401 463112303 670194644 148295378 897052920 337867193 22462071 304900070 737711091 665480978 823159855 481862593 827100577 316492474 693956517 618429668 870188133 65980921 940212747 403208852 268141196 171329777 255058173 740325554 ...

output:

395519880
988998325
123071413
493713767
662307084
960909185
899731232
660410246
707341210
28490302
887326532
11593659
417615875
848911573
573179668
137809591
475174820
133873443
756015822
372043435
654859285
863530053
521918428
957117123
712163801
591167143
206607972
85953124
12946789
66960555
99205...

result:

ok 50000 numbers

Test #14:

score: 0
Accepted
time: 214ms
memory: 41744kb

input:

50000 50000
271460757 98184763 207476207 318550358 36132989 163998764 834240576 816456648 104049969 565152081 639115703 63526614 540131202 584035121 125994524 103597578 198061629 69949079 246096816 249710935 309174260 770090066 306030177 506695475 716974345 478421640 989138506 146754109 896531147 87...

output:

227639846
402726965
215887242
144596012
768374615
60584104
132321406
817024981
963910026
42360689
737913188
348299774
276641697
65869541
636135686
129087361
794550831
458540944
2270242
99210275
74519859
983209150
670092005
849382923
682067660
418183252
61685226
144713076
943183123
543020736
32933718...

result:

ok 50000 numbers

Subtask #3:

score: 20
Accepted

Test #15:

score: 20
Accepted
time: 1452ms
memory: 486440kb

input:

250000 250000
768540930 17767906 372927484 987601476 466807233 279110163 484031897 581293130 869165405 440806324 190995959 228277657 510008046 885148108 825022142 732048181 608976903 327270073 923084855 752263987 475969665 911033413 561860569 377841111 401028041 117941740 350378391 295513473 2304741...

output:

645687892
804644292
204845058
833159303
438840602
426417420
912375389
325277630
897894204
651802587
232723981
612719545
449284803
97772899
900152796
609960724
641400352
204127911
176781081
752207129
720790544
624982826
923898464
696425075
641906962
568669044
49974863
45637134
16934743
814263646
3524...

result:

ok 250000 numbers

Test #16:

score: 0
Accepted
time: 1489ms
memory: 486320kb

input:

250000 250000
891116300 898356877 251723070 604671849 697052662 536848016 939693407 986573382 593450706 855565471 640899587 67478597 127577868 205200967 935001574 667983193 695063369 974771972 958840013 509047663 933018751 809878590 601610117 337290677 687704465 365112336 704196535 158405904 7278515...

output:

119336010
921443294
779683070
950551877
180248958
344824198
755825894
552477508
969820065
401891602
680193691
326353587
922152363
128919523
206197552
621042892
992122592
674625075
560913507
365647753
93734067
528767756
49194731
580013693
408137293
293884394
395805325
171434454
83012338
512032587
864...

result:

ok 250000 numbers

Test #17:

score: 0
Accepted
time: 1484ms
memory: 486320kb

input:

250000 250000
988998207 760388680 80877172 892847778 807199431 393547350 436490526 580450227 796105943 37118112 564378459 973015163 696339619 330864317 339107150 393054808 269903945 542034556 593508399 142447284 506346702 54826941 491062909 411280253 562632098 740794370 841286188 751650890 408061646...

output:

533479270
244359425
776984548
501658625
503647730
421165217
475383706
493748710
803957134
308028631
338652576
225743050
719589438
797270766
308210397
681648078
715232260
755309870
297023667
540327743
655176795
199967718
768390190
381825918
261506225
816338258
650716640
807889190
837604717
903940898
...

result:

ok 250000 numbers

Test #18:

score: 0
Accepted
time: 1476ms
memory: 486392kb

input:

250000 250000
82054290 888723988 925549675 334581140 696787014 591297195 24015805 250825352 455399696 29763540 339278830 610597821 29807173 237262484 567614041 186608691 582297589 858558005 946613881 84740258 747546189 286666089 526643626 856259798 96238988 789860420 678959410 683142401 842582154 43...

output:

185366931
801951859
356265156
462055598
126863911
949108884
412193442
213529342
464936198
390513058
492908470
412470588
49794849
694745450
799113332
757373572
111634187
780139796
206811208
297593116
215666373
588229368
129921558
277637592
192167089
750104385
43787346
966654517
181439099
622785017
21...

result:

ok 250000 numbers

Test #19:

score: 0
Accepted
time: 1437ms
memory: 486380kb

input:

250000 250000
303112864 577259977 305520229 955904347 408230826 263382697 14414636 918886374 372550214 528678589 225017216 378695342 29985355 399933915 507292974 962381308 958737761 702243621 838729080 353665889 928018619 162044348 121018117 947282353 481418612 587591271 898269843 805889605 35816203...

output:

585867031
201035063
490999542
736033151
895744149
914585406
837995141
208389376
776508499
640779260
838103956
230216004
710637540
829432702
693525890
745770938
516105287
569949793
581870756
84779525
105610416
745875258
701536062
383879261
237965240
488513885
471198096
114317593
689839166
867352849
5...

result:

ok 250000 numbers

Subtask #4:

score: 40
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #20:

score: 40
Accepted
time: 1089ms
memory: 486376kb

input:

250000 250000
1684 27592 26500 13048 4760 29684 15515 5159 20974 134 23909 27520 30454 1904 227 2452 28497 25053 30049 13839 3142 25354 11256 7474 2660 20823 7510 12676 15465 30110 27586 21956 23907 13507 26202 25377 19989 26508 20895 24494 16796 25779 6452 30992 7507 28986 20195 6009 4083 2815 6881...

output:

96805739
420659502
903298513
653391797
31584693
21333603
648135326
691422708
651502421
477431034
238029494
737658150
533593084
416924184
881552318
771216145
581451529
563971625
764611945
801800267
213752161
642275568
178651185
141795059
307732170
341959588
546615494
592854489
306671319
286287897
850...

result:

ok 250000 numbers

Test #21:

score: 0
Accepted
time: 1099ms
memory: 487888kb

input:

250000 250000
273454832 61165554 138978408 952167942 635817365 846849881 51983320 852242093 870031526 699882390 807849868 208112402 871431949 169868594 568585854 123479258 879148358 588122366 801409681 226744708 560897676 774847666 527032093 809571499 856702921 261475124 213818964 804136443 45145396...

output:

688246029
738768024
700299201
159787197
602586269
389742373
607912531
56775939
915113444
131816024
337546683
946234110
756953408
386879497
89080765
780665447
258681502
393468404
307916255
845849464
480086432
159354225
331723079
447232243
710183111
307545667
535515922
447103595
803052761
556146877
59...

result:

ok 250000 numbers

Test #22:

score: 0
Accepted
time: 1018ms
memory: 486500kb

input:

250000 250000
845661708 894214426 541561058 736979837 322802291 165893456 609113642 342937685 292467413 212735563 968770551 371078091 881365806 148688119 392637318 696487994 431461714 385798077 135953844 541102597 359826915 350081154 223588203 477955740 84392108 911799498 360547727 25279152 51258214...

output:

730570227
689104229
571666217
151459711
714373868
464935881
382779209
864817550
885715167
445233491
632583331
355398238
532372470
148938691
573927090
976067771
889182715
291086382
968344277
505706494
355641034
416206399
355398238
985756477
222015775
464935881
334260016
581636842
272233420
548547018
...

result:

ok 250000 numbers

Test #23:

score: 0
Accepted
time: 1007ms
memory: 486616kb

input:

250000 250000
977363486 180012423 110599277 454367372 415553248 102667517 537902367 785876905 797068885 950818874 752982444 304846363 48109952 906420206 481938316 615125212 842846382 155836031 399528071 102386303 585559370 444636696 710850937 176710682 548464548 359066604 81561018 786795375 57377947...

output:

694415709
559533518
708151991
62279815
425948308
139821639
655938530
282782096
733098378
521693385
200547282
790539899
292124457
314001387
122287087
969375427
61061117
622792353
622792353
862288865
140720257
143249801
122287087
222240462
997363992
146604531
866950861
374421858
376281049
840829443
61...

result:

ok 250000 numbers

Test #24:

score: 0
Accepted
time: 1172ms
memory: 486688kb

input:

250000 250000
980555690 369427259 473639057 950309534 848267012 658598026 65128458 795543041 319623008 742960899 230487249 524563728 856223084 834339002 213240867 775647167 773705695 61724210 29783807 34124384 47694009 236107067 899461307 801677303 500190363 340272535 259943680 151409241 504290388 7...

output:

693829110
295500135
579106566
377830874
343558379
187903485
101431411
567868212
727886380
573834190
335555762
923935544
669034236
516411510
778884325
780878041
340491922
676872446
335555762
819786629
477470468
187903485
937480882
676872446
86036689
708243366
688837230
337559980
888736997
615714561
4...

result:

ok 250000 numbers

Test #25:

score: 0
Accepted
time: 695ms
memory: 486616kb

input:

250000 250000
108180640 712788404 464345111 644200440 275726048 567360675 287863732 511371968 289940876 361314525 938128307 997745046 497896797 820778902 126020819 838170161 857517936 298532450 252785643 241071577 912275868 388990815 403875943 370236034 951274566 477433824 841947144 284178989 767895...

output:

216003542
253420577
104492939
264233000
109937956
899240811
446080699
81028094
775926609
825553192
413739755
497832643
731862975
134704537
514630921
963288223
586378523
578878966
885505053
714842857
465174535
867793597
104492939
294016200
458913181
449785952
320080485
955573556
701519852
54770267
92...

result:

ok 250000 numbers

Test #26:

score: 0
Accepted
time: 1162ms
memory: 490280kb

input:

250000 250000
893967818 413368243 95936001 671477683 430625665 301601967 942682717 281813776 799509515 617130893 354075654 125597267 768363026 963429347 132701697 775468486 166482455 99032698 483822135 927321522 739381313 849148488 553165616 845835001 806661122 410824858 440369153 842447243 26205542...

output:

593820435
144495423
77218615
810556630
280282853
863118439
291177560
928782703
763577305
926448383
647553200
551683574
425352646
624247253
261031294
735012124
47423445
160738642
356849307
123826611
881471042
444713533
898477371
630875403
908300427
861755981
890957384
891238724
424496256
268200554
61...

result:

ok 250000 numbers

Test #27:

score: 0
Accepted
time: 1132ms
memory: 490356kb

input:

250000 250000
694433866 677391079 596493624 189913523 801732953 256568081 404172180 349367112 748689549 9643467 897741295 298190724 773918860 978688640 952017342 83842158 894767935 549252356 940589381 329401451 286412855 118702867 964739882 518633149 459069899 490903261 464177363 719265226 8714793 9...

output:

342423925
300428247
457299501
958179993
101894865
336941157
117254359
739891611
799502835
406868994
501185409
699104698
479742507
547261007
331570170
402292387
326290753
292105133
389431818
252655403
232801824
131528111
632746750
12976537
481975561
35218095
959896180
60936461
897345065
934366037
579...

result:

ok 250000 numbers

Test #28:

score: 0
Accepted
time: 1053ms
memory: 486544kb

input:

250000 250000
444039540 517913074 144010038 518348949 331752020 8965912 308880655 337598666 350975906 682657250 48504584 434197462 434197517 252259943 435749432 695042401 353027827 458998754 320906945 139754827 787874765 729096645 624097936 896664297 389544552 614915674 896338919 563646843 722139480...

output:

763643159
108975276
162819372
829092083
30697236
399818327
955796868
850839502
697455934
924179100
903340355
960370919
455462540
166603341
345284078
371248143
614049898
477775
36384003
796466560
453817182
442073293
328755926
10534376
255481970
658361043
336847052
587023442
935742601
687497074
939120...

result:

ok 250000 numbers

Test #29:

score: 0
Accepted
time: 1000ms
memory: 486452kb

input:

250000 250000
634239861 700230915 543977198 102269393 84860058 214510250 638461073 406451362 585333119 770779015 516606467 354262283 658294196 378217713 674101580 205683923 462813999 415514263 187228852 58926145 953054588 881022802 633791554 222191831 604465842 155391407 600052841 873978210 55744961...

output:

156895441
203785187
46126
975179086
159023790
867690710
641842976
316509752
530325463
950466640
180774832
226635796
718747931
815710787
245678376
593160999
355656292
755004385
241592815
974936456
751111129
226711845
722263497
564692075
202832770
670328763
122451847
157602776
280537123
174072596
8834...

result:

ok 250000 numbers

Test #30:

score: 0
Accepted
time: 996ms
memory: 486348kb

input:

250000 250000
466961379 425077386 462152125 464413965 441740400 959521636 199483059 691533162 970976445 241211982 703171223 728579261 815725 467567505 892227079 152553541 342153848 557372064 34590978 834940169 630549103 371807030 843944178 260990353 288712653 112504733 244083110 492270553 707217684 ...

output:

867045655
329905588
577554906
415581748
406068811
972274157
257433642
952145713
761602434
681416448
343031803
581337924
99260337
464881390
268769952
592106379
807976381
181732886
314329130
316378762
842273678
458156518
946601182
936206304
778817102
636688560
46621840
563245938
6874112
529788666
1945...

result:

ok 250000 numbers

Test #31:

score: 0
Accepted
time: 1025ms
memory: 486432kb

input:

250000 250000
35839338 255250785 404104622 802716624 611592063 815495807 396788518 627169697 102787275 675716759 650613378 92469526 127612616 653070571 842461512 802204587 562875756 839471021 608546563 699744026 505837360 271088425 875083321 948166391 640801456 875188810 990172057 424948395 11603148...

output:

789103997
267058879
361433991
303468257
854193044
256963457
754823786
211574483
920172781
798597410
266589308
925714843
283488870
254291649
235048256
202909842
750488458
306809306
80437543
697823141
270651880
608070727
5004551
57445342
960432762
945021886
947540451
503797053
469531530
949703974
6844...

result:

ok 250000 numbers

Test #32:

score: 0
Accepted
time: 1060ms
memory: 486400kb

input:

250000 250000
356147137 690649169 989562736 798556559 152017537 543884113 500904117 96146181 557954447 345133770 977617049 871113574 989477630 171821569 808041378 119956463 511784686 371006694 919963791 643016750 386359071 449588016 456990648 242747210 880733402 353729034 635146566 243625932 2745447...

output:

17763972
941221986
435954205
909066487
477632125
719198400
413687354
659111940
757119265
530427474
210075610
642798209
673329742
66862305
880061602
817453101
961354767
626848645
563486729
387744963
608661408
785054997
122412179
916221341
813506791
52842682
419803197
572788884
464058864
449790876
385...

result:

ok 250000 numbers

Test #33:

score: 0
Accepted
time: 1069ms
memory: 486392kb

input:

250000 250000
210468723 802776182 691160939 228354389 259740347 711015904 24512414 504867835 463668544 820774383 268031940 411823597 65938974 753354303 565869770 321434334 194349770 524816039 729275734 197684311 320471725 875424924 780754599 106021784 810740879 63554629 770977306 367869158 221820872...

output:

471482593
973399321
423792759
371661823
749875502
378631219
10537636
397727709
327488234
338645220
520565795
845217245
294903463
521817447
28841161
843092465
213256825
74766457
355980942
106712107
504992196
287018279
74766457
467938931
514964442
799288104
243643552
244311408
254055102
356072208
6286...

result:

ok 250000 numbers

Test #34:

score: 0
Accepted
time: 1052ms
memory: 486304kb

input:

250000 250000
591151890 917514066 583692559 467808900 945109211 794877241 541022672 412843769 334763151 789853235 309280019 1505780 322220754 717945592 463132577 333286461 680709559 442614606 87316118 487136396 86563695 150576413 561758867 536430773 51977093 983642463 142227445 593822652 797288689 9...

output:

659464212
245532191
787991106
114620116
417110711
841975664
458320756
514928486
518147797
929424576
363803358
232497727
667665870
446070287
494043045
105190702
113835495
99405690
149473276
586662685
319365793
702897598
899505351
670745695
936843873
259040038
665956783
690007495
334665613
220320222
5...

result:

ok 250000 numbers

Test #35:

score: 0
Accepted
time: 1278ms
memory: 486432kb

input:

250000 250000
523624865 151154406 677403949 241083940 764942321 943185025 237815149 143062455 433122101 94437943 390469142 292743918 520927128 223908907 748893687 574487658 639803639 856191050 800344887 184484572 105763600 2220540 417731716 238615854 561003898 567782198 560858124 896249963 698311890...

output:

52789778
236852120
352256637
949868155
609291529
963294204
460282856
652840354
871157609
279453212
807011547
745411837
898404411
436328435
88644109
212281760
114534074
931144019
940612341
598323835
847911426
252191132
66129991
806277511
756865066
489203728
235619332
100409254
47322310
125725178
4502...

result:

ok 250000 numbers

Test #36:

score: 0
Accepted
time: 1093ms
memory: 486384kb

input:

250000 250000
382226884 762000322 737057273 76925634 34007808 970184279 738425765 242261618 230377709 433717846 72684969 620972834 884815196 462240285 693448663 216713664 179715712 216756060 244786982 611726501 480959151 847521757 262602953 558238181 551441558 676899526 543499060 788075884 969995981...

output:

131025310
919567695
119226573
721768151
77439420
677876517
590258482
886973455
691769179
90089601
572481516
364522799
95295630
649746317
286276930
514743096
888014306
265930732
492013709
959786457
304456631
766891324
381597134
763263334
693064090
755680275
871692645
355475843
769210730
263103382
187...

result:

ok 250000 numbers

Test #37:

score: 0
Accepted
time: 850ms
memory: 486360kb

input:

250000 250000
847193614 829941311 890442766 851827010 188932953 808238583 477609971 499975972 251969703 776298934 594414391 167366484 263766066 75803348 264437453 160270007 396149581 479587202 952810172 337034130 27516997 71822164 307208336 252813026 808160676 68863575 345299530 442484611 28362810 3...

output:

656254225
360072318
981645731
868336908
6472237
191097112
926036622
937621032
90553515
881347581
682414009
434799737
391053125
957961188
458630043
96943397
391027530
165324991
831753
836363757
496951473
374986959
75567093
481227272
289819563
373796726
594658255
46638734
584552523
322175676
734927479...

result:

ok 250000 numbers

Test #38:

score: 0
Accepted
time: 593ms
memory: 486392kb

input:

250000 250000
831954329 614686133 797406252 818037256 868915749 667882037 644834174 578276087 258267898 755068157 775012274 939218768 988201780 28365450 47281159 279971620 529902363 595644430 944185925 284427850 844755928 692063201 582969136 429936216 332420793 582716257 154812203 521238942 99547616...

output:

440409928
424806498
970161614
960914618
425916531
551523050
69005204
535604677
730506125
791942641
398610404
472100474
384869378
406284062
447749529
247267041
563742562
485429318
191738037
362002901
945436930
958151356
911344910
489058035
977176113
43823648
265320441
684560738
667837448
660210828
76...

result:

ok 250000 numbers

Test #39:

score: 0
Accepted
time: 821ms
memory: 486316kb

input:

250000 250000
822647001 169723165 499715142 164333669 161131419 744404964 314754451 891808067 777957290 825961326 18593997 478527656 409450594 20763997 103512130 528213594 977085602 566900538 25637325 861510359 661274174 118271572 347467739 732628148 840199498 473941172 993308182 237724880 620974648...

output:

268730582
123569883
538001588
56493229
845492198
415991545
968850925
832413588
179671554
846167210
501123314
584712295
628084561
108390120
213156316
276571234
622099847
824859503
440849233
228009473
960472284
712014959
14116945
966867758
992895444
986043854
683595466
758972361
103291477
20214304
265...

result:

ok 250000 numbers

Test #40:

score: 0
Accepted
time: 1136ms
memory: 488332kb

input:

250000 250000
760647166 803257065 832993748 921583247 193948578 416062231 436662651 600930112 7525304 497451447 256764936 246331301 401802439 666857762 848822421 717870181 587426051 98543210 994447053 950530141 660387635 312399874 449540775 344792017 915553816 764925268 965744251 100227279 727737369...

output:

132622354
49833053
986187992
526471235
847157971
98968226
767443452
148778287
751326678
127627277
527332372
541090502
546143054
83110345
329289579
528804041
500756526
265874836
792638334
194534592
975213083
608380407
822943920
749703105
611526584
703561185
517222614
896599773
984392839
765166643
111...

result:

ok 250000 numbers

Test #41:

score: 0
Accepted
time: 1166ms
memory: 488164kb

input:

250000 250000
793150105 86048103 757432375 624356369 288349268 309970883 10891885 741145848 483590890 865924373 583158648 427985830 222078037 293021534 972369250 827292268 517979009 497120339 841979610 667735195 784816319 210979692 424568613 157846713 184281872 763744244 779675648 413714524 28451233...

output:

529338496
131664020
749592299
101244997
82678650
329897318
439019353
533573373
367255387
694786760
754658404
403425863
482420874
143763120
971930142
864746490
198176289
166820242
464009629
816487072
300018257
521156838
903141244
524483469
274331156
746908947
318387632
73565122
53429468
360578255
300...

result:

ok 250000 numbers

Test #42:

score: 0
Accepted
time: 1474ms
memory: 486416kb

input:

250000 250000
567459311 752107335 557770976 119339889 131632460 399812910 217864199 807077299 318472166 28140229 23728872 610120825 450797252 104499865 727685062 781906355 671226432 964698583 111153072 9669751 978570619 615754124 383360941 328101047 571402996 888527608 519885093 920931022 200241919 ...

output:

31108299
710949470
364149104
955158782
956762869
88318207
826117496
814005524
131706758
118166477
814308336
491858377
215445232
968752536
739096284
992736
807758184
290700177
131339980
115799226
258542144
824271506
309198128
196607283
356868544
706667407
752049356
573876942
545847410
411761633
35204...

result:

ok 250000 numbers

Test #43:

score: 0
Accepted
time: 1497ms
memory: 486484kb

input:

250000 250000
703980703 861296982 931676495 428676619 606941481 3718548 350696007 595281073 135016020 596494809 472400989 1838193 931517285 849895291 720513805 159726527 488726450 863433878 132575049 357488513 401563352 919180126 531074415 410465946 902628333 855959552 58820554 863579583 67909720 16...

output:

433989284
892795617
316347437
200822530
149275189
36626167
36396735
325145217
648472032
786476064
660520698
613232413
117365317
625829464
275217838
645513730
851721531
452280843
788935915
631649732
983990902
984151895
832870808
524365720
451106535
106315130
352090324
677914214
930642415
974310861
63...

result:

ok 250000 numbers