Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#import itertools
import collections

def op(v):
    count = collections.Counter(v).most_common() 

    #v_ = itertools.groupby(sorted(v))
    #count = sorted([(k, len(list(g))) for k, g in v_], key = lambda x:x[1])
    return count

n = int(input())
V = [int(n) for n in input().split()]

if len(set(V)) == 1:
    ans = len(V) // 2
else:
    vp_ = [v for i, v in enumerate(V) if i%2 == 0] 
    vn_ = [v for i, v in enumerate(V) if i%2 != 0] 

    vp = op(vp_)
    vn = op(vn_)    

    if vp[-1][0] != vn[-1][0]:
        gp = vp[-1][1]
        gn = vn[-1][1]
    else:
        if vp[-1][1] > vn[-1][1]:
            gp = vp[-1][1]
            gn = vn[-2][1]
        else:
            gp = vp[-2][1]
            gn = vn[-1][1]

    #ans_p = sum([g for k, g in vp]) - gp
    #ans_n = sum([g for k, g in vn]) - gn

    #ans  = ans_p + ans_n
    ans = n - gp - gn

print(ans)



Fixed submission:
n = input()
#print(n)
new = []
for i in n:
    if i == '1':
        new.append('9')
    elif i =='9':
        new.append('1')
    else:
        new.append(i)
print(''.join(new))
Buggy python submission (verdict: Runtime Error):
n = list(map(int, input().split()))
nmax = max(n)
print(nmax * 10 + sum(n.remove(nmax)))

Fixed submission:
import itertools, copy

n = input().split()

ans = 0
for p0, p1 in itertools.permutations(n, 2):
    n_ = copy.copy(n)
    n_.remove(p0)
    n_.remove(p1)
    
    total = int(''.join([p0, p1])) + int(n_[0])
    ans = max(ans, total)

print(ans)

Buggy python submission (verdict: Runtime Error):
n = list(map(int, input().split()))
print(max(n) * 10 + sum(n.remove(nmax)))

Fixed submission:
import itertools, copy

n = input().split()

ans = 0
for p0, p1 in itertools.permutations(n, 2):
    n_ = copy.copy(n)
    n_.remove(p0)
    n_.remove(p1)
    
    total = int(''.join([p0, p1])) + int(n_[0])
    ans = max(ans, total)

print(ans)
Buggy python submission (verdict: Runtime Error):
if (a*b) % 2 == 0:
    print('No')
else:
    print('Yes') 

Fixed submission:
a, b = map(int, input().split())
if (a*b) % 2 == 0:
    print('No')
else:
    print('Yes')

Buggy python submission (verdict: Runtime Error):
if a*b % 2 == 0:
    print('No')
else:
    print('Yes') 

Fixed submission:
a, b = map(int, input().split())
if (a*b) % 2 == 0:
    print('No')
else:
    print('Yes')
Buggy python submission (verdict: Runtime Error):
D, G = [int(n) for n in input().split()]

score_table = []
for i in range(1, D+1):
    p, c = [int(n) for n in input().split()]
    score_table.append([i*100, p, c])

min_count = sum([l[1] for l in score_table])
#print(min_count)

for bit in range(1<<D):
    score = 0
    count = 0

    for i in range(D):
        if bit & (1<<i):
            score += score_table[i][0] * score_table[i][1] + score_table[i][2]
            count += score_table[i][1]
    
    if score >= G:
        min_count = min(min_count, count)
    else:
        additional = []
        for j in range(D):
            if not bit & (1<<j):
                additional.append(score_table[j])
        
        additional_ = sorted(additional, key=lambda x:x[0], reverse=True)
        #print(additional_)
        
        # for i in additional_:
        #     if i[1] > 1:
        #         add_score = i
        #         break

        add_score = additional_[0]

        for k in range(add_score[1]-1):
            score += add_score[0]
            count += 1
            if score >= G:
                min_count = min(min_count, count)

print(min_count)

Fixed submission:
R = int(input())

if R < 1200:
    print('ABC')
elif R < 2800:
    print('ARC')
else:
    print('AGC')
Buggy python submission (verdict: Runtime Error):
A = list(map(int, input().split()))

A = sorted(A)
ans = a[2] - a[0]
print(ans)

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

A = sorted(A)
ans = A[2] - A[0]
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
a_ = [n - (i+1) for i, n in enumerate(a) ]

b = sum(a_) // N
b_ = b + 1
s = [abs(n - b) for i, n in enumerate(a_)]
s_ = [abs(n - b_) for i, n in enumerate(a_)]

print(min(sum(s), sum(s_))

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
a_ = sorted([n - (i+1) for i, n in enumerate(a) ])

if N//2 == 0:
    b = a_[N//2]
else:
    b = a_[(N-1)//2]

s = [abs(n - b) for i, n in enumerate(a_)]

print(sum(s))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

count_min = 10**5

for i in range(n):
    s0 = s[:i].count('W')
    s1 = s[i+1:].count('E')
    count = s0+s1
    count_min = min(count_min, count)    
 
print(count_min)

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

w, e = 0, 0
W = [0]*n
E = [0]*n
for i in range(n):
    if s[i] == 'W':
        w += 1
        W[i] += w 
        E[i] = e
    else:
        e += 1
        E[i] += e
        W[i] = w

count_min = E[-1]
for i in range(1, n):
    count = W[i-1] + (E[-1] - E[i]) 
    count_min = min(count_min, count)

print(count_min)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = [['.']*W]
for i in range(H):
    S.append(['.'] + list(input()) + ['.'])
S.append(['.']*W)

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i][j] == '#':
            if S[i+1][j] == '.' and S[i-1][j] == '.' and S[i][j+1] == '.' and S[i][j-1] == '.':
                print('No')
                break
    else:
        continue
    break

else:
    print('Yes')

Fixed submission:
H, W = map(int, input().split())
S = [['.']*(W+2)]
for i in range(H):
    S.append(['.'] + list(input()) + ['.'])
S.append(['.']*(W+2))

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i][j] == '#':
            if S[i+1][j] == '.' and S[i-1][j] == '.' and S[i][j+1] == '.' and S[i][j-1] == '.':
                print('No')
                break
    else:
        continue
    break
else:
    print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
import copy

n = int(input())
x = [int(num) for num in input().split()]
xx = sorted(x)

for i in range(n):
    x_ =copy.copy(xx) 
    x_.remove(x[i])
    b = x_[n//2 - 1]
    print(b)

Fixed submission:
n = int(input())
x = [int(num) for num in input().split()]
xx = sorted(x)

mid_l = xx[n//2 -1]
mid_r = xx[n//2]

for _ in x:
    if _ <= mid_l:
        print(mid_r)
    else:
        print(mid_l)

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

n = int(input())
x = [int(num) for num in input().split()]
xs = sorted(x)

for i in range(n):
    xs_ = copy.copy(xs)
    xs_.remove(x[i])
    
    b = xs_[(n//2 - 1)]
    print(b)

Fixed submission:
n = int(input())
x = [int(num) for num in input().split()]
xx = sorted(x)

mid_l = xx[n//2 -1]
mid_r = xx[n//2]

for _ in x:
    if _ <= mid_l:
        print(mid_r)
    else:
        print(mid_l)

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

n = int(input())
x = [int(num) for num in input().split()]

for i in range(n):
    x_ = copy.copy(x)
    del x_[i]

    x_ = sorted(x_)
    b = x_[(n//2 - 1)]
    print(b)

Fixed submission:
n = int(input())
x = [int(num) for num in input().split()]
xx = sorted(x)

mid_l = xx[n//2 -1]
mid_r = xx[n//2]

for _ in x:
    if _ <= mid_l:
        print(mid_r)
    else:
        print(mid_l)
Buggy python submission (verdict: Time Limit Exceeded):
import copy

def calc_fee(l):
    s = 0
    l = [0] + l + [0]
    for i in range(len(l)-1):
        s += abs(l[i+1] - l[i])
    return s

n = int(input())
A = [int(n) for n in input().split()]

for i in range(n):
    A_ = copy.copy(A)
    del A_[i]
    
    price = calc_fee(A_)
    print(price)

Fixed submission:
def calc_fee(l):
    s = 0
    for i in range(len(l)-1):
        s += abs(l[i+1] - l[i])
    return s

n = int(input())
A = [0] + [int(n) for n in input().split()] + [0]


total_fee = calc_fee(A)

for i in range(1, n+1):
    price = total_fee - (abs(A[i] - A[i-1]) + abs(A[i+1] - A[i]))  + abs(A[i+1] - A[i-1])
    print(price)
Buggy python submission (verdict: Runtime Error):
import math

n = math.sqrt(int(input()))
print(math.floor(n)**2)

Fixed submission:
c = list(input())

if c[::-1] == list(input()):
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
n = math.sqrt(int(input()))
print(math.floor(n)**2)

Fixed submission:
import math
n = math.sqrt(int(input()))
print(math.floor(n)**2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(num) for num in input().split()]

count_max = 0
for x in range(min(a), max(a)+1):
    count=0
    for k in a:
        if x-1 <= k <= x+1:
            count += 1 
    count_max = max(count_max, count)

print(count_max)

Fixed submission:
import collections

n = int(input())
a = [int(num) for num in input().split()]

list_num = collections.Counter(a)

count_max = 0
for x in range(min(a), max(a)+1):
    count = list_num[x-1] + list_num[x] + list_num[x+1]
    count_max = max(count_max, count)

print(count_max)
Buggy python submission (verdict: Time Limit Exceeded):
k, s = [int(n) for n in input().split()]

count = 0
for i in range(k+1):
    for j in range(k+1):
        for l in range(k+1):
            if i + j + l == s:
                count += 1

print(count)

Fixed submission:
k, s = [int(n) for n in input().split()]

count = 0
for x in range(k+1):
    for y in range(k+1):
        if 0 <= s - (x + y) <= k:
            count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
A1, A2, A3 = input().split()

T = A1 + A2 + A3

if T > 21:
  print("bust")
else:
  print("win")

Fixed submission:
A1, A2, A3 = map(int, input().split())

t = A1 + A2 + A3

if t >= 22:
  print("bust")
else:
  print("win")
Buggy python submission (verdict: Time Limit Exceeded):
N, M = [int(x) for x in input().split()]

a, b = [int(x) for x in input().split()]
s = set(range(a, b + 1))
for _ in range(M-1):
  a, b = [int(x) for x in input().split()]
  temp = set(range(a, b + 1))
  s = s & temp
print(len(s))

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

max_a, min_b = 0, 10000000
for _ in range(M):
  a, b = [int(x) for x in input().split()]
  if a > max_a:
    max_a = a
  if b < min_b:
    min_b = b
if min_b < max_a:
  print(0)
else:
  print(min_b - max_a + 1)
Buggy python submission (verdict: Runtime Error):
N, M = [int(x) for x in input().split()]

A = [int(x) for x in input().split()]
A.sort(reverse=True)

C = []
for _ in range(M):
  b, c = [int(x) for x in input().split()]
  C.extend([c]*b)
C.sort(reverse=True)

total = 0
for _ in range(N):
  if A[0] > C[0]:
    a = A.pop(0)
    total += a
  else:
    c = C.pop(0)
    total += c

print(total)

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

A = [int(x) for x in input().split()]
A.sort(reverse=True)

S = []
for _ in range(M):
  b, c = [int(x) for x in input().split()]
  S.append((c, b))

S.sort(reverse=True)

total = 0
count = 0

while count < N and len(S) > 0:
  if A[0] > S[0][0]:
    a = A.pop(0)
    total += a
    count += 1
  else:
    c = S.pop(0)
    if c[1] < N - count:
      total += c[0] * c[1]
      count += c[1]
    else:
      total += c[0] * (N - count)
      count = N
if len(S) == 0:
  total += sum(A[:N-count])
print(total)
Buggy python submission (verdict: Runtime Error):
N, K = [int(x) for x input().split()]

print(N - K + 1)

Fixed submission:
N, K = [int(x) for x in input().split()]

print(N - K + 1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]


def max_GCD(m_list):
  m_list.sort()
  a = m_list.pop()
  result = a
  while m_list:
    b = m_list.pop()
    a = GCD(a, b)
    if a < result:
      result = a
    if result == 1:
      return result
  return result

def GCD(m, n):
  a = max(m, n)
  b = min(m, n)
  while b > 0:
    r = a % b
    if r == 0:
      return b
    a = b
    b = r  

r_list = [0] * N
for i in range(N):
  A_ = A.copy()
  A_.pop(i)
  r_list[i] = max_GCD(A_)
  
print(max(r_list))

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]

def GCD(m, n):
  if m == 0:
    return n
  elif n == 0:
    return m
  a = max(m, n)
  b = min(m, n)
  while b > 0:
    r = a % b
    if r == 0:
      return b
    a = b
    b = r  

L = [0] * (N + 1)
R = [0] * (N + 1)
for i in range(N):
  L[i + 1] = GCD(L[i], A[i])
  R[N - i - 1] = GCD(R[N - i], A[N - i - 1])
M = [GCD(L[i], R[i+1]) for i in range(N)]
print(max(M))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]

def GCD(m, n):
  a = max(m, n)
  b = min(m, n)
  while b > 0:
    r = a % b
    if r == 0:
      return b
    a = b
    b = r  

import numpy as np

B = np.ones((N, N)) * 10 ** 10

for m in range(N):
  for n in range(m, N):
    if m == n:
      B[m, m] = 0
    else:
      B[m, n] = B[n, m] = GCD(A[m], A[n])

C = B.sum(axis=1)
idx = C.argmin()

B = np.where(B == 0, 10 ** 10, B)
B = np.delete(B, idx, axis=0)
B = np.delete(B, idx, axis=1)
print(int(B.min()))

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]

def GCD(m, n):
  if m == 0:
    return n
  elif n == 0:
    return m
  a = max(m, n)
  b = min(m, n)
  while b > 0:
    r = a % b
    if r == 0:
      return b
    a = b
    b = r  

L = [0] * (N + 1)
R = [0] * (N + 1)
for i in range(N):
  L[i + 1] = GCD(L[i], A[i])
  R[N - i - 1] = GCD(R[N - i], A[N - i - 1])
M = [GCD(L[i], R[i+1]) for i in range(N)]
print(max(M))
Buggy python submission (verdict: Runtime Error):
S = input()

base_list = ["A", "T", "G", "C"]
seq_list = []
seq = ""
for s in S:
  if s in base_list:
    seq += s
  else:
    seq_list.append(seq)
    seq = ""
seq_len_list = [len(seq) for seq in seq_list]
print(max(seq_len_list))

Fixed submission:
S = input()

base_list = ["A", "T", "G", "C"]
seq_list = []
seq = ""
for s in S:
  if s in base_list:
    seq += s
  else:
    seq_list.append(seq)
    seq = ""
seq_list.append(seq)
seq_len_list = [len(seq) for seq in seq_list]
print(max(seq_len_list))
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = list(map(int, input().split()))
S = input()
import re


for _ in range(Q):
  l, r = list(map(int, input().split()))
  s = S[l-1:r]
  print(len(re.findall("AC", s)))

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

# Sのi番目までに出現するACの数を格納するリストです
t = [0] * (N + 1)
for i in range(N):
  t[i + 1] = t[i] + (1 if S[i:i+2] == "AC" else 0)
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(t[r-1] - t[l-1])
Buggy python submission (verdict: Runtime Error):
N, M = [int(x) for x in input().split()]
V = [tuple(map(int, innput().split())) for i in range(N)]
V.sort()

money = 0
count = 0

for a, b in V:
  if count + b < M:
    count += b
    money += a * b
  else:
    money += (M - b) * a
    break
print(money)

Fixed submission:
N, M = [int(x) for x in input().split()]
V = [tuple(map(int, input().split())) for i in range(N)]
V.sort()

money = 0
count = 0

for a, b in V:
  if count + b < M:
    count += b
    money += a * b
  else:
    money += (M - count) * a
    break
print(money)

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

class value():
  def __init__(self, a, b):
    self.a = a
    self.b = b
  def __gt__(self, other):
    return self.a > other.a
  def __ge__(self, other):
    return self.a >= other.a

V = []
for i in range(N):
  a, b = [int(x) for x in input().split()]
  V.append(value(a, b))
  V.sort()

money = 0
i = 0

while True:
  v = V[i]
  if M <= v.b:
    break
  else:
    money += v.a * v.b
    M -= v.b
    i += 1
money += v.a * M
print(money)

Fixed submission:
N, M = [int(x) for x in input().split()]
V = [tuple(map(int, input().split())) for i in range(N)]
V.sort()

money = 0
count = 0

for a, b in V:
  if count + b < M:
    count += b
    money += a * b
  else:
    money += (M - count) * a
    break
print(money)

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

A = [0] * N
B = [0] * N

for i in range(N):
  a, b = [int(x) for x in input().split()]
  A[i] = a
  B[i] = b
  
money = 0

while True:
  idx = A.index(min(A))
  a = A.pop(idx)
  b = B.pop(idx)
  if M <= b:
    break
  else:
    money += a * b
    M -= b
money += a * M
print(money)

Fixed submission:
N, M = [int(x) for x in input().split()]
V = [tuple(map(int, input().split())) for i in range(N)]
V.sort()

money = 0
count = 0

for a, b in V:
  if count + b < M:
    count += b
    money += a * b
  else:
    money += (M - count) * a
    break
print(money)
Buggy python submission (verdict: Runtime Error):
class Union_Find():
  def __init__(self, n):
    self.par = [-1] * n
  def root(self, x):
    if self.par[x] < 0:
      return x
    else:
      self.par[x] = root(par[x])
      return self.par[x]
  def unite(self, x, y):
    root_x = self.root(x)
    root_y = self.root(y)
    if root_x == root_y:
      pass
    else:
      self.par[root_x] = root_y
  def same(self, x, y):
    root_x = self.root(x)
    root_y = self.root(y)
    return root_x == root_y
  def count_size(self, x):
    # 根を共有している要素の数を数える。
    return self.par.count(self.root(x))
 
N, M = list(map(int, input().split()))
uf = Union_Find(N)
bridge_list = []
inconv_list = [0] * (M + 1)
inconv_list[0] = N * (N - 1) //2
for _ in range(M):
  a, b = list(map(int, input().split()))
  bridge_list.append((a-1, b-1))
bridge_list.reverse()
for i in range(M):
  x, y = bridge_list[i]
  if uf.same(x, y):
    inconv_list[i+1] = inconv_list[i]
  else:
    Nx = uf.count_size(x)
    Ny = uf.count_size(y)
    inconv_list[i+1] = inconv_list[i] - Nx * Ny
    uf.unite(x, y)
 
inconv_list.sort()  
 
for i in range(1, M+1):
  print(inconv_list[i])

Fixed submission:
class Union_Find():
  def __init__(self, n):
    self.par = list(range(n))
    self.size = [-1] * n
    self.rank = [0] * n
  def root(self, x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] = self.root(self.par[x])
      return self.par[x]
  def unite(self, x, y):
    root_x = self.root(x)
    root_y = self.root(y)
    if root_x == root_y:
      pass
    else:
      if self.rank[root_x] > self.rank[root_y]:
        self.par[root_y] = root_x
        self.rank[root_x] += 1
        self.size[root_x] += self.size[root_y]
      else:
        self.par[root_x] = root_y
        self.rank[root_y] += 1
        self.size[root_y] += self.size[root_x]
        
        
  def same(self, x, y):
    root_x = self.root(x)
    root_y = self.root(y)
    return root_x == root_y
  def count_size(self, x):
    # 根を共有している要素の数を数える。
    return self.size[self.root(x)]
 
N, M = list(map(int, input().split()))
uf = Union_Find(N)
bridge_list = []
inconv_list = [0] * (M + 1)
inconv_list[0] = N * (N - 1) //2
for _ in range(M):
  a, b = list(map(int, input().split()))
  bridge_list.append((a-1, b-1))
bridge_list.reverse()
for i in range(M):
  x, y = bridge_list[i]
  if uf.same(x, y):
    inconv_list[i+1] = inconv_list[i]
  else:
    Nx = uf.count_size(x)
    Ny = uf.count_size(y)
    inconv_list[i+1] = inconv_list[i] - Nx * Ny
    uf.unite(x, y)
 
inconv_list.sort()  
 
for i in range(1, M+1):
  print(inconv_list[i])
Buggy python submission (verdict: Runtime Error):
N, A, B, C = [int(x) for x in input().split()]
l = []
for i in range(N):
  l.append(int(input()))
 
def dfs(cur, a, b, c):
  if cur == N:
    return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else 1000000
  ret0 = dfs(cur + 1, a, b, c)
  ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
  ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
  ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
  return min(ret0, ret1, ret2, ret3)
 
print(dfs(0, 0, 0, 0))

Fixed submission:
y, m, d = list(input().split('/'))

#y = y.zfill(4)
n = int(y + m + d)

if n <= 20190430:
  print("Heisei")
else:
  print("TBD")
Buggy python submission (verdict: Runtime Error):
D = int(input())

if D == 25:
  print('Christmas')
elif D == 24:
  print('Christmas Eve')
elif D == 23:
  print('Christmas Eve Eve')
elif = D == 22:
  print('Christmas Eve Eve Eve')
  

Fixed submission:
D = int(input())
 
if D == 25:
  print('Christmas')
elif D == 24:
  print('Christmas Eve')
elif D == 23:
  print('Christmas Eve Eve')
elif D == 22:
  print('Christmas Eve Eve Eve')
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, K = list(map(int, input().split()))

for i in range(K):
  if A == B and B == C:
    break
  next_A = B + C
  next_B = A + C
  next_C = A + B
  A = next_A
  B = next_B
  C = next_C
if abs(A - B) > 10**18:
  print('Unfair')
else:
  print(A - B)

Fixed submission:
A, B, C, K = list(map(int, input().split()))

if abs(A - B) > 10**18:
  print('Unfair')
else:
  print((A -B)*(-1)**K)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))

ld={}
for i in range(n):
    ld.setdefault(i,l[i])

ans=0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if ld[i]+ld[j]>ld[k] and ld[j]+ld[k]>ld[i] and ld[k]+ld[i]>ld[j]:
                ans+=1
            #print(l[i],l[j],l[k])

print(ans)

Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))
ls = sorted(l)

ld={}
for i in range(n):
    ld.setdefault(i,ls[i])
#print(ld)

ans=0
for i in range(n-2):
    for j in range(i+1, n-1):
        k = bisect.bisect_left(ls, ld[i]+ld[j])
        #print(k)
        ans += k-j-1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

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

ld={}
for i in range(n):
    ld.setdefault(i,l[i])

ans=0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if ld[i]+ld[j]>ld[k] and ld[j]+ld[k]>ld[i] and ld[k]+ld[i]>ld[j]:
                ans+=1
            #print(l[i],l[j],l[k])

print(ans)


Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))
ls = sorted(l)

ld={}
for i in range(n):
    ld.setdefault(i,ls[i])
#print(ld)

ans=0
for i in range(n-2):
    for j in range(i+1, n-1):
        k = bisect.bisect_left(ls, ld[i]+ld[j])
        #print(k)
        ans += k-j-1

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

def gcd(a, b):
  while b:
    a, b = b, a%b
  return a

a, b = map(int, input().split())
max = gcd(a, b)
pf=[]

#print(max)
tmp=max
i=2

while tmp != 1:
    if tmp%i == 0:
        pf.append(i)
        tmp=tmp/i
    else:
        i+=1

#print(pf)
spf = set(pf)
#print(spf)
print(len(spf)+1)


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

a, b = map(int, input().split())
max = gcd(a, b)
pf=[]

#print(max)
tmp=max
i=2
while tmp % 2 == 0:
    pf.append(2)
    tmp //= 2
f = 3
while f * f <= tmp:
    if tmp % f == 0:
        pf.append(f)
        tmp //= f
    else:
        f += 2
if tmp != 1:
    pf.append(tmp)


#print(pf)
spf = set(pf)
#print(spf)
print(len(spf)+1)
Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())

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

print(ans)

Fixed submission:
from decimal import Decimal

n = int(input())
print(int(Decimal((n-1)/2)*Decimal(n)))

Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())

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

print(ans)

Fixed submission:
from decimal import Decimal

n = int(input())
print(int(Decimal((n-1)/2)*Decimal(n)))
Buggy python submission (verdict: Runtime Error):
ans = 0
for i in ai:
    ans=ans+1/i

print(1/ans)


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

#print(ai)

ans = 0
for i in ai:
    ans=ans+1/i

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

N = int(input())
pi = list(map(int, input().split()))
#print(pi)

pis = sorted(pi)
#print(pis)

count = 0

for i in range(5):
    if pi[i] != pis [i]:
        count += 1

if count <= 2:
    print("YES")
else:
    print("NO")


Fixed submission:
N = int(input())
pi = list(map(int, input().split()))
#print(pi)

pis = sorted(pi)
#print(pis)

count = 0
for i in range(N):
    if pi[i] != pis[i]:
        count += 1

if count <= 2:
    print("YES")
else:
    print("NO")