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

Fixed submission:
import numpy as np

N = int(input())
S = np.array([int(x) for x in input().split()],dtype=np.int64)

# 右移動着地点：等差数列、ゴール含む
# 左移動着地点：等差数列、スタート含む

answer = 0
for d in range(1,N):
  # d = A-B
  cum_left = np.cumsum(S[::d])
  cum_right = np.cumsum(S[::-1][::d])
  score = cum_left + cum_right # 等差数列の長さ-1 -> 得点
  # あとは、その経路がルール内で実現できるかどうか
  for L,s in enumerate(score):
    if answer >= s:
      continue
    # 右左に進んでいることの確認
    A = N-1-L*d
    B = A-d
    if A <= 0:
      continue
    if A<=B:
      continue
    if B<=0:
      continue
    # 同じ場所を取っていないかの確認
    # kd = N-1-ldとなるとまずい
    # 約数のとき、Ld >= N-Ldだとまずい
    if (N-1)%d == 0 and 2*L*d >= N-1:
      continue
    answer = s

print(answer)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
S = np.array(read().split(),np.int64)

def F(d):
    # 公差を固定
    L = S[::d].cumsum()
    R = S[::-d].cumsum()
    if (N-1)%d == 0:
        n = (N-1)//d
        x = np.arange(1,n+2)
        bl = (x+x <= n+1)
        L = L[bl]; R = R[bl]
    return (L+R).max()

def G(n):
    # 項数n+1を固定
    D = (N-1)//n
    L = np.zeros(D+1,np.int64)
    R = np.zeros(D+1,np.int64)
    for i in range(1,n+1):
        L += S[:i*(D+1):i]
        R += S[::-1][:i*(D+1):i]
    ok = np.ones(D+1,np.bool)
    overlap = (np.arange(D+1) * (n+n) >= N-1)
    overlap[1:] &= ((N-1)%np.arange(1,D+1) == 0)
    x = L+R
    x[overlap] = 0
    return x.max()

L = (N-1)**.5 + 10
L = min(N-1,L)

x = max(F(n) for n in range(1,L+1))
y = max(F(n) for n in range(1,L+1))
answer = max(x,y)
print(answer)

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

N = int(input())
S = np.array([int(x) for x in input().split()],dtype=np.int64)

# 右移動着地点：等差数列、ゴール含む
# 左移動着地点：等差数列、スタート含む

answer = 0
for d in range(1,N):
    # d = A-B
    cum_left = np.cumsum(S[::d])
    cum_right = np.cumsum(S[::-1][::d])
    score = cum_left + cum_right # 等差数列の長さ-1 -> 得点
    # あとは、その経路がルール内で実現できるかどうか
    for L,s in enumerate(score):
        if answer >= s:
            continue
        # 右左に進んでいることの確認
        A = N-1-L*d
        B = A-d
        if A<=B:
            continue
		if B<=0:
          	continue
        # 同じ場所を取っていないかの確認
        # kd = N-1-ldとなるとまずい
        # 約数のとき、Ld >= N-Ldだとまずい
        if (N-1)%d == 0 and 2*L*d >= N-1:
            continue
        answer = s


print(answer)
Problem p03045 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
# 連結成分
# UF tree

N,M = map(int,input().split())
n_component = N

root = list(range(N+1))
depth = [0] * (N+1)

def find_root(x):
  y = root[x]
  if x == y:
    return x
  z = find_root(y)
  root[x] = z
  return z

def merge(x,y):
  global n_component
  xx = find_root(x)
  yy = find_root(y)
  if xx == yy:
    return
  n_component -= 1
  if depth[xx] >= depth[yy]:
    root[yy] = xx
    depth[xx] += 1
  else:
    root[xx] = yy
    depth[yy] += 1
  
for _ in range(M):
  x,y,z = [int(x) for x in input().split()]
  merge(x,y)

answer = n_component
print(answer)

Buggy submission (verdict: Runtime Error):
# 連結成分 + 1
# UF tree

N,M = map(int,input().split())
n_component = N

root = list(range(N+1))
depth = [0] * (N+1)

def find_root(x):
  y = root[x]
  if x == y:
    return x
  z = find_root[y]
  root[x] = z
  return z

def merge(x,y):
  global n_component
  xx = find_root(x)
  yy = find_root(y)
  if xx == yy:
    return
  n_component -= 1
  if depth[xx] >= depth[yy]:
    root[yy] = xx
    depth[xx] += 1
  else:
    root[xx] = yy
    depth[yy] += 1
  
for _ in range(M):
  x,y,z = [int(x) for x in input().split()]
  merge(x,y)


answer = n_component
print(answer)
Problem p03053 (python)

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

H,W = map(int,input().split())
INF = 10**18
q = []

visited = [[True]*(W+2)]
visited += [[True] + [x == '#' for x in input().rstrip()] + [True] for _ in range(H)]
visited.append([True]*(W+2))
  
for i in range(1,H+1):
  for j in range(1,W+1):
    if visited[i][j]:
      q.append((i,j))

moves = [(0,1),(0,-1),(1,0),(-1,0)]

ans = -1
while q:
  qq = []
  ans += 1
  for x,y in q:
    if not visited[x-1][y]:
      visited[x-1][y] = True
      qq.append((x-1,y))
    if not visited[x+1][y]:
      visited[x+1][y] = True
      qq.append((x+1,y))
    if not visited[x][y-1]:
      visited[x][y-1] = True
      qq.append((x,y-1))
    if not visited[x][y+1]:
      visited[x][y+1] = True
      qq.append((x,y+1))
  q = qq
  
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
# グラフの最長経路が-1か-2かを選べる
N = int(input())
edge = [[] for _ in range(N)]
INF = 10**18
for _ in range(N-1):
  a,b = map(int,input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

opposite = 0
max_dist = 0
def f(d,x):
  global max_dist,opposite
  dx = d[x]
  if dx > max_dist:
    opposite = x
    max_dist = dx
  for y in edge[x]:
    if d[y] == INF:
      d[y] = dx + 1
      f(d,y)

# 0からの距離
d = [INF] * N
d[0] = 0
f(d,0)

v = opposite
d = [INF] * N
d[v] = 0
f(d,v)

X = max_dist

ans = 'First' if max_dist%3 != 1 else 'Second'
print(ans)
Problem p03055 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
# グラフの最長経路が-1か-2かを選べる
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N-1):
  a,b = map(int,input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)


def f(x):
  opposite = 0
  max_dist = 0
  # 最離点と距離とを返す
  d = [None]*N
  q = [(x,0)]
  while q:
    x,dx = q.pop()
    d[x] = dx
    if dx > max_dist:
      max_dist = dx
      opposite = x
    for y in edge[x]:
      if d[y] is None:
        q.append((y,dx+1))
  return opposite,max_dist

if N != 1:
  # 0からの距離
  v,_ = f(0)
  _,max_dist = f(v)

  ans = 'First' if max_dist%3 != 1 else 'Second'
  print(ans)
else:
  print('First')

Buggy submission (verdict: Runtime Error):
# グラフの最長経路が-1か-2かを選べる
N = int(input())
edge = [[] for _ in range(N)]
INF = 10**18
for _ in range(N-1):
  a,b = map(int,input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

opposite = 0
max_dist = 0
def f(d,x):
  global max_dist,opposite
  dx = d[x]
  if dx > max_dist:
    opposite = x
    max_dist = dx
  for y in edge[x]:
    if d[y] == INF:
      d[y] = dx + 1
      f(d,y)

# 0からの距離
d = [INF] * N
d[0] = 0
f(d,0)

v = opposite
d = [INF] * N
d[v] = 0
f(d,v)

X = max_dist

ans = 'First' if max_dist%3 != 1 else 'Second'
print(ans)
Problem p03135 (python)

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

Buggy submission (verdict: Runtime Error):
a,b = map(int,input())
print(a/b)
Problem p03275 (python)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
total_medians = N*(N+1)//2
# n件のデータ
# (上側中央値 >= x) iff (a > x となる a が(n-1)//2以下)

def BIT_update(BIT,x,value):
  # 番号xにvalueを加える
  L = len(BIT)
  while x < L:
    BIT[x] += value
    bottom_bit = x & (-x)
    x += bottom_bit
  return

def BIT_sum(BIT,x):
  # 番号1～xの和を求める
  result = 0
  while x:
    result += BIT[x]
    bottom_bit = x & (-x)
    x -= bottom_bit
  return result

def test(x):
  # 「答はx以下である」
  # 「xより真に大きな区間中央値が(total_medians-1)//2個以下」
  B = [0]
  for a in A:
    B.append(B[-1] + (1 if a>x else -1))
  m = min(B)-1
  B = [x-m for x in B]

  BIT = [0]*(N+1)
  
  cnt = 0
  for R in range(1,N+1):
    BIT_update(BIT,B[R-1],1)
    cnt += BIT_sum(BIT,B[R]) # 右端がRとなる(L,R)対
  return cnt <= (total_medians-1)//2

AA = sorted(A)
left = -1 # 答はAA[left]より大きい
right = len(AA)-1 # 答はAA[right]以下である
while right - left > 1:
  mid = (left+right)//2
  if test(AA[mid]):
    right = mid
  else:
    left = mid
answer = AA[right]

print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]
total_medians = N*(N+1)//2
# n件のデータ
# (上側中央値 >= x) iff (a > x となる a が(n-1)//2以下)

def test(x):
  # 「答はx以下である」
  # 「xより真に大きな区間中央値が(total_medians-1)//2個以下」
  B = [0]
  for a in A:
    B.append(B[-1] + (1 if a > x else -1))
  m = min(B)-1
  BIT = [0]*(N+1)
  cnt = 0
  for b in B:
    x = b-m
    while x:
      cnt += BIT[x]
      x -= (x & (-x))
    x = b-m
    b -= m
    while x <= N:
      BIT[x] += 1
      x += (x & (-x))
  return cnt <= (total_medians-1)//2

AA = sorted(A)
left = -1 # 答はAA[left]より大きい
right = len(AA)-1 # 答はAA[right]以下である
while right - left > 1:
  mid = (left+right)//2
  if test(AA[mid]):
    right = mid
  else:
    left = mid
    
answer = AA[right]
print(answer)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = np.array(input().split(),dtype=np.int32)
total_medians = N*(N+1)//2
# n件のデータ
# (上側中央値 >= x) iff (a > x となる a が(n-1)//2以下)

def BIT_update(BIT,x,value):
  # 番号xにvalueを加える
  L = len(BIT)
  while x < L:
    BIT[x] += value
    bottom_bit = x & (-x)
    x += bottom_bit
  return

def BIT_sum(BIT,x):
  # 番号1～xの和を求める
  result = 0
  while x:
    result += BIT[x]
    bottom_bit = x & (-x)
    x -= bottom_bit
  return result

def test(x):
  # 「答はx以下である」
  # 「xより真に大きな区間中央値が(total_medians-1)//2個以下」
  B = np.concatenate([[0],(A > x).cumsum()])
  # count L,R such that -1<=L<R<=N-1 and B(R)-B(L) >= (R-L)/2
  # count L,R such that B(R) - R/2 >= B(L) - L/2
  C = 2*B-np.arange(N+1)
  C -= np.min(C) - 1
  M = C.max()
  BIT = [0]*(M+1)
  
  cnt = 0
  prev = C[0]
  for c in C[1:]:
    BIT_update(BIT,prev,1)
    cnt += BIT_sum(BIT,c) # 右端がRとなる(L,R)対
    prev = c
  return cnt <= (total_medians-1)//2

AA = sorted(set(A))
left = -1 # 答はAA[left]より大きい
right = len(AA)-1 # 答はAA[right]以下である
while right - left > 1:
  mid = (left+right)//2
  if test(AA[mid]):
    right = mid
  else:
    left = mid
    
answer = AA[right]
print(answer)
Problem p03634 (python)

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

N = int(input())
edge = [[] for _ in range(N+1)]
 
for _ in range(N-1):
  a,b,c = map(int,input().split())
  edge[a].append((b,c))
  edge[b].append((a,c))

Q,K = map(int,input().split())

dist = [None]*(N+1)

def set_dist(x,d):
  dist[x] = d
  for y,dd in edge[x]:
    if dist[y] is not None:
      continue
    set_dist(y,d+dd)

set_dist(K,0)

for _ in range(Q):
  x,y = map(int,input().split())
  print(dist[x] + dist[y])

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

N = int(input())
edge = [[] for _ in range(N+1)]
 
for _ in range(N-1):
  a,b,c = map(int,input().split())
  edge[a].append((b,c))
  edge[b].append((a,c))

Q,K = map(int,input().split())

dist = [None]*(N+1)

def set_dist(x,d):
  dist[x] = d
  for y,dd in edge[x]:
    if dist[y] is not None:
      continue
    set_dist(y,d+dd)

set_dist(K,0)

for _ in range(Q):
  x,y = map(int,input().split())
  print(dist[x] + dist[y])

Buggy submission (verdict: Runtime Error):
from scipy.sparse import lil_matrix
import sys
input = sys.stdin.readline

print(scipy.__version__())
N = int(input())
edge = lil_matrix((N+1,N+1))
 
for _ in range(N-1):
  a,b,c = map(int,input().split())
  edge[a,b] = c
 
Q,K = map(int,input().split())
 
from scipy.sparse.csgraph import dijkstra
dist = dijkstra(edge,directed = False, indices = K).astype(int)
 
for _ in range(Q):
  x,y = map(int,input().split())
  print(dist[x] + dist[y])
Problem p03769 (python)

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

from collections import deque

N = int(input())

# empty
N += 1

bit = [i for i in range(60) if N&(1<<i)]

n = bit[-1]
left = deque(range(n,0,-1))
right = deque()
x = n+1

for i in range(n,0,-1):
    right.append(i)
    if i-1 in bit:
        right.append(x)
        left.appendleft(x)
        x += 1

S = list(left) + list(right)
print(len(S))
print(' '.join(map(str,S)))

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

from collections import deque

N = int(input())

# empty
N -= 1

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

bit = [i for i in range(60) if N&(1<<i)]

n = bit[-1]
left = deque(range(n,0,-1))
right = deque()
x = n+1

for i in range(n,0,-1):
    right.append(i)
    if i-1 in bit:
        right.append(x)
        left.appendleft(x)
        x += 1

S = left + right
print(len(S))
print(' '.join(map(str,S)))

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

from collections import deque

N = int(input())

bit = [i for i in range(60) if N&(1<<i)]

n = bit[-1]
left = deque(range(n,0,-1))
right = deque()
x = n+1

left,right

for i in range(n,0,-1):
    right.append(i)
    if i-1 in bit:
        right.append(x)
        left.appendleft(x)
        x += 1

S = left + right
print(len(S))
print(' '.join(map(str,S)))
Problem p03805 (python)

Fixed submission:
import itertools
N,M = map(int,input().split())
edges = set()
for _ in range(M):
  a,b = map(int,input().split())
  edges.add((a,b))
  edges.add((b,a))

answer = 0

for p in itertools.permutations(range(1,N+1)):
  if p[0] != 1:
    continue
  bl = True
  for i in range(N-1):
    if (p[i], p[i+1]) not in edges:
      bl = False
      break
  if bl:
    answer += 1

print(answer)

Buggy submission (verdict: Runtime Error):
import itertools
N,M = map(int,input().split())
edges = set()
for _ in range(N):
  a,b = map(int,input().split())
  edges.add((a,b))
  edges.add((b,a))

answer = 0

for p in itertools.permutations(range(1,N+1)):
  if p[0] != 1:
    continue
  bl = True
  for i in range(N-1):
    if (p[i], p[i+1]) not in edges:
      bl = False
      break
  if bl:
    answer += 1

print(answer)
Problem p03839 (python)

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

import numpy as np

# どこかの長さKは最後に単色で残る
# そこを残すと決めると他は自由に設定できる

N,K = map(int,input().split())
A = np.array(input().split(), dtype=np.int64)

Acum = A.cumsum()
range_sum = Acum[K-1:] - Acum[:N-(K-1)] + A[:N-(K-1)]

# 各地点を左端として、長さKの区間の合計を求める
Acum = A.cumsum()
range_sum = Acum[K-1:] - Acum[:N-(K-1)] + A[:N-(K-1)]
best = np.maximum(A,0)
best_cum = best.cumsum()
best_range_sum = best_cum[K-1:] - best_cum[:N-(K-1)] + best[:N-(K-1)]

min_loss = (best_range_sum - np.maximum(range_sum,0)).min()

answer = best.sum() - min_loss
print(answer)

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit('(i8,i8,i8[:])', cache=True)
def main(N, K, A):
    B = np.maximum(A, 0)
    Acum = np.zeros(len(A) + 1, np.int64)
    Bcum = np.zeros(len(A) + 1, np.int64)
    Acum[1:] = np.cumsum(A)
    Bcum[1:] = np.cumsum(B)
    ret = -(10**18)
    for l in range(N - K + 1):
        r = l + K
        sum1 = Bcum[l]
        sum2 = Bcum[-1] - Bcum[r]
        sum3 = Acum[r] - Acum[l]
        x = sum1 + sum2 + max(sum3, 0)
        ret = max(ret, x)
    return ret

N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)

print(main(N, K, A))
Problem p03954 (python)

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

import numpy as np

N = int(readline())
A = np.array(readline().split(),np.int32)

def test(x):
    # 答はx以上
    B = (A >= x)
    # 連番の左側にフラグを立てる
    flag = np.zeros(N+N-1,np.bool)
    flag[:-1] = (B[:-1] == B[1:])
    # 最寄りの連番を探す
    """ version違いでボツ
    L = np.where(flag[:N])[0].max(initial=-1) + 1
    R = np.where(flag[N-1:-1])[0].min(initial=N-1) + N - 1
    """
    x = np.where(flag[:N])[0]
    L = x.max() + 1 if len(x) >= 1 else 0
    x = np.where(flag[N-1:-1])[0]
    R = x.min() + N - 1 if len(x) >= 1 else N+N-2
    if (N-1)-L > R-(N-1):
        return B[R]
    else:
        return B[L]

left = 0 # 答はleft以上
right = N+N+10 # 答はright未満
while left + 1 < right:
    mid = (left + right)//2
    if test(mid):
        left = mid
    else:
        right = mid
answer = left
print(answer)

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

import numpy as np

N = int(readline())
A = np.array(readline().split(),np.int32)

def test(x):
    # 答はx以上
    B = (A >= x)
    # 連番の左側にフラグを立てる
    flag = np.zeros(N+N-1,np.bool)
    flag[:-1] = (B[:-1] == B[1:])
    # 最寄りの連番を探す
    L = np.where(flag[:N])[0].max(initial=-1) + 1
    R = np.where(flag[N-1:-1])[0].min(initial=N-2) + N
    if (N-1)-L > R-(N-1):
        return B[R]
    else:
        return B[L]

left = 0 # 答はleft以上
right = N+10 # 答はright未満
while left + 1 < right:
    mid = (left + right)//2
    if test(mid):
        left = mid
    else:
        right = mid
answer = left
print(answer)
Problem p04008 (python)

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

N,K = map(int,readline().split())
A = [int(x)-1 for x in readline().split()]

desc_edge = [set() for _ in range(N)]
parent = [0] * N
for i,x in enumerate(A[1:],1):
    # 根から葉に向かう向きに辺を持つ
    desc_edge[x].add(i)
    parent[i]=x

depth = [None] * N
q = [0]
depth[0]=0
while q:
    x = q.pop()
    for y in desc_edge[x]:
        q.append(y)
        depth[y] = depth[x]+1

V = set(range(N))

q=[]
depth_to_v = [[] for _ in range(N)]
for v,x in enumerate(depth):
    depth_to_v[x].append(v)
for d in range(N-1,-1,-1):
    q += depth_to_v[d]

q

answer = 0
for x in q:
    if x == 0:
        break
    if x not in V:
        continue
    if depth[x] <= K:
        break
    answer += 1
    y=x
    for _ in range(K-1):
        y = parent[y]
    # yの転送先を0に変更する、yの部分木は捨てる
    qq = [y]
    while qq:
        z = qq.pop()
        V.remove(z)
        for w in desc_edge[z]:
            if w in V:
                qq.append(w)

if A[0] != 0:
    answer += 1
print(answer)

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

N,K = map(int,readline().split())
A = [int(x)-1 for x in readline().split()]

desc_edge = [set() for _ in range(N)]
parent = [0] * N
for i,x in enumerate(A[1:],1):
    # 根から葉に向かう向きに辺を持つ
    desc_edge[x].add(i)
    parent[i]=x

depth = [None] * N
q = [0]
depth[0]=0
while q:
    x = q.pop()
    for y in desc_edge[x]:
        q.append(y)
        depth[y] = depth[x]+1

V = set(range(N))

q=[]
depth_to_v = [[] for _ in range(N)]
for v,x in enumerate(depth):
    depth_to_v[x].append(v)
for d in range(N):
    q += depth_to_v[d]

answer = 0
while q:
    x = q.pop()
    if x == 0:
        break
    if x not in V:
        continue
    if depth[x] <= K:
        break
    answer += 1
    for _ in range(K-1):
        y = parent[y]
    # yの転送先を0に変更する、yの部分木は捨てる
    qq = [y]
    while qq:
        z = qq.pop()
        V.remove(z)
        for w in desc_edge[z]:
            if w in V:
                qq.append(w)

if A[0] != 0:
    answer += 1
print(answer)
Problem p04021 (python)

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

"""
奇数番目集合、偶数番目集合の中で自由にできるのが操作2．
操作1で集合間のやりとりをする
"""

import numpy as np

N = int(input())
A = np.fromstring(sys.stdin.read(),dtype=np.int64,sep='\n')

B = np.sort(A)

answer = len(np.setdiff1d(A[::2],B[::2]))
print(answer)

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

I,O,T,J,L,S,Z = map(int,input().split())

# T,S,Z は無関係
# I,O,J,Lに注目
# Oは足すだけ
# I,J,Lが問題
# II, JIL, JJ, LL

x = (I//2 + J//2 + L//2) * 2
if I>0 and J>0 and L>0:
    x = max(x,((I-1)//2 + (J-1)//2 + (L-1)//2) * 2 + 3)
x += O

print(x)
Problem p04037 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*A = map(int,read().split())

A.sort(reverse = True)

A.append(0)
i = 0
while A[i + 1] > i + 1:
    i += 1

x = A[i] - (i + 1)
y = max(j for j in range(N) if A[j] > i) - i

answer = 'First' if x&1 or y&1 else 'Second'
print(answer)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*A = map(int,read().split())

A.sort(reverse = True)

A.append(0)
i = 0
while A[i + 1] < i + 1:
    i += 1

x = A[i] - (i + 1)
y = max(j for j in range(N) if A[j] <= i + 1) - i

answer = 'First' if x&1 or y&1 else 'Second'
print(answer)
Problem p04050 (python)

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

N,M = map(int,readline().split())
A = [int(x) for x in readline().split()]

OD = [x for x in A if x&1]
EV = [x for x in A if not x&1]

if len(OD) >= 3:
    print('Impossible')
    exit()

if len(A) == 1:
    if N == 1:
        B = [1]
    else:
        B = [1,N-1]
elif len(OD) == 0:
    B = A.copy()
    B[0] -= 1
    B[-1] += 1
elif len(OD) == 1:
    A = OD + EV
    B = A.copy()
    B[0] += 1
    B[-1] -= 1
else:
    A = [OD[0]] + EV + [OD[-1]]
    B = A.copy()
    B[0] += 1
    B[-1] -= 1
B = [x for x in B if x > 0]

print(*A)
print(len(B))
print(*B)

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

N,M = map(int,readline().split())
A = [int(x) for x in readline().split()]

OD = [x for x in A if x&1]
EV = [x for x in A if not x&1]

if len(OD) >= 3:
    print('Impossible')
    exit()

if len(A) == 1:
    if N == 1:
        B = [1]
    else:
        B = [1,N-1]
elif len(OD) == 0:
    B = A.copy()
    B[0] -= 1
    B[-1] += 1
elif len(OD) == 1:
    A = OD + EV
    B = A.copy()
    B[0] += 1
    B[-1] -= 1
else:
    A = OD[0] + EV + OD[-1]
    B = A.copy()
    B[0] += 1
    B[-1] -= 1
B = [x for x in B if x > 0]

print(*A)
print(len(B))
print(*B)
Problem p02552 (python)

Fixed submission:
x = int(input())

if x == 0:
    print(1)
else:
    print(0)

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

if x == 0:
    print(1)
els:
    print(0)
Problem p02682 (python)

Fixed submission:
A, B, C, K = map(int,input().split())
if K <= A:
    print(K)
elif K <= A + B:
    print(A)
else:
    print(2*A + B - K)

Buggy submission (verdict: Runtime Error):
#入力させる
A = int(input())
B = int(input())
C = int(input())
K = int(input())
#the number of A,B,C for given K
if K-A<0: #K<Aであれば、1をＫ枚選ぶ。
    NA = K
    NB = 0
    NC = 0
else: #K≧Aであれば、1をA枚選び、残りのK-A枚は0 or -1 を選ぶ。
    NA = A
    if (K-A)-B<0: #K-A<Bであれば、K-A枚全て0を選べる
        NB = K-A
        NC = 0
    else: #K-A≧Bであれば、0をB枚選び、残りのK-A-B枚は0 or -1 を選ぶ。
        NB = B
        NC = K-A-B

#最大値を求める
sum = NA *1 + NB *0 + NC *(-1)

#出力
print(sum)
Problem p02570 (python)

Fixed submission:
D,T,S =(int(x) for x in input().split())

if (D<=T*S):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
D,T,S =(int(x) for x in input().split(","))

if (D<=T*S):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
D,T,S =(int(x) for x in input().split(","));

if (D<=T*S):
    print("Yes");
else:
    print("No");
Problem p02577 (python)

Fixed submission:
N = int(input())
x = N //1000
x1 = (N - x*1000)//100
x2 = (N - x*1000 - x1*100)//10
x3 = N - x*1000 - x1*100 - x2*10
sum = x+x1+x2+x3
if sum % 9 != 0:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
N = int(input())
sum = int(N % 10) + (int(N/10))
if sum % 9 != 0:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
N = int(input())
sum = int(N % 10) + (int(N/10))
if sum % 9 == 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
sum = 0
while (N != 0):
    sum = sum + int(N % 10)
    N = int(N / 10)
if sum%9 == 0:
    print("Yes")
else:
    print("No")
Problem p02682 (python)

Fixed submission:
a,b,c,k = list(map(int,input().split()))
if a+b >= k:
  print(min(a,k))
else:
  print(a-(k-a-b))

Buggy submission (verdict: Runtime Error):
a,b,c,k = list(map(input(),split()))
if a+b >= k:
  print(min(a,k))
else:
  print(a-(k-a-b))
Problem p02785 (python)

Fixed submission:
n,k = map(int,input().split())
h = list(map(int,input().split()))
h.sort(reverse = True)
for i in range(min(n,k)):
    h[i] = 0
print(sum(h))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
h = list(map(int,input().split()))
h.sort(reverse = True)
for i in range(k):
    h[i] = 0
print(sum(h))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
h = list(map(int,input().split()))
h.sort()
for i in range(k):
    h[i] = 0
print(sum(h))