Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
S=input()
ans=0
for i in range(len(S)):
    cnt=0
    k=i
    while True:
        if S[k] in ["A","C","G","T"] and k<len(S):
            cnt+=1
            k+=1
        else:
            if cnt>ans:
                ans=cnt
            break
print(ans)

Fixed submission:
S=input()
ans=0
for i in range(len(S)):
    cnt=0
    while True:
        if  i>=len(S):
            break
        elif S[i] not in ["A","C","G","T"]:
            break
        else:
            cnt+=1
            i+=1    
    if cnt>ans:
        ans=cnt
print(ans)

Buggy python submission (verdict: Runtime Error):
S=input()
ans=0
for i in range(len(S)):
    cnt=0
    while True:
        if S[i] in ["A","C","G","T"] and i<len(S):
            cnt+=1
            i+=1
        else:
            if cnt>ans:
                ans=cnt
            break
print(ans)

Fixed submission:
S=input()
ans=0
for i in range(len(S)):
    cnt=0
    while True:
        if  i>=len(S):
            break
        elif S[i] not in ["A","C","G","T"]:
            break
        else:
            cnt+=1
            i+=1    
    if cnt>ans:
        ans=cnt
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy
s=list(input())
t=list(input())
dp=[["" for _ in range(len(t)+1)] for _ in range(len(s)+1)]
for i in range(len(s)):
    for j in range(len(t)):
        if s[i]==t[j]:
            list=[dp[i][j]+s[i],dp[i+1][j],dp[i][j+1]]
            index=numpy.argmax([len(item) for item in list])
            dp[i+1][j+1]=list[index]
        else:
            list=[dp[i][j],dp[i+1][j],dp[i][j+1]]
            index=numpy.argmax([len(item) for item in list])
            dp[i+1][j+1]=list[index]
print(dp[len(s)][len(t)])

Fixed submission:
s=list(input())
t=list(input())
dp=[[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i]==t[j]:
            dp[i+1][j+1]=max(dp[i][j]+1,dp[i+1][j],dp[i][j+1])
        else:
            dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1])

path=[]

lens=len(s)
lent=len(t)
while lens>-1 and lent>-1 :
    if dp[lens][lent]==dp[lens-1][lent]:
        lens-=1
    elif dp[lens][lent]==dp[lens][lent-1]:
        lent-=1
    else:
        path.append(lens)
        lens-=1
        lent-=1

path.sort()
if path==[]:
    print("")
else:
    for i in path:
    	print(s[i-1],end="")

Buggy python submission (verdict: Runtime Error):
import numpy
s=list(input())
t=list(input())
dp=[["" for _ in range(len(t)+1)] for _ in range(len(s)+1)]
for i in range(len(s)):
    for j in range(len(t)):
        if s[i]==t[j]:
            list=[dp[i][j]+s[i],dp[i+1][j],dp[i][j+1]]
            index=numpy.argmax([len(item) for item in list])
            dp[i+1][j+1]=list[index]
        else:
            list=[dp[i][j],dp[i+1][j],dp[i][j+1]]
            index=numpy.argmax([len(item) for item in list])
            dp[i+1][j+1]=list[index]
print(dp[len(s)][len(t)])

Fixed submission:
s=list(input())
t=list(input())
dp=[[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i]==t[j]:
            dp[i+1][j+1]=max(dp[i][j]+1,dp[i+1][j],dp[i][j+1])
        else:
            dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1])

path=[]

lens=len(s)
lent=len(t)
while lens>-1 and lent>-1 :
    if dp[lens][lent]==dp[lens-1][lent]:
        lens-=1
    elif dp[lens][lent]==dp[lens][lent-1]:
        lent-=1
    else:
        path.append(lens)
        lens-=1
        lent-=1

path.sort()
if path==[]:
    print("")
else:
    for i in path:
    	print(s[i-1],end="")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
cnt=0
for i in range(1,N+1):
    s=str(i)
    if "3" in s and "5" in s and "7" in s:
        if len(set(s))==3:
            cnt+=1
print(cnt)


Fixed submission:
N=int(input())
import queue
que=queue.Queue()
que.put(3);que.put(5);que.put(7)
num=[3,5,7]
cnt=0
while not que.empty():
    v=que.get()
    for n in num:
        nv=v*10+n
        if nv<=N:
            que.put(nv)
            nv_str=str(nv)
            if "3" in nv_str and "5" in nv_str and "7" in nv_str and len(set(nv_str))==3:
                cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
# ABC 087 B Coins
A=input()
B=input()
C=input()
X=input()

cnt=0
for a in range(A):
    if 500*a >X:
        break
    else:
        for b in range(B):
            if 500*a + 100*b >X:
                break
            elif (X-500*a-100*b)/50<=C:
                cnt+=1
            else:
                continue
print(cnt)


Fixed submission:
i = [int(input()) for i in range(4)]
A=i[0]
B=i[1]
C=i[2]
X=i[3]

cnt=0
for a in range(A+1):
    if 500*a >X:
        break
    else:
        for b in range(B+1):
            if 500*a + 100*b >X:
                break
            elif (X-500*a-100*b)/50<=C:
                cnt+=1
            else:
                continue
print(cnt)
Buggy python submission (verdict: Runtime Error):
N=int(input())
des=[list(map(int,input().split())) for _ in range(N)]
des.insert(0,[0,0,0])
for i in range(N):
    time=des[i+1][0]-des[i][0]
    d_x=abs(des[i+1][1]-des[i][1])
    d_y=abs(des[i+1][2]-des[i][2])
    if (time-(d_x+d_y))%2!=0 and time>=(d_x+d_y)
        print("No")
        exit()
print("Yes")

Fixed submission:
N=int(input())
des=[list(map(int,input().split())) for _ in range(N)]
des.insert(0,[0,0,0])
for i in range(N):
    time=des[i+1][0]-des[i][0]
    d_x=abs(des[i+1][1]-des[i][1])
    d_y=abs(des[i+1][2]-des[i][2])
    if (time-(d_x+d_y))%2!=0 or time<(d_x+d_y):
        print("No")
        exit()
print("Yes")
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
S1,S2=input().split("-")
if len(S1)==A and len(S2)==B:
    print("Yes")
else:
    print("No")

Fixed submission:
A,B=map(int,input().split())
S=input()
if S.count("-")==1 and S.index("-")==A:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
s=input()
counter=0
if s[0]=1:
    counter+=1
if s[1]=1:
    counter+=1
if s[2]=1:
    counter+=1
print(counter)

Fixed submission:

s=input()
list0=["000"]
list1=["100","010","001"]
list2=["110","101","011"]
list3=["111"]
if s in list0:
    print(0)
if s in list1:
    print(1)
if s in list2:
    print(2)
if s in list3:
    print(3)

Buggy python submission (verdict: Runtime Error):
s=input()
list0=[000]
list1=[100,010,001]
list2=[110,101,011]
list3=[111]
if s in list0:
    print(0)
if s in list1:
    print(1)
if s in list2:
    print(2)
if s in list3:
    print(3)

Fixed submission:

s=input()
list0=["000"]
list1=["100","010","001"]
list2=["110","101","011"]
list3=["111"]
if s in list0:
    print(0)
if s in list1:
    print(1)
if s in list2:
    print(2)
if s in list3:
    print(3)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(x) for x in input().split()]
counter=0
while True:
    z=2**(counter+1)
    for i in range(n):
        if a[i]%z==0:
        else :
            print(counter)
            break
    counter+=1

Fixed submission:
N = int(input())
a = [int(x) for x in input().split()]
cnt=0
Flag=True
while(Flag):
    for i in range(N):
        if a[i]%2!=0:
            Flag=False
            break
        a[i]/=2
    cnt+=1
print(cnt-1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]
counter=0
while True:
    for i in range(n):
        if a[i]%2==0:
            a[i]=a[i]/2
        else :
            print(counter)
            break
    counter+=1

Fixed submission:
N = int(input())
a = [int(x) for x in input().split()]
cnt=0
Flag=True
while(Flag):
    for i in range(N):
        if a[i]%2!=0:
            Flag=False
            break
        a[i]/=2
    cnt+=1
print(cnt-1)

Buggy python submission (verdict: Runtime Error):
a = [int(x) for x in input().split()]
d=0
while True:
    c=0
    for i in range(n):
        if a[i]%2==0:
            a[i]=a[i]/2
            c+=1
    if c==0:
        break
    else:
        d+=1
print(d-1)


Fixed submission:
N = int(input())
a = [int(x) for x in input().split()]
cnt=0
Flag=True
while(Flag):
    for i in range(N):
        if a[i]%2!=0:
            Flag=False
            break
        a[i]/=2
    cnt+=1
print(cnt-1)

Buggy python submission (verdict: Runtime Error):
a = [int(x) for x in input().split()]
d=0
while True:
    c=0
    for i in range(n):
        if a[i]%2==0:
            a[i]=a[i]/2
            c+=1
    if c==0:
        break
    else:
        d+=1
print(d)

Fixed submission:
N = int(input())
a = [int(x) for x in input().split()]
cnt=0
Flag=True
while(Flag):
    for i in range(N):
        if a[i]%2!=0:
            Flag=False
            break
        a[i]/=2
    cnt+=1
print(cnt-1)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
B_reverse=B[::-1]
C=sorted(list(map(int,input().split())))
cnt=0
dict={}
val=0
for b in B_reverse:
    c_min=bisect(C,b)
    val+=len(C[c_min:])
    dict[b]=val
for a in A:
    b_min=bisect(B,a)
    if b_min==len(B):
        pass
    else:
        cnt+=dict[B[b_min]]
print(cnt)

Fixed submission:
from bisect import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
B_reverse=B[::-1]
C=sorted(list(map(int,input().split())))
cnt=0
dict={}
val=0
for b in B_reverse:
    c_min=bisect(C,b)
    val+=N-c_min
    dict[b]=val
for a in A:
    b_min=bisect(B,a)
    if b_min==N:
        pass
    else:
        cnt+=dict[B[b_min]]
print(cnt)

Buggy python submission (verdict: Runtime Error):
from bisect import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
B_reverse=B[::-1]
C=sorted(list(map(int,input().split())))
cnt=0
dict={}
val=0
for b in B_reverse:
    c_min=bisect(C,b)
    val+=len(C[c_min:])
    dict[b]=val
for a in A:
    cnt+=dict[B[bisect(B,a)]]
print(cnt)

Fixed submission:
from bisect import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
B_reverse=B[::-1]
C=sorted(list(map(int,input().split())))
cnt=0
dict={}
val=0
for b in B_reverse:
    c_min=bisect(C,b)
    val+=N-c_min
    dict[b]=val
for a in A:
    b_min=bisect(B,a)
    if b_min==N:
        pass
    else:
        cnt+=dict[B[b_min]]
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect 
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))
cnt=0
for a in A:
    b_min=bisect(B,a)
    for b in B[b_min:]:
        c_min=bisect(C,b)
        cnt+=len(C[c_min:])
print(cnt)

Fixed submission:
from bisect import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
B_reverse=B[::-1]
C=sorted(list(map(int,input().split())))
cnt=0
dict={}
val=0
for b in B_reverse:
    c_min=bisect(C,b)
    val+=N-c_min
    dict[b]=val
for a in A:
    b_min=bisect(B,a)
    if b_min==N:
        pass
    else:
        cnt+=dict[B[b_min]]
print(cnt)
Buggy python submission (verdict: Runtime Error):
import math
N=int(input())
a=0
for i in range(1,1+math.ceil(math.sqrt(N))):
    if N%i==0 and i>a:
        a=i
b=int(N/a)
print(max([len(str(a)),len(str(b))]))9876543210

Fixed submission:
import math
N=int(input())
a=0
for i in range(1,1+math.ceil(math.sqrt(N))):
    if N%i==0 and i>a:
        a=i
b=int(N/a)
print(max([len(str(a)),len(str(b))]))
Buggy python submission (verdict: Time Limit Exceeded):
# Tenka1 2017 C

from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    for h in range(1, 3501):
        for w in range(1, 3501):
            upper = N * h * w
            lower = 4 * h * w - N * w - N * h
            if lower == 0 or upper % lower != 0:
                continue

            n = int(upper / lower)
            if n > 0:
                print(h, n, w)
                return


main()

Fixed submission:
# Tenka1 2017 C

from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    for h in range(1, 3501):
        for w in range(1, 3501):
            upper = N * h * w
            lower = 4 * h * w - N * w - N * h
            if lower == 0 or upper % lower != 0:
                continue

            n = int(upper / lower)
            if n > 0:
                print(h, n, w)
                return


main()
Buggy python submission (verdict: Runtime Error):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,k=mp()
a=sorted(lmp())
ans=10**10
l=1
r=a[-1]
while True:
    if x==l and y==r:
        print(r)
        exit()
    m=(l+r)//2
    c=0
    for i in a:
        c+=-(-i//m)-1
    if c>k:
        l=m
    else:
        r=m


Fixed submission:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,k=map(int,input().split())
a=lmp()

def ok(s):
    c=0
    for i in a:
        c+=-(-i//s)-1
    return c<=k


l=0
r=max(a)
while r>l+1:
    md=(r+l)//2
    if ok(md):
        r=md
    else:
        l=md
print(r)
Buggy python submission (verdict: Runtime Error):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
a.insert(0,10000)
a.append(0)
l=[0]*(n+2)
for i in range(1,n+1):
    if a[i-1]<a[i]>=a[i+1]:
        l[i]=1
    elif a[i-1]>a[i]<=a[i+1]:
        l[i]=-1
sto=[0,1000]
for i in range(n+2):
    if l[i]==-1:
        sto[0],sto[1]=divmod(sto[1],a[i])
    if l[i]==1:
        sto[1]+=sto[0]*a[i]
        sto[0]=0
if sto[0]!=0:
    for i in range(n+2):
        if l[n+2-i]==-1:
            print(sto[1]+sto[0]*a[n+2-1])
            exit()
else:
    print(sto[1])

Fixed submission:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
a.insert(0,10000)
a.append(0)
i=0
m=len(a)
while i<m-1:
    if a[i]==a[i+1]:
        del a[i]
        i-=1
    i+=1
    m=len(a)

n=len(a)-2

l=[0]*(n+2)
for i in range(1,n+1):
    if a[i-1]<a[i]>a[i+1]:
        l[i]=1
    elif a[i-1]>a[i]<a[i+1]:
        l[i]=-1
sto=[0,1000]
for i in range(n+2):
    if l[n+1-i]==-1:
        l[n+1-i]=0
        break
    elif l[n+1-i]==1:
        break
for i in range(n+2):
    if l[i]==-1:
        sto[0],sto[1]=divmod(sto[1],a[i])
    if l[i]==1:
        sto[1]+=sto[0]*a[i]
        sto[0]=0
print(sto[1])
Buggy python submission (verdict: Runtime Error):
from decimal import Decimal
a,b=map(str,input().split())
f1 = Decimal(a)
f2 = Decimal(b)
print(int(a*b))

Fixed submission:
a,b=map(float,input().split())
a=int(a)
b=int(b*1000)
print((a*b)//1000)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,k=mp()
a=lmp()
l=[]
i=0
while a[i] not in l:
    l.append(a[i])
    i=a[i]-1


x=l.index(a[i])
y=len(l)-x

if k<=x:
    print(l[k-1])
else:
    print(l[(k-x-1)%y+x])

Fixed submission:
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,k=mp()
a=lmp()
l=[]
i=0
ch=[0]*(n+1)
while True:
    if ch[i]==1:
        break
    else:
        ch[i]=1
        l.append(a[i])
        i=a[i]-1


x=l.index(a[i])
y=len(l)-x

if k<=x:
    print(l[k-1])
else:
    print(l[(k-x-1)%y+x])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,k=mp()
a=lmp()
l=[]
i=0
while a[i] not in l:
    l.append(a[i])
    i=a[i]-1


x=l.index(a[i])
y=len(l)-x

if k<=x:
    print(l[k-1])
else:
    print(l[(k-x-1)%y+x])

Fixed submission:
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,k=mp()
a=lmp()
l=[]
i=0
ch=[0]*(n+1)
while True:
    if ch[i]==1:
        break
    else:
        ch[i]=1
        l.append(a[i])
        i=a[i]-1


x=l.index(a[i])
y=len(l)-x

if k<=x:
    print(l[k-1])
else:
    print(l[(k-x-1)%y+x])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
l=[]
ans=0
for i in range(n):
  l=list(map(lambda x: x+1,l))
  ans+=l.count(a[i])
  l.append(-a[i])
print(ans)

Fixed submission:
import collections
n=int(input())
l=list(map(int,input().split()))
a=[0]*n
b=[0]*n
for i in range(n):
  a[i]=i+1+l[i]
  b[i]=(i+1-l[i])
A=collections.Counter(a)
aa=A.most_common()
B=collections.Counter(b)

ans=0
for i in range(len(aa)):
  ans+=B[aa[i][0]]*aa[i][1]

print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
l=[]
ans=0
for i in range(n):
  print(l)
  l=list(map(lambda x: x+1,l))
  ans+=l.count(a[i])
  l.append(-a[i])
print(ans)

Fixed submission:
import collections
n=int(input())
l=list(map(int,input().split()))
a=[0]*n
b=[0]*n
for i in range(n):
  a[i]=i+1+l[i]
  b[i]=(i+1-l[i])
A=collections.Counter(a)
aa=A.most_common()
B=collections.Counter(b)

ans=0
for i in range(len(aa)):
  ans+=B[aa[i][0]]*aa[i][1]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(q)] 
u=[]
for i in range(1,m+1):
  for k in range(n):
    u.append(i)
a=list(set(list(itertools.combinations(u,n))))
ans=[]

for i in range(len(a)):
  c=0
  for k in range(len(l)):
    if a[i][l[k][1]-1]-a[i][l[k][0]-1]==l[k][2]:
      c+=l[k][3]
  ans.append(c)
print(max(ans))


Fixed submission:
import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

from itertools import combinations_with_replacement as cwr
n,m,q=mp()
l=[lmp() for i in range(q)]
ans=0


for i in cwr(range(1,m+1),n):
    s=0
    for a,b,c,d in l:
        if i[b-1]-i[a-1]==c:
            s+=d
    ans=max(ans,s)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(q)] 
u=[]
for i in range(1,m+1):
  for k in range(n):
    u.append(i)
a=list(itertools.combinations(u,n))
ans=[]

for i in range(len(a)):
  c=0
  for k in range(len(l)):
    if a[i][l[k][1]-1]-a[i][l[k][0]-1]==l[k][2]:
      c+=l[k][3]
  ans.append(c)
print(max(ans))

Fixed submission:
import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

from itertools import combinations_with_replacement as cwr
n,m,q=mp()
l=[lmp() for i in range(q)]
ans=0


for i in cwr(range(1,m+1),n):
    s=0
    for a,b,c,d in l:
        if i[b-1]-i[a-1]==c:
            s+=d
    ans=max(ans,s)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=int(input())
n=len(str(s))
 
ans=0
for L in range(5,n+1):
  for i in range(n-L+1):
    if ((s//(10**(n-L-i)))%(10**L))%2019==0:
      ans+=1
 
print(ans)

Fixed submission:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

s=input()[::-1]
n=len(s)
a=[0]*2019
a[0]=1
c,d=0,1
for i in s:
    c+=int(i)*d
    c%=2019
    d*=10
    d%=2019
    a[c]+=1
ans=0
for i in a:
    ans+=i*(i-1)//2
print(ans)

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

ans=0
for L in range(4,n+1):
  for i in range(n-L+1):
    if ((s//(10**(n-L-i)))%(10**L))%2019==0:
      ans+=1

print(ans)

Fixed submission:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

s=input()[::-1]
n=len(s)
a=[0]*2019
a[0]=1
c,d=0,1
for i in s:
    c+=int(i)*d
    c%=2019
    d*=10
    d%=2019
    a[c]+=1
ans=0
for i in a:
    ans+=i*(i-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
k=int(input())
a=1
s=0
while a<=k:
  b=1
  while b<=k:
    c=1
    while c<=k:
      g=math.gcd(a,b)
      s+=math.gcd(g,c)
      c+=1
    b+=1
  a+=1
print(s)

Fixed submission:
from fractions import gcd
n=int(input())
ans=0
for i in range(1,n+1):
  for k in range(i,n+1):
    gc=gcd(i,k)
    for _ in range(k,n+1):
      g=gcd(gc,_)
      if i==_:
        ans+=g
      elif i==k or k==_:
        ans+=g*3
      else:
        ans+=g*6
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
n=int(input())
ans=0
for i in range(1,n+1):
  for k in range(i,n+1):
    for _ in range(k,n+1):
      g=gcd(gcd(i,k),_)
      if i==_:
        ans+=g
      elif i==k or k==_:
        ans+=g*3
      else:
        ans+=g*6
print(ans)

Fixed submission:
from fractions import gcd
n=int(input())
ans=0
for i in range(1,n+1):
  for k in range(i,n+1):
    gc=gcd(i,k)
    for _ in range(k,n+1):
      g=gcd(gc,_)
      if i==_:
        ans+=g
      elif i==k or k==_:
        ans+=g*3
      else:
        ans+=g*6
print(ans)

Buggy python submission (verdict: Runtime Error):
from fractions import gcd
n=int(input())
ans=0
for i in range(n):
  for k in range(i,n):
    for _ in range(k,n):
      if i==_:
        ans+=gcd(i,k,_)
      else if i==k or k==_:
        ans+=gcd(i,k,_)*3
      else:
        ans+=gcd(i,k,_)*6
print(ans)
      

Fixed submission:
from fractions import gcd
n=int(input())
ans=0
for i in range(1,n+1):
  for k in range(i,n+1):
    gc=gcd(i,k)
    for _ in range(k,n+1):
      g=gcd(gc,_)
      if i==_:
        ans+=g
      elif i==k or k==_:
        ans+=g*3
      else:
        ans+=g*6
print(ans)