Prompt:
def shortestDistanceAfterQueries(n: int, queries: List[List[int]]) -> List[int]:
    """
    You are given an integer n and a 2D integer array queries.
    There are n cities numbered from 0 to n - 1. Initially, there is a unidirectional road from city i to city i + 1 for all 0 <= i < n - 1.
    queries[i] = [ui, vi] represents the addition of a new unidirectional road from city ui to city vi. After each query, you need to find the length of the shortest path from city 0 to city n - 1.
    Return an array answer where for each i in the range [0, queries.length - 1], answer[i] is the length of the shortest path from city 0 to city n - 1 after processing the first i + 1 queries.

    Example 1:

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

    After the addition of the road from 2 to 4, the length of the shortest path from 0 to 4 is 3.

    After the addition of the road from 0 to 2, the length of the shortest path from 0 to 4 is 2.

    After the addition of the road from 0 to 4, the length of the shortest path from 0 to 4 is 1.

    Example 2:

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

    After the addition of the road from 0 to 3, the length of the shortest path from 0 to 3 is 1.

    After the addition of the road from 0 to 2, the length of the shortest path remains 1.
    """


Prompt:
def shortestDistanceAfterQueries(n: int, queries: List[List[int]]) -> List[int]:
    """
    You are given an integer n and a 2D integer array queries.
    There are n cities numbered from 0 to n - 1. Initially, there is a unidirectional road from city i to city i + 1 for all 0 <= i < n - 1.
    queries[i] = [ui, vi] represents the addition of a new unidirectional road from city ui to city vi. After each query, you need to find the length of the shortest path from city 0 to city n - 1.
    There are no two queries such that queries[i][0] < queries[j][0] < queries[i][1] < queries[j][1].
    Return an array answer where for each i in the range [0, queries.length - 1], answer[i] is the length of the shortest path from city 0 to city n - 1 after processing the first i + 1 queries.

    Example 1:

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

    After the addition of the road from 2 to 4, the length of the shortest path from 0 to 4 is 3.

    After the addition of the road from 0 to 2, the length of the shortest path from 0 to 4 is 2.

    After the addition of the road from 0 to 4, the length of the shortest path from 0 to 4 is 1.

    Example 2:

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

    After the addition of the road from 0 to 3, the length of the shortest path from 0 to 3 is 1.

    After the addition of the road from 0 to 2, the length of the shortest path remains 1.
    """


Prompt:
def subsequenceCount(nums: List[int]) -> int:
    """
    Given an array nums, return the number of subsequences with an odd sum of elements.
    Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> subsequenceCount(nums = [1,1,1])
    >>> 4
    Explanation:
    The odd-sum subsequences are: [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1].

    Example 2:

    >>> subsequenceCount(nums = [1,2,2])
    >>> 4
    Explanation:
    The odd-sum subsequences are: [1, 2, 2], [1, 2, 2], [1, 2, 2], [1, 2, 2].
    """


Prompt:
def finalPositionOfSnake(n: int, commands: List[str]) -> int:
    """
    There is a snake in an n x n matrix grid and can move in four possible directions. Each cell in the grid is identified by the position: grid[i][j] = (i * n) + j.
    The snake starts at cell 0 and follows a sequence of commands.
    You are given an integer n representing the size of the grid and an array of strings commands where each command[i] is either "UP", "RIGHT", "DOWN", and "LEFT". It's guaranteed that the snake will remain within the grid boundaries throughout its movement.
    Return the position of the final cell where the snake ends up after executing commands.

    Example 1:

    >>> finalPositionOfSnake(n = 2, commands = ["RIGHT","DOWN"])
    >>> 3
    Explanation:

    0
    1

    2
    3

    0
    1

    2
    3

    0
    1

    2
    3

    Example 2:

    >>> finalPositionOfSnake(n = 3, commands = ["DOWN","RIGHT","UP"])
    >>> 1
    Explanation:

    0
    1
    2

    3
    4
    5

    6
    7
    8

    0
    1
    2

    3
    4
    5

    6
    7
    8

    0
    1
    2

    3
    4
    5

    6
    7
    8

    0
    1
    2

    3
    4
    5

    6
    7
    8
    """


Prompt:
def countGoodNodes(edges: List[List[int]]) -> int:
    """
    There is an undirected tree with n nodes labeled from 0 to n - 1, and rooted at node 0. You are given 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.
    A node is good if all the subtrees rooted at its children have the same size.
    Return the number of good nodes in the given tree.
    A subtree of treeName is a tree consisting of a node in treeName and all of its descendants.

    Example 1:

    >>> countGoodNodes(edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]])
    >>> 7
    Explanation:

    All of the nodes of the given tree are good.

    Example 2:

    >>> countGoodNodes(edges = [[0,1],[1,2],[2,3],[3,4],[0,5],[1,6],[2,7],[3,8]])
    >>> 6
    Explanation:

    There are 6 good nodes in the given tree. They are colored in the image above.
    Example 3:

    >>> countGoodNodes(edges = [[0,1],[1,2],[1,3],[1,4],[0,5],[5,6],[6,7],[7,8],[0,9],[9,10],[9,12],[10,11]])
    >>> 12
    Explanation:

    All nodes except node 9 are good.
    """


Prompt:
def countOfPairs(nums: List[int]) -> int:
    """
    You are given an array of positive integers nums of length n.
    We call a pair of non-negative integer arrays (arr1, arr2) monotonic if:

    The lengths of both arrays are n.
    arr1 is monotonically non-decreasing, in other words, arr1[0] <= arr1[1] <= ... <= arr1[n - 1].
    arr2 is monotonically non-increasing, in other words, arr2[0] >= arr2[1] >= ... >= arr2[n - 1].
    arr1[i] + arr2[i] == nums[i] for all 0 <= i <= n - 1.

    Return the count of monotonic pairs.
    Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> countOfPairs(nums = [2,3,2])
    >>> 4
    Explanation:
    The good pairs are:

    ([0, 1, 1], [2, 2, 1])
    ([0, 1, 2], [2, 2, 0])
    ([0, 2, 2], [2, 1, 0])
    ([1, 2, 2], [1, 1, 0])

    Example 2:

    >>> countOfPairs(nums = [5,5,5,5])
    >>> 126
    """


Prompt:
def countOfPairs(nums: List[int]) -> int:
    """
    You are given an array of positive integers nums of length n.
    We call a pair of non-negative integer arrays (arr1, arr2) monotonic if:

    The lengths of both arrays are n.
    arr1 is monotonically non-decreasing, in other words, arr1[0] <= arr1[1] <= ... <= arr1[n - 1].
    arr2 is monotonically non-increasing, in other words, arr2[0] >= arr2[1] >= ... >= arr2[n - 1].
    arr1[i] + arr2[i] == nums[i] for all 0 <= i <= n - 1.

    Return the count of monotonic pairs.
    Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> countOfPairs(nums = [2,3,2])
    >>> 4
    Explanation:
    The good pairs are:

    ([0, 1, 1], [2, 2, 1])
    ([0, 1, 2], [2, 2, 0])
    ([0, 2, 2], [2, 1, 0])
    ([1, 2, 2], [1, 1, 0])

    Example 2:

    >>> countOfPairs(nums = [5,5,5,5])
    >>> 126
    """


Prompt:
def minimumCost(target: str, words: List[str], costs: List[int]) -> int:
    """
    You are given a string target, an array of strings words, and an integer array costs, both arrays of the same length.
    Imagine an empty string s.
    You can perform the following operation any number of times (including zero):

    Choose an index i in the range [0, words.length - 1].
    Append words[i] to s.
    The cost of operation is costs[i].

    Return the minimum cost to make s equal to target. If it's not possible, return -1.

    Example 1:

    >>> minimumCost(target = "abcdef", words = ["abdef","abc","d","def","ef"], costs = [100,1,1,10,5])
    >>> 7
    Explanation:
    The minimum cost can be achieved by performing the following operations:

    Select index 1 and append "abc" to s at a cost of 1, resulting in s = "abc".
    Select index 2 and append "d" to s at a cost of 1, resulting in s = "abcd".
    Select index 4 and append "ef" to s at a cost of 5, resulting in s = "abcdef".

    Example 2:

    >>> minimumCost(target = "aaaa", words = ["z","zz","zzz"], costs = [1,10,100])
    >>> -1
    Explanation:
    It is impossible to make s equal to target, so we return -1.
    """


Prompt:
def resultsArray(nums: List[int], k: int) -> List[int]:
    """
    You are given an array of integers nums of length n and a positive integer k.
    The power of an array is defined as:

    Its maximum element if all of its elements are consecutive and sorted in ascending order.
    -1 otherwise.

    You need to find the power of all subarrays of nums of size k.
    Return an integer array results of size n - k + 1, where results[i] is the power of nums[i..(i + k - 1)].

    Example 1:

    >>> resultsArray(nums = [1,2,3,4,3,2,5], k = 3)
    >>> [3,4,-1,-1,-1]
    Explanation:
    There are 5 subarrays of nums of size 3:

    [1, 2, 3] with the maximum element 3.
    [2, 3, 4] with the maximum element 4.
    [3, 4, 3] whose elements are not consecutive.
    [4, 3, 2] whose elements are not sorted.
    [3, 2, 5] whose elements are not consecutive.

    Example 2:

    >>> resultsArray(nums = [2,2,2,2,2], k = 4)
    >>> [-1,-1]

    Example 3:

    >>> resultsArray(nums = [3,2,3,2,3,2], k = 2)
    >>> [-1,3,-1,3,-1]
    """


Prompt:
def resultsArray(nums: List[int], k: int) -> List[int]:
    """
    You are given an array of integers nums of length n and a positive integer k.
    The power of an array is defined as:

    Its maximum element if all of its elements are consecutive and sorted in ascending order.
    -1 otherwise.

    You need to find the power of all subarrays of nums of size k.
    Return an integer array results of size n - k + 1, where results[i] is the power of nums[i..(i + k - 1)].

    Example 1:

    >>> resultsArray(nums = [1,2,3,4,3,2,5], k = 3)
    >>> [3,4,-1,-1,-1]
    Explanation:
    There are 5 subarrays of nums of size 3:

    [1, 2, 3] with the maximum element 3.
    [2, 3, 4] with the maximum element 4.
    [3, 4, 3] whose elements are not consecutive.
    [4, 3, 2] whose elements are not sorted.
    [3, 2, 5] whose elements are not consecutive.

    Example 2:

    >>> resultsArray(nums = [2,2,2,2,2], k = 4)
    >>> [-1,-1]

    Example 3:

    >>> resultsArray(nums = [3,2,3,2,3,2], k = 2)
    >>> [-1,3,-1,3,-1]
    """


Prompt:
def maximumValueSum(board: List[List[int]]) -> int:
    """
    You are given a m x n 2D array board representing a chessboard, where board[i][j] represents the value of the cell (i, j).
    Rooks in the same row or column attack each other. You need to place three rooks on the chessboard such that the rooks do not attack each other.
    Return the maximum sum of the cell values on which the rooks are placed.

    Example 1:

    >>> maximumValueSum(board = [[-3,1,1,1],[-3,1,-3,1],[-3,2,1,1]])
    >>> 4
    Explanation:

    We can place the rooks in the cells (0, 2), (1, 3), and (2, 1) for a sum of 1 + 1 + 2 = 4.

    Example 2:

    >>> maximumValueSum(board = [[1,2,3],[4,5,6],[7,8,9]])
    >>> 15
    Explanation:
    We can place the rooks in the cells (0, 0), (1, 1), and (2, 2) for a sum of 1 + 5 + 9 = 15.

    Example 3:

    >>> maximumValueSum(board = [[1,1,1],[1,1,1],[1,1,1]])
    >>> 3
    Explanation:
    We can place the rooks in the cells (0, 2), (1, 1), and (2, 0) for a sum of 1 + 1 + 1 = 3.
    """


Prompt:
def maximumValueSum(board: List[List[int]]) -> int:
    """
    You are given a m x n 2D array board representing a chessboard, where board[i][j] represents the value of the cell (i, j).
    Rooks in the same row or column attack each other. You need to place three rooks on the chessboard such that the rooks do not attack each other.
    Return the maximum sum of the cell values on which the rooks are placed.

    Example 1:

    >>> maximumValueSum(board = [[-3,1,1,1],[-3,1,-3,1],[-3,2,1,1]])
    >>> 4
    Explanation:

    We can place the rooks in the cells (0, 2), (1, 3), and (2, 1) for a sum of 1 + 1 + 2 = 4.

    Example 2:

    >>> maximumValueSum(board = [[1,2,3],[4,5,6],[7,8,9]])
    >>> 15
    Explanation:
    We can place the rooks in the cells (0, 0), (1, 1), and (2, 2) for a sum of 1 + 5 + 9 = 15.

    Example 3:

    >>> maximumValueSum(board = [[1,1,1],[1,1,1],[1,1,1]])
    >>> 3
    Explanation:
    We can place the rooks in the cells (0, 2), (1, 1), and (2, 0) for a sum of 1 + 1 + 1 = 3.
    """


Prompt:
def countKConstraintSubstrings(s: str, k: int) -> int:
    """
    You are given a binary string s and an integer k.
    A binary string satisfies the k-constraint if either of the following conditions holds:

    The number of 0's in the string is at most k.
    The number of 1's in the string is at most k.

    Return an integer denoting the number of substrings of s that satisfy the k-constraint.

    Example 1:

    >>> countKConstraintSubstrings(s = "10101", k = 1)
    >>> 12
    Explanation:
    Every substring of s except the substrings "1010", "10101", and "0101" satisfies the k-constraint.

    Example 2:

    >>> countKConstraintSubstrings(s = "1010101", k = 2)
    >>> 25
    Explanation:
    Every substring of s except the substrings with a length greater than 5 satisfies the k-constraint.

    Example 3:

    >>> countKConstraintSubstrings(s = "11111", k = 1)
    >>> 15
    Explanation:
    All substrings of s satisfy the k-constraint.
    """


Prompt:
def maxEnergyBoost(energyDrinkA: List[int], energyDrinkB: List[int]) -> int:
    """
    You are given two integer arrays energyDrinkA and energyDrinkB of the same length n by a futuristic sports scientist. These arrays represent the energy boosts per hour provided by two different energy drinks, A and B, respectively.
    You want to maximize your total energy boost by drinking one energy drink per hour. However, if you want to switch from consuming one energy drink to the other, you need to wait for one hour to cleanse your system (meaning you won't get any energy boost in that hour).
    Return the maximum total energy boost you can gain in the next n hours.
    Note that you can start consuming either of the two energy drinks.

    Example 1:

    >>> maxEnergyBoost(energyDrinkA = [1,3,1], energyDrinkB = [3,1,1])
    >>> 5
    Explanation:
    To gain an energy boost of 5, drink only the energy drink A (or only B).

    Example 2:

    >>> maxEnergyBoost(energyDrinkA = [4,1,1], energyDrinkB = [1,1,3])
    >>> 7
    Explanation:
    To gain an energy boost of 7:

    Drink the energy drink A for the first hour.
    Switch to the energy drink B and we lose the energy boost of the second hour.
    Gain the energy boost of the drink B in the third hour.
    """


Prompt:
def largestPalindrome(n: int, k: int) -> str:
    """
    You are given two positive integers n and k.
    An integer x is called k-palindromic if:

    x is a palindrome.
    x is divisible by k.

    Return the largest integer having n digits (as a string) that is k-palindromic.
    Note that the integer must not have leading zeros.

    Example 1:

    >>> largestPalindrome(n = 3, k = 5)
    >>> "595"
    Explanation:
    595 is the largest k-palindromic integer with 3 digits.

    Example 2:

    >>> largestPalindrome(n = 1, k = 4)
    >>> "8"
    Explanation:
    4 and 8 are the only k-palindromic integers with 1 digit.

    Example 3:

    >>> largestPalindrome(n = 5, k = 6)
    >>> "89898"
    """


Prompt:
def countKConstraintSubstrings(s: str, k: int, queries: List[List[int]]) -> List[int]:
    """
    You are given a binary string s and an integer k.
    You are also given a 2D integer array queries, where queries[i] = [li, ri].
    A binary string satisfies the k-constraint if either of the following conditions holds:

    The number of 0's in the string is at most k.
    The number of 1's in the string is at most k.

    Return an integer array answer, where answer[i] is the number of substrings of s[li..ri] that satisfy the k-constraint.

    Example 1:

    >>> countKConstraintSubstrings(s = "0001111", k = 2, queries = [[0,6]])
    >>> [26]
    Explanation:
    For the query [0, 6], all substrings of s[0..6] = "0001111" satisfy the k-constraint except for the substrings s[0..5] = "000111" and s[0..6] = "0001111".

    Example 2:

    >>> countKConstraintSubstrings(s = "010101", k = 1, queries = [[0,5],[1,4],[2,3]])
    >>> [15,9,3]
    Explanation:
    The substrings of s with a length greater than 3 do not satisfy the k-constraint.
    """


Prompt:
def getFinalState(nums: List[int], k: int, multiplier: int) -> List[int]:
    """
    You are given an integer array nums, an integer k, and an integer multiplier.
    You need to perform k operations on nums. In each operation:

    Find the minimum value x in nums. If there are multiple occurrences of the minimum value, select the one that appears first.
    Replace the selected minimum value x with x * multiplier.

    Return an integer array denoting the final state of nums after performing all k operations.

    Example 1:

    >>> getFinalState(nums = [2,1,3,5,6], k = 5, multiplier = 2)
    >>> [8,4,6,5,6]
    Explanation:

    Operation
    Result

    After operation 1
    [2, 2, 3, 5, 6]

    After operation 2
    [4, 2, 3, 5, 6]

    After operation 3
    [4, 4, 3, 5, 6]

    After operation 4
    [4, 4, 6, 5, 6]

    After operation 5
    [8, 4, 6, 5, 6]

    Example 2:

    >>> getFinalState(nums = [1,2], k = 3, multiplier = 4)
    >>> [16,8]
    Explanation:

    Operation
    Result

    After operation 1
    [4, 2]

    After operation 2
    [4, 8]

    After operation 3
    [16, 8]
    """


Prompt:
def countPairs(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    We call two integers x and y in this problem almost equal if both integers can become equal after performing the following operation at most once:

    Choose either x or y and swap any two digits within the chosen number.

    Return the number of indices i and j in nums where i < j such that nums[i] and nums[j] are almost equal.
    Note that it is allowed for an integer to have leading zeros after performing an operation.

    Example 1:

    >>> countPairs(nums = [3,12,30,17,21])
    >>> 2
    Explanation:
    The almost equal pairs of elements are:

    3 and 30. By swapping 3 and 0 in 30, you get 3.
    12 and 21. By swapping 1 and 2 in 12, you get 21.

    Example 2:

    >>> countPairs(nums = [1,1,1,1,1])
    >>> 10
    Explanation:
    Every two elements in the array are almost equal.

    Example 3:

    >>> countPairs(nums = [123,231])
    >>> 0
    Explanation:
    We cannot swap any two digits of 123 or 231 to reach the other.
    """


Prompt:
def getFinalState(nums: List[int], k: int, multiplier: int) -> List[int]:
    """
    You are given an integer array nums, an integer k, and an integer multiplier.
    You need to perform k operations on nums. In each operation:

    Find the minimum value x in nums. If there are multiple occurrences of the minimum value, select the one that appears first.
    Replace the selected minimum value x with x * multiplier.

    After the k operations, apply modulo 109 + 7 to every value in nums.
    Return an integer array denoting the final state of nums after performing all k operations and then applying the modulo.

    Example 1:

    >>> getFinalState(nums = [2,1,3,5,6], k = 5, multiplier = 2)
    >>> [8,4,6,5,6]
    Explanation:

    Operation
    Result

    After operation 1
    [2, 2, 3, 5, 6]

    After operation 2
    [4, 2, 3, 5, 6]

    After operation 3
    [4, 4, 3, 5, 6]

    After operation 4
    [4, 4, 6, 5, 6]

    After operation 5
    [8, 4, 6, 5, 6]

    After applying modulo
    [8, 4, 6, 5, 6]

    Example 2:

    >>> getFinalState(nums = [100000,2000], k = 2, multiplier = 1000000)
    >>> [999999307,999999993]
    Explanation:

    Operation
    Result

    After operation 1
    [100000, 2000000000]

    After operation 2
    [100000000000, 2000000000]

    After applying modulo
    [999999307, 999999993]
    """


Prompt:
def countPairs(nums: List[int]) -> int:
    """
    Attention: In this version, the number of operations that can be performed, has been increased to twice.
    You are given an array nums consisting of positive integers.
    We call two integers x and y almost equal if both integers can become equal after performing the following operation at most twice:

    Choose either x or y and swap any two digits within the chosen number.

    Return the number of indices i and j in nums where i < j such that nums[i] and nums[j] are almost equal.
    Note that it is allowed for an integer to have leading zeros after performing an operation.

    Example 1:

    >>> countPairs(nums = [1023,2310,2130,213])
    >>> 4
    Explanation:
    The almost equal pairs of elements are:

    1023 and 2310. By swapping the digits 1 and 2, and then the digits 0 and 3 in 1023, you get 2310.
    1023 and 213. By swapping the digits 1 and 0, and then the digits 1 and 2 in 1023, you get 0213, which is 213.
    2310 and 213. By swapping the digits 2 and 0, and then the digits 3 and 2 in 2310, you get 0213, which is 213.
    2310 and 2130. By swapping the digits 3 and 1 in 2310, you get 2130.

    Example 2:

    >>> countPairs(nums = [1,10,100])
    >>> 3
    Explanation:
    The almost equal pairs of elements are:

    1 and 10. By swapping the digits 1 and 0 in 10, you get 01 which is 1.
    1 and 100. By swapping the second 0 with the digit 1 in 100, you get 001, which is 1.
    10 and 100. By swapping the first 0 with the digit 1 in 100, you get 010, which is 10.
    """


Prompt:
def minLargest(nums1: List[int], nums2: List[int]) -> int:
    """
    Given 2 integer arrays nums1 and nums2 consisting only of 0 and 1, your task is to calculate the minimum possible largest number in arrays nums1 and nums2, after doing the following.
    Replace every 0 with an even positive integer and every 1 with an odd positive integer. After replacement, both arrays should be increasing and each integer should be used at most once.
    Return the minimum possible largest number after applying the changes.

    Example 1:

    >>> minLargest(nums1 = [], nums2 = [1,0,1,1])
    >>> 5
    Explanation:
    After replacing, nums1 = [], and nums2 = [1, 2, 3, 5].

    Example 2:

    >>> minLargest(nums1 = [0,1,0,1], nums2 = [1,0,0,1])
    >>> 9
    Explanation:
    One way to replace, having 9 as the largest element is nums1 = [2, 3, 8, 9], and nums2 = [1, 4, 6, 7].

    Example 3:

    >>> minLargest(nums1 = [0,1,0,0,1], nums2 = [0,0,0,1])
    >>> 13
    Explanation:
    One way to replace, having 13 as the largest element is nums1 = [2, 3, 4, 6, 7], and nums2 = [8, 10, 12, 13].
    """


Prompt:
def generateKey(num1: int, num2: int, num3: int) -> int:
    """
    You are given three positive integers num1, num2, and num3.
    The key of num1, num2, and num3 is defined as a four-digit number such that:

    Initially, if any number has less than four digits, it is padded with leading zeros.
    The ith digit (1 <= i <= 4) of the key is generated by taking the smallest digit among the ith digits of num1, num2, and num3.

    Return the key of the three numbers without leading zeros (if any).

    Example 1:

    >>> generateKey(num1 = 1, num2 = 10, num3 = 1000)
    >>> 0
    Explanation:
    On padding, num1 becomes "0001", num2 becomes "0010", and num3 remains "1000".

    The 1st digit of the key is min(0, 0, 1).
    The 2nd digit of the key is min(0, 0, 0).
    The 3rd digit of the key is min(0, 1, 0).
    The 4th digit of the key is min(1, 0, 0).

    Hence, the key is "0000", i.e. 0.

    Example 2:

    >>> generateKey(num1 = 987, num2 = 879, num3 = 798)
    >>> 777

    Example 3:

    >>> generateKey(num1 = 1, num2 = 2, num3 = 3)
    >>> 1
    """


Prompt:
def stringHash(s: str, k: int) -> str:
    """
    You are given a string s of length n and an integer k, where n is a multiple of k. Your task is to hash the string s into a new string called result, which has a length of n / k.
    First, divide s into n / k substrings, each with a length of k. Then, initialize result as an empty string.
    For each substring in order from the beginning:

    The hash value of a character is the index of that character in the English alphabet (e.g., 'a' → 0, 'b' → 1, ..., 'z' → 25).
    Calculate the sum of all the hash values of the characters in the substring.
    Find the remainder of this sum when divided by 26, which is called hashedChar.
    Identify the character in the English lowercase alphabet that corresponds to hashedChar.
    Append that character to the end of result.

    Return result.

    Example 1:

    >>> stringHash(s = "abcd", k = 2)
    >>> "bf"
    Explanation:
    First substring: "ab", 0 + 1 = 1, 1 % 26 = 1, result[0] = 'b'.
    Second substring: "cd", 2 + 3 = 5, 5 % 26 = 5, result[1] = 'f'.

    Example 2:

    >>> stringHash(s = "mxz", k = 3)
    >>> "i"
    Explanation:
    The only substring: "mxz", 12 + 23 + 25 = 60, 60 % 26 = 8, result[0] = 'i'.
    """


Prompt:
def countGoodIntegers(n: int, k: int) -> int:
    """
    You are given two positive integers n and k.
    An integer x is called k-palindromic if:

    x is a palindrome.
    x is divisible by k.

    An integer is called good if its digits can be rearranged to form a k-palindromic integer. For example, for k = 2, 2020 can be rearranged to form the k-palindromic integer 2002, whereas 1010 cannot be rearranged to form a k-palindromic integer.
    Return the count of good integers containing n digits.
    Note that any integer must not have leading zeros, neither before nor after rearrangement. For example, 1010 cannot be rearranged to form 101.

    Example 1:

    >>> countGoodIntegers(n = 3, k = 5)
    >>> 27
    Explanation:
    Some of the good integers are:

    551 because it can be rearranged to form 515.
    525 because it is already k-palindromic.

    Example 2:

    >>> countGoodIntegers(n = 1, k = 4)
    >>> 2
    Explanation:
    The two good integers are 4 and 8.

    Example 3:

    >>> countGoodIntegers(n = 5, k = 6)
    >>> 2468
    """


Prompt:
def minDamage(power: int, damage: List[int], health: List[int]) -> int:
    """
    You are given an integer power and two integer arrays damage and health, both having length n.
    Bob has n enemies, where enemy i will deal Bob damage[i] points of damage per second while they are alive (i.e. health[i] > 0).
    Every second, after the enemies deal damage to Bob, he chooses one of the enemies that is still alive and deals power points of damage to them.
    Determine the minimum total amount of damage points that will be dealt to Bob before all n enemies are dead.

    Example 1:

    >>> minDamage(power = 4, damage = [1,2,3,4], health = [4,5,6,8])
    >>> 39
    Explanation:

    Attack enemy 3 in the first two seconds, after which enemy 3 will go down, the number of damage points dealt to Bob is 10 + 10 = 20 points.
    Attack enemy 2 in the next two seconds, after which enemy 2 will go down, the number of damage points dealt to Bob is 6 + 6 = 12 points.
    Attack enemy 0 in the next second, after which enemy 0 will go down, the number of damage points dealt to Bob is 3 points.
    Attack enemy 1 in the next two seconds, after which enemy 1 will go down, the number of damage points dealt to Bob is 2 + 2 = 4 points.

    Example 2:

    >>> minDamage(power = 1, damage = [1,1,1,1], health = [1,2,3,4])
    >>> 20
    Explanation:

    Attack enemy 0 in the first second, after which enemy 0 will go down, the number of damage points dealt to Bob is 4 points.
    Attack enemy 1 in the next two seconds, after which enemy 1 will go down, the number of damage points dealt to Bob is 3 + 3 = 6 points.
    Attack enemy 2 in the next three seconds, after which enemy 2 will go down, the number of damage points dealt to Bob is 2 + 2 + 2 = 6 points.
    Attack enemy 3 in the next four seconds, after which enemy 3 will go down, the number of damage points dealt to Bob is 1 + 1 + 1 + 1 = 4 points.

    Example 3:

    >>> minDamage(power = 8, damage = [40], health = [59])
    >>> 320
    """


Prompt:
def checkTwoChessboards(coordinate1: str, coordinate2: str) -> bool:
    """
    You are given two strings, coordinate1 and coordinate2, representing the coordinates of a square on an 8 x 8 chessboard.
    Below is the chessboard for reference.

    Return true if these two squares have the same color and false otherwise.
    The coordinate will always represent a valid chessboard square. The coordinate will always have the letter first (indicating its column), and the number second (indicating its row).

    Example 1:

    >>> checkTwoChessboards(coordinate1 = "a1", coordinate2 = "c3")
    >>> true
    Explanation:
    Both squares are black.

    Example 2:

    >>> checkTwoChessboards(coordinate1 = "a1", coordinate2 = "h3")
    >>> false
    Explanation:
    Square "a1" is black and "h3" is white.
    """


Prompt:
def resultsArray(queries: List[List[int]], k: int) -> List[int]:
    """
    There is an infinite 2D plane.
    You are given a positive integer k. You are also given a 2D array queries, which contains the following queries:

    queries[i] = [x, y]: Build an obstacle at coordinate (x, y) in the plane. It is guaranteed that there is no obstacle at this coordinate when this query is made.

    After each query, you need to find the distance of the kth nearest obstacle from the origin.
    Return an integer array results where results[i] denotes the kth nearest obstacle after query i, or results[i] == -1 if there are less than k obstacles.
    Note that initially there are no obstacles anywhere.
    The distance of an obstacle at coordinate (x, y) from the origin is given by |x| + |y|.

    Example 1:

    >>> resultsArray(queries = [[1,2],[3,4],[2,3],[-3,0]], k = 2)
    >>> [-1,7,5,3]
    Explanation:

    Initially, there are 0 obstacles.
    After queries[0], there are less than 2 obstacles.
    After queries[1], there are obstacles at distances 3 and 7.
    After queries[2], there are obstacles at distances 3, 5, and 7.
    After queries[3], there are obstacles at distances 3, 3, 5, and 7.

    Example 2:

    >>> resultsArray(queries = [[5,5],[4,4],[3,3]], k = 1)
    >>> [10,8,6]
    Explanation:

    After queries[0], there is an obstacle at distance 10.
    After queries[1], there are obstacles at distances 8 and 10.
    After queries[2], there are obstacles at distances 6, 8, and 10.
    """


Prompt:
def maxScore(grid: List[List[int]]) -> int:
    """
    You are given a 2D matrix grid consisting of positive integers.
    You have to select one or more cells from the matrix such that the following conditions are satisfied:

    No two selected cells are in the same row of the matrix.
    The values in the set of selected cells are unique.

    Your score will be the sum of the values of the selected cells.
    Return the maximum score you can achieve.

    Example 1:

    >>> maxScore(grid = [[1,2,3],[4,3,2],[1,1,1]])
    >>> 8
    Explanation:

    We can select the cells with values 1, 3, and 4 that are colored above.

    Example 2:

    >>> maxScore(grid = [[8,7,6],[8,3,2]])
    >>> 15
    Explanation:

    We can select the cells with values 7 and 8 that are colored above.
    """


Prompt:
def maximumSubarrayXor(nums: List[int], queries: List[List[int]]) -> List[int]:
    """
    You are given an array nums of n integers, and a 2D integer array queries of size q, where queries[i] = [li, ri].
    For each query, you must find the maximum XOR score of any subarray of nums[li..ri].
    The XOR score of an array a is found by repeatedly applying the following operations on a so that only one element remains, that is the score:

    Simultaneously replace a[i] with a[i] XOR a[i + 1] for all indices i except the last one.
    Remove the last element of a.

    Return an array answer of size q where answer[i] is the answer to query i.

    Example 1:

    >>> maximumSubarrayXor(nums = [2,8,4,32,16,1], queries = [[0,2],[1,4],[0,5]])
    >>> [12,60,60]
    Explanation:
    In the first query, nums[0..2] has 6 subarrays [2], [8], [4], [2, 8], [8, 4], and [2, 8, 4] each with a respective XOR score of 2, 8, 4, 10, 12, and 6. The answer for the query is 12, the largest of all XOR scores.
    In the second query, the subarray of nums[1..4] with the largest XOR score is nums[1..4] with a score of 60.
    In the third query, the subarray of nums[0..5] with the largest XOR score is nums[1..4] with a score of 60.

    Example 2:

    >>> maximumSubarrayXor(nums = [0,7,3,2,8,5,1], queries = [[0,3],[1,5],[2,4],[2,6],[5,6]])
    >>> [7,14,11,14,5]
    Explanation:

    Index
    nums[li..ri]
    Maximum XOR Score Subarray
    Maximum Subarray XOR Score

    0
    [0, 7, 3, 2]
    [7]
    7

    1
    [7, 3, 2, 8, 5]
    [7, 3, 2, 8]
    14

    2
    [3, 2, 8]
    [3, 2, 8]
    11

    3
    [3, 2, 8, 5, 1]
    [2, 8, 5, 1]
    14

    4
    [5, 1]
    [5]
    5
    """


Prompt:
def maxArea(height: int, positions: List[int], directions: str) -> int:
    """
    There are several pistons in an old car engine, and we want to calculate the maximum possible area under the pistons.
    You are given:

    An integer height, representing the maximum height a piston can reach.
    An integer array positions, where positions[i] is the current position of piston i, which is equal to the current area under it.
    A string directions, where directions[i] is the current moving direction of piston i, 'U' for up, and 'D' for down.

    Each second:

    Every piston moves in its current direction 1 unit. e.g., if the direction is up, positions[i] is incremented by 1.
    If a piston has reached one of the ends, i.e., positions[i] == 0 or positions[i] == height, its direction will change.

    Return the maximum possible area under all the pistons.

    Example 1:

    >>> maxArea(height = 5, positions = [2,5], directions = "UD")
    >>> 7
    Explanation:
    The current position of the pistons has the maximum possible area under it.

    Example 2:

    >>> maxArea(height = 6, positions = [0,0,6,3], directions = "UUDU")
    >>> 15
    Explanation:
    After 3 seconds, the pistons will be in positions [3, 3, 3, 6], which has the maximum possible area under it.
    """


Prompt:
def convertDateToBinary(date: str) -> str:
    """
    You are given a string date representing a Gregorian calendar date in the yyyy-mm-dd format.
    date can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in year-month-day format.
    Return the binary representation of date.

    Example 1:

    >>> convertDateToBinary(date = "2080-02-29")
    >>> "100000100000-10-11101"
    Explanation:
    100000100000, 10, and 11101 are the binary representations of 2080, 02, and 29 respectively.

    Example 2:

    >>> convertDateToBinary(date = "1900-01-01")
    >>> "11101101100-1-1"
    Explanation:
    11101101100, 1, and 1 are the binary representations of 1900, 1, and 1 respectively.
    """


Prompt:
def maxPossibleScore(start: List[int], d: int) -> int:
    """
    You are given an array of integers start and an integer d, representing n intervals [start[i], start[i] + d].
    You are asked to choose n integers where the ith integer must belong to the ith interval. The score of the chosen integers is defined as the minimum absolute difference between any two integers that have been chosen.
    Return the maximum possible score of the chosen integers.

    Example 1:

    >>> maxPossibleScore(start = [6,0,3], d = 2)
    >>> 4
    Explanation:
    The maximum possible score can be obtained by choosing integers: 8, 0, and 4. The score of these chosen integers is min(|8 - 0|, |8 - 4|, |0 - 4|) which equals 4.

    Example 2:

    >>> maxPossibleScore(start = [2,6,13,13], d = 5)
    >>> 5
    Explanation:
    The maximum possible score can be obtained by choosing integers: 2, 7, 13, and 18. The score of these chosen integers is min(|2 - 7|, |2 - 13|, |2 - 18|, |7 - 13|, |7 - 18|, |13 - 18|) which equals 5.
    """


Prompt:
def findMaximumScore(nums: List[int]) -> int:
    """
    You are given an integer array nums of length n.
    Your goal is to start at index 0 and reach index n - 1. You can only jump to indices greater than your current index.
    The score for a jump from index i to index j is calculated as (j - i) * nums[i].
    Return the maximum possible total score by the time you reach the last index.

    Example 1:

    >>> findMaximumScore(nums = [1,3,1,5])
    >>> 7
    Explanation:
    First, jump to index 1 and then jump to the last index. The final score is 1 * 1 + 2 * 3 = 7.

    Example 2:

    >>> findMaximumScore(nums = [4,3,1,3,2])
    >>> 16
    Explanation:
    Jump directly to the last index. The final score is 4 * 4 = 16.
    """


Prompt:
def maxMoves(kx: int, ky: int, positions: List[List[int]]) -> int:
    """
    There is a 50 x 50 chessboard with one knight and some pawns on it. You are given two integers kx and ky where (kx, ky) denotes the position of the knight, and a 2D array positions where positions[i] = [xi, yi] denotes the position of the pawns on the chessboard.
    Alice and Bob play a turn-based game, where Alice goes first. In each player's turn:

    The player selects a pawn that still exists on the board and captures it with the knight in the fewest possible moves. Note that the player can select any pawn, it might not be one that can be captured in the least number of moves.
    In the process of capturing the selected pawn, the knight may pass other pawns without capturing them. Only the selected pawn can be captured in this turn.

    Alice is trying to maximize the sum of the number of moves made by both players until there are no more pawns on the board, whereas Bob tries to minimize them.
    Return the maximum total number of moves made during the game that Alice can achieve, assuming both players play optimally.
    Note that in one move, a chess knight has eight possible positions it can move to, as illustrated below. Each move is two cells in a cardinal direction, then one cell in an orthogonal direction.

    Example 1:

    >>> maxMoves(kx = 1, ky = 1, positions = [[0,0]])
    >>> 4
    Explanation:

    The knight takes 4 moves to reach the pawn at (0, 0).

    Example 2:

    >>> maxMoves(kx = 0, ky = 2, positions = [[1,1],[2,2],[3,3]])
    >>> 8
    Explanation:

    Alice picks the pawn at (2, 2) and captures it in two moves: (0, 2) -> (1, 4) -> (2, 2).
    Bob picks the pawn at (3, 3) and captures it in two moves: (2, 2) -> (4, 1) -> (3, 3).
    Alice picks the pawn at (1, 1) and captures it in four moves: (3, 3) -> (4, 1) -> (2, 2) -> (0, 3) -> (1, 1).

    Example 3:

    >>> maxMoves(kx = 0, ky = 0, positions = [[1,2],[2,4]])
    >>> 3
    Explanation:

    Alice picks the pawn at (2, 4) and captures it in two moves: (0, 0) -> (1, 2) -> (2, 4). Note that the pawn at (1, 2) is not captured.
    Bob picks the pawn at (1, 2) and captures it in one move: (2, 4) -> (1, 2).
    """


Prompt:
def getSum(nums: List[int]) -> int:
    """
    We call an array arr of length n consecutive if one of the following holds:

    arr[i] - arr[i - 1] == 1 for all 1 <= i < n.
    arr[i] - arr[i - 1] == -1 for all 1 <= i < n.

    The value of an array is the sum of its elements.
    For example, [3, 4, 5] is a consecutive array of value 12 and [9, 8] is another of value 17. While [3, 4, 3] and [8, 6] are not consecutive.
    Given an array of integers nums, return the sum of the values of all consecutive subarrays.
    Since the answer may be very large, return it modulo 109 + 7.
    Note that an array of length 1 is also considered consecutive.

    Example 1:

    >>> getSum(nums = [1,2,3])
    >>> 20
    Explanation:
    The consecutive subarrays are: [1], [2], [3], [1, 2], [2, 3], [1, 2, 3].
    Sum of their values would be: 1 + 2 + 3 + 3 + 5 + 6 = 20.

    Example 2:

    >>> getSum(nums = [1,3,5,7])
    >>> 16
    Explanation:
    The consecutive subarrays are: [1], [3], [5], [7].
    Sum of their values would be: 1 + 3 + 5 + 7 = 16.

    Example 3:

    >>> getSum(nums = [7,6,1,2])
    >>> 32
    Explanation:
    The consecutive subarrays are: [7], [6], [1], [2], [7, 6], [1, 2].
    Sum of their values would be: 7 + 6 + 1 + 2 + 13 + 3 = 32.
    """


Prompt:
def stableMountains(height: List[int], threshold: int) -> List[int]:
    """
    There are n mountains in a row, and each mountain has a height. You are given an integer array height where height[i] represents the height of mountain i, and an integer threshold.
    A mountain is called stable if the mountain just before it (if it exists) has a height strictly greater than threshold. Note that mountain 0 is not stable.
    Return an array containing the indices of all stable mountains in any order.

    Example 1:

    >>> stableMountains(height = [1,2,3,4,5], threshold = 2)
    >>> [3,4]
    Explanation:

    Mountain 3 is stable because height[2] == 3 is greater than threshold == 2.
    Mountain 4 is stable because height[3] == 4 is greater than threshold == 2.

    Example 2:

    >>> stableMountains(height = [10,1,10,1,10], threshold = 3)
    >>> [1,3]

    Example 3:

    >>> stableMountains(height = [10,1,10,1,10], threshold = 10)
    >>> []
    """


Prompt:
def findSafeWalk(grid: List[List[int]], health: int) -> bool:
    """
    You are given an m x n binary matrix grid and an integer health.
    You start on the upper-left corner (0, 0) and would like to get to the lower-right corner (m - 1, n - 1).
    You can move up, down, left, or right from one cell to another adjacent cell as long as your health remains positive.
    Cells (i, j) with grid[i][j] = 1 are considered unsafe and reduce your health by 1.
    Return true if you can reach the final cell with a health value of 1 or more, and false otherwise.

    Example 1:

    >>> findSafeWalk(grid = [[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]], health = 1)
    >>> true
    Explanation:
    The final cell can be reached safely by walking along the gray cells below.

    Example 2:

    >>> findSafeWalk(grid = [[0,1,1,0,0,0],[1,0,1,0,0,0],[0,1,1,1,0,1],[0,0,1,0,1,0]], health = 3)
    >>> false
    Explanation:
    A minimum of 4 health points is needed to reach the final cell safely.

    Example 3:

    >>> findSafeWalk(grid = [[1,1,1],[1,0,1],[1,1,1]], health = 5)
    >>> true
    Explanation:
    The final cell can be reached safely by walking along the gray cells below.

    Any path that does not go through the cell (1, 1) is unsafe since your health will drop to 0 when reaching the final cell.
    """


Prompt:
def maxValue(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and a positive integer k.
    The value of a sequence seq of size 2 * x is defined as:

    (seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 * x - 1]).

    Return the maximum value of any subsequence of nums having size 2 * k.

    Example 1:

    >>> maxValue(nums = [2,6,7], k = 1)
    >>> 5
    Explanation:
    The subsequence [2, 7] has the maximum value of 2 XOR 7 = 5.

    Example 2:

    >>> maxValue(nums = [4,2,5,6,7], k = 2)
    >>> 2
    Explanation:
    The subsequence [4, 5, 6, 7] has the maximum value of (4 OR 5) XOR (6 OR 7) = 2.
    """


Prompt:
def maxPathLength(coordinates: List[List[int]], k: int) -> int:
    """
    You are given a 2D array of integers coordinates of length n and an integer k, where 0 <= k < n.
    coordinates[i] = [xi, yi] indicates the point (xi, yi) in a 2D plane.
    An increasing path of length m is defined as a list of points (x1, y1), (x2, y2), (x3, y3), ..., (xm, ym) such that:

    xi < xi + 1 and yi < yi + 1 for all i where 1 <= i < m.
    (xi, yi) is in the given coordinates for all i where 1 <= i <= m.

    Return the maximum length of an increasing path that contains coordinates[k].

    Example 1:

    >>> maxPathLength(coordinates = [[3,1],[2,2],[4,1],[0,0],[5,3]], k = 1)
    >>> 3
    Explanation:
    (0, 0), (2, 2), (5, 3) is the longest increasing path that contains (2, 2).

    Example 2:

    >>> maxPathLength(coordinates = [[2,1],[7,0],[5,6]], k = 2)
    >>> 2
    Explanation:
    (2, 1), (5, 6) is the longest increasing path that contains (5, 6).
    """


Prompt:
def getSneakyNumbers(nums: List[int]) -> List[int]:
    """
    In the town of Digitville, there was a list of numbers called nums containing integers from 0 to n - 1. Each number was supposed to appear exactly once in the list, however, two mischievous numbers sneaked in an additional time, making the list longer than usual.
    As the town detective, your task is to find these two sneaky numbers. Return an array of size two containing the two numbers (in any order), so peace can return to Digitville.

    Example 1:

    >>> getSneakyNumbers(nums = [0,1,1,0])
    >>> [0,1]
    Explanation:
    The numbers 0 and 1 each appear twice in the array.

    Example 2:

    >>> getSneakyNumbers(nums = [0,3,2,1,3,2])
    >>> [2,3]
    Explanation:
    The numbers 2 and 3 each appear twice in the array.

    Example 3:

    >>> getSneakyNumbers(nums = [7,1,5,4,3,4,6,0,9,5,8,2])
    >>> [4,5]
    Explanation:
    The numbers 4 and 5 each appear twice in the array.
    """


Prompt:
def maxScore(a: List[int], b: List[int]) -> int:
    """
    You are given an integer array a of size 4 and another integer array b of size at least 4.
    You need to choose 4 indices i0, i1, i2, and i3 from the array b such that i0 < i1 < i2 < i3. Your score will be equal to the value a[0] * b[i0] + a[1] * b[i1] + a[2] * b[i2] + a[3] * b[i3].
    Return the maximum score you can achieve.

    Example 1:

    >>> maxScore(a = [3,2,5,6], b = [2,-6,4,-5,-3,2,-7])
    >>> 26
    Explanation:
    We can choose the indices 0, 1, 2, and 5. The score will be 3 * 2 + 2 * (-6) + 5 * 4 + 6 * 2 = 26.

    Example 2:

    >>> maxScore(a = [-1,4,5,-2], b = [-5,-1,-3,-2,-4])
    >>> -1
    Explanation:
    We can choose the indices 0, 1, 3, and 4. The score will be (-1) * (-5) + 4 * (-1) + 5 * (-2) + (-2) * (-4) = -1.
    """


Prompt:
def minValidStrings(words: List[str], target: str) -> int:
    """
    You are given an array of strings words and a string target.
    A string x is called valid if x is a prefix of any string in words.
    Return the minimum number of valid strings that can be concatenated to form target. If it is not possible to form target, return -1.

    Example 1:

    >>> minValidStrings(words = ["abc","aaaaa","bcdef"], target = "aabcdabc")
    >>> 3
    Explanation:
    The target string can be formed by concatenating:

    Prefix of length 2 of words[1], i.e. "aa".
    Prefix of length 3 of words[2], i.e. "bcd".
    Prefix of length 3 of words[0], i.e. "abc".

    Example 2:

    >>> minValidStrings(words = ["abababab","ab"], target = "ababaababa")
    >>> 2
    Explanation:
    The target string can be formed by concatenating:

    Prefix of length 5 of words[0], i.e. "ababa".
    Prefix of length 5 of words[0], i.e. "ababa".

    Example 3:

    >>> minValidStrings(words = ["abcdef"], target = "xyz")
    >>> -1
    """


Prompt:
def minValidStrings(words: List[str], target: str) -> int:
    """
    You are given an array of strings words and a string target.
    A string x is called valid if x is a prefix of any string in words.
    Return the minimum number of valid strings that can be concatenated to form target. If it is not possible to form target, return -1.

    Example 1:

    >>> minValidStrings(words = ["abc","aaaaa","bcdef"], target = "aabcdabc")
    >>> 3
    Explanation:
    The target string can be formed by concatenating:

    Prefix of length 2 of words[1], i.e. "aa".
    Prefix of length 3 of words[2], i.e. "bcd".
    Prefix of length 3 of words[0], i.e. "abc".

    Example 2:

    >>> minValidStrings(words = ["abababab","ab"], target = "ababaababa")
    >>> 2
    Explanation:
    The target string can be formed by concatenating:

    Prefix of length 5 of words[0], i.e. "ababa".
    Prefix of length 5 of words[0], i.e. "ababa".

    Example 3:

    >>> minValidStrings(words = ["abcdef"], target = "xyz")
    >>> -1
    """


Prompt:
def reportSpam(message: List[str], bannedWords: List[str]) -> bool:
    """
    You are given an array of strings message and an array of strings bannedWords.
    An array of words is considered spam if there are at least two words in it that exactly match any word in bannedWords.
    Return true if the array message is spam, and false otherwise.

    Example 1:

    >>> reportSpam(message = ["hello","world","leetcode"], bannedWords = ["world","hello"])
    >>> true
    Explanation:
    The words "hello" and "world" from the message array both appear in the bannedWords array.

    Example 2:

    >>> reportSpam(message = ["hello","programming","fun"], bannedWords = ["world","programming","leetcode"])
    >>> false
    Explanation:
    Only one word from the message array ("programming") appears in the bannedWords array.
    """


Prompt:
def minNumberOfSeconds(mountainHeight: int, workerTimes: List[int]) -> int:
    """
    You are given an integer mountainHeight denoting the height of a mountain.
    You are also given an integer array workerTimes representing the work time of workers in seconds.
    The workers work simultaneously to reduce the height of the mountain. For worker i:

    To decrease the mountain's height by x, it takes workerTimes[i] + workerTimes[i] * 2 + ... + workerTimes[i] * x seconds. For example:

    To reduce the height of the mountain by 1, it takes workerTimes[i] seconds.
    To reduce the height of the mountain by 2, it takes workerTimes[i] + workerTimes[i] * 2 seconds, and so on.

    Return an integer representing the minimum number of seconds required for the workers to make the height of the mountain 0.

    Example 1:

    >>> minNumberOfSeconds(mountainHeight = 4, workerTimes = [2,1,1])
    >>> 3
    Explanation:
    One way the height of the mountain can be reduced to 0 is:

    Worker 0 reduces the height by 1, taking workerTimes[0] = 2 seconds.
    Worker 1 reduces the height by 2, taking workerTimes[1] + workerTimes[1] * 2 = 3 seconds.
    Worker 2 reduces the height by 1, taking workerTimes[2] = 1 second.

    Since they work simultaneously, the minimum time needed is max(2, 3, 1) = 3 seconds.

    Example 2:

    >>> minNumberOfSeconds(mountainHeight = 10, workerTimes = [3,2,2,4])
    >>> 12
    Explanation:

    Worker 0 reduces the height by 2, taking workerTimes[0] + workerTimes[0] * 2 = 9 seconds.
    Worker 1 reduces the height by 3, taking workerTimes[1] + workerTimes[1] * 2 + workerTimes[1] * 3 = 12 seconds.
    Worker 2 reduces the height by 3, taking workerTimes[2] + workerTimes[2] * 2 + workerTimes[2] * 3 = 12 seconds.
    Worker 3 reduces the height by 2, taking workerTimes[3] + workerTimes[3] * 2 = 12 seconds.

    The number of seconds needed is max(9, 12, 12, 12) = 12 seconds.

    Example 3:

    >>> minNumberOfSeconds(mountainHeight = 5, workerTimes = [1])
    >>> 15
    Explanation:
    There is only one worker in this example, so the answer is workerTimes[0] + workerTimes[0] * 2 + workerTimes[0] * 3 + workerTimes[0] * 4 + workerTimes[0] * 5 = 15.
    """


Prompt:
def validSubstringCount(word1: str, word2: str) -> int:
    """
    You are given two strings word1 and word2.
    A string x is called valid if x can be rearranged to have word2 as a prefix.
    Return the total number of valid substrings of word1.

    Example 1:

    >>> validSubstringCount(word1 = "bcca", word2 = "abc")
    >>> 1
    Explanation:
    The only valid substring is "bcca" which can be rearranged to "abcc" having "abc" as a prefix.

    Example 2:

    >>> validSubstringCount(word1 = "abcabc", word2 = "abc")
    >>> 10
    Explanation:
    All the substrings except substrings of size 1 and size 2 are valid.

    Example 3:

    >>> validSubstringCount(word1 = "abcabc", word2 = "aaabc")
    >>> 0
    """


Prompt:
def validSubstringCount(word1: str, word2: str) -> int:
    """
    You are given two strings word1 and word2.
    A string x is called valid if x can be rearranged to have word2 as a prefix.
    Return the total number of valid substrings of word1.
    Note that the memory limits in this problem are smaller than usual, so you must implement a solution with a linear runtime complexity.

    Example 1:

    >>> validSubstringCount(word1 = "bcca", word2 = "abc")
    >>> 1
    Explanation:
    The only valid substring is "bcca" which can be rearranged to "abcc" having "abc" as a prefix.

    Example 2:

    >>> validSubstringCount(word1 = "abcabc", word2 = "abc")
    >>> 10
    Explanation:
    All the substrings except substrings of size 1 and size 2 are valid.

    Example 3:

    >>> validSubstringCount(word1 = "abcabc", word2 = "aaabc")
    >>> 0
    """


Prompt:
def getSum(nums: List[int]) -> int:
    """
    We call an array arr of length n consecutive if one of the following holds:

    arr[i] - arr[i - 1] == 1 for all 1 <= i < n.
    arr[i] - arr[i - 1] == -1 for all 1 <= i < n.

    The value of an array is the sum of its elements.
    For example, [3, 4, 5] is a consecutive array of value 12 and [9, 8] is another of value 17. While [3, 4, 3] and [8, 6] are not consecutive.
    Given an array of integers nums, return the sum of the values of all consecutive non-empty subsequences.
    Since the answer may be very large, return it modulo 109 + 7.
    Note that an array of length 1 is also considered consecutive.

    Example 1:

    >>> getSum(nums = [1,2])
    >>> 6
    Explanation:
    The consecutive subsequences are: [1], [2], [1, 2].

    Example 2:

    >>> getSum(nums = [1,4,2,3])
    >>> 31
    Explanation:
    The consecutive subsequences are: [1], [4], [2], [3], [1, 2], [2, 3], [4, 3], [1, 2, 3].
    """


Prompt:
def minElement(nums: List[int]) -> int:
    """
    You are given an integer array nums.
    You replace each element in nums with the sum of its digits.
    Return the minimum element in nums after all replacements.

    Example 1:

    >>> minElement(nums = [10,12,13,14])
    >>> 1
    Explanation:
    nums becomes [1, 3, 4, 5] after all replacements, with minimum element 1.

    Example 2:

    >>> minElement(nums = [1,2,3,4])
    >>> 1
    Explanation:
    nums becomes [1, 2, 3, 4] after all replacements, with minimum element 1.

    Example 3:

    >>> minElement(nums = [999,19,199])
    >>> 10
    Explanation:
    nums becomes [27, 10, 19] after all replacements, with minimum element 10.
    """


Prompt:
def maximumTotalSum(maximumHeight: List[int]) -> int:
    """
    You are given an array maximumHeight, where maximumHeight[i] denotes the maximum height the ith tower can be assigned.
    Your task is to assign a height to each tower so that:

    The height of the ith tower is a positive integer and does not exceed maximumHeight[i].
    No two towers have the same height.

    Return the maximum possible total sum of the tower heights. If it's not possible to assign heights, return -1.

    Example 1:

    >>> maximumTotalSum(maximumHeight = [2,3,4,3])
    >>> 10
    Explanation:
    We can assign heights in the following way: [1, 2, 4, 3].

    Example 2:

    >>> maximumTotalSum(maximumHeight = [15,10])
    >>> 25
    Explanation:
    We can assign heights in the following way: [15, 10].

    Example 3:

    >>> maximumTotalSum(maximumHeight = [2,2,1])
    >>> -1
    Explanation:
    It's impossible to assign positive heights to each index so that no two towers have the same height.
    """


Prompt:
def validSequence(word1: str, word2: str) -> List[int]:
    """
    You are given two strings word1 and word2.
    A string x is called almost equal to y if you can change at most one character in x to make it identical to y.
    A sequence of indices seq is called valid if:

    The indices are sorted in ascending order.
    Concatenating the characters at these indices in word1 in the same order results in a string that is almost equal to word2.

    Return an array of size word2.length representing the lexicographically smallest valid sequence of indices. If no such sequence of indices exists, return an empty array.
    Note that the answer must represent the lexicographically smallest array, not the corresponding string formed by those indices.

    Example 1:

    >>> validSequence(word1 = "vbcca", word2 = "abc")
    >>> [0,1,2]
    Explanation:
    The lexicographically smallest valid sequence of indices is [0, 1, 2]:

    Change word1[0] to 'a'.
    word1[1] is already 'b'.
    word1[2] is already 'c'.

    Example 2:

    >>> validSequence(word1 = "bacdc", word2 = "abc")
    >>> [1,2,4]
    Explanation:
    The lexicographically smallest valid sequence of indices is [1, 2, 4]:

    word1[1] is already 'a'.
    Change word1[2] to 'b'.
    word1[4] is already 'c'.

    Example 3:

    >>> validSequence(word1 = "aaaaaa", word2 = "aaabc")
    >>> []
    Explanation:
    There is no valid sequence of indices.

    Example 4:

    >>> validSequence(word1 = "abc", word2 = "ab")
    >>> [0,1]
    """


Prompt:
def minStartingIndex(s: str, pattern: str) -> int:
    """
    You are given two strings s and pattern.
    A string x is called almost equal to y if you can change at most one character in x to make it identical to y.
    Return the smallest starting index of a substring in s that is almost equal to pattern. If no such index exists, return -1.
    A substring is a contiguous non-empty sequence of characters within a string.

    Example 1:

    >>> minStartingIndex(s = "abcdefg", pattern = "bcdffg")
    >>> 1
    Explanation:
    The substring s[1..6] == "bcdefg" can be converted to "bcdffg" by changing s[4] to "f".

    Example 2:

    >>> minStartingIndex(s = "ababbababa", pattern = "bacaba")
    >>> 4
    Explanation:
    The substring s[4..9] == "bababa" can be converted to "bacaba" by changing s[6] to "c".

    Example 3:

    >>> minStartingIndex(s = "abcd", pattern = "dba")
    >>> -1

    Example 4:

    >>> minStartingIndex(s = "dde", pattern = "d")
    >>> 0
    """


Prompt:
def kthCharacter(k: int) -> str:
    """
    Alice and Bob are playing a game. Initially, Alice has a string word = "a".
    You are given a positive integer k.
    Now Bob will ask Alice to perform the following operation forever:

    Generate a new string by changing each character in word to its next character in the English alphabet, and append it to the original word.

    For example, performing the operation on "c" generates "cd" and performing the operation on "zb" generates "zbac".
    Return the value of the kth character in word, after enough operations have been done for word to have at least k characters.
    Note that the character 'z' can be changed to 'a' in the operation.

    Example 1:

    >>> kthCharacter(k = 5)
    >>> "b"
    Explanation:
    Initially, word = "a". We need to do the operation three times:

    Generated string is "b", word becomes "ab".
    Generated string is "bc", word becomes "abbc".
    Generated string is "bccd", word becomes "abbcbccd".

    Example 2:

    >>> kthCharacter(k = 10)
    >>> "c"
    """


Prompt:
def countOfSubstrings(word: str, k: int) -> int:
    """
    You are given a string word and a non-negative integer k.
    Return the total number of substrings of word that contain every vowel ('a', 'e', 'i', 'o', and 'u') at least once and exactly k consonants.

    Example 1:

    >>> countOfSubstrings(word = "aeioqq", k = 1)
    >>> 0
    Explanation:
    There is no substring with every vowel.

    Example 2:

    >>> countOfSubstrings(word = "aeiou", k = 0)
    >>> 1
    Explanation:
    The only substring with every vowel and zero consonants is word[0..4], which is "aeiou".

    Example 3:

    >>> countOfSubstrings(word = "ieaouqqieaouqq", k = 1)
    >>> 3
    Explanation:
    The substrings with every vowel and one consonant are:

    word[0..5], which is "ieaouq".
    word[6..11], which is "qieaou".
    word[7..12], which is "ieaouq".
    """


Prompt:
def countOfSubstrings(word: str, k: int) -> int:
    """
    You are given a string word and a non-negative integer k.
    Return the total number of substrings of word that contain every vowel ('a', 'e', 'i', 'o', and 'u') at least once and exactly k consonants.

    Example 1:

    >>> countOfSubstrings(word = "aeioqq", k = 1)
    >>> 0
    Explanation:
    There is no substring with every vowel.

    Example 2:

    >>> countOfSubstrings(word = "aeiou", k = 0)
    >>> 1
    Explanation:
    The only substring with every vowel and zero consonants is word[0..4], which is "aeiou".

    Example 3:

    >>> countOfSubstrings(word = "ieaouqqieaouqq", k = 1)
    >>> 3
    Explanation:
    The substrings with every vowel and one consonant are:

    word[0..5], which is "ieaouq".
    word[6..11], which is "qieaou".
    word[7..12], which is "ieaouq".
    """


Prompt:
def kthCharacter(k: int, operations: List[int]) -> str:
    """
    Alice and Bob are playing a game. Initially, Alice has a string word = "a".
    You are given a positive integer k. You are also given an integer array operations, where operations[i] represents the type of the ith operation.
    Now Bob will ask Alice to perform all operations in sequence:

    If operations[i] == 0, append a copy of word to itself.
    If operations[i] == 1, generate a new string by changing each character in word to its next character in the English alphabet, and append it to the original word. For example, performing the operation on "c" generates "cd" and performing the operation on "zb" generates "zbac".

    Return the value of the kth character in word after performing all the operations.
    Note that the character 'z' can be changed to 'a' in the second type of operation.

    Example 1:

    >>> kthCharacter(k = 5, operations = [0,0,0])
    >>> "a"
    Explanation:
    Initially, word == "a". Alice performs the three operations as follows:

    Appends "a" to "a", word becomes "aa".
    Appends "aa" to "aa", word becomes "aaaa".
    Appends "aaaa" to "aaaa", word becomes "aaaaaaaa".

    Example 2:

    >>> kthCharacter(k = 10, operations = [0,1,0,1])
    >>> "b"
    Explanation:
    Initially, word == "a". Alice performs the four operations as follows:

    Appends "a" to "a", word becomes "aa".
    Appends "bb" to "aa", word becomes "aabb".
    Appends "aabb" to "aabb", word becomes "aabbaabb".
    Appends "bbccbbcc" to "aabbaabb", word becomes "aabbaabbbbccbbcc".
    """


Prompt:
def maxGoodNumber(nums: List[int]) -> int:
    """
    You are given an array of integers nums of size 3.
    Return the maximum possible number whose binary representation can be formed by concatenating the binary representation of all elements in nums in some order.
    Note that the binary representation of any number does not contain leading zeros.

    Example 1:

    >>> maxGoodNumber(nums = [1,2,3])
    >>> 30
    Explanation:
    Concatenate the numbers in the order [3, 1, 2] to get the result "11110", which is the binary representation of 30.

    Example 2:

    >>> maxGoodNumber(nums = [2,8,16])
    >>> 1296
    Explanation:
    Concatenate the numbers in the order [2, 8, 16] to get the result "10100010000", which is the binary representation of 1296.
    """


Prompt:
def remainingMethods(n: int, k: int, invocations: List[List[int]]) -> List[int]:
    """
    You are maintaining a project that has n methods numbered from 0 to n - 1.
    You are given two integers n and k, and a 2D integer array invocations, where invocations[i] = [ai, bi] indicates that method ai invokes method bi.
    There is a known bug in method k. Method k, along with any method invoked by it, either directly or indirectly, are considered suspicious and we aim to remove them.
    A group of methods can only be removed if no method outside the group invokes any methods within it.
    Return an array containing all the remaining methods after removing all the suspicious methods. You may return the answer in any order. If it is not possible to remove all the suspicious methods, none should be removed.

    Example 1:

    >>> remainingMethods(n = 4, k = 1, invocations = [[1,2],[0,1],[3,2]])
    >>> [0,1,2,3]
    Explanation:

    Method 2 and method 1 are suspicious, but they are directly invoked by methods 3 and 0, which are not suspicious. We return all elements without removing anything.

    Example 2:

    >>> remainingMethods(n = 5, k = 0, invocations = [[1,2],[0,2],[0,1],[3,4]])
    >>> [3,4]
    Explanation:

    Methods 0, 1, and 2 are suspicious and they are not directly invoked by any other method. We can remove them.

    Example 3:

    >>> remainingMethods(n = 3, k = 2, invocations = [[1,2],[0,1],[2,0]])
    >>> []
    Explanation:

    All methods are suspicious. We can remove them.
    """


Prompt:
def constructGridLayout(n: int, edges: List[List[int]]) -> List[List[int]]:
    """
    You are given a 2D integer array edges representing an undirected graph having n nodes, where edges[i] = [ui, vi] denotes an edge between nodes ui and vi.
    Construct a 2D grid that satisfies these conditions:

    The grid contains all nodes from 0 to n - 1 in its cells, with each node appearing exactly once.
    Two nodes should be in adjacent grid cells (horizontally or vertically) if and only if there is an edge between them in edges.

    It is guaranteed that edges can form a 2D grid that satisfies the conditions.
    Return a 2D integer array satisfying the conditions above. If there are multiple solutions, return any of them.

    Example 1:

    >>> constructGridLayout(n = 4, edges = [[0,1],[0,2],[1,3],[2,3]])
    >>> [[3,1],[2,0]]
    Explanation:

    Example 2:

    >>> constructGridLayout(n = 5, edges = [[0,1],[1,3],[2,3],[2,4]])
    >>> [[4,2,3,1,0]]
    Explanation:

    Example 3:

    >>> constructGridLayout(n = 9, edges = [[0,1],[0,4],[0,5],[1,7],[2,3],[2,4],[2,5],[3,6],[4,6],[4,7],[6,8],[7,8]])
    >>> [[8,6,3],[7,4,2],[1,0,5]]
    Explanation:
    """


Prompt:
def gcdValues(nums: List[int], queries: List[int]) -> List[int]:
    """
    You are given an integer array nums of length n and an integer array queries.
    Let gcdPairs denote an array obtained by calculating the GCD of all possible pairs (nums[i], nums[j]), where 0 <= i < j < n, and then sorting these values in ascending order.
    For each query queries[i], you need to find the element at index queries[i] in gcdPairs.
    Return an integer array answer, where answer[i] is the value at gcdPairs[queries[i]] for each query.
    The term gcd(a, b) denotes the greatest common divisor of a and b.

    Example 1:

    >>> gcdValues(nums = [2,3,4], queries = [0,2,2])
    >>> [1,2,2]
    Explanation:
    gcdPairs = [gcd(nums[0], nums[1]), gcd(nums[0], nums[2]), gcd(nums[1], nums[2])] = [1, 2, 1].
    After sorting in ascending order, gcdPairs = [1, 1, 2].
    So, the answer is [gcdPairs[queries[0]], gcdPairs[queries[1]], gcdPairs[queries[2]]] = [1, 2, 2].

    Example 2:

    >>> gcdValues(nums = [4,4,2,1], queries = [5,3,1,0])
    >>> [4,2,1,1]
    Explanation:
    gcdPairs sorted in ascending order is [1, 1, 1, 2, 2, 4].

    Example 3:

    >>> gcdValues(nums = [2,2], queries = [0,0])
    >>> [2,2]
    Explanation:
    gcdPairs = [2].
    """


Prompt:
def lastMarkedNodes(edges: List[List[int]]) -> List[int]:
    """
    There exists an undirected tree with n nodes numbered 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the tree.
    Initially, all nodes are unmarked. After every second, you mark all unmarked nodes which have at least one marked node adjacent to them.
    Return an array nodes where nodes[i] is the last node to get marked in the tree, if you mark node i at time t = 0. If nodes[i] has multiple answers for any node i, you can choose any one answer.

    Example 1:

    >>> lastMarkedNodes(edges = [[0,1],[0,2]])
    >>> [2,2,1]
    Explanation:

    For i = 0, the nodes are marked in the sequence: [0] -> [0,1,2]. Either 1 or 2 can be the answer.
    For i = 1, the nodes are marked in the sequence: [1] -> [0,1] -> [0,1,2]. Node 2 is marked last.
    For i = 2, the nodes are marked in the sequence: [2] -> [0,2] -> [0,1,2]. Node 1 is marked last.

    Example 2:

    >>> lastMarkedNodes(edges = [[0,1]])
    >>> [1,0]
    Explanation:

    For i = 0, the nodes are marked in the sequence: [0] -> [0,1].
    For i = 1, the nodes are marked in the sequence: [1] -> [0,1].

    Example 3:

    >>> lastMarkedNodes(edges = [[0,1],[0,2],[2,3],[2,4]])
    >>> [3,3,1,1,1]
    Explanation:

    For i = 0, the nodes are marked in the sequence: [0] -> [0,1,2] -> [0,1,2,3,4].
    For i = 1, the nodes are marked in the sequence: [1] -> [0,1] -> [0,1,2] -> [0,1,2,3,4].
    For i = 2, the nodes are marked in the sequence: [2] -> [0,2,3,4] -> [0,1,2,3,4].
    For i = 3, the nodes are marked in the sequence: [3] -> [2,3] -> [0,2,3,4] -> [0,1,2,3,4].
    For i = 4, the nodes are marked in the sequence: [4] -> [2,4] -> [0,2,3,4] -> [0,1,2,3,4].
    """


Prompt:
def minBitwiseArray(nums: List[int]) -> List[int]:
    """
    You are given an array nums consisting of n prime integers.
    You need to construct an array ans of length n, such that, for each index i, the bitwise OR of ans[i] and ans[i] + 1 is equal to nums[i], i.e. ans[i] OR (ans[i] + 1) == nums[i].
    Additionally, you must minimize each value of ans[i] in the resulting array.
    If it is not possible to find such a value for ans[i] that satisfies the condition, then set ans[i] = -1.

    Example 1:

    >>> minBitwiseArray(nums = [2,3,5,7])
    >>> [-1,1,4,3]
    Explanation:

    For i = 0, as there is no value for ans[0] that satisfies ans[0] OR (ans[0] + 1) = 2, so ans[0] = -1.
    For i = 1, the smallest ans[1] that satisfies ans[1] OR (ans[1] + 1) = 3 is 1, because 1 OR (1 + 1) = 3.
    For i = 2, the smallest ans[2] that satisfies ans[2] OR (ans[2] + 1) = 5 is 4, because 4 OR (4 + 1) = 5.
    For i = 3, the smallest ans[3] that satisfies ans[3] OR (ans[3] + 1) = 7 is 3, because 3 OR (3 + 1) = 7.

    Example 2:

    >>> minBitwiseArray(nums = [11,13,31])
    >>> [9,12,15]
    Explanation:

    For i = 0, the smallest ans[0] that satisfies ans[0] OR (ans[0] + 1) = 11 is 9, because 9 OR (9 + 1) = 11.
    For i = 1, the smallest ans[1] that satisfies ans[1] OR (ans[1] + 1) = 13 is 12, because 12 OR (12 + 1) = 13.
    For i = 2, the smallest ans[2] that satisfies ans[2] OR (ans[2] + 1) = 31 is 15, because 15 OR (15 + 1) = 31.
    """


Prompt:
def minBitwiseArray(nums: List[int]) -> List[int]:
    """
    You are given an array nums consisting of n prime integers.
    You need to construct an array ans of length n, such that, for each index i, the bitwise OR of ans[i] and ans[i] + 1 is equal to nums[i], i.e. ans[i] OR (ans[i] + 1) == nums[i].
    Additionally, you must minimize each value of ans[i] in the resulting array.
    If it is not possible to find such a value for ans[i] that satisfies the condition, then set ans[i] = -1.

    Example 1:

    >>> minBitwiseArray(nums = [2,3,5,7])
    >>> [-1,1,4,3]
    Explanation:

    For i = 0, as there is no value for ans[0] that satisfies ans[0] OR (ans[0] + 1) = 2, so ans[0] = -1.
    For i = 1, the smallest ans[1] that satisfies ans[1] OR (ans[1] + 1) = 3 is 1, because 1 OR (1 + 1) = 3.
    For i = 2, the smallest ans[2] that satisfies ans[2] OR (ans[2] + 1) = 5 is 4, because 4 OR (4 + 1) = 5.
    For i = 3, the smallest ans[3] that satisfies ans[3] OR (ans[3] + 1) = 7 is 3, because 3 OR (3 + 1) = 7.

    Example 2:

    >>> minBitwiseArray(nums = [11,13,31])
    >>> [9,12,15]
    Explanation:

    For i = 0, the smallest ans[0] that satisfies ans[0] OR (ans[0] + 1) = 11 is 9, because 9 OR (9 + 1) = 11.
    For i = 1, the smallest ans[1] that satisfies ans[1] OR (ans[1] + 1) = 13 is 12, because 12 OR (12 + 1) = 13.
    For i = 2, the smallest ans[2] that satisfies ans[2] OR (ans[2] + 1) = 31 is 15, because 15 OR (15 + 1) = 31.
    """


Prompt:
def maxRemovals(source: str, pattern: str, targetIndices: List[int]) -> int:
    """
    You are given a string source of size n, a string pattern that is a subsequence of source, and a sorted integer array targetIndices that contains distinct numbers in the range [0, n - 1].
    We define an operation as removing a character at an index idx from source such that:

    idx is an element of targetIndices.
    pattern remains a subsequence of source after removing the character.

    Performing an operation does not change the indices of the other characters in source. For example, if you remove 'c' from "acb", the character at index 2 would still be 'b'.
    Return the maximum number of operations that can be performed.

    Example 1:

    >>> maxRemovals(source = "abbaa", pattern = "aba", targetIndices = [0,1,2])
    >>> 1
    Explanation:
    We can't remove source[0] but we can do either of these two operations:

    Remove source[1], so that source becomes "a_baa".
    Remove source[2], so that source becomes "ab_aa".

    Example 2:

    >>> maxRemovals(source = "bcda", pattern = "d", targetIndices = [0,3])
    >>> 2
    Explanation:
    We can remove source[0] and source[3] in two operations.

    Example 3:

    >>> maxRemovals(source = "dda", pattern = "dda", targetIndices = [0,1,2])
    >>> 0
    Explanation:
    We can't remove any character from source.

    Example 4:

    >>> maxRemovals(source = "yeyeykyded", pattern = "yeyyd", targetIndices = [0,2,3,4])
    >>> 2
    Explanation:
    We can remove source[2] and source[3] in two operations.
    """


Prompt:
def numberOfWays(n: int, x: int, y: int) -> int:
    """
    You are given three integers n, x, and y.
    An event is being held for n performers. When a performer arrives, they are assigned to one of the x stages. All performers assigned to the same stage will perform together as a band, though some stages might remain empty.
    After all performances are completed, the jury will award each band a score in the range [1, y].
    Return the total number of possible ways the event can take place.
    Since the answer may be very large, return it modulo 109 + 7.
    Note that two events are considered to have been held differently if either of the following conditions is satisfied:

    Any performer is assigned a different stage.
    Any band is awarded a different score.

    Example 1:

    >>> numberOfWays(n = 1, x = 2, y = 3)
    >>> 6
    Explanation:

    There are 2 ways to assign a stage to the performer.
    The jury can award a score of either 1, 2, or 3 to the only band.

    Example 2:

    >>> numberOfWays(n = 5, x = 2, y = 1)
    >>> 32
    Explanation:

    Each performer will be assigned either stage 1 or stage 2.
    All bands will be awarded a score of 1.

    Example 3:

    >>> numberOfWays(n = 3, x = 3, y = 4)
    >>> 684
    """


Prompt:
def findXSum(nums: List[int], k: int, x: int) -> List[int]:
    """
    You are given an array nums of n integers and two integers k and x.
    The x-sum of an array is calculated by the following procedure:

    Count the occurrences of all elements in the array.
    Keep only the occurrences of the top x most frequent elements. If two elements have the same number of occurrences, the element with the bigger value is considered more frequent.
    Calculate the sum of the resulting array.

    Note that if an array has less than x distinct elements, its x-sum is the sum of the array.
    Return an integer array answer of length n - k + 1 where answer[i] is the x-sum of the subarray nums[i..i + k - 1].

    Example 1:

    >>> findXSum(nums = [1,1,2,2,3,4,2,3], k = 6, x = 2)
    >>> [6,10,12]
    Explanation:

    For subarray [1, 1, 2, 2, 3, 4], only elements 1 and 2 will be kept in the resulting array. Hence, answer[0] = 1 + 1 + 2 + 2.
    For subarray [1, 2, 2, 3, 4, 2], only elements 2 and 4 will be kept in the resulting array. Hence, answer[1] = 2 + 2 + 2 + 4. Note that 4 is kept in the array since it is bigger than 3 and 1 which occur the same number of times.
    For subarray [2, 2, 3, 4, 2, 3], only elements 2 and 3 are kept in the resulting array. Hence, answer[2] = 2 + 2 + 2 + 3 + 3.

    Example 2:

    >>> findXSum(nums = [3,8,7,8,7,5], k = 2, x = 2)
    >>> [11,15,15,15,12]
    Explanation:
    Since k == x, answer[i] is equal to the sum of the subarray nums[i..i + k - 1].
    """


Prompt:
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def kthLargestPerfectSubtree(root: Optional[TreeNode], k: int) -> int:
    """
    You are given the root of a binary tree and an integer k.
    Return an integer denoting the size of the kth largest perfect binary subtree, or -1 if it doesn't exist.
    A perfect binary tree is a tree where all leaves are on the same level, and every parent has two children.

    Example 1:

    >>> __init__(root = [5,3,6,5,2,5,7,1,8,null,null,6,8], k = 2)
    >>> 3
    Explanation:

    The roots of the perfect binary subtrees are highlighted in black. Their sizes, in non-increasing order are [3, 3, 1, 1, 1, 1, 1, 1].
    The 2nd largest size is 3.

    Example 2:

    >>> __init__(root = [1,2,3,4,5,6,7], k = 1)
    >>> 7
    Explanation:

    The sizes of the perfect binary subtrees in non-increasing order are [7, 3, 3, 1, 1, 1, 1]. The size of the largest perfect binary subtree is 7.

    Example 3:

    >>> __init__(root = [1,2,3,null,4], k = 3)
    >>> -1
    Explanation:

    The sizes of the perfect binary subtrees in non-increasing order are [1, 1]. There are fewer than 3 perfect binary subtrees.
    """


Prompt:
def countWinningSequences(s: str) -> int:
    """
    Alice and Bob are playing a fantasy battle game consisting of n rounds where they summon one of three magical creatures each round: a Fire Dragon, a Water Serpent, or an Earth Golem. In each round, players simultaneously summon their creature and are awarded points as follows:

    If one player summons a Fire Dragon and the other summons an Earth Golem, the player who summoned the Fire Dragon is awarded a point.
    If one player summons a Water Serpent and the other summons a Fire Dragon, the player who summoned the Water Serpent is awarded a point.
    If one player summons an Earth Golem and the other summons a Water Serpent, the player who summoned the Earth Golem is awarded a point.
    If both players summon the same creature, no player is awarded a point.

    You are given a string s consisting of n characters 'F', 'W', and 'E', representing the sequence of creatures Alice will summon in each round:

    If s[i] == 'F', Alice summons a Fire Dragon.
    If s[i] == 'W', Alice summons a Water Serpent.
    If s[i] == 'E', Alice summons an Earth Golem.

    Bob’s sequence of moves is unknown, but it is guaranteed that Bob will never summon the same creature in two consecutive rounds. Bob beats Alice if the total number of points awarded to Bob after n rounds is strictly greater than the points awarded to Alice.
    Return the number of distinct sequences Bob can use to beat Alice.
    Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> countWinningSequences(s = "FFF")
    >>> 3
    Explanation:
    Bob can beat Alice by making one of the following sequences of moves: "WFW", "FWF", or "WEW". Note that other winning sequences like "WWE" or "EWW" are invalid since Bob cannot make the same move twice in a row.

    Example 2:

    >>> countWinningSequences(s = "FWEFW")
    >>> 18
    Explanation:
    Bob can beat Alice by making one of the following sequences of moves: "FWFWF", "FWFWE", "FWEFE", "FWEWE", "FEFWF", "FEFWE", "FEFEW", "FEWFE", "WFEFE", "WFEWE", "WEFWF", "WEFWE", "WEFEF", "WEFEW", "WEWFW", "WEWFE", "EWFWE", or "EWEWE".
    """


Prompt:
def findXSum(nums: List[int], k: int, x: int) -> List[int]:
    """
    You are given an array nums of n integers and two integers k and x.
    The x-sum of an array is calculated by the following procedure:

    Count the occurrences of all elements in the array.
    Keep only the occurrences of the top x most frequent elements. If two elements have the same number of occurrences, the element with the bigger value is considered more frequent.
    Calculate the sum of the resulting array.

    Note that if an array has less than x distinct elements, its x-sum is the sum of the array.
    Return an integer array answer of length n - k + 1 where answer[i] is the x-sum of the subarray nums[i..i + k - 1].

    Example 1:

    >>> findXSum(nums = [1,1,2,2,3,4,2,3], k = 6, x = 2)
    >>> [6,10,12]
    Explanation:

    For subarray [1, 1, 2, 2, 3, 4], only elements 1 and 2 will be kept in the resulting array. Hence, answer[0] = 1 + 1 + 2 + 2.
    For subarray [1, 2, 2, 3, 4, 2], only elements 2 and 4 will be kept in the resulting array. Hence, answer[1] = 2 + 2 + 2 + 4. Note that 4 is kept in the array since it is bigger than 3 and 1 which occur the same number of times.
    For subarray [2, 2, 3, 4, 2, 3], only elements 2 and 3 are kept in the resulting array. Hence, answer[2] = 2 + 2 + 2 + 3 + 3.

    Example 2:

    >>> findXSum(nums = [3,8,7,8,7,5], k = 2, x = 2)
    >>> [11,15,15,15,12]
    Explanation:
    Since k == x, answer[i] is equal to the sum of the subarray nums[i..i + k - 1].
    """


Prompt:
def minConnectedGroups(intervals: List[List[int]], k: int) -> int:
    """
    You are given a 2D array intervals, where intervals[i] = [starti, endi] represents the start and the end of interval i. You are also given an integer k.
    You must add exactly one new interval [startnew, endnew] to the array such that:

    The length of the new interval, endnew - startnew, is at most k.
    After adding, the number of connected groups in intervals is minimized.

    A connected group of intervals is a maximal collection of intervals that, when considered together, cover a continuous range from the smallest point to the largest point with no gaps between them. Here are some examples:

    A group of intervals [[1, 2], [2, 5], [3, 3]] is connected because together they cover the range from 1 to 5 without any gaps.
    However, a group of intervals [[1, 2], [3, 4]] is not connected because the segment (2, 3) is not covered.

    Return the minimum number of connected groups after adding exactly one new interval to the array.

    Example 1:

    >>> minConnectedGroups(intervals = [[1,3],[5,6],[8,10]], k = 3)
    >>> 2
    Explanation:
    After adding the interval [3, 5], we have two connected groups: [[1, 3], [3, 5], [5, 6]] and [[8, 10]].

    Example 2:

    >>> minConnectedGroups(intervals = [[5,10],[1,1],[3,3]], k = 1)
    >>> 3
    Explanation:
    After adding the interval [1, 1], we have three connected groups: [[1, 1], [1, 1]], [[3, 3]], and [[5, 10]].
    """


Prompt:
def stringSequence(target: str) -> List[str]:
    """
    You are given a string target.
    Alice is going to type target on her computer using a special keyboard that has only two keys:

    Key 1 appends the character "a" to the string on the screen.
    Key 2 changes the last character of the string on the screen to its next character in the English alphabet. For example, "c" changes to "d" and "z" changes to "a".

    Note that initially there is an empty string "" on the screen, so she can only press key 1.
    Return a list of all strings that appear on the screen as Alice types target, in the order they appear, using the minimum key presses.

    Example 1:

    >>> stringSequence(target = "abc")
    >>> ["a","aa","ab","aba","abb","abc"]
    Explanation:
    The sequence of key presses done by Alice are:

    Press key 1, and the string on the screen becomes "a".
    Press key 1, and the string on the screen becomes "aa".
    Press key 2, and the string on the screen becomes "ab".
    Press key 1, and the string on the screen becomes "aba".
    Press key 2, and the string on the screen becomes "abb".
    Press key 2, and the string on the screen becomes "abc".

    Example 2:

    >>> stringSequence(target = "he")
    >>> ["a","b","c","d","e","f","g","h","ha","hb","hc","hd","he"]
    """


Prompt:
def numberOfSubstrings(s: str, k: int) -> int:
    """
    Given a string s and an integer k, return the total number of substrings of s where at least one character appears at least k times.

    Example 1:

    >>> numberOfSubstrings(s = "abacb", k = 2)
    >>> 4
    Explanation:
    The valid substrings are:

    "aba" (character 'a' appears 2 times).
    "abac" (character 'a' appears 2 times).
    "abacb" (character 'a' appears 2 times).
    "bacb" (character 'b' appears 2 times).

    Example 2:

    >>> numberOfSubstrings(s = "abcde", k = 1)
    >>> 15
    Explanation:
    All substrings are valid because every character appears at least once.
    """


Prompt:
def minOperations(nums: List[int]) -> int:
    """
    You are given an integer array nums.
    Any positive divisor of a natural number x that is strictly less than x is called a proper divisor of x. For example, 2 is a proper divisor of 4, while 6 is not a proper divisor of 6.
    You are allowed to perform an operation any number of times on nums, where in each operation you select any one element from nums and divide it by its greatest proper divisor.
    Return the minimum number of operations required to make the array non-decreasing.
    If it is not possible to make the array non-decreasing using any number of operations, return -1.

    Example 1:

    >>> minOperations(nums = [25,7])
    >>> 1
    Explanation:
    Using a single operation, 25 gets divided by 5 and nums becomes [5, 7].

    Example 2:

    >>> minOperations(nums = [7,7,6])
    >>> -1

    Example 3:

    >>> minOperations(nums = [1,1,1,1])
    >>> 0
    """


Prompt:
def findAnswer(parent: List[int], s: str) -> List[bool]:
    """
    You are given a tree rooted at node 0, consisting of n nodes numbered from 0 to n - 1. The tree is represented by an array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.
    You are also given a string s of length n, where s[i] is the character assigned to node i.
    Consider an empty string dfsStr, and define a recursive function dfs(int x) that takes a node x as a parameter and performs the following steps in order:

    Iterate over each child y of x in increasing order of their numbers, and call dfs(y).
    Add the character s[x] to the end of the string dfsStr.

    Note that dfsStr is shared across all recursive calls of dfs.
    You need to find a boolean array answer of size n, where for each index i from 0 to n - 1, you do the following:

    Empty the string dfsStr and call dfs(i).
    If the resulting string dfsStr is a palindrome, then set answer[i] to true. Otherwise, set answer[i] to false.

    Return the array answer.

    Example 1:

    >>> findAnswer(parent = [-1,0,0,1,1,2], s = "aababa")
    >>> [true,true,false,true,true,true]
    Explanation:

    Calling dfs(0) results in the string dfsStr = "abaaba", which is a palindrome.
    Calling dfs(1) results in the string dfsStr = "aba", which is a palindrome.
    Calling dfs(2) results in the string dfsStr = "ab", which is not a palindrome.
    Calling dfs(3) results in the string dfsStr = "a", which is a palindrome.
    Calling dfs(4) results in the string dfsStr = "b", which is a palindrome.
    Calling dfs(5) results in the string dfsStr = "a", which is a palindrome.

    Example 2:

    >>> findAnswer(parent = [-1,0,0,0,0], s = "aabcb")
    >>> [true,true,true,true,true]
    Explanation:
    Every call on dfs(x) results in a palindrome string.
    """


Prompt:
def numberOfSubstrings(s: str, k: int) -> int:
    """
    Given a string s and an integer k, return the total number of substrings of s where at least one character appears at least k times.

    Example 1:

    >>> numberOfSubstrings(s = "abacb", k = 2)
    >>> 4
    Explanation:
    The valid substrings are:

    "aba" (character 'a' appears 2 times).
    "abac" (character 'a' appears 2 times).
    "abacb" (character 'a' appears 2 times).
    "bacb" (character 'b' appears 2 times).

    Example 2:

    >>> numberOfSubstrings(s = "abcde", k = 1)
    >>> 15
    Explanation:
    All substrings are valid because every character appears at least once.
    """


Prompt:
def possibleStringCount(word: str) -> int:
    """
    Alice is attempting to type a specific string on her computer. However, she tends to be clumsy and may press a key for too long, resulting in a character being typed multiple times.
    Although Alice tried to focus on her typing, she is aware that she may still have done this at most once.
    You are given a string word, which represents the final output displayed on Alice's screen.
    Return the total number of possible original strings that Alice might have intended to type.

    Example 1:

    >>> possibleStringCount(word = "abbcccc")
    >>> 5
    Explanation:
    The possible strings are: "abbcccc", "abbccc", "abbcc", "abbc", and "abcccc".

    Example 2:

    >>> possibleStringCount(word = "abcd")
    >>> 1
    Explanation:
    The only possible string is "abcd".

    Example 3:

    >>> possibleStringCount(word = "aaaa")
    >>> 4
    """


Prompt:
def findSubtreeSizes(parent: List[int], s: str) -> List[int]:
    """
    You are given a tree rooted at node 0 that consists of n nodes numbered from 0 to n - 1. The tree is represented by an array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.
    You are also given a string s of length n, where s[i] is the character assigned to node i.
    We make the following changes on the tree one time simultaneously for all nodes x from 1 to n - 1:

    Find the closest node y to node x such that y is an ancestor of x, and s[x] == s[y].
    If node y does not exist, do nothing.
    Otherwise, remove the edge between x and its current parent and make node y the new parent of x by adding an edge between them.

    Return an array answer of size n where answer[i] is the size of the subtree rooted at node i in the final tree.

    Example 1:

    >>> findSubtreeSizes(parent = [-1,0,0,1,1,1], s = "abaabc")
    >>> [6,3,1,1,1,1]
    Explanation:

    The parent of node 3 will change from node 1 to node 0.

    Example 2:

    >>> findSubtreeSizes(parent = [-1,0,4,0,1], s = "abbba")
    >>> [5,2,1,1,1]
    Explanation:

    The following changes will happen at the same time:

    The parent of node 4 will change from node 1 to node 0.
    The parent of node 2 will change from node 4 to node 1.
    """


Prompt:
def maxScore(n: int, k: int, stayScore: List[List[int]], travelScore: List[List[int]]) -> int:
    """
    You are given two integers, n and k, along with two 2D integer arrays, stayScore and travelScore.
    A tourist is visiting a country with n cities, where each city is directly connected to every other city. The tourist's journey consists of exactly k 0-indexed days, and they can choose any city as their starting point.
    Each day, the tourist has two choices:

    Stay in the current city: If the tourist stays in their current city curr during day i, they will earn stayScore[i][curr] points.
    Move to another city: If the tourist moves from their current city curr to city dest, they will earn travelScore[curr][dest] points.

    Return the maximum possible points the tourist can earn.

    Example 1:

    >>> maxScore(n = 2, k = 1, stayScore = [[2,3]], travelScore = [[0,2],[1,0]])
    >>> 3
    Explanation:
    The tourist earns the maximum number of points by starting in city 1 and staying in that city.

    Example 2:

    >>> maxScore(n = 3, k = 2, stayScore = [[3,4,2],[2,1,2]], travelScore = [[0,2,1],[2,0,4],[3,2,0]])
    >>> 8
    Explanation:
    The tourist earns the maximum number of points by starting in city 1, staying in that city on day 0, and traveling to city 2 on day 1.
    """


Prompt:
def possibleStringCount(word: str, k: int) -> int:
    """
    Alice is attempting to type a specific string on her computer. However, she tends to be clumsy and may press a key for too long, resulting in a character being typed multiple times.
    You are given a string word, which represents the final output displayed on Alice's screen. You are also given a positive integer k.
    Return the total number of possible original strings that Alice might have intended to type, if she was trying to type a string of size at least k.
    Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> possibleStringCount(word = "aabbccdd", k = 7)
    >>> 5
    Explanation:
    The possible strings are: "aabbccdd", "aabbccd", "aabbcdd", "aabccdd", and "abbccdd".

    Example 2:

    >>> possibleStringCount(word = "aabbccdd", k = 8)
    >>> 1
    Explanation:
    The only possible string is "aabbccdd".

    Example 3:

    >>> possibleStringCount(word = "aaabbb", k = 3)
    >>> 8
    """


Prompt:
def maxScore(nums: List[int]) -> int:
    """
    You are given an integer array nums.
    The factor score of an array is defined as the product of the LCM and GCD of all elements of that array.
    Return the maximum factor score of nums after removing at most one element from it.
    Note that both the LCM and GCD of a single number are the number itself, and the factor score of an empty array is 0.

    Example 1:

    >>> maxScore(nums = [2,4,8,16])
    >>> 64
    Explanation:
    On removing 2, the GCD of the rest of the elements is 4 while the LCM is 16, which gives a maximum factor score of 4 * 16 = 64.

    Example 2:

    >>> maxScore(nums = [1,2,3,4,5])
    >>> 60
    Explanation:
    The maximum factor score of 60 can be obtained without removing any elements.

    Example 3:

    >>> maxScore(nums = [3])
    >>> 9
    """


Prompt:
def lengthAfterTransformations(s: str, t: int) -> int:
    """
    You are given a string s and an integer t, representing the number of transformations to perform. In one transformation, every character in s is replaced according to the following rules:

    If the character is 'z', replace it with the string "ab".
    Otherwise, replace it with the next character in the alphabet. For example, 'a' is replaced with 'b', 'b' is replaced with 'c', and so on.

    Return the length of the resulting string after exactly t transformations.
    Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> lengthAfterTransformations(s = "abcyy", t = 2)
    >>> 7
    Explanation:

    First Transformation (t = 1):

    'a' becomes 'b'
    'b' becomes 'c'
    'c' becomes 'd'
    'y' becomes 'z'
    'y' becomes 'z'
    String after the first transformation: "bcdzz"

    Second Transformation (t = 2):

    'b' becomes 'c'
    'c' becomes 'd'
    'd' becomes 'e'
    'z' becomes "ab"
    'z' becomes "ab"
    String after the second transformation: "cdeabab"

    Final Length of the string: The string is "cdeabab", which has 7 characters.

    Example 2:

    >>> lengthAfterTransformations(s = "azbk", t = 1)
    >>> 5
    Explanation:

    First Transformation (t = 1):

    'a' becomes 'b'
    'z' becomes "ab"
    'b' becomes 'c'
    'k' becomes 'l'
    String after the first transformation: "babcl"

    Final Length of the string: The string is "babcl", which has 5 characters.
    """


Prompt:
def subsequencePairCount(nums: List[int]) -> int:
    """
    You are given an integer array nums.
    Your task is to find the number of pairs of non-empty subsequences (seq1, seq2) of nums that satisfy the following conditions:

    The subsequences seq1 and seq2 are disjoint, meaning no index of nums is common between them.
    The GCD of the elements of seq1 is equal to the GCD of the elements of seq2.

    Return the total number of such pairs.
    Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> subsequencePairCount(nums = [1,2,3,4])
    >>> 10
    Explanation:
    The subsequence pairs which have the GCD of their elements equal to 1 are:

    ([1, 2, 3, 4], [1, 2, 3, 4])
    ([1, 2, 3, 4], [1, 2, 3, 4])
    ([1, 2, 3, 4], [1, 2, 3, 4])
    ([1, 2, 3, 4], [1, 2, 3, 4])
    ([1, 2, 3, 4], [1, 2, 3, 4])
    ([1, 2, 3, 4], [1, 2, 3, 4])
    ([1, 2, 3, 4], [1, 2, 3, 4])
    ([1, 2, 3, 4], [1, 2, 3, 4])
    ([1, 2, 3, 4], [1, 2, 3, 4])
    ([1, 2, 3, 4], [1, 2, 3, 4])

    Example 2:

    >>> subsequencePairCount(nums = [10,20,30])
    >>> 2
    Explanation:
    The subsequence pairs which have the GCD of their elements equal to 10 are:

    ([10, 20, 30], [10, 20, 30])
    ([10, 20, 30], [10, 20, 30])

    Example 3:

    >>> subsequencePairCount(nums = [1,1,1,1])
    >>> 50
    """