Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
p=list(map(int,input().split()))
Exception_p=[]
for i in range(N):
    Exception_p.append((1+p[i])/2)
sum_Exception=[]
for i in range(N-K+1):
    sum=0
    for k in range(K):
        sum=Exception_p[i+k]+sum        
    sum_Exception.append(sum)
list.sort(sum_Exception)
print(sum_Exception.pop(-1))


Fixed submission:
N,K=map(int,input().split())
p=list(map(int,input().split()))
Exception_p=[]
for i in range(N):
    Exception_p.append((1+p[i])/2)
sum_Exception=[]
sum=0
for k in range(K):
    sum=(p[k]+1)/2+sum
sum_Exception.append(sum)
for i in range(N-K):
    sum=sum_Exception[i]-p[i]/2+p[i+K]/2
    sum_Exception.append(sum)
list.sort(sum_Exception)    
print(sum_Exception.pop(-1))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
P=list(map(int,input().split()))
count=0
P_new=[]
for index in range(N):
    P_new.append(P[index])
    P_new.sort()
    if P_new[0]==P[index]:
        count+=1
print(count)

Fixed submission:
N=int(input())
P=list(map(int,input().split()))
count=0
P_new=[]
for index in range(N):
    P_new.append(P[index])
    if P_new[0]>P_new[index]:
        P_new[0]=P_new[index]
    if P_new[0]==P[index]:
        count+=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
P=list(map(int,input().split()))
count=0
for index in range(N):
    P_new=P[:index+1]
    P_new.sort()
    if P_new[0]==P[index]:
        count+=1
print(count)

Fixed submission:
N=int(input())
P=list(map(int,input().split()))
count=0
P_new=[]
for index in range(N):
    P_new.append(P[index])
    if P_new[0]>P_new[index]:
        P_new[0]=P_new[index]
    if P_new[0]==P[index]:
        count+=1
print(count)
Buggy python submission (verdict: Runtime Error):
import math
A,B=map(int,input().split())
print(int(A*B/math.gcd(A,B)))

Fixed submission:
import fractions
A,B=map(int,input().split())
print(int(A*B/fractions.gcd(A,B)))
Buggy python submission (verdict: Runtime Error):
import math
a,b,x=map(int,input().split())
if a*a*b/2<x:
    theta=a/(2*b-2*x/a**2)
else:
    theta=2*x/(a*b*b)
print(90-math.atan(theta)*180/math.pi)

Fixed submission:
import math
a,b,x=map(int,input().split())
if a*a*b/2<x:
    theta=(2*b-2*x/a**2)/a
else:
    theta=b**2*a/2/x
print(math.atan(theta)*180/math.pi)

Buggy python submission (verdict: Runtime Error):
import fractions as math
a,b,x=map(int,input().split())
if a*a*b/2<x:
    theta=a/(2*b-2*x/a**2)
else:
    theta=2*x/(a*b*b)
print(90-math.atan(theta)*180/math.pi)

Fixed submission:
import math
a,b,x=map(int,input().split())
if a*a*b/2<x:
    theta=(2*b-2*x/a**2)/a
else:
    theta=b**2*a/2/x
print(math.atan(theta)*180/math.pi)

Buggy python submission (verdict: Runtime Error):
import math
a,b,x=map(int,input().split())
if a*a*b/2<x:
    theta=a/(2*b-2*x/a**2)
else:
    theta=2*x/(a*b*b)
print(90-math.atan(theta)*180/math.pi)

Fixed submission:
import math
a,b,x=map(int,input().split())
if a*a*b/2<x:
    theta=(2*b-2*x/a**2)/a
else:
    theta=b**2*a/2/x
print(math.atan(theta)*180/math.pi)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
l=list(map(int,input().split()))
l.sort()
count=0

for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if l[i]+l[j]>l[k]:
                count+=1
            else:
                break
print(count)

Fixed submission:
N=int(input())
l=list(map(int,input().split()))
l.sort()
count=0
import bisect
for i in range(N):
    for j in range(i+1,N-1):
        m=bisect.bisect_left(l,l[i]+l[j])
        count+=m-(j+1)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
l=list(map(int,input().split()))
l.sort()
count=0

for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if l[i]+l[j]>l[k]:
                count+=1
print(count)

Fixed submission:
N=int(input())
l=list(map(int,input().split()))
l.sort()
count=0
import bisect
for i in range(N):
    for j in range(i+1,N-1):
        m=bisect.bisect_left(l,l[i]+l[j])
        count+=m-(j+1)
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=list(map(int,input().split()))
l=""
for i in range(N):
    print(a.index(i+1)+1,end=" ")

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
b=[0]*N
for index, m in enumerate(a):
    b[m-1]=index+1
print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=list(map(int,input().split()))
l=""
for i in range(N):
    l=l+str(a.index(i+1)+1)+" "
print(l)

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
b=[0]*N
for index, m in enumerate(a):
    b[m-1]=index+1
print(*b)
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()))
takashi=0
for m,i in enumerate(a):
    takashi+=b[i-1]
    if 0<m<n:
        if abs(a[m]-a[m-1])==1:
            takashi+=c[a[m-1]-1]
print(takashi)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
takashi=b[a[0]-1]
for i in range(1,n):
    takashi+=b[a[i]-1]
    if a[i]-a[i-1]==1:
        takashi+=c[a[i-1]-1]

print(takashi)
Buggy python submission (verdict: Runtime Error):
a = [int(input()) for i in range(n)]
m = max(a)
p = a.index(m)
s = max(a)
for i in range(n):
    if i != p:
        print(m)
    else:
        print(s)


Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
m = max(a)
p = a.index(m)
a.remove(m)
s = max(a)
for i in range(n):
    if i != p:
        print(m)
    else:
        print(s)

Buggy python submission (verdict: Runtime Error):
a = [int(input()) for i in range(n)]
m = max(a)
p = a.index(m)
a.remove(m)
s = max(a)
for i in range(n):
    if i != p:
        print(m)
    else:
        print(s)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
m = max(a)
p = a.index(m)
a.remove(m)
s = max(a)
for i in range(n):
    if i != p:
        print(m)
    else:
        print(s)

Buggy python submission (verdict: Runtime Error):
a = [int(input()) for i in range(n)]
m = max(a)
print(a)
p = a.index(m)
a.remove(m)
s = max(a)
print(s)
for i in range(n):
    if i != p:
        print(m)
    else:
        print(s)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
m = max(a)
p = a.index(m)
a.remove(m)
s = max(a)
for i in range(n):
    if i != p:
        print(m)
    else:
        print(s)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
a = deque( int(input()) for i in range(n))
for i in range(n):
    s = a.popleft()
    m = max(a)
    print(m)
    a.append(s)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
m = max(a)
p = a.index(m)
a.remove(m)
s = max(a)
for i in range(n):
    if i != p:
        print(m)
    else:
        print(s)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
a = deque()
for i in range(n):
    j = int(input())
    a.append(j)
for i in range(n):
    s = a.popleft()
    m = max(a)
    print(m)
    a.append(s)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
m = max(a)
p = a.index(m)
a.remove(m)
s = max(a)
for i in range(n):
    if i != p:
        print(m)
    else:
        print(s)
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())

#cで割り切れる数+dで割り切れる数-gcd(c,d)で割り切れる数を求めればよい
ans=(b//c+b//d-b//(c*d//math.gcd(c,d)))-((a-1)//c+(a-1)//d-(a-1)//(c*d//math.gcd(c,d)))

print(b-a+1-ans)


Fixed submission:
s = input()
if s[0] != s[1] and s[1] != s[2] and s[2] != s[3]:
    print("Good")
else:
    print("Bad")
Buggy python submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = list(int(input()) for _ in range(m))
dp = [[] for _ in range(n + 1)]
dp[0] = 1
# j = 0
if m = 0:
    dp[1] = 1
    for i in range(2, n + 1):
        dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
    print(dp[n])
    exit()
if a[0] == 1:
    dp[1] = 0
    j = 1
else:
    dp[1] = 1
    j = 0
for i in range(2, n + 1):
    # print(i, dp)
    if j < m:
        if a[j]  == i:
            dp[i] = 0
            j += 1
            continue
    dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])

Fixed submission:
n, m = map(int,input().split())
a = list(int(input()) for _ in range(m))
dp = [[] for _ in range(n + 1)]
dp[0] = 1
# j = 0
if m == 0:
    dp[1] = 1
    for i in range(2, n + 1):
        dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
    print(dp[n])
    exit()
if a[0] == 1:
    dp[1] = 0
    j = 1
else:
    dp[1] = 1
    j = 0
for i in range(2, n + 1):
    # print(i, dp)
    if j < m:
        if a[j]  == i:
            dp[i] = 0
            j += 1
            continue
    dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])

Buggy python submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = list(int(input()) for _ in range(m))
dp = [[] for _ in range(n + 1)]
dp[0] = 1
# j = 0
if a[0] == 1:
    dp[1] = 0
    j = 1
else:
    dp[1] = 1
    j = 0
for i in range(2, n + 1):
    # print(i, dp)
    if j < m:
        if a[j]  == i:
            dp[i] = 0
            j += 1
            continue
    dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])

Fixed submission:
n, m = map(int,input().split())
a = list(int(input()) for _ in range(m))
dp = [[] for _ in range(n + 1)]
dp[0] = 1
# j = 0
if m == 0:
    dp[1] = 1
    for i in range(2, n + 1):
        dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
    print(dp[n])
    exit()
if a[0] == 1:
    dp[1] = 0
    j = 1
else:
    dp[1] = 1
    j = 0
for i in range(2, n + 1):
    # print(i, dp)
    if j < m:
        if a[j]  == i:
            dp[i] = 0
            j += 1
            continue
    dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
dp = [[0] * (w + 1) for _ in range(n + 1)]
wv = [[0, 0]] + [list(map(int, input().split())) for _ in range(n)]

for i in range(1, n + 1):
    for j in range(1, w + 1):
        if j - wv[i][0] >= 0:
            dp[i][j] = max(dp[i - 1][j - wv[i][0]] + wv[i][1], dp[i-1][j])
        else:
            dp[i][j] = dp[i - 1][j]

print(dp[n][w])

Fixed submission:
n, w = map(int, input().split())
dp = [[0] * (w + 1) for _ in range(n + 1)]
wv = [[0, 0]] + [list(map(int, input().split())) for _ in range(n)]

for i in range(1, n + 1):
    for j in range(1, w + 1):
        if j - wv[i][0] >= 0:
            dp[i][j] = max(dp[i - 1][j - wv[i][0]] + wv[i][1], dp[i-1][j])
        else:
            dp[i][j] = dp[i - 1][j]

print(dp[n][w])
Buggy python submission (verdict: Runtime Error):
from math import gcd
n, x =map(int,input().split())
s = list(map(int,input().split()))
y = abs(s[0] - x)
for i in range(1,n-1):
    y = gcd(y, abs(s[i] - x))
print(y)


Fixed submission:
from fractions import gcd
n, x =map(int,input().split())
s = list(map(int,input().split()))
y = abs(s[0] - x)
for i in range(1,n):
    y = gcd(y, abs(s[i] - x))
print(y)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
n, x =map(int,input().split())
s = list(map(int,input().split()))
s.sort()
a, b = x - s[0], s[-1] - x
visit = [0] * n
while sum(visit) != n:
    visit = [0] * n
    y = gcd(a, b)
    i = 0
    while s[0] + y * i <= s[-1] :
        if s[0] + y * i in s:
            visit[s.index(s[0] + y * i)] = 1
        i += 1
    a,b = min(a, b), y
print(y)



Fixed submission:
from fractions import gcd
n, x =map(int,input().split())
s = list(map(int,input().split()))
y = abs(s[0] - x)
for i in range(1,n):
    y = gcd(y, abs(s[i] - x))
print(y)

Buggy python submission (verdict: Runtime Error):
from fraction import gcd
n, x =map(int,input().split())
s = list(map(int,input().split()))
s.sort()
a, b = x - s[0], s[-1] - x
visit = [0] * n
while sum(visit) != n:
    visit = [0] * n
    y = gcd(a, b)
    i = 0
    while s[0] + y * i <= s[-1] :
        if s[0] + y * i in s:
            visit[s.index(s[0] + y * i)] = 1
        i += 1
    a,b = min(a, b), y
print(y)



Fixed submission:
from fractions import gcd
n, x =map(int,input().split())
s = list(map(int,input().split()))
y = abs(s[0] - x)
for i in range(1,n):
    y = gcd(y, abs(s[i] - x))
print(y)

Buggy python submission (verdict: Runtime Error):
n, x =map(int,input().split())
s = list(map(int,input().split()))
s.sort()
a, b = x - s[0], s[-1] - x
visit = [0] * n
while sum(visit) != n:
    visit = [0] * n
    y = gcd(a, b)
    i = 0
    while s[0] + y * i <= s[-1] :
        if s[0] + y * i in s:
            visit[s.index(s[0] + y * i)] = 1
        i += 1
    a,b = min(a, b), y
print(y)


Fixed submission:
from fractions import gcd
n, x =map(int,input().split())
s = list(map(int,input().split()))
y = abs(s[0] - x)
for i in range(1,n):
    y = gcd(y, abs(s[i] - x))
print(y)
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = dict()
for i in range(n):
    s = list(input())
    if s[0] == "M" or s[0] == "A" or s[0] == "R" or s[0] == "C" or s[0] == "H":
        if s[0] not in d:
            d[s[0]] = 1
        else:
            d[s[0]] += 1
count = 0
d = list(d.values())
if len(d) == 3:
    count = 1
    for i in d:
        count *= i
elif len(d) == 4:
    count += d[0] * d[1] * d[2]
    count += d[3] * d[1] * d[2]
    count += d[0] * d[1] * d[3]
    count += d[0] * d[3] * d[2]
else:    
    count += d[0] * d[1] * d[2]
    count += d[3] * d[1] * d[2]
    count += d[0] * d[1] * d[3]
    count += d[0] * d[3] * d[2]

    # count += d[0] * d[1] * d[2]
    count += d[4] * d[1] * d[2]
    count += d[0] * d[1] * d[4]
    count += d[0] * d[4] * d[2]

    count += d[4] * d[1] * d[2]
    # count += d[3] * d[1] * d[2]
    count += d[4] * d[1] * d[3]
    count += d[4] * d[3] * d[2]


print(count)

Fixed submission:
n = int(input())
d = dict()
for i in range(n):
    s = list(input())
    if s[0] == "M" or s[0] == "A" or s[0] == "R" or s[0] == "C" or s[0] == "H":
        if s[0] not in d:
            d[s[0]] = 1
        else:
            d[s[0]] += 1
count = 0
d = list(d.values())
if len(d) == 3:
    count += d[0] * d[1] * d[2]
elif len(d) == 4:
    count += d[0] * d[1] * d[2]
    count += d[3] * d[1] * d[2]
    count += d[0] * d[1] * d[3]
    count += d[0] * d[3] * d[2]
elif len(d) == 5:    
    count += d[0] * d[1] * d[2]
    count += d[3] * d[1] * d[2]
    count += d[0] * d[1] * d[3]
    count += d[0] * d[3] * d[2]

    # count += d[0] * d[1] * d[2]
    count += d[4] * d[1] * d[2]
    count += d[0] * d[1] * d[4]
    count += d[0] * d[4] * d[2]

    # count += d[4] * d[1] * d[2]
    # count += d[3] * d[1] * d[2]
    count += d[4] * d[1] * d[3]
    count += d[4] * d[3] * d[2]

    # count += d[0] * d[4] * d[2]
    # count += d[3] * d[4] * d[2]
    count += d[0] * d[4] * d[3]
    # count += d[0] * d[3] * d[2]


print(count)
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n):
    if p[i] - 1 == i:
        count += 1
        p[i] ,p[i + 1] = p[i + 1], p[i]
print(count)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n-1):
    if p[i] - 1 == i:
        count += 1
        p[i] ,p[i + 1] = p[i + 1], p[i]
if p[n - 1] - 1 == n - 1:
    count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
n = int( input() )
#print( n )

cnt = 0
for i in range( n ):
    a, b = map( int, input().split() )
    if a == b:
        cnt = cnt + 1
    else:
        cnt = 0

    if cnt == 3:
        exit( "Yes" )


print( "No" )


Fixed submission:
n = int( input() )
#print( n )

cnt = 0
ans = "No"
for i in range( n ):
    a, b = map( int, input().split() )
    if a == b:
        cnt = cnt + 1
    else:
        cnt = 0

    if cnt == 3:
        ans = "Yes"


print( ans )

Buggy python submission (verdict: Runtime Error):
n = int( input() )
#print( n )

d1 = [ 0 ] * n
d2 = [ 0 ] * n
#print( d1, d2 )

for i in range( n ):
    d1[ i ], d2[ i ] = map( int, input().split() )

#print( d1, d2 )


for i in range( n-2 ):
    if d1[ i ] == d2[ i ]:
        if d1[ i+1 ] == d2[ i+1 ]:
            if d1[ i+2 ] == d2[ i+2 ]:
                exit( "Yes" )

print( "No" )


Fixed submission:
n = int( input() )
#print( n )

cnt = 0
ans = "No"
for i in range( n ):
    a, b = map( int, input().split() )
    if a == b:
        cnt = cnt + 1
    else:
        cnt = 0

    if cnt == 3:
        ans = "Yes"


print( ans )
Buggy python submission (verdict: Runtime Error):
n, k = map( int, input().split() )
a = [ int( i ) for i in input().split() ]

leg = [ 0 ] * n
leg[ 0 ] = 1

p = 0
city_old = 1
for x in range( k ):
    city_new = a[ city_old-1 ]
    if leg[ city_new-1 ] == 0:
        leg[ city_new-1 ] += x + 1
    else:
        loop = x + 1 - leg[ city_new-1 ]
        modk = ( k - ( x + 1 ) ) % loop
        break
    city_old = city_new
    p += 1

if p == k:
    print( city_old )
    exit()


city_old = city_new
for x in range( modk ):
    city_new = a[ city_old-1 ]
    city_old = city_new

print( city_old )


Fixed submission:
n, k = map( int, input().split() )
a = [ int( i ) for i in input().split() ]

leg = [ 0 ] * n
leg[ 0 ] = 0

p = 0
city_old = 1
for x in range( k ):
    city_new = a[ city_old-1 ]
    if leg[ city_new-1 ] == 0 and city_new != 1:
        leg[ city_new-1 ] = x + 1
    else:
        loop = x + 1 - leg[ city_new-1 ]
        modk = ( k - ( x + 1 ) ) % loop
#        print( loop, modk )
        break
    city_old = city_new
    p += 1

if p == k:
    print( city_old )
    exit()


city_old = city_new
for x in range( modk ):
    city_new = a[ city_old-1 ]
    city_old = city_new

print( city_old )
Buggy python submission (verdict: Runtime Error):
import numpy as np

s = input()
#print( s, w )

if s == "ABC":
    print( "ARC" )
else:
    print( "ABC" )


Fixed submission:
import numpy as np

s = input()
#print( s, w )

if s == "ABC":
    print( "ARC" )
elif s == "ARC":
    print( "ABC" )
Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map( int, input().split() )
#print( a, b, n )

beta = 0.0e0
for ni in range( n+1 ):
#    print( ni )
    betai = ni/b  - int( ni/b )
    beta = max( beta, betai )

ans = int( a * beta )
print( ans )


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

if b <= n:
    beta = ( b-1 )/b - int( ( b-1 )/b )

elif b > n:
    beta = n/b - int( n/b )

ans = int( a * beta )
print( ans )

Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map( int, input().split() )
#print( a, b, n )

ans = int( 0 )
for ni in range( n+1 ):
#    print( ni )
    ansi = int( ( a*ni )/b ) - a * int( ni/b )
    ans = max( ans, ansi )

print( ans )


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

if b <= n:
    beta = ( b-1 )/b - int( ( b-1 )/b )

elif b > n:
    beta = n/b - int( n/b )

ans = int( a * beta )
print( ans )
Buggy python submission (verdict: Time Limit Exceeded):
s = int( input() )
ss = str( s )
l = len( ss )
#print( s, l )

ans = int( 0 )
for i in range( l-4 ):
    for j in range( i+4, l+1 ):
        ssij = ss[ i:j ]
        sij = int( ssij )
#        print( i, j, sij )
        if sij % 2019 == 0:
#            print( "Yes" )
            ans = ans + 1

print( ans )


Fixed submission:
import numpy as np

s = input()

d = [ int( 0 ) ] * 2019
d[ 0 ] = int( 1 )
r = int( 0 )
t = int( 1 )

for si in reversed( s ):
#    print( si )

    r = int( si ) * t + r
    r = r % 2019

    t = t * 10
    t = t % 2019

    d[ r ] = d[ r ] + 1

ans = int( 0 )
for di in d:
    ans = ans + di * ( di - 1 ) // 2

print( ans )

Buggy python submission (verdict: Runtime Error):
import numpy as np

s = int( input() )
ss = str( s )
l = len( ss )
#print( s, l )

ans = int( 0 )
for i in range( l-4 ):
    for j in range( i+4, l+1 ):
        ssij = ss[ i:j ]
        sij = int( ssij )
#        print( i, j, sij )
        if sij % 2019 == 0:
#            print( "Yes" )
            ans = ans + 1

print( ans )


Fixed submission:
import numpy as np

s = input()

d = [ int( 0 ) ] * 2019
d[ 0 ] = int( 1 )
r = int( 0 )
t = int( 1 )

for si in reversed( s ):
#    print( si )

    r = int( si ) * t + r
    r = r % 2019

    t = t * 10
    t = t % 2019

    d[ r ] = d[ r ] + 1

ans = int( 0 )
for di in d:
    ans = ans + di * ( di - 1 ) // 2

print( ans )

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

s = int( input() )
ss = str( s )
n = len( ss )

cmod = np.zeros( 2019 )
cmod[ 0 ] += int( 1 )

tkm1 = int( 0 )
for km in range( n ):
    k = n - km
    tkm1 = tkm1 + 10**( n - k ) * int( ss[ k - 1 ] )
    lmod = tkm1 % 2019
    cmod[ lmod ] += 1
#    print( lmod, tkm1 )

ans = int( 0 )
for icmod in cmod:
    ans += icmod * ( icmod-1 ) * 0.5e0

ans = int( ans )
print( ans )


Fixed submission:
import numpy as np

s = input()

d = [ int( 0 ) ] * 2019
d[ 0 ] = int( 1 )
r = int( 0 )
t = int( 1 )

for si in reversed( s ):
#    print( si )

    r = int( si ) * t + r
    r = r % 2019

    t = t * 10
    t = t % 2019

    d[ r ] = d[ r ] + 1

ans = int( 0 )
for di in d:
    ans = ans + di * ( di - 1 ) // 2

print( ans )

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

s = int( input() )
ss = str( s )
l = len( ss )
#print( s, l )

ans = int( 0 )
for i in range( l-4 ):
    for j in range( i+4, l+1 ):
        ssij = ss[ i:j ]
        sij = int( ssij )
#        print( i, j, sij )
        if sij % 2019 == 0:
#            print( "Yes" )
            ans = ans + 1

print( ans )


Fixed submission:
import numpy as np

s = input()

d = [ int( 0 ) ] * 2019
d[ 0 ] = int( 1 )
r = int( 0 )
t = int( 1 )

for si in reversed( s ):
#    print( si )

    r = int( si ) * t + r
    r = r % 2019

    t = t * 10
    t = t % 2019

    d[ r ] = d[ r ] + 1

ans = int( 0 )
for di in d:
    ans = ans + di * ( di - 1 ) // 2

print( ans )
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map( int, input().split() )
h = [ int( hi ) for hi in input().split() ]
#print( n, k )
#print( h )

cost = [ 1000000000 ] * n
cost[ 0 ] = 0
for ni in range( 1, n ):
    for ki in range( 1, min( k+1, ni+1 ) ):
#        print( ni, ki )
        costx = cost[ ni-ki ] + max( h[ ni ]-h[ ni-ki ], h[ ni-ki ]-h[ ni ] )
        cost[ ni ] = min( cost[ ni ], costx )

print( cost[ n-1 ] )


Fixed submission:
import numpy as np
N,K = map(int,input().split())
h = np.array(list(map(int,input().split())))

dp = np.zeros(N,dtype=int)
for i in range(1,N):
    dp[i] = (dp[max(0,i-K):i] + np.abs(h[i]-h[max(0,i-K):i])).min()
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map( int, input().split() )
h = [ int( hi ) for hi in input().split() ]
#print( n, k )
#print( h )

cost = [ 1000000000 ] * n
cost[ 0 ] = 0
for ni in range( 1, n ):
    for ki in range( 1, k+1 ):
#        print( ni, ki )
        if ni-ki >= 0:
            costx = cost[ ni-ki ] + max( h[ ni ]-h[ ni-ki ], h[ ni-ki ]-h[ ni ] )
            cost[ ni ] = min( cost[ ni ], costx )

print( cost[ n-1 ] )


Fixed submission:
import numpy as np
N,K = map(int,input().split())
h = np.array(list(map(int,input().split())))

dp = np.zeros(N,dtype=int)
for i in range(1,N):
    dp[i] = (dp[max(0,i-K):i] + np.abs(h[i]-h[max(0,i-K):i])).min()
print(dp[-1])