Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import bisect

N, K = map(int, input().split())
x = list(map(int, input().split()))

x_negative = x[:bisect.bisect_left(x,0)]
x_positive = x[bisect.bisect_left(x,0):]

# 0以上の地点にロウソクが無い場合
if len(x_positive) == 0:
    print(abs(x_negative[-K]))
    exit()

# 地点0にロウソクがある場合
if x_positive[0] == 0:
    if K == 1:
        print(0)
        exit()
    K -= 1
    del x_positive[0]

t_list = []

# 全くターンしない場合
if len(x_negative) >= K:
    t_list.append(abs(x_negative[-K]))
if len(x_positive) >= K:
    t_list.append(x_positive[K-1])

# 1回だけターンする場合
for i in range(1, K-1):
    t_list.append(2*abs(x_negative[-i]) + x_positive[K-i-1])
    t_list.append(2*x_positive[i-1] + abs(x_negative[-(K-i)]))

print(min(t_list))

Fixed submission:
import bisect

N, K = map(int, input().split())
x = list(map(int, input().split()))

x_negative = x[:bisect.bisect_left(x,0)]
x_positive = x[bisect.bisect_left(x,0):]

# 0以上の地点にロウソクが無い場合
if len(x_positive) == 0:
    print(abs(x_negative[-K]))
    exit()

# 地点0にロウソクがある場合
if x_positive[0] == 0:
    if K == 1:
        print(0)
        exit()
    K -= 1
    del x_positive[0]

t_list = []

# 全くターンしない場合
if len(x_negative) >= K:
    t_list.append(abs(x_negative[-K]))
if len(x_positive) >= K:
    t_list.append(x_positive[K-1])

# 1回だけターンする場合
for i in range(1, K-1):
    try:
        t_list.append(2*abs(x_negative[-i]) + x_positive[K-i-1])
    except IndexError:
        pass
    
for i in range(1, K-1):
    try:
        t_list.append(2*x_positive[i-1] + abs(x_negative[-(K-i)]))
    except IndexError:
        pass

print(min(t_list))

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

N, K = map(int, input().split())
x = list(map(int, input().split()))

x_negative = x[:bisect.bisect_left(x,0)]
x_positive = x[bisect.bisect_left(x,0):]

# 地点0にロウソクがある場合
if x_positive[0] == 0:
    if K == 1:
        print(0)
        exit()
    K -= 1
    del x_positive[0]

t_list = []

# 全くターンしない場合
if len(x_negative) >= K:
    t_list.append(x_negative[-K])
if len(x_positive) >= K:
    t_list.append(x_positive[K-1])

# 1回だけターンする場合
for i in range(1, K-1):
    t_list.append(2*abs(x_negative[-i]) + x_positive[K-i-1])
    t_list.append(2*x_positive[i-1] + abs(x_negative[-(K-i)]))

print(min(t_list))

Fixed submission:
import bisect

N, K = map(int, input().split())
x = list(map(int, input().split()))

x_negative = x[:bisect.bisect_left(x,0)]
x_positive = x[bisect.bisect_left(x,0):]

# 0以上の地点にロウソクが無い場合
if len(x_positive) == 0:
    print(abs(x_negative[-K]))
    exit()

# 地点0にロウソクがある場合
if x_positive[0] == 0:
    if K == 1:
        print(0)
        exit()
    K -= 1
    del x_positive[0]

t_list = []

# 全くターンしない場合
if len(x_negative) >= K:
    t_list.append(abs(x_negative[-K]))
if len(x_positive) >= K:
    t_list.append(x_positive[K-1])

# 1回だけターンする場合
for i in range(1, K-1):
    try:
        t_list.append(2*abs(x_negative[-i]) + x_positive[K-i-1])
    except IndexError:
        pass
    
for i in range(1, K-1):
    try:
        t_list.append(2*x_positive[i-1] + abs(x_negative[-(K-i)]))
    except IndexError:
        pass

print(min(t_list))
Buggy python submission (verdict: Time Limit Exceeded):
# D - Candy Distribution

import numpy as np

N, M = map(int, input().split())
A = np.array(list(map(int, input().split())))

C = A.cumsum()
C = np.insert(C,0,0)

ans = 0
for i in range(N):
    for j in range(i+1, N+1):
        if (C[j] - C[i]) % M == 0:
            ans += 1
            
print(ans)

Fixed submission:
# D - Candy Distribution

import numpy as np
from collections import defaultdict

N, M = map(int, input().split())
A = np.array(list(map(int, input().split())), np.int64)

C = A.cumsum()
C = np.insert(C,0,0)
remainder = defaultdict(int)

for x in C:
    remainder[x%M] += 1

ans = 0
for key in remainder:
    if remainder[key] >= 2:
        ans += (remainder[key] * (remainder[key] - 1)) // 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from statistics import mean
import math

N = int(input())
A = list(map(int, input().split()))
A = [A[idx]-(idx+1) for idx in range(N)]

b = round(mean(A))

ans1 = 0
ans2 = 0
for i in range(N):
    ans1 += abs(math.floor(mean(A))-A[i])
    ans2 += abs(math.ceil(mean(A)) - A[i])
    
print(min(ans1,ans2))

Fixed submission:
from statistics import median
import math

N = int(input())
A = list(map(int, input().split()))
A = [A[idx]-(idx+1) for idx in range(N)]

ans1 = 0
ans2 = 0
median_A = median(A)
median_floor_A = math.floor(median_A)
median_ceil_A = math.ceil(median(A))

for i in range(N):
    ans1 += abs(median_floor_A - A[i])
    ans2 += abs(median_ceil_A - A[i])
    
print(min(ans1,ans2))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

# リーダーより西にいる人のうち西を向いている人数+リーダーより東にいる人のうち東を向いている人数 を調べる
n_turn_list = []
for i in range(N):
    n_turn_list.append(S[:i].count("W") + S[i+1:].count("E"))

print(min(n_turn_list))

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

# 左端からリーダーにしていく
# リーダーを1つ右隣に移すとき、振り向く合計人数は、リーダーと右隣の人の向きが(W,W)なら+1、(E,E)なら-1、(E,W)or(W,E)なら変化なし
n_turn_list = [S[1:].count("E")] # 左端リーダーのときに振り向く人数

for leader_position in range(N-1): # 右端の1つ左まで
    if S[leader_position+1] == "W" and S[leader_position] == "W":
        n_turn_list.append(n_turn_list[leader_position]+1)
    elif S[leader_position+1] == "E" and S[leader_position] == "E":
        n_turn_list.append(n_turn_list[leader_position]-1)
    else:
        n_turn_list.append(n_turn_list[leader_position])

print(min(n_turn_list))
Buggy python submission (verdict: Runtime Error):
# D - Xor Sum 2

N = int(input())
A = list(map(int, input().split()))

l,r = 0,1 # l<rの場合を考える
tmp_xor = A[l] ^ A[r]
tmp_sum = A[l] + A[r]
ans = N

while 1:
    if tmp_xor == tmp_sum:
        ans += r-l # 先頭l以上、末尾rの部分数列の個数
        r += 1
        if r == N:
            break
        tmp_xor = tmp_xor ^ A[r]
        tmp_sum += A[r]
    elif l+1 < r:
        tmp_sum -= A[l]
        tmp_xor = tmp_xor ^ A[l]
        l += 1
    else:
        l = r
        r += 1
        if r == N:
            break
        tmp_xor = A[l] ^ A[r]
        tmp_sum = A[l] + A[r]

print(ans)

Fixed submission:
# D - Xor Sum 2

N = int(input())
A = list(map(int, input().split()))

if N == 1:
    print(1)
    exit()

l,r = 0,1 # l<rの場合を考える
tmp_xor = A[l] ^ A[r]
tmp_sum = A[l] + A[r]
ans = N

while 1:
    if tmp_xor == tmp_sum:
        ans += r-l # 先頭l以上、末尾rの部分数列の個数
        r += 1
        if r == N:
            break
        tmp_xor = tmp_xor ^ A[r]
        tmp_sum += A[r]
    elif l+1 < r:
        tmp_sum -= A[l]
        tmp_xor = tmp_xor ^ A[l]
        l += 1
    else:
        l = r
        r += 1
        if r == N:
            break
        tmp_xor = A[l] ^ A[r]
        tmp_sum = A[l] + A[r]

print(ans)

Buggy python submission (verdict: Runtime Error):
# D - Xor Sum 2

N = int(input())
A = list(map(int, input().split()))

l,r = 0,1 # l<rの場合を考える
tmp_xor = A[l] ^ A[r]
tmp_sum = A[l] + A[r]
ans = N

while 1:
    if tmp_xor == tmp_sum:
        ans += r-l # 先頭l以上、末尾rの部分数列の個数
        r += 1
        if r == N:
            break
        tmp_xor = tmp_xor ^ A[r]
        tmp_sum += A[r]
    elif l+1 < r:
        tmp_sum -= A[l]
        l += 1
        tmp_xor = A[l]
        for idx in range(l+1,r+1):
            tmp_xor = tmp_xor ^ A[idx]
    else:
        l = r
        r += 1
        if r == N:
            break
        tmp_xor = A[l] ^ A[r]
        tmp_sum = A[l] + A[r]

print(ans)

Fixed submission:
# D - Xor Sum 2

N = int(input())
A = list(map(int, input().split()))

if N == 1:
    print(1)
    exit()

l,r = 0,1 # l<rの場合を考える
tmp_xor = A[l] ^ A[r]
tmp_sum = A[l] + A[r]
ans = N

while 1:
    if tmp_xor == tmp_sum:
        ans += r-l # 先頭l以上、末尾rの部分数列の個数
        r += 1
        if r == N:
            break
        tmp_xor = tmp_xor ^ A[r]
        tmp_sum += A[r]
    elif l+1 < r:
        tmp_sum -= A[l]
        tmp_xor = tmp_xor ^ A[l]
        l += 1
    else:
        l = r
        r += 1
        if r == N:
            break
        tmp_xor = A[l] ^ A[r]
        tmp_sum = A[l] + A[r]

print(ans)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())

S = [list(input()) for _ in range(H)]

# #の座標(i,j)を与え、隣接している#があるならばTrue、そうでなければNoを出力して終了する
def exist_neighbor_black_cell(i,j):
    if "#" in [S[max(0,i-1)][j], S[min(H-1,i+1)][j], S[i][max(0,j-1)], S[i][min(W-1,j+1)]]:
        return True
    else:
        print("No")
        exit()

# どの#にも隣接していない#マスがあれば不可。そうでなければ可
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            exist_neighbor_black_cell(i, j)

print("Yes")

Fixed submission:
# A - Day of Takahashi

a, b = map(int, input().split())
print(a if a <= b else a-1)

Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())

S = [list(input()) for _ in range(H)]

# #の座標(i,j)を与え、隣接している#があるならばTrue、そうでなければNoを出力して終了する
def exist_neighbor_black_cell(i,j):
    if "#" in [S[max(0,i-1)][j], S[min(H-1,i+1)][j], S[i][max(0,j-1)], S[i][min(W-1,j+1)]]:
        return True
    else:
        print("No")
        exit()

# どの#にも隣接していない#マスがあれば不可。そうでなければ可
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            exist_neighbor_black_cell(i, j)

print("Yes")

Fixed submission:
# A - Day of Takahashi

a, b = map(int, input().split())
print(a if a <= b else a-1)
Buggy python submission (verdict: Time Limit Exceeded):
# D - Binomial Coefficients

import bisect, math

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

def comb(n, r):
    if n < r:
        return 0
    else:
        tmp = 1
        for i in range(n+1, n-r+1, -1):
            tmp *= i
        return tmp // math.factorial(r)
    
idx = bisect.bisect_left(a, a[-1]//2)

try:
    if idx != n-1:
        tmp = comb(a[-1], a[idx])
        ans = [a[-1], a[idx]]
    else:
        tmp = 0
    if tmp < comb(a[-1], a[idx-1]):
        tmp = comb(a[-1], a[idx-1])
        ans = [a[-1], a[idx-1]]
    if tmp < comb(a[-1], a[idx+1]) and idx+1 != n-1:
        ans = [a[-1], a[idx+1]]
except IndexError:
    pass

print(*ans)

Fixed submission:
# D - Binomial Coefficients

import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
    
idx = bisect.bisect_left(a, a[-1]//2)
tmp = float("inf")

try:
    if idx != n-1:
        tmp = abs(a[idx]-a[-1]/2)
        ans = [a[-1], a[idx]]
    if abs(a[idx-1] - a[-1]/2) < tmp:
        tmp = abs(a[idx-1] - a[-1]/2)
        ans = [a[-1], a[idx-1]]
    if abs(a[idx+1] - a[-1]/2) < tmp and idx+1 != n-1:
        ans = [a[-1], a[idx+1]]
except IndexError:
    pass

print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
# D - Binomial Coefficients

import bisect, math

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

def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    
idx = bisect.bisect_left(a, a[-1]//2)

try:
    if a[-1] != a[idx]:
        tmp = comb(a[-1], a[idx])
        ans = [a[-1], a[idx]]
    else:
        tmp = 0
    if tmp < comb(a[-1], a[idx-1]) and a[-1] != a[idx-1]:
        tmp = comb(a[-1], a[idx-1])
        ans = [a[-1], a[idx-1]]
    if tmp < comb(a[-1], a[idx+1]) and a[-1] != a[idx+1]:
        ans = [a[-1], a[idx+1]]
except IndexError:
    pass

print(*ans)

Fixed submission:
# D - Binomial Coefficients

import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
    
idx = bisect.bisect_left(a, a[-1]//2)
tmp = float("inf")

try:
    if idx != n-1:
        tmp = abs(a[idx]-a[-1]/2)
        ans = [a[-1], a[idx]]
    if abs(a[idx-1] - a[-1]/2) < tmp:
        tmp = abs(a[idx-1] - a[-1]/2)
        ans = [a[-1], a[idx-1]]
    if abs(a[idx+1] - a[-1]/2) < tmp and idx+1 != n-1:
        ans = [a[-1], a[idx+1]]
except IndexError:
    pass

print(*ans)
Buggy python submission (verdict: Runtime Error):
import itertools

N = int(input())

# 頭文字Mグループ、頭文字Aグループ、のように分割する
# どの3つのグループから1人選ぶかを考える

n_initial_MARCH = [0]*5
match_initial = ["M", "A", "R", "C", "H"]
for _ in range(N):
    s = input()
    for idx in range(5):
        if s[0] == match_initial[idx]:
            n_initial_MARCH[idx] += 1

taken_indices = list(itertools.combinations([idx for idx in range(N) if n_initial_MARCH[idx] > 0], 3))

ans = 0

for groups in taken_indices:
    ans += n_initial_MARCH[groups[0]] * n_initial_MARCH[groups[1]] * n_initial_MARCH[groups[2]]

print(ans)

Fixed submission:
import itertools

N = int(input())

# 頭文字Mグループ、頭文字Aグループ、のように分割する
# どの3つのグループから1人選ぶかを考える

n_initial_MARCH = [0]*5
match_initial = ["M", "A", "R", "C", "H"]
for _ in range(N):
    s = input()
    for idx in range(5):
        if s[0] == match_initial[idx]:
            n_initial_MARCH[idx] += 1

taken_indices = list(itertools.combinations([idx for idx in range(5) if n_initial_MARCH[idx] > 0], 3))

ans = 0

for groups in taken_indices:
    ans += n_initial_MARCH[groups[0]] * n_initial_MARCH[groups[1]] * n_initial_MARCH[groups[2]]

print(ans)

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

N = int(input())

# 頭文字Mグループ、頭文字Aグループ、のように分割する
# どの3つのグループから1人選ぶかを考える

n_initial_MARCH = [0]*5
match_initial = ["M", "A", "R", "C", "H"]
for _ in range(N):
    s = input()
    for idx in range(N):
        if s[0] == match_initial[idx]:
            n_initial_MARCH[idx] += 1

taken_indices = list(itertools.combinations([idx for idx in range(N) if n_initial_MARCH[idx] > 0], 3))

ans = 0

for groups in taken_indices:
    ans += n_initial_MARCH[groups[0]] * n_initial_MARCH[groups[1]] * n_initial_MARCH[groups[2]]

print(ans)

Fixed submission:
import itertools

N = int(input())

# 頭文字Mグループ、頭文字Aグループ、のように分割する
# どの3つのグループから1人選ぶかを考える

n_initial_MARCH = [0]*5
match_initial = ["M", "A", "R", "C", "H"]
for _ in range(N):
    s = input()
    for idx in range(5):
        if s[0] == match_initial[idx]:
            n_initial_MARCH[idx] += 1

taken_indices = list(itertools.combinations([idx for idx in range(5) if n_initial_MARCH[idx] > 0], 3))

ans = 0

for groups in taken_indices:
    ans += n_initial_MARCH[groups[0]] * n_initial_MARCH[groups[1]] * n_initial_MARCH[groups[2]]

print(ans)
Buggy python submission (verdict: Runtime Error):
# D - People on a Line

import sys

N, M = map(int, sys.stdin.buffer.readline().split())
LRD = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]

LRD = [[LRD[i][0]-1, LRD[i][1]-1, LRD[i][2]] for i in range(M)]

if N == 1 or M == 0:
    print("Yes")
    exit()

neighbor = [[] for _ in range(N)]
for i in range(M):
    neighbor[LRD[i][0]].append([LRD[i][1], LRD[i][2]])
    neighbor[LRD[i][1]].append([LRD[i][0], -LRD[i][2]])

x = [None] * N

def check(i):
    if x[i] == None:
        x[i] = 0
    for next_point, dist in neighbor[i]:
        if x[next_point] == None:
            x[next_point] = x[i] + dist
            check(next_point)
        elif x[next_point] != x[i] + dist:
            print('No')
            exit()

for i in range(N):
    if x[i] == None:
        check(i)

print('Yes')

Fixed submission:
# D - People on a Line

import sys
sys.setrecursionlimit(10000000)

N, M = map(int, sys.stdin.buffer.readline().split())
LRD = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]

LRD = [[LRD[i][0]-1, LRD[i][1]-1, LRD[i][2]] for i in range(M)]

if N == 1 or M == 0:
    print("Yes")
    exit()

neighbor = [[] for _ in range(N)]
for i in range(M):
    neighbor[LRD[i][0]].append([LRD[i][1], LRD[i][2]])
    neighbor[LRD[i][1]].append([LRD[i][0], -LRD[i][2]])

x = [None] * N

def check(i):
    if x[i] == None:
        x[i] = 0
    for next_point, dist in neighbor[i]:
        if x[next_point] == None:
            x[next_point] = x[i] + dist
            check(next_point)
        elif x[next_point] != x[i] + dist:
            print('No')
            exit()

for i in range(N):
    if x[i] == None:
        check(i)

print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
# D - Checker

import numpy as np

N, K = map(int, input().split())
g = np.zeros((K,K), np.int64) # PDF解説通り2K*2K範囲でやると市松模様の処理が大変なのでK*Kの範囲で計算

for _ in range(N):
    x, y, c = input().split()
    x = int(x)
    y = int(y)
    tmp = (x//K + y//K) % 2
    x %= K
    y %= K
    if (tmp == 0 and c == "B") or (tmp == 1 and c == "W"):
        g[x][y] += 1
    else:
        g[x][y] -= 1 # 白希望の点を-1で記録する

np.cumsum(g, axis=0, out=g)
np.cumsum(g, axis=1, out=g)

# [i,j]を黒範囲の左下の点とする。[0,i] * [0,j] の範囲または[i+1,K-1] * [j+1,K-1]の範囲にある黒希望点の個数を足し、白希望の点の個数を引く
# 上記範囲外にある白希望の点の個数を足し、黒希望の点の個数を引く
ans = 0
for i in range(K):
    for j in range(K):
        n_satisfied = g[-1][-1] -2*(g[-1][j] + g[i][-1]) + 4*g[i][j]
        ans = max(ans, (N + n_satisfied)//2, (N - n_satisfied)//2) # ((希望通りの点 + 希望通りでない点) + (希望通りの点 - 希望通りでない点))//2

print(ans)

Fixed submission:
# D - Checker

N, K = map(int, input().split())
g = [[0]*K for _ in range(K)] # PDF解説通り2K*2K範囲でやると市松模様の処理が大変なのでK*Kの範囲で計算

for _ in range(N):
    x, y, c = input().split()
    x = int(x)
    y = int(y)
    tmp = (x//K + y//K) % 2
    x %= K
    y %= K
    if (tmp == 0 and c == "B") or (tmp == 1 and c == "W"):
        g[x][y] += 1
    else:
        g[x][y] -= 1 # 白希望の点を-1で記録する

for i in range(K):
    for j in range(1,K):
        g[i][j] += g[i][j-1]

for i in range(1,K):
    for j in range(K):
        g[i][j] += g[i-1][j]

# [i,j]を黒範囲の左下の点とする。[0,i] * [0,j] の範囲または[i+1,K-1] * [j+1,K-1]の範囲にある黒希望点の個数を足し、白希望の点の個数を引く
# 上記範囲外にある白希望の点の個数を足し、黒希望の点の個数を引く
ans = 0
for i in range(K):
    for j in range(K):
        n_satisfied = g[-1][-1] -2*(g[-1][j] + g[i][-1]) + 4*g[i][j]
        ans = max(ans, (N + n_satisfied)//2, (N - n_satisfied)//2) # ((希望通りの点 + 希望通りでない点) + (希望通りの点 - 希望通りでない点))//2

print(ans)
Buggy python submission (verdict: Runtime Error):
N_n_osatsu, Y_sum_money = map(int, input().split())

rest_money = Y_sum_money
rest_n_osatsu = N_n_osatsu
n_each_osatsu_list = [] # 万札、五千円札、千円札の枚数の2重リスト

def skip_search(rest_money, rest_n_osatsu):  # 明らかに無理な場合、処理をスキップ
    if rest_n_osatsu*1000 > rest_money or rest_n_osatsu*10000 < rest_money:
        return True

def is_answer(n_10000, n_5000, n_1000): # 正答ならばそれを出力して終了
    if n_10000 + n_5000 + n_1000 == N_n_osatsu and n_10000*10000 + n_5000*5000 + n_1000*1000 == Y_sum_money:
        print(n_10000, n_5000, n_1000)
        exit()

for n_10000 in range(min(Y_sum_money//10000, N_n_osatsu)+1): # 万札枚数。0枚からスタート
    is_answer(n_10000, 0, 0)
    rest_money = Y_sum_money - 10000*n_10000
    rest_n_osatsu = N_n_osatsu - n_10000
    if skip_search(rest_money, rest_n_osatsu):
        break

    for n_5000 in range(min(rest_money//5000 + 1, rest_n_osatsu)+1): # 万札枚数決定後に5000円の枚数を探索。5000円0枚からスタート
        is_answer(n_10000, n_5000, 0)
        rest_money = Y_sum_money - 10000*n_10000 - 5000*n_5000
        rest_n_osatsu = N_n_osatsu - n_10000 - n_5000
        if skip_search(rest_money, rest_n_osatsu):
            break
        n_1000 = rest_money//1000
        is_answer(n_10000, n_5000, n_1000)

print("-1 -1 -1")

Fixed submission:
# A - Already 2018

S = input()
print("2018" + S[4:])

Buggy python submission (verdict: Runtime Error):
N = int(input())
d_list = [int(input()) for _ in range(N)]
print(len(set(d_list)))

Fixed submission:
# A - Already 2018

S = input()
print("2018" + S[4:])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for mid in B:
    n_bottom = len(C[bisect.bisect_right(C,mid):])
    n_top = len(A[:bisect.bisect_left(A,mid)])
    ans += n_bottom * n_top

print(ans)

Fixed submission:
import bisect

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for mid in B:
    n_bottom = N - bisect.bisect_right(C,mid)
    n_top = bisect.bisect_left(A,mid)
    ans += n_bottom * n_top

print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()

s_no_x = ""
for i in range(len(s)):
    if s[i] != "x":
        s_no_x += s[i]

if s_no_x != s_no_x[::-1]:
    print(-1)
    exit()

if len(s_no_x) % 2 == 0:
    non_x_count = 0
    for i in range(len(s)):
        if s[i] != "x":
            non_x_count += 1
        if non_x_count == len(s_no_x)//2:
            s1 = s[:i]
        if non_x_count == len(s_no_x)//2 + 1:
            s2 = s[i+1:]
            break
else:
    non_x_count = 0
    for i in range(len(s)):
        if s[i] != "x":
            non_x_count += 1
        if non_x_count == len(s_no_x)//2 + 1:
            s1 = s[:i]
            s2 = s[i+1:]
            break

ans = abs(len(s1) - len(s2))
for i in range(min(len(s1), len(s2))):
    if s[i] != s[-i-1]:
        ans += 1

print(ans)

Fixed submission:
s = input()

l = 0
r = len(s)-1
ans = 0

while l < r:
    if s[l] != s[r]:
        if s[l] == "x":
            ans += 1
            l += 1
        elif s[r] == "x":
            ans += 1
            r -= 1
        else:
            print(-1)
            exit()
    else:
        l += 1
        r -= 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

N = int(input())
T = [int(input()) for _ in range(N)]

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm_list(T))

Fixed submission:
import fractions
from functools import reduce

N = int(input())
T = [int(input()) for _ in range(N)]

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm_list(T))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

if N == 1:
    if A[0] == K:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    exit()

if K > max(A):
    print("IMPOSSIBLE")
    exit()

A = list(set(A))
N = len(A)
A.sort()

min_diff = min([A[i] - A[i-1] for i in range(1,N)])

for i in range(N):
    if abs(A[i]-K) % min_diff == 0:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")

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

A = list(set(A))
N = len(A)
A.sort()

if K > max(A):
    print("IMPOSSIBLE")
    exit()

if N == 1:
    if A[0] == K:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    exit()

min_diff = min([A[i] - A[i-1] for i in range(1,N)])

for i in range(N):
    if abs(A[i]-K) % min_diff == 0:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
# C - Bugged
# DP Overkill

N = int(input())
s = [int(input()) for _ in range(N)]

dp = [0] + [-1]*sum(s)

while s:
    x = s.pop()
    for idx in reversed(range(len(dp))):
        if dp[idx] != -1 and idx + x <= len(dp) - 1:
            dp[idx+x] = dp[idx] + x
            
dp = set(dp)
dp.remove(-1)
dp = list(dp)
dp.sort(reverse = True)

for idx in range(len(dp)):
    if idx == len(dp) - 1:
        print(0)
    elif dp[idx] % 10 > 0:
        print(dp[idx])
        break

Fixed submission:
# C - Bugged

N = int(input())
s = [int(input()) for _ in range(N)]

mod10 = [x%10 for x in s]
fraction = [x for x in s if x%10 > 0]

if len(set(mod10)) == 1 and mod10[0] == 0:
    print(0)
elif sum(mod10)%10 > 0:
    print(sum(s))
else:
    print(sum(s) - min(fraction))