TnT/CodeNet4Repair huggingface dataset:
Problem:
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems.  The score allocated to the i-th (1≦i≦N) problem is i points.  Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve.  As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him.  Determine the set of problems that should be solved.

Incorrect submission (verdict: Wrong Answer):
n=int(input())
def solve(m):
    big=m[0]
    ok=0
    for i in range(big-1,-1,-1):
        if i not in m and big-i not in m:
            m.pop(0)
            m.append(i)
            m.append(big-i)
            ok+=1
            break
    if ok>0:
        m.sort(reverse=True)
        return solve(m)
    else:
        return(m)
ans=solve([n])
for i in ans:
    print(i)

Fixed, accepted submission:
n=int(input())
t=1
while n>t:
    n-=t
    t+=1
rem=t-n
las=t
for i in range(1,las+1):
    if i!=rem:
        print(i)
Problem:
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though.  Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious.  Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it.  Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.

Incorrect submission (verdict: Wrong Answer):
x,a,b = map(int,input().split())

if x-(a-b) > 0:
  print("dangerous")
else:
  if a > b:
    print("delicious")
  else:
    print("safe")


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

if x+a-b < 0:
  print("dangerous")
else:
  if a >= b:
    print("delicious")
  else:
    print("safe")
Problem:
We have a grid with H rows and W columns, where all the squares are initially white.  You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions:    * Choose one row, then paint all the squares in that row black.   * Choose one column, then paint all the squares in that column black.  At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.

Incorrect submission (verdict: Wrong Answer):
h = int(input())
w = int(input())
n = int(input())

if h > w:
  print(n//h)
else:
  print(n//w)

Fixed, accepted submission:
h = int(input())
w = int(input())
n = int(input())

if h > w:
  print(-(-n//h)) 
else:
  print(-(-n//w))
Problem:
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b.  Determine whether the arrangement of the poles is beautiful.

Incorrect submission (verdict: Wrong Answer):
a,b,c = map(int,list(input().split()))
if b-a == c-b:
    print('Yes')
else:
    print('No')


Fixed, accepted submission:
a,b,c = map(int,list(input().split()))
if b-a == c-b:
    print('YES')
else:
    print('NO')
Problem:
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.  Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.  Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)  At most how much can he earn on balance?  Note that the same string may be written on multiple cards.

Incorrect submission (verdict: Wrong Answer):
from itertools import groupby

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

def main():
    for t in T:
        if t in S:
            S.remove(t)
    ans = [len(list(group)) for key, group in groupby(S)]
    print(max([0] + ans))

if __name__ == "__main__":
    main()

Fixed, accepted submission:
from itertools import groupby

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

def main():
    for t in T:
        if t in S:
            S.remove(t)
    S.sort() # have to sort before using groupby()
    ans = [len(list(g)) for key, g in groupby(S)]
    print(max([0] + ans))

if __name__ == "__main__":
    main()
Problem:
Snuke loves working out. He is now exercising N times.  Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i.  Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
ans = 1
for i in range(1, N+1):
  ans * i
print(ans)


Fixed, accepted submission:
MOD = int(1e9)+7
N = int(input())
ans = 1
for i in range(1, N+1):
  ans *= i
  ans %= MOD
print(ans)
Problem:
Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".

Incorrect submission (verdict: Wrong Answer):
x = input().split()
a = int(x[0])
b = int(x[1])
c = int(x[2])
if a > b and b > c:
    print('Yes')
else:
    print('No')

Fixed, accepted submission:
x = input().split()
a = int(x[0])
b = int(x[1])
c = int(x[2])
if a < b and b < c:
    print('Yes')
else:
    print('No')
Problem:
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:    * 1 \leq x,y,z   * x^2 + y^2 + z^2 + xy + yz + zx = n  Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).

Incorrect submission (verdict: Time Limit Exceeded):
n = int(input())

lst = [0]*n
a = int(n ** 0.5)

for x in range(1, a):
    for y in range(1, a):
        for z in range(1, a):
            b = x**2 + y**2 + z**2 + x*y + y*z + z*x
            while b <= n:
                lst[b - 1] += 1

for i in lst:
    print(i) 


Fixed, accepted submission:
n = int(input())

lst = [0]*n
a = int(n ** 0.5)

for x in range(1, a):
    for y in range(1, a):
        for z in range(1, a):
            b = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if b > n:
                continue
            else:
                lst[b - 1] += 1

for i in lst:
    print(i)
Problem:
There are N positive integers written on a blackboard: A_1, ..., A_N.  Snuke can perform the following operation when all integers on the blackboard are even:    * Replace each integer X on the blackboard by X divided by 2.  Find the maximum possible number of operations that Snuke can perform.

Incorrect submission (verdict: Time Limit Exceeded):
if __name__=="__main__":
    count = 0
    idx = int(input())
    n = list(map(int,input().split(" ")))
    while True:
        for i in range(idx):
            if n[i]|1 ==n[i]:
                print(count)
                exit()
        count+=1

Fixed, accepted submission:
if __name__=="__main__":
    count = 0
    idx = int(input())
    n = list(map(int,input().split(" ")))
    while True:
        for i in range(idx):
            if n[i]|1==n[i]:
                print(count)
                exit()
            else:
                n[i]=n[i]>>1
        count+=1
Problem:
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}.  Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.

Incorrect submission (verdict: Wrong Answer):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

s = list(input())
t = list(input())
t2 = ""
for i in range(len(t)):
    t2+=t[len(t)-i-1]
if s == t2:
    print("YES")
else:
    print("NO")
 

Fixed, accepted submission:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

s = input()
t = input()
t2 = t[::-1]
if s == t2:
    print("YES")
else:
    print("NO")
Problem:
n! = n × (n − 1) × (n − 2) × ...  × 3 × 2 × 1      を n の階乗といいます。例えば、12 の階乗は      12! = 12 × 11 × 10 × 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1 = 479001600      となり、末尾に 0 が 2 つ連続して並んでいます。  整数 n を入力して、n! の末尾に連続して並んでいる 0 の数を出力するプログラムを作成してください。ただし、n は 20000 以下の正の整数とします。

Incorrect submission (verdict: Wrong Answer):
for e in iter(input,'0'):
 a=i=1;e=int(e)
 while 1:
  d=e//5**i
  print(i,d)
  if d:a+=d
  else:break
  i+=1
 print(a-1)


Fixed, accepted submission:
for e in iter(input,'0'):print(sum(int(e)//5**i for i in range(1,7)))
Problem:
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.

Incorrect submission (verdict: Wrong Answer):
a,b=map(int,input().split())
print((a+b)//2+1)

Fixed, accepted submission:
import math
a,b=map(int,input().split())
print(math.ceil((a+b)/2))
Problem:
You are given an H × W grid.   The squares in the grid are described by H strings, S_1,...,S_H.   The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).   `.` stands for an empty square, and `#` stands for a square containing a bomb.  Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.   (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)   He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.  Print the strings after the process.

Incorrect submission (verdict: Wrong Answer):
# coding: utf-8
H, W = map(int, input().split())


lst = ["."*(W+2)] + ["." + input() + "." for _ in range(H)] + ["."*(W+2)]
print(lst)


lst2 = []
for _ in range(H+2):
    lst2.append([0 for _ in range(W+2)])


for i in range(1, H+1):
    for j in range(1, W+1):
        cnt = 0
        if lst[i][j] == ".":
            cnt += lst[i-1][j-1:j+2].count("#")
            cnt += lst[i][j-1:j+2].count("#")
            cnt += lst[i+1][j-1:j+2].count("#")
            lst2[i][j] = str(cnt)
        else:
            lst2[i][j] = "#"

for i in range(1, H+1):
    print("".join(lst2[i][1:W+1]))


Fixed, accepted submission:
# coding: utf-8
H, W = map(int, input().split())


lst = ["."*(W+2)] + ["." + input() + "." for _ in range(H)] + ["."*(W+2)]


lst2 = []
for _ in range(H+2):
    lst2.append([0 for _ in range(W+2)])


for i in range(1, H+1):
    for j in range(1, W+1):
        cnt = 0
        if lst[i][j] == ".":
            cnt += lst[i-1][j-1:j+2].count("#")
            cnt += lst[i][j-1:j+2].count("#")
            cnt += lst[i+1][j-1:j+2].count("#")
            lst2[i][j] = str(cnt)
        else:
            lst2[i][j] = "#"

for i in range(1, H+1):
    print("".join(lst2[i][1:W+1]))
Problem:
We ask you to select some number of positive integers, and calculate the sum of them.  It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.  Your objective is to make the sum congruent to C modulo B. Determine whether this is possible.  If the objective is achievable, print `YES`. Otherwise, print `NO`.

Incorrect submission (verdict: Wrong Answer):
a,b,c = map(int,input().split())

cnt = 0
su = a
while cnt < 10:
    if su%b == c:
        print("Yes")
        exit()
    su+=a
    cnt+=1
    
print("No")

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

cnt = 0
su = a
while cnt < 100:
    if su%b == c:
        print("YES")
        exit()
    su+=a
    cnt+=1
    
print("NO")
Problem:
It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts.   There are N houses along _TopCoDeer street_. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses.   Find the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions.

Incorrect submission (verdict: Wrong Answer):
A=list(map(int,input().split()))
A=sorted(A)
print(A[-1]-A[0])


Fixed, accepted submission:
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
print(A[-1]-A[0])
Problem:
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.  Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.

Incorrect submission (verdict: Wrong Answer):
a,b,c,x,y=map(int,input().split())
m=10**10
for i in range(x+y+1):
  p=2*i
  m=min(m,(x-i)*a+(y-i)*b+p*c)
print(m)
  

Fixed, accepted submission:
a,b,c,x,y=map(int,input().split())
m=10**10
for i in range(2*(x+y)+1):
  m=min(m,max(0,x-i//2)*a+max(0,y-i//2)*b+i*c)
print(m)
Problem:
We will buy a product for N yen (the currency of Japan) at a shop.  If we use only 1000-yen bills to pay the price, how much change will we receive?  Assume we use the minimum number of bills required.

Incorrect submission (verdict: Wrong Answer):
x =int(input())
while x > 1000:
    x -= 1000
print(x)


Fixed, accepted submission:
x =int(input())
while x > 1000:
    x -= 1000
print(1000 - x)
Problem:
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions:    * Question 1: Are you subscribing to Newspaper X?   * Question 2: Are you subscribing to Newspaper Y?  As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2.  What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y?  Write a program to answer this question.

Incorrect submission (verdict: Wrong Answer):
n,a,b=map(int,input().split())
if n>=a+b:
    if a>b:
        print(a,0)
    else:
        print(b,0)
else:
    if a>b:
        print(a,a+b-n)
    else:
        print(b,a+b-n)

Fixed, accepted submission:
n,a,b=map(int,input().split())
if n>=a+b:
    if a>b:
        print(b,0)
    else:
        print(a,0)
else:
    if a>b:
        print(b,a+b-n)
    else:
        print(a,a+b-n)
Problem:
We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i.  How many squares i satisfy both of the following conditions?    * The assigned number, i, is odd.   * The written integer is odd.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
a=list(map(int,input().split()))
cnt=0
for i in range((N+1)//2):
    if a[2*i-1] % 2 == 1:
        cnt += 1
print(cnt)

Fixed, accepted submission:
N = int(input())
a=list(map(int,input().split()))
cnt=0
for i in range((N+1)//2):
    if a[2*i] % 2 == 1:
        cnt += 1
print(cnt)
Problem:
You are given three strings A, B and C. Check whether they form a _word chain_.  More formally, determine whether both of the following are true:    * The last character in A and the initial character in B are the same.   * The last character in B and the initial character in C are the same.  If both are true, print `YES`. Otherwise, print `NO`.

Incorrect submission (verdict: Wrong Answer):
a,b,c=input().split();print('Yes' if a[-1]==b[0] and b[-1]==c[0] else 'No')

Fixed, accepted submission:
a,b,c=input().split();print('YES' if a[-1]==b[0] and b[-1]==c[0] else 'NO')
Problem:
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.    An example of a trapezoid  Find the area of this trapezoid.

Incorrect submission (verdict: Wrong Answer):
#coding:utf-8

a = int(input())
b = int(input())
h = int(input())

print(((a+b)*h)/2)

Fixed, accepted submission:
#coding:utf-8

a = int(input())
b = int(input())
h = int(input())

print(((a+b)*h)//2)
Problem:
You are given three strings A, B and C. Check whether they form a _word chain_.  More formally, determine whether both of the following are true:    * The last character in A and the initial character in B are the same.   * The last character in B and the initial character in C are the same.  If both are true, print `YES`. Otherwise, print `NO`.

Incorrect submission (verdict: Wrong Answer):
def is_shiritori(s):
    before_mozi = None
    for mozi in s.split():
        if before_mozi is None:
            before_mozi = mozi
            continue
        else:
            if mozi[0] is not before_mozi[-1]:
                print("No")
                return False
            before_mozi = mozi
    print("OK")

is_shiritori(input())


Fixed, accepted submission:
def is_shiritori(s):
    before_mozi = None
    for mozi in s.split():
        if before_mozi is None:
            before_mozi = mozi
            continue
        else:
            if mozi[0] is not before_mozi[-1]:
                print("NO")
                return False
            before_mozi = mozi
    print("YES")

ss = input()
is_shiritori(ss)
Problem:
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges.   The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i.  An edge whose removal disconnects the graph is called a _bridge_.   Find the number of the edges that are bridges among the M edges.

Incorrect submission (verdict: Wrong Answer):


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

#n = len(g)
root = 0
order = [n]*n
low = [n]*n

s = [root]
cnt = 0
par = [-1]*n
seq = []
while s:
    v = s.pop()
    if order[v] != n:
        continue
    order[v] = cnt
    seq.append(v)
    low[v] = cnt
    cnt += 1
    for u in g[v]:
        if order[u] < cnt:
            if par[v] != u:
                low[v] = min(low[v], order[u])
                continue
        else:
            par[u] = v
            s.append(u)
child = [[] for _ in range(n)]
for v in range(n):
    if par[v] != -1:
        child[par[v]].append(v)
#seq.reverse()
#for v in seq:
    #for u in child[v]:
        #low[v] = min(low[v], low[u])
# bridge
bridge = []
for p in range(n):
    for c in child[p]:
        if order[p] < low[c]:
            bridge.append((p, c))

# articulation points
AP = []
for v in range(n):
    if v == root:
        if len(child[v]) >= 2:
            AP.append(v)
    else:
        for c in child[v]:
            if order[v] <= low[c]:
                AP.append(v)
                break

print(len(bridge))


Fixed, accepted submission:


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

def lowlink(g, root=0):
    n = len(g)
    order = [n]*n
    low = [n]*n

    s = [root]
    cnt = 0
    par = [-1]*n
    seq = []
    while s:
        v = s.pop()
        if order[v] != n:
            continue
        order[v] = cnt
        seq.append(v)
        low[v] = cnt
        cnt += 1
        for u in g[v]:
            if order[u] < cnt:
                if par[v] != u:
                    low[v] = min(low[v], order[u])
                    continue
            else:
                par[u] = v
                s.append(u)
    child = [[] for _ in range(n)]
    for v in range(n):
        if par[v] != -1:
            child[par[v]].append(v)
    seq.reverse()
    for v in seq:
        for u in child[v]:
            low[v] = min(low[v], low[u])
    # bridge
    bridge = []
    for p in range(n):
        for c in child[p]:
            if order[p] < low[c]:
                bridge.append((p, c))

    # articulation points
    AP = []
    for v in range(n):
        if v == root:
            if len(child[v]) >= 2:
                AP.append(v)
        else:
            for c in child[v]:
                if order[v] <= low[c]:
                    AP.append(v)
                    break
    return AP, bridge

_, bridge = lowlink(g, 0)
print(len(bridge))
Problem:
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i.  Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0.  Now, the following Q operations will be performed:    * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j.  Find the value of the counter on each vertex after all operations.

Incorrect submission (verdict: Wrong Answer):
#!/usr/bin/env python3
from collections import deque

n, q = map(int, input().split())
a, b = [0] * (-1 + n), [0] * (n - 1)
path = [[] for _ in range(n)]
for i in range(n - 1):
    a[i], b[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1
    path[a[i]].append(b[i])
    path[b[i]].append(a[i])
add = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    add[p] += x
q = deque()
ans = [0] * n

q.append(0)
visit = [0] * n
visit[0] = 1
ans[0] = add[0]
while q:
    pos = q.popleft()
    for v in path[pos]:
        if visit[v] == 0:
            ans[v] = ans[pos] + add[v]
            q.append(v)
            visit[v] = 1
print(ans)


Fixed, accepted submission:
#!/usr/bin/env python3
from collections import deque

n, q = map(int, input().split())
a, b = [0] * (-1 + n), [0] * (n - 1)
path = [[] for _ in range(n)]
for i in range(n - 1):
    a[i], b[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1
    path[a[i]].append(b[i])
    path[b[i]].append(a[i])
add = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    add[p] += x
q = deque()
ans = [0] * n

q.append(0)
visit = [0] * n
visit[0] = 1
ans[0] = add[0]
while q:
    pos = q.popleft()
    for v in path[pos]:
        if visit[v] == 0:
            ans[v] = ans[pos] + add[v]
            q.append(v)
            visit[v] = 1
print(*ans)