Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import collections

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

c = collections.Counter(a)

for i in range(n):
    r = 0
    k = a[i]
    c[k] = c[k]-1
    for j in c:
        if c[j] > 1:
            r = int(r + (c[j] * (c[j] - 1) / 2))
    print(r)
    c[k] = c[k]+1

Fixed submission:
import collections

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

c = collections.Counter(a)

r = 0
for j in c:
    if c[j] > 1:
        r = int(r + (c[j] * (c[j] - 1) / 2))

tmp = r 
for i in range(n):
    r = int(r - ((c[a[i]] * (c[a[i]] - 1) / 2)) + (((c[a[i]] - 1) * (c[a[i]] - 2) / 2)))
    print(r)
    r = tmp

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

for i in range(n):
    r = 0
    tmp = a
    k = tmp[i]
    tmp.pop(i)
    
    for j in range(n-1):
        r = r + tmp[j+1:].count(tmp[j])
    print(r)
    tmp.insert(0,k)

Fixed submission:
import collections

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

c = collections.Counter(a)

r = 0
for j in c:
    if c[j] > 1:
        r = int(r + (c[j] * (c[j] - 1) / 2))

tmp = r 
for i in range(n):
    r = int(r - ((c[a[i]] * (c[a[i]] - 1) / 2)) + (((c[a[i]] - 1) * (c[a[i]] - 2) / 2)))
    print(r)
    r = tmp
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int, input().split()))
tmp = 0

for i in range(n):
    if a[i] % 2 == 0 and (a[i] % 3 != 0 and a[i] % 5 != 0):
        print('DENIED')
        tmp = 1
        break

if tmp == 0:
    rint('APPROVED')

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

for i in range(n):
    if a[i] % 2 == 0 and (a[i] % 3 != 0 and a[i] % 5 != 0):
        print('DENIED')
        tmp = 1
        break

if tmp == 0:
    print('APPROVED')
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s = []
max = 0

for i in range(n):
    s.append(input())

for i in range(n):
    if max < s.count(str(s[i])):
        max = s.count(str(s[i]))
        s2 = []
        s2.append(s[i])
    elif max == s.count(str(s[i])):
        s2.append(s[i])

s2.sort()

for i in range(len(s2)):
    if i == 0:
        print(s2[i])
    elif s2[i] != s2[i-1]:
        print(s2[i])

Fixed submission:
import collections

n=int(input())
s = []
max = 0

for i in range(n):
    s.append(input())

c = collections.Counter(s)

for i in c.items():
    if i[1] > max:
        max = i[1]

s2 = [i[0] for i in c.items() if i[1] == max]

s2.sort()

for j in range(len(s2)):
    print(s2[j])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s = []
max = 0

for i in range(n):
    s.append(input())

s.sort()

for i in range(n):
    if max < s.count(str(s[i])):
        max = s.count(str(s[i]))

for i in range(n):
    if i == 0 and max == s.count(str(s[i])):
        print(s[i])
    elif max == s.count(str(s[i])) and s[i] != s[i-1]:
        print(s[i])

Fixed submission:
import collections

n=int(input())
s = []
max = 0

for i in range(n):
    s.append(input())

c = collections.Counter(s)

for i in c.items():
    if i[1] > max:
        max = i[1]

s2 = [i[0] for i in c.items() if i[1] == max]

s2.sort()

for j in range(len(s2)):
    print(s2[j])
Buggy python submission (verdict: Time Limit Exceeded):
import math
n,k=map(int, input().split())
p=list(map(int, input().split()))
max = 0

for i in range(n):
    if p[i] % 2 == 0:
        p[i] = (p[i] + 1) * (p[i] / 2) /p[i]
    else:
        p[i] = ((p[i] + 1) * math.floor(p[i] / 2) + math.ceil(p[i] / 2))  /p[i]

for i in range(n - k + 1):
    tmp = 0
    for j in range(k):
        tmp = tmp + p[i + j]
    if max < tmp:
        max = tmp

print(max)

Fixed submission:
import math
n,k=map(int, input().split())
p=list(map(int, input().split()))

for i in range(n):
    if p[i] % 2 == 0:
        p[i] = (p[i] + 1) * (p[i] / 2) /p[i]
    else:
        p[i] = ((p[i] + 1) * math.floor(p[i] / 2) + math.ceil(p[i] / 2))  /p[i]

tmp = 0
for j in range(k):
    tmp = tmp + p[j]

max = tmp

for i in range(n - k):
    tmp = tmp - p[i] + p[i + k]
    if max < tmp:
        max = tmp

print(max)
Buggy python submission (verdict: Time Limit Exceeded):
a, b ,c= input().split()
a = int(a)
b = int(b)
c = int(c)
for i in range(c):
    if a > 0:
        a = a - 1
    elif b > 0:
        b = b - 1
print(str(a)+" "+str(b))

Fixed submission:
a, b ,c= input().split()
a = int(a)
b = int(b)
c = int(c)
d = a - c
if d < 0:
    a = 0
    e = b + d
    if e < 0:
        b = 0
    else:
        b = b + d
else:
    a = a - c
print(str(a)+" "+str(b))
Buggy python submission (verdict: Runtime Error):
a,b,c,d = int(input().split())

print(max(a*c, a*d, b*c, b*d))

Fixed submission:
a,b,c,d = map(int,input().split())

print(max(a*c, a*d, b*c, b*d))
Buggy python submission (verdict: Runtime Error):

if k<a:
  print(k)
elif a<=k and k<=a+b:
  print(a)
elif a+b<k and k<a+b+c:
  print(a-(k-a-b))
else:
  print(a-c)

Fixed submission:
a,b,c,k = map(int,input().split())

if k<a:
  print(k)
elif a<=k and k<=a+b:
  print(a)
elif a+b<k and k<a+b+c:
  print(a-(k-a-b))
else:
  print(a-c)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
lis = [list(input().split()) for _ in range(m)]

dp = [[0 for _ in range(2)] for _ in range(n)] # AC_flg, WA数

for i in range(m):
    if dp[i][0]==1:
        continue
    else:
        if lis[i][1]=='WA':
            dp[int(lis[i][0])][1] += 1
        if lis[i][1]=='AC':
            dp[int(lis[i][0])][0] = 1

ac = 0
wa = 0

for i in range(n):
    if dp[i][0]==1:
        ac += 1
        wa += dp[i][1]

print(ac,wa)

Fixed submission:
n,m = map(int,input().split())
lis = [list(input().split()) for _ in range(m)]

dp = [[0 for _ in range(2)] for _ in range(n)] # AC_flg, WA数

for i in range(m):
    if dp[int(lis[i][0])-1][0]==1:
        continue
    else:
        if lis[i][1]=='WA':
            dp[int(lis[i][0])-1][1] += 1
        if lis[i][1]=='AC':
            dp[int(lis[i][0])-1][0] = 1

ac = 0
wa = 0

for i in range(n):
    if dp[i][0]==1:
        ac += 1
        wa += dp[i][1]

print(ac,wa)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools   # accumulate, compress, permutations(nPr), combinations(nCr)
# import bisect      # bisect_left(insert位置), bisect_right(slice用)
# import math        # factorical（階乗) # hypot(距離)
# import heapq
# from fractions import gcd # Python3.5以前 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
from math import gcd # Python3.6以降
# --------------------------------------------------------------

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

cnt = 0

for i in itertools.combinations(bo,3):
    if i[0]<i[1]+i[2] and i[1]<i[2]+i[0] and i[2]<i[0]+i[1]:
        cnt += 1

print(cnt)

Fixed submission:
import itertools   # accumulate, compress, permutations(nPr), combinations(nCr)
import bisect      # bisect_left(insert位置), bisect_right(slice用)
# import math        # factorical（階乗) # hypot(距離)
# import heapq
# from fractions import gcd # Python3.5以前 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # Python3.6以降
# --------------------------------------------------------------

n  = int(input())
bo = list(map(int,input().split()))
 
cnt = 0
bo.sort()
 
for a in range(n-1):
    for b in range(a+1,n):
        cnt += bisect.bisect_left(bo, bo[a]+bo[b]) - (b+1)

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

for i in range(m):
    price[price.index(max(price))] //= 2

print(sum(price))

Fixed submission:
import math        # factorical（階乗) # hypot(距離)
import heapq
# from fractions import gcd # Python3.5以前 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # Python3.6以降
# --------------------------------------------------------------

n,m = map(int,input().split())
price = list(map(int,input().split()))

price = [-i for i in price]

heapq.heapify(price)

for i in range(m):
    sm = heapq.heappop(price)
    sm = -(-sm//2)
    heapq.heappush(price,sm)

price = [-i for i in price]

print(sum(price))
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
s = list(input())

ans  = 0
tran = 0

for i in range(n):
    chk = s[i] + s[i+1]

    if chk == 'LR' or chk == 'RL':
        tran += 1
    else:
        ans += 1

if k*2 >= tran:
    print(n-1)
else:
    print(tran+(k*2))

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

ans  = 0
tran = 0

for i in range(n-1):
    chk = s[i] + s[i+1]

    if chk == 'LR' or chk == 'RL':
        tran += 1
    else:
        ans += 1

if k*2 >= tran:
    print(n-1)
else:
    print(ans+(k*2))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans=0

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

print(ans)

Fixed submission:
n = int(input())

ans = n*(n-1)//2

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

li = sorted(li)
tmp = li[0]

for i in range(1,N):
  tmp = (tmp + li[i]) / 2

print(tmp)

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

if a<3200:
  s = 'red'

print(s)
Buggy python submission (verdict: Runtime Error):

a,b=int(input().split())

print(max(a*b,a-b,a+b))

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

print(max(a+b,a-b,a*b))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
# from fractions import gcd # >=Python3.5 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # <Python3.5
# from math import sqrt

# input = sys.stdin.readline
# def main():

#---------------------------------------------------------

n = int(input())

clist = [None for _ in range(n)]
cnt   = 0

for i in range(n):
    clist[i] = Counter(input())

for i in range(n):
    if i < n:
        for j in range(i+1,n):
            if clist[i] == clist[j]:
                cnt += 1

print(cnt)

Fixed submission:
from collections import Counter
# from fractions import gcd # >=Python3.5 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # <Python3.5
# from math import sqrt

# input = sys.stdin.readline
# def main():

#---------------------------------------------------------

n = int(input())

clist = [''.join(sorted(input())) for _ in range(n)]

c = Counter(clist)

print(sum([v*(v-1)//2 for v in c.values()]))

Buggy python submission (verdict: Runtime Error):
n = int(input())

clist = [None for _ in range(n)]
cnt   = 0

for i in range(n):
    clist[i] = Counter(input())

for i in range(n):
    if i < n:
        for j in range(i+1,n):
            if clist[i] == clist[j]:
                cnt += 1

print(cnt)

Fixed submission:
from collections import Counter
# from fractions import gcd # >=Python3.5 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # <Python3.5
# from math import sqrt

# input = sys.stdin.readline
# def main():

#---------------------------------------------------------

n = int(input())

clist = [''.join(sorted(input())) for _ in range(n)]

c = Counter(clist)

print(sum([v*(v-1)//2 for v in c.values()]))
Buggy python submission (verdict: Time Limit Exceeded):
n   = int(input())
li1 = [int(input()) for i in range(n)]
li2 = li1.copy()
mx  = max(li1)

for i in range(n):
    if li1[i]==mx:
        li2.remove(li1[i])
        print(max(li2))
        li2.append(li1[i])
    else:
        print(mx)

Fixed submission:
n   = int(input())
li1 = [int(input()) for i in range(n)]

li2 = li1.copy()
li2.sort(reverse=True)

for i in range(n):
    if li1[i]!=li2[0]:
        print(li2[0])
    else:
        print(li2[1])

Buggy python submission (verdict: Time Limit Exceeded):
n   = int(input())
li1 = [int(input()) for i in range(n)]
li2 = li1.copy()

for i in range(n):
    li2.remove(li1[i])
    print(max(li2))
    li2.append(li1[i])

Fixed submission:
n   = int(input())
li1 = [int(input()) for i in range(n)]

li2 = li1.copy()
li2.sort(reverse=True)

for i in range(n):
    if li1[i]!=li2[0]:
        print(li2[0])
    else:
        print(li2[1])
Buggy python submission (verdict: Runtime Error):
def bisect_left_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番左側のidxとなる。
    '''
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok
 
n = int(input())
li = [int(input()) for i in range(n)]
 
tmp = [li[0]]
minli = li[0]
 
for i in range(1,n):
    if li[i] <= minli:
        minli = li[i]
        tmp.append(li[i])
    else:
        idx = bisect_left_reverse(tmp,li[i])
        tmp[idx] = li[i]
 
print(len(tmp))

Fixed submission:
import bisect
# from collections import deque
# from collections import Counter
# from fractions import gcd # >=Python3.5 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # <Python3.5
# from math import sqrt
 
n = int(input())
li = [int(input()) for i in range(n)]
li = [-x for x in li]

X = []
X.append(li[0])

for i in range(1,n):
    idx = bisect.bisect_right(X,li[i])
    if idx==len(X):
        X.append(li[i])
    else:
        X[idx] = li[i]

print(len(X))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = [int(input()) for i in range(n)]

tmp = [li[0]]

for i in range(1,n):
    if li[i] <= min(li):
        tmp.append(li[i])
    else:
        for cnt, j in enumerate(tmp):
            if li[i] > j:
                tmp[cnt] = li[i]
                break

print(len(tmp))

Fixed submission:
import bisect
# from collections import deque
# from collections import Counter
# from fractions import gcd # >=Python3.5 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # <Python3.5
# from math import sqrt
 
n = int(input())
li = [int(input()) for i in range(n)]
li = [-x for x in li]

X = []
X.append(li[0])

for i in range(1,n):
    idx = bisect.bisect_right(X,li[i])
    if idx==len(X):
        X.append(li[i])
    else:
        X[idx] = li[i]

print(len(X))
Buggy python submission (verdict: Time Limit Exceeded):
n,ng = map(int,input().split())
nglist = list(int(input()) for i in range(ng))

MOD   = 10**9+7 
dp    = [0]*(n+1)
dp[0] = 1
 
for i in range(1,n+1):

  if i in nglist:
    dp[i] = 0
    continue

  if i==1:
    dp[1] = dp[0]
    continue
  
  dp[i] = (dp[i-2] + dp[i-1]) % MOD

print(dp[n])

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

MOD    = 10**9+7 
nglist = [0]*(n+1)
dp     = [0]*(n+1)
dp[0]  = 1

for i in range(ng):
  x = int(input())
  nglist[x] = 1
 
for i in range(1,n+1):

  if nglist[i]==1:
    dp[i] = 0
    continue

  if i==1:
    dp[1] = dp[0]
    continue
  
  dp[i] = (dp[i-2] + dp[i-1]) % MOD

print(dp[n])

Buggy python submission (verdict: Time Limit Exceeded):
n,ng = map(int,input().split())
nglist = list(int(input()) for i in range(ng))

MOD   = 10**9+7 
dp    = [0]*(n+1)
dp[0] = 1

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

  if i in nglist:
    dp[i] = 0
    continue

  if i==1:
    dp[1] = dp[0]
    continue
  
  dp[i] = dp[i-2] + dp[i-1]

print(dp[n] % MOD)

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

MOD    = 10**9+7 
nglist = [0]*(n+1)
dp     = [0]*(n+1)
dp[0]  = 1

for i in range(ng):
  x = int(input())
  nglist[x] = 1
 
for i in range(1,n+1):

  if nglist[i]==1:
    dp[i] = 0
    continue

  if i==1:
    dp[1] = dp[0]
    continue
  
  dp[i] = (dp[i-2] + dp[i-1]) % MOD

print(dp[n])

Buggy python submission (verdict: Time Limit Exceeded):
n,ng = map(int,input().split())
nglist = list(int(input()) for i in range(ng))

MOD   = 10**9+7 
dp    = [0]*(n+1)
dp[0] = 1

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

  if i in nglist:
    dp[i] = 0
    continue

  if i==1:
    dp[1] = dp[0]
    continue
  
  dp[i] = (dp[i-2] + dp[i-1]) % MOD

print(dp[n])

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

MOD    = 10**9+7 
nglist = [0]*(n+1)
dp     = [0]*(n+1)
dp[0]  = 1

for i in range(ng):
  x = int(input())
  nglist[x] = 1
 
for i in range(1,n+1):

  if nglist[i]==1:
    dp[i] = 0
    continue

  if i==1:
    dp[1] = dp[0]
    continue
  
  dp[i] = (dp[i-2] + dp[i-1]) % MOD

print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
rc = [list(map(int,input().split())) for i in range(k)]

tmp = set(range(1,n+1))

for i in rc:
    tmp = tmp & set(range(i[0],i[1]+1))

print(len(tmp))

Fixed submission:
n,k = map(int,input().split())
rc = [list(map(int,input().split())) for i in range(k)]
transpose = [x for x in zip(*rc)]

ans = min(transpose[1]) - max(transpose[0])

if ans<0:
    print(0)
else:
    print(ans+1)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
li = list(map(int,input().split()))
rc = [list(map(int,input().split())) for i in range(k)]

for i in rc:
    li = li + [i[1]]*i[0]

print(sum(sorted(li, reverse=True)[0:n]))

Fixed submission:
n,k = map(int,input().split())
li = list(map(int,input().split()))
rc = [list(map(int,input().split())) for i in range(k)]

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

tmp = 0

for i in rc:
    li += [i[1]]*i[0]
    tmp += i[0]
    if tmp>n:
        break 

print(sum(sorted(li, reverse=True)[0:n]))
Buggy python submission (verdict: Runtime Error):
a,b,c,d = input()

li1 = [a,b]
li2 = [c,d]

int1 = int(''.join(li1))
int2 = int(''.join(li2))

if (int1 > 12 and int2 > 12):
    ans = 'NA'
elif (int1 == 0 and int2 == 0):
    ans = 'NA'
elif (int1 > 12 and int2 == 0):
    ans = 'NA'
elif (int1 > 12):
    ans = 'YYMM'
elif (int2 > 12 and int1 == 0):
    ans = 'NA'
elif (int2 > 12):
    ans = 'MMYY'
elif:
    ans = 'AMBIGUOUS'

print(ans)


Fixed submission:
a,b,c,d = input()

li1 = [a,b]
li2 = [c,d]

int1 = int(''.join(li1))
int2 = int(''.join(li2))

if (int1 in range(1,13)) and (int2 in range(1,13)):
    ans = 'AMBIGUOUS'
elif (int1 in range(1,13)) and (int2 not in range(1,13)):
    ans = 'MMYY'
elif (int2 in range(1,13)) and (int1 not in range(1,13)):
    ans = 'YYMM'
else:
    ans = 'NA'

print(ans)
Buggy python submission (verdict: Runtime Error):
n    = int(input())
li   = [list(map(int,input().split())) for i in range(n-1)]
clr  = [0]*n
done = [0]*n
tmp  = 0

print(li)

for i in li:
  if i[0]>i[1]:
    tmp  = i[0]
    i[0] = i[1]
    i[1] = tmp
  i[2] %= 2

li.sort()

for i in li:
  if done[i[0]-1]==0 and done[i[1]-1]==0:
    if i[2]==1:
      i[1] = i[0]^1
    done[i[0]-1] = 1
    done[i[1]-1] = 1
  elif done[i[0]-1]==1 and done[i[1]-1]==0:
    if i[2]==1:
      i[1] = i[0]^1
    done[i[1]-1] = 1
  elif done[i[0]-1]==0 and done[i[1]-1]==1:
    if i[2]==1:
      i[0] = i[1]^1
    done[i[0]-1] = 1
  else:
    continue

for i in clr:
  print(i)

Fixed submission:
from collections import deque
# from fractions import gcd # >=Python3.5
# from math import gcd # <Python3.5

n  = int(input())
li = [list(map(int,input().split())) for i in range(n-1)]

road = [[] for i in range(n)]
cost = [[] for i in range(n)]

for i in li:
  i[0]-=1
  i[1]-=1
  road[i[0]].append(i[1])
  road[i[1]].append(i[0])
  cost[i[0]].append(i[2]%2)
  cost[i[1]].append(i[2]%2)

dist = [-1]*n
que  = deque()
dist[0] = 0
que.append(0)

while(len(que)!=0):
  # BFS/DFS
  v = que.popleft()
  for i,r in enumerate(road[v]):
    if dist[r]!=-1:
      continue
    dist[r] = (dist[v]+cost[v][i])%2
    que.append(r)

print(*dist,sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split(" ")))

    total = 0
    c_list = []
    a_count_list = []
    for i in range(n):
        count = a.count(i + 1)
        a_count_list.append(count)
        # print(count)
        if count > 1: # 2個以上
            # c = combinations_count(count, 2)
            c = count * (count - 1) // 2
        else:
            c = 0

        c_list.append(c)
        total = total + c

    # print(a, c_list, total, a_count_list)
    for k in range(n):
        if c_list[a[k] - 1] == 1:
            q = 1
        elif c_list[a[k] - 1] == 0:
            q = 0
        else:
            # q = c_list[a[k] - 1] - 1
            q = c_list[a[k] - 1] - c_list[a[k] - 1] * (a_count_list[a[k] - 1] - 2) // a_count_list[a[k] - 1]
        print(total - q)

Fixed submission:
from collections import defaultdict

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split(" ")))

    variation = set(a)
    a_count_dict = defaultdict(int)
    for j in a:
        a_count_dict[j] += 1

    total = 0
    c_dict = {}
    for i in variation:
        count = a_count_dict[i]
        if count > 1: # 2個以上
            # c = combinations_count(count, 2)
            c = count * (count - 1) // 2
        else:
            c = 0
        c_dict[i] = c
        total = total + c

    # total = 0
    # c_list = []
    # a_count_list = []
    # for i in range(n):
    #     count = a.count(i + 1)
    #     a_count_list.append(count)
    #     # print(count)
    #     if count > 1: # 2個以上
    #         # c = combinations_count(count, 2)
    #         c = count * (count - 1) // 2
    #     else:
    #         c = 0
    #
    #     c_list.append(c)
    #     total = total + c

    # print(a, c_list, total, a_count_list)
    for k in range(n):
        ck = c_dict[a[k]]
        ca = a_count_dict[a[k]]
        if ck == 1 or ck == 0:
            q = ck
        else:
            # q = c_list[a[k] - 1] - 1
            q = ck - ck * (ca - 2) // ca


        # if c_list[a[k] - 1] == 1:
        #     q = 1
        # elif c_list[a[k] - 1] == 0:
        #     q = 0
        # else:
        #     # q = c_list[a[k] - 1] - 1
        #     q = c_list[a[k] - 1] - c_list[a[k] - 1] * (a_count_list[a[k] - 1] - 2) // a_count_list[a[k] - 1]
        print(total - q)
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input())
    p = list(map(int, input().split(" ")))

    count = 0
    for i in range(n):
        flag = 0
        for j in range(n):
            if i > j:
                if p[i] > p[j]:
                    flag = 1
                    break
                    # print(i, j)
        if flag == 0:
            count = count + 1

    print(count)

Fixed submission:
if __name__ == '__main__':
    n = int(input())
    p = list(map(int, input().split(" ")))

    count = 0
    min_num = 10000000
    for i in p:
        if i < min_num:
            count = count + 1
            min_num = i

    print(count)

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

    count = 0
    for i in range(n):
        flag = 0
        for j in range(n):
            if i > j:
                if p[i] > p[j]:
                    flag = 1
                    # print(i, j)
        if flag == 0:
            count = count + 1

    print(count)

Fixed submission:
if __name__ == '__main__':
    n = int(input())
    p = list(map(int, input().split(" ")))

    count = 0
    min_num = 10000000
    for i in p:
        if i < min_num:
            count = count + 1
            min_num = i

    print(count)
Buggy python submission (verdict: Runtime Error):
s=list(input())
if s[-1]=='s':
    print(s+'es')
else:
    print(s+'s')

Fixed submission:
s=input()
if s[-1]=='s':
    print(s,'es',sep='')
else:
    print(s,'s',sep='')
Buggy python submission (verdict: Runtime Error):
n=int(input())
for i in range(n):
    a,b=list(map(int,input().split()))
for i in range(n-2):
    if a[i]==b[i] and a[i+1]==b[i+1] and a[i+2]==b[i+2]:
        print('Yes')
        exit()
print('No')

Fixed submission:
n=int(input())
k=0
l=0
for i in range(n):
    a,b=map(int,input().split())
    if a==b:
        k += 1
        if k==3:
            print('Yes')
            exit()
    else:
        k = 0
print('No')