Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import collections
n = int(input())
v = list(map(int,input().split()))
a = v[0::2]
suma = len(a)
b = v[1::2]
sumb = len(b)
a = collections.Counter(a)
a = a.most_common()
b = collections.Counter(b)
b = b.most_common()

if a[0][0] != b[0][0]:
        ans = suma-a[0][1] + sumb-b[0][1]
        print(ans)
else:  
        ans1 = suma-a[1][1] + sumb-b[0][1]
        ans2 = suma-a[0][1] + sumb-b[1][1]
        print(min(ans1,ans2))

Fixed submission:
import collections
n = int(input())
v = list(map(int,input().split()))
a = v[0::2]
b = v[1::2]
a = collections.Counter(a)
a = a.most_common()
b = collections.Counter(b)
b = b.most_common()
c = n//2
if a[0][0] != b[0][0]:
    ans = c-a[0][1] + c-b[0][1]
    print(ans)
else: 
    if len(a) == 1:
        tmpa = 0
    else:
        tmpa = a[1][1]
    if len(b) == 1:
        tmpb = 0
    else:
        tmpb = b[1][1]
    ans1 = c-tmpa + c-b[0][1]
    ans2 = c-a[0][1] + c-tmpb
    print(min(ans1,ans2))

Buggy python submission (verdict: Runtime Error):
n = int(input())
v = list(map(int,input().split()))
a = []
x = []
b = []
y = []

for i in range(n):
        if i%2==1:
                if v[i] in a:
                        x[a.index(v[i])] += 1
                else:
                        a.append(v[i])
                        x.append(1)
        else:
                if v[i] in b:
                        y[b.index(v[i])] += 1
                else:
                        b.append(v[i])
                        y.append(1)

if a[x.index(max(x))] != b[y.index(max(y))]:
        x=sorted(x)[::-1]
        y=sorted(y)[::-1]

        sumx = sum(x)
        sumy = sum(y)

        changea = sumx-x[0]
        changeb = sumy-y[0]
        print(changea + changeb)
else:  
        x=sorted(x)[::-1]
        y=sorted(y)[::-1]
        sumx = sum(x)
        sumy = sum(y)

        ans1 = sumx-x[0] + sumy-y[1]
        ans2 = sumx-x[1] + sumy-y[0]
        print(min(ans1,ans2))

Fixed submission:
import collections
n = int(input())
v = list(map(int,input().split()))
a = v[0::2]
b = v[1::2]
a = collections.Counter(a)
a = a.most_common()
b = collections.Counter(b)
b = b.most_common()
c = n//2
if a[0][0] != b[0][0]:
    ans = c-a[0][1] + c-b[0][1]
    print(ans)
else: 
    if len(a) == 1:
        tmpa = 0
    else:
        tmpa = a[1][1]
    if len(b) == 1:
        tmpb = 0
    else:
        tmpb = b[1][1]
    ans1 = c-tmpa + c-b[0][1]
    ans2 = c-a[0][1] + c-tmpb
    print(min(ans1,ans2))
Buggy python submission (verdict: Runtime Error):
a = int(input()) 
b = int(input())
if a>9 or b>9:
    print(":(")
else:
    print("Yay!")

Fixed submission:
a,b= map(int ,input().split())
if a>8 or b>8:
    print(":(")
else:
    print("Yay!")
Buggy python submission (verdict: Runtime Error):
a = int(input())
s = input()
x=[]
y=[]
count=[]
for i in range (a):
    for j in range (i):
        x[j]=s[j]
    for k in range (a-i):
        y[k]=s[i+k]
    for l in range (i):
        for m in range (a-i):
            if x[l] == y[m]:
                count[i]+=1
                break
print(max(count))

Fixed submission:
n = int(input())
s = input()
s = list(s)
x = 0
for i in range(1,n):
  a = set(s[:i])
  b = set(s[i:])
  c = len(list(a&b))
  if x<c:
    x = c
print(x)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
x = 10000000
for i in range(n):
  a = s[:i]
  b = s[i+1:]
  c = a.count("W")+b.count("E")
  if x>c:
    x = c
print(x)

Fixed submission:
n = int(input())
s = list(input())
a = []
a.append(s[1:].count("E"))
for i in range(n-1):
    if s[i+1] == "E" and s[i] == "E":
        a.append(a[i]-1)
    elif s[i+1] == "W" and s[i] == "E":
        a.append(a[i])
    elif s[i+1] == "E" and s[i] == "W":
        a.append(a[i])
    elif s[i+1] == "W" and s[i] == "W":
        a.append(a[i]+1)
print(min(a))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect as bi
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
ans = 0
for i in range(len(c)):
    for j in range(bi.bisect_left(b,c[i])):
        ans += bi.bisect_left(a,b[j])
print(ans)

Fixed submission:
import bisect as bi
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
ans = 0
for i in range(len(b)):
        ans += bi.bisect_left(a,b[i]) *  (len(c) - bi.bisect_right(c,b[i]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
Vn=list(map(int,input().split()))
Cn=list(map(int,input().split()))

best = 0
for i in range(2**N):
    t = 0
    for j in range(N):
        if (i >> j) & 1:
            t += (Vn[j] - Cn[j])
    if t > best:
        best = t
print(best)


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

best = 0
for i in range(2**N):
    t = 0
    for j in range(N):
        if (i >> j) & 1:
            t += (Vn[j] - Cn[j])
    if t > best:
        best = t
print(best)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()

b = 0
for i in range(N):
    if S[N-i-1] == '#':
        b += (2**i)

print(min(bin((2**i-1)^b).count("1") for i in range(N+1)))


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

w = [0] * N
b = [0] * N

if S[0] == '#':
    w[0] = 1
for i in range(1, N):
    if S[i] == '#':
        w[i] = w[i-1] + 1
    else:
        w[i] = w[i-1]

if S[N-1] == '.':
    b[N-1] = 1
for i in range(N-2, -1, -1):
    if S[i] == '.':
        b[i] = b[i+1] + 1
    else:
        b[i] = b[i+1]

m = min(b[0], w[N-1])
for n in range(N-1):
    v = w[n] + b[n+1]
    if v < m:
        m = v
print(m)

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

b = 0
for i in range(N):
    if S[N-i-1] == '#':
        b += (2**i)

print(min(bin((2**i-1)^b).count("1") for i in range(N+1)))

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

w = [0] * N
b = [0] * N

if S[0] == '#':
    w[0] = 1
for i in range(1, N):
    if S[i] == '#':
        w[i] = w[i-1] + 1
    else:
        w[i] = w[i-1]

if S[N-1] == '.':
    b[N-1] = 1
for i in range(N-2, -1, -1):
    if S[i] == '.':
        b[i] = b[i+1] + 1
    else:
        b[i] = b[i+1]

m = min(b[0], w[N-1])
for n in range(N-1):
    v = w[n] + b[n+1]
    if v < m:
        m = v
print(m)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
hn = list(map(int, input().split()))

dp = [0]*N
for i in range(1, N):
    dp[i] = min(dp[j]+abs(hn[i]-hn[j]) for j in range(i-1, i-1-K, -1) if j >= 0)
print(dp[-1])


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

dp = [0]*N
for i in range(1, N):
    dp[i] = min(dp[j]+abs(hn[i]-hn[j]) for j in range(i-1, i-1-K, -1) if j >= 0)
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
N,X=map(int,input().split())
xn = map(int, input().split())
dxn = [abs(x-X) for x in xn]
import fractions
a, b = dxn[0], dxn[1]
for i in range(N-1):
    c = fractions.gcd(a, b)
    a = b
    b = c
print(c)


Fixed submission:
N,X=map(int,input().split())
xn = map(int, input().split())
dxn = [abs(x-X) for x in xn]
import fractions
from functools import reduce
print(reduce(fractions.gcd, dxn))
Buggy python submission (verdict: Runtime Error):
c11, c12, c13 = map(int, input().split())
c21, c22, c23 = map(int, input().split())
c31, c32, c33 = map(int, input().split())

bs = []
for a1 in range(0, 100):
    for b1 in range(0, 100):
        if a1 + b1 == c11:
            f1 = True
            break
    for b2 in range(0, 100):
        if a1 + b2 == c12:
            f2 = True
            break
    for b3 in range(0, 100):
        if a1 + b3 == c13:
            f3 = True
            break
    if f1 and f2 and f3:
        bs.append((b1, b2, b3))

bss = []
for a2 in range(0, 100):
    for b1, b2, b3 in bs:
        if a2 + b1 == c21 and a2 + b2 == c22 and a2 + b3 == c23:
            bss.append((b1, b2, b3))

for a3 in range(0, 100):
    for b1, b2, b3 in bss:
        if a3 + b1 == c31 and a3 + b2 == c32 and a3 + b3 == c33:
            print("Yes")
            break
    else:
        continue
    break
else:
    print("No")


Fixed submission:
c11, c12, c13 = map(int, input().split())
c21, c22, c23 = map(int, input().split())
c31, c32, c33 = map(int, input().split())

bs = []
for a1 in range(0, 101):
    for b1 in range(0, 101):
        if a1 + b1 == c11:
            f1 = True
            break
    for b2 in range(0, 101):
        if a1 + b2 == c12:
            f2 = True
            break
    for b3 in range(0, 101):
        if a1 + b3 == c13:
            f3 = True
            break
    if f1 and f2 and f3:
        bs.append((b1, b2, b3))

bss = []
for a2 in range(0, 101):
    for b1, b2, b3 in bs:
        if a2 + b1 == c21 and a2 + b2 == c22 and a2 + b3 == c23:
            bss.append((b1, b2, b3))

for a3 in range(0, 101):
    for b1, b2, b3 in bss:
        if a3 + b1 == c31 and a3 + b2 == c32 and a3 + b3 == c33:
            print("Yes")
            break
    else:
        continue
    break
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
for n in range(1, 3501):
    for w in range(1, 3501):
        denominator = 4*n*w - w*N - n*N
        numerator = n*w*N
        if denominator != 0 and numerator%denominator == 0:
            h = numerator // denominator
            if 0 < h <= 3500:
                print(h, n, w)
                break
    else:
        continue
    break

Fixed submission:
N = int(input())
for n in range(1, 3501):
    for w in range(1, 3501):
        denominator = 4*n*w - w*N - n*N
        numerator = n*w*N
        if denominator != 0 and numerator%denominator == 0:
            h = numerator // denominator
            if 0 < h <= 3500:
                print(h, n, w)
                break
    else:
        continue
    break
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
an = map(int, input().split())

sum_an = []
tmp = 0
for a in an:
    tmp += a
    sum_an.append(tmp)

c = 0
before_positive = sum_an[0] <= 0
for i in range(n):
    if before_positive and sum_an[i] >= 0:
        p = abs(sum_an[i]) + 1
        c += p
        for j in range(i, n):
            sum_an[j] -= p
        before_positive = False
    elif not before_positive and sum_an[i] <= 0:
        p = abs(sum_an[i]) + 1
        c += p
        for j in range(i, n):
            sum_an[j] += p
        before_positive = True
    else:
        before_positive = not before_positive

print(c)


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

c1 = 0
c2 = 0
sum1 = 0 # 偶数番目が正
sum2 = 0 # 奇数番目が正
for i in range(n):
    sum1 += an[i]
    sum2 += an[i]
    if i%2 == 0:
        if sum1 <= 0:
            p = abs(sum1) + 1
            c1 += p
            sum1 += p
        if sum2 >= 0:
            p = abs(sum2) + 1
            c2 += p
            sum2 -= p
    else:
        if sum1 >= 0:
            p = abs(sum1) + 1
            c1 += p
            sum1 -= p
        if sum2 <= 0:
            p = abs(sum2) + 1
            c2 += p
            sum2 += p

print(min(c1, c2))
Buggy python submission (verdict: Runtime Error):
import sys
import bisect
input = sys.stdin.readline

a,b,q = map(int, input().split())
s = [-1 for i in range(a)]
t = [-1 for i in range(b)]

for i in range(a):
	S = int(input())
    s[i] = S
    
for i in range(b):
	T = int(input())
    t[i] = T
    
s.sort()
t.sort()

for i in range(q):
	x = int(input())
    slidx = bisect.bisect_left(s, x)
    tlidx = bisect.bisect_left(t, x) 
	sl = x - s[slidx]
	tl = x - t[tlidx]
    tr = 90000000000 - x
    sr = 90000000000 - x
    if slidx < a-1:
      sr = s[slidx+1] - x
    if slidx < b-1:
      tr = t[tlidx+1] - x
    dist = min( [max(sl,tl), max(sr,tr), min(sr, sl)*2 + min(tr,tl), min(tr,tl)*2 + min(sr,sl)] )
    print(dist)

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

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

s = [-1 for i in range(a)]
t = [-1 for i in range(b)]

for i in range(a):
	S = int(input())
	s[i] = S
    
for i in range(b):
	T = int(input())
	t[i] = T
    
s.sort()
t.sort()
for i in range(q):
	x = int(input())

	slidx = bisect.bisect_left(s, x) -1
	tlidx = bisect.bisect_left(t, x) -1
	sl = -20000000000
	tl = -20000000000
	sr = 20000000000
	tr = 20000000000
	if slidx >= 0:
		sl = s[slidx]
	if tlidx >= 0:
		tl = t[tlidx]

	if slidx < a-1:
		sr = s[slidx+1]
	if tlidx < b-1:
		tr = t[tlidx+1]
	sl = x - sl
	tl = x - tl
	sr = sr - x
	tr = tr - x
	#print([sl,tl,sr,tr])
	dist = min( [max(sl,tl), max(sr,tr), min(sr, sl)*2 + min(tr,tl), min(tr,tl)*2 + min(sr,sl)])
	print(dist)

Buggy python submission (verdict: Runtime Error):
import sys
import bisect
input = sys.stdin.readline

a,b,q = map(int, input().split())
s = [-1 for i in range(a)]
t = [-1 for i in range(b)]

for i in range(a):
	S = int(input())
    s[i] = S
    
for i in range(b):
	T = int(input())
    t[i] = T
    
s.sort()
t.sort()

for i in range(q):
	x = int(input())
    slidx = bisect.bisect_left(s, x)
    tlidx = bisect.bisect_left(t, x) 
	sl = x - s[slidx]
	tl = x - t[tlidx]
    tr = 90000000000 - x
    sr = 90000000000 - x
    if slidx < a-1:
      sr = s[slidx+1] - x
    if slidx < b-1:
      tr = t[tlidx+1] - x
    dist = min( max(sl,tl), max(sr,tr), min(sr, sl)*2 + min(tr,tl), min(tr,tl)*2 + min(sr,sl))
    print(dist)

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

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

s = [-1 for i in range(a)]
t = [-1 for i in range(b)]

for i in range(a):
	S = int(input())
	s[i] = S
    
for i in range(b):
	T = int(input())
	t[i] = T
    
s.sort()
t.sort()
for i in range(q):
	x = int(input())

	slidx = bisect.bisect_left(s, x) -1
	tlidx = bisect.bisect_left(t, x) -1
	sl = -20000000000
	tl = -20000000000
	sr = 20000000000
	tr = 20000000000
	if slidx >= 0:
		sl = s[slidx]
	if tlidx >= 0:
		tl = t[tlidx]

	if slidx < a-1:
		sr = s[slidx+1]
	if tlidx < b-1:
		tr = t[tlidx+1]
	sl = x - sl
	tl = x - tl
	sr = sr - x
	tr = tr - x
	#print([sl,tl,sr,tr])
	dist = min( [max(sl,tl), max(sr,tr), min(sr, sl)*2 + min(tr,tl), min(tr,tl)*2 + min(sr,sl)])
	print(dist)
Buggy python submission (verdict: Runtime Error):
s = input()

ans = 0
stack = [s[0]]

for c in s[1:-1]:
  if c == stack[-1]:
    ans += 2
    stack.pop(-1)
  else:
    stack.append(c)
    
print(ans)


Fixed submission:
s = input()
 
ans = 0
stack = []
 
for c in s:
  if stack == []:
    stack.append(c)
    continue
  if c != stack[-1]:
    ans += 2
    stack.pop(-1)
  else:
    stack.append(c)
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h, w, d = map(int, input().split())
A = []
for i in range(h) :
    A.append(list(map(int, input().split())))

cost = []
for i in range(h) :
    for j in range(w) :
        cost.append([A[i][j], j+1, i+1])

cost.sort(key=lambda c:c[0])

q = int(input())
for _ in range(q) :
    ans = 0
    l, r = map(int, input().split())
    while l != r :
        x1 = cost[l-1][1]
        y1 = cost[l-1][2]
        x2 = cost[l-1+d][1]
        y2 = cost[l-1+d][2]
        ans += abs(x1-x2) + abs(y1-y2)
        l += d
    else :
        print(ans)

Fixed submission:
h, w, d = map(int, input().split())
A = []
for i in range(h) :
    A.append(list(map(int, input().split())))

cost = []
for i in range(h) :
    for j in range(w) :
        cost.append([A[i][j], j+1, i+1])

cost.sort(key=lambda c:c[0])


power = [0 for _ in range(h*w)]
for i in range(d) :
    pos = i
    x1 = cost[pos][1]
    y1 = cost[pos][2]
    while pos + d < h*w :
        x2 = cost[pos+d][1]
        y2 = cost[pos+d][2]
        power[pos+d] = power[pos] + abs(x1-x2) + abs(y1-y2)
        pos += d
        x1 = x2
        y1 = y2


q = int(input())
for _ in range(q) :
    l, r = map(int, input().split())
    print(power[r-1]-power[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
s = input().split('T')
x, y = map(int, input().split())
x = abs(x-len(s[0]))
y = abs(y)
dx = []
for i in range(2, len(s), 2) :
    dx.append(len(s[i]))
dy = []
for i in range(1, len(s), 2) :
    dy.append(len(s[i]))

if sum(dx) < x or sum(dy) < y :
    print('No')
    exit()

xl = len(dx)
for i in range(1 << xl) :
    nx = 0
    for j in range(xl) :
        if i>>j & 1 :
            nx -= dx[j]
        else :
            nx += dx[j]
    if nx == x :
        break
else :
    print('No')
    exit()

yl = len(dy)
for i in range(1 << yl) :
    ny = 0
    for j in range(yl) :
        if i>>j & 1 :
            ny -= dy[j]
        else :
            ny += dy[j]
    if ny == y :
        break
else :
    print('No')
    exit()

print('Yes')

Fixed submission:
s = input().split('T')
x, y = map(int, input().split())
s = [len(_) for _ in s]
dx = s[::2]
dy = s[1::2]

x = abs(x-dx[0])
y = abs(y)
dx = dx[1:]
px = 0
py = 0
for d in reversed(sorted(dx)) :
    if px > x :
        px -= d
    else :
        px += d

for d in reversed(sorted(dy)) :
    if py > y :
        py -= d
    else :
        py += d

if px == x and py == y :
    print('Yes')
else :
    print('No')

Buggy python submission (verdict: Time Limit Exceeded):
s = input().split('T')
x, y = map(int, input().split())
x = abs(x-len(s[0]))
y = abs(y)
i = 0
j = 0
dx = []
for i in range(2, len(s), 2) :
    dx.append(len(s[i]))
dy = []
for i in range(1, len(s), 2) :
    dy.append(len(s[i]))

if sum(dx) < x or sum(dy) < y :
    print('No')
    exit()

xl = len(dx)
for i in range(1 << xl) :
    nx = 0
    for j in range(xl) :
        if i>>j & 1 :
            nx -= dx[j]
        else :
            nx += dx[j]
    if nx == x :
        break
else :
    print('No')

yl = len(dy)
for i in range(1 << yl) :
    ny = 0
    for j in range(yl) :
        if i>>j & 1 :
            ny -= dy[j]
        else :
            ny += dy[j]
    if ny == y :
        break
else :
    print('No')

print('Yes')

Fixed submission:
s = input().split('T')
x, y = map(int, input().split())
s = [len(_) for _ in s]
dx = s[::2]
dy = s[1::2]

x = abs(x-dx[0])
y = abs(y)
dx = dx[1:]
px = 0
py = 0
for d in reversed(sorted(dx)) :
    if px > x :
        px -= d
    else :
        px += d

for d in reversed(sorted(dy)) :
    if py > y :
        py -= d
    else :
        py += d

if px == x and py == y :
    print('Yes')
else :
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, z, w = map(int, input().split())
a = list(map(int, input().split()))
score = abs(z-w)
a = np.array(a)
final_scare = np.abs(a - a[-1])
last = a[-1]
final_scare = final_scare[0:-1]
if n == 1 or abs(w-a[-1]) >= final_scare.max():
    print(abs(w-a[-1]))
    exit()

idx = 0
turn = True
while idx != n-2 :
    if turn :
        idx = final_scare[idx:].argmax()
        z = a[idx]
    else :
        idx = final_scare[idx:].argmin()
        w = a[idx]
    turn = not turn

if turn :
    z = last
else :
    w = last
print(abs(z-w))

Fixed submission:
n, z, w = map(int, input().split())
a = list(map(int, input().split()))
print(abs(a[0]-w) if n == 1 else max(abs(a[-1]-w), abs(a[-1]-a[-2])))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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()
ins_c = [0]*n
ins_b = [0]*n
for i in range(n) :
    ins_c[i] = bisect.bisect_right(c, b[i])
    ins_b[i] = bisect.bisect_right(b, a[i])
ans = 0
for i in range(n) :
    for j in range(ins_b[i], n) :
        ans += n - ins_c[j]

print(ans)

Fixed submission:
import bisect

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()
dp = [0]*(n+1)
for i in range(n-1, -1, -1) :
    ins_c = bisect.bisect_right(c, b[i])
    dp[i] = dp[i+1] + (n-ins_c)
ans = 0
for i in range(n) :
    ins_b = bisect.bisect_right(b, a[i])
    ans += dp[ins_b]

print(ans)

Buggy python submission (verdict: Runtime Error):
import bisect

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()
ins_c = [0]*n
ins_b = [0]*n
parts_comb = [0]*n
for i in range(n) :
    ins_c = bisect.bisect_right(c, b[i])
    ins_b = bisect.bisect_right(b, a[i])
ans = 0
for i in range(n) :
    for j in range(ins_b[i], n) :
        ans += n - r_c

print(ans)

Fixed submission:
import bisect

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()
dp = [0]*(n+1)
for i in range(n-1, -1, -1) :
    ins_c = bisect.bisect_right(c, b[i])
    dp[i] = dp[i+1] + (n-ins_c)
ans = 0
for i in range(n) :
    ins_b = bisect.bisect_right(b, a[i])
    ans += dp[ins_b]

print(ans)

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

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()
ans = 0
for i in range(n) :
    r_b = bisect.bisect_right(b, a[i])
    for j in range(r_b, n) :
        r_c = bisect.bisect_right(c, b[j]) 
        ans += n - r_c

print(ans)

Fixed submission:
import bisect

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()
dp = [0]*(n+1)
for i in range(n-1, -1, -1) :
    ins_c = bisect.bisect_right(c, b[i])
    dp[i] = dp[i+1] + (n-ins_c)
ans = 0
for i in range(n) :
    ins_b = bisect.bisect_right(b, a[i])
    ans += dp[ins_b]

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

if n < m :
    print("NO")
else :
    s = set(t)
    for ss in s :
        if d.count(ss) < t.count(ss) :
            print("NO")
            break
    else :
        print("YES")

Fixed submission:
import collections

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


if n < m :
    print("NO")
else :
    dic = collections.defaultdict(int)
    for dd in d :
        dic[dd] += 1
    
    for tt in t :
        dic[tt] -= 1
        if dic[tt] < 0 :
            print("NO")
            break
    else :
        print("YES")

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

if n < m :
    print("NO")
else :
    s = set(t)
    for ss in s :
        if d.count(ss) < t.count(ss) :
            print("NO")
            break
    else :
        print("YES")

Fixed submission:
import collections

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


if n < m :
    print("NO")
else :
    dic = collections.defaultdict(int)
    for dd in d :
        dic[dd] += 1
    
    for tt in t :
        dic[tt] -= 1
        if dic[tt] < 0 :
            print("NO")
            break
    else :
        print("YES")

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

if n < m :
    print("NO")
else :
    for tt in t :
        if tt in d :
            idx = d.index(tt)
            d[idx] = -1
        else :
            print("NO")
            break
    else :
        print("YES")

Fixed submission:
import collections

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


if n < m :
    print("NO")
else :
    dic = collections.defaultdict(int)
    for dd in d :
        dic[dd] += 1
    
    for tt in t :
        dic[tt] -= 1
        if dic[tt] < 0 :
            print("NO")
            break
    else :
        print("YES")
Buggy python submission (verdict: Time Limit Exceeded):
def main() :
    a = input()
    L = len(a)
    ans = 1
    for i in range(L-1) :
        for j in range(L-1, i, -1) :
            if a[i] != a[j] :
                ans += 1

    print(ans)

main()

Fixed submission:
def main() :
    a = input()
    L = len(a)
    ans = L*(L-1)//2 + 1
    alp = "abcdefghijklmnopqrstuvwxyz"

    for c in alp :
        cnt = a.count(c)
        ans -= cnt*(cnt-1)//2
    
    print(ans)

main()