CT25567

The Secret First Repeat

EasyL3 · Syntax SurferAcceptance: 0.0%XP: 20

In the acacia flats of Thornveld, Trader the surveyor keeps careful count of the ingots. Compute the guild dues owed, every figure matters. Task: Read n integers and print the first value that appears twice (the value whose second occurrence has the smallest index). If all are distinct print -1. Input format: First line: n. Second line: n space-separated integers. Output format: Print the first repeated value, or -1. Constraints: 1 <= n <= 304; 0 <= a[i] <= 1000000; answers fit a signed 64-bit integer.

Example 1:

Input: 167 634873 570192 31285 400745 482661 987950 765790 249464 90461 63131 558352 343945 229603 713278 345432 325008 898663 60836 60083 231843 863286 3007 802562 222114 299023 697175 636383 773156 319377 172455 97217 89853 101912 69330 11308 44753 34783 992864 81664 162474 163344 258569 906217 68633 486360 875102 738874 49714 359876 847981 625162 403639 441218 990984 535253 326111 104551 873612 478406 30955 911929 85700 611463 112957 990087 579788 534413 155269 430923 269959 456435 10680 281720 10293 991518 931661 851895 968956 955732 587091 568891 655621 397537 619866 989706 258812 771575 101652 961642 102848 878989 224974 944575 538328 96779 155337 320823 703868 574115 455098 19241 863468 896585 377188 852975 506501 794553 659555 839412 525941 325937 998604 383445 534725 831020 728645 507122 509602 152338 862240 324375 537852 611462 456072 96008 350458 926623 287527 873412 251056 21087 40110 436706 220350 207357 465010 442240 722274 482670 3235 596492 935424 225538 73012 337948 753836 502234 810093 594119 476930 38666 109685 905294 39394 621600 616540 926623 689079 959568 597642 252440 195919 327165 216729 806957 449139 517803
Output: 926623

Example 2:

Input: 127 970481 608165 641312 728572 526416 692634 231827 638116 930636 566046 606352 708351 406454 549041 733001 918867 804063 478656 303788 159294 480390 171911 862183 843599 56440 246257 1270 198947 262142 503367 222477 700393 183856 207975 666979 789766 595530 779656 55280 543895 225772 388248 273171 249381 845483 862162 182402 612766 657067 170940 660858 471073 534306 23555 781338 651029 290220 692027 560545 150069 973253 54939 80597 71298 113246 982442 306621 115847 214662 483295 665101 689799 180906 595226 797414 626130 155204 731993 140091 350672 856668 968080 241438 447462 93146 19679 549041 121693 50566 409399 115060 76602 221155 887572 560913 932037 403207 36277 842962 483213 652189 820141 279858 796680 20994 319615 64172 461150 4475 554539 478208 627534 644727 302076 855330 131547 926658 79426 904348 785829 208764 226433 577968 990419 87414 882897 284055
Output: 549041

Example 3:

Input: 194 700775 591666 389834 193259 595217 200509 477578 775482 325920 484199 667491 2074 383129 564391 978435 813728 31743 767529 594082 352139 695685 528373 187098 934146 67552 324286 503261 149789 413354 81223 392338 434591 144173 556348 821032 673456 655463 913421 778925 480089 726706 935260 914199 226323 292823 373827 604093 670042 650397 863315 760914 553782 58168 683679 271320 411793 539396 337867 649207 122854 149690 470138 420970 954453 914670 913634 242501 466167 675539 62823 524325 728675 185946 152411 682975 472280 878771 583228 400421 538357 388325 513855 530001 218944 55895 904756 388633 196495 945649 783646 588620 703690 247315 656404 924021 703453 395873 71634 38228 193476 304397 478829 814849 964982 760482 251219 59156 418781 397295 732767 268387 504948 689388 888744 978383 149446 744627 633774 52724 218694 210574 794280 179898 435262 662674 172230 85883 137298 625697 111748 111407 464883 712659 690999 576372 267614 955271 834824 449901 593970 394102 502501 921832 317838 920061 971384 795103 744298 792596 596296 171960 232975 997554 726726 872493 485877 324407 902173 992840 498832 42397 785380 17213 461761 708994 31324 629414 104535 892107 297510 750893 200630 679527 388744 968192 161858 339385 680510 798384 760641 770603 716795 786613 7331 16035 901541 584210 846479 733016 670842 599105 365847 266191 116231
Output: -1

Constraints:

1 <= n <= 304; 0 <= a[i] <= 1000000; answers fit a signed 64-bit integer.

Loading...
Test Cases:No test cases
No test cases available.