QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#720663#9604. CyberangelBronya100 ✓1046ms55192kbC++143.6kb2024-11-07 13:36:312024-11-07 13:36:37

Judging History

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

  • [2024-11-07 13:36:37]
  • 评测
  • 测评结果:100
  • 用时:1046ms
  • 内存:55192kb
  • [2024-11-07 13:36:31]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
namespace IO {
constexpr int MAXSIZE = 1 << 20;
char buf[MAXSIZE], *p1, *p2;
#define gc()                                                               \
  (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) \
       ? EOF                                                               \
       : *p1++)

int rd() {
  int x = 0, f = 1;
  char c = gc();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = gc();
  }
  while (isdigit(c)) x = x * 10 + (c ^ 48), c = gc();
  return x * f;
}

char pbuf[1 << 20], *pp = pbuf;

void push(const char &c) {
  if (pp - pbuf == 1 << 20) fwrite(pbuf, 1, 1 << 20, stdout), pp = pbuf;
  *pp++ = c;
}

}  // namespace IO
inline int read(){
    int x = 0, t = 1;
    char ch=getchar(); 
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            t=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);  
        ch=getchar();
    }
    return x*t;
}
inline void write(__int128 x)
{
    if(x<0){
    	putchar('-');
		x=-x;
	}
    if(x>9) 
		write(x/10);
    putchar(x%10+'0');
}
const int N=2e6;
int n,m;
__int128 ans=0,lans;
int a[N+5],id[N+5],id2[N+5];
int fa[N+5],fr[N+5],lim[N+5];
long long sum[N+5];
int cs=0;
int Find(int u){//cs++;
	// return u;
	return (u!=fa[u]?fa[u]=Find(fa[u]):u);
}
void Solve(int l,int r){
	if(l==r){
		id[l]=l;
		lans+=1ll*(m-a[l]+1)*a[l];
		return;
	}
	int mid=l+r>>1;
	Solve(l,mid);Solve(mid+1,r);
	int l1=l,l2=mid+1,l3=l;
	while(l1<=mid||l2<=r){
		if((l2>r)||(l1<=mid&&a[id[l1]]<=a[id[l2]]))id2[l3++]=id[l1],l1++;
		else id2[l3++]=id[l2],l2++;
	}
	for(int i=l;i<=r;i++)id[i]=id2[i];
	for(int i=l;i<=r;i++)fa[i]=i,sum[i]=0,fr[i]=0;
	stack<int>L,R;
	ans=0;
	for(int j=l;j<=r;j++){
		int x=id[j];
		if(x<=mid){
			while(!L.empty()&&L.top()<x){
				int y=L.top();L.pop();
				sum[x]+=sum[y];
				ans-=(__int128)sum[y]*(x-y);
				if(fr[y]==0)ans-=(__int128)a[y]*lim[y]*(r-mid);
				else {
					int z=Find(fr[y]);
					sum[z]-=1ll*a[y]*lim[y];
					ans-=(__int128)a[y]*lim[y]*(z-mid-1);
				}
				fa[y]=x;fr[y]=-1;
			}
			for(int i=j-1;i>=l;i--){
				if(id[i]<=mid)break;
				int y=id[i];
				if(fr[y]==-1)continue;
				fr[y]=x;sum[x]+=1ll*lim[y]*a[y];
				ans-=(__int128)a[y]*lim[y]*(x-l+1);
			}
			if(!L.empty()){
				int y=L.top();
				if(fr[y]==0)ans+=(__int128)a[y]*(r-mid)*(y-x-lim[y]);
				else {
					int z=Find(fr[y]);
					sum[z]+=1ll*a[y]*(y-x-lim[y]);
					ans+=(__int128)a[y]*(z-mid-1)*(y-x-lim[y]);
				}
				lim[y]=y-x;
			}
			lim[x]=x-l+1;L.push(x);
			ans+=(__int128)a[x]*lim[x]*(r-mid);
		}
		else {
			while(!R.empty()&&R.top()>x){
				int y=R.top();R.pop();
				sum[x]+=sum[y];
				ans-=(__int128)sum[y]*(y-x);
				if(fr[y]==0)ans-=(__int128)a[y]*lim[y]*(mid-l+1);
				else {
					int z=Find(fr[y]);
					sum[z]-=1ll*a[y]*lim[y];
					ans-=(__int128)a[y]*lim[y]*(mid-z);
				}
				fa[y]=x;fr[y]=-1;
			}
			for(int i=j-1;i>=l;i--){
				if(id[i]>mid)break;
				int y=id[i];
				if(fr[y]==-1)continue;
				fr[y]=x;sum[x]+=1ll*lim[y]*a[y];
				ans-=(__int128)a[y]*lim[y]*(r-x+1);
			}
			if(!R.empty()){
				int y=R.top();
				if(fr[y]==0)ans+=(__int128)a[y]*(mid-l+1)*(x-y-lim[y]);
				else {
					int z=Find(fr[y]);
					sum[z]+=1ll*a[y]*(x-y-lim[y]);
					ans+=(__int128)a[y]*(mid-z)*(x-y-lim[y]);
				}
				lim[y]=x-y;
			}
			lim[x]=r-x+1;R.push(x);
			ans+=(__int128)a[x]*lim[x]*(mid-l+1);
		}
		lans+=ans*(j<r?a[id[j+1]]-a[x]:m-a[x]+1);
	}
}
int main(){
	n=IO::rd();m=IO::rd();
	for(int i=1;i<=n;i++)a[i]=IO::rd();
	Solve(1,n);
	write(lans);
	return 0;
}

详细

Subtask #1:

score: 5
Accepted

Test #1:

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

input:

500 995106803
150608560 532482040 23208958 442246216 2917205 948292264 962672628 610596054 69010421 206923685 605381259 560683057 374135360 323257595 224120348 773540778 414928542 327812091 524797091 241525558 228068400 618957683 365266079 992727350 87923118 536412424 557677355 392087162 158151043 2...

output:

59854856571283884484109

result:

ok single line: '59854856571283884484109'

Test #2:

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

input:

500 998177916
831776477 192175032 961088945 183712798 579677277 717304183 832903374 615887036 442602679 409553238 129885355 100943200 343489036 687786479 430405465 777511373 204923633 343819665 25948944 842220326 549608142 468749656 142098334 933571884 251697899 59109537 789796162 785935340 73343227...

output:

60246542713395218641133

result:

ok single line: '60246542713395218641133'

Test #3:

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

input:

500 997709021
801389775 126836923 995423900 219539434 339502026 400019091 497938039 72089859 869274947 184571531 95809171 59962362 417254404 298805403 917564456 174720088 556735156 56414432 280677373 588219772 522819920 10779045 716982277 910938390 725089141 281874084 483114735 734955935 987450129 1...

output:

60181661281845334448315

result:

ok single line: '60181661281845334448315'

Test #4:

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

input:

500 999864497
627827881 25595645 328673824 270847919 489497074 903403290 421254283 159758901 6189614 343812596 911516439 60128926 482199981 830880981 367241232 57161002 550510139 120327439 186258690 809283515 227915662 506674645 430185166 372234930 650467661 69593303 51637417 704635555 894789119 531...

output:

60396928745198318213258

result:

ok single line: '60396928745198318213258'

Test #5:

score: 5
Accepted
time: 3ms
memory: 15876kb

input:

500 998970591
594389705 43008089 396347059 986339673 905846754 807045742 470917409 639614371 637270684 136879653 58845444 425605406 777235535 28588928 139911753 103232624 154106955 961479631 886521757 107881189 253056135 620990994 615378167 665480349 722387860 856766009 760620628 65813484 801372010 ...

output:

60301465403020284987744

result:

ok single line: '60301465403020284987744'

Test #6:

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

input:

500 989354834
660461 1884309 2515211 2982180 6020191 8648567 9104058 9622568 11387149 15218527 15757206 15839199 17545553 18657144 23829639 23974929 24203477 25293790 29677662 31112007 32068246 33915814 39839268 40549810 42735311 43467522 44090402 46074234 48410214 49938093 51091987 52098376 5237871...

output:

40532371095490200672323

result:

ok single line: '40532371095490200672323'

Test #7:

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

input:

500 995856121
995856021 993286190 992428714 987211623 986866652 973993987 970908624 965906992 962384596 961444659 959872088 959274665 954413029 954237972 952206028 950914253 936598037 936541012 936315259 933876938 931901616 929610770 928438496 928418851 927097736 925343918 922758477 921599847 915514...

output:

41163428747490462739833

result:

ok single line: '41163428747490462739833'

Test #8:

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

input:

500 996970428
55157343 782882347 768451599 768451599 216444512 768451599 26520824 371900895 628553310 870731874 768451599 189471193 371900895 564613440 371900895 870731874 443892194 628553310 515311766 626042362 953946357 371900895 139227361 443892194 766070123 766070123 953946357 953946357 37190089...

output:

56893191095878174612719

result:

ok single line: '56893191095878174612719'

Test #9:

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

input:

500 999683066
223727705 480369708 112292804 481160745 224317240 481725729 45280199 488390505 224431750 489839974 117626392 490591180 224711896 490697505 17917789 491413367 224744745 494790152 118515418 495247247 224837576 505897124 58691469 507771381 225294818 507936116 120348431 508509141 227390703...

output:

53154300124913676131137

result:

ok single line: '53154300124913676131137'

Test #10:

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

input:

500 996680038
197437207 458179304 97398864 458338863 198111821 462929198 47263622 464290325 198266716 467555428 100906560 470063484 199483735 472198668 21866514 472442955 200116781 473511671 101048946 476465465 202606998 477951175 47358497 485263524 203886219 488787675 102911236 490111517 207661861 ...

output:

52269022842767688419390

result:

ok single line: '52269022842767688419390'

Test #11:

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

input:

500 996836518
225663257 487415392 113657597 489627476 229686724 493005821 55589679 494314979 231928299 495884741 113824536 497766188 234758176 499178014 24183623 500198901 237391031 500395616 114684268 501242775 240056411 504928824 57255729 508780751 240102366 510732434 116605228 511761619 241162385...

output:

52901323000404343054947

result:

ok single line: '52901323000404343054947'

Test #12:

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

input:

500 997308361
734384892 487928623 885511190 485978519 732782900 485503315 943352135 485139910 731135061 483452593 884499732 480665632 728846479 470610017 966846915 469944921 726748288 466928565 884344389 466856622 726342874 466668864 941970606 466454046 723150867 464794706 884103531 462749291 723117...

output:

52771619017756982130181

result:

ok single line: '52771619017756982130181'

Test #13:

score: 5
Accepted
time: 3ms
memory: 18188kb

input:

500 998995500
707934238 443951641 841012116 443699773 707580586 443209459 924668947 442662521 706274831 442081118 838685438 439562971 705821480 437121050 970118929 432994869 701550583 431651576 838650253 430926740 701508876 419349462 922548610 417491326 696577019 416970255 837263122 413262645 687275...

output:

53853636162421336664462

result:

ok single line: '53853636162421336664462'

Test #14:

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

input:

500 996650138
765626812 453357781 885559897 453256645 761785891 450241520 934514768 446699514 755330669 443755169 884997036 443304254 754923200 434085582 970099818 430508063 754466272 425416574 884513817 424764093 754038009 423164779 934372987 423139345 738573359 422204416 884460993 417674914 732117...

output:

52624776032982600280160

result:

ok single line: '52624776032982600280160'

Test #15:

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

input:

500 999700415
582362183 192179044 534193232 257560075 715029649 684274335 816995706 839543380 688559527 634842016 384705910 136286773 34458146 605084919 279247643 786036528 266661206 203719326 482073421 104473700 627545971 142037098 832947668 418619361 115575142 982412566 388148602 468755125 3841767...

output:

60332370236440636673573

result:

ok single line: '60332370236440636673573'

Subtask #2:

score: 5
Accepted

Dependency #1:

100%
Accepted

Test #16:

score: 5
Accepted
time: 2ms
memory: 15968kb

input:

4000 999415835
325434705 485976668 926029739 370138494 732722191 208960936 412781133 493804459 4441873 29594424 212942231 469635956 113686686 586697026 150736460 253382523 181223360 944337109 416622295 467119741 260653459 645818255 435141298 973596863 434331375 615989573 998308216 741169188 12392168...

output:

3970595078712735751359371

result:

ok single line: '3970595078712735751359371'

Test #17:

score: 5
Accepted
time: 5ms
memory: 15968kb

input:

4000 999802203
649599118 250242603 68728072 326316859 495033111 280504659 609604408 220764914 987811589 424440173 93884997 758158169 950052420 735205708 754774713 403044281 925970729 869867857 793650314 144640266 692849593 268339283 395685942 279053437 386372770 454100953 954177968 293123588 2209313...

output:

3973569086333886235045817

result:

ok single line: '3973569086333886235045817'

Test #18:

score: 5
Accepted
time: 5ms
memory: 17940kb

input:

4000 999877964
366336061 5210161 430101309 335127841 327462116 704349665 757207803 152973338 175661848 115244100 300447019 919391649 774029717 151987390 197961326 457019353 202390579 681204583 808751729 731297172 473513672 36167641 621014106 514616325 491331963 66505607 355272432 776013920 51048286 ...

output:

3974047727292952591000299

result:

ok single line: '3974047727292952591000299'

Test #19:

score: 5
Accepted
time: 4ms
memory: 15844kb

input:

4000 999849325
314868515 254328634 886011412 690249804 131156418 749422062 944497587 939604455 255160614 561080726 368272617 204518254 436529716 59820879 562032608 325312316 181182732 364045397 521201470 285317185 14219931 545598397 506701309 277400987 633623772 703083605 815923782 512555570 6845219...

output:

3974026736738603400578723

result:

ok single line: '3974026736738603400578723'

Test #20:

score: 5
Accepted
time: 5ms
memory: 18232kb

input:

4000 999649683
293143786 404089543 948645960 591213944 420128767 913693955 904637197 90800310 285150476 40950603 561661321 824213238 245828843 95056861 901351197 260851255 529952933 567089905 577858555 278276783 867308618 151221118 542207472 381126520 757554818 581601842 978757967 34224053 402078118...

output:

3972590869295078207458903

result:

ok single line: '3972590869295078207458903'

Test #21:

score: 5
Accepted
time: 3ms
memory: 18216kb

input:

4000 999218074
322817 448108 1286850 1517907 1751394 1933727 1969357 1970595 2180924 2228253 2813059 2819753 2858829 2969167 2991999 3018423 3440367 3644635 3745672 4007786 4030391 4217008 4419577 4425316 4434695 4710215 4740192 5029585 5051326 5197090 5216976 5344821 5757139 5870299 5907179 6286242...

output:

2659476620951389455115559

result:

ok single line: '2659476620951389455115559'

Test #22:

score: 5
Accepted
time: 2ms
memory: 18012kb

input:

4000 999981742
999981642 999695393 999576758 998588017 998141300 997821833 997412364 996967360 996626793 996586318 996507782 996270534 996194469 995965073 995351707 995274486 995102954 994858106 994809057 994205121 993397640 993370901 993229088 992832981 992647741 991702382 991607766 991482261 99135...

output:

2661497262129514677449083

result:

ok single line: '2661497262129514677449083'

Test #23:

score: 5
Accepted
time: 2ms
memory: 17952kb

input:

4000 999998958
80298119 639623534 252373841 252373841 608720231 484025037 942468624 903920599 451221576 188477857 440570903 237556588 80298119 193335644 696786290 639623534 252373841 183942572 788156619 788156619 188397915 203318773 55628357 223723934 188477857 463664308 80298119 696786290 34175503 ...

output:

3860241287673882783928813

result:

ok single line: '3860241287673882783928813'

Test #24:

score: 5
Accepted
time: 4ms
memory: 15968kb

input:

4000 999947196
214942340 464409068 109365821 464921377 214993245 465607259 56260965 465620386 215230440 465885744 109490186 465940347 215301695 465991711 27981930 466373867 215602198 466493112 109789662 467266751 215686242 467670762 56325714 467840457 215712437 467925361 110074398 468260419 21594999...

output:

3392374041798690694758388

result:

ok single line: '3392374041798690694758388'

Test #25:

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

input:

4000 999999487
218682572 490886474 106276872 491038599 219062294 491785864 52115263 491844714 219234571 492390769 106436098 492590218 219475533 493221333 27006922 493446981 219607721 493480680 106511961 493595231 219918468 493679774 52477644 493748411 219937062 493890295 106590281 493897494 22080828...

output:

3404899865741070334696090

result:

ok single line: '3404899865741070334696090'

Test #26:

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

input:

4000 999870525
217442425 477510224 106411508 477897702 217857300 478055519 53847707 478223762 218453183 478530742 106606463 479257650 219043641 479372241 27806875 479563483 219101462 479747067 107088825 479769420 219261547 480193067 53870525 480275186 219453795 480459697 107565396 481178742 21952370...

output:

3398492240577479556055359

result:

ok single line: '3398492240577479556055359'

Test #27:

score: 5
Accepted
time: 2ms
memory: 18016kb

input:

4000 999883955
729352274 461616143 866927797 461561189 729126408 461504230 933802293 461276976 728847649 461137600 866127851 461060925 728573581 461055654 965971255 461007013 728544812 460447099 866048510 460215816 728280963 460090715 933186083 459641714 728063215 459566415 866010625 459427713 72776...

output:

3461503156788610927181394

result:

ok single line: '3461503156788610927181394'

Test #28:

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

input:

4000 999836657
726830261 437428117 864291876 437323121 726389365 436458491 929883217 436151067 726372382 436006434 863853298 435889116 726112171 435354528 959868001 435028691 725992398 434401003 863845895 433804894 725960900 432689843 929715566 432556191 725825927 432181732 862812972 432118481 72538...

output:

3470328507514617180628041

result:

ok single line: '3470328507514617180628041'

Test #29:

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

input:

4000 999709272
728347937 454004519 860864229 453924255 728304682 453916739 931339376 453578314 727171596 453474157 860846212 453070751 727104606 452793137 967850158 452643321 726707831 452573104 860480356 452143802 726689292 452074495 931046885 452001062 726167880 451665383 860026196 451328684 72564...

output:

3459828322351305394151676

result:

ok single line: '3459828322351305394151676'

Test #30:

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

input:

4000 999983168
212171530 317645701 896420454 999983068 927873123 820697889 226091734 339988907 451707831 859400977 940847121 759591226 230435743 587395309 145084943 243699242 137076914 419528394 68029220 329940970 36749752 918563727 667086543 715080242 694075052 521593064 936248720 693562834 3012614...

output:

3975167381683625168594671

result:

ok single line: '3975167381683625168594671'

Subtask #3:

score: 5
Accepted

Test #31:

score: 5
Accepted
time: 423ms
memory: 54180kb

input:

1000000 2
2 1 1 1 2 2 2 2 2 2 2 1 2 2 1 1 1 2 2 2 2 1 2 2 1 2 1 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 1 1 2 1 1 2 1 1 1 1 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 1 1 2 1 1 1 2 1 1 1 2 2 2 2 2 2 1 1 2 1 1 2 2 2 2 2 1 1 2 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 2 2 1 2 2 1 2 1 2 2 2 1 1 2 2 1 1 2 2 1 1 1 1 1 2 ...

output:

1499999500314

result:

ok single line: '1499999500314'

Test #32:

score: 5
Accepted
time: 418ms
memory: 51600kb

input:

1000000 2
1 1 1 2 1 2 1 1 2 2 1 2 2 2 1 2 2 1 1 2 2 2 2 2 1 1 2 1 2 2 2 1 1 2 1 2 1 2 1 2 1 2 1 1 2 2 1 2 1 1 2 2 2 1 1 1 2 1 2 1 1 1 1 1 1 1 1 2 1 1 1 2 2 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 1 1 2 2 2 1 1 1 2 2 1 2 2 2 2 2 2 1 1 1 2 2 1 2 1 1 1 2 2 1 1 1 1 1 2 1 2 1 1 1 2 1 1 2 2 1 2 1 2 1 2 1 1 2 2 1 ...

output:

1499999506039

result:

ok single line: '1499999506039'

Test #33:

score: 5
Accepted
time: 424ms
memory: 55192kb

input:

1000000 2
2 2 1 2 2 1 1 2 2 1 2 1 2 2 1 2 1 1 2 1 2 1 1 1 2 1 1 2 2 1 1 1 1 1 2 1 2 2 2 2 2 1 1 1 2 2 1 2 1 1 1 2 2 2 1 2 2 2 2 2 1 1 1 2 1 2 2 1 2 1 2 1 2 1 1 2 1 2 2 1 2 2 2 2 1 2 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 2 1 2 2 2 1 2 2 2 1 2 1 1 2 2 1 2 2 1 2 2 2 1 2 1 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 ...

output:

1499999502685

result:

ok single line: '1499999502685'

Test #34:

score: 5
Accepted
time: 423ms
memory: 54876kb

input:

1000000 2
2 1 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 1 2 1 2 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 1 2 2 1 2 2 1 2 2 2 1 2 1 1 1 2 2 2 2 1 1 1 2 2 2 1 1 1 1 1 2 2 1 1 2 2 2 1 2 2 1 2 1 1 2 2 2 2 2 2 1 2 1 1 1 2 2 2 1 1 2 2 2 1 1 1 1 1 1 2 2 2 2 1 1 2 1 2 2 1 1 2 1 2 2 2 1 2 2 1 2 1 2 1 2 1 2 2 1 2 1 1 1 1 1 2 1 2 ...

output:

1499999500625

result:

ok single line: '1499999500625'

Test #35:

score: 5
Accepted
time: 428ms
memory: 54592kb

input:

1000000 2
2 2 2 1 2 2 1 2 1 1 2 1 1 1 2 2 2 2 2 2 2 1 1 2 2 2 2 2 1 1 1 2 1 1 1 1 1 2 2 1 1 2 2 1 1 1 1 2 2 2 1 2 1 1 1 1 1 1 2 1 1 2 2 2 2 2 2 2 1 1 1 2 2 2 1 1 1 1 1 2 2 1 2 2 1 2 1 1 1 2 1 2 2 2 2 2 2 1 2 2 1 1 2 1 1 1 2 1 2 1 1 2 1 1 2 1 1 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 2 2 1 1 1 1 1 2 1 2 2 2 2 ...

output:

1499999504912

result:

ok single line: '1499999504912'

Subtask #4:

score: 20
Accepted

Dependency #3:

100%
Accepted

Test #36:

score: 20
Accepted
time: 695ms
memory: 50516kb

input:

1000000 50
40 1 23 10 38 24 24 18 4 4 7 29 9 2 38 29 10 8 30 27 46 29 10 23 23 3 49 33 50 27 35 21 26 9 43 30 47 23 19 20 15 44 48 36 35 19 50 17 18 41 26 27 50 8 25 41 28 41 41 3 11 29 42 10 28 8 29 29 2 43 48 34 9 13 2 44 10 23 26 43 1 47 29 47 9 14 14 39 35 11 42 5 30 12 44 47 37 33 37 40 43 36 4...

output:

637492948235135

result:

ok single line: '637492948235135'

Test #37:

score: 20
Accepted
time: 714ms
memory: 49808kb

input:

1000000 50
16 49 20 6 16 19 42 5 14 35 1 33 46 25 1 11 12 5 26 1 6 33 36 38 26 16 3 21 5 40 2 4 50 14 10 19 31 31 12 32 31 34 27 21 42 20 38 39 1 3 47 1 42 23 22 42 40 38 23 45 7 48 2 47 11 13 22 48 36 23 39 19 44 31 23 1 4 39 33 41 27 5 13 21 24 43 21 43 20 36 27 36 14 6 8 48 22 19 4 47 13 13 37 16...

output:

637492938291731

result:

ok single line: '637492938291731'

Test #38:

score: 20
Accepted
time: 706ms
memory: 50288kb

input:

1000000 50
6 18 21 30 24 2 18 8 29 18 42 45 6 15 27 41 30 24 33 13 30 39 23 35 7 6 31 19 28 4 13 26 24 37 5 34 40 9 4 38 18 2 43 25 29 32 26 24 2 5 31 21 7 16 4 6 30 39 44 26 34 47 15 33 8 3 22 48 43 3 17 35 15 47 38 40 46 3 40 15 24 37 2 22 39 34 30 21 10 18 8 3 41 31 45 4 49 46 36 1 23 19 22 21 23...

output:

637492935401403

result:

ok single line: '637492935401403'

Test #39:

score: 20
Accepted
time: 731ms
memory: 53572kb

input:

1000000 50
37 43 9 28 41 28 32 37 5 21 22 16 29 10 13 20 9 49 29 23 45 47 28 5 35 21 33 13 7 32 46 7 50 20 42 47 12 2 25 41 6 48 4 11 16 38 41 47 42 11 18 15 21 47 13 1 50 15 16 28 8 5 36 41 15 41 29 50 28 16 45 18 2 6 6 38 5 22 23 20 10 9 23 45 3 11 50 32 33 5 42 24 15 20 25 5 22 1 29 14 16 42 5 6 ...

output:

637492942865162

result:

ok single line: '637492942865162'

Test #40:

score: 20
Accepted
time: 738ms
memory: 50784kb

input:

1000000 50
36 10 4 4 8 41 38 11 41 19 30 31 12 21 10 17 23 49 46 1 27 44 23 18 13 16 32 34 15 45 33 27 40 19 21 25 50 27 25 50 8 37 15 50 30 38 37 12 42 36 19 1 32 29 6 38 43 26 17 37 17 9 21 45 22 13 43 33 17 19 18 50 32 30 43 46 20 22 49 18 44 33 13 36 50 40 35 3 17 36 18 47 49 14 46 24 31 31 45 1...

output:

637492940655745

result:

ok single line: '637492940655745'

Subtask #5:

score: 10
Accepted

Test #41:

score: 10
Accepted
time: 500ms
memory: 33820kb

input:

500000 999997472
323565887 829841159 316294741 207123786 197822285 87425904 283234947 457350978 346818392 59983222 782455248 784568068 729477373 116544863 669509195 402486856 202576480 122339471 760623311 842345622 481616662 856729905 50173442 129883284 52084768 196396910 320675364 895095006 6623157...

output:

62494142856139796619073017185

result:

ok single line: '62494142856139796619073017185'

Test #42:

score: 10
Accepted
time: 428ms
memory: 34740kb

input:

500000 999999553
667453610 985296846 471867206 423696432 233164549 154579933 367256868 728088881 476194023 677038635 749157071 751430375 85313530 331919642 246642439 391435901 997652469 559113830 384029939 555439403 475608681 457340998 228043331 131094541 41708960 940467763 396070120 622422171 78747...

output:

62494406715437396311893377081

result:

ok single line: '62494406715437396311893377081'

Test #43:

score: 10
Accepted
time: 435ms
memory: 33552kb

input:

500000 999998743
464862541 664034699 394902484 584423210 493215309 106482211 523666077 670018355 601304012 709311860 588414424 927001567 173321522 869869225 562063292 734075465 368832112 112786699 479176298 601727933 384016812 307112969 458188366 380837831 40405318 149226410 955683156 187817692 8302...

output:

62494301541996963734473914707

result:

ok single line: '62494301541996963734473914707'

Test #44:

score: 10
Accepted
time: 431ms
memory: 31948kb

input:

500000 999999154
148629783 396065662 507286031 60252364 812258831 990156550 482055480 344612745 662120204 218541175 617656479 140458580 281288174 215390077 292794180 785929872 15303218 137846606 143030359 405903938 341246613 878156010 771716573 127241069 253172468 974059930 265787570 994605699 38947...

output:

62494357582343278093672682827

result:

ok single line: '62494357582343278093672682827'

Test #45:

score: 10
Accepted
time: 437ms
memory: 34440kb

input:

500000 1000000000
354441153 587161063 644374382 494175154 31242329 125426507 411623955 259888466 869007726 160597405 896021904 765095877 129610454 114787457 361773764 525472552 242017756 874017002 65209160 846899181 214776846 781131283 129559262 742812029 183166905 578824254 79611675 347781223 64259...

output:

62494461286669963181498291894

result:

ok single line: '62494461286669963181498291894'

Subtask #6:

score: 20
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #46:

score: 20
Accepted
time: 74ms
memory: 21600kb

input:

100000 999993517
598790459 537183965 68335700 591512847 918579772 779728634 48635238 740788103 407135955 819858816 563534822 567426511 517675399 559397183 296013105 923989546 259659935 728984034 189521707 829247701 283361594 213446040 199487702 371296223 366945332 121551756 10042853 341828937 107625...

output:

2499023948226277145506670339

result:

ok single line: '2499023948226277145506670339'

Test #47:

score: 20
Accepted
time: 73ms
memory: 24012kb

input:

100000 1000000000
228638491 342616552 266382758 5620534 331715907 171982354 517556742 898641868 893053146 367319613 259209178 24105248 620120127 162182814 260734438 456868228 928250275 433673591 102770151 141638275 371115215 884752629 84165921 263475491 604184639 723208585 466771639 977658195 341406...

output:

2499058342036176563445261927

result:

ok single line: '2499058342036176563445261927'

Test #48:

score: 20
Accepted
time: 73ms
memory: 21732kb

input:

100000 999993562
774238858 163464263 230752092 408034190 495695380 629066311 72378650 926166525 472820642 167046472 620544068 289242404 88988859 40931951 559244087 148475563 619694680 602826768 439388468 135675054 864788457 833456553 634132595 381781768 110222994 466984438 319714467 54903233 1539095...

output:

2499024285320100699543949927

result:

ok single line: '2499024285320100699543949927'

Test #49:

score: 20
Accepted
time: 77ms
memory: 21032kb

input:

100000 999977575
440316497 909968433 759958606 4576290 489575973 457463493 771829864 211997526 82253332 402192606 706897977 236511354 979476305 251882596 177304903 780317568 170605235 98992665 703024310 531079 929286317 977712751 372337703 444874080 591144838 162612317 29869947 52675990 205247058 33...

output:

2498943155127844474124965206

result:

ok single line: '2498943155127844474124965206'

Test #50:

score: 20
Accepted
time: 75ms
memory: 21620kb

input:

100000 999982412
574843805 326482 521329603 541304676 902554609 840100877 791913133 889911995 48623127 229926099 184005818 912782982 309194325 842293045 563458953 906453280 817706701 5036583 265909915 493187390 888003651 402029109 487425451 578006353 457563267 768631159 793134694 301549180 383641077...

output:

2498966815278645425457031022

result:

ok single line: '2498966815278645425457031022'

Test #51:

score: 20
Accepted
time: 30ms
memory: 21236kb

input:

100000 999977998
2451 5660 6122 15876 15878 16927 25109 37029 48545 50068 59046 64887 68970 73887 79793 84821 91133 91692 92448 93053 97647 102604 110023 119978 137892 142562 144540 156431 161115 183617 190234 216247 218827 220156 236005 243839 247102 259763 264579 276364 279000 281951 293441 307885...

output:

1662901433801840811138768796

result:

ok single line: '1662901433801840811138768796'

Test #52:

score: 20
Accepted
time: 22ms
memory: 24084kb

input:

100000 999998336
999998236 999988614 999986594 999985837 999956264 999955082 999946593 999942913 999931615 999917014 999895181 999886402 999866103 999862849 999861375 999853359 999847466 999843175 999813003 999803665 999800225 999793929 999785092 999770201 999748922 999747280 999741188 999709688 999...

output:

1662489461317694235716115907

result:

ok single line: '1662489461317694235716115907'

Test #53:

score: 20
Accepted
time: 68ms
memory: 19624kb

input:

100000 999957623
446810386 821543315 100399296 587500888 895104175 868516855 946002331 781682911 507245685 578791020 611566484 537817388 248645058 712082644 780469663 525473449 712082644 616400268 796565250 99256758 62457143 446805472 928836180 756185122 822701847 310766718 406043292 949612509 51481...

output:

2484109152497159511916644641

result:

ok single line: '2484109152497159511916644641'

Test #54:

score: 20
Accepted
time: 40ms
memory: 21924kb

input:

100000 999994277
281898679 630126597 142553898 281915375 630127001 71267112 281919938 630128155 142560906 281920542 630159000 35303546 281931516 630160661 142565083 281932199 630169727 71281342 281946839 630180393 142565618 281956414 630227849 17437135 281961762 630234503 142572511 281964793 6302454...

output:

2183642082294724399987613045

result:

ok single line: '2183642082294724399987613045'

Test #55:

score: 20
Accepted
time: 33ms
memory: 22236kb

input:

100000 999989935
281824492 630732578 140813734 281826924 630734141 69392416 281841389 630737498 140824745 281843264 630755465 34412684 281871957 630759373 140830416 281886105 630763025 69401629 281893721 630763528 140835959 281909546 630792661 17006964 281915507 630795726 140861060 281916302 6308032...

output:

2183769234221601045239518166

result:

ok single line: '2183769234221601045239518166'

Test #56:

score: 20
Accepted
time: 37ms
memory: 24288kb

input:

100000 999987678
281725806 632151301 140712805 281732383 632155953 69283754 281737209 632182415 140719751 281750239 632182932 34977356 281750468 632194469 140727664 281756619 632197101 69284308 281765670 632217723 140738076 281765774 632239068 17702922 281801935 632251088 140747614 281802482 6322631...

output:

2182903070453698278314708450

result:

ok single line: '2182903070453698278314708450'

Test #57:

score: 20
Accepted
time: 39ms
memory: 21988kb

input:

100000 999996529
648747031 295151456 824446917 648742536 295149513 913074050 648720054 295145623 824428193 648714328 295136686 956036335 648714121 295134544 824404550 648712884 295127399 913069066 648711418 295091129 824403429 648710149 295074229 978051246 648709094 295072495 824395134 648687304 295...

output:

2210236369225836428102049853

result:

ok single line: '2210236369225836428102049853'

Test #58:

score: 20
Accepted
time: 35ms
memory: 21304kb

input:

100000 999990094
647869938 296015868 823938266 647864237 296005968 912569107 647862123 296000511 823932479 647861955 295994770 956007004 647856432 295978580 823921291 647853062 295976664 912564165 647838184 295973140 823909637 647826660 295955563 977860577 647823348 295933740 823886750 647821581 295...

output:

2210984650161167649271540660

result:

ok single line: '2210984650161167649271540660'

Test #59:

score: 20
Accepted
time: 36ms
memory: 21964kb

input:

100000 999994348
649084114 296653978 822986271 649074322 296650018 911479084 649070948 296649224 822978103 649069705 296640329 955840774 649059329 296625221 822964545 649055630 296575438 911470886 649050628 296570515 822959340 649044596 296566986 978186172 649033537 296553202 822917858 649023017 296...

output:

2212041173434475498073650808

result:

ok single line: '2212041173434475498073650808'

Test #60:

score: 20
Accepted
time: 70ms
memory: 22964kb

input:

100000 999994910
402614565 872918387 479539441 918569383 303408166 464271786 595082956 949339001 417522902 263277467 322516311 76083352 443960075 100777481 178873091 145969229 362760923 860245864 142129279 315660521 484105242 575119623 730203830 313225238 463216216 940743776 808572493 207747033 5913...

output:

2499029187162010067381946992

result:

ok single line: '2499029187162010067381946992'

Subtask #7:

score: 35
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Test #61:

score: 35
Accepted
time: 1008ms
memory: 51120kb

input:

1000000 999999769
887751698 684907202 30164919 121455250 754727041 100571558 67233720 212870688 945051356 183621868 974015571 923270922 468271440 954586111 16297684 987685536 287454950 440969821 756894983 362462889 580766494 477147569 330514939 102381089 692280549 913206882 965370285 194351327 29558...

output:

249988114394895168554036233524

result:

ok single line: '249988114394895168554036233524'

Test #62:

score: 35
Accepted
time: 1011ms
memory: 50596kb

input:

1000000 999999924
606144713 862645786 230359041 730860134 530558913 58999293 125269549 48197984 610837372 85588682 482847101 503557816 992645909 51556251 736172543 372563596 10508798 407147723 374942697 239889865 472305015 299052626 989636159 725000221 641867623 65387432 146967739 861412575 10999666...

output:

249988182691488924244985000869

result:

ok single line: '249988182691488924244985000869'

Test #63:

score: 35
Accepted
time: 935ms
memory: 48016kb

input:

1000000 999999781
413353073 78715385 342158468 203513655 661720078 520578172 850802856 331022104 422856000 730619262 19233757 354449273 741330884 316548087 924816231 70817558 242928849 261426160 989921126 37988126 525612794 326712662 832696931 997091653 866686817 782440167 227244763 811445401 583238...

output:

249988116903321417362305553477

result:

ok single line: '249988116903321417362305553477'

Test #64:

score: 35
Accepted
time: 935ms
memory: 47712kb

input:

1000000 999999112
401279898 532704737 273289498 627493323 31347897 839339632 310586269 478991294 575540075 448279966 183294566 808886931 560749819 293207998 818876305 272153950 63647029 40276099 549742072 794383031 375064457 267389001 883534720 194912305 568642073 999534553 848080660 750440900 75227...

output:

249987780976305782861954187561

result:

ok single line: '249987780976305782861954187561'

Test #65:

score: 35
Accepted
time: 923ms
memory: 49368kb

input:

1000000 999998251
786262005 135970857 554942604 31668490 531846930 434912844 966943054 52392738 744626198 548819431 51735538 823576676 205461447 124544766 52138307 720733713 533150805 665644207 522135998 792212062 769575763 362993766 151995980 675746234 841818445 386566521 38015842 646997368 9339094...

output:

249987345442729176785041614983

result:

ok single line: '249987345442729176785041614983'

Test #66:

score: 35
Accepted
time: 339ms
memory: 50280kb

input:

1000000 999998816
417 470 2758 2839 4135 4205 4915 6133 8145 8725 10073 10689 11465 12128 12339 13078 13770 14787 16540 17068 18304 19040 20900 21061 21830 23452 23848 24227 24277 25006 25593 26123 27638 29259 29306 30445 32778 33009 33078 33949 34057 35207 35404 35678 40046 40341 40385 41281 41876 ...

output:

166264506289451755177890517776

result:

ok single line: '166264506289451755177890517776'

Test #67:

score: 35
Accepted
time: 325ms
memory: 51432kb

input:

1000000 999999878
999999778 999999424 999998423 999996489 999996481 999994233 999993116 999992413 999992354 999992242 999991817 999990558 999989169 999986498 999985606 999984919 999981972 999981405 999978888 999976606 999976382 999973088 999972517 999970535 999969174 999968120 999967866 999967471 99...

output:

166263066827599989337265419595

result:

ok single line: '166263066827599989337265419595'

Test #68:

score: 35
Accepted
time: 829ms
memory: 47740kb

input:

1000000 999999429
863895452 749170892 573598436 445647172 723913907 564201756 659849349 261106111 275231016 949648407 810013869 278737437 268417466 748166658 735383086 289325797 125724628 422668660 120417666 166803646 285527892 292339403 268417466 944354968 564201756 621871936 736766508 503815426 34...

output:

249484456778871083277539071298

result:

ok single line: '249484456778871083277539071298'

Test #69:

score: 35
Accepted
time: 466ms
memory: 51600kb

input:

1000000 999997995
225272658 489795078 112671535 489799254 225275729 489800816 56358876 489803069 225276727 489803331 112675067 489803813 225279215 489804732 28318752 225280259 489804758 112675240 489805118 225280728 489807700 56359806 489808383 225281705 489809356 112675656 489810469 225283543 48981...

output:

213573289015571428092557133403

result:

ok single line: '213573289015571428092557133403'

Test #70:

score: 35
Accepted
time: 455ms
memory: 51616kb

input:

1000000 999999013
224629202 488262565 112587348 488263385 224629571 488264497 56159504 488266324 224630842 488266817 112587627 488269036 224631018 488269570 28184656 224631500 488270182 112588209 488270813 224632632 488271659 56159609 488272355 224635685 488272556 112590401 488272681 224635989 48827...

output:

213529295227447185987397689338

result:

ok single line: '213529295227447185987397689338'

Test #71:

score: 35
Accepted
time: 474ms
memory: 54728kb

input:

1000000 999999116
224695053 488920341 112108240 488924850 224695628 488925961 55962794 488926447 224695874 488930208 112108911 488931438 224696120 488931991 27861315 224696833 488933135 112109486 488933324 224697060 488933877 55963446 488937673 224697167 488938513 112109734 488938952 224697423 48893...

output:

213494352150668986443358912310

result:

ok single line: '213494352150668986443358912310'

Test #72:

score: 35
Accepted
time: 443ms
memory: 52272kb

input:

1000000 999999124
718543381 437497317 860028495 437496349 718540461 437496098 929934788 437494542 718539888 437493927 860027426 437492224 718539677 437491828 965001496 718536077 437491428 860026801 437490420 718536071 437485335 929934183 437484050 718535074 437483751 860025900 437482105 718534606 43...

output:

217309184864997501744803192500

result:

ok single line: '217309184864997501744803192500'

Test #73:

score: 35
Accepted
time: 459ms
memory: 51376kb

input:

1000000 999999640
718515896 436562197 859739640 436561583 718514420 436557614 929815657 436554725 718511762 436551952 859737287 436550199 718511739 436548109 964839057 718511000 436547607 859736501 436544637 718508832 436544216 929813689 436542426 718508361 436541559 859734896 436537027 718507106 43...

output:

217330421430066605333304566705

result:

ok single line: '217330421430066605333304566705'

Test #74:

score: 35
Accepted
time: 462ms
memory: 52264kb

input:

1000000 999999486
718919004 438041588 859601263 438041218 718918847 438039621 929917962 438037549 718917101 438037252 859600457 438036104 718916070 438034273 965106616 718914638 438033129 859600231 438028954 718914516 438028699 929917820 438026730 718913245 438025616 859599198 438025080 718910919 43...

output:

217292159530412768413798760842

result:

ok single line: '217292159530412768413798760842'

Test #75:

score: 35
Accepted
time: 1035ms
memory: 48832kb

input:

1000000 999998419
536682209 58873365 718981208 397830949 2176591 963042298 32683858 228708122 77255544 739365892 739822594 213860367 468266278 479342113 774745469 582898815 893394224 16579021 898445055 802779308 461716426 108684634 770872018 348731309 42572413 938258293 165074335 502001614 284764608...

output:

249987427725854743013902455399

result:

ok single line: '249987427725854743013902455399'

Test #76:

score: 35
Accepted
time: 948ms
memory: 48412kb

input:

1000000 999997715
532979357 761797045 534053825 112996227 329436146 595539599 334086885 734326463 797292049 940183874 220614171 719508246 428772471 399444314 88732798 35722319 86473862 226350765 83936729 234131754 160394357 149993118 734438093 79705899 392684949 342594247 212542089 182056033 7884517...

output:

249987085583688519930374354719

result:

ok single line: '249987085583688519930374354719'

Test #77:

score: 35
Accepted
time: 1005ms
memory: 50628kb

input:

1000000 1000000000
209877320 255366597 235160062 194456762 56498955 346275205 282844170 996403743 953601017 111786088 202611637 958796994 224671526 724811234 236927791 26506670 300700585 228049020 730249069 126406069 669851337 962766965 480760570 466825168 66119364 417768247 734201910 66915110 53740...

output:

249988228359489804829661211301

result:

ok single line: '249988228359489804829661211301'

Test #78:

score: 35
Accepted
time: 923ms
memory: 48052kb

input:

1000000 999994460
11240553 999938125 162475362 214289583 252112570 65326251 403379010 15653348 194349912 408536689 769198256 69037989 827798138 848781158 725381381 725652261 524144167 531358336 876865870 157062110 167170848 575138944 99443122 662646016 150800911 37824478 126263772 603770033 77509819...

output:

249985452000381339111277899301

result:

ok single line: '249985452000381339111277899301'

Test #79:

score: 35
Accepted
time: 917ms
memory: 50076kb

input:

1000000 999998688
887455340 464186051 202852143 104143417 397171657 968565190 281192536 831167857 510331866 4119340 996180815 551006510 659306298 144672499 377643623 234694267 399894462 38644516 640606723 321463546 214110605 457753721 339314438 35212715 608466032 820934094 786860901 312229569 624623...

output:

249987576400161954845181002508

result:

ok single line: '249987576400161954845181002508'

Test #80:

score: 35
Accepted
time: 1046ms
memory: 48932kb

input:

1000000 999999718
210655783 605592402 780014781 264933214 796024431 5917982 540842999 558771827 547693304 82998917 347636598 116636333 305680565 193818631 981245574 422544823 914020850 53387737 1677863 539491394 889165136 896019906 588192317 380631714 94122852 78153851 894376731 35264112 155110293 6...

output:

249988076147705987289688156391

result:

ok single line: '249988076147705987289688156391'