Prompt:
def max_of_min_2d_array(n: int, m: int, array: List[List[int]]) -> int:
    """
    =====Function Descriptions=====
    min

    The tool min returns the minimum value along a given axis.

    import numpy

    my_array = numpy.array([[2, 5],
    [3, 7],
    [1, 3],
    [4, 0]])

    print numpy.min(my_array, axis = 0)         #Output : [1 0]
    print numpy.min(my_array, axis = 1)         #Output : [2 3 1 0]
    print numpy.min(my_array, axis = None)      #Output : 0
    print numpy.min(my_array)                   #Output : 0

    By default, the axis value is None. Therefore, it finds the minimum over all the dimensions of the input array.

    max

    The tool max returns the maximum value along a given axis.

    import numpy

    my_array = numpy.array([[2, 5],
    [3, 7],
    [1, 3],
    [4, 0]])

    print numpy.max(my_array, axis = 0)         #Output : [4 7]
    print numpy.max(my_array, axis = 1)         #Output : [5 7 3 4]
    print numpy.max(my_array, axis = None)      #Output : 7
    print numpy.max(my_array)                   #Output : 7

    By default, the axis value is None. Therefore, it finds the maximum over all the dimensions of the input array.

    =====Problem Statement=====
    You are given a 2-D array with dimensions NXM.
    Your task is to perform the min function over axis 1 and then find the max of that.

    =====Input Format=====
    The first line of input contains the space separated values of N and M.
    The next N lines contains M space separated integers.

    =====Output Format=====
    Compute the min along axis 1 and then print the max of that result.
    """
    import numpy as np
    np_array = np.array(array)
    min_values = np.min(np_array, axis=1)
    return np.max(min_values)

def check(candidate):
    assert candidate(4, 2, [[2, 5], [3, 7], [1, 3], [4, 0]]) == 3
check(max_of_min_2d_array)


Prompt:
def guess_hat_color(a: str, b: str, c: str, d: str) -> int:
    """
    # Task
    Four men, `a, b, c and d` are standing in a line, one behind another.

    There's a wall between the first three people (a, b and c) and the last one (d).

    a, b and c are lined up in order of height, so that person a can see the backs of b and c, person b can see the back of c, and c can see just the wall.

    There are 4 hats, 2 black and 2 white. Each person is given a hat. None of them can see their own hat, but person a can see the hats of b and c, while person b can see the hat of person c. Neither c nor d can see any hats.

    Once a person figures out their hat's color, they shouts it.

    ![](http://stuffbox.in/wp-content/uploads/2016/08/Guess-hat-colour-604x270.png)

    Your task is to return the person who will guess their hat first. You can assume that they will speak only when they reach a correct conclusion.

    # Input/Output

    - `[input]` string `a`

    a's hat color ("white" or "black").

    - `[input]` string `b`

    b's hat color ("white" or "black").

    - `[input]` string `c`

    c's hat color ("white" or "black").

    - `[input]` string `d`

    d's hat color ("white" or "black").

    - `[output]` an integer

    The person to guess his hat's color first, `1 for a, 2 for b, 3 for c and 4 for d`.
    """

def check(candidate):
    assert candidate('white', 'black', 'white', 'black') == 2
    assert candidate('white', 'black', 'black', 'white') == 1
check(guess_hat_color)

assert guess_hat_color('white', 'black', 'white', 'black') == 2


Prompt:
def tictactoe(moves: List[List[int]]) -> str:
    """
    Tic-tac-toe is played by two players A and B on a 3 x 3 grid.
    Here are the rules of Tic-Tac-Toe:

    Players take turns placing characters into empty squares (" ").
    The first player A always places "X" characters, while the second player B always places "O" characters.
    "X" and "O" characters are always placed into empty squares, never on filled ones.
    The game ends when there are 3 of the same (non-empty) character filling any row, column, or diagonal.
    The game also ends if all squares are non-empty.
    No more moves can be played if the game is over.

    Given an array moves where each element is another array of size 2 corresponding to the row and column of the grid where they mark their respective character in the order in which A and B play.
    Return the winner of the game if it exists (A or B), in case the game ends in a draw return "Draw", if there are still movements to play return "Pending".
    You can assume that moves is valid (It follows the rules of Tic-Tac-Toe), the grid is initially empty and A will play first.

    Example 1:
    Input: moves = [[0,0],[2,0],[1,1],[2,1],[2,2]]
    Output: "A"
    Explanation: "A" wins, he always plays first.
    "X  "    "X  "    "X  "    "X  "    "X  "
    "   " -> "   " -> " X " -> " X " -> " X "
    "   "    "O  "    "O  "    "OO "    "OOX"

    Example 2:
    Input: moves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]
    Output: "B"
    Explanation: "B" wins.
    "X  "    "X  "    "XX "    "XXO"    "XXO"    "XXO"
    "   " -> " O " -> " O " -> " O " -> "XO " -> "XO "
    "   "    "   "    "   "    "   "    "   "    "O  "

    Example 3:
    Input: moves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]
    Output: "Draw"
    Explanation: The game ends in a draw since there are no moves to make.
    "XXO"
    "OOX"
    "XOX"

    Example 4:
    Input: moves = [[0,0],[1,1]]
    Output: "Pending"
    Explanation: The game has not finished yet.
    "X  "
    " O "
    "   "

    Constraints:

    1 <= moves.length <= 9
    moves[i].length == 2
    0 <= moves[i][j] <= 2
    There are no repeated elements on moves.
    moves follow the rules of tic tac toe.
    """

assert tictactoe([[0, 0], [1, 1]]) == 'Pending'


Prompt:
def case_unification(s: str) -> str:
    """
    # Task
    Given an initial string `s`, switch case of the minimal possible number of letters to make the whole string written in the upper case or in the lower case.

    # Input/Output

    `[input]` string `s`

    String of odd length consisting of English letters.

    3 ≤ inputString.length ≤ 99.

    `[output]` a string

    The resulting string.

    # Example

    For `s = "Aba"`, the output should be `"aba"`

    For `s = "ABa"`, the output should be `"ABA"`
    """

def check(candidate):
    assert candidate('asdERvT') == 'asdervt'
    assert candidate('oyTYbWQ') == 'OYTYBWQ'
    assert candidate('bbiIRvbcW') == 'bbiirvbcw'
    assert candidate('rWTmvcoRWEWQQWR') == 'RWTMVCORWEWQQWR'
check(case_unification)

assert case_unification('Aba') == 'aba'
assert case_unification('ABa') == 'ABA'


Prompt:
def complete_series(a: List[int]) -> List[int]:
    """
    You are given an array of non-negative integers, your task is to complete the series from 0 to the highest number in the array.

    If the numbers in the sequence provided are not in order you should order them, but if a value repeats, then you must return a sequence with only one item, and the value of that item must be 0. like this:
    ```
    inputs        outputs
    [2,1]     ->  [0,1,2]
    [1,4,4,6] ->  [0]
    ```
    Notes: all numbers are positive integers.

    This is set of example outputs based on the input sequence.
    ```
    inputs        outputs
    [0,1]   ->    [0,1]
    [1,4,6] ->    [0,1,2,3,4,5,6]
    [3,4,5] ->    [0,1,2,3,4,5]
    [0,1,0] ->    [0]
    ```
    """

def check(candidate):
    assert candidate([0, 1]) == [0, 1]
    assert candidate([1, 4, 6]) == [0, 1, 2, 3, 4, 5, 6]
    assert candidate([3, 4, 5]) == [0, 1, 2, 3, 4, 5]
    assert candidate([2, 1]) == [0, 1, 2]
    assert candidate([1, 4, 4, 6]) == [0]
check(complete_series)

assert complete_series([0, 1]) == [0, 1]

assert complete_series([0, 1, 0]) == [0]

assert complete_series([2, 1]) == [0, 1, 2]

assert complete_series([1, 4, 4, 6]) == [0]


Prompt:
def does_fred_need_houseboat(x: int, y: int) -> int:
    """
    # Task
    Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned that the state of Louisiana is actually shrinking by 50 square miles each year, due to erosion caused by the Mississippi River. Since Fred is hoping to live in this house the rest of his life, he needs to know if his land is going to be lost to erosion.

    After doing more research, Fred has learned that the land that is being lost forms a semicircle. This semicircle is part of a circle centered at (0,0), with the line that bisects the circle being the `x` axis. Locations below the `x` axis are in the water. The semicircle has an area of 0 at the beginning of year 1. (Semicircle illustrated in the Figure.)

    ![](http://media.openjudge.cn/images/1005/semicircle.GIF)

    Given two coordinates `x` and `y`, your task is to calculate that Fred Mapper's house will begin eroding in how many years.

    Note:

    1. No property will appear exactly on the semicircle boundary: it will either be inside or outside.

    2. All locations are given in miles.

    3. (0,0) will not be given.

    # Example

    For `x = 1, y = 1`, the result should be `1`.

    After 1 year, Fred Mapper's house will begin eroding.

    For `x = 25, y = 0`, the result should be `20`.

    After 20 year, Fred Mapper's house will begin eroding.

    # Input/Output

    - `[input]` integer `x`

    The X coordinates of the land Fred is considering. It will be an integer  point numbers measured in miles.

    `-100 <= x <= 100`

    - `[input]` integer `y`

    The Y coordinates of the land Fred is considering. It will be an integer point numbers measured in miles.

    `0 <= y <= 100`

    - `[output]` an integer

    The first year (start from 1) this point will be within the semicircle AT THE END OF YEAR.
    """

def check(candidate):
    assert candidate(1, 1) == 1
    assert candidate(25, 0) == 20
check(does_fred_need_houseboat)

assert does_fred_need_houseboat(1, 1) == 1

assert does_fred_need_houseboat(25, 0) == 20


Prompt:
def folding(a: int, b: int) -> int:
    """
    # Task
    John was in math class and got bored, so he decided to fold some origami from a rectangular `a × b` sheet of paper (`a > b`). His first step is to make a square piece of paper from the initial rectangular piece of paper by folding the sheet along the bisector of the right angle and cutting off the excess part.

    After moving the square piece of paper aside, John wanted to make even more squares! He took the remaining (`a-b`) × `b` strip of paper and went on with the process until he was left with a square piece of paper.

    Your task is to determine how many square pieces of paper John can make.

    # Example:

    For: `a = 2, b = 1`, the output should be `2`.

    Given `a = 2` and `b = 1`, John can fold a `1 × 1` then another `1 × 1`.

    So the answer is `2`.

    For: `a = 10, b = 7`, the output should be `6`.

    We are given `a = 10` and `b = 7`. The following is the order of squares John folds: `7 × 7, 3 × 3, 3 × 3, 1 × 1, 1 × 1, and 1 × 1`.

    Here are pictures for the example cases.

    # Input/Output

    - `[input]` integer `a`

    `2 ≤ a ≤ 1000`

    - `[input]` integer `b`

    `1 ≤ b < a ≤ 1000`

    - `[output]` an integer

    The maximum number of squares.
    """

def check(candidate):
    assert candidate(2, 1) == 2
    assert candidate(10, 7) == 6
    assert candidate(3, 1) == 3
    assert candidate(4, 1) == 4
    assert candidate(3, 2) == 3
    assert candidate(4, 2) == 2
    assert candidate(1000, 700) == 6
    assert candidate(1000, 999) == 1000
check(folding)

assert folding(2, 1) == 2
assert folding(10, 7) == 6


Prompt:
def substring_test(first: str, second: str) -> bool:
    """
    Given 2 strings, your job is to find out if there is a substring that appears in both strings. You will return true if you find a substring that appears in both strings, or false if you do not. We only care about substrings that are longer than one letter long.

    #Examples:

    ````
    *Example 1*
    SubstringTest("Something","Fun"); //Returns false

    *Example 2*
    SubstringTest("Something","Home"); //Returns true
    ````
    In the above example, example 2 returns true because both of the inputs contain the substring "me". (so**ME**thing and ho**ME**)
    In example 1, the method will return false because something and fun contain no common substrings. (We do not count the 'n' as a substring in this Kata because it is only 1 character long)

    #Rules:
    Lowercase and uppercase letters are the same. So 'A' == 'a'.
    We only count substrings that are > 1 in length.

    #Input:
    Two strings with both lower and upper cases.
    #Output:
    A boolean value determining if there is a common substring between the two inputs.
    """

def check(candidate):
    assert candidate('Something', 'Home') == True
    assert candidate('Something', 'Fun') == False
    assert candidate('Something', '') == False
    assert candidate('', 'Something') == False
    assert candidate('BANANA', 'banana') == True
    assert candidate('test', 'lllt') == False
    assert candidate('', '') == False
    assert candidate('1234567', '541265') == True
    assert candidate('supercalifragilisticexpialidocious', 'SoundOfItIsAtrocious') == True
    assert candidate('LoremipsumdolorsitametconsecteturadipiscingelitAeneannonaliquetligulautplaceratorciSuspendissepotentiMorbivolutpatauctoripsumegetaliquamPhasellusidmagnaelitNullamerostellustemporquismolestieaornarevitaediamNullaaliquamrisusnonviverrasagittisInlaoreetultricespretiumVestibulumegetnullatinciduntsempersemacrutrumfelisPraesentpurusarcutempusnecvariusidultricesaduiPellentesqueultriciesjustolobortisrhoncusdignissimNuncviverraconsequatblanditUtbibendumatlacusactristiqueAliquamimperdietnuncsempertortorefficiturviverra', 'thisisalongstringtest') == True
    assert candidate('Codewars is sweet!', 'is') == True
check(substring_test)

assert substring_test('Something', 'Fun') == False

assert substring_test('Something', 'Home') == True


Prompt:
def nickname_generator(name: str) -> str:
    """
    Nickname Generator

    Write a function, `nicknameGenerator` that takes a string name as an argument and returns the first 3 or 4 letters as a nickname.

    If the 3rd letter is a consonant, return the first 3 letters.

    If the 3rd letter is a vowel, return the first 4 letters.

    If the string is less than 4 characters, return "Error: Name too short".

    **Notes:**

    - Vowels are "aeiou", so discount the letter "y".
    - Input will always be a string.
    - Input will always have the first letter capitalised and the rest lowercase (e.g. Sam).
    - The input can be modified
    """

def check(candidate):
    assert candidate('Jimmy') == 'Jim'
    assert candidate('Samantha') == 'Sam'
    assert candidate('Sam') == 'Error: Name too short'
    assert candidate('Kayne') == 'Kay'
    assert candidate('Melissa') == 'Mel'
    assert candidate('James') == 'Jam'
    assert candidate('Gregory') == 'Greg'
    assert candidate('Jeannie') == 'Jean'
    assert candidate('Kimberly') == 'Kim'
    assert candidate('Timothy') == 'Tim'
    assert candidate('Dani') == 'Dan'
    assert candidate('Saamy') == 'Saam'
    assert candidate('Saemy') == 'Saem'
    assert candidate('Saimy') == 'Saim'
    assert candidate('Saomy') == 'Saom'
    assert candidate('Saumy') == 'Saum'
    assert candidate('Boyna') == 'Boy'
    assert candidate('Kiyna') == 'Kiy'
    assert candidate('Sayma') == 'Say'
    assert candidate('Ni') == 'Error: Name too short'
    assert candidate('Jam') == 'Error: Name too short'
    assert candidate('Suv') == 'Error: Name too short'
check(nickname_generator)

assert nickname_generator('Robert') == 'Rob'

assert nickname_generator('Jeannie') == 'Jean'


Prompt:
def candles(candlesNumber: int, makeNew: int) -> int:
    """
    # Task
    When a candle finishes burning it leaves a leftover. makeNew leftovers can be combined to make a new candle, which, when burning down, will in turn leave another leftover.

    You have candlesNumber candles in your possession. What's the total number of candles you can burn, assuming that you create new candles as soon as you have enough leftovers?

    # Example

    For candlesNumber = 5 and makeNew = 2, the output should be `9`.

    Here is what you can do to burn 9 candles:
    ```
    burn 5 candles, obtain 5 leftovers;
    create 2 more candles, using 4 leftovers (1 leftover remains);
    burn 2 candles, end up with 3 leftovers;
    create another candle using 2 leftovers (1 leftover remains);
    burn the created candle, which gives another leftover (2 leftovers in total);
    create a candle from the remaining leftovers;
    burn the last candle.
    Thus, you can burn 5 + 2 + 1 + 1 = 9 candles, which is the answer.
    ```

    # Input/Output

    - `[input]` integer `candlesNumber`

    The number of candles you have in your possession.

    Constraints: 1 ≤ candlesNumber ≤ 50.

    - `[input]` integer `makeNew`

    The number of leftovers that you can use up to create a new candle.

    Constraints: 2 ≤ makeNew ≤ 5.

    - `[output]` an integer
    """

def check(candidate):
    assert candidate(5, 2) == 9
check(candles)


Prompt:
def segment_cover(A: List[int], L: int) -> int:
    """
    # Task
    Given some points(array `A`) on the same line, determine the minimum number of line segments with length `L` needed to cover all of the given points. A point is covered if it is located inside some segment or on its bounds.

    # Example

    For `A = [1, 3, 4, 5, 8]` and `L = 3`, the output should be `2`.

    Check out the image below for better understanding:

    ![](https://codefightsuserpics.s3.amazonaws.com/tasks/segmentCover/img/example.png?_tm=1474900035857)

    For `A = [1, 5, 2, 4, 3]` and `L = 1`, the output should be `3`.

    segment1: `1-2`(covered points 1,2),

    segment2: `3-4`(covered points 3,4),

    segment3: `5-6`(covered point 5)

    For `A = [1, 10, 100, 1000]` and `L = 1`, the output should be `4`.

    segment1: `1-2`(covered point 1),

    segment2: `10-11`(covered point 10),

    segment3: `100-101`(covered point 100),

    segment4: `1000-1001`(covered point 1000)

    # Input/Output

    - `[input]` integer array A

    Array of point coordinates on the line (all points are different).

    Constraints:

    `1 ≤ A.length ≤ 50,`

    `-5000 ≤ A[i] ≤ 5000.`

    - `[input]` integer `L`

    Segment length, a positive integer.

    Constraints: `1 ≤ L ≤ 100.`

    - `[output]` an integer

    The minimum number of line segments that can cover all of the given points.
    """

def check(candidate):
    assert candidate([1, 3, 4, 5, 8], 3) == 2
    assert candidate([-7, -2, 0, -1, -6, 7, 3, 4], 4) == 3
    assert candidate([1, 5, 2, 4, 3], 1) == 3
    assert candidate([1, 10, 100, 1000], 1) == 4
check(segment_cover)


Prompt:
def timed_reading(max_length: int, text: str) -> int:
    """
    # Task
    Timed Reading is an educational tool used in many schools to improve and advance reading skills. A young elementary student has just finished his very first timed reading exercise. Unfortunately he's not a very good reader yet, so whenever he encountered a word longer than maxLength, he simply skipped it and read on.

    Help the teacher figure out how many words the boy has read by calculating the number of words in the text he has read, no longer than maxLength.

    Formally, a word is a substring consisting of English letters, such that characters to the left of the leftmost letter and to the right of the rightmost letter are not letters.

    # Example

    For `maxLength = 4` and `text = "The Fox asked the stork, 'How is the soup?'"`, the output should be `7`

    The boy has read the following words: `"The", "Fox", "the", "How", "is", "the", "soup".`

    # Input/Output

    - `[input]` integer `maxLength`

    A positive integer, the maximum length of the word the boy can read.

    Constraints: `1 ≤ maxLength ≤ 10.`

    - `[input]` string `text`

    A non-empty string of English letters and punctuation marks.

    - `[output]` an integer

    The number of words the boy has read.
    """

def check(candidate):
    assert candidate(4, 'The Fox asked the stork, How is the soup?') == 7
    assert candidate(1, '...') == 0
    assert candidate(3, 'This play was good for us.') == 3
    assert candidate(3, 'Suddenly he stopped, and glanced up at the houses') == 5
    assert candidate(6, 'Zebras evolved among the Old World horses within the last four million years.') == 11
    assert candidate(5, 'Although zebra species may have overlapping ranges, they do not interbreed.') == 6
    assert candidate(1, 'Oh!') == 0
    assert candidate(5, 'Now and then, however, he is horribly thoughtless, and seems to take a real delight in giving me pain.') == 14
check(timed_reading)

assert timed_reading(4, 'The Fox asked the stork, How is the soup?') == 7


Prompt:
def evil_code_medal(user_time: str, gold: str, silver: str, bronze: str) -> str:
    """
    # Task
    `EvilCode` is a game similar to `Codewars`. You have to solve programming tasks as quickly as possible. However, unlike `Codewars`, `EvilCode` awards you with a medal, depending on the time you took to solve the task.

    To get a medal, your time must be (strictly) inferior to the time corresponding to the medal. You can be awarded `"Gold", "Silver" or "Bronze"` medal, or `"None"` medal at all. Only one medal (the best achieved) is awarded.

    You are given the time achieved for the task and the time corresponding to each medal. Your task is to return the awarded medal.

    Each time is given in the format `HH:MM:SS`.

    # Input/Output

    `[input]` string `userTime`

    The time the user achieved.

    `[input]` string `gold`

    The time corresponding to the gold medal.

    `[input]` string `silver`

    The time corresponding to the silver medal.

    `[input]` string `bronze`

    The time corresponding to the bronze medal.

    It is guaranteed that `gold < silver < bronze`.

    `[output]` a string

    The medal awarded, one of for options: `"Gold", "Silver", "Bronze" or "None"`.

    # Example

    For
    ```
    userTime = "00:30:00", gold = "00:15:00",
    silver = "00:45:00" and bronze = "01:15:00"```

    the output should be `"Silver"`

    For
    ```
    userTime = "01:15:00", gold = "00:15:00",
    silver = "00:45:00" and bronze = "01:15:00"```

    the output should be `"None"`

    # For Haskell version
    ```
    In Haskell, the result is a Maybe, returning Just String indicating
    the medal if they won or Nothing if they don't.
    ```
    """


Prompt:
def decrypt(s: str) -> str:
    """
    # Task
    Smartphones software security has become a growing concern related to mobile telephony. It is particularly important as it relates to the security of available personal information.

    For this reason, Ahmed decided to encrypt phone numbers of contacts in such a way that nobody can decrypt them. At first he tried encryption algorithms very complex, but the decryption process is tedious, especially when he needed to dial a speed dial.

    He eventually found the algorithm following: instead of writing the number itself, Ahmed multiplied by 10, then adds the result to the original number.

    For example, if the phone number is `123`, after the transformation, it becomes `1353`. Ahmed truncates the result (from the left), so it has as many digits as the original phone number. In this example Ahmed wrote `353` instead of `123` in his smart phone.

    Ahmed needs a program to recover the original phone number from number stored on his phone. The program return "impossible" if the initial number can not be calculated.

    Note: There is no left leading zero in either the input or the output; Input `s` is given by string format, because it may be very huge ;-)

    # Example

    For `s="353"`, the result should be `"123"`

    ```
    1230
    +  123
    .......
    = 1353

    truncates the result to 3 digit -->"353"

    So the initial number is "123"
    ```
    For `s="123456"`, the result should be `"738496"`

    ```
    7384960
    +  738496
    .........
    = 8123456

    truncates the result to 6 digit -->"123456"

    So the initial number is "738496"
    ```
    For `s="4334"`, the result should be `"impossible"`

    Because no such a number can be encrypted to `"4334"`.

    # Input/Output

    - `[input]` string `s`

    string presentation of n with `1 <= n <= 10^100`

    - `[output]` a string

    The original phone number before encryption, or `"impossible"` if the initial number can not be calculated.
    """

def check(candidate):
    assert candidate('353') == '123'
    assert candidate('444') == '404'
    assert candidate('123456') == '738496'
    assert candidate('147') == '377'
    assert candidate('4334') == 'impossible'
check(decrypt)

assert decrypt('353') == '123'
assert decrypt('123456') == '738496'
assert decrypt('4334') == 'impossible'


Prompt:
def reformat(s: str) -> str:
    """
    Given alphanumeric string s. (Alphanumeric string is a string consisting of lowercase English letters and digits).
    You have to find a permutation of the string where no letter is followed by another letter and no digit is followed by another digit. That is, no two adjacent characters have the same type.
    Return the reformatted string or return an empty string if it is impossible to reformat the string.

    Example 1:
    Input: s = "a0b1c2"
    Output: "0a1b2c"
    Explanation: No two adjacent characters have the same type in "0a1b2c". "a0b1c2", "0a1b2c", "0c2a1b" are also valid permutations.

    Example 2:
    Input: s = "leetcode"
    Output: ""
    Explanation: "leetcode" has only characters so we cannot separate them by digits.

    Example 3:
    Input: s = "1229857369"
    Output: ""
    Explanation: "1229857369" has only digits so we cannot separate them by characters.

    Example 4:
    Input: s = "covid2019"
    Output: "c2o0v1i9d"

    Example 5:
    Input: s = "ab123"
    Output: "1a2b3"

    Constraints:

    1 <= s.length <= 500
    s consists of only lowercase English letters and/or digits.
    """

def check(candidate):
    assert candidate('a0b1c2') == '0a1b2c' or candidate('a0b1c2') == 'a0b1c2' or candidate('a0b1c2') == '0c2a1b'
    assert candidate('leetcode') == ''
    assert candidate('1229857369') == ''
    assert candidate('covid2019') == 'c2o0v1i9d' or candidate('covid2019') == '2c0o1v9i'
    assert candidate('ab123') == '1a2b3' or candidate('ab123') == 'a1b2c'
check(reformat)

assert reformat('a0b1c2') == '0a1b2c' or reformat('a0b1c2') == 'a0b1c2' or reformat('a0b1c2') == '0c2a1b'


Prompt:
def pass_the_bill(total: int, conservative: int, reformist: int) -> int:
    """
    # Story&Task
    There are three parties in parliament. The "Conservative Party", the "Reformist Party", and a group of independants.

    You are a member of the “Conservative Party” and you party is trying to pass a bill. The “Reformist Party” is trying to block it.

    In order for a bill to pass, it must have a majority vote, meaning that more than half of all members must approve of a bill before it is passed . The "Conservatives" and "Reformists" always vote the same as other members of thier parties, meaning that all the members of each party will all vote yes, or all vote no .

    However, independants vote individually, and the independant vote is often the determining factor as to whether a bill gets passed or not.

    Your task is to find the minimum number of independents that have to vote for your party's (the Conservative Party's) bill so that it is passed .

    In each test case the makeup of the Parliament will be different . In some cases your party may make up the majority of parliament, and in others it may make up the minority. If your party is the majority, you may find that you do not neeed any independants to vote in favor of your bill in order for it to pass . If your party is the minority, it may be possible that there are not enough independants for your bill to be passed . If it is impossible for your bill to pass, return `-1`.

    # Input/Output

    - `[input]` integer `totalMembers`

    The total number of members.

    - `[input]` integer `conservativePartyMembers`

    The number of members in the Conservative Party.

    - `[input]` integer `reformistPartyMembers`

    The number of members in the Reformist Party.

    - `[output]` an integer

    The minimum number of independent members that have to vote as you wish so that the bill is passed, or `-1` if you can't pass it anyway.

    # Example

    For `n = 8, m = 3 and k = 3`, the output should be `2`.

    It means:
    ```
    Conservative Party member --> 3
    Reformist Party member   --> 3
    the independent members --> 8 - 3 - 3 = 2
    If 2 independent members change their minds
    3 + 2 > 3
    the bill will be passed.
    If 1 independent members change their minds
    perhaps the bill will be failed
    (If the other independent members is against the bill).
    3 + 1 <= 3 + 1
    ```

    For `n = 13, m = 4 and k = 7`, the output should be `-1`.
    ```
    Even if all 2 independent members support the bill
    there are still not enough votes to pass the bill
    4 + 2 < 7
    So the output is -1
    ```
    """

def check(candidate):
    assert candidate(8, 3, 3) == 2
    assert candidate(13, 4, 7) == -1
    assert candidate(7, 4, 3) == 0
    assert candidate(11, 4, 1) == 2
    assert candidate(11, 5, 1) == 1
    assert candidate(11, 6, 1) == 0
    assert candidate(11, 4, 4) == 2
    assert candidate(11, 5, 4) == 1
    assert candidate(11, 5, 5) == 1
    assert candidate(11, 4, 6) == -1
    assert candidate(11, 4, 5) == 2
    assert candidate(15, 9, 3) == 0
    assert candidate(16, 7, 8) == -1
    assert candidate(16, 8, 7) == 1
    assert candidate(16, 1, 8) == -1
check(pass_the_bill)

assert pass_the_bill(8, 3, 3) == 2
assert pass_the_bill(13, 4, 7) == -1


Prompt:
def capitals_first(string: str) -> str:
    """
    Create a function that takes an input String and returns a String, where all the uppercase words of the input String are in front and all the lowercase words at the end.
    The order of the uppercase and lowercase words should be the order in which they occur.

    If a word starts with a number or special character, skip the word and leave it out of the result.

    Input String will not be empty.

    For an input String: "hey You, Sort me Already!"
    the function should return: "You, Sort Already! hey me"
    """

def check(candidate):
    assert candidate('hey You, Sort me Already') == 'You, Sort Already hey me'
    assert candidate('sense Does to That Make you?') == 'Does That Make sense to you?'
    assert candidate('i First need Thing In coffee The Morning') == 'First Thing In The Morning i need coffee'
    assert candidate('123 baby You and Me') == 'You Me baby and'
    assert candidate('Life gets Sometimes pretty !Hard') == 'Life Sometimes gets pretty'
check(capitals_first)

assert capitals_first('hey You, Sort me Already') == 'You, Sort Already hey me'


Prompt:
def day_of_the_week(day: int, month: int, year: int) -> str:
    """
    Given a date, return the corresponding day of the week for that date.
    The input is given as three integers representing the day, month and year respectively.
    Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.

    Example 1:
    Input: day = 31, month = 8, year = 2019
    Output: "Saturday"

    Example 2:
    Input: day = 18, month = 7, year = 1999
    Output: "Sunday"

    Example 3:
    Input: day = 15, month = 8, year = 1993
    Output: "Sunday"

    Constraints:

    The given dates are valid dates between the years 1971 and 2100.
    """

def check(candidate):
    assert candidate(31, 8, 2019) == 'Saturday'
    assert candidate(18, 7, 1999) == 'Sunday'
    assert candidate(15, 8, 1993) == 'Sunday'
check(day_of_the_week)

assert day_of_the_week(31, 8, 2019) == 'Saturday'

assert day_of_the_week(18, 7, 1999) == 'Sunday'

assert day_of_the_week(15, 8, 1993) == 'Sunday'


Prompt:
def max_length_three_blocks_palindrome(t: int, cases: List[Tuple[int, List[int]]]) -> List[int]:
    """
    The only difference between easy and hard versions is constraints.

    You are given a sequence $a$ consisting of $n$ positive integers.

    Let's define a three blocks palindrome as the sequence, consisting of at most two distinct elements (let these elements are $a$ and $b$, $a$ can be equal $b$) and is as follows: $[\underbrace{a, a, \dots, a}_{x}, \underbrace{b, b, \dots, b}_{y}, \underbrace{a, a, \dots, a}_{x}]$. There $x, y$ are integers greater than or equal to $0$. For example, sequences $[]$, $[2]$, $[1, 1]$, $[1, 2, 1]$, $[1, 2, 2, 1]$ and $[1, 1, 2, 1, 1]$ are three block palindromes but $[1, 2, 3, 2, 1]$, $[1, 2, 1, 2, 1]$ and $[1, 2]$ are not.

    Your task is to choose the maximum by length subsequence of $a$ that is a three blocks palindrome.

    You have to answer $t$ independent test cases.

    Recall that the sequence $t$ is a a subsequence of the sequence $s$ if $t$ can be derived from $s$ by removing zero or more elements without changing the order of the remaining elements. For example, if $s=[1, 2, 1, 3, 1, 2, 1]$, then possible subsequences are: $[1, 1, 1, 1]$, $[3]$ and $[1, 2, 1, 3, 1, 2, 1]$, but not $[3, 2, 3]$ and $[1, 1, 1, 1, 2]$.

    -----Input-----

    The first line of the input contains one integer $t$ ($1 \le t \le 2000$) — the number of test cases. Then $t$ test cases follow.

    The first line of the test case contains one integer $n$ ($1 \le n \le 2000$) — the length of $a$. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 26$), where $a_i$ is the $i$-th element of $a$. Note that the maximum value of $a_i$ can be up to $26$.

    It is guaranteed that the sum of $n$ over all test cases does not exceed $2000$ ($\sum n \le 2000$).

    -----Output-----

    For each test case, print the answer — the maximum possible length of some subsequence of $a$ that is a three blocks palindrome.

    -----Example-----
    Input
    6
    8
    1 1 2 2 3 2 1 1
    3
    1 3 3
    4
    1 10 10 1
    1
    26
    2
    2 1
    3
    1 1 1

    Output
    7
    2
    4
    1
    1
    3
    """


Prompt:
def moment_of_time_in_space(moment: str) -> List[bool]:
    """
    # Task
    You are given a `moment` in time and space. What you must do is break it down into time and space, to determine if that moment is from the past, present or future.

    `Time` is the sum of characters that increase time (i.e. numbers in range ['1'..'9'].

    `Space` in the number of characters which do not increase time (i.e. all characters but those that increase time).

    The moment of time is determined as follows:
    ```
    If time is greater than space, than the moment is from the future.
    If time is less than space, then the moment is from the past.
    Otherwise, it is the present moment.```

    You should return an array of three elements, two of which are false, and one is true. The true value should be at the `1st, 2nd or 3rd` place for `past, present and future` respectively.

    # Examples

    For `moment = "01:00 pm"`, the output should be `[true, false, false]`.

    time equals 1, and space equals 7, so the moment is from the past.

    For `moment = "12:02 pm"`, the output should be `[false, true, false]`.

    time equals 5, and space equals 5, which means that it's a present moment.

    For `moment = "12:30 pm"`, the output should be `[false, false, true]`.

    time equals 6, space equals 5, so the moment is from the future.

    # Input/Output

    - `[input]` string `moment`

    The moment of time and space that the input time came from.

    - `[output]` a boolean array

    Array of three elements, two of which are false, and one is true. The true value should be at the 1st, 2nd or 3rd place for past, present and future respectively.
    """

def check(candidate):
    assert candidate('12:30 am') == [False, False, True]
    assert candidate('12:02 pm') == [False, True, False]
    assert candidate('01:00 pm') == [True, False, False]
    assert candidate('11:12 am') == [False, False, True]
    assert candidate('05:20 pm') == [False, False, True]
    assert candidate('04:20 am') == [False, True, False]
check(moment_of_time_in_space)

assert moment_of_time_in_space('12:02 pm') == [False, True, False]

assert moment_of_time_in_space('12:30 am') == [False, False, True]

assert moment_of_time_in_space('01:00 pm') == [True, False, False]


Prompt:
def max_distance_between_ones(n: int) -> int:
    """
    Given a positive integer n, find and return the longest distance between any two adjacent 1's in the binary representation of n. If there are no two adjacent 1's, return 0.
    Two 1's are adjacent if there are only 0's separating them (possibly no 0's). The distance between two 1's is the absolute difference between their bit positions. For example, the two 1's in "1001" have a distance of 3.

    Example 1:
    Input: n = 22
    Output: 2
    Explanation: 22 in binary is "10110".
    The first adjacent pair of 1's is "10110" with a distance of 2.
    The second adjacent pair of 1's is "10110" with a distance of 1.
    The answer is the largest of these two distances, which is 2.
    Note that "10110" is not a valid pair since there is a 1 separating the two 1's underlined.

    Example 2:
    Input: n = 5
    Output: 2
    Explanation: 5 in binary is "101".

    Example 3:
    Input: n = 6
    Output: 1
    Explanation: 6 in binary is "110".

    Example 4:
    Input: n = 8
    Output: 0
    Explanation: 8 in binary is "1000".
    There aren't any adjacent pairs of 1's in the binary representation of 8, so we return 0.

    Example 5:
    Input: n = 1
    Output: 0

    Constraints:

    1 <= n <= 109
    """

def check(candidate):
    assert candidate(22) == 2
    assert candidate(5) == 2
    assert candidate(8) == 0
check(max_distance_between_ones)

assert max_distance_between_ones(22) == 2

assert max_distance_between_ones(8) == 0

assert max_distance_between_ones(5) == 2


Prompt:
def bin2gray(bits: list) -> list:
    """
    Gray code is a form of binary encoding where transitions between consecutive numbers differ by only one bit. This is a useful encoding for reducing hardware data hazards with values that change rapidly and/or connect to slower hardware as inputs. It is also useful for generating inputs for Karnaugh maps.

    Here is an exemple of what the code look like:

    ```
    0:    0000
    1:    0001
    2:    0011
    3:    0010
    4:    0110
    5:    0111
    6:    0101
    7:    0100
    8:    1100
    ```

    The goal of this kata is to build two function bin2gray and gray2bin wich will convert natural binary to Gray Code and vice-versa. We will use the "binary reflected Gray code". The input and output will be arrays of 0 and 1, MSB at index 0.

    There are "simple" formula to implement these functions. It is a very interesting exercise to find them by yourself.

    All input will be correct binary arrays.
    """


Prompt:
def pig_latin(s: str) -> str:
    """
    Pig Latin is an English language game where the goal is to hide the meaning of a word from people not aware of the rules.

    So, the goal of this kata is to wite a function that encodes a single word string to pig latin.

    The rules themselves are rather easy:

    1) The word starts with a vowel(a,e,i,o,u) -> return the original string plus "way".

    2) The word starts with a consonant -> move consonants from the beginning of the word to the end of the word until the first vowel, then return it plus "ay".

    3) The result must be lowercase, regardless of the case of the input. If the input string has any non-alpha characters, the function must return None, null, Nothing (depending on the language).

    4) The function must also handle simple random strings and not just English words.

    5) The input string has no vowels -> return the original string plus "ay".

    For example, the word "spaghetti" becomes "aghettispay" because the first two letters ("sp") are consonants, so they are moved to the end of the string and "ay" is appended.
    """

def check(candidate):
    assert candidate('Hello') == 'ellohay'
    assert candidate('CCCC') == 'ccccay'
    assert candidate('tes3t5') == None
    assert candidate('ay') == 'ayway'
    assert candidate('') == None
    assert candidate('YA') == 'ayay'
    assert candidate('123') == None
    assert candidate('ya1') == None
    assert candidate('yaYAya') == 'ayayayay'
    assert candidate('YayayA') == 'ayayayay'
check(pig_latin)

assert pig_latin('spaghetti') == 'aghettispay'


Prompt:
def modifyString(s: str) -> str:
    """
    Given a string s containing only lower case English letters and the '?' character, convert all the '?' characters into lower case letters such that the final string does not contain any consecutive repeating characters. You cannot modify the non '?' characters.
    It is guaranteed that there are no consecutive repeating characters in the given string except for '?'.
    Return the final string after all the conversions (possibly zero) have been made. If there is more than one solution, return any of them. It can be shown that an answer is always possible with the given constraints.

    Example 1:
    Input: s = "?zs"
    Output: "azs"
    Explanation: There are 25 solutions for this problem. From "azs" to "yzs", all are valid. Only "z" is an invalid modification as the string will consist of consecutive repeating characters in "zzs".
    Example 2:
    Input: s = "ubv?w"
    Output: "ubvaw"
    Explanation: There are 24 solutions for this problem. Only "v" and "w" are invalid modifications as the strings will consist of consecutive repeating characters in "ubvvw" and "ubvww".

    Example 3:
    Input: s = "j?qg??b"
    Output: "jaqgacb"

    Example 4:
    Input: s = "??yw?ipkj?"
    Output: "acywaipkja"

    Constraints:

    1 <= s.length <= 100
    s contains only lower case English letters and '?'.
    """

def check(candidate):
    assert candidate('?zs') == 'azs'
    assert candidate('ubv?w') == 'ubvaw'
    assert candidate('j?qg??b') == 'jaqgacb'
    assert candidate('??yw?ipkj?') == 'acywaipkja'
check(modifyString)

assert modifyString('j?qg??b') == 'jaqgacb'

assert modifyString('??yw?ipkj?') == 'acywaipkja'


Prompt:
def blocks(s: str) -> str:
    """
    ## Task

    You will receive a string consisting of lowercase letters, uppercase letters and digits as input. Your task is to return this string as blocks separated by dashes (`"-"`). The elements of a block should be sorted with respect to the hierarchy listed below, and each block cannot contain multiple instances of the same character. Elements should be put into the first suitable block.

    The hierarchy is:
    1. lowercase letters (`a - z`), in alphabetical order
    2. uppercase letters (`A - Z`), in alphabetical order
    3. digits (`0 - 9`), in ascending order

    ## Examples

    * `"21AxBz" -> "xzAB12"` - since input does not contain repeating characters, you only need 1 block
    * `"abacad" -> "abcd-a-a"` - character "a" repeats 3 times, thus 3 blocks are needed
    * `"" -> ""` - an empty input should result in an empty output
    * `"hbh420sUUW222IWOxndjn93cdop69NICEep832" -> "bcdehjnopsxCEINOUW0234689-dhnpIUW239-2-2-2"` - a more sophisticated example

    Good luck!
    """

def check(candidate):
    assert candidate('heyitssampletestkk') == 'aeiklmpsty-ehkst-s'
    assert candidate('dasf6ds65f45df65gdf651vdf5s1d6g5f65vqweAQWIDKsdds') == 'adefgqsvwADIKQW1456-dfgsv156-dfs56-dfs56-dfs56-df56-d5-d'
    assert candidate('SDF45648374RHF8BFVYg378rg3784rf87g3278bdqG') == 'bdfgqrBDFGHRSVY2345678-grF3478-gF3478-3478-78-8'
    assert candidate('') == ''
    assert candidate('aaaaaaaaaa') == 'a-a-a-a-a-a-a-a-a-a'
check(blocks)

assert blocks('21AxBz') == 'xzAB12'
assert blocks('abacad') == 'abcd-a-a'
assert blocks('->') == ''


Prompt:
def AlanAnnoyingKid(sentence: str) -> str:
    """
    Alan's child can be annoying at times.

    When Alan comes home and tells his kid what he has accomplished today, his kid never believes him.

    Be that kid.

    Your function 'AlanAnnoyingKid' takes as input a sentence spoken by Alan (a string). The sentence contains the following structure:

    "Today I " + [action_verb] + [object] + "."

    (e.g.: "Today I played football.")

    Your function will return Alan's kid response, which is another sentence with the following structure:

    "I don't think you " + [action_performed_by_alan] + " today, I think you " + ["did" OR "didn't"] + [verb_of _action_in_present_tense] + [" it!" OR " at all!"]

    (e.g.:"I don't think you played football today, I think you didn't play at all!")

    Note the different structure depending on the presence of a negation in Alan's first sentence (e.g., whether Alan says "I dind't play football", or "I played football").

    ! Also note: Alan's kid is young and only uses simple, regular verbs that use a simple "ed" to make past tense.
    There are random test cases.

    Some more examples:

    input  = "Today I played football."
    output = "I don't think you played football today, I think you didn't play at all!"

    input  = "Today I didn't attempt to hardcode this Kata."
    output = "I don't think you didn't attempt to hardcode this Kata today, I think you did attempt it!"

    input  = "Today I didn't play football."
    output = "I don't think you didn't play football today, I think you did play it!"

    input  = "Today I cleaned the kitchen."
    output = "I don't think you cleaned the kitchen today, I think you didn't clean at all!"
    """

def check(candidate):
    assert candidate('Today I played football.') == "I don't think you played football today, I think you didn't play at all!"
    assert candidate("Today I didn't play football.") == "I don't think you didn't play football today, I think you did play it!"
    assert candidate("Today I didn't attempt to hardcode this Kata.") == "I don't think you didn't attempt to hardcode this Kata today, I think you did attempt it!"
    assert candidate('Today I cleaned the kitchen.') == "I don't think you cleaned the kitchen today, I think you didn't clean at all!"
    assert candidate('Today I learned to code like a pro.') == "I don't think you learned to code like a pro today, I think you didn't learn at all!"
check(AlanAnnoyingKid)

assert AlanAnnoyingKid('Today I played football.') == "I don't think you played football today, I think you didn't play at all!"

assert AlanAnnoyingKid("Today I didn't attempt to hardcode this Kata.") == "I don't think you didn't attempt to hardcode this Kata today, I think you did attempt it!"

assert AlanAnnoyingKid("Today I didn't play football.") == "I don't think you didn't play football today, I think you did play it!"

assert AlanAnnoyingKid('Today I cleaned the kitchen.') == "I don't think you cleaned the kitchen today, I think you didn't clean at all!"


Prompt:
def T9(words: list, seq: str) -> list:
    """
    The T9 typing predictor helps with suggestions for possible word combinations on an old-style numeric keypad phone. Each digit in the keypad (2-9) represents a group of 3-4 letters. To type a letter, press once the key which corresponds to the letter group that contains the required letter. Typing words is done by typing letters of the word in sequence.

    The letter groups and corresponding digits are as follows:
    ```
    -----------------
    |  1  |  2  |  3  |
    |     | ABC | DEF |
    |-----|-----|-----|
    |  4  |  5  |  6  |
    | GHI | JKL | MNO |
    |-----|-----|-----|
    |  7  |  8  |  9  |
    | PQRS| TUV | WXYZ|
    -----------------
    ```

    The prediction algorithm tries to match the input sequence against a predefined dictionary of words. The combinations which appear in the dictionary are considered valid words and are shown as suggestions.

    Given a list of words as a reference dictionary, and a non-empty string (of digits 2-9) as input, complete the function which returns suggestions based on the string of digits, which are found in the reference dictionary.

    For example:
    ```python
    T9(['hello', 'world'], '43556') returns ['hello']
    T9(['good', 'home', 'new'], '4663') returns ['good', 'home']
    ```

    Note that the dictionary must be case-insensitive (`'hello'` and `'Hello'` are same entries). The list returned must contain the word as it appears in the dictionary (along with the case).

    Example:
    ```python
    T9(['Hello', 'world'], '43556') returns ['Hello']
    ```

    If there is no prediction available from the given dictionary, then return the string containing first letters of the letter groups, which correspond to the input digits.

    For example:
    ```python
    T9([], '43556') returns ['gdjjm']
    T9(['gold', 'word'], '4663') returns ['gmmd']
    ```
    """

def check(candidate):
    assert candidate(['hello', 'world'], '43556') == ['hello']
    assert candidate(['good', 'home', 'new'], '4663') == ['good', 'home']
    assert candidate(['gone', 'hood', 'good', 'old'], '4663') == ['gone', 'hood', 'good']
    assert candidate(['Hello', 'world'], '43556') == ['Hello']
    assert candidate(['gOOD', 'hOmE', 'NeW'], '4663') == ['gOOD', 'hOmE']
    assert candidate(['goNe', 'hood', 'GOOD', 'old'], '4663') == ['goNe', 'hood', 'GOOD']
    assert candidate([], '43556') == ['gdjjm']
    assert candidate(['gold'], '4663') == ['gmmd']
    assert candidate(['gone', 'hood', 'good', 'old'], '729') == ['paw']
check(T9)


Prompt:
def wheat_from_chaff(values: list) -> list:
    """
    # Scenario

    With **_Cereal crops_** like wheat or rice, before we can eat the grain kernel, we need to remove that inedible hull, or *to separate the wheat from the chaff*.
    ___

    # Task

    **_Given_** a *sequence of n integers* , **_separate_** *the negative numbers (chaff) from positive ones (wheat).*
    ___

    # Notes

    * **_Sequence size_** is _at least_ **_3_**
    * **_Return_** *a new sequence*, such that  **_negative numbers (chaff) come first, then positive ones (wheat)_**.
    * In Java , *you're not allowed to modify the input Array/list/Vector*
    * **_Have no fear_** , *it is guaranteed that there will be no zeroes* .
    * **_Repetition_** of numbers in *the input sequence could occur* , so **_duplications are included when separating_**.
    * If a misplaced *positive* number is found in the front part of the sequence, replace it with the last misplaced negative number (the one found near the end of the input). The second misplaced positive number should be swapped with the second last misplaced negative number. *Negative numbers found at the head (begining) of the sequence* , **_should be kept in place_** .

    ____

    # Input >> Output Examples:

    ```
    wheatFromChaff ({7, -8, 1 ,-2}) ==> return ({-2, -8, 1, 7})
    ```

    ## **_Explanation_**:

    * **_Since_** `7 ` is a  **_positive number_** , it should not be located at the beginnig so it needs to be swapped with the **last negative number** `-2`.
    ____

    ```
    wheatFromChaff ({-31, -5, 11 , -42, -22, -46, -4, -28 }) ==> return ({-31, -5,- 28, -42, -22, -46 , -4, 11})
    ```

    ## **_Explanation_**:

    * **_Since_**, `{-31, -5} ` are  **_negative numbers_** *found at the head (begining) of the sequence* , *so we keep them in place* .
    * Since `11` is a positive number, it's replaced by  the last negative which is `-28` , and so on till sepration is complete.

    ____

    ```
    wheatFromChaff ({-25, -48, -29, -25, 1, 49, -32, -19, -46, 1}) ==> return ({-25, -48, -29, -25, -46, -19, -32, 49, 1, 1})
    ```

    ## **_Explanation_**:

    * **_Since_** `{-25, -48, -29, -25} ` are  **_negative numbers_** *found at the head (begining) of the input* , *so we keep them in place* .

    * Since `1` is a positive number, it's replaced by  the last negative which is `-46` , and so on till sepration is complete.

    * Remeber, *duplications are included when separating* , that's why the number `1` appeared twice at the end of the output.
    ____

    # Tune Your Code , There are 250 Assertions , 100.000 element For Each .

    # Only O(N) Complexity Solutions Will pass .
    ____
    """


Prompt:
def is_rectangle_overlap(rec1: list, rec2: list) -> bool:
    """
    An axis-aligned rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) is the coordinate of its bottom-left corner, and (x2, y2) is the coordinate of its top-right corner. Its top and bottom edges are parallel to the X-axis, and its left and right edges are parallel to the Y-axis.
    Two rectangles overlap if the area of their intersection is positive. To be clear, two rectangles that only touch at the corner or edges do not overlap.
    Given two axis-aligned rectangles rec1 and rec2, return true if they overlap, otherwise return false.

    Example 1:
    Input: rec1 = [0,0,2,2], rec2 = [1,1,3,3]
    Output: true
    Example 2:
    Input: rec1 = [0,0,1,1], rec2 = [1,0,2,1]
    Output: false
    Example 3:
    Input: rec1 = [0,0,1,1], rec2 = [2,2,3,3]
    Output: false

    Constraints:

    rect1.length == 4
    rect2.length == 4
    -109 <= rec1[i], rec2[i] <= 109
    rec1[0] <= rec1[2] and rec1[1] <= rec1[3]
    rec2[0] <= rec2[2] and rec2[1] <= rec2[3]
    """

def check(candidate):
    assert candidate([0, 0, 2, 2], [1, 1, 3, 3]) == True
    assert candidate([0, 0, 1, 1], [1, 0, 2, 1]) == False
    assert candidate([0, 0, 1, 1], [2, 2, 3, 3]) == False
check(is_rectangle_overlap)

assert is_rectangle_overlap([0, 0, 2, 2], [1, 1, 3, 3]) == True

assert is_rectangle_overlap([0, 0, 1, 1], [1, 0, 2, 1]) == False

assert is_rectangle_overlap([0, 0, 1, 1], [2, 2, 3, 3]) == False


Prompt:
def buddy_strings(A: str, B: str) -> bool:
    """
    Given two strings A and B of lowercase letters, return true if you can swap two letters in A so the result is equal to B, otherwise, return false.
    Swapping letters is defined as taking two indices i and j (0-indexed) such that i != j and swapping the characters at A[i] and A[j]. For example, swapping at indices 0 and 2 in "abcd" results in "cbad".

    Example 1:
    Input: A = "ab", B = "ba"
    Output: true
    Explanation: You can swap A[0] = 'a' and A[1] = 'b' to get "ba", which is equal to B.

    Example 2:
    Input: A = "ab", B = "ab"
    Output: false
    Explanation: The only letters you can swap are A[0] = 'a' and A[1] = 'b', which results in "ba" != B.

    Example 3:
    Input: A = "aa", B = "aa"
    Output: true
    Explanation: You can swap A[0] = 'a' and A[1] = 'a' to get "aa", which is equal to B.

    Example 4:
    Input: A = "aaaaaaabc", B = "aaaaaaacb"
    Output: true

    Example 5:
    Input: A = "", B = "aa"
    Output: false

    Constraints:

    0 <= A.length <= 20000
    0 <= B.length <= 20000
    A and B consist of lowercase letters.
    """

def check(candidate):
    assert candidate('ab', 'ba') == True
    assert candidate('ab', 'ab') == False
    assert candidate('aa', 'aa') == True
    assert candidate('aaaaaaabc', 'aaaaaaacb') == True
    assert candidate('', 'aa') == False
check(buddy_strings)

assert buddy_strings('ab', 'ba') == True

assert buddy_strings('ab', 'ab') == False

assert buddy_strings('aa', 'aa') == True

assert buddy_strings('aaaaaaabc', 'aaaaaaacb') == True


Prompt:
def mystery_range(s: str, n: int) -> list[int]:
    """
    In this kata, your task is to write a function that returns the smallest and largest integers in an unsorted string. In this kata, a range is considered a finite sequence of consecutive integers.
    Input
    Your function will receive two arguments:

    A string comprised of integers in an unknown range; think of this string as the result when a range of integers is shuffled around in random order then joined together into a string
    An integer value representing the size of the range

    Output
    Your function should return the starting (minimum) and ending (maximum) numbers of the range in the form of an array/list comprised of two integers.

    Test Example

    ```python
    input_string = '1568141291110137'

    mystery_range(input_string, 10) # [6, 15]

    # The 10 numbers in this string are:
    # 15 6 8 14 12 9 11 10 13 7
    # Therefore the range of numbers is from 6 to 15
    ```

    Technical Details

    The maximum size of a range will be 100 integers
    The starting number of a range will be: 0 < n < 100
    Full Test Suite: 21 fixed tests, 100 random tests
    Use Python 3+ for the Python translation
    For JavaScript, require has been disabled and most built-in prototypes have been frozen (prototype methods can be added to Array and Function)
    All test cases will be valid

    If you enjoyed this kata, be sure to check out my other katas
    """

def check(candidate):
    assert candidate('1568141291110137', 10) == [6, 15]
check(mystery_range)


Prompt:
def min_start_value(nums: list[int]) -> int:
    """
    Given an array of integers nums, you start with an initial positive value startValue.
    In each iteration, you calculate the step by step sum of startValue plus elements in nums (from left to right).
    Return the minimum positive value of startValue such that the step by step sum is never less than 1.

    Example 1:
    Input: nums = [-3,2,-3,4,2]
    Output: 5
    Explanation: If you choose startValue = 4, in the third iteration your step by step sum is less than 1.
    step by step sum
    startValue = 4 | startValue = 5 | nums
    (4 -3 ) = 1  | (5 -3 ) = 2    |  -3
    (1 +2 ) = 3  | (2 +2 ) = 4    |   2
    (3 -3 ) = 0  | (4 -3 ) = 1    |  -3
    (0 +4 ) = 4  | (1 +4 ) = 5    |   4
    (4 +2 ) = 6  | (5 +2 ) = 7    |   2

    Example 2:
    Input: nums = [1,2]
    Output: 1
    Explanation: Minimum start value should be positive.

    Example 3:
    Input: nums = [1,-2,-3]
    Output: 5

    Constraints:

    1 <= nums.length <= 100
    -100 <= nums[i] <= 100
    """

def check(candidate):
    assert candidate([-3, 2, -3, 4, 2]) == 5
    assert candidate([1, 2]) == 1
    assert candidate([1, -2, -3]) == 5
check(min_start_value)


Prompt:
def encode(stg: str) -> str:
    """
    *Translations appreciated*

    ## Background information

    The Hamming Code is used to correct errors, so-called bit flips, in data transmissions. Later in the description follows a detailed explanation of how it works.
    In this Kata we will implement the Hamming Code with bit length 3, this has some advantages and disadvantages:
    - ✓ Compared to other versions of hamming code, we can correct more mistakes
    - ✓ It's simple to implement
    - x  The size of the input triples

    ## Task 1: Encode function:

    First of all we have to implement the encode function, which is pretty easy, just follow the steps below.

    Steps:
    1. convert every letter of our text to ASCII value
    2. convert ASCII value to 8-bit binary string
    3. replace every "0" with "000" and every "1" with "111"

    Let's do an example:

    We have to convert the string ```hey``` to hamming code sequence.

    1. First convert it to ASCII values:

    ```104``` for ```h```, ```101``` for ```e``` and ```121``` for ```y```.

    2. Now we convert the ASCII values to a 8-bit binary string:

    ```104``` -> ```01101000```, ```101``` -> ```01100101``` and ```121``` -> ```01111001```

    if we concat the binarys we get ```011010000110010101111001```

    3. Now we replace every "0" with "000" and every "1" with "111":

    ```011010000110010101111001``` -> ```000111111000111000000000000111111000000111000111000111111111111000000111```

    That's it good job!

    ## Task 2: Decode function:

    Now we have to check if there happened any mistakes and correct them.
    Errors will only be a bit flip and not a loose of bits, so the length of the input string is always divisible by 3.

    example:
    - 111 --> 101  this can and will happen
    - 111 --> 11   this won't happen

    The length of the input string is also always divsible by 24 so that you can convert it to an ASCII value.

    Steps:
    1. Split the string of 0 and 1 in groups of three characters example: "000", "111"
    2. Check if an error occured:
    If no error occured the group is "000" or "111", then replace "000" with "0" and "111" with 1
    If an error occured the group is for example "001" or "100" or "101" and so on...
    Replace this group with the character that occurs most often. example: "010" -> "0" , "110" -> "1"

    3. Now take a group of 8 characters and convert that binary number to decimal ASCII value
    4. Convert the ASCII value to a char and well done you made it :)

    Look at this example carefully to understand it better:

    We got a bit sequence:

    ```100111111000111001000010000111111000000111001111000111110110111000010111```

    First we split the bit sequence into groups of three:

    ```100```, ```111```, ```111```, ```000```, ```111```, ```001``` ....

    Every group with the most "0" becomes "0" and every group with the most "1" becomes "1":

    ```100``` -> ```0``` Because there are two ```0``` and only one ```1```

    ```111``` -> ```1``` Because there are zero ```0``` and three ```1```

    ```111``` -> ```1``` Because there are zero ```0``` and three ```1```

    ```000``` -> ```0``` Because there are three ```0``` and zero ```1```

    ```111``` -> ```1``` Because there are zero ```0``` and three ```1```

    ```001``` -> ```0``` Because there are two ```0``` and one ```1```

    Now concat all 0 and 1 to get ```011010000110010101111001```

    We split this string into groups of eight:
    ```01101000```, ```01100101``` and ```01111001```.

    And now convert it back to letters:

    ```01101000``` is binary representation of 104, which is ASCII value of ```h```

    ```01100101``` is binary representation of 101, which is ASCII value of ```e```

    ```01111001``` is binary representation of 121, which is ASCII value of ```y```

    Now we got our word ```hey``` !
    """

    def decode(bits: str) -> str:
    """
    Now we have to check if there happened any mistakes and correct them.
    Errors will only be a bit flip and not a loss of bits, so the length of the input string is always divisible by 3.
    Split the string of 0 and 1 in groups of three characters. Check if an error occurred:
    If no error occurred the group is '000' or '111', then replace '000' with '0' and '111' with '1'.
    If an error occurred the group is for example '001' or '100' or '101' and so on...
    Replace this group with the character that occurs most often. Take a group of 8 characters and convert that binary number to decimal ASCII value.
    Convert the ASCII value to a character.

    Args:
    bits (str): The input string of bits to be decoded.

    Returns:
    str: The decoded string from the Hamming Code.
    """


Prompt:
def min_cost_to_move_chips(position: list[int]) -> int:
    """
    We have n chips, where the position of the ith chip is position[i].
    We need to move all the chips to the same position. In one step, we can change the position of the ith chip from position[i] to:

    position[i] + 2 or position[i] - 2 with cost = 0.
    position[i] + 1 or position[i] - 1 with cost = 1.

    Return the minimum cost needed to move all the chips to the same position.

    Example 1:

    Input: position = [1,2,3]
    Output: 1
    Explanation: First step: Move the chip at position 3 to position 1 with cost = 0.
    Second step: Move the chip at position 2 to position 1 with cost = 1.
    Total cost is 1.

    Example 2:

    Input: position = [2,2,2,3,3]
    Output: 2
    Explanation: We can move the two chips at poistion 3 to position 2. Each move has cost = 1. The total cost = 2.

    Example 3:
    Input: position = [1,1000000000]
    Output: 1

    Constraints:

    1 <= position.length <= 100
    1 <= position[i] <= 10^9
    """

def check(candidate):
    assert candidate([1, 2, 3]) == 1
    assert candidate([2, 2, 2, 3, 3]) == 2
    assert candidate([1, 1000000000]) == 1
check(min_cost_to_move_chips)

assert min_cost_to_move_chips([1, 2, 3]) == 1

assert min_cost_to_move_chips([2,2,2,3,3]) == 2

assert min_cost_to_move_chips([1,1000000000]) == 1


Prompt:
def build_palindrome(s: str) -> str:
    """
    ## Task

    Given a string, add the fewest number of characters possible from the front or back to make it a palindrome.

    ## Example

    For the input `cdcab`, the output should be `bacdcab`

    ## Input/Output

    Input is a string consisting of lowercase latin letters with length 3 <= str.length <= 10

    The output is a palindrome string satisfying the task.

    For s = `ab` either solution (`aba` or `bab`) will be accepted.
    """

def check(candidate):
    assert candidate('abcdc') == 'abcdcba'
    assert candidate('ababa') == 'ababa'
check(build_palindrome)

assert build_palindrome('cdcab') == 'bacdcab'


Prompt:
def containsDuplicate(nums: list[int]) -> bool:
    """
    Given an array of integers, find if the array contains any duplicates.

    Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.

    Example 1:

    Input: [1,2,3,1]
    Output: true

    Example 2:

    Input: [1,2,3,4]
    Output: false

    Example 3:

    Input: [1,1,1,3,3,4,3,2,4,2]
    Output: true
    """

def check(candidate):
    assert candidate([1, 2, 3, 1]) == True
    assert candidate([1, 2, 3, 4]) == False
    assert candidate([1, 1, 1, 3, 3, 4, 3, 2, 4, 2]) == True
check(containsDuplicate)

assert containsDuplicate([1, 2, 3, 1]) == True

assert containsDuplicate([1, 2, 3, 4]) == False

assert containsDuplicate([1, 1, 1, 3, 3, 4, 3, 2, 4, 2]) == True


Prompt:
def vaccine_list(age: str, status: str, month: str) -> list[str]:
    """
    ### Vaccinations for children under 5
    You have been put in charge of administrating vaccinations for children in your local area. Write a function that will generate a list of vaccines for each child presented for vaccination, based on the child's age and vaccination history, and the month of the year.
    #### The function takes three parameters: age, status and month
    - The parameter 'age' will be given in weeks up to 16 weeks, and thereafter in months. You can assume that children presented will be scheduled for vaccination (eg '16 weeks', '12 months' etc).
    - The parameter 'status' indicates if the child has missed a scheduled vaccination, and the argument will be a string that says 'up-to-date', or a scheduled stage (eg '8 weeks') that has been missed, in which case you need to add any missing shots to the list. Only one missed vaccination stage will be passed in per function call.
    - If the month is 'september', 'october' or 'november' add 'offer fluVaccine' to the list.
    - Make sure there are no duplicates in the returned list, and sort it alphabetically.

    #### Example input and output
    ~~~~
    input     ('12 weeks', 'up-to-date', 'december')
    output    ['fiveInOne', 'rotavirus']

    input     ('12 months', '16 weeks', 'june')
    output     ['fiveInOne', 'hibMenC', 'measlesMumpsRubella', 'meningitisB', 'pneumococcal']

    input     ('40 months', '12 months', 'october')
    output    ['hibMenC', 'measlesMumpsRubella', 'meningitisB', 'offer fluVaccine', 'preSchoolBooster']
    ~~~~

    #### To save you typing it up, here is the vaccinations list
    ~~~~
    fiveInOne : ['8 weeks', '12 weeks', '16 weeks'],
    //Protects against: diphtheria, tetanus, whooping cough, polio and Hib (Haemophilus influenzae type b)
    pneumococcal : ['8 weeks', '16 weeks'],
    //Protects against: some types of pneumococcal infection
    rotavirus : ['8 weeks', '12 weeks'],
    //Protects against: rotavirus infection, a common cause of childhood diarrhoea and sickness
    meningitisB : ['8 weeks', '16 weeks', '12 months'],
    //Protects against: meningitis caused by meningococcal type B bacteria
    hibMenC : ['12 months'],
    //Protects against: Haemophilus influenzae type b (Hib), meningitis caused by meningococcal group C bacteria
    measlesMumpsRubella : ['12 months', '40 months'],
    //Protects against: measles, mumps and rubella
    fluVaccine : ['september','october','november'],
    //Given at: annually in Sept/Oct
    preSchoolBooster : ['40 months']
    //Protects against: diphtheria, tetanus, whooping cough and polio
    ~~~~
    """

def check(candidate):
    assert candidate('12 weeks', 'up-to-date', 'december') == ['fiveInOne', 'rotavirus']
    assert candidate('12 months', '16 weeks', 'june') == ['fiveInOne', 'hibMenC', 'measlesMumpsRubella', 'meningitisB', 'pneumococcal']
    assert candidate('40 months', '12 months', 'october') == ['hibMenC', 'measlesMumpsRubella', 'meningitisB', 'offer fluVaccine', 'preSchoolBooster']
check(vaccine_list)

assert vaccine_list('12 weeks', 'up-to-date', 'december') == ['fiveInOne', 'rotavirus']

assert vaccine_list('12 months', '16 weeks', 'june') == ['fiveInOne', 'hibMenC', 'measlesMumpsRubella', 'meningitisB', 'pneumococcal']

assert vaccine_list('40 months', '12 months', 'october') == ['hibMenC', 'measlesMumpsRubella', 'meningitisB', 'offer fluVaccine', 'preSchoolBooster']


Prompt:
def max_burles_spent(t: int, test_cases: list[int]) -> list[int]:
    """
    Mishka wants to buy some food in the nearby shop. Initially, he has $s$ burles on his card.

    Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer number $1 \le x \le s$, buy food that costs exactly $x$ burles and obtain $\lfloor\frac{x}{10}\rfloor$ burles as a cashback (in other words, Mishka spends $x$ burles and obtains $\lfloor\frac{x}{10}\rfloor$ back). The operation $\lfloor\frac{a}{b}\rfloor$ means $a$ divided by $b$ rounded down.

    It is guaranteed that you can always buy some food that costs $x$ for any possible value of $x$.

    Your task is to say the maximum number of burles Mishka can spend if he buys food optimally.

    For example, if Mishka has $s=19$ burles then the maximum number of burles he can spend is $21$. Firstly, he can spend $x=10$ burles, obtain $1$ burle as a cashback. Now he has $s=10$ burles, so can spend $x=10$ burles, obtain $1$ burle as a cashback and spend it too.

    You have to answer $t$ independent test cases.

    -----Input-----

    The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

    The next $t$ lines describe test cases. Each test case is given on a separate line and consists of one integer $s$ ($1 \le s \le 10^9$) — the number of burles Mishka initially has.

    -----Output-----

    For each test case print the answer on it — the maximum number of burles Mishka can spend if he buys food optimally.

    -----Example-----
    Input
    6
    1
    10
    19
    9876
    12345
    1000000000

    Output
    1
    11
    21
    10973
    13716
    1111111111
    """


Prompt:
def pac_man(N: int, PM: list[int], enemies: list[list[int]]) -> int:
    """
    # Task
    Pac-Man got lucky today! Due to minor performance issue all his enemies have frozen. Too bad Pac-Man is not brave enough to face them right now, so he doesn't want any enemy to see him.

    Given a gamefield of size `N` x `N`, Pac-Man's position(`PM`) and his enemies' positions(`enemies`), your task is to count the number of coins he can collect without being seen.

    An enemy can see a Pac-Man if they are standing on the same row or column.

    It is guaranteed that no enemy can see Pac-Man on the starting position. There is a coin on each empty square (i.e. where there is no Pac-Man or enemy).

    # Example

    For `N = 4, PM = [3, 0], enemies = [[1, 2]]`, the result should be `3`.
    ```
    Let O represent coins, P - Pac-Man and E - enemy.
    OOOO
    OOEO
    OOOO
    POOO```
    Pac-Man cannot cross row 1 and column 2.

    He can only collect coins from points `(2, 0), (2, 1) and (3, 1)`, like this:
    ```
    x is the points that Pac-Man can collect the coins.
    OOOO
    OOEO
    xxOO
    PxOO
    ```

    # Input/Output

    - `[input]` integer `N`

    The field size.

    - `[input]` integer array `PM`

    Pac-Man's position (pair of integers)

    - `[input]` 2D integer array `enemies`

    Enemies' positions (array of pairs)

    - `[output]` an integer

    Number of coins Pac-Man can collect.

    # More PacMan Katas

    - [Play PacMan: Devour all](https://www.codewars.com/kata/575c29d5fcee86cb8b000136)

    - [Play PacMan 2: The way home](https://www.codewars.com/kata/575ed46e23891f67d90000d8)
    """


Prompt:
def distanceBetweenBusStops(distance: List[int], start: int, destination: int) -> int:
    """
    A bus has n stops numbered from 0 to n - 1 that form a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number i and (i + 1) % n.
    The bus goes along both directions i.e. clockwise and counterclockwise.
    Return the shortest distance between the given start and destination stops.

    Example 1:

    Input: distance = [1,2,3,4], start = 0, destination = 1
    Output: 1
    Explanation: Distance between 0 and 1 is 1 or 9, minimum is 1.

    Example 2:

    Input: distance = [1,2,3,4], start = 0, destination = 2
    Output: 3
    Explanation: Distance between 0 and 2 is 3 or 7, minimum is 3.

    Example 3:

    Input: distance = [1,2,3,4], start = 0, destination = 3
    Output: 4
    Explanation: Distance between 0 and 3 is 6 or 4, minimum is 4.

    Constraints:

    1 <= n <= 10^4
    distance.length == n
    0 <= start, destination < n
    0 <= distance[i] <= 10^4
    """

def check(candidate):
    assert candidate([1, 2, 3, 4], 0, 1) == 1
    assert candidate([1, 2, 3, 4], 0, 2) == 3
    assert candidate([1, 2, 3, 4], 0, 3) == 4
check(distanceBetweenBusStops)

assert distanceBetweenBusStops([1, 2, 3, 4], 0, 1) == 1

assert distanceBetweenBusStops([1, 2, 3, 4], 0, 2) == 3

assert distanceBetweenBusStops([1, 2, 3, 4], 0, 3) == 4


Prompt:
def reverse(x: int) -> int:
    """
    Given a 32-bit signed integer, reverse digits of an integer.

    Example 1:

    Input: 123
    Output: 321

    Example 2:

    Input: -123
    Output: -321

    Example 3:

    Input: 120
    Output: 21

    Note:
    Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
    """

def check(candidate):
    assert candidate(123) == 321
    assert candidate(-123) == -321
    assert candidate(120) == 21
check(reverse)

assert reverse(123) == 321
assert reverse(-123) == -321
assert reverse(120) == 21


Prompt:
def min_moves_to_regular_bracket_sequence(t: int, test_cases: list[tuple[int, str]]) -> list[int]:
    """
    You are given a bracket sequence $s$ of length $n$, where $n$ is even (divisible by two). The string $s$ consists of $\frac{n}{2}$ opening brackets '(' and $\frac{n}{2}$ closing brackets ')'.

    In one move, you can choose exactly one bracket and move it to the beginning of the string or to the end of the string (i.e. you choose some index $i$, remove the $i$-th character of $s$ and insert it before or after all remaining characters of $s$).

    Your task is to find the minimum number of moves required to obtain regular bracket sequence from $s$. It can be proved that the answer always exists under the given constraints.

    Recall what the regular bracket sequence is:

    "()" is regular bracket sequence;  if $s$ is regular bracket sequence then "(" + $s$ + ")" is regular bracket sequence;  if $s$ and $t$ are regular bracket sequences then $s$ + $t$ is regular bracket sequence.

    For example, "()()", "(())()", "(())" and "()" are regular bracket sequences, but ")(", "()(" and ")))" are not.

    You have to answer $t$ independent test cases.

    -----Input-----

    The first line of the input contains one integer $t$ ($1 \le t \le 2000$) — the number of test cases. Then $t$ test cases follow.

    The first line of the test case contains one integer $n$ ($2 \le n \le 50$) — the length of $s$. It is guaranteed that $n$ is even. The second line of the test case containg the string $s$ consisting of $\frac{n}{2}$ opening and $\frac{n}{2}$ closing brackets.

    -----Output-----

    For each test case, print the answer — the minimum number of moves required to obtain regular bracket sequence from $s$. It can be proved that the answer always exists under the given constraints.

    -----Example-----
    Input
    4
    2
    )(
    4
    ()()
    8
    ())()()(
    10
    )))((((())

    Output
    1
    0
    1
    3

    -----Note-----

    In the first test case of the example, it is sufficient to move the first bracket to the end of the string.

    In the third test case of the example, it is sufficient to move the last bracket to the beginning of the string.

    In the fourth test case of the example, we can choose last three openning brackets, move them to the beginning of the string and obtain "((()))(())".
    """


Prompt:
def checkIfExist(arr: list[int]) -> bool:
    """
    Given an array arr of integers, check if there exists two integers N and M such that N is the double of M ( i.e. N = 2 * M).
    More formally check if there exists two indices i and j such that :

    i != j
    0 <= i, j < arr.length
    arr[i] == 2 * arr[j]

    Example 1:
    Input: arr = [10,2,5,3]
    Output: true
    Explanation: N = 10 is the double of M = 5,that is, 10 = 2 * 5.

    Example 2:
    Input: arr = [7,1,14,11]
    Output: true
    Explanation: N = 14 is the double of M = 7,that is, 14 = 2 * 7.

    Example 3:
    Input: arr = [3,1,7,11]
    Output: false
    Explanation: In this case does not exist N and M, such that N = 2 * M.

    Constraints:

    2 <= arr.length <= 500
    -10^3 <= arr[i] <= 10^3
    """

def check(candidate):
    assert candidate([10, 2, 5, 3]) == True
    assert candidate([7, 1, 14, 11]) == True
    assert candidate([3, 1, 7, 11]) == False
check(checkIfExist)

assert checkIfExist([10, 2, 5, 3]) == True

assert checkIfExist([7, 1, 14, 11]) == True

assert checkIfExist([3, 1, 7, 11]) == False


Prompt:
def min_num_subsequences(t: int, test_cases: list[tuple[int, str]]) -> list[tuple[int, list[int]]]:
    """
    You are given a binary string $s$ consisting of $n$ zeros and ones.

    Your task is to divide the given string into the minimum number of subsequences in such a way that each character of the string belongs to exactly one subsequence and each subsequence looks like "010101 ..." or "101010 ..." (i.e. the subsequence should not contain two adjacent zeros or ones).

    Recall that a subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. For example, subsequences of "1011101" are "0", "1", "11111", "0111", "101", "1001", but not "000", "101010" and "11100".

    You have to answer $t$ independent test cases.

    -----Input-----

    The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow.

    The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of $s$. The second line of the test case contains $n$ characters '0' and '1' — the string $s$.

    It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).

    -----Output-----

    For each test case, print the answer: in the first line print one integer $k$ ($1 \le k \le n$) — the minimum number of subsequences you can divide the string $s$ to. In the second line print $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the number of subsequence the $i$-th character of $s$ belongs to.

    If there are several answers, you can print any.

    -----Example-----
    Input
    4
    4
    0011
    6
    111111
    5
    10101
    8
    01010000

    Output
    2
    1 2 2 1
    6
    1 2 3 4 5 6
    1
    1 1 1 1 1
    4
    1 1 1 1 1 2 3 4
    """


Prompt:
def make_upper_case(s: str) -> str:
    """
    Write a function which converts the input string to uppercase.

    ~~~if:bf
    For BF all inputs end with \0, all inputs are lowercases and there is no space between.
    ~~~
    """

def check(candidate):
    assert candidate('hello') == 'HELLO'
    assert candidate('hello world') == 'HELLO WORLD'
    assert candidate('hello world !') == 'HELLO WORLD !'
    assert candidate('heLlO wORLd !') == 'HELLO WORLD !'
    assert candidate('1,2,3 hello world!') == '1,2,3 HELLO WORLD!'
check(make_upper_case)

assert make_upper_case('hello world !') == 'HELLO WORLD !'


Prompt:
def encrypt(text: str) -> str:
    """
    For encrypting strings this region of chars is given (in this order!):

    * all letters (ascending, first all UpperCase, then all LowerCase)
    * all digits (ascending)
    * the following chars: `.,:;-?! '()$%&"`

    These are 77 chars! (This region is zero-based.)

    Write two methods:
    ```python
    def encrypt(text)
    def decrypt(encrypted_text)
    ```

    Prechecks:
    1. If the input-string has chars, that are not in the region, throw an Exception(C#, Python) or Error(JavaScript).
    2. If the input-string is null or empty return exactly this value!

    For building the encrypted string:
    1. For every second char do a switch of the case.
    2. For every char take the index from the region. Take the difference from the region-index of the char before (from the input text! Not from the fresh encrypted char before!). (Char2 = Char1-Char2)
    Replace the original char by the char of the difference-value from the region. In this step the first letter of the text is unchanged.
    3. Replace the first char by the mirror in the given region. (`'A' -> '"'`, `'B' -> '&'`, ...)

    Simple example:

    * Input:  `"Business"`
    * Step 1: `"BUsInEsS"`
    * Step 2: `"B61kujla"`
    * `B -> U`
    * `B (1) - U (20) = -19`
    * `-19 + 77 = 58`
    * `Region[58] = "6"`
    * `U -> s`
    * `U (20) - s (44) = -24`
    * `-24 + 77 = 53`
    * `Region[53] = "1"`
    * Step 3: `"&61kujla"`

    This kata is part of the Simple Encryption Series:
    Simple Encryption #1 - Alternating Split
    Simple Encryption #2 - Index-Difference
    Simple Encryption #3 - Turn The Bits Around
    Simple Encryption #4 - Qwerty

    Have fun coding it and please don't forget to vote and rank this kata! :-)
    """

def decrypt(encrypted_text: str) -> str:
    """
    The reverse process of the encryption described above.
    """

def check(candidate):
    assert candidate('$-Wy,dM79H\'i\'o$n0C&I.ZTcMJw5vPlZc Hn!krhlaa:khV mkL;gvtP-S7Rt1Vp2RV:wV9VuhO Iz3dqb.U0w') == 'Do the kata "Kobayashi-Maru-Test!" Endless fun and excitement when finding a solution!'
    assert candidate('5MyQa9p0riYplZc') == 'This is a test!'
    assert candidate('5MyQa79H\'ijQaw!Ns6jVtpmnlZ.V6p') == 'This kata is very interesting!'
    assert candidate('') == ''
    assert candidate(None) == None
check(encrypt)

assert encrypt('$-Wy,dM79H\'i\'o$n0C&I.ZTcMJw5vPlZc Hn!krhlaa:khV mkL;gvtP-S7Rt1Vp2RV:wV9VuhO Iz3dqb.U0w') == 'Do the kata "Kobayashi-Maru-Test!" Endless fun and excitement when finding a solution!'


Prompt:
def find_unique_k_diff_pairs(arr: list[int], k: int) -> int:
    """
    Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both numbers in the array and their absolute difference is k.

    Example 1:

    Input: [3, 1, 4, 1, 5], k = 2
    Output: 2
    Explanation: There are two 2-diff pairs in the array, (1, 3) and (3, 5).Although we have two 1s in the input, we should only return the number of unique pairs.

    Example 2:

    Input:[1, 2, 3, 4, 5], k = 1
    Output: 4
    Explanation: There are four 1-diff pairs in the array, (1, 2), (2, 3), (3, 4) and (4, 5).

    Example 3:

    Input: [1, 3, 1, 5, 4], k = 0
    Output: 1
    Explanation: There is one 0-diff pair in the array, (1, 1).

    Note:

    The pairs (i, j) and (j, i) count as the same pair.
    The length of the array won't exceed 10,000.
    All the integers in the given input belong to the range: [-1e7, 1e7].
    """

def check(candidate):
    assert candidate([3, 1, 4, 1, 5], 2) == 2
    assert candidate([1, 2, 3, 4, 5], 1) == 4
    assert candidate([1, 3, 1, 5, 4], 0) == 1
check(find_unique_k_diff_pairs)

assert find_unique_k_diff_pairs([3, 1, 4, 1, 5], 2) == 2

assert find_unique_k_diff_pairs([1, 2, 3, 4, 5], 1) == 4

assert find_unique_k_diff_pairs([1, 3, 1, 5, 4], 0) == 1


Prompt:
def check_parity_QC(n: int, cases: List[Tuple[int, int]]) -> List[int]:
    """
    The Quark Codejam's number QC(n, m) represents the number of ways to partition a set of n things into m nonempty subsets. For example, there are seven ways to split a four-element set into two parts:

    {1, 2, 3} ∪ {4}, {1, 2, 4} ∪ {3}, {1, 3, 4} ∪ {2}, {2, 3, 4} ∪ {1},

    {1, 2} ∪ {3, 4}, {1, 3} ∪ {2, 4}, {1, 4} ∪ {2, 3}.

    We can compute QC(n, m) using the recurrence,

    QC(n, m) = mQC(n − 1, m) + QC(n − 1, m − 1), for integers 1 < m < n.

    but your task is a somewhat different: given integers n and m, compute the parity of QC(n, m), i.e. QC(n, m) mod 2.

    Example :

    QC(4, 2) mod 2 = 1.
    Write a program that reads two positive integers n and m, computes QC(n, m) mod 2, and writes the

    result.

    -----Input-----
    The input begins with a single positive integer on a line by itself indicating the number of the cases. This line is followed by the input cases.

    The input consists two integers n and m separated by a space, with 1 ≤ m ≤ n ≤ 1000000000.

    -----Output-----
    For each test case, print the output.

    The output should be the integer S(n, m) mod 2.
    Sample Input
    1

    4 2
    Sample Output
    1
    """

def check(candidate):
    assert candidate(1, [(4, 2)]) == [1]
check(check_parity_QC)

assert check_parity_QC(1, [(4, 2)]) == [1]


Prompt:
def calculate_scales(T: int, test_cases: List[Tuple[str, int]]) -> List[int]:
    """
    Recently, Chef got obsessed with piano. He is a just a rookie in this stuff and can not move his fingers from one key to other fast enough. He discovered that the best way to train finger speed is to play scales.

    There are different kinds of scales which are divided on the basis of their interval patterns. For instance, major scale is defined by pattern T-T-S-T-T-T-S, where ‘T’ stands for a whole tone whereas ‘S’ stands for a semitone. Two semitones make one tone. To understand how they are being played, please refer to the below image of piano’s octave – two consecutive keys differ by one semitone.

    If we start playing from first key (note C), then we’ll play all white keys in a row (notes C-D-E-F-G-A-B-C – as you can see C and D differ for a tone as in pattern, and E and F differ for a semitone).

    This pattern could be played some number of times (in cycle).

    Each time Chef takes some type of a scale and plays using some number of octaves. Sometimes Chef can make up some scales, so please don’t blame him if you find some scale that does not exist in real world.

    Formally, you have a set of 12 keys (i.e. one octave) and you have N such sets in a row. So in total, you have 12*N keys. You also have a pattern that consists of letters 'T' and 'S', where 'T' means move forward for two keys (from key x to key x + 2, and 'S' means move forward for one key (from key x to key x + 1).

    Now, you can start playing from any of the 12*N keys. In one play, you can repeat the pattern as many times as you want, but you cannot go outside the keyboard.

    Repeating pattern means that if, for example, you have pattern STTST, you can play STTST as well as STTSTSTTST, as well as STTSTSTTSTSTTST, as well as any number of repeating. For this pattern, if you choose to repeat it once, if you start at some key x, you'll press keys: x (letter 'S')-> x + 1 (letter 'T')-> x + 3 (letter 'T')-> x + 5 (letter 'S') -> x + 6 (letter 'T')-> x + 8. Also 1 ≤ x, x + 8 ≤ 12*N so as to avoid going off the keyboard.

    You are asked to calculate number of different plays that can be performed. Two plays differ if and only if they start at different keys or patterns are repeated different number of times.

    -----Input-----
    The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.

    First line of each test case contains scale’s pattern – string s consisting of letters ‘T’ and ‘S’ only.

    Second line contains one integer N – number of octaves he’ll be using.

    -----Output-----
    For each test case output a single number in a line corresponding to number of different scales he’ll play.

    -----Constraints-----
    - 1 ≤ T ≤ 105
    - 1 ≤ |S| ≤ 100
    - 1 ≤ n ≤ 7

    -----Subtasks-----
    Subtask 1: T < 10 4, N = 1
    Subtask 2: No additional constraints.

    -----Example-----
    Input:
    2
    TTTT
    1
    TTSTTTS
    3

    Output:
    4
    36

    -----Explanation-----
    Example case 1. In the first case there is only one octave and Chef can play scale (not in cycle each time) starting with notes C, C#, D, D# - four together.
    """

def check(candidate):
    assert candidate(2, [('TTTT', 1), ('TTSTTTS', 3)]) == [4, 36]
check(calculate_scales)

assert calculate_scales(2, [('TTTT', 1), ('TTSTTTS', 3)]) == [4, 36]


Prompt:
def pawn_chess(T: int, test_cases: List[str]) -> List[str]:
    """
    Ada is playing pawn chess with Suzumo.
    Pawn chess is played on a long board with N$N$ squares in one row. Initially, some of the squares contain pawns.
    Note that the colours of the squares and pawns do not matter in this game, but otherwise, the standard chess rules apply:
    - no two pawns can occupy the same square at the same time
    - a pawn cannot jump over another pawn (they are no knights!), i.e. if there is a pawn at square i$i$, then it can only be moved to square i−2$i-2$ if squares i−1$i-1$ and i−2$i-2$ are empty
    - pawns cannot move outside of the board (outs are forbidden)
    The players alternate turns; as usual, Ada plays first. In each turn, the current player must choose a pawn and move it either one or two squares to the left of its current position. The player that cannot make a move loses.
    Can Ada always beat Suzumo? Remember that Ada is a chess grandmaster, so she always plays optimally.

    -----Input-----
    - The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows.
    - The first and only line of each test case contains a single string S$S$ with length N$N$ describing the initial board from left to right. An empty square and a square containing a pawn are denoted by the characters '.' and 'P' respectively.

    -----Output-----
    For each test case, print a single line containing the string "Yes" if Ada wins the game or "No" otherwise (without quotes).

    -----Constraints-----
    - 1≤T≤500$1 \le T \le 500$
    - 2≤N≤128$2 \le N \le 128$
    - S$S$ contains only characters '.' and 'P'

    -----Example Input-----
    1
    ..P.P

    -----Example Output-----
    Yes

    -----Explanation-----
    Example case 1: Ada can move the first pawn two squares to the left; the board after this move looks like
    P...P

    and now, Suzumo can only move the second pawn. If he moves it one square to the left, Ada will move it two squares to the left on her next move, and if he moves it two squares to the left, Ada will move it one square to the left, so the board after Ada's next move will look like
    PP...

    and Suzumo cannot make any move here.
    """

def check(candidate):
    assert candidate(1, ['..P.P']) == ['Yes']
check(pawn_chess)

assert pawn_chess(1, ['..P.P']) == ['Yes']


Prompt:
def minimize_m(T: int, test_cases: List[Tuple[int, List[int]]]) -> List[int]:
    """
    "I'm a fan of anything that tries to replace actual human contact." - Sheldon.
    After years of hard work, Sheldon was finally able to develop a formula which would diminish the real human contact.
    He found k$k$ integers n1,n2...nk$n_1,n_2...n_k$ . Also he found that if he could minimize the value of m$m$ such that  ∑ki=1$\sum_{i=1}^k$n$n$i$i$C$C$m$m$i$i$ is even, where m$m$ = ∑ki=1$\sum_{i=1}^k$mi$m_i$, he would finish the real human contact.
    Since Sheldon is busy choosing between PS-4 and XBOX-ONE, he want you to help him to calculate the minimum value of m$m$.

    -----Input:-----
    - The first line of the input contains a single integer T$T$ denoting the number of test cases. The
    description of T$T$ test cases follows.
    - The first line of each test case contains a single integer k$k$.
    - Next line contains k space separated integers n1,n2...nk$n_1,n_2...n_k$ .

    -----Output:-----
    For each test case output the minimum value of m for which ∑ki=1$\sum_{i=1}^k$n$n$i$i$C$C$m$m$i$i$ is even, where  m$m$=m1$m_1$+m2$m_2$+. . . mk$m_k$   and  0$0$ <= mi$m_i$<= ni$n_i$ .  If no such answer exists print -1.

    -----Constraints-----
    - 1≤T≤1000$1 \leq T \leq 1000$
    - 1≤k≤1000$1 \leq k \leq 1000$
    - 1≤ni≤10$1 \leq n_i \leq 10$18$18$

    -----Sample Input:-----
    1
    1
    5

    -----Sample Output:-----
    2

    -----EXPLANATION:-----
    5$5$C$C$2$2$ = 10 which is even and m is minimum.
    """

def check(candidate):
    assert candidate(1, [(1, [5])]) == [2]
check(minimize_m)


Prompt:
def min_additional_cost(N: int, costs: List[List[int]]) -> int:
    """
    The Government of Siruseri is no different from any other when it comes to being "capital-centric" in its policies. Recently the government decided to set up a nationwide fiber-optic network to take Siruseri into the digital age. And as usual, this decision was implemented in a capital centric manner --- from each city in the country, a fiber optic cable was laid to the capital! Thus, traffic between any two cities had to go through the capital.
    Soon, it became apparent that this was not quite a clever idea, since any breakdown at the capital resulted in the disconnection of services between other cities. So, in the second phase, the government plans to connect a few more pairs of cities directly by fiber-optic cables. The government has specified that this is to be done in such a way that the disruption of services at any one city will still leave the rest of the country connected.
    The government has data on the cost of laying fiber optic cables between every pair of cities. You task is to compute the minimum cost of additional cabling required to ensure the requirement described above is met.
    For example, if Siruseri has $4$ cities numbered $1,2,3$ and $4$ where $1$ is the capital and further suppose that the cost of laying cables between these cities are as given in the table below:

    Note that the government has already connected the capital with every other city. So, if we connect the cities $2$ and $3$ as well as $3$ and $4$, you can check that disruption of service at any one city will still leave the other cities connected. The cost of connecting these two pairs is $4 + 6 = 10$. The same effect could have been achieved by connecting $2$ and $3$ as well as $2$ and $4$, which would have cost $4 + 5 = 9$. You can check that this is the best you can do.
    Your task is to write a program that allows the government to determine the minimum cost it has to incur in laying additional cables to fulfil the requirement.

    -----Input:-----
    - The first line of the input contains a single integer $N$ indicating the number of cities in Siruseri. You may assume that the capital city is always numbered $1$.
    - This is followed by $N$ lines of input each containing $N$ integers.
    - The $j^{th}$ integer on line $i$ is the cost of connecting city $i$ with city $j$. The $j^{th}$ integer on line $i$ will be the same as the $i^{th}$ integer on line $j$ (since the links are bidirectional) and the $i^{th}$ entry on line $i$ will always be $0$ (there is no cost in connecting a city with itself).

    -----Output:-----
    A single integer indicating the minimum total cost of the links to be added to ensure that disruption of services at one city does not disconnect the rest of the cities.

    -----Constraints:-----
    - $1 \leq N \leq 2000$.
    - $0 \leq$ costs given in the input $\leq 100000$

    -----Sample Input-----
    4
    0 7 8 10
    7 0 4 5
    8 4 0 6
    10 5 6 0

    -----Sample Output-----
    9
    """


Prompt:
def count_bubbly_words(M: int, words: List[str]) -> int:
    """
    -----Problem-----

    Nikki's latest work is writing a story of letters. However, she finds writing story so boring that, after working for three hours, she realized that all she has written are M long words consisting entirely of letters A and B. Having accepted that she will never finish the story in time, Nikki has decided to at least have some fun with it by counting bubbly words.

    Now Nikki is connecting pairs of identical letters (A with A, B with B) by drawing lines above the word. A given word is bubbly if each letter can be connected to exactly one other letter in such a way that no two lines intersect. So here is your task. Help Nikki count how many words are bubbly.

    -----Input-----
    -
    The first line of input contains the positive integer M, the number of words written down by Nikki.

    -
    Each of the following M lines contains a single word consisting of letters A and B, with length

    between 2 and 10^5, inclusive. The sum of lengths of all words doesn't exceed 10^6.

    -----Output-----

    The first and only line of output must contain the number of bubbly words.

    -----Constraints-----
    -
    1 ≤ M ≤ 100

    -----Sample Input-----

    3

    ABAB

    AABB

    ABBA

    -----Sample Output-----
    2

    -----Explanation-----
    -
    ABAB - It is not bubbly as A(indexed 1) will connect to A(indexed 3) by a line and when we try to connect B(indexed 2) with B(indexed 4) by a line then it will intersect with the line b/w A and A.

    -
    AABB - It is bubbly as line b/w A and A will not intersect with the line b/w B and B.

    -
    ABBA -It is also bubbly as lines will not intersect. We can draw line b/w A and A above the line b/w B and B.
    p { text-align:justify }
    """

def check(candidate):
    assert candidate(3, ['ABAB', 'AABB', 'ABBA']) == 2
check(count_bubbly_words)

assert count_bubbly_words(3, ['ABAB', 'AABB', 'ABBA']) == 2