{"problem": "In a certain video game, the player controls a hero characterized by a single integer value: power. The hero will have to beat monsters that are also characterized by a single integer value: armor.\n\nOn the current level, the hero is facing n caves. To pass the level, the hero must enter all the caves in some order, each cave exactly once, and exit every cave safe and sound. When the hero enters cave i, he will have to fight k_i monsters in a row: first a monster with armor a_{i, 1}, then a monster with armor a_{i, 2} and so on, finally, a monster with armor a_{i, k_i}.\n\nThe hero can beat a monster if and only if the hero's power is strictly greater than the monster's armor. If the hero can't beat the monster he's fighting, the game ends and the player loses. Note that once the hero enters a cave, he can't exit it before he fights all the monsters in it, strictly in the given order.\n\nEach time the hero beats a monster, the hero's power increases by 1.\n\nFind the smallest possible power the hero must start the level with to be able to enter all the caves in some order and beat all the monsters.\n\nInput\n\nEach test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^5). Description of the test cases follows.\n\nThe first line of each test case contains a single integer n (1 ≤ n ≤ 10^5) — the number of caves.\n\nThe i-th of the next n lines contains an integer k_i (1 ≤ k_i ≤ 10^5) — the number of monsters in the i-th cave, followed by k_i integers a_{i, 1}, a_{i, 2}, …, a_{i, k_i} (1 ≤ a_{i, j} ≤ 10^9) — armor levels of the monsters in cave i in order the hero has to fight them.\n\nIt is guaranteed that the sum of k_i over all test cases does not exceed 10^5.\n\nOutput\n\nFor each test case print a single integer — the smallest possible power the hero must start the level with to be able to enter all the caves in some order and beat all the monsters.\n\nExample\n\nInput\n\n\n2\n1\n1 42\n2\n3 10 15 8\n2 12 11\n\n\nOutput\n\n\n43\n13\n\nNote\n\nIn the first test case, the hero has to beat a single monster with armor 42, it's enough to have power 43 to achieve that.\n\nIn the second test case, the hero can pass the level with initial power 13 as follows: \n\n * enter cave 2: \n * beat a monster with armor 12, power increases to 14; \n * beat a monster with armor 11, power increases to 15; \n * enter cave 1: \n * beat a monster with armor 10, power increases to 16; \n * beat a monster with armor 15, power increases to 17; \n * beat a monster with armor 8, power increases to 18. ", "test_cases": {"inputs": ["2\n1\n1 42\n2\n3 10 15 8\n2 12 11\n", "2\n1\n1 42\n2\n3 10 15 1\n2 12 11\n", "2\n1\n1 20\n2\n3 10 15 8\n2 12 11\n", "2\n1\n1 42\n2\n3 1 15 8\n2 12 19\n", "2\n1\n1 42\n2\n3 19 15 0\n2 12 11\n", "2\n1\n1 42\n2\n3 13 15 0\n2 12 16\n", "2\n1\n1 41\n2\n3 1 15 8\n2 12 19\n", "2\n1\n1 42\n2\n3 10 16 0\n2 12 11\n", "2\n1\n1 42\n2\n3 13 24 0\n2 12 16\n", "2\n1\n1 41\n1\n3 1 15 8\n2 12 19\n", "2\n1\n1 42\n2\n3 13 24 0\n2 12 26\n", "2\n1\n1 15\n2\n3 1 15 8\n2 12 19\n", "2\n1\n1 41\n2\n3 1 15 8\n2 12 29\n", "2\n1\n1 42\n2\n3 1 19 6\n2 12 11\n", "2\n1\n1 84\n2\n3 19 16 0\n2 12 11\n", "2\n1\n1 84\n2\n3 19 16 0\n2 21 11\n", "2\n1\n1 84\n2\n3 1 16 0\n2 21 11\n", "2\n1\n1 15\n2\n3 2 15 8\n2 31 19\n", "2\n1\n1 42\n2\n3 10 15 1\n2 21 11\n", "2\n1\n1 14\n2\n3 1 15 8\n2 12 19\n", "2\n1\n1 39\n1\n3 1 15 8\n2 12 19\n", "2\n1\n1 41\n2\n3 1 15 8\n2 12 0\n", "2\n1\n1 15\n2\n3 1 18 8\n2 13 19\n", "2\n1\n1 84\n2\n3 1 16 0\n2 14 11\n", "2\n1\n1 14\n2\n3 1 22 8\n2 12 19\n", "2\n1\n1 15\n2\n3 1 18 8\n2 13 33\n", "2\n1\n1 9\n2\n3 2 9 8\n2 13 19\n", "2\n1\n1 24\n2\n3 2 15 1\n2 12 19\n", "2\n1\n1 2\n2\n3 1 22 8\n2 12 19\n", "2\n1\n1 75\n2\n3 13 24 0\n2 12 0\n", "2\n1\n1 24\n2\n3 2 15 1\n2 12 15\n", "2\n1\n1 41\n2\n3 1 15 20\n2 12 1\n", "2\n1\n1 16\n2\n3 0 15 2\n2 6 15\n", "2\n1\n1 16\n2\n3 0 15 2\n2 6 13\n", "2\n1\n1 35\n2\n3 13 15 0\n2 12 11\n", "2\n1\n1 42\n2\n3 1 15 8\n2 12 31\n", "2\n1\n1 42\n2\n3 24 24 0\n2 12 16\n", "2\n1\n1 5\n2\n3 1 15 6\n2 12 11\n", "2\n1\n1 80\n2\n3 10 15 0\n2 12 5\n", "2\n1\n1 15\n2\n3 2 15 8\n2 13 15\n", "2\n1\n1 84\n2\n3 19 16 0\n2 32 11\n", "2\n1\n1 30\n2\n3 10 15 1\n2 21 11\n", "2\n1\n1 45\n1\n3 10 15 0\n2 12 11\n", "2\n1\n1 42\n2\n3 1 15 1\n2 12 35\n", "2\n1\n1 14\n2\n3 1 18 8\n2 12 19\n", "2\n1\n1 42\n2\n3 10 16 0\n2 27 11\n", "2\n1\n1 70\n2\n3 1 24 6\n2 12 11\n", "2\n1\n1 146\n2\n3 19 16 0\n2 21 2\n", "2\n1\n1 15\n2\n3 1 22 8\n2 18 19\n", "2\n1\n1 15\n2\n3 2 14 0\n2 43 19\n"], "outputs": ["43\n13\n", "43\n13\n", "21\n13\n", "43\n16\n", "43\n18\n", "43\n15\n", "42\n16\n", "43\n14\n", "43\n22\n", "42\n15\n", "43\n24\n", "16\n16\n", "42\n26\n", "43\n17\n", "85\n18\n", "85\n20\n", "85\n19\n", "16\n29\n", "43\n19\n", "15\n16\n", "40\n15\n", "42\n13\n", "16\n18\n", "85\n15\n", "15\n20\n", "16\n30\n", "10\n16\n", "25\n16\n", "3\n20\n", "76\n22\n", "25\n15\n", "42\n17\n", "17\n15\n", "17\n13\n", "36\n13\n", "43\n28\n", "43\n23\n", "6\n13\n", "81\n13\n", "16\n15\n", "85\n30\n", "31\n19\n", "46\n15\n", "43\n32\n", "15\n18\n", "43\n25\n", "71\n22\n", "147\n20\n", "16\n20\n", "16\n41\n"]}, "starter_code": "", "problem_sha1": "1e5f32074cfd43ac81c4a873c724e29b516b6c5e", "n_test_cases_total": 201, "n_test_cases_kept": 50, "test_cases_truncated": true, "seed_id": "cc-06489", "original_id": null, "source": "code_contests", "domain": "code", "test_case_format": "stdin_stdout", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": null} {"problem": "You are given two positive integers n and s. Find the maximum possible median of an array of n non-negative integers (not necessarily distinct), such that the sum of its elements is equal to s.\n\nA median of an array of integers of length m is the number standing on the ⌈ {m/2} ⌉-th (rounding up) position in the non-decreasing ordering of its elements. Positions are numbered starting from 1. For example, a median of the array [20,40,20,50,50,30] is the ⌈ m/2 ⌉-th element of [20,20,30,40,50,50], so it is 30. There exist other definitions of the median, but in this problem we use the described definition.\n\nInput\n\nThe input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.\n\nEach test case contains a single line with two integers n and s (1 ≤ n, s ≤ 10^9) — the length of the array and the required sum of the elements.\n\nOutput\n\nFor each test case print a single integer — the maximum possible median.\n\nExample\n\nInput\n\n\n8\n1 5\n2 5\n3 5\n2 1\n7 17\n4 14\n1 1000000000\n1000000000 1\n\n\nOutput\n\n\n5\n2\n2\n0\n4\n4\n1000000000\n0\n\nNote\n\nPossible arrays for the first three test cases (in each array the median is underlined):\n\n * In the first test case [\\underline{5}] \n * In the second test case [\\underline{2}, 3] \n * In the third test case [1, \\underline{2}, 2] ", "test_cases": {"inputs": ["8\n1 5\n2 5\n3 5\n2 1\n7 17\n4 14\n1 1000000000\n1000000000 1\n", "8\n1 5\n2 5\n3 5\n2 1\n14 17\n4 14\n1 1000000000\n1000000000 1\n", "8\n1 5\n2 5\n3 5\n2 1\n14 17\n4 14\n1 1010000000\n1000000000 1\n", "8\n1 5\n1 5\n3 5\n2 1\n14 17\n4 14\n1 1010000000\n1000100000 1\n", "8\n1 5\n1 9\n3 5\n2 1\n14 17\n4 14\n1 1010000000\n1000100000 1\n", "8\n1 5\n1 9\n3 5\n2 1\n14 17\n4 14\n1 1010001000\n1000100000 1\n", "8\n1 5\n1 9\n3 5\n2 1\n14 17\n4 14\n1 1000001000\n1000100000 1\n", "8\n1 5\n1 9\n3 5\n2 1\n14 17\n4 0\n1 1000001000\n1000100000 1\n", "8\n1 5\n1 9\n3 3\n2 1\n14 17\n4 0\n1 1000001000\n1000100000 1\n", "8\n1 5\n1 9\n3 3\n2 1\n14 17\n4 0\n1 1000001100\n1000100000 1\n", "8\n1 9\n2 5\n3 5\n2 1\n14 17\n4 14\n1 1000000000\n1000000000 1\n", "8\n1 5\n1 5\n3 5\n2 1\n14 17\n4 14\n1 1000000000\n1000100000 1\n", "8\n1 5\n1 9\n3 5\n2 1\n14 0\n4 14\n1 1010000000\n1000100000 1\n", "8\n1 1\n1 9\n3 5\n2 1\n14 17\n4 14\n1 1010001000\n1000100000 1\n", "8\n1 5\n1 9\n3 5\n2 1\n14 17\n4 14\n1 1001001000\n1000100000 1\n", "8\n1 5\n1 1\n3 3\n2 1\n14 17\n4 0\n1 1000001000\n1000100000 1\n", "8\n1 9\n2 5\n3 5\n2 1\n14 17\n4 3\n1 1000000000\n1000000000 1\n", "8\n1 5\n2 5\n3 5\n2 1\n14 17\n4 14\n1 1010010000\n1010000000 1\n", "8\n2 5\n2 10\n3 5\n2 1\n14 17\n4 14\n1 1010000000\n1000100000 1\n", "8\n1 5\n1 5\n3 5\n2 1\n14 17\n4 14\n1 1000001000\n1000100000 1\n", "8\n1 5\n1 9\n3 5\n2 1\n14 0\n4 14\n1 1010010000\n1000100000 1\n", "8\n1 1\n1 9\n3 5\n2 1\n14 17\n2 14\n1 1010001000\n1000100000 1\n", "8\n1 5\n1 18\n3 5\n2 1\n14 17\n4 0\n1 1000001000\n1000100000 1\n", "8\n2 5\n1 1\n3 3\n2 1\n14 17\n4 0\n1 1000001000\n1000100000 1\n", "8\n1 9\n2 1\n3 5\n2 1\n14 17\n4 3\n1 1000000000\n1000000000 1\n", "8\n1 5\n2 5\n4 5\n2 1\n14 17\n4 14\n1 1010010000\n1010000000 1\n", "8\n2 5\n2 10\n3 5\n2 1\n14 0\n4 14\n1 1010000000\n1000100000 1\n", "8\n1 4\n1 5\n3 5\n2 1\n14 17\n4 14\n1 1000001000\n1000100000 1\n", "8\n1 5\n1 9\n3 5\n2 1\n14 0\n4 2\n1 1010010000\n1000100000 1\n", "8\n1 1\n1 9\n3 5\n2 1\n14 17\n2 23\n1 1010001000\n1000100000 1\n", "8\n2 5\n1 9\n3 5\n4 1\n14 17\n4 14\n1 1001001000\n1000100000 1\n", "8\n1 5\n1 18\n3 5\n2 1\n14 17\n4 0\n2 1000001000\n1000100000 1\n", "8\n2 5\n1 1\n3 3\n2 1\n14 17\n4 0\n1 1000001010\n1000100000 1\n", "8\n1 5\n1 9\n3 3\n2 1\n14 29\n2 0\n1 1000001100\n1010100000 1\n", "8\n1 9\n2 1\n3 5\n2 1\n14 17\n4 2\n1 1000000000\n1000000000 1\n", "8\n1 5\n1 5\n4 5\n2 1\n14 17\n4 14\n1 1010010000\n1010000000 1\n", "8\n1 4\n1 5\n4 5\n2 1\n14 17\n4 14\n1 1000001000\n1000100000 1\n", "8\n1 9\n1 9\n3 5\n2 1\n14 0\n4 2\n1 1010010000\n1000100000 1\n", "8\n2 5\n1 9\n3 5\n4 1\n14 17\n4 16\n1 1001001000\n1000100000 1\n", "8\n1 5\n1 18\n3 0\n2 1\n14 17\n4 0\n2 1000001000\n1000100000 1\n", "8\n2 5\n1 1\n6 3\n2 1\n14 17\n4 0\n1 1000001010\n1000100000 1\n", "8\n2 5\n2 10\n3 3\n2 1\n14 0\n4 14\n1 1010000000\n1000100000 2\n", "8\n1 1\n1 9\n3 5\n2 2\n14 17\n4 23\n1 1010001000\n1000100000 1\n", "8\n2 5\n1 9\n3 5\n4 1\n5 17\n4 16\n1 1001001000\n1000100000 1\n", "8\n1 5\n1 18\n3 0\n2 1\n20 17\n4 0\n2 1000001000\n1000100000 1\n", "8\n1 6\n2 1\n3 5\n2 1\n14 17\n4 2\n1 1000000000\n1000000000 2\n", "8\n1 5\n1 5\n4 5\n2 1\n14 5\n4 14\n1 1010010000\n1010000001 1\n", "8\n2 5\n2 10\n3 3\n2 1\n14 0\n4 18\n1 1010000000\n1000100000 2\n", "8\n1 4\n1 5\n8 3\n2 1\n14 17\n4 14\n1 1000001000\n1000100000 1\n", "8\n1 9\n1 9\n3 7\n2 1\n14 0\n6 2\n1 1010010000\n1000100000 1\n"], "outputs": ["5\n2\n2\n0\n4\n4\n1000000000\n0\n", "5\n2\n2\n0\n2\n4\n1000000000\n0\n", "5\n2\n2\n0\n2\n4\n1010000000\n0\n", "5\n5\n2\n0\n2\n4\n1010000000\n0\n", "5\n9\n2\n0\n2\n4\n1010000000\n0\n", "5\n9\n2\n0\n2\n4\n1010001000\n0\n", "5\n9\n2\n0\n2\n4\n1000001000\n0\n", "5\n9\n2\n0\n2\n0\n1000001000\n0\n", "5\n9\n1\n0\n2\n0\n1000001000\n0\n", "5\n9\n1\n0\n2\n0\n1000001100\n0\n", "9\n2\n2\n0\n2\n4\n1000000000\n0\n", "5\n5\n2\n0\n2\n4\n1000000000\n0\n", "5\n9\n2\n0\n0\n4\n1010000000\n0\n", "1\n9\n2\n0\n2\n4\n1010001000\n0\n", "5\n9\n2\n0\n2\n4\n1001001000\n0\n", "5\n1\n1\n0\n2\n0\n1000001000\n0\n", "9\n2\n2\n0\n2\n1\n1000000000\n0\n", "5\n2\n2\n0\n2\n4\n1010010000\n0\n", "2\n5\n2\n0\n2\n4\n1010000000\n0\n", "5\n5\n2\n0\n2\n4\n1000001000\n0\n", "5\n9\n2\n0\n0\n4\n1010010000\n0\n", "1\n9\n2\n0\n2\n7\n1010001000\n0\n", "5\n18\n2\n0\n2\n0\n1000001000\n0\n", "2\n1\n1\n0\n2\n0\n1000001000\n0\n", "9\n0\n2\n0\n2\n1\n1000000000\n0\n", "5\n2\n1\n0\n2\n4\n1010010000\n0\n", "2\n5\n2\n0\n0\n4\n1010000000\n0\n", "4\n5\n2\n0\n2\n4\n1000001000\n0\n", "5\n9\n2\n0\n0\n0\n1010010000\n0\n", "1\n9\n2\n0\n2\n11\n1010001000\n0\n", "2\n9\n2\n0\n2\n4\n1001001000\n0\n", "5\n18\n2\n0\n2\n0\n500000500\n0\n", "2\n1\n1\n0\n2\n0\n1000001010\n0\n", "5\n9\n1\n0\n3\n0\n1000001100\n0\n", "9\n0\n2\n0\n2\n0\n1000000000\n0\n", "5\n5\n1\n0\n2\n4\n1010010000\n0\n", "4\n5\n1\n0\n2\n4\n1000001000\n0\n", "9\n9\n2\n0\n0\n0\n1010010000\n0\n", "2\n9\n2\n0\n2\n5\n1001001000\n0\n", "5\n18\n0\n0\n2\n0\n500000500\n0\n", "2\n1\n0\n0\n2\n0\n1000001010\n0\n", "2\n5\n1\n0\n0\n4\n1010000000\n0\n", "1\n9\n2\n1\n2\n7\n1010001000\n0\n", "2\n9\n2\n0\n5\n5\n1001001000\n0\n", "5\n18\n0\n0\n1\n0\n500000500\n0\n", "6\n0\n2\n0\n2\n0\n1000000000\n0\n", "5\n5\n1\n0\n0\n4\n1010010000\n0\n", "2\n5\n1\n0\n0\n6\n1010000000\n0\n", "4\n5\n0\n0\n2\n4\n1000001000\n0\n", "9\n9\n3\n0\n0\n0\n1010010000\n0\n"]}, "starter_code": "", "problem_sha1": "0a2ffe82b1170e4beeea292c14854a4e0687a34b", "n_test_cases_total": 201, "n_test_cases_kept": 50, "test_cases_truncated": true, "seed_id": "cc-06494", "original_id": null, "source": "code_contests", "domain": "code", "test_case_format": "stdin_stdout", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": null} {"problem": "Alice has recently received an array a_1, a_2, ..., a_n for her birthday! She is very proud of her array, and when she showed her friend Bob the array, he was very happy with her present too!\n\nHowever, soon Bob became curious, and as any sane friend would do, asked Alice to perform q operations of two types on her array:\n\n * 1 x y: update the element a_x to y (set a_x = y). \n * 2 l r: calculate how many non-decreasing subarrays exist within the subarray [a_l, a_{l+1}, ..., a_r]. More formally, count the number of pairs of integers (p,q) such that l ≤ p ≤ q ≤ r and a_p ≤ a_{p+1} ≤ ... ≤ a_{q-1} ≤ a_q. \n\n\n\nHelp Alice answer Bob's queries!\n\nInput\n\nThe first line contains two integers n and q (1 ≤ n, q ≤ 2 ⋅ 10^5) — the size of the array, and the number of queries, respectively.\n\nThe second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the elements of Alice's array.\n\nThe next q lines consist of three integers each. The first integer of the i-th line is t_i, the operation being performed on the i-th step (t_i = 1 or t_i = 2).\n\nIf t_i = 1, the next two integers are x_i and y_i (1 ≤ x_i ≤ n; 1 ≤ y_i ≤ 10^9), updating the element at position x_i to y_i (setting a_{x_i} = y_i).\n\nIf t_i = 2, the next two integers are l_i and r_i (1 ≤ l_i ≤ r_i ≤ n), the two indices Bob asks Alice about for the i-th query.\n\nIt's guaranteed that there is at least one operation of the second type.\n\nOutput\n\nFor each query of type 2, print a single integer, the answer to the query.\n\nExample\n\nInput\n\n\n5 6\n3 1 4 1 5\n2 2 5\n2 1 3\n1 4 4\n2 2 5\n1 2 6\n2 2 5\n\n\nOutput\n\n\n6\n4\n10\n7\n\nNote\n\nFor the first query, l = 2 and r = 5, and the non-decreasing subarrays [p,q] are [2,2], [3,3], [4,4], [5,5], [2,3] and [4,5].", "test_cases": {"inputs": ["5 6\n3 1 4 1 5\n2 2 5\n2 1 3\n1 4 4\n2 2 5\n1 2 6\n2 2 5\n", "10 20\n1 9 15 26 8 4 25 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 23\n1 10 4\n1 3 13\n2 6 7\n1 1 19\n1 1 18\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n1 9 28\n", "10 20\n1 9 15 26 8 4 25 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 23\n1 10 4\n1 3 13\n2 6 7\n1 1 19\n1 1 18\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n1 9 9\n", "5 6\n3 1 4 1 5\n2 2 5\n2 1 3\n1 4 8\n2 2 5\n1 2 6\n2 2 5\n", "10 20\n1 9 15 26 8 4 25 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 33\n1 10 4\n1 3 13\n2 6 7\n1 1 19\n1 1 18\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 5\n1 7 5\n2 1 7\n1 9 9\n", "10 20\n1 9 15 26 8 4 25 46 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 33\n1 10 4\n1 3 13\n2 6 7\n1 1 19\n1 1 9\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n2 9 9\n", "5 6\n1 1 4 1 5\n2 2 5\n2 1 3\n1 4 4\n2 2 5\n1 2 6\n2 2 5\n", "10 20\n1 9 15 26 8 4 25 46 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 27\n2 8 10\n1 2 33\n1 10 4\n1 3 13\n2 6 7\n1 1 19\n1 1 9\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n1 9 9\n", "10 20\n1 9 15 26 8 4 25 46 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 33\n1 10 4\n1 3 1\n2 6 7\n1 1 19\n1 1 9\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n2 9 9\n", "10 20\n1 9 15 26 8 4 25 8 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 23\n1 2 4\n1 3 13\n2 6 7\n1 1 19\n1 1 18\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n1 9 28\n", "10 20\n1 9 15 26 8 4 25 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 23\n1 10 4\n1 3 13\n2 6 7\n1 1 19\n1 1 18\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 13\n1 7 5\n2 1 7\n1 9 28\n", "5 6\n3 1 4 1 5\n2 2 5\n2 1 3\n1 4 4\n2 3 5\n1 2 6\n2 2 5\n", "10 20\n1 9 15 26 8 4 25 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 33\n1 10 4\n1 3 13\n2 7 7\n1 1 19\n1 1 9\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n1 9 9\n", "5 6\n3 1 4 1 5\n2 2 5\n2 1 3\n1 4 8\n2 2 5\n1 2 6\n2 1 5\n", "5 6\n1 1 4 1 5\n2 2 5\n2 1 3\n1 4 4\n2 4 5\n1 2 6\n2 2 5\n", "10 20\n1 9 15 26 8 4 25 13 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 33\n1 10 4\n1 3 1\n2 6 7\n1 1 19\n1 1 14\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n2 9 9\n", "10 20\n1 9 15 26 8 4 24 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 33\n1 10 4\n1 3 13\n2 6 7\n1 1 19\n1 1 18\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 5\n1 7 5\n2 1 9\n1 9 9\n", "10 20\n1 9 15 26 8 4 25 13 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 2 15\n2 8 10\n1 2 33\n1 10 4\n1 3 1\n2 6 7\n1 1 19\n1 1 14\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n2 9 9\n", "10 20\n1 9 15 26 8 4 24 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 33\n1 10 4\n1 3 13\n2 6 10\n1 1 19\n1 1 18\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 5\n1 7 5\n2 1 9\n1 9 9\n", "10 20\n1 9 15 26 8 4 25 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 23\n1 10 4\n1 3 13\n2 6 7\n1 1 19\n1 1 18\n1 4 2\n2 3 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n1 9 28\n", "5 6\n3 1 4 1 5\n2 4 5\n2 1 3\n1 4 4\n2 2 5\n1 2 6\n2 2 5\n", "10 20\n1 9 15 26 8 4 25 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 23\n1 10 4\n1 3 13\n2 6 7\n1 1 19\n1 1 18\n1 4 2\n2 5 8\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n1 9 9\n", "5 6\n3 1 4 1 5\n2 2 5\n2 1 3\n1 4 8\n1 2 5\n1 2 6\n2 2 5\n", "5 6\n1 1 4 1 5\n2 3 5\n2 1 3\n1 4 4\n2 4 5\n1 2 6\n2 2 5\n", "10 20\n1 9 15 26 8 4 25 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 26\n1 9 15\n2 8 10\n1 2 33\n1 10 4\n1 3 13\n2 7 7\n1 1 19\n1 1 9\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 4 5\n2 1 7\n1 9 9\n", "5 6\n4 1 8 1 5\n2 2 5\n2 1 3\n1 4 8\n2 2 5\n1 2 6\n2 1 5\n", "5 4\n1 1 4 0 5\n2 2 5\n2 1 3\n1 4 4\n2 4 5\n1 2 6\n2 2 5\n", "10 20\n1 9 15 26 8 4 25 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 23\n1 10 4\n1 3 13\n2 6 7\n1 1 19\n1 1 18\n1 4 2\n2 5 6\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n1 9 28\n", "10 3\n1 9 15 26 8 4 25 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 33\n1 10 4\n1 3 13\n2 6 7\n1 1 31\n1 1 18\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 5\n1 7 5\n2 1 7\n1 9 9\n", "10 20\n1 9 15 9 8 4 25 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 23\n1 10 4\n1 3 13\n2 6 7\n1 1 19\n1 1 18\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 13\n1 7 5\n2 1 4\n1 9 28\n", "10 20\n1 9 15 26 8 4 25 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 26\n1 9 15\n2 8 10\n1 2 33\n1 10 4\n1 3 13\n2 7 7\n1 1 19\n1 1 9\n1 4 2\n2 5 5\n1 1 2\n1 9 17\n1 4 10\n1 4 5\n2 1 7\n1 9 9\n", "10 20\n1 9 15 26 8 4 25 13 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 2 15\n2 8 10\n1 2 33\n1 10 4\n1 3 1\n2 6 7\n1 1 35\n1 1 14\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 2 7\n2 9 9\n", "10 20\n1 9 15 26 0 4 25 46 23 14\n2 8 9\n1 8 20\n2 1 8\n1 6 16\n1 9 15\n2 8 10\n1 3 33\n1 10 3\n1 3 13\n2 6 7\n1 1 2\n1 1 9\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n1 9 9\n", "5 6\n3 2 4 1 5\n2 4 5\n2 2 3\n1 4 4\n2 2 5\n1 2 6\n2 2 5\n", "10 20\n1 9 15 26 8 4 25 8 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n1 8 10\n1 2 23\n1 2 4\n1 3 13\n2 6 7\n1 1 19\n1 1 18\n1 4 2\n2 5 5\n1 1 2\n1 3 17\n1 4 9\n1 7 4\n2 1 7\n1 9 28\n", "10 20\n1 9 15 9 8 4 25 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 23\n1 10 4\n1 4 13\n2 6 7\n1 1 19\n1 1 18\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 13\n1 7 5\n2 1 4\n1 9 28\n", "5 6\n3 2 4 1 5\n2 4 5\n2 2 3\n1 4 4\n2 4 5\n1 2 6\n2 2 5\n", "10 20\n1 9 15 26 8 4 25 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 23\n1 2 4\n1 3 13\n2 6 7\n1 1 19\n1 1 18\n1 4 2\n2 5 10\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n1 9 28\n", "10 20\n1 9 15 26 8 4 25 8 23 14\n2 8 9\n1 3 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 23\n1 2 4\n1 3 13\n2 6 7\n1 1 19\n1 1 18\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n1 9 28\n", "10 20\n1 9 15 26 8 4 1 46 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 33\n1 10 4\n1 3 1\n2 6 7\n1 1 19\n1 1 14\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n2 9 9\n", "5 6\n3 1 4 1 5\n2 2 5\n2 1 2\n1 4 4\n2 3 5\n1 2 6\n2 2 5\n", "10 20\n1 9 15 26 8 4 25 24 23 14\n2 9 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 33\n1 10 4\n1 3 13\n2 7 7\n1 1 19\n1 1 9\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n1 9 9\n", "5 3\n3 1 4 1 5\n2 2 5\n2 1 3\n1 4 8\n2 2 5\n1 2 6\n2 1 5\n", "5 6\n1 1 4 1 5\n2 2 5\n2 1 3\n1 4 8\n2 2 5\n1 2 6\n2 1 5\n", "5 6\n3 1 4 1 5\n2 2 5\n2 1 3\n1 4 8\n1 2 5\n1 2 6\n2 4 5\n", "10 20\n1 9 15 26 8 4 25 24 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 7 10\n1 2 33\n1 10 4\n1 3 13\n2 6 7\n1 1 31\n1 1 18\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 5\n1 7 5\n2 1 7\n1 9 9\n", "10 20\n1 9 15 26 8 4 10 46 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 33\n1 10 8\n1 3 13\n2 6 7\n1 1 19\n1 1 9\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n2 1 7\n1 9 9\n", "5 6\n3 0 4 1 5\n2 2 5\n2 1 3\n1 2 4\n2 3 5\n1 2 6\n2 2 5\n", "10 20\n1 9 15 26 8 4 25 46 23 14\n2 8 9\n1 8 20\n2 8 8\n1 6 21\n1 9 15\n2 8 10\n1 2 33\n1 10 4\n1 3 13\n2 6 7\n1 1 4\n1 1 9\n1 4 2\n2 5 5\n1 1 2\n1 6 17\n1 4 10\n1 7 5\n1 1 7\n1 9 9\n", "5 6\n1 1 4 1 5\n2 3 5\n2 1 3\n1 1 4\n2 4 5\n1 2 6\n2 2 5\n"], "outputs": ["6\n4\n10\n7\n", "2\n1\n3\n3\n1\n9\n", "2\n1\n3\n3\n1\n9\n", "6\n4\n7\n5\n", "2\n1\n3\n3\n1\n11\n", "2\n1\n3\n3\n1\n9\n1\n", "6\n6\n10\n7\n", "2\n1\n4\n3\n1\n9\n", "2\n1\n3\n3\n1\n10\n1\n", "3\n1\n3\n3\n1\n11\n", "2\n1\n3\n3\n1\n10\n", "6\n4\n6\n7\n", "2\n1\n3\n1\n1\n9\n", "6\n4\n7\n7\n", "6\n6\n3\n7\n", "3\n1\n3\n3\n1\n10\n1\n", "2\n1\n3\n3\n1\n14\n", "3\n1\n4\n3\n1\n10\n1\n", "2\n1\n3\n6\n1\n14\n", "2\n1\n3\n3\n4\n9\n", "3\n4\n10\n7\n", "2\n1\n3\n3\n7\n9\n", "6\n4\n5\n", "4\n6\n3\n7\n", "2\n1\n3\n1\n1\n14\n", "6\n4\n7\n11\n", "6\n6\n3\n", "2\n1\n3\n3\n3\n9\n", "2\n1\n", "2\n1\n3\n3\n1\n6\n", "2\n1\n3\n1\n1\n11\n", "3\n1\n4\n3\n1\n8\n1\n", "2\n17\n3\n3\n1\n11\n", "3\n3\n10\n7\n", "3\n1\n3\n1\n11\n", "2\n1\n3\n3\n1\n5\n", "3\n3\n3\n7\n", "2\n1\n3\n3\n9\n11\n", "3\n1\n4\n3\n1\n11\n", "2\n1\n3\n2\n1\n10\n1\n", "6\n2\n6\n7\n", "1\n1\n3\n1\n1\n9\n", "6\n4\n", "6\n6\n7\n7\n", "6\n4\n2\n", "2\n1\n4\n3\n1\n11\n", "2\n1\n3\n2\n1\n9\n", "6\n4\n4\n5\n", "2\n1\n3\n3\n1\n", "4\n6\n3\n5\n"]}, "starter_code": "", "problem_sha1": "771ffc55527262c4924cb4050a7de8113527559b", "n_test_cases_total": 202, "n_test_cases_kept": 50, "test_cases_truncated": true, "seed_id": "cc-06499", "original_id": null, "source": "code_contests", "domain": "code", "test_case_format": "stdin_stdout", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": null} {"problem": "You are given a book with n chapters.\n\nEach chapter has a specified list of other chapters that need to be understood in order to understand this chapter. To understand a chapter, you must read it after you understand every chapter on its required list.\n\nCurrently you don't understand any of the chapters. You are going to read the book from the beginning till the end repeatedly until you understand the whole book. Note that if you read a chapter at a moment when you don't understand some of the required chapters, you don't understand this chapter.\n\nDetermine how many times you will read the book to understand every chapter, or determine that you will never understand every chapter no matter how many times you read the book.\n\nInput\n\nEach test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 2⋅10^4).\n\nThe first line of each test case contains a single integer n (1 ≤ n ≤ 2⋅10^5) — number of chapters.\n\nThen n lines follow. The i-th line begins with an integer k_i (0 ≤ k_i ≤ n-1) — number of chapters required to understand the i-th chapter. Then k_i integers a_{i,1}, a_{i,2}, ..., a_{i, k_i} (1 ≤ a_{i, j} ≤ n, a_{i, j} ≠ i, a_{i, j} ≠ a_{i, l} for j ≠ l) follow — the chapters required to understand the i-th chapter.\n\nIt is guaranteed that the sum of n and sum of k_i over all testcases do not exceed 2⋅10^5.\n\nOutput\n\nFor each test case, if the entire book can be understood, print how many times you will read it, otherwise print -1.\n\nExample\n\nInput\n\n\n5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 2\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 5\n0\n\n\nOutput\n\n\n2\n-1\n1\n2\n5\n\nNote\n\nIn the first example, we will understand chapters \\{2, 4\\} in the first reading and chapters \\{1, 3\\} in the second reading of the book.\n\nIn the second example, every chapter requires the understanding of some other chapter, so it is impossible to understand the book.\n\nIn the third example, every chapter requires only chapters that appear earlier in the book, so we can understand everything in one go.\n\nIn the fourth example, we will understand chapters \\{2, 3, 4\\} in the first reading and chapter 1 in the second reading of the book.\n\nIn the fifth example, we will understand one chapter in every reading from 5 to 1.", "test_cases": {"inputs": ["5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 2\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 5\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 5\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 2\n1 3\n1 4\n5\n0\n0\n2 1 4\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 5\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 3\n5\n1 5\n1 1\n1 2\n1 3\n1 4\n5\n0\n0\n2 1 4\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 5\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 3\n5\n1 5\n1 1\n1 2\n1 3\n1 4\n5\n0\n0\n2 1 4\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 4\n1 3\n1 4\n1 5\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 3\n5\n1 5\n1 1\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 4\n0\n0\n2 3 1\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 2\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 4\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 1\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 2 4\n1 1\n5\n1 2\n1 1\n1 1\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 2\n1 1\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 1 2\n5\n1 3\n1 3\n1 4\n1 5\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 3\n5\n1 5\n1 1\n1 2\n1 3\n1 4\n5\n0\n0\n2 1 4\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 2\n1 5\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 4\n0\n0\n2 3 1\n5\n1 2\n1 5\n1 2\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 2\n1 1\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 4 3\n0\n0\n2 1 2\n5\n1 2\n1 3\n1 4\n1 5\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 4\n1 2\n2 2 1\n4\n2 2 4\n0\n0\n2 1 1\n5\n1 2\n1 4\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 2 4\n1 2\n5\n1 2\n1 1\n1 1\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 4\n1 3\n1 5\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 1\n5\n1 3\n0 2\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 4\n1 2\n2 2 1\n4\n2 2 4\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 3\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 4\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 2\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 2\n1 1\n1 1\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 3\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 2\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 1\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 2\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 3\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 1\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 2\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 1\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 1\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 2\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 1\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 1\n1 1\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 2\n1 1\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 5\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 2\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 4\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 2\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 3\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 4\n1 2\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 1\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n0 1\n1 2\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 4\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 2\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 3\n1 3\n1 4\n1 2\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 2\n1 3\n1 2\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 5\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 1 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 3\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 2\n1 1\n1 1\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 3\n5\n1 5\n1 1\n1 1\n1 2\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 4\n1 2\n1 1\n1 1\n1 3\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 1\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 2\n0 1\n1 2\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 4\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 3\n5\n1 5\n1 1\n1 1\n1 2\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 4\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 2\n0 1\n1 2\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 4\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 1\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 2\n1 2\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 2 4\n1 2\n5\n1 5\n1 1\n1 1\n1 2\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 4\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 3\n0\n2 1 4\n1 4\n5\n1 5\n1 1\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 4\n0\n0\n2 3 1\n5\n1 2\n1 4\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 1 2\n5\n1 2\n1 3\n1 4\n1 2\n0\n", "5\n4\n1 2\n0\n2 2 4\n1 2\n5\n1 2\n1 1\n1 1\n1 3\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n0 1\n1 2\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 4\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 1\n1 3\n0\n", "5\n4\n1 4\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 2\n1 2\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 1\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 1\n1 3\n1 4\n1 3\n0\n"], "outputs": ["2\n-1\n1\n2\n5\n", "2\n-1\n1\n2\n5\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n2\n2\n5\n", "-1\n-1\n2\n2\n5\n", "-1\n-1\n2\n2\n4\n", "-1\n-1\n1\n2\n-1\n", "2\n-1\n1\n-1\n-1\n", "2\n-1\n2\n2\n-1\n", "3\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n4\n", "-1\n-1\n2\n2\n-1\n", "2\n-1\n1\n-1\n3\n", "2\n-1\n1\n-1\n5\n", "2\n-1\n2\n-1\n-1\n", "2\n-1\n1\n2\n3\n", "3\n-1\n2\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n5\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n5\n", "2\n-1\n1\n2\n-1\n", "-1\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "-1\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "-1\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "-1\n-1\n1\n2\n-1\n", "2\n-1\n1\n-1\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n", "2\n-1\n1\n2\n-1\n"]}, "starter_code": "", "problem_sha1": "4ffd9c799de7a1675e86ea5a26fc5fe7b58c1f0b", "n_test_cases_total": 150, "n_test_cases_kept": 50, "test_cases_truncated": true, "seed_id": "cc-06504", "original_id": null, "source": "code_contests", "domain": "code", "test_case_format": "stdin_stdout", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": null} {"seed_id": "apps-00002", "original_id": null, "source": "apps", "domain": "code", "problem": "The sequence of $m$ integers is called the permutation if it contains all integers from $1$ to $m$ exactly once. The number $m$ is called the length of the permutation.\n\nDreamoon has two permutations $p_1$ and $p_2$ of non-zero lengths $l_1$ and $l_2$.\n\nNow Dreamoon concatenates these two permutations into another sequence $a$ of length $l_1 + l_2$. First $l_1$ elements of $a$ is the permutation $p_1$ and next $l_2$ elements of $a$ is the permutation $p_2$. \n\nYou are given the sequence $a$, and you need to find two permutations $p_1$ and $p_2$. If there are several possible ways to restore them, you should find all of them. (Note that it is also possible that there will be no ways.)\n\n\n-----Input-----\n\nThe first line contains an integer $t$ ($1 \\le t \\le 10\\,000$) denoting the number of test cases in the input.\n\nEach test case contains two lines. The first line contains one integer $n$ ($2 \\leq n \\leq 200\\,000$): the length of $a$. The second line contains $n$ integers $a_1, a_2, \\ldots, a_n$ ($1 \\leq a_i \\leq n-1$).\n\nThe total sum of $n$ is less than $200\\,000$.\n\n\n-----Output-----\n\nFor each test case, the first line of output should contain one integer $k$: the number of ways to divide $a$ into permutations $p_1$ and $p_2$.\n\nEach of the next $k$ lines should contain two integers $l_1$ and $l_2$ ($1 \\leq l_1, l_2 \\leq n, l_1 + l_2 = n$), denoting, that it is possible to divide $a$ into two permutations of length $l_1$ and $l_2$ ($p_1$ is the first $l_1$ elements of $a$, and $p_2$ is the last $l_2$ elements of $a$). You can print solutions in any order.\n\n\n-----Example-----\nInput\n6\n5\n1 4 3 2 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n\nOutput\n2\n1 4\n4 1\n1\n4 2\n0\n0\n1\n2 10\n0\n\n\n\n-----Note-----\n\nIn the first example, two possible ways to divide $a$ into permutations are $\\{1\\} + \\{4, 3, 2, 1\\}$ and $\\{1,4,3,2\\} + \\{1\\}$.\n\nIn the second example, the only way to divide $a$ into permutations is $\\{2,4,1,3\\} + \\{2,1\\}$.\n\nIn the third example, there are no possible ways.", "starter_code": "", "test_cases": {"inputs": ["6\n5\n1 4 3 2 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n"], "outputs": ["2\n1 4\n4 1\n1\n4 2\n0\n0\n1\n2 10\n0\n"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "03d24c65e102d5494e680db7ccde02390d356246", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00007", "original_id": null, "source": "apps", "domain": "code", "problem": "Try guessing the statement from this picture: $3$ \n\nYou are given a non-negative integer $d$. You have to find two non-negative real numbers $a$ and $b$ such that $a + b = d$ and $a \\cdot b = d$.\n\n\n-----Input-----\n\nThe first line contains $t$ ($1 \\le t \\le 10^3$) — the number of test cases.\n\nEach test case contains one integer $d$ $(0 \\le d \\le 10^3)$.\n\n\n-----Output-----\n\nFor each test print one line.\n\nIf there is an answer for the $i$-th test, print \"Y\", and then the numbers $a$ and $b$.\n\nIf there is no answer for the $i$-th test, print \"N\".\n\nYour answer will be considered correct if $|(a + b) - a \\cdot b| \\le 10^{-6}$ and $|(a + b) - d| \\le 10^{-6}$.\n\n\n-----Example-----\nInput\n7\n69\n0\n1\n4\n5\n999\n1000\n\nOutput\nY 67.985071301 1.014928699\nY 0.000000000 0.000000000\nN\nY 2.000000000 2.000000000\nY 3.618033989 1.381966011\nY 997.998996990 1.001003010\nY 998.998997995 1.001002005", "starter_code": "", "test_cases": {"inputs": ["7\n69\n0\n1\n4\n5\n999\n1000\n"], "outputs": ["Y 67.985071301 1.014928699\nY 0.000000000 0.000000000\nN\nY 2.000000000 2.000000000\nY 3.618033989 1.381966011\nY 997.998996990 1.001003010\nY 998.998997995 1.001002005\n"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "a943f76616dca4d14bfc1e8de03f47399069b48f", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00012", "original_id": null, "source": "apps", "domain": "code", "problem": "Let's call some positive integer classy if its decimal representation contains no more than $3$ non-zero digits. For example, numbers $4$, $200000$, $10203$ are classy and numbers $4231$, $102306$, $7277420000$ are not.\n\nYou are given a segment $[L; R]$. Count the number of classy integers $x$ such that $L \\le x \\le R$.\n\nEach testcase contains several segments, for each of them you are required to solve the problem separately.\n\n\n-----Input-----\n\nThe first line contains a single integer $T$ ($1 \\le T \\le 10^4$) — the number of segments in a testcase.\n\nEach of the next $T$ lines contains two integers $L_i$ and $R_i$ ($1 \\le L_i \\le R_i \\le 10^{18}$).\n\n\n-----Output-----\n\nPrint $T$ lines — the $i$-th line should contain the number of classy integers on a segment $[L_i; R_i]$.\n\n\n-----Example-----\nInput\n4\n1 1000\n1024 1024\n65536 65536\n999999 1000001\n\nOutput\n1000\n1\n0\n2", "starter_code": "", "test_cases": {"inputs": ["4\n1 1000\n1024 1024\n65536 65536\n999999 1000001\n"], "outputs": ["1000\n1\n0\n2\n"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "80e4dace1f8af625199e677232450e2c7dff03a5", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00017", "original_id": null, "source": "apps", "domain": "code", "problem": "You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \\cdots + a_n = 0$.\n\nIn one operation, you can choose two different indices $i$ and $j$ ($1 \\le i, j \\le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.\n\nHow many coins do you have to spend in order to make all elements equal to $0$?\n\n\n-----Input-----\n\nEach test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \\le t \\le 5000$). Description of the test cases follows.\n\nThe first line of each test case contains an integer $n$ ($1 \\le n \\le 10^5$)  — the number of elements.\n\nThe next line contains $n$ integers $a_1, \\ldots, a_n$ ($-10^9 \\le a_i \\le 10^9$). It is given that $\\sum_{i=1}^n a_i = 0$.\n\nIt is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.\n\n\n-----Output-----\n\nFor each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.\n\n\n-----Example-----\nInput\n7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0\n\nOutput\n3\n0\n4\n1\n8\n3000000000\n0\n\n\n\n-----Note-----\n\nPossible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.", "starter_code": "", "test_cases": {"inputs": ["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0\n"], "outputs": ["3\n0\n4\n1\n8\n3000000000\n0\n"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "fa35760eca85a1b644802c1b0527e2d8510064b1", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00022", "original_id": null, "source": "apps", "domain": "code", "problem": "You are given a colored permutation $p_1, p_2, \\dots, p_n$. The $i$-th element of the permutation has color $c_i$.\n\nLet's define an infinite path as infinite sequence $i, p[i], p[p[i]], p[p[p[i]]] \\dots$ where all elements have same color ($c[i] = c[p[i]] = c[p[p[i]]] = \\dots$).\n\nWe can also define a multiplication of permutations $a$ and $b$ as permutation $c = a \\times b$ where $c[i] = b[a[i]]$. Moreover, we can define a power $k$ of permutation $p$ as $p^k=\\underbrace{p \\times p \\times \\dots \\times p}_{k \\text{ times}}$.\n\nFind the minimum $k > 0$ such that $p^k$ has at least one infinite path (i.e. there is a position $i$ in $p^k$ such that the sequence starting from $i$ is an infinite path).\n\nIt can be proved that the answer always exists.\n\n\n-----Input-----\n\nThe first line contains single integer $T$ ($1 \\le T \\le 10^4$) — the number of test cases.\n\nNext $3T$ lines contain test cases — one per three lines. The first line contains single integer $n$ ($1 \\le n \\le 2 \\cdot 10^5$) — the size of the permutation.\n\nThe second line contains $n$ integers $p_1, p_2, \\dots, p_n$ ($1 \\le p_i \\le n$, $p_i \\neq p_j$ for $i \\neq j$) — the permutation $p$.\n\nThe third line contains $n$ integers $c_1, c_2, \\dots, c_n$ ($1 \\le c_i \\le n$) — the colors of elements of the permutation.\n\nIt is guaranteed that the total sum of $n$ doesn't exceed $2 \\cdot 10^5$.\n\n\n-----Output-----\n\nPrint $T$ integers — one per test case. For each test case print minimum $k > 0$ such that $p^k$ has at least one infinite path.\n\n\n-----Example-----\nInput\n3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n\nOutput\n1\n5\n2\n\n\n\n-----Note-----\n\nIn the first test case, $p^1 = p = [1, 3, 4, 2]$ and the sequence starting from $1$: $1, p[1] = 1, \\dots$ is an infinite path.\n\nIn the second test case, $p^5 = [1, 2, 3, 4, 5]$ and it obviously contains several infinite paths.\n\nIn the third test case, $p^2 = [3, 6, 1, 8, 7, 2, 5, 4]$ and the sequence starting from $4$: $4, p^2[4]=8, p^2[8]=4, \\dots$ is an infinite path since $c_4 = c_8 = 4$.", "starter_code": "", "test_cases": {"inputs": ["3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n"], "outputs": ["1\n5\n2\n"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "140a55a5d6813d43309c80367f94669c7196298c", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00027", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a string s, return the maximum number of ocurrences of any substring under the following rules:\n\nThe number of unique characters in the substring must be less than or equal to maxLetters.\nThe substring size must be between minSize and maxSize inclusive.\n\n \nExample 1:\nInput: s = \"aababcaab\", maxLetters = 2, minSize = 3, maxSize = 4\nOutput: 2\nExplanation: Substring \"aab\" has 2 ocurrences in the original string.\nIt satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize).\n\nExample 2:\nInput: s = \"aaaa\", maxLetters = 1, minSize = 3, maxSize = 3\nOutput: 2\nExplanation: Substring \"aaa\" occur 2 times in the string. It can overlap.\n\nExample 3:\nInput: s = \"aabcabcab\", maxLetters = 2, minSize = 2, maxSize = 3\nOutput: 3\n\nExample 4:\nInput: s = \"abcde\", maxLetters = 2, minSize = 3, maxSize = 3\nOutput: 0\n\n \nConstraints:\n\n1 <= s.length <= 10^5\n1 <= maxLetters <= 26\n1 <= minSize <= maxSize <= min(26, s.length)\ns only contains lowercase English letters.", "starter_code": "\nclass Solution:\n def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int:\n ", "test_cases": {"inputs": [["\"aababcaab\"", 2, 3, 4]], "outputs": [2], "fn_name": "maxFreq"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "e8b3823a67fda0be3802761f9c8573ede90c5d93", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "maxFreq"} {"seed_id": "apps-00032", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a positive integer N, return the number of positive integers less than or equal to N that have at least 1 repeated digit.\n \n\nExample 1:\nInput: 20\nOutput: 1\nExplanation: The only positive number (<= 20) with at least 1 repeated digit is 11.\n\n\nExample 2:\nInput: 100\nOutput: 10\nExplanation: The positive numbers (<= 100) with atleast 1 repeated digit are 11, 22, 33, 44, 55, 66, 77, 88, 99, and 100.\n\n\nExample 3:\nInput: 1000\nOutput: 262\n\n\n \nNote:\n\n1 <= N <= 10^9", "starter_code": "\nclass Solution:\n def numDupDigitsAtMostN(self, N: int) -> int:\n ", "test_cases": {"inputs": [[20]], "outputs": [1], "fn_name": "numDupDigitsAtMostN"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "b7593aa51c161168c0aa47dcfd55ec780679b2b1", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "numDupDigitsAtMostN"} {"seed_id": "apps-00037", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231.\n\nFind the maximum result of ai XOR aj, where 0 ≤ i, j < n.\n\nCould you do this in O(n) runtime?\n\nExample:\n\nInput: [3, 10, 5, 25, 2, 8]\n\nOutput: 28\n\nExplanation: The maximum result is 5 ^ 25 = 28.", "starter_code": "\nclass Solution:\n def findMaximumXOR(self, nums: List[int]) -> int:\n ", "test_cases": {"inputs": [[[3, 10, 5, 25, 2, 8]]], "outputs": [28], "fn_name": "findMaximumXOR"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "078bcb3a9b525e36ad26ff0bce49690297f4a8c2", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "findMaximumXOR"} {"seed_id": "apps-00042", "original_id": null, "source": "apps", "domain": "code", "problem": "You have 4 cards each containing a number from 1 to 9. You need to judge whether they could operated through *, /, +, -, (, ) to get the value of 24.\n\n\nExample 1:\n\nInput: [4, 1, 8, 7]\nOutput: True\nExplanation: (8-4) * (7-1) = 24\n\n\n\nExample 2:\n\nInput: [1, 2, 1, 2]\nOutput: False\n\n\n\nNote:\n\nThe division operator / represents real division, not integer division. For example, 4 / (1 - 2/3) = 12.\nEvery operation done is between two numbers. In particular, we cannot use - as a unary operator. For example, with [1, 1, 1, 1] as input, the expression -1 - 1 - 1 - 1 is not allowed.\nYou cannot concatenate numbers together. For example, if the input is [1, 2, 1, 2], we cannot write this as 12 + 12.", "starter_code": "\nclass Solution:\n def judgePoint24(self, nums: List[int]) -> bool:\n ", "test_cases": {"inputs": [[[4, 1, 8, 7]]], "outputs": [true], "fn_name": "judgePoint24"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "a340daa4f63edd54190e1fc1551ae6625c61c622", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "judgePoint24"} {"seed_id": "apps-00047", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an array A, partition it into two (contiguous) subarrays left and right so that:\n\nEvery element in left is less than or equal to every element in right.\nleft and right are non-empty.\nleft has the smallest possible size.\n\nReturn the length of left after such a partitioning.  It is guaranteed that such a partitioning exists.\n \nExample 1:\nInput: [5,0,3,8,6]\nOutput: 3\nExplanation: left = [5,0,3], right = [8,6]\n\n\nExample 2:\nInput: [1,1,1,0,6,12]\nOutput: 4\nExplanation: left = [1,1,1,0], right = [6,12]\n\n \n\nNote:\n\n2 <= A.length <= 30000\n0 <= A[i] <= 10^6\nIt is guaranteed there is at least one way to partition A as described.", "starter_code": "\nclass Solution:\n def partitionDisjoint(self, A: List[int]) -> int:\n ", "test_cases": {"inputs": [[[5, 0, 3, 8, 6]]], "outputs": [3], "fn_name": "partitionDisjoint"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "ab9b648d0fe55978180a7d9607f9ae229c827e55", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "partitionDisjoint"} {"seed_id": "apps-00052", "original_id": null, "source": "apps", "domain": "code", "problem": "Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences.  If multiple answers exist, you may return any of them.\n(A string S is a subsequence of string T if deleting some number of characters from T (possibly 0, and the characters are chosen anywhere from T) results in the string S.)\n \nExample 1:\nInput: str1 = \"abac\", str2 = \"cab\"\nOutput: \"cabac\"\nExplanation: \nstr1 = \"abac\" is a subsequence of \"cabac\" because we can delete the first \"c\".\nstr2 = \"cab\" is a subsequence of \"cabac\" because we can delete the last \"ac\".\nThe answer provided is the shortest such string that satisfies these properties.\n\n \nNote:\n\n1 <= str1.length, str2.length <= 1000\nstr1 and str2 consist of lowercase English letters.", "starter_code": "\nclass Solution:\n def shortestCommonSupersequence(self, str1: str, str2: str) -> str:\n ", "test_cases": {"inputs": [["\"abac\"", "\"cab\""]], "outputs": ["\"cabac\""], "fn_name": "shortestCommonSupersequence"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "039150932c26587c2ef5a01d9ee339431b0e1c00", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "shortestCommonSupersequence"} {"seed_id": "apps-00057", "original_id": null, "source": "apps", "domain": "code", "problem": "One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as #.\n\n\n _9_\n / \\\n 3 2\n / \\ / \\\n 4 1 # 6\n/ \\ / \\ / \\\n# # # # # #\n\n\nFor example, the above binary tree can be serialized to the string \"9,3,4,#,#,1,#,#,2,#,6,#,#\", where # represents a null node.\n\nGiven a string of comma separated values, verify whether it is a correct preorder traversal serialization of a binary tree. Find an algorithm without reconstructing the tree.\n\nEach comma separated value in the string must be either an integer or a character '#' representing null pointer.\n\nYou may assume that the input format is always valid, for example it could never contain two consecutive commas such as \"1,,3\".\n\nExample 1:\n\n\nInput: \"9,3,4,#,#,1,#,#,2,#,6,#,#\"\nOutput: true\n\nExample 2:\n\n\nInput: \"1,#\"\nOutput: false\n\n\nExample 3:\n\n\nInput: \"9,#,#,1\"\nOutput: false", "starter_code": "\nclass Solution:\n def isValidSerialization(self, preorder: str) -> bool:\n ", "test_cases": {"inputs": [["\"9,3,4,#,#,1,#,#,2,#,6,#,#\""]], "outputs": [false], "fn_name": "isValidSerialization"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "a2a187878700f3629733c74c40a1bf7be56ae93c", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "isValidSerialization"} {"seed_id": "apps-00062", "original_id": null, "source": "apps", "domain": "code", "problem": "You are given K eggs, and you have access to a building with N floors from 1 to N. \nEach egg is identical in function, and if an egg breaks, you cannot drop it again.\nYou know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floor F will not break.\nEach move, you may take an egg (if you have an unbroken one) and drop it from any floor X (with 1 <= X <= N). \nYour goal is to know with certainty what the value of F is.\nWhat is the minimum number of moves that you need to know with certainty what F is, regardless of the initial value of F?\n \n\n\n\nExample 1:\nInput: K = 1, N = 2\nOutput: 2\nExplanation: \nDrop the egg from floor 1. If it breaks, we know with certainty that F = 0.\nOtherwise, drop the egg from floor 2. If it breaks, we know with certainty that F = 1.\nIf it didn't break, then we know with certainty F = 2.\nHence, we needed 2 moves in the worst case to know what F is with certainty.\n\n\nExample 2:\nInput: K = 2, N = 6\nOutput: 3\n\n\nExample 3:\nInput: K = 3, N = 14\nOutput: 4\n\n \nNote:\n\n1 <= K <= 100\n1 <= N <= 10000", "starter_code": "\nclass Solution:\n def superEggDrop(self, K: int, N: int) -> int:\n ", "test_cases": {"inputs": [[1, 2]], "outputs": [2], "fn_name": "superEggDrop"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "b1d93ecba2017d390a71b4627c567baddfbbe034", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "superEggDrop"} {"seed_id": "apps-00067", "original_id": null, "source": "apps", "domain": "code", "problem": "You are given an integer num. You will apply the following steps exactly two times:\n\nPick a digit x (0 <= x <= 9).\nPick another digit y (0 <= y <= 9). The digit y can be equal to x.\nReplace all the occurrences of x in the decimal representation of num by y.\nThe new integer cannot have any leading zeros, also the new integer cannot be 0.\n\nLet a and b be the results of applying the operations to num the first and second times, respectively.\nReturn the max difference between a and b.\n \nExample 1:\nInput: num = 555\nOutput: 888\nExplanation: The first time pick x = 5 and y = 9 and store the new integer in a.\nThe second time pick x = 5 and y = 1 and store the new integer in b.\nWe have now a = 999 and b = 111 and max difference = 888\n\nExample 2:\nInput: num = 9\nOutput: 8\nExplanation: The first time pick x = 9 and y = 9 and store the new integer in a.\nThe second time pick x = 9 and y = 1 and store the new integer in b.\nWe have now a = 9 and b = 1 and max difference = 8\n\nExample 3:\nInput: num = 123456\nOutput: 820000\n\nExample 4:\nInput: num = 10000\nOutput: 80000\n\nExample 5:\nInput: num = 9288\nOutput: 8700\n\n \nConstraints:\n\n1 <= num <= 10^8", "starter_code": "\nclass Solution:\n def maxDiff(self, num: int) -> int:\n ", "test_cases": {"inputs": [[555]], "outputs": [888], "fn_name": "maxDiff"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "f87e333a6b9f95fca636409d1e5ecc127741bf15", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "maxDiff"} {"seed_id": "apps-00072", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).\n\nExample:\n\n\nInput: S = \"ADOBECODEBANC\", T = \"ABC\"\nOutput: \"BANC\"\n\n\nNote:\n\n\n If there is no such window in S that covers all characters in T, return the empty string \"\".\n If there is such window, you are guaranteed that there will always be only one unique minimum window in S.", "starter_code": "\nclass Solution:\n def minWindow(self, s: str, t: str) -> str:\n ", "test_cases": {"inputs": [["\"ADOBECODEBANC\"", "\"ABC\""]], "outputs": ["\"ADOBECODEBANC\""], "fn_name": "minWindow"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "2582468c3e96d492bab4d5cea745e6698a7ffdeb", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "minWindow"} {"seed_id": "apps-00077", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a string text, we are allowed to swap two of the characters in the string. Find the length of the longest substring with repeated characters.\n \nExample 1:\nInput: text = \"ababa\"\nOutput: 3\nExplanation: We can swap the first 'b' with the last 'a', or the last 'b' with the first 'a'. Then, the longest repeated character substring is \"aaa\", which its length is 3.\n\nExample 2:\nInput: text = \"aaabaaa\"\nOutput: 6\nExplanation: Swap 'b' with the last 'a' (or the first 'a'), and we get longest repeated character substring \"aaaaaa\", which its length is 6.\n\nExample 3:\nInput: text = \"aaabbaaa\"\nOutput: 4\n\nExample 4:\nInput: text = \"aaaaa\"\nOutput: 5\nExplanation: No need to swap, longest repeated character substring is \"aaaaa\", length is 5.\n\nExample 5:\nInput: text = \"abcdef\"\nOutput: 1\n\n \nConstraints:\n\n1 <= text.length <= 20000\ntext consist of lowercase English characters only.", "starter_code": "\nclass Solution:\n def maxRepOpt1(self, text: str) -> int:\n ", "test_cases": {"inputs": [["\"ababa\""]], "outputs": [3], "fn_name": "maxRepOpt1"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "2d3a4df142d2dee18ed435af9d2317b0b4e663f4", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "maxRepOpt1"} {"seed_id": "apps-00082", "original_id": null, "source": "apps", "domain": "code", "problem": "Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.\n\nExample 1:\n\nInput:\nA: [1,2,3,2,1]\nB: [3,2,1,4,7]\nOutput: 3\nExplanation: \nThe repeated subarray with maximum length is [3, 2, 1].\n\n\n\nNote:\n\n1 \n0", "starter_code": "\nclass Solution:\n def findLength(self, A: List[int], B: List[int]) -> int:\n ", "test_cases": {"inputs": [[[1, 2, 3, 2, 1], [3, 2, 1, 4, 7]]], "outputs": [3], "fn_name": "findLength"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "712d686e28b6d2593a315e1f11cc81bcd72e2126", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "findLength"} {"seed_id": "apps-00087", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an array of integers A, find the number of triples of indices (i, j, k) such that:\n\n0 <= i < A.length\n0 <= j < A.length\n0 <= k < A.length\nA[i] & A[j] & A[k] == 0, where & represents the bitwise-AND operator.\n\n \nExample 1:\nInput: [2,1,3]\nOutput: 12\nExplanation: We could choose the following i, j, k triples:\n(i=0, j=0, k=1) : 2 & 2 & 1\n(i=0, j=1, k=0) : 2 & 1 & 2\n(i=0, j=1, k=1) : 2 & 1 & 1\n(i=0, j=1, k=2) : 2 & 1 & 3\n(i=0, j=2, k=1) : 2 & 3 & 1\n(i=1, j=0, k=0) : 1 & 2 & 2\n(i=1, j=0, k=1) : 1 & 2 & 1\n(i=1, j=0, k=2) : 1 & 2 & 3\n(i=1, j=1, k=0) : 1 & 1 & 2\n(i=1, j=2, k=0) : 1 & 3 & 2\n(i=2, j=0, k=1) : 3 & 2 & 1\n(i=2, j=1, k=0) : 3 & 1 & 2\n\n \nNote:\n\n1 <= A.length <= 1000\n0 <= A[i] < 2^16", "starter_code": "\nclass Solution:\n def countTriplets(self, A: List[int]) -> int:\n ", "test_cases": {"inputs": [[[2, 1, 3]]], "outputs": [12], "fn_name": "countTriplets"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "c1d23eea4010945b65f0e15537a88d790abf82f6", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "countTriplets"} {"seed_id": "apps-00092", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an integer k, return the minimum number of Fibonacci numbers whose sum is equal to k. The same Fibonacci number can be used multiple times.\nThe Fibonacci numbers are defined as:\n\nF1 = 1\nF2 = 1\nFn = Fn-1 + Fn-2 for n > 2.\n\nIt is guaranteed that for the given constraints we can always find such Fibonacci numbers that sum up to k.\n \nExample 1:\nInput: k = 7\nOutput: 2 \nExplanation: The Fibonacci numbers are: 1, 1, 2, 3, 5, 8, 13, ... \nFor k = 7 we can use 2 + 5 = 7.\nExample 2:\nInput: k = 10\nOutput: 2 \nExplanation: For k = 10 we can use 2 + 8 = 10.\n\nExample 3:\nInput: k = 19\nOutput: 3 \nExplanation: For k = 19 we can use 1 + 5 + 13 = 19.\n\n \nConstraints:\n\n1 <= k <= 10^9", "starter_code": "\nclass Solution:\n def findMinFibonacciNumbers(self, k: int) -> int:\n ", "test_cases": {"inputs": [[7]], "outputs": [2], "fn_name": "findMinFibonacciNumbers"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "d5039050f6a5c638297565b8f10035be2f0ceab1", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "findMinFibonacciNumbers"} {"seed_id": "apps-00097", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a number, that number will not be available for the next player. This continues until all the scores have been chosen. The player with the maximum score wins. \n\nGiven an array of scores, predict whether player 1 is the winner. You can assume each player plays to maximize his score. \n\nExample 1:\n\nInput: [1, 5, 2]\nOutput: False\nExplanation: Initially, player 1 can choose between 1 and 2. If he chooses 2 (or 1), then player 2 can choose from 1 (or 2) and 5. If player 2 chooses 5, then player 1 will be left with 1 (or 2). So, final score of player 1 is 1 + 2 = 3, and player 2 is 5. Hence, player 1 will never be the winner and you need to return False.\n\n\n\nExample 2:\n\nInput: [1, 5, 233, 7]\nOutput: True\nExplanation: Player 1 first chooses 1. Then player 2 have to choose between 5 and 7. No matter which number player 2 choose, player 1 can choose 233.Finally, player 1 has more score (234) than player 2 (12), so you need to return True representing player1 can win.\n\n\n\nNote:\n\n1 \nAny scores in the given array are non-negative integers and will not exceed 10,000,000.\nIf the scores of both players are equal, then player 1 is still the winner.", "starter_code": "\nclass Solution:\n def PredictTheWinner(self, nums: List[int]) -> bool:\n ", "test_cases": {"inputs": [[[1, 5, 2]]], "outputs": [false], "fn_name": "PredictTheWinner"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "9738e005fc72d12b87994d995b1fa764ae46a5eb", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "PredictTheWinner"} {"seed_id": "apps-00102", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a string s, return the maximum number of unique substrings that the given string can be split into.\nYou can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.\nA substring is a contiguous sequence of characters within a string.\n \nExample 1:\nInput: s = \"ababccc\"\nOutput: 5\nExplanation: One way to split maximally is ['a', 'b', 'ab', 'c', 'cc']. Splitting like ['a', 'b', 'a', 'b', 'c', 'cc'] is not valid as you have 'a' and 'b' multiple times.\n\nExample 2:\nInput: s = \"aba\"\nOutput: 2\nExplanation: One way to split maximally is ['a', 'ba'].\n\nExample 3:\nInput: s = \"aa\"\nOutput: 1\nExplanation: It is impossible to split the string any further.\n\n \nConstraints:\n\n\n1 <= s.length <= 16\n\n\ns contains only lower case English letters.", "starter_code": "\nclass Solution:\n def maxUniqueSplit(self, s: str) -> int:\n ", "test_cases": {"inputs": [["\"ababccc\""]], "outputs": [6], "fn_name": "maxUniqueSplit"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "fc7b725452081b6e609d81bb5156ea3655556745", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "maxUniqueSplit"} {"seed_id": "apps-00107", "original_id": null, "source": "apps", "domain": "code", "problem": "We have an array A of non-negative integers.\nFor every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].\nReturn the number of possible results.  (Results that occur more than once are only counted once in the final answer.)\n \n\nExample 1:\nInput: [0]\nOutput: 1\nExplanation: \nThere is only one possible result: 0.\n\n\nExample 2:\nInput: [1,1,2]\nOutput: 3\nExplanation: \nThe possible subarrays are [1], [1], [2], [1, 1], [1, 2], [1, 1, 2].\nThese yield the results 1, 1, 2, 1, 3, 3.\nThere are 3 unique values, so the answer is 3.\n\n\nExample 3:\nInput: [1,2,4]\nOutput: 6\nExplanation: \nThe possible results are 1, 2, 3, 4, 6, and 7.\n\n\n\n\n \nNote:\n\n1 <= A.length <= 50000\n0 <= A[i] <= 10^9", "starter_code": "\nclass Solution:\n def subarrayBitwiseORs(self, A: List[int]) -> int:\n ", "test_cases": {"inputs": [[[0]]], "outputs": [1], "fn_name": "subarrayBitwiseORs"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "8bab297a04afc79d87543fcab70676d2026a4afb", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "subarrayBitwiseORs"} {"seed_id": "apps-00112", "original_id": null, "source": "apps", "domain": "code", "problem": "A sequence X_1, X_2, ..., X_n is fibonacci-like if:\n\nn >= 3\nX_i + X_{i+1} = X_{i+2} for all i + 2 <= n\n\nGiven a strictly increasing array A of positive integers forming a sequence, find the length of the longest fibonacci-like subsequence of A.  If one does not exist, return 0.\n(Recall that a subsequence is derived from another sequence A by deleting any number of elements (including none) from A, without changing the order of the remaining elements.  For example, [3, 5, 8] is a subsequence of [3, 4, 5, 6, 7, 8].)\n \n\n\nExample 1:\nInput: [1,2,3,4,5,6,7,8]\nOutput: 5\nExplanation:\nThe longest subsequence that is fibonacci-like: [1,2,3,5,8].\n\nExample 2:\nInput: [1,3,7,11,12,14,18]\nOutput: 3\nExplanation:\nThe longest subsequence that is fibonacci-like:\n[1,11,12], [3,11,14] or [7,11,18].\n\n \nNote:\n\n3 <= A.length <= 1000\n1 <= A[0] < A[1] < ... < A[A.length - 1] <= 10^9\n(The time limit has been reduced by 50% for submissions in Java, C, and C++.)", "starter_code": "\nclass Solution:\n def lenLongestFibSubseq(self, A: List[int]) -> int:\n ", "test_cases": {"inputs": [[[1, 2, 3, 4, 5, 6, 7, 8]]], "outputs": [5], "fn_name": "lenLongestFibSubseq"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "5cfc1b4868d4ef5daf00e668a113e346b0096b8e", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "lenLongestFibSubseq"} {"seed_id": "apps-00117", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an array A of 0s and 1s, we may change up to K values from 0 to 1.\nReturn the length of the longest (contiguous) subarray that contains only 1s. \n \n\nExample 1:\nInput: A = [1,1,1,0,0,0,1,1,1,1,0], K = 2\nOutput: 6\nExplanation: \n[1,1,1,0,0,1,1,1,1,1,1]\nBolded numbers were flipped from 0 to 1. The longest subarray is underlined.\n\nExample 2:\nInput: A = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], K = 3\nOutput: 10\nExplanation: \n[0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1]\nBolded numbers were flipped from 0 to 1. The longest subarray is underlined.\n\n \nNote:\n\n1 <= A.length <= 20000\n0 <= K <= A.length\nA[i] is 0 or 1", "starter_code": "\nclass Solution:\n def longestOnes(self, A: List[int], K: int) -> int:\n ", "test_cases": {"inputs": [[[1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0], 2]], "outputs": [6], "fn_name": "longestOnes"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "cade24f3a22b904dd6f383e1116fbd69dfaf735e", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "longestOnes"} {"seed_id": "apps-00122", "original_id": null, "source": "apps", "domain": "code", "problem": "In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo's attacking ascending time series towards Ashe and the poisoning time duration per Teemo's attacking, you need to output the total time that Ashe is in poisoned condition.\n\n\nYou may assume that Teemo attacks at the very beginning of a specific time point, and makes Ashe be in poisoned condition immediately.\n\nExample 1:\n\nInput: [1,4], 2\nOutput: 4\nExplanation: At time point 1, Teemo starts attacking Ashe and makes Ashe be poisoned immediately. This poisoned status will last 2 seconds until the end of time point 2. And at time point 4, Teemo attacks Ashe again, and causes Ashe to be in poisoned status for another 2 seconds. So you finally need to output 4.\n\n\n\n\nExample 2:\n\nInput: [1,2], 2\nOutput: 3\nExplanation: At time point 1, Teemo starts attacking Ashe and makes Ashe be poisoned. This poisoned status will last 2 seconds until the end of time point 2. However, at the beginning of time point 2, Teemo attacks Ashe again who is already in poisoned status. Since the poisoned status won't add up together, though the second poisoning attack will still work at time point 2, it will stop at the end of time point 3. So you finally need to output 3.\n\n\n\n\nNote:\n\nYou may assume the length of given time series array won't exceed 10000.\nYou may assume the numbers in the Teemo's attacking time series and his poisoning time duration per attacking are non-negative integers, which won't exceed 10,000,000.", "starter_code": "\nclass Solution:\n def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:\n ", "test_cases": {"inputs": [[[1, 4], 2]], "outputs": [4], "fn_name": "findPoisonedDuration"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "523d2545e6f4f21cfbfc2a5a08d5fc250594afcd", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "findPoisonedDuration"} {"seed_id": "apps-00127", "original_id": null, "source": "apps", "domain": "code", "problem": "We have a set of items: the i-th item has value values[i] and label labels[i].\nThen, we choose a subset S of these items, such that:\n\n|S| <= num_wanted\nFor every label L, the number of items in S with label L is <= use_limit.\n\nReturn the largest possible sum of the subset S.\n \n\nExample 1:\nInput: values = [5,4,3,2,1], labels = [1,1,2,2,3], num_wanted = 3, use_limit = 1\nOutput: 9\nExplanation: The subset chosen is the first, third, and fifth item.\n\n\nExample 2:\nInput: values = [5,4,3,2,1], labels = [1,3,3,3,2], num_wanted = 3, use_limit = 2\nOutput: 12\nExplanation: The subset chosen is the first, second, and third item.\n\n\nExample 3:\nInput: values = [9,8,8,7,6], labels = [0,0,0,1,1], num_wanted = 3, use_limit = 1\nOutput: 16\nExplanation: The subset chosen is the first and fourth item.\n\n\nExample 4:\nInput: values = [9,8,8,7,6], labels = [0,0,0,1,1], num_wanted = 3, use_limit = 2\nOutput: 24\nExplanation: The subset chosen is the first, second, and fourth item.\n\n \nNote:\n\n1 <= values.length == labels.length <= 20000\n0 <= values[i], labels[i] <= 20000\n1 <= num_wanted, use_limit <= values.length", "starter_code": "\nclass Solution:\n def largestValsFromLabels(self, values: List[int], labels: List[int], num_wanted: int, use_limit: int) -> int:\n ", "test_cases": {"inputs": [[[5, 4, 3, 2, 1], [1, 1, 2, 2, 3], 3, 1]], "outputs": [9], "fn_name": "largestValsFromLabels"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "a6df87676cfd3732f15b5ad1ab3e6c30d7cc9422", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "largestValsFromLabels"} {"seed_id": "apps-00132", "original_id": null, "source": "apps", "domain": "code", "problem": "In English, we have a concept called root, which can be followed by some other words to form another longer word - let's call this word successor. For example, the root an, followed by other, which can form another word another.\n\n\n\n\nNow, given a dictionary consisting of many roots and a sentence. You need to replace all the successor in the sentence with the root forming it. If a successor has many roots can form it, replace it with the root with the shortest length.\n\n\n\nYou need to output the sentence after the replacement.\n\n\n\nExample 1:\n\nInput: dict = [\"cat\", \"bat\", \"rat\"]\nsentence = \"the cattle was rattled by the battery\"\nOutput: \"the cat was rat by the bat\"\n\n\n\n\nNote:\n\nThe input will only have lower-case letters.\n 1 \n 1 \n 1 \n 1", "starter_code": "\nclass Solution:\n def replaceWords(self, dictionary: List[str], sentence: str) -> str:\n ", "test_cases": {"inputs": [[["\"cat\"", "\"bat\"", "\"rat\""], "\"the cattle was rattled by the battery\""]], "outputs": ["\"the cattle was rattled by the battery\""], "fn_name": "replaceWords"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "3fad4a573f52bf69a4d764e759c7901962d25ddc", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "replaceWords"} {"seed_id": "apps-00137", "original_id": null, "source": "apps", "domain": "code", "problem": "You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty. \n\n\nFor each move, you could choose any m (1 ≤ m ≤ n) washing machines, and pass one dress of each washing machine to one of its adjacent washing machines at the same time . \n\nGiven an integer array representing the number of dresses in each washing machine from left to right on the line, you should find the minimum number of moves to make all the washing machines have the same number of dresses. If it is not possible to do it, return -1.\n\nExample1\n\nInput: [1,0,5]\n\nOutput: 3\n\nExplanation: \n1st move: 1 0 1 1 4\n2nd move: 1 2 1 3 \n3rd move: 2 1 2 2 2 \n\n\nExample2\n\nInput: [0,3,0]\n\nOutput: 2\n\nExplanation: \n1st move: 0 1 2 0 \n2nd move: 1 2 --> 0 => 1 1 1 \n\n\nExample3\n\nInput: [0,2,0]\n\nOutput: -1\n\nExplanation: \nIt's impossible to make all the three washing machines have the same number of dresses. \n\n\n\n\nNote:\n\nThe range of n is [1, 10000].\nThe range of dresses number in a super washing machine is [0, 1e5].", "starter_code": "\nclass Solution:\n def findMinMoves(self, machines: List[int]) -> int:\n ", "test_cases": {"inputs": [[[1, 0, 5]]], "outputs": [3], "fn_name": "findMinMoves"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "780d8ff64afa9b9db30925081e18f26f7a2f57d3", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "findMinMoves"} {"seed_id": "apps-00142", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an array of integers nums and an integer threshold, we will choose a positive integer divisor and divide all the array by it and sum the result of the division. Find the smallest divisor such that the result mentioned above is less than or equal to threshold.\nEach result of division is rounded to the nearest integer greater than or equal to that element. (For example: 7/3 = 3 and 10/2 = 5).\nIt is guaranteed that there will be an answer.\n \nExample 1:\nInput: nums = [1,2,5,9], threshold = 6\nOutput: 5\nExplanation: We can get a sum to 17 (1+2+5+9) if the divisor is 1. \nIf the divisor is 4 we can get a sum to 7 (1+1+2+3) and if the divisor is 5 the sum will be 5 (1+1+1+2). \n\nExample 2:\nInput: nums = [2,3,5,7,11], threshold = 11\nOutput: 3\n\nExample 3:\nInput: nums = [19], threshold = 5\nOutput: 4\n\n \nConstraints:\n\n1 <= nums.length <= 5 * 10^4\n1 <= nums[i] <= 10^6\nnums.length <= threshold <= 10^6", "starter_code": "\nclass Solution:\n def smallestDivisor(self, nums: List[int], threshold: int) -> int:\n ", "test_cases": {"inputs": [[[1, 2, 5, 9], 6]], "outputs": [5], "fn_name": "smallestDivisor"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "17c1481e6fffe3b08d41c7c826405808c2ef3795", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "smallestDivisor"} {"seed_id": "apps-00147", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an array nums and an integer target.\nReturn the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarray is equal to target.\n \nExample 1:\nInput: nums = [1,1,1,1,1], target = 2\nOutput: 2\nExplanation: There are 2 non-overlapping subarrays [1,1,1,1,1] with sum equals to target(2).\n\nExample 2:\nInput: nums = [-1,3,5,1,4,2,-9], target = 6\nOutput: 2\nExplanation: There are 3 subarrays with sum equal to 6.\n([5,1], [4,2], [3,5,1,4,2,-9]) but only the first 2 are non-overlapping.\nExample 3:\nInput: nums = [-2,6,6,3,5,4,1,2,8], target = 10\nOutput: 3\n\nExample 4:\nInput: nums = [0,0,0], target = 0\nOutput: 3\n\n \nConstraints:\n\n1 <= nums.length <= 10^5\n-10^4 <= nums[i] <= 10^4\n0 <= target <= 10^6", "starter_code": "\nclass Solution:\n def maxNonOverlapping(self, nums: List[int], target: int) -> int:\n ", "test_cases": {"inputs": [[[1, 1, 1, 1, 1], 2]], "outputs": [2], "fn_name": "maxNonOverlapping"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "5d685c943a20b586e9fb60182be6bb3bf1f3b2ef", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "maxNonOverlapping"} {"seed_id": "apps-00152", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an array of non-negative integers, you are initially positioned at the first index of the array.\n\nEach element in the array represents your maximum jump length at that position.\n\nDetermine if you are able to reach the last index.\n\nExample 1:\n\n\nInput: [2,3,1,1,4]\nOutput: true\nExplanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.\n\n\nExample 2:\n\n\nInput: [3,2,1,0,4]\nOutput: false\nExplanation: You will always arrive at index 3 no matter what. Its maximum\n  jump length is 0, which makes it impossible to reach the last index.", "starter_code": "\nclass Solution:\n def canJump(self, nums: List[int]) -> bool:\n ", "test_cases": {"inputs": [[[2, 3, 1, 1, 4]]], "outputs": [true], "fn_name": "canJump"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "d782236be8ed5824ef81d3dade71774e15e130d7", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "canJump"} {"seed_id": "apps-00157", "original_id": null, "source": "apps", "domain": "code", "problem": "Think about Zuma Game. You have a row of balls on the table, colored red(R), yellow(Y), blue(B), green(G), and white(W). You also have several balls in your hand.\n\nEach time, you may choose a ball in your hand, and insert it into the row (including the leftmost place and rightmost place). Then, if there is a group of 3 or more balls in the same color touching, remove these balls. Keep doing this until no more balls can be removed.\n\nFind the minimal balls you have to insert to remove all the balls on the table. If you cannot remove all the balls, output -1.\n\n\nExamples:\nInput: \"WRRBBW\", \"RB\"\nOutput: -1\nExplanation: WRRBBW -> WRR[R]BBW -> WBBW -> WBB[B]W -> WW\n\nInput: \"WWRRBBWW\", \"WRBRW\"\nOutput: 2\nExplanation: WWRRBBWW -> WWRR[R]BBWW -> WWBBWW -> WWBB[B]WW -> WWWW -> empty\n\nInput:\"G\", \"GGGGG\"\nOutput: 2\nExplanation: G -> G[G] -> GG[G] -> empty \n\nInput: \"RBYYBBRRB\", \"YRBGB\"\nOutput: 3\nExplanation: RBYYBBRRB -> RBYY[Y]BBRRB -> RBBBRRB -> RRRB -> B -> B[B] -> BB[B] -> empty \n\n\n\nNote:\n\nYou may assume that the initial row of balls on the table won’t have any 3 or more consecutive balls with the same color.\nThe number of balls on the table won't exceed 20, and the string represents these balls is called \"board\" in the input.\nThe number of balls in your hand won't exceed 5, and the string represents these balls is called \"hand\" in the input.\nBoth input strings will be non-empty and only contain characters 'R','Y','B','G','W'.", "starter_code": "\nclass Solution:\n def findMinStep(self, board: str, hand: str) -> int:\n ", "test_cases": {"inputs": [["\"WRRBBW\"", "\"RB\""]], "outputs": [-1], "fn_name": "findMinStep"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "1b8bb86709e1980a6f644f52687b7332ea31fd47", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "findMinStep"} {"seed_id": "apps-00162", "original_id": null, "source": "apps", "domain": "code", "problem": "Given two strings s and t, your goal is to convert s into t in k moves or less.\nDuring the ith (1 <= i <= k) move you can:\n\nChoose any index j (1-indexed) from s, such that 1 <= j <= s.length and j has not been chosen in any previous move, and shift the character at that index i times.\nDo nothing.\n\nShifting a character means replacing it by the next letter in the alphabet (wrapping around so that 'z' becomes 'a'). Shifting a character by i means applying the shift operations i times.\nRemember that any index j can be picked at most once.\nReturn true if it's possible to convert s into t in no more than k moves, otherwise return false.\n \nExample 1:\nInput: s = \"input\", t = \"ouput\", k = 9\nOutput: true\nExplanation: In the 6th move, we shift 'i' 6 times to get 'o'. And in the 7th move we shift 'n' to get 'u'.\n\nExample 2:\nInput: s = \"abc\", t = \"bcd\", k = 10\nOutput: false\nExplanation: We need to shift each character in s one time to convert it into t. We can shift 'a' to 'b' during the 1st move. However, there is no way to shift the other characters in the remaining moves to obtain t from s.\n\nExample 3:\nInput: s = \"aab\", t = \"bbb\", k = 27\nOutput: true\nExplanation: In the 1st move, we shift the first 'a' 1 time to get 'b'. In the 27th move, we shift the second 'a' 27 times to get 'b'.\n\n \nConstraints:\n\n1 <= s.length, t.length <= 10^5\n0 <= k <= 10^9\ns, t contain only lowercase English letters.", "starter_code": "\nclass Solution:\n def canConvertString(self, s: str, t: str, k: int) -> bool:\n ", "test_cases": {"inputs": [["\"input\"", "\"ouput\"", 9]], "outputs": [true], "fn_name": "canConvertString"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "d3b7e5b930c477ae3846f98e7321ff2070b284a9", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "canConvertString"} {"seed_id": "apps-00167", "original_id": null, "source": "apps", "domain": "code", "problem": "Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of the following is true for the ith position (1 \nThe number at the ith position is divisible by i.\ni is divisible by the number at the ith position.\n\n\n\n\nNow given N, how many beautiful arrangements can you construct?\n\n\nExample 1:\n\nInput: 2\nOutput: 2\nExplanation: \nThe first beautiful arrangement is [1, 2]:\nNumber at the 1st position (i=1) is 1, and 1 is divisible by i (i=1).\nNumber at the 2nd position (i=2) is 2, and 2 is divisible by i (i=2).\nThe second beautiful arrangement is [2, 1]:\nNumber at the 1st position (i=1) is 2, and 2 is divisible by i (i=1).\nNumber at the 2nd position (i=2) is 1, and i (i=2) is divisible by 1.\n\n\n\nNote:\n\nN is a positive integer and will not exceed 15.", "starter_code": "\nclass Solution:\n def countArrangement(self, N: int) -> int:\n ", "test_cases": {"inputs": [[2]], "outputs": [2], "fn_name": "countArrangement"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "79ccae21277f0573766d68a299a7542ae2ab207a", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "countArrangement"} {"seed_id": "apps-00172", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task could be done in one interval. For each interval, CPU could finish one task or just be idle.\n\nHowever, there is a non-negative cooling interval n that means between two same tasks, there must be at least n intervals that CPU are doing different tasks or just be idle. \n\nYou need to return the least number of intervals the CPU will take to finish all the given tasks.\n\nExample 1:\n\nInput: tasks = [\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"], n = 2\nOutput: 8\nExplanation: A -> B -> idle -> A -> B -> idle -> A -> B.\n\n\n\nNote:\n\nThe number of tasks is in the range [1, 10000].\nThe integer n is in the range [0, 100].", "starter_code": "\nclass Solution:\n def leastInterval(self, tasks: List[str], n: int) -> int:\n ", "test_cases": {"inputs": [[["\"A\"", "\"A\"", "\"A\"", "\"B\"", "\"B\"", "\"B\""], 2]], "outputs": [8], "fn_name": "leastInterval"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "a9811ba2e55ccdd6f8d0e288bb1c3213f4036bfb", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "leastInterval"} {"seed_id": "apps-00177", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a single positive integer x, we will write an expression of the form x (op1) x (op2) x (op3) x ... where each operator op1, op2, etc. is either addition, subtraction, multiplication, or division (+, -, *, or /).  For example, with x = 3, we might write 3 * 3 / 3 + 3 - 3 which is a value of 3.\nWhen writing such an expression, we adhere to the following conventions:\n\nThe division operator (/) returns rational numbers.\nThere are no parentheses placed anywhere.\nWe use the usual order of operations: multiplication and division happens before addition and subtraction.\nIt's not allowed to use the unary negation operator (-).  For example, \"x - x\" is a valid expression as it only uses subtraction, but \"-x + x\" is not because it uses negation.\n\nWe would like to write an expression with the least number of operators such that the expression equals the given target.  Return the least number of operators used.\n \n\nExample 1:\nInput: x = 3, target = 19\nOutput: 5\nExplanation: 3 * 3 + 3 * 3 + 3 / 3. The expression contains 5 operations.\n\nExample 2:\n\nInput: x = 5, target = 501\nOutput: 8\nExplanation: 5 * 5 * 5 * 5 - 5 * 5 * 5 + 5 / 5. The expression contains 8 operations.\n\n\nExample 3:\nInput: x = 100, target = 100000000\nOutput: 3\nExplanation: 100 * 100 * 100 * 100. The expression contains 3 operations.\n \n\n\n\nNote:\n\n2 <= x <= 100\n1 <= target <= 2 * 10^8", "starter_code": "\nclass Solution:\n def leastOpsExpressTarget(self, x: int, target: int) -> int:\n ", "test_cases": {"inputs": [[3, 19]], "outputs": [5], "fn_name": "leastOpsExpressTarget"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "6eda2a292e3953f40c502ebd710e8ff3fc86f98f", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "leastOpsExpressTarget"} {"seed_id": "apps-00182", "original_id": null, "source": "apps", "domain": "code", "problem": "Return the number of distinct non-empty substrings of text that can be written as the concatenation of some string with itself (i.e. it can be written as a + a where a is some string).\n \nExample 1:\nInput: text = \"abcabcabc\"\nOutput: 3\nExplanation: The 3 substrings are \"abcabc\", \"bcabca\" and \"cabcab\".\n\nExample 2:\nInput: text = \"leetcodeleetcode\"\nOutput: 2\nExplanation: The 2 substrings are \"ee\" and \"leetcodeleetcode\".\n\n \nConstraints:\n\n1 <= text.length <= 2000\ntext has only lowercase English letters.", "starter_code": "\nclass Solution:\n def distinctEchoSubstrings(self, text: str) -> int:\n ", "test_cases": {"inputs": [["\"abcabcabc\""]], "outputs": [3], "fn_name": "distinctEchoSubstrings"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "22c8c77761f220cd66ddf145b0d5cf0e1cfd4ed2", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "distinctEchoSubstrings"} {"seed_id": "apps-00187", "original_id": null, "source": "apps", "domain": "code", "problem": "There are N children standing in a line. Each child is assigned a rating value.\n\nYou are giving candies to these children subjected to the following requirements:\n\n\n Each child must have at least one candy.\n Children with a higher rating get more candies than their neighbors.\n\n\nWhat is the minimum candies you must give?\n\nExample 1:\n\n\nInput: [1,0,2]\nOutput: 5\nExplanation: You can allocate to the first, second and third child with 2, 1, 2 candies respectively.\n\n\nExample 2:\n\n\nInput: [1,2,2]\nOutput: 4\nExplanation: You can allocate to the first, second and third child with 1, 2, 1 candies respectively.\n The third child gets 1 candy because it satisfies the above two conditions.", "starter_code": "\nclass Solution:\n def candy(self, ratings: List[int]) -> int:\n ", "test_cases": {"inputs": [[[1, 0, 2]]], "outputs": [5], "fn_name": "candy"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "a86bcdc44a036e6e7add44752ff000060dbf7d81", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "candy"} {"seed_id": "apps-00192", "original_id": null, "source": "apps", "domain": "code", "problem": "A string is called a happy prefix if is a non-empty prefix which is also a suffix (excluding itself).\nGiven a string s. Return the longest happy prefix of s .\nReturn an empty string if no such prefix exists.\n \nExample 1:\nInput: s = \"level\"\nOutput: \"l\"\nExplanation: s contains 4 prefix excluding itself (\"l\", \"le\", \"lev\", \"leve\"), and suffix (\"l\", \"el\", \"vel\", \"evel\"). The largest prefix which is also suffix is given by \"l\".\n\nExample 2:\nInput: s = \"ababab\"\nOutput: \"abab\"\nExplanation: \"abab\" is the largest prefix which is also suffix. They can overlap in the original string.\n\nExample 3:\nInput: s = \"leetcodeleet\"\nOutput: \"leet\"\n\nExample 4:\nInput: s = \"a\"\nOutput: \"\"\n\n \nConstraints:\n\n1 <= s.length <= 10^5\ns contains only lowercase English letters.", "starter_code": "\nclass Solution:\n def longestPrefix(self, s: str) -> str:\n ", "test_cases": {"inputs": [["\"level\""]], "outputs": ["\""], "fn_name": "longestPrefix"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "861b823fb47ebbab1218f9af8a9d29483f96f597", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "longestPrefix"} {"seed_id": "apps-00197", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some elements in the array. Return the minimum number of patches required.\n\nExample 1:\n\n\nInput: nums = [1,3], n = 6\nOutput: 1 \nExplanation:\nCombinations of nums are [1], [3], [1,3], which form possible sums of: 1, 3, 4.\nNow if we add/patch 2 to nums, the combinations are: [1], [2], [3], [1,3], [2,3], [1,2,3].\nPossible sums are 1, 2, 3, 4, 5, 6, which now covers the range [1, 6].\nSo we only need 1 patch.\n\nExample 2:\n\n\nInput: nums = [1,5,10], n = 20\nOutput: 2\nExplanation: The two patches can be [2, 4].\n\n\nExample 3:\n\n\nInput: nums = [1,2,2], n = 5\nOutput: 0", "starter_code": "\nclass Solution:\n def minPatches(self, nums: List[int], n: int) -> int:\n ", "test_cases": {"inputs": [[[1, 3], 6]], "outputs": [1], "fn_name": "minPatches"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "ef961a33dc8beb228a2246bbe8dfd1663539e6db", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "minPatches"} {"seed_id": "apps-00202", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a sequence of n integers a1, a2, ..., an, a 132 pattern is a subsequence ai, aj, ak such\nthat i < j < k and ai < ak < aj. Design an algorithm that takes a list of n numbers as input and checks whether there is a 132 pattern in the list.\n\nNote: n will be less than 15,000.\n\nExample 1:\n\nInput: [1, 2, 3, 4]\n\nOutput: False\n\nExplanation: There is no 132 pattern in the sequence.\n\n\n\nExample 2:\n\nInput: [3, 1, 4, 2]\n\nOutput: True\n\nExplanation: There is a 132 pattern in the sequence: [1, 4, 2].\n\n\n\nExample 3:\n\nInput: [-1, 3, 2, 0]\n\nOutput: True\n\nExplanation: There are three 132 patterns in the sequence: [-1, 3, 2], [-1, 3, 0] and [-1, 2, 0].", "starter_code": "\nclass Solution:\n def find132pattern(self, nums: List[int]) -> bool:\n ", "test_cases": {"inputs": [[[1, 2, 3, 4]]], "outputs": [false], "fn_name": "find132pattern"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "feadc03dbaf6f53f27b77c5e481924b266e3f789", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "find132pattern"} {"seed_id": "apps-00207", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a string s and an array of integers cost where cost[i] is the cost of deleting the ith character in s.\nReturn the minimum cost of deletions such that there are no two identical letters next to each other.\nNotice that you will delete the chosen characters at the same time, in other words, after deleting a character, the costs of deleting other characters will not change.\n \nExample 1:\nInput: s = \"abaac\", cost = [1,2,3,4,5]\nOutput: 3\nExplanation: Delete the letter \"a\" with cost 3 to get \"abac\" (String without two identical letters next to each other).\n\nExample 2:\nInput: s = \"abc\", cost = [1,2,3]\nOutput: 0\nExplanation: You don't need to delete any character because there are no identical letters next to each other.\n\nExample 3:\nInput: s = \"aabaa\", cost = [1,2,3,4,1]\nOutput: 2\nExplanation: Delete the first and the last character, getting the string (\"aba\").\n\n \nConstraints:\n\ns.length == cost.length\n1 <= s.length, cost.length <= 10^5\n1 <= cost[i] <= 10^4\ns contains only lowercase English letters.", "starter_code": "\nclass Solution:\n def minCost(self, s: str, cost: List[int]) -> int:\n ", "test_cases": {"inputs": [["\"abaac\"", [1, 2, 3, 4, 5]]], "outputs": [4], "fn_name": "minCost"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "1b12a8a3eeb039ed945280b93e59976612244c48", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "minCost"} {"seed_id": "apps-00212", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an absolute path for a file (Unix-style), simplify it.\n\nFor example,\npath = \"/home/\", => \"/home\"\npath = \"/a/./b/../../c/\", => \"/c\"\n\nCorner Cases:\n\n\n Did you consider the case where path = \"/../\"?\n In this case, you should return \"/\".\n Another corner case is the path might contain multiple slashes '/' together, such as \"/home//foo/\".\n In this case, you should ignore redundant slashes and return \"/home/foo\".", "starter_code": "\nclass Solution:\n def simplifyPath(self, path: str) -> str:\n ", "test_cases": {"inputs": [["\"/home/\""]], "outputs": ["/\"/home/\""], "fn_name": "simplifyPath"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "89738625c607500354ccff96fb54765f8e8646aa", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "simplifyPath"} {"seed_id": "apps-00217", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.\nReturn the number of nice sub-arrays.\n \nExample 1:\nInput: nums = [1,1,2,1,1], k = 3\nOutput: 2\nExplanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].\n\nExample 2:\nInput: nums = [2,4,6], k = 1\nOutput: 0\nExplanation: There is no odd numbers in the array.\n\nExample 3:\nInput: nums = [2,2,2,1,2,2,1,2,2,2], k = 2\nOutput: 16\n\n \nConstraints:\n\n1 <= nums.length <= 50000\n1 <= nums[i] <= 10^5\n1 <= k <= nums.length", "starter_code": "\nclass Solution:\n def numberOfSubarrays(self, nums: List[int], k: int) -> int:\n ", "test_cases": {"inputs": [[[1, 1, 2, 1, 1], 3]], "outputs": [2], "fn_name": "numberOfSubarrays"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "637202fe93373ca2804b191660916f808d048135", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "numberOfSubarrays"} {"seed_id": "apps-00222", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a list of words, each word consists of English lowercase letters.\nLet's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, \"abc\" is a predecessor of \"abac\".\nA word chain is a sequence of words [word_1, word_2, ..., word_k] with k >= 1, where word_1 is a predecessor of word_2, word_2 is a predecessor of word_3, and so on.\nReturn the longest possible length of a word chain with words chosen from the given list of words.\n \nExample 1:\nInput: [\"a\",\"b\",\"ba\",\"bca\",\"bda\",\"bdca\"]\nOutput: 4\nExplanation: one of the longest word chain is \"a\",\"ba\",\"bda\",\"bdca\".\n\n \nNote:\n\n1 <= words.length <= 1000\n1 <= words[i].length <= 16\nwords[i] only consists of English lowercase letters.", "starter_code": "\nclass Solution:\n def longestStrChain(self, words: List[str]) -> int:\n ", "test_cases": {"inputs": [[["\"a\"", "\"b\"", "\"ba\"", "\"bca\"", "\"bda\"", "\"bdca\""]]], "outputs": [4], "fn_name": "longestStrChain"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "dc9ed556a2dc67e04ded56891569e240f536e42c", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "longestStrChain"} {"seed_id": "apps-00227", "original_id": null, "source": "apps", "domain": "code", "problem": "You are given an array representing a row of seats where seats[i] = 1 represents a person sitting in the ith seat, and seats[i] = 0 represents that the ith seat is empty (0-indexed).\nThere is at least one empty seat, and at least one person sitting.\nAlex wants to sit in the seat such that the distance between him and the closest person to him is maximized. \nReturn that maximum distance to the closest person.\n \nExample 1:\n\nInput: seats = [1,0,0,0,1,0,1]\nOutput: 2\nExplanation: \nIf Alex sits in the second open seat (i.e. seats[2]), then the closest person has distance 2.\nIf Alex sits in any other open seat, the closest person has distance 1.\nThus, the maximum distance to the closest person is 2.\n\nExample 2:\nInput: seats = [1,0,0,0]\nOutput: 3\nExplanation: \nIf Alex sits in the last seat (i.e. seats[3]), the closest person is 3 seats away.\nThis is the maximum distance possible, so the answer is 3.\n\nExample 3:\nInput: seats = [0,1]\nOutput: 1\n\n \nConstraints:\n\n2 <= seats.length <= 2 * 104\nseats[i] is 0 or 1.\nAt least one seat is empty.\nAt least one seat is occupied.", "starter_code": "\nclass Solution:\n def maxDistToClosest(self, seats: List[int]) -> int:\n ", "test_cases": {"inputs": [[[1, 0, 0, 0, 1, 0, 1]]], "outputs": [2], "fn_name": "maxDistToClosest"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "140ddd7e6a2fe719f3afba478a7bae3c012e5def", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "maxDistToClosest"} {"seed_id": "apps-00232", "original_id": null, "source": "apps", "domain": "code", "problem": "You are given two jugs with capacities x and y litres. There is an infinite amount of water supply available.\nYou need to determine whether it is possible to measure exactly z litres using these two jugs.\n\nIf z liters of water is measurable, you must have z liters of water contained within one or both buckets by the end.\n\n\nOperations allowed:\n\nFill any of the jugs completely with water.\nEmpty any of the jugs.\nPour water from one jug into another till the other jug is completely full or the first jug itself is empty.\n\n\n\nExample 1: (From the famous \"Die Hard\" example)\n\nInput: x = 3, y = 5, z = 4\nOutput: True\n\n\n\nExample 2:\n\nInput: x = 2, y = 6, z = 5\nOutput: False\n\n\n\nCredits:Special thanks to @vinod23 for adding this problem and creating all test cases.", "starter_code": "\nclass Solution:\n def canMeasureWater(self, x: int, y: int, z: int) -> bool:\n ", "test_cases": {"inputs": [[3, 5, 4]], "outputs": [true], "fn_name": "canMeasureWater"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "6a08560316da3af3249c851497b65c62baf9faa8", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "canMeasureWater"} {"seed_id": "apps-00237", "original_id": null, "source": "apps", "domain": "code", "problem": "We have a list of bus routes. Each routes[i] is a bus route that the i-th bus repeats forever. For example if routes[0] = [1, 5, 7], this means that the first bus (0-th indexed) travels in the sequence 1->5->7->1->5->7->1->... forever.\nWe start at bus stop S (initially not on a bus), and we want to go to bus stop T. Travelling by buses only, what is the least number of buses we must take to reach our destination? Return -1 if it is not possible.\nExample:\nInput: \nroutes = [[1, 2, 7], [3, 6, 7]]\nS = 1\nT = 6\nOutput: 2\nExplanation: \nThe best strategy is take the first bus to the bus stop 7, then take the second bus to the bus stop 6.\n\n \nConstraints:\n\n1 <= routes.length <= 500.\n1 <= routes[i].length <= 10^5.\n0 <= routes[i][j] < 10 ^ 6.", "starter_code": "\nclass Solution:\n def numBusesToDestination(self, routes: List[List[int]], S: int, T: int) -> int:\n ", "test_cases": {"inputs": [[[[1, 2, 7], [3, 6, 7], [], []], 1, 6]], "outputs": [2], "fn_name": "numBusesToDestination"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "bb281d0d434031457ef26c112a6f4d420b6cc6f8", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "numBusesToDestination"} {"seed_id": "apps-00242", "original_id": null, "source": "apps", "domain": "code", "problem": "Given N, consider a convex N-sided polygon with vertices labelled A[0], A[i], ..., A[N-1] in clockwise order.\nSuppose you triangulate the polygon into N-2 triangles.  For each triangle, the value of that triangle is the product of the labels of the vertices, and the total score of the triangulation is the sum of these values over all N-2 triangles in the triangulation.\nReturn the smallest possible total score that you can achieve with some triangulation of the polygon.\n \n\n\n\nExample 1:\nInput: [1,2,3]\nOutput: 6\nExplanation: The polygon is already triangulated, and the score of the only triangle is 6.\n\n\nExample 2:\n\nInput: [3,7,4,5]\nOutput: 144\nExplanation: There are two triangulations, with possible scores: 3*7*5 + 4*5*7 = 245, or 3*4*5 + 3*4*7 = 144. The minimum score is 144.\n\n\nExample 3:\nInput: [1,3,1,4,1,5]\nOutput: 13\nExplanation: The minimum score triangulation has score 1*1*3 + 1*1*4 + 1*1*5 + 1*1*1 = 13.\n\n \nNote:\n\n3 <= A.length <= 50\n1 <= A[i] <= 100", "starter_code": "\nclass Solution:\n def minScoreTriangulation(self, A: List[int]) -> int:\n ", "test_cases": {"inputs": [[[1, 2, 3]]], "outputs": [6], "fn_name": "minScoreTriangulation"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "54db49e8aa5ceb71c1d3aa8fd664112e5902bb67", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "minScoreTriangulation"} {"seed_id": "apps-00247", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead.\n\nExample: \n\n\nInput: s = 7, nums = [2,3,1,2,4,3]\nOutput: 2\nExplanation: the subarray [4,3] has the minimal length under the problem constraint.\n\nFollow up:\n\nIf you have figured out the O(n) solution, try coding another solution of which the time complexity is O(n log n).", "starter_code": "\nclass Solution:\n def minSubArrayLen(self, s: int, nums: List[int]) -> int:\n ", "test_cases": {"inputs": [[7, [2, 3, 1, 2, 4, 3]]], "outputs": [2], "fn_name": "minSubArrayLen"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "b66480dc6294fd7b95fc1245325f50ce97bf308a", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "minSubArrayLen"} {"seed_id": "apps-00252", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.\n\nAccording to the definition of h-index on Wikipedia: \"A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each.\"\n\nExample:\n\n\nInput: citations = [3,0,6,1,5]\nOutput: 3 \nExplanation: [3,0,6,1,5] means the researcher has 5 papers in total and each of them had \n received 3, 0, 6, 1, 5 citations respectively. \n  Since the researcher has 3 papers with at least 3 citations each and the remaining \n  two with no more than 3 citations each, her h-index is 3.\n\nNote: If there are several possible values for h, the maximum one is taken as the h-index.", "starter_code": "\nclass Solution:\n def hIndex(self, citations: List[int]) -> int:\n ", "test_cases": {"inputs": [[[0, 1, 3, 5, 6]]], "outputs": [3], "fn_name": "hIndex"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "075cb562bca67e057b4227b08ea373c7b104f14a", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "hIndex"} {"seed_id": "apps-00257", "original_id": null, "source": "apps", "domain": "code", "problem": "Write a program to find the n-th ugly number.\nUgly numbers are positive integers which are divisible by a or b or c.\n \nExample 1:\nInput: n = 3, a = 2, b = 3, c = 5\nOutput: 4\nExplanation: The ugly numbers are 2, 3, 4, 5, 6, 8, 9, 10... The 3rd is 4.\nExample 2:\nInput: n = 4, a = 2, b = 3, c = 4\nOutput: 6\nExplanation: The ugly numbers are 2, 3, 4, 6, 8, 9, 10, 12... The 4th is 6.\n\nExample 3:\nInput: n = 5, a = 2, b = 11, c = 13\nOutput: 10\nExplanation: The ugly numbers are 2, 4, 6, 8, 10, 11, 12, 13... The 5th is 10.\n\nExample 4:\nInput: n = 1000000000, a = 2, b = 217983653, c = 336916467\nOutput: 1999999984\n\n \nConstraints:\n\n1 <= n, a, b, c <= 10^9\n1 <= a * b * c <= 10^18\nIt's guaranteed that the result will be in range [1, 2 * 10^9]", "starter_code": "\nclass Solution:\n def nthUglyNumber(self, n: int, a: int, b: int, c: int) -> int:\n ", "test_cases": {"inputs": [[3, 2, 3, 5]], "outputs": [4], "fn_name": "nthUglyNumber"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "84962ce481a640f8ef19a4de25da599d6de3c3dc", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "nthUglyNumber"} {"seed_id": "apps-00262", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.\n\nExample 1:\n\nInput:nums = [1,1,1], k = 2\nOutput: 2\n\n\n\nNote:\n\nThe length of the array is in range [1, 20,000].\nThe range of numbers in the array is [-1000, 1000] and the range of the integer k is [-1e7, 1e7].", "starter_code": "\nclass Solution:\n def subarraySum(self, nums: List[int], k: int) -> int:\n ", "test_cases": {"inputs": [[[1, 1, 1], 2]], "outputs": [2], "fn_name": "subarraySum"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "669471d2c86c73d9f8d1e608a8ac05e1fc595974", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "subarraySum"} {"seed_id": "apps-00267", "original_id": null, "source": "apps", "domain": "code", "problem": "We partition a row of numbers A into at most K adjacent (non-empty) groups, then our score is the sum of the average of each group. What is the largest score we can achieve?\nNote that our partition must use every number in A, and that scores are not necessarily integers.\nExample:\nInput: \nA = [9,1,2,3,9]\nK = 3\nOutput: 20\nExplanation: \nThe best choice is to partition A into [9], [1, 2, 3], [9]. The answer is 9 + (1 + 2 + 3) / 3 + 9 = 20.\nWe could have also partitioned A into [9, 1], [2], [3, 9], for example.\nThat partition would lead to a score of 5 + 2 + 6 = 13, which is worse.\n\n \nNote: \n\n1 <= A.length <= 100.\n1 <= A[i] <= 10000.\n1 <= K <= A.length.\nAnswers within 10^-6 of the correct answer will be accepted as correct.", "starter_code": "\nclass Solution:\n def largestSumOfAverages(self, A: List[int], K: int) -> float:\n ", "test_cases": {"inputs": [[[9, 1, 2, 3, 9], 3]], "outputs": [20.0], "fn_name": "largestSumOfAverages"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "3b83fcea405c1235b7ec7e2370b7ad7c45690762", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "largestSumOfAverages"} {"seed_id": "apps-00272", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.\n\nNote:\n\n\n The same word in the dictionary may be reused multiple times in the segmentation.\n You may assume the dictionary does not contain duplicate words.\n\n\nExample 1:\n\n\nInput: s = \"leetcode\", wordDict = [\"leet\", \"code\"]\nOutput: true\nExplanation: Return true because \"leetcode\" can be segmented as \"leet code\".\n\n\nExample 2:\n\n\nInput: s = \"applepenapple\", wordDict = [\"apple\", \"pen\"]\nOutput: true\nExplanation: Return true because \"applepenapple\" can be segmented as \"apple pen apple\".\n  Note that you are allowed to reuse a dictionary word.\n\n\nExample 3:\n\n\nInput: s = \"catsandog\", wordDict = [\"cats\", \"dog\", \"sand\", \"and\", \"cat\"]\nOutput: false", "starter_code": "\nclass Solution:\n def wordBreak(self, s: str, wordDict: List[str]) -> bool:\n ", "test_cases": {"inputs": [["\"leetcode\"", ["\"leet\"", "\"code\""]]], "outputs": [false], "fn_name": "wordBreak"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "2372a44cc8b8c738e5ec7303fd0b01eb9c9f73a7", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "wordBreak"} {"seed_id": "apps-00277", "original_id": null, "source": "apps", "domain": "code", "problem": "A game on an undirected graph is played by two players, Mouse and Cat, who alternate turns.\nThe graph is given as follows: graph[a] is a list of all nodes b such that ab is an edge of the graph.\nMouse starts at node 1 and goes first, Cat starts at node 2 and goes second, and there is a Hole at node 0.\nDuring each player's turn, they must travel along one edge of the graph that meets where they are.  For example, if the Mouse is at node 1, it must travel to any node in graph[1].\nAdditionally, it is not allowed for the Cat to travel to the Hole (node 0.)\nThen, the game can end in 3 ways:\n\nIf ever the Cat occupies the same node as the Mouse, the Cat wins.\nIf ever the Mouse reaches the Hole, the Mouse wins.\nIf ever a position is repeated (ie. the players are in the same position as a previous turn, and it is the same player's turn to move), the game is a draw.\n\nGiven a graph, and assuming both players play optimally, return 1 if the game is won by Mouse, 2 if the game is won by Cat, and 0 if the game is a draw.\n \n\n\n\nExample 1:\nInput: [[2,5],[3],[0,4,5],[1,4,5],[2,3],[0,2,3]]\nOutput: 0\nExplanation:\n4---3---1\n|   |\n2---5\n \\ /\n  0\n\n \nNote:\n\n3 <= graph.length <= 50\nIt is guaranteed that graph[1] is non-empty.\nIt is guaranteed that graph[2] contains a non-zero element.", "starter_code": "\nclass Solution:\n def catMouseGame(self, graph: List[List[int]]) -> int:\n ", "test_cases": {"inputs": [[[[2, 5], [3], [0, 4, 5], [1, 4, 5], [2, 3], [0, 2, 3], [], []]]], "outputs": [0], "fn_name": "catMouseGame"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "98819a02416f8ae77ffb2ff4785a314ea1e3800c", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "catMouseGame"} {"seed_id": "apps-00282", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a string s, return the last substring of s in lexicographical order.\n \nExample 1:\nInput: \"abab\"\nOutput: \"bab\"\nExplanation: The substrings are [\"a\", \"ab\", \"aba\", \"abab\", \"b\", \"ba\", \"bab\"]. The lexicographically maximum substring is \"bab\".\n\nExample 2:\nInput: \"leetcode\"\nOutput: \"tcode\"\n\n \nNote:\n\n1 <= s.length <= 4 * 10^5\ns contains only lowercase English letters.", "starter_code": "\nclass Solution:\n def lastSubstring(self, s: str) -> str:\n ", "test_cases": {"inputs": [["\"abab\""]], "outputs": ["bab\""], "fn_name": "lastSubstring"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "9ad028dfe489a73f05a8a3d5bf6b722ac1916f64", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "lastSubstring"} {"seed_id": "apps-00287", "original_id": null, "source": "apps", "domain": "code", "problem": "Given n orders, each order consist in pickup and delivery services. \nCount all valid pickup/delivery possible sequences such that delivery(i) is always after of pickup(i). \nSince the answer may be too large, return it modulo 10^9 + 7.\n \nExample 1:\nInput: n = 1\nOutput: 1\nExplanation: Unique order (P1, D1), Delivery 1 always is after of Pickup 1.\n\nExample 2:\nInput: n = 2\nOutput: 6\nExplanation: All possible orders: \n(P1,P2,D1,D2), (P1,P2,D2,D1), (P1,D1,P2,D2), (P2,P1,D1,D2), (P2,P1,D2,D1) and (P2,D2,P1,D1).\nThis is an invalid order (P1,D2,P2,D1) because Pickup 2 is after of Delivery 2.\n\nExample 3:\nInput: n = 3\nOutput: 90\n\n \nConstraints:\n\n1 <= n <= 500", "starter_code": "\nclass Solution:\n def countOrders(self, n: int) -> int:\n ", "test_cases": {"inputs": [[1]], "outputs": [1], "fn_name": "countOrders"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "ee8998f7433a182664da52c8587a6bcb51d9ef27", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "countOrders"} {"seed_id": "apps-00292", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into sets of k consecutive numbers\nReturn True if its possible otherwise return False.\n \nExample 1:\nInput: nums = [1,2,3,3,4,4,5,6], k = 4\nOutput: true\nExplanation: Array can be divided into [1,2,3,4] and [3,4,5,6].\n\nExample 2:\nInput: nums = [3,2,1,2,3,4,3,4,5,9,10,11], k = 3\nOutput: true\nExplanation: Array can be divided into [1,2,3] , [2,3,4] , [3,4,5] and [9,10,11].\n\nExample 3:\nInput: nums = [3,3,2,2,1,1], k = 3\nOutput: true\n\nExample 4:\nInput: nums = [1,2,3,4], k = 3\nOutput: false\nExplanation: Each array should be divided in subarrays of size 3.\n\n \nConstraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9\n1 <= k <= nums.length", "starter_code": "\nclass Solution:\n def isPossibleDivide(self, nums: List[int], k: int) -> bool:\n ", "test_cases": {"inputs": [[[1, 2, 3, 3, 4, 4, 5, 6], 4]], "outputs": [true], "fn_name": "isPossibleDivide"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "b7871b8ad28663b6b220f5fa27c889651e6f3885", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "isPossibleDivide"} {"seed_id": "apps-00297", "original_id": null, "source": "apps", "domain": "code", "problem": "An encoded string S is given.  To find and write the decoded string to a tape, the encoded string is read one character at a time and the following steps are taken:\n\nIf the character read is a letter, that letter is written onto the tape.\nIf the character read is a digit (say d), the entire current tape is repeatedly written d-1 more times in total.\n\nNow for some encoded string S, and an index K, find and return the K-th letter (1 indexed) in the decoded string.\n \n\nExample 1:\nInput: S = \"leet2code3\", K = 10\nOutput: \"o\"\nExplanation: \nThe decoded string is \"leetleetcodeleetleetcodeleetleetcode\".\nThe 10th letter in the string is \"o\".\n\n\nExample 2:\nInput: S = \"ha22\", K = 5\nOutput: \"h\"\nExplanation: \nThe decoded string is \"hahahaha\". The 5th letter is \"h\".\n\n\nExample 3:\nInput: S = \"a2345678999999999999999\", K = 1\nOutput: \"a\"\nExplanation: \nThe decoded string is \"a\" repeated 8301530446056247680 times. The 1st letter is \"a\".\n\n\n\n\n \nConstraints:\n\n2 <= S.length <= 100\nS will only contain lowercase letters and digits 2 through 9.\nS starts with a letter.\n1 <= K <= 10^9\nIt's guaranteed that K is less than or equal to the length of the decoded string.\nThe decoded string is guaranteed to have less than 2^63 letters.", "starter_code": "\nclass Solution:\n def decodeAtIndex(self, S: str, K: int) -> str:\n ", "test_cases": {"inputs": [["\"leet2code3\"", 10]], "outputs": ["t"], "fn_name": "decodeAtIndex"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "67e753f9773b117db61ef9c80a9f15dde0403470", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "decodeAtIndex"} {"seed_id": "apps-00302", "original_id": null, "source": "apps", "domain": "code", "problem": "There are n soldiers standing in a line. Each soldier is assigned a unique rating value.\nYou have to form a team of 3 soldiers amongst them under the following rules:\n\nChoose 3 soldiers with index (i, j, k) with rating (rating[i], rating[j], rating[k]).\nA team is valid if:  (rating[i] < rating[j] < rating[k]) or (rating[i] > rating[j] > rating[k]) where (0 <= i < j < k < n).\n\nReturn the number of teams you can form given the conditions. (soldiers can be part of multiple teams).\n \nExample 1:\nInput: rating = [2,5,3,4,1]\nOutput: 3\nExplanation: We can form three teams given the conditions. (2,3,4), (5,4,1), (5,3,1). \n\nExample 2:\nInput: rating = [2,1,3]\nOutput: 0\nExplanation: We can't form any team given the conditions.\n\nExample 3:\nInput: rating = [1,2,3,4]\nOutput: 4\n\n \nConstraints:\n\nn == rating.length\n1 <= n <= 200\n1 <= rating[i] <= 10^5", "starter_code": "\nclass Solution:\n def numTeams(self, rating: List[int]) -> int:\n ", "test_cases": {"inputs": [[[2, 5, 3, 4, 1]]], "outputs": [3], "fn_name": "numTeams"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "8b1e0c669c9acffd3214e0784099eac1ce764217", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "numTeams"} {"seed_id": "apps-00307", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple of k, that is, sums up to n*k where n is also an integer.\n\n\n\nExample 1:\n\nInput: [23, 2, 4, 6, 7], k=6\nOutput: True\nExplanation: Because [2, 4] is a continuous subarray of size 2 and sums up to 6.\n\n\n\n\nExample 2:\n\nInput: [23, 2, 6, 4, 7], k=6\nOutput: True\nExplanation: Because [23, 2, 6, 4, 7] is an continuous subarray of size 5 and sums up to 42.\n\n\n\nNote:\n\nThe length of the array won't exceed 10,000.\nYou may assume the sum of all the numbers is in the range of a signed 32-bit integer.", "starter_code": "\nclass Solution:\n def checkSubarraySum(self, nums: List[int], k: int) -> bool:\n ", "test_cases": {"inputs": [[[23, 2, 4, 6, 7], 6]], "outputs": [true], "fn_name": "checkSubarraySum"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "f8c57f81d82fecaa65e3257e3e238db4ee6694a3", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "checkSubarraySum"} {"seed_id": "apps-00312", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a non-negative integer, you could swap two digits at most once to get the maximum valued number. Return the maximum valued number you could get.\n\n\nExample 1:\n\nInput: 2736\nOutput: 7236\nExplanation: Swap the number 2 and the number 7.\n\n\n\nExample 2:\n\nInput: 9973\nOutput: 9973\nExplanation: No swap.\n\n\n\n\nNote:\n\nThe given number is in the range [0, 108]", "starter_code": "\nclass Solution:\n def maximumSwap(self, num: int) -> int:\n ", "test_cases": {"inputs": [[2736]], "outputs": [7236], "fn_name": "maximumSwap"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "368ac69d09b8dda260aa949631579138a7b27481", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "maximumSwap"} {"seed_id": "apps-00317", "original_id": null, "source": "apps", "domain": "code", "problem": "A zero-indexed array A of length N contains all integers from 0 to N-1. Find and return the longest length of set S, where S[i] = {A[i], A[A[i]], A[A[A[i]]], ... } subjected to the rule below.\n\nSuppose the first element in S starts with the selection of element A[i] of index = i, the next element in S should be A[A[i]], and then A[A[A[i]]]… By that analogy, we stop adding right before a duplicate element occurs in S.\n\nExample 1:\n\nInput: A = [5,4,0,3,1,6,2]\nOutput: 4\nExplanation: \nA[0] = 5, A[1] = 4, A[2] = 0, A[3] = 3, A[4] = 1, A[5] = 6, A[6] = 2.\n\nOne of the longest S[K]:\nS[0] = {A[0], A[5], A[6], A[2]} = {5, 6, 2, 0}\n\n\nNote:\n\nN is an integer within the range [1, 20,000].\nThe elements of A are all distinct.\nEach element of A is an integer within the range [0, N-1].", "starter_code": "\nclass Solution:\n def arrayNesting(self, nums: List[int]) -> int:\n ", "test_cases": {"inputs": [[[5, 4, 0, 3, 1, 6, 2]]], "outputs": [4], "fn_name": "arrayNesting"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "e6fdce3a92a0a716c631123c32be31261a2eef8f", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "arrayNesting"} {"seed_id": "apps-00322", "original_id": null, "source": "apps", "domain": "code", "problem": "We are given a personal information string S, which may represent either an email address or a phone number.\nWe would like to mask this personal information according to the following rules:\n\n1. Email address:\nWe define a name to be a string of length ≥ 2 consisting of only lowercase letters a-z or uppercase letters A-Z.\nAn email address starts with a name, followed by the symbol '@', followed by a name, followed by the dot '.' and followed by a name. \nAll email addresses are guaranteed to be valid and in the format of \"name1@name2.name3\".\nTo mask an email, all names must be converted to lowercase and all letters between the first and last letter of the first name must be replaced by 5 asterisks '*'.\n\n2. Phone number:\nA phone number is a string consisting of only the digits 0-9 or the characters from the set {'+', '-', '(', ')', ' '}. You may assume a phone number contains 10 to 13 digits.\nThe last 10 digits make up the local number, while the digits before those make up the country code. Note that the country code is optional. We want to expose only the last 4 digits and mask all other digits.\nThe local number should be formatted and masked as \"***-***-1111\", where 1 represents the exposed digits.\nTo mask a phone number with country code like \"+111 111 111 1111\", we write it in the form \"+***-***-***-1111\".  The '+' sign and the first '-' sign before the local number should only exist if there is a country code.  For example, a 12 digit phone number mask should start with \"+**-\".\nNote that extraneous characters like \"(\", \")\", \" \", as well as extra dashes or plus signs not part of the above formatting scheme should be removed.\n \nReturn the correct \"mask\" of the information provided.\n \nExample 1:\nInput: \"LeetCode@LeetCode.com\"\nOutput: \"l*****e@leetcode.com\"\nExplanation: All names are converted to lowercase, and the letters between the\n  first and last letter of the first name is replaced by 5 asterisks.\n  Therefore, \"leetcode\" -> \"l*****e\".\n\nExample 2:\nInput: \"AB@qq.com\"\nOutput: \"a*****b@qq.com\"\nExplanation: There must be 5 asterisks between the first and last letter \n  of the first name \"ab\". Therefore, \"ab\" -> \"a*****b\".\n\nExample 3:\nInput: \"1(234)567-890\"\nOutput: \"***-***-7890\"\nExplanation: 10 digits in the phone number, which means all digits make up the local number.\n\nExample 4:\nInput: \"86-(10)12345678\"\nOutput: \"+**-***-***-5678\"\nExplanation: 12 digits, 2 digits for country code and 10 digits for local number. \n\nNotes:\n\nS.length <= 40.\nEmails have length at least 8.\nPhone numbers have length at least 10.", "starter_code": "\nclass Solution:\n def maskPII(self, S: str) -> str:\n", "test_cases": {"inputs": [["\"LeetCode@LeetCode.com\""]], "outputs": ["\"*****e@leetcode.com\""], "fn_name": "maskPII"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "8e5d3dcf957e45444a90db00869525a53d2e350a", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "maskPII"} {"seed_id": "apps-00327", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an array of non-negative integers arr, you are initially positioned at start index of the array. When you are at index i, you can jump to i + arr[i] or i - arr[i], check if you can reach to any index with value 0.\nNotice that you can not jump outside of the array at any time.\n \nExample 1:\nInput: arr = [4,2,3,0,3,1,2], start = 5\nOutput: true\nExplanation: \nAll possible ways to reach at index 3 with value 0 are: \nindex 5 -> index 4 -> index 1 -> index 3 \nindex 5 -> index 6 -> index 4 -> index 1 -> index 3 \n\nExample 2:\nInput: arr = [4,2,3,0,3,1,2], start = 0\nOutput: true \nExplanation: \nOne possible way to reach at index 3 with value 0 is: \nindex 0 -> index 4 -> index 1 -> index 3\n\nExample 3:\nInput: arr = [3,0,2,1,2], start = 2\nOutput: false\nExplanation: There is no way to reach at index 1 with value 0.\n\n \nConstraints:\n\n1 <= arr.length <= 5 * 10^4\n0 <= arr[i] < arr.length\n0 <= start < arr.length", "starter_code": "\nclass Solution:\n def canReach(self, arr: List[int], start: int) -> bool:\n ", "test_cases": {"inputs": [[[4, 2, 3, 0, 3, 1, 2], 5]], "outputs": [true], "fn_name": "canReach"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "10967728446603f061a975521d4d5926fc91eea1", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "canReach"} {"seed_id": "apps-00332", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.\n\nNote:\n\nYour algorithm should have a linear runtime complexity. Could you implement it without using extra memory?\n\nExample 1:\n\n\nInput: [2,2,3,2]\nOutput: 3\n\n\nExample 2:\n\n\nInput: [0,1,0,1,0,1,99]\nOutput: 99", "starter_code": "\nclass Solution:\n def singleNumber(self, nums: List[int]) -> int:\n ", "test_cases": {"inputs": [[[2, 2, 3, 2]]], "outputs": [3], "fn_name": "singleNumber"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "855c0de5688762044301ad65e2e9840c276a2584", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "singleNumber"} {"seed_id": "apps-00337", "original_id": null, "source": "apps", "domain": "code", "problem": "Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.\n\nNote: You may not slant the container and n is at least 2.", "starter_code": "\nclass Solution:\n def maxArea(self, height: List[int]) -> int:\n ", "test_cases": {"inputs": [[[1, 8, 6, 2, 5, 4, 8, 3, 7]]], "outputs": [49], "fn_name": "maxArea"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "6ab0f694a3aa3b038f85054cab22f0096fb425b9", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "maxArea"} {"seed_id": "apps-00342", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an array A of integers, a ramp is a tuple (i, j) for which i < j and A[i] <= A[j].  The width of such a ramp is j - i.\nFind the maximum width of a ramp in A.  If one doesn't exist, return 0.\n \nExample 1:\nInput: [6,0,8,2,1,5]\nOutput: 4\nExplanation: \nThe maximum width ramp is achieved at (i, j) = (1, 5): A[1] = 0 and A[5] = 5.\n\n\nExample 2:\nInput: [9,8,1,0,1,9,4,0,4,1]\nOutput: 7\nExplanation: \nThe maximum width ramp is achieved at (i, j) = (2, 9): A[2] = 1 and A[9] = 1.\n\n\n\n\n \nNote:\n\n2 <= A.length <= 50000\n0 <= A[i] <= 50000", "starter_code": "\nclass Solution:\n def maxWidthRamp(self, A: List[int]) -> int:\n ", "test_cases": {"inputs": [[[6, 0, 8, 2, 1, 5]]], "outputs": [4], "fn_name": "maxWidthRamp"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "a4cc6662e0b60fe987d081b304152a072100b976", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "maxWidthRamp"} {"seed_id": "apps-00347", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.\nReturn the least number of moves to make every value in A unique.\n \nExample 1:\nInput: [1,2,2]\nOutput: 1\nExplanation: After 1 move, the array could be [1, 2, 3].\n\n\nExample 2:\nInput: [3,2,1,2,1,7]\nOutput: 6\nExplanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].\nIt can be shown with 5 or less moves that it is impossible for the array to have all unique values.\n\n \n\nNote:\n\n0 <= A.length <= 40000\n0 <= A[i] < 40000", "starter_code": "\nclass Solution:\n def minIncrementForUnique(self, A: List[int]) -> int:\n ", "test_cases": {"inputs": [[[1, 2, 2]]], "outputs": [1], "fn_name": "minIncrementForUnique"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "3b1214d1643590ffdc4cd2365c63a5b68742f78d", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "minIncrementForUnique"} {"seed_id": "apps-00352", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a sentence text (A sentence is a string of space-separated words) in the following format:\n\nFirst letter is in upper case.\nEach word in text are separated by a single space.\n\nYour task is to rearrange the words in text such that all words are rearranged in an increasing order of their lengths. If two words have the same length, arrange them in their original order.\nReturn the new text following the format shown above.\n \nExample 1:\nInput: text = \"Leetcode is cool\"\nOutput: \"Is cool leetcode\"\nExplanation: There are 3 words, \"Leetcode\" of length 8, \"is\" of length 2 and \"cool\" of length 4.\nOutput is ordered by length and the new first word starts with capital letter.\n\nExample 2:\nInput: text = \"Keep calm and code on\"\nOutput: \"On and keep calm code\"\nExplanation: Output is ordered as follows:\n\"On\" 2 letters.\n\"and\" 3 letters.\n\"keep\" 4 letters in case of tie order by position in original text.\n\"calm\" 4 letters.\n\"code\" 4 letters.\n\nExample 3:\nInput: text = \"To be or not to be\"\nOutput: \"To be or to be not\"\n\n \nConstraints:\n\ntext begins with a capital letter and then contains lowercase letters and single space between words.\n1 <= text.length <= 10^5", "starter_code": "\nclass Solution:\n def arrangeWords(self, text: str) -> str:\n ", "test_cases": {"inputs": [["\"Leetcode is cool\""]], "outputs": ["Is cool\" \"leetcode"], "fn_name": "arrangeWords"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "a2dfe568bd2239279508001ff013bf399b336474", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "arrangeWords"} {"seed_id": "apps-00357", "original_id": null, "source": "apps", "domain": "code", "problem": "There is an infinitely long street that runs west to east, which we consider as a number line.\nThere are N roadworks scheduled on this street.\nThe i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5.\nQ people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point.\nFind the distance each of the Q people will walk.\n\n-----Constraints-----\n - All values in input are integers.\n - 1 \\leq N, Q \\leq 2 \\times 10^5\n - 0 \\leq S_i < T_i \\leq 10^9\n - 1 \\leq X_i \\leq 10^9\n - 0 \\leq D_1 < D_2 < ... < D_Q \\leq 10^9\n - If i \\neq j and X_i = X_j, the intervals [S_i, T_i) and [S_j, T_j) do not overlap.\n\n-----Input-----\nInput is given from Standard Input in the following format:\nN Q\nS_1 T_1 X_1\n:\nS_N T_N X_N\nD_1\n:\nD_Q\n\n-----Output-----\nPrint Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever.\n\n-----Sample Input-----\n4 6\n1 3 2\n7 13 10\n18 20 13\n3 4 2\n0\n1\n2\n3\n5\n8\n\n-----Sample Output-----\n2\n2\n10\n-1\n13\n-1\n\nThe first person starts coordinate 0 at time 0 and stops walking at coordinate 2 when reaching a point blocked by the first roadwork at time 2.\nThe second person starts coordinate 0 at time 1 and reaches coordinate 2 at time 3. The first roadwork has ended, but the fourth roadwork has begun, so this person also stops walking at coordinate 2.\nThe fourth and sixth persons encounter no roadworks while walking, so they walk forever. The output for these cases is -1.", "starter_code": "", "test_cases": {"inputs": ["4 6\n1 3 2\n7 13 10\n18 20 13\n3 4 2\n0\n1\n2\n3\n5\n8\n"], "outputs": ["2\n2\n10\n-1\n13\n-1\n"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "6c2e8398dec2f653f548a6938e5a5fc55ba4a421", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00362", "original_id": null, "source": "apps", "domain": "code", "problem": "Almir had a small sequence $A_1, A_2, \\ldots, A_N$. He decided to make $K$ copies of this sequence and concatenate them, forming a sequence $X_1, X_2, \\ldots, X_{NK}$; for each valid $i$ and $j$ ($0 \\le j < K$), $X_{j \\cdot N + i} = A_i$.\nFor example, if $A = (1, 2, 3)$ and $K = 4$, the final sequence is $X = (1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3)$.\nA pair $(i, j)$, where $1 \\le i < j \\le N$, is an inversion if $X_i > X_j$. Find the number of inversions in the final sequence $X$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $K$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer ― the number of inversions in the sequence $X$.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le N \\le 100$\n- $1 \\le K \\le 10^6$\n- $1 \\le A_i \\le 10^9$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n2\n3 3\n2 1 3\n4 100\n99 2 1000 24\n\n-----Example Output-----\n12\n30000", "starter_code": "", "test_cases": {"inputs": ["2\n3 3\n2 1 3\n4 100\n99 2 1000 24\n"], "outputs": ["12\n30000"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "97840f094bc6fabec31177254307ea4d97b961b7", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00367", "original_id": null, "source": "apps", "domain": "code", "problem": "Nature photographing may be fun for tourists, but it is one of the most complicated things for photographers. To capture all the facets of a bird, you might need more than one cameras. You recently encountered such a situation.\nThere are $n$ photographers, so there are $n$ cameras in a line on the x-axis. All the cameras are at distinct coordinates. \nYou want to pair up these cameras ($n$ is even) in such a way that the sum of angles subtended on the bird by the pair of cameras is maximized. Formally, let A, B be two cameras, and let P be the bird to be captured by these two cameras. The angle will APB. \nNote: All angles are in radians.\n\n-----Input-----\n- The first line of the input contains an integer $T$ denoting the number of test cases. The description of the test cases follows.\n- The first line of each test case contains an integer $n$.\n- The second line of each test case contains $n$ space-separated integers denoting the $x_i$ coordinates of the cameras.\n- The third line of each test case contains two space-separated integers $P, Q$ denoting the x and y coordinates of the bird respectively.\n\n-----Output-----\nFor each test case, output your answer in a single line. Your answer would be considered correct if its absolute error is less than or equal to 1e-6 of the actual answer. \n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $2 \\le n \\leq 100$\n- $1 \\le x_i \\leq 300$\n- $0 \\le P \\leq 300$\n- $1 \\le Q \\leq 300$\n\n-----Example Input-----\n2\n2\n0 1\n0 1\n2\n0 1\n100 1\n\n-----Example Output-----\n0.785398163397\n0.000100999899\n\n-----Explanation-----\nNote: $1 \\leq x_i$ is not being satisfied by the sample input, but will be satisfied in the actual test data.\nTestcase 1: There are only 2 cameras, so they have to paired up with each other. And the angle subtended by then is 45 degrees. Converting this to radians gives the output.", "starter_code": "", "test_cases": {"inputs": ["2\n2\n0 1\n0 1\n2\n0 1\n100 1\n"], "outputs": ["0.785398163397\n0.000100999899"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "f234980fbf07e56756f0b717bbcfd1998f266db8", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00372", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an Array of length $N$ containing elements $Ai$ ( i = 1 to n ) . You have to handle $Q$ queries on this array . Each Query is of two types k=(1 or 2). \nType 1:- $k$ $l$ $r$ in which you have to tell whether the product of numbers in range l to r results in a perfect square or not. if product of numbers in range $l$ to$r$ is a perfect square then simply output YES else output NO.\nType 2:- $k$ $i$ $val$ Multiply the value present at index $i$ with $val$.\nNote#1: 1 based indexing in each query.\nNote#2: Values of prime factors of all numbers $val$ and $Ai$ is between 2 to 100 only.\n\n-----Input:-----\n- First line will contain $N$, denoting the size of the array. Then the next line follow. \n- N integers $Ai - An$.\n- Third line will contain $Q$, denoting the number of queries. Then the next $Q$ lines follow -description of each query. \n- Each query consists of either type 1 or type 2 and each query gives you three elements either\n-{$k$ $l$ $r$} or {$k$ $i$ $val$}\n\n-----Output:-----\nFor each Query of Type 1 Output either \"YES\" or \"NO\" Without Quotes.\n\n-----Constraints-----\n- $1 \\leq N \\leq 20000$\n- $1 \\leq Q \\leq 20000$\n- $2 \\leq Ai \\leq 1000000$\n- $1 \\leq i ,l,r \\leq N$\n- $1 \\leq val \\leq 1000000$\n- $1 \\leq l \\leq r$\n\n-----Subtasks-----\nSubtask 1 :-40 points \n- Values of prime factors of all numbers $val$ and $Ai$ is between 2 to 40 only.\nSubtask 2 :- 60 points\n- Original Constraints \n\n-----Sample Input:-----\n4\n2 2 3 4\n4\n1 1 2\n1 3 4\n2 3 3\n1 1 4\n\n-----Sample Output:-----\nYES\nNO\nYES\n\n-----EXPLANATION:-----\n-Query 1 :- product of numbers in range 1 to 2=2 * 2=4 (perfect square so YES)\n-Query 2:- product of numbers in range 3 to 4 = 3 * 4 = 12 (not perfect square so NO)\n-Query 3:- multiply number at index3 with 3 so number at index 3= 3*3 = 9 .\n-Query 4:- product of numbers in range 1 to 4 = 2 * 2 * 9 * 4 = 144 (perfect square so YES)", "starter_code": "", "test_cases": {"inputs": ["4\n2 2 3 4\n4\n1 1 2\n1 3 4\n2 3 3\n1 1 4"], "outputs": ["YES\nNO\nYES"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "6d058158d9787a7a5bd4c44d0469c164cd200d22", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00377", "original_id": null, "source": "apps", "domain": "code", "problem": "Vasya's older brother, Petya, attends an algorithm course in his school. Today he learned about matchings in graphs. Formally, a set of edges in a graph is called a matching if no pair of distinct edges in the set shares a common endpoint.\nPetya instantly came up with an inverse concept, an antimatching. In an antimatching, any pair of distinct edges should have a common endpoint.\nPetya knows that finding a largest matching in a graph is a somewhat formidable task. He wonders if finding the largest antimatching is any easier. Help him find the number of edges in a largest antimatching in a given graph.\n\n-----Input:-----\nThe first line contains T$T$, number of test cases per file.\nThe first line of each test case contains two integers n$n$ and m−$m-$ the number of vertices and edges of the graph respectively (1≤n≤104$1 \\leq n \\leq 10^4$, 0≤m≤104$0 \\leq m \\leq 10^4$).\nThe next m$m$ lines describe the edges. The i$i$-th of these lines contains two integers ui$u_i$ and vi−$v_i-$ the indices of endpoints of the i$i$-th edge (1≤ui,vi≤n$1 \\leq u_i, v_i \\leq n$, ui≠vi$u_i \\neq v_i$).\nIt is guaranteed that the graph does not contain self-loops nor multiple edges. It is not guaranteed that the graph is connected.\n\n-----Output:-----\nPrint a single number per test case −$-$ the maximum size of an antichain in the graph.\n\n-----Constraints-----\n- 1≤T≤10$1 \\leq T \\leq 10$\n- 1≤n≤104$1 \\leq n \\leq 10^4$\n- 0≤m≤104$0 \\leq m \\leq 10^4$\n- 1≤ui,vi≤n$1 \\leq u_i, v_i \\leq n$\n- ui≠vi$u_i \\neq v_i$\n\n-----Sample Input:-----\n3\n3 3\n1 2\n1 3\n2 3\n4 2\n1 2\n3 4\n5 0\n\n-----Sample Output:-----\n3\n1\n0\n\n-----EXPLANATION:-----\nIn the first sample all three edges form an antimatching.\nIn the second sample at most one of the two edges can be included in an antimatching since they do not share common endpoints.\nIn the third sample there are no edges, hence the answer is 0$0$.", "starter_code": "", "test_cases": {"inputs": ["3\n3 3\n1 2\n1 3\n2 3\n4 2\n1 2\n3 4\n5 0"], "outputs": ["3\n1\n0"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "b2c27c8a3f51ef50416717a23619c26063a97ddf", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00382", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef has a sequence of positive integers $A_1, A_2, \\ldots, A_N$. He wants to choose some elements of this sequence (possibly none or all of them) and compute their MEX, i.e. the smallest positive integer which does not occur among the chosen elements. For example, the MEX of $[1, 2, 4]$ is $3$.\nHelp Chef find the largest number of elements of the sequence $A$ which he can choose such that their MEX is equal to $M$, or determine that it is impossible.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $M$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer ― the maximum number of elements Chef can choose, or $-1$ if he cannot choose elements in such a way that their MEX is $M$.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $2 \\le M \\le N \\le 10^5$\n- $1 \\le A_i \\le 10^9$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $10^6$\n\n-----Example Input-----\n1\n3 3\n1 2 4\n\n-----Example Output-----\n3\n\n-----Explanation-----\nExample case 1: The MEX of whole array is 3. Hence, we can choose all the elements.", "starter_code": "", "test_cases": {"inputs": ["1\n3 3\n1 2 4\n"], "outputs": ["3"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "00fead366b33af336385848d2d2a1a072b58b38d", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00387", "original_id": null, "source": "apps", "domain": "code", "problem": "Motu and Patlu are playing with a Magical Ball. Patlu find some interesting pattern in the motion of the ball that ball always bounce back from the ground after travelling a linear distance whose value is some power of $2$. Patlu gave Motu total distance $D$ travelled by the ball and ask him to calculate the minimum number of bounces that the ball makes before coming to rest.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, single integers $D$.\n- Note : Power of $2$ must be a non-negative integer. \n\n-----Output:-----\nFor each testcase, output in a single line answer, the minimum number of bounces the ball makes before coming to rest.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $1$ $\\leq$ $M$< $10$^18\n\n-----Sample Input:-----\n1\n13 \n\n-----Sample Output:-----\n2\n\n-----EXPLANATION:-----", "starter_code": "", "test_cases": {"inputs": ["1\n13"], "outputs": ["2"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "ded84669ecaa9cd3bbe209ab75714264cdae4612", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00392", "original_id": null, "source": "apps", "domain": "code", "problem": "Sherlock Holmes has decided to start a new academy to some of the young lads. He has conducted several tests and finally selected N equally brilliant\n\nstudents.Now he don't know whether to train all the N students or not. Now since Holmes was in a confusion, Watson came up with an idea. He wanted to\n\ntest the obedience of the students. So during the camp, the students were given some Swiss Chocolates as gifts each time when they passed a level.Now some of them have\n\nfinished eating all the chocolates, some of them had some remaining. Now to test their team chemistry and IQ skills, Watson told the lads to arrange themselves in such \na way that, number of chocolates of the ith kid should be equal to the sum of (i-1)th kid and (i-2)th kid. Now they have arranged themselves in an order.\nNow Sherlock announced that he will select the students who have formed the line according to this order. But since there can be many such small groups among the\n\nentire N kids, he will select a sequence of kids such that the length of the sequence is maximized, meanwhile satisfying the above condition \n\n-----Input-----\nFirst line is an integer T which denotes the total number of test cases. Each of the next T lines contains an integer N which denotes, N students. The next \nline contains N spaced integers.where it denotes the order in which the kids arranged themselves. \n\n-----Output-----\nEach line contains an integer which denotes the maximum number of students among the N students who have arranged themselves according the rule said by Watson.It is guaranteed that Holmes will select atleast 1 or 2 students\n\n-----Constraints-----\n- 1 ≤ T ≤ 10\n- 1 ≤ N ≤ 10^5\n- 1 ≤ Each of next N integers ≤ 10^9\n\n-----Subtasks-----\nSubtask #1 : (20 points)\n- 1 ≤ T ≤ 10\n- 1 ≤ N≤ 100\n- 1 ≤ Each element≤ 10^3\n\nSubtask 2 : (80 points) \n\n- 1 ≤ T ≤ 10\n- 1 ≤ N≤ 100000\n- 1 ≤ Each element≤ 10^9\n\n-----Example-----\nInput:\n2\n5\n2 3 5 1 2\n3\n1 2 3\n\nOutput:\n3\n3\n\n-----Explanation-----\nExample case 1. Here the first kid has 2 chocolates, second has 3 chocolates, third kid has 5 chocolates, which is the sum of first kid's total chocolates \nand second kid's chocolate. Forth student has only 1 chocolate where he did not follow the rule. So the maximum number of kids who arranged themselves in the order was \n3. That is students at index 1 to index 3.", "starter_code": "", "test_cases": {"inputs": ["2\n5\n2 3 5 1 2\n3\n1 2 3"], "outputs": ["3\n3"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "31db946e5b667f1eb69c55519fb674600f385cfa", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00397", "original_id": null, "source": "apps", "domain": "code", "problem": "This time minions are celebrating Diwali Festival. There are N minions in total. Each of them owns a house. On this Festival, Each of them wants to decorate their house. But none of them have enough money to do that. One of the minion, Kevin, requested Gru for money. Gru agreed for money distribution but he will be giving money to a minion if and only if demanded money is less than or equal to the money Gru have. Now Gru wonders if he can spend all the money or not.\n\n-----Input-----\nFirst line have number of test cases T. Each test case consist of Two Lines. First line contains two space separated integers N and K i.e. Number of minions and Amount of Money Gru have. Next line contains N space separated integers A1,A2,A3,.....,AN representing amount of money demanded by ith minion.\n\n-----Output-----\nOutput YES if Gru can spend his all of the money on minions i.e. after distribution Gru have zero amount of money else NO.\n\n-----Constraints-----\n- 1 ≤ T ≤ 105\n- 1 ≤ N ≤ 102\n- 1 ≤ K,Ai ≤ 109\n\n-----Example-----\nInput:\n2 \n4 9\n5 2 2 4\n4 9\n5 2 18 3\n\nOutput:\nYES\nNO\n\n\n-----Explanation-----\nExample case 1.At first Gru is having 9 Rs. If he gives 5 Rs. to first minion then remaining 4 Rs. can be given to 2nd and 3rd minion or to the 4th minion. Which will leave zero amount of money in the hands of Gru.\nExample case 2.At first Gru is having 9 Rs. If he gives 5 Rs. to the first minion then from remaining 4 Rs. either he can give 2 Rs. to the 2nd minion or 3 Rs. to the fourth minion. Which will leave either 2 Rs. or 1 Rs. in the hands of Gru.", "starter_code": "", "test_cases": {"inputs": ["2\n4 9\n5 2 2 4\n4 9\n5 2 18 3"], "outputs": ["YES\nNO"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "47a56a6674b246e515f6a2a6cddd9636e2482402", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00402", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef likes strings a lot but he likes palindromic strings more. Today, Chef has two strings A and B, each consisting of lower case alphabets.\n\nChef is eager to know whether it is possible to choose some non empty strings s1 and s2 where s1 is a substring of A, s2 is a substring of B such that s1 + s2 is a palindromic string. Here '+' denotes the concatenation between the strings.\nNote:\nA string is a palindromic string if it can be read same both forward as well as backward. To know more about palindromes click here.\n\n-----Input-----\n- First line of input contains a single integer T denoting the number of test cases.\n- For each test case:\n\t\n- First line contains the string A\n- Second line contains the string B.\n\n-----Output-----\nFor each test case, Print \"Yes\" (without quotes) if it possible to choose such strings s1 & s2. Print \"No\" (without quotes) otherwise.\n\n\n-----Constraints-----\n- 1 ≤ T ≤ 10 \n- 1 ≤ |A|, |B| ≤ 1000 \n\n-----Subtasks-----\n- Subtask 1: 1 ≤ |A|, |B| ≤ 10 : ( 40 pts )\n- Subtask 2: 1 ≤ |A|, |B| ≤ 1000 : ( 60 pts )\n\n-----Example-----Input\n3\nabc\nabc\na\nb\nabba\nbaab\n\nOutput\nYes\nNo\nYes\n\n-----Explanation-----\n- Test 1: One possible way of choosing s1 & s2 is s1 = \"ab\", s2 = \"a\" such that s1 + s2 i.e \"aba\" is a palindrome.\n- Test 2: There is no possible way to choose s1 & s2 such that s1 + s2 is a palindrome.\n- Test 3: You can figure it out yourself.", "starter_code": "", "test_cases": {"inputs": ["3\nabc\nabc\na\nb\nabba\nbaab"], "outputs": ["Yes\nNo\nYes"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "08824221de27815e4ac433b5b6b9ff5ddd86ed8b", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00407", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. \nChef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants.\nHelp Chef find the minimum possible P with which he can create a valid sequence.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. \n\n-----Output-----\nFor each test case, output a single line containing an integer corresponding to the minimum possible P. \n\n-----Constraints-----\n- 1 ≤ T, |s| ≤ 105\n- 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106\n\n-----Subtasks-----\nSubtask #1 (30 points)\n- 1 ≤ T, |s| ≤ 103\n- 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104\n\nSubtask #2 (70 points)\n- Original constraints\n\n-----Example-----\nInput:\n4\n<<<\n<><\n<=>\n<=<\n\nOutput:\n4\n2\n2\n3\n\n-----Explanation-----\nHere are some possible valid sequences which can be formed with the minimum P for each of the test cases:\n1 < 2 < 3 < 4\n1 < 2 > 1 < 2\n1 < 2 = 2 > 1\n1 < 2 = 2 < 3", "starter_code": "", "test_cases": {"inputs": ["4\n<<<\n<><\n<=>\n<=<"], "outputs": ["4\n2\n2\n3"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "72475ddf8eb3a3d3aeb5ad4a180522eaa3c26ec1", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00412", "original_id": null, "source": "apps", "domain": "code", "problem": "You may have tried your level best to help Chef but Dr Doof has managed to come up with his masterplan in the meantime. Sadly, you have to help Chef once again. Dr Doof has designed a parenthesis-inator. It throws a stream of $N$ brackets at the target, $1$ bracket per second. The brackets can either be opening or closing. Chef appears in front of the stream at time $t$. If Chef faces an opening bracket, he gets hit. However, if he faces a closing bracket, he may choose to let it pass through him (Chef is immune to closing brackets). Chef gets a chance to counter attack Doof as soon as he finds a balanced non-empty bracket sequence. Help Chef by providing him the minimum time $x$ at which he will be able to launch his counter attack. If Chef is unable to counter attack, answer $-1$.\nFormally, you are given a string $S$ of length $N$ consisting only of opening brackets $($ and closing brackets $)$. The substring of $S$ starting at index $L$ and ending at index $R$, i.e. $S_L S_{L+1} \\ldots S_{R}$ is denoted by $S[L, R]$ . Consider $Q$ cases. In the $i^{\\text{th}}$ case, Chef appears at time $t_i$ $(1 \\leq t_i \\leq N)$ and faces all characters from index $t_i$ to $N$. Find the minimum index $x$ $(t_i \\leq x \\leq N)$ such that the substring $S[t_i, x]$ contains a non-empty balanced bracket subsequence containing the same number of opening brackets as $S[t_i, x]$ (i.e., you cannot remove any opening bracket from the substring). If such an $x$ does not exist, print $-1$.\nA string $X$ is called a subsequence of a string $Y$ if it is possible to obtain $X$ by erasing some (possibly zero) characters from $Y$ without changing the order of the remaining characters.\nA balanced bracket sequence is defined as: \n- an empty string is a balanced bracket sequence.\n- if $s$ is a balanced bracket sequence, then so is $(s)$.\n- if $s$ and $t$ are balanced bracket sequences, then so is $st$.\n$Note :-$ The input files are large. The use of Fast I/O is recommended.\n\n-----Input-----\n- The first line contains a single integer $T$ denoting the number of testcases.\n- The first line of each test case contains the string $S$.\n- The next line contains a single integer $Q$ denoting the number of cases to consider.\n- The next line contains $Q$ space separated integers, each denoting $t_i$.\n\n-----Output-----\nFor each query, print the minimum value of $x$ in a separate line. If no such $x$ exists, print $-1$.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^3$\n- $1 \\leq |S| \\leq 10^7$\n- $1 \\leq Q \\leq 10^6$\n- $1 \\leq t_i \\leq N$\n- Every character of $S$ is either $($ or $)$.\n- Sum of $|S|$ and $Q$ over all testcases for a particular test file does not exceed $10^7$ and $10^6$ respectively.\n\n-----Sample Input-----\n1\n)())((()\n3\n1 7 6\n\n-----Sample Output-----\n3\n8\n-1\n\n-----Explanation-----\nFor the first query, Chef chooses to let $S_1$ pass through him, gets hit by $S_2$ and finally completes a balanced bracket sequence by adding $S_3$ to $S_2$ at time $x$ = $3$.", "starter_code": "", "test_cases": {"inputs": ["1\n)())((()\n3\n1 7 6"], "outputs": ["3\n8\n-1"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "6dec6aa102abd79ba4a395655aeeb53b11f3a93f", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00417", "original_id": null, "source": "apps", "domain": "code", "problem": "Vasya has ordered a pizza delivery. The pizza can be considered a perfect circle. There were $n$ premade cuts in the pizza when it was delivered. Each cut is a straight segment connecting the center of the pizza with its boundary.\nLet $O$ be the center of the pizza, $P_i$ be the endpoint of the $i$-th cut lying on the boundary, and $R$ be the point of the boundary straight to the right of $O$. Then the counterclockwise-measured angle $\\angle ROP_i$ is equal to $a_i$ degrees, where $a_i$ is an integer between $0$ and $359$. Note that angles between $0$ and $180$ angles correspond to $P_i$ in the top half of the pizza, while angles between $180$ and $360$ angles correspond to the bottom half.\nVasya may cut his pizza a few more times, and the new cuts still have to be straight segments starting at the center. He wants to make the pizza separated into several equal slices, with each slice being a circular sector with no cuts inside of it. How many new cuts Vasya will have to make?\n\n-----Input:-----\nThe first line of input contains $T$ , i.e number of test cases per file.\nThe first line of each test case contains a single integer $n-$ the numbers of premade cuts ($2 \\leq n \\leq 360$).\nThe second lines contains $n$ integers $a_1, \\ldots, a_n-$ angles of the cuts $1, \\ldots, n$ respectively ($0 \\leq a_1 < \\ldots, a_{n - 1} < 360$).\n\n-----Output:-----\nPrint a single integer$-$ the smallest number of additional cuts Vasya has to make so that the pizza is divided into several equal slices.\n\n-----Constraints-----\n- $1 \\leq T \\leq 36$\n- $2 \\leq n \\leq 360$\n- $0 \\leq a_1 < \\ldots, a_{n - 1} < 360$\n\n-----Sample Input:-----\n3\n4 \n0 90 180 270\n2\n90 210\n2\n0 1\n\n-----Sample Output:-----\n0\n1\n358\n\n-----EXPLANATION:-----\nIn the first sample the pizza is already cut into four equal slices.\nIn the second sample the pizza will be cut into three equal slices after making one extra cut at $330$ degrees.\nIn the third sample Vasya will have to cut his pizza into $360$ pieces of $1$ degree angle each.", "starter_code": "", "test_cases": {"inputs": ["3\n4\n0 90 180 270\n2\n90 210\n2\n0 1"], "outputs": ["0\n1\n358"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "c5bbeabf1fe636d0c4c565307132b08d4e6d82e5", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00422", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef is playing a game on the non-negative x-axis. It takes him $1$ second to reach from $i^{th}$ position to $(i-1)^{th}$ position or $(i+1)^{th}$ position. The chef never goes to the negative x-axis. Also, Chef doesn't stop at any moment of time.\nThe movement of chef can be described as follows.\n- At the start he is standing at $x=0$ at time $0$.\n- In the first round, he moves towards $x=1$ and comes back to the $x=0$ position. \n- In the second round, he moves towards the $x=2$ and comes back again to $x=0$. \n- Generalizing, in the $k^{th}$ round, he moves from $x=0$ to $x=k$ and then returns back to $x=0$ at the end of the round. This goes on as the game progresses.\nFor Example, the path of Chef for $3^{rd}$ round is given below.\n$0 - 1 - 2 - 3 - 2 - 1 - 0$ \nThe overall path followed by Chef would look somewhat like this:\n$0 - 1 - 0 - 1 - 2 - 1 - 0 - 1 - 2 - 3 - 2 - 1 - 0 - 1 - 2 - 3 - 4 - 3 - …$\nYou are given two non-negative integers $N$ and $K$. You have to tell the time at which Chef arrives at $x=N$ for the $K^{th}$ time. \nNote - Chef can not skip a position while visiting the positions.\n\n-----Input:-----\n- The first line contains $T$ the number of test cases. Then the test cases follow.\n- Each test case contains a single line of two integers $N$ and $K$.\n\n-----Output:-----\nFor each test case, print a single line containing one integer -- the time taken by the chef to arrive at $x=N$ for the $K^{th}$ time by modulo $1,000,000,007$.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $0 \\le N \\le 10^9$\n- $1 \\le K \\le 10^9$\n\n-----Sample Input:-----\n5\n0 1\n1 1\n2 1\n1 3\n4 6\n\n-----Sample Output:-----\n0\n1\n4\n5\n46\n\n-----Explanation:-----\nTest Case 1:\n\nChef starts the journey from the $N = 0$ at time $t = 0$ and it's the first time $(K = 1)$, he is here. So, the answer is $0$. \nTest Case 2:\n\nChef starts the journey from the $N = 0$ at time $t = 0$ then goes to $N = 1$ at $t = 1$ and it's the first time $(K = 1)$, he is here. So, the answer is $1$.\nTest Case 4:\n\nThe path followed by Chef to reach $1$ for the third time is given below.\n$0 - 1 - 0 - 1 - 2 - 1$\n\nHe reaches $1$ for the third time at $t=5$.", "starter_code": "", "test_cases": {"inputs": ["5\n0 1\n1 1\n2 1\n1 3\n4 6"], "outputs": ["0\n1\n4\n5\n46"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "9c86cca900d716d06153d44f44628f5effe589a2", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00427", "original_id": null, "source": "apps", "domain": "code", "problem": "You are given a grid with $R$ rows (numbered $1$ through $R$) and $C$ columns (numbered $1$ through $C$). A cell in row $r$ and column $c$ is denoted by $(r, c)$. Two cells in the grid are adjacent if they have a common side. For each valid $i$ and $j$, there is a value $a_{i, j}$ written in cell $a_{i, j}$.\nA cell in the grid is stable if the number of cells in the grid which are adjacent to this cell is strictly greater than the value written in this cell. The whole grid is stable if all cells in the grid are stable.\nCan you determine whether the grid is stable?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $R$ and $C$.\n- $R$ lines follow. For each $i$ ($1 \\le i \\le R$), the $i$-th of these lines contains $C$ space-separated integers $a_{i, 1}, a_{i, 2}, \\ldots, a_{i, C}$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"Stable\" if the grid is stable or \"Unstable\" if it is unstable (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 3,000$\n- $3 \\le R, C \\le 10$\n- $0 \\le a_{i, j} \\le 4$ for each valid $i, j$\n\n-----Example Input-----\n2\n3 3\n1 2 1\n2 3 2\n1 2 1\n3 4\n0 0 0 0\n0 0 0 0\n0 0 4 0\n\n-----Example Output-----\nStable\nUnstable\n\n-----Explanation-----\nExample case 1: Each cell of the grid is stable, so the grid is stable.\nExample case 2: The cell in row $3$ and column $3$ is unstable since the number of cells adjacent to this cell is $3$.", "starter_code": "", "test_cases": {"inputs": ["2\n3 3\n1 2 1\n2 3 2\n1 2 1\n3 4\n0 0 0 0\n0 0 0 0\n0 0 4 0"], "outputs": ["Stable\nUnstable"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "6d97351b7bc794681f8fcb63dd7e7082ea8cc7d0", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00432", "original_id": null, "source": "apps", "domain": "code", "problem": "Due to the COVID pandemic, people have been advised to stay at least $6$ feet away from any other person. Now, people are lining up in a queue at the local shop and it is your duty to check whether they are all following this advice.\nThere are a total of $N$ spots (numbered $1$ through $N$) where people can stand in front of the local shop. The distance between each pair of adjacent spots is $1$ foot. Each spot may be either empty or occupied; you are given a sequence $A_1, A_2, \\ldots, A_N$, where for each valid $i$, $A_i = 0$ means that the $i$-th spot is empty, while $A_i = 1$ means that there is a person standing at this spot. It is guaranteed that the queue is not completely empty.\nFor example, if $N = 11$ and the sequence $A$ is $(0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1)$, then this is a queue in which people are not following the advice because there are two people at a distance of just $3$ feet from each other.\nYou need to determine whether the people outside the local shop are following the social distancing advice or not. As long as some two people are standing at a distance smaller than 6 feet from each other, it is bad and you should report it, since social distancing is not being followed.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The next line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"YES\" if social distancing is being followed or \"NO\" otherwise (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N \\le 100$\n- $0 \\le A_i \\le 1$ for each valid $i$\n- at least one spot is occupied\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n3\n3\n1 0 1\n7\n1 0 0 0 0 0 1\n11\n0 1 0 0 0 0 0 1 0 0 1\n\n-----Example Output-----\nNO\nYES\nNO\n\n-----Explanation-----\nExample case 1: The first and third spots are occupied and the distance between them is $2$ feet.\nExample case 2: The first and seventh spots are occupied and the distance between them is $6$ feet.", "starter_code": "", "test_cases": {"inputs": ["3\n3\n1 0 1\n7\n1 0 0 0 0 0 1\n11\n0 1 0 0 0 0 0 1 0 0 1\n"], "outputs": ["NO\nYES\nNO"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "00b66d0345eba1f3cb5454c532351137b2759ccf", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00437", "original_id": null, "source": "apps", "domain": "code", "problem": "There are $M$ levels for a building numbered from $1$ to $M$ from top to bottom, each level having $N$ parking spots numbered from $1$ to $N$ from left to right. Some spots might have a car while other may be empty, the information of which is given in form of two dimensional character array $C$ ($C_{i, j}$ denote parking spot at $j$-th position on $i$-th level).\nThere is a thief who wants to unlock all the cars. Now, he is skilled such that for the first time, he can directly reach in any parking spot in no time. Basically he can reach the first car to be stolen in 0 time.\nNow, he can move within the parking lot only in following manner, each taking 1 unit of time:\n- Move down a level. That is, if current position is $(i, j)$, then he reaches $(i+1, j)$\n- If current position is $(i, j)$ and if\n- $i$ is odd, then he can move from $(i, j)$ to $(i, j+1)$\n- $i$ is even, then he can move from $(i, j)$ to $(i, j-1)$\nNote that he wants to unlock the cars in minimum time and the car is unlocked as soon as the thief reaches that parking spot.If the parking lot is empty, then the time taken is considered to be 0. \nFind the minimum time when all the cars would be unlocked. Note that once all cars are unlocked, the thief can escape instantly, so this time does not count.\n\n-----Input :-----\n- The first line of input contains a single integer $T$ (number of test cases).\n- First liine of each test case contains $M$ and $N$(number of levels and spots per each level) \n- Next $M$ line contains $N$ space separated characters $C_{i, 1}, C_{i, 2} \\ldots C_{i, N}$ where $(1\\leq i\\leq M)$ and $C_{i, j}$ is either $'P'$ or $'N'$ (without quotes).\nIf the spot contains $'P'$, then a car is parked there. else, it’s not parked.\n\n-----Output :-----\nFor each test case print a single integer, the minimum time in which thief can unlock all cars.\n\n-----Constraints :-----\n- $1\\leq T \\leq100.$ \n- $1\\leq M,N \\leq300$ \n\n-----Subtasks :-----\n- \nSubtask 1 (20 points): $1\\leq M \\leq2.$ \n- \nSubtask 2 (80 points): Original Constraints\n\n-----Sample Input :-----\n2\n4 5\nN P N N P\nN N P N N\nN P N N N\nP N N N N\n3 3\nN P P\nP P P \nP P N\n\n-----Sample Output :-----\n10\n6\n\n-----Explanation:-----\nIn the first case, He will select the spot $(1,2)$ and the path he takes will be $(1,2)→(1,3)→(1,4)→(1,5)→(2,5)→(2,4)→(2,3)→(2,2)→(3,2)→(4,2)→(4,1)$\n\nSo, he takes 10 steps to unlock all the cars.\nIn the second case, He will select the spot $(1,2)$ and the path he takes will be $(1,2)→(1,3)→(2,3)→(2,2)→(2,1)→(3,1)→(3,2)$.\nSo, he takes 6 steps.", "starter_code": "", "test_cases": {"inputs": ["2\n4 5\nN P N N P\nN N P N N\nN P N N N\nP N N N N\n3 3\nN P P\nP P P\nP P N"], "outputs": ["10\n6"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "fcbcb458c4308f68889d215804117770f5e682da", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00442", "original_id": null, "source": "apps", "domain": "code", "problem": "Given the list of numbers, you are to sort them in non decreasing order.\n\n-----Input-----\nt – the number of numbers in list, then t lines follow [t <= 10^6]. \n\nEach line contains one integer: N [0 <= N <= 10^6]\n\n-----Output-----\nOutput given numbers in non decreasing order.\n\n-----Example-----\nInput:\n5\n5\n3\n6\n7\n1\n\nOutput:\n1\n3\n5\n6\n7", "starter_code": "", "test_cases": {"inputs": ["5\n5\n3\n6\n7\n1"], "outputs": ["1\n3\n5\n6\n7"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "c57f887b1d705ab07ab566b67a57090ea0a67e55", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00447", "original_id": null, "source": "apps", "domain": "code", "problem": "Sheldon is a little geek living in Texas. While his friends like to play outside, little Sheldon likes to play around with ICs and lasers in his house. He decides to build N clap activated toggle machines each with one power inlet and one outlet. Each machine works when its power source inlet is receiving power. When the machine is in 'ON' state and is receiving power at its inlet, it makes power available at its power outlet to which a bulb or another ToGgLe machine could be attached.\n\nSuppose Sheldon attached 2 such machines to one another with the power inlet of the first machine attached to a power source at his house and the outlet of the second machine to a bulb. Initially both machines are in 'OFF' state and power source to first machine is off too. Now the power source is switched on. The first machine receives power but being in the 'OFF' state it does not transmit any power. Now on clapping the first ToGgLe machine toggles to 'ON' and the second machine receives power. On clapping once more the first toggles to 'OFF' and the second toggles to 'ON'. But since the second ToGgLe machine receives no power the bulb does not light up yet. On clapping once more, the first machine which is still receiving power from the source toggles to 'ON' and the second which was already 'ON' does not toggle since it was not receiving power. So both the machine are in 'ON' state and the bulb lights up and little Sheldon is happy.\n\nBut when Sheldon goes out for a while, his evil twin sister attaches N such ToGgLe machines (after making sure they were all in 'OFF' state) and attaches the first to a power source (the power source is initially switched off) and the last ToGgLe machine to a bulb. Sheldon is horrified to find that his careful arrangement has been disturbed.\n\nCoders, help the poor boy by finding out if clapping k times for the N ToGgLe machines (all in 'OFF' state with the first one connected to a switched off power source and last one to a bulb) would light the bulb. Hurry before Sheldon has a nervous breakdown!\n\n-----Input-----\nFirst line has number of test cases, T.\n\nFollowing T lines have N, k separated by a single space where N is the number of \nToGgLe machines and k is the number of times Sheldon clapped.\n\n-----Output-----\nT lines with cach line of the form: \"ON\" (just the word on without the double quotes) if the bulb is 'ON' for the \ntest case numbered n and \"OFF\" (just the word off without the double quotes) if the bulb is 'OFF' for the test case numbered n.\n\n\n-----Example-----\nInput:\n4\n4 0\n4 47\n1 0\n1 1\n\nOutput:\nOFF\nON\nOFF\nON", "starter_code": "", "test_cases": {"inputs": ["4\n4 0\n4 47\n1 0\n1 1"], "outputs": ["OFF\nON\nOFF\nON"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "9c50c4076cf7d9f0ae2d25ef6dd9cb29472570dd", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00452", "original_id": null, "source": "apps", "domain": "code", "problem": "You will be given m strings. For each of those strings, you need to count the total number of appearances of that string as substrings in all possible strings of length n containing only lower case English letters. \n\nA string may appear in a string multiple times. Also, these appearances may overlap. All these must be counted separately. For example, aa appears thrice in the string aaacaa: aaacaa, aaacaa and aaacaa.\n\n-----Input-----\n- The first line contains one integer, T, the number of test cases. The description of each test case follows:\n- The first line of each test case will contain two integers n and m.\n- The ith of the next m lines will have one string in each line. All the strings will consist only of lower case English letters.\n\n-----Output-----\n- For each test case, print \"Case x:\" (without quotes. x is the test case number, 1-indexed) in the first line.\n- Then print m lines. The ith line should contain the number of appearances of the ith string in all possible strings of length n. As the numbers can be very large, print the answers modulo 109+7.\n\n-----Constraints-----\n- 1 ≤ T ≤ 100\n- 1 ≤ n ≤ 100000\n- 1 ≤ m ≤ 1000 \n- 1 ≤ Length of every string in input\n- 1 ≤ Total length of all strings in one test case ≤ 5 * 105\n- 1 ≤ Total length of all strings in one test file ≤ 5 * 106\n\n-----Example-----\nInput:\n3\n2 1\naa\n2 1\nd\n12 3\ncdmn\nqweewef\nqs\n\nOutput:\nCase 1:\n1\nCase 2:\n52\nCase 3:\n443568031\n71288256\n41317270\n\n-----Explanation:-----\nTestcase 1: aa is the only string of length 2 which contains aa as a substring. And it occurs only once. Hence the answer is 1.", "starter_code": "", "test_cases": {"inputs": ["3\n2 1\naa\n2 1\nd\n12 3\ncdmn\nqweewef\nqs\n\n"], "outputs": ["Case 1:\n1\nCase 2:\n52\nCase 3:\n443568031\n71288256\n41317270"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "fa6aad098c1721a7334cad68365fc3a2c1d9fe73", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00457", "original_id": null, "source": "apps", "domain": "code", "problem": "Ted$Ted$ loves prime numbers. One day he is playing a game called legendary$legendary$ with his girlfriend Robin$Robin$. Ted$Ted$ writes a number N$N$ on a table and the number is in the form of :\nN = P1A1 * P2A2 * ……….. * PnAn\nTed$Ted$ asks Robin$Robin$ to find the sum of all the numbers which are less than or equal to N$N$ and also contains all the primes whose minimum power in the number is given by an array B$B$. \nAs Robin$Robin$ is bad with maths she asks your help to answer this question.\n\n-----Input:-----\n- The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows. \n- The first line of each test case contains a single integer n$n$, represents a number of distinct prime numbers.\n- The second line of each test case contains n$n$ space separated distinct prime numbers which represents an array P$P$.\n- The third line of each test case contains n$n$ space separated integers which represents an array A$A$.\n- The fourth line of each test case contains n$n$ space separated integers which represents an array B$B$ \n\n-----Output:-----\nFor each test case, output the Answer Modulo 109 + 7 in a single line.\n\n-----Constraints-----\n- 1≤T≤3$1 \\leq T \\leq 3$\n- 1≤n≤105$1 \\leq n \\leq 10^5$\n- 2≤Pi≤106$2 \\leq P_{i} \\leq 10^6$\n- 1≤Ai≤109$1 \\leq A_{i} \\leq 10^9$\n- 0≤Bi≤Ai$0 \\leq B_{i} \\leq Ai$\n\n-----Sample Input:-----\n1\n3\n2 3 5\n2 1 2\n1 1 1\n\n-----Sample Output:-----\n540\n\n-----EXPLANATION:-----\n22 * 31 * 52= 300 which is N over here. \nThe four numbers less than or equal to 300 are 30, 60, 150 and 300.\n\n30 = 21 * 31 * 51 , 60 = 22 * 31 * 51, 150 = 21 * 31 * 52 and 300 = 22 * 31 * 52. \nIn the 4 numbers, the minimum powers for 2, 3 and 5 are 1, 1 and 1 or more than them in every case.", "starter_code": "", "test_cases": {"inputs": ["1\n3\n2 3 5\n2 1 2\n1 1 1"], "outputs": ["540"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "0ca28c9ee9529bd42b772608974e9cb551236fa9", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00462", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef is going to organize a hill jumping competition and he is going to be one of the judges in it. In this competition there are N hills in a row, and the initial height of i-th hill is Ai. Participants are required to demonstrate their jumping skills by doing what the judges tell them.\nJudges will give each participant a card which has two numbers, i and k, which means that the participant should start at the i-th hill and jump k times, where one jump should be from the current hill to the nearest hill to the right which is strictly higher (in height) than the current one. If there is no such hill or its distance (i.e. difference between their indices) is more than 100 then the participant should remain in his current hill.\nPlease help Chef by creating a program to use it during the competitions. It should read the initial heights of the hill and should support two kinds of operations:\nType 1: Given a two numbers: i and k, your program should output the index of the hill the participant is expected to finish if he starts from the i-th hill (as explained above).\nType 2: Given three numbers: L, R, X, the heights of all the hills between L and R, both end points inclusive, should be increased by X (if X is negative then their height is decreased).\n\n-----Input-----\n- First line contains two integers N and Q, denoting the number of hills and number of operations respectively.\n- Second line contains N space-separated integers A1, A2, ..., AN denoting the initial heights of the hills.\n- Each of the next Q lines describes an operation. If the first integer is equal to 1, it means that the operation is of Type 1, and it will be followed by two integers i and k. Otherwise the first number will be equal to 2, and it means that the operation is of Type 2, and so it will be followed by three integers L, R and X.\n\n-----Output-----\nFor each operation of Type 1, output the index of the hill in which the participant will finish.\n\n-----Constraints-----\n- 1 ≤ N, Q ≤ 100,000\n- 1 ≤ Ai ≤ 1,000,000\n- 1 ≤ L ≤ R ≤ N\n- -1,000,000 ≤ X ≤ 1,000,000\n- 1 ≤ i, k ≤ N\n\n-----Subtasks-----\n- Subtask 1 (20 points) : 1 ≤ N, Q ≤ 1,000 \n- Subtask 2 (80 points) : Original constraints\n\n-----Example-----\nInput:\n5 3\n1 2 3 4 5\n1 1 2\n2 3 4 -1\n1 1 2\n\nOutput:\n3\n4\n\n-----Explanation-----\nThe initial heights are (1, 2, 3, 4, 5). The first operation is of Type 1 and starts from Hill 1 and wants to jump twice. The first jump will be to Hill 2, and the second jump will be to Hill 3. Hence the output for this is 3.\nThe second operation changes the heights to (1, 2, 2, 3, 5).\nThe last operation starts from Hill 1. The first jump is to Hill 2. But the next jump will skip Hill 3 (because it's height is not strictly greater than the current hill's height), and will go to Hill 4. Hence the output is 4.", "starter_code": "", "test_cases": {"inputs": ["5 3\n1 2 3 4 5\n1 1 2\n2 3 4 -1\n1 1 2"], "outputs": ["3\n4"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "55ee15dbc6e3f3937c989820db861ca7025d5031", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00467", "original_id": null, "source": "apps", "domain": "code", "problem": "You have a laser with P amount of energy in it. You are playing a game where you have to use the laser to destroy some crystals, each with some health of their own. Initially, you have 0 points.\nEach crystal has an associated health. The health of the ith crystal is given by health[i]. You can perform one of the two actions:\n- \nAt the cost of health[i] energy, you can destroy the ith crystal and gain 1 point. You can only perform this action if your laser has atleast health[i] energy in it.\n- \nAt the cost of 1 point, you can destroy the ith crystal and refuel the laser's energy by an amount equal to health[i]. This action can only be performed if you have atleast one point.\nNote: Each crystal can only be destroyed once.\nDetermine the maximum number of points you can obtain by destroying any number of crystals and performing either action as you wish.\n\n-----Input:-----\n- First line will contain n, number of crystals. \n- Second line will contain space separated integers, health of each crystal.\n- Third line will contain an integer P, initial energy of the laser.\n\n-----Output:-----\nPrint the largest number of points we can have after destroying any number of crystals.\n\n-----Constraints-----\n- health.length <= 1000\n- 0 <= health[i] < 10000\n- 0 <= P < 10000\n\n-----Subtasks-----\n- 40 points : 1 <= health.length <= 100\n- 60 points : health.length > 100\n\n-----Sample Input 1:-----\n1\n200\n100\n\n-----Sample Output 1:-----\n0\n\n-----Explanation:-----\nThe laser initially has only 100 energy. Since the only crystal requires 200 energy to destroy, we cannot perform any action here, and the game ends. The number of points is zero.\n\n-----Sample Input 2:-----\n2\n100 200\n150\n\n-----Sample Output 2:-----\n1\n\n-----Explanation:-----\nThe laser has 150 energy. We can consume 100 energy and destroy the first crystal and gain 1 point. The remaining energy is 50, which is not enough to destroy the other crystal. We end the game here as we have the maximum possible points attainable.", "starter_code": "", "test_cases": {"inputs": ["1\n200\n100"], "outputs": ["0"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "12e719ee8eb9ce2f57b4a238581ac016a1d91187", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00472", "original_id": null, "source": "apps", "domain": "code", "problem": "The chef was busy in solving algebra, he found some interesting results, that there are many numbers which can be formed by the sum of the factorial of the digits, he wrote all those interesting numbers in the diary(in increasing order) and went to sleep. Cheffina came and stole his diary, in morning chef found that his diary is missing. Now the chef wants your help to find those numbers, Chef asks you whether N is that interesting number or not. If N is an interesting number then print 1. Else print 0. \n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, $N$. \n\n-----Output:-----\nFor each test case, output in a single line answer 1 or 0.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^6$\n- $0 \\leq N \\leq 10^9$\n\n-----Sample Input:-----\n2\n2\n10\n\n-----Sample Output:-----\n1\n0\n\n-----EXPLANATION:-----\nFor 1) Factorial of 2 is 2, hence it is an interesting number.\nFor 2) conversion for 10 is 1! + 0! = 2, which is not equal to 10, hence not an interesting number.", "starter_code": "", "test_cases": {"inputs": ["2\n2\n10"], "outputs": ["1\n0"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "6b7a8ead71651266b6c7e86072c7d9f304956eb3", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00477", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef organised a chess tournament, which spanned over $M$ months. There were $N$ players, and player $i$ was rated $R_i$ before the start of the tournament. To see the progress of the players, he noted their rating changes at the end of each month.\nAfter the tournament, FIDE asked Chef to find the number of players whose peak rating and peak ranking did not occur in the same month. In other words, Chef was asked to find the ratings and ranking of each player after each of the $M$ months. Then, using this data, he should find the number of players, such that the month in which they achieved their highest rating over all the months, was different from the month in which they achieved their best rank (based on ratings), over all the months. Note that we do not consider the initial rating/ranking, but only the rating and rankings after each of the $M$ months. \nFor a particular player, if there are multiple peak rating or peak ranking months, Chef was to consider the earliest of them. If multiple players had the same rating at the end of some month, they were to be given the same rank. For example, if there were $5$ players, and their ratings at the end of some month were $(2600$, $2590$, $2600$, $2600$ and $2590)$, players $1$, $3$ and $4$ were to be given the first rank, while players $2$ and $5$ should be given the fourth rank.\nAs Chef hates statistics, he asks you, his friend, to help him find this. Can you help Chef?\n\n-----Input:-----\n- The first line contains an integer $T$, the number of test cases.\n- The first line of each test case contains two space-separated integers $N$ and $M$, the number of players and the number of months that the tournament spanned over.\n- The second line of each test case contains $N$ space-separated integers, $R_1, R_2, \\ldots, R_N$ denoting the initial ratings of the players, i.e., their ratings before the start of the tournament.\n- The next $N$ lines each contain $M$ space-separated integers. The $j^{th}$ integer of the $i^{th}$ line, $C_{i,j}$ denotes the rating change of the $i^{th}$ player after the $j^{th}$ month.\n\n-----Output:-----\nFor each test case, print the number of players whose peak ratings did not occur in the same month as their peak ranking, in a new line.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $1 \\le N,M \\le 500$\n- $1800 \\le R_i \\le 2800$\n- $-20 \\le C_{i,j} \\le 20$\n\n-----Subtasks-----\n- 30 points : $1 \\leq N,M \\leq 50$\n- 70 points : Original constraints.\n\n-----Sample Input:-----\n2\n3 3\n2500 2500 2520\n10 -5 -20\n10 15 20\n-15 17 13\n2 3\n2125 2098\n-20 10 -10\n10 10 -20\n\n-----Sample Output:-----\n2\n2\n\n-----Explanation:-----\nTest case 1:\n- \nThe ratings for player $1$ after each month are: $(2510$, $2505$ and $2485)$, while his rankings are first, third and third, respectively. Thus, his best rating and best ranking occur after the same month, i.e., after the first month.\n- \nThe ratings for player $2$ after each month are: $(2510$, $2525$ and $2545)$, while his rankings are first, first and first, respectively. His best rating occurs after the third month, while his best ranking occurs after the first month (we consider the first month even though his peak ranking is over all the months, because we consider only the earliest month where he attains the peak ranking).\n- \nThe ratings for player $3$ after each month are: $(2505$, $2522$ and $2535)$, while his rankings are third, second and second, respectively. His best rating occurs after the third month, while his best ranking occurs after the second month.\nSo there are two players ($2$ and $3$), whose peak ratings did not occur in the same month as their peak ranking, and hence the answer is 2.\nTest case 2:\n- \nThe ratings for player $1$ after each month are: $(2105$, $2115$ and $2105)$, while his rankings are second, second and first, respectively. Best rating is after second month, but best ranking is after third month.\n- \nThe ratings for player $2$ after each month are: $(2108$, $2118$ and $2098)$, while his rankings are first, first and second, respectively. Best rating is after second month, but best ranking is after first month.\nSo there are two players ($1$ and $2$), whose peak ratings did not occur in the same month as their peak ranking, and hence the answer is 2.", "starter_code": "", "test_cases": {"inputs": ["2\n3 3\n2500 2500 2520\n10 -5 -20\n10 15 20\n-15 17 13\n2 3\n2125 2098\n-20 10 -10\n10 10 -20"], "outputs": ["2\n2"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "a4d2146c0b0fe3b79067192ab4c5a9ccf8a70870", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00482", "original_id": null, "source": "apps", "domain": "code", "problem": "Sereja has an array A of N positive integers : A[1], A[2], A[3], ... , A[N]. \n\nIn a single operation on the array, he performs the following two steps : \n\n- Pick two indices i, j s.t. A[i] > A[j]\n- A[i] -= A[j]\n\nSereja can apply these operations any number of times (possibly zero), such that the sum of resulting elements of the array is as small as possible.\n\nHelp Sereja find this minimum sum.\n\n-----Input-----\n\nFirst line of input contains an integer T - the number of test cases. T test cases follow.\n\nFirst line of each test case contains the integer N. The next line contains N integers — A[1], A[2], A[3], ... , A[N].\n\n-----Output-----\nFor each test case, output a single line with the answer.\n\n-----Constraints-----\n- 1 ≤ T ≤ 10\n- 1 ≤ N ≤ 105\n- 1 ≤ A[i] ≤ 109\n\n-----Example-----\nInput:\n2\n1\n1\n3\n2 4 6\n\nOutput:\n1\n6\n\n-----Explanation-----\nExample case 2. In this case, one possible way in which Sereja can perform the operations could be as follows. \n\n- Pick i = 2, j = 1. A[2] -= A[1]. Now the resulting array would be [2, 2, 6].\n- Pick i = 3, j = 2. A[3] -= A[2]. Now the resulting array would be [2, 2, 4].\n- Pick i = 3, j = 2. A[3] -= A[2]. Now the resulting array would be [2, 2, 2]. \n\nAs the resulting array is [2 2 2], so the sum is 6.", "starter_code": "", "test_cases": {"inputs": ["2\n1\n1\n3\n2 4 6"], "outputs": ["1\n6"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "0b315d7ba691849f9428e53e45c0c1c47e3c8091", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00487", "original_id": null, "source": "apps", "domain": "code", "problem": "Snackdown 2019 is coming! People have started to spread the word and tell other people about the contest.\nThere are $N$ people numbered $1$ through $N$. Initially, only person $1$ knows about Snackdown. On each day, everyone who already knows about Snackdown tells other people about it. For each valid $i$, person $i$ can tell up to $A_i$ people per day. People spread the information among the people who don't know about Snackdown in the ascending order of their indices; you may assume that no two people try to tell someone about Snackdown at the same moment. Each person is only allowed to start telling other people about Snackdown since the day after he/she gets to know about it (person $1$ can start telling other people already on day $1$). How many days does it take for all people to know about Snackdown?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\dots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer — the number of days.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $2 \\le N \\le 10^5$\n- the sum of $N$ for all test cases does not exceed $10^6$\n- $0 \\le A_i \\le N$ for each valid $i$\n- $1 \\le A_1$\n\n-----Example Input-----\n2\n7\n2 1 1 5 5 5 5\n5\n5 1 3 2 1\n\n-----Example Output-----\n2\n1\n\n-----Explanation-----\nExample case 1: On day $1$, person $1$ tells people $2$ and $3$ about Snackdown. On day $2$, the first three people know about Snackdown, so they can tell $2+1+1 = 4$ people about it in a single day. That means the last four people get to know about Snackdown on day $2$, so the total number of days is $2$.\nExample case 2: On each day, person $1$ can tell up to $5$ people about Snackdown, so on the first day, he simply tells all people about it and the total number of days is $1$.", "starter_code": "", "test_cases": {"inputs": ["2\n7\n2 1 1 5 5 5 5\n5\n5 1 3 2 1"], "outputs": ["2\n1"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "6241f35079f1582a72a4dbd50bbbbe3eb943df80", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00492", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef has been working in a restaurant which has N floors. He wants to minimize the time it takes him to go from the N-th floor to ground floor. He can either take the elevator or the stairs. \nThe stairs are at an angle of 45 degrees and Chef's velocity is V1 m/s when taking the stairs down. The elevator on the other hand moves with a velocity V2 m/s. Whenever an elevator is called, it always starts from ground floor and goes to N-th floor where it collects Chef (collecting takes no time), it then makes its way down to the ground floor with Chef in it. \n\nThe elevator cross a total distance equal to N meters when going from N-th floor to ground floor or vice versa, while the length of the stairs is sqrt(2) * N because the stairs is at angle 45 degrees.\n\nChef has enlisted your help to decide whether he should use stairs or the elevator to minimize his travel time. Can you help him out?\n\n-----Input-----\nThe first line contains a single integer T, the number of test cases. Each test case is described by a single line containing three space-separated integers N, V1, V2. \n\n-----Output-----\nFor each test case, output a single line with string Elevator or Stairs, denoting the answer to the problem.\n\n-----Constraints-----\n- 1 ≤ T ≤ 1000 \n- 1 ≤ N, V1, V2 ≤ 100 \n\n-----Example-----\nInput:\n3\n5 10 15\n2 10 14\n7 14 10\n\nOutput:\nElevator\nStairs\nStairs", "starter_code": "", "test_cases": {"inputs": ["3\n5 10 15\n2 10 14\n7 14 10"], "outputs": ["Elevator\nStairs\nStairs"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "5ee42717f1f4438f842a26bd021ce50eedcbbf6f", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00497", "original_id": null, "source": "apps", "domain": "code", "problem": "There is crazy man named P29892P. He always tries to do crazy things as he thinks. One day he invented a machine and named it as ANGEN. The ANGEN is used to perform range operations. The range operation means performing operations on range values from {L..R}. At any time it performs operations on values in between L to R.\nANGEN can perform following operations\nU I V - Update the value present at I with value V\nA L R - Find the sum between range L and R\nM L R - Find the maximum number between L and R\nm L R - Find the minimum number between L and R\nS L R - Find second maximum value in between L and R\ns L R - Find second mimimum value in between L and R\nIf it is not possible perform operation ANGEN returns “NA” with out quotes.\nFor Invalid operations ANGEN returns “!!!” with out quotes.\nNow P29892P challenging his friends and you too, to build his invention with yourown code. So it's your time to defeat P29892P by implementing his invention with your own ability. Let's go and solve the problem.\n\n-----Input-----\nInput description.\n- The first line of the input contains an integer N denoting the number of integers. \n- The next line contains N space separated integers.\"\n- The next line contains a single integer Q denoting the number of Questions.\n- The next Q lines contains T Question type , L and R.\n\n-----Output-----\nPrint output for each question in separate line.\n\n-----Constraints-----\nShould contain all the constraints on the input data that you may have. Format it like:\n- 1 ≤ N ≤ 100000\n- 1 ≤ values[i] ≤ 1000000000\n- 1 ≤ Q ≤ 10000\n- T in { A..Z, a..z }\n- 1 ≤ L ≤ R ≤ N\n\n-----Example-----\nInput:\n6\n1 2 5 3 10 6\n6\nA 1 5\nM 1 3\nm 5 6\ns 3 6\nU 1 7\nS 1 2\n\nOutput:\n21\n5\n6\n5\n2\n\n-----Explanation-----\n...", "starter_code": "", "test_cases": {"inputs": ["6\n1 2 5 3 10 6\n6\nA 1 5\nM 1 3\nm 5 6\ns 3 6\nU 1 7\nS 1 2"], "outputs": ["21\n5\n6\n5\n2"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "d26d576c0bc167dbba3207ad1f2714dd8f49a625", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00502", "original_id": null, "source": "apps", "domain": "code", "problem": "For years you have been working hard in Santa's factory to manufacture gifts for kids in substandard work environments with no pay. You have finally managed to escape the factory and now you seek revenge. You are planning a heist with the Grinch to steal all the gifts which are locked in a safe. Since you have worked in the factory for so many years, you know how to crack the safe.\nThe passcode for the safe is an integer. This passcode keeps changing everyday, but you know a way to crack it. You will be given two numbers A and B .\nPasscode is the number of X such that 0 ≤ X < B and\ngcd(A,B) = gcd(A+X,B).\nNote : gcd(A,B) is the greatest common divisor of A & B.\n\n-----Input-----\nThe first line contains the single integer T (1 ≤ T ≤ 50) — the number of test cases.\nNext T lines contain test cases per line. Each line contains two integers A & B \n( 1 ≤ A < B ≤ 1010 )\n\n-----Output-----\nPrint T integers, one for each Test case. For each test case print the appropriate passcode for that day.\n\n-----Sample Input-----\n3\n4 9\n5 10\n42 9999999967\n\n-----Output-----\n6\n1\n9999999966", "starter_code": "", "test_cases": {"inputs": ["3\n4 9\n5 10\n42 9999999967"], "outputs": ["6\n1\n9999999966"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "d8276603125107ff1a1b3c889f5244c48d94d211", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00507", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef gives an integer $K$ in the input. If the given number is beautiful binary number, print it, Else find its previous beautiful binary number. A beautiful binary number is a number whose binary representation does not contain any consecutive 1s.\nNote: 1 is also a beautiful binary number.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, print a beautiful number.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq K \\leq 10^5$\n\n-----Sample Input:-----\n3\n3\n6\n8\n\n-----Sample Output:-----\n2\n5\n8\n\n-----EXPLANATION:-----\nFor 1) 3 is not a beautiful binary number because the binary representation of 3 is \"11\" which has consecutive 1s. hence 2 which is less than 3 is printed.\nFor 3) 8 is already a beautiful binary number with no consecutive 1s in its binary representation. so, print 8 as it is.", "starter_code": "", "test_cases": {"inputs": ["3\n3\n6\n8"], "outputs": ["2\n5\n8"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "fb4accd8db779e44ce0a11dd7851c89ebb506696", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00512", "original_id": null, "source": "apps", "domain": "code", "problem": "You are given a square matrix $M$ with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$). Initially, all the elements of this matrix are equal to $A$. The matrix is broken down in $N$ steps (numbered $1$ through $N$); note that during this process, some elements of the matrix are simply marked as removed, but all elements are still indexed in the same way as in the original matrix. For each valid $i$, the $i$-th step consists of the following:\n- Elements $M_{1, N-i+1}, M_{2, N-i+1}, \\ldots, M_{i-1, N-i+1}$ are removed.\n- Elements $M_{i, N-i+1}, M_{i, N-i+2}, \\ldots, M_{i, N}$ are removed.\n- Let's denote the product of all $2i-1$ elements removed in this step by $p_i$. Each of the remaining elements of the matrix (those which have not been removed yet) is multiplied by $p_i$.\nFind the sum $p_1 + p_2 + p_3 + \\ldots + p_N$. Since this number could be very large, compute it modulo $10^9+7$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $N$ and $A$.\n\n-----Output-----\nFor each test case, print a single line containing one integer ― the sum of products at each step modulo $10^9+7$.\n\n-----Constraints-----\n- $1 \\le T \\le 250$\n- $1 \\le N \\le 10^5$\n- $0 \\le A \\le 10^9$\n- the sum of $N$ over all test cases does not exceed $10^5$\n\n-----Example Input-----\n1\n3 2\n\n-----Example Output-----\n511620149\n\n-----Explanation-----\nExample case 1:", "starter_code": "", "test_cases": {"inputs": ["1\n3 2"], "outputs": ["511620149"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "a334222f2549008a7ec8228709556bb4f5311f61", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00517", "original_id": null, "source": "apps", "domain": "code", "problem": "It's John's birthday; he has brought some candies in distribute among N of his friends. Being a good friend, he decided to distribute all of his candies equally among his friend and he don't want to keep any for himself. He left the task of distributing candies up to his friends, but his friends haven't done a great job in distributing them and now they all have unequal amount of candies.\nHe asked all of his friends to keep all the candies in their hands (A[1] to A[N]) so that he can redistribute the candies. Taking a candy away from someone makes them sad and makes the person who gets it happy. Thus, you do not want to do many operations on the number of candies.\nHere each operation stands for, taking away 1 candy from someone and giving it to somebody else.\nAfter applying the operations, he might not be able to distribute all the candies among all of your friends, and you might need to buy some more candies as well. Buying each candy will be counted as 1 operation as well. John is saving up for his birthday party in the evening and so he wants to spend the least amount of money on candies as possible.\nThus, he asks for your help. You have to find the minimum number of operations required to make the distributions equal.\n\n-----Input:-----\n- The first line consists of the number T representing the number of test cases.\n- Each test case consists of 2 lines.\n- The first line contains of the number N representing the number of friends.\n- The second line contains space separated numbers (A[1] to A[N]) representing the number of candies each friend currently has.\n\n-----Output:-----\nFor each test case, you much print the minimum number of operations.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^5$\n- $0 \\leq A[i] \\leq 10^9$\n\n-----Sample Input:-----\n3\n\n4\n\n7 8 6 4\n\n6\n\n7 3 10 2 3 8\n\n1\n\n10 \n\n-----Sample Output:-----\n4\n\n10\n\n0", "starter_code": "", "test_cases": {"inputs": ["3\n4\n7 8 6 4\n6\n7 3 10 2 3 8\n1\n10"], "outputs": ["4\n10\n0"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "b86d0d9b69d5294891a7dd6c78bcd35b48a1e9e4", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00522", "original_id": null, "source": "apps", "domain": "code", "problem": "All strings in Chefland are beautiful because they are binary strings (a binary string contains only characters '0' and '1'). The beauty of a binary string $S$ is defined as the number of pairs $(i, j)$ ($1 \\le i \\le j \\le |S|$) such that the substring $S_i, S_{i+1}, \\ldots, S_j$ is special.\nFor a binary string $U$, let's denote the number of occurrences of the characters '1' and '0' in $U$ by $cnt_1$ and $cnt_0$ respectively; then, $U$ is special if $cnt_0 = cnt_1 \\cdot cnt_1$.\nToday, Chef's friend Araspa is celebrating her birthday. Chef wants to give Araspa the most beautiful binary string he can find. Currently, he is checking out binary strings in a shop, but he needs your help to calculate their beauties. Tell Chef the beauty of each binary string he gives you.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single string $S$.\n\n-----Output-----\nFor each test case, print a single line containing one integer — the beauty of the string $S$.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $1 \\le |S| \\le 10^5$\n- each character of $S$ is '0' or '1'\n\n-----Example Input-----\n2\n010001\n10\n\n-----Example Output-----\n4\n1\n\n-----Explanation-----\nExample case 1: The special substrings correspond to $(i, j) = (1, 2), (1, 6), (2, 3), (5, 6)$.", "starter_code": "", "test_cases": {"inputs": ["2\n010001\n10"], "outputs": ["4\n1"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "c6a4c20c9e66be95d947af1019cdd4a3b0edd0b4", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00527", "original_id": null, "source": "apps", "domain": "code", "problem": "Every Friday Chef and his N - 1 friends go for a party. At these parties, they play board games. This Friday, they are playing a game named \"Boats! Boats! Boats!\". In this game players have to transport cookies between Venice and Constantinople. Each player has a personal storage. The players are numbered from 1 to N, Chef is numbered 1. Rules for determining a winner are very difficult, therefore Chef asks you to write a program, which will determine who is a winner. \n\nThere are 6 types of cookies. For each cookie in the storage player gets 1 point. Also player gets additional points if he packs his cookies in some boxes as follows: \n\n- A box containing 4 different types of cookies fetches 1 additional point.\n- A box containing 5 different types of cookies fetches 2 additional points.\n- A box containing 6 different types of cookies fetches 4 additional points.\n\nObviously a cookie can be put into a single box.\n\nFor each player, you know the number of cookies in his storage (denoted by c[i]), also the types of cookies in the storage given denoted by type[i][j].\n\nYour task is to determine the winner of this game. Output \"tie\" if there are two or more players with same maximum score, \"chef\" if only Chef has a maximum score, winner's index in all other cases.\n\n-----Input-----\n\nThe first line of input contains a single integer T denoting the number of test cases. This will be followed by T test cases.\nThe first line of each test case contains an integer N denoting the number of players.\nThe second line of each test case contains an integer c[i] denoting the number of cookies in the i-th storage, followed by c[i] space-separated integers type[i][j] which denote the type if j-th cookie in the storage i-th.\n\n-----Output-----\nFor each test case, output a single line containing the answer as specified in the statement.\n\n-----Constraints and Subtasks-----Subtask #1 : (20 points) \n\n- 1 ≤ T ≤ 10 \n- 1 ≤ N ≤ 100 \n- 1 ≤ c[i] ≤ 100 \n- 1 ≤ type[i][j] ≤ 3 \nSubtask #2 : (80 points) \n\n- 1 ≤ T ≤ 10 \n- 1 ≤ N ≤ 100 \n- 1 ≤ c[i] ≤ 100 \n- 1 ≤ type[i][j] ≤ 6 \n\n-----Example-----\nInput:\n3\n2\n6 1 2 3 4 5 6\n9 3 3 3 4 4 4 5 5 5\n2\n5 2 3 4 5 6\n7 1 1 2 2 3 3 4\n3\n4 1 1 2 3\n4 1 2 2 3\n4 1 2 3 3\nOutput:\nchef\n2\ntie\n\n-----Explanation-----\nExample case 1.\nChef has total 6 cookie, so he gets 6 points for that. Also, he can put all his cookies (as they are all distinct) in a bag of size 6. It will fetch him additional 4 points. So, Chef's total points will be 10.\nThe second player has 9 cookies, he gets 9 points for that. Other than this, he can't create a bag with either 4, 5 or 6 distinct cookies. So, his final score is 9.\n10 > 9 - Chef wins.\nExample case 2.\nChef has 5 + 2 (a bag with 5 different cookies) = 7.\nThe second player has 7 + 1(a bag with 4 different cookies) = 8.\n7 < 8 - the second player wins.\nExample case 3.\nEvery player has 4 cookies and can't create any bag of sweets. So, it's a tie.", "starter_code": "", "test_cases": {"inputs": ["3\n2\n6 1 2 3 4 5 6\n9 3 3 3 4 4 4 5 5 5\n2\n5 2 3 4 5 6\n7 1 1 2 2 3 3 4\n3\n4 1 1 2 3\n4 1 2 2 3\n4 1 2 3 3"], "outputs": ["chef\n2\ntie"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "a308352901335f5d54f0e36451cd6232797923d9", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00532", "original_id": null, "source": "apps", "domain": "code", "problem": "Gargi is thinking of a solution to a problem. Meanwhile, her friend asks her to solve another problem. Since Gargi is busy in her own problem, she seeks your help to solve the new problem.\n\nYou are given a string S containing characters a-z (lower case letters) only. You need to change the string to a new string consisting of only one letter from a-z.\n\nFor a given character S[i] in the string, if you change it to a character having lower ASCII value than the character S[i], you gain points equal to the difference in ASCII value of the old character and the new character. Similarly, for a given character S[j] in the string, if you change it to a character having higher ASCII value than the character S[j], you lose points equal to the difference in ASCII value of the old character and the new character.\n\nHowever, Gargi does not like gaining or losing points. She has asked you to change the string in such a way that the total losing or gaining of points at the end of the string conversion is minimum.\n\nGive Gargi the absolute value of the points you have at the end of the string conversion.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\n\nThe first line of each of the T test case contains a string S containing only lower case characters (a-z)\n\n-----Output-----\nFor each test case, output a single line containing the answer.\n\n-----Constraints-----\n- 1 ≤ T ≤ 10\n- 1 ≤ |S| ≤ 100000\n\n-----Example-----\nInput:\n1\nabba\n\nOutput:\n2\n\n-----Explanation-----\nExample case 1. The new string can be aaaa where you have +2 points at the end of string conversion or it can be bbbb where you have -2 points at the end of string conversion. Hence the output is 2.", "starter_code": "", "test_cases": {"inputs": ["1\nabba"], "outputs": ["2"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "6e7c17a0f0a8ebd235ea43d748853467f7e31910", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00537", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a positive integer K > 2, with prime\nfactorization:\n\nK = p1^a1 * p2^a2 ... * pn^an\n\nCompute the following:\n\nS = a1*p1 + a2*p2 ... + an*pn.\n\n-----Input-----\nA list of <100 integers, one on each line,\nall less than $2*10^{18}$.\n\n-----Output-----\nFor each integer compute the super factor\nsum and output it on a single line.\n\n-----Example-----\nInput:\n6\n7\nOutput:\n5\n7", "starter_code": "", "test_cases": {"inputs": ["6\n7"], "outputs": ["5\n7"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "c63ac411a421bf56ae38401156ab8ce425448195", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00542", "original_id": null, "source": "apps", "domain": "code", "problem": "There are n villages in a Chefland. Some of the villages have electricity facilities, other doesn't. You can consider the villages arranged in line in the order 1 to n from left to right. i-th of village can be considered at xi coordinates.\n\nChef decided that electricity should be provided to all the villages. So, he decides to buy some amount of electric wires to connect the villeges without electricity to some villages with electricity. As Chef does not want to spend too much amount of money on wires, can you find out minimum amount of length of wire Chef should buy.\n\n-----Input-----\nFirst line of the input contains an integer T denoting the number of test cases. T test cases follow.\nFirst line of each test case contains an integer n denoting number of villages in Chefland.\nSecond line will contain a string of length n containing '0' or '1's only. If i-th character of the string is '1', then it denotes that i-th village has electricity.\nNext line contains n space separated integers denoting the x coordinates of the villages in the order from village 1 to n\n\n-----Output-----\nFor each test case, output a single line containing a integer corresponding to the minimum length of wire Chef needs to buy.\n\n-----Constraints-----\n- 1 ≤ T ≤ 10\n- It is guaranteed that there will be at least one village which will have electricity.\n- 1 ≤ x1 < x2 < ... < xn ≤ 109\n\n-----Subtasks-----\nSubtask #1 : 30 points\n- 1 ≤ N ≤ 1000\n\nSubtask #2 : 70 points\n- 1 ≤ N ≤ 105\n\n-----Example-----\nInput\n2\n2\n01\n1 2\n3\n100\n1 5 6\nOutput:\n1\n5\n\n-----Explanation-----\nIn the first example, first village does not have electricity. If we put a wire between village 1 and 2 of length 1, then both the villages will have electricity.\n\nIn the second example,\nWe can a draw a wire from first village to third village, passing through second village. Its total length will be 5. Now all the villages will have electricity. This is the minimum length of wire you will require.", "starter_code": "", "test_cases": {"inputs": ["2\n2\n01\n1 2\n3\n100\n1 5 6"], "outputs": ["1\n5"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "b6b5ef8dd9fa0348ad8e0241eb49e332773efc51", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00547", "original_id": null, "source": "apps", "domain": "code", "problem": "Everyone loves short problem statements.\nGiven a function $ f(x) $ find its minimum value over the range $ 0 < x < π/2$\n$\nf(x) = ( x^2 + b*x + c ) / sin( x )\n$\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, two real numbers $b, c$. \n\n-----Output:-----\nFor each test case, output the minimum value of $ f(x) $ over the given range. Absolute error of $10^{-6}$ is allowed.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100000$\n- $1 \\leq b,c \\leq 20$\n\n-----Sample Input:-----\n1\n2 2\n\n-----Sample Output:-----\n5.8831725615", "starter_code": "", "test_cases": {"inputs": ["1\n2 2"], "outputs": ["5.8831725615"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "4b0bb0a057bc0831667025149ff442f20f34830b", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00552", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef likes to travel a lot. Every day Chef tries to visit as much cities as possible. Recently he had a quite a few trips of great Chefland for learning various recipes. Chefland had N cities numbered from 1 to N. People in Chefland are very friendly, friendliness of i-th city is given by Fi.\n\nBefore starting of each trip, Chef's initial enjoyment is 1 unit. Whenever he visits a city with friendliness Fi, his enjoyment gets multiplied by Fi units. \n\nCity 1 is the home city of Chef. He starts each trip from his home city. Before starting a trip, he chooses a parameter R which denotes that he will start from city 1, and go to city 1 + R, then to 1 + 2 * R, then to 1 + 3 * R, till 1 + i * R such that i is largest integer satisfying 1 + i * R ≤ N.\n\nNow, Chef wants you to help him recreate his visit of the cities. Specifically, he will ask you Q queries, each of which can be of following two types.\n\n- 1 p f : friendliness of p-th city changes to f, i.e. Fp = f \n- 2 R : Find out the total enjoyment Chef will have during this trip. As Chef does not like big numbers, he just asks you to output two things, first digit of the enjoyment and value of enjoyment modulo 109 + 7.\n\n-----Input-----\nThere is a single test case.\nFirst line of input contains a single integer N, denoting number of cities in Chefland.\nSecond line of the input contains N space separated integer - F1, F2, ..., FN, denoting the friendliness of the cities in order from 1 to N.\nNext line contains an integer Q, denoting number of queries.\n\nFor each of the next Q queries, each line corresponds to one of the two types of the query. First there will be an integer denoting the type of the query, followed by the actual query. For query of type 1, there will be three space separated integers \"1 p f\" as defined above. For query of type 2, there will be two space separated integers \"2 R \", as defined above.\n\n-----Output-----\nFor each query of type 2, output two space separated integers, first digit of Chef's enjoyment in this trip followed by the value of enjoyment modulo 109 + 7.\n\n-----Constraints-----\n- 1 ≤ N, Q ≤ 105 \n- 1 ≤ Fi ≤ 10^9 \n- 1 ≤ f ≤ 10^9 \n- 1 ≤ p ≤ N \n- 1 ≤ R ≤ N \n\n-----Subtasks-----\nSubtask #1 (5 points) : \n\n- 1 ≤ N ≤ 10 \n- 1 ≤ Q ≤ 1000 \n- 1 ≤ Fi ≤ 10 \n- 1 ≤ f ≤ 10 \n\nSubtask #2 (15 points) : \n\n- 1 ≤ N ≤ 1000 \n- 1 ≤ Q ≤ 100 \n- 1 ≤ Fi ≤ 109 \n- 1 ≤ f ≤ 1000 \n\nSubtask #3 (80 points) : \n\n- original constraints\n\n-----Example-----\nInput:\n5\n1 2 3 4 5\n3\n2 1\n1 3 10\n2 2\n\nOutput:\n1 120\n5 50\n\n-----Explanation-----\nIn the first query, Chef is going to visit cities 1, 2, 3, 4, 5 in order. At the end of the trip, his total enjoyment will be 1 * 2 * 3 * 4 * 5 = 120. First digit of enjoyment is 1 and 120 modulo 109 + 7 is 120.\nIn the third query, Chef is going to visit cities 1, 3, 5 in order. At the end of the trip, his total enjoyment will be 1 * 10 * 5 = 50.", "starter_code": "", "test_cases": {"inputs": ["5\n1 2 3 4 5\n3\n2 1\n1 3 10\n2 2"], "outputs": ["1 120\n5 50"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "fae673a68f64d471b28a301561e28ea6f285672c", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00557", "original_id": null, "source": "apps", "domain": "code", "problem": "Sultan, the freestyle wrestler, you all know him. He broke multiple records in the history of all wrestling leagues. Now 20 years have passed, Sultan has grown old. He has two sons, he wants them to be like him. Sultan being orthodox goes to his astrologer, where he is told that his sons shall be invincible like him. \nSultan starts to train them. After training, his son Multan & Fultan, having strengths are M and F respectively, decide to fight. They can defeat if the strength of challengers Si is a positive integer multiple of their strength else they lose. Multan fights first, then Fultan. A challenger once knocked out cannot challenge them again. Sultan's sons are still not very good wrestlers. Sultan considers them wrestlers if they both combined are able to win at least 70% of the all the fights. Also, he wants to know who is a better wrestler of the two. Your task is to help Sultan in this venture. Print \"Yes\" (without quotes) if they are able to win, else print \"No\" (without quotes). If yes, also name whether, \"Multan\" or \"Fultan\" is a better wrestler, if both win equally print “Both”.\n\n-----Input-----\n- First line contains single integer T denoting test cases.\n- Second Line contains single integer N for number of challengers.\n- Third Line contains space separated two integer denoting strength M & F\n- Next Line contains strength space separated N integer ith of which denoting Si of N challengers respectively.\n\n-----Output-----\n- Yes or No corresponding the result.\n- Also, if Yes, print, Multan, Fultan, Both accordingly. \n\n-----Constraints-----\n- 1 ≤ T ≤ 100\n- 1 ≤ N ≤ 1000\n- 1 ≤ M, F ≤ 109\n- 0 ≤ Si ≤ 109\n\n-----Example-----\nInput:\n2\n7\n2 3\n4 5 7 8 9 10 14\n6\n5 7\n1 2 8 9 10 11\n\nOutput:\nYes\nMultan\nNo\n\n\n-----Explanation-----\nExample case 1.\n\nMultan (M) defeats total 4 challengers with strengths 4, 8, 10, 14 and Fultan (F) defeats 1 challenger with strength 9. Their total wins are 5 out of 7 and win accuracy of 71.4%. Hence, 'Yes' and since Multan is better wrestler so 'Multan'\n\nExample case 2.\nMultan defeats 1 and Fultan defeat 0 challengers. Total wins 1 out of 6 with accuracy 16.67% Hence, No.", "starter_code": "", "test_cases": {"inputs": ["2\n7\n2 3\n4 5 7 8 9 10 14\n6\n5 7\n1 2 8 9 10 11"], "outputs": ["Yes\nMultan\nNo"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "c1fad56c8a61bfc1b83a0e660a11033a71fc244b", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00562", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an Integer N, write a program to reverse it.\n\n-----Input-----\n\nThe first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N. \n\n-----Output-----\nFor each test case, display the reverse of the given number N, in a new line.\n\n-----Constraints-----\n- 1 ≤ T ≤ 1000\n- 1 ≤ N ≤ 1000000\n\n-----Example-----\nInput\n4\n12345\n31203\n2123\n2300\nOutput\n54321\n30213\n3212\n32", "starter_code": "", "test_cases": {"inputs": ["4\n12345\n31203\n2123\n2300"], "outputs": ["54321\n30213\n3212\n32"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "1ea10b007fd601f55dc7e9b400edb5b2ada563aa", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00567", "original_id": null, "source": "apps", "domain": "code", "problem": "You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \\cdot t$, where $Q(0)$ is the initial position of $Q$.\nIt is guaranteed that $Q$ is not visible from $P$ initially (at time $t=0$). It is also guaranteed that $P$ and $Q$ do not touch the sphere at any time.\nFind the smallest positive time $t_v$ when $Q$ is visible from $P$, i.e. when the line segment connecting points $P$ and $Q$ does not intersect the sphere.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains 13 space-separated integers.\n- The first three integers $P_x, P_y, P_z$ denote the coordinates of $P$.\n- The next three integers $Q_x, Q_y, Q_z$ denote the initial coordinates of $Q$.\n- The next three integers $d_x, d_y, d_z$ denote the components of the direction vector $d$.\n- The last four integers $c_x, c_y, c_z, r$ denote the coordinates of the centre of the sphere and its radius.\n\n-----Output-----\nFor each test case, print a single line containing one real number — the time $t_v$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $t_v$ exists and does not exceed $10^9$.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- the absolute values of coordinates of all points do not exceed $2\\cdot10^9$\n- $1 \\le r \\le 10^9$\n\n-----Subtasks-----\nSubtask #1 (25 points): $P_z = Q_z = d_z = c_z = 0$\nSubtask #2 (75 points): original constraints\n\n-----Example Input-----\n1\n3 0 0 -10 -10 0 0 10 0 0 -3 0 3\n\n-----Example Output-----\n1.0000000000", "starter_code": "", "test_cases": {"inputs": ["1\n3 0 0 -10 -10 0 0 10 0 0 -3 0 3"], "outputs": ["1.0000000000"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "51c3347bcfc7991557b816dd4143e4bdc48d0b92", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00572", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef's dog Snuffles has so many things to play with! This time around, Snuffles has an array A containing N integers: A1, A2, ..., AN.\nBad news: Snuffles only loves to play with an array in which all the elements are equal.\nGood news: We have a mover of size D. ! \nA mover of size D is a tool which helps to change arrays. Chef can pick two existing elements Ai and Aj from the array, such that i + D = j and subtract 1 from one of these elements (the element should have its value at least 1), and add 1 to the other element. In effect, a single operation of the mover, moves a value of 1 from one of the elements to the other.\nChef wants to find the minimum number of times she needs to use the mover of size D to make all the elements of the array A equal. Help her find this out.\n\n-----Input-----\n- The first line of the input contains an integer T, denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains two integers N and D, denoting the number of elements in the array and the size of the mover. \n- The second line of each testcase contains N space-separated integers: A1, A2, ..., AN, denoting the initial elements of the array. \n\n-----Output-----\n- For each test case, output a single line containing the minimum number of uses or -1 if it is impossible to do what Snuffles wants.\n\n-----Constraints-----\n- 1 ≤ T ≤ 10\n- 2 ≤ N ≤ 105\n- 1 ≤ D < N\n- 1 ≤ Ai ≤ 109\n\n-----Subtasks-----\n- Subtask 1 (30 points) : N ≤ 103\n- Subtask 2 (70 points) : Original constraints\n\n-----Example-----\nInput:\n3\n5 2\n1 4 5 2 3\n3 1\n1 4 1\n4 2\n3 4 3 5\n\nOutput:\n3\n2\n-1\n\n-----Explanation-----\nTestcase 1:\nHere is a possible sequence of usages of the mover:\n- Move 1 from A3 to A1\n- Move 1 from A3 to A1\n- Move 1 from A2 to A4\nAt the end, the array becomes (3, 3, 3, 3, 3), which Snuffles likes. And you cannot achieve this in fewer moves. Hence the answer is 3.\nTestcase 2:\nHere is a possible sequence of usages of the mover:\n- Move 1 from A2 to A1\n- Move 1 from A2 to A3\nAt the end, the array becomes (2, 2, 2), which Snuffles likes. And you cannot achieve this in fewer moves. Hence the answer is 2.\nTestcase 3:\nIt is impossible to make all the elements equal. Hence the answer is -1.", "starter_code": "", "test_cases": {"inputs": ["3\n5 2\n1 4 5 2 3\n3 1\n1 4 1\n4 2\n3 4 3 5"], "outputs": ["3\n2\n-1"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "5ee129198bd38efa0020e59f3a74fe60e40ed1c3", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00577", "original_id": null, "source": "apps", "domain": "code", "problem": "Zonal Computing Olympiad 2013, 10 Nov 2012\n\nLittle Red Riding Hood is carrying a basket with berries through the forest to her grandmother's house. The forest is arranged in the form of a square N × N grid of cells. The top left corner cell, where Little Red Riding Hood starts her journey, is numbered (1,1) and the bottom right corner cell, where her grandmother lives, is numbered (N,N). In each step, she can move either one position right or one position down.\n\nThe forest is full of dangerous wolves and she is looking for a safe path to reach her destination. Little Red Riding Hood's fairy godmother has placed some special anti-wolf magical charms in some of the cells in the grid. Each charm has a strength. If the charm in cell (i,j) has strength k then its zone of influence is all the cells within k steps of (i,j); that is, all cells (i',j') such that |i - i'| + |j - j'| ≤ k. A cell within the zone of influence of a charm is safe from wolves. A safe path from (1,1) to (N,N) is one in which every cell along the path is safe.\n\nLittle Red Riding Hood is carrying a basket with berries. In each cell, she drops some berries while pushing her way through the thick forest. However, sometimes she is also able to pick up fresh berries. Each cell is labelled with an integer that indicates the net change in the number of berries in her basket on passing through the cell; that is, the number of berries she picks up in that cell minus the number of berries she drops. You can assume that there are enough berries in her basket to start with so that the basket never becomes empty.\n\nLittle Red Riding Hood knows the positions and strengths of all the magic charms and is looking for a safe path along which the number of berries she has in the basket when she reaches her grandmother's house is maximized.\n\nAs an example consider the following grid:\n\n3 3 2 4 3 \n2 1 -1 -2 2 \n-1 2 4 3 -3 \n-2 2 3 2 1 \n3 -1 2 -1 2 \n\nSuppose there are 3 magic charms, at position (1,2) with strength 2, at position (4,5) with strength 2 and one at position (4,2) with strength 1. The positions within the zone of influence of these three charms are indicated in the three grids below using X's. \n\nX X X X . . . . . . . . . . .\nX X X . . . . . . X . . . . .\n. X . . . . . . X X . X . . .\n. . . . . . . X X X X X X . .\n. . . . . . . . X X . X . . .\n\nPutting these together, the cells that are under the zone of influence of at least one charm are marked with X below.\n\nX X X X .\nX X X . X\n. X . X X\nX X X X X\n. X . X X\n\nHere are two examples of safe paths in this grid, marked using Y's. \n\nY Y X X . Y X X X .\nX Y X . X Y Y X . X\n. Y . X X . Y . X X\nX Y Y Y Y X Y Y Y X\n. X . X Y . X . Y Y\n\nAlong the first path, she accumulates 19 berries while on the second path she collects 16 berries. You can verify that among all safe paths, the maximum number of berries she can collect is 19. \n\nYour task is to help Little Red Riding Hood find out if there is at least one safe path and, if so, compute the maximum number of berries she can collect among all safe paths (which may be a negative number, in which case it is the minimum number of berries she will lose among all safe paths).\n\n-----Input format-----\nLine 1: Two space separated integers N and M, giving the dimension of the grid and the number of magic charms, respectively\n\nLines 2 to N+1: These N lines desribe the grid. Line i+1 contains N space separated integers, describing the net change in berries in the N cells along row i of the grid.\n\nLines N+2 to N+M+1: These M lines describe the magic charms. Each of these lines has 3 integers: the first two integers describe the position of the charm in the grid and the third integer describes its strength.\n\n-----Output format-----\nThe first line of output must either consist of the word YES, if there are safe paths, or the word NO, if there are no safe paths. If the output on the first line is YES then the second line should contain a single integer giving the maximum number of berries Little Red Riding Hood can collect among all safe paths. \n\n-----Sample Input-----\n5 3\n3 3 2 4 3 \n2 1 -1 -2 2 \n-1 2 4 3 -3 \n-2 2 3 2 1 \n3 -1 2 -1 2 \n1 2 2\n4 5 2\n4 2 1\n\n-----Sample Output-----\nYES\n19\n\n-----Test data-----\nIn all subtasks, you may assume that 2 ≤ N ≤ 500. Each value on the grid is guaranteed to have absolute value not more than 1000. \nLet K denote the maximum strength among all the magic charms.\n- Subtask 1 (30 marks) : 1 ≤ M ≤ 10, 1 ≤ K ≤ 1,000.\n- Subtask 2 (70 marks) : 1 ≤ M ≤ 10,000, 1 ≤ K ≤ 10.\n\n-----Live evaluation data-----\n- Subtask 1: Testcases 0,1,2,3,4.\n- Subtask 2: Testcases 5,6,7,8.", "starter_code": "", "test_cases": {"inputs": ["5 3\n3 3 2 4 3 \n2 1 -1 -2 2 \n-1 2 4 3 -3 \n-2 2 3 2 1 \n3 -1 2 -1 2 \n1 2 2\n4 5 2\n4 2 1\n"], "outputs": ["YES\n19"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "b3f7f42fa61f0282a0026ede4e1ae54402985948", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00582", "original_id": null, "source": "apps", "domain": "code", "problem": "in Chefland, there is a very famous street where $N$ types of street food (numbered $1$ through $N$) are offered. For each valid $i$, there are $S_i$ stores that offer food of the $i$-th type, the price of one piece of food of this type is $V_i$ (the same in each of these stores) and each day, $P_i$ people come to buy it; each of these people wants to buy one piece of food of the $i$-th type.\nChef is planning to open a new store at this street, where he would offer food of one of these $N$ types. Chef assumes that the people who want to buy the type of food he'd offer will split equally among all stores that offer it, and if this is impossible, i.e. the number of these people $p$ is not divisible by the number of these stores $s$, then only $\\left\\lfloor\\frac{p}{s}\\right\\rfloor$ people will buy food from Chef.\nChef wants to maximise his daily profit. Help Chef choose which type of food to offer and find the maximum daily profit he can make.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$. \n- $N$ lines follow. For each $i$ ($1 \\le i \\le N$), the $i$-th of these lines contains three space-separated integers $S_i$, $P_i$ and $V_i$.\n\n-----Output-----\nFor each test case, print a single line containing one integer ― the maximum profit.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N \\le 100$\n- $1 \\le S_i, V_i, P_i \\le 10,000$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n2\n3\n4 6 8\n2 6 6\n1 4 3\n1\n7 7 4\n\n-----Example Output-----\n12\n0\n\n-----Explanation-----\nExample case 1: Chef should offer food of the second type. On each day, two people would buy from him, so his daily profit would be $12$.\nExample case 2: Chef has no option other than to offer the only type of food, but he does not expect anyone to buy from him anyway, so his daily profit is $0$.", "starter_code": "", "test_cases": {"inputs": ["2\n3\n4 6 8\n2 6 6\n1 4 3\n1\n7 7 4"], "outputs": ["12\n0"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "96a086f10f01c65a83f655c61ac7e8d3fa6fb39e", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00587", "original_id": null, "source": "apps", "domain": "code", "problem": "Harsh, like usual, started studying 6 months before for his end semester examinations. He was going to complete his 8th revision of the whole syllabus, when suddenly Pranav showed up in his room with the last year's question paper for their algorithms course. This paper contains a problem which both of them couldn't solve. Frustrated he asked you for help. But you declined him and instead try to do this problem instead:\nYou are given an array $A_1,A_2,\\dots,A_N$, a positive integer $K$, and a function $F(x)=\\displaystyle\\sum_{i=1}^{N}{\\left|{\\left({x-A_i}\\right)^K}\\right|}$. Find the smallest integer $x$ such that $F(x)$ is minimum.Input\n- The first line contains two space-seperated integers , $N$ and $K$\n- The second line contains $N$ space-seperated integers $A_1,A_2,\\dots,A_N$. Output\nIn the first and only line print the smallest integer $x$ such that $F(x)$ is minimumConstraints\n- $1 \\leq N \\leq {10}^{5}$\n- $1 \\leq K \\leq {3}$\n- $1 \\leq A_i \\leq {5}\\times{10}^{4}$ for each valid $i$Sample Input 1\n3 1\n6 1 7\nSample Output 1\n6\nExplanation 1\n$F(6) = \\displaystyle\\sum_{i=1}^{N}{\\left|{\\left({6-A_i}\\right)^K}\\right|} \\\\ F(6) = \\left|{\\left({6-6}\\right)^1}\\right| + \\left|{\\left({6-1}\\right)^1}\\right| + \\left|{\\left({6-7}\\right)^1}\\right| \\\\ F(6) = 0 + 5+ 1 \\\\ F(6) = 6 $\nHere $6$ is the minumum value for $F(x)$ for any integer value of $x$.Sample Input 2\n3 2\n6 1 7\nSample Output 2\n5\nExplanation 2\n$F(5) = \\displaystyle\\sum_{i=1}^{N}{\\left|{\\left({5-A_i}\\right)^K}\\right|} \\\\F(5) = \\left|{\\left({5-6}\\right)^2}\\right| + \\left|{\\left({5-1}\\right)^2}\\right| + \\left|{\\left({5-7}\\right)^2}\\right| \\\\F(5) = 1 + 16 + 4 \\\\F(5) = 21$ \nHere $21$ is the minumum value for $F(x)$ for any integer value of $x$.Sample Input 3\n3 3\n6 1 7\nSample Output 3\n4\nExplanation 3\n$F(4) = \\displaystyle\\sum_{i=1}^{N}{\\left|{\\left({4-A_i}\\right)^K}\\right|} \\\\F(4) = \\left|{\\left({4-6}\\right)^3}\\right| + \\left|{\\left({4-1}\\right)^3}\\right| + \\left|{\\left({4-7}\\right)^3}\\right| \\\\F(4) = 8 + 27 + 27 \\\\F(4) = 62 $\nHere $62$ is the minumum value for $F(x)$ for any integer value of $x$.", "starter_code": "", "test_cases": {"inputs": ["3 1\n6 1 7"], "outputs": ["6"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "05b1130d315c1eaf8c0c9fb32ef74766366e4e23", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00592", "original_id": null, "source": "apps", "domain": "code", "problem": "Motu wants to learn Cricket from a coach, but firstly coach wants to test his IQ level, so he gave Motu $1$ $Red$ $ball$ and $1$ $Black$ $ball$ , and asked him to buy other $x – 1$ red balls and other $y – 1$ black balls from the market. But he put some conditions on buying balls, that if he has $R$ red and $B$ black balls then he can either buy $B$ red balls or $R$ black balls in one operation. He can perform this operation as many times as he want. But as Motu is not so good in solving problems so he needs your help. So you have to tell him whether his coach’s task possible or not.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, two integers $x , y$. \n\n-----Output:-----\nFor each testcase, print $YES$, if it is possible to complete coach task, else print $NO$(without quotes) in a separate line.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100000$\n- $1 \\leq x, y \\leq$ 10^18\n\n-----Sample Input:-----\n2\n1 2\n2 3\n\n-----Sample Output:-----\nYES\nYES", "starter_code": "", "test_cases": {"inputs": ["2\n1 2\n2 3"], "outputs": ["YES\nYES"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "3301ab83a626cadbfb3dd84c3a4f9ca0df99a7d9", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00597", "original_id": null, "source": "apps", "domain": "code", "problem": "Our Chef is doing what he is best at, COOKING A BARBECUE for his guests. He has invited all of us, and taking the help of his apprentice to smoke the barbecues. The chef has got BBQ sticks, each can take N fillings, and he presents N distinctly filled sticks in front his guests forming a N*N matrix\n\nBut here is the problem, he has got only two type of fillings, meat and capsicum, but still wants the N sticks to look \"presentable\", he is very particular about it. As a solution he fills the main diagonal of the N*N matrix with the same type of filling (either meat or capsicum) forming a \"presentable\" set\n\nThe Chef's apprentice is a fool, so the Chef asks him to cook M distinctly filled sticks ,so that the Chef is sure that among M there exist N sticks forming a \"presentable\" set. Your job is to determine smallest possible value of M.\n\n\n-----Input-----\nT, the number of test cases, followed by T lines. \nEach line containing the positive integer N >= 4\n\n-----Output-----\nT lines of output, each line contain the positive integer M\n\n-----Example-----\nInput:\n1\n4\n\nOutput:\n5", "starter_code": "", "test_cases": {"inputs": ["1\n4"], "outputs": ["5"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "ad5b448878ae3335724f0eab0e5c6a8cc15c61c3", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00602", "original_id": null, "source": "apps", "domain": "code", "problem": "Galileo's latest project involves determining the density of stars in certain regions of the sky. For this purpose he started looking for datasets online, and discovered a dataset on Newton's blog. Newton had decomposed the night sky into a Voronoi tessellation with the generators arranged in a grid. He has stored the number of stars in a Voronoi cell at a position in a matrix that corresponds to the position of the generator in the grid.\nThis dataset does not directly help Galileo, because he needs to be able to query the number of stars in a rectangular portion of the sky. Galileo tried to write a program that does this on his own, but it turned out to be too slow. Can you help him?\n\n-----Input Format-----\nThe first line contains two integers n and m that denote the height and width of the matrix respectively. This is followed by n lines each containing m integers each.\nThe line following this would contain a single integer t, the number of queries to be run. Each query line consists of 4 integers px, py, qx, qy. The first two integers denote the row and column numbers of the upper left corner of the rectangular region, and the second pair of numbers correspond to the lower right corner.\n\n-----Output Format-----\nFor each query output a single line containing the number of stars in that rectangular region.\n\n-----Example-----\nInput:\n\n3 3\n10 10 10\n10 10 10\n10 10 10\n4\n1 1 1 1\n1 1 3 3\n2 1 3 3\n3 1 3 3\n\nOutput:\n\n10\n90\n60\n30", "starter_code": "", "test_cases": {"inputs": ["3 3\n10 10 10\n10 10 10\n10 10 10\n4\n1 1 1 1\n1 1 3 3\n2 1 3 3\n3 1 3 3"], "outputs": ["10\n90\n60\n30"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "a41b538e10fa954f2574de14e72bd4f5cc0b30db", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00607", "original_id": null, "source": "apps", "domain": "code", "problem": "The Petrozavodsk camp takes place in about one month. Jafar wants to participate in the camp, but guess what? His coach is Yalalovichik.\nYalalovichik is a legendary coach, famous in the history of competitive programming. However, he is only willing to send to the camp students who solve really hard problems on Timus. The deadline that Yalalovichik set before has passed and he refuses to send Jafar to the camp.\nJafar decided to make Yalalovichik happy in hopes of changing his decision, so he invented a new sequence of numbers and named them Yalalovichik numbers. Jafar is writing a research paper about their properties and wants to publish it in the Science Eagle yearly journal.\nA Yalalovichik number is created in the following way:\n- Consider an integer $N$ in decimal notation; let's call it the base of the Yalalovichik number $Y_N$. $N$ may not contain the digit $0$.\n- Treat $N$ as a decimal string. Compute all left shifts of this string $N_0, N_1, \\ldots, N_{|N|-1}$ ($|N|$ denotes the number of digits of $N$); specifically, $N_k$ denotes the string formed by moving the first $k$ digits of $N$ to the end in the same order.\n- Concatenate the strings $N_0, N_1, \\ldots, N_{|N|-1}$. The resulting string is the decimal notation of $Y_N$.\nFor example, if $N = 123$, the left shifts are $123, 231, 312$ and thus $Y_N = 123231312$.\nYou are given the base $N$. Calculate the value of $Y_N$ modulo $10^9+7$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single decimal integer $N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer — the value of the Yalalovichik number $Y_N$ modulo $10^9+7$.\n\n-----Constraints-----\n- $1 \\le T \\le 200$\n- $|N| \\le 10^5$\n- $N$ does not contain the digit $0$\n- the sum of $|N|$ over all test cases does not exceed $10^6$\n\n-----Example Input-----\n1\n123\n\n-----Example Output-----\n123231312", "starter_code": "", "test_cases": {"inputs": ["1\n123\n"], "outputs": ["123231312"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "5b868945753f219a97e00c5e4a61eb6ce7e97aa7", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00612", "original_id": null, "source": "apps", "domain": "code", "problem": "Did you know that the people of America eat around 100 acres of pizza per day ? Having read this fact on internet, two chefs from the Elephant city, Arjuna and Bhima are set to make pizza popular in India. They organized a social awareness camp, where N people ( other than these two ) sit around a large pizza. To make it more interesting, they make some pairs among these N people and the two persons in a pair, feed each other.\n\nEach person should be a part of at most one pair and most importantly, to make feeding easy, any two pairs should not cross each other ( see figure for more clarity ). Arjuna and Bhima decided to play a game on making the pairs. In his turn, a player makes a pair ( selects two persons, as long as its valid ) and this pair start feeding each other. Arjuna and Bhima take turns alternately, by making a pair in each turn, and they play optimally ( see Notes for more clarity ). The one who can not make a pair in his turn, loses. Given N, find who wins the game, if Arjuna starts first. \n\n-----Notes-----\n- 'Optimally' means, if there is a possible move a person can take in his turn that can make him win finally, he will always take that. You can assume both are very intelligent. \n\n-----Input-----\nFirst line contains an integer T ( number of test cases, around 1000 ). Each of the next T lines contains an integer N ( 2 <= N <= 10000 )\n\n-----Output-----\nFor each test case, output the name of the winner ( either \"Arjuna\" or \"Bhima\" ( without quotes ) ) in a new line.\n\n-----Example-----\nInput:\n4\n2\n4\n5\n6\n\nOutput:\nArjuna\nArjuna\nBhima\nArjuna\n\nExplanation:\n\nLet the people around the table are numbered 1, 2, ... , N in clock-wise order as shown in the image \n\nCase 1 : N = 2. Only two persons and Arjuna makes the only possible pair (1,2)\n\nCase 2 : N = 4. Arjuna can make the pair (1,3). Bhima can not make any more pairs ( without crossing the pair (1,3) )\n\nCase 3 : N = 5. No matter which pair Arjuna makes first, Bhima can always make one more pair, and Arjuna can not make any further", "starter_code": "", "test_cases": {"inputs": ["4\n2\n4\n5\n6"], "outputs": ["Arjuna\nArjuna\nBhima\nArjuna"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "446a1d3a128fe348c9cf01535ebcc146e631eba3", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00617", "original_id": null, "source": "apps", "domain": "code", "problem": "A beautiful sequence is defined as a sequence that do not have any repeating elements in it.\nYou will be given any random sequence of integers, and you have to tell whether it is a beautiful sequence or not. \n\n-----Input:-----\n- The first line of the input contains a single integer $T$. $T$ denoting the number of test cases. The description of $T$ test cases is as follows.\n- The next line of the input contains a single integer $N$. $N$ denotes the total number of elements in the sequence.\n- The next line of the input contains $N$ space-separated integers $A1, A2, A3...An$ denoting the sequence.\n\n-----Output:-----\n- Print \"prekrasnyy\"(without quotes) if the given sequence is a beautiful sequence, else print \"ne krasivo\"(without quotes)\nNote: each test case output must be printed on new line\n\n-----Constraints:-----\n- $1 \\leq T \\leq 10^2$\n- $1 \\leq N \\leq 10^3$\n- $1 \\leq A1, A2, A3...An \\leq 10^5$\n\n-----Sample Input:-----\n2\n4\n1 2 3 4\n6\n1 2 3 5 1 4\n\n-----Sample Output:-----\nprekrasnyy\nne krasivo\n\n-----Explanation:-----\n- \nAs 1st sequence do not have any elements repeating, hence it is a beautiful sequence\n- \nAs in 2nd sequence the element 1 is repeated twice, hence it is not a beautiful sequence", "starter_code": "", "test_cases": {"inputs": ["2\n4\n1 2 3 4\n6\n1 2 3 5 1 4"], "outputs": ["prekrasnyy\nne krasivo"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "0578bab756a6a34215ccb092c70d573105a522e3", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00622", "original_id": null, "source": "apps", "domain": "code", "problem": "Voritex a big data scientist collected huge amount of big data having structure of two rows and n columns.\nVoritex is storing all the valid data for manipulations and pressing invalid command when data not satisfying the constraints.\nVoritex likes brute force method and he calls it as BT, he decided to run newly created BT engine for getting good result.\nAt each instance when BT engine is outputting a newly created number Voritex calls it as BT number.\nVoritex is daydreaming and thinking that his engine is extremely optimised and will get an interview call in which he will be explaining the structure of BT engine and which will be staring from 1 and simultaneously performing $i$-th xor operation with $i$ and previously(one step before) obtained BT number.\nBT engine is outputting the $K$-th highest BT number in the first $N$ natural numbers.\nChef : (thinking) I also want to create BT engine……..\n\n-----Input:-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of T test cases follows.\n- The line of each test case contains a two integers $N$ and $K$.\n\n-----Output:-----\nFor each test case, print a single line containing integer $K$-th highest number else print -$1$ when invalid command pressed.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100000$\n- $1 \\leq N \\leq 100000$\n- $1 \\leq K \\leq N$\n\n-----Sample Input:-----\n2\n4 2\n5 5\n\n-----Sample Output:-----\n2\n0\n\n-----EXPLANATION:-----\nFor first valid constraints generating output as 0 2 1 5 \n1^1 first BT number is 0\n2^0 second BT number is 2\n3^2 third BT number is 1\n4^1 fourth BT number is 5\nHence the answer is 2.", "starter_code": "", "test_cases": {"inputs": ["2\n4 2\n5 5"], "outputs": ["2\n0"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "881ec7a2345af1a0bb1ff9e934d4ab4da42b7c17", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00627", "original_id": null, "source": "apps", "domain": "code", "problem": "These days, chef is very much interested in Mathematics. He has started attending Recitations too! His hunger for problems is increasing day by day!\nToday, chef was a given a crumpled maths problem, which he is stuck with . He needs your help to do it\nHere's what his teacher said: \"Find sum of all numbers till N, do not include numbers which are powers of K from K, K2, K3... which are less than or equal to N\"\nEasy, right? Can you solve it?\n\n-----INPUT-----\nThe first line of the input contains an integer T, denoting the number of test cases. The description of T test cases follows. The first line of each test contains two integers N and K, as per the above given problem specification.\n\n-----OUTPUT-----\nFor each test case, output a single line printing the sum of the each test case, in format Case #T: S, where T is the Tth test case running and S is sum of corresponding test case.\n\n-----CONSTRAINTS-----\n\n10 < T < 50\n\n10 < N < 104\n\n0 < K < 100\n\n-----EXAMPLE-----\nInput:\n\n2\n\n10 3\n\n20 2\n\nOutput:\n\nCase #1: 43\n\nCase #2: 180", "starter_code": "", "test_cases": {"inputs": ["2\n10 3\n20 2"], "outputs": ["Case #1: 43\nCase #2: 180"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "a2ff6505a8e2d47965f51efc6c1c6dfd21ee3e3a", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00632", "original_id": null, "source": "apps", "domain": "code", "problem": "We say that a binary string (a string containing only characters '0' and '1') is pure if it does not contain either of the strings \"0101\" or \"1010\" as a subsequence.\nRecall that string T is a subsequence of string S if we can delete some of the letters of S (possibly none) such that the resulting string will become T.\nYou are given a binary string $S$ with length $N$. We want to make this string pure by deleting some (possibly zero) characters from it. What is the minimum number of characters we have to delete?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single string $S$ with length $N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer — the minimum number of characters we have to delete from $S$.\n\n-----Constraints-----\n- $1 \\le T \\le 40$\n- $1 \\le N \\le 1,000$\n- $S$ contains only characters '0' and '1'\n\n-----Example Input-----\n4\n010111101\n1011100001011101\n0110\n111111\n\n-----Example Output-----\n2\n3\n0\n0\n\n-----Explanation-----\nExample case 1: We can delete the first and third character of our string. There is no way to make the string pure by deleting only one character.\nExample case 3: The given string is already pure, so the answer is zero.", "starter_code": "", "test_cases": {"inputs": ["4\n010111101\n1011100001011101\n0110\n111111"], "outputs": ["2\n3\n0\n0"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "f2d65371d52a083967aabb9c2d1ca9adc96bceb9", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00637", "original_id": null, "source": "apps", "domain": "code", "problem": "Rachel has some candies and she decided to distribute them among $N$ kids. The ith kid receives $A_i$ candies. The kids are happy iff the difference between the highest and lowest number of candies received is less than $X$.\nFind out if the children are happy or not.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- The first line contains $N$ and $X$. \n- The second line contains $N$ integers $A_1,A_2,...,A_N$. \n\n-----Output:-----\nFor each test case print either \"YES\"(without quotes) if the kids are happy else \"NO\"(without quotes)\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N, X \\leq 10^5$\n- $1 \\leq A_i \\leq 10^5$\n\n-----Sample Input:-----\n2\n\n5 6\n\n3 5 6 8 1\n\n3 10\n\n5 2 9\n\n-----Sample Output:-----\nNO\n\nYES\n\n-----EXPLANATION:-----\n- Example 1: Difference between maximum and minimum candies received is 8-1=7. 7 is greater than 6, therefore, the kids are not happy.", "starter_code": "", "test_cases": {"inputs": ["2\n5 6\n3 5 6 8 1\n3 10\n5 2 9"], "outputs": ["NO\nYES"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "2e1e201cb53ebad8f77993af542b3f534a9c4028", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00642", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an array $A_1, A_2, ..., A_N$, count the number of subarrays of array $A$ which are non-decreasing.\n\nA subarray $A[i, j]$, where $1 ≤ i ≤ j ≤ N$ is a sequence of integers $A_i, A_i+1, ..., A_j$.\nA subarray $A[i, j]$ is non-decreasing if $A_i ≤ A_i+1 ≤ A_i+2 ≤ ... ≤ A_j$. You have to count the total number of such subarrays.\n\n-----Input-----\n- \nThe first line of input contains an integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- \nThe first line of each test case contains a single integer $N$ denoting the size of array.\n- \nThe second line contains $N$ space-separated integers $A_1$, $A_2$, …, $A_N$ denoting the elements of the array.\n\n-----Output-----\nFor each test case, output in a single line the required answer.\n\n-----Constraints-----\n- $1 ≤ T ≤ 5$\n- $1 ≤ N ≤ 10^5$\n- $1 ≤ A_i ≤ 10^9$\n\n-----Subtasks-----\n- Subtask 1 (20 points) : $1 ≤ N ≤ 100$\n- Subtask 2 (30 points) : $1 ≤ N ≤ 1000$\n- Subtask 3 (50 points) : Original constraints\n\n-----Sample Input:-----\n2\n4\n1 4 2 3\n1\n5\n\n-----Sample Output:-----\n6\n1\n\n-----Explanation-----\nExample case 1.\n\nAll valid subarrays are $A[1, 1], A[1, 2], A[2, 2], A[3, 3], A[3, 4], A[4, 4]$.\n\nNote that singleton subarrays are identically non-decreasing.\nExample case 2.\n\nOnly single subarray $A[1, 1]$ is non-decreasing.", "starter_code": "", "test_cases": {"inputs": ["2\n4\n1 4 2 3\n1\n5"], "outputs": ["6\n1"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "766957d6e8b9988b26196e179e9384e4beab77c4", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00647", "original_id": null, "source": "apps", "domain": "code", "problem": "Arya and Aryan live in a country called Nadaca. Nadaca consists of $N$ cities numbered $1$ through $N$, which are connected by some bidirectional roads. Each road has a positive (not necessarily integer) length. Arya lives in city $1$ and Aryan lives in city $N$.\nArya claims that for each city $v$, the shortest path from city $1$ to city $v$ has length $a_v$. Aryan does not disagree, but claims that for each city $v$, the shortest path from city $N$ to city $v$ has length $b_v$. You are the wisest person they know, so they asked you to tell them if it is possible for their claims to be true, i.e. if a road network which fully satisfies their claims exists. Help them!\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $a_1, a_2, \\ldots, a_N$.\n- The third line contains $N$ space-separated integers $b_1, b_2, \\ldots, b_N$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"Yes\" if Arya's and Aryan's claims can be true or \"No\" otherwise.\n\n-----Constraints-----\n- $1 \\le T \\le 10^3$\n- $2 \\le N \\le 10^6$\n- $0 \\le a_i, b_i \\le 10^9$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $10^6$\n\n-----Subtasks-----\nSubtask #1 (50 points): the sum of $N$ over all test cases does not exceed $10^3$\nSubtask #2 (50 points): original constraints\n\n-----Example Input-----\n2\n3\n0 1 1\n1 1 0\n3\n0 1 5\n5 1 0\n\n-----Example Output-----\nYes\nNo", "starter_code": "", "test_cases": {"inputs": ["2\n3\n0 1 1\n1 1 0\n3\n0 1 5\n5 1 0"], "outputs": ["Yes\nNo"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "8c94f27751da554c530b40914c50a973468352e2", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00652", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef had an array A with length N, but some of its elements got lost. Now, each element of this array is either unknown (denoted by -1) or a positive integer not exceeding K.\nChef decided to restore the array A by replacing each unknown element by a positive integer not exceeding K.\nHowever, Chef has M restrictions that must hold for the restored array. There are two types of restrictions:\n\n- I L R, meaning that for each i such that L < i ≤ R, the condition Ai - Ai-1 = 1 should be satisfied.\n- D L R, meaning that for each i such that L < i ≤ R, the condition Ai - Ai-1 = -1 should be satisfied.\n\nChef would like to know the number of ways to restore the array while satisfying all restrictions, modulo 109+7.\n\n-----Input-----\n- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains three space-separated integers N, M and K.\n- The second line contains N integers A1, A2, ..., AN.\n- Each of the following M lines contains one restriction in the form I L R or D L R.\n\n-----Output-----\nFor each test case, print a single line containing one integer - the number of ways to restore the array modulo 109+7.\n\n-----Constraints-----\n- 1 ≤ T ≤ 10\n- 1 ≤ N, M ≤ 100,000\n- 1 ≤ K ≤ 1,000,000,000\n- 1 ≤ L < R ≤ N\n- 1 ≤ Ai ≤ K or Ai = -1 for each valid i\n- 1 ≤ sum of N over all test cases ≤ 500,000\n- 1 ≤ sum of M over all test cases ≤ 500,000\n\n-----Example-----\nInput:\n\n3\n4 2 10\n2 3 5 4\nI 1 2 \nD 3 4\n5 2 10\n-1 -1 -1 -1 -1\nI 1 3\nD 3 5\n6 2 2\n-1 -1 -1 -1 -1 -1\nI 1 4\nD 4 6\n\nOutput:\n\n1\n8\n0", "starter_code": "", "test_cases": {"inputs": ["3\n4 2 10\n2 3 5 4\nI 1 2\nD 3 4\n5 2 10\n-1 -1 -1 -1 -1\nI 1 3\nD 3 5\n6 2 2\n-1 -1 -1 -1 -1 -1\nI 1 4\nD 4 6"], "outputs": ["1\n8\n0"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "0930a8321e681fb672345e6b2187b02a299f48cf", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00657", "original_id": null, "source": "apps", "domain": "code", "problem": "Tweedle-Dee and Tweedle-Dum are playing a fierce match of binary Nim. This novel game is played with $N$ stacks, each of them containing only $1$-s and $0$-s.\nJust like in normal Nim, Tweedle-Dee and Tweedle-Dum alternate turns; in their turn, a player must choose one non-empty stack and remove a positive number of elements from the top of this stack. However, Tweedle-Dee may only choose a stack with $0$ at the top (and remove elements from it afterwards), and similarly, Tweedle-Dum may only choose a stack with $1$ at the top. the player that cannot make a move loses\nSuzumo does not want to wait for the end of the game, so given the starting player he asks you to determine the winner. Remember that Tweedle-Dee and Tweedle-Dum are legendary grandmasters of combinatorial games, so both always play optimally.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains an integer $N$, a string $S$ denoting the number of stacks, the player that starts the game, respectively.\n- Each of the following $N$ lines contains a single binary string $B$ representing a stack; the first character of $B$ corresponds to the top element of the stack and the last character to the bottom element.\n\n-----Output-----\nFor each test case, print a single line containing the string \"Dee\" if Tweedle-Dee wins the match or \"Dum\" if Tweedle-Dum wins.\n\n-----Constraints-----\n- $1 \\le T \\le 500$\n- $1 \\le N \\le 50$\n- $1 \\le |B| \\le 50$\n- each character in $B$ is either '1' or '0'\n- $S$ is either \"Dee\" or \"Dum\"\n\n-----Example Input-----\n2\n2 Dee\n101\n010\n2 Dum\n101\n010\n\n-----Example Output-----\nDum\nDee", "starter_code": "", "test_cases": {"inputs": ["2\n2 Dee\n101\n010\n2 Dum\n101\n010"], "outputs": ["Dum\nDee"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "1fb827052ef4ff974e0c33bf827dfbe53d0b82c4", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00662", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef belongs to a very rich family which owns many gold mines. Today, he brought N gold coins and decided to form a triangle using these coins. Isn't it strange?\nChef has a unusual way of forming a triangle using gold coins, which is described as follows:\n- He puts 1 coin in the 1st row.\n- then puts 2 coins in the 2nd row.\n- then puts 3 coins in the 3rd row.\n- and so on as shown in the given figure.\nChef is interested in forming a triangle with maximum possible height using at most N coins. Can you tell him the maximum possible height of the triangle?\n\n-----Input-----\nThe first line of input contains a single integer T denoting the number of test cases. \nThe first and the only line of each test case contains an integer N denoting the number of gold coins Chef has.\n\n-----Output-----\nFor each test case, output a single line containing an integer corresponding to the maximum possible height of the triangle that Chef can get.\n\n-----Constraints-----\n- 1 ≤ T ≤ 100\n- 1 ≤ N ≤ 109\n\n-----Subtasks-----\n- Subtask 1 (48 points) : 1 ≤ N ≤ 105\n- Subtask 2 (52 points) : 1 ≤ N ≤ 109\n\n-----Example-----\nInput3\n3\n5\n7\n\nOutput2\n2\n3\n\n-----Explanation-----\n- Test 1: Chef can't form a triangle with height > 2 as it requires atleast 6 gold coins.\n- Test 2: Chef can't form a triangle with height > 2 as it requires atleast 6 gold coins.\n- Test 3: Chef can't form a triangle with height > 3 as it requires atleast 10 gold coins.", "starter_code": "", "test_cases": {"inputs": ["3\n3\n5\n7"], "outputs": ["2\n2\n3"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "93313fa714685e9867ed9ac334e9fcebf7391482", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00667", "original_id": null, "source": "apps", "domain": "code", "problem": "Mr. Wire Less is not that good at implementing circuit in a breadboard. In his Digital Logic Design course, he has to implement several boolean functions using the breadboard. In a breadboard, inputs are given through the switches and outputs are taken through the LEDs. Each input switch can be either in ground state or in high state. So, if he wishes to implement a boolean function, f(x1, x2, .., xn) that takes n boolean values as input and returns m boolean values as output, he will use n switches and m LEDs. \nMr. Wire Less can quickly assemble the necessary ICs and wires, but the key problem is testing. While testing he has to check with all possible input combination, to make sure whether the output of LED corresponds to the expected output or not. This is taking too long for him, as most of the switches are jammed and difficult to toggle. \nMr. Wire Less is asking for help to minimize his time of testing. So, your task is to minimize the total number of switch-toggle throughout the testing.\nFor example, if Mr. Wire Less has to test a function f(x0, x1) of two variables, he may choose this switching-sequence for testing 00, 11, 10, 01. In this case, the total number of switch-toggle will be 2+1+2 = 5. But if he tests in this sequence 00, 10, 11, 01 total number of toggle will be 1+1+1 = 3.\nGiven n, you have to output the minimum number of toggle needed for complete testing. Though it seems impractical, he wants you to solve the problem for a very large value of n. But, then the toggle value can be quite big. So, he is completely okay with the toggle value modulo 8589934592 (233).

\n\n-----Input-----\nThe first line of the input contains a positive integer T(T ≤ 105), denoting the number of test-case. Each of the following T lines contains a single non-negative integer n(n ≤ 1020).\n\n-----Output-----\nFor every test-case, output a single containing test-case number and the minimum number of switch-toggle modulo 8589934592 (233).\n\n-----Sample----- \nInput \n2\n1\n2\n\nOutput\nCase 1: 1\nCase 2: 3", "starter_code": "", "test_cases": {"inputs": ["2\n1\n2\n\n"], "outputs": ["Case 1: 1\nCase 2: 3"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "bcd9b79090a4c7404cf230117720b71a288fab79", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00672", "original_id": null, "source": "apps", "domain": "code", "problem": "Given an empty array A of infinite length and a positive integer K you have to process \nQ queries of type: \n- ! l r x: Fill the value x in all the empty places in the array from index l to r (both inclusive).\n- ? l r: Print the number of prime factors of K which is also a prime factor of at least one number in A[l], A[l + 1], A[l + 2], … A[r]. \n\n-----Input-----\n- The first line contains two space separated integers K and Q respectively.\n- Then Q lines follow:\n- Each of the $i^{th}$ line contains one of the above two types of queries.\n\n-----Output-----\nFor each query of the second type, print in a new line the answer to that query. i.e. number of prime factors of K which is also a prime factor of at least one number in A[l], A[l + 1], A[l + 2], … A[r]. \n\n-----Constraints-----\n- $1 \\leq K, x \\leq 10^9$\n- $ 1 \\leq l \\leq r \\leq 10^5$\n- $ 1 \\leq Q \\leq 10^5$ \n\n-----Sample Input-----\n20 5\n\n? 1 5\n\n! 3 5 4\n\n? 1 5\n\n! 1 4 15\n\n? 1 5 \n\n-----Sample Output-----\n0\n\n1\n\n2 \n\n-----EXPLANATION-----\nInitially, all the places in the array are empty. i.e _ _ _ _ _\n\nAfter first update the array looks like: _ _ 4 4 4\n\nIn the range [1, 5] the only factor of 20 which is also a prime factor of at least one number in _ _ 4 4 4 is 2.\n\nAfter the second update the array looks like: 15 15 4 4 4\n\nIn the range [1, 5] the prime factors of 20 i.e. 5 is a prime factor of 15, 15 and 2 is the prime factor of 4, 4, 4.", "starter_code": "", "test_cases": {"inputs": ["20 5\n? 1 5\n! 3 5 4\n? 1 5\n! 1 4 15\n? 1 5"], "outputs": ["0\n1\n2"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "bfc386bcee123b1045982ed509139f8b031e8b93", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00677", "original_id": null, "source": "apps", "domain": "code", "problem": "One day, Delta, the dog, got very angry. He has $N$ items with different values, and he decided to destroy a few of them. However, Delta loves his hooman as well. So he only destroyed those items whose Least Significant Bit in binary representation is 0. \nCan you help Delta to find the total damage he did so he could make an equally sorry face?\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- First line of Each test case a single integer $N$.\n- Next line contains $N$ integers denoting values of items.\n\n-----Output:-----\nFor each testcase, output in a single line the total damage caused by Delta.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^3$\n- $1 \\leq N \\leq 10^3$\n- $1 \\leq value \\leq 10^3$\n\n-----Sample Input:-----\n1\n5\n\n1 2 3 4 5\n\n-----Sample Output:-----\n6\n\n-----EXPLANATION:-----\nTotal Damage: $2 + 4 = 6$.", "starter_code": "", "test_cases": {"inputs": ["1\n5\n1 2 3 4 5"], "outputs": ["6"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "6d7977d155c93df5c1d25897cb997d2208ee7419", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00682", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef has an array A consisting of N elements. He wants to find number of pairs of non-intersecting segments [a, b] and [c, d] (1 ≤ a ≤ b < c ≤ d ≤ N) such there is no number that occurs in the subarray {Aa, Aa+1, ... , Ab} and {Ac, Ac+1, ... , Ad} simultaneously. \nHelp Chef to find this number.\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains a single integer N denoting the number of elements in the array.\n- The second line contains N space-separated integers A1, A2, ..., AN. \n\n-----Output-----\n- For each test case, output a single line containing one integer - number of pairs of non-intersecting segments. \n\n-----Constraints-----\n- 1 ≤ T ≤ 5\n- 1 ≤ N ≤ 1000\n- 1 ≤ Ai ≤ 109\n\n-----Subtasks-----Subtask 1 (7 points)\n- 1 ≤ N ≤ 20Subtask 2 (34 points)\n- 1 ≤ N ≤ 300Subtask 3 (59 points)\n- Original constraints\n\n-----Example-----\nInput:\n2\n3\n1 2 3\n4\n1 2 1 2\n\nOutput:\n5\n4\n\n-----Explanation-----\nExample case 1.\nAll possible variants are correct: {[1, 1], [2, 2]}, {[1, 1], [2, 3]}, {[1, 2], [3, 3]}, {[2, 2], [3, 3]}, {[1,1], [3, 3]}.\n\nExample case 2.\nCorrect segments: {[1, 1], [2, 2]}, {[1, 1], [4, 4]}, {[2, 2], [3, 3]}, {[3, 3], [4, 4]}.", "starter_code": "", "test_cases": {"inputs": ["2\n3\n1 2 3\n4\n1 2 1 2"], "outputs": ["5\n4"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "766f382ff8e898a7323258a9c4c30ffd77d6b7b2", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00687", "original_id": null, "source": "apps", "domain": "code", "problem": "Tejas has invited the Clash Team for a Dinner Party. He places V empty plates (numbered from 1 to V inclusive) in a straight line on a table. He has prepared 2 kinds of Delicious Dishes named dish A and dish B.\n\nHe has exactly V servings of Dish A and W servings of dish B. \n\nNow he wants to serve the dishes in such a way that if theith plate has serving of Dish A then (i-1)th plate should not have serving of Dish B. Assuming all the Dishes are identical find number of ways Tejas can serve the Clash Team.\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases . The description of T testcases follow.\n\n- The first line of each test case contains two space seperated integers V W .\n\n-----Output-----\nFor each test case, output the number of ways Tejas can serve the Clash Team.\n\n\n-----Constraints-----\n\n- 1 ≤ T ≤ 100\n- 1 ≤ V ≤ 1000\n- 1 ≤ W ≤ 1000\n\n-----Example-----\nInput:\n\n1\n\n3 3 \n\nOutput:\n4\n\n\n\n-----Explanation-----\n\nIn the above example the 4 ways are:\n\nAAA\n\nAAB\n\nABB\n\nBBB", "starter_code": "", "test_cases": {"inputs": ["1\n3 3"], "outputs": ["4"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "a5987063d66ca503c03ce6bbf0c452e2bac63c0d", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00692", "original_id": null, "source": "apps", "domain": "code", "problem": "IIST is thinking of acquiring some land nearby to build its new state of the art labs. The land it has chosen incidentaly has some abandoned college buildings which IIST wants to use. The administration decide the value of the building based on the amount of work that has to be done to get it in shape (lower amount of work, higher value). The security experts want to tear down some of the buildings and use the bricks to build a boundary wall. \n\nThe director has chosen you to write a program which determines the buildings which needs to be demolished to maximise the value while fulfilling the above criterion. \n\nInput Format: \n\nThe first line contains the number of test cases, T.\n\nThe next T cases contains information about hypothetical plots.\n\nEach test case starts with a single integer n, 2 ≤ n ≤ 15, the number of abandoned buildings in the plot. The buildings are identified by consecutive integers 1 to n. Each of the subsequent lines contains 4 integers x_i , y_i , v_i , l_i that describe a single building. (x_i, y_i) is the position of the building in the plane, v_i is its value, and l_i is the length of boundary wall that can be built using the bricks from the building. v_i and l_i are between 0 and 10,000.\n\nOutput Format:\n\nFor each test case, compute a subset of the buildings such that, using the bricks from the buildings from that subset, the remaining buildings can be enclosed in a single boundary. Find the subset with a minimum value. If more than one such minimum-value subset exists, choose one with the smallest number of buildings. \n\nDisplay, as shown below, the identity of each building to be demolished, and the length of the excess boundary (accurate to two fractional digits).\n\nSample Input: \n\n2\n\n6\n\n0 0 8 3\n\n1 4 3 2\n\n2 1 7 1\n\n4 1 2 3\n\n3 5 4 6\n\n2 3 9 8\n\n3\n\n3 0 10 2\n\n5 5 20 25\n\n7 -3 30 32\n\nSample Output: \n\n2 4 5\n\n3.16\n\n2\n\n15.00", "starter_code": "", "test_cases": {"inputs": ["2\n6\n0 0 8 3\n1 4 3 2\n2 1 7 1\n4 1 2 3\n3 5 4 6\n2 3 9 8\n3\n3 0 10 2\n5 5 20 25\n7 -3 30 32"], "outputs": ["2 4 5\n3.16\n2\n15.00"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "017ce9ca2221693b80772979ec3b0929609d440b", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00697", "original_id": null, "source": "apps", "domain": "code", "problem": "Tired of the overpopulated world, Miu - The introverted cat visits a new continent in search for a new house. \nThere are $N$ houses lying on the X-axis.\n\nTheir positions are given by $X$$i$ , where $i$ refers to the $i$th house. ( $1 <= i <= N$ )\n\nEach of these positions are pairwise distinct \nMiu is supposed to choose one of these houses for herself.\n\nMiu defines a term - The Distance of Peace, as the minimum distance from her house to any other house. \nMiu wonders what is maximum Distance of Peace she can obtain. Can you help her?\n\n-----Input:-----\n- The first line of the input consists of a single integer $T$, denoting the number of test cases \n- The first line of each test case consists of a single integer $N$ \n- The second line of each test case consists of $N$ space-separated integers\n$X$$1$ $X$$2$ $X$$3$ … $X$$N$\n\n-----Output:-----\n- For each test case print the answer in a single line, the maximum Distance of Peace Miu can obtain\n\n-----Constraints-----\n- 1 <= $T$ <= 100 \n- 2 <= $N$ <= 105 \n- -109 <= $X$$i$ <= 109 \n- Sum of $N$ over all test cases does not exceed 106 \n\n-----Subtasks-----\nSubtask #1 (30 points): \n- $N$ <= 103 \nSubtask #2 (70 points): \n- Original Constraints\n\n-----Sample Input:-----\n2\n\n6\n\n7 -1 2 13 -5 15\n\n4\n\n6 10 3 12 \n\n-----Sample Output:-----\n5\n\n3 \n\n-----EXPLANATION:-----\nTest Case 1:\n\nThe $1$st house has the maximum Distance of Peace, which is from the $3$rd house:\n$| 7 - 2 | = 5$\n\nHence, the answer is $5$", "starter_code": "", "test_cases": {"inputs": ["2\n6\n7 -1 2 13 -5 15\n4\n6 10 3 12"], "outputs": ["5\n3"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "ae12f71bed650bb6a481fa9fda5d9c17268fe45e", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00702", "original_id": null, "source": "apps", "domain": "code", "problem": "Since due to COVID 19, India has undergone a complete 21 day lockdown. So Amol was attending an online lecture where his professor asked him to solve a question. Amol was unable to solve the question so he asked you to solve the question and give him the correct answer. \n\nThe question was asked a such that his professor gave him a number M and a list of integers of length N (i.e. A1, A2,..... AN) and you have to find out all the subsets that add up to M and the total number of subsets will be the final answer. \n\nInput: \n• The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. \n\n• The first line of each test case contains a single integer N. \n\n• The second line of each test case contains a single integer M. \n\n• The third line contains N space-separated integers A1, A2,..... AN. \n\nOutput: \nFor each test case, print a single line containing one integer ― the no. of subsets that adds upto M.\n\nConstraints: \n• 1≤T≤5\n\n• 1≤N≤100 \n\n• 10≤M≤100 \n\n• 1≤Ai≤100\n\nExampleInput:\n\n2\n\n4\n\n16\n\n2 4 6 10 \n\n4 \n\n20 \n\n2 8 12 10 \n\nOutput:\n\n2\n\n2\n\nExplanation:\nIn the 1st example there are two subsets {2,4,10} and {6,10} that adds upto 16 so the output is 2.", "starter_code": "", "test_cases": {"inputs": ["2\n4\n16\n2 4 6 10\n4\n20\n2 8 12 10"], "outputs": ["2\n2"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "ca431c59ed1a5135d90a12ac8989daafdfaea2e1", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00707", "original_id": null, "source": "apps", "domain": "code", "problem": "You are given an $array$ of size $N$ and an integer $K$ ( $N > 1 , K > 0$ ).\nEach element in the array can be incremented by $K$ or decremented by $K$ $at$ $most$ $once$.\nSo there will be $3^n$ possible combinations of final array. (As there are 3 options for every element).\n\nOut of these combinations, you have to select a combination, in which the $absolute$ difference between the largest and the smallest element is $maximum$.\nYou have to print the $maximum$ $absolute$ $difference$.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a two lines of input\n- First line contains two integers $N, K$. \n- Second line contains $N$ space separated integers.\n\n-----Output:-----\nFor each testcase, output the maximum absolute difference that can be achieved on a new line.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $2 \\leq N \\leq 1000$\n- $1 \\leq K , arr[i] \\leq 10000$\n$NOTE$: Large input files, Use of fastio is recommended.\n\n-----Sample Input:-----\n2\n\n4 3\n\n4 2 5 1\n\n3 5\n\n2 5 3\n\n-----Sample Output:-----\n10\n\n13", "starter_code": "", "test_cases": {"inputs": ["2\n4 3\n4 2 5 1\n3 5\n2 5 3"], "outputs": ["10\n13"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "12026b31fb3044e9429a04a010ae07209d95dba7", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00712", "original_id": null, "source": "apps", "domain": "code", "problem": "You are given a grid of size M x N, where each square is colored with some random color among K colors with each having equal probability.\n\nA Good Rectangle is defined as one where all squares lying on the inner border are of the same color.\n\nWhat is the expected number of Good Rectangles in the given grid.\n\n-----Input-----\n\n- \nFirst Line contains M, N, K\n\n-----Output-----\nA single value rounded off to the nearest Integer corresponding to the required answer.\n\n-----Constraints-----\n- 1 <= N <= 105 \n- 1 <= M <= 105 \n- 1 <= K <= 105 \n\n-----Example-----\nInput:\n1 3 1\nOutput:\n6", "starter_code": "", "test_cases": {"inputs": ["1 3 1"], "outputs": ["6"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "ebe800a28bf44619d930377fb558307d4012c359", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00717", "original_id": null, "source": "apps", "domain": "code", "problem": "Problem Statement:Captain America and Iron Man are at WAR and the rage inside Iron Man is rising.\n\nBut Iron Man faces a problem to identify the location of Captain America.\n\nThere are N buildings situtaed adjacently to each other and Captain America can be at any building.\n\nIron Man has to arrange the Buildings from 1 to N is such a way that Value(i.e abs(Building Number -Position of Building))=K for every building.\n\nCan You help Iron Man to Find The Arrangement of the Buildings?\n\nP.S- If no arrangement exist, then print \n“CAPTAIN AMERICA EVADES”.\n\nInput Format:\nThe first line of input contains a single integer,T, denoting the number of test cases.\n\nEach of the T subsequent lines contains 2 space-separated integers describing the respective N and K values for a test case.\n\nOutput Format:\nOn a new line for each test case, \n\nPrint the lexicographically smallest arrangement; \n\nIf no absolute arrangement exists, print “CAPTAIN AMERICA EVADES”.\n\nConstraints:\nSubTask#1\n1<=T<=10\n\n1<=N<=10^5\n\n0<=K<=N\n\nSubTask#2\nOriginal Constraints..\n\nSubTask#3\nOriginal Constraints..\n\nSample Input:\n3\n\n2 1\n\n3 0\n\n3 2\n\nSample Output:\n\n2 1\n\n1 2 3\n\nCAPTAIN AMERICA EVADES\n\nExplanation:\nCase 1:\n\nN=2 and K=1\n\nTherefore the arrangement is [2,1].\n\nCase 2:\n\nN=3 and K=0\n\nTherefore arrangement is [1,2,3].", "starter_code": "", "test_cases": {"inputs": ["3\n2 1\n3 0\n3 2"], "outputs": ["2 1\n1 2 3\nCAPTAIN AMERICA EVADES"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "782f1c1c27f6c33056b201fa9872da116621cfd5", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00722", "original_id": null, "source": "apps", "domain": "code", "problem": "January and February are usually very cold in ChefLand. The temperature may reach -20 and even -30 degrees Celsius. Because of that, many people seal up windows in their houses.\nSergey also lives in ChefLand. He wants to seal the window in his house. The window has the shape of a simple convex polygon with N vertices.\nFor the sealing, there are M kinds of sticky stripes, which are sold in the shops. The stripe of the ith type has the length of Li millimeters and the cost of Ci rubles.\nThe sealing process consists in picking the stripe and sticking it on the border of the window. The stripe can't be cut (it is made of very lasting material) and can only be put straight, without foldings. It is not necessary to put the strip strictly on the window border, it can possibly extend outside the border side of window too (by any possible amount). The window is considered sealed up if every point on its' border is covered with at least one stripe.\nNow Sergey is curious about the stripes he needs to buy. He wonders about the cheapest cost, at which he can seal his window. Please help him.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe first line of each test case contains a single integer N denoting the number of number of vertices in the polygon denoting Sergey's window.\nEach of the following N lines contains a pair of space-separated integer numbers Xi Yi, denoting the coordinates of the ith points.\nThe following line contains a single integer M denoting the number of types of sticky stripe which is sold in the shop.\nEach of the following M lines contains a pair of space-separated integers Li Ci denoting the length and the cost of the sticky stripe of the ith type respectively.\n\n-----Output-----\nFor each test case, output a single line containing the minimum cost of sealing up the window.\n\n-----Constraints-----\n- 1 ≤ T ≤ 10\n- The coordinates of the window are given either in clockwise or in a counter-clockwise order.\n- No three or more vertices lie on the same line (i.e. are collinear).\n- 0 ≤ Xi, Yi ≤ 106\n- 1 ≤ Li, Ci ≤ 106\n\n-----Subtasks-----\n- Subtask #1 (17 points): 3 ≤ N ≤ 10, M = 1\n- Subtask #2 (24 points): 3 ≤ N ≤ 42, M ≤ 2\n- Subtask #3 (59 points): 3 ≤ N ≤ 2000, 1 ≤ M ≤ 10\n\n-----Example-----\nInput:1\n4\n0 0\n1000 0\n1000 2000\n0 2000\n2\n1000 10\n2000 15\n\nOutput:50\n\n-----Explanation-----\nExample case 1. In this case, Sergey's window is a rectangle with the side lengths of 1000 and 2000. There are two types of the sticky stripes in the shop - the one of the length 1000 with the cost of 10 rubles and with the length of 2000 and the cost of 15 rubles. The optimal solution would be to buy 2 stripes of the first type 2 stripes of the second type. The cost will be 2 × 15 + 2 × 10 = 50 rubles.", "starter_code": "", "test_cases": {"inputs": ["1\n4\n0 0\n1000 0\n1000 2000\n0 2000\n2\n1000 10\n2000 15"], "outputs": ["50"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "d3209493a5bfea3d4bd6db48c819cab0adcb26e1", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00727", "original_id": null, "source": "apps", "domain": "code", "problem": "Dr. S. De teaches computer architecture in NIT Patna. Whenever he comes across any good question(with complexity $k$), he gives that question to students within roll number range $i$ and $j$\nAt the start of semester he assigns score of $10$ to every student in his class if a student submits a question of complexity $k$, his score gets multiplied by $k$\nThis month he gave $M$ questions and he is wondering what will be mean of maximum scores of all the student. He is busy in improving his finger print attendance module, can you help him?\nInput file may be large so try to use fast input output\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a First line of input, two integers $N, M$ i.e. Number of students in the class and number of questions given in this month. \n- Next $M$ lines contains 3 integers -$i, j, k$ i.e. starting roll number, end roll number and complexity of the question\n\n-----Output:-----\nFor each testcase, output in a single line answer - $floor$ value of Mean of maximum possible score for all students.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N, M \\leq 10^5$\n- $1 \\leq i \\leq j \\leq N$\n- $1 \\leq k \\leq 100$\n\n-----Subtasks-----\nSubtask1 \n- \n$1 \\leq T \\leq 10$\n- \n$1 \\leq N, M \\leq 10^4$\nSubtask2\n- \nOriginal Constraints \n\n-----Sample Input:-----\n1\n5 3\n1 3 5\n2 5 2\n3 4 7\n\n-----Sample Output:-----\n202\n\n-----EXPLANATION:-----\nInitial score of students will be : $[10, 10, 10, 10, 10]$\nafter solving question 1 scores will be: $[50, 50, 50, 10, 10]$\nafter solving question 2 scores will be: $[50, 100, 100, 20, 20]$\nafter solving question 1 scores will be: $[50, 100, 700, 140, 20]$\nHence after all questions mean of maximum scores will $(50+100+700+140+20)/5 = 202$", "starter_code": "", "test_cases": {"inputs": ["1\n5 3\n1 3 5\n2 5 2\n3 4 7"], "outputs": ["202"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "5555349d62a8b61e262b21763d5c66d67587ab93", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00732", "original_id": null, "source": "apps", "domain": "code", "problem": "A group of rebels travelling on a square hoverboard is ambushed by Imperial Stormtroopers.Their big hoverboard is an easy target, so they decide to split the board into smaller square hoverboards so that they can bolt away easily.But they should also make sure they don't get too spread out.Help the rebels split the craft into minimum number of smaller crafts possible.\n\n-----Input-----\nA single integer N denoting the side length of the big hoverboard.\n\n-----Output-----\nIn the first line, output the integer 'k' which is the minimum number of square boards into which the bigger board can be split up.\n\nIn the second line, output k space separated integers which denote the sizes of the smaller square hoverboards.This must be in increasing order of sizes.\n\n-----Constraints-----\nN ranges from 2 to 50.\n\n-----Example-----\nInput:\n3\n\nOutput:\n6\n1 1 1 1 1 2\n\n-----Explanation-----\nA square of side length 3 can be split into smaller squares in two ways: Either into 9 squares of side1 or 5 squares of side 1 and 1 square of size 2.The second case is the favourable one.", "starter_code": "", "test_cases": {"inputs": ["3"], "outputs": ["6\n1 1 1 1 1 2"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "ad2aa5e26d06deb4114ebca07b4ce3483a94acf3", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00737", "original_id": null, "source": "apps", "domain": "code", "problem": "Anmol gained a lot of weight last semester. So this semester, he decided to run everyday. There is a very long straight road starting at his hostel. There are N poles on the road - P1, P2, P3,..., PN on the road. All the poles lie on the same side of his hostel. The distance between Pi and his hostel is Di.\nFor 1 ≤ i, j ≤ N, i < j implies Di < Dj\nEveryday, Anmol chooses a pole Pi to start running from. He keeps on running until he reaches Pi+K. Whenever he reaches a pole (other than the starting pole), he records the distance traveled since the last pole.\n\nYou are given the distances recorded by him today. Your task is to find the number of distinct values of i such that i + K ≤ N and if he starts at Pi and end at Pi+K, he would end up having exactly the same record of distances (in the same order).\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases.\n- The first line of each test case contains two space separated integers N and K.\n- The next line contains N space separated integers D1, D2,..., DN.\n- The next line contains K space separated integers representing the distances recorded by Anmol in the same order.\n.\n\n-----Output-----\n- For each test case, output a single line containing the answer for that test case.\n\n-----Constraints-----\n- 1 ≤ T ≤ 10\n- 2 ≤ N ≤ 5 x 104\n- 1 ≤ K < N\n- 1 ≤ Di ≤ 106\n\n-----Subtasks-----\n\n-----Subtask #1 (20 points)-----\n- 1 ≤ N ≤ 1000\n\n-----Subtask #2 (80 points)-----\n- Original constraints\n\n-----Example-----\nInput:\n3\n5 1\n1 5 10 12 14\n5\n5 2\n5 8 13 16 21\n3 5\n5 3\n2 6 8 11 16\n2 3 5\n\nOutput:\n1\n2\n1\n\n-----Explanation-----\nExample case 1. If he runs from P2 to P3, he will record (5)\nExample case 2. He can start at P1 or P3\nExample case 3. He can start at P2", "starter_code": "", "test_cases": {"inputs": ["3\n5 1\n1 5 10 12 14\n5\n5 2\n5 8 13 16 21\n3 5\n5 3\n2 6 8 11 16\n2 3 5"], "outputs": ["1\n2\n1"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "efd002ef134c24cc79bf109858cdc995f69295d3", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00742", "original_id": null, "source": "apps", "domain": "code", "problem": "You have been recently hired as a developer in CodeChef. Your first mission is to implement a feature that will determine the number of submissions that were judged late in a contest.\nThere are $N$ submissions, numbered $1$ through $N$. For each valid $i$, the $i$-th submission was submitted at time $S_i$ and judged at time $J_i$ (in minutes). Submitting and judging both take zero time. Please determine how many submissions received their verdicts after a delay of more than $5$ minutes.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of the input contains a single integer $N$.\n- $N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $S_i$ and $J_i$.\n\n-----Output-----\nFor each test case, print a single line containing one integer — the number of submissions for which the judging was delayed by more than 5 minutes.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N \\le 100$\n- $1 \\le S_i \\le J_i \\le 300$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n1\n5\n1 3\n4 4\n4 10\n1 11\n2 7\n\n-----Example Output-----\n2\n\n-----Explanation-----\nExample case 1: The delays of the respective submissions are $2$ minutes, $0$ minutes, $6$ minutes, $10$ minutes and $5$ minutes. Only submissions $3$ and $4$ are delayed by more than $5$ minutes, hence the answer is $2$.", "starter_code": "", "test_cases": {"inputs": ["1\n5\n1 3\n4 4\n4 10\n1 11\n2 7"], "outputs": ["2"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "0d58ede58f60aded1c399e5f0ca115a0c86cccb8", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00747", "original_id": null, "source": "apps", "domain": "code", "problem": "The chef likes to play with numbers. He takes some integer number x, writes it down on his iPad, and then performs with it n−1 operations of the two kinds:\n- divide the number x by 3 (x must be divisible by 3);\n- multiply the number x by 2.\nAfter each iteration, Chef writes down the result on his iPad and replaces x with the result. So there will be n numbers on the iPad after all.\nYou are given a sequence of length n — the numbers that Chef wrote down. This sequence is given in the order of the sequence can mismatch the order of the numbers written on the iPad.\nYour problem is to rearrange elements of this sequence in such a way that it can match a possible Chef's game in the order of the numbers written on the board. I.e. each next number will be exactly two times the previous number or exactly one-third of the previous number.\nI can give a guarantee that the answer exists.\n\n-----Input:-----\n- The first line of the input contains an integer number N i.e the number of the elements in the sequence. \n- The second line of the input contains n integer numbers a1,a2,…, an i.e rearranged (reordered) sequence that Chef can write down on the iPad.\n\n-----Output:-----\nPrint N integer numbers — rearranged (reordered) input sequence that can be the sequence that Chef could write down on the iPad.\nIt is guaranteed that the answer exists\n\n-----Constraints-----\n- $2 \\leq N \\leq 100$\n- $1 \\leq A[i] \\leq 3* 10^{18} $\n\n-----Sample Input:-----\n6\n4 8 6 3 12 9\n\n-----Sample Output:-----\n9 3 6 12 4 8 \n\n-----EXPLANATION:-----\nIn the first example, the given sequence can be rearranged in the following way: [9,3,6,12,4,8]. It can match possible Polycarp's game which started with x=9.", "starter_code": "", "test_cases": {"inputs": ["6\n4 8 6 3 12 9"], "outputs": ["9 3 6 12 4 8"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "d2572033a79b905474d21ed79656916d456b90ce", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00752", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef recently learned about concept of periodicity of strings. A string is said to have a period P, if P divides N and for each i, the i-th of character of the string is same as i-Pth character (provided it exists), e.g. \"abab\" has a period P = 2, It also has a period of P = 4, but it doesn't have a period of 1 or 3.\nChef wants to construct a string of length N that is a palindrome and has a period P. It's guaranteed that N is divisible by P. This string can only contain character 'a' or 'b'. Chef doesn't like the strings that contain all a's or all b's.\nGiven the values of N, P, can you construct one such palindromic string that Chef likes? If it's impossible to do so, output \"impossible\" (without quotes)\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases.\nThe only line of each test case contains two space separated integers N, P.\n\n-----Output-----\nFor each test case, output a single line containing the answer of the problem, i.e. the valid string if it exists otherwise \"impossible\" (without quotes). If there are more than possible answers, you can output any.\n\n-----Constraints-----\n- 1 ≤ T ≤ 20\n- 1 ≤ P, N ≤ 105\n\n-----Subtasks-----\n- Subtask #1 (25 points) : P = N\n- Subtask #2 (75 points) : No additional constraints\n\n-----Example-----\nInput\n5\n3 1\n2 2\n3 3\n4 4\n6 3\n\nOutput\nimpossible\nimpossible\naba\nabba\nabaaba\n\n-----Explanation-----\nExample 1: The only strings possible are either aaa or bbb, which Chef doesn't like. So, the answer is impossible.\nExample 2: There are four possible strings, aa, ab, ba, bb. Only aa and bb are palindromic, but Chef doesn't like these strings. Hence, the answer is impossible.\nExample 4: The string abba is a palindrome and has a period of 4.\nExample 5: The string abaaba is a palindrome and has a period of length 3.", "starter_code": "", "test_cases": {"inputs": ["5\n3 1\n2 2\n3 3\n4 4\n6 3"], "outputs": ["impossible\nimpossible\naba\nabba\nabaaba"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "16bdbfbda4a7cebee25f7f3feacdaa1c2d7ac9fa", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00757", "original_id": null, "source": "apps", "domain": "code", "problem": "Consider a 2d-grid. That is, each cell is identified by (i,j). You have received reports of two snake-sightings on this grid. You want to check whether they could be partial sightings of the same snake or not.\nEach of the snake sightings correspond to a straight, axis-parallel line segment in the grid, and the starting and ending cells for each are given to you. Now consider a graph, where each cell in the 2d-grid is a vertex. And there is an edge between 2 vertices if and only if the cells corresponding to these two vertices are consecutive cells in at least one of the two snakes. That is, at least in one of the snakes, when you go from one end point to the other end point, these two cells should occur consecutively.\nThe two sightings/snakes are said to be same, if both these conditions are satisfied:\n- The union of the set of cells in the first snake and the set of cells in the second snake, should form a connected component in this graph.\n- No vertex should have degree more than 2 in the graph.\nIn other words, the induced subgraph on the union set must be a path graph.\n\n-----Input-----\n- The first line contains a single integer, T, which is the number of testcases. The description of each testcase follows.\n- The first line of each testcase contains four integers: X11, Y11, X12, Y12. This represents the fact that the first snake's end points are (X11, Y11) and (X12, Y12).\n- The second line of each testcase contains four integers: X21, Y21, X22, Y22. This represents the fact that the second snake's end points are (X21, Y21) and (X22, Y22).\n\n-----Output-----\n- For each testcase, output \"yes\" if the snakes are the same, as per the definition given above. Output \"no\" otherwise.\n\n-----Constraints-----\n- 1 ≤ T ≤ 105\n- -109 ≤ Xij,Yij ≤ 109\n- The two end points of every snake is guaranteed to be either on the same row or on the same column. Thus, the snake occupies all the cells between these cells, including the end points.\n\n-----Example-----\nInput:\n4\n2 1 8 1\n11 1 7 1\n2 1 8 1\n11 1 9 1\n2 1 8 1\n3 1 3 -2\n2 1 8 1\n2 1 2 -2\nOutput:\nyes\nno\nno\nyes\n\n-----Explanation-----\nIn the images, the first snake is red, the second snake is yellow, and the intersections, if any, are in orange.\nThe first test case corresponds to:\n\nBoth the conditions on the graph are satisfied, and hence this is a \"yes\".\nThe second test case corresponds to:\n\nThere is no edge between the vertex corresponding to the (8,1) cell and the vertex corresponding to (9,1), Hence, the union set is disconnected, and thus the answer is \"no\". \nThe third test case corresponds to:\n\nThe vertex corresponding to the cell (3,1) has degree 3, which is more than 2, and thus the answer is \"no\". \nThe fourth test case corresponds to:\n\nBoth the conditions on the graph are satisfied, and hence this is a \"yes\".", "starter_code": "", "test_cases": {"inputs": ["4\n2 1 8 1\n11 1 7 1\n2 1 8 1\n11 1 9 1\n2 1 8 1\n3 1 3 -2\n2 1 8 1\n2 1 2 -2"], "outputs": ["yes\nno\nno\nyes"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "4fddd1f28eebd852c456b9857d8d10d7c2d76c49", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00762", "original_id": null, "source": "apps", "domain": "code", "problem": "Ripul was skilled in the art of lapidary. He used to collect stones and convert it into decorative items for sale. There were n stone shops. Each shop was having one exclusive stone of value s[i] , where 1<=i<=n. If number of stones collected are more than 1, then total value will be product of values of all the stones he collected. Ripul wants to have maximum value of stones he collected. Help Ripul in picking up the subarray which leads to maximum value of stones he collected.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- The first line of each testcase contains an integer $N$, denoting number of elements in the given array.\n- The second line contains $N$ space-separated integers $S1$, $S2$, …, $SN$ denoting the value of stone in each shop. \n\n-----Output:-----\nFor each testcase, output the maximum value of stones possible, the starting index and ending index of the chosen subarray (0-based indexing). If there are multiple subarrays with same value, print the one with greater starting index. If there are multiple answer subarrays with same starting index, print the one with greater ending index. (The answer will fit in 64 bit binary number).\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^5$\n- $-100 \\leq S[i] \\leq 100$\n\n-----Subtasks-----\n- 30 points : $1 \\leq N \\leq 10^3$\n- 70 points : $1 \\leq N \\leq 10^5$\n\n-----Sample Input:-----\n1\n3\n\n1 2 3\n\n-----Sample Output:-----\n6 1 2\n\n-----EXPLANATION:-----\nIf Ripul collects all the all the three gems, total value will be 6 (1 * 2 * 3).\nIf Ripul collects last two gems, total value will be 6 (1 * 2 * 3).\nSo, he picks the subarray with greater starting index.", "starter_code": "", "test_cases": {"inputs": ["1\n3\n1 2 3"], "outputs": ["6 1 2"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "d2e13155f8425aba830f31a398fd77a5829c619d", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00767", "original_id": null, "source": "apps", "domain": "code", "problem": "-----\nARRAY AND DISTINCT ELEMENTS\n-----\n\nChef is multitalented but he mistakenly took part in 2 contest which will take place\nat the same time. So while chef is busy at one cooking contest, he wants you to\ntake part in coding contest. Chef wants u to solve this program for him.\n\n\t\n\nYou have been given an array of size n. You have to calculate a subarray of size k\nwith maximum sum having distinct elements same as original array.\n\n\t\t\n\t\t\n\n-----Input Format-----\n\nFirst line contains no. of test cases. Second line contains n and k. Third line\ncontains array of n integers.\n\n\n-----Output-----\n\nPrint maximum possible sum as stated in question\n\n\t\t\n\t\t\n\n-----Example Text Case-----\nInput:\n\n1\n10 6\n8 8 3 5 3 8 5 7 7 7\n\nOutput:\n37\n\n\t\t", "starter_code": "", "test_cases": {"inputs": ["1\n10 6\n8 8 3 5 3 8 5 7 7 7"], "outputs": ["37"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "ec1c1592878d342c0c76b1015f94699f72433dfb", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00772", "original_id": null, "source": "apps", "domain": "code", "problem": "Alice is a very brilliant student. He considers '4' and '7' as Magic numbers. The numbers containing only magic numbers are also magical. Given a magic number N ,he wants to know what could be the next magical number greater than the given number.\n\n-----Input-----\n\nFirst line of input contains number of test cases T. For each test case, there is exits only one line containing a magic number N. \n\n-----Output-----\n\nFor each test case, output a single line containing the next greater magical number.\n\n-----Constraints-----\n1<=T<=1000\n4<= N<=10^100\n\n-----Example-----\nInput:\n2\n4\n47\n\nOutput:\n7\n74", "starter_code": "", "test_cases": {"inputs": ["2\n4\n47\n\n"], "outputs": ["7\n74"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "47b681b70750608ac7043219a85ad7b46dbf260a", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00777", "original_id": null, "source": "apps", "domain": "code", "problem": "Ho, Ho, Ho!\nIt's Christmas time and our friendly grandpa Santa Claus is busy distributing gifts to all the nice children. With the rising population, Santa's workload every year gets increased and he seeks your help to wrap the gifts with fancy wrapping papers while he gets them distributed. \nEverything was going great until you realised that you'll fall short of wrapping paper. But luckily, you get a very innovative idea, that will allow you to pack all the remaining gifts without worrying about lack of wrapping paper. Any guesses what the idea is? Using ice for wrapping, obviously! That's the only thing available at the North Pole.\nNow, in order to reduce your trips to the ice factory, you decide to write a program that helps you visualize how much ice is needed for a particular gift. \n\n-----Input:-----\nInput will consist of a single line with size $n$.\n\n-----Output:-----\nPrint the ice wrapped gift box for the given size. \n\n-----Constraints-----\n- $0 \\leq n \\leq 1000$\n\n-----Sample Input:-----\n4\n\n-----Sample Output:-----\n4 4 4 4 4 4 4\n4 3 3 3 3 3 4\n4 3 2 2 2 3 4\n4 3 2 1 2 3 4\n4 3 2 2 2 3 4 \n4 3 3 3 3 3 4\n4 4 4 4 4 4 4", "starter_code": "", "test_cases": {"inputs": ["4"], "outputs": ["4 4 4 4 4 4 4\n4 3 3 3 3 3 4\n4 3 2 2 2 3 4\n4 3 2 1 2 3 4\n4 3 2 2 2 3 4\n4 3 3 3 3 3 4\n4 4 4 4 4 4 4"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "0388e8c8bed981bdf6d623522478909d1600b9f3", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00782", "original_id": null, "source": "apps", "domain": "code", "problem": "Ada's classroom contains $N \\cdot M$ tables distributed in a grid with $N$ rows and $M$ columns. Each table is occupied by exactly one student.\nBefore starting the class, the teacher decided to shuffle the students a bit. After the shuffling, each table should be occupied by exactly one student again. In addition, each student should occupy a table that is adjacent to that student's original table, i.e. immediately to the left, right, top or bottom of that table.\nIs it possible for the students to shuffle while satisfying all conditions of the teacher?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $N$ and $M$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"YES\" if it is possible to satisfy the conditions of the teacher or \"NO\" otherwise (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 5,000$\n- $2 \\le N, M \\le 50$\n\n-----Example Input-----\n2\n3 3\n4 4\n\n-----Example Output-----\nNO\nYES\n\n-----Explanation-----\nExample case 2: The arrows in the following image depict how the students moved.", "starter_code": "", "test_cases": {"inputs": ["2\n3 3\n4 4"], "outputs": ["NO\nYES"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "195f16ddaccae47faad8a24b2509024f46570f47", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00787", "original_id": null, "source": "apps", "domain": "code", "problem": "You are given two integers $N$ and $M$. Find the number of sequences $A_1, A_2, \\ldots, A_N$, where each element is an integer between $1$ and $M$ (inclusive) and no three consecutive elements are equal. Since this number could be very large, compute it modulo $10^9+7$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $N$ and $M$.\n\n-----Output-----\nFor each test case, print a single line containing one integer ― the number of valid sequences modulo $10^9+7$.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $1 \\le N, M \\le 10^{18}$\n\n-----Subtasks-----\nSubtask #1 (50 points):\n- $T \\le 20$\n- $N \\le 10^5$\nSubtask #2 (50 points): original constraints\n\n-----Example Input-----\n2 \n2 2\n3 4\n\n-----Example Output-----\n4\n60", "starter_code": "", "test_cases": {"inputs": ["2\n2 2\n3 4"], "outputs": ["4\n60"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "3088f46390ed4edde655782e3b74cbba71f34e7c", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00792", "original_id": null, "source": "apps", "domain": "code", "problem": "Every day, Mike goes to his job by a bus, where he buys a ticket. On the ticket, there is a letter-code that can be represented as a string of upper-case Latin letters.\nMike believes that the day will be successful in case exactly two different letters in the code alternate. Otherwise, he believes that the day will be unlucky. Please see note section for formal definition of alternating code.\nYou are given a ticket code. Please determine, whether the day will be successful for Mike or not. Print \"YES\" or \"NO\" (without quotes) corresponding to the situation.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe first and only line of each test case contains a single string S denoting the letter code on the ticket.\n\n-----Output-----\nFor each test case, output a single line containing \"YES\" (without quotes) in case the day will be successful and \"NO\" otherwise.\n\n-----Note-----\nTwo letters x, y where x != y are said to be alternating in a code, if code is of form \"xyxyxy...\".\n\n-----Constraints-----\n\n- 1 ≤ T ≤ 100\n- S consists only of upper-case Latin letters\n\nSubtask 1 (50 points):\n\n- |S| = 2\n\nSubtask 2 (50 points):\n\n- 2 ≤ |S| ≤ 100\n\n-----Example-----\nInput:\n2\nABABAB\nABC\n\nOutput:\nYES\nNO", "starter_code": "", "test_cases": {"inputs": ["2\nABABAB\nABC"], "outputs": ["YES\nNO"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "bff8caa0e3c7d02d3893b24c90dfdcc58b94fe5d", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00797", "original_id": null, "source": "apps", "domain": "code", "problem": "Let's define the niceness of a sequence of positive integers X1,X2,…,XN$X_1, X_2, \\dots, X_N$ as the sum of greatest common divisors of all pairs of its elements, i.e.\nN∑i=1N∑j=i+1gcd(Xi,Xj).∑i=1N∑j=i+1Ngcd(Xi,Xj).\\sum_{i=1}^N \\sum_{j=i+1}^N \\mathrm{gcd}(X_i, X_j)\\;.\nFor example, the niceness of the sequence [1,2,2]$[1, 2, 2]$ is gcd(1,2)+gcd(1,2)+gcd(2,2)=4$gcd(1, 2) + gcd(1, 2) + gcd(2, 2) = 4$.\nYou are given a sequence A1,A2,…,AN$A_1, A_2, \\dots, A_N$; each of its elements is either a positive integer or missing.\nConsider all possible ways to replace each missing element of A$A$ by a positive integer (not necessarily the same for each element) such that the sum of all elements is equal to S$S$. Your task is to find the total niceness of all resulting sequences, i.e. compute the niceness of each possible resulting sequence and sum up all these values. Since the answer may be very large, compute it modulo 109+7$10^9 + 7$.\n\n-----Input-----\n- The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows.\n- The first line of each test case contains two space-separated integers N$N$ and S$S$. \n- The second line contains N$N$ space-separated integers A1,A2,…,AN$A_1, A_2, \\dots, A_N$. Missing elements in this sequence are denoted by −1$-1$.\n\n-----Output-----\nFor each test case, print a single line containing one integer — the total niceness modulo 109+7$10^9 + 7$.\n\n-----Constraints-----\n- 1≤T≤20$1 \\le T \\le 20$\n- 1≤N,S≤50$1 \\le N, S \\le 50$\n- 1≤Ai≤50$1 \\le A_i \\le 50$ or Ai=−1$A_i = -1$ for each valid i$i$\n\n-----Subtasks-----\nSubtask #1 (30 points):\n- 1≤N,S≤18$1 \\le N, S \\le 18$\n- 1≤Ai≤18$1 \\le A_i \\le 18$ or Ai=−1$A_i = -1$ for each valid i$i$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n3\n3 3\n1 1 -1\n4 8\n1 -1 -1 3\n3 10\n-1 -1 -1\n\n-----Example Output-----\n3\n23\n150\n\n-----Explanation-----\nExample case 1: There is only one possible way to fill in the missing element; the resulting sequence is [1,1,1]$[1, 1, 1]$. Its niceness is 3$3$.\nExample case 2: There is only three possible ways to fill in the missing elements; the resulting sequences are [1,1,3,3]$[1, 1, 3, 3]$, [1,3,1,3]$[1, 3, 1, 3]$, and [1,2,2,3]$[1, 2, 2, 3]$. The sum of their niceness is 8+8+7=23$8 + 8 + 7 = 23$.", "starter_code": "", "test_cases": {"inputs": ["3\n3 3\n1 1 -1\n4 8\n1 -1 -1 3\n3 10\n-1 -1 -1\n"], "outputs": ["3\n23\n150"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "9e3f51d6275b9f668084b8d23e489b5700749d63", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00802", "original_id": null, "source": "apps", "domain": "code", "problem": "Indraneel has to sort the books in his library. His library has one long shelf. His books are numbered $1$ through $N$ and he wants to rearrange the books so that they appear in the sequence $1,2, ..., N$.\nHe intends to do this by a sequence of moves. In each move he can pick up any book from the shelf and insert it at a different place in the shelf. Suppose Indraneel has $5$ books and they are initially arranged in the order\n21453214532 \\quad 1 \\quad 4 \\quad 5 \\quad 3\nIndraneel will rearrange this in ascending order by first moving book $1$ to the beginning of the shelf to get\n12453124531 \\quad 2 \\quad 4 \\quad 5 \\quad 3\nThen, moving book $3$ to position $3$, he gets\n12345123451 \\quad 2 \\quad 3 \\quad 4 \\quad 5\nYour task is to write a program to help Indraneel determine the minimum number of moves that are necessary to sort his book shelf.\n\n-----Input:-----\nThe first line of the input will contain a single integer $N$ indicating the number of books in Indraneel's library. This is followed by a line containing a permutation of $1, 2, ..., N$ indicating the intial state of Indraneel's book-shelf.\n\n-----Output:-----\nA single integer indicating the minimum number of moves necessary to sort Indraneel's book-shelf.\n\n-----Constraints:-----\n- $1 \\leq N \\leq 200000$.\n- You may also assume that in $50 \\%$ of the inputs, $1 \\leq N \\leq 5000$.\n\n-----Sample Input-----\n5\n2 1 4 5 3 \n\n-----Sample Output-----\n2", "starter_code": "", "test_cases": {"inputs": ["5\n2 1 4 5 3"], "outputs": ["2"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "f225514c3491daddbda14bdd7b2b2f3297c4c180", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00807", "original_id": null, "source": "apps", "domain": "code", "problem": "After failing to clear his school mathematics examination, infinitepro decided to prepare very hard for his upcoming re-exam, starting with the topic he is weakest at ― computational geometry.\nBeing an artist, infinitepro has C$C$ pencils (numbered 1$1$ through C$C$); each of them draws with one of C$C$ distinct colours. He draws N$N$ lines (numbered 1$1$ through N$N$) in a 2D Cartesian coordinate system; for each valid i$i$, the i$i$-th line is drawn with the ci$c_i$-th pencil and it is described by the equation y=ai⋅x+bi$y = a_i \\cdot x + b_i$.\nNow, infinitepro calls a triangle truly-geometric if each of its sides is part of some line he drew and all three sides have the same colour. He wants to count these triangles, but there are too many of them! After a lot of consideration, he decided to erase a subset of the N$N$ lines he drew. He wants to do it with his eraser, which has length K$K$.\nWhenever erasing a line with a colour i$i$, the length of the eraser decreases by Vi$V_i$. In other words, when the eraser has length k$k$ and we use it to erase a line with a colour i$i$, the length of the eraser decreases to k−Vi$k-V_i$; if k 10$, this participant does not receive a certificate.\n- Participant $4$ watched $1 + 1 + 1 + 3 = 6$ minutes of lectures and asked the question $12$ times. Since $6 < M$ and $12 > 10$, this participant does not receive a certificate.\nOnly participant $2$ receives a certificate.", "starter_code": "", "test_cases": {"inputs": ["4 8 4\n1 2 1 2 5\n3 5 1 3 4\n1 2 4 5 11\n1 1 1 3 12"], "outputs": ["1"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "d94850449da0a1f2bbb51e97bd9995deea3ace9d", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00817", "original_id": null, "source": "apps", "domain": "code", "problem": "You are given a tree with $N$ vertices (numbered $1$ through $N$) and a sequence of integers $A_1, A_2, \\ldots, A_N$. You may choose an arbitrary permutation $p_1, p_2, \\ldots, p_N$ of the integers $1$ through $N$. Then, for each vertex $i$, you should assign the value $A_{p_i}$ to this vertex.\nThe profit of a path between two vertices $u$ and $v$ is the sum of the values assigned to the vertices on that path (including $u$ and $v$).\nLet's consider only (undirected) paths that start at a leaf and end at a different leaf. Calculate the maximum possible value of the sum of profits of all such paths. Since this value could be very large, compute it modulo $10^9 + 7$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n- Each of the following $N−1$ lines contains two space-separated integers $u$ and $v$ denoting that vertices $u$ and $v$ are connected by an edge.\n\n-----Output-----\nFor each test case, print a single line containing one integer — the maximum sum of profits, modulo $10^9 + 7$.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le N \\le 300,000$\n- $1 \\le A_i \\le 10^9$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $5 \\cdot 10^5$\n\n-----Example Input-----\n2\n4\n1 2 3 4\n1 2\n2 3\n2 4\n5\n1 2 3 4 5\n1 2\n2 3\n3 4\n4 5\n\n-----Example Output-----\n24\n15\n\n-----Explanation-----\nExample case 1: $(1, 4, 2, 3)$ is one of the possible permutations that give the optimal answer. Then, the profits of paths between pairs of vertices $(1, 3)$, $(1, 4)$ and $(3, 4)$ are $7$, $8$ and $9$ respectively.\nExample case 2: Here, any permutation could be chosen.", "starter_code": "", "test_cases": {"inputs": ["2\n4\n1 2 3 4\n1 2\n2 3\n2 4\n5\n1 2 3 4 5\n1 2\n2 3\n3 4\n4 5"], "outputs": ["24\n15"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "3b1a8d7f6829c716eb435ddd6163ec207f388829", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00822", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef is stuck on the minute hand of a giant clock. To escape from this clock he needs to get onto the hour hand which has an exit door. \nSince the minute hand and and hour hand are not connected at any point, chef will surely need to make a jump. Since he wants minimum risks, he chooses to jump on the hour hand so that the angle he has to cover is minimum possible.\nYou will be given a clock time in $UTC$ format denoting time of chef's jump and you have to compute the minimum angle that chef needs to cover while completing the jump.\nFor some reason chef times his jump only when the number of minutes is a multiple of 5.\n\n-----Input:-----\nThe first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\nThe first line of each test case contains a string denoting time in UTC format (e.g. 10:20 i.e. 10 hours and 20 minutes)\n\n-----Output-----\nFor each test case, print a single line denoting the smallest angle of jump.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^3$\n- $0 \\leq hours \\leq 23$\n- $0 \\leq minutes \\leq 59$\n\n-----Example Input-----\n3\n14:20\n02:10\n09:30\n\n-----Example Output-----\n50 degree \n5 degree \n105 degree\n\n-----Explanation-----\n- In the second case, once the hour hand reaches 2 it starts moving towards 3 with the passing of every minute, hence when the minute hand points 10 minutes, the hour hand has already covered some angle towards 3. \nIn this scenario the two angles made by hour and minute hand are 355 and 5 degrees. Since chef will jump on the side with minimum angle, he chooses the one with 5-degree angle.", "starter_code": "", "test_cases": {"inputs": ["3\n14:20\n02:10\n09:30"], "outputs": ["50 degree\n5 degree\n105 degree"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "df7eab42e71127ab7f6d2d7947f3da79017bd0ce", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00827", "original_id": null, "source": "apps", "domain": "code", "problem": "\"How did you get the deal,how did he agree?\"\n\"Its's simple Tom I just made him an offer he couldn't refuse\" \nAyush is the owner of a big construction company and a close aide of Don Vito The Godfather, recently with the help of the Godfather his company has been assigned a big contract according to the contract he has to make n number of V shaped infinitely long roads(two V shaped roads may or not intersect) on an infinitely large field.\nNow the company assigning the contract needs to know the maximum number of regions they can get after making n such roads.\nHelp Ayush by answering the above question.\n\n-----Input:-----\n- The first line consists of the number of test cases $T$. \n- Next T lines consists of the number of V shaped roads $n$.\n\n-----Output:-----\nFor each test case print a single line consisting of the maximum regions obtained.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq n \\leq 10^9$\n\n-----Sample Input:-----\n2\n1\n2\n\n-----Sample Output:-----\n2\n7\n\n-----EXPLANATION:-----\nTest case 1: For one V shaped road there will be 2 regions\n\nTest case 2: For n=2 the following figure depicts the case of maximum regions:", "starter_code": "", "test_cases": {"inputs": ["2\n1\n2"], "outputs": ["2\n7"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "169dc977c01c54155bcbded0d021b1c813bf1ea9", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00832", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef has an array of N natural numbers most of them are repeated. Cheffina challenges chef to find all numbers(in ascending order) whose frequency is strictly more than K.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains two lines of input, two integers $N, K$.\n- N space-separated natural numbers.\n\n-----Output:-----\nFor each test case, output in a single line answer.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N, K \\leq 10^5$\n- $1 \\leq arr[i] \\leq 10^5$\n\n-----Sample Input:-----\n1\n5 1\n5 2 1 2 5\n\n-----Sample Output:-----\n2 5", "starter_code": "", "test_cases": {"inputs": ["1\n5 1\n5 2 1 2 5"], "outputs": ["2 5"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "8ea9ba25c3572c02a332d239456027bc989415f9", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00837", "original_id": null, "source": "apps", "domain": "code", "problem": "Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way such that they won't leave any empty space in between two consecutive persons at any given time. \n\nWhen a person number i arrives at the corridor, he must go and stand to the immediate right of the person numbered A[i] (if A[i] = 0, then this person just stands at the leftmost end of the line). \n\nBut there is a problem, as there is no space between two consecutive persons at any given time, so for this person to sit, space must be created by moving either all the persons to left of the place to the left one step each, or all the persons to right of the place to the right one step each. \n\nNow, Sereja is wondering about what could be the minimum number of steps people will take so as to sit in the dinner party. Please find it fast, so that Sereja can peacefully entertain his guests.\n\n-----Input-----\nFirst line of input contain an integer T — the number of test cases. T tests follow.\nFirst line of each test case contain the integer N, and the next line contains N integers — A[1], A[2], ... , A[N].\n\n-----Output-----\nFor each test case, output a single line with the answer — the minimal number of steps required.\n\n-----Constraints-----\n- 1 ≤ T ≤ 100\n- 1 ≤ N ≤ 100\n- 0 ≤ A[i] < i\n\n-----Example-----\nInput:\n3\n1\n0\n3\n0 0 0\n5\n0 1 2 1 4\n\nOutput:\n0\n0\n3\n\n-----Explanation-----\nExample case 3.\n- First three persons don't need any steps to sit. The line after the arrangement of these persons will look like [1, 2, 3]. \n\n- When person #4 comes in, he wants to sit to the right of person 1, so we need to either move the first person to the left, or the second and third persons to the right. The first case is clearly better. Now the line will look like [1, 4, 2, 3]. \n\n- When person #5 arrives, he will need to move 2 persons in either case. The final arrangement will be [1, 4, 5, 2, 3]. \n\nSo total number of steps people moved during the entire process is 1 + 2 = 3. So the answer is 3.", "starter_code": "", "test_cases": {"inputs": ["3\n1\n0\n3\n0 0 0\n5\n0 1 2 1 4"], "outputs": ["0\n0\n3"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "ea2f4a0b0e11136503f13243c7a6a1c7b7297d1b", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00842", "original_id": null, "source": "apps", "domain": "code", "problem": "Devu loves to play with binary strings a lot. One day he borrowed a binary string s of size n from his friend Churu. Before starting to play with it, he wants to make sure that string does not contain more than k consecutive equal characters. For achieving that, only kind of operation he is allowed to perform is to flip any ith character of the string. \n\nAs Devu is always in hurry to meet his girlfriend, he wants you to help him in finding out the minimum number of operations he will need. Also he wants you to print one of the possible modified string too.\n\n-----Input-----\n- First line of input contains an integer T denoting the number of test cases. \n- For each test case, there are two lines. \n- First line contains two space separated integers n, k as defined in the problem. \n- Next line contains string s of size n.\n\n-----Output-----\n- For each test case, print two lines.\n- First line should contain an integer corresponding to minimum number of operations Devu needs.\n- In second line, print one of the possible modified strings.\n\n-----Constraints-----\nSubtask #1: 20 points\n- 1 ≤ T ≤ 100, 1 ≤ n ≤ 20, 1 ≤ k ≤ n\n\nSubtask #2: 35 points\n- 1 ≤ T ≤ 102, 1 ≤ n ≤ 103, 1 ≤ k ≤ n\n\nSubtask #3: 45 points\n- 1 ≤ T ≤ 105, 1 ≤ n ≤ 105, 1 ≤ k ≤ n\n- Sum of n over all the test cases is ≤ 106 \n\n-----Example-----\nInput:\n3\n2 1\n11\n2 2\n11\n4 1\n1001\n\nOutput:\n1\n10\n0\n11\n2\n1010\n\n-----Explanation-----\nExample case 1: As 1 is occurring twice consecutively, we can convert 11 to 10 in a single operation.\nExample case 2: You don't need to modify the string as it does not have more than 2 equal consecutive character.\nExample case 3: As 0 is occurring twice consecutively, we can convert 1001 to 1010 in a two operations (Flip third and fourth character).", "starter_code": "", "test_cases": {"inputs": ["3\n2 1\n11\n2 2\n11\n4 1\n1001"], "outputs": ["1\n10\n0\n11\n2\n1010"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "f5ce2773e84ae656bee778a06fb54a820bff7cc2", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00847", "original_id": null, "source": "apps", "domain": "code", "problem": "There is a city with $N$ numbered $0 - N-1$ shops. A market is a place where we can reach from one shop to another using some road. There are $M$ roads in this city connecting each connecting any two shops. \nFind the number of markets in the city.\nNOTE: A market having only one shop is also a valid market.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- First line of Each Test Case is $N, M$, denoting the number of shops and the number of roads respectively.\n- Next M lines consist of two integers $A$ and $B$ denoting that there exists a road between Shop A and Shop B\n\n-----Output:-----\nFor each testcase, output the number of markets.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N,M \\leq 10^3$\n- $0 \\leq A,B < N$\n\n-----Sample Input:-----\n1\n5 3\n0 1\n2 3\n3 4\n\n-----Sample Output:-----\n2", "starter_code": "", "test_cases": {"inputs": ["1\n5 3\n0 1\n2 3\n3 4"], "outputs": ["2"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "ef163e4669a182580cabc51386b019ef7914f429", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00852", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef will not be able to attend the birthday of his best friend Rock. He promised Rock that this will not be the case on his half birthday. To keep his promise Chef must know Rock’s next half birthday accurately. Being busy, he is assigning this work to you.\nHalf birthday is the day that occurs exactly between two subsequent birthdays. \nYou will be provided with Rock’s birthdate and birth month, you will have to figure out his half birthday.\n$Note$: Consider every year to be a leap year and all months are displayed in lowercase English characters.\n\n-----Input:-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. \n- The description of each of the $T$ test cases contains an integer $d$ followed by a string, denoting month $m$.\n- Here $d$ denotes day of a month and $m$ denotes the month of a year respectively.\n\n-----Output:-----\nFor each test case print an integer $d1$ followed by a string, denoting month $m1$, which overall denotes date and month of Rock’s half birthday.\n\n-----Constraints:-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq d , d1 \\leq 31$\n- $january \\leq m , m1 \\leq december$\n\n-----Sample Input:-----\n3\n15 january\n31 august\n10 october\n\n-----Sample Output:-----\n16 july\n1 march\n10 april", "starter_code": "", "test_cases": {"inputs": ["3\n15 january\n31 august\n10 october"], "outputs": ["16 july\n1 march\n10 april"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "2cba8291fe669380696efacee703b996e1ea5c43", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00857", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef has a sequence of N$N$ integers A1,A2,...,AN$A_1, A_2, ..., A_N$. \nChef thinks that a triplet of integers (i,j,k)$(i,j,k)$ is good if 1≤i 0, Ai+1 > 0, and Ai+2 exists, then he can decrease both Ai, and Ai+1 by one and increase Ai+2 by one. If Ai+2 doesn't exist, but Ai > 0, and Ai+1 > 0, then he can decrease both Ai, and Ai+1 (which will be the currently last two elements of the array) by one and add a new element at the end, whose value is 1.\nNow Chef wants to know the number of different arrays that he can make from A using this operation as many times as he wishes. Help him find this, and because the answer could be very large, he is fine with you reporting the answer modulo 109+7.\nTwo arrays are same if they have the same number of elements and if each corresponding element is the same. For example arrays (2,1,1) and (1,1,2) are different. \n\n-----Input-----\n- The first line of the input contains a single integer T denoting the number of test cases.\n- The first line contains a single integer N denoting the initial number of elements in A.\n- The second line contains N space-separated integers: A1, A2, ... , AN. \n\n-----Output-----\nFor each test case, output answer modulo 109+7 in a single line. \n\n-----Constraints-----\n- 1 ≤ T ≤ 5\n- 1 ≤ N ≤ 50\n- 0 ≤ Ai ≤ 50\n\n-----Subtasks-----\n- Subtask 1 (20 points) : 1 ≤ N ≤ 8, 0 ≤ Ai ≤ 4\n- Subtask 2 (80 points) : Original constraints\n\n-----Example-----\nInput:\n3\n3\n2 3 1\n2\n2 2\n3\n1 2 3\n\nOutput:\n9\n4\n9\n\n-----Explanation-----\nExample case 1.\nWe'll list the various single steps that you can take (ie. in one single usage of the operation):\n- (2, 3, 1) → (2, 2, 0, 1)\n- (2, 2, 0, 1) → (1, 1, 1, 1)\n- (1, 1, 1, 1) → (1, 1, 0, 0, 1)\n- (1, 1, 0, 0, 1) → (0, 0, 1, 0, 1)\n- (1, 1, 1, 1) → (1, 0, 0, 2)\n- (1, 1, 1, 1) → (0, 0, 2, 1)\n- (2, 3, 1) → (1, 2, 2)\n- (1, 2, 2) → (0, 1, 3)\n\nSo all the arrays you can possibly get are: \n(2, 3, 1), (2, 2, 0, 1), (1, 1, 1, 1), (1, 1, 0, 0, 1), (0, 0, 1, 0, 1), (1, 0, 0, 2), (0, 0, 2, 1), (1, 2, 2), and (0, 1, 3)\nSince there are 9 different arrays that you can reach, the answer is 9.", "starter_code": "", "test_cases": {"inputs": ["3\n3\n2 3 1\n2\n2 2\n3\n1 2 3\n\n"], "outputs": ["9\n4\n9"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "cd8c6255129792300031e4de6788eb7bfbb2d199", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00897", "original_id": null, "source": "apps", "domain": "code", "problem": "The EEE classes are so boring that the students play games rather than paying attention during the lectures. Harsha and Dubey are playing one such game.\n\nThe game involves counting the number of anagramic pairs of a given string (you can read about anagrams from here). Right now Harsha is winning. Write a program to help Dubey count this number quickly and win the game!\n\n-----Input-----\nThe first line has an integer T which is the number of strings. Next T lines each contain a strings. Each string consists of lowercase english alphabets only.\n\n-----Output-----\nFor each string, print the answer in a newline.\n\n-----Constraints-----\n- 1 ≤ T ≤ 1000\n- 1 ≤ length of each string ≤ 100\n\n-----Example-----\nInput:\n3\nrama\nabba\nabcd\nOutput:\n2\n4\n0\n\n-----Explanation-----\nrama has the following substrings:\n\n- r\n- ra\n- ram\n- rama\n- a\n- am\n- ama\n- m\n- ma\n- a\nOut of these, {5,10} and {6,9} are anagramic pairs.\n\nHence the answer is 2.\n\nSimilarly for other strings as well.", "starter_code": "", "test_cases": {"inputs": ["3\nrama\nabba\nabcd"], "outputs": ["2\n4\n0"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "e415076000d2b2dbe59d3c6ccfe3a6328e1d1ff0", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00902", "original_id": null, "source": "apps", "domain": "code", "problem": "Motu and Tomu are very good friends who are always looking for new games to play against each other and ways to win these games. One day, they decided to play a new type of game with the following rules:\n- The game is played on a sequence $A_0, A_1, \\dots, A_{N-1}$.\n- The players alternate turns; Motu plays first, since he's earlier in lexicographical order.\n- Each player has a score. The initial scores of both players are $0$.\n- On his turn, the current player has to pick the element of $A$ with the lowest index, add its value to his score and delete that element from the sequence $A$.\n- At the end of the game (when $A$ is empty), Tomu wins if he has strictly greater score than Motu. Otherwise, Motu wins the game.\nIn other words, Motu starts by selecting $A_0$, adding it to his score and then deleting it; then, Tomu selects $A_1$, adds its value to his score and deletes it, and so on.\nMotu and Tomu already chose a sequence $A$ for this game. However, since Tomu plays second, he is given a different advantage: before the game, he is allowed to perform at most $K$ swaps in $A$; afterwards, the two friends are going to play the game on this modified sequence.\nNow, Tomu wants you to determine if it is possible to perform up to $K$ swaps in such a way that he can win this game.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $K$ denoting the number of elements in the sequence and the maximum number of swaps Tomu can perform.\n- The second line contains $N$ space-separated integers $A_0, A_1, \\dots, A_{N-1}$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"YES\" if Tomu can win the game or \"NO\" otherwise (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N \\le 10,000$\n- $0 \\le K \\le 10,000$\n- $1 \\le A_i \\le 10,000$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (20 points): $1 \\le N \\le 100$\nSubtask #2 (80 points): original constraints\n\n-----Example Input-----\n2\n6 0\n1 1 1 1 1 1\n5 1\n2 4 6 3 4\n\n-----Example Output-----\nNO\nYES\n\n-----Explanation-----\nExample case 1: At the end of the game, both Motu and Tomu will have scores $1+1+1 = 3$. Tomu is unable to win that game, so the output is \"NO\".\nExample case 2: If no swaps were performed, Motu's score would be $2+6+4 = 12$ and Tomu's score would be $4+3 = 7$. However, Tomu can swap the elements $A_2 = 6$ and $A_3 = 3$, which makes Motu's score at the end of the game equal to $2+3+4 = 9$ and Tomu's score equal to $4+6 = 10$. Tomu managed to score higher than Motu, so the output is \"YES\".", "starter_code": "", "test_cases": {"inputs": ["2\n6 0\n1 1 1 1 1 1\n5 1\n2 4 6 3 4"], "outputs": ["NO\nYES"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "228c721bf08803a1380ac246e7bdde398d60a7c3", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00907", "original_id": null, "source": "apps", "domain": "code", "problem": "You are given a set of n pens, each of them can be red, blue, green, orange, and violet in color. Count a minimum number of pens that should be taken out from the set so that any two neighboring pens have different colors. Pens are considered to be neighboring if there are no other pens between them.\n\n-----Input:-----\n- \nThe first line contains t denoting the number of test cases.\n- \nThe first line of each test case will contain a single integer n.\n- \nThe second line of each test case will contain a string s.\n(s contains only 'R', 'B', 'G', 'O', and 'V' characters denoting red, blue, green, orange, and violet respectively)\n\n-----Output:-----\nFor each test case, print single line containing one integer - The minimum number of pens that need to be taken out.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq n \\leq 1000$\n\n-----Sample Input:-----\n2\n5\nRBBRG\n5\nRBGOV\n\n-----Sample Output:-----\n1\n0\n\n-----EXPLANATION:-----\nIn first test case, two blue pens are neighboring each other, if we take out any one of them then the string will be RBRG in which each pen has different neighbors.\nIn second test case, no pen needs to be taken out as each pen has different neighbors.", "starter_code": "", "test_cases": {"inputs": ["2\n5\nRBBRG\n5\nRBGOV"], "outputs": ["1\n0"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "c78e1285d1ce6c8ae855668b498656b9e361d760", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00912", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef received a permutation $P_1, P_2, \\ldots, P_N$ and also an integer $D$ from his good friend Grux, because Grux was afraid he would forget them somewhere. However, since Grux was just playing with the permutation, it was all shuffled, and Chef only likes sorted permutations, so he decided to sort it by performing some swaps.\nChef wants to use the integer $D$ he just received, so he is only willing to swap two elements of the permutation whenever their absolute difference is exactly $D$. He has limited time, so you should determine the minimum number of swaps he needs to perform to sort the permutation, or tell him that it is impossible to sort it his way.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $D$.\n- The second line contains $N$ space-separated integers $P_1, P_2, \\ldots, P_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer ― the minimum number of swaps, or $-1$ if it is impossible to sort the permutation.\n\n-----Constraints-----\n- $1 \\le T \\le 20$\n- $1 \\le N \\le 200,000$\n- $1 \\le D \\le N$\n- $1 \\le P_i \\le N$ for each valid $i$\n- $P_1, P_2, \\ldots, P_N$ are pairwise distinct\n- the sum of $N$ over all test cases does not exceed $10^6$\n\n-----Subtasks-----\nSubtask #1 (20 points): $D = 1$\nSubtask #2 (30 points):\n- $N \\le 1,000$\n- the sum of $N$ over all test cases does not exceed $10,000$\nSubtask #3 (50 points): original constraints\n\n-----Example Input-----\n2\n5 2 \n3 4 5 2 1\n5 2 \n4 3 2 1 5 \n\n-----Example Output-----\n3\n-1\n\n-----Explanation-----\nExample case 1: Chef can perform the following swaps in this order:\n- swap the first and fifth element\n- swap the third and fifth element\n- swap the second and fourth element", "starter_code": "", "test_cases": {"inputs": ["2\n5 2\n3 4 5 2 1\n5 2\n4 3 2 1 5"], "outputs": ["3\n-1"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "2920249ccf463003adb3a13ecb7733c034ed4593", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00917", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef wants to organize a contest. Predicting difficulty levels of the problems can be a daunting task. Chef wants his contests to be balanced in terms of difficulty levels of the problems.\nAssume a contest had total P participants. A problem that was solved by at least half of the participants (i.e. P / 2 (integer division)) is said to be cakewalk difficulty. A problem solved by at max P / 10 (integer division) participants is categorized to be a hard difficulty.\nChef wants the contest to be balanced. According to him, a balanced contest must have exactly 1 cakewalk and exactly 2 hard problems. You are given the description of N problems and the number of participants solving those problems. Can you tell whether the contest was balanced or not?\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases.\nThe first line of each test case contains two space separated integers, N, P denoting the number of problems, number of participants respectively.\nThe second line contains N space separated integers, i-th of which denotes number of participants solving the i-th problem.\n\n-----Output-----\nFor each test case, output \"yes\" or \"no\" (without quotes) denoting whether the contest is balanced or not.\n\n-----Constraints-----\n- 1 ≤ T, N ≤ 500 \n- 1 ≤ P ≤ 108 \n- 1 ≤ Number of participants solving a problem ≤ P\n\n-----Subtasks-----\n- Subtask #1 (40 points): P is a multiple of 10\n- Subtask #2 (60 points): Original constraints\n\n-----Example-----\nInput\n6\n3 100\n10 1 100\n3 100\n11 1 100\n3 100\n10 1 10\n3 100\n10 1 50\n4 100\n50 50 50 50\n4 100\n1 1 1 1\n\nOutput\nyes\nno\nno\nyes\nno\nno\n\n-----Explanation-----\nExample case 1.: The problems are of hard, hard and cakewalk difficulty. There is 1 cakewalk and 2 hard problems, so the contest is balanced.\nExample case 2.: The second problem is hard and the third is cakewalk. There is 1 cakewalk and 1 hard problem, so the contest is not balanced.\nExample case 3.: All the three problems are hard. So the contest is not balanced.\nExample case 4.: The problems are of hard, hard, cakewalk difficulty. The contest is balanced.\nExample case 5.: All the problems are cakewalk. The contest is not balanced.\nExample case 6.: All the problems are hard. The contest is not balanced.", "starter_code": "", "test_cases": {"inputs": ["6\n3 100\n10 1 100\n3 100\n11 1 100\n3 100\n10 1 10\n3 100\n10 1 50\n4 100\n50 50 50 50\n4 100\n1 1 1 1"], "outputs": ["yes\nno\nno\nyes\nno\nno"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "f40b10271747b6c4ab955dbb75ea9800ecd32e7e", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00922", "original_id": null, "source": "apps", "domain": "code", "problem": "You have been appointed as the designer for your school's computer network.\nIn total, there are N computers in the class, and M computer-to-computer connections need to be made. Also, there are three mandatory conditions the design should fulfill.\nThe first requirement is that any computer in the network should be able to communicate with any other computer through the connections, possibly, through some other computers.\nNetwork attacks are possible, so the second requirement is that even if any one computer from the network gets disabled so that the rest of the computers are unable to communicate with it, the rest of the computers can still communicate with each other. In other words, the first requirement still holds for any subset of (N-1) computers.\nThe third requirement is that there shouldn't be any irrelevant connections in the network. We will call a connection irrelevant if and only if after its' removal, the above two requirements are still held.\nGiven N, M, please build a network with N computers and M connections, or state that it is impossible.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe first and only line of each test case contains a pair of space-separated integers N and M denoting the number of computers and the number of connections.\n\n-----Output-----\nOutput T blocks.\nIf it is impossible to construct a network with the given parameters for the corresponding test case, output just -1 -1. Otherwise, output M lines, each of which contains a space-separated pairs of integers denoting the IDs of the computers that should be connected. Note that multiple connections between any pair of computers and connections connecting a computer to itself are implicitly not allowed due to the third requirement.\n\n-----Constraints-----\n\n- 1 ≤ T ≤ 1000\n- 1 ≤ M ≤ N * (N - 1) / 2\n- 1 ≤ Sum of all N ≤ 1000\n- Subtask 1 (21 point): 1 ≤ N ≤ 4\n- Subtask 2 (79 points): 1 ≤ N ≤ 100\n\n-----Example-----\nInput:2\n10 1\n5 5\n\nOutput:-1 -1\n1 2\n2 3\n3 4\n4 5\n5 1\n\n-----Explanation-----\nExample case 1. There are not enough connections even to satisfy the first requirement.\nExample case 2. The obtained network satisfies all the requirements.", "starter_code": "", "test_cases": {"inputs": ["2\n10 1\n5 5"], "outputs": ["-1 -1\n1 2\n2 3\n3 4\n4 5\n5 1"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "24b26645d201ada174fab16c10275e322fcba9b7", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00927", "original_id": null, "source": "apps", "domain": "code", "problem": "There is a universal library, where there is a big waiting room with seating capacity for maximum $m$ people, each of whom completes reading $n$ books sequentially. Reading each book requires one unit of time. \nUnfortunately, reading service is provided sequentially. After all of the $m$ people enter the library, the entrance gate is closed. There is only one reading table. So when someone reads, others have to wait in the waiting room. \nAt first everybody chooses $n$ books they want to read. It takes $x$ amount of time. People can choose books simultaneously. Then they enter the waiting room. After reading $n$ books the person leaves the library immediately. \nAs nothing is free, the cost of reading is also not free. If a person stays in the library $t$ units of time then the cost of reading is $\\left \\lfloor \\frac{t-n}{m} \\right \\rfloor$ units of money. So, the $i^{th}$ person pays for time $x$ he needs to choose books and the time $(i-1)*n$ he needs to wait for all the persons before him to complete reading.\nNote: $\\left \\lfloor a \\right \\rfloor$ denotes the floor($a$).\n\n-----Input-----\n- Each case contains three space-separated positive integers $n$, $m$ and $x$ where $n, x \\leq 1000$ and $m \\leq 10^{15}$. \n- End of input is determined by three zeros. \n- There are no more than 1000 test cases.\n\n-----Output-----\n- For each case, output in a single line the total unit of money the library gets in that day.\n\n-----Sample Input-----\n1 100 9\n11 2 10\n12 2 11\n0 0 0\n\n-----Sample Output-----\n9\n15\n16\n\n-----Explanation:-----\nTestcase 2: Here, $n=11$, $m=2$, $x=10$.\nFor 1st person, \n$t=21$ and he/she gives $\\left \\lfloor \\frac{21-11}{2} \\right \\rfloor = 5$ units of money.\nFor 2nd person,\n$t=32$ and he/she gives $\\left \\lfloor \\frac{32-11}{2} \\right \\rfloor= 10$ units of money.\nSo, total units of money $= 5+10 = 15$", "starter_code": "", "test_cases": {"inputs": ["1 100 9\n11 2 10\n12 2 11\n0 0 0"], "outputs": ["9\n15\n16"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "d46bfd04513b660d02b515150f97dcf20543d96d", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00932", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef hates unoptimized codes and people who write such codes. One fine day he decided to look through the kitchen's codebase and found a function whose pseudo-code is given here:\n\ninput: integer N, list X[1, 2, ..., N], list Y[1, 2, ..., N]\n\noutput: integer res\n\nfunction:\n\nset res = 0;\nfor i := 1 to N do\nfor j := 1 to N do\nfor k := 1 to N do\nif (X[i] = X[j]) OR (X[j] = X[k]) OR (X[k] = X[i])\ncontinue\nelse\nset res = max(res, Y[i] + Y[j] + Y[k])\nreturn res\n\nLuckily enough this code gets triggered only if the Head Chef makes a submission. But still there is a possibility that this can crash the judge. So help Chef by writing a new function which does the same thing but is faster.\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains an integer N denoting the number of elements in the two lists.\n- The i-th of the next N lines contains a pair of space-separated integers denoting the values of X[i] and Y[i] respectively.\n\n-----Output-----\nFor each test case, output an integer corresponding to the return value of the function.\n\n-----Constraints-----\n- 1 ≤ T ≤ 10\n- 1 ≤ N ≤ 105\n- 1 ≤ X[i], Y[i] ≤ 108\n\n-----Example-----\nInput\n2\n3\n1 3\n3 1\n1 2\n5\n1 3\n2 4\n1 2\n3 2\n3 4\n\nOutput\n0\n11\n\n-----Explanation-----\nTestcase 2: The maximum is attained when i = 1, j = 2 and k = 5. This leads to res being 3 + 4 + 4 = 11. This value is attained in other iterations as well, but it never exceeds this, and hence this is the answer.", "starter_code": "", "test_cases": {"inputs": ["2\n3\n1 3\n3 1\n1 2\n5\n1 3\n2 4\n1 2\n3 2\n3 4"], "outputs": ["0\n11"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "5077baf902dfea82266ad45049a46c232d65576d", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00937", "original_id": null, "source": "apps", "domain": "code", "problem": "Coach Khaled is a swag teacher in HIT (Hag Institute of Technology). However, he has some obsession problems.\nRecently, coach Khaled was teaching a course in building 8G networks using TV antennas and programming them with assembly. There are $N$ students (numbered $1$ through $N$) in his class; for some reason, this number is always a multiple of $4$. The final exam has finished and Khaled has all the scores of his $N$ students. For each valid $i$, the score of the $i$-th student is $A_i$; each score is an integer between $0$ and $100$. Currently, the score-grade distribution is as follows:\n- grade D for score smaller than $60$\n- grade C for score greater or equal to $60$, but smaller than $75$\n- grade B for score greater or equal to $75$, but smaller than $90$\n- grade A for score greater or equal to $90$\nHowever, coach Khaled is not satisfied with this. He wants exactly $N/4$ students to receive each grade (A, B, C and D), so that the grades are perfectly balanced. The scores cannot be changed, but the boundaries between grades can. Therefore, he wants to choose three integers $x$, $y$ and $z$ and change the grade distribution to the following (note that initially, $x = 60$, $y = 75$ and $z = 90$):\n- grade D for score smaller than $x$\n- grade C for score greater or equal to $x$, but smaller than $y$\n- grade B for score greater or equal to $y$, but smaller than $z$\n- grade A for score greater or equal to $z$\nYour task is to find thresholds $x$, $y$ and $z$ that result in a perfect balance of grades. If there are multiple solutions, choose the one with the maximum value of $x+y+z$ (because coach Khaled wants seem smarter than his students); it can be proved that there is at most one such solution. Sometimes, there is no way to choose the thresholds and coach Khaled would resign because his exam questions were low-quality.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, if there is no solution, print a single line containing the integer $-1$; otherwise, print a single line containing three space-separated integers $x$, $y$ and $z$.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $4 \\le N \\le 100$\n- $N$ is divisible by $4$\n- $0 \\le A_i \\le 100$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $5,000$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n6\n4\n90 25 60 75\n8\n27 29 92 92 67 67 85 92\n4\n0 1 2 3\n4\n100 100 100 100\n4\n30 30 40 50\n4\n30 40 40 50\n\n-----Example Output-----\n60 75 90\n-1\n1 2 3\n-1\n-1\n-1\n\n-----Explanation-----\nExample case 1: The default distribution is the correct one.\nExample case 4: All students have the same score and grade, so there is no way to choose the thresholds and coach Khaled must resign.", "starter_code": "", "test_cases": {"inputs": ["6\n4\n90 25 60 75\n8\n27 29 92 92 67 67 85 92\n4\n0 1 2 3\n4\n100 100 100 100\n4\n30 30 40 50\n4\n30 40 40 50"], "outputs": ["60 75 90\n-1\n1 2 3\n-1\n-1\n-1"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "d0c7cf4a6a55fe6d741b8c189154f2c58d252265", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00942", "original_id": null, "source": "apps", "domain": "code", "problem": "Write a program to obtain a number $(N)$ from the user and display whether the number is a one digit number, 2 digit number, 3 digit number or more than 3 digit number\n\n-----Input:-----\n- First line will contain the number $N$,\n\n-----Output:-----\nPrint \"1\" if N is a 1 digit number.\nPrint \"2\" if N is a 2 digit number.\nPrint \"3\" if N is a 3 digit number.\nPrint \"More than 3 digits\" if N has more than 3 digits.\n\n-----Constraints-----\n- $0 \\leq N \\leq 1000000$\n\n-----Sample Input:-----\n9\n\n-----Sample Output:-----\n1", "starter_code": "", "test_cases": {"inputs": ["9"], "outputs": ["1"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "455aecc2728dfb0449de94ba577c544b2dce3b8c", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00947", "original_id": null, "source": "apps", "domain": "code", "problem": "In Byteland there are N cities, numbered 1 through N. Some pairs of cities are connected by bi-directional roads in such a way that starting from any one city you can visit all other cities either directly or indirectly.\n\nChef is currently at city A and wants to visit all other cities in Byteland. Chef can only move according to following rule. \n\nIf Chef is at city A then he continues to move from city A to city B, city B to city C (provided A is directly connected to B, B is directly connected to C) and so on unless there are no more cities leading from current city.\n\nIf so he jumps back to previous city and repeat the same tour with other cities leading from it which are not visited. Chef repeat this step unless all cities are not visited.\n\nHelp Chef to count number of ways in which he can visit all other cities . As this number can be large print it modulo 109+7\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains a single integer N denoting the number of cities in Byteland.\n- Next N-1 lines contain two space-separated integers u and v denoting there is bi-directional road between city numbered u and v. \n- Next line contains a single integer A denoting the city number where Chef is present.\n\n-----Output-----\n- For each test case, output a single line containing number of ways in which Chef can visit all cities modulo 109+7.\n\n-----Constraints-----\n- 1 ≤ T ≤ 5\n- 1 ≤ N ≤ 105\n- 1 ≤ A ≤ N\n\n-----Subtasks-----\nSubtask #1 : (10 points) \n- 1 ≤ N ≤ 5\nSubtask #2 : (30 points) \n- 1 ≤ N ≤ 100\nSubtask #3 : (60 points) \n- 1 ≤ N ≤ 105\n\n-----Example-----\nInput:\n2\n3\n1 2\n1 3\n1\n5\n1 2\n1 3\n2 4\n2 5\n1\n\nOutput:\n2\n4\n\n-----Explanation-----\nExample case 1. Chef can visit cities in two ways according to the problem: 1-2-3 and 1-3-2\nExample case 1. Chef can visit cities in four ways according to the problem:\n\n1-2-4-5-3\n1-2-5-4-3\n1-3-2-4-5\n1-3-2-5-4", "starter_code": "", "test_cases": {"inputs": ["2\n3\n1 2\n1 3\n1\n5\n1 2\n1 3\n2 4\n2 5\n1"], "outputs": ["2\n4"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "2588a4ba6f79b2d7216907f3d403afedab2dc8a0", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00952", "original_id": null, "source": "apps", "domain": "code", "problem": "The chef has a number N, Cheffina challenges chef to form the largest number X from the digits of N.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, $N$. \n\n-----Output:-----\nFor each test case, output in a single line answer.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq N \\leq 10^6$\n\n-----Sample Input:-----\n2\n2\n212\n\n-----Sample Output:-----\n2\n221", "starter_code": "", "test_cases": {"inputs": ["2\n2\n212"], "outputs": ["2\n221"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "2393efae0e9447bb75d75c4d0d1af429a45d0c22", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00957", "original_id": null, "source": "apps", "domain": "code", "problem": "You are given a string S constisting of uppercase Latin letters. Is it possible to reorder the characters in this string to get a string with prefix \"LTIME\" and suffix \"EMITL\"?\nWe remind you that a prefix of a string is any substring which contains its first character, while a suffix of a string is substring containing its last character.\n\n-----Input-----\nThe first line contains a single integer T, denoting the number of testcases. The descriptions of T test cases follow.\nThe first and only line of the test case description has one non-empty string S consisting of uppercase Latin letters only.\n\n-----Output-----\nFor each testcase output a single line containing the string \"YES\" (without quotes) if it's possible to reorder the characters to get the required prefix and suffix, or \"NO\" (without quotes) otherwise.\n\n-----Constraints-----\n- Subtask 1 (23 points) : 1 ≤ T ≤ 100, 1 ≤ |S| ≤ 9\n- Subtask 2 (77 points) : 1 ≤ T ≤ 1000, 1 ≤ |S| ≤ 100\n\n-----Example-----\nInput:3\nLTIMEAZAZAITLME\nLLLTTTIIIMMMEEEAHA\nLTIMEM\n\nOutput:YES\nYES\nNO\n\n-----Explanation-----\nTest case 1: we can permute the last 5 letters and get LTIMEAZAZAEMITL\nTest case 2: we have 3 copies of each of the letters 'L', 'T', 'I', 'M', 'E' so we can leave 5 of them in the beginning and move 5 of them to the end.\nTest case 3: we have only one letter 'L' so we can't make necessary prefix and suffix at the same time.", "starter_code": "", "test_cases": {"inputs": ["3\nLTIMEAZAZAITLME\nLLLTTTIIIMMMEEEAHA\nLTIMEM"], "outputs": ["YES\nYES\nNO"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "ab0252803ecaa0124c928784e4fc46c4b72faeed", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00962", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef just come up with a very good idea for his business. He needs to hire two group of software engineers. Each group of engineers will work on completely different things and people from different groups don't want to disturb (and even hear) each other. Chef has just rented a whole floor for his purposes in business center \"Cooking Plaza\". The floor is a rectangle with dimensions N over M meters. For simplicity of description the floor's structure, let's imagine that it is split into imaginary squares of size 1x1 called \"cells\".\nThe whole floor is split into rooms (not necessarily rectangular). There are some not noise-resistant walls between some of the cells. Two adjacent cells belong to the same room if they don't have the wall between them. Cells are considered adjacent if and only if they share an edge. Also, we say that relation \"belong to the same room\" is transitive. In other words we say that if cells A and B belong to the same room and B and C belong to the same room then A and C belong to the same room.\nSo we end up having a partition of the floor into rooms. It also means, that each point on the floor belongs to some room.\nChef have to distribute the rooms between engineers of two groups. Engineers from the different groups cannot seat in the same room. If engineers from a different groups seat in adjacent rooms, the walls these rooms share have to be noise-resistant. The cost of having one meter of wall isolated is K per month. Due to various reasons Chef has to pay an additional cost for support of each of the room (e.g. cleaning costs money as well). Interesting to know that support cost for a particular room may differ depending on engineers of which group seat in this room.\nChef doesn't know the number of people he needs in each group of engineers so he wants to minimize the money he needs to pay for all the floor rent and support. He will see how it goes and then redistribute the floor or find another floor to rent or whatever. Either way, you don't need to care about this.\nPlease pay attention to the restriction that all the rooms should be occupied by engineers of one of the teams. Also, it might happen that all the rooms will be assigned to the same team and this is completely okay.\n\n-----Input-----\nThe first line of the input contains three integers N, M, W, K and R, where N and M denote size of the floor, W denote number of one-meter-length walls, K denote cost of having one-meter-length wall be noise-resistant and R denote the number of rooms in which floor is partitioned.\nNext W lines contain four integers each X1, Y1, X2, Y2. This means that cells with coordinates X1, Y1 and X2, Y2 have a wall between them. It's guaranteed that this cells share an edge.\nNext R lines will contain four space separated integers each X, Y, C1, C2. This should be treated as support cost per month in a room that contain cell X, Y is C1 for first group of engineers and C2 for second group of engineers. It's guaranteed that all of cells among these R cells belong to different rooms. All coordinates are indexed starting from 1.\n\n-----Output-----\nOutput a single integer - sum of the rent and support costs per month.\n\n-----Constraints-----\n- 1 ≤ N, M ≤ 1000\n- 1 ≤ W ≤ min(2*N*M, 150000)\n- 1 ≤ X1 ≤ N\n- 1 ≤ Y1 ≤ M\n- 1 ≤ X2 ≤ N\n- 1 ≤ Y2 ≤ M\n- 1 ≤ K ≤ 10000\n- 1 ≤ C1, C2 ≤ 10000\n- Limitations on R is described in subtasks section.\n\n-----Subtasks-----\n- Subtask #1 [30 points]: 1 ≤ R ≤ 50\n- Subtask #2 [70 points]: 1 ≤ R ≤ 500\n\n-----Example-----\nInput:\n2 4 5 5 3\n1 2 1 3\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n1 1 30 12\n1 3 10 15\n2 3 11 22\nOutput:\n48\n\n-----Explanation-----\nHere's the scheme of the floor\nThe correct assignment is the following.\n\n- The blue color denotes assignment to the first team. Total cost for renting two rooms for this team is 11 + 10 = 21.\n- The red color denotes assignment to the second team. Total cost for renting the only room for the team is 12.\n- There are 3 meters of walls between them, resulting in isolating cost of 15.\nThe grand total is 21 + 12 + 15 = 48", "starter_code": "", "test_cases": {"inputs": ["2 4 5 5 3\n1 2 1 3\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n1 1 30 12\n1 3 10 15\n2 3 11 22"], "outputs": ["48"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "a8735c4dc55108284f8043fd275e3f6773f28daf", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00967", "original_id": null, "source": "apps", "domain": "code", "problem": "Snackdown 2019 is coming! There are two rounds (round A and round B) after the qualification round. From both of them, teams can qualify to the pre-elimination round. According to the rules, in each of these two rounds, teams are sorted in descending order by their score and each team with a score greater or equal to the score of the team at the $K=1500$-th place advances to the pre-elimination round (this means it is possible to have more than $K$ qualified teams from each round in the case of one or more ties after the $K$-th place).\nToday, the organizers ask you to count the number of teams which would qualify for the pre-elimination round from round A for a given value of $K$ (possibly different from $1500$). They provided the scores of all teams to you; you should ensure that all teams scoring at least as many points as the $K$-th team qualify.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $K$.\n- The second line contains $N$ space-separated integers $S_1, S_2, \\dots, S_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer — the number of qualified teams.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le K \\le N \\le 10^5$\n- $1 \\le S_i \\le 10^9$ for each valid $i$\n- the sum of $N$ for all test cases does not exceed $10^6$\n\n-----Example Input-----\n2\n5 1\n3 5 2 4 5\n6 4\n6 5 4 3 2 1\n\n-----Example Output-----\n2\n4", "starter_code": "", "test_cases": {"inputs": ["2\n5 1\n3 5 2 4 5\n6 4\n6 5 4 3 2 1"], "outputs": ["2\n4"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "5dac72ece754a094bc8c62dcc8882b6508f7c2cb", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00972", "original_id": null, "source": "apps", "domain": "code", "problem": "Firdavs is living on planet F. There are $N$ cities (numbered $1$ through $N$) on this planet; let's denote the value of city $i$ by $v_i$. Firdavs can travel directly from each city to any other city. When he travels directly from city $x$ to city $y$, he needs to pay $f(x, y) = |v_y-v_x|+y-x$ coins (this number can be negative, in which case he receives $-f(x, y)$ coins).\nLet's define a simple path from city $x$ to city $y$ with length $k \\ge 1$ as a sequence of cities $a_1, a_2, \\ldots, a_k$ such that all cities in this sequence are different, $a_1 = x$ and $a_k = y$. The cost of such a path is $\\sum_{i=1}^{k-1} f(a_i, a_{i+1})$.\nYou need to answer some queries for Firdavs. In each query, you are given two cities $x$ and $y$, and you need to find the minimum cost of a simple path from city $x$ to city $y$. Then, you need to find the length of the longest simple path from $x$ to $y$ with this cost.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $Q$.\n- The second line contains $N$ space-separated integers $v_1, v_2, \\ldots, v_N$.\n- The following $Q$ lines describe queries. Each of these lines contains two space-separated integers $x$ and $y$.\n\n-----Output-----\nFor each query, print a single line containing two space-separated integers ― the minimum cost and the maximum length.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N, Q \\le 2 \\cdot 10^5$\n- $0 \\le v_i \\le 10^9$ for each valid $i$\n- $1 \\le x, y \\le N$\n- the sum of $N$ in all test cases does not exceed $5 \\cdot 10^5$\n- the sum of $Q$ in all test cases does not exceed $5 \\cdot 10^5$\n\n-----Subtasks-----\nSubtask #1 (30 points):\n- $1 \\le N, Q \\le 1,000$\n- $v_1 < v_2 < \\ldots < v_N$\n- the sum of $N$ in all test cases does not exceed $5,000$\n- the sum of $Q$ in all test cases does not exceed $5,000$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n2\n4 2\n4 2 5 7\n2 3\n3 4\n2 1\n1 1\n2 1\n\n-----Example Output-----\n4 3\n3 2\n-1 2\n\n-----Explanation-----\nExample case 1: For the first query, there are two paths with cost $4$ from city $2$ to city $3$:\n- $2 \\rightarrow 1 \\rightarrow 3$: cost $(|4-2|+1-2)+(|5-4|+3-1) = 4$, length $3$\n- $2 \\rightarrow 3$: cost $|5-2|+3-2 = 4$, length $2$\nAll other paths have greater costs, so the minimum cost is $4$. Among these two paths, we want the one with greater length, which is $3$.", "starter_code": "", "test_cases": {"inputs": ["2\n4 2\n4 2 5 7\n2 3\n3 4\n2 1\n1 1\n2 1"], "outputs": ["4 3\n3 2\n-1 2"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "2afda6f59ec872791c98cd4e78b2fd5debec4556", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00977", "original_id": null, "source": "apps", "domain": "code", "problem": "The $String$ Family gave birth to a new $Tripartite$ $trio$ $sisters$ and named them $Hema$, $Rekha$ and $Sushma$. Hema and Rekha are very fond of parties whereas Sushma hates them. One day Hema and Rekha asked their parents to buy them candies to distribute to people in their birthday party. (Remember Hema, Rekha and Sushma were born on the same day). But Sushma was uninterested in the party and only wanted candies for herself.\nYou will be given a list $P$ of possible number of candidates coming to the party. Were $P[i]$ denotes the count of people coming in the i th possibility. In each case every person should get maximum possible equal number of candies such that after distributing the candies, there are always $R$ candies remaining for Sushma. You have to calculate the minimum number of candies required to buy so that, in any possible situation of the given array, each person coming to party gets equal number of candies (at least 1 and maximum possible out of total) and there are always $R$ candies remaining for Sushma.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- First line of each test case contain $N$, number of possible count of people coming to party\n- Next line contain $N$ spaced integers denoting the count of people \n- Next line contain $R$ the number of candies always remaining after maximum equal distribution\n\n-----Output:-----\nFor each testcase, output in a single line answer, the minimum number of candies required to buy.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N \\leq 10^4$\n- $1 \\leq P[i] \\leq 41$\n- $0 \\leq R < min(P[i])$\n\n-----Sample Input:-----\n1\n2\n2 3\n1\n\n-----Sample Output:-----\n7", "starter_code": "", "test_cases": {"inputs": ["1\n2\n2 3\n1"], "outputs": ["7"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "14ac7d79b129f1bc06e7aff732fc7174e434d661", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00982", "original_id": null, "source": "apps", "domain": "code", "problem": "VK gave a problem to Chef, but Chef is too lazy, so he asked you to solve the problem for him. The statement of the problem follows.\nConsider an integer with $N$ digits (in decimal notation, without leading zeroes) $D_1, D_2, D_3, \\dots, D_N$. Here, $D_1$ is the most significant digit and $D_N$ the least significant. The weight of this integer is defined as ∑i=2N(Di−Di−1).∑i=2N(Di−Di−1).\\sum_{i=2}^N (D_i - D_{i-1})\\,.\nYou are given integers $N$ and $W$. Find the number of positive integers with $N$ digits (without leading zeroes) and weight equal to $W$. Compute this number modulo $10^9+7$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $N$ and $W$ denoting the number of digits and the required weight.\n\n-----Output-----\nFor each test case, print a single line containing one integer — the number of $N$-digit positive integers with weight $W$, modulo $10^9+7$.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $2 \\le N \\le 10^{18}$\n- $|W| \\le 300$\n\n-----Subtasks-----\nSubtask #1 (20 points):\n- $1 \\le T \\le 10^3$\n- $2 \\le N \\le 10^3$\nSubtask #2 (80 points): original constraints\n\n-----Example Input-----\n\n1\n2 3\n\n-----Example Output-----\n\n6\n\n-----Explanation-----\nExample case 1: Remember that the digits are arranged from most significant to least significant as $D_1, D_2$. The two-digit integers with weight $3$ are $14, 25, 36, 47, 58, 69$. For example, the weight of $14$ is $D_2-D_1 = 4-1 = 3$. We can see that there are no other possible numbers.", "starter_code": "", "test_cases": {"inputs": ["1\n2 3"], "outputs": ["6"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "ec2fb3b08a871842ffd8b799bfe9d7e8d209b26e", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00987", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef likes to play with array elements. His teacher has given him an array problem. But now he is busy as Christmas is coming. So, he needs your help. Can you help him to solve this problem.\nYou are given an array $(A1,A2,A3……AN)$ of length $N$. You have to create an another array using the given array in the following ways:\n\nFor each valid i, the ith element of the output array will be the sum of the ith element and (A[i])th element if $A[i]$ is less equal $N$.\n\nOther wise for each valid i following the step below\n\ni) Divide the value of $A[i]$ by 2 untill it will be less than$N$.\n\nii) then find the difference ($D$) between $N$ and $A[i]$.\n\niii) the ith element of the output array will be $Dth$ element. \n\n-----Input:-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of T test cases follows. \n- The first line of each test case contains a single integer $N$. \n- The second line contains $N$ space-separated integers $A1,A2,…,AN$. \n\n-----Output:-----\n- For each testcase, print new array in each line.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $1 \\leq N \\leq 10^5$\n- $1\\leq A1,A2.....AN \\leq 10^7$\n\n-----Sample Input:-----\n2\n\n5\n\n2 4 5 7 9\n\n4\n\n5 4 2 3\n\n-----Sample Output:-----\n6 11 14 4 2\n\n4 7 6 5\n\n-----EXPLANATION:-----\nFor 1st test case: A1 = 2+4 =6, A2 = 4+7 =11 , A3 = 5+9 =14 , A4 > N (5) ,So A4/2 = 3 then A4 = A[5 -3] , A4=A[2]=4, And A5 =A[1]=2. Then array becomes 6,11,14,4,2.", "starter_code": "", "test_cases": {"inputs": ["2\n5\n2 4 5 7 9\n4\n5 4 2 3"], "outputs": ["6 11 14 4 2\n4 7 6 5"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "f814d7811eadbdc60b14653e2e44eba560a93503", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00992", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef has $N$ points (numbered $1$ through $N$) in a 2D Cartesian coordinate system. For each valid $i$, the $i$-th point is $(x_i, y_i)$. He also has a fixed integer $c$ and he may perform operations of the following type: choose a point $(x_i, y_i)$ and move it to $(x_i + c, y_i + c)$ or $(x_i - c, y_i - c)$.\nNow, Chef wants to set up one or more checkpoints (points in the same coordinate system) and perform zero or more operations in such a way that after they are performed, each of his (moved) $N$ points is located at one of the checkpoints.\nChef's primary objective is to minimise the number of checkpoints. Among all options with this minimum number of checkpoints, he wants to choose one which minimises the number of operations he needs to perform.\nCan you help Chef find the minimum number of required checkpoints and the minimum number of operations he needs to perform to move all $N$ points to these checkpoints?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $c$.\n- $N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $x_i$ and $y_i$.\n\n-----Output-----\nFor each test case, print a single line containing two integers ― the minimum number of checkpoints and the minimum number of moves.\n\n-----Constraints-----\n- $1 \\le T \\le 5$\n- $1 \\le N \\le 5 \\cdot 10^5$\n- $|x_i|, |y_i| \\le 10^9$ for each valid $i$\n- $0 < c \\le 10^9$\n- the sum of $N$ over all test cases does not exceed $5 \\cdot 10^5$\n\n-----Example Input-----\n1\n3 1\n1 1\n1 0\n3 2\n\n-----Example Output-----\n2 2\n\n-----Explanation-----\nExample case 1: One optimal solution is to set up checkpoints at coordinates $(1, 1)$ and $(1, 0)$. Since the points $(1, 1)$ and $(1, 0)$ are already located at checkpoints, Chef can just move the point $(3, 2)$ to the checkpoint $(1, 0)$ in two moves: $(3, 2) \\rightarrow (2, 1) \\rightarrow (1, 0)$.", "starter_code": "", "test_cases": {"inputs": ["1\n3 1\n1 1\n1 0\n3 2"], "outputs": ["2 2"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "6404aeb1edaa4bc4e86e824a8438c0759dfe2387", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-00997", "original_id": null, "source": "apps", "domain": "code", "problem": "The Jones Trucking Company tracks the location of each of its trucks on a grid similar to an (x, y) plane. The home office is at the location (0, 0). Read the coordinates of truck A and the coordinates of truck B and determine which is closer to the office.\n\n-----Input:-----\nThe first line of the data set for this problem is an integer representing the number of collections of data that follow. Each collection contains 4 integers: the x-coordinate and then the \ny-coordinate of truck A followed by the x-coordinate and then the y-coordinate of truck B.\n\n-----Output:-----\nAll letters are upper case.\nThe output is to be formatted exactly like that for the sample output given below.\n\n-----Assumptions:-----\nThe x-coordinate is in the range –20 .. 20. The y-coordinate is in the range –20 .. 20.\n\n-----Discussion:-----\nThe distance between point #1 with coordinates (x1, y1) and point #2 with coordinates (x2, y2) is:\n\n-----Sample Input:-----\n4\n3 -2 -5 -3\n0 6 1 2\n-7 8 4 -1\n3 3 -2 2\n\n-----Sample Output:-----\nA IS CLOSER\nB IS CLOSER\nB IS CLOSER\nB IS CLOSER", "starter_code": "", "test_cases": {"inputs": ["4\n3 -2 -5 -3\n0 6 1 2\n-7 8 4 -1\n3 3 -2 2"], "outputs": ["A IS CLOSER\nB IS CLOSER\nB IS CLOSER\nB IS CLOSER"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "255a05c31785e30c02e3215d78e09467eb38ae95", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01002", "original_id": null, "source": "apps", "domain": "code", "problem": "A simple string contains a large repetition of letters within it. This problem is related to string handling and manipulation. An original message is sent from planet Earth to planet Cybertron in form of a string. However, the letter position and string size is not important. The number of time each letter has occurred in the string is important. So the original string which is sent to Cybertron is encrypted in the new string which comprises the letters followed by each time it has occurred in the original string. Eg- original message is- abcdabf. Then the encrypted string is- a2b2c1d1f1\n\n-----Input-----\nThe input consists of a single line string without any space or numeric or special characters.\n\n-----Output-----\nIt will consist of in the encrypted string which comprises the letters followed by each time it has occurred in the original string in order.\n\n-----Example-----\nInput:\ninformation\n\nOutput:\ni2n2f1o2r1m1a1t1", "starter_code": "", "test_cases": {"inputs": ["information"], "outputs": ["i2n2f1o2r1m1a1t1"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "ae3d40f3570eff897b5c718c3b1f78865ebf871f", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01007", "original_id": null, "source": "apps", "domain": "code", "problem": "Gru has a string $S$ of length $N$, consisting of only characters $a$ and $b$ for banana and $P$ points to spend.\nNow Gru wants to replace and/or re-arrange characters of this given string to get the lexicographically smallest string possible. For this, he can perform the following two operations any number of times.\n1) Swap any two characters in the string. This operation costs $1$ $point$. (any two, need not be adjacent)\n2) Replace a character in the string with any other lower case english letter. This operation costs $2$ $points$.\nHelp Gru in obtaining the lexicographically smallest string possible, by using at most $P$ points.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains two lines of input, first-line containing two integers $N$ , $P$.\n- The second line contains a string $S$ consisting of $N$ characters.\n\n-----Output:-----\nFor each testcase, output in a single containing the lexicographically smallest string obtained.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^5$\n- $0 \\leq P \\leq 2N$\n- $S$ only consists of $'a'$ and $'b'$\n\n-----Sample Input:-----\n1\n3 3\nbba\n\n-----Sample Output:-----\naab\n\n-----Explanation:-----\nWe swap $S[0]$ and $S[2]$, to get $abb$. With the 2 remaining points, we replace $S[1]$ to obtain $aab$ which is the lexicographically smallest string possible for this case.", "starter_code": "", "test_cases": {"inputs": ["1\n3 3\nbba"], "outputs": ["aab"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "46163451730aeab511af28ceb119933759c25fc7", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01012", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef and Chefina are best friends. Chefina wants to test the Problem Solving skills of chef so she provides Chef 2 integer number $X$ and $Y$\nThe task of chef is to take the two numbers $X$ and $Y$ and return their SUM.\nIdentify whether Chef can solve the problem or not? \n\n-----Input:-----\n- First line will contain the two integers $X$ and $Y$.\n\n-----Output:-----\nFor each testcase, output in a single line the SUM of these two numbers $X$ and $Y$.\n\n-----Constraints-----\n- $1 \\leq X \\leq 100$\n- $1 \\leq Y \\leq 100$\n\n-----Sample Input:-----\n6 70\n\n-----Sample Output:-----\n76", "starter_code": "", "test_cases": {"inputs": ["6 70"], "outputs": ["76"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "2a0ff5b0bfe3e43a7cf5c5f25554915b6c464db4", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01017", "original_id": null, "source": "apps", "domain": "code", "problem": "Chandler has a list of non zero positive integers with him. He made a very interesting observation about the list. He noticed that the number of unique integers in an array of size $N$ is in the range $L$ to $R$ (both inclusive) and every element was either 1 or an even number x, in which case x/2 was also definitely present in the array. \nChandler has misplaced the list of integers but he wants to impress Monica with his problem solving skills by finding out the minimum and maximum possible sum of all elements of the list of integers.\nCan you also help him solve the problem so that he can win over Monica?\n\n-----Input:-----\n- First line will contain $T$, the number of testcases. \n- The first line of each test case contains integers $N$, $L$, and $R$. \n\n-----Output:-----\nFor each test case print 2 space-separated integers, the minimum and the maximum possible sum of N elements based on the above facts.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N \\leq 1000$\n- $1 \\leq L \\leq R \\leq min(N,20)$\n\n-----Sample Input:-----\n2\n\n4 2 2\n\n5 1 5\n\n-----Sample Output:-----\n5 7\n\n5 31\n\n-----EXPLANATION:-----\n- \nExample 1: For an array of size 4, with minimum 2 unique integers and maximum 2 unique integers, the possible arrays are (1,1,1,2), (1,1,2,2), (1,2,2,2)\nOut of these, the minimum possible sum of elements is 5(1+1+1+2) and maximum possible sum is 7(1+2+2+2)\n- \nExample 2: For an array of size 5, with minimum 1 unique integer and maximum 5 unique integers, minimum possible sum of elements is 5(1+1+1+1+1) and maximum possible sum is 31(1+2+4+8+16)", "starter_code": "", "test_cases": {"inputs": ["2\n4 2 2\n5 1 5"], "outputs": ["5 7\n5 31"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "0bcbccb4e88c58bccc5807f41ed104fefa56de21", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01022", "original_id": null, "source": "apps", "domain": "code", "problem": "A sophomore Computer Science student is frustrated with boring college lectures. Professor X agreed to give him some questions; if the student answers all questions correctly, then minimum attendance criteria will not apply to him.\nProfessor X chooses a sequence $A_1, A_2, \\ldots, A_N$ and asks $Q$ queries. In each query, the student is given an integer $P$; he has to construct a sequence $B_1, B_2, \\ldots, B_N$, where $P \\oplus A_i = B_i$ for each valid $i$ ($\\oplus$ denotes bitwise XOR), and then he has to find the number of elements of this sequence which have an even number of $1$-s in the binary representation and the number of elements with an odd number of $1$-s in the binary representation. Help him answer the queries.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $Q$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n- $Q$ lines follow. Each of these lines contains a single integer $P$ describing a query.\n\n-----Output-----\nFor each query, print a single line containing two space-separated integers ― the number of elements with an even number of $1$-s and the number of elements with an odd number of $1$-s in the binary representation.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N, Q \\le 10^5$\n- $ T \\cdot (N+Q) \\leq 4 \\cdot 10^6 $\n- $1 \\le A_i \\le 10^8$ for each valid $i$\n- $1 \\le P \\le 10^5$\nThe input/output is quite large, please use fast reading and writing methods.\n\n-----Subtasks-----\nSubtask #1 (30 points): $N, Q \\le 1,000$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n1\n6 1\n4 2 15 9 8 8\n3\n\n-----Example Output-----\n2 4\n\n-----Explanation-----\nExample case 1: The elements of the sequence $B$ are $P \\oplus 4 = 7$, $P \\oplus 2 = 1$, $P \\oplus 15 = 12$, $P \\oplus 9 = 10$, $P \\oplus 8 = 11$ and $P \\oplus 8 = 11$. The elements which have an even number of $1$-s in the binary representation are $12$ and $10$, while the elements with an odd number of $1$-s are $7$, $1$, $11$ and $11$.", "starter_code": "", "test_cases": {"inputs": ["1\n6 1\n4 2 15 9 8 8\n3"], "outputs": ["2 4"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "65aec6fbd18e5ce9c89fbf2e2859f0f7f6ac3373", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01027", "original_id": null, "source": "apps", "domain": "code", "problem": "You are given a sequence $A_1, A_2, \\ldots, A_N$. You may perform the following operation an arbitrary number of times (including zero): choose two adjacent elements of this sequence, i.e. $A_i$, $A_{i+1}$ for some valid $i$, and swap them. However, for each valid $i$, it is not allowed to choose $A_i$ (the element with the index $i$, regardless of its value at any point in time) more than once in total during this process.\nFind the maximum of the sum $S = \\sum_{i=1}^N A_i \\cdot i$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer ― the maximum possible value of $S$.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le N \\le 10^5$\n- $1 \\le A_i \\le 10^9$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $10^6$\n\n-----Subtasks-----\nSubtask #1 (50 points):\n- $N \\le 20$\n- the sum of $N$ over all test cases does not exceed $200$\nSubtask #2 (50 points): original constraints\n\n-----Example Input-----\n2\n4\n2 1 4 3\n4\n7 6 3 2\n\n-----Example Output-----\n30\n39\n\n-----Explanation-----\nExample case 1: Swap the first and second element of the initial sequence. Then, swap the third and fourth element of the resulting sequence. The final sequence $A$ is $(1, 2, 3, 4)$.\nExample case 2: Swap the second and third element to make the sequence $(7, 3, 6, 2)$.", "starter_code": "", "test_cases": {"inputs": ["2\n4\n2 1 4 3\n4\n7 6 3 2"], "outputs": ["30\n39"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "5bd973dd90edbba3f33a6a60dd5191e9eda5b7f2", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01032", "original_id": null, "source": "apps", "domain": "code", "problem": "Today, puppy Tuzik is going to a new dog cinema. He has already left his home and just realised that he forgot his dog-collar! This is a real problem because the city is filled with catchers looking for stray dogs.\nA city where Tuzik lives in can be considered as an infinite grid, where each cell has exactly four neighbouring cells: those sharing a common side with the cell. Such a property of the city leads to the fact, that the distance between cells (xA, yA) and (xB, yB) equals |xA - xB| + |yA - yB|.\nInitially, the puppy started at the cell with coordinates (0, 0). There are N dog-catchers located at the cells with the coordinates (xi, yi), where 1 ≤ i ≤ N. Tuzik's path can be described as a string S of M characters, each of which belongs to the set {'D', 'U', 'L', 'R'} (corresponding to it moving down, up, left, and right, respectively). To estimate his level of safety, Tuzik wants to know the sum of the distances from each cell on his path to all the dog-catchers. You don't need to output this sum for the staring cell of the path (i.e. the cell with the coordinates (0, 0)).\n\n-----Input-----\nThe first line of the input contains two integers N and M.\nThe following N lines contain two integers xi and yi each, describing coordinates of the dog-catchers.\nThe last line of the input contains string S of M characters on the set {'D', 'U', 'L', 'R'}.\n- 'D' - decrease y by 1\n- 'U' - increase y by 1\n- 'L' - decrease x by 1\n- 'R' - increase x by 1\n\n-----Output-----\nOutput M lines: for each cell of the path (except the starting cell), output the required sum of the distances.\n\n-----Constraints-----\n- 1 ≤ N ≤ 3 ✕ 105\n- 1 ≤ M ≤ 3 ✕ 105\n- -106 ≤ xi, yi ≤ 106\n\n-----Example-----\nInput:\n2 3\n1 2\n0 1\nRDL\n\nOutput:\n4\n6\n6\n\n-----Explanation-----\n\nInitially Tuzik stays at cell (0, 0). Let's consider his path:\n\n- Move 'R' to the cell (1, 0). Distance to the catcher (1, 2) equals 2, distance to the catcher (0, 1) equals 2, so the total distance equals 4\n- Move 'D' to the cell (1, -1). Distance to the catcher (1, 2) equals 3, distance to the catcher (0, 1) equals 3, so the total distance equals 6\n- Move 'L' to the cell (0, -1). Distance to the catcher (1, 2) equals 4, distance to the catcher (0, 1) equals 2, so the total distance equals 6", "starter_code": "", "test_cases": {"inputs": ["2 3\n1 2\n0 1\nRDL"], "outputs": ["4\n6\n6"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "e1d2d3f4ebb1315e92f0bbe87edde88b3111c83f", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01037", "original_id": null, "source": "apps", "domain": "code", "problem": "Bandwidth of a matrix A is defined as the smallest non-negative integer K such that A(i, j) = 0 for |i - j| > K.\nFor example, a matrix with all zeros will have its bandwith equal to zero. Similarly bandwith of diagonal matrix will also be zero.\n\nFor example, for the below given matrix, the bandwith of this matrix is 2.\n\n1 0 0\n0 1 1\n1 1 0 \n\nBandwidth of the below matrix is 1. \n\nBandwidth of the below matrix is 2. \n\nBandwidth of the below matrix is also 2. \n\nYou will be a given a binary matrix A of dimensions N × N. You are allowed to make following operation as many times as you wish (possibly zero or more). In a single operation, you can swap any two entries of the matrix. Your aim is to minimize the bandwidth of the matrix. Find the minimum bandwidth of the matrix A you can get after making as many operations of above type as you want.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follow.\nFirst line of each test case contains an integer N denoting the height/width of the matrix.\nNext N lines of each test case contain N space separated binary integers (either zero or one) corresponding to the entries of the matrix.\n\n-----Output-----\nFor each test case, output a single integer corresponding to the minimum bandwidth that you can obtain.\n\n-----Constraints-----\n- 1 ≤ T ≤ 10\n- 1 ≤ N ≤ 500\n- 0 ≤ A(i, j) ≤ 1\n\n-----Subtasks-----\n- Subtask #1 (40 points) : 1 ≤ N ≤ 100\n- Subtask #2 (60 points) : original constraints\n\n-----Example-----\nInput:\n6\n2\n0 0\n0 0\n2\n1 0\n0 1\n2\n1 0\n1 0\n2\n1 0\n1 1\n3\n1 0 0\n0 1 1\n1 1 0\n4\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n\nOutput:\n0\n0\n0\n1\n1\n3\n\n-----Explanation-----\nExample case 1. The bandwidth of a matrix will all zero entries will be zero. This is the minimum bandwidth you can get, so there is no need of performing any swap operation.\nExample case 2. The bandwidth of a diagonal matrix will also be zero.\nExample case 3. You can make the given matrix a diagonal matrix by swapping A(2, 1) and A(2, 2), which will have zero bandwidth.\nExample case 4. You can not make swaps in any way that can reduce the bandwidth of this matrix. Bandwidth of this matrix is equal to 1, which is the minimum bandwidth that you can get.\nExample case 5. Bandwidth of the given matrix is 2. You can make it equal to be 1 by swapping A(3, 1) and A(3, 3), i.e. the matrix after the operation will look like\n\n1 0 0\n0 1 1\n0 1 1\n\nThe bandwidth of this matrix is 1.\n\nExample case 6. The swap operations won't have any effect on the matrix. Its bandwidth is equal to 3.", "starter_code": "", "test_cases": {"inputs": ["6\n2\n0 0\n0 0\n2\n1 0\n0 1\n2\n1 0\n1 0\n2\n1 0\n1 1\n3\n1 0 0\n0 1 1\n1 1 0\n4\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n\n"], "outputs": ["0\n0\n0\n1\n1\n3"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "6caf86f24481409ce56c0d72816335c9836c2b89", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01042", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef is again playing a game with his best friend Garry. As usual, the rules of this game are extremely strange and uncommon.\nFirst, they are given a stack of $N$ discs. Each disc has a distinct, non-negative integer written on it. The players exchange turns to make a move. Before the start of the game, they both agree upon a set of positive integers $S$ of size $K$. It is guaranteed that S contains the integer $1$. In a move, a player can select any value $x$ from $S$ and pop exactly $x$ elements from the top of the stack. The game ends when there are no discs remaining. Chef goes first.\nScoring: For every disc a player pops, his score increases by $2^p$ where $p$ is the integer written on the disc. For example, if a player pops the discs, with integers $p_1, p_2, p_3, \\dots, p_m$ written on it, during the entire course of the game, then his total score will be $2^{p_1} + 2^{p_2} + 2^{p_3} + \\dots + 2^{p_m}$.\nThe player with higher score wins the game. Determine the winner if both the players play optimally, or if the game ends in a draw.\n\n-----Input:-----\n- First line contains $T$, the number of testcases. Then the testcases follow.\n- The first line of each test case contains two space separated integers $N$ and $K$, denoting the size of the stack and the set S respectively.\n- Next line contains $N$ space separated integers $A_i$ where $A_1$ is the topmost element, denoting the initial arrangement of the stack.\n- The last line of each test case contains $K$ space separated integers each denoting $x_i$.\n\n-----Output:-----\nFor each testcase, output \"Chef\" (without quotes) if Chef wins, \"Garry\" (without quotes) if Garry wins, otherwise \"Draw\" (without quotes) in a separate line.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $1 \\leq N \\leq 10^5$\n- $1 \\leq K \\leq \\min(100, N)$\n- $0 \\leq A_i \\leq 10^9$\n- $1 \\leq x_i \\leq N$\n- $x_i \\neq x_j$ for all $i \\neq j$\n- $A_i \\neq A_j$ for all $i \\neq j$\n- Set $S$ contains integer $1$. \n- Sum of $N$ over all test cases does not exceed $10^5$.\n\n-----Sample Input:-----\n1\n3 2\n5 7 1\n1 2\n\n-----Sample Output:-----\nChef\n\n-----Explanation:-----\nChef can select 2 from the set and draw the top two discs (with integers 5 and 7 written on it) from the stack. Garry cannot select 2 from the set as there is only 1 disc left in the stack. However, he can select 1 from the set and pop the last disc.\nSo, Chef's score = $2^5$ + $2^7$ = $160$\n\nGarry's score = $2^1$ = $2$\n\nChef wins.", "starter_code": "", "test_cases": {"inputs": ["1\n3 2\n5 7 1\n1 2"], "outputs": ["Chef"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "162f5b44c39bf070dfc2b29a171322f32efcba91", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01047", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef has a sequence $A_1, A_2, \\ldots, A_N$; each element of this sequence is either $0$ or $1$. Appy gave him a string $S$ with length $Q$ describing a sequence of queries. There are two types of queries:\n- '!': right-shift the sequence $A$, i.e. replace $A$ by another sequence $B_1, B_2, \\ldots, B_N$ satisfying $B_{i+1} = A_i$ for each valid $i$ and $B_1 = A_N$\n- '?': find the length of the longest contiguous subsequence of $A$ with length $\\le K$ such that each element of this subsequence is equal to $1$\nAnswer all queries of the second type.\n\n-----Input-----\n- The first line of the input contains three space-separated integers $N$, $Q$ and $K$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n- The third line contains a string with length $Q$ describing queries. Each character of this string is either '?', denoting a query of the second type, or '!', denoting a query of the first type.\n\n-----Output-----\nFor each query of the second type, print a single line containing one integer — the length of the longest required subsequence.\n\n-----Constraints-----\n- $1 \\le K \\le N \\le 10^5$\n- $1 \\le Q \\le 3 \\cdot 10^5$\n- $0 \\le A_i \\le 1$ for each valid $i$\n- $S$ contains only characters '?' and '!'\n\n-----Subtasks-----\nSubtask #1 (30 points):\n- $1 \\le N \\le 10^3$\n- $1 \\le Q \\le 3 \\cdot 10^3$\nSubtask #2 (70 points): original constraints \n\n-----Example Input-----\n5 5 3\n1 1 0 1 1\n?!?!? \n\n-----Example Output-----\n2\n3\n3\n\n-----Explanation-----\n- In the first query, there are two longest contiguous subsequences containing only $1$-s: $A_1, A_2$ and $A_4, A_5$. Each has length $2$.\n- After the second query, the sequence $A$ is $[1, 1, 1, 0, 1]$.\n- In the third query, the longest contiguous subsequence containing only $1$-s is $A_1, A_2, A_3$.\n- After the fourth query, $A = [1, 1, 1, 1, 0]$.\n- In the fifth query, the longest contiguous subsequence containing only $1$-s is $A_1, A_2, A_3, A_4$ with length $4$. However, we only want subsequences with lengths $\\le K$. One of the longest such subsequences is $A_2, A_3, A_4$, with length $3$.", "starter_code": "", "test_cases": {"inputs": ["5 5 3\n1 1 0 1 1\n?!?!?"], "outputs": ["2\n3\n3"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "7433a573647bb3949976a62e33047a0deabbb4de", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01052", "original_id": null, "source": "apps", "domain": "code", "problem": "Consider the fraction, $a/b$, where $a$ and $b$ are positive integers. If $a < b$ and $GCD(a,b) = 1$, it is called a reduced proper fraction.\nIf we list the set of a reduced proper fraction for $d \\leq 8$, (where $d$ is the denominator) in ascending order of size, we get:\n$1/8$, $1/7$, $1/6$, $1/5$, $1/4$, $2/7$, $1/3$, $3/8$, $2/5$ , $3/7$, $1/2$, $4/7$, $3/5$, $5/8$, $2/3$, $5/7$, $3/4$, $4/5$, $5/6$, $6/7$, $7/8$\nIt can be seen that $2/5$ is the fraction immediately to the left of $3/7$.\nBy listing the set of reduced proper fractions for $d \\leq N$ in ascending order of value, find the numerator and denominator of the fraction immediately to the left of $a/b$ when $a$ and $b$ are given.\n\n-----Input:-----\n- First line of input contains an integer $T$, number of test cases\n- Next $T$ lines contain $a$ $b$ $N$ separated by space\n\n-----Output:-----\nPrint the numerator and denominator separated by a space corresponding to each test case on a new line\n\n-----Constraints-----\n- $1 \\leq T \\leq 50$\n- $1 \\leq a < b \\leq 10^9$\n- $GCD(a,b) = 1$\n- $b < N \\leq 10^{15}$\n\n-----Subtasks-----\n- 10 points: $1 \\leq N \\leq 100$\n- 30 points : $1 \\leq N \\leq 10^6$\n- 60 points : $1 \\leq N \\leq 10^{15}$\n\n-----Sample Input:-----\n5\n3 7 8\n3 5 8\n4 5 8\n6 7 8\n1 5 8\n\n-----Sample Output:-----\n2 5\n4 7\n3 4\n5 6\n1 6", "starter_code": "", "test_cases": {"inputs": ["5\n3 7 8\n3 5 8\n4 5 8\n6 7 8\n1 5 8"], "outputs": ["2 5\n4 7\n3 4\n5 6\n1 6"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "c2bec56c302d16e222c415ea1cf231e05fc22f93", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01057", "original_id": null, "source": "apps", "domain": "code", "problem": "Ms. E.T. came from planet Hex. She has 8 fingers in each hand which makes her count in hexadecimal way. When she meets you, she tells you that she came from 7E light years from the planet Earth. You see she means that it is 126 light years far away and she is telling you the numbers in hexadecimal. Now, you are in trouble to understand what those numbers really mean. Therefore, you have to convert the hexadecimal numbers to decimals.\n\nInput:\n\nFirst line of code contain T test cases.\n\nevery line of text case contain a Hex-value \n\nOutput:\n\nEvery line of output contain a decimal conversion of given nunmber\n\nSample Input:\n\n3\n\nA\n\n1A23\n\n2C2A\n\nSample Output:\n\n10\n\n6691\n\n11306", "starter_code": "", "test_cases": {"inputs": ["3\nA\n1A23\n2C2A"], "outputs": ["10\n6691\n11306"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "1d0f7623946d68ab9e0f4a367855fd1f2f874011", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01062", "original_id": null, "source": "apps", "domain": "code", "problem": "Abhiram needs to search for an antidote. He comes to know that clue for finding the antidote is carefully hidden by KrishnaMurthy in the form of a puzzle.\n\nThe puzzle consists of a string S and a keywordK. Abhiram needs to find the string of position of anagrams R of the keyword in the string which is the clue. \nThe antidote is found in the box numbered R. Help him find his clue R.\nAnagram: A word or phrase that is made by arranging the letters of another word or phrase in a different order. Eg: 'elvis' and 'lives' are both anagrams of each other.\nNote: Consider, Tac and act are not anagrams(case sensitive).\n\n-----Input:-----\nThe first line contains a string S of length land the second line contains a keyword K.\n\n-----Output:-----\n\nOutput contains a line\"The antidote is found in R.\" Where R= string of positions of anagrams.(the position of the first word in the string is 1).\n\n-----Constraints:-----\n1<=l<=500\n\n1<=k<=50\n\n-----Example:-----\nInput:\ncat is the act of tac\ncat\n\nOutput:\nThe antidote is found in 46.", "starter_code": "", "test_cases": {"inputs": ["cat is the act of tac\ncat"], "outputs": ["The antidote is found in 46."]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "4a177eaff47bf0a95b760a1281862da2d7f5bcb8", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01067", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef's company wants to make ATM PINs for its users, so that they could use the PINs for withdrawing their hard-earned money. One of these users is Reziba, who lives in an area where a lot of robberies take place when people try to withdraw their money. \nChef plans to include a safety feature in the PINs: if someone inputs the reverse of their own PIN in an ATM machine, the Crime Investigation Department (CID) are immediately informed and stop the robbery. However, even though this was implemented by Chef, some people could still continue to get robbed. The reason is that CID is only informed if the reverse of a PIN is different from that PIN (so that there wouldn't be false reports of robberies).\nYou know that a PIN consists of $N$ decimal digits. Find the probability that Reziba could get robbed. Specifically, it can be proven that this probability can be written as a fraction $P/Q$, where $P \\ge 0$ and $Q > 0$ are coprime integers; you should compute $P$ and $Q$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single integer $N$ denoting the length of each PIN. \n\n-----Output-----\nFor each test case, print a single line containing two space-separated integers — the numerator $P$ and denominator $Q$ of the probability.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N \\le 10^5$\n\n-----Subtasks-----\nSubtask #1 (10 points): $N \\le 18$\nSubtask #2 (20 points): $N \\le 36$\nSubtask #3 (70 points): original constraints\n\n-----Example Input-----\n1\n1\n\n-----Example Output-----\n1 1\n\n-----Explanation-----\nExample case 1: A PIN containing only one number would fail to inform the CID, since when it's input in reverse, the ATM detects the same PIN as the correct one. Therefore, Reziba can always get robbed — the probability is $1 = 1/1$.", "starter_code": "", "test_cases": {"inputs": ["1\n1"], "outputs": ["1 1"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "32fd60f7b93fa8f6675fad47d703dd6fe52fba76", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01072", "original_id": null, "source": "apps", "domain": "code", "problem": "$Harshad$ $Mehta$ is planning a new scam with the stocks he is given a stock of integer price S and a number K . $harshad$ has got the power to change the number $S$ at most $K$ times\nIn order to raise the price of stock and now cash it for his benefits\nFind the largest price at which $harshad$ can sell the stock in order to maximize his profit \n\n-----Input:-----\n- First line will contain $S$ and $K$ , the price of the stock and the number K \n\n-----Output:-----\nPrint the largest profit he can make in a single line.\n\n-----Constraints-----\n- S can take value upto 10^18\nNOTE: use 64 int number to fit range\n- K can take value from [0.. 9]\n\n-----Sample Input:-----\n4483 2\n\n-----Sample Output:-----\n9983\n\n-----EXPLANATION:-----\nFirst two digits of the number are changed to get the required number.", "starter_code": "", "test_cases": {"inputs": ["4483 2"], "outputs": ["9983"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "bb1c296304c871cb30dd10d816cf4a194b42a275", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01077", "original_id": null, "source": "apps", "domain": "code", "problem": "Rohit has n empty boxes lying on the ground in a line. The size of the boxes is given in the form of an array $a$. The size of the ith box is denoted by $a[i]$. Since Rohit has a tiny room, there is a shortage of space. Therefore, he has to reduce the number of boxes on the ground by putting a box into another box that is at least twice the size of the current box i.e if we have to put the ith box into the jth box then $( 2*a[i] ) <= a[j]$.\nEach box can contain a maximum of one box and the box which is kept in another box cannot\nhold any box itself.\nFind the minimum number of boxes that will remain on the ground after putting boxes into each other.\n\n-----Input:-----\n- The first line contains a single integer n.\n- The next n lines contain the integer a[i] - the size of the i-th box.\n\n-----Output:-----\nOutput a single integer denoting the minimum number of boxes remaining on the ground.\n\n-----Constraints-----\n- $1 \\leq n \\leq 5*10^5$\n- $1 \\leq a[i] \\leq 10^5$\n\n-----Subtasks-----\n- 30 points : $1 \\leq n \\leq 10^2$\n- 70 points : $1 \\leq n \\leq 5*10^5$\n\n-----Sample Input:-----\n5\n16\n1\n4\n8\n2\n\n-----Sample Output:-----\n3", "starter_code": "", "test_cases": {"inputs": ["5\n16\n1\n4\n8\n2"], "outputs": ["3"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "3f9249fbc4626e40cc4856aa535ebc6dc2f93275", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01082", "original_id": null, "source": "apps", "domain": "code", "problem": "Given a Complete Binary Tree of ‘n’ depth, you can perform 4 types of mirror operation on the tree:-\n\nMirror on the right. The tree is mirrored to the right and rightmost node on every level is connected with the mirrored corresponding node.\n\nMirror on the left. The tree is mirrored to the left and leftmost node on every level is connected with the mirrored corresponding node.\n\nMirror on the top. The tree is mirrored to the top and topmost nodes are connected with corresponding nodes.\n\nMirror on the bottom. The tree is mirrored to the bottom and bottom most nodes are connected with the corresponding nodes.\n\nSee the image for details. \nMirror Right: \n\nMirror Bottom: \n\nYou are given ‘q’ queries, each performing this type of operation or asking for the no of edges in the produced graph.\n\nQueries are of the form “1 x” or “2” where x is 1 for right, 2 for left, 3 for top or 4 for bottom.\n\n1 x: Perform x operation on the result graph.\n\n2: Print the no of edges in the graph. Since it can be very large, print it modulo 1000000007. \n\n-----Input:-----\n- First line will contain $n$, the depth of the initial tree and $q$, the number of queries. \n- Next $q$ lines contain queries of the form \"1 $x$\" or \"2\".\n\n-----Output:-----\nFor each query of type \"2\", output a single line containing the no of edges in the graph modulo 1000000007.\n\n-----Constraints-----\n- $1 \\leq n \\leq 1000$\n- $1 \\leq q \\leq 10^5$\n- $1 \\leq x \\leq 4$\n\n-----Sample Input:-----\n2 3\n1 1\n1 4\n2\n\n-----Sample Output:-----\n38\n\n-----EXPLANATION:-----\nInitial no of edges = 6\n\nAfter the operation 1 1, no of edges = 15\n\nAfter the operation 1 4, no of edges = 38\n\nAt operation 2, we print the no of edges that is 38.", "starter_code": "", "test_cases": {"inputs": ["2 3\n1 1\n1 4\n2"], "outputs": ["38"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "2e0ad3576a28430efaed839de87a7e07db0271a9", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01087", "original_id": null, "source": "apps", "domain": "code", "problem": "Cherry has a binary matrix $A$ consisting of $N$ rows and $M$ columns. The rows are numbered from $1$ to $N$, columns are numbered from $1$ to $M$. Element at row $i$ ($1$ ≤ $i$ ≤ $N$) and column $j$ ($1$ ≤ $j$ ≤ $M$) is denoted as $A_{ij}$. All elements of $A$ are either $0$ or $1$.\nHe performs $Q$ queries on matrix. Each query is provided by four integers $x_{1}$, $y_{1}$, $x_{2}$, $y_{2}$ which define the rectangle, where ($x_{1}$, $y_{1}$) stands for the coordinates of the top left cell of the rectangle, while ($x_{2}$, $y_{2}$) stands for the coordinates of the bottom right cell. You need to flip all the bits i.e. ($0$ to $1$, $1$ to $0$) that are located fully inside the query rectangle.\nFinally, print the matrix after performing all the queries.\nNote: $x_{1}$ represents the row number while $y_{1}$ represents the column number.\n\n-----Input:-----\n- The first line of the input contains two integers $N$ and $M$ — the number of rows and the number of columns in the matrix.\n- Each of the next $N$ lines contains a string of length $M$, where the $j^{th}$ character of $i^{th}$ line denotes the value of $A_{i,j}$. \n- Next line contains an integer $Q$ — the number of queries.\n- Then follow $Q$ lines with queries descriptions. Each of them contains four space-seperated integers $x_{1}$, $y_{1}$, $x_{2}$, $y_{2}$ — coordinates of the up left and bottom right cells of the query rectangle.\n\n-----Output:-----\nPrint the matrix, in the form of $N$ strings, after performing all the queries.\n\n-----Constraints-----\n- $1 \\leq N,M \\leq 1000$\n- $0 \\leq A_{ij} \\leq 1$\n- $1 \\leq Q \\leq 10^6$\n- $1 \\leq x_{1} \\leq x_{2} \\leq N$\n- $1 \\leq y_{1} \\leq y_{2} \\leq M$\n\n-----Sample Input:-----\n2 2\n00\n00\n3\n1 1 1 1\n2 2 2 2\n1 1 2 2 \n\n-----Sample Output:-----\n01\n10\n\n-----Explanation:-----\nExample case 1:\nAfter processing the 1st query 1 1 1 1, matrix becomes:\n[1000][1000]\\begin{bmatrix} 10 \\\\ 00 \\end{bmatrix}\nAfter processing the 2nd query 2 2 2 2, the matrix becomes:\n[1001][1001]\\begin{bmatrix} 10 \\\\ 01 \\end{bmatrix}\nAfter processing the 3rd query 1 1 2 2, matrix becomes:\n[0110][0110]\\begin{bmatrix} 01 \\\\ 10 \\end{bmatrix}\nWe need to output the matrix after processing all queries.", "starter_code": "", "test_cases": {"inputs": ["2 2\n00\n00\n3\n1 1 1 1\n2 2 2 2\n1 1 2 2"], "outputs": ["01\n10"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "e391c93788397c6de3a07e89932b11b2405efe81", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01092", "original_id": null, "source": "apps", "domain": "code", "problem": "Tuzik and Vanya are playing the following game.\nThey have an N × M board and a chip to indicate the current game position. The chip can be placed on any one cell of the game board, each of which is uniquely identified by an ordered pair of positive integers (r, c), where 1 ≤ r ≤ N is the row number and 1 ≤ c ≤ M is the column number.\nInitially, the chip is placed at the cell identified as (1, 1). For his move, a player can move it either 1, 2 or 3 cells up, or 1 or 2 cells to the right. The player who can not move the chip loses. In other words, a player suffers defeat if the chip is placed in the cell (N, M) at the start of his turn.\nTuzik starts the game. You have to determine who will win the game if both players play optimally.\n\n-----Input-----\nThe first line contains an integer T denoting the number of tests. Each of the following T lines contain two integers N and M.\n\n-----Output-----\nFor each test output \"Tuzik\" or \"Vanya\" on a separate line, indicating who will win the game.\n\n-----Constraints-----\n- 1 ≤ T ≤ 100\n- 1 ≤ N, M ≤ 106\n\n-----Example-----\nInput:\n2\n4 4\n2 2\n\nOutput:\nTuzik\nVanya\n\n\n-----Explanation-----Test case 1: On his first turn Tuzik moves chip 3 cells up to the cell (4, 1). On his turn Vanya can move chip only right to the cell (4, 2) or to the cell (4, 3) and after that Tuzik moves it to (4, 4) and finishes the game.\n\nTest case 2: On his first Turn Tuzik can move chip to the cell (2, 1) or (1, 2), but on his next turn Vanya moves it to (2, 2) and wins the game.", "starter_code": "", "test_cases": {"inputs": ["2\n4 4\n2 2"], "outputs": ["Tuzik\nVanya"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "e49896fe9f46a2bc08b4c8aceccd57cf7c08c31a", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01097", "original_id": null, "source": "apps", "domain": "code", "problem": "The chef was busy in solving algebra, he found some interesting results, that there are many numbers which can be formed by sum of some numbers which are prime. Chef wrote those numbers in dairy. Cheffina came and saw what the chef was doing. Cheffina immediately closed chef's dairy and for testing chef's memory, she starts asking numbers and chef needs to answer wheater given number N can be formed by the sum of K prime numbers if it yes then print 1 else print 0. \n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, two integers $N, K$.\n\n-----Output:-----\nFor each test case, output in a single line answer as 1 or 0.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $2 \\leq N \\leq 10^5$\n- $1 \\leq K \\leq 10^5$\n\n-----Sample Input:-----\n2\n12 2\n11 2\n\n-----Sample Output:-----\n1\n0", "starter_code": "", "test_cases": {"inputs": ["2\n12 2\n11 2"], "outputs": ["1\n0"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "f8570417672724b8b8094542bdc7c3ef9d560732", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01102", "original_id": null, "source": "apps", "domain": "code", "problem": "Zombies zombies everywhere!! \nIn a parallel world of zombies, there are N zombies. There are infinite number of unused cars, each of same model only differentiated by the their colors. The cars are of K colors.\n\nA zombie parent can give birth to any number of zombie-children (possibly zero), i.e. each zombie will have its parent except the head zombie which was born in the winters by combination of ice and fire.\n\nNow, zombies are having great difficulties to commute to their offices without cars, so they decided to use the cars available. Every zombie will need only one car. Head zombie called a meeting regarding this, in which he will allow each zombie to select a car for him.\n\nOut of all the cars, the head zombie chose one of cars for him. Now, he called his children to choose the cars for them. After that they called their children and so on till each of the zombie had a car. Head zombie knew that it won't be a good idea to allow children to have cars of same color as that of parent, as they might mistakenly use that. So, he enforced this rule during the selection of cars.\n\nProfessor James Moriarty is a criminal mastermind and has trapped Watson again in the zombie world. Sherlock somehow manages to go there and met the head zombie. Head zombie told Sherlock that they will let Watson free if and only if Sherlock manages to tell him the maximum number of ways in which the cars can be selected by N Zombies among all possible hierarchies. A hierarchy represents parent-child relationships among the N zombies. Since the answer may be large, output the answer modulo 109 + 7. Sherlock can not compute big numbers, so he confides you to solve this for him.\n\n-----Input-----\nThe first line consists of a single integer T, the number of test-cases.\n\nEach test case consists of two space-separated integers N and K, denoting number of zombies and the possible number of colors of the cars respectively.\n\n-----Output-----\nFor each test-case, output a single line denoting the answer of the problem.\n\n-----Constraints-----\n- 1 ≤ T ≤ 100\n- 1 ≤ N ≤ 10^9\n- 1 ≤ K ≤ 10^9\n\n-----Subtasks-----\nSubtask #1 : (10 points)\n- 1 ≤ T ≤ 20\n- 1 ≤ N, K ≤ 10\n\nSubtask 2 : (20 points) \n\n- 1 ≤ T ≤ 10\n- 1 ≤ N, K ≤ 10000\n\nSubtask 3 : (70 points) \n\n- 1 ≤ T ≤ 100\n- 1 ≤ N, K ≤ 10^9\n\n-----Example-----\nInput\n2\n2 2\n3 3\nOutput:\n2\n12\n\n-----Explanation\nIn the first sample test case, there are 2 zombies. Let us name them Z1 and Z2. Let one hierarchy be one in which Z1 is parent of Z2. There are 2 colors, suppose red and blue. If Z1 takes red, then Z2 should take a blue. If Z1 takes blue, then Z2 should take red. \nNote that one other possible hierarchy could be one in which Z2 is a parent of Z1. In that hierarchy also, number of possible ways of assigning cars is 2.\nSo there maximum number of possible ways is 2.\n\nIn the second example, we have 3 Zombies say Z1, Z2, Z3 and cars of 3 colors, suppose red, blue and green.\nA hierarchy to maximize the number of possibilities is Z1 is the parent of Z2, Z2 is the parent of Z3.\nZombie Z1 can choose one of red, blue or green cars. Z2 can choose one of the remaining two colors (as its car's color can not be same as its parent car.). Z3 can also choose his car in two colors, (one of them could be color same as Z1, and other being the color which is not same as cars of both Z1 and Z2.). This way, there can be 12 different ways of selecting the cars.\n\n-----\nIn the first sample test case, there are 2 zombies. Let us name them Z1 and Z2. Let one hierarchy be one in which Z1 is parent of Z2. There are 2 colors, suppose red and blue. If Z1 takes red, then Z2 should take a blue. If Z1 takes blue, then Z2 should take red. \n\nNote that one other possible hierarchy could be one in which Z2 is a parent of Z1. In that hierarchy also, number of possible ways of assigning cars is 2.\n\nSo there maximum number of possible ways is 2.\n\nIn the second example, we have 3 Zombies say Z1, Z2, Z3 and cars of 3 colors, suppose red, blue and green.\n\nA hierarchy to maximize the number of possibilities is Z1 is the parent of Z2, Z2 is the parent of Z3.\n\nZombie Z1 can choose one of red, blue or green cars. Z2 can choose one of the remaining two colors (as its car's color can not be same as its parent car.). Z3 can also choose his car in two colors, (one of them could be color same as Z1, and other being the color which is not same as cars of both Z1 and Z2.). This way, there can be 12 different ways of selecting the cars.", "starter_code": "", "test_cases": {"inputs": ["2\n2 2\n3 3"], "outputs": ["2\n12"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "6604bf710b1ad5d5e2b516ba4c35df846faad33d", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01107", "original_id": null, "source": "apps", "domain": "code", "problem": "As you know America’s Presidential Elections are about to take place and the most popular leader of the Republican party Donald Trump is famous for throwing allegations against anyone he meets.\n\nHe goes to a rally and meets n people which he wants to offend. For each person i he can choose an integer between 1 to max[i].\n\nHe wants to decide in how many ways he can offend all these persons (N) given the condition that all numbers chosen by him for each person are distinct.\nSo he needs your help to find out the number of ways in which he can do that. If no solution is possible print 0\n\n-----Input-----\nThe first line of the input contains an integer T (1<=T<=100) denoting the number of test cases. The description of T test cases follows.\n\nThe first line of each test case contains a single integer N denoting the number of people Trump wants to offend. The second line contains N space-separated integers maxnumber[0], maxnumber[1], ..., maxnumber[n-1] denoting the maxnumber that trump can choose for each person. \n\n-----Output-----\nFor each test case, output a single line containing the number of ways Trump can assign numbers to the people, modulo 1,000,000,007. If it's impossible to assign distinct integers to the people, print 0\n\n-----Constraints-----\n- 1 ≤ T ≤ 100\n- 1 ≤ N ≤ 50\n- 1 ≤ Maxnumber[i] ≤ 3000\n\n-----Example-----\nInput:\n3\n1\n4\n2\n10 5\n4\n2 3 1 3\n\nOutput:\n4\n45\n0\n\n\n-----Explanation-----\nIn case 1, He can choose any number from 1 to 4\n\nIn case 2,Out of the total 50 combination he can not take (1,1) ,(2,2) , (3,3) ,(4,4) or (5,5).", "starter_code": "", "test_cases": {"inputs": ["3\n1\n4\n2\n10 5\n4\n2 3 1 3"], "outputs": ["4\n45\n0"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "1abad242125824463bc85e6574b8d31e9dc9184a", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01112", "original_id": null, "source": "apps", "domain": "code", "problem": "Prime numbers are arranged in a ordered list U$U$, in increasing order. Let S$S$ be a sublist of U$U$ with a unique property that for every element A$A$ belonging to list S$S$, if i$i$ denotes the index of A$A$ in list U$U$, than i$i$ also belongs to list U$U$.\nGiven N$N$, find sum of first N$N$ elements of list S$S$, assuming 1-based indexing.\nAs the sum can be very large, print the sum modulo 109+7$10^{9}+7$.\n\n-----Input:-----\n-The first line of the input contains a single integer T$T$ denoting the number of test cases.\n-Only line of each test case has an integer N$N$ .\n\n-----Output:-----\nFor each test case, print a single integer denoting the sum of first N$N$ elements of set S$S$ modulo 109+7$10^{9}+7$.\n\n-----Constraints-----\n- 1≤T≤10000$1 \\leq T \\leq 10000$\n- 1≤N≤1000$1 \\leq N \\leq 1000$\n\n-----Subtasks-----\n- \n20 points : \n- \n1≤T≤10000$1 \\leq T \\leq 10000$\n- \n1≤N≤10$1 \\leq N \\leq 10$\n- \n20 points :\n- \n1≤T≤100$1 \\leq T \\leq 100$\n- \n1≤N≤100$1 \\leq N \\leq 100$\n- \n60 points : Original Constraints\n\n-----Sample Input:-----\n2\n\n1\n2\n\n-----Sample Output:-----\n3\n8\n\n-----EXPLANATION:-----\nExample case 1: \nFirst few elements of set S$S$ are {3,5,11…} , so sum is 3.\nExample case 2: \nSum is 3+5=8.", "starter_code": "", "test_cases": {"inputs": ["2\n1\n2"], "outputs": ["3\n8"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "7bbcb536840ab681b2db491898f55d08142d71a4", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01117", "original_id": null, "source": "apps", "domain": "code", "problem": "The Quark Codejam's number QC(n, m) represents the number of ways to partition a set of n things into m nonempty subsets. For example, there are seven ways to split a four-element set into two parts:\n\n{1, 2, 3} ∪ {4}, {1, 2, 4} ∪ {3}, {1, 3, 4} ∪ {2}, {2, 3, 4} ∪ {1},\n\n{1, 2} ∪ {3, 4}, {1, 3} ∪ {2, 4}, {1, 4} ∪ {2, 3}.\n\nWe can compute QC(n, m) using the recurrence,\n\nQC(n, m) = mQC(n − 1, m) + QC(n − 1, m − 1), for integers 1 < m < n.\n\nbut your task is a somewhat different: given integers n and m, compute the parity of QC(n, m), i.e. QC(n, m) mod 2.\n\nExample : \n\nQC(4, 2) mod 2 = 1. \nWrite a program that reads two positive integers n and m, computes QC(n, m) mod 2, and writes the\n\nresult.\n\n-----Input-----\nThe input begins with a single positive integer on a line by itself indicating the number of the cases. This line is followed by the input cases.\n\nThe input consists two integers n and m separated by a space, with 1 ≤ m ≤ n ≤ 1000000000.\n\n-----Output-----\nFor each test case, print the output.\n\nThe output should be the integer S(n, m) mod 2.\nSample Input\n1\n\n4 2\nSample Output\n1", "starter_code": "", "test_cases": {"inputs": ["1\n4 2"], "outputs": ["1"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "10e910b36e244e5a05f6ec54e8486a0e4a30006c", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01122", "original_id": null, "source": "apps", "domain": "code", "problem": "\"I don't have any fancy quotes.\" - vijju123\nChef was reading some quotes by great people. Now, he is interested in classifying all the fancy quotes he knows. He thinks that all fancy quotes which contain the word \"not\" are Real Fancy; quotes that do not contain it are regularly fancy.\nYou are given some quotes. For each quote, you need to tell Chef if it is Real Fancy or just regularly fancy.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single string $S$ denoting a quote.\n\n-----Output-----\nFor each test case, print a single line containing the string \"Real Fancy\" or \"regularly fancy\" (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 50$\n- $1 \\le |S| \\le 100$\n- each character of $S$ is either a lowercase English letter or a space\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n2\ni do not have any fancy quotes\nwhen nothing goes right go left\n\n-----Example Output-----\nReal Fancy\nregularly fancy\n\n-----Explanation-----\nExample case 1: \"i do not have any fancy quotes\"\nExample case 2: The word \"not\" does not appear in the given quote.", "starter_code": "", "test_cases": {"inputs": ["2\ni do not have any fancy quotes\nwhen nothing goes right go left"], "outputs": ["Real Fancy\nregularly fancy"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "255cc7706c45e5b000eb84897b1fef13a7dfb3d4", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01127", "original_id": null, "source": "apps", "domain": "code", "problem": "Chef usually likes to play cricket, but now, he is bored of playing it too much, so he is trying new games with strings. Chef's friend Dustin gave him binary strings $S$ and $R$, each with length $N$, and told him to make them identical. However, unlike Dustin, Chef does not have any superpower and Dustin lets Chef perform only operations of one type: choose any pair of integers $(i, j)$ such that $1 \\le i, j \\le N$ and swap the $i$-th and $j$-th character of $S$. He may perform any number of operations (including zero).\nFor Chef, this is much harder than cricket and he is asking for your help. Tell him whether it is possible to change the string $S$ to the target string $R$ only using operations of the given type.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains a binary string $S$.\n- The third line contains a binary string $R$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"YES\" if it is possible to change $S$ to $R$ or \"NO\" if it is impossible (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 400$\n- $1 \\le N \\le 100$\n- $|S| = |R| = N$\n- $S$ and $R$ will consist of only '1' and '0'\n\n-----Example Input-----\n2\n5\n11000\n01001\n3\n110\n001\n\n-----Example Output-----\nYES\nNO\n\n-----Explanation-----\nExample case 1: Chef can perform one operation with $(i, j) = (1, 5)$. Then, $S$ will be \"01001\", which is equal to $R$.\nExample case 2: There is no sequence of operations which would make $S$ equal to $R$.", "starter_code": "", "test_cases": {"inputs": ["2\n5\n11000\n01001\n3\n110\n001"], "outputs": ["YES\nNO"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "117e4fc86e9d992b9c8a293b1623b6a171b3e99a", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01132", "original_id": null, "source": "apps", "domain": "code", "problem": "\"I'm a fan of anything that tries to replace actual human contact.\" - Sheldon.\nAfter years of hard work, Sheldon was finally able to develop a formula which would diminish the real human contact. \nHe found k$k$ integers n1,n2...nk$n_1,n_2...n_k$ . Also he found that if he could minimize the value of m$m$ such that ∑ki=1$\\sum_{i=1}^k$n$n$i$i$C$C$m$m$i$i$ is even, where m$m$ = ∑ki=1$\\sum_{i=1}^k$mi$m_i$, he would finish the real human contact. \nSince Sheldon is busy choosing between PS-4 and XBOX-ONE, he want you to help him to calculate the minimum value of m$m$. \n\n-----Input:-----\n- The first line of the input contains a single integer T$T$ denoting the number of test cases. The \ndescription of T$T$ test cases follows.\n- The first line of each test case contains a single integer k$k$.\n- Next line contains k space separated integers n1,n2...nk$n_1,n_2...n_k$ .\n\n-----Output:-----\nFor each test case output the minimum value of m for which ∑ki=1$\\sum_{i=1}^k$n$n$i$i$C$C$m$m$i$i$ is even, where m$m$=m1$m_1$+m2$m_2$+. . . mk$m_k$ and 0$0$ <= mi$m_i$<= ni$n_i$ . If no such answer exists print -1.\n\n-----Constraints-----\n- 1≤T≤1000$1 \\leq T \\leq 1000$\n- 1≤k≤1000$1 \\leq k \\leq 1000$\n- 1≤ni≤10$1 \\leq n_i \\leq 10$18$18$\n\n-----Sample Input:-----\n1\n1\n5\n\n-----Sample Output:-----\n2\n\n-----EXPLANATION:-----\n5$5$C$C$2$2$ = 10 which is even and m is minimum.", "starter_code": "", "test_cases": {"inputs": ["1\n1\n5"], "outputs": ["2"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "bc14adb7488aa34654144ae4639e174735326232", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01137", "original_id": null, "source": "apps", "domain": "code", "problem": "Dhote and Shweta went on a tour by plane for the first time.Dhote was surprised by the conveyor belt at the airport.As Shweta was getting bored Dhote had an idea of playing a game with her.He asked Shweta to count the number of bags whose individual weight is greater than or equal to the half of the total number of bags on the conveyor belt.Shweta got stuck in the puzzle! Help Shweta. \n\n-----Input:-----\n- First line will contain T$T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, one integers N$N$.\n- next line conatins N$N$ integers that represents weight of bag \n\n-----Output:-----\nFor each testcase, print required answer in new line .\n\n-----Constraints-----\n- 1≤T≤1000$1 \\leq T \\leq 1000$\n- 1≤N≤105$1 \\leq N \\leq 10^5$\n- 1≤weightofbag≤105$ 1\\leq weight of bag \\leq 10^5$ \n\n-----Sample Input:-----\n1\n4 \n1 2 3 4\n\n-----Sample Output:-----\n3", "starter_code": "", "test_cases": {"inputs": ["1\n4\n1 2 3 4"], "outputs": ["3"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "bdfd6a4ca4b311ecdfbfe84ac43392526916f167", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01142", "original_id": null, "source": "apps", "domain": "code", "problem": "You like tracking airplane flights a lot. Specifically, you maintain history of an airplane’s flight at several instants and record them in your notebook. Today, you have recorded N such records h1, h2, ..., hN, denoting the heights of some airplane at several instants. These records mean that airplane was first flying on height h1, then started changing its height to h2, then from h2 to h3 and so on. The airplanes are usually on cruise control while descending or ascending, so \nyou can assume that plane will smoothly increase/decrease its height from hi to hi + 1 with a constant speed. You can see that during this period, the airplane will cover all possible heights in the range [min(hi, hi+1), max(hi, hi+1)] (both inclusive). It is easy to see that the plane will be at all possible heights in the range exactly a single instant of time during this ascend/descend.\n\nYou are interested in finding the maximum integer K such that the plane was at some height exactly K times during the flight.\n\n-----Input-----\nThere is a single test case.\nFirst line of the input contains an integer N denoting the number of records of heights of the plane.\nSecond line contains N space separated integers denoting h1, h2, ..., hN.\n\n-----Output-----\nOutput a single maximum integer K in one line, such that the plane was at some height exactly K times during the flight.\n\n-----Constraints-----\n- hi ≠ hi+1\n\n-----Subtasks-----\nSubtask #1: (30 points)\n- 1 ≤ N ≤ 1000\n- 1 ≤ hi ≤ 1000\n\nSubtask #2: (70 points)\n- 1 ≤ N ≤ 105\n- 1 ≤ hi ≤ 109\n\n-----Example-----\nInput:\n5\n1 2 3 2 3\n\nOutput:\n3\n\n-----Explanation-----\n\nThe flight can be draw as:\n\n3 /\\/\n2 /\n1\n\nThere are infinitely many heights at which the plane was 3 times during the flight, for example 2.5, 2.1. Notice that the plane was only 2 times at height 2. Moreover, there are no height at which the plane was more than 3 times, so the answer is 3.", "starter_code": "", "test_cases": {"inputs": ["5\n1 2 3 2 3"], "outputs": ["3"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "90c6c5662922a0e00f2bf153f08e62b66f77fa46", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01147", "original_id": null, "source": "apps", "domain": "code", "problem": "Kajaria has an empty bag and 2 types of tiles - \ntiles of type $1$ have the number $X$ written and those of type $2$ have the number $Y$ written on them. He has an infinite supply of both type of tiles.\nIn one move, Kajaria adds exactly $1$ tile to the bag. He adds a tile of type $1$ with probability $p$ and a tile of type $2$ with probability $(1 - p)$.\nIf $2$ tiles in the bag have the same number written on them (say $Z$), they are merged into a single tile of twice that number ($2Z$).\nFind the expected number of moves to reach the first tile with number $S$ written on it.\nNotes on merging: \n- Consider that the bag contains tiles $(5, 10, 20, 40)$ and if the new tile added is $5$, then it would merge with the existing $5$ and the bag would now contain $(10, 10, 20, 40)$. The tiles $10$ (already present) and $10$ (newly formed) would then merge in the same move to form $(20, 20, 40)$, and that will form $(40, 40)$, which will form $(80)$.\nKajaria guarantees that:\n- $X$ and $Y$ are not divisible by each other.\n- A tile with number $S$ can be formed.\n\n-----Input-----\n- First line contains a single integer $T$ - the total no. of testcases\n- Each testcase is described by $2$ lines:\n- $X, Y, S$ - $3$ space-separated natural numbers\n- $u, v$ - $2$ space-separated natural numbers describing the probability $p$\nThe value of $p$ is provided as a fraction in its lowest form $u/v$ ($u$ and $v$ are co-prime)\n\n-----Output-----\n- For each testcase, if the expected number of moves can be expressed as a fraction $p/q$ in its lowest form, print $(p * q^{-1})$ modulo $10^9 + 7$, where $q^{-1}$ denotes the modular inverse of $q$ wrt $10^9 + 7$.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $2 \\leq X, Y \\leq 5 * 10^{17}$\n- $1 \\leq S \\leq 10^{18}$\n- $1 \\leq u < v \\leq 10^{9}$\n\n-----Sample Input-----\n1\n5 3 96\n1 3\n\n-----Sample Output-----\n48", "starter_code": "", "test_cases": {"inputs": ["1\n5 3 96\n1 3"], "outputs": ["48"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "80910ab4d35177b3e8f0a5bcc9ee7d749c135c62", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01152", "original_id": null, "source": "apps", "domain": "code", "problem": "Write a program that reads numbers until -1 is not given.\nThe program finds how many of the given numbers are more than 30, $N$.\nIt also finds the average weighted sum of even numbers, $A$.\nThe weight of the $i$th number is defined as the position of the number (1 based indexing) times the number. To find the average weighted sum, you need to add all these weights for the even numbers, then divide the sum by the sum of the positions of the numbers.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains some numbers, terminated by -1\n\n-----Output:-----\nFor each testcase, output in a single line the count of numbers that are greater than 30, $N$, and the average weighted sum of the even numbers, $A$, separated by a space. Make sure to set the precision of the average weighted sum to 2 places after the decimal point.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $2 \\leq N \\leq 1000$\n\n-----Sample Input:-----\n1\n33 100 77 42 12 -1\n\n-----Sample Output:-----\n4 38.91\n\n-----EXPLANATION:-----\nIn the series of numbers 33 100 77 42 12 -1, the count of numbers greater than 30 is 4\nThe average weighted sum of the even numbers is given by:\n((2 * 100) + (4 * 42) + (5 * 12)) / (2 + 4 + 5)", "starter_code": "", "test_cases": {"inputs": ["1\n33 100 77 42 12 -1"], "outputs": ["4 38.91"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "4af9828556cebc9b53cbf6cd08183e115f5f558d", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01157", "original_id": null, "source": "apps", "domain": "code", "problem": "After fixing the mercury leak, Kim has arrived in the planning room, where he finds a square map of a field, with $N$ rows and $N$ columns. Each cell in the field is either empty, or has a lookout tower on it. Using his notes, he immediately realises that this field is where the JSA will build their new base!\nKim knows that Soum is a fan of symmetric base design, and will only approve of a base to be built if it is square. Furthermore, Soum also requires that all the rows in the base, and all the columns in the base have exactly one tower square in them. \nThis means that a base plan is valid if and only if:\n- It is square in shape\n- Every row in the base has exactly one lookout tower in it.\n- Every column in the base has exactly one lookout tower in it.\nKim notices that all the rows and all the columns in the field have exactly one tower square in them, but he knows that some of them could have been built to throw him off! Can you help Kim find how many valid base plans are possible in this field? Two base plans are considered different if one contains a cell in the grid that the other does not.\nPlease refer to the samples for more details.\n\n-----Input:-----\n- The first line of input contains $T$, the number of testcases.\n- The first line of each testcase contains a single integer, $N$, representing the side length of the field.\n- The next $N$ lines of each testcase contain a string of length $N$, consisting of only 0 and 1. If position $j$ in string $i$ is 0, it means that this the field has no tower at $[i][j]$, and if it is 1, then this cell does have a tower at $[i][j]$.\nIt is guaranteed that every row in the input will have exactly one tower, and every column in the input will also have exactly one tower.\n\n-----Output:-----\nFor each testcase, output a single integer $K$, representing the number of different base plans possible.\n\n-----Subtasks-----\n- For all subtasks, $N \\leq 2500$ and $T \\leq 10$. \n- In addition, the sum of $N$ in any testfile is at most $2500$.\nSubtask 1 [28 points] : All the towers will be on the diagonal from the top-left to the bottom-right positions. Formally, all positions where $i = j$ have a tower. And no other position has a tower\nSubtask 2 [39 points] : $N \\leq 600$\nSubtask 3 [33 points] : $N \\leq 2500$\n\n-----Sample Input:-----\n2\n2\n10\n01\n4\n1000\n0010\n0100\n0001\n\n-----Sample Output:-----\n3\n8\n\n-----Explanation:-----\n\nIn the first testcase, there are three valid base plans: The entire 2x2 square, the 1x1 square which contains only the cell (1, 1) and the 1x1 square which contains only the cell (2, 2).\n\nIn the second testcase, \n\nThere are eight valid base plans:\n- The 4x4 square with top left corner at (1, 1)\n- The 3x3 square with top left corner at (1, 1)\n- The 3x3 square with top left corner at (2, 2)\n- The 3x3 square with top left corner at (1, 1)\n- The 2x2 square with top left corner at (2, 2)\n- The 1x1 square which contains only the cell (1, 1)\n- The 1x1 square which contains only the cell (2, 3)\n- The 1x1 square which contains only the cell (3, 2)\n- The 1x1 square which contains only the cell (4, 4)", "starter_code": "", "test_cases": {"inputs": ["2\n2\n10\n01\n4\n1000\n0010\n0100\n0001"], "outputs": ["3\n8"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "af8926b4abec9d5cc56d016ba63cf577fefd6225", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01162", "original_id": null, "source": "apps", "domain": "code", "problem": "There is a girl named ''Akansha''. She is very fond of eating chocolates but she has a weak immune system due to which she gets cold after eating chocolate during morning, evening and night and can only eat at most $x$ number of chocolate each afternoon. A friend of hers gifted her some $n$ number of chocolates that she doesn't want to share with anyone. Those chocolate have to be finished before they expire. (no. of days in which they are going to expire from the day she has been gifted the chocolate is given for each chocolate) $Note:$ Chocolate cannot be consumed on the day it expires.\n\nHelp Akansha to know if it is possible for her to finish all the chocolates before they expire or not.\n\n-----Input:-----\n- First line will contain $T$, number of test cases. Then the test cases follow. \n- First line contains $n$,the number of chocolates gifted to her\n- Second line contains $x$,the number of chocolates she can eat each afternoon\n- Third line contains $n$ space separated integers $A1,A2...An$,denoting the expiry of each of the $n$ chocolates\n\n-----Output:-----\nFor each testcase, print $Possible$, if she can complete all the chocolates gifted to her. Otherwise, print $Impossible$, if she can not finish all the chocolates.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq n \\leq 1500$\n- $1 \\leq x \\leq 1500$\n- $1 \\leq Ai \\leq 1500$\n\n-----Subtasks-----\n- 100 points : $Original Constraints$\n\n-----Sample Input:-----\n3\n\n3\n\n5\n\n4 1 2\n\n5\n\n2\n\n4 4 3 2 2\n\n5\n\n1\n\n4 2 3 1 1 \n\n-----Sample Output:-----\nImpossible\n\nPossible\n\nImpossible \n\n-----EXPLANATION:-----\n- \nExample case 1\n\n1st and 3rd chocolate on the 1st afternoon as she can consume at most 5. one chocolate will be wasted.\n$Note:$ she cannot eat the 2nd chocolate because chocolates cannot be consumed on the day of expiry.\n- \nExample case 2\n\n4th and 5th chocolate on 1st afternoon, 3rd and 1st chocolate on 2nd afternoon. And 2nd chocolate on the 3rd afternoon.\nIt will take a total of 3 days to finish the chocolate.\n- \nExample case 3\n\nShe cannot eat 4th and 5th chocolate as they will expire on the very 1st day, she can eat 2nd chocolate on 1st afternoon, then 3rd chocolate on 2nd afternoon, then 1st chocolate on 3rd afternoon, and 2 chocolates 4th and 5th will expire.", "starter_code": "", "test_cases": {"inputs": ["3\n3\n5\n4 1 2\n5\n2\n4 4 3 2 2\n5\n1\n4 2 3 1 1"], "outputs": ["Impossible\nPossible\nImpossible"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "82d6a0b364f53724fc2c681ddc52e82b567655e9", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01167", "original_id": null, "source": "apps", "domain": "code", "problem": "Complete the solution so that it strips all text that follows any of a set of comment markers passed in. Any whitespace at the end of the line should also be stripped out. \n\n**Example:**\n\nGiven an input string of:\n```\napples, pears # and bananas\ngrapes\nbananas !apples\n```\n\nThe output expected would be:\n```\napples, pears\ngrapes\nbananas\n```\n\nThe code would be called like so:\n\n```python\nresult = solution(\"apples, pears # and bananas\\ngrapes\\nbananas !apples\", [\"#\", \"!\"])\n# result should == \"apples, pears\\ngrapes\\nbananas\"\n\n```", "starter_code": "\ndef solution(string,markers):\n\t", "test_cases": {"inputs": [["apples, pears # and bananas\ngrapes\nbananas !apples", ["#", "!"]], ["a #b\nc\nd $e f g", ["#", "$"]], ["apples, pears # and bananas\ngrapes\nbananas !#apples", ["#", "!"]], ["apples, pears # and bananas\ngrapes\nbananas #!apples", ["#", "!"]], ["apples, pears # and bananas\ngrapes\navocado @apples", ["@", "!"]], ["apples, pears § and bananas\ngrapes\navocado *apples", ["*", "§"]], ["", ["#", "!"]], ["#", ["#", "!"]], ["\n§", ["#", "§"]], ["apples, pears # and bananas\ngrapes\nbananas !apples", []]], "outputs": [["apples, pears\ngrapes\nbananas"], ["a\nc\nd"], ["apples, pears\ngrapes\nbananas"], ["apples, pears\ngrapes\nbananas"], ["apples, pears # and bananas\ngrapes\navocado"], ["apples, pears\ngrapes\navocado"], [""], [""], ["\n"], ["apples, pears # and bananas\ngrapes\nbananas !apples"]], "fn_name": "solution"}, "test_case_format": "function_call", "n_test_cases_total": 10, "n_test_cases_kept": 10, "test_cases_truncated": false, "problem_sha1": "0f3c1b4d46cd00096d0f0c001d8263baa2c32bea", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "solution"} {"seed_id": "apps-01172", "original_id": null, "source": "apps", "domain": "code", "problem": "My little sister came back home from school with the following task:\ngiven a squared sheet of paper she has to cut it in pieces\nwhich, when assembled, give squares the sides of which form\nan increasing sequence of numbers.\nAt the beginning it was lot of fun but little by little we were tired of seeing the pile of torn paper.\nSo we decided to write a program that could help us and protects trees.\n\n## Task\n\nGiven a positive integral number n, return a **strictly increasing** sequence (list/array/string depending on the language) of numbers, so that the sum of the squares is equal to n².\n\nIf there are multiple solutions (and there will be), return as far as possible the result with the largest possible values:\n\n## Examples\n\n`decompose(11)` must return `[1,2,4,10]`. Note that there are actually two ways to decompose 11²,\n11² = 121 = 1 + 4 + 16 + 100 = 1² + 2² + 4² + 10² but don't return `[2,6,9]`, since 9 is smaller than 10.\n\nFor `decompose(50)` don't return `[1, 1, 4, 9, 49]` but `[1, 3, 5, 8, 49]` since `[1, 1, 4, 9, 49]`\ndoesn't form a strictly increasing sequence.\n\n## Note\nNeither `[n]` nor `[1,1,1,…,1]` are valid solutions. If no valid solution exists, return `nil`, `null`, `Nothing`, `None` (depending on the language) or `\"[]\"` (C) ,`{}` (C++), `[]` (Swift, Go).\n\nThe function \"decompose\" will take a positive integer n \nand return the decomposition of N = n² as:\n\n- [x1 ... xk]\nor\n- \"x1 ... xk\"\nor\n- Just [x1 ... xk]\nor\n- Some [x1 ... xk]\nor\n- {x1 ... xk}\nor\n- \"[x1,x2, ... ,xk]\"\n\ndepending on the language (see \"Sample tests\")\n\n# Note for Bash\n```\ndecompose 50 returns \"1,3,5,8,49\"\ndecompose 4 returns \"Nothing\"\n```\n# Hint\n\nVery often `xk` will be `n-1`.", "starter_code": "\ndef decompose(n):\n\t", "test_cases": {"inputs": [[12], [6], [50], [44], [625], [5], [7100], [123456], [1234567], [7654321], [4], [7654322]], "outputs": [[[1, 2, 3, 7, 9]], [null], [[1, 3, 5, 8, 49]], [[2, 3, 5, 7, 43]], [[2, 5, 8, 34, 624]], [[3, 4]], [[2, 3, 5, 119, 7099]], [[1, 2, 7, 29, 496, 123455]], [[2, 8, 32, 1571, 1234566]], [[6, 10, 69, 3912, 7654320]], [null], [[1, 4, 11, 69, 3912, 7654321]]], "fn_name": "decompose"}, "test_case_format": "function_call", "n_test_cases_total": 12, "n_test_cases_kept": 12, "test_cases_truncated": false, "problem_sha1": "9ca0a556d8895a96670651113bf28b83a52e76f3", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "decompose"} {"seed_id": "apps-01177", "original_id": null, "source": "apps", "domain": "code", "problem": "# Task\n Sorting is one of the most basic computational devices used in Computer Science. \n \n Given a sequence (length ≤ 1000) of 3 different key values (7, 8, 9), your task is to find the minimum number of exchange operations necessary to make the sequence sorted. \n\n One operation is the switching of 2 key values in the sequence.\n\n# Example\n\n For `sequence = [7, 7, 8, 8, 9, 9]`, the result should be `0`.\n \n It's already a sorted sequence.\n\n For `sequence = [9, 7, 8, 8, 9, 7]`, the result should be `1`.\n \n We can switching `sequence[0]` and `sequence[5]`.\n \n For `sequence = [8, 8, 7, 9, 9, 9, 8, 9, 7]`, the result should be `4`.\n \n We can:\n```\n [8, 8, 7, 9, 9, 9, 8, 9, 7] \n switching sequence[0] and sequence[3]\n --> [9, 8, 7, 8, 9, 9, 8, 9, 7]\n switching sequence[0] and sequence[8]\n --> [7, 8, 7, 8, 9, 9, 8, 9, 9]\n switching sequence[1] and sequence[2]\n --> [7, 7, 8, 8, 9, 9, 8, 9, 9]\n switching sequence[5] and sequence[7]\n --> [7, 7, 8, 8, 8, 9, 9, 9, 9] \n```\nSo `4` is the minimum number of operations for the sequence to become sorted.\n\n# Input/Output\n\n\n - `[input]` integer array `sequence`\n\n The Sequence.\n\n\n - `[output]` an integer\n\n the minimum number of operations.", "starter_code": "\ndef exchange_sort(sequence):\n\t", "test_cases": {"inputs": [[[7, 7, 8, 8, 9, 9]], [[9, 7, 8, 8, 9, 7]], [[8, 8, 7, 9, 9, 9, 8, 9, 7]], [[9, 9, 9, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7]], [[9, 9, 9, 7, 7, 8, 9, 7, 8, 9, 7, 9]], [[9, 9, 7, 7, 8, 8]], [[9, 7, 9]], [[8, 7, 8]], [[7, 8, 7, 8]], [[8, 8, 7, 8]], [[8, 8, 7, 7, 8]]], "outputs": [[0], [1], [4], [6], [4], [4], [1], [1], [1], [1], [2]], "fn_name": "exchange_sort"}, "test_case_format": "function_call", "n_test_cases_total": 11, "n_test_cases_kept": 11, "test_cases_truncated": false, "problem_sha1": "6547c882d9a7c83b71686e984234f908f520d12f", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "exchange_sort"} {"seed_id": "apps-01182", "original_id": null, "source": "apps", "domain": "code", "problem": "# Task\n You are given a string `s`. Every letter in `s` appears once. \n \n Consider all strings formed by rearranging the letters in `s`. After ordering these strings in dictionary order, return the middle term. (If the sequence has a even length `n`, define its middle term to be the `(n/2)`th term.)\n\n# Example\n\n For `s = \"abc\"`, the result should be `\"bac\"`.\n```\nThe permutations in order are:\n\"abc\", \"acb\", \"bac\", \"bca\", \"cab\", \"cba\"\nSo, The middle term is \"bac\".```\n\n# Input/Output\n\n\n - `[input]` string `s`\n\n unique letters (`2 <= length <= 26`)\n\n - `[output]` a string\n\n middle permutation.", "starter_code": "\ndef middle_permutation(string):\n\t", "test_cases": {"inputs": [["abc"], ["abcd"], ["abcdx"], ["abcdxg"], ["abcdxgz"]], "outputs": [["bac"], ["bdca"], ["cbxda"], ["cxgdba"], ["dczxgba"]], "fn_name": "middle_permutation"}, "test_case_format": "function_call", "n_test_cases_total": 5, "n_test_cases_kept": 5, "test_cases_truncated": false, "problem_sha1": "0252e2f1b888f628562c10ae1a536bf135e824bb", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "middle_permutation"} {"seed_id": "apps-01187", "original_id": null, "source": "apps", "domain": "code", "problem": "# The Kata\nYour task is to transform an input nested list into an hypercube list, which is a special kind of nested list where each level must have the very same size,\nThis Kata is an exercise on recursion and algorithms. You will need to visualize many aspects of this question to be able to solve it efficiently, as such there is a section on definitions of the terms that will be used in the Kata, make sure to fully understand them before attempting. A naive brute-force-ish answer will most likely fail the tests. There will be tests on nested lists of dimension and size up to 10. Good luck.\n\n\n# Definitions\n### Nested List\nA nested list is a list that may contain either non-list items or more nested lists as items in the list. Here are a few examples of nested lists.\n\n [[2, 3], 4, 5, 6, [2, [2, 3, 4, 5], 2, 1, 2], [[[[1]]]], []]\n [[[]]]\n [1, 2]\n [[], []]\n [4, 5, 6, 7, [], 2]\n []\n\n\n- A *basic element* refers to any non-list element of a nested list.\n\n\n- A nested list's *dimension* is defined as the deepest the list goes. \n\n\n- A nested list's *size* is defined as the longest the list or any of its sublists go. \n\nFor example, the *dimension* and *size* of the above nested lists is as follows.\n\n [[2, 3], 4, 5, 6, [2, [2, 3, 4, 5], 2, 1, 2], [[[[1]]]], []] # dimension: 5, size: 7\n [[[]]] # dimension: 3, size: 1\n [1, 2] # dimension: 1, size: 2\n [[], []] # dimension: 2, size: 2\n [4, 5, 6, 7, [], 2] # dimension: 2, size: 6\n [] # dimension: 1, size: 0\n\n\n### Hypercube List\n- A `1`-dimensional **hypercube list** of size `n` is a nested list of dimension `1` and size `n`. \n\n\n- A `d`-dimensional hypercube list of size `n` is a nested list of dimension `d` and size `n` such that the nested list has `n` elements each of which is a `d - 1`-dimensional hypercube list of size `n`. \n\n\nHere are some examples of hypercube lists.\n\n [1] # dimension: 1, size: 1\n [[1, 2], [3, 4]] # dimension: 2, size: 2\n [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # dimension: 2, size: 3\n [[0]] # dimension: 2, size: 1\n [[[0, 0], [1, 1]], [[2, 2], [3, 3]]] # dimension: 3, size: 2\n [1, 2, 3, 4] # dimension: 1, size: 4\n [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]] # dimension: 2, size: 4\n\n\n# The Task\nYour task is to implement `normalize` which converts any given `nested_list` to be in hypercube format with the same dimension and size as the given nested list, extending and growing with the given `growing_value`. The default growing value is the integer `0`.\n\n### The Algorithm\nIn most scenarios you will encounter a nested list that does not have the same size throughout. When working on such a list the algorithm should behave as follows.\n\n * If a hypercube list of dimension 1 needs extra elements, append the required number of growing value elements.\n * If a hypercube list of dimension greater than 1 has a direct basic element as a child, replace it with the required hypercube list with its basic elements all being the replaced item.\n * If a hypercube list of dimension greater than 1 needs extra elements, append the required hypercube list with its basic elements all being the growing value.\n\n\nTake note of the given example, it will be very helpful in understanding the intricacies of the algorithm.\n\n >>> normalize(\n [\n [\n [2, 3, 4],\n [1, 2],\n 2,\n [1]\n ],\n [\n 2,\n [2, 3],\n 1,\n 4,\n [2, 2, 6, 7]\n ],\n 5\n ]\n )\n \nGives the following result.\n\n [\n [\n [2, 3, 4, 0, 0],\n [1, 2, 0, 0, 0],\n [2, 2, 2, 2, 2],\n [1, 0, 0, 0, 0],\n [0, 0, 0, 0, 0]\n ],\n [\n [2, 2, 2, 2, 2],\n [2, 3, 0, 0, 0],\n [1, 1, 1, 1, 1],\n [4, 4, 4, 4, 4],\n [2, 2, 6, 7, 0]\n ],\n [\n [5, 5, 5, 5, 5],\n [5, 5, 5, 5, 5],\n [5, 5, 5, 5, 5],\n [5, 5, 5, 5, 5],\n [5, 5, 5, 5, 5]\n ],\n [\n [0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0]\n ],\n [\n [0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0]\n ]\n ]\n\n\nGood luck!", "starter_code": "\ndef normalize(nested_list, growing_value=0):\n\t", "test_cases": {"inputs": [[[]]], "outputs": [[[]]], "fn_name": "normalize"}, "test_case_format": "function_call", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "0f74ac8bafbb71a93514a046f7747c96466a875f", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "normalize"} {"seed_id": "apps-01192", "original_id": null, "source": "apps", "domain": "code", "problem": "Create a function that takes a positive integer and returns the next bigger number that can be formed by rearranging its digits. For example:\n\n```\n12 ==> 21\n513 ==> 531\n2017 ==> 2071\n```\n\nIf the digits can't be rearranged to form a bigger number, return `-1` (or `nil` in Swift):\n\n```\n9 ==> -1\n111 ==> -1\n531 ==> -1\n```", "starter_code": "\ndef next_bigger(n):\n\t", "test_cases": {"inputs": [[12], [513], [2017], [414], [144], [123456789], [1234567890], [9876543210], [9999999999], [59884848459853]], "outputs": [[21], [531], [2071], [441], [414], [123456798], [1234567908], [-1], [-1], [59884848483559]], "fn_name": "next_bigger"}, "test_case_format": "function_call", "n_test_cases_total": 10, "n_test_cases_kept": 10, "test_cases_truncated": false, "problem_sha1": "42732fb99d3e85ba5f3268b30b5f51a95d761c59", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "next_bigger"} {"seed_id": "apps-01197", "original_id": null, "source": "apps", "domain": "code", "problem": "With your birthday coming up soon, your eccentric friend sent you a message to say \"happy birthday\":\n\n hhhappyyyy biirrrrrthddaaaayyyyyyy to youuuu\n hhapppyyyy biirtttthdaaay too youuu\n happy birrrthdayy to youuu\n happpyyyy birrtthdaaay tooooo youu\n\nAt first it looks like a song, but upon closer investigation, you realize that your friend hid the phrase \"happy birthday\" thousands of times inside his message. In fact, it contains it more than 2 million times! To thank him, you'd like to reply with exactly how many times it occurs.\n\nTo count all the occurences, the procedure is as follows: look through the paragraph and find a `'h'`; then find an `'a'` later in the paragraph; then find an `'p'` after that, and so on. Now count the number of ways in which you can choose letters in this way to make the full phrase.\n\nMore precisely, given a text string, you are to determine how many times the search string appears as a sub-sequence of that string.\n\nWrite a function called `countSubsequences` that takes two arguments: `needle`, the string to be search for and `haystack`, the string to search in. In our example, `\"happy birthday\"` is the needle and the birthday message is the haystack. The function should return the number of times `needle` occurs as a sub-sequence of `haystack`. Spaces are also considered part of the needle.\n\nSince the answers can be very large, return only the last 8 digits of the answer in case it exceeds 8 digits. The answers to the test cases will all be shorter than 8 digits.", "starter_code": "\ndef count_subsequences(a, b):\n\t", "test_cases": {"inputs": [["happy birthday", "appyh appy birth day"], ["happy birthday", "hhaappyy bbiirrtthhddaayy"], ["happy birthday", "happy holidays"], ["happy birthday", "happy birthday"], ["happy", "hhhappy"], ["happy birthday", "hhhappyyyy biirrrrrthddaaaayyyyyyy to youuuu"]], "outputs": [[1], [2048], [0], [1], [3], [7680]], "fn_name": "count_subsequences"}, "test_case_format": "function_call", "n_test_cases_total": 6, "n_test_cases_kept": 6, "test_cases_truncated": false, "problem_sha1": "1b31fa818b559249f3e97cc1819affa4829a427a", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "count_subsequences"} {"seed_id": "apps-01202", "original_id": null, "source": "apps", "domain": "code", "problem": "Complete the function/method (depending on the language) to return `true`/`True` when its argument is an array that has the same nesting structures and same corresponding length of nested arrays as the first array.\n\nFor example:\n\n```python\n# should return True\nsame_structure_as([ 1, 1, 1 ], [ 2, 2, 2 ] )\nsame_structure_as([ 1, [ 1, 1 ] ], [ 2, [ 2, 2 ] ] )\n\n# should return False \nsame_structure_as([ 1, [ 1, 1 ] ], [ [ 2, 2 ], 2 ] )\nsame_structure_as([ 1, [ 1, 1 ] ], [ [ 2 ], 2 ] )\n\n# should return True\nsame_structure_as([ [ [ ], [ ] ] ], [ [ [ ], [ ] ] ] )\n\n# should return False\nsame_structure_as([ [ [ ], [ ] ] ], [ [ 1, 1 ] ] )\n```\n\n~~~if:javascript\nFor your convenience, there is already a function 'isArray(o)' declared and defined that returns true if its argument is an array, false otherwise.\n~~~\n\n~~~if:php\nYou may assume that all arrays passed in will be non-associative.\n~~~", "starter_code": "\ndef same_structure_as(a, b):\n\t", "test_cases": {"inputs": [[[1, [1, 1]], [[2, 2], 2]], [[1, [1, 1]], [2, [2]]], [[[[], []]], [[[], []]]], [[[[], []]], [[1, 1]]], [[1, [[[1]]]], [2, [[[2]]]]], [[], 1], [[], {}], [[1, "[", "]"], ["[", "]", 1]]], "outputs": [[false], [false], [true], [false], [true], [false], [false], [true]], "fn_name": "same_structure_as"}, "test_case_format": "function_call", "n_test_cases_total": 8, "n_test_cases_kept": 8, "test_cases_truncated": false, "problem_sha1": "a8c03db08469ea8957664c626c88ff30db65ce25", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true, "fn_name": "same_structure_as"} {"seed_id": "apps-01207", "original_id": null, "source": "apps", "domain": "code", "problem": "Uttu got to know about an interesting two-player mobile game recently and invites his friend Gangwar to try it out with him. Gangwar, however, has been playing this game since it was out 5 years ago and is a Legendary Grandmaster at it. Uttu immediately thought of somehow cheating in this game to beat Gangwar.\nBut the most he could do was choose if he wanted to go \"First\" or if he wanted to go \"Second\" in this alternative turn based game. Help Uttu choose so that he will always win regardless of Gangwar's moves.Description of the game\nYou are playing on a continent name Tamriel. This continent have $N$ towns numbered from $1$ to $N$ where town $1$ is the capital. These towns are connected to each other by $N-1$ roads. Any two towns are connected by some series of roads, i.e., You can go from any town to any other town using these roads.\nEach town $i$ some initial amout of soldiers $S_i$ in it. At every move, a player can choose a town other than the capital $i$ and move some non-zero amount of its current soldiers to a town which is one step closer towards the capital. After the first move, the moves are alternated between the players. The player who cannot make a move loses.Input\n- The first line contains a single integer $N$\n- The second line contains a $N$ space seperated integers denoting $S_1,S_2,\\dots,S_n$\n- The $N-1$ subsequent lines contain two space seperated integers $u$ and $v$, denoting that the town $u$ and town $v$ are connected by a road.Output\n- Print \"First\" or \"Second\" based on what Uttu should choose to win.Constraints\n- $ 2 \\leq N \\leq {2}\\times{10}^{5}$\n- $ 1 \\leq S_i \\leq {10}^{9}$ for each valid $i$\n- $ 1 \\leq u,v \\leq N$Sample Input 1\n2\n10 10\n1 2\nSample Output 1\nFirst\nExplanation 1\nUttu will move the $10$ soldiers at town $2$ to the capital (town $1$). After this Gangwar cannot make a move, so he loses.Sample Input 2\n3\n1 1 1\n1 2\n1 3\nSample Output 2\nSecond\nExplanation 2\nGangwar has options: either move the soldier at town $2$, or move the soldier at town $3$.\nWhatever he choses, Uttu will chose the other town's soldier to move. And then Gangwar loses.", "starter_code": "", "test_cases": {"inputs": ["2\n10 10\n1 2"], "outputs": ["First"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 1, "n_test_cases_kept": 1, "test_cases_truncated": false, "problem_sha1": "c2942928ca96816ff9931d1ca79842ebb20d8084", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01212", "original_id": null, "source": "apps", "domain": "code", "problem": "You are given two binary strings $a$ and $b$ of the same length. You can perform the following two operations on the string $a$:\n\n Swap any two bits at indices $i$ and $j$ respectively ($1 \\le i, j \\le n$), the cost of this operation is $|i - j|$, that is, the absolute difference between $i$ and $j$. Select any arbitrary index $i$ ($1 \\le i \\le n$) and flip (change $0$ to $1$ or $1$ to $0$) the bit at this index. The cost of this operation is $1$. \n\nFind the minimum cost to make the string $a$ equal to $b$. It is not allowed to modify string $b$.\n\n\n-----Input-----\n\nThe first line contains a single integer $n$ ($1 \\le n \\le 10^6$) — the length of the strings $a$ and $b$.\n\nThe second and third lines contain strings $a$ and $b$ respectively.\n\nBoth strings $a$ and $b$ have length $n$ and contain only '0' and '1'.\n\n\n-----Output-----\n\nOutput the minimum cost to make the string $a$ equal to $b$.\n\n\n-----Examples-----\nInput\n3\n100\n001\n\nOutput\n2\n\nInput\n4\n0101\n0011\n\nOutput\n1\n\n\n\n-----Note-----\n\nIn the first example, one of the optimal solutions is to flip index $1$ and index $3$, the string $a$ changes in the following way: \"100\" $\\to$ \"000\" $\\to$ \"001\". The cost is $1 + 1 = 2$.\n\nThe other optimal solution is to swap bits and indices $1$ and $3$, the string $a$ changes then \"100\" $\\to$ \"001\", the cost is also $|1 - 3| = 2$.\n\nIn the second example, the optimal solution is to swap bits at indices $2$ and $3$, the string $a$ changes as \"0101\" $\\to$ \"0011\". The cost is $|2 - 3| = 1$.", "starter_code": "", "test_cases": {"inputs": ["3\n100\n001\n", "4\n0101\n0011\n", "8\n10001001\n01101110\n", "1\n0\n1\n", "6\n110110\n000000\n", "15\n101010101010101\n010101010101010\n", "7\n1110001\n0000000\n", "7\n1110001\n0000001\n", "91\n0010010000110001001011011011111001000110001000100111110010010001100110010111100111011111100\n1101110110000100110000100011010110111101100000011011100111111000110000001101101111100100101\n", "19\n1111010011111010100\n1010000110100110110\n", "2\n10\n01\n", "10\n1010101010\n1010101010\n", "1\n1\n1\n", "2\n10\n00\n", "4\n1000\n0001\n"], "outputs": ["2\n", "1\n", "4\n", "1\n", "4\n", "8\n", "4\n", "3\n", "43\n", "8\n", "1\n", "0\n", "0\n", "1\n", "2\n"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 15, "n_test_cases_kept": 15, "test_cases_truncated": false, "problem_sha1": "7507d12584aaaf0a92158b011b346f109a4cce92", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01217", "original_id": null, "source": "apps", "domain": "code", "problem": "Recently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with $n$ elements. The $i$-th element is $a_i$ ($i$ = $1, 2, \\ldots, n$). He gradually takes the first two leftmost elements from the deque (let's call them $A$ and $B$, respectively), and then does the following: if $A > B$, he writes $A$ to the beginning and writes $B$ to the end of the deque, otherwise, he writes to the beginning $B$, and $A$ writes to the end of the deque. We call this sequence of actions an operation.\n\nFor example, if deque was $[2, 3, 4, 5, 1]$, on the operation he will write $B=3$ to the beginning and $A=2$ to the end, so he will get $[3, 4, 5, 1, 2]$.\n\nThe teacher of the course, seeing Valeriy, who was passionate about his work, approached him and gave him $q$ queries. Each query consists of the singular number $m_j$ $(j = 1, 2, \\ldots, q)$. It is required for each query to answer which two elements he will pull out on the $m_j$-th operation.\n\nNote that the queries are independent and for each query the numbers $A$ and $B$ should be printed in the order in which they will be pulled out of the deque.\n\nDeque is a data structure representing a list of elements where insertion of new elements or deletion of existing elements can be made from both sides.\n\n\n-----Input-----\n\nThe first line contains two integers $n$ and $q$ ($2 \\leq n \\leq 10^5$, $0 \\leq q \\leq 3 \\cdot 10^5$) — the number of elements in the deque and the number of queries. The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$, where $a_i$ $(0 \\leq a_i \\leq 10^9)$ — the deque element in $i$-th position. The next $q$ lines contain one number each, meaning $m_j$ ($1 \\leq m_j \\leq 10^{18}$).\n\n\n-----Output-----\n\nFor each teacher's query, output two numbers $A$ and $B$ — the numbers that Valeriy pulls out of the deque for the $m_j$-th operation.\n\n\n-----Examples-----\nInput\n5 3\n1 2 3 4 5\n1\n2\n10\n\nOutput\n1 2\n2 3\n5 2\n\nInput\n2 0\n0 0\n\nOutput\n\n\n\n-----Note----- Consider all 10 steps for the first test in detail: $[1, 2, 3, 4, 5]$ — on the first operation, $A$ and $B$ are $1$ and $2$, respectively.\n\nSo, $2$ we write to the beginning of the deque, and $1$ — to the end.\n\nWe get the following status of the deque: $[2, 3, 4, 5, 1]$. $[2, 3, 4, 5, 1] \\Rightarrow A = 2, B = 3$. $[3, 4, 5, 1, 2]$ $[4, 5, 1, 2, 3]$ $[5, 1, 2, 3, 4]$ $[5, 2, 3, 4, 1]$ $[5, 3, 4, 1, 2]$ $[5, 4, 1, 2, 3]$ $[5, 1, 2, 3, 4]$ $[5, 2, 3, 4, 1] \\Rightarrow A = 5, B = 2$.", "starter_code": "", "test_cases": {"inputs": ["5 3\n1 2 3 4 5\n1\n2\n10\n", "2 0\n0 0\n", "2 1\n1 2\n1\n", "3 2\n1000000 999999 999998\n98\n999999999999\n", "5 10\n5728 41414 457879 94 1\n1\n100\n10000\n1000000\n100000000\n10000000000\n1000000000000\n100000000000000\n10000000000000000\n1000000000000000000\n", "71 57\n9 26 80 10 65 60 63 1 15 85 71 1 58 27 41 97 42 15 42 56 87 22 10 28 34 90 13 70 71 56 65 21 0 78 47 96 56 77 32 83 28 16 10 41 0 18 78 12 27 58 4 67 21 41 99 20 21 52 74 10 83 45 43 65 2 15 1 63 46 97 72\n81\n21\n81\n81\n5\n9\n41\n76\n81\n92\n95\n94\n78\n93\n47\n30\n92\n3\n45\n81\n42\n88\n17\n3\n39\n9\n95\n19\n95\n1\n79\n21\n15\n57\n31\n21\n61\n53\n93\n56\n55\n91\n62\n16\n41\n65\n65\n1\n31\n12\n27\n61\n61\n81\n29\n56\n61\n", "66 31\n2 35 79 90 61 55 7 13 96 67 58 18 72 46 59 43 45 78 72 86 78 47 47 14 84 43 91 19 25 81 63 94 23 48 50 74 1 4 92 97 84 86 91 1 73 66 77 75 30 57 16 46 17 22 54 4 44 44 95 56 34 16 41 13 29 39\n95\n78\n48\n33\n97\n28\n83\n21\n93\n97\n9\n76\n13\n97\n44\n96\n85\n13\n45\n24\n57\n1\n73\n94\n89\n1\n39\n49\n49\n87\n81\n", "51 15\n14 34 51 71 72 56 100 38 30 60 75 74 90 84 59 97 45 43 18 71 95 1 26 40 73 48 20 10 98 2 17 33 100 60 83 40 50 9 23 77 57 12 77 9 83 99 10 47 32 76 69\n81\n2\n82\n37\n21\n60\n9\n19\n85\n19\n1\n46\n16\n27\n21\n", "49 55\n88 17 40 32 36 60 78 90 64 78 5 77 46 94 48 12 91 65 75 18 81 92 8 19 61 70 46 27 74 10 39 67 87 95 97 35 17 24 56 58 22 17 9 42 74 74 79 48 20\n89\n21\n5\n57\n46\n65\n76\n60\n76\n63\n34\n1\n98\n45\n77\n5\n61\n30\n77\n1\n21\n69\n74\n15\n91\n28\n18\n13\n100\n19\n51\n65\n8\n18\n17\n97\n81\n97\n21\n1\n100\n99\n31\n1\n69\n6\n81\n67\n81\n33\n81\n31\n26\n78\n1\n", "42 58\n70 65 58 27 24 10 88 81 83 30 29 98 42 97 61 59 48 2 69 22 43 48 94 27 92 70 94 87 69 42 72 79 57 23 62 32 39 86 95 16 11 42\n61\n74\n11\n13\n73\n29\n34\n87\n75\n27\n79\n37\n7\n31\n11\n42\n14\n18\n73\n13\n41\n42\n61\n45\n3\n21\n95\n51\n10\n45\n31\n55\n20\n13\n33\n65\n50\n56\n29\n5\n62\n61\n48\n85\n3\n91\n21\n97\n53\n80\n56\n65\n19\n24\n49\n89\n93\n94\n", "51 12\n52 59 4 82 16 80 52 81 0 36 70 25 0 66 24 58 70 34 81 71 53 87 45 12 97 73 72 35 51 55 66 43 8 20 89 48 48 53 32 87 17 13 43 80 70 84 16 87 8 18 25\n59\n31\n89\n77\n9\n78\n81\n29\n8\n41\n17\n59\n", "5 3\n5 1 2 3 4\n1\n316\n2\n", "4 5\n1 2 5 5\n1\n2\n3\n4\n5\n"], "outputs": ["1 2\n2 3\n5 2\n", "", "1 2\n", "1000000 999998\n1000000 999999\n", "5728 41414\n457879 1\n457879 1\n457879 1\n457879 1\n457879 1\n457879 1\n457879 1\n457879 1\n457879 1\n", "99 1\n97 22\n99 1\n99 1\n80 60\n80 85\n97 16\n99 63\n99 1\n99 10\n99 90\n99 34\n99 15\n99 28\n97 12\n97 65\n99 10\n80 10\n97 18\n99 1\n97 10\n99 42\n97 15\n80 10\n97 83\n80 85\n99 90\n97 56\n99 90\n9 26\n99 80\n97 22\n85 97\n99 52\n97 21\n97 22\n99 45\n97 41\n99 28\n99 21\n99 20\n99 22\n99 43\n97 42\n97 16\n99 15\n99 15\n9 26\n97 21\n85 58\n97 70\n99 45\n99 45\n99 1\n97 56\n99 21\n99 45\n", "97 63\n97 46\n97 30\n96 48\n97 23\n96 25\n97 72\n96 47\n97 25\n97 23\n96 67\n97 18\n96 46\n97 23\n97 73\n97 94\n97 78\n96 46\n97 66\n96 84\n97 44\n2 35\n97 90\n97 81\n97 84\n2 35\n96 97\n97 57\n97 57\n97 47\n97 45\n", "100 33\n34 51\n100 100\n100 9\n100 1\n100 75\n100 60\n100 71\n100 40\n100 71\n14 34\n100 10\n100 45\n100 10\n100 1\n", "97 17\n94 92\n88 60\n97 78\n97 79\n97 65\n97 74\n97 46\n97 74\n97 12\n95 97\n88 17\n97 40\n97 74\n97 10\n88 60\n97 90\n94 39\n97 10\n88 17\n94 92\n97 92\n97 46\n94 12\n97 42\n94 74\n94 75\n90 94\n97 36\n94 18\n97 32\n97 65\n90 64\n94 75\n94 65\n97 17\n97 94\n97 17\n94 92\n88 17\n97 36\n97 32\n94 67\n88 17\n97 92\n88 78\n97 94\n97 18\n97 94\n94 95\n97 94\n94 67\n94 46\n97 39\n88 17\n", "98 43\n98 23\n88 98\n98 97\n98 57\n98 42\n98 62\n98 10\n98 62\n98 87\n98 95\n98 86\n88 81\n98 79\n88 98\n98 65\n98 61\n98 69\n98 57\n98 97\n98 42\n98 65\n98 43\n98 24\n70 27\n98 48\n98 97\n98 29\n88 29\n98 24\n98 79\n98 61\n98 43\n98 97\n98 23\n98 92\n98 30\n98 59\n98 42\n70 10\n98 48\n98 43\n98 81\n98 27\n70 27\n98 30\n98 48\n98 59\n98 42\n98 16\n98 59\n98 92\n98 22\n98 92\n98 83\n98 81\n98 88\n98 42\n", "97 36\n97 43\n97 87\n97 35\n82 36\n97 51\n97 43\n97 55\n82 0\n97 13\n82 34\n97 36\n", "5 1\n5 4\n5 2\n", "1 2\n2 5\n5 5\n5 1\n5 2\n"]}, "test_case_format": "stdin_stdout", "n_test_cases_total": 13, "n_test_cases_kept": 13, "test_cases_truncated": false, "problem_sha1": "79bd1cd481a681adecbaf62948055b1344f4150a", "leakage_note": "question_and_tests_only_no_solution_or_reasoning; test_cases are the VERIFIER not an answer", "do_not_use_fields": ["ground_truth_solution", "deepseek_solution", "deepseek_reasoning"], "reference_passed": true} {"seed_id": "apps-01222", "original_id": null, "source": "apps", "domain": "code", "problem": "For the multiset of positive integers $s=\\{s_1,s_2,\\dots,s_k\\}$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $s$ as follow: $\\gcd(s)$ is the maximum positive integer $x$, such that all integers in $s$ are divisible on $x$. $\\textrm{lcm}(s)$ is the minimum positive integer $x$, that divisible on all integers from $s$.\n\nFor example, $\\gcd(\\{8,12\\})=4,\\gcd(\\{12,18,6\\})=6$ and $\\textrm{lcm}(\\{4,6\\})=12$. Note that for any positive integer $x$, $\\gcd(\\{x\\})=\\textrm{lcm}(\\{x\\})=x$.\n\nOrac has a sequence $a$ with length $n$. He come up with the multiset $t=\\{\\textrm{lcm}(\\{a_i,a_j\\})\\ |\\ i