Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from math import factorial
# alpha = 'abcdefghijklmnopqrstuvwxyz'

def com(n,r):
    return factorial(n) // (factorial(n-r)*factorial(r))

N = int(input())
anss = []
ans = 0
dic = defaultdict(int)
for i in range(N):
    t = input()
    t = sorted(t)
    if t in anss:
        dic[anss.index(t)] += 1
    else: anss.append(t)
# print(dic)
for k in dic.keys():
    if dic[k] > 1:
        ans += com(dic[k]+1,2)
    else: ans += dic[k]
print(ans)

Fixed submission:
from collections import defaultdict
from math import factorial
# alpha = 'abcdefghijklmnopqrstuvwxyz'

def com(n,r):
    return factorial(n) // (factorial(n-r)*factorial(r))

N = int(input())
ans = 0
anss = defaultdict(int)
for i in range(N):
    t = input()
    ts = ''.join(c for c in sorted(t))
    anss[ts] += 1
# print(anss)
for k in anss.keys():
    if anss[k] > 1:
        ans += com(anss[k],2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque
N,M = map(int,input().split())
abc = []
for i in range(N):
    a,b = map(int,input().split())
    c = b/a
    abc.append((a,b,c))

abc.sort(key=lambda x:x[2],reverse=True)

d = defaultdict(deque)
for a,b,c in abc:
    d[a].append(b)
# print(abc)
# print(d)
ans = 0
for i in range(M-1,-1,-1):
    if not d: break
    tmpk = -1
    tmpv = -1
    dif = M - i
    for k in sorted(d.keys()):
        if k > dif: break
        if d[k][0] > tmpv:
            tmpv = d[k][0]
            tmpk = k
    if tmpk != -1:
        ans += tmpv
        d[tmpk].popleft()
        if not d[tmpk]:
            d.pop(tmpk)
print(ans)

Fixed submission:
from heapq import heappop, heappush
from collections import defaultdict
N,M = map(int,input().split())
jobs = defaultdict(list)
for i in range(N):
    a,b = map(int,input().split())
    if a <= M: jobs[a-1].append(b)
h = []
ans = 0
for i in range(M):
    if jobs[i]:
        for j in jobs[i]:
            heappush(h, -j)
    if len(h) > 0:
        ans += -heappop(h)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque
N,M = map(int,input().split())
abc = []
for i in range(N):
    a,b = map(int,input().split())
    c = b/a
    abc.append((a,b,c))

abc.sort(key=lambda x:x[2],reverse=True)

d = defaultdict(deque)
for a,b,c in abc:
    d[a].append(b)
# print(abc)
# print(d)
now = 1
ans = 0
days = [True] * M
for i in range(M-1,-1,-1):
    tmpk = -1
    tmpv = -1
    dif = M - i
    for k in sorted(d.keys()):
        if k > dif: break
        if d[k][0] > tmpv:
            tmpv = d[k][0]
            tmpk = k
    if tmpk != -1:
        ans += tmpv
        d[tmpk].popleft()
        if not d[tmpk]:
            d.pop(tmpk)
print(ans)

Fixed submission:
from heapq import heappop, heappush
from collections import defaultdict
N,M = map(int,input().split())
jobs = defaultdict(list)
for i in range(N):
    a,b = map(int,input().split())
    if a <= M: jobs[a-1].append(b)
h = []
ans = 0
for i in range(M):
    if jobs[i]:
        for j in jobs[i]:
            heappush(h, -j)
    if len(h) > 0:
        ans += -heappop(h)
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import factorial
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

def combinations_with_replacement_count(n, r):
    return combinations_count(n + r - 1, r)

div = 10**9+7

N,K = map(int,input().split())

for i in range(1,K+1):
    ans = combinations_count(N-K+1,i) % div
    ans = ans * combinations_count(K-1,i-1) % div
    print(ans)


Fixed submission:
from math import factorial
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

div = 10**9+7

N,K = map(int,input().split())

for i in range(1,K+1):
    if N-K+1 < i:
        print(0)
        continue
    ans = combinations_count(N-K+1,i) % div
    ans = ans * combinations_count(K-1,i-1) % div
    print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = []
for i in range(M):
    b,c = map(int,input().split())
    BC.append([b,c])
BC.sort(key=lambda x:x[1], reverse=True)
# print(BC)

A.sort()

i = 0
j = 0
while BC[j][1] > A[i] and i < N and j < M:
    if BC[j][0] < 1:
        j += 1
        continue
    A[i] = BC[j][1]
    BC[j][0] -= 1
    i += 1

print(sum(A))

Fixed submission:
N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = []
for i in range(M):
    b,c = map(int,input().split())
    BC.append([b,c])
BC.sort(key=lambda x:x[1], reverse=True)
# print(BC)

A.sort()

i = 0
j = 0
while i < N and j < M and BC[j][1] > A[i]:
    if BC[j][0] < 1:
        j += 1
        continue
    A[i] = BC[j][1]
    BC[j][0] -= 1
    i += 1

print(sum(A))

Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = []
for i in range(M):
    b,c = map(int,input().split())
    BC.append([b,c])
BC.sort(key=lambda x:x[1], reverse=True)

A.sort()

i = 0
j = 0
while i < N and j < M:
    while BC[j][1] > A[i]:
        if BC[j][0] < 1:
            j += 1
            continue
        A[i] = BC[j][1]
        BC[j][0] -= 1
        i += 1
    break

print(sum(A))

Fixed submission:
N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = []
for i in range(M):
    b,c = map(int,input().split())
    BC.append([b,c])
BC.sort(key=lambda x:x[1], reverse=True)
# print(BC)

A.sort()

i = 0
j = 0
while i < N and j < M and BC[j][1] > A[i]:
    if BC[j][0] < 1:
        j += 1
        continue
    A[i] = BC[j][1]
    BC[j][0] -= 1
    i += 1

print(sum(A))
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = 0

from math import sqrt
ans = 0
for k in range(1,int(sqrt(N)+1)):
    if N%k == 0:
        m = N//k-1
        if k == N%m: ans += m

print(ans)

Fixed submission:
N = int(input())

from math import sqrt
ans = 0
if N != 1:
    for k in range(1,int(sqrt(N)+1)):
        if N%k == 0:
            m = N//k-1
            if k == N%m: ans += m

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

li.sort()
while len(li) > 1:
    a = li.pop()
    b = li.pop()
    if a % b == 1:
        li[0] = 1
        break
    if a % b != 0:
        li.append(a % b)
    li.append(b)
    li.sort()
print(li[0])

Fixed submission:
from fractions import gcd
N = int(input())
li = set(map(int,input().split()))
li = list(li)

ans = li[0]
for i in range(1,len(li)):
    ans = gcd(ans,li[i])
    if ans == 1: break

print(ans)

Buggy python submission (verdict: Runtime Error):
from heapq import heappush
N = int(input())
li = list(map(int,input().split()))

li.sort()
while len(li) > 1:
    a = li.pop()
    b = li.pop()
    if a % b != 0: heappush(li,a % b)
print(li[0])

Fixed submission:
from fractions import gcd
N = int(input())
li = set(map(int,input().split()))
li = list(li)

ans = li[0]
for i in range(1,len(li)):
    ans = gcd(ans,li[i])
    if ans == 1: break

print(ans)
Buggy python submission (verdict: Runtime Error):
l = sorted(map(int,input().split()),reversed=True)
print(eval(''.join(l[:2])+'+'+str(l[2])))

Fixed submission:
l = sorted(map(int,input().split()),reverse=True)
print(eval(''.join(map(str,l[:2]))+'+'+str(l[2])))
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))

def lcm(a,b): return a*b//gcd(a,b)

l = A[0]
for i in range(1,N):
    l = lcm(l,A[i])
l -= 1

ans = 0
for a in A: ans += l % a
print(ans)

Fixed submission:
A = sorted(map(int,input().split()))
ans = 0
for i in range(2): ans += A[i+1] - A[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import gcd
N = int(input())
A = list(map(int,input().split()))

def lcm(a,b): return a*b//gcd(a,b)

l = A[0]
for i in range(1,N):
    l = lcm(l,A[i])
l -= 1

ans = 0
for a in A: ans += l % a
print(ans)

Fixed submission:
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))

def lcm(a,b): return a*b//gcd(a,b)

l = A[0]
for i in range(1,N):
    l = lcm(l,A[i])
l -= 1

ans = 0
for a in A: ans += l % a
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

ans = []
for i in range(N):
    ans.append(S[:i].count('W') + S[i+1:].count('E'))

print(min(ans))

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

Wsum = [0]
for i in range(N):
    if S[i] == 'W':
        Wsum.append(Wsum[i] + 1)
    else:
        Wsum.append(Wsum[i])
del Wsum[0]

S = S[::-1]
Esum = [0]
for i in range(N):
    if S[i] == 'E':
        Esum.append(Esum[i] + 1)
    else:
        Esum.append(Esum[i])
del Esum[0]
Esum = Esum[::-1]

Sum = []
for i in range(0,N):
    Sum.append(Wsum[i] + Esum[i]-1)

print(min(Sum))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int,input().split()))
idx = N//2-1
for i in range(N):
    tmp = X[:i] + X[i+1:]
    tmp.sort()
    print(tmp[idx])

Fixed submission:
N = int(input())
X = list(map(int,input().split()))
mid = N//2-1
sX = sorted(X)
for i in range(N):
    if X[i] <= sX[mid]: print(sX[mid+1])
    else: print(sX[mid])
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for i in range(0, A+1):
    xi = X - 500 * i
    if xi < 0: break
    for j in range(0, B+1):
        xj = xi - 100 * j
        if xj < 0: break
        for k in range(0, C+1):
            xk = xj - 50 * k
            # print('{} {} {} {}'.format(i,j,k,xk))
            if xk == 0: ans += 1
            if xk < 0: break

print(ans)

Fixed submission:
X = int(input())
A = int(input())
B = int(input())

print((X - A) % B)
Buggy python submission (verdict: Runtime Error):
N = int(input())

flag = True
t0 = x0 = y0 = 0
for i in range(N):
    t1, x1, y1 = map(int, input().split())
    t = t1 - t0
    x = x1 - x0
    y = y1 - y0
    if t % (abs(x) + abs(y)) != 0: flag = False
    t0 = t1
    x0 = x1
    y0 = y1

if flag: print('Yes')
else: print('No')

Fixed submission:
N = int(input())

flag = True
t0 = x0 = y0 = 0
for i in range(N):
    t1, x1, y1 = map(int, input().split())
    t = t1 - t0
    x = x1 - x0
    y = y1 - y0
    if (abs(x) + abs(y)) == 0:
        if t % 2 == 0: pass
    elif t % (abs(x) + abs(y)) != 0:
        flag = False
    t0 = t1
    x0 = x1
    y0 = y1

if flag: print('Yes')
else: print('No')
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))

ans = 'IMPOSSIBLE'
if max(A) >= K:
    from math import gcd
    from functools import reduce
    g = reduce(gcd,A)
    if K % g == 0: ans = 'POSSIBLE'

print(ans)

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

ans = 'IMPOSSIBLE'
if max(A) >= K:
    # from math import gcd
    from fractions import gcd
    from functools import reduce
    g = reduce(gcd,A)
    # print(g)
    if K % g == 0: ans = 'POSSIBLE'

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))
A.reverse()
ans = []
left = True
while A:
    if left: ans = [A.pop()] + ans
    else: ans.append(A.pop())
    left = not left
if n % 2 == 0: ans.reverse()
print(' '.join(str(a) for a in ans))

Fixed submission:
from collections import deque
n = int(input())
A = list(map(int,input().split()))
A.reverse()

left = True
ans = deque()
while A:
    if left: ans.appendleft(A.pop())
    else: ans.append(A.pop())
    left = not left
if n % 2 == 0: ans.reverse()
print(' '.join(str(a) for a in ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))
A.reverse()
ans = []
left = True
while A:
    if left: ans.insert(0,A.pop())
    else: ans.append(A.pop())
    left = not left
if n % 2 == 0: ans.reverse()
print(' '.join(str(a) for a in ans))

Fixed submission:
from collections import deque
n = int(input())
A = list(map(int,input().split()))
A.reverse()

left = True
ans = deque()
while A:
    if left: ans.appendleft(A.pop())
    else: ans.append(A.pop())
    left = not left
if n % 2 == 0: ans.reverse()
print(' '.join(str(a) for a in ans))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

dif = [0] * (N-1)
for i in range(1,N): dif[i-1] = A[i] - A[i-1]

ans = 1
t = dif[0]
for i in range(N-1):
    if dif[i]*t < 0:
        ans += 1
        if i < N-2:
            t = dif[i+1]
print(ans)

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

dif = [0] * (N-1)
for i in range(1,N): dif[i-1] = A[i] - A[i-1]

ans = 1
t = 0
i = 0
for d in dif:
    if t == 0:
        t = d
    elif d*t < 0:
        ans += 1
        t = 0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())

ans = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i+j+k == S: ans += 1
            if i+j+k > S: break
        if i+j > S: break
    if i > S: break

print(ans)

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

ans = 0
for i in range(K+1):
    for j in range(K+1):
        if 0 <= S-i-j <= K: ans+=1
        if S-i-j < 0: break
    if i > S: break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
TA = [tuple(map(int, input().split())) for i in range(N)]

tak = TA[0][0]
aok = TA[0][1]
for i in range(1,N):
    j = 1
    while tak > TA[i][0]*j or aok > TA[i][1]*j:
        j += 1
    tak = TA[i][0] * j
    aok = TA[i][1] * j

print(tak+aok)

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

def floordiv(a,b):
    return (a+b-1)//b

tak = TA[0][0]
aok = TA[0][1]
for i in range(1,N): 
    mul = max(floordiv(tak,TA[i][0]), floordiv(aok,TA[i][1]))
    tak = TA[i][0] * mul
    aok = TA[i][1] * mul

print(tak+aok)
Buggy python submission (verdict: Time Limit Exceeded):
X = input()
while 'ST' in X:
    X = X.replace('ST','',1)
print(len(X))

Fixed submission:
X = input()
st = []
for s in X:
    if s == 'S': st.append(s)
    if s == 'T':
        if (not st) or st[-1] == 'T': st.append(s)
        if st[-1] == 'S': st.pop()
print(len(st))

Buggy python submission (verdict: Time Limit Exceeded):
X = input()
for i in range(len(X)//2+1):
    X = X.replace('ST','')
print(len(X))

Fixed submission:
X = input()
st = []
for s in X:
    if s == 'S': st.append(s)
    if s == 'T':
        if (not st) or st[-1] == 'T': st.append(s)
        if st[-1] == 'S': st.pop()
print(len(st))

Buggy python submission (verdict: Time Limit Exceeded):
X = input()
while 'ST' in X:
    X = X.replace('ST','')
print(len(X))

Fixed submission:
X = input()
st = []
for s in X:
    if s == 'S': st.append(s)
    if s == 'T':
        if (not st) or st[-1] == 'T': st.append(s)
        if st[-1] == 'S': st.pop()
print(len(st))
Buggy python submission (verdict: Time Limit Exceeded):
a=int(input())
b=list(map(int,input().split()))
c=b.copy()
d=0
e=[]
for m in range(a):
    tmp=0
    d+=1
    for i in range(m,len(b)):
        if d==b[i]:
            try:
                c.remove(b[i])
                tmp+=1
            except ValueError:
                break
    e.append(str(tmp))

f='\n'.join(e)
print(f)

Fixed submission:
a=int(input())
b=list(map(int,input().split()))
d=0
e=[0 for i in range(a)]


for i in range(len(b)):
    e[b[i]-1]+=1

for j in e:
    print(str(j))

Buggy python submission (verdict: Time Limit Exceeded):
a=int(input())
b=list(map(int,input().split()))
c=b.copy()
d=0
e=[]
for m in range(a):
    tmp=0
    d+=1
    for n,i in enumerate(b):
        if d==i:
            try:
                c.remove(i)
                tmp+=1
            except ValueError:
                break
    e.append(str(tmp))

f='\n'.join(e)
print(f)


Fixed submission:
a=int(input())
b=list(map(int,input().split()))
d=0
e=[0 for i in range(a)]


for i in range(len(b)):
    e[b[i]-1]+=1

for j in e:
    print(str(j))
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a%b!=0:print((a//b)+1) else:print(a//b)


Fixed submission:
a,b=map(int,input().split())
if a%b!=0:print((a//b)+1)
else:print(a//b)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

count = 0
for i in range(1000):
  pin = "00" + str(i)
  pin = pin[-3:]
  
  idx = 0
  for j in range(n):
    if s[j] == pin[idx]:
      idx += 1
      
    if idx == 3:
      break

  if idx == 3:
    count += 1
      
print(count)

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

count = 0
for i in range(1000):
  pin = "00" + str(i)
  pin = pin[-3:]
  
  idx = 0
  for j in range(n):
    if s[j] == pin[idx]:
      idx += 1
      
    if idx == 3:
      break

  if idx == 3:
    count += 1
      
print(count)

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

count = 0
for i in range(1000):
  pin = "00" + str(i)
  pin = pin[-3:]
  
  idx = 0
  for j in range(n):
    if s[j] == pin[idx]:
      idx += 1
      
    if idx == 3:
      count += 1
      break
      
print(count)

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

count = 0
for i in range(1000):
  pin = "00" + str(i)
  pin = pin[-3:]
  
  idx = 0
  for j in range(n):
    if s[j] == pin[idx]:
      idx += 1
      
    if idx == 3:
      break

  if idx == 3:
    count += 1
      
print(count)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
numlist = [str(i) for i in range(10)]
numlist *= 3

numcombi = list(itertools.combinations(numlist, 3))

print(numcombi)

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

count = 0
for i in range(1000):
  pin = "00" + str(i)
  pin = pin[-3:]
  
  idx = 0
  for j in range(n):
    if s[j] == pin[idx]:
      idx += 1
      
    if idx == 3:
      break

  if idx == 3:
    count += 1
      
print(count)

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

n = int(input())
s = input() 
pin = set()
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      pin.add(s[i]+s[j]+s[k])
  
print(len(pin))

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

count = 0
for i in range(1000):
  pin = "00" + str(i)
  pin = pin[-3:]
  
  idx = 0
  for j in range(n):
    if s[j] == pin[idx]:
      idx += 1
      
    if idx == 3:
      break

  if idx == 3:
    count += 1
      
print(count)
Buggy python submission (verdict: Runtime Error):
from math import gcd

def calc_half(n):
    return n//2

def lcm(L):
    ret=1
    for i in range(len(L)):
        ret=(ret*L[i])//gcd(ret,L[i])
    return ret

def f(n):
    ret=0
    while n%2==0:
        ret+=1
        n=n//2
    return ret

def g(L):
    l=[]
    for i in L:
        l.append(f(i))
    if len(set(l))==1:
        return False
    else:
        return True

n,m=map(int,input().split())
A=list(map(int,input().split()))
Auniq=list(set(A))
Ahalf=list(map(calc_half,Auniq))
lcm_ori=lcm(Auniq)
lcm_half=lcm(Ahalf)

if m<lcm_half or g(Auniq):
    print("0")
else:
    print(1+(m-lcm_half)//lcm_ori)

Fixed submission:
from fractions import gcd

def calc_half(n):
    return n//2

def lcm(L):
    ret=1
    for i in range(len(L)):
        ret=(ret*L[i])//gcd(ret,L[i])
    return ret

def f(n):
    ret=0
    while n%2==0:
        ret+=1
        n=n//2
    return ret

def g(L):
    l=[]
    for i in L:
        l.append(f(i))
    if len(set(l))==1:
        return False
    else:
        return True

n,m=map(int,input().split())
A=list(map(int,input().split()))
Auniq=list(set(A))
Ahalf=list(map(calc_half,Auniq))
lcm_ori=lcm(Auniq)
lcm_half=lcm(Ahalf)

if m<lcm_half or g(Auniq):
    print("0")
else:
    print(1+(m-lcm_half)//lcm_ori)

Buggy python submission (verdict: Runtime Error):
from math import gcd

def calc_half(n):
    return n//2

def lcm(L):
    ret=1
    for i in range(len(L)):
        ret=(ret*L[i])//gcd(ret,L[i])
    return ret

n,m=map(int,input().split())
A=list(map(int,input().split()))
Auniq=list(set(A))
Ahalf=list(map(calc_half,Auniq))
lcm_ori=lcm(Auniq)
lcm_half=lcm(Ahalf)

if m<lcm_half:
    print("0")
else:
    print(1+(m-lcm_half)//lcm_ori)

Fixed submission:
from fractions import gcd

def calc_half(n):
    return n//2

def lcm(L):
    ret=1
    for i in range(len(L)):
        ret=(ret*L[i])//gcd(ret,L[i])
    return ret

def f(n):
    ret=0
    while n%2==0:
        ret+=1
        n=n//2
    return ret

def g(L):
    l=[]
    for i in L:
        l.append(f(i))
    if len(set(l))==1:
        return False
    else:
        return True

n,m=map(int,input().split())
A=list(map(int,input().split()))
Auniq=list(set(A))
Ahalf=list(map(calc_half,Auniq))
lcm_ori=lcm(Auniq)
lcm_half=lcm(Ahalf)

if m<lcm_half or g(Auniq):
    print("0")
else:
    print(1+(m-lcm_half)//lcm_ori)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for b in range(1,n-1):
    for c in range(b+1,n):
        ans+=b-bisect.bisect_right(L[:b],L[c]-L[b])
print(ans)

Fixed submission:
import bisect
n=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for b in range(1,n-1):
    for c in range(b+1,n):
        ans+=b-bisect.bisect_right(L[:b],L[c]-L[b])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
inf=10**9+7
n,m,l=map(int,input().split())
D=[[inf]*(n+1) for _ in range(n+1)]
for _ in range(m):
    a,b,c=map(int,input().split())
    D[a][b]=c
    D[b][a]=c

for k in range(1,n+1):
    for i in range(1,n+1):
        for j in range(1,n+1):
            D[i][j]=min(D[i][j],D[i][k]+D[k][j])

DD=[[inf]*(n+1) for _ in range(n+1)]
for x in range(1,n+1):
    for y in range(1,n+1):
        if D[x][y]<=l:
            DD[x][y]=1

for k in range(1,n+1):
    for i in range(1,n+1):
        for j in range(1,n+1):
            DD[i][j]=min(DD[i][j],DD[i][k]+DD[k][j])

q=int(input())
for _ in range(q):
    s,t=map(int,input().split())
    if DD[s][t]==inf:
        print(-1)
    else:
        print(DD[s][t]-1)

Fixed submission:
import sys
input=sys.stdin.readline
inf=10**9+7
n,m,l=map(int,input().split())
D=[[inf]*(n+1) for _ in range(n+1)]
for _ in range(m):
    a,b,c=map(int,input().split())
    D[a][b]=c
    D[b][a]=c

for k in range(1,n+1):
    for i in range(1,n+1):
        for j in range(1,n+1):
            D[i][j]=min(D[i][j],D[i][k]+D[k][j])

DD=[[inf]*(n+1) for _ in range(n+1)]
for x in range(1,n+1):
    for y in range(1,n+1):
        if D[x][y]<=l:
            DD[x][y]=1

for k in range(1,n+1):
    for i in range(1,n+1):
        for j in range(1,n+1):
            DD[i][j]=min(DD[i][j],DD[i][k]+DD[k][j])

q=int(input())
for _ in range(q):
    s,t=map(int,input().split())
    if DD[s][t]==inf:
        print(-1)
    else:
        print(DD[s][t]-1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

n,m=map(int,input().split())
inf=10**9+7
dp=[inf]*(2**n)
dp[0]=0

for i in range(m):
    a,b=map(int,input().split())
    C=list(map(int,input().split()))
    bit=0
    for i in C:
        bit|=(1<<(i-1))
    for j in range(2**n):
        dp[j|bit]=min(dp[j|bit],dp[j]+a)

if dp[-1]>=inf:
    print(-1)
else:
    print(dp[-1])

Fixed submission:
import sys
input=sys.stdin.readline

n,m=map(int,input().split())
inf=10**9+7
dp=[inf]*(2**n)
dp[0]=0

for i in range(m):
    a,b=map(int,input().split())
    C=list(map(int,input().split()))
    bit=0
    for i in C:
        bit|=(1<<(i-1))
    for j in range(2**n):
        dp[j|bit]=min(dp[j|bit],dp[j]+a)

if dp[-1]>=inf:
    print(-1)
else:
    print(dp[-1])
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(2*10**5)
n,q=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
counter=[0]*n
for _ in range(q):
  p,x=map(int,input().split())
  counter[p-1]+=x
score=[0]*(n+1)
stack=[(0,-1)]
while stack!=[]:
  node,prev=stack.pop()
  score[node]=score[prev]+counter[node]
  for i in graph[node]:
    if i!=prev:
      stack.append((i,node))
print(*score[:-1])


Fixed submission:
a=int(input())
s=input()
if a>=3200:
    print(s)
else:
    print("red")