TnT/CodeNet4Repair huggingface dataset:
Problem:
You have an integer variable x. Initially, x=0.  Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`.  Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).

Incorrect submission (verdict: Wrong Answer):
N = int(input())
S = list(input())
count = 0

for i in range(N):
    if i == "I":
        count += 1
    if i == "D":
        count -= 1
else:
    print(count)


Fixed, accepted submission:
N = int(input())
S = list(input())
count = 0
max_count = 0
for i in S:
    if i == "I":
        count += 1
    if i == "D":
        count -= 1
    if max_count < count:
        max_count = count
else:
    print(max_count)
Problem:
ケーキ屋さんが、まちまちな大きさのロールケーキをたくさん作りました。あなたは、このケーキを箱に並べる仕事を任されました。  ロールケーキはとてもやわらかいので、他のロールケーキが上に乗るとつぶれてしまいます。ですから、図(a) のように全てのロールケーキは必ず箱の底面に接しているように並べなければなりません。並べ替えると必要な幅も変わります。     ---   図(a)      図(b)      n 個のロールケーキの半径 r1, r2, ..., rn と箱の長さを読み込み、それぞれについて、箱の中にうまく収まるかどうか判定し、並べる順番を工夫すると箱に入る場合は "OK"、どう並べても入らない場合には "NA"を出力するプログラムを作成してください。  ロールケーキの断面は円であり、箱の壁の高さは十分に高いものとします。 ただし、ロールケーキの半径は 3 以上 10 以下の整数とします。つまり、ケーキの半径に極端な差はなく、図(b) のように大きなケーキの間に小さなケーキがはまり込んでしまうことはありません。

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

def calcwidth(cks):
    if len(cks) == 1: return cks[0]*2
    width = cks[0] + cks[-1]
    for ck1,ck2 in zip(cks[:-1],cks[1:]):
        width += ((ck1+ck2)**2-(ck1-ck2)**2)**0.5
    return width

while True:
    try: W, *rs = list(map(float,input().split()))
    except: break
    rs = deque(sorted(rs))
    dp = [float('inf')]*len(rs)
    cs = deque([rs.popleft()])

    last_pick_small = -1
    # if -1: last pick up is smallest, if 0: last pick up is biggest
    while rs:
        if last_pick_small: nxt = rs.pop()
        else: nxt = rs.popleft()
        if abs(nxt-cs[0]) > abs(nxt-cs[-1]): cs.appendleft(nxt)
        else: cs.append(nxt)
        last_pick_small = -1-last_pick_small
    ret = calcwidth(list(cs))
    if ret < W: print('OK')
    else: print('NA')




Fixed, accepted submission:
from collections import deque

def calcwidth(cks):
    if len(cks) == 1: return cks[0]*2
    width = cks[0] + cks[-1]
    for ck1,ck2 in zip(cks[:-1],cks[1:]):
        width += ((ck1+ck2)**2-(ck1-ck2)**2)**0.5
    return width

while True:
    try: W, *rs = list(map(float,input().split()))
    except: break
    rs = deque(sorted(rs))
    dp = [float('inf')]*len(rs)
    cs = deque([rs.popleft()])

    last_pick_small = -1
    # if -1: last pick up is smallest, if 0: last pick up is biggest
    while rs:
        if last_pick_small: nxt = rs.pop()
        else: nxt = rs.popleft()
        if abs(nxt-cs[0]) > abs(nxt-cs[-1]): cs.appendleft(nxt)
        else: cs.append(nxt)
        last_pick_small = -1-last_pick_small
    ret = calcwidth(list(cs))
    if ret <= W: print('OK')
    else: print('NA')
Problem:
Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.    * Operation 1: Pour 100A grams of water into the beaker.   * Operation 2: Pour 100B grams of water into the beaker.   * Operation 3: Put C grams of sugar into the beaker.   * Operation 4: Put D grams of sugar into the beaker.  In our experimental environment, E grams of sugar can dissolve into 100 grams of water.  Snuke will make sugar water with the highest possible density.  The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted.  We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.

Incorrect submission (verdict: Wrong Answer):
a,b,c,d,e,f = map(int,input().split())
L = []
for p in range(31):
    for q in range(31):
        h = 100*(a*p+b*q)
        for r in range((f-h)//(c)):
            for s in range((f-h)//(d)):
                g = c*r+d*s
                if g+h !=0:
                    bool1 = (g/(g+h) <= 100*e/(100+e))
                    if bool1 and g+h <= f:
                        if h !=0:
                            L.append((100*g/(g+h),g+h,g))
L.sort(reverse = True)  
#print(L)
print(L[0][1],L[0][2])

Fixed, accepted submission:
a,b,c,d,e,f = map(int,input().split())
L = []
for p in range(f//a+1):
    for q in range((f-a*p)//b+1):
        h = 100*(a*p+b*q)
        for r in range((f-h)//c+1):
            for s in range((f-h-c*r)//d+1):
                g = c*r+d*s
                if g+h !=0:
                    bool1 = (g/(g+h) <= e/(100+e))
                    if bool1 and g+h <= f:
                        if h !=0:
                            L.append((100*g/(g+h),g+h,g))
L.sort(reverse = True)  
#print(L)
print(L[0][1],L[0][2])
Problem:
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives.  You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative.  For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins.  If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?

Incorrect submission (verdict: Wrong Answer):
#ABC119 B
N = int(input())
ans = 0
for i in range(N):
    x, v = input().split()
    x = float(x)
    if v == "BTC":
        x *= 38000.0
    ans += x 
print(ans)        

Fixed, accepted submission:
#ABC119 B
N = int(input())
ans = 0
for i in range(N):
    x, v = input().split()
    x = float(x)
    if v == "BTC":
        x *= 380000
    ans += x 
print(ans)
Problem:
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.

Incorrect submission (verdict: Wrong Answer):
S=input();print("YES" if len(S)==len(set(S)) else "NO")

Fixed, accepted submission:
S=input();print(["no","yes"][len(S)==len(set(S))])
Problem:
There are N positive integers written on a blackboard: A_1, ..., A_N.  Snuke can perform the following operation when all integers on the blackboard are even:    * Replace each integer X on the blackboard by X divided by 2.  Find the maximum possible number of operations that Snuke can perform.

Incorrect submission (verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
s=0
cnt=0
while True:
    tmp=a.copy()
    for j in range(n):
        s+=tmp.pop()
    if s%n==0:
        a=[int(int(j)/2) for j in a]
        cnt+=1
        tmp=a.copy()
        s=0
    else : break
print(cnt)

Fixed, accepted submission:
n=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(len(a)):
    cnt=0
    m=a[i]
    while m%2==0:
        cnt+=1
        m//=2
    ans.append(cnt)
print(min(ans))
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 = input()
print("2017" + s[:4])

Fixed, accepted submission:
s = input()
print("2018" + s[4:])
Problem:
For an integer n not less than 0, let us define f(n) as follows:    * f(n) = 1 (if n < 2)   * f(n) = n f(n-2) (if n \geq 2)  Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).

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

result = 0

if num  % 2 != 0:
    result = 0
else:
    num = num / 2
    while(num > 0):
        result += num // 5
        num = num // 5

print(result)


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

result = 0

if num  % 2 != 0:
    result = 0
else:
    num = num // 2
    while(num > 0):
        result += num // 5
        num = num // 5

print(result)
Problem:
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**.  You are given a 4-digit integer N. Answer the question: Is N **good**?

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

if N[0] == N[1] and N[1] == N[2] and N[2] == N[3]:
    print('Yes')
else:
    print('No')

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

if N[0] == N[1] == N[2]:
    print('Yes')
elif N[1] == N[2] == N[3]:
    print('Yes')
else:
    print('No')
Problem:
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs.  Determine if it is possible that there are exactly X cats among these A + B animals.

Incorrect submission (verdict: Wrong Answer):
import sys
import os

OK = 'APPROVED'
NG = 'DENIED'


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, X = list(map(int, sys.stdin.buffer.readline().split()))

    print('YES' if X - A >= B else 'NO')


if __name__ == '__main__':
    main()


Fixed, accepted submission:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, X = il()
    print('YES' if A > X - B and X >= A else 'NO')


if __name__ == '__main__':
    main()
Problem:
A binary heap which satisfies max-heap property is called max-heap. In a max- heap, for every node $i$ other than the root, $A    Write a program which reads an array and constructs a max-heap from the array based on the following pseudo code.  $maxHeapify(A, i)$ move the value of $A[i]$ down to leaves to make a sub-tree of node $i$ a max-heap. Here, $H$ is the size of the heap.                 1  maxHeapify(A, i) 2      l = left(i) 3      r = right(i) 4      // select the node which has the maximum value 5      if l ≤ H and A[l] > A[i] 6          largest = l 7      else  8          largest = i 9      if r ≤ H and A[r] > A[largest] 10         largest = r 11 12     if largest ≠ i　// value of children is larger than that of i 13         swap A[i] and A[largest] 14         maxHeapify(A, largest) // call recursively   The following procedure buildMaxHeap(A) makes $A$ a max-heap by performing maxHeapify in a bottom-up manner.                 1 buildMaxHeap(A) 2    for i = H/2 downto 1 3        maxHeapify(A, i)

Incorrect submission (verdict: Wrong Answer):


def  maxHeapify(i):
    l =2*i
    r = 2*i+1
    print(A[i])
    largest =0
    if l <=H and A[l]> A[i]:
        largest = l
    else:
        largest = i

    if r <= H and A[r] > A[largest]:
        largest = r

    if largest != i :
        A[i],A[largest] = A[largest],A[i]
        maxHeapify(largest)
    print(A)



H = int(input())

A = list(map(int,input().split()))

A = [-1]+A

for i in range(int(H/2),0,-1):
    maxHeapify(i)

Astr = list(map(str,A))

print(" ".join(Astr[1:]))

Fixed, accepted submission:


def  maxHeapify(i):
    l =2*i
    r = 2*i+1
    # print(A[i])
    largest =0
    if l <=H and A[l]> A[i]:
        largest = l
    else:
        largest = i

    if r <= H and A[r] > A[largest]:
        largest = r

    if largest != i :
        A[i],A[largest] = A[largest],A[i]
        maxHeapify(largest)
    # print(A)



H = int(input())

A = list(map(int,input().split()))

A = [-1]+A

for i in range(int(H/2),0,-1):
    maxHeapify(i)

Astr = list(map(str,A))

print(" ",end="")

print(" ".join(Astr[1:]))
Problem:
Snuke is giving cookies to his three goats.  He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins).  Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.

Incorrect submission (verdict: Wrong Answer):
a,b=map(int,input().split())
if a+b%3==0:
  print("Possible")
else:
  print("Impossible")

Fixed, accepted submission:
a,b=map(int,input().split())
if a%3==0 or b%3==0 or (a+b)%3==0:
  print("Possible")
else:
  print("Impossible")
Problem:
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.

Incorrect submission (verdict: Wrong Answer):
import string

text = input()
character_count_map = {}

for c in text:
    if c not in character_count_map:
        character_count_map[c] = 0
    character_count_map[c] += 1

for c in string.ascii_lowercase:
    if c in character_count_map:
        print(c, ":", character_count_map[c])
    else:
        print(c, ":", 0)

Fixed, accepted submission:
import sys
import string

text = ""
for line in sys.stdin:
    text += line

character_count_map = {}

for c in text.lower():
    if c not in character_count_map:
        character_count_map[c] = 0
    character_count_map[c] += 1

for c in string.ascii_lowercase:
    if c in character_count_map:
        print(c, ":", character_count_map[c])
    else:
        print(c, ":", 0)
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):
def ok(target, S):
    pos = 0
    for t in target:
        if t in S[pos:]:
            pos = S[pos:].index(t)
        else:
            return False
    return True


N = int(input())
S = input()
ans = 0

for i in range(0, 999+1):
    target = str(i).zfill(3)
    ans += ok(target, S)

print(ans)


Fixed, accepted submission:
N = int(input())
S = input()
ans = 0
for s in range(0, 1000):
    s = str(s).zfill(3)
    i = 0
    for d in s:
        if d in S[i:]:
            i += S[i:].index(d) + 1
        else:
            break
    else:
        ans += 1
print(ans)
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())
print(n%1000)

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

oturi=10000-n

print(oturi%1000)
Problem:
Takahashi is a user of a site that hosts programming contests.   When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows:    * Let the current rating of the user be a.   * Suppose that the performance of the user in the contest is b.   * Then, the new rating of the user will be the avarage of a and b.  For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000.  Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest.   Find the performance required to achieve it.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
k = int(input())
a = 1
for i in range(n):
    if 2*a>=a+k:
        a = a+k
    else:
        a = 2*a
print(a)

Fixed, accepted submission:
r = int(input())
g = int(input())
goal = 2*g - r
print(goal)
Problem:
There are N positive integers written on a blackboard: A_1, ..., A_N.  Snuke can perform the following operation when all integers on the blackboard are even:    * Replace each integer X on the blackboard by X divided by 2.  Find the maximum possible number of operations that Snuke can perform.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
ans = 0 
for a in A:
    i = 0
    while a % 2 == 0:
        a = a // 2
        i += 1
    ans = min(ans,i)
print(ans)

Fixed, accepted submission:
ans=10**9
n=int(input())
s=list(map(int,input().split()))
for i in s:
    p=0
    while i%2==0:
        i//=2
        p+=1
    if p<ans:
        ans=p
print(ans)
Problem:
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.

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

for i in range(N):
    sides = list(map(int, input().split()))
    if max(sides) == min(sides):
        print('YES')
    else:
        print('NO')



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

for i in range(N):
    adjacent_side_1, adjacent_side_2, hypotenuse = sorted(list(map(int, input().split())))
    if adjacent_side_1**2 + adjacent_side_2**2 == hypotenuse**2:
        print('YES')
    else:
        print('NO')
Problem:
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?

Incorrect submission (verdict: Wrong Answer):
n,m=map(int,input().split())
a=[input() for i in range(m)]
print(a)

Fixed, accepted submission:
n,m=map(int,input().split())
items=[input().split() for i in range(m)]
for i in range(1,n+1):
  cnt=0
  for j in range(m):
    cnt+=items[j].count(str(i))
  print(cnt)
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())
print(N % 1000)


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

print(1000 - (N % 1000) if (N % 1000) != 0 else 0)
Problem:
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode:                 BubbleSort(A) 1 for i = 0 to A.length-1 2     for j = A.length-1 downto i+1 3         if A[j] < A[j-1] 4             swap A[j] and A[j-1]   Note that, indices for array elements are based on 0-origin.  Your program should also print the number of swap operations defined in line 4 of the pseudocode.

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

def bubblesort(A, N):
    flag = True
    i = 0
    cnt = 0
    while flag:
        flag = False
        for j in range(N-1, i, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = True
                cnt += 1
        i += 1     
    return cnt

print(*A)
print(bubblesort(A,N))

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

def bubblesort(A, N):
    flag = True
    i = 0
    cnt = 0
    while flag:
        flag = False
        for j in range(N-1, i, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = True
                cnt += 1
        i += 1     
    print(*A)
    print(cnt)

bubblesort(A,N)
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())
x = A - B
v = abs(V - W)
if v <= 0:
        print('NO')
else:
    for t in range(1,T+1):
        x -= v
        if x == 0:
            print('YES')
            break
    else:
        print('NO')

Fixed, accepted submission:
A,V = map(int, input().split())
B,W = map(int, input().split())
T = int(input())
x = abs(A - B)
v = V - W
if v <= 0:
        print('NO')
else:
    if T < x // v:        
        print('NO')
    elif T == x // v and x % v > 0:
        print('NO')
    else:
        print('YES')
Problem:
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total?  Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.

Incorrect submission (verdict: Wrong Answer):
a,b,c,x=map(int,open(0).read().split())
cnt=0
#O(n**3)=O(50**3)=O(125000)
for i in range(a):
  for j in range(b):
    for k in range(c):
      if 500*i+100*j+50*k==x:
        cnt+=1
print(cnt)

Fixed, accepted submission:
a,b,c,x=map(int,open(0).read().split())
cnt=0
#O(n**3)=O(50**3)=O(125000)
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i+100*j+50*k==x:
        cnt+=1
print(cnt)
Problem:
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode:                 BubbleSort(A) 1 for i = 0 to A.length-1 2     for j = A.length-1 downto i+1 3         if A[j] < A[j-1] 4             swap A[j] and A[j-1]   Note that, indices for array elements are based on 0-origin.  Your program should also print the number of swap operations defined in line 4 of the pseudocode.

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

flag = True
judge = True

while flag:
    for i in range(n-1,0,-1):
        if a[i] < a[i - 1]:
            a[i],a[i - 1] = a[i - 1], a[i] #swap
    print(' '.join(map(str,a)))
    if sorted(a) == a: flag = False




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

flag = True
judge = True
count=0

while flag:
    for i in range(n-1,0,-1):
        if a[i] < a[i - 1]:
            a[i],a[i - 1] = a[i - 1], a[i] #swap
            count+=1
    if sorted(a) == a: flag = False

print(' '.join(map(str,a)))
print(count)
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())
all_num =[]
all_num.append(a)
all_num.append(b)
all_num.append(c)
if all_num.count(5)==2 and all_num.count(7)==1:
    print("Yes")
else:
    print("No")


Fixed, accepted submission:
#042 A
S = [int(j) for j in input().split()]
if S.count(5)==2 and S.count(7)==1:
    print('YES')
else:
    print('NO')