Prompt:
from typing import List
def minCost(n: int, cost: List[List[int]]) -> int:
    """
    You are given an even integer n representing the number of houses arranged in a straight line, and a 2D array cost of size n x 3, where cost[i][j] represents the cost of painting house i with color j + 1.
    The houses will look beautiful if they satisfy the following conditions:

    No two adjacent houses are painted the same color.
    Houses equidistant from the ends of the row are not painted the same color. For example, if n = 6, houses at positions (0, 5), (1, 4), and (2, 3) are considered equidistant.

    Return the minimum cost to paint the houses such that they look beautiful.

    Example 1:

    >>> minCost(n = 4, cost = [[3,5,7],[6,2,9],[4,8,1],[7,3,5]])
    >>> 9
    Explanation:
    The optimal painting sequence is [1, 2, 3, 2] with corresponding costs [3, 2, 1, 3]. This satisfies the following conditions:

    No adjacent houses have the same color.
    Houses at positions 0 and 3 (equidistant from the ends) are not painted the same color (1 != 2).
    Houses at positions 1 and 2 (equidistant from the ends) are not painted the same color (2 != 3).

    The minimum cost to paint the houses so that they look beautiful is 3 + 2 + 1 + 3 = 9.

    Example 2:

    >>> minCost(n = 6, cost = [[2,4,6],[5,3,8],[7,1,9],[4,6,2],[3,5,7],[8,2,4]])
    >>> 18
    Explanation:
    The optimal painting sequence is [1, 3, 2, 3, 1, 2] with corresponding costs [2, 8, 1, 2, 3, 2]. This satisfies the following conditions:

    No adjacent houses have the same color.
    Houses at positions 0 and 5 (equidistant from the ends) are not painted the same color (1 != 2).
    Houses at positions 1 and 4 (equidistant from the ends) are not painted the same color (3 != 1).
    Houses at positions 2 and 3 (equidistant from the ends) are not painted the same color (2 != 3).

    The minimum cost to paint the houses so that they look beautiful is 2 + 8 + 1 + 2 + 3 + 2 = 18.
    """


Prompt:
from typing import List
def minUnlockedIndices(nums: List[int], locked: List[int]) -> int:
    """
    You are given an array nums consisting of integers between 1 and 3, and a binary array locked of the same size.
    We consider nums sortable if it can be sorted using adjacent swaps, where a swap between two indices i and i + 1 is allowed if nums[i] - nums[i + 1] == 1 and locked[i] == 0.
    In one operation, you can unlock any index i by setting locked[i] to 0.
    Return the minimum number of operations needed to make nums sortable. If it is not possible to make nums sortable, return -1.

    Example 1:

    >>> minUnlockedIndices(nums = [1,2,1,2,3,2], locked = [1,0,1,1,0,1])
    >>> 0
    Explanation:
    We can sort nums using the following swaps:

    swap indices 1 with 2
    swap indices 4 with 5

    So, there is no need to unlock any index.

    Example 2:

    >>> minUnlockedIndices(nums = [1,2,1,1,3,2,2], locked = [1,0,1,1,0,1,0])
    >>> 2
    Explanation:
    If we unlock indices 2 and 5, we can sort nums using the following swaps:

    swap indices 1 with 2
    swap indices 2 with 3
    swap indices 4 with 5
    swap indices 5 with 6

    Example 3:

    >>> minUnlockedIndices(nums = [1,2,1,2,3,2,1], locked = [0,0,0,0,0,0,0])
    >>> -1
    Explanation:
    Even if all indices are unlocked, it can be shown that nums is not sortable.
    """


Prompt:
from typing import List
def countPartitions(nums: List[int]) -> int:
    """
    You are given an integer array nums of length n.
    A partition is defined as an index i where 0 <= i < n - 1, splitting the array into two non-empty subarrays such that:

    Left subarray contains indices [0, i].
    Right subarray contains indices [i + 1, n - 1].

    Return the number of partitions where the difference between the sum of the left and right subarrays is even.

    Example 1:

    >>> countPartitions(nums = [10,10,3,7,6])
    >>> 4
    Explanation:
    The 4 partitions are:

    [10], [10, 3, 7, 6] with a sum difference of 10 - 26 = -16, which is even.
    [10, 10], [3, 7, 6] with a sum difference of 20 - 16 = 4, which is even.
    [10, 10, 3], [7, 6] with a sum difference of 23 - 13 = 10, which is even.
    [10, 10, 3, 7], [6] with a sum difference of 30 - 6 = 24, which is even.

    Example 2:

    >>> countPartitions(nums = [1,2,2])
    >>> 0
    Explanation:
    No partition results in an even sum difference.

    Example 3:

    >>> countPartitions(nums = [2,4,6,8])
    >>> 3
    Explanation:
    All partitions result in an even sum difference.
    """


Prompt:
from typing import List
def countMentions(numberOfUsers: int, events: List[List[str]]) -> List[int]:
    """
    You are given an integer numberOfUsers representing the total number of users and an array events of size n x 3.
    Each events[i] can be either of the following two types:

    Message Event: ["MESSAGE", "timestampi", "mentions_stringi"]

    This event indicates that a set of users was mentioned in a message at timestampi.
    The mentions_stringi string can contain one of the following tokens:

    id: where  is an integer in range [0,numberOfUsers - 1]. There can be multiple ids separated by a single whitespace and may contain duplicates. This can mention even the offline users.
    ALL: mentions all users.
    HERE: mentions all online users.

    Offline Event: ["OFFLINE", "timestampi", "idi"]

    This event indicates that the user idi had become offline at timestampi for 60 time units. The user will automatically be online again at time timestampi + 60.

    Return an array mentions where mentions[i] represents the number of mentions the user with id i has across all MESSAGE events.
    All users are initially online, and if a user goes offline or comes back online, their status change is processed before handling any message event that occurs at the same timestamp.
    Note that a user can be mentioned multiple times in a single message event, and each mention should be counted separately.

    Example 1:

    >>> countMentions(numberOfUsers = 2, events = [["MESSAGE","10","id1 id0"],["OFFLINE","11","0"],["MESSAGE","71","HERE"]])
    >>> [2,2]
    Explanation:
    Initially, all users are online.
    At timestamp 10, id1 and id0 are mentioned. mentions = [1,1]
    At timestamp 11, id0 goes offline.
    At timestamp 71, id0 comes back online and "HERE" is mentioned. mentions = [2,2]

    Example 2:

    >>> countMentions(numberOfUsers = 2, events = [["MESSAGE","10","id1 id0"],["OFFLINE","11","0"],["MESSAGE","12","ALL"]])
    >>> [2,2]
    Explanation:
    Initially, all users are online.
    At timestamp 10, id1 and id0 are mentioned. mentions = [1,1]
    At timestamp 11, id0 goes offline.
    At timestamp 12, "ALL" is mentioned. This includes offline users, so both id0 and id1 are mentioned. mentions = [2,2]

    Example 3:

    >>> countMentions(numberOfUsers = 2, events = [["OFFLINE","10","0"],["MESSAGE","12","HERE"]])
    >>> [0,1]
    Explanation:
    Initially, all users are online.
    At timestamp 10, id0 goes offline.
    At timestamp 12, "HERE" is mentioned. Because id0 is still offline, they will not be mentioned. mentions = [0,1]
    """


Prompt:
from typing import List
def maxFrequency(nums: List[int], k: int) -> int:
    """
    You are given an array nums of length n. You are also given an integer k.
    You perform the following operation on nums once:

    Select a subarray nums[i..j] where 0 <= i <= j <= n - 1.
    Select an integer x and add x to all the elements in nums[i..j].

    Find the maximum frequency of the value k after the operation.

    Example 1:

    >>> maxFrequency(nums = [1,2,3,4,5,6], k = 1)
    >>> 2
    Explanation:
    After adding -5 to nums[2..5], 1 has a frequency of 2 in [1, 2, -2, -1, 0, 1].

    Example 2:

    >>> maxFrequency(nums = [10,2,3,4,5,5,4,3,2,2], k = 10)
    >>> 4
    Explanation:
    After adding 8 to nums[1..9], 10 has a frequency of 4 in [10, 10, 11, 12, 13, 13, 12, 11, 10, 10].
    """


Prompt:
from typing import List
def supersequences(words: List[str]) -> List[List[int]]:
    """
    You are given an array of strings words. Find all shortest common supersequences (SCS) of words that are not permutations of each other.
    A shortest common supersequence is a string of minimum length that contains each string in words as a subsequence.
    Return a 2D array of integers freqs that represent all the SCSs. Each freqs[i] is an array of size 26, representing the frequency of each letter in the lowercase English alphabet for a single SCS. You may return the frequency arrays in any order.

    Example 1:

    >>> supersequences(words = ["ab","ba"])
    >>> [[1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]
    Explanation:
    The two SCSs are "aba" and "bab". The output is the letter frequencies for each one.

    Example 2:

    >>> supersequences(words = ["aa","ac"])
    >>> [[2,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]
    Explanation:
    The two SCSs are "aac" and "aca". Since they are permutations of each other, keep only "aac".

    Example 3:

    >>> supersequences(words = ["aa","bb","cc"])
    >>> [[2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]
    Explanation:
    "aabbcc" and all its permutations are SCSs.
    """


Prompt:
from typing import List
def permute(n: int) -> List[List[int]]:
    """
    Given an integer n, an alternating permutation is a permutation of the first n positive integers such that no two adjacent elements are both odd or both even.
    Return all such alternating permutations sorted in lexicographical order.

    Example 1:

    >>> permute(n = 4)
    >>> [[1,2,3,4],[1,4,3,2],[2,1,4,3],[2,3,4,1],[3,2,1,4],[3,4,1,2],[4,1,2,3],[4,3,2,1]]

    Example 2:

    >>> permute(n = 2)
    >>> [[1,2],[2,1]]

    Example 3:

    >>> permute(n = 3)
    >>> [[1,2,3],[3,2,1]]
    """


Prompt:
def findValidPair(s: str) -> str:
    """
    You are given a string s consisting only of digits. A valid pair is defined as two adjacent digits in s such that:

    The first digit is not equal to the second.
    Each digit in the pair appears in s exactly as many times as its numeric value.

    Return the first valid pair found in the string s when traversing from left to right. If no valid pair exists, return an empty string.

    Example 1:

    >>> findValidPair(s = "2523533")
    >>> "23"
    Explanation:
    Digit '2' appears 2 times and digit '3' appears 3 times. Each digit in the pair "23" appears in s exactly as many times as its numeric value. Hence, the output is "23".

    Example 2:

    >>> findValidPair(s = "221")
    >>> "21"
    Explanation:
    Digit '2' appears 2 times and digit '1' appears 1 time. Hence, the output is "21".

    Example 3:

    >>> findValidPair(s = "22")
    >>> ""
    Explanation:
    There are no valid adjacent pairs.
    """


Prompt:
from typing import List
def maxFreeTime(eventTime: int, k: int, startTime: List[int], endTime: List[int]) -> int:
    """
    You are given an integer eventTime denoting the duration of an event, where the event occurs from time t = 0 to time t = eventTime.
    You are also given two integer arrays startTime and endTime, each of length n. These represent the start and end time of n non-overlapping meetings, where the ith meeting occurs during the time [startTime[i], endTime[i]].
    You can reschedule at most k meetings by moving their start time while maintaining the same duration, to maximize the longest continuous period of free time during the event.
    The relative order of all the meetings should stay the same and they should remain non-overlapping.
    Return the maximum amount of free time possible after rearranging the meetings.
    Note that the meetings can not be rescheduled to a time outside the event.

    Example 1:

    >>> maxFreeTime(eventTime = 5, k = 1, startTime = [1,3], endTime = [2,5])
    >>> 2
    Explanation:

    Reschedule the meeting at [1, 2] to [2, 3], leaving no meetings during the time [0, 2].

    Example 2:

    >>> maxFreeTime(eventTime = 10, k = 1, startTime = [0,2,9], endTime = [1,4,10])
    >>> 6
    Explanation:

    Reschedule the meeting at [2, 4] to [1, 3], leaving no meetings during the time [3, 9].

    Example 3:

    >>> maxFreeTime(eventTime = 5, k = 2, startTime = [0,1,2,3,4], endTime = [1,2,3,4,5])
    >>> 0
    Explanation:
    There is no time during the event not occupied by meetings.
    """


Prompt:
from typing import List
def maxFreeTime(eventTime: int, startTime: List[int], endTime: List[int]) -> int:
    """
    You are given an integer eventTime denoting the duration of an event. You are also given two integer arrays startTime and endTime, each of length n.
    These represent the start and end times of n non-overlapping meetings that occur during the event between time t = 0 and time t = eventTime, where the ith meeting occurs during the time [startTime[i], endTime[i]].
    You can reschedule at most one meeting by moving its start time while maintaining the same duration, such that the meetings remain non-overlapping, to maximize the longest continuous period of free time during the event.
    Return the maximum amount of free time possible after rearranging the meetings.
    Note that the meetings can not be rescheduled to a time outside the event and they should remain non-overlapping.
    Note: In this version, it is valid for the relative ordering of the meetings to change after rescheduling one meeting.

    Example 1:

    >>> maxFreeTime(eventTime = 5, startTime = [1,3], endTime = [2,5])
    >>> 2
    Explanation:

    Reschedule the meeting at [1, 2] to [2, 3], leaving no meetings during the time [0, 2].

    Example 2:

    >>> maxFreeTime(eventTime = 10, startTime = [0,7,9], endTime = [1,8,10])
    >>> 7
    Explanation:

    Reschedule the meeting at [0, 1] to [8, 9], leaving no meetings during the time [0, 7].

    Example 3:

    >>> maxFreeTime(eventTime = 10, startTime = [0,3,7,9], endTime = [1,4,8,10])
    >>> 6
    Explanation:

    Reschedule the meeting at [3, 4] to [8, 9], leaving no meetings during the time [1, 7].

    Example 4:

    >>> maxFreeTime(eventTime = 5, startTime = [0,1,2,3,4], endTime = [1,2,3,4,5])
    >>> 0
    Explanation:
    There is no time during the event not occupied by meetings.
    """


Prompt:
def minCostGoodCaption(caption: str) -> str:
    """
    You are given a string caption of length n. A good caption is a string where every character appears in groups of at least 3 consecutive occurrences.
    For example:

    "aaabbb" and "aaaaccc" are good captions.
    "aabbb" and "ccccd" are not good captions.

    You can perform the following operation any number of times:
    Choose an index i (where 0 <= i < n) and change the character at that index to either:

    The character immediately before it in the alphabet (if caption[i] != 'a').
    The character immediately after it in the alphabet (if caption[i] != 'z').

    Your task is to convert the given caption into a good caption using the minimum number of operations, and return it. If there are multiple possible good captions, return the lexicographically smallest one among them. If it is impossible to create a good caption, return an empty string "".

    Example 1:

    >>> minCostGoodCaption(caption = "cdcd")
    >>> "cccc"
    Explanation:
    It can be shown that the given caption cannot be transformed into a good caption with fewer than 2 operations. The possible good captions that can be created using exactly 2 operations are:

    "dddd": Change caption[0] and caption[2] to their next character 'd'.
    "cccc": Change caption[1] and caption[3] to their previous character 'c'.

    Since "cccc" is lexicographically smaller than "dddd", return "cccc".

    Example 2:

    >>> minCostGoodCaption(caption = "aca")
    >>> "aaa"
    Explanation:
    It can be proven that the given caption requires at least 2 operations to be transformed into a good caption. The only good caption that can be obtained with exactly 2 operations is as follows:

    Operation 1: Change caption[1] to 'b'. caption = "aba".
    Operation 2: Change caption[1] to 'a'. caption = "aaa".

    Thus, return "aaa".

    Example 3:

    >>> minCostGoodCaption(caption = "bc")
    >>> ""
    Explanation:
    It can be shown that the given caption cannot be converted to a good caption by using any number of operations.
    """


Prompt:
def maxDifference(s: str) -> int:
    """
    You are given a string s consisting of lowercase English letters. Your task is to find the maximum difference between the frequency of two characters in the string such that:

    One of the characters has an even frequency in the string.
    The other character has an odd frequency in the string.

    Return the maximum difference, calculated as the frequency of the character with an odd frequency minus the frequency of the character with an even frequency.

    Example 1:

    >>> maxDifference(s = "aaaaabbc")
    >>> 3
    Explanation:

    The character 'a' has an odd frequency of 5, and 'b' has an even frequency of 2.
    The maximum difference is 5 - 2 = 3.

    Example 2:

    >>> maxDifference(s = "abcabcab")
    >>> 1
    Explanation:

    The character 'a' has an odd frequency of 3, and 'c' has an even frequency of 2.
    The maximum difference is 3 - 2 = 1.
    """


Prompt:
def maxDistance(s: str, k: int) -> int:
    """
    You are given a string s consisting of the characters 'N', 'S', 'E', and 'W', where s[i] indicates movements in an infinite grid:

    'N' : Move north by 1 unit.
    'S' : Move south by 1 unit.
    'E' : Move east by 1 unit.
    'W' : Move west by 1 unit.

    Initially, you are at the origin (0, 0). You can change at most k characters to any of the four directions.
    Find the maximum Manhattan distance from the origin that can be achieved at any time while performing the movements in order.
    The Manhattan Distance between two cells (xi, yi) and (xj, yj) is |xi - xj| + |yi - yj|.

    Example 1:

    >>> maxDistance(s = "NWSE", k = 1)
    >>> 3
    Explanation:
    Change s[2] from 'S' to 'N'. The string s becomes "NWNE".

    Movement
    Position (x, y)
    Manhattan Distance
    Maximum

    s[0] == 'N'
    (0, 1)
    0 + 1 = 1
    1

    s[1] == 'W'
    (-1, 1)
    1 + 1 = 2
    2

    s[2] == 'N'
    (-1, 2)
    1 + 2 = 3
    3

    s[3] == 'E'
    (0, 2)
    0 + 2 = 2
    3

    The maximum Manhattan distance from the origin that can be achieved is 3. Hence, 3 is the output.

    Example 2:

    >>> maxDistance(s = "NSWWEW", k = 3)
    >>> 6
    Explanation:
    Change s[1] from 'S' to 'N', and s[4] from 'E' to 'W'. The string s becomes "NNWWWW".
    The maximum Manhattan distance from the origin that can be achieved is 6. Hence, 6 is the output.
    """


Prompt:
from typing import List
def minimumIncrements(nums: List[int], target: List[int]) -> int:
    """
    You are given two arrays, nums and target.
    In a single operation, you may increment any element of nums by 1.
    Return the minimum number of operations required so that each element in target has at least one multiple in nums.

    Example 1:

    >>> minimumIncrements(nums = [1,2,3], target = [4])
    >>> 1
    Explanation:
    The minimum number of operations required to satisfy the condition is 1.

    Increment 3 to 4 with just one operation, making 4 a multiple of itself.

    Example 2:

    >>> minimumIncrements(nums = [8,4], target = [10,5])
    >>> 2
    Explanation:
    The minimum number of operations required to satisfy the condition is 2.

    Increment 8 to 10 with 2 operations, making 10 a multiple of both 5 and 10.

    Example 3:

    >>> minimumIncrements(nums = [7,9,10], target = [7])
    >>> 0
    Explanation:
    Target 7 already has a multiple in nums, so no additional operations are needed.
    """


Prompt:
def maxDifference(s: str, k: int) -> int:
    """
    You are given a string s and an integer k. Your task is to find the maximum difference between the frequency of two characters, freq[a] - freq[b], in a substring subs of s, such that:

    subs has a size of at least k.
    Character a has an odd frequency in subs.
    Character b has an even frequency in subs.

    Return the maximum difference.
    Note that subs can contain more than 2 distinct characters.

    Example 1:

    >>> maxDifference(s = "12233", k = 4)
    >>> -1
    Explanation:
    For the substring "12233", the frequency of '1' is 1 and the frequency of '3' is 2. The difference is 1 - 2 = -1.

    Example 2:

    >>> maxDifference(s = "1122211", k = 3)
    >>> 1
    Explanation:
    For the substring "11222", the frequency of '2' is 3 and the frequency of '1' is 2. The difference is 3 - 2 = 1.

    Example 3:

    >>> maxDifference(s = "110", k = 3)
    >>> -1
    """


Prompt:
from typing import List
def sortMatrix(grid: List[List[int]]) -> List[List[int]]:
    """
    You are given an n x n square matrix of integers grid. Return the matrix such that:

    The diagonals in the bottom-left triangle (including the middle diagonal) are sorted in non-increasing order.
    The diagonals in the top-right triangle are sorted in non-decreasing order.

    Example 1:

    >>> sortMatrix(grid = [[1,7,3],[9,8,2],[4,5,6]])
    >>> [[8,2,3],[9,6,7],[4,5,1]]
    Explanation:

    The diagonals with a black arrow (bottom-left triangle) should be sorted in non-increasing order:

    [1, 8, 6] becomes [8, 6, 1].
    [9, 5] and [4] remain unchanged.

    The diagonals with a blue arrow (top-right triangle) should be sorted in non-decreasing order:

    [7, 2] becomes [2, 7].
    [3] remains unchanged.

    Example 2:

    >>> sortMatrix(grid = [[0,1],[1,2]])
    >>> [[2,1],[1,0]]
    Explanation:

    The diagonals with a black arrow must be non-increasing, so [0, 2] is changed to [2, 0]. The other diagonals are already in the correct order.

    Example 3:

    >>> sortMatrix(grid = [[1]])
    >>> [[1]]
    Explanation:
    Diagonals with exactly one element are already in order, so no changes are needed.
    """


Prompt:
from typing import List
def assignElements(groups: List[int], elements: List[int]) -> List[int]:
    """
    You are given an integer array groups, where groups[i] represents the size of the ith group. You are also given an integer array elements.
    Your task is to assign one element to each group based on the following rules:

    An element at index j can be assigned to a group i if groups[i] is divisible by elements[j].
    If there are multiple elements that can be assigned, assign the element with the smallest index j.
    If no element satisfies the condition for a group, assign -1 to that group.

    Return an integer array assigned, where assigned[i] is the index of the element chosen for group i, or -1 if no suitable element exists.
    Note: An element may be assigned to more than one group.

    Example 1:

    >>> assignElements(groups = [8,4,3,2,4], elements = [4,2])
    >>> [0,0,-1,1,0]
    Explanation:

    elements[0] = 4 is assigned to groups 0, 1, and 4.
    elements[1] = 2 is assigned to group 3.
    Group 2 cannot be assigned any element.

    Example 2:

    >>> assignElements(groups = [2,3,5,7], elements = [5,3,3])
    >>> [-1,1,0,-1]
    Explanation:

    elements[1] = 3 is assigned to group 1.
    elements[0] = 5 is assigned to group 2.
    Groups 0 and 3 cannot be assigned any element.

    Example 3:

    >>> assignElements(groups = [10,21,30,41], elements = [2,1])
    >>> [0,1,0,1]
    Explanation:
    elements[0] = 2 is assigned to the groups with even values, and elements[1] = 1 is assigned to the groups with odd values.
    """


Prompt:
def countSubstrings(s: str) -> int:
    """
    You are given a string s consisting of digits.
    Return the number of substrings of s divisible by their non-zero last digit.
    Note: A substring may contain leading zeros.

    Example 1:

    >>> countSubstrings(s = "12936")
    >>> 11
    Explanation:
    Substrings "29", "129", "293" and "2936" are not divisible by their last digit. There are 15 substrings in total, so the answer is 15 - 4 = 11.

    Example 2:

    >>> countSubstrings(s = "5701283")
    >>> 18
    Explanation:
    Substrings "01", "12", "701", "012", "128", "5701", "7012", "0128", "57012", "70128", "570128", and "701283" are all divisible by their last digit. Additionally, all substrings that are just 1 non-zero digit are divisible by themselves. Since there are 6 such digits, the answer is 12 + 6 = 18.

    Example 3:

    >>> countSubstrings(s = "1010101010")
    >>> 25
    Explanation:
    Only substrings that end with digit '1' are divisible by their last digit. There are 25 such substrings.
    """


Prompt:
from typing import List
def maxScore(points: List[int], m: int) -> int:
    """
    You are given an array points of size n and an integer m. There is another array gameScore of size n, where gameScore[i] represents the score achieved at the ith game. Initially, gameScore[i] == 0 for all i.
    You start at index -1, which is outside the array (before the first position at index 0). You can make at most m moves. In each move, you can either:

    Increase the index by 1 and add points[i] to gameScore[i].
    Decrease the index by 1 and add points[i] to gameScore[i].

    Note that the index must always remain within the bounds of the array after the first move.
    Return the maximum possible minimum value in gameScore after at most m moves.

    Example 1:

    >>> maxScore(points = [2,4], m = 3)
    >>> 4
    Explanation:
    Initially, index i = -1 and gameScore = [0, 0].

    Move
    Index
    gameScore

    Increase i
    0
    [2, 0]

    Increase i
    1
    [2, 4]

    Decrease i
    0
    [4, 4]

    The minimum value in gameScore is 4, and this is the maximum possible minimum among all configurations. Hence, 4 is the output.

    Example 2:

    >>> maxScore(points = [1,2,3], m = 5)
    >>> 2
    Explanation:
    Initially, index i = -1 and gameScore = [0, 0, 0].

    Move
    Index
    gameScore

    Increase i
    0
    [1, 0, 0]

    Increase i
    1
    [1, 2, 0]

    Decrease i
    0
    [2, 2, 0]

    Increase i
    1
    [2, 4, 0]

    Increase i
    2
    [2, 4, 3]

    The minimum value in gameScore is 2, and this is the maximum possible minimum among all configurations. Hence, 2 is the output.
    """


Prompt:
from typing import List
def maxStudentsOnBench(students: List[List[int]]) -> int:
    """
    You are given a 2D integer array of student data students, where students[i] = [student_id, bench_id] represents that student student_id is sitting on the bench bench_id.
    Return the maximum number of unique students sitting on any single bench. If no students are present, return 0.
    Note: A student can appear multiple times on the same bench in the input, but they should be counted only once per bench.

    Example 1:

    >>> maxStudentsOnBench(students = [[1,2],[2,2],[3,3],[1,3],[2,3]])
    >>> 3
    Explanation:

    Bench 2 has two unique students: [1, 2].
    Bench 3 has three unique students: [1, 2, 3].
    The maximum number of unique students on a single bench is 3.

    Example 2:

    >>> maxStudentsOnBench(students = [[1,1],[2,1],[3,1],[4,2],[5,2]])
    >>> 3
    Explanation:

    Bench 1 has three unique students: [1, 2, 3].
    Bench 2 has two unique students: [4, 5].
    The maximum number of unique students on a single bench is 3.

    Example 3:

    >>> maxStudentsOnBench(students = [[1,1],[1,1]])
    >>> 1
    Explanation:

    The maximum number of unique students on a single bench is 1.

    Example 4:

    >>> maxStudentsOnBench(students = [])
    >>> 0
    Explanation:

    Since no students are present, the output is 0.
    """


Prompt:
from typing import List
def sumOfGoodNumbers(nums: List[int], k: int) -> int:
    """
    Given an array of integers nums and an integer k, an element nums[i] is considered good if it is strictly greater than the elements at indices i - k and i + k (if those indices exist). If neither of these indices exists, nums[i] is still considered good.
    Return the sum of all the good elements in the array.

    Example 1:

    >>> sumOfGoodNumbers(nums = [1,3,2,1,5,4], k = 2)
    >>> 12
    Explanation:
    The good numbers are nums[1] = 3, nums[4] = 5, and nums[5] = 4 because they are strictly greater than the numbers at indices i - k and i + k.

    Example 2:

    >>> sumOfGoodNumbers(nums = [2,1], k = 1)
    >>> 2
    Explanation:
    The only good number is nums[0] = 2 because it is strictly greater than nums[1].
    """


Prompt:
from typing import Any, List
def separateSquares(squares: List[List[int]]) -> float:
    """
    You are given a 2D integer array squares. Each squares[i] = [xi, yi, li] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.
    Find the minimum y-coordinate value of a horizontal line such that the total area of the squares above the line equals the total area of the squares below the line.
    Answers within 10-5 of the actual answer will be accepted.
    Note: Squares may overlap. Overlapping areas should be counted multiple times.

    Example 1:

    >>> separateSquares(squares = [[0,0,1],[2,2,1]])
    >>> 1.00000
    Explanation:

    Any horizontal line between y = 1 and y = 2 will have 1 square unit above it and 1 square unit below it. The lowest option is 1.

    Example 2:

    >>> separateSquares(squares = [[0,0,2],[1,1,1]])
    >>> 1.16667
    Explanation:

    The areas are:

    Below the line: 7/6 * 2 (Red) + 1/6 (Blue) = 15/6 = 2.5.
    Above the line: 5/6 * 2 (Red) + 5/6 (Blue) = 15/6 = 2.5.

    Since the areas above and below the line are equal, the output is 7/6 = 1.16667.
    """


Prompt:
from typing import Any, List
def separateSquares(squares: List[List[int]]) -> float:
    """
    You are given a 2D integer array squares. Each squares[i] = [xi, yi, li] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.
    Find the minimum y-coordinate value of a horizontal line such that the total area covered by squares above the line equals the total area covered by squares below the line.
    Answers within 10-5 of the actual answer will be accepted.
    Note: Squares may overlap. Overlapping areas should be counted only once in this version.

    Example 1:

    >>> separateSquares(squares = [[0,0,1],[2,2,1]])
    >>> 1.00000
    Explanation:

    Any horizontal line between y = 1 and y = 2 results in an equal split, with 1 square unit above and 1 square unit below. The minimum y-value is 1.

    Example 2:

    >>> separateSquares(squares = [[0,0,2],[1,1,1]])
    >>> 1.00000
    Explanation:

    Since the blue square overlaps with the red square, it will not be counted again. Thus, the line y = 1 splits the squares into two equal parts.
    """


Prompt:
def shortestMatchingSubstring(s: str, p: str) -> int:
    """
    You are given a string s and a pattern string p, where p contains exactly two '*' characters.
    The '*' in p matches any sequence of zero or more characters.
    Return the length of the shortest substring in s that matches p. If there is no such substring, return -1.
    Note: The empty substring is considered valid.

    Example 1:

    >>> shortestMatchingSubstring(s = "abaacbaecebce", p = "ba*c*ce")
    >>> 8
    Explanation:
    The shortest matching substring of p in s is "baecebce".

    Example 2:

    >>> shortestMatchingSubstring(s = "baccbaadbc", p = "cc*baa*adb")
    >>> -1
    Explanation:
    There is no matching substring in s.

    Example 3:

    >>> shortestMatchingSubstring(s = "a", p = "**")
    >>> 0
    Explanation:
    The empty substring is the shortest matching substring.

    Example 4:

    >>> shortestMatchingSubstring(s = "madlogic", p = "*adlogi*")
    >>> 6
    Explanation:
    The shortest matching substring of p in s is "adlogi".
    """


Prompt:
def hasSpecialSubstring(s: str, k: int) -> bool:
    """
    You are given a string s and an integer k.
    Determine if there exists a substring of length exactly k in s that satisfies the following conditions:

    The substring consists of only one distinct character (e.g., "aaa" or "bbb").
    If there is a character immediately before the substring, it must be different from the character in the substring.
    If there is a character immediately after the substring, it must also be different from the character in the substring.

    Return true if such a substring exists. Otherwise, return false.

    Example 1:

    >>> hasSpecialSubstring(s = "aaabaaa", k = 3)
    >>> true
    Explanation:
    The substring s[4..6] == "aaa" satisfies the conditions.

    It has a length of 3.
    All characters are the same.
    The character before "aaa" is 'b', which is different from 'a'.
    There is no character after "aaa".

    Example 2:

    >>> hasSpecialSubstring(s = "abc", k = 2)
    >>> false
    Explanation:
    There is no substring of length 2 that consists of one distinct character and satisfies the conditions.
    """


Prompt:
from typing import List
def maxWeight(pizzas: List[int]) -> int:
    """
    You are given an integer array pizzas of size n, where pizzas[i] represents the weight of the ith pizza. Every day, you eat exactly 4 pizzas. Due to your incredible metabolism, when you eat pizzas of weights W, X, Y, and Z, where W <= X <= Y <= Z, you gain the weight of only 1 pizza!

    On odd-numbered days (1-indexed), you gain a weight of Z.
    On even-numbered days, you gain a weight of Y.

    Find the maximum total weight you can gain by eating all pizzas optimally.
    Note: It is guaranteed that n is a multiple of 4, and each pizza can be eaten only once.

    Example 1:

    >>> maxWeight(pizzas = [1,2,3,4,5,6,7,8])
    >>> 14
    Explanation:

    On day 1, you eat pizzas at indices [1, 2, 4, 7] = [2, 3, 5, 8]. You gain a weight of 8.
    On day 2, you eat pizzas at indices [0, 3, 5, 6] = [1, 4, 6, 7]. You gain a weight of 6.

    The total weight gained after eating all the pizzas is 8 + 6 = 14.

    Example 2:

    >>> maxWeight(pizzas = [2,1,1,1,1,1,1,1])
    >>> 3
    Explanation:

    On day 1, you eat pizzas at indices [4, 5, 6, 0] = [1, 1, 1, 2]. You gain a weight of 2.
    On day 2, you eat pizzas at indices [1, 2, 3, 7] = [1, 1, 1, 1]. You gain a weight of 1.

    The total weight gained after eating all the pizzas is 2 + 1 = 3.
    """


Prompt:
from typing import Any
def maxSubstringLength(s: str, k: int) -> bool:
    """
    Given a string s of length n and an integer k, determine whether it is possible to select k disjoint special substrings.
    A special substring is a substring where:

    Any character present inside the substring should not appear outside it in the string.
    The substring is not the entire string s.

    Note that all k substrings must be disjoint, meaning they cannot overlap.
    Return true if it is possible to select k such disjoint special substrings; otherwise, return false.

    Example 1:

    >>> maxSubstringLength(s = "abcdbaefab", k = 2)
    >>> true
    Explanation:

    We can select two disjoint special substrings: "cd" and "ef".
    "cd" contains the characters 'c' and 'd', which do not appear elsewhere in s.
    "ef" contains the characters 'e' and 'f', which do not appear elsewhere in s.

    Example 2:

    >>> maxSubstringLength(s = "cdefdc", k = 3)
    >>> false
    Explanation:
    There can be at most 2 disjoint special substrings: "e" and "f". Since k = 3, the output is false.

    Example 3:

    >>> maxSubstringLength(s = "abeabe", k = 0)
    >>> true
    """


Prompt:
from typing import List
def lenOfVDiagonal(grid: List[List[int]]) -> int:
    """
    You are given a 2D integer matrix grid of size n x m, where each element is either 0, 1, or 2.
    A V-shaped diagonal segment is defined as:

    The segment starts with 1.
    The subsequent elements follow this infinite sequence: 2, 0, 2, 0, ....
    The segment:

    Starts along a diagonal direction (top-left to bottom-right, bottom-right to top-left, top-right to bottom-left, or bottom-left to top-right).
    Continues the sequence in the same diagonal direction.
    Makes at most one clockwise 90-degree turn to another diagonal direction while maintaining the sequence.

    Return the length of the longest V-shaped diagonal segment. If no valid segment exists, return 0.

    Example 1:

    >>> lenOfVDiagonal(grid = [[2,2,1,2,2],[2,0,2,2,0],[2,0,1,1,0],[1,0,2,2,2],[2,0,0,2,2]])
    >>> 5
    Explanation:

    The longest V-shaped diagonal segment has a length of 5 and follows these coordinates: (0,2) → (1,3) → (2,4), takes a 90-degree clockwise turn at (2,4), and continues as (3,3) → (4,2).

    Example 2:

    >>> lenOfVDiagonal(grid = [[2,2,2,2,2],[2,0,2,2,0],[2,0,1,1,0],[1,0,2,2,2],[2,0,0,2,2]])
    >>> 4
    Explanation:

    The longest V-shaped diagonal segment has a length of 4 and follows these coordinates: (2,3) → (3,2), takes a 90-degree clockwise turn at (3,2), and continues as (2,1) → (1,0).

    Example 3:

    >>> lenOfVDiagonal(grid = [[1,2,2,2,2],[2,2,2,2,0],[2,0,0,0,0],[0,0,2,2,2],[2,0,0,2,0]])
    >>> 5
    Explanation:

    The longest V-shaped diagonal segment has a length of 5 and follows these coordinates: (0,0) → (1,1) → (2,2) → (3,3) → (4,4).

    Example 4:

    >>> lenOfVDiagonal(grid = [[1]])
    >>> 1
    Explanation:
    The longest V-shaped diagonal segment has a length of 1 and follows these coordinates: (0,0).
    """


Prompt:
def longestCommonPrefix(s: str, t: str) -> int:
    """
    You are given two strings s and t.
    Return the length of the longest common prefix between s and t after removing at most one character from s.
    Note: s can be left without any removal.

    Example 1:

    >>> longestCommonPrefix(s = "madxa", t = "madam")
    >>> 4
    Explanation:
    Removing s[3] from s results in "mada", which has a longest common prefix of length 4 with t.

    Example 2:

    >>> longestCommonPrefix(s = "leetcode", t = "eetcode")
    >>> 7
    Explanation:
    Removing s[0] from s results in "eetcode", which matches t.

    Example 3:

    >>> longestCommonPrefix(s = "one", t = "one")
    >>> 3
    Explanation:
    No removal is needed.

    Example 4:

    >>> longestCommonPrefix(s = "a", t = "b")
    >>> 0
    Explanation:
    s and t cannot have a common prefix.
    """


Prompt:
def hasSameDigits(s: str) -> bool:
    """
    You are given a string s consisting of digits. Perform the following operation repeatedly until the string has exactly two digits:

    For each pair of consecutive digits in s, starting from the first digit, calculate a new digit as the sum of the two digits modulo 10.
    Replace s with the sequence of newly calculated digits, maintaining the order in which they are computed.

    Return true if the final two digits in s are the same; otherwise, return false.

    Example 1:

    >>> hasSameDigits(s = "3902")
    >>> true
    Explanation:

    Initially, s = "3902"
    First operation:

    (s[0] + s[1]) % 10 = (3 + 9) % 10 = 2
    (s[1] + s[2]) % 10 = (9 + 0) % 10 = 9
    (s[2] + s[3]) % 10 = (0 + 2) % 10 = 2
    s becomes "292"

    Second operation:

    (s[0] + s[1]) % 10 = (2 + 9) % 10 = 1
    (s[1] + s[2]) % 10 = (9 + 2) % 10 = 1
    s becomes "11"

    Since the digits in "11" are the same, the output is true.

    Example 2:

    >>> hasSameDigits(s = "34789")
    >>> false
    Explanation:

    Initially, s = "34789".
    After the first operation, s = "7157".
    After the second operation, s = "862".
    After the third operation, s = "48".
    Since '4' != '8', the output is false.
    """


Prompt:
from typing import List
def maxSum(grid: List[List[int]], limits: List[int], k: int) -> int:
    """
    You are given a 2D integer matrix grid of size n x m, an integer array limits of length n, and an integer k. The task is to find the maximum sum of at most k elements from the matrix grid such that:

    The number of elements taken from the ith row of grid does not exceed limits[i].

    Return the maximum sum.

    Example 1:

    >>> maxSum(grid = [[1,2],[3,4]], limits = [1,2], k = 2)
    >>> 7
    Explanation:

    From the second row, we can take at most 2 elements. The elements taken are 4 and 3.
    The maximum possible sum of at most 2 selected elements is 4 + 3 = 7.

    Example 2:

    >>> maxSum(grid = [[5,3,7],[8,2,6]], limits = [2,2], k = 3)
    >>> 21
    Explanation:

    From the first row, we can take at most 2 elements. The element taken is 7.
    From the second row, we can take at most 2 elements. The elements taken are 8 and 6.
    The maximum possible sum of at most 3 selected elements is 7 + 8 + 6 = 21.
    """


Prompt:
def hasSameDigits(s: str) -> bool:
    """
    You are given a string s consisting of digits. Perform the following operation repeatedly until the string has exactly two digits:

    For each pair of consecutive digits in s, starting from the first digit, calculate a new digit as the sum of the two digits modulo 10.
    Replace s with the sequence of newly calculated digits, maintaining the order in which they are computed.

    Return true if the final two digits in s are the same; otherwise, return false.

    Example 1:

    >>> hasSameDigits(s = "3902")
    >>> true
    Explanation:

    Initially, s = "3902"
    First operation:

    (s[0] + s[1]) % 10 = (3 + 9) % 10 = 2
    (s[1] + s[2]) % 10 = (9 + 0) % 10 = 9
    (s[2] + s[3]) % 10 = (0 + 2) % 10 = 2
    s becomes "292"

    Second operation:

    (s[0] + s[1]) % 10 = (2 + 9) % 10 = 1
    (s[1] + s[2]) % 10 = (9 + 2) % 10 = 1
    s becomes "11"

    Since the digits in "11" are the same, the output is true.

    Example 2:

    >>> hasSameDigits(s = "34789")
    >>> false
    Explanation:

    Initially, s = "34789".
    After the first operation, s = "7157".
    After the second operation, s = "862".
    After the third operation, s = "48".
    Since '4' != '8', the output is false.
    """


Prompt:
from typing import List
def maxDistance(side: int, points: List[List[int]], k: int) -> int:
    """
    You are given an integer side, representing the edge length of a square with corners at (0, 0), (0, side), (side, 0), and (side, side) on a Cartesian plane.
    You are also given a positive integer k and a 2D integer array points, where points[i] = [xi, yi] represents the coordinate of a point lying on the boundary of the square.
    You need to select k elements among points such that the minimum Manhattan distance between any two points is maximized.
    Return the maximum possible minimum Manhattan distance between the selected k points.
    The Manhattan Distance between two cells (xi, yi) and (xj, yj) is |xi - xj| + |yi - yj|.

    Example 1:

    >>> maxDistance(side = 2, points = [[0,2],[2,0],[2,2],[0,0]], k = 4)
    >>> 2
    Explanation:

    Select all four points.

    Example 2:

    >>> maxDistance(side = 2, points = [[0,0],[1,2],[2,0],[2,2],[2,1]], k = 4)
    >>> 1
    Explanation:

    Select the points (0, 0), (2, 0), (2, 2), and (2, 1).

    Example 3:

    >>> maxDistance(side = 2, points = [[0,0],[0,1],[0,2],[1,2],[2,0],[2,2],[2,1]], k = 5)
    >>> 1
    Explanation:

    Select the points (0, 0), (0, 1), (0, 2), (1, 2), and (2, 2).
    """


Prompt:
from typing import List
def maxCoins(lane1: List[int], lane2: List[int]) -> int:
    """
    Mario drives on a two-lane freeway with coins every mile. You are given two integer arrays, lane1 and lane2, where the value at the ith index represents the number of coins he gains or loses in the ith mile in that lane.

    If Mario is in lane 1 at mile i and lane1[i] > 0, Mario gains lane1[i] coins.
    If Mario is in lane 1 at mile i and lane1[i] < 0, Mario pays a toll and loses abs(lane1[i]) coins.
    The same rules apply for lane2.

    Mario can enter the freeway anywhere and exit anytime after traveling at least one mile. Mario always enters the freeway on lane 1 but can switch lanes at most 2 times.
    A lane switch is when Mario goes from lane 1 to lane 2 or vice versa.
    Return the maximum number of coins Mario can earn after performing at most 2 lane switches.
    Note: Mario can switch lanes immediately upon entering or just before exiting the freeway.

    Example 1:

    >>> maxCoins(lane1 = [1,-2,-10,3], lane2 = [-5,10,0,1])
    >>> 14
    Explanation:

    Mario drives the first mile on lane 1.
    He then changes to lane 2 and drives for two miles.
    He changes back to lane 1 for the last mile.

    Mario collects 1 + 10 + 0 + 3 = 14 coins.

    Example 2:

    >>> maxCoins(lane1 = [1,-1,-1,-1], lane2 = [0,3,4,-5])
    >>> 8
    Explanation:

    Mario starts at mile 0 in lane 1 and drives one mile.
    He then changes to lane 2 and drives for two more miles. He exits the freeway before mile 3.

    He collects 1 + 3 + 4 = 8 coins.

    Example 3:

    >>> maxCoins(lane1 = [-5,-4,-3], lane2 = [-1,2,3])
    >>> 5
    Explanation:

    Mario enters at mile 1 and immediately switches to lane 2. He stays here the entire way.

    He collects a total of 2 + 3 = 5 coins.

    Example 4:

    >>> maxCoins(lane1 = [-3,-3,-3], lane2 = [9,-2,4])
    >>> 11
    Explanation:

    Mario starts at the beginning of the freeway and immediately switches to lane 2. He stays here the whole way.

    He collects a total of 9 + (-2) + 4 = 11 coins.

    Example 5:

    >>> maxCoins(lane1 = [-10], lane2 = [-2])
    >>> -2
    Explanation:

    Since Mario must ride on the freeway for at least one mile, he rides just one mile in lane 2.

    He collects a total of -2 coins.
    """


Prompt:
from typing import List
def transformArray(nums: List[int]) -> List[int]:
    """
    You are given an integer array nums. Transform nums by performing the following operations in the exact order specified:

    Replace each even number with 0.
    Replace each odd numbers with 1.
    Sort the modified array in non-decreasing order.

    Return the resulting array after performing these operations.

    Example 1:

    >>> transformArray(nums = [4,3,2,1])
    >>> [0,0,1,1]
    Explanation:

    Replace the even numbers (4 and 2) with 0 and the odd numbers (3 and 1) with 1. Now, nums = [0, 1, 0, 1].
    After sorting nums in non-descending order, nums = [0, 0, 1, 1].

    Example 2:

    >>> transformArray(nums = [1,5,1,4,2])
    >>> [0,0,1,1,1]
    Explanation:

    Replace the even numbers (4 and 2) with 0 and the odd numbers (1, 5 and 1) with 1. Now, nums = [1, 1, 1, 0, 0].
    After sorting nums in non-descending order, nums = [0, 0, 1, 1, 1].
    """


Prompt:
from typing import List
def countArrays(original: List[int], bounds: List[List[int]]) -> int:
    """
    You are given an array original of length n and a 2D array bounds of length n x 2, where bounds[i] = [ui, vi].
    You need to find the number of possible arrays copy of length n such that:

    (copy[i] - copy[i - 1]) == (original[i] - original[i - 1]) for 1 <= i <= n - 1.
    ui <= copy[i] <= vi for 0 <= i <= n - 1.

    Return the number of such arrays.

    Example 1:

    >>> countArrays(original = [1,2,3,4], bounds = [[1,2],[2,3],[3,4],[4,5]])
    >>> 2
    Explanation:
    The possible arrays are:

    [1, 2, 3, 4]
    [2, 3, 4, 5]

    Example 2:

    >>> countArrays(original = [1,2,3,4], bounds = [[1,10],[2,9],[3,8],[4,7]])
    >>> 4
    Explanation:
    The possible arrays are:

    [1, 2, 3, 4]
    [2, 3, 4, 5]
    [3, 4, 5, 6]
    [4, 5, 6, 7]

    Example 3:

    >>> countArrays(original = [1,2,1,2], bounds = [[1,1],[2,3],[3,3],[2,3]])
    >>> 0
    Explanation:
    No array is possible.
    """


Prompt:
from typing import List
def minCost(nums: List[int]) -> int:
    """
    You are given an integer array nums. Your task is to remove all elements from the array by performing one of the following operations at each step until nums is empty:

    Choose any two elements from the first three elements of nums and remove them. The cost of this operation is the maximum of the two elements removed.
    If fewer than three elements remain in nums, remove all the remaining elements in a single operation. The cost of this operation is the maximum of the remaining elements.

    Return the minimum cost required to remove all the elements.

    Example 1:

    >>> minCost(nums = [6,2,8,4])
    >>> 12
    Explanation:
    Initially, nums = [6, 2, 8, 4].

    In the first operation, remove nums[0] = 6 and nums[2] = 8 with a cost of max(6, 8) = 8. Now, nums = [2, 4].
    In the second operation, remove the remaining elements with a cost of max(2, 4) = 4.

    The cost to remove all elements is 8 + 4 = 12. This is the minimum cost to remove all elements in nums. Hence, the output is 12.

    Example 2:

    >>> minCost(nums = [2,1,3,3])
    >>> 5
    Explanation:
    Initially, nums = [2, 1, 3, 3].

    In the first operation, remove nums[0] = 2 and nums[1] = 1 with a cost of max(2, 1) = 2. Now, nums = [3, 3].
    In the second operation remove the remaining elements with a cost of max(3, 3) = 3.

    The cost to remove all elements is 2 + 3 = 5. This is the minimum cost to remove all elements in nums. Hence, the output is 5.
    """


Prompt:
from typing import List
def permute(n: int, k: int) -> List[int]:
    """
    Given two integers, n and k, an alternating permutation is a permutation of the first n positive integers such that no two adjacent elements are both odd or both even.
    Return the k-th alternating permutation sorted in lexicographical order. If there are fewer than k valid alternating permutations, return an empty list.

    Example 1:

    >>> permute(n = 4, k = 6)
    >>> [3,4,1,2]
    Explanation:
    The lexicographically-sorted alternating permutations of [1, 2, 3, 4] are:

    [1, 2, 3, 4]
    [1, 4, 3, 2]
    [2, 1, 4, 3]
    [2, 3, 4, 1]
    [3, 2, 1, 4]
    [3, 4, 1, 2] ← 6th permutation
    [4, 1, 2, 3]
    [4, 3, 2, 1]

    Since k = 6, we return [3, 4, 1, 2].

    Example 2:

    >>> permute(n = 3, k = 2)
    >>> [3,2,1]
    Explanation:
    The lexicographically-sorted alternating permutations of [1, 2, 3] are:

    [1, 2, 3]
    [3, 2, 1] ← 2nd permutation

    Since k = 2, we return [3, 2, 1].

    Example 3:

    >>> permute(n = 2, k = 3)
    >>> []
    Explanation:
    The lexicographically-sorted alternating permutations of [1, 2] are:

    [1, 2]
    [2, 1]

    There are only 2 alternating permutations, but k = 3, which is out of range. Thus, we return an empty list [].
    """


Prompt:
from typing import List
def largestInteger(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and an integer k.
    An integer x is almost missing from nums if x appears in exactly one subarray of size k within nums.
    Return the largest almost missing integer from nums. If no such integer exists, return -1.
    A subarray is a contiguous sequence of elements within an array.

    Example 1:

    >>> largestInteger(nums = [3,9,2,1,7], k = 3)
    >>> 7
    Explanation:

    1 appears in 2 subarrays of size 3: [9, 2, 1] and [2, 1, 7].
    2 appears in 3 subarrays of size 3: [3, 9, 2], [9, 2, 1], [2, 1, 7].
    3 appears in 1 subarray of size 3: [3, 9, 2].
    7 appears in 1 subarray of size 3: [2, 1, 7].
    9 appears in 2 subarrays of size 3: [3, 9, 2], and [9, 2, 1].

    We return 7 since it is the largest integer that appears in exactly one subarray of size k.

    Example 2:

    >>> largestInteger(nums = [3,9,7,2,1,7], k = 4)
    >>> 3
    Explanation:

    1 appears in 2 subarrays of size 4: [9, 7, 2, 1], [7, 2, 1, 7].
    2 appears in 3 subarrays of size 4: [3, 9, 7, 2], [9, 7, 2, 1], [7, 2, 1, 7].
    3 appears in 1 subarray of size 4: [3, 9, 7, 2].
    7 appears in 3 subarrays of size 4: [3, 9, 7, 2], [9, 7, 2, 1], [7, 2, 1, 7].
    9 appears in 2 subarrays of size 4: [3, 9, 7, 2], [9, 7, 2, 1].

    We return 3 since it is the largest and only integer that appears in exactly one subarray of size k.

    Example 3:

    >>> largestInteger(nums = [0,0], k = 1)
    >>> -1
    Explanation:
    There is no integer that appears in only one subarray of size 1.
    """


Prompt:
def longestPalindromicSubsequence(s: str, k: int) -> int:
    """
    You are given a string s and an integer k.
    In one operation, you can replace the character at any position with the next or previous letter in the alphabet (wrapping around so that 'a' is after 'z'). For example, replacing 'a' with the next letter results in 'b', and replacing 'a' with the previous letter results in 'z'. Similarly, replacing 'z' with the next letter results in 'a', and replacing 'z' with the previous letter results in 'y'.
    Return the length of the longest palindromic subsequence of s that can be obtained after performing at most k operations.

    Example 1:

    >>> longestPalindromicSubsequence(s = "abced", k = 2)
    >>> 3
    Explanation:

    Replace s[1] with the next letter, and s becomes "acced".
    Replace s[4] with the previous letter, and s becomes "accec".

    The subsequence "ccc" forms a palindrome of length 3, which is the maximum.

    Example 2:

    >>> longestPalindromicSubsequence(s = "aaazzz", k = 4)
    >>> 6
    Explanation:

    Replace s[0] with the previous letter, and s becomes "zaazzz".
    Replace s[4] with the next letter, and s becomes "zaazaz".
    Replace s[3] with the next letter, and s becomes "zaaaaz".

    The entire string forms a palindrome of length 6.
    """


Prompt:
from typing import List
def maxSum(nums: List[int], k: int, m: int) -> int:
    """
    You are given an integer array nums and two integers, k and m.
    Return the maximum sum of k non-overlapping subarrays of nums, where each subarray has a length of at least m.

    Example 1:

    >>> maxSum(nums = [1,2,-1,3,3,4], k = 2, m = 2)
    >>> 13
    Explanation:
    The optimal choice is:

    Subarray nums[3..5] with sum 3 + 3 + 4 = 10 (length is 3 >= m).
    Subarray nums[0..1] with sum 1 + 2 = 3 (length is 2 >= m).

    The total sum is 10 + 3 = 13.

    Example 2:

    >>> maxSum(nums = [-10,3,-1,-2], k = 4, m = 1)
    >>> -10
    Explanation:
    The optimal choice is choosing each element as a subarray. The output is (-10) + 3 + (-1) + (-2) = -10.
    """


Prompt:
def generateString(str1: str, str2: str) -> str:
    """
    You are given two strings, str1 and str2, of lengths n and m, respectively.
    A string word of length n + m - 1 is defined to be generated by str1 and str2 if it satisfies the following conditions for each index 0 <= i <= n - 1:

    If str1[i] == 'T', the substring of word with size m starting at index i is equal to str2, i.e., word[i..(i + m - 1)] == str2.
    If str1[i] == 'F', the substring of word with size m starting at index i is not equal to str2, i.e., word[i..(i + m - 1)] != str2.

    Return the lexicographically smallest possible string that can be generated by str1 and str2. If no string can be generated, return an empty string "".

    Example 1:

    >>> generateString(str1 = "TFTF", str2 = "ab")
    >>> "ababa"
    Explanation:
    The table below represents the string "ababa"

    Index
    T/F
    Substring of length m

    0
    'T'
    "ab"

    1
    'F'
    "ba"

    2
    'T'
    "ab"

    3
    'F'
    "ba"

    The strings "ababa" and "ababb" can be generated by str1 and str2.
    Return "ababa" since it is the lexicographically smaller string.

    Example 2:

    >>> generateString(str1 = "TFTF", str2 = "abc")
    >>> ""
    Explanation:
    No string that satisfies the conditions can be generated.

    Example 3:

    >>> generateString(str1 = "F", str2 = "d")
    >>> "a"
    """


Prompt:
from typing import List
def maxProfit(workers: List[int], tasks: List[List[int]]) -> int:
    """
    You are given an integer array workers, where workers[i] represents the skill level of the ith worker. You are also given a 2D integer array tasks, where:

    tasks[i][0] represents the skill requirement needed to complete the task.
    tasks[i][1] represents the profit earned from completing the task.

    Each worker can complete at most one task, and they can only take a task if their skill level is equal to the task's skill requirement. An additional worker joins today who can take up any task, regardless of the skill requirement.
    Return the maximum total profit that can be earned by optimally assigning the tasks to the workers.

    Example 1:

    >>> maxProfit(workers = [1,2,3,4,5], tasks = [[1,100],[2,400],[3,100],[3,400]])
    >>> 1000
    Explanation:

    Worker 0 completes task 0.
    Worker 1 completes task 1.
    Worker 2 completes task 3.
    The additional worker completes task 2.

    Example 2:

    >>> maxProfit(workers = [10,10000,100000000], tasks = [[1,100]])
    >>> 100
    Explanation:
    Since no worker matches the skill requirement, only the additional worker can complete task 0.

    Example 3:

    >>> maxProfit(workers = [7], tasks = [[3,3],[3,3]])
    >>> 3
    Explanation:
    The additional worker completes task 1. Worker 0 cannot work since no task has a skill requirement of 7.
    """


Prompt:
from typing import List
def numOfUnplacedFruits(fruits: List[int], baskets: List[int]) -> int:
    """
    You are given two arrays of integers, fruits and baskets, each of length n, where fruits[i] represents the quantity of the ith type of fruit, and baskets[j] represents the capacity of the jth basket.
    From left to right, place the fruits according to these rules:

    Each fruit type must be placed in the leftmost available basket with a capacity greater than or equal to the quantity of that fruit type.
    Each basket can hold only one type of fruit.
    If a fruit type cannot be placed in any basket, it remains unplaced.

    Return the number of fruit types that remain unplaced after all possible allocations are made.

    Example 1:

    >>> numOfUnplacedFruits(fruits = [4,2,5], baskets = [3,5,4])
    >>> 1
    Explanation:

    fruits[0] = 4 is placed in baskets[1] = 5.
    fruits[1] = 2 is placed in baskets[0] = 3.
    fruits[2] = 5 cannot be placed in baskets[2] = 4.

    Since one fruit type remains unplaced, we return 1.

    Example 2:

    >>> numOfUnplacedFruits(fruits = [3,6,1], baskets = [6,4,7])
    >>> 0
    Explanation:

    fruits[0] = 3 is placed in baskets[0] = 6.
    fruits[1] = 6 cannot be placed in baskets[1] = 4 (insufficient capacity) but can be placed in the next available basket, baskets[2] = 7.
    fruits[2] = 1 is placed in baskets[1] = 4.

    Since all fruits are successfully placed, we return 0.
    """


Prompt:
from typing import List
def findMaxSum(nums1: List[int], nums2: List[int], k: int) -> List[int]:
    """
    You are given two integer arrays, nums1 and nums2, both of length n, along with a positive integer k.
    For each index i from 0 to n - 1, perform the following:

    Find all indices j where nums1[j] is less than nums1[i].
    Choose at most k values of nums2[j] at these indices to maximize the total sum.

    Return an array answer of size n, where answer[i] represents the result for the corresponding index i.

    Example 1:

    >>> findMaxSum(nums1 = [4,2,1,5,3], nums2 = [10,20,30,40,50], k = 2)
    >>> [80,30,0,80,50]
    Explanation:

    For i = 0: Select the 2 largest values from nums2 at indices [1, 2, 4] where nums1[j] < nums1[0], resulting in 50 + 30 = 80.
    For i = 1: Select the 2 largest values from nums2 at index [2] where nums1[j] < nums1[1], resulting in 30.
    For i = 2: No indices satisfy nums1[j] < nums1[2], resulting in 0.
    For i = 3: Select the 2 largest values from nums2 at indices [0, 1, 2, 4] where nums1[j] < nums1[3], resulting in 50 + 30 = 80.
    For i = 4: Select the 2 largest values from nums2 at indices [1, 2] where nums1[j] < nums1[4], resulting in 30 + 20 = 50.

    Example 2:

    >>> findMaxSum(nums1 = [2,2,2,2], nums2 = [3,1,2,3], k = 1)
    >>> [0,0,0,0]
    Explanation:
    Since all elements in nums1 are equal, no indices satisfy the condition nums1[j] < nums1[i] for any i, resulting in 0 for all positions.
    """


Prompt:
from typing import List
def numOfUnplacedFruits(fruits: List[int], baskets: List[int]) -> int:
    """
    You are given two arrays of integers, fruits and baskets, each of length n, where fruits[i] represents the quantity of the ith type of fruit, and baskets[j] represents the capacity of the jth basket.
    From left to right, place the fruits according to these rules:

    Each fruit type must be placed in the leftmost available basket with a capacity greater than or equal to the quantity of that fruit type.
    Each basket can hold only one type of fruit.
    If a fruit type cannot be placed in any basket, it remains unplaced.

    Return the number of fruit types that remain unplaced after all possible allocations are made.

    Example 1:

    >>> numOfUnplacedFruits(fruits = [4,2,5], baskets = [3,5,4])
    >>> 1
    Explanation:

    fruits[0] = 4 is placed in baskets[1] = 5.
    fruits[1] = 2 is placed in baskets[0] = 3.
    fruits[2] = 5 cannot be placed in baskets[2] = 4.

    Since one fruit type remains unplaced, we return 1.

    Example 2:

    >>> numOfUnplacedFruits(fruits = [3,6,1], baskets = [6,4,7])
    >>> 0
    Explanation:

    fruits[0] = 3 is placed in baskets[0] = 6.
    fruits[1] = 6 cannot be placed in baskets[1] = 4 (insufficient capacity) but can be placed in the next available basket, baskets[2] = 7.
    fruits[2] = 1 is placed in baskets[1] = 4.

    Since all fruits are successfully placed, we return 0.
    """


Prompt:
from typing import List
def maxSubarrays(n: int, conflictingPairs: List[List[int]]) -> int:
    """
    You are given an integer n which represents an array nums containing the numbers from 1 to n in order. Additionally, you are given a 2D array conflictingPairs, where conflictingPairs[i] = [a, b] indicates that a and b form a conflicting pair.
    Remove exactly one element from conflictingPairs. Afterward, count the number of non-empty subarrays of nums which do not contain both a and b for any remaining conflicting pair [a, b].
    Return the maximum number of subarrays possible after removing exactly one conflicting pair.

    Example 1:

    >>> maxSubarrays(n = 4, conflictingPairs = [[2,3],[1,4]])
    >>> 9
    Explanation:

    Remove [2, 3] from conflictingPairs. Now, conflictingPairs = [[1, 4]].
    There are 9 subarrays in nums where [1, 4] do not appear together. They are [1], [2], [3], [4], [1, 2], [2, 3], [3, 4], [1, 2, 3] and [2, 3, 4].
    The maximum number of subarrays we can achieve after removing one element from conflictingPairs is 9.

    Example 2:

    >>> maxSubarrays(n = 5, conflictingPairs = [[1,2],[2,5],[3,5]])
    >>> 12
    Explanation:

    Remove [1, 2] from conflictingPairs. Now, conflictingPairs = [[2, 5], [3, 5]].
    There are 12 subarrays in nums where [2, 5] and [3, 5] do not appear together.
    The maximum number of subarrays we can achieve after removing one element from conflictingPairs is 12.
    """


Prompt:
from typing import List
def applySubstitutions(replacements: List[List[str]], text: str) -> str:
    """
    You are given a replacements mapping and a text string that may contain placeholders formatted as %var%, where each var corresponds to a key in the replacements mapping. Each replacement value may itself contain one or more such placeholders. Each placeholder is replaced by the value associated with its corresponding replacement key.
    Return the fully substituted text string which does not contain any placeholders.

    Example 1:

    >>> applySubstitutions(replacements = [["A","abc"],["B","def"]], text = "%A%_%B%")
    >>> "abc_def"
    Explanation:

    The mapping associates "A" with "abc" and "B" with "def".
    Replace %A% with "abc" and %B% with "def" in the text.
    The final text becomes "abc_def".

    Example 2:

    >>> applySubstitutions(replacements = [["A","bce"],["B","ace"],["C","abc%B%"]], text = "%A%_%B%_%C%")
    >>> "bce_ace_abcace"
    Explanation:

    The mapping associates "A" with "bce", "B" with "ace", and "C" with "abc%B%".
    Replace %A% with "bce" and %B% with "ace" in the text.
    Then, for %C%, substitute %B% in "abc%B%" with "ace" to obtain "abcace".
    The final text becomes "bce_ace_abcace".
    """


Prompt:
from typing import List
def totalNumbers(digits: List[int]) -> int:
    """
    You are given an array of digits called digits. Your task is to determine the number of distinct three-digit even numbers that can be formed using these digits.
    Note: Each copy of a digit can only be used once per number, and there may not be leading zeros.

    Example 1:

    >>> totalNumbers(digits = [1,2,3,4])
    >>> 12
    Explanation: The 12 distinct 3-digit even numbers that can be formed are 124, 132, 134, 142, 214, 234, 312, 314, 324, 342, 412, and 432. Note that 222 cannot be formed because there is only 1 copy of the digit 2.

    Example 2:

    >>> totalNumbers(digits = [0,2,2])
    >>> 2
    Explanation: The only 3-digit even numbers that can be formed are 202 and 220. Note that the digit 2 can be used twice because it appears twice in the array.

    Example 3:

    >>> totalNumbers(digits = [6,6,6])
    >>> 1
    Explanation: Only 666 can be formed.

    Example 4:

    >>> totalNumbers(digits = [1,3,5])
    >>> 0
    Explanation: No even 3-digit numbers can be formed.
    """


Prompt:
from typing import List
def longestCommonPrefix(words: List[str], k: int) -> List[int]:
    """
    You are given an array of strings words and an integer k.
    For each index i in the range [0, words.length - 1], find the length of the longest common prefix among any k strings (selected at distinct indices) from the remaining array after removing the ith element.
    Return an array answer, where answer[i] is the answer for ith element. If removing the ith element leaves the array with fewer than k strings, answer[i] is 0.

    Example 1:

    >>> longestCommonPrefix(words = ["jump","run","run","jump","run"], k = 2)
    >>> [3,4,4,3,4]
    Explanation:

    Removing index 0 ("jump"):

    words becomes: ["run", "run", "jump", "run"]. "run" occurs 3 times. Choosing any two gives the longest common prefix "run" (length 3).

    Removing index 1 ("run"):

    words becomes: ["jump", "run", "jump", "run"]. "jump" occurs twice. Choosing these two gives the longest common prefix "jump" (length 4).

    Removing index 2 ("run"):

    words becomes: ["jump", "run", "jump", "run"]. "jump" occurs twice. Choosing these two gives the longest common prefix "jump" (length 4).

    Removing index 3 ("jump"):

    words becomes: ["jump", "run", "run", "run"]. "run" occurs 3 times. Choosing any two gives the longest common prefix "run" (length 3).

    Removing index 4 ("run"):

    words becomes: ["jump", "run", "run", "jump"]. "jump" occurs twice. Choosing these two gives the longest common prefix "jump" (length 4).

    Example 2:

    >>> longestCommonPrefix(words = ["dog","racer","car"], k = 2)
    >>> [0,0,0]
    Explanation:

    Removing any index results in an answer of 0.
    """


Prompt:
from typing import List
def longestSpecialPath(edges: List[List[int]], nums: List[int]) -> List[int]:
    """
    You are given an undirected tree rooted at node 0, with n nodes numbered from 0 to n - 1. This is represented by a 2D array edges of length n - 1, where edges[i] = [ui, vi, lengthi] indicates an edge between nodes ui and vi with length lengthi. You are also given an integer array nums, where nums[i] represents the value at node i.
    A special path is defined as a downward path from an ancestor node to a descendant node in which all node values are distinct, except for at most one value that may appear twice.
    Return an array result of size 2, where result[0] is the length of the longest special path, and result[1] is the minimum number of nodes in all possible longest special paths.

    Example 1:

    >>> longestSpecialPath(edges = [[0,1,1],[1,2,3],[1,3,1],[2,4,6],[4,7,2],[3,5,2],[3,6,5],[6,8,3]], nums = [1,1,0,3,1,2,1,1,0])
    >>> [9,3]
    Explanation:
    In the image below, nodes are colored by their corresponding values in nums.

    The longest special paths are 1 -> 2 -> 4 and 1 -> 3 -> 6 -> 8, both having a length of 9. The minimum number of nodes across all longest special paths is 3.

    Example 2:

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

    The longest path is 0 -> 3 consisting of 2 nodes with a length of 5.
    """


Prompt:
from typing import List
def maxSum(nums: List[int]) -> int:
    """
    You are given an integer array nums.
    You are allowed to delete any number of elements from nums without making it empty. After performing the deletions, select a subarray of nums such that:

    All elements in the subarray are unique.
    The sum of the elements in the subarray is maximized.

    Return the maximum sum of such a subarray.

    Example 1:

    >>> maxSum(nums = [1,2,3,4,5])
    >>> 15
    Explanation:
    Select the entire array without deleting any element to obtain the maximum sum.

    Example 2:

    >>> maxSum(nums = [1,1,0,1,1])
    >>> 1
    Explanation:
    Delete the element nums[0] == 1, nums[1] == 1, nums[2] == 0, and nums[3] == 1. Select the entire array [1] to obtain the maximum sum.

    Example 3:

    >>> maxSum(nums = [1,2,-1,-2,1,0,-1])
    >>> 3
    Explanation:
    Delete the elements nums[2] == -1 and nums[3] == -2, and select the subarray [2, 1] from [1, 2, 1, 0, -1] to obtain the maximum sum.
    """


Prompt:
from typing import List
def solveQueries(nums: List[int], queries: List[int]) -> List[int]:
    """
    You are given a circular array nums and an array queries.
    For each query i, you have to find the following:

    The minimum distance between the element at index queries[i] and any other index j in the circular array, where nums[j] == nums[queries[i]]. If no such index exists, the answer for that query should be -1.

    Return an array answer of the same size as queries, where answer[i] represents the result for query i.

    Example 1:

    >>> solveQueries(nums = [1,3,1,4,1,3,2], queries = [0,3,5])
    >>> [2,-1,3]
    Explanation:

    Query 0: The element at queries[0] = 0 is nums[0] = 1. The nearest index with the same value is 2, and the distance between them is 2.
    Query 1: The element at queries[1] = 3 is nums[3] = 4. No other index contains 4, so the result is -1.
    Query 2: The element at queries[2] = 5 is nums[5] = 3. The nearest index with the same value is 1, and the distance between them is 3 (following the circular path: 5 -> 6 -> 0 -> 1).

    Example 2:

    >>> solveQueries(nums = [1,2,3,4], queries = [0,1,2,3])
    >>> [-1,-1,-1,-1]
    Explanation:
    Each value in nums is unique, so no index shares the same value as the queried element. This results in -1 for all queries.
    """


Prompt:
from typing import List
def minZeroArray(nums: List[int], queries: List[List[int]]) -> int:
    """
    You are given an integer array nums of length n and a 2D array queries, where queries[i] = [li, ri, vali].
    Each queries[i] represents the following action on nums:

    Select a subset of indices in the range [li, ri] from nums.
    Decrement the value at each selected index by exactly vali.

    A Zero Array is an array with all its elements equal to 0.
    Return the minimum possible non-negative value of k, such that after processing the first k queries in sequence, nums becomes a Zero Array. If no such k exists, return -1.

    Example 1:

    >>> minZeroArray(nums = [2,0,2], queries = [[0,2,1],[0,2,1],[1,1,3]])
    >>> 2
    Explanation:

    For query 0 (l = 0, r = 2, val = 1):

    Decrement the values at indices [0, 2] by 1.
    The array will become [1, 0, 1].

    For query 1 (l = 0, r = 2, val = 1):

    Decrement the values at indices [0, 2] by 1.
    The array will become [0, 0, 0], which is a Zero Array. Therefore, the minimum value of k is 2.

    Example 2:

    >>> minZeroArray(nums = [4,3,2,1], queries = [[1,3,2],[0,2,1]])
    >>> -1
    Explanation:
    It is impossible to make nums a Zero Array even after all the queries.

    Example 3:

    >>> minZeroArray(nums = [1,2,3,2,1], queries = [[0,1,1],[1,2,1],[2,3,2],[3,4,1],[4,4,1]])
    >>> 4
    Explanation:

    For query 0 (l = 0, r = 1, val = 1):

    Decrement the values at indices [0, 1] by 1.
    The array will become [0, 1, 3, 2, 1].

    For query 1 (l = 1, r = 2, val = 1):

    Decrement the values at indices [1, 2] by 1.
    The array will become [0, 0, 2, 2, 1].

    For query 2 (l = 2, r = 3, val = 2):

    Decrement the values at indices [2, 3] by 2.
    The array will become [0, 0, 0, 0, 1].

    For query 3 (l = 3, r = 4, val = 1):

    Decrement the value at index 4 by 1.
    The array will become [0, 0, 0, 0, 0]. Therefore, the minimum value of k is 4.

    Example 4:

    >>> minZeroArray(nums = [1,2,3,2,6], queries = [[0,1,1],[0,2,1],[1,4,2],[4,4,4],[3,4,1],[4,4,5]])
    >>> 4
    """


Prompt:
def beautifulNumbers(l: int, r: int) -> int:
    """
    You are given two positive integers, l and r. A positive integer is called beautiful if the product of its digits is divisible by the sum of its digits.
    Return the count of beautiful numbers between l and r, inclusive.

    Example 1:

    >>> beautifulNumbers(l = 10, r = 20)
    >>> 2
    Explanation:
    The beautiful numbers in the range are 10 and 20.

    Example 2:

    >>> beautifulNumbers(l = 1, r = 15)
    >>> 10
    Explanation:
    The beautiful numbers in the range are 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10.
    """


Prompt:
from typing import List
def phonePrefix(numbers: List[str]) -> bool:
    """
    You are given a string array numbers that represents phone numbers. Return true if no phone number is a prefix of any other phone number; otherwise, return false.

    Example 1:

    >>> phonePrefix(numbers = ["1","2","4","3"])
    >>> true
    Explanation:
    No number is a prefix of another number, so the output is true.

    Example 2:

    >>> phonePrefix(numbers = ["001","007","15","00153"])
    >>> false
    Explanation:
    The string "001" is a prefix of the string "00153". Thus, the output is false.
    """


Prompt:
def maxContainers(n: int, w: int, maxWeight: int) -> int:
    """
    You are given a positive integer n representing an n x n cargo deck on a ship. Each cell on the deck can hold one container with a weight of exactly w.
    However, the total weight of all containers, if loaded onto the deck, must not exceed the ship's maximum weight capacity, maxWeight.
    Return the maximum number of containers that can be loaded onto the ship.

    Example 1:

    >>> maxContainers(n = 2, w = 3, maxWeight = 15)
    >>> 4
    Explanation:
    The deck has 4 cells, and each container weighs 3. The total weight of loading all containers is 12, which does not exceed maxWeight.

    Example 2:

    >>> maxContainers(n = 3, w = 5, maxWeight = 20)
    >>> 4
    Explanation:
    The deck has 9 cells, and each container weighs 5. The maximum number of containers that can be loaded without exceeding maxWeight is 4.
    """


Prompt:
from typing import List
def numberOfComponents(properties: List[List[int]], k: int) -> int:
    """
    You are given a 2D integer array properties having dimensions n x m and an integer k.
    Define a function intersect(a, b) that returns the number of distinct integers common to both arrays a and b.
    Construct an undirected graph where each index i corresponds to properties[i]. There is an edge between node i and node j if and only if intersect(properties[i], properties[j]) >= k, where i and j are in the range [0, n - 1] and i != j.
    Return the number of connected components in the resulting graph.

    Example 1:

    >>> numberOfComponents(properties = [[1,2],[1,1],[3,4],[4,5],[5,6],[7,7]], k = 1)
    >>> 3
    Explanation:
    The graph formed has 3 connected components:

    Example 2:

    >>> numberOfComponents(properties = [[1,2,3],[2,3,4],[4,3,5]], k = 2)
    >>> 1
    Explanation:
    The graph formed has 1 connected component:

    Example 3:

    >>> numberOfComponents(properties = [[1,1],[1,1]], k = 2)
    >>> 2
    Explanation:
    intersect(properties[0], properties[1]) = 1, which is less than k. This means there is no edge between properties[0] and properties[1] in the graph.
    """


Prompt:
from typing import List
def minTime(skill: List[int], mana: List[int]) -> int:
    """
    You are given two integer arrays, skill and mana, of length n and m, respectively.
    In a laboratory, n wizards must brew m potions in order. Each potion has a mana capacity mana[j] and must pass through all the wizards sequentially to be brewed properly. The time taken by the ith wizard on the jth potion is timeij = skill[i] * mana[j].
    Since the brewing process is delicate, a potion must be passed to the next wizard immediately after the current wizard completes their work. This means the timing must be synchronized so that each wizard begins working on a potion exactly when it arrives.
    Return the minimum amount of time required for the potions to be brewed properly.

    Example 1:

    >>> minTime(skill = [1,5,2,4], mana = [5,1,4,2])
    >>> 110
    Explanation:

    Potion Number
    Start time
    Wizard 0 done by
    Wizard 1 done by
    Wizard 2 done by
    Wizard 3 done by

    0
    0
    5
    30
    40
    60

    1
    52
    53
    58
    60
    64

    2
    54
    58
    78
    86
    102

    3
    86
    88
    98
    102
    110

    As an example for why wizard 0 cannot start working on the 1st potion before time t = 52, consider the case where the wizards started preparing the 1st potion at time t = 50. At time t = 58, wizard 2 is done with the 1st potion, but wizard 3 will still be working on the 0th potion till time t = 60.

    Example 2:

    >>> minTime(skill = [1,1,1], mana = [1,1,1])
    >>> 5
    Explanation:

    Preparation of the 0th potion begins at time t = 0, and is completed by time t = 3.
    Preparation of the 1st potion begins at time t = 1, and is completed by time t = 4.
    Preparation of the 2nd potion begins at time t = 2, and is completed by time t = 5.

    Example 3:

    >>> minTime(skill = [1,2,3,4], mana = [1,2])
    >>> 21
    """


Prompt:
from typing import List
def minOperations(queries: List[List[int]]) -> int:
    """
    You are given a 2D array queries, where queries[i] is of the form [l, r]. Each queries[i] defines an array of integers nums consisting of elements ranging from l to r, both inclusive.
    In one operation, you can:

    Select two integers a and b from the array.
    Replace them with floor(a / 4) and floor(b / 4).

    Your task is to determine the minimum number of operations required to reduce all elements of the array to zero for each query. Return the sum of the results for all queries.

    Example 1:

    >>> minOperations(queries = [[1,2],[2,4]])
    >>> 3
    Explanation:
    For queries[0]:

    The initial array is nums = [1, 2].
    In the first operation, select nums[0] and nums[1]. The array becomes [0, 0].
    The minimum number of operations required is 1.

    For queries[1]:

    The initial array is nums = [2, 3, 4].
    In the first operation, select nums[0] and nums[2]. The array becomes [0, 3, 1].
    In the second operation, select nums[1] and nums[2]. The array becomes [0, 0, 0].
    The minimum number of operations required is 2.

    The output is 1 + 2 = 3.

    Example 2:

    >>> minOperations(queries = [[2,6]])
    >>> 4
    Explanation:
    For queries[0]:

    The initial array is nums = [2, 3, 4, 5, 6].
    In the first operation, select nums[0] and nums[3]. The array becomes [0, 3, 4, 1, 6].
    In the second operation, select nums[2] and nums[4]. The array becomes [0, 3, 1, 1, 1].
    In the third operation, select nums[1] and nums[2]. The array becomes [0, 0, 0, 1, 1].
    In the fourth operation, select nums[3] and nums[4]. The array becomes [0, 0, 0, 0, 0].
    The minimum number of operations required is 4.

    The output is 4.
    """


Prompt:
from typing import List
def maxScore(nums: List[int]) -> int:
    """
    You are given an array of integers nums. You must repeatedly perform one of the following operations while the array has more than two elements:

    Remove the first two elements.
    Remove the last two elements.
    Remove the first and last element.

    For each operation, add the sum of the removed elements to your total score.
    Return the maximum possible score you can achieve.

    Example 1:

    >>> maxScore(nums = [2,4,1])
    >>> 6
    Explanation:
    The possible operations are:

    Remove the first two elements (2 + 4) = 6. The remaining array is [1].
    Remove the last two elements (4 + 1) = 5. The remaining array is [2].
    Remove the first and last elements (2 + 1) = 3. The remaining array is [4].

    The maximum score is obtained by removing the first two elements, resulting in a final score of 6.

    Example 2:

    >>> maxScore(nums = [5,-1,4,2])
    >>> 7
    Explanation:
    The possible operations are:

    Remove the first and last elements (5 + 2) = 7. The remaining array is [-1, 4].
    Remove the first two elements (5 + -1) = 4. The remaining array is [4, 2].
    Remove the last two elements (4 + 2) = 6. The remaining array is [5, -1].

    The maximum score is obtained by removing the first and last elements, resulting in a total score of 7.
    """


Prompt:
def reverseDegree(s: str) -> int:
    """
    Given a string s, calculate its reverse degree.
    The reverse degree is calculated as follows:

    For each character, multiply its position in the reversed alphabet ('a' = 26, 'b' = 25, ..., 'z' = 1) with its position in the string (1-indexed).
    Sum these products for all characters in the string.

    Return the reverse degree of s.

    Example 1:

    >>> reverseDegree(s = "abc")
    >>> 148
    Explanation:

    Letter
    Index in Reversed Alphabet
    Index in String
    Product

    'a'
    26
    1
    26

    'b'
    25
    2
    50

    'c'
    24
    3
    72

    The reversed degree is 26 + 50 + 72 = 148.

    Example 2:

    >>> reverseDegree(s = "zaza")
    >>> 160
    Explanation:

    Letter
    Index in Reversed Alphabet
    Index in String
    Product

    'z'
    1
    1
    1

    'a'
    26
    2
    52

    'z'
    1
    3
    3

    'a'
    26
    4
    104

    The reverse degree is 1 + 52 + 3 + 104 = 160.
    """


Prompt:
def maxActiveSectionsAfterTrade(s: str) -> int:
    """
    You are given a binary string s of length n, where:

    '1' represents an active section.
    '0' represents an inactive section.

    You can perform at most one trade to maximize the number of active sections in s. In a trade, you:

    Convert a contiguous block of '1's that is surrounded by '0's to all '0's.
    Afterward, convert a contiguous block of '0's that is surrounded by '1's to all '1's.

    Return the maximum number of active sections in s after making the optimal trade.
    Note: Treat s as if it is augmented with a '1' at both ends, forming t = '1' + s + '1'. The augmented '1's do not contribute to the final count.

    Example 1:

    >>> maxActiveSectionsAfterTrade(s = "01")
    >>> 1
    Explanation:
    Because there is no block of '1's surrounded by '0's, no valid trade is possible. The maximum number of active sections is 1.

    Example 2:

    >>> maxActiveSectionsAfterTrade(s = "0100")
    >>> 4
    Explanation:

    String "0100" → Augmented to "101001".
    Choose "0100", convert "101001" → "100001" → "111111".
    The final string without augmentation is "1111". The maximum number of active sections is 4.

    Example 3:

    >>> maxActiveSectionsAfterTrade(s = "1000100")
    >>> 7
    Explanation:

    String "1000100" → Augmented to "110001001".
    Choose "000100", convert "110001001" → "110000001" → "111111111".
    The final string without augmentation is "1111111". The maximum number of active sections is 7.

    Example 4:

    >>> maxActiveSectionsAfterTrade(s = "01010")
    >>> 4
    Explanation:

    String "01010" → Augmented to "1010101".
    Choose "010", convert "1010101" → "1000101" → "1111101".
    The final string without augmentation is "11110". The maximum number of active sections is 4.
    """


Prompt:
from typing import List
def minimumCost(nums: List[int], cost: List[int], k: int) -> int:
    """
    You are given two integer arrays, nums and cost, of the same size, and an integer k.
    You can divide nums into subarrays. The cost of the ith subarray consisting of elements nums[l..r] is:

    (nums[0] + nums[1] + ... + nums[r] + k * i) * (cost[l] + cost[l + 1] + ... + cost[r]).

    Note that i represents the order of the subarray: 1 for the first subarray, 2 for the second, and so on.
    Return the minimum total cost possible from any valid division.

    Example 1:

    >>> minimumCost(nums = [3,1,4], cost = [4,6,6], k = 1)
    >>> 110
    Explanation:
    The minimum total cost possible can be achieved by dividing nums into subarrays [3, 1] and [4].

    The cost of the first subarray [3,1] is (3 + 1 + 1 * 1) * (4 + 6) = 50.
    The cost of the second subarray [4] is (3 + 1 + 4 + 1 * 2) * 6 = 60.

    Example 2:

    >>> minimumCost(nums = [4,8,5,1,14,2,2,12,1], cost = [7,2,8,4,2,2,1,1,2], k = 7)
    >>> 985
    Explanation:
    The minimum total cost possible can be achieved by dividing nums into subarrays [4, 8, 5, 1], [14, 2, 2], and [12, 1].

    The cost of the first subarray [4, 8, 5, 1] is (4 + 8 + 5 + 1 + 7 * 1) * (7 + 2 + 8 + 4) = 525.
    The cost of the second subarray [14, 2, 2] is (4 + 8 + 5 + 1 + 14 + 2 + 2 + 7 * 2) * (2 + 2 + 1) = 250.
    The cost of the third subarray [12, 1] is (4 + 8 + 5 + 1 + 14 + 2 + 2 + 12 + 1 + 7 * 3) * (1 + 2) = 210.
    """


Prompt:
from typing import List
def maxActiveSectionsAfterTrade(s: str, queries: List[List[int]]) -> List[int]:
    """
    You are given a binary string s of length n, where:

    '1' represents an active section.
    '0' represents an inactive section.

    You can perform at most one trade to maximize the number of active sections in s. In a trade, you:

    Convert a contiguous block of '1's that is surrounded by '0's to all '0's.
    Afterward, convert a contiguous block of '0's that is surrounded by '1's to all '1's.

    Additionally, you are given a 2D array queries, where queries[i] = [li, ri] represents a substring s[li...ri].
    For each query, determine the maximum possible number of active sections in s after making the optimal trade on the substring s[li...ri].
    Return an array answer, where answer[i] is the result for queries[i].
    Note

    For each query, treat s[li...ri] as if it is augmented with a '1' at both ends, forming t = '1' + s[li...ri] + '1'. The augmented '1's do not contribute to the final count.
    The queries are independent of each other.

    Example 1:

    >>> maxActiveSectionsAfterTrade(s = "01", queries = [[0,1]])
    >>> [1]
    Explanation:
    Because there is no block of '1's surrounded by '0's, no valid trade is possible. The maximum number of active sections is 1.

    Example 2:

    >>> maxActiveSectionsAfterTrade(s = "0100", queries = [[0,3],[0,2],[1,3],[2,3]])
    >>> [4,3,1,1]
    Explanation:

    Query [0, 3] → Substring "0100" → Augmented to "101001"
    	Choose "0100", convert "0100" → "0000" → "1111".
    	The final string without augmentation is "1111". The maximum number of active sections is 4.

    Query [0, 2] → Substring "010" → Augmented to "10101"
    	Choose "010", convert "010" → "000" → "111".
    	The final string without augmentation is "1110". The maximum number of active sections is 3.

    Query [1, 3] → Substring "100" → Augmented to "11001"
    	Because there is no block of '1's surrounded by '0's, no valid trade is possible. The maximum number of active sections is 1.

    Query [2, 3] → Substring "00" → Augmented to "1001"
    	Because there is no block of '1's surrounded by '0's, no valid trade is possible. The maximum number of active sections is 1.

    Example 3:

    >>> maxActiveSectionsAfterTrade(s = "1000100", queries = [[1,5],[0,6],[0,4]])
    >>> [6,7,2]
    Explanation:

    Query [1, 5] → Substring "00010" → Augmented to "1000101"
    	Choose "00010", convert "00010" → "00000" → "11111".
    	The final string without augmentation is "1111110". The maximum number of active sections is 6.

    Query [0, 6] → Substring "1000100" → Augmented to "110001001"
    	Choose "000100", convert "000100" → "000000" → "111111".
    	The final string without augmentation is "1111111". The maximum number of active sections is 7.

    Query [0, 4] → Substring "10001" → Augmented to "1100011"
    	Because there is no block of '1's surrounded by '0's, no valid trade is possible. The maximum number of active sections is 2.

    Example 4:

    >>> maxActiveSectionsAfterTrade(s = "01010", queries = [[0,3],[1,4],[1,3]])
    >>> [4,4,2]
    Explanation:

    Query [0, 3] → Substring "0101" → Augmented to "101011"
    	Choose "010", convert "010" → "000" → "111".
    	The final string without augmentation is "11110". The maximum number of active sections is 4.

    Query [1, 4] → Substring "1010" → Augmented to "110101"
    	Choose "010", convert "010" → "000" → "111".
    	The final string without augmentation is "01111". The maximum number of active sections is 4.

    Query [1, 3] → Substring "101" → Augmented to "11011"
    	Because there is no block of '1's surrounded by '0's, no valid trade is possible. The maximum number of active sections is 2.
    """


Prompt:
from typing import List
def minCosts(cost: List[int]) -> List[int]:
    """
    You are given an integer array cost of size n. You are currently at position n (at the end of the line) in a line of n + 1 people (numbered from 0 to n).
    You wish to move forward in the line, but each person in front of you charges a specific amount to swap places. The cost to swap with person i is given by cost[i].
    You are allowed to swap places with people as follows:

    If they are in front of you, you must pay them cost[i] to swap with them.
    If they are behind you, they can swap with you for free.

    Return an array answer of size n, where answer[i] is the minimum total cost to reach each position i in the line.

    Example 1:

    >>> minCosts(cost = [5,3,4,1,3,2])
    >>> [5,3,3,1,1,1]
    Explanation:
    We can get to each position in the following way:

    i = 0. We can swap with person 0 for a cost of 5.
    i = 1. We can swap with person 1 for a cost of 3.
    i = 2. We can swap with person 1 for a cost of 3, then swap with person 2 for free.
    i = 3. We can swap with person 3 for a cost of 1.
    i = 4. We can swap with person 3 for a cost of 1, then swap with person 4 for free.
    i = 5. We can swap with person 3 for a cost of 1, then swap with person 5 for free.

    Example 2:

    >>> minCosts(cost = [1,2,4,6,7])
    >>> [1,1,1,1,1]
    Explanation:
    We can swap with person 0 for a cost of 1, then we will be able to reach any position i for free.
    """


Prompt:
def longestPalindrome(s: str, t: str) -> int:
    """
    You are given two strings, s and t.
    You can create a new string by selecting a substring from s (possibly empty) and a substring from t (possibly empty), then concatenating them in order.
    Return the length of the longest palindrome that can be formed this way.

    Example 1:

    >>> longestPalindrome(s = "a", t = "a")
    >>> 2
    Explanation:
    Concatenating "a" from s and "a" from t results in "aa", which is a palindrome of length 2.

    Example 2:

    >>> longestPalindrome(s = "abc", t = "def")
    >>> 1
    Explanation:
    Since all characters are different, the longest palindrome is any single character, so the answer is 1.

    Example 3:

    >>> longestPalindrome(s = "b", t = "aaaa")
    >>> 4
    Explanation:
    Selecting "aaaa" from t is the longest palindrome, so the answer is 4.

    Example 4:

    >>> longestPalindrome(s = "abcde", t = "ecdba")
    >>> 5
    Explanation:
    Concatenating "abc" from s and "ba" from t results in "abcba", which is a palindrome of length 5.
    """


Prompt:
def longestPalindrome(s: str, t: str) -> int:
    """
    You are given two strings, s and t.
    You can create a new string by selecting a substring from s (possibly empty) and a substring from t (possibly empty), then concatenating them in order.
    Return the length of the longest palindrome that can be formed this way.

    Example 1:

    >>> longestPalindrome(s = "a", t = "a")
    >>> 2
    Explanation:
    Concatenating "a" from s and "a" from t results in "aa", which is a palindrome of length 2.

    Example 2:

    >>> longestPalindrome(s = "abc", t = "def")
    >>> 1
    Explanation:
    Since all characters are different, the longest palindrome is any single character, so the answer is 1.

    Example 3:

    >>> longestPalindrome(s = "b", t = "aaaa")
    >>> 4
    Explanation:
    Selecting "aaaa" from t is the longest palindrome, so the answer is 4.

    Example 4:

    >>> longestPalindrome(s = "abcde", t = "ecdba")
    >>> 5
    Explanation:
    Concatenating "abc" from s and "ba" from t results in "abcba", which is a palindrome of length 5.
    """


Prompt:
from typing import List
def minOperations(nums: List[int], x: int, k: int) -> int:
    """
    You are given an integer array nums and two integers, x and k. You can perform the following operation any number of times (including zero):

    Increase or decrease any element of nums by 1.

    Return the minimum number of operations needed to have at least k non-overlapping subarrays of size exactly x in nums, where all elements within each subarray are equal.

    Example 1:

    >>> minOperations(nums = [5,-2,1,3,7,3,6,4,-1], x = 3, k = 2)
    >>> 8
    Explanation:

    Use 3 operations to add 3 to nums[1] and use 2 operations to subtract 2 from nums[3]. The resulting array is [5, 1, 1, 1, 7, 3, 6, 4, -1].
    Use 1 operation to add 1 to nums[5] and use 2 operations to subtract 2 from nums[6]. The resulting array is [5, 1, 1, 1, 7, 4, 4, 4, -1].
    Now, all elements within each subarray [1, 1, 1] (from indices 1 to 3) and [4, 4, 4] (from indices 5 to 7) are equal. Since 8 total operations were used, 8 is the output.

    Example 2:

    >>> minOperations(nums = [9,-2,-2,-2,1,5], x = 2, k = 2)
    >>> 3
    Explanation:

    Use 3 operations to subtract 3 from nums[4]. The resulting array is [9, -2, -2, -2, -2, 5].
    Now, all elements within each subarray [-2, -2] (from indices 1 to 2) and [-2, -2] (from indices 3 to 4) are equal. Since 3 operations were used, 3 is the output.
    """