QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#114681#2179. Dungeon 3lmeowdn100 ✓1083ms265776kbC++146.0kb2023-06-22 21:08:282023-06-22 21:08:30

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-22 21:08:30]
  • 评测
  • 测评结果:100
  • 用时:1083ms
  • 内存:265776kb
  • [2023-06-22 21:08:28]
  • 提交

answer

#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x) {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=2e5+5;
int n,m,a[N],b[N],s[N],tot,ans[N],tick,nxt[N],dfn[N],dt,sz[N],st[N],top,fa[N][25],sum[N][25];
pii f[25][N],g[25][N];
set<int> sc;
struct qry {int s,t,u,id;} q[N];
priority_queue<pii>Q;
vi e[N];

bool cmp(const qry &a,const qry &b) {return a.u<b.u;}
pii operator + (const pii &a,const pii &b) {return pii(a.fi+b.fi,a.se+b.se);}
pii operator * (const pii &a,const int &b) {return pii(a.fi*b,a.se*b);}
pii qmax(int l,int r) {
  int len=r-l+1, h=__lg(len);
  return max(f[h][l],f[h][r-(1<<h)+1]);
}
pii qmin(int l,int r) {
  int len=r-l+1, h=__lg(len);
  return min(g[h][l],g[h][r-(1<<h)+1]);
}

void dfs(int u) {
  dfn[u]=++dt; sz[u]=1;
  rep(h,1,20) fa[u][h]=fa[fa[u][h-1]][h-1], sum[u][h]=sum[u][h-1]+sum[fa[u][h-1]][h-1];
  for(int v:e[u]) fa[v][0]=u, sum[v][0]=b[v]*(s[u-1]-s[v-1]), dfs(v), sz[u]+=sz[v];
}

pii val(int x,int pnxt=0) {
  auto itp=sc.lower_bound(x), itn=sc.upper_bound(x);
  if(*itp!=x) return pii(0,0);
  else if(itp==sc.begin()) {
    int nxt=*itn;
    if(b[x]>b[nxt]) return pii(0,s[nxt-1]-s[x-1])*b[x];
    else return pii(1,0)*b[x];
  } else {
    int pre=*--itp, nxt=*itn; if(pnxt) nxt=pnxt;
    if(b[pre]>b[x]&&b[x]>b[nxt]) return pii(0,s[nxt-1]-s[x-1])*b[x];
    else if(b[pre]>b[x]) return pii(1,0)*b[x];
    else if(b[x]>b[nxt]) return pii(-1,s[nxt-1]-s[pre-1])*b[x];
    else return pii(0,s[x-1]-s[pre-1])*b[x];
  }
}
void insd(int x) {
  auto itp=sc.lower_bound(x), itn=sc.upper_bound(x);
  if(*itp!=x) return;
  else if(itp==sc.begin()) return;
  else {
    int pre=*--itp, nxt=*itn;
    if(b[x]>=b[pre]&&b[x]>b[nxt]) Q.push(pii(-s[nxt-1]+s[pre-1],x));
  }
}

namespace SegT {
  int ls[N<<1],rs[N<<1],tot=1; pii s[N<<1];
  void build(int p,int l,int r) {
    if(l==r) {s[p]=val(l); return;} int mid=l+r>>1;
    build(ls[p]=++tot,l,mid), build(rs[p]=++tot,mid+1,r);
    s[p]=s[ls[p]]+s[rs[p]];
  }
  void mdf(int p,int l,int r,int x) {
    if(l==r) {s[p]=val(l); return;} int mid=l+r>>1;
    if(x<=mid) mdf(ls[p],l,mid,x);
    else mdf(rs[p],mid+1,r,x);
    s[p]=s[ls[p]]+s[rs[p]];
  }
  pii qry(int p,int l,int r,int x,int y) {
    chmin(y,n);
    if(l==x&&r==y) return s[p]; int mid=l+r>>1;
    if(y<=mid) return qry(ls[p],l,mid,x,y);
    else if(x>mid) return qry(rs[p],mid+1,r,x,y);
    else return qry(ls[p],l,mid,x,mid)+qry(rs[p],mid+1,r,mid+1,y);
  }
}

namespace FenT {
  int s[N];
  int lb(int x) {return x&-x;}
  void add(int x,int y) {for(;x<=n+1;x+=lb(x)) s[x]+=y;}
  int qry(int x,int y=0) {for(;x;x-=lb(x)) y+=s[x]; return y;}
  void add(int l,int r,int x) {add(l,x), add(r+1,-x);}
}

int query(int S,int T,int u) {
  auto itx=sc.upper_bound(S);
  if(*itx>=T) {
    if(!sc.count(S)) {
      int ans=0;
      per(h,20,0) if(fa[S][h]&&fa[S][h]<=T) ans+=sum[S][h], S=fa[S][h];
      return ans+b[S]*(s[T-1]-s[S-1]); 
    } else return b[S]*(s[T-1]-s[S-1]);
  }
  int x=*itx, bt=b[T], fls=0;
  if(!sc.count(S)) sc.insert(S), fls=1;
  int y=lower_bound(s,s+n,s[T-1]-u)-s+1; y=qmin(max(S,y),T-1).se;
  if(y==S) return b[S]*(s[T-1]-s[S-1]);
  SegT::mdf(1,1,n,x); pii res(0,0);
  if(x<y) res=res+SegT::qry(1,1,n,x,y-1);
  assert(x<=y);
  int tmp=0; swap(tmp,b[T]); res=res+val(y,T); swap(tmp,b[T]);
  if(fls) sc.erase(S);
  if(fls&&b[S]>b[x]) res.se+=FenT::qry(dfn[S]);
  else if(b[S]>b[x]) res.se+=b[S]*(s[x-1]-s[S-1]);
  else res.fi+=b[S];
  SegT::mdf(1,1,n,x);
  return res.fi*u+res.se;
}

signed main() {
  n=read(), m=read(), tick=1;
  rep(i,1,n) a[i]=read();
  rep(i,1,n+1) s[i]=s[i-1]+a[i];
  rep(i,1,n) b[i]=read(); st[++top]=n+1;
  per(i,n,1) {
    while(b[st[top]]>=b[i]) --top;
    nxt[i]=st[top]; e[st[top]].eb(i);
    st[++top]=i;
  }
  dfs(n+1);
  rep(i,1,n) f[0][i]=pii(a[i],i), g[0][i]=pii(b[i],i);
  rep(h,1,20) rep(i,1,n) if(i+(1<<h)-1<=n)
    f[h][i]=max(f[h-1][i],f[h-1][i+(1<<h-1)]),
    g[h][i]=min(g[h-1][i],g[h-1][i+(1<<h-1)]);
  rep(i,1,m) {
    int s=read(), t=read(), u=read();
    if(qmax(s,t-1).fi>u) ans[i]=-1;
    else q[++tot]=(qry){s,t,u,i};
  }
  sort(q+1,q+tot+1,cmp);
  rep(i,1,n+1) sc.insert(i);
  SegT::build(1,1,n);
  rep(i,2,n) insd(i);
  while(!Q.empty()) {
    int x=Q.top().se, w=-Q.top().fi; Q.pop();
    if(!sc.count(x)) continue;
    auto itp=sc.lower_bound(x), itn=sc.upper_bound(x);
    int pre=*--itp, nxt=*itn;
    if(s[nxt-1]-s[pre-1]!=w) continue;
    while(tick<=tot) {
      if(q[tick].u>=w) break;
      ans[q[tick].id]=query(q[tick].s,q[tick].t,q[tick].u);
      ++tick;
    }
    if(tick>tot) break;
    sc.erase(x); insd(pre); insd(nxt);
    FenT::add(dfn[x],dfn[x]+sz[x]-1,(s[nxt-1]-s[x-1])*b[x]);
    SegT::mdf(1,1,n,x); SegT::mdf(1,1,n,pre); SegT::mdf(1,1,n,nxt);
  }
  while(tick<=tot) {
    ans[q[tick].id]=query(q[tick].s,q[tick].t,q[tick].u);
    ++tick;
  }
  rep(i,1,m) printf("%lld\n",ans[i]);
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 11
Accepted

Test #1:

score: 11
Accepted
time: 7ms
memory: 78808kb

input:

2968 3000
195694 114761 84601 149164 83572 166860 83871 71067 14931 22597 45549 26862 29127 9421 126511 19869 175633 47521 181323 38646 178807 186054 31799 173648 106553 94698 98918 149462 95647 145666 121002 178141 154888 183449 176438 194661 97265 28777 98620 113016 49316 125390 35010 31772 159928...

output:

646758143905
-1
691191572558
192301106829
503691788062
136375921869
789174277209
1878434150794
-1
76495643279
234719906270
278581826840
178422836927
761213865348
596973476366
-1
3649891101352
-1
1768936832497
1864726938342
1646411424142
805188342798
2480719218365
1540142237698
2100449734488
48678149...

result:

ok 3000 lines

Test #2:

score: 0
Accepted
time: 3ms
memory: 72700kb

input:

2985 3000
1643 2564 495 3814 1776 1110 747 4868 4459 115 2805 4101 773 4986 1423 56 1523 2920 3424 2007 4907 1616 3545 4757 2672 4060 1370 3243 3132 2454 1601 2925 3970 2545 1192 500 2475 3645 471 456 4436 1227 4527 1822 1153 890 169 1515 266 2742 4487 1361 624 75 1538 2679 1168 2815 419 4157 111 37...

output:

560517127956
406753449461
75037798350
120444434460
820920461777
289077908562
313941880061
99111155571
21161706811
143920185130
120935068604
518676363859
222724626637
510101403980
418036351278
234670223667
813839591942
367028205096
1463392378045
770311965507
506381827742
581571715085
181734818384
121...

result:

ok 3000 lines

Test #3:

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

input:

2923 3000
2139 1783 1177 4588 140 912 1362 2972 1759 1299 3009 3360 1457 2124 1127 142 2037 3528 4730 1732 3612 275 534 4641 4231 1943 2411 2014 61 1480 3158 200 3396 3241 4672 1857 2644 168 2269 403 2235 3969 3149 4760 2282 197 3106 2417 2294 4225 1202 3730 368 4507 4699 3276 4925 3597 2177 3292 29...

output:

563980715891
501430478252
941332848420
512580729965
787463681822
284110214411
192981880433
384141395148
382346359714
748919812915
1302164217727
509358707211
187692623430
625636298562
110661992579
647687432857
93693778870
-1
735959536032
1300625099534
484349981955
-1
7010460165
175456461027
678959512...

result:

ok 3000 lines

Test #4:

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

input:

2939 3000
93 181 257 335 342 391 471 481 517 628 650 687 740 743 864 1116 1164 1186 1203 1244 1250 1348 1350 1374 1406 1480 1495 1521 1566 1592 1708 1792 2000 2017 2066 2196 2305 2428 2445 2496 2499 2560 2660 2858 2954 2981 3027 3064 3077 3171 3183 3326 3326 3367 3392 3538 3578 3645 3701 3722 3726 4...

output:

105216784828
101245407760
103973901719
52333571394
6157452678708
86767499186
929093750829
1821129730615
2257220493299
284989615473
85439987657
3510061683059
4266492672046
562464218307
443085988895
3473531512024
788570327425
367473181972
8917048030871
1089507461430
1890460761377
1680844227764
1474103...

result:

ok 3000 lines

Test #5:

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

input:

2954 3000
1 3 6 6 7 10 15 21 24 26 27 30 33 33 35 39 40 43 44 45 47 50 50 52 52 54 55 57 59 63 64 65 66 66 69 71 73 73 73 75 79 82 83 85 87 88 93 93 94 96 97 100 100 101 102 107 112 114 117 119 119 119 122 125 128 128 131 132 135 135 138 142 142 143 146 147 147 147 148 152 152 156 159 160 166 168 16...

output:

77627558386
212664247792
522082675374
745562910173
1396908830934
927230685782
303053691829
489233803748
752620661988
1022169810030
689370604
154160326004
1101129851925
136788139717
376564329540
276244602765
1422180120919
145349770104
76746046306
1067608739607
1375259978425
18276134052
1414325105455
...

result:

ok 3000 lines

Test #6:

score: 0
Accepted
time: 5ms
memory: 79104kb

input:

2990 3000
11 40 214 258 263 336 362 370 548 594 715 740 748 753 785 793 880 910 913 1185 1232 1363 1436 1486 1499 1570 1580 1644 1690 1720 1729 1734 1851 1952 2011 2148 2187 2216 2241 2307 2355 2370 2461 2487 2708 2732 2781 2817 2848 3021 3025 3052 3067 3138 3144 3171 3186 3292 3364 3470 3524 3547 3...

output:

-1
31442869613547
16996310339973
15648913415475
7628516252824
596569474932
2434019470382
27328059116378
40197155081755
54238451709287
13851466779851
735352574467
7382067891002
57982678827722
2901800189059
8483243067350
-1
4025413567610
57309167508036
57083175118448
50783409409579
2826549552931
29602...

result:

ok 3000 lines

Test #7:

score: 0
Accepted
time: 4ms
memory: 74768kb

input:

2981 3000
5000 4999 4995 4992 4992 4985 4983 4981 4981 4979 4978 4977 4976 4976 4974 4971 4970 4969 4966 4965 4964 4964 4963 4963 4960 4958 4958 4958 4954 4953 4952 4952 4951 4951 4947 4946 4945 4944 4940 4940 4938 4938 4937 4937 4936 4935 4933 4933 4931 4930 4924 4921 4919 4917 4915 4915 4913 4912 ...

output:

219390367326
23804471459
11372969082
46054893539
-1
1613644575
5405571197
9781879593
2234284138
3329941785
327426166374
185039169050
1990018583
2262510958
68351978236
1974163710
1784204426
4197284649
1829879761
176325180794
1732480004
8595686614
7303494667
26753370796
3829666783
27909550065
27675250...

result:

ok 3000 lines

Test #8:

score: 0
Accepted
time: 5ms
memory: 76732kb

input:

2975 3000
4998 4997 4996 4991 4988 4988 4987 4984 4984 4984 4983 4982 4980 4978 4976 4972 4970 4969 4968 4965 4963 4962 4960 4959 4958 4957 4956 4956 4953 4953 4950 4950 4949 4948 4947 4945 4945 4945 4945 4943 4943 4941 4938 4937 4936 4935 4935 4934 4933 4933 4930 4930 4928 4927 4926 4922 4918 4917 ...

output:

278550667744
1463104267886
1481664572758
646951609524
169264326416
859274886451
226776077948
-1
1041823967396
1342483136298
50645684250
31675811127
726263439888
3511854247
358454950551
115927088948
154178256141
218637852669
417938451122
376093223343
514719589685
4582912222
517948056140
17696119922
4...

result:

ok 3000 lines

Test #9:

score: 0
Accepted
time: 3ms
memory: 77068kb

input:

2942 3000
5000 4998 4997 4995 4995 4994 4992 4989 4989 4989 4987 4986 4985 4984 4983 4981 4980 4976 4974 4974 4973 4971 4971 4970 4964 4962 4961 4958 4958 4954 4950 4947 4947 4947 4946 4945 4940 4937 4936 4935 4933 4931 4929 4929 4926 4924 4923 4921 4920 4920 4918 4917 4916 4914 4913 4911 4910 4905 ...

output:

167333439318
634446640660
473775216224
27351213345
-1
358921329822
703716614812
373963740090
463485564664
140405701607
235711418840
596472506714
3540235648
39175666139
1149586227761
237333053920
281592736581
1060648920141
100652431852
87930126434
639145247549
1472933567908
107967530734
-1
6619923995...

result:

ok 3000 lines

Test #10:

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

input:

2948 3000
21087 141349 10206 199320 58267 117049 57796 174521 75036 133853 46187 123531 54956 163630 94350 189073 30943 173449 2951 157107 52178 187478 47534 115697 5145 193693 80490 173598 12135 121201 88925 184882 29984 114393 98065 189293 79767 121803 81271 116733 10585 140967 79442 143509 92184 ...

output:

4752959077051
-1
290393714551
-1
1957250444830
317002502575
4990415597665
2974663654838
113139894114
77971978286
335949293588
227799655638
200392492594
630650522375
-1
4093650913408
-1
912303739748
4476535430711
175598374472
276742968881
43049178236
1076442816529
630300470935
1493207136228
123946001...

result:

ok 3000 lines

Test #11:

score: 0
Accepted
time: 4ms
memory: 72716kb

input:

2955 3000
36292 142401 30036 101698 36219 122536 75244 138118 46438 107597 15215 164288 30983 194250 19031 152036 86220 165421 80796 185393 18082 140558 24827 124350 51934 106720 11335 177503 78835 107409 77272 125775 44168 156011 51457 198952 66084 160887 59053 177594 49844 149670 19121 105949 6975...

output:

-1
46423527481172
45142641848005
24466449935901
32993634707655
4392489200205
57832539090968
-1
11759473675096
28822393321952
13130850483879
55910172854461
29308246748826
-1
25774263140878
35495441779018
-1
18981067120531
57475643202762
25010164724881
3496112089334
30250447717801
16133785794962
50134...

result:

ok 3000 lines

Test #12:

score: 0
Accepted
time: 4ms
memory: 75184kb

input:

2984 3000
84952 196644 51085 154237 61940 147864 76484 106401 1196 180396 51564 169097 44131 129117 23929 125441 34770 186103 42077 168214 56135 152587 81773 98513 14606 120797 71396 145443 4847 104202 42064 116654 84131 147524 73138 148203 92276 147672 42745 176221 49291 155856 24657 170718 38014 1...

output:

17480579202548
33366998393702
18436506708207
57069663287374
13865442626545
3406520042529
49417117021122
9345356256398
56596672810903
21374684578570
56211970912079
31619329001202
4530756479763
30962871759147
37196047380981
34114416199955
40129946563309
-1
32685167094592
18138711863636
2758333925931
4...

result:

ok 3000 lines

Test #13:

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

input:

2985 3000
173126 197279 34624 80913 53828 41410 151811 120640 163979 112773 160662 37601 114506 108654 104239 142170 169276 43287 13385 106984 177073 69299 66728 30577 46328 102953 122467 158941 167209 92839 97072 115193 168277 40073 38952 175771 134554 68966 111835 4713 172003 146197 110326 61622 1...

output:

10413524339717
22532275201453
1278743643958
43909362033755
10575516116617
22250537718897
44949591649569
-1
25703314524884
25282462654793
9429176371418
845829978780
39200891300
16935877182560
23411821731405
-1
12473598525163
-1
-1
21599945856034
1181480291239
30486294371852
21400209992869
75424491325...

result:

ok 3000 lines

Test #14:

score: 0
Accepted
time: 4ms
memory: 77148kb

input:

2960 3000
3406 1954 4691 11 2932 768 63 478 2875 1829 3784 755 4913 2715 2038 4005 1448 4500 783 590 2524 4427 42 4782 502 239 4448 1785 4585 1659 2560 4221 3090 4126 280 1637 3253 707 4947 2676 625 2353 2160 212 2426 557 956 3515 1162 3791 4176 3377 4034 1864 1217 4238 3360 3782 1006 2830 563 4667 ...

output:

541153468159
235155324757
109271043095
1450956091548
804151589038
1440364986044
857150578172
1160729908013
6302448300
793725189059
466472689704
115481107390
16718216248
76113783513
50173881412
307214985542
207242512452
349200117803
934954331713
706693751199
202600142317
1315290838
182225754981
19650...

result:

ok 3000 lines

Test #15:

score: 0
Accepted
time: 4ms
memory: 77052kb

input:

2937 3000
92 95 96 99 101 102 103 103 104 104 105 108 110 114 115 115 116 122 123 123 126 127 129 132 138 141 142 145 150 152 156 157 159 160 160 165 166 172 172 173 173 174 175 178 180 181 181 184 185 187 187 187 188 194 199 199 202 203 203 206 208 208 211 217 218 220 220 220 224 225 226 228 230 23...

output:

1093245608311
685023209468
1469454706537
22752560833
54069588849
410868259048
451801507669
387392463241
767008445569
113876071959
690352912281
346615911616
428346456975
216335776165
343030756822
79393106487
147187294578
8246019065
36643940843
1469363786349
1114795791058
599683378782
130110480253
930...

result:

ok 3000 lines

Test #16:

score: 0
Accepted
time: 4ms
memory: 74684kb

input:

2989 3000
23 22 21 20 19 18 18 16 14 14 11 10 10 6 4999 4999 4998 4998 4996 4995 4994 4992 4992 4990 4989 4988 4985 4983 4983 4976 4975 4973 4971 4970 4969 4967 4963 4963 4963 4961 4961 4959 4957 4957 4956 4956 4955 4955 4954 4953 4950 4949 4948 4946 4944 4944 4941 4941 4936 4934 4933 4933 4932 4932...

output:

776975949190
-1
1024550787964
229436173785
89714295902
768375842319
1449631589782
1270553915309
237708074516
110892754622
149246154285
963115755119
84017836036
724043208210
862181838
89985458607
1476022447511
1337306668535
1473552872227
848194182156
776585037311
604617330703
14843284500
23028643162
...

result:

ok 3000 lines

Test #17:

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

input:

2976 3000
199966 3 90 199989 199996 18 199978 4 199914 199901 60 62 54 25 68 199965 199912 42 86 199981 41 199956 199964 6 199993 199940 199975 20 199925 85 199975 199942 199913 19 27 22 199903 199940 199955 35 3 199971 73 199998 96 96 41 22 60 199904 199954 27 199945 2 12 199948 91 90 44 199987 57 ...

output:

532804397196
191107847494
96687740649
-1
12373612653069
4261444311411
237750674859
-1
-1
-1
-1
238722584089
148457317750
330541281252
-1
1206981756172
3456407589884
420250998357
61345423881
105979091942
159769741594
132414606655
515028093539
4539549703269
394659644987
1114661533145
-1
1306986881207
...

result:

ok 3000 lines

Test #18:

score: 0
Accepted
time: 5ms
memory: 72732kb

input:

2942 3000
199921 32 199978 199956 199912 199903 199951 42 63 78 98 84 199966 49 199948 83 199936 199943 57 83 199982 12 8 199937 199949 199917 200000 36 42 23 199982 199940 23 41 199915 66 35 199964 199961 6 27 64 200000 199968 11 86 199932 199916 10 14 34 199924 47 199963 199920 80 67 86 199938 92 ...

output:

4905171511324
-1
-1
4075528204774
13301382268435
43724335674803
2690148942204
14838025524014
3454709649210
-1
-1
-1
1616950518503
-1
-1
-1
34037970748268
-1
-1
9773917101806
7880201934751
28587305148263
27606380690524
-1
15769354874529
21435430490628
-1
-1
17576854467826
25654032243766
-1
9106873271...

result:

ok 3000 lines

Test #19:

score: 0
Accepted
time: 3ms
memory: 75100kb

input:

2988 3000
91 100 199912 9 47 199924 83 199937 96 199931 1 76 26 33 83 199927 199973 199940 9 199902 199995 199997 43 67 200000 24 199984 199976 199986 199981 58 199968 199902 75 199921 77 44 89 46 57 199949 199981 199900 25 67 199987 100 2 199928 199936 199957 2 36 62 85 199958 56 81 66 199970 19990...

output:

-1
7254352521094
-1
10503453880390
29736685505042
36512902384182
3527330997160
18942430102204
30931520706797
-1
43808006703132
4071442653662
24617431303055
30009534588630
10247178531352
-1
28574416358976
-1
-1
12513463824695
37536629612965
10277835054027
8961814045160
9314557715164
4923427697020
244...

result:

ok 3000 lines

Test #20:

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

input:

3000 3000
500 495 500 499 495 497 492 499 494 498 495 499 495 494 495 494 496 495 500 497 499 500 491 491 500 499 491 500 498 494 500 497 496 495 490 493 490 498 493 498 492 494 497 495 499 492 491 495 492 495 492 499 494 495 494 497 498 493 491 494 499 493 493 493 497 500 490 497 496 494 493 500 49...

output:

285677254516
288109687104
288687782288
290630018781
286531863652
290539410637
288198297314
291827650142
287338534404
290045409287
284305860602
285754488319
288995878400
286241791751
287542474710
290827031649
285580929230
287444895577
287708240012
288112565607
289475449182
287250707421
291321798185
2...

result:

ok 3000 lines

Subtask #2:

score: 14
Accepted

Test #21:

score: 14
Accepted
time: 109ms
memory: 149132kb

input:

49414 50000
1 2 3 4 17 22 23 24 29 30 35 42 47 48 55 57 63 65 67 68 72 74 78 94 99 105 106 107 113 115 115 115 121 122 123 124 128 132 133 139 148 154 160 160 166 167 169 172 172 176 180 185 185 186 191 192 201 202 206 208 213 214 229 230 233 239 240 244 251 252 255 258 263 267 269 270 273 273 274 2...

output:

229351781114038
691585722607106
212249616022073
436679871997312
47649154641794
152704801333623
162265699885646
12770601806238
203195986279961
824969157587126
824819070962027
825150008439340
200947987555379
301235704785556
44273973887492
532874836353182
681913863278118
315446799789453
148010020319595...

result:

ok 50000 lines

Test #22:

score: 0
Accepted
time: 162ms
memory: 144480kb

input:

49783 50000
199999 199998 199997 199987 199970 199959 199954 199950 199948 199947 199946 199944 199937 199934 199933 199930 199929 199923 199919 199919 199911 199909 199907 199905 199904 199900 199900 199899 199896 199891 199888 199882 199881 199881 199880 199876 199870 199869 199864 199860 199836 1...

output:

497466286743600
527630073716750
279083639630009
315531758376292
79434438300864
24053542782821
440526099777571
575739757470698
366164927517175
107971687459384
611789286123468
665431936694383
615073472257053
228032817148668
518462984735324
359531014475570
373554277409827
156864655092511
24083138387395...

result:

ok 50000 lines

Test #23:

score: 0
Accepted
time: 109ms
memory: 141028kb

input:

49981 50000
23009 170341 195209 81423 76571 154255 140917 29859 27022 136449 171933 156782 62643 166647 7745 140744 106258 20454 84289 185834 159594 37704 27083 77442 69085 52489 104300 166232 135720 176735 104219 127536 142459 32265 91722 102195 143779 77514 144966 80550 41236 130315 119950 95721 8...

output:

370887039568282
62020637794395
162750214931549
54381550483527
480834223167746
72794199913594
727209877286758
123459520952044
271031459507229
77733473425608
234040065889437
14394866413596
361737806721862
873764912666217
874411497468422
78248388914543
873385679061354
670138937416955
874316755548235
24...

result:

ok 50000 lines

Test #24:

score: 0
Accepted
time: 121ms
memory: 148832kb

input:

49038 50000
133535 184751 162691 29924 94710 72776 63045 35454 93424 105220 114542 6282 111684 117424 149309 158678 8052 72166 191811 69703 53637 108018 3627 58906 88782 158504 52854 121454 78301 86117 74876 74578 183002 92283 6966 192661 71336 56364 134743 122290 181125 55279 144368 194925 28224 89...

output:

556520480774469
223989451511714
323447742719248
89544730535979
486819714373318
45031971978409
858249383981266
164126750263605
372516941144433
91368458170586
857187068542539
492550376928735
101284238464345
255459305170655
307798606893581
200221637718571
314636885356329
424560810873733
765927785592747...

result:

ok 50000 lines

Test #25:

score: 0
Accepted
time: 184ms
memory: 142852kb

input:

49941 50000
131322 47352 154983 120298 40153 37053 97781 139625 66248 154670 133089 151710 158445 138843 143925 3764 82900 55303 94620 154723 135544 85996 53980 13099 103904 87846 23200 191282 144500 56684 162447 138643 170805 171243 16691 16606 28326 67218 126821 62220 185520 188093 137845 118277 4...

output:

11692126876441
6934215982040
15250734392300
10766067597410
15336156571547
17741511205060
4895556346222
29355581409472
10519477251440
15201990529012
11037104257302
13725080841290
10085765588385
19180646252495
10976234584834
29374002175560
345205928853
10981855215161
14115800851885
22169069579432
1230...

result:

ok 50000 lines

Test #26:

score: 0
Accepted
time: 621ms
memory: 258148kb

input:

193753 200000
200000 199999 199998 199998 199997 199996 199995 199995 199995 199992 199990 199987 199985 199981 199980 199976 199976 199976 199975 199973 199973 199973 199972 199971 199970 199970 199970 199970 199970 199966 199965 199964 199962 199961 199961 199961 199959 199957 199957 199956 199955...

output:

1973409677491495
946870681672896
589874837778694
2410478717696133
313027804112285
1146937496440672
1957641832124075
130552215453650
25507298948148
1243545541588866
2183698242841216
998729244969895
113583142033587
1000977351402115
511742884863546
650383267686477
396484726244
2027492020505327
11032653...

result:

ok 200000 lines

Test #27:

score: 0
Accepted
time: 841ms
memory: 238568kb

input:

191306 200000
1 1 1 2 3 6 8 8 9 11 12 12 13 15 17 17 18 18 18 21 22 23 23 26 26 27 29 31 32 32 33 33 34 34 37 38 41 41 41 42 45 45 46 47 48 48 48 49 50 51 51 52 52 52 53 53 55 58 58 58 60 61 63 63 63 63 64 64 65 67 67 68 69 71 71 71 73 75 75 75 75 76 77 78 80 80 81 81 81 82 82 83 84 86 87 92 92 94 9...

output:

17942279796494
668697765942789
362358604350475
80714625918169
453204708620175
841425374075513
134606178635484
551895334042706
841352202982509
544495176107763
1180125841321
748085287863333
357033126252460
191392026111024
193942446181181
679775006923916
105385579711355
32537228490229
423797737932316
7...

result:

ok 200000 lines

Test #28:

score: 0
Accepted
time: 667ms
memory: 238784kb

input:

199738 200000
17035 193120 173512 115988 46299 126801 183676 131144 167421 66659 8716 175854 56173 67012 111681 12021 164944 150341 131386 81174 135637 137459 102441 41848 33021 130284 157758 28004 58282 32329 38349 26204 50763 105530 20525 120755 194771 179837 198556 139927 187157 51731 46391 10370...

output:

752592260792184
180185544719122
1035593710086552
58563855586796
907561445285564
800782810983990
61886133631973
122075204898485
1737691213668127
1091894279204125
29141829051378
26347170570089
1522109524587175
468181859892318
636262996933023
625040402759330
1330099561418790
563986537786845
98702930171...

result:

ok 200000 lines

Test #29:

score: 0
Accepted
time: 665ms
memory: 264796kb

input:

198132 200000
167663 39131 30806 57797 53268 186791 105076 21491 119676 196746 162198 144212 38966 142044 22464 19031 105252 24051 8527 197224 63078 70205 66444 173453 109181 114838 24663 107445 199388 78034 197709 50835 184912 74044 5016 32121 177300 101798 135179 47425 57638 67236 70863 52703 1319...

output:

1243360015867261
1483378424066601
80834557260593
2000548953087381
1947559539633146
366797297684443
6158103549002
369772645177097
1490052971399207
91017998972473
357671356373697
935185385863135
814591107820181
1999767390503456
1686555251273193
496341412988306
840147986839777
1656796413216324
80242415...

result:

ok 200000 lines

Test #30:

score: 0
Accepted
time: 659ms
memory: 236576kb

input:

195683 200000
798 3667 754 4087 351 3117 537 4617 1896 4919 403 4100 1991 4855 387 4008 1293 4141 1341 2529 1219 4313 2432 3130 1977 4427 1986 4077 1984 3738 299 3400 2048 4661 2014 4042 1371 3383 2425 2913 619 3815 2276 4936 2220 2912 1409 3767 54 4869 556 3075 1439 3964 2374 2522 2388 4238 917 341...

output:

26616848644445
23517457580054
15683720107824
15551960587011
15577012658294
22990512071835
9015100018800
27573681413915
7153769352885
31608815105751
27274269359417
30037932150069
16649719715150
9391066493348
32600541764368
9055988845758
2634849878585
30249314645816
10336041016971
49048088729076
19992...

result:

ok 200000 lines

Test #31:

score: 0
Accepted
time: 634ms
memory: 236124kb

input:

191129 200000
401 4244 2858 2275 3656 424 4301 1187 3314 307 3080 4198 1313 2802 808 1516 2747 1464 3579 1759 3652 3984 2567 1739 4151 2319 3367 3165 3622 3451 513 1740 3311 607 3497 3405 202 1474 107 4220 4792 1273 3793 1135 673 813 673 3380 5 4747 2206 2528 1733 458 4041 3288 2020 1625 3819 2828 4...

output:

2305777011533
12965944451404
6346652835174
15497730081037
24100572214282
20103777577193
49056220352353
1210438399278
24623241503660
49043595287144
16597865475
24526224341796
23887728018018
2238230633394
960997869763
16925699137584
2931140790281
8280736134381
4029002928361
49052168708972
93547985048
...

result:

ok 200000 lines

Test #32:

score: 0
Accepted
time: 675ms
memory: 261348kb

input:

199021 200000
1591 2647 4480 3981 1089 1226 576 4198 3748 4800 3686 1269 68 4092 1406 1042 3881 446 3776 898 2434 3006 1063 2694 4708 1863 4090 4443 2826 546 2118 2288 3801 2198 1789 1218 3465 4301 4210 1042 2251 3044 3756 2606 2926 4973 2240 3065 2222 2402 852 1713 1353 307 3474 3627 4225 519 2275 ...

output:

27550611674326
32091038868785
18744932620099
32662549600908
34772522670366
11458311438489
22783800346271
103888833304
33849015613352
902908515053
27619554297669
28943087447805
140136149374
7350725307733
14415644919473
1707684400055
18148531023410
18024843710529
18398568807958
22335045765800
16052653...

result:

ok 200000 lines

Test #33:

score: 0
Accepted
time: 901ms
memory: 242132kb

input:

200000 200000
566 2811 4614 4746 839 1010 3222 4995 4655 3797 4915 3704 2030 2652 3529 2453 3995 2818 4350 2362 3282 682 930 2944 3880 3827 2650 1604 3473 4391 1926 2974 3769 960 3026 2793 537 1550 3808 3098 3140 2841 56 4709 2792 4941 4015 4463 2263 4367 1451 4151 3760 4029 737 3347 1919 87 1354 10...

output:

5156293958
13476045473
12349407467
32232455873
19958768792
19373715071
39830205077
11944496701
16230632683
29542050715
9106103532
4903007415
8808275550
8624516163
11584937370
12713012723
22960205410
24013764459
22498802395
32728394610
8612837200
10885647424
12031844074
7282316319
26511373001
2664334...

result:

ok 200000 lines

Test #34:

score: 0
Accepted
time: 824ms
memory: 242016kb

input:

200000 200000
4766 245 3995 1203 2666 2935 3003 3796 4233 1635 4921 84 4912 3479 1448 3072 655 1214 2147 4135 3017 2013 4105 3102 580 2236 3785 4267 2503 1568 3367 4219 3016 3305 3384 318 3442 2483 986 2802 3760 2722 438 2419 311 1833 1528 3782 2793 3960 4064 1977 1665 4912 4858 419 3080 3371 1704 3...

output:

1154807559
4585126550
6212649007
5125939648
7268924933
4786559200
5447279840
4885843055
3945102642
2760236135
4803555164
2105007069
5478488622
8500390626
4177506437
7958682962
11742107674
5424114838
5072594320
10417594179
649513393
5429946739
10352756958
3128523357
6100705348
10937794427
2547986750
...

result:

ok 200000 lines

Test #35:

score: 0
Accepted
time: 314ms
memory: 241068kb

input:

200000 200000
495 490 496 492 498 496 498 495 496 490 497 497 500 494 492 493 498 493 494 500 500 497 494 500 490 498 493 496 491 495 492 492 492 491 496 494 496 492 499 500 499 491 498 498 491 493 499 498 492 493 496 497 498 498 492 494 498 497 500 490 499 494 492 496 492 499 493 494 500 493 495 49...

output:

296991831
197993564
791926752
197988622
494959195
989908430
791934672
692963614
296990352
395989112
494964165
791958376
692949768
296990352
98995791
296981463
791954432
593954010
692967065
98993812
692956705
890917614
791962352
494961680
593974746
791962352
98994309
98997769
890930925
593948046
3959...

result:

ok 200000 lines

Subtask #3:

score: 31
Accepted

Test #36:

score: 31
Accepted
time: 966ms
memory: 243080kb

input:

200000 200000
28646 30154 5388 22119 32077 11843 22185 20457 4284 19797 14537 18426 21420 13034 28504 15056 17391 26651 4316 44669 34999 17336 14427 42183 25112 29907 16908 32904 23781 27635 44514 36024 12435 14555 40422 25692 43414 12346 3329 31641 29115 14449 12127 40639 1576 37164 13309 31976 113...

output:

7450981853127
27293062194659
110364549999546
7125556246842
116279620730
19109542894069
-1
2272372077636
68246604637944
23503319546799
811993199574
-1
525547926571
1654302033014
213109416873758
-1
1951754477279
60240802359572
2318612470778
6347007399747
427696556322
-1
42455737680576
155367200626716
...

result:

ok 200000 lines

Test #37:

score: 0
Accepted
time: 475ms
memory: 238556kb

input:

198781 200000
41347 20065 6204 4814 44018 8591 43440 12282 37222 21545 42129 17899 19806 40502 42837 1367 13361 31748 32713 18329 42398 27501 26213 19700 24809 43273 32352 888 4769 32491 469 38764 34396 16495 15540 14429 14239 43828 19180 34466 44392 10210 25920 41148 11337 8476 38167 14419 7816 355...

output:

195326293797462
192593075473614
436547269675178
279764593598739
36130303113145
277318574292498
99778036622194
448855277771852
152328823473274
238617697167297
415017690941858
-1
421007993862870
437743943218488
218990018175263
428518267554950
141846972047584
221483177204247
121397101867126
43303775982...

result:

ok 200000 lines

Test #38:

score: 0
Accepted
time: 536ms
memory: 263304kb

input:

199118 200000
163061 179623 143510 186465 18838 131740 31117 184300 117277 51345 84598 161889 49433 97945 152007 71659 108494 14554 163998 173373 76005 152943 67745 198141 17821 186169 49940 25285 138597 28148 32026 39280 124018 110112 130394 29195 90118 140298 122169 41652 113713 147245 46396 45386...

output:

1178218704720205
677773915384
1997517627123061
57974685628820
87435626029681
-1
694479375323
1693201760295853
177945035569540
310296661727165
1959723480643459
673076340322705
834218767545642
942363169116525
512195740668066
16709754857781
904159208094420
20674775647997
1379990284078222
27017679278560...

result:

ok 200000 lines

Test #39:

score: 0
Accepted
time: 864ms
memory: 239404kb

input:

192638 200000
200000 200000 200000 199996 199993 199992 199992 199991 199990 199989 199988 199986 199986 199985 199985 199984 199982 199981 199979 199979 199977 199977 199976 199976 199975 199972 199972 199971 199971 199970 199969 199969 199969 199968 199968 199968 199967 199967 199967 199966 199965...

output:

22747900261737
588389982480791
38956720702677
2358522175434
153460845596975
10495738360089
14731681124581
1208681373406
62024127687563
66167526112216
-1
1114971368068
16364159577873
1700502659235
1081192596006
220100720495225
296963416800
21069917519031
123955101952130
14059635028271
1371257868263
1...

result:

ok 200000 lines

Test #40:

score: 0
Accepted
time: 521ms
memory: 261804kb

input:

192997 200000
3 6 7 7 8 8 10 10 10 14 15 15 16 16 16 17 18 19 22 23 27 28 28 29 29 30 30 32 34 34 34 34 35 35 36 36 37 42 42 42 42 42 43 44 46 50 51 52 53 54 55 56 57 58 59 59 64 64 65 66 66 67 67 69 74 75 75 76 76 76 77 79 81 81 81 87 89 90 90 90 90 92 93 93 94 95 98 99 99 99 99 101 102 102 102 105...

output:

884552070206136
1348680568650510
-1
355411738489408
1235269267600281
831257733503223
1212879033741170
114801524540435
498845145610547
-1
626315406872607
734686091620573
-1
1364985778379039
142510314835926
112876269065844
599460397994590
1201647073748306
1065404328641356
58332420889155
35921868975135...

result:

ok 200000 lines

Test #41:

score: 0
Accepted
time: 512ms
memory: 236096kb

input:

190855 200000
13152 39369 21069 26278 7154 23230 6552 41074 14422 44265 17519 31611 6968 30489 14724 38717 16381 30696 9325 33835 5275 44929 4481 22738 13500 40380 563 37360 14052 29648 22082 44651 12153 38763 5696 29019 18617 37819 9132 31932 22135 32803 15195 36055 21387 38684 3478 25720 18510 325...

output:

286483864382441
111353825347137
423437007854579
62472178790145
112878436336389
336673756992723
372027242976358
393406893384076
389712719007654
403058442679944
128437154997944
158047849795747
408883483176214
407141152463427
369303517803366
388880289127605
360433990836983
31648360542416
32472527355703...

result:

ok 200000 lines

Test #42:

score: 0
Accepted
time: 928ms
memory: 241968kb

input:

197120 200000
199960 20 199926 199977 199981 1 100 199949 199931 92 70 68 199990 49 97 199921 90 45 199949 199950 87 199930 5 199910 39 199944 46 199933 35 199956 8 199928 199935 35 72 83 86 199951 45 100 199901 76 27 41 199955 81 199982 199979 199975 40 199973 199922 38 97 199966 16 199915 75 19990...

output:

-1
7229601490823
17880183975646
-1
14347681744836
52260608732334
521512180100181
-1
459020531748450
110513752556777
861252494358692
5867731745074
9370745833169
-1
117413356730470
4802232916502
14564798828719
9291429661807
-1
2978745969893
431465395115841
6980843171555
-1
-1
9061632379582
-1
67065268...

result:

ok 200000 lines

Test #43:

score: 0
Accepted
time: 444ms
memory: 234176kb

input:

190847 200000
199941 7 199951 33 18 20 199991 67 76 63 56 72 199912 94 56 199956 199952 199969 199980 78 199931 199950 199914 77 27 199912 199950 79 199908 85 1 43 16 15 49 49 199991 84 20 57 199900 28 60 16 98 199918 199972 199936 69 64 17 70 43 39 23 199956 199970 199966 199998 199903 199903 89 19...

output:

1966397883436288
1775581330592378
939253216690125
1622187401925307
1509452647679459
-1
1752237318839120
953114357867728
984285353869579
1989153796957219
-1
-1
-1
1273255951885604
-1
1969201890862282
1954890604208429
1749395116078014
1804429155918399
456198563037298
1430927391392460
467656275403935
1...

result:

ok 200000 lines

Test #44:

score: 0
Accepted
time: 476ms
memory: 262680kb

input:

194574 200000
199989 11 72 21 199910 199943 84 199924 199999 17 199980 199917 10 67 46 55 49 199925 99 199903 53 13 6 199955 199936 48 199964 199928 199922 90 25 199938 93 199961 71 199930 199901 22 34 199962 41 199950 5 199915 82 88 199920 8 199921 51 2 33 199983 71 1 25 199927 199997 199962 199922...

output:

182069204827332
1753363320675067
-1
502381920378792
6182900544253
50656740857004
-1
-1
138419556222294
1349317698654425
1333698441183693
-1
1334122933382248
432561904279188
262510725395837
1428356523194164
449921309911230
490680731564571
-1
1360900946393258
-1
1018638711813703
208532732354700
-1
701...

result:

ok 200000 lines

Test #45:

score: 0
Accepted
time: 409ms
memory: 241092kb

input:

200000 200000
495 496 495 495 500 496 491 493 499 496 500 490 498 492 495 490 490 490 500 491 493 494 500 491 499 493 490 494 494 499 499 497 491 496 490 491 496 491 490 490 493 492 498 500 490 492 497 500 498 493 490 498 496 493 498 495 492 491 496 490 493 490 495 493 493 500 496 491 496 490 500 49...

output:

2427267960155
2427016359685
2425823310215
2427256975549
2425862912843
2426426699614
2427860986069
2428018432855
2426471939310
2425568667698
2427668695280
2427659987449
2426219506770
2427956683147
2427070896611
2426860266491
2426521335404
2428015365529
2425767472809
2427363471169
2427475505992
242686...

result:

ok 200000 lines

Test #46:

score: 0
Accepted
time: 442ms
memory: 263920kb

input:

200000 200000
103551 188803 150957 167235 111671 9357 98322 20857 21314 52146 132627 182369 19964 14539 67310 193060 78720 193467 176482 89308 75105 109343 106842 131521 11862 146718 184945 191870 23686 193574 109181 96662 86219 78993 169997 33221 27085 152933 24454 14140 3917 48488 143047 170626 29...

output:

1088116548451813
17536515670585
1548735972870256
-1
-1
1271734436891697
-1
562605387279032
382621833822517
-1
28639913380994
142336895680836
412536683506160
721024406323791
1674424887330085
-1
1597206658
-1
1367211531870113
48254974085761
1853750978850
1793710746930795
215215879271557
-1
-1
29803627...

result:

ok 200000 lines

Subtask #4:

score: 44
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #47:

score: 44
Accepted
time: 1083ms
memory: 243024kb

input:

200000 200000
4440 1333 1534 2098 1068 3586 1637 1062 4089 3738 2473 2476 2105 2782 2439 3452 1497 85 2730 3984 2813 3522 3971 4690 2797 4421 2936 4463 3333 2241 4136 3250 3168 2443 3014 2978 3752 2559 412 2904 2096 2607 1366 4153 2124 4235 3688 162 3456 3894 589 4665 4011 2743 4895 2347 4445 1561 7...

output:

1866744289822
304889459618
29298000040
14216589013
6787607302917
1132981492162
509526046402
-1
-1
1960253152606
6026620577
-1
3408798849229
2570632892841
5904390511800
40493951549
2347600572
246200783352
39801475186
68104714828
2845501858460
47927479453
55077214946
1292322500115
-1
11733208179669
64...

result:

ok 200000 lines

Test #48:

score: 0
Accepted
time: 611ms
memory: 238064kb

input:

199066 200000
83028 18767 197999 109429 38645 168117 171495 33293 54570 1554 29945 86934 102883 5905 20648 114521 154672 71203 153374 33640 125560 150213 71651 64562 75021 55000 113780 190706 59063 23972 117738 71831 19124 182109 191092 118980 2001 189091 16049 4443 45526 74349 93641 129101 109017 1...

output:

1030539988177477
727320970407004
813264549962795
352765476713929
1090016209123940
552110550932017
-1
242058550910740
-1
1191575254890678
1307849356811630
1995551236768128
26686871450900
-1
1011675958380756
459741558559056
219989904379173
83512397613135
134701503239704
1555520957849080
19947615255210...

result:

ok 200000 lines

Test #49:

score: 0
Accepted
time: 629ms
memory: 263804kb

input:

200000 200000
4601 3145 1198 2679 3701 3914 3537 196 2707 4358 2957 3682 3809 4743 4267 4475 3377 3302 4598 2126 1368 2000 2002 2209 2740 3834 824 516 4368 142 854 4045 4417 117 2135 1691 3215 1490 3116 4002 2326 4393 231 4586 3360 1960 3333 2959 2465 2287 4689 215 391 908 2069 4962 2136 1696 1232 7...

output:

623601032384
49994337485186
12035541930512
37379808006034
1177526505313
50001284650593
31750545696989
34411784838795
18295124764140
31542253932506
43880741187475
24080406365741
34763659388628
8987809227268
23663506637877
2736860066499
32442484585410
7147459875767
2612274234156
1133708594956
20205273...

result:

ok 200000 lines

Test #50:

score: 0
Accepted
time: 938ms
memory: 243184kb

input:

196236 200000
2 3 4 5 6 8 8 9 9 9 10 12 13 16 16 16 17 22 23 24 25 25 28 28 28 29 30 33 34 34 35 36 37 40 40 40 41 42 43 43 43 44 48 49 52 53 53 54 54 55 55 56 57 57 58 60 61 62 64 64 65 65 66 69 70 70 70 71 73 74 74 75 75 79 79 79 80 80 81 81 82 82 85 88 88 89 90 91 92 92 93 94 94 95 96 97 97 100 1...

output:

12324427261714
95560037265262
118804428245293
36907901699541
5760547067348
53657272941494
102501228364045
94017391686469
7112696179868
89407244846069
262012237704836
247573965785783
35839180700466
57577289439477
96076145881737
90654745471775
17545046583
17663587386054
235030117168502
-1
269959666632...

result:

ok 200000 lines

Test #51:

score: 0
Accepted
time: 647ms
memory: 257248kb

input:

191823 200000
5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 4999 4999 4999 4999 4999 4999 4999 4999 4...

output:

2976247222650
1005804999597
8932705332274
3501065259671
2104149782518
1419440233149
65148912725157
65254637790893
534787833264
-1
8885354044798
29780761917757
64989818538793
276129349105
26174156675198
65255637396754
5020153813038
6701255594844
-1
8082773127695
14338208233819
16403492856585
40371085...

result:

ok 200000 lines

Test #52:

score: 0
Accepted
time: 625ms
memory: 236400kb

input:

194277 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 4999 4999 4999 4999 4999 4999 4999 4999 4999 4999 4999 4999 4999 4999 4999 ...

output:

30073405064749
6452274709665
22037421605719
815610678059
22044058881582
12268791561197
9990162042764
13944369258352
6671653952832
29194027652370
20927478586995
-1
11364140653975
34253734964537
768794181961
4920799278982
1050777823224
-1
29271976158955
6652532349259
3222367261387
25715097966554
24449...

result:

ok 200000 lines

Test #53:

score: 0
Accepted
time: 995ms
memory: 244140kb

input:

199674 200000
99 33 199930 85 199974 98 199937 46 40 199901 60 199930 63 199936 99 10 199963 44 41 52 25 64 199900 199983 199914 199954 8 199984 85 6 70 199999 66 199960 95 36 49 199968 89 85 14 199924 56 99 199932 15 199998 199900 199974 28 96 20 199911 199965 199926 53 199999 199926 59 199904 1999...

output:

-1
-1
61627351700020
-1
-1
1392991297312
147854465696856
1541038586180
984871470965983
-1
9500018984584
9338206046359
20807644147721
15903558886646
-1
158079828048622
383767426306750
4021163854614
12102639889739
129125798732334
108739896817363
-1
15671323147225
732155281166264
66283895409647
-1
3239...

result:

ok 200000 lines

Test #54:

score: 0
Accepted
time: 555ms
memory: 239436kb

input:

198022 200000
26 199935 199921 95 199977 199989 199954 64 24 199902 84 81 199909 3 199998 199925 34 199956 15 199906 46 74 199959 39 37 22 199917 44 82 92 95 199904 27 199965 199948 29 63 199928 199932 60 33 199995 199988 199912 20 199941 199930 25 38 199914 13 82 199907 199987 199909 72 14 199961 1...

output:

-1
710347133187781
614509967869881
215170591439167
1068062816626312
839569944604330
1445735248814307
1252374310691986
248681172302796
117748543798038
67789734423476
514401914199859
169023024924158
1622586497819183
-1
-1
1350352993305
-1
489410683616576
-1
109006840085978
443449212180684
101464909956...

result:

ok 200000 lines

Test #55:

score: 0
Accepted
time: 574ms
memory: 265776kb

input:

199666 200000
24 3 61 96 199990 199903 68 199911 66 199910 27 199935 13 14 78 199985 199928 100 17 199969 199991 62 56 49 52 86 199977 199908 55 75 199931 76 77 199977 41 70 56 199962 38 97 98 199946 80 39 59 199959 88 199946 78 199989 199943 199965 97 74 199913 199955 10 6 59 199988 90 199966 9 61 ...

output:

1101306085787497
798124441293142
1747818828119544
-1
-1
725614302750323
53977572302955
1068305984618286
304882964372125
232102640930726
1465705669495918
279608361352986
92502445566060
342617537048943
235225956374324
267777658174811
841688730545373
1017075500945457
320515163876146
456385120597318
207...

result:

ok 200000 lines

Test #56:

score: 0
Accepted
time: 417ms
memory: 238228kb

input:

200000 200000
498 499 498 491 492 500 495 494 495 492 493 491 495 498 496 496 495 500 497 496 499 493 490 495 497 490 500 495 490 491 491 493 492 500 493 496 497 492 493 493 490 500 493 497 490 493 495 493 493 494 491 495 494 499 491 499 497 496 493 493 498 491 493 496 491 497 490 500 500 500 493 49...

output:

2425237451890
2423802531914
2426740438253
2425797534756
2426632568541
2424878166144
2425352532564
2424091534961
2426083486394
2423964056854
2426772352056
2423711723361
2424591844516
2423891416564
2425784143647
2424094536264
2427281441481
2425579854337
2424155843794
2424482427084
2424750554431
242519...

result:

ok 200000 lines

Test #57:

score: 0
Accepted
time: 538ms
memory: 261824kb

input:

200000 200000
7024 136515 68390 1950 88170 96290 102925 94825 113269 123289 50906 76145 12887 18923 35924 105369 123313 159437 149208 35662 96077 151851 124529 11520 194363 66146 34268 14512 95889 58172 170566 11451 29814 161487 127288 172867 90250 117953 159143 188434 193900 33313 133081 54379 6782...

output:

712423794522660
-1
-1
-1
537909541127169
789155049970140
932543502702845
502419352438513
-1
1213529880164323
1015002729449254
-1
329787022670299
-1
-1
252671377408299
-1
-1
1227634268986698
-1
-1
180690383336414
1776283177984395
217519849823473
1305646617331838
-1
1332314175850142
-1
319892721140937...

result:

ok 200000 lines

Extra Test:

score: 0
Extra Test Passed