Prompt:
from typing import List
def repairCars(ranks: List[int], cars: int) -> int:
    """
    You are given an integer array ranks representing the ranks of some mechanics. ranksi is the rank of the ith mechanic. A mechanic with a rank r can repair n cars in r * n2 minutes.
    You are also given an integer cars representing the total number of cars waiting in the garage to be repaired.
    Return the minimum time taken to repair all the cars.
    Note: All the mechanics can repair the cars simultaneously.

    Example 1:

    >>> repairCars(ranks = [4,2,3,1], cars = 10)
    >>> 16
    Explanation:
    - The first mechanic will repair two cars. The time required is 4 * 2 * 2 = 16 minutes.
    - The second mechanic will repair two cars. The time required is 2 * 2 * 2 = 8 minutes.
    - The third mechanic will repair two cars. The time required is 3 * 2 * 2 = 12 minutes.
    - The fourth mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.
    It can be proved that the cars cannot be repaired in less than 16 minutes.

    Example 2:

    >>> repairCars(ranks = [5,1,8], cars = 6)
    >>> 16
    Explanation:
    - The first mechanic will repair one car. The time required is 5 * 1 * 1 = 5 minutes.
    - The second mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.
    - The third mechanic will repair one car. The time required is 8 * 1 * 1 = 8 minutes.
    It can be proved that the cars cannot be repaired in less than 16 minutes.
    """


Prompt:
from typing import List
def evenOddBit(n: int) -> List[int]:
    """
    You are given a positive integer n.
    Let even denote the number of even indices in the binary representation of n with value 1.
    Let odd denote the number of odd indices in the binary representation of n with value 1.
    Note that bits are indexed from right to left in the binary representation of a number.
    Return the array [even, odd].

    Example 1:

    >>> evenOddBit(n = 50)
    >>> [1,2]
    Explanation:
    The binary representation of 50 is 110010.
    It contains 1 on indices 1, 4, and 5.

    Example 2:

    >>> evenOddBit(n = 2)
    >>> [0,1]
    Explanation:
    The binary representation of 2 is 10.
    It contains 1 only on index 1.
    """


Prompt:
from typing import List
def checkValidGrid(grid: List[List[int]]) -> bool:
    """
    There is a knight on an n x n chessboard. In a valid configuration, the knight starts at the top-left cell of the board and visits every cell on the board exactly once.
    You are given an n x n integer matrix grid consisting of distinct integers from the range [0, n * n - 1] where grid[row][col] indicates that the cell (row, col) is the grid[row][col]th cell that the knight visited. The moves are 0-indexed.
    Return true if grid represents a valid configuration of the knight's movements or false otherwise.
    Note that a valid knight move consists of moving two squares vertically and one square horizontally, or two squares horizontally and one square vertically. The figure below illustrates all the possible eight moves of a knight from some cell.

    Example 1:

    >>> checkValidGrid(grid = [[0,11,16,5,20],[17,4,19,10,15],[12,1,8,21,6],[3,18,23,14,9],[24,13,2,7,22]])
    >>> true
    Explanation: The above diagram represents the grid. It can be shown that it is a valid configuration.

    Example 2:

    >>> checkValidGrid(grid = [[0,3,6],[5,8,1],[2,7,4]])
    >>> false
    Explanation: The above diagram represents the grid. The 8th move of the knight is not valid considering its position after the 7th move.
    """


Prompt:
from typing import List
def beautifulSubsets(nums: List[int], k: int) -> int:
    """
    You are given an array nums of positive integers and a positive integer k.
    A subset of nums is beautiful if it does not contain two integers with an absolute difference equal to k.
    Return the number of non-empty beautiful subsets of the array nums.
    A subset of nums is an array that can be obtained by deleting some (possibly none) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.

    Example 1:

    >>> beautifulSubsets(nums = [2,4,6], k = 2)
    >>> 4
    Explanation: The beautiful subsets of the array nums are: [2], [4], [6], [2, 6].
    It can be proved that there are only 4 beautiful subsets in the array [2,4,6].

    Example 2:

    >>> beautifulSubsets(nums = [1], k = 1)
    >>> 1
    Explanation: The beautiful subset of the array nums is [1].
    It can be proved that there is only 1 beautiful subset in the array [1].
    """


Prompt:
from typing import List
def findSmallestInteger(nums: List[int], value: int) -> int:
    """
    You are given a 0-indexed integer array nums and an integer value.
    In one operation, you can add or subtract value from any element of nums.

    For example, if nums = [1,2,3] and value = 2, you can choose to subtract value from nums[0] to make nums = [-1,2,3].

    The MEX (minimum excluded) of an array is the smallest missing non-negative integer in it.

    For example, the MEX of [-1,2,3] is 0 while the MEX of [1,0,3] is 2.

    Return the maximum MEX of nums after applying the mentioned operation any number of times.

    Example 1:

    >>> findSmallestInteger(nums = [1,-10,7,13,6,8], value = 5)
    >>> 4
    Explanation: One can achieve this result by applying the following operations:
    - Add value to nums[1] twice to make nums = [1,0,7,13,6,8]
    - Subtract value from nums[2] once to make nums = [1,0,2,13,6,8]
    - Subtract value from nums[3] twice to make nums = [1,0,2,3,6,8]
    The MEX of nums is 4. It can be shown that 4 is the maximum MEX we can achieve.

    Example 2:

    >>> findSmallestInteger(nums = [1,-10,7,13,6,8], value = 7)
    >>> 2
    Explanation: One can achieve this result by applying the following operation:
    - subtract value from nums[2] once to make nums = [1,-10,0,13,6,8]
    The MEX of nums is 2. It can be shown that 2 is the maximum MEX we can achieve.
    """


Prompt:
from typing import List
def makePrefSumNonNegative(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums. You can apply the following operation any number of times:

    Pick any element from nums and put it at the end of nums.

    The prefix sum array of nums is an array prefix of the same length as nums such that prefix[i] is the sum of all the integers nums[j] where j is in the inclusive range [0, i].
    Return the minimum number of operations such that the prefix sum array does not contain negative integers. The test cases are generated such that it is always possible to make the prefix sum array non-negative.

    Example 1:

    >>> makePrefSumNonNegative(nums = [2,3,-5,4])
    >>> 0
    Explanation: we do not need to do any operations.
    The array is [2,3,-5,4]. The prefix sum array is [2, 5, 0, 4].

    Example 2:

    >>> makePrefSumNonNegative(nums = [3,-5,-2,6])
    >>> 1
    Explanation: we can do one operation on index 1.
    The array after the operation is [3,-2,6,-5]. The prefix sum array is [3, 1, 7, 2].
    """


Prompt:
def kItemsWithMaximumSum(numOnes: int, numZeros: int, numNegOnes: int, k: int) -> int:
    """
    There is a bag that consists of items, each item has a number 1, 0, or -1 written on it.
    You are given four non-negative integers numOnes, numZeros, numNegOnes, and k.
    The bag initially contains:

    numOnes items with 1s written on them.
    numZeroes items with 0s written on them.
    numNegOnes items with -1s written on them.

    We want to pick exactly k items among the available items. Return the maximum possible sum of numbers written on the items.

    Example 1:

    >>> kItemsWithMaximumSum(numOnes = 3, numZeros = 2, numNegOnes = 0, k = 2)
    >>> 2
    Explanation: We have a bag of items with numbers written on them {1, 1, 1, 0, 0}. We take 2 items with 1 written on them and get a sum in a total of 2.
    It can be proven that 2 is the maximum possible sum.

    Example 2:

    >>> kItemsWithMaximumSum(numOnes = 3, numZeros = 2, numNegOnes = 0, k = 4)
    >>> 3
    Explanation: We have a bag of items with numbers written on them {1, 1, 1, 0, 0}. We take 3 items with 1 written on them, and 1 item with 0 written on it, and get a sum in a total of 3.
    It can be proven that 3 is the maximum possible sum.
    """


Prompt:
from typing import List
def primeSubOperation(nums: List[int]) -> bool:
    """
    You are given a 0-indexed integer array nums of length n.
    You can perform the following operation as many times as you want:

    Pick an index i that you haven’t picked before, and pick a prime p strictly less than nums[i], then subtract p from nums[i].

    Return true if you can make nums a strictly increasing array using the above operation and false otherwise.
    A strictly increasing array is an array whose each element is strictly greater than its preceding element.

    Example 1:

    >>> primeSubOperation(nums = [4,9,6,10])
    >>> true
    Explanation: In the first operation: Pick i = 0 and p = 3, and then subtract 3 from nums[0], so that nums becomes [1,9,6,10].
    In the second operation: i = 1, p = 7, subtract 7 from nums[1], so nums becomes equal to [1,2,6,10].
    After the second operation, nums is sorted in strictly increasing order, so the answer is true.
    Example 2:

    >>> primeSubOperation(nums = [6,8,11,12])
    >>> true
    Explanation: Initially nums is sorted in strictly increasing order, so we don't need to make any operations.
    Example 3:

    >>> primeSubOperation(nums = [5,8,3])
    >>> false
    Explanation: It can be proven that there is no way to perform operations to make nums sorted in strictly increasing order, so the answer is false.
    """


Prompt:
from typing import List
def minOperations(nums: List[int], queries: List[int]) -> List[int]:
    """
    You are given an array nums consisting of positive integers.
    You are also given an integer array queries of size m. For the ith query, you want to make all of the elements of nums equal to queries[i]. You can perform the following operation on the array any number of times:

    Increase or decrease an element of the array by 1.

    Return an array answer of size m where answer[i] is the minimum number of operations to make all elements of nums equal to queries[i].
    Note that after each query the array is reset to its original state.

    Example 1:

    >>> minOperations(nums = [3,1,6,8], queries = [1,5])
    >>> [14,10]
    Explanation: For the first query we can do the following operations:
    - Decrease nums[0] 2 times, so that nums = [1,1,6,8].
    - Decrease nums[2] 5 times, so that nums = [1,1,1,8].
    - Decrease nums[3] 7 times, so that nums = [1,1,1,1].
    So the total number of operations for the first query is 2 + 5 + 7 = 14.
    For the second query we can do the following operations:
    - Increase nums[0] 2 times, so that nums = [5,1,6,8].
    - Increase nums[1] 4 times, so that nums = [5,5,6,8].
    - Decrease nums[2] 1 time, so that nums = [5,5,5,8].
    - Decrease nums[3] 3 times, so that nums = [5,5,5,5].
    So the total number of operations for the second query is 2 + 4 + 1 + 3 = 10.

    Example 2:

    >>> minOperations(nums = [2,9,6,3], queries = [10])
    >>> [20]
    Explanation: We can increase each value in the array to 10. The total number of operations will be 8 + 1 + 4 + 7 = 20.
    """


Prompt:
from typing import List
def collectTheCoins(coins: List[int], edges: List[List[int]]) -> int:
    """
    There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given an integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given an array coins of size n where coins[i] can be either 0 or 1, where 1 indicates the presence of a coin in the vertex i.
    Initially, you choose to start at any vertex in the tree. Then, you can perform the following operations any number of times:

    Collect all the coins that are at a distance of at most 2 from the current vertex, or
    Move to any adjacent vertex in the tree.

    Find the minimum number of edges you need to go through to collect all the coins and go back to the initial vertex.
    Note that if you pass an edge several times, you need to count it into the answer several times.

    Example 1:

    >>> collectTheCoins(coins = [1,0,0,0,0,1], edges = [[0,1],[1,2],[2,3],[3,4],[4,5]])
    >>> 2
    Explanation: Start at vertex 2, collect the coin at vertex 0, move to vertex 3, collect the coin at vertex 5 then move back to vertex 2.

    Example 2:

    >>> collectTheCoins(coins = [0,0,0,1,1,0,0,1], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[5,6],[5,7]])
    >>> 2
    Explanation: Start at vertex 0, collect the coins at vertices 4 and 3, move to vertex 2,  collect the coin at vertex 7, then move back to vertex 0.
    """


Prompt:
from typing import Any, List
def minimumTime(hens: List[int], grains: List[int]) -> int:
    """
    There are n hens and m grains on a line. You are given the initial positions of the hens and the grains in two integer arrays hens and grains of size n and m respectively.
    Any hen can eat a grain if they are on the same position. The time taken for this is negligible. One hen can also eat multiple grains.
    In 1 second, a hen can move right or left by 1 unit. The hens can move simultaneously and independently of each other.
    Return the minimum time to eat all grains if the hens act optimally.

    Example 1:

    >>> minimumTime(hens = [3,6,7], grains = [2,4,7,9])
    >>> 2
    Explanation:
    One of the ways hens eat all grains in 2 seconds is described below:
    - The first hen eats the grain at position 2 in 1 second.
    - The second hen eats the grain at position 4 in 2 seconds.
    - The third hen eats the grains at positions 7 and 9 in 2 seconds.
    So, the maximum time needed is 2.
    It can be proven that the hens cannot eat all grains before 2 seconds.
    Example 2:

    >>> minimumTime(hens = [4,6,109,111,213,215], grains = [5,110,214])
    >>> 1
    Explanation:
    One of the ways hens eat all grains in 1 second is described below:
    - The first hen eats the grain at position 5 in 1 second.
    - The fourth hen eats the grain at position 110 in 1 second.
    - The sixth hen eats the grain at position 214 in 1 second.
    - The other hens do not move.
    So, the maximum time needed is 1.
    """


Prompt:
from typing import List
def minNumber(nums1: List[int], nums2: List[int]) -> int:
    """
    Given two arrays of unique digits nums1 and nums2, return the smallest number that contains at least one digit from each array.

    Example 1:

    >>> minNumber(nums1 = [4,1,3], nums2 = [5,7])
    >>> 15
    Explanation: The number 15 contains the digit 1 from nums1 and the digit 5 from nums2. It can be proven that 15 is the smallest number we can have.

    Example 2:

    >>> minNumber(nums1 = [3,5,2,6], nums2 = [3,1,7])
    >>> 3
    Explanation: The number 3 contains the digit 3 which exists in both arrays.
    """


Prompt:
from typing import List
def maximumCostSubstring(s: str, chars: str, vals: List[int]) -> int:
    """
    You are given a string s, a string chars of distinct characters and an integer array vals of the same length as chars.
    The cost of the substring is the sum of the values of each character in the substring. The cost of an empty string is considered 0.
    The value of the character is defined in the following way:

    If the character is not in the string chars, then its value is its corresponding position (1-indexed) in the alphabet.

    For example, the value of 'a' is 1, the value of 'b' is 2, and so on. The value of 'z' is 26.

    Otherwise, assuming i is the index where the character occurs in the string chars, then its value is vals[i].

    Return the maximum cost among all substrings of the string s.

    Example 1:

    >>> maximumCostSubstring(s = "adaa", chars = "d", vals = [-1000])
    >>> 2
    Explanation: The value of the characters "a" and "d" is 1 and -1000 respectively.
    The substring with the maximum cost is "aa" and its cost is 1 + 1 = 2.
    It can be proven that 2 is the maximum cost.

    Example 2:

    >>> maximumCostSubstring(s = "abc", chars = "abc", vals = [-1,-1,-1])
    >>> 0
    Explanation: The value of the characters "a", "b" and "c" is -1, -1, and -1 respectively.
    The substring with the maximum cost is the empty substring "" and its cost is 0.
    It can be proven that 0 is the maximum cost.
    """


Prompt:
from typing import List
def makeSubKSumEqual(arr: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array arr and an integer k. The array arr is circular. In other words, the first element of the array is the next element of the last element, and the last element of the array is the previous element of the first element.
    You can do the following operation any number of times:

    Pick any element from arr and increase or decrease it by 1.

    Return the minimum number of operations such that the sum of each subarray of length k is equal.
    A subarray is a contiguous part of the array.

    Example 1:

    >>> makeSubKSumEqual(arr = [1,4,1,3], k = 2)
    >>> 1
    Explanation: we can do one operation on index 1 to make its value equal to 3.
    The array after the operation is [1,3,1,3]
    - Subarray starts at index 0 is [1, 3], and its sum is 4
    - Subarray starts at index 1 is [3, 1], and its sum is 4
    - Subarray starts at index 2 is [1, 3], and its sum is 4
    - Subarray starts at index 3 is [3, 1], and its sum is 4

    Example 2:

    >>> makeSubKSumEqual(arr = [2,5,5,7], k = 3)
    >>> 5
    Explanation: we can do three operations on index 0 to make its value equal to 5 and two operations on index 3 to make its value equal to 5.
    The array after the operations is [5,5,5,5]
    - Subarray starts at index 0 is [5, 5, 5], and its sum is 15
    - Subarray starts at index 1 is [5, 5, 5], and its sum is 15
    - Subarray starts at index 2 is [5, 5, 5], and its sum is 15
    - Subarray starts at index 3 is [5, 5, 5], and its sum is 15
    """


Prompt:
from typing import List
def findShortestCycle(n: int, edges: List[List[int]]) -> int:
    """
    There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1. The edges in the graph are represented by a given 2D integer array edges, where edges[i] = [ui, vi] denotes an edge between vertex ui and vertex vi. Every vertex pair is connected by at most one edge, and no vertex has an edge to itself.
    Return the length of the shortest cycle in the graph. If no cycle exists, return -1.
    A cycle is a path that starts and ends at the same node, and each edge in the path is used only once.

    Example 1:

    >>> findShortestCycle(n = 7, edges = [[0,1],[1,2],[2,0],[3,4],[4,5],[5,6],[6,3]])
    >>> 3
    Explanation: The cycle with the smallest length is : 0 -> 1 -> 2 -> 0

    Example 2:

    >>> findShortestCycle(n = 4, edges = [[0,1],[0,2]])
    >>> -1
    Explanation: There are no cycles in this graph.
    """


Prompt:
def findTheLongestBalancedSubstring(s: str) -> int:
    """
    You are given a binary string s consisting only of zeroes and ones.
    A substring of s is considered balanced if all zeroes are before ones and the number of zeroes is equal to the number of ones inside the substring. Notice that the empty substring is considered a balanced substring.
    Return the length of the longest balanced substring of s.
    A substring is a contiguous sequence of characters within a string.

    Example 1:

    >>> findTheLongestBalancedSubstring(s = "01000111")
    >>> 6
    Explanation: The longest balanced substring is "000111", which has length 6.

    Example 2:

    >>> findTheLongestBalancedSubstring(s = "00111")
    >>> 4
    Explanation: The longest balanced substring is "0011", which has length 4.

    Example 3:

    >>> findTheLongestBalancedSubstring(s = "111")
    >>> 0
    Explanation: There is no balanced substring except the empty substring, so the answer is 0.
    """


Prompt:
from typing import List
def findMatrix(nums: List[int]) -> List[List[int]]:
    """
    You are given an integer array nums. You need to create a 2D array from nums satisfying the following conditions:

    The 2D array should contain only the elements of the array nums.
    Each row in the 2D array contains distinct integers.
    The number of rows in the 2D array should be minimal.

    Return the resulting array. If there are multiple answers, return any of them.
    Note that the 2D array can have a different number of elements on each row.

    Example 1:

    >>> findMatrix(nums = [1,3,4,1,2,3,1])
    >>> [[1,3,4,2],[1,3],[1]]
    Explanation: We can create a 2D array that contains the following rows:
    - 1,3,4,2
    - 1,3
    - 1
    All elements of nums were used, and each row of the 2D array contains distinct integers, so it is a valid answer.
    It can be shown that we cannot have less than 3 rows in a valid array.
    Example 2:

    >>> findMatrix(nums = [1,2,3,4])
    >>> [[4,3,2,1]]
    Explanation: All elements of the array are distinct, so we can keep all of them in the first row of the 2D array.
    """


Prompt:
from typing import List
def miceAndCheese(reward1: List[int], reward2: List[int], k: int) -> int:
    """
    There are two mice and n different types of cheese, each type of cheese should be eaten by exactly one mouse.
    A point of the cheese with index i (0-indexed) is:

    reward1[i] if the first mouse eats it.
    reward2[i] if the second mouse eats it.

    You are given a positive integer array reward1, a positive integer array reward2, and a non-negative integer k.
    Return the maximum points the mice can achieve if the first mouse eats exactly k types of cheese.

    Example 1:

    >>> miceAndCheese(reward1 = [1,1,3,4], reward2 = [4,4,1,1], k = 2)
    >>> 15
    Explanation: In this example, the first mouse eats the 2nd (0-indexed) and the 3rd types of cheese, and the second mouse eats the 0th and the 1st types of cheese.
    The total points are 4 + 4 + 3 + 4 = 15.
    It can be proven that 15 is the maximum total points that the mice can achieve.

    Example 2:

    >>> miceAndCheese(reward1 = [1,1], reward2 = [1,1], k = 2)
    >>> 2
    Explanation: In this example, the first mouse eats the 0th (0-indexed) and 1st types of cheese, and the second mouse does not eat any cheese.
    The total points are 1 + 1 = 2.
    It can be proven that 2 is the maximum total points that the mice can achieve.
    """


Prompt:
from typing import List
def beautifulPair(nums1: List[int], nums2: List[int]) -> List[int]:
    """
    You are given two 0-indexed integer arrays nums1 and nums2 of the same length. A pair of indices (i,j) is called beautiful if|nums1[i] - nums1[j]| + |nums2[i] - nums2[j]| is the smallest amongst all possible indices pairs where i < j.
    Return the beautiful pair. In the case that there are multiple beautiful pairs, return the lexicographically smallest pair.
    Note that

    |x| denotes the absolute value of x.
    A pair of indices (i1, j1) is lexicographically smaller than (i2, j2) if i1 < i2 or i1 == i2 and j1 < j2.

    Example 1:

    >>> beautifulPair(nums1 = [1,2,3,2,4], nums2 = [2,3,1,2,3])
    >>> [0,3]
    Explanation: Consider index 0 and index 3. The value of |nums1[i]-nums1[j]| + |nums2[i]-nums2[j]| is 1, which is the smallest value we can achieve.

    Example 2:

    >>> beautifulPair(nums1 = [1,2,4,3,2,5], nums2 = [1,4,2,3,5,1])
    >>> [1,4]
    Explanation: Consider index 1 and index 4. The value of |nums1[i]-nums1[j]| + |nums2[i]-nums2[j]| is 1, which is the smallest value we can achieve.
    """


Prompt:
from typing import List
def diagonalPrime(nums: List[List[int]]) -> int:
    """
    You are given a 0-indexed two-dimensional integer array nums.
    Return the largest prime number that lies on at least one of the diagonals of nums. In case, no prime is present on any of the diagonals, return 0.
    Note that:

    An integer is prime if it is greater than 1 and has no positive integer divisors other than 1 and itself.
    An integer val is on one of the diagonals of nums if there exists an integer i for which nums[i][i] = val or an i for which nums[i][nums.length - i - 1] = val.

    In the above diagram, one diagonal is [1,5,9] and another diagonal is [3,5,7].

    Example 1:

    >>> diagonalPrime(nums = [[1,2,3],[5,6,7],[9,10,11]])
    >>> 11
    Explanation: The numbers 1, 3, 6, 9, and 11 are the only numbers present on at least one of the diagonals. Since 11 is the largest prime, we return 11.

    Example 2:

    >>> diagonalPrime(nums = [[1,2,3],[5,17,7],[9,11,10]])
    >>> 17
    Explanation: The numbers 1, 3, 9, 10, and 17 are all present on at least one of the diagonals. 17 is the largest prime, so we return 17.
    """


Prompt:
from typing import List
def distance(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed integer array nums. There exists an array arr of length nums.length, where arr[i] is the sum of |i - j| over all j such that nums[j] == nums[i] and j != i. If there is no such j, set arr[i] to be 0.
    Return the array arr.

    Example 1:

    >>> distance(nums = [1,3,1,1,2])
    >>> [5,0,3,4,0]
    Explanation:
    When i = 0, nums[0] == nums[2] and nums[0] == nums[3]. Therefore, arr[0] = |0 - 2| + |0 - 3| = 5.
    When i = 1, arr[1] = 0 because there is no other index with value 3.
    When i = 2, nums[2] == nums[0] and nums[2] == nums[3]. Therefore, arr[2] = |2 - 0| + |2 - 3| = 3.
    When i = 3, nums[3] == nums[0] and nums[3] == nums[2]. Therefore, arr[3] = |3 - 0| + |3 - 2| = 4.
    When i = 4, arr[4] = 0 because there is no other index with value 2.

    Example 2:

    >>> distance(nums = [0,5,3])
    >>> [0,0,0]
    Explanation: Since each element in nums is distinct, arr[i] = 0 for all i.
    """


Prompt:
from typing import List
def minimizeMax(nums: List[int], p: int) -> int:
    """
    You are given a 0-indexed integer array nums and an integer p. Find p pairs of indices of nums such that the maximum difference amongst all the pairs is minimized. Also, ensure no index appears more than once amongst the p pairs.
    Note that for a pair of elements at the index i and j, the difference of this pair is |nums[i] - nums[j]|, where |x| represents the absolute value of x.
    Return the minimum maximum difference among all p pairs. We define the maximum of an empty set to be zero.

    Example 1:

    >>> minimizeMax(nums = [10,1,2,7,1,3], p = 2)
    >>> 1
    Explanation: The first pair is formed from the indices 1 and 4, and the second pair is formed from the indices 2 and 5.
    The maximum difference is max(|nums[1] - nums[4]|, |nums[2] - nums[5]|) = max(0, 1) = 1. Therefore, we return 1.

    Example 2:

    >>> minimizeMax(nums = [4,2,1,2], p = 1)
    >>> 0
    Explanation: Let the indices 1 and 3 form a pair. The difference of that pair is |2 - 2| = 0, which is the minimum we can attain.
    """


Prompt:
from typing import List
def minimumVisitedCells(grid: List[List[int]]) -> int:
    """
    You are given a 0-indexed m x n integer matrix grid. Your initial position is at the top-left cell (0, 0).
    Starting from the cell (i, j), you can move to one of the following cells:

    Cells (i, k) with j < k <= grid[i][j] + j (rightward movement), or
    Cells (k, j) with i < k <= grid[i][j] + i (downward movement).

    Return the minimum number of cells you need to visit to reach the bottom-right cell (m - 1, n - 1). If there is no valid path, return -1.

    Example 1:

    >>> minimumVisitedCells(grid = [[3,4,2,1],[4,2,3,1],[2,1,0,0],[2,4,0,0]])
    >>> 4
    Explanation: The image above shows one of the paths that visits exactly 4 cells.

    Example 2:

    >>> minimumVisitedCells(grid = [[3,4,2,1],[4,2,1,1],[2,1,1,0],[3,4,1,0]])
    >>> 3
    Explanation: The image above shows one of the paths that visits exactly 3 cells.

    Example 3:

    >>> minimumVisitedCells(grid = [[2,1,0],[1,0,0]])
    >>> -1
    Explanation: It can be proven that no path exists.
    """


Prompt:
from typing import List
def countTheNumOfKFreeSubsets(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums, which contains distinct elements and an integer k.
    A subset is called a k-Free subset if it contains no two elements with an absolute difference equal to k. Notice that the empty set is a k-Free subset.
    Return the number of k-Free subsets of nums.
    A subset of an array is a selection of elements (possibly none) of the array.

    Example 1:

    >>> countTheNumOfKFreeSubsets(nums = [5,4,6], k = 1)
    >>> 5
    Explanation: There are 5 valid subsets: {}, {5}, {4}, {6} and {4, 6}.

    Example 2:

    >>> countTheNumOfKFreeSubsets(nums = [2,3,5,8], k = 5)
    >>> 12
    Explanation: There are 12 valid subsets: {}, {2}, {3}, {5}, {8}, {2, 3}, {2, 3, 5}, {2, 5}, {2, 5, 8}, {2, 8}, {3, 5} and {5, 8}.

    Example 3:

    >>> countTheNumOfKFreeSubsets(nums = [10,5,9,11], k = 20)
    >>> 16
    Explanation: All subsets are valid. Since the total count of subsets is 24 = 16, so the answer is 16.
    """


Prompt:
from typing import List
def findColumnWidth(grid: List[List[int]]) -> List[int]:
    """
    You are given a 0-indexed m x n integer matrix grid. The width of a column is the maximum length of its integers.

    For example, if grid = [[-10], [3], [12]], the width of the only column is 3 since -10 is of length 3.

    Return an integer array ans of size n where ans[i] is the width of the ith column.
    The length of an integer x with len digits is equal to len if x is non-negative, and len + 1 otherwise.

    Example 1:

    >>> findColumnWidth(grid = [[1],[22],[333]])
    >>> [3]
    Explanation: In the 0th column, 333 is of length 3.

    Example 2:

    >>> findColumnWidth(grid = [[-15,1,3],[15,7,12],[5,6,-2]])
    >>> [3,1,2]
    Explanation:
    In the 0th column, only -15 is of length 3.
    In the 1st column, all integers are of length 1.
    In the 2nd column, both 12 and -2 are of length 2.
    """


Prompt:
from typing import List
def findPrefixScore(nums: List[int]) -> List[int]:
    """
    We define the conversion array conver of an array arr as follows:

    conver[i] = arr[i] + max(arr[0..i]) where max(arr[0..i]) is the maximum value of arr[j] over 0 <= j <= i.

    We also define the score of an array arr as the sum of the values of the conversion array of arr.
    Given a 0-indexed integer array nums of length n, return an array ans of length n where ans[i] is the score of the prefix nums[0..i].

    Example 1:

    >>> findPrefixScore(nums = [2,3,7,5,10])
    >>> [4,10,24,36,56]
    Explanation:
    For the prefix [2], the conversion array is [4] hence the score is 4
    For the prefix [2, 3], the conversion array is [4, 6] hence the score is 10
    For the prefix [2, 3, 7], the conversion array is [4, 6, 14] hence the score is 24
    For the prefix [2, 3, 7, 5], the conversion array is [4, 6, 14, 12] hence the score is 36
    For the prefix [2, 3, 7, 5, 10], the conversion array is [4, 6, 14, 12, 20] hence the score is 56

    Example 2:

    >>> findPrefixScore(nums = [1,1,2,4,8,16])
    >>> [2,4,8,16,32,64]
    Explanation:
    For the prefix [1], the conversion array is [2] hence the score is 2
    For the prefix [1, 1], the conversion array is [2, 2] hence the score is 4
    For the prefix [1, 1, 2], the conversion array is [2, 2, 4] hence the score is 8
    For the prefix [1, 1, 2, 4], the conversion array is [2, 2, 4, 8] hence the score is 16
    For the prefix [1, 1, 2, 4, 8], the conversion array is [2, 2, 4, 8, 16] hence the score is 32
    For the prefix [1, 1, 2, 4, 8, 16], the conversion array is [2, 2, 4, 8, 16, 32] hence the score is 64
    """


Prompt:
from typing import Optional
class TreeNode:
    def __init__(val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
def replaceValueInTree(root: Optional[TreeNode]) -> Optional[TreeNode]:
"""
Given the root of a binary tree, replace the value of each node in the tree with the sum of all its cousins' values.
Two nodes of a binary tree are cousins if they have the same depth with different parents.
Return the root of the modified tree.
Note that the depth of a node is the number of edges in the path from the root node to it.

Example 1:

>>> replaceValueInTree(root = [5,4,9,1,10,null,7])
>>> [0,0,0,7,7,null,11]
Explanation: The diagram above shows the initial binary tree and the binary tree after changing the value of each node.
- Node with value 5 does not have any cousins so its sum is 0.
- Node with value 4 does not have any cousins so its sum is 0.
- Node with value 9 does not have any cousins so its sum is 0.
- Node with value 1 has a cousin with value 7 so its sum is 7.
- Node with value 10 has a cousin with value 7 so its sum is 7.
- Node with value 7 has cousins with values 1 and 10 so its sum is 11.

Example 2:

>>> replaceValueInTree(root = [3,1,2])
>>> [0,0,0]
Explanation: The diagram above shows the initial binary tree and the binary tree after changing the value of each node.
- Node with value 3 does not have any cousins so its sum is 0.
- Node with value 1 does not have any cousins so its sum is 0.
- Node with value 2 does not have any cousins so its sum is 0.
"""


Prompt:
from typing import List
def rowAndMaximumOnes(mat: List[List[int]]) -> List[int]:
    """
    Given a m x n binary matrix mat, find the 0-indexed position of the row that contains the maximum count of ones, and the number of ones in that row.
    In case there are multiple rows that have the maximum count of ones, the row with the smallest row number should be selected.
    Return an array containing the index of the row, and the number of ones in it.

    Example 1:

    >>> rowAndMaximumOnes(mat = [[0,1],[1,0]])
    >>> [0,1]
    Explanation: Both rows have the same number of 1's. So we return the index of the smaller row, 0, and the maximum count of ones (1). So, the answer is [0,1].

    Example 2:

    >>> rowAndMaximumOnes(mat = [[0,0,0],[0,1,1]])
    >>> [1,2]
    Explanation: The row indexed 1 has the maximum count of ones (2). So we return its index, 1, and the count. So, the answer is [1,2].

    Example 3:

    >>> rowAndMaximumOnes(mat = [[0,0],[1,1],[0,0]])
    >>> [1,2]
    Explanation: The row indexed 1 has the maximum count of ones (2). So the answer is [1,2].
    """


Prompt:
from typing import List
def maxDivScore(nums: List[int], divisors: List[int]) -> int:
    """
    You are given two integer arrays nums and divisors.
    The divisibility score of divisors[i] is the number of indices j such that nums[j] is divisible by divisors[i].
    Return the integer divisors[i] with the maximum divisibility score. If multiple integers have the maximum score, return the smallest one.

    Example 1:

    >>> maxDivScore(nums = [2,9,15,50], divisors = [5,3,7,2])
    >>> 2
    Explanation:
    The divisibility score of divisors[0] is 2 since nums[2] and nums[3] are divisible by 5.
    The divisibility score of divisors[1] is 2 since nums[1] and nums[2] are divisible by 3.
    The divisibility score of divisors[2] is 0 since none of the numbers in nums is divisible by 7.
    The divisibility score of divisors[3] is 2 since nums[0] and nums[3] are divisible by 2.
    As divisors[0], divisors[1], and divisors[3] have the same divisibility score, we return the smaller one which is divisors[3].

    Example 2:

    >>> maxDivScore(nums = [4,7,9,3,9], divisors = [5,2,3])
    >>> 3
    Explanation:
    The divisibility score of divisors[0] is 0 since none of numbers in nums is divisible by 5.
    The divisibility score of divisors[1] is 1 since only nums[0] is divisible by 2.
    The divisibility score of divisors[2] is 3 since nums[2], nums[3] and nums[4] are divisible by 3.

    Example 3:

    >>> maxDivScore(nums = [20,14,21,10], divisors = [10,16,20])
    >>> 10
    Explanation:
    The divisibility score of divisors[0] is 2 since nums[0] and nums[3] are divisible by 10.
    The divisibility score of divisors[1] is 0 since none of the numbers in nums is divisible by 16.
    The divisibility score of divisors[2] is 1 since nums[0] is divisible by 20.
    """


Prompt:
def addMinimum(word: str) -> int:
    """
    Given a string word to which you can insert letters "a", "b" or "c" anywhere and any number of times, return the minimum number of letters that must be inserted so that word becomes valid.
    A string is called valid if it can be formed by concatenating the string "abc" several times.

    Example 1:

    >>> addMinimum(word = "b")
    >>> 2
    Explanation: Insert the letter "a" right before "b", and the letter "c" right next to "b" to obtain the valid string "abc".

    Example 2:

    >>> addMinimum(word = "aaa")
    >>> 6
    Explanation: Insert letters "b" and "c" next to each "a" to obtain the valid string "abcabcabc".

    Example 3:

    >>> addMinimum(word = "abc")
    >>> 0
    Explanation: word is already valid. No modifications are needed.
    """


Prompt:
from typing import List
def minimumTotalPrice(n: int, edges: List[List[int]], price: List[int], trips: List[List[int]]) -> int:
    """
    There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.
    Each node has an associated price. You are given an integer array price, where price[i] is the price of the ith node.
    The price sum of a given path is the sum of the prices of all nodes lying on that path.
    Additionally, you are given a 2D integer array trips, where trips[i] = [starti, endi] indicates that you start the ith trip from the node starti and travel to the node endi by any path you like.
    Before performing your first trip, you can choose some non-adjacent nodes and halve the prices.
    Return the minimum total price sum to perform all the given trips.

    Example 1:

    >>> minimumTotalPrice(n = 4, edges = [[0,1],[1,2],[1,3]], price = [2,2,10,6], trips = [[0,3],[2,1],[2,3]])
    >>> 23
    Explanation: The diagram above denotes the tree after rooting it at node 2. The first part shows the initial tree and the second part shows the tree after choosing nodes 0, 2, and 3, and making their price half.
    For the 1st trip, we choose path [0,1,3]. The price sum of that path is 1 + 2 + 3 = 6.
    For the 2nd trip, we choose path [2,1]. The price sum of that path is 2 + 5 = 7.
    For the 3rd trip, we choose path [2,1,3]. The price sum of that path is 5 + 2 + 3 = 10.
    The total price sum of all trips is 6 + 7 + 10 = 23.
    It can be proven, that 23 is the minimum answer that we can achieve.

    Example 2:

    >>> minimumTotalPrice(n = 2, edges = [[0,1]], price = [2,2], trips = [[0,0]])
    >>> 1
    Explanation: The diagram above denotes the tree after rooting it at node 0. The first part shows the initial tree and the second part shows the tree after choosing node 0, and making its price half.
    For the 1st trip, we choose path [0]. The price sum of that path is 1.
    The total price sum of all trips is 1. It can be proven, that 1 is the minimum answer that we can achieve.
    """


Prompt:
from typing import List
def colorRed(n: int) -> List[List[int]]:
    """
    You are given an integer n. Consider an equilateral triangle of side length n, broken up into n2 unit equilateral triangles. The triangle has n 1-indexed rows where the ith row has 2i - 1 unit equilateral triangles.
    The triangles in the ith row are also 1-indexed with coordinates from (i, 1) to (i, 2i - 1). The following image shows a triangle of side length 4 with the indexing of its triangle.

    Two triangles are neighbors if they share a side. For example:

    Triangles (1,1) and (2,2) are neighbors
    Triangles (3,2) and (3,3) are neighbors.
    Triangles (2,2) and (3,3) are not neighbors because they do not share any side.

    Initially, all the unit triangles are white. You want to choose k triangles and color them red. We will then run the following algorithm:

    Choose a white triangle that has at least two red neighbors.

    If there is no such triangle, stop the algorithm.

    Color that triangle red.
    Go to step 1.

    Choose the minimum k possible and set k triangles red before running this algorithm such that after the algorithm stops, all unit triangles are colored red.
    Return a 2D list of the coordinates of the triangles that you will color red initially. The answer has to be of the smallest size possible. If there are multiple valid solutions, return any.

    Example 1:

    >>> colorRed(n = 3)
    >>> [[1,1],[2,1],[2,3],[3,1],[3,5]]
    Explanation: Initially, we choose the shown 5 triangles to be red. Then, we run the algorithm:
    - Choose (2,2) that has three red neighbors and color it red.
    - Choose (3,2) that has two red neighbors and color it red.
    - Choose (3,4) that has three red neighbors and color it red.
    - Choose (3,3) that has three red neighbors and color it red.
    It can be shown that choosing any 4 triangles and running the algorithm will not make all triangles red.

    Example 2:

    >>> colorRed(n = 2)
    >>> [[1,1],[2,1],[2,3]]
    Explanation: Initially, we choose the shown 3 triangles to be red. Then, we run the algorithm:
    - Choose (2,2) that has three red neighbors and color it red.
    It can be shown that choosing any 2 triangles and running the algorithm will not make all triangles red.
    """


Prompt:
def findDelayedArrivalTime(arrivalTime: int, delayedTime: int) -> int:
    """
    You are given a positive integer arrivalTime denoting the arrival time of a train in hours, and another positive integer delayedTime denoting the amount of delay in hours.
    Return the time when the train will arrive at the station.
    Note that the time in this problem is in 24-hours format.

    Example 1:

    >>> findDelayedArrivalTime(arrivalTime = 15, delayedTime = 5)
    >>> 20
    Explanation: Arrival time of the train was 15:00 hours. It is delayed by 5 hours. Now it will reach at 15+5 = 20 (20:00 hours).

    Example 2:

    >>> findDelayedArrivalTime(arrivalTime = 13, delayedTime = 11)
    >>> 0
    Explanation: Arrival time of the train was 13:00 hours. It is delayed by 11 hours. Now it will reach at 13+11=24 (Which is denoted by 00:00 in 24 hours format so return 0).
    """


Prompt:
def sumOfMultiples(n: int) -> int:
    """
    Given a positive integer n, find the sum of all integers in the range [1, n] inclusive that are divisible by 3, 5, or 7.
    Return an integer denoting the sum of all numbers in the given range satisfying the constraint.

    Example 1:

    >>> sumOfMultiples(n = 7)
    >>> 21
    Explanation: Numbers in the range [1, 7] that are divisible by 3, 5, or 7 are 3, 5, 6, 7. The sum of these numbers is 21.

    Example 2:

    >>> sumOfMultiples(n = 10)
    >>> 40
    Explanation: Numbers in the range [1, 10] that are divisible by 3, 5, or 7 are 3, 5, 6, 7, 9, 10. The sum of these numbers is 40.

    Example 3:

    >>> sumOfMultiples(n = 9)
    >>> 30
    Explanation: Numbers in the range [1, 9] that are divisible by 3, 5, or 7 are 3, 5, 6, 7, 9. The sum of these numbers is 30.
    """


Prompt:
from typing import List
def getSubarrayBeauty(nums: List[int], k: int, x: int) -> List[int]:
    """
    Given an integer array nums containing n integers, find the beauty of each subarray of size k.
    The beauty of a subarray is the xth smallest integer in the subarray if it is negative, or 0 if there are fewer than x negative integers.
    Return an integer array containing n - k + 1 integers, which denote the beauty of the subarrays in order from the first index in the array.

    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> getSubarrayBeauty(nums = [1,-1,-3,-2,3], k = 3, x = 2)
    >>> [-1,-2,-2]
    Explanation: There are 3 subarrays with size k = 3.
    The first subarray is [1, -1, -3] and the 2nd smallest negative integer is -1.
    The second subarray is [-1, -3, -2] and the 2nd smallest negative integer is -2.
    The third subarray is [-3, -2, 3] and the 2nd smallest negative integer is -2.
    Example 2:

    >>> getSubarrayBeauty(nums = [-1,-2,-3,-4,-5], k = 2, x = 2)
    >>> [-1,-2,-3,-4]
    Explanation: There are 4 subarrays with size k = 2.
    For [-1, -2], the 2nd smallest negative integer is -1.
    For [-2, -3], the 2nd smallest negative integer is -2.
    For [-3, -4], the 2nd smallest negative integer is -3.
    For [-4, -5], the 2nd smallest negative integer is -4.
    Example 3:

    >>> getSubarrayBeauty(nums = [-3,1,2,-3,0,-3], k = 2, x = 1)
    >>> [-3,0,-3,-3,-3]
    Explanation: There are 5 subarrays with size k = 2.
    For [-3, 1], the 1st smallest negative integer is -3.
    For [1, 2], there is no negative integer so the beauty is 0.
    For [2, -3], the 1st smallest negative integer is -3.
    For [-3, 0], the 1st smallest negative integer is -3.
    For [0, -3], the 1st smallest negative integer is -3.
    """


Prompt:
from typing import List
def minOperations(nums: List[int]) -> int:
    """
    You are given a 0-indexed array nums consisiting of positive integers. You can do the following operation on the array any number of times:

    Select an index i such that 0 <= i < n - 1 and replace either of nums[i] or nums[i+1] with their gcd value.

    Return the minimum number of operations to make all elements of nums equal to 1. If it is impossible, return -1.
    The gcd of two integers is the greatest common divisor of the two integers.

    Example 1:

    >>> minOperations(nums = [2,6,3,4])
    >>> 4
    Explanation: We can do the following operations:
    - Choose index i = 2 and replace nums[2] with gcd(3,4) = 1. Now we have nums = [2,6,1,4].
    - Choose index i = 1 and replace nums[1] with gcd(6,1) = 1. Now we have nums = [2,1,1,4].
    - Choose index i = 0 and replace nums[0] with gcd(2,1) = 1. Now we have nums = [1,1,1,4].
    - Choose index i = 2 and replace nums[3] with gcd(1,4) = 1. Now we have nums = [1,1,1,1].

    Example 2:

    >>> minOperations(nums = [2,10,6,14])
    >>> -1
    Explanation: It can be shown that it is impossible to make all the elements equal to 1.
    """


Prompt:
from typing import List
def findMaximalUncoveredRanges(n: int, ranges: List[List[int]]) -> List[List[int]]:
    """
    You are given an integer n which is the length of a 0-indexed array nums, and a 0-indexed 2D-array ranges, which is a list of sub-ranges of nums (sub-ranges may overlap).
    Each row ranges[i] has exactly 2 cells:

    ranges[i][0], which shows the start of the ith range (inclusive)
    ranges[i][1], which shows the end of the ith range (inclusive)

    These ranges cover some cells of nums and leave some cells uncovered. Your task is to find all of the uncovered ranges with maximal length.
    Return a 2D-array answer of the uncovered ranges, sorted by the starting point in ascending order.
    By all of the uncovered ranges with maximal length, we mean satisfying two conditions:

    Each uncovered cell should belong to exactly one sub-range
    There should not exist two ranges (l1, r1) and (l2, r2) such that r1 + 1 = l2

    Example 1:

    >>> findMaximalUncoveredRanges(n = 10, ranges = [[3,5],[7,8]])
    >>> [[0,2],[6,6],[9,9]]
    Explanation: The ranges (3, 5) and (7, 8) are covered, so if we simplify the array nums to a binary array where 0 shows an uncovered cell and 1 shows a covered cell, the array becomes [0,0,0,1,1,1,0,1,1,0] in which we can observe that the ranges (0, 2), (6, 6) and (9, 9) aren't covered.

    Example 2:

    >>> findMaximalUncoveredRanges(n = 3, ranges = [[0,2]])
    >>> []
    Explanation: In this example, the whole of the array nums is covered and there are no uncovered cells so the output is an empty array.

    Example 3:

    >>> findMaximalUncoveredRanges(n = 7, ranges = [[2,4],[0,3]])
    >>> [[5,6]]
    Explanation: The ranges (0, 3) and (2, 4) are covered, so if we simplify the array nums to a binary array where 0 shows an uncovered cell and 1 shows a covered cell, the array becomes [1,1,1,1,1,0,0] in which we can observe that the range (5, 6) is uncovered.
    """


Prompt:
from typing import List
def maximizeSum(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums and an integer k. Your task is to perform the following operation exactly k times in order to maximize your score:

    Select an element m from nums.
    Remove the selected element m from the array.
    Add a new element with a value of m + 1 to the array.
    Increase your score by m.

    Return the maximum score you can achieve after performing the operation exactly k times.

    Example 1:

    >>> maximizeSum(nums = [1,2,3,4,5], k = 3)
    >>> 18
    Explanation: We need to choose exactly 3 elements from nums to maximize the sum.
    For the first iteration, we choose 5. Then sum is 5 and nums = [1,2,3,4,6]
    For the second iteration, we choose 6. Then sum is 5 + 6 and nums = [1,2,3,4,7]
    For the third iteration, we choose 7. Then sum is 5 + 6 + 7 = 18 and nums = [1,2,3,4,8]
    So, we will return 18.
    It can be proven, that 18 is the maximum answer that we can achieve.

    Example 2:

    >>> maximizeSum(nums = [5,5,5], k = 2)
    >>> 11
    Explanation: We need to choose exactly 2 elements from nums to maximize the sum.
    For the first iteration, we choose 5. Then sum is 5 and nums = [5,5,6]
    For the second iteration, we choose 6. Then sum is 5 + 6 = 11 and nums = [5,5,7]
    So, we will return 11.
    It can be proven, that 11 is the maximum answer that we can achieve.
    """


Prompt:
from typing import List
def findThePrefixCommonArray(A: List[int], B: List[int]) -> List[int]:
    """
    You are given two 0-indexed integer permutations A and B of length n.
    A prefix common array of A and B is an array C such that C[i] is equal to the count of numbers that are present at or before the index i in both A and B.
    Return the prefix common array of A and B.
    A sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.

    Example 1:

    >>> findThePrefixCommonArray(A = [1,3,2,4], B = [3,1,2,4])
    >>> [0,2,3,4]
    Explanation: At i = 0: no number is common, so C[0] = 0.
    At i = 1: 1 and 3 are common in A and B, so C[1] = 2.
    At i = 2: 1, 2, and 3 are common in A and B, so C[2] = 3.
    At i = 3: 1, 2, 3, and 4 are common in A and B, so C[3] = 4.

    Example 2:

    >>> findThePrefixCommonArray(A = [2,3,1], B = [3,1,2])
    >>> [0,1,3]
    Explanation: At i = 0: no number is common, so C[0] = 0.
    At i = 1: only 3 is common in A and B, so C[1] = 1.
    At i = 2: 1, 2, and 3 are common in A and B, so C[2] = 3.
    """


Prompt:
from typing import List
def findMaxFish(grid: List[List[int]]) -> int:
    """
    You are given a 0-indexed 2D matrix grid of size m x n, where (r, c) represents:

    A land cell if grid[r][c] = 0, or
    A water cell containing grid[r][c] fish, if grid[r][c] > 0.

    A fisher can start at any water cell (r, c) and can do the following operations any number of times:

    Catch all the fish at cell (r, c), or
    Move to any adjacent water cell.

    Return the maximum number of fish the fisher can catch if he chooses his starting cell optimally, or 0 if no water cell exists.
    An adjacent cell of the cell (r, c), is one of the cells (r, c + 1), (r, c - 1), (r + 1, c) or (r - 1, c) if it exists.

    Example 1:

    >>> findMaxFish(grid = [[0,2,1,0],[4,0,0,3],[1,0,0,4],[0,3,2,0]])
    >>> 7
    Explanation: The fisher can start at cell (1,3) and collect 3 fish, then move to cell (2,3) and collect 4 fish.

    Example 2:

    >>> findMaxFish(grid = [[1,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]])
    >>> 1
    Explanation: The fisher can start at cells (0,0) or (3,3) and collect a single fish.
    """


Prompt:
from typing import List
def countOperationsToEmptyArray(nums: List[int]) -> int:
    """
    You are given an integer array nums containing distinct numbers, and you can perform the following operations until the array is empty:

    If the first element has the smallest value, remove it
    Otherwise, put the first element at the end of the array.

    Return an integer denoting the number of operations it takes to make nums empty.

    Example 1:

    >>> countOperationsToEmptyArray(nums = [3,4,-1])
    >>> 5

    Operation
    Array

    1
    [4, -1, 3]

    2
    [-1, 3, 4]

    3
    [3, 4]

    4
    [4]

    5
    []

    Example 2:

    >>> countOperationsToEmptyArray(nums = [1,2,4,3])
    >>> 5

    Operation
    Array

    1
    [2, 4, 3]

    2
    [4, 3]

    3
    [3, 4]

    4
    [4]

    5
    []

    Example 3:

    >>> countOperationsToEmptyArray(nums = [1,2,3])
    >>> 3

    Operation
    Array

    1
    [2, 3]

    2
    [3]

    3
    []
    """


Prompt:
from typing import List
def isWinner(player1: List[int], player2: List[int]) -> int:
    """
    You are given two 0-indexed integer arrays player1 and player2, representing the number of pins that player 1 and player 2 hit in a bowling game, respectively.
    The bowling game consists of n turns, and the number of pins in each turn is exactly 10.
    Assume a player hits xi pins in the ith turn. The value of the ith turn for the player is:

    2xi if the player hits 10 pins in either (i - 1)th or (i - 2)th turn.
    Otherwise, it is xi.

    The score of the player is the sum of the values of their n turns.
    Return

    1 if the score of player 1 is more than the score of player 2,
    2 if the score of player 2 is more than the score of player 1, and
    0 in case of a draw.

    Example 1:

    >>> isWinner(player1 = [5,10,3,2], player2 = [6,5,7,3])
    >>> 1
    Explanation:
    The score of player 1 is 5 + 10 + 2*3 + 2*2 = 25.
    The score of player 2 is 6 + 5 + 7 + 3 = 21.

    Example 2:

    >>> isWinner(player1 = [3,5,7,6], player2 = [8,10,10,2])
    >>> 2
    Explanation:
    The score of player 1 is 3 + 5 + 7 + 6 = 21.
    The score of player 2 is 8 + 10 + 2*10 + 2*2 = 42.

    Example 3:

    >>> isWinner(player1 = [2,3], player2 = [4,1])
    >>> 0
    Explanation:
    The score of player1 is 2 + 3 = 5.
    The score of player2 is 4 + 1 = 5.

    Example 4:

    >>> isWinner(player1 = [1,1,1,10,10,10,10], player2 = [10,10,10,10,1,1,1])
    >>> 2
    Explanation:
    The score of player1 is 1 + 1 + 1 + 10 + 2*10 + 2*10 + 2*10 = 73.
    The score of player2 is 10 + 2*10 + 2*10 + 2*10 + 2*1 + 2*1 + 1 = 75.
    """


Prompt:
from typing import List
def firstCompleteIndex(arr: List[int], mat: List[List[int]]) -> int:
    """
    You are given a 0-indexed integer array arr, and an m x n integer matrix mat. arr and mat both contain all the integers in the range [1, m * n].
    Go through each index i in arr starting from index 0 and paint the cell in mat containing the integer arr[i].
    Return the smallest index i at which either a row or a column will be completely painted in mat.

    Example 1:

    >>> firstCompleteIndex(arr = [1,3,4,2], mat = [[1,4],[2,3]])
    >>> 2
    Explanation: The moves are shown in order, and both the first row and second column of the matrix become fully painted at arr[2].

    Example 2:

    >>> firstCompleteIndex(arr = [2,8,7,4,1,3,5,6,9], mat = [[3,2,5],[1,4,6],[8,7,9]])
    >>> 3
    Explanation: The second column becomes fully painted at arr[3].
    """


Prompt:
from typing import List
def minimumCost(start: List[int], target: List[int], specialRoads: List[List[int]]) -> int:
    """
    You are given an array start where start = [startX, startY] represents your initial position (startX, startY) in a 2D space. You are also given the array target where target = [targetX, targetY] represents your target position (targetX, targetY).
    The cost of going from a position (x1, y1) to any other position in the space (x2, y2) is |x2 - x1| + |y2 - y1|.
    There are also some special roads. You are given a 2D array specialRoads where specialRoads[i] = [x1i, y1i, x2i, y2i, costi] indicates that the ith special road goes in one direction from (x1i, y1i) to (x2i, y2i) with a cost equal to costi. You can use each special road any number of times.
    Return the minimum cost required to go from (startX, startY) to (targetX, targetY).

    Example 1:

    >>> minimumCost(start = [1,1], target = [4,5], specialRoads = [[1,2,3,3,2],[3,4,4,5,1]])
    >>> 5
    Explanation:

    (1,1) to (1,2) with a cost of |1 - 1| + |2 - 1| = 1.
    (1,2) to (3,3). Use specialRoads[0] with the cost 2.
    (3,3) to (3,4) with a cost of |3 - 3| + |4 - 3| = 1.
    (3,4) to (4,5). Use specialRoads[1] with the cost 1.

    So the total cost is 1 + 2 + 1 + 1 = 5.

    Example 2:

    >>> minimumCost(start = [3,2], target = [5,7], specialRoads = [[5,7,3,2,1],[3,2,3,4,4],[3,3,5,5,5],[3,4,5,6,6]])
    >>> 7
    Explanation:
    It is optimal not to use any special edges and go directly from the starting to the ending position with a cost |5 - 3| + |7 - 2| = 7.
    Note that the specialRoads[0] is directed from (5,7) to (3,2).

    Example 3:

    >>> minimumCost(start = [1,1], target = [10,4], specialRoads = [[4,2,1,1,3],[1,2,7,4,4],[10,3,6,1,2],[6,1,1,2,3]])
    >>> 8
    Explanation:

    (1,1) to (1,2) with a cost of |1 - 1| + |2 - 1| = 1.
    (1,2) to (7,4). Use specialRoads[1] with the cost 4.
    (7,4) to (10,4) with a cost of |10 - 7| + |4 - 4| = 3.
    """


Prompt:
def smallestBeautifulString(s: str, k: int) -> str:
    """
    A string is beautiful if:

    It consists of the first k letters of the English lowercase alphabet.
    It does not contain any substring of length 2 or more which is a palindrome.

    You are given a beautiful string s of length n and a positive integer k.
    Return the lexicographically smallest string of length n, which is larger than s and is beautiful. If there is no such string, return an empty string.
    A string a is lexicographically larger than a string b (of the same length) if in the first position where a and b differ, a has a character strictly larger than the corresponding character in b.

    For example, "abcd" is lexicographically larger than "abcc" because the first position they differ is at the fourth character, and d is greater than c.

    Example 1:

    >>> smallestBeautifulString(s = "abcz", k = 26)
    >>> "abda"
    Explanation: The string "abda" is beautiful and lexicographically larger than the string "abcz".
    It can be proven that there is no string that is lexicographically larger than the string "abcz", beautiful, and lexicographically smaller than the string "abda".

    Example 2:

    >>> smallestBeautifulString(s = "dc", k = 4)
    >>> ""
    Explanation: It can be proven that there is no string that is lexicographically larger than the string "dc" and is beautiful.
    """


Prompt:
from typing import List
def tourOfKnight(m: int, n: int, r: int, c: int) -> List[List[int]]:
    """
    Given two positive integers m and n which are the height and width of a 0-indexed 2D-array board, a pair of positive integers (r, c) which is the starting position of the knight on the board.
    Your task is to find an order of movements for the knight, in a manner that every cell of the board gets visited exactly once (the starting cell is considered visited and you shouldn't visit it again).
    Return the array board in which the cells' values show the order of visiting the cell starting from 0 (the initial place of the knight).
    Note that a knight can move from cell (r1, c1) to cell (r2, c2) if 0 <= r2 <= m - 1 and 0 <= c2 <= n - 1 and min(abs(r1 - r2), abs(c1 - c2)) = 1 and max(abs(r1 - r2), abs(c1 - c2)) = 2.

    Example 1:

    >>> tourOfKnight(m = 1, n = 1, r = 0, c = 0)
    >>> [[0]]
    Explanation: There is only 1 cell and the knight is initially on it so there is only a 0 inside the 1x1 grid.

    Example 2:

    >>> tourOfKnight(m = 3, n = 4, r = 0, c = 0)
    >>> [[0,3,6,9],[11,8,1,4],[2,5,10,7]]
    Explanation: By the following order of movements we can visit the entire board.
    (0,0)->(1,2)->(2,0)->(0,1)->(1,3)->(2,1)->(0,2)->(2,3)->(1,1)->(0,3)->(2,2)->(1,0)
    """


Prompt:
from typing import List
def distinctDifferenceArray(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed array nums of length n.
    The distinct difference array of nums is an array diff of length n such that diff[i] is equal to the number of distinct elements in the suffix nums[i + 1, ..., n - 1] subtracted from the number of distinct elements in the prefix nums[0, ..., i].
    Return the distinct difference array of nums.
    Note that nums[i, ..., j] denotes the subarray of nums starting at index i and ending at index j inclusive. Particularly, if i > j then nums[i, ..., j] denotes an empty subarray.

    Example 1:

    >>> distinctDifferenceArray(nums = [1,2,3,4,5])
    >>> [-3,-1,1,3,5]
    Explanation: For index i = 0, there is 1 element in the prefix and 4 distinct elements in the suffix. Thus, diff[0] = 1 - 4 = -3.
    For index i = 1, there are 2 distinct elements in the prefix and 3 distinct elements in the suffix. Thus, diff[1] = 2 - 3 = -1.
    For index i = 2, there are 3 distinct elements in the prefix and 2 distinct elements in the suffix. Thus, diff[2] = 3 - 2 = 1.
    For index i = 3, there are 4 distinct elements in the prefix and 1 distinct element in the suffix. Thus, diff[3] = 4 - 1 = 3.
    For index i = 4, there are 5 distinct elements in the prefix and no elements in the suffix. Thus, diff[4] = 5 - 0 = 5.

    Example 2:

    >>> distinctDifferenceArray(nums = [3,2,3,4,2])
    >>> [-2,-1,0,2,3]
    Explanation: For index i = 0, there is 1 element in the prefix and 3 distinct elements in the suffix. Thus, diff[0] = 1 - 3 = -2.
    For index i = 1, there are 2 distinct elements in the prefix and 3 distinct elements in the suffix. Thus, diff[1] = 2 - 3 = -1.
    For index i = 2, there are 2 distinct elements in the prefix and 2 distinct elements in the suffix. Thus, diff[2] = 2 - 2 = 0.
    For index i = 3, there are 3 distinct elements in the prefix and 1 distinct element in the suffix. Thus, diff[3] = 3 - 1 = 2.
    For index i = 4, there are 3 distinct elements in the prefix and no elements in the suffix. Thus, diff[4] = 3 - 0 = 3.
    """


Prompt:
from typing import List, Set
def colorTheArray(n: int, queries: List[List[int]]) -> List[int]:
    """
    You are given an integer n representing an array colors of length n where all elements are set to 0's meaning uncolored. You are also given a 2D integer array queries where queries[i] = [indexi, colori]. For the ith query:

    Set colors[indexi] to colori.
    Count adjacent pairs in colors set to the same color (regardless of colori).

    Return an array answer of the same length as queries where answer[i] is the answer to the ith query.

    Example 1:

    >>> colorTheArray(n = 4, queries = [[0,2],[1,2],[3,1],[1,1],[2,1]])
    >>> [0,1,1,0,2]
    Explanation:

    Initially array colors = [0,0,0,0], where 0 denotes uncolored elements of the array.
    After the 1st query colors = [2,0,0,0]. The count of adjacent pairs with the same color is 0.
    After the 2nd query colors = [2,2,0,0]. The count of adjacent pairs with the same color is 1.
    After the 3rd query colors = [2,2,0,1]. The count of adjacent pairs with the same color is 1.
    After the 4th query colors = [2,1,0,1]. The count of adjacent pairs with the same color is 0.
    After the 5th query colors = [2,1,1,1]. The count of adjacent pairs with the same color is 2.

    Example 2:

    >>> colorTheArray(n = 1, queries = [[0,100000]])
    >>> [0]
    Explanation:
    After the 1st query colors = [100000]. The count of adjacent pairs with the same color is 0.
    """


Prompt:
from typing import List
def minIncrements(n: int, cost: List[int]) -> int:
    """
    You are given an integer n representing the number of nodes in a perfect binary tree consisting of nodes numbered from 1 to n. The root of the tree is node 1 and each node i in the tree has two children where the left child is the node 2 * i and the right child is 2 * i + 1.
    Each node in the tree also has a cost represented by a given 0-indexed integer array cost of size n where cost[i] is the cost of node i + 1. You are allowed to increment the cost of any node by 1 any number of times.
    Return the minimum number of increments you need to make the cost of paths from the root to each leaf node equal.
    Note:

    A perfect binary tree is a tree where each node, except the leaf nodes, has exactly 2 children.
    The cost of a path is the sum of costs of nodes in the path.

    Example 1:

    >>> minIncrements(n = 7, cost = [1,5,2,2,3,3,1])
    >>> 6
    Explanation: We can do the following increments:
    - Increase the cost of node 4 one time.
    - Increase the cost of node 3 three times.
    - Increase the cost of node 7 two times.
    Each path from the root to a leaf will have a total cost of 9.
    The total increments we did is 1 + 3 + 2 = 6.
    It can be shown that this is the minimum answer we can achieve.

    Example 2:

    >>> minIncrements(n = 3, cost = [5,3,3])
    >>> 0
    Explanation: The two paths already have equal total costs, so no increments are needed.
    """


Prompt:
from typing import List
def countSeniors(details: List[str]) -> int:
    """
    You are given a 0-indexed array of strings details. Each element of details provides information about a given passenger compressed into a string of length 15. The system is such that:

    The first ten characters consist of the phone number of passengers.
    The next character denotes the gender of the person.
    The following two characters are used to indicate the age of the person.
    The last two characters determine the seat allotted to that person.

    Return the number of passengers who are strictly more than 60 years old.

    Example 1:

    >>> countSeniors(details = ["7868190130M7522","5303914400F9211","9273338290F4010"])
    >>> 2
    Explanation: The passengers at indices 0, 1, and 2 have ages 75, 92, and 40. Thus, there are 2 people who are over 60 years old.

    Example 2:

    >>> countSeniors(details = ["1313579440F2036","2921522980M5644"])
    >>> 0
    Explanation: None of the passengers are older than 60.
    """


Prompt:
from typing import List
def matrixSum(nums: List[List[int]]) -> int:
    """
    You are given a 0-indexed 2D integer array nums. Initially, your score is 0. Perform the following operations until the matrix becomes empty:

    From each row in the matrix, select the largest number and remove it. In the case of a tie, it does not matter which number is chosen.
    Identify the highest number amongst all those removed in step 1. Add that number to your score.

    Return the final score.

    Example 1:

    >>> matrixSum(nums = [[7,2,1],[6,4,2],[6,5,3],[3,2,1]])
    >>> 15
    Explanation: In the first operation, we remove 7, 6, 6, and 3. We then add 7 to our score. Next, we remove 2, 4, 5, and 2. We add 5 to our score. Lastly, we remove 1, 2, 3, and 1. We add 3 to our score. Thus, our final score is 7 + 5 + 3 = 15.

    Example 2:

    >>> matrixSum(nums = [[1]])
    >>> 1
    Explanation: We remove 1 and add it to the answer. We return 1.
    """


Prompt:
from typing import List
def maximumOr(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums of length n and an integer k. In an operation, you can choose an element and multiply it by 2.
    Return the maximum possible value of nums[0] | nums[1] | ... | nums[n - 1] that can be obtained after applying the operation on nums at most k times.
    Note that a | b denotes the bitwise or between two integers a and b.

    Example 1:

    >>> maximumOr(nums = [12,9], k = 1)
    >>> 30
    Explanation: If we apply the operation to index 1, our new array nums will be equal to [12,18]. Thus, we return the bitwise or of 12 and 18, which is 30.

    Example 2:

    >>> maximumOr(nums = [8,1,2], k = 2)
    >>> 35
    Explanation: If we apply the operation twice on index 0, we yield a new array of [32,1,2]. Thus, we return 32|1|2 = 35.
    """


Prompt:
from typing import List
def sumOfPower(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums representing the strength of some heroes. The power of a group of heroes is defined as follows:

    Let i0, i1, ... ,ik be the indices of the heroes in a group. Then, the power of this group is max(nums[i0], nums[i1], ... ,nums[ik])2 * min(nums[i0], nums[i1], ... ,nums[ik]).

    Return the sum of the power of all non-empty groups of heroes possible. Since the sum could be very large, return it modulo 109 + 7.

    Example 1:

    >>> sumOfPower(nums = [2,1,4])
    >>> 141
    Explanation:
    1st group: [2] has power = 22 * 2 = 8.
    2nd group: [1] has power = 12 * 1 = 1.
    3rd group: [4] has power = 42 * 4 = 64.
    4th group: [2,1] has power = 22 * 1 = 4.
    5th group: [2,4] has power = 42 * 2 = 32.
    6th group: [1,4] has power = 42 * 1 = 16.
    7th group: [2,1,4] has power = 42 * 1 = 16.
    The sum of powers of all groups is 8 + 1 + 64 + 4 + 32 + 16 + 16 = 141.

    Example 2:

    >>> sumOfPower(nums = [1,1,1])
    >>> 7
    Explanation: A total of 7 groups are possible, and the power of each group will be 1. Therefore, the sum of the powers of all groups is 7.
    """


Prompt:
from typing import List
def circularGameLosers(n: int, k: int) -> List[int]:
    """
    There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend brings you to the (i+1)th friend for 1 <= i < n, and moving clockwise from the nth friend brings you to the 1st friend.
    The rules of the game are as follows:
    1st friend receives the ball.

    After that, 1st friend passes it to the friend who is k steps away from them in the clockwise direction.
    After that, the friend who receives the ball should pass it to the friend who is 2 * k steps away from them in the clockwise direction.
    After that, the friend who receives the ball should pass it to the friend who is 3 * k steps away from them in the clockwise direction, and so on and so forth.

    In other words, on the ith turn, the friend holding the ball should pass it to the friend who is i * k steps away from them in the clockwise direction.
    The game is finished when some friend receives the ball for the second time.
    The losers of the game are friends who did not receive the ball in the entire game.
    Given the number of friends, n, and an integer k, return the array answer, which contains the losers of the game in the ascending order.

    Example 1:

    >>> circularGameLosers(n = 5, k = 2)
    >>> [4,5]
    Explanation: The game goes as follows:
    1) Start at 1st friend and pass the ball to the friend who is 2 steps away from them - 3rd friend.
    2) 3rd friend passes the ball to the friend who is 4 steps away from them - 2nd friend.
    3) 2nd friend passes the ball to the friend who is 6 steps away from them  - 3rd friend.
    4) The game ends as 3rd friend receives the ball for the second time.

    Example 2:

    >>> circularGameLosers(n = 4, k = 4)
    >>> [2,3,4]
    Explanation: The game goes as follows:
    1) Start at the 1st friend and pass the ball to the friend who is 4 steps away from them - 1st friend.
    2) The game ends as 1st friend receives the ball for the second time.
    """


Prompt:
from typing import List
def doesValidArrayExist(derived: List[int]) -> bool:
    """
    A 0-indexed array derived with length n is derived by computing the bitwise XOR (⊕) of adjacent values in a binary array original of length n.
    Specifically, for each index i in the range [0, n - 1]:

    If i = n - 1, then derived[i] = original[i] ⊕ original[0].
    Otherwise, derived[i] = original[i] ⊕ original[i + 1].

    Given an array derived, your task is to determine whether there exists a valid binary array original that could have formed derived.
    Return true if such an array exists or false otherwise.

    A binary array is an array containing only 0's and 1's

    Example 1:

    >>> doesValidArrayExist(derived = [1,1,0])
    >>> true
    Explanation: A valid original array that gives derived is [0,1,0].
    derived[0] = original[0] ⊕ original[1] = 0 ⊕ 1 = 1
    derived[1] = original[1] ⊕ original[2] = 1 ⊕ 0 = 1
    derived[2] = original[2] ⊕ original[0] = 0 ⊕ 0 = 0

    Example 2:

    >>> doesValidArrayExist(derived = [1,1])
    >>> true
    Explanation: A valid original array that gives derived is [0,1].
    derived[0] = original[0] ⊕ original[1] = 1
    derived[1] = original[1] ⊕ original[0] = 1

    Example 3:

    >>> doesValidArrayExist(derived = [1,0])
    >>> false
    Explanation: There is no valid original array that gives derived.
    """


Prompt:
from typing import List
def maxMoves(grid: List[List[int]]) -> int:
    """
    You are given a 0-indexed m x n matrix grid consisting of positive integers.
    You can start at any cell in the first column of the matrix, and traverse the grid in the following way:

    From a cell (row, col), you can move to any of the cells: (row - 1, col + 1), (row, col + 1) and (row + 1, col + 1) such that the value of the cell you move to, should be strictly bigger than the value of the current cell.

    Return the maximum number of moves that you can perform.

    Example 1:

    >>> maxMoves(grid = [[2,4,3,5],[5,4,9,3],[3,4,2,11],[10,9,13,15]])
    >>> 3
    Explanation: We can start at the cell (0, 0) and make the following moves:
    - (0, 0) -> (0, 1).
    - (0, 1) -> (1, 2).
    - (1, 2) -> (2, 3).
    It can be shown that it is the maximum number of moves that can be made.
    Example 2:

    >>> maxMoves(grid = [[3,2,4],[2,1,9],[1,1,7]])
    >>> 0
    Explanation: Starting from any cell in the first column we cannot perform any moves.
    """


Prompt:
from typing import List
def countCompleteComponents(n: int, edges: List[List[int]]) -> int:
    """
    You are given an integer n. There is an undirected graph with n vertices, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting vertices ai and bi.
    Return the number of complete connected components of the graph.
    A connected component is a subgraph of a graph in which there exists a path between any two vertices, and no vertex of the subgraph shares an edge with a vertex outside of the subgraph.
    A connected component is said to be complete if there exists an edge between every pair of its vertices.

    Example 1:

    >>> countCompleteComponents(n = 6, edges = [[0,1],[0,2],[1,2],[3,4]])
    >>> 3
    Explanation: From the picture above, one can see that all of the components of this graph are complete.

    Example 2:

    >>> countCompleteComponents(n = 6, edges = [[0,1],[0,2],[1,2],[3,4],[3,5]])
    >>> 1
    Explanation: The component containing vertices 0, 1, and 2 is complete since there is an edge between every pair of two vertices. On the other hand, the component containing vertices 3, 4, and 5 is not complete since there is no edge between vertices 4 and 5. Thus, the number of complete components in this graph is 1.
    """


Prompt:
def minLength(s: str) -> int:
    """
    You are given a string s consisting only of uppercase English letters.
    You can apply some operations to this string where, in one operation, you can remove any occurrence of one of the substrings "AB" or "CD" from s.
    Return the minimum possible length of the resulting string that you can obtain.
    Note that the string concatenates after removing the substring and could produce new "AB" or "CD" substrings.

    Example 1:

    >>> minLength(s = "ABFCACDB")
    >>> 2
    Explanation: We can do the following operations:
    - Remove the substring "ABFCACDB", so s = "FCACDB".
    - Remove the substring "FCACDB", so s = "FCAB".
    - Remove the substring "FCAB", so s = "FC".
    So the resulting length of the string is 2.
    It can be shown that it is the minimum length that we can obtain.
    Example 2:

    >>> minLength(s = "ACBBD")
    >>> 5
    Explanation: We cannot do any operations on the string so the length remains the same.
    """


Prompt:
def makeSmallestPalindrome(s: str) -> str:
    """
    You are given a string s consisting of lowercase English letters, and you are allowed to perform operations on it. In one operation, you can replace a character in s with another lowercase English letter.
    Your task is to make s a palindrome with the minimum number of operations possible. If there are multiple palindromes that can be made using the minimum number of operations, make the lexicographically smallest one.
    A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
    Return the resulting palindrome string.

    Example 1:

    >>> makeSmallestPalindrome(s = "egcfe")
    >>> "efcfe"
    Explanation: The minimum number of operations to make "egcfe" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is "efcfe", by changing 'g'.

    Example 2:

    >>> makeSmallestPalindrome(s = "abcd")
    >>> "abba"
    Explanation: The minimum number of operations to make "abcd" a palindrome is 2, and the lexicographically smallest palindrome string we can get by modifying two characters is "abba".

    Example 3:

    >>> makeSmallestPalindrome(s = "seven")
    >>> "neven"
    Explanation: The minimum number of operations to make "seven" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is "neven".
    """


Prompt:
def punishmentNumber(n: int) -> int:
    """
    Given a positive integer n, return the punishment number of n.
    The punishment number of n is defined as the sum of the squares of all integers i such that:

    1 <= i <= n
    The decimal representation of i * i can be partitioned into contiguous substrings such that the sum of the integer values of these substrings equals i.

    Example 1:

    >>> punishmentNumber(n = 10)
    >>> 182
    Explanation: There are exactly 3 integers i in the range [1, 10] that satisfy the conditions in the statement:
    - 1 since 1 * 1 = 1
    - 9 since 9 * 9 = 81 and 81 can be partitioned into 8 and 1 with a sum equal to 8 + 1 == 9.
    - 10 since 10 * 10 = 100 and 100 can be partitioned into 10 and 0 with a sum equal to 10 + 0 == 10.
    Hence, the punishment number of 10 is 1 + 81 + 100 = 182

    Example 2:

    >>> punishmentNumber(n = 37)
    >>> 1478
    Explanation: There are exactly 4 integers i in the range [1, 37] that satisfy the conditions in the statement:
    - 1 since 1 * 1 = 1.
    - 9 since 9 * 9 = 81 and 81 can be partitioned into 8 + 1.
    - 10 since 10 * 10 = 100 and 100 can be partitioned into 10 + 0.
    - 36 since 36 * 36 = 1296 and 1296 can be partitioned into 1 + 29 + 6.
    Hence, the punishment number of 37 is 1 + 81 + 100 + 1296 = 1478
    """


Prompt:
from typing import List
def modifiedGraphEdges(n: int, edges: List[List[int]], source: int, destination: int, target: int) -> List[List[int]]:
    """
    You are given an undirected weighted connected graph containing n nodes labeled from 0 to n - 1, and an integer array edges where edges[i] = [ai, bi, wi] indicates that there is an edge between nodes ai and bi with weight wi.
    Some edges have a weight of -1 (wi = -1), while others have a positive weight (wi > 0).
    Your task is to modify all edges with a weight of -1 by assigning them positive integer values in the range [1, 2 * 109] so that the shortest distance between the nodes source and destination becomes equal to an integer target. If there are multiple modifications that make the shortest distance between source and destination equal to target, any of them will be considered correct.
    Return an array containing all edges (even unmodified ones) in any order if it is possible to make the shortest distance from source to destination equal to target, or an empty array if it's impossible.
    Note: You are not allowed to modify the weights of edges with initial positive weights.

    Example 1:

    >>> modifiedGraphEdges(n = 5, edges = [[4,1,-1],[2,0,-1],[0,3,-1],[4,3,-1]], source = 0, destination = 1, target = 5)
    >>> [[4,1,1],[2,0,1],[0,3,3],[4,3,1]]
    Explanation: The graph above shows a possible modification to the edges, making the distance from 0 to 1 equal to 5.

    Example 2:

    >>> modifiedGraphEdges(n = 3, edges = [[0,1,-1],[0,2,5]], source = 0, destination = 2, target = 6)
    >>> []
    Explanation: The graph above contains the initial edges. It is not possible to make the distance from 0 to 2 equal to 6 by modifying the edge with weight -1. So, an empty array is returned.

    Example 3:

    >>> modifiedGraphEdges(n = 4, edges = [[1,0,4],[1,2,3],[2,3,5],[0,3,-1]], source = 0, destination = 2, target = 6)
    >>> [[1,0,4],[1,2,3],[2,3,5],[0,3,1]]
    Explanation: The graph above shows a modified graph having the shortest distance from 0 to 2 as 6.
    """


Prompt:
from typing import List
def minOperations(nums: List[int], x: int, y: int) -> int:
    """
    You are given a 0-indexed integer array nums and two integers x and y. In one operation, you must choose an index i such that 0 <= i < nums.length and perform the following:

    Decrement nums[i] by x.
    Decrement values by y at all indices except the ith one.

    Return the minimum number of operations to make all the integers in nums less than or equal to zero.

    Example 1:

    >>> minOperations(nums = [3,4,1,7,6], x = 4, y = 2)
    >>> 3
    Explanation: You will need three operations. One of the optimal sequence of operations is:
    Operation 1: Choose i = 3. Then, nums = [1,2,-1,3,4].
    Operation 2: Choose i = 3. Then, nums = [-1,0,-3,-1,2].
    Operation 3: Choose i = 4. Then, nums = [-3,-2,-5,-3,-2].
    Now, all the numbers in nums are non-positive. Therefore, we return 3.

    Example 2:

    >>> minOperations(nums = [1,2,1], x = 2, y = 1)
    >>> 1
    Explanation: We can perform the operation once on i = 1. Then, nums becomes [0,0,0]. All the positive numbers are removed, and therefore, we return 1.
    """


Prompt:
from typing import List
def buyChoco(prices: List[int], money: int) -> int:
    """
    You are given an integer array prices representing the prices of various chocolates in a store. You are also given a single integer money, which represents your initial amount of money.
    You must buy exactly two chocolates in such a way that you still have some non-negative leftover money. You would like to minimize the sum of the prices of the two chocolates you buy.
    Return the amount of money you will have leftover after buying the two chocolates. If there is no way for you to buy two chocolates without ending up in debt, return money. Note that the leftover must be non-negative.

    Example 1:

    >>> buyChoco(prices = [1,2,2], money = 3)
    >>> 0
    Explanation: Purchase the chocolates priced at 1 and 2 units respectively. You will have 3 - 3 = 0 units of money afterwards. Thus, we return 0.

    Example 2:

    >>> buyChoco(prices = [3,2,3], money = 3)
    >>> 3
    Explanation: You cannot buy 2 chocolates without going in debt, so we return 3.
    """


Prompt:
from typing import List
def minExtraChar(s: str, dictionary: List[str]) -> int:
    """
    You are given a 0-indexed string s and a dictionary of words dictionary. You have to break s into one or more non-overlapping substrings such that each substring is present in dictionary. There may be some extra characters in s which are not present in any of the substrings.
    Return the minimum number of extra characters left over if you break up s optimally.

    Example 1:

    >>> minExtraChar(s = "leetscode", dictionary = ["leet","code","leetcode"])
    >>> 1
    Explanation: We can break s in two substrings: "leet" from index 0 to 3 and "code" from index 5 to 8. There is only 1 unused character (at index 4), so we return 1.

    Example 2:

    >>> minExtraChar(s = "sayhelloworld", dictionary = ["hello","world"])
    >>> 3
    Explanation: We can break s in two substrings: "hello" from index 3 to 7 and "world" from index 8 to 12. The characters at indices 0, 1, 2 are not used in any substring and thus are considered as extra characters. Hence, we return 3.
    """


Prompt:
from typing import List
def maxStrength(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums representing the score of students in an exam. The teacher would like to form one non-empty group of students with maximal strength, where the strength of a group of students of indices i0, i1, i2, ... , ik is defined as nums[i0] * nums[i1] * nums[i2] * ... * nums[ik].
    Return the maximum strength of a group the teacher can create.

    Example 1:

    >>> maxStrength(nums = [3,-1,-5,2,5,-9])
    >>> 1350
    Explanation: One way to form a group of maximal strength is to group the students at indices [0,2,3,4,5]. Their strength is 3 * (-5) * 2 * 5 * (-9) = 1350, which we can show is optimal.

    Example 2:

    >>> maxStrength(nums = [-4,-5,-4])
    >>> 20
    Explanation: Group the students at indices [0, 1] . Then, we’ll have a resulting strength of 20. We cannot achieve greater strength.
    """


Prompt:
from typing import List
def canTraverseAllPairs(nums: List[int]) -> bool:
    """
    You are given a 0-indexed integer array nums, and you are allowed to traverse between its indices. You can traverse between index i and index j, i != j, if and only if gcd(nums[i], nums[j]) > 1, where gcd is the greatest common divisor.
    Your task is to determine if for every pair of indices i and j in nums, where i < j, there exists a sequence of traversals that can take us from i to j.
    Return true if it is possible to traverse between all such pairs of indices, or false otherwise.

    Example 1:

    >>> canTraverseAllPairs(nums = [2,3,6])
    >>> true
    Explanation: In this example, there are 3 possible pairs of indices: (0, 1), (0, 2), and (1, 2).
    To go from index 0 to index 1, we can use the sequence of traversals 0 -> 2 -> 1, where we move from index 0 to index 2 because gcd(nums[0], nums[2]) = gcd(2, 6) = 2 > 1, and then move from index 2 to index 1 because gcd(nums[2], nums[1]) = gcd(6, 3) = 3 > 1.
    To go from index 0 to index 2, we can just go directly because gcd(nums[0], nums[2]) = gcd(2, 6) = 2 > 1. Likewise, to go from index 1 to index 2, we can just go directly because gcd(nums[1], nums[2]) = gcd(3, 6) = 3 > 1.

    Example 2:

    >>> canTraverseAllPairs(nums = [3,9,5])
    >>> false
    Explanation: No sequence of traversals can take us from index 0 to index 2 in this example. So, we return false.

    Example 3:

    >>> canTraverseAllPairs(nums = [4,3,12,8])
    >>> true
    Explanation: There are 6 possible pairs of indices to traverse between: (0, 1), (0, 2), (0, 3), (1, 2), (1, 3), and (2, 3). A valid sequence of traversals exists for each pair, so we return true.
    """


Prompt:
def removeTrailingZeros(num: str) -> str:
    """
    Given a positive integer num represented as a string, return the integer num without trailing zeros as a string.

    Example 1:

    >>> removeTrailingZeros(num = "51230100")
    >>> "512301"
    Explanation: Integer "51230100" has 2 trailing zeros, we remove them and return integer "512301".

    Example 2:

    >>> removeTrailingZeros(num = "123")
    >>> "123"
    Explanation: Integer "123" has no trailing zeros, we return integer "123".
    """


Prompt:
from typing import List
def differenceOfDistinctValues(grid: List[List[int]]) -> List[List[int]]:
    """
    Given a 2D grid of size m x n, you should find the matrix answer of size m x n.
    The cell answer[r][c] is calculated by looking at the diagonal values of the cell grid[r][c]:

    Let leftAbove[r][c] be the number of distinct values on the diagonal to the left and above the cell grid[r][c] not including the cell grid[r][c] itself.
    Let rightBelow[r][c] be the number of distinct values on the diagonal to the right and below the cell grid[r][c], not including the cell grid[r][c] itself.
    Then answer[r][c] = |leftAbove[r][c] - rightBelow[r][c]|.

    A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until the end of the matrix is reached.

    For example, in the below diagram the diagonal is highlighted using the cell with indices (2, 3) colored gray:

    Red-colored cells are left and above the cell.
    Blue-colored cells are right and below the cell.

    Return the matrix answer.

    Example 1:

    >>> differenceOfDistinctValues(grid = [[1,2,3],[3,1,5],[3,2,1]])
    >>> Output: [[1,1,0],[1,0,1],[0,1,1]]
    Explanation:
    To calculate the answer cells:

    answer
    left-above elements
    leftAbove
    right-below elements
    rightBelow
    |leftAbove - rightBelow|

    [0][0]
    []
    0
    [grid[1][1], grid[2][2]]
    |{1, 1}| = 1
    1

    [0][1]
    []
    0
    [grid[1][2]]
    |{5}| = 1
    1

    [0][2]
    []
    0
    []
    0
    0

    [1][0]
    []
    0
    [grid[2][1]]
    |{2}| = 1
    1

    [1][1]
    [grid[0][0]]
    |{1}| = 1
    [grid[2][2]]
    |{1}| = 1
    0

    [1][2]
    [grid[0][1]]
    |{2}| = 1
    []
    0
    1

    [2][0]
    []
    0
    []
    0
    0

    [2][1]
    [grid[1][0]]
    |{3}| = 1
    []
    0
    1

    [2][2]
    [grid[0][0], grid[1][1]]
    |{1, 1}| = 1
    []
    0
    1

    Example 2:

    >>> differenceOfDistinctValues(grid = [[1]])
    >>> Output: [[0]]
    """


Prompt:
def minimumCost(s: str) -> int:
    """
    You are given a 0-indexed binary string s of length n on which you can apply two types of operations:

    Choose an index i and invert all characters from index 0 to index i (both inclusive), with a cost of i + 1
    Choose an index i and invert all characters from index i to index n - 1 (both inclusive), with a cost of n - i

    Return the minimum cost to make all characters of the string equal.
    Invert a character means if its value is '0' it becomes '1' and vice-versa.

    Example 1:

    >>> minimumCost(s = "0011")
    >>> 2
    Explanation: Apply the second operation with i = 2 to obtain s = "0000" for a cost of 2. It can be shown that 2 is the minimum cost to make all characters equal.

    Example 2:

    >>> minimumCost(s = "010101")
    >>> 9
    Explanation: Apply the first operation with i = 2 to obtain s = "101101" for a cost of 3.
    Apply the first operation with i = 1 to obtain s = "011101" for a cost of 2.
    Apply the first operation with i = 0 to obtain s = "111101" for a cost of 1.
    Apply the second operation with i = 4 to obtain s = "111110" for a cost of 2.
    Apply the second operation with i = 5 to obtain s = "111111" for a cost of 1.
    The total cost to make all characters equal is 9. It can be shown that 9 is the minimum cost to make all characters equal.
    """


Prompt:
from typing import List
def maxIncreasingCells(mat: List[List[int]]) -> int:
    """
    Given a 1-indexed m x n integer matrix mat, you can select any cell in the matrix as your starting cell.
    From the starting cell, you can move to any other cell in the same row or column, but only if the value of the destination cell is strictly greater than the value of the current cell. You can repeat this process as many times as possible, moving from cell to cell until you can no longer make any moves.
    Your task is to find the maximum number of cells that you can visit in the matrix by starting from some cell.
    Return an integer denoting the maximum number of cells that can be visited.

    Example 1:

    >>> maxIncreasingCells(mat = [[3,1],[3,4]])
    >>> 2
    Explanation: The image shows how we can visit 2 cells starting from row 1, column 2. It can be shown that we cannot visit more than 2 cells no matter where we start from, so the answer is 2.

    Example 2:

    >>> maxIncreasingCells(mat = [[1,1],[1,1]])
    >>> 1
    Explanation: Since the cells must be strictly increasing, we can only visit one cell in this example.

    Example 3:

    >>> maxIncreasingCells(mat = [[3,1,6],[-9,5,7]])
    >>> 4
    Explanation: The image above shows how we can visit 4 cells starting from row 2, column 1. It can be shown that we cannot visit more than 4 cells no matter where we start from, so the answer is 4.
    """


Prompt:
from typing import List
def shortestPathWithHops(n: int, edges: List[List[int]], s: int, d: int, k: int) -> int:
    """
    You are given a positive integer n which is the number of nodes of a 0-indexed undirected weighted connected graph and a 0-indexed 2D array edges where edges[i] = [ui, vi, wi] indicates that there is an edge between nodes ui and vi with weight wi.
    You are also given two nodes s and d, and a positive integer k, your task is to find the shortest path from s to d, but you can hop over at most k edges. In other words, make the weight of at most k edges 0 and then find the shortest path from s to d.
    Return the length of the shortest path from s to d with the given condition.

    Example 1:

    >>> shortestPathWithHops(n = 4, edges = [[0,1,4],[0,2,2],[2,3,6]], s = 1, d = 3, k = 2)
    >>> 2
    Explanation: In this example there is only one path from node 1 (the green node) to node 3 (the red node), which is (1->0->2->3) and the length of it is 4 + 2 + 6 = 12. Now we can make weight of two edges 0, we make weight of the blue edges 0, then we have 0 + 2 + 0 = 2. It can be shown that 2 is the minimum length of a path we can achieve with the given condition.

    Example 2:

    >>> shortestPathWithHops(n = 7, edges = [[3,1,9],[3,2,4],[4,0,9],[0,5,6],[3,6,2],[6,0,4],[1,2,4]], s = 4, d = 1, k = 2)
    >>> 6
    Explanation: In this example there are 2 paths from node 4 (the green node) to node 1 (the red node), which are (4->0->6->3->2->1) and (4->0->6->3->1). The first one has the length 9 + 4 + 2 + 4 + 4 = 23, and the second one has the length 9 + 4 + 2 + 9 = 24. Now if we make weight of the blue edges 0, we get the shortest path with the length 0 + 4 + 2 + 0 = 6. It can be shown that 6 is the minimum length of a path we can achieve with the given condition.

    Example 3:

    >>> shortestPathWithHops(n = 5, edges = [[0,4,2],[0,1,3],[0,2,1],[2,1,4],[1,3,4],[3,4,7]], s = 2, d = 3, k = 1)
    >>> 3
    Explanation: In this example there are 4 paths from node 2 (the green node) to node 3 (the red node), which are (2->1->3), (2->0->1->3), (2->1->0->4->3) and (2->0->4->3). The first two have the length 4 + 4 = 1 + 3 + 4 = 8, the third one has the length 4 + 3 + 2 + 7 = 16 and the last one has the length 1 + 2 + 7 = 10. Now if we make weight of the blue edge 0, we get the shortest path with the length 1 + 2 + 0 = 3. It can be shown that 3 is the minimum length of a path we can achieve with the given condition.
    """


Prompt:
def minimizedStringLength(s: str) -> int:
    """
    Given a string s, you have two types of operation:

    Choose an index i in the string, and let c be the character in position i. Delete the closest occurrence of c to the left of i (if exists).
    Choose an index i in the string, and let c be the character in position i. Delete the closest occurrence of c to the right of i (if exists).

    Your task is to minimize the length of s by performing the above operations zero or more times.
    Return an integer denoting the length of the minimized string.

    Example 1:

    >>> minimizedStringLength(s = "aaabc")
    >>> 3
    Explanation:

    Operation 2: we choose i = 1 so c is 'a', then we remove s[2] as it is closest 'a' character to the right of s[1].
    s becomes "aabc" after this.
    Operation 1: we choose i = 1 so c is 'a', then we remove s[0] as it is closest 'a' character to the left of s[1].
    s becomes "abc" after this.

    Example 2:

    >>> minimizedStringLength(s = "cbbd")
    >>> 3
    Explanation:

    Operation 1: we choose i = 2 so c is 'b', then we remove s[1] as it is closest 'b' character to the left of s[1].
    s becomes "cbd" after this.

    Example 3:

    >>> minimizedStringLength(s = "baadccab")
    >>> 4
    Explanation:

    Operation 1: we choose i = 6 so c is 'a', then we remove s[2] as it is closest 'a' character to the left of s[6].
    s becomes "badccab" after this.
    Operation 2: we choose i = 0 so c is 'b', then we remove s[6] as it is closest 'b' character to the right of s[0].
    s becomes "badcca" fter this.
    Operation 2: we choose i = 3 so c is 'c', then we remove s[4] as it is closest 'c' character to the right of s[3].
    s becomes "badca" after this.
    Operation 1: we choose i = 4 so c is 'a', then we remove s[1] as it is closest 'a' character to the left of s[4].
    s becomes "bdca" after this.
    """


Prompt:
from typing import List
def semiOrderedPermutation(nums: List[int]) -> int:
    """
    You are given a 0-indexed permutation of n integers nums.
    A permutation is called semi-ordered if the first number equals 1 and the last number equals n. You can perform the below operation as many times as you want until you make nums a semi-ordered permutation:

    Pick two adjacent elements in nums, then swap them.

    Return the minimum number of operations to make nums a semi-ordered permutation.
    A permutation is a sequence of integers from 1 to n of length n containing each number exactly once.

    Example 1:

    >>> semiOrderedPermutation(nums = [2,1,4,3])
    >>> 2
    Explanation: We can make the permutation semi-ordered using these sequence of operations:
    1 - swap i = 0 and j = 1. The permutation becomes [1,2,4,3].
    2 - swap i = 2 and j = 3. The permutation becomes [1,2,3,4].
    It can be proved that there is no sequence of less than two operations that make nums a semi-ordered permutation.

    Example 2:

    >>> semiOrderedPermutation(nums = [2,4,1,3])
    >>> 3
    Explanation: We can make the permutation semi-ordered using these sequence of operations:
    1 - swap i = 1 and j = 2. The permutation becomes [2,1,4,3].
    2 - swap i = 0 and j = 1. The permutation becomes [1,2,4,3].
    3 - swap i = 2 and j = 3. The permutation becomes [1,2,3,4].
    It can be proved that there is no sequence of less than three operations that make nums a semi-ordered permutation.

    Example 3:

    >>> semiOrderedPermutation(nums = [1,3,4,2,5])
    >>> 0
    Explanation: The permutation is already a semi-ordered permutation.
    """