Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = input()

    sum_count = s.count('R') * s.count('G') * s.count('B')

    r_list = []
    g_list = []
    b_list = []

    for i in range(n):
        if s[i] == 'R':
            r_list.append(i)
        elif s[i] == 'G':
            g_list.append(i)
        elif s[i] == 'B':
            b_list.append(i)

    for r in r_list:
        for g in g_list:
            L = g - r
            if g + L in b_list:
                sum_count -= 1
            if r - L in b_list:
                sum_count -= 1
            if L % 2 == 0 and L//2 + r in b_list:
                sum_count -= 1

    print(sum_count)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n = int(input())
    s = input()

    sum_count = s.count('R') * s.count('G') * s.count('B')

    r_list = set()
    g_list = set()
    b_list = set()

    for i in range(n):
        if s[i] == 'R':
            r_list.add(i)
        elif s[i] == 'G':
            g_list.add(i)
        elif s[i] == 'B':
            b_list.add(i)

    for r in r_list:
        for g in g_list:
            L = g - r
            if g + L in b_list:
                sum_count -= 1
            if r - L in b_list:
                sum_count -= 1
            if L % 2 == 0 and L//2 + r in b_list:
                sum_count -= 1

    print(sum_count)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = input()

    sum_count = s.count('R') * s.count('G') * s.count('B')

    r_list = []
    g_list = []
    b_list = []

    for i in range(n):
        if s[i] == 'R':
            r_list.append(i)
        elif s[i] == 'G':
            g_list.append(i)
        elif s[i] == 'B':
            b_list.append(i)

    for r in r_list:
        for g in g_list:
            L = g - r
            if g + L in b_list:
                sum_count -= 1
            if r - L in b_list:
                sum_count -= 1
            if L % 2 == 0 and L//2 + r in b_list:
                sum_count -= 1

    print(sum_count)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n = int(input())
    s = input()

    sum_count = s.count('R') * s.count('G') * s.count('B')

    r_list = set()
    g_list = set()
    b_list = set()

    for i in range(n):
        if s[i] == 'R':
            r_list.add(i)
        elif s[i] == 'G':
            g_list.add(i)
        elif s[i] == 'B':
            b_list.add(i)

    for r in r_list:
        for g in g_list:
            L = g - r
            if g + L in b_list:
                sum_count -= 1
            if r - L in b_list:
                sum_count -= 1
            if L % 2 == 0 and L//2 + r in b_list:
                sum_count -= 1

    print(sum_count)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

def main():
    n, x, y = map(int, input().split())
    cost = [[float("inf") for i in range(n)] for i in range(n)] 
    for i in range(n):
        if i == n - 1:
            tmp_x, tmp_y = x-1, y-1
        else:
            tmp_x, tmp_y = i, i+1
        cost[tmp_x][tmp_y] = 1
        cost[tmp_y][tmp_x] = 1

    ans_list = [0]*n

    for i in range(n):
        di_list = dijkstra(i,n,n,cost)
        for j in range(i+1,n):
            ans_list[di_list[j]] += 1

    for i in range(1,n):
        print(ans_list[i])

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n, x, y = map(int, input().split())

    x -= 1
    y -= 1

    ans_list = [0]*n

    for i in range(n):
        for j in range(i,n):
            ans_list[min(abs(i-j), abs(i-x)+abs(j-y)+1, abs(j-x)+abs(i-y)+1)] += 1

    for i in range(1,n):
        print(ans_list[i])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from scipy import special

def main():
    n, m = map(int, input().split())

    ans = 0
    ans += special.comb(n, 2)
    ans += special.comb(m, 2)

    print(int(ans))

if __name__ == '__main__':
    main()


Fixed submission:
from itertools import combinations

def main():
    n, m = map(int, input().split())

    ans = 0

    n_list = [i+1 for i in range(n)]
    m_list = [i+1 for i in range(m)]

    ans += len(list(combinations(n_list, 2)))
    ans += len(list(combinations(m_list, 2)))

    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
from scipy import special

def main():
    n, m = map(int, input().split())

    ans = 0
    ans += special.comb(n, 2)
    ans += special.comb(m, 2)

    print(int(ans))

if __name__ == '__main__':
    main()

Fixed submission:
from itertools import combinations

def main():
    n, m = map(int, input().split())

    ans = 0

    n_list = [i+1 for i in range(n)]
    m_list = [i+1 for i in range(m)]

    ans += len(list(combinations(n_list, 2)))
    ans += len(list(combinations(m_list, 2)))

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter # 重複個数のカウント: Counter(num_list)

def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    ans = 0

    cnt_list = Counter(num_list)

    for i in range(n):
        for k, v in cnt_list.items():
            if k == num_list[i]:
                v -= 1
            if v == 1:
                continue
            ans += v * (v-1) // 2
        print(ans)
        ans = 0

if __name__ == '__main__':
    main()

Fixed submission:
from collections import Counter # 重複個数のカウント: Counter(num_list)

def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    ans_list = [0] * n
    cnt_list = Counter(num_list)
    for k, v in cnt_list.items():
        if v == 1:
            ans_list[k-1] = 0
            continue
        ans_list[k-1] = v * (v-1) // 2
        
    sum_num = sum(ans_list)

    ans = sum_num

    for i in range(n):
        ans -= ans_list[num_list[i]-1]
        if cnt_list[num_list[i]]-1 != 1:
            ans += (cnt_list[num_list[i]]-1) * (cnt_list[num_list[i]]-2) // 2
        print(ans)
        ans = sum_num

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter # 重複個数のカウント: Counter(num_list)
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    cp_num_list = num_list[:]
    ans = 0

    for i in range(n):
        cp_num_list.pop(i)
        cnt_list = Counter(cp_num_list)
        for v in cnt_list.values():
            if v == 1:
                continue
            ans += comb(v, 2)
        print(ans)
        cp_num_list = num_list[:]
        ans = 0


if __name__ == '__main__':
    main()

Fixed submission:
from collections import Counter # 重複個数のカウント: Counter(num_list)

def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    ans_list = [0] * n
    cnt_list = Counter(num_list)
    for k, v in cnt_list.items():
        if v == 1:
            ans_list[k-1] = 0
            continue
        ans_list[k-1] = v * (v-1) // 2
        
    sum_num = sum(ans_list)

    ans = sum_num

    for i in range(n):
        ans -= ans_list[num_list[i]-1]
        if cnt_list[num_list[i]]-1 != 1:
            ans += (cnt_list[num_list[i]]-1) * (cnt_list[num_list[i]]-2) // 2
        print(ans)
        ans = sum_num

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    q = int(input())

    is_true = True
    for _ in range(q):
        input_list = list(input().split())
        if input_list[0] == '1':
            if is_true:
                is_true = False
            else:
                is_true = True
            continue
        if input_list[1] == '1':
            if is_true:
                t = [input_list[2], s]
                s = ''.join(t)
            else:
                t = [s, input_list[2]]
                s = ''.join(t)
        else:
            if is_true:
                t = [s, input_list[2]]
                s = ''.join(t)
            else:
                t = [input_list[2], s]
                s = ''.join(t)
            
    if not is_true:
        s = s[::-1]

    print(s)

if __name__ == '__main__':
    main()

Fixed submission:
from collections import deque

def main():
    s = input()
    q = int(input())

    is_true = True

    d = deque(s)

    for _ in range(q):
        input_list = list(input().split())
        if input_list[0] == '1':
            if is_true:
                is_true = False
            else:
                is_true = True
            continue
        if input_list[1] == '1':
            if is_true:
                d.appendleft(input_list[2])
            else:
                d.append(input_list[2])

        else:
            if is_true:
                d.append(input_list[2])
            else:
                d.appendleft(input_list[2])
            
    if not is_true:
        d.reverse()

    print(''.join(d))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    q = int(input())

    is_true = True
    for i in range(q):
        input_list = list(input().split())
        if input_list[0] == '1':
            if is_true:
                is_true = False
            else:
                is_true = True
            continue
        if input_list[1] == '1':
            if is_true:
                s = input_list[2] + s
            else:
                s = s + input_list[2]
        else:
            if is_true:
                s = s + input_list[2]
            else:
                s = input_list[2] + s
            
    if not is_true:
        s = s[::-1]

    print(s)

if __name__ == '__main__':
    main()

Fixed submission:
from collections import deque

def main():
    s = input()
    q = int(input())

    is_true = True

    d = deque(s)

    for _ in range(q):
        input_list = list(input().split())
        if input_list[0] == '1':
            if is_true:
                is_true = False
            else:
                is_true = True
            continue
        if input_list[1] == '1':
            if is_true:
                d.appendleft(input_list[2])
            else:
                d.append(input_list[2])

        else:
            if is_true:
                d.append(input_list[2])
            else:
                d.appendleft(input_list[2])
            
    if not is_true:
        d.reverse()

    print(''.join(d))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
mod = 1000000007

def mod_cmb(n: int, k: int, p: int) -> int:
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    if (k > n - k):
        return mod_cmb(n, n - k, p)
    c = d = 1
    for i in range(k):
        c *= (n - i)
        d *= (k - i)
        c %= p
        d %= p
    return c * pow(d, -1, p) % p

def main():
    n, a, b = map(int, input().split())

    ans = pow(2, n, mod) - 1

    tmp_a = mod_cmb(n , a, mod)
    tmp_b = mod_cmb(n , b, mod)

    print((ans-tmp_a-tmp_b)%mod)

if __name__ == '__main__':
    main()


Fixed submission:
mod = 1000000007

# 繰り返し二乗法  
def mod_pow(a, n, p):
    if n == 1:
        return a % p
    if n % 2 == 1:
        return (a* mod_pow(a, n - 1, p)) % p
    tmp = mod_pow(a, n / 2, p)
    return ( tmp * tmp ) % p

# 組み合わせ
def mod_cmb(n, k, p):
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    if (k > n - k):
        return mod_cmb(n, n - k, p)
    c = d = 1
    for i in range(k):
        c *= (n - i)
        d *= (k - i)
        c %= p
        d %= p
    return c * mod_pow(d, p - 2, p) % p

def main():
    n, a, b = map(int, input().split())

    ans = mod_pow(2, n, mod) - 1

    tmp_a = mod_cmb(n , a, mod)
    tmp_b = mod_cmb(n , b, mod)

    print((ans-tmp_a-tmp_b)%mod)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    count = n

    for i in range(1,n+1):
        for j in range(1,i):
            if num_list[i-1] > num_list[j-1]:
                count -= 1
                break

    print(count)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    count = n

    min = num_list[0]

    for i in range(1,n):
        if num_list[i] > min:
            count -= 1
        if num_list[i] < min:
            min = num_list[i]

    print(count)

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

def main():
    n = int(input())
    s = input()

    ans = 0

    cmb_list = list(itertools.combinations(range(n), 3))
    cmb_len = len(cmb_list)

    output_list = []

    for a, b,c in cmb_list:
        tmp = s[a] + s[b] + s[c]
        output_list.append(tmp)

    print(len(set(output_list)))

if __name__ == '__main__':
    main()

Fixed submission:
import itertools

def main():
    n = int(input())
    s = input()

    ans = 0
    output_list = []

    for i in range(1000):
        if len(str(i)) == 1:
            a = 0
            b = 0
            c = i
        elif len(str(i)) == 2:
            a = 0
            b = i // 10
            c = i - b * 10
        else:
            a = i // 100
            b = (i - a * 100) // 10
            c = i - a * 100 - b * 10
        tmp = str(a) + str(b) + str(c)
        output_list.append(tmp)
    
    for i in range(1000):
        a = output_list[i][0]
        b = output_list[i][1]
        c = output_list[i][2]
        first_flag = False
        second_flag = False
        for j in range(n):
            if not first_flag and s[j] == a:
                first_flag = True
                continue
            if first_flag and not second_flag and s[j] == b:
                second_flag = True
                continue
            if first_flag and second_flag and s[j] == c:
                ans += 1
                break

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
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 main():
    n = int(input())

    count = n + 1

    ls = make_divisors(n)

    for i in range(len(ls)):
        if i % 2 != 0:
            continue
        if ls[i] + ls[i+1] < count:
            count = ls[i] + ls[i+1]

    print(count-2)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n = int(input())

    count = n + 1

    for i in range(1,int(n**0.5)+1):
        if n % i == 0 and n // i + i < count:
            count = n // i + i

    print(count-2)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k, q = map(int, input().split())
    
    ls = [k] * n

    for i in range(q):
        maru = int(input())
        for j in range(n):
            if j != maru - 1:
                ls[j] -= 1

    for i in range(n):
        print('Yes' if ls[i] > 0 else 'No')

if __name__ == '__main__':
    main()

Fixed submission:
import numpy as np

def main():
    n, k, q = map(int, input().split())
    
    ls = [q] * n

    rls = [k] * n

    maru_list = [0] * n

    ls = np.array(ls)
    rls = np.array(rls)
    maru_list = np.array(maru_list)

    for i in range(q):
        maru = int(input())
        maru_list[maru-1] += 1

    ls = ls - maru_list

    rls = rls - ls

    for i in range(n):
        print('Yes' if rls[i] > 0 else 'No')

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())

    ans = 0
    for i in range(n):
        ans += i % n

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n = int(input())

    ans = 0

    for i in range(1,n):
        ans += i

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    num_list = [int(input()) for _ in range(n)]

    tmp = copy.deepcopy(num_list)
    tmp.sort()

    max_first = max(num_list)
    max_second = tmp[1]
    
    for num in num_list:
        if num == max_first:
            print(max_second)
        else:
            print(max_first)
        
if __name__ == '__main__':
    main()

Fixed submission:
import copy

def main():
    n = int(input())
    num_list = [int(input()) for _ in range(n)]

    tmp = copy.deepcopy(num_list)
    tmp.sort()

    max_first = max(num_list)
    max_second = tmp[n-2]
    
    for num in num_list:
        if num == max_first:
            print(max_second)
            continue
        print(max_first)
        
if __name__ == '__main__':
    main()

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

def main():
    n = int(input())
    num_list = [int(input()) for _ in range(n)]
    
    for i in range(n):
        tmp = copy.deepcopy(num_list)
        tmp.pop(i)
        print(max(set(tmp)))
        
if __name__ == '__main__':
    main()

Fixed submission:
import copy

def main():
    n = int(input())
    num_list = [int(input()) for _ in range(n)]

    tmp = copy.deepcopy(num_list)
    tmp.sort()

    max_first = max(num_list)
    max_second = tmp[n-2]
    
    for num in num_list:
        if num == max_first:
            print(max_second)
            continue
        print(max_first)
        
if __name__ == '__main__':
    main()

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

def main():
    n = int(input())
    num_list = [int(input()) for _ in range(n)]
    
    for i in range(n):
        tmp = copy.deepcopy(num_list)
        tmp.pop(i)
        print(max(tmp))
        
if __name__ == '__main__':
    main()

Fixed submission:
import copy

def main():
    n = int(input())
    num_list = [int(input()) for _ in range(n)]

    tmp = copy.deepcopy(num_list)
    tmp.sort()

    max_first = max(num_list)
    max_second = tmp[n-2]
    
    for num in num_list:
        if num == max_first:
            print(max_second)
            continue
        print(max_first)
        
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n = map(int, input().split())

    train = n * a
    taxi = b

    print(min(train,taxi))

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, a, b = map(int, input().split())
 
    train = n * a
    taxi = b
 
    print(min(train,taxi))
 
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n,x = map(int, input().split())
    num_list = list(map(int, input().split()))

    count = 0
    sum = 0

    while(sum <= x):
        sum += num_list[count]
        count += 1

    print(count)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n,x = map(int, input().split())
    num_list = list(map(int, input().split()))

    sum = 0
    ans = 1

    for i in num_list:
        sum += i
        if sum <= x:
            ans += 1

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())

    card_list = [0] * n

    for _ in range(m):
        l, r = map(int, input().split())
        for i in range(l-1,r):
            card_list[i] += 1

    print(card_list.count(m))

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n, m = map(int, input().split())

    card_list = [0] * n

    l_list = []
    r_list = []

    for _ in range(m):
        l, r = map(int, input().split())
        l_list.append(l)
        r_list.append(r)

    max_l = max(l_list)
    min_r = min(r_list)

    print(min_r-max_l+1 if min_r >= max_l else 0)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        # tmp = num_list[i]
        # num_list[i] = max(num_list)
        # ans = max(ans, fractions.gcd(num_list[i],min(num_list)))
        # num_list[i] = tmp
        li = num_list[:i] + num_list[i + 1:]
        tmp = gcd_list(li)
        if tmp > ans:
            ans = tmp

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import fractions

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    left = [0] * (n + 1)
    right = [0] * (n + 1)
    for i in range(n):
        left[i + 1] = (fractions.gcd(left[i],num_list[i]))
        right[n - i - 1] = (fractions.gcd(right[n - i],num_list[n - 1 - i]))
    
    ans = 0
    for i in range(n):
        ans = max(ans,fractions.gcd(left[i],right[i + 1]))

    print(ans)

if __name__ == '__main__':
    main()

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

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    ans = 1
    for i in range(n):
        tmp = num_list[i]
        num_list[i] = max(num_list)
        ans = max(ans, gcd_list(num_list))
        num_list[i] = tmp

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import fractions

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    left = [0] * (n + 1)
    right = [0] * (n + 1)
    for i in range(n):
        left[i + 1] = (fractions.gcd(left[i],num_list[i]))
        right[n - i - 1] = (fractions.gcd(right[n - i],num_list[n - 1 - i]))
    
    ans = 0
    for i in range(n):
        ans = max(ans,fractions.gcd(left[i],right[i + 1]))

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    b = input()

    if b == 'A':
        print('T')
    else b == 'T':
        print('A')
    else b == 'C':
        print('G')
    else b == 'G':
        print('C')

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    b = input()

    if b == 'A':
        print('T')
    elif b == 'T':
        print('A')
    elif b == 'C':
        print('G')
    elif b == 'G':
        print('C')

if __name__ == '__main__':
    main()