Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
x = int(input())
a = []
for i in range(-10**4, 10**4):
    a.append(i**5)
    # print(i**5)
for i in a:
    if x - i in a:
        A = int(pow(i, 1/5))
        B = int(pow(x-i, 1/5))
        print(A, B)
        break

Fixed submission:
x = int(input())
check = 0
for a in range(1000):
    for b in range(-1000, 1000):
        if a ** 5 - b ** 5 == x:
            print(a, b)
            check = 1
            break
    if check:
        break
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
dp = [0 for _ in range(n)]
dp[-1] = int(s[-1])
for i in range(n-2, -1, -1):
    dp[i] = (dp[i+1] + int(s[i]) * (10**(n-i-1))) % 2019

cnt_dic = {}

for i in dp:
    if not i in cnt_dic:
        cnt_dic[i] = 0

    cnt_dic[i] += 1

# print(dp)
ans = 0
# print(cnt_dic)
for i, j in cnt_dic.items():
    if i == 0:
        ans += j
    else:
        ans += j * (j - 1) // 2

print(ans)

Fixed submission:
s = input()
n = len(s)
dp = [0 for _ in range(n)]
dp[-1] = int(s[-1])
memo = 0
cnt_dic = {}
tmp = 1
ans = 0
cnt_dic[0] = 1
for i in range(n-1, -1, -1):
    memo = (memo + int(s[i]) * pow(10, n-i-1, 2019)) % 2019
    if not memo in cnt_dic:
        cnt_dic[memo] = 0
    ans += cnt_dic[memo]
    cnt_dic[memo] += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
S = input()
r = []
g = []
b = []
for i, s in enumerate(S):
    if s == "R":
        r.append(i)
    elif s == "G":
        g.append(i)
    else:
        b.append(i)

# print(s, r, g, b)
ans = 0
for i, j in enumerate(r):
    for k, l in enumerate(g):
        for m, n in enumerate(b):
            I = min(j, l, n)
            K = max(j, l, n)
            J = j + l + n - I - K
            if K - J != J - I:
                ans += 1
print(ans)

Fixed submission:
import bisect
n = int(input())
S = input()
r = []
g = []
b = []
for i, s in enumerate(S):
    if s == "R":
        r.append(i)
    elif s == "G":
        g.append(i)
    else:
        b.append(i)

# print(s, r, g, b)
ans = len(r) * len(g) * len(b)
i = 0
j = 1
while i + 2 * j < n:
    while i + 2 * j < n:
        if S[i] != S[i + j] != S[i + 2 * j] != S[i]:
            ans -= 1
        i += 1
    j += 1
    i = 0

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
direction = 1
mae = ""
usiro = ""
for i in range(q):
    # print(i)
    qi = input()
    if qi == "1":
        direction *= -1
        # print(123, direction)
    else:
        tfq = list(qi.split())
        # print(tfq)
        t = tfq[0]
        f = tfq[1]
        q = tfq[2]

        if f == "1":
            if direction == 1:
                mae += q
            else:
                usiro += q
        else:
            if direction == 1:
                usiro += q
            else:
                mae += q
    # print(i, direction)

if direction == -1:
    s = usiro[::-1] + s[::-1] + mae
else:
    s = mae[::-1] + s + usiro
print(s)

Fixed submission:
s = list(input())
q = int(input())
direction = 1
mae = []
usiro = []
for i in range(q):
    qi = input()
    if qi == "1":
        direction *= -1
    else:
        tfq = list(qi.split())
        t = tfq[0]
        f = tfq[1]
        q = tfq[2]

        if f == "1":
            if direction == 1:
                mae.append(q)
            else:
                s.append(q)
        else:
            if direction == 1:
                s.append(q)
            else:
                mae.append(q)
# print(mae)
if direction == -1:
    for i in s[::-1]:
        print(i, end = "")
    for i in mae:
        print(i, end = "")
else:
    for i in mae[::-1]:
        print(i, end = "")
    for i in s:
        print(i, end = "")
Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
connect = [[] for _ in range(n)]
cCnt = [0 for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    connect[a - 1].append(b - 1)
    cCnt[a - 1] += 1
    connect[b - 1].append(a - 1)
    cCnt[b - 1] += 1

group = [0 for _ in range(n)]
gNum = 0
import queue
for i in range(n):
    if group[i]:
        continue
    gNum += 1
    next = queue.Queue()
    for j in connect[i]:
        next.put(j)
    group[i] = gNum

    while not next.empty():
        j = next.get()
        group[j] = gNum
        for l in connect[j]:
            if not group[l]:
                next.put(l)

hunaka = [0 for i in range(n)]
for i in range(k):
    c, d = map(int, input().split())
    if group[c - 1] != group[d - 1]:
        continue
    hunaka[c - 1] += 1
    hunaka[d - 1] += 1

groupCnt = [0 for _ in range(gNum + 1)]
for i in group:
    groupCnt[i] += 1

for i in range(n):
    tmp = groupCnt[group[i]]
    tmp -= cCnt[i]
    tmp -= hunaka[i]
    tmp -= 1
    print(tmp, end = " ")

Fixed submission:
n, m, k = map(int, input().split())
connect = [[] for _ in range(n)]
cCnt = [0 for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    connect[a - 1].append(b - 1)
    cCnt[a - 1] += 1
    connect[b - 1].append(a - 1)
    cCnt[b - 1] += 1

group = [0 for _ in range(n)]
gNum = 0
import queue
for i in range(n):
    if group[i]:
        continue
    gNum += 1
    next = queue.Queue()
    for j in connect[i]:
        group[j] = gNum
        next.put(j)
    group[i] = gNum

    while not next.empty():
        j = next.get()
        group[j] = gNum
        for l in connect[j]:
            if not group[l]:
                group[l] = gNum
                next.put(l)

hunaka = [0 for i in range(n)]
for i in range(k):
    c, d = map(int, input().split())
    if group[c - 1] != group[d - 1]:
        continue
    hunaka[c - 1] += 1
    hunaka[d - 1] += 1

groupCnt = [0 for _ in range(gNum + 1)]
for i in group:
    groupCnt[i] += 1

for i in range(n):
    tmp = groupCnt[group[i]]
    tmp -= cCnt[i]
    tmp -= hunaka[i]
    tmp -= 1
    print(tmp, end = " ")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
n = str(n)
k = 0
pay = 0
n_list = []
for i in n[::-1]:
    n_list.append(int(i))
n_list.append(0)
ans = 0
for i in range(len(n_list) - 1):
    num = n_list[i]
    if (num <= 5 and n_list[i + 1] < 5) or num < 5:
        # pay += num * 10 ** k
        ans += num
    else:
        n_list[i + 1] += 1
        ans += 10 - n_list[i]
    k += 1

# pay += n_list[-1] * 10 ** k
ans += n_list[-1]
print(ans)
# oturi = pay - int(n)
# ans = 0
#
# for i in str(pay):
#     ans += int(i)
# for i in str(oturi):
#     ans += int(i)
# print(ans)


Fixed submission:
n = input()
k = 0
pay = 0
n_list = []
for i in n[::-1]:
    n_list.append(int(i))
n_list.append(0)
ans = 0
for i in range(len(n_list) - 1):
    num = n_list[i]
    if num < 5:
        ans += num
    elif (num <= 5 and n_list[i + 1] < 5):
        ans += num
    else:
        n_list[i + 1] += 1
        ans += 10 - num

ans += n_list[-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
n = str(n)
k = 0
pay = 0
n_list = []
for i in n[::-1]:
    n_list.append(int(i))
n_list.append(0)
ans = 0
for i in range(len(n_list) - 1):
    num = n_list[i]
    if (num <= 5 and n_list[i + 1] < 5) or num < 5:
        # pay += num * 10 ** k
        ans += num
    else:
        n_list[i + 1] += 1
        ans += 10 - n_list[i]
    k += 1

# pay += n_list[-1] * 10 ** k
ans += n_list[-1]
print(ans)
# oturi = pay - int(n)
# ans = 0
#
# for i in str(pay):
#     ans += int(i)
# for i in str(oturi):
#     ans += int(i)
# print(ans)

Fixed submission:
n = input()
k = 0
pay = 0
n_list = []
for i in n[::-1]:
    n_list.append(int(i))
n_list.append(0)
ans = 0
for i in range(len(n_list) - 1):
    num = n_list[i]
    if num < 5:
        ans += num
    elif (num <= 5 and n_list[i + 1] < 5):
        ans += num
    else:
        n_list[i + 1] += 1
        ans += 10 - num

ans += n_list[-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
n = str(n)
k = 0
pay = 0
n_list = []
for i in n[::-1]:
    n_list.append(int(i))
n_list.append(0)
for i in range(len(n_list) - 1):
    num = n_list[i]
    if (num <= 5 and n_list[i + 1] < 5) or num < 5:
        pay += num * 10 ** k
    else:
        n_list[i + 1] += 1
    k += 1
pay += n_list[-1] * 10 ** k
oturi = pay - int(n)
ans = 0

for i in str(pay):
    ans += int(i)
for i in str(oturi):
    ans += int(i)
print(ans)

Fixed submission:
n = input()
k = 0
pay = 0
n_list = []
for i in n[::-1]:
    n_list.append(int(i))
n_list.append(0)
ans = 0
for i in range(len(n_list) - 1):
    num = n_list[i]
    if num < 5:
        ans += num
    elif (num <= 5 and n_list[i + 1] < 5):
        ans += num
    else:
        n_list[i + 1] += 1
        ans += 10 - num

ans += n_list[-1]
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
h = int(input())
# cnt = 0
# while h > 0:
#     if h == 1:
#         cnt += 1
#         break
#     else:
#         h //= 2
#         cnt += 1

ans = math.log2(h)
ans = int(ans)
#
# print(2 ** cnt - 1)
print(2 ** (int(ans) + 1) - 1)

Fixed submission:
h = int(input())
cnt = 0
while h > 0:
    if h == 1:
        cnt += 1
        break
    else:
        h //= 2
        cnt += 1

print(2 ** cnt - 1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
xl = []
for i in range(n):
    x1, l1 = map(int, input().split())
    xl.append([x1, x1 + l1, 2 * l1])
xl.sort()
ans = n
for i in range(n - 1):
    if xl[i][1] > xl[i + 1][0]:
        if xl[i][2] >= xl[i + 1][2]:
            ans -= 1
        else:
            ans -= 1
            xl[i + 1][0] = [i][0]
            xl[i + 1][1] = [i][1]
            xl[i + 1][2] = [i][2]

print(ans)

Fixed submission:
n = int(input())
st = []
for i in range(n):
    x, l = map(int, input().split())
    st.append([x + l, x - l])

st.sort()
cnt = 1
right = st[0][0]
for i in range(1, n):
    if right <= st[i][1]:
        right = st[i][0]
        cnt += 1

print(cnt)

Buggy python submission (verdict: Runtime Error):
n = int(input())
x = []
l = []
xl = []
for i in range(n):
    x1, l1 = map(int, input().split())
    xl.append([x1, x1 + l1, 2 * l1])
xl.sort()
ans = n
for i in range(n - 1):
    if xl[i][1] > xl[i + 1][0]:
        if xl[i][2] >= xl[i + 1][2]:
            ans -= 1
        else:
            ans -= 1
            xl[i + 1] = [i]
print(ans)

Fixed submission:
n = int(input())
st = []
for i in range(n):
    x, l = map(int, input().split())
    st.append([x + l, x - l])

st.sort()
cnt = 1
right = st[0][0]
for i in range(1, n):
    if right <= st[i][1]:
        right = st[i][0]
        cnt += 1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
bin_a = []
for i in a:
    bin_a.append(bin(i)[2::])
maxlen = 0
for i, j in enumerate(bin_a):
    maxlen = max(maxlen, len(j))

for i, j in enumerate(bin_a):
    while len(bin_a[i]) < maxlen:
        bin_a[i] = "0" + bin_a[i]
bin_a.sort()
ans = 0
mod = 10**9+7
for i in range(maxlen):
    zerocnt = 0
    onecnt = 0
    for j in range(len(bin_a)):
        if bin_a[j][i] == "0":
            zerocnt += 1
        else:
            onecnt += 1
    ans += zerocnt * onecnt * pow(2, (maxlen-i-1), mod)
    ans %= mod
ans %= mod
print(ans)

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

for i in a:
    j = 0
    while i > 0:
        if len(onecnts) - 1 < j:
            onecnts.append(0)
        if i % 2 != 0:
            onecnts[j] += 1
        j += 1
        i >>= 1

ans = 0
mod = 10**9+7

for i, onecnt in enumerate(onecnts):
    ans += onecnt * (n-onecnt) * (2**i)
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
bin_a = []
for i in a:
    bin_a.append(bin(i)[2::])
maxlen = 0
for i, j in enumerate(bin_a):
    maxlen = max(maxlen, len(j))

for i, j in enumerate(bin_a):
    while len(bin_a[i]) < maxlen:
        bin_a[i] = "0" + bin_a[i]
bin_a.sort()
ans = 0
mod = 10**9+7
for i in range(maxlen):
    zerocnt = 0
    onecnt = 0
    for j in range(len(bin_a)):
        if bin_a[j][i] == "0":
            zerocnt += 1
        else:
            onecnt += 1
    ans += zerocnt * onecnt * (2 ** (maxlen-i-1))
    ans %= mod
ans %= mod
print(ans)

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

for i in a:
    j = 0
    while i > 0:
        if len(onecnts) - 1 < j:
            onecnts.append(0)
        if i % 2 != 0:
            onecnts[j] += 1
        j += 1
        i >>= 1

ans = 0
mod = 10**9+7

for i, onecnt in enumerate(onecnts):
    ans += onecnt * (n-onecnt) * (2**i)
    ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
tmp = 0
key = 0
for i in range(n):
    if tmp + a[i] >= sum(a) / 2:
        key = i
        break
    tmp += a[i]

ans = abs(sum(a[0:key]) - sum(a[key::]))
tmp = 0
key = 0
for i in range(n):
    tmp += a[i]
    if tmp >= sum(a) / 2:
        key = i + 1
        break

ans = min(abs(sum(a[0:key]) - sum(a[key::])), ans)
print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
tmp = 0
key = 0
SUMA = sum(a)

for i in range(n):
    if tmp + a[i] >= SUMA / 2:
        key = i
        break
    tmp += a[i]

ans = abs(sum(a[0:key]) - sum(a[key::]))
tmp = 0
key += 1
ans = min(abs(sum(a[0:key]) - sum(a[key::])), ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p

def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

x, y = map(int, input().split())
X = x
Y = y
ans = 0
while True:
    # print(x, y)
    if y == x * 2:
        ans = 1
        break
    elif x < 0 or y < 0:
        ans = 0
        break
    x -= 2
    y -= 1
# print(1, ans, x, y)
xx = 0
yy = 0
if ans == 0:
    print(ans)
else:
    xx = X - x
    xx //= 2
    yy = y // 2
# print(xx, yy)
    print(comb(xx + yy, xx, 10 ** 9 + 7))
# print(xx, yy, x, y)

Fixed submission:
def solve():
    x, y = map(int, input().split())
    n = (2*y-x) / 3
    m = (2*x-y) / 3

    mod = 10**9+7

    if n < 0 or m < 0 or (x+y)% 3 != 0:
        return 0
    cmb = 1
    n = int(n)
    m = int(m)
    
    cnt = 0
    for i in range(n):
        cnt += 1
        cmb *= n+m-i
        cmb *= pow(i+1, mod-2, mod)
        cmb %= mod
    return cmb

print(solve())
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

jobs = [[] for i in range(10**4+1)]

for i in range(n):
    a, b = map(int, input().split())
    jobs[b].append(a)

job_schedules = [0 for _ in range(m+1)]
today = m
for i in range(len(jobs)-1, -1, -1):
    jobs[i].sort()
    for j in jobs[i]:
        day = min(today, m - j)
        while job_schedules[day] and day >= 0:
            day -= 1
        if day < 0:
            break
        job_schedules[day] = i

print(sum(job_schedules))

Fixed submission:
import heapq
n, m = map(int, input().split())

jobs = [[] for i in range(10**5+1)]

for i in range(n):
    a, b = map(int, input().split())
    jobs[a].append(b)

candidate = []
ans = 0
for i in range(m+1):
    for j in jobs[i]:
        heapq.heappush(candidate, -j)

    # print(i, candidate)
    if len(candidate) >= 1:
        ans += heapq.heappop(candidate) * -1


print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(1, n + 1):
	cnt = 1
    while True:
  		n //= 10
  		cnt += 1
  		if n < 10:
    		break
	if n % 2 != 0:
      ans += 1
print(ans)

Fixed submission:
n = int(input())
ans = 0
for i in range(1, n + 1):
  cnt = 0
  while i > 0:
    i //= 10
    cnt += 1
  if cnt % 2 != 0:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(n)]
ans = []
for i in range(n, 0, -1):
    if a[i-1] == 0:
        tmp = 0
        j = i * 2
        while j < n:
            # print(j)
            tmp += b[j-1]
            j += i
        if tmp % 2 == 0:
            b[i-1] = 0
        else:
            b[i-1] = 1
    else:
        tmp = 0
        j = i * 2
        while j < n:
            # print(j-1)
            tmp += b[j-1]
            j += i
        if tmp % 2 == 1:
            b[i-1] = 0
        else:
            b[i-1] = 1

for i in range(n):
    if b[i] % 2 != 0:
        # print(b[i]%2)
        ans.append(a[i+1])
# print(b)
print(len(ans))
for i in ans:
    print(i)

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

input_num = [0 for _ in range(n)]

for i in range(n-1, -1, -1):
    tmp = 0
    j = i+i+1
    while j < n:
        tmp += input_num[j]
        j += i+1

    if tmp % 2 != a[i]:
        input_num[i] = 1

print(sum((input_num)))
for i, j in enumerate(input_num):
    if j:
        print(i+1, end=' ')
Buggy python submission (verdict: Runtime Error):
l, r = map(int, input().split())
ans = 10**10
for i in range(l, r):
    for j in range(i+1, r):
        ans = min(ans, (i*j)%(2019))
        if i*j%2019==0:
            break
    if i*j%2019==0:
        break
print(ans)

Fixed submission:
l, r = map(int, input().split())
ans = 10**10
for i in range(l, r+1):
    for j in range(i+1, r+1):
        ans = min(ans, (i*j)%(2019))
        if i*j%2019==0:
            break
    if i*j%2019==0:
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
s.sort()
cnt = 1
ans = 1
for i in range(1, 4):
  if s[i - 1] != s[i]:
    if cnt < 2:
      ans = 0
      break
    cnt = 1
  if not ans:
    break
if cnt > 2:
  ans = 0
if not ans:
  print("No")
else:
  print("Yes")


Fixed submission:
s = list(input())
s.sort()
cnt = 1
ans = 1
# print(s)
for i in range(1, 4):
  # print(cnt)
  if s[i - 1] != s[i]:
    if cnt < 2:
      ans = 0
      break
    cnt = -1
  if not ans:
    break
  cnt += 1
if cnt > 3:
  ans = 0
if not ans:
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = 1
b = 1 + (n - k)
if k == 1:
    print(0)
else:
    print(b - a)

Fixed submission:
n, k = map(int, input().split())
a = 1
b = 1 + (n - k)
if k == 1:
    print(0)
else:
    print(b - a)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
#
# a.sort()
# ans = a[0]
# for i in range(1, n - 1):
#     ans += a[i] * (-1)
#
# print(a[-1] - ans)
# key = a[0]
# for i in range(1, n - 1):
#     print(key, a[i])
#     key = key - a[i]
# print(a[-1], key)

a.sort()
plusa = []
minusa = []
for i in a[1:-1]:
    if i < 0:
        minusa.append(i)
    else:
        plusa.append(i)
#
# print(minusa, plusa)
anslist = []
if len(plusa) == 0:
    plusa.append(minusa[-1])
    del minusa[-1]

for i in minusa:
    # print(plusa[0], i)
    anslist.append([plusa[0], i])
    plusa[0] -= i

for i in plusa:
    # print(a[0], i)
    anslist.append([a[0], i])
    a[0] -= i
# print(a[0])
print(a[-1] - a[0])
for i, j in anslist:
    print(i, j)
# print(anslist)
print(a[-1], a[0])

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort()
anslist = []
for i in range(1, n - 1):
    if a[i] >= 0:
        anslist.append([a[0], a[i]])
        a[0] -= a[i]
    else:
        anslist.append([a[-1], a[i]])
        a[-1] -= a[i]

anslist.append([a[-1], a[0]])
ans = a[-1] - a[0]
print(ans)
for i, j in anslist:
    print(i, j)
#
# a.sort()
# ans = a[0]
# for i in range(1, n - 1):
#     ans += a[i] * (-1)
#
# print(a[-1] - ans)
# key = a[0]
# for i in range(1, n - 1):
#     print(key, a[i])
#     key = key - a[i]
# print(a[-1], key)

# a.sort()
# plusa = []
# minusa = []
# for i in a[1:-1]:
#     if i < 0:
#         minusa.append(i)
#     else:
#         plusa.append(i)
# #
# # print(minusa, plusa)
# anslist = []
# # if len(a) == 2:
# #     print(max(a) - min(a))
# #     print(max(a), min(a))
# # if min(a) >= 0:
# #     for i in range(1, n - 1):
# #         anslist.append([a[0], a[i]])
# #         a[0] -= a[i]
# #     anslist.append([a[-1], a[0]])
# #     print(a[-1] - a[0])
# #     for i, j in anslist:
# #         print(i, j)
# # else:
# #     if len(plusa) == 0:
# #         plusa.append(minusa[-1])
# #         del minusa[-1]
# #
# #     for i in minusa:
# #         # print(plusa[0], i)
# #         anslist.append([plusa[0], i])
# #         plusa[0] -= i
# #
# #     for i in plusa:
# #         # print(a[0], i)
# #         anslist.append([a[0], i])
# #         a[0] -= i
# #     # print(a[0])
# #     print(a[-1] - a[0])
# #     for i, j in anslist:
# #         print(i, j)
# #     # print(anslist)
# #     print(a[-1], a[0])
Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

countL2R = [[0 for i in range(w)] for j in range(h)]
countR2L = [[0 for i in range(w)] for j in range(h)]
countU2D = [[0 for i in range(w)] for j in range(h)]
countD2U = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            countL2R[i][j] = -1
            countR2L[i][j] = -1
            countU2D[i][j] = -1
            countD2U[i][j] = -1

for i in range(h):
    for j in range(w):
        if j > 0 and countL2R[i][j] != -1:
                countL2R[i][j] = countL2R[i][j - 1] + 1

        j = w - j - 1
        if j < w - 1 and countR2L[i][j] != -1:
            countR2L[i][j] = countR2L[i][j + 1] + 1

        if i > 0 and countU2D[i][j] != -1:
            countU2D[i][j] = countU2D[i - 1][j] + 1

        I = i
        i = h - i - 1
        if i < h - 1 and countD2U[i][j] != -1:
            countD2U[i][j] = countD2U[i + 1][j] + 1
        i = I

ans = 0
for i in range(h):
    for j in range(w):
        if countD2U[i][j] != -1:
            ans = max(ans, countD2U[i][j] + countU2D[i][j] + countR2L[i][j] + countL2R[i][j])

print(ans + 1)


Fixed submission:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

countL2R = [[0 for i in range(w)] for j in range(h)]
countR2L = [[0 for i in range(w)] for j in range(h)]
countU2D = [[0 for i in range(w)] for j in range(h)]
countD2U = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            countL2R[i][j] = -1
            countR2L[i][j] = -1
            countU2D[i][j] = -1
            countD2U[i][j] = -1

for i in range(h):
    for j in range(w):
        if j > 0 and countL2R[i][j] != -1:
                countL2R[i][j] = countL2R[i][j - 1] + 1

        j = w - j - 1
        if j < w - 1 and countR2L[i][j] != -1:
            countR2L[i][j] = countR2L[i][j + 1] + 1

        if i > 0 and countU2D[i][j] != -1:
            countU2D[i][j] = countU2D[i - 1][j] + 1

        I = i
        i = h - i - 1
        if i < h - 1 and countD2U[i][j] != -1:
            countD2U[i][j] = countD2U[i + 1][j] + 1
        i = I

ans = 0
for i in range(h):
    for j in range(w):
        if countD2U[i][j] != -1:
            ans = max(ans, countD2U[i][j] + countU2D[i][j] + countR2L[i][j] + countL2R[i][j])

print(ans + 1)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
def change(i):
    global s
    #print(i)
    if s[i : i + 3] == ["A", "B", "C"]:
        s[i:i + 3] = ["B", "C", "A"]
        #print(s)
        return 1
    return 0

cnt = 0
for i in range(0,  len(s)):
    if change(i):
        cnt += 1
        for j in range(i - 1, -1, -1):
            if not change(j):
                break
            cnt += 1

print(cnt)

Fixed submission:
s = list(input())
def change(i):
    global s
    #print(i)
    if s[i : i + 3] == ["A", "B", "C"]:
        s[i:i + 3] = ["B", "C", "A"]
        #print(s)
        return 1
    return 0

cnt = 0
cnA = 0
i = 0
while i < len(s) - 1:
    #print(i, cnA)
    if s[i:i + 2] == ["B", "C"]:
        cnt += cnA
        i += 1
    elif s[i] == "A":
        cnA += 1
    else:
        cnA = 0
    i += 1

print(cnt)