TnT/CodeNet4Repair huggingface dataset:
Problem:
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s).  Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.

Incorrect submission (verdict: Wrong Answer):
s = input()
a_index = 0
z_index = 0

for i in range(0, len(s)):
    if s[i] == "A":
        a_index = i
        break
        
for i in range(0, len(s)):
    if s[len(s)-i-1] == "Z":
        z_index = len(s)-i
        break
print(s[a_index:z_index])

Fixed, accepted submission:
s = input()
a_index = 0
z_index = 0

for i in range(0, len(s)):
    if s[i] == "A":
        a_index = i
        break
        
for i in range(0, len(s)):
    if s[len(s)-i-1] == "Z":
        z_index = len(s)-i-1
        break
print(z_index - a_index +1)
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())

ans = 0

for m in range(max(x, y)+1):
    price = (2*m*c) + max(0, (x-m))*a + max(0, y-m)*b
    ans = min(ans, price)

print(ans)

Fixed, accepted submission:
a, b, c, x, y=map(int,input().split())
 
cnt = 10**9
for m in range(max(x,y)+1):
    price = (2*m*c) + max(0,(x-m))*a + max(0,y-m)*b
    cnt = min(cnt, price)

print(cnt)
Problem:
You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like.

Incorrect submission (verdict: Wrong Answer):
N = int(input())

num_list = []
for _ in range(N):
    num_list.append(int(input()))
    
num_sorted = sorted(num_list)

def calc_diff(add, add2, diff, diff2, num_sorted):
    total = 0
    
    for _ in range(add2):
        tmp = num_sorted.pop()
        total += tmp * 2
        
    for _ in range(add):
        tmp = num_sorted.pop()
        total += tmp * 1
        
    for _ in range(diff):
        tmp = num_sorted.pop()
        total -= tmp * 1
            
    for _ in range(diff2):
        tmp = num_sorted.pop()
        total -= tmp * 2
        
    return total
  
import copy

def calc(N, num_sorted):
    
    diff2 = 0
    add2 = 0
    diff = 0
    add = 0
    
    if N % 2 == 0:
        add = 1
        diff = 1
        add2 = N // 2 - 1
        diff2 = N // 2 - 1
        
        total = calc_diff(add, add2, diff, diff2, copy.deepcopy(num_sorted))

        return total
            
    if N % 2 == 1:        
        add = 0
        diff = 2
        add2 =(N - 1) // 2
        diff2 = (N - 1) // 2 - 1
        
        totalB = calc_diff(add, add2, diff, diff2, copy.deepcopy(num_sorted))
        
        add = 2
        diff = 0
        add2 =(N - 1) // 2 - 1
        diff2 = (N - 1) // 2
        
        totalC = calc_diff(add, add2, diff, diff2, copy.deepcopy(num_sorted))
        
        return max(totalB, totalC)
      
calc(N, num_sorted)

Fixed, accepted submission:
N = int(input())
 
num_list = []
for _ in range(N):
    num_list.append(int(input()))
    
num_sorted = sorted(num_list)
 
def calc_diff(add, add2, diff, diff2, num_sorted):
    total = 0
    
    for _ in range(add2):
        tmp = num_sorted.pop()
        total += tmp * 2
        
    for _ in range(add):
        tmp = num_sorted.pop()
        total += tmp * 1
        
    for _ in range(diff):
        tmp = num_sorted.pop()
        total -= tmp * 1
            
    for _ in range(diff2):
        tmp = num_sorted.pop()
        total -= tmp * 2
        
    return total
  
import copy
 
def calc(N, num_sorted):
    
    diff2 = 0
    add2 = 0
    diff = 0
    add = 0
    
    if N % 2 == 0:
        add = 1
        diff = 1
        add2 = N // 2 - 1
        diff2 = N // 2 - 1
        
        total = calc_diff(add, add2, diff, diff2, copy.deepcopy(num_sorted))
 
        return total
            
    if N % 2 == 1:        
        add = 0
        diff = 2
        add2 =(N - 1) // 2
        diff2 = (N - 1) // 2 - 1
        
        totalB = calc_diff(add, add2, diff, diff2, copy.deepcopy(num_sorted))
        
        add = 2
        diff = 0
        add2 =(N - 1) // 2 - 1
        diff2 = (N - 1) // 2
        
        totalC = calc_diff(add, add2, diff, diff2, copy.deepcopy(num_sorted))
        
        return max(totalB, totalC)
      
print(calc(N, num_sorted))
Problem:
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi.  Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?

Incorrect submission (verdict: Wrong Answer):
# -*- coding: utf-8 -*-
n=int(input())
d_list=list(map(int,input().split()))
d_set = set(d_list)
print(len(d_set))

Fixed, accepted submission:
n=int(input())
a_list=[input() for i in range(n)]
a_list_int = [int(n) for n in a_list]
a_set_int = set(a_list_int)
print(len(a_set_int))
Problem:
We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left.   According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j.   Determine if he is correct.

Incorrect submission (verdict: Wrong Answer):
c = []
for _ in range(3) :
    c += [list(map(int, input().split()))]
a1 = c[1][0]-c[0][0]
a2 = c[2][0]-c[0][0]
c1 = [c[0][i] + a1 for i in range(3)]
c2 = [c[0][i] + a2 for i in range(3)]
if c[1] == c1 and c[2] == c2 :
    print("yes")
else :
    print("no")

Fixed, accepted submission:
c = []
for _ in range(3) :
    c += [list(map(int, input().split()))]
a1 = c[1][0]-c[0][0]
a2 = c[2][0]-c[0][0]
c1 = [c[0][i] + a1 for i in range(3)]
c2 = [c[0][i] + a2 for i in range(3)]
if c[1] == c1 and c[2] == c2 :
    print("Yes")
else :
    print("No")
Problem:
Snuke has a favorite restaurant.  The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer.  So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
print(800 * n - (n // 15) ** 200)

Fixed, accepted submission:
n = int(input())
print(800 * n - 200 * (n // 15))
Problem:
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
S = list(input())
K = int(input())
a = S[K-1]
print(a)
for i in range(N):
    if S[i]!=a:
        S[i] = '*'
print(*S,sep='')

Fixed, accepted submission:
N = int(input())
S = list(input())
K = int(input())
a = S[K-1]
for i in range(N):
    if S[i]!=a:
        S[i] = '*'
print(*S,sep='')
Problem:
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions:    * The graph is simple and connected.   * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S.  It can be proved that at least one such graph exists under the constraints of this problem.

Incorrect submission (verdict: Wrong Answer):
def find(N):
    k=N//2
    edges=[]
    if N==2*k:
        for i in range(1,k):
            edges+=[(i,N-i)]
            edges+=[(i,i+1)]
            edges+=[(N+1-i,i+1)]
            edges+=[(N+1-i,N-i)]
        edges+=[(k,1)]
        edges+=[(k,N)]
        edges+=[(k+1,1)]
        edges+=[(k+1,N)]
        edges=set(edges)
        print(len(edges))
        for X in edges:
            print(X[0],X[1])
    else:
        for i in range(1,k):
            edges+=[(i,N-1-i)]
            edges+=[(i,i+1)]
            edges+=[(N-1+1-i,i+1)]
            edges+=[(N-1+1-i,N-1-i)]
        edges+=[(k,N),(N-k,N),(1,N),(N-1,N)]
        edges=set(edges)
        print(len(edges))
        for X in edges:
            print(X[0],X[1])
            
find(int(input()))         
            
        
        

Fixed, accepted submission:
def find(N):
    
    if N==3:
        print(2)
        print(1,3)
        print(2,3)
        return 0
        
    if N==4:
        print(4)
        print(1,2)
        print(2,4)
        print(3,4)
        print(1,3)
        return 0
    
    k=N//2
    edges=[]
    if N==2*k:
        for i in range(1,k):
            edges+=[(i,N-i)]
            edges+=[(i,i+1)]
            edges+=[(N+1-i,i+1)]
            edges+=[(N+1-i,N-i)]
        edges+=[(k,1)]
        edges+=[(k,N)]
        edges+=[(k+1,1)]
        edges+=[(k+1,N)]
        edges=set(edges)
        print(len(edges))
        for X in edges:
            print(X[0],X[1])
    else:
        for i in range(1,k):
            edges+=[(i,N-1-i)]
            edges+=[(i,i+1)]
            edges+=[(N-1+1-i,i+1)]
            edges+=[(N-1+1-i,N-1-i)]
        edges+=[(k,N),(N-k,N),(1,N),(N-1,N)]
        edges=set(edges)
        print(len(edges))
        for X in edges:
            print(X[0],X[1])
            
find(int(input()))
Problem:
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.  They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card.  Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.

Incorrect submission (verdict: Wrong Answer):
import math as ma
N = int(input())
a = list(map(int, input().split()))
s = sum(a)
A = 0
diff = 9999999999
for i in range(N):
    A += a[i]
    if diff > (ma.fabs(2*A - s)):
        diff = ma.fabs(2*A -s)
print(diff)

Fixed, accepted submission:
import math as ma
N = int(input())
a = list(map(int, input().split()))
s = sum(a)
A = 0
diff = 9999999999
for i in range(N-1):
    A += a[i]
    if diff > (ma.fabs(2*A - s)):
        diff = ma.fabs(2*A -s)
print(int(diff))
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())
min = A * X + B * Y

for x in range(X+1):
  for y in range(Y+1):
    if x <= y:
      z = 2 * (X - x)
    else:
      z = 2 * (Y - y)
    Sum = A * x + B * y + C * z
    if Sum < min:
      min = Sum

print(Sum)

Fixed, accepted submission:
A, B, C, X, Y = map(int, input().split())
Sum = A * X + B * Y

if A+B > 2*C:
  if X < Y:
    if 2*C <= B:
      Sum = C * 2 * Y
    else:
      Sum = C * 2 * X + B * (Y - X)
  elif Y < X:
    if 2*C <= A:
      Sum = C * 2 * X
    else:
      Sum = C * 2 * Y + A * (X - Y)
  else:
    Sum = C * 2 * X

print(Sum)
Problem:
Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them.  He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2).  Find the minimum total cost to achieve his objective.

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

sql=[x*2 for x in integers]
s=sum(integers)
t=sum(sql)
m=min(s%n, n-s%n)

print((m**2-s**2)//n+t)

Fixed, accepted submission:
n=int(input())
integers=list(map(int,input().split()))
 
sql=[x**2 for x in integers]
s=sum(integers)
t=sum(sql)
m=min(s%n, n-s%n)
 
print((m**2-s**2)//n+t)
Problem:
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions:    * The graph is simple and connected.   * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S.  It can be proved that at least one such graph exists under the constraints of this problem.

Incorrect submission (verdict: Wrong Answer):
N = int(input())

bridge = []
for i in range(1, N):
    for j in range(i + 1, N + 1):
        if(N % 2 == 0):
            if(i + j == N + 1):
                print("skip = [{}, {}]".format(i,j))
                continue
        else:
            if(i + j == N):
                print("skip = [{}, {}]".format(i,j))
                continue
        bridge.append([i, j])

print(str(len(bridge)))
for i in bridge:
    print(" ".join(map(str, i)))


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

bridge = []
for i in range(1, N):
    for j in range(i + 1, N + 1):
        if(N % 2 == 0):
            if(i + j == N + 1):
#                print("skip = [{}, {}]".format(i,j))
                continue
        else:
            if(i + j == N):
#                print("skip = [{}, {}]".format(i,j))
                continue
        bridge.append([i, j])

print(str(len(bridge)))
for i in bridge:
    print(" ".join(map(str, i)))
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):
print("YES" if eval(input().replace(" ","+"))%4==0 else "NO")

Fixed, accepted submission:
print("YES" if eval(input().replace(" ",""))%4==0 else "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):

nN = int(input())

sListA = []
nListA = [ 0 for i in range(nN)]

for i in range(nN):
  sTmp = input()
  if sTmp in sListA:
    nTmp = sListA.index(sTmp)
    nListA[nTmp] += 1
  else:
    sListA.append(sTmp)
    nTmp = sListA.index(sTmp)
    nListA[nTmp] += 1

    
nN = int(input())
sListB = []
nListB = [ 0 for i in range(nN)]

for i in range(nN):
  sTmp = input()
  if sTmp in sListA:
    nTmp = sListA.index(sTmp)
    nListB[nTmp] -= 1

nMax =max(nListA)
print(nListA)


Fixed, accepted submission:
nN = int(input())
 
sListA = []
nListA = [ 0 for i in range(202)]
 
for i in range(nN):
  sTmp = input()
  if sTmp in sListA:
    nTmp = sListA.index(sTmp)
    nListA[nTmp] += 1
  else:
    sListA.append(sTmp)
    nTmp = sListA.index(sTmp)
    nListA[nTmp] += 1
 
    
nN = int(input())
sListB = []
nListB = [ 0 for i in range(nN)]
 
for i in range(nN):
  sTmp = input()
  if sTmp in sListA:
    nTmp = sListA.index(sTmp)
    nListA[nTmp] -= 1
  else:
    sListA.append(sTmp)
    nTmp = sListA.index(sTmp)
    nListA[nTmp] -= 1
 
nMax = max(nListA)
# print(sListA)
print(nMax)
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())
while n >= 1000:
    n -= 1000
print(n)

Fixed, accepted submission:
n = int(input())
while n >= 1000:
    n -= 1000
if n != 0:
    n=1000-n
print(n)
Problem:
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.  Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times **before** he does the cut:    * Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).   * Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.  Find the minimum amount of money needed before cutting the bar into two parts with the same length.

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

tmp = [0 for i in range(N+1)]
length = 0
for i in range(N):
  tmp[i+1] = tmp[i] + A[i]
  length += A[i]
  
ans = 0
for i in range(1, N+1):
 ans = min(ans, abs(length - tmp[i]))

print(ans)

Fixed, accepted submission:
N = int(input())
A = list(map(int, input().split()))

tmp = [0 for i in range(N+1)]
length = 0
for i in range(N):
  tmp[i+1] = tmp[i] + A[i]
  length += A[i]
  
ans = 10 ** 10
for i in range(1, N+1):
 ans = min(ans, abs((length - tmp[i]) - tmp[i]))

print(ans)
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())
combis = [set(list(map(int, input().split()))) for i in range(m)]
count = 0
for i in range(m):
    combis_x = combis[0:i] + combis[i+1:m]
    islands = []
    for combi in combis_x:
        # init
        if not islands:
            islands.append(combi)
            continue
        # compare existed islands
        new_islands = islands
        joint_i = []
        for j, island in enumerate(islands):
            if not island.isdisjoint(combi):
                new_islands[j] = island | combi
                joint_i.append(j)
        else:
            if not joint_i:
                new_islands.append(combi)
            elif len(joint_i) == 2:
                new_islands[joint_i[0]] = new_islands[joint_i[0]] | new_islands[joint_i[1]]
                new_islands.pop(joint_i[1])
        islands = new_islands

    # judge
    if len(islands) == 1 and len(islands[0]) == n:
        continue
    elif len(islands) == 1 and len(islands[0]) == n - 1:
        count += 1
    else:# len(islands) == 2 and islands[0].isdisjoint(islands[1]):
        count += 1
print("count", count)



Fixed, accepted submission:
n , m = map(int, input().split())
combis = [set(list(map(int, input().split()))) for i in range(m)]
count = 0
for i in range(m):
    combis_x = combis[0:i] + combis[i+1:m]
    islands = []
    for combi in combis_x:
        # init
        if not islands:
            islands.append(combi)
            continue
        # compare existed islands
        new_islands = islands
        joint_i = []
        for j, island in enumerate(islands):
            if not island.isdisjoint(combi):
                new_islands[j] = island | combi
                joint_i.append(j)
        else:
            if not joint_i:
                new_islands.append(combi)
            elif len(joint_i) == 2:
                new_islands[joint_i[0]] = new_islands[joint_i[0]] | new_islands[joint_i[1]]
                new_islands.pop(joint_i[1])
        islands = new_islands

    # judge
    if len(islands) == 1 and len(islands[0]) == n:
        continue
    elif len(islands) == 1 and len(islands[0]) == n - 1:
        count += 1
    else:# len(islands) == 2 and islands[0].isdisjoint(islands[1]):
        count += 1
print(count)
Problem:
There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of the vertices, except the root, has a directed edge coming from its parent. Note that the root may not be Vertex 1.  Takahashi has added M new directed edges to this graph. Each of these M edges, u \rightarrow v, extends from some vertex u to its descendant v.  You are given the directed graph with N vertices and N-1+M edges after Takahashi added edges. More specifically, you are given N-1+M pairs of integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the i-th edge extends from Vertex A_i to Vertex B_i.  Restore the original rooted tree.

Incorrect submission (verdict: Wrong Answer):
from heapq import heappop, heappush
def inpl(): return list(map(int, input().split()))

N, M = inpl()
G = {i:[] for i in range(N)}
X = [0]*(N)
searched = [0]*(N)

for _ in range(N-1+M):
    a, b = inpl()
    G[a-1].append(b-1)
    X[b-1] += 1

if min(X) != 0:
    raise

Fixed, accepted submission:
from collections import deque
def inpl(): return list(map(int, input().split()))

N, M = inpl()
G = {i:[] for i in range(N)}
rG = {i: [] for i in range(N)}
X = [0]*(N)
searched = [0]*(N)

for _ in range(N-1+M):
    a, b = inpl()
    G[a-1].append(b-1)
    rG[b-1].append(a-1)
    X[b-1] += 1

q = X.index(0)
T = [0]*N
Q = deque([q])
t = 0
while Q:
    p = Q.popleft()
    T[p] = t
    t += 1
    for q in G[p]:          
        X[q] -= 1
        if X[q] == 0:
            Q.append(q)

for i in range(N):
    c, ans = -1, 0
    for p in rG[i]:
        if c < T[p]:
            c, ans = T[p], p+1
    print(ans)