import core.stdc.stdlib;
bool is_sorted(long[] lst)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `bool is_sorted(long[] lst)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def is_sorted(lst):

    count_digit = dict([(i, 0) for i in lst])
    for i in lst:
        count_digit[i]+=1
    if any(count_digit[i] > 2 for i in lst):
        return False
    if all(lst[i-1] <= lst[i] for i in range(1, len(lst))):
        return True
    else:
        return False

```

#<INSERT>
unittest
{
    alias candidate = is_sorted;

    assert(candidate([5L]) == true);
    assert(candidate([1L, 2L, 3L, 4L, 5L]) == true);
    assert(candidate([1L, 3L, 2L, 4L, 5L]) == false);
    assert(candidate([1L, 2L, 3L, 4L, 5L, 6L]) == true);
    assert(candidate([1L, 2L, 3L, 4L, 5L, 6L, 7L]) == true);
    assert(candidate([1L, 3L, 2L, 4L, 5L, 6L, 7L]) == false);
    assert(candidate([]) == true);
    assert(candidate([1L]) == true);
    assert(candidate([3L, 2L, 1L]) == false);
    assert(candidate([1L, 2L, 2L, 2L, 3L, 4L]) == false);
    assert(candidate([1L, 2L, 3L, 3L, 3L, 4L]) == false);
    assert(candidate([1L, 2L, 2L, 3L, 3L, 4L]) == true);
    assert(candidate([1L, 2L, 3L, 4L]) == true);
}
void main(){}


import core.stdc.stdlib;
long[] factorize(long n)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long[] factorize(long n)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python
from typing import List

def factorize(n: int) -> List[int]:

    import math
    fact = []
    i = 2
    while i <= int(math.sqrt(n) + 1):
        if n % i == 0:
            fact.append(i)
            n //= i
        else:
            i += 1

    if n > 1:
        fact.append(n)
    return fact

```

问题：写一段 python 代码实现以下功能。
找出小于第n个斐波那契数的最大完全平方数
函数命名为 max_square_number，输入为整数 n

答案：
```python
def max_square_number(n):
    if n <= 2:
        return 0  # 对于斐波那契数列的前两个数，没有完全平方数可用

    fibs = [0, 1]  # 存储斐波那契数列的前两个数
    squares = []  # 存储完全平方数的列表

    max_square = 0
    i = 2

    while i <= n:
        fibs.append(fibs[i-1] + fibs[i-2])  # 计算下一个斐波那契数
        i += 1

    fib = fibs[-1]
    perfect_squares = [i**2 for i in range(1, int(math.sqrt(fib)) + 1)]
    max_square = max(filter(lambda x: x < fib, perfect_squares))
    return max_square
```

----------------

#<INSERT>
unittest
{
    alias candidate = factorize;

    assert(candidate(2L) == [2L]);
    assert(candidate(4L) == [2L, 2L]);
    assert(candidate(8L) == [2L, 2L, 2L]);
    assert(candidate(57L) == [3L, 19L]);
    assert(candidate(3249L) == [3L, 3L, 19L, 19L]);
    assert(candidate(185193L) == [3L, 3L, 3L, 19L, 19L, 19L]);
    assert(candidate(20577L) == [3L, 19L, 19L, 19L]);
    assert(candidate(18L) == [2L, 3L, 3L]);
}
void main(){}


import core.stdc.stdlib;
long how_many_times(string string, string substring)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long how_many_times(string string, string substring)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def how_many_times(string: str, substring: str) -> int:

    times = 0

    for i in range(len(string) - len(substring) + 1):
        if string[i:i+len(substring)] == substring:
            times += 1

    return times

```

#<INSERT>
unittest
{
    alias candidate = how_many_times;

    assert(candidate("", "x") == 0L);
    assert(candidate("xyxyxyx", "x") == 4L);
    assert(candidate("cacacacac", "cac") == 4L);
    assert(candidate("john doe", "john") == 1L);
}
void main(){}


import core.stdc.stdlib;
string[] words_string(string s)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `string[] words_string(string s)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def words_string(s):

    if not s:
        return []

    s_list = []

    for letter in s:
        if letter == ',':
            s_list.append(' ')
        else:
            s_list.append(letter)

    s_list = "".join(s_list)
    return s_list.split()

```

#<INSERT>
unittest
{
    alias candidate = words_string;

    assert(candidate("Hi, my name is John") == ["Hi", "my", "name", "is", "John"]);
    assert(candidate("One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]);
    assert(candidate("Hi, my name") == ["Hi", "my", "name"]);
    assert(candidate("One,, two, three, four, five, six,") == ["One", "two", "three", "four", "five", "six"]);
    assert(candidate("") == []);
    assert(candidate("ahmed     , gamal") == ["ahmed", "gamal"]);
}
void main(){}


import core.stdc.stdlib;
string[] total_match(string[] lst1, string[] lst2)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `string[] total_match(string[] lst1, string[] lst2)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def total_match(lst1, lst2):

    l1 = 0
    for st in lst1:
        l1 += len(st)

    l2 = 0
    for st in lst2:
        l2 += len(st)

    if l1 <= l2:
        return lst1
    else:
        return lst2

```

#<INSERT>
unittest
{
    alias candidate = total_match;

    assert(candidate([], []) == []);
    assert(candidate(["hi", "admin"], ["hi", "hi"]) == ["hi", "hi"]);
    assert(candidate(["hi", "admin"], ["hi", "hi", "admin", "project"]) == ["hi", "admin"]);
    assert(candidate(["4"], ["1", "2", "3", "4", "5"]) == ["4"]);
    assert(candidate(["hi", "admin"], ["hI", "Hi"]) == ["hI", "Hi"]);
    assert(candidate(["hi", "admin"], ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]);
    assert(candidate(["hi", "admin"], ["hI", "hi", "hii"]) == ["hi", "admin"]);
    assert(candidate([], ["this"]) == []);
    assert(candidate(["this"], []) == []);
}
void main(){}


import core.stdc.stdlib;
long digits(long n)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long digits(long n)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def digits(n):

    product = 1
    odd_count = 0
    for digit in str(n):
        int_digit = int(digit)
        if int_digit%2 == 1:
            product= product*int_digit
            odd_count+=1
    if odd_count ==0:
        return 0
    else:
        return product

```

#<INSERT>
unittest
{
    alias candidate = digits;

    assert(candidate(5L) == 5L);
    assert(candidate(54L) == 5L);
    assert(candidate(120L) == 1L);
    assert(candidate(5014L) == 5L);
    assert(candidate(98765L) == 315L);
    assert(candidate(5576543L) == 2625L);
    assert(candidate(2468L) == 0L);
}
void main(){}


import core.stdc.stdlib;
float triangle_area(long a, long b, long c)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `float triangle_area(long a, long b, long c)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def triangle_area(a, b, c):

    if a + b <= c or a + c <= b or b + c <= a:
        return -1
    s = (a + b + c)/2
    area = (s * (s - a) * (s - b) * (s - c)) ** 0.5
    area = round(area, 2)
    return area

```

#<INSERT>
unittest
{
    alias candidate = triangle_area;

    assert(candidate(3L, 4L, 5L) == 6.0);
    assert(candidate(1L, 2L, 10L) == -1L);
    assert(candidate(4L, 8L, 5L) == 8.18);
    assert(candidate(2L, 2L, 2L) == 1.73);
    assert(candidate(1L, 2L, 3L) == -1L);
    assert(candidate(10L, 5L, 7L) == 16.25);
    assert(candidate(2L, 6L, 3L) == -1L);
    assert(candidate(1L, 1L, 1L) == 0.43);
    assert(candidate(2L, 2L, 10L) == -1L);
}
void main(){}


import core.stdc.stdlib;
long[] order_by_points(long[] nums)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long[] order_by_points(long[] nums)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def order_by_points(nums):

    def digits_sum(n):
        neg = 1
        if n < 0: n, neg = -1 * n, -1
        n = [int(i) for i in str(n)]
        n[0] = n[0] * neg
        return sum(n)
    return sorted(nums, key=digits_sum)

```


import core.stdc.stdlib;
string[] odd_count(string[] lst)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `string[] odd_count(string[] lst)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def odd_count(lst):

    res = []
    for arr in lst:
        n = sum(int(d)%2==1 for d in arr)
        res.append("the number of odd elements " + str(n) + "n the str"+ str(n) +"ng "+ str(n) +" of the "+ str(n) +"nput.")
    return res

```

#<INSERT>
unittest
{
    alias candidate = odd_count;

    assert(candidate(["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]);
    assert(candidate(["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]);
    assert(candidate(["271", "137", "314"]) == ["the number of odd elements 2n the str2ng 2 of the 2nput.", "the number of odd elements 3n the str3ng 3 of the 3nput.", "the number of odd elements 2n the str2ng 2 of the 2nput."]);
}
void main(){}


import core.stdc.stdlib;
long[] tri(long n)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long[] tri(long n)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def tri(n):

    if n == 0:
        return [1]
    my_tri = [1, 3]
    for i in range(2, n + 1):
        if i % 2 == 0:
            my_tri.append(i / 2 + 1)
        else:
            my_tri.append(my_tri[i - 1] + my_tri[i - 2] + (i + 3) / 2)
    return my_tri

```

#<INSERT>
unittest
{
    alias candidate = tri;

    assert(candidate(3L) == [1L, 3L, 2L, 8L]);
    assert(candidate(4L) == [1L, 3L, 2L, 8L, 3L]);
    assert(candidate(5L) == [1L, 3L, 2L, 8L, 3L, 15L]);
    assert(candidate(6L) == [1L, 3L, 2L, 8L, 3L, 15L, 4L]);
    assert(candidate(7L) == [1L, 3L, 2L, 8L, 3L, 15L, 4L, 24L]);
    assert(candidate(8L) == [1L, 3L, 2L, 8L, 3L, 15L, 4L, 24L, 5L]);
    assert(candidate(9L) == [1L, 3L, 2L, 8L, 3L, 15L, 4L, 24L, 5L, 35L]);
    assert(candidate(20L) == [1L, 3L, 2L, 8L, 3L, 15L, 4L, 24L, 5L, 35L, 6L, 48L, 7L, 63L, 8L, 80L, 9L, 99L, 10L, 120L, 11L]);
    assert(candidate(0L) == [1L]);
    assert(candidate(1L) == [1L, 3L]);
}
void main(){}


import core.stdc.stdlib;
string string_xor(string a, string b)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `string string_xor(string a, string b)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python
from typing import List

def string_xor(a: str, b: str) -> str:

    def xor(i, j):
        if i == j:
            return '0'
        else:
            return '1'

    return ''.join(xor(x, y) for x, y in zip(a, b))

```

#<INSERT>
unittest
{
    alias candidate = string_xor;

    assert(candidate("111000", "101010") == "010010");
    assert(candidate("1", "1") == "0");
    assert(candidate("0101", "0000") == "0101");
}
void main(){}


import core.stdc.stdlib;
long do_algebra(string[] operator, long[] operand)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long do_algebra(string[] operator, long[] operand)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def do_algebra(operator, operand):

    expression = str(operand[0])
    for oprt, oprn in zip(operator, operand[1:]):
        expression+= oprt + str(oprn)
    return eval(expression)

```

#<INSERT>
unittest
{
    alias candidate = do_algebra;

    assert(candidate(["**", "*", "+"], [2L, 3L, 4L, 5L]) == 37L);
    assert(candidate(["+", "*", "-"], [2L, 3L, 4L, 5L]) == 9L);
    assert(candidate(["//", "*"], [7L, 3L, 4L]) == 8L);
}
void main(){}


import core.stdc.stdlib;
string encode(string message)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `string encode(string message)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def encode(message):

    vowels = "aeiouAEIOU"
    vowels_replace = dict([(i, chr(ord(i) + 2)) for i in vowels])
    message = message.swapcase()
    return ''.join([vowels_replace[i] if i in vowels else i for i in message])

```

#<INSERT>
unittest
{
    alias candidate = encode;

    assert(candidate("TEST") == "tgst");
    assert(candidate("Mudasir") == "mWDCSKR");
    assert(candidate("YES") == "ygs");
    assert(candidate("This is a message") == "tHKS KS C MGSSCGG");
    assert(candidate("I DoNt KnOw WhAt tO WrItE") == "k dQnT kNqW wHcT Tq wRkTg");
}
void main(){}


import core.stdc.stdlib;
long fizz_buzz(long n)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long fizz_buzz(long n)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def fizz_buzz(n: int):

    ns = []
    for i in range(n):
        if i % 11 == 0 or i % 13 == 0:
            ns.append(i)
    s = ''.join(list(map(str, ns)))
    ans = 0
    for c in s:
        ans += (c == '7')
    return ans

```

#<INSERT>
unittest
{
    alias candidate = fizz_buzz;

    assert(candidate(50L) == 0L);
    assert(candidate(78L) == 2L);
    assert(candidate(79L) == 3L);
    assert(candidate(100L) == 3L);
    assert(candidate(200L) == 6L);
    assert(candidate(4000L) == 192L);
    assert(candidate(10000L) == 639L);
    assert(candidate(100000L) == 8026L);
}
void main(){}


import core.stdc.stdlib;
string[] filter_by_prefix(string[] strings, string prefix)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `string[] filter_by_prefix(string[] strings, string prefix)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python
from typing import List

def filter_by_prefix(strings: List[str], prefix: str) -> List[str]:

    return [x for x in strings if x.startswith(prefix)]

```

#<INSERT>
unittest
{
    alias candidate = filter_by_prefix;

    assert(candidate([], "john") == []);
    assert(candidate(["xxx", "asd", "xxy", "john doe", "xxxAAA", "xxx"], "xxx") == ["xxx", "xxxAAA", "xxx"]);
}
void main(){}


import core.stdc.stdlib;
long[] eat(long number, long need, long remaining)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long[] eat(long number, long need, long remaining)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def eat(number, need, remaining):

    if(need <= remaining):
        return [ number + need , remaining-need ]
    else:
        return [ number + remaining , 0]

```

#<INSERT>
unittest
{
    alias candidate = eat;

    assert(candidate(5L, 6L, 10L) == [11L, 4L]);
    assert(candidate(4L, 8L, 9L) == [12L, 1L]);
    assert(candidate(1L, 10L, 10L) == [11L, 0L]);
    assert(candidate(2L, 11L, 5L) == [7L, 0L]);
    assert(candidate(4L, 5L, 7L) == [9L, 2L]);
    assert(candidate(4L, 5L, 1L) == [5L, 0L]);
}
void main(){}


import core.stdc.stdlib;
string[] all_prefixes(string string)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `string[] all_prefixes(string string)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python
from typing import List

def all_prefixes(string: str) -> List[str]:

    result = []

    for i in range(len(string)):
        result.append(string[:i+1])
    return result

```

#<INSERT>
unittest
{
    alias candidate = all_prefixes;

    assert(candidate("") == []);
    assert(candidate("asdfgh") == ["a", "as", "asd", "asdf", "asdfg", "asdfgh"]);
    assert(candidate("WWW") == ["W", "WW", "WWW"]);
}
void main(){}


import core.stdc.stdlib;
bool pairs_sum_to_zero(long[] l)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `bool pairs_sum_to_zero(long[] l)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def pairs_sum_to_zero(l):

    for i, l1 in enumerate(l):
        for j in range(i + 1, len(l)):
            if l1 + l[j] == 0:
                return True
    return False

```

#<INSERT>
unittest
{
    alias candidate = pairs_sum_to_zero;

    assert(candidate([1L, 3L, 5L, 0L]) == false);
    assert(candidate([1L, 3L, -2L, 1L]) == false);
    assert(candidate([1L, 2L, 3L, 7L]) == false);
    assert(candidate([2L, 4L, -5L, 3L, 5L, 7L]) == true);
    assert(candidate([1L]) == false);
    assert(candidate([-3L, 9L, -1L, 3L, 2L, 30L]) == true);
    assert(candidate([-3L, 9L, -1L, 3L, 2L, 31L]) == true);
    assert(candidate([-3L, 9L, -1L, 4L, 2L, 30L]) == false);
    assert(candidate([-3L, 9L, -1L, 4L, 2L, 31L]) == false);
}
void main(){}


import core.stdc.stdlib;
long special_factorial(long n)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long special_factorial(long n)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def special_factorial(n):

    fact_i = 1
    special_fact = 1
    for i in range(1, n+1):
        fact_i *= i
        special_fact *= fact_i
    return special_fact

```

#<INSERT>
unittest
{
    alias candidate = special_factorial;

    assert(candidate(4L) == 288L);
    assert(candidate(5L) == 34560L);
    assert(candidate(7L) == 125411328000L);
    assert(candidate(1L) == 1L);
}
void main(){}


import core.stdc.stdlib;
long max_fill(long[][] grid, long capacity)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long max_fill(long[][] grid, long capacity)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def max_fill(grid, capacity):
    import math

    return sum([math.ceil(sum(arr)/capacity) for arr in grid])

```


import core.stdc.stdlib;
long count_upper(string s)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long count_upper(string s)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def count_upper(s):

    count = 0
    for i in range(0,len(s),2):
        if s[i] in "AEIOU":
            count += 1
    return count

```

#<INSERT>
unittest
{
    alias candidate = count_upper;

    assert(candidate("aBCdEf") == 1L);
    assert(candidate("abcdefg") == 0L);
    assert(candidate("dBBE") == 0L);
    assert(candidate("B") == 0L);
    assert(candidate("U") == 1L);
    assert(candidate("") == 0L);
    assert(candidate("EEEE") == 2L);
}
void main(){}


import core.stdc.stdlib;
long is_bored(string S)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long is_bored(string S)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def is_bored(S):

    import re
    sentences = re.split(r'[.?!]\s*', S)
    return sum(sentence[0:2] == 'I ' for sentence in sentences)

```

#<INSERT>
unittest
{
    alias candidate = is_bored;

    assert(candidate("Hello world") == 0L);
    assert(candidate("Is the sky blue?") == 0L);
    assert(candidate("I love It !") == 1L);
    assert(candidate("bIt") == 0L);
    assert(candidate("I feel good today. I will be productive. will kill It") == 2L);
    assert(candidate("You and I are going for a walk") == 0L);
}
void main(){}


import core.stdc.stdlib;
long[] sort_array(long[] array)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long[] sort_array(long[] array)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def sort_array(array):

    return [] if len(array) == 0 else sorted(array, reverse= (array[0]+array[-1]) % 2 == 0)

```

#<INSERT>
unittest
{
    alias candidate = sort_array;

    assert(candidate([]) == []);
    assert(candidate([5L]) == [5L]);
    assert(candidate([2L, 4L, 3L, 0L, 1L, 5L]) == [0L, 1L, 2L, 3L, 4L, 5L]);
    assert(candidate([2L, 4L, 3L, 0L, 1L, 5L, 6L]) == [6L, 5L, 4L, 3L, 2L, 1L, 0L]);
    assert(candidate([2L, 1L]) == [1L, 2L]);
    assert(candidate([15L, 42L, 87L, 32L, 11L, 0L]) == [0L, 11L, 15L, 32L, 42L, 87L]);
    assert(candidate([21L, 14L, 23L, 11L]) == [23L, 21L, 14L, 11L]);
}
void main(){}


import core.stdc.stdlib;
string remove_vowels(string text)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `string remove_vowels(string text)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def remove_vowels(text):

    return "".join([s for s in text if s.lower() not in ["a", "e", "i", "o", "u"]])

```

#<INSERT>
unittest
{
    alias candidate = remove_vowels;

    assert(candidate("") == "");
    assert(candidate("abcdef
ghijklm") == "bcdf
ghjklm");
    assert(candidate("fedcba") == "fdcb");
    assert(candidate("eeeee") == "");
    assert(candidate("acBAA") == "cB");
    assert(candidate("EcBOO") == "cB");
    assert(candidate("ybcd") == "ybcd");
}
void main(){}


import core.stdc.stdlib;
long largest_divisor(long n)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long largest_divisor(long n)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def largest_divisor(n: int) -> int:

    for i in reversed(range(n)):
        if n % i == 0:
            return i

```

#<INSERT>
unittest
{
    alias candidate = largest_divisor;

    assert(candidate(3L) == 1L);
    assert(candidate(7L) == 1L);
    assert(candidate(10L) == 5L);
    assert(candidate(100L) == 50L);
    assert(candidate(49L) == 7L);
}
void main(){}


import core.stdc.stdlib;
long add_elements(long[] arr, long k)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long add_elements(long[] arr, long k)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def add_elements(arr, k):

    return sum(elem for elem in arr[:k] if len(str(elem)) <= 2)

```

#<INSERT>
unittest
{
    alias candidate = add_elements;

    assert(candidate([1L, -2L, -3L, 41L, 57L, 76L, 87L, 88L, 99L], 3L) == -4L);
    assert(candidate([111L, 121L, 3L, 4000L, 5L, 6L], 2L) == 0L);
    assert(candidate([11L, 21L, 3L, 90L, 5L, 6L, 7L, 8L, 9L], 4L) == 125L);
    assert(candidate([111L, 21L, 3L, 4000L, 5L, 6L, 7L, 8L, 9L], 4L) == 24L);
    assert(candidate([1L], 1L) == 1L);
}
void main(){}


import core.stdc.stdlib;
long[] derivative(long[] xs)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long[] derivative(long[] xs)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def derivative(xs: list):

    return [(i * x) for i, x in enumerate(xs)][1:]

```

#<INSERT>
unittest
{
    alias candidate = derivative;

    assert(candidate([3L, 1L, 2L, 4L, 5L]) == [1L, 4L, 12L, 20L]);
    assert(candidate([1L, 2L, 3L]) == [2L, 6L]);
    assert(candidate([3L, 2L, 1L]) == [2L, 2L]);
    assert(candidate([3L, 2L, 1L, 0L, 4L]) == [2L, 2L, 0L, 16L]);
    assert(candidate([1L]) == []);
}
void main(){}


import core.stdc.stdlib;
string flip_case(string string)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `string flip_case(string string)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def flip_case(string: str) -> str:

    return string.swapcase()

```

#<INSERT>
unittest
{
    alias candidate = flip_case;

    assert(candidate("") == "");
    assert(candidate("Hello!") == "hELLO!");
    assert(candidate("These violent delights have violent ends") == "tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS");
}
void main(){}


import core.stdc.stdlib;
bool is_equal_to_sum_even(long n)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `bool is_equal_to_sum_even(long n)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def is_equal_to_sum_even(n):

    return n%2 == 0 and n >= 8

```

#<INSERT>
unittest
{
    alias candidate = is_equal_to_sum_even;

    assert(candidate(4L) == false);
    assert(candidate(6L) == false);
    assert(candidate(8L) == true);
    assert(candidate(10L) == true);
    assert(candidate(11L) == false);
    assert(candidate(12L) == true);
    assert(candidate(13L) == false);
    assert(candidate(16L) == true);
}
void main(){}


import core.stdc.stdlib;
bool iscube(long a)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `bool iscube(long a)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def iscube(a):

    a = abs(a)
    return int(round(a ** (1. / 3))) ** 3 == a

```

#<INSERT>
unittest
{
    alias candidate = iscube;

    assert(candidate(1L) == true);
    assert(candidate(2L) == false);
    assert(candidate(-1L) == true);
    assert(candidate(64L) == true);
    assert(candidate(180L) == false);
    assert(candidate(1000L) == true);
    assert(candidate(0L) == true);
    assert(candidate(1729L) == false);
}
void main(){}


import core.stdc.stdlib;
string solve(long N)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `string solve(long N)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def solve(N):

    return bin(sum(int(i) for i in str(N)))[2:]

```

#<INSERT>
unittest
{
    alias candidate = solve;

    assert(candidate(1000L) == "1");
    assert(candidate(150L) == "110");
    assert(candidate(147L) == "1100");
    assert(candidate(333L) == "1001");
    assert(candidate(963L) == "10010");
}
void main(){}


import core.stdc.stdlib;
long[] unique(long[] l)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long[] unique(long[] l)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def unique(l: list):

    return sorted(list(set(l)))

```

#<INSERT>
unittest
{
    alias candidate = unique;

    assert(candidate([5L, 3L, 5L, 2L, 3L, 3L, 9L, 0L, 123L]) == [0L, 2L, 3L, 5L, 9L, 123L]);
}
void main(){}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
std::tuple<float, float> find_closest_elements(std::vector<float> numbers) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `std::tuple<float, float> find_closest_elements(std::vector<float> numbers)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python
from typing import List, Tuple

def find_closest_elements(numbers: List[float]) -> Tuple[float, float]:

    closest_pair = None
    distance = None

    for idx, elem in enumerate(numbers):
        for idx2, elem2 in enumerate(numbers):
            if idx != idx2:
                if distance is None:
                    distance = abs(elem - elem2)
                    closest_pair = tuple(sorted([elem, elem2]))
                else:
                    new_distance = abs(elem - elem2)
                    if new_distance < distance:
                        distance = new_distance
                        closest_pair = tuple(sorted([elem, elem2]))

    return closest_pair

```

问题：请将以下代码改用 cpp 实现，要求以 markdown fenced block 格式输出
```python
from collections import defaultdict

def wordCount(text):
    countMap = defaultdict(int)
    words = text.split()

    for word in words:
        countMap[word] += 1

    return countMap
```

答案：
```cpp
#include <iostream>
#include <string>
#include <unordered_map>

std::unordered_map<std::string, int> wordCount(const std::string& text) {
    std::unordered_map<std::string, int> countMap;
    std::string word;
    std::size_t startPos = 0;
    std::size_t endPos = 0;

    while (endPos != std::string::npos) {
        endPos = text.find_first_of(" \t\n", startPos);
        word = text.substr(startPos, endPos - startPos);
        if (!word.empty()) {
            ++countMap[word];
        }
        startPos = text.find_first_not_of(" \t\n", endPos);
    }

    return countMap;
}
```

----------------

#include <cassert>
#<INSERT>

int main() {
    auto candidate = find_closest_elements;
    assert(candidate((std::vector<float>({(float)1.0f, (float)2.0f, (float)3.9f, (float)4.0f, (float)5.0f, (float)2.2f}))) == (std::make_tuple(3.9f, 4.0f)));
    assert(candidate((std::vector<float>({(float)1.0f, (float)2.0f, (float)5.9f, (float)4.0f, (float)5.0f}))) == (std::make_tuple(5.0f, 5.9f)));
    assert(candidate((std::vector<float>({(float)1.0f, (float)2.0f, (float)3.0f, (float)4.0f, (float)5.0f, (float)2.2f}))) == (std::make_tuple(2.0f, 2.2f)));
    assert(candidate((std::vector<float>({(float)1.0f, (float)2.0f, (float)3.0f, (float)4.0f, (float)5.0f, (float)2.0f}))) == (std::make_tuple(2.0f, 2.0f)));
    assert(candidate((std::vector<float>({(float)1.1f, (float)2.2f, (float)3.1f, (float)4.1f, (float)5.1f}))) == (std::make_tuple(2.2f, 3.1f)));
}


import std.typecons;
import core.stdc.stdlib;
bool check_dict_case(Nullable!(string[string]) dict)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `bool check_dict_case(Nullable!(string[string]) dict)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def check_dict_case(dict):

    if len(dict.keys()) == 0:
        return False
    else:
        state = "start"
        for key in dict.keys():

            if isinstance(key, str) == False:
                state = "mixed"
                break
            if state == "start":
                if key.isupper():
                    state = "upper"
                elif key.islower():
                    state = "lower"
                else:
                    break
            elif (state == "upper" and not key.isupper()) or (state == "lower" and not key.islower()):
                    state = "mixed"
                    break
            else:
                break
        return state == "upper" or state == "lower"

```

import std.typecons;
#<INSERT>
unittest
{
    alias candidate = check_dict_case;

    assert(candidate(["p": "pineapple", "b": "banana"].nullable) == true);
    assert(candidate(["p": "pineapple", "A": "banana", "B": "banana"].nullable) == false);
    assert(candidate(["p": "pineapple", "5": "banana", "a": "apple"].nullable) == false);
    assert(candidate(["Name": "John", "Age": "36", "City": "Houston"].nullable) == false);
    assert(candidate(["STATE": "NC", "ZIP": "12345"].nullable) == true);
    assert(candidate(["fruit": "Orange", "taste": "Sweet"].nullable) == true);
    assert(candidate(Nullable!(string[string]).init) == false);
}
void main(){}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
std::vector<std::string> bf(std::string planet1, std::string planet2) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `std::vector<std::string> bf(std::string planet1, std::string planet2)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def bf(planet1, planet2):

    planet_names = ("Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune")
    if planet1 not in planet_names or planet2 not in planet_names or planet1 == planet2:
        return ()
    planet1_index = planet_names.index(planet1)
    planet2_index = planet_names.index(planet2)
    if planet1_index < planet2_index:
        return (planet_names[planet1_index + 1: planet2_index])
    else:
        return (planet_names[planet2_index + 1 : planet1_index])

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = bf;
    assert(candidate(("Jupiter"), ("Neptune")) == (std::vector<std::string>({(std::string)"Saturn", (std::string)"Uranus"})));
    assert(candidate(("Earth"), ("Mercury")) == (std::vector<std::string>({(std::string)"Venus"})));
    assert(candidate(("Mercury"), ("Uranus")) == (std::vector<std::string>({(std::string)"Venus", (std::string)"Earth", (std::string)"Mars", (std::string)"Jupiter", (std::string)"Saturn"})));
    assert(candidate(("Neptune"), ("Venus")) == (std::vector<std::string>({(std::string)"Earth", (std::string)"Mars", (std::string)"Jupiter", (std::string)"Saturn", (std::string)"Uranus"})));
    assert(candidate(("Earth"), ("Earth")) == (std::vector<std::string>()));
    assert(candidate(("Mars"), ("Earth")) == (std::vector<std::string>()));
    assert(candidate(("Jupiter"), ("Makemake")) == (std::vector<std::string>()));
}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
bool is_nested(std::string string) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `bool is_nested(std::string string)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def is_nested(string):

    opening_bracket_index = []
    closing_bracket_index = []
    for i in range(len(string)):
        if string[i] == '[':
            opening_bracket_index.append(i)
        else:
            closing_bracket_index.append(i)
    closing_bracket_index.reverse()
    cnt = 0
    i = 0
    l = len(closing_bracket_index)
    for idx in opening_bracket_index:
        if i < l and idx < closing_bracket_index[i]:
            cnt += 1
            i += 1
    return cnt >= 2

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = is_nested;
    assert(candidate(("[[]]")) == (true));
    assert(candidate(("[]]]]]]][[[[[]")) == (false));
    assert(candidate(("[][]")) == (false));
    assert(candidate(("[]")) == (false));
    assert(candidate(("[[[[]]]]")) == (true));
    assert(candidate(("[]]]]]]]]]]")) == (false));
    assert(candidate(("[][][[]]")) == (true));
    assert(candidate(("[[]")) == (false));
    assert(candidate(("[]]")) == (false));
    assert(candidate(("[[]][[")) == (true));
    assert(candidate(("[[][]]")) == (true));
    assert(candidate(("")) == (false));
    assert(candidate(("[[[[[[[[")) == (false));
    assert(candidate(("]]]]]]]]")) == (false));
}


import core.stdc.stdlib;
string fix_spaces(string text)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `string fix_spaces(string text)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def fix_spaces(text):

    new_text = ""
    i = 0
    start, end = 0, 0
    while i < len(text):
        if text[i] == " ":
            end += 1
        else:
            if end - start > 2:
                new_text += "-"+text[i]
            elif end - start > 0:
                new_text += "_"*(end - start)+text[i]
            else:
                new_text += text[i]
            start, end = i+1, i+1
        i+=1
    if end - start > 2:
        new_text += "-"
    elif end - start > 0:
        new_text += "_"
    return new_text

```

#<INSERT>
unittest
{
    alias candidate = fix_spaces;

    assert(candidate("Example") == "Example");
    assert(candidate("Mudasir Hanif ") == "Mudasir_Hanif_");
    assert(candidate("Yellow Yellow  Dirty  Fellow") == "Yellow_Yellow__Dirty__Fellow");
    assert(candidate("Exa   mple") == "Exa-mple");
    assert(candidate("   Exa 1 2 2 mple") == "-Exa_1_2_2_mple");
}
void main(){}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
std::vector<std::string> by_length(std::vector<long> arr) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `std::vector<std::string> by_length(std::vector<long> arr)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def by_length(arr):

    dic = {
        1: "One",
        2: "Two",
        3: "Three",
        4: "Four",
        5: "Five",
        6: "Six",
        7: "Seven",
        8: "Eight",
        9: "Nine",
    }
    sorted_arr = sorted(arr, reverse=True)
    new_arr = []
    for var in sorted_arr:
        try:
            new_arr.append(dic[var])
        except:
            pass
    return new_arr

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = by_length;
    assert(candidate((std::vector<long>({(long)2, (long)1, (long)1, (long)4, (long)5, (long)8, (long)2, (long)3}))) == (std::vector<std::string>({(std::string)"Eight", (std::string)"Five", (std::string)"Four", (std::string)"Three", (std::string)"Two", (std::string)"Two", (std::string)"One", (std::string)"One"})));
    assert(candidate((std::vector<long>())) == (std::vector<std::string>()));
    assert(candidate((std::vector<long>({(long)1, (long)-1, (long)55}))) == (std::vector<std::string>({(std::string)"One"})));
    assert(candidate((std::vector<long>({(long)1, (long)-1, (long)3, (long)2}))) == (std::vector<std::string>({(std::string)"Three", (std::string)"Two", (std::string)"One"})));
    assert(candidate((std::vector<long>({(long)9, (long)4, (long)8}))) == (std::vector<std::string>({(std::string)"Nine", (std::string)"Eight", (std::string)"Four"})));
}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
long prime_fib(long n) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `long prime_fib(long n)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def prime_fib(n: int):

    import math

    def is_prime(p):
        if p < 2:
            return False
        for k in range(2, min(int(math.sqrt(p)) + 1, p - 1)):
            if p % k == 0:
                return False
        return True
    f = [0, 1]
    while True:
        f.append(f[-1] + f[-2])
        if is_prime(f[-1]):
            n -= 1
        if n == 0:
            return f[-1]

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = prime_fib;
    assert(candidate((1)) == (2));
    assert(candidate((2)) == (3));
    assert(candidate((3)) == (5));
    assert(candidate((4)) == (13));
    assert(candidate((5)) == (89));
    assert(candidate((6)) == (233));
    assert(candidate((7)) == (1597));
    assert(candidate((8)) == (28657));
    assert(candidate((9)) == (514229));
    assert(candidate((10)) == (433494437));
}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
std::string make_palindrome(std::string string) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `std::string make_palindrome(std::string string)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def is_palindrome(string: str) -> bool:

    return string == string[::-1]

def make_palindrome(string: str) -> str:

    if not string:
        return ''

    beginning_of_suffix = 0

    while not is_palindrome(string[beginning_of_suffix:]):
        beginning_of_suffix += 1

    return string + string[:beginning_of_suffix][::-1]

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = make_palindrome;
    assert(candidate(("")) == (""));
    assert(candidate(("x")) == ("x"));
    assert(candidate(("xyz")) == ("xyzyx"));
    assert(candidate(("xyx")) == ("xyx"));
    assert(candidate(("jerry")) == ("jerryrrej"));
}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
std::vector<long> factorize(long n) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `std::vector<long> factorize(long n)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python
from typing import List

def factorize(n: int) -> List[int]:

    import math
    fact = []
    i = 2
    while i <= int(math.sqrt(n) + 1):
        if n % i == 0:
            fact.append(i)
            n //= i
        else:
            i += 1

    if n > 1:
        fact.append(n)
    return fact

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = factorize;
    assert(candidate((2)) == (std::vector<long>({(long)2})));
    assert(candidate((4)) == (std::vector<long>({(long)2, (long)2})));
    assert(candidate((8)) == (std::vector<long>({(long)2, (long)2, (long)2})));
    assert(candidate((57)) == (std::vector<long>({(long)3, (long)19})));
    assert(candidate((3249)) == (std::vector<long>({(long)3, (long)3, (long)19, (long)19})));
    assert(candidate((185193)) == (std::vector<long>({(long)3, (long)3, (long)3, (long)19, (long)19, (long)19})));
    assert(candidate((20577)) == (std::vector<long>({(long)3, (long)19, (long)19, (long)19})));
    assert(candidate((18)) == (std::vector<long>({(long)2, (long)3, (long)3})));
}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
std::vector<std::string> words_string(std::string s) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `std::vector<std::string> words_string(std::string s)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def words_string(s):

    if not s:
        return []

    s_list = []

    for letter in s:
        if letter == ',':
            s_list.append(' ')
        else:
            s_list.append(letter)

    s_list = "".join(s_list)
    return s_list.split()

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = words_string;
    assert(candidate(("Hi, my name is John")) == (std::vector<std::string>({(std::string)"Hi", (std::string)"my", (std::string)"name", (std::string)"is", (std::string)"John"})));
    assert(candidate(("One, two, three, four, five, six")) == (std::vector<std::string>({(std::string)"One", (std::string)"two", (std::string)"three", (std::string)"four", (std::string)"five", (std::string)"six"})));
    assert(candidate(("Hi, my name")) == (std::vector<std::string>({(std::string)"Hi", (std::string)"my", (std::string)"name"})));
    assert(candidate(("One,, two, three, four, five, six,")) == (std::vector<std::string>({(std::string)"One", (std::string)"two", (std::string)"three", (std::string)"four", (std::string)"five", (std::string)"six"})));
    assert(candidate(("")) == (std::vector<std::string>()));
    assert(candidate(("ahmed     , gamal")) == (std::vector<std::string>({(std::string)"ahmed", (std::string)"gamal"})));
}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
std::string solve(std::string s) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `std::string solve(std::string s)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def solve(s):

    flg = 0
    idx = 0
    new_str = list(s)
    for i in s:
        if i.isalpha():
            new_str[idx] = i.swapcase()
            flg = 1
        idx += 1
    s = ""
    for i in new_str:
        s += i
    if flg == 0:
        return s[len(s)::-1]
    return s

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = solve;
    assert(candidate(("AsDf")) == ("aSdF"));
    assert(candidate(("1234")) == ("4321"));
    assert(candidate(("ab")) == ("AB"));
    assert(candidate(("#a@C")) == ("#A@c"));
    assert(candidate(("#AsdfW^45")) == ("#aSDFw^45"));
    assert(candidate(("#6@2")) == ("2@6#"));
    assert(candidate(("#$a^D")) == ("#$A^d"));
    assert(candidate(("#ccc")) == ("#CCC"));
}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
long how_many_times(std::string string, std::string substring) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `long how_many_times(std::string string, std::string substring)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def how_many_times(string: str, substring: str) -> int:

    times = 0

    for i in range(len(string) - len(substring) + 1):
        if string[i:i+len(substring)] == substring:
            times += 1

    return times

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = how_many_times;
    assert(candidate((""), ("x")) == (0));
    assert(candidate(("xyxyxyx"), ("x")) == (4));
    assert(candidate(("cacacacac"), ("cac")) == (4));
    assert(candidate(("john doe"), ("john")) == (1));
}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
std::vector<long> count_up_to(long n) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `std::vector<long> count_up_to(long n)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def count_up_to(n):

    primes = []
    for i in range(2, n):
        is_prime = True
        for j in range(2, i):
            if i % j == 0:
                is_prime = False
                break
        if is_prime:
            primes.append(i)
    return primes

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = count_up_to;
    assert(candidate((5)) == (std::vector<long>({(long)2, (long)3})));
    assert(candidate((6)) == (std::vector<long>({(long)2, (long)3, (long)5})));
    assert(candidate((7)) == (std::vector<long>({(long)2, (long)3, (long)5})));
    assert(candidate((10)) == (std::vector<long>({(long)2, (long)3, (long)5, (long)7})));
    assert(candidate((0)) == (std::vector<long>()));
    assert(candidate((22)) == (std::vector<long>({(long)2, (long)3, (long)5, (long)7, (long)11, (long)13, (long)17, (long)19})));
    assert(candidate((1)) == (std::vector<long>()));
    assert(candidate((18)) == (std::vector<long>({(long)2, (long)3, (long)5, (long)7, (long)11, (long)13, (long)17})));
    assert(candidate((47)) == (std::vector<long>({(long)2, (long)3, (long)5, (long)7, (long)11, (long)13, (long)17, (long)19, (long)23, (long)29, (long)31, (long)37, (long)41, (long)43})));
    assert(candidate((101)) == (std::vector<long>({(long)2, (long)3, (long)5, (long)7, (long)11, (long)13, (long)17, (long)19, (long)23, (long)29, (long)31, (long)37, (long)41, (long)43, (long)47, (long)53, (long)59, (long)61, (long)67, (long)71, (long)73, (long)79, (long)83, (long)89, (long)97})));
}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
long do_algebra(std::vector<std::string> op, std::vector<long> operand) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `long do_algebra(std::vector<std::string> op, std::vector<long> operand)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def do_algebra(operator, operand):

    expression = str(operand[0])
    for oprt, oprn in zip(operator, operand[1:]):
        expression+= oprt + str(oprn)
    return eval(expression)

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = do_algebra;
    assert(candidate((std::vector<std::string>({(std::string)"**", (std::string)"*", (std::string)"+"})), (std::vector<long>({(long)2, (long)3, (long)4, (long)5}))) == (37));
    assert(candidate((std::vector<std::string>({(std::string)"+", (std::string)"*", (std::string)"-"})), (std::vector<long>({(long)2, (long)3, (long)4, (long)5}))) == (9));
    assert(candidate((std::vector<std::string>({(std::string)"//", (std::string)"*"})), (std::vector<long>({(long)7, (long)3, (long)4}))) == (8));
}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
std::vector<long> strange_sort_list(std::vector<long> lst) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `std::vector<long> strange_sort_list(std::vector<long> lst)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def strange_sort_list(lst):

    res, switch = [], True
    while lst:
        res.append(min(lst) if switch else max(lst))
        lst.remove(res[-1])
        switch = not switch
    return res

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = strange_sort_list;
    assert(candidate((std::vector<long>({(long)1, (long)2, (long)3, (long)4}))) == (std::vector<long>({(long)1, (long)4, (long)2, (long)3})));
    assert(candidate((std::vector<long>({(long)5, (long)6, (long)7, (long)8, (long)9}))) == (std::vector<long>({(long)5, (long)9, (long)6, (long)8, (long)7})));
    assert(candidate((std::vector<long>({(long)1, (long)2, (long)3, (long)4, (long)5}))) == (std::vector<long>({(long)1, (long)5, (long)2, (long)4, (long)3})));
    assert(candidate((std::vector<long>({(long)5, (long)6, (long)7, (long)8, (long)9, (long)1}))) == (std::vector<long>({(long)1, (long)9, (long)5, (long)8, (long)6, (long)7})));
    assert(candidate((std::vector<long>({(long)5, (long)5, (long)5, (long)5}))) == (std::vector<long>({(long)5, (long)5, (long)5, (long)5})));
    assert(candidate((std::vector<long>())) == (std::vector<long>()));
    assert(candidate((std::vector<long>({(long)1, (long)2, (long)3, (long)4, (long)5, (long)6, (long)7, (long)8}))) == (std::vector<long>({(long)1, (long)8, (long)2, (long)7, (long)3, (long)6, (long)4, (long)5})));
    assert(candidate((std::vector<long>({(long)0, (long)2, (long)2, (long)2, (long)5, (long)5, (long)-5, (long)-5}))) == (std::vector<long>({(long)-5, (long)5, (long)-5, (long)5, (long)0, (long)2, (long)2, (long)2})));
    assert(candidate((std::vector<long>({(long)111111}))) == (std::vector<long>({(long)111111})));
}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
long fizz_buzz(long n) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `long fizz_buzz(long n)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def fizz_buzz(n: int):

    ns = []
    for i in range(n):
        if i % 11 == 0 or i % 13 == 0:
            ns.append(i)
    s = ''.join(list(map(str, ns)))
    ans = 0
    for c in s:
        ans += (c == '7')
    return ans

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = fizz_buzz;
    assert(candidate((50)) == (0));
    assert(candidate((78)) == (2));
    assert(candidate((79)) == (3));
    assert(candidate((100)) == (3));
    assert(candidate((200)) == (6));
    assert(candidate((4000)) == (192));
    assert(candidate((10000)) == (639));
    assert(candidate((100000)) == (8026));
}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
bool is_simple_power(long x, long n) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `bool is_simple_power(long x, long n)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def is_simple_power(x, n):

    if (n == 1):
        return (x == 1)
    power = 1
    while (power < x):
        power = power * n
    return (power == x)

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = is_simple_power;
    assert(candidate((16), (2)) == (true));
    assert(candidate((143214), (16)) == (false));
    assert(candidate((4), (2)) == (true));
    assert(candidate((9), (3)) == (true));
    assert(candidate((16), (4)) == (true));
    assert(candidate((24), (2)) == (false));
    assert(candidate((128), (4)) == (false));
    assert(candidate((12), (6)) == (false));
    assert(candidate((1), (1)) == (true));
    assert(candidate((1), (12)) == (true));
}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
std::vector<long> sort_array(std::vector<long> array) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `std::vector<long> sort_array(std::vector<long> array)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def sort_array(array):

    return [] if len(array) == 0 else sorted(array, reverse= (array[0]+array[-1]) % 2 == 0)

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = sort_array;
    assert(candidate((std::vector<long>())) == (std::vector<long>()));
    assert(candidate((std::vector<long>({(long)5}))) == (std::vector<long>({(long)5})));
    assert(candidate((std::vector<long>({(long)2, (long)4, (long)3, (long)0, (long)1, (long)5}))) == (std::vector<long>({(long)0, (long)1, (long)2, (long)3, (long)4, (long)5})));
    assert(candidate((std::vector<long>({(long)2, (long)4, (long)3, (long)0, (long)1, (long)5, (long)6}))) == (std::vector<long>({(long)6, (long)5, (long)4, (long)3, (long)2, (long)1, (long)0})));
    assert(candidate((std::vector<long>({(long)2, (long)1}))) == (std::vector<long>({(long)1, (long)2})));
    assert(candidate((std::vector<long>({(long)15, (long)42, (long)87, (long)32, (long)11, (long)0}))) == (std::vector<long>({(long)0, (long)11, (long)15, (long)32, (long)42, (long)87})));
    assert(candidate((std::vector<long>({(long)21, (long)14, (long)23, (long)11}))) == (std::vector<long>({(long)23, (long)21, (long)14, (long)11})));
}


import core.stdc.stdlib;
long[] parse_music(string music_string)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long[] parse_music(string music_string)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python
from typing import List

def parse_music(music_string: str) -> List[int]:

    note_map = {'o': 4, 'o|': 2, '.|': 1}
    return [note_map[x] for x in music_string.split(' ') if x]

```

#<INSERT>
unittest
{
    alias candidate = parse_music;

    assert(candidate("") == []);
    assert(candidate("o o o o") == [4L, 4L, 4L, 4L]);
    assert(candidate(".| .| .| .|") == [1L, 1L, 1L, 1L]);
    assert(candidate("o| o| .| .| o o o o") == [2L, 2L, 1L, 1L, 4L, 4L, 4L, 4L]);
    assert(candidate("o| .| o| .| o o| o o|") == [2L, 1L, 2L, 1L, 4L, 2L, 4L, 2L]);
}
void main(){}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
std::vector<long> derivative(std::vector<long> xs) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `std::vector<long> derivative(std::vector<long> xs)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def derivative(xs: list):

    return [(i * x) for i, x in enumerate(xs)][1:]

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = derivative;
    assert(candidate((std::vector<long>({(long)3, (long)1, (long)2, (long)4, (long)5}))) == (std::vector<long>({(long)1, (long)4, (long)12, (long)20})));
    assert(candidate((std::vector<long>({(long)1, (long)2, (long)3}))) == (std::vector<long>({(long)2, (long)6})));
    assert(candidate((std::vector<long>({(long)3, (long)2, (long)1}))) == (std::vector<long>({(long)2, (long)2})));
    assert(candidate((std::vector<long>({(long)3, (long)2, (long)1, (long)0, (long)4}))) == (std::vector<long>({(long)2, (long)2, (long)0, (long)16})));
    assert(candidate((std::vector<long>({(long)1}))) == (std::vector<long>()));
}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
long largest_divisor(long n) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `long largest_divisor(long n)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def largest_divisor(n: int) -> int:

    for i in reversed(range(n)):
        if n % i == 0:
            return i

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = largest_divisor;
    assert(candidate((3)) == (1));
    assert(candidate((7)) == (1));
    assert(candidate((10)) == (5));
    assert(candidate((100)) == (50));
    assert(candidate((49)) == (7));
}


import core.stdc.stdlib;
string encrypt(string s)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `string encrypt(string s)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def encrypt(s):

    d = 'abcdefghijklmnopqrstuvwxyz'
    out = ''
    for c in s:
        if c in d:
            out += d[(d.index(c)+2*2) % 26]
        else:
            out += c
    return out

```

#<INSERT>
unittest
{
    alias candidate = encrypt;

    assert(candidate("hi") == "lm");
    assert(candidate("asdfghjkl") == "ewhjklnop");
    assert(candidate("gf") == "kj");
    assert(candidate("et") == "ix");
    assert(candidate("faewfawefaewg") == "jeiajeaijeiak");
    assert(candidate("hellomyfriend") == "lippsqcjvmirh");
    assert(candidate("dxzdlmnilfuhmilufhlihufnmlimnufhlimnufhfucufh") == "hbdhpqrmpjylqmpyjlpmlyjrqpmqryjlpmqryjljygyjl");
    assert(candidate("a") == "e");
}
void main(){}


import core.stdc.stdlib;
long fibfib(long n)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long fibfib(long n)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def fibfib(n: int):

    if n == 0:
        return 0
    if n == 1:
        return 0
    if n == 2:
        return 1
    return fibfib(n - 1) + fibfib(n - 2) + fibfib(n - 3)

```

#<INSERT>
unittest
{
    alias candidate = fibfib;

    assert(candidate(2L) == 1L);
    assert(candidate(1L) == 0L);
    assert(candidate(5L) == 4L);
    assert(candidate(8L) == 24L);
    assert(candidate(10L) == 81L);
    assert(candidate(12L) == 274L);
    assert(candidate(14L) == 927L);
}
void main(){}


#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <any>
#include <variant>
std::string solve(long N) { exit(0); }

请将以下代码改用 cpp 实现，函数签名为 `std::string solve(long N)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def solve(N):

    return bin(sum(int(i) for i in str(N)))[2:]

```

#include <cassert>
#<INSERT>

int main() {
    auto candidate = solve;
    assert(candidate((1000)) == ("1"));
    assert(candidate((150)) == ("110"));
    assert(candidate((147)) == ("1100"));
    assert(candidate((333)) == ("1001"));
    assert(candidate((963)) == ("10010"));
}


import core.stdc.stdlib;
long double_the_difference(float[] lst)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long double_the_difference(float[] lst)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def double_the_difference(lst):

    return sum([i**2 for i in lst if i > 0 and i%2!=0 and "." not in str(i)])

```


import core.stdc.stdlib;
string decimal_to_binary(long decimal)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `string decimal_to_binary(long decimal)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def decimal_to_binary(decimal):

    return "db" + bin(decimal)[2:] + "db"

```

#<INSERT>
unittest
{
    alias candidate = decimal_to_binary;

    assert(candidate(0L) == "db0db");
    assert(candidate(32L) == "db100000db");
    assert(candidate(103L) == "db1100111db");
    assert(candidate(15L) == "db1111db");
}
void main(){}


import core.stdc.stdlib;
long add(long[] lst)
{
    exit(0);
}

请将以下代码改用 D 实现，函数签名为 `long add(long[] lst)`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def add(lst):

    return sum([lst[i] for i in range(1, len(lst), 2) if lst[i]%2 == 0])

```

#<INSERT>
unittest
{
    alias candidate = add;

    assert(candidate([4L, 88L]) == 88L);
    assert(candidate([4L, 5L, 6L, 7L, 2L, 122L]) == 122L);
    assert(candidate([4L, 0L, 6L, 7L]) == 0L);
    assert(candidate([4L, 4L, 6L, 8L]) == 12L);
}
void main(){}


def findClosestElements(numbers : List[Float]) : Tuple2[Float, Float] = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `findClosestElements(numbers : List[Float]) : Tuple2[Float, Float]`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python
from typing import List, Tuple

def find_closest_elements(numbers: List[float]) -> Tuple[float, float]:

    closest_pair = None
    distance = None

    for idx, elem in enumerate(numbers):
        for idx2, elem2 in enumerate(numbers):
            if idx != idx2:
                if distance is None:
                    distance = abs(elem - elem2)
                    closest_pair = tuple(sorted([elem, elem2]))
                else:
                    new_distance = abs(elem - elem2)
                    if new_distance < distance:
                        distance = new_distance
                        closest_pair = tuple(sorted([elem, elem2]))

    return closest_pair

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // From a supplied list of numbers (of length at least two) select and return two that are the closest to each
    // other and return them in order (smaller number, larger number).
    // >>> findClosestElements((List[Float](1.0f.toFloat, 2.0f.toFloat, 3.0f.toFloat, 4.0f.toFloat, 5.0f.toFloat, 2.2f.toFloat)))
    // ((2.0f, 2.2f))
    // >>> findClosestElements((List[Float](1.0f.toFloat, 2.0f.toFloat, 3.0f.toFloat, 4.0f.toFloat, 5.0f.toFloat, 2.0f.toFloat)))
    // ((2.0f, 2.0f))
#<INSERT>
    def main(args: Array[String]) = {
    assert(findClosestElements((List[Float](1.0f.toFloat, 2.0f.toFloat, 3.9f.toFloat, 4.0f.toFloat, 5.0f.toFloat, 2.2f.toFloat))).equals(((3.9f, 4.0f))));
    assert(findClosestElements((List[Float](1.0f.toFloat, 2.0f.toFloat, 5.9f.toFloat, 4.0f.toFloat, 5.0f.toFloat))).equals(((5.0f, 5.9f))));
    assert(findClosestElements((List[Float](1.0f.toFloat, 2.0f.toFloat, 3.0f.toFloat, 4.0f.toFloat, 5.0f.toFloat, 2.2f.toFloat))).equals(((2.0f, 2.2f))));
    assert(findClosestElements((List[Float](1.0f.toFloat, 2.0f.toFloat, 3.0f.toFloat, 4.0f.toFloat, 5.0f.toFloat, 2.0f.toFloat))).equals(((2.0f, 2.0f))));
    assert(findClosestElements((List[Float](1.1f.toFloat, 2.2f.toFloat, 3.1f.toFloat, 4.1f.toFloat, 5.1f.toFloat))).equals(((2.2f, 3.1f))));
    }

}


def evenOddPalindrome(n : Long) : Tuple2[Long, Long] = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `evenOddPalindrome(n : Long) : Tuple2[Long, Long]`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def even_odd_palindrome(n):

    def is_palindrome(n):
        return str(n) == str(n)[::-1]

    even_palindrome_count = 0
    odd_palindrome_count = 0

    for i in range(1, n+1):
        if i%2 == 1 and is_palindrome(i):
                odd_palindrome_count += 1
        elif i%2 == 0 and is_palindrome(i):
            even_palindrome_count += 1
    return (even_palindrome_count, odd_palindrome_count)

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Given a positive integer n, return a tuple that has the number of even and odd
    // integer palindromes that fall within the range(1, n), inclusive.
    // Example 1:
    // >>> evenOddPalindrome((3l))
    // ((1l, 2l))
    // Explanation:
    // Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
    // Example 2:
    // >>> evenOddPalindrome((12l))
    // ((4l, 6l))
    // Explanation:
    // Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
    // Note:
    // 1. 1 <= n <= 10^3
    // 2. returned tuple has the number of even and odd integer palindromes respectively.
#<INSERT>
    def main(args: Array[String]) = {
    assert(evenOddPalindrome((123l)).equals(((8l, 13l))));
    assert(evenOddPalindrome((12l)).equals(((4l, 6l))));
    assert(evenOddPalindrome((3l)).equals(((1l, 2l))));
    assert(evenOddPalindrome((63l)).equals(((6l, 8l))));
    assert(evenOddPalindrome((25l)).equals(((5l, 6l))));
    assert(evenOddPalindrome((19l)).equals(((4l, 6l))));
    assert(evenOddPalindrome((9l)).equals(((4l, 5l))));
    assert(evenOddPalindrome((1l)).equals(((0l, 1l))));
    }

}


def byLength(arr : List[Long]) : List[String] = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `byLength(arr : List[Long]) : List[String]`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def by_length(arr):

    dic = {
        1: "One",
        2: "Two",
        3: "Three",
        4: "Four",
        5: "Five",
        6: "Six",
        7: "Seven",
        8: "Eight",
        9: "Nine",
    }
    sorted_arr = sorted(arr, reverse=True)
    new_arr = []
    for var in sorted_arr:
        try:
            new_arr.append(dic[var])
        except:
            pass
    return new_arr

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Given a list of integers, sort the integers that are between 1 and 9 inclusive,
    // reverse the resulting list, and then replace each digit by its corresponding name from
    // "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
    // For example:
    // >>> byLength((List[Long](2l.toLong, 1l.toLong, 1l.toLong, 4l.toLong, 5l.toLong, 8l.toLong, 2l.toLong, 3l.toLong)))
    // (List[String]("Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"))
    // If the list is empty, return an empty list:
    // >>> byLength((List[Long]()))
    // (List[String]())
    // If the list has any strange number ignore it:
    // >>> byLength((List[Long](1l.toLong, -1l.toLong, 55l.toLong)))
    // (List[String]("One"))
#<INSERT>
    def main(args: Array[String]) = {
    assert(byLength((List[Long](2l.toLong, 1l.toLong, 1l.toLong, 4l.toLong, 5l.toLong, 8l.toLong, 2l.toLong, 3l.toLong))).equals((List[String]("Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"))));
    assert(byLength((List[Long]())).equals((List[String]())));
    assert(byLength((List[Long](1l.toLong, -1l.toLong, 55l.toLong))).equals((List[String]("One"))));
    assert(byLength((List[Long](1l.toLong, -1l.toLong, 3l.toLong, 2l.toLong))).equals((List[String]("Three", "Two", "One"))));
    assert(byLength((List[Long](9l.toLong, 4l.toLong, 8l.toLong))).equals((List[String]("Nine", "Eight", "Four"))));
    }

}


def isSorted(lst : List[Long]) : Boolean = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `isSorted(lst : List[Long]) : Boolean`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def is_sorted(lst):

    count_digit = dict([(i, 0) for i in lst])
    for i in lst:
        count_digit[i]+=1
    if any(count_digit[i] > 2 for i in lst):
        return False
    if all(lst[i-1] <= lst[i] for i in range(1, len(lst))):
        return True
    else:
        return False

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Given a list of numbers, return whether or not they are sorted
    // in ascending order. If list has more than 1 duplicate of the same
    // number, return false. Assume no negative numbers and only integers.
    // Examples
    // >>> isSorted((List[Long](5l.toLong)))
    // (true)
    // >>> isSorted((List[Long](1l.toLong, 2l.toLong, 3l.toLong, 4l.toLong, 5l.toLong)))
    // (true)
    // >>> isSorted((List[Long](1l.toLong, 3l.toLong, 2l.toLong, 4l.toLong, 5l.toLong)))
    // (false)
    // >>> isSorted((List[Long](1l.toLong, 2l.toLong, 3l.toLong, 4l.toLong, 5l.toLong, 6l.toLong)))
    // (true)
    // >>> isSorted((List[Long](1l.toLong, 2l.toLong, 3l.toLong, 4l.toLong, 5l.toLong, 6l.toLong, 7l.toLong)))
    // (true)
    // >>> isSorted((List[Long](1l.toLong, 3l.toLong, 2l.toLong, 4l.toLong, 5l.toLong, 6l.toLong, 7l.toLong)))
    // (false)
    // >>> isSorted((List[Long](1l.toLong, 2l.toLong, 2l.toLong, 3l.toLong, 3l.toLong, 4l.toLong)))
    // (true)
    // >>> isSorted((List[Long](1l.toLong, 2l.toLong, 2l.toLong, 2l.toLong, 3l.toLong, 4l.toLong)))
    // (false)
#<INSERT>
    def main(args: Array[String]) = {
    assert(isSorted((List[Long](5l.toLong))) == (true));
    assert(isSorted((List[Long](1l.toLong, 2l.toLong, 3l.toLong, 4l.toLong, 5l.toLong))) == (true));
    assert(isSorted((List[Long](1l.toLong, 3l.toLong, 2l.toLong, 4l.toLong, 5l.toLong))) == (false));
    assert(isSorted((List[Long](1l.toLong, 2l.toLong, 3l.toLong, 4l.toLong, 5l.toLong, 6l.toLong))) == (true));
    assert(isSorted((List[Long](1l.toLong, 2l.toLong, 3l.toLong, 4l.toLong, 5l.toLong, 6l.toLong, 7l.toLong))) == (true));
    assert(isSorted((List[Long](1l.toLong, 3l.toLong, 2l.toLong, 4l.toLong, 5l.toLong, 6l.toLong, 7l.toLong))) == (false));
    assert(isSorted((List[Long]())) == (true));
    assert(isSorted((List[Long](1l.toLong))) == (true));
    assert(isSorted((List[Long](3l.toLong, 2l.toLong, 1l.toLong))) == (false));
    assert(isSorted((List[Long](1l.toLong, 2l.toLong, 2l.toLong, 2l.toLong, 3l.toLong, 4l.toLong))) == (false));
    assert(isSorted((List[Long](1l.toLong, 2l.toLong, 3l.toLong, 3l.toLong, 3l.toLong, 4l.toLong))) == (false));
    assert(isSorted((List[Long](1l.toLong, 2l.toLong, 2l.toLong, 3l.toLong, 3l.toLong, 4l.toLong))) == (true));
    assert(isSorted((List[Long](1l.toLong, 2l.toLong, 3l.toLong, 4l.toLong))) == (true));
    }

}


def factorize(n : Long) : List[Long] = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `factorize(n : Long) : List[Long]`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python
from typing import List

def factorize(n: int) -> List[int]:

    import math
    fact = []
    i = 2
    while i <= int(math.sqrt(n) + 1):
        if n % i == 0:
            fact.append(i)
            n //= i
        else:
            i += 1

    if n > 1:
        fact.append(n)
    return fact

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Return list of prime factors of given integer in the order from smallest to largest.
    // Each of the factors should be listed number of times corresponding to how many times it appeares in factorization.
    // Input number should be equal to the product of all factors
    // >>> factorize((8l))
    // (List[Long](2l.toLong, 2l.toLong, 2l.toLong))
    // >>> factorize((25l))
    // (List[Long](5l.toLong, 5l.toLong))
    // >>> factorize((70l))
    // (List[Long](2l.toLong, 5l.toLong, 7l.toLong))
#<INSERT>
    def main(args: Array[String]) = {
    assert(factorize((2l)).equals((List[Long](2l.toLong))));
    assert(factorize((4l)).equals((List[Long](2l.toLong, 2l.toLong))));
    assert(factorize((8l)).equals((List[Long](2l.toLong, 2l.toLong, 2l.toLong))));
    assert(factorize((57l)).equals((List[Long](3l.toLong, 19l.toLong))));
    assert(factorize((3249l)).equals((List[Long](3l.toLong, 3l.toLong, 19l.toLong, 19l.toLong))));
    assert(factorize((185193l)).equals((List[Long](3l.toLong, 3l.toLong, 3l.toLong, 19l.toLong, 19l.toLong, 19l.toLong))));
    assert(factorize((20577l)).equals((List[Long](3l.toLong, 19l.toLong, 19l.toLong, 19l.toLong))));
    assert(factorize((18l)).equals((List[Long](2l.toLong, 3l.toLong, 3l.toLong))));
    }

}


def solve(s : String) : String = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `solve(s : String) : String`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def solve(s):

    flg = 0
    idx = 0
    new_str = list(s)
    for i in s:
        if i.isalpha():
            new_str[idx] = i.swapcase()
            flg = 1
        idx += 1
    s = ""
    for i in new_str:
        s += i
    if flg == 0:
        return s[len(s)::-1]
    return s

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // You are given a string s.
    // if s[i] is a letter, reverse its case from lower to upper or vise versa,
    // otherwise keep it as it is.
    // If the string contains no letters, reverse the string.
    // The function should return the resulted string.
    // Examples
    // >>> solve(("1234"))
    // ("4321")
    // >>> solve(("ab"))
    // ("AB")
    // >>> solve(("#a@C"))
    // ("#A@c")
#<INSERT>
    def main(args: Array[String]) = {
    assert(solve(("AsDf")).equals(("aSdF")));
    assert(solve(("1234")).equals(("4321")));
    assert(solve(("ab")).equals(("AB")));
    assert(solve(("#a@C")).equals(("#A@c")));
    assert(solve(("#AsdfW^45")).equals(("#aSDFw^45")));
    assert(solve(("#6@2")).equals(("2@6#")));
    assert(solve(("#$a^D")).equals(("#$A^d")));
    assert(solve(("#ccc")).equals(("#CCC")));
    }

}


def wordsString(s : String) : List[String] = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `wordsString(s : String) : List[String]`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def words_string(s):

    if not s:
        return []

    s_list = []

    for letter in s:
        if letter == ',':
            s_list.append(' ')
        else:
            s_list.append(letter)

    s_list = "".join(s_list)
    return s_list.split()

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // You will be given a string of words separated by commas or spaces. Your task is
    // to split the string into words and return a list of the words.
    // For example:
    // >>> wordsString(("Hi, my name is John"))
    // (List[String]("Hi", "my", "name", "is", "John"))
    // >>> wordsString(("One, two, three, four, five, six"))
    // (List[String]("One", "two", "three", "four", "five", "six"))
#<INSERT>
    def main(args: Array[String]) = {
    assert(wordsString(("Hi, my name is John")).equals((List[String]("Hi", "my", "name", "is", "John"))));
    assert(wordsString(("One, two, three, four, five, six")).equals((List[String]("One", "two", "three", "four", "five", "six"))));
    assert(wordsString(("Hi, my name")).equals((List[String]("Hi", "my", "name"))));
    assert(wordsString(("One,, two, three, four, five, six,")).equals((List[String]("One", "two", "three", "four", "five", "six"))));
    assert(wordsString(("")).equals((List[String]())));
    assert(wordsString(("ahmed     , gamal")).equals((List[String]("ahmed", "gamal"))));
    }

}


def oddCount(lst : List[String]) : List[String] = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `oddCount(lst : List[String]) : List[String]`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def odd_count(lst):

    res = []
    for arr in lst:
        n = sum(int(d)%2==1 for d in arr)
        res.append("the number of odd elements " + str(n) + "n the str"+ str(n) +"ng "+ str(n) +" of the "+ str(n) +"nput.")
    return res

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Given a list of strings, where each string consists of only digits, return a list.
    // Each element i of the output should be "the number of odd elements in the
    // string i of the input." where all the i's should be replaced by the number
    // of odd digits in the i'th string of the input.
    // >>> oddCount((List[String]("1234567")))
    // (List[String]("the number of odd elements 4n the str4ng 4 of the 4nput."))
    // >>> oddCount((List[String]("3", "11111111")))
    // (List[String]("the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."))
#<INSERT>
    def main(args: Array[String]) = {
    assert(oddCount((List[String]("1234567"))).equals((List[String]("the number of odd elements 4n the str4ng 4 of the 4nput."))));
    assert(oddCount((List[String]("3", "11111111"))).equals((List[String]("the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."))));
    assert(oddCount((List[String]("271", "137", "314"))).equals((List[String]("the number of odd elements 2n the str2ng 2 of the 2nput.", "the number of odd elements 3n the str3ng 3 of the 3nput.", "the number of odd elements 2n the str2ng 2 of the 2nput."))));
    }

}


def orderByPoints(nums : List[Long]) : List[Long] = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `orderByPoints(nums : List[Long]) : List[Long]`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def order_by_points(nums):

    def digits_sum(n):
        neg = 1
        if n < 0: n, neg = -1 * n, -1
        n = [int(i) for i in str(n)]
        n[0] = n[0] * neg
        return sum(n)
    return sorted(nums, key=digits_sum)

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Write a function which sorts the given list of integers
    // in ascending order according to the sum of their digits.
    // Note: if there are several items with similar sum of their digits,
    // order them based on their index in original list.
    // For example:
    // >>> orderByPoints((List[Long](1l.toLong, 11l.toLong, -1l.toLong, -11l.toLong, -12l.toLong)))
    // (List[Long](-1l.toLong, -11l.toLong, 1l.toLong, -12l.toLong, 11l.toLong))
    // >>> orderByPoints((List[Long]()))
    // (List[Long]())
#<INSERT>
    def main(args: Array[String]) = {
    assert(orderByPoints((List[Long](1l.toLong, 11l.toLong, -1l.toLong, -11l.toLong, -12l.toLong))).equals((List[Long](-1l.toLong, -11l.toLong, 1l.toLong, -12l.toLong, 11l.toLong))));
    assert(orderByPoints((List[Long](1234l.toLong, 423l.toLong, 463l.toLong, 145l.toLong, 2l.toLong, 423l.toLong, 423l.toLong, 53l.toLong, 6l.toLong, 37l.toLong, 3457l.toLong, 3l.toLong, 56l.toLong, 0l.toLong, 46l.toLong))).equals((List[Long](0l.toLong, 2l.toLong, 3l.toLong, 6l.toLong, 53l.toLong, 423l.toLong, 423l.toLong, 423l.toLong, 1234l.toLong, 145l.toLong, 37l.toLong, 46l.toLong, 56l.toLong, 463l.toLong, 3457l.toLong))));
    assert(orderByPoints((List[Long]())).equals((List[Long]())));
    assert(orderByPoints((List[Long](1l.toLong, -11l.toLong, -32l.toLong, 43l.toLong, 54l.toLong, -98l.toLong, 2l.toLong, -3l.toLong))).equals((List[Long](-3l.toLong, -32l.toLong, -98l.toLong, -11l.toLong, 1l.toLong, 2l.toLong, 43l.toLong, 54l.toLong))));
    assert(orderByPoints((List[Long](1l.toLong, 2l.toLong, 3l.toLong, 4l.toLong, 5l.toLong, 6l.toLong, 7l.toLong, 8l.toLong, 9l.toLong, 10l.toLong, 11l.toLong))).equals((List[Long](1l.toLong, 10l.toLong, 2l.toLong, 11l.toLong, 3l.toLong, 4l.toLong, 5l.toLong, 6l.toLong, 7l.toLong, 8l.toLong, 9l.toLong))));
    assert(orderByPoints((List[Long](0l.toLong, 6l.toLong, 6l.toLong, -76l.toLong, -21l.toLong, 23l.toLong, 4l.toLong))).equals((List[Long](-76l.toLong, -21l.toLong, 0l.toLong, 4l.toLong, 23l.toLong, 6l.toLong, 6l.toLong))));
    }

}


def f(n : Long) : List[Long] = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `f(n : Long) : List[Long]`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def f(n):

    ret = []
    for i in range(1,n+1):
        if i%2 == 0:
            x = 1
            for j in range(1,i+1): x *= j
            ret += [x]
        else:
            x = 0
            for j in range(1,i+1): x += j
            ret += [x]
    return ret

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Implement the function f that takes n as a parameter,
    // and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even
    // or the sum of numbers from 1 to i otherwise.
    // i starts from 1.
    // the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
    // Example:
    // >>> f((5l))
    // (List[Long](1l.toLong, 2l.toLong, 6l.toLong, 24l.toLong, 15l.toLong))
#<INSERT>
    def main(args: Array[String]) = {
    assert(f((5l)).equals((List[Long](1l.toLong, 2l.toLong, 6l.toLong, 24l.toLong, 15l.toLong))));
    assert(f((7l)).equals((List[Long](1l.toLong, 2l.toLong, 6l.toLong, 24l.toLong, 15l.toLong, 720l.toLong, 28l.toLong))));
    assert(f((1l)).equals((List[Long](1l.toLong))));
    assert(f((3l)).equals((List[Long](1l.toLong, 2l.toLong, 6l.toLong))));
    }

}


def triangleArea(a : Long, b : Long, c : Long) : Float = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `triangleArea(a : Long, b : Long, c : Long) : Float`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def triangle_area(a, b, c):

    if a + b <= c or a + c <= b or b + c <= a:
        return -1
    s = (a + b + c)/2
    area = (s * (s - a) * (s - b) * (s - c)) ** 0.5
    area = round(area, 2)
    return area

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Given the lengths of the three sides of a triangle. Return the area of
    // the triangle rounded to 2 decimal points if the three sides form a valid triangle.
    // Otherwise return -1
    // Three sides make a valid triangle when the sum of any two sides is greater
    // than the third side.
    // Example:
    // >>> triangleArea((3l), (4l), (5l))
    // (6.0f)
    // >>> triangleArea((1l), (2l), (10l))
    // -1l
#<INSERT>
    def main(args: Array[String]) = {
    assert(triangleArea((3l), (4l), (5l)) == (6.0f));
    assert(triangleArea((1l), (2l), (10l)) == -1l);
    assert(triangleArea((4l), (8l), (5l)) == (8.18f));
    assert(triangleArea((2l), (2l), (2l)) == (1.73f));
    assert(triangleArea((1l), (2l), (3l)) == -1l);
    assert(triangleArea((10l), (5l), (7l)) == (16.25f));
    assert(triangleArea((2l), (6l), (3l)) == -1l);
    assert(triangleArea((1l), (1l), (1l)) == (0.43f));
    assert(triangleArea((2l), (2l), (10l)) == -1l);
    }

}


def tri(n : Long) : List[Long] = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `tri(n : Long) : List[Long]`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def tri(n):

    if n == 0:
        return [1]
    my_tri = [1, 3]
    for i in range(2, n + 1):
        if i % 2 == 0:
            my_tri.append(i / 2 + 1)
        else:
            my_tri.append(my_tri[i - 1] + my_tri[i - 2] + (i + 3) / 2)
    return my_tri

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
    // the last couple centuries. However, what people don't know is Tribonacci sequence.
    // Tribonacci sequence is defined by the recurrence:
    // tri(1) = 3
    // tri(n) = 1 + n / 2, if n is even.
    // tri(n) =  tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
    // For example:
    // tri(2) = 1 + (2 / 2) = 2
    // tri(4) = 3
    // tri(3) = tri(2) + tri(1) + tri(4)
    // = 2 + 3 + 3 = 8
    // You are given a non-negative integer number n, you have to a return a list of the
    // first n + 1 numbers of the Tribonacci sequence.
    // Examples:
    // >>> tri((3l))
    // (List[Long](1l.toLong, 3l.toLong, 2l.toLong, 8l.toLong))
#<INSERT>
    def main(args: Array[String]) = {
    assert(tri((3l)).equals((List[Long](1l.toLong, 3l.toLong, 2l.toLong, 8l.toLong))));
    assert(tri((4l)).equals((List[Long](1l.toLong, 3l.toLong, 2l.toLong, 8l.toLong, 3l.toLong))));
    assert(tri((5l)).equals((List[Long](1l.toLong, 3l.toLong, 2l.toLong, 8l.toLong, 3l.toLong, 15l.toLong))));
    assert(tri((6l)).equals((List[Long](1l.toLong, 3l.toLong, 2l.toLong, 8l.toLong, 3l.toLong, 15l.toLong, 4l.toLong))));
    assert(tri((7l)).equals((List[Long](1l.toLong, 3l.toLong, 2l.toLong, 8l.toLong, 3l.toLong, 15l.toLong, 4l.toLong, 24l.toLong))));
    assert(tri((8l)).equals((List[Long](1l.toLong, 3l.toLong, 2l.toLong, 8l.toLong, 3l.toLong, 15l.toLong, 4l.toLong, 24l.toLong, 5l.toLong))));
    assert(tri((9l)).equals((List[Long](1l.toLong, 3l.toLong, 2l.toLong, 8l.toLong, 3l.toLong, 15l.toLong, 4l.toLong, 24l.toLong, 5l.toLong, 35l.toLong))));
    assert(tri((20l)).equals((List[Long](1l.toLong, 3l.toLong, 2l.toLong, 8l.toLong, 3l.toLong, 15l.toLong, 4l.toLong, 24l.toLong, 5l.toLong, 35l.toLong, 6l.toLong, 48l.toLong, 7l.toLong, 63l.toLong, 8l.toLong, 80l.toLong, 9l.toLong, 99l.toLong, 10l.toLong, 120l.toLong, 11l.toLong))));
    assert(tri((0l)).equals((List[Long](1l.toLong))));
    assert(tri((1l)).equals((List[Long](1l.toLong, 3l.toLong))));
    }

}


def doAlgebra(op : List[String], operand : List[Long]) : Long = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `doAlgebra(op : List[String], operand : List[Long]) : Long`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def do_algebra(operator, operand):

    expression = str(operand[0])
    for oprt, oprn in zip(operator, operand[1:]):
        expression+= oprt + str(oprn)
    return eval(expression)

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Given two lists operator, and operand. The first list has basic algebra operations, and
    // the second list is a list of integers. Use the two given lists to build the algebric
    // expression and return the evaluation of this expression.
    // The basic algebra operations:
    // Addition ( + )
    // Subtraction ( - )
    // Multiplication ( * )
    // Floor division ( // )
    // Exponentiation ( ** )
    // Example:
    // operator['+', '*', '-']
    // list = [2, 3, 4, 5]
    // result = 2 + 3 * 4 - 5
    // => result = 9
    // Note:
    // The length of operator list is equal to the length of operand list minus one.
    // Operand is a list of of non-negative integers.
    // Operator list has at least one operator, and operand list has at least two operands.
#<INSERT>
    def main(args: Array[String]) = {
    assert(doAlgebra((List[String]("**", "*", "+")), (List[Long](2l.toLong, 3l.toLong, 4l.toLong, 5l.toLong))) == (37l));
    assert(doAlgebra((List[String]("+", "*", "-")), (List[Long](2l.toLong, 3l.toLong, 4l.toLong, 5l.toLong))) == (9l));
    assert(doAlgebra((List[String]("//", "*")), (List[Long](7l.toLong, 3l.toLong, 4l.toLong))) == (8l));
    }

}


def encode(message : String) : String = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `encode(message : String) : String`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def encode(message):

    vowels = "aeiouAEIOU"
    vowels_replace = dict([(i, chr(ord(i) + 2)) for i in vowels])
    message = message.swapcase()
    return ''.join([vowels_replace[i] if i in vowels else i for i in message])

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Write a function that takes a message, and encodes in such a
    // way that it swaps case of all letters, replaces all vowels in
    // the message with the letter that appears 2 places ahead of that
    // vowel in the english alphabet.
    // Assume only letters.
    // Examples:
    // >>> encode(("test"))
    // ("TGST")
    // >>> encode(("This is a message"))
    // ("tHKS KS C MGSSCGG")
#<INSERT>
    def main(args: Array[String]) = {
    assert(encode(("TEST")).equals(("tgst")));
    assert(encode(("Mudasir")).equals(("mWDCSKR")));
    assert(encode(("YES")).equals(("ygs")));
    assert(encode(("This is a message")).equals(("tHKS KS C MGSSCGG")));
    assert(encode(("I DoNt KnOw WhAt tO WrItE")).equals(("k dQnT kNqW wHcT Tq wRkTg")));
    }

}


def strangeSortList(lst : List[Long]) : List[Long] = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `strangeSortList(lst : List[Long]) : List[Long]`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def strange_sort_list(lst):

    res, switch = [], True
    while lst:
        res.append(min(lst) if switch else max(lst))
        lst.remove(res[-1])
        switch = not switch
    return res

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Given list of integers, return list in strange order.
    // Strange sorting, is when you start with the minimum value,
    // then maximum of the remaining integers, then minimum and so on.
    // Examples:
    // >>> strangeSortList((List[Long](1l.toLong, 2l.toLong, 3l.toLong, 4l.toLong)))
    // (List[Long](1l.toLong, 4l.toLong, 2l.toLong, 3l.toLong))
    // >>> strangeSortList((List[Long](5l.toLong, 5l.toLong, 5l.toLong, 5l.toLong)))
    // (List[Long](5l.toLong, 5l.toLong, 5l.toLong, 5l.toLong))
    // >>> strangeSortList((List[Long]()))
    // (List[Long]())
#<INSERT>
    def main(args: Array[String]) = {
    assert(strangeSortList((List[Long](1l.toLong, 2l.toLong, 3l.toLong, 4l.toLong))).equals((List[Long](1l.toLong, 4l.toLong, 2l.toLong, 3l.toLong))));
    assert(strangeSortList((List[Long](5l.toLong, 6l.toLong, 7l.toLong, 8l.toLong, 9l.toLong))).equals((List[Long](5l.toLong, 9l.toLong, 6l.toLong, 8l.toLong, 7l.toLong))));
    assert(strangeSortList((List[Long](1l.toLong, 2l.toLong, 3l.toLong, 4l.toLong, 5l.toLong))).equals((List[Long](1l.toLong, 5l.toLong, 2l.toLong, 4l.toLong, 3l.toLong))));
    assert(strangeSortList((List[Long](5l.toLong, 6l.toLong, 7l.toLong, 8l.toLong, 9l.toLong, 1l.toLong))).equals((List[Long](1l.toLong, 9l.toLong, 5l.toLong, 8l.toLong, 6l.toLong, 7l.toLong))));
    assert(strangeSortList((List[Long](5l.toLong, 5l.toLong, 5l.toLong, 5l.toLong))).equals((List[Long](5l.toLong, 5l.toLong, 5l.toLong, 5l.toLong))));
    assert(strangeSortList((List[Long]())).equals((List[Long]())));
    assert(strangeSortList((List[Long](1l.toLong, 2l.toLong, 3l.toLong, 4l.toLong, 5l.toLong, 6l.toLong, 7l.toLong, 8l.toLong))).equals((List[Long](1l.toLong, 8l.toLong, 2l.toLong, 7l.toLong, 3l.toLong, 6l.toLong, 4l.toLong, 5l.toLong))));
    assert(strangeSortList((List[Long](0l.toLong, 2l.toLong, 2l.toLong, 2l.toLong, 5l.toLong, 5l.toLong, -5l.toLong, -5l.toLong))).equals((List[Long](-5l.toLong, 5l.toLong, -5l.toLong, 5l.toLong, 0l.toLong, 2l.toLong, 2l.toLong, 2l.toLong))));
    assert(strangeSortList((List[Long](111111l.toLong))).equals((List[Long](111111l.toLong))));
    }

}


def fizzBuzz(n : Long) : Long = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `fizzBuzz(n : Long) : Long`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def fizz_buzz(n: int):

    ns = []
    for i in range(n):
        if i % 11 == 0 or i % 13 == 0:
            ns.append(i)
    s = ''.join(list(map(str, ns)))
    ans = 0
    for c in s:
        ans += (c == '7')
    return ans

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
    // >>> fizzBuzz((50l))
    // (0l)
    // >>> fizzBuzz((78l))
    // (2l)
    // >>> fizzBuzz((79l))
    // (3l)
#<INSERT>
    def main(args: Array[String]) = {
    assert(fizzBuzz((50l)) == (0l));
    assert(fizzBuzz((78l)) == (2l));
    assert(fizzBuzz((79l)) == (3l));
    assert(fizzBuzz((100l)) == (3l));
    assert(fizzBuzz((200l)) == (6l));
    assert(fizzBuzz((4000l)) == (192l));
    assert(fizzBuzz((10000l)) == (639l));
    assert(fizzBuzz((100000l)) == (8026l));
    }

}


def roundedAvg(n : Long, m : Long) : Either[String, Long] = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `roundedAvg(n : Long, m : Long) : Either[String, Long]`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def rounded_avg(n, m):

    if m < n:
        return -1
    summation = 0
    for i in range(n, m+1):
        summation += i
    return bin(round(summation/(m - n + 1)))

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // You are given two positive integers n and m, and your task is to compute the
    // average of the integers from n through m (including n and m).
    // Round the answer to the nearest integer and convert that to binary.
    // If n is greater than m, return -1.
    // Example:
    // >>> roundedAvg((1l), (5l))
    // "0b11"
    // >>> roundedAvg((7l), (5l))
    // -1l
    // >>> roundedAvg((10l), (20l))
    // "0b1111"
    // >>> roundedAvg((20l), (33l))
    // "0b11010"
#<INSERT>
    def main(args: Array[String]) = {
    assert(roundedAvg((1l), (5l)).equals("0b11"));
    assert(roundedAvg((7l), (13l)).equals("0b1010"));
    assert(roundedAvg((964l), (977l)).equals("0b1111001010"));
    assert(roundedAvg((996l), (997l)).equals("0b1111100100"));
    assert(roundedAvg((560l), (851l)).equals("0b1011000010"));
    assert(roundedAvg((185l), (546l)).equals("0b101101110"));
    assert(roundedAvg((362l), (496l)).equals("0b110101101"));
    assert(roundedAvg((350l), (902l)).equals("0b1001110010"));
    assert(roundedAvg((197l), (233l)).equals("0b11010111"));
    assert(roundedAvg((7l), (5l)).equals(-1l));
    assert(roundedAvg((5l), (1l)).equals(-1l));
    assert(roundedAvg((5l), (5l)).equals("0b101"));
    }

}


def parseMusic(music_string : String) : List[Long] = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `parseMusic(music_string : String) : List[Long]`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python
from typing import List

def parse_music(music_string: str) -> List[int]:

    note_map = {'o': 4, 'o|': 2, '.|': 1}
    return [note_map[x] for x in music_string.split(' ') if x]

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Input to this function is a string representing musical notes in a special ASCII format.
    // Your task is to parse this string and return list of integers corresponding to how many beats does each
    // not last.
    // Here is a legend:
    // 'o' - whole note, lasts four beats
    // 'o|' - half note, lasts two beats
    // '.|' - quater note, lasts one beat
    // >>> parseMusic(("o o| .| o| o| .| .| .| .| o o"))
    // (List[Long](4l.toLong, 2l.toLong, 1l.toLong, 2l.toLong, 2l.toLong, 1l.toLong, 1l.toLong, 1l.toLong, 1l.toLong, 4l.toLong, 4l.toLong))
#<INSERT>
    def main(args: Array[String]) = {
    assert(parseMusic(("")).equals((List[Long]())));
    assert(parseMusic(("o o o o")).equals((List[Long](4l.toLong, 4l.toLong, 4l.toLong, 4l.toLong))));
    assert(parseMusic((".| .| .| .|")).equals((List[Long](1l.toLong, 1l.toLong, 1l.toLong, 1l.toLong))));
    assert(parseMusic(("o| o| .| .| o o o o")).equals((List[Long](2l.toLong, 2l.toLong, 1l.toLong, 1l.toLong, 4l.toLong, 4l.toLong, 4l.toLong, 4l.toLong))));
    assert(parseMusic(("o| .| o| .| o o| o o|")).equals((List[Long](2l.toLong, 1l.toLong, 2l.toLong, 1l.toLong, 4l.toLong, 2l.toLong, 4l.toLong, 2l.toLong))));
    }

}


def encrypt(s : String) : String = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `encrypt(s : String) : String`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def encrypt(s):

    d = 'abcdefghijklmnopqrstuvwxyz'
    out = ''
    for c in s:
        if c in d:
            out += d[(d.index(c)+2*2) % 26]
        else:
            out += c
    return out

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Create a function encrypt that takes a string as an argument and
    // returns a string encrypted with the alphabet being rotated.
    // The alphabet should be rotated in a manner such that the letters
    // shift down by two multiplied to two places.
    // For example:
    // >>> encrypt(("hi"))
    // ("lm")
    // >>> encrypt(("asdfghjkl"))
    // ("ewhjklnop")
    // >>> encrypt(("gf"))
    // ("kj")
    // >>> encrypt(("et"))
    // ("ix")
#<INSERT>
    def main(args: Array[String]) = {
    assert(encrypt(("hi")).equals(("lm")));
    assert(encrypt(("asdfghjkl")).equals(("ewhjklnop")));
    assert(encrypt(("gf")).equals(("kj")));
    assert(encrypt(("et")).equals(("ix")));
    assert(encrypt(("faewfawefaewg")).equals(("jeiajeaijeiak")));
    assert(encrypt(("hellomyfriend")).equals(("lippsqcjvmirh")));
    assert(encrypt(("dxzdlmnilfuhmilufhlihufnmlimnufhlimnufhfucufh")).equals(("hbdhpqrmpjylqmpyjlpmlyjrqpmqryjlpmqryjljygyjl")));
    assert(encrypt(("a")).equals(("e")));
    }

}


def filterIntegers(values : List[Any]) : List[Long] = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `filterIntegers(values : List[Any]) : List[Long]`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python
from typing import List, Any

def filter_integers(values: List[Any]) -> List[int]:

    return [x for x in values if isinstance(x, int)]

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Filter given list of any scalathon values only for integers
    // >>> filterIntegers((List[Any]("a", 3.14f, 5l)))
    // (List[Long](5l.toLong))
    // >>> filterIntegers((List[Any](1l, 2l, 3l, "abc", Map[Long,Long](), List[Long]())))
    // (List[Long](1l.toLong, 2l.toLong, 3l.toLong))
#<INSERT>
    def main(args: Array[String]) = {
    assert(filterIntegers((List[Any]())).equals((List[Long]())));
    assert(filterIntegers((List[Any](4l, Map[Long,Long](), List[Long](), 23.2f, 9l, "adasd"))).equals((List[Long](4l.toLong, 9l.toLong))));
    assert(filterIntegers((List[Any](3l, "c", 3l, 3l, "a", "b"))).equals((List[Long](3l.toLong, 3l.toLong, 3l.toLong))));
    }

}


def maxFill(grid : List[List[Long]], capacity : Long) : Long = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `maxFill(grid : List[List[Long]], capacity : Long) : Long`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def max_fill(grid, capacity):
    import math

    return sum([math.ceil(sum(arr)/capacity) for arr in grid])

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // You are given a rectangular grid of wells. Each row represents a single well,
    // and each 1 in a row represents a single unit of water.
    // Each well has a corresponding bucket that can be used to extract water from it,
    // and all buckets have the same capacity.
    // Your task is to use the buckets to empty the wells.
    // Output the number of times you need to lower the buckets.
    // Example 1:
    // >>> maxFill((List[List[Long]](List[Long](0l.toLong, 0l.toLong, 1l.toLong, 0l.toLong), List[Long](0l.toLong, 1l.toLong, 0l.toLong, 0l.toLong), List[Long](1l.toLong, 1l.toLong, 1l.toLong, 1l.toLong))), (1l))
    // (6l)
    // Example 2:
    // >>> maxFill((List[List[Long]](List[Long](0l.toLong, 0l.toLong, 1l.toLong, 1l.toLong), List[Long](0l.toLong, 0l.toLong, 0l.toLong, 0l.toLong), List[Long](1l.toLong, 1l.toLong, 1l.toLong, 1l.toLong), List[Long](0l.toLong, 1l.toLong, 1l.toLong, 1l.toLong))), (2l))
    // (5l)
    // Example 3:
    // >>> maxFill((List[List[Long]](List[Long](0l.toLong, 0l.toLong, 0l.toLong), List[Long](0l.toLong, 0l.toLong, 0l.toLong))), (5l))
    // (0l)
    // Constraints:
    // * all wells have the same length
    // * 1 <= grid.length <= 10^2
    // * 1 <= grid[:,1].length <= 10^2
    // * grid[i][j] -> 0 | 1
    // * 1 <= capacity <= 10
#<INSERT>
    def main(args: Array[String]) = {
    assert(maxFill((List[List[Long]](List[Long](0l.toLong, 0l.toLong, 1l.toLong, 0l.toLong), List[Long](0l.toLong, 1l.toLong, 0l.toLong, 0l.toLong), List[Long](1l.toLong, 1l.toLong, 1l.toLong, 1l.toLong))), (1l)) == (6l));
    assert(maxFill((List[List[Long]](List[Long](0l.toLong, 0l.toLong, 1l.toLong, 1l.toLong), List[Long](0l.toLong, 0l.toLong, 0l.toLong, 0l.toLong), List[Long](1l.toLong, 1l.toLong, 1l.toLong, 1l.toLong), List[Long](0l.toLong, 1l.toLong, 1l.toLong, 1l.toLong))), (2l)) == (5l));
    assert(maxFill((List[List[Long]](List[Long](0l.toLong, 0l.toLong, 0l.toLong), List[Long](0l.toLong, 0l.toLong, 0l.toLong))), (5l)) == (0l));
    assert(maxFill((List[List[Long]](List[Long](1l.toLong, 1l.toLong, 1l.toLong, 1l.toLong), List[Long](1l.toLong, 1l.toLong, 1l.toLong, 1l.toLong))), (2l)) == (4l));
    assert(maxFill((List[List[Long]](List[Long](1l.toLong, 1l.toLong, 1l.toLong, 1l.toLong), List[Long](1l.toLong, 1l.toLong, 1l.toLong, 1l.toLong))), (9l)) == (2l));
    }

}


def doubleTheDifference(lst : List[Float]) : Long = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `doubleTheDifference(lst : List[Float]) : Long`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def double_the_difference(lst):

    return sum([i**2 for i in lst if i > 0 and i%2!=0 and "." not in str(i)])

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Given a list of numbers, return the sum of squares of the numbers
    // in the list that are odd. Ignore numbers that are negative or not integers.
    // >>> doubleTheDifference((List[Float](1l.toLong, 3l.toLong, 2l.toLong, 0l.toLong)))
    // (10l)
    // >>> doubleTheDifference((List[Float](-1l.toLong, -2l.toLong, 0l.toLong)))
    // (0l)
    // >>> doubleTheDifference((List[Float](9l.toLong, -2l.toLong)))
    // (81l)
    // >>> doubleTheDifference((List[Float](0l.toLong)))
    // (0l)
    // If the input list is empty, return 0.
#<INSERT>
    def main(args: Array[String]) = {
    assert(doubleTheDifference((List[Float]())) == (0l));
    assert(doubleTheDifference((List[Float](5.0f.toFloat, 4.0f.toFloat))) == (25l));
    assert(doubleTheDifference((List[Float](0.1f.toFloat, 0.2f.toFloat, 0.3f.toFloat))) == (0l));
    assert(doubleTheDifference((List[Float](-10.0f.toFloat, -20.0f.toFloat, -30.0f.toFloat))) == (0l));
    assert(doubleTheDifference((List[Float](-1.0f.toFloat, -2.0f.toFloat, 8.0f.toFloat))) == (0l));
    assert(doubleTheDifference((List[Float](0.2f.toFloat, 3.0f.toFloat, 5.0f.toFloat))) == (34l));
    assert(doubleTheDifference((List[Float](-9.0f.toFloat, -7.0f.toFloat, -5.0f.toFloat, -3.0f.toFloat, -1.0f.toFloat, 1.0f.toFloat, 3.0f.toFloat, 5.0f.toFloat, 7.0f.toFloat, 9.0f.toFloat))) == (165l));
    }

}


def sortArray(array : List[Long]) : List[Long] = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `sortArray(array : List[Long]) : List[Long]`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def sort_array(array):

    return [] if len(array) == 0 else sorted(array, reverse= (array[0]+array[-1]) % 2 == 0)

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Given a list of non-negative integers, return a coscala of the given list after sorting,
    // you will sort the given list in ascending order if the sum( first index value, last index value) is odd,
    // or sort it in descending order if the sum( first index value, last index value) is even.
    // Note:
    // * don't change the given list.
    // Examples:
    // >>> sortArray((List[Long]()))
    // (List[Long]())
    // >>> sortArray((List[Long](5l.toLong)))
    // (List[Long](5l.toLong))
    // >>> sortArray((List[Long](2l.toLong, 4l.toLong, 3l.toLong, 0l.toLong, 1l.toLong, 5l.toLong)))
    // (List[Long](0l.toLong, 1l.toLong, 2l.toLong, 3l.toLong, 4l.toLong, 5l.toLong))
    // >>> sortArray((List[Long](2l.toLong, 4l.toLong, 3l.toLong, 0l.toLong, 1l.toLong, 5l.toLong, 6l.toLong)))
    // (List[Long](6l.toLong, 5l.toLong, 4l.toLong, 3l.toLong, 2l.toLong, 1l.toLong, 0l.toLong))
#<INSERT>
    def main(args: Array[String]) = {
    assert(sortArray((List[Long]())).equals((List[Long]())));
    assert(sortArray((List[Long](5l.toLong))).equals((List[Long](5l.toLong))));
    assert(sortArray((List[Long](2l.toLong, 4l.toLong, 3l.toLong, 0l.toLong, 1l.toLong, 5l.toLong))).equals((List[Long](0l.toLong, 1l.toLong, 2l.toLong, 3l.toLong, 4l.toLong, 5l.toLong))));
    assert(sortArray((List[Long](2l.toLong, 4l.toLong, 3l.toLong, 0l.toLong, 1l.toLong, 5l.toLong, 6l.toLong))).equals((List[Long](6l.toLong, 5l.toLong, 4l.toLong, 3l.toLong, 2l.toLong, 1l.toLong, 0l.toLong))));
    assert(sortArray((List[Long](2l.toLong, 1l.toLong))).equals((List[Long](1l.toLong, 2l.toLong))));
    assert(sortArray((List[Long](15l.toLong, 42l.toLong, 87l.toLong, 32l.toLong, 11l.toLong, 0l.toLong))).equals((List[Long](0l.toLong, 11l.toLong, 15l.toLong, 32l.toLong, 42l.toLong, 87l.toLong))));
    assert(sortArray((List[Long](21l.toLong, 14l.toLong, 23l.toLong, 11l.toLong))).equals((List[Long](23l.toLong, 21l.toLong, 14l.toLong, 11l.toLong))));
    }

}


def countUpper(s : String) : Long = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `countUpper(s : String) : Long`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def count_upper(s):

    count = 0
    for i in range(0,len(s),2):
        if s[i] in "AEIOU":
            count += 1
    return count

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // Given a string s, count the number of uppercase vowels in even indices.
    // For example:
    // >>> countUpper(("aBCdEf"))
    // (1l)
    // >>> countUpper(("abcdefg"))
    // (0l)
    // >>> countUpper(("dBBE"))
    // (0l)
#<INSERT>
    def main(args: Array[String]) = {
    assert(countUpper(("aBCdEf")) == (1l));
    assert(countUpper(("abcdefg")) == (0l));
    assert(countUpper(("dBBE")) == (0l));
    assert(countUpper(("B")) == (0l));
    assert(countUpper(("U")) == (1l));
    assert(countUpper(("")) == (0l));
    assert(countUpper(("EEEE")) == (2l));
    }

}


def derivative(xs : List[Long]) : List[Long] = {
    sys.exit(0)
}

请将以下代码改用 scala 实现，函数签名为 `derivative(xs : List[Long]) : List[Long]`
注意：
1、只需实现目标函数，与引入所需的包，不要生成其他代码

```python

def derivative(xs: list):

    return [(i * x) for i, x in enumerate(xs)][1:]

```

import scala.math._
import scala.collection.mutable._
object Problem {
    // xs represent coefficients of a polynomial.
    // xs[0] + xs[1] * x + xs[2] * x^2 + ....
    // Return derivative of this polynomial in the same form.
    // >>> derivative((List[Long](3l.toLong, 1l.toLong, 2l.toLong, 4l.toLong, 5l.toLong)))
    // (List[Long](1l.toLong, 4l.toLong, 12l.toLong, 20l.toLong))
    // >>> derivative((List[Long](1l.toLong, 2l.toLong, 3l.toLong)))
    // (List[Long](2l.toLong, 6l.toLong))
#<INSERT>
    def main(args: Array[String]) = {
    assert(derivative((List[Long](3l.toLong, 1l.toLong, 2l.toLong, 4l.toLong, 5l.toLong))).equals((List[Long](1l.toLong, 4l.toLong, 12l.toLong, 20l.toLong))));
    assert(derivative((List[Long](1l.toLong, 2l.toLong, 3l.toLong))).equals((List[Long](2l.toLong, 6l.toLong))));
    assert(derivative((List[Long](3l.toLong, 2l.toLong, 1l.toLong))).equals((List[Long](2l.toLong, 2l.toLong))));
    assert(derivative((List[Long](3l.toLong, 2l.toLong, 1l.toLong, 0l.toLong, 4l.toLong))).equals((List[Long](2l.toLong, 2l.toLong, 0l.toLong, 16l.toLong))));
    assert(derivative((List[Long](1l.toLong))).equals((List[Long]())));
    }

}