Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# C
import numpy as np
n, q = map(int, input().split())
s = str(input())
s_flag = [0] * n
for i in range(n-1):
    if s[i:i+2] == 'AC':
        s_flag[i] = 1
s_flag = np.array(s_flag)
for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    ans = np.sum(s_flag[l:r+1])
    if s_flag[r:r+1] == 1:
        ans -=1
    print(ans)

Fixed submission:
# C
n, q = map(int, input().split())
s = str(input())
s_flag = [0] * n
v = 0
for i in range(n-1):
    if s[i:i+2] == 'AC':
        v += 1
    s_flag[i+1] = v

for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    ans = s_flag[r] - s_flag[l]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# C
n, q = map(int, input().split())
s = str(input())
s_flag = [0] * n
for i in range(n-1):
    if s[i:i+2] == 'AC':
        s_flag[i] = 1
for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    ans = sum(s_flag[l:r])
    if s_flag[r:r+1] == 1:
        ans -=1
    print(ans)

Fixed submission:
# C
n, q = map(int, input().split())
s = str(input())
s_flag = [0] * n
v = 0
for i in range(n-1):
    if s[i:i+2] == 'AC':
        v += 1
    s_flag[i+1] = v

for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    ans = s_flag[r] - s_flag[l]
    print(ans)
Buggy python submission (verdict: Runtime Error):
# C
n, m = map(int, input().split())
ab = [0, 0] * n
for i in range(n):
    ab[i] = map(int, input().split())
ab.sort(key=lambda x:x[0])

cost = 0
for i in range(n):
    value = ab[i][0]
    num = ab[i][1]
    if num > m:
        cost += value * m
        break
    else:
        cost += value * num
        m -= num
print(cost)

Fixed submission:
# C
n, m = map(int, input().split())
ab = [[int(i) for i in input().split()] for i in range(n)]
ab.sort(key=lambda x: x[0])
index = 0
ans = 0
while m > 0 and index <= n:
    if ab[index][1] <= m:
        ans += ab[index][0] * ab[index][1]
        m -= ab[index][1]
    else:
        ans += ab[index][0] * m
        m = 0
    index += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
# C
n = int(input()) 
a = list(map(int, input().split()))

import functools
import math

gcd = functools.reduce(math.gcd, a)
print(gcd)

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

from functools import reduce
def gcd(a,b):
    if a<b:a,b=b,a
    if a%b==0:return b
    return gcd(b,a%b)

gcd=reduce(gcd,a)
print(gcd)
Buggy python submission (verdict: Runtime Error):
# D
n, m = map(int, input().split())
a = list(map(int, input().split()))
match_list = [[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]

use_list = []
# for i in match_list:
#     if i[0] in a:
#         use_list.append(i)
use_list = match_list
use_list.sort(key=lambda x:x[1])
print(use_list)
ans_list = []
num = n // use_list[0][1]
while n > 0:
    if n % use_list[0][1] == n:
        n += use_list[0][1]
        ans_list.pop(0)
        
        for i in use_list:
        break
    elif n >= use_list[0][1]:
        n -= use_list[0][1]
        ans_list.append(str(use_list[0][0]))

ans_list.sort()
ans_list.reverse()
print(''.join(map(str, ans_list)))

Fixed submission:
# D
n,m = map(int, input().split())
b = [0,2,5,5,4,5,6,3,7,6]
a = [0]+list(map(int, input().split()))
f = [-1]*10010
f[0]=0
for i in range(1,n+1):
    for j in range(1,m+1):
        x = a[j]
        if(i-b[x]<0):
            continue
        f[i] = max(f[i],f[i-b[x]]*10 + x)
print(f[n])

Buggy python submission (verdict: Runtime Error):
# D
n, m = map(int, input().split())
a = list(map(int, input().split()))
match_list = [[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]

use_list = []
# for i in match_list:
#     if i[0] in a:
#         use_list.append(i)
use_list = match_list
use_list.sort(key=lambda x:x[1])
print(use_list)
ans_list = []
num = n // use_list[0][1]
while n > 0:
    if n % use_list[0][1] == n:
        n += use_list[0][1]
        ans_list.pop(0)
        
        for i in use_list:
        break
    elif n >= use_list[0][1]:
        n -= use_list[0][1]
        ans_list.append(str(use_list[0][0]))

ans_list.sort()
ans_list.reverse()
print(''.join(map(str, ans_list)))

Fixed submission:
# D
n,m = map(int, input().split())
b = [0,2,5,5,4,5,6,3,7,6]
a = [0]+list(map(int, input().split()))
f = [-1]*10010
f[0]=0
for i in range(1,n+1):
    for j in range(1,m+1):
        x = a[j]
        if(i-b[x]<0):
            continue
        f[i] = max(f[i],f[i-b[x]]*10 + x)
print(f[n])
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input())
print(min(a, b), a+b-n)

Fixed submission:
n, a, b = map(int, input().split())
ans_min = 0 if a+b-n <0 else a+b-n
print(min(a, b), ans_min)
Buggy python submission (verdict: Time Limit Exceeded):
# B
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*(n+1)
 
for i in range(2, n+1):
    c_list = []
    if i-2 >= k:
        for j in range(1,k+1):
            c_list.append(dp[i-j] + abs(h[i-1-j] - h[i-1]))
        dp[i] = min(c_list)
    else:
        for j in range(1, i):
            c_list.append(dp[i-j] + abs(h[i-1-j] - h[i-1]))
        dp[i] = min(c_list)
print(dp[-1])

Fixed submission:
# B
import numpy as np
N, K = map(int, input().split())
h = np.array(input().split(), dtype="int32")
dp = np.zeros(N, dtype="int32")
 
for i in range(1, N):
    if i < K:
        dp[i] = np.min(dp[:i] + np.abs(h[i]-h[:i]))
    else:
        dp[i] = np.min(dp[i-K:i] + np.abs(h[i]-h[i-K:i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
# B
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*(n+1)
 
for i in range(2, n+1):
    c_list = []
    if i-2 >= k:
        for j in range(1,k+1):
            c_list.append(dp[i-j] + abs(h[i-1-j] - h[i-1]))
    else:
        for j in range(1, i):
            c_list.append(dp[i-j] + abs(h[i-1-j] - h[i-1]))
    dp[i] = min(c_list)
print(dp[-1])

Fixed submission:
# B
import numpy as np
N, K = map(int, input().split())
h = np.array(input().split(), dtype="int32")
dp = np.zeros(N, dtype="int32")
 
for i in range(1, N):
    if i < K:
        dp[i] = np.min(dp[:i] + np.abs(h[i]-h[:i]))
    else:
        dp[i] = np.min(dp[i-K:i] + np.abs(h[i]-h[i-K:i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
# B
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*(n+1)

for i in range(2, n+1):
    c_list = []
    if i-2 < k:
        for j in range(1, i):
            c_list.append(dp[i-j] + abs(h[i-1-j] - h[i-1]))
    else:
        for j in range(1,k+1):
            c_list.append(dp[i-j] + abs(h[i-1-j] - h[i-1]))
    dp[i] = min(c_list)
print(dp[-1])

Fixed submission:
# B
import numpy as np
N, K = map(int, input().split())
h = np.array(input().split(), dtype="int32")
dp = np.zeros(N, dtype="int32")
 
for i in range(1, N):
    if i < K:
        dp[i] = np.min(dp[:i] + np.abs(h[i]-h[:i]))
    else:
        dp[i] = np.min(dp[i-K:i] + np.abs(h[i]-h[i-K:i]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
# D

N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [[0] * (W+1) for _ in range(N)]
for i in range(N):
    for j in range(W+1):
        if j >= w[i]:
            dp[i][j] = max(dp[i-1][j-w[i]] + v[i], dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]

print(max(dp[-1]))

Fixed submission:
# D
import numpy as np
n,w = map(int, input().split())
 
items = list(map(int, input().split()) for _ in [0]*n)
dp = np.zeros(w+1, dtype='int64')
 
for weight, value in items:
    dp[weight:] = np.maximum(dp[weight:], dp[:w-weight+1] + value)
print(dp.max())
Buggy python submission (verdict: Time Limit Exceeded):
# C
N, K = map(int, input().split())
h = [0]*N
for i in range(N):
    h[i] = int(input())
h.sort()
result = 1e10
for i in range(N-K+1):
    h_list = h[i:i+K]
    result = min(result, max(h_list) - min(h_list))
print(result)

Fixed submission:
# C
N, K = map(int, input().split())
h = [0]*N
for i in range(N):
    h[i] = int(input())
h.sort()
result = 1e10
for i in range(N-K+1):
    result = min(result, h[i+K-1]-h[i])
print(result)
Buggy python submission (verdict: Runtime Error):
# D
N, X = map(int, input().split())
lv = [0]*(N+1)
lv[0] = 'P'
for i in range(1, len(lv)):
    lv[i] = 'B' + lv[i-1] + 'P' + lv[i-1] + 'B'
print(lv[N][-X:].count('P'))

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

a, p = [1], [1]
for i in range(n):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def f(n, x):
    if n == 0:
        if x <= 0:
            return 0
        else:
            return 1
    elif x <= 1 + a[n - 1]:
        return f(n-1, x-1)
    else:
        return p[n-1] + 1 + f(n-1, x-2-a[n-1])

print(f(n, x))
Buggy python submission (verdict: Runtime Error):
# C
from functools import reduce
from fractions import gcd
from functools import lru_cache

@lru_cache(None)
def lcm(a, b):
    return int(a*b/gcd(a, b))

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

result = 0
mod = reduce(lcm, a)-1

for i in range(len(a)):
    result += mod % a[i] 

print(int(result))

Fixed submission:
from functools import reduce
from fractions import gcd
N, X = map(int, input().split())
x = list(map(int, input().split()))
new_list = list(map(lambda l: abs(l - X), x))
new_list.sort()
gcd = reduce(gcd, new_list)
print(gcd)

Buggy python submission (verdict: Runtime Error):
from functools import reduce
import math
N, X = map(int, input().split())
x = list(map(int, input().split()))
new_list = list(map(lambda l: abs(l - X), x))
new_list.sort()
gcd = reduce(math.gcd, new_list)
print(gcd)

Fixed submission:
from functools import reduce
from fractions import gcd
N, X = map(int, input().split())
x = list(map(int, input().split()))
new_list = list(map(lambda l: abs(l - X), x))
new_list.sort()
gcd = reduce(gcd, new_list)
print(gcd)

Buggy python submission (verdict: Runtime Error):
import functools
import math
N, X = map(int, input().split())
x = list(map(int, input().split()))
new_list = list(map(lambda l: abs(l - X), x))
new_list.sort()
gcd = functools.reduce(math.gcd, new_list)
print(gcd)

Fixed submission:
from functools import reduce
from fractions import gcd
N, X = map(int, input().split())
x = list(map(int, input().split()))
new_list = list(map(lambda l: abs(l - X), x))
new_list.sort()
gcd = reduce(gcd, new_list)
print(gcd)

Buggy python submission (verdict: Runtime Error):
# C
import functools
import math

N, X = map(int, input().split())
x = list(map(int, input().split()))
new_list = list(map(lambda l: abs(l - X), x))
new_list.sort()
gcd = functools.reduce(math.gcd, new_list)
print(gcd)

Fixed submission:
from functools import reduce
from fractions import gcd
N, X = map(int, input().split())
x = list(map(int, input().split()))
new_list = list(map(lambda l: abs(l - X), x))
new_list.sort()
gcd = reduce(gcd, new_list)
print(gcd)

Buggy python submission (verdict: Runtime Error):
# C
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N, X = map(int, input().split())
x = list(map(int, input().split()))
new_list = list(map(lambda l: abs(l - X), x))
new_list.sort()
print(gcd(*new_list))

Fixed submission:
from functools import reduce
from fractions import gcd
N, X = map(int, input().split())
x = list(map(int, input().split()))
new_list = list(map(lambda l: abs(l - X), x))
new_list.sort()
gcd = reduce(gcd, new_list)
print(gcd)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline

n, m, q = map(int, input().split())

class TwoDimSum():
    def __init__(self, h, w):
        self.counts = [[0 for _ in range(w+1)] for _ in range(h+1)]
        self.s = [[0 for _ in range(w+1)] for _ in range(h+1)]

    def add_count(self, x, y):
        # 0-indexed
        self.counts[y+1][x+1] += 1

    def build(self):
        for i in range(h):
            for j in range(w):
                self.s[i+1][j+1] = self.s[i][j+1] + self.s[i+1][j] - self.s[i][j] + self.counts[i][j]

    def solve(self, x1, y1, x2, y2):
        return self.s[x2][y2] - self.s[x1][y2] - s[x2][y1] + s[x1][y1]

counts = TwoDimSum()
for _ in range(m):
    l, r = map(int, input().split())
    counts.add_count(l-1, r-1)
counts.build()

for i in range(q):
    x, y = map(int, input().split())
    ans.append(str(counts.solve(x, x, y, y)))
print("\n".join(ans))

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

n, m, q = map(int, input().split())

counts = [[0 for _ in range(n+1)] for _ in range(n+1)]
for _ in range(m):
    l, r = map(int, input().split())
    counts[l][r] += 1

s = [[0 for _ in range(n+1)] for _ in range(n+1)]
# 横方向
for i in range(n+1):
    v = 0
    for j in range(n+1):
        v += counts[i][j]
        s[i][j] = v
# 縦方向
cs = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(n+1):
    v = 0
    for j in range(n+1):
        v += s[j][i]
        cs[j][i] = v


ans = []
for i in range(q):
    p, q = map(int, input().split())
    t = 0
    for i in range(p, q+1):
        t += s[i][q] - s[i][p-1]
    ans.append(str(t))
print("\n".join(ans))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

left = [""] * (n - 2)
right = [""] * (n - 2)

for i in range(m):
    a, b = map(int, input().split())
    left[a - 1] = "["
    right[b - 2] = "]"

s = ""
for i in range(n):
    s += left[i]
    s += right[i]

count = 0
for i in range(len(s) - 1):
    if s[i:i+2] == "[]":
        count += 1
print(count)

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

N, M = (int(i) for i in input().split())
dic = {}
cnt = 0
pos = 0
for i in range(M):
    a, b = map(int, input().split())
    if b not in dic or dic[b] < a:
        dic[b] = a

for j in sorted(dic.keys()):
    if dic[j] >= pos:
        cnt += 1
        pos = j
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import statistics
n = int(input())
a = list(map(int, input().split()))
l = []
m = []
for i in range(n):
    m.append(a[i]-i)
for i in range(n):
    l.append(abs(a[i]-(int(statistics.median(m))+i)))
print(sum(l))

Fixed submission:
import statistics
n = int(input())
a = list(map(int, input().split()))
l = []
m = []
for i in range(n):
    m.append(a[i]-i)
med = int(statistics.median(m))
for i in range(n):
    l.append(abs(a[i]-(med+i)))
print(sum(l))
Buggy python submission (verdict: Runtime Error):
# C
n,k=map(int,input().split())
print((n+k-3)//(k-1))

Fixed submission:
# A
s = str(input())
result = 0
for c in list(s):
    if c == '+':
        result += 1
    else:
        result -= 1
print(result)
Buggy python submission (verdict: Runtime Error):
n = map(int, input())

if n >= 1000:
    print('ABD')
else:
    print('ABC')

Fixed submission:
n = int(input())

if n >= 1000:
    print('ABD')
else:
    print('ABC')
Buggy python submission (verdict: Time Limit Exceeded):
# C
import copy
import numpy as np
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    l = copy.copy(a)
    l.pop(i)
    print(sum(abs(np.array([0] + l) - np.array(l+[0]))))

Fixed submission:
import copy
import numpy as np
n = int(input())
a = list(map(int, input().split()))
S = sum(abs(np.array([0] + a) - np.array(a+[0])))
a = [0] + a + [0]
for i in range(1, len(a)-1):
    cost = S + abs(a[i-1] - a[i+1]) - (abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]))
    print(cost)
Buggy python submission (verdict: Time Limit Exceeded):
#D
n, k = map(int, input().split())
count = 0
for a in range(1, n+1):
    for b in range(1, n+1):
        if a % b >= k:
            count += 1
print(count)

Fixed submission:
#D
n,k = map(int,input().split())
s = 0
for b in range(k+1,n+1):
    s += n//b*(b-k) + max(n%b-max(k-1,0),0)
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
# D
h, w, d = map(int, input().split())
points = [[0]*2 for i in range(h*w + 1)]
for h_i in range(h):
    a_row = [int(i) for i in input().split()]
    for r_i, a in enumerate(a_row):
        points[a][0] = h_i
        points[a][1] = r_i

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    ans = 0
    while l != r:
        next_l = l + d
        ans += abs(points[l][0] - points[next_l][0]) + abs(points[l][1] - points[next_l][1])
        l = next_l
    print(ans)

Fixed submission:
# D
h, w, d = map(int, input().split())
points = [[0]*2 for i in range(h*w)]
cost = [0]* (h*w)
for h_i in range(h):
    a_row = [int(i) for i in input().split()]
    for r_i, a in enumerate(a_row):
        points[a-1][0] = h_i
        points[a-1][1] = r_i
for i in range(d, (h*w)):
    cost[i] = cost[i-d] + abs(points[i][0]-points[i-d][0]) + abs(points[i][1]-points[i-d][1])
q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(cost[r-1] - cost[l-1])
Buggy python submission (verdict: Runtime Error):
# C
n = int(input())
preX = [0,0,0]
ans = True
for i in range(n):
    curX = list(map(int, input().split()))
    time = 
    if not curX[0] - preX[0] >= (abs(curX[1] - preX[1]) + abs(curX[2] - preX[2])) and curX[0] - preX[0] % 2 == (abs(curX[1] - preX[1]) + abs(curX[2] - preX[2])) % 2:
        ans = False
if ans:
    print('Yes')
else:
    print('No')
            

Fixed submission:
import numpy as np

n = int(input())
input_X = [[int(i) for i in input().split()] for i in range(n)]
X = np.array(input_X)

pre_t = 0
pre_x = 0
pre_y = 0
for i in range(n):
    x_move = abs(X[i][1] - pre_x)
    y_move = abs(X[i][2] - pre_y)
    xy_sum = x_move + y_move
    spend_time = X[i][0]-pre_t
    if xy_sum%2 == spend_time%2 and spend_time >= xy_sum:
        pre_t = X[i][0]
        pre_x = X[i][1]
        pre_y = X[i][2]
        if i+1 == n:
            print('Yes')
        else:
            continue
    else:
        print('No')
        break
Buggy python submission (verdict: Runtime Error):
n, y = map(int, input().split())

ans = "-1 -1 -1"

for i in range(n+1):
    for j in range(n+1):
        if i + j > n:
            break
        k = n - i - j
        if 10000*i + 5000*j + 1000*k == y:
            ans = f"{i} {j} {k}"

print(ans)


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

num_10 = 0
num_5  = 0
num_1  = 0
none = True

for i in range(n+1):
    for j in range(n+1):
        k = n-i-j
        if (i*10000 + j*5000 + k*1000) == y and k >= 0:
            num_10 = i
            num_5 = j
            num_1 = k
            none = False
            break
    if none == False:
        break
if none:
    print('-1 -1 -1')
else:
    print("{} {} {}".format(num_10, num_5, num_1))
Buggy python submission (verdict: Runtime Error):
%%test_input https://atcoder.jp/contests/abc085/tasks/abc085_d
# D
import math
n, h = map(int, input().split())
max_a = 0
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
    if max_a < a[i]:
        max_a = a[i]
throw = []
for i in range(n):
    if b[i] > max_a:
        throw.append(b[i])
throw.sort(reverse=True)
damage = 0
count = 0
for i in range(len(throw)):
    damage += throw[i]
    count += 1
    if damage >= h:
        break
if damage < h:
    count += math.ceil((h - damage) / max_a)
print(count)

Fixed submission:
# D
import math
n, h = map(int, input().split())
max_a = 0
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
    if max_a < a[i]:
        max_a = a[i]
throw = []
for i in range(n):
    if b[i] > max_a:
        throw.append(b[i])
throw.sort(reverse=True)
damage = 0
count = 0
for i in range(len(throw)):
    damage += throw[i]
    count += 1
    if damage >= h:
        break
if damage < h:
    count += math.ceil((h - damage) / max_a)
print(count)
Buggy python submission (verdict: Runtime Error):
%%test_input https://atcoder.jp/contests/abc082/tasks/abc082_b
#B
import collections

s = str(input())
t = str(input())
sd = list(s)
td = list(t)
sd.sort()
td.sort(reverse=True)
a = ''
b = ''
for c in sd:
    a += c
for c in td:
    b += c
if sd < td:
    print('Yes')
else:
    print('No')

Fixed submission:
#B
import collections

s = str(input())
t = str(input())
sd = list(s)
td = list(t)
sd.sort()
td.sort(reverse=True)
a = ''
b = ''
for c in sd:
    a += c
for c in td:
    b += c
if sd < td:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
# B
n = int(input())
a = [int(i) for i in input().split()]
count = 0
flag = True
while flag:
    for i in range(len(a)):
        if a[i] % 2 == 0:
            continue
        else:
            flag  = False
            break
    a = map(lambda x: x / 2, a)
print(count)

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

def calc_half(n):
    return int(n / 2)

all_even = True
count = 0
while all_even:
    for value in a:
        if value % 2 == 1:
            all_even = False
            break
    if all_even:
        a = list(map(calc_half, a))
        count +=1
print(count)
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()

b_num = [0 for _ in range(len(b))]
for b_i in range(len(b)):
    c_i = bisect.bisect_right(c, b[b_i])
    b_num[b_i] = len(b) - c_i

ans = 0
for a_i in range(len(a)):
    b_i = bisect.bisect_right(b, a[a_i])
    for j in range(b_i, len(b_num)):
        ans += b_num[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()

b_num = [0 for _ in range(n)]
for b_i in range(n):
    c_i = bisect.bisect_right(c, b[b_i])
    b_num[b_i] = n - c_i

for i in range(1, len(b_num)):
    b_num[len(b_num) - 1 - i] += b_num[len(b_num) - i]

ans = 0
for a_i in range(len(a)):
    b_i = bisect.bisect_right(b, a[a_i])
    if b_i >= n:
        continue
    ans += b_num[b_i]
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()

b_num = [0 for _ in range(len(b))]
for b_i in range(len(b)):
    c_i = bisect.bisect_right(c, b[b_i])
    b_num[b_i] = len(b) - c_i

ans = 0
for a_i in range(len(a)):
    b_i = bisect.bisect_right(b, a[a_i])
    for j in range(b_i, len(b_num)):
        ans += b_num[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()

b_num = [0 for _ in range(n)]
for b_i in range(n):
    c_i = bisect.bisect_right(c, b[b_i])
    b_num[b_i] = n - c_i

for i in range(1, len(b_num)):
    b_num[len(b_num) - 1 - i] += b_num[len(b_num) - i]

ans = 0
for a_i in range(len(a)):
    b_i = bisect.bisect_right(b, a[a_i])
    if b_i >= n:
        continue
    ans += b_num[b_i]
print(ans)