Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
S = input()
A = [chr(ord('a') + i) for i in range(26)]
c = 0

for i in range(26):
  if A[i] in S:
    continue
  else:
    print(A[i])
    c = 1
    break
if c = 0:
  print("None")

Fixed submission:
S = input()
A = [chr(ord('a') + i) for i in range(26)]
c = 0

for i in range(26):
  if A[i] in S:
    continue
  else:
    print(A[i])
    c = 1
    break
if c == 0:
  print("None")
Buggy python submission (verdict: Runtime Error):
n=inupt()
if n==n[::-1]:
  print("Yes")
else:
  print("No")

Fixed submission:
n=input()
if n==n[::-1]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
print("YES") if int(input().gsub(" ", "")) % 4 == 0 else print("NO")

Fixed submission:
print("YES") if int(input().replace(" ", "")) % 4 == 0 else print("NO")
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split()) 
if a + b >= 10:
  print("error") 
else:
  print(sum(a + b)


Fixed submission:
a, b = map(int, input().split()) 
if a + b >= 10:
  print("error") 
else:
  print(a + b)

Buggy python submission (verdict: Runtime Error):
print("error") if sum(input().split()) >= 10 else print(sum(input().split()))

Fixed submission:
a, b = map(int, input().split()) 
if a + b >= 10:
  print("error") 
else:
  print(a + b)
Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main(){
  int N, K, a, b, S, ans;
  cin >> N >> K;
  
  vector<int> C(100000);
  
  for (int i = 0; i < N; i++){
    cin >> a >> b;
    C.at(a-1) += b;
  }
  
  for (int i = 0; i < N; i++){
    S += C.at(i);
    if (S >= K){
      cout << i+1 << endl;
      break;
    }
  }
}

Fixed submission:
A, B, C = map(int, input().split())
if A <= C and C <= B:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
if A =< C and C =< B:
  print("Yes")
else:
  print("No")


Fixed submission:
A, B, C = map(int, input().split())
if A <= C and C <= B:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
if A =< C =< B:
  print("Yes")
else:
  print("No")

Fixed submission:
A, B, C = map(int, input().split())
if A <= C and C <= B:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
a, b, c, = map(int, input().split())
print("Yes") if a <= c =< b else print("No")

Fixed submission:
A, B, C = map(int, input().split())
if A <= C and C <= B:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
a, b, c, = map(int, input().split())
pront("Yes") if a <= c =< b else print("No")

Fixed submission:
A, B, C = map(int, input().split())
if A <= C and C <= B:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
V, E = map(int, input().split())
G = [[] for i in range(V+1)]
for i in range(E):
    a, b, c = map(int, input().split())
    G[a-1].append((b-1, 0-c))
G[V-1].append((V, 0))

INF = float('inf')
dist = [INF] * (V + 1)
dist[0] = 0
Flag = False

for i in range(V+1):
    UnUpdate = True
    for v, e in enumerate(G):
        for t, cost in e:
            if dist[v] != INF and dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                UnUpdate = False
    if UnUpdate and i < V:
        Flag = True
        break

if Flag:
    print(0-dist[V])
else:
    print(1/0)

Fixed submission:
INF = float('inf')


def Bellmanford(node, edges, source):
    d = [INF] * node  # ある頂点までのコストを保存するリスト
    d[source] = 0

    for i in range(node):
        for start, goal, cost in edges:
            # 辺の始まりの頂点までのコストが INF でなく
            # 辺の向かう先の頂点のコストが、より軽くなる場合に、
            # リストを更新する
            if d[start] != INF and d[start] + cost < d[goal]:
                d[goal] = d[start] + cost
                if i == node-1 and goal == node-1:
                    return 'inf'
    return -d[node-1]


N, M = map(int, input().split())
abc = [map(int, input().split()) for _ in range(M)]
Edges = [None] * M

for i in range(M):
    ai, bi, ci = abc[i]
    Edges[i] = (ai-1, bi-1, -ci)


ans = Bellmanford(N, Edges, 0)
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c=input().split()
print("YES") if a[len(a)] == b[0] and b[len(b)] == c[0] else print("NO")

Fixed submission:
S = input().split()
if S[0][-1] == S[1][0] and S[1][-1] == S[2][0]:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())

if A > B:
  print("GREATER")
else if A < B:
  print("LESS")
else:
  print("EQUAL")

Fixed submission:
A = int(input())
B = int(input())

if A > B:
  print("GREATER")
elif A < B:
  print("LESS")
else:
  print("EQUAL")
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
if b - a == c - b:
  print("YES")
else:
  pront("NO")

Fixed submission:
a, b, c = map(int, input().split())
if b - a == c - b:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
A, op, C = map(str, input().split())
if op == "+":
  print(int(A) + int(B))
else:
  print(int(A) - int(B))

Fixed submission:
A, op, B = map(str, input().split())
if op == "+":
  print(int(A) + int(B))
else:
  print(int(A) - int(B))
Buggy python submission (verdict: Runtime Error):
def f(S,L):
  if not L:
    return True
  if L >= 7:
    if S[-7:] == "dreamer":
      return f(S[:-7],L-7)
  if L >= 6:
    if S[-6:] == "eraser":
      return f(S[:-6],L-6)
  if L >= 5:
    if S[-5:] == "dream" or S[-5:] == "erase":
      return f(S[:-5],L-5)
  return False

s = input()
if f(s, len(s)):
  print("YES")
else:
  print("NO")

Fixed submission:
S = input()
L = len(S)

while L:
  f = True
  if L >= 7:
    if S[L-7:L] == "dreamer":
      L -= 7
      f = False
  if L >= 6:
    if S[L-6:L] == "eraser":
      L -= 6
      f = False
  if L >= 5:
    if S[L-5:L] == "dream" or S[L-5:L] == "erase":
      L -= 5
      f = False
  if f:
    break

if L:
  print("NO")
else:
  print("YES")
Buggy python submission (verdict: Runtime Error):
import sys

S = [int(i) for i in input().split()]
T = sum(T)/2

for i in range(3):
  if S[i] == T:
    print("Yes")
    sys.exit()
    
print("No")

Fixed submission:
import sys

S = [int(i) for i in input().split()]
T = sum(S)/2

for i in range(3):
  if S[i] == T:
    print("Yes")
    sys.exit()
    
print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A, T = [0 for i in range(N)], [0 for i in range(N)]
T[0], A[0] = map(int, input().split())

for i in range(1, N):
  dt, da = map(int, input().split())
  for j in range(max(A[i-1]//da, T[i-1]//dt)+3):
    if A[i-1] <= j * da and T[i-1] <= j * dt:
      n = j
      break
      
  T[i], A[i] = dt * n, da * n

print(A[N-1] + T[N-1])

Fixed submission:
import math

N = int(input())
A, T = [0 for i in range(N)], [0 for i in range(N)]
T[0], A[0] = map(int, input().split())

for i in range(1, N):
  dt, da = map(int, input().split())
  for j in range(max(A[i-1]//da, T[i-1]//dt)-1, max(A[i-1]//da, T[i-1]//dt)+3):
    if A[i-1] <= j * da and T[i-1] <= j * dt:
      n = j
      break
      
  T[i], A[i] = dt * n, da * n

print(A[N-1] + T[N-1])

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

N = int(input())
A, T = [0 for i in range(N)], [0 for i in range(N)]
T[0], A[0] = map(int, input().split())

for i in range(1, N):
  dt, da = map(int, input().split())
  for j in range(10**9):
    if A[i-1] <= j * da and T[i-1] <= j * dt:
      n = j
      break
      
  T[i], A[i] = dt * n, da * n

print(A[N-1] + T[N-1])

Fixed submission:
import math

N = int(input())
A, T = [0 for i in range(N)], [0 for i in range(N)]
T[0], A[0] = map(int, input().split())

for i in range(1, N):
  dt, da = map(int, input().split())
  for j in range(max(A[i-1]//da, T[i-1]//dt)-1, max(A[i-1]//da, T[i-1]//dt)+3):
    if A[i-1] <= j * da and T[i-1] <= j * dt:
      n = j
      break
      
  T[i], A[i] = dt * n, da * n

print(A[N-1] + T[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A, T = [0] * N, [0] * N
T[0], A[0] = map(int, input().split())

for i in range(1, N):
  dt, da = map(int, input().split())
  t, a = dt, da
  
  while t < T[i-1] or a < A[i-1]:
    t += dt
    a += da
  
  T[i], A[i] = t, a
  
print(A[-1] + T[-1])

Fixed submission:
import math

N = int(input())
A, T = [0 for i in range(N)], [0 for i in range(N)]
T[0], A[0] = map(int, input().split())

for i in range(1, N):
  dt, da = map(int, input().split())
  for j in range(max(A[i-1]//da, T[i-1]//dt)-1, max(A[i-1]//da, T[i-1]//dt)+3):
    if A[i-1] <= j * da and T[i-1] <= j * dt:
      n = j
      break
      
  T[i], A[i] = dt * n, da * n

print(A[N-1] + T[N-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(i) for i in input().split()]
S = 0
for i in range(N):
  if a[a[i]] == i:
    S += 1
print(S//2)

Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]
S = 0
for i in range(N):
  if a[a[i]-1] == i+1:
    S += 1
print(S//2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P=list(map(int,input().split()))

a=1
for i in range(N):
  if(P[i]==0):
    a=-1
    break
if a!=0:
  for i in range(N):
    a*=P[i]
    if(a>1000000000000000000):
      a=-1
      break
print(a)

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

a=1
for i in range(N):
  if(P[i]==0):
    a=0
    break
if a!=0:
  for i in range(N):
    a*=P[i]
    if(a>1000000000000000000):
      a=-1
      break
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
import math
k=int(input())
s=0
for a in range(k):
  for b in range(k):
    for c in range(k):
      s+=math.gcd(math.gcd(a+1,b+1),c+1)
print(s)

Fixed submission:
import math
k=int(input())
s=0
for a in range(k):
  for b in range(k):
    x=math.gcd(a+1,b+1)
    for c in range(k):
      s+=math.gcd(x,c+1)
print(s)
Buggy python submission (verdict: Runtime Error):
    i = int(input())
    a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    print(a[i - 1])

Fixed submission:
i = int(input())
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[i - 1])

Buggy python submission (verdict: Runtime Error):
i = int(input())
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[i + 1])

Fixed submission:
i = int(input())
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[i - 1])
Buggy python submission (verdict: Runtime Error):
from collections import Counter

N,M = map(int,input().split())
num = [i for i in range(N+1)]
ab = [list(map(int,input().split())) for _ in range(M)]

ab.sort()

for a,b in ab:
    m = min(num[a],num[b])
    num[a] = num[b] = m

print(max(Coutner(num).values()))

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



N,M = map(int,input().split())
uf = UnionFind(N)

for _ in range(M):
    a,b = map(int,input().split())
    uf.union(a-1,b-1)

ans = 1
for i in range(N):
    ans = max(ans,uf.size(i))

print(ans)
Buggy python submission (verdict: Runtime Error):
def res(n):
    pos = n
    cnt = 1
    while 1:
        pos = P[pos]-1
        if pos == n:
            break
        cnt += 1

    tmp = 0
    pos = n
    ans = []

    for _ in range(min(K,cnt)):
        pos = P[pos]-1
        tmp += C[pos]
        ans.append(tmp)
    
    pos =
    ##ループして0以上なら(K//cnt)回ループしてあまりをシミュレーション
    if tmp > 0:
        d = K%cnt
        tmp = (K//cnt)*tmp
        ans.append(tmp)
        for _ in range(d):
            pos = P[pos]-1
            tmp += C[pos]
            ans.append(tmp)

    return max(ans)

            
N,K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = -1e20
for i in range(N):
    ans = max(ans,res(i))

print(ans)


Fixed submission:
def res(n):
    pos = n
    cnt = 1
    while 1:
        pos = P[pos]-1
        if pos == n:
            break
        cnt += 1

    tmp = 0
    ans = -float("inf")
    pos = n

    for _ in range(min(K,cnt)):
        pos = P[pos]-1
        tmp += C[pos]
        ans = max(ans,tmp)
    
    ##ループして0以上なら(K//cnt)回ループしてあまりをシミュレーション
    if tmp > 0 and K > cnt:
        pos = n
        d = K%cnt
        tmp = (K//cnt-1)*tmp
        ans = max(ans,tmp)
        for _ in range(d+cnt):
            pos = P[pos]-1
            tmp += C[pos]
            ans = max(ans,tmp)

    return ans

N,K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = -float("inf")
for i in range(N):
    ans = max(ans,res(i))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil

def BinarySearch(x):
    ans = sum([ceil(a/x)-1 for a in A])
    if ans <= K:
        return True
    else:
        return False

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

r = max(A)
l = 0
eps = 10**-7

while abs(r-l) > eps:

    m = (r+l)/2

    if BinarySearch(m):
        r = m
    else:
        l = m

print(ceil(r)) 


Fixed submission:
from math import ceil

def BinarySearch(x):
    ans = sum([ceil(a/x)-1 for a in A])
    if ans <= K:
        return True
    else:
        return False

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

r = max(A)
l = 0
eps = 10**-6

while abs(r-l) > eps:

    m = (r+l)/2

    if BinarySearch(m):
        r = m
    else:
        l = m

print(ceil(r))

Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil

def BinarySearch(x):
    ans = sum([ceil(a/x)-1 for a in A])
    if ans <= K:
        return True
    else:
        return False

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

r = max(A)
l = 0
eps = 10**-10

while abs(r-l) > eps:

    m = (r+l)/2

    if BinarySearch(m):
        r = m
    else:
        l = m

print(ceil(r)) 


Fixed submission:
from math import ceil

def BinarySearch(x):
    ans = sum([ceil(a/x)-1 for a in A])
    if ans <= K:
        return True
    else:
        return False

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

r = max(A)
l = 0
eps = 10**-6

while abs(r-l) > eps:

    m = (r+l)/2

    if BinarySearch(m):
        r = m
    else:
        l = m

print(ceil(r))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
conv = [0]*(N+1)
for i in range(1,N+1):
    for j in range(1,N//i+1):##その数の倍数をメモ
        conv[i*j-1] += 1
   
##print(conv)
print(sum([(i+1)*conv[i] for i in range(N)]))

Fixed submission:
N = int(input())
conv = [0]*(N+1)
for i in range(1,N+1):
    for j in range(1,N//i+1):##その数の倍数をメモ
        conv[i*j-1] += 1
   
##print(conv)
print(sum([(i+1)*conv[i] for i in range(N)]))
Buggy python submission (verdict: Runtime Error):
"""
https://atcoder.jp/contests/tokiomarine2020/submissions/14229099
"""
N,K = map(int,input().split())
A = list(map(int,input().split()))
 
def update(A):
    b = [0]*N
    for i,a in enumerate(A):
        l = max(0,i-a)
        r = min(N-1,i+a)
        b[l] += 1
        if r+1 < N:
            b[r+1] -= 1
    res = []
    s = 0
    for i in b:
        s += i
        res.append(s)
    return res
 
for _ in range(min(K,30)):
    A = update(A)
 
print(*A)

Fixed submission:
S = input()
print(S[:3])

Buggy python submission (verdict: Runtime Error):
"""
https://atcoder.jp/contests/tokiomarine2020/submissions/14229099
"""
N,K = map(int,input().split())
A = list(map(int,input().split()))
 
def update(A):
    b = [0]*N
 
    for i,a in enumerate(A):
        l = max(0,i-a)
        r = min(N-1,i+a)
 
        b[l] += 1
        if r+1 < N:
            b[r+1] -= 1
    
    res = []
    s = 0
    for i in b:
        s += i
        res.append(s)
    return res
 
for _ in range(min(K,50)):
    A = update(A)
 
print(*A)

Fixed submission:
S = input()
print(S[:3])
Buggy python submission (verdict: Runtime Error):
N = int(input())
ab = []
for i in range(N):
    ab.append(tuple(map(int,input().split())))
 
up = sorted(ab,key=lambda a:a[0],reverse=True)
down = sorted(ab,key=lambda a:a[1],reverse=True)
 
if N%2 == 1:
    print(up[N//2][1]-down[N//2][0]+1)
else:
  up2 = sorted(ab,key=lambda a:a[0],reverse=True)
  down2 = sorted(ab,key=lambda a:a[1],reverse=True)
    r = (up[N//2][1]+up2[N//2][1])
    l = (down[N//2][0]+down2[N//2][0])
    print(r-l+1)

Fixed submission:
N = int(input())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if N%2 == 1:
    print(B[N//2]-A[N//2]+1)
else:
    r = (B[N//2-1]+B[N//2])
    l = (A[N//2-1]+A[N//2])
    print(r-l+1)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if N%2 == 1:
    print(B[N//2][1]-A[N//2][0]+1)
else:
    r = (B[N//2-1][1]+B[N//2][1])
    l = (A[N//2-1][0]+A[N//2][0])
    print(r-l+1)

Fixed submission:
N = int(input())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if N%2 == 1:
    print(B[N//2]-A[N//2]+1)
else:
    r = (B[N//2-1]+B[N//2])
    l = (A[N//2-1]+A[N//2])
    print(r-l+1)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict,deque

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

loop = N
pos = 0
oto = defaultdict(int)
ind = 0
tej = deque([])
for i in range(N):
    pos = A[pos] - 1
    tej.append(pos+1)
    if oto[pos] == 1:
        ind = A.index(pos+1)
        loop = i - ind + 1
        break
    oto[pos] = 1

##print("loop",loop,"ind",ind)
##print(tej)
if K <= ind:
    print(tej[K])
else:
    print(tej[(K-ind)%loop+max(0,ind-1)])

Fixed submission:
from collections import defaultdict,deque

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

loop = N
pos = 0
oto = defaultdict(int)
ind = 0
tej = deque([])
for i in range(N):
    pos = A[pos] - 1
    tej.append(pos+1)
    if oto[pos] == 1:
        ind = tej.index(pos+1)
        loop = i - ind 
        break
    oto[pos] = 1
K -= 1
##print("loop",loop,"ind",ind)
##print(tej)
if K <= ind:
    print(tej[K])
else:
    print(tej[(K-ind)%loop+ind])

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

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

loop = N
pos = 0
oto = defaultdict(int)
ind = 0
tej = []
for i in range(N):
    pos = A[pos] - 1
    tej.append(pos+1)
    if oto[pos] == 1:
        ind = A.index(pos+1)
        loop = i - ind + 1
        break
    oto[pos] = 1

##print("loop",loop,"ind",ind)
##print(tej)
if K <= ind:
    print(tej[K])
else:
    print(tej[K%loop+ind])

Fixed submission:
from collections import defaultdict,deque

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

loop = N
pos = 0
oto = defaultdict(int)
ind = 0
tej = deque([])
for i in range(N):
    pos = A[pos] - 1
    tej.append(pos+1)
    if oto[pos] == 1:
        ind = tej.index(pos+1)
        loop = i - ind 
        break
    oto[pos] = 1
K -= 1
##print("loop",loop,"ind",ind)
##print(tej)
if K <= ind:
    print(tej[K])
else:
    print(tej[(K-ind)%loop+ind])
Buggy python submission (verdict: Time Limit Exceeded):
import math

X = int(input())

for i in range(-int(X**0.2),int(1e7)):
    tmp = (X+i**5)**0.2
    if tmp%1 == 0:
        print(int(tmp),i)
        exit()
    

Fixed submission:
X = int(input())

for i in range(-1000,1000):
    for j in range(-1000,1000):
        if i**5 - j**5 == X:
            print(i,j)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
S = input()[::-1]
P = [0]*(len(S)+1)
for i,j in enumerate((S)):
    P[i+1] = (P[i] + int(j)*pow(10,i))

dp = [0]*2019
for i in P:
    dp[i%2019] += 1
print(sum([i*(i-1)//2 for i in dp]))


Fixed submission:
P = 2019
S = input()
N = len(S)
res = 0
 
if P in [2,5]:
    for i in range(N):
        if int(S[i])% P == 0:
            res += i+1
else:
    dic = {0:1}
    t1 = 0
    t2 = 1
    for i in range(N):
        t2 = (10*t2) % P
        t1 = (int(S[N-1-i])*t2 + t1) % P
        if t1 in dic:
            res += dic[t1]
            dic[t1] += 1
        else:
            dic[t1] = 1
 
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()[::-1]
dp = [0]*2019
dp[0] = 1
P = [int(S[:i][::-1]) for i in range(1,len(S)+1)]
for i in P:
    dp[i%2019] += 1
print(sum([i*(i-1)//2 for i in dp]))

Fixed submission:
P = 2019
S = input()
N = len(S)
res = 0
 
if P in [2,5]:
    for i in range(N):
        if int(S[i])% P == 0:
            res += i+1
else:
    dic = {0:1}
    t1 = 0
    t2 = 1
    for i in range(N):
        t2 = (10*t2) % P
        t1 = (int(S[N-1-i])*t2 + t1) % P
        if t1 in dic:
            res += dic[t1]
            dic[t1] += 1
        else:
            dic[t1] = 1
 
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()[::-1]
dp = [0]*2019
dp[0] = 1
for i in range(1,len(S)+1):
    dp[int(S[:i][::-1])%2019] += 1
print(sum([i*(i-1)//2 for i in dp]))

Fixed submission:
P = 2019
S = input()
N = len(S)
res = 0
 
if P in [2,5]:
    for i in range(N):
        if int(S[i])% P == 0:
            res += i+1
else:
    dic = {0:1}
    t1 = 0
    t2 = 1
    for i in range(N):
        t2 = (10*t2) % P
        t1 = (int(S[N-1-i])*t2 + t1) % P
        if t1 in dic:
            res += dic[t1]
            dic[t1] += 1
        else:
            dic[t1] = 1
 
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()[::-1]
dp = [0]*2019
dp[0] = 1
for i in range(1,len(S)+1):
    dp[int(S[:i][::-1])%2019] += 1

print(sum([i*(i-1)//2 for i in dp]))

Fixed submission:
P = 2019
S = input()
N = len(S)
res = 0
 
if P in [2,5]:
    for i in range(N):
        if int(S[i])% P == 0:
            res += i+1
else:
    dic = {0:1}
    t1 = 0
    t2 = 1
    for i in range(N):
        t2 = (10*t2) % P
        t1 = (int(S[N-1-i])*t2 + t1) % P
        if t1 in dic:
            res += dic[t1]
            dic[t1] += 1
        else:
            dic[t1] = 1
 
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
l = len(S)
ans = 0
for i in range(l+1):
    for j in range(l-i):
        if int(S[j:i+j+1])%2019 == 0:
            ans += 1
print(ans)

Fixed submission:
P = 2019
S = input()
N = len(S)
res = 0
 
if P in [2,5]:
    for i in range(N):
        if int(S[i])% P == 0:
            res += i+1
else:
    dic = {0:1}
    t1 = 0
    t2 = 1
    for i in range(N):
        t2 = (10*t2) % P
        t1 = (int(S[N-1-i])*t2 + t1) % P
        if t1 in dic:
            res += dic[t1]
            dic[t1] += 1
        else:
            dic[t1] = 1
 
print(res)