Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np

S = raw_input()
N = len(S)
T = np.zeros([N,N], dtype=bool)
for i in xrange(0, N):
    if (i-1)>=0 and S[i-1] == "R":
        T[i, i-1] = True
    if (i+1) <N and S[i+1] == "L":
        T[i, i+1] = True
    
Even = np.ones(N, dtype=int) # Last even times status
Stat = np.ones(N, dtype=int) # Current status

for i in xrange(1, 1000):
    Stat = np.dot(T, Stat)
    if i % 2 == 0:
        if np.all(Stat == Even):
            break
        else:
            Even = Stat

print " ".join([str(i) for i in Stat])

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

ans = [0 for _ in xrange(N)]
for i in xrange(0,N-1):
    if S[i] == "R" and S[i+1] == "L":
        # Positon of "RL"
        ans[i] = 1
        ans[i+1] = 1
        # Search the Left wind
        j = 1
        while (i-j) >=0 and S[i-j] == "R":
            if j %2 == 1:
                ans[i+1] += 1
            else:
                ans[i] += 1
            j += 1
        # Search the right wind
        j = 2
        while (i+j) <N and S[i+j] == "L":
            if j %2 == 1:
                ans[i+1] += 1
            else:
                ans[i] += 1
            j += 1
        
print " ".join([str(i) for i in ans])
Buggy python submission (verdict: Runtime Error):

A, P = map(int, raw_input.split())

N_piec = A * 3  + P
N_pie  = N_piec / 2
print N_pie

Fixed submission:
A, P = map(int, raw_input().split())

N_piec = A * 3  + P
N_pie  = N_piec / 2
print N_pie
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, K = map(int, raw_input().split())
A = np.array(map(int, raw_input().split()))
A = np.sort(A)
Sum = A.sum()
if Sum < K:
    print N
else:
    # Find the Smallest Necessary Number 
    # SmallNec = N-1
    A_cumsum = np.concatenate(([0], np.cumsum(A)))
    # SubSet A[0:I]
    I = np.where(A_cumsum<K)[0][-1] + 1
    Sum_ = A_cumsum[I]
    while Sum_ >= K:
        for J in xrange(I-1, -1, -1):
            if A[J] >= Sum_ - K:
                # A[J] is Necessary
                I = J
                pass
            else:
                # A[J] Maybe Unnecessary
                break
        Sum_ = A_cumsum[I]
    print I

Fixed submission:
from math import sqrt
X = int(raw_input())

ans = 0
Init = int(sqrt(2*X)) + 1
for N in xrange(X+1):
    if (N+1) * N >= 2 * X:
        ans = N
        break
    
print ans

Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
N, K = map(int, raw_input().split())
A = np.array(map(int, raw_input().split()))
A = np.sort(A)
Sum = A.sum()
if Sum < K:
    print N
    sys.exit()
   
A_cumsum = np.concatenate(([0], np.cumsum(A)))
I = np.where(A_cumsum<K)[0][-1] + 1

Sum_ = A_cumsum[I]
while Sum_ > K:
    for J in xrange(I-1, -1, -1):
        if A[J] <= Sum_ - K:
            break
    I = J + 1
    Sum_ = A_cumsum[I]

print I

Fixed submission:
from math import sqrt
X = int(raw_input())

ans = 0
Init = int(sqrt(2*X)) + 1
for N in xrange(X+1):
    if (N+1) * N >= 2 * X:
        ans = N
        break
    
print ans
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = input().split()
A = [int(x) for x in A]

diff, diffm = 0,0

for i in range(len(A)-1):

  diff = max(A[i:]) - A[i]

  if diff > diffm: diffm = diff

print(diffm)

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

total, large = 0,0

for i in A:
  
  if large > i:
    total += (large - i)
  
  if i > large: large = i
    
print(total)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = input().split()
A = [int(x) for x in A]

diff, diffm = 0,0

for i in range(len(A)-1):
  for j in range(len(A)-i-1):
    diff = A[j+i+1] - A[i]
    
    if diff > diffm: diffm = diff
      
print(diffm)

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

total, large = 0,0

for i in A:
  
  if large > i:
    total += (large - i)
  
  if i > large: large = i
    
print(total)
Buggy python submission (verdict: Runtime Error):
'''input
100000 5
'''
from math import ceil, log2
N, K = [int(x) for x in input().split()]

ats = 0.0

for i in range(1, N+1):
	if i >= K:
		ats += 1/N
		continue

	ats += 1/N/(2.0**(float(ceil(log2(K/i)))))

print(ats)

Fixed submission:
'''input
100000 5
'''
from math import ceil, log2
N, K = [int(x) for x in input().split()]

ats = 0.0

for i in range(1, N+1):
	if i >= K:
		ats += 1/N
		continue

	ats += 1/N/(2.0**(float(ceil(log2(K/i)))))

print(ats)

Buggy python submission (verdict: Runtime Error):
'''input
100000 5
'''
from math import ceil, log2
N, K = [int(x) for x in input().split()]

ats = 0.0

for i in range(1, N+1):
	if i >= K:
		ats += 1/N
		continue

	ats += 1/N*2**(-ceil(log2(K/i)))

print(ats)

Fixed submission:
'''input
100000 5
'''
from math import ceil, log2
N, K = [int(x) for x in input().split()]

ats = 0.0

for i in range(1, N+1):
	if i >= K:
		ats += 1/N
		continue

	ats += 1/N/(2.0**(float(ceil(log2(K/i)))))

print(ats)
Buggy python submission (verdict: Time Limit Exceeded):
'''input
100000 1
1 100000 100
'''
import sys
sys.setrecursionlimit(100100)
N, M = [int(x) for x in input().split()]

vien = [[] for _ in range(N)]

for _ in range(M):
	a, b, w = [int(x) for x in input().split()]
	a -= 1
	b -= 1
	w = w & 1
	vien[a].append(b)
	vien[b].append(a)

been = [False]*N
ats = 0
def dfs(x):
	been[x] = True
	for u in vien[x]:
		if not been[u]:
			dfs(u)


for i in range(N):
	if been[i]: continue

	ats += 1
	dfs(i)

print(ats)

Fixed submission:
'''input
100000 1
1 100000 100
'''
import sys
sys.setrecursionlimit(100100)
N, M = [int(x) for x in input().split()]

vien = [[] for _ in range(N)]

for _ in range(M):
	a, b, w = [int(x) for x in input().split()]
	a -= 1
	b -= 1
	w = w & 1
	vien[a].append(b)
	vien[b].append(a)

been = [False]*N
ats = 0
def dfs(x):
	been[x] = True
	for u in vien[x]:
		if not been[u]:
			dfs(u)


for i in range(N):
	if been[i]: continue

	ats += 1
	dfs(i)

print(ats)

Buggy python submission (verdict: Runtime Error):
'''input
100000 1
1 100000 100
'''

N, M = [int(x) for x in input().split()]

vien = [[] for _ in range(N)]

for _ in range(M):
	a, b, w = [int(x) for x in input().split()]
	a -= 1
	b -= 1
	w = w & 1
	vien[a].append(b)
	vien[b].append(a)

been = [False]*N
ats = 0
def dfs(x):
	been[x] = True
	for u in vien[x]:
		if not been[u]:
			dfs(u)


for i in range(N):
	if been[i]: continue

	ats += 1
	dfs(i)

print(ats)

Fixed submission:
'''input
100000 1
1 100000 100
'''
import sys
sys.setrecursionlimit(100100)
N, M = [int(x) for x in input().split()]

vien = [[] for _ in range(N)]

for _ in range(M):
	a, b, w = [int(x) for x in input().split()]
	a -= 1
	b -= 1
	w = w & 1
	vien[a].append(b)
	vien[b].append(a)

been = [False]*N
ats = 0
def dfs(x):
	been[x] = True
	for u in vien[x]:
		if not been[u]:
			dfs(u)


for i in range(N):
	if been[i]: continue

	ats += 1
	dfs(i)

print(ats)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

mod = 10**9+7
ans = 0

for i in range(N-1):
    ans += A[i] * (sum(A[i+1:]))
print(ans%mod)


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

mod = 10**9+7
s = sum(A)
ans = 0

for i in range(N-1):
    s -= A[i]
    ans += A[i] * s
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

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

mod = 10**9+7
c = combinations(A, 2)
ans = 0

for v in c:
    ans += v[0] * v[1]
print(ans%mod)


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

mod = 10**9+7
s = sum(A)
ans = 0

for i in range(N-1):
    s -= A[i]
    ans += A[i] * s
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
import queue

N, M = map(int, input().split())
AB = {}
for i in range(N): AB[i] = set()
for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    AB[A].add(B)
    AB[B].add(A)

finish = [False] * N
q = queue.Queue()
ans = 0
for i in range(N):
    if finish[i]: continue
    q.put(i)
    group = set()
    while not q.empty():
        x = q.get()
        group.add(x)
        finish[x] = True
        for friend in AB[x]:
            if finish[friend]: continue
            q.put(friend)
    ans = max(ans, len(group))
print(ans)


Fixed submission:
import queue

N, M = map(int, input().split())
AB = {}
for i in range(N): AB[i] = set()
for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    AB[A].add(B)
    AB[B].add(A)

finish = [False] * N
q = queue.Queue()
ans = 0
for i in range(N):
    if finish[i]: continue
    q.put(i)
    group = set()
    while not q.empty():
        x = q.get()
        group.add(x)
        finish[x] = True
        for friend in AB[x]:
            if finish[friend]: continue
            q.put(friend)
            finish[friend] = True
    tmp = len(group)
    if tmp >= N / 2:
        ans = tmp
        break
    ans = max(ans, len(group))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#import collections
import numpy

def get_index(l, n):
    tmp = [x for x in l if x <= n]
    return len(tmp)

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

Ac = numpy.cumsum(A)
Bc = numpy.cumsum(B)

ans = 0
for i in range(len(Ac)):
    n = K - Ac[i]
    if n < 0: break
    ans = i + 1
    ans += get_index(Bc, n)
ans = max(ans, get_index(Ac, K), get_index(Bc, K))
print(ans)


'''
#Aq = collections.deque(A)
#Bq = collections.deque(B)

ans = 0
sumt = 0
flag = True
while len(Aq) > 0 and len(Bq) > 0:
    if Aq[0] <= Bq[0]:
        if sumt + Aq[0] > K:
            flag = False
            break
        sumt += Aq.popleft()
        ans += 1
    else:
        if sumt + Bq[0] > K:
            flag = False
            break
        sumt += Bq.popleft()
        ans += 1
if flag:
    if len(Aq) > 0:
        while len(Aq) > 0:
            if sumt + Aq[0] > K:
                break
            sumt += Aq.popleft()
            ans += 1
    else:
        while len(Bq) > 0:
            if sumt + Bq[0] > K:
                break
            sumt += Bq.popleft()
            ans += 1
print(ans)
'''

Fixed submission:
import bisect

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

Ac = [0]*(N+1)
Bc = [0]*(M+1)
for i in range(1, N+1):
    Ac[i] = Ac[i-1] + A[i-1]
for j in range(1, M+1):
    Bc[j] = Bc[j-1] + B[j-1]

ans = 0
for i in range(N+1):
    n = K - Ac[i]
    if n < 0: break
    tmp = bisect.bisect_right(Bc, n) - 1
    ans = max(ans, i + tmp)
    #print(i, tmp, ans, n, Ac, Bc)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def divisors_count(n):
    i = 1
    c = 0
    while i*i <= n:
        if n % i == 0:
            c += 1
            if i != n // i:
                c += 1
        i += 1
    return c

N = int(input())
ans = 0
for i in range(1, N+1):
    ans += i * divisors_count(i)
print(ans)

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

for i in range(1, N+1):
    j = N // i
    ans += int(j * (j+1) * i / 2)
print(ans)

Buggy python submission (verdict: Runtime Error):
import sympy

def divisors_count(n):
    #lower_divisors , upper_divisors = [], []
    i = 1
    c = 0
    while i*i <= n:
        if n % i == 0:
            #lower_divisors.append(i)
            c += 1
            if i != n // i:
                #upper_divisors.append(n//i)
                c += 1
        i += 1
    #return lower_divisors + upper_divisors[::-1]
    return c

N = int(input())
ans = 0
for i in range(1, N+1):
    ans += i * divisors_count(i)
print(ans)

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

for i in range(1, N+1):
    j = N // i
    ans += int(j * (j+1) * i / 2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N, K = map(int, input().split())
p = list(map(int, input().split()))

c = itertools.combinations(p, K)
ans = 10**10
for i in c:
    ans = min(ans, sum(i))
print(ans)

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

p.sort()
print(sum(p[:K]))
Buggy python submission (verdict: Time Limit Exceeded):
import time
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]

num = {}
for i in A:
    if i in num:
        num[i] += 1
    else:
        num[i] = 1
for i in range(Q):
    p, n = BC[i][0], BC[i][1]
    if p in num:
        if n in num:
            num[n] += num[p]
        else:
            num[n] = num[p]
        num[p] = 0
    ans = 0
    for k, v in num.items(): ans += k * v
    print(ans)

Fixed submission:
import time
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]

num = [0] * 100010
for i in A:
    num[i] += 1
s = sum(A)

for i in range(Q):
    p, n = BC[i][0], BC[i][1]
    s += (n - p) * num[p]
    num[n] += num[p]
    num[p] = 0
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]

for i in range(Q):
    p, n = BC[i][0], BC[i][1]
    A = [x if x != p else n for x in A]
    print(sum(A))

Fixed submission:
import time
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]

num = [0] * 100010
for i in A:
    num[i] += 1
s = sum(A)

for i in range(Q):
    p, n = BC[i][0], BC[i][1]
    s += (n - p) * num[p]
    num[n] += num[p]
    num[p] = 0
    print(s)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
dp = [0] * max(A)

for i in range(N):
    if dp[A[i]-1] != 0:
        dp[A[i]-1] = 2
        continue
    else:
        for j in range(1, max(A)//A[i]+1):
            dp[A[i]*j-1] += 1

ans = 0
for i in range(N):
    if dp[A[i]-1] == 1:
        ans += 1
print(ans)

Fixed submission:
from numba import njit

N = int(input())
A = list(map(int, input().split()))
maxA = max(A)
dp = [0] * maxA

for i in range(N):
    if dp[A[i]-1] != 0:
        dp[A[i]-1] = 2
        continue
    else:
        for j in range(1, maxA//A[i]+1):
            dp[A[i]*j-1] += 1

ans = 0
for i in range(N):
    if dp[A[i]-1] == 1:
        ans += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr
    ref = arr[0]
    ref_count = 0
    for ele in arr:
        if ele < ref:
            left.append(ele)
        elif ele > ref:
            right.append(ele)
        else:
            ref_count += 1
    left = quick_sort(left)
    right = quick_sort(right)
    return right + [ref] * ref_count + left

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

A = [x for x in A if A.count(x) == 1]
A = quick_sort(A)

ans = 0
if len(A) == 0:
    print(ans)
    exit()
for i in range(N):
    flag = True
    for j in range(i+1, N):
        if A[i] % A[j] == 0:
            flag = False
            break
    if flag: ans += 1
print(ans)

Fixed submission:
from numba import njit

N = int(input())
A = list(map(int, input().split()))
maxA = max(A)
dp = [0] * maxA

for i in range(N):
    if dp[A[i]-1] != 0:
        dp[A[i]-1] = 2
        continue
    else:
        for j in range(1, maxA//A[i]+1):
            dp[A[i]*j-1] += 1

ans = 0
for i in range(N):
    if dp[A[i]-1] == 1:
        ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 0
for i, v in enumerate(A):
    flag = True    
    for j, w in enumerate(A):
        if j == i: continue
        if v % w == 0:
            flag = False
            break
    if flag: ans += 1
print(ans)

Fixed submission:
from numba import njit

N = int(input())
A = list(map(int, input().split()))
maxA = max(A)
dp = [0] * maxA

for i in range(N):
    if dp[A[i]-1] != 0:
        dp[A[i]-1] = 2
        continue
    else:
        for j in range(1, maxA//A[i]+1):
            dp[A[i]*j-1] += 1

ans = 0
for i in range(N):
    if dp[A[i]-1] == 1:
        ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

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

ans = reduce(mul, A)
if ans > 10**18: ans = -1

print(ans)

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

ans = 1
if 0 in A:
    ans = 0
else:
    for i in A:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix

n, m = map(int, input().split())
l = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
  a, b = map(int, input().split())
  l[a-1][b-1] = 1
  l[b-1][a-1] = 1

csr = csr_matrix(l)
d, p = shortest_path(csr, method='D', indices=0, directed=False, unweighted=True, return_predecessors=True)
#d, p = shortest_path(csr, indices=0, directed=False, unweighted=True, return_predecessors=True)
p += 1
#print(p)
print('Yes')
for i in p:
  if i < 0: continue
  print(i)

Fixed submission:
import sys
import math
import numpy as np
from collections import deque

def I():
  return int(input())
def IS():
  return map(int, input().split())
def IL():
  return [int(x) for x in input().split()]
def ILL(n):
  return [list(map(int, input().split())) for _ in range(n)]
def S():
  return input()
def SS():
  return input().split()

def main():
  N, M = IS()
  to = [[] for _ in range(N)]
  INF = float('inf')
  for i in range(M):
    A, B = IS()
    A -= 1
    B -= 1
    to[A].append(B)
    to[B].append(A) 
  # queue
  q = deque()
  q.append(0)
  # diatance to first room
  dist = [INF] * N
  # previous room
  prev = [-1] * N
 
  #### BFS ####
  while len(q) != 0:
    # pop from queue
    v = q.popleft()
    # seatch room of v's neighboor
    for u in to[v]:
      if prev[u] == -1:
        dist[u] = dist[v] + 1
        prev[u] = v
        q.append(u)
  # print answer
  print("Yes")
  for i in range(1, len(prev)):
    print(prev[i] + 1)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix

n, m = map(int, input().split())
l = [[0 for _ in range(m)] for _ in range(m)]
for _ in range(m):
  a, b = map(int, input().split())
  l[a-1][b-1] = 1
  l[b-1][a-1] = 1

csr = csr_matrix(l)
d, p = shortest_path(csr, indices=0, directed=False, unweighted=True, return_predecessors=True)
p += 1

print('Yes')
for i in p:
  if i < 0: continue
  print(i)

Fixed submission:
import sys
import math
import numpy as np
from collections import deque

def I():
  return int(input())
def IS():
  return map(int, input().split())
def IL():
  return [int(x) for x in input().split()]
def ILL(n):
  return [list(map(int, input().split())) for _ in range(n)]
def S():
  return input()
def SS():
  return input().split()

def main():
  N, M = IS()
  to = [[] for _ in range(N)]
  INF = float('inf')
  for i in range(M):
    A, B = IS()
    A -= 1
    B -= 1
    to[A].append(B)
    to[B].append(A) 
  # queue
  q = deque()
  q.append(0)
  # diatance to first room
  dist = [INF] * N
  # previous room
  prev = [-1] * N
 
  #### BFS ####
  while len(q) != 0:
    # pop from queue
    v = q.popleft()
    # seatch room of v's neighboor
    for u in to[v]:
      if prev[u] == -1:
        dist[u] = dist[v] + 1
        prev[u] = v
        q.append(u)
  # print answer
  print("Yes")
  for i in range(1, len(prev)):
    print(prev[i] + 1)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import math

a, b, n = map(int, input().split())
ans = 0
for x in range(1, n+1):
    ans = max(ans, (math.floor(a * x / b) - a * math.floor(x / b)))
print(ans)

Fixed submission:
import math

a, b, n = map(int, input().split())
x = min(b-1, n)
ans = math.floor(a * x / b) - a * math.floor(x / b)
print(ans)
Buggy python submission (verdict: Runtime Error):
s, w = map(int, input())
if w >= s:
    print('unsafe')
else:
    print('safe')

Fixed submission:
s, w = map(int, input().split())
if w >= s:
    print('unsafe')
else:
    print('safe')
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ans = 0
l = len(s)

for i in range(l - 3):
    if int(s[i:i+2]) % 2 != 0:
        continue
    else:
        for j in range(i + 4, l + 1):
            sub_s = int(s[i:j])
            if sub_s % 2019 == 0: ans += 1
print(ans)

Fixed submission:
s = input()[::-1]

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ans = 0
l = len(s)

for i in range(l - 3):
    if int(s[i:i+2]) % 2 != 0: continue
    for j in range(i + 4, l + 1):
        sub_s = int(s[i:j])
        if sub_s % 2019 == 0: ans += 1
print(ans)

Fixed submission:
s = input()[::-1]

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ans = 0

for i in range(len(s) - 3): 
    for j in range(i + 4, len(s) + 1):
        sub_s = int(s[i:j])
        if sub_s % 2019 == 0: ans += 1
print(ans)

Fixed submission:
s = input()[::-1]

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
mod = 10**9 + 7

if n + 1 == k:
    print(1)
    exit()

n_list = [i for i in range(n+1)]
ans = 0
for i in range(k, n+2): 
    min_num = sum(n_list[:i])
    max_num = sum(n_list[-i:])
    ans += (max_num - min_num + 1)
print(ans % mod)

Fixed submission:
n, k = map(int, input().split())
mod = 10**9 + 7

ans = 0
for i in range(k, n+2): 
    a = 0.5 * i * (i - 1)
    b = 0.5 * i * (2 * n - i + 1)
    ans += (b - a + 1)
print(int(ans % mod))
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0
for a in range(1,k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += gcd(a,b,c)
print(ans)

Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0
for a in range(1,k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            if a == b and b == c:
                ans += gcd(a,b,c)
            elif (a == b and b != c) or (a != b and b == c):
                ans += gcd(a,b,c) * 3
            elif a != b and b != c:
                ans += gcd(a,b,c) * 6
            else:
                print('error')
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
runrun_counter = 0
no_runrun = False
ans = 0
for i in range(1,10**8):
    if i < 10:
        ans = i
        runrun_counter += 1
    else:
        num = [int(s) for s in list(str(i))]
        for n in range(len(num)-1):
            if abs(num[n]-num[n+1]) > 1:
                no_runrun = True
                break
        if not no_runrun:
            runrun_counter += 1
            ans = int(''.join(map(str, num)))
        no_runrun = False
    if runrun_counter == k:
        print(ans)
        exit()

Fixed submission:
import queue

k = int(input())
q = queue.Queue()
x = -1
for i in range(1,10):
    q.put(i)
for i in range(1,k+1):
    x = q.get()
    if x % 10 != 0:
        q.put(10 * x + (x % 10) - 1)
    q.put(10 * x + (x % 10))
    if x % 10 != 9:
        q.put(10 * x + (x % 10) + 1)
print(x)