Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left, bisect_right

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

an.sort()
bn.sort()
cn.sort()

cnt = 0

for b in bn:
    a = bisect_left(an,b)
    c = bisect_right(cn,b)
    cnt += a * (n-c)
print(cnt)

Fixed submission:
from bisect import bisect_left, bisect_right

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

a.sort()
b.sort()
c.sort()

cnt = 0

for b_e in b:
    a_cases = bisect_left(a, b_e)
    c_cases = bisect_right(c, b_e)
    cnt += a_cases * (n - c_cases)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
b = [int(x) for x in input().split()]
b.sort()
c = [int(x) for x in input().split()]
c.sort()
l = [[a[i], b[i], c[i]] for i in range(n)]

def solve(value: int, key: int) -> bool:
    return value >= key

def binary_search(l, key: int) -> int:
    ng = -1
    ok = len(l)

    while abs(ok - ng) > 1:
        mid = int((ok + ng) / 2)
        if solve(l[mid], key):
            ok = mid
        else:
            ng = mid
    return ok

result = 0

for c_elem in c:
    cases = binary_search(b, c_elem)
    for b_elem in b[:cases]:
        tmp = binary_search(a, b_elem)
        result += tmp

print(result)
    
    

Fixed submission:
from bisect import bisect_left, bisect_right

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

a.sort()
b.sort()
c.sort()

cnt = 0

for b_e in b:
    a_cases = bisect_left(a, b_e)
    c_cases = bisect_right(c, b_e)
    cnt += a_cases * (n - c_cases)
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

edges = {i : [] for i in range(1, N+1)}
for _ in range(M):
  a, b = map(int, input().split())
  edges[a].append(b)
  edges[b].append(a)

def dfs(n, count):
  # 定期便2つでは行けない
  if count == 3:
    return False
  if n == N:
    return True
  
  for edge in edges[n]:
    if dfs(edge, count + 1):
      return True
  
  return False

print("POSSIBLE" if dfs(1, 0) else "IMPOSSIBLE")

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

edges = {i : [] for i in range(1, N+1)}
visited = [False for _ in range(N+1)]

for _ in range(M):
  a, b = map(int, input().split())
  edges[a].append(b)
  edges[b].append(a)

def dfs(n, count):
  # 定期便2つでは行けない
  if count == 3:
    return False
  if n == N:
    return True
  visited[n] = True
  
  for edge in edges[n]:
    if visited[edge]:
      continue
    if dfs(edge, count + 1):
      return True
  
  return False

print("POSSIBLE" if dfs(1, 0) else "IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]

b = []
ap = b.append

for i in range(n):
  ap(a[i])
  b.reverse()

print(' '.join(map(str, b)))

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

if n & 1:
  print(' '.join(a[::-2]+a[1::2]))
else:
  print(' '.join(a[-1:0:-2]+a[::2]))
Buggy python submission (verdict: Runtime Error):
input()
a = list(map(int, input().split()))
l = len(filter(lambda x : x & 1, a))
if l & 1:
  print("NO")
else:
  print("YES")

Fixed submission:
input()
a = list(map(int, input().split()))
l = len(list(filter(lambda x : x & 1, a)))
if l & 1:
  print("NO")
else:
  print("YES")
Buggy python submission (verdict: Runtime Error):
5
100 1 2 3 14 15 58 58 58 29


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort()
res = 0
for i in range(0, 2*n, 2):
  res += min(a[i], a[i+1])

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

ans = 0
s = 0

def mod(x):
    return int(x % (1e+9 + 7))
 
for i in range(N):
    for j in range(N):
        if i<j:
            ans += A[i] * A[j]
print(mod(ans))
  

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

ans = 0
s = 0

def mod(x):
    return int(x % int(1e+9 + 7))

for i in reversed(range(N-1)):
    s += A[i+1]
    s = mod(s)
    ans += A[i] * s

    ans = mod(ans) 

print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N = int(input())

A = np.zeros(N)



for i in range(N):
   for j in range(N):
       for k in range(N):
           x = i + 1
           y = j + 1
           z = k + 1
           n = x**2 + y**2 + z**2 + x*y + y*z + z*x
           if N < n :
               continue
           else:
               A[n-1] += 1



for a in A:
    print(int(a))

Fixed submission:
import numpy as np

N = int(input())
rN = int(np.sqrt(N))

A = np.zeros(N)



for i in range(rN):
   for j in range(rN):
       for k in range(rN):
           x = i + 1
           y = j + 1
           z = k + 1
           n = x**2 + y**2 + z**2 + x*y + y*z + z*x
           if N < n :
               break
           else:
               A[n-1] += 1



for a in A:
    print(int(a))
Buggy python submission (verdict: Runtime Error):
T = int(input())

print(T.replace('?', 'D'))

Fixed submission:
T = input()

print(T.replace('?', 'D'))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

ans = 0
for i in range(n-1):
  ans += a[i]*sum(a[i+1:])
  ans = ans%(10**9+7)
print(ans)

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

sum_a = sum(a)
ans = 0
for i in range(n-1):
  sum_a-=a[i]
  ans += a[i]*sum_a
  ans = ans%(10**9+7)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
x = 7%k

flg = True
for i in range(1,10**12):
  x = x%k
  if x ==0:
    break
  else:
    x = x*10+7
    
if k%2==0:
  flg = False
    
print(i if flg else '-1')


Fixed submission:
k = int(input())
x = 7%k

flg = False
for i in range(1,k+1):
  x = x%k
  if x ==0:
    flg = True
    break
  else:
    x = x*10+7
  
print(i if flg else '-1')

Buggy python submission (verdict: Runtime Error):
k = int(input())
x = 7%k

flg = True
for i in range(1,k):
  x = x%k
  if x ==0:
    break
  else:
    x = x*10+7
    
if k%2==0:
  flg = False
    
print(i if flg else '-1')



Fixed submission:
k = int(input())
x = 7%k

flg = False
for i in range(1,k+1):
  x = x%k
  if x ==0:
    flg = True
    break
  else:
    x = x*10+7
  
print(i if flg else '-1')

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

if k%2==0:#偶数時の処理
  print(-1)
  exit()

flg = False
for i in range(1,10**6):
  s = '7'*i
  s = int(s)
  if s%k==0:
    flg = True
    break
    
print(i if flg else '-1')

Fixed submission:
k = int(input())
x = 7%k

flg = False
for i in range(1,k+1):
  x = x%k
  if x ==0:
    flg = True
    break
  else:
    x = x*10+7
  
print(i if flg else '-1')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

from collections import defaultdict
d = defaultdict(int)

for i in range(1,n+1):
  for j in range(1,n+1):
    for k in range(1,n+1):
      d[i**2+j**2+k**2+i*j+j*k+k*i]+=1

for j in range(1,n+1):
  if d[j]:
    print(d[j])
  else:
    print(0)
    

Fixed submission:
n = int(input())

from collections import defaultdict
d = defaultdict(int)

ul=int(n**0.5)

for i in range(1,ul):
  for j in range(1,ul):
    for k in range(1,ul):
      d[i**2+j**2+k**2+i*j+j*k+k*i]+=1
for j in range(1,n+1):
  print(d.get(j,0))
#  print(d[j] if d[j] else 0)

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

for nn in range(1,n+1):
  ul = int(nn**0.5)+1
  cnt=0
  for i in range(1,ul):
    for j in range(1,ul):
      for k in range(1,ul):
        if i**2+j**2+k**2+i*j+j*k+k*i==nn:
          cnt+=1
  print(cnt)

Fixed submission:
n = int(input())

from collections import defaultdict
d = defaultdict(int)

ul=int(n**0.5)

for i in range(1,ul):
  for j in range(1,ul):
    for k in range(1,ul):
      d[i**2+j**2+k**2+i*j+j*k+k*i]+=1
for j in range(1,n+1):
  print(d.get(j,0))
#  print(d[j] if d[j] else 0)

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

for nn in range(1,n+1):
  ul = int(nn**0.5)+1
  cnt=0
  for i in range(1,ul):
    for j in range(1,ul):
      for k in range(1,ul):
        if i**2+j**2+k**2+i*j+j*k+k*i==nn:
          cnt+=1
  print(cnt)

Fixed submission:
n = int(input())

from collections import defaultdict
d = defaultdict(int)

ul=int(n**0.5)

for i in range(1,ul):
  for j in range(1,ul):
    for k in range(1,ul):
      d[i**2+j**2+k**2+i*j+j*k+k*i]+=1
for j in range(1,n+1):
  print(d.get(j,0))
#  print(d[j] if d[j] else 0)
Buggy python submission (verdict: Runtime Error):
n,m,k = list(map(int,input().split()))
a = list(map(int,input().split()))[::-1]
b = list(map(int,input().split()))[::-1]
cnt_book=0
cnt_time=0

while cnt_time<k:
  if not a or a[-1]>=b[-1]:
    cnt_time+=b.pop()
  else:
    cnt_time+=a.pop()
  if cnt_time>k:
    break    
  cnt_book+=1

print(cnt_book)


Fixed submission:
import bisect

n,m,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
b = [0]+list(map(int,input().split()))

for i in range(1,n+1):
  a[i] = a[i]+a[i-1]
for j in range(1,m+1):
  b[j] = b[j]+b[j-1]

book_cnt=0
for a_cnt in range(n+1):
  if a[a_cnt]>k:
    continue
  rest=k-a[a_cnt]
  b_cnt=bisect.bisect(b,rest)-1
  book_cnt=max(book_cnt,a_cnt+b_cnt)

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

n = int(input())
a = list(map(int,input().split()))
b = [0]*n

for i in range(n):
  b[i] = reduce(lambda x,y : x^y,a[0:i+1]+a[i:])

print(" ".join(list(map(str,b))))

Fixed submission:
from functools import reduce

n = int(input())
a = list(map(int,input().split()))
b = [0]*n
a_xor=reduce(lambda x,y : x^y,a)
for i in range(n):
  b[i]=a[i]^a_xor  
##  b[i] = reduce(lambda x,y : x^y,a[0:i+1]+a[i:])

print(" ".join(list(map(str,b))))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))
s=1
for a in A:
  s*=a
print(-1 if s>10**18 else s)

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

if 0 in A:
  s=0
else:
  for a in A:
    s*=a
    if s>10**18:
      s=-1
      break
print(s)
Buggy python submission (verdict: Runtime Error):
import math
def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True        

n=int(input())
cnt=0
e=[]# used_list
f=0
pn=[2,3,5,7,11,13,17,19,23,29,31,37,41]
z=[2,3,4,5,7,8,9,16,25,27,32]
if n==1:
  cnt=0

else:
  while not is_prime(n):
    if n%z[f]==0:
      n=n//z[f]
      cnt+=1
      if n==1:break
    f+=1

print(cnt)

Fixed submission:
n=int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

if n==1:
  print(0)
  exit()  
  
f=factorization(n)
cnt=0
for i in range(len(f)):
  m=2 # 強引
  while f[i][1]>0:
    f[i][1]-=m
    m+=1
    cnt+=1
#    print(f)
print(cnt)
Buggy python submission (verdict: Runtime Error):
n,k=list(map(int,input().split()))
a=[0]+ list(map(int,input().split()))

visited=[1]

for i in range(n):
  next=a[visited[-1]]
  visited.append(next)
  
loop_end=n
loop_start=n-1
while visited[loop_start]!=visited[loop_end]:
  loop_start-=1
period=loop_end-loop_start
#print(visited) 
#print("p:",period)
#print("k%period:",k%period)

if k<n+1:
  print(visited[k])
  exit()
else:
  print(visited[n-(k-n)%period+1])

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

visited=[1]

for i in range(n):
  next=a[visited[-1]]
  visited.append(next)
  
loop_end=n
loop_start=n-1
while visited[loop_start]!=visited[loop_end]:
  loop_start-=1
period=loop_end-loop_start
#print(visited) 
#print("p:",period)
#print("(k-n)%period:",(k-n)%period)

if k<n+1:
  print(visited[k])
  exit()
else:
  print(visited[n-period+(k-n)%period])

Buggy python submission (verdict: Runtime Error):
n,k=list(map(int,input().split()))
a=[0]+ list(map(int,input().split()))

visited=[1]

for i in range(n):
  next=a[visited[-1]]
  if next in visited:
    loop_end=n+1
    loop_start=visited.index(n)
    period=loop_end-loop_start
  visited.append(next)
#print(visited) 
#print(period)
if k<n+1:
  print(visited[k])
  exit()
else:
  print(visited[k%period])

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

visited=[1]

for i in range(n):
  next=a[visited[-1]]
  visited.append(next)
  
loop_end=n
loop_start=n-1
while visited[loop_start]!=visited[loop_end]:
  loop_start-=1
period=loop_end-loop_start
#print(visited) 
#print("p:",period)
#print("(k-n)%period:",(k-n)%period)

if k<n+1:
  print(visited[k])
  exit()
else:
  print(visited[n-period+(k-n)%period])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=list(input())
ans=0
for i in range(n-2):
  for j in range(i,n-1):
    if S[i]==S[j]:
      continue
    for k in range(j,n):
      if S[j]==S[k] or S[i]==S[k]:
        continue
      if j-i != k-j:
        ans+=1
    continue
print(ans)

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

nr=s.count('R')
ng=s.count('G')
nb=s.count('B')
ans=nr*ng*nb
cnt=0

for i in range(n-1):
  for j in range(i+1,n):
    k=2*j-i
    if k>=n or k<=j:
      continue
    if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
      cnt+=1
print(ans-cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=list(input())
ans=0
for i in range(n-2):
  for j in range(i,n-1):
    if S[i]==S[j]:
      continue
    for k in range(j,n):
      if S[j]==S[k] or S[i]==S[k]:
        continue
      if j-i != k-j:
        ans+=1
print(ans)

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

nr=s.count('R')
ng=s.count('G')
nb=s.count('B')
ans=nr*ng*nb
cnt=0

for i in range(n-1):
  for j in range(i+1,n):
    k=2*j-i
    if k>=n or k<=j:
      continue
    if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
      cnt+=1
print(ans-cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=list(input())
ans=0
for i in range(n-2):
  for j in range(i,n-1):
    for k in range(j,n):
      if S[i]!=S[j] and S[j]!=S[k] and S[i]!=S[k] and (j-i != k-j):
        ans+=1
print(ans)

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

nr=s.count('R')
ng=s.count('G')
nb=s.count('B')
ans=nr*ng*nb
cnt=0

for i in range(n-1):
  for j in range(i+1,n):
    k=2*j-i
    if k>=n or k<=j:
      continue
    if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
      cnt+=1
print(ans-cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
a = list(map(int,input().split()))
tmp = list(map(lambda x:x+n,a))
a = a + tmp
l = len(a)

b=[0]*(l-1)
for i in range(l-1):
  b[i] = a[i+1]-a[i]

ans = 10**9
for j in range(l-k+1):
  ans = min(ans,sum(b[j:j+k-1]))
print(ans)


Fixed submission:
k,n=list(map(int,input().split()))
A=list(map(int,input().split()))
l=[]
for i in range(n-1):
  l.append(A[i+1]-A[i])
l.append(k-A[-1]+A[0])
print(sum(l)-max(l))
Buggy python submission (verdict: Runtime Error):
range(math.floor(a*100/8),math.floor((a+1)*100/8)+1):

Fixed submission:
import math
a,b=list(map(int,input().split()))
ans=-1
for i in range(1,1100):
  if math.floor(i*0.08)==a and math.floor(i*0.1)==b:
    ans=i
    break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=list(input())
q=int(input())

d = deque(s)
for i in range(q):
  qs=list(input().split())
  
  if qs[0]=='1':
    d.reverse()
  else:
    if qs[1]=='1':
      d.appendleft(qs[2])
    else:
      d.append(qs[2])

print("".join(d))


Fixed submission:
from collections import deque

s=list(input())
q=int(input())
d = deque(s)
reverse=False

for i in range(q):
  qs=list(input().split())
  if qs[0]=='1':
    reverse=not reverse
  else:
    if qs[1]=='1':
      d.appendleft(qs[2]) if not reverse else d.append(qs[2])
    else:
      d.append(qs[2]) if not reverse else d.appendleft(qs[2])
#  print(d)
if reverse:
  d.reverse()
print("".join(d))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
dic={}
for i in range(n):
  a=input()
  if a not in dic.keys():dic[a]=1
  else:dic[a]+=1
dic_max=[k for k, v in dic.items() if v==max(dic.values())]
dic_s=sorted(dic_max)
[print(i) for i in dic_s]

Fixed submission:
n=int(input())
dic={}
for i in range(n):
  a=input()
  if a not in dic.keys():dic[a]=1
  else:dic[a]+=1
max_value=max(dic.values())
dic_max=[k for k, v in dic.items() if v==max_value]
dic_s=sorted(dic_max)
[print(i) for i in dic_s]
Buggy python submission (verdict: Time Limit Exceeded):
n,k=list(map(int,input().split()))
p=list(map(int,input().split()))
ans=0

for l in range(n-k+1):
  ans=max(ans,(k+sum(p[l:l+k]))/2)

print(ans)

Fixed submission:
n,k=list(map(int,input().split()))
p=list(map(int,input().split()))
s=sum(p[0:k])
ans=(k+s)/2

for l in range(n-k):
  s-=p[l]
  s+=p[l+k]
  ans=max(ans,(k+s)/2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=list(map(int,input().split()))
p=list(map(int,input().split()))
ans=0
for i in range(n-k+1):
  ans=max(ans,sum(p[i:k+i]))
print((ans+k)/2)

Fixed submission:
n,k=list(map(int,input().split()))
p=list(map(int,input().split()))
s=sum(p[0:k])
ans=(k+s)/2

for l in range(n-k):
  s-=p[l]
  s+=p[l+k]
  ans=max(ans,(k+s)/2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
P=list(map(int,input().split()))
cnt=0

for i in range(N):
  if P[i]<=min(P[:i+1]):
    cnt+=1

print(cnt)


Fixed submission:
N=int(input())
P=list(map(int,input().split()))
cnt=0
bar=P[0]
for i in range(N):
  if P[i]<=bar:
    bar=P[i]
    cnt+=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
P=list(map(int,input().split()))
R=[[True for i in range(N)] for j in range(N)]
R1=[False for i in range(N)]

for i in range(N):
  if P[i]<=min(P[:i+1]):
    R[i]=True
  else:
    R[i]=False

print(R.count(True))

Fixed submission:
N=int(input())
P=list(map(int,input().split()))
cnt=0
bar=P[0]
for i in range(N):
  if P[i]<=bar:
    bar=P[i]
    cnt+=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
P=list(map(int,input().split()))
R=[[True for i in range(N)] for j in range(N)]
R1=['' for i in range(N)]

for j in range(N):
  for i in range(j,N):
    if P[i]<=P[j]:
      R[i][j]=True
    else:
      R[i][j]=False

for i in range(N):
  if all(R[i]):
    R1[i]=True
print(R1.count(True))

Fixed submission:
N=int(input())
P=list(map(int,input().split()))
cnt=0
bar=P[0]
for i in range(N):
  if P[i]<=bar:
    bar=P[i]
    cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=list(input())
x=count=0
search_word=["A","B","C"]
 
for x in range(N):
  if S[x]==search_word[0] and S[x+1]==search_word[1] and S[x+2]==search_word[2]:
    count+=1
  x+=1
 
print(count)

Fixed submission:
N=int(input())
S=list(input())
x=count=0
search_word=["A","B","C"]
 
for x in range(N-2):
  if S[x]==search_word[0] and S[x+1]==search_word[1] and S[x+2]==search_word[2]:
    count+=1
  x+=1
 
print(count)

Buggy python submission (verdict: Runtime Error):
N=input()
S=list(input())
x=count=0
search_word=["A","B","C"]

for i in S:
  if S[x]==search_word[0] and S[x+1]==search_word[1] and S[x+2]==search_word[2]:
    count+=1
  x+=1

print(count)


Fixed submission:
N=int(input())
S=list(input())
x=count=0
search_word=["A","B","C"]
 
for x in range(N-2):
  if S[x]==search_word[0] and S[x+1]==search_word[1] and S[x+2]==search_word[2]:
    count+=1
  x+=1
 
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
A,B,K=map(int,input().split())
i=0
for i in range(K):
  if A>0:
    A-=1
  else:
    B-=1

print('{} {}'.format(A,B))

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

if A>=K:
  A=A-K
elif A+B<=K:
  A=B=0
else:
  B=A+B-K
  A=0

print('{} {}'.format(A,B))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
bar=10**12

def f(x):
  d=[]
  for i in range(1,int(x**0.5)+1):
    if x%i==0:
      d.append(i)
      if i!=x//i:
        d.append(x//i)
  d.sort()
  return d

for i in f(N):
  for j in f(N):
    if i*j==N and i+j<bar:
      bar=i+j
      x=i
      y=j

print(x-1+y-1)
 

Fixed submission:
N=int(input())
bar=10**12
d=[]
for i in range(1,int(N**0.5)+1):
  if N%i==0 and i+N//i<bar:
    d.append(i+N//i)
    bar=i+N//i
#print(d)
print(min(d)-2)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=sorted(list(map(int,input().split())))
cnt=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[i]<l[j]+l[k] and l[j]<l[k]+l[i] and l[k]<l[i]+l[j]:
        cnt+=1
#        print(l[i],l[j],l[k])
print(cnt)
    

Fixed submission:
import bisect
N=int(input())
d=sorted(list(map(int,input().split())))
cnt=0
for i in range(N-1,1,-1):
  for j in range(i-1,0,-1):
    k=bisect.bisect_right(d,d[i]-d[j])
    if j-k>0:
      cnt+=j-k
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N=int(input())
d=list(map(int,input().split()))
cnt=0
for i in itertools.combinations(d,3):
  if i[0]<i[1]+i[2] and i[1]<i[0]+i[2] and i[2]<i[0]+i[1]:
    cnt+=1
print(cnt)

Fixed submission:
import bisect
N=int(input())
d=sorted(list(map(int,input().split())))
cnt=0
for i in range(N-1,1,-1):
  for j in range(i-1,0,-1):
    k=bisect.bisect_right(d,d[i]-d[j])
    if j-k>0:
      cnt+=j-k
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q=list(map(int,input().split()))
s=[k]*n
for i in range(q):
  a=int(input())
  s=list(map(lambda x:x-1,s))
  s[a-1]+=1
t=list(map(lambda x:'Yes' if x>0 else 'No',s))
[print(i) for i in t]

Fixed submission:
n,k,q=list(map(int,input().split()))
s=[k]*n
for i in range(q):
  a=int(input())
  s[a-1]+=1
s=list(map(lambda x:x-q,s))
t=list(map(lambda x:print('Yes') if x>0 else print('No'),s))

Buggy python submission (verdict: Time Limit Exceeded):
n,k,q=list(map(int,input().split()))
s=[k]*n
for i in range(q):
  a=int(input())
  s=list(map(lambda x:x-1,s))
  s[a-1]+=1
for j in range(n):
  if s[j]>0:print('Yes')
  else:print('No')

Fixed submission:
n,k,q=list(map(int,input().split()))
s=[k]*n
for i in range(q):
  a=int(input())
  s[a-1]+=1
s=list(map(lambda x:x-q,s))
t=list(map(lambda x:print('Yes') if x>0 else print('No'),s))

Buggy python submission (verdict: Time Limit Exceeded):
n,k,q=list(map(int,input().split()))
a=[int(input()) for i in range(q)]
s=[k]*n
for i in a:
  s=list(map(lambda x:x-1,s))
  s[i-1]+=1
for j in range(n):
  if s[j]>0:print('Yes')
  else:print('No')

Fixed submission:
n,k,q=list(map(int,input().split()))
s=[k]*n
for i in range(q):
  a=int(input())
  s[a-1]+=1
s=list(map(lambda x:x-q,s))
t=list(map(lambda x:print('Yes') if x>0 else print('No'),s))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,m=list(map(int,input().split()))
a=sorted(list(map(int,input().split())))

for i in range(m):
  a[-1]//=2
  bisect.insort_left(a,a[-1])
  a.pop()
  if a[-1]<1:break
print(sum(a))

Fixed submission:
import heapq
n,m=list(map(int,input().split()))
a=list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(a)
for i in range(m):
  m=heapq.heappop(a)
  heapq.heappush(a, (-m//2)*(-1))
print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))

for i in range(m):
  a[a.index(max(a))]//=2
  if a[a.index(max(a))]<1:break
print(sum(a))

Fixed submission:
import heapq
n,m=list(map(int,input().split()))
a=list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(a)
for i in range(m):
  m=heapq.heappop(a)
  heapq.heappush(a, (-m//2)*(-1))
print(-sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
print(sum(range(n)))

Fixed submission:
n=int(input())
print(n*(n-1)//2)