Harryxun/stf_run huggingface dataset:
S=input()
K=int(input())

i=0
c=0
while i<len(S)-1:
  if S[i]==S[i+1]:
    c+=1
    i+=2
  else:
    i+=1
    
if S[0]==S[-1] and S[-2]!=S[-1]:
  print((c+1)*K-1)
else:
  print(c*K)

### FIXED CODE ###

S=input()
K=int(input())

def f(s):
  i=0
  c=0
  n=len(s)
  if n==1:
    return 0
  else:
    while i<n-1:
      if s[i]==s[i+1]:
        c+=1
        i+=2
      else:
        i+=1
    return c

a=0
n=len(S)
while a<n-1 and S[0]==S[a+1]:
  a+=1
  
b=-1
while a<n-1 and S[0]==S[b]:
  b-=1
  
if a==n-1:
  ans=n*K//2
elif b==-1:
  ans=f(S)*K
elif a==0 and b!=-1:
  ans=(K-1)*((-b-1)//2)+K*f(S[1:b+1])+(-b-1)//2
elif a!=0 and b!=-1:
  ans=(a+1)//2+f(S[a+1:b+1])*K+((a-b)//2)*(K-1)+(-b-1)//2
  
print(ans)
import sys
input = sys.stdin.readline

def main():
    n,m=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    a.reverse()
    l,r=2*a[-1],2*a[0]
    x=(l+r)//2
    while l+1<r:
        cnt=0
        s=0
        for A in a:
            for B in a:
                if A+B>=x:
                    cnt+=1
                    s+=A+B
                else:
                    break
        if cnt>=m:
            l=x
        else:
            r=x
        x=(l+r)//2
    print(s+(m-cnt)*l)
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
from bisect import bisect, bisect_left
from itertools import accumulate

def main():
    def check(x):
        count = 0
        for a in aaa:
            if x <= a:
                count += n
            else:
                count += n - bisect_left(aaa, x - a)
        return count >= m
    
    
    n, m = map(int, input().split())
    aaa = list(map(int, input().split()))
    aaa.sort()
    acc = [0] + list(accumulate(aaa))
    sum_a = acc[-1]
    
    l, r = 0, 200001
    while l + 1 < r:
        mid = (l + r) // 2
        if check(mid):
            l = mid
        else:
            r = mid
    
    # 合計がlより大きい組み合わせの和と組数を求める→Mに足りない分だけ合計がlの組を採用
    ans = 0
    count = 0
    for a in aaa:
        if l <= a:
            ans += sum_a + a * n
            count += n
        else:
            omit = bisect(aaa, l - a)
            if omit < n:
                ans += sum_a - acc[omit] + a * (n - omit)
                count += n - omit
    ans += l * (m - count)
    print(ans)
    
if __name__ == '__main__':
    main()
n, k, q = map(int, input().split())
v = [0] * n

for _ in range(q):
  v[int(input())+1] += 1

for x in v:
  if x + k - q > 0:
    print('Yes')
  else:
    print('No')


### FIXED CODE ###

n, k, q = map(int, input().split())
v = [0] * n

for _ in range(q):
  v[int(input())-1] += 1

for x in v:
  if x + k - q > 0:
    print('Yes')
  else:
    print('No')
N = int(input)
isDiv = 'No'
for i in range(1, 10):
  if N % i == 0:
    if N / i <= 9:
    	isDiv = 'Yes'
    	break
print(isDiv)


### FIXED CODE ###

N = int(input())
isDiv = 'No'
for i in range(1, 10):
  if N % i == 0:
    if N / i <= 9:
    	isDiv = 'Yes'
    	break
print(isDiv)
a, b, c = input().split()
print(c + ' ' + a + ' '

### FIXED CODE ###

a, b, c = input().split()
print(c + ' ' + a + ' ' + b)
# coding: utf-8
a,b,x = map(int, input().split())
print(b//x - (a-1)//x)

### FIXED CODE ###

# -*- coding: utf-8 -*-
print("".join([w[0] for w in input().split()]))
from collections import Counter
a = int(input())
l = []
for i in range(0,a):
    b = int(input())
    l.append(b)
c=Counter(l)
d = dict(c)
kv = []
for k,v in d.items():
    if k>v:
        t = v
        kv.append(t)
    elif k<v:
        t = v-k
        kv.append(t)
    elif k==v:
       t= 0
       kv.append(t)        
s = sum(kv)
print(s)




### FIXED CODE ###

from collections import Counter
a = int(input())
l = list(map(int, input().split()))
#i = 1

c=Counter(l)
d = dict(c)
kv = []
for k,v in d.items():
    if k>v:
        kv.append(v)
    elif k<v:
        t = v-k
        kv.append(t)
s = sum(kv)
print(s)
import math
n=int(input())
a=list(map(int,input().split()))
r=[a[-1]]
l=[a[0]]
for i in range(1,n-1):
    l.append(math.gcd(l[i-1],a[i]))
    r.append(math.gcd(r[i-1],a[-1-i]))
ans=r[-1]    
for i in range(n-2):
    ans=max(ans,math.gcd(l[i],r[-2-i]))
ans=max(ans,l[-1])
print(ans)

### FIXED CODE ###

from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
r=[a[-1]]
l=[a[0]]
for i in range(1,n-1):
    l.append(gcd(l[i-1],a[i]))
    r.append(gcd(r[i-1],a[-1-i]))
ans=r[-1]    
for i in range(n-2):
    ans=max(ans,gcd(l[i],r[-2-i]))
ans=max(ans,l[-1])
print(ans)
n, m, k = map(int, input().split())
z = 998244353
if n <= k+1:
    a = 1
    for i in range(n):
        a = a*m%z
    print(a)
else:
    d = m
    for i in range(n-1):
        d = d*(m-1)%z
    a = [d]
    b = [1]
    c = 0
    for i in range(k):
        b.append(int(b[-1]/(i+1)*(n-i-1)%z))
    for i in range(k):
        a.append(int((a[-1]*b[i+1]%z)/b[i]/(m-1)))
    for i in range(k+1):
        c = (c+a[i])%z
    print(c)

### FIXED CODE ###

n, m, k = map(int, input().split())
z = 998244353
if n <= k+1:
    a = 1
    for i in range(n):
        a = a*m%z
    print(a)
else:
    a = []
    b = []
    d = [1, 1]
    e = [1, 1]
    f = [0, 1]
    for i in range(2, n):
        d.append(d[-1]*i%z)
        f.append((-f[z%i]*(z//i))%z)
        e.append(e[-1]*f[-1]%z)
    for i in range(k+1):
        b.append(d[n-1]*e[i]*e[n-i-1]%z)
    x = 0
    g = [1]
    for i in range(n-1):
        g.append(g[i]*(m-1)%z)
    for i in range(k+1):
        a.append(b[i]*m*g[n-i-1]%z)
    for i in range(k+1):
        x = (x+a[i])%z
    print(x)
n, a, b = map(int, input())
print(min(a, b), a+b-n)

### FIXED CODE ###

n, a, b = map(int, input().split())
ans_min = 0 if a+b-n <0 else a+b-n
print(min(a, b), ans_min)
l = [list(map(int,input.split())) for i in range(n)]
N = l[0][0]
D = l[0][1]
count = 0
for i in range(N):
    if l[i+1][0]**2 + l[i+1][1]**2 <= D**2:
        count += 1
print(count)

### FIXED CODE ###

N,D = map(int,input().split())
count = 0
for i in range(N):
    X,Y = map(int,input().split())
    if X**2 + Y**2 <= D**2:
        count += 1
print(count)
import math
while True:
    s=input().split()
    if s[0]==0:
        break
    elif s[1]==+:
        print(int(s[0])+int(s[2]))
    elif s[1]==-:
        print(int(s[0])-int(s[2]))
    elif s[1]==*:
        print(int(s[0])*int(s[2]))
    elif s[1]==/:
        print(math.floor(int(s[0])/int(s[2])))


### FIXED CODE ###

import math
while True:
    s=input().split()
    if s[1]=="?":
        break
    elif s[1]=="+":
        print(int(s[0])+int(s[2]))
    elif s[1]=="-":
        print(int(s[0])-int(s[2]))
    elif s[1]=="*":
        print(int(s[0])*int(s[2]))
    elif s[1]=="/":
        print(math.floor(int(s[0])/int(s[2])))
a,b,k = map(int,input().split())
ansa = 0
if a + b <k:
    print("0 0")
elif a < k:
    ansa =0
    ansb = b-(k-a)
else:
    ansa = a-k
    ansb = b
print(str(ansa)+" "+str(ansb))

### FIXED CODE ###

a,b,k = map(int,input().split())
ansa = 0
if a + b <k:
    print("0 0")
elif a < k:
    ansa =0
    ansb = b-(k-a)
    print(str(ansa)+" "+str(ansb))
else:
    ansa = a-k
    ansb = b
    print(str(ansa)+" "+str(ansb))
#include <iostream>
using namespace std;
int main(void){
	int a,b;
	cin >> a >> b;
	if (b%a==0) {
		cout << a+b << endl;
	}else {
		cout << b-a << endl;
	}
	return 0;
}

### FIXED CODE ###

a,b = (int(i) for i in input().split())
if b%a==0:
    print(a+b)
else:
    print(b-a)
def main()
	n = input()
  	arr = list(map(input().split()))
    if 0 in arr:
        return print(0)
  	prod = 1
    for x in arr:
        prod *= x
        if prod > int(1e18):
            return print(-1)
    print(prod)

if __name__ = "__main__":
	main()

### FIXED CODE ###

def main():
    n = int(input())
    arr = list(map(int, input().split()))
    if 0 in arr:
        print(0)
        return
    prod = 1
    for x in arr:
        prod *= x
        if prod > int(1e18):
            print(-1)
            return
    print(prod)

if __name__ == "__main__":
    main()
N = int(input())
if(N in [1, 2, 3, 4, 5, 6, 7 ,8 ,9, 10, 12, 14, 15, 16, 18, 20, 21 ,24, 25, 27, 30, 32, 35, 36, 40, 42,45, 48, 49, 54, 56, 63, 64 ,72, 81]):
    print("Yes")
else:
    print("No")


### FIXED CODE ###

A, B = map(int, input().split())
print(A*B if A <= 9 and B <= 9 else -1)
import math
def lcm(x, y):
    return x // math.gcd(x, y) * y
a,b = map(int,input().split())
print(lcm(a,b))

### FIXED CODE ###

from fractions import gcd
def lcm(x, y):
    return (x // gcd(x, y) *y)
a,b = map(int,input().split())
ans = lcm(a, b)
print(ans)
a*b = c
if c%2 == 0:
  print("Even")
else:
  print("Odd")

### FIXED CODE ###

a, b = map(int, input().split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")
A, P = map(int,input().split())
print((3A+P)//2)

### FIXED CODE ###

A, P = map(int,input().split())
print((3*A+P)//2)
N=int(input())
List=list(map(int,input().split()))
c=0
for i in range(N-1):
  for j in range(i+1:N):
    c=c+(List[i]*List[j])
print(c)

### FIXED CODE ###

N=int(input())
List=list(map(int,input().split()))
c=0
for i in range(N-1):
  for j in range(i+1,N):
    c=c+(List[i]*List[j])
print(c)
num = input().split(" ")
zahyou = input().split(" ")

num[1] = int(num[1])
plus = []
minus = []
rousoku = []
for i in range(int(num[0])):
    if(int(zahyou[i]) < 0):
        minus.append(int(zahyou[i]))
    else:
        plus.append(int(zahyou[i]))

# プラス方向で終了する場合

if(num[1] > len(plus)):
    plus_tmp = minus[(len(plus)-num[1]):] + plus
    minus_tmp = minus[:(len(minus)+len(plus_tmp)-num[1]-1)]
rousoku = plus_tmp[0:num[1]]
minus_tmp_2 = []
for i in minus_tmp:
    minus_tmp_2.append(i)
while(True):
    if(rousoku[-1] - rousoku[-2] >= (min(min(rousoku), 0) - minus_tmp_2[-1]) * 2):
        rousoku.pop(-1)
        rousoku.insert(0, minus_tmp_2.pop(-1))
    else:
        break
rousoku_move_plus = []
for i in rousoku:
    rousoku_move_plus.append(i - min(rousoku) * 2)

# マイナス方向で終了する場合
if(num[1] > len(minus)):
    minus_tmp = minus + plus[:(num[1]-len(minus))]
    plus_tmp = plus[(num[1]-len(minus)):]
rousoku = minus_tmp[(-(num[1]+1)):]
plus_tmp_2 = []
for i in plus_tmp:
    plus_tmp_2.append(i)
while(True):
    if(rousoku[1] - rousoku[0] >= (plus_tmp_2[0] - max(max(rousoku), 0)) * 2):
        rousoku.pop(0)
        rousoku.append(plus_tmp_2.pop(0))
    else:
        break
rousoku_move_minus = []
for i in rousoku:
    rousoku_move_minus.append(max(rousoku) * 2 - i)

print(min(max(rousoku_move_plus), max(rousoku_move_minus)))


### FIXED CODE ###

num = input().split(" ")
zahyou = input().split(" ")
zahyou_int = [int(i) for i in zahyou]
num[0] = int(num[0])
num[1] = int(num[1])

rousoku = []
flag = 1
time = 3 * 10 ** 8
for i in range(num[0]-num[1]+1):
    rousoku_min = zahyou_int[i]
    rousoku_max = zahyou_int[(i+num[1]-1)]
    if(flag == 0):
        break
    elif(rousoku_min > 0):
        flag = 0
    time_p = -min(0, rousoku_min) * 2 + rousoku_max
    time_m = max(0, rousoku_max) * 2 - rousoku_min
    if(min(time_p, time_m) < time):
        time = min(time_p, time_m)

print(time)
def add_node(tree, counter, ope, node, value):
    if node in ope:
        value += ope[node]
    counter[node - 1] += value

    if node in tree:
        for i in tree[node]:
            add_node(tree, counter, ope, i, value)


n, q = map(int, input().split())

tree = {}

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

ope = {}
for j in range(q):
    p, x = map(int, input().split())
    if p not in ope:
        ope[p] = x
    else:
        ope[p] += x

counter = [0] * n

# print(tree, ope)

# for k in ope:
add_node(tree, counter, ope, 1, 0)

print(*counter)



### FIXED CODE ###

# def add_node(tree, counter, ope, node, value):
#     if node in ope:
#         value += ope[node]
#     counter[node - 1] += value

#     if node in tree:
#         for i in tree[node]:
#             add_node(tree, counter, ope, i, value)


n, q = map(int, input().split())

tree = {}

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

ope = {}
for j in range(q):
    p, x = map(int, input().split())
    if p not in ope:
        ope[p] = x
    else:
        ope[p] += x

counter = [0] * n

# print(tree, ope)

# for k in ope:
for i in range(1, n + 1):
    if i in ope:
        counter[i - 1] += ope[i]
    if i in tree:
        for j in tree[i]:
            counter[j - 1] += counter[i - 1]
    
# add_node(tree, counter, ope, 1, 0)

print(*counter)
import bisect


n, k = map(int, input().split())
xs = list(map(int, input().split()))
index = bisect.bisect_right(xs, -1)

a = xs[:index][::-1]
cost = 0
if xs[index] == 0:
    cost += 1
    b = xs[index + 1:]
else:
    b = xs[index:]

cost_a = [0]
cost_b = [0]
for c in a:
    cost_a.append(abs(c))
for c in b:
    cost_b.append(c)

ret = float('inf')
if len(a) > k - cost:
    ret = min(ret, cost_a[k - cost])
if len(b) > k - cost:
    ret = min(ret, cost_b[k - cost])

for i in range(len(cost_a)):
    if 0 <= k - i < len(cost_b):
        ret = min(ret, 2 * cost_a[i] + cost_b[k - i])

for i in range(len(cost_b)):
    if 0 <= k - i < len(cost_a):
        ret = min(ret, 2 * cost_b[i] + cost_a[k - i])
print(ret)



### FIXED CODE ###

import bisect


n, k = map(int, input().split())
xs = list(map(int, input().split()))
index = bisect.bisect_right(xs, -1)

a = xs[:index][::-1]
cost = 0
if index < len(xs) and xs[index] == 0:
    cost += 1
    b = xs[index + 1:]
else:
    b = xs[index:]

cost_a = [0]
cost_b = [0]
for c in a:
    cost_a.append(abs(c))
for c in b:
    cost_b.append(c)

ret = float('inf')
if len(a) >= k - cost:
    ret = min(ret, cost_a[k - cost])
if len(b) >= k - cost:
    ret = min(ret, cost_b[k - cost])

for i in range(len(cost_a)):
    if 0 <= k - i < len(cost_b):
        ret = min(ret, 2 * cost_a[i] + cost_b[k - i])

for i in range(len(cost_b)):
    if 0 <= k - i < len(cost_a):
        ret = min(ret, 2 * cost_b[i] + cost_a[k - i])
print(ret)
n=int(input())
a=list(map(int,input().split()))
out = 0
for i in range(len(a)):
  if i > 0 :
  	for j in range(i):
  		if not (a[j] <= a[i]):
      		break
  out += 1
print(out)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
out = 0
for i in range(len(a)):
  flg = 1
  if i > 0 :
    for j in range(i):
      if not (a[j] <= a[i]):
        flg = 0
  if flg == 1:
    out += 1
print(out)
def check(pair,m,x):
  sum = 0
  
  for i in range(1,m):
    p = 0
    for e in pair:
      p += e[i]
    
    if(p < x):
      return -1
    
  for e in pair:
    sum += e[0]
  return sum
      
n,m,x = (int(x) for x in input().split())
a = []
for i in range(n):
  a.append(tuple([int(x) for x in input().split()]))
  
list = [] 
  
for i in range(2 ** n):
  pair = []
  for j in range(n):
    if((i >> j) & 1):
      pair.append(a[j])
      
  sum = check(pair,m,x)
  if(sum != -1):
    list.append(sum)
print(min(list))

### FIXED CODE ###

def check(pair,m,x):
  sum = 0
  
  for i in range(1,m+1):
    p= 0
    for e in pair:
      p += e[i]
    if(p < x):
      return -1
    
  for e in pair:
    sum += e[0]
  return sum
      
n,m,x = (int(x) for x in input().split())
a = []
for i in range(n):
  a.append(tuple([int(x) for x in input().split()]))
  
min = -1
  
for i in range(2 ** n):
  pair = []
  for j in range(n):
    if((i >> j) & 1):
      pair.append(a[j])
  sum = check(pair,m,x)
  
  if min == -1:
    min = sum
  elif sum != -1 and min > sum:
    min = sum
    
print(min)
import math
A,B,C,D = [int(i) for i in input().split()]

l= (C * D) // math.gcd(C, D)

s=B - A + 1 - ((B//C - (A-1)//C)+(B//D - (A-1)//D)-(B//l))
print(s)


### FIXED CODE ###

import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
abcd = input().split(" ")
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])
cd = lcm(c, d)
print(b-a-(b//c-((a-1)//c + 1))-(b//d - ((a-1)//d + 1))+(b//cd-((a-1)//cd + 1)))
yohou[] = input().split("")
tenki[] = input().split("")

tekichu = 0

for i in range(0,3):
  if yohou[i] == tenki[i]:
    tekichu += 1

print(tekichu)

### FIXED CODE ###

s = list(input())
t = list(input())

cnt = 0
for i in range(3):
  if s[i] == t[i]:
    cnt += 1

print(cnt)
#ABC067.B
N,K = map(int,input().split())
l = [map(int,input().split())]
l.sort()
L = l[(N-K):]
ans = sum(L)
print(ans)

### FIXED CODE ###

#ABC067.B
N,K = map(int,input().split())
l = list(map(int,input().split()))
l.sort()
L = l[(N-K):]
ans = sum(L)
print(ans)
K, S = map(int, input().split())

count = 0
for x in range(K+1):
    if S-x<=2*K:
        for y in range(K+1):
            if S-x-y<=K:
                cout += S-x-y+1
#                 for z in range(K+1):
#                     if x+y+z==S:
#                         count += 1
print(count)

### FIXED CODE ###

K, S = map(int, input().split())

count = 0
for x in range(K+1):
    if S-x<=2*K and S-x>=0:
        for y in range(K+1):
            if S-x-y<=K and S-x-y>=0:
                count += 1
#                 for z in range(K+1):
#                     if x+y+z==S:
#                         count += 1
print(count)
n, k, d = map(int, input().split())
n = abs(n)
ok = n // d
left = k - (ok)
if left % 2:
  print(d - (n%d))
  else:
    print(n%d)

### FIXED CODE ###

n, k, d = map(int, input().split())
n = abs(n)
ok = n // d
if k < ok:
  print(n - (k*d))
else:
  left = k - (ok)
  if left % 2:
  	print(d - (n%d))
  else:
    print(n%d)
s,t=input().split()
a,b=map(int,input()split())
u=input()
if u==s:
    a-=
elif:b-=
print(a, b)

### FIXED CODE ###

s, t = input().split()
a, b = map(int, input().split())
u = input()
if u == s:
    a-= 1
else: b -= 1
print(a, b)
nb = raw_input().split(' ')

a, b = int(nb[0],16), int(nb[1], 16)
if a > b:
    print '>'
elif a < b:
    print '<'
else:
    print '='

### FIXED CODE ###

nb = input().split(' ')

a, b = int(nb[0],16), int(nb[1], 16)
if a > b:
    print ('>')
elif a < b:
    print ('<')
else:
    print ('=')
n = int(input())
for i in range(9):
    if 111*i >= n:
        result = i
        break

print(result*111)


### FIXED CODE ###

n = int(input())
for i in range(9):
    if 111*(i+1) >= n:
        print(111*(i+1))
        break
n,m = map(int,input().split())
if m == 0:
    if n == 1:
        print(0)
        exit()
    else:
        print(-1)
        exit()

lists = [list(map(int,input().split())) for i in range(m)]
keta = ["0"]*n
Max = -999999
Min = 99999999
tmp = lists[0][0]
for i,j in lists:
    keta[i-1] = str(j)
    Max = max(i,Max)
    num = "".join(keta)
    ans = int(num)
    if tmp == i:
        Min = min(ans,Min)
        keta = list(str(Min))
    else:
        Min = ans
if len(str(Min)) == n:
    print(Min)
else:
    print(-1)




### FIXED CODE ###


n,m = map(int,input().split())
lists = [list(map(int,input().split())) for i in range(m)]
for i in range((10**3) + 1):
    num = str(i)
    flag = True
    if len(num) == n:
        for s,c in lists:
            if num[s-1] != str(c):
                flag = False
        if flag:
            print(num)
            exit()
print(-1)
n = int(input())
A = map(int, input().split())

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

X = [0] * (n + 1)
Y = [0] * (n + 1)

for i in range(n):
  X[i+1] = gcd(X[i], A[i])
  Y[n-1-i] = gcd(Y[n-i], A[n-1-i])

gcds = []

for i in range(n+1):
  gcds.append(gcd(X[i], Y[i+1]))

print(max(gcds))

### FIXED CODE ###

# coding: utf-8

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

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

L = [0]
R = [0]

for i in range(n):
    L.append(gcd(L[i], A[i]))
    R.append(gcd(R[i], A[n-1-i]))
R.reverse()

result = []

for i in range(n):
    result.append(gcd(L[i], R[i+1])) 

print(max(result))
S=input()
K=int(input())
A=[]
D=1
for i in range(len(S)-2):
  if S[i]==S[i+1]:
    D+=1
  else:
    A.append(D)
    D=1
A.append(D)
B=[i for i in A if not i==1]
C=[(i//2) for i in B]
count=(sum(C)*K)

if S[0]==S[-1]:
  count+= (K-1)
if S[-1]==S[-2]:
  count+=1
  
print(count)

### FIXED CODE ###

S=input()
K=int(input())
T=S+S
if len(set(S))!=1:
  A=[]
  D=1
  for i in range(len(S)-1):
    if S[i]==S[i+1]:
      D+=1
    else:
      A.append(D)
      D=1
  A.append(D)
  B=[i for i in A if not i==1]
  C=[(i//2) for i in B]
  Scount=(sum(C))

  E=[]
  H=1
  for j in range(len(T)-1):
    if T[j]==T[j+1]:
      H+=1
    else:
      E.append(H)
      H=1
  E.append(H)
  F=[j for j in E if not j==1]
  G=[(j//2) for j in F]
  Tcount=(sum(G))
  ans=(Tcount-Scount)*(K-1)+Scount
  print(ans)
else:
  print(K*len(S)//2)
from collections import deque
def LI():
  return list(map(int,input().split()))

N,M,K = map(int,input().split())
A = deque(LI())
B = deque(LI())
res = 0

while K >= 0:
  if len(A) == 0:
    if K >= B[0]:
      b = B.popleft()
      K -= b
    else:
      break
  elif len(B) == 0:
    if K>=A[0]:
      a = A.popleft()
      K -= a
    else:
      break
  else:
    if A[0] > B[0]:
      b = B.popleft()
      K -= b
    elif A[0] < B[0]:
      a = A.popleft()
      K -= a
    else:
      if A[1] > B[1]:
        b = B.popleft()
        K -= b
      else:
        a = A.popleft()
        K -= a

  if K >= 0:
    res += 1
  else:
    break

  if len(A) == 0 and len(B) == 0:
    break


print(res)

### FIXED CODE ###

import bisect
def LI():
  return list(map(int,input().split()))

N,M,K = map(int,input().split())
A = LI()
B = LI()

cumA = [0]
for a in A:
  cumA.append(cumA[-1]+a)

cumB = [0]
for b in B:
  cumB.append(cumB[-1]+b)

res = 0
for i in range(N+1):
  cuma = cumA[i]
  if cuma > K: continue
  rem = K-cuma
  deskb = bisect.bisect_right(cumB, rem)-1

  res = max(res, i+deskb)

print(res)
from math import gcd
from functools import reduce

n, x = map(int,input().split())
City = list(map(int, input().split()))
Distance = [0] * n

for i in range(n):
    Distance[i] = abs(City[i]-x)

ans = reduce(gcd, Distance)

print(ans)


### FIXED CODE ###

n, x = map(int,input().split())
City = list(map(int, input().split()))
Distance = [0] * n

for i in range(n):
    Distance[i] = abs(City[i]-x)

Distance.sort()
ans = Distance[0]

def gcd(a,b):
    if a < b:
        a,b = b,a
    while a % b != 0:
        a, b = b, a % b
    return b

for i in range(1,n):
    ans = gcd(ans, Distance[i])

print(ans)
import math
x=int(input())
x=180-x

ans=360//math.gcd(360,x)

if(ans>=5):
    print(1//0)
else:
    print(ans)

#for i in range(1,180):
#    print(i,"°",360//math.gcd(360,i))
#    if(i==x):
#        print("問題の箇所",x,ans)

### FIXED CODE ###

import math
x=int(input())
x=180-x

ans=360//math.gcd(360,x)

ex=[60,120]

if(x in ex):
    x=180-x
    ans=360//math.gcd(360,x)
print(ans)
#for i in range(1,180):
#    if(360//math.gcd(360,i)==6):
#        print(i,360//math.gcd(360,i))
#    if(i==x):
        #print("問題の箇所",x,ans)
def solve():
    N, K = map(int, input().split())
    L = [int(i) for i in input().split()]
    L.sort(reversed = True)
    print(sum(L[:K]))


if __name__ == "__main__":
    solve()

### FIXED CODE ###

N, K = map(int, input().split())
L = [int(l) for l in input().split()]
L.sort(reverse = True)
print(sum(L[:K]))
s = raw_input()
print(s.count("+") - s.count("-"))

### FIXED CODE ###

s = raw_input()
print (s.count("+") - s.count("-"))
def decide_H(Cx,Cy,x,y,h):
    H=h+abs(x-Cx)+abs(y-Cy)
    if h>=1:
        return(H)
 
def check_H(Cx,Cy,H):
    for x,y,h in T:
        if h != max(H - abs(x - Cx) - abs(y - Cy), 0):
            return False
    return True
 
N=int(input())
T=[[int(i) for i in input().split()] for _ in range(N)]
 
for Cx in range(101):
    for Cy in range(101):
        for x,y,h in T:
            H=decide_H(Cx,Cy,x,y,h)
            if check_H(Cx,Cy,H):
                print(Cx,Cy,H)
                exit()
            else:
                break

### FIXED CODE ###

def get_H(Cx, Cy):
    for x, y, h in L:
        if h > 0:
            return abs(x - Cx) + abs(y - Cy) + h


def check_H(Cx, Cy, H):
    for x, y, h in L:
        if h != max(H - abs(x - Cx) - abs(y - Cy), 0):
            return False
    return True


N = int(input())

L = [(list(map(int, input().split()))) for _ in range(N)]

for Cx in range(101):
    for Cy in range(101):
        H = get_H(Cx, Cy)
        if check_H(Cx, Cy, H):
            print('{} {} {}'.format(Cx, Cy, H))
            exit(0)