Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())

HW_list = []
for i in range(H):
    x = input()
    char_list = list(x)
    if "#" in char_list:
        HW_list.append(char_list)
    else:
        pass

i = 0
while True:
    count = 0
    for j in range(len(HW_list)):
        if HW_list[j][i] == ".":
            count += 1
        
    if count == len(HW_list):
        for j in range(len(HW_list)):
            del HW_list[j][i]
    else:
        i += 1
    if i > len(HW_list) - 1:
        break
    
for j in range(len(HW_list)):
    print("".join(HW_list[j]))

Fixed submission:
H, W = map(int, input().split())

HW_list = []
for i in range(H):
    x = input()
    char_list = list(x)
    if "#" in char_list:
        HW_list.append(char_list)
    else:
        pass

i = 0
while True:
    count = 0
    for j in range(len(HW_list)):
        if HW_list[j][i] == ".":
            count += 1
        
    if count == len(HW_list):
        for j in range(len(HW_list)):
            del HW_list[j][i]

    else:
        i += 1
    if i > len(HW_list[0]) - 1:
        break
    
for j in range(len(HW_list)):
    print("".join(HW_list[j]))
Buggy python submission (verdict: Time Limit Exceeded):
N, M, Q = map(int, input().split())

LR_plane = [[0 for i in range(N)] for j in range(N)]

for i in range(M):
    L, R = map(int, input().split())
    LR_plane[L-1][R-1] += 1

for i in range(Q):
    p, q = map(int, input().split())
    ans = 0
    for j in range(p-1, q):
        for k in range(p-1, q):
            ans += LR_plane[j][k]
    print(ans)


Fixed submission:
N, M, Q = map(int, input().split())

LR_plane = [[0 for i in range(N+1)] for j in range(N+1)]

for i in range(M):
    L, R = map(int, input().split())
    LR_plane[L-1][R-1] += 1

for i in range(N-1, -1, -1):
    for j in range(N+1):
        LR_plane[i][j] = LR_plane[i+1][j] + LR_plane[i][j]
        
for i in range(N+1):
    for j in range(1, N+1):
        LR_plane[i][j] = LR_plane[i][j-1] + LR_plane[i][j]

for i in range(Q):
    p, q = map(int, input().split())
    print(LR_plane[p-1][q-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

West = []
East = []
count = 1
if S[0] == "W":
    WE = "W"
else:
    WE = "E"
for i in range(1, N):
    if S[i] == WE:
        count += 1
    else:
        if S[i] == "W":
            East.append(count)
            WE = "W"
        else:
            West.append(count)
            WE = "E"
        count = 1
if S[N-1] == "E":
    East.append(count)
else:
    West.append(count)

print(min(sum(West) - max(East) + 1, sum(East) - max(West) + 1))


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

leader = S[0]
right = 0
left = 0

for i in range(1, N):
    if S[i] == "W":
        right += 1
        
result = right

for i in range(1, N):
    if S[i-1] == "E":
        left += 1
    if S[i] == "W":
        right -= 1
    result = max(result, right+left)
    
print(N - result - 1)
Buggy python submission (verdict: Runtime Error):
s = input()
K = int(input())
 
sub_s = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        if s[i:j] not in sub_s and len(s[i:j]) == K:
            sub_s.append(s[i:j])
 
sub_s = sorted(sub_s)        
#print(sub_s)
print(sub_s[K-1])


Fixed submission:
s = input()
K = int(input())
 
sub_s = []
for i in range(1, K+1):
    for j in range(len(s) - i + 1):
        sub_s.append(s[j:j+i])
 
sub_s = sorted(list(set(sub_s)))        
#print(sub_s)
print(sub_s[K-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())
 
sub_s = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        if s[i:j] not in sub_s and len(s[i:j]) <= K:
            sub_s.append(s[i:j])
 
sub_s = sorted(sub_s)        
#print(sub_s)
print(sub_s[K-1])

Fixed submission:
s = input()
K = int(input())
 
sub_s = []
for i in range(1, K+1):
    for j in range(len(s) - i + 1):
        sub_s.append(s[j:j+i])
 
sub_s = sorted(list(set(sub_s)))        
#print(sub_s)
print(sub_s[K-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())

sub_s = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        if s[i:j] not in sub_s:
            sub_s.append(s[i:j])

sub_s = sorted(sub_s)        
#print(sub_s)
print(sub_s[K-1])

Fixed submission:
s = input()
K = int(input())
 
sub_s = []
for i in range(1, K+1):
    for j in range(len(s) - i + 1):
        sub_s.append(s[j:j+i])
 
sub_s = sorted(list(set(sub_s)))        
#print(sub_s)
print(sub_s[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

n = int(input())
a = list(map(int, input().split()))

a = sorted(a)
max_a = a[-1]
left_med_a = a[n//2-1]
right_med_a = a[n//2]

if cmb(max_a, left_med_a) < cmb(max_a, right_med_a):
    print(max_a, right_med_a)
else:
    print(max_a, left_med_a)

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

a = sorted(a)
max_a = a[-1]
max_a_harf = (max_a+1) // 2

ans = 0
for i in range(n):
    if abs(max_a_harf - a[i]) < abs(max_a_harf - ans):
        ans = a[i]

print(max_a, ans)

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

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n = int(input())
a = list(map(int, input().split()))

a = sorted(a)
max_a = a[-1]
left_med_a = a[n//2-1]
right_med_a = a[n//2]

if cmb(max_a, left_med_a) < cmb(max_a, right_med_a):
    print(max_a, right_med_a)
else:
    print(max_a, left_med_a)

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

a = sorted(a)
max_a = a[-1]
max_a_harf = (max_a+1) // 2

ans = 0
for i in range(n):
    if abs(max_a_harf - a[i]) < abs(max_a_harf - ans):
        ans = a[i]

print(max_a, ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, Y = map(int, input().split())

for i in range(Y // 10000 + 1):
    for j in range(Y // 5000 + 1):
        k = (Y - i*10000 - j*5000) // 1000
        if (Y - i*10000 - j*5000) % 1000 == 0 and i+j+k == N and k>=0:
            print(i, j, k)
            exit()
        else:
            pass
                
print(-1, -1, -1)

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

for i in range(Y // 10000 + 1):
    for j in range((Y - i*10000) // 5000 + 1):
        remain_money = (Y - i*10000 - j*5000)
        k = remain_money // 1000
        if remain_money % 1000 == 0 and i+j+k == N:
            print(i, j, k)
            exit()
        else:
            pass
                
print(-1, -1, -1)

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

for i in range(Y // 10000 + 1):
    for j in range(Y // 5000 + 1):
        for k in range(Y // 1000 + 1):
            if i+j+k == N:
                if i*10000 + j*5000 + k*1000 == Y:
                    print(i, j, k)
                    exit()
                
print(-1, -1, -1)

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

for i in range(Y // 10000 + 1):
    for j in range((Y - i*10000) // 5000 + 1):
        remain_money = (Y - i*10000 - j*5000)
        k = remain_money // 1000
        if remain_money % 1000 == 0 and i+j+k == N:
            print(i, j, k)
            exit()
        else:
            pass
                
print(-1, -1, -1)
Buggy python submission (verdict: Runtime Error):
def eratosthenes(n):
    is_prime = [True for i in range(n+1)]
    is_prime[0], is_prime[1] = False, False
    prime = []
    for i in range(2, n+1):
        if is_prime[i]:
            prime.append(i)
            for j in range(2*i, n+1, i):
                is_prime[j] = False
    return prime
    

Q = int(input())
N = 10**5

prime = eratosthenes(N)
prime_num = [0 for i in range(N+1)]
for p in prime:
    prime_num[p] = 1
    
count = 0
ans = [0 for i in range(N+1)]
for i in range(1, N+1, 2):
    if prime_num[i] == 1 and prime_num[(i+1)//2] == 1:
        count += 1
    ans[i] = count
    
for i in range(Q):
    l, r = map(int, input().split())
    print(ans[r+2] - ans[l-2])

Fixed submission:
def eratosthenes(n):
    is_prime = [True for i in range(n+1)]
    is_prime[0], is_prime[1] = False, False
    prime = []
    for i in range(2, n+1):
        if is_prime[i]:
            prime.append(i)
            for j in range(2*i, n+1, i):
                is_prime[j] = False
    return prime
    

Q = int(input())
N = 10**5

prime = eratosthenes(N)
prime_num = [0 for i in range(N+1)]
for p in prime:
    prime_num[p] = 1
    
count = 0
ans = [0 for i in range(N+1)]
for i in range(1, N+1, 2):
    if prime_num[i] == 1 and prime_num[(i+1)//2] == 1:
        count += 1
    ans[i] = count
    
for i in range(Q):
    l, r = map(int, input().split())
    print(ans[r] - ans[l-2])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

word = []
for i in range(N):
    a = int(input())
    if a in word:
        word.remove(a)
    else:
        word.append(a)
        
print(len(word))

Fixed submission:
N = int(input())

word = set()
for i in range(N):
    a = int(input())
    if a in word:
        word.remove(a)
    else:
        word.add(a)
        
print(len(word))
Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

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

N = int(input())

T = []
for i in range(N):
    T.append(int(input()))
    
lcm_T = lcm(T[0], T[1])
for i in range(2, N):
    lcm_T = lcm(lcm_T, T[i])
    
print(lcm_T)

Fixed submission:
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

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

N = int(input())

if N == 1:
    T = int(input())
    print(T)
    exit()

T = []
for i in range(N):
    T.append(int(input()))
    
lcm_T = lcm(T[0], T[1])
for i in range(2, N):
    lcm_T = lcm(lcm_T, T[i])
    
print(lcm_T)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

start = []
goal = []
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        start.append(b)
    if b == N:
        goal.append(a)
    
for i in range(len(start)):
    if start[i] in goal:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")

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

start = set()
goal = set()
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        start.add(b)
    if b == N:
        goal.add(a)
    
if len(start & goal) != 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
import heapq as hq

N, A, B = map(int, input().split())
h = []
for i in range(N):
    hq.heappush(h, -int(input()))
    
count = 0
while True:
    max_h = hq.heappop(h)
    
    if max_h >= 0:
        break
    
    h = [x + B for x in h]
    hq.heapify(h)
    hq.heappush(h, max_h + A)
    count += 1

print(count)

Fixed submission:
N, A, B = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))
    
left = 0
right = max(h)

def can_kill(count):
    ness = 0
    for hp in h:
        ness += max(-(-(hp - B * count) // (A - B)), 0)
    if ness <= count:
        return True
    return False
    
while right - left > 1:
    middle = left + (right - left) // 2
    if can_kill(middle):
        right = middle
    else:
        left = middle

print(right)

Buggy python submission (verdict: Time Limit Exceeded):
N, A, B = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))
    
count = 0
while True:
    max_h = 0
    for i in range(N):
        if h[i] > max_h:
            max_h = h[i]
            max_num = i
    
    if max_h <= 0:
        break
    
    h = [x - B for x in h]
    h[max_num] += B - A
    count += 1

print(count)

Fixed submission:
N, A, B = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))
    
left = 0
right = max(h)

def can_kill(count):
    ness = 0
    for hp in h:
        ness += max(-(-(hp - B * count) // (A - B)), 0)
    if ness <= count:
        return True
    return False
    
while right - left > 1:
    middle = left + (right - left) // 2
    if can_kill(middle):
        right = middle
    else:
        left = middle

print(right)
Buggy python submission (verdict: Runtime Error):
INF = float('inf')
def bellmanford(n, edges, r):  # r : start
    d = [INF] * n
    d[r] = 0
    for i in range(n):
        for (u, v, c) in edges:
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                if i == n-1 and v == n-1:
                    return 'inf'
    return d[n-1]


N, M = map(int, input().split())
edges = [None] * M
for i in range(M):
    a, b, c = map(int, input().split())
    edges[i] = (a-1, b-1, -c)
ans = bellmanford(N, edges, 0)
print(-ans)

Fixed submission:
INF = float('inf')
def bellmanford(n, edges, r):  # r : start
    d = [INF] * n
    d[r] = 0
    for i in range(n):
        for (u, v, c) in edges:
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                if i == n-1 and v == n-1:
                    return 'inf'
    return -d[n-1]


N, M = map(int, input().split())
edges = [None] * M
for i in range(M):
    a, b, c = map(int, input().split())
    edges[i] = (a-1, b-1, -c)
ans = bellmanford(N, edges, 0)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())

count = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i + j + k == S:
                count += 1

print(count)

Fixed submission:
K, S = map(int, input().split())

count = 0
for x in range(K+1):
    for y in range(K+1):
        z = S - x - y
        if z <= K and z >= 0:
            count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

a, b = 1, 1
for i in range(N):
    T, A = map(int, input().split())
    tmp_T = T
    tmp_A = A
    while True:
        if a <= tmp_T and b <= tmp_A:
            a = tmp_T
            b = tmp_A
            break
        tmp_T += T
        tmp_A += A
        
print(a+b)

Fixed submission:
N = int(input())

a, b = 1, 1
for i in range(N):
    T, A = map(int, input().split())
    mult = max((T+a-1)//T, (A+b-1)//A)
    a, b = T * mult, A * mult
        
print(a+b)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

N = input()
cnt = 0

for n in N:
    cnt += int(N)
    cnt %= 9

if cnt % 9 == 0:
    print('Yes')
else:
    print('No')




Fixed submission:
#!/usr/bin/env python3

N = input()
cnt = 0
for i in range(len(N)):
    cnt += int(N[i]) % 9

if cnt % 9 == 0:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

N = input()
cnt = 0

for n in N:
    cnt += int(N)

if cnt % 9 == 0:
    print('Yes')
else:
    print('No')




Fixed submission:
#!/usr/bin/env python3

N = input()
cnt = 0
for i in range(len(N)):
    cnt += int(N[i]) % 9

if cnt % 9 == 0:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import copy
N, K = map(int, input().split())
A = list(map(int, input().split()))

before = 1

for i in range(K, 0, -1):
    before *= A[K-i]
for i in range(K, N):
    after = (before//A[i-K])*A[i]
    if before < after:
        print('Yes')
    else:
        print('No')
    before = copy.deepcopy(after)




Fixed submission:
#!/usr/bin/env python3
import copy
N, K = map(int, input().split())
A = list(map(int, input().split()))

before = 0
for i in range(K, 0, -1):
    before += A[K-i]
for i in range(K, N):
    after = (before-A[i-K])+A[i]
    if before < after:
        print('Yes')
    else:
        print('No')
    before = copy.deepcopy(after)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

N = int(input())


Ret = [0 for _ in range(10**4+1)]

for i in range(1, N+1):
    for j in range(1, N+1):
        for k in range(1, N+1):
            r = i**2 + j**2 + k**2 + i*j + j*k + i*k
            Ret[r] += 1

for r in Ret[1:N+1]:
    print(r)




Fixed submission:
#!/usr/bin/env python3

N = int(input())

Ret = [0 for _ in range(10**5)]

for i in range(1, 101):
    for j in range(1, 101):
        for k in range(1, 101):
            r = i**2 + j**2 + k**2 + i*j + j*k + i*k
            if r > len(Ret): print(r)
            Ret[r] += 1

for r in Ret[1:N+1]:
    print(r)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import collections
import copy
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

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

if 1 in A:
    if A.count(1) == 1:
        print(1)
    else:
        print(0)
    exit()

ret = 0

D = collections.Counter(A)
D2 = copy.copy(D)


for k, v in D2.items():
    if v != 1:
        D.pop(k)
    elif is_prime(k):
        D.pop(k)
        ret += 1



A = list(set(A))

for a in D.keys():
    f = make_divisors(a)
    flag = True
    for f2 in f[2:]:
        if D2[f2] == 0: continue
        else: flag = False
    if flag: ret += 1


print(ret)


Fixed submission:
#!/usr/bin/env python3

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

M = 10 ** 6  + 5
dp = [0]*(M)

for a in A:
    index = 1
    if dp[a] != 0:
        dp[a] = 2
        continue
    for i in range(a, M, a):
        dp[i] += 1

ret = 0
for a in A:
    if dp[a] == 1: ret +=1

print(ret)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


X = int(input())

F = factorization(X)

ans = []

Y = 0
#while Y < 10**9:
f2 = False
nex = F[0][0]
b = - X//nex
a = b + nex
ans = []
while Y<10**9:
    Y = a**5 - b**5
    if X == Y:
        ans = [a,b]
        break
    a += nex
    b += nex


print(str(ans[0]) + ' ' + str(ans[1]))


Fixed submission:
#!/usr/bin/env python3

X = int(input())


ans = {}

for a in range(-200, 201):
    for b in range(-200, 201):
        Y = a**5 - b**5
        ans[Y] = [a, b]

print(str(ans[X][0]) + ' ' + str(ans[X][1]))
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

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

L = []
R = []
for i in range(N):
    L.append(i+A[i])
    R.append(i-A[i])
ans = 0
for l in L:
    ans += R.count(l)
print(ans)


Fixed submission:
#!/usr/bin/env python3

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

L = []
R = []
for i in range(N):
    L.append(i+A[i])
    R.append(i-A[i])

C_L = collections.Counter(L)
C_R = collections.Counter(R)
ans = 0
for l, t in C_L.items():
    if l in C_R:
        ans += t*C_R[l]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

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

L = [i+A[i] for i in range(N)]
R = [i-A[i] for i in range(N)]
ans = 0
for l in L:
    ans += R.count(l)
print(ans)


Fixed submission:
#!/usr/bin/env python3

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

L = []
R = []
for i in range(N):
    L.append(i+A[i])
    R.append(i-A[i])

C_L = collections.Counter(L)
C_R = collections.Counter(R)
ans = 0
for l, t in C_L.items():
    if l in C_R:
        ans += t*C_R[l]
print(ans)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

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

F12 = []

for i in range(1, B):
    x = i
    f1 = int(A*x/B) 
    f2 = A * int(x/B)
    F12.append(f1-f2)

if N < B:
    print(F12[N-1])
else:
    print(F12[-1])


Fixed submission:
#!/usr/bin/env python3

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

f1 = 0
f2 = 0
if N >=B:
    f1 = int(A*(B-1)/B)
    f2 = A*int((B-1)/B)
else:
    f1 = int(A*N/B)
    f2 = A*int(N/B)

ans = f1-f2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
s = 0
e = s + 4
ans = 0
loop = False

while True:
    
    if loop == False:
        index = int(S[s:e])
        if index % 2019 == 0:
            ans += 1
            loop = True
            s_cp = s
            e_cp = e
        else:
            e += 1
    else:
        s2 = e_cp
        e2 = s2+e_cp-s_cp
        if S[s:e] == S[s2:e2]:
            ans += 1
            s_cp = s2
            e_cp = e2
        else:
            loop = False
            e += 1
    if e > len(S) :
        s += 1
        e = s + 4
        if e > len(S): break

print(ans)


Fixed submission:
#!/usr/bin/env python3
S = input()[::-1]

mod = [0]*2019
mod[0] = 1
ten = 1
index = 0
for s in S:
    index += ten*int(s)
    index %= 2019
    mod[index] += 1
    ten *= 10
    ten %= 2019

ans = 0
for m in mod:
    ans += m * (m-1) // 2

print(ans)

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

index = 0
ans = 0
for i in range(len(S)):
    for j in range(i+1, len(S)):
        index = int(S[i:j+1])
        if index % 2019 == 0: ans+=1
print(ans)


Fixed submission:
#!/usr/bin/env python3
S = input()[::-1]

mod = [0]*2019
mod[0] = 1
ten = 1
index = 0
for s in S:
    index += ten*int(s)
    index %= 2019
    mod[index] += 1
    ten *= 10
    ten %= 2019

ans = 0
for m in mod:
    ans += m * (m-1) // 2

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


K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i==j and i==k: g = i
            elif (i==j and i!=k):
                g = math.gcd(i,math.gcd(j,k))*3
            elif (i==k and i!=j):
                g = math.gcd(i,math.gcd(j,k))*3
            elif (j==k and i!=j):
                g = math.gcd(i,math.gcd(j,k))*3
            else : g = math.gcd(i,math.gcd(j,k))*6
            ans += g
print(ans)


Fixed submission:
#!/usr/bin/env python3
import math
MOD = 10**9
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i==j and i==k: g = i
            elif (i==j and i!=k):
                g = math.gcd(i,math.gcd(j,k))*3
            elif (i==k and i!=j):
                g = math.gcd(i,math.gcd(j,k))*3
            elif (j==k and i!=j):
                g = math.gcd(i,math.gcd(j,k))*3
            else : g = math.gcd(i,math.gcd(j,k))*6
            ans += g
print(ans)