Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03478 (python)

Fixed submission:
def main():
    n, a, b = [int(i) for i in input().split()]
    ans = 0
    for i in range(1,n+1):
        tmp = 0
        for ss in str(i):
            tmp += int(ss)
        if a <= tmp <= b:
            ans += i
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
	n, a, b = [int(i) for i in input().split()]
    ans = 0
    for i in range(1,n+1):
        tmp = 0
        for ss in str(i):
            tmp += int(ss)
        if a <= tmp <= b:
            ans += tmp
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = int(input())
    b = int(input())
    ans = 0
    for i in range(1,n+1):
        tmp = 0
        for ss in str(i):
            tmp += int(ss)
        if a <= tmp <= b:
            ans += tmp
    print(ans)


if __name__ == '__main__':
    main()
Problem p03579 (python)

Fixed submission:
import sys

sys.setrecursionlimit(100000)
from collections import defaultdict

G = defaultdict(list)


N, M = map(int, input().split())
visited = [[False for i in range(N)] for j in range(5)]
for i in range(M):
    v,u = map(int, input().split())
    G[v-1].append(u-1)
    G[u-1].append(v-1)

# 頂点間に奇数長のパスがあるかどうか確認するために 2部グラフ 判定をする
COLOR = [0 for i in range(N)]

def dfs(pos, color):
    global COLOR
    COLOR[pos] = color
    ans = True
    for to in G[pos]:
        if COLOR[to] == color:
            return False
        elif COLOR[to] == 0:
            ans &= dfs(to, -color)
    return ans

if dfs(0, 1):
    count = 0
    for i in COLOR:
        if i == -1:
            count += 1
    another = N-count
    print(count*another-M)
else:
    # 2 部グラフではなかったので、完全グラフから M を引いた値を出力する
    print(N*(N-1)//2-M)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

G = defaultdict(list)


N, M = map(int, input().split())
visited = [[False for i in range(N)] for j in range(5)]
for i in range(M):
    v,u = map(int, input().split())
    G[v-1].append(u-1)
    G[u-1].append(v-1)

# 頂点間に奇数長のパスがあるかどうか確認するために 2部グラフ 判定をする
COLOR = [0 for i in range(N)]

def dfs(pos, color):
    global COLOR
    COLOR[pos] = color
    ans = True
    for to in G[pos]:
        if COLOR[to] == color:
            return False
        elif COLOR[to] == 0:
            ans &= dfs(to, -color)
    return ans

if dfs(0, 1):
    count = 0
    for i in COLOR:
        if i == -1:
            count += 1
    another = N-count
    print(count*another-M)
else:
    # 2 部グラフではなかったので、完全グラフから M を引いた値を出力する
    print(N*(N-1)//2-M)
Problem p02952 (python)

Fixed submission:
n = int(input())
t = n
c = 0
while t > 0:
    t //= 10
    c += 1
ans = 0
for i in range(1, c+1, 2):
    if i == c:
        ans += n - 10 ** (i-1) + 1
    else:
        ans += (10**i - 10**(i-1))
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
t = n
c = 0
while t > 0:
    t //= 10
    c += 1
ans = 0
for i in range(1, c+1, 2):
    if i == c:
        tmp = int(str(n)[1:])
        ans += (tmp + 1)
    else:
        ans += (10**i - 10**(i-1))
print(ans)
Problem p03000 (python)

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

ans = 0
d = 0
while(d <= x):
    if ans == n:
        ans += 1
        break
    d = d + l[ans]
    ans += 1
print(ans)

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

ans = 0
d = 0
while(d <= x):
    d = d + l[ans]
    ans += 1
print(ans)
Problem p03067 (python)

Fixed submission:
a, b, c = map(int, input().split())
if a < c and b > c:
    print("Yes")
elif b < c and a > c:
    print("Yes")
else:
    print("No")

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

n = int(input())
s = input()

left = 0
right = s.count(".")
res = min(right, s.count("#"))
for i in range(n):
    if s[i] == "#":
        left += 1
    else:
        right -= 1
    res = min(res, left+right)

print(res)
Problem p03240 (python)

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

n = int(input())
l = []
for _ in range(n):
    x, y, h = map(int, input().split())
    if h >= 1:
        l.append([x, y, h])

result = None
for i in range(101):
    for j in range(101):
        judge = True
        x, y, h = l[0]
        highest = abs(i - x) + abs(j - y) + h
        if len(l) == 1:
            result = (x, y, h)
            break
        for x, y, h in l[1:]:
            if abs(i - x) + abs(j - y) + h != highest:
                judge = False
                break
        if judge:
            result = (i, j, highest)
            break
    if result:
        break

print(result[0], result[1], result[2])

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

n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

result = None
for i in range(101):
    for j in range(101):
        judge = True
        x, y, h = l[0]
        highest = abs(i - x) + abs(j - y) + h
        if len(l) == 1:
            result = (x, y, h)
            break
        for x, y, h in l[1:]:
            if abs(i - x) + abs(j - y) + h != highest:
                judge = False
                break
        if judge:
            result = (i, j, highest)
            break
    if result:
        break

print(result[0], result[1], result[2])

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

n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

result = None
for i in range(101):
    for j in range(101):
        judge = True
        x, y, h = l[0]
        highest = abs(i - x) + abs(j - y) + h
        for x, y, h in l[1:]:
            if abs(i - x) + abs(j - y) + h != highest:
                judge = False
                break
        if judge:
            result = (i, j, highest)
            break
    if result:
        break

print(result[0], result[1], result[2])
Problem p03361 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10000)
h, w = map(int, input().split())
cam = [input() for _ in range(h)]
painted = [[False for i in range(w)] for j in range(h)]

def dfs(x, y):
    global cnt
    if x < 0 or y < 0 or x > h-1 or y > w-1:
        return
    elif cam[x][y] == ".":
        return
    elif painted[x][y]:
        return
    cnt += 1
    painted[x][y] = True
    dfs(x-1, y)
    dfs(x, y-1)
    dfs(x+1, y)
    dfs(x, y+1)
    
for i in range(h):
    for j in range(w):
        cnt = 0
        if cam[i][j] == "#":
            dfs(i, j)
        if cnt == 1:
            painted[i][j] = False
            
flag = False
for i in range(h):
    for j in range(w):
        if cam[i][j] == "#":
            if not painted[i][j]:
                flag = True
                break
        elif cam[i][j] == ".":
            if painted[i][j]:
                flag = True
                break
    if flag:
        break
if flag:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
cam = [input() for _ in range(h)]
painted = [[False for i in range(w)] for j in range(h)]

def dfs(x, y):
    global cnt
    if x < 0 or y < 0 or x > h-1 or y > w-1:
        return
    elif cam[x][y] == ".":
        return
    elif painted[x][y]:
        return
    cnt += 1
    painted[x][y] = True
    dfs(x-1, y)
    dfs(x, y-1)
    dfs(x+1, y)
    dfs(x, y+1)
    
for i in range(h):
    for j in range(w):
        cnt = 0
        if cam[i][j] == "#":
            dfs(i, j)
        if cnt == 1:
            painted[i][j] = False
            
flag = False
for i in range(h):
    for j in range(w):
        if cam[i][j] == "#":
            if not painted[i][j]:
                flag = True
                break
        elif cam[i][j] == ".":
            if painted[i][j]:
                flag = True
                break
    if flag:
        break
if flag:
    print("No")
else:
    print("Yes")
Problem p02887 (python)

Fixed submission:
N=int(input())
slimes = []
all_slime=input()
slimes.append(all_slime[0])
lastColor = all_slime[0]
for i in range(1,N):
    new_slime = all_slime[i]
    if not lastColor == new_slime:
        slimes.append(new_slime)
    lastColor=new_slime
print(len(slimes))

Buggy submission (verdict: Runtime Error):
N=int(input())
slimes = []
slimes.append(input())
lastColor = slimes[0]
for i in range(N-1):
	new_slime = input()
	if not lastColor == new_slime:
    	slimes.append(new_slime)
print(slimes.length())
Problem p02910 (python)

Fixed submission:
S = str(input())
step_count = 0
ans='Yes'
for step in S:
    step_count += 1
    if step_count%2:
        if step == 'L':
            ans='No'
            break
            
    else:
        if step == 'R':
            ans='No'
            break
print(ans)

Buggy submission (verdict: Runtime Error):
S = str(input())
step_count = 0
ans='Yes'
for step in S:
    step_count += 1
    if step_count%2:
        if step == 'L':
            ans='No'
            brake
            
    else:
        if step == 'R':
            ans='No'
            brake
print(ans)
Problem p02921 (python)

Fixed submission:
S = str(input())
T = str(input())
# 出力
A = 0

for i in range(3):
    if S[i] == T[i]:
        A += 1

print(A)

Buggy submission (verdict: Runtime Error):
A,B = [int(x) for x in input().split()]
print((B-1)//(A-1)+1)
Problem p02922 (python)

Fixed submission:
import math
Input = input().split(" ")
A = int(Input[0])
B = int(Input[1])
n = (B-1)/(A-1)
print(math.ceil(n))

Buggy submission (verdict: Runtime Error):
A,B = map(int, input().split())
print((B-1)//(A-2) + 1)

Buggy submission (verdict: Runtime Error):
A,B = [int(x) for x in input().split()]
print((B-1)//(A-2) + 1)
Problem p02888 (python)

Fixed submission:
import bisect


N = int(input())
str_l = input()
num = 0
L = []
for v in str_l.split(' '):
    L.append(int(v))

L.sort()
for i in range(N - 1):
    a = L[i]
    for j in range(i, N - 2):
        b = L[j + 1]
        index = bisect.bisect_left(L[j + 2:], a + b)
        num += index
        # for k in range(0, index):
        #     c = (L[j + 2:])[k]
        #     if b + c > a and a + c > b:
        #         num += 1

print(num)

Buggy submission (verdict: Runtime Error):
def binary_search(list, item):
    low = 0
    lengyh = len(list)
    if list[lengyh - 1] < item:
        return lengyh - 1
    high = lengyh - 1

    while low <= high:
        mid = (low + high) // 2
        guess = list[mid]

        if guess == item - 1 or (mid < lengyh - 1 and (guess < item and list[mid + 1] > item)) or (mid == lengyh - 1 and guess < item):
            return mid
        if guess > item:
            high = mid - 1
        else:
            low = mid + 1

    return None


N = int(input())
str_l = input()
num = 0
L = []
for v in str_l.split(' '):
    L.append(int(v))

L.sort()
for i in range(N):
    a = L[i]
    for j in range(i, N - 1):
        b = L[j + 1]
        index = binary_search(L[j + 2:], a + b)
        if index is None:
            continue
        else:
            for k in range(0, index + 1):
                c = (L[j + 2:])[k]
                if b + c > a and a + c > b:
                    num += 1

print(num)

Buggy submission (verdict: Runtime Error):
def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) // 2
        guess = list[mid]
        if guess == item or (list[mid - 1] < item and list[mid + 1] > item):
            return mid
        if guess > item:
            high = mid - 1
        else:
            low = mid + 1

    return None


N = int(input())
str_l = input()
num = 0
L = []
for v in str_l.split(' '):
    L.push(int(v))

L.sort()
for i in range(N):
    Ldash = L
    a = Ldash.pop(i)
    for j in range(N - 1):
        b = Ldash.pop(j)
        index = binary_search(Ldash, a + b)
        if index is None:
            continue
        else:
            for k in range(index + 1):
                c = Ldash[k]
                if b + c > a and a + c < b:
                    num += 1

print(num)
Problem p02889 (python)

Fixed submission:
import sys
import copy

N, M, L = list(map(int, sys.stdin.readline().strip().split(" ")))
INF = 10**10

def warshall_floyd(g_mat):
    dp = copy.copy(g_mat)
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
    return dp

graph = [[INF for _ in range(N)] for _ in range(N)]

for _ in range(M):
    a, b, c = list(map(int, sys.stdin.readline().strip().split(" ")))
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

dist_graph = warshall_floyd(graph)
bool_graph = [[INF for _ in range(N)] for _ in range(N)]

for i in range(N):
    for j in range(N):
        if dist_graph[i][j] <= L:
            bool_graph[i][j] = 1

ans_graph = warshall_floyd(bool_graph)

Q = int(sys.stdin.readline().strip())
for _ in range(Q):
    s, t = list(map(int, sys.stdin.readline().strip().split(" ")))
    ans = ans_graph[s-1][t-1]
    print(ans-1 if ans != INF else -1)

Buggy submission (verdict: Runtime Error):
import sys

N, M, L = list(map(int, sys.stdin.readline().strip().split(" ")))
INF = 10**10

def warshall_floyd(g_mat):
    dp = [[INF for _ in range(N)] for _ in range(N)]
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
    return dp

graph = [[INF for _ in range(N)] for _ in range(N)]

for _ in range(M):
    a, b, c = list(map(int, sys.stdin.readline().strip().split(" ")))
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

dist_graph = warshall_floyd(graph)
bool_graph = [[INF for _ in range(N)] for _ in range(N)]

for i in range(N):
    for j in range(N):
        if dist_graph[i][j] <= L:
            bool_graph[i][j] = 1

ans_graph = warshall_floyd(bool_graph)

Q = int(sys.stdin.readline().strip())
for _ in range(Q):
    s, t = list(map(int, sys.stdin.readline().strip().split(" ")))
    ans = ans_graph[s][t]
    print(ans if ans != INF else -1)
Problem p03001 (python)

Fixed submission:
import sys

W, H, x, y = list(map(int, sys.stdin.readline().strip().split(" ")))
b = 0

if x == W/2 and y == H/2:
    b = 1

print(str(W*H/2) + " " + str(b))

Buggy submission (verdict: Runtime Error):
import sys

W, H, x, y = list(map(int, sys.stdin.readline()))
b = 0

if x == W/2 and y == H/2:
    b = 1

print(str(W*H/2) + " " + str(b))
Problem p03160 (python)

Fixed submission:
import sys

N = int(sys.stdin.readline().strip())
cost_list = list(map(int, sys.stdin.readline().strip().split(" ")))
dp = [10**9 for _ in range(N)]
dp[0] = 0
dp[1] = abs(cost_list[1] - cost_list[0])

for i in range(2, N):
    dp[i] = min(dp[i-2] + abs(cost_list[i] - cost_list[i-2]), dp[i-1] + abs(cost_list[i] - cost_list[i-1]))

print(dp[N-1])

Buggy submission (verdict: Runtime Error):
import os
import sys

N = int(sys.stdin.readline().strip())
cost_list = list(map(int, sys.stdin.readline().strip()))
dp = [10**9 for _ in range(N)]
dp[0] = 0
dp[1] = abs(cost_list[1] - cost_list[0])

for i in range(2, N):
    dp[i] = min(dp[i-2] + abs(cost_list[i] - cost_list[i-2]), dp[i-1] + abs(cost_list[i] - cost_list[i-1]))

print(dp[N-1])
Problem p03238 (python)

Fixed submission:
import sys

a = int(sys.stdin.readline().strip())
if a == 1:
    print("Hello World")
else:
    b = int(sys.stdin.readline().strip())
    c = int(sys.stdin.readline().strip())
    print(b + c)

Buggy submission (verdict: Runtime Error):
import sys

a = int(sys.stdin.readline().strip())
b = int(sys.stdin.readline().strip())
c = int(sys.stdin.readline().strip())

if a == 1:
    print("Hello World")
else:
    print(b + c)

Buggy submission (verdict: Runtime Error):
import sys
a = int(sys.stdin.readline().strip())
b = int(sys.stdin.readline().strip())
c = int(sys.stdin.readline().strip())

if a == 1:
  print("Hello World")
else:
  print(b + c)
Problem p03425 (python)

Fixed submission:
import sys
import numpy as np
import itertools

N = int(sys.stdin.readline().strip())
dct = {}
dct["M"] = 0
dct["A"] = 0
dct["R"] = 0
dct["C"] = 0
dct["H"] = 0
char_list = ["M", "A", "R", "C", "H"]

for _ in range(N):
    name = sys.stdin.readline().strip()
    first = name[0]
    if first not in dct:
        continue
    dct[first] += 1

count = 0
for a, b, c in list(itertools.combinations(char_list, 3)):
    count += dct[a] * dct[b] * dct[c]
print(count)

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

N = int(sys.stdin.readline().strip())
dct = {}
dct["M"] = 0
dct["A"] = 0
dct["R"] = 0
dct["C"] = 0
dct["H"] = 0
char_list = ["M", "A", "R", "C", "H"]

for _ in range(N):
    name = sys.stdin.readline().strip()
    first = name[0]
    dct[first] += 1

count = 0
for a, b, c in list(itertools.combinations(char_list, 3)):
    count += dct[a] * dct[b] * dct[c]
print(count)
Problem p03471 (python)

Fixed submission:
import sys

n, y = list(map(int, sys.stdin.readline().strip().split(" ")))

t_list = []

for a in range(n + 1):
    for b in range(n-a+1):
        #t_list.append((n-i-j, j, i))
        c = n-a-b
        if 10000 * a + 5000 * b + 1000 * c == y:
            print(" ".join([str(a), str(b), str(c)]))
            sys.exit()

print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
import sys

n, y = list(map(int, sys.stdin.readline().strip().split(" ")))

t_list = []

for a in range(n + 1):
    for b in range(n-i+1):
        #t_list.append((n-i-j, j, i))
        c = n-a-b
        if 10000 * a + 5000 * b + 1000 * c == y:
            print(" ".join([str(a), str(b), str(c)]))
            sys.exit()

print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
import sys

n, y = list(map(int, sys.stdin.readline().strip().split(" ")))

t_list = []

for i in range(n + 1):
    for j in range(n-i+1):
        t_list.append(N-i-j, j, i)

for a, b, c in t_list:
    if 10000 * a + 5000 * b + 1000 * c == y:
        print(" ".join([str(a), str(b), str(c)]))
        sys.exit()

print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
import sys

n, y = list(map(int, sys.stdin.readline(),strip().split(" ")))

t_list = []

for i in range(n + 1):
    for j in range(n-i+1):
        t_list.append(N-i-j, j, i)

for a, b, c in t_list:
    if 10000 * a + 5000 * b + 1000 * c == y:
        print(" ".join([str(a), str(b), str(c)]))
        sys.exit()

print("-1 -1 -1")
Problem p03546 (python)

Fixed submission:
import sys
import numpy as np

def dijk(edge_list, start):
    checked = []
    queue = []
    dist = [100000 for i in range(10)]
    dist[start] = 0
    queue.append(start)
    while len(queue) != 0:
        index = np.argmin(list(map(lambda x: dist[x], queue)))
        node = queue.pop(index)
        checked.append(node)
        for child in edge_list[node]:
            dist[child[0]] = min(dist[child[0]], child[1] + dist[node])
            if (child[0] not in queue) and (child[0] not in checked):
                queue.append(child[0])
    return dist

H, W = list(map(int, sys.stdin.readline().strip().split(" ")))

edge_list = []
for i in range(10):
    l = list(map(int, sys.stdin.readline().strip().split(" ")))
    ll = []
    for j in range(10):
        ll.append((j, l[j]))
    edge_list.append(ll)

cost = []
for i in range(10):
    cost.append(dijk(edge_list, i)[1])

res = 0
for i in range(H):
    input_list = list(map(int, sys.stdin.readline().strip().split(" ")))
    res += np.sum(list(map(lambda x: 0 if (x == -1) else cost[x], input_list)))

print(res)

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

def dijk(edge_list, start):
    queue = []
    dist = [100000 for i in range(10)]
    dist[start] = 0
    queue.append([i for i in range(10)])
    while len(queue) != 0:
        index = np.argmin(map(lambda x: dist[x], queue))
        node = queue.pop(index)
        for child in edge_list[node]:
            dist[child[0]] = min(dist[child[0]], child[1] + dist[node])

    return dist

H, W = list(map(int, sys.stdin.readline().strip().split(" ")))

edge_list = []
for i in range(10):
    l = list(map(int, sys.stdin.readline().strip().split(" ")))
    ll = []
    for j in range(10):
        ll.append((j, l[j]))
    edge_list.append(ll)

cost = []
for i in range(10):
    cost.append(dijk(edge_list, i)[1])

res = 0
for i in range(H):
    input_list = list(map(int, sys.stdin.readline().strip().split(" ")))
    res += np.sum(list(map(lambda x: 0 if (x == -1) else cost[x], input_list)))

print(res)

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

def dijk(edge_list, start):
    queue = []
    dist = [100000 for i in range(10)]
    dist[start] = 0
    queue.append([i for i in range(10)])
    while len(queue) != 0:
        index = np.argmin(map(lambda x: dist[x], queue))
        node = queue.pop(index)
        for child in edge_list[node]:
            dist[child[0]] = min(dist[child[0]], child[1] + dist[node])
            if (child[0] not in queue):
                queue.append(child[0])
    return dist

H, W = list(map(int, sys.stdin.readline().strip().split(" ")))

edge_list = []
for i in range(10):
    l = list(map(int, sys.stdin.readline().strip().split(" ")))
    ll = []
    for j in range(10):
        ll.append((j, l[j]))
    edge_list.append(ll)

cost = []
for i in range(10):
    cost.append(dijk(edge_list, i)[1])

res = 0
for i in range(H):
    input_list = list(map(int, sys.stdin.readline().strip().split(" ")))
    res += np.sum(list(map(lambda x: 0 if (x == -1) else cost[x], input_list)))

print(res)
Problem p03557 (python)

Fixed submission:
import sys
import numpy as np

def binary_search(array, num):
    # numより真に大きいはじめのindex
    if array[-1] <= num:
        return -1
    left = -1
    right = N-1
    while right - left > 1:
        mid = int((left + right)/2)
        if array[mid] <= num:
            left = mid
        else:
            right = mid
    return right

a_index = []
b_index = []

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().split(" ")))
A = np.sort(A)
B = list(map(int, sys.stdin.readline().strip().split(" ")))
B = np.sort(B)
C = list(map(int, sys.stdin.readline().strip().split(" ")))
C = np.sort(C)

for a in A:
    a_index.append(binary_search(B, a))
    
for b in B:
    b_index.append(binary_search(C, b))


b_index = list(map(lambda x: N-x if (x != -1) else 0, b_index))

bb = []
tmp = np.sum(b_index)
for i in range(N):
    bb.append(tmp)
    tmp = tmp - b_index[i]

res = 0
for a_i in a_index:
    if a_i == -1:
        continue
    res += bb[a_i]
print(str(res))

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

def binary_search(array, num):
    # numより真に大きいはじめのindex
    if array[-1] <= num:
        return -1
    left = -1
    right = N-1
    while right - left > 1:
        mid = int((left + right)/2)
        if array[mid] <= num:
            left = mid
        else:
            right = mid
    return right

a_index = []
b_index = []

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().split(" ")))
A = np.sort(A)
B = list(map(int, sys.stdin.readline().strip().split(" ")))
B = np.sort(B)
C = list(map(int, sys.stdin.readline().strip().split(" ")))
C = np.sort(C)

for a in A:
    a_index.append(binary_search(B, a))
    
for b in B:
    b_index.append(binary_search(C, b))

bb = []
tmp = np.sum(b_index)
for i in range(N):
    bb.append(tmp)
    bb = bb - b_index[i]
    
res = 0
for a_i in a_index:
    if a_i == -1:
        continue
    res += N * (N - a_i) - bb[a_i]
print(str(res))