Statistics

Problem Statement for "PubTrivia"

Problem Statement

You and your friends have gotten together for a Trivia night at the local pub. There are N questions asked during the night. Each question is worth a number of points; the i-th element of the points array corresponds to the score received if you correctly answer the i-th question, but you lose that many points if you answer it incorrectly. The questions are given in the order specified, and you must answer each question before the next is asked.

In addition, after each correct answer you will receive a token. If you then have tokensNeeded tokens, the pub will immediately take all of your tokens and award you additional bonus points. However, if you get the question wrong, the pub will take away all of your tokens without giving you any bonuses. The bonuses change after each question; element i of the bonuses array corresponds to the bonus you receive if you win the bonus on question i. Note that it is possible to receive multiple bonuses during the game.

To generate the arrays points and bonuses described above, you should use the following pseudo-code on the arrays p and b, respectively.

Input array:  X
Output array:  P (size N)
k := 0
M := size of X
For i=0 to N-1
	P[i] := X[k]
	s := (k+1)%M
	X[k] := ( ( X[k] ^ X[s] ) + 13 ) % G
	k := s

In the above code, use the value 1001 for G when generating points, and 10001 when generating bonus; this guarantees that all questions will be worth between 0 and 1000 points, inclusive, and that all bonuses will be worth between 0 and 10,000 points, inclusive. In the above code, % represents the modulo operator, and ^ is the binary XOR operator (see the Notes section for the implementation in your language).

You know the answer to all the questions and want to maximize the number of points that you receive. Return the maximum points that you can receive if you correctly choose which questions to answer.

Definition

Class:
PubTrivia
Method:
maximumScore
Parameters:
int, int, int[], int[]
Returns:
long
Method signature:
long maximumScore(int N, int tokensNeeded, int[] p, int[] b)
(be sure your method is public)

Notes

  • The input is only coded for convenience. The intended solution does not rely on any property of the number generation; it just generates both arrays and works on them.
  • If x and y are ints, (x^y) represents the bitwise XOR operation on them in C++, Java, and C#. In VB.net, (x BitXor y) does it.

Constraints

  • N will be between 1 and 500,000, inclusive.
  • tokensNeeded will be between 1 and 500,000, inclusive.
  • p and b will each contain between 1 and 50 elements, inclusive.
  • Each element of p will be between 0 and 1000, inclusive.
  • Each element of b will be between 0 and 10000, inclusive.

Examples

  1. 5

    5

    {1, 2, 3, 4, 5}

    {0, 0, 0, 2, 5}

    Returns: 20

    The best strategy here is to answer all five questions correctly. You score 15 points for the questions, and a 5 point bonus for answering five questions in a row.

  2. 5

    3

    {1, 2, 3, 4, 5}

    {0, 0, 0, 2, 5}

    Returns: 16

    This time, it is best to answer all of the questions correctly except for the second question. You then receive the bonus on the final question for answering three in a row.

  3. 5

    3

    {1, 2, 3}

    {7, 0}

    Returns: 98

    Here the question values are {1, 2, 3, 16, 14}, and the bonuses are {7, 0, 20, 33, 66}.

  4. 500000

    12

    {1, 34, 643, 293}

    {2938, 398, 103}

    Returns: 477926801

    Large test case, runs in 0.27 secs

  5. 4

    4

    {998, 1}

    {9998, 1}

    Returns: 1056

  6. 6

    8

    {1, 3, 6, 7, 2}

    {5}

    Returns: 34

  7. 10

    1

    {13}

    {13}

    Returns: 260

  8. 101

    2

    {13}

    {13}

    Returns: 1963

  9. 3257

    348

    {382, 238, 29, 192, 839, 999, 238, 328, 129, 129, 385, 234, 89}

    {21, 1291, 3289, 3257, 9029, 9999, 129, 1, 2489, 1902}

    Returns: 1635567

  10. 100000

    27

    {328, 389, 203, 908, 999, 382, 109, 90, 2, 35, 395, 98}

    {9283, 9023, 1209, 2901, 3982, 2398, 9238, 923, 12, 1389}

    Returns: 72717936

  11. 500000

    1

    {1000}

    {10000}

    Returns: 13010974

  12. 430887

    289384

    {992,1,521,220,380,729,969,184,887,104,641,909,378,724,582,387,583,241,294,159,198,653,369,418,692,36,901,516}

    {2472,9493,6170}

    Returns: 210367694

  13. 461394

    398168

    {464,219,183,648,796,287,979}

    {1758,6985,3337,524,3468,5048,4818,6568,8800,6957,3083,4871,8716,3733,1140,2504,3356,3612,3076,604,279,8484,1258,2479,1974,5461,5610,455,8945,8560,4389,1781,6623,7727,3385,1169,2774,8203}

    Returns: 225184733

  14. 393585

    195789

    {65,113,260,985}

    {8536,8988,3354,1611,671,3634,1174,1929,7192,4227,7390}

    Returns: 187285727

  15. 97468

    460379

    {763,216}

    {141,7877,4737,1311,1729,4018,126,4382,255,2025,1904,6287,7658,1646,4823,6645,5001,7513}

    Returns: 23441318

  16. 120710

    390676

    {494,577,572,5,659,259,120,421,165,194,637,577,39,900,472,4,724,577,157,304,486,261,249,312,592,411,874,397}

    {7549,9273,5245,6612,4343,5116,8476,4096,4559,2780,6157,3196,9384,6094,7649,6219,7761,7199,4259,3808,5926,4325}

    Returns: 58971508

  17. 316438

    452552

    {597,646,712,470,42,730,231,459,932,569,829,138,565,766,466,673,559,678,417,618,930,751,840,184,809,639,287,550,923}

    {9476,8957,2727,8050,3546,6246,465,5684,114,8126,5512,8327,3059,3815,1714,2552,4899,1258}

    Returns: 154691180

  18. 388465

    308543

    {575,336,860,760,835,498,737,384,110,78,925,320,755,176,690,784,848,981,653,140,840,659,262,954,812,850,431,523,495,16,233,70,352,92,520,877,280,256,260,390,24,185,400,780,51,89,253,900}

    {8249,6436,1354,662,4661,2886,6947,6517,394,3411,4692,4347,7850,2759,4665,3661,8255,3371,8052,7876,8972,5382,2497,940,3531,2687,7327,7122,6849,9676,2918,5098,6112,5351,6839,1851,8237,3785,9448,9711,8275,5218,5136,7203,7977}

    Returns: 189780406

  19. 455940

    229905

    {662,507,458,601,162,735,725,217,481,591,51,791}

    {2182,4473,512,7534,1311,2364,6849,6175,1811,6559,5529,7029,1695,2731,6084,2575,4674,2314,7905,5746,8578,2206,2200,6260,8526,3264,8786,2172,3608,7082,5495,5790,2633,6007,3323,5023,9450,172,1198,2339,7810,6727,446,583,536,6530,3158}

    Returns: 222886743

  20. 328203

    18945

    {898,830,795}

    {5839,3952,8579,4624,6125,2186,2785,2698,7976,5418,9784,2378,441,9234,3629,2718,1572,2517,523,2019,3101,1059,9628,6259,7349,9551,8401,9384,8051,3827,4697,4968,7780,3275,9592,4983,6540,3455,7681,5595,8874,7464,7973}

    Returns: 98383523

  21. 43922

    253415

    {209,464,467,916,814,40,625,105,820,496,54}

    {2503,1831,8943,7201,6799,7801,1554,7470,3862,8095,924,1542,3689,876,84,2740,1269,7861,5420,5459,9367,1695,9093,2891,9994,4865,6043,6708,9064,9825,1822,1567,1655,1843,9847,9534,9644,1400,8082,3505}

    Returns: 21450759

  22. 453827

    570

    {868,536,610,118,642,9,946,958,873,931,878,549,646,733,20,180,775,547,11,771,287,103,594,135,411,406,492,989,375,201,817,933,427}

    {1834,1213,1590,6413,1060,7185,2687,10000,5670,33,4883,1277,3008,8830,5629,8885,5422,3794,6604,1860,1492,5045,9699,8351,8071,9190,5294,7223,4022,3197,3663,5856,5489,6333,3347,6549,4596,7114,7628,266,7147}

    Returns: 227679327

  23. 436874

    490784

    {746,663,426,688,825,744,914,811,853}

    {4046,916,9667,9340,8139,3688,3615,2880,622,9105,9213,5048,6732,3809,2161,5438,5154,9309,9027,7776,542,2523,6026,660,1441,9150,8461,2219,4845,2384}

    Returns: 213272089

  24. 296158

    391522

    {139,672,692,81,507,968,84,589,398,835,944,744,331,234,931,906,99,906,691,89,234,592,768,386,927}

    {6762,1708,6419,5652,6088,9860,4960,9684,9146,8963,6160,9054,2068}

    Returns: 144762807

  25. 163951

    20128

    {813,796,688,744,701,787,339,81,566,573,363,333,650,980,382,379,783,327,432,724,722,155,47,577,386,27,827,206,406,601,659,219,86,346,963,787,823}

    {5723,4133,2758,6501,420,3419,8761,9353,1920,2728,4704,6074,3863,9915,6267,4681,5349,6500,1658,916,8802,1564,1572,3010,6053,5513,7637,3012,1321,8065,7026,7044,3276,9784,4623,3696,4281,3383,3049}

    Returns: 80371691

  26. 414640

    82196

    {977,395,60,537,919,860,484,159,486,326,116,92,518,983,95,747,501,264,798,321,301,928,395,948,469,374,875,185,636,173,22,612,568,82,149,176,633,323,335,118,339,142,901,858,124,686,604,626,951,91}

    {2311,8185,6798,1710,2025,223,5572,9995,929,5545,6794,6069,5492}

    Returns: 202404975

  27. 91172

    102748

    {481,505,395,289,844,537,189,391,351,876,685,667,826,466,994,767,174,716,345,352,501,799,405,923,424,480,956}

    {4893,5969,4260,7950,913,662,8893,5975,171,6463,2323,8875,7071,7683,8027,5213,1082,5912,7824,3744,1673,2144,7353,8737,2037}

    Returns: 44516807

  28. 473814

    311132

    {270,855,700,288,682,757,788,394}

    {8482,5806,5657,4944,8129,4531,2014,6890,3637,8306,9051,627,6129,2795,3379,8274,1226,2115,1389,5419,8846,8865,1086,1794,9428,2725,712,4251,2314,542,815,796,7427,6472,5740,6634,2082,8834}

    Returns: 231018469

  29. 197315

    294584

    {566,107,124,988,579,651,414,337,144,320,996,721,806,509,686,960,394,408,902,363,339,108,283,849,247,480,275}

    {5633}

    Returns: 96529106

  30. 363828

    9098

    {494,133,211,763,784,315,99,618,635,786,28,130,985,715,90,68,122,992,431,152,99,404,0,36,575,275,899}

    {8507,5565,9111,6201,9190,7003,4698,7592,5805,6113,2160,8780,2528,1761,9169,3580,7979,777,1059,5063,3762,6588,3830,1076,6512,1830,8461,8546,2224,6905,7292,1809,2469,6402,8010,2737,4483,2707,1407,288,9900,4646,146,2427,6407,9315,7087,5464,1171}

    Returns: 177504109

  31. 224791

    476365

    {14,536,296,465,756,21,799,249,645,365,786,485,78,476}

    {1203,3096,1223,1491,4074,6948,2716,6501,3355,3110,4666,9898,4281,3891,424,292}

    Returns: 109542637

  32. 273680

    39876

    {290,38,443,780,978,87,835,763,262,913,930,317,371,394,456,572,554,811,825,281,230,256,744,970,776,555,26,902,380,1000,324,361,37,457,140,705,545,975,158,497,578,87}

    {4574,1852,8537,3676,7643,3300,5495,1012,2497,423,9049,1592,9633,3133,1111,213,6921,7570,7096,7050,8234,143,3311,3672}

    Returns: 133897988

  33. 125384

    474977

    {241,807,123,746,445,294,86,346,709,238,70,715,309,432,153,350,568,147,107,606}

    {3423,3804,5216,2735,3948,9606,6408,4679,8865,2672,1696,6166,9073,9435,197,7324,5710,7906,3218,5285,2188,1203,8436,6894,8237,2100,3389,9483,7954,9020,7649,2456,3902,3943}

    Returns: 61297622

  34. 128790

    27584

    {424,270,711,997,802,17,692,79,769,371,443,867,760,735,725,553,335,705,190,977,252,974,35,96,659,648,599,669,226,648,570,341,918,971,337,410,988,719,489,446,89}

    {9499,7499,4858,1604,4743,1183,603,1303,1767,4071,7347,304,6557,1038,1297}

    Returns: 62694836

  35. 381520

    339644

    {407,914,678,14,574,705,424,561,423,603,7,203,224,9,743,270,737,215,342,858,569,80,231,896,854,392,881,274,150,224,611,247,829,289,953,402,994,376,654,417,670,351,310}

    {7764,1465,4969,3492,9742,1306,9825,400,1568,226,8406,1055,8265,8528,1839,1406,9481,2261,4967,4604,9026,1109,2888,9580,7299,5139,2554,6817,9858}

    Returns: 185941712

  36. 86318

    99485

    {216,862,668,864,438,312,80,94,188,501,604,145,183}

    {2992,1742,2865,9039,6346,2969,1226,312,2548,9604}

    Returns: 42250174

  37. 403567

    406528

    {651,610,411,842,516,272,200,380,711,512,460,805,390,651,99,536,524,176,479,613,28,468,126,254,765,777,226,124,597}

    {6722,6186,3414,1930,1274,4188,9817,8555,6653,3845,7851,4446,3426,1548,5973,1771,5753,9763,1798,5107,5293,5770,3500,8249,1631,3119,2595,2198,3420,2393,8947,141,9658,3440,3150,931,7628,4046,9486}

    Returns: 197147994

  38. 10636

    463954

    {574,858,515,313,753,312,577,515,588,454,305,22,147,39,221,617,1000,545,373,704,776,376,70,326,850,997,777,611,171,528,244,745,76,449,748,519,451,15,33,730,159,338,752,306,377,974}

    {3302,1102,656,2127,6420,7618,4392,5967,5511,4284,638,3969,9535,2122,1920,5668,7080,9836,8657,6203}

    Returns: 5219524

  39. 63180

    476506

    {766,434,651,208,430,28,181,42,786,389,718,246,62,770,467,62,670,684,838,562,762,832,699,274,902,284,224,181,10,500,804,467,624,454,675,54,172,546,96,958,625,505,203}

    {7756}

    Returns: 30664558

  40. 438330

    102409

    {734,968,887,495,799,585,459,391,559,684,572,569,874,375,726,187,519,400,241,382,636,28,339,260,533,233,638,497,283,76,821,17,43,707,512,533,291,662,924,540,35,185,800,599,250,525,786,769,616,27}

    {3935,4034,8664,9081}

    Returns: 213733704

  41. 349811

    39808

    {465,386,916,976,403,960,683,606,182,664,958,796,204,993,981,3,591,230,218,66,689,834,784,840,85,529,710,597,497,503,746,652,889,661,318}

    {7400,7946,415,4828,824,3598,1987,1801,1734,8316,7164,7083,6111,1848,5918,4038}

    Returns: 170898382

  42. 1

    2

    {0, 323, 35, 239, 358, 3}

    {0, 238, 23}

    Returns: 0

    Minimal return

  43. 500000

    1

    {1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, 1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, 1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, 1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, 1000,1000,1000,1000,1000,1000,1000,1000,1000,1000}

    {10000,10000,10000,10000,10000,10000,10000,10000,10000,10000, 10000,10000,10000,10000,10000,10000,10000,10000,10000,10000, 10000,10000,10000,10000,10000,10000,10000,10000,10000,10000, 10000,10000,10000,10000,10000,10000,10000,10000,10000,10000, 10000,10000,10000,10000,10000,10000,10000,10000,10000,10000}

    Returns: 2277323685

    Long required return value

  44. 500000

    1

    {1000,999,1000,998,1000,997,1000,999,1000,998, 1000,999,1000,998,1000,997,1000,999,1000,998, 1000,999,1000,998,1000,997,1000,999,1000,998, 1000,999,1000,998,1000,997,1000,999,1000,998, 1000,999,1000,998,1000,997,1000,999,1000,998}

    {10000,9999,10000,9998,10000,9997,10000,9999,10000,9997, 10000,9999,10000,9998,10000,9997,10000,9999,10000,9997, 10000,9999,10000,9998,10000,9997,10000,9999,10000,9997, 10000,9999,10000,9998,10000,9997,10000,9999,10000,9997, 10000,9999,10000,9998,10000,9997,10000,9999,10000,9997}

    Returns: 2290771387

    Long required return value

  45. 50

    10

    {1, 1, 1, 1, 1, 1, 1, 1, 1, 800, 1, 1, 2, 2, 2, 2,2, 2, 2,2, 2, 3, 4, 3, 4, 4, 3, 3, 3, 2, 6, 5, 4, 2, 3, 1,5, 2,2, 3, 1, 0, 7, 9, 7, 2, 1, 3, 4, 8}

    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1500, 0, 0, 0, 0, 0, 0, 0, 0, 1900, 0, 0, 0, 0, 0, 0, 0, 3100, 0, 0, 0, 0, 0, 0, 5000, 0, 0, 0, 1500}

    Returns: 7823

  46. 357

    10

    {1, 1, 1, 1, 1, 1, 1, 1, 1, 800, 1, 1, 2, 2, 2, 2,2, 2, 2,2, 2, 3, 4, 3, 4, 4, 3, 3, 3, 2, 6, 5, 4, 2, 3, 1,5, 2,2, 3, 1, 0, 7, 9, 7, 2, 1, 3, 4, 8}

    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1500, 0, 0, 0, 0, 0, 0, 0, 0, 1900, 0, 0, 0, 0, 0, 0, 0, 3100, 0, 0, 0, 0, 0, 0, 5000, 0, 0, 0, 1500}

    Returns: 99237

  47. 3

    2

    {1, 2, 3}

    {1, 4, 7}

    Returns: 11

  48. 3

    2

    {13}

    {13}

    Returns: 52

  49. 500000

    1

    {96,998,883,966,834,258,615,706,110,752,917,963,212,884,153,50,910,565,774,67,547,179,698,127,552,656,297,46,901,953,875,37,535,683,469,785,679,230,206,762,751,483,206,708,764,889,387,283,490,725}

    {2879,5906,838,9833,796,4802,3494,6131,9763,3180,9581,9576,9617,3645,5779,9433,9371,9009,7517,973,1124,1769,6472,5112,226,3587,2145,1836,8941,6861,7760,8211,8972,2311,6120,9237,1948,1644,8506,3842,7778,5031,9919,2732,5261,4915,6004,5060,6394,9575}

    Returns: 2298441919

  50. 500000

    2

    {913,686,522,988,618,394,164,691,106,653,966,8,965,35,746,812,76,511,622,722,474,523,779,81,410,468,262,696,217,318,480,106,691,498,396,760,482,157,106,175,700,588,886,912,711,332,442,36,552,564}

    {5314,557,5808,8854,8297,5833,3898,2421,921,2829,7059,4185,7213,6073,3848,8446,9703,7795,7151,7669,3542,5194,9598,3628,1882,7657,1137,5884,6068,7907,408,7199,6949,9186,5840,1686,1914,453,1759,8929,8124,388,8510,328,452,8211,2698,4104,6178,3850}

    Returns: 1417699059

  51. 500000

    7

    {573,339,523,394,709,761,764,719,921,456,206,672,507,911,451,693,795,520,604,971,188,693,137,482,725,194,791,417,593,656,476,283,255,426,413,862,572,102,831,940,503,981,207,698,503,202,114,12,189,257}

    {4231,3565,6425,6605,8123,6513,9932,2598,7119,9171,3005,2129,3330,6577,7631,1759,3406,5347,4511,6176,4066,4098,1459,183,7180,8507,1438,9953,7484,5815,8122,9437,8266,8042,7710,7625,892,6368,5820,9856,6373,244,8617,7467,7259,365,4532,3318,1748,5625}

    Returns: 648301783

  52. 500000

    8

    {212,817,434,8,711,877,570,16,922,731,343,476,707,841,536,766,548,877,152,266,706,993,567,810,379,741,416,59,205,419,970,879,894,417,313,67,501,648,544,352,205,150,798,273,999,914,494,536,725,6}

    {5639,8253,855,5032,5575,6676,9946,9951,2295,6695,5681,3020,6863,7002,9295,957,7320,1084,792,2811,7456,422,9878,3652,5521,42,5001,4911,7273,4428,3416,7503,3361,4603,5988,1484,3482,6871,8185,5703,9966,7703,9021,1463,5445,7698,5941,6719,4385,8398}

    Returns: 603597108

  53. 500000

    29

    {630,675,721,31,145,540,549,785,927,257,479,111,785,2,827,934,451,277,836,418,102,765,227,370,776,440,721,517,795,722,9,893,595,303,247,44,622,390,826,956,776,965,521,541,884,996,673,888,234,463}

    {9895,6809,6290,1342,5831,5032,4689,2405,509,3642,9833,5346,7719,573,9373,9325,5272,9170,5937,3833,58,9353,2019,2330,9082,5715,9249,5393,5783,2092,1048,8845,2726,5920,3044,1842,9390,5562,479,5074,6049,1858,6225,8090,9641,2083,6070,1199,4233,4946}

    Returns: 356354792

  54. 500000

    50

    {259,439,100,433,627,248,694,412,707,933,720,878,115,442,24,877,743,98,950,670,38,776,179,313,191,145,162,409,295,841,204,685,309,446,147,502,4,39,952,162,938,46,527,636,549,257,341,268,7,936}

    {6071,126,6536,6546,6879,5045,7772,9016,2317,8006,7573,245,3993,5224,5459,5418,9543,7038,3704,9633,6245,8634,3796,7790,2727,1707,1609,6024,8033,5861,5266,5202,5161,69,5656,7426,9907,6045,45,8791,1216,8735,3506,8319,8243,5949,6828,7454,6848,4300}

    Returns: 311922440

  55. 500000

    123

    {469,122,633,967,676,712,175,560,959,361,682,650,877,76,366,171,932,847,707,596,1000,873,866,63,761,661,650,683,601,126,324,749,330,977,654,461,530,17,733,265,191,389,758,987,757,773,597,353,556,5}

    {4561,2062,2658,8431,3602,9711,547,7709,4346,5043,23,8904,857,7372,4274,6790,4885,159,3817,1226,3454,9694,3048,6622,1267,3831,2360,4857,3687,2293,1842,484,5427,4206,6158,8302,3284,1911,4127,7108,3247,3951,7617,9714,4038,6442,2326,2905,8247,5481}

    Returns: 272884240

  56. 500000

    146

    {301,748,713,763,881,898,324,453,484,419,636,725,613,164,239,936,614,462,39,606,248,754,953,698,753,376,215,942,238,356,747,642,750,470,950,975,738,548,894,121,611,411,725,385,976,734,230,751,217,25}

    {8749,2732,6983,783,7763,8150,7622,6194,483,7714,3803,4102,3977,1468,768,5513,6790,2635,4014,7463,5642,3360,2145,4266,8131,86,4124,2454,1650,5896,9,5714,146,8015,3521,6702,9791,2976,6693,9698,5408,4577,1783,8145,117,8225,1354,2815,6897,7958}

    Returns: 268256888

  57. 500000

    343

    {852,155,195,137,36,764,528,782,690,378,931,184,633,514,338,949,789,766,279,608,689,750,974,716,486,397,345,499,965,958,759,690,85,419,101,582,854,528,533,431,811,635,868,658,885,663,711,719,555,555}

    {5733,2072,9951,5396,1363,8506,3615,4177,8223,4437,237,3952,5431,6491,2379,513,8606,3662,9924,6536,2116,2938,3236,8386,5504,3652,3169,5278,7217,9775,5062,4669,1685,3936,4277,9322,1203,8195,248,5324,6031,7774,9889,2709,6339,4853,1257,2504,6293,382}

    Returns: 255354955

  58. 500000

    551

    {383,56,782,411,950,104,385,126,23,289,14,359,465,984,185,990,831,725,858,791,66,0,714,258,56,538,388,648,41,494,779,219,457,927,361,383,443,314,210,384,693,578,415,369,357,695,154,912,786,717}

    {8068,1215,8119,39,981,5889,9671,3903,743,1779,9887,5447,38,9810,3260,2468,3963,7352,7591,1859,8510,2817,6994,7299,1879,2184,8122,478,3316,7294,2136,2840,9227,4364,5162,4499,7413,2938,1751,972,3406,1462,6252,8519,8917,8809,4248,7911,9766,8597}

    Returns: 251465285

  59. 500000

    1523

    {815,652,725,554,405,827,33,386,658,836,471,961,315,600,391,234,19,602,326,566,79,100,168,302,893,503,660,758,532,730,823,76,652,962,530,361,680,555,230,697,874,962,470,917,563,535,377,598,177,99}

    {7159,9283,8250,940,6771,4968,6697,2684,9178,1822,9947,9599,4893,718,7268,7634,3902,188,5937,3810,3314,8066,4549,8766,9610,4748,8924,8591,1374,3392,7769,4613,6971,5652,8712,8924,6224,9611,4260,6781,2379,1460,5946,6397,2375,3796,2290,2888,8595,5642}

    Returns: 246482574

  60. 500000

    2120

    {451,53,723,793,617,640,73,271,29,131,396,22,915,170,479,712,277,562,399,745,452,273,817,901,484,286,703,16,956,129,471,832,755,180,113,216,487,242,983,964,552,982,445,869,63,92,127,427,457,176}

    {5545,5932,5714,2529,8990,5466,1635,5126,8370,9351,6948,56,7326,2429,1073,2669,198,6540,8915,4526,5831,8414,6460,4785,2926,4639,59,4554,8473,9979,3392,8310,5677,3263,6335,7070,3579,1616,6285,1091,643,2425,369,5102,7129,2624,1481,7948,3045,2544}

    Returns: 245913402

  61. 500000

    7126

    {560,387,245,209,578,401,947,759,533,837,888,679,628,62,486,148,452,301,596,392,460,491,620,404,40,961,123,461,156,857,278,328,36,890,916,238,732,464,469,69,375,152,234,669,240,986,195,277,677,473}

    {6824,1732,4808,5407,8755,5211,1166,5781,3321,2870,398,9213,7067,3918,3440,1702,4777,8626,4380,9616,5654,6619,9139,5998,1521,2493,1253,6191,5242,1076,7727,5130,8525,2542,545,4228,3266,522,5898,5873,1284,5050,8265,6305,4473,579,322,1734,8029,4189}

    Returns: 244829485

  62. 500000

    8727

    {989,897,258,435,670,402,395,680,986,899,475,90,321,22,103,569,826,767,159,517,718,283,541,269,878,618,409,636,286,720,283,965,479,414,385,741,96,566,870,760,130,65,385,613,792,688,494,109,452,124}

    {6956,9630,8599,4095,9747,4169,6113,8984,6904,4679,9653,4815,336,6388,9125,690,5421,137,5821,7712,1940,1344,3484,1392,1322,1889,8989,5361,7358,6566,8529,5254,2058,3541,2847,2500,9411,8018,9868,4568,7993,2705,7128,8037,7467,7365,2805,5271,104,3647}

    Returns: 244613818

  63. 500000

    20265

    {681,934,40,618,497,508,697,658,11,447,721,942,998,983,944,825,865,703,16,282,431,580,829,753,141,395,708,932,984,794,199,727,953,211,551,638,755,89,607,405,277,74,439,905,455,237,298,397,127,296}

    {1660,2967,2068,8465,1663,5690,483,9964,6581,8348,960,5802,4565,5326,3692,2177,6298,4389,1487,7281,2081,7630,3066,6328,4584,1865,1040,5537,4793,5465,3791,308,602,3098,4038,1089,1152,3424,4808,5130,6710,5536,6680,9800,2822,8668,1529,7463,1455,3695}

    Returns: 244626042

  64. 500000

    51768

    {258,233,720,360,378,727,154,806,147,623,494,399,56,374,826,502,800,336,333,486,348,934,710,233,302,240,231,184,430,762,325,489,172,905,443,436,365,250,438,549,690,197,26,871,466,335,760,515,615,669}

    {9388,9494,4372,9405,3736,2728,8896,8082,4320,998,1982,9634,4133,8967,2797,9117,4492,2601,9823,9420,3668,1203,6158,5337,1735,4770,2984,3339,6680,619,2181,9709,9334,5815,3021,5029,3283,8110,827,7078,1560,6505,3082,2048,403,3522,511,8007,6911,6473}

    Returns: 244455169

  65. 500000

    127624

    {440,320,714,376,689,416,220,418,853,776,114,659,488,466,251,77,22,690,798,105,163,371,589,863,586,289,643,240,179,200,787,192,460,234,724,598,426,921,850,452,583,789,320,988,745,848,989,175,818,552}

    {1726,3347,3382,6715,3116,3748,4996,8685,8810,4162,8263,5265,8371,3236,9775,8047,9574,4113,4322,2444,7645,1627,8491,4844,1673,4102,7693,2394,8934,6974,8730,9245,4941,2423,3025,1155,2470,8543,9364,418,1002,4239,7447,9572,3233,212,1432,5683,3462,6380}

    Returns: 244183331

  66. 500000

    132319

    {381,205,609,348,767,112,844,866,743,602,810,864,46,83,373,883,847,579,413,448,413,817,813,230,972,992,23,640,118,734,550,174,628,138,183,983,424,542,403,442,578,767,486,898,400,434,160,737,381,66}

    {5278,8184,879,9771,9364,3951,2004,5063,5479,8887,58,8479,2684,3570,1297,4461,2970,1446,9903,6542,4158,1139,1288,5833,3191,2313,2868,2918,3954,3848,4275,2929,5586,3792,8206,6178,6555,4369,3160,509,5845,3840,9502,125,3035,779,4979,5250,6089,5307}

    Returns: 243880732

  67. 500000

    348848

    {1000,164,672,78,322,546,147,218,711,572,406,910,131,410,988,642,673,665,641,203,309,712,300,427,863,18,793,696,897,714,704,831,50,20,986,154,895,432,554,189,372,317,135,38,903,787,305,605,277,813}

    {1345,3429,7489,5608,2837,1720,5942,9158,866,5828,5226,2504,4399,8485,2635,3023,5529,5902,3813,3900,9046,6233,4918,6726,3610,6381,7150,6996,7070,6854,2,6739,7235,5854,51,8028,332,9380,4846,9070,5261,5377,2757,7743,6508,3585,7894,6345,977,7494}

    Returns: 244472906

  68. 500000

    500000

    {860,138,431,730,150,212,647,857,555,443,99,911,981,93,434,50,586,695,557,623,269,506,362,964,639,935,501,926,134,745,386,975,97,703,257,43,127,542,36,453,183,693,365,501,947,532,772,395,480,674}

    {226,3683,7863,3297,5015,760,2796,8954,3783,1263,6497,8181,423,7064,6554,1810,6431,934,9608,3808,3339,5238,9660,9057,8706,6935,436,9946,3478,4375,5361,5600,8563,8893,3386,2560,2046,5744,1216,729,4230,6038,3451,4841,2985,947,3373,2425,6605,5902}

    Returns: 244184375

  69. 10

    4

    {998, 1}

    {9998, 1}

    Returns: 1695

  70. 500000

    399999

    {590, 575, 84, 781, 474, 899, 952, 185, 886, 847, 308, 821, 866, 851, 288, 321, 366, 519, 52, 29, 722, 115, 72, 521, 398, 615, 964, 101, 706, 315, 152, 281, 622, 415, 740, 685, 122, 779, 104, 865, 566, 759, 524, 213, 834, 651, 592, 65, 54, 247 }

    {2212, 5757, 2146, 3827, 7728, 2265, 3262, 7983, 3180, 4245, 1754, 155, 1816, 2753, 3862, 9159, 6676, 2461, 5714, 8403, 8096, 6761, 7518, 2479, 8044, 8293, 1130, 6251, 1688, 1569, 2118, 1943, 9796, 7821, 6562, 7347, 1552, 6985, 8302, 655, 6924, 9653, 3098, 5035, 4392, 7425, 2838, 7639, 4116, 3805 }

    Returns: 244053039

  71. 499999

    85000

    {1, 3, 67, 8, 1 }

    {5, 12, 4, 1, 2, 5, 700 }

    Returns: 232978165

  72. 500000

    8641

    {414, 999, 313, 5, 0, 1000, 123, 312, 461, 777, 11, 12, 13, 14, 921, 998, 126, 126, 345, 411, 414, 999, 313, 5, 0, 1000, 123, 312, 461, 777, 11, 12, 13, 14, 921, 998, 126, 126, 345, 411, 414, 999, 313, 5, 0, 1000, 123, 312, 461 }

    {414, 999, 3213, 5, 0, 1000, 123, 312, 0, 7775, 11, 1000, 13, 14, 921, 998, 0, 1226, 3445, 411, 414, 999, 3113, 10000, 0, 1000, 123, 312, 0, 7177 }

    Returns: 244470026

  73. 500000

    2

    {10, 100, 45, 76, 2, 67, 77, 888, 543, 1, 456, 22, 345, 999, 0, 0, 0, 345, 657, 123, 345, 12, 23, 676, 987, 123, 456, 789, 335, 662, 5, 6, 7, 8, 9, 45, 56, 67, 78, 89, 90, 123, 543, 676, 987, 443, 221, 938, 467 }

    {345, 3453, 6575, 1234, 564, 55, 6757, 6754, 8888, 6665, 90, 8, 4522, 3423, 5678, 3232, 222, 1234, 55, 2342, 9999, 6784, 5466, 88, 980, 5, 4512, 3478, 111, 1111, 9090, 8643, 4568, 56, 32, 1235, 7631 }

    Returns: 1416815892

  74. 9

    2

    {1, 2, 3, 4, 5, 7, 8, 9, 10 }

    {2, 2, 2, 2, 2, 2, 100, 2, 2 }

    Returns: 153

  75. 500000

    3

    {1, 2, 3, 4, 5 }

    {0, 0, 0, 2, 5 }

    Returns: 1050382441

  76. 500000

    499995

    {12, 3, 2, 2, 3 }

    {3, 2, 23, 3, 1 }

    Returns: 238324223

  77. 7

    2

    {10, 10, 10, 10, 10, 10, 10 }

    {0, 100, 0, 100, 0, 100, 0 }

    Returns: 370

  78. 500000

    11781

    {903, 301, 3, 2, 1, 452, 432, 31, 2, 3, 4, 5 }

    {89, 399, 193, 4, 13, 4, 15, 52, 31, 256, 432 }

    Returns: 243946067

  79. 500000

    5

    {1, 2, 3, 4, 5 }

    {0, 0, 0, 2, 5 }

    Returns: 795737340

  80. 3

    1

    {1, 2, 3 }

    {1, 2, 3 }

    Returns: 12

  81. 500000

    250000

    {1, 2, 3 }

    {7, 0 }

    Returns: 185970068

  82. 6

    3

    {5, 5, 5, 5, 4, 3 }

    {0, 0, 7, 1, 1, 9 }

    Returns: 43

  83. 500000

    1

    {998, 1 }

    {9998, 1 }

    Returns: 2547909750

  84. 50000

    1234

    {649, 885, 512, 14, 687, 285, 614, 744, 628, 89, 886, 645, 669, 240, 793, 279, 909, 695, 289, 617, 471, 356, 651, 434, 720, 184, 567, 236, 705, 754, 181, 802, 360, 920, 472, 24, 823, 230, 17, 82, 183, 927, 130, 290, 992, 418, 67, 986, 789, 174 }

    {2804, 2575, 440, 6112, 5913, 8178, 3673, 2705, 377, 5455, 9595, 2356, 5029, 1029, 1573, 9938, 5397, 2522, 58, 9060, 926, 9527, 7598, 8735, 6067, 6564, 7460, 8448, 1090, 2576, 7549, 8372, 4275, 638, 1550, 1283, 5747, 3890, 1162, 8299, 1221, 3327, 7059, 5154, 8300, 2154, 3093, 9019, 7779, 3400 }

    Returns: 24660431

  85. 113876

    474255

    {341, 585, 630, 977 }

    {6801, 3339, 9947, 7671 }

    Returns: 53652030

  86. 10

    1

    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }

    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }

    Returns: 20

  87. 500000

    500000

    {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }

    {10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }

    Returns: 244470487

  88. 5

    3

    {1, 2, 3, 4, 5 }

    {0, 0, 0, 2, 5 }

    Returns: 16

  89. 500000

    3

    {1000, 1, 1, 1, 1, 1, 1 }

    {0, 0, 0, 0, 0, 100 }

    Returns: 1070272674


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: