Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))


def f(n):
    cnt = 0
    for a in A:
            # a/nが偶数の場合
        if a % n == 0:
            cnt += a//(n-1)
        # a/nが奇数の場合
        else:
            cnt += a//n
    return True if K >= cnt else False


l = 0
r = max(A)
# 二分探索
while r - l > 1:
    m = (r+l)//2
    if f(m):
        r = m
    else:
        l = m
print(r)


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))


def f(n):
    cnt = 0
    for a in A:
            # a/nが偶数の場合
        if a % n == 0:
            cnt += a//n-1
        # a/nが奇数の場合
        else:
            cnt += a//n
    return True if K >= cnt else False


l = 0
r = max(A)
# 二分探索
while r - l > 1:
    m = (r+l)//2
    if f(m):
        r = m
    else:
        l = m
print(r)

Buggy python submission (verdict: Runtime Error):
def f(n):
    cnt = 0
    for a in A:
            # a/nが偶数の場合
        if a % n == 0:
            cnt += a//(n-1)
        # a/nが奇数の場合
        else:
            cnt += a//n
    return True if K >= cnt else False


N, K = map(int, input().split())
A = list(map(int, input().split()))
l = 0
r = max(A)
# 二分探索
while r - l > 1:
    cnt = 0
    m = (r+l)//2
    if f(m):
        r = m
    else:
        l = m
print(r)


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))


def f(n):
    cnt = 0
    for a in A:
            # a/nが偶数の場合
        if a % n == 0:
            cnt += a//n-1
        # a/nが奇数の場合
        else:
            cnt += a//n
    return True if K >= cnt else False


l = 0
r = max(A)
# 二分探索
while r - l > 1:
    m = (r+l)//2
    if f(m):
        r = m
    else:
        l = m
print(r)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = 0
r = max(A)
# 二分探索
while r - l > 1:
    cnt = 0
    flag = False
    m = (r+l)//2
    for a in A:
        # a/mが偶数の場合
        if a % m == 0:
            cnt += a//(m-1)
        # a/mが奇数の場合
        else:
            cnt += a//m
    flag = True if K >= cnt else False
    # Trueなら右側を狭める
    # Falseなら左側を狭める
    if flag == True:
        r = m
    else:
        l = m
print(r)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))


def f(n):
    cnt = 0
    for a in A:
            # a/nが偶数の場合
        if a % n == 0:
            cnt += a//n-1
        # a/nが奇数の場合
        else:
            cnt += a//n
    return True if K >= cnt else False


l = 0
r = max(A)
# 二分探索
while r - l > 1:
    m = (r+l)//2
    if f(m):
        r = m
    else:
        l = m
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split(' '))
A = list(map(int,input().split(' ')))
sum_score = A[0]
for i in range(1,K):
    sum_score *= A[i]
cnt = 0
for k in range(K-1,N):
    prev_sum_score = int(sum_score)
    if k + 1 > N - 1:
        break
    sum_score /= A[cnt]
    sum_score *= A[k+1]
    cnt += 1
    if prev_sum_score >= int(sum_score):
        print("No")
    else:
        print("Yes")

Fixed submission:
N,K = map(int,input().split(' '))
A = list(map(int,input().split(' ')))
cnt = 0
for k in range(K,N):
    if A[k] > A[cnt]:
        print("Yes")
    else:
        print("No")
    cnt += 1
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 1
for a in A:
    ans *= a

if ans > 10**18:
    print('-1')
    exit()

print(ans)


Fixed submission:
# ABC169
N = int(input())
A = list(map(int, input().split()))

ans = 1
if 0 in A:
    print(0)
    exit()
for a in A:
    ans *= a
    if ans > 10**18:
        print('-1')
        exit()

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
ans = 10**10
while True:
    temp = N % K
    if temp < ans:
        ans = temp
    elif temp == ans:
        break

ans = min(abs(ans-K), ans)
print(ans)


Fixed submission:
# C
N, K = map(int, input().split())
ans = 10**10
mod = N % K
ans = min(mod, abs(mod-K))
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(map(int, input().split()))
max_N = max(X)
ans = []

for p in range(1, max_N):
    tmp = sum([(x-p)**2 for x in X])
    ans.append(tmp)
print(min(ans))


Fixed submission:
N = int(input())
X = list(map(int, input().split()))
max_N = max(X)
ans = 10000000000

for p in range(1, max_N+1):
    tmp = sum([(x-p)**2 for x in X])
    if tmp <= ans:
        ans = tmp
    else:
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
p = list(map(int,input().split()))

max_i = -1
max_sum = -1
for i in range(N-K+1):
    csum = sum(p[i:i+K])
    if  csum > max_sum:
        max_sum = csum
        max_i = i

# print(max_sum)
# print(max_i)
ans = 0
for k in range(K):
    ans += (p[max_i+k]+1)/2

print(ans)

    

Fixed submission:
N,K = map(int,input().split())
p = list(map(int,input().split()))

#累積和を使う
e_s = [0] * (N+1)
for i in range(N):
    # 期待値の計算
    e = (p[i]+1)/2
    e_s[i+1] = e_s[i] + e

ans = 0
for j in range(N-K+1):
    ans = max(ans,e_s[j+K]-e_s[j])
print(ans)
Buggy python submission (verdict: Runtime Error):
X = int(input())
dp = [True] + [False] * (X)

# 100~105円はyes
for i in range(100,106):
  dp[i] = True

for i in range(106,X+1):
  for j in range(100,106):
    if dp[i-j] == True:
      dp[i] = True
      break

print(1 if dp[X] == True else 0)

Fixed submission:
X = int(input())
dp = [True] + [False] * (X)

if X < 106:
  if 100 <= X <= 105:
    print(1)
    exit()
  else:
    print(0)
    exit()


# 100~105円はyes
for i in range(100,106):
  dp[i] = True

for i in range(106,X+1):
  for j in range(100,106):
    if dp[i-j] == True:
      dp[i] = True
      break

print(1 if dp[X] == True else 0)
Buggy python submission (verdict: Runtime Error):
print(int(input()**2)

Fixed submission:
print(int(input())**2)
Buggy python submission (verdict: Time Limit Exceeded):
# C
N = int(input())
D = sorted(list(map(int, input().split())))
center = len(D)//2
cnt = 0
for k in range(min(D), max(D)+1):
    for i in range(len(D)):
        if D[i] >= k:
            break
    if center == i:
        cnt += 1
print(cnt)


Fixed submission:
# C
import math
N = int(input())
D = sorted(list(map(int, input().split())))
print(D[math.ceil((N)/2)] - D[math.ceil((N)/2)-1])
Buggy python submission (verdict: Runtime Error):
import sys,math
input = sys.stdin.readline

A,B,C,D = map(int,input().split())
lcm =  (C*D)/math.gcd(C,D)
c=0
End = (B//C)+(B//D)-(B//(lcm))
if A != 1:
  Start = ((A-1)//C)+((A-1)//D)-((A-1)//(lcm))
else :
  Start = 1
print(int((B-A+1)-(End-Start)))


Fixed submission:
import sys,fractions
input = sys.stdin.readline

A,B,C,D = map(int,input().split())


lcm =  (C*D)//fractions.gcd(C,D)
c=0
End = (B//C)+(B//D)-(B//(lcm))

Start = ((A-1)//C)+((A-1)//D)-((A-1)//(lcm))

print(int((B-A+1)-(End-Start)))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A_B = [list(map(int,input().split())) for i in range(N)]
A_B = sorted(A_B,key=itemgetter(1))
#print(A_B)
s=0
for a_b in A_B:
  s+=a_b[0]
  lim = a_b[1]
  if s > lim:
    print("No")
    exit()
print("Yes")


Fixed submission:
import sys
from operator import itemgetter
input = sys.stdin.readline
N = int(input())
A_B = [list(map(int,input().split())) for i in range(N)]
A_B = sorted(A_B,key=itemgetter(1))
#print(A_B)
s=0
for a_b in A_B:
  s+=a_b[0]
  lim = a_b[1]
  if s > lim:
    print("No")
    exit()
print("Yes")
Buggy python submission (verdict: Runtime Error):
import sys,math
input=sys.stdin.readline
N=int(input())
num = list(map(int,input().split()))
left=[0]*(N+1)
right=[0]*(N+1)
for i in range(N):
  j = N-i-1#初期値=4
  left[i+1] = math.gcd(left[i],num[i])
  right[j] = math.gcd(right[j+1],num[j])
ans=0
for k in range(N):
  ans = max(ans,math.gcd(left[k],right[k+1]))
print(ans)

Fixed submission:
import sys,fractions
input=sys.stdin.readline
N=int(input())
num = list(map(int,input().split()))
g = fractions.gcd
left=[0]*(N+1)
right=[0]*(N+1)
for i in range(N):
  j = N-i-1#初期値=4
  left[i+1] = g(left[i],num[i])
  right[j] = g(right[j+1],num[j])
ans=0
for k in range(N):
  ans = max(ans,g(left[k],right[k+1]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def countc(color,num):
  cnt=0
  if color=='#':
    for i in range(num):
      if S[i]=='#':
        cnt+=1
  else:
    for j in range(num,N):
      if S[j]=='.':
        cnt+=1
  return cnt


import sys
input=sys.stdin.readline
N=int(input())
S=input()[:-1]
c=N*2
for i in range(N+1):
  c = min(c,countc('#',i)+countc('.',i))
print(c)

Fixed submission:
import sys
input=sys.stdin.readline
N=int(input())
S=input()
w=S.count('.')
c=w
for i in range(N):
  if S[i]=='.':
    w-=1
  else:
    w+=1
  c=min(c,w)
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
N=int(input())
S=input()[:-1]
c=N
for i in range(N+1):
  c = min(c,S[:i].count('#')+S[i:].count("."))
print(c)


Fixed submission:
import sys
input=sys.stdin.readline
N=int(input())
S=input()
w=S.count('.')
c=w
for i in range(N):
  if S[i]=='.':
    w-=1
  else:
    w+=1
  c=min(c,w)
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
N=int(input())
S=input()[:-1]
c=N*2
for i in range(N+1):
  c = min(c,S[:i].count('#')+S[i:].count("."))
print(c)


Fixed submission:
import sys
input=sys.stdin.readline
N=int(input())
S=input()
w=S.count('.')
c=w
for i in range(N):
  if S[i]=='.':
    w-=1
  else:
    w+=1
  c=min(c,w)
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
N=int(input())
S=input()[:-1]
c=N*2
for i in range(N+1):
  c = min(c,S[:i].count('#')+S[i:].count("."))
print(c)


Fixed submission:
import sys
input=sys.stdin.readline
N=int(input())
S=input()
w=S.count('.')
c=w
for i in range(N):
  if S[i]=='.':
    w-=1
  else:
    w+=1
  c=min(c,w)
print(c)

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
N=int(input())
S=list(input()[:-1])
c=0
for i in range(1,N+1):
  if S[i-1]=='#'and S[i]=='.':
    S[i]='#'
    c+=1
print(c)

Fixed submission:
import sys
input=sys.stdin.readline
N=int(input())
S=input()
w=S.count('.')
c=w
for i in range(N):
  if S[i]=='.':
    w-=1
  else:
    w+=1
  c=min(c,w)
print(c)
Buggy python submission (verdict: Runtime Error):
A,B = map(int, raw_input().split())
if((A <= 8) or (B <= 8)):
	print("Yay!")
else:
	print(":(")


Fixed submission:
A,B = map(int, input().split())

if (A > 8) or (B > 8):
    print(":(")
else:
    print("Yay!")
Buggy python submission (verdict: Time Limit Exceeded):
# ABC093
A, B, K = map(int, input().split())

for num in range(A, B+1):
    if (A <= num < A+K) or (B-K < num <= B):
        print(num)

Fixed submission:
# ABC093
A, B, K = map(int, input().split())

for num in range(A, min(B+1, A+K)):
    print(num)
for num in range(max(A+K, B-K+1), B+1):
    print(num)
Buggy python submission (verdict: Runtime Error):
N=input();c=0
for n in range(len(N)-1):
    if N[n]==N[n+1]:
        c+=1
    else:
        c=0
   if c>=3:
    print('Yes')
    exit()
print('No')

Fixed submission:
N=input();cnt=0
for i in range(1,4):
    if N[i-1]==N[i]:
        cnt+=1
        if cnt>=2:
            print('Yes')
            exit()
    else:
        cnt=0
print('No')

Buggy python submission (verdict: Runtime Error):
N=input();c=0
for n in range(len(N)-1):
    if N[n]==N[n+1]:
        c+=1
    else:
        c=0
   if c>=3:
    print('Yes')
    exit()
print('No')

Fixed submission:
N=input();cnt=0
for i in range(1,4):
    if N[i-1]==N[i]:
        cnt+=1
        if cnt>=2:
            print('Yes')
            exit()
    else:
        cnt=0
print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = input().split()
b = []

x = 0
if n % 2 != 0:
    b.insert(0,a[x])
    x += 1

for i in range(x,n):
    if(i % 2 == 0):
        b.append(a[i])
    else:
        b.insert(0,a[i])
if n % 2 != 0:
    b.reverse()

print(*b)



Fixed submission:
from collections import deque
n = int(input())
a = input().split()
b = deque()


for i in range(0,n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])
if n % 2 != 0:
    b.reverse()

print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = input().split()
b = []

x = 0
if n % 2 != 0:
    b.insert(0,a[x])
    x += 1

for i in range(x,n):
    if(i % 2 == 0):
        b.append(a[i])
    else:
        b.insert(0,a[i])
if n % 2 != 0:
    b.reverse()
    
print(' '.join(b))



Fixed submission:
from collections import deque
n = int(input())
a = input().split()
b = deque()


for i in range(0,n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])
if n % 2 != 0:
    b.reverse()

print(*b)
Buggy python submission (verdict: Time Limit Exceeded):

# ABC055
N = int(input())
power = 1
for n in range(1, N+1):
    power *= n
print(power % (10**9+7))


Fixed submission:
N = int(input())
power = 1
for n in range(1, N+1):
    power = power % (10**9+7) * n
print(power % (10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
K,S=map(int,input().split());c=0
for x in range(K+1):
  if x>S:
    break
  for y in range(K+1):
    if x+y>S:
      break 
    for z in range(K+1):
      if x+y+z>S:
        break
      if x+y+z == S:
        c+=1
print(c)

Fixed submission:
import sys
input=sys.stdin.readline
K,S=map(int,input().split());c=0
for x in range(K+1):
  for y in range(K+1):
    z = S-x-y
    if 0<=z<=K:
      c+=1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
K,S=map(int,input().split());c=0
for x in range(K+1):
  for y in range(K+1):
    for z in range(K+1):
      if x+y+z == S:
        c+=1
print(c)

Fixed submission:
import sys
input=sys.stdin.readline
K,S=map(int,input().split());c=0
for x in range(K+1):
  for y in range(K+1):
    z = S-x-y
    if 0<=z<=K:
      c+=1
print(c)
Buggy python submission (verdict: Runtime Error):
# ABC045
from collections import deque
S_A = deque(input())
S_B = deque(input())
S_C = deque(input())

next_turn = S_A.pop()

while True:
    if next_turn == 'a':
        next_turn = S_A.pop()
    elif next_turn == 'b':
        next_turn = S_B.pop()
    else:
        next_turn = S_C.pop()

    # 勝利判定
    if len(S_A) == 0:
        print("A")
        exit()
    elif len(S_B) == 0:
        print("B")
        exit()
    elif len(S_C) == 0:
        print("C")
        exit()
    else:
        pass


Fixed submission:
# ABC045
from collections import deque
S_A = deque(input())
S_B = deque(input())
S_C = deque(input())

# 最初はAから
next_turn = 'a'

while True:
    # 勝利判定
    if len(S_A) == 0 and next_turn == 'a':
        print("A")
        exit()
    elif len(S_B) == 0 and next_turn == 'b':
        print("B")
        exit()
    elif len(S_C) == 0 and next_turn == 'c':
        print("C")
        exit()
    else:
        if next_turn == 'a':
            next_turn = S_A.popleft()
        elif next_turn == 'b':
            next_turn = S_B.popleft()
        elif next_turn == 'c':
            next_turn = S_C.popleft()
Buggy python submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
N,M = map(int,input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    A[i],B[i] = map(int,input().split())
uf = UnionFind(N)
for i in range(M):
    uf.union(A[i],B[i])
groups = uf.group_count()
print(groups-1)

Fixed submission:

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
N,M = map(int,input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    A[i],B[i] = map(int,input().split())
uf = UnionFind(N)
for i in range(M):
    uf.union(A[i]-1,B[i]-1)
groups = uf.group_count()
print(groups-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
sumans = 0
for i in range(N-1):
    sumans += A[i]*sum(A[i+1:])%mod
    sumans = sumans%mod
print(sumans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
sumpre = 0
sumans = 0
for i in range(N-1):
    sumpre += A[i]
    sumans += A[i+1]*sumpre%mod
    sumans =sumans%mod
print(sumans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = sorted(map(int,input().split()),reverse = True)
answer = 0
i = 1
s = 0
answer = A[0]
while True:
    s = (i+1)//2
    answer += A[s]
    i += 1
    if i == N-1:
        break
    
print(answer)

Fixed submission:
N = int(input())
A = sorted(map(int,input().split()),reverse = True)
answer = 0
i = 1
s = 0
answer = A[0]
if N == 2:
    anwer=A[0]
else:
    while True:
        s = (i+1)//2
        answer += A[s]
        i += 1
        if i == N-1:
            break
    
print(answer)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = sorted(map(int,input().split()),reverse = True)
answer = 0
i = 1
s = 0
answer = A[0]
while True:
    s = (i+1)//2
    answer += A[s]
    print(i,s)
    i += 1
    if i == N-1:
        break
    
print(answer)

Fixed submission:
N = int(input())
A = sorted(map(int,input().split()),reverse = True)
answer = 0
i = 1
s = 0
answer = A[0]
if N == 2:
    anwer=A[0]
else:
    while True:
        s = (i+1)//2
        answer += A[s]
        i += 1
        if i == N-1:
            break
    
print(answer)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = sorted(map(int,input().split()),reverse = True)
answer = 0
i = 1
s = 0
answer = A[0]
while True:
    s = i-(i-1)%2
    answer += A[s]
    #print(i,s)
    i += 1
    if i == N-1:
        break
    
print(answer)

Fixed submission:
N = int(input())
A = sorted(map(int,input().split()),reverse = True)
answer = 0
i = 1
s = 0
answer = A[0]
if N == 2:
    anwer=A[0]
else:
    while True:
        s = (i+1)//2
        answer += A[s]
        i += 1
        if i == N-1:
            break
    
print(answer)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = sorted(map(int,input().split()),reverse = True)
answer = 0
i = 1
s = 0
answer = A[0]
while True:
    s = i+i%2
    answer += A[s]
    #print(i,s)
    i += 1
    if i == N-1:
        break
    
print(answer)

Fixed submission:
N = int(input())
A = sorted(map(int,input().split()),reverse = True)
answer = 0
i = 1
s = 0
answer = A[0]
if N == 2:
    anwer=A[0]
else:
    while True:
        s = (i+1)//2
        answer += A[s]
        i += 1
        if i == N-1:
            break
    
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = []
for _ in range(N):
    s = str(input())
    if s not in S:
        S.append(s)

print(len(S))

Fixed submission:
N = int(input())
S = []
for _ in range(N):
    s = str(input())
    S.append(s)
S1 = sorted(S)
counter=1
for i in range(N-1):
    if S1[i]!=S1[i+1]:
        counter+=1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = []
for i in range(N):
    s = str(input())
    if s not in S:
        S.append(s)

print(len(S))

Fixed submission:
N = int(input())
S = []
for _ in range(N):
    s = str(input())
    S.append(s)
S1 = sorted(S)
counter=1
for i in range(N-1):
    if S1[i]!=S1[i+1]:
        counter+=1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = []
for i in range(N):
    S.append(str(input()))
words = []
for i in range(N):
    if S[i] not in words:
        words.append(S[i])
print(len(words))

Fixed submission:
N = int(input())
S = []
for _ in range(N):
    s = str(input())
    S.append(s)
S1 = sorted(S)
counter=1
for i in range(N-1):
    if S1[i]!=S1[i+1]:
        counter+=1
print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
Q = int(input())
Qvery = [0]*Q
for i in range(Q):
    Qvery[i] = list(map(str,input().split()))
frontback = 1
for i in range(Q):
    if Qvery[i][0]=='1':
        frontback *= -1
        
    else:
        if Qvery[i][1]=='2':
            if frontback == 1:
                S = S + str(Qvery[i][2])
            else:
                S = str(Qvery[i][2]) + S
        else:
            if frontback == 1:
                S = str(Qvery[i][2]) + S
            else:
                S = S + str(Qvery[i][2])
if frontback == -1:
    S = S[::-1]
print(S)

Fixed submission:
S = str(input())
Q = int(input())
Qvery = [0]*Q
for i in range(Q):
    Qvery[i] = list(map(str,input().split()))
frontback = 1
tail = ''
head = ''
for i in range(Q):
    if Qvery[i][0]=='1':
        frontback *= -1
        
    else:
        if Qvery[i][1]=='2':
            if frontback == 1:
                tail +=  str(Qvery[i][2])
            else:
                head = str(Qvery[i][2]) + head
        else:
            if frontback == 1:
                head = str(Qvery[i][2])+head
            else:
                tail += str(Qvery[i][2])
S = head + S + tail
if frontback == -1:
    S = S[::-1]
    
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
Q = int(input())
Qvery = [0]*Q
for i in range(Q):
    Qvery[i] = list(map(str,input().split()))
    
for i in range(Q):
    if Qvery[i][0]=='1':
        S = S[::-1]
    else:
        if Qvery[i][1]=='2':
            S = S + str(Qvery[i][2])
        else:
            S = str(Qvery[i][2]+S)
  
print(S)

Fixed submission:
S = str(input())
Q = int(input())
Qvery = [0]*Q
for i in range(Q):
    Qvery[i] = list(map(str,input().split()))
frontback = 1
tail = ''
head = ''
for i in range(Q):
    if Qvery[i][0]=='1':
        frontback *= -1
        
    else:
        if Qvery[i][1]=='2':
            if frontback == 1:
                tail +=  str(Qvery[i][2])
            else:
                head = str(Qvery[i][2]) + head
        else:
            if frontback == 1:
                head = str(Qvery[i][2])+head
            else:
                tail += str(Qvery[i][2])
S = head + S + tail
if frontback == -1:
    S = S[::-1]
    
print(S)