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

Fixed submission:
#!/usr/bin/env python
# vim:fileencoding=utf-8

import sys

n = int(sys.stdin.readline().strip())

if n == 1:
    print("Hello World")
elif n == 2:
    i = int(sys.stdin.readline().strip())
    j = int(sys.stdin.readline().strip())
    print(i + j)

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

N = int(sys.stdin.readline().strip())

set_list = []
for line in sys.stdin.readlines():
    x, y, h = list(map(int, line.strip().split()))
    ans_set = set()
    for Cx, Cy in itertools.product(range(101), range(101)):
        dx = abs(x - Cx)
        dy = abs(y - Cy)
        d = dx + dy
        H = h + d
        # if H >= d:
        if H >= 1:
            ans_set.add((Cx, Cy, H))
    set_list.append(ans_set)

ans_set = set_list[0]
if len(set_list) > 1:
    for s in set_list[1:]:
        ans_set = ans_set & s

if len(ans_set) == 1:
    Cx, Cy, H = list(ans_set)[0]
    print(Cx, Cy, H)
#else:
#    for s in set_list:
#        Cx, Cy, H = list(ans_set)[0]
#        if H >= 1:
#            print(Cx, Cy, H)
Problem p02995 (python)

Fixed submission:
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


A, B, C, D = map(int, input().strip().split())

a_c = A // C
a_c_mod = A % C
b_c = B // C
a_d = A // D
a_d_mod = A % D
b_d = B // D

l = lcm(C, D)

a_cd = A // l
a_cd_mod = A % l
b_cd = B // l

if a_c_mod == 0:
    a_c -= 1

if a_d_mod == 0:
    a_d -= 1

if a_cd_mod == 0:
    a_cd -= 1

print((B - A + 1) - (b_c - a_c) - (b_d - a_d) + (b_cd - a_cd))

Buggy submission (verdict: Runtime Error):
import math


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


A, B, C, D = map(int, input().strip().split())

a_c = A // C
a_c_mod = A % C
b_c = B // C
a_d = A // D
a_d_mod = A % D
b_d = B // D

l = lcm(C, D)

a_cd = A // l
a_cd_mod = A % l
b_cd = B // l

if a_c_mod == 0:
    a_c -= 1

if a_d_mod == 0:
    a_d -= 1

if a_cd_mod == 0:
    a_cd -= 1

print((B - A + 1) - (b_c - a_c) - (b_d - a_d) + (b_cd + a_cd))
Problem p03471 (python)

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

N = l[0]
Y = l[1]
ans = [-1,-1,-1]

if Y/10000 <= N:
    for i in range(int(Y/10000)+1):
        a = i
        n = N - a
        Y1 = Y - (a * 10000)
        if Y1/5000 <= n:
            for j in range(int(Y1/5000)+1):
                b = j
                c = n - j
                if 10000 * a + 5000 * b + 1000 * c == Y:
                    ans = [a,b,c]

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

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

N = l[0]
Y = l[1]
ans = [-1,-1,-1]

if Y/10000 < N:
    for i in range(int(Y/10000)+1):
        a = i
        n = N - a
        Y1 = Y - (a * 10000)
        if Y1/5000 < n:
            for j in range(int(Y1/5000)+1):
                b = j
                c = n - j
                if 10000 * a + 5000 * b + 1000 * c == Y:
                    ans = [a,b,c]

print(" ".join(ans))

Buggy submission (verdict: Runtime Error):
l = list(map(int, input().split()))                     
                                                        
N = l[0]                                                
Y = l[1]                                                
ans = [-1,-1,-1]                                        
                                                        
if Y/10000 < N:                                         
    for i in range(int(Y/10000)+1):                     
a = i                                           
n = N - a                                       
Y1 = Y - (a * 10000)                            
if Y1/5000 < n:                                 
for j in range(int(Y1/5000)+1):             
b = j                                   
c = n - j                               
if 10000 * a + 5000 * b + 1000 * c == Y:
ans = [a,b,c]                       
                                                        
print(ans)

Buggy submission (verdict: Runtime Error):
l = list(map(int, input().split()))                     
                                                        
N = l[0]                                                
Y = l[1]                                                
ans = [-1,-1,-1]                                        
                                                        
if Y/10000 < N:                                         
    for i in range(int(Y/10000)+1):                     
    ¦   a = i                                           
    ¦   n = N - a                                       
    ¦   Y1 = Y - (a * 10000)                            
    ¦   if Y1/5000 < n:                                 
    ¦   ¦   for j in range(int(Y1/5000)+1):             
    ¦   ¦   ¦   b = j                                   
    ¦   ¦   ¦   c = n - j                               
    ¦   ¦   ¦   if 10000 * a + 5000 * b + 1000 * c == Y:
    ¦   ¦   ¦   ¦   ans = [a,b,c]                       
                                                        
print(ans)
Problem p03545 (python)

Fixed submission:
import numpy as np

s = [w for w in input()]
length = len(s)

for i in range(2 ** (length-1)):
    b = format(i, 'b')
    b_len = len(b)
    pad_width = ((length-1) - b_len, 0)
    b_pad = np.pad([int(n) for n in b], pad_width, 'constant')
    score = int(s[0])
    result = s[0]
    for flag, num in zip(b_pad, s[1:]):
        if flag == 1:
            score += int(num)
            result += '+' + num
        else:
            score -= int(num)
            result += '-' + num

    if score == 7:
        print(result+'=7')
        break

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

s = [w for w in input()]
length = len(s)

for i in range(2 ** (length-1)):
    b = format(i, 'b')
    b_len = len(b)
    pad_width = ((length-1) - b_len, 0)
    b_pad = np.pad([int(n) for n in b], pad_width, 'constant')
    score = int(s[0])
    result = s[0]
    for flag, num in zip(b_pad, s[1:]):
        if flag == 1:
            score += int(num)
            result += '+' + num
        else:
            score -= int(num)
            result += '-' + num

    if score == 7:
        print(result+'=7')
        break
Problem p03047 (python)

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

print(N-K+1)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
cnt = 0
for k in range(1,math.floor(math.sqrt(N)) + 1):
  if N % k == 0 and N // k > k + 1:
    cnt += N // k - 1
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
 
cnt = 0
list = [0,0,0]
 
for i in range(N):
    s = input()
    cnt += s.count('AB')
    if s[0] == 'B' and s[-1] == 'A':
        list[0] += 1
    elif s[-1] == 'A':
        list[1] += 1
    elif s[0] == 'B':
        list[2] += 1
 
min_ = min(list[0],list[1],list[2])
 
if min_ >= 1:
    cnt += 2*min_
    list[0] -= min_
    list[1] -= min_
    list[2] -= min_
 
if list[0] >= 2:
    cnt += 2*list[0]//2
    list[0] -= 2*(list[0]//2)
 
if list[1] == list[2]:
    cnt += list[1]
elif list[1] > list[2]:
    cnt += list[2] + min(list[0],list[1]-list[2])
elif list[1] < list[2]:
    cnt += list[1] + min(list[0],list[2]-list[1])
 
print(cnt)
Problem p03069 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

N = int(input())
S = input()

result = S.count('.')
r = result
def dfs(i):
    global result
    global r
    if i == N:
        return float('inf')
    if S[i] == '#':
        r += 1
    else:
        r -= 1
    result = min(result,r)
    return min(result,dfs(i+1))

print(dfs(0))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()

result = S.count('.')
r = result
def dfs(i):
    global result
    global r
    if i == N:
        return float('inf')
    if S[i] == '#':
        r += 1
    else:
        r -= 1
    result = min(result,r)
    return min(result,dfs(i+1))

print(dfs(0))
Problem p03103 (python)

Fixed submission:
N,M = map(int,input().split())

list = [list(map(int,input().split())) for i in range(N) ]

list.sort()
sum = 0
cnt = 0

for A,B in list:
    if cnt + B >= M:
        sum += A*(M - cnt)
        cnt += M - cnt
        break
    sum += A*B
    cnt += B

print(sum)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)

N,M = map(int,input().split())
list = [list(map(int,input().split())) for i in range(N)]
list.sort(key=lambda x:x[0])

def dfs(m,cnt):
    if m <= 0 or cnt == len(list):
        return 0
    b = list[cnt][1] if list[cnt][1] < m else m
    a = b*list[cnt][0]

    return a + dfs(m-b,cnt+1)

print(dfs(M,0))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
list = [list(map(int,input().split())) for i in range(N)]
list.sort()

def dfs(m,cnt):
    if cnt >= len(list):
        return 0
    b = list[cnt][1] if list[cnt][1] < m else m
    a = b*list[cnt][0]
    if m - b < 0 :
        return 0

    return a + dfs(m-b,cnt+1)

print(dfs(M,0))

Buggy submission (verdict: Runtime Error):
from math import ceil
N,M = map(int,input().split())
list = [list(map(int,input().split())) for i in range(N)]
list.sort(key=lambda x:x[0])

def dfs(m,cnt):
    if m <= 0 or cnt == len(list):
        return 0
    b = list[cnt][1] if list[cnt][1] < m else m
    a = b*list[cnt][0]

    return a + dfs(m-b,cnt+1)

print(dfs(M,0))
Problem p03110 (python)

Fixed submission:
N = int(input())

total = 0
for i in range(N):
    a,b = map(str,input().split())
    if b == 'JPY':
        total += float(a)
    elif b == 'BTC':
        total += float(a)*380000

print(total)

Buggy submission (verdict: Runtime Error):
N = int(input())

total = 0
for i in range(N):
    a,b = map(str,raw_input().split())
    if b == 'JPY':
        total += float(a)
    elif b == 'BTC':
        total += float(a)*380000

print(total)
Problem p03244 (python)

Fixed submission:
from collections import Counter

n = int(input())
v = [int(i) for i in input().split()]

ki = v[::2]
gu = v[1::2]

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

ans = 0

if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n / 2)
    else:
        if ki[1][1] > gu[1][1]:
            ans = n - ki[1][1] - gu[0][1]
        else:
            ans = n - ki[0][1] - gu[1][1]
else:
    ans = n - ki[0][1] - gu[0][1]

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
list = [int(i) for i in input().split()]

list_odd = list[::2]
list_even = list[1::2]

def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v,k) for k,v in dict.items()]

cnt_odd = sorted(cnt_element(list_odd),reverse=True)
cnt_even = sorted(cnt_element(list_even),reverse=True)

#最頻値が同じの場合
if cnt_odd[0][1] == cnt_even[0][1]:
    #リスト内の値が１つの場合
    if len(cnt_odd) == len(cnt_even) == 1:
        ans = 1
    #リストが２つ以上の場合
    else:
        #第２最頻値の出現数が奇数の方が多い
        if cnt_odd[1][0] > cnt_even[1][0]:
            ans = n - cnt_odd[1][0] - cnt_even[0][0]
        #第二２最頻値の出現数が偶数の方が多い
        elif cnt_odd[1][0] < cnt_even[1][0]:
            ans = n - cnt_odd[0][0] - cnt_even[1][0]
#最頻値が異なる場合
else:
    ans = n - cnt_odd[0][0] - cnt_even[0][1]

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
list = [int(i) for i in input().split()]

list_odd = list[::2]
list_even = list[1::2]

def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v,k) for k,v in dict.items()]

cnt_odd = sorted(cnt_element(list_odd),reverse=True)
cnt_even = sorted(cnt_element(list_even),reverse=True)

if len(cnt_odd) == len(cnt_even) == 1:
    if cnt_even[0][1] != cnt_odd[0][1]:
        ans = 0
    elif cnt_even[0][1] == cnt_odd[0][1]:
        ans = int(n / 2)
elif cnt_even[0][1] != cnt_odd[0][1]:
    ans = n - cnt_odd[0][0] - cnt_even[0][0]

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
list = [int(i) for i in input().split()]

list_odd = list[::2]
list_even = list[1::2]

def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v,k) for k,v in dict.items()]

cnt_odd = sorted(cnt_element(list_odd),reverse=True)
cnt_even = sorted(cnt_element(list_even),reverse=True)
print(cnt_odd)
print(cnt_even)

if len(cnt_odd) == len(cnt_even) == 1
    if cnt_even[0][1] != cnt_odd[0][1]:
        ans = 0
    elif cnt_even[0][1] == cnt_odd[0][1]:
        ans = int(n / 2)
elif cnt_even[0][1] != cnt_odd[0][1]:
    ans = n - cnt_odd[0][0] - cnt_even[0][0]

print(ans)
Problem p03251 (python)

Fixed submission:
N,M,X,Y = map(int, input().split())
num_list = [list(map(int, input().split())) for _ in range(2)]

Z = list(range(X+1,Y+1))

for z in Z:
    if max(num_list[0]) < z and min(num_list[1]) >= z:
        print('No War')
        break
    if z == Z[-1]:
        print('War')

Buggy submission (verdict: Runtime Error):
N,M,X,Y = map(int, input().split())
num_list = [list(map(int, input().split())) for _ in range(2)]
 
x_max = max(num_list[0])
y_min = min(num_list[1])
 
if x_max >= y_max:
    print('War')
elif x_max < X or y_max > Y:
    print('War')
else:
    print('No war')

Buggy submission (verdict: Runtime Error):
N,M,X,Y = map(int, input().split())
num_list = [list(map(int, input().split())) for _ in range(M)]

Z = list(range(X+1,Y+1))

for z in Z:
    if max(num_list[0]) < z and min(num_list[1]) >= z:
        print('No War')
        break
    if z == Z[-1]:
        print('War')
Problem p03260 (python)

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

if A * B % 2 == 1:
    print('Yes')
else:
 print('No')

Buggy submission (verdict: Runtime Error):
from itertools import product
 
H, W = map(int, input().split())
 
a = [ list(map(int, input().split())) for _ in range(H) ]
 
output = ''
direction = -1
idou = 0
last_i = 0
last_j = 0
count = 0
j = -1
for i in range(H):
    direction *= -1
    j += direction
    for _ in range(W):
        if idou == 1:
            count += 1
            output += '{} {} {} {}\n'.format(last_i+1, last_j+1, i+1, j+1)
        if (a[i][j] + idou) % 2 == 1:
            idou = 1
        else:
            idou = 0
        last_i = i
        last_j = j
        j += direction
 
output = str(count) + '\n' + output.strip()
print(output)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())

for i in range(1,4):
    if A * B * i % 2 == 1:
        print('Yes')
        break

print('No')
Problem p03261 (python)

Fixed submission:
N = int(input())
W = [input() for i in range(N)]

stock = []
last = W[0][0]

for i in range(0,len(W)):
    #過去の発言に含まれない
    if W[i] in stock:
        print('No')
        break
    #前の単語の最後と次の単語の最初が一致する
    if W[i][0] != last:
        print('No')
        break
    stock.append(W[i])
    last = W[i][-1]
    #最後まで回り切ったらyesを表示
    if i+1 == len(W):
        print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
W = [input() for i in range(N)]

word_stock = []

for word in word_list:
    #同じワード確認
    if word in word_stock:
        print('No')
    #最後の文字確認
    try:
        if word_stock[-1][-1] != word[0]:
            print('No')
    except:
        pass
    word_stock.append(word)

print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
W = [input() for i in range(N)]

for word in word_list:
    #同じワード確認
    if word in word_stock:
        print('No')
    #最後の文字確認
    try:
        if word_stock[-1][-1] != word[0]:
            print('No')
    except:
        pass
    word_stock.append(word)

print('Yes')

Buggy submission (verdict: Runtime Error):
for word in word_list:
    #同じワード確認
    if word in word_stock:
        print('No')
    #最後の文字確認
    try:
        if word_stock[-1][-1] != word[0]:
            print('No')
    except:
        pass
    word_stock.append(word)

print('Yes')
Problem p03262 (python)

Fixed submission:
import functools as ft
 
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
 
def gcd_list(numbers):
    return ft.reduce(gcd,numbers)
 
N, X = map(int, input().split(" "))
Xi = [int(a) for a in input().split()]
 
def MinusX(Xi_):
    return abs(Xi_-X)
 
def main(Xi):
    Xi = map(MinusX,Xi)
    output = gcd_list(Xi)
    print(output)
 
if __name__ == "__main__":
    main(Xi)

Buggy submission (verdict: Runtime Error):
N,X = map(int,input().split())
list = [int(x) for x in input().split()]
list_dist = sorted([abs(x - X) for x in list])

def gcd(a, b):
    if a < b:
        a , b = b , a
    while b:
        a, b = b, a % b
    return a

ans = list_dist[0]

for x in list_dist[1:]:
    result = gcd(result,x)

print(result)

Buggy submission (verdict: Runtime Error):
N,X = map(int,input().split())
list = [int(x) for x in input().split()]
list_dist = sorted([abs(x - X) for x in list])

def gcd(a, b):
    if a < b:
        a,b = b,a
    while b:
        a, b = b, a % b
    return a

print(gcd(list_dist[0],list_dist[1]))

Buggy submission (verdict: Runtime Error):
N, X = list(map(int, input().split())) # 整数
list_temp = []
list_temp.append(list(map(int, input().split())))

list = list_temp[0]
list_dev = []

#公約数の関数作成
def devisor(x):
    list_div = []
    for i in range(1,x+1):
        if x % i == 0:
            list_div.append(i)
    return list_div

#xiとXの絶対値をとって、各絶対値の最大公約数を算出
for i in list:
    abs_temp = abs(i - X)
    list_dev += devisor(abs_temp)

l_dupli = [i for i in set(list_dev) if list_dev.count(i) > 2]
print(l_dupli[-1])
Problem p03264 (python)

Fixed submission:
K = int(input())
list = [i for i in range(1, K + 1)]
odd = list[1::2]
even = list[0::2]

cnt = 0

for i in odd:
    for j in even:
        cnt += 1

print(cnt)

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

if k%2==1:
    ans = (n//k)**3
else:
    even = n//k
    odd  = (2*n)//k - even
    ans = even**3 + odd**3
print(ans)

Buggy submission (verdict: Runtime Error):
list = [i for i in range(1, K + 1)]
odd = list[1::2]
even = list[0::2]

cnt = 0

for i in odd:
    for j in even:
        cnt += 1

print(cnt)
Problem p03273 (python)

Fixed submission:
H, W = map(int, input().split())
list = []
for i in range(H):
    list.append(input())

new_list = []

H_del = []
W_del = []

#削除する行列の探索
for i in range(H):
    if list[i] == '.'*W:
        W_del.append(i)

for i in range(W):
    H_stock = ''
    for j in range(H):
        H_stock += list[j][i]
        if H_stock == '.'*H:
            H_del.append(i)

#削除する行列を除いた行列を再作成
for i in range(H):
    if i not in W_del:
        W_list = ''
        for j in range(W):
            if j not in H_del:
                W_list += list[i][j]
        new_list.append(W_list)

#答えを表示
for i in range(len(new_list)):
    print(new_list[i])

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
list = []
for i in range(H):
    list.append(input())

new_list = []

H_del = []
W_del = []

#削除する行列の探索
for i in range(W):
    if list[i] == '.'*W:
        W_del.append(i)
    H_stock = ''
    for j in range(H):
        H_stock += list[j][i]
        if H_stock == '.'*H:
            H_del.append(i)

#削除する行列を除いた行列を再作成
for i in range(W):
    if i not in W_del:
        W_list = ''
        for j in range(H):
            if j not in H_del:
                W_list += list[i][j]
        new_list.append(W_list)

#答えを表示
for i in range(len(new_list)):
    print(new_list[i])
Problem p03032 (python)

Fixed submission:
from heapq import heappush, heappop, heapify

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

# N jewels in dequeue D
# at most K operations
# 1 <= N <= 50
# 1 <= K <= 100
# -10000000 <= Vi <= 10000000

# Operation A, B: Remove left or right
# Operation C, D: Add to left or right

S = 0
for take in range(min(N, K) + 1):
    for takeL in range(take + 1):
        for takeR in range(take - takeL + 1):
            hand = []
            for i in range(takeL):
                heappush(hand, V[i])
            for i in range(takeR):
                if N - i - 1 < takeL:
                    break
                heappush(hand, V[N- i - 1])
            S = max(sum(hand), S)
            for _ in range(K - take):
                if not hand or hand[0] >= 0:
                    break
                heappop(hand)
                S = max(sum(hand), S)
print(S)

Buggy submission (verdict: Runtime Error):
from heapq import heappush, heappop, heapify

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

# N jewels in dequeue D
# at most K operations
# 1 <= N <= 50
# 1 <= K <= 100
# -10000000 <= Vi <= 10000000

# Operation A, B: Remove left or right
# Operation C, D: Add to left or right

S = 0
for take in range(K):
    for takeL in range(take + 1):
        for takeR in range(take - takeL + 1):
            hand = []
            for i in range(takeL):
                if i >= len(V):
                    break
                heappush(hand, V[i])
            for i in range(takeR):
                if N - i - 1 >= len(V):
                    break
                heappush(hand, V[N- i - 1])
            for i in range(K - take):
                if not hand:
                    break
                heappop(hand)
                s = sum(hand)
                S = max(s, S)
print(S)

Buggy submission (verdict: Runtime Error):
from heapq import heappush, heappop, heapify

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

# N jewels in dequeue D
# at most K operations
# 1 <= N <= 50
# 1 <= K <= 100
# -10000000 <= Vi <= 10000000

# Operation A, B: Remove left or right
# Operation C, D: Add to left or right

S = 0
for take in range(K):
    for takeL in range(take + 1):
        for takeR in range(take - takeL + 1):
            hand = []
            for i in range(takeL):
                heappush(hand, V[i])
            for i in range(takeR):
                heappush(hand, V[N- i - 1])
            for i in range(K - take):
                if not hand:
                    break
                heappop(hand)
                s = sum(hand)
                S = max(s, S)
print(S)
Problem p03559 (python)

Fixed submission:
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
A.sort()
B.sort()
C.sort()
# print(A, B, C)
for b in B:
    a_i = bisect.bisect_left(A, b)
    c_i = bisect.bisect_right(C, b)
    cnt = (a_i) * (N - c_i)
    # print(b, a_i, c_i, cnt)
    ans += cnt

print(ans)

Buggy submission (verdict: Runtime Error):
import bisect

N = int(input())
A = list(set(map(int, input().split())))
B = list(set(map(int, input().split())))
C = list(set(map(int, input().split())))
ans = 0
A.sort()
B.sort()
C.sort()
# print(A, B, C)
for i in range(N):
    b = B[i]
    a_i = bisect.bisect_left(A, b)
    c_i = bisect.bisect_right(C, b)
    cnt = (a_i) * (N - c_i)
    # print(b, a_i, c_i, cnt)
    ans += cnt

print(ans)
Problem p03584 (python)

Fixed submission:
N, K = map(int, input().split())
A, B, a = [0] * N, [0] * N, [''] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
    a[i] = str(bin(A[i])[2:]).rjust(30, '0')
k = str(bin(K)[2:]).rjust(30, '0')

ans = 0

s = k.index('1') if '1' in k else 30
for r in range(s, 30 + 1):
    tmp = 0
    for i in range(N):
        if r < 30 and k[r] == '0':
            continue
        affordable = True
        for j in range(r):
            if k[j] == '0' and a[i][j] == '1':
                affordable = False
        if r < 30 and a[i][r] == '1':
            affordable = False
        if affordable:
            tmp += B[i]
    ans = max(ans, tmp)

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A, B, a = [0] * N, [0] * N, [''] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
    a[i] = str(bin(A[i])[2:]).rjust(30, '0')
k = str(bin(K)[2:]).rjust(30, '0')

ans = 0

s = k.index('1')
for r in range(s, 30 + 1):
    tmp = 0
    for i in range(N):
        affordable = True
        for j in range(r):
            if k[j] == '0' and a[i][j] == '1':
                affordable = False
        if r < 30 and a[i][r] == '1':
            affordable = False
        if affordable:
            tmp += B[i]
    ans = max(ans, tmp)

print(ans)