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

Fixed submission:
import math
a=int(input())
b=math.floor(float(a/2))
print(float((a-b)/a))

Buggy submission (verdict: Runtime Error):
import math
a=int(input())
b=math.floor(float(a/2))
print({}.format(float((a-b)/a)))

Buggy submission (verdict: Runtime Error):
import math
a=int(input())
b=math.floor(float(a/2))
print({}.format(float((a-b)/a)))

Buggy submission (verdict: Runtime Error):
a = int(input())
if a = 1:
  print(a)
elif a%2 = 0:
  print(0.5)
else:
  print(f'({int(a/2)}+1)/{a}')

Buggy submission (verdict: Runtime Error):
a=int(input())
if a = 1:
  print(a)
elif a%2 = 0:
  print(1/2)
else:
  print((int(a/2)+1)/a)

Buggy submission (verdict: Runtime Error):
a = int(input())
if a = 1:
  print(a)
elif a%2 = 0:
  print(0.5)
else:
  print((int(a/2)+1)/a)

Buggy submission (verdict: Runtime Error):
a = int(input())
if a = 1:
  print(a)
elif int(a/2) = 0:
  print((a/2)/a)
else:
  print((int(a/2)+1)/a)

Buggy submission (verdict: Runtime Error):
a=int(input())
if a = 1:
  print(a)
elif int(a/2) = 0:
  print((a/2)/a)
else:
  print((int(a/2)+1)/a)

Buggy submission (verdict: Runtime Error):
a=int(input())
if a = 1:
  print(a)
elif int(a/2)=0:
  print((a/2)/a)
else:
  print((int(a/2)+1)/a)

Buggy submission (verdict: Runtime Error):
a=int(input())
if a=1:
  print(a)
elif a//2=0:
  print((a/2)/a)
else:
  print((int(a/2)+1)/a)

Buggy submission (verdict: Runtime Error):
a=int(input())
if a=1:
  print(a)
elif int(a/2)=0:
  print((a/2)/a)
else:
  print((int(a/2)+1)/a)

Buggy submission (verdict: Runtime Error):
a=int(input())
if a=1:
  print(a)
elif a%2==0:
  print((a/2)/a)
else:
  print((int(a/2)+1)/a)

Buggy submission (verdict: Runtime Error):
a=int(input())
if a=1:
  print(a)
elif a%2==0:
  print((a/2)/a)
else:
  print(-(-a//2)/a)

Buggy submission (verdict: Runtime Error):
a=input(int())
if a=1:
  print(a)
elif a%2==0:
  print((a/2)/a)
else:
  print(-(-a//2)/a)

Buggy submission (verdict: Runtime Error):
a=input()
if a=1:
  print(1)
elif a%2==0:
  print(0.5)
else:
  print(-(-a//2)/a)
Problem p02915 (python)

Fixed submission:
a=int(input())
print(a*a*a)

Buggy submission (verdict: Runtime Error):
a=int,input()
print(a^3)
Problem p02970 (python)

Fixed submission:
N,D = map(int,input().split())
a = N//(2*D+1)
if N%(2*D+1) == 0:
	print(a)
else:
 	print(a+1)

Buggy submission (verdict: Runtime Error):
N,D = map(int,input(),split())
a = (N-1)//(2*D)
if (N-1)%(2*D) == 0:
	print(a)
else:
 	print((N-1)//(2*D+1))

Buggy submission (verdict: Runtime Error):
N,D = map(int,input(),split())
a = (N-1)/(2*D)
if (N-1)%(2*D)==0:
	print(a)
else:
 	print((N-1)//(2*D+1))

Buggy submission (verdict: Runtime Error):
N,D = map(int,input(),split()))
a = (N-1)/(2*D)
if (N-1)%(2*D)==0:
	print(a)
else :
 	print((N-1)//2*D+1)
Problem p02723 (python)

Fixed submission:
s = input()

if((s[2]==s[3]) and (s[4]==s[5])):
  	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
s = input()

if((s[3]==s[4]) and (s[5]==s[6])):
  	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
s = input()

if((s[3]==s[4]) and (s[5]==s[6])):
  	print("yes")
else:
	print("no")

Buggy submission (verdict: Runtime Error):
s=input()

if (s[3]==s[4] and s[5]==s[6]):
	print("yes")
	else:
    print("no")

Buggy submission (verdict: Runtime Error):
s=input()

if s[3]==s[4] and s[5]==s[6]:
	print("sはcoffeeと似ています")
	else:
    print("sはcoffeeと似ていません")

Buggy submission (verdict: Runtime Error):
s=input()

if s[3]==s[4] and s[5]==s[6];
	print("sはcoffeeと似ています")
	else;
    print("sはcoffeeと似ていません")

Buggy submission (verdict: Runtime Error):
s=input()

if s[3]==s[4] and s[5]==s[6];
	print("sはcoffeeと似ています")
	else
    print("sはcoffeeと似ていません")

Buggy submission (verdict: Runtime Error):
s=input()

if s[3]==s[4] and s[5]==s[6]
	print("sはcoffeeと似ています")
	else
    print("sはcoffeeと似ていません")
Problem p02897 (python)

Fixed submission:
#整数で受け取る
N = int(input())

number = 0
#奇数の数を数える
for i in range(1, N+1):
    if i % 2 != 0:
        number += 1

result = number / N

print(result)

Buggy submission (verdict: Runtime Error):
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

lst1 = []
lst2 = []
A1,B1 = map(int, input().split(" "))

A = factorization(A1)
B = factorization(B1)

for i in range(len(A)):
    lst1.append(A[i][0])

for i in range(len(B)):
    lst2.append(B[i][0])
# print(lst1)
# print(lst2)

lst1_set = set(lst1)
lst2_set = set(lst2)

result_set = lst1_set & lst2_set


# print(result_set)
if A1 == 0 or B1 == 0:
    print(0)
elif A1 == 1 and B1 == 1:
    print(1)
else:
    print(len(result_set) + 1)

Buggy submission (verdict: Runtime Error):
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

lst1 = []
lst2 = []
A1,B1 = map(int, input().split(" "))

A = factorization(A1)
B = factorization(B1)

for i in range(len(A)):
    lst1.append(A[i][0])

for i in range(len(B)):
    lst2.append(B[i][0])
# print(lst1)
# print(lst2)

lst1_set = set(lst1)
lst2_set = set(lst2)

result_set = lst1_set & lst2_set


# print(result_set)
if (A1 == 0 or B1 == 0):
    print(0)
else:
    print(len(result_set) + 1)
Problem p02915 (python)

Fixed submission:
N = int(input())

result = N*N*N 

print(result)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split(" ")))  #食べた順番
B = list(map(int,input().split(" "))) #満足度
C = list(map(int,input().split(" ")) )#追加満足度


#満足度を足し合わせていく
manzoku = 0
for i in range(N):
    manzoku += B[A[i]-1]
    
    if i != 0 and (A[i] ==A[i-1] + 1):
        manzoku += C[A[i-1]-1]
        



print(manzoku)
Problem p02835 (python)

Fixed submission:
print('bust'if sum(map(int,input().split()))>=22else 'win')

Buggy submission (verdict: Runtime Error):
if sum(map(int,input().split()))<22:
 print("win")
else print("bust")

Buggy submission (verdict: Runtime Error):
if sum(map(int,input().split())<22:
 print("win")
else print("bust")

Buggy submission (verdict: Runtime Error):
a,b,c=int(input().split)
if a+b+c>21:
    print("bust")
else print("win")

Buggy submission (verdict: Runtime Error):
a,b,c=input().split
if a+b+c>21:
    print("bust")
else print("win")

Buggy submission (verdict: Runtime Error):
a,b,c=input().split
if a+b+c>21:
    print(“bust”)
else print(“win”)
Problem p02829 (python)

Fixed submission:
a = int(input())
b = int(input())
print(6-a-b)

Buggy submission (verdict: Runtime Error):
a, b = map(int,input().split())
ans = 6-a-b
print(ans)

Buggy submission (verdict: Runtime Error):
a, b = map(int,input().split())
print(6-a-b)
Problem p02847 (python)

Fixed submission:
day = {"SUN":7, "MON":6, "TUE":5, "WED":4, "THU":3, "FRI":2, "SAT":1}
s = input()
print(day[s])

Buggy submission (verdict: Runtime Error):
day = {"SUN":7, "MON":6, "TUE":5, "WED":4, "THU":3, "FRY":2, "SAT":1}
s = input()
print(day[s])
Problem p03011 (python)

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

print(sum(a) - max(a))

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

print(sum(a,b,c) - max(a,b,c))
Problem p03013 (python)

Fixed submission:
n,m = map(int,input().split())
broken = [True] * (n+1)
for _ in range(m):
    broken[int(input())] = False

mod = 10 ** 9 + 7

dp = [0] * (n+1)
dp[-1] = 1
if broken[n-1]:
    dp[n-1] = 1

for i in reversed(range(n-1)):
    if broken[i]:
        dp[i] = (dp[i+1] + dp[i+2]) % mod
        
print(dp[0])

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10000)

n, m = map(int, input().split())
broken = []
for i in range(m):
    broken.append(int(input()))
    if len(broken) > 1 and broken[-2] + 1 == broken[-1]:
        print(0)
        exit()
    

dp = [-float('inf')] * (n + 1)

def rec(i):
    global dp
    if dp[i] > -float('inf'):
        return dp[i]
      
    if i in broken:
        return 0
    
    if i >= n - 1:
        return 1
    
    dp[i] = rec(i + 1) + rec(i + 2)
    
    return dp[i]
            
print(rec(0)%1000000007)

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10000)

n, m = map(int, input().split())
broken = []
for i in range(m):
    broken.append(int(input()))
    if len(broken) > 1 and broken[-2] + 1 == broken[-1]:
        print(0)
        exit()
    

dp = [0] * (n + 1)

def rec(i):
    global dp
    if dp[i] > 0:
        return dp[i]
      
    if i in broken:
        return 0
    
    if i >= n - 1:
        return 1
    
    dp[i] = rec(i + 1) + rec(i + 2)
    
    return dp[i]
            
print(rec(0)%1000000007)

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(2000)

n, m = map(int, input().split())
broken = []
for i in range(m):
    broken.append(int(input()))
    if len(broken) > 1 and broken[-2] + 1 == broken[-1]:
        print(0)
        exit()
    

dp = [0] * (n + 1)

def rec(i):
    global dp
    if dp[i] > 0:
        return dp[i]
    
    if i >= n - 1:
        return 1
    
    if i in broken:
        return 0
    
    dp[i] = rec(i + 1) + rec(i + 2)
    
    return dp[i]
            
print(rec(0)%1000000007)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
broken = []
for i in range(m):
    broken.append(int(input()))
    if len(broken) > 1 and broken[-2] + 1 == broken[-1]:
        print(0)
        exit()
    

dp = [0] * (n + 1)
def rec(i):
    global dp
    if dp[i] > 0:
        return dp[i]
    
    if i >= n - 1:
        return 1
    
    if i in broken:
        return 0
    
    dp[i] = rec(i + 1) + rec(i + 2)
    
    return dp[i]
            
print(rec(0)%1000000007)
Problem p03075 (python)

Fixed submission:
a = list(map(int,[input() for i in range(6)]))

if max(a[:-1]) - min(a[:-1]) > a[-1]:
  print(":(")
else:
  print("Yay!")

Buggy submission (verdict: Runtime Error):
a = list(map(int,[input() for i in range(5)]))

if max(a[-1]) - min(a[-1]) > a[-1]:
  print(":(")
else:
  print("Yay!")

Buggy submission (verdict: Runtime Error):
a = list(map(int,[input() for i in range(4)]))

if max(a[-1]) - min(a[-1]) > a[-1]:
  print(":(")
else:
  print("Yay!")

Buggy submission (verdict: Runtime Error):
a = list(map(int,i for i in input()))

if max(a[-1]) - min(a[-1]) > a[-1]:
  print(":(")
else:
  print("Yay!")
Problem p03077 (python)

Fixed submission:
import math
n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
miti=[a,b,c,d,e]
mini=min(miti)
retu=math.ceil(n/mini)
print(4+retu)

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
miti= list([map(int,input()) for i in range(5)])
print(4+math.ceil(n/min(miti)))

Buggy submission (verdict: Runtime Error):
bimport math
n=int(input())
miti= list([int(input()) for i in range(5)])
print(4+math.ceil(n/min(miti)))

Buggy submission (verdict: Runtime Error):
bimport math
n=int(input())
miti= list([map(int,input()) for i in range(5)])
print(4+math.ceil(n/min(miti)))

Buggy submission (verdict: Runtime Error):
bimport math
n=int(input())
miti= list(map(int,[input() for i in range(5)]))
print(4+math.ceil(n/min(miti)))

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
miti=[a,b,c,d,e]
print(4+ceil(n/min(miti)))

Buggy submission (verdict: Runtime Error):
n = map(int,input())
a = list(map(int,[input() for i in range(5)]))
print(n // min(a) + 5)

Buggy submission (verdict: Runtime Error):
import math
n = map(int,input())
a = list(map(int,[input() for i in range(5)]))
print(floor(n / min(a)) + 5)

Buggy submission (verdict: Runtime Error):
import math
n = input()
a = list(map(int,[input() for i in range(5)]))
print(floor(n / min(a)) + 5)

Buggy submission (verdict: Runtime Error):
n = input()
a = list(map(int,[input() for i in range(5)]))
print((n // min(a)) + 5)

Buggy submission (verdict: Runtime Error):
n = input()
a = list(map(int,[input() for i in range(5)]))
b = n // min(a) + 5
print(b)

Buggy submission (verdict: Runtime Error):
n = input()
a = list(map(int,[input() for i in range(5)]))
print(n // min(a) + 5)

Buggy submission (verdict: Runtime Error):
from math import floor
n = input()
a = list(map(int,[input() for i in range(5)]))
print(floor(n / min(a)) + 5)

Buggy submission (verdict: Runtime Error):
from math import floor
n = input()
a = list(map(int,[input() for i in range(5)]))
print(floar(n / min(a)) + 5)

Buggy submission (verdict: Runtime Error):
n = input()
a = list(map(int,[input() for i in range(5)]))
print(floar(n / min(a)) + 5)
Problem p02815 (python)

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

mod = 10**9 + 7
c.sort()
ans = 0

for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2+n, mod) * (n-i-1) + pow(2, n-i-1+n, mod)) % mod
    ans %= mod

print(ans)

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

mod = 10**9 + 7
c.sort()
ans = 0

for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2, mod) * (n-i-1) + pow(2, n-i-1, mod)) % mod * pow(2, n, mod) % mod
    ans %= mod

print(ans)

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

mod = 10**9 + 7
c.sort()
ans = 0

for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2, mod) * (n-i-1) + pow(2, n-i-1, mod)) % mod * pow(2, n, mod) % mod
    ans %= mod

print(ans)

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

mod = 10**9 + 7
c.sort()
ans = 0

for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2, mod) * (n-i-1) + pow(2, n-i-1, mod) ) % mod * pow(2, n, mod) % mod
    ans %= mod

print(ans)

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

mod = 10**9 + 7
c.sort()
ans = 0

for i in range(n):
    ans += c[i] * pow(2, i, mod) % mod * (pow(2, n-i-2, mod) * (n-i-1) + pow(2, n-i-1, mod) ) % mod * pow(2, n, mod) % mod
    ans %= mod

print(ans)
Problem p02892 (python)

Fixed submission:
from collections import deque

class UnionFind:
    def __init__(self, n):
        self.rank = [0]*n
        self.parent = [i for i in range(n)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def merge(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        elif self.rank[x] > self.rank[y]:
            self.parent[y] = x
        else:
            self.parent[x] = y
            self.rank[y] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)



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

min_i = 0
min_count = n + 1
for i in range(n):
    count = 0
    for j in range(n):
        if s[i][j]:
            count += 1
    if count < min_count:
        min_count = count
        min_i = i

uf = UnionFind(n)

INF = 1001001001
ans = 0

for min_i in range(n):
    dist = [INF] * n
    dist[min_i] = 0
    q = deque([(min_i, 0, -1)])

    while q:
        v, d, p = q.popleft()
        box = []
        for nv in range(n):
            if s[v][nv] == '1':
                if nv == p:
                    continue
                if uf.same(v, nv):
                    print(-1)
                    exit()
                if d + 1 < dist[nv]:
                    dist[nv] = d + 1
                    q.append((nv, d + 1, v))
                    box.append(nv)
        for i in range(len(box) - 1):
            uf.merge(box[i], box[i + 1])
    ans = max(ans, max(dist) + 1)

print(ans)

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

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

# 二部グラフ判定
memo = [-1] * n
memo[0] = 0
q = deque((0, -1))
while q:
    v, p = q.popleft()
    for nv in range(n):
        if s[v][nv] == '1':
            if nv == p:
                continue
            if memo[nv] == -1:
                memo[nv] = (memo[v] + 1) % 2
                q.append((nv, v))
            else:
                if memo[nv] == memo[v]:
                    print(-1)
                    exit()

# ワーシャルフロイドでグラフの直径を求めてもよし
INF = float('inf')
dp = [[1 if c == '1' else INF for c in row] for row in s]

for i in range(n):
    dp[i][i] = 0

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])

dist = 0
for i in range(n):
    d = 0
    for j in range(n):
        d = max(d, dp[i][j])
    dist = max(d, dist)

print(dist+1)
Problem p03038 (python)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
b_c = [list(map(int, input().split())) for _ in range(m)]
b_c.sort(key=lambda x: x[1], reverse=True)

j = 0
for i in range(m):
    b = b_c[i][0]
    c = b_c[i][1]
    for _ in range(b):
        if j >= n:
            print(sum(a))
            exit()
        if a[j] < c:
            a[j] = c
            j += 1
        else:
            break

print(sum(a))

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

a.sort()
b_c = [list(map(int, input().split())) for _ in range(m)]
b_c.sort(key=lambda x: x[1], reverse=True)

j = 0
for i in range(m):
    b = b_c[i][0]
    c = b_c[i][1]
    for _ in range(b):
        if a[j] < c:
            a[j] = c
            j += 1
        else:
            break

print(sum(a))
Problem p03055 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())
graph = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)


def dfs(v, dist, memo):
    memo[v] = dist
    for nv in graph[v]:
        if memo[nv] >= 0:
            continue
        dfs(nv, dist+1, memo)

memo = [-1] * n
dfs(0, 0, memo)

node = 0
dist = 0
for i in range(n):
    if memo[i] > dist:
        dist = memo[i]
        node = i

memo = [-1] * n
dfs(node, 0, memo)

dist = max(memo)
count = dist + 1

dp = [0] * (count + 10)
dp[0] = 0
dp[1] = 1
dp[2] = 0
dp[3] = 1
dp[4] = 1


if count >= 5:
    for i in range(5, count+1):
        if dp[i-2] == 1 and dp[i-1] == 1:
            dp[i] = 0
        else:
            dp[i] = 1

if dp[count]:
    print("First")
else:
    print("Second")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())
graph = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)


def dfs(v, dist, memo):
    memo[v] = dist
    for nv in graph[v]:
        if memo[nv] >= 0:
            continue
        dfs(nv, dist+1, memo)

memo = [-1] * n
dfs(0, 0, memo)

node = 0
dist = 0
for i in range(n):
    if memo[i] > dist:
        dist = memo[i]
        node = i

memo = [-1] * n
dfs(node, 0, memo)

dist = max(memo)
count = dist + 1

dp = [0] * (count+1)
dp[0] = 0
dp[1] = 1
dp[2] = 0
dp[3] = 1
dp[4] = 1


if count >= 5:
    for i in range(5, count+1):
        if dp[i-2] == 1 and dp[i-1] == 1:
            dp[i] = 0
        else:
            dp[i] = 1

if dp[count]:
    print("First")
else:
    print("Second")
Problem p03201 (python)

Fixed submission:
from collections import defaultdict

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

a.sort()
memo = defaultdict(int)
for i in range(n):
    memo[a[i]] += 1

count = 0
for i in reversed(range(n)):
    if memo[a[i]] == 0:
        continue
    if (memo[(1 << (len(bin(a[i])) - 2)) - a[i]] > 0 and (1 << (len(bin(a[i])) - 2)) - a[i] != a[i]) or memo[(1 << (len(bin(a[i])) - 2)) - a[i]] > 1:
        memo[a[i]] -= 1
        memo[(1 << (len(bin(a[i])) - 2)) - a[i]] -= 1
        count += 1

print(count)

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

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

a.sort()
memo = defaultdict(int)
for i in range(n):
    memo[a[i]] += 1

count = 0
for i in reversed(range(n)):
    if memo[a[i]] == 0:
        continue
    if memo[1 << (len(bin(a[i])) - 2) - a[i]] == 0:
        continue
    memo[a[i]] -= 1
    memo[1 << (len(bin(a[i])) - 2) - a[i]] -= 1
    count += 1

print(count)
Problem p03705 (python)

Fixed submission:
n, a, b = map(int, input().split())

if n == 1:
    if a == b:
        print(1)
    else:
        print(0)
else:
    if a < b:
        low = a * (n - 1) + b
        high = a + b * (n - 1)
        print(high - low + 1)
    elif a == b:
        print(1)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if a == b:
    print(1)
    exit()

# 二進数xの長さを求める時、len(bin(x)) - 2　では、xが0のとき1を返してしまい、バグる原因になる
# よって、二進数の長さを計算する関数を用意しておく
def bitlen(x):
    return 1 + bitlen(x >> 1) if x else 0

t = a ^ b
n = bitlen(t)

T = 1 << (n - 1)

a = a & (T * 2 - 1)
b = b & (T * 2 - 1)

sb = b & (T - 1)
b_max = (2 ** bitlen(sb) - 1) | T

if (T + a) > b_max:
    print((b_max - a + 1) + (2 * T - 1 - (T + a) + 1))
else:
    print(2 * T - 1 - a + 1)
Problem p03776 (python)

Fixed submission:
from collections import Counter
from scipy.misc import comb

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

v.sort(reverse=True)
v_cum = []
num = 0
for i in range(n):
    num += v[i]
    v_cum.append(num)

print(v_cum[a-1]/a)

if a == n:
    print(1)
else:
    if v[a-1] == v[a]:
        num = v[a-1]
        cf = Counter(v[:a])
        cb = Counter(v[a:])
        n_cf = cf[num]
        n_cb = cb[num]
        if n_cf != a:
            print(comb(n_cf+n_cb, n_cf, exact=True))
        else:
            ans = 0
            for k in range(a, min(b+1, a+n_cb+1)):
                ans += comb(a+n_cb, k, exact=True)
            print(ans)
    else:
        print(1)

Buggy submission (verdict: Runtime Error):
from collections import Counter
from itertools import combinations

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

v.sort(reverse=True)
v_cum = []
num = 0
for i in range(n):
    num += v[i]
    v_cum.append(num)

print(v_cum[a-1]/a)

if a == n:
    print(1)
else:
    if v[a-1] == v[a]:
        num = v[a-1]
        cf = Counter(v[:a])
        cb = Counter(v[a:])
        n_cf = cf[num]
        n_cb = cb[num]
        if cf[num] != a:
            print(combinations(n_cf+n_cb, n_cf))
        else:
            ans = 0
            for k in range(a, a+n_cb+1):
                ans += combinations(a+n_cb, k)
            print(ans)
    else:
        print(1)
Problem p03804 (python)

Fixed submission:
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]


for i in range(n-m+1):
    for j in range(n-m+1):
        flag = 0
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] != b[k][l]:
                    flag = 1
        if flag == 0:
            print('Yes')
            exit()


print('No')

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]


for i in range(n-m+1):
    for j in range(n-m)+1:
        flag = 0
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] != b[k][l]:
                    flag = 1
        if flag == 0:
            print('Yes')
            exit()


print('No')