Harryxun/stf_run huggingface dataset:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left

def solve():
    # n, m = [int(x) for x in input().split()]
    s = [x for x in input()]
    a = s[:]
    k = int(input())
    if len(s) == 1:
        print(k // 2)
        return
    if len(set(s)) == 1:
        print((len(s) * k)//2)
        return
    cnt = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s[i] = '.'
            cnt += 1

    cnt *= k
    
    if s[0] == s[-1] and s[0] != '.':
        cnt += (k - 1)

    print(min(cnt,ans))


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left

def solve():
    # n, m = [int(x) for x in input().split()]
    s = [x for x in input()]
    k = int(input())
    n = len(s)
    if len(set(s)) == 1:
        print(n*k//2)
        return
    b = [1]
    for i in range(1, n):
        if s[i] == s[i-1]:
            b[-1] += 1
        else:
            b.append(1)
    ans = 0
    for e in b:
        ans += e // 2 * k

    if s[0] == s[-1] and b[0] % 2 and b[-1] % 2:
        ans += k-1
    
    print(ans)


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""
n,x=map(int,input().split())
s="P"
for _ in range(n):
    s='B'+s+'P'+s+'B'
print(s[-1*x:].count('P'))

### FIXED CODE ###

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


b=[1]
p=[1]
for i in range(n):
    b.append(2*b[-1]+3)
    p.append(2*p[-1]+1)

def f(N,X):
    if N==0:
        return 0 if X<=0 else 1
    elif X==1:
        return 0
    elif 1<X and X<=b[N-1]+1:
        return f(N-1,X-1)
    elif X==b[N-1]+2:
        return p[N-1]+1
    else:
        return p[N-1]+1+f(N-1,X-2-b[N-1])

print(f(n,x))
a, b = map(int, input().split())

print(a*b, 2a+2b)


### FIXED CODE ###

a, b = map(int, input().split())
print(a*b, 2*a+2*b)
S = input().sprint("/")

if int(S[5]) < 5 :
	print('Heisei')
else :
	print('TBD')

### FIXED CODE ###

s = input()

if s <= "2019/04/30":
    print("Heisei")
else:
    print("TBD")
from string import*;from itertools import*;b=ascii_lowercase;r=s=input();d=l=len(s);t=s[::-1]
if l>25:d=-[p*len(list(k))for p,k in groupby([i<j for i,j in zip(s[::-1],s[-2::-1])])][0]-2;s,b,o=s[:d],s[d+1:],1
print(-(d<-26)or s+sorted(set(b)-set([s,b[:ord(s[d])-97]][o]))[0])

### FIXED CODE ###

#!/usr/bin/env python3
from string import*
from itertools import*
b = ascii_lowercase
s = input()
l = len(s)
if l < 26:
    print(s + sorted(set(b) - set(s))[0])
else:
    t = s[::-1]
    a = [(p, len(list(k))) for p, k in groupby([i < j for i, j in zip(t, t[1:])])][0]
    d = - a[0]*a[1] - 2
    print(-(d < -26) or s[:d] + sorted(set(s[d+1:]) - set(b[:ord(s[d]) - 97]))[0])
N,W = map(int, input().split())
dp = [0]*(W+1)
for i in range(N):
	a,b = map(int,input().split())
	for j in range(b,W+1,b):
		x = a + dp[j-b]
		if x >= dp[j]:
			dp = x

print(W+1)



### FIXED CODE ###

N,W = map(int, input().split())
dp = [0 for i in range(W+1)]
for i in range(N):
	a,b = map(int,input().split())
	for j in range(b,W+1):
		x = a + dp[j-b]
		if x >= dp[j]:
			dp[j] = x

print(max(dp))
x=int(input())
for i in range(-200,200):
  for j in range(-200,200):
    if i**5-j**5==x:
      prtin(i,j)
      exit()


### FIXED CODE ###

x=int(input())
for i in range(-200,200):
  for j in range(-200,200):
    if i**5-j**5==x:
      print(i,j)
      exit()
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def prime_decomposition(n):
  i = 2
  d = {}
  while i * i <= n:
    while n % i == 0:
      n /= i
      if i not in d:
          d[i] = 0
      d[i] += 1
    i += 1
  if n > 1:
    if n not in d:
        d[n] = 1
  return d

def eratosthenes(n):
    prime = []
    limit = n**0.5
    numbers = [i for i in range(2,n+1)]
    while True:
        p = numbers[0]
        if limit <= p:
            return prime + numbers
        prime.append(p)
        numbers = [i for i in numbers if i%p != 0]
    return prime

N = int(input())
A = [int(input()) for i in range(N+1)]
g = A[0]
for a in A:
     g = gcd(g,a)
d = prime_decomposition(g)
ans = [p for p in d]

prime = eratosthenes(N+2)
A.reverse()
for p in prime:
    if A[0]%p != 0:
        continue
    for n in range(1,p):
        s = 0
        for k in range(int((N-n)/(p-1))+1):
            s += A[n+k*(p-1)]
            s %= p
        if s != 0:
            break
    if s == 0:
        ans.append(p)

ans = list(set(ans))
ans.sort()

for p in ans:
    print(p)

### FIXED CODE ###

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def prime_decomposition(n):
  i = 2
  d = {}
  while i * i <= n:
    while n % i == 0:
      n //= i
      if i not in d:
          d[i] = 0
      d[i] += 1
    i += 1
  if n > 1:
    if n not in d:
        d[n] = 1
  return d

def eratosthenes(n):
    if n < 2:
        return []
    prime = []
    limit = n**0.5
    numbers = [i for i in range(2,n+1)]
    while True:
        p = numbers[0]
        if limit <= p:
            return prime + numbers
        prime.append(p)
        numbers = [i for i in numbers if i%p != 0]
    return prime

def ok(p):
    if A[0]%p != 0:
        return False
    B = [A[i]%p for i in range(1,N+1)]
    mod = [0]*(p-1)
    for i in range(N):
        mod[i%(p-1)] += B[i]
        mod[i%(p-1)] %= p
    return sum(mod)==0

N = int(input())
A = [int(input()) for i in range(N+1)][::-1]
g = abs(A[0])
for a in A:
     g = gcd(g,abs(a))
d = prime_decomposition(g)
ans = [p for p in d]

prime = eratosthenes(N+1)

for p in prime:
    if ok(p):
        ans.append(p)

ans = list(set(ans))
ans.sort()

for p in ans:
    print(p)
N,K = map(int,input().split())
h = list(map(int,input().split()))
h.sort(reverse = True)
l = [0]*(N-(K-1))
for i in range(N-(K-1)):
  l[i] = h[i]-h[i+K-1]
ans = min(l)
print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
h = [int(input()) for i in range(N)]
h.sort(reverse = True)
l = [0]*(N-(K-1))
for i in range(N-(K-1)):
  l[i] = h[i]-h[i+K-1]
ans = min(l)
print(ans)
a = int(input())
b = int(input())
 
ab = a*b
if ab%2 == 0:
  print("Even")
else:
  print("Odd")

### FIXED CODE ###

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

if a*b%2 == 0:
  print("Even")
else:
  print("Odd")
import sys
N,Y = map(int,input().split(" "))

man_max = Y//10000

go_max = Y // 5000

sen_max = Y // 1000

if man_max > N:
    man_max = N
if go_max > N:
    go_max = N
if sen_max > N:
    sen_max = N


if Y%10000 == 0 and Y//10000 ==N:
     print(str(N) + " " +"0 0")
     sys.exit()
if Y%5000 == 0 and Y//5000 ==N:
     print("0 " + str(N) +" 0")
     sys.exit()
if Y%1000 == 0 and Y//1000 ==N:
     print("0 0 " + str(N))
     sys.exit()

for k in range(man_max+1):
    for j in range(go_max+1):
        for i in range(sen_max+1):
            if (10000*k + 5000*j + 1000*i == Y):
                if i+j+k == N:
                    print(str(k)+" "+str(j) + " " + str(i))
                    sys.exit()
            elif(10000*k + 5000*j + 1000*i > Y):


print("-1 -1 -1")

### FIXED CODE ###

import sys
N,Y = map(int,input().split(" "))

man_max = Y//10000

go_max = Y // 5000

sen_max = Y // 1000


for i in range(N,-1,-1):
    for j in range (N-i+1):
        if 10000*i +5000*j +1000*(N-(i+j)) == Y: 
            print(str(i)+" "+str(j) + " " + str(N-(i+j)))
            sys.exit()
print("-1 -1 -1")
N = int(input())

xy = [map(int,input().split()) for _ in range(N)]
x,y = [list(i) for i in zip(*xy)]

ans = 0

for i in range(N):
    if x[i] == y[i]:
        ans +=1
    elif ans >= 3:
        flag = True
        ans = 0
    else:
        ans = 0
        
if ans >= 3 or flag ==True:
    print("Yes")
    
else:
    print("No")

### FIXED CODE ###

N = int(input())

xy = [map(int,input().split()) for _ in range(N)]
x,y = [list(i) for i in zip(*xy)]

ans = 0
flag = False

for i in range(N):
    if x[i] == y[i]:
        ans +=1
    elif ans >= 3:
        flag = True
        ans = 0
    else:
        ans = 0
        
if ans >= 3  or flag ==True:
    print("Yes")
    
else:
    print("No")
#デフォルト
import itertools
from collections import defaultdict
import collections
import math
import sys
sys.setrecursionlimit(200000)
mod = 1000000007

t = list(input())

for i in range(len(t)):
    if (t[i] == '?' and i == 0):
        if t[i + 1] == 'D':
            print("P", end="")
        else:
            print("D", end="")
    elif (t[i] == "?"):
        if t[i - 1] == "D":
            print("P",end="")
        else:
            print("D", end="")
    else:
        print(t[i],end="")


### FIXED CODE ###

#デフォルト
import itertools
from collections import defaultdict
import collections
import math
import sys
sys.setrecursionlimit(200000)
mod = 1000000007

t = list(input())

for i in range(len(t)):
    if (t[i] == "?"):
        print("D",end="")
    else:
        print(t[i],end="")
n = input()
a = n / 1.08
if float(n%1.08) ==0:
      x = int(a)
else:
      x = int(a) + 1
v = int(x * 1.08)
print(x,v,n)
if v == n:
  print(x)
else:
  print(":(")


### FIXED CODE ###

n=int(input())
a = n / 1.08
if a-int(a) == 0.00:
      x = int(a)
else:
      x = int(a) + 1
v = int(x * 1.08)
if v == n:
  print(x)
else:
  print(":(")
a,b,c=list(input().split())
print(a[0]+b[1]+c[2])

### FIXED CODE ###

a,b,c=[input() for i in range(3)]
print(a[0]+b[1]+c[2])
from copy import copy
N=10
K=4
p=list(map(int, input().split()))
expP = [(1+i)/2 for i in p]
id_H = N-K
id_T = N
minus = sum(expP[:id_H])
minimum = minus
for i in range(id_H):
    minus -= expP[id_H - i -1]
    minus += expP[id_T - i -1]
    if minus < minimum:
        minimum = copy(minus)
ans = sum(expP) - minimum
print(ans)

### FIXED CODE ###

from copy import copy
N,K = map(int, input().split())
p=list(map(int, input().split()))
expP = [(1+i)/2 for i in p]
id_H = N-K
id_T = N
minus = sum(expP[:id_H])
minimum = minus
for i in range(id_H):
    minus -= expP[id_H - i -1]
    minus += expP[id_T - i -1]
    if minus < minimum:
        minimum = copy(minus)
ans = sum(expP) - minimum
print(ans)
import numpy as np
n = int(input())
H = np.array([list(map(int, input().split())) for _ in range(n)], dtype = np.int)
dp = np.zeros((n, 3), dtype = np.int)
dp[0] = H[0]
def except_ind(num):
    ind = np.ones((3, ), dtype = bool)
    ind[num] = False
    return ind
for i in range(1, n):
    for j in range(3):
        dp[i][j] = np.max(dp[i - 1][except_ind(j)]) + H[i][j]
print(np.max(dp[n - 1]))

### FIXED CODE ###

n = int(input())
H = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * 3 for _ in range(n)]
dp[0] = H[0]
for i in range(1, n):
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + H[i][0]
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + H[i][1]
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + H[i][2]
print(max(dp[n - 1]))
a = input()
b = input()

print(a*b)

### FIXED CODE ###

a , b = (input().split(' '))
a = int(a)
b = int(b)
print(a*b)
a = input().split()
if a[0] == a[1] == a[2]:
  print('No')
else:
  print('Yes')

### FIXED CODE ###

a = input()
if a[0] == a[1] and a[1] == a[2]:
  print('No')
else:
  print('Yes')
s = input()

N = len(s)

i = 0
result = 0
count_a = 0
count_bc = 0

while i < N-2:
    if s[i] == 'A':
        while s[i] == 'A':
            count_a += 1
            i += 1
        
        if i >= N-1:
            break
        
        if s[i] == 'B' and s[i+1] == 'C':
            result += count_a - 1
        
        count_a = 0
        
        while s[i] == 'B' and s[i+1] == 'C':
            count_bc += 1
            i += 2
            if i >= N-1:
                break
            if s[i] == 'A':
                count_a = 1
        
        result += count_bc
        count_bc = 0
            
        if i >= N -1:
            break
        
    else:
        i += 1
        
print(result)    

### FIXED CODE ###

s = input()

N = len(s)

i = 0
result = 0
count_a = 0
count_bc = 0

while i < N-2:
    if s[i] == 'A':
        while s[i] == 'A' and i < N-2:
            count_a += 1
            i += 1
        
        if i >= N-1:
            break
                        
        while s[i] == 'B' and s[i+1] == 'C':
            count_bc += 1
            i += 2
            if i >= N-1:
                break
        
        result += count_a * count_bc

        if i >= N-1:
            break
        
        if count_bc > 0 and s[i] == 'A':
            count_a = count_a
        else:
            count_a = 0
        
        count_bc = 0
                    
    else:
        i += 1
        
print(result)
S = input('天気が雨である日が連続していた最大の日数を出力せよ。')
if S == 'SSS'
	print(0)
else if S == 'SSR'
	print(1)
else if S == 'SRR'
	print(2)
else if S == 'SRS'
	print(1)
else if S == 'RSS'
	print(1)
else if S == 'RRS'
	print(2)
else if S == 'RRR'
	print(3)
else if S == 'RRS'
	print(2)


### FIXED CODE ###

S = input()
if S == 'SSS':
  print(0)
elif S == 'SRR':
  print(2)
elif S == 'RRS':
  print(2)
elif S == 'RRR':
  print(3)
else:
  print(1)
n=int(input())
a=[int(input()) for i in range(n)]

maxa = max(a[0],a[1])
mina = min(a[0],a[1])

for i in range(2,n):
    if a[i] >= maxa:
        mina = maxa
        maxa = a[i]
    elif a[i] >mina:
        mina = a[i]

for i in range(n):
    if a[i] == maxa:
        print(mina)
    else:
        print(maxa)
å


### FIXED CODE ###

n=int(input())
a=[int(input()) for i in range(n)]

maxa = max(a[0],a[1])
mina = min(a[0],a[1])

for i in range(2,n):
    if a[i] >= maxa:
        mina = maxa
        maxa = a[i]
    elif a[i] >mina:
        mina = a[i]

for i in range(n):
    if a[i] == maxa:
        print(mina)
    else:
        print(maxa)
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip()
    x,y = map(int, input().split())
    f = s.split('T')
    dx_list = list(map(len, f[::2]))
    dy_list = list(map(len, f[1::2]))
    
    nx = dx.pop(0)
    ny = 0

    dx_list.sort(reverse=True)
    dy_list.sort(reverse=True)

    for dx in dx_list:
        if x >= nx:
            nx += dx
        else:
            nx -= dx
    for dy in dy_list:
        if x >= nx:
            nx += dy
        else:
            nx -= dy

    if nx == x and ny == y:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip() + 'T'
    x,y = map(int, input().split())
    # 奇数はy方向, 偶数はx方向
    l = []
    susumu = 0
    for i in range(len(s)):
        if s[i] == 'T':
            l.append(susumu)
            susumu = 0
        else:
            susumu += 1
    b = len(l)
    dp = [[0]*16001 for _ in range(3)]
    dp[0][8000] = 1
    dp[1][8000] = 1
    for i in range(b):
        if i==0:
            dp[2][8000+l[i]] = 1
        elif i%2 == 0:
            for j in range(16000):
                if dp[0][j]:
                    dp[2][j-l[i]] = 1
                    dp[2][j+l[i]] = 1
        elif i%2 == 1:
            for j in range(16000):
                if dp[0][j]:
                    dp[2][j-l[i]] = 1
                    dp[2][j+l[i]] = 1
        dp = dp[1:] + [[0]*16000]
    if b%2 == 0:
        if dp[0][x+8000] == 1 and dp[1][y+8000] == 1:
            print('Yes')
        else:
            print('No')
    else:
        if dp[1][x+8000] == 1 and dp[0][y+8000] == 1:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()
from collections import deque

mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

N,M = MI()
links = [[] for _ in range(N)]

for _ in range(M):
    a, b = MI()
    a -= 1
    b -= 1
    links[a].append(b)
    links[b].append(a)

ans = [-1] * N
ans[0] = 0
q = deque([(0, 0)])
while q:
    room, prev = q.popleft()
    for next_ in links[room]:
        if ans[next_] < 0:
            ans[next_] = ans[room+1]+1
            q.append((next_, room))
for i in range(1,N):
  print(ans[i])

### FIXED CODE ###

from collections import deque

mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

N,M = MI()
links = [[] for _ in range(N)]

for _ in range(M):
    a, b = MI()
    a -= 1
    b -= 1
    links[a].append(b)
    links[b].append(a)

ans = [-1] * N
ans[0] = 0
q = deque([(0, 0)])
while q:
  room, prev = q.popleft()
  for next_ in links[room]:
    if ans[next_] < 0:
      ans[next_] = room+1
      q.append((next_, room))
print("Yes")
for i in range(1,N):
  print(ans[i])
n = int(input())
*A, = map(int, input().split())
maxA = max(A)
# C[a] = A内のaの個数
C = {}
for a in A:
    try:
        C[a] += 1
    except KeyError:
        C[a] = 1
# D[a]=1: Aにaより小さいaの約数が存在する
D = {}
for a in A:
    if C[a] > 0:
        tmp = 2
        while a * tmp <= maxA:
            D[a * tmp] = 1
            tmp += 1
ans = 0
for a in A:
    if C[a] == 1 and D[a] == 0:
        ans += 1
print(ans)


### FIXED CODE ###

n = int(input())
*A, = map(int, input().split())
maxA = max(A)
# C[a] = A内のaの個数
C = {a: 0 for a in range(1, maxA + 1)}
for a in A:
    C[a] += 1
# D[a]=1: Aにaより小さいaの約数が存在する
D = {a: 0 for a in range(1, maxA + 1)}
for a in A:
    if C[a] > 0:
        tmp = 2
        while a * tmp <= maxA:
            D[a * tmp] = 1
            tmp += 1
ans = 0
for a in A:
    if C[a] == 1 and D[a] == 0:
        ans += 1
print(ans)
#!/usr/bin/env python3

n, k = map(int, input().split())
D = list(map(int, input().split()))

paid = n
while True:
    st = set(int(x) for x in str(paid))
    l = len(st)
    if len([x for x in st if x not in D]) == l:
        print(paid)
        break
    paid += 1

### FIXED CODE ###

#!/usr/bin/env python3

import sys
  
if sorted(sys.stdin.readline().split()) == ['5', '5', '7']:
  print('YES')
else:
  print('NO')
a,b=input.split()

### FIXED CODE ###

x = int(input())
print(x*x*x)
import heapq
N = int(input())
A = list(map(int,input().split()))
B1 = []
for i in range(N):
    heapq.heappush(B1,(A[i],i))
C = []
for i in range(N,3*N):
    heapq.heappush(C,(A[i],i))
B2 = []
for _ in range(N):
    a,i = heapq.heappop(C)
    B2.append((-a,i))
dmax = 0
for i in range(N):
    dmax += B1[i][0]+B2[i][0]
C = []
for i in range(N,2*N):
    heapq.heappush(C,(A[i],i))
d = dmax
for i in range(N,2*N):
    a = A[i]
    if B1[0][0]<a:
        d += a-B1[0][0]
        heapq.heappop(B1)
        heapq.heappush(B1,(a,i))
    while C[0][1]<=i:
        heapq.heappop(C)
    while B2 and B2[0][1]<=i:
        b,i = heapq.heappop(B2)
        b = -b
        d += b
        a,i = heapq.heappop(C)
        heapq.heappush(B2,(-a,i))
        d -= a
    dmax = max(dmax,d)
print(dmax)        

### FIXED CODE ###

import heapq
N = int(input())
A = list(map(int,input().split()))
B1 = []
for i in range(N):
    heapq.heappush(B1,(A[i],i))
C = []
for i in range(N,3*N):
    heapq.heappush(C,(A[i],i))
B2 = []
for _ in range(N):
    a,i = heapq.heappop(C)
    heapq.heappush(B2,(i,a))
dmax = 0
for i in range(N):
    dmax += B1[i][0]-B2[i][1]
d = dmax
for i in range(N,2*N):
    a = A[i]
    if B1[0][0]<a:
        d += a-B1[0][0]
        heapq.heappop(B1)
        heapq.heappush(B1,(a,i))
    while C and B2[0][0]<=i:
        _,b = heapq.heappop(B2)
        d += b
        a,j = heapq.heappop(C)
        heapq.heappush(B2,(j,a))
        d -= a
    dmax = max(dmax,d)
print(dmax)
if __name__ == '__main__':
    a = [int(i) for i in input().split()]
    n = int(input())
    a.sort()
    a[2] = a[2]*(2**n)
    print(su

### FIXED CODE ###

if __name__ == '__main__':
    a = [int(i) for i in input().split()]
    n = int(input())
    a.sort()
    a[2] = a[2]*(2**n)
    print(sum(a))
#!/usr/bin/env python3
import sys
from itertools import *
from operator import itemgetter

def solve(N: int, M: int, P: "List[int]", Y: "List[int]"):
    sorted_list = [(P[i], Y[i]) for i in range(M)]
    sorted_list.sort()

    group_list = dict((key, list(map(lambda x: x[1], items))) for key, items in groupby(sorted_list, key = itemgetter(0)))
    for i in range(N + 1):
        key = P[i]
        rank = group_list[P[i]].index(Y[i]) + 1
        print('{0:06d}'.format(key, rank) + '{0:06d}'.format(rank))

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    P = [int()] * (M)  # type: "List[int]"
    Y = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        P[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    solve(N, M, P, Y)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

dic = {}

def list_sort(x):
    values = dic[x]
    values.sort()

    return {x: values}

def solve(N: int, M: int, P: "List[int]", Y: "List[int]"):
    for i in range(N):
        dic[i + 1] = []
    
    for i in range(M):
        dic[P[i]].append(Y[i])

    sorted_dic = {}
    for key in dic.keys():
        tmp = {}
        values = dic[key]

        values.sort()
        for i in range(len(values)):
            tmp[values[i]] = i + 1

        sorted_dic[key] = tmp


    for m in range(M):
        key = P[m]
        value = Y[m]
        sorted_ranked_dic = sorted_dic[key]
        rank = sorted_ranked_dic[value]

        print('{0:06d}'.format(key, rank) + '{0:06d}'.format(rank))



    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    P = [int()] * (M)  # type: "List[int]"
    Y = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        P[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    solve(N, M, P, Y)

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

pattern_even=(N-1)*N/2
pattern_odd=(M-1)*M/2

return (pattern_even+pattern_odd)

### FIXED CODE ###

N,M=map(int,input().split())

pattern_o=(N-1)*N/2
pattern_e=(M-1)*M/2

print(int(pattern_o+pattern_e))