QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#767582#4936. Shopping ChangesFireball0424#AC ✓182ms29536kbC++172.5kb2024-11-20 21:19:292024-11-20 21:19:30

Judging History

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

  • [2024-11-20 21:19:30]
  • 评测
  • 测评结果:AC
  • 用时:182ms
  • 内存:29536kb
  • [2024-11-20 21:19:29]
  • 提交

answer

// #pragma GCC optimizer("Ofast")
// #pragma GCC target("avx2")
#include <bits/stdc++.h>
#define int long long 
#define ld long double
#define ull unsigned long long 
#define fr first
#define fi first
#define sc second
#define se second
#define all(x) x.begin(), x.end()
#define pii pair<int,int>
//#define sz(x) (int)x.size()
using namespace std;

#ifndef fireball
#define tofu ios::sync_with_stdio(0); cin.tie(0);
#else
#define tofu freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif 

void db() {cout << '\n';}
template <typename T, typename ...U> void db(T a, U ...b) {cout << a << ' ', db(b...);}

const int N = 3e5 + 5;
int bit[N] = {};
vector<int> undo;

void init(){
    for(int i : undo) bit[i] = 0;
    undo.clear();
}
void add(int pos, int val){
    for(int i = pos; i < N; i += (i & (-i))){
        bit[i] += val;
        undo.push_back(i);
    }
}
int query(int pos){
    int res = 0;
    for(int i = pos; i; i -= (i & (-i))) res += bit[i];
    return res;
}

signed main(){
    tofu;

    int n, m;
    cin >> n >> m;
    vector<int> v, a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        v.push_back(a[i]);
    }
    
    vector<vector<int> > b;
    for(int i = 0; i < m; ++i){
        int l; cin >> l;
        b.push_back(vector<int>(l));
        for(int j = 0; j < l; ++j){
            cin >> b[i][j];
            v.push_back(b[i][j]);
        }
    }

    sort(all(v));
    v.erase(unique(all(v)), v.end());
    
    for(int i = 0; i < n; ++i) a[i] = lower_bound(all(v), a[i]) - v.begin() + 1;
    for(int i = 0; i < m; ++i){
        for(int &j : b[i]) j = lower_bound(all(v), j) - v.begin() + 1;
    }
    
    int fix = 0;
    // in-first
    for(int i = n - 1; i >= 0; --i){
        fix += query(a[i] - 1);
        add(a[i], 1);
    }

    sort(all(a));                 
    // in-second 
    for(int i = 0; i < m; ++i){
        int l = (int)b[i].size();
        init();
        int in = 0, btw = 0;
        for(int j = l - 1; j >= 0; --j){
            in += query(b[i][j] - 1);
            add(b[i][j], 1);

            btw += lower_bound(all(a), b[i][j]) - a.begin();
        }
        //db(in, btw);

        int ans = fix + in + btw;
        for(int j = l - 1; j >= 0; --j){
            btw -= lower_bound(all(a), b[i][j]) - a.begin();
            btw += n - (upper_bound(all(a), b[i][j]) - a.begin());
            ans = min(ans, fix + in + btw);
        }
        db(ans);
    }

}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5928kb

input:

3 3
5 6 7
6 2 3 4 8 9 10
2 100 99
3 5 6 7

output:

0 
1 
1 

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 3560kb

input:

3 2
7 6 5
6 2 3 4 8 9 10
6 10 9 8 4 3 2

output:

3 
27 

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 1ms
memory: 3824kb

input:

1 1
589284012
1 767928734

output:

0 

result:

ok single line: '0 '

Test #4:

score: 0
Accepted
time: 90ms
memory: 9400kb

input:

10000 9999
298772847 712804102 869795012 527998188 804246450 598105371 843966934 639805471 937482040 887551242 254734680 188704975 17408126 626523673 553956319 697723205 231690822 637079761 232393146 377026277 962223856 338922458 912529500 710873344 942955137 51167037 195729799 529674367 990599310 4...

output:

24802338 
24830913 
24857654 
24813132 
24846150 
24785558 
24857315 
24805175 
24862714 
24785339 
24804999 
24780907 
24808009 
24798987 
24958122 
24781372 
24772291 
24846071 
24953540 
24778276 
24778689 
24979527 
24770012 
24892097 
24776909 
24865295 
24821506 
24772586 
24800432 
24891424 
...

result:

ok 9999 lines

Test #5:

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

input:

42320 25000
977178721 305456426 916831455 324594376 259922325 798438534 906876242 353428436 459214642 504133134 734517252 944888626 929971853 735313273 285979369 866298401 385768124 918185862 811827492 3054135 190006456 852394509 784943097 903969029 4089198 931644108 916374905 942243264 383987411 45...

output:

448869835 
448857081 
449001851 
448984953 
448766022 
449088370 
448752999 
448813227 
448791232 
448952235 
448991581 
448762188 
449564834 
448895404 
448773616 
448827147 
448822397 
448871140 
448785180 
448915022 
448786815 
448758118 
448930420 
449164516 
448765912 
448826222 
448791834 
448...

result:

ok 25000 lines

Test #6:

score: 0
Accepted
time: 129ms
memory: 15572kb

input:

50000 50000
478377125 98598664 834663974 414981508 481428682 921148788 327891419 311824685 274571883 326908479 516913707 230013528 47214051 844074075 870004539 261165376 338829696 476144552 905505033 857420851 4709519 198366271 90438077 24208873 865090108 250612383 910141082 205796257 712687049 6996...

output:

626276046 
626281383 
626305127 
626284808 
626194742 
626223647 
626345428 
626232541 
626201578 
626246219 
626205408 
626202408 
626200781 
626281457 
626203632 
626200319 
626196783 
626209587 
626202530 
626221984 
626236632 
626240922 
626221575 
626193667 
626196147 
626357475 
626201484 
626...

result:

ok 50000 lines

Test #7:

score: 0
Accepted
time: 149ms
memory: 22784kb

input:

100000 100000
408955074 826956417 701304685 581625834 949621992 368783244 994452559 15165521 509385486 202776927 176245918 114961790 593275666 396884961 828315109 874631453 542662516 575542309 479957124 380751420 712708199 246976317 507231011 379597065 514719061 64484505 60035132 476324867 388329012...

output:

2494932275 
2494950917 
2495055343 
2495095625 
2494970083 
2494929429 
2494961331 
2494930584 
2494953189 
2494953759 
2494933601 
2494923029 
2494953864 
2494990089 
2494954457 
2494943413 
2494928840 
2494947556 
2494964296 
2494958475 
2494990095 
2494959517 
2494921564 
2494925864 
2495010171 
...

result:

ok 100000 lines

Test #8:

score: 0
Accepted
time: 161ms
memory: 23292kb

input:

99999 100000
600463446 248799387 649864729 273788358 322200216 344039737 562505373 207275943 404254290 846099123 114006949 796949465 130737378 123479822 216726932 519509989 601537036 634922281 871300849 302338370 910662817 86998445 29786621 542318360 619477390 583386020 930091258 234201740 277351034...

output:

2486926452 
2486896186 
2486894414 
2486993043 
2487000342 
2486956897 
2486881813 
2486886322 
2486882361 
2486885243 
2487045570 
2486957654 
2486877874 
2486875105 
2486905255 
2486868528 
2486900862 
2486887524 
2486869232 
2486892803 
2487102103 
2486994953 
2486978968 
2487026409 
2486906487 
...

result:

ok 100000 lines

Test #9:

score: 0
Accepted
time: 182ms
memory: 25044kb

input:

99990 99890
181528078 10459806 239702948 863416907 442860360 89133612 165027754 672621668 226192456 687919502 16701664 419403423 160203548 853988789 258867818 627341337 570883140 3744084 884046739 471496077 388609094 286449445 594086131 113314789 975603728 245711864 846262379 157495698 903007487 649...

output:

2501260106 
2501219924 
2501325056 
2501422142 
2501352630 
2501348093 
2501321550 
2501210401 
2501366266 
2501251160 
2501343895 
2501408582 
2501237542 
2501208856 
2501221609 
2501364415 
2501217017 
2501210560 
2501219517 
2501299320 
2501217079 
2501215015 
2501257508 
2501219120 
2501232627 
...

result:

ok 99890 lines

Test #10:

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

input:

99901 99999
808818250 377330700 906463575 151522566 390356188 145583324 379152244 243783967 401060325 993494764 146062914 348313915 107183249 349586900 940719241 394798213 212797919 136975674 835324527 555101637 220575052 691162851 360455326 822052332 852047152 677589130 687581417 747434371 64521579...

output:

2497942713 
2498009330 
2498172084 
2497932157 
2497975878 
2497931183 
2498004786 
2497975120 
2497949915 
2498019381 
2497975274 
2497972508 
2497970168 
2497941682 
2497933763 
2497965423 
2497958308 
2497936805 
2497944133 
2497974549 
2497975354 
2497973985 
2497974783 
2497967673 
2497946121 
...

result:

ok 99999 lines

Test #11:

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

input:

100000 99990
713956590 839522958 145242968 938176360 388033787 910252476 197085546 32515053 480887927 385712159 334339726 757263131 331067071 712224076 663860268 418563452 735547157 609250006 6864664 64411104 150984904 683541757 667068971 831313096 79839363 690201996 877789177 359618813 539556151 65...

output:

2497561425 
2497627897 
2497483348 
2497549619 
2497492765 
2497454636 
2497499827 
2497474340 
2497480675 
2497542588 
2497551088 
2497497492 
2497491658 
2497706646 
2497475133 
2497483774 
2497466663 
2497490868 
2497499401 
2497467229 
2497523662 
2497527024 
2497549877 
2497478058 
2497522969 
...

result:

ok 99990 lines

Test #12:

score: 0
Accepted
time: 1ms
memory: 3596kb

input:

1 1
248317542
1 181081692

output:

0 

result:

ok single line: '0 '

Test #13:

score: 0
Accepted
time: 1ms
memory: 3892kb

input:

2 1
196235096 759195653
2 366013494 674976236

output:

2 

result:

ok single line: '2 '

Test #14:

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

input:

2 1
906523441 647212241
1 909729626

output:

1 

result:

ok single line: '1 '

Test #15:

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

input:

1 2
363565725
1 369336605
1 632710489

output:

0 
0 

result:

ok 2 lines

Test #16:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

10 5
148782870 215561121 231134410 287688846 475208813 540129254 597334068 708247439 750986572 763456166
2 144293465 271603550
4 328457119 369952611 746795877 848941153
6 34481419 130039916 204924304 344374889 756586236 864262291
3 396985797 932091720 938646507
4 460111039 527118784 723171460 724935...

output:

3 
10 
6 
4 
13 

result:

ok 5 lines

Test #17:

score: 0
Accepted
time: 1ms
memory: 3900kb

input:

5 2
403075608 418584921 556160905 622684870 808124784
3 498323961 651918533 741591816
1 220757201

output:

4 
0 

result:

ok 2 lines

Test #18:

score: 0
Accepted
time: 1ms
memory: 3640kb

input:

100 20
1801697 3287412 16019002 22702014 33686046 35688493 54104663 60203947 64930467 101780420 102563086 123579725 132469567 157160604 176361221 177691323 186499330 190872135 192146197 194726200 213033519 214539640 216662574 220395373 236644158 246606097 251271502 260130059 275817565 286524519 3079...

output:

41 
37 
46 
37 
139 
119 
59 
2 
41 
85 
23 
10 
10 
94 
9 
15 
66 
107 
72 
34 

result:

ok 20 lines

Test #19:

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

input:

1 1
440175539
1 525449075

output:

0 

result:

ok single line: '0 '

Test #20:

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

input:

2 1
553308505 218315040
2 807423387 688595659

output:

2 

result:

ok single line: '2 '

Test #21:

score: 0
Accepted
time: 1ms
memory: 3640kb

input:

1 2
248112012
1 483754601
1 421299831

output:

0 
0 

result:

ok 2 lines

Test #22:

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

input:

10 5
951286059 935545570 923545979 750637337 721366010 626759088 409605692 132998489 55806861 42774749
4 790537375 421524107 273912014 108698941
6 885237556 603431975 581855332 573113021 525738692 205187737
2 89859991 77978743
7 913504104 667919697 631048711 542110617 239755219 210761800 58306247
1 ...

output:

67 
86 
50 
95 
50 

result:

ok 5 lines

Test #23:

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

input:

5 2
788844469 683798016 492024994 411980128 111411750
1 241390711
4 870906702 316423515 92954113 17527444

output:

11 
22 

result:

ok 2 lines

Test #24:

score: 0
Accepted
time: 1ms
memory: 3892kb

input:

100 20
997066724 992718602 990418647 982708996 973347794 970964324 952774795 941780669 936163639 928686704 920417257 905481891 904156911 902061541 897717576 897479441 892002971 882185406 878269129 866398863 863912656 862997257 859524837 857655910 821044998 816269235 807873247 801170156 798073625 769...

output:

5201 
5141 
4951 
5190 
5028 
5006 
4981 
5238 
4954 
4999 
4991 
4989 
4989 
4987 
4997 
5005 
5209 
4986 
4987 
5041 

result:

ok 20 lines

Test #25:

score: 0
Accepted
time: 1ms
memory: 3636kb

input:

1 2
454895875
1 412726717
1 469855690

output:

0 
0 

result:

ok 2 lines

Test #26:

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

input:

2 2
744773615 657129865
30177 999925482 999853650 999815120 999812464 999795500 999794786 999778724 999769575 999764484 999763358 999747142 999733608 999672181 999666484 999590809 999582230 999539349 999478051 999430532 999401821 999334058 999317416 999271687 999132366 999069801 999016387 998970365 ...

output:

455328682 
266945669 

result:

ok 2 lines

Test #27:

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

input:

100000 1000
999992622 999967226 999957759 999949971 999947843 999940723 999938467 999926688 999911916 999909942 999908758 999906021 999900282 999873879 999868978 999857100 999855421 999834251 999833103 999829430 999823466 999821915 999814111 999807670 999797324 999793830 999793413 999784976 99978390...

output:

5004001968 
5005515185 
5014455444 
5006347829 
5003612267 
5017110634 
5004106513 
4999985325 
5006272426 
5003762172 
5002534713 
5010004011 
5010762472 
5005845372 
5009008354 
5010681926 
5001315264 
5002231972 
5020012924 
5006535090 
5001303943 
5001161411 
5004565781 
5001450033 
5001860444 
...

result:

ok 1000 lines

Test #28:

score: 0
Accepted
time: 149ms
memory: 19904kb

input:

100000 10000
999996091 999980448 999974694 999970400 999968278 999959991 999947417 999928343 999899914 999890435 999865462 999822401 999805064 999801955 999796484 999761858 999743462 999740904 999739622 999727799 999708821 999700030 999678199 999674166 999652791 999650303 999648520 999635126 9996250...

output:

5000230988 
5000429248 
5000131198 
5001242270 
5001548536 
5000099210 
5001506852 
4999984707 
5000278698 
5000530686 
5000812266 
5002277401 
5001108597 
4999972208 
5000484835 
4999984516 
5000477674 
5000055898 
5001194520 
5000135342 
5001284598 
5000983174 
5000998423 
5000080217 
5000490532 
...

result:

ok 10000 lines

Test #29:

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

input:

100000 50000
999996882 999996762 999977797 999977757 999970056 999950570 999946769 999943088 999931045 999919043 999908615 999904280 999900530 999898746 999895745 999895596 999875314 999867667 999857794 999855554 999844569 999843414 999832729 999819009 999802769 999797198 999787114 999775838 9997562...

output:

5000116287 
4999980884 
5000074522 
5000085600 
4999975879 
5000614055 
5000071577 
5000105709 
4999952115 
5000018881 
5000089815 
4999984041 
4999978618 
5000296092 
4999977800 
5000177792 
5000258427 
4999950778 
5000138474 
5000270419 
4999995939 
5000047203 
5000161175 
5000048198 
5000172601 
...

result:

ok 50000 lines

Test #30:

score: 0
Accepted
time: 155ms
memory: 19876kb

input:

100000 1000
999980095 999978410 999972318 999948058 999939785 999927697 999927658 999916673 999897886 999894579 999873409 999873334 999871631 999869454 999864288 999848834 999833536 999832727 999825736 999806314 999795055 999781552 999779999 999772239 999753160 999751723 999749898 999728367 99972145...

output:

5009600979 
5009922556 
5009402273 
5009853801 
5009715320 
5009682565 
5009545567 
5009896744 
5009743602 
5009945844 
5009557136 
5009209028 
5009826234 
5009957882 
5009268244 
5009262146 
5009304373 
5009929900 
5009347848 
5009224725 
5009891191 
5009796056 
5009825839 
5009722290 
5009549903 
...

result:

ok 1000 lines

Test #31:

score: 0
Accepted
time: 148ms
memory: 20020kb

input:

100000 10000
999978562 999972321 999971197 999941492 999921861 999890471 999890038 999870229 999846959 999838429 999829900 999829289 999821269 999798584 999759849 999758052 999736385 999734798 999722883 999717277 999710007 999701403 999701120 999690738 999673194 999660137 999649103 999639615 9996303...

output:

5000866563 
5000765254 
5000869909 
5000743238 
5000854942 
5000691134 
5000918153 
5000787101 
5000887505 
5000922116 
5000886495 
5000686243 
5000895708 
5000870832 
5000863718 
5000810412 
5000792913 
5000879193 
5000814326 
5000741308 
5000919323 
5000896130 
5000885760 
5000748549 
5000933909 
...

result:

ok 10000 lines

Test #32:

score: 0
Accepted
time: 163ms
memory: 19444kb

input:

100000 20000
999999477 999990558 999990326 999982083 999971945 999960562 999952102 999949481 999946302 999944762 999941592 999935545 999930444 999929854 999901965 999899725 999894968 999881179 999877137 999850349 999849572 999847243 999816279 999800885 999800812 999793057 999765795 999750735 9997351...

output:

5000410897 
5000300173 
5000281780 
5000263955 
5000302929 
5000276854 
5000429635 
5000447125 
5000395903 
5000320111 
5000431446 
5000378231 
5000305970 
5000303944 
5000360953 
5000385920 
5000426895 
5000390349 
5000312475 
5000376838 
5000420521 
5000421302 
5000403079 
5000387467 
5000276984 
...

result:

ok 20000 lines

Test #33:

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

input:

100000 50000
999996362 999989589 999960676 999941238 999938459 999930375 999929805 999929759 999926622 999925596 999918647 999911843 999908271 999891042 999877663 999875184 999874053 999873073 999871292 999853678 999849966 999839833 999828319 999799656 999791118 999783584 999762099 999753364 9997276...

output:

5000147657 
5000120490 
5000055480 
5000126407 
5000066931 
5000138011 
5000099943 
5000147448 
5000086178 
5000143146 
5000114758 
5000068504 
5000143979 
5000141684 
5000129123 
5000101529 
5000084395 
5000076098 
5000147216 
5000066720 
5000065128 
5000131040 
5000138436 
5000118563 
5000096576 
...

result:

ok 50000 lines

Test #34:

score: 0
Accepted
time: 154ms
memory: 23748kb

input:

100000 100000
999993430 999986704 999973854 999970819 999950357 999947656 999947102 999937334 999920741 999918890 999900630 999886692 999883282 999844967 999844631 999838793 999837951 999818358 999804144 999800794 999792846 999791552 999785287 999755216 999751595 999749875 999737020 999735280 999722...

output:

5000179323 
4999966695 
4999989092 
4999960014 
4999980937 
5000028261 
4999952751 
4999986188 
4999979525 
4999977269 
4999974565 
5000055118 
5000031411 
4999978077 
5000009442 
4999973460 
4999996538 
4999972625 
5000016025 
4999993345 
5000087495 
5000078296 
4999957861 
4999979386 
5000028389 
...

result:

ok 100000 lines

Test #35:

score: 0
Accepted
time: 164ms
memory: 25228kb

input:

99999 100000
999993706 999992117 999969443 999961685 999960814 999958217 999956534 999955231 999952734 999949221 999905672 999902350 999896128 999895091 999893554 999870605 999868117 999867817 999857976 999853300 999849139 999818154 999804540 999797841 999797777 999793496 999787352 999763502 9997178...

output:

4999883275 
4999874951 
4999866014 
4999918877 
4999929388 
4999996392 
4999873457 
4999866983 
4999850226 
4999934349 
4999900474 
4999867106 
4999853681 
4999890236 
4999872925 
4999987774 
4999942644 
4999874982 
5000348748 
5000037461 
4999979739 
4999860833 
4999887744 
4999871853 
5000084782 
...

result:

ok 100000 lines

Test #36:

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

input:

10 5
319475350 957533970 60895095 292762468 411717199 512889009 850108282 872059530 567896598 515371564
1 835539456
1 150700500
4 934168428 934249073 508532761 858089975
3 859971373 495509693 558858440
1 838086821

output:

18 
16 
29 
29 
18 

result:

ok 5 lines

Test #37:

score: 0
Accepted
time: 149ms
memory: 24028kb

input:

99990 99890
999982518 999973188 999971350 999961764 999960979 999960263 999952685 999928427 999890498 999890247 999890191 999859532 999848545 999847487 999842299 999834498 999818887 999807986 999807591 999801783 999792062 999757959 999756255 999741531 999740489 999733925 999717806 999688473 99968559...

output:

4999035417 
4998956256 
4998980112 
4999034506 
4998997399 
4999194768 
4999029477 
4999027685 
4998999318 
4998966063 
4998978172 
4998959198 
4998992605 
4998950878 
4999132122 
4999007053 
4999056860 
4999033796 
4999098812 
4998977891 
4998976800 
4998978007 
4999522266 
4998982890 
4998972481 
...

result:

ok 99890 lines

Test #38:

score: 0
Accepted
time: 166ms
memory: 22360kb

input:

99901 99999
999980670 999976501 999936136 999913938 999911313 999910135 999903625 999896960 999894261 999886395 999879911 999878904 999855747 999852864 999838189 999835750 999831790 999830441 999817956 999800469 999797936 999787104 999786654 999781004 999762461 999743754 999733511 999726216 99967848...

output:

4990164091 
4990066223 
4990174290 
4990185369 
4990079851 
4990129329 
4990089143 
4990094601 
4990292794 
4990145697 
4990104475 
4990059684 
4990143951 
4990088010 
4990077324 
4990072450 
4990078467 
4990089836 
4990060693 
4990238810 
4990171548 
4990059866 
4990334661 
4990082414 
4990083370 
...

result:

ok 99999 lines

Test #39:

score: 0
Accepted
time: 167ms
memory: 24164kb

input:

100000 99990
999990761 999985404 999983859 999975065 999970973 999936671 999932850 999920302 999911717 999906025 999897025 999896361 999890930 999890725 999860993 999847811 999809154 999794869 999791118 999772840 999765658 999758729 999757572 999750513 999741805 999713589 999705383 999701876 9996824...

output:

4999964690 
4999953218 
4999979593 
4999985449 
4999968884 
5000084842 
5000074404 
4999990323 
4999989505 
4999981103 
4999987423 
5000008184 
4999978666 
4999993683 
5000161948 
5000005903 
4999993977 
4999965430 
5000098763 
4999981044 
4999995691 
4999968361 
5000199752 
4999998662 
4999993556 
...

result:

ok 99990 lines

Test #40:

score: 0
Accepted
time: 124ms
memory: 20996kb

input:

100000 1000
999994614 999980556 999970894 999966419 999954040 999947343 999937457 999937301 999934425 999932367 999927515 999924750 999920404 999916567 999900259 999876373 999866895 999838101 999833067 999830497 999829240 999816352 999812855 999810457 999797088 999783896 999779969 999779023 99977549...

output:

5000532041 
4999981289 
5003479124 
5017644585 
5007834663 
5010495847 
5000087266 
5013467764 
5009205410 
5013941489 
5001123238 
5011519803 
5000028137 
5006295729 
5021728782 
5003248125 
5004413973 
5003493474 
5013076885 
5004949756 
5004389576 
5010002662 
5032122634 
5014359201 
5001479555 
...

result:

ok 1000 lines

Test #41:

score: 0
Accepted
time: 147ms
memory: 20132kb

input:

100000 10000
999990152 999950203 999939239 999934274 999931041 999896767 999882493 999881188 999873658 999863191 999857755 999843065 999832829 999831763 999829884 999816740 999801943 999800556 999770739 999755437 999742537 999708231 999701161 999676083 999637043 999631237 999629601 999622705 9996171...

output:

5000749547 
5000376982 
5001777251 
5001702053 
5001382208 
5000094455 
5000371354 
5001595268 
5000493222 
5000365863 
5001567034 
5000788269 
5001633620 
5002417904 
5000297269 
5000882702 
5000024563 
5000012342 
4999993759 
4999970552 
5000282347 
5000174592 
5000129792 
5000002768 
5000009588 
...

result:

ok 10000 lines

Test #42:

score: 0
Accepted
time: 158ms
memory: 20376kb

input:

100000 50000
999991219 999979969 999973217 999967000 999963709 999943929 999941109 999911398 999909455 999894601 999890251 999883168 999882422 999878378 999855099 999852152 999846327 999845762 999844474 999844310 999831777 999823673 999810868 999807307 999798673 999798154 999777250 999762126 9997612...

output:

4999959203 
5000018296 
5000217438 
5000044929 
5000605320 
5000036768 
5000156459 
4999978700 
5000033998 
5000118894 
5000117723 
5000071788 
5000113178 
4999960292 
5000206587 
4999989112 
5000286517 
5000015291 
4999979893 
5000246771 
4999969808 
5000039413 
5000464251 
5000072628 
5000130255 
...

result:

ok 50000 lines

Test #43:

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

input:

100000 1000
999990080 999978417 999969429 999949046 999947944 999943475 999940521 999929201 999922209 999921600 999890374 999889502 999859132 999846220 999839708 999839116 999833889 999832632 999828234 999825825 999813946 999811990 999805632 999782793 999781832 999779636 999775277 999770157 99975003...

output:

5009470071 
5009168717 
5009816216 
5009197775 
5009169737 
5009256608 
5009397233 
5009319329 
5009421016 
5009489656 
5009201558 
5009250227 
5008927293 
5009222568 
5009605042 
5008960600 
5009336631 
5009433804 
5009303746 
5009519365 
5009494829 
5009551354 
5009187768 
5009540957 
5008985884 
...

result:

ok 1000 lines

Test #44:

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

input:

100000 10000
999981037 999977843 999975120 999965188 999962223 999961348 999942401 999929778 999928059 999919888 999919036 999911500 999901021 999893571 999883306 999851853 999825647 999822839 999806447 999804276 999788407 999779317 999770163 999764824 999753075 999738544 999725954 999724448 9997172...

output:

5000796680 
5000708279 
5000804399 
5000727434 
5000770074 
5000756440 
5000777685 
5000739921 
5000836486 
5000724427 
5000892250 
5000886372 
5000738387 
5000758425 
5000827430 
5000702020 
5000721991 
5000845806 
5000739138 
5000668646 
5000869475 
5000793138 
5000894119 
5000758234 
5000790792 
...

result:

ok 10000 lines

Test #45:

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

input:

100000 20000
999997459 999995751 999993694 999991540 999962968 999952303 999927539 999923040 999922505 999918757 999911243 999900281 999894765 999893512 999892995 999855333 999851474 999840646 999831602 999809720 999802750 999801609 999765637 999744952 999743467 999730159 999724647 999719104 9997107...

output:

5000401933 
5000268627 
5000223732 
5000223663 
5000330655 
5000367309 
5000323773 
5000263146 
5000330145 
5000336315 
5000329694 
5000250642 
5000371229 
5000236847 
5000384260 
5000285788 
5000259785 
5000295572 
5000379372 
5000369939 
5000442335 
5000378313 
5000282114 
5000341511 
5000349551 
...

result:

ok 20000 lines

Test #46:

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

input:

100000 50000
999980686 999965350 999953982 999944207 999930470 999923228 999912062 999911112 999897561 999895323 999887902 999880305 999878552 999877876 999863726 999853152 999848164 999845381 999834807 999819234 999806336 999805043 999800024 999800012 999770723 999758936 999737782 999707086 9997028...

output:

5000086860 
5000107517 
5000128574 
5000120621 
5000094772 
5000097900 
5000117054 
5000026887 
5000092091 
5000110753 
5000069433 
5000053259 
5000089298 
5000099267 
5000086375 
5000031012 
5000128775 
5000089806 
5000017360 
5000080093 
5000130192 
5000118630 
5000057884 
5000109938 
5000068713 
...

result:

ok 50000 lines

Test #47:

score: 0
Accepted
time: 1ms
memory: 3672kb

input:

5 2
728941349 126996196 773773418 687109961 624938993
1 814557321
1 560330376

output:

6 
7 

result:

ok 2 lines

Test #48:

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

input:

100000 100000
999986940 999980713 999976237 999966656 999966295 999964472 999956520 999950889 999944790 999903817 999890943 999880483 999876869 999862326 999838436 999825547 999814206 999811949 999810332 999799219 999765900 999762250 999744926 999732950 999717545 999717476 999707899 999692860 999690...

output:

5000046244 
4999954984 
4999997761 
5000131413 
5000030825 
5000134827 
4999964224 
4999975981 
5000049639 
4999990285 
4999960832 
5000014960 
5000089191 
4999970114 
5000072902 
4999975308 
5000060306 
4999975348 
5000009849 
4999991277 
4999961752 
4999972903 
5000023181 
4999999234 
4999972686 
...

result:

ok 100000 lines

Test #49:

score: 0
Accepted
time: 149ms
memory: 22556kb

input:

99999 100000
999991144 999973518 999970640 999961029 999960067 999959662 999957160 999936283 999924912 999917119 999912960 999910307 999909337 999906525 999905831 999878987 999871221 999860408 999855792 999853826 999851239 999845127 999832814 999830417 999823691 999812897 999811049 999809644 9997858...

output:

4999851369 
4999915641 
4999930021 
4999992980 
4999916432 
4999976494 
4999861135 
4999876955 
4999938646 
4999929785 
4999907231 
5000020272 
4999861309 
4999878586 
4999938716 
4999930876 
4999880472 
4999862440 
4999884466 
4999881338 
4999893718 
4999905157 
4999951489 
4999901329 
4999900732 
...

result:

ok 100000 lines

Test #50:

score: 0
Accepted
time: 145ms
memory: 22888kb

input:

99990 99890
999993843 999924602 999922396 999910118 999909602 999889447 999888909 999851358 999834786 999807549 999803771 999800972 999780420 999753932 999747570 999724673 999713796 999700932 999689623 999677484 999663090 999658634 999654874 999640646 999639726 999633124 999629621 999621804 99961700...

output:

4999023177 
4998995073 
4999029703 
4998970230 
4998954643 
4998953999 
4999040407 
4998989597 
4998967660 
4999036187 
4999046880 
4998976662 
4999181971 
4998982825 
4998997978 
4998962255 
4999075311 
4999024595 
4999091644 
4998994381 
4999127633 
4999087702 
4999049216 
4998978269 
4999069364 
...

result:

ok 99890 lines

Test #51:

score: 0
Accepted
time: 155ms
memory: 24952kb

input:

99901 99999
999997307 999994163 999954304 999953740 999950698 999945729 999936493 999931210 999929208 999907691 999907050 999905881 999883776 999877479 999852459 999851753 999827231 999806815 999804715 999793626 999793289 999790054 999775050 999768649 999748922 999738208 999721435 999713986 99969774...

output:

4990134660 
4990090624 
4990085883 
4990124907 
4990101335 
4990092935 
4990128015 
4990082178 
4990074025 
4990084886 
4990070440 
4990087947 
4990064359 
4990086612 
4990081614 
4990076191 
4990108969 
4990160184 
4990080241 
4990102182 
4990070253 
4990085975 
4990107548 
4990108585 
4990072313 
...

result:

ok 99999 lines

Test #52:

score: 0
Accepted
time: 146ms
memory: 23140kb

input:

100000 99990
999934233 999916397 999913760 999884786 999850676 999826877 999818517 999811375 999792281 999790517 999773964 999771535 999765740 999764468 999725917 999713639 999700396 999685945 999685937 999680954 999660534 999660490 999653903 999652141 999640926 999633562 999580773 999561160 9995552...

output:

4999970225 
4999957017 
4999966826 
4999991534 
5000142872 
4999973738 
5000073795 
5000005354 
4999971125 
4999960708 
4999992596 
5000107183 
4999997798 
5000034249 
4999997625 
5000002655 
5000055542 
5000041688 
4999994778 
4999950245 
4999961170 
4999971001 
5000044478 
4999988337 
5000038348 
...

result:

ok 99990 lines

Test #53:

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

input:

1 100000
437319875
3 601483245 495061771 442359253
1 59125653
1 118970392
1 777023401
1 504894943
1 671180839
1 50190406
2 776282732 136315499
1 720099141
4 32406295 725276611 411803667 806144946
2 696790761 38680862
1 59613608
1 842670606
1 538266177
3 64109177 26086483 63116278
1 626865841
1 42806...

output:

3 
0 
0 
0 
0 
0 
0 
2 
0 
2 
2 
0 
0 
0 
2 
0 
0 
0 
0 
0 
0 
0 
0 
0 
0 
0 
0 
4 
0 
0 
0 
0 
0 
0 
0 
0 
0 
3 
0 
0 
0 
0 
0 
0 
0 
0 
0 
0 
0 
0 
0 
0 
0 
0 
0 
0 
0 
0 
1 
0 
0 
0 
0 
0 
0 
2 
0 
0 
0 
3 
0 
0 
0 
2 
0 
0 
1 
0 
0 
0 
0 
2 
0 
0 
0 
0 
0 
0 
1 
4 
0 
0 
1 
1 
0 
0 
0 
2 
0 
0 
...

result:

ok 100000 lines

Test #54:

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

input:

1 1
1
1 1

output:

0 

result:

ok single line: '0 '

Test #55:

score: 0
Accepted
time: 160ms
memory: 29096kb

input:

100000 1
835117501 4089906 509558573 547960269 724731223 967787161 618013445 81395673 329377372 815511635 717817575 647833835 798051303 941387837 921518118 680535546 573840459 298132741 493031345 17910591 74355142 677685973 185690529 40037370 602135152 258313109 550659540 909925624 669689132 8069126...

output:

22501815991 

result:

ok single line: '22501815991 '

Test #56:

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

input:

100000 1
42224 45565 46894 70957 75405 82751 84761 95843 96886 108040 108938 109592 134281 134385 134814 148239 154191 159542 159836 176520 177530 225507 236924 262848 263775 267140 308650 309559 313701 336610 338919 353632 376065 406386 414377 416962 431798 437753 441029 443487 450352 451906 456092...

output:

19970322943 

result:

ok single line: '19970322943 '

Test #57:

score: 0
Accepted
time: 146ms
memory: 29536kb

input:

100000 1
999994047 999982330 999973921 999943013 999936631 999934925 999933933 999920311 999900431 999890765 999889422 999883494 999878031 999861913 999858115 999842287 999813022 999802211 999795915 999794441 999783618 999774910 999754536 999731118 999730873 999713533 999705460 999682471 999677606 9...

output:

24944517170 

result:

ok single line: '24944517170 '

Test #58:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

100 20
113717427 445239870 508524582 284064425 200072832 831327091 791259869 489787694 232519176 610351305 145189409 20175393 348043754 663181070 160712162 657232778 238715771 662427838 414989381 969157730 732098971 483130123 386018671 658271880 469259487 968889409 749075793 106601466 64666603 71593...

output:

2506 
2834 
2486 
2837 
2505 
2596 
2511 
2568 
2520 
2570 
3660 
2504 
3332 
2708 
2913 
2482 
2487 
2697 
2768 
2560 

result:

ok 20 lines

Test #59:

score: 0
Accepted
time: 107ms
memory: 26924kb

input:

100000 1
999995984 999989864 999978261 999973424 999954731 999951274 999950341 999942644 999931658 999919901 999919792 999906041 999900616 999889549 999886688 999867217 999858304 999825094 999819866 999819493 999805975 999803836 999777201 999766287 999759254 999731041 999718151 999713574 999698422 9...

output:

17942236870 

result:

ok single line: '17942236870 '

Test #60:

score: 0
Accepted
time: 82ms
memory: 25932kb

input:

99999 1
999999803 999986384 999986020 999984429 999969534 999949862 999941999 999933900 999931930 999927299 999926834 999915928 999915308 999915109 999898307 999880905 999872571 999862862 999859712 999858293 999855766 999853713 999840238 999836861 999826672 999814364 999811851 999798331 999784226 99...

output:

14035968268 

result:

ok single line: '14035968268 '

Test #61:

score: 0
Accepted
time: 86ms
memory: 17568kb

input:

99990 2
999988540 999984430 999982134 999978823 999971881 999969395 999964292 999962292 999956210 999955665 999950278 999932930 999916238 999915938 999913101 999911095 999908982 999900059 999894882 999891602 999880011 999858559 999847474 999844067 999840512 999834311 999831748 999819875 999819532 99...

output:

8424841262 
7253186871 

result:

ok 2 lines

Test #62:

score: 0
Accepted
time: 53ms
memory: 24204kb

input:

99901 1
999979415 999968041 999945001 999936103 999932803 999930392 999925056 999922833 999919194 999903610 999890696 999889076 999880949 999858029 999837964 999824250 999815106 999795395 999783746 999781596 999780330 999775698 999770169 999766180 999760954 999749731 999742240 999730281 999721212 99...

output:

7895797959 

result:

ok single line: '7895797959 '

Test #63:

score: 0
Accepted
time: 101ms
memory: 19184kb

input:

100000 10
999987883 999973628 999967833 999949821 999941995 999939526 999937208 999933728 999933469 999926259 999925793 999919708 999918204 999912125 999880508 999879380 999871799 999860192 999859820 999853053 999839707 999830021 999828120 999823963 999818083 999808814 999806819 999779043 999772109 ...

output:

5023952786 
5078541201 
6030729204 
6015872394 
6010553443 
8732860864 
6629752158 
5318778631 
5087382021 
5634689872 

result:

ok 10 lines

Test #64:

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

input:

100000 1
100001 100002 100003 100004 100005 100006 100007 100008 100009 100010 100011 100012 100013 100014 100015 100016 100017 100018 100019 100020 100021 100022 100023 100024 100025 100026 100027 100028 100029 100030 100031 100032 100033 100034 100035 100036 100037 100038 100039 100040 100041 1000...

output:

0 

result:

ok single line: '0 '

Test #65:

score: 0
Accepted
time: 57ms
memory: 27784kb

input:

100000 1
200000 199999 199998 199997 199996 199995 199994 199993 199992 199991 199990 199989 199988 199987 199986 199985 199984 199983 199982 199981 199980 199979 199978 199977 199976 199975 199974 199973 199972 199971 199970 199969 199968 199967 199966 199965 199964 199963 199962 199961 199960 1999...

output:

34999850000 

result:

ok single line: '34999850000 '

Test #66:

score: 0
Accepted
time: 75ms
memory: 19188kb

input:

100000 2
300000 299999 299998 299997 299996 299995 299994 299993 299992 299991 299990 299989 299988 299987 299986 299985 299984 299983 299982 299981 299980 299979 299978 299977 299976 299975 299974 299973 299972 299971 299970 299969 299968 299967 299966 299965 299964 299963 299962 299961 299960 2999...

output:

14999900000 
14999900000 

result:

ok 2 lines

Test #67:

score: 0
Accepted
time: 86ms
memory: 8168kb

input:

1000 1000
727010807 576147539 651809672 962793467 767399989 504118767 232891361 489641974 711974800 973259013 282740251 147339306 22173848 246122375 814302878 946595120 343615793 971118925 411741219 693405935 631700695 348625688 892331487 558035644 675364118 59433 937001509 334857363 293713522 45682...

output:

433713 
255669 
363156 
385303 
312688 
297205 
260122 
322488 
344091 
312835 
254376 
258451 
261099 
265100 
264872 
364342 
283758 
345543 
266744 
264616 
455414 
316863 
807120 
452719 
345543 
288204 
267953 
472792 
337443 
284251 
281748 
380589 
474393 
883719 
323213 
434646 
405617 
2626...

result:

ok 1000 lines

Test #68:

score: 0
Accepted
time: 36ms
memory: 5976kb

input:

2000 2000
62389602 188728880 919764640 808400808 754846251 726227520 837630754 348182223 730672177 566741054 790804793 18248165 779680059 49056791 886791787 106038143 433515952 112461923 4110046 571692216 83976888 825634037 214740724 998984224 505938965 837443209 306640021 63408506 135923845 8062605...

output:

1040068 
1068948 
1078610 
1091617 
1039665 
1044792 
1048084 
1020172 
1034738 
1082591 
1046189 
1039054 
1281927 
1035831 
1035850 
1024287 
1050038 
1074780 
1036010 
1024049 
1093994 
1084417 
1124691 
1058822 
1029581 
1030603 
1045604 
1035559 
1025153 
1025998 
1032211 
1134755 
1027152 
105...

result:

ok 2000 lines

Test #69:

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

input:

9999 1234
374456064 124095832 307475642 670249960 694923714 34573847 76804405 81255253 202245813 220687929 822188156 684185037 837947211 296994394 106059598 608955040 833157106 880755960 38897255 466339827 298250315 634895149 796569775 60743552 880145211 762522506 90533142 773885301 632293983 414133...

output:

24903167 
24899501 
24903256 
24902920 
24910444 
24912950 
24899443 
24903503 
24911729 
24902159 
24901847 
24903047 
24905512 
24902040 
24901238 
24901843 
24899996 
24901082 
24904284 
24899743 
24904876 
24900670 
24902832 
24934947 
24902506 
24935520 
24914177 
24906661 
24907064 
24899094 
...

result:

ok 1234 lines