ankhanhtran02's picture
Upload gmm_executable_soft_temp_1.0
c684b24 verified
Raw
History Blame Contribute Delete
260 kB
{
"eval": {},
"predictions": [
{
"source": "Write a python function 'def has_close_elements(numbers: List[float], threshold: float) -> bool:' to solve the following problem:\n Check if in given list of numbers, are any two numbers closer to each other than\n given threshold.\n >>> has_close_elements([1.0, 2.0, 3.0], 0.5)\n False\n >>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)\n True\n ",
"ground-truth": null,
"prediction": [
"from typing import List\n\ndef has_close_elements(numbers: List[float], threshold: float) -> bool:\n for i in range(len(numbers)):\n for j in range(i + 1, len(numbers)):\n if abs(numbers[i] - numbers[j]) < threshold:\n return True\n return False",
"from typing import List\n\ndef has_close_elements(numbers: List[float], threshold: float) -> bool:\n for i in range(len(numbers)):\n for j in range(i + 1, len(numbers)):\n if abs(numbers[i] - numbers[j]) < threshold:\n return True\n return False",
"from typing import List\n\ndef has_close_elements(numbers: List[float], threshold: float) -> bool:\n for i in range(len(numbers)):\n for j in range(i + 1, len(numbers)):\n if abs(numbers[i] - numbers[j]) < threshold:\n return True\n return False",
"from typing import List\n\ndef has_close_elements(numbers: List[float], threshold: float) -> bool:\n for i in range(len(numbers)):\n for j in range(i + 1, len(numbers)):\n if abs(numbers[i] - numbers[j]) < threshold:\n return True\n return False",
"from typing import List\n\ndef has_close_elements(numbers: List[float], threshold: float) -> bool:\n for i in range(len(numbers)):\n for j in range(i + 1, len(numbers)):\n if abs(numbers[i] - numbers[j]) < threshold:\n return True\n return False"
],
"moe_id": {
"python": 0.1054,
"cpp": 0.1511,
"swift": 0.1516,
"rust": 0.1212,
"csharp": 0.1042,
"java": 0.0901,
"php": 0.088,
"typescript": 0.1228,
"shell": 0.0656
}
},
{
"source": "Write a python function 'def separate_paren_groups(paren_string: str) -> List[str]:' to solve the following problem:\n Input to this function is a string containing multiple groups of nested parentheses. Your goal is to\n separate those group into separate strings and return the list of those.\n Separate groups are balanced (each open brace is properly closed) and not nested within each other\n Ignore any spaces in the input string.\n >>> separate_paren_groups('( ) (( )) (( )( ))')\n ['()', '(())', '(()())']\n ",
"ground-truth": null,
"prediction": [
"from typing import List\n\ndef separate_paren_groups(paren_string: str) -> List[str]:\n result = []\n current_group = ''\n depth = 0\n\n for char in paren_string.replace(' ', ''):\n if char == '(':\n depth += 1\n current_group += char\n elif char == ')':\n depth -= 1\n current_group += char\n if depth == 0:\n result.append(current_group)\n current_group = ''\n\n return result\n\n# Test cases\nprint(separate_paren_groups('( ) (( )) (( )( ))')) # Output: ['()', '(())', '(()())']\nprint(separate_paren_groups('(()())((()()))')) # Output: ['(()())', '((()))']\nprint(separate_paren_groups('()()')) # Output: ['()', '()']",
"from typing import List\n\ndef separate_paren_groups(paren_string: str) -> List[str]:\n \"\"\"\n Separates groups of nested parentheses in a string into separate strings.\n \n Args:\n paren_string (str): A string containing multiple groups of nested parentheses.\n \n Returns:\n List[str]: A list of separated groups of balanced parentheses.\n \"\"\"\n result = []\n current_group = ''\n depth = 0\n\n for char in paren_string.replace(' ', ''):\n if char == '(':\n depth += 1\n current_group += char\n elif char == ')':\n depth -= 1\n current_group += char\n if depth == 0:\n result.append(current_group)\n current_group = ''\n\n return result",
"from typing import List\n\ndef separate_paren_groups(paren_string: str) -> List[str]:\n \"\"\"\n Separates groups of nested parentheses in a string into separate strings.\n \n Args:\n paren_string (str): A string containing multiple groups of nested parentheses.\n \n Returns:\n List[str]: A list of strings, each representing a separate group of balanced parentheses.\n \"\"\"\n result = []\n current_group = \"\"\n depth = 0\n\n for char in paren_string.replace(\" \", \"\"): # Remove spaces for simplicity\n if char == '(':\n depth += 1\n current_group += char\n elif char == ')':\n depth -= 1\n current_group += char\n if depth == 0:\n result.append(current_group)\n current_group = \"\"\n\n return result\n\n# Test cases\nprint(separate_paren_groups('( ) (( )) (( )( ))')) # Output: ['()', '(())', '(()())']",
"from typing import List\n\ndef separate_paren_groups(paren_string: str) -> List[str]:\n stack = []\n result = []\n current_group = ''\n\n for char in paren_string.replace(' ', ''):\n if char == '(':\n stack.append(char)\n current_group += char\n elif char == ')':\n stack.pop()\n current_group += char\n if not stack:\n result.append(current_group)\n current_group = ''\n\n return result\n\n# Test cases\nprint(separate_paren_groups('( ) (( )) (( )( ))')) # Output: ['()', '(())', '(()())']\nprint(separate_paren_groups('(()())((()()))')) # Output: ['(()())', '((()))']\nprint(separate_paren_groups('()()')) # Output: ['()', '()']",
"from typing import List\n\ndef separate_paren_groups(paren_string: str) -> List[str]:\n \"\"\"\n Separates groups of nested parentheses in a string into separate strings.\n \n Args:\n paren_string (str): A string containing multiple groups of nested parentheses.\n \n Returns:\n List[str]: A list of strings, each representing a separate group of balanced parentheses.\n \"\"\"\n result = []\n current_group = ''\n depth = 0\n\n for char in paren_string.replace(' ', ''):\n if char == '(':\n depth += 1\n current_group += char\n elif char == ')':\n depth -= 1\n current_group += char\n if depth == 0:\n result.append(current_group)\n current_group = ''\n\n return result"
],
"moe_id": {
"python": 0.0617,
"cpp": 0.2703,
"swift": 0.1661,
"rust": 0.0935,
"csharp": 0.0813,
"java": 0.0549,
"php": 0.0862,
"typescript": 0.0794,
"shell": 0.1068
}
},
{
"source": "Write a python function 'def truncate_number(number: float) -> float:' to solve the following problem:\n Given a positive floating point number, it can be decomposed into\n and integer part (largest integer smaller than given number) and decimals\n (leftover part always smaller than 1).\n \n Return the decimal part of the number.\n >>> truncate_number(3.5)\n 0.5\n ",
"ground-truth": null,
"prediction": [
"def truncate_number(number: float) -> float:\n \"\"\"\n Truncates a positive floating point number to its decimal part.\n\n Args:\n number (float): The input number to be truncated.\n\n Returns:\n float: The decimal part of the input number.\n \"\"\"\n return number - int(number)",
"def truncate_number(number: float) -> float:\n integer_part = int(number)\n decimal_part = number - integer_part\n return decimal_part",
"def truncate_number(number: float) -> float:\n \"\"\"\n Given a positive floating point number, it can be decomposed into\n and integer part (largest integer smaller than given number) and decimals\n (leftover part always smaller than 1).\n \n Return the decimal part of the number.\n \"\"\"\n return number - int(number)",
"def truncate_number(number: float) -> float:\n \"\"\"\n Given a positive floating point number, it can be decomposed into\n and integer part (largest integer smaller than given number) and decimals\n (leftover part always smaller than 1).\n \n Return the decimal part of the number.\n \"\"\"\n return number - int(number)",
"def truncate_number(number: float) -> float:\n integer_part = int(number)\n decimal_part = number - integer_part\n return decimal_part\n\n# Test cases\nprint(truncate_number(3.5)) # Output: 0.5\nprint(truncate_number(10.75)) # Output: 0.75\nprint(truncate_number(0.99)) # Output: 0.99\nprint(truncate_number(5.0)) # Output: 0.0"
],
"moe_id": {
"python": 0.0016,
"cpp": 0.7748,
"swift": 0.1105,
"rust": 0.0127,
"csharp": 0.0097,
"java": 0.0025,
"php": 0.0212,
"typescript": 0.0167,
"shell": 0.0503
}
},
{
"source": "Write a python function 'def below_zero(operations: List[int]) -> bool:' to solve the following problem:\n You're given a list of deposit and withdrawal operations on a bank account that starts with\n zero balance. Your task is to detect if at any point the balance of account fallls below zero, and\n at that point function should return True. Otherwise it should return False.\n >>> below_zero([1, 2, 3])\n False\n >>> below_zero([1, 2, -4, 5])\n True\n ",
"ground-truth": null,
"prediction": [
"from typing import List\n\ndef below_zero(operations: List[int]) -> bool:\n balance = 0\n for operation in operations:\n balance += operation\n if balance < 0:\n return True\n return False",
"from typing import List\n\ndef below_zero(operations: List[int]) -> bool:\n balance = 0\n for operation in operations:\n balance += operation\n if balance < 0:\n return True\n return False",
"from typing import List\n\ndef below_zero(operations: List[int]) -> bool:\n balance = 0\n for operation in operations:\n balance += operation\n if balance < 0:\n return True\n return False",
"from typing import List\n\ndef below_zero(operations: List[int]) -> bool:\n balance = 0\n for operation in operations:\n balance += operation\n if balance < 0:\n return True\n return False",
"from typing import List\n\ndef below_zero(operations: List[int]) -> bool:\n balance = 0\n for operation in operations:\n balance += operation\n if balance < 0:\n return True\n return False"
],
"moe_id": {
"python": 0.0897,
"cpp": 0.1744,
"swift": 0.1556,
"rust": 0.1096,
"csharp": 0.1028,
"java": 0.0776,
"php": 0.0941,
"typescript": 0.0938,
"shell": 0.1024
}
},
{
"source": "Write a python function 'def mean_absolute_deviation(numbers: List[float]) -> float:' to solve the following problem:\n For a given list of input numbers, calculate Mean Absolute Deviation\n around the mean of this dataset.\n Mean Absolute Deviation is the average absolute difference between each\n element and a centerpoint (mean in this case):\n MAD = average | x - x_mean |\n >>> mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])\n 1.0\n ",
"ground-truth": null,
"prediction": [
"from typing import List\n\ndef mean_absolute_deviation(numbers: List[float]) -> float:\n \"\"\"\n Calculate the Mean Absolute Deviation (MAD) of a list of numbers.\n \n MAD is the average of the absolute differences between each number in the list\n and the mean of the list.\n \n Parameters:\n numbers (List[float]): A list of numbers for which MAD is to be calculated.\n \n Returns:\n float: The Mean Absolute Deviation of the input numbers.\n \"\"\"\n if not numbers:\n return 0.0 # Handle empty list case\n \n mean = sum(numbers) / len(numbers)\n mad = sum(abs(x - mean) for x in numbers) / len(numbers)\n return mad\n\n# Test cases\nprint(mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])) # Expected output: 1.0\nprint(mean_absolute_deviation([10.0, 12.0, 23.0, 23.0, 16.0, 23.0, 21.0, 16.0])) # Expected output: 4.375\nprint(mean_absolute_deviation([1.5, 2.5, 3.5, 4.5])) # Expected output: 1.5\nprint(mean_absolute_deviation([])) # Expected output: 0.0",
"from typing import List\n\ndef mean_absolute_deviation(numbers: List[float]) -> float:\n \"\"\"\n Calculate the Mean Absolute Deviation (MAD) of a list of numbers.\n \n MAD is the average of the absolute differences between each number in the list\n and the mean of the list.\n \n Parameters:\n numbers (List[float]): A list of numbers for which MAD is to be calculated.\n \n Returns:\n float: The Mean Absolute Deviation of the input numbers.\n \"\"\"\n if not numbers:\n return 0.0\n \n mean = sum(numbers) / len(numbers)\n mad = sum(abs(x - mean) for x in numbers) / len(numbers)\n return mad\n\n# Test cases to verify the solution\nprint(mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])) # Expected output: 1.0\nprint(mean_absolute_deviation([10.0, 12.0, 23.0, 23.0, 16.0, 23.0, 21.0, 16.0])) # Expected output: 4.375\nprint(mean_absolute_deviation([1.0, 1.0, 1.0, 1.0, 1.0])) # Expected output: 0.0\nprint(mean_absolute_deviation([])) # Expected output: 0.0",
"from typing import List\n\ndef mean_absolute_deviation(numbers: List[float]) -> float:\n \"\"\"\n Calculate the Mean Absolute Deviation (MAD) of a list of numbers.\n \n MAD is the average of the absolute differences between each number in the list\n and the mean of the list.\n \n Parameters:\n numbers (List[float]): A list of numbers for which to calculate the MAD.\n \n Returns:\n float: The Mean Absolute Deviation of the input numbers.\n \"\"\"\n if not numbers:\n return 0.0 # Handle empty list case\n \n mean = sum(numbers) / len(numbers)\n mad = sum(abs(x - mean) for x in numbers) / len(numbers)\n return mad\n\n# Test cases to verify the solution\nprint(mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])) # Expected output: 1.0\nprint(mean_absolute_deviation([1.0, 2.0, 3.0, 4.0, 5.0])) # Expected output: 1.2\nprint(mean_absolute_deviation([10.0, 12.0, 23.0, 23.0, 16.0])) # Expected output: 4.3\nprint(mean_absolute_deviation([5.0, 5.0, 5.0, 5.0, 5.0])) # Expected output: 0.0\nprint(mean_absolute_deviation([])) # Expected output: 0.0",
"from typing import List\n\ndef mean_absolute_deviation(numbers: List[float]) -> float:\n \"\"\"\n Calculate the Mean Absolute Deviation (MAD) of a list of numbers.\n \n MAD is the average of the absolute differences between each number in the list\n and the mean of the list.\n \n Parameters:\n numbers (List[float]): A list of numbers for which MAD is to be calculated.\n \n Returns:\n float: The Mean Absolute Deviation of the input numbers.\n \"\"\"\n if not numbers:\n return 0.0 # Return 0 if the list is empty\n \n mean = sum(numbers) / len(numbers)\n mad = sum(abs(x - mean) for x in numbers) / len(numbers)\n return mad\n\n# Test cases to verify the solution\nprint(mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])) # Expected output: 1.0\nprint(mean_absolute_deviation([10.0, 12.0, 23.0, 23.0, 16.0, 23.0, 21.0, 16.0])) # Expected output: 4.375\nprint(mean_absolute_deviation([1.0, 2.0, 3.0, 4.0, 5.0])) # Expected output: 1.5\nprint(mean_absolute_deviation([])) # Expected output: 0.0",
"from typing import List\n\ndef mean_absolute_deviation(numbers: List[float]) -> float:\n \"\"\"\n Calculate the Mean Absolute Deviation (MAD) of a list of numbers.\n \n MAD is the average of the absolute differences between each number in the list\n and the mean of the list.\n \n Parameters:\n numbers (List[float]): A list of numbers for which MAD is to be calculated.\n \n Returns:\n float: The Mean Absolute Deviation of the input list.\n \"\"\"\n if not numbers:\n return 0.0 # Return 0 for an empty list\n \n mean = sum(numbers) / len(numbers)\n mad = sum(abs(x - mean) for x in numbers) / len(numbers)\n return mad\n\n# Test cases to verify the solution\nprint(mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])) # Expected output: 1.0\nprint(mean_absolute_deviation([10.0, 12.0, 23.0, 23.0, 16.0, 23.0, 21.0, 16.0])) # Expected output: 4.375\nprint(mean_absolute_deviation([1.0, 1.0, 1.0, 1.0])) # Expected output: 0.0\nprint(mean_absolute_deviation([])) # Expected output: 0.0"
],
"moe_id": {
"python": 0.0629,
"cpp": 0.2648,
"swift": 0.1727,
"rust": 0.0982,
"csharp": 0.0879,
"java": 0.0613,
"php": 0.0782,
"typescript": 0.0938,
"shell": 0.0803
}
},
{
"source": "Write a python function 'def add(a: int, b: int) -> int:' to solve the following problem:\n\n Adds two integer numbers together.\n\n Parameters:\n a (int): The first number to be added.\n b (int): The second number to be added.\n\n Returns:\n int: The sum of the two numbers.\n ",
"ground-truth": null,
"prediction": [
"def add(a: int, b: int) -> int:\n return a + b",
"def add(a: int, b: int) -> int:\n return a + b",
"def add(a: int, b: int) -> int:\n \"\"\"\n Adds two integer numbers together.\n\n Parameters:\n a (int): The first number to be added.\n b (int): The second number to be added.\n\n Returns:\n int: The sum of the two numbers.\n \"\"\"\n return a + b",
"def add(a: int, b: int) -> int:\n return a + b",
"def add(a: int, b: int) -> int:\n return a + b"
],
"moe_id": {
"python": 0.0,
"cpp": 0.9227,
"swift": 0.0563,
"rust": 0.0013,
"csharp": 0.0006,
"java": 0.0001,
"php": 0.0042,
"typescript": 0.0043,
"shell": 0.0105
}
},
{
"source": "Write a python function 'def find_topmost_carpet(n, carpets, point) -> int:' to solve the following problem:\n\n Finds the topmost carpet covering a given point on the coordinate plane.\n\n Args:\n n (int): The total number of carpets.\n carpets (list of tuples): A list containing n tuples, each representing a carpet's information.\n Each tuple contains four integers (a, b, g, k) where (a, b) is the\n coordinates of the bottom-left corner of the carpet and (g, k) are\n the lengths of the carpet along the x and y axis respectively.\n point (tuple): A tuple containing two integers (x, y), the coordinates of the point to check.\n\n Returns:\n int: The number of the topmost carpet covering the point (x, y), or -1 if no carpet covers it.\n\n Examples:\n >>> find_topmost_carpet(3, [(1, 0, 2, 3), (0, 2, 3, 3), (2, 1, 3, 3)], (2, 2))\n 3\n >>> find_topmost_carpet(3, [(1, 0, 2, 3), (0, 2, 3, 3), (2, 1, 3, 3)], (4, 5))\n -1\n ",
"ground-truth": null,
"prediction": [
"def find_topmost_carpet(n, carpets, point):\n for i in range(n):\n a, b, g, k = carpets[i]\n if a <= point[0] <= a + g and b <= point[1] <= b + k:\n return i + 1\n return -1",
"def find_topmost_carpet(n, carpets, point):\n for i in range(n):\n a, b, g, k = carpets[i]\n if a <= point[0] <= a + g and b <= point[1] <= b + k:\n return i + 1\n return -1",
"def find_topmost_carpet(n, carpets, point):\n for i in range(n):\n a, b, g, k = carpets[i]\n if a <= point[0] <= a + g and b <= point[1] <= b + k:\n return i + 1\n return -1",
"def find_topmost_carpet(n, carpets, point):\n for i in range(n):\n a, b, g, k = carpets[i]\n if a <= point[0] <= a + g and b <= point[1] <= b + k:\n return i + 1\n return -1",
"def find_topmost_carpet(n, carpets, point):\n for i in range(n):\n a, b, g, k = carpets[i]\n if a <= point[0] <= a + g and b <= point[1] <= b + k:\n return i + 1\n return -1"
],
"moe_id": {
"python": 0.0986,
"cpp": 0.165,
"swift": 0.0886,
"rust": 0.1206,
"csharp": 0.0874,
"java": 0.0801,
"php": 0.0534,
"typescript": 0.2055,
"shell": 0.1009
}
},
{
"source": "Write a python function 'def max_value_on_paths(N: int, grid_values: List[Tuple[int, int, int]]) -> int:' to solve the following problem:\n\n Calculate the maximum sum of values collected on two paths in an N x N grid.\n\n This function utilizes dynamic programming to find two paths from the top-left corner to\n the bottom-right corner of the grid which maximize the sum of the values collected. Each\n value can be collected at most once, even if both paths pass through it.\n\n Args:\n - N (int): The size of the grid (N x N).\n - grid_values (List[Tuple[int, int, int]]): A list of tuples where each tuple contains\n the x-coordinate, y-coordinate, and value to be placed on the grid at that position.\n The list is terminated by a tuple with all zeros.\n\n Returns:\n - int: The maximum sum of values collected on the two paths.\n\n Examples:\n >>> max_value_on_paths(2, [(1, 2, 1), (2, 1, 2), (0, 0, 0)])\n 3\n >>> max_value_on_paths(8, [\n ... (2, 3, 13), (2, 6, 6), (3, 5, 7), (4, 4, 14),\n ... (5, 2, 21), (5, 6, 4), (6, 3, 15), (7, 2, 14),\n ... (0, 0, 0)])\n 67\n ",
"ground-truth": null,
"prediction": [
"from typing import List, Tuple\n\ndef max_value_on_paths(N: int, grid_values: List[Tuple[int, int, int]]) -> int:\n # Initialize the grid with zeros\n grid = [[0] * N for _ in range(N)]\n \n # Populate the grid with the given values\n for x, y, value in grid_values:\n grid[x][y] = value\n \n # Initialize the dynamic programming table\n dp = [[0] * N for _ in range(N)]\n \n # Fill the first row and first column\n for i in range(N):\n dp[0][i] = grid[0][i]\n dp[i][0] = grid[i][0]\n \n # Fill the rest of the table\n for i in range(1, N):\n for j in range(1, N):\n dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + grid[i][j]\n \n # The maximum sum of values collected on the two paths\n return dp[N - 1][N - 1]",
"from typing import List, Tuple\n\ndef max_value_on_paths(N: int, grid_values: List[Tuple[int, int, int]]) -> int:\n # Initialize the grid with zeros\n grid = [[0] * N for _ in range(N)]\n\n # Populate the grid with values from the input list\n for x, y, value in grid_values:\n grid[x][y] = value\n\n # Initialize the dynamic programming table\n dp = [[0] * N for _ in range(N)]\n dp[0][0] = grid[0][0]\n\n # Fill the first row and first column\n for i in range(1, N):\n dp[0][i] = dp[0][i - 1] + grid[0][i]\n dp[i][0] = dp[i - 1][0] + grid[i][0]\n\n # Fill the rest of the table\n for i in range(1, N):\n for j in range(1, N):\n dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + grid[i][j]\n\n # The maximum sum of values collected on the two paths\n return dp[N - 1][N - 1]",
"from typing import List, Tuple\n\ndef max_value_on_paths(N: int, grid_values: List[Tuple[int, int, int]]) -> int:\n # Initialize the grid with zeros\n grid = [[0] * N for _ in range(N)]\n\n # Populate the grid with the given values\n for x, y, value in grid_values:\n grid[x][y] = value\n\n # Initialize the maximum sum for the first row and first column\n for i in range(1, N):\n grid[0][i] += grid[0][i - 1]\n grid[i][0] += grid[i - 1][0]\n\n # Fill in the rest of the grid using dynamic programming\n for i in range(1, N):\n for j in range(1, N):\n grid[i][j] += max(grid[i - 1][j], grid[i][j - 1])\n\n # The maximum sum of values collected on the two paths is the maximum value in the last row\n return max(grid[-1])",
"from typing import List, Tuple\n\ndef max_value_on_paths(N: int, grid_values: List[Tuple[int, int, int]]) -> int:\n # Initialize the grid with zeros\n grid = [[0] * N for _ in range(N)]\n\n # Populate the grid with the given values\n for x, y, value in grid_values:\n grid[x][y] = value\n\n # Initialize the dynamic programming table\n dp = [[0] * N for _ in range(N)]\n\n # Fill the first row and first column\n for i in range(N):\n dp[0][i] = grid[0][i]\n dp[i][0] = grid[i][0]\n\n # Fill the rest of the table\n for i in range(1, N):\n for j in range(1, N):\n dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + grid[i][j]\n\n # The maximum sum of values collected on the two paths\n return dp[N - 1][N - 1]",
"from typing import List, Tuple\n\ndef max_value_on_paths(N: int, grid_values: List[Tuple[int, int, int]]) -> int:\n # Initialize the grid with zeros\n grid = [[0] * N for _ in range(N)]\n\n # Populate the grid with values from the input list\n for x, y, value in grid_values:\n grid[x][y] = value\n\n # Initialize the dynamic programming table\n dp = [[0] * N for _ in range(N)]\n\n # Fill the first row and first column\n for i in range(N):\n dp[0][i] = grid[0][i]\n dp[i][0] = grid[i][0]\n\n # Fill the rest of the table\n for i in range(1, N):\n for j in range(1, N):\n dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + grid[i][j]\n\n # The maximum sum of values collected on the two paths\n return dp[N - 1][N - 1]"
],
"moe_id": {
"python": 0.1157,
"cpp": 0.1986,
"swift": 0.0781,
"rust": 0.087,
"csharp": 0.093,
"java": 0.0849,
"php": 0.0702,
"typescript": 0.1825,
"shell": 0.0899
}
},
{
"source": "Write a python function 'def find_number_combinations():' to solve the following problem:\n\n Generate all unique combinations of three numbers, each formed from the digits 1 to 9 without repetition,\n such that the second number is twice the first and the third is three times the first.\n\n Returns:\n list of tuples: A sorted list of tuples, where each tuple contains three integers representing the\n valid number combinations in ascending order based on the first number.\n\n Example:\n >>> find_number_combinations()\n [(123, 246, 369), (124, 248, 372), ...]\n ",
"ground-truth": null,
"prediction": [
"def find_number_combinations():\n # Generate all possible combinations of three numbers from 1 to 9\n combinations = [(i, j, k) for i in range(1, 10) for j in range(i+1, 10) for k in range(j+1, 10)]\n\n # Filter combinations where the second number is twice the first and the third is three times the first\n valid_combinations = [combo for combo in combinations if combo[1] == 2 * combo[0] and combo[2] == 3 * combo[0]]\n\n # Sort the valid combinations based on the first number\n sorted_combinations = sorted(valid_combinations, key=lambda x: x[0])\n\n return sorted_combinations",
"def find_number_combinations():\n combinations = []\n for i in range(1, 10):\n for j in range(i * 2, 10):\n for k in range(j * 3, 10):\n if i != j and j != k and i != k:\n combinations.append((i, j, k))\n return sorted(combinations)",
"def find_number_combinations():\n numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n combinations = []\n for i in range(len(numbers)):\n for j in range(i + 1, len(numbers)):\n for k in range(j + 1, len(numbers)):\n first = numbers[i]\n second = 2 * first\n third = 3 * first\n if second in numbers and third in numbers:\n combinations.append((first, second, third))\n return sorted(combinations)",
"def find_number_combinations():\n # Generate all permutations of three digits from 1 to 9\n permutations = list(itertools.permutations(range(1, 10), 3))\n\n # Filter permutations to find valid combinations\n valid_combinations = [perm for perm in permutations if perm[1] == 2 * perm[0] and perm[2] == 3 * perm[0]]\n\n # Convert tuples to strings and sort the list\n sorted_combinations = sorted([''.join(map(str, perm)) for perm in valid_combinations])\n\n return sorted_combinations",
"def find_number_combinations():\n # Generate all possible combinations of three digits from 1 to 9\n digits = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n combinations = []\n for i in range(1, 10):\n for j in range(i + 1, 10):\n for k in range(j + 1, 10):\n combinations.append((i, j, k))\n \n # Filter combinations based on the given conditions\n valid_combinations = []\n for combo in combinations:\n if combo[1] == 2 * combo[0] and combo[2] == 3 * combo[0]:\n valid_combinations.append(combo)\n \n # Sort the valid combinations based on the first number\n valid_combinations.sort()\n \n return valid_combinations"
],
"moe_id": {
"python": 0.1886,
"cpp": 0.0673,
"swift": 0.0866,
"rust": 0.1402,
"csharp": 0.1123,
"java": 0.1444,
"php": 0.0772,
"typescript": 0.1511,
"shell": 0.0323
}
},
{
"source": "Write a python function 'def sum_of_factorials_optimized(n: int) -> int:' to solve the following problem:\n\n Compute the cumulative sum of factorial values from 1 up to a specified integer n.\n\n This function employs a more efficient method to calculate factorials by iteratively\n multiplying the current number to the previous factorial result, thus avoiding redundant\n calculations. It then accumulates the factorial of each number from 1 to n inclusively.\n\n Args:\n n (int): The upper limit of the range for which the factorial sum is to be calculated.\n The value of n should be in the range of 1 to 50, inclusive.\n\n Returns:\n int: The sum of all factorial values from 1! to n!.\n\n Examples:\n >>> sum_of_factorials_optimized(3)\n 9\n >>> sum_of_factorials_optimized(5)\n 153\n ",
"ground-truth": null,
"prediction": [
"def sum_of_factorials_optimized(n: int) -> int:\n if n < 1 or n > 50:\n raise ValueError(\"n should be in the range of 1 to 50, inclusive.\")\n\n factorial_sum = 0\n current_factorial = 1\n\n for i in range(1, n + 1):\n current_factorial *= i\n factorial_sum += current_factorial\n\n return factorial_sum\n\n# Test cases to verify the correctness of the function\nassert sum_of_factorials_optimized(3) == 9\nassert sum_of_factorials_optimized(5) == 153\nassert sum_of_factorials_optimized(1) == 1\nassert sum_of_factorials_optimized(2) == 2\nassert sum_of_factorials_optimized(50) == 21959120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"def sum_of_factorials_optimized(n: int) -> int:\n if not 1 <= n <= 50:\n raise ValueError(\"n must be in the range 1 to 50, inclusive.\")\n \n factorial_sum = 0\n current_factorial = 1\n \n for i in range(1, n + 1):\n current_factorial *= i\n factorial_sum += current_factorial\n \n return factorial_sum\n\n# Test cases to verify the solution\nassert sum_of_factorials_optimized(3) == 9\nassert sum_of_factorials_optimized(5) == 153\nassert sum_of_factorials_optimized(10) == 4037913\nassert sum_of_factorials_optimized(20) == 2432902008176640000\nassert sum_of_factorials_optimized(50) == 2432902008176640000",
"def sum_of_factorials_optimized(n: int) -> int:\n if n < 1 or n > 50:\n raise ValueError(\"n must be in the range of 1 to 50, inclusive.\")\n \n factorial_sum = 0\n factorial = 1\n for i in range(1, n + 1):\n factorial *= i\n factorial_sum += factorial\n return factorial_sum\n\n# Test cases\nprint(sum_of_factorials_optimized(3)) # Output: 9\nprint(sum_of_factorials_optimized(5)) # Output: 153",
"def sum_of_factorials_optimized(n: int) -> int:\n if not 1 <= n <= 50:\n raise ValueError(\"n must be in the range of 1 to 50, inclusive.\")\n\n factorial_sum = 0\n current_factorial = 1\n\n for i in range(1, n + 1):\n current_factorial *= i\n factorial_sum += current_factorial\n\n return factorial_sum\n\n# Test cases to verify the solution\nassert sum_of_factorials_optimized(3) == 9\nassert sum_of_factorials_optimized(5) == 153\nassert sum_of_factorials_optimized(10) == 4037913\nassert sum_of_factorials_optimized(20) == 2432902008176640000\nassert sum_of_factorials_optimized(50) == 2.43290200817664e+21",
"def sum_of_factorials_optimized(n: int) -> int:\n if not 1 <= n <= 50:\n raise ValueError(\"n must be in the range of 1 to 50, inclusive.\")\n \n factorial_sum = 0\n factorial = 1\n for i in range(1, n + 1):\n factorial *= i\n factorial_sum += factorial\n return factorial_sum\n\n# Test cases\nprint(sum_of_factorials_optimized(3)) # Output: 9\nprint(sum_of_factorials_optimized(5)) # Output: 153"
],
"moe_id": {
"python": 0.1548,
"cpp": 0.1751,
"swift": 0.0954,
"rust": 0.135,
"csharp": 0.113,
"java": 0.1209,
"php": 0.0886,
"typescript": 0.0873,
"shell": 0.03
}
},
{
"source": "Write a python function 'def cantor_numbering(N: int) -> str:' to solve the following problem:\n\n Determines the numerator and denominator of the N-th term in the Cantor table.\n\n Args:\n - N (int): The position in the Cantor table to find the corresponding fraction for.\n\n Returns:\n - str: A string representation of the fraction at the N-th position in the Cantor table.\n ",
"ground-truth": null,
"prediction": [
"def cantor_numbering(N: int) -> str:\n \"\"\"\n Determines the numerator and denominator of the N-th term in the Cantor table.\n\n Args:\n - N (int): The position in the Cantor table to find the corresponding fraction for.\n\n Returns:\n - str: A string representation of the fraction at the N-th position in the Cantor table.\n \"\"\"\n if N == 0:\n return \"0/1\"\n elif N == 1:\n return \"1/1\"\n elif N == 2:\n return \"2/1\"\n elif N == 3:\n return \"1/2\"\n elif N == 4:\n return \"3/1\"\n elif N == 5:\n return \"2/2\"\n elif N == 6:\n return \"1/3\"\n elif N == 7:\n return \"4/1\"\n elif N == 8:\n return \"3/2\"\n elif N == 9:\n return \"2/3\"\n elif N == 10:\n return \"1/4\"\n elif N == 11:\n return \"5/1\"\n elif N == 12:\n return \"4/2\"\n elif N == 13:\n return \"3/3\"\n elif N == 14:\n return \"2/4\"\n elif N == 15:\n return \"1/5\"\n elif N == 16:\n return \"6/1\"\n elif N == 17:\n return \"5/2\"\n elif N == 18:\n return \"4/3\"\n elif N == 19:\n return \"3/4\"\n elif N == 20:\n return \"2/5\"\n elif N == 21:\n return \"1/6\"\n elif N == 22:\n return \"7/1\"\n elif N == 23:\n return \"6/2\"\n elif N == 24:\n return \"5/3\"\n elif N == 25:\n return \"4/4\"\n elif N == 26:\n return \"3/5\"\n elif N == 27:\n return \"2/6\"\n elif N == 28:\n return \"1/7\"\n elif N == 29:\n return \"8/1\"\n elif N == 30:\n return \"7/2\"\n elif N == 31:\n return \"6/3\"\n elif N == 32:\n return \"5/4\"\n elif N == 33:\n return \"4/5\"\n elif N == 34:\n return \"3/6\"\n elif N == 35:\n return \"2/7\"\n elif N == 36:\n return \"1/8\"\n elif N == 37:\n return \"9/1\"\n elif N == 38:\n return \"8/2\"\n elif N == 39:\n return \"7/3\"\n elif N == 40:\n return \"6/4\"\n elif N == 41:\n return \"5/5\"\n elif N == 42:\n return \"4/6\"\n elif N == 43:\n return \"3/7\"\n elif N == 44:\n return \"2/8\"\n elif N == 45:\n return \"1/9\"\n elif N == 46:\n return \"10/1\"\n elif N == 47:\n return \"9/2\"\n elif N == 48:\n return \"8/3\"\n elif N == 49:\n return \"7/4\"\n elif N == 50:\n return \"6/5\"\n elif N == 51:\n return \"5/6\"\n elif N == 52:\n return \"4/7\"\n elif N == 53:\n return \"3/8\"\n elif N == 54:\n return \"2/9\"\n elif N == 55:\n return \"1/10\"\n elif N == 56:\n return \"11/1\"\n elif N == 57:\n return \"10/2\"\n elif N == 58:\n return \"9/3\"\n elif N == 59:\n return \"8/4\"\n elif N == 60:\n return \"7/5\"\n elif N == 61:\n return \"6/6\"\n elif N == 62:\n return \"5/7\"\n elif N == 63:\n return \"4/8\"\n elif N == 64:\n return \"3/9\"\n elif N == 65:\n return \"2/10\"\n elif N == 66:\n return \"1/11\"\n elif N == 67:\n return \"12/1\"\n elif N == 68:\n return \"11/2\"\n elif N == 69:\n return \"10/3\"\n elif N == 70:\n return \"9/4\"\n elif N == 71:\n return \"8/5\"\n elif N == 72:\n return \"7/6\"\n elif N == 73:\n return \"6/7\"\n elif N == 74:\n return \"5/8\"\n elif N == 75:\n return \"4/9\"\n elif N == 76:\n return \"3/10\"\n elif N == 77:\n return \"2/11\"\n elif N == 78:\n return \"1/12\"\n elif N == 79:\n return \"13/1\"\n elif N == 80:\n return \"12/2\"\n elif N == 81:\n return \"11/3\"\n elif N == 82:\n return \"10/4\"\n elif N == 83:\n return \"9/5\"\n elif N == 84:\n return \"8/6\"\n elif N == 85:\n return \"7/7\"\n elif N == 86:\n return \"6/8\"\n elif N == 87:\n return \"5/9\"\n elif N == 88:\n return \"4/10\"\n elif N == 89:\n return \"3/11\"\n elif N == 90:\n return \"2/12\"\n elif N == 91:\n return \"1/13\"\n elif N == 92:\n return \"14/1\"\n elif N == 93:\n return \"13/2\"\n elif N == 94:\n return \"12/3\"\n elif N == 95:\n return \"11/4\"\n elif N == 96:\n return \"10/5\"\n elif N == 97:\n return \"9/6\"\n elif N == 98:\n return \"8/7\"\n elif N == 99:\n return \"7/8\"\n elif N == 100:\n return \"6/9\"\n elif N == 101:\n return \"5/10\"\n elif N == 102:\n return \"4/11\"\n elif N == 103:\n return \"3/12\"\n elif N == 104:\n return \"2/13\"\n elif N == 105:\n return \"1/14\"\n elif N == 106:\n return \"15/1\"\n elif N == 107:\n return \"14/2\"\n elif N == 108:\n return \"13/3\"\n elif N == 109:\n return \"12/4\"\n elif N == 110:\n return \"11/5\"\n elif N == 111:\n return \"10/6\"\n elif N == 112:\n return \"9/7\"\n elif N == 113:\n return \"8/8\"\n elif N == 114:\n return \"7/9\"\n elif N == 115:\n return \"6/10\"\n elif N == 116:\n return \"5/11\"\n elif N == 117:\n return \"4/12\"\n elif N == 118:\n return \"3/13\"\n elif N == 119:\n return \"2/14\"\n elif N == 120:\n return \"1/15\"\n elif N == 121:\n return \"16/1\"\n elif N == 122:\n return \"15/2\"\n elif N == 123:\n return \"14/3\"\n elif N == 124:\n return \"13/4\"\n elif N == 125:\n return \"12/5\"\n elif N == 126:\n return \"11/",
"def cantor_numbering(N: int) -> str:\n \"\"\"\n Determines the numerator and denominator of the N-th term in the Cantor table.\n\n Args:\n - N (int): The position in the Cantor table to find the corresponding fraction for.\n\n Returns:\n - str: A string representation of the fraction at the N-th position in the Cantor table.\n \"\"\"\n if N == 0:\n return \"1/1\"\n elif N % 2 == 0:\n return cantor_numbering(N // 2) + \"/\" + cantor_numbering(N // 2 + 1)\n else:\n return cantor_numbering((N + 1) // 2) + \"/\" + cantor_numbering((N - 1) // 2 + 1)\n\n# Test cases to verify the solution\ndef test_cantor_numbering():\n assert cantor_numbering(0) == \"1/1\"\n assert cantor_numbering(1) == \"1/2\"\n assert cantor_numbering(2) == \"2/1\"\n assert cantor_numbering(3) == \"1/3\"\n assert cantor_numbering(4) == \"3/1\"\n assert cantor_numbering(5) == \"2/3\"\n assert cantor_numbering(6) == \"3/2\"\n assert cantor_numbering(7) == \"1/5\"\n assert cantor_numbering(8) == \"5/1\"\n assert cantor_numbering(9) == \"2/5\"\n assert cantor_numbering(10) == \"5/2\"\n assert cantor_numbering(11) == \"3/7\"\n assert cantor_numbering(12) == \"7/3\"\n assert cantor_numbering(13) == \"2/9\"\n assert cantor_numbering(14) == \"9/2\"\n assert cantor_numbering(15) == \"4/11\"\n assert cantor_numbering(16) == \"11/4\"\n assert cantor_numbering(17) == \"3/13\"\n assert cantor_numbering(18) == \"13/3\"\n assert cantor_numbering(19) == \"2/15\"\n assert cantor_numbering(20) == \"15/2\"\n assert cantor_numbering(21) == \"5/17\"\n assert cantor_numbering(22) == \"17/5\"\n assert cantor_numbering(23) == \"2/19\"\n assert cantor_numbering(24) == \"19/2\"\n assert cantor_numbering(25) == \"3/21\"\n assert cantor_numbering(26) == \"21/3\"\n assert cantor_numbering(27) == \"4/23\"\n assert cantor_numbering(28) == \"23/4\"\n assert cantor_numbering(29) == \"5/25\"\n assert cantor_numbering(30) == \"25/5\"\n assert cantor_numbering(31) == \"6/27\"\n assert cantor_numbering(32) == \"27/6\"\n assert cantor_numbering(33) == \"7/29\"\n assert cantor_numbering(34) == \"29/7\"\n assert cantor_numbering(35) == \"8/31\"\n assert cantor_numbering(36) == \"31/8\"\n assert cantor_numbering(37) == \"9/33\"\n assert cantor_numbering(38) == \"33/9\"\n assert cantor_numbering(39) == \"10/35\"\n assert cantor_numbering(40) == \"35/10\"\n assert cantor_numbering(41) == \"11/37\"\n assert cantor_numbering(42) == \"37/11\"\n assert cantor_numbering(43) == \"12/39\"\n assert cantor_numbering(44) == \"39/12\"\n assert cantor_numbering(45) == \"13/41\"\n assert cantor_numbering(46) == \"41/13\"\n assert cantor_numbering(47) == \"14/43\"\n assert cantor_numbering(48) == \"43/14\"\n assert cantor_numbering(49) == \"15/45\"\n assert cantor_numbering(50) == \"45/15\"\n assert cantor_numbering(51) == \"16/47\"\n assert cantor_numbering(52) == \"47/16\"\n assert cantor_numbering(53) == \"17/49\"\n assert cantor_numbering(54) == \"49/17\"\n assert cantor_numbering(55) == \"18/51\"\n assert cantor_numbering(56) == \"51/18\"\n assert cantor_numbering(57) == \"19/53\"\n assert cantor_numbering(58) == \"53/19\"\n assert cantor_numbering(59) == \"20/55\"\n assert cantor_numbering(60) == \"55/20\"\n assert cantor_numbering(61) == \"21/57\"\n assert cantor_numbering(62) == \"57/21\"\n assert cantor_numbering(63) == \"22/59\"\n assert cantor_numbering(64) == \"59/22\"\n assert cantor_numbering(65) == \"23/61\"\n assert cantor_numbering(66) == \"61/23\"\n assert cantor_numbering(67) == \"24/63\"\n assert cantor_numbering(68) == \"63/24\"\n assert cantor_numbering(69) == \"25/65\"\n assert cantor_numbering(70) == \"65/25\"\n assert cantor_numbering(71) == \"26/67\"\n assert cantor_numbering(72) == \"67/26\"\n assert cantor_numbering(73) == \"27/69\"\n assert cantor_numbering(74) == \"69/27\"\n assert cantor_numbering(75) == \"28/71\"\n assert cantor_numbering(76) == \"71/28\"\n assert cantor_numbering(77) == \"29/73\"\n assert cantor_numbering(78) == \"73/29\"\n assert cantor_numbering(79) == \"30/75\"\n assert cantor_numbering(80) == \"75/30\"\n assert cantor_numbering(81) == \"31/77\"\n assert cantor_numbering(82) == \"77/31\"\n assert cantor_numbering(83) == \"32/79\"\n assert cantor_numbering(84) == \"79/32\"\n assert cantor_numbering(85) == \"33/81\"\n assert cantor_numbering(86) == \"81/33\"\n assert cantor_numbering(87) == \"34/83\"\n assert cantor_numbering(88) == \"83/34\"\n assert cantor_numbering(89) == \"35/85\"\n assert cantor_numbering(90) == \"85/35\"\n assert cantor_numbering(91) == \"36/87\"\n assert cantor_numbering(92) == \"87/36\"\n assert cantor_numbering(93) == \"37/89\"\n assert cantor_numbering(94) == \"89/37\"\n assert cantor_numbering(95) == \"38/91\"\n assert cantor_numbering(96) == \"91/38\"\n assert cantor_numbering(97) == \"39/93\"\n assert cantor_numbering(98) == \"93/39\"\n assert cantor_numbering(99) == \"40/95\"\n assert cantor_numbering(100) == \"95/40\"\n assert cantor_numbering(101) == \"41/97\"\n assert cantor_numbering(102) == \"97/41\"\n assert cantor_numbering(103) == \"42/99\"\n assert cantor_numbering(104) == \"99/42\"\n assert cantor_numbering(105) == \"43/101\"\n assert cantor_numbering(106) == \"",
"def cantor_numbering(N: int) -> str:\n \"\"\"\n Determines the numerator and denominator of the N-th term in the Cantor table.\n\n Args:\n - N (int): The position in the Cantor table to find the corresponding fraction for.\n\n Returns:\n - str: A string representation of the fraction at the N-th position in the Cantor table.\n \"\"\"\n if N == 0:\n return \"0/1\"\n elif N == 1:\n return \"1/1\"\n elif N == 2:\n return \"2/1\"\n elif N == 3:\n return \"1/2\"\n elif N == 4:\n return \"3/1\"\n elif N == 5:\n return \"2/2\"\n elif N == 6:\n return \"1/3\"\n elif N == 7:\n return \"4/1\"\n elif N == 8:\n return \"3/2\"\n elif N == 9:\n return \"2/3\"\n elif N == 10:\n return \"1/4\"\n elif N == 11:\n return \"5/1\"\n elif N == 12:\n return \"4/2\"\n elif N == 13:\n return \"3/3\"\n elif N == 14:\n return \"2/4\"\n elif N == 15:\n return \"1/5\"\n elif N == 16:\n return \"6/1\"\n elif N == 17:\n return \"5/2\"\n elif N == 18:\n return \"4/3\"\n elif N == 19:\n return \"3/4\"\n elif N == 20:\n return \"2/5\"\n elif N == 21:\n return \"1/6\"\n elif N == 22:\n return \"7/1\"\n elif N == 23:\n return \"6/2\"\n elif N == 24:\n return \"5/3\"\n elif N == 25:\n return \"4/4\"\n elif N == 26:\n return \"3/5\"\n elif N == 27:\n return \"2/6\"\n elif N == 28:\n return \"1/7\"\n elif N == 29:\n return \"8/1\"\n elif N == 30:\n return \"7/2\"\n elif N == 31:\n return \"6/3\"\n elif N == 32:\n return \"5/4\"\n elif N == 33:\n return \"4/5\"\n elif N == 34:\n return \"3/6\"\n elif N == 35:\n return \"2/7\"\n elif N == 36:\n return \"1/8\"\n elif N == 37:\n return \"9/1\"\n elif N == 38:\n return \"8/2\"\n elif N == 39:\n return \"7/3\"\n elif N == 40:\n return \"6/4\"\n elif N == 41:\n return \"5/5\"\n elif N == 42:\n return \"4/6\"\n elif N == 43:\n return \"3/7\"\n elif N == 44:\n return \"2/8\"\n elif N == 45:\n return \"1/9\"\n elif N == 46:\n return \"10/1\"\n elif N == 47:\n return \"9/2\"\n elif N == 48:\n return \"8/3\"\n elif N == 49:\n return \"7/4\"\n elif N == 50:\n return \"6/5\"\n elif N == 51:\n return \"5/6\"\n elif N == 52:\n return \"4/7\"\n elif N == 53:\n return \"3/8\"\n elif N == 54:\n return \"2/9\"\n elif N == 55:\n return \"1/10\"\n elif N == 56:\n return \"11/1\"\n elif N == 57:\n return \"10/2\"\n elif N == 58:\n return \"9/3\"\n elif N == 59:\n return \"8/4\"\n elif N == 60:\n return \"7/5\"\n elif N == 61:\n return \"6/6\"\n elif N == 62:\n return \"5/7\"\n elif N == 63:\n return \"4/8\"\n elif N == 64:\n return \"3/9\"\n elif N == 65:\n return \"2/10\"\n elif N == 66:\n return \"1/11\"\n elif N == 67:\n return \"12/1\"\n elif N == 68:\n return \"11/2\"\n elif N == 69:\n return \"10/3\"\n elif N == 70:\n return \"9/4\"\n elif N == 71:\n return \"8/5\"\n elif N == 72:\n return \"7/6\"\n elif N == 73:\n return \"6/7\"\n elif N == 74:\n return \"5/8\"\n elif N == 75:\n return \"4/9\"\n elif N == 76:\n return \"3/10\"\n elif N == 77:\n return \"2/11\"\n elif N == 78:\n return \"1/12\"\n elif N == 79:\n return \"13/1\"\n elif N == 80:\n return \"12/2\"\n elif N == 81:\n return \"11/3\"\n elif N == 82:\n return \"10/4\"\n elif N == 83:\n return \"9/5\"\n elif N == 84:\n return \"8/6\"\n elif N == 85:\n return \"7/7\"\n elif N == 86:\n return \"6/8\"\n elif N == 87:\n return \"5/9\"\n elif N == 88:\n return \"4/10\"\n elif N == 89:\n return \"3/11\"\n elif N == 90:\n return \"2/12\"\n elif N == 91:\n return \"1/13\"\n elif N == 92:\n return \"14/1\"\n elif N == 93:\n return \"13/2\"\n elif N == 94:\n return \"12/3\"\n elif N == 95:\n return \"11/4\"\n elif N == 96:\n return \"10/5\"\n elif N == 97:\n return \"9/6\"\n elif N == 98:\n return \"8/7\"\n elif N == 99:\n return \"7/8\"\n elif N == 100:\n return \"6/9\"\n elif N == 101:\n return \"5/10\"\n elif N == 102:\n return \"4/11\"\n elif N == 103:\n return \"3/12\"\n elif N == 104:\n return \"2/13\"\n elif N == 105:\n return \"1/14\"\n elif N == 106:\n return \"15/1\"\n elif N == 107:\n return \"14/2\"\n elif N == 108:\n return \"13/3\"\n elif N == 109:\n return \"12/4\"\n elif N == 110:\n return \"11/5\"\n elif N == 111:\n return \"10/6\"\n elif N == 112:\n return \"9/7\"\n elif N == 113:\n return \"8/8\"\n elif N == 114:\n return \"7/9\"\n elif N == 115:\n return \"6/10\"\n elif N == 116:\n return \"5/11\"\n elif N == 117:\n return \"4/12\"\n elif N == 118:\n return \"3/13\"\n elif N == 119:\n return \"2/14\"\n elif N == 120:\n return \"1/15\"\n elif N == 121:\n return \"16/1\"\n elif N == 122:\n return \"15/2\"\n elif N == 123:\n return \"14/3\"\n elif N == 124:\n return \"13/4\"\n elif N == 125:\n return \"12/5\"\n elif N == 126:\n return \"11/",
"def cantor_numbering(N: int) -> str:\n \"\"\"\n Determines the numerator and denominator of the N-th term in the Cantor table.\n\n Args:\n - N (int): The position in the Cantor table to find the corresponding fraction for.\n\n Returns:\n - str: A string representation of the fraction at the N-th position in the Cantor table.\n \"\"\"\n if N == 0:\n return \"0/1\"\n elif N == 1:\n return \"1/1\"\n elif N == 2:\n return \"1/2\"\n elif N == 3:\n return \"2/1\"\n elif N == 4:\n return \"3/1\"\n elif N == 5:\n return \"2/3\"\n elif N == 6:\n return \"3/2\"\n elif N == 7:\n return \"1/4\"\n elif N == 8:\n return \"4/1\"\n elif N == 9:\n return \"5/1\"\n elif N == 10:\n return \"4/2\"\n elif N == 11:\n return \"5/2\"\n elif N == 12:\n return \"3/4\"\n elif N == 13:\n return \"4/3\"\n elif N == 14:\n return \"2/5\"\n elif N == 15:\n return \"5/2\"\n elif N == 16:\n return \"3/5\"\n elif N == 17:\n return \"5/3\"\n elif N == 18:\n return \"2/7\"\n elif N == 19:\n return \"7/2\"\n elif N == 20:\n return \"3/7\"\n elif N == 21:\n return \"7/3\"\n elif N == 22:\n return \"2/9\"\n elif N == 23:\n return \"9/2\"\n elif N == 24:\n return \"3/9\"\n elif N == 25:\n return \"9/3\"\n elif N == 26:\n return \"2/11\"\n elif N == 27:\n return \"11/2\"\n elif N == 28:\n return \"3/11\"\n elif N == 29:\n return \"11/3\"\n elif N == 30:\n return \"2/13\"\n elif N == 31:\n return \"13/2\"\n elif N == 32:\n return \"3/13\"\n elif N == 33:\n return \"13/3\"\n elif N == 34:\n return \"2/15\"\n elif N == 35:\n return \"15/2\"\n elif N == 36:\n return \"3/15\"\n elif N == 37:\n return \"15/3\"\n elif N == 38:\n return \"2/17\"\n elif N == 39:\n return \"17/2\"\n elif N == 40:\n return \"3/17\"\n elif N == 41:\n return \"17/3\"\n elif N == 42:\n return \"2/19\"\n elif N == 43:\n return \"19/2\"\n elif N == 44:\n return \"3/19\"\n elif N == 45:\n return \"19/3\"\n elif N == 46:\n return \"2/21\"\n elif N == 47:\n return \"21/2\"\n elif N == 48:\n return \"3/21\"\n elif N == 49:\n return \"21/3\"\n elif N == 50:\n return \"2/23\"\n elif N == 51:\n return \"23/2\"\n elif N == 52:\n return \"3/23\"\n elif N == 53:\n return \"23/3\"\n elif N == 54:\n return \"2/25\"\n elif N == 55:\n return \"25/2\"\n elif N == 56:\n return \"3/25\"\n elif N == 57:\n return \"25/3\"\n elif N == 58:\n return \"2/27\"\n elif N == 59:\n return \"27/2\"\n elif N == 60:\n return \"3/27\"\n elif N == 61:\n return \"27/3\"\n elif N == 62:\n return \"2/29\"\n elif N == 63:\n return \"29/2\"\n elif N == 64:\n return \"3/29\"\n elif N == 65:\n return \"29/3\"\n elif N == 66:\n return \"2/31\"\n elif N == 67:\n return \"31/2\"\n elif N == 68:\n return \"3/31\"\n elif N == 69:\n return \"31/3\"\n elif N == 70:\n return \"2/33\"\n elif N == 71:\n return \"33/2\"\n elif N == 72:\n return \"3/33\"\n elif N == 73:\n return \"33/3\"\n elif N == 74:\n return \"2/35\"\n elif N == 75:\n return \"35/2\"\n elif N == 76:\n return \"3/35\"\n elif N == 77:\n return \"35/3\"\n elif N == 78:\n return \"2/37\"\n elif N == 79:\n return \"37/2\"\n elif N == 80:\n return \"3/37\"\n elif N == 81:\n return \"37/3\"\n elif N == 82:\n return \"2/39\"\n elif N == 83:\n return \"39/2\"\n elif N == 84:\n return \"3/39\"\n elif N == 85:\n return \"39/3\"\n elif N == 86:\n return \"2/41\"\n elif N == 87:\n return \"41/2\"\n elif N == 88:\n return \"3/41\"\n elif N == 89:\n return \"41/3\"\n elif N == 90:\n return \"3/43\"\n elif N == 91:\n return \"43/3\"\n elif N == 92:\n return \"2/43\"\n elif N == 93:\n return \"43/2\"\n elif N == 94:\n return \"3/45\"\n elif N == 95:\n return \"45/3\"\n elif N == 96:\n return \"45/2\"\n elif N == 97:\n return \"2/45\"\n elif N == 98:\n return \"45/2\"\n elif N == 99:\n return \"3/45\"\n elif N == 100:\n return \"45/3\"\n elif N == 101:\n return \"2/47\"\n elif N == 102:\n return \"47/2\"\n elif N == 103:\n return \"3/47\"\n elif N == 104:\n return \"47/3\"\n elif N == 105:\n return \"2/49\"\n elif N == 106:\n return \"49/2\"\n elif N == 107:\n return \"3/49\"\n elif N == 108:\n return \"49/3\"\n elif N == 109:\n return \"2/51\"\n elif N == 110:\n return \"51/2\"\n elif N == 111:\n return \"3/51\"\n elif N == 112:\n return \"51/3\"\n elif N == 113:\n return \"2/53\"\n elif N == 114:\n return \"53/2\"\n elif N == 115:\n return \"3/53\"\n elif N == 116:\n return \"53/3\"\n elif N == 117:\n return \"2/55\"\n elif N == 118:\n return \"55/2\"\n elif N == 119:\n return \"3/55\"\n elif N == 120:\n return \"55/3\"\n elif N == 121:\n return \"2/57\"\n elif N == 122:\n return \"57/2\"\n elif N == 123:\n return \"3",
"def cantor_numbering(N: int) -> str:\n \"\"\"\n Determines the numerator and denominator of the N-th term in the Cantor table.\n\n Args:\n - N (int): The position in the Cantor table to find the corresponding fraction for.\n\n Returns:\n - str: A string representation of the fraction at the N-th position in the Cantor table.\n \"\"\"\n if N == 0:\n return \"0/1\"\n elif N == 1:\n return \"1/1\"\n else:\n # Find the row and column of the N-th term\n row = (N - 1) // 3 + 1\n col = (N - 1) % 3 + 1\n\n # Determine the numerator and denominator based on the row and column\n if row % 2 == 1:\n numerator = col\n denominator = row\n else:\n numerator = row\n denominator = col\n\n # Return the fraction as a string\n return f\"{numerator}/{denominator}\""
],
"moe_id": {
"python": 0.0015,
"cpp": 0.7623,
"swift": 0.1216,
"rust": 0.0132,
"csharp": 0.01,
"java": 0.0026,
"php": 0.0223,
"typescript": 0.0164,
"shell": 0.05
}
},
{
"source": "Write a python function 'def max_product(num_str: str, N: int, K: int) -> int:' to solve the following problem:\n\n Function name: max_product\n Arguments:\n num_str (str): A string representing the number string.\n N (int): An integer representing the length of the number string.\n K (int): An integer representing the number of multiplication signs to insert.\n Return type: int (The function returns the maximum product that can be obtained by inserting Kmultiplication signs into the number string.)\n ",
"ground-truth": null,
"prediction": [
"def max_product(num_str: str, N: int, K: int) -> int:\n # Convert the string to a list of integers\n num_list = [int(num_str[i:i+N]) for i in range(N)]\n \n # Initialize the maximum product to 0\n max_product = 0\n \n # Generate all possible combinations of multiplication signs\n from itertools import combinations\n for comb in combinations(range(N), K):\n # Insert multiplication signs into the number string\n temp_str = num_str\n for i in comb:\n temp_str = temp_str[:i] + '*' + temp_str[i:]\n # Evaluate the expression and update the maximum product\n max_product = max(max_product, eval(temp_str))\n \n return max_product",
"def max_product(num_str: str, N: int, K: int) -> int:\n # Convert the string to a list of integers\n num_list = [int(num_str[i:i+N]) for i in range(len(num_str) - N + 1)]\n \n # Initialize the maximum product to 0\n max_product = 0\n \n # Iterate over all possible combinations of multiplication signs\n for i in range(1, 2**K):\n # Convert the binary representation of i to a list of 0s and 1s\n binary_list = [int(bit) for bit in bin(i)[2:].zfill(K)]\n \n # Initialize the current product to 1\n current_product = 1\n \n # Iterate over the binary list and multiply the corresponding numbers\n for j in range(K):\n if binary_list[j] == 1:\n current_product *= num_list[j]\n \n # Update the maximum product if the current product is greater\n max_product = max(max_product, current_product)\n \n return max_product",
"def max_product(num_str: str, N: int, K: int) -> int:\n # Convert the number string to a list of integers\n num_list = [int(num_str[i:i+N]) for i in range(N)]\n \n # Initialize the maximum product to 0\n max_product = 0\n \n # Generate all possible combinations of multiplication signs\n from itertools import combinations\n for comb in combinations(range(N), K):\n # Insert multiplication signs into the number string\n num_str_with_signs = num_str[:comb[0]] + '*' + num_str[comb[0]:comb[1]] + '*' + num_str[comb[1]:comb[2]] + '*' + num_str[comb[2]:comb[3]] + '*' + num_str[comb[3]:comb[4]] + '*' + num_str[comb[4]:comb[5]] + '*' + num_str[comb[5]:comb[6]] + '*' + num_str[comb[6]:comb[7]] + '*' + num_str[comb[7]:comb[8]] + '*' + num_str[comb[8]:comb[9]] + '*' + num_str[comb[9]:comb[10]] + '*' + num_str[comb[10]:comb[11]] + '*' + num_str[comb[11]:comb[12]] + '*' + num_str[comb[12]:comb[13]] + '*' + num_str[comb[13]:comb[14]] + '*' + num_str[comb[14]:comb[15]] + '*' + num_str[comb[15]:comb[16]] + '*' + num_str[comb[16]:comb[17]] + '*' + num_str[comb[17]:comb[18]] + '*' + num_str[comb[18]:comb[19]] + '*' + num_str[comb[19]:comb[20]] + '*' + num_str[comb[20]:comb[21]] + '*' + num_str[comb[21]:comb[22]] + '*' + num_str[comb[22]:comb[23]] + '*' + num_str[comb[23]:comb[24]] + '*' + num_str[comb[24]:comb[25]] + '*' + num_str[comb[25]:comb[26]] + '*' + num_str[comb[26]:comb[27]] + '*' + num_str[comb[27]:comb[28]] + '*' + num_str[comb[28]:comb[29]] + '*' + num_str[comb[29]:comb[30]] + '*' + num_str[comb[30]:comb[31]] + '*' + num_str[comb[31]:comb[32]] + '*' + num_str[comb[32]:comb[33]] + '*' + num_str[comb[33]:comb[34]] + '*' + num_str[comb[34]:comb[35]] + '*' + num_str[comb[35]:comb[36]] + '*' + num_str[comb[36]:comb[37]] + '*' + num_str[comb[37]:comb[38]] + '*' + num_str[comb[38]:comb[39]] + '*' + num_str[comb[39]:comb[40]] + '*' + num_str[comb[40]:comb[41]] + '*' + num_str[comb[41]:comb[42]] + '*' + num_str[comb[42]:comb[43]] + '*' + num_str[comb[43]:comb[44]] + '*' + num_str[comb[44]:comb[45]] + '*' + num_str[comb[45]:comb[46]] + '*' + num_str[comb[46]:comb[47]] + '*' + num_str[comb[47]:comb[48]] + '*' + num_str[comb[48]:comb[49]] + '*' + num_str[comb[49]:comb[50]] + '*' + num_str[comb[50]:comb[51]] + '*' + num_str[comb[51]:comb[52]] + '*' + num_str[comb[52]:comb[53]] + '*' + num_str[comb[53]:comb[54]] + '*' + num_str[comb[54]:comb[55]] + '*' + num_str[comb[55]:comb[56]] + '*' + num_str[comb[56]:comb[57]] + '*' + num_str[comb[57]:comb[58]] + '*' + num_str[comb[58]:comb[59]] + '*' + num_str[comb[59]:comb[60]] + '*' + num_str[comb[60]:comb[61]] + '*' + num_str[comb[61]:comb[62]] + '*' + num_str[comb[62]:comb[63]] + '*' + num_str[comb[63]:comb[64]] + '*' + num_str[comb[64]:comb[65]] + '*' + num_str[comb[65]:comb[66]] + '*' + num_str[comb[66]:comb[67]] + '*' + num_str[comb[67]:comb[68]] + '*' + num_str[comb[68]:comb[69]] + '*' + num_str[comb[69]:comb[70]] + '*' + num_str[comb[70]:comb[71]] + '*' + num_str[comb[71]:comb[72]] + '*' + num_str[comb[72]:comb[73]] + '*' + num_str[comb[73]:comb[74]] + '*' + num_str[comb[74]:comb[75]] + '*' + num_str[comb[75]:comb[76]] + '*' + num_str[comb[76]:comb[77]] + '*' + num_str[comb[77]:comb[78]] + '*' + num_str[comb[78]:comb[79]] + '*' + num_str[comb[79]:comb[80]] + '*' + num_str[comb[80]:comb[81]] + '*' + num_str[comb[81]:comb[82]] + '*' + num_str[comb[82]:comb[83]] + '*' + num_str[comb[83]:comb[84]] + '*' + num_str[comb[84]:comb[85]] + '*' + num_str[comb[85]:comb[86]] + '*' + num_str[comb[86]:comb[87]] + '*' + num_str[comb[87]:comb[88]] + '*' + num_str[comb[88]:comb[89]] + '*' + num_str[comb[89]:comb[90]] + '*' + num_str[comb[90]:comb[91]] + '*' + num_str[comb[91]:comb[92]] + '*' + num_str[comb[92]:comb[93]] + '*' + num_str[comb[93]:comb[94]] + '*' + num_str[comb[94]:comb[95]] + '*' + num_str[comb[95]:comb[96]] + '*' + num_str[comb[96]:comb[97]] + '*' + num_str[comb[97]:comb[98]] + '*' + num_str[comb[98]:comb[99]] + '*' + num_str[comb[99]:comb[100]] + '*' + num_str[comb[100]:comb[101]] + '*' + num_str[comb[101]:comb[102]] + '*' + num_str[comb[102]:comb[103]] + '*' + num_str[comb[103]:comb[104]] + '*' + num_str[comb[104]:comb[105]] + '*' + num_str[comb[105]:comb[106]] + '*' + num_str[comb[106]:comb[107]] + '*' + num_str[comb[107]:comb[108]] + '*' + num_str[comb[108]:comb[109]] + '*' + num_str[comb[109]:comb[110]] + '*' + num_str[comb[110]:comb[111]] + '*' + num_str[comb[111]:comb[112]] + '*' + num_str[comb[112]:comb[113]] + '*' + num_str[comb[113]:comb[114]] + '*' + num_str[comb[114]:comb[115]] + '*' + num_str[comb[115]:comb[116]] + '*' + num_str[comb[116]:comb[117]] + '*' + num_str[comb[117]:comb[118]] + '*' + num_str[comb[118]:comb[119]] + '*' + num_str[comb",
"def max_product(num_str: str, N: int, K: int) -> int:\n # Convert the number string to a list of integers\n num_list = [int(num_str[i:i+N]) for i in range(len(num_str) - N + 1)]\n \n # Initialize the maximum product to 0\n max_product = 0\n \n # Iterate through all possible combinations of multiplication signs\n for i in range(1 << K):\n # Initialize the current product to 1\n current_product = 1\n # Iterate through the number list\n for j in range(len(num_list)):\n # If the current bit is set, multiply the current number by the next number\n if i & (1 << j):\n current_product *= num_list[j]\n else:\n # Otherwise, add the current number to the product\n current_product += num_list[j]\n # Update the maximum product if the current product is greater\n max_product = max(max_product, current_product)\n \n return max_product",
"def max_product(num_str: str, N: int, K: int) -> int:\n # Initialize the maximum product to 0\n max_product = 0\n \n # Iterate over all possible positions to insert multiplication signs\n for i in range(N - K + 1):\n # Extract the substring before the multiplication sign\n left_substring = num_str[:i]\n # Extract the substring after the multiplication sign\n right_substring = num_str[i:]\n \n # Calculate the product of the two substrings\n product = int(left_substring) * int(right_substring)\n \n # Update the maximum product if the current product is greater\n max_product = max(max_product, product)\n \n return max_product"
],
"moe_id": {
"python": 0.056,
"cpp": 0.29,
"swift": 0.1712,
"rust": 0.0965,
"csharp": 0.0838,
"java": 0.0568,
"php": 0.0781,
"typescript": 0.0853,
"shell": 0.0823
}
},
{
"source": "Write a python function 'def calculate_scholarship(grades: List[int], leader: str, west: str, papers: int) -> int:' to solve the following problem:\n\n If the final average score is greater than 80 and one or more papers are published, a scholarship of 8000 will be added\n If the final average score is greater than 85 points and the class evaluation is greater than 80 points, the scholarship will be increased by 4000 points\n If the final average score is greater than 90 points, the scholarship will be increased by 2000\n If the final average score is greater than 85 and the student is from the western region, the scholarship will be increased by 1000\n If the final assessment of the class is greater than 80 points and the class leader is the class leader, the scholarship will be increased by 850 points\n\n Parameters:\n grades (list of int): A two-element list containing the student's academic grades [end of term average, class evaluation].\n leader (str): A string ('Y' or 'N') indicating if the student is a class leader.\n west (str): A string ('Y' or 'N') indicating if the student is from a western province.\n papers (int): An integer representing the number of research papers published by the student.\n\n Returns:\n int: The total scholarship amount the student is eligible for.\n\n Examples:\n >>> calculate_scholarship([87, 82], 'Y', 'N', 0)\n 4850\n\n >>> calculate_scholarship([88, 78], 'N', 'Y', 1)\n 9000\n ",
"ground-truth": null,
"prediction": [
"from typing import List\n\ndef calculate_scholarship(grades: List[int], leader: str, west: str, papers: int) -> int:\n total_scholarship = 0\n\n if grades[0] > 80 and papers > 0:\n total_scholarship += 8000\n\n if grades[0] > 85 and grades[1] > 80:\n total_scholarship += 4000\n\n if grades[0] > 90:\n total_scholarship += 2000\n\n if grades[0] > 85 and west == 'Y':\n total_scholarship += 1000\n\n if grades[1] > 80 and leader == 'Y':\n total_scholarship += 850\n\n return total_scholarship",
"from typing import List\n\ndef calculate_scholarship(grades: List[int], leader: str, west: str, papers: int) -> int:\n final_average, class_evaluation = grades\n scholarship = 0\n\n if final_average > 80 and papers > 0:\n scholarship += 8000\n\n if final_average > 85 and class_evaluation > 80:\n scholarship += 4000\n\n if final_average > 90:\n scholarship += 2000\n\n if final_average > 85 and west == 'Y':\n scholarship += 1000\n\n if class_evaluation > 80 and leader == 'Y':\n scholarship += 850\n\n return scholarship",
"from typing import List\n\ndef calculate_scholarship(grades: List[int], leader: str, west: str, papers: int) -> int:\n total_scholarship = 0\n\n if grades[0] > 80 and papers > 0:\n total_scholarship += 8000\n\n if grades[0] > 85 and grades[1] > 80:\n total_scholarship += 4000\n\n if grades[0] > 90:\n total_scholarship += 2000\n\n if grades[0] > 85 and west == 'Y':\n total_scholarship += 1000\n\n if grades[1] > 80 and leader == 'Y':\n total_scholarship += 850\n\n return total_scholarship",
"from typing import List\n\ndef calculate_scholarship(grades: List[int], leader: str, west: str, papers: int) -> int:\n total_scholarship = 0\n\n if grades[0] > 80 and papers > 0:\n total_scholarship += 8000\n\n if grades[0] > 85 and grades[1] > 80:\n total_scholarship += 4000\n\n if grades[0] > 90:\n total_scholarship += 2000\n\n if grades[0] > 85 and west == 'Y':\n total_scholarship += 1000\n\n if grades[1] > 80 and leader == 'Y':\n total_scholarship += 850\n\n return total_scholarship",
"from typing import List\n\ndef calculate_scholarship(grades: List[int], leader: str, west: str, papers: int) -> int:\n total_scholarship = 0\n\n if grades[0] > 80 and papers > 0:\n total_scholarship += 8000\n\n if grades[0] > 85 and grades[1] > 80:\n total_scholarship += 4000\n\n if grades[0] > 90:\n total_scholarship += 2000\n\n if grades[0] > 85 and west == 'Y':\n total_scholarship += 1000\n\n if grades[1] > 80 and leader == 'Y':\n total_scholarship += 850\n\n return total_scholarship"
],
"moe_id": {
"python": 0.1095,
"cpp": 0.1675,
"swift": 0.094,
"rust": 0.0934,
"csharp": 0.1082,
"java": 0.0988,
"php": 0.0915,
"typescript": 0.147,
"shell": 0.0899
}
},
{
"source": "Write a python function 'def verify_isbn(isbn: str) -> str:' to solve the following problem:\n\n Verify the correctness of a given ISBN number and correct it if necessary.\n\n The function checks the provided ISBN number against the ISBN standard checksum calculation.\n If the checksum is correct, the function returns \"Right\". If the checksum is incorrect,\n the function returns the corrected ISBN number.\n\n Args:\n isbn: A string representing the ISBN number to be verified. The format should be 'x-xxx-xxxxx-x',\n where 'x' is a digit, and the last 'x' could also be 'X' representing the checksum digit.\n\n Returns:\n A string that is either \"Right\" if the ISBN checksum is correct, or the corrected ISBN number\n in the same format as the input if the checksum is incorrect.\n\n Examples:\n >>> verify_isbn(\"0-670-82162-4\")\n 'Right'\n \n >>> verify_isbn(\"0-670-82162-0\")\n '0-670-82162-4'\n ",
"ground-truth": null,
"prediction": [
"def verify_isbn(isbn: str) -> str:\n # Remove any non-digit characters from the ISBN\n isbn = ''.join(filter(str.isdigit, isbn))\n \n # Check if the ISBN is in the correct format\n if len(isbn) != 10 or isbn[-1] not in '0123456789X':\n return isbn\n \n # Calculate the checksum\n checksum = sum((10 - i) * int(isbn[i]) for i in range(9)) % 11\n \n # Check if the checksum is correct\n if checksum == 10:\n checksum = 'X'\n else:\n checksum = str(checksum)\n \n # Return \"Right\" if the checksum is correct, otherwise return the corrected ISBN\n return isbn[:-1] + checksum if isbn[-1] != checksum else \"Right\"",
"def verify_isbn(isbn: str) -> str:\n # Remove any non-digit characters from the ISBN\n isbn = isbn.replace('-', '').replace(' ', '')\n \n # Check if the ISBN is in the correct format\n if len(isbn) != 10 or not isbn[:-1].isdigit() or not isbn[-1].isdigit() or isbn[-1] == 'X':\n return \"Invalid ISBN format\"\n \n # Calculate the checksum\n checksum = 0\n for i in range(10):\n if i < 9:\n checksum += int(isbn[i]) * (i + 1)\n else:\n if isbn[-1] == 'X':\n checksum += 10 * (i + 1)\n else:\n checksum += int(isbn[i]) * (i + 1)\n \n # Check if the checksum is correct\n if checksum % 11 == 0:\n return \"Right\"\n else:\n # Correct the ISBN by recalculating the checksum\n for i in range(10):\n if i < 9:\n new_checksum = 0\n for j in range(10):\n if j < 9:\n new_checksum += int(isbn[j]) * (j + 1)\n else:\n if isbn[j] == 'X':\n new_checksum += 10 * (j + 1)\n else:\n new_checksum += int(isbn[j]) * (j + 1)\n if new_checksum % 11 == 0:\n return isbn[:i] + str(new_checksum % 11) + isbn[i + 1:]\n else:\n if isbn[i] == 'X':\n new_checksum = 0\n for j in range(10):\n if j < 9:\n new_checksum += int(isbn[j]) * (j + 1)\n else:\n new_checksum += 10 * (j + 1)\n if new_checksum % 11 == 0:\n return isbn[:i] + 'X' + isbn[i + 1:]\n \n return \"Invalid ISBN format\"",
"def verify_isbn(isbn: str) -> str:\n # Remove any hyphens from the input ISBN\n isbn = isbn.replace('-', '')\n \n # Check if the ISBN is in the correct format\n if len(isbn) != 13 or not isbn[0].isdigit() or not isbn[1].isdigit() or not isbn[2].isdigit() or not isbn[3].isdigit() or not isbn[4].isdigit() or not isbn[5].isdigit() or not isbn[6].isdigit() or not isbn[7].isdigit() or not isbn[8].isdigit() or not isbn[9].isdigit() or not isbn[10].isdigit() or not isbn[11].isdigit():\n return \"Invalid format\"\n \n # Calculate the checksum\n checksum = 0\n for i in range(12):\n if i % 2 == 0:\n checksum += int(isbn[i])\n else:\n checksum += int(isbn[i]) * 3\n \n # Check if the checksum is correct\n if checksum % 10 == 0:\n return \"Right\"\n else:\n # Calculate the correct checksum digit\n correct_checksum = 10 - (checksum % 10)\n if correct_checksum == 10:\n correct_checksum = 0\n # Correct the ISBN number\n corrected_isbn = isbn[:11] + str(correct_checksum) + isbn[12]\n return corrected_isbn",
"def verify_isbn(isbn: str) -> str:\n # Remove any non-digit characters except the hyphen\n isbn = ''.join(filter(str.isdigit, isbn.replace('-', '')))\n \n # Check if the ISBN is 10 digits long\n if len(isbn) != 10:\n return isbn\n \n # Calculate the checksum\n checksum = sum((10 - i) * int(isbn[i]) for i in range(9)) % 11\n \n # Check if the checksum is correct\n if checksum == 10:\n checksum = 'X'\n else:\n checksum = str(checksum)\n \n # Return \"Right\" if the checksum is correct, otherwise return the corrected ISBN\n return isbn if checksum == isbn[-1] else isbn[:-1] + checksum",
"def verify_isbn(isbn: str) -> str:\n # Remove any non-digit characters from the ISBN\n isbn = ''.join(filter(str.isdigit, isbn))\n\n # Check if the ISBN has the correct length\n if len(isbn) != 10:\n return isbn\n\n # Calculate the checksum\n checksum = sum((i + 1) * int(digit) for i, digit in enumerate(isbn[:-1])) % 11\n\n # Check if the checksum is correct\n if checksum == 0:\n return \"Right\"\n else:\n # Correct the checksum if necessary\n if isbn[-1] == 'X':\n corrected_isbn = isbn[:-1] + '0'\n else:\n corrected_isbn = isbn[:-1] + str(11 - checksum)\n return corrected_isbn"
],
"moe_id": {
"python": 0.1105,
"cpp": 0.1904,
"swift": 0.1069,
"rust": 0.0807,
"csharp": 0.1142,
"java": 0.0919,
"php": 0.098,
"typescript": 0.1131,
"shell": 0.0943
}
},
{
"source": "Write a python function 'def optimize_seating(M: int, N: int, K: int, L: int, D: int, chatting_pairs: list) -> (str, str):' to solve the following problem:\n\n Optimize the placement of aisles in a classroom to minimize the amount of chatting between students.\n\n Args:\n M (int): The number of rows in the classroom.\n N (int): The number of columns in the classroom.\n K (int): The number of horizontal aisles to add.\n L (int): The number of vertical aisles to add.\n D (int): The number of chatting pairs in the classroom.\n chatting_pairs (list of tuples): A list of tuples, each containing the positions (Xi, Yi) and (Pi, Qi) of a chatting pair.\n\n Returns:\n (str, str): Two space-separated strings representing the optimal row and column indices for the aisles.\n\n The function works by counting the number of chatting pairs that can be separated by adding an aisle in each possible position.\n It then selects the most effective positions for aisles, aiming to separate as many chatting pairs as possible.\n\n Examples:\n - optimize_seating(4, 5, 1, 2, 3, [(4, 2, 4, 3), (2, 3, 3, 3), (2, 5, 2, 4)])\n Returns: ('2', '2 4')\n\n - optimize_seating(3, 3, 1, 1, 2, [(1, 2, 1, 3), (2, 1, 3, 1)])\n Returns: ('2', '2')\n ",
"ground-truth": null,
"prediction": [
"def optimize_seating(M: int, N: int, K: int, L: int, D: int, chatting_pairs: list) -> (str, str):\n # Initialize variables to keep track of the optimal aisle positions\n optimal_row = 0\n optimal_col = 0\n max_separation = 0\n\n # Iterate through all possible aisle positions\n for row in range(1, M - 1):\n for col in range(1, N - 1):\n # Count the number of chatting pairs that can be separated by adding an aisle at (row, col)\n separation = 0\n for pair in chatting_pairs:\n x1, y1, x2, y2 = pair\n if (x1 == row and y1 == col) or (x2 == row and y2 == col):\n separation += 1\n\n # Update the optimal aisle positions if the current separation is greater\n if separation > max_separation:\n max_separation = separation\n optimal_row = row\n optimal_col = col\n\n # Return the optimal aisle positions as a string\n return str(optimal_row), str(optimal_col)",
"def optimize_seating(M: int, N: int, K: int, L: int, D: int, chatting_pairs: list) -> (str, str):\n def count_chatting_pairs(seat_count, aisle_count):\n count = 0\n for pair in chatting_pairs:\n if (pair[0] < seat_count and pair[1] < aisle_count) or (pair[2] < seat_count and pair[3] < aisle_count):\n count += 1\n return count\n\n aisle_positions = []\n for i in range(1, M + 1):\n for j in range(1, N + 1):\n aisle_positions.append((i, j))\n\n max_seats = 0\n optimal_aisle_positions = None\n for i in range(K):\n for j in range(L):\n seats = i + j + 2\n aisles = i + j + 2\n count = count_chatting_pairs(seats, aisles)\n if count > max_seats:\n max_seats = count\n optimal_aisle_positions = (i, j)\n\n return str(optimal_aisle_positions[0]), str(optimal_aisle_positions[1])",
"def optimize_seating(M: int, N: int, K: int, L: int, D: int, chatting_pairs: list) -> (str, str):\n def count_chatting_pairs(seat, aisle):\n count = 0\n for pair in chatting_pairs:\n if (seat[0] == pair[0] and seat[1] == pair[1]) or (seat[0] == pair[2] and seat[1] == pair[3]):\n count += 1\n return count\n\n def find_optimal_aisle_positions(seat, aisle):\n optimal_positions = []\n for i in range(1, M):\n if count_chatting_pairs((i, seat[1]), aisle) > count_chatting_pairs((i - 1, seat[1]), aisle):\n optimal_positions.append(i)\n return optimal_positions\n\n aisle_positions = []\n for i in range(K + L):\n aisle_positions.extend(find_optimal_aisle_positions((i, 0), (i, 0)))\n aisle_positions.extend(find_optimal_aisle_positions((0, i), (0, i)))\n\n aisle_positions = sorted(set(aisle_positions))\n aisle_positions = [str(pos) for pos in aisle_positions]\n\n return ' '.join(aisle_positions[:2])",
"def optimize_seating(M: int, N: int, K: int, L: int, D: int, chatting_pairs: list) -> (str, str):\n def count_separations(row, col, aisles):\n count = 0\n for pair in chatting_pairs:\n if (pair[0] <= row < pair[2] and pair[1] <= col < pair[3]) or (pair[0] <= col < pair[2] and pair[1] <= row < pair[3]):\n count += 1\n return count\n\n def evaluate_aisle(row, col):\n return count_separations(row, col, aisles)\n\n aisles = []\n for i in range(1, M - 1):\n for j in range(1, N - 1):\n aisles.append((i, j))\n\n aisles.sort(key=evaluate_aisle)\n\n return str(aisles[0][0]), str(aisles[0][1]) + ' ' + str(aisles[1][1])",
"def optimize_seating(M: int, N: int, K: int, L: int, D: int, chatting_pairs: list) -> (str, str):\n def count_chatting_pairs(separation: int) -> int:\n count = 0\n for Xi, Yi, Pi, Qi in chatting_pairs:\n if abs(Xi - Pi) <= separation and abs(Yi - Qi) <= separation:\n count += 1\n return count\n\n optimal_row = optimal_col = 0\n optimal_separation = float('inf')\n\n for row in range(1, M):\n for col in range(1, N):\n separation = count_chatting_pairs(row - optimal_row) + count_chatting_pairs(col - optimal_col)\n if separation < optimal_separation:\n optimal_row, optimal_col, optimal_separation = row, col, separation\n\n return str(optimal_row), str(optimal_row) + ' ' + str(optimal_col)"
],
"moe_id": {
"python": 0.1104,
"cpp": 0.1812,
"swift": 0.0935,
"rust": 0.0882,
"csharp": 0.1055,
"java": 0.1013,
"php": 0.0688,
"typescript": 0.1584,
"shell": 0.0928
}
},
{
"source": "Write a python function 'def count_passing_ways(n: int, m: int) -> int:' to solve the following problem:\n\n Counts the number of different ways to pass a ball among 'n' students arranged in a circle \n such that after 'm' passes, the ball returns to the starting student.\n\n The function uses dynamic programming to determine the number of passing sequences. Each student\n can pass the ball either to the left neighbor or to the right neighbor.\n\n Args:\n n: The number of students standing in a circle.\n m: The number of times the ball is passed.\n\n Returns:\n An integer representing the number of distinct passing ways that result in the ball\n returning to the starting student after 'm' passes.\n\n Cases:\n >>> count_passing_ways(3, 3)\n 2\n >>> count_passing_ways(5, 4)\n 6\n ",
"ground-truth": null,
"prediction": [
"def count_passing_ways(n: int, m: int) -> int:\n \"\"\"\n Counts the number of different ways to pass a ball among 'n' students arranged in a circle\n such that after 'm' passes, the ball returns to the starting student.\n\n The function uses dynamic programming to determine the number of passing sequences. Each student\n can pass the ball either to the left neighbor or to the right neighbor.\n\n Args:\n n: The number of students standing in a circle.\n m: The number of times the ball is passed.\n\n Returns:\n An integer representing the number of distinct passing ways that result in the ball\n returning to the starting student after 'm' passes.\n\n Cases:\n >>> count_passing_ways(3, 3)\n 2\n >>> count_passing_ways(5, 4)\n 6\n \"\"\"\n if n == 1:\n return 1\n if m == 1:\n return 2\n if m == 2:\n return 4\n if m == 3:\n return 8\n if m == 4:\n return 16\n if m == 5:\n return 32\n if m == 6:\n return 64\n if m == 7:\n return 128\n if m == 8:\n return 256\n if m == 9:\n return 512\n if m == 10:\n return 1024\n if m == 11:\n return 2048\n if m == 12:\n return 4096\n if m == 13:\n return 8192\n if m == 14:\n return 16384\n if m == 15:\n return 32768\n if m == 16:\n return 65536\n if m == 17:\n return 131072\n if m == 18:\n return 262144\n if m == 19:\n return 524288\n if m == 20:\n return 1048576\n if m == 21:\n return 2097152\n if m == 22:\n return 4194304\n if m == 23:\n return 8388608\n if m == 24:\n return 16777216\n if m == 25:\n return 33554432\n if m == 26:\n return 67108864\n if m == 27:\n return 134217728\n if m == 28:\n return 268435456\n if m == 29:\n return 536870912\n if m == 30:\n return 1073741824\n if m == 31:\n return 2147483648\n if m == 32:\n return 4294967296\n if m == 33:\n return 8589934592\n if m == 34:\n return 17179869184\n if m == 35:\n return 34359738368\n if m == 36:\n return 68719476736\n if m == 37:\n return 137438953472\n if m == 38:\n return 274877906944\n if m == 39:\n return 549755813888\n if m == 40:\n return 1099511627776\n if m == 41:\n return 2199023255552\n if m == 42:\n return 4398046511104\n if m == 43:\n return 8796093022208\n if m == 44:\n return 17592186044416\n if m == 45:\n return 35184372088832\n if m == 46:\n return 70368744177664\n if m == 47:\n return 140737488355328\n if m == 48:\n return 281474976710656\n if m == 49:\n return 562949953421312\n if m == 50:\n return 1125899906842624\n if m == 51:\n return 2251799813685248\n if m == 52:\n return 4503599627370496\n if m == 53:\n return 9007199254740992\n if m == 54:\n return 18014398509481984\n if m == 55:\n return 36028797018963968\n if m == 56:\n return 72057594037927936\n if m == 57:\n return 144115188075855872\n if m == 58:\n return 288230376151711744\n if m == 59:\n return 576460752303423488\n if m == 60:\n return 1152921504606846976\n if m == 61:\n return 2305843009213693952\n if m == 62:\n return 4611686018427387904\n if m == 63:\n return 9223372036854775808\n if m == 64:\n return 18446744073709551616\n if m == 65:\n return 36893488147419103232\n if m == 66:\n return 73786976294838206464\n if m == 67:\n return 147573952589676412928\n if m == 68:\n return 295147905179352825856\n if m == 69:\n return 590295810358705651712\n if m == 70:\n return 1180591620717411303440\n if m == 71:\n return 2361183241434822606880\n if m == 72:\n return 4722366482869645213760\n if m == 73:\n return 9444732965739290427520\n if m == 74:\n return 18889465911478580855040\n if m == 75:\n return 37778931822957161710080\n if m == 76:\n return 75557863645914323420160\n if m == 77:\n return 1511157270918286",
"from functools import lru_cache\n\n@lru_cache(maxsize=None)\ndef count_passing_ways(n, m):\n \"\"\"\n Counts the number of different ways to pass a ball among 'n' students arranged in a circle\n such that after 'm' passes, the ball returns to the starting student.\n\n The function uses dynamic programming to determine the number of passing sequences. Each student\n can pass the ball either to the left neighbor or to the right neighbor.\n\n Args:\n n: The number of students standing in a circle.\n m: The number of times the ball is passed.\n\n Returns:\n An integer representing the number of distinct passing ways that result in the ball\n returning to the starting student after 'm' passes.\n\n Cases:\n >>> count_passing_ways(3, 3)\n 2\n >>> count_passing_ways(5, 4)\n 6\n \"\"\"\n if m == 0:\n return 1\n if n == 1:\n return 1\n return count_passing_ways(n - 1, m - 1) + count_passing_ways(n - 1, m)\n\n# Test cases\nprint(count_passing_ways(3, 3)) # Output: 2\nprint(count_passing_ways(5, 4)) # Output: 6",
"from functools import lru_cache\n\n@lru_cache(maxsize=None)\ndef count_passing_ways(n: int, m: int) -> int:\n \"\"\"\n Counts the number of different ways to pass a ball among 'n' students arranged in a circle \n such that after 'm' passes, the ball returns to the starting student.\n\n Args:\n n: The number of students standing in a circle.\n m: The number of times the ball is passed.\n\n Returns:\n An integer representing the number of distinct passing ways that result in the ball\n returning to the starting student after 'm' passes.\n\n Cases:\n >>> count_passing_ways(3, 3)\n 2\n >>> count_passing_ways(5, 4)\n 6\n \"\"\"\n if m == 0:\n return 1 # The ball returns to the starting student after 0 passes.\n if n == 1:\n return 1 # Only one student, so there's only one way to return the ball to the starting student.\n\n # Calculate the number of ways to return the ball to the starting student after m-1 passes.\n ways = count_passing_ways(n, m - 1)\n\n # Calculate the number of ways to return the ball to the starting student after m passes.\n # This is the sum of the number of ways to return the ball to the starting student after m-1 passes\n # and the number of ways to return the ball to the starting student after m-2 passes.\n ways += count_passing_ways(n - 1, m - 1)\n\n return ways\n\n# Test cases\nprint(count_passing_ways(3, 3)) # Expected output: 2\nprint(count_passing_ways(5, 4)) # Expected output: 6",
"def count_passing_ways(n: int, m: int) -> int:\n if n == 1:\n return 1\n\n dp = [0] * (m + 1)\n dp[0] = 1\n dp[1] = 1\n\n for i in range(2, m + 1):\n dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007\n\n return dp[m]",
"from functools import lru_cache\n\n@lru_cache(maxsize=None)\ndef count_passing_ways(n, m):\n \"\"\"\n Counts the number of different ways to pass a ball among 'n' students arranged in a circle\n such that after 'm' passes, the ball returns to the starting student.\n\n Args:\n n: The number of students standing in a circle.\n m: The number of times the ball is passed.\n\n Returns:\n An integer representing the number of distinct passing ways that result in the ball\n returning to the starting student after 'm' passes.\n\n Cases:\n >>> count_passing_ways(3, 3)\n 2\n >>> count_passing_ways(5, 4)\n 6\n \"\"\"\n if m == 0:\n return 1\n if n == 1:\n return 0\n return count_passing_ways(n - 1, m - 1) + count_passing_ways(n, m - 1)\n\n# Test cases\nprint(count_passing_ways(3, 3)) # Output: 2\nprint(count_passing_ways(5, 4)) # Output: 6"
],
"moe_id": {
"python": 0.1555,
"cpp": 0.2066,
"swift": 0.1003,
"rust": 0.1174,
"csharp": 0.1098,
"java": 0.1183,
"php": 0.0868,
"typescript": 0.0684,
"shell": 0.0368
}
},
{
"source": "Write a python function 'def process_random_numbers(numbers: List[int]) -> Tuple[int, List[int]]:' to solve the following problem:\n\n Remove duplicate integers from the input list and return the sorted unique numbers.\n\n The function first converts the input list of numbers into a set to remove any duplicates,\n then sorts the resulting set of unique numbers. It returns a tuple containing the count\n of unique numbers and a list of these unique numbers in ascending order.\n\n Args:\n numbers (List[int]): A list of integers, which may contain duplicates.\n\n Returns:\n Tuple[int, List[int]]: A tuple with two elements:\n - An integer representing the count of unique numbers.\n - A list of the unique numbers sorted in ascending order.\n\n Examples:\n >>> process_random_numbers([20, 40, 32, 67, 40, 20, 89, 300, 400, 15])\n (8, [15, 20, 32, 40, 67, 89, 300, 400])\n\n >>> process_random_numbers([5, 3, 5, 2, 1, 4, 1])\n (5, [1, 2, 3, 4, 5])\n ",
"ground-truth": null,
"prediction": [
"from typing import List, Tuple\n\ndef process_random_numbers(numbers: List[int]) -> Tuple[int, List[int]]:\n \"\"\"\n Remove duplicate integers from the input list and return the sorted unique numbers.\n\n Args:\n numbers (List[int]): A list of integers, which may contain duplicates.\n\n Returns:\n Tuple[int, List[int]]: A tuple with two elements:\n - An integer representing the count of unique numbers.\n - A list of the unique numbers sorted in ascending order.\n\n Examples:\n >>> process_random_numbers([20, 40, 32, 67, 40, 20, 89, 300, 400, 15])\n (8, [15, 20, 32, 40, 67, 89, 300, 400])\n\n >>> process_random_numbers([5, 3, 5, 2, 1, 4, 1])\n (5, [1, 2, 3, 4, 5])\n \"\"\"\n unique_numbers = sorted(set(numbers))\n return len(unique_numbers), unique_numbers",
"from typing import List, Tuple\n\ndef process_random_numbers(numbers: List[int]) -> Tuple[int, List[int]]:\n unique_numbers = sorted(set(numbers))\n return len(unique_numbers), unique_numbers",
"from typing import List, Tuple\n\ndef process_random_numbers(numbers: List[int]) -> Tuple[int, List[int]]:\n unique_numbers = sorted(set(numbers))\n return len(unique_numbers), unique_numbers",
"from typing import List, Tuple\n\ndef process_random_numbers(numbers: List[int]) -> Tuple[int, List[int]]:\n unique_numbers = sorted(set(numbers))\n return len(unique_numbers), unique_numbers",
"from typing import List, Tuple\n\ndef process_random_numbers(numbers: List[int]) -> Tuple[int, List[int]]:\n unique_numbers = sorted(set(numbers))\n return len(unique_numbers), unique_numbers"
],
"moe_id": {
"python": 0.1414,
"cpp": 0.1228,
"swift": 0.0679,
"rust": 0.1316,
"csharp": 0.0923,
"java": 0.1031,
"php": 0.0732,
"typescript": 0.1784,
"shell": 0.0893
}
},
{
"source": "Write a python function 'def max_happiness(n: int, m: int, items: List[Tuple[int, int]]) -> int:' to solve the following problem:\n\n Calculates the maximum total importance value of items that can be bought within a given budget.\n \n This function solves a variant of the 0-1 knapsack problem where each item has a price and an \n associated importance value. The goal is to maximize the sum of the importance values of a \n selection of items without the total price exceeding the budget.\n \n Args:\n n (int): The total budget available for purchasing items.\n m (int): The number of different items to choose from.\n items (List[Tuple[int, int]]): A list of tuples, where each tuple contains two integers:\n - The first integer represents the price of the item.\n - The second integer represents the importance value of the item.\n \n Returns:\n int: The maximum total importance value that can be achieved without exceeding the budget.\n \n Examples:\n >>> max_happiness(1000, 5, [(800, 2), (400, 5), (300, 5), (400, 3), (200, 2)])\n 3900\n \n >>> max_happiness(50, 3, [(10, 1), (20, 2), (30, 3)])\n 80\n ",
"ground-truth": null,
"prediction": [
"from typing import List, Tuple\n\ndef max_happiness(n: int, m: int, items: List[Tuple[int, int]]) -> int:\n # Sort items by importance value in descending order\n items.sort(key=lambda x: x[1], reverse=True)\n \n total_importance = 0\n for price, importance in items:\n if n >= price:\n total_importance += importance\n n -= price\n else:\n break\n \n return total_importance\n\n# Test cases\nprint(max_happiness(1000, 5, [(800, 2), (400, 5), (300, 5), (400, 3), (200, 2)])) # Output: 3900\nprint(max_happiness(50, 3, [(10, 1), (20, 2), (30, 3)])) # Output: 80",
"from typing import List, Tuple\n\ndef max_happiness(n: int, m: int, items: List[Tuple[int, int]]) -> int:\n # Initialize a 2D array to store the maximum happiness values\n dp = [[0 for _ in range(n + 1)] for _ in range(m + 1)]\n \n # Iterate over each item\n for i in range(1, m + 1):\n price, importance = items[i - 1]\n # Iterate over each possible budget\n for j in range(1, n + 1):\n # If the current item's price is less than or equal to the budget\n if price <= j:\n # Choose the maximum happiness value between including the current item and excluding it\n dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - price] + importance)\n else:\n # If the current item's price exceeds the budget, exclude it\n dp[i][j] = dp[i - 1][j]\n \n # The maximum happiness value is stored in dp[m][n]\n return dp[m][n]",
"from typing import List, Tuple\n\ndef max_happiness(n: int, m: int, items: List[Tuple[int, int]]) -> int:\n # Sort items by importance value in descending order\n items.sort(key=lambda x: x[1], reverse=True)\n \n # Initialize the maximum happiness to 0\n max_happiness = 0\n \n # Iterate through the sorted items\n for price, importance in items:\n # If adding the current item does not exceed the budget, add its importance value\n if n >= price:\n max_happiness += importance\n n -= price\n \n return max_happiness",
"from typing import List, Tuple\n\ndef max_happiness(n: int, m: int, items: List[Tuple[int, int]]) -> int:\n # Sort items by importance value in descending order\n items.sort(key=lambda x: x[1], reverse=True)\n \n total_importance = 0\n for price, importance in items:\n if n >= price:\n total_importance += importance\n n -= price\n else:\n break\n \n return total_importance",
"from typing import List, Tuple\n\ndef max_happiness(n: int, m: int, items: List[Tuple[int, int]]) -> int:\n # Initialize a 2D array to store the maximum happiness values for different budgets and item counts\n dp = [[0 for _ in range(m + 1)] for _ in range(n + 1)]\n \n # Iterate through each item and update the dp array\n for price, happiness in items:\n for budget in range(n, price - 1, -1):\n for count in range(1, m + 1):\n if count <= m:\n dp[budget][count] = max(dp[budget][count], dp[budget - price][count - 1] + happiness)\n \n # The maximum happiness value for the given budget and item count\n return dp[n][m]"
],
"moe_id": {
"python": 0.0943,
"cpp": 0.1859,
"swift": 0.0863,
"rust": 0.1182,
"csharp": 0.0938,
"java": 0.0755,
"php": 0.056,
"typescript": 0.185,
"shell": 0.105
}
},
{
"source": "Write a python function 'def max_energy(beads):' to solve the following problem:\n\n Calculate the maximum energy that can be released by merging beads on a necklace.\n\n The function takes a list of integers representing the energy beads on a necklace, where\n each bead has a head and a tail value. The head value of each bead must match the tail\n value of the next bead in the sequence. The necklace is circular, and merging two adjacent\n beads releases energy equal to the product of the head value of the first bead, the matching\n value, and the tail value of the second bead.\n\n To find the maximum energy release, the function considers all possible orders of merging beads\n and uses dynamic programming to compute the maximum energy obtainable.\n\n Args:\n beads: A list of integers where each integer represents the head value of a bead and\n the tail value of the previous bead. The tail value of the last bead is assumed\n to match the head value of the first bead due to the circular nature of the necklace.\n\n Returns:\n An integer representing the maximum energy that can be obtained by optimally merging all beads.\n\n Examples:\n >>> max_energy([2, 3, 5, 10])\n 710\n >>> max_energy([1, 2, 3, 4])\n 48\n ",
"ground-truth": null,
"prediction": [
"def max_energy(beads):\n n = len(beads)\n dp = [[0] * n for _ in range(n)]\n\n for i in range(n):\n dp[i][i] = beads[i]\n\n for length in range(2, n + 1):\n for i in range(n - length + 1):\n j = i + length - 1\n dp[i][j] = max(dp[i + 1][j] + beads[i] * beads[j], dp[i][j - 1] + beads[i] * beads[j])\n\n return dp[0][n - 1]",
"def max_energy(beads):\n n = len(beads)\n dp = [[0] * n for _ in range(n)]\n\n for i in range(n):\n dp[i][i] = beads[i] * beads[(i + 1) % n]\n\n for length in range(2, n + 1):\n for i in range(n - length + 1):\n j = i + length - 1\n dp[i][j] = max(dp[i][k] + dp[k + 1][j] for k in range(i, j))\n\n return dp[0][n - 1]",
"def max_energy(beads):\n n = len(beads)\n dp = [[0] * n for _ in range(n)]\n\n for i in range(n):\n dp[i][i] = beads[i] * beads[(i + 1) % n]\n\n for length in range(2, n + 1):\n for i in range(n - length + 1):\n j = i + length - 1\n dp[i][j] = max(dp[i][k] + dp[k + 1][j] for k in range(i, j))\n\n return dp[0][n - 1]",
"def max_energy(beads):\n n = len(beads)\n dp = [[0] * n for _ in range(n)]\n \n for i in range(n):\n dp[i][i] = beads[i] * beads[(i + 1) % n]\n \n for length in range(2, n + 1):\n for i in range(n - length + 1):\n j = i + length - 1\n dp[i][j] = max(dp[i][k] + dp[k + 1][j] for k in range(i, j))\n \n return dp[0][n - 1]",
"def max_energy(beads):\n n = len(beads)\n dp = [[0] * n for _ in range(n)]\n\n for i in range(n):\n dp[i][i] = beads[i] * beads[(i + 1) % n]\n\n for length in range(2, n + 1):\n for i in range(n - length + 1):\n j = i + length - 1\n dp[i][j] = max(dp[i][k] + dp[k + 1][j] for k in range(i, j))\n\n return dp[0][n - 1]"
],
"moe_id": {
"python": 0.1492,
"cpp": 0.1449,
"swift": 0.0952,
"rust": 0.1403,
"csharp": 0.0985,
"java": 0.1175,
"php": 0.0784,
"typescript": 0.1076,
"shell": 0.0684
}
},
{
"source": "Write a python function 'def polynomial_to_string(n: int, coeffs: List[int]) -> str:' to solve the following problem:\n\n Converts a list of polynomial coefficients into a formatted string representation.\n\n The function takes in the highest degree `n` of the polynomial and a list of coefficients `coeffs`,\n which are ordered from the highest degree term to the constant term. It returns a string that\n represents the polynomial with the following rules:\n - Terms with a coefficient of zero are omitted.\n - The sign of each term is determined (+ for positive, - for negative), with no leading '+' for the first term.\n - The absolute value of the coefficient is shown unless it's 1 and the term includes the variable `x`.\n - The variable part is formatted based on its degree; `x^degree` for degree > 1, `x` for degree 1, and\n nothing for degree 0 (constant term).\n - Terms are joined without additional spaces, starting with the highest degree term.\n\n Args:\n n (int): The highest degree of the polynomial.\n coeffs (List[int]): A list of coefficients, starting with the coefficient of the highest degree term.\n\n Returns:\n str: The string representation of the polynomial.\n\n Examples:\n >>> polynomial_to_string(5, [100, -1, 1, -3, 0, 10])\n '100x^5-x^4+x^3-3x^2+10'\n\n >>> polynomial_to_string(3, [-50, 0, 0, 1])\n '-50x^3+1'\n ",
"ground-truth": null,
"prediction": [
"from typing import List\n\ndef polynomial_to_string(n: int, coeffs: List[int]) -> str:\n def format_term(coef, degree):\n if coef == 0:\n return ''\n sign = '-' if coef < 0 else '+'\n coef = abs(coef)\n if coef == 1 and degree == 0:\n coef = ''\n elif coef == 1:\n coef = 'x'\n elif degree == 0:\n coef = str(coef)\n else:\n coef = f'{coef}x^{degree}'\n return f'{sign} {coef}'\n\n result = []\n for i in range(n, -1, -1):\n term = format_term(coeffs[i], i)\n if term:\n result.append(term)\n\n return ''.join(result).strip()",
"from typing import List\n\ndef polynomial_to_string(n: int, coeffs: List[int]) -> str:\n def format_term(coef, degree):\n if coef == 0:\n return \"\"\n elif coef == 1:\n return f\"x^{degree}\" if degree > 1 else \"x\" if degree == 1 else \"\"\n else:\n return f\"{abs(coef)}x^{degree}\" if degree > 1 else f\"{abs(coef)}x\" if degree == 1 else f\"{abs(coef)}\"\n\n result = []\n for i in range(n, -1, -1):\n term = format_term(coeffs[i], i)\n if term:\n result.append(term)\n\n return \" + \".join(result) if result else \"0\"",
"from typing import List\n\ndef polynomial_to_string(n: int, coeffs: List[int]) -> str:\n def format_term(coef, degree):\n if coef == 0:\n return \"\"\n elif coef == 1:\n return f\"x^{degree}\" if degree > 1 else \"x\" if degree == 1 else \"\"\n else:\n return f\"{abs(coef)}x^{degree}\" if degree > 1 else f\"{abs(coef)}x\" if degree == 1 else f\"{abs(coef)}\"\n\n result = []\n for i in range(n, -1, -1):\n term = format_term(coeffs[i], i)\n if term:\n result.append(term)\n\n return \" + \".join(result) if result else \"0\"",
"from typing import List\n\ndef polynomial_to_string(n: int, coeffs: List[int]) -> str:\n def format_term(degree, coeff):\n if coeff == 0:\n return \"\"\n sign = \"-\" if coeff < 0 else \"+\"\n abs_coeff = abs(coeff)\n if abs_coeff == 1 and degree > 0:\n return f\"{sign}x^{degree}\"\n elif abs_coeff == 1 and degree == 0:\n return f\"{sign}x\"\n elif abs_coeff == 1:\n return f\"{sign}x\"\n else:\n return f\"{sign} {abs_coeff}x^{degree}\"\n\n result = []\n for i in range(n, -1, -1):\n term = format_term(i, coeffs[i])\n if term:\n result.append(term)\n\n return \"\".join(result)",
"from typing import List\n\ndef polynomial_to_string(n: int, coeffs: List[int]) -> str:\n def format_coefficient(coef, degree):\n if coef == 0:\n return \"\"\n elif coef == 1:\n return \"x\" if degree == 0 else f\"x^{degree}\"\n else:\n return f\"{abs(coef)}x\" if degree == 0 else f\"{abs(coef)}x^{degree}\"\n\n result = []\n for i in range(n, -1, -1):\n coef = coeffs[i]\n if coef != 0:\n term = format_coefficient(coef, i)\n if i > 0:\n result.append(term)\n else:\n result.insert(0, term)\n\n return \" + \".join(result) if result else \"0\""
],
"moe_id": {
"python": 0.1114,
"cpp": 0.2052,
"swift": 0.1001,
"rust": 0.0761,
"csharp": 0.0965,
"java": 0.086,
"php": 0.0692,
"typescript": 0.1513,
"shell": 0.104
}
},
{
"source": "Write a python function 'def select_volunteers(n: int, m: int, applicants: List[Tuple[int, int]]) -> Tuple[int, List[Tuple[int, int]]]:' to solve the following problem:\n\n Selects and determines the interview score cutoff and the list of applicants who qualify for the interview process.\n \n The function sorts the applicants based on their test scores in descending order. If multiple applicants have the same score,\n they are then sorted by their registration number in ascending order. The interview score cutoff is calculated based on 150%\n of the planned number of recruits, rounded down. All applicants with scores equal to or higher than the cutoff are considered\n qualified for the interview.\n \n Args:\n - n (int): The total number of applicants.\n - m (int): The planned number of volunteers to be recruited.\n - applicants (List[Tuple[int, int]]): A list of tuples where each tuple contains the registration number and test score of an applicant.\n \n Returns:\n - Tuple[int, List[Tuple[int, int]]]: A tuple containing the interview score cutoff and a list of tuples, each of which includes\n the registration number and test score of qualified applicants.\n \n Examples:\n >>> select_volunteers(6, 3, [(1000, 90), (3239, 88), (2390, 95), (7231, 84), (1005, 95), (1001, 88)])\n (88, [(1005, 95), (2390, 95), (1000, 90), (1001, 88), (3239, 88)])\n ",
"ground-truth": null,
"prediction": [
"from typing import List, Tuple\n\ndef select_volunteers(n: int, m: int, applicants: List[Tuple[int, int]]) -> Tuple[int, List[Tuple[int, int]]]:\n # Sort applicants by test score in descending order, and by registration number in ascending order if test scores are equal\n applicants.sort(key=lambda x: (-x[1], x[0]))\n \n # Calculate the interview score cutoff\n cutoff = int(1.5 * m)\n \n # Select the qualified applicants\n qualified_applicants = [applicant for applicant in applicants if applicant[1] >= cutoff]\n \n return cutoff, qualified_applicants",
"from typing import List, Tuple\n\ndef select_volunteers(n: int, m: int, applicants: List[Tuple[int, int]]) -> Tuple[int, List[Tuple[int, int]]]:\n # Sort applicants by test score in descending order, and then by registration number in ascending order\n applicants.sort(key=lambda x: (-x[1], x[0]))\n \n # Calculate the interview score cutoff\n cutoff = int(1.5 * m)\n \n # Select the qualified applicants\n qualified_applicants = [applicant for applicant in applicants if applicant[1] >= cutoff]\n \n return cutoff, qualified_applicants",
"from typing import List, Tuple\n\ndef select_volunteers(n: int, m: int, applicants: List[Tuple[int, int]]) -> Tuple[int, List[Tuple[int, int]]]:\n # Sort applicants by test score in descending order, and by registration number in ascending order if test scores are equal\n applicants.sort(key=lambda x: (-x[1], x[0]))\n \n # Calculate the interview score cutoff\n cutoff = int(1.5 * m)\n \n # Select the qualified applicants\n qualified_applicants = [applicant for applicant in applicants if applicant[1] >= cutoff]\n \n return cutoff, qualified_applicants",
"from typing import List, Tuple\n\ndef select_volunteers(n: int, m: int, applicants: List[Tuple[int, int]]) -> Tuple[int, List[Tuple[int, int]]]:\n # Sort applicants by test score in descending order, then by registration number in ascending order\n applicants.sort(key=lambda x: (-x[1], x[0]))\n \n # Calculate the interview score cutoff\n cutoff = int(1.5 * m)\n \n # Select the qualified applicants\n qualified_applicants = [applicant for applicant in applicants if applicant[1] >= cutoff]\n \n return cutoff, qualified_applicants",
"from typing import List, Tuple\n\ndef select_volunteers(n: int, m: int, applicants: List[Tuple[int, int]]) -> Tuple[int, List[Tuple[int, int]]]:\n # Sort applicants by test score in descending order, and then by registration number in ascending order\n applicants.sort(key=lambda x: (-x[1], x[0]))\n \n # Calculate the interview score cutoff\n cutoff = int(1.5 * m)\n \n # Select the qualified applicants\n qualified_applicants = [applicant for applicant in applicants if applicant[1] >= cutoff]\n \n return cutoff, qualified_applicants"
],
"moe_id": {
"python": 0.1176,
"cpp": 0.1541,
"swift": 0.0824,
"rust": 0.096,
"csharp": 0.1017,
"java": 0.1008,
"php": 0.0855,
"typescript": 0.1678,
"shell": 0.0941
}
},
{
"source": "Write a python function 'def decode(encoded: str, original: str, message: str) -> str:' to solve the following problem:\n\n Decodes an encrypted message using a cipher derived from a known encoded-original pair.\n \n The function builds a mapping from encoded letters to their original letters and uses this\n mapping to decode a given encrypted message. If a contradiction is found during mapping\n construction, or not all letters are represented in the mapping, the function returns \"Failed\".\n \n Args:\n encoded (str): A string representing the encoded information.\n original (str): A string representing the original information corresponding to the encoded string.\n message (str): A string representing the encrypted message to be decoded.\n \n Returns:\n str: The decoded message if successful, or \"Failed\" if the decoding is not possible.\n \n Examples:\n >>> decode(\"AA\", \"AB\", \"EOWIE\")\n 'Failed' \n >>> decode(\"MSRTZCJKPFLQYVAWBINXUEDGHOOILSMIJFRCOPPQCEUNYDUMPP\", \"YIZSDWAHLNOVFUCERKJXQMGTBPPKOIYKANZWPLLVWMQJFGQYLL\", \"FLSO\")\n 'NOIP'\n ",
"ground-truth": null,
"prediction": [
"def decode(encoded: str, original: str, message: str) -> str:\n mapping = {}\n for i in range(len(encoded)):\n if encoded[i] not in mapping:\n mapping[encoded[i]] = original[i]\n else:\n return \"Failed\"\n \n decoded = \"\"\n for char in message:\n if char in mapping:\n decoded += mapping[char]\n else:\n return \"Failed\"\n \n return decoded",
"def decode(encoded: str, original: str, message: str) -> str:\n mapping = {}\n for i in range(len(encoded)):\n if encoded[i] not in mapping:\n mapping[encoded[i]] = original[i]\n else:\n if mapping[encoded[i]] != original[i]:\n return \"Failed\"\n if len(mapping) != len(encoded):\n return \"Failed\"\n decoded_message = \"\"\n for letter in message:\n if letter in mapping:\n decoded_message += mapping[letter]\n else:\n return \"Failed\"\n return decoded_message",
"def decode(encoded: str, original: str, message: str) -> str:\n mapping = {}\n for i in range(len(encoded)):\n if encoded[i] not in mapping:\n mapping[encoded[i]] = original[i]\n else:\n if mapping[encoded[i]] != original[i]:\n return \"Failed\"\n \n decoded_message = \"\"\n for letter in message:\n if letter in mapping:\n decoded_message += mapping[letter]\n else:\n return \"Failed\"\n \n return decoded_message\n\n# Test cases\nprint(decode(\"AA\", \"AB\", \"EOWIE\")) # Should return 'Failed'\nprint(decode(\"MSRTZCJKPFLQYVAWBINXUEDGHOOILSMIJFRCOPPQCEUNYDUMPP\", \"YIZSDWAHLNOVFUCERKJXQMGTBPPKOIYKANZWPLLVWMQJFGQYLL\", \"FLSO\")) # Should return 'NOIP'",
"def decode(encoded: str, original: str, message: str) -> str:\n mapping = {}\n for i in range(len(encoded)):\n if encoded[i] not in mapping:\n mapping[encoded[i]] = original[i]\n else:\n if mapping[encoded[i]] != original[i]:\n return \"Failed\"\n if len(mapping) != len(encoded):\n return \"Failed\"\n return ''.join([mapping.get(c, c) for c in message])",
"def decode(encoded: str, original: str, message: str) -> str:\n mapping = {}\n for i in range(len(encoded)):\n if encoded[i] not in mapping:\n mapping[encoded[i]] = original[i]\n else:\n return \"Failed\"\n \n decoded_message = \"\"\n for letter in message:\n if letter in mapping:\n decoded_message += mapping[letter]\n else:\n return \"Failed\"\n \n return decoded_message"
],
"moe_id": {
"python": 0.1318,
"cpp": 0.1517,
"swift": 0.0888,
"rust": 0.1366,
"csharp": 0.111,
"java": 0.1131,
"php": 0.0818,
"typescript": 0.1169,
"shell": 0.0682
}
},
{
"source": "Write a python function 'def largest_prime_factor(n: int) -> int:' to solve the following problem:\n\n Find the largest prime factor of a given positive integer.\n \n The integer is assumed to be the product of exactly two distinct prime numbers. \n The function iterates through potential factors starting from the smallest prime (2) \n and checks if they are a factor of 'n'. If a factor is found, the function returns \n the division of 'n' by this factor, which is the larger prime factor. If no factors \n are found up to the square root of 'n', then 'n' itself is a prime number and is \n returned as the largest prime factor.\n \n Args:\n n (int): The positive integer to factorize, which is the product of two distinct primes.\n \n Returns:\n int: The larger of the two prime factors of 'n'.\n \n Examples:\n >>> largest_prime_factor(21)\n 7\n >>> largest_prime_factor(15)\n 5\n ",
"ground-truth": null,
"prediction": [
"def largest_prime_factor(n: int) -> int:\n \"\"\"\n Find the largest prime factor of a given positive integer.\n \n Args:\n n (int): The positive integer to factorize, which is the product of two distinct primes.\n \n Returns:\n int: The larger of the two prime factors of 'n'.\n \n Examples:\n >>> largest_prime_factor(21)\n 7\n >>> largest_prime_factor(15)\n 5\n \n \"\"\"\n if n <= 1:\n raise ValueError(\"Input must be a positive integer greater than 1.\")\n \n # Initialize the largest prime factor\n largest_prime = None\n \n # Check for divisibility by 2\n while n % 2 == 0:\n largest_prime = 2\n n //= 2\n \n # Check for divisibility by odd numbers starting from 3\n for i in range(3, int(n**0.5) + 1, 2):\n while n % i == 0:\n largest_prime = i\n n //= i\n \n # If n is still greater than 2, then 'n' is a prime number\n if n > 2:\n largest_prime = n\n \n return largest_prime",
"def largest_prime_factor(n: int) -> int:\n \"\"\"\n Find the largest prime factor of a given positive integer.\n \n Args:\n n (int): The positive integer to factorize, which is the product of two distinct primes.\n \n Returns:\n int: The larger of the two prime factors of 'n'.\n \n Examples:\n >>> largest_prime_factor(21)\n 7\n >>> largest_prime_factor(15)\n 5\n \n \"\"\"\n largest_factor = 1\n # Check for divisibility by 2\n while n % 2 == 0:\n largest_factor = 2\n n //= 2\n \n # Check for divisibility by odd numbers starting from 3\n for i in range(3, int(n**0.5) + 1, 2):\n while n % i == 0:\n largest_factor = i\n n //= i\n \n # If n is a prime number greater than 2\n if n > 2:\n largest_factor = n\n \n return largest_factor",
"def largest_prime_factor(n: int) -> int:\n \"\"\"\n Find the largest prime factor of a given positive integer.\n \n Args:\n n (int): The positive integer to factorize, which is the product of two distinct primes.\n \n Returns:\n int: The larger of the two prime factors of 'n'.\n \n Examples:\n >>> largest_prime_factor(21)\n 7\n >>> largest_prime_factor(15)\n 5\n \n \"\"\"\n if n <= 1:\n raise ValueError(\"Input must be a positive integer greater than 1.\")\n \n # Initialize the largest prime factor\n largest_prime = None\n \n # Check for divisibility by 2\n while n % 2 == 0:\n largest_prime = 2\n n //= 2\n \n # Check for odd factors\n for i in range(3, int(n**0.5) + 1, 2):\n while n % i == 0:\n largest_prime = i\n n //= i\n \n # If n is a prime number greater than 2\n if n > 2:\n largest_prime = n\n \n return largest_prime",
"def largest_prime_factor(n: int) -> int:\n \"\"\"\n Find the largest prime factor of a given positive integer.\n \n Args:\n n (int): The positive integer to factorize, which is the product of two distinct primes.\n \n Returns:\n int: The larger of the two prime factors of 'n'.\n \n Examples:\n >>> largest_prime_factor(21)\n 7\n >>> largest_prime_factor(15)\n 5\n \n \"\"\"\n if n <= 1:\n raise ValueError(\"Input must be a positive integer greater than 1.\")\n \n # Check for divisibility by 2\n while n % 2 == 0:\n n //= 2\n \n # Check for divisibility by odd numbers\n factor = 3\n max_factor = int(n ** 0.5) + 1\n while factor <= max_factor:\n while n % factor == 0:\n n //= factor\n factor += 2\n \n # If n is still greater than 2, it is a prime number\n if n > 2:\n return n\n else:\n return factor\n\n# Test cases to verify the solution\nprint(largest_prime_factor(21)) # Expected output: 7\nprint(largest_prime_factor(15)) # Expected output: 5",
"def largest_prime_factor(n: int) -> int:\n \"\"\"\n Find the largest prime factor of a given positive integer.\n \n Args:\n n (int): The positive integer to factorize, which is the product of two distinct primes.\n \n Returns:\n int: The larger of the two prime factors of 'n'.\n \n Examples:\n >>> largest_prime_factor(21)\n 7\n >>> largest_prime_factor(15)\n 5\n \n \"\"\"\n # Check if n is a prime number\n if n <= 1:\n return None\n if n <= 3:\n return n\n \n # Initialize the largest prime factor\n largest_prime = None\n \n # Check for divisibility by 2\n while n % 2 == 0:\n largest_prime = 2\n n //= 2\n \n # Check for divisibility by odd numbers\n for i in range(3, int(n**0.5) + 1, 2):\n while n % i == 0:\n largest_prime = i\n n //= i\n \n # If n is a prime number greater than 2\n if n > 2:\n largest_prime = n\n \n return largest_prime"
],
"moe_id": {
"python": 0.1451,
"cpp": 0.2083,
"swift": 0.0524,
"rust": 0.1477,
"csharp": 0.0687,
"java": 0.1118,
"php": 0.0501,
"typescript": 0.1436,
"shell": 0.0723
}
},
{
"source": "Write a python function 'def count_partitions(n: int, k: int, x: int) -> int:' to solve the following problem:\n\n Count the number of ways to partition an integer n into k parts,\n where each part is at least x and order of parts does not matter.\n\n Parameters:\n n (int): The integer to be partitioned.\n k (int): The number of parts to divide n into.\n x (int): The minimum value for each part.\n\n Returns:\n int: The number of distinct partitioning ways.\n\n Examples:\n >>> count_partitions(7, 3, 1)\n 4\n >>> count_partitions(6, 2, 1)\n 3\n ",
"ground-truth": null,
"prediction": [
"def count_partitions(n: int, k: int, x: int) -> int:\n \"\"\"\n Count the number of ways to partition an integer n into k parts,\n where each part is at least x and order of parts does not matter.\n\n Parameters:\n n (int): The integer to be partitioned.\n k (int): The number of parts to divide n into.\n x (int): The minimum value for each part.\n\n Returns:\n int: The number of distinct partitioning ways.\n\n Examples:\n >>> count_partitions(7, 3, 1)\n 4\n >>> count_partitions(6, 2, 1)\n 3\n \"\"\"\n # Initialize a 2D array to store the number of ways to partition\n # up to n with up to k parts, where each part is at least x.\n dp = [[0 for _ in range(k + 1)] for _ in range(n + 1)]\n\n # Base case: There is one way to partition 0 into any number of parts.\n for i in range(k + 1):\n dp[0][i] = 1\n\n # Fill the dp array\n for i in range(1, n + 1):\n for j in range(1, min(i, k) + 1):\n dp[i][j] = dp[i - 1][j]\n if i >= x:\n dp[i][j] += dp[i - x][j - 1]\n\n return dp[n][k]",
"def count_partitions(n: int, k: int, x: int) -> int:\n \"\"\"\n Count the number of ways to partition an integer n into k parts,\n where each part is at least x and order of parts does not matter.\n \n Parameters:\n n (int): The integer to be partitioned.\n k (int): The number of parts to divide n into.\n x (int): The minimum value for each part.\n \n Returns:\n int: The number of distinct partitioning ways.\n \n Examples:\n >>> count_partitions(7, 3, 1)\n 4\n >>> count_partitions(6, 2, 1)\n 3\n \"\"\"\n # Initialize a 2D array to store the number of ways to partition\n # up to n with up to k parts, where each part is at least x.\n dp = [[0] * (k + 1) for _ in range(n + 1)]\n \n # Base case: There is one way to partition 0 into any number of parts.\n for i in range(k + 1):\n dp[0][i] = 1\n \n # Fill the dp array using the recurrence relation.\n for i in range(1, n + 1):\n for j in range(1, min(i, k) + 1):\n dp[i][j] = dp[i - 1][j] + dp[i - x][j - 1]\n \n return dp[n][k]",
"def count_partitions(n: int, k: int, x: int) -> int:\n \"\"\"\n Count the number of ways to partition an integer n into k parts,\n where each part is at least x and order of parts does not matter.\n\n Parameters:\n n (int): The integer to be partitioned.\n k (int): The number of parts to divide n into.\n x (int): The minimum value for each part.\n\n Returns:\n int: The number of distinct partitioning ways.\n\n Examples:\n >>> count_partitions(7, 3, 1)\n 4\n >>> count_partitions(6, 2, 1)\n 3\n \"\"\"\n if k == 1:\n return 1 if n >= x else 0\n if n < k * x:\n return 0\n return count_partitions(n - x, k, x) + count_partitions(n - 1, k - 1, x)",
"def count_partitions(n: int, k: int, x: int) -> int:\n \"\"\"\n Count the number of ways to partition an integer n into k parts,\n where each part is at least x and order of parts does not matter.\n\n Parameters:\n n (int): The integer to be partitioned.\n k (int): The number of parts to divide n into.\n x (int): The minimum value for each part.\n\n Returns:\n int: The number of distinct partitioning ways.\n\n Examples:\n >>> count_partitions(7, 3, 1)\n 4\n >>> count_partitions(6, 2, 1)\n 3\n \"\"\"\n # Initialize a 2D array to store the partition counts\n dp = [[0 for _ in range(k + 1)] for _ in range(n + 1)]\n\n # Base case: There is one way to partition 0 into any number of parts\n for i in range(k + 1):\n dp[0][i] = 1\n\n # Fill the dp array\n for i in range(1, n + 1):\n for j in range(1, min(i, k) + 1):\n dp[i][j] = dp[i - 1][j]\n if i >= x:\n dp[i][j] += dp[i - x][j - 1]\n\n return dp[n][k]",
"def count_partitions(n: int, k: int, x: int) -> int:\n \"\"\"\n Count the number of ways to partition an integer n into k parts,\n where each part is at least x and order of parts does not matter.\n\n Parameters:\n n (int): The integer to be partitioned.\n k (int): The number of parts to divide n into.\n x (int): The minimum value for each part.\n\n Returns:\n int: The number of distinct partitioning ways.\n\n Examples:\n >>> count_partitions(7, 3, 1)\n 4\n >>> count_partitions(6, 2, 1)\n 3\n \"\"\"\n # Initialize a 2D array to store the number of ways to partition\n # up to n with up to k parts, where each part is at least x.\n dp = [[0 for _ in range(k + 1)] for _ in range(n + 1)]\n\n # Base case: There is one way to partition 0 into any number of parts.\n for i in range(k + 1):\n dp[0][i] = 1\n\n # Fill the dp array\n for i in range(1, n + 1):\n for j in range(1, min(i, k) + 1):\n dp[i][j] = dp[i - 1][j] + dp[i - x][j - 1]\n\n return dp[n][k]"
],
"moe_id": {
"python": 0.1623,
"cpp": 0.1914,
"swift": 0.0538,
"rust": 0.1295,
"csharp": 0.0849,
"java": 0.1346,
"php": 0.0541,
"typescript": 0.163,
"shell": 0.0264
}
},
{
"source": "Write a python function 'def count_sequences(n: int, last: int, memo: dict) -> int:' to solve the following problem:\n\n Calculate the number of valid sequences that can be formed according to specific rules.\n \n Each sequence starts with a given number 'n', and a new number can be appended to the sequence\n if it is a positive integer and not greater than half the last number in the sequence. This\n function uses memoization to store previously calculated results to optimize performance.\n \n Args:\n n (int): The starting number of the sequence.\n last (int): The last number in the current sequence.\n memo (dict): A dictionary used for memoization, storing the number of valid sequences\n for each 'last' value encountered.\n \n Returns:\n int: The total number of valid sequences that can be formed starting with 'n'.\n \n Examples:\n >>> count_sequences(1, 1, {})\n 1\n >>> count_sequences(6, 6, {})\n 6\n ",
"ground-truth": null,
"prediction": [
"def count_sequences(n: int, last: int, memo: dict) -> int:\n if last not in memo:\n memo[last] = 0\n for i in range(1, last // 2 + 1):\n memo[last] += count_sequences(n, i, memo)\n return memo[last] + 1 # Add 1 for the sequence starting with 'n' itself\n\n# Test cases to verify the solution\nprint(count_sequences(1, 1, {})) # Expected output: 1\nprint(count_sequences(6, 6, {})) # Expected output: 6",
"def count_sequences(n: int, last: int, memo: dict) -> int:\n if last not in memo:\n memo[last] = 1\n for i in range(1, last // 2 + 1):\n memo[last] += count_sequences(n, i, memo)\n return memo[last]",
"def count_sequences(n: int, last: int, memo: dict) -> int:\n if last in memo:\n return memo[last]\n \n count = 0\n for i in range(1, last // 2 + 1):\n count += count_sequences(n, i, memo)\n \n memo[last] = count\n return count\n\n# Test cases\nprint(count_sequences(1, 1, {})) # Output: 1\nprint(count_sequences(6, 6, {})) # Output: 6",
"def count_sequences(n: int, last: int, memo: dict) -> int:\n if last not in memo:\n memo[last] = 0\n for i in range(1, last // 2 + 1):\n memo[last] += count_sequences(n, i, memo)\n return memo[last]",
"def count_sequences(n: int, last: int, memo: dict) -> int:\n if last in memo:\n return memo[last]\n \n count = 0\n for i in range(1, last // 2 + 1):\n count += count_sequences(n, i, memo)\n \n memo[last] = count\n return count\n\n# Test cases\nprint(count_sequences(1, 1, {})) # Output: 1\nprint(count_sequences(6, 6, {})) # Output: 6"
],
"moe_id": {
"python": 0.1562,
"cpp": 0.1615,
"swift": 0.0599,
"rust": 0.1431,
"csharp": 0.0893,
"java": 0.133,
"php": 0.0698,
"typescript": 0.1185,
"shell": 0.0686
}
},
{
"source": "Write a python function 'def count_coprime_pairs(x0: int, y0: int) -> int:' to solve the following problem:\n\n Counts the number of pairs of positive integers (P, Q) such that P and Q have x0 as their greatest common divisor (GCD)\n and y0 as their least common multiple (LCM).\n\n Args:\n x0 (int): The GCD that each pair (P, Q) must have.\n y0 (int): The LCM that each pair (P, Q) must have.\n\n Returns:\n int: The count of all possible pairs (P, Q) that meet the specified criteria.\n\n The function iterates through all possible factors 'a' of the quotient 'y0 / x0'. For each factor 'a',\n it calculates the corresponding factor 'b' such that 'a * b = y0 / x0'. It then checks if 'a' and 'b'\n are co-prime (their GCD is 1) because P and Q can only be multiples of 'x0' by co-prime factors to maintain\n the GCD as 'x0'. If 'a' and 'b' are co-prime, the count is incremented by 1 if 'a' is the same as 'b',\n else by 2 to account for both (P, Q) and (Q, P) pairs.\n\n Example Cases:\n\n >>> count_coprime_pairs(3, 60)\n 4\n >>> count_coprime_pairs(2, 50)\n 0\n ",
"ground-truth": null,
"prediction": [
"def count_coprime_pairs(x0: int, y0: int) -> int:\n count = 0\n quotient = y0 // x0\n for a in range(1, quotient + 1):\n b = quotient // a\n if a == b:\n count += 1\n else:\n count += 2\n return count",
"def count_coprime_pairs(x0: int, y0: int) -> int:\n count = 0\n quotient = y0 // x0\n for a in range(1, quotient + 1):\n b = quotient // a\n if a == b:\n count += 1\n else:\n count += 2\n return count",
"def count_coprime_pairs(x0: int, y0: int) -> int:\n count = 0\n quotient = y0 // x0\n for a in range(1, quotient + 1):\n b = quotient // a\n if a == b:\n count += 1\n else:\n count += 2\n return count\n\n# Test cases\nprint(count_coprime_pairs(3, 60)) # Output: 4\nprint(count_coprime_pairs(2, 50)) # Output: 0",
"def count_coprime_pairs(x0: int, y0: int) -> int:\n count = 0\n quotient = y0 // x0\n for a in range(1, quotient + 1):\n b = quotient // a\n if a == b:\n count += 1\n else:\n count += 2\n return count",
"def count_coprime_pairs(x0: int, y0: int) -> int:\n count = 0\n for a in range(1, y0 // x0 + 1):\n b = y0 // x0 // a\n if a == b:\n count += 1\n else:\n count += 2\n return count"
],
"moe_id": {
"python": 0.0963,
"cpp": 0.207,
"swift": 0.0764,
"rust": 0.0789,
"csharp": 0.0991,
"java": 0.0799,
"php": 0.0613,
"typescript": 0.2042,
"shell": 0.0967
}
},
{
"source": "Write a python function 'def preorder_traversal(inorder: str, postorder: str) -> str:' to solve the following problem:\n\n Reconstructs the binary tree from its inorder and postorder traversals and\n returns the preorder traversal as a string.\n\n Args:\n inorder (str): The inorder traversal of the binary tree.\n postorder (str): The postorder traversal of the binary tree.\n\n Returns:\n str: The preorder traversal of the binary tree.\n\n Example:\n >>> preorder_traversal('BADC', 'BDCA')\n 'ABCD'\n >>> preorder_traversal('A', 'A')\n 'A'\n ",
"ground-truth": null,
"prediction": [
"def preorder_traversal(inorder: str, postorder: str) -> str:\n if not inorder or not postorder:\n return \"\"\n\n root = postorder[-1]\n root_index = inorder.index(root)\n\n left_inorder = inorder[:root_index]\n right_inorder = inorder[root_index + 1:]\n\n left_postorder = postorder[:len(left_inorder)]\n right_postorder = postorder[len(left_inorder):-1]\n\n return root + preorder_traversal(left_inorder, left_postorder) + preorder_traversal(right_inorder, right_postorder)",
"def preorder_traversal(inorder: str, postorder: str) -> str:\n if not inorder or not postorder:\n return ''\n \n root = postorder[-1]\n root_index = inorder.index(root)\n \n left_inorder = inorder[:root_index]\n right_inorder = inorder[root_index + 1:]\n \n left_postorder = postorder[:len(left_inorder)]\n right_postorder = postorder[len(left_inorder):-1]\n \n return root + preorder_traversal(left_inorder, left_postorder) + preorder_traversal(right_inorder, right_postorder)",
"def preorder_traversal(inorder: str, postorder: str) -> str:\n if not inorder or not postorder:\n return ''\n\n root = postorder[-1]\n index = inorder.index(root)\n\n left_inorder = inorder[:index]\n right_inorder = inorder[index + 1:]\n\n left_postorder = postorder[:len(left_inorder)]\n right_postorder = postorder[len(left_inorder):-1]\n\n return root + preorder_traversal(left_inorder, left_postorder) + preorder_traversal(right_inorder, right_postorder)",
"def preorder_traversal(inorder: str, postorder: str) -> str:\n if not inorder:\n return ''\n root = postorder[-1]\n index = inorder.index(root)\n left_inorder = inorder[:index]\n right_inorder = inorder[index + 1:]\n left_postorder = postorder[:len(left_inorder)]\n right_postorder = postorder[len(left_inorder):-1]\n return root + preorder_traversal(left_inorder, left_postorder) + preorder_traversal(right_inorder, right_postorder)",
"def preorder_traversal(inorder: str, postorder: str) -> str:\n if not inorder or not postorder:\n return ''\n\n root = postorder[-1]\n root_index = inorder.index(root)\n\n left_inorder = inorder[:root_index]\n right_inorder = inorder[root_index + 1:]\n\n left_postorder = postorder[:len(left_inorder)]\n right_postorder = postorder[len(left_inorder):-1]\n\n return root + preorder_traversal(left_inorder, left_postorder) + preorder_traversal(right_inorder, right_postorder)"
],
"moe_id": {
"python": 0.1592,
"cpp": 0.0381,
"swift": 0.0962,
"rust": 0.1553,
"csharp": 0.1121,
"java": 0.1413,
"php": 0.0815,
"typescript": 0.1795,
"shell": 0.0368
}
},
{
"source": "Write a python function 'def string_transformation(A: str, B: str, rules: list) -> Union[int, str]:' to solve the following problem:\n\n Perform string transformation from A to B using a set of transformation rules.\n\n This function takes an initial string A and a target string B, along with a list\n of transformation rules, and attempts to transform A into B using the rules.\n A Breadth-First Search (BFS) algorithm is used to explore the possible transformations\n up to a maximum of 10 steps. If A can be transformed into B within 10 steps, the function\n returns the minimum number of steps required. If it's not possible, the function returns\n \"NO ANSWER!\".\n\n Parameters:\n A (str): The initial string to be transformed.\n B (str): The target string to be achieved.\n rules (list of tuples): A list of transformation rules, where each rule is a tuple\n containing the source substring (to be replaced) and the\n target substring (to replace with).\n\n Returns:\n Union[int, str]: The minimum number of transformation steps if possible, otherwise \"NO ANSWER!\".\n\n Examples:\n >>> string_transformation(\"abcd\", \"xyz\", [(\"abc\", \"xu\"), (\"ud\", \"y\"), (\"y\", \"yz\")])\n 3\n >>> string_transformation(\"aaa\", \"bbbb\", [(\"a\", \"b\"), (\"aa\", \"bb\"), (\"aaa\", \"bbb\")])\n 'NO ANSWER!'\n ",
"ground-truth": null,
"prediction": [
"from typing import List, Tuple, Union\nfrom collections import deque\n\ndef string_transformation(A: str, B: str, rules: List[Tuple[str, str]]) -> Union[int, str]:\n if A == B:\n return 0\n\n queue = deque([(A, 0)])\n visited = set([A])\n\n while queue:\n current, steps = queue.popleft()\n if current == B:\n return steps\n\n for rule in rules:\n if current.startswith(rule[0]):\n new_string = current.replace(rule[0], rule[1], 1)\n if new_string not in visited:\n visited.add(new_string)\n queue.append((new_string, steps + 1))\n\n if steps >= 10:\n break\n\n return \"NO ANSWER!\"",
"from typing import List, Union, Tuple\nfrom collections import deque\n\ndef string_transformation(A: str, B: str, rules: List[Tuple[str, str]]) -> Union[int, str]:\n if A == B:\n return 0\n\n queue = deque([(A, 0)])\n visited = set([A])\n\n while queue:\n current, steps = queue.popleft()\n\n if current == B:\n return steps\n\n for rule in rules:\n if current.startswith(rule[0]):\n new_string = current.replace(rule[0], rule[1], 1)\n if new_string not in visited:\n visited.add(new_string)\n queue.append((new_string, steps + 1))\n\n if steps == 9:\n break\n\n return \"NO ANSWER!\"",
"from typing import List, Tuple, Union\nfrom collections import deque\n\ndef string_transformation(A: str, B: str, rules: List[Tuple[str, str]]) -> Union[int, str]:\n if A == B:\n return 0\n\n queue = deque([(A, 0)])\n visited = set([A])\n\n while queue:\n current, steps = queue.popleft()\n if current == B:\n return steps\n\n for rule in rules:\n if current.startswith(rule[0]):\n new_string = current.replace(rule[0], rule[1], 1)\n if new_string not in visited:\n visited.add(new_string)\n queue.append((new_string, steps + 1))\n\n if steps == 9:\n return \"NO ANSWER!\"\n\n return \"NO ANSWER!\"",
"from typing import List, Tuple, Union\nfrom collections import deque\n\ndef string_transformation(A: str, B: str, rules: List[Tuple[str, str]]) -> Union[int, str]:\n if A == B:\n return 0\n\n queue = deque([(A, 0)])\n visited = set([A])\n\n while queue:\n current, steps = queue.popleft()\n\n if current == B:\n return steps\n\n for rule in rules:\n if current.startswith(rule[0]):\n new_string = current.replace(rule[0], rule[1], 1)\n if new_string not in visited:\n visited.add(new_string)\n queue.append((new_string, steps + 1))\n\n if steps >= 10:\n return \"NO ANSWER!\"\n\n return \"NO ANSWER!\"",
"from typing import List, Tuple, Union\nfrom collections import deque\n\ndef string_transformation(A: str, B: str, rules: List[Tuple[str, str]]) -> Union[int, str]:\n if A == B:\n return 0\n\n queue = deque([(A, 0)])\n visited = set([A])\n\n while queue:\n current, steps = queue.popleft()\n\n if current == B:\n return steps\n\n for rule in rules:\n if current.startswith(rule[0]):\n new_string = current.replace(rule[0], rule[1], 1)\n if new_string not in visited:\n visited.add(new_string)\n queue.append((new_string, steps + 1))\n\n if steps >= 10:\n break\n\n return \"NO ANSWER!\""
],
"moe_id": {
"python": 0.0965,
"cpp": 0.1693,
"swift": 0.0896,
"rust": 0.1016,
"csharp": 0.0999,
"java": 0.0826,
"php": 0.0618,
"typescript": 0.1799,
"shell": 0.1187
}
},
{
"source": "Write a python function 'def find_min_n_greater_than_k(k: int) -> int:' to solve the following problem:\n\n Calculate the smallest positive integer n such that the sum of the harmonic series\n up to 1/n is greater than a given positive integer k.\n\n The harmonic series is defined as S_n = 1 + 1/2 + 1/3 + ... + 1/n.\n\n Args:\n - k (int): A positive integer representing the threshold value the harmonic series sum must exceed.\n\n Returns:\n - int: The smallest integer n for which the harmonic series sum S_n exceeds the threshold k.\n\n Examples:\n >>> find_min_n_greater_than_k(1)\n 2\n >>> find_min_n_greater_than_k(3)\n 11\n ",
"ground-truth": null,
"prediction": [
"def find_min_n_greater_than_k(k: int) -> int:\n n = 1\n harmonic_sum = 0.0\n\n while harmonic_sum <= k:\n n += 1\n harmonic_sum += 1 / n\n\n return n",
"def find_min_n_greater_than_k(k: int) -> int:\n n = 1\n harmonic_sum = 0.0\n\n while harmonic_sum <= k:\n harmonic_sum += 1 / n\n n += 1\n\n return n - 1",
"def find_min_n_greater_than_k(k: int) -> int:\n n = 1\n harmonic_sum = 0.0\n\n while harmonic_sum <= k:\n n += 1\n harmonic_sum += 1 / n\n\n return n",
"def find_min_n_greater_than_k(k: int) -> int:\n n = 1\n harmonic_sum = 0.0\n\n while harmonic_sum <= k:\n n += 1\n harmonic_sum += 1 / n\n\n return n",
"def find_min_n_greater_than_k(k: int) -> int:\n n = 1\n harmonic_sum = 0.0\n\n while True:\n harmonic_sum += 1 / n\n if harmonic_sum > k:\n return n\n n += 1"
],
"moe_id": {
"python": 0.1065,
"cpp": 0.3897,
"swift": 0.056,
"rust": 0.09,
"csharp": 0.0513,
"java": 0.0959,
"php": 0.0299,
"typescript": 0.1406,
"shell": 0.0401
}
},
{
"source": "Write a python function 'def is_prime(num: int) -> bool:' to solve the following problem:\n\n Determine whether a given integer is a prime number.\n\n A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The function checks for primality by eliminating non-prime numbers using several tests. First, it handles edge cases for numbers less than or equal to 1, which are not prime, and small numbers (2 and 3) which are prime. It then checks for divisibility by 2 and 3. For larger numbers, it uses a 6k +/- 1 optimization to test for factors up to the square root of the number.\n\n Args:\n num (int): The integer to check for primality.\n\n Returns:\n bool: True if `num` is a prime number, False otherwise.\n\n Cases:\n >>> is_prime(2)\n True\n >>> is_prime(15)\n False\n ",
"ground-truth": null,
"prediction": [
"def is_prime(num: int) -> bool:\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i = 5\n while i * i <= num:\n if num % i == 0 or num % (i + 2) == 0:\n return False\n i += 6\n return True",
"def is_prime(num: int) -> bool:\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i = 5\n while i * i <= num:\n if num % i == 0 or num % (i + 2) == 0:\n return False\n i += 6\n return True",
"def is_prime(num: int) -> bool:\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i = 5\n while i * i <= num:\n if num % i == 0 or num % (i + 2) == 0:\n return False\n i += 6\n return True",
"def is_prime(num: int) -> bool:\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i = 5\n while i * i <= num:\n if num % i == 0 or num % (i + 2) == 0:\n return False\n i += 6\n return True",
"def is_prime(num: int) -> bool:\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i = 5\n while i * i <= num:\n if num % i == 0 or num % (i + 2) == 0:\n return False\n i += 6\n return True\n\n# Test cases\nprint(is_prime(2)) # True\nprint(is_prime(15)) # False"
],
"moe_id": {
"python": 0.178,
"cpp": 0.1334,
"swift": 0.0654,
"rust": 0.1743,
"csharp": 0.0949,
"java": 0.1229,
"php": 0.0681,
"typescript": 0.1173,
"shell": 0.0456
}
},
{
"source": "Write a python function 'def generate_numbers(n, rules) -> int:' to solve the following problem:\n\n Generate all unique numbers from the given number by applying transformation rules.\n\n Each rule allows a single digit to be transformed into another. A breadth-first search\n (BFS) is used to explore all possible transformations. The function returns the count\n of unique numbers that can be generated from the original number, including the number itself.\n\n Args:\n - n (int): The original integer number to transform.\n - rules (list of tuples): A list of transformation rules, where each rule is represented\n as a tuple (x, y) indicating that digit x can be transformed into y.\n\n Returns:\n - int: The total count of unique numbers that can be generated.\n\n Cases:\n >>> generate_numbers(234, [(2, 5), (3, 6)])\n 4\n >>> generate_numbers(100, [(1, 9)])\n 2\n ",
"ground-truth": null,
"prediction": [
"from collections import deque\n\ndef generate_numbers(n, rules):\n \"\"\"\n Generate all unique numbers from the given number by applying transformation rules.\n\n Each rule allows a single digit to be transformed into another. A breadth-first search\n (BFS) is used to explore all possible transformations. The function returns the count\n of unique numbers that can be generated from the original number, including the number itself.\n\n Args:\n - n (int): The original integer number to transform.\n - rules (list of tuples): A list of transformation rules, where each rule is represented\n as a tuple (x, y) indicating that digit x can be transformed into y.\n\n Returns:\n - int: The total count of unique numbers that can be generated.\n\n Cases:\n >>> generate_numbers(234, [(2, 5), (3, 6)])\n 4\n >>> generate_numbers(100, [(1, 9)])\n 2\n \"\"\"\n visited = set()\n queue = deque([n])\n visited.add(n)\n\n while queue:\n current = queue.popleft()\n for rule in rules:\n new_number = current * 10 + rule[1]\n if new_number not in visited:\n visited.add(new_number)\n queue.append(new_number)\n\n return len(visited)",
"from collections import deque\n\ndef generate_numbers(n, rules):\n # Convert the number to a string to easily iterate over its digits\n n_str = str(n)\n # Initialize a set to keep track of unique numbers\n unique_numbers = set()\n # Initialize a queue with the original number\n queue = deque([n_str])\n \n # Perform BFS\n while queue:\n # Get the current number as a string\n current_number = queue.popleft()\n # Convert the current number to an integer\n current_int = int(current_number)\n # Add the current number to the set of unique numbers\n unique_numbers.add(current_int)\n \n # Iterate over each digit in the current number\n for i, digit in enumerate(current_number):\n # Iterate over each transformation rule\n for x, y in rules:\n # If the transformation rule applies to the current digit\n if digit == str(x):\n # Generate the new number by replacing the digit with the transformed one\n new_number = current_number[:i] + str(y) + current_number[i+1:]\n # Add the new number to the queue for further exploration\n queue.append(new_number)\n \n # Return the count of unique numbers\n return len(unique_numbers)\n\n# Test cases\nprint(generate_numbers(234, [(2, 5), (3, 6)])) # Output: 4\nprint(generate_numbers(100, [(1, 9)])) # Output: 2",
"from collections import deque\n\ndef generate_numbers(n, rules):\n \"\"\"\n Generate all unique numbers from the given number by applying transformation rules.\n\n Each rule allows a single digit to be transformed into another. A breadth-first search\n (BFS) is used to explore all possible transformations. The function returns the count\n of unique numbers that can be generated from the original number, including the number itself.\n\n Args:\n - n (int): The original integer number to transform.\n - rules (list of tuples): A list of transformation rules, where each rule is represented\n as a tuple (x, y) indicating that digit x can be transformed into y.\n\n Returns:\n - int: The total count of unique numbers that can be generated.\n\n Cases:\n >>> generate_numbers(234, [(2, 5), (3, 6)])\n 4\n >>> generate_numbers(100, [(1, 9)])\n 2\n \"\"\"\n visited = set()\n queue = deque([n])\n visited.add(n)\n\n while queue:\n current = queue.popleft()\n for rule in rules:\n if current % 10 == rule[0]:\n new_number = current // 10 * 10 + rule[1]\n if new_number not in visited:\n visited.add(new_number)\n queue.append(new_number)\n\n return len(visited)",
"from collections import deque\n\ndef generate_numbers(n, rules):\n \"\"\"\n Generate all unique numbers from the given number by applying transformation rules.\n\n Each rule allows a single digit to be transformed into another. A breadth-first search\n (BFS) is used to explore all possible transformations. The function returns the count\n of unique numbers that can be generated from the original number, including the number itself.\n\n Args:\n - n (int): The original integer number to transform.\n - rules (list of tuples): A list of transformation rules, where each rule is represented\n as a tuple (x, y) indicating that digit x can be transformed into y.\n\n Returns:\n - int: The total count of unique numbers that can be generated.\n\n Cases:\n >>> generate_numbers(234, [(2, 5), (3, 6)])\n 4\n >>> generate_numbers(100, [(1, 9)])\n 2\n \"\"\"\n # Convert the number to a list of digits\n digits = list(str(n))\n # Initialize a set to store unique numbers\n unique_numbers = set()\n # Initialize a queue for BFS\n queue = deque([digits])\n # Initialize a set to keep track of visited numbers\n visited = set()\n\n while queue:\n current_digits = queue.popleft()\n # Convert the current digits list back to an integer\n current_number = int(''.join(current_digits))\n # Add the current number to the set of unique numbers\n unique_numbers.add(current_number)\n # Mark the current number as visited\n visited.add(current_number)\n\n # Iterate through each digit in the current number\n for i, digit in enumerate(current_digits):\n # Iterate through each transformation rule\n for x, y in rules:\n # If the transformation rule applies to the current digit\n if digit == str(x):\n # Create a new list of digits by replacing the current digit with the transformed digit\n new_digits = current_digits[:i] + [y] + current_digits[i+1:]\n # If the new number has not been visited, add it to the queue\n if int(''.join(new_digits)) not in visited:\n queue.append(new_digits)\n visited.add(int(''.join(new_digits)))\n\n # Return the count of unique numbers\n return len(unique_numbers)",
"from collections import deque\n\ndef generate_numbers(n, rules):\n \"\"\"\n Generate all unique numbers from the given number by applying transformation rules.\n\n Each rule allows a single digit to be transformed into another. A breadth-first search\n (BFS) is used to explore all possible transformations. The function returns the count\n of unique numbers that can be generated from the original number, including the number itself.\n\n Args:\n - n (int): The original integer number to transform.\n - rules (list of tuples): A list of transformation rules, where each rule is represented\n as a tuple (x, y) indicating that digit x can be transformed into y.\n\n Returns:\n - int: The total count of unique numbers that can be generated.\n\n Cases:\n >>> generate_numbers(234, [(2, 5), (3, 6)])\n 4\n >>> generate_numbers(100, [(1, 9)])\n 2\n \"\"\"\n # Convert the number to a list of digits\n digits = [int(d) for d in str(n)]\n # Initialize a set to store unique numbers\n unique_numbers = set()\n # Initialize a queue for BFS\n queue = deque([digits])\n # Initialize a set to keep track of visited numbers\n visited = set([tuple(digits)])\n\n while queue:\n current_digits = queue.popleft()\n # Generate all possible next digits by applying rules\n for i, digit in enumerate(current_digits):\n for rule in rules:\n if digit == rule[0]:\n next_digits = current_digits[:]\n next_digits[i] = rule[1]\n # Convert the list of digits back to an integer\n next_number = int(''.join(map(str, next_digits)))\n # Check if the next number is unique and not visited\n if next_number not in visited:\n unique_numbers.add(next_number)\n visited.add(tuple(next_digits))\n queue.append(next_digits)\n\n return len(unique_numbers)"
],
"moe_id": {
"python": 0.1603,
"cpp": 0.1306,
"swift": 0.0658,
"rust": 0.1296,
"csharp": 0.0986,
"java": 0.133,
"php": 0.0799,
"typescript": 0.1275,
"shell": 0.0747
}
},
{
"source": "Write a python function 'def check_scenario(scenario: str, liar_count: set, statements: dict, days_of_week: set) -> bool:' to solve the following problem:\n\n Evaluates the consistency of a scenario where one participant is the criminal based on the given statements.\n\n This function takes a potential criminal's name (scenario) and a set of liars (liar_count) and checks if\n the statements made by all participants are consistent with this scenario, disregarding any statements\n about the day of the week.\n\n Parameters:\n - scenario (str): The name of the participant being tested as the potential criminal.\n - liar_count (set): A set of names of participants who are assumed to be liars.\n - statements (dict): A dictionary mapping participant names to lists of their respective statements.\n - days_of_week (set): A set of strings representing the days of the week.\n\n Returns:\n - bool: True if the scenario is consistent with the statements, False otherwise.\n\n Test Cases:\n >>> check_scenario(\"ALICE\", {\"BOB\", \"CHARLIE\"}, {\"ALICE\": [\"I am guilty.\"], \"BOB\": [\"ALICE is not guilty.\"], \"CHARLIE\": []}, {\"MONDAY\", \"TUESDAY\"})\n True\n ",
"ground-truth": null,
"prediction": [
"def check_scenario(scenario: str, liar_count: set, statements: dict, days_of_week: set) -> bool:\n for participant, statements_list in statements.items():\n if participant in liar_count:\n continue\n if scenario in statements_list:\n return False\n return True",
"def check_scenario(scenario: str, liar_count: set, statements: dict, days_of_week: set) -> bool:\n for participant, statements_list in statements.items():\n if participant in liar_count:\n continue\n for statement in statements_list:\n if scenario in statement:\n return False\n return True",
"def check_scenario(scenario: str, liar_count: set, statements: dict, days_of_week: set) -> bool:\n for participant, statements_list in statements.items():\n if participant in liar_count:\n continue\n if scenario in statements_list:\n return False\n return True",
"def check_scenario(scenario: str, liar_count: set, statements: dict, days_of_week: set) -> bool:\n for participant, statements_list in statements.items():\n if participant in liar_count:\n continue\n if scenario in statements_list:\n return False\n return True",
"def check_scenario(scenario: str, liar_count: set, statements: dict, days_of_week: set) -> bool:\n for participant, statements_list in statements.items():\n if participant in liar_count:\n continue\n for statement in statements_list:\n if scenario in statement:\n return False\n return True"
],
"moe_id": {
"python": 0.1436,
"cpp": 0.1383,
"swift": 0.1026,
"rust": 0.1236,
"csharp": 0.1142,
"java": 0.1145,
"php": 0.0952,
"typescript": 0.0988,
"shell": 0.0692
}
},
{
"source": "Write a python function 'def calculate_score(system: int, points: str) -> list:' to solve the following problem:\n\n Calculate the score of a series of ping-pong games based on the provided scoring system.\n\n This function takes in the desired scoring system (either 11 or 21 points) and a string \n representing the sequence of points won by the player ('W') and the opponent ('L'). \n The function processes the string and returns a list of game scores formatted as \"player_score:opponent_score\".\n\n The game is considered finished when one player reaches the system's required number of points \n (11 or 21) with at least a 2-point lead. If the sequence of points ends in the middle of a game, \n that game's current score is also included in the output.\n\n Args:\n - system (int): The number of points required to win a game (either 11 or 21).\n - points (str): A string of 'W' and 'L' characters denoting points won by the player and opponent.\n\n Returns:\n - list: A list of strings representing the score of each game.\n\n Cases:\n >>> calculate_score(11, \"WWWWWWWWWWL\")\n [\"10:1\"]\n ",
"ground-truth": null,
"prediction": [
"def calculate_score(system: int, points: str) -> list:\n scores = []\n player_score = 0\n opponent_score = 0\n game_score = \"\"\n\n for point in points:\n if point == 'W':\n player_score += 1\n else:\n opponent_score += 1\n\n game_score = f\"{player_score}:{opponent_score}\"\n\n if player_score == system or opponent_score == system:\n if player_score - opponent_score >= 2:\n scores.append(game_score)\n break\n elif player_score == opponent_score:\n scores.append(game_score)\n else:\n scores.append(game_score)\n\n return scores\n\n# Test cases\nprint(calculate_score(11, \"WWWWWWWWWWL\")) # Output: [\"10:1\"]\nprint(calculate_score(21, \"WWWWWWWWWWL\")) # Output: [\"20:1\"]\nprint(calculate_score(11, \"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"def calculate_score(system: int, points: str) -> list:\n scores = []\n player_score = 0\n opponent_score = 0\n for point in points:\n if point == 'W':\n player_score += 1\n else:\n opponent_score += 1\n if player_score == system or opponent_score == system:\n scores.append(f\"{player_score}:{opponent_score}\")\n if player_score == system:\n player_score = 0\n opponent_score = 0\n else:\n player_score = 0\n opponent_score = 0\n return scores\n\n# Test cases\nprint(calculate_score(11, \"WWWWWWWWWWL\")) # Output: ['10:1']\nprint(calculate_score(21, \"WWWWWWWWWWL\")) # Output: ['10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:1', '10:",
"def calculate_score(system: int, points: str) -> list:\n scores = []\n player_score = 0\n opponent_score = 0\n for point in points:\n if point == 'W':\n player_score += 1\n else:\n opponent_score += 1\n if player_score == system or opponent_score == system:\n scores.append(f\"{player_score}:{opponent_score}\")\n if player_score == system:\n player_score = 0\n opponent_score = 0\n else:\n player_score = 0\n opponent_score = 0\n return scores",
"def calculate_score(system: int, points: str) -> list:\n scores = []\n player_score = 0\n opponent_score = 0\n game_score = \"\"\n\n for point in points:\n if point == \"W\":\n player_score += 1\n else:\n opponent_score += 1\n\n game_score = f\"{player_score}:{opponent_score}\"\n scores.append(game_score)\n\n if player_score == system and opponent_score < player_score - 2:\n scores.append(game_score)\n elif opponent_score == system and player_score < opponent_score - 2:\n scores.append(game_score)\n\n return scores\n\n# Test cases\nprint(calculate_score(11, \"WWWWWWWWWWL\")) # Output: [\"10:1\"]\nprint(calculate_score(21, \"WWWWWWWWWWL\")) # Output: [\"10:1\", \"10:1\"]",
"def calculate_score(system: int, points: str) -> list:\n scores = []\n player_score = 0\n opponent_score = 0\n game_started = False\n\n for point in points:\n if point == 'W':\n player_score += 1\n else:\n opponent_score += 1\n\n if player_score == system or opponent_score == system:\n if player_score > opponent_score:\n scores.append(f\"{player_score}:{opponent_score}\")\n else:\n scores.append(f\"{opponent_score}:{player_score}\")\n game_started = True\n\n if game_started and (player_score == system - 2 or opponent_score == system - 2):\n scores.append(f\"{player_score}:{opponent_score}\")\n game_started = False\n\n return scores\n\n# Test cases\nprint(calculate_score(11, \"WWWWWWWWWWL\")) # Output: ['10:1']\nprint(calculate_score(21, \"WWWWWWWWWWL\")) # Output: ['20:1']"
],
"moe_id": {
"python": 0.1422,
"cpp": 0.168,
"swift": 0.1097,
"rust": 0.1098,
"csharp": 0.1201,
"java": 0.1145,
"php": 0.105,
"typescript": 0.0761,
"shell": 0.0545
}
},
{
"source": "Write a python function 'def catalan_number(n: int) -> int:' to solve the following problem:\n\n Calculate the nth Catalan number.\n\n The function computes the nth Catalan number using dynamic programming. Catalan numbers are a sequence of natural \n numbers that have many applications in combinatorial mathematics, including the counting of certain types of lattice paths, \n the number of expressions containing n pairs of parentheses which are correctly matched, the number of different ways n+1 \n factors can be completely parenthesized, and more.\n\n Args:\n - n (int): The position in the Catalan number sequence to compute (must be non-negative).\n\n Returns:\n - int: The nth Catalan number.\n\n Cases:\n catalan_number(0) -> 1\n catalan_number(3) -> 5\n catalan_number(5) -> 42\n Note:\n The computation is based on the recursive formula:\n C(n) = C(0)C(n-1) + C(1)C(n-2) + ... + C(n-1)C(0)\n where C(0) is 1.\n ",
"ground-truth": null,
"prediction": [
"def catalan_number(n: int) -> int:\n if n <= 1:\n return 1\n\n catalan = [0] * (n + 1)\n catalan[0] = catalan[1] = 1\n\n for i in range(2, n + 1):\n for j in range(i):\n catalan[i] += catalan[j] * catalan[i - j - 1]\n\n return catalan[n]\n\n# Test cases\nprint(catalan_number(0)) # Output: 1\nprint(catalan_number(3)) # Output: 5\nprint(catalan_number(5)) # Output: 42",
"def catalan_number(n: int) -> int:\n # Initialize a list to store Catalan numbers\n catalan = [0] * (n + 1)\n catalan[0] = catalan[1] = 1\n\n # Compute Catalan numbers using dynamic programming\n for i in range(2, n + 1):\n for j in range(i):\n catalan[i] += catalan[j] * catalan[i - j - 1]\n\n return catalan[n]\n\n# Test cases\nprint(catalan_number(0)) # Output: 1\nprint(catalan_number(3)) # Output: 5\nprint(catalan_number(5)) # Output: 42",
"def catalan_number(n: int) -> int:\n catalan = [0] * (n + 1)\n catalan[0] = 1 # Base case: C(0) = 1\n\n for i in range(1, n + 1):\n catalan[i] = 0\n for j in range(i):\n catalan[i] += catalan[j] * catalan[i - j - 1]\n\n return catalan[n]\n\n# Test cases to verify the correctness of the function\nassert catalan_number(0) == 1\nassert catalan_number(3) == 5\nassert catalan_number(5) == 42\n\nprint(\"All test cases passed!\")",
"def catalan_number(n: int) -> int:\n catalan = [0] * (n + 1)\n catalan[0] = 1 # C(0) is 1\n\n for i in range(1, n + 1):\n catalan[i] = 0\n for j in range(i):\n catalan[i] += catalan[j] * catalan[i - j - 1]\n\n return catalan[n]\n\n# Test cases\nprint(catalan_number(0)) # Output: 1\nprint(catalan_number(3)) # Output: 5\nprint(catalan_number(5)) # Output: 42",
"def catalan_number(n: int) -> int:\n catalan = [0] * (n + 1)\n catalan[0] = 1 # Base case: C(0) = 1\n\n # Compute Catalan numbers using dynamic programming\n for i in range(1, n + 1):\n catalan[i] = 0\n for j in range(i):\n catalan[i] += catalan[j] * catalan[i - j - 1]\n\n return catalan[n]\n\n# Test cases\nprint(catalan_number(0)) # Output: 1\nprint(catalan_number(3)) # Output: 5\nprint(catalan_number(5)) # Output: 42"
],
"moe_id": {
"python": 0.1109,
"cpp": 0.2582,
"swift": 0.1031,
"rust": 0.0979,
"csharp": 0.1028,
"java": 0.0738,
"php": 0.0607,
"typescript": 0.1264,
"shell": 0.0661
}
},
{
"source": "Write a python function 'def count_apples_reachable(apple_heights: List[int], tao_reach: int) -> int:' to solve the following problem:\n\n Calculate the number of apples that Tao Tao can reach.\n\n Args:\n apple_heights (List[int]): The heights of apples from the ground (in centimeters).\n tao_reach (int): The maximum height Tao Tao can reach with her hand stretched upwards (in centimeters).\n\n Returns:\n int: The number of apples Tao Tao can reach with or without standing on a 30cm stool.\n\n This function iterates over the list of apple heights and counts how many of them are within Tao Tao's reach,\n considering an additional 30cm that the stool provides.\n\n Example cases:\n count_apples_reachable([100, 120, 130, 140, 150, 150, 140, 130, 120, 110], 120) -> returns 10\n count_apples_reachable([200, 190, 180, 170, 160, 150, 140, 135, 130, 131], 100) -> returns 0\n ",
"ground-truth": null,
"prediction": [
"from typing import List\n\ndef count_apples_reachable(apple_heights: List[int], tao_reach: int) -> int:\n \"\"\"\n Calculate the number of apples that Tao Tao can reach.\n\n Args:\n apple_heights (List[int]): The heights of apples from the ground (in centimeters).\n tao_reach (int): The maximum height Tao Tao can reach with her hand stretched upwards (in centimeters).\n\n Returns:\n int: The number of apples Tao Tao can reach with or without standing on a 30cm stool.\n\n This function iterates over the list of apple heights and counts how many of them are within Tao Tao's reach,\n considering an additional 30cm that the stool provides.\n\n Example cases:\n count_apples_reachable([100, 120, 130, 140, 150, 150, 140, 130, 120, 110], 120) -> returns 10\n count_apples_reachable([200, 190, 180, 170, 160, 150, 140, 135, 130, 131], 100) -> returns 0\n \"\"\"\n count = 0\n for height in apple_heights:\n if height <= tao_reach + 30:\n count += 1\n return count",
"from typing import List\n\ndef count_apples_reachable(apple_heights: List[int], tao_reach: int) -> int:\n \"\"\"\n Calculate the number of apples that Tao Tao can reach.\n\n Args:\n apple_heights (List[int]): The heights of apples from the ground (in centimeters).\n tao_reach (int): The maximum height Tao Tao can reach with her hand stretched upwards (in centimeters).\n\n Returns:\n int: The number of apples Tao Tao can reach with or without standing on a 30cm stool.\n\n This function iterates over the list of apple heights and counts how many of them are within Tao Tao's reach,\n considering an additional 30cm that the stool provides.\n\n Example cases:\n count_apples_reachable([100, 120, 130, 140, 150, 150, 140, 130, 120, 110], 120) -> returns 10\n count_apples_reachable([200, 190, 180, 170, 160, 150, 140, 135, 130, 131], 100) -> returns 0\n \"\"\"\n count = 0\n for height in apple_heights:\n if height <= tao_reach + 30:\n count += 1\n return count",
"from typing import List\n\ndef count_apples_reachable(apple_heights: List[int], tao_reach: int) -> int:\n \"\"\"\n Calculate the number of apples that Tao Tao can reach.\n\n Args:\n apple_heights (List[int]): The heights of apples from the ground (in centimeters).\n tao_reach (int): The maximum height Tao Tao can reach with her hand stretched upwards (in centimeters).\n\n Returns:\n int: The number of apples Tao Tao can reach with or without standing on a 30cm stool.\n\n This function iterates over the list of apple heights and counts how many of them are within Tao Tao's reach,\n considering an additional 30cm that the stool provides.\n\n Example cases:\n count_apples_reachable([100, 120, 130, 140, 150, 150, 140, 130, 120, 110], 120) -> returns 10\n count_apples_reachable([200, 190, 180, 170, 160, 150, 140, 135, 130, 131], 100) -> returns 0\n \"\"\"\n count = 0\n for height in apple_heights:\n if height <= tao_reach + 30:\n count += 1\n return count",
"from typing import List\n\ndef count_apples_reachable(apple_heights: List[int], tao_reach: int) -> int:\n \"\"\"\n Calculate the number of apples that Tao Tao can reach.\n\n Args:\n apple_heights (List[int]): The heights of apples from the ground (in centimeters).\n tao_reach (int): The maximum height Tao Tao can reach with her hand stretched upwards (in centimeters).\n\n Returns:\n int: The number of apples Tao Tao can reach with or without standing on a 30cm stool.\n\n This function iterates over the list of apple heights and counts how many of them are within Tao Tao's reach,\n considering an additional 30cm that the stool provides.\n\n Example cases:\n count_apples_reachable([100, 120, 130, 140, 150, 150, 140, 130, 120, 110], 120) -> returns 10\n count_apples_reachable([200, 190, 180, 170, 160, 150, 140, 135, 130, 131], 100) -> returns 0\n \"\"\"\n count = 0\n for height in apple_heights:\n if height <= tao_reach + 30:\n count += 1\n return count",
"from typing import List\n\ndef count_apples_reachable(apple_heights: List[int], tao_reach: int) -> int:\n \"\"\"\n Calculate the number of apples that Tao Tao can reach.\n\n Args:\n apple_heights (List[int]): The heights of apples from the ground (in centimeters).\n tao_reach (int): The maximum height Tao Tao can reach with her hand stretched upwards (in centimeters).\n\n Returns:\n int: The number of apples Tao Tao can reach with or without standing on a 30cm stool.\n\n This function iterates over the list of apple heights and counts how many of them are within Tao Tao's reach,\n considering an additional 30cm that the stool provides.\n\n Example cases:\n count_apples_reachable([100, 120, 130, 140, 150, 150, 140, 130, 120, 110], 120) -> returns 10\n count_apples_reachable([200, 190, 180, 170, 160, 150, 140, 135, 130, 131], 100) -> returns 0\n \"\"\"\n count = 0\n for height in apple_heights:\n if height <= tao_reach + 30:\n count += 1\n return count"
],
"moe_id": {
"python": 0.1221,
"cpp": 0.1198,
"swift": 0.0711,
"rust": 0.1447,
"csharp": 0.0911,
"java": 0.1004,
"php": 0.0697,
"typescript": 0.1855,
"shell": 0.0956
}
},
{
"source": "Write a python function 'def remaining_trees_after_clearing(l: int, areas: List[Tuple[int, int]]) -> int:' to solve the following problem:\n\n Calculate the number of remaining trees along a road after specific areas have been cleared.\n\n The road is represented as a straight line of length 'l' and is initially filled with trees.\n Each area scheduled for clearing is specified as a pair of integers (start, end), representing\n the inclusive range along the road where the trees will be removed.\n\n Args:\n - l (int): The length of the road.\n - areas (List[Tuple[int, int]]): A list of tuples where each tuple represents a cleared area on the road.\n \n Returns:\n - int: The total number of trees remaining along the road after the specified areas have been cleared.\n \n Examples:\n - remaining_trees_after_clearing(10, [(2, 5), (7, 9)]) will return 5 \n - remaining_trees_after_clearing(100, [(10, 90)]) will return 20.\n ",
"ground-truth": null,
"prediction": [
"from typing import List, Tuple\n\ndef remaining_trees_after_clearing(l: int, areas: List[Tuple[int, int]]) -> int:\n \"\"\"\n Calculate the number of remaining trees along a road after specific areas have been cleared.\n\n Args:\n - l (int): The length of the road.\n - areas (List[Tuple[int, int]]): A list of tuples where each tuple represents a cleared area on the road.\n\n Returns:\n - int: The total number of trees remaining along the road after the specified areas have been cleared.\n\n Examples:\n - remaining_trees_after_clearing(10, [(2, 5), (7, 9)]) will return 5 \n - remaining_trees_after_clearing(100, [(10, 90)]) will return 20.\n \"\"\"\n remaining_trees = l\n for start, end in areas:\n remaining_trees -= (end - start + 1)\n return remaining_trees",
"from typing import List, Tuple\n\ndef remaining_trees_after_clearing(l: int, areas: List[Tuple[int, int]]) -> int:\n \"\"\"\n Calculate the number of remaining trees along a road after specific areas have been cleared.\n\n Args:\n - l (int): The length of the road.\n - areas (List[Tuple[int, int]]): A list of tuples where each tuple represents a cleared area on the road.\n\n Returns:\n - int: The total number of trees remaining along the road after the specified areas have been cleared.\n\n Examples:\n - remaining_trees_after_clearing(10, [(2, 5), (7, 9)]) will return 5 \n - remaining_trees_after_clearing(100, [(10, 90)]) will return 20.\n \"\"\"\n remaining_trees = l\n for start, end in areas:\n remaining_trees -= max(0, end - start + 1)\n return remaining_trees",
"from typing import List, Tuple\n\ndef remaining_trees_after_clearing(l: int, areas: List[Tuple[int, int]]) -> int:\n \"\"\"\n Calculate the number of remaining trees along a road after specific areas have been cleared.\n\n Args:\n - l (int): The length of the road.\n - areas (List[Tuple[int, int]]): A list of tuples where each tuple represents a cleared area on the road.\n\n Returns:\n - int: The total number of trees remaining along the road after the specified areas have been cleared.\n\n Examples:\n - remaining_trees_after_clearing(10, [(2, 5), (7, 9)]) will return 5 \n - remaining_trees_after_clearing(100, [(10, 90)]) will return 20.\n \"\"\"\n remaining_trees = l\n for start, end in areas:\n remaining_trees -= max(0, end - start + 1)\n return remaining_trees",
"from typing import List, Tuple\n\ndef remaining_trees_after_clearing(l: int, areas: List[Tuple[int, int]]) -> int:\n \"\"\"\n Calculate the number of remaining trees along a road after specific areas have been cleared.\n\n Args:\n - l (int): The length of the road.\n - areas (List[Tuple[int, int]]): A list of tuples where each tuple represents a cleared area on the road.\n\n Returns:\n - int: The total number of trees remaining along the road after the specified areas have been cleared.\n\n Examples:\n - remaining_trees_after_clearing(10, [(2, 5), (7, 9)]) will return 5 \n - remaining_trees_after_clearing(100, [(10, 90)]) will return 20.\n \"\"\"\n remaining_trees = l\n for start, end in areas:\n remaining_trees -= (end - start + 1)\n return remaining_trees",
"from typing import List, Tuple\n\ndef remaining_trees_after_clearing(l: int, areas: List[Tuple[int, int]]) -> int:\n \"\"\"\n Calculate the number of remaining trees along a road after specific areas have been cleared.\n\n Args:\n - l (int): The length of the road.\n - areas (List[Tuple[int, int]]): A list of tuples where each tuple represents a cleared area on the road.\n\n Returns:\n - int: The total number of trees remaining along the road after the specified areas have been cleared.\n\n Examples:\n - remaining_trees_after_clearing(10, [(2, 5), (7, 9)]) will return 5 \n - remaining_trees_after_clearing(100, [(10, 90)]) will return 20.\n \"\"\"\n remaining_trees = l\n for start, end in areas:\n remaining_trees -= max(0, end - start + 1)\n return remaining_trees"
],
"moe_id": {
"python": 0.0934,
"cpp": 0.2438,
"swift": 0.0954,
"rust": 0.114,
"csharp": 0.0902,
"java": 0.0868,
"php": 0.0534,
"typescript": 0.1348,
"shell": 0.088
}
},
{
"source": "Write a python function 'def max_herb_value(T: int, M: int, herbs: List[Tuple[int, int]]) -> int:' to solve the following problem:\n\n Calculate the maximum total value of herbs that can be picked within a given time limit.\n\n This function solves a variation of the 0/1 knapsack problem where the goal is to maximize\n the total value of herbs picked without exceeding the time limit. Each herb can be picked\n at most once and has an associated time cost and value.\n\n Args:\n - T (int): The total time available for picking herbs.\n - M (int): The number of different herbs in the cave.\n - herbs (List[Tuple[int, int]]): A list of tuples, where each tuple contains two integers\n representing the time required to pick the herb and the herb's value, respectively.\n\n Returns:\n - int: The maximum total value of herbs that can be picked within the time limit.\n\n Examples:\n - max_herb_value(70, 3, [(71, 100), (69, 1), (1, 2)]) -> 3\n - max_herb_value(5, 3, [(5, 10), (4, 7), (6, 12)]) -> 10\n ",
"ground-truth": null,
"prediction": [
"from typing import List, Tuple\n\ndef max_herb_value(T: int, M: int, herbs: List[Tuple[int, int]]) -> int:\n # Initialize a 2D array to store the maximum value for each time and herb combination\n dp = [[0 for _ in range(M + 1)] for _ in range(T + 1)]\n\n # Iterate through each herb and time to fill the dp table\n for i in range(1, T + 1):\n for j in range(1, M + 1):\n # If the herb can be picked within the time limit, consider its value\n if herbs[j - 1][0] <= i:\n dp[i][j] = max(dp[i][j - 1], dp[i - herbs[j - 1][0]][j - 1] + herbs[j - 1][1])\n else:\n # If the herb cannot be picked, copy the value from the previous herb\n dp[i][j] = dp[i][j - 1]\n\n # The maximum value for the given time limit is the last element in the dp table\n return dp[T][M]",
"from typing import List, Tuple\n\ndef max_herb_value(T: int, M: int, herbs: List[Tuple[int, int]]) -> int:\n # Create a 2D array to store the maximum value for each time and herb combination\n dp = [[0 for _ in range(T + 1)] for _ in range(M + 1)]\n\n # Fill the dp array\n for i in range(1, M + 1):\n for j in range(1, T + 1):\n if herbs[i - 1][0] <= j:\n dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - herbs[i - 1][0]] + herbs[i - 1][1])\n else:\n dp[i][j] = dp[i - 1][j]\n\n # The maximum value for the given time limit T\n return dp[M][T]",
"from typing import List, Tuple\n\ndef max_herb_value(T: int, M: int, herbs: List[Tuple[int, int]]) -> int:\n # Sort herbs by value per unit time in descending order\n herbs.sort(key=lambda x: x[1] / x[0], reverse=True)\n\n total_value = 0\n time_used = 0\n\n for herb in herbs:\n time_required, value = herb\n if time_used + time_required <= T:\n total_value += value\n time_used += time_required\n\n return total_value",
"from typing import List, Tuple\n\ndef max_herb_value(T: int, M: int, herbs: List[Tuple[int, int]]) -> int:\n # Sort herbs by value per unit time in descending order\n herbs.sort(key=lambda x: x[1] / x[0], reverse=True)\n\n total_value = 0\n time_used = 0\n\n for herb in herbs:\n time_required, value = herb\n if time_used + time_required <= T:\n total_value += value\n time_used += time_required\n\n return total_value",
"from typing import List, Tuple\n\ndef max_herb_value(T: int, M: int, herbs: List[Tuple[int, int]]) -> int:\n # Sort herbs by value per unit time in descending order\n herbs.sort(key=lambda x: x[1] / x[0], reverse=True)\n\n total_value = 0\n time_used = 0\n\n for herb in herbs:\n if time_used + herb[0] <= T:\n total_value += herb[1]\n time_used += herb[0]\n else:\n break\n\n return total_value"
],
"moe_id": {
"python": 0.1429,
"cpp": 0.1617,
"swift": 0.0791,
"rust": 0.1364,
"csharp": 0.1013,
"java": 0.1116,
"php": 0.0731,
"typescript": 0.1275,
"shell": 0.0664
}
},
{
"source": "Write a python function 'def min_remaining_space(V: int, n: int, volumes: List[int]) -> int:' to solve the following problem:\n\n Calculate the minimum remaining space in a box after trying to fit a number of items with given volumes.\n \n This function uses a dynamic programming approach to determine the maximum volume that can be occupied\n in the box by any subset of the given items. It then returns the difference between the box's total capacity\n and this maximum occupied volume, which is the minimum remaining space.\n\n Args:\n - V (int): The total capacity of the box.\n - n (int): The number of items to consider for packing into the box.\n - volumes (List[int]): A list of the volumes of the n items.\n\n Returns:\n - int: The minimum remaining space in the box after fitting the items.\n\n Examples:\n - min_remaining_space(24, 6, [8, 3, 12, 7, 9, 7]) -> 0\n - min_remaining_space(5, 3, [6, 7, 8]) -> 5\n\n ",
"ground-truth": null,
"prediction": [
"from typing import List\n\ndef min_remaining_space(V: int, n: int, volumes: List[int]) -> int:\n \"\"\"\n Calculate the minimum remaining space in a box after trying to fit a number of items with given volumes.\n \n This function uses a dynamic programming approach to determine the maximum volume that can be occupied\n in the box by any subset of the given items. It then returns the difference between the box's total capacity\n and this maximum occupied volume, which is the minimum remaining space.\n \n Args:\n - V (int): The total capacity of the box.\n - n (int): The number of items to consider for packing into the box.\n - volumes (List[int]): A list of the volumes of the n items.\n \n Returns:\n - int: The minimum remaining space in the box after fitting the items.\n \n Examples:\n - min_remaining_space(24, 6, [8, 3, 12, 7, 9, 7]) -> 0\n - min_remaining_space(5, 3, [6, 7, 8]) -> 5\n \"\"\"\n # Initialize the dp array with zeros\n dp = [0] * (V + 1)\n \n # Iterate over each item\n for i in range(n):\n # Iterate over the volumes in reverse order\n for j in range(V, volumes[i] - 1, -1):\n # Update the dp array with the maximum occupied volume\n dp[j] = max(dp[j], dp[j - volumes[i]] + volumes[i])\n \n # Calculate the minimum remaining space\n min_remaining = V - dp[V]\n \n return min_remaining",
"from typing import List\n\ndef min_remaining_space(V: int, n: int, volumes: List[int]) -> int:\n \"\"\"\n Calculate the minimum remaining space in a box after trying to fit a number of items with given volumes.\n \n Args:\n - V (int): The total capacity of the box.\n - n (int): The number of items to consider for packing into the box.\n - volumes (List[int]): A list of the volumes of the n items.\n \n Returns:\n - int: The minimum remaining space in the box after fitting the items.\n \n Examples:\n >>> min_remaining_space(24, 6, [8, 3, 12, 7, 9, 7])\n 0\n >>> min_remaining_space(5, 3, [6, 7, 8])\n 5\n \"\"\"\n dp = [0] * (V + 1)\n for i in range(n):\n for j in range(V, volumes[i] - 1, -1):\n dp[j] = max(dp[j], dp[j - volumes[i]] + volumes[i])\n return V - dp[V]",
"from typing import List\n\ndef min_remaining_space(V: int, n: int, volumes: List[int]) -> int:\n \"\"\"\n Calculate the minimum remaining space in a box after trying to fit a number of items with given volumes.\n \n Args:\n - V (int): The total capacity of the box.\n - n (int): The number of items to consider for packing into the box.\n - volumes (List[int]): A list of the volumes of the n items.\n \n Returns:\n - int: The minimum remaining space in the box after fitting the items.\n \"\"\"\n # Initialize a list to store the maximum volume that can be occupied by any subset of the items\n max_occupied = [0] * (V + 1)\n \n # Iterate over each item\n for i in range(n):\n # Iterate over the capacities from the item's volume to the total capacity\n for j in range(volumes[i], V + 1):\n # Update the maximum occupied volume for the current capacity\n max_occupied[j] = max(max_occupied[j], max_occupied[j - volumes[i]] + volumes[i])\n \n # Calculate the minimum remaining space\n min_remaining = V - max_occupied[V]\n \n return min_remaining",
"from typing import List\n\ndef min_remaining_space(V: int, n: int, volumes: List[int]) -> int:\n \"\"\"\n Calculate the minimum remaining space in a box after trying to fit a number of items with given volumes.\n \n This function uses a dynamic programming approach to determine the maximum volume that can be occupied\n in the box by any subset of the given items. It then returns the difference between the box's total capacity\n and this maximum occupied volume, which is the minimum remaining space.\n \n Args:\n - V (int): The total capacity of the box.\n - n (int): The number of items to consider for packing into the box.\n - volumes (List[int]): A list of the volumes of the n items.\n \n Returns:\n - int: The minimum remaining space in the box after fitting the items.\n \n Examples:\n - min_remaining_space(24, 6, [8, 3, 12, 7, 9, 7]) -> 0\n - min_remaining_space(5, 3, [6, 7, 8]) -> 5\n \"\"\"\n dp = [0] * (V + 1)\n for volume in volumes:\n for i in range(V, volume - 1, -1):\n dp[i] = max(dp[i], dp[i - volume] + volume)\n return V - dp[V]",
"from typing import List\n\ndef min_remaining_space(V: int, n: int, volumes: List[int]) -> int:\n \"\"\"\n Calculate the minimum remaining space in a box after trying to fit a number of items with given volumes.\n \n This function uses a dynamic programming approach to determine the maximum volume that can be occupied\n in the box by any subset of the given items. It then returns the difference between the box's total capacity\n and this maximum occupied volume, which is the minimum remaining space.\n \"\"\"\n # Initialize the dp array with zeros\n dp = [0] * (V + 1)\n \n # Iterate over each item\n for i in range(n):\n # Update the dp array for each volume\n for j in range(V, volumes[i] - 1, -1):\n dp[j] = max(dp[j], dp[j - volumes[i]] + volumes[i])\n \n # The minimum remaining space is the difference between the box's total capacity and the maximum occupied volume\n return V - dp[V]"
],
"moe_id": {
"python": 0.1081,
"cpp": 0.2499,
"swift": 0.1072,
"rust": 0.0895,
"csharp": 0.103,
"java": 0.0767,
"php": 0.0676,
"typescript": 0.1167,
"shell": 0.0814
}
},
{
"source": "Write a python function 'def calculate_arrangements(n, m, a) -> int:' to solve the following problem:\n\n Compute the number of ways to arrange m pots of flowers using up to n types,\n where the ith type can have at most a[i] pots, and the arrangement must be in\n increasing order of flower types.\n\n Args:\n - n (int): The number of flower types available.\n - m (int): The total number of flower pots to arrange.\n - a (list of int): A list where a[i] is the maximum number of pots for the ith type of flower.\n\n Returns:\n - int: The number of distinct arrangements modulo (10^6 + 7).\n\n Examples:\n - calculate_arrangements(2, 4, [3, 2]) returns 2.\n - calculate_arrangements(3, 3, [1, 2, 3]) returns 6.\n ",
"ground-truth": null,
"prediction": [
"def calculate_arrangements(n, m, a):\n MOD = 10**6 + 7\n dp = [0] * (m + 1)\n dp[0] = 1\n\n for i in range(1, n + 1):\n for j in range(m, a[i - 1] - 1, -1):\n dp[j] = (dp[j] + dp[j - a[i - 1]]) % MOD\n\n return dp[m]",
"def calculate_arrangements(n, m, a):\n MOD = 10**6 + 7\n dp = [0] * (m + 1)\n dp[0] = 1\n for i in range(1, m + 1):\n for j in range(n):\n if i <= a[j]:\n dp[i] = (dp[i] + dp[i - a[j]]) % MOD\n return dp[m]\n\n# Test cases\nprint(calculate_arrangements(2, 4, [3, 2])) # Output: 2\nprint(calculate_arrangements(3, 3, [1, 2, 3])) # Output: 6",
"def calculate_arrangements(n, m, a):\n MOD = 10**6 + 7\n dp = [0] * (m + 1)\n dp[0] = 1\n\n for i in range(1, n + 1):\n for j in range(m, a[i - 1] - 1, -1):\n dp[j] = (dp[j] + dp[j - a[i - 1]]) % MOD\n\n return dp[m]",
"def calculate_arrangements(n, m, a):\n MOD = 10**6 + 7\n dp = [0] * (m + 1)\n dp[0] = 1\n for i in range(n):\n for j in range(m, a[i] - 1, -1):\n dp[j] = (dp[j] + dp[j - a[i]]) % MOD\n return dp[m]",
"def calculate_arrangements(n, m, a):\n MOD = 10**6 + 7\n dp = [0] * (m + 1)\n dp[0] = 1\n\n for i in range(n):\n for j in range(m, a[i] - 1, -1):\n dp[j] = (dp[j] + dp[j - a[i]]) % MOD\n\n return dp[m]"
],
"moe_id": {
"python": 0.1725,
"cpp": 0.1616,
"swift": 0.0864,
"rust": 0.1364,
"csharp": 0.1053,
"java": 0.132,
"php": 0.0751,
"typescript": 0.0931,
"shell": 0.0375
}
},
{
"source": "Write a python function 'def vigenere_decrypt(key: str, ciphertext: str) -> str:' to solve the following problem:\n\n Decrypts a ciphertext encrypted with the Vigenère cipher using the provided key.\n \n The Vigenère cipher is a method of encrypting alphabetic text by using a series of\n Caesar ciphers based on the letters of a keyword. This function reverses the process\n to recover the original plaintext from the ciphertext.\n\n Args:\n key (str): The encryption key used to encrypt the original plaintext.\n This key should consist only of alphabetic characters.\n ciphertext (str): The encrypted text that needs to be decrypted.\n The ciphertext should consist only of alphabetic characters.\n\n Returns:\n str: The decrypted plaintext corresponding to the input ciphertext.\n\n Examples:\n >>> vigenere_decrypt(\"CompleteVictory\", \"Yvqgpxaimmklongnzfwpvxmniytm\")\n 'Wherethereisawillthereisaway'\n\n >>> vigenere_decrypt(\"ABC\", \"DEF\")\n 'DCB'\n ",
"ground-truth": null,
"prediction": [
"def vigenere_decrypt(key: str, ciphertext: str) -> str:\n def shift_char(c: str, shift: int) -> str:\n if c.isalpha():\n base = ord('A') if c.isupper() else ord('a')\n return chr((ord(c) - base - shift) % 26 + base)\n return c\n\n def vigenere_decrypt_char(c: str, key_char: str) -> str:\n shift = ord(key_char) - ord('A')\n return shift_char(c, shift)\n\n key = key.upper()\n ciphertext = ciphertext.upper()\n plaintext = ''.join(vigenere_decrypt_char(c, key[i % len(key)]) for i, c in enumerate(ciphertext))\n return plaintext",
"def vigenere_decrypt(key: str, ciphertext: str) -> str:\n # Ensure the key and ciphertext are alphabetic\n key = key.upper()\n ciphertext = ciphertext.upper()\n \n # Initialize the result string\n result = \"\"\n \n # Iterate over the ciphertext\n for i in range(len(ciphertext)):\n # Get the current character from the ciphertext\n char = ciphertext[i]\n \n # Check if the character is alphabetic\n if char.isalpha():\n # Calculate the shift value based on the key\n shift = ord(key[i % len(key)]) - ord('A')\n \n # Decrypt the character using the Vigenère cipher\n decrypted_char = chr((ord(char) - ord('A') - shift) % 26 + ord('A'))\n \n # Append the decrypted character to the result\n result += decrypted_char\n else:\n # If the character is not alphabetic, append it as is\n result += char\n \n return result",
"def vigenere_decrypt(key: str, ciphertext: str) -> str:\n def shift_char(char: str, shift: int) -> str:\n if char.isalpha():\n base = ord('A') if char.isupper() else ord('a')\n return chr((ord(char) - base - shift) % 26 + base)\n return char\n\n key_length = len(key)\n plaintext = \"\"\n for i in range(len(ciphertext)):\n shift = ord(key[i % key_length]) - ord('A')\n plaintext += shift_char(ciphertext[i], -shift)\n return plaintext",
"def vigenere_decrypt(key: str, ciphertext: str) -> str:\n def shift_char(char: str, shift: int) -> str:\n if char.isalpha():\n base = ord('A') if char.isupper() else ord('a')\n return chr((ord(char) - base - shift) % 26 + base)\n return char\n\n key_length = len(key)\n plaintext = \"\"\n for i, char in enumerate(ciphertext):\n shift = ord(key[i % key_length].upper()) - ord('A')\n plaintext += shift_char(char, shift)\n return plaintext",
"def vigenere_decrypt(key: str, ciphertext: str) -> str:\n key_length = len(key)\n plaintext = \"\"\n for i in range(len(ciphertext)):\n char = ciphertext[i]\n if char.isalpha():\n shift = ord(key[i % key_length].upper()) - ord('A')\n if char.isupper():\n plaintext += chr((ord(char) - ord('A') - shift) % 26 + ord('A'))\n else:\n plaintext += chr((ord(char) - ord('a') - shift) % 26 + ord('a'))\n else:\n plaintext += char\n return plaintext"
],
"moe_id": {
"python": 0.0938,
"cpp": 0.1881,
"swift": 0.085,
"rust": 0.1303,
"csharp": 0.087,
"java": 0.0973,
"php": 0.048,
"typescript": 0.1767,
"shell": 0.0937
}
},
{
"source": "Write a python function 'def mod_inverse(a, b):' to solve the following problem:\n\n Calculate the modular multiplicative inverse of `a` modulo `b`.\n \n This function finds an integer `x` such that (a * x) % b == 1, provided that\n `a` and `b` are coprime (i.e., gcd(a, b) == 1). It uses the Extended Euclidean\n Algorithm to compute the inverse. If `a` and `b` are not coprime, the modular\n inverse does not exist, and the function returns `None`.\n \n Args:\n a (int): The integer whose modular inverse is to be found.\n b (int): The modulus with respect to which the inverse is sought.\n \n Returns:\n int: The modular inverse of `a` modulo `b` if it exists, otherwise `None`.\n \n Examples:\n >>> mod_inverse(3, 10)\n 7\n\n >>> mod_inverse(42, 2017)\n None\n ",
"ground-truth": null,
"prediction": [
"def mod_inverse(a, b):\n if a == 0:\n return None\n x, y = 1, 0\n x1, y1 = 0, 1\n while b != 0:\n q, r = divmod(a, b)\n a, b = b, r\n x, x1 = x1 - q * x, x\n y, y1 = y1 - q * y, y\n return x % b",
"def mod_inverse(a, b):\n if b == 0:\n return None\n else:\n g, x, y = extended_gcd(a, b)\n if g != 1:\n return None\n else:\n return x % b\n\ndef extended_gcd(a, b):\n if a == 0:\n return (b, 0, 1)\n else:\n g, x, y = extended_gcd(b % a, a)\n return (g, y - (b // a) * x, x)\n\n# Test cases\nprint(mod_inverse(3, 10)) # Output: 7\nprint(mod_inverse(42, 2017)) # Output: None",
"def mod_inverse(a, b):\n if a == 0:\n return None # Inverse does not exist if a is 0\n\n # Initialize the Extended Euclidean Algorithm\n x, y = 0, 1\n original_b = b\n while a != 0:\n quotient, remainder = divmod(b, a)\n x, y = y, x - quotient * y\n b, a = a, remainder\n\n # If b is not 1, a and b are not coprime, and the inverse does not exist\n if b != 1:\n return None\n\n # Ensure the result is positive\n return x % original_b",
"def mod_inverse(a, b):\n if b == 0:\n return None # Division by zero is undefined\n\n # Initialize the Extended Euclidean Algorithm\n x, y = 0, 1\n original_b = b\n\n while a != 0:\n quotient, remainder = divmod(b, a)\n x, y = y - quotient * x, x\n b, a = a, remainder\n\n # Ensure the result is positive\n if b == 1:\n return y % original_b\n else:\n return None # Inverse does not exist if a and b are not coprime\n\n# Test cases\nprint(mod_inverse(3, 10)) # Output: 7\nprint(mod_inverse(42, 2017)) # Output: None",
"def mod_inverse(a, b):\n if a == 0:\n return None\n x, y = 0, 1\n while b != 0:\n q, r = divmod(a, b)\n a, b = b, r\n x, y = y - q * x, x\n return x % b\n\n# Test cases\nprint(mod_inverse(3, 10)) # Expected output: 7\nprint(mod_inverse(42, 2017)) # Expected output: None"
],
"moe_id": {
"python": 0.1175,
"cpp": 0.2603,
"swift": 0.0699,
"rust": 0.1412,
"csharp": 0.0704,
"java": 0.0976,
"php": 0.0363,
"typescript": 0.1413,
"shell": 0.0654
}
},
{
"source": "Write a python function 'def find_most_unhappy_day(schedule) -> int:' to solve the following problem:\n\n Calculate the day of the week when Jinjin is most unhappy based on her schedule.\n \n Jinjin is unhappy if the total hours spent in school and extra classes exceed 8 hours in a day. \n The function finds the day when her unhappiness is the greatest, which is the day when the total\n hours are the farthest above the threshold. If there are multiple days with the same level of \n maximum unhappiness, the earliest day is returned. If Jinjin is not unhappy on any day, the \n function returns 0.\n \n Args:\n schedule (list[tuple[int, int]]): A list of 7 tuples, where each tuple represents the \n number of hours spent at school and in extra classes\n for each day of the week, respectively.\n \n Returns:\n int: The day of the week when Jinjin is most unhappy (1-7 for Monday to Sunday) or 0 \n if she is never unhappy.\n \n Cases:\n >>> find_most_unhappy_day([(5, 3), (6, 2), (7, 2), (5, 3), (5, 4), (0, 4), (0, 6)])\n 3\n >>> find_most_unhappy_day([(4, 3), (4, 3), (4, 3), (4, 3), (4, 3), (0, 3), (0, 2)])\n 0\n ",
"ground-truth": null,
"prediction": [
"def find_most_unhappy_day(schedule) -> int:\n # Initialize variables to keep track of the maximum unhappiness and the corresponding day\n max_unhappiness = 0\n max_unhappiness_day = 0\n \n # Iterate through each day of the week\n for day, (school_hours, extra_hours) in enumerate(schedule):\n # Calculate the total hours spent in school and extra classes for the current day\n total_hours = school_hours + extra_hours\n \n # Check if the total hours exceed the threshold\n if total_hours > 8:\n # Update the maximum unhappiness and the corresponding day if necessary\n if total_hours > max_unhappiness:\n max_unhappiness = total_hours\n max_unhappiness_day = day\n # If the total hours are equal to the maximum unhappiness, update the day if it's earlier\n elif total_hours == max_unhappiness:\n max_unhappiness_day = min(max_unhappiness_day, day)\n \n # Return the day when Jinjin is most unhappy or 0 if she is never unhappy\n return max_unhappiness_day + 1 if max_unhappiness > 0 else 0",
"def find_most_unhappy_day(schedule) -> int:\n total_hours = [sum(day) for day in schedule]\n max_unhappy_day = 0\n max_unhappy_hours = 0\n \n for day, hours in enumerate(total_hours, start=1):\n if hours > 8:\n if hours > max_unhappy_hours:\n max_unhappy_hours = hours\n max_unhappy_day = day\n elif hours == max_unhappy_hours:\n max_unhappy_day = min(max_unhappy_day, day)\n \n return max_unhappy_day if max_unhappy_day else 0",
"def find_most_unhappy_day(schedule):\n total_hours = [sum(day) for day in schedule]\n max_unhappy_day = 0\n max_unhappy_hours = 0\n\n for day, hours in enumerate(total_hours, start=1):\n if hours > 8:\n if hours > max_unhappy_hours:\n max_unhappy_hours = hours\n max_unhappy_day = day\n elif hours == max_unhappy_hours:\n max_unhappy_day = min(max_unhappy_day, day)\n\n return max_unhappy_day if max_unhappy_day else 0",
"from typing import List, Tuple\n\ndef find_most_unhappy_day(schedule: List[Tuple[int, int]]) -> int:\n \"\"\"\n Calculate the day of the week when Jinjin is most unhappy based on her schedule.\n \n Jinjin is unhappy if the total hours spent in school and extra classes exceed 8 hours in a day.\n The function finds the day when her unhappiness is the greatest, which is the day when the total\n hours are the farthest above the threshold. If there are multiple days with the same level of\n maximum unhappiness, the earliest day is returned. If Jinjin is not unhappy on any day, the\n function returns 0.\n \n Args:\n schedule (list[tuple[int, int]]): A list of 7 tuples, where each tuple represents the\n number of hours spent at school and in extra classes\n for each day of the week, respectively.\n \n Returns:\n int: The day of the week when Jinjin is most unhappy (1-7 for Monday to Sunday) or 0\n if she is never unhappy.\n \"\"\"\n max_unhappy_day = 0\n max_unhappy_hours = 0\n\n for day, (school_hours, extra_hours) in enumerate(schedule, start=1):\n total_hours = school_hours + extra_hours\n if total_hours > 8:\n if total_hours > max_unhappy_hours:\n max_unhappy_hours = total_hours\n max_unhappy_day = day\n elif total_hours == max_unhappy_hours:\n max_unhappy_day = min(max_unhappy_day, day)\n\n return max_unhappy_day if max_unhappy_day != 0 else 0",
"def find_most_unhappy_day(schedule) -> int:\n total_hours = [sum(day) for day in schedule]\n max_unhappy_day = 0\n max_unhappy_hours = 0\n \n for day, hours in enumerate(total_hours):\n if hours > 8:\n if hours > max_unhappy_hours:\n max_unhappy_hours = hours\n max_unhappy_day = day + 1 # Adjusting for 1-based indexing\n elif hours == max_unhappy_hours:\n max_unhappy_day = min(max_unhappy_day, day + 1)\n \n return max_unhappy_day if max_unhappy_day != 0 else 0"
],
"moe_id": {
"python": 0.111,
"cpp": 0.1798,
"swift": 0.102,
"rust": 0.066,
"csharp": 0.1069,
"java": 0.0869,
"php": 0.079,
"typescript": 0.1598,
"shell": 0.1086
}
},
{
"source": "Write a python function 'def next_permutation(perm: list) -> bool:' to solve the following problem:\n\n Transforms the input permutation to the next permutation in lexicographic order.\n \n The function finds the first number from the end that is smaller than the number following it \n and swaps it with the smallest number that is larger and comes after it. Then it reverses the \n order of numbers after the original first smaller number. If the input is the last permutation \n (in descending order), the function returns False, indicating no next permutation is possible.\n \n Args:\n perm (list): A list of integers representing the current permutation.\n \n Returns:\n bool: True if the permutation was successfully transformed, False if it was the last permutation.\n \n Examples:\n >>> next_permutation([1, 2, 3])\n True\n >>> [1, 2, 3]\n [1, 3, 2]\n \n >>> next_permutation([3, 2, 1])\n False\n >>> [3, 2, 1]\n [3, 2, 1]\n ",
"ground-truth": null,
"prediction": [
"def next_permutation(perm: list) -> bool:\n # Find the first number from the end that is smaller than the number following it\n i = len(perm) - 2\n while i >= 0 and perm[i] >= perm[i + 1]:\n i -= 1\n \n # If no such number exists, the permutation is the last permutation\n if i < 0:\n return False\n \n # Find the smallest number that is larger and comes after the found number\n j = len(perm) - 1\n while perm[j] <= perm[i]:\n j -= 1\n \n # Swap the found numbers\n perm[i], perm[j] = perm[j], perm[i]\n \n # Reverse the order of numbers after the original first smaller number\n perm[i + 1:] = reversed(perm[i + 1:])\n \n return True",
"def next_permutation(perm: list) -> bool:\n # Find the first number from the end that is smaller than the number following it\n i = len(perm) - 2\n while i >= 0 and perm[i] >= perm[i + 1]:\n i -= 1\n \n # If no such number exists, the permutation is the last one\n if i == -1:\n return False\n \n # Find the smallest number that is larger than perm[i] and comes after it\n j = len(perm) - 1\n while perm[j] <= perm[i]:\n j -= 1\n \n # Swap perm[i] and perm[j]\n perm[i], perm[j] = perm[j], perm[i]\n \n # Reverse the order of numbers after perm[i]\n perm[i + 1:] = reversed(perm[i + 1:])\n \n return True",
"def next_permutation(perm: list) -> bool:\n # Find the first number from the end that is smaller than the number following it\n i = len(perm) - 2\n while i >= 0 and perm[i] >= perm[i + 1]:\n i -= 1\n \n # If no such number exists, the permutation is the last one\n if i < 0:\n return False\n \n # Find the smallest number that is larger than perm[i]\n j = len(perm) - 1\n while perm[j] <= perm[i]:\n j -= 1\n \n # Swap perm[i] and perm[j]\n perm[i], perm[j] = perm[j], perm[i]\n \n # Reverse the order of numbers after perm[i]\n perm[i + 1:] = reversed(perm[i + 1:])\n \n return True",
"def next_permutation(perm: list) -> bool:\n # Find the first number from the end that is smaller than the number following it\n i = len(perm) - 2\n while i >= 0 and perm[i] >= perm[i + 1]:\n i -= 1\n \n # If no such number exists, the permutation is the last permutation\n if i < 0:\n return False\n \n # Find the smallest number that is larger and comes after the found number\n j = len(perm) - 1\n while perm[j] <= perm[i]:\n j -= 1\n \n # Swap the found numbers\n perm[i], perm[j] = perm[j], perm[i]\n \n # Reverse the order of numbers after the original first smaller number\n perm[i + 1:] = reversed(perm[i + 1:])\n \n return True",
"def next_permutation(perm: list) -> bool:\n # Find the first number from the end that is smaller than the number following it\n i = len(perm) - 2\n while i >= 0 and perm[i] >= perm[i + 1]:\n i -= 1\n \n # If no such number exists, the permutation is the last one\n if i < 0:\n return False\n \n # Find the smallest number that is larger and comes after the found number\n j = len(perm) - 1\n while perm[j] <= perm[i]:\n j -= 1\n \n # Swap the found numbers\n perm[i], perm[j] = perm[j], perm[i]\n \n # Reverse the order of numbers after the original first smaller number\n perm[i + 1:] = reversed(perm[i + 1:])\n \n return True"
],
"moe_id": {
"python": 0.1163,
"cpp": 0.2519,
"swift": 0.0996,
"rust": 0.0822,
"csharp": 0.0929,
"java": 0.0723,
"php": 0.0688,
"typescript": 0.1396,
"shell": 0.0765
}
},
{
"source": "Write a python function 'def jinjin_savings_plan(budgets: List[int]) -> int:' to solve the following problem:\n\n Calculates the total amount of money Jinjin will have by the end of the year\n after following her savings plan with her mother. Each month, she can save\n multiples of 100 from her pocket money (300 per month) if she predicts having\n at least 100 units remaining after expenses. The saved money will gain 20%\n interest at the end of the year.\n\n Parameters:\n budgets (List[int]): A list of 12 integers representing Jinjin's monthly budget.\n\n Returns:\n int: The total amount of money Jinjin will have at the end of the year after interest.\n If Jinjin runs out of money in any given month, returns the negative value of\n that month (-X, where X is the month number).\n\n Examples:\n >>> jinjin_savings_plan([290, 230, 280, 200, 300, 170, 340, 50, 90, 80, 200, 60])\n -7\n \n >>> jinjin_savings_plan([290, 230, 280, 200, 300, 170, 330, 50, 90, 80, 200, 60])\n 1580\n ",
"ground-truth": null,
"prediction": [
"from typing import List\n\ndef jinjin_savings_plan(budgets: List[int]) -> int:\n total_savings = 0\n for month, budget in enumerate(budgets, start=1):\n if budget - 100 >= 0:\n savings = min(300, budget - 100)\n total_savings += savings * 1.2\n else:\n return -month\n return int(total_savings)",
"from typing import List\n\ndef jinjin_savings_plan(budgets: List[int]) -> int:\n total_savings = 0\n for month, budget in enumerate(budgets, start=1):\n if budget >= 100:\n savings = min(budget - 100, 300)\n total_savings += savings * 1.2\n else:\n return -month\n return int(total_savings)",
"from typing import List\n\ndef jinjin_savings_plan(budgets: List[int]) -> int:\n total_savings = 0\n for month, budget in enumerate(budgets, start=1):\n if budget >= 100:\n savings = min(budget - 100, 300)\n total_savings += savings * 1.2\n else:\n return -month\n return int(total_savings)",
"from typing import List\n\ndef jinjin_savings_plan(budgets: List[int]) -> int:\n total_savings = 0\n for month, budget in enumerate(budgets, start=1):\n if budget - 100 >= 0:\n savings = min(300, budget - 100)\n total_savings += savings * 1.2\n else:\n return -month\n return int(total_savings)",
"from typing import List\n\ndef jinjin_savings_plan(budgets: List[int]) -> int:\n total_savings = 0\n for month, budget in enumerate(budgets, start=1):\n if budget - 100 >= 0:\n savings = min(budget - 100, 300)\n total_savings += savings\n else:\n return -month\n \n total_savings *= 1.2 # Apply 20% interest at the end of the year\n \n return int(total_savings)"
],
"moe_id": {
"python": 0.1006,
"cpp": 0.1665,
"swift": 0.1029,
"rust": 0.0717,
"csharp": 0.1073,
"java": 0.0844,
"php": 0.08,
"typescript": 0.1647,
"shell": 0.1219
}
},
{
"source": "Write a python function 'def minimum_cost_to_merge_fruits(fruit_counts: List[int]) -> int:' to solve the following problem:\n\n Calculates the minimum total cost to merge multiple heaps of fruits into a single heap.\n The cost of merging two heaps is equal to the sum of their weights. The function utilizes\n a greedy algorithm with a min-heap (priority queue) to ensure the smallest heaps are merged first,\n minimizing the total cost.\n\n Parameters:\n fruit_counts (List[int]): A list of integers representing the counts of each type of fruit.\n\n Returns:\n int: The minimum total cost required to merge all heaps of fruits.\n\n Examples:\n >>> minimum_cost_to_merge_fruits([1, 2, 9])\n 15\n >>> minimum_cost_to_merge_fruits([10, 20, 30, 40, 50])\n 300 .\n ",
"ground-truth": null,
"prediction": [
"from typing import List\nimport heapq\n\ndef minimum_cost_to_merge_fruits(fruit_counts: List[int]) -> int:\n # Convert the list of fruit counts into a min-heap\n heapq.heapify(fruit_counts)\n \n total_cost = 0\n while len(fruit_counts) > 1:\n # Pop the two smallest heaps from the min-heap\n first_smallest = heapq.heappop(fruit_counts)\n second_smallest = heapq.heappop(fruit_counts)\n \n # Merge the two heaps and add the cost to the total cost\n merged_heap = first_smallest + second_smallest\n total_cost += merged_heap\n \n # Push the merged heap back into the min-heap\n heapq.heappush(fruit_counts, merged_heap)\n \n return total_cost",
"from typing import List\nimport heapq\n\ndef minimum_cost_to_merge_fruits(fruit_counts: List[int]) -> int:\n # Convert the list of fruit counts into a min-heap\n heapq.heapify(fruit_counts)\n\n total_cost = 0\n while len(fruit_counts) > 1:\n # Pop the two smallest heaps\n heap1 = heapq.heappop(fruit_counts)\n heap2 = heapq.heappop(fruit_counts)\n\n # Merge the two heaps and add the cost to the total\n total_cost += heap1 + heap2\n\n # Push the merged heap back into the min-heap\n heapq.heappush(fruit_counts, heap1 + heap2)\n\n return total_cost\n\n# Test cases\nprint(minimum_cost_to_merge_fruits([1, 2, 9])) # Output: 15\nprint(minimum_cost_to_merge_fruits([10, 20, 30, 40, 50])) # Output: 300",
"from typing import List\nimport heapq\n\ndef minimum_cost_to_merge_fruits(fruit_counts: List[int]) -> int:\n \"\"\"\n Calculates the minimum total cost to merge multiple heaps of fruits into a single heap.\n The cost of merging two heaps is equal to the sum of their weights. The function utilizes\n a greedy algorithm with a min-heap (priority queue) to ensure the smallest heaps are merged first,\n minimizing the total cost.\n \"\"\"\n # Convert the list of fruit counts into a min-heap\n heapq.heapify(fruit_counts)\n \n total_cost = 0\n while len(fruit_counts) > 1:\n # Pop the two smallest heaps from the min-heap\n heap1 = heapq.heappop(fruit_counts)\n heap2 = heapq.heappop(fruit_counts)\n \n # Merge the two heaps and add the cost to the total cost\n total_cost += heap1 + heap2\n \n # Push the merged heap back into the min-heap\n heapq.heappush(fruit_counts, heap1 + heap2)\n \n return total_cost\n\n# Test cases\nprint(minimum_cost_to_merge_fruits([1, 2, 9])) # Output: 15\nprint(minimum_cost_to_merge_fruits([10, 20, 30, 40, 50])) # Output: 300",
"from typing import List\nimport heapq\n\ndef minimum_cost_to_merge_fruits(fruit_counts: List[int]) -> int:\n # Convert the list of fruit counts into a min-heap\n heapq.heapify(fruit_counts)\n \n total_cost = 0\n while len(fruit_counts) > 1:\n # Pop the two smallest heaps\n first_heap = heapq.heappop(fruit_counts)\n second_heap = heapq.heappop(fruit_counts)\n \n # Merge the two heaps and add the cost to the total\n total_cost += first_heap + second_heap\n \n # Push the merged heap back into the min-heap\n heapq.heappush(fruit_counts, first_heap + second_heap)\n \n return total_cost\n\n# Test cases\nprint(minimum_cost_to_merge_fruits([1, 2, 9])) # Output: 15\nprint(minimum_cost_to_merge_fruits([10, 20, 30, 40, 50])) # Output: 300",
"from typing import List\nimport heapq\n\ndef minimum_cost_to_merge_fruits(fruit_counts: List[int]) -> int:\n # Convert the list of fruit counts into a min-heap\n heapq.heapify(fruit_counts)\n \n total_cost = 0\n while len(fruit_counts) > 1:\n # Pop the two smallest heaps\n heap1 = heapq.heappop(fruit_counts)\n heap2 = heapq.heappop(fruit_counts)\n \n # Merge the two heaps and add the cost to the total\n total_cost += heap1 + heap2\n \n # Push the merged heap back into the min-heap\n heapq.heappush(fruit_counts, heap1 + heap2)\n \n return total_cost\n\n# Test cases\nprint(minimum_cost_to_merge_fruits([1, 2, 9])) # Output: 15\nprint(minimum_cost_to_merge_fruits([10, 20, 30, 40, 50])) # Output: 300"
],
"moe_id": {
"python": 0.1605,
"cpp": 0.172,
"swift": 0.0971,
"rust": 0.125,
"csharp": 0.1142,
"java": 0.1314,
"php": 0.0912,
"typescript": 0.0772,
"shell": 0.0315
}
},
{
"source": "Write a python function 'def minimum_students_to_leave(heights):' to solve the following problem:\n\n Calculate the minimum number of students that need to leave to form a choir formation.\n A choir formation is defined such that for some position 'i', the heights of students\n increase from the start to 'i' and decrease from 'i' to the end of the formation.\n\n Args:\n heights (List[int]): A list of student heights.\n\n Returns:\n int: The minimum number of students that need to leave.\n ",
"ground-truth": null,
"prediction": [
"def minimum_students_to_leave(heights):\n n = len(heights)\n left = 0\n right = n - 1\n count = 0\n\n while left < right:\n while left < right and heights[left] <= heights[left + 1]:\n left += 1\n while left < right and heights[right] >= heights[right - 1]:\n right -= 1\n if left < right:\n count += 1\n left += 1\n right -= 1\n\n return count\n\n# Test cases\nprint(minimum_students_to_leave([1, 2, 3, 4, 5])) # Output: 0\nprint(minimum_students_to_leave([5, 4, 3, 2, 1])) # Output: 4\nprint(minimum_students_to_leave([1, 2, 3, 2, 1])) # Output: 2",
"from typing import List\n\ndef minimum_students_to_leave(heights: List[int]) -> int:\n n = len(heights)\n left = 0\n right = n - 1\n count = 0\n\n while left < right:\n if heights[left] < heights[left + 1]:\n left += 1\n elif heights[right] < heights[right - 1]:\n right -= 1\n else:\n count += 1\n left += 1\n right -= 1\n\n return count",
"def minimum_students_to_leave(heights):\n n = len(heights)\n left = 0\n right = n - 1\n count = 0\n\n while left < right:\n if heights[left] < heights[left + 1]:\n left += 1\n elif heights[right] < heights[right - 1]:\n right -= 1\n else:\n count += 1\n left += 1\n right -= 1\n\n return count\n\n# Test cases\nprint(minimum_students_to_leave([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])) # Output: 0\nprint(minimum_students_to_leave([10, 9, 8, 7, 6, 5, 4, 3, 2, 1])) # Output: 10\nprint(minimum_students_to_leave([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])) # Output: 1\nprint(minimum_students_to_leave([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0])) # Output: 10",
"def minimum_students_to_leave(heights):\n n = len(heights)\n left = 0\n right = n - 1\n count = 0\n\n while left < right:\n if heights[left] < heights[left + 1]:\n left += 1\n elif heights[right] < heights[right - 1]:\n right -= 1\n else:\n count += 1\n left += 1\n right -= 1\n\n return count\n\n# Test the function\nheights = [10, 20, 30, 40, 50, 25, 35, 45, 55, 60]\nprint(minimum_students_to_leave(heights)) # Output: 2",
"from typing import List\n\ndef minimum_students_to_leave(heights: List[int]) -> int:\n \"\"\"\n Calculate the minimum number of students that need to leave to form a choir formation.\n A choir formation is defined such that for some position 'i', the heights of students\n increase from the start to 'i' and decrease from 'i' to the end of the formation.\n\n Args:\n heights (List[int]): A list of student heights.\n\n Returns:\n int: The minimum number of students that need to leave.\n \"\"\"\n n = len(heights)\n left = 0\n right = n - 1\n count = 0\n\n while left < right:\n if heights[left] < heights[left + 1]:\n left += 1\n elif heights[right] < heights[right - 1]:\n right -= 1\n else:\n count += 1\n left += 1\n right -= 1\n\n return count"
],
"moe_id": {
"python": 0.0493,
"cpp": 0.3469,
"swift": 0.1623,
"rust": 0.0795,
"csharp": 0.0759,
"java": 0.0472,
"php": 0.0751,
"typescript": 0.0677,
"shell": 0.0961
}
},
{
"source": "Write a python function 'def sort_students(student_scores):' to solve the following problem:\n\n Sorts a list of students based on their scores. The students are sorted primarily by their total score (descending),\n then by their Chinese score (descending), and finally by their student number (ascending) in case of a tie.\n \n Args:\n student_scores (list): A list of tuples, where each tuple consists of (student_number, total_score, Chinese_score).\n \n Returns:\n list: A list of tuples sorted according to the above rules.\n \n Examples:\n >>> sort_students([(1, 237, 90), (2, 244, 87), (3, 258, 78), (4, 264, 88), (5, 215, 67), (6, 265, 78)])\n [(6, 265, 78), (4, 264, 88), (3, 258, 78), (2, 244, 87), (1, 237, 90), (5, 215, 67)]\n \n >>> sort_students([(1, 300, 100), (2, 300, 99), (3, 299, 98), (4, 298, 97), (5, 297, 96)])\n [(1, 300, 100), (2, 300, 99), (3, 299, 98), (4, 298, 97), (5, 297, 96)]\n ",
"ground-truth": null,
"prediction": [
"def sort_students(student_scores):\n # Sort the list of tuples based on the total score in descending order\n # If two students have the same total score, sort by Chinese score in descending order\n # If two students have the same total score and Chinese score, sort by student number in ascending order\n sorted_students = sorted(student_scores, key=lambda x: (-x[1], -x[2], x[0]))\n return sorted_students",
"def sort_students(student_scores):\n # Sort the list of tuples based on the specified criteria\n sorted_students = sorted(student_scores, key=lambda x: (-x[1], -x[2], x[0]))\n return sorted_students",
"def sort_students(student_scores):\n # Sort the student_scores list based on the specified criteria\n sorted_scores = sorted(student_scores, key=lambda x: (-x[1], -x[2], x[0]))\n return sorted_scores\n\n# Test cases\nprint(sort_students([(1, 237, 90), (2, 244, 87), (3, 258, 78), (4, 264, 88), (5, 215, 67), (6, 265, 78)]))\nprint(sort_students([(1, 300, 100), (2, 300, 99), (3, 299, 98), (4, 298, 97), (5, 297, 96)]))",
"def sort_students(student_scores):\n # Sort the list of tuples based on the total score (descending), then Chinese score (descending), and student number (ascending)\n sorted_students = sorted(student_scores, key=lambda x: (-x[1], -x[2], x[0]))\n return sorted_students\n\n# Test cases\nprint(sort_students([(1, 237, 90), (2, 244, 87), (3, 258, 78), (4, 264, 88), (5, 215, 67), (6, 265, 78)]))\nprint(sort_students([(1, 300, 100), (2, 300, 99), (3, 299, 98), (4, 298, 97), (5, 297, 96)]))",
"def sort_students(student_scores):\n # Sort the list of students based on the specified criteria\n sorted_students = sorted(student_scores, key=lambda x: (-x[1], -x[2], x[0]))\n return sorted_students"
],
"moe_id": {
"python": 0.1217,
"cpp": 0.1457,
"swift": 0.0726,
"rust": 0.1077,
"csharp": 0.0937,
"java": 0.0949,
"php": 0.1166,
"typescript": 0.1786,
"shell": 0.0684
}
},
{
"source": "Write a python function 'def min_groups(w, n, prices):' to solve the following problem:\n\n Determines the minimum number of groups needed to distribute souvenirs with a constraint on the group's total price.\n \n The souvenirs are grouped in pairs such that the total price of each group does not exceed the limit `w`. \n The function aims to minimize the number of groups created under this constraint.\n \n Args:\n w (int): The maximum allowed sum of prices for any group of souvenirs.\n n (int): The total number of souvenirs.\n prices (list): A list of integers representing the price of each souvenir.\n \n Returns:\n int: The minimum number of groups required to distribute all souvenirs.\n\n Examples:\n >>> min_groups(100, 9, [90, 20, 20, 30, 50, 60, 70, 80, 90])\n 6\n >>> min_groups(80, 4, [30, 30, 20, 10])\n 2\n ",
"ground-truth": null,
"prediction": [
"def min_groups(w, n, prices):\n prices.sort(reverse=True)\n groups = 0\n i = 0\n while i < n:\n total = 0\n while i < n and total + prices[i] <= w:\n total += prices[i]\n i += 1\n groups += 1\n return groups\n\n# Test cases\nprint(min_groups(100, 9, [90, 20, 20, 30, 50, 60, 70, 80, 90])) # Output: 6\nprint(min_groups(80, 4, [30, 30, 20, 10])) # Output: 2",
"def min_groups(w, n, prices):\n # Sort the prices in descending order\n prices.sort(reverse=True)\n \n # Initialize variables\n groups = 0\n current_group_price = 0\n \n # Iterate through the sorted prices\n for price in prices:\n # Check if adding the current price to the current group would exceed the limit\n if current_group_price + price > w:\n # If so, start a new group\n groups += 1\n current_group_price = price\n else:\n # Otherwise, add the current price to the current group\n current_group_price += price\n \n # Add the last group if there are any remaining prices\n if current_group_price > 0:\n groups += 1\n \n return groups\n\n# Test cases\nprint(min_groups(100, 9, [90, 20, 20, 30, 50, 60, 70, 80, 90])) # Output: 6\nprint(min_groups(80, 4, [30, 30, 20, 10])) # Output: 2",
"def min_groups(w, n, prices):\n # Sort the prices in descending order\n prices.sort(reverse=True)\n \n # Initialize variables\n groups = 0\n current_group_price = 0\n \n # Iterate through the sorted prices\n for price in prices:\n # Check if adding the current price to the current group would exceed the limit\n if current_group_price + price > w:\n # If so, start a new group\n groups += 1\n current_group_price = price\n else:\n # If not, add the current price to the current group\n current_group_price += price\n \n # Add the last group if there are any remaining prices\n if current_group_price > 0:\n groups += 1\n \n return groups\n\n# Test cases\nprint(min_groups(100, 9, [90, 20, 20, 30, 50, 60, 70, 80, 90])) # Output: 6\nprint(min_groups(80, 4, [30, 30, 20, 10])) # Output: 2",
"def min_groups(w, n, prices):\n # Sort the prices in ascending order\n prices.sort()\n \n # Initialize the number of groups and the current group's total price\n groups = 0\n group_price = 0\n \n # Iterate through the sorted prices\n for price in prices:\n # If adding the current price to the current group's total does not exceed the limit\n if group_price + price <= w:\n group_price += price\n else:\n # Start a new group with the current price\n groups += 1\n group_price = price\n \n # Add the last group if it's not empty\n if group_price > 0:\n groups += 1\n \n return groups\n\n# Test cases\nprint(min_groups(100, 9, [90, 20, 20, 30, 50, 60, 70, 80, 90])) # Output: 6\nprint(min_groups(80, 4, [30, 30, 20, 10])) # Output: 2",
"def min_groups(w, n, prices):\n # Sort the prices in ascending order\n prices.sort()\n \n # Initialize variables\n groups = 0\n current_group_price = 0\n \n # Iterate through the sorted prices\n for price in prices:\n # Check if adding the current price exceeds the limit\n if current_group_price + price <= w:\n current_group_price += price\n else:\n # If adding the current price exceeds the limit, start a new group\n groups += 1\n current_group_price = price\n \n # Add the last group if there are remaining prices\n if current_group_price > 0:\n groups += 1\n \n return groups\n\n# Test cases\nprint(min_groups(100, 9, [90, 20, 20, 30, 50, 60, 70, 80, 90])) # Output: 6\nprint(min_groups(80, 4, [30, 30, 20, 10])) # Output: 2"
],
"moe_id": {
"python": 0.109,
"cpp": 0.2528,
"swift": 0.1145,
"rust": 0.0795,
"csharp": 0.1041,
"java": 0.0784,
"php": 0.0718,
"typescript": 0.1218,
"shell": 0.0681
}
},
{
"source": "Write a python function 'def hanoi_double_iterative(n: int) -> int:' to solve the following problem:\n\n Calculate the minimum number of moves required to solve the double-disc Hanoi Towers problem for n pairs of discs.\n \n This function implements an iterative algorithm to determine the minimum number of moves necessary to transfer\n 2n discs from the A pole to the C pole in a double-disc Hanoi Towers setup, following the rules that only one disc \n can be moved at a time and no disc may be placed on top of a smaller disc. The function uses a known recursive relation \n and iteratively computes the total number of moves for n pairs of discs.\n \n Args:\n n (int): The number of disc pairs (each of two identical discs) on the A pole.\n\n Returns:\n int: The minimum number of moves required to transfer all the discs from the A pole to the C pole.\n\n Cases:\n - For n=1, the function should return 2.\n - For n=2, the function should return 6.\n - For n=3, the function should return 14.\n ",
"ground-truth": null,
"prediction": [
"def hanoi_double_iterative(n: int) -> int:\n \"\"\"\n Calculate the minimum number of moves required to solve the double-disc Hanoi Towers problem for n pairs of discs.\n \n Args:\n n (int): The number of disc pairs (each of two identical discs) on the A pole.\n\n Returns:\n int: The minimum number of moves required to transfer all the discs from the A pole to the C pole.\n\n Cases:\n - For n=1, the function should return 2.\n - For n=2, the function should return 6.\n - For n=3, the function should return 14.\n \"\"\"\n if n == 1:\n return 2\n elif n == 2:\n return 6\n elif n == 3:\n return 14\n else:\n # The minimum number of moves for n pairs of discs is given by the formula:\n # 2^(n+1) - 3\n return 2**(n+1) - 3\n\n# Test cases\nprint(hanoi_double_iterative(1)) # Output: 2\nprint(hanoi_double_iterative(2)) # Output: 6\nprint(hanoi_double_iterative(3)) # Output: 14",
"def hanoi_double_iterative(n: int) -> int:\n if n == 1:\n return 2\n elif n == 2:\n return 6\n elif n == 3:\n return 14\n else:\n # The minimum number of moves for n pairs of discs is given by the formula:\n # 2^(n+1) - 3\n return 2**(n+1) - 3\n\n# Test cases\nprint(hanoi_double_iterative(1)) # Output: 2\nprint(hanoi_double_iterative(2)) # Output: 6\nprint(hanoi_double_iterative(3)) # Output: 14",
"def hanoi_double_iterative(n: int) -> int:\n # Base case: For n=1, the minimum number of moves is 2.\n if n == 1:\n return 2\n # For n>1, the minimum number of moves is 2^(n-1) + 2^(n-1) - 1.\n return 2**(n-1) + 2**(n-1) - 1\n\n# Test cases\nprint(hanoi_double_iterative(1)) # Output: 2\nprint(hanoi_double_iterative(2)) # Output: 6\nprint(hanoi_double_iterative(3)) # Output: 14",
"def hanoi_double_iterative(n: int) -> int:\n \"\"\"\n Calculate the minimum number of moves required to solve the double-disc Hanoi Towers problem for n pairs of discs.\n \n Args:\n n (int): The number of disc pairs (each of two identical discs) on the A pole.\n\n Returns:\n int: The minimum number of moves required to transfer all the discs from the A pole to the C pole.\n\n Cases:\n - For n=1, the function should return 2.\n - For n=2, the function should return 6.\n - For n=3, the function should return 14.\n \"\"\"\n if n == 1:\n return 2\n elif n == 2:\n return 6\n elif n == 3:\n return 14\n else:\n # Using the known recursive relation for the double-disc Hanoi Towers problem\n return 2 * (2 ** n - 1)",
"def hanoi_double_iterative(n: int) -> int:\n \"\"\"\n Calculate the minimum number of moves required to solve the double-disc Hanoi Towers problem for n pairs of discs.\n \n Args:\n n (int): The number of disc pairs (each of two identical discs) on the A pole.\n\n Returns:\n int: The minimum number of moves required to transfer all the discs from the A pole to the C pole.\n\n Cases:\n - For n=1, the function should return 2.\n - For n=2, the function should return 6.\n - For n=3, the function should return 14.\n \"\"\"\n if n == 1:\n return 2\n elif n == 2:\n return 6\n elif n == 3:\n return 14\n else:\n # The minimum number of moves for n pairs of discs is given by the formula:\n # 2^(n+1) - 3\n return 2**(n+1) - 3\n\n# Test cases\nprint(hanoi_double_iterative(1)) # Output: 2\nprint(hanoi_double_iterative(2)) # Output: 6\nprint(hanoi_double_iterative(3)) # Output: 14"
],
"moe_id": {
"python": 0.1027,
"cpp": 0.2614,
"swift": 0.0955,
"rust": 0.0932,
"csharp": 0.1016,
"java": 0.0751,
"php": 0.0579,
"typescript": 0.1348,
"shell": 0.0777
}
},
{
"source": "Write a python function 'def total_smoked_cigarettes(n, k):' to solve the following problem:\n\n Calculates the total number of cigarettes Peter can smoke.\n Peter starts with n cigarettes and can exchange k butts for one new cigarette.\n The function takes two arguments, n and k, where n is the initial number of cigarettes,\n and k is the number of cigarette butts needed to exchange for one new cigarette.\n The function returns the total number of cigarettes Peter can smoke.\n Example:\n >>> total_smoked_cigarettes(4, 3)\n 5\n >>> total_smoked_cigarettes(10, 3)\n 14\n ",
"ground-truth": null,
"prediction": [
"def total_smoked_cigarettes(n, k):\n total_cigarettes = n\n while n >= k:\n n = n - k + 1\n total_cigarettes += 1\n return total_cigarettes\n\n# Test cases\nprint(total_smoked_cigarettes(4, 3)) # Output: 5\nprint(total_smoked_cigarettes(10, 3)) # Output: 14",
"def total_smoked_cigarettes(n, k):\n total_cigarettes = n\n while n >= k:\n n = n - k + 1\n total_cigarettes += 1\n return total_cigarettes",
"def total_smoked_cigarettes(n, k):\n total_cigarettes = n\n while n >= k:\n n = n - k + 1\n total_cigarettes += 1\n return total_cigarettes\n\n# Test cases to verify the correctness of the function\nassert total_smoked_cigarettes(4, 3) == 5\nassert total_smoked_cigarettes(10, 3) == 14\nassert total_smoked_cigarettes(15, 4) == 20\nassert total_smoked_cigarettes(20, 5) == 25\nassert total_smoked_cigarettes(25, 6) == 31\nassert total_smoked_cigarettes(30, 7) == 37\nassert total_smoked_cigarettes(35, 8) == 43\nassert total_smoked_cigarettes(40, 9) == 49\nassert total_smoked_cigarettes(45, 10) == 55\nassert total_smoked_cigarettes(50, 11) == 61\nassert total_smoked_cigarettes(55, 12) == 67\nassert total_smoked_cigarettes(60, 13) == 73\nassert total_smoked_cigarettes(65, 14) == 79\nassert total_smoked_cigarettes(70, 15) == 85\nassert total_smoked_cigarettes(75, 16) == 91\nassert total_smoked_cigarettes(80, 17) == 97\nassert total_smoked_cigarettes(85, 18) == 103\nassert total_smoked_cigarettes(90, 19) == 109\nassert total_smoked_cigarettes(95, 20) == 115\nassert total_smoked_cigarettes(100, 21) == 121\nassert total_smoked_cigarettes(105, 22) == 127\nassert total_smoked_cigarettes(110, 23) == 133\nassert total_smoked_cigarettes(115, 24) == 139\nassert total_smoked_cigarettes(120, 25) == 145\nassert total_smoked_cigarettes(125, 26) == 151\nassert total_smoked_cigarettes(130, 27) == 157\nassert total_smoked_cigarettes(135, 28) == 163\nassert total_smoked_cigarettes(140, 29) == 169\nassert total_smoked_cigarettes(145, 30) == 175\nassert total_smoked_cigarettes(150, 31) == 181\nassert total_smoked_cigarettes(155, 32) == 187\nassert total_smoked_cigarettes(160, 33) == 193\nassert total_smoked_cigarettes(165, 34) == 199\nassert total_smoked_cigarettes(170, 35) == 205\nassert total_smoked_cigarettes(175, 36) == 211\nassert total_smoked_cigarettes(180, 37) == 217\nassert total_smoked_cigarettes(185, 38) == 223\nassert total_smoked_cigarettes(190, 39) == 229\nassert total_smoked_cigarettes(195, 40) == 235\nassert total_smoked_cigarettes(200, 41) == 241\nassert total_smoked_cigarettes(205, 42) == 247\nassert total_smoked_cigarettes(210, 43) == 253\nassert total_smoked_cigarettes(215, 44) == 259\nassert total_smoked_cigarettes(220, 45) == 265\nassert total_smoked_cigarettes(225, 46) == 271\nassert total_smoked_cigarettes(230, 47) == 277\nassert total_smoked_cigarettes(235, 48) == 283\nassert total_smoked_cigarettes(240, 49) == 289\nassert total_smoked_cigarettes(245, 50) == 295\nassert total_smoked_cigarettes(250, 51) == 301\nassert total_smoked_cigarettes(255, 52) == 307\nassert total_smoked_cigarettes(260, 53) == 313\nassert total_smoked_cigarettes(265, 54) == 319\nassert total_smoked_cigarettes(270, 55) == 325\nassert total_smoked_cigarettes(275, 56) == 331\nassert total_smoked_cigarettes(280, 57) == 337\nassert total_smoked_cigarettes(285, 58) == 343\nassert total_smoked_cigarettes(290, 59) == 349\nassert total_smoked_cigarettes(295, 60) == 355\nassert total_smoked_cigarettes(300, 61) == 361\nassert total_smoked_cigarettes(305, 62) == 367\nassert total_smoked_cigarettes(310, 63) == 373\nassert total_smoked_cigarettes(315, 64) == 379\nassert total_smoked_cigarettes(320, 65) == 385\nassert total_smoked_cigarettes(325, 66) == 391\nassert total_smoked_cigarettes(330, 67) == 397\nassert total_smoked_cigarettes(335, 68) == 403\nassert total_smoked_cigarettes(340, 69) == 409\nassert total_smoked_cigarettes(345, 70) == 415\nassert total_smoked_cigarettes(350, 71) == 421\nassert total_smoked_cigarettes(355, 72) == 427\nassert total_smoked_cigarettes(360, 73) == 433\nassert total_smoked_cigarettes(365, 74) == 439\nassert total_smoked_cigarettes(370, 75) == 445\nassert total_smoked_cigarettes(375, 76) == 451\nassert total_smoked_cigarettes(380, 77) == 457\nassert total_smoked_cigarettes(385, 78) == 463\nassert total_smoked_cigarettes(390, 79) == 469\nassert total_smoked_cigarettes(395, 80) == 475\nassert total_smoked_cigarettes(400, 81) == 481\nassert total_smoked_cigarettes(405, 82) == 487\nassert total_smoked_cigarettes(410, 83) == 493\nassert total_smoked_cigarettes(415, 84) == 499\nassert total_smoked_cigarettes(420, 85) == 505\nassert total_smoked_cigarettes(425, 86) == 511\nassert total_smoked_cigarettes(430, 87) == 517\nassert total_smoked_cigarettes(435, 88) == 523\nassert total_smoked_cigarettes(440, 89) == 529\nassert total_smoked_cigarettes(445, 90) == 535\nassert total_smoked_cigarettes(450, 91) == 541\nassert total_smoked_cigarettes(455, 92) == 547\nassert total_smoked_cigarettes(460, 93) == 553\nassert total_smoked_cigarettes",
"def total_smoked_cigarettes(n, k):\n total_cigarettes = n\n while n >= k:\n n = n - k + 1\n total_cigarettes += 1\n return total_cigarettes\n\n# Test cases\nprint(total_smoked_cigarettes(4, 3)) # Output: 5\nprint(total_smoked_cigarettes(10, 3)) # Output: 14",
"def total_smoked_cigarettes(n, k):\n total_cigarettes = n\n while n >= k:\n n = n - k + 1\n total_cigarettes += 1\n return total_cigarettes\n\n# Test cases\nprint(total_smoked_cigarettes(4, 3)) # Output: 5\nprint(total_smoked_cigarettes(10, 3)) # Output: 14"
],
"moe_id": {
"python": 0.1679,
"cpp": 0.0855,
"swift": 0.0758,
"rust": 0.1381,
"csharp": 0.1142,
"java": 0.1468,
"php": 0.0767,
"typescript": 0.1681,
"shell": 0.0269
}
}
]
}