Prompt:
def robotWithString(s: str) -> str:
    """
    You are given a string s and a robot that currently holds an empty string t. Apply one of the following operations until s and t are both empty:

    Remove the first character of a string s and give it to the robot. The robot will append this character to the string t.
    Remove the last character of a string t and give it to the robot. The robot will write this character on paper.

    Return the lexicographically smallest string that can be written on the paper.

    Example 1:

    >>> robotWithString(s = "zza")
    >>> "azz"
    Explanation: Let p denote the written string.
    Initially p="", s="zza", t="".
    Perform first operation three times p="", s="", t="zza".
    Perform second operation three times p="azz", s="", t="".

    Example 2:

    >>> robotWithString(s = "bac")
    >>> "abc"
    Explanation: Let p denote the written string.
    Perform first operation twice p="", s="c", t="ba".
    Perform second operation twice p="ab", s="c", t="".
    Perform first operation p="ab", s="", t="c".
    Perform second operation p="abc", s="", t="".

    Example 3:

    >>> robotWithString(s = "bdda")
    >>> "addb"
    Explanation: Let p denote the written string.
    Initially p="", s="bdda", t="".
    Perform first operation four times p="", s="", t="bdda".
    Perform second operation four times p="addb", s="", t="".
    """


Prompt:
from typing import List
def numberOfPaths(grid: List[List[int]], k: int) -> int:
    """
    You are given a 0-indexed m x n integer matrix grid and an integer k. You are currently at position (0, 0) and you want to reach position (m - 1, n - 1) moving only down or right.
    Return the number of paths where the sum of the elements on the path is divisible by k. Since the answer may be very large, return it modulo 109 + 7.

    Example 1:

    >>> numberOfPaths(grid = [[5,2,4],[3,0,5],[0,7,2]], k = 3)
    >>> 2
    Explanation: There are two paths where the sum of the elements on the path is divisible by k.
    The first path highlighted in red has a sum of 5 + 2 + 4 + 5 + 2 = 18 which is divisible by 3.
    The second path highlighted in blue has a sum of 5 + 3 + 0 + 5 + 2 = 15 which is divisible by 3.

    Example 2:

    >>> numberOfPaths(grid = [[0,0]], k = 5)
    >>> 1
    Explanation: The path highlighted in red has a sum of 0 + 0 = 0 which is divisible by 5.

    Example 3:

    >>> numberOfPaths(grid = [[7,3,4,9],[2,3,6,2],[2,3,7,0]], k = 1)
    >>> 10
    Explanation: Every integer is divisible by 1 so the sum of the elements on every possible path is divisible by k.
    """


Prompt:
from typing import List
def minimumSplits(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    Split the array into one or more disjoint subarrays such that:

    Each element of the array belongs to exactly one subarray, and
    The GCD of the elements of each subarray is strictly greater than 1.

    Return the minimum number of subarrays that can be obtained after the split.
    Note that:

    The GCD of a subarray is the largest positive integer that evenly divides all the elements of the subarray.
    A subarray is a contiguous part of the array.

    Example 1:

    >>> minimumSplits(nums = [12,6,3,14,8])
    >>> 2
    Explanation: We can split the array into the subarrays: [12,6,3] and [14,8].
    - The GCD of 12, 6 and 3 is 3, which is strictly greater than 1.
    - The GCD of 14 and 8 is 2, which is strictly greater than 1.
    It can be shown that splitting the array into one subarray will make the GCD = 1.

    Example 2:

    >>> minimumSplits(nums = [4,12,6,14])
    >>> 1
    Explanation: We can split the array into only one subarray, which is the whole array.
    """


Prompt:
def countTime(time: str) -> int:
    """
    You are given a string of length 5 called time, representing the current time on a digital clock in the format "hh:mm". The earliest possible time is "00:00" and the latest possible time is "23:59".
    In the string time, the digits represented by the ? symbol are unknown, and must be replaced with a digit from 0 to 9.
    Return an integer answer, the number of valid clock times that can be created by replacing every ? with a digit from 0 to 9.

    Example 1:

    >>> countTime(time = "?5:00")
    >>> 2
    Explanation: We can replace the ? with either a 0 or 1, producing "05:00" or "15:00". Note that we cannot replace it with a 2, since the time "25:00" is invalid. In total, we have two choices.

    Example 2:

    >>> countTime(time = "0?:0?")
    >>> 100
    Explanation: Each ? can be replaced by any digit from 0 to 9, so we have 100 total choices.

    Example 3:

    >>> countTime(time = "??:??")
    >>> 1440
    Explanation: There are 24 possible choices for the hours, and 60 possible choices for the minutes. In total, we have 24 * 60 = 1440 choices.
    """


Prompt:
from typing import List
def productQueries(n: int, queries: List[List[int]]) -> List[int]:
    """
    Given a positive integer n, there exists a 0-indexed array called powers, composed of the minimum number of powers of 2 that sum to n. The array is sorted in non-decreasing order, and there is only one way to form the array.
    You are also given a 0-indexed 2D integer array queries, where queries[i] = [lefti, righti]. Each queries[i] represents a query where you have to find the product of all powers[j] with lefti <= j <= righti.
    Return an array answers, equal in length to queries, where answers[i] is the answer to the ith query. Since the answer to the ith query may be too large, each answers[i] should be returned modulo 109 + 7.

    Example 1:

    >>> productQueries(n = 15, queries = [[0,1],[2,2],[0,3]])
    >>> [2,4,64]
    Explanation:
    For n = 15, powers = [1,2,4,8]. It can be shown that powers cannot be a smaller size.
    Answer to 1st query: powers[0] * powers[1] = 1 * 2 = 2.
    Answer to 2nd query: powers[2] = 4.
    Answer to 3rd query: powers[0] * powers[1] * powers[2] * powers[3] = 1 * 2 * 4 * 8 = 64.
    Each answer modulo 109 + 7 yields the same answer, so [2,4,64] is returned.

    Example 2:

    >>> productQueries(n = 2, queries = [[0,0]])
    >>> [2]
    Explanation:
    For n = 2, powers = [2].
    The answer to the only query is powers[0] = 2. The answer modulo 109 + 7 is the same, so [2] is returned.
    """


Prompt:
from typing import List
def minimizeArrayValue(nums: List[int]) -> int:
    """
    You are given a 0-indexed array nums comprising of n non-negative integers.
    In one operation, you must:

    Choose an integer i such that 1 <= i < n and nums[i] > 0.
    Decrease nums[i] by 1.
    Increase nums[i - 1] by 1.

    Return the minimum possible value of the maximum integer of nums after performing any number of operations.

    Example 1:

    >>> minimizeArrayValue(nums = [3,7,1,6])
    >>> 5
    Explanation:
    One set of optimal operations is as follows:
    1. Choose i = 1, and nums becomes [4,6,1,6].
    2. Choose i = 3, and nums becomes [4,6,2,5].
    3. Choose i = 1, and nums becomes [5,5,2,5].
    The maximum integer of nums is 5. It can be shown that the maximum number cannot be less than 5.
    Therefore, we return 5.

    Example 2:

    >>> minimizeArrayValue(nums = [10,1])
    >>> 10
    Explanation:
    It is optimal to leave nums as is, and since 10 is the maximum value, we return 10.
    """


Prompt:
from typing import List
def componentValue(nums: List[int], edges: List[List[int]]) -> int:
    """
    There is an undirected tree with n nodes labeled from 0 to n - 1.
    You are given a 0-indexed integer array nums of length n where nums[i] represents the value of the ith node. You are also given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.
    You are allowed to delete some edges, splitting the tree into multiple connected components. Let the value of a component be the sum of all nums[i] for which node i is in the component.
    Return the maximum number of edges you can delete, such that every connected component in the tree has the same value.

    Example 1:

    >>> componentValue(nums = [6,2,2,2,6], edges = [[0,1],[1,2],[1,3],[3,4]])
    >>> 2
    Explanation: The above figure shows how we can delete the edges [0,1] and [3,4]. The created components are nodes [0], [1,2,3] and [4]. The sum of the values in each component equals 6. It can be proven that no better deletion exists, so the answer is 2.

    Example 2:

    >>> componentValue(nums = [2], edges = [])
    >>> 0
    Explanation: There are no edges to be deleted.
    """


Prompt:
from typing import List
def findMaxK(nums: List[int]) -> int:
    """
    Given an integer array nums that does not contain any zeros, find the largest positive integer k such that -k also exists in the array.
    Return the positive integer k. If there is no such integer, return -1.

    Example 1:

    >>> findMaxK(nums = [-1,2,-3,3])
    >>> 3
    Explanation: 3 is the only valid k we can find in the array.

    Example 2:

    >>> findMaxK(nums = [-1,10,6,7,-7,1])
    >>> 7
    Explanation: Both 1 and 7 have their corresponding negative values in the array. 7 has a larger value.

    Example 3:

    >>> findMaxK(nums = [-10,8,6,7,-2,-3])
    >>> -1
    Explanation: There is no a single valid k, we return -1.
    """


Prompt:
from typing import List
def countDistinctIntegers(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.
    You have to take each integer in the array, reverse its digits, and add it to the end of the array. You should apply this operation to the original integers in nums.
    Return the number of distinct integers in the final array.

    Example 1:

    >>> countDistinctIntegers(nums = [1,13,10,12,31])
    >>> 6
    Explanation: After including the reverse of each number, the resulting array is [1,13,10,12,31,1,31,1,21,13].
    The reversed integers that were added to the end of the array are underlined. Note that for the integer 10, after reversing it, it becomes 01 which is just 1.
    The number of distinct integers in this array is 6 (The numbers 1, 10, 12, 13, 21, and 31).
    Example 2:

    >>> countDistinctIntegers(nums = [2,2,2])
    >>> 1
    Explanation: After including the reverse of each number, the resulting array is [2,2,2,2,2,2].
    The number of distinct integers in this array is 1 (The number 2).
    """


Prompt:
def sumOfNumberAndReverse(num: int) -> bool:
    """
    Given a non-negative integer num, return true if num can be expressed as the sum of any non-negative integer and its reverse, or false otherwise.

    Example 1:

    >>> sumOfNumberAndReverse(num = 443)
    >>> true
    Explanation: 172 + 271 = 443 so we return true.

    Example 2:

    >>> sumOfNumberAndReverse(num = 63)
    >>> false
    Explanation: 63 cannot be expressed as the sum of a non-negative integer and its reverse so we return false.

    Example 3:

    >>> sumOfNumberAndReverse(num = 181)
    >>> true
    Explanation: 140 + 041 = 181 so we return true. Note that when a number is reversed, there may be leading zeros.
    """


Prompt:
from typing import List
def countSubarrays(nums: List[int], minK: int, maxK: int) -> int:
    """
    You are given an integer array nums and two integers minK and maxK.
    A fixed-bound subarray of nums is a subarray that satisfies the following conditions:

    The minimum value in the subarray is equal to minK.
    The maximum value in the subarray is equal to maxK.

    Return the number of fixed-bound subarrays.
    A subarray is a contiguous part of an array.

    Example 1:

    >>> countSubarrays(nums = [1,3,5,2,7,5], minK = 1, maxK = 5)
    >>> 2
    Explanation: The fixed-bound subarrays are [1,3,5] and [1,3,5,2].

    Example 2:

    >>> countSubarrays(nums = [1,1,1,1], minK = 1, maxK = 1)
    >>> 10
    Explanation: Every subarray of nums is a fixed-bound subarray. There are 10 possible subarrays.
    """


Prompt:
from typing import List
def numberOfNodes(n: int, queries: List[int]) -> int:
    """
    There is an undirected connected tree with n nodes labeled from 1 to n and n - 1 edges. You are given the integer n. The parent node of a node with a label v is the node with the label floor (v / 2). The root of the tree is the node with the label 1.

    For example, if n = 7, then the node with the label 3 has the node with the label floor(3 / 2) = 1 as its parent, and the node with the label 7 has the node with the label floor(7 / 2) = 3 as its parent.

    You are also given an integer array queries. Initially, every node has a value 0 on it. For each query queries[i], you should flip all values in the subtree of the node with the label queries[i].
    Return the total number of nodes with the value 1 after processing all the queries.
    Note that:

    Flipping the value of a node means that the node with the value 0 becomes 1 and vice versa.
    floor(x) is equivalent to rounding x down to the nearest integer.

    Example 1:

    >>> numberOfNodes(n = 5 , queries = [1,2,5])
    >>> 3
    Explanation: The diagram above shows the tree structure and its status after performing the queries. The blue node represents the value 0, and the red node represents the value 1.
    After processing the queries, there are three red nodes (nodes with value 1): 1, 3, and 5.

    Example 2:

    >>> numberOfNodes(n = 3, queries = [2,3,3])
    >>> 1
    Explanation: The diagram above shows the tree structure and its status after performing the queries. The blue node represents the value 0, and the red node represents the value 1.
    After processing the queries, there are one red node (node with value 1): 2.
    """


Prompt:
from typing import List
def haveConflict(event1: List[str], event2: List[str]) -> bool:
    """
    You are given two arrays of strings that represent two inclusive events that happened on the same day, event1 and event2, where:

    event1 = [startTime1, endTime1] and
    event2 = [startTime2, endTime2].

    Event times are valid 24 hours format in the form of HH:MM.
    A conflict happens when two events have some non-empty intersection (i.e., some moment is common to both events).
    Return true if there is a conflict between two events. Otherwise, return false.

    Example 1:

    >>> haveConflict(event1 = ["01:15","02:00"], event2 = ["02:00","03:00"])
    >>> true
    Explanation: The two events intersect at time 2:00.

    Example 2:

    >>> haveConflict(event1 = ["01:00","02:00"], event2 = ["01:20","03:00"])
    >>> true
    Explanation: The two events intersect starting from 01:20 to 02:00.

    Example 3:

    >>> haveConflict(event1 = ["10:00","11:00"], event2 = ["14:00","15:00"])
    >>> false
    Explanation: The two events do not intersect.
    """


Prompt:
from typing import List
def subarrayGCD(nums: List[int], k: int) -> int:
    """
    Given an integer array nums and an integer k, return the number of subarrays of nums where the greatest common divisor of the subarray's elements is k.
    A subarray is a contiguous non-empty sequence of elements within an array.
    The greatest common divisor of an array is the largest integer that evenly divides all the array elements.

    Example 1:

    >>> subarrayGCD(nums = [9,3,1,2,6,3], k = 3)
    >>> 4
    Explanation: The subarrays of nums where 3 is the greatest common divisor of all the subarray's elements are:
    - [9,3,1,2,6,3]
    - [9,3,1,2,6,3]
    - [9,3,1,2,6,3]
    - [9,3,1,2,6,3]

    Example 2:

    >>> subarrayGCD(nums = [4], k = 7)
    >>> 0
    Explanation: There are no subarrays of nums where 7 is the greatest common divisor of all the subarray's elements.
    """


Prompt:
from typing import List
def minCost(nums: List[int], cost: List[int]) -> int:
    """
    You are given two 0-indexed arrays nums and cost consisting each of n positive integers.
    You can do the following operation any number of times:

    Increase or decrease any element of the array nums by 1.

    The cost of doing one operation on the ith element is cost[i].
    Return the minimum total cost such that all the elements of the array nums become equal.

    Example 1:

    >>> minCost(nums = [1,3,5,2], cost = [2,3,1,14])
    >>> 8
    Explanation: We can make all the elements equal to 2 in the following way:
    - Increase the 0th element one time. The cost is 2.
    - Decrease the 1st element one time. The cost is 3.
    - Decrease the 2nd element three times. The cost is 1 + 1 + 1 = 3.
    The total cost is 2 + 3 + 3 = 8.
    It can be shown that we cannot make the array equal with a smaller cost.

    Example 2:

    >>> minCost(nums = [2,2,2,2,2], cost = [4,2,8,1,3])
    >>> 0
    Explanation: All the elements are already equal, so no operations are needed.
    """


Prompt:
from typing import List
def makeSimilar(nums: List[int], target: List[int]) -> int:
    """
    You are given two positive integer arrays nums and target, of the same length.
    In one operation, you can choose any two distinct indices i and j where 0 <= i, j < nums.length and:

    set nums[i] = nums[i] + 2 and
    set nums[j] = nums[j] - 2.

    Two arrays are considered to be similar if the frequency of each element is the same.
    Return the minimum number of operations required to make nums similar to target. The test cases are generated such that nums can always be similar to target.

    Example 1:

    >>> makeSimilar(nums = [8,12,6], target = [2,14,10])
    >>> 2
    Explanation: It is possible to make nums similar to target in two operations:
    - Choose i = 0 and j = 2, nums = [10,12,4].
    - Choose i = 1 and j = 2, nums = [10,14,2].
    It can be shown that 2 is the minimum number of operations needed.

    Example 2:

    >>> makeSimilar(nums = [1,2,5], target = [4,1,3])
    >>> 1
    Explanation: We can make nums similar to target in one operation:
    - Choose i = 1 and j = 2, nums = [1,4,3].

    Example 3:

    >>> makeSimilar(nums = [1,1,1,1,1], target = [1,1,1,1,1])
    >>> 0
    Explanation: The array nums is already similiar to target.
    """


Prompt:
def countDistinctStrings(s: str, k: int) -> int:
    """
    You are given a binary string s and a positive integer k.
    You can apply the following operation on the string any number of times:

    Choose any substring of size k from s and flip all its characters, that is, turn all 1's into 0's, and all 0's into 1's.

    Return the number of distinct strings you can obtain. Since the answer may be too large, return it modulo 109 + 7.
    Note that:

    A binary string is a string that consists only of the characters 0 and 1.
    A substring is a contiguous part of a string.

    Example 1:

    >>> countDistinctStrings(s = "1001", k = 3)
    >>> 4
    Explanation: We can obtain the following strings:
    - Applying no operation on the string gives s = "1001".
    - Applying one operation on the substring starting at index 0 gives s = "0111".
    - Applying one operation on the substring starting at index 1 gives s = "1110".
    - Applying one operation on both the substrings starting at indices 0 and 1 gives s = "0000".
    It can be shown that we cannot obtain any other string, so the answer is 4.
    Example 2:

    >>> countDistinctStrings(s = "10110", k = 5)
    >>> 2
    Explanation: We can obtain the following strings:
    - Applying no operation on the string gives s = "10110".
    - Applying one operation on the whole string gives s = "01001".
    It can be shown that we cannot obtain any other string, so the answer is 2.
    """


Prompt:
from typing import List
def oddString(words: List[str]) -> str:
    """
    You are given an array of equal-length strings words. Assume that the length of each string is n.
    Each string words[i] can be converted into a difference integer array difference[i] of length n - 1 where difference[i][j] = words[i][j+1] - words[i][j] where 0 <= j <= n - 2. Note that the difference between two letters is the difference between their positions in the alphabet i.e. the position of 'a' is 0, 'b' is 1, and 'z' is 25.

    For example, for the string "acb", the difference integer array is [2 - 0, 1 - 2] = [2, -1].

    All the strings in words have the same difference integer array, except one. You should find that string.
    Return the string in words that has different difference integer array.

    Example 1:

    >>> oddString(words = ["adc","wzy","abc"])
    >>> "abc"
    Explanation:
    - The difference integer array of "adc" is [3 - 0, 2 - 3] = [3, -1].
    - The difference integer array of "wzy" is [25 - 22, 24 - 25]= [3, -1].
    - The difference integer array of "abc" is [1 - 0, 2 - 1] = [1, 1].
    The odd array out is [1, 1], so we return the corresponding string, "abc".

    Example 2:

    >>> oddString(words = ["aaa","bob","ccc","ddd"])
    >>> "bob"
    Explanation: All the integer arrays are [0, 0] except for "bob", which corresponds to [13, -13].
    """


Prompt:
from typing import List
def twoEditWords(queries: List[str], dictionary: List[str]) -> List[str]:
    """
    You are given two string arrays, queries and dictionary. All words in each array comprise of lowercase English letters and have the same length.
    In one edit you can take a word from queries, and change any letter in it to any other letter. Find all words from queries that, after a maximum of two edits, equal some word from dictionary.
    Return a list of all words from queries, that match with some word from dictionary after a maximum of two edits. Return the words in the same order they appear in queries.

    Example 1:

    >>> twoEditWords(queries = ["word","note","ants","wood"], dictionary = ["wood","joke","moat"])
    >>> ["word","note","wood"]
    Explanation:
    - Changing the 'r' in "word" to 'o' allows it to equal the dictionary word "wood".
    - Changing the 'n' to 'j' and the 't' to 'k' in "note" changes it to "joke".
    - It would take more than 2 edits for "ants" to equal a dictionary word.
    - "wood" can remain unchanged (0 edits) and match the corresponding dictionary word.
    Thus, we return ["word","note","wood"].

    Example 2:

    >>> twoEditWords(queries = ["yes"], dictionary = ["not"])
    >>> []
    Explanation:
    Applying any two edits to "yes" cannot make it equal to "not". Thus, we return an empty array.
    """


Prompt:
from typing import List
def destroyTargets(nums: List[int], space: int) -> int:
    """
    You are given a 0-indexed array nums consisting of positive integers, representing targets on a number line. You are also given an integer space.
    You have a machine which can destroy targets. Seeding the machine with some nums[i] allows it to destroy all targets with values that can be represented as nums[i] + c * space, where c is any non-negative integer. You want to destroy the maximum number of targets in nums.
    Return the minimum value of nums[i] you can seed the machine with to destroy the maximum number of targets.

    Example 1:

    >>> destroyTargets(nums = [3,7,8,1,1,5], space = 2)
    >>> 1
    Explanation: If we seed the machine with nums[3], then we destroy all targets equal to 1,3,5,7,9,...
    In this case, we would destroy 5 total targets (all except for nums[2]).
    It is impossible to destroy more than 5 targets, so we return nums[3].

    Example 2:

    >>> destroyTargets(nums = [1,3,5,2,4,6], space = 2)
    >>> 1
    Explanation: Seeding the machine with nums[0], or nums[3] destroys 3 targets.
    It is not possible to destroy more than 3 targets.
    Since nums[0] is the minimal integer that can destroy 3 targets, we return 1.

    Example 3:

    >>> destroyTargets(nums = [6,2,5], space = 100)
    >>> 2
    Explanation: Whatever initial seed we select, we can only destroy 1 target. The minimal seed is nums[1].
    """


Prompt:
from typing import List
def secondGreaterElement(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed array of non-negative integers nums. For each integer in nums, you must find its respective second greater integer.
    The second greater integer of nums[i] is nums[j] such that:

    j > i
    nums[j] > nums[i]
    There exists exactly one index k such that nums[k] > nums[i] and i < k < j.

    If there is no such nums[j], the second greater integer is considered to be -1.

    For example, in the array [1, 2, 4, 3], the second greater integer of 1 is 4, 2 is 3, and that of 3 and 4 is -1.

    Return an integer array answer, where answer[i] is the second greater integer of nums[i].

    Example 1:

    >>> secondGreaterElement(nums = [2,4,0,9,6])
    >>> [9,6,6,-1,-1]
    Explanation:
    0th index: 4 is the first integer greater than 2, and 9 is the second integer greater than 2, to the right of 2.
    1st index: 9 is the first, and 6 is the second integer greater than 4, to the right of 4.
    2nd index: 9 is the first, and 6 is the second integer greater than 0, to the right of 0.
    3rd index: There is no integer greater than 9 to its right, so the second greater integer is considered to be -1.
    4th index: There is no integer greater than 6 to its right, so the second greater integer is considered to be -1.
    Thus, we return [9,6,6,-1,-1].

    Example 2:

    >>> secondGreaterElement(nums = [3,3])
    >>> [-1,-1]
    Explanation:
    We return [-1,-1] since neither integer has any integer greater than it.
    """


Prompt:
from typing import List
def averageValue(nums: List[int]) -> int:
    """
    Given an integer array nums of positive integers, return the average value of all even integers that are divisible by 3.
    Note that the average of n elements is the sum of the n elements divided by n and rounded down to the nearest integer.

    Example 1:

    >>> averageValue(nums = [1,3,6,10,12,15])
    >>> 9
    Explanation: 6 and 12 are even numbers that are divisible by 3. (6 + 12) / 2 = 9.

    Example 2:

    >>> averageValue(nums = [1,2,4,7,10])
    >>> 0
    Explanation: There is no single number that satisfies the requirement, so return 0.
    """


Prompt:
from typing import List
def mostPopularCreator(creators: List[str], ids: List[str], views: List[int]) -> List[List[str]]:
    """
    You are given two string arrays creators and ids, and an integer array views, all of length n. The ith video on a platform was created by creators[i], has an id of ids[i], and has views[i] views.
    The popularity of a creator is the sum of the number of views on all of the creator's videos. Find the creator with the highest popularity and the id of their most viewed video.

    If multiple creators have the highest popularity, find all of them.
    If multiple videos have the highest view count for a creator, find the lexicographically smallest id.

    Note: It is possible for different videos to have the same id, meaning that ids do not uniquely identify a video. For example, two videos with the same ID are considered as distinct videos with their own viewcount.
    Return a 2D array of strings answer where answer[i] = [creatorsi, idi] means that creatorsi has the highest popularity and idi is the id of their most popular video. The answer can be returned in any order.

    Example 1:

    >>> mostPopularCreator(creators = ["alice","bob","alice","chris"], ids = ["one","two","three","four"], views = [5,10,5,4])
    >>> [["alice","one"],["bob","two"]]
    Explanation:
    The popularity of alice is 5 + 5 = 10.
    The popularity of bob is 10.
    The popularity of chris is 4.
    alice and bob are the most popular creators.
    For bob, the video with the highest view count is "two".
    For alice, the videos with the highest view count are "one" and "three". Since "one" is lexicographically smaller than "three", it is included in the answer.

    Example 2:

    >>> mostPopularCreator(creators = ["alice","alice","alice"], ids = ["a","b","c"], views = [1,2,2])
    >>> [["alice","b"]]
    Explanation:
    The videos with id "b" and "c" have the highest view count.
    Since "b" is lexicographically smaller than "c", it is included in the answer.
    """


Prompt:
def makeIntegerBeautiful(n: int, target: int) -> int:
    """
    You are given two positive integers n and target.
    An integer is considered beautiful if the sum of its digits is less than or equal to target.
    Return the minimum non-negative integer x such that n + x is beautiful. The input will be generated such that it is always possible to make n beautiful.

    Example 1:

    >>> makeIntegerBeautiful(n = 16, target = 6)
    >>> 4
    Explanation: Initially n is 16 and its digit sum is 1 + 6 = 7. After adding 4, n becomes 20 and digit sum becomes 2 + 0 = 2. It can be shown that we can not make n beautiful with adding non-negative integer less than 4.

    Example 2:

    >>> makeIntegerBeautiful(n = 467, target = 6)
    >>> 33
    Explanation: Initially n is 467 and its digit sum is 4 + 6 + 7 = 17. After adding 33, n becomes 500 and digit sum becomes 5 + 0 + 0 = 5. It can be shown that we can not make n beautiful with adding non-negative integer less than 33.

    Example 3:

    >>> makeIntegerBeautiful(n = 1, target = 1)
    >>> 0
    Explanation: Initially n is 1 and its digit sum is 1, which is already smaller than or equal to target.
    """


Prompt:
from typing import List, Optional
class TreeNode:
    def __init__(val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
def treeQueries(root: Optional[TreeNode], queries: List[int]) -> List[int]:
"""
You are given the root of a binary tree with n nodes. Each node is assigned a unique value from 1 to n. You are also given an array queries of size m.
You have to perform m independent queries on the tree where in the ith query you do the following:

Remove the subtree rooted at the node with the value queries[i] from the tree. It is guaranteed that queries[i] will not be equal to the value of the root.

Return an array answer of size m where answer[i] is the height of the tree after performing the ith query.
Note:

The queries are independent, so the tree returns to its initial state after each query.
The height of a tree is the number of edges in the longest simple path from the root to some node in the tree.

Example 1:

>>> treeQueries(root = [1,3,4,2,null,6,5,null,null,null,null,null,7], queries = [4])
>>> [2]
Explanation: The diagram above shows the tree after removing the subtree rooted at node with value 4.
The height of the tree is 2 (The path 1 -> 3 -> 2).

Example 2:

>>> treeQueries(root = [5,8,9,2,1,3,7,4,6], queries = [3,2,4,8])
>>> [3,2,3,2]
Explanation: We have the following queries:
- Removing the subtree rooted at node with value 3. The height of the tree becomes 3 (The path 5 -> 8 -> 2 -> 4).
- Removing the subtree rooted at node with value 2. The height of the tree becomes 2 (The path 5 -> 8 -> 1).
- Removing the subtree rooted at node with value 4. The height of the tree becomes 3 (The path 5 -> 8 -> 2 -> 6).
- Removing the subtree rooted at node with value 8. The height of the tree becomes 2 (The path 5 -> 9 -> 3).
"""


Prompt:
from typing import List
def sortArray(nums: List[int]) -> int:
    """
    You are given an integer array nums of size n containing each element from 0 to n - 1 (inclusive). Each of the elements from 1 to n - 1 represents an item, and the element 0 represents an empty space.
    In one operation, you can move any item to the empty space. nums is considered to be sorted if the numbers of all the items are in ascending order and the empty space is either at the beginning or at the end of the array.
    For example, if n = 4, nums is sorted if:

    nums = [0,1,2,3] or
    nums = [1,2,3,0]

    ...and considered to be unsorted otherwise.
    Return the minimum number of operations needed to sort nums.

    Example 1:

    >>> sortArray(nums = [4,2,0,3,1])
    >>> 3
    Explanation:
    - Move item 2 to the empty space. Now, nums = [4,0,2,3,1].
    - Move item 1 to the empty space. Now, nums = [4,1,2,3,0].
    - Move item 4 to the empty space. Now, nums = [0,1,2,3,4].
    It can be proven that 3 is the minimum number of operations needed.

    Example 2:

    >>> sortArray(nums = [1,2,3,4,0])
    >>> 0
    Explanation: nums is already sorted so return 0.

    Example 3:

    >>> sortArray(nums = [1,0,2,4,3])
    >>> 2
    Explanation:
    - Move item 2 to the empty space. Now, nums = [1,2,0,4,3].
    - Move item 3 to the empty space. Now, nums = [1,2,3,4,0].
    It can be proven that 2 is the minimum number of operations needed.
    """


Prompt:
from typing import List
def applyOperations(nums: List[int]) -> List[int]:
    """
    You are given a 0-indexed array nums of size n consisting of non-negative integers.
    You need to apply n - 1 operations to this array where, in the ith operation (0-indexed), you will apply the following on the ith element of nums:

    If nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[i + 1] to 0. Otherwise, you skip this operation.

    After performing all the operations, shift all the 0's to the end of the array.

    For example, the array [1,0,2,0,0,1] after shifting all its 0's to the end, is [1,2,1,0,0,0].

    Return the resulting array.
    Note that the operations are applied sequentially, not all at once.

    Example 1:

    >>> applyOperations(nums = [1,2,2,1,1,0])
    >>> [1,4,2,0,0,0]
    Explanation: We do the following operations:
    - i = 0: nums[0] and nums[1] are not equal, so we skip this operation.
    - i = 1: nums[1] and nums[2] are equal, we multiply nums[1] by 2 and change nums[2] to 0. The array becomes [1,4,0,1,1,0].
    - i = 2: nums[2] and nums[3] are not equal, so we skip this operation.
    - i = 3: nums[3] and nums[4] are equal, we multiply nums[3] by 2 and change nums[4] to 0. The array becomes [1,4,0,2,0,0].
    - i = 4: nums[4] and nums[5] are equal, we multiply nums[4] by 2 and change nums[5] to 0. The array becomes [1,4,0,2,0,0].
    After that, we shift the 0's to the end, which gives the array [1,4,2,0,0,0].

    Example 2:

    >>> applyOperations(nums = [0,1])
    >>> [1,0]
    Explanation: No operation can be applied, we just shift the 0 to the end.
    """


Prompt:
from typing import List
def maximumSubarraySum(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and an integer k. Find the maximum subarray sum of all the subarrays of nums that meet the following conditions:

    The length of the subarray is k, and
    All the elements of the subarray are distinct.

    Return the maximum subarray sum of all the subarrays that meet the conditions. If no subarray meets the conditions, return 0.
    A subarray is a contiguous non-empty sequence of elements within an array.

    Example 1:

    >>> maximumSubarraySum(nums = [1,5,4,2,9,9,9], k = 3)
    >>> 15
    Explanation: The subarrays of nums with length 3 are:
    - [1,5,4] which meets the requirements and has a sum of 10.
    - [5,4,2] which meets the requirements and has a sum of 11.
    - [4,2,9] which meets the requirements and has a sum of 15.
    - [2,9,9] which does not meet the requirements because the element 9 is repeated.
    - [9,9,9] which does not meet the requirements because the element 9 is repeated.
    We return 15 because it is the maximum subarray sum of all the subarrays that meet the conditions

    Example 2:

    >>> maximumSubarraySum(nums = [4,4,4], k = 3)
    >>> 0
    Explanation: The subarrays of nums with length 3 are:
    - [4,4,4] which does not meet the requirements because the element 4 is repeated.
    We return 0 because no subarrays meet the conditions.
    """


Prompt:
from typing import List
def totalCost(costs: List[int], k: int, candidates: int) -> int:
    """
    You are given a 0-indexed integer array costs where costs[i] is the cost of hiring the ith worker.
    You are also given two integers k and candidates. We want to hire exactly k workers according to the following rules:

    You will run k sessions and hire exactly one worker in each session.
    In each hiring session, choose the worker with the lowest cost from either the first candidates workers or the last candidates workers. Break the tie by the smallest index.

    For example, if costs = [3,2,7,7,1,2] and candidates = 2, then in the first hiring session, we will choose the 4th worker because they have the lowest cost [3,2,7,7,1,2].
    In the second hiring session, we will choose 1st worker because they have the same lowest cost as 4th worker but they have the smallest index [3,2,7,7,2]. Please note that the indexing may be changed in the process.

    If there are fewer than candidates workers remaining, choose the worker with the lowest cost among them. Break the tie by the smallest index.
    A worker can only be chosen once.

    Return the total cost to hire exactly k workers.

    Example 1:

    >>> totalCost(costs = [17,12,10,2,7,2,11,20,8], k = 3, candidates = 4)
    >>> 11
    Explanation: We hire 3 workers in total. The total cost is initially 0.
    - In the first hiring round we choose the worker from [17,12,10,2,7,2,11,20,8]. The lowest cost is 2, and we break the tie by the smallest index, which is 3. The total cost = 0 + 2 = 2.
    - In the second hiring round we choose the worker from [17,12,10,7,2,11,20,8]. The lowest cost is 2 (index 4). The total cost = 2 + 2 = 4.
    - In the third hiring round we choose the worker from [17,12,10,7,11,20,8]. The lowest cost is 7 (index 3). The total cost = 4 + 7 = 11. Notice that the worker with index 3 was common in the first and last four workers.
    The total hiring cost is 11.

    Example 2:

    >>> totalCost(costs = [1,2,4,1], k = 3, candidates = 3)
    >>> 4
    Explanation: We hire 3 workers in total. The total cost is initially 0.
    - In the first hiring round we choose the worker from [1,2,4,1]. The lowest cost is 1, and we break the tie by the smallest index, which is 0. The total cost = 0 + 1 = 1. Notice that workers with index 1 and 2 are common in the first and last 3 workers.
    - In the second hiring round we choose the worker from [2,4,1]. The lowest cost is 1 (index 2). The total cost = 1 + 1 = 2.
    - In the third hiring round there are less than three candidates. We choose the worker from the remaining workers [2,4]. The lowest cost is 2 (index 0). The total cost = 2 + 2 = 4.
    The total hiring cost is 4.
    """


Prompt:
from typing import List
def minimumTotalDistance(robot: List[int], factory: List[List[int]]) -> int:
    """
    There are some robots and factories on the X-axis. You are given an integer array robot where robot[i] is the position of the ith robot. You are also given a 2D integer array factory where factory[j] = [positionj, limitj] indicates that positionj is the position of the jth factory and that the jth factory can repair at most limitj robots.
    The positions of each robot are unique. The positions of each factory are also unique. Note that a robot can be in the same position as a factory initially.
    All the robots are initially broken; they keep moving in one direction. The direction could be the negative or the positive direction of the X-axis. When a robot reaches a factory that did not reach its limit, the factory repairs the robot, and it stops moving.
    At any moment, you can set the initial direction of moving for some robot. Your target is to minimize the total distance traveled by all the robots.
    Return the minimum total distance traveled by all the robots. The test cases are generated such that all the robots can be repaired.
    Note that

    All robots move at the same speed.
    If two robots move in the same direction, they will never collide.
    If two robots move in opposite directions and they meet at some point, they do not collide. They cross each other.
    If a robot passes by a factory that reached its limits, it crosses it as if it does not exist.
    If the robot moved from a position x to a position y, the distance it moved is |y - x|.

    Example 1:

    >>> minimumTotalDistance(robot = [0,4,6], factory = [[2,2],[6,2]])
    >>> 4
    Explanation: As shown in the figure:
    - The first robot at position 0 moves in the positive direction. It will be repaired at the first factory.
    - The second robot at position 4 moves in the negative direction. It will be repaired at the first factory.
    - The third robot at position 6 will be repaired at the second factory. It does not need to move.
    The limit of the first factory is 2, and it fixed 2 robots.
    The limit of the second factory is 2, and it fixed 1 robot.
    The total distance is |2 - 0| + |2 - 4| + |6 - 6| = 4. It can be shown that we cannot achieve a better total distance than 4.

    Example 2:

    >>> minimumTotalDistance(robot = [1,-1], factory = [[-2,1],[2,1]])
    >>> 2
    Explanation: As shown in the figure:
    - The first robot at position 1 moves in the positive direction. It will be repaired at the second factory.
    - The second robot at position -1 moves in the negative direction. It will be repaired at the first factory.
    The limit of the first factory is 1, and it fixed 1 robot.
    The limit of the second factory is 1, and it fixed 1 robot.
    The total distance is |2 - 1| + |(-2) - (-1)| = 2. It can be shown that we cannot achieve a better total distance than 2.
    """


Prompt:
from typing import List
def validSubarraySplit(nums: List[int]) -> int:
    """
    You are given an integer array nums.
    Splitting of an integer array nums into subarrays is valid if:

    the greatest common divisor of the first and last elements of each subarray is greater than 1, and
    each element of nums belongs to exactly one subarray.

    Return the minimum number of subarrays in a valid subarray splitting of nums. If a valid subarray splitting is not possible, return -1.
    Note that:

    The greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.
    A subarray is a contiguous non-empty part of an array.

    Example 1:

    >>> validSubarraySplit(nums = [2,6,3,4,3])
    >>> 2
    Explanation: We can create a valid split in the following way: [2,6] | [3,4,3].
    - The starting element of the 1st subarray is 2 and the ending is 6. Their greatest common divisor is 2, which is greater than 1.
    - The starting element of the 2nd subarray is 3 and the ending is 3. Their greatest common divisor is 3, which is greater than 1.
    It can be proved that 2 is the minimum number of subarrays that we can obtain in a valid split.

    Example 2:

    >>> validSubarraySplit(nums = [3,5])
    >>> 2
    Explanation: We can create a valid split in the following way: [3] | [5].
    - The starting element of the 1st subarray is 3 and the ending is 3. Their greatest common divisor is 3, which is greater than 1.
    - The starting element of the 2nd subarray is 5 and the ending is 5. Their greatest common divisor is 5, which is greater than 1.
    It can be proved that 2 is the minimum number of subarrays that we can obtain in a valid split.

    Example 3:

    >>> validSubarraySplit(nums = [1,2,1])
    >>> -1
    Explanation: It is impossible to create valid split.
    """


Prompt:
from typing import List
def distinctAverages(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums of even length.
    As long as nums is not empty, you must repetitively:

    Find the minimum number in nums and remove it.
    Find the maximum number in nums and remove it.
    Calculate the average of the two removed numbers.

    The average of two numbers a and b is (a + b) / 2.

    For example, the average of 2 and 3 is (2 + 3) / 2 = 2.5.

    Return the number of distinct averages calculated using the above process.
    Note that when there is a tie for a minimum or maximum number, any can be removed.

    Example 1:

    >>> distinctAverages(nums = [4,1,4,0,3,5])
    >>> 2
    Explanation:
    1. Remove 0 and 5, and the average is (0 + 5) / 2 = 2.5. Now, nums = [4,1,4,3].
    2. Remove 1 and 4. The average is (1 + 4) / 2 = 2.5, and nums = [4,3].
    3. Remove 3 and 4, and the average is (3 + 4) / 2 = 3.5.
    Since there are 2 distinct numbers among 2.5, 2.5, and 3.5, we return 2.

    Example 2:

    >>> distinctAverages(nums = [1,100])
    >>> 1
    Explanation:
    There is only one average to be calculated after removing 1 and 100, so we return 1.
    """


Prompt:
def countGoodStrings(low: int, high: int, zero: int, one: int) -> int:
    """
    Given the integers zero, one, low, and high, we can construct a string by starting with an empty string, and then at each step perform either of the following:

    Append the character '0' zero times.
    Append the character '1' one times.

    This can be performed any number of times.
    A good string is a string constructed by the above process having a length between low and high (inclusive).
    Return the number of different good strings that can be constructed satisfying these properties. Since the answer can be large, return it modulo 109 + 7.

    Example 1:

    >>> countGoodStrings(low = 3, high = 3, zero = 1, one = 1)
    >>> 8
    Explanation:
    One possible valid good string is "011".
    It can be constructed as follows: "" -> "0" -> "01" -> "011".
    All binary strings from "000" to "111" are good strings in this example.

    Example 2:

    >>> countGoodStrings(low = 2, high = 3, zero = 1, one = 2)
    >>> 5
    Explanation: The good strings are "00", "11", "000", "110", and "011".
    """


Prompt:
from typing import List
def mostProfitablePath(edges: List[List[int]], bob: int, amount: List[int]) -> int:
    """
    There is an undirected tree with n nodes labeled from 0 to n - 1, rooted at node 0. You are given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.
    At every node i, there is a gate. You are also given an array of even integers amount, where amount[i] represents:

    the price needed to open the gate at node i, if amount[i] is negative, or,
    the cash reward obtained on opening the gate at node i, otherwise.

    The game goes on as follows:

    Initially, Alice is at node 0 and Bob is at node bob.
    At every second, Alice and Bob each move to an adjacent node. Alice moves towards some leaf node, while Bob moves towards node 0.
    For every node along their path, Alice and Bob either spend money to open the gate at that node, or accept the reward. Note that:

    If the gate is already open, no price will be required, nor will there be any cash reward.
    If Alice and Bob reach the node simultaneously, they share the price/reward for opening the gate there. In other words, if the price to open the gate is c, then both Alice and Bob pay c / 2 each. Similarly, if the reward at the gate is c, both of them receive c / 2 each.

    If Alice reaches a leaf node, she stops moving. Similarly, if Bob reaches node 0, he stops moving. Note that these events are independent of each other.

    Return the maximum net income Alice can have if she travels towards the optimal leaf node.

    Example 1:

    >>> mostProfitablePath(edges = [[0,1],[1,2],[1,3],[3,4]], bob = 3, amount = [-2,4,2,-4,6])
    >>> 6
    Explanation:
    The above diagram represents the given tree. The game goes as follows:
    - Alice is initially on node 0, Bob on node 3. They open the gates of their respective nodes.
      Alice's net income is now -2.
    - Both Alice and Bob move to node 1.
      Since they reach here simultaneously, they open the gate together and share the reward.
      Alice's net income becomes -2 + (4 / 2) = 0.
    - Alice moves on to node 3. Since Bob already opened its gate, Alice's income remains unchanged.
      Bob moves on to node 0, and stops moving.
    - Alice moves on to node 4 and opens the gate there. Her net income becomes 0 + 6 = 6.
    Now, neither Alice nor Bob can make any further moves, and the game ends.
    It is not possible for Alice to get a higher net income.

    Example 2:

    >>> mostProfitablePath(edges = [[0,1]], bob = 1, amount = [-7280,2350])
    >>> -7280
    Explanation:
    Alice follows the path 0->1 whereas Bob follows the path 1->0.
    Thus, Alice opens the gate at node 0 only. Hence, her net income is -7280.
    """


Prompt:
from typing import List
def splitMessage(message: str, limit: int) -> List[str]:
    """
    You are given a string, message, and a positive integer, limit.
    You must split message into one or more parts based on limit. Each resulting part should have the suffix "", where "b" is to be replaced with the total number of parts and "a" is to be replaced with the index of the part, starting from 1 and going up to b. Additionally, the length of each resulting part (including its suffix) should be equal to limit, except for the last part whose length can be at most limit.
    The resulting parts should be formed such that when their suffixes are removed and they are all concatenated in order, they should be equal to message. Also, the result should contain as few parts as possible.
    Return the parts message would be split into as an array of strings. If it is impossible to split message as required, return an empty array.

    Example 1:

    >>> splitMessage(message = "this is really a very awesome message", limit = 9)
    >>> ["thi<1/14>","s i<2/14>","s r<3/14>","eal<4/14>","ly <5/14>","a v<6/14>","ery<7/14>"," aw<8/14>","eso<9/14>","me<10/14>"," m<11/14>","es<12/14>","sa<13/14>","ge<14/14>"]
    Explanation:
    The first 9 parts take 3 characters each from the beginning of message.
    The next 5 parts take 2 characters each to finish splitting message.
    In this example, each part, including the last, has length 9.
    It can be shown it is not possible to split message into less than 14 parts.

    Example 2:

    >>> splitMessage(message = "short message", limit = 15)
    >>> ["short mess<1/2>","age<2/2>"]
    Explanation:
    Under the given constraints, the string can be split into two parts:
    - The first part comprises of the first 10 characters, and has a length 15.
    - The next part comprises of the last 3 characters, and has a length 8.
    """


Prompt:
from typing import List
def convertTemperature(celsius: float) -> List[float]:
    """
    You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius.
    You should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = [kelvin, fahrenheit].
    Return the array ans. Answers within 10-5 of the actual answer will be accepted.
    Note that:

    Kelvin = Celsius + 273.15
    Fahrenheit = Celsius * 1.80 + 32.00

    Example 1:

    >>> convertTemperature(celsius = 36.50)
    >>> [309.65000,97.70000]
    Explanation: Temperature at 36.50 Celsius converted in Kelvin is 309.65 and converted in Fahrenheit is 97.70.

    Example 2:

    >>> convertTemperature(celsius = 122.11)
    >>> [395.26000,251.79800]
    Explanation: Temperature at 122.11 Celsius converted in Kelvin is 395.26 and converted in Fahrenheit is 251.798.
    """


Prompt:
from typing import List
def subarrayLCM(nums: List[int], k: int) -> int:
    """
    Given an integer array nums and an integer k, return the number of subarrays of nums where the least common multiple of the subarray's elements is k.
    A subarray is a contiguous non-empty sequence of elements within an array.
    The least common multiple of an array is the smallest positive integer that is divisible by all the array elements.

    Example 1:

    >>> subarrayLCM(nums = [3,6,2,7,1], k = 6)
    >>> 4
    Explanation: The subarrays of nums where 6 is the least common multiple of all the subarray's elements are:
    - [3,6,2,7,1]
    - [3,6,2,7,1]
    - [3,6,2,7,1]
    - [3,6,2,7,1]

    Example 2:

    >>> subarrayLCM(nums = [3], k = 2)
    >>> 0
    Explanation: There are no subarrays of nums where 2 is the least common multiple of all the subarray's elements.
    """


Prompt:
from typing import Optional
class TreeNode:
    def __init__(val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
def minimumOperations(root: Optional[TreeNode]) -> int:
"""
You are given the root of a binary tree with unique values.
In one operation, you can choose any two nodes at the same level and swap their values.
Return the minimum number of operations needed to make the values at each level sorted in a strictly increasing order.
The level of a node is the number of edges along the path between it and the root node.

Example 1:

>>> minimumOperations(root = [1,4,3,7,6,8,5,null,null,null,null,9,null,10])
>>> 3
Explanation:
- Swap 4 and 3. The 2nd level becomes [3,4].
- Swap 7 and 5. The 3rd level becomes [5,6,8,7].
- Swap 8 and 7. The 3rd level becomes [5,6,7,8].
We used 3 operations so return 3.
It can be proven that 3 is the minimum number of operations needed.

Example 2:

>>> minimumOperations(root = [1,3,2,7,6,5,4])
>>> 3
Explanation:
- Swap 3 and 2. The 2nd level becomes [2,3].
- Swap 7 and 4. The 3rd level becomes [4,6,5,7].
- Swap 6 and 5. The 3rd level becomes [4,5,6,7].
We used 3 operations so return 3.
It can be proven that 3 is the minimum number of operations needed.

Example 3:

>>> minimumOperations(root = [1,2,3,4,5,6])
>>> 0
Explanation: Each level is already sorted in increasing order so return 0.
"""


Prompt:
def maxPalindromes(s: str, k: int) -> int:
    """
    You are given a string s and a positive integer k.
    Select a set of non-overlapping substrings from the string s that satisfy the following conditions:

    The length of each substring is at least k.
    Each substring is a palindrome.

    Return the maximum number of substrings in an optimal selection.
    A substring is a contiguous sequence of characters within a string.

    Example 1:

    >>> maxPalindromes(s = "abaccdbbd", k = 3)
    >>> 2
    Explanation: We can select the substrings underlined in s = "abaccdbbd". Both "aba" and "dbbd" are palindromes and have a length of at least k = 3.
    It can be shown that we cannot find a selection with more than two valid substrings.

    Example 2:

    >>> maxPalindromes(s = "adbcda", k = 2)
    >>> 0
    Explanation: There is no palindrome substring of length at least 2 in the string.
    """


Prompt:
from typing import List
def minCost(n: int, roads: List[List[int]], appleCost: List[int], k: int) -> List[int]:
    """
    You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads, where roads[i] = [ai, bi, costi] indicates that there is a bidirectional road between cities ai and bi with a cost of traveling equal to costi.
    You can buy apples in any city you want, but some cities have different costs to buy apples. You are given the 1-based array appleCost where appleCost[i] is the cost of buying one apple from city i.
    You start at some city, traverse through various roads, and eventually buy exactly one apple from any city. After you buy that apple, you have to return back to the city you started at, but now the cost of all the roads will be multiplied by a given factor k.
    Given the integer k, return a 1-based array answer of size n where answer[i] is the minimum total cost to buy an apple if you start at city i.

    Example 1:

    >>> minCost(n = 4, roads = [[1,2,4],[2,3,2],[2,4,5],[3,4,1],[1,3,4]], appleCost = [56,42,102,301], k = 2)
    >>> [54,42,48,51]
    Explanation: The minimum cost for each starting city is the following:
    - Starting at city 1: You take the path 1 -> 2, buy an apple at city 2, and finally take the path 2 -> 1. The total cost is 4 + 42 + 4 * 2 = 54.
    - Starting at city 2: You directly buy an apple at city 2. The total cost is 42.
    - Starting at city 3: You take the path 3 -> 2, buy an apple at city 2, and finally take the path 2 -> 3. The total cost is 2 + 42 + 2 * 2 = 48.
    - Starting at city 4: You take the path 4 -> 3 -> 2 then you buy at city 2, and finally take the path 2 -> 3 -> 4. The total cost is 1 + 2 + 42 + 1 * 2 + 2 * 2 = 51.

    Example 2:

    >>> minCost(n = 3, roads = [[1,2,5],[2,3,1],[3,1,2]], appleCost = [2,3,1], k = 3)
    >>> [2,3,1]
    Explanation: It is always optimal to buy the apple in the starting city.
    """


Prompt:
from typing import List
def unequalTriplets(nums: List[int]) -> int:
    """
    You are given a 0-indexed array of positive integers nums. Find the number of triplets (i, j, k) that meet the following conditions:

    0 <= i < j < k < nums.length
    nums[i], nums[j], and nums[k] are pairwise distinct.

    In other words, nums[i] != nums[j], nums[i] != nums[k], and nums[j] != nums[k].

    Return the number of triplets that meet the conditions.

    Example 1:

    >>> unequalTriplets(nums = [4,4,2,4,3])
    >>> 3
    Explanation: The following triplets meet the conditions:
    - (0, 2, 4) because 4 != 2 != 3
    - (1, 2, 4) because 4 != 2 != 3
    - (2, 3, 4) because 2 != 4 != 3
    Since there are 3 triplets, we return 3.
    Note that (2, 0, 4) is not a valid triplet because 2 > 0.

    Example 2:

    >>> unequalTriplets(nums = [1,1,1,1,1])
    >>> 0
    Explanation: No triplets meet the conditions so we return 0.
    """


Prompt:
from typing import List, Optional
class TreeNode:
    def __init__(val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
def closestNodes(root: Optional[TreeNode], queries: List[int]) -> List[List[int]]:
"""
You are given the root of a binary search tree and an array queries of size n consisting of positive integers.
Find a 2D array answer of size n where answer[i] = [mini, maxi]:

mini is the largest value in the tree that is smaller than or equal to queries[i]. If a such value does not exist, add -1 instead.
maxi is the smallest value in the tree that is greater than or equal to queries[i]. If a such value does not exist, add -1 instead.

Return the array answer.

Example 1:

>>> closestNodes(root = [6,2,13,1,4,9,15,null,null,null,null,null,null,14], queries = [2,5,16])
>>> [[2,2],[4,6],[15,-1]]
Explanation: We answer the queries in the following way:
- The largest number that is smaller or equal than 2 in the tree is 2, and the smallest number that is greater or equal than 2 is still 2. So the answer for the first query is [2,2].
- The largest number that is smaller or equal than 5 in the tree is 4, and the smallest number that is greater or equal than 5 is 6. So the answer for the second query is [4,6].
- The largest number that is smaller or equal than 16 in the tree is 15, and the smallest number that is greater or equal than 16 does not exist. So the answer for the third query is [15,-1].

Example 2:

>>> closestNodes(root = [4,null,9], queries = [3])
>>> [[-1,4]]
Explanation: The largest number that is smaller or equal to 3 in the tree does not exist, and the smallest number that is greater or equal to 3 is 4. So the answer for the query is [-1,4].
"""


Prompt:
from typing import List
def minimumFuelCost(roads: List[List[int]], seats: int) -> int:
    """
    There is a tree (i.e., a connected, undirected graph with no cycles) structure country network consisting of n cities numbered from 0 to n - 1 and exactly n - 1 roads. The capital city is city 0. You are given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirectional road connecting cities ai and bi.
    There is a meeting for the representatives of each city. The meeting is in the capital city.
    There is a car in each city. You are given an integer seats that indicates the number of seats in each car.
    A representative can use the car in their city to travel or change the car and ride with another representative. The cost of traveling between two cities is one liter of fuel.
    Return the minimum number of liters of fuel to reach the capital city.

    Example 1:

    >>> minimumFuelCost(roads = [[0,1],[0,2],[0,3]], seats = 5)
    >>> 3
    Explanation:
    - Representative1 goes directly to the capital with 1 liter of fuel.
    - Representative2 goes directly to the capital with 1 liter of fuel.
    - Representative3 goes directly to the capital with 1 liter of fuel.
    It costs 3 liters of fuel at minimum.
    It can be proven that 3 is the minimum number of liters of fuel needed.

    Example 2:

    >>> minimumFuelCost(roads = [[3,1],[3,2],[1,0],[0,4],[0,5],[4,6]], seats = 2)
    >>> 7
    Explanation:
    - Representative2 goes directly to city 3 with 1 liter of fuel.
    - Representative2 and representative3 go together to city 1 with 1 liter of fuel.
    - Representative2 and representative3 go together to the capital with 1 liter of fuel.
    - Representative1 goes directly to the capital with 1 liter of fuel.
    - Representative5 goes directly to the capital with 1 liter of fuel.
    - Representative6 goes directly to city 4 with 1 liter of fuel.
    - Representative4 and representative6 go together to the capital with 1 liter of fuel.
    It costs 7 liters of fuel at minimum.
    It can be proven that 7 is the minimum number of liters of fuel needed.

    Example 3:

    >>> minimumFuelCost(roads = [], seats = 1)
    >>> 0
    Explanation: No representatives need to travel to the capital city.
    """


Prompt:
def beautifulPartitions(s: str, k: int, minLength: int) -> int:
    """
    You are given a string s that consists of the digits '1' to '9' and two integers k and minLength.
    A partition of s is called beautiful if:

    s is partitioned into k non-intersecting substrings.
    Each substring has a length of at least minLength.
    Each substring starts with a prime digit and ends with a non-prime digit. Prime digits are '2', '3', '5', and '7', and the rest of the digits are non-prime.

    Return the number of beautiful partitions of s. Since the answer may be very large, return it modulo 109 + 7.
    A substring is a contiguous sequence of characters within a string.

    Example 1:

    >>> beautifulPartitions(s = "23542185131", k = 3, minLength = 2)
    >>> 3
    Explanation: There exists three ways to create a beautiful partition:
    "2354 | 218 | 5131"
    "2354 | 21851 | 31"
    "2354218 | 51 | 31"

    Example 2:

    >>> beautifulPartitions(s = "23542185131", k = 3, minLength = 3)
    >>> 1
    Explanation: There exists one way to create a beautiful partition: "2354 | 218 | 5131".

    Example 3:

    >>> beautifulPartitions(s = "3312958", k = 3, minLength = 1)
    >>> 1
    Explanation: There exists one way to create a beautiful partition: "331 | 29 | 58".
    """


Prompt:
from typing import List
def maxXor(n: int, edges: List[List[int]], values: List[int]) -> int:
    """
    There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. The root of the tree is the node labeled 0.
    Each node has an associated value. You are given an array values of length n, where values[i] is the value of the ith node.
    Select any two non-overlapping subtrees. Your score is the bitwise XOR of the sum of the values within those subtrees.
    Return the maximum possible score you can achieve. If it is impossible to find two nonoverlapping subtrees, return 0.
    Note that:

    The subtree of a node is the tree consisting of that node and all of its descendants.
    Two subtrees are non-overlapping if they do not share any common node.

    Example 1:

    >>> maxXor(n = 6, edges = [[0,1],[0,2],[1,3],[1,4],[2,5]], values = [2,8,3,6,2,5])
    >>> 24
    Explanation: Node 1's subtree has sum of values 16, while node 2's subtree has sum of values 8, so choosing these nodes will yield a score of 16 XOR 8 = 24. It can be proved that is the maximum possible score we can obtain.

    Example 2:

    >>> maxXor(n = 3, edges = [[0,1],[1,2]], values = [4,6,1])
    >>> 0
    Explanation: There is no possible way to select two non-overlapping subtrees, so we just return 0.
    """


Prompt:
def numberOfCuts(n: int) -> int:
    """
    A valid cut in a circle can be:

    A cut that is represented by a straight line that touches two points on the edge of the circle and passes through its center, or
    A cut that is represented by a straight line that touches one point on the edge of the circle and its center.

    Some valid and invalid cuts are shown in the figures below.

    Given the integer n, return the minimum number of cuts needed to divide a circle into n equal slices.

    Example 1:

    >>> numberOfCuts(n = 4)
    >>> 2
    Explanation:
    The above figure shows how cutting the circle twice through the middle divides it into 4 equal slices.

    Example 2:

    >>> numberOfCuts(n = 3)
    >>> 3
    Explanation:
    At least 3 cuts are needed to divide the circle into 3 equal slices.
    It can be shown that less than 3 cuts cannot result in 3 slices of equal size and shape.
    Also note that the first cut will not divide the circle into distinct parts.
    """


Prompt:
from typing import List
def onesMinusZeros(grid: List[List[int]]) -> List[List[int]]:
    """
    You are given a 0-indexed m x n binary matrix grid.
    A 0-indexed m x n difference matrix diff is created with the following procedure:

    Let the number of ones in the ith row be onesRowi.
    Let the number of ones in the jth column be onesColj.
    Let the number of zeros in the ith row be zerosRowi.
    Let the number of zeros in the jth column be zerosColj.
    diff[i][j] = onesRowi + onesColj - zerosRowi - zerosColj

    Return the difference matrix diff.

    Example 1:

    >>> onesMinusZeros(grid = [[0,1,1],[1,0,1],[0,0,1]])
    >>> [[0,0,4],[0,0,4],[-2,-2,2]]
    Explanation:
    - diff[0][0] = onesRow0 + onesCol0 - zerosRow0 - zerosCol0 = 2 + 1 - 1 - 2 = 0
    - diff[0][1] = onesRow0 + onesCol1 - zerosRow0 - zerosCol1 = 2 + 1 - 1 - 2 = 0
    - diff[0][2] = onesRow0 + onesCol2 - zerosRow0 - zerosCol2 = 2 + 3 - 1 - 0 = 4
    - diff[1][0] = onesRow1 + onesCol0 - zerosRow1 - zerosCol0 = 2 + 1 - 1 - 2 = 0
    - diff[1][1] = onesRow1 + onesCol1 - zerosRow1 - zerosCol1 = 2 + 1 - 1 - 2 = 0
    - diff[1][2] = onesRow1 + onesCol2 - zerosRow1 - zerosCol2 = 2 + 3 - 1 - 0 = 4
    - diff[2][0] = onesRow2 + onesCol0 - zerosRow2 - zerosCol0 = 1 + 1 - 2 - 2 = -2
    - diff[2][1] = onesRow2 + onesCol1 - zerosRow2 - zerosCol1 = 1 + 1 - 2 - 2 = -2
    - diff[2][2] = onesRow2 + onesCol2 - zerosRow2 - zerosCol2 = 1 + 3 - 2 - 0 = 2

    Example 2:

    >>> onesMinusZeros(grid = [[1,1,1],[1,1,1]])
    >>> [[5,5,5],[5,5,5]]
    Explanation:
    - diff[0][0] = onesRow0 + onesCol0 - zerosRow0 - zerosCol0 = 3 + 2 - 0 - 0 = 5
    - diff[0][1] = onesRow0 + onesCol1 - zerosRow0 - zerosCol1 = 3 + 2 - 0 - 0 = 5
    - diff[0][2] = onesRow0 + onesCol2 - zerosRow0 - zerosCol2 = 3 + 2 - 0 - 0 = 5
    - diff[1][0] = onesRow1 + onesCol0 - zerosRow1 - zerosCol0 = 3 + 2 - 0 - 0 = 5
    - diff[1][1] = onesRow1 + onesCol1 - zerosRow1 - zerosCol1 = 3 + 2 - 0 - 0 = 5
    - diff[1][2] = onesRow1 + onesCol2 - zerosRow1 - zerosCol2 = 3 + 2 - 0 - 0 = 5
    """


Prompt:
def bestClosingTime(customers: str) -> int:
    """
    You are given the customer visit log of a shop represented by a 0-indexed string customers consisting only of characters 'N' and 'Y':

    if the ith character is 'Y', it means that customers come at the ith hour
    whereas 'N' indicates that no customers come at the ith hour.

    If the shop closes at the jth hour (0 <= j <= n), the penalty is calculated as follows:

    For every hour when the shop is open and no customers come, the penalty increases by 1.
    For every hour when the shop is closed and customers come, the penalty increases by 1.

    Return the earliest hour at which the shop must be closed to incur a minimum penalty.
    Note that if a shop closes at the jth hour, it means the shop is closed at the hour j.

    Example 1:

    >>> bestClosingTime(customers = "YYNY")
    >>> 2
    Explanation:
    - Closing the shop at the 0th hour incurs in 1+1+0+1 = 3 penalty.
    - Closing the shop at the 1st hour incurs in 0+1+0+1 = 2 penalty.
    - Closing the shop at the 2nd hour incurs in 0+0+0+1 = 1 penalty.
    - Closing the shop at the 3rd hour incurs in 0+0+1+1 = 2 penalty.
    - Closing the shop at the 4th hour incurs in 0+0+1+0 = 1 penalty.
    Closing the shop at 2nd or 4th hour gives a minimum penalty. Since 2 is earlier, the optimal closing time is 2.

    Example 2:

    >>> bestClosingTime(customers = "NNNNN")
    >>> 0
    Explanation: It is best to close the shop at the 0th hour as no customers arrive.
    Example 3:

    >>> bestClosingTime(customers = "YYYY")
    >>> 4
    Explanation: It is best to close the shop at the 4th hour as customers arrive at each hour.
    """


Prompt:
def countPalindromes(s: str) -> int:
    """
    Given a string of digits s, return the number of palindromic subsequences of s having length 5. Since the answer may be very large, return it modulo 109 + 7.
    Note:

    A string is palindromic if it reads the same forward and backward.
    A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.

    Example 1:

    >>> countPalindromes(s = "103301")
    >>> 2
    Explanation:
    There are 6 possible subsequences of length 5: "10330","10331","10301","10301","13301","03301".
    Two of them (both equal to "10301") are palindromic.

    Example 2:

    >>> countPalindromes(s = "0000000")
    >>> 21
    Explanation: All 21 subsequences are "00000", which is palindromic.

    Example 3:

    >>> countPalindromes(s = "9999900000")
    >>> 2
    Explanation: The only two palindromic subsequences are "99999" and "00000".
    """


Prompt:
def pivotInteger(n: int) -> int:
    """
    Given a positive integer n, find the pivot integer x such that:

    The sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively.

    Return the pivot integer x. If no such integer exists, return -1. It is guaranteed that there will be at most one pivot index for the given input.

    Example 1:

    >>> pivotInteger(n = 8)
    >>> 6
    Explanation: 6 is the pivot integer since: 1 + 2 + 3 + 4 + 5 + 6 = 6 + 7 + 8 = 21.

    Example 2:

    >>> pivotInteger(n = 1)
    >>> 1
    Explanation: 1 is the pivot integer since: 1 = 1.

    Example 3:

    >>> pivotInteger(n = 4)
    >>> -1
    Explanation: It can be proved that no such integer exist.
    """


Prompt:
def appendCharacters(s: str, t: str) -> int:
    """
    You are given two strings s and t consisting of only lowercase English letters.
    Return the minimum number of characters that need to be appended to the end of s so that t becomes a subsequence of s.
    A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.

    Example 1:

    >>> appendCharacters(s = "coaching", t = "coding")
    >>> 4
    Explanation: Append the characters "ding" to the end of s so that s = "coachingding".
    Now, t is a subsequence of s ("coachingding").
    It can be shown that appending any 3 characters to the end of s will never make t a subsequence.

    Example 2:

    >>> appendCharacters(s = "abcde", t = "a")
    >>> 0
    Explanation: t is already a subsequence of s ("abcde").

    Example 3:

    >>> appendCharacters(s = "z", t = "abcde")
    >>> 5
    Explanation: Append the characters "abcde" to the end of s so that s = "zabcde".
    Now, t is a subsequence of s ("zabcde").
    It can be shown that appending any 4 characters to the end of s will never make t a subsequence.
    """


Prompt:
from typing import Optional
class ListNode:
    def __init__(val=0, next=None):
        self.val = val
        self.next = next
def removeNodes(head: Optional[ListNode]) -> Optional[ListNode]:
"""
You are given the head of a linked list.
Remove every node which has a node with a greater value anywhere to the right side of it.
Return the head of the modified linked list.

Example 1:

>>> removeNodes(head = [5,2,13,3,8])
>>> [13,8]
Explanation: The nodes that should be removed are 5, 2 and 3.
- Node 13 is to the right of node 5.
- Node 13 is to the right of node 2.
- Node 8 is to the right of node 3.

Example 2:

>>> removeNodes(head = [1,1,1,1])
>>> [1,1,1,1]
Explanation: Every node has value 1, so no nodes are removed.
"""


Prompt:
from typing import List
def countSubarrays(nums: List[int], k: int) -> int:
    """
    You are given an array nums of size n consisting of distinct integers from 1 to n and a positive integer k.
    Return the number of non-empty subarrays in nums that have a median equal to k.
    Note:

    The median of an array is the middle element after sorting the array in ascending order. If the array is of even length, the median is the left middle element.

    For example, the median of [2,3,1,4] is 2, and the median of [8,4,3,5,1] is 4.

    A subarray is a contiguous part of an array.

    Example 1:

    >>> countSubarrays(nums = [3,2,1,4,5], k = 4)
    >>> 3
    Explanation: The subarrays that have a median equal to 4 are: [4], [4,5] and [1,4,5].

    Example 2:

    >>> countSubarrays(nums = [2,3,1], k = 3)
    >>> 1
    Explanation: [3] is the only subarray that has a median equal to 3.
    """


Prompt:
def fixedRatio(s: str, num1: int, num2: int) -> int:
    """
    You are given a binary string s, and two integers num1 and num2. num1 and num2 are coprime numbers.
    A ratio substring is a substring of s where the ratio between the number of 0's and the number of 1's in the substring is exactly num1 : num2.

    For example, if num1 = 2 and num2 = 3, then "01011" and "1110000111" are ratio substrings, while "11000" is not.

    Return the number of non-empty ratio substrings of s.
    Note that:

    A substring is a contiguous sequence of characters within a string.
    Two values x and y are coprime if gcd(x, y) == 1 where gcd(x, y) is the greatest common divisor of x and y.

    Example 1:

    >>> fixedRatio(s = "0110011", num1 = 1, num2 = 2)
    >>> 4
    Explanation: There exist 4 non-empty ratio substrings.
    - The substring s[0..2]: "0110011". It contains one 0 and two 1's. The ratio is 1 : 2.
    - The substring s[1..4]: "0110011". It contains one 0 and two 1's. The ratio is 1 : 2.
    - The substring s[4..6]: "0110011". It contains one 0 and two 1's. The ratio is 1 : 2.
    - The substring s[1..6]: "0110011". It contains two 0's and four 1's. The ratio is 2 : 4 == 1 : 2.
    It can be shown that there are no more ratio substrings.

    Example 2:

    >>> fixedRatio(s = "10101", num1 = 3, num2 = 1)
    >>> 0
    Explanation: There is no ratio substrings of s. We return 0.
    """


Prompt:
def isCircularSentence(sentence: str) -> bool:
    """
    A sentence is a list of words that are separated by a single space with no leading or trailing spaces.

    For example, "Hello World", "HELLO", "hello world hello world" are all sentences.

    Words consist of only uppercase and lowercase English letters. Uppercase and lowercase English letters are considered different.
    A sentence is circular if:

    The last character of each word in the sentence is equal to the first character of its next word.
    The last character of the last word is equal to the first character of the first word.

    For example, "leetcode exercises sound delightful", "eetcode", "leetcode eats soul" are all circular sentences. However, "Leetcode is cool", "happy Leetcode", "Leetcode" and "I like Leetcode" are not circular sentences.
    Given a string sentence, return true if it is circular. Otherwise, return false.

    Example 1:

    >>> isCircularSentence(sentence = "leetcode exercises sound delightful")
    >>> true
    Explanation: The words in sentence are ["leetcode", "exercises", "sound", "delightful"].
    - leetcode's last character is equal to exercises's first character.
    - exercises's last character is equal to sound's first character.
    - sound's last character is equal to delightful's first character.
    - delightful's last character is equal to leetcode's first character.
    The sentence is circular.
    Example 2:

    >>> isCircularSentence(sentence = "eetcode")
    >>> true
    Explanation: The words in sentence are ["eetcode"].
    - eetcode's last character is equal to eetcode's first character.
    The sentence is circular.
    Example 3:

    >>> isCircularSentence(sentence = "Leetcode is cool")
    >>> false
    Explanation: The words in sentence are ["Leetcode", "is", "cool"].
    - Leetcode's last character is not equal to is's first character.
    The sentence is not circular.
    """


Prompt:
from typing import List
def dividePlayers(skill: List[int]) -> int:
    """
    You are given a positive integer array skill of even length n where skill[i] denotes the skill of the ith player. Divide the players into n / 2 teams of size 2 such that the total skill of each team is equal.
    The chemistry of a team is equal to the product of the skills of the players on that team.
    Return the sum of the chemistry of all the teams, or return -1 if there is no way to divide the players into teams such that the total skill of each team is equal.

    Example 1:

    >>> dividePlayers(skill = [3,2,5,1,3,4])
    >>> 22
    Explanation:
    Divide the players into the following teams: (1, 5), (2, 4), (3, 3), where each team has a total skill of 6.
    The sum of the chemistry of all the teams is: 1 * 5 + 2 * 4 + 3 * 3 = 5 + 8 + 9 = 22.

    Example 2:

    >>> dividePlayers(skill = [3,4])
    >>> 12
    Explanation:
    The two players form a team with a total skill of 7.
    The chemistry of the team is 3 * 4 = 12.

    Example 3:

    >>> dividePlayers(skill = [1,1,2,3])
    >>> -1
    Explanation:
    There is no way to divide the players into teams such that the total skill of each team is equal.
    """


Prompt:
from typing import List
def minScore(n: int, roads: List[List[int]]) -> int:
    """
    You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads where roads[i] = [ai, bi, distancei] indicates that there is a bidirectional road between cities ai and bi with a distance equal to distancei. The cities graph is not necessarily connected.
    The score of a path between two cities is defined as the minimum distance of a road in this path.
    Return the minimum possible score of a path between cities 1 and n.
    Note:

    A path is a sequence of roads between two cities.
    It is allowed for a path to contain the same road multiple times, and you can visit cities 1 and n multiple times along the path.
    The test cases are generated such that there is at least one path between 1 and n.

    Example 1:

    >>> minScore(n = 4, roads = [[1,2,9],[2,3,6],[2,4,5],[1,4,7]])
    >>> 5
    Explanation: The path from city 1 to 4 with the minimum score is: 1 -> 2 -> 4. The score of this path is min(9,5) = 5.
    It can be shown that no other path has less score.

    Example 2:

    >>> minScore(n = 4, roads = [[1,2,2],[1,3,4],[3,4,7]])
    >>> 2
    Explanation: The path from city 1 to 4 with the minimum score is: 1 -> 2 -> 1 -> 3 -> 4. The score of this path is min(2,2,4,7) = 2.
    """


Prompt:
from typing import List
def magnificentSets(n: int, edges: List[List[int]]) -> int:
    """
    You are given a positive integer n representing the number of nodes in an undirected graph. The nodes are labeled from 1 to n.
    You are also given a 2D integer array edges, where edges[i] = [ai, bi] indicates that there is a bidirectional edge between nodes ai and bi. Notice that the given graph may be disconnected.
    Divide the nodes of the graph into m groups (1-indexed) such that:

    Each node in the graph belongs to exactly one group.
    For every pair of nodes in the graph that are connected by an edge [ai, bi], if ai belongs to the group with index x, and bi belongs to the group with index y, then |y - x| = 1.

    Return the maximum number of groups (i.e., maximum m) into which you can divide the nodes. Return -1 if it is impossible to group the nodes with the given conditions.

    Example 1:

    >>> magnificentSets(n = 6, edges = [[1,2],[1,4],[1,5],[2,6],[2,3],[4,6]])
    >>> 4
    Explanation: As shown in the image we:
    - Add node 5 to the first group.
    - Add node 1 to the second group.
    - Add nodes 2 and 4 to the third group.
    - Add nodes 3 and 6 to the fourth group.
    We can see that every edge is satisfied.
    It can be shown that that if we create a fifth group and move any node from the third or fourth group to it, at least on of the edges will not be satisfied.

    Example 2:

    >>> magnificentSets(n = 3, edges = [[1,2],[2,3],[3,1]])
    >>> -1
    Explanation: If we add node 1 to the first group, node 2 to the second group, and node 3 to the third group to satisfy the first two edges, we can see that the third edge will not be satisfied.
    It can be shown that no grouping is possible.
    """


Prompt:
from typing import List
def evenProduct(nums: List[int]) -> int:
    """
    Given a 0-indexed integer array nums, return the number of subarrays of nums having an even product.

    Example 1:

    >>> evenProduct(nums = [9,6,7,13])
    >>> 6
    Explanation: There are 6 subarrays with an even product:
    - nums[0..1] = 9 * 6 = 54.
    - nums[0..2] = 9 * 6 * 7 = 378.
    - nums[0..3] = 9 * 6 * 7 * 13 = 4914.
    - nums[1..1] = 6.
    - nums[1..2] = 6 * 7 = 42.
    - nums[1..3] = 6 * 7 * 13 = 546.

    Example 2:

    >>> evenProduct(nums = [7,3,5])
    >>> 0
    Explanation: There are no subarrays with an even product.
    """


Prompt:
from typing import List
def maximumValue(strs: List[str]) -> int:
    """
    The value of an alphanumeric string can be defined as:

    The numeric representation of the string in base 10, if it comprises of digits only.
    The length of the string, otherwise.

    Given an array strs of alphanumeric strings, return the maximum value of any string in strs.

    Example 1:

    >>> maximumValue(strs = ["alic3","bob","3","4","00000"])
    >>> 5
    Explanation:
    - "alic3" consists of both letters and digits, so its value is its length, i.e. 5.
    - "bob" consists only of letters, so its value is also its length, i.e. 3.
    - "3" consists only of digits, so its value is its numeric equivalent, i.e. 3.
    - "4" also consists only of digits, so its value is 4.
    - "00000" consists only of digits, so its value is 0.
    Hence, the maximum value is 5, of "alic3".

    Example 2:

    >>> maximumValue(strs = ["1","01","001","0001"])
    >>> 1
    Explanation:
    Each string in the array has value 1. Hence, we return 1.
    """


Prompt:
from typing import List
def maxStarSum(vals: List[int], edges: List[List[int]], k: int) -> int:
    """
    There is an undirected graph consisting of n nodes numbered from 0 to n - 1. You are given a 0-indexed integer array vals of length n where vals[i] denotes the value of the ith node.
    You are also given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting nodes ai and bi.
    A star graph is a subgraph of the given graph having a center node containing 0 or more neighbors. In other words, it is a subset of edges of the given graph such that there exists a common node for all edges.
    The image below shows star graphs with 3 and 4 neighbors respectively, centered at the blue node.

    The star sum is the sum of the values of all the nodes present in the star graph.
    Given an integer k, return the maximum star sum of a star graph containing at most k edges.

    Example 1:

    >>> maxStarSum(vals = [1,2,3,4,10,-10,-20], edges = [[0,1],[1,2],[1,3],[3,4],[3,5],[3,6]], k = 2)
    >>> 16
    Explanation: The above diagram represents the input graph.
    The star graph with the maximum star sum is denoted by blue. It is centered at 3 and includes its neighbors 1 and 4.
    It can be shown it is not possible to get a star graph with a sum greater than 16.

    Example 2:

    >>> maxStarSum(vals = [-5], edges = [], k = 0)
    >>> -5
    Explanation: There is only one possible star graph, which is node 0 itself.
    Hence, we return -5.
    """


Prompt:
from typing import List
def maxJump(stones: List[int]) -> int:
    """
    You are given a 0-indexed integer array stones sorted in strictly increasing order representing the positions of stones in a river.
    A frog, initially on the first stone, wants to travel to the last stone and then return to the first stone. However, it can jump to any stone at most once.
    The length of a jump is the absolute difference between the position of the stone the frog is currently on and the position of the stone to which the frog jumps.

    More formally, if the frog is at stones[i] and is jumping to stones[j], the length of the jump is |stones[i] - stones[j]|.

    The cost of a path is the maximum length of a jump among all jumps in the path.
    Return the minimum cost of a path for the frog.

    Example 1:

    >>> maxJump(stones = [0,2,5,6,7])
    >>> 5
    Explanation: The above figure represents one of the optimal paths the frog can take.
    The cost of this path is 5, which is the maximum length of a jump.
    Since it is not possible to achieve a cost of less than 5, we return it.

    Example 2:

    >>> maxJump(stones = [0,3,9])
    >>> 9
    Explanation:
    The frog can jump directly to the last stone and come back to the first stone.
    In this case, the length of each jump will be 9. The cost for the path will be max(9, 9) = 9.
    It can be shown that this is the minimum achievable cost.
    """


Prompt:
from typing import List
def minimumTotalCost(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two 0-indexed integer arrays nums1 and nums2, of equal length n.
    In one operation, you can swap the values of any two indices of nums1. The cost of this operation is the sum of the indices.
    Find the minimum total cost of performing the given operation any number of times such that nums1[i] != nums2[i] for all 0 <= i <= n - 1 after performing all the operations.
    Return the minimum total cost such that nums1 and nums2 satisfy the above condition. In case it is not possible, return -1.

    Example 1:

    >>> minimumTotalCost(nums1 = [1,2,3,4,5], nums2 = [1,2,3,4,5])
    >>> 10
    Explanation:
    One of the ways we can perform the operations is:
    - Swap values at indices 0 and 3, incurring cost = 0 + 3 = 3. Now, nums1 = [4,2,3,1,5]
    - Swap values at indices 1 and 2, incurring cost = 1 + 2 = 3. Now, nums1 = [4,3,2,1,5].
    - Swap values at indices 0 and 4, incurring cost = 0 + 4 = 4. Now, nums1 =[5,3,2,1,4].
    We can see that for each index i, nums1[i] != nums2[i]. The cost required here is 10.
    Note that there are other ways to swap values, but it can be proven that it is not possible to obtain a cost less than 10.

    Example 2:

    >>> minimumTotalCost(nums1 = [2,2,2,1,3], nums2 = [1,2,2,3,3])
    >>> 10
    Explanation:
    One of the ways we can perform the operations is:
    - Swap values at indices 2 and 3, incurring cost = 2 + 3 = 5. Now, nums1 = [2,2,1,2,3].
    - Swap values at indices 1 and 4, incurring cost = 1 + 4 = 5. Now, nums1 = [2,3,1,2,2].
    The total cost needed here is 10, which is the minimum possible.

    Example 3:

    >>> minimumTotalCost(nums1 = [1,2,2], nums2 = [1,2,2])
    >>> -1
    Explanation:
    It can be shown that it is not possible to satisfy the given conditions irrespective of the number of operations we perform.
    Hence, we return -1.
    """


Prompt:
from typing import List
def deleteGreatestValue(grid: List[List[int]]) -> int:
    """
    You are given an m x n matrix grid consisting of positive integers.
    Perform the following operation until grid becomes empty:

    Delete the element with the greatest value from each row. If multiple such elements exist, delete any of them.
    Add the maximum of deleted elements to the answer.

    Note that the number of columns decreases by one after each operation.
    Return the answer after performing the operations described above.

    Example 1:

    >>> deleteGreatestValue(grid = [[1,2,4],[3,3,1]])
    >>> 8
    Explanation: The diagram above shows the removed values in each step.
    - In the first operation, we remove 4 from the first row and 3 from the second row (notice that, there are two cells with value 3 and we can remove any of them). We add 4 to the answer.
    - In the second operation, we remove 2 from the first row and 3 from the second row. We add 3 to the answer.
    - In the third operation, we remove 1 from the first row and 1 from the second row. We add 1 to the answer.
    The final answer = 4 + 3 + 1 = 8.

    Example 2:

    >>> deleteGreatestValue(grid = [[10]])
    >>> 10
    Explanation: The diagram above shows the removed values in each step.
    - In the first operation, we remove 10 from the first row. We add 10 to the answer.
    The final answer = 10.
    """


Prompt:
from typing import List
def longestSquareStreak(nums: List[int]) -> int:
    """
    You are given an integer array nums. A subsequence of nums is called a square streak if:

    The length of the subsequence is at least 2, and
    after sorting the subsequence, each element (except the first element) is the square of the previous number.

    Return the length of the longest square streak in nums, or return -1 if there is no square streak.
    A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

    Example 1:

    >>> longestSquareStreak(nums = [4,3,6,16,8,2])
    >>> 3
    Explanation: Choose the subsequence [4,16,2]. After sorting it, it becomes [2,4,16].
    - 4 = 2 * 2.
    - 16 = 4 * 4.
    Therefore, [4,16,2] is a square streak.
    It can be shown that every subsequence of length 4 is not a square streak.

    Example 2:

    >>> longestSquareStreak(nums = [2,3,5,6,7])
    >>> -1
    Explanation: There is no square streak in nums so return -1.
    """


Prompt:
from typing import List
def maxPoints(grid: List[List[int]], queries: List[int]) -> List[int]:
    """
    You are given an m x n integer matrix grid and an array queries of size k.
    Find an array answer of size k such that for each integer queries[i] you start in the top left cell of the matrix and repeat the following process:

    If queries[i] is strictly greater than the value of the current cell that you are in, then you get one point if it is your first time visiting this cell, and you can move to any adjacent cell in all 4 directions: up, down, left, and right.
    Otherwise, you do not get any points, and you end this process.

    After the process, answer[i] is the maximum number of points you can get. Note that for each query you are allowed to visit the same cell multiple times.
    Return the resulting array answer.

    Example 1:

    >>> maxPoints(grid = [[1,2,3],[2,5,7],[3,5,1]], queries = [5,6,2])
    >>> [5,8,1]
    Explanation: The diagrams above show which cells we visit to get points for each query.
    Example 2:

    >>> maxPoints(grid = [[5,2,1],[1,1,2]], queries = [3])
    >>> [0]
    Explanation: We can not get any points because the value of the top left cell is already greater than or equal to 3.
    """


Prompt:
from typing import List
def subsequenceSumOr(nums: List[int]) -> int:
    """
    Given an integer array nums, return the value of the bitwise OR of the sum of all possible subsequences in the array.
    A subsequence is a sequence that can be derived from another sequence by removing zero or more elements without changing the order of the remaining elements.

    Example 1:

    >>> subsequenceSumOr(nums = [2,1,0,3])
    >>> 7
    Explanation: All possible subsequence sums that we can have are: 0, 1, 2, 3, 4, 5, 6.
    And we have 0 OR 1 OR 2 OR 3 OR 4 OR 5 OR 6 = 7, so we return 7.

    Example 2:

    >>> subsequenceSumOr(nums = [0,0,0])
    >>> 0
    Explanation: 0 is the only possible subsequence sum we can have, so we return 0.
    """


Prompt:
from typing import List
def similarPairs(words: List[str]) -> int:
    """
    You are given a 0-indexed string array words.
    Two strings are similar if they consist of the same characters.

    For example, "abca" and "cba" are similar since both consist of characters 'a', 'b', and 'c'.
    However, "abacba" and "bcfd" are not similar since they do not consist of the same characters.

    Return the number of pairs (i, j) such that 0 <= i < j <= word.length - 1 and the two strings words[i] and words[j] are similar.

    Example 1:

    >>> similarPairs(words = ["aba","aabb","abcd","bac","aabc"])
    >>> 2
    Explanation: There are 2 pairs that satisfy the conditions:
    - i = 0 and j = 1 : both words[0] and words[1] only consist of characters 'a' and 'b'.
    - i = 3 and j = 4 : both words[3] and words[4] only consist of characters 'a', 'b', and 'c'.

    Example 2:

    >>> similarPairs(words = ["aabb","ab","ba"])
    >>> 3
    Explanation: There are 3 pairs that satisfy the conditions:
    - i = 0 and j = 1 : both words[0] and words[1] only consist of characters 'a' and 'b'.
    - i = 0 and j = 2 : both words[0] and words[2] only consist of characters 'a' and 'b'.
    - i = 1 and j = 2 : both words[1] and words[2] only consist of characters 'a' and 'b'.

    Example 3:

    >>> similarPairs(words = ["nba","cba","dba"])
    >>> 0
    Explanation: Since there does not exist any pair that satisfies the conditions, we return 0.
    """


Prompt:
def smallestValue(n: int) -> int:
    """
    You are given a positive integer n.
    Continuously replace n with the sum of its prime factors.

    Note that if a prime factor divides n multiple times, it should be included in the sum as many times as it divides n.

    Return the smallest value n will take on.

    Example 1:

    >>> smallestValue(n = 15)
    >>> 5
    Explanation: Initially, n = 15.
    15 = 3 * 5, so replace n with 3 + 5 = 8.
    8 = 2 * 2 * 2, so replace n with 2 + 2 + 2 = 6.
    6 = 2 * 3, so replace n with 2 + 3 = 5.
    5 is the smallest value n will take on.

    Example 2:

    >>> smallestValue(n = 3)
    >>> 3
    Explanation: Initially, n = 3.
    3 is the smallest value n will take on.
    """


Prompt:
from typing import List
def isPossible(n: int, edges: List[List[int]]) -> bool:
    """
    There is an undirected graph consisting of n nodes numbered from 1 to n. You are given the integer n and a 2D array edges where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi. The graph can be disconnected.
    You can add at most two additional edges (possibly none) to this graph so that there are no repeated edges and no self-loops.
    Return true if it is possible to make the degree of each node in the graph even, otherwise return false.
    The degree of a node is the number of edges connected to it.

    Example 1:

    >>> isPossible(n = 5, edges = [[1,2],[2,3],[3,4],[4,2],[1,4],[2,5]])
    >>> true
    Explanation: The above diagram shows a valid way of adding an edge.
    Every node in the resulting graph is connected to an even number of edges.

    Example 2:

    >>> isPossible(n = 4, edges = [[1,2],[3,4]])
    >>> true
    Explanation: The above diagram shows a valid way of adding two edges.
    Example 3:

    >>> isPossible(n = 4, edges = [[1,2],[1,3],[1,4]])
    >>> false
    Explanation: It is not possible to obtain a valid graph with adding at most 2 edges.
    """


Prompt:
from typing import List
def cycleLengthQueries(n: int, queries: List[List[int]]) -> List[int]:
    """
    You are given an integer n. There is a complete binary tree with 2n - 1 nodes. The root of that tree is the node with the value 1, and every node with a value val in the range [1, 2n - 1 - 1] has two children where:

    The left node has the value 2 * val, and
    The right node has the value 2 * val + 1.

    You are also given a 2D integer array queries of length m, where queries[i] = [ai, bi]. For each query, solve the following problem:

    Add an edge between the nodes with values ai and bi.
    Find the length of the cycle in the graph.
    Remove the added edge between nodes with values ai and bi.

    Note that:

    A cycle is a path that starts and ends at the same node, and each edge in the path is visited only once.
    The length of a cycle is the number of edges visited in the cycle.
    There could be multiple edges between two nodes in the tree after adding the edge of the query.

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

    Example 1:

    >>> cycleLengthQueries(n = 3, queries = [[5,3],[4,7],[2,3]])
    >>> [4,5,3]
    Explanation: The diagrams above show the tree of 23 - 1 nodes. Nodes colored in red describe the nodes in the cycle after adding the edge.
    - After adding the edge between nodes 3 and 5, the graph contains a cycle of nodes [5,2,1,3]. Thus answer to the first query is 4. We delete the added edge and process the next query.
    - After adding the edge between nodes 4 and 7, the graph contains a cycle of nodes [4,2,1,3,7]. Thus answer to the second query is 5. We delete the added edge and process the next query.
    - After adding the edge between nodes 2 and 3, the graph contains a cycle of nodes [2,1,3]. Thus answer to the third query is 3. We delete the added edge.

    Example 2:

    >>> cycleLengthQueries(n = 2, queries = [[1,2]])
    >>> [2]
    Explanation: The diagram above shows the tree of 22 - 1 nodes. Nodes colored in red describe the nodes in the cycle after adding the edge.
    - After adding the edge between nodes 1 and 2, the graph contains a cycle of nodes [2,1]. Thus answer for the first query is 2. We delete the added edge.
    """


Prompt:
from typing import List
def isThereAPath(grid: List[List[int]]) -> bool:
    """
    You are given a 0-indexed m x n binary matrix grid. You can move from a cell (row, col) to any of the cells (row + 1, col) or (row, col + 1).
    Return true if there is a path from (0, 0) to (m - 1, n - 1) that visits an equal number of 0's and 1's. Otherwise return false.

    Example 1:

    >>> isThereAPath(grid = [[0,1,0,0],[0,1,0,0],[1,0,1,0]])
    >>> true
    Explanation: The path colored in blue in the above diagram is a valid path because we have 3 cells with a value of 1 and 3 with a value of 0. Since there is a valid path, we return true.

    Example 2:

    >>> isThereAPath(grid = [[1,1,0],[0,0,1],[1,0,0]])
    >>> false
    Explanation: There is no path in this grid with an equal number of 0's and 1's.
    """