Problem:


Score : 200 points

Problem Statement

Snuke is having a barbeque party.

At the party, he will make N servings of Skewer Meal.

Example of a serving of Skewer Meal

He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i.
Also, he has an infinite supply of ingredients.

To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers.
Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.

What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Constraints

1≦N≦100

1≦L_i≦100

For each i, L_i is an integer.

Input

The input is given from Standard Input in the following format:

N
L_1 L_2 ... L_{2N}

Output

Print the maximum total number of ingredients that Snuke's N servings of Skewer Meal can hold.

Sample Input 1

2
1 3 1 2

Sample Output 1

3

If he makes a serving using the first and third skewers, and another using the second and fourth skewers, each serving will hold 1 and 2 ingredients, for the total of 3.

Sample Input 2

5
100 1 2 3 14 15 58 58 58 29

Sample Output 2

135



Sample input:
2
1 3 1 2


Sample output:
3

Submission status: Runtime Error

Solution code:
import numpy as np

cnt = input()
arr = input()
arr = map(int, arr.split(' '))

r = np.array(sorted(arr)[::-1])

print(sum([min(pair) for pair in r.reshape(5,2)]))

Submission status: Runtime Error

Solution code:
#座標平面に落とし込んで再帰関数で無理やり計算
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5)
N, X = map(int, input().split())
if 2 * X > N: #対称性
    X = N - X

#座標の作成
dp = [[-1] * (N+3)]
for i in range(N+1):
    tmp = [-1]
    for j in range(N+1):
        if i <= j:
            tmp.append(0) #到達していないマス
        else:
            tmp.append(-1) #壁(範囲外)
    tmp.append(-1)
    tmp.reverse()
    dp.append(tmp)
dp.append([-1] * (N+3))
# print (np.array(dp))


#m: 0:右へ, 1:左下へ, 2:左上へ
def moving(x, y, total, m):
    if x == X and y == 1 and dp[x][y] == 1: #一周回ってもとの座標に戻ってきた時
        # print ('D')
        return total
    if m == 0: #右に動く時
        tmp = 0
        while dp[x-1][y+1] == 0: #右に進める時
            dp[x-1][y+1] = 1 #右進んだマスを到達したことにする
            tmp += 1
            x -= 1
            y += 1
        if dp[x-1][y+1] == -1: #右側が壁の時-->左下に進む
            # print ('1-B')
            return moving(x, y, total + tmp, 1)
        if dp[x-1][y+1] == 1: #右側が光の線の時-->左上へ進む
            tmp += 1
            # print ('1-C')
            return moving(x-1, y+1, total + tmp, 2)
    
    if m == 1: #左下へ動く時
        tmp = 0
        while dp[x+1][y] == 0: #左下に進める時
            dp[x+1][y] = 1
            tmp += 1
            x += 1
        if dp[x+1][y] == -1: #左下が壁の時-->左上に進む
            # print ('2-C')
            return moving(x, y, total + tmp, 2)
        if dp[x+1][y] == 1: #左下が光の線の時-->左上に進む
            tmp += 1
            # print ('2-C')
            return moving(x+1, y, total + tmp, 2)
    
    if m == 2: #左上に動く時
        tmp = 0
        while dp[x][y-1] == 0: #左上に進める時
            dp[x][y-1] = 1
            tmp += 1
            y -= 1
        if dp[x][y-1] == -1: #左上が壁の時-->右に進む
            # print ('3-A')
            return moving(x, y, total + tmp, 0)
        if dp[x][y-1] == 1: #左上が光の線の時-->左下に進む
            tmp += 1
            # print ('3-B')
            return moving(x, y-1, total + tmp, 1)

X += 1
print (moving(X, 1, 0, 0))
# print (np.array(dp))

Submission status: Runtime Error

Solution code:
N = int(input())
L =[]
for i in range(N*2):
    guzai=int(input())
    L.append(guzai)

L.sort()
L_even=L[0::2]
goukei=sum(L_even)
print(str(goukei))

Submission status: Runtime Error

Solution code:
N = int(input())
L =[]

guzai=int(input())
L.append(guzai)

L.sort()
L_even=L[0::2]
goukei=sum(L_even)
print(str(goukei))

Submission status: Runtime Error

Solution code:
n = int(input())
l = [map(int, input().split())]

ans = 0
l.sort()

for i in range(n):
    ans += l[2*i]

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
L = list(map(int, input().split()))

L.sort()
s = 0

for n in range(N):
    s += L[2*n}

print(s)

Submission status: Runtime Error

Solution code:
N = int(input())
L = list(map(int,input().split())
 
L.sort()
 
s = 0
 
for n in range(N):
    s += L[2*n]
print(s)

Submission status: Runtime Error

Solution code:
N = input()
L = list(map(int,input().split())
 
L.sort()
 
s = 0
 
for n in range(N):
    s += L[2*n]
print(s)

Submission status: Runtime Error

Solution code:
N =int( input())
L = list(map(int,input().split())
 
L.sort
 
s = 0
 
for n in range(N):
    s += L[2*n]
print(s)

Submission status: Runtime Error

Solution code:
N = input()
L = list(map(int,input().split())

L.sort

s = 0

for n in range(N):
    s += L[2*n]
print(s)

Submission status: Runtime Error

Solution code:
N = int(input())

s = map(int,input().split())

list(s).sort(reverse=True)

sum = 0

for i in range(N):
  sum = sum +list(s)[2*i]

print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())

s = map(int,input().split())

s.sort()

sum = 0

for i in range(N):
  sum = sum + s[2*i+1]

print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())

s = map(int,input().split())

s.sort()

sum = 0

for i in range(N):
  sum = sum + s[2*i]

print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())

s = map(int,input().split())

s.sort(reverse=True)

sum = 0

for i in range(N):
  sum = sum + s[2*i]

print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())

s = input().split()

s.sort(reverse=True)

sum = 0

for i in range(N):
  sum = sum + s[2*i]

print(sum)

Submission status: Runtime Error

Solution code:
n=input()
a=input().split()
a=[int(i) for i in a]
a=a.sorted()
count=0
ans=0
for i in a:
  if count%2==0:
    ans+=i
  count+=1

Submission status: Runtime Error

Solution code:
n=int(input());print(sum(sorted(list(map(int,input().split())))[::2]))
print("RE WA?"

Submission status: Runtime Error

Solution code:
b=input()
a=int(input().split(" "))
sum=0
for i in a:
  sum=sum+i
sum//=2
print(sum)

Submission status: Runtime Error

Solution code:
a=int(input().split())
sum=0
for i in a:
  sum=sum+i
sum//=2
print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
c=list(map(int, input().split()))
c.sort()
Max = 0
for i in range(N):
  K = 2*N
  Max = Max + c[K]
print(Max)

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(map(int,input().split()))
s.sort()
sum = 0

for i in range(0,2n,2):
  sum += s[i]
print(sum)

Submission status: Runtime Error

Solution code:
def f(a,b):
	if a==b:
		return 2*a
	elif a < b:
		return 2*a* + f(a,b-a)
	else:
		return 2*b + f(a-b,b)


N,X = map(int,input().split(" "))

print(N+f(N-X,X))

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
l=set(l)
z=0
for i in range(n):
  z+=l[2*i]
print(z)

Submission status: Runtime Error

Solution code:
num = input()
num_list = list(map(int, input().split()))sort()
i = 0
sum = 0
while i < num * 2:
  sum += num_list[i]
  i += 2
print(sum)

Submission status: Runtime Error

Solution code:
def main():
    n,x=map(int,input().split())
    a,b=n-x,x
    if(a<b):
       a,b=b,a
    path_length = calc_path(a,b,n)
    print(path_length)

def  calc_path(a1,b1,c1):
    q , mod=divmod(a1,b1)
    count=0
    if mod==0:
         c2=c1+2*b1*q-b1
         return c2
    else:
        count=count+1
        c2=c1+2*b1*q
        a2=a1-b1*q
        b2=b1
        if(a2<b2):
           a2,b2=b2,a2
        return calc_path(a2,b2,c2)
if __name__=='__main__':
  main()

Submission status: Runtime Error

Solution code:
def main():
    n,x=map(int,input().split())
    a,b=n-x,x
    if(a<b):
       a,b=b,a
    path_length = calc_path(a,b,n)
    print(path_length)

def  calc_path(a1,b1,c1):
    q , mod=divmod(a1,b1)
    count=0
    if mod==0:
         c2=c1+b1*(q+1)
         return c2
    else:
        count=count+1
        c2=c1+b1*(q+1)
        a2=a1-b1*q
        b2=b1
        if(a2<b2):
           a2,b2=b2,a2
        return calc_path(a2,b2,c2)
if __name__=='__main__':
  main()

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(0,n/2,2):
    ans+=l[i]
print(ans)n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range([0,]n[,2]):
    ans+=l[i]
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(0,n/2,2):
    ans+=l[i]
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
table = list(map(int,input().split()))
table.sort()
count = 0
for i in range(n):
    if i%2 = 0:
        count += table[i]
    else:
        pass
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
table = list(map(int,input().split()))
table.sort()
count = 0
for i in range(1,n+1):
    if i%2 = 1:
        count += table[i]
    else:
        pass
print(count)

Submission status: Runtime Error

Solution code:
#-*- coding: utf-8 -*-
N = int(input())
L_list = [int(input()) for n in range(2N)]

L_list.sort()
print(sum(L_list[::2]))

Submission status: Runtime Error

Solution code:
#-*- coding: utf-8 -*-
N = int(input())
L_list = [int(input()) for n in range(2N)]

L_list.sort()
print(sum(L_list[1::2]))

Submission status: Runtime Error

Solution code:
from fractionsimport gcd
n,x=map(int,input().split())
print(3*(n-gcd(n,x)))

Submission status: Runtime Error

Solution code:
def tri_len(x,y):
  if x== y:
    return x
  elif x < y:
    return tri_len(y-x,x)+2*x
  else:
    return tri_len(x-y,y)+2*y
import sys
sys.setrecursionlimit(100000)

n,x= list(map(int,input().split(" ")))

print( n+tri_len(x,n-x))

Submission status: Runtime Error

Solution code:
def tri_len(x,y):
  if x== y:
    return x
  elif x < y:
    return tri_len(y-x,x)+2*x
  else:
    return tri_len(x-y,y)+2*y
import sys
sys.setrecursionlimit(10000)

n,x= list(map(int,input().split(" ")))

print( n+tri_len(x,n-x))

Submission status: Runtime Error

Solution code:
a = input()
lst = input().split(" ")
lst.sort()
ans=0
for i in range(int(len(lst))):
  ans += lst[len(lst)-2*i-2]

print(ans)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    int d=0;
    int a[N*2];
    for(int i=0;i<N*2;i++){
        cin>>a[i];
    }
    sort(a,a+N);
    for(int l=0;l<N*2;l+=2){
        d+=a[l];
    }
    cout<<d<<endl;
}

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

N_stick = int(sys.argv[1])

left = [0 for i in range(N_stick)]
right = [0 for i in range(N_stick)]
stuff = [ 0 for i in range(N_stick*2)]

for i in range(N_stick*2):
    stuff[i] = sys.argv[i+2]

left = [ int(stuff[2*i]) for i in range(N_stick)]
right = [ int(stuff[2*i+1]) for i in range(N_stick)]

total = left + right
sortedlist  = sorted(total)

for i in range(N_stick):
    left[i] = sortedlist[2*i]
    right[i] = sortedlist[2*i+1]

meat = sum(left)

print(meat)

Submission status: Runtime Error

Solution code:
input_word = input()
input_list = input_word.split(" ")
N = int(input_list[0])
K = int(input_list[1])
input_word = input()
tmp_list = input_word.split(" ")
input_list = [ int(i) for i in tmp_list ]

while True:
  flag = 0
  for i in range(1,N):
    number = input_list.index(i)
    number_1 = input_list.index(i+1)
    if number - number_1 >= K:
        input_list[number_1],input_list[number] = input_list[number],input_list[number_1]
        flag = 1
        break
  if flag == 0:
    break

for i in input_list:
  print(i)

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split())).sort()
ans = 0
for a, b in zip(A, A[1:]):
  ans += a
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=sorted(list(map(int,input().split())),reverse=True)
print(sum(l[1::2])

Submission status: Runtime Error

Solution code:
n=int(input())
l=sorted(list(map(int,iput().split())),reverse=True)
print(sum(l[1::2])

Submission status: Runtime Error

Solution code:
n=int(input())
l=sorted(list(map(int,iput().split()),reverse=True)
print(sum(l[1::2])

Submission status: Runtime Error

Solution code:
n=int(input())
l=[input() for i in range(n)]
l.sort()
s=0
for j in l[::2]:
    s+=j
print(s)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = [int(input()) for i in range(2*N)]
L = sort(a)
b = []
for i in range(2*N):
  b.append(a[2*i])
print(sum(b))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = [int(input()) for i in range(2N)]
L = sort(a)
b = []
for i in range(2N):
  b.append(a[2*i])
print(sum(b))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = [int(input()) for i in range(2N)]
L = sort(a)
b = []
for i in range(2N)
b.append(a[2*i])
print(sum(b))

Submission status: Runtime Error

Solution code:
n = int(input())

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

x.sort()

ans = 0

for i range(n):
  ans = ans + x[i*2]
    
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

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

x.sort()

ans = 0

for i range(n):
  ans = ans + x[i*2]
    
print(ans)

Submission status: Runtime Error

Solution code:
n= int(input())

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

x.sort()

ans = 0

for i range(n):
  ans = ans + x[i*2]
    
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())

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

x.sort()

ans = 0

for i range(n):
  ans = ans + x[i*2]
    
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int, input().split()))

x.sort()

ans = 0

for i range(n):
  ans = ans + x[i*2]
    
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int, input().split()))

x.sort()

ans=0

for i range(n):
  ans = ans + x[i*2]
    
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int, input().split()))

x.sort()

ans=0

for i range(n):
  ans=ans+x[i*2]
    
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int, input().split()))

x.sort()
ans=0

for i range(n):
  ans=ans+x[i*2]
    
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int,input().split()))

x.sort()
ans=0

for i range(n):
  ans=ans+x[i*2]
    
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int,input().split()))

x.sort()
ans=0

for i range(n):
  ans=+x[i*2]
    
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int,input().split()))

x.sort()
ans=0

for i range(n):
  ans+=x[i*2]
    
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int,input().split()))

x.sort()
ans=0

for i range(n):
  if i%2==1:
    pass
  else:
    ans+=min(x[i],x[i+1])
    
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
cou=0

for i in range(n*2):
  a[i]=int(input())
  
a.sort()
for i*2 in range(n):
  cou+=min(a[i],a[i+1])
  
print(cou)

Submission status: Runtime Error

Solution code:
n = input
l = map(int, input().split())
l = sorted(l)

ans = 0
for i in range(len(n)):
  a = l[2*i]
  b = l[2*i+1]
  ans =+ min(a,b)

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))

l.sort()
k=l[::2]

print(k.sum())

Submission status: Runtime Error

Solution code:
n = int(input())
l = [int(i) for i in input().split()]
a = 0
for i in len(l):
    if i % 2 == 0:
        a = a + l[i]
print(a)

Submission status: Runtime Error

Solution code:
N = int(raw_input())
list_input = sorted(map(int, raw_input().split()))
print(sum(list_input[::2]))

Submission status: Runtime Error

Solution code:
N = int(raw_input())
list_input = map(int, raw_input().split())

list_input = sorted(list_input)
sums = 0
for i in range(0,2*N,2):
    print(i)
    sums += min(list_input[i],list_input[i+1])
print(sums)

Submission status: Runtime Error

Solution code:
N = int(raw_input())
list_input = map(int, raw_input().split())

list_input = sorted(list_input)
sums = 0
for i in range(0,2*N,2):
    sums += min(list_input[i],list_input[i+1])

print(sums)

Submission status: Runtime Error

Solution code:
N = int(input())
list_input = map(int, raw_input().split())

list_input = sorted(list_input)
sums = 0
for i in range(0,2*N,2):
    sums += min(list_input[i],list_input[i+1])

print(sums)

Submission status: Runtime Error

Solution code:
N = input()
list_input = map(int, raw_input().split())

list_input = sorted(list_input)
sums = 0
for i in range(0,2*N,2):
    sums += min(list_input[i],list_input[i+1])

print(sums)

Submission status: Runtime Error

Solution code:
N = input()
list_input = map(int, raw_input().split())

list_input = sorted(list_input)
sums = 0
for i in range(N,2*N):
    sums += list_input[i]

print(sums)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())

import sys

sys.setrecursionlimit(20000)

l = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    l[a-1].append(b-1)
    l[b-1].append(a-1)

def first_search(first, depth):
    record = 0
    for i in l[first]:
        temp = search(first, i, depth-1)
        if record < temp:
            record = temp
    return record + 1

def search(before, now, depth):
    if depth <= 0:
        return 1
    else:
        ans = 1
        for i in l[now]:
            if before != i:
                ans += search(now, i, depth-1)
        return ans

ret = 0    
for i in range(n):
    temp = first_search(i, k)
    if temp > ret:
        ret = temp
        
if ret > n:
    print(0)
else:
    print(n-ret)

Submission status: Runtime Error

Solution code:
a = int(input())

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

b.sorted()

su = 0

for i in range(a-1):
  su += b[2*i]

Submission status: Runtime Error

Solution code:
a = int(input())

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

b.sorted()

su = 0

for i in range(a):
  su += b[2*i]

Submission status: Runtime Error

Solution code:
import numpy as np
N, K = map(int, input().split())

E = np.zeros((N, N), dtype=int)
exit(0)

Elist = []
for e in range(N-1):
    i, o = map(int, input().split())
    Elist.append((i-1, o-1))
    E[i-1][o-1] = 1
    E[o-1][i-1] = 1
    
# print("N, K=", N, K)
# for e in Elist:
#     print(e[0], e[1])

I = np.eye(N, dtype=int)

# print("I=", I)

ie = I
for k in range(K):
    ie = ie + np.matmul(I, E)
# print("I + IE =", ie)

# withinK = np.count_nonzero(ie, axis=0)
withinK = np.zeros(N, dtype=int)
for i in range(N):
    for j in range(N):
        if ie[i][j] > 0:
            withinK[i] += 1 
# print("withinK=", withinK)
maxBall = np.amax(withinK)
# print("maxBall=", maxBall)
solution = N - maxBall
print(solution)

Submission status: Runtime Error

Solution code:
from collections import deque

N, K = map(int, input().split())
T = [[] for i in range(N)]
E = []
for i in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    T[a].append(b)
    T[b].append(a)
    E.append((a, b))


def bfs(n):
    visited = [False] * N
    dist = [0] * N
    queue = deque([n])
    while queue:
        node = queue.pop()
        if visited[node]:
            continue
        visited[node] = True
        for n in T[node]:
            if not visited[n]:
                dist[n] = dist[node] + 1
                queue.appendleft(n)
    return dist


dist = []
for i in range(N):
    dist.append(bfs(i))

ans = float('inf')
if K % 2 == 0:
    # 全ての頂点について全探索
    for i in range(N):
        ans = min(ans, len([d for d in dist[i] if d > K / 2]))
else:
    # 全ての辺について全探索
    for a, b in E:
        adist = [(1 if min(d1, d2) > (K-1) / 2 else 0) for d1, d2 in zip(dist[a], dist[b])]
        ans = min(ans, sum(adist))

print(ans)

Submission status: Runtime Error

Solution code:
N = input()
Li = map(int, input().split(" "))
Li.sort()
total = 0
for i in Li[0::2]
    total += i
print(total)

Submission status: Runtime Error

Solution code:
n = int(input())

arr = [map(int,raw_input().split()) for i in range(n)]

count = 0
for i in range(n-1):
	for j in range(i+1,n):
			s = sum(arr[i]) + sum(arr[j])
			comb = s*(s-1)/2
			count += comb

print count%(1000000000+7)

Submission status: Runtime Error

Solution code:
n = int(input())
print(sum(sorted(map(int, input()))[::2]))

Submission status: Runtime Error

Solution code:
N, X = map(int, intpu().split())
if X <= N / 3:
    result = 3 * (N - X)
if N / 3 < X and X < N /2:
    result = 6 * X
if N / 2 <= X:
    result = 3 * X
print(result)

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
sum=0
for x in range(0,n*2+1,2):
    sum+=min(l[x:x+2])
print(sum)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)



N,k = map(int,raw_input().split())
#k = int(raw_input())
#A = map(int, raw_input().split())
ans = gcd(N,k)
print 3*(N - ans)

Submission status: Runtime Error

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
sum = 0
A.sort()
A = A[::2]
print sum(A)

Submission status: Runtime Error

Solution code:
N = input()
kushi = sorted(list(map(int, input().split())))
even = kushi[0::2]
print(sum(even)

Submission status: Runtime Error

Solution code:
n = int(input())
L = map(int, input().split(" "))
L_sorted = sorted(L)

pairs = []
for index in range(0, len(L_sorted)/2, 2):
    pairs.append(L_sorted[index : index +2])

answer = sum( min(x) for x in pairs)
print(answer)

Submission status: Runtime Error

Solution code:
ii=lambda:map(int,raw_input().split())
n,k=ii()
T,F=True,False
e=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=ii()
    e[a-1]+=[b-1];e[b-1]+=[a-1]
cost=[0]*n
ans=10**5
def dfs(x,f):
    if f>=0:vis[f]=T
    q=[(x,0)]
    while len(q):
        v,c=q.pop(0)
        if c>k/2:break
        cost[v]=c;vis[v]=T
        for w in e[v]:
            if not vis[w]:q+=[(w,c+1)]
    return n-vis.count(T)
if k%2:
    for i in range(n):
        for j in e[i]:
            if i<j:vis=[F]*n;dfs(i,j);ans=min(ans,dfs(j,i))
else:
    for i in range(n):vis=[F]*n;ans=min(ans,dfs(i,-1))
print ans

Submission status: Runtime Error

Solution code:
N = int(input())
L = map(int, input().split())
sort(L)
sum = 0
for i in range(0,len(L),2):
	sum += L[i]
print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
L = map(int, input().split())
sort(L)
sum = 0
for i in range(0,N):
    sum += L[i*2]
print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
L = map(int, input().split())
sort(L)
sum = 0
for i in range(0,len(L),2):
    sum += L[i]
print(sum)

Submission status: Runtime Error

Solution code:
n, x = map(int, raw_input().split())

def cal(n):
	return n + 1 + (n - 2)*2

if n % x == 0:
	l = cal(n) - cal(x)
else:
	l = cal(n)

print l

Submission status: Runtime Error

Solution code:
n = raw_input()
l = raw_input().split()
print(sum(sorted(l, reverse=True)[1::2]))

Submission status: Runtime Error

Solution code:
NX = input()
NX = "".join(NX).split(" ")
NX = [int(s) for s in NX]
D = NX[0]-NX[1]
if NX[0] ==0 or NX[1]==0:
	print(str(0))
if NX[1]<D:
	Mod = D%NX[1]
	if Mod!=0:
		print(int(2*NX[1]+NX[1]+(D-NX[1]/2)*3))
	else:
		print(int(NX[1]*4+D))
elif NX[1]==D:
	print(int(3*NX[1]))
elif NX[1]>D:	
	Mod = NX[1]%D
	if Mod!=0:
		print(int(NX[1]+(Mod*3)+D+(D*2*int(NX[1]/D))))
	else:
		print(int(NX[1]+int((NX[1]/D))*2*D))

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3
import sys

sys.setrecursionlimit(100000)

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

def f(a,b):
    if a > b:
        a,b = b,a
    if a==0 or b==0:
        return 0
    if b%a is 0:
        return int(a*(2*(b/a)-1))

    return int(2*a*int(b/a) + f(a,b%a))

print(N+f(N-X, X))

Submission status: Runtime Error

Solution code:
n, x = map(int,input().split())

if x > n // 2:
    x = n - x

xx = x
yy = n - x

ans = n
i = 0

while True:
    ans += 2 * (yy // xx) * xx
    yy %= xx

    if yy == 0:
        ans -= xx
        break

    if yy < xx:
        tmp = xx
        xx = yy
        yy = tmp

print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

def dfs1(s,c):
    visited[s]=1
    for i in v[s]:
        if visited[i]==0:
            d[c][i]=d[c][s]+1
            dfs1(i,c)
    return

def dfs2(c1,c2):
    visited[c2]=1
    dfs1(c1,c1)
    dfs1(c2,c2)
    return

n,k=map(int,raw_input().split())
d=[[0]*n for _ in xrange(n)]
v=[[] for _ in xrange(n)]
e=[]
for i in xrange(n-1):
    a,b=map(int,raw_input().split())
    a-=1
    b-=1
    v[a].append(b)
    v[b].append(a)
    e.append([a,b])
if k%2==0:
    min_del=1000000
    for i in xrange(n):
        cnt=0
        visited=[0]*n
        dfs1(i,i)
        for j in xrange(n):
            if d[i][j]>k/2:
                cnt+=1
        min_del=min(min_del,cnt)
    print(min_del)
else:
    min_del=1000000
    for i,j in e:
        cnt=0
        visited=[0]*n
        d=[[0]*n for _ in xrange(n)]
        dfs2(i,j)
        for l in xrange(n):
            if d[i][l]>(k-1)/2 or d[j][l]>(k-1)/2:
                cnt+=1
        min_del=min(min_del,cnt)
    print(min_del)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)


n,x=map(int,raw_input().split())
print 3*(n-gcd(n,x))

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)


n,x=map(int,raw_input().split())
print 3*(n-gcd(n,x))

Submission status: Runtime Error

Solution code:
n,x = map(int,raw_input().split())
print '%d' %(n + ((n/x) - 1)*2*x + 3*(n%x))

Submission status: Runtime Error

Solution code:
n,x = map(int,raw_input().split())
if n > 2*x :
    print '%d' %(n + (n/x - 1)*2*x + 3*(n-(n/x)*x))
else :
    print '%d' %(n + x)

Submission status: Runtime Error

Solution code:
import scipy.misc as scm
def combi(p,q):
    return scm.comb(p,q,1)

ans=0
n=int(input())
k=[]
for i in range(n):
    a,b=map(int,input().split())
    k.append([a,b])

for i in range(n-1):
    for j in range(i+1,n):
        p=k[i][0]+k[i][1]+k[j][0]+k[j][1]
        q=k[i][0]+k[j][0]
        ans += combi(p,q) % (10**9+7)


ans = ans % (10**9+7)
print(ans)

Submission status: Runtime Error

Solution code:
def f(a, b):
    if b%a==0:
        return b//a*2-1
    else:
        return b//a*a*2+f(b%a,a)

N, X = map(int, input().split())
ans = N + f(min(N-X,X), max(N-X,X))
print(ans)

Submission status: Runtime Error

Solution code:
N = input()
L = input()
i = 0
array = []
anser = 0

while i < len(L):
    if L[i] != ' ':
        array.append(int(L[i]))
    i+=1
i = 1
array.sort(reverse=True)
for i in range(array):
    if i // 2 == 0:
        anser+=i
print(anser)

Submission status: Runtime Error

Solution code:
import sys;
n,x=map(int,raw_input().split());
if(2*x<n):
        print x+(n-x)+x+x+(n-2*x)*(2*x-1);
    
elif(2*x==n):
        print x+(n-x)+x;

else:
        print x+(n-x)+x+(n-x)+x+(n-x);

Submission status: Runtime Error

Solution code:
# encoding: utf-8

n, x = map(int, raw_input().split())

ac_bc = n - x
s = ac_bc / 3
l = ac_bc - s
print ac_bc + s * 3 + l * 3

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N, X = list(map(int, input().split()))
sum_ = X
prev = X
next = N - X
i = 0
while True:
    num = prev // next
    if i == 0:
        sum_ += 2 * num * next
    elif i % 2 == 1:
        sum_ += 2 * num * next - next
    else:
        sum_ += 2 * num * next - next
    mod_ = prev % next
    if mod_ == 0:
        break
    sum_ += next
    prev = next
    next = mod_
    i += 1
print(sum_)

Submission status: Runtime Error

Solution code:
N, X = map(int, raw_input().split())
ans = 0
if N%2 ==0:
    d = min(X, N-X)
    ans = (N-d)*3
else:
    ans = (N-1)*3

print(ans)

Submission status: Runtime Error

Solution code:
N, X = map(int, raw_input().strip().split())
print N + (N-X)*2 -1

Submission status: Runtime Error

Solution code:
N, x = map(long, raw_input().split())
print (N - x) + 3 * x + 3 * (N - x - x)

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3

N, X = map(int, input().split())
if X*2 == N:
    print(X*3)
else:
    print(X*3*((N-X)//X + (1 if (N-X)%X>0 else 0)))

Submission status: Runtime Error

Solution code:
def bbq():
    n = int(input())
    a = input()
    tmp = a.split()
    l = [int(x) for x in tmp]
    l.sort()
    n = 0
    i = 0
    while(i<n:
        n += l[i]
        i += 2
    print (n)

if __name__ == "__main__":
    bbq()

Submission status: Runtime Error

Solution code:
N=raw_input()
up=raw_input()
up=up.split()

up=map(int,up)
up.sort()
count=0
for i in range(N):
    count+=up[i*2]
print count

Submission status: Runtime Error

Solution code:
N=raw_input()
up=raw_input().split()

up=map(int,up)
up.sort()
count=0
for i in range(N):
    count+=up[i*2]
print count

Submission status: Runtime Error

Solution code:
N=raw_input()
up=raw_input().split()

up=up.sort()
count=0
for i in range(N):
    count+=int(up[i*2])
print count