QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#88853#5002. Distance and TreeSorahISAAC ✓92ms145668kbC++201.9kb2023-03-17 19:41:172023-03-17 19:41:18

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-17 19:41:18]
  • 评测
  • 测评结果:AC
  • 用时:92ms
  • 内存:145668kb
  • [2023-03-17 19:41:17]
  • 提交

answer

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

using pii = pair<int, int>;

#define ALL(x) begin(x), end(x)
#define SZ(x) ((int)(x).size())
#define eb emplace_back
#define ee emplace

const int INF = INT_MAX;
const int maxn = 1E5 + 5;


vector<int> dep;
deque<int> depth[2 * maxn];
vector<pii> edges;

bool exit_flag = false;

void WA() {
    if (!exit_flag) cout << -1 << "\n";
    exit_flag = true;
}

void recur(int l, int r, int d) {
    // cerr << l << " " << r << " " << d << "\n";
    if (d >= 100004) return WA();
    if (r == l + 1) return;
    if (SZ(depth[d])) recur(l, min(depth[d][0], r), d + 1);
    if (exit_flag) return;
    
    while (SZ(depth[d]) and depth[d][0] <= r) {
        if (dep[l] == d - 1) edges.eb(depth[d][0], l);
        else if (dep[r] == d - 1) edges.eb(depth[d][0], r);
        else return WA();
        
        if (SZ(depth[d]) > 1) recur(depth[d][0], min(depth[d][1], r), d + 1);
        else                  recur(depth[d][0], r, d + 1);
        depth[d].pop_front();
        if (exit_flag) return;
    }
}

void solve() {
    int N; cin >> N;
    
    dep.resize(2 * N);
    
    for (int i = 0; i < N; ++i) {
        cin >> dep[i], dep[i+N] = dep[i];
        depth[dep[i]].eb(i);
    }
    if (SZ(depth[0]) != 1) return WA();
    
    int root = depth[0][0];
    for (int i = 0; i < N; ++i) {
        for (int &x : depth[i]) x = (x < root ? x + N : x);
        sort(ALL(depth[i]));
    }
    
    recur(root, root + N, 1);
    
    if (SZ(edges) != N-1) return WA();
    
    for (auto [u, v] : edges) {
        if (u >= N) u -= N;
        if (v >= N) v -= N;
        cout << u + 1 << " " << v + 1 << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
    
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 48ms
memory: 137692kb

input:

5
0 1 2 1 3

output:

-1

result:

ok Accepted

Test #2:

score: 0
Accepted
time: 35ms
memory: 137808kb

input:

5
1 1 0 1 1

output:

4 3
5 3
1 3
2 3

result:

ok Accepted

Test #3:

score: 0
Accepted
time: 80ms
memory: 145592kb

input:

100000
96770 96764 96762 96761 96759 96755 96754 96753 96752 96751 96750 96748 96746 96745 96741 96740 96739 96736 96735 96734 96730 96728 96727 96726 96723 96718 96714 96712 96710 96709 96706 96705 96704 96703 96702 96698 96697 96696 96695 96693 96692 96690 96687 96684 96683 96682 96681 96679 96677...

output:

48446 48444
48447 48439
48448 48435
48449 48448
48450 48434
48451 48431
48452 48430
48453 48452
48454 48429
48455 48454
48456 48428
48457 48456
48458 48457
48459 48426
48460 48459
48461 48425
48462 48424
48463 48462
48464 48463
48465 48422
48466 48419
48467 48466
48468 48467
48469 48414
48470 48412
...

result:

ok Accepted

Test #4:

score: 0
Accepted
time: 87ms
memory: 145668kb

input:

100000
36370 36368 36365 36364 36362 36360 36356 36355 36354 36351 36349 36348 36336 36332 36331 36329 36327 36326 36325 36324 36321 36318 36317 36315 36314 36310 36308 36305 36304 36303 36299 36297 36295 36294 36291 36290 36289 36286 36284 36283 36280 36279 36276 36275 36273 36271 36269 36268 36267...

output:

18267 18255
18268 18267
18269 18268
18270 18269
18271 18254
18272 18253
18273 18251
18274 18249
18275 18274
18276 18248
18277 18276
18278 18247
18279 18278
18280 18279
18281 18244
18282 18241
18283 18282
18284 18240
18285 18284
18286 18238
18287 18286
18288 18235
18289 18288
18290 18234
18291 18290
...

result:

ok Accepted

Test #5:

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

input:

100000
62834 62837 62839 62841 62844 62845 62849 62850 62852 62853 62854 62855 62857 62859 62863 62866 62867 62871 62873 62875 62876 62877 62880 62882 62885 62887 62888 62889 62890 62892 62894 62897 62898 62899 62905 62909 62910 62913 62914 62915 62916 62917 62918 62919 62920 62921 62922 62923 62925...

output:

68601 68598
68602 68601
68603 68597
68604 68603
68605 68596
68606 68595
68607 68606
68608 68607
68609 68594
68610 68609
68611 68592
68612 68589
68613 68586
68614 68613
68615 68614
68616 68584
68617 68616
68618 68583
68619 68618
68620 68582
68621 68576
68622 68575
68623 68622
68624 68623
68625 68624
...

result:

ok Accepted

Test #6:

score: 0
Accepted
time: 83ms
memory: 145592kb

input:

100000
57363 57369 57371 57372 57373 57375 57376 57378 57380 57383 57385 57389 57390 57394 57395 57396 57399 57401 57402 57403 57406 57409 57410 57412 57422 57423 57425 57426 57429 57432 57433 57438 57439 57441 57444 57448 57449 57450 57455 57458 57462 57463 57468 57469 57472 57475 57476 57477 57478...

output:

71452 71451
71453 71452
71454 71447
71455 71454
71456 71446
71457 71445
71458 71443
71459 71441
71460 71440
71461 71439
71462 71461
71463 71438
71464 71463
71465 71437
71466 71435
71467 71433
71468 71467
71469 71468
71470 71430
71471 71429
71472 71471
71473 71427
71474 71473
71475 71474
71476 71425
...

result:

ok Accepted

Test #7:

score: 0
Accepted
time: 92ms
memory: 145556kb

input:

100000
55980 55983 55985 55987 55988 55991 55992 55993 55994 55995 55996 55997 55999 56005 56008 56009 56011 56014 56015 56017 56018 56028 56029 56033 56035 56037 56038 56040 56044 56050 56051 56055 56058 56062 56064 56070 56074 56076 56079 56082 56083 56085 56086 56087 56089 56091 56092 56095 56099...

output:

71914 71911
71915 71910
71916 71909
71917 71908
71918 71917
71919 71906
71920 71900
71921 71896
71922 71894
71923 71893
71924 71892
71925 71889
71926 71925
71927 71926
71928 71888
71929 71928
71930 71929
71931 71887
71932 71883
71933 71932
71934 71880
71935 71934
71936 71879
71937 71878
71938 71877
...

result:

ok Accepted

Test #8:

score: 0
Accepted
time: 29ms
memory: 137840kb

input:

1000
582 580 578 575 574 570 569 559 558 557 555 553 551 550 549 548 546 544 543 542 541 534 531 529 528 525 524 523 521 520 519 517 514 502 500 498 496 495 494 493 491 490 486 484 483 477 474 473 472 471 470 469 468 466 465 464 461 459 458 453 449 448 445 444 440 439 438 436 435 434 433 432 428 425...

output:

298 297
299 296
300 289
301 288
302 287
303 302
304 286
305 304
306 305
307 284
308 307
309 308
310 283
311 310
312 280
313 312
314 276
315 275
316 271
317 316
318 317
319 270
320 319
321 264
322 321
323 322
324 323
325 262
326 325
327 326
328 258
329 257
330 255
331 330
332 254
333 252
334 251
335 ...

result:

ok Accepted

Test #9:

score: 0
Accepted
time: 42ms
memory: 137772kb

input:

1000
921 922 927 928 931 932 933 935 936 940 941 942 947 948 949 950 952 956 957 961 965 969 970 971 972 973 977 979 980 984 985 986 988 989 990 992 994 999 998 997 996 995 993 991 987 983 982 981 978 976 975 974 968 967 966 964 963 962 960 959 958 955 954 953 951 946 945 944 943 939 938 937 934 930...

output:

543 542
544 541
545 540
546 539
547 546
548 535
549 548
550 549
551 550
552 534
553 533
554 553
555 554
556 531
557 556
558 528
559 558
560 527
561 526
562 561
563 562
564 524
565 564
566 565
567 523
568 522
569 521
570 569
571 570
572 571
573 520
574 519
575 574
576 518
577 517
578 577
579 578
580 ...

result:

ok Accepted

Test #10:

score: 0
Accepted
time: 50ms
memory: 137768kb

input:

1000
658 660 661 666 667 668 672 677 678 679 680 681 683 684 686 688 689 690 691 695 697 698 701 702 705 708 711 713 715 716 719 720 722 727 731 734 738 740 742 744 747 748 749 750 751 752 753 757 760 761 766 768 769 770 771 772 773 774 775 778 779 780 781 782 783 784 785 788 789 790 791 792 793 794...

output:

679 674
680 673
681 669
682 668
683 682
684 683
685 684
686 685
687 686
688 667
689 688
690 666
691 665
692 664
693 663
694 693
695 694
696 695
697 661
698 660
699 659
700 658
701 700
702 657
703 655
704 653
705 649
706 705
707 648
708 646
709 708
710 645
711 636
712 711
713 712
714 635
715 634
716 ...

result:

ok Accepted

Test #11:

score: 0
Accepted
time: 41ms
memory: 137828kb

input:

1000
221 222 225 226 229 230 231 232 235 236 237 238 240 242 243 244 245 246 248 250 253 254 255 256 263 266 269 271 272 274 275 276 277 279 280 282 284 285 286 287 290 295 296 299 301 302 304 305 307 310 312 313 314 315 317 319 320 324 325 329 334 337 339 344 345 346 348 351 352 355 357 361 362 363...

output:

899 898
900 895
901 890
902 888
903 902
904 903
905 885
906 884
907 906
908 883
909 879
910 909
911 873
912 911
913 912
914 870
915 869
916 868
917 867
918 866
919 918
920 865
921 920
922 862
923 857
924 923
925 924
926 855
927 926
928 927
929 928
930 853
931 930
932 851
933 932
934 933
935 934
936 ...

result:

ok Accepted

Test #12:

score: 0
Accepted
time: 32ms
memory: 137796kb

input:

1000
186 187 188 189 190 191 194 196 199 201 203 205 206 210 211 212 213 216 217 219 220 221 223 229 231 235 240 241 243 244 245 246 247 248 250 255 257 258 259 262 263 264 266 267 268 269 272 273 275 276 278 281 282 283 284 291 292 294 301 302 304 305 307 311 316 317 318 319 322 326 327 328 333 334...

output:

918 915
919 914
920 919
921 920
922 921
923 922
924 913
925 909
926 925
927 907
928 904
929 928
930 901
931 930
932 898
933 932
934 897
935 934
936 893
937 892
938 888
939 887
940 886
941 885
942 884
943 882
944 943
945 944
946 881
947 880
948 877
949 876
950 949
951 950
952 875
953 874
954 869
955 ...

result:

ok Accepted

Test #13:

score: 0
Accepted
time: 56ms
memory: 137688kb

input:

10
4 3 2 1 0 5 6 9 8 7

output:

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

result:

ok Accepted

Test #14:

score: 0
Accepted
time: 50ms
memory: 137688kb

input:

10
0 1 4 5 9 8 7 6 3 2

output:

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

result:

ok Accepted

Test #15:

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

input:

10
5 6 8 9 7 3 0 1 2 4

output:

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

result:

ok Accepted

Test #16:

score: 0
Accepted
time: 62ms
memory: 137796kb

input:

10
3 0 1 2 7 9 8 6 5 4

output:

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

result:

ok Accepted

Test #17:

score: 0
Accepted
time: 41ms
memory: 137684kb

input:

10
5 9 8 7 6 0 1 2 3 4

output:

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

result:

ok Accepted

Test #18:

score: 0
Accepted
time: 50ms
memory: 141472kb

input:

50000
22746 22745 22743 22742 22739 22735 22733 22732 22731 22729 22727 22724 22722 22720 22719 22717 22716 22714 22713 22708 22707 22706 22705 22703 22702 22700 22698 22693 22692 22689 22687 22685 22683 22682 22680 22679 22678 22676 22674 22671 22667 22665 22664 22661 22659 22658 22656 22650 22649 ...

output:

11426 11417
11427 11426
11428 11427
11429 11428
11430 11414
11431 11413
11432 11412
11433 11408
11434 11433
11435 11406
11436 11435
11437 11404
11438 11403
11439 11402
11440 11439
11441 11440
11442 11401
11443 11442
11444 11399
11445 11393
11446 11445
11447 11446
11448 11392
11449 11448
11450 11449
...

result:

ok Accepted

Test #19:

score: 0
Accepted
time: 79ms
memory: 141544kb

input:

50000
27526 27521 27520 27519 27517 27511 27506 27505 27504 27499 27497 27495 27492 27490 27489 27488 27486 27482 27481 27480 27478 27477 27476 27475 27474 27473 27468 27467 27466 27465 27463 27462 27461 27460 27455 27454 27452 27451 27449 27448 27447 27445 27444 27442 27441 27440 27439 27438 27436 ...

output:

13763 13762
13764 13763
13765 13757
13766 13765
13767 13755
13768 13767
13769 13768
13770 13752
13771 13770
13772 13771
13773 13772
13774 13773
13775 13774
13776 13775
13777 13751
13778 13777
13779 13750
13780 13779
13781 13748
13782 13747
13783 13746
13784 13745
13785 13784
13786 13743
13787 13741
...

result:

ok Accepted

Test #20:

score: 0
Accepted
time: 65ms
memory: 141424kb

input:

50000
18177 18178 18180 18181 18182 18183 18184 18185 18186 18188 18189 18190 18193 18194 18195 18196 18198 18200 18204 18206 18209 18212 18214 18215 18217 18218 18220 18221 18223 18226 18228 18230 18232 18234 18235 18236 18237 18238 18239 18240 18243 18244 18246 18248 18249 18250 18251 18254 18255 ...

output:

40892 40889
40893 40892
40894 40893
40895 40886
40896 40885
40897 40896
40898 40882
40899 40898
40900 40899
40901 40879
40902 40878
40903 40877
40904 40873
40905 40868
40906 40905
40907 40906
40908 40867
40909 40908
40910 40864
40911 40910
40912 40911
40913 40912
40914 40862
40915 40860
40916 40915
...

result:

ok Accepted

Test #21:

score: 0
Accepted
time: 73ms
memory: 141528kb

input:

50000
13195 13194 13193 13192 13191 13190 13186 13184 13181 13180 13179 13176 13172 13168 13166 13160 13159 13158 13156 13155 13154 13151 13150 13149 13148 13147 13145 13144 13142 13141 13138 13137 13135 13133 13132 13131 13130 13127 13126 13125 13124 13122 13121 13119 13113 13112 13111 13109 13106 ...

output:

6686 6684
6687 6683
6688 6682
6689 6681
6690 6689
6691 6690
6692 6691
6693 6692
6694 6693
6695 6680
6696 6695
6697 6678
6698 6676
6699 6698
6700 6699
6701 6700
6702 6701
6703 6674
6704 6703
6705 6704
6706 6673
6707 6668
6708 6666
6709 6708
6710 6664
6711 6663
6712 6661
6713 6712
6714 6660
6715 6714
...

result:

ok Accepted

Test #22:

score: 0
Accepted
time: 59ms
memory: 141540kb

input:

50000
1852 1856 1857 1858 1859 1860 1862 1868 1871 1873 1874 1875 1876 1877 1878 1879 1880 1882 1883 1885 1888 1891 1892 1896 1897 1898 1899 1901 1902 1904 1907 1910 1913 1914 1915 1916 1919 1922 1924 1933 1934 1939 1942 1943 1944 1945 1946 1947 1951 1952 1954 1958 1959 1960 1963 1967 1971 1972 1974...

output:

49096 49093
49097 49092
49098 49097
49099 49091
49100 49090
49101 49100
49102 49101
49103 49102
49104 49087
49105 49085
49106 49083
49107 49082
49108 49081
49109 49108
49110 49079
49111 49110
49112 49111
49113 49112
49114 49113
49115 49075
49116 49115
49117 49074
49118 49117
49119 49118
49120 49119
...

result:

ok Accepted

Test #23:

score: 0
Accepted
time: 25ms
memory: 137676kb

input:

10
0 1 2 3 4 1 3 4 2 3

output:

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

result:

ok Accepted

Test #24:

score: 0
Accepted
time: 89ms
memory: 138012kb

input:

100000
14879 87590 37413 82877 91816 99368 57722 18313 13232 60892 82794 83615 74864 40543 14870 85014 43195 10372 6873 49345 74272 13216 63600 69518 67189 49138 85317 50772 14868 77474 80767 29747 65064 18180 28977 56880 33900 86699 91545 47133 63943 90691 30748 55160 47586 61970 40174 90782 72342 ...

output:

-1

result:

ok Accepted

Test #25:

score: 0
Accepted
time: 76ms
memory: 138148kb

input:

100000
81178 95341 24040 3728 26335 48898 35932 98152 927 65240 82807 15496 29663 67304 7197 54578 66546 18582 8041 5923 5729 76555 53351 92767 61036 29539 68463 2428 7564 43887 41361 5095 39228 81753 8823 81916 30651 44755 96420 47930 26348 79228 63426 56011 62884 86975 26942 45782 5558 34983 51705...

output:

-1

result:

ok Accepted

Test #26:

score: 0
Accepted
time: 69ms
memory: 138064kb

input:

100000
53577 25315 53433 30671 6467 2872 84147 91912 85319 61542 47611 80695 26481 99184 41582 3433 77823 89796 77230 82767 28980 12731 72640 93192 69769 10999 26066 18889 52239 85327 83628 22168 26994 37062 52839 49814 39934 36986 41726 41605 14880 89338 22300 57713 4874 63882 61146 82697 70031 383...

output:

-1

result:

ok Accepted

Test #27:

score: 0
Accepted
time: 83ms
memory: 138048kb

input:

100000
81135 8663 9164 19316 86324 40203 5062 19568 82356 42929 5927 82216 98924 58933 66389 82692 72054 67580 12241 11633 81401 2763 38411 10157 74285 93803 99394 5099 38298 26499 11008 19433 51514 20172 38749 37838 76728 60163 73758 75436 3093 79685 57652 2017 38619 40394 84709 27025 7974 13303 38...

output:

-1

result:

ok Accepted

Test #28:

score: 0
Accepted
time: 65ms
memory: 138040kb

input:

100000
50905 98560 21701 12345 66048 48067 82660 29832 54525 71372 78765 94726 45795 66860 44975 87565 46302 72141 648 90792 39614 84964 12322 57149 78604 33000 56676 60927 43448 30819 1490 10706 29380 39543 39403 95428 87610 38415 25260 42135 9788 4026 53213 55583 87238 14540 59500 49892 86681 6014...

output:

-1

result:

ok Accepted

Test #29:

score: 0
Accepted
time: 48ms
memory: 137764kb

input:

1000
389 253 88 629 904 706 826 449 986 6 831 427 363 977 557 421 177 379 868 525 151 489 590 180 636 869 465 775 663 459 91 52 712 532 33 968 238 859 769 224 217 953 3 580 282 561 1 459 940 221 337 91 62 927 271 699 148 736 826 811 547 918 215 612 450 248 580 40 459 702 264 677 655 267 609 937 180 ...

output:

-1

result:

ok Accepted

Test #30:

score: 0
Accepted
time: 21ms
memory: 137752kb

input:

1000
790 91 483 213 442 184 2 936 155 65 927 281 302 281 221 399 823 2 158 68 766 977 962 992 371 127 856 921 808 540 943 950 983 426 164 426 610 518 714 117 935 641 399 589 274 972 989 449 327 147 518 445 476 480 437 199 959 645 120 768 186 415 70 521 842 586 299 804 105 13 274 392 7 673 982 281 99...

output:

-1

result:

ok Accepted

Test #31:

score: 0
Accepted
time: 73ms
memory: 137820kb

input:

1000
567 319 394 372 340 194 966 619 998 93 366 99 125 694 335 498 367 216 274 198 349 138 618 644 115 897 245 338 560 499 4 479 170 398 851 862 944 817 481 942 910 847 393 35 894 729 533 261 297 159 811 646 298 781 642 765 679 887 103 239 738 459 718 261 858 922 123 802 91 605 97 2 452 842 389 698 ...

output:

-1

result:

ok Accepted

Test #32:

score: 0
Accepted
time: 66ms
memory: 137764kb

input:

1000
692 429 923 196 573 950 350 696 594 53 802 151 459 735 550 873 632 715 78 602 573 823 793 127 712 311 896 956 82 692 872 775 121 795 323 46 746 673 94 692 79 248 196 890 336 746 115 320 813 194 923 386 17 68 866 729 731 762 37 166 806 909 293 279 705 616 678 803 289 772 495 720 373 691 610 61 7...

output:

-1

result:

ok Accepted

Test #33:

score: 0
Accepted
time: 46ms
memory: 137716kb

input:

1000
202 510 838 645 383 283 551 693 689 882 473 723 45 573 294 598 433 569 27 681 676 756 407 105 21 528 844 963 876 40 619 430 902 457 427 285 92 978 330 781 860 803 857 905 377 151 855 162 721 882 844 749 638 251 206 11 131 50 974 359 442 945 789 344 754 216 981 847 546 312 980 406 115 837 663 84...

output:

-1

result:

ok Accepted

Test #34:

score: 0
Accepted
time: 52ms
memory: 137808kb

input:

10
5 6 6 7 4 1 5 8 8 6

output:

-1

result:

ok Accepted

Test #35:

score: 0
Accepted
time: 34ms
memory: 137748kb

input:

10
6 0 1 1 2 8 1 0 5 3

output:

-1

result:

ok Accepted

Test #36:

score: 0
Accepted
time: 47ms
memory: 137812kb

input:

10
2 1 5 4 0 3 9 7 6 9

output:

-1

result:

ok Accepted

Test #37:

score: 0
Accepted
time: 47ms
memory: 137684kb

input:

10
9 8 7 8 7 5 4 5 9 6

output:

-1

result:

ok Accepted

Test #38:

score: 0
Accepted
time: 42ms
memory: 137708kb

input:

10
0 5 1 5 5 1 1 5 8 9

output:

-1

result:

ok Accepted

Test #39:

score: 0
Accepted
time: 55ms
memory: 137852kb

input:

50000
33913 532 38127 33353 3578 15234 43983 32672 22946 37844 32249 49533 3729 39801 21328 44522 11143 32850 33043 28846 32287 2258 16388 12556 37216 30241 34962 44478 32584 23184 21929 16498 23717 26408 16203 43647 41643 26538 26320 30941 30734 8569 30475 34463 14722 1803 45338 25865 1006 44733 21...

output:

-1

result:

ok Accepted

Test #40:

score: 0
Accepted
time: 52ms
memory: 137824kb

input:

50000
20498 38005 17560 14794 2319 19653 40349 34217 39094 23056 8668 43724 31914 17162 13977 39487 16082 20008 21394 39176 12096 6435 36270 30301 39025 36734 478 46842 122 13134 40439 20620 17491 8000 35415 19811 44005 42116 4028 49451 31524 12696 9528 29790 46210 23505 19278 12292 43514 7024 17820...

output:

-1

result:

ok Accepted

Test #41:

score: 0
Accepted
time: 56ms
memory: 137748kb

input:

50000
2078 12656 6446 27911 15092 29319 4809 10939 5717 22669 33900 42772 32276 18932 15047 44291 13239 29478 34243 36626 3998 43551 49800 16657 47172 13891 33427 15793 49884 25121 34792 18314 37777 7590 46225 19222 36910 17386 46513 42627 6408 46765 35399 5036 32049 16799 49328 45288 12629 49923 31...

output:

-1

result:

ok Accepted

Test #42:

score: 0
Accepted
time: 65ms
memory: 137748kb

input:

50000
26680 46058 18928 34937 26245 22060 3670 31236 44839 1362 10522 14491 39637 8281 7578 11167 22174 16412 5931 14446 4412 719 328 26397 11807 35659 34628 26146 20707 22121 20944 13739 34532 39872 48676 10777 28285 18699 8365 39476 36413 35239 20319 42402 43521 44250 3569 32047 10662 25852 12845 ...

output:

-1

result:

ok Accepted

Test #43:

score: 0
Accepted
time: 50ms
memory: 137776kb

input:

50000
37398 9325 44810 27451 9682 44314 36630 30210 20053 36304 48964 9937 12999 618 49834 44954 16297 33049 15847 35838 19363 38021 28378 47262 45179 12562 3229 41054 3119 19652 18101 40518 28977 29264 34321 5011 23578 20951 35222 9983 7256 538 19920 20255 1157 36106 31561 33806 19155 47408 35996 4...

output:

-1

result:

ok Accepted

Test #44:

score: 0
Accepted
time: 77ms
memory: 139640kb

input:

100000
0 2 1 1 2 1 2 1 2 1 1 1 1 1 3 3 2 1 2 1 3 2 3 1 1 1 1 1 2 2 1 1 2 1 2 1 2 1 1 2 1 1 1 2 1 1 1 1 2 3 1 1 2 1 2 2 2 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 2 2 1 2 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 1 2 1 2 1 1 2 1 1 1 1 1 1 2 1 3 3 2 3 1 1 1 1 1 2 1 2 2 1 2 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 2 1...

output:

2 3
3 1
4 1
5 4
6 1
7 6
8 1
9 8
10 1
11 1
12 1
13 1
14 1
15 17
16 17
17 14
18 1
19 18
20 1
21 22
22 20
23 22
24 1
25 1
26 1
27 1
28 1
29 28
30 28
31 1
32 1
33 32
34 1
35 34
36 1
37 36
38 1
39 1
40 39
41 1
42 1
43 1
44 43
45 1
46 1
47 1
48 1
49 48
50 49
51 1
52 1
53 52
54 1
55 54
56 54
57 54
58 1
59 ...

result:

ok Accepted

Test #45:

score: 0
Accepted
time: 80ms
memory: 139492kb

input:

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

output:

2 4
3 4
4 1
5 1
6 1
7 8
8 6
9 1
10 1
11 12
12 10
13 12
14 1
15 1
16 17
17 18
18 15
19 1
20 1
21 1
22 21
23 21
24 21
25 21
26 21
27 1
28 1
29 28
30 29
31 1
32 31
33 1
34 1
35 1
36 35
37 36
38 1
39 40
40 41
41 38
42 1
43 1
44 1
45 44
46 1
47 46
48 1
49 48
50 1
51 1
52 1
53 52
54 1
55 1
56 1
57 56
58 5...

result:

ok Accepted

Test #46:

score: 0
Accepted
time: 79ms
memory: 139648kb

input:

100000
0 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 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 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 1 1 1 1 1 1 1 1 1...

output:

2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
11 1
12 1
13 1
14 1
15 1
16 1
17 1
18 1
19 1
20 1
21 1
22 1
23 1
24 1
25 1
26 1
27 1
28 1
29 1
30 1
31 1
32 1
33 1
34 1
35 1
36 35
37 1
38 1
39 1
40 1
41 1
42 1
43 1
44 1
45 1
46 1
47 1
48 1
49 1
50 1
51 1
52 1
53 1
54 1
55 54
56 1
57 1
58 1
59 1
60 1
61 1
62 1
6...

result:

ok Accepted

Test #47:

score: 0
Accepted
time: 78ms
memory: 139576kb

input:

100000
0 2 1 2 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 1 1 2 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 2 1 1 2 1 1...

output:

2 3
3 1
4 3
5 3
6 1
7 1
8 1
9 1
10 1
11 1
12 1
13 1
14 1
15 1
16 1
17 16
18 1
19 1
20 1
21 1
22 1
23 22
24 1
25 1
26 25
27 1
28 1
29 1
30 1
31 30
32 1
33 1
34 1
35 1
36 35
37 1
38 1
39 1
40 1
41 1
42 1
43 1
44 1
45 44
46 1
47 1
48 1
49 1
50 1
51 1
52 1
53 1
54 1
55 1
56 55
57 1
58 1
59 1
60 1
61 60
...

result:

ok Accepted

Test #48:

score: 0
Accepted
time: 80ms
memory: 139524kb

input:

100000
0 2 1 2 2 2 3 2 2 1 2 2 2 2 2 1 2 2 1 2 2 1 1 2 1 3 2 3 2 1 2 3 1 3 2 3 1 2 2 2 2 1 3 2 3 1 3 3 3 4 2 3 1 1 1 2 2 2 2 2 2 2 2 1 4 5 3 4 3 5 4 5 3 2 4 3 4 1 2 3 2 2 2 2 3 1 1 2 2 2 2 2 2 2 1 2 4 3 2 3 2 2 2 3 3 2 2 3 2 2 3 2 3 2 3 2 2 2 1 1 3 2 1 2 3 4 1 2 2 2 2 2 2 2 1 2 1 2 2 4 3 2 2 2 2 2 2...

output:

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

result:

ok Accepted

Test #49:

score: 0
Accepted
time: 62ms
memory: 137720kb

input:

1000
0 3 2 1 1 1 1 2 1 3 2 2 3 1 1 1 1 2 2 3 3 1 2 2 2 1 1 2 1 2 3 2 1 1 1 1 1 1 1 2 1 1 2 1 1 3 2 3 2 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 2 1 1 1 1 1 1 3 2 1 2 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 2 3 2 1 1 2 2 2 2 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 1 2 1 1...

output:

2 3
3 4
4 1
5 1
6 1
7 1
8 7
9 1
10 11
11 9
12 9
13 12
14 1
15 1
16 1
17 1
18 17
19 17
20 19
21 19
22 1
23 22
24 22
25 22
26 1
27 1
28 27
29 1
30 29
31 30
32 29
33 1
34 1
35 1
36 1
37 1
38 1
39 1
40 39
41 1
42 1
43 42
44 1
45 1
46 47
47 45
48 47
49 45
50 1
51 1
52 1
53 1
54 1
55 1
56 55
57 1
58 57
59...

result:

ok Accepted

Test #50:

score: 0
Accepted
time: 34ms
memory: 137724kb

input:

1000
0 2 1 2 1 1 1 1 2 1 2 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 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 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 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 2 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 1...

output:

2 3
3 1
4 3
5 1
6 1
7 1
8 1
9 8
10 1
11 10
12 1
13 1
14 1
15 1
16 1
17 1
18 1
19 1
20 1
21 1
22 1
23 1
24 1
25 1
26 1
27 1
28 1
29 1
30 1
31 1
32 1
33 1
34 1
35 1
36 1
37 1
38 37
39 1
40 1
41 1
42 1
43 1
44 1
45 1
46 1
47 1
48 1
49 1
50 1
51 50
52 1
53 52
54 1
55 1
56 1
57 1
58 1
59 1
60 1
61 1
62 1...

result:

ok Accepted

Test #51:

score: 0
Accepted
time: 31ms
memory: 137852kb

input:

1000
0 1 1 2 1 1 1 2 1 1 2 1 1 1 2 1 1 1 1 2 1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 2 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 3 2 1 1 1 1 2 1 1 2 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 2 2 1 2 1 2 1 2 1 1 2 1 1 1 1 2 1 1 2 2...

output:

2 1
3 1
4 3
5 1
6 1
7 1
8 7
9 1
10 1
11 10
12 1
13 1
14 1
15 14
16 1
17 1
18 1
19 1
20 19
21 1
22 21
23 1
24 1
25 1
26 25
27 1
28 1
29 1
30 1
31 30
32 1
33 1
34 1
35 1
36 1
37 1
38 1
39 1
40 39
41 1
42 1
43 1
44 1
45 1
46 1
47 1
48 1
49 48
50 1
51 50
52 1
53 1
54 1
55 1
56 55
57 1
58 1
59 1
60 1
61 ...

result:

ok Accepted

Test #52:

score: 0
Accepted
time: 43ms
memory: 137720kb

input:

1000
0 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 2 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 9
11 1
12 1
13 1
14 1
15 1
16 1
17 1
18 1
19 1
20 1
21 20
22 1
23 1
24 1
25 24
26 1
27 1
28 1
29 1
30 1
31 1
32 1
33 1
34 1
35 1
36 1
37 1
38 1
39 1
40 1
41 1
42 41
43 1
44 43
45 1
46 1
47 46
48 1
49 1
50 1
51 50
52 1
53 1
54 1
55 1
56 1
57 1
58 1
59 1
60 1
61 1
62...

result:

ok Accepted

Test #53:

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

input:

1000
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 3 1 1 1 2 1 1 1 2 1 1 2 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 2 1 2 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 2 1 1 2 1 1 1...

output:

2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
11 1
12 1
13 1
14 1
15 1
16 1
17 1
18 1
19 1
20 1
21 1
22 1
23 22
24 1
25 1
26 1
27 1
28 1
29 1
30 1
31 1
32 31
33 32
34 1
35 1
36 1
37 36
38 1
39 1
40 1
41 40
42 1
43 1
44 43
45 1
46 1
47 46
48 1
49 1
50 1
51 1
52 1
53 1
54 53
55 1
56 1
57 1
58 1
59 1
60 1
61 1
...

result:

ok Accepted

Test #54:

score: 0
Accepted
time: 33ms
memory: 137736kb

input:

10
0 1 2 1 2 2 1 1 1 1

output:

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

result:

ok Accepted

Test #55:

score: 0
Accepted
time: 29ms
memory: 137760kb

input:

10
0 1 1 1 1 2 3 2 2 2

output:

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

result:

ok Accepted

Test #56:

score: 0
Accepted
time: 28ms
memory: 137688kb

input:

10
0 1 1 1 1 1 1 1 1 1

output:

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

result:

ok Accepted

Test #57:

score: 0
Accepted
time: 26ms
memory: 137740kb

input:

10
0 2 1 2 2 2 1 1 1 2

output:

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

result:

ok Accepted

Test #58:

score: 0
Accepted
time: 34ms
memory: 137688kb

input:

10
0 1 1 1 1 1 1 1 1 1

output:

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

result:

ok Accepted

Test #59:

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

input:

50000
0 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1 2 1 1 1 1 1 1 2 2 1 1 1 1 1 1 2 1 1 1 1 1 1 2 3 1 1 1 2 1 1 2 1 1 2 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 ...

output:

2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
11 1
12 1
13 1
14 1
15 14
16 1
17 1
18 1
19 1
20 19
21 1
22 21
23 1
24 1
25 1
26 25
27 25
28 25
29 25
30 25
31 1
32 1
33 1
34 1
35 1
36 1
37 1
38 1
39 1
40 1
41 1
42 41
43 1
44 1
45 1
46 1
47 1
48 1
49 48
50 1
51 1
52 1
53 1
54 53
55 1
56 1
57 1
58 1
59 1
60 1
61...

result:

ok Accepted

Test #60:

score: 0
Accepted
time: 65ms
memory: 138556kb

input:

50000
0 1 1 2 1 2 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 2 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 2 1 1 1 2 1 1 1 1 1 2 1 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 ...

output:

2 1
3 1
4 3
5 1
6 5
7 1
8 1
9 8
10 1
11 1
12 11
13 1
14 1
15 1
16 1
17 1
18 1
19 1
20 1
21 1
22 1
23 1
24 1
25 1
26 1
27 1
28 1
29 1
30 1
31 1
32 1
33 1
34 1
35 1
36 1
37 36
38 1
39 1
40 1
41 1
42 1
43 1
44 1
45 1
46 45
47 1
48 1
49 1
50 49
51 1
52 1
53 1
54 53
55 1
56 1
57 1
58 1
59 1
60 1
61 1
62 ...

result:

ok Accepted

Test #61:

score: 0
Accepted
time: 49ms
memory: 138544kb

input:

50000
0 1 1 2 1 2 1 1 1 2 1 1 2 1 1 2 1 2 2 3 2 2 1 2 1 2 1 2 1 2 1 2 1 1 2 1 1 2 1 2 1 2 1 2 1 1 1 1 1 2 1 1 2 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 3 2 2 1 1 1 1 1 1 2 2 1 1 1 2 2 2 2 1 1 1 2 1 2 1 1 1 1 1 1 2 1 2 1 1 2 2 1 1 2 1 1 1 1 1 2 1 1 2 3 3 1 1 3 2 2 2 1 1 2 1 3 2 3 3 1 1 1 1 1 2 1 3 2 2 1 2 ...

output:

2 1
3 1
4 3
5 1
6 5
7 1
8 1
9 1
10 9
11 1
12 1
13 12
14 1
15 1
16 15
17 1
18 17
19 17
20 19
21 17
22 17
23 1
24 23
25 1
26 25
27 1
28 27
29 1
30 29
31 1
32 31
33 1
34 1
35 34
36 1
37 1
38 37
39 1
40 39
41 1
42 41
43 1
44 43
45 1
46 1
47 1
48 1
49 1
50 49
51 1
52 1
53 52
54 1
55 1
56 1
57 1
58 57
59 ...

result:

ok Accepted

Test #62:

score: 0
Accepted
time: 58ms
memory: 138636kb

input:

50000
0 1 3 4 2 1 2 3 4 3 2 3 1 1 1 1 2 2 1 3 2 2 1 2 2 1 2 2 1 2 2 2 2 1 2 2 1 1 2 1 1 1 1 2 2 2 2 2 1 2 1 3 2 2 2 1 1 2 1 2 2 2 2 2 1 1 2 2 2 1 1 1 3 2 2 2 2 2 2 2 2 2 3 1 2 2 2 2 2 2 2 1 1 1 1 2 2 1 2 2 1 2 3 4 1 2 2 1 2 1 1 1 3 2 3 1 1 2 2 1 1 3 2 1 1 1 4 4 4 5 5 3 2 1 2 1 1 2 1 2 1 2 3 2 2 2 1 ...

output:

2 1
3 5
4 3
5 2
6 1
7 6
8 7
9 8
10 7
11 6
12 11
13 1
14 1
15 1
16 1
17 16
18 16
19 1
20 21
21 19
22 19
23 1
24 23
25 23
26 1
27 26
28 26
29 1
30 29
31 29
32 29
33 29
34 1
35 34
36 34
37 1
38 1
39 38
40 1
41 1
42 1
43 1
44 43
45 43
46 43
47 43
48 43
49 1
50 49
51 1
52 53
53 51
54 51
55 51
56 1
57 1
5...

result:

ok Accepted

Test #63:

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

input:

50000
0 1 2 1 3 3 3 2 3 2 1 2 1 2 1 2 3 3 2 3 2 3 2 1 2 3 1 2 4 3 1 2 1 2 2 2 1 1 2 1 3 4 2 2 2 3 2 3 1 2 2 2 2 2 2 2 2 2 3 2 2 2 2 3 1 2 2 3 2 4 3 2 3 3 2 3 2 2 3 3 2 4 3 2 1 2 1 2 1 2 1 2 2 3 2 3 2 2 2 3 3 2 2 2 3 2 2 3 2 2 2 3 1 3 2 1 2 2 2 2 2 2 2 2 1 3 2 3 2 2 3 2 1 3 5 4 3 4 4 3 4 2 2 3 3 3 1 ...

output:

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

result:

ok Accepted