Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N=int(input())
T,A=map(int,input().split())
mylist=list(map(int,input().split()))
ans=[abs(A-(T-x*0.006)) for x in mylist]
print(ans.index(min(mylist))+1)



Fixed submission:
N=int(input())
T,A=map(int,input().split())
mylist=list(map(int,input().split()))
mymin=10**6
index=0

for i in range(N):
  if(mymin>abs(A-(T-0.006*mylist[i]))):
    mymin=abs(A-(T-0.006*mylist[i]))
    index=i
print(index+1)

Buggy python submission (verdict: Runtime Error):
N=int(input())
T,A=map(int,input().split())
mylist=list(map(int,input().split()))
min=T
index=0

for i in range(N):
  if(min>abs(T-0.006*mylist[i])):
    min=mylist
    index=i
print(index)


Fixed submission:
N=int(input())
T,A=map(int,input().split())
mylist=list(map(int,input().split()))
mymin=10**6
index=0

for i in range(N):
  if(mymin>abs(A-(T-0.006*mylist[i]))):
    mymin=abs(A-(T-0.006*mylist[i]))
    index=i
print(index+1)
Buggy python submission (verdict: Runtime Error):
n=input()
a=list(map(int,input().split()))

Max=0
Min=10**9

for i in range(n):
  if(Max<a[i]):
    Max=a[i]
  if(min>a[i]):
    Min=a[i]

print(abs(Max-Min))

Fixed submission:
n=int(input())
mylist=list(map(int,input().split()))
mymax=max(mylist)
mymin=min(mylist)
print(abs(mymax-mymin))

Buggy python submission (verdict: Runtime Error):
n=input()
a=list(map(int,input().split()))

Max=0
Min=10**9

for i in a:
  if(Max<i):
    Max=i
  if(min>i):
    Min=i
print(abs(Max-Min))

Fixed submission:
n=int(input())
mylist=list(map(int,input().split()))
mymax=max(mylist)
mymin=min(mylist)
print(abs(mymax-mymin))

Buggy python submission (verdict: Runtime Error):
N=int(input())
mylist=list(map(int,input().split))
mymax=max(mylist)
mymin=min(mylist)
print(abs(mymax-mymin))



Fixed submission:
n=int(input())
mylist=list(map(int,input().split()))
mymax=max(mylist)
mymin=min(mylist)
print(abs(mymax-mymin))
Buggy python submission (verdict: Time Limit Exceeded):
n = input()
a = list(map(int, input().split()))
cut=0
 
while all(i%2==0 for i in a):
  list=[i/2 for i in a]
  cut+=1
print(cut)



Fixed submission:
n = input()
a = list(map(int, input().split()))
cnt = 0
while all(i%2==0 for i in a):
    a = [i/2 for i in a]
    cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = input()
a = list(map(int, input().split()))
cut=0
 
while all(i%2==0 for i in a):
  list=[i/2 for i in a]
  cut+=1
print(cut)

Fixed submission:
n = input()
a = list(map(int, input().split()))
cnt = 0
while all(i%2==0 for i in a):
    a = [i/2 for i in a]
    cnt += 1
print(cnt)

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

while(all(i%2==0 for i in a)):
  list=[i/2 for i in a]
  cut+=1
print(cut)

Fixed submission:
n = input()
a = list(map(int, input().split()))
cnt = 0
while all(i%2==0 for i in a):
    a = [i/2 for i in a]
    cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
import itertools import product
a=list(map(str,input().split()))

for b in product(["+","-"],repeat=3):
  if(eval(a[0]+b[0]+a[1]+b[1]+a[2]+b[2]+a[3])==7):
    print(str(a[0]+b[0]+a[1]+b[1]+a[2]+b[2]+a[3]=7))
    break:
      

Fixed submission:
from itertools import product
a=list(input())

for b in product(["+","-"],repeat=3):
  if(eval(a[0]+b[0]+a[1]+b[1]+a[2]+b[2]+a[3])==7):
    print(str(a[0]+b[0]+a[1]+b[1]+a[2]+b[2]+a[3]+"=7"))
    break
Buggy python submission (verdict: Runtime Error):
n=int(input)
i=1
while i*2<=n:
  i*=2
print(i)
    

Fixed submission:
n=int(input())
i=1
while i*2<=n:
  i*=2
print(i)

Buggy python submission (verdict: Runtime Error):
n=input()
maxn=0
maxcount=0
 
for i in range(n+1):
  count=0
  now=i
  while n%2==0:
    now=now/2
    count+=1
  if maxcount < count:
    maxn=now
    maxcount=count
 
print(maxn)

Fixed submission:
n=int(input())
i=1
while i*2<=n:
  i*=2
print(i)

Buggy python submission (verdict: Runtime Error):
n=input()
maxn=0
maxcount=0
 
for i in range(n+1):
  count=0
  while n%2==0:
    n=n/2
    count+=1
  if maxcount < count:
    maxn=i
    maxcount=count
 
print(maxn)

Fixed submission:
n=int(input())
i=1
while i*2<=n:
  i*=2
print(i)

Buggy python submission (verdict: Runtime Error):
n=input()
maxn=0
maxccount=0

for i in range(n+1):
  count=0
  while n%2==0:
    n=n/2
    count+=1
  if maxcount < count:
    maxn=i
    maxcount=count

print(maxn)
    

Fixed submission:
n=int(input())
i=1
while i*2<=n:
  i*=2
print(i)

Buggy python submission (verdict: Runtime Error):
n=input()
maxn=0
maxccount=0

for i in range(n+1):
  count=0
  while n-i%2==0:
    n=n/2
    count+=1
  if maxcount < count:
    maxn=i
    maxcount=count

print(maxn)
    

Fixed submission:
n=int(input())
i=1
while i*2<=n:
  i*=2
print(i)
Buggy python submission (verdict: Runtime Error):
input()
A = list(map(int, input().split())).sort(reverse=True)
print(sum([A[i] * ((-1) ** (i % 2)) for i in range(len(A))]))

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

A.sort(reverse=True)
print(sum([A[i] for i in range(len(A)) if i % 2 == 0]) - sum([A[i] for i in range(len(A)) if i % 2 == 1]))
Buggy python submission (verdict: Runtime Error):


v = map(int, input().split())

if (v[0] * v[1]) % 2 == 0:
    print('Even')
else
    print('Odd')


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

if (v[0] * v[1]) % 2 == 0:
    print('Even')
else:
    print('Odd')
Buggy python submission (verdict: Runtime Error):
i = input().rstrip()

T = ['dreamer', 'dream', 'eraser', 'erase']

def exec(s):
    for t in T:
        if s.startswith(t):
            n = s.replace(t, '', 1)
            if len(n) == 0:
                print('YES')
                exit()
            else:
                exec(n)

exec(i)
print('NO')

Fixed submission:
i = input()[::-1]
T = []
for t in ['dreamer', 'dream', 'eraser', 'erase']:
    T.append(t[::-1])

match = True
while match:
    match = False
    for t in T:
        if i.startswith(t):
            match = True
            i = i.replace(t, '', 1)
            if len(i) < 1:
                print('YES')
                exit()

print('NO')

Buggy python submission (verdict: Runtime Error):
i = input()

T = ['dreamer', 'dream', 'eraser', 'erase']

def exec(s):
    for t in T:
        if s.startswith(t):
            n = s.replace(t, '', 1)
            if len(n) == 0:
                print('YES')
                exit()
            else:
                exec(n)

exec(i)
print('NO')

Fixed submission:
i = input()[::-1]
T = []
for t in ['dreamer', 'dream', 'eraser', 'erase']:
    T.append(t[::-1])

match = True
while match:
    match = False
    for t in T:
        if i.startswith(t):
            match = True
            i = i.replace(t, '', 1)
            if len(i) < 1:
                print('YES')
                exit()

print('NO')

Buggy python submission (verdict: Runtime Error):
i = input()

T = ['dreamer', 'dream', 'eraser', 'erase']

ans = False

def exec(s):
    for t in T:
        if s.startswith(t):
            n = s.replace(t, '', 1)
            if len(n) == 0:
                print('YES')
                exit()
            else:
                exec(n)

exec(i)
print('NO')

Fixed submission:
i = input()[::-1]
T = []
for t in ['dreamer', 'dream', 'eraser', 'erase']:
    T.append(t[::-1])

match = True
while match:
    match = False
    for t in T:
        if i.startswith(t):
            match = True
            i = i.replace(t, '', 1)
            if len(i) < 1:
                print('YES')
                exit()

print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque, Counter, defaultdict
from itertools import permutations
import heapq


def resolve():
    N = int(sys.stdin.readline().strip())
    pq = []
    for _ in range(N):
        X, L = map(int, sys.stdin.readline().strip().split())
        heapq.heappush(pq, (X + L, X - L))
    ans = 0
    while pq:
        ans += 1
        right, _ = heapq.heappop(pq)
        if pq:
            _, next_left = min(pq)
            while next_left < right:
                heapq.heappop(pq)
                if not pq:
                    break
                _, next_left = min(pq)

    print(ans)


if __name__ == "__main__":
    resolve()


Fixed submission:
import sys
from collections import deque, Counter, defaultdict
from itertools import permutations
import heapq


def resolve():
    N = int(sys.stdin.readline().strip())
    pq = []
    for _ in range(N):
        X, L = map(int, sys.stdin.readline().strip().split())
        heapq.heappush(pq, (X + L, X - L))
    ans = 0
    while pq:
        ans += 1
        right, _ = heapq.heappop(pq)
        if pq:
            _, next_left = pq[0]
            while next_left < right:
                heapq.heappop(pq)
                if not pq:
                    break
                _, next_left = pq[0]

    print(ans)


if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import math

H, W = map(int, input().split())
C = [list(input()) for _ in range(H)]

move = ((1, 0), (-1, 0), (0, 1), (0, -1))
visited = [['.'] * W for _ in range(H)]
ideal = [['#'] * W for _ in range(H)]
c_max = 0

def bfs(S):
    global visited
    global c_max
    c = 0

    for s in S:
        visited[s[0]][s[1]] = '#'
    que_init = [(s[0], s[1], 0) for s in S]
    que = deque(que_init)

    while que:
        if ideal == visited:
            return c_max

        ci, cj, c = que.popleft()
        for di, dj in move:
            ni, nj = ci + di, cj + dj
            if 0 <= ni < H and 0 <= nj < W and visited[ni][nj] == '.' and C[ni][nj] != '#':
                visited[ni][nj] = '#'
                c_max = max(c_max, c+1)
                que.append((ni, nj, c+1))
    return 0


sg = []
ans = 0
for h in range(H):
    for w in range(W):
        if C[h][w] == '#':
            sg.append((h,w))

ans = bfs(sg)
print(ans)

Fixed submission:
import numpy as np

H, W = map(int, input().split())
grid = (np.array([list(input())
                  for _ in range(H)]) == "#")
cost = np.full((H, W), 10 ** 9, dtype=np.int64)
cost[grid[:, :]] = 0

for i in range(1, H):
    cost[i] = np.minimum(cost[i], cost[i - 1] + 1)

for i in range(H - 2, -1, -1):
    cost[i] = np.minimum(cost[i], cost[i + 1] + 1)

for i in range(1, W):
    cost[:, i] = np.minimum(cost[:, i], cost[:, i - 1] + 1)

for i in range(W - 2, -1, -1):
    cost[:, i] = np.minimum(cost[:, i], cost[:, i + 1] + 1)

print(np.max(cost))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
islands = [map(int, input().split()) for _ in range(M)]
islands.sort()

cnt = 0
last = -float('inf')
for left, right in islands:
    if last <= left:
        cnt += 1
        last = right

print(cnt)


Fixed submission:
N, M = map(int, input().split())
islands = [tuple(map(int, input().split())) for _ in range(M)]
islands.sort()

cnt = 0
l = 1
r = N
for left, right in islands:
    if r <= left:
        cnt += 1
        l = left
        r = right
    else:
        l = max(l, left)
        r = min(r, right)

print(cnt+1)
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    s = input()s
    if n % 2 == 0:
        s1 = s[:(n//2)]
        s2 = s[n//2:]
        if s1 == s2:
            print("Yes")
        else:
            print("No")
    else:
        print("No")



if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    s = input()
    if n % 2 == 0:
        s1 = s[:(n//2)]
        s2 = s[n//2:]
        if s1 == s2:
            print("Yes")
        else:
            print("No")
    else:
        print("No")



if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
INF = float("inf") #const
MOD = 10**9+7 #const
MAX = 510000 #const

def repeat(n,p):
    if p == 0:
        return 1
    if p%2==0:
        t = repeat(n,p//2)
        return t * t % MOD
    return n * repeat(n,p-1) % MOD


def com(n,r):
    if n < r or n < 0:
        return 0
    if n == 0 and r == 0:
        return 1
    fact = [0] * (n+1)
    fact[0] = 1
    for i in range(n):
        fact[i+1] = fact[i] * (i+1) % MOD #階乗計算
    f_inv = repeat(fact[r],MOD-2)
    f = repeat(fact[n-r],MOD-2)

    return fact[n] * f_inv * f % MOD


def main():
    x,y = map(int,input().split())
    if (x+y)%3 != 0:
        print(0)
        return
    n = (2*y - x)//3
    m = (2*x - y)//3
    print(com(n+m,n))


if __name__ == "__main__":
    main()


Fixed submission:
INF = float("inf") #const
MOD = 10**9+7 #const
MAX = 510000 #const

def repeat(n,p):
    if p == 0:
        return 1
    if p%2==0:
        t = repeat(n,p//2)
        return t * t % MOD
    return n * repeat(n,p-1) % MOD


def com(n,r):
    if n < r or n < 0:
        return 0
    if n == 0 and r == 0:
        return 1
    fact = [0] * (10**6+1)
    fact[0] = 1
    for i in range(n):
        fact[i+1] = fact[i] * (i+1) % MOD #階乗計算
    f_inv = repeat(fact[r],MOD-2)
    f = repeat(fact[n-r],MOD-2)
    return fact[n] * f_inv * f % MOD


def main():
    x,y = map(int,input().split())
    if (x+y)%3 != 0:
        print(0)
        return
    n = (2*y - x)//3
    m = (2*x - y)//3
    print(com(n+m,n))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
MOD = 10**9+7 #const

def repeat(n,p):
    if p == 0:
        return 1
    if p%2==0:
        t = repeat(n,p//2)
        return t * t % MOD
    return n * repeat(n,p-1) % MOD


def com(n,r):
    if n < r or n < 0:
        return 0
    if n == 0 and r == 0:
        return 1
    fact = [0] * (n+1)
    fact[0] = 1
    for i in range(n):
        fact[i+1] = fact[i] * (i+1) % MOD #階乗計算
    f_inv = repeat(fact[r],MOD-2)
    f = repeat(fact[n-r],MOD-2)

    return fact[n] * f_inv * f % MOD


def main():
    x,y = map(int,input().split())
    if (x+y)%3 != 0:
        print(0)
    n = (2*y - x)//3
    m = (2*x - y)//3
    print(com(n+m,n))


if __name__ == "__main__":
    main()


Fixed submission:
INF = float("inf") #const
MOD = 10**9+7 #const
MAX = 510000 #const

def repeat(n,p):
    if p == 0:
        return 1
    if p%2==0:
        t = repeat(n,p//2)
        return t * t % MOD
    return n * repeat(n,p-1) % MOD


def com(n,r):
    if n < r or n < 0:
        return 0
    if n == 0 and r == 0:
        return 1
    fact = [0] * (10**6+1)
    fact[0] = 1
    for i in range(n):
        fact[i+1] = fact[i] * (i+1) % MOD #階乗計算
    f_inv = repeat(fact[r],MOD-2)
    f = repeat(fact[n-r],MOD-2)
    return fact[n] * f_inv * f % MOD


def main():
    x,y = map(int,input().split())
    if (x+y)%3 != 0:
        print(0)
        return
    n = (2*y - x)//3
    m = (2*x - y)//3
    print(com(n+m,n))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def test():
    n = int(input())
    a = [int(input()) for i in range(n)]
    s = 0
    for i in range(n):
        s = a[i]
        a[i] = 0
        print(max(a))
        a[i] = s


if __name__ == "__main__":
    test()


Fixed submission:
def test():
    n = int(input())
    s = 0; t = 0; index_ = 0
    for i in range(n):
        a = int(input())
        if s < a:
            index_ = i
            s = a
        elif t < a and a <= s:
            t = a
    for i in range(n):
        if index_ == i:
            print(t)
        else:
            print(s)


if __name__ == "__main__":
    test()
Buggy python submission (verdict: Time Limit Exceeded):
def test():
    n,q = map(int,input().split())
    s = input()
    l = []
    for i in range(q):
        l.append(list(map(int,input().split())))
    for i in range(q):
        print(s[l[i][0]-1:l[i][1]].count("AC"))


if __name__ == "__main__":
    test()


Fixed submission:
def test():
    n,q = map(int,input().split())
    s = input()
    t = [0] * (n+1)
    for i in range(n):
        t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)
    for i in range(q):
        l,r = map(int,input().split())
        print(t[r-1]-t[l-1])


if __name__ == "__main__":
    test()
Buggy python submission (verdict: Runtime Error):
import math

def test():
    n = int(input())
    a = list(map(int,input().split()))
    ans = a[0]
    for i in a:
        ans = math.gcd(ans,i)
    print(ans)


if __name__ == "__main__":
    test()


Fixed submission:
import fractions

def test():
    n = int(input())
    a = list(map(int,input().split()))
    ans = a[0]
    for i in a:
        ans = fractions.gcd(ans,i)
    print(ans)


if __name__ == "__main__":
    test()

Buggy python submission (verdict: Runtime Error):
import numpy as np

def test():
    n = int(input())
    a = np.array(list(map(int,input().split())))
    if all(x%a.min() == 0 for x in a):
        print(a.min())
    else:
        a = sorted(list(set(a//a.min())))
        print(a[1]-a[0])


if __name__ == "__main__":
    test()


Fixed submission:
import fractions

def test():
    n = int(input())
    a = list(map(int,input().split()))
    ans = a[0]
    for i in a:
        ans = fractions.gcd(ans,i)
    print(ans)


if __name__ == "__main__":
    test()

Buggy python submission (verdict: Runtime Error):
import numpy as np

def test():
    n = int(input())
    a = np.array(list(map(int,input().split())))
    if all(x%a.min() == 0 for x in a):
        print(a.min())
    else:
        a = sorted(list(set(a//a.min())))
        print(a[1]-a[0])


if __name__ == "__main__":
    test()


Fixed submission:
import fractions

def test():
    n = int(input())
    a = list(map(int,input().split()))
    ans = a[0]
    for i in a:
        ans = fractions.gcd(ans,i)
    print(ans)


if __name__ == "__main__":
    test()
Buggy python submission (verdict: Time Limit Exceeded):
INF = float("inf") #const

def main():
    n,k = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [INF]*n
    dp[0] = 0

    for i in range(n):
        for j in range(1,k+1):
            if i+j >= n:
                break
            else:
                dp[i+j] = min(dp[i+j],dp[i] + abs(h[i]-h[i+j]))

    print(dp[n-1])


if __name__ == "__main__":
    main()


Fixed submission:
INF = float("inf") #const

def main():
    n,k = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [INF]*n
    dp[0] = 0

    for i in range(n):
        res = dp[i]
        for j in range(1,k+1):
            if i+j >= n:
                break
            else:
                dp[i+j] = min(dp[i+j],res + abs(h[i]-h[i+j]))

    print(dp[n-1])


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def test():
    n,k = map(int,input().split())
    a = int(n / k)
    b = int(n % a)

    if b == 0:
        print(b)
    else:
        print(abs(a-b))


if __name__ == "__main__":
    test()


Fixed submission:
def test():
    n,k = map(int,input().split())
    print(0 if n % k == 0 else 1)


if __name__ == "__main__":
    test()
Buggy python submission (verdict: Runtime Error):
def test():
    s = input()
    a = []
    count = 0
    if s[0].isupper():
        for i in range(2,len(s)-1):
            if s[i] == "C":
                a.append(i)
                count += 1

    s2 = list(s)
    for i in a:
        s2.remove(s2[i])

    s3 = "".join(s2[1:])

    if count == 1 and s3.islower():
        print("AC")
    else:
        print("WA")


if __name__ == "__main__":
    test()


Fixed submission:
def test():
    s = input()
    a = []
    count = 0
    if s[0] == "A":
        for i in range(2,len(s)-1):
            if s[i] == "C":
                a.append(i)
                count += 1

    s2 = list(s)
    for i in a:
        s2.remove(s[i])

    s3 = "".join(s2[1:])

    if count == 1 and s3.islower():
        print("AC")
    else:
        print("WA")


if __name__ == "__main__":
    test()
Buggy python submission (verdict: Runtime Error):
def test():
    d,n = map(int,input().split())
    if d == 0:
        a = [i for i in range(1,n+1) if int(i/100)==0 or i%100 != 0]
        print(a[n])
    elif d == 1:
        a = [i for i in range(1,n+1) if int(i/100)==1]
        print(a[n])
    elif d == 2:
        a = [i for i in range(1,n+1) if int(i/100)==2]
        print(a[n])


if __name__ == "__main__":
    test()


Fixed submission:
def test():
    d,n = map(int,input().split())
    if n == 100:
        n += 1
    print(100**d*n)


if __name__ == "__main__":
    test()
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def test():
    n = int(input())
    a = np.array(list(map(int,input().split())))
    b = set(a)
    ans = 0
    for i in b:
        c = sum(a==i)
        if c > i:
            ans += c - i
        elif c < i:
            ans += c
    print(ans)


if __name__ == "__main__":
    test()


Fixed submission:
import collections as coll

def test():
    n = int(input())
    a = list(map(int,input().split()))
    b = coll.Counter(a)
    ans = 0
    for i,j in b.items():
        if i < j:
            ans += j - i
        elif i > j:
            ans += j
    print(ans)


if __name__ == "__main__":
    test()
Buggy python submission (verdict: Time Limit Exceeded):
def low_left(ls,key):
    left,right = -1,len(ls)
    while right - left > 1:
        mid = (right+left)//2
        if ls[mid] >= key:
            right = mid
        else:
            left = mid
    return len(ls[:(left+1)])


def high_right(ls,key):
    left,right = -1,len(ls)
    while right - left > 1:
        mid = (right+left)//2
        if ls[mid]<=key:
            left = mid
        else:
            right = mid
    return len(ls[right:])


def test():
    n = int(input())
    A,B,C = [list(sorted(map(int,input().split()))) for i in range(3)]
    ans = 0

    for b in B:
        ans += high_right(C,b)*low_left(A,b)
    print(ans)


if __name__ == "__main__":
    test()


Fixed submission:
def test():
    n = int(input())
    A,B,C = [list(sorted(map(int,input().split()))) for i in range(3)]
    ans = 0

    for b in B:
        ans += low_left(A,b) * (n-high_right(C,b))
    print(ans) 


def low_left(ls,t):
    low,high = 0,len(ls)
    while low<high:
        mid = (low+high)//2
        if ls[mid] < t:
            low = mid + 1
        else:
            high = mid
    return low


def high_right(ls,t):
    low,high = 0,len(ls)
    while low<high:
        mid = (low+high)//2
        if ls[mid] > t:
            high = mid
        else:
            low = mid + 1
    return low


if __name__ == "__main__":
    test()

Buggy python submission (verdict: Time Limit Exceeded):
def low_left(ls,key):
    left,right = -1,len(ls)
    while right - left > 1:
        mid = (right+left)//2
        if ls[mid] >= key:
            right = mid
        else:
            left = mid
    return len(ls[:(left+1)])


def high_right(ls,key):
    left,right = -1,len(ls)
    while right - left > 1:
        mid = (right+left)//2
        if ls[mid]<=key:
            left = mid
        else:
            right = mid
    return len(ls[right:])


def test():
    n = int(input())
    A,B,C = [list(sorted((map(int,input().split())))) for i in range(3)]
    ans = 0

    for b in B:
        ans += high_right(C,b)*low_left(A,b)
    print(ans)


if __name__ == "__main__":
    test()


Fixed submission:
def test():
    n = int(input())
    A,B,C = [list(sorted(map(int,input().split()))) for i in range(3)]
    ans = 0

    for b in B:
        ans += low_left(A,b) * (n-high_right(C,b))
    print(ans) 


def low_left(ls,t):
    low,high = 0,len(ls)
    while low<high:
        mid = (low+high)//2
        if ls[mid] < t:
            low = mid + 1
        else:
            high = mid
    return low


def high_right(ls,t):
    low,high = 0,len(ls)
    while low<high:
        mid = (low+high)//2
        if ls[mid] > t:
            high = mid
        else:
            low = mid + 1
    return low


if __name__ == "__main__":
    test()