TnT/CodeNet4Repair huggingface dataset:
Problem:
Snuke has N dogs and M monkeys. He wants them to line up in a row.  As a Japanese saying goes, these dogs and monkeys are on bad terms. _("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.)_ Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.  How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.

Incorrect submission (verdict: Wrong Answer):
import sys
sys.setrecursionlimit(int(1e6))

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

base = int(1e9 + 7)
ans = 0
if abs(N -M) > 1:
  pass
else:
  fact = 1
  for i in range(1, min(N+1, M+1)):
    fact = (fact * i) % (base)
  
  if N == M:
    ans = 2 * fact * fact
  else:
    ans = fact * fact * max(N, M)
    
print(ans)

ans = ans % base
print(ans)


Fixed, accepted submission:
import sys
sys.setrecursionlimit(int(1e6))

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

base = int(1e9 + 7)
ans = 0
if abs(N -M) > 1:
  pass
else:
  fact = 1
  for i in range(1, min(N+1, M+1)):
    fact = (fact * i) % (base)
  
  if N == M:
    ans = 2 * fact * fact
  else:
    ans = fact * fact * max(N, M)
    
ans = ans % base
print(ans)
Problem:
AtCoDeer has three cards, one red, one green and one blue.   An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.   We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.   Is this integer a multiple of 4?

Incorrect submission (verdict: Wrong Answer):
a,b,c=map(str,input().split())
a+=b
a+=c
if int(a)%4==0:
    print("Yes")
else:
    print("No")

Fixed, accepted submission:
a,b,c=map(str,input().split())
a+=b
a+=c
if int(a)%4==0:
    print("YES")
else:
    print("NO")
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:
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(int(a)/int(b)))
    elif op == '?':
        break
Problem:
There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i.  Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W.  Find the maximum possible sum of the values of items that Taro takes home.

Incorrect submission (verdict: Wrong Answer):
def solve(n, w, items):
    dp = [[0] * (w + 1) for i in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(1, w + 1):
            prev = i - 1
            dp[i][j] = max(dp[i][j], dp[prev][j])
            weight, value = items[i - 1][0], items[i - 1][1]
            if j - weight >= 0:
                dp[i][j] = max(dp[i][j], dp[i][j - weight] + value)
    return dp[n][w]

def main():
    n, w = map(int, input().split())
    items = []
    for i in range(n):
        items.append(list(map(int, input().split())))
    ans = solve(n, w, items)
    print(ans)

main()


Fixed, accepted submission:
import numpy as np


def solve(w, items):
    dp = np.zeros(w + 1, dtype=int)

    for weight, value in items:
        dp[weight:] = np.maximum(dp[weight:], dp[:w-weight+1] + value)

    return dp[w]


def main():
    n, w = map(int, input().split())
    items = list(list(map(int, input().split())) for _ in range(n))

    ans = solve(w, items)
    print(ans)


main()
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):
# Simple Calculator

end = 0
while end == 0:
    n = [i for i in input().rstrip().split()]
    a = int(n[0])
    op = n[1]
    b = int(n[2])

    if op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    elif op == '/':
        print(a / b)
    else:
        end += 1



Fixed, accepted submission:
# Simple Calculator

end = 0
while end == 0:
    n = [i for i in input().rstrip().split()]
    a = int(n[0])
    op = n[1]
    b = int(n[2])

    if op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    elif op == '/':
        print(a // b)
    else:
        end += 1
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):
N = int(input())
if N % 1000:
    print(1000)
else:
    print(1000 - N % 1000)

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

if n % 1000 == 0:
  print(0)
else:
  print(1000 - n % 1000)
Problem:
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.  Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.  Given the name of the contest, print the abbreviation of the name.

Incorrect submission (verdict: Wrong Answer):
print("A%sC",input()[0])

Fixed, accepted submission:
print("A"+input()[8]+"C")
Problem:
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters.  We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person.  At most how many people can sit on the seat?

Incorrect submission (verdict: Wrong Answer):
X, Y, Z = map(int, input().split())
ans = X // (Y + 2*Z)
print(ans)

Fixed, accepted submission:
X, Y, Z = map(int, input().split())
ans = (X - Z) // (Y + Z)
print(ans)
Problem:
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not.  You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.

Incorrect submission (verdict: Wrong Answer):
s = input()
n = len(s)//2
for i in range(n):
    if s[:n-i] == s[n-i:2*(n-i)]:
        print(2*(n-i))
        break

Fixed, accepted submission:
s = input()
n = len(s)//2
for i in range(1,n):
    if s[:n-i] == s[n-i:2*(n-i)]:
        print(2*(n-i))
        break
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):
from collections import deque

N, M = map(int, input().split())
Gs = [[] for _ in range(N+1)]

for _ in range(M):
    a, b = map(int, input().split())
    Gs[a].append(b)
    Gs[b].append(a)

ms = [0] * (N+1)
def bfs(c):
    queue = deque()
    ns = Gs[c]
    for n in ns:
        queue.append((n, c))
    while queue:
        c, p = queue.popleft()

        if ms[c] != 0:
            continue

        ms[c] = p

        ns = Gs[c]
        for n in ns:
            if n != p:
                queue.append((n, c))

bfs(1)

print(ms)
for m in ms[2:]:
    if m == 0:
        print('No')
        break
else:
    print('Yes')
    for m in ms[2:]:
        print(m)


Fixed, accepted submission:
from collections import deque

N, M = map(int, input().split())
Gs = [[] for _ in range(N+1)]

for _ in range(M):
    a, b = map(int, input().split())
    Gs[a].append(b)
    Gs[b].append(a)

ms = [0] * (N+1)
def bfs(c):
    queue = deque()
    ns = Gs[c]
    for n in ns:
        queue.append((n, c))
    while queue:
        c, p = queue.popleft()

        if ms[c] != 0:
            continue

        ms[c] = p

        ns = Gs[c]
        for n in ns:
            if n != p:
                queue.append((n, c))

bfs(1)

for m in ms[2:]:
    if m == 0:
        print('No')
        break
else:
    print('Yes')
    for m in ms[2:]:
        print(m)
Problem:
Print all the integers that satisfies the following in ascending order:    * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.

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

a,b,k = map(int,input().split())
list = []

for i in range(a,a+k):
    list.append(i)

for i in range(b,b-k,-1):
    list.append(i)

list.sort()

l = set(list)

for i in l:
    print(i)


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

a,b,k = map(int,input().split())
lists = []

for i in range(a,min(a+k,b+1)):
    lists.append(i)

for i in range(b,max(b-k,a),-1):
    lists.append(i)

l = set(lists)
m = list(l)

m.sort()

for i in m:
    print(i)
Problem:
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i.  Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.

Incorrect submission (verdict: Wrong Answer):
n = input()
i = []
for x in range(int(n)):
    if x % 2 == 0:
        i.append(x)
print(len(i))

Fixed, accepted submission:
print(input().count("1"))
Problem:
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}.  Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.

Incorrect submission (verdict: Wrong Answer):
h,w=map(int,input().split())
print("*"*(w+2))
for i in range(h):
    a=input()
    print("*"+a+"*")
print("*"*(w+2))

Fixed, accepted submission:
h,w=map(int,input().split())
print("#"*(w+2))
for i in range(h):
    a=input()
    print("#"+a+"#")
print("#"*(w+2))
Problem:
M-kun has the following three cards:    * A red card with the integer A.   * A green card with the integer B.   * A blue card with the integer C.  He is a genius magician who can do the following operation at most K times:    * Choose one of the three cards and multiply the written integer by 2.  His magic is successful if both of the following conditions are satisfied after the operations:    * The integer on the green card is **strictly** greater than the integer on the red card.   * The integer on the blue card is **strictly** greater than the integer on the green card.  Determine whether the magic can be successful.

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

while 1:
  if n == 0:
    print("No")
    break
  elif a[0] >= a[1]:
    a[1] *= 2
    n -= 1
  elif a[1] >= a[2]:
    a[2] *= 2
    n -= 1
  else:
    print("Yse")
    break

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

for i in range(n):
    if a[0] >= a[1]:
        a[1] *= 2
    elif a[1] >= a[2]:
        a[2] *= 2
    
if a[0] < a[1] < a[2]:
    print("Yes")
else:
    print("No")
Problem:
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.

Incorrect submission (verdict: Wrong Answer):
from bisect import bisect_left
from scipy.misc import comb

N = int(input())
A = sorted(map(int, input().split()))
if N == 2:
    print(*A[::-1])
    quit()

n = A.pop()
idx = bisect_left(A, n // 2)
print(n, (A[idx] if comb(n, A[idx]) > comb(n, A[idx - 1]) else A[idx - 1]))


Fixed, accepted submission:
import numpy as np
N = int(input())
M, *A = sorted(map(int, input().split()), reverse=True)
if N == 2:
    print(M, *A)
    quit()
print(M, A[np.abs(np.array(A, dtype=np.int64) - M / 2).argmin()])
Problem:
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second.  He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.

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

if abs(v-w)*t>abs(a-b):
  print("NO")
else:
  print("YES")

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

if (v-w)*t<abs(a-b):
  print("NO")
else:
  print("YES")
Problem:
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`.  You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.

Incorrect submission (verdict: Wrong Answer):
A,B = list(map(int,input().split(" ")))
S = input()

for i in range(len(S)):
    if i==A:
        if S[i]!="-":
            print("No")
            exit()
    else:
        if not ord('0')<=i<=ord('9'):
            print("No")
            exit()
print("Yes")
            


Fixed, accepted submission:
A,B = list(map(int,input().split(" ")))
S = input()

for i in range(len(S)):

    if i==A:
        if S[i]!="-":
            print("No")
            exit()
    else:
        if not ord('0')<=ord(str(S[i]))<=ord('9'):
            print("No")
            exit()
print("Yes")
Problem:
Takahashi loves numbers divisible by 2.  You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.  Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.  For example,    * 6 can be divided by 2 once: 6 -> 3.   * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.   * 3 can be divided by 2 zero times.

Incorrect submission (verdict: Wrong Answer):
A = int(input())
list=[]
for i in range(0, A+1 , 2):
    list.append(i)
print(list[-1])


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

answer = 1
while answer*2 <= N:
  answer *= 2
  #print(answer)
print(answer)
Problem:
Write a program which reads two integers a and b, and calculates the following values:    * a ÷ b: d (in integer)   * remainder of a ÷ b: r (in integer)   * a ÷ b: f (in real number)

Incorrect submission (verdict: Wrong Answer):
a,b =[int(i) for i in input().split()]
#a=3
#b=2
A=[a//b,a%b,a/b]
print("{0} {1} {2}".format(A[0],A[1],A[2]))

Fixed, accepted submission:
a,b =[int(i) for i in input().split()]
#a=2
#b=100000009

A=[a//b,a%b,a/b]
print("{0} {1} {2:.5f}".format(A[0],A[1],A[2]))
Problem:
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i.  Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.

Incorrect submission (verdict: Wrong Answer):
s = list(input())
print(s,s.count('1'))

Fixed, accepted submission:
s = list(input())
print(s.count('1'))
Problem:
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.  The problem has N test cases.  For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.  See the Output section for the output format.

Incorrect submission (verdict: Wrong Answer):
t=int(input())
ac=0
wa=0
tle=0
re=0
for _ in range(t):
  s=input()
  if(s=="AC"):
    ac+=1
  elif(s=="WA"):
    wa+=1
  elif(s=="TLE"):
    tle+=1
  else:
    re+=1
print("AC X ",ac)
print("WA X ",wa)
print("TLE X ",tle)
print("RE X ",re)
    
   

Fixed, accepted submission:
t=int(input())
ac=0
wa=0
tle=0
re=0
for _ in range(t):
  s=input()
  if(s=="AC"):
    ac+=1
  elif(s=="WA"):
    wa+=1
  elif(s=="TLE"):
    tle+=1
  else:
    re+=1
print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)
Problem:
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.  To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.

Incorrect submission (verdict: Wrong Answer):
a,b,c=map(int,input().split())
if a==5 and b==7 and c==5:
    print('YES')
else:
    print('NO')

Fixed, accepted submission:
a=list(map(int,input().split()))
b=sorted(a)
if b[0]==5 and b[1]==5 and b[2]==7:
    print('YES')
else:
    print('NO')
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):
a, op, b = map(str, 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))
else:
    exit()


Fixed, accepted submission:
while True:
    a, op, b = map(str, 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))
    else:
        exit()
Problem:
You are given a tree with N vertices 1,2,\ldots,N, and positive integers c_1,c_2,\ldots,c_N. The i-th edge in the tree (1 \leq i \leq N-1) connects Vertex a_i and Vertex b_i.  We will write a positive integer on each vertex in T and calculate our _score_ as follows:    * On each edge, write the smaller of the integers written on the two endpoints.   * Let our score be the sum of the integers written on all the edges.  Find the maximum possible score when we write each of c_1,c_2,\ldots,c_N on one vertex in T, and show one way to achieve it. If an integer occurs multiple times in c_1,c_2,\ldots,c_N, we must use it that number of times.

Incorrect submission (verdict: Wrong Answer):

nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()


N = n()
M = 0
ds = [None] * N

ranks = [0] * N
for i in range(N-1):
    a, b = nl()
    ranks[a-1] += 1
    ranks[b-1] += 1
cs = sorted(nl())
M = sum(cs[:-1])

ranks = [[i, ranks[i]] for i in range(N)]
ranks = sorted(ranks, key=lambda r: r[1])

for i in range(N):
    ds[ranks[i][0]] = cs[i]

print(M)
print(' '.join([str(d) for d in ds]))


Fixed, accepted submission:
import heapq
from collections import defaultdict

nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()


N = n()
M = 0
ds = [None] * N

edges = defaultdict(set)
ranks = [0] * N
for i in range(N-1):
    a, b = nl()
    edges[a-1].add(b-1)
    edges[b-1].add(a-1)
    ranks[a-1] += 1
    ranks[b-1] += 1
cs = sorted(nl())
M = sum(cs[:-1])

h = []
for i in range(N):
    heapq.heappush(h, (ranks[i], i))

for i in range(N):
    rank, node = heapq.heappop(h)
    ds[node] = cs[i]
    for next_node in edges[node]:
        ranks[next_node] -= 1
        heapq.heappush(h, (ranks[next_node], next_node))
        edges[next_node].remove(node)

print(M)
print(' '.join([str(d) for d in ds]))
Problem:
N persons are standing in a row. The height of the i-th person from the front is A_i.  We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:  Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.  Find the minimum total height of the stools needed to meet this goal.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
s = 0
if N==1:
  print(0)
  exit()

for i,a in enumerate(A):
  if i==0:
    continue
  
  s+=(a<A[i-1])*a

print(s)

Fixed, accepted submission:
N = int(input())
A = list(map(int, input().split()))
s = 0
if N==1:
  print(0)
  exit()

for i,a in enumerate(A):
  if i==0:
    continue
  
  tmp = A[i-1] - a
  if tmp>0:
    A[i] = A[i-1]
    s += tmp

print(s)
Problem:
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.  He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.  Find the minimum number of balls that Takahashi needs to rewrite the integers on them.

Incorrect submission (verdict: Wrong Answer):
N, K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
print(A)
a = 0
b = 0
B = [A[0]]
s = 200001
t = 0
u = 0
for k in range(N):
    if not A[k] in B:
        B.append(A[k])
        a += 1
for i in range(N):
        if A.count(A[i]) > u:
            u = A.count(A[i])
            v = A[i]
        if A.count(A[i]) < s:
            s = A.count(A[i])
            t = A[i]
while a >= K:
    a -= 1
    b += 1
    for i in range(N):
        for j in range(N):
            if A[j] == t:
                A[j] = s
        if A.count(A[i]) > u:
            u = A.count(A[i])
            v = A[i]
        if A.count(A[i]) < s:
            s = A.count(A[i])
            t = A[i]


print(b)

Fixed, accepted submission:
N,K=map(int,input().split())
B = [0] * (N)
for a in map(int,input().split()):
  B[a-1] += 1
B=sorted(B)[::-1]
print(sum(B[K:]))