Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = [int(input()) for _ in range(n)]
sort_a = list(np.sort(a))
sort_arg = np.argsort(a)
for i in range(n):
    tmp_l = sort_a[:]
    tmp_l.pop(sort_arg[i])
    print(tmp_l.pop(-1))

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
sort_a = sorted(a)
max_a = max(a)
max_ind = 0
for i in range(n):
    if a[i] == max_a: max_ind = i
for i in range(n):
    ans = max_a if i != max_ind else sort_a[-2]
    print(ans)

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

n = int(input())
a = [int(input()) for _ in range(n)]
sort_a = list(np.sort(a))
sort_arg = np.argsort(a)
for i in range(n):
    tmp_l = sort_a[:]
    tmp_l.pop(sort_arg[i])
    print(tmp_l.pop(-1))

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
sort_a = sorted(a)
max_a = max(a)
max_ind = 0
for i in range(n):
    if a[i] == max_a: max_ind = i
for i in range(n):
    ans = max_a if i != max_ind else sort_a[-2]
    print(ans)

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

n = int(input())
a = [int(input()) for _ in range(n)]
sort_a = list(np.sort(a))
#sort_arg = np.argsort(a)
for i in range(n):
    tmp_l = sort_a[:]
    tmp_l.remove(a[i])
    print(tmp_l.pop(-1))

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
sort_a = sorted(a)
max_a = max(a)
max_ind = 0
for i in range(n):
    if a[i] == max_a: max_ind = i
for i in range(n):
    ans = max_a if i != max_ind else sort_a[-2]
    print(ans)
Buggy python submission (verdict: Runtime Error):
import math
def count(n, m, l):
    c_m = n // m
    c_l = n // l
    c_ml = n // (m * l // math.gcd(m, l))
    return n - (c_m + c_l - c_ml)

a, b, c, d = map(int, input().split())
b_tar = count(b, c, d)
a_tar = count(a, c, d)
is_plus_a = not(bool(a % c == 0 or a % d == 0))
ans = b_tar - a_tar
if is_plus_a: ans += 1
print(ans)

Fixed submission:
import fractions

def main():
    a, b, c, d = map(int, input().split())
    l =  (c * d) // fractions.gcd(c, d)
    cntb = b - (b // c + b // d - b // l)
    cnta = (a-1) - ((a-1) // c + (a-1) // d - (a-1) // l)
    ans = cntb - cnta

    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import math
def count(n, m, l):
    c_m = n // m
    c_l = n // l
    c_ml = n // (m * l // math.gcd(m, l))
     return n - (c_m + c_l - c_ml)

a, b, c, d = map(int, input().split())
b_tar = count(b, c, d)
a_tar = count(a, c, d)
is_plus_a = not(a % c == 0 or a % d == 0)
ans = b_tar - a_tar
if is_plus_a: ans += 1
print(ans)

Fixed submission:
import fractions

def main():
    a, b, c, d = map(int, input().split())
    l =  (c * d) // fractions.gcd(c, d)
    cntb = b - (b // c + b // d - b // l)
    cnta = (a-1) - ((a-1) // c + (a-1) // d - (a-1) // l)
    ans = cntb - cnta

    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import math
def count(n, m, l):
    c_m = n // m
    c_l = n // l
    c_ml = n // (m * l // math.gcd(m, l))
    return n - (c_m + c_l - c_ml)

a, b, c, d = map(int, input().split())
b_tar = count(b, c, d)
a_tar = count(a, c, d)
is_plus_a = not(a % c == 0 or a % d == 0)
ans = b_tar - a_tar
if is_plus_a: ans += 1
print(ans)

Fixed submission:
import fractions

def main():
    a, b, c, d = map(int, input().split())
    l =  (c * d) // fractions.gcd(c, d)
    cntb = b - (b // c + b // d - b // l)
    cnta = (a-1) - ((a-1) // c + (a-1) // d - (a-1) // l)
    ans = cntb - cnta

    print(ans)

if __name__ == '__main__':
    main()

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


def main():
    a, b, c, d = map(int, input().split())
    l =  (c * d) // math.gcd(c, d)
    cntb = b - (b // c + b // d - b // l)
    cnta = (a-1) - ((a-1) // c + (a-1) // d - (a-1) // l)
    ans = cntb - cnta

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import fractions

def main():
    a, b, c, d = map(int, input().split())
    l =  (c * d) // fractions.gcd(c, d)
    cntb = b - (b // c + b // d - b // l)
    cnta = (a-1) - ((a-1) // c + (a-1) // d - (a-1) // l)
    ans = cntb - cnta

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    W, H, x, y = map(int, f.input().split())
    ans = W * H / 2
    num = 1 if (2*x == W and 2*y == H) else 0
    print(ans, num)

  
if __name__ == '__main__':
    main()


Fixed submission:
def main():
    W, H, x, y = map(int, input().split())
    ans = W * H / 2
    num = 1 if (2*x == W and 2*y == H) else 0
    print(ans, num)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    with open('./input/input.txt') as f:
        W, H, x, y = map(int, f.input().split())
    ans = W * H / 2
    num = 1 if (2*x == W and 2*y == H) else 0
    print(ans, num)

  
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    W, H, x, y = map(int, input().split())
    ans = W * H / 2
    num = 1 if (2*x == W and 2*y == H) else 0
    print(ans, num)
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n, m = LI()
a = LI()
a = sorted(a)[::-1]
bc = LIR(m)

bc = sorted(bc, key=lambda x: x[1])[::-1]
all_c = []
for bi, ci in bc:
    all_c += [ci] * bi
if len(all_c) < n:
    all_c += [0] * (n - len(all_c))
ans = 0
a_i = 0
c_i = 0
for _ in range(n):
    if a[a_i] > all_c[c_i]:
        ans += a[a_i]
        a_i += 1
    else:
        ans += all_c[c_i]
        c_i += 1
print(ans)


Fixed submission:
import bisect
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n, m = LI()
a = LI()
a = sorted(a)[::-1]
bc = LIR(m)
bc = sorted(bc, key=lambda x: x[1])[::-1]
all_c = []
for bi, ci in bc:
    all_c += [ci] * bi
    if len(all_c) >= n:
        break
if len(all_c) < n:
    all_c += [0] * (n - len(all_c))

ans = 0
a_i = 0
c_i = 0
for _ in range(n):
    if a[a_i] > all_c[c_i]:
        ans += a[a_i]
        a_i += 1
    else:
        ans += all_c[c_i]
        c_i += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict, deque
import sys

INF = float('inf')
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


b = S()
ans = 'T' if b == 'A' else 'A' if b == 'T' else 'C' if b == 'G' else 'C' if b == 'G'
print(ans)


Fixed submission:
from collections import defaultdict, deque
import sys

INF = float('inf')
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


b = S()
ans = 'T' if b == 'A' else 'A' if b == 'T' else 'C' if b == 'G' else 'G'
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
s = list(sys.stdin.readline())
n = len(s)
cntd = {'0':0, '1':0}
for i in range(n):
    cntd[s[i]] += 1
ans = 2 * min(cntd.values())
print(ans)

Fixed submission:
s = list(input())
n = len(s)
cntd = {'0':0, '1':0}

for i in range(n):
    cntd[s[i]] += 1
ans = 0
ans = 2 * min(cntd.values())
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
*s, = sys.stdin.readline()
n = len(s)
cntd = {'0':0, '1':0}

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

ans = 2 * min(cntd.values())
print(ans)

Fixed submission:
s = list(input())
n = len(s)
cntd = {'0':0, '1':0}

for i in range(n):
    cntd[s[i]] += 1
ans = 0
ans = 2 * min(cntd.values())
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
*s, = sys.stdin.readline()
n = len(s)
cntd = {'0':0, '1':0}
for i in range(n):
    cntd[s[i]] += 1
ans = 2 * min(cntd.values())
print(ans)

Fixed submission:
s = list(input())
n = len(s)
cntd = {'0':0, '1':0}

for i in range(n):
    cntd[s[i]] += 1
ans = 0
ans = 2 * min(cntd.values())
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
*s, = sys.stdin.readline()
n = len(s)
cntd = {'0':0, '1':0}
for i in range(n):
    cntd[s[i]] += 1
ans = 2 * min(cntd.values())
print(ans)

Fixed submission:
s = list(input())
n = len(s)
cntd = {'0':0, '1':0}

for i in range(n):
    cntd[s[i]] += 1
ans = 0
ans = 2 * min(cntd.values())
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import math
f = sys.stdin
n = int(f.readline())
a = list(map(int, f.readline().split()))
a.sort()
gcd = math.gcd(a[0], a[1])
print(gcd)

Fixed submission:
import sys
import fractions
import functools
f = sys.stdin
n = int(f.readline())
a = list(map(int, f.readline().split()))
gcd = functools.reduce(fractions.gcd, a)
print(gcd)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
n, k = map(int, sys.stdin.readline().strip('\n').split())
h = list(map(int, sys.stdin.readline().strip('\n').split()))
dp = [float('inf') for _ in range(n)]
dp[0] = 0
for i in range(1, n):
  for j in range(k+1):
    if i-j>=0: dp[i] = min(dp[i], dp[i-j] + abs(h[i-j]-h[i]))
print(dp[n-1])

Fixed submission:
import sys
n, k = map(int, sys.stdin.readline().strip('\n').split())
h = list(map(int, sys.stdin.readline().strip('\n').split()))
dp = [float('inf') for _ in range(n)]
dp[0] = 0
for i in range(1, n):
  for j in range(k+1):
    if i-j>=0: dp[i] = min(dp[i], dp[i-j] + abs(h[i-j]-h[i]))
print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
# 02
import sys
import math


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, m = LI()
s = S()
t = S()

gcd = math.gcd(n, m)
l = n * m // gcd
d_s = l // n
d_t = l // m
x = list('*' * l)
is_ok = True

for i in range(n):
    x[d_s * i] = s[i]

for i in range(m):
    if x[d_t * i] != '*':
        if x[d_t * i] != t[i]:
            is_ok = False
            break
    else:
        x[d_t * i] = t[i]

if is_ok:
    ans = len(x)
    print(ans)
else:
    print(-1)


Fixed submission:
# 02
import sys
import math


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, m = LI()
s = S()
t = S()

gcd = math.gcd(n, m)
lcm = n * m // gcd
i_s = n // gcd
i_t = m // gcd
for i in range(gcd):
    if s[i*i_s] != t[i*i_t]:
        print(-1)
        exit()
print(lcm)

Buggy python submission (verdict: Runtime Error):
# 02
import sys
import math


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, m = LI()
s = S()
t = S()

gcd = math.gcd(n, m)
l = n * m // gcd
d_s = l // n
d_t = l // m

x = list('*' * l)
is_ok = True
for i in range(n):
    x[d_s * i] = s[i]
for i in range(m):
    if x[d_t * i] != '*' and x[d_t * i] != t[i]:
        is_ok = False
        break
    x[d_t * i] = t[i]
if is_ok:
    ans = len(x)
    print(ans)
else:
    print(-1)


Fixed submission:
# 02
import sys
import math


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, m = LI()
s = S()
t = S()

gcd = math.gcd(n, m)
lcm = n * m // gcd
i_s = n // gcd
i_t = m // gcd
for i in range(gcd):
    if s[i*i_s] != t[i*i_t]:
        print(-1)
        exit()
print(lcm)
Buggy python submission (verdict: Runtime Error):
import collections
n = int(input())
*v, = map(int, input().split())
v_even, v_odd = [v[i] for i in range(n) if i % 2 == 0], [v[i] for i in range(n) if i % 2 != 0]

counter_even = collections.Counter(v_even)
counter_odd = collections.Counter(v_odd)

count_even = sorted(counter_even.items(), key=lambda x:x[1], reverse=True)
print(count_even)
count_odd = sorted(counter_odd.items(), key=lambda x:x[1], reverse=True)
print(count_odd)

if len(counter_even) == 1 and len(counter_odd) == 1:
    if count_even[0][0] != count_odd[0][0]:
        ans = 0
    else:
        ans1 = 0
        for i in range(n // 2):
            if v_even[i] != count_even[1][0]:
                v_even[i] = count_even[1][0]
                ans1 += 1
            
            if v_odd[i] != count_odd[0][0]:
                v_odd[i] = count_odd[0][0]
                ans1 += 1
    
        ans2 = 0
        for i in range(n // 2):
            if v_even[i] != count_even[0][0]:
                v_even[i] = count_even[0][0]
                ans2 += 1
            
            if v_odd[i] != count_odd[1][0]:
                v_odd[i] = count_odd[1][0]
                ans2 += 1
                
        ans = min(ans1, ans2)

else:
    ans = 0 
    for i in range(n // 2):
        if v_even[i] != count_even[0][0]:
            v_even[i] = count_even[0][0]
            ans += 1
        
        if v_odd[i] != count_odd[0][0]:
            v_odd[i] = count_odd[0][0]
            ans += 1

print(ans)

Fixed submission:
from collections import Counter
n = int(input())
*v, = map(int, input().split())
v_even, v_odd = v[::2], v[1::2]
even = Counter(v_even).most_common(2)
odd = Counter(v_odd).most_common(2)

ans = 0

if even[0][0] != odd[0][0]:
    ans = n - odd[0][1] - even[0][1]

else:
    if len(even) == 1 and len(odd) == 1:
        ans = n // 2
        
    elif len(even) == 1:
        ans = n - even[0][1] - odd[1][1]
        
    elif len(odd) == 1:
        ans = n - even[1][1] - odd[0][1]
        
    else:
        ans = min(n - even[0][1] - odd[1][1], 
                  n - even[1][1] - odd[0][1])
                  
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
lengh = 0
ans = '1'
for i in list(s):
    if i != '1':
        ans = i
        break
if k <= len(s) and s[k-1] == '1': ans = s['k-1']
print(ans)

Fixed submission:
s = input()
k = int(input())
lengh = 0
ans = '1'
flag = True
for i in list(s):
    if i != '1':
        ans = i
        break
if k <= len(s):
    for i in list(s)[:k]:
        if i == '1': continue
        flag = False
        break
    if flag: ans = s[k-1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
s = SR(n)

name_h = tuple([name[0] for name in s if name[0] in {'M', 'A', 'R', 'C', 'H'}])

ans = list(itertools.combinations(name_h, 3))
ans = len([a for a in ans if len(set(a)) == 3])

print(ans)


Fixed submission:
from collections import defaultdict
from itertools import combinations
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
s = SR(n)
d = defaultdict(int)
for c in ['M', 'A', 'R', 'C', 'H']:
    d[c] = 0
for name in s:
    if name[0] in {'M', 'A', 'R', 'C', 'H'}:
        d[name[0]] += 1
combs = list(combinations(['M', 'A', 'R', 'C', 'H'], 3))

ans = 0
for c in combs:
    ans += d[c[0]] * d[c[1]] * d[c[2]]
print(ans)
Buggy python submission (verdict: Runtime Error):
def test():
    nums = list(map(int, list(input())))
    for i in range(2 ** 3):
        ans = nums[0]
        res = '{}'.format(nums[0])
        for j in range(3):
            if (i >> j) & 1:
                ans += nums[j+1]
                res += '+{}'.format(nums[j+1])
            else:
                ans -= nums[j+1]
                res += '-{}'.format(nums[j+1])
        if ans == 7:
            print('{}=7'.format(res))
            exit(1)

if __name__ == '__main__':
    test()

Fixed submission:
def test():
    nums = list(map(int, list(input())))
    end = False
    for i in range(2 ** 3):
        ans = nums[0]
        res = '{}'.format(nums[0])
        for j in range(3):
            if (i >> j) & 1:
                ans += nums[j+1]
                res += '+{}'.format(nums[j+1])
            else:
                ans -= nums[j+1]
                res += '-{}'.format(nums[j+1])
        if ans == 7:
            end = True
            break
    print('{}=7'.format(res))

if __name__ == '__main__':
    test()

Buggy python submission (verdict: Runtime Error):
def test():
    nums = list(map(int, list(input())))
    for i in range(2 ** 3):
        ans = nums[0]
        res = f'{nums[0]}'
        for j in range(3):
            if (i >> j) & 1:
                ans += nums[j+1]
                res += f'+{nums[j+1]}'
            else:
                ans -= nums[j+1]
                res += f'-{nums[j+1]}'
        if ans == 7:
            print(f'{res}=7')
            exit(1)

if __name__ == '__main__':
    test()

Fixed submission:
def test():
    nums = list(map(int, list(input())))
    end = False
    for i in range(2 ** 3):
        ans = nums[0]
        res = '{}'.format(nums[0])
        for j in range(3):
            if (i >> j) & 1:
                ans += nums[j+1]
                res += '+{}'.format(nums[j+1])
            else:
                ans -= nums[j+1]
                res += '-{}'.format(nums[j+1])
        if ans == 7:
            end = True
            break
    print('{}=7'.format(res))

if __name__ == '__main__':
    test()
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


def main():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    a.sort()
    b.sort()
    c.sort()
    ans = 0
    for bi in b:
        a_ind = bisect.bisect_left(a, bi)
        a_oks = a[:a_ind]
        c_ind = bisect.bisect_right(c, bi)
        c_oks = c[c_ind:]
        ans += len(a_oks) * len(c_oks)
    print(ans)


main()


Fixed submission:
import bisect
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


def main():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    a.sort()
    b.sort()
    c.sort()
    ans = 0
    for bi in b:
        num_a = bisect.bisect_left(a, bi)
        num_c = n - bisect.bisect_right(c, bi)
        ans += num_a * num_c
    print(ans)


main()

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


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


def is_ok(l, i, key):
    if l[i] > key:
        return True


def binary_seach(l, key):
    left = -1
    right = len(l)

    while right - left > 1:
        mid = left + (right - left) // 2
        if is_ok(l, mid, key):
            right = mid
        else:
            left = mid

    return right


def main():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    a.sort()
    b.sort()
    c.sort()
    ans = 0
    # すべてのaに対して条件を満たすbを探索(O(N) * O(log N))
    for ai in a:
        b_ind = binary_seach(b, ai)
        ok_b = b[b_ind:]
       # そのbに対して条件を満たすcを探索(O(log N))
        for bi in ok_b:
            c_ind = binary_seach(c, bi)
            ok_c = c[c_ind:]
            ans += len(ok_c)
    print(ans)


main()


Fixed submission:
import bisect
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


def main():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    a.sort()
    b.sort()
    c.sort()
    ans = 0
    for bi in b:
        num_a = bisect.bisect_left(a, bi)
        num_c = n - bisect.bisect_right(c, bi)
        ans += num_a * num_c
    print(ans)


main()
Buggy python submission (verdict: Time Limit Exceeded):
# 15
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
d = LI()
m = I()
t = LI()
d.sort()
t.sort()
ans = 'YES'
i = 0
for elem in d:
    # print(elem, t[0])
    if t[0] == elem:
        t.pop(0)
    if len(t) == 0:
        break
if len(t) != 0:
    ans = 'NO'
print(ans)


Fixed submission:
# 15
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
d = LI()
m = I()
t = LI()
d.sort()
t.sort()
c_t = Counter(t)
c_d = Counter(d)
# print(c_t.items())
# print(c_d.items())
ans = 'YES'
i = 0
c_d = dict([(k, v) for k, v in c_d.items() if k in c_t.keys()])
if len(c_d) != len(c_t):
    ans = 'NO'
    print(ans)
    exit()
for (k_t, v_t), (k_d, v_d) in zip(c_t.items(), c_d.items()):
    if v_t > v_d:
        ans = 'NO'
        break
print(ans)