TnT/CodeNet4Repair huggingface dataset:
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):
l = input()
print(int(l[-3:]))

Fixed, accepted submission:
l = input()
if int(l[-3:]) == 0:
  print(0)
else:
  print(1000-int(l[-3:]))
Problem:
E869120 has A 1-yen coins and infinitely many 500-yen coins.   Determine if he can pay exactly N yen using only these coins.

Incorrect submission (verdict: Wrong Answer):
if (int(input()) - int(input())) % 500 == 0:
  print('Yes')
else:
  print('No')

Fixed, accepted submission:
print('Yes' if int(input()) % 500 <= int(input()) else 'No')
Problem:
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.

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

a, b = map(int, input().split())

if a*b%2 == 0:
  print("0dd")
else:
  print("Even")

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

if a*b%2 == 0:
  print('Even')
else:
  print('Odd')
Problem:
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`.  After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.

Incorrect submission (verdict: Wrong Answer):
s=str(input())
print(s.replace("2018","2017"))

Fixed, accepted submission:
s=str(input())
print(s.replace("2017","2018"))
Problem:
In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019.  Integers M_1, D_1, M_2, and D_2 will be given as input.   It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1.   Determine whether the date 2019-M_1-D_1 is the last day of a month.

Incorrect submission (verdict: Wrong Answer):
import numpy as np
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
x = [30] * 13
x[1] = x[3] = x[5] = x[7] = x[8] = x[10] = x[12] = 31
x[2] = 28
x[0] = 0
x = np.add.accumulate(x)
print('1' if x[m1 - 1] + d1 + 1 == x[m2 - 1] + d2 else '0')


Fixed, accepted submission:
import numpy as np
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
x = [30] * 13
x[1] = x[3] = x[5] = x[7] = x[8] = x[10] = x[12] = 31
x[2] = 28
x[0] = 0
print('1' if x[m1] == d1 else '0')
Problem:
There is a hotel with the following accommodation fee:    * X yen (the currency of Japan) per night, for the first K nights   * Y yen per night, for the (K+1)-th and subsequent nights  Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.

Incorrect submission (verdict: Wrong Answer):
n=int(input())
k=int(input())
x=int(input())
y=int(input())
print(n*x if n<=k else n*x+(n-k)*y)

Fixed, accepted submission:
n = int(input())
k = int(input())
x = int(input())
y = int(input())
print(n*x if n <= k else k*x+(n-k)*y)
Problem:
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b.  The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.

Incorrect submission (verdict: Wrong Answer):
while True:
    a, op, b = input().split(' ')
    if (op == '+'):
        print(int(a) + int(b))
    elif (op == '-'):
        print(int(a) - int(b))
    elif (op == '*'):
        print(int(a) * int(b))
    elif (op == '/'):
        print(int(a) / int(b))
    elif (op == '?'):
        break


Fixed, accepted submission:
import math 
while True:
    a, op, b = input().split()
    if (op == '+'):
        print(int(a) + int(b))
    elif (op == '-'):
        print(int(a) - int(b))
    elif (op == '*'):
        print(int(a) * int(b))
    elif (op == '/' and int(b) != 0):
        print(math.trunc((int(a) / int(b))))
    elif (op == '?' ):
        break
Problem:
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.  The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)  Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?

Incorrect submission (verdict: Wrong Answer):
X = int(input())
ans = 100
cnt = 0
risok = 0
while ans <= X:
    cnt += 1
    risok = int(ans * 0.01)
    ans = ans + risok
print(cnt)


Fixed, accepted submission:
X = int(input())
ans = 100
year = 0

while ans < X:
    year += 1
    ans = int(ans*1.01)
print(year)
Problem:
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
def make_prime_list(num):
    if num < 2:
        return []

    prime_list = []
    for prime in range(2, num + 1):
        if is_prime(prime):
            prime_list.append(prime)
    return prime_list
  
def is_prime(num):
    if num < 2:
        return False
    if num == 2 or num == 3 or num == 5:
        return True
    if num % 2 == 0 or num % 3 == 0 or num % 5 == 0:
        return False

    
    prime = 7
    step = 4
    num_sqrt = math.sqrt(num)
    while prime <= num_sqrt:
        if num % prime == 0:
            return False
        prime += step
        step = 6 - step

    return True
  

import math
from collections import defaultdict
def search_divisor_num_of_factorial_num(num):
    if num <= 0:
        return 0
    elif num == 1 or num == 2:
        return 1
    else:
        
        dict_counter = defaultdict(int)
        
        dict_memo = defaultdict(list)

        for a_num in range(2, num + 1):
            num_sqrt = math.ceil(math.sqrt(a_num))
            prime_list = make_prime_list(num_sqrt)

            に入れるためのkeyを残しておく
            now_num = a_num

            for prime in prime_list:
                while a_num % prime == 0:
                    
                    if a_num in dict_memo:
                        for memo in dict_memo[a_num]:
                            dict_counter[memo] += 1
                            dict_memo[now_num].append(memo)

                        a_num = 1

                    else:
                        dict_counter[prime] += 1
                        dict_memo[now_num].append(prime)
                        a_num //= prime

            if a_num != 1:
                dict_counter[a_num] += 1
                dict_memo[now_num].append(a_num)

        divisor_num = 1
        dict_fact = dict(dict_counter)
        for value in dict_fact.values():
            divisor_num *= (value + 1)

        return divisor_num
print(search_divisor_num_of_factorial_num(N) % (10 ** 9 + 7))

Fixed, accepted submission:
N = int(input())
import math
def is_prime(num):
    if num < 2:
        return False
    if num == 2 or num == 3 or num == 5:
        return True
    if num % 2 == 0 or num % 3 == 0 or num % 5 == 0:
        return False

    
    prime = 7
    step = 4
    num_sqrt = math.sqrt(num)
    while prime <= num_sqrt:
        if num % prime == 0:
            return False
        prime += step
        step = 6 - step

    return True
  
def make_prime_list(num):
    if num < 2:
        return []

    prime_list = []
    for prime in range(2, num + 1):
        if is_prime(prime):
            prime_list.append(prime)
    return prime_list
  
num = N
prime_list = make_prime_list(num)
pcount={}
for p in prime_list:
    pcount[p]=0
for nn in range(2,num+1):
    for p in prime_list:
        n=nn
        if n<p:
            break
        while n%p==0:
            n//=p
            pcount[p]+=1
            
ans = 1
for i in pcount.values():
    ans *= (i + 1)
print(ans % (10 ** 9 + 7))
Problem:
Niwango-kun is an employee of Dwango Co., Ltd.   One day, he is asked to generate a thumbnail from a video a user submitted.   To generate a thumbnail, he needs to select a frame of the video according to the following procedure:    * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video.   * Select t-th frame whose representation a_t is nearest to the average of all frame representations.   * If there are multiple such frames, select the frame with the smallest index.  Find the index t of the frame he should select to generate a thumbnail.

Incorrect submission (verdict: Wrong Answer):
print(int((int(input())+1)/2))

Fixed, accepted submission:
N=int(input())
A=list(map(int,input().split(' ')))
m=sum(A)/N
B=[abs(a-m) for a in A]
print(B.index(min(B)))
Problem:
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied:    * Each lowercase letter of the English alphabet occurs even number of times in w.  You are given the string w. Determine if w is beautiful.

Incorrect submission (verdict: Wrong Answer):
S = input()
ec = 0
c = {}
for each in S:
    try:
        c[each] += 1
        if c[each] % 2 == 0:
            ec -= 1
        else:
            ec += 1
    except:
        c[each] = 1
        ec += 1
if (ec == 0):
    print("YES")
else:
    print("NO")


Fixed, accepted submission:
S = input()
ec = 0
c = {}
for each in S:
    try:
        c[each] += 1
        if c[each] % 2 == 0:
            ec -= 1
        else:
            ec += 1
    except:
        c[each] = 1
        ec += 1
if (ec == 0):
    print("Yes")
else:
    print("No")
Problem:
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.  The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day:    * A: Swim in the sea. Gain a_i points of happiness.   * B: Catch bugs in the mountains. Gain b_i points of happiness.   * C: Do homework at home. Gain c_i points of happiness.  As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.  Find the maximum possible total points of happiness that Taro gains.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
abc = [list(map(int, input().split())) for i in range(n)]
dp = [-1] * n
m = max(abc[0])
dp[0] = m
x = abc[0].index(m)

for i in range(1,n):
    m = -1
    t = -1
    for j in range(3):
        if x == j:
            continue
        print(j,x)
        if m < abc[i][j]:
            m = abc[i][j]
            t = j
    x = t
    dp[i] = m + dp[i-1]
print(dp[-1])


Fixed, accepted submission:
n = int(input())
abc = [tuple(map(int,input().split())) for i in range(n)]

dp = [[0,0,0] for i in range(n+1)]


for i in range(n):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][k] = max(dp[i+1][k],dp[i][j]+abc[i][k])

print(max(dp[-1]))
Problem:
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N.  In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N.  When activated, each type of robot will operate as follows.    * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.    * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.  Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.

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

n = int(input())
k = int(input())
x = list(map(int, input().split())) #x[0->(n-1)]

sum = 0

for i in x:
    if i > k - i:
        sum = sum + i
    else:
        sum = sum + k - i

print(sum)

Fixed, accepted submission:
# -*- coding: utf-8 -*-

n = int(input())
k = int(input())
x = list(map(int, input().split())) #x[0->(n-1)]

sum = 0

for i in x:
    if i < k - i:
        sum = sum + i
    else:
        sum = sum + k - i

print(sum*2)
Problem:
You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion.  All strings that can be obtained in this way can be evaluated as formulas.  Evaluate all possible formulas, and print the sum of the results.

Incorrect submission (verdict: Wrong Answer):
def abc045_c():
    S = list(input())
    for i in range(len(S)-1):
        i = i * 2 + 1
        S.insert(i,'+')
    abc045_c2(S)

def abc045_c2(S):
    cnt = 0
    for i in range(S.count('+')):
        cnt += eval(''.join(S))
        i = i + 1
        del S[i]
    print(cnt)
    
if __name__ == '__main__':
    abc045_c()

Fixed, accepted submission:
def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split('+'))))

    return dfs(i + 1, f + a[i + 1]) + dfs(i + 1, f + '+' + a[i + 1])


a = input()
n = len(a)

print(dfs(0, a[0]))
Problem:
2 つの正の整数 p, q を入力し、 p / q を小数として正確に表現することを考えます。(ただし、0 < p < q < 106とします。)  このとき、結果は    * 有限の桁で正確に表現できる。   * ある桁の範囲を繰り返す循環小数となる。  のいずれかとなります。筆算と同じ手順で1桁ずつ小数部を求めていくと、    * 割り切れた(余りが 0 になった)なら、そこまでの桁で正確に表現できた。   * 1度出てきた余りが、再び現れたなら、循環した。  と区別できます。  2 つの整数 p, q を入力すると、 p / q を小数で表した時の、小数部を出力するプログラムを作成してください。 ただし、    * 結果が有限の桁で正確に表現できる時は、数値だけを 1 行に出力してください。   * 結果が循環小数になる時は次のように 2 行に出力してください。      * 最初の行に、循環する部分までの数字を出力してください。     * 次の行には、循環しない部分の下には空白を出力し、循環する部分の下には「^」を出力してください。   * いずれの場合も数字列は 80 文字を超えることはないものとします。

Incorrect submission (verdict: Wrong Answer):
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0113
"""
import sys



def solve(p, q):
    quotients = []
    mods = []
    cyclic = False
    cycle_start = 0
    cycle_length = 0

    while True:
        mods.append(p)
        p *= 10
        quotients.append(p // q)
        p = p % q

        if p == 0:
            break
        if p in mods:
            cyclic = True
            cycle_start = mods.index(p)
            cycle_length = len(quotients) - mods.index(p)
            break

    return cyclic, quotients, cycle_start, cycle_length


def main(args):
    p = 100000
    q = 32768
    cyclic, quotients, cycle_start, cycle_length = solve(p, q)
    if cyclic:
        print(''.join(map(str, quotients)))
        print(' '*cycle_start + '^'*cycle_length)
    else:
        print(''.join(map(str, quotients)))


if __name__ == '__main__':
    main(sys.argv[1:])

Fixed, accepted submission:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0113
"""
import sys



def solve(p, q):
    quotients = []
    mods = []
    cyclic = False
    cycle_start = 0
    cycle_length = 0

    while True:
        mods.append(p)
        p *= 10
        quotients.append(p // q)
        p = p % q

        if p == 0:
            break
        if p in mods:
            cyclic = True
            cycle_start = mods.index(p)
            cycle_length = len(quotients) - mods.index(p)
            break

    return cyclic, quotients, cycle_start, cycle_length


def main(args):
    for line in sys.stdin:
        p, q = [int(x) for x in line.strip().split(' ')]
        cyclic, quotients, cycle_start, cycle_length = solve(p, q)
        if cyclic:
            print(''.join(map(str, quotients)))
            print(' '*cycle_start + '^'*cycle_length)
        else:
            print(''.join(map(str, quotients)))


if __name__ == '__main__':
    main(sys.argv[1:])
Problem:
How many multiples of d are there among the integers between L and R (inclusive)?

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

count = 0

for i in range(int(b)):
  i+=int(a)
  if i % int(c) == 0:
    count+=1

print(count)

Fixed, accepted submission:
a,b,c = input().split()
 
count = 0
num = int(a)

while num <= int(b):
  if num % int(c) == 0:
    count+=1
  num += 1
 
print(count)
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):
a = input()
b = input()
if(a[0] == b[2] and a[1] == b[1] and a[2] == b[0]):
    print("Yes")
else:
    print("No")


Fixed, accepted submission:
a = input()
b = input()
if(a[0] == b[2] and a[1] == b[1] and a[2] == b[0]):
    print("YES")
else:
    print("NO")
Problem:
There is a cave.  The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside.  It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage.  Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1.    * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.  Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.

Incorrect submission (verdict: Wrong Answer):
print('No')

Fixed, accepted submission:
from collections import deque
n, m = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(m)]

ans = [deque([]) for _ in range(m+10)]
ans2 = [[] for _ in range(m+10)]
for i in range(m):
    s = li[i][0]
    t = li[i][1]

    ans[s].append(t)
    ans[t].append(s)

stack = deque([1])
while stack:
    v = stack[0]

    if ans[v]:
        w = ans[v].popleft()
        if True:
            ans2[w].append(v)
        stack.append(w)
    else:
        stack.popleft()

print('Yes')
for i in range(2, n+1):
    print(ans2[i][0])
Problem:
We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.  However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells.  Find the number of ways she can travel to the bottom-right cell.  Since this number can be extremely large, print the number modulo 10^9+7.

Incorrect submission (verdict: Time Limit Exceeded):
h,w,a,b=map(int,input().split())

p=10**9+7
#p=127

def modp_factorial(n):
    s=1
    for x in range(1,h+1):
        s=(s*x) % p
    return s
def modp_prod(lst):
    s=1
    for x in lst:
        s=(s*x)%p
    return s
def inv(n):
    s=1
    q=p-2
    while q>0:
        if q&1:
            s=s*n % p
        n=n*n
        q>>=1
    return s

l=[1]
f=1
for x in range(1,h+w+1):
    f=f*x % p
    l.append(f)
invl=[inv(l[-1])]
for n in range(h+w,1,-1):
    invl.append((invl[-1]*n) % p)
invl.append(1)
invl.reverse()


s=0
for x in range(1,h-a+1):
    s=s+modp_prod([l[x+b-2],invl[x-1],invl[b-1]\
        ,l[w-b+h-x-1],invl[h-x],invl[w-b-1]])% p
print(s)


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

p=10**9+7
#p=127

def modp_factorial(n):
    s=1
    for x in range(1,h+1):
        s=(s*x) % p
    return s
def modp_prod(lst):
    s=1
    for x in lst:
        s=(s*x)%p
    return s
def inv(n):
    s=1
    q=p-2
    while q>0:
        if q&1:
            s=(s*n) % p
        n=(n*n) % p
        q>>=1
    return s

l=[1]
f=1
for x in range(1,h+w):
    f=(f*x) % p
    l.append(f)
invl=[inv(l[-1])]
for n in range(h+w-1,1,-1):
    invl.append((invl[-1]*n) % p)

invl.append(1)
invl.reverse()


s=0
for x in range(1,h-a+1):
    s=(s+modp_prod([l[x+b-2],invl[x-1],invl[b-1]\
        ,l[w-b+h-x-1],invl[h-x],invl[w-b-1]])) % p
print(s)
Problem:
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N.  There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i.  Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.  Help him.

Incorrect submission (verdict: Wrong Answer):
from operator import itemgetter
N, M = map(int, input().split())
ab = []
for i in range(M):
    a,b = map(int, input().split())
    ab.append((a,b))
ab.sort(key=itemgetter(0))
print(ab)
fl = False
for i,j in ab:
    if i!=1:
        continue
    for k,l in ab:
        if i==1 and (j!=k or l!=N):
            continue
        else:
            fl = True
print('POSSIBLE') if fl else print('IMPOSSIBLE')

Fixed, accepted submission:
from collections import defaultdict
N, M = map(int, input().split())
d = defaultdict(list)
for i in range(M):
    a,b = map(int, input().split())
    d[a].append(b)

for j in d[1]:
    if N in d[j]:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')
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):
A = int(input())
B = int(input())
H = int(input())

print((A+B)*H/2)

Fixed, accepted submission:
A = int(input())
B = int(input())
H = int(input())
answer = (H*(A+B)//2)

print(answer)
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):
def pay(N):
	return N % 1000

Fixed, accepted submission:
N = int(input())
N = (1000 - N % 1000) % 1000
print(N)