Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
L, R = (int(i) for i in input().split())

if (R - L) <= 2019:
    temp1 = float("inf")
    for i in range(R - L):
        for j in range(R - L):
            temp2 = ((R-i) * (R - 1 -j)) % 2019
            if temp2 < temp1:
                temp1 = temp2
    print(temp1)
else:
    temp1 = float("inf")
    for i in range(2019):
        if (R-i-1) < L:
            break
        for j in range(R - L):
            temp2 = ((R - i) * (R - 1 - j)) % 2019
            if temp2 < temp1:
                temp1 = temp2
    print(temp1)

Fixed submission:
L, R = (int(i) for i in input().split())

if (R - L) <= 2019:
    temp1 = float("inf")
    for i in range(R - L):
        for j in range(R - L):
            temp2 = ((R-i) * (R - 1 -j)) % 2019
            if temp2 < temp1:
                temp1 = temp2
    print(temp1)
else:
    temp1 = float("inf")
    for i in range(2019):
        if (R-i-1) < L:
            break
        for j in range(2019):
            temp2 = ((R - i) * (R - 1 - j)) % 2019
            if temp2 < temp1:
                temp1 = temp2
    print(temp1)
Buggy python submission (verdict: Runtime Error):
import math

A, B, C, D = (int(i) for i in input().split())

if C == D:
    duplicate = C
elif C > D and C % D == 0:
    duplicate = C
elif D > C and D % C == 0:
    duplicate = D
else:
    duplicate = C * D // math.gcd(C, D)

cCnt = (B - A) // C
dCnt = (B - A) // D
duplicateCnt = (B - A) // duplicate

print(B - A - cCnt - dCnt + duplicateCnt)

Fixed submission:
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        A, B, C, D = map(int, input().split())

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

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

        def f(x):
            return x - (x // C + x // D - x // lcm(C, D))

        print(f(B) - f(A - 1))


# Run main
if __name__ == '__main__':
    AtCoder().main()
Buggy python submission (verdict: Runtime Error):
s = input().split()

n = s[0]
k = s[1]

if n ==1 :
    print(0)
else:
    print(n-k)

Fixed submission:
s = input().split()

n = int(s[0])
k = int(s[1])

if k==1 :
    print(0)
else:
    print(n-k)

Buggy python submission (verdict: Runtime Error):
input = input().split()

n = s[0]
k = s[1]

if n ==1 :
    print(0)
else:
    print(n-k)

Fixed submission:
s = input().split()

n = int(s[0])
k = int(s[1])

if k==1 :
    print(0)
else:
    print(n-k)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
K = int(input())

kc = S[K]
ans = ''
for c in S:
  if c != kc:
    ans += '*'
  else:
    ans += c

print(ans)

Fixed submission:
N = int(input())
S = input()
K = int(input())

kc = S[K - 1]
ans = ''
for c in S:
  if c != kc:
    ans += '*'
  else:
    ans += c

print(ans)

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

S = list(S)
c = S[K]
for i in range(N):
  if S[i] != c:
    S[i] = '*'

print(str.join('', S))

Fixed submission:
N = int(input())
S = input()
K = int(input())

kc = S[K - 1]
ans = ''
for c in S:
  if c != kc:
    ans += '*'
  else:
    ans += c

print(ans)

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

c = S[K]
for i in range(N):
  if S[i] != c:
    S[i] = '*'

print(S)
    

Fixed submission:
N = int(input())
S = input()
K = int(input())

kc = S[K - 1]
ans = ''
for c in S:
  if c != kc:
    ans += '*'
  else:
    ans += c

print(ans)

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

c = S[K]
for i in range(N):
  if S[i] !== c:
    S[i] = '*'

print(S)
    

Fixed submission:
N = int(input())
S = input()
K = int(input())

kc = S[K - 1]
ans = ''
for c in S:
  if c != kc:
    ans += '*'
  else:
    ans += c

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

info = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h > 0:
        info.append([h, x, y])

info.sort(reverse=True)

for c_x in range(101):
    for c_y in range(101):
        H = info[0][0] + abs(info[0][1] - c_x) + abs(info[0][2] - c_y)
        flag = True
        for i in range(1, N):
            if info[i][0] != H - abs(info[i][1] - c_x) - abs(info[i][2] - c_y):
                flag = False
                break

        if flag:
            print(*[c_x, c_y, H])
            exit()

Fixed submission:
N = int(input())

info = []
for _ in range(N):
    x, y, h = map(int, input().split())
    info.append([h, x, y])

info.sort(reverse=True)

for c_x in range(101):
    for c_y in range(101):
        H = info[0][0] + abs(info[0][1] - c_x) + abs(info[0][2] - c_y)
        flag = True
        for i in range(1, N):
            if info[i][0] != max(H - abs(info[i][1] - c_x) - abs(info[i][2] - c_y), 0):
                flag = False
                break

        if flag:
            print(*[c_x, c_y, H])
            exit()
Buggy python submission (verdict: Runtime Error):
l = map(int, input().split())
l.sort()

print(l[2] * 10 + sum(l[:2]))

Fixed submission:
l = list(map(int, input().split()))
l.sort()

print(l[2] * 10 + sum(l[:2]))

Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
print(sum(A, B, C) - min(A, B, C))

Fixed submission:
l = list(map(int, input().split()))
l.sort()

print(l[2] * 10 + sum(l[:2]))
Buggy python submission (verdict: Runtime Error):
A = list(map(int, input().split()))
A.sort()

ans = 0
for i in range(1,3):
  ans += a[i] - a[i-1]
print(ans)

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

ans = 0
for i in range(1,3):
  ans += A[i] - A[i-1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        A, B, C, D, E, F = map(int, input().split())

        sousa1 = 0
        sousa2 = 0
        ans = (0, 0, 0)
        while True:
            if sousa1 * 100 * A > F:
                break
            while True:
                water = sousa1 * 100 * A + sousa2 * 100 * B
                if water == 0:
                    continue
                if water > F:
                    sousa2 = 0
                    break
                sugar_limit = water // 100 * E
                sousa3 = 0
                sousa4 = 0
                max_sugar = 0
                while True:
                    if sousa3 * C > sugar_limit:
                        break
                    while True:
                        sugar = sousa3 * C + sousa4 * D
                        if water + sugar > F or sugar > sugar_limit:
                            sousa4 = 0
                            break
                        else:
                            max_sugar = max(max_sugar, sugar)
                        sousa4 += 1
                    sousa3 += 1
                concentration = 100 * max_sugar / (water + max_sugar)
                if ans[0] < concentration:
                    ans = [concentration, water, max_sugar]
                sousa2 += 1
            sousa1 += 1

        print('{} {}'.format(sum(ans[1:]), ans[2]))


# Run main
if __name__ == '__main__':
    AtCoder().main()


Fixed submission:
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        A, B, C, D, E, F = map(int, input().split())

        sousa1 = 1
        sousa2 = 0
        ans = (0, 100 * A, 0)
        while True:
            if sousa1 * 100 * A > F:
                break
            while True:
                water = sousa1 * 100 * A + sousa2 * 100 * B
                if water > F:
                    sousa2 = 0
                    break

                sugar_limit = water // 100 * E
                sousa3 = 0
                sousa4 = 0
                max_sugar = 0
                while True:
                    if sousa3 * C > sugar_limit:
                        break
                    while True:
                        sugar = sousa3 * C + sousa4 * D
                        if water + sugar > F or sugar > sugar_limit:
                            sousa4 = 0
                            break
                        else:
                            max_sugar = max(max_sugar, sugar)
                        sousa4 += 1
                    sousa3 += 1
                concentration = 100 * max_sugar / (water + max_sugar)
                if ans[0] < concentration:
                    ans = [concentration, water, max_sugar]
                sousa2 += 1
            sousa1 += 1

        print('{} {}'.format(sum(ans[1:]), ans[2]))


# Run main
if __name__ == '__main__':
    AtCoder().main()
Buggy python submission (verdict: Time Limit Exceeded):
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        a = list(map(int, input().split()))

        ans = 0
        for x in range(10 ** 5 + 1):
            ans = max(ans, a.count(x - 1) + a.count(x) + a.count(x + 1))
        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Fixed submission:
# sys.stdin.readline
import collections
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        a = list(map(int, input().split()))

        cnt = collections.Counter(a)

        ans = 0
        for x in range(10 ** 5 + 1):
            ans = max(ans, cnt[x - 1] + cnt[x] + cnt[x + 1])
        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()
Buggy python submission (verdict: Runtime Error):
S = set(list(input()))

for c in string.ascii_lowercase:
  if c not in S:
    print(c)
    exit()

print('None')

Fixed submission:
import string

S = set(list(input()))

for c in string.ascii_lowercase:
  if c not in S:
    print(c)
    exit()

print('None')
Buggy python submission (verdict: Runtime Error):
N = input()

half = N // 2

if N%2 == 0:
  left_N = N[:half]
  right_N = N[half:]
else:
  left_N = N[:half]
  right_N = N[half+1:]

for l,r in zip(left_N, right_N[::-1]):
  if l != r:
    print('No')
    exit()
    
print('Yes')

Fixed submission:
N = input()

half = len(N) // 2

if len(N)%2 == 0:
  left_N = N[:half]
  right_N = N[half:]
else:
  left_N = N[:half]
  right_N = N[half+1:]

for l,r in zip(left_N, right_N[::-1]):
  if l != r:
    print('No')
    exit()
    
print('Yes')
Buggy python submission (verdict: Runtime Error):
O = input()
E = input()

ans = ''
for i in range(len(O) -1):
  ans += O[i] + E(i)

if len(O) - len(E) == 0:
  ans += O[-1] + E[-1]
else:
  ans += O[-1]
  
print(ans)

Fixed submission:
O = input()
E = input()

ans = ''
for i in range(len(O) -1):
  ans += O[i] + E[i]

if len(O) - len(E) == 0:
  ans += O[-1] + E[-1]
else:
  ans += O[-1]
  
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
s.replace(','. ' ')
print(s)

Fixed submission:
s = input()
print(s.replace(',', ' '))
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        K, S = map(int, input().split())
        ans = 0
        for i in range(K + 1):
            for j in range(K + 1):
                for k in range(K + 1):
                    if i + j + k == S:
                        ans += 1
        print(ans)

if __name__ == '__main__':
    AtCoder().main()

Fixed submission:
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        K, S = map(int, input().split())
        ans = 0
        for i in range(K + 1):
            for j in range(K + 1):
                Z = S - i - j
                if 0 <= Z <= K:
                    ans += 1
        print(ans)


if __name__ == '__main__':
    AtCoder().main()

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

input = sys.stdin.readline


class AtCoder:
    def main(self):
        K, S = map(int, input().split())
        ans = 0
        for i in range(K + 1):
            for j in range(K + 1):
                for k in range(K + 1):
                    if i + j + k == S:
                        ans += 1
        print(ans)

if __name__ == '__main__':
    AtCoder().main()

Fixed submission:
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        K, S = map(int, input().split())
        ans = 0
        for i in range(K + 1):
            for j in range(K + 1):
                Z = S - i - j
                if 0 <= Z <= K:
                    ans += 1
        print(ans)


if __name__ == '__main__':
    AtCoder().main()
Buggy python submission (verdict: Time Limit Exceeded):
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = input().rstrip()
        dp = [False] * (len(S) + 1)

        words = ["dream", "dreamer", "erase", "eraser"]

        dp[0] = True
        for i in range(len(S)):
            if not dp[i]:
                continue
            for word in words:
                if S[i:].startswith(word):
                    dp[i + len(word)] = True

        print('YES' if dp[len(S)] else 'NO')


# Run main
if __name__ == '__main__':
    AtCoder().main()

Fixed submission:
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = input().rstrip()

        while len(S) > 0:
            if S[:11] == 'dreameraser':
                S = S[11:]
            elif S[:10] == 'dreamerase':
                S = S[10:]
            elif S[:7] == 'dreamer':
                S = S[7:]
            elif S[:6] == 'eraser':
                S = S[6:]
            elif S[:5] == 'dream' or S[:5] == 'erase':
                S = S[5:]
            else:
                print('NO')
                exit()
        print('YES')


# Run main
if __name__ == '__main__':
    AtCoder().main()
Buggy python submission (verdict: Runtime Error):
contest_name = [word for word in input.split()]
 
print('A' + contest_name[1][0] + 'C')

Fixed submission:
contest_name = [word for word in input().split()]
 
print('A' + contest_name[1][0] + 'C')

Buggy python submission (verdict: Runtime Error):
contest_name = input.split()

print('A' + contest_name[1][0] + 'C')

Fixed submission:
contest_name = [word for word in input().split()]
 
print('A' + contest_name[1][0] + 'C')
Buggy python submission (verdict: Runtime Error):
N, L = input().split()
S = [input() for i in range(N)]

print(*sorted(S), sep='')

Fixed submission:
N, L = map(int, input().split())
S = [input() for i in range(N)]

print(*sorted(S), sep='')
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)


n=int(input())
X=str(input())

number=0
for i in range(n):
    if X[i]=='1':
        number+=1

base1=0
for i in range(n):
    if X[i]=='1':
        base1=(base1+pow(2,n-i-1,number+1))%(number+1)


base2=0
for i in range(n):
    if X[i]=='1':
        base2=(base2+pow(2,n-i-1,number-1))%(number-1)



def culc(x):
    bin_x=str(bin(x)[2:])
    one=0
    for i in range(len(bin_x)):
        if bin_x[i]=='1':
            one+=1
    return x%one
        



#dp[i](0<=i<=number)
dp=[-1]*(number+1)
dp[0]=0
def rec(x):
    if dp[x]>=0:
        return dp[x]
    else:
        dp[x]=rec(culc(x))+1
        return dp[x]





for i in range(n):
    #base1
    if X[i]=='0':
        temp=(base1+pow(2,n-i-1,number+1))%(number+1)
        ans=rec(temp)+1
        print(ans)
    #base2
    if X[i]=='1':
        temp=(base2-pow(2,n-i-1,number-1))%(number-1)
        ans=rec(temp)+1
        print(ans)



Fixed submission:
import sys
sys.setrecursionlimit(10**7)


n=int(input())
X=str(input())

number=0
for i in range(n):
    if X[i]=='1':
        number+=1



def culc(x):
    bin_x=str(bin(x)[2:])
    one=0
    for i in range(len(bin_x)):
        if bin_x[i]=='1':
            one+=1
    return x%one
        



#dp[i](0<=i<=number)
dp=[-1]*(number+1)
dp[0]=0
def rec(x):
    if dp[x]>=0:
        return dp[x]
    else:
        dp[x]=rec(culc(x))+1
        return dp[x]



if number==0:
    for i in range(n):
        print(1)
    sys.exit()



base1=0
for i in range(n):
    if X[i]=='1':
        base1=(base1+pow(2,n-i-1,number+1))%(number+1)

if number==1:
    for i in range(n):
        if X[i]=='1':
            print(0)
        else:
            temp=(base1+pow(2,n-i-1,number+1))%(number+1)
            ans=rec(temp)+1
            print(ans)
    sys.exit()



base2=0
for i in range(n):
    if X[i]=='1':
        base2=(base2+pow(2,n-i-1,number-1))%(number-1)






for i in range(n):
    #base1
    if X[i]=='0':
        temp=(base1+pow(2,n-i-1,number+1))%(number+1)
        ans=rec(temp)+1
        print(ans)
    #base2
    if X[i]=='1':
        temp=(base2-pow(2,n-i-1,number-1))%(number-1)
        ans=rec(temp)+1
        print(ans)
Buggy python submission (verdict: Runtime Error):
d=int(input())
C=list(map(int,input().split()))
S=[]
for i in range(d):
    S.append(list(map(int,input().split())))
T=[]
for i in range(d):
    t=int(input())-1
    T.append(t)


Last=[0]*26

ans=0
for i in range(d):
    t=T[i]
    temp=S[i][t]
    for j in range(26):
        if j==t:
            Last[j]=i+1
        else:
            temp-=C[j]*(i+1-Last[j])
    ans+=temp
    print(ans)
    


Fixed submission:
d=int(input())
C=list(map(int,input().split()))
S=[]
for i in range(d):
    S.append(list(map(int,input().split())))


last=[0]*26

for i in range(d):
    s=-1
    for j in range(26):
        temp=S[i][j]+C[j]*(i+1-last[j])
        if temp>s:
            s=temp
            index=j
    last[index]=i+1
    print(index+1)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
A=list(map(int,input().split()))

def culc(L):
    subL=[0]*(n+1)

    for i in range(n):
        temp=L[i]
        bottom=max(i-temp,0)
        top=min(i+temp,n-1)

        subL[bottom]+=1
        subL[top+1]-=1
    
    resL=[0]*n
    resL[0]=subL[0]
    for i in range(1,n):
        resL[i]=resL[i-1]+subL[i]

    return resL

for i in range(min(k,20)):
    A=culc(A)

print(*A)


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

def culc(L):
    subL=[0]*(n+1)

    for i in range(n):
        temp=L[i]
        bottom=max(i-temp,0)
        top=min(i+temp,n-1)

        subL[bottom]+=1
        subL[top+1]-=1
    
    resL=[0]*n
    resL[0]=subL[0]
    for i in range(1,n):
        resL[i]=resL[i-1]+subL[i]

    return resL

for i in range(min(k,50)):
    A=culc(A)

print(*A)
Buggy python submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
P=998244353

start=(M*pow(M-1,N-1,P))%P

fac=[0]*N
finv=[0]*N
inv=[0]*N
fac[0]=1
fac[1]=1
finv[0]=1
finv[1]=1
inv[1]=1
for i in range(2,N):
    fac[i]=(fac[i-1]*i)%P
    inv[i]=P-(inv[P%i]*(P//i))%P
    finv[i]=(finv[i-1]*inv[i])%P

def comb(n,k):
    return fac[n]*(finv[k]*finv[n-k]%P)%P



comp=0
last=(N-1)-K #K=0ならthru
if K>=1:
    for i in range(1,K+1):
        comp=(comp+comb(N-1,i)*pow(M-1,(N-1)-i,P))%P
comp=(comp*M)%P

print((start+comp)%P)

Fixed submission:
N,M,K=map(int,input().split())
P=998244353

start=(M*pow(M-1,N-1,P))%P



if N>=2:
    fac=[0]*N
    finv=[0]*N
    inv=[0]*N
    fac[0]=1
    fac[1]=1
    finv[0]=1
    finv[1]=1
    inv[1]=1
    for i in range(2,N):
        fac[i]=(fac[i-1]*i)%P
        inv[i]=P-(inv[P%i]*(P//i))%P
        finv[i]=(finv[i-1]*inv[i])%P

    def comb(n,k):
        return fac[n]*(finv[k]*finv[n-k]%P)%P



    comp=0
    last=(N-1)-K #K=0ならthru
    for i in range(1,K+1):
        comp=(comp+comb(N-1,i)*pow(M-1,(N-1)-i,P))%P
    comp=(comp*M)%P

    print((start+comp)%P)

else:
    print(M%P)

Buggy python submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
P=998244353

start=(M*pow(M-1,N-1,P))%P

fac=[0]*N
finv=[0]*N
inv=[0]*N
fac[0]=1
fac[1]=1
finv[0]=1
finv[1]=1
inv[1]=1
for i in range(2,N):
    fac[i]=(fac[i-1]*i)%P
    inv[i]=P-(inv[P%i]*(P//i))%P
    finv[i]=(finv[i-1]*inv[i])%P

def comb(n,k):
    return fac[n]*(finv[k]*finv[n-k]%P)%P



comp=0
last=(N-1)-K #K=0ならthru
for i in range(1,K+1):
    comp=(comp+comb(N-1,i)*pow(M-1,(N-1)-i,P))%P
comp=(comp*M)%P

print((start+comp)%P)

Fixed submission:
N,M,K=map(int,input().split())
P=998244353

start=(M*pow(M-1,N-1,P))%P



if N>=2:
    fac=[0]*N
    finv=[0]*N
    inv=[0]*N
    fac[0]=1
    fac[1]=1
    finv[0]=1
    finv[1]=1
    inv[1]=1
    for i in range(2,N):
        fac[i]=(fac[i-1]*i)%P
        inv[i]=P-(inv[P%i]*(P//i))%P
        finv[i]=(finv[i-1]*inv[i])%P

    def comb(n,k):
        return fac[n]*(finv[k]*finv[n-k]%P)%P



    comp=0
    last=(N-1)-K #K=0ならthru
    for i in range(1,K+1):
        comp=(comp+comb(N-1,i)*pow(M-1,(N-1)-i,P))%P
    comp=(comp*M)%P

    print((start+comp)%P)

else:
    print(M%P)
Buggy python submission (verdict: Runtime Error):
S_str=str(input())
S=int(S_str[-1])
N=len(S_str)

mod=[0]*2018
mod[0]=1
now=S%2019
mod[now]+=1

for i in range(N-1)[::-1]:
    #print(i+1,S,S%2019)
    next=pow(10,N-1-i,2019)
    next=(next*int(S_str[i]))%2019
    now=(now+next)%2019
    mod[now]+=1

    

def culc(x):
    return x*(x-1)//2


ans=0
for j in range(len(mod)):
    ans+=culc(mod[j])

print(ans)




Fixed submission:
S_str=str(input())
S=int(S_str[-1])
N=len(S_str)

mod=[0]*2019
mod[0]=1
now=S%2019
mod[now]+=1

for i in range(N-1)[::-1]:
    #print(i+1,S,S%2019)
    next=pow(10,N-1-i,2019)
    next=(next*int(S_str[i]))%2019
    now=(now+next)%2019
    mod[now]+=1

    

def culc(x):
    return x*(x-1)//2


ans=0
for j in range(len(mod)):
    ans+=culc(mod[j])

print(ans)

Buggy python submission (verdict: Runtime Error):
S_str=str(input())
S_list=list(S_str)
S=int(S_list[-1])
N=len(S_str)

mod=[0]*2018
mod[0]=1
now=S%2019
mod[now]+=1

for i in range(N-1)[::-1]:
    #print(i+1,S,S%2019)
    next=pow(10,N-1-i,2019)
    next=(next*int(S_list[i]))%2019
    now=(now+next)%2019
    mod[now]+=1

    

def culc(x):
    return x*(x-1)//2


ans=0
for j in range(len(mod)):
    ans+=culc(mod[j])

print(ans)




Fixed submission:
S_str=str(input())
S=int(S_str[-1])
N=len(S_str)

mod=[0]*2019
mod[0]=1
now=S%2019
mod[now]+=1

for i in range(N-1)[::-1]:
    #print(i+1,S,S%2019)
    next=pow(10,N-1-i,2019)
    next=(next*int(S_str[i]))%2019
    now=(now+next)%2019
    mod[now]+=1

    

def culc(x):
    return x*(x-1)//2


ans=0
for j in range(len(mod)):
    ans+=culc(mod[j])

print(ans)

Buggy python submission (verdict: Runtime Error):
S_str=str(input())
S_list=list(S_str)
S=int(S_str)
N=len(S_str)

mod=[0]*2018
mod[0]=1

for i in range(N):
    #print(i+1,S,S%2019)
    mod[S%2019]+=1
    S-=int(S_list[i])*(10**(N-1-i))

def culc(x):
    return x*(x-1)//2


ans=0
for j in range(len(mod)):
    ans+=culc(mod[j])

print(ans)




Fixed submission:
S_str=str(input())
S=int(S_str[-1])
N=len(S_str)

mod=[0]*2019
mod[0]=1
now=S%2019
mod[now]+=1

for i in range(N-1)[::-1]:
    #print(i+1,S,S%2019)
    next=pow(10,N-1-i,2019)
    next=(next*int(S_str[i]))%2019
    now=(now+next)%2019
    mod[now]+=1

    

def culc(x):
    return x*(x-1)//2


ans=0
for j in range(len(mod)):
    ans+=culc(mod[j])

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

N,K=map(int,input().split())
P=10**9+7

L=[0]*K
for i in range(N):
    L[i]=pow(K//(i+1),N-1,P)

def culc(x):
    f=K//i
    r=K-f
    if r==1:
        return (f*(N-1))%P
    else:
        y=pow(r,N-1)-1
        return ((f*y)//(r-1))%P

for j in range(1,K):
    L[0]+=culc(j+1)

ans=0
for k in range(K):
    ans+=((k+1)*L[k])%P

print(ans)



Fixed submission:
N,K=map(int,input().split())
P=10**9+7

L=[0]*(K+1)
for i in range(1,K+1)[::-1]:
    minus=0
    count=2
    while True:
        if count*i<=K:
            minus+=L[count*i]
            minus=minus%P
            count+=1
        else:
            break

    L[i]=(pow(K//i,N,P)-minus)%P

ans=0
for j in range(1,K+1):
    ans+=j*L[j]
    ans=ans%P

print(ans)
Buggy python submission (verdict: Runtime Error):
S=str(input())

if S=='AAA' or S='BBB':
    print('No')
else:
    print('Yes')

Fixed submission:
S=str(input())

if S=='AAA' or S=='BBB':
    print('No')
else:
    print('Yes')