Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, bu, re = list(map(int, input().split(" ")))
 
ttlBu, ttlRe = 0, 0
 
while True:
    for _ in range(bu):
        if ttlBu + ttlRe == n:
            print(ttlBu)
            exit()
        ttlBu += 1
    for _ in range(re):
        if ttlBu + ttlRe == n:
            print(ttlBu)
            exit()
        ttlRe += 1

Fixed submission:
import math

n, a, b = map(int, input().split(" "))

ans = (n // (a + b)) * a
ans += min((n % (a + b)), a)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, bu, re = list(map(int, input().split(" ")))

ttlBu, ttlRe = 0, 0

while True:
    for _ in range(bu):
        if ttlBu + ttlRe == n:
            print(ttlBu)
            exit()
        ttlBu += 1
    for _ in range(re):
        if ttlBu + ttlRe == n:
            print(ttlBu)
            exit()
        ttlRe += 1

Fixed submission:
import math

n, a, b = map(int, input().split(" "))

ans = (n // (a + b)) * a
ans += min((n % (a + b)), a)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

n, m = list(map(int, input().split()))
ar = [list(map(int, input().split())) for _ in range(m)]
ans = [0 for _ in range(n)]

for a in ar:
    if a[0] == 1 and a[1] == 0:
        print(-1)
        sys.exit()
    if ans[a[0] - 1] != 0 and ans[a[0] - 1] != a[1]:
        print(-1)
        sys.exit()
    ans[a[0] - 1] = a[1]

if ans[0] == 0:
    if ans[1] == 0:
        ans[1] = 1
    ans[0] = 1

ans = int("".join(map(str, ans)))
print(ans)


Fixed submission:
import math

n, m = map(int, input().split(" "))

ans = list([0 for _ in range(n)])

err = False
for i in range(m):
    s, c = map(int, input().split(" "))
    if s == 1 and c == 0:
        if n == 1:
            print(0)
            exit()
        err = True
    elif ans[s - 1] == 0:
        ans[s - 1] = c
    elif not ans[s - 1] == c:
        err = True

if ans[0] == 0:
    ans[0] = 1

if (n == 1 and ans[0] == 0) or (n == 1 and m == 0):
    print(0)
    exit()

if err:
    print(-1)
    exit()

print("".join(map(str, ans)))

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

n, m = list(map(int, input().split()))
ar = [list(map(int, input().split())) for _ in range(m)]
ans = [0 for _ in range(n)]

for a in ar:
    if ans[a[0] - 1] != 0 and ans[a[0] - 1] != a[1]:
        print(-1)
        sys.exit()
    ans[a[0] - 1] = a[1]

if ans[0] == 0:
    if ans[1] == 0:
        ans[1] = 1
    ans[0] = 1

ans = int("".join(map(str, ans)))
print(ans)

Fixed submission:
import math

n, m = map(int, input().split(" "))

ans = list([0 for _ in range(n)])

err = False
for i in range(m):
    s, c = map(int, input().split(" "))
    if s == 1 and c == 0:
        if n == 1:
            print(0)
            exit()
        err = True
    elif ans[s - 1] == 0:
        ans[s - 1] = c
    elif not ans[s - 1] == c:
        err = True

if ans[0] == 0:
    ans[0] = 1

if (n == 1 and ans[0] == 0) or (n == 1 and m == 0):
    print(0)
    exit()

if err:
    print(-1)
    exit()

print("".join(map(str, ans)))
Buggy python submission (verdict: Time Limit Exceeded):
import math

n, a, b = map(int, input().split(" "))


def choose(n, a):
    x = 1
    y = 1
    for i in range(a):
        x *= n - i
        y *= i + 1
    return x // y


def pow2(num):
    c = 2
    d = 1
    dic = {d: c}

    for _ in range(20):
        c **= 2
        d *= 2
        dic[d] = c

    ret = 0
    while d != 0:
        if num >= d:
            num -= d
            if ret == 0:
                ret = dic[d]
            else:
                ret *= dic[d]
        else:
            d //= 2
    return ret


print((pow2(n) - 1 - choose(n, a) - choose(n, b)) % 1000000007)

Fixed submission:
from functools import reduce

n, a, b = map(int, input().split(" "))

MOD = 10**9 + 7


def comb(n, r, mod=float("inf")):
    c = 1
    m = 1
    r = min(n - r, r)
    for i in range(r):
        c = c * (n - i) % mod
        m = m * (i + 1) % mod
    return c * pow(m, mod - 2, mod) % mod


print((pow(2, n, MOD) - comb(n, a, MOD) - comb(n, b, MOD) - 1) % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ar = [input() for _ in range(n)]

d = {}

for a in ar:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

print("\n".join(sorted([k for k, v in d.items() if v == max(d.values())])))

Fixed submission:
n = int(input())
ar = [input() for _ in range(n)]

d = {}

for a in ar:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

max_val = max(d.values())
print("\n".join(sorted([key for key in d if d[key] == max_val])))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ar = [input() for _ in range(n)]

d = {}

for a in ar:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

print("\n".join(sorted([k for k, v in d.items() if v == max(d.values())])))

Fixed submission:
n = int(input())
ar = [input() for _ in range(n)]

d = {}

for a in ar:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

max_val = max(d.values())
print("\n".join(sorted([key for key in d if d[key] == max_val])))
Buggy python submission (verdict: Time Limit Exceeded):
import math

n, k = map(int, input().split(" "))
pL = list(map(int, input().split(" ")))

mx = 0
for i in range(len(pL) - k + 1):
    sm = 0
    for j in range(k):
        sm += pL[i + j]
    mx = max(sm, mx)

print((mx + k) / 2)

Fixed submission:
import math

n, k = map(int, input().split(" "))
pL = list(map(int, input().split(" ")))

mx = 0
cs = 0
for i in range(k):
    cs += pL[i]
    mx = cs
for i in range(1, len(pL) - k + 1):
    cs = cs - pL[i - 1] + pL[i + k - 1]
    mx = max(mx, cs)
print((mx + k) / 2)
Buggy python submission (verdict: Time Limit Exceeded):
h = int(input())

s = 0
c = 1
while h >= 0:
  s += c
  c *= 2
  h //= 2
print(s)

Fixed submission:
h = int(input())

s = 0
c = 1
while h != 0:
  s += c
  c *= 2
  h //= 2
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
import math

n, m = map(int, input().split(" "))
aL = list(map(int, input().split(" ")))

d = {}
for i, a in enumerate(aL):
    if a in d:
        d[a].append(i)
    else:
        d[a] = [i]

cnt = 0
while True:
    if len(d) == 0:
        break
    dMax = max(d)
    while True:
        if cnt == m:
            ans = 0
            for k, v in d.items():
                ans += k * len(v)
            print(ans)
            exit()
        nxt = d[dMax].pop(0)

        if (dMax // 2) in d:
            d[dMax // 2].append(nxt)
        else:
            d[dMax // 2] = [nxt]

        cnt += 1

        if len(d[dMax]) == 0:
            del d[dMax]
            break

ans = 0
for k, v in d.items():
    ans += k * len(v)
print(ans)

Fixed submission:
import heapq

n, m = map(int, input().split())
aL = list(map(lambda x: int(x) * (-1), input().split(" ")))

heapq.heapify(aL)

for i in range(m):
    a = heapq.heappop(aL)
    a = int(a / 2)
    heapq.heappush(aL, a)

print(int(sum(aL) * -1))

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

n, m = map(int, input().split(" "))
aL = sorted(list(map(int, input().split(" "))), reverse=True)

for i in range(m):
    aL[0] //= 2
    for i in range(1, n):
        if aL[0] > aL[i]:
            aL = aL[1:i] + [aL[0]] + aL[i:]
            break

print(sum(aL))


Fixed submission:
import heapq

n, m = map(int, input().split())
aL = list(map(lambda x: int(x) * (-1), input().split(" ")))

heapq.heapify(aL)

for i in range(m):
    a = heapq.heappop(aL)
    a = int(a / 2)
    heapq.heappush(aL, a)

print(int(sum(aL) * -1))

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

n, m = map(int, input().split(" "))
aL = list(map(int, input().split(" ")))

for i in range(m):
    aL.sort(reverse=True)
    aL[0] //= 2

print(sum(aL))


Fixed submission:
import heapq

n, m = map(int, input().split())
aL = list(map(lambda x: int(x) * (-1), input().split(" ")))

heapq.heapify(aL)

for i in range(m):
    a = heapq.heappop(aL)
    a = int(a / 2)
    heapq.heappush(aL, a)

print(int(sum(aL) * -1))
Buggy python submission (verdict: Time Limit Exceeded):
import math

s = input()
li = [0 for _ in range(len(s))]

for i in range(len(s)):
    if s[i] == "R":
        t = s[i:].index("L")
        if t % 2 != 0:
            li[i + t - 1] += 1
        else:
            li[i + t] += 1
    else:
        t = s[:i].rfind("R")
        if (i - t) % 2 != 0:
            li[t + 1] += 1
        else:
            li[t] += 1

print(*li)

Fixed submission:
import math

s = input()
li = [0 for _ in range(len(s))]

for i in range(len(s)):
    if s[i] == "R":
        t = s[i:].index("L")
        if t % 2 != 0:
            li[i + t - 1] += 1
        else:
            li[i + t] += 1
    else:
        t = s[:i].rfind("R")
        if (i - t) % 2 != 0:
            li[t + 1] += 1
        else:
            li[t] += 1

print(*li)

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

s = input()
li = [0 for _ in range(len(s))]

for i in range(len(s)):
    if s[i] == "R":
        c = 1
        while True:
            if s[i + c] == "L":
                if c % 2 != 0:
                    li[i + c - 1] += 1
                else:
                    li[i + c] += 1
                break
            c += 1
    else:
        c = 1
        while True:
            if s[i - c] == "R":
                if c % 2 != 0:
                    li[i - c + 1] += 1
                else:
                    li[i - c] += 1
                break
            c += 1

print(*li)

Fixed submission:
import math

s = input()
li = [0 for _ in range(len(s))]

for i in range(len(s)):
    if s[i] == "R":
        t = s[i:].index("L")
        if t % 2 != 0:
            li[i + t - 1] += 1
        else:
            li[i + t] += 1
    else:
        t = s[:i].rfind("R")
        if (i - t) % 2 != 0:
            li[t + 1] += 1
        else:
            li[t] += 1

print(*li)

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

s = input()
li = [0 for _ in range(len(s))]

for i in range(len(s)):
    if s[i] == "R":
        c = 1
        while True:
            ni = i + c
            if s[ni] == "L":
                if c % 2 != 0:
                    li[ni - 1] += 1
                else:
                    li[ni] += 1
                break
            c += 1
    else:
        c = 1
        while True:
            ni = i - c
            if s[ni] == "R":
                if c % 2 != 0:
                    li[ni + 1] += 1
                else:
                    li[ni] += 1
                break
            c += 1

print(" ".join(map(str, li)))

Fixed submission:
import math

s = input()
li = [0 for _ in range(len(s))]

for i in range(len(s)):
    if s[i] == "R":
        t = s[i:].index("L")
        if t % 2 != 0:
            li[i + t - 1] += 1
        else:
            li[i + t] += 1
    else:
        t = s[:i].rfind("R")
        if (i - t) % 2 != 0:
            li[t + 1] += 1
        else:
            li[t] += 1

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

a, b, c, d = map(int, input().split(" "))


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


def sj(base, i1, i2):
    cz = base // i1
    dz = base // i2
    cd = base // lcm(i1, i2)
    return base - (cz + dz - cd)


print(sj(b, c, d) - sj(a - 1, c, d))


Fixed submission:
from fractions import gcd

a, b, c, d = map(int, input().split(" "))


def lcm(x, y):
    return (x * y) // gcd(x, y)


def sj(base, i1, i2):
    cz = base // i1
    dz = base // i2
    cd = base // lcm(i1, i2)
    return base - (cz + dz - cd)


print(sj(b, c, d) - sj(a - 1, c, d))
Buggy python submission (verdict: Runtime Error):
import math

n, m = map(int, input().split(" "))
aL = sorted(list(map(int, input().split(" "))))
bcL = sorted([list(map(int,
                       input().split(" "))) for _ in range(m)],
             key=lambda x: x[1],
             reverse=True)

csl = 0
for cnt, point in bcL:
    for i in range(cnt):
        if aL[csl] >= point:
            print(sum(aL))
            exit()
        aL[csl] = point
        csl += 1

print(sum(aL))
exit()

Fixed submission:
import math

n, m = map(int, input().split(" "))
aL = sorted(list(map(int, input().split(" "))))
bcL = sorted([list(map(int,
                       input().split(" "))) for _ in range(m)],
             key=lambda x: x[1],
             reverse=True)

csl = 0
for cnt, point in bcL:
    for i in range(cnt):
        if csl == n or aL[csl] >= point:
            print(sum(aL))
            exit()
        aL[csl] = point
        csl += 1

print(sum(aL))
exit()
Buggy python submission (verdict: Time Limit Exceeded):
import math

n, q = map(int, input().split(" "))
s = input()

lrL = [list(map(int, input().split(" "))) for _ in range(q)]

idx = []
# n
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        idx.append(i)

for l, r in lrL:
    cnt = 0
    for x in idx:
        if x > r - 2:
            break
        if l - 1 <= x <= r - 2:
            cnt += 1
    print(cnt)


Fixed submission:
import math

n, q = map(int, input().split(" "))
s = input()

lrL = [list(map(int, input().split(" "))) for _ in range(q)]

li = [0] * n
mx = 0
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        mx += 1
    li[i + 1] = mx

for l, r in lrL:
    print(li[r - 1] - li[l - 1])

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

n, q = map(int, input().split(" "))
s = input()

lrL = [list(map(int, input().split(" "))) for _ in range(q)]

idx = []
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        idx.append(i)

for l, r in lrL:
    print(len(list(filter(lambda x: l - 1 <= x <= r - 2, idx))))


Fixed submission:
import math

n, q = map(int, input().split(" "))
s = input()

lrL = [list(map(int, input().split(" "))) for _ in range(q)]

li = [0] * n
mx = 0
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        mx += 1
    li[i + 1] = mx

for l, r in lrL:
    print(li[r - 1] - li[l - 1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
sum_com = a[0]
comfort = [a[1], a[1]]

for ai in a[2:]:
    sum_com += comfort[0]
    if comfort[0] == ai:
        comfort.append(ai)
    else:
        comfort.pop(0)
        comfort += [ai, ai]

print(sum_com)


Fixed submission:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
sum_com = 0
distinct_a = sorted(list(set(a)), reverse=True)
comfort = {i: 0 for i in distinct_a}
comfort[a[0]] = 1
max_com = 0

for ai in a[1:]:
    sum_com += distinct_a[max_com]
    if distinct_a[max_com] == ai:
        comfort[distinct_a[max_com]] += 1
    else:
        comfort[distinct_a[max_com]] -= 1
        comfort[ai] += 2
        if comfort[distinct_a[max_com]] == 0:
            max_com += 1

print(sum_com)
Buggy python submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = 0
cnt2 = 0
for i, ai in enumerate(a):
    for j in range(i, n):
        if ai > a[j]:
            cnt += 1
    if i > 0:
        for j in range(i):
            if ai > a[j]:
                cnt2 += 1

if k % 2 == 0:
    mul = (1 + k) * (k // 2)
else:
    mul = (1 + k) * (k // 2) + (k // 2 + 1)
if k > 1:
    k -= 1
    if k % 2 == 0:
        mul2 = (1 + k) * (k // 2)
    else:
        mul2 = (1 + k) * (k // 2) + (k // 2 + 1)
print(((cnt * mul) + (cnt2 * mul2)) % 1000000007)


Fixed submission:
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = 0
cnt2 = 0
for i, ai in enumerate(a):
    for j in range(i, n):
        if ai > a[j]:
            cnt += 1
    if i > 0:
        for j in range(i):
            if ai > a[j]:
                cnt2 += 1

if k % 2 == 0:
    mul = (1 + k) * (k // 2)
else:
    mul = (1 + k) * (k // 2) + (k // 2 + 1)
mul2 = 0
if k > 1:
    k -= 1
    if k % 2 == 0:
        mul2 = (1 + k) * (k // 2)
    else:
        mul2 = (1 + k) * (k // 2) + (k // 2 + 1)
print(((cnt * mul) + (cnt2 * mul2)) % 1000000007)
Buggy python submission (verdict: Runtime Error):
from math import factorial

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

memo = dict()
ans = []
d = 0
for i in range(1, k+1):
    nn = n - k + 1
    k1 = nn - i
    k2 = i
    nn2 = k - 1
    k3 = nn2 - (i - 1)
    k4 = i - 1
    if nn not in memo:
        memo[nn] = factorial(nn)
    if k1 not in memo:
        memo[k1] = factorial(k1)
    if k2 not in memo:
        memo[k2] = factorial(k2)
    if nn2 not in memo:
        memo[nn2] = factorial(nn2)
    if k3 not in memo:
        memo[k3] = factorial(k3)
    if k4 not in memo:
        memo[k4] = factorial(k4)
    c = ((memo[nn] // memo[k1] // memo[k2]) * (memo[nn2] // memo[k3] // memo[k4])) % 1000000007
    ans.append(str(c))
print("\n".join(ans))


Fixed submission:
from math import factorial

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

memo = dict()
ans = []
d = 0
for i in range(1, k+1):
    nn = n - k + 1
    if i > nn:
        ans.append("0")
        continue
    k1 = i
    k2 = nn - k1
    nn2 = k - 1
    k3 = i - 1
    k4 = nn2 - k3
    if nn not in memo:
        memo[nn] = factorial(nn)
    if k1 not in memo:
        memo[k1] = factorial(k1)
    if k2 not in memo:
        memo[k2] = factorial(k2)
    if nn2 not in memo:
        memo[nn2] = factorial(nn2)
    if k3 not in memo:
        memo[k3] = factorial(k3)
    if k4 not in memo:
        memo[k4] = factorial(k4)
    c = ((memo[nn] // memo[k2] // memo[k1]) * (memo[nn2] // memo[k4] // memo[k3])) % 1000000007
    ans.append(str(c))
print("\n".join(ans))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
hand = []
for _ in range(m):
    b, c = map(int, input().split())
    hand.append((b, c))
hand.sort(key=lambda x: x[1], reverse=True)

i = 0
lena = len(a)
flag = False
for h in hand:
    for j in range(h[0]):
        if i < lena and a[i] >= h[1]:
            flag = True
            break
        else:
            a[i] = h[1]
            i += 1
    if flag:
        break

print(sum(a))


Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
hand = []
for _ in range(m):
    b, c = map(int, input().split())
    hand.append((b, c))
hand.sort(key=lambda x: x[1], reverse=True)

i = 0
lena = len(a)
flag = False
for h in hand:
    for j in range(h[0]):
        if i >= lena:
            flag = True
            break
        if a[i] >= h[1]:
            flag = True
            break
        else:
            a[i] = h[1]
            i += 1
    if flag:
        break

print(sum(a))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
hand = []
for _ in range(m):
    b, c = map(int, input().split())
    hand.append((b, c))
hand.sort(key=lambda x: x[1], reverse=True)

i = 0
flag = False
for h in hand:
    for j in range(h[0]):
        if a[i] >= h[1]:
            flag = True
            break
        else:
            a[i] = h[1]
            i += 1
    if flag:
        break

print(sum(a))


Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
hand = []
for _ in range(m):
    b, c = map(int, input().split())
    hand.append((b, c))
hand.sort(key=lambda x: x[1], reverse=True)

i = 0
lena = len(a)
flag = False
for h in hand:
    for j in range(h[0]):
        if i >= lena:
            flag = True
            break
        if a[i] >= h[1]:
            flag = True
            break
        else:
            a[i] = h[1]
            i += 1
    if flag:
        break

print(sum(a))
Buggy python submission (verdict: Runtime Error):
x = []
for _ in range(5):
    x.append(int(input()))
t = 0
wt = []
for a in x:
    t += a
    m = a % 10
    if m > 0:
      wt.append(10-m)
wt.sort()
wt.pop()
for x in wt:
    t += x
print(t)

Fixed submission:
x = []
for _ in range(5):
    x.append(int(input()))
t = 0
wt = []
for a in x:
    t += a
    m = a % 10
    if m > 0:
      wt.append(10-m)
if len(wt) > 1:
    wt.sort()
    wt.pop()
    for x in wt:
        t += x
print(t)
Buggy python submission (verdict: Runtime Error):
X = int(input())
if X == 1:
    print(0)
else:1
    print(1)
    

Fixed submission:
X = int(input())
if X == 1:
    print(0)
else:
    print(1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = input()

times = len(s)
for i in range(len(s) + 1):
    r, l = s[:i], s[i:]
    if times > max(r.count("W"), l.count("R")):
        times = max(r.count("W"), l.count("R"))
print(times)

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

R, L = 0, s.count("R")
times = max(R, L)
for c in s:
    if c == "W":
        R += 1
    else:
        L -= 1
    if times > max(R, L):
        times = max(R, L)
print(times)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int,input().split()))


import functools
import operator
total_product = functools.partial(functools.reduce, operator.mul)
ans = total_product(a)

if ans > 10**18:
    ans = -1

if 0 in a:
    ans = 0
print(ans)

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

ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        ans = -1
        break

if 0 in A:
    ans = 0

print(ans)

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

for _a in a:
    ans *= _a

if ans > 10**18:
    ans = -1

if 0 in a:
    ans = 0
print(ans)

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

ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        ans = -1
        break

if 0 in A:
    ans = 0

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

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

Fixed submission:
S = input()
P =2019
ans = 0

count = [0] * P
count[0] = 1
u = 0
for i, s in enumerate(reversed(S)):
    u = (int(s) * pow(10, i, P) + u) % P
    ans += count[u]
    count[u] += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

import math
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += math.gcd(math.gcd(i,j),k)
print(ans)

Fixed submission:
K = int(input())

import math
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += math.gcd(math.gcd(i,j),k)
print(ans)
Buggy python submission (verdict: Runtime Error):
K = int(input())
lun = [1, 2, 3, 4, 5, 6, 7, 8, 9]
cnt = 0

while(len(lun) < K):
  target = lun[cnt]
  num = target % 10
  print(lun,target,num)
  if num != 0:
      lun.append(target * 10 + num - 1)
  lun.append(target * 10 + num)
  if num != 9:
      lun.append(target * 10 + num + 1)
  cnt += 1

print(lun[K-1])


Fixed submission:
K = int(input())
lun = [1, 2, 3, 4, 5, 6, 7, 8, 9]
cnt = 0

while(len(lun) < K):
  target = lun[cnt]
  num = target % 10
  if num != 0:
      lun.append(target * 10 + num - 1)
  lun.append(target * 10 + num)
  if num != 9:
      lun.append(target * 10 + num + 1)
  cnt += 1

print(lun[K-1])