HelioAI's picture
LFM3-1.7B inference modules: experimental release
67ebcef verified
Raw History Blame Contribute Delete
62.3 kB
{"id": "lcb/abc390_b", "task": "lcb", "testtype": "stdin", "difficulty": "easy", "date": "2025-01-25T00:00:00", "func_name": null, "prompt": "You are given a length-N sequence A=(A_1,A_2,\\ldots,A_N) of positive integers.\nDetermine whether A is a geometric progression.\n\nInput\n\nThe input is given from Standard Input in the following format:\nN\r\nA_1 A_2 \\ldots A_N\n\nOutput\n\nIf A is a geometric progression, print Yes; otherwise, print No.\n\nConstraints\n\n\n- 2 \\leq N \\leq 100\n- 1 \\leq A_i \\leq 10^9\n- All input values are integers.\n\nSample Input 1\n\n5\r\n3 6 12 24 48\n\nSample Output 1\n\nYes\r\n\nA=(3,6,12,24,48).\nA is a geometric progression with first term 3, common ratio 2, and five terms.\r\nTherefore, print Yes.\n\nSample Input 2\n\n3\r\n1 2 3\n\nSample Output 2\n\nNo\r\n\nA=(1,2,3).\r\nSince A_1 : A_2 = 1 : 2 \\neq 2 : 3 = A_2 : A_3, A is not a geometric progression.\r\nTherefore, print No.\n\nSample Input 3\n\n2\r\n10 8\n\nSample Output 3\n\nYes\r\n\nA is a geometric progression with first term 10, common ratio 0.8, and two terms.\r\nTherefore, print Yes.\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["5\n3 6 12 24 48", "Yes"], ["3\n1 2 3", "No"], ["2\n10 8", "Yes"]]}
{"id": "lcb/abc397_a", "task": "lcb", "testtype": "stdin", "difficulty": "easy", "date": "2025-03-15T00:00:00", "func_name": null, "prompt": "Takahashi measured his body temperature and found it to be X {}^\\circC.\nBody temperature is classified into the following:\n\n- Higher than or equal to 38.0 {}^\\circC: “High fever”\n- Higher than or equal to 37.5 {}^\\circC and lower than 38.0 {}^\\circC: “Fever”\n- Lower than 37.5 {}^\\circC: “Normal”\n\nWhich classification does Takahashi's body temperature fall into? Present the answer as an integer according to the Output section.\n\nInput\n\nThe input is given from Standard Input in the following format:\nX\n\nOutput\n\nPrint an integer specified below corresponding to Takahashi's body temperature classification.\n\n- High fever: 1\n- Fever: 2\n- Normal: 3\n\nConstraints\n\n\n- 30 \\leq X \\leq 50\n- X is given to one decimal place.\n\nSample Input 1\n\n40.0\n\nSample Output 1\n\n1\r\n\nHis body temperature is 40.0 {}^\\circC, which is classified as a high fever. Thus, print 1.\n\nSample Input 2\n\n37.7\n\nSample Output 2\n\n2\r\n\nHis body temperature is 37.7 {}^\\circC, which is classified as a fever. Thus, print 2.\n\nSample Input 3\n\n36.6\n\nSample Output 3\n\n3\r\n\nHis body temperature is 36.6 {}^\\circC, which is classified as a normal temperature. Thus, print 3.\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["40.0", "1"], ["37.7", "2"], ["36.6", "3"]]}
{"id": "lcb/3705", "task": "lcb", "testtype": "functional", "difficulty": "easy", "date": "2025-03-01T18:30:00", "func_name": "largestInteger", "prompt": "You are given an integer array nums and an integer k.\nAn integer x is almost missing from nums if x appears in exactly one subarray of size k within nums.\nReturn the largest almost missing integer from nums. If no such integer exists, return -1.\nA subarray is a contiguous sequence of elements within an array.\n \nExample 1:\n\nInput: nums = [3,9,2,1,7], k = 3\nOutput: 7\nExplanation:\n\n1 appears in 2 subarrays of size 3: [9, 2, 1] and [2, 1, 7].\n2 appears in 3 subarrays of size 3: [3, 9, 2], [9, 2, 1], [2, 1, 7].\n3 appears in 1 subarray of size 3: [3, 9, 2].\n7 appears in 1 subarray of size 3: [2, 1, 7].\n9 appears in 2 subarrays of size 3: [3, 9, 2], and [9, 2, 1].\n\nWe return 7 since it is the largest integer that appears in exactly one subarray of size k.\n\nExample 2:\n\nInput: nums = [3,9,7,2,1,7], k = 4\nOutput: 3\nExplanation:\n\n1 appears in 2 subarrays of size 4: [9, 7, 2, 1], [7, 2, 1, 7].\n2 appears in 3 subarrays of size 4: [3, 9, 7, 2], [9, 7, 2, 1], [7, 2, 1, 7].\n3 appears in 1 subarray of size 4: [3, 9, 7, 2].\n7 appears in 3 subarrays of size 4: [3, 9, 7, 2], [9, 7, 2, 1], [7, 2, 1, 7].\n9 appears in 2 subarrays of size 4: [3, 9, 7, 2], [9, 7, 2, 1].\n\nWe return 3 since it is the largest and only integer that appears in exactly one subarray of size k.\n\nExample 3:\n\nInput: nums = [0,0], k = 1\nOutput: -1\nExplanation:\nThere is no integer that appears in only one subarray of size 1.\n\n \nConstraints:\n\n1 <= nums.length <= 50\n0 <= nums[i] <= 50\n1 <= k <= nums.length\n\nComplete the following starter code and return the full solution (the class with the method) in a single ```python code block.\n\n```python\nclass Solution:\n def largestInteger(self, nums: List[int], k: int) -> int:\n```", "public": [["[3, 9, 2, 1, 7]\n3", "7"], ["[3, 9, 7, 2, 1, 7]\n4", "3"], ["[0, 0]\n1", "-1"]]}
{"id": "lcb/3799", "task": "lcb", "testtype": "functional", "difficulty": "easy", "date": "2025-03-15T07:30:00", "func_name": "totalNumbers", "prompt": "You are given an array of digits called digits. Your task is to determine the number of distinct three-digit even numbers that can be formed using these digits.\nNote: Each copy of a digit can only be used once per number, and there may not be leading zeros.\n \nExample 1:\n\nInput: digits = [1,2,3,4]\nOutput: 12\nExplanation: The 12 distinct 3-digit even numbers that can be formed are 124, 132, 134, 142, 214, 234, 312, 314, 324, 342, 412, and 432. Note that 222 cannot be formed because there is only 1 copy of the digit 2.\n\nExample 2:\n\nInput: digits = [0,2,2]\nOutput: 2\nExplanation: The only 3-digit even numbers that can be formed are 202 and 220. Note that the digit 2 can be used twice because it appears twice in the array.\n\nExample 3:\n\nInput: digits = [6,6,6]\nOutput: 1\nExplanation: Only 666 can be formed.\n\nExample 4:\n\nInput: digits = [1,3,5]\nOutput: 0\nExplanation: No even 3-digit numbers can be formed.\n\n \nConstraints:\n\n3 <= digits.length <= 10\n0 <= digits[i] <= 9\n\nComplete the following starter code and return the full solution (the class with the method) in a single ```python code block.\n\n```python\nclass Solution:\n def totalNumbers(self, digits: List[int]) -> int:\n```", "public": [["[1, 2, 3, 4]", "12"], ["[0, 2, 2]", "2"], ["[6, 6, 6]", "1"], ["[1, 3, 5]", "0"]]}
{"id": "lcb/abc391_d", "task": "lcb", "testtype": "stdin", "difficulty": "medium", "date": "2025-02-01T00:00:00", "func_name": null, "prompt": "There is a grid with 10^9 rows and W columns. The cell at the x-th column from the left and the y-th row from the bottom is denoted by (x,y).\nThere are N blocks. Each block is a 1 \\times 1 square, and block i-th (1 \\leq i \\leq N) is located at cell (X_i,Y_i) at time 0.\nAt times t=1,2,\\dots,10^{100}, the blocks are moved according to the following rules:\n\n- If the entire bottom row is filled with blocks, then all blocks in the bottom row are removed.\n- For each remaining block, in order from bottom to top, perform the following:\n- If the block is in the bottom row, or if there is a block in the cell immediately below it, do nothing.\n- Otherwise, move the block one cell downward.\n\n\n\nYou are given Q queries. For the j-th query (1 \\leq j \\leq Q), answer whether block A_j exists at time T_j+0.5.\n\nInput\n\nThe input is given from Standard Input in the following format:\nN W\nX_1 Y_1\nX_2 Y_2\n\\vdots\nX_N Y_N\nQ\nT_1 A_1\nT_2 A_2\n\\vdots\nT_Q A_Q\n\nOutput\n\nPrint Q lines. The i-th line should contain Yes if block A_i exists at time T_i+0.5, and No otherwise.\n\nConstraints\n\n\n- 1 \\leq N \\leq 2 \\times 10^5\n- 1 \\leq W \\leq N\n- 1 \\leq X_i \\leq W\n- 1 \\leq Y_i \\leq 10^9\n- (X_i,Y_i) \\neq (X_j,Y_j) if i \\neq j.\n- 1 \\leq Q \\leq 2 \\times 10^5\n- 1 \\leq T_j \\leq 10^9\n- 1 \\leq A_j \\leq N\n- All input values are integers.\n\nSample Input 1\n\n5 3\n1 1\n1 2\n2 2\n3 2\n2 3\n6\n1 1\n1 2\n2 3\n2 5\n3 4\n3 5\n\nSample Output 1\n\nYes\nYes\nNo\nYes\nNo\nYes\n\nThe positions of the blocks change as follows: (\"時刻\" means \"time.\")\n\n\n- Query 1: At time 1.5, block 1 exists, so the answer is Yes.\n- Query 2: At time 1.5, block 2 exists, so the answer is Yes.\n- Query 3: Block 3 disappears at time 2, so it does not exist at time 2.5, and the answer is No.\n\nSample Input 2\n\n3 2\n1 1\n2 1\n1 2\n4\n1 1\n1 2\n1 3\n2 3\n\nSample Output 2\n\nNo\nNo\nYes\nYes\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["5 3\n1 1\n1 2\n2 2\n3 2\n2 3\n6\n1 1\n1 2\n2 3\n2 5\n3 4\n3 5", "Yes\nYes\nNo\nYes\nNo\nYes"], ["3 2\n1 1\n2 1\n1 2\n4\n1 1\n1 2\n1 3\n2 3", "No\nNo\nYes\nYes"]]}
{"id": "lcb/abc397_c", "task": "lcb", "testtype": "stdin", "difficulty": "medium", "date": "2025-03-15T00:00:00", "func_name": null, "prompt": "This problem is a simplified version of Problem F.\n\nYou are given an integer sequence of length N: A = (A_1, A_2, \\ldots, A_N).\nWhen splitting A at one position into two non-empty (contiguous) subarrays, find the maximum possible sum of the counts of distinct integers in those subarrays.\nMore formally, find the maximum sum of the following two values for an integer i such that 1 \\leq i \\leq N-1: the count of distinct integers in (A_1, A_2, \\ldots, A_i), and the count of distinct integers in (A_{i+1}, A_{i+2}, \\ldots, A_N).\n\nInput\n\nThe input is given from Standard Input in the following format:\nN\nA_1 A_2 \\ldots A_N\n\nOutput\n\nPrint the answer.\n\nConstraints\n\n\n- 2 \\leq N \\leq 3 \\times 10^5\n- 1 \\leq A_i \\leq N (1 \\leq i \\leq N)\n- All input values are integers.\n\nSample Input 1\n\n5\n3 1 4 1 5\n\nSample Output 1\n\n5\n\n\n- For i=1, (3) contains 1 distinct integer, and (1,4,1,5) contains 3 distinct integers, for a total of 4.\n- For i=2, (3,1) contains 2 distinct integers, and (4,1,5) contains 3 distinct integers, for a total of 5.\n- For i=3, (3,1,4) contains 3 distinct integers, and (1,5) contains 2 distinct integers, for a total of 5.\n- For i=4, (3,1,4,1) contains 3 distinct integers, and (5) contains 1 distinct integer, for a total of 4.\n\nTherefore, the maximum sum is 5 for i=2,3.\n\nSample Input 2\n\n10\n2 5 6 5 2 1 7 9 7 2\n\nSample Output 2\n\n8\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["5\n3 1 4 1 5", "5"], ["10\n2 5 6 5 2 1 7 9 7 2", "8"]]}
{"id": "lcb/3786", "task": "lcb", "testtype": "functional", "difficulty": "medium", "date": "2025-03-01T18:30:00", "func_name": "longestPalindromicSubsequence", "prompt": "You are given a string s and an integer k.\nIn one operation, you can replace the character at any position with the next or previous letter in the alphabet (wrapping around so that 'a' is after 'z'). For example, replacing 'a' with the next letter results in 'b', and replacing 'a' with the previous letter results in 'z'. Similarly, replacing 'z' with the next letter results in 'a', and replacing 'z' with the previous letter results in 'y'.\nReturn the length of the longest palindromic subsequence of s that can be obtained after performing at most k operations.\n \nExample 1:\n\nInput: s = \"abced\", k = 2\nOutput: 3\nExplanation:\n\nReplace s[1] with the next letter, and s becomes \"acced\".\nReplace s[4] with the previous letter, and s becomes \"accec\".\n\nThe subsequence \"ccc\" forms a palindrome of length 3, which is the maximum.\n\nExample 2:\n\nInput: s = \"aaazzz\", k = 4\nOutput: 6\nExplanation:\n\nReplace s[0] with the previous letter, and s becomes \"zaazzz\".\nReplace s[4] with the next letter, and s becomes \"zaazaz\".\nReplace s[3] with the next letter, and s becomes \"zaaaaz\".\n\nThe entire string forms a palindrome of length 6.\n\n \nConstraints:\n\n1 <= s.length <= 200\n1 <= k <= 200\ns consists of only lowercase English letters.\n\nComplete the following starter code and return the full solution (the class with the method) in a single ```python code block.\n\n```python\nclass Solution:\n def longestPalindromicSubsequence(self, s: str, k: int) -> int:\n```", "public": [["\"abced\"\n2", "3"], ["\"aaazzz\"\n4", "6"]]}
{"id": "lcb/3722", "task": "lcb", "testtype": "functional", "difficulty": "medium", "date": "2025-03-01T18:30:00", "func_name": "maxSum", "prompt": "You are given an integer array nums and two integers, k and m.\nReturn the maximum sum of k non-overlapping subarrays of nums, where each subarray has a length of at least m.\n \nExample 1:\n\nInput: nums = [1,2,-1,3,3,4], k = 2, m = 2\nOutput: 13\nExplanation:\nThe optimal choice is:\n\nSubarray nums[3..5] with sum 3 + 3 + 4 = 10 (length is 3 >= m).\nSubarray nums[0..1] with sum 1 + 2 = 3 (length is 2 >= m).\n\nThe total sum is 10 + 3 = 13.\n\nExample 2:\n\nInput: nums = [-10,3,-1,-2], k = 4, m = 1\nOutput: -10\nExplanation:\nThe optimal choice is choosing each element as a subarray. The output is (-10) + 3 + (-1) + (-2) = -10.\n\n \nConstraints:\n\n1 <= nums.length <= 2000\n-10^4 <= nums[i] <= 10^4\n1 <= k <= floor(nums.length / m)\n1 <= m <= 3\n\nComplete the following starter code and return the full solution (the class with the method) in a single ```python code block.\n\n```python\nclass Solution:\n def maxSum(self, nums: List[int], k: int, m: int) -> int:\n```", "public": [["[1, 2, -1, 3, 3, 4]\n2\n2", "13"], ["[-10, 3, -1, -2]\n4\n1", "-10"]]}
{"id": "lcb/3779", "task": "lcb", "testtype": "functional", "difficulty": "medium", "date": "2025-02-15T18:30:00", "func_name": "maxWeight", "prompt": "You are given an integer array pizzas of size n, where pizzas[i] represents the weight of the i^th pizza. Every day, you eat exactly 4 pizzas. Due to your incredible metabolism, when you eat pizzas of weights W, X, Y, and Z, where W <= X <= Y <= Z, you gain the weight of only 1 pizza!\n\nOn odd-numbered days (1-indexed), you gain a weight of Z.\nOn even-numbered days, you gain a weight of Y.\n\nFind the maximum total weight you can gain by eating all pizzas optimally.\nNote: It is guaranteed that n is a multiple of 4, and each pizza can be eaten only once.\n \nExample 1:\n\nInput: pizzas = [1,2,3,4,5,6,7,8]\nOutput: 14\nExplanation:\n\nOn day 1, you eat pizzas at indices [1, 2, 4, 7] = [2, 3, 5, 8]. You gain a weight of 8.\nOn day 2, you eat pizzas at indices [0, 3, 5, 6] = [1, 4, 6, 7]. You gain a weight of 6.\n\nThe total weight gained after eating all the pizzas is 8 + 6 = 14.\n\nExample 2:\n\nInput: pizzas = [2,1,1,1,1,1,1,1]\nOutput: 3\nExplanation:\n\nOn day 1, you eat pizzas at indices [4, 5, 6, 0] = [1, 1, 1, 2]. You gain a weight of 2.\nOn day 2, you eat pizzas at indices [1, 2, 3, 7] = [1, 1, 1, 1]. You gain a weight of 1.\n\nThe total weight gained after eating all the pizzas is 2 + 1 = 3.\n\n \nConstraints:\n\n4 <= n == pizzas.length <= 2 * 10^5\n1 <= pizzas[i] <= 10^5\nn is a multiple of 4.\n\nComplete the following starter code and return the full solution (the class with the method) in a single ```python code block.\n\n```python\nclass Solution:\n def maxWeight(self, pizzas: List[int]) -> int:\n```", "public": [["[1, 2, 3, 4, 5, 6, 7, 8]", "14"], ["[2, 1, 1, 1, 1, 1, 1, 1]", "3"]]}
{"id": "lcb/3677", "task": "lcb", "testtype": "functional", "difficulty": "medium", "date": "2025-01-11T18:30:00", "func_name": "maximumAmount", "prompt": "You are given an m x n grid. A robot starts at the top-left corner of the grid (0, 0) and wants to reach the bottom-right corner (m - 1, n - 1). The robot can move either right or down at any point in time.\nThe grid contains a value coins[i][j] in each cell:\n\nIf coins[i][j] >= 0, the robot gains that many coins.\nIf coins[i][j] < 0, the robot encounters a robber, and the robber steals the absolute value of coins[i][j] coins.\n\nThe robot has a special ability to neutralize robbers in at most 2 cells on its path, preventing them from stealing coins in those cells.\nNote: The robot's total coins can be negative.\nReturn the maximum profit the robot can gain on the route.\n \nExample 1:\n\nInput: coins = [[0,1,-1],[1,-2,3],[2,-3,4]]\nOutput: 8\nExplanation:\nAn optimal path for maximum coins is:\n\nStart at (0, 0) with 0 coins (total coins = 0).\nMove to (0, 1), gaining 1 coin (total coins = 0 + 1 = 1).\nMove to (1, 1), where there's a robber stealing 2 coins. The robot uses one neutralization here, avoiding the robbery (total coins = 1).\nMove to (1, 2), gaining 3 coins (total coins = 1 + 3 = 4).\nMove to (2, 2), gaining 4 coins (total coins = 4 + 4 = 8).\n\n\nExample 2:\n\nInput: coins = [[10,10,10],[10,10,10]]\nOutput: 40\nExplanation:\nAn optimal path for maximum coins is:\n\nStart at (0, 0) with 10 coins (total coins = 10).\nMove to (0, 1), gaining 10 coins (total coins = 10 + 10 = 20).\nMove to (0, 2), gaining another 10 coins (total coins = 20 + 10 = 30).\nMove to (1, 2), gaining the final 10 coins (total coins = 30 + 10 = 40).\n\n\n \nConstraints:\n\nm == coins.length\nn == coins[i].length\n1 <= m, n <= 500\n-1000 <= coins[i][j] <= 1000\n\nComplete the following starter code and return the full solution (the class with the method) in a single ```python code block.\n\n```python\nclass Solution:\n def maximumAmount(self, coins: List[List[int]]) -> int:\n```", "public": [["[[0, 1, -1], [1, -2, 3], [2, -3, 4]]", "8"], ["[[10, 10, 10], [10, 10, 10]]", "40"]]}
{"id": "lcb/3771", "task": "lcb", "testtype": "functional", "difficulty": "medium", "date": "2025-02-15T18:30:00", "func_name": "maxSubstringLength", "prompt": "Given a string s of length n and an integer k, determine whether it is possible to select k disjoint special substrings.\nA special substring is a substring where:\n\nAny character present inside the substring should not appear outside it in the string.\nThe substring is not the entire string s.\n\nNote that all k substrings must be disjoint, meaning they cannot overlap.\nReturn true if it is possible to select k such disjoint special substrings; otherwise, return false.\n \nExample 1:\n\nInput: s = \"abcdbaefab\", k = 2\nOutput: true\nExplanation:\n\nWe can select two disjoint special substrings: \"cd\" and \"ef\".\n\"cd\" contains the characters 'c' and 'd', which do not appear elsewhere in s.\n\"ef\" contains the characters 'e' and 'f', which do not appear elsewhere in s.\n\n\nExample 2:\n\nInput: s = \"cdefdc\", k = 3\nOutput: false\nExplanation:\nThere can be at most 2 disjoint special substrings: \"e\" and \"f\". Since k = 3, the output is false.\n\nExample 3:\n\nInput: s = \"abeabe\", k = 0\nOutput: true\n\n \nConstraints:\n\n2 <= n == s.length <= 5 * 10^4\n0 <= k <= 26\ns consists only of lowercase English letters.\n\nComplete the following starter code and return the full solution (the class with the method) in a single ```python code block.\n\n```python\nclass Solution:\n def maxSubstringLength(self, s: str, k: int) -> bool:\n```", "public": [["\"abcdbaefab\"\n2", "true"], ["\"cdefdc\"\n3", "false"], ["\"abeabe\"\n0", "true"]]}
{"id": "lcb/3743", "task": "lcb", "testtype": "functional", "difficulty": "medium", "date": "2025-02-01T06:30:00", "func_name": "maxFreeTime", "prompt": "You are given an integer eventTime denoting the duration of an event, where the event occurs from time t = 0 to time t = eventTime.\nYou are also given two integer arrays startTime and endTime, each of length n. These represent the start and end time of n non-overlapping meetings, where the i^th meeting occurs during the time [startTime[i], endTime[i]].\nYou can reschedule at most k meetings by moving their start time while maintaining the same duration, to maximize the longest continuous period of free time during the event.\nThe relative order of all the meetings should stay the same and they should remain non-overlapping.\nReturn the maximum amount of free time possible after rearranging the meetings.\nNote that the meetings can not be rescheduled to a time outside the event.\n \nExample 1:\n\nInput: eventTime = 5, k = 1, startTime = [1,3], endTime = [2,5]\nOutput: 2\nExplanation:\n\nReschedule the meeting at [1, 2] to [2, 3], leaving no meetings during the time [0, 2].\n\nExample 2:\n\nInput: eventTime = 10, k = 1, startTime = [0,2,9], endTime = [1,4,10]\nOutput: 6\nExplanation:\n\nReschedule the meeting at [2, 4] to [1, 3], leaving no meetings during the time [3, 9].\n\nExample 3:\n\nInput: eventTime = 5, k = 2, startTime = [0,1,2,3,4], endTime = [1,2,3,4,5]\nOutput: 0\nExplanation:\nThere is no time during the event not occupied by meetings.\n\n \nConstraints:\n\n1 <= eventTime <= 10^9\nn == startTime.length == endTime.length\n2 <= n <= 10^5\n1 <= k <= n\n0 <= startTime[i] < endTime[i] <= eventTime\nendTime[i] <= startTime[i + 1] where i lies in the range [0, n - 2].\n\nComplete the following starter code and return the full solution (the class with the method) in a single ```python code block.\n\n```python\nclass Solution:\n def maxFreeTime(self, eventTime: int, k: int, startTime: List[int], endTime: List[int]) -> int:\n```", "public": [["5\n1\n[1, 3]\n[2, 5]", "2"], ["10\n1\n[0, 2, 9]\n[1, 4, 10]", "6"], ["5\n2\n[0, 1, 2, 3, 4]\n[1, 2, 3, 4, 5]", "0"]]}
{"id": "lcb/3751", "task": "lcb", "testtype": "functional", "difficulty": "medium", "date": "2025-01-25T18:30:00", "func_name": "maxFrequency", "prompt": "You are given an array nums of length n. You are also given an integer k.\nYou perform the following operation on nums once:\n\nSelect a subarray nums[i..j] where 0 <= i <= j <= n - 1.\nSelect an integer x and add x to all the elements in nums[i..j].\n\nFind the maximum frequency of the value k after the operation.\n \nExample 1:\n\nInput: nums = [1,2,3,4,5,6], k = 1\nOutput: 2\nExplanation:\nAfter adding -5 to nums[2..5], 1 has a frequency of 2 in [1, 2, -2, -1, 0, 1].\n\nExample 2:\n\nInput: nums = [10,2,3,4,5,5,4,3,2,2], k = 10\nOutput: 4\nExplanation:\nAfter adding 8 to nums[1..9], 10 has a frequency of 4 in [10, 10, 11, 12, 13, 13, 12, 11, 10, 10].\n\n \nConstraints:\n\n1 <= n == nums.length <= 10^5\n1 <= nums[i] <= 50\n1 <= k <= 50\n\nComplete the following starter code and return the full solution (the class with the method) in a single ```python code block.\n\n```python\nclass Solution:\n def maxFrequency(self, nums: List[int], k: int) -> int:\n```", "public": [["[1, 2, 3, 4, 5, 6]\n1", "2"], ["[10, 2, 3, 4, 5, 5, 4, 3, 2, 2]\n10", "4"]]}
{"id": "lcb/3764", "task": "lcb", "testtype": "functional", "difficulty": "medium", "date": "2025-02-22T18:30:00", "func_name": "maxSum", "prompt": "You are given a 2D integer matrix grid of size n x m, an integer array limits of length n, and an integer k. The task is to find the maximum sum of at most k elements from the matrix grid such that:\n\n\nThe number of elements taken from the i^th row of grid does not exceed limits[i].\n\n\nReturn the maximum sum.\n \nExample 1:\n\nInput: grid = [[1,2],[3,4]], limits = [1,2], k = 2\nOutput: 7\nExplanation:\n\nFrom the second row, we can take at most 2 elements. The elements taken are 4 and 3.\nThe maximum possible sum of at most 2 selected elements is 4 + 3 = 7.\n\n\nExample 2:\n\nInput: grid = [[5,3,7],[8,2,6]], limits = [2,2], k = 3\nOutput: 21\nExplanation:\n\nFrom the first row, we can take at most 2 elements. The element taken is 7.\nFrom the second row, we can take at most 2 elements. The elements taken are 8 and 6.\nThe maximum possible sum of at most 3 selected elements is 7 + 8 + 6 = 21.\n\n\n \nConstraints:\n\nn == grid.length == limits.length\nm == grid[i].length\n1 <= n, m <= 500\n0 <= grid[i][j] <= 10^5\n0 <= limits[i] <= m\n0 <= k <= min(n * m, sum(limits))\n\nComplete the following starter code and return the full solution (the class with the method) in a single ```python code block.\n\n```python\nclass Solution:\n def maxSum(self, grid: List[List[int]], limits: List[int], k: int) -> int:\n```", "public": [["[[1, 2], [3, 4]]\n[1, 2]\n2", "7"], ["[[5, 3, 7], [8, 2, 6]]\n[2, 2]\n3", "21"]]}
{"id": "lcb/3714", "task": "lcb", "testtype": "functional", "difficulty": "medium", "date": "2025-01-18T18:30:00", "func_name": "minMaxSums", "prompt": "You are given an integer array nums and a positive integer k. Return the sum of the maximum and minimum elements of all subsequences of nums with at most k elements.\nSince the answer may be very large, return it modulo 10^9 + 7.\n \nExample 1:\n\nInput: nums = [1,2,3], k = 2\nOutput: 24\nExplanation:\nThe subsequences of nums with at most 2 elements are:\n\n\n\nSubsequence \nMinimum\nMaximum\nSum\n\n\n[1]\n1\n1\n2\n\n\n[2]\n2\n2\n4\n\n\n[3]\n3\n3\n6\n\n\n[1, 2]\n1\n2\n3\n\n\n[1, 3]\n1\n3\n4\n\n\n[2, 3]\n2\n3\n5\n\n\nFinal Total\n \n \n24\n\n\n\nThe output would be 24.\n\nExample 2:\n\nInput: nums = [5,0,6], k = 1\nOutput: 22\nExplanation: \nFor subsequences with exactly 1 element, the minimum and maximum values are the element itself. Therefore, the total is 5 + 5 + 0 + 0 + 6 + 6 = 22.\n\nExample 3:\n\nInput: nums = [1,1,1], k = 2\nOutput: 12\nExplanation:\nThe subsequences [1, 1] and [1] each appear 3 times. For all of them, the minimum and maximum are both 1. Thus, the total is 12.\n\n \nConstraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^9\n1 <= k <= min(70, nums.length)\n\nComplete the following starter code and return the full solution (the class with the method) in a single ```python code block.\n\n```python\nclass Solution:\n def minMaxSums(self, nums: List[int], k: int) -> int:\n```", "public": [["[1, 2, 3]\n2", "24"], ["[5, 0, 6]\n1", "22"], ["[1, 1, 1]\n2", "12"]]}
{"id": "lcb/abc397_b", "task": "lcb", "testtype": "stdin", "difficulty": "medium", "date": "2025-03-15T00:00:00", "func_name": null, "prompt": "Takahashi aggregated usage records from ticket gates.\r\nHowever, he accidentally erased some records of entering and exiting stations.\r\nHe is trying to restore the erased records.\n\nYou are given a string S consisting of i and o. We want to insert zero or more characters at arbitrary positions in S so that the resulting string satisfies the following conditions:\n\n- Its length is even, and every odd-numbered (1st, 3rd, ...) character is i while every even-numbered (2nd, 4th, ...) character is o.\n\nFind the minimum number of characters that need to be inserted. It can be proved under the constraints of this problem that by inserting an appropriate finite number of characters, S can be made to satisfy the conditions.\n\nInput\n\nThe input is given from Standard Input in the following format:\nS\n\nOutput\n\nPrint the answer.\n\nConstraints\n\n\n- S is a string of length between 1 and 100, consisting of i and o.\n\nSample Input 1\n\nioi\n\nSample Output 1\n\n1\r\n\nWe can insert o after the 3rd character to form ioio to satisfy the conditions. The conditions cannot be satisfied by inserting zero or fewer characters.\n\nSample Input 2\n\niioo\n\nSample Output 2\n\n2\r\n\nWe can insert o after the 1st character and i after the 3rd character to satisfy the conditions. The conditions cannot be satisfied by inserting one or fewer characters.\n\nSample Input 3\n\nio\n\nSample Output 3\n\n0\r\n\nS already satisfies the conditions.\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["ioi", "1"], ["iioo", "2"], ["io", "0"]]}
{"id": "lcb/abc387_f", "task": "lcb", "testtype": "stdin", "difficulty": "hard", "date": "2025-01-04T00:00:00", "func_name": null, "prompt": "You are given positive integers N, M, and a sequence A = (A_1, A_2, \\dots, A_N) of length N, each element being an integer between 1 and N, inclusive.\nFind the number, modulo 998244353, of sequences x = (x_1, x_2, \\dots, x_N) of length N, each element being an integer between 1 and M, inclusive, that satisfy the following condition:\n\n- x_i \\leq x_{A_i} for every i (1 \\leq i \\leq N).\n\nInput\n\nThe input is given from Standard Input in the following format:\nN M\r\nA_1 A_2 \\dots A_N\n\nOutput\n\nPrint the answer.\n\nConstraints\n\n\n- 1 \\leq N, M \\leq 2025\n- 1 \\leq A_i \\leq N\n- All input values are integers.\n\nSample Input 1\n\n3 3\r\n2 1 1\n\nSample Output 1\n\n6\r\n\nThe sequences x=(1,1,1),(2,2,1),(2,2,2),(3,3,1),(3,3,2),(3,3,3) satisfy the condition.\n\nSample Input 2\n\n4 9\r\n1 1 1 1\n\nSample Output 2\n\n2025\n\nSample Input 3\n\n10 5\r\n9 4 5 5 4 2 1 5 7 2\n\nSample Output 3\n\n10010\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["3 3\n2 1 1", "6"], ["4 9\n1 1 1 1", "2025"], ["10 5\n9 4 5 5 4 2 1 5 7 2", "10010"]]}
{"id": "lcb/3784", "task": "lcb", "testtype": "functional", "difficulty": "hard", "date": "2025-03-15T07:30:00", "func_name": "longestCommonPrefix", "prompt": "You are given an array of strings words and an integer k.\nFor each index i in the range [0, words.length - 1], find the length of the longest common prefix among any k strings (selected at distinct indices) from the remaining array after removing the i^th element.\nReturn an array answer, where answer[i] is the answer for i^th element. If removing the i^th element leaves the array with fewer than k strings, answer[i] is 0.\n \nExample 1:\n\nInput: words = [\"jump\",\"run\",\"run\",\"jump\",\"run\"], k = 2\nOutput: [3,4,4,3,4]\nExplanation:\n\nRemoving index 0 (\"jump\"):\n\n\t\nwords becomes: [\"run\", \"run\", \"jump\", \"run\"]. \"run\" occurs 3 times. Choosing any two gives the longest common prefix \"run\" (length 3).\n\n\nRemoving index 1 (\"run\"):\n\t\nwords becomes: [\"jump\", \"run\", \"jump\", \"run\"]. \"jump\" occurs twice. Choosing these two gives the longest common prefix \"jump\" (length 4).\n\n\nRemoving index 2 (\"run\"):\n\t\nwords becomes: [\"jump\", \"run\", \"jump\", \"run\"]. \"jump\" occurs twice. Choosing these two gives the longest common prefix \"jump\" (length 4).\n\n\nRemoving index 3 (\"jump\"):\n\t\nwords becomes: [\"jump\", \"run\", \"run\", \"run\"]. \"run\" occurs 3 times. Choosing any two gives the longest common prefix \"run\" (length 3).\n\n\nRemoving index 4 (\"run\"):\n\t\nwords becomes: [\"jump\", \"run\", \"run\", \"jump\"]. \"jump\" occurs twice. Choosing these two gives the longest common prefix \"jump\" (length 4).\n\n\n\n\nExample 2:\n\nInput: words = [\"dog\",\"racer\",\"car\"], k = 2\nOutput: [0,0,0]\nExplanation:\n\nRemoving any index results in an answer of 0.\n\n\n \nConstraints:\n\n1 <= k <= words.length <= 10^5\n1 <= words[i].length <= 10^4\nwords[i] consists of lowercase English letters.\nThe sum of words[i].length is smaller than or equal 10^5.\n\nComplete the following starter code and return the full solution (the class with the method) in a single ```python code block.\n\n```python\nclass Solution:\n def longestCommonPrefix(self, words: List[str], k: int) -> List[int]:\n```", "public": [["[\"jump\", \"run\", \"run\", \"jump\", \"run\"]\n2", "[3, 4, 4, 3, 4]"], ["[\"dog\", \"racer\", \"car\"]\n2", "[0, 0, 0]"]]}
{"id": "lcb/abc391_f", "task": "lcb", "testtype": "stdin", "difficulty": "hard", "date": "2025-02-01T00:00:00", "func_name": null, "prompt": "You are given three integer sequences of length N, namely A=(A_1,A_2,\\ldots,A_N), B=(B_1,B_2,\\ldots,B_N), and C=(C_1,C_2,\\ldots,C_N), and an integer K.\nFor each of the N^3 choices of integers i,j,k (1\\leq i,j,k\\leq N), compute the value A_iB_j + B_jC_k + C_kA_i. Among all these values, find the K-th largest value.\n\nInput\n\nThe input is given from Standard Input in the following format:\nN K\nA_1 A_2 \\ldots A_N\nB_1 B_2 \\ldots B_N\nC_1 C_2 \\ldots C_N\n\nOutput\n\nPrint the answer.\n\nConstraints\n\n\n- 1\\leq N \\leq 2\\times 10^5\n- 1\\leq K \\leq \\min(N^3,5\\times 10^5)\n- 1\\leq A_i,B_i,C_i \\leq 10^9\n- All input values are integers.\n\nSample Input 1\n\n2 5\n1 2\n3 4\n5 6\n\nSample Output 1\n\n31\n\nThe N^3=8 values are computed as follows:\n\n- For (i,j,k)=(1,1,1): A_1B_1+B_1C_1+C_1A_1=1\\times 3+3\\times 5+5\\times 1=23\n- For (i,j,k)=(1,1,2): A_1B_1+B_1C_2+C_2A_1=1\\times 3+3\\times 6+6\\times 1=27\n- For (i,j,k)=(1,2,1): A_1B_2+B_2C_1+C_1A_1=1\\times 4+4\\times 5+5\\times 1=29\n- For (i,j,k)=(1,2,2): A_1B_2+B_2C_2+C_2A_1=1\\times 4+4\\times 6+6\\times 1=34\n- For (i,j,k)=(2,1,1): A_2B_1+B_1C_1+C_1A_2=2\\times 3+3\\times 5+5\\times 2=31\n- For (i,j,k)=(2,1,2): A_2B_1+B_1C_2+C_2A_2=2\\times 3+3\\times 6+6\\times 2=36\n- For (i,j,k)=(2,2,1): A_2B_2+B_2C_1+C_1A_2=2\\times 4+4\\times 5+5\\times 2=38\n- For (i,j,k)=(2,2,2): A_2B_2+B_2C_2+C_2A_2=2\\times 4+4\\times 6+6\\times 2=44\n\nSorting these values in descending order, we have (44,38,36,34,31,29,27,23), so the 5th largest value is 31.\n\nSample Input 2\n\n3 10\n100 100 100\n100 100 100\n100 100 100\n\nSample Output 2\n\n30000\n\nSample Input 3\n\n5 54\n800516877 573289179 26509423 168629803 696409999\n656737335 915059758 201458890 931198638 185928366\n140174496 254538849 830992027 305186313 322164559\n\nSample Output 3\n\n689589940713840351\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["2 5\n1 2\n3 4\n5 6", "31"], ["3 10\n100 100 100\n100 100 100\n100 100 100", "30000"], ["5 54\n800516877 573289179 26509423 168629803 696409999\n656737335 915059758 201458890 931198638 185928366\n140174496 254538849 830992027 305186313 322164559", "689589940713840351"]]}
{"id": "lcb/abc392_f", "task": "lcb", "testtype": "stdin", "difficulty": "hard", "date": "2025-02-08T00:00:00", "func_name": null, "prompt": "There is an empty array A. For i = 1,2,\\ldots,N, perform the following operation in order:\n\n- Insert the number i into A so that it becomes the P_i-th element from the beginning.\n- More precisely, replace A with the concatenation of the first P_i-1 elements of A, then i, then the remaining elements of A starting from the P_i-th element, in this order.\n\n\n\nOutput the final array A after all operations have been completed.\n\nInput\n\nThe input is given from Standard Input in the following format:\nN\r\nP_1 P_2 \\ldots P_N\n\nOutput\n\nLet the final array be A = (A_1, A_2, \\ldots, A_N).\r\nPrint A_1, A_2, \\ldots, A_N in this order, separated by spaces.\n\nConstraints\n\n\n- 1 \\leq N \\leq 5\\times 10^5\n- 1 \\leq P_i \\leq i\n- All input values are integers.\n\nSample Input 1\n\n4\r\n1 1 2 1\n\nSample Output 1\n\n4 2 3 1\r\n\nThe operations are performed as follows:\n\n- Insert the number 1 so that it becomes the 1st element of A. Now, A = (1).\n- Insert the number 2 so that it becomes the 1st element of A. Now, A = (2, 1).\n- Insert the number 3 so that it becomes the 2nd element of A. Now, A = (2, 3, 1).\n- Insert the number 4 so that it becomes the 1st element of A. Now, A = (4, 2, 3, 1).\n\nSample Input 2\n\n5\r\n1 2 3 4 5\n\nSample Output 2\n\n1 2 3 4 5\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["4\n1 1 2 1", "4 2 3 1"], ["5\n1 2 3 4 5", "1 2 3 4 5"]]}
{"id": "lcb/abc400_g", "task": "lcb", "testtype": "stdin", "difficulty": "hard", "date": "2025-04-05T00:00:00", "func_name": null, "prompt": "Takahashi, a patissier working at the ABC pastry shop, decided to sell assorted cakes to commemorate AtCoder Beginner Contest 400.\nThe shop sells N kinds of cakes: cake 1, cake 2, \\ldots, cake N.\r\nEach cake has three non-negative integer values: beauty, tastiness, and popularity. Specifically, cake i has beauty X_i, tastiness Y_i, and popularity Z_i.\nHe considers pairing up these cakes into K pairs without overlaps.\r\nFormally, he will choose 2K distinct integers a_1,b_1,a_2,b_2,\\ldots,a_K,b_K between 1 and N (inclusive), and pair cake a_i with cake b_i.\r\nThe price of a pair formed by cakes a_i and b_i is \\max(X_{a_i} + X_{b_i},\\, Y_{a_i} + Y_{b_i},\\, Z_{a_i} + Z_{b_i}).\r\nHere, \\max(P,Q,R) denotes the greatest value among P,Q,R.\nFind the maximum possible total price of the K pairs.\nYou are given T test cases; solve each of them.\n\nInput\n\nThe input is given from Standard Input in the following format:\nT\r\n\\mathrm{case}_1\r\n\\mathrm{case}_2\r\n\\vdots\r\n\\mathrm{case}_T\r\n\n\\mathrm{case}_i represents the i-th test case. Each test case is given in the following format:\nN K\r\nX_1 Y_1 Z_1\r\nX_2 Y_2 Z_2\r\n\\vdots\r\nX_N Y_N Z_N\n\nOutput\n\nPrint T lines. The i-th line (1\\leq i\\leq T) should contain the answer to the i-th test case.\n\nConstraints\n\n\n- 1\\leq T\\leq 1000\n- 2\\leq N \\leq 10^5\n- The sum of N over all test cases in each input file is at most 10^5.\n- 1\\leq K \\leq \\lfloor \\frac{N}{2}\\rfloor (For a real number x, \\lfloor x\\rfloor denotes the greatest integer not exceeding x.)\n- 0\\leq X_i,Y_i,Z_i \\leq 10^9\n- All input values are integers.\n\nSample Input 1\n\n1\r\n3 1\r\n6 3 8\r\n3 5 0\r\n2 7 3\n\nSample Output 1\n\n12\r\n\nWe form one pair out of three cakes.\nIf we pair cake 1 with cake 2, the price is \\max(6+3,\\,3+5,\\,8+0) = 9.\r\nIf we pair cake 1 with cake 3, the price is \\max(6+2,\\,3+7,\\,8+3) = 11.\r\nIf we pair cake 2 with cake 3, the price is \\max(3+2,\\,5+7,\\,0+3) = 12.\nHence, pairing cake 2 with cake 3 gives the highest price, which is 12.\n\nSample Input 2\n\n2\r\n5 2\r\n1 2 3\r\n1 2 3\r\n1 2 3\r\n1 2 3\r\n100 100 200\r\n6 2\r\n21 74 25\r\n44 71 80\r\n46 28 96\r\n1 74 24\r\n81 83 16\r\n55 31 1\n\nSample Output 2\n\n209\r\n333\r\n\nNote that each cake can appear in at most one pair.\r\nAlso note that there can be different cakes with identical values of beauty, tastiness, and popularity.\nFor the first test case, pairing cake 1 with cake 2 gives a price of 6, pairing cake 3 with cake 5 gives a price of 203, and choosing these two pairs yields a total price of 209, which is the maximum. \nFor the second test case, pairing cake 2 with cake 3 gives a price of 176, pairing cake 4 with cake 5 gives a price of 157, and choosing these two pairs yields a total price of 333, which is the maximum.\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["1\n3 1\n6 3 8\n3 5 0\n2 7 3", "12"], ["2\n5 2\n1 2 3\n1 2 3\n1 2 3\n1 2 3\n100 100 200\n6 2\n21 74 25\n44 71 80\n46 28 96\n1 74 24\n81 83 16\n55 31 1", "209\n333"]]}
{"id": "lcb/abc391_g", "task": "lcb", "testtype": "stdin", "difficulty": "hard", "date": "2025-02-01T00:00:00", "func_name": null, "prompt": "You are given a lowercase English string S of length N and an integer M. For each k=0,1,\\ldots,N, solve the following problem:\n\n- There are 26^M lowercase English strings of length M. Among these, find the number, modulo 998244353, of strings whose longest common subsequence with S has length exactly k.\n\nInput\n\nThe input is given from Standard Input in the following format:\nN M\r\nS\n\nOutput\n\nLet \\mathrm{ans}_i be the answer for k=i. Print the answers in the following format:\n\\mathrm{ans}_0 \\mathrm{ans}_1 \\ldots \\mathrm{ans}_N\n\nConstraints\n\n\n- 1\\leq N\\leq 10\n- 1\\leq M\\leq 100\n- N and M are integers.\n- S is a lowercase English string of length N.\n\nSample Input 1\n\n2 2\r\nab\n\nSample Output 1\n\n576 99 1\r\n\nThe answers for k=0,1,2 are as follows:\n\n- For k=0: Among length 2 lowercase English strings, those with a longest common subsequence of length 0 with ab include strings such as cd, re, zz, totaling 576.\n- For k=1: Among length 2 lowercase English strings, those with a longest common subsequence of length 1 with ab include strings such as ac, wa, ba, totaling 99.\n- For k=2: Among length 2 lowercase English strings, there is 1 string (ab) whose longest common subsequence with ab has length 2.\n\nSample Input 2\n\n3 4\r\naaa\n\nSample Output 2\n\n390625 62500 3750 101\n\nSample Input 3\n\n7 50\r\natcoder\n\nSample Output 3\n\n309810541 226923474 392073062 146769908 221445233 435648037 862664208 238437587\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["2 2\nab", "576 99 1"], ["3 4\naaa", "390625 62500 3750 101"], ["7 50\natcoder", "309810541 226923474 392073062 146769908 221445233 435648037 862664208 238437587"]]}
{"id": "lcb/arc196_c", "task": "lcb", "testtype": "stdin", "difficulty": "hard", "date": "2025-04-06T00:00:00", "func_name": null, "prompt": "There is a directed graph with 2N vertices and 2N-1 edges.\r\nThe vertices are numbered 1, 2, \\ldots, 2N, and the i-th edge is a directed edge from vertex i to vertex i+1.\nYou are given a length-2N string S = S_1 S_2 \\ldots S_{2N} consisting of N Ws and N Bs.\r\nVertex i is colored white if S_i is W, and black if S_i is B.\nYou will perform the following series of operations:\n\n- Partition the 2N vertices into N pairs, each consisting of one white vertex and one black vertex.\n- For each pair, add a directed edge from the white vertex to the black vertex.\n\nPrint the number, modulo 998244353, of ways to partition the vertices into N pairs such that the final graph is strongly connected.\n Notes on strongly connectedness\nA directed graph is strongly connected if and only if it is possible to travel from any vertex to any vertex by following edges.\n\nInput\n\nThe input is given from Standard Input in the following format:\nN\r\nS\n\nOutput\n\nPrint the number, modulo 998244353, of ways to partition the vertices into N pairs so that the final graph is strongly connected.\n\nConstraints\n\n\n- 1 \\le N \\le 2\\times 10^5\n- S is a length 2N string consisting of N Ws and N Bs.\n- N is an integer.\n\nSample Input 1\n\n2\r\nBWBW\n\nSample Output 1\n\n1\r\n\nVertices 2,4 are white, and vertices 1,3 are black.\nLet (u,v) denote an edge from vertex u to vertex v.\nIf we pair up vertices as (2,1), (4,3), the final graph have the edges (1,2), (2,3), (3,4), (2,1), (4,3). In this case, for example, it is impossible to travel from vertex 3 to vertex 1 by following edges, so this graph is not strongly connected.\nIf we pair up vertices as (2,3), (4,1), the final graph have the edges (1,2), (2,3), (3,4), (2,3), (4,1). This graph is strongly connected.\nTherefore, there is exactly 1 way to pair up the vertices that satisfies the condition.\n\nSample Input 2\n\n4\r\nBWWBWBWB\n\nSample Output 2\n\n0\r\n\nNo matter how you pair up the vertices, you cannot satisfy the condition.\n\nSample Input 3\n\n9\r\nBWWBWBBBWWBWBBWWBW\n\nSample Output 3\n\n240792\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["2\nBWBW", "1"], ["4\nBWWBWBWB", "0"], ["9\nBWWBWBBBWWBWBBWWBW", "240792"]]}
{"id": "lcb/abc388_g", "task": "lcb", "testtype": "stdin", "difficulty": "hard", "date": "2025-01-11T00:00:00", "func_name": null, "prompt": "There are N mochi (rice cakes), arranged in ascending order of size.\r\nThe size of the i-th mochi (1\\leq i\\leq N) is A_i.\nGiven two mochi A and B, with sizes a and b respectively, you can make one kagamimochi (a stacked rice cake) by placing mochi A on top of mochi B if and only if a is at most half of b.\nYou are given Q integer pairs. Let (L_i, R_i) be the i-th pair (1\\leq i\\leq Q), and solve the following problem for each i:\n\nUsing only the R_i - L_i + 1 mochi from the L_i-th to the R_i-th, how many kagamimochi can you make simultaneously? \nMore precisely, find the maximum non-negative integer K such that:\n\n- Out of the R_i - L_i + 1 mochi from the L_i-th to the R_i-th, choose 2K mochi and form K pairs. For each pair, place one mochi on top of the other, to make K kagamimochi.\n\nInput\n\nThe input is given from Standard Input in the following format:\nN\r\nA_1 A_2 \\dotsc A_N\r\nQ\r\nL_1 R_1\r\nL_2 R_2\r\n\\vdots\r\nL_Q R_Q\n\nOutput\n\nPrint Q lines. The i-th line (1\\leq i\\leq Q) should contain the answer to the i-th query.\n\nConstraints\n\n\n- 2 \\leq N \\leq 2 \\times 10^5\n- 1 \\leq A_i \\leq 10^9 \\ (1 \\leq i \\leq N)\n- A_i \\leq A_{i+1} \\ (1 \\leq i < N)\n- 1 \\leq Q \\leq 2 \\times 10^5\n- 1 \\leq L_i < R_i \\leq N \\ (1 \\leq i \\leq Q)\n- All input values are integers.\n\nSample Input 1\n\n11\r\n1 1 2 3 4 4 7 10 11 12 20\r\n5\r\n2 5\r\n3 8\r\n7 11\r\n1 2\r\n1 11\n\nSample Output 1\n\n2\r\n3\r\n1\r\n0\r\n5\r\n\nThe answers to each query are as follows. One possible way to make the kagamimochi is given for each query.\n\n- The mochi sizes are (1, 2, 3, 4). You can make the two kagamimochi (1,3) and (2,4).\n- The mochi sizes are (2, 3, 4, 4, 7, 10). You can make the three kagamimochi (2,4), (3,7), and (4,10).\n- The mochi sizes are (7, 10, 11, 12, 20). You can make one kagamimochi (10,20).\n- The mochi sizes are (1, 1). You cannot make any kagamimochi.\n- The mochi sizes are (1, 1, 2, 3, 4, 4, 7, 10, 11, 12, 20). You can make five kagamimochi (1,2), (1,3), (4,10), (4,11), and (7,20).\n\nHence, print 2, 3, 1, 0, 5 in this order.\n\nSample Input 2\n\n24\r\n127 148 170 174 258 311 331 414 416 436 517 523 532 587 591 638 660 748 760 776 837 857 972 984\r\n15\r\n7 11\r\n8 9\r\n8 13\r\n12 15\r\n9 23\r\n1 17\r\n8 12\r\n1 5\r\n6 17\r\n3 7\r\n12 19\r\n13 18\r\n7 22\r\n1 12\r\n14 15\n\nSample Output 2\n\n0\r\n0\r\n0\r\n0\r\n2\r\n6\r\n0\r\n1\r\n1\r\n0\r\n0\r\n0\r\n3\r\n5\r\n0\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["11\n1 1 2 3 4 4 7 10 11 12 20\n5\n2 5\n3 8\n7 11\n1 2\n1 11", "2\n3\n1\n0\n5"], ["24\n127 148 170 174 258 311 331 414 416 436 517 523 532 587 591 638 660 748 760 776 837 857 972 984\n15\n7 11\n8 9\n8 13\n12 15\n9 23\n1 17\n8 12\n1 5\n6 17\n3 7\n12 19\n13 18\n7 22\n1 12\n14 15", "0\n0\n0\n0\n2\n6\n0\n1\n1\n0\n0\n0\n3\n5\n0"]]}
{"id": "lcb/3697", "task": "lcb", "testtype": "functional", "difficulty": "hard", "date": "2025-02-01T18:30:00", "func_name": "minimumIncrements", "prompt": "You are given two arrays, nums and target.\nIn a single operation, you may increment any element of nums by 1.\nReturn the minimum number of operations required so that each element in target has at least one multiple in nums.\n \nExample 1:\n\nInput: nums = [1,2,3], target = [4]\nOutput: 1\nExplanation:\nThe minimum number of operations required to satisfy the condition is 1.\n\nIncrement 3 to 4 with just one operation, making 4 a multiple of itself.\n\n\nExample 2:\n\nInput: nums = [8,4], target = [10,5]\nOutput: 2\nExplanation:\nThe minimum number of operations required to satisfy the condition is 2.\n\nIncrement 8 to 10 with 2 operations, making 10 a multiple of both 5 and 10.\n\n\nExample 3:\n\nInput: nums = [7,9,10], target = [7]\nOutput: 0\nExplanation:\nTarget 7 already has a multiple in nums, so no additional operations are needed.\n\n \nConstraints:\n\n1 <= nums.length <= 5 * 10^4\n1 <= target.length <= 4\ntarget.length <= nums.length\n1 <= nums[i], target[i] <= 10^4\n\nComplete the following starter code and return the full solution (the class with the method) in a single ```python code block.\n\n```python\nclass Solution:\n def minimumIncrements(self, nums: List[int], target: List[int]) -> int:\n```", "public": [["[1, 2, 3]\n[4]", "1"], ["[8, 4]\n[10, 5]", "2"], ["[7, 9, 10]\n[7]", "0"]]}
{"id": "lcb/arc191_d", "task": "lcb", "testtype": "stdin", "difficulty": "hard", "date": "2025-01-26T00:00:00", "func_name": null, "prompt": "You are given a simple connected undirected graph with N vertices and M edges, where the vertices are numbered 1 to N and the edges are numbered 1 to M. Edge i connects vertex u_i and vertex v_i in both directions.\nInitially, there is a piece A on vertex S and a piece B on vertex T. Here, S and T are given as input.\nYou may perform the following operation any number of times in any order:\n\n- Choose either piece A or piece B, and move it from its current vertex to an adjacent vertex via an edge. However, you cannot make a move that results in both pieces ending up on the same vertex.\n\nYour goal is to reach the state in which piece A is on vertex T and piece B is on vertex S.\nDetermine whether this is possible, and if it is, find the minimum number of operations required to achieve it.\n\nInput\n\nThe input is given from Standard Input in the following format:\nN M S T\nu_1 v_1\nu_2 v_2\n\\vdots\nu_M v_M\n\nOutput\n\nIf it is impossible to achieve the goal, print -1.\nIf it is possible, print the minimum number of operations required.\n\nConstraints\n\n\n- 2 \\le N \\le 2\\times 10^5\n- \\displaystyle N-1 \\le M \\le \\min\\left(\\frac{N(N-1)}{2},\\,2\\times 10^5\\right)\n- 1 \\le u_i < v_i \\le N\n- The given graph is simple and connected.\n- 1 \\le S, T \\le N\n- S \\neq T\n- All input values are integers.\n\nSample Input 1\n\n4 4 3 4\n2 4\n1 4\n3 4\n2 3\n\nSample Output 1\n\n3\n\nFor example, the following sequence of operations completes the goal in three moves:\n\n- Move piece A to vertex 2.\n- Piece A is on vertex 2, piece B is on vertex 4.\n\n\n- Move piece B to vertex 3.\n- Piece A is on vertex 2, piece B is on vertex 3.\n\n\n- Move piece A to vertex 4.\n- Piece A is on vertex 4, piece B is on vertex 3.\n\n\n\nIt is impossible to complete the goal in fewer than three moves, so print 3.\n\nSample Input 2\n\n2 1 1 2\n1 2\n\nSample Output 2\n\n-1\n\nNo matter how you move the pieces, you cannot achieve the goal.\n\nSample Input 3\n\n5 6 3 5\n1 2\n2 3\n1 5\n2 4\n1 3\n2 5\n\nSample Output 3\n\n4\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["4 4 3 4\n2 4\n1 4\n3 4\n2 3", "3"], ["2 1 1 2\n1 2", "-1"], ["5 6 3 5\n1 2\n2 3\n1 5\n2 4\n1 3\n2 5", "4"]]}
{"id": "lcb/abc397_d", "task": "lcb", "testtype": "stdin", "difficulty": "hard", "date": "2025-03-15T00:00:00", "func_name": null, "prompt": "You are given a positive integer N. Determine whether there exists a pair of positive integers (x,y) such that x^3 - y^3 = N. If such a pair exists, print one such pair (x,y).\n\nInput\n\nThe input is given from Standard Input in the following format:\nN\n\nOutput\n\nIf there is no pair of positive integers (x,y) satisfying x^3 - y^3 = N, print -1.\r\nIf there is such a pair, print x and y in this order separated by a space. If there are multiple solutions, printing any one of them is accepted as correct.\n\nConstraints\n\n\n- 1 \\leq N \\leq 10^{18}\n- All input values are integers.\n\nSample Input 1\n\n397\n\nSample Output 1\n\n12 11\r\n\nWe have 12^3 - 11^3 = 397, so (x,y) = (12,11) is a solution.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n-1\r\n\nNo pair of positive integers (x,y) satisfies x^3 - y^3 = 1. Thus, print -1.\n\nSample Input 3\n\n39977273855577088\n\nSample Output 3\n\n342756 66212\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["397", "12 11"], ["1", "-1"], ["39977273855577088", "342756 66212"]]}
{"id": "lcb/arc194_e", "task": "lcb", "testtype": "stdin", "difficulty": "hard", "date": "2025-03-09T00:00:00", "func_name": null, "prompt": "You are given two strings S and T, each of length N and consisting of 0 and 1, as well as two positive integers X and Y. For i = 1, 2, \\ldots, N, let S_i denote the i-th character of S.\nDetermine whether it is possible to make S identical to T by repeatedly performing Operations A and B below any number of times (possibly zero) in any order:\n\n- \r\n(Operation A) Choose an integer i satisfying 1 \\leq i \\leq N-(X+Y)+1, S_{i} = S_{i+1} = \\cdots = S_{i+X-1} = 0, and S_{i+X} = S_{i+X+1} = \\cdots = S_{i+X+Y-1} = 1, then change each of S_{i}, S_{i+1}, \\ldots, S_{i+Y-1} to 1 and each of S_{i+Y}, S_{i+Y+1}, \\ldots, S_{i+Y+X-1} to 0.\n\n- \r\n(Operation B) Choose an integer i satisfying 1 \\leq i \\leq N-(X+Y)+1, S_{i} = S_{i+1} = \\cdots = S_{i+Y-1} = 1, and S_{i+Y} = S_{i+Y+1} = \\cdots = S_{i+Y+X-1} = 0, then change each of S_{i}, S_{i+1}, \\ldots, S_{i+X-1} to 0 and each of S_{i+X}, S_{i+X+1}, \\ldots, S_{i+X+Y-1} to 1.\n\nInput\n\nThe input is given from Standard Input in the following format:\nN X Y\r\nS\r\nT\n\nOutput\n\nIf it is possible to make S identical to T, print Yes; otherwise, print No.\n\nConstraints\n\n\n- 1 \\leq N \\leq 5 \\times 10^5\n- 1 \\leq X, Y \\leq N\n- S and T are strings of length N consisting of 0 and 1.\n- All input values are integers.\n\nSample Input 1\n\n9 2 1\r\n000111001\r\n011000011\n\nSample Output 1\n\nYes\r\n\nThe following procedure can transform S into T:\n\n- First, perform Operation A with i = 2. Now, S = 010011001.\n- Next, perform Operation B with i = 6. Now, S = 010010011.\n- Finally, perform Operation A with i = 3. Now, S = 011000011.\n\nThus, print Yes.\n\nSample Input 2\n\n1 1 1\r\n0\r\n1\n\nSample Output 2\n\nNo\r\n\nIt is impossible to make S identical to T. Thus, print No.\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["9 2 1\n000111001\n011000011", "Yes"], ["1 1 1\n0\n1", "No"]]}
{"id": "lcb/abc398_g", "task": "lcb", "testtype": "stdin", "difficulty": "hard", "date": "2025-03-22T00:00:00", "func_name": null, "prompt": "You are given a simple undirected graph with N vertices and M edges, with vertices labeled 1 to N and edges labeled 1 to M. The i-th edge connects vertices U_i and V_i. Initially, G does not contain an odd cycle.\nTakahashi and Aoki will play a game using this graph G. With Aoki going first, they take turns performing the following operation:\n\n- Choose a pair of integers (i,j) with 1 \\leq i < j \\leq N that satisfies both of the following conditions, then add an edge connecting vertices i and j to G.\n- G does not already have an edge connecting vertices i and j.\n- Adding an edge connecting vertices i and j does not create an odd cycle.\n\n\n\nA player who cannot perform this operation loses, and the other player wins.\nDetermine who wins when both players play optimally.\n\nWhat is an odd cycle?\nA sequence of vertices (v_0,v_1,\\ldots,v_k) of G is called an odd cycle if and only if all of the following conditions are satisfied:\n\n- k is odd.\n- v_0=v_k.\n- For every 1\\leq i \\leq k, there is an edge connecting v_{i-1} and v_{i}.\n\nInput\n\nThe input is given from Standard Input in the following format:\nN M\nU_1 V_1\nU_2 V_2\n\\vdots\nU_M V_M\n\nOutput\n\nIf Aoki (the first player) wins, print Aoki; otherwise, if Takahashi (the second player) wins, print Takahashi.\n\nConstraints\n\n\n- 1 \\leq N \\leq 2\\times 10^5\n- 0 \\leq M \\leq 2\\times 10^5\n- 1 \\leq U_i < V_i \\leq N\n- The given graph does not contain an odd cycle.\n- The given graph does not contain multi-edges.\n- All input values are integers.\n\nSample Input 1\n\n4 3\n1 2\n2 3\n3 4\n\nSample Output 1\n\nAoki\n\nIf Aoki (the first player) adds the edge (1,4), Takahashi (the second player) cannot move. Thus, Aoki wins.\n\nSample Input 2\n\n4 2\n1 2\n3 4\n\nSample Output 2\n\nTakahashi\n\nNo matter how Aoki plays, Takahashi wins.\n\nSample Input 3\n\n9 5\n2 9\n2 3\n4 6\n5 7\n1 8\n\nSample Output 3\n\nAoki\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["4 3\n1 2\n2 3\n3 4", "Aoki"], ["4 2\n1 2\n3 4", "Takahashi"], ["9 5\n2 9\n2 3\n4 6\n5 7\n1 8", "Aoki"]]}
{"id": "lcb/arc192_d", "task": "lcb", "testtype": "stdin", "difficulty": "hard", "date": "2025-02-09T00:00:00", "func_name": null, "prompt": "For a positive rational number x, define f(x) as follows:\n\nExpress x as \\dfrac{P}{Q} using coprime positive integers P and Q. f(x) is defined as the value P\\times Q.\n\nYou are given a positive integer N and a sequence A=(A_1,A_2,\\dots,A_{N-1}) of positive integers of length N-1.\nWe call a sequence S=(S_1,S_2,\\dots,S_N) of positive integers of length N a good sequence if it satisfies all of the following conditions:\n\n- For every integer i with 1\\leq i\\leq N-1, it holds that f\\left(\\dfrac{S_i}{S_{i+1}}\\right)=A_i.\n- \\gcd(S_1,S_2,\\dots,S_N)=1.\n\nDefine the score of a sequence as the product of all its elements.\nIt can be proved that there are finitely many good sequences. Find the sum, modulo 998244353, of the scores of all good sequences.\n\nInput\n\nThe input is given from Standard Input in the following format:\nN\nA_1 A_2 \\dots A_{N-1}\n\nOutput\n\nPrint the sum, modulo 998244353, of the scores of all good sequences.\n\nConstraints\n\n\n- 2\\leq N\\leq 1000\n- 1\\leq A_i\\leq 1000 (1\\leq i\\leq N-1)\n- All input values are integers.\n\nSample Input 1\n\n6\n1 9 2 2 9\n\nSample Output 1\n\n939634344\n\nFor example, both (2,2,18,9,18,2) and (18,18,2,1,2,18) are good sequences, and both have a score of 23328.\nThere are a total of 16 good sequences, and the sum of the scores of all of them is 939634344.\n\nSample Input 2\n\n2\n9\n\nSample Output 2\n\n18\n\nThere are 2 good sequences, both with a score of 9.\n\nSample Input 3\n\n25\n222 299 229 22 999 922 99 992 22 292 222 229 992 922 22 992 222 222 99 29 92 999 2 29\n\nSample Output 3\n\n192457116\n\nDo not forget to compute the sum modulo 998244353.\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["6\n1 9 2 2 9", "939634344"], ["2\n9", "18"], ["25\n222 299 229 22 999 922 99 992 22 292 222 229 992 922 22 992 222 222 99 29 92 999 2 29", "192457116"]]}
{"id": "lcb/arc193_b", "task": "lcb", "testtype": "stdin", "difficulty": "hard", "date": "2025-02-23T00:00:00", "func_name": null, "prompt": "You are given a positive integer N and a length-N string s_0s_1\\ldots s_{N-1} consisting only of 0 and 1.\nConsider a simple undirected graph G with (N+1) vertices numbered 0, 1, 2, \\ldots, N, and the following edges:\n\n- For each i = 0, 1, \\ldots, N-1, there is an undirected edge between vertices i and (i+1)\\bmod N.\n- For each i = 0, 1, \\ldots, N-1, there is an undirected edge between vertices i and N if and only if s_i = 1.\n- There are no other edges.\n\nFurthermore, create a directed graph G' by assigning a direction to each edge of G. That is, for each undirected edge \\lbrace u, v \\rbrace in G, replace it with either a directed edge (u, v) from u to v or a directed edge (v, u) from v to u.\nFor each i = 0, 1, \\ldots, N, let d_i be the in-degree of vertex i in G'. Print the number, modulo 998244353, of distinct sequences (d_0, d_1, \\ldots, d_N) that can be obtained.\n\nInput\n\nThe input is given from Standard Input in the following format:\nN\ns_0s_1\\ldots s_{N-1}\n\nOutput\n\nPrint the answer.\n\nConstraints\n\n\n- 3 \\leq N \\leq 10^6\n- N is an integer.\n- Each s_i is 0 or 1.\n\nSample Input 1\n\n3\n010\n\nSample Output 1\n\n14\n\nG has four undirected edges: \\lbrace 0, 1 \\rbrace, \\lbrace 0, 2 \\rbrace, \\lbrace 1, 2 \\rbrace, \\lbrace 1, 3 \\rbrace.\nFor example, if we assign directions to each edge as 0 \\to 1, 2 \\to 0, 2 \\to 1, 1 \\to 3, then (d_0, d_1, d_2, d_3) = (1, 2, 0, 1) is obtained.\nThe possible sequences (d_0, d_1, d_2, d_3) are\n(0, 1, 2, 1), (0, 2, 1, 1), (0, 2, 2, 0), (0, 3, 1, 0), (1, 0, 2, 1), (1, 1, 1, 1), (1, 1, 2, 0), (1, 2, 0, 1), (1, 2, 1, 0), (1, 3, 0, 0), (2, 0, 1, 1), (2, 1, 0, 1), (2, 1, 1, 0), (2, 2, 0, 0), for a total of 14.\n\nSample Input 2\n\n20\n00001100111010100101\n\nSample Output 2\n\n261339902\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["3\n010", "14"], ["20\n00001100111010100101", "261339902"]]}
{"id": "lcb/arc194_c", "task": "lcb", "testtype": "stdin", "difficulty": "hard", "date": "2025-03-09T00:00:00", "func_name": null, "prompt": "You are given two integer sequences of length N, A = (A_1, A_2, \\ldots, A_N) and B = (B_1, B_2, \\ldots, B_N), each consisting of 0 and 1.\nYou can perform the following operation on A any number of times (possibly zero):\n\n- First, choose an integer i satisfying 1 \\leq i \\leq N, and flip the value of A_i (if the original value is 0, change it to 1; if it is 1, change it to 0).\n- Then, pay \\sum_{k=1}^N A_k C_k yen as the cost of this operation.\n\nNote that the cost calculation in step 2 uses the A after the change in step 1.\nPrint the minimum total cost required to make A identical to B.\n\nInput\n\nThe input is given from Standard Input in the following format:\nN\r\nA_1 A_2 \\ldots A_N\r\nB_1 B_2 \\ldots B_N\r\nC_1 C_2 \\ldots C_N\n\nOutput\n\nPrint the answer.\n\nConstraints\n\n\n- 1 \\leq N \\leq 2 \\times 10^5\n- A_i, B_i \\in {0, 1}\n- 1 \\leq C_i \\leq 10^6\n- All input values are integers.\n\nSample Input 1\n\n4\r\n0 1 1 1\r\n1 0 1 0\r\n4 6 2 9\n\nSample Output 1\n\n16\r\n\nConsider the following procedure:\n\n- First, flip A_4. Now, A = (0, 1, 1, 0). The cost of this operation is 0 \\times 4 + 1 \\times 6 + 1 \\times 2 + 0 \\times 9 = 8 yen.\n- Next, flip A_2. Now, A = (0, 0, 1, 0). The cost of this operation is 0 \\times 4 + 0 \\times 6 + 1 \\times 2 + 0 \\times 9 = 2 yen.\n- Finally, flip A_1. Now, A = (1, 0, 1, 0), which matches B. The cost of this operation is 1 \\times 4 + 0 \\times 6 + 1 \\times 2 + 0 \\times 9 = 6 yen.\n\nIn this case, the total cost is 8 + 2 + 6 = 16 yen, which is the minimum possible.\n\nSample Input 2\n\n5\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\n\nSample Output 2\n\n0\r\n\nA and B are already identical initially, so there is no need to perform any operations.\n\nSample Input 3\n\n20\r\n1 1 1 1 0 0 1 1 0 0 0 1 0 1 0 1 1 0 1 0\r\n0 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 1 0 0\r\n52 73 97 72 54 15 79 67 13 55 65 22 36 90 84 46 1 2 27 8\n\nSample Output 3\n\n2867\n\nWrite a Python 3 program that reads from standard input and writes to standard output. Put the complete program in a single ```python code block.", "public": [["4\n0 1 1 1\n1 0 1 0\n4 6 2 9", "16"], ["5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1", "0"], ["20\n1 1 1 1 0 0 1 1 0 0 0 1 0 1 0 1 1 0 1 0\n0 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 1 0 0\n52 73 97 72 54 15 79 67 13 55 65 22 36 90 84 46 1 2 27 8", "2867"]]}