Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
hlis = list(map(int, input().split()))
dp = [float('inf')]*(N+1)
dp[1] = 0
for i in range(1, N):
    for j in range(1,min(K+1, N-i+1)):
        dp[i+j] = min(dp[i+j], dp[i] + abs(hlis[i-1]-hlis[i+j-1]))
print(dp[-1])

Fixed submission:
N, K = map(int, input().split())
hlis = list(map(int, input().split()))
dp = [float('inf')]*(N+1)
dp[1] = 0
for i in range(1, N):
    for j in range(1,min(K+1, N-i+1)):
        dp[i+j] = min(dp[i+j], dp[i] + abs(hlis[i-1]-hlis[i+j-1]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, k = map(int, input().split())
hlis = np.array(list(map(int, input().split())))
dp = np.zeros(n, dtype=int)
dp[0] = 0
for i in range(1,n):
    dp[i] = min(dp[j] + abs(hlis[i] - hlis[j]) for j in range(max(0, i-k), i))
print(dp[-1])

Fixed submission:
N, K = map(int, input().split())
hlis = list(map(int, input().split()))
dp = [float('inf')]*(N+1)
dp[1] = 0
for i in range(1, N):
    for j in range(1,min(K+1, N-i+1)):
        dp[i+j] = min(dp[i+j], dp[i] + abs(hlis[i-1]-hlis[i+j-1]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, k = map(int, input().split())
hlis = np.array(list(map(int, input().split())))
dp = np.zeros(n, dtype=int)
dp[0] = 0
dp[1] = abs(hlis[0] - hlis[1])
for i in range(2,n):
    dp[i] = min(dp[j] + abs(hlis[i] - hlis[j]) for j in range(max(0, i-k), i))
print(dp[n-1])

Fixed submission:
N, K = map(int, input().split())
hlis = list(map(int, input().split()))
dp = [float('inf')]*(N+1)
dp[1] = 0
for i in range(1, N):
    for j in range(1,min(K+1, N-i+1)):
        dp[i+j] = min(dp[i+j], dp[i] + abs(hlis[i-1]-hlis[i+j-1]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
hlis = list(map(int, input().split()))
dp = [0] + [float('inf')]*(n-1)
dp[1] = abs(hlis[0] - hlis[1])
for i in range(2,n):
    dp[i] = min(dp[j] + abs(hlis[i] - hlis[j]) for j in range(max(0, i-k), i))
print(dp[n-1])

Fixed submission:
N, K = map(int, input().split())
hlis = list(map(int, input().split()))
dp = [float('inf')]*(N+1)
dp[1] = 0
for i in range(1, N):
    for j in range(1,min(K+1, N-i+1)):
        dp[i+j] = min(dp[i+j], dp[i] + abs(hlis[i-1]-hlis[i+j-1]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
hlis = list(map(int, input().split()))
dp = [0] + [float('inf')]*(n-1)
for i in range(1, n):
    l = 1
    while i-l >= 0 and l <= k:
        dp[i] = min(dp[i], dp[i-l]+abs(hlis[i-l] - hlis[i]))
        l += 1
print(dp[n-1])

Fixed submission:
N, K = map(int, input().split())
hlis = list(map(int, input().split()))
dp = [float('inf')]*(N+1)
dp[1] = 0
for i in range(1, N):
    for j in range(1,min(K+1, N-i+1)):
        dp[i+j] = min(dp[i+j], dp[i] + abs(hlis[i-1]-hlis[i+j-1]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
wlis, vlis = [0], [0]
for i in range(N):
    w, v = map(int, input().split())
    wlis.append(w)
    vlis.append(v)
dp = [[0]*(W+1) for _ in range(N+2)]
for i in range(1, N+1):
    for j in range(W+1):
        if wlis[i] <= j:
            dp[i+1][j] = max(dp[i][j], dp[i][j-wlis[i]]+vlis[i])
        dp[i+1][j] = max(dp[i][j], dp[i+1][j])
print(dp[N+1][W])

Fixed submission:
N, W = map(int, input().split())
wlis, vlis = [0], [0]
for i in range(N):
    w, v = map(int, input().split())
    wlis.append(w)
    vlis.append(v)
dp = [[0]*(W+1) for _ in range(N+2)]
for i in range(1, N+1):
    for j in range(W+1):
        if wlis[i] <= j:
            dp[i+1][j] = max(dp[i][j], dp[i][j-wlis[i]]+vlis[i])
        dp[i+1][j] = max(dp[i][j], dp[i+1][j])
print(dp[N+1][W])
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
xlis = list(map(int, input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

d = gcd(abs(xlis[0]-x), abs(xlis[1]-x))
for i in range(2, n):
    d = gcd(d, abs(xlis[i]-x))
print(d)

Fixed submission:
n, x = map(int, input().split())
xlis = list(map(int, input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
if n > 1:
    d = gcd(abs(xlis[0]-x), abs(xlis[1]-x))
    for i in range(2, n):
        d = gcd(d, abs(xlis[i]-x))
    print(d)
else:
    print(abs(xlis[0] - x))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
def func(n):
  if n == 0:
    return 0
  else:
    return func(n-1) + n
print(func(b-a-1) - a)

Fixed submission:
a, b = map(int, input().split())
ans = 0
for i in range(1, b-a):
  ans += i
print(ans - a)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
alis = sorted(list(map(int, input().split())))
blis = sorted(list(map(int, input().split())))
clis = sorted(list(map(int, input().split())))
bc = [0]*n
for i in range(n):
    bc[i] = n - bisect.bisect_right(clis, blis[i])
ans = 0
for i in range(n):
    index = bisect.bisect_right(blis, alis[i])
    ans += sum(bc[index:])
print(ans)

Fixed submission:
from bisect import bisect_left, bisect_right, bisect
n = int(input())
alis = sorted(list(map(int, input().split())))
blis = list(map(int, input().split()))
clis = sorted(list(map(int, input().split())))
ans = 0
for b in blis:
    up = bisect_left(alis, b)
    down = n - bisect(clis, b)
    ans += up*down
print(ans)
Buggy python submission (verdict: Runtime Error):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n = ni()

    one = n % 10

    a = set(2, 4, 5, 7, 9)
    b = set(0, 1, 6, 8)
    if one in a:
        print('hon')
    elif one in b:
        print('pon')
    else:
        print('bon')


if __name__ == '__main__':
    main()

Fixed submission:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n = ni()

    one = n % 10

    a = set([2, 4, 5, 7, 9])
    b = set([0, 1, 6, 8])
    if one in a:
        print('hon')
    elif one in b:
        print('pon')
    else:
        print('bon')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    a, b, c, d = nm()
    while True:
        c -= d
        if c <= 0:
            print('Yes')
            exit()
        a -= d:
        if a <= 0:
            print('No')
            exit()


if __name__ == '__main__':
    main()

Fixed submission:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    a, b, c, d = nm()
    while True:
        c -= b
        if c <= 0:
            print('Yes')
            exit()
        a -= d
        if a <= 0:
            print('No')
            exit()


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

N = input().split()

for i in range(3):
    if N[i] == '7':
        print('Yes')
        exit()
print('No')

Fixed submission:
import sys

input = sys.stdin.readline

N = input().strip()

for i in range(3):
    if N[i] == '7':
        print('Yes')
        exit()
print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from fractions import gcd
input = sys.stdin.readline

K = int(input())
ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += gcd(gcd(i, j), k)

print(ans)

Fixed submission:
import sys
from math import gcd
input = sys.stdin.readline

K = int(input())
ans = 0

for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i == j and k == i:
                ans += gcd(gcd(i, j), k)
            elif i == j or k == i or j == k:
                ans += 3 * gcd(gcd(i, j), k)
            else:
                ans += 6 * gcd(gcd(i, j), k)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from fractions import gcd
input = sys.stdin.readline

K = int(input())
ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += gcd(gcd(i, j), k)

print(ans)

Fixed submission:
import sys
from math import gcd
input = sys.stdin.readline

K = int(input())
ans = 0

for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i == j and k == i:
                ans += gcd(gcd(i, j), k)
            elif i == j or k == i or j == k:
                ans += 3 * gcd(gcd(i, j), k)
            else:
                ans += 6 * gcd(gcd(i, j), k)

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

N, K = map(int, input().split())
diff = abs(K - N)

if N < K:
    print(N)
    exit()

if N % K == 0:
    print(0)
else:
    print(min(K - N%K), N%K)



Fixed submission:
import sys

input = sys.stdin.readline

N, K = map(int, input().split())

if N < K:
    print(min(N, K - N))
    exit()

if N % K == 0:
    print(0)
else:
    print(min(K - N%K, N%K))

Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline

N, K = map(int, input().split())
diff = abs(K - N)

if N % K == 0:
    print(0)
    exit()
while True:
    if diff < abs(diff - K):
        break
    else:
        diff = abs(K - diff)
print(diff)

Fixed submission:
import sys

input = sys.stdin.readline

N, K = map(int, input().split())

if N < K:
    print(min(N, K - N))
    exit()

if N % K == 0:
    print(0)
else:
    print(min(K - N%K, N%K))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

count = Counter(A)
check = {}
for num in A:
    ans = 0
    if num in check.keys():
        ans += check[num]
    else:
        for key, value in count.items():
            if key == num:
                ans += (value-1)*(value-2)//2
            else:
                ans += value*(value-1)//2
        check[num] = ans
    print(ans)


Fixed submission:
import sys
from collections import Counter
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

count = Counter(A)
sm = {}
sm2 = {}
for key, value in count.items():
    sm[key] = value*(value-1)//2
    sm2[key] = (value-1)*(value-2)//2
total = sum(sm.values())

for num in A:
    print(total - sm[num] + sm2[num])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

count = Counter(A)

for num in A:
    ans = 0
    for key, value in count.items():
        if key != num:
            ans += value*(value-1)//2
        else:
            ans += (value-1)*(value-2)//2
    print(ans)


Fixed submission:
import sys
from collections import Counter
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

count = Counter(A)
sm = {}
sm2 = {}
for key, value in count.items():
    sm[key] = value*(value-1)//2
    sm2[key] = (value-1)*(value-2)//2
total = sum(sm.values())

for num in A:
    print(total - sm[num] + sm2[num])
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
from math import factorial

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def nCr(n,r):
    return (factorial(n) // factorial(r) // factorial(n - r))


def main():
    k = ni()
    s = ns()
    n = len(s)
    mod = 1000000007
    ans = 0
    tmp1 = factorial(n+k)%mod
    tmp2 = 1
    tmp3 = tmp1
    for m in range(n):
        ans += ((nCr(n+k,m)%mod)*pow(25,n+k-m,mod))%mod
    ans = pow(26,n+k,mod) - ans
    ans %= mod
    print(ans)
    return


if __name__ == '__main__':
    main()


Fixed submission:
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    k = ni()
    s = ns()
    n = len(s)
    mod = 1000000007
    ans = 0
    inv25 = pow(25, mod-2, mod)
    tmp1 = 1
    tmp2 = pow(25,n+k,mod)
    for m in range(n):
        ans += (tmp1*tmp2)%mod
        ans %= mod
        tmp1 *= (n+k-m)*pow(m+1,mod-2,mod)
        tmp2 *= inv25
        tmp1 %= mod
        tmp2 %= mod
    ans = pow(26,n+k,mod) - ans
    ans %= mod
    print(ans)
    return


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def BinarySearch(num, List):
    if len(List) == 0:
        print("Erorr : list has no element")
        return
    left,right = 0,len(List)
    while left < right:
        mid  = (left+right)//2
        if num < List[mid]:#
            right = mid
        else:
            left = mid + 1
    return right


def main():
    nn = ni()
    atmp = sorted(na())
    a = []
    if atmp[0] != atmp[1]:
        a = [atmp[0]]
    pre = atmp[0]
    for i in range(1, nn):
        if pre != atmp[i]:
            a += [atmp[i]]
    n = len(a)
    if n == 0:
        print(0)
        return
    asub = [i for i in a]
    ans = 0
    for i in range(n):
        ai = a[i]
        if ai != -1:
            ans += 1
            cnt = 2
            right = i
            while right != n:
                right = BinarySearch(ai*cnt, asub)
                if a[right-1] == ai*cnt:
                    a[right-1] = -1
                cnt += 1
    print(ans)
    return


if __name__ == '__main__':
    main()

Fixed submission:
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def BinarySearch(num, List):
    if len(List) == 0:
        print("Erorr : list has no element")
        return
    left,right = 0,len(List)
    while left < right:
        mid  = (left+right)//2
        if num < List[mid]:#
            right = mid
        else:
            left = mid + 1
    return right


def main():
    n = ni()
    a = sorted(na())
    asub = [i for i in a]

    for i in range(n):
        ai = a[i]
        right = BinarySearch(ai, a)
        if right-1 != i:
            asub[right-1] = -1
            asub[i] = -1
            continue
        cnt = 2
        while right != n:
            right = BinarySearch(ai*cnt, a)
            if asub[right-1] == ai*cnt:
                asub[right-1] = -1
            cnt += 1
    
    ans = 0
    for i in range(n):
        if asub[i] != -1:
            ans += 1
    print(ans)
    return


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
import copy

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    n,k = na()
    a = na()
    anss = [0]*n
    while k != 0:
        flag = 0
        anss = [0]*n
        for i in range(n):
            ai = a[i]
            if ai >= n-1:
                flag += 1
            for j in range(max(0,i-ai), min(n,i+ai+1)):
                anss[j] += 1
        if flag == n:
            for i in range(n):
                anss[i] = n
            break
        a = copy.copy(anss)
        k -= 1
    print(' '.join(list(map(str,anss))))
    return


if __name__ == '__main__':
    main()

Fixed submission:
# coding: utf-8
import sys
import copy

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    n,k = na()
    a = na()
    memo = [0]*(n+1)
    for i in range(n):
        ai = a[i]
        memo[max(0, i-ai)] += 1
        memo[min(n, i+ai+1)] -= 1
    k -= 1
    if k == 0:
        tmp = 0
        for i in range(n):
            tmp += memo[i]
            print(tmp, end=' ')
        return
    while k != 0:
        flag = 0
        memo2 = [0]*(n+1)
        tmp = 0
        for i in range(n+1):
            tmp += memo[i]
            if tmp >= max(i, n-i-1):
                flag += 1
            memo2[max(0, i-tmp)] += 1
            memo2[min(n, i+tmp+1)] -= 1
        if flag == n:
            memo2[0] = n
            memo2[-1] = -1*n
            break
        memo = copy.copy(memo2)
        k -= 1
    tmp = 0
    for i in range(n):
        tmp += memo2[i]
        print(tmp, end=' ')
    return


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    n =ni()
    s = na()
    l = pow(10,18)
    ans = 1
    for i in s:
        ans *= i
    if ans > l:
        print(-1)
        return
    print(ans)
    return


if __name__ == '__main__':
    main()

Fixed submission:
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    n =ni()
    s = na()
    s.sort()
    l = pow(10,18)
    ans = 1
    for i in s:
        ans *= i
        if ans > l:
            print(-1)
            return
    print(ans)
    return


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
import random

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

def mkDivisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors



def main():
    x = ni()
    xmod10 = x%10
    div = mkDivisors(x)
    random.shuffle(div)
    for i in div:
        for n in [i,-1*i]:
            if n%10 == xmod10:
                for b in range(-n-125, n+125):
                    a = b + n
                    if pow(a,5) - pow(b,5) == x:
                        print(a,b)
                        return
    print("Erorr")
    return


if __name__ == '__main__':
    main()

Fixed submission:
# coding: utf-8
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces


def main():
    x = ni()
    xmod10 = x%10
    for a in range(-125, 125):
        for b in range(-125, 125):
            if (a-b)%10 == xmod10:
                if pow(a,5) - pow(b,5) == x:
                    print(a,b)
                    return
    print("Erorr")
    return


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

def mkDivisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors


def main():
    x = ni()
    div = mkDivisors(x)
    for i in div:
        for n in [i,-1*i]:
            for b in range(-n-125, n+125):
                a = b + n
                if pow(a,5) - pow(b,5) == x:
                    print(a,b)
                    return
    print("Erorr")
    return


if __name__ == '__main__':
    main()

Fixed submission:
# coding: utf-8
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces


def main():
    x = ni()
    xmod10 = x%10
    for a in range(-125, 125):
        for b in range(-125, 125):
            if (a-b)%10 == xmod10:
                if pow(a,5) - pow(b,5) == x:
                    print(a,b)
                    return
    print("Erorr")
    return


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

# アルファベット→数値
def alpha2num(alpha):
    num=0
    for index, item in enumerate(list(alpha)):
        num += pow(26,len(alpha)-index-1)*(ord(item)-ord('A')+1)
    return num

def BinarySearch(num, nums):
    if len(nums) == 0:
        print("Erorr : list has no element")
        return
    left,right = 0,len(nums)
    while left < right:
        mid  = (left+right)//2
        if num < nums[mid]:
            right = mid
        else:
            left = mid + 1
    return right

def main():
    n = ni()
    items = [alpha2num(ns())]
    for i in range(n-1):
        item = alpha2num(ns())
        right = BinarySearch(item,items)
        if items[right-1] != item:
            items = items[:right] + [item] + items[right:]
    print(len(items))
    return
    
if __name__ == '__main__':
  main()

Fixed submission:
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

def alpha2num(alpha):
    num=0
    for index, item in enumerate(list(alpha)):
        num += pow(26,len(alpha)-index-1)*(ord(item)-ord('A')+1)
    return num
    
def main():
    n = ni()
    s = set([alpha2num(ns()) for i in range(n)])
    print(len(s))
    return

if __name__ == '__main__':
  main()