Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for i in range(M)]

T=[]
for m in range(M):
    t=[BC[m][1]]*BC[m][0]
    T=T+t

D=A+T
D=sorted(D,reverse=True)

ANS=sum(D[:N])

print(ANS)

    


Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for i in range(M)]
BC=sorted(BC,key=lambda x:x[1],reverse=True)

T=[0]*N
count=0
cntmp=0
for m in range(M):
    count+=BC[m][0]
    if count>N:
        T[cntmp:]=[BC[m][1]]*(N-count+BC[m][0])
        break
    else:
        T[cntmp:count]=[BC[m][1]]*BC[m][0]
    cntmp=count


#print(A)
#print(T)

D=A+T
D=sorted(D,reverse=True)

ANS=sum(D[:N])

print(ANS)
Buggy python submission (verdict: Runtime Error):
import math

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

#print(A)

lgcd=[A[0]]*N
for i in range(1,N):
    lgcd[i]=math.gcd(lgcd[i-1],A[i])

rgcd=[A[-1]]*N
for i in reversed(range(0,N-1)):
    rgcd[i]=math.gcd(rgcd[i+1],A[i])

#print(lgcd)
#print(rgcd)


ans=[0]*N
ans[0]=rgcd[1]
ans[N-1]=lgcd[N-2]
for i in range(1,N-1):
    ans[i]=math.gcd(lgcd[i-1],rgcd[i+1])
print(max(ans))


Fixed submission:
import math

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

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

#print(A)
lgcd=[A[0]]*N
for i in range(1,N):
    lgcd[i]=gcd(lgcd[i-1],A[i])

rgcd=[A[-1]]*N
for i in reversed(range(0,N-1)):
    rgcd[i]=gcd(rgcd[i+1],A[i])

#print(lgcd)
#print(rgcd)

ans=[0]*N
ans[0]=rgcd[1]
ans[N-1]=lgcd[N-2]
for i in range(1,N-1):
    ans[i]=gcd(lgcd[i-1],rgcd[i+1])
print(max(ans))
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))

Ap=[]
Am=[]
for a in A:
    if a >= 0:
        Ap.append(a)
    else:
        Am.append(a)

Ap=sorted(Ap)
Am=sorted(Am,reverse=True)

if len(Am)%2==0:
    Ams=-sum(Am)
    Aps=sum(Ap)
    ans=Ams+Aps
else:
    Ams=-sum(Am)+Am[0]
    Aps=sum(Ap)-Ap[0]
    tmp=Ap[0]+Am[0]
    if tmp<0:
        tmp=-tmp
    ans=Ams+Aps+tmp
        
print(ans)


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

Ap=[]
Am=[]
for a in A:
    if a >= 0:
        Ap.append(a)
    else:
        Am.append(a)

Ap=sorted(Ap)
Am=sorted(Am,reverse=True)


if len(Ap)==0:
    if len(Am)%2==0:
        ans=-sum(Am)
    else:
        ans=-sum(Am)+2*Am[0]
        
elif len(Am)%2==0:
    Ams=-sum(Am)
    Aps=sum(Ap)
    ans=Ams+Aps
else:
    Ams=-sum(Am)+Am[0]
    Aps=sum(Ap)-Ap[0]
    tmp=Ap[0]+Am[0]
    if tmp<0:
        tmp=-tmp
    ans=Ams+Aps+tmp
        
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))

Ap=[]
Am=[]
for a in A:
    if a >= 0:
        Ap.append(a)
    else:
        Am.append(a)

Ap=sorted(Ap)
Am=sorted(Am,reverse=True)

if len(Am)%2==0:
    Ams=-sum(Am)
    Aps=sum(Ap)
    ans=Ams+Aps
else:
    Ams=-sum(Am[1:])
    Aps=sum(Ap[1:])
    tmp=Ap[0]+Am[0]
    if tmp<0:
        tmp=-tmp
    ans=Ams+Aps+tmp
        
print(ans)


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

Ap=[]
Am=[]
for a in A:
    if a >= 0:
        Ap.append(a)
    else:
        Am.append(a)

Ap=sorted(Ap)
Am=sorted(Am,reverse=True)


if len(Ap)==0:
    if len(Am)%2==0:
        ans=-sum(Am)
    else:
        ans=-sum(Am)+2*Am[0]
        
elif len(Am)%2==0:
    Ams=-sum(Am)
    Aps=sum(Ap)
    ans=Ams+Aps
else:
    Ams=-sum(Am)+Am[0]
    Aps=sum(Ap)-Ap[0]
    tmp=Ap[0]+Am[0]
    if tmp<0:
        tmp=-tmp
    ans=Ams+Aps+tmp
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K,S=map(int,input().split())

cnt=0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if S==(x+y+z):
                cnt+=1

print(cnt)



Fixed submission:
K,S=map(int,input().split())

cnt=0
for x in range(K+1):
    for y in range(K+1):
        if 0<=(S-(x+y))<=K:
            cnt+=1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding:utf-8 -*-

# input N
n = int(input())

# N!を求める
nk = 1
for i in range(2, n+1):
    nk *= i

# nkの約数の個数を求める
x = 0
for i in range(1, nk+1):
    if nk % i == 0:
        x += 1

# xを10^9 + 7で割った余りを出力
x2 = x % (pow(10, 9) + 7)
print(x2)


Fixed submission:
# -*- coding:utf-8 -*-

# input N
n = int(input())
a = [0] * (n+1)

s = 1
for i in range(2, n+1):
    for j in range(2, i):
        if i % j == 0:
            break
    else:
        for k in range(2, n+1):
            while k >= i:
                if k % i == 0:
                    a[i] += 1
                    k /= i
                else:
                    break

for i in range(2, n+1):
    if a[i] != 0:
        a[i] += 1
        s *= a[i]

print(s % (pow(10, 9) + 7))
Buggy python submission (verdict: Time Limit Exceeded):
# AtCoder Beginner Contest 162: C (2020/04/12)
import math
K = int(input())
S = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            x = [a, b, c]
            ans = x[0]
            for i in range(1, 3):
                ans = math.gcd(ans, x[i])
            S = S + ans
print(S)

Fixed submission:
# AtCoder Beginner Contest 162: C (2020/04/12)
import math
K = int(input())
S = 0
for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            x = [a, b, c]
            ans = x[0]
            for i in range(1, 3):
                ans = math.gcd(ans, x[i])
            if a == b and b == c:
                S = S + ans
            elif a == b or b == c:
                S = S + 3*ans
            else:
                S = S + 6*ans
print(S)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

ans = 3*(10**5)
for i in range(n):
  
  east = s.count('W', 0, i-1) if i else 0
  west = s.count('E', i+1) if not i==n-1 else 0
  ans = east+west if ans>east+west else ans
  
print(ans)


Fixed submission:
n = int(input())
s = input()

to_east = 0
to_west = s.count('E', 1)
ans = to_east+to_west

for i in range(1, n):
  if s[i-1]=='W':
    to_east += 1
  if s[i]=='E':
    to_west -= 1
  ans = to_east+to_west if ans>to_east+to_west else ans
  
print(ans)
Buggy python submission (verdict: Runtime Error):
w = list(map(str,input()))
w.sort()
w = "".join(w)

flag = 0
w = [w[i*2:i*2+2] for i in range(-(-len(w)//2))]
for i in w:
  if not i[0] == i[1]:
    flag = 1

print("Yes") if not flag else print("No")

Fixed submission:
w = list(map(str,input()))
w.sort()
w = "".join(w)

flag = 0
w = [w[i*2:i*2+2] for i in range(-(-len(w)//2))]
for i in w:
  if len(i)==1 or not i[0] == i[1]:
    flag = 1
    break

print("Yes") if not flag else print("No")

Buggy python submission (verdict: Runtime Error):
w = list(map(str,input()))
w.sort()
w = "".join(w)

flag = 0
w = [w[i*2:i*2+2] for i in range(-(-len(w)//2))]
for i in w:
  if not w[0] == w[1]:
    flag = 1

print("Yes") if not flag else print("No")


Fixed submission:
w = list(map(str,input()))
w.sort()
w = "".join(w)

flag = 0
w = [w[i*2:i*2+2] for i in range(-(-len(w)//2))]
for i in w:
  if len(i)==1 or not i[0] == i[1]:
    flag = 1
    break

print("Yes") if not flag else print("No")
Buggy python submission (verdict: Runtime Error):
import numpy as np

n=100
X = int(input())

a = np.array(range(n))
ex = np.full(n, 5)

m = a*n+a.reshape(n,1)

b = np.power(a, ex)

plus = b + b.reshape(n,1)
minus = b - b.reshape(n,1)

plus = plus==X
minus = minus==X

if np.count_nonzero(plus):
  c = m[plus][0]
  ans = int(c/n), -int(c%n)
else:
  c = m[minus][0]
  ans = int(c/n), int(c%n)
  
print(ans[0], ans[1], sep=' ')

Fixed submission:
import numpy as np

n=1000
X = int(input())

a = np.array(range(n))
ex = np.full(n, 5)

m = a*n+a.reshape(n,1)

b = np.power(a, ex)

plus = b + b.reshape(n,1)
minus = b - b.reshape(n,1)

plus = plus==X
minus = minus==X

if np.count_nonzero(plus):
  c = m[plus][0]
  ans = int(c/n), -int(c%n)
else:
  c = m[minus][0]
  ans = int(c/n), int(c%n)
  
print(ans[0], ans[1], sep=' ')
Buggy python submission (verdict: Runtime Error):
import math

A, B, N = tuple(map(int, input().split()))

m = 0
n = 1

def cal(x):
  return math.floor(A*x/B)-A*math.floor(x/B)

while n<N:
  c = B*(math.floor((n+1)/B)+1)-1
  n = min(N, c)
  m = max(cal(n), m)
  if (A*x)%B == 0:
    break
  
print(m)

Fixed submission:
import math

A, B, N = tuple(map(int, input().split()))

m = 0
n = 1

def cal(x):
  return math.floor(A*x/B)-A*math.floor(x/B)

while n<N:
  c = B*(math.floor((n+1)/B)+1)-1
  n = min(N, c)
  m = max(cal(n), m)
  if (A*n)%B == 0:
    break
  
print(m)

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

A, B, N = tuple(map(int, input().split()))

m = 0
n = 1

def cal(x):
  return math.floor(A*x/B)-A*math.floor(x/B)

def Bceil(x):
  return B*(math.floor((x+1)/B)+1)-1

while n<N:
  c = Bceil(n)
  n = min(N, c)
  m = max(cal(n), m)
  
print(m)

Fixed submission:
import math

A, B, N = tuple(map(int, input().split()))

m = 0
n = 1

def cal(x):
  return math.floor(A*x/B)-A*math.floor(x/B)

while n<N:
  c = B*(math.floor((n+1)/B)+1)-1
  n = min(N, c)
  m = max(cal(n), m)
  if (A*n)%B == 0:
    break
  
print(m)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

lis = []

for n in range(N):
  s = input()
  if not s in lis:
    lis.append(s)

print(len(lis))

Fixed submission:
N = int(input())

lis = []

for n in range(N):
  lis.append(input())

s = set(lis)
print(len(s))

Buggy python submission (verdict: Runtime Error):
N = int(input())

lis = []

for n in range(N):
  s = input()
  if not s in lis:
    s.append(s)

print(len(lis))

Fixed submission:
N = int(input())

lis = []

for n in range(N):
  lis.append(input())

s = set(lis)
print(len(s))
Buggy python submission (verdict: Runtime Error):
s = input().split
s = s[0]+s[1]+s[2]

if s.count('5')==2 and s.count('7')==1:
  print("Yes")
else:
  print("No")


Fixed submission:
a, b, c = input().split()

if (a+b+c).count('5')==2 and (a+b+c).count('7')==1:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())
 
if N == 2:
  print(A+B)
elif N ==1:
  print("Hello World")

Fixed submission:
N = int(input())
if N ==1:
  print("Hello World")
elif N == 2:
  A = int(input())
  B = int(input())
  print(A+B)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())

if N = 2:
  print(A+B)
elif N =1:
  print("Hello World")

Fixed submission:
N = int(input())
if N ==1:
  print("Hello World")
elif N == 2:
  A = int(input())
  B = int(input())
  print(A+B)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())

if N > 1:
  print(A+B)
else:
  print("Hello World")

Fixed submission:
N = int(input())
if N ==1:
  print("Hello World")
elif N == 2:
  A = int(input())
  B = int(input())
  print(A+B)

Buggy python submission (verdict: Runtime Error):
N = input()
A = int(input())
B = int(input())

if N > 1:
  print(A+B)
else:
  print("Hello World")

Fixed submission:
N = int(input())
if N ==1:
  print("Hello World")
elif N == 2:
  A = int(input())
  B = int(input())
  print(A+B)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, raw_input().split())
a = []
for i in range(N):
    a.append(map(int, raw_input().split()))

mincost = 10001
minnum = 10000
for i in range(N):
    if a[i][1]>M:
        continue
    else:
        if mincost > a[i][0]:
            mincost = a[i][0]
            minnum = i

print(a[minnum][0])

Fixed submission:
N, M = map(int, raw_input().split())
a = []
for i in range(N):
    a.append(map(int, raw_input().split()))

mincost = 10001
minnum = 10000
for i in range(N):
    if a[i][1]>M:
        continue
    else:
        if mincost > a[i][0]:
            mincost = a[i][0]
            minnum = i
if mincost == 10001:
  print ("TLE")
else:
  print(a[minnum][0])
Buggy python submission (verdict: Runtime Error):
A = raw_input()
C = raw_input()

B = int(C)

num = map(int, str(A))

i = 0

while num[i] == 1:
  i = i +1

  
if i < B:
  print num[i]
elif i > B-1:
  print 1



Fixed submission:
A = raw_input()
C = raw_input()

B = int(C)

num = map(int, str(A))

numnum = len(num)


i = 0

while num[i] == 1 and numnum-1 > i:
  i = i +1

  
if i < B:
  print num[i]
elif i > B-1:
  print 1
Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split())
a = list(map(int, input().split()))

if 0 in a:
  N = N - 1
  if N == 0:
    print('0')
    exit()

aLow = list(filter(lambda x: x < 0, a))
aLow = list(map(lambda x: abs(x), aLow))
aLow.sort()

aHigh = list(filter(lambda x: x > 0, a))

least = 99999999999999999

#print(aLow)
#print(aHigh)

for i in range(0,N+1):
  j = K - i
  if i > len(aLow) or j > len(aHigh):
    continue

  if i == 0:
    dist = aHigh[j-1]
  elif j == 0:
    dist = aLow[i-1]
  else:
    dist = min(2*aLow[i-1]+aHigh[j-1], aLow[i-1]+2*aHigh[j-1])

  if least > dist:
    least = dist

print(least)


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

if 0 in a:
  K = K - 1
  if K == 0:
    print('0')
    exit()

aLow = list(filter(lambda x: x < 0, a))
aLow = list(map(lambda x: abs(x), aLow))
aLow.sort()

aHigh = list(filter(lambda x: x > 0, a))

least = 99999999999999999

#print(aLow)
#print(aHigh)

for i in range(0,K+1):
  j = K - i
  if i > len(aLow) or j > len(aHigh):
    continue

  if i == 0:
    dist = aHigh[j-1]
  elif j == 0:
    dist = aLow[i-1]
  else:
    dist = min(2*aLow[i-1]+aHigh[j-1], aLow[i-1]+2*aHigh[j-1])

  if least > dist:
    least = dist

print(least)

Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split())
a = list(map(int, input().split()))

if 0 in a:
  N = N - 1
  if N == 0:
    print('0')
    exit()

aLow = list(filter(lambda x: x < 0, a))
aLow = list(map(lambda x: abs(x), aLow))
aLow = aLow.sort()

aHigh = list(filter(lambda x: x > 0, a))

least = 99999999999999999

for i in range(0,len(aLow)):
  j = N - i
  if i == 0:
    dist = aHigh[j-1]
  elif j == 0:
    dist = aLow[i-1]
  else:
    dist = min(2*aLow[i-1]+aHigh[j-1], aLow[i-1]+2*aHigh[j-1])

  if least > dist:
    least = dist

print(least)


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

if 0 in a:
  K = K - 1
  if K == 0:
    print('0')
    exit()

aLow = list(filter(lambda x: x < 0, a))
aLow = list(map(lambda x: abs(x), aLow))
aLow.sort()

aHigh = list(filter(lambda x: x > 0, a))

least = 99999999999999999

#print(aLow)
#print(aHigh)

for i in range(0,K+1):
  j = K - i
  if i > len(aLow) or j > len(aHigh):
    continue

  if i == 0:
    dist = aHigh[j-1]
  elif j == 0:
    dist = aLow[i-1]
  else:
    dist = min(2*aLow[i-1]+aHigh[j-1], aLow[i-1]+2*aHigh[j-1])

  if least > dist:
    least = dist

print(least)
Buggy python submission (verdict: Runtime Error):
N, M, Q = map(int, input().split())

a = [[0 for i in range(509)] for j in range(509)]
sum = [[0 for i in range(509)] for j in range(509)]

for i in range(M):
  p, q = map(int, input().split())
  a[p][q] += 1

for i in range(1,N+1):
  for j in range(i,N+1):
    sum[i][j] = sum[i][j-1] + a[i][j]


for i in range(Q):
  p, q = map(int, input().split())
  ans = 0
  for j in range(p,q+1):
    ans += sum[j][q] - sum[j][p-1]
  print(ans)


Fixed submission:
A, B =  map(int, input().split())
result = A * B - A - B + 1
print(result)
Buggy python submission (verdict: Runtime Error):
N = int(input())

flag = False
for i in range(0,30):
  for j in range(0,30):
  	if i * 4 + j * 7 == N:
      flag = True

if flag == True:
  print('Yes')
else:
  print('No')

Fixed submission:
N = int(input())

flag = False
for i in range(0,30):
  for j in range(0,30):
    if i * 4 + j * 7 == N:
      flag = True

if flag == True:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
date = input()
date[3] = '8'
print(date)

Fixed submission:
str = input()
print(str[0:3]+'8'+str[4:])
Buggy python submission (verdict: Runtime Error):
S = raw_input()
length = len(S)

print '{0}{1}{2}'.format(S[0], length-2, S[length-1])


Fixed submission:
S = raw_input()
length = len(S)

print '{0}{1}{2}'.format(S[0], length-2, S[length-1])
Buggy python submission (verdict: Runtime Error):
X = int(input())

def nb(b):
    if b == 0:
        return 1
    elif b > 0:
        return -b
    else:
        return -b+1

b = 0

while 1:
    # print("b:",b)
    a_est = int((b**5+X)**0.2)
    if a_est**5-b**5==X:
        a = a_est
        break
    elif (a_est+1)**5-b==X:
        a = a_est+1
        break
    
    # print(a_est)
    b = nb(b)

print(a,b)

Fixed submission:
X = int(input())

def nb(b):
    if b == 0:
        return 1
    elif b > 0:
        return -b
    else:
        return -b+1

b = 0

def fac(x):
    if x>=0:
        return x**0.2
    else:
        return -(-x)**0.2

while 1:
   
# for i in range(1):
    # print("b:",b)
    a_est = int(fac(b**5+X))
    if a_est**5-b**5==X:
        a = a_est
        break
    elif (a_est+1)**5-b==X:
        a = a_est+1
        break
    
    # print(a_est)
    b = nb(b)

print(a,b)
Buggy python submission (verdict: Runtime Error):
n,a,b,c = map(int,input().split())
Y = []
f = True
S = []
for i in range(n):
    S.append(input())
GB = []
i = 0
g = False
while i<n:
    s = S[i]
    if s == "AB":
        if a>b:
            a -= 1
            b += 1
            Y.append("B")
        elif a<b:
            a += 1
            b -= 1
            Y.append("A")
        else:
            if g:
                a -= 1
                b += 1
                Y.append("B")
            else:
                a += 1
                b -= 1
                Y.append("A")
                GB.append(i)
    elif s == "AC":
        if a>c:
            a -= 1
            c += 1
            Y.append("C")
        elif a<c:
            a += 1
            c -= 1
            Y.append("A")
        else:
            if g:
                a -= 1
                c += 1
                Y.append("C")
            else:
                a += 1
                c -= 1
                Y.append("A")
                GB.append(i)
    else:
        if c>b:
            c -= 1
            b += 1
            Y.append("B")
        elif c<b:
            c += 1
            b -= 1
            Y.append("C")
        else:
            if g:
                c -= 1
                b += 1
                Y.append("B")
            else:
                c += 1
                b -= 1
                Y.append("C")
                GB.append(i)
    # print("i",i)
    # print(a,b,c)
    # print(GB)
    if a<0 or b<0 or c<0:
        if GB:
            i = GB.pop(-1)
            del Y[i]
        else:
            f = False
            print("No")
            break
    
    i += 1 
        
if f:
    print("Yes")
    for y in Y:
        print(y)


Fixed submission:
N,a,b,c = map(int,input().split())
S = []
D = [a,b,c]
# d = a+b+c
for _ in range(N):
    S.append(input())
# print(S)
Y = []

def f(s,ns):
    s0 = ord(s[0])-65
    s1 = ord(s[1])-65
    k = 0
    if D[s0] == D[s1]:
        ns0 = ord(ns[0])-65
        ns1 = ord(ns[1])-65
        
        if s0 == ns0 and s1 == ns1:
            k = 0
        elif s0 == 3 - ns0 - ns1:
            k = 0
        else:
            k = 1
    
    elif D[s0] > D[s1]:
        k = 0
    else:
        k = 1
        
    if k==0:
        D[s0] -= 1
        D[s1] += 1
        # print(s[1])
        Y.append(s[1])
    else:
        D[s0] += 1
        D[s1] -= 1
        # print(s[0])
        Y.append(s[0])
        

g = True
# print(D)
for i in range(N):
    s = S[i]
    if i == N-1:
        ns = s
    else:
        ns = S[i+1]
    # print(s,ns)
    f(s,ns)
    # print(D)
    if D[0] < 0 or D[1] < 0 or D[2] < 0:
        print("No")
        g = False
        break
    
if g:
    print("Yes")
    for y in Y:
        print(y)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Y = [[[] for _ in range(26)] for _ in range(10)]
# print(Y)
c = 0

for i in range(N):
    s = input()
    o = ord(s[0])-97
    l = len(s)
    if s not in Y[l-1][o]:
        Y[l-1][o].append(s)
        c += 1
# print(Y)
print(c)


Fixed submission:
N = int(input())
Y = []
for i in range(N):
    Y.append(input())
print(len(set(Y)))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Y = [[] for _ in range(26)]
c = 0

for i in range(N):
    s = input()
    o = ord(s[0])-97
    if s not in Y[o]:
        Y[o].append(s)
        c += 1
# print(Y)
print(c)

Fixed submission:
N = int(input())
Y = []
for i in range(N):
    Y.append(input())
print(len(set(Y)))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Y = [[] for _ in range(10)]
c = 0
for i in range(N):
    s = input()
    l = len(s)
    if s not in Y[l-1]:
        Y[l-1].append(s)
        c += 1
# print(Y)
print(c)

Fixed submission:
N = int(input())
Y = []
for i in range(N):
    Y.append(input())
print(len(set(Y)))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Y = []
c = 0
for i in range(N):
    S = input()
    if S not in Y:
        Y.append(S)
        c += 1
print(c)

Fixed submission:
N = int(input())
Y = []
for i in range(N):
    Y.append(input())
print(len(set(Y)))

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

Fixed submission:
N = int(input())
Y = []
for i in range(N):
    Y.append(input())
print(len(set(Y)))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
n = len(S)
Y = {0:1}
# print(Y)
Y[0] = 1
for i in range(1,n+1):
    k = int(S[-i:])%2019
    if k not in Y:
        Y[k] = 1
    else:
        Y[k] += 1
# print(Y)

c = 0
for y in Y:
    d = Y[y]
    c += d*(d-1)//2
print(c)


Fixed submission:
import time

p0 = time.time()
S = input()
n = len(S)
Y = {0:1}
# print(Y)
Y[0] = 1
A = [0]
pk = 0
for i in range(1,n+1):
    # print(S[-i])
    k = (int(S[-i])*pow(10,i-1,2019)+pk)%2019
    A.append(k)
    if k not in Y:
        Y[k] = 1
    else:
        Y[k] += 1
    pk = k

# print(A)
# print(Y)
# print(time.time()-p0)
c = 0
for y in Y:
    d = Y[y]
    c += d*(d-1)//2
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
n = len(S)
# print(n)
M = 2019
# A = [0]
Y = [0]*M
Y[0] = 1
for i in range(1,n+1):
    Y[int(S[-i:])%2019] += 1
    # A.append(int(S[-i:])%2019)
# print(A)
# print(Y)
c = 0
for y in Y:
    if y >= 2:
        c += y*(y-1)//2
print(c)

Fixed submission:
import time

p0 = time.time()
S = input()
n = len(S)
Y = {0:1}
# print(Y)
Y[0] = 1
A = [0]
pk = 0
for i in range(1,n+1):
    # print(S[-i])
    k = (int(S[-i])*pow(10,i-1,2019)+pk)%2019
    A.append(k)
    if k not in Y:
        Y[k] = 1
    else:
        Y[k] += 1
    pk = k

# print(A)
# print(Y)
# print(time.time()-p0)
c = 0
for y in Y:
    d = Y[y]
    c += d*(d-1)//2
print(c)