TnT/CodeNet4Repair huggingface dataset:
Problem:
Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.

Incorrect submission (verdict: Wrong Answer):
D=int(input())
c = list(map(int,input().split()))
s=[[0 for e in range(26)] for f in range(D)]
for i in range(D):
 s[i]=list(map(int,input().split()))
last=[0]*26
ans=0
point=[0]*D
for i in range(D):
 saidai=-(10**10)
 kouho=0
 for j in range(26):
  if s[i][j]+c[j]*((i+1)-last[j])>=saidai:
   kouho=j+1
   saidai=s[i][j]+c[j]*((i+1)-last[j])
 print(kouho)


Fixed, accepted submission:
D=int(input())
c = list(map(int,input().split()))
s=[[0 for e in range(26)] for f in range(D)]
for i in range(D):
 s[i]=list(map(int,input().split()))
last=[0]*26
ans=0
point=[0]*D
for i in range(D):
 t=int(input())
 ans+=s[i][t-1]
 last[t-1]=i+1
 for j in range(26):
  ans+=c[j]*(last[j]-(i+1))
  point[i]=ans
for i in range(D):
 print(point[i])
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())
if A+B <= C*2:
  print(A*X + B*Y)
else:
  if X>=Y:
    print(Y*C + (X-Y)*A)
  else:
    print(X*C + (Y-X)*B)


Fixed, accepted submission:
A, B, C, X, Y = map(int,input().split())
ans = float('inf')
for i in range(0, max(X,Y)+1):
  num = i*2*C + max(0, X-i)*A + max(0, Y-i)*B
  ans = min(ans, num)
print(ans)
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):
n = int(input())
A = [int(a) for a in input().split()]

max_val = max(A)
mid_val = max_val - max_val//2



m = 0
for a in A:
    if abs(a - mid_val) > abs(m - mid_val):
        m = a
    # print("m: {}".format(m))

print("{} {}".format(max_val, m))


Fixed, accepted submission:
n = int(input())
A = [int(a) for a in input().split()]

max_val = max(A)
mid_val = max_val - max_val//2



m = 0
for a in A:
    # print(abs(a - mid_val))
    # print(abs(m - mid_val))
    if abs(a - mid_val) < abs(m - mid_val):
        m = a
    # print("m: {}".format(m))

print("{} {}".format(max_val, m))
Problem:
There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors.  Find the number of the possible ways to paint the balls.

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

ans = K
for i in range(N-1):
    ans += (K-1)

print(ans)

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

ans = K
for i in range(N-1):
    ans *= (K-1)

print(ans)
Problem:
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right.  Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N.  Find the minimum cost incurred before reaching the goal.

Incorrect submission (verdict: Wrong Answer):
a = [input().split() for l in range(2)]
print(a)

N = int(a[0][0]) 
M = int(a[0][1]) 
X = int(a[0][2]) 

goal_len01 = N - X # end place
goal_len02 = X # start place

cost1 = 0
for i in range(goal_len01):
  if str(X+i+1) in a[1]:
    cost1 += 1

cost2 = 0
for i in range(goal_len02):
  if str(i+1) in a[1]:
    cost2 += 1

min_cost = 0
if cost1 >= cost2:
  min_cost = cost2
else:
  min_cost = cost1
  
print(min_cost)

Fixed, accepted submission:
a = [input().split() for l in range(2)]

N = int(a[0][0]) 
M = int(a[0][1]) 
X = int(a[0][2]) 

goal_len01 = N - X # end place
goal_len02 = X # start place

cost1 = 0
for i in range(goal_len01):
  if str(X+i+1) in a[1]:
    cost1 += 1

cost2 = 0
for i in range(goal_len02):
  if str(i+1) in a[1]:
    cost2 += 1

min_cost = 0
if cost1 >= cost2:
  min_cost = cost2
else:
  min_cost = cost1
  
print(min_cost)
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+B+C==17:
    print('Yes')
else:
    print('No')

Fixed, accepted submission:
A,B,C=map(int,input().split())

if A+B+C==17:
    print('YES')
else:
    print('NO')
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,B,C = map(int,input().split())
K = int(input())

while B<A:
    B *= 2
    K -= 1
while C<A:
    C *= 2
    K -= 1
if K>0:
    print("Yes")
else :
    print("No")
    


Fixed, accepted submission:
A,B,C = map(int,input().split())
K = int(input())
if B<=A:
    while B<=A:
        B *= 2
        K -= 1
if C<=B:
    while C<=B:
        C *= 2
        K -= 1
if K>=0:
    print("Yes")
else :
    print("No")
Problem:
There are N villages. Each village is numbered from 1 to N. The recent merger boom has resulted in several villages being merged. Two or more villages merged become one new city, and villages not merged with any village remain villages. You are given multiple pieces of information that two villages will become the same city after merging. Depending on the combination of information, three or more villages could become one city. Given information about villages that will become the same city after merging, output the absolute value of the difference between the number of cities and villages after merging.

Incorrect submission (verdict: Wrong Answer):
[m,n] = map(int,input().split())

def find(v,cs):
    for c in cities:
        if v in c:
            return (True,c)
    return (False,set([v]))

cities = []
for _ in range(n):
    [a,b] = map(int,input().split())

    (ra,fa) = find(a,cities)
    (rb,fb) = find(b,cities)

    mg = fa | fb

    print(fa)

    if ra:
        cities.remove(fa)
    else:
        m = m - 1
    if rb:
        if fa != fb:
            cities.remove(fb)
    else:
        m = m - 1
    cities.append(mg)

print(abs(m-len(cities)))



Fixed, accepted submission:
[m,n] = map(int,input().split())

def find(v,cs):
    for c in cities:
        if v in c:
            return (True,c)
    return (False,set([v]))

cities = []
for _ in range(n):
    [a,b] = map(int,input().split())

    (ra,fa) = find(a,cities)
    (rb,fb) = find(b,cities)

    mg = fa | fb

    if ra:
        cities.remove(fa)
    else:
        m = m - 1
    if rb:
        if fa != fb:
            cities.remove(fb)
    else:
        m = m - 1
    cities.append(mg)

print(abs(m-len(cities)))
Problem:
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements?  Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds:    * r_1 + c_1 = r_2 + c_2   * r_1 - c_1 = r_2 - c_2  For example, in the following figure, the bishop can move to any of the red squares in one move:  

Incorrect submission (verdict: Wrong Answer):
H,W=map(int,input().split())
S=H*W
if S%2==0:
    print(S/2)
else:
    print(S//2+1) 

Fixed, accepted submission:
H,W=map(int,input().split())
S=H*W

while True:
    if H==1 or W==1:
        print(1)
        break

    if S%2==0:
        print(int(S/2))
        break
    elif S%2==1:
        print(int(S//2+1))
        break
Problem:
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament.  The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day.  Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.

Incorrect submission (verdict: Wrong Answer):
S = input()
x = 15 - len(S)
y = 8 - S.count("o")
ans = "Yes" if x - y >= 0 else "No"
print(ans)

Fixed, accepted submission:
S = input()
k = len(S)
x = 15 - k
y = 8 - S.count("o")
ans = "YES" if x - y >= 0 else "NO"
print(ans)
Problem:
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.  The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y.  One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control.  If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.    * X < Z \leq Y   * x_1, x_2, ..., x_N < Z   * y_1, y_2, ..., y_M \geq Z  Determine if war will break out.

Incorrect submission (verdict: Wrong Answer):
n,m,x,y=map(int,input().split())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
cnt=0
if max(X)>=min(Y):
  print('War')
else:
  for i in range(max(X)+1,min(Y)+1):
    if x<i and i<=y:
      print('No war')
      cnt+=1
      exit()
  if cnt==0:
    print('War')

Fixed, accepted submission:
n,m,x,y=map(int,input().split())
xl=list(map(int,input().split()))
yl=list(map(int,input().split()))
a=max(x,max(xl))
b=min(y,min(yl))
if b-a<=0:
  print('War')
else:
  print('No War')
Problem:
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
a = input()
dic="abcdefghijklmnopqrstuvwxyz"
maxcount = 0
for i in range(n):
  for j in range(26):
    count = 0
    if str(dic[j]) in a[:i] and str(dic[j]) in a[i:]:
      count+=1
  maxcount = max(count,maxcount)
print(maxcount)

Fixed, accepted submission:
n = int(input())
a = input()
dic="abcdefghijklmnopqrstuvwxyz"
maxcount = 0
for i in range(n):
  count = 0
  for j in range(26):
    if str(dic[j]) in a[:i] and str(dic[j]) in a[i:]:
      count+=1
  maxcount = max(count,maxcount)
print(maxcount)
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, input().split())

if b - a == c - b:
    print("Yes")
else:
    print("No")


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

if b - a == c - b:
    print("YES")
else:
    print("NO")
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())
mini = A + B - N
maxi = min(A,B)
print(maxi,mini)

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

mini = A + B - N
if mini < 0:
    mini = 0
maxi = min(A,B)
print(maxi,mini)
Problem:
You are given two integers A and B. Find the largest value among A+B, A-B and A \times B.

Incorrect submission (verdict: Wrong Answer):
a,b = map(int, input().split())
print(min(a+b, a-b, a*b))


Fixed, accepted submission:
a,b = map(int, input().split())
print(max(a+b, a-b, a*b))
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):
print(-int(input())%1e3)

Fixed, accepted submission:
print(-int(input())%1000)
Problem:
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:    * Choose two among A, B and C, then increase both by 1.   * Choose one among A, B and C, then increase it by 2.  It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.

Incorrect submission (verdict: Wrong Answer):
nums = list(map(int, input().split()))
nums.sort()
count = nums[2] - nums[1]
nums[0] += nums[2] - nums[1]
if (nums[2]-nums[0])%2 == 0:
  count += (nums[2]-nums[0])//2
else:
  count += (nums[2]-nums[0])//2 + 2

Fixed, accepted submission:
nums = list(map(int, input().split()))
nums.sort()
count = nums[2] - nums[1]
nums[0] += nums[2] - nums[1]
if (nums[2]-nums[0])%2 == 0:
  count += (nums[2]-nums[0])//2
else:
  count += (nums[2]-nums[0])//2 + 2
print(count)
Problem:
AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code.  The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.  How many different PIN codes can he set this way?  Both the lucky number and the PIN code may begin with a 0.

Incorrect submission (verdict: Wrong Answer):
n=int(input())
s=input()
cnt=0
for i in range(1000):
  l=(3-len(str(i)))*'0'+str(i)
  if l[0] in s and l[1] in s and l[2] in s and s.index(l[0])<s.index(l[1])<s.index(l[2]):
    cnt+=1
print(cnt)

Fixed, accepted submission:
n=int(input())
s=input()
ans=0
d=dict()
for i in range(1000):
  num='0'*(3-len(str(i)))+str(i)
  if num[0] in s:
    j=s.index(num[0])
    if num[1] in s[j+1:]:
      k=s[j+1:].index(num[1])
      if num[2] in s[j+2+k:]:
        ans+=1
print(ans)
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):


a,b=list(map(int,input().split(" ")))
p=a*b

if p%2==0: 
    print("Odd")
else: 
    print("Even")

Fixed, accepted submission:


a,b=list(map(int,input().split(" ")))
p=a*b

if p%2==0: 
    print("Even")
else: 
    print("Odd")
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):
n = int(input())

num = 100
i = 0
while num <=n:
    num = num*101//100
    i +=1
print(i)

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

num = 100
i = 0
while num <=n:
    num = num*101//100
    i +=1
    if num >= n:
        print(i)
        exit()
Problem:
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Incorrect submission (verdict: Wrong Answer):
n,a,b=map(int,input().split())
sum=0
for i in range(n):
     x10 = i // 10
     x1 = i - x10
     if 2 <= x10 + x1 and x10 + x1 <=5:
         sum +=x10+x1
print(sum)

Fixed, accepted submission:
n,a,b=map(int,input().split())
sum=0
for i in range(n+1):
     wa = int((i / 10000) % 10)+int((i / 1000) % 10) + int((i / 100) % 10) + int((i / 10) % 10)  + int(i % 10)
     if a <= wa and wa<=b:
         sum += i
print(sum)
Problem:
You are given an integer sequence of length N, a_1,a_2,...,a_N.  For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing.  After these operations, you select an integer X and count the number of i such that a_i=X.  Maximize this count by making optimal choices.

Incorrect submission (verdict: Wrong Answer):
n  = int(input())
ls = list(map(int, input().split()))
ls_plus1  = list(map(lambda x: x + 1, ls))
ls_minus1 = list(map(lambda x: x - 1, ls))
dic = {}
for a in ls_minus1 + ls + ls_plus1:
    dic[a] = dic.get(a, 1) + 1
print(sorted(dic.values())[-1])

Fixed, accepted submission:
n  = int(input())
ls = list(map(int, input().split()))
ls_plus1  = list(map(lambda x: x + 1, ls))
ls_minus1 = list(map(lambda x: x - 1, ls))
dic = {}
for a in ls_minus1 + ls + ls_plus1:
    dic[a] = dic.get(a, 0) + 1
print(max(dic.values()))
Problem:
Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition:    * For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.

Incorrect submission (verdict: Wrong Answer):
n=int(input())
listx=list(map(int,input().split()))
listx.sort()
count=0
x=1
if listx[0]==0:
  for i in range(1,n):
    if i==n-1:
      x*=count+1
    elif listx[i]==listx[i+1]:
      x*=count+2
      count=0
    else:
      count+=1
else:
  x=0
print(x)

Fixed, accepted submission:
#B
import sys
from collections import Counter
n=int(input())
d=list(map(int,input().split()))
e=Counter(d)
mod=998244353
if d[0]!=0 or e[0]!=1:
    print(0)
    sys.exit()
ans=1
for i in range(2,n):
    ans*=pow(e[i-1],e[i],mod)
    ans%=mod
print(ans%mod)
Problem:
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.

Incorrect submission (verdict: Wrong Answer):
from collections import Counter

X = int(input())

l = [0]
i = 0
while i**5 - (i-1)**5 <= X:
    i+=1
    l.append(i**5)

print(l)

for i in l:
    if Counter(l)[X - i]==1:
        print(l.index((X-i)), -l.index(i))
        quit()
    if Counter(l)[X + i]==1:
        print(l.index(X+i), l.index(i))

Fixed, accepted submission:
from collections import Counter

X = int(input())

l = [0]
i = 0
while i**5 - (i-1)**5 <= X:
    i+=1
    l.append(i**5)

for i in l:
    if Counter(l)[X - i]==1:
        print(l.index((X-i)), -l.index(i))
        quit()
    if Counter(l)[X + i]==1:
        print(l.index(X+i), l.index(i))
Problem:
You have written N problems to hold programming contests. The i-th problem will have a score of P_i points if used in a contest.  With these problems, you would like to hold as many contests as possible under the following condition:    * A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points.  The same problem should not be used in multiple contests. At most how many contests can be held?

Incorrect submission (verdict: Wrong Answer):
def resolve():
    n = int(input())
    a, b = map(int, input().split())
    p = list(map(int, input().split()))
    low, mid, high = 0, 0, 0
    for pi in p:
        if pi <= a:
            low += 1
        elif a + 1 <= pi <= a:
            mid += 1
        else:
            high += 1
    print(min(low, mid, high))


if __name__ == "__main__":
    resolve()


Fixed, accepted submission:
def resolve():
    n = int(input())
    a, b = map(int, input().split())
    p = list(map(int, input().split()))
    low, mid, high = 0, 0, 0
    for pi in p:
        if pi <= a:
            low += 1
        elif a + 1 <= pi <= b:
            mid += 1
        else:
            high += 1
    print(min(low, mid, high))


if __name__ == "__main__":
    resolve()
Problem:
n 分間にわたり， トンネルの入口と出口で， 1分間に通過する車の数を数えたデータがある． そのデータは， 全部で n+2 行からなり， 各行には次の内容が書かれている．    * 第1行目には，正整数 n が書かれており， 調査時間が n 分間であったことを表している．   * 第2行目には，正整数 m が書かれており， 調査開始時におけるトンネル内の車の台数が m であったことを表している．   * 第(2+i)行目（ i = 1, 2, ... , n ) には， 調査開始後 (i-1) 分経過した時点から i 分経過するまでの1分間に， 入口を通過した車の台数と出口を通過した車の台数が １つの空白で区切られて書かれている．  調査開始後 j 分経過した時点 ( j=0, 1, 2, ... , n ) におけるトンネル内の車の台数を Sj とする． Sj の最大値を出力しなさい． また， トンネル内の車の台数が負になることは考えられないので， Sj が一度でも負になった場合は， 「エラー」の意味で 0 を出力しなさい． ただし， n は 10000 以下で， トンネルの入口および出口を1分間に通過する車の台数は 100 以下である．  出力ファイルにおいては， 出力の最後の行にも改行コードを入れること．

Incorrect submission (verdict: Wrong Answer):
n=int(input())
ans=c=m=int(input())
for i in[0]*n:
    a,b=map(int,input().split())
    if c<0:ans=0;break
    c+=a-b
    ans=max(ans,c)

Fixed, accepted submission:
n=int(input())
ans=c=m=int(input())
for i in[0]*n:
    a,b=map(int,input().split())
    if c<0:ans=0;break
    c+=a-b
    ans=max(ans,c)
print(ans)