Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import numpy
H,W = (int(x) for x in input().split())

S_arr_arr = [[1]*(W+2)]
for i in range(H):
    S_arr_arr.append([0 if s=="." else 1 for s in "#"+input()+"#"])
S_arr_arr.append([1]*(W+2))
W_arr_arr = [[0]*(W+2) for _ in range(H+2)]

S_arr_arr = numpy.array(S_arr_arr)
W_arr_arr = numpy.zeros_like(S_arr_arr)

for j in range(H+2):
    i_begin = 0
    for i in range(W+2):
        if S_arr_arr[j,i] == 1:
            for ix in range(i_begin+1, i):
                W_arr_arr[j,ix] += i-i_begin-1
            i_begin = i
for i in range(W+2):
    j_begin = 0
    for j in range(H+2):
        if S_arr_arr[j,i] == 1:
            for jx in range(j_begin+1, j):
                W_arr_arr[jx,i] += j-j_begin-1
            j_begin = j

max_ans = max([max(W_arr) for W_arr in W_arr_arr]) - 1

print(max_ans)


Fixed submission:
H,W = (int(x) for x in input().split())

S_arr_arr = [[1]*(W+2)]
for i in range(H):
    S_arr_arr.append([0 if s=="." else 1 for s in "#"+input()+"#"])
S_arr_arr.append([1]*(W+2))

W_arr_arr = [[0]*(W+2) for _ in range(H+2)]
for j in range(H+2):
    i_begin = 0
    for i in range(W+2):
        if S_arr_arr[j][i] == 1:
            for ix in range(i_begin+1, i):
                W_arr_arr[j][ix] += i-i_begin-1
            i_begin = i
for i in range(W+2):
    j_begin = 0
    for j in range(H+2):
        if S_arr_arr[j][i] == 1:
            for jx in range(j_begin+1, j):
                W_arr_arr[jx][i] += j-j_begin-1
            j_begin = j

max_ans = max([max(W_arr) for W_arr in W_arr_arr]) - 1

print(max_ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,W = (int(x) for x in input().split())

S_arr_arr = [[1]*(W+2)]
for i in range(H):
    S_arr_arr.append([0 if s=="." else 1 for s in "#"+input()+"#"])
S_arr_arr.append([1]*(W+2))

W_arr_arr = [[0]*(W+2) for _ in range(H+2)]
for j in range(H+2):
    i_begin = 0
    for i in range(W+2):
        if S_arr_arr[j][i] == 1:
            for ix in range(i_begin+1, i):
                W_arr_arr[j][ix] += i-i_begin-1
            i_begin = i
for i in range(W+2):
    j_begin = 0
    for j in range(H+2):
        if S_arr_arr[j][i] == 1:
            for jx in range(j_begin+1, j):
                W_arr_arr[jx][i] += j-j_begin-1
            j_begin = j

max_ans = max([max(W_arr) for W_arr in W_arr_arr]) - 1

print(max_ans)


Fixed submission:
H,W = (int(x) for x in input().split())

S_arr_arr = [[1]*(W+2)]
for i in range(H):
    S_arr_arr.append([0 if s=="." else 1 for s in "#"+input()+"#"])
S_arr_arr.append([1]*(W+2))

W_arr_arr = [[0]*(W+2) for _ in range(H+2)]
for j in range(H+2):
    i_begin = 0
    for i in range(W+2):
        if S_arr_arr[j][i] == 1:
            for ix in range(i_begin+1, i):
                W_arr_arr[j][ix] += i-i_begin-1
            i_begin = i
for i in range(W+2):
    j_begin = 0
    for j in range(H+2):
        if S_arr_arr[j][i] == 1:
            for jx in range(j_begin+1, j):
                W_arr_arr[jx][i] += j-j_begin-1
            j_begin = j

max_ans = max([max(W_arr) for W_arr in W_arr_arr]) - 1

print(max_ans)
Buggy python submission (verdict: Runtime Error):
N,M = (int(x) for x in input().split())
A_arr = [int(x) for x in input().split()]
BC_arr = [[0,0] for _ in range(M)]
for i in range(M):
    b,c = (int(x) for x in input().split())
    BC_arr[i][0] = b
    BC_arr[i][1] = c

A_arr.sort()
BC_arr.sort(key=lambda x:x[1], reverse=True)

break_th = False
j_count = 0
for BC in BC_arr:
    Bi = BC[0]
    Ci = BC[1]
    for j in range(Bi):
        if A_arr[j_count] >= Ci:
            break_th = True
            break
        A_arr[j_count] = Ci
        j_count += 1
    if break_th:
        break
print(sum(A_arr))


Fixed submission:
N,M = (int(x) for x in input().split())
A_arr = [int(x) for x in input().split()]
BC_arr = [[0,0] for _ in range(M)]
for i in range(M):
    b,c = (int(x) for x in input().split())
    BC_arr[i][0] = b
    BC_arr[i][1] = c

A_arr.sort()
BC_arr.sort(key=lambda x:x[1], reverse=True)

break_th = False
j_count = 0
for BC in BC_arr:
    Bi = BC[0]
    Ci = BC[1]
    for j in range(Bi):
        if A_arr[j_count] >= Ci:
            break_th = True
            break
        A_arr[j_count] = Ci
        j_count += 1
        if j_count == N:
            break_th = True
            break
    if break_th:
        break
print(sum(A_arr))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = (int(x) for x in input().split())
A_arr = [int(x) for x in input().split()]
BC_arr = [[0,0] for _ in range(M)]
for i in range(M):
    b,c = (int(x) for x in input().split())
    BC_arr[i][0] = b
    BC_arr[i][1] = c

A_arr.sort()

for BC in BC_arr:
    Bi = BC[0]
    Ci = BC[1]
    for j in range(Bi):
        if A_arr[j] < Ci:
            A_arr[j] = Ci
        else:
            break
    A_arr.sort()

print(sum(A_arr))


Fixed submission:
N,M = (int(x) for x in input().split())
A_arr = [int(x) for x in input().split()]
BC_arr = [[0,0] for _ in range(M)]
for i in range(M):
    b,c = (int(x) for x in input().split())
    BC_arr[i][0] = b
    BC_arr[i][1] = c

A_arr.sort()
BC_arr.sort(key=lambda x:x[1], reverse=True)

break_th = False
j_count = 0
for BC in BC_arr:
    Bi = BC[0]
    Ci = BC[1]
    for j in range(Bi):
        if A_arr[j_count] >= Ci:
            break_th = True
            break
        A_arr[j_count] = Ci
        j_count += 1
        if j_count == N:
            break_th = True
            break
    if break_th:
        break
print(sum(A_arr))
Buggy python submission (verdict: Runtime Error):
def uf_init(n):
    return list(range(n))

def uf_root(uf, x):
    if uf[x] != x:
        uf[x] = uf_root(uf, uf[x])
    return uf[x]

def uf_same(uf, x, y):
    return uf_root(uf, x) == uf_root(uf, y)

def uf_unite(uf, x, y):
    x = uf_root(uf, x)
    y = uf_root(uf, y)
    if x == y:
        return
    uf[x] = y

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

uf = uf_init(N)

for _ in range(M):
    X,Y,Z = (int(x) for x in input().split())
    uf_unite(uf, X-1, Y-1)

uf_roots = set()
for i in range(N):
    uf_roots.add(uf_root(uf, i))

print(len(uf_roots))



Fixed submission:
def uf_init(n):
    return list(range(n))

def uf_root(uf, x):
    update_node_arr = []
    while(uf[x] != x):
        update_node_arr.append(x)
        x = uf[x]
    for y in update_node_arr:
        uf[y] = x
    return x

def uf_same(uf, x, y):
    return uf_root(uf, x) == uf_root(uf, y)

def uf_unite(uf, x, y):
    x = uf_root(uf, x)
    y = uf_root(uf, y)
    if x == y:
        return
    uf[x] = y

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

uf = uf_init(N)

for _ in range(M):
    X,Y,Z = (int(x) for x in input().split())
    uf_unite(uf, X-1, Y-1)

uf_roots = set()
for i in range(N):
    uf_roots.add(uf_root(uf, i))

print(len(uf_roots))
Buggy python submission (verdict: Time Limit Exceeded):
N,M = (int(x) for x in input().split())

max_i = 0
for i in range(1, M//N+1):
    if M%i == 0 and M//i >= N:
        max_i = i
print(max_i)


Fixed submission:
N,M = (int(x) for x in input().split())

max_i = 0
for i in range(1, int(M**0.5)+1):
    if M%i == 0:
        if M//i >= N:
            max_i = max(max_i, i)
        if i >= N:
            max_i = max(max_i, M//i)
print(max_i)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())

if a > b:
  print("GREATER")
else :
  print("LESS")


Fixed submission:
a = int(input())
b = int(input())

if a > b:
  print("GREATER")
elif a < b:
  print("LESS")
else :
  print("EQUAL")
Buggy python submission (verdict: Runtime Error):
from math import gcd
from functools import reduce


def least_common_multiple(iter):
    '''
    最小公倍数を返す
    '''
    lcm = lambda x, y: x*y//gcd(x, y)
    return reduce(lcm, iter)


AB = map(int, input().split())
print(least_common_multiple(AB))


Fixed submission:
from functools import reduce
from fractions import gcd


def least_common_multiple(iter):
    '''
    最小公倍数を返す
    '''
    lcm = lambda x, y: x*y//gcd(x, y)
    return reduce(lcm, iter)


AB = map(int, input().split())
print(least_common_multiple(AB))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

X = [-1, -1, -1]
ans = 1
for a in A:
    t = X.count(a-1)
    ans = ans * t % 1000000007
    idx = X.index(a-1)
    if idx < 0:
        print(0)
        exit()
    X[idx] += 1
print(ans)


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

X = [-1, -1, -1]
ans = 1
for a in A:
    t = X.count(a-1)
    ans = ans * t % 1000000007
    if a-1 not in X:
        print(0)
        exit()
    idx = X.index(a-1)
    X[idx] += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

X = [-1, -1, -1]
ans = 1
for a in A:
    t = X.count(a-1)
    ans = ans * t % 1000000007
    X[X.index(a-1)] += 1
print(ans)


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

X = [-1, -1, -1]
ans = 1
for a in A:
    t = X.count(a-1)
    ans = ans * t % 1000000007
    if a-1 not in X:
        print(0)
        exit()
    idx = X.index(a-1)
    X[idx] += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

X = [-1, -1, -1]
ans = 1
for a in A:
    t = X.count(a-1)
    ans = ans * t % 1000000007
    if a-1 not in X:
        print(0)
        exit()
    idx = X.index(a-1)
    X[idx] += 1
print(ans)


Fixed submission:
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

P = (A1 - B1) * T1
Q = (A2 - B2) * T2

if P > 0:
    P *= -1
    Q *= -1

if P + Q < 0:
    print(0)
elif P + Q == 0:
    print('infinity')
else:
    S, T = divmod(-P, P+Q)
    if T != 0:
        print(S * 2 + 1)
    else:
        print(S * 2)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = input()

# 現在位置
now = 0
_now = 0
ans = []
while now <= N-1:
    for i in range(M, 0, -1):
        if now+i > N:
            continue
        if S[now+i] == '0':
            ans.append(i)
            now += i
    if _now == now:
        print(-1)
        exit()
    _now = now

# 辞書順最小化を目指す
ans = sorted(ans)
new_ans = []
now = 0
while len(ans) > 0:
    length = 0
    for a in ans:
        if S[now+a] == '0':
            new_ans.append(a)
            now += a
            length = a
            break
    ans.remove(length)
print(*new_ans)


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

# 現在位置
now = 0
_now = 0
ans = []
while now <= N-1:
    for i in range(min(M, N-now), 0, -1):
        if S[now+i] == '0':
            ans.append(i)
            now += i
            break
    if _now == now:
        print(-1)
        exit()
    _now = now
print(*reversed(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)

while M > 0:
    A[0] //= 2
    for i in range(1, N):
        if A[0] > A[i]:
            A = A[1:i] + [A[0]] + A[i:]
            break
    else:
        A = A[1:] + [A[0]]
    M -= 1
print(sum(A))


Fixed submission:
import heapq


class Reverse:
    def __init__(self, val):
        self.val = val

    def __lt__(self, other):
        return self.val > other.val

    def __repr__(self):
        return repr(self.val)


class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
        self.desc = desc
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        if len(self.hq) == 0:
            return None
        if self.desc:
            return heapq.heappop(self.hq).val
        else:
            return heapq.heappop(self.hq)

    def push(self, a):
        if self.desc:
            heapq.heappush(self.hq, Reverse(a))
        else:
            heapq.heappush(self.hq, a)


N, M = map(int, input().split())
q = Heapq(list(map(int, input().split())), desc=True)

while M > 0:
    a = q.pop() // 2
    q.push(a)
    M -= 1

tmp = 0
while True:
    try:
        a = q.pop()
        tmp += a
    except:
        break
print(tmp)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i in range(N-1, -1, -1):
    for j in range(N-1, i, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i+1][j+1]+1

ans = 0
for i in range(N):
    for j in range(i+1, N):
        now = min(dp[i][j], j-i)
        ans = max(ans, now)
print(ans)


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

ans = 0
len_s = 1
for i in range(N):
    tmp_s = S[i:i+len_s]
    while tmp_s in S[i+len_s:]:
        len_s += 1
        tmp_s = S[i:i+len_s]
        ans += 1
print(ans)

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

dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i in range(N-1, -1, -1):
    for j in range(N-1, -1, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i+1][j+1]+1

ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        now = min(dp[i][j], j-i)
        ans = max(ans, now)
print(ans)


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

ans = 0
len_s = 1
for i in range(N):
    tmp_s = S[i:i+len_s]
    while tmp_s in S[i+len_s:]:
        len_s += 1
        tmp_s = S[i:i+len_s]
        ans += 1
print(ans)

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

for length_s in range(N//2, 0, -1):
    for start_s in range(0, N-length_s):
        check_s = S[start_s:start_s+length_s]
        if length_s > N - start_s - length_s:
            break
        if check_s in S[start_s+length_s:]:
            print(length_s)
            exit()
print(0)


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

ans = 0
len_s = 1
for i in range(N):
    tmp_s = S[i:i+len_s]
    while tmp_s in S[i+len_s:]:
        len_s += 1
        tmp_s = S[i:i+len_s]
        ans += 1
print(ans)

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

for length_s in range(N//2, 0, -1):
    for start_s in range(0, N-length_s):
        check_s = S[start_s:start_s+length_s]
        if check_s in S[start_s+length_s:]:
            print(length_s)
            exit()
print(0)


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

ans = 0
len_s = 1
for i in range(N):
    tmp_s = S[i:i+len_s]
    while tmp_s in S[i+len_s:]:
        len_s += 1
        tmp_s = S[i:i+len_s]
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
print(sum(list(range(N))))


Fixed submission:
N = int(input())
print((N-1) * N // 2)
Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
# tree = [list(map(int, input().split())) for i in range(n-1)]
edges = [set() for i in range(n)]
for _ in range(n-1):
    a, b= map(int,input().split())
    edges[a-1].add(b-1)
cnt = [0] * n

for _ in range(q):
    p, x = map(int, input().split())
    cnt[p-1] += x

l = [[0, cnt[0]]]
while len(l) != 0:
    a, b = l.pop()
    if a != 0:
        cnt[a] += b
    for i in edges[a]:
        l.append((i, cnt[a]))
print(*cnt)


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

print(s if a >= 3200 else 'red')
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
edges = [set() for i in range(n)]
for _ in range(n-1):
    a, b= map(int,input().split())
    edges[a-1].add(b-1)
cnt = [0] * n

for _ in range(q):
    p, x = map(int, input().split())
    l = [p-1]
    while len(l) != 0:
        a = l.pop()
        cnt[a] += x
        for i in edges[a]:
            l.append(i)
print(*cnt)


Fixed submission:
n, q = map(int, input().split())
# tree = [list(map(int, input().split())) for i in range(n-1)]
edges = [set() for i in range(n)]
for _ in range(n-1):
    a, b= map(int,input().split())
    edges[a-1].add(b-1)
cnt = [0] * n

for _ in range(q):
    p, x = map(int, input().split())
    cnt[p-1] += x

l = [0]
l2 = [cnt[0]]
while len(l) != 0:
    a = l.pop()
    b = l2.pop()
    if a != 0:
        cnt[a] += b
    for i in edges[a]:
        l.append(i)
        l2.append(cnt[a])
print(*cnt)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


def move(s, score):
    new_score = [0] * len(s)
    for i, v in enumerate(score):
        if v == 0:
            continue
        if s[i] == 'R':
            new_score[i + 1] += v
        else:
            new_score[i - 1] += v
    return new_score


if __name__ == '__main__':
    s = input()
    score = _score = [1] * len(s)
    i = 0
    while True:
        tmp_score = score
        score = move(s, score)
        if score == _score:
            if i % 2 == 0:
                score = move(s, score)
            break
        _score = tmp_score
        i += 1
    print(' '.join(map(str, score)))


Fixed submission:
# -*- coding: utf-8 -*-


if __name__ == '__main__':
    S = input()
    score = _score = [0] * len(S)
    r_num = 0
    l_num = 0
    _s = None
    change_idx = None
    for i, s in enumerate(S):
        if s == 'L' and _s == 'R':
            change_idx = i
        if s == 'R' and _s == 'L':
            #計算
            if r_num == l_num or (r_num + l_num) % 2 == 0:
                score[change_idx - 1] = (r_num + l_num) / 2
                score[change_idx] = (r_num + l_num) / 2
            elif r_num % 2 == 0:
                score[change_idx - 1] = (r_num + l_num) // 2
                score[change_idx] = (r_num + l_num) // 2 + 1
            else:
                score[change_idx - 1] = (r_num + l_num) // 2 + 1
                score[change_idx] = (r_num + l_num) // 2
            #初期化
            r_num = 0
            l_num = 0
            change_idx = None
        if s == 'R':
            r_num += 1
        else:
            l_num += 1
        _s = s

    #計算
    if r_num == l_num or (r_num + l_num) % 2 == 0:
        score[change_idx - 1] = (r_num + l_num) / 2
        score[change_idx] = (r_num + l_num) / 2
    elif r_num % 2 == 0:
        score[change_idx - 1] = (r_num + l_num) // 2
        score[change_idx] = (r_num + l_num) // 2 + 1
    else:
        score[change_idx - 1] = (r_num + l_num) // 2 + 1
        score[change_idx] = (r_num + l_num) // 2

    print(' '.join(map(str, map(int, score))))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


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 sorted(divisors, reverse=True)


if __name__ == '__main__':
    n, k = map(int, input().split(' '))
    A = list(map(int, input().split(' ')))
    divisors = make_divisors(sum(A))
    for divisor in divisors:
        remainders = sorted(map(lambda x: x % divisor, A))
        for i in range(1, n):
            ope_num = max(sum(remainders[0:i]), sum(map(lambda x: divisor - x, remainders[i:n])))
            if ope_num <= k:
                print(divisor)
                exit()

Fixed submission:
# -*- coding: utf-8 -*-


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 sorted(divisors, reverse=True)


if __name__ == '__main__':
    n, k = map(int, input().split(' '))
    A = list(map(int, input().split(' ')))
    divisors = make_divisors(sum(A))
    for divisor in divisors:
        remainders = sorted(map(lambda x: x % divisor, A))
        idx = n - sum(remainders) // divisor
        ope_num = sum(remainders[:idx])
        if ope_num <= k:
            print(divisor)
            break
Buggy python submission (verdict: Runtime Error):
# vをcに塗る。pはvの親
def dfs(v, p, c):
    res[v] = c
    for e in G[v]:
        if e[0] == p:
            continue
        if e[1] & 1:
            dfs(e[0], v, 1-c)
        else:
            dfs(e[0], v, c)


N = int(input())

G = [[] for _ in range(N)]
res = [0] * N
for _ in range(N-1):
    u, v, w = map(int, input().split())
    G[u-1].append([v-1, w])
    G[v-1].append([u-1, w])
dfs(0, -1, 1)
print('\n'.join(map(str, res)))


Fixed submission:
import sys
sys.setrecursionlimit(pow(10, 7))


# vをcに塗る。pはvの親
def dfs(v, p, c):
    res[v] = c
    for e in G[v]:
        if e[0] == p:
            continue
        if e[1] & 1:
            dfs(e[0], v, 1-c)
        else:
            dfs(e[0], v, c)


N = int(input())

G = [[] for _ in range(N)]
res = [0] * N
for _ in range(N-1):
    u, v, w = map(int, input().split())
    G[u-1].append([v-1, w])
    G[v-1].append([u-1, w])
dfs(0, -1, 1)
print('\n'.join(map(str, res)))
Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split(' '))
s = input()
c = [0] * n
for i in range(1, n):
    c[i] += c[i-1]
    if s[i-1:i+1] == 'AC':
        c[i] += 1
for _ in range(q):
    l, r = map(int, input().split(' '))
    print(c[r-1] - c[l-1])


Fixed submission:
master = {
    'A': 'T',
    'T': 'A',
    'C': 'G',
    'G': 'C'
}
print(master[input()])
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split(' '))
s = input()
c = [0] * n
for i in range(1, n+1):
    c[i-1] = s[:i].count('AC')
for _ in range(q):
    l, r = map(int, input().split(' '))
    print(c[r-1] - c[l-1])


Fixed submission:
n, q = map(int, input().split(' '))
s = input()
c = [0] * n
for i in range(1, n):
    c[i] += c[i-1]
    if s[i-1:i+1] == 'AC':
        c[i] += 1
for _ in range(q):
    l, r = map(int, input().split(' '))
    print(c[r-1] - c[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split(' '))
s = input()
for _ in range(q):
    l, r = map(int, input().split(' '))
    print(s[l-1:r].count('AC'))


Fixed submission:
n, q = map(int, input().split(' '))
s = input()
c = [0] * n
for i in range(1, n):
    c[i] += c[i-1]
    if s[i-1:i+1] == 'AC':
        c[i] += 1
for _ in range(q):
    l, r = map(int, input().split(' '))
    print(c[r-1] - c[l-1])
Buggy python submission (verdict: Runtime Error):
coin = {}
for _ in range(int(input())):
    x, u = input().split(' ')
    coin[u] = coin.get(u, 0) + float(x)

print(coin['JPY'] + coin['BTC'] * 380000)


Fixed submission:
coin = {
    'JPY': 0,
    'BTC': 0
}
for _ in range(int(input())):
    x, u = input().split(' ')
    coin[u] += float(x)
print(coin['JPY'] + coin['BTC'] * 380000)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
V = list(map(int, input().split()))
S1 = Counter([V[i] for i in range(0, N, 2)])
S2 = Counter([V[i] for i in range(1, N, 2)])

S1 = sorted(S1.items(), key=lambda x: x[1], reverse=True)
S2 = sorted(S2.items(), key=lambda x: x[1], reverse=True)

if S1[0][0] == S2[0][0]:
    ans = min(N-(S1[0][1]+S2[1][1]), N-(S1[1][1]+S2[0][1]))
else:
    ans = N - (S1[0][1] + S2[0][1])
print(ans)


Fixed submission:
from collections import Counter

N = int(input())
V = list(map(int, input().split()))
S1 = Counter([V[i] for i in range(0, N, 2)])
S2 = Counter([V[i] for i in range(1, N, 2)])

S1 = sorted(S1.items(), key=lambda x: x[1], reverse=True)
S2 = sorted(S2.items(), key=lambda x: x[1], reverse=True)
S1.append([0, 0])
S2.append([0, 0])

if S1[0][0] == S2[0][0]:
    ans = min(N-(S1[0][1]+S2[1][1]), N-(S1[1][1]+S2[0][1]))
else:
    ans = N - (S1[0][1] + S2[0][1])
print(ans)
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
x = list(map(lambda y: abs(x - int(y)), input().split()))


from functools import reduce
from math import gcd
def greatest_common_divisor(iter):
    '''
    最大公約数を返す
    '''
    return reduce(gcd, iter)


print(greatest_common_divisor(x))


Fixed submission:
n, x = map(int, input().split())
x = list(map(lambda y: abs(x - int(y)), input().split()))


from functools import reduce
from fractions import gcd
def greatest_common_divisor(iter):
    '''
    最大公約数を返す
    '''
    return reduce(gcd, iter)


print(greatest_common_divisor(x))