qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
S = input()
ans = 0
a = []
up = True
count = 0
for i in S:
    if up:
        if i == '>':
            a.append(count)
            count = 1
            up = False
        else:
            count += 1
    else:
        if i == '<':
            a.append(count)
            count = 1
            up = True
        else:
            count += 1
a.append(count)
a.append(0)
for i in range(0,len(a),2):
    u,d = max(a[i],a[i+1]), min(a[i],a[i+1])-1
    ans += u*(u+1)//2 + d*(d+1)//2
print(ans)
    

# Fixed code:
S = input()
ans = 0
a = []
up = True
count = 0
for i in S:
    if up:
        if i == '>':
            a.append(count)
            count = 1
            up = False
        else:
            count += 1
    else:
        if i == '<':
            a.append(count)
            count = 1
            up = True
        else:
            count += 1
a.append(count)
if len(a)%2 == 1:
    a.append(0)
for i in range(0,len(a),2):
    u,d = max(a[i],a[i+1]), min(a[i],a[i+1])-1
    ans += u*(u+1)//2 + d*(d+1)//2
print(ans)
# Buggy code:
S = input()

ans = [0] * (len(S) + 1)
for i in range(len(S)):
    if S[i] == '<':
        ans[i + 1] = ans[i] + 1

print(ans)

for i in range(len(S)-1, -1, -1):
    if S[i] == '>':
        ans[i] = max(ans[i + 1] + 1, ans[i])
print(ans)
print(sum(ans))


# Fixed code:
S = input()

ans = [0] * (len(S) + 1)
for i in range(len(S)):
    if S[i] == '<':
        ans[i + 1] = ans[i] + 1

for i in range(len(S)-1, -1, -1):
    if S[i] == '>':
        ans[i] = max(ans[i + 1] + 1, ans[i])
print(sum(ans))
# Buggy code:
input = int(input())
for i in range(1, 10):
  for j in range(1, 10):
    if i*j==input:
      print("Yes")
    else:
      print("No")

# Fixed code:
input = int(input())
for i in range(1, 10):
  for j in range(1, 10):
    if i*j==input:
      print("Yes")
      exit()
    else:
      continue
print("No")
# Buggy code:
N=int(input())
list=[]
for i in range(1:10):
  for j in range(1:10):
    list.append(i*j)
if N in list:
   print("Yes")
 else:
   print("No")
    

# Fixed code:
N = int(input())
list = []
for i in range(1,10):
  for j in range(i,10):
    list.append(i*j)
if N in list:
  print('Yes')
else:
  print('No')
# Buggy code:
def solve():
    N = int(input())
    flag = False

    for i in range(9):
        for j in range(9):
            if((i+1)+(j+1) == N):
                print("Yes")
                flag = True
        if flag:
            break
    else:
        print("No")


if __name__ == "__main__":
    solve()

# Fixed code:
def solve():
    N = int(input())
    flag = False

    for i in range(9):
        for j in range(9):
            if((i+1)*(j+1) == N):
                print("Yes")
                flag = True
        if flag:
            break
    else:
        print("No")


if __name__ == "__main__":
    solve()
# Buggy code:
n=int(input())
for i in range(0,9):
  if n%i==0 and n/i>=1 and n/i<=9:
    print("Yes")
    break
else:
  print("No")


# Fixed code:
n=int(input())
for i in range(1,10):
  if n%i==0:
    if n/i>=1 and n/i<=9:
      print("Yes")
      break
else:
  print("No")
# Buggy code:
n=int(input())
for i in range(1,9):
  for j in range(9):
    if i*j==n:
      a+=1
if a>0:
  print("Yes")
else:
  print("No")

# Fixed code:
n=int(input())
a=0
for i in range(1,10):
  for j in range(1,10):
    if i*j==n:
      a+=1
if a>0:
  print("Yes")
else:
  print("No")
# Buggy code:
n = int(input())
flag = false
for i in range(1,10):
  if n%i == 0 and 0 < n/i < 10:
    flag = True
    break
if flag:
  print("Yes")
else
  print("No")

# Fixed code:
n = int(input())
flag = False
for i in range(1,10):
  if n%i == 0 and 0 < n/i < 10:
    flag = True
    break
if flag:
  print("Yes")
else:
  print("No")
# Buggy code:
n=input(n)
t=False

for i in range(1,10):
  for j in range(1,10):
    if i*j==n:
      t=True
      break
if t:
  print('Yes')
else:
  print('No')


# Fixed code:
n=int(input())
t=False

for i in range(1,10):
  for j in range(1,10):
    if i*j==n:
      t=True
      break
if t:
  print('Yes')
else:
  print('No')
# Buggy code:
import sys
n=int(input())
for j in range(2):
    for i in range(1,10):
        if n%(10-i)==0:
            n=n/(10-i)
            sys.exit()
if n==1:
    print('Yes')
else:
    print('No')

# Fixed code:
import sys
n=int(input())
for j in range(2):
    for i in range(1,10):
        if n%(10-i)==0:
            n=n/(10-i)
            break
if n==1:
    print('Yes')
else:
    print('No')
# Buggy code:
n = int(input())
bl = 0
for i in range(1,9):
    for j in range(1,9):
        if n == i * j:
            bl = 1
            break

if bl == 1:
    print ("Yes")
else:
    print ("No")

# Fixed code:
n = int(input())
bl = 0
for i in range(1,10):
    for j in range(1,10):
        if n == (i * j):
            bl = 1
            break
if bl == 1:
    print ("Yes")
else:
    print ("No")
# Buggy code:
n = int(input())

for x in range(1, 9 + 1):
    for y in range(1, 9 + 1):
        if x * y == n:
            a = True

if a:
    print('Yes')
else:
    print('No')

# Fixed code:
n = int(input())
a = 0
for x in range(1, 9 + 1):
    for y in range(1, 9 + 1):
        if x * y == n:
            a = True

if a:
    print('Yes')
else:
    print('No')
# Buggy code:
n = int(input())
l = []
for i in range(1,10):
    for j in range(1, 10):
        l.append(i * j)
for k in l:
    if i == n:
        print("Yes")
        break
else:
    print("No")


# Fixed code:
n = int(input())
l = []
for i in range(1,10):
    for j in range(1, 10):
        l.append(i * j)
for k in l:
    if n == k:
        print("Yes")
        break
else:
    print("No")
# Buggy code:
n = int(input())
list = [1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,
       24,25,27,28,30,32,35,36,40,42,45,48,49,54,
       56,63,64,72,81]

if list in n:
  print('Yes')
else:
  print('No')

# Fixed code:
n = int(input())
list = [1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,
       24,25,27,28,30,32,35,36,40,42,45,48,49,54,
       56,63,64,72,81]

if n in list:
  print('Yes')
else:
  print('No')
# Buggy code:
    import sys
    N = int(input())
     
    for i in range(1,10):
        for j in range(1,10):
            if(N == i*j):
                print("Yes")
                sys.exit()
    print("No")

# Fixed code:
import sys
N = int(input())

for i in range(1,10):
    for j in range(1,10):
        if(N == i*j):
            print("Yes")
            sys.exit()
print("No")
# Buggy code:
n=int(input())
def c():
    for i in range(1,10):
        for s in range(1,11-i):
            if i*s==n:
                print("Yes")
                return
    print("No")
c()

# Fixed code:
n=int(input())
def c():
    for i in range(1,10):
        for s in range(1,10):
            if i*s==n:
                print("Yes")
                return
    print("No")
c()
# Buggy code:
n = int(input())
flg = False
for i in range(1, 10):
    for j in range(1, 10):
        if n == i * j:
            print("Yes")
            flg = True
    else:
        continue
    break
if not flg:
    print("No")

# Fixed code:
n = int(input())
flg = False
for i in range(1,10):
  if flg:
    break
  for j in range(1,10):
    if i*j == n:
      flg = True
      break
print("Yes" if flg else "No")
# Buggy code:
dic={}

for i in range(9):
    for j in range(9):
        if dic.get(i*j,None)==None:
            dic[i*j]=1
        else:
            dic[i*j]+=1

N = int(input())

if dic.get(N,None)==None:
    print("No")
else:
    print("Yes")

# Fixed code:
dic={}

for i in range(1,10):
    for j in range(1,10):
        if dic.get(i*j,None)==None:
            dic[i*j]=1
        else:
            dic[i*j]+=1

N = int(input())

if dic.get(N,None)==None:
    print("No")
else:
    print("Yes")
# Buggy code:
n = int(input())

a = 0

for i in range(1, 10):
    for j in range(1,10):
        if n/i==j:
            print("Yes")
            exit()
            a +=1
        else:
            continue

print("No")

if a == 0:
    print("No")
else:
    exit()

# Fixed code:
n = int(input())

a = 0

for i in range(1, 10):
    for j in range(1,10):
        if n/i==j:
            print("Yes")
            exit()
            a +=1
        else:
            continue

if a == 0:
    print("No")
else:
    exit()
# Buggy code:
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
import math
# mod = 10**9 + 7

# n = int(input())
# a = list(map(int, input().split()))
n = int(input())


if n > 81:
    print('No')
    exit()

else:
    for i in range(1,10):
        if n % i == 0:
            print('Yes')
            exit()

print('No')
    

# Fixed code:
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
import math
# mod = 10**9 + 7

# n = int(input())
# a = list(map(int, input().split()))
n = int(input())


if n > 81:
    print('No')
    exit()

else:
    for i in range(1,10):
        if n % i == 0 and 1<= (n // i) <=9:
            print('Yes')
            exit()

print('No')
# Buggy code:
N = int(input())

hoge = [0] * 81

for i in range(9):
    for j in range(9):
        hoge[9*i+j] = (i+1)*(j+1)

if N in hoge:
    print("Yes")
else:
    print("No")

print(hoge)

# Fixed code:
N = int(input())

hoge = [0] * 81

for i in range(9):
    for j in range(9):
        hoge[9*i+j] = (i+1)*(j+1)

if N in hoge:
    print("Yes")
else:
    print("No")
# Buggy code:
N=int(input())
lst=[]
for i in range(1,9):
    for j in range(1,9):
        lst.append(i*j)

print("Yes" if N in lst else "No")
        

# Fixed code:
N=int(input())
lst=[]
for i in range(1,10):
    for j in range(1,10):
        lst.append(i*j)

if N in lst:
    print("Yes")
else:
    print("No")
# Buggy code:
n = int(input())
for i in range(1, 10):
  for j in range(1, 10):
    if n == i*j:
      print('Yes')
      break
  else:
    continue
  break

# Fixed code:
n = int(input())
label = 'No'
for i in range(1, 10):
  for j in range(1, 10):
    if n == i*j:
      label = 'Yes'
      break
  else:
    continue
  break
print(label)
# Buggy code:
n = int(input())
for i in range(1,10):
  for i in range(1,10):
    if i*j == n:
      print('Yes')
      exit()
print('No')  


# Fixed code:
x = int(input())
for i in range(1,10):
  for j in range(1,10):
    if i*j==x:
      print("Yes")
      exit()
print("No")
# Buggy code:
N = int(input())
flag = 0

for i  in range(10):
    atai = N / (i + 1) 
    for j in range(10):
        if atai == j:
            flag = 1
            break
if flag == 1:
    print("Yes")
else:
    print("No")


# Fixed code:
N = int(input())
flag = 0

for i  in range(9):
    atai = N / (i + 1) 
    for j in range(9):
        if atai == j + 1:
            flag = 1
            break
    if flag == 1:
        break
if flag == 1:
    print("Yes")
else:
    print("No")
# Buggy code:
list=[]
for i in range(1,9):
  for j in range(i+1,10):
    list.append(i*j)
a=int(input())
if a in list:
  print("Yes")
else:
  print("No")


# Fixed code:
list=[]
for i in range(1,10):
  for j in range(1,10):
    list.append(i*j)
a=int(input())
if a in list:
  print("Yes")
else:
  print("No")
# Buggy code:
N = int(input())
ans = ''
if N > 81 or N < 1:
    ans = 'No'
else:
    a = [i for i in range(1,10)]
    for i in a:
        q, mod = divmod(N, i)
        if q < 10 and mod == 0:
            ans = 'Yes'
            break
if ans == 'No':
    print('No')
else:
    print('Yes')

# Fixed code:
N = int(input())
ans = ''
if N > 81 or N < 1:
    ans = 'No'
else:
    a = [i for i in range(1,10)]
    for i in a:
        q, mod = divmod(N, i)
        if q < 10 and mod == 0:
            ans = 'Yes'
            break
if ans == 'No' or ans == '':
    print('No')
else:
    print('Yes')
# Buggy code:
print("Yes" if sum([int(input()) == x * y for x in range(1, 10) for y in range(1, 10)]) else "No")

# Fixed code:
n = int(input())
print("Yes" if sum([n == x * y for x in range(1, 10) for y in range(1, 10)]) else "No")
# Buggy code:
n=int(input())
for a in range(1,10):
  for b in range(1,10):
  if n==a*b:
    break
    print("Yes")
  else:
    print("No")

# Fixed code:
n=int(input())
for a in range(1,10):
  for b in  range(1,10):
    if n==a*b:
      print("Yes")
      exit()
else:
  print("No")
# Buggy code:
kuku = []
for i in range(1, 10):
  for j in range(1, 10):
    kuku.append(i * j)
num = set(kuku)
n = input()
if(n in kuku):
  print("Yes")
else:
  print("No")

# Fixed code:
kuku = []
for i in range(1, 10):
  for j in range(1, 10):
    kuku.append(i * j)
num = set(kuku)
n = int(input())
if(n in num):
  print("Yes")
else:
  print("No")
# Buggy code:
n = int(input())
for i in range(1, 10):
    for j in range(1, 10):
        print(i,j)
        if i * j == n:
            print('Yes')
            exit()
else:print('No')

# Fixed code:
n = int(input())
for i in range(1, 10):
    for j in range(1, 10):
        if i * j == n:
            print('Yes')
            exit()
else:print('No')
# Buggy code:
n = int(input())
ans = 'No'
for i in range(1, 9):
  if n % i == 0 and n // i <= 9:
      ans = 'Yes'
      break
print(ans)

# Fixed code:
n = int(input())
ans = 'No'
for i in range(1, 10):
  if n % i == 0 and 1 <= n // i <= 9:
      ans = 'Yes'
      break
print(ans)
# Buggy code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    S = input()
    K = int(input())

    ls = len(S)

    if ls == 1:
        print(K//2)
        return

    if ls == 2:
        print(0 if S[0] != S[1] else K)
        return

    if S[0] == S[-1]:
        c0 = S[0]
        for i in range(1, ls):
            if c0 != S[i]:
                break
        else:
            print(ls*K//2)
            return
        i0 = i
    else:
        i = i0 = 0

    ans = 0
    c0 , cn = "", 0
    for i in range(i, ls):
        c1 = S[i]
        if c1 == c0:
            cn += 1
        else:
            if cn > 1:
                ans += cn // 2
            cn = 1
            c0 = c1

    if i0 == 0:
        ans *= K
    else:
        print(i0, cn)
        ans = ans * K + ((i0+cn)//2) * (K-1) + i0//2 + cn//2


    print(ans)

if __name__ == "__main__":
    resolve()


# Fixed code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    S = input()
    K = int(input())

    ls = len(S)

    if ls == 1:
        print(K//2)
        return

    if ls == 2:
        print(0 if S[0] != S[1] else K)
        return

    if S[0] == S[-1]:
        c0 = S[0]
        for i in range(1, ls):
            if c0 != S[i]:
                break
        else:
            print(ls*K//2)
            return
        i0 = i
    else:
        i = i0 = 0

    ans = 0
    c0 , cn = "", 0
    for i in range(i, ls):
        c1 = S[i]
        if c1 == c0:
            cn += 1
        else:
            if cn > 1:
                ans += cn // 2
            cn = 1
            c0 = c1

    if i0 == 0:
        if cn > 1:
            ans += cn // 2
        ans *= K
    else:
        ans = ans * K + ((i0+cn)//2) * (K-1) + i0//2 + cn//2


    print(ans)

if __name__ == "__main__":
    resolve()
# Buggy code:
s=input()
k=int(input())
d=[]
w=""
cnt=0
for i in s:
    if w!=i:
        w=i
        if cnt:
            d.append(cnt)
        cnt=1
    else:
        cnt+=1
d.append(cnt)
t=len(d)
if t==1:
    print(d[0]*k//2)
else:
    ans=0
    for i in range(t):
        if i==0 and s[0]!=s[-1]:
            ans+=(d[0]*k)//2
        elif i==0 and s[0]==s[-1]:
            ans+=d[0]*k//2
        elif i==t-1 and s[0]==s[-1]:
            ans+=(d[0]+d[-1])*(k-1)//2
            ans+=d[-1]//2
        elif i==t-1 and s[0]!=s[-1]:
            ans+=d[-1]*k//2
        else:
            ans+=d[i]//2
    print(ans)


# Fixed code:
s=input()
k=int(input())
d=[]
w=""
cnt=0
for i in s:
    if w!=i:
        w=i
        if cnt:
            d.append(cnt)
        cnt=1
    else:
        cnt+=1
d.append(cnt)
t=len(d)
if t==1:
    print(d[0]*k//2)
else:
    ans=0
    for i in range(t):
        if i==0 and s[0]!=s[-1] and d[0]>1:
            ans+=d[0]//2*k
        elif i==0 and s[0]==s[-1] and d[0]>1:
            ans+=d[0]//2
        elif i==t-1 and s[0]==s[-1]:
            ans+=(d[0]+d[-1])//2*(k-1)
            ans+=d[-1]//2
        elif i==t-1 and s[0]!=s[-1]:
            ans+=d[-1]//2*k
        elif d[i]>1:
            ans+=d[i]//2*k
    print(ans)
# Buggy code:
def cal(S):
    tmp, a, cnt = S[0], 1, 0
    flag = True
    for s in S[1:]:
        if S[0]!=s: flag=False
        if flag: a+=1
        if tmp[-1]==s:
            s = '*'
            ans += 1
        tmp += s
    return a, cnt


S = input().replace('\n', '')
k = int(input())
ans = 0
if len(list(set(S)))==1:
    ans = len(S)*k//2
else:
    a, cnt = cal(S)
    b, _ = cal(S[::-1])
    ans = cnt*k
    if S[0]==S[-1]:
        ans -= ((a//2)+(b//2)-((a+b)//2))*(k-1)
print(ans)

# Fixed code:
def cal(S):
    tmp, a, cnt = S[0], 1, 0
    flag = True
    for s in S[1:]:
        if S[0]!=s: flag=False
        if flag: a+=1
        if tmp[-1]==s:
            s = '*'
            cnt += 1
        tmp += s
    return a, cnt


S = input().replace('\n', '')
k = int(input())
ans = 0
if len(list(set(S)))==1:
    ans = len(S)*k//2
else:
    a, cnt = cal(S)
    b, _ = cal(S[::-1])
    ans = cnt*k
    if S[0]==S[-1]:
        ans -= ((a//2)+(b//2)-((a+b)//2))*(k-1)
print(ans)
# Buggy code:
s = list(input())
k = int(input())

check = ""
check_cnt = 0
ans1 = 0
for i in range(len(s)):
    if check_cnt == 0:
        check = s[i]
        check_cnt += 1
        continue
    if check == s[i]:
        check_cnt += 1
        continue
    else:
        check = s[i]
        if check_cnt == 1:
            pass
        elif check_cnt%2 == 0:
            ans1 += check_cnt//2
        else:
            ans1 += (check_cnt - 1)//2
    check_cnt = 1
else:
    if check_cnt == 1:
        pass
    elif check_cnt%2 == 0:
        ans1 += check_cnt//2
    else:
        ans1 += (check_cnt - 1)//2
    
cnt2 = 0
cnt3 = 0

temp = s[0]
for i in range(len(s)):
    if temp == s[i]:
        cnt2 += 1
    else:
        break
    
for i in range(1,len(s)+1):
    if temp == s[-i]:
        cnt3 += 1
    else:
        break

add = 0
if cnt2%2 == 1 and cnt3%2 == 1:
    add = 1
    
same = s[0]
for i in range(len(s)):
    if same == s[i]:
        continue
    else:
        break
else:
    t = len(s) * k
    if k%2 == 0:
        print(t//2)
    else:
        print((t-1)//2)
    exit()
    
print(ans1 * k + add * (k-1))

# Fixed code:
s = list(input())
k = int(input())

check = ""
check_cnt = 0
ans1 = 0
for i in range(len(s)):
    if check_cnt == 0:
        check = s[i]
        check_cnt += 1
        continue
    if check == s[i]:
        check_cnt += 1
        continue
    else:
        check = s[i]
        if check_cnt == 1:
            pass
        elif check_cnt%2 == 0:
            ans1 += check_cnt//2
        else:
            ans1 += (check_cnt - 1)//2
    check_cnt = 1
else:
    if check_cnt == 1:
        pass
    elif check_cnt%2 == 0:
        ans1 += check_cnt//2
    else:
        ans1 += (check_cnt - 1)//2
    
cnt2 = 0
cnt3 = 0

temp = s[0]
for i in range(len(s)):
    if temp == s[i]:
        cnt2 += 1
    else:
        break
    
for i in range(1,len(s)+1):
    if temp == s[-i]:
        cnt3 += 1
    else:
        break

add = 0
if cnt2%2 == 1 and cnt3%2 == 1:
    add = 1
    
same = s[0]
for i in range(len(s)):
    if same == s[i]:
        continue
    else:
        break
else:
    t = len(s) * k
    if t%2 == 0:
        print(t//2)
    else:
        print((t-1)//2)
    exit()
    
print(ans1 * k + add * (k-1))
# Buggy code:
def check_subseq(s):
    subseq_list = []
    tmp_length = 1
    for i in range(1, len(s)):
        if s[i - 1] == s[i]:
            tmp_length += 1
        else:
            if tmp_length >= 2:
                subseq_list.append(tmp_length)
            tmp_length = 1
        
    if tmp_length >= 2:
        subseq_list.append(tmp_length)

    return subseq_list


s = input()
k = int(input())

if s[0] == s[-1]:
    if len(set(s)) == 1:
        print(len(s) * k // 2)
        exit()

    i = 1
    while True:
        if s[i] != s[-1]:
            first_subseq_length = i
            break
        i += 1

    i = 1
    while True:
        if s[-(i + 1)] != s[0]:
            last_subseq_length = i
            break
        i += 1

    print(first_subseq_length, last_subseq_length)
    s = s[first_subseq_length:] + s[:first_subseq_length]
    subseq_list = check_subseq(s)
    ans = sum(map(lambda x: x // 2, subseq_list)) * k
    ans += first_subseq_length // 2 + last_subseq_length // 2 - subseq_list[-1] // 2
else:
    subseq_list = check_subseq(s)
    ans = sum(map(lambda x: x // 2, subseq_list)) * k
print(ans)



# Fixed code:
def check_subseq(s):
    subseq_list = []
    tmp_length = 1
    for i in range(1, len(s)):
        if s[i - 1] == s[i]:
            tmp_length += 1
        else:
            if tmp_length >= 2:
                subseq_list.append(tmp_length)
            tmp_length = 1
        
    if tmp_length >= 2:
        subseq_list.append(tmp_length)

    return subseq_list


s = input()
k = int(input())

if s[0] == s[-1]:
    if len(set(s)) == 1:
        ans = len(s) * k // 2
    else:
        i = 1
        while True:
            if s[i] != s[-1]:
                first_subseq_length = i
                break
            i += 1

        i = 1
        while True:
            if s[-(i + 1)] != s[0]:
                last_subseq_length = i
                break
            i += 1

        # print(first_subseq_length, last_subseq_length)
        s = s[first_subseq_length:] + s[:first_subseq_length]
        subseq_list = check_subseq(s)
        ans = sum(map(lambda x: x // 2, subseq_list)) * k
        ans += first_subseq_length // 2 + last_subseq_length // 2 - subseq_list[-1] // 2
else:
    subseq_list = check_subseq(s)
    ans = sum(map(lambda x: x // 2, subseq_list)) * k
print(ans)
# Buggy code:


def main():
    s = list(input())
    k = int(input())
    lst = []
    cnt = 1
    flg = 0
    ans = 0
    prev = s[0]
    for i in range(1, len(s)):
        if prev == s[i]:
            cnt += 1
        else:
            lst.append(cnt)
            cnt = 1
            prev = s[i]
            flg = 1
    lst.append(cnt)
    if len(lst) == 1:
        ans = s * k // 2
    else:
        # ans += sum(list(map(lambda x: x // 2, lst[1:len(lst)-1]))) * k
        for l in lst[1: len(lst) - 1]:
            ans += l // 2 * k
        if s[-1] == s[0]:
            ans += (lst[0] + lst[-1]) // 2 * (k - 1)
            ans += lst[0] // 2 + lst[-1] // 2
        else:
            ans += (lst[0] // 2 + lst[-1] // 2) * k
    print(ans)


if __name__ == "__main__":
    main()


# Fixed code:


def main():
    s = list(input())
    k = int(input())
    lst = []
    cnt = 1
    flg = 0
    ans = 0
    prev = s[0]
    for i in range(1, len(s)):
        if prev == s[i]:
            cnt += 1
        else:
            lst.append(cnt)
            cnt = 1
            prev = s[i]
            flg = 1
    lst.append(cnt)
    if len(lst) == 1:
        ans = len(s) * k // 2
    else:
        ans += sum(list(map(lambda x: x // 2, lst[1:len(lst)-1]))) * k
        # for l in lst[1: len(lst) - 1]:
        #     ans += l // 2 * k
        if s[-1] == s[0]:
            ans += (lst[0] + lst[-1]) // 2 * (k - 1)
            ans += lst[0] // 2 + lst[-1] // 2
        else:
            ans += (lst[0] // 2 + lst[-1] // 2) * k
    print(ans)


if __name__ == "__main__":
    main()