Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict


def warshall_floyd(graph: dict, N: int):
    """ graph:
    {node:{node:cost,node:cost,...},
     node:{node:cost,node:cost,...},...}
    """
    INF = float("inf")
    dp = [[INF] * N for _ in range(N)]
    for i in range(N):
        dp[i][i] = 0

    # Step 1: fill dp
    for v1, edges in graph.items():
        for v2, cost in edges.items():
            dp[v1][v2] = cost

    # search
    for k in range(N):  # 中継点
        for i in range(N):  # 始点
            for j in range(N):  # 終点
                dp[i][j] = min(dp[i][k] + dp[k][j], dp[i][j])

    return dp


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    graph = defaultdict(dict)
    for _ in range(n - 1):
        a, b, c = input_int_list()
        graph[a][b] = c
        graph[b][a] = c
    dp = warshall_floyd(graph, n + 1)
    q, k = input_int_list()
    ans = []
    for _ in range(q):
        x, y = input_int_list()
        ans.append(dp[x][k] + dp[k][y])

    for i in ans:
        print(i)

    return


if __name__ == "__main__":
    main()


Fixed submission:
import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict
from heapq import heappop, heappush


class Dijkstra:
    """Graph input:
    {
    node:{node:cost,node:cost...},
    node:{node:cost,node:cost...},
    ...
    }
    """

    def __init__(self, graph: dict, N: int):
        self.graph = graph
        self.costs = [float("inf")] * N

    def calculate(self, start):
        queue = list()

        # step1: push the start point into the priority queue
        self.costs[start] = 0
        heappush(queue, (0, start))  # (cost,node)

        while queue:
            # step2: get the minimum cost node from unfixed node and fix the cost
            cost_from_start, min_node = heappop(queue)

            # step3: update the direct connected nodes
            for link, cost in self.graph[min_node].items():
                if cost_from_start + cost < self.costs[link]:
                    self.costs[link] = cost_from_start + cost
                    heappush(queue, (self.costs[link], link))

        return self.costs


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    graph = defaultdict(dict)
    for _ in range(n - 1):
        a, b, c = input_int_list()
        graph[a][b] = c
        graph[b][a] = c
    # dp = warshall_floyd(graph, n + 1) O(n**3) => TLD

    q, k = input_int_list()

    solver = Dijkstra(graph, n + 1)
    costs = solver.calculate(k)

    ans = []
    for _ in range(q):
        x, y = input_int_list()
        ans.append(costs[x] + costs[y])
    for i in ans:
        print(i)

    return


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
S = input()
while True:
  S = S[:-1]
  mid = len(S)//2
  if S[:mid] == S[mid:]:
    print(len(S))
    break
  elif S = "":
    break

Fixed submission:
S = input()
while len(S) > 0:
  S = S[:-1]
  mid = len(S)//2
  if S[:mid] == S[mid:]:
    print(len(S))
    break
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N,M = [int(i) for i in input().strip().split()]
    students = [[int(i) for i in input().strip().split()] for _ in range(N)]
    checkpoints = [[int(i) for i in input().strip().split()] for _ in range(N)]
    ans = [0] * N

    for i,student in enumerate(students):
        dist = [float("inf")] * M
        for j, checkpoint in enumerate(checkpoints):
            dist[j] = abs(student[0] - checkpoint[0]) + abs(student[1] - checkpoint[1])
        ans[i] = dist.index(min(dist)) + 1

    return ans


if __name__ == "__main__":
    for n in main():
        print(n)


Fixed submission:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N,M = [int(i) for i in input().strip().split()]
    students = [[int(i) for i in input().strip().split()] for _ in range(N)]
    checkpoints = [[int(i) for i in input().strip().split()] for _ in range(M)]
    ans = [0] * N

    for i,student in enumerate(students):
        dist = [float("inf")] * M
        for j, checkpoint in enumerate(checkpoints):
            dist[j] = abs(student[0] - checkpoint[0]) + abs(student[1] - checkpoint[1])
        ans[i] = dist.index(min(dist)) + 1

    return ans


if __name__ == "__main__":
    for n in main():
        print(n)
Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/agc011/tasks/agc011_b

import sys
input = sys.stdin.buffer.readline

n = int(input())
A = sorted([int(i) for i in input().strip().split()])
_max = A[-1]
cul_sum = [0] * (n + 1)

for i in range(1, n + 1):
    cul_sum[i] = cul_sum[i - 1] + A[i - 1]

ans = -1

cur = 0
ptr = cur
_tmp = cul_sum[ptr]
while True:
    _tmp += A[ptr]
    if _tmp * 2 >= _max:
        ans = cur
        break
    elif _tmp * 2 < A[ptr + 1]:
        cur += 1
        ptr = cur
        _tmp = cul_sum[ptr]
    else:
        ptr += 1

print(n - ans)


Fixed submission:
# https://atcoder.jp/contests/agc011/tasks/agc011_b

import sys
input = sys.stdin.buffer.readline

n = int(input())
A = sorted([int(i) for i in input().strip().split()])
_max = A[-1]
cul_sum = [0] * (n + 1)

for i in range(1, n + 1):
    cul_sum[i] = cul_sum[i - 1] + A[i - 1]

ptr = 0
for i in range(1, n + 1):
    if cul_sum[i] * 2 < A[i]:
        ptr = i
    elif cul_sum[i] * 2 >= _max:
        print(n - ptr)
        sys.exit()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def get_prime(N, prime):
    if N < 2:
        return {1: 1}

    i = 2
    while i * i <= N:
        while N % i == 0:
            if i in prime.keys():
                prime[i] += 1
            else:
                prime[i] = 1
            N = N // i
        i += 1
    if N != 1:
        prime[N] = 1
    return prime


def main():
    N = int(input().strip())
    div_table = [1] * (N + 1)
    MOD = 10**9 + 7
    ans = 0
    for i in range(2, N + 1):
        for j in range(i, N + 1, i):
            div_table[j] += 1

    prime = dict()
    prime[1] = 1

    for i in range(1, N + 1):
        if div_table[i] == 2:
            prime = get_prime(i, prime)
    ans = 1
    for k, v in prime:
        ans *= v
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def get_prime(N):
    prime = dict()
    prime[1] = 1
    i = 2
    while i * i <= N:
        while N % i == 0:
            if i in prime.keys():
                prime[i] += 1
            else:
                prime[i] = 1
            N = N // i
        i += 1
    if N != 1:
        prime[N] = 1
    return prime


def main():
    N = int(input().strip())
    div_table = [0] * (N + 1)
    MOD = 10**9 + 7
    ans = 1
    for i in range(2, N + 1):
        for j in range(i, N + 1, i):
            div_table[j] += 1

    prime = dict()
    for i in range(2, N + 1):
        if div_table[i] == 1:
            prime[i] = 0

    for i in range(2, N + 1):
        _prime = get_prime(i)
        for k, v in _prime.items():
            if k == 1:
                continue
            prime[k] += v

    for k, v in prime.items():
        ans *= v + 1
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
k,s = list(map(int,input().split()))
ans = 0
for x in range(k+1):
  for y in range(k+1):
    for z in range(k+1):
      if x+y+z == s:
        ans += 1
print(ans)

Fixed submission:
k,s = list(map(int,input().split()))
ans = 0
for x in range(k+1):
  for y in range(k+1):
    if s-x-y < k+1 and s-x-y >= 0:
      ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
k,s = list(map(int,input().split()))
ans = 0
for x in range(k+1):
  for y in range(k+1):
    for z in range(k+1):
      if x+y+z = s:
        ans += 1
print(ans)

Fixed submission:
k,s = list(map(int,input().split()))
ans = 0
for x in range(k+1):
  for y in range(k+1):
    if s-x-y < k+1 and s-x-y >= 0:
      ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
#C

K=int(input())
if K==1:
    ans=1
elif K==2 or K==5 or K==10:
    ans=-1
else:
    p=0
    for i in range(1,K+2):
        p = (p*10+7)%K 
        #print(i,p)
        if p==0:
            ans=i
            break

print(ans)

Fixed submission:
#C

K=int(input())
ans=-1
if K==1:
    ans=1
elif K==2 or K==5 or K==10:
    ans=-1
else:
    p=0
    for i in range(1,K+1):
        p = (p*10+7)%K 
        #print(i,p)
        if p==0:
            ans=i
            break

print(ans)

Buggy python submission (verdict: Runtime Error):
#C

K=int(input())
if K==1:
    ans=1
elif K==2 or K==5 or K==10:
    ans=-1
else:
    p=0
    for i in range(1,K+1):
        p = (p*10+7)%K 
        #print(i,p)
        if p==0:
            ans=i
            break

print(ans)

Fixed submission:
#C

K=int(input())
ans=-1
if K==1:
    ans=1
elif K==2 or K==5 or K==10:
    ans=-1
else:
    p=0
    for i in range(1,K+1):
        p = (p*10+7)%K 
        #print(i,p)
        if p==0:
            ans=i
            break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#C

K=int(input())
ans=-1

for i in range(1,10**7):
    tmp= 7*(pow(10,i)-1) // 9
    if tmp%K==0:
        ans=i
        break
print(i)

Fixed submission:
#C

K=int(input())
ans=-1
if K==1:
    ans=1
elif K==2 or K==5 or K==10:
    ans=-1
else:
    p=0
    for i in range(1,K+1):
        p = (p*10+7)%K 
        #print(i,p)
        if p==0:
            ans=i
            break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#C

K=int(input())
ans=-1
for i in range(1,10**8):
    tmp=int("7"*i)
    if tmp%K==0:
        ans=i
        break
print(ans)

Fixed submission:
#C

K=int(input())
ans=-1
if K==1:
    ans=1
elif K==2 or K==5 or K==10:
    ans=-1
else:
    p=0
    for i in range(1,K+1):
        p = (p*10+7)%K 
        #print(i,p)
        if p==0:
            ans=i
            break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc174/tasks/abc174_e

from math import ceil,floor
N,K=map(int,input().split())
A=list(map(int,input().split()))

L=0
R=max(A)
i=0
ans=(L+R)/2
cnt=0
right=0
left=0

while i<1000:
    i +=1
    for num in A:
        cnt += ceil(num/ans)-1
    if cnt <=K:
        R = ans
    elif cnt>=K:
        L = ans
    else:
        #print("fin",i-1,cnt,ans)
        break           
    ans = (R+L)/2
    cnt=0
        
print(ceil(ans))

Fixed submission:
# https://atcoder.jp/contests/abc174/tasks/abc174_e

from math import ceil,floor
N,K=map(int,input().split())
A=list(map(int,input().split()))

L=0
R=max(A)
i=0
ans=(L+R)/2
cnt=0
right=0
left=0

while i<100:
    i +=1
    for num in A:
        cnt += ceil(num/ans)-1
    if cnt <=K:
        R = ans
    elif cnt>=K:
        L = ans
    else:
        #print("fin",i-1,cnt,ans)
        break           
    ans = (R+L)/2
    cnt=0
        
print(ceil(ans))

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc174/tasks/abc174_e

from math import ceil,floor
N,K=map(int,input().split())
A=list(map(int,input().split()))

L=0
R=max(A)
i=0
ans=(L+R)/2
cnt=0
right=0
left=0

while i<1000:
    i +=1
    for num in A:
        cnt += ceil(num/ans)-1
    if cnt <=K:
        R = ans
    elif cnt>=K:
        L = ans
    else:
        #print("fin",i-1,cnt,ans)
        break           
    ans = (R+L)/2
    cnt=0
        
print(ceil(ans))

Fixed submission:
# https://atcoder.jp/contests/abc174/tasks/abc174_e

from math import ceil,floor
N,K=map(int,input().split())
A=list(map(int,input().split()))

L=0
R=max(A)
i=0
ans=(L+R)/2
cnt=0
right=0
left=0

while i<100:
    i +=1
    for num in A:
        cnt += ceil(num/ans)-1
    if cnt <=K:
        R = ans
    elif cnt>=K:
        L = ans
    else:
        #print("fin",i-1,cnt,ans)
        break           
    ans = (R+L)/2
    cnt=0
        
print(ceil(ans))
Buggy python submission (verdict: Runtime Error):
from collections import deque

N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(key=lambda x:abs(x),reverse=True)
MOD=10**9+7

P=[]
M=[]
for num in A:
    if num>=0:
        P.append(num)
    else:
        M.append(num)
       
#print(P,M)
       
if len(M)==N and K%2==1:
    ans= M[-1]
    for j in range(1,K):
        ans = (ans*M[-1-j])%MOD
       
else:
    Q=deque(P)
    R=deque(M)
    cnt=0
    ans_list=[]

    while cnt<K:

        if Q:
            tmp_p=Q.popleft()
        else:
            tmp_p=0

        if len(R)>=2 and K-cnt>=2:
            x= R.popleft()
            y= R.popleft()
            tmp_q= x*y
        else:
            tmp_q=0

        if tmp_p>=tmp_q:
            ans_list.append(tmp_p)
            if tmp_q>0:
                R.appendleft(y)
                R.appendleft(x)
            cnt +=1
        else:
            ans_list.append(x)
            ans_list.append(y)
            Q.appendleft(tmp_p)
            cnt +=2

    #print(cnt, tmp_p, tmp_q,Q,R,ans_list)
       
    ans=ans_list[0]
    for j in range(1,len(ans_list)):
        ans = (ans*ans_list[j])%MOD
       
       
print(ans)


Fixed submission:
N=int(input())
if N%1000==0:
    print(0)
else:
    print(1000-N%1000)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)

ans=A[0]
if N>2:
    p = (N-2)//2
    q = (N-2)%2
#print(p,q)

ans += 2*sum(A[1:1+p])
if q==1:
    ans += A[1+p]

print(ans)

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

ans=A[0]
if N>2:
    p = (N-2)//2
    q = (N-2)%2
    ans += 2*sum(A[1:1+p])
    if q==1:
        ans += A[1+p]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#ABC172-D

def calc(x):
    a=0
    p=floor(x**0.5)
    cnt=0
    for i in range(1,p+1):
        if x%i==0:
            if i!=x//i:
                cnt +=2
            else:
                cnt +=1
    return cnt

from math import floor
N=int(input())
ans=0
for i in range(1,N+1):
    #print(i,calc(i))
    ans += i*calc(i)
print(ans)

Fixed submission:
#ABC172-D

N=int(input())
yaku=[0]+[1]*N

for i in range(2,N+1):
    t=N//i
    for j in range(1,t+1):
        #print(i,j)
        yaku[i*j] +=1
ans=0
for i in range(1,N+1):
    ans += i*yaku[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
# D 

from collections import deque
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=deque(A)
#print(B)

cnt=0
tmp=[]
while B:
    i = B.popleft()
    for j in B:
        flag=True
        if j==i:
            flag=False
        elif j%i==0:
            pass
        else:
            tmp.append(j)
    else:
        if flag:
            cnt += 1
        #print(i,tmp,cnt)
        B=deque(tmp)
        tmp=[]
        continue

print(cnt)

Fixed submission:
# D 

from collections import Counter
N=int(input())
A=list(map(int,input().split()))
A.sort()
maxi=A[-1]
real=set()
forbid=set()
#print(A[0],maxi)
d=dict(Counter(A))
#print(d)

cnt=0
for i in range(N):
    if A[i] not in forbid:
        if d[A[i]]==1:
            cnt +=1
        p=maxi//A[i]
        for j in range(1,p+1):
            forbid.add(j*A[i])
        
        
#print(forbid)
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=[0]+list(map(int,input().split()))+[0]
p=50

if K<=p:    
    for i in range(K):
        B=[0]+[0]*N+[0]
        for j in range(1,N+1):
            left  = max(0,j-A[j])
            right = min(N+1,j+A[j]+1)
            B[left]  += 1
            B[right] -= 1
        A[0]=B[0]
        for k in range(1,N+1):
            A[k]=A[k-1]+B[k]
else:
    A=[N]*(N+2)
print(*A[1:N+1])

Fixed submission:
N,K=map(int,input().split())
A=[0]+list(map(int,input().split()))+[0]
p=50

if K<=p:    
    for i in range(K):
        B=[0]+[0]*N+[0]
        for j in range(1,N+1):
            left  = max(0,j-A[j])
            right = min(N+1,j+A[j]+1)
            B[left]  += 1
            B[right] -= 1
        A[0]=B[0]
        for k in range(1,N+1):
            A[k]=A[k-1]+B[k]
else:
    A=[N]*(N+2)
print(*A[1:N+1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=[0]+list(map(int,input().split()))+[0]
p=100

if K<=p:    
    for i in range(K):
        B=[0]+[0]*N+[0]
        for j in range(1,N+1):
            left  = max(0,j-A[j])
            right = min(N+1,j+A[j]+1)
            B[left]  += 1
            B[right] -= 1
        A[0]=B[0]
        for k in range(1,N+1):
            A[k]=A[k-1]+B[k]
else:
    A=[N]*(N+2)
print(*A[1:N+1])

Fixed submission:
N,K=map(int,input().split())
A=[0]+list(map(int,input().split()))+[0]
p=50

if K<=p:    
    for i in range(K):
        B=[0]+[0]*N+[0]
        for j in range(1,N+1):
            left  = max(0,j-A[j])
            right = min(N+1,j+A[j]+1)
            B[left]  += 1
            B[right] -= 1
        A[0]=B[0]
        for k in range(1,N+1):
            A[k]=A[k-1]+B[k]
else:
    A=[N]*(N+2)
print(*A[1:N+1])
Buggy python submission (verdict: Runtime Error):
A,B,C,K=map(int,input().split())

s = [1]*A+[0]*B+[-1]*C
print(sum(s[:K]))

Fixed submission:
A,B,C,K=map(int,input().split())

a = min(A,K)
t1= K-a
b = min(B,t1)
c = K-a-b

#print(a,b,c)
print(a-c)
Buggy python submission (verdict: Time Limit Exceeded):
def combi(y,x,p=998244353):
  s=fac[y]
  t=fac[x]
  u=fac[y-x]
  ans= (s* pow(t,p-2,p)*pow(u,p-2,p))%p
  return ans

###############################

N,M,K=map(int,input().split())
p=998244353
fac=[1,1]
for i in range(2,N+1):
  fac.append( (fac[-1]*i)%p )


ans=0
for i in range(0,K+1):
  R = ( (M%p) *pow(M-1,N-1-i,p) )%p
  L = combi(N-1,i)
  ans = (ans + (R*L)%p)%p
  
print(ans)

Fixed submission:
def combi(y,x,p=998244353):
  s=fac[y]
  t=fac[x]
  u=fac[y-x]
  ans= (s* pow(t,p-2,p)*pow(u,p-2,p))%p
  return ans

###############################

N,M,K=map(int,input().split())
p=998244353
fac=[1,1]
for i in range(2,N+1):
  fac.append( (fac[-1]*i)%p )


ans=0
for i in range(0,K+1):
  R = ( (M%p) *pow(M-1,N-1-i,p) )%p
  L = combi(N-1,i)
  ans = (ans + (R*L)%p)%p
  
print(ans)

Buggy python submission (verdict: Runtime Error):
def combi(y,x,p=998244353):
  s=fac[y]
  t=fac[x]
  u=fac[y-x]
  ans= (s* pow(t,p-2,p)*pow(u,p-2,p))%p
  return ans

###############################

N,M,K=map(int,input().split())
p=998244353
fac=[1,1]
for i in range(2,N+1):
  fac.append( (fac[-1]*i)%p )
R = M*(M-1)**(N-K-2)

ans=0
for i in range(K,-1,-1):
  R = (R*(M-1))%p
  L = combi(N-1,i)
  #print(i,R,L)
  ans = (ans + (R*L)%p)%p
print(ans)

Fixed submission:
def combi(y,x,p=998244353):
  s=fac[y]
  t=fac[x]
  u=fac[y-x]
  ans= (s* pow(t,p-2,p)*pow(u,p-2,p))%p
  return ans

###############################

N,M,K=map(int,input().split())
p=998244353
fac=[1,1]
for i in range(2,N+1):
  fac.append( (fac[-1]*i)%p )


ans=0
for i in range(0,K+1):
  R = ( (M%p) *pow(M-1,N-1-i,p) )%p
  L = combi(N-1,i)
  ans = (ans + (R*L)%p)%p
  
print(ans)

Buggy python submission (verdict: Runtime Error):
def combi(y,x,p=998244353):
  s=fac[y]
  t=fac[x]
  u=fac[y-x]
  ans= (s* pow(t,p-2,p)*pow(u,p-2,p))%p
  return ans

###############################

N,M,K=map(int,input().split())
p=998244353
fac=[1,1]
for i in range(2,N+1):
  fac.append( (fac[-1]*i)%p )
R = M*(M-1)**(N-K-2)

ans=0
for i in range(K,-1,-1):
  R = (R*(M-1))%p
  L = combi(N,i)
  ans = (ans + (R*L)%p)%p
print(ans)

Fixed submission:
def combi(y,x,p=998244353):
  s=fac[y]
  t=fac[x]
  u=fac[y-x]
  ans= (s* pow(t,p-2,p)*pow(u,p-2,p))%p
  return ans

###############################

N,M,K=map(int,input().split())
p=998244353
fac=[1,1]
for i in range(2,N+1):
  fac.append( (fac[-1]*i)%p )


ans=0
for i in range(0,K+1):
  R = ( (M%p) *pow(M-1,N-1-i,p) )%p
  L = combi(N-1,i)
  ans = (ans + (R*L)%p)%p
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
N=len(S)

T=[0]
for i in range(N):
    p = int(S[-1-i])
    T.append( (T[-1]+(p*(10**i))%2019)%2019 )
    
from collections import Counter
ans=0
U=dict(Counter(T))
for num in U:
    ans += U[num]*(U[num]-1)//2
print(ans)


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

T=[0]
for i in range(N):
    p = int(S[-1-i])
    T.append( (T[-1]+ pow(10,i,2019)*p)%2019 )
    
from collections import Counter
ans=0
U=dict(Counter(T))
for num in U:
    ans += U[num]*(U[num]-1)//2
print(ans)

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

T=[0]
for i in range(N):
    p = int(S[-1-i])
    T.append( (T[-1]+(p*(10**i))%2019)%2019 )
    
from collections import Counter
ans=0
U=dict(Counter(T))
for num in U:
    ans += U[num]*(U[num]-1)//2
print(ans)

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

T=[0]
for i in range(N):
    p = int(S[-1-i])
    T.append( (T[-1]+ pow(10,i,2019)*p)%2019 )
    
from collections import Counter
ans=0
U=dict(Counter(T))
for num in U:
    ans += U[num]*(U[num]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S=input()
n=len(S)

T=[0]*n
U=[0]*n
for i in range(n):
    T[i]=int(S[i:])
    U[i]=T[i]%2019
T.append(0)
U.append(0)
    
#print(T)
#print(U)
#print(Counter(U))
ans=0
di= dict(Counter(U))
for a in di:
    b=di[a]
    if b>=2:
        ans += b*(b-1)//2
print(ans)

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

T=[0]
for i in range(N):
    p = int(S[-1-i])
    T.append( (T[-1]+ pow(10,i,2019)*p)%2019 )
    
from collections import Counter
ans=0
U=dict(Counter(T))
for num in U:
    ans += U[num]*(U[num]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S=input()
n=len(S)

T=[0]*n
U=[0]*n
for i in range(n):
    T[i]=int(S[i:])
    U[i]=T[i]%2019
T.append(0)
U.append(0)
    
#print(T)
#print(U)
#print(Counter(U))
ans=0
di= dict(Counter(U))
for a in di:
    b=di[a]
    if b>=2:
        ans += b*(b-1)//2
print(ans)

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

T=[0]
for i in range(N):
    p = int(S[-1-i])
    T.append( (T[-1]+ pow(10,i,2019)*p)%2019 )
    
from collections import Counter
ans=0
U=dict(Counter(T))
for num in U:
    ans += U[num]*(U[num]-1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
sum=0

for i in range(1,N+1):
  if i%3==0 or i%5==0:
    pass
  else:
    ans += i
    
print(ans)

Fixed submission:
N=int(input())
ans=0

for i in range(1,N+1):
  if i%3==0 or i%5==0:
    pass
  else:
    ans += i
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd

K=int(input())
sum=0

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


Fixed submission:
from math import gcd

K=int(input())
sum=0

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

Buggy python submission (verdict: Runtime Error):
from math import gcd

K=int(input())
sum=0

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

Fixed submission:
from math import gcd

K=int(input())
sum=0

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