TnT/CodeNet4Repair huggingface dataset:
Problem:
AtCoDeer is thinking of painting an infinite two-dimensional grid in a _checked pattern of side K_. Here, a checked pattern of side K is a pattern where each square is painted black or white so that each connected component of each color is a K × K square. Below is an example of a checked pattern of side 3:    AtCoDeer has N desires. The i-th desire is represented by x_i, y_i and c_i. If c_i is `B`, it means that he wants to paint the square (x_i,y_i) black; if c_i is `W`, he wants to paint the square (x_i,y_i) white. At most how many desires can he satisfy at the same time?

Incorrect submission (verdict: Wrong Answer):
import numpy as np
N, K = map(int, input().split())
mod = 2*K
field = [[0]*(2*K+1) for _ in range(2*K+1)]

def gen_pattern(x):
    if x < K-1:
        return [[0, x+1], [x+K+1, 2*K]]
    else:
        return [[x-K+1, x+1]]

for _ in range(N):
    x, y, c = input().split()
    x, y = int(x), int(y)
    if c == 'W':
        y += K
    x %= mod
    y %= mod
    for tmp in [0, K]:
        for l, r in gen_pattern((x+tmp) % mod):
            for b, t in gen_pattern((y+tmp) % mod):
                print(l,r,b,t,x,y,tmp)
                field[l][b] += 1
                field[l][t] -= 1
                field[r][b] -= 1
                field[r][t] += 1
print(np.max(np.cumsum(np.cumsum(field, axis=0), axis=1)))


Fixed, accepted submission:
import numpy as np
N, K = map(int, input().split())
mod = 2*K
field = [[0]*(2*K+1) for _ in range(2*K+1)]

def gen_pattern(x):
    if x < K-1:
        return [[0, x+1], [x+K+1, 2*K]]
    else:
        return [[x-K+1, x+1]]

for _ in range(N):
    x, y, c = input().split()
    x, y = int(x), int(y)
    if c == 'W':
        y += K
    x %= mod
    y %= mod
    for tmp in [0, K]:
        for l, r in gen_pattern((x+tmp) % mod):
            for b, t in gen_pattern((y+tmp) % mod):
                field[l][b] += 1
                field[l][t] -= 1
                field[r][b] -= 1
                field[r][t] += 1
print(np.max(np.cumsum(np.cumsum(field, axis=0), axis=1)))
Problem:
We have N cards. A number a_i is written on the i-th card.   Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.   The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.

Incorrect submission (verdict: Wrong Answer):
from sys import stdin

n = stdin.readline().rstrip()
A = [int(x) for x in stdin.readline().rstrip().split()]

A.sort(reverse=True)

print (A)

N=M=0

for i in range(0,len(A),2):
    N = N + A[i]

for i in range(1, len(A), 2):
    M = M + A[i]

print (N-M)







Fixed, accepted submission:
from sys import stdin

n = stdin.readline().rstrip()
A = [int(x) for x in stdin.readline().rstrip().split()]

A.sort(reverse=True)

N=M=0

for i in range(0,len(A),2):
    N = N + A[i]

for i in range(1, len(A), 2):
    M = M + A[i]

print (N-M)
Problem:
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:    * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times.   * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.  The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?

Incorrect submission (verdict: Wrong Answer):
from sys import stdin
N,H = [int(x) for x in stdin.readline().rstrip().split()]
swing = []
throw = []
for _ in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    swing.append(a)
    throw.append(b)
swing_m = max(swing)
throw_l = [i for i in throw if i >= swing_m]
ans = (H - sum(throw_l))//swing_m
print(ans+len(throw_l))

Fixed, accepted submission:
from sys import stdin
import math
N,H = [int(x) for x in stdin.readline().rstrip().split()]
swing = []
throw = []
for _ in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    swing.append(a)
    throw.append(b)
swing_m = max(swing)
throw_l = [i for i in throw if i >= swing_m]
ans = 0
H_ = H
flag = True
for j in sorted(throw_l)[::-1]:
    H_ -= j
    ans += 1
    if H_ <= 0:
        flag = False
        break
if flag:
    ans = (H - sum(throw_l))/swing_m
    ans = math.ceil(ans)
    print(ans+len(throw_l))
else:
    print(ans)
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):
abc = input().split()
print(abc.count("1"))

Fixed, accepted submission:
s= input()
print(s.count('1'))
Problem:
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these.  According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.

Incorrect submission (verdict: Wrong Answer):
N , Y = list(map(int, input().split()))
Y = Y/1000
Z = Y - N
A = 9*N - Z
if Z < 0 or Z > 9*N:
  X = [-1,-1,-1]
elif 24 <= Z <= 9*N - 32:
  X = [(Z-27)//9+((Z%9)%4-1)%4,(9-2*(Z%9))%9,N-((Z-27)//9+((Z%9)%4-1)%4+(9-2*(Z%9))%9)]
  X = list(map(int, X))
elif 0 <= Z <= 23:
  if Z%4 == 0:
    X = [0,Z/4,N-(Z/4)]
  elif Z%9 == 0:
    X = [Z/9,0,N-(Z/9)]
  elif Z == 13 or Z == 17 or Z == 21:
    X = [1,(Z-9)/4,N-((Z-5)/4)]
  elif Z == 22:
    X = [2,1,N-3]
  else:
    X = [-1,-1,-1]
  X = list(map(int, X))
else:
  if A%5 == 0:
    X = [N-(A/5),A/5,0]
  elif A%9 == 0:
    X = [N-(A/9),0,A/9]
  elif A == 14 or A == 19 or A == 24 or A == 29:
    X = [N-((A-4)/5),(A-9)/5,1]
  elif A == 23 or A == 28:
    X = [N-((A-8)/5),(A-18)/5,2]
  else:
    X = [-1,-1,-1]
  X = list(map(int, X))
print(X)

Fixed, accepted submission:
N , Y = list(map(int, input().split()))
Y = Y/1000
Z = Y - N
A = 9*N - Z
if Z < 0 or Z > 9*N:
  X = [-1,-1,-1]
elif 24 <= Z <= 9*N - 32:
  X = [(Z-27)//9+((Z%9)%4-1)%4,(9-2*(Z%9))%9,N-((Z-27)//9+((Z%9)%4-1)%4+(9-2*(Z%9))%9)]
  X = list(map(int, X))
elif 0 <= Z <= 23:
  if Z%4 == 0:
    X = [0,Z/4,N-(Z/4)]
  elif Z%9 == 0:
    X = [Z/9,0,N-(Z/9)]
  elif Z == 13 or Z == 17 or Z == 21:
    X = [1,(Z-9)/4,N-((Z-5)/4)]
  elif Z == 22:
    X = [2,1,N-3]
  else:
    X = [-1,-1,-1]
  X = list(map(int, X))
else:
  if A%5 == 0:
    X = [N-(A/5),A/5,0]
  elif A%9 == 0:
    X = [N-(A/9),0,A/9]
  elif A == 14 or A == 19 or A == 24 or A == 29:
    X = [N-((A-4)/5),(A-9)/5,1]
  elif A == 23 or A == 28:
    X = [N-((A-8)/5),(A-18)/5,2]
  else:
    X = [-1,-1,-1]
  X = list(map(int, X))
print(X[0],X[1],X[2])
Problem:
Snuke has an empty sequence a.  He will perform N operations on this sequence.  In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).  You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
b = list(map(int,input().split()))
ans = []
for i in range(N):
    for j in range(len(b)-1,-1,-1):
        if b[j] <= j+1:
            ans.append(b[j])
            b.pop(j)
            break
if len(ans) == N:
    for i in ans:
        print(i)
else:
    print(-1)


Fixed, accepted submission:
N = int(input())
b = list(map(int,input().split()))
ans = []
count = 1
for i in range(N-1,-1,-1):
    flag = True
    for j in range(i,-1,-1):
        if b[j] == j+1:
            ans.append(j+1)
            b.pop(j)
            flag = False
            break
    if flag:
        break
if flag:
    print(-1)
else:
    for i in range(len(ans)-1,-1,-1):
        print(ans[i])
Problem:
E869120 has A 1-yen coins and infinitely many 500-yen coins.   Determine if he can pay exactly N yen using only these coins.

Incorrect submission (verdict: Wrong Answer):
money = int(input())
A = int(input())

if (money % 500) > A:
    print('NO')
else:
    print('YES')


Fixed, accepted submission:
money = int(input())
A = int(input())

if (money % 500) > A:
    print('No')
else:
    print('Yes')
Problem:
Compute A \times B, truncate its fractional part, and print the result as an integer.

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

print(round(A*B))


Fixed, accepted submission:
import math
A, B = input().split()
A = int(A)

B_i = int(B[:-3])
B_f = int(B[-2:])


f = str(A*B_f)
if (len(f) >= 3):
    f_i = int(f[:-2])
else:
    f_i = 0

print(A*B_i + f_i)
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):
import sys

a_b_c = list(map(int, input().split()))
r = a_b_c[0]
g = a_b_c[1]
b = a_b_c[2]
k = int(input())

while (g <= r and k >= 0):
    g *= 2
    k -= 1
while (b <= g and k >= 0):
    b *= 2
    k -= 1
if (k < 0):
    print("No")
else:
    print("YES")

Fixed, accepted submission:
import sys

a_b_c = list(map(int, input().split()))
r = a_b_c[0]
g = a_b_c[1]
b = a_b_c[2]
k = int(input())

while (g <= r and k >= 0):
    g *= 2
    k -= 1
while (b <= g and k >= 0):
    b *= 2
    k -= 1
if (k < 0):
    print("No")
else:
    print("Yes")
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):
N=int(input())
A=list(map(int, input().split()))
b=[]
sum=0
for a in A:
    sum+=a
    b.append(sum)

print(b)
ans=float("inf")
for i in range(0,N-1):
    if ans>abs(b[-1]-b[i]*2):
        ans=abs(b[-1]-b[i]*2)
print(ans)


Fixed, accepted submission:
N=int(input())
A=list(map(int, input().split()))
b=[]
sum=0
for a in A:
    sum+=a
    b.append(sum)

ans=float("inf")
for i in range(0,N-1):
    if ans>abs(b[-1]-b[i]*2):
        ans=abs(b[-1]-b[i]*2)
print(ans)
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):
N = int(input())

ACcount = 0 
WAcount = 0
TLEcount = 0
REcount = 0
for i in range(N):
	S=input()

	if S == "AC":
		ACcount = ACcount + 1
	elif S == "WA":
		WAcount = WAcount + 1
	elif S == "TLE":
		TLEcount = TLEcount + 1
	elif S == "RE":
		REcount = REcount + 1

print("AC x　" + str(ACcount))
print("WA x　" + str(WAcount))
print("TLE x　" + str(TLEcount))
print("RE x　" + str(REcount))

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

ACcount = 0 
WAcount = 0
TLEcount = 0
REcount = 0
for i in range(N):
	S=input()

	if S == "AC":
		ACcount = ACcount + 1
	elif S == "WA":
		WAcount = WAcount + 1
	elif S == "TLE":
		TLEcount = TLEcount + 1
	elif S == "RE":
		REcount = REcount + 1

print("AC x", ACcount)
print("WA x", WAcount)
print("TLE x", TLEcount)
print("RE x", REcount)
Problem:
There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies.  Snuke can perform the following operation any number of times:    * Choose a box containing at least one candy, and eat one of the candies in the chosen box.  His objective is as follows:    * Any two neighboring boxes contain at most x candies in total.  Find the minimum number of operations required to achieve the objective.

Incorrect submission (verdict: Wrong Answer):
n,k = map(int,input().split())
lis = list(map(int,input().split()))
ans = 0
for i in range(n-1):
  if lis[i] + lis[i+1] > k:
    num = k-lis[i+1]-lis[i]
    ans += num
    if num >= lis[i+1]:
      num -= lis[i+1]
      lis[i+1] = 0
      lis[i] -= num
    else:
      lis[i+1] -= num
print(ans)

Fixed, accepted submission:
n,k = map(int,input().split())
lis = list(map(int,input().split()))
ans = 0
for i in range(n-1):
  if lis[i] + lis[i+1] > k:
    num = lis[i+1]+lis[i] -k
    ans += num
    if num >= lis[i+1]:
      num -= lis[i+1]
      lis[i+1] = 0
      lis[i] -= num
    else:
      lis[i+1] -= num
print(ans)
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())
a = list(map(int, input().split()))
a.sort()
ans = 0
median = 0
if N % 2 == 0:
	median = int((a[int(N/2) - 1] + a[int(N/2)]) / 2)
else:
	median = a[int(N/2)]
print(median)
for i in range(len(a)):
	ans += pow(median - a[i], 2)
print(ans)

Fixed, accepted submission:
N = int(input())
a = list(map(int, input().split()))
ans = pow(100, 9)
for i in range(-100, 101):
	temp = 0
	for j in range(len(a)):
		temp += pow(i - a[j], 2)
	ans = min(ans, temp)
print(ans)
Problem:
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
s = list(input())

l = [0]*n
l[n-1] = s[:n-1].count('E')
for i in range(n-1):
  w_side = s[:i].count('E')
  e_side = s[i+1:].count('W')
  l[i] = w_side + e_side
  
print(min(l))

Fixed, accepted submission:
import sys

n, s = sys.stdin.read().split()

def main():
    cnt = s.count('E')
    cur = 'E'
    res = [cnt]
    for c in s:
        if cur == 'W': cnt += 1
        if c == 'E': cnt -= 1
        res.append(cnt)
        cur = c
    print(min(res))
    
if __name__ ==  '__main__':
    main()
Problem:
Rng is preparing a problem set for a qualification round of CODEFESTIVAL.  He has N candidates of problems. The difficulty of the i-th candidate is D_i.  There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems.  Determine whether Rng can complete the problem set without creating new candidates of problems.

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

if __name__ == '__main__':
    N = int(input())
    D = list(map(int, input().split()))
    M = int(input())
    T = list(map(int, input().split()))

    counter_d = Counter(D)
    counter_t = Counter(T)

    ans = "Yes"
    for point, num in counter_t.items():

        if counter_d.get(point) is None or counter_d.get(point) < num:
            ans = "No"
            break

    print(ans)


Fixed, accepted submission:
from collections import Counter

if __name__ == '__main__':
    N = int(input())
    D = list(map(int, input().split()))
    M = int(input())
    T = list(map(int, input().split()))

    counter_d = Counter(D)
    counter_t = Counter(T)

    ans = "YES"
    for point, num in counter_t.items():
        if counter_d.get(point) is None or counter_d.get(point) < num:
            ans = "NO"
            break

    print(ans)
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: Time Limit Exceeded):
input_n = int(input())
num_list = [int(i) for i in (input().split())]

count = 0
while True:
    if all(i % 2 == 0 for i in num_list):
        nom_list = map(lambda x: x / 2, num_list)
        count += 1
    else:
        break
print(count)

Fixed, accepted submission:
import numpy as np

_ = int(input())
num_array = np.array(list(map(int, input().split())))

count = 0
while True:
    if any(num_array % 2 != 0):
        break
    num_array = num_array / 2
    count += 1
print(count)
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())
l=[]
for i in range(1,n+1): 
    ic = list(str(int(i))) 
    s = list(map(int,ic))
    print(s,sum(s))
    if sum(s) >= a and sum(s) <= b:
        l.append(i)
print(sum(l))

Fixed, accepted submission:
n,a,b = map(int,input().split())
l=[]
for i in range(1,n+1): 
    ic = list(str(int(i))) 
    s = list(map(int,ic))
    if sum(s) >= a and sum(s) <= b:
        l.append(i)
print(sum(l))
Problem:
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10.  Given an integer N, determine whether it is a Harshad number.

Incorrect submission (verdict: Wrong Answer):
N = list(input())
a = 0

for x in N:
    a += int(x)

if a % 10 == 0:
    print('Yes')
else:
    print('No')

Fixed, accepted submission:
N = list(input())
a = 0

for x in N:
    a += int(x)

if int(''.join(N)) % a == 0:
    print('Yes')
else:
    print('No')
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):
a, b, c = map(int, input().split())
total = 0

for x in range(a):
  z = x
  d = 0
  while z != 0:
    d += z % 10
    z = z // 10
  if b <= d <= c:total += x
print(total)


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

for x in range(a+1):
  z = x
  d = 0
  while z != 0:
    d += z % 10
    z = z // 10
  if b <= d <= c:total += x
print(total)
Problem:
AtCoder's head office consists of N rooms numbered 1 to N. For any two rooms, there is a direct passage connecting these rooms.  For security reasons, Takahashi the president asked you to set a **level** for every passage, which is a positive integer and must satisfy the following condition:    * For each room i\ (1 \leq i \leq N), if we leave Room i, pass through some passages whose levels are all equal and get back to Room i, the number of times we pass through a passage is always even.  Your task is to set levels to the passages so that the highest level of a passage is minimized.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
for i in range(1, n):
  print(*[i]*(n-i))

Fixed, accepted submission:
n = int(input())
for i in range(n-1):
  L = []
  for j in range(i+1, n):
    x = i^j
    l = (x&-x).bit_length()
    L.append(l)
  print(*L)
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):

coin_500 = int(input('500'))
coin_100 = int(input('100'))
coin_50 = int(input('50'))

target = int(input('target'))

counter = 0


for i_500 in range(coin_500 + 1):
    # print('======= loop 500 =======')
    if i_500 * 500 > target:
        break

    for i_100 in range(coin_100 + 1):
        # print('-------- loop 100 ---------')
        if i_500 * 500 + i_100 * 100 > target:
            break

        for i_50 in range(coin_50 + 1):
            # print('........... loop 50 ..........')
            if i_500 * 500 + i_100 * 100 + i_50 * 50 == target:
                # print('match: ', i_500, i_100, i_50)
                counter += 1

print(counter)

Fixed, accepted submission:

coin_500 = int(input())
coin_100 = int(input())
coin_50 = int(input())

target = int(input())

counter = 0


for i_500 in range(coin_500 + 1):
    # print('======= loop 500 =======')
    if i_500 * 500 > target:
        break

    for i_100 in range(coin_100 + 1):
        # print('-------- loop 100 ---------')
        if i_500 * 500 + i_100 * 100 > target:
            break

        for i_50 in range(coin_50 + 1):
            # print('........... loop 50 ..........')
            if i_500 * 500 + i_100 * 100 + i_50 * 50 == target:
                # print('match: ', i_500, i_100, i_50)
                counter += 1

print(counter)
Problem:
Snuke has N sticks. The length of the i-th stick is l_i.  Snuke is making a snake toy by joining K of the sticks together.  The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.

Incorrect submission (verdict: Wrong Answer):
A = input().split()

N = int(A[0])
K = int(A[1])

A = input().split()
l = []

for n in range(N):
    l.append(int(A[n]))

l.sort(reverse=True)
sum=0
for i in range(K):
    sum = sum + l[i]
print(l)
print(sum)


Fixed, accepted submission:
A = input().split()

N = int(A[0])
K = int(A[1])

A = input().split()
l = []

for n in range(N):
    l.append(int(A[n]))

l.sort(reverse=True)
sum=0
for i in range(K):
    sum = sum + l[i]
print(sum)