QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#322598 | #4829. Mark on a Graph | Pentagonal | 0 | 1436ms | 4292kb | C++17 | 6.7kb | 2024-02-07 11:55:26 | 2024-02-07 11:55:26 |
Judging History
answer
// #pragma GCC target("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimization ("Ofast")
//#pragma GCC -Wnarrowing
//Template {
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
using namespace std;
using namespace __gnu_pbds;
//IO templates
//Note: use endl only for interactive problems or to debug segfaults; use newl for other problems
#define newl "\n"
#define fastIO ios::sync_with_stdio(false); cin.tie(nullptr)
#define fileIO(x) ifstream fin((str) x + (str) ".in"); ofstream fout((str) x + (str) ".out");
// void fileIO(string x) {}
#define flush() fflush(stdout)
#define interact(n) fflush(stdout); cin >> n; if (n == -1) return 0
#define testcases int tt; cin >> tt; fun (i, tt) solve();
#define edgeIO(m) fun (i, m) {int a, b; cin >> a >> b; addEdges(a, b);}
#define WeightedEdgeIO(m) fun (i, m) {int a, b, c; cin >> a >> b >> c; addWeightedEdges(a, b, c);}
#define numberedEdgeIO(m) fun (i, m) {int a, b; cin >> a >> b; addWeightedEdges(a, b, i);}
//types
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define ld long double
#define str string
#define boolean bool
#define String string
//vector
#define pb push_back
#define append push_back
//pairs
#define mp make_pair
#define p2 pair<int, int>
#define p3 pair<int, p2>
#define m3(x, y, z) mp(x, mp(y, z))
#define ich first
#define ni second.first
#define sanshi second.second
//For loops
#define ahegao(i, a, b) for (int i = a; i < b; i++)
#define baka(i, b, a) for (int i = b; i > a; i--)
#define fun(i, n) for (int i = 1; i <= (n); (i)++)
#define fon(i, n) for (int i = 0; i < (n); (i)++)
#define fur(i, n) for (auto i : (n))
#define oniichan(i, n) for (auto &i : (n))
//Sorts
#define sz(aaa) ((signed) aaa.size())
// #define len(aaa) ((signed) aaa.size())
#define all(a) a.begin(), a.end()
#define Sort(a) sort((a).begin(), (a).end())
#define rSort(a) sort((a).rbegin(), (a).rend())
#define clamp(x, y) (x) = min((int) (x), (int) (y))
#define CLAMP(x, y) (x) = max((int) (x), (int) (y))
//Other stuff
#define pqueue priority_queue
#define elif else if
#define addEdges(a, b) adj[a].pb(b); adj[b].pb(a)
#define addWeightedEdges(a, b, c) adj[a].pb(mp(b, c)); adj[b].pb(mp(a, c))
// #define find find_by_order
#define printLength(x) if (x < INF) cout << x << newl; else cout << -1 << newl;
// #define printVector(a) fur (i, a) cout << i << ' '; cout << newl;
void printVector(vector<int> DontUseThisName) {
fur (i, DontUseThisName) cout << i << ' '; cout << newl;
}
void printVector(vector<p2> DontUseThisName) {
fur (i, DontUseThisName) cout << i.first << ' ' << i.second << newl; cout << newl;
}
void printVector(vector<vector<int>> DontUseThisName) {
fur (i, DontUseThisName) printVector(i); cout << newl;
}
ll max(ll a, signed b) {return max(a, (ll) b);}
ll max(signed a, ll b) {return max((ll) a, b);}
void pv(int a) {cout << a << newl;}
void pv(int a, int b) {printVector({a, b});}
void pv(p2 a) {printVector({a.first, a.second});};
void pv(int a, int b, int c) {printVector({a, b, c});}
void pv(int a, int b, int c, int d) {printVector({a, b, c, d});}
void pv(int a, int b, int c, int d, int e) {printVector({a, b, c, d, e});}
void pv(int a, int b, int c, int d, int e, int f) {printVector({a, b, c, d, e, f});}
// void pv(int a, )
// void printVector(vector<char> DontUseThisName) {
// fur (i, DontUseThisName) cout << i << ' '; cout << newl;
// }
// void printRange(vector<int>::iterator Left, vector<int>::iterator Right) {
// for (auto i = Left; i < Right; i++) cout << *i << ' ';
// cout << newl;
// }
//Constants
// const int MOD = 1e9+7; // 998244353
// const int SMALLMOD = 998244353;
const int INF = 2e9+1337;
const ll EXCEED = 2e18+1337;
const ll GRAVITY = 8e18;
//#define vectorIO(n, MikuBondage) fun (j, n) {int i; cin >> i; MikuBondage.pb(i);}
void vectorIO(int n, vector<int> &DontUseThisName) {
fun (j, n) {int i; cin >> i; DontUseThisName.pb(i);}
}
//#define vector2IO(n, MikuBondage) fun (j, n) {int i, ii; cin >> i >> ii; MikuBondage.pb(mp(i, ii));}
void vector2IO(int n, vector<p2> &DontUseThisName) {
fun (j, n) {int i, ii; cin >> i >> ii; DontUseThisName.pb(mp(i, ii));}
}
// const int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
#define shortest_path_queue priority_queue<p2, vector<p2>, greater<p2>>
#define printArray(DontUseThisName, NakedLolisGalore, GenshinImpactClimbing) ahegao (j, NakedLolisGalore, GenshinImpactClimbing + 1) cout << DontUseThisName[j] << ' '; cout << newl;
#define print2dArray(SplitComplexProblemsIntoMultipleParts, ScuteSwarm, GenshinImpactClimbing) fun (i, ScuteSwarm) {fun (j, GenshinImpactClimbing) cout << SplitComplexProblemsIntoMultipleParts[i][j] << ' '; cout << newl;}
//}
const int MAX = 1003;
const int MOD = 2003;
int n, m, k, curr;
set<int> adj[MAX];
int cnt[1003];
unsigned long long rng = chrono::steady_clock::now().time_since_epoch().count();
int hash1() {
vector<int> aaa;
fun (i, n) {
vector<int> temp;
fur (j, adj[i]) temp.pb(sz(adj[j]));
// Sort(temp);
int res = 1;
fur (j, temp) res = (res + j) % MOD;
cnt[i] = res;
}
fun (i, n) {
vector<int> temp;
fur (j, adj[i]) temp.pb(cnt[j]);
Sort(temp);
int res = 1;
fur (j, temp) res = (71 * res + j) % MOD;
aaa.pb(res);
}
// Sort(aaa);
int rrr = 1;
fur (j, aaa) rrr = (rrr + j * j * j) % MOD;
// pv(rrr);
return rrr;
}
int randint() {
rng = ((1337 * (rng % 483187) + (rng << 5) + (rng << 27) + 987654321 + (rng % 235612) * (rng * 55679))) % INF;
return rng;
}
signed main() {
fastIO;
cin >> n >> m;
// edgeIO(m);
fun (i, m) {
int a, b; cin >> a >> b;
adj[a].insert(b); adj[b].insert(a);
}
// cout << hash1() << newl;
if (hash1() == 1337) {
cout << "ok";
return 0;
}
// return 0;
// fun (i, n) ahegao (j, i+1, n+1) {
fun (i, n) ahegao (j, i+1, n+1) {
if (randint() % 10) continue;
if (adj[i].find(j) == adj[i].end()) {
adj[i].insert(j);
adj[j].insert(i);
if (hash1() == 1337) {
cout << "mark" << newl;
cout << 1 << newl;
pv(i, j);
return 0;
}
adj[i].erase(j);
adj[j].erase(i);
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 64ms
memory: 4292kb
input:
1000 3560 603 151 415 20 102 569 895 552 678 734 24 614 689 518 440 223 751 919 223 433 711 551 502 634 706 583 812 501 514 535 780 751 720 530 532 384 888 139 864 791 292 675 171 881 30 592 464 557 280 299 654 650 894 335 250 532 792 10 83 969 118 771 579 300 852 983 243 940 957 939 817 889 911 319...
output:
mark 1 3 55
input:
1000 3561 269 626 882 830 665 959 338 534 682 161 833 50 155 199 183 656 184 95 383 358 259 450 771 817 335 355 174 167 402 763 582 250 950 401 850 500 902 369 521 246 368 418 794 262 920 351 831 643 688 730 553 125 506 102 419 188 962 736 11 36 37 355 600 53 201 783 267 511 790 201 951 583 937 221 ...
output:
ok
result:
ok all right
Test #2:
score: 100
Accepted
time: 526ms
memory: 4148kb
input:
1000 2000 457 335 160 497 464 992 892 255 853 3 308 301 970 363 541 299 89 418 425 128 626 827 603 854 484 874 755 295 607 483 798 552 356 850 320 357 254 940 675 901 168 525 301 636 520 555 773 910 343 701 889 966 218 529 909 950 71 64 682 284 424 138 721 792 670 544 386 72 654 909 725 235 592 437 ...
output:
mark 1 31 451
input:
1000 2001 181 711 426 320 451 386 377 313 97 233 231 792 993 482 403 152 835 246 554 952 541 72 227 182 962 916 584 649 546 673 962 651 529 178 731 324 39 263 541 268 568 620 379 375 415 582 622 628 341 884 672 70 564 349 532 563 99 37 741 982 23 450 411 738 758 235 770 529 414 78 838 977 956 965 50...
output:
ok
result:
ok all right
Test #3:
score: 100
Accepted
time: 994ms
memory: 4260kb
input:
1000 5000 449 632 597 26 701 322 249 190 411 770 666 596 989 995 112 861 445 818 544 659 24 680 739 593 344 439 193 932 600 526 574 869 216 918 716 793 259 686 555 993 255 578 659 271 328 524 729 672 39 771 241 866 27 790 417 109 56 403 338 299 387 232 280 306 589 794 833 419 900 802 54 697 539 807 ...
output:
mark 1 24 26
input:
1000 5001 551 533 786 996 219 796 171 208 412 802 127 305 361 305 592 435 378 24 75 559 578 166 45 106 156 570 128 805 254 918 647 729 396 945 345 309 992 501 13 247 854 986 582 363 471 245 754 461 326 865 934 1 926 923 206 888 458 321 744 533 21 787 854 115 566 344 337 781 274 421 55 266 649 530 15...
output:
ok
result:
ok all right
Test #4:
score: 100
Accepted
time: 625ms
memory: 4024kb
input:
1000 3156 347 398 792 278 754 442 413 757 391 130 636 625 207 437 81 415 47 974 887 779 524 619 379 894 868 594 653 919 29 117 123 867 632 505 648 147 130 420 495 876 637 659 882 348 462 878 282 646 398 525 419 224 926 448 305 934 855 570 396 345 774 918 336 123 502 491 984 783 845 142 790 594 754 4...
output:
mark 1 24 473
input:
1000 3157 540 43 167 499 403 962 814 342 154 900 990 212 366 612 456 962 777 715 539 243 441 28 582 563 810 843 38 856 841 423 811 609 952 757 435 668 64 778 925 392 396 865 503 527 481 64 311 954 315 976 508 855 940 42 161 215 501 285 617 957 869 225 879 919 610 421 127 448 58 923 748 615 671 799 7...
output:
ok
result:
ok all right
Test #5:
score: 100
Accepted
time: 49ms
memory: 4000kb
input:
1000 3433 634 21 789 966 541 959 213 381 366 781 107 649 747 122 336 869 222 648 833 972 929 524 712 524 744 525 568 679 634 163 901 501 56 518 128 587 720 117 208 439 860 85 852 168 934 947 34 858 520 568 408 464 232 432 999 504 71 982 957 372 570 436 281 309 410 405 521 275 554 589 4 707 498 148 5...
output:
mark 1 2 512
input:
1000 3434 901 246 623 554 416 864 837 660 635 898 735 811 356 790 272 376 783 903 899 769 437 114 257 179 750 607 514 98 669 181 109 968 905 300 341 848 451 211 992 861 307 925 776 682 505 132 117 713 892 451 669 188 24 655 5 358 753 318 505 99 671 425 441 167 30 188 410 42 82 762 344 661 6 213 667 ...
output:
ok
result:
ok all right
Test #6:
score: 100
Accepted
time: 651ms
memory: 4208kb
input:
1000 3057 985 223 432 967 405 822 845 650 893 646 599 718 754 710 333 73 392 355 895 496 200 562 816 36 457 953 9 623 889 662 482 590 249 29 689 694 185 990 285 690 12 323 611 560 903 722 476 86 105 666 441 193 695 640 36 617 840 42 80 527 977 539 606 150 384 585 784 648 919 360 157 532 568 98 995 8...
output:
mark 1 24 681
input:
1000 3058 29 48 203 126 262 63 954 309 294 719 506 107 14 443 241 921 666 607 733 571 432 324 921 572 990 304 552 44 520 921 243 22 4 640 623 947 712 927 877 225 701 146 263 667 509 228 450 626 603 573 971 732 337 771 237 348 652 580 168 116 832 454 75 314 250 947 993 310 995 567 719 792 191 934 578...
output:
ok
result:
ok all right
Test #7:
score: 100
Accepted
time: 159ms
memory: 4248kb
input:
1000 3085 484 405 841 443 661 315 392 941 355 558 523 394 773 929 673 840 5 707 255 610 744 58 301 794 505 33 668 533 787 945 747 810 803 115 340 900 791 909 596 418 129 491 460 698 156 233 664 502 231 465 795 486 829 102 608 212 253 344 419 557 100 421 321 793 207 302 544 479 33 916 736 129 6 156 9...
output:
mark 1 6 876
input:
1000 3086 665 821 248 628 417 787 474 734 953 941 570 533 479 888 883 619 174 274 613 554 480 160 570 398 86 617 76 6 518 662 743 672 728 94 896 52 778 568 474 293 977 247 701 533 219 773 31 664 108 860 640 490 907 603 436 948 289 874 608 575 396 963 453 369 843 44 765 772 595 347 595 330 959 65 53 ...
output:
ok
result:
ok all right
Test #8:
score: 100
Accepted
time: 383ms
memory: 4288kb
input:
1000 4289 963 66 959 467 930 83 419 699 731 948 702 583 699 245 636 721 859 551 377 251 90 889 286 843 908 47 864 979 223 948 269 684 85 579 162 376 414 255 602 884 65 132 842 907 488 360 553 898 649 249 253 711 675 632 629 446 708 413 819 511 512 113 189 76 242 464 828 261 440 737 643 389 75 907 49...
output:
mark 1 10 967
input:
1000 4290 765 673 929 54 935 953 570 307 368 586 798 495 123 313 236 163 75 337 610 299 436 338 495 999 636 660 410 96 84 766 445 483 832 382 944 554 74 443 110 621 318 320 668 204 433 884 662 198 240 752 628 722 278 215 592 755 404 955 102 15 67 129 602 33 681 306 781 759 569 257 562 186 538 759 98...
output:
ok
result:
ok all right
Test #9:
score: 100
Accepted
time: 303ms
memory: 4208kb
input:
1000 4763 544 167 316 76 78 841 699 1 645 745 827 262 568 545 595 81 924 561 108 253 397 626 142 967 613 397 723 633 711 259 363 249 5 436 165 88 178 463 734 529 195 324 135 41 1000 136 215 967 371 638 588 753 542 909 633 106 537 852 111 232 303 500 892 461 868 300 772 667 40 172 956 575 613 163 933...
output:
mark 1 8 75
input:
1000 4764 450 710 910 637 103 839 624 791 228 948 299 625 271 750 307 347 156 263 710 838 914 936 591 421 53 837 990 918 308 320 500 181 444 557 50 827 635 705 821 379 332 116 800 90 224 370 516 163 767 976 558 429 66 306 667 394 847 158 148 122 968 872 634 793 396 746 331 388 180 214 757 251 862 67...
output:
ok
result:
ok all right
Test #10:
score: 100
Accepted
time: 254ms
memory: 4120kb
input:
1000 4250 747 446 769 425 773 753 217 298 217 4 514 774 752 3 905 857 532 410 224 250 367 33 29 541 809 996 76 960 25 603 532 600 518 304 546 95 735 413 312 476 83 534 157 62 170 836 668 976 244 557 972 860 828 170 975 468 677 714 800 170 530 191 216 930 242 728 318 505 269 162 579 963 769 822 171 4...
output:
mark 1 8 132
input:
1000 4251 112 370 102 703 776 233 835 409 598 303 9 55 320 874 639 193 819 701 447 83 308 365 300 156 219 36 14 309 617 487 685 229 585 656 79 394 495 250 342 188 275 604 326 920 728 164 380 74 892 31 797 986 984 629 148 404 377 353 270 60 578 582 5 848 261 174 398 338 494 140 371 94 146 199 45 240 ...
output:
ok
result:
ok all right
Test #11:
score: 100
Accepted
time: 49ms
memory: 4068kb
input:
1000 3336 161 745 81 702 879 347 452 553 809 32 359 925 984 783 558 366 611 89 948 530 565 496 123 348 534 986 991 511 322 407 6 878 20 897 188 150 527 440 487 333 218 572 597 575 308 684 50 780 900 451 763 785 210 682 964 992 811 537 537 167 320 133 523 899 629 732 435 281 826 405 868 567 201 858 2...
output:
mark 1 2 624
input:
1000 3337 252 599 420 343 900 936 700 161 202 1000 338 992 72 621 164 413 141 280 419 154 137 958 412 217 675 438 58 687 433 172 423 120 877 884 373 329 90 134 957 76 984 685 499 533 153 420 992 986 293 418 808 502 289 367 381 82 812 370 916 843 932 30 524 236 723 854 766 709 356 376 85 153 410 921 ...
output:
ok
result:
ok all right
Test #12:
score: 100
Accepted
time: 84ms
memory: 4084kb
input:
1000 3482 910 881 481 989 349 262 963 679 970 752 651 210 86 339 724 310 765 410 118 619 662 351 568 148 292 61 136 385 997 772 210 735 816 310 698 649 581 313 414 280 92 872 965 925 35 930 813 29 617 210 854 940 486 479 412 644 660 623 126 85 664 327 459 165 266 113 108 206 686 660 918 536 173 366 ...
output:
mark 1 3 639
input:
1000 3483 732 216 26 960 633 812 543 818 650 60 104 532 706 504 396 473 87 574 944 144 436 698 109 269 668 71 400 568 443 464 680 920 384 711 455 324 487 770 791 666 52 549 160 733 544 682 624 866 862 240 189 630 256 803 812 625 840 631 346 963 543 492 723 843 539 742 511 97 616 452 391 131 744 173 ...
output:
ok
result:
ok all right
Test #13:
score: 100
Accepted
time: 433ms
memory: 4000kb
input:
1000 2141 358 723 692 581 753 295 864 391 984 462 525 271 508 897 739 537 124 933 577 499 863 37 279 622 361 605 454 951 527 837 1 224 641 404 479 220 931 126 182 719 464 451 805 452 529 800 292 689 17 320 728 790 967 41 412 752 276 535 643 636 611 56 802 414 861 603 857 722 1000 584 435 118 266 392...
output:
mark 1 24 676
input:
1000 2142 482 327 435 67 842 324 542 821 998 372 408 746 560 886 635 960 211 898 925 983 745 399 986 692 831 943 92 121 561 366 414 271 27 418 594 270 407 480 625 453 98 796 425 37 65 129 376 824 49 673 225 670 988 76 945 907 131 938 999 30 491 432 788 961 597 526 515 710 587 409 338 550 357 308 305...
output:
ok
result:
ok all right
Test #14:
score: 100
Accepted
time: 83ms
memory: 4056kb
input:
1000 2950 244 361 694 442 547 577 545 866 488 207 888 997 263 45 850 200 30 927 195 510 274 582 467 158 664 667 880 573 522 986 736 375 206 326 999 940 875 609 151 161 602 673 664 200 827 579 12 190 300 249 95 502 951 317 669 243 350 841 692 572 619 302 955 999 480 891 109 779 198 893 105 442 214 14...
output:
mark 1 4 370
input:
1000 2951 585 749 754 407 266 289 671 238 489 256 818 116 14 867 939 353 663 816 637 187 222 773 204 215 666 180 995 537 256 492 570 257 109 563 583 713 964 992 66 754 931 44 793 916 710 944 43 981 609 3 914 367 578 462 262 59 806 755 239 845 180 476 763 865 22 248 833 279 15 841 209 418 426 11 760 ...
output:
ok
result:
ok all right
Test #15:
score: 100
Accepted
time: 149ms
memory: 4212kb
input:
1000 2725 336 461 575 6 961 482 496 574 134 336 671 452 172 957 633 89 909 334 222 155 90 660 201 950 436 671 726 683 487 356 536 389 107 844 403 732 550 608 607 54 718 438 960 144 710 278 398 747 152 501 86 385 34 251 309 822 773 321 329 213 897 948 356 401 290 329 278 591 683 454 122 523 729 436 4...
output:
mark 1 7 616
input:
1000 2726 826 863 860 669 482 579 461 442 496 849 962 420 832 558 899 680 671 586 876 932 6 579 49 750 506 996 166 759 563 508 764 228 210 471 707 306 89 391 16 349 728 923 496 830 591 108 534 553 220 382 489 624 969 790 385 891 343 989 69 837 478 200 455 886 539 29 37 349 554 860 316 683 143 324 33...
output:
ok
result:
ok all right
Test #16:
score: 100
Accepted
time: 601ms
memory: 4044kb
input:
1000 2812 357 725 462 948 927 875 21 284 52 197 457 876 744 315 990 255 660 522 51 971 392 275 736 77 131 216 581 438 495 271 965 111 376 89 824 363 628 13 33 585 836 144 791 404 916 588 668 243 960 335 505 368 744 264 332 893 65 320 205 81 929 44 135 224 306 351 938 505 70 927 825 634 161 492 434 1...
output:
mark 1 26 434
input:
1000 2813 677 559 157 134 87 218 65 463 383 514 308 94 994 900 400 922 977 176 59 893 403 802 525 873 143 629 152 187 592 100 405 99 353 186 445 514 286 171 291 135 207 153 424 703 80 391 268 83 146 844 237 635 524 740 608 279 898 307 394 312 961 353 954 603 156 224 296 172 897 177 766 214 736 205 8...
output:
ok
result:
ok all right
Test #17:
score: 100
Accepted
time: 1436ms
memory: 4204kb
input:
1000 2616 518 38 164 144 301 140 711 11 36 636 443 779 107 901 467 922 759 675 229 276 467 880 975 435 382 460 238 663 639 927 74 953 777 326 689 944 152 237 501 789 795 889 95 376 390 401 279 64 520 803 273 292 333 454 202 485 860 54 872 641 101 951 236 726 464 847 992 656 576 565 739 176 562 327 2...
output:
mark 1 66 916
input:
1000 2617 903 669 336 738 42 206 724 449 510 323 166 928 895 796 138 853 709 590 223 681 131 55 763 978 492 132 887 251 962 647 947 939 722 681 229 720 216 949 793 266 394 854 600 375 87 491 530 541 461 500 892 139 78 124 959 230 718 623 22 222 780 914 81 851 610 950 321 335 326 697 232 202 137 154 ...
output:
ok
result:
ok all right
Test #18:
score: 100
Accepted
time: 318ms
memory: 4204kb
input:
1000 4792 659 787 666 143 711 116 742 958 604 434 293 882 175 28 557 753 106 808 527 599 942 249 843 109 174 76 429 255 415 489 463 540 878 235 688 87 629 402 927 418 704 734 886 463 702 992 570 370 492 865 795 889 638 594 887 203 732 896 610 492 960 422 44 255 442 448 426 697 862 351 318 277 783 22...
output:
mark 1 8 916
input:
1000 4793 417 206 539 243 977 260 678 534 954 877 14 340 329 6 731 340 832 196 956 718 871 722 840 903 500 615 378 232 167 490 280 834 884 342 375 107 552 492 754 241 395 694 357 53 43 772 932 658 199 420 879 863 144 359 952 731 636 538 706 744 141 380 338 312 402 890 402 697 838 117 562 980 69 972 ...
output:
ok
result:
ok all right
Test #19:
score: 0
Stage 1: Program answer Time Limit Exceeded
input:
1000 3724 513 194 958 159 936 285 493 34 668 957 824 152 450 421 92 170 416 782 546 100 698 433 299 741 261 975 661 408 4 927 789 856 52 784 541 618 99 780 527 957 618 74 440 321 839 496 360 484 71 21 149 302 25 505 240 587 584 736 490 934 817 867 682 287 882 528 985 852 201 46 254 112 862 582 379 3...