Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n,m=map(int, input().split())
a = 0
b = 0
if n != 1:
  a = cmb(n, 2)  
if m != 1:
  b = cmb(m,2)
print(a+b)

Fixed submission:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n,m=map(int, input().split())
a = 0
b = 0
if n > 1:
  a = cmb(n, 2)  
if m > 1:
  b = cmb(m,2)
print(a+b)

Buggy python submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n,m=map(int, input().split())
a = cmb(n, 2)
b = 0
if m != 1:
  b = cmb(m,2)
print(a+b)


Fixed submission:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n,m=map(int, input().split())
a = 0
b = 0
if n > 1:
  a = cmb(n, 2)  
if m > 1:
  b = cmb(m,2)
print(a+b)
Buggy python submission (verdict: Runtime Error):
M,D = map(int,input().split())

if D < 22:
  print("0")
  exit()

count = 0
  
for m in range(1,M+1):
  for d in range(22,N+1):
    if int(str(d)[1]) < 2:
      continue
   	if int(str(d)[0]) * int(str(d)[1]) == m:
      count += 1
print(count)

Fixed submission:
M,D = map(int,input().split())

if D < 22:
  print("0")
  exit()

count = 0

for m in range(1,M+1):
  for d in range(22,D+1):
    if int(str(d)[1]) < 2:
      continue
    if int(str(d)[0]) * int(str(d)[1]) == m:
      count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())

sn = []
count = 0

for i in range(n):
  sn.append(sorted(Counter(list(input())).items()))


for i in range(n - 1):
  for j in range(i+1,n):
    if sn[i] == sn[j]:
      count += 1
print(count)

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

l = [a+b,a-b,a*b]

print(max(l))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

l = []

for i in range(n):
  l.append(int(input()))

m = max(l)

if l.count(m) >= 2:
  for i in range(n):
    print(m)
  exit()

for i in range(n):
  tmp = l.pop(i)
  
  if tmp != m:
    print(m)
    l.insert(i,tmp)
    continue
  
  print(max(l))
  l.insert(i,tmp)
  

Fixed submission:
n = int(input())

l = []

for i in range(n):
  l.append(int(input()))

m = max(l)

if l.count(m) >= 2:
  for i in range(n):
    print(m)
  exit()

index = l.index(m)  

l.pop(index)

for i in range(n):
  if i == index:
  	print(max(l))
  else:
    print(m)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

l = []

for i in range(n):
  l.append(int(input()))

m = max(l)
  
for i in range(n):
  tmp = l.pop(i)
  
  if tmp != m:
    print(m)
    l.insert(i,tmp)
    continue
  
  print(max(l))
  l.insert(i,tmp)
  

Fixed submission:
n = int(input())

l = []

for i in range(n):
  l.append(int(input()))

m = max(l)

if l.count(m) >= 2:
  for i in range(n):
    print(m)
  exit()

index = l.index(m)  

l.pop(index)

for i in range(n):
  if i == index:
  	print(max(l))
  else:
    print(m)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

l = []

for i in range(n):
  l.append(int(input()))

for i in range(n):
  tmp = l.pop(i)
  print(max(l))
  l.insert(i,tmp)
  

Fixed submission:
n = int(input())

l = []

for i in range(n):
  l.append(int(input()))

m = max(l)

if l.count(m) >= 2:
  for i in range(n):
    print(m)
  exit()

index = l.index(m)  

l.pop(index)

for i in range(n):
  if i == index:
  	print(max(l))
  else:
    print(m)
Buggy python submission (verdict: Runtime Error):
n,m=map(int, input().split())
h=list(map(int, input().split()))
root=[list(map(int,input().split()))  for _ in range(m)]

ans=0
lis=[1 for _ in range(n)]

for i in range(len(root)):
    a=root[i][0]
    b=root[i][1]
    if h[a-1] > h[b-1]:
        lis[b-1]=0
    elif h[a-1]< h[b-1]:
        lis[a-1]=0
    else:
        lis[a-1],lis[b-1]=0

ans=sum(lis)
print(ans)

Fixed submission:
n,m=map(int, input().split())
h=list(map(int, input().split()))
root=[list(map(int,input().split()))  for _ in range(m)]

ans=0
lis=[1 for _ in range(n)]

for i in range(len(root)):
    a=root[i][0]
    b=root[i][1]
    if h[a-1] > h[b-1]:
        lis[b-1]=0
    elif h[a-1]< h[b-1]:
        lis[a-1]=0
    else:
        lis[a-1]=0
        lis[b-1]=0

ans=sum(lis)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=0

for i in range(1,n+1):
   b=a.count(i)
   print(b)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[0 for _ in range(n)]

for i in range(0,len(a)):
   b[a[i]-1]+=1
[print(i) for i in b]
Buggy python submission (verdict: Runtime Error):
n=input()

    if  '7' in n:
        print('Yes')
    else:
        print('No')

Fixed submission:
def resolve():
    n=input()

    if  '7' in n:
        print('Yes')
    else:
        print('No')
if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
ef resolve():
    n=int(input())
    ans=0

    for i in range(n+1):
        if i%3!=0 and i%5!=0:
            ans+=i
    print(ans)
if __name__ == "__main__":
    resolve()

Fixed submission:
def resolve():
    n=int(input())
    ans=0

    for i in range(n+1):
        if i%3!=0 and i%5!=0:
            ans+=i
    print(ans)
if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
n=int(input())
d=list(map(int,input().split()))
ans=1
a=1
b=1
d=sorted(d)
if d[0]!=0 or d[1]==0:
    ans=0
else:
    if d[-1]==d[-2]:
        for i in range(1,n-1):
            if d[i]==d[i+1]:
                a+=1
            else:
                ans=ans*(b**a)
                b=a
                a=1
    else:
        for j in range(1,n-1):
            if d[i]==d[i+1]:
                a+=1
            else:
                ans=ans*(b**a)
                b=a
                a=1
            ans=ans*b
ans=ans%998244353
print(ans)
      

Fixed submission:
n=int(input())
d=list(map(int,input().split()))
ans=1
a=1
b=1
if n==1 or d[0]!=0:
    ans=0
d=sorted(d)
for j in range(0,n-1):
        if d[j+1]-d[j]>1:
            ans=0
            break
        
if d[0]!=0 or d[1]==0:
    ans=0
else:
    for i in range(1,n-1):
        if d[i]==d[i+1]:
            a+=1
        else:
            ans=ans*(b**a)
            b=a
            a=1
ans=ans*(b**a)
ans=ans%998244353
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b=list(map(int,input().split()))
if a<=b*2:
  print 0
else:
  print a-b*2

Fixed submission:
a,b=list(map(int,input().split()))
if a<=b*2:
  print(0)
else:
  print(a-b*2)
Buggy python submission (verdict: Runtime Error):
N=input()
stu=list(map(int,input().split()))
stu2=list(range(8))
for i in range(N):
  for j in range(N):
    if stu[i]==j:
      stu2[j-1]=i+1
print(stu2)


Fixed submission:
N=int(input())
stu=list(map(int,input().split()))
stu2=list(range(N))
for i in range(N):
    stu2[stu[i]-1]=i+1
print(*stu2,end=' ')

Buggy python submission (verdict: Runtime Error):
N=input()
stu=list(map(int,input().split()))
lis=[x for x in range(N)]
for i in range(N):
  for j in range(N):
    if stu[i]==j:
      lis[j-1]=i+1
print(lis)

Fixed submission:
N=int(input())
stu=list(map(int,input().split()))
stu2=list(range(N))
for i in range(N):
    stu2[stu[i]-1]=i+1
print(*stu2,end=' ')
Buggy python submission (verdict: Runtime Error):
S=input('')
if S='Sunny':
  print('Cloudy')
elif S='Cloudy':
  print('Rainy')
else:
  print('Sunny')

Fixed submission:
S=input('')
if S=='Sunny':
  print('Cloudy')
elif S=='Cloudy':
  print('Rainy')
else:
  print('Sunny')
Buggy python submission (verdict: Runtime Error):
S=input()
for i in range(0,int(len(S)):
  if S[2*i]!='L' and S[2*i+1]!='R':
    print('Yes')
  else:
    print('No')

Fixed submission:
S=input()
ans='Yes'

for i in range(0,int(len(S))):
  if i%2==0:
    if S[i]=='L':
        ans='No'
        break
  elif i%2==1:
    if S[i]=='R':
        ans='No'
        break
print(ans)

Buggy python submission (verdict: Runtime Error):
S=input()
for i in range(int(S)):
  if S[2i]!='L' and S[2i+1]!='R':
    print('Yes')
  else:
    print('No')

Fixed submission:
S=input()
ans='Yes'

for i in range(0,int(len(S))):
  if i%2==0:
    if S[i]=='L':
        ans='No'
        break
  elif i%2==1:
    if S[i]=='R':
        ans='No'
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
co=0
for i in range(len(B)):
    co+=B[i]
for j in range(len(C)):
    if A[j+1]==A[j]+1:
        co+=C[A[j]]
print(co)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
co=0
for i in range(len(B)):
    co+=B[i]
for j in range(len(C)):
    if A[j+1]==A[j]+1:
        co+=C[A[j]-1]
print(co)
Buggy python submission (verdict: Runtime Error):
S,T=input()
for i in range(0,len(S)):
  cr=0
  if S[i]==T[i]:
    cr+=1
print(cr)


Fixed submission:
s=input()
t=input()
cr=0
for i in range(3):
  if s[i]==t[i]:
    cr+=1
print(cr)

Buggy python submission (verdict: Runtime Error):
S,T=input().split()
for i in range(0,len(S)):
  cr=0
  if S[i]==T[i]:
    cr+=1
print(cr)

Fixed submission:
s=input()
t=input()
cr=0
for i in range(3):
  if s[i]==t[i]:
    cr+=1
print(cr)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
re=0
for i in A:
  re+=1/A[i]
print(1/re)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
re=0
for i in range(N):
  re+=1/A[i]
print(1/re)
Buggy python submission (verdict: Runtime Error):
A,B=int(input()),int(input())
print(max[A+B,A-B,A*B])

Fixed submission:
A,B=list(map(int,input().split()))
print(max(A+B,A-B,A*B))
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
N=input()
ans=0
if N<=9:
  ans=N
elif 10<=N<=99:
  ans=10
elif 100<=N<=999:
  ans=9+(N-99)
elif 1000<=N<=9999:
  ans=909
elif 10000<=N<=99999:
  ans=909+(N-9999)
else:
  ans=90909
print(ans)

Fixed submission:
import sys
input=sys.stdin.readline
N=int(input())
ans=0
if N<=9:
  ans=N
elif 10<=N<=99:
  ans=9
elif 100<=N<=999:
  ans=9+(N-99)
elif 1000<=N<=9999:
  ans=909
elif 10000<=N<=99999:
  ans=909+(N-9999)
else:
  ans=90909
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
N=input()
if N<=9:
  print(N)
elif 10<=N<=99:
  print(10)
elif 100<=N<=999:
  print(9+(N-99))
elif 1000<=N<=9999:
  print(909)
elif 10000<=N<=99999:
  print(909+(N-9999))
else:
  print(90909)


Fixed submission:
import sys
input=sys.stdin.readline
N=int(input())
ans=0
if N<=9:
  ans=N
elif 10<=N<=99:
  ans=9
elif 100<=N<=999:
  ans=9+(N-99)
elif 1000<=N<=9999:
  ans=909
elif 10000<=N<=99999:
  ans=909+(N-9999)
else:
  ans=90909
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
N=input()
if N<=9:
  print(N)
elif N<=99:
  print(10)
elif N<=999:
  print(9+(N-99))
elif N<=9999:
  print(909)
elif N<=99999:
  print(909+(N-9999))
else:
  print(90909)

Fixed submission:
import sys
input=sys.stdin.readline
N=int(input())
ans=0
if N<=9:
  ans=N
elif 10<=N<=99:
  ans=9
elif 100<=N<=999:
  ans=9+(N-99)
elif 1000<=N<=9999:
  ans=909
elif 10000<=N<=99999:
  ans=909+(N-9999)
else:
  ans=90909
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
a,b=int(input())
if (a+b)%2==0:
  print((a+b)/2)
else:
  print('impossible')


Fixed submission:
a,b=map(int, input().split())
print (int((a+b)/2) if (a+b)%2 == 0 else "IMPOSSIBLE")

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
a,b=int(input())
if a+b%2==0:
  print((a+b)/2)
else:
  print('impossible')

Fixed submission:
a,b=map(int, input().split())
print (int((a+b)/2) if (a+b)%2 == 0 else "IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
N=int(input())
p=list(map(int,input().split()))
co=0
ans='YES'
for i in range(N):
  if p[i]!=i+1:
    co+=1
if co<=1:
  break
else:
  ans='NO'
print(ans)

Fixed submission:
N=int(input())
p=list(map(int,input().split()))
np=sorted(p)
co=0
ans='YES'
for i in range(N):
  if p[i]!=np[i]:
    co+=1
if co<=2:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
r,l=map(int,input().split())
v1,v2=r//2019,l//2019
if v2-v1>=1 or r%2019==0 or l%2019==0:
    print(0)
else:
    ans=2018
    for i in range(r,l):
        for j in range(i+1,l+1):
            ans=min(ans,(i*j)%2019)
print(ans)

Fixed submission:
r,l=map(int,input().split())
v1,v2=r//2019,l//2019
if v2-v1>=1 or r%2019==0 or l%2019==0:
    print(0)
else:
    ans=2018
    for i in range(r,l):
        for j in range(i+1,l+1):
            ans=min(ans,(i*j)%2019)
    print(ans)

Buggy python submission (verdict: Runtime Error):
r,l=map(int,input().split())
if l-r>=2019 or r%2019==0 or l%2019==0:
    print(0)
else:
    ans=2018
    for i in range(r,l):
        for j in range(i+1,l+1):
            ans=min(ans,(i*j)%2019)
print(ans)

Fixed submission:
r,l=map(int,input().split())
v1,v2=r//2019,l//2019
if v2-v1>=1 or r%2019==0 or l%2019==0:
    print(0)
else:
    ans=2018
    for i in range(r,l):
        for j in range(i+1,l+1):
            ans=min(ans,(i*j)%2019)
    print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
s2=sorted(s)
if s2[0]==s2[1] and s2[2]==s2[3] and s2[1]!=s2[2]
  print('Yes')
else:
  print('No')

Fixed submission:
s=input()
s2=sorted(s)
if s2[0]==s2[1] and s2[2]==s2[3] and s2[1]!=s2[2]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
s=input()
ans=0
if t[0]==t[1] or t[1]==t[2] or t[2]==t[3]:
    ans='Bad'
else:
    ans='Good'
print(ans)

Fixed submission:
t=input()
ans=0
if t[0]==t[1] or t[1]==t[2] or t[2]==t[3]:
    ans='Bad'
else:
    ans='Good'
print(ans)

Buggy python submission (verdict: Runtime Error):
s=int(input())
n=str(s)
t=list(map(int,n))
ans=0
if t[0]==t[1] or t[1]==t[2] or t[2]==t[3]:
    ans='Bad'
else:
    ans='Good'
print(ans)

Fixed submission:
t=input()
ans=0
if t[0]==t[1] or t[1]==t[2] or t[2]==t[3]:
    ans='Bad'
else:
    ans='Good'
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
b=[0]*(n+1)
b[0]=1
if 1 not in a:
    b[1]=1
for i in range(2,n+1):
    if i in a:
        b[i]=0 
    else:
        b[i]=b[i-1]+b[i-2]
print(b[-1]%1000000007)

Fixed submission:
n, m = map(int, input().split())
a = set()
for i in range(m):
    a.add(int(input()))

b = [0] * (n + 1)
b[0] = 1
if 1 not in a:
    b[1] = 1
for i in range(2, n + 1):
    if i in a:
        b[i] = 0
    else:
        b[i] = b[i - 1] + b[i - 2]
print(b[n] % 1000000007)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split()))
a=[int(input()) for i in range(m)]
b=[0]*(n+1)
b[0]=1
if 1 not in a:
    b[1]=1
for i in range(2,n+1):
    if i in a:
        b[i]=0 #0の代入で2連続以上の場合もカバー
    else:
        b[i]=b[i-1]+b[i-2]
print(b[-1]%1000000007)

Fixed submission:
n, m = map(int, input().split())
a = set()
for i in range(m):
    a.add(int(input()))

b = [0] * (n + 1)
b[0] = 1
if 1 not in a:
    b[1] = 1
for i in range(2, n + 1):
    if i in a:
        b[i] = 0
    else:
        b[i] = b[i - 1] + b[i - 2]
print(b[n] % 1000000007)
Buggy python submission (verdict: Runtime Error):
n=int(input())
sp_lis=[]
for i in range(n):
    s,p=input().split()
    sp_lis.append([s,100-int(p),i+1])
for j in range(n):
    print(sorted(sp_lis[j][2]))

Fixed submission:
n=int(input())
sp_lis=[]
for i in range(n):
    s,p=input().split()
    sp_lis.append([s,100-int(p),i+1])
sp_lis.sort()
for j in range(n):
    print(sp_lis[j][2])

Buggy python submission (verdict: Runtime Error):
n=int(input())
sp_lis=[]
for i in range(n):
    s,p=input().split()
    sp_lis.append([s,100-p,i+1])
sp_lis.sort()
for j in range(n):
    print(sp_lis[j][2])

Fixed submission:
n=int(input())
sp_lis=[]
for i in range(n):
    s,p=input().split()
    sp_lis.append([s,100-int(p),i+1])
sp_lis.sort()
for j in range(n):
    print(sp_lis[j][2])

Buggy python submission (verdict: Runtime Error):
n=int(input())
sp_lis=[]
for i in range(n):
    s,p=input().split()
    sp_lis.append([s,100-p,i+1])
for j in range(n):
    print(sorted(sp_lis[j][2]))

Fixed submission:
n=int(input())
sp_lis=[]
for i in range(n):
    s,p=input().split()
    sp_lis.append([s,100-int(p),i+1])
sp_lis.sort()
for j in range(n):
    print(sp_lis[j][2])

Buggy python submission (verdict: Runtime Error):
n=int(input())
sp_lis=[]
s,p=input().split()
for i in range(1,n+1):
  sp_lis.append([s,100-p,i])
for j in range(n)
print(sorted(sp_lis[j][2]))

Fixed submission:
n=int(input())
sp_lis=[]
for i in range(n):
    s,p=input().split()
    sp_lis.append([s,100-int(p),i+1])
sp_lis.sort()
for j in range(n):
    print(sp_lis[j][2])
Buggy python submission (verdict: Runtime Error):
n = input()
h = (2,4,5,7,9)
p = (0,1,6,8)
b = 3
m = int(n) % 10
if m in b:
  print("bon")
if m in p:
  print("pon")
if m == h:
  print("hon")

Fixed submission:
n = input()
h = (2,4,5,7,9)
p = (0,1,6,8)
b = 3
m = int(n) % 10
if m in h:
  print("hon")
if m in p:
  print("pon")
if m == b:
  print("bon")
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d = input().split(" ")
a = int(a)
b = int(b)
c = int(c)
d = int(d)
t1 = 30* + 0.5*d
t2 = 6*d
print(t1,t2)
print(sqrt(e))

Fixed submission:
import math
a,b,c,d = input().split(" ")
a = int(a)
b = int(b)
c = int(c)
d = int(d)
t1 = 30*c + 0.5*d
t2 = 6*d
e = math.cos(math.radians(t1-t2))
f = a*a + b*b - 2*a*b*e
print(f ** 0.5)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
N=len(S)

m=[0]*(N+1)

for i in range(1,N+1):
  m[i]=int(S[i-1:N]) % 2019

dic={}
for i in range(1,N+1):
  if m[i] in dic:
    dic[m[i]].append(i)
  else:
    dic[m[i]]=[i]

c=0
for k,v in dic.items():
  if k == 0:
    c+=len(v)
  else:
    c+=int(len(v)*(len(v)-1)/2)
print(c)

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
N=len(S)

m=[0]*(N+1)

for i in range(1,N+1):
  m[i]=int(S[i-1:N]) % 2019

dic={}
for i in range(1,N+1):
  if m[i] in dic:
    dic[m[i]].append(i)
  else:
    dic[m[i]]=[i]

c=0
for k,v in dic.items():
  if k == 0:
    c+=len(v)
  else:
    c+=int(len(v)*(len(v)-1)/2)
print(c)

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
S=input()

N=len(S)
n=0
for i in range(N-3):
  for j in range(i+3,N):
    if int(S[i:j+1]) % 2019 == 0:
      n+=1
print(n)

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
S=input()

N=len(S)
n=0
for i in range(N-3):
  for j in range(i+3,N):
    if int(S[i:j+1]) % 2019 == 0:
      n+=1
print(n)

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力
Buggy python submission (verdict: Time Limit Exceeded):
import math

K=int(input())
sum=0

for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      sum+=math.gcd(math.gcd(i,j),k)

        
print(sum)

Fixed submission:
import math

K=int(input())
sum=0

for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      sum+=math.gcd(math.gcd(i,j),k)

        
print(sum)

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

K=200
sum=0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            sum+=fractions.gcd(i,fractions.gcd(j,k))
print(sum)

Fixed submission:
import math

K=int(input())
sum=0

for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      sum+=math.gcd(math.gcd(i,j),k)

        
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

for k in range(N):
  a=A[:k]+A[k+1:]
  a.sort()
  gr=itertools.groupby(a)
  s=0
  for _,group in gr:
    l=len(list(group))
    if l>=2:
      s+=int(l*(l-1)/2)
  print(s)

Fixed submission:
import itertools

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

gr=itertools.groupby(sorted(A))
s=0
dic={}
for x,group in gr:
  l=len(list(group))
  if l >= 2:
    s+=l*(l-1)/2
  dic[x]=l

for k in range(N):
  l=dic[A[k]]
  if l >= 2:
    print(int(s-l*(l-1)/2+(l-1)*(l-2)/2))
  else:
    print(int(s))

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

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

for k in range(N):
  a=A[:k]+A[k+1:]
  a.sort()
  gr=itertools.groupby(a)
  s=0
  for _,group in gr:
    l=len(list(group))
    if l>=2:
      s+=int(l*(l-1)/2)
  print(s)

Fixed submission:
import itertools

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

gr=itertools.groupby(sorted(A))
s=0
dic={}
for x,group in gr:
  l=len(list(group))
  if l >= 2:
    s+=l*(l-1)/2
  dic[x]=l

for k in range(N):
  l=dic[A[k]]
  if l >= 2:
    print(int(s-l*(l-1)/2+(l-1)*(l-2)/2))
  else:
    print(int(s))
Buggy python submission (verdict: Runtime Error):
2000 20000000

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

Y=int(Y/1000)
A=B=C=-1

for c in range(N+1):
  for b in range(N+1):
    a=N-b-c
    if c+5*b > Y:
      break
    if c+5*b+10*a == Y:
      A,B,C=a,b,c
      
print(A,B,C)
Buggy python submission (verdict: Runtime Error):
N,H=map(int,input().split())

a=[0]*N
b=[0]*N
for i in range(N):
  a[i],b[i]=map(int,input().split())

amax=max(a)
n=0
total=0
b.sort(reverse=True)
for i in range(N):
  if b[i] > amax:
    n+=1
    total+=b[i]
  else:
    break

if H <= total:
  for i in range(n):
    H-=b[i]
    if H <＝0:
      print(i+1)
      break
else:
  print(n+int((H-total-1)/amax)+1)

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

a=[0]*N
b=[0]*N
for i in range(N):
  a[i],b[i]=map(int,input().split())

amax=max(a)
n=0
total=0
b.sort(reverse=True)
for i in range(N):
  if b[i] > amax:
    n+=1
    total+=b[i]
  else:
    break

if H <= total:
  for i in range(n):
    H-=b[i]
    if H <= 0:
      print(i+1)
      break
else:
  print(n+int((H-total-1)/amax)+1)