Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split(' ')))

for _ in range(M):
    l, r = list(map(int, input().split(' ')))
    
    if _ == 0:
        if r > N:
            r = N
        ans = set(range(l, r+1))
        
    else:
        if r > N:
            r = N
        _ans = ans
        ans = set(range(l, r+1))
        ans = ans & _ans

print(len(ans))

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

L = 1
R = N

for _ in range(M):
    l, r = list(map(int, input().split(' ')))
    if l > L:
        L = l
    if r < R:
        R = r

ans = R-L+1
if ans >= 0:
  print(ans)
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split(' ')))
A  = list(map(int, input().split(' ')))

for _ in range(M):
    B, C = list(map(int, input().split(' ')))
    A.extend([C]*B)
    
A = sorted(A)
print(sum(A[-N:]))

Fixed submission:
import collections
N, M = list(map(int, input().split(' ')))
A  = list(map(int, input().split(' ')))
dic = dict(collections.Counter(A))
for _ in range(M):
    B, C = list(map(int, input().split(' ')))
    if C in dic.keys():
        dic[C] += B
    else:
        dic[C] = B
l = 0
su = 0
for key in reversed(sorted(dic.keys())):
    l += dic[key]
    if l < N:
        su += key*dic[key]
    else:
        su += key*(dic[key]+(N-l))
        break
print(su)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split(' ')))
A  = list(map(int, input().split(' ')))

for _ in range(M):
    A = sorted(A)
    B, C = list(map(int, input().split(' ')))
    for i in range(B):
        if A[i] < C:
            A[i] = C
        else:
            break
print(sum(A))

Fixed submission:
import collections
N, M = list(map(int, input().split(' ')))
A  = list(map(int, input().split(' ')))
dic = dict(collections.Counter(A))
for _ in range(M):
    B, C = list(map(int, input().split(' ')))
    if C in dic.keys():
        dic[C] += B
    else:
        dic[C] = B
l = 0
su = 0
for key in reversed(sorted(dic.keys())):
    l += dic[key]
    if l < N:
        su += key*dic[key]
    else:
        su += key*(dic[key]+(N-l))
        break
print(su)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B ,N = list(map(int, input().split(' ')))

cnt = 0

li = [R, G, B]
li = sorted(li)

_i = N//li[2]

for i in range(_i+1):
    _j = (N - li[2]*i)//li[1] 
    for j in range(_j+1):
        _k = (N - li[2]*i - li[1]*j)//li[0]
        for k in range(_k, _k+1):
            if i*li[2] + j*li[1] + k*li[0] == N:
                cnt += 1
print(cnt)

Fixed submission:
R, G, B ,N = list(map(int, input().split(' ')))

cnt = 0

li = [R, G, B]
li = sorted(li)

_i = N//li[2]
for i in range(_i+1):
    _j = (N - li[2]*i )//li[1]
    for j in range(_j + 1):
        if (N - i*li[2] -  j*li[1])%li[0] == 0:
            cnt += 1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B ,N = list(map(int, input().split(' ')))

cnt = 0

_R = N//R

for i in range(_R+1):
    _G = (N - R*i)//G 
    for j in range(_G+1):
        _B = (N - R*i - G*j)//B 
        for k in range(_B, _B+1):
            if i*R + j*G + k*B == N:
                cnt += 1
print(cnt)

Fixed submission:
R, G, B ,N = list(map(int, input().split(' ')))

cnt = 0

li = [R, G, B]
li = sorted(li)

_i = N//li[2]
for i in range(_i+1):
    _j = (N - li[2]*i )//li[1]
    for j in range(_j + 1):
        if (N - i*li[2] -  j*li[1])%li[0] == 0:
            cnt += 1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B ,N = list(map(int, input().split(' ')))

cnt = 0

_R = N//R
_G = N//G
_B = N//B

for i in range(_R+1):
    for j in range(_G+1):
        if  i*R + j*G > N:
            break
        for k in range(_B+1):
            if i*R + j*G + k*B == N:
                cnt += 1
            elif i*R + j*G + k*B > N:
                break
print(cnt)

Fixed submission:
R, G, B ,N = list(map(int, input().split(' ')))

cnt = 0

li = [R, G, B]
li = sorted(li)

_i = N//li[2]
for i in range(_i+1):
    _j = (N - li[2]*i )//li[1]
    for j in range(_j + 1):
        if (N - i*li[2] -  j*li[1])%li[0] == 0:
            cnt += 1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B ,N = list(map(int, input().split(' ')))

cnt = 0

_R = N//R
_G = N//G
_B = N//B

for i in range(_R+1):
    for j in range(_G+1):
        for k in range(_B+1):
            if i*R + j*G + k*B == N:
                cnt += 1
print(cnt)
    

Fixed submission:
R, G, B ,N = list(map(int, input().split(' ')))

cnt = 0

li = [R, G, B]
li = sorted(li)

_i = N//li[2]
for i in range(_i+1):
    _j = (N - li[2]*i )//li[1]
    for j in range(_j + 1):
        if (N - i*li[2] -  j*li[1])%li[0] == 0:
            cnt += 1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B ,N = list(map(int, input().split(' ')))

cnt = 0

for i in range(N+1):
    for j in range(N+1):
        for k in range(N+1):
            if i*R + j*G + k*B == N:
                cnt += 1
print(cnt)
    

Fixed submission:
R, G, B ,N = list(map(int, input().split(' ')))

cnt = 0

li = [R, G, B]
li = sorted(li)

_i = N//li[2]
for i in range(_i+1):
    _j = (N - li[2]*i )//li[1]
    for j in range(_j + 1):
        if (N - i*li[2] -  j*li[1])%li[0] == 0:
            cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
import collections

def cal_divs(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)
    return divisors
  
def check(num, kouho, N, i):
  for val in kouho.keys():
    if num%val == 0:
      kouho[val] += 1
      
  return {k: v for k, v in kouho.items() if v > i-1}
  
  
N = int(input())
A= list(map(int, input().split()))
pri_flag = True

if N > 4:
  divs = []
  for i in range(3):
      divs.extend(cal_divs(A[i]))
  kouho = {}
  c = collections.Counter(divs)
  for div, n in c.most_common():
      kouho[div] = n

  kouho = {k: v for k, v in kouho.items() if v > 1}

  for i,num in enumerate(A[3:]):
    if len(kouho) == 1:
      print(1)
      pri_flag = False
      break
    kouho = check(num, kouho, N, i+3)

  if pri_flag:
      print(max(kouho))
else:
    divs = []
    kouho = {}
    for i in range(N):
        divs.extend(cal_divs(A[i]))
        c = collections.Counter(divs)
    for div, n in c.most_common():
        kouho[div] = n
    kouho = {k: v for k, v in kouho.items() if v > N-2}
    print(max(kouho))

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

print((T//A)*B)
Buggy python submission (verdict: Runtime Error):
N, K = list(map(int, input().split(' ')))
S = list(input())

size = []

now = S[0]
cnt = 1

END = False

for i in range(1,N,1):
  before = now
  now = S[i]
  if now == before:
    cnt += 1
  else:
    size.append(cnt)
    cnt = 1

size.append(cnt)

if 3*K > len(size):
  print(sum(size))
  END = True

max_sum = 0
max_sum2 = 0

if  S[0] == '0':
  start = 1
else:
  start = 0
  
if END:
  pass
else:
  for i in range(start,len(size),2):
    try:
      now_sum = sum(size[i:i+3*K])
      now_sum2 = sum(size[i+1:i+1+3*(K-1)])
      if max_sum < now_sum:
          max_sum = now_sum
      if max_sum2 < now_sum2:
          max_sum2 = now_sum2
    except:
      pass
  
  if max_sum2 > max_sum:
  	print(max_sum2)
  else:
    print(max_sum)


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

get_coin = 0

for _ in range(2):
  if A > B:
  	get_coin += A
  	A = A-1
  else:
    get_coin += B
    B = B-1
   
print(get_coin)

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

li = []
size = []

now = S[0]
cnt = 1

for i in range(1,N,1):
  before = now
  now = S[i]
  if now == before:
    cnt += 1
  else:
    li.append(before)
    size.append(cnt)
    cnt = 1

li.append(now)
size.append(cnt)

if 3*K > len(size):
  print(sum(size))
  END = True

max_sum = 0

if END:
  pass
else:
  for i in range(K):
    try:
      now_sum = sum(size[i:i+3*K])
      if max_sum < now_sum:
          max_sum = now_sum
    except:
      pass

  print(max_sum)

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

get_coin = 0

for _ in range(2):
  if A > B:
  	get_coin += A
  	A = A-1
  else:
    get_coin += B
    B = B-1
   
print(get_coin)
Buggy python submission (verdict: Runtime Error):
X, Y, Z, K = list(map(int, input().split(' ')))

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


A.sort()
A.reverse()
B.sort()
B.reverse()
C.sort()
C.reverse()

cal = []

def a(X,K):
  if X > K:
  	return K
  else:
    return X
  
for i in range(a(X,K-1000)):
  for j in range(a(Y,K-1000)):
    for k in range(a(Z,K-1000)):
      cal.append(A[i]+B[j]+C[k])

cal.sort()
cal.reverse()

for i in range(K):
  print(cal[i])


Fixed submission:
anntena_list = []
 
for i in range(5):
    anntena_list.append(int(input()))
    
m = int(input())
    
flag = False
for i in range(4):
  for j in range(3-i):
    if anntena_list[4-i] - anntena_list[j]  > m:
      flag = True
      
if flag:
  print(':(')
else:
  print('Yay!')
Buggy python submission (verdict: Time Limit Exceeded):
def trans(x1, A):
    if x1 >= A:
        return A
    else:
        return x1
      
N = int(input())
t = []

for i in range(5):
  t.append(int(input()))

 
x1 = N
x2, x3, x4, x5, x6 = 0, 0, 0, 0, 0

time = 0
while True:
    x2add = trans(x1, t[0])
    x3add = trans(x2, t[1])
    x4add = trans(x3, t[2])
    x5add = trans(x4, t[3])
    x6add = trans(x5, t[4])

    x1 -= x2add
    x2 += x2add
    
    x2 -= x3add
    x3 += x3add
    
    x3 -= x4add
    x4 += x4add
    
    x4 -= x5add
    x5 += x5add
    
    x5 -= x6add
    x6 += x6add
    
    time += 1
    if x6 == N:
        break

print(time)

Fixed submission:
import math

N = int(input())
t = []

for i in range(5):
  t.append(int(input()))

print(4 + math.ceil(N/min(t)))
Buggy python submission (verdict: Runtime Error):
import sys
day = sys.argv[1]
if day == '22':
 print('Christmas Eve Eve Eve')
elif day == '23':
 print('Christmas Eve Eve')
elif day == '24':
 print('Christmas Eve')
elif day == '25':
 print('Christmas')

Fixed submission:

day = input()
if day == '22':
 print('Christmas Eve Eve Eve')
elif day == '23':
 print('Christmas Eve Eve')
elif day == '24':
 print('Christmas Eve')
elif day == '25':
 print('Christmas')

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

day = sys.argv[1]
if day == '22'

 print('Christmas Eve Eve Eve')
elif day == '23'
 print('Christmas Eve Eve')
elif day == '24'
 print('Christmas Eve')
elif day == '25'
 print('Christmas')


Fixed submission:

day = input()
if day == '22':
 print('Christmas Eve Eve Eve')
elif day == '23':
 print('Christmas Eve Eve')
elif day == '24':
 print('Christmas Eve')
elif day == '25':
 print('Christmas')
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())

pre_n = n
while pre_n >= n:
  pre_n = n
  n = abs(n-k)
  
print(pre_n)

Fixed submission:
n,k = map(int, input().split())
print(min(n%k, abs(n%k-k)))
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q = list(map(int, input().split()))
win_lst = []
for i in range(q):
  winner = int(input())
  win_lst.append(winner)
#print(win_lst)
    
win_ct_lst = []
for j in range(1, n + 1):
  win_ct_lst.append(win_lst.count(j))
#print(win_ct_lst)

lose_pt_lst = []
for m in range(len(win_ct_lst)):
  lose_pt_lst.append(win_ct_lst[m] - sum(win_ct_lst))

for l in range(len(win_ct_lst)):
  if (k + lose_pt_lst[l] >= 1):
    print("Yes")
  else:
    print("No")


Fixed submission:
n,k,q = list(map(int, input().split()))
win_lst = []
for i in range(q):
  winner = int(input())
  win_lst.append(winner)

ct_lst = [0] * n
for x in win_lst:
  ct_lst[x-1] += 1

ttl = sum(ct_lst)
for y in ct_lst:
  if (k-ttl + y) >= 1:
    print("Yes")
  else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
n,k,q = list(map(int, input().split()))
win_lst = []
for i in range(q):
  winner = int(input())
  win_lst.append(winner)
#print(win_lst)
    
win_ct_lst = []
for j in range(1, n + 1):
  win_ct_lst.append(win_lst.count(j))
#print(win_ct_lst)

lose_pt_lst = []
for m in range(len(win_ct_lst)):
  lose_pt_lst.append(win_ct_lst[m] - sum(win_ct_lst))

for l in range(len(win_ct_lst)):
  if (k + lose_pt_lst[l] >= 1):
    print("Yes")
  else:
    print("No")


Fixed submission:
n,k,q = list(map(int, input().split()))
win_lst = []
for i in range(q):
  winner = int(input())
  win_lst.append(winner)

ct_lst = [0] * n
for x in win_lst:
  ct_lst[x-1] += 1

ttl = sum(ct_lst)
for y in ct_lst:
  if (k-ttl + y) >= 1:
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Runtime Error):
a,b = list(map(int, input()split()))
if a>=b:
  print(10)
else:
  print(0)

Fixed submission:
a,b = list(map(int, input().split()))
if a>=b:
  print(10)
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
a,b = list(map(int, input()split()))
if a>=b:
  print(19)
else:
  print(0)

Fixed submission:
a,b = list(map(int, input().split()))
if a>=b:
  print(10)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
n = int.input()

if n == 7 or n == 5 or n == 3:
  print("YES")
else:
  print("NO")

Fixed submission:
n = int(input())

if n == 7 or n == 5 or n == 3:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
l = map(int, raw_input().split())
n = l[0]
t = l[1]

"""
x = []
for i in range(n):
  x.append(map(int, raw_input().split()))
print(x)
"""

lst = [map(int, raw_input().split()) for i in range(n)]
#print(lst)

"""
minc = x[0]
mint = t

for j in range(n):
  if x[j][1] <= mint:
    mint = x[j][1]
    minc = x[j][0]
    #print("mint updated")
  else:
    continue

if mint < t:
  print(minc)
else:
  print("TLE")
"""

#sort_using lambda
lst = sorted(lst, key = lambda x:x[1])
#print(lst)

maxt = t
minc = 9999

for j in range(n + 10):
  if lst[j][1] <= maxt and lst[j][0] <= minc:
    minc = lst[j][0]
  else:
    break

"""
if maxt <= t:
  print(minc)
else:
  print("TLE")
"""

if minc == 9999:
  print("TLE")
else:
  print(minc)


Fixed submission:
lst = []
n = input()
if n == 1:
  print('Hello World')

else:
  for i in range(2):
    lst.append(input())
  print(lst[0] + lst[1])
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 18 21:48:15 2018

@author: nakag
"""
n = int(raw_input())
print(n)
#1からNまでで因数分解を行う
ans_lst = []

import math
for j in range(1,n+1):
    I=int(j)
    s=0
    R=int(I)
    L=[]
    while s==0:
        #R=int(math.sqrt(R))
        for i in range(2,R+1):
            if I%i==0:
                I=I/i
                if I==1:
                    s=1
                L.append(i)
                break
    print(len(L))

    #素数の数に応じて場合分け
    if len(L)==1:
        if L[0]**3 == j:
            ans_lst.append(1)
    
    elif len(L)==2:
        #約数が8のときとりえる場合の積を数える
        s1 = L[0] * L[1]**3
        s2 = L[0]**3 * L[1]
        if s1 == j:
            ans_lst.append(1)
        elif s2 ==j:
            ans_lst.append(1)
    elif len(L) ==3:
        s3 = L[0] * L[1] * L[2]
        if s3 == j:
            ans_lst.append(1)
    
    print(ans_lst)



Fixed submission:
l = map(int, raw_input().split())
#print(l)

s = (l[0] - 1) * (l[1] - 1)
print(s)
Buggy python submission (verdict: Runtime Error):
lst = map(int, raw_input().split())

print(max(lst)-min(lst

Fixed submission:
lst = map(int, raw_input().split())


print(max(lst)-min(lst))
Buggy python submission (verdict: Runtime Error):
n = input()
if n < 1000:
  print("ABC")
else:
  print("ABD")

Fixed submission:
n = int(input())
if n < 1000:
  print("ABC")
else:
  print("ABD")
Buggy python submission (verdict: Runtime Error):
print(int(input())%%3)

Fixed submission:
print(int(input())//3)
Buggy python submission (verdict: Runtime Error):
if a*b%2 == 0:
  print("Even")
else:
  print("Odd")

Fixed submission:
a,b = list(map(int, input().split()))
if a*b%2 == 0:
  print("Even")
else:
  print("Odd")
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n = int(raw_input())
l = []
for i in range(n):
  l.append(int(raw_input()))
#print(l)

flag = [0] *100
#print(flag)
for j in l:
  if flag[j] == 0:
    flag[j] = 1
#print(flag)

num = 0
for k in flag:
#  print(k)
  if k == 1:
    num += 1
print(num)

"""
##これだとエラーでる
##flag[k]だとflag[0]かflag[1]にしかならないことに注意
num = 0
for k in flag:
  print(flag[k])
  if flag[k] == 1:
    num += 1
print(num)
"""

Fixed submission:
s = input()
print(s[:3]+"8"+s[4:])
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n = int(raw_input())
l = []
for i in range(n):
  l.append(int(raw_input()))
#print(l)

flag = [0] *100
#print(flag)
for j in l:
  if flag[j] == 0:
    flag[j] = 1
#print(flag)

num = 0
for k in flag:
#  print(k)
  if k == 1:
    num += 1
print(num)

"""
##これだとエラーでる
##flag[k]だとflag[0]かflag[1]にしかならないことに注意
num = 0
for k in flag:
  print(flag[k])
  if flag[k] == 1:
    num += 1
print(num)
"""

Fixed submission:
# -*- coding: utf-8 -*-
n = int(raw_input())
l = []
for i in range(n):
  l.append(int(raw_input()))
#print(l)

flag = [0] *110
#print(flag)
for j in l:
  if flag[j] == 0:
    flag[j] = 1
#print(flag)

num = 0
for k in flag:
#  print(k)
  if k == 1:
    num += 1
print(num)

"""
##これだとエラーでる
##flag[k]だとflag[0]かflag[1]にしかならないことに注意
num = 0
for k in flag:
  print(flag[k])
  if flag[k] == 1:
    num += 1
print(num)
"""
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

print(int((a+b)/2) + 1)

Fixed submission:
a, b = list(map(int, input().split()))
import math
ans = math.ceil((a+b)/2)
print(ans)
"""
if a != b:
  print(int((a+b)/2) + 1)
else:
  print(a)
"""
Buggy python submission (verdict: Runtime Error):
a,b,c = list(map(int, input().split()))
print(min(a*b), c)

Fixed submission:
a,b,c = list(map(int, input().split()))
print(min(a*b, c))
Buggy python submission (verdict: Runtime Error):
x,y = list(map(int, input().split()))
if ord(x) < ord(y):
  print("<")
elif ord(x) > ord(y):
  print(">")
else:
  print("=")

Fixed submission:
x,y = input().split()
if ord(x) < ord(y):
  print("<")
elif ord(x) > ord(y):
  print(">")
else:
  print("=")
Buggy python submission (verdict: Runtime Error):
"""
a = "kanji"
for i in a:
  print(i)
"""

s = raw_input()
print(s)

ch_lst = "abcdefghijklmnopqrstqvwxyz"
#ch_lst = [chr(i) for i in range(ord('a'), ord('z')+1)]
print(ch_lst)

match = 0
for j in ch_lst:
  ch = s.find(j)
  if ch != -1:
    #print(ch)
  else:
    match = 1
    break

if match == 0:
  print("none")
elif match == 1:
  print(j)

Fixed submission:
s = raw_input()
#print(s)

ch_lst = "abcdefghijklmnopqrstqvwxyz"
#ch_lst = [chr(i) for i in range(ord('a'), ord('z')+1)]
#print(ch_lst)

match = 0
for j in ch_lst:
  ch = s.find(j)
  if ch != -1:
    continue
  else:
    match = 1
    break

if match == 0:
  print("None")
elif match == 1:
  print(j)
Buggy python submission (verdict: Runtime Error):
a,b = list(map(int, input().split()))
print(mod(a+b))

Fixed submission:
a,b = list(map(int, input().split()))
print((a+b)%24)
Buggy python submission (verdict: Runtime Error):
a,b = list(map(input().split()))
if a == "H" and b == "H":
    print("H")
elif a == "D" and b == "D":
    print("H")
else:
    print("D")

Fixed submission:
a,b = list(input().split())
if a == "H" and b == "H":
    print("H")
elif a == "D" and b == "D":
    print("H")
else:
    print("D")

Buggy python submission (verdict: Runtime Error):
a,b = list(map(int, input().split()))
if a == "H" and b == "H":
    print("H")
elif a == "D" and b == "D":
    print("H")
else:
    print("D")

Fixed submission:
a,b = list(input().split())
if a == "H" and b == "H":
    print("H")
elif a == "D" and b == "D":
    print("H")
else:
    print("D")
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
p=0
ans=set()
while(p!=(len(S)//2+1)):
    for i in range(p+3,len(S)+1):
        if int(S[p:i])%2019==0:
            ans.add((p,i))
        if int(S[len(S)-i:len(S)-p])%2019==0:
            ans.add((len(S)-i,len(S)-p))
    p+=1
print(len(ans))

Fixed submission:
s=input()
mod=2019
dp=[0]*mod
k=0
t=1
for x in map(int,s[::-1]):
    k+=t*x
    k%=mod
    dp[k]+=1
    t*=10
    t%=mod
print(sum(i*(i-1)//2 for i in dp)+dp[0])

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
p=0
cnt=0
while(p!=len(S)):
    for i in range(p+3,len(S)+1):
        if int(S[p:i])%2019==0:
            cnt+=1
    p+=1
print(cnt)

Fixed submission:
s=input()
mod=2019
dp=[0]*mod
k=0
t=1
for x in map(int,s[::-1]):
    k+=t*x
    k%=mod
    dp[k]+=1
    t*=10
    t%=mod
print(sum(i*(i-1)//2 for i in dp)+dp[0])

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
p=0
cnt=0
while(p!=len(S)):
    for i in range(p+1,len(S)+1):
        if int(S[p:i])%2019==0:
            cnt+=1
    p+=1
print(cnt)

Fixed submission:
s=input()
mod=2019
dp=[0]*mod
k=0
t=1
for x in map(int,s[::-1]):
    k+=t*x
    k%=mod
    dp[k]+=1
    t*=10
    t%=mod
print(sum(i*(i-1)//2 for i in dp)+dp[0])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
for i in range(N):
    print(A.count(i+1))

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
P=[0]*N
for i in range(N-1):
    P[A[i]-1]+=1
for i in range(N):
    print(P[i])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
for i in range(N):
    print(A.count(i+1))

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
P=[0]*N
for i in range(N-1):
    P[A[i]-1]+=1
for i in range(N):
    print(P[i])

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
for i in range(N):
    print(A.count(i+1)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
P=[0]*N
for i in range(N-1):
    P[A[i]-1]+=1
for i in range(N):
    print(P[i])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
pre=0
for i in range(N-1):
    if A[i]!=pre:
        print(A.count(i+1))
    else:
        print(0)
        pre=A[i]
print(0)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
P=[0]*N
for i in range(N-1):
    P[A[i]-1]+=1
for i in range(N):
    print(P[i])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
s=[]
for i in range(N-1):
    if A[i] not in s:
        print(A.count(i+1))
        s.append(i)
    else:
        print(0)
print(0)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
P=[0]*N
for i in range(N-1):
    P[A[i]-1]+=1
for i in range(N):
    print(P[i])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
s=set()
for i in range(N-1):
    if A[i] not in s:
        print(A.count(i+1))
    else:
        print(0)
print(0)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
P=[0]*N
for i in range(N-1):
    P[A[i]-1]+=1
for i in range(N):
    print(P[i])
Buggy python submission (verdict: Time Limit Exceeded):
import math
N=int(input())
ans=0
for a in range(1,N+1):
    for b in range(1,N+1):
        for c in range(1,N+1):
            ans+=math.gcd(math.gcd(a,b),c)
print(ans)

Fixed submission:
import math
N=int(input())
g1=[math.gcd(x,y) for x in range(1,N+1) for y in range(1,N+1)]
g2=[math.gcd(x,y) for x in g1 for y in range(1,N+1)]
print(sum(g2))