Harryxun/stf_run huggingface dataset:
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li2 = [0]*n
li.append(1)

next = 0
t=0
rep = False

for i in range(n):
    li.append(A[next])
    li2[next] = 1
    next = A[next]-1

    if li2[next] == 1:
        t = li.index(A[next])
        rep = True
        break


if rep == True and t != 0:
    tmp = (k%len(li[t:])) - len(li[0:t])
    g=li[t:]
    print(g[tmp])
else:
    print(li[k-1])


### FIXED CODE ###

from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li2 = [0]*n
li.append(1)

next = 0

t=0
rep = False

for i in range(k):
    if i == k:
        print(next+1)
        exit()

    if li2[next] == 1:
        t = li.index(next+1)
        rep = True
        li.pop()
        break

    li.append(A[next])
    li2[next] = 1
    next = A[next]-1


tmp = (k-t)%len(li[t:])
print(li[tmp+t])
a,b,c,d=map(int,input().split())
g=[]
g.append(a*c)
g.append(a*d)
g.append(b*c)
g.append(b*d)
print(max(g))

### FIXED CODE ###

t=int(input())
if t==1:
    print("0")
else:
    print("1")
[n, k], [*a] = [[*map(int, t.split())] for t in open(0)]
count = 0
visited = dict()
tmp = 1
while count <= k and tmp not in visited:
    visited[tmp] = count
    tmp = a[tmp - 1]
    count += 1
if count <= k:
    k = (k - count) % (count - visited[tmp])
    for _ in range(k):
        tmp = a[tmp - 1]
print(tmp)

### FIXED CODE ###

s = str(input())
t = str(input())
ans = 'No'
if s == t[:-1]:
    ans = 'Yes'
print(ans)
n = int(input())
a = map(int, input().split())
print(min(a), max(a), sum(a))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
print(min(a), max(a), sum(a))
N,X,T = input(int()).split()

A = ((N // X) + 1 ) * T
print(int(A))

### FIXED CODE ###

N,X,T = input().split()

N = int(N)
X = int(X)
T = int(T)

if N % X != 0:
  A = ((N // X) + 1 ) * T
else:
  A = (N/X) * T
print(int(A))
import math
S = int(input())

hoge = math.sqrt(S)
hoge = math.ceil(hoge)
onon = hoge ** 2 - S
for i in range(2, 10*9):
    if onon % i == 0:
        hogehoge = onon // i
        hogehoge2 = i
        break

print("0 0 " + str(i) + " " + str(hoge) + " " + str(hoge) + " " + str(hogehoge2))

### FIXED CODE ###

import math
S = int(input())

hoge = math.sqrt(S)
hoge = math.ceil(hoge)
onon = hoge ** 2 - S
hogehoge = onon
hogehoge2 = 1
for i in range(2, 10*9):
    if onon % i == 0:
        hogehoge = onon // i
        hogehoge2 = i
        break

print("0 0 " + str(hogehoge) + " " + str(hoge) + " " + str(hoge) + " " + str(hogehoge2))
#include <iostream>
#include <string>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)

int main(){
  string s;
  cin >> s;
  int ans = 0;
  rep(i, 4){
    if (s[i] == '+') ++ans;
    else --ans;
  }
  cout << ans << endl;
}

### FIXED CODE ###

N = input()
print(N.count('+') - N.count('-'))
n, k = map(int, input().split())
edges = []
for _ in range(n-1):
  edges.append(list(map(int, input().split())))

edge_dict = {}
for i in range(1, n+1):
  edge_dict[i] = set()

for edge in edges:
  edge_dict[edge[0]].add(edge[1])
  edge_dict[edge[1]].add(edge[0])

visited = set()

def dfs(node, parent):
  for child in edge_dict[node]:
    if child is parent:
      continue
    
    dfs(child, node)
  
  return k

print(dfs(1, None))

### FIXED CODE ###

import queue

n, k = map(int, input().split())
edges = []
for _ in range(n-1):
  edges.append(list(map(int, input().split())))
mod = 10**9+7

edge_dict = {}
for i in range(1, n+1):
  edge_dict[i] = set()

for edge in edges:
  edge_dict[edge[0]].add(edge[1])
  edge_dict[edge[1]].add(edge[0])

visited = set()
q = queue.LifoQueue()
q.put(1)

num_cases = 1
while not q.empty():
  node = q.get()
  
  visited.add(node)
  num_available_colors = k -2 if node is not 1 else k -1
  
  for child in (edge_dict[node] - visited):
    num_cases *= num_available_colors
    num_available_colors -= 1
    num_cases %= mod
    q.put(child)

print((k*num_cases)%mod)
import math

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())
sum = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    for k in range(1, K+1):
      sum += gcd(i,j,k)
print(sum)

### FIXED CODE ###

import math
K=int(input())
ans=0
for i in range(1,K+1):
    for j in range(1,K+1):
        tmp=math.gcd(i,j)
        for k in range(1,K+1):
            ans+=math.gcd(tmp,k)         
print(ans)
t, x = map(int, raw_input.split()) 
print(t/x)

### FIXED CODE ###

t, x = map(int, input().split()) 
print(t/x)
s=input()
s[3]="8"

### FIXED CODE ###

s=input()
c=""
for i in range(len(s)):
  if i==3:
    c+="8"
  else:
    c+=s[i]
print(c)
s = input()
l = len(s)
a = [0]*l
for i in range(l):
    if s[i] == "A" or s[i] =="T" or s[i] =="C" or s[i] =="G":
        a[i] = 1
m = 0
if a[0] = 1:
  m = 1
for i in range(1,l):
    a[i] = (a[i-1]+1)*a[i]
    if m < a[i]:
        m = a[i]

print(m)

### FIXED CODE ###

s = input()
l = len(s)
a = [0]*l
for i in range(l):
    if s[i] == "A" or s[i] =="T" or s[i] =="C" or s[i] =="G":
        a[i] = 1
m = 0
if a[0] == 1:
  m = 1
for i in range(1,l):
    a[i] = (a[i-1]+1)*a[i]
    if m < a[i]:
        m = a[i]

print(m)
from functools import reduce

def nCk(n, k, mod=10 ** 9 + 7):
    if n < k:
        return 0
    k = min(k, n - k)
    mod_mul = lambda a, b: a * b % mod
    numer = reduce(mod_mul, range(n - k + 1, n + 1))
    denom = reduce(mod_mul, range(1, k + 1))
    return numer * pow(denom, mod - 2, mod) % mod

X, Y = map(int, input().split())

b = (2 * X - Y) // 3
a = (-X + 2 * Y) // 3

if (X + Y) % 3 != 0 or a < 0 or b < 0:
    print(0)
else:
    print(nCk(a + b, a))


### FIXED CODE ###

class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod

    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod

mod = 10 ** 9 + 7
mc = ModComb(3 * 10 ** 6, mod)

X, Y = map(int, input().split())
if (2 * X - Y) % 3 != 0 or (X - 2 * Y) % 3 != 0:
    print(0)
    quit()

b = (2 * X - Y) // 3
a = (-X + 2 * Y) // 3

print(mc.nCk(a + b, a))
S = input()
n = len(S)//2
i = 0

if len(S)%2 == 0:
    while i <= n-1:
        if S[2*i] != "L" and S[2*i+1] != "R":
            i = i + 1
        else:
            print("No")
            break
    if i == n:
        print("Yes")
else:
    while i <= n-1:
        if S[2*i] != "L" and S[2*i+1] != "R":
            i = i + 1
        else:
            print("No")
            break
    if i == n and S[2*i] != "L":
        print("Yes")
    else if i ==n:
        print("No")


### FIXED CODE ###

ss = input()
count = 0
ans  = 0
for s in ss:
    if count%2 == 0 and s != "L":
        pass
    elif count%2 == 0:
        ans += 1
    elif count%2 == 1 and s != "R":
        pass
    elif count%2 == 1:
        ans += 1
    count += 1
if ans == 0:
    print("Yes")
else:
    print("No")
N, K = [int(ipt) for ipt in input().split(' ')]

sunukekuns = [str(i) for i in range(N)]

for k in range(K):
  _ = input()
  sunukekun = input().split(' ')
  for (kun in sunukekun):
    if kun in sunukekuns:
      sunukekuns.remove(kun)

print(len(sunukekuns))


### FIXED CODE ###

N, K = [int(ipt) for ipt in input().split(' ')]

sunukekuns = [str(i+1) for i in range(N)]

for k in range(K):
  _ = input()
  sunukekun = input().split(' ')
  for kun in sunukekun:
    if kun in sunukekuns:
      sunukekuns.remove(kun)

print(len(sunukekuns))
a, b = list(map(int, input().split()))
if a == 'H':
  b = 'D' if b == 'H' else 'H'
print(b)


### FIXED CODE ###

a, b = list(input().split())
if a == 'D':
  b = 'D' if b == 'H' else 'H'
print(b)
X = int(input())
 
flag = 0
A = 0
B = 0
 
for i in range(0, 100):
  for j in range(0, 100):
    if i**5 - j**5 == X:
      A = i
      B = j
      break
    elif i**5 + j**5 == X:
      A = i
      B = j
      break
    elif -i**5 - j**5 == X:
      A = -i
      B = j
      break
print(str(A) + ' ' + str(B))

### FIXED CODE ###

a = input()

if a == 'ABC':
  print('ARC')
else:
  print('ABC')
import math
from functools import reduce

N, K = map(int, input().split())
p = 0
dnms = []


def calc_p(n, c):
    return 1/n * pow(1/2, c)


def calc_dnm(n, c):
    return n * 2 ** c


def calc_lcm(ns):
    return reduce(lcm, ns, 1)


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


for i in range(1, N+1):
    score = i
    cnt = 0
    while score <= K:
        score *= 2
        cnt += 1
    dnms.append(calc_dnm(N, cnt))
    p += calc_p(N, cnt)

print(p)

l = calc_lcm(dnms)
mlcls = [l/x for x in dnms]
print(sum(mlcls) / calc_lcm(dnms))


### FIXED CODE ###

N, K = map(int, input().split())
S = list(input())
S[K-1] = S[K-1].lower()
print(''.join(S))
s = input()

count = 0
while True:
    n = len(s)
    if n == 0 or sum(s) == 0 or sum(s) == n:
        break
    sn = s + '\n'
    for i in range(n):
        if sn[i-1] + sn[i] == '10' or sn[i-1] + sn[i] == '01':
            s = sn[:i-1] + sn[i+1:n]
            count += 1
            break

print(count * 2)

### FIXED CODE ###

s = input()

zero = s.count('0')
one = s.count('1')

print(2 * min(zero, one))
def solve(n,k):
    if k == 0:
        return 1
    for i in range(len(n)):
        if n[i] != 0:
            break
    n = n[i:]
    if n == []:
        return 0
    l = len(n)
    ans = 0

    # n-1桁からKこ取る
    tmp1 = 1
    for i in range(1, k+1):
        tmp1 = tmp1*9*(l-i)
    for i in range(1, k+1):
        tmp1 = tmp1 // i

    # 最上位から1つ（最上位の数以外）とる。
    tmp2 = n[0]-1
    for i in range(1, k):
        tmp2 = tmp2*9*(l-i)
    for i in range(1, k):
        tmp2 = tmp2 // i

    # 最上位からその数をとる。
    tmp3 = solve(n[1:],k-1)

    ans = tmp1 + tmp2 + tmp3
    return ans

n = list(map(int, input()))
k = int(input())

print(solve(n,k))


### FIXED CODE ###


def solve(n,k):
    for i in range(len(n)):
        if n[i] != 0:
            break
    n = n[i:]
    if n == []:
        return 0
    l = len(n)
    ans = 0
    # n-1桁からKこ取る
    tmp = 1
    for i in range(1, k+1):
        tmp = tmp*9*(l-i)
    for i in range(1, k+1):
        tmp = tmp // i
    ans += tmp

    # 最上位から1つ（最上位の数以外）とる。
    tmp = n[0]-1
    for i in range(1, k):
        tmp = tmp*9*(l-i)
    for i in range(1, k):
        tmp = tmp // i
    ans += tmp

    # 最上位からその数をとる。
    tmp = 0
    if k == 3:
        tmp += solve(n[1:],k-1)

    elif k == 2:
        for i in range(1, l):
            if n[i] != 0:
                tmp += n[i] + 9*(l-i-1)
                break
    else:
        tmp += 1
    ans += tmp
    return ans

n = list(map(int, input()))
k = int(input())

print(solve(n,k))
def Gcd(a,b):
	if a<b:
		return Gcd(b,a)
	else:
		if a%b:
			return Gcd(b, a%b):
		else:
			return b
N = int(input())
arr = list(map(int,input().split()))
gcd = arr[0]
for i in arr:
	gcd = Gcd(gcd, i)
print(gcd)

### FIXED CODE ###

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

n = int(input())
a = list(map(int, input().split()))
a.sort()
for i in range(n-1):
    a[i+1]  = gcd(a[i], a[i+1])
print(a[n-1])
a,b = map(int,input().split())
if (a * b) % 2 = 0:
  print(Even)
else:
  print(Odd)


### FIXED CODE ###

a,b = map(int,input().split())
if (a * b) % 2:
  print('Odd')
else:
  print('Even')
from fractions import gcd
n, m = map(int, input().split())
s = input()
t = input()
l = n * m // gcd(n, m)
a = [""] * (n*m)
for i in range(n):
    a[i*l//n] = s[i]
for i in range(m):
    if a[i*l//m] == "" or a[i*l//m] == t[i]:
        a[i*l//m] == t[i]
    else:
        print(-1)
        exit()
print(l)
 


### FIXED CODE ###

from fractions import gcd
n, m = map(int, input().split())
s = input()
t = input()
g = gcd(n,m)
l = n*m//g
for k in range(g):
    if s[k*n//g] != t[k*m//g]:
        print(-1)
        exit()
print(l)
A = input()
B = input()
A = int(A)
B = int(B)
ans = 0

if A> B:
  ans = ans + A
else :
  ans = ans + B
  
if A> B:
  ans = ans + A
else :
  ans = ans + B
  
print(ans)


### FIXED CODE ###

str = input().split()
A = int(str[0])
B = int(str[1])
ans = 0
 
if A> B:
  ans = ans + A
  A = A-1
else :
  ans = ans + B
  B = B-1
if A> B:
  ans = ans + A
else :
  ans = ans + B
  
print(ans)
a=input()
b=input()
ans="No"
for i in range(len(a)):
  k=1
  for j in range(len(a)):
    j=(j+i)%len(n)
    if a[j]!=b[j]:
      k=0
      break
  if k==1:
    ans="Yes"
    break
    
print(ans)

### FIXED CODE ###

a=input()
b=input()
ans="No"
for i in range(len(a)):
  k=1
  for j in range(len(a)):
    j2=(j+i)%len(a)
    if a[j]!=b[j2]:
      k=0
      break
  if k==1:
    ans="Yes"
    break
    
print(ans)
n, m = map(int, input().split())
p = []
s = []
for i in range(m):
  p_i, s_i = input().split()
  p.append(int(p_i))
  s.append(s_i)

list_correct = [0] * n
list_pena = [0] * n
for i in range(m):
  if s[i] == "AC":
    if list_correct[p[i]] == 0:
      list_correct[p[i]] = 1
  else:
    if list_correct[p[i]] == 0:
      list_pena[p[i]] = list_pena[p[i]] + 1
      
sum_correct = sum(list_correct)
combined = [x * y for (x, y) in zip(list_correct, list_pena)]
sum_pena = sum(combined)

print (sum_correct, sum_pena)

### FIXED CODE ###

n, m = map(int, input().split())
p = []
s = []
for i in range(m):
  p_i, s_i = input().split()
  p.append(int(p_i))
  s.append(s_i)

list_correct = [0] * n
list_pena = [0] * n
for i in range(m):
  if s[i] == "AC":
    if list_correct[p[i]-1] == 0:
      list_correct[p[i]-1] = 1
  else:
    if list_correct[p[i]-1] == 0:
      list_pena[p[i]-1] = list_pena[p[i]-1] + 1
      
sum_correct = sum(list_correct)
combined = [x * y for (x, y) in zip(list_correct, list_pena)]
sum_pena = sum(combined)

print (sum_correct, sum_pena)
A,B,H,M = map(int,input().split())
C2 = A**2+B**2-2*A*B*math.cos(math.radians((30*H+M*0.5)-6*M))
print(C2**0.5)

### FIXED CODE ###

import math

A,B,H,M = map(int,input().split())
C2 = A**2+B**2-2*A*B*math.cos(math.radians(abs((30*H+M*0.5)-6*M)))
print(C2**0.5)
time = raw_input()
h = time /3600
m = time % 3600 / 60
s = time % 3600 % 60
":".join(map(str,[h,m,s]))

### FIXED CODE ###


time = input()
h = time / 3600
m = time % 3600 / 60
s = time % 3600 % 60
print ":".join(map(str,[h,m,s]))
def prog(x):
    n = len(x)
    y = [int(i * 10**9) for i in x]
    #y

    def count25(n):
        two = five = 0
        while n % 2 == 0:
            two += 1
            n //= 2
        while n % 5 == 0:
            five += 1
            n //= 5
        return two, five

    two = [0] * n
    five = [0] * n
    for i in range(n):
        two[i], five[i] = count25(y[i])
    count = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            #if min(two[i] + two[j], five[i] + five[j]) >= 18:
            if two[i] + two[j] >= 18 and five[i] + five[j] >= 18:
                #print(min(two1,two2) + min(five1, five2), two1, two2, five1, five2)
                #print(y[i] * y[j], (y[i] * y[j]) / 10**18)
                #print(y[i] / 10**9, y[j] / 10**9)
                #print('=================')
                count += 1
    print(count)

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


### FIXED CODE ###

def conv(s):
    if s.find('.') == -1:
        s += '.'
    s = s.rstrip('0')
    t = len(s) - s.find('.') - 1
    a = int(s.replace('.', ''))
    if a == 0:
        return (0, 0)
    x, y = -t, -t
    while a % 5 == 0:
        x += 1
        a //= 5
    while a % 2 == 0:
        y += 1
        a //= 2
    return (x, y)


N, *A = open(0).read().split()
N = int(N)

d = {}
for a in A:
    t = conv(a)
    d.setdefault(t, 0)
    d[t] += 1

result = 0
xs = list(d.keys())
for i in range(len(xs)):
    x, y = xs[i]
    t = d[xs[i]]
    if x >= 0 and y >= 0:
        result += t * (t - 1) // 2
    for j in range(i + 1, len(xs)):
        m, n = xs[j]
        if x + m >= 0 and y + n >= 0:
            result += t * d[xs[j]]
print(result)
K = int(input().split()[3])
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

ans = []
for i in range(len(A)):
    for j in range(len(B)):
        if (i+1) * (j+1) > K:
            break
        for k in range(len(C)):
            if (i+1)*(j+1)*(k+1) > K:
                break
            ans.append(A[i]+B[j]+C[k])
ans.sort(reverse=True)
for _ in range(K):
    print(ans[_])



### FIXED CODE ###

List = list(map(int, [input() for _ in range(5)]))
k = int(input())

if List[4] - List[0] <= k:
    print("Yay!")
else:
    print(":(")
from decimal import Decimal
T = tuple(map(Decimal, input().split()))

A = list(map(Decimal, input().split()))
B = list(map(Decimal, input().split()))


ans = 0
if A[0] < B[0]:
    tmp = (A[0], A[1])
    A[0], A[1] = B[0], B[1]
    B[0], B[1] = tmp[0], tmp[1]

a = abs(T[0]*A[0] - T[0]*B[0])

b = T[0]*(B[0]-A[0])+T[1]*(B[1]-A[1])


if b == 0:
    print("Infinity")
elif b < 0:
    print(0)
    exit(0)
else:
    ans += 1
    if b > a:
        print(1)
    elif b == a:
        print("infinity")
    else:
        if a % b == 0:
            print(((a//b)*2)
        else:
            print((a//b)*2 + 1)


### FIXED CODE ###

from decimal import Decimal
T = tuple(map(Decimal, input().split()))

A = list(map(Decimal, input().split()))
B = list(map(Decimal, input().split()))


ans = 0
if A[0] < B[0]:
    tmp = (A[0], A[1])
    A[0], A[1] = B[0], B[1]
    B[0], B[1] = tmp[0], tmp[1]

a = abs(T[0]*A[0] - T[0]*B[0])

b = T[0]*(B[0]-A[0])+T[1]*(B[1]-A[1])


if b == 0:
    print("infinity")
elif b < 0:
    print(0)
    exit(0)
else:
    ans += 1
    if b > a:
        print(1)
    elif b == a:
        print("infinity")
    else:
        if a % b == 0:
            print((a//b)*2)
        else:
            print((a//b)*2 + 1)
T = input()
T = list(T)
for i in range(len(T)):
    if i == 0:
        if T[i] == "?":
            if T[i+1] == D:
                T[i] = "P"
            else:
                T[i] = "D"
    else:
        if T[i] == "?":
            T[i] = "D"
print("".join(T))

### FIXED CODE ###

T = list(input())
for i in range(len(T)):
    if i == 0:
        if T[i] == "?":
            if len(T) == 1:
                T[i] = "D"
                break
            if T[i+1] == "D":
                T[i] = "P"
            else:
                T[i] = "D"
    else:
        if T[i] == "?":
            T[i] = "D"
print("".join(T))
import sys
sys.setrecursionlimit(10**6)
from collections import Counter

def dfs(nw):
    for nx in B[nw]:
        if V[nx]==-1:
            V[nx] = cnt
            dfs(nx)

F = [[] for _ in range(n)]
B = [[] for _ in range(n)]
n, m, k = list(map(int, sys.stdin.readaline().split()))
for i in range(m):
    a,b = map(lambda x: int(x)-1, map(int, sys.stdin.readline().split()))
    F[a].append(b)
    F[b].append(a)
for i in range(k):
    c,d = map(lambda x: int(x)-1, map(int, sys.stdin.readline().split()))
    F[c].append(d)
    F[d].append(c)

V = [-1]*n
cnt = 1
for i in range(n):
    if V[i]==-1:
        V[i] = cnt
        dfs(i)
        cnt += 1
cV = Counter(V)
ans = []
for i in range(n):
    ans.append(cV[V[i]]-1 - len(F[i]) - sum([V[b]==V[i] for b in B[i]]))

print(*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
from collections import Counter

def dfs(nw):
    for nx in F[nw]:
        if V[nx]==-1:
            V[nx] = cnt
            dfs(nx)

n, m, k = list(map(int, sys.stdin.readline().split()))
F = [[] for _ in range(n)]
B = [[] for _ in range(n)]
for i in range(m):
    a,b = map(lambda x: int(x)-1, map(int, sys.stdin.readline().split()))
    F[a].append(b)
    F[b].append(a)
for i in range(k):
    c,d = map(lambda x: int(x)-1, map(int, sys.stdin.readline().split()))
    B[c].append(d)
    B[d].append(c)

V = [-1]*n
cnt = 1
for i in range(n):
    if V[i]==-1:
        V[i] = cnt
        dfs(i)
        cnt += 1
cV = Counter(V)
ans = []
for i in range(n):
    ans.append(cV[V[i]]-1 - len(F[i]) - sum([V[b]==V[i] for b in B[i]]))

print(*ans)
s = input()
k = int(input())
n = len(s)

if k == 1:
    cnt1 = 0
    cnt2 = 0
    for i in range(n):
        if i == 0:
            if s[i] == s[i+1]:
                cnt1 += 1
        elif i == 2*n-1:
            if i%2 == 0:
                if s[i] == s[i-1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1]:
                    cnt2 += 1
        else:
            if i%2 == 0:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt2 += 1
    print(min(cnt1, cnt2))
elif k == 2:
    s += s
    cnt1 = 0
    cnt2 = 0
    for i in range(2*n):
        if i == 0:
            if s[i] == s[i+1]:
                cnt1 += 1
        elif i == 2*n-1:
            if i%2 == 0:
                if s[i] == s[i-1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1]:
                    cnt2 += 1
        else:
            if i%2 == 0:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt2 += 1
    print(min(cnt1, cnt2))
else:
    s += 2*s
    s1 = ''
    s2 = ''
    for i in range(3*n):
        if i < 3*n - 1 and i > 0:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i-1] or s[i] == s[i + 1]:
                    s1 += '0'
                else:
                    s1 += s[i]
            else:
                s1 += s[i]
                if s[i] == s[i-1] or s[i] == s[i + 1]:
                    s2 += '0'
                else:
                    s2 += s[i]
        elif i == 3*n - 1:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i-1]:
                    s1 += '0'
                else:
                    s1 += s[i]
            else:
                s1 += s[i]
                if s[i] == s[i-1]:
                    s2 += '0'
                else:
                    s2 += s[i]
        else:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i + 1]:
                    s1 += '0'
                else:
                    s1 += s[i]
                    
    s1_arr = [s1[:n].count('0'), s1[n:2*n].count('0'), s1[2*n:].count('0')]
    s2_arr = [s2[:n].count('0'), s2[n:2*n].count('0'), s2[2*n:].count('0')]
    print(min(s1_arr[0] + s1_arr[1]*(k-2) + s1_arr[2], s2_arr[0] + s2_arr[1]*(k-2) + s2_arr[2]))


### FIXED CODE ###

s = input()
k = int(input())
n = len(s)
if len(set(s)) == 1:
    print((n*k)//2)
else:
    arr = []
    cnt = 0
    last = s[0]
    for i in s + '0':
        if i != last:
            arr.append(cnt)
            cnt = 1
            last = i
        else:
            cnt += 1
    ans = 0
    if s[0] == s[-1]:
        ans += (arr[0] + arr[-1])//2*(k-1) + arr[0]//2 + arr[-1]//2
        for i in arr[1:-1]:
            ans += (i//2)*k
    else:
        for i in arr:
            ans += (i//2)*k
    print(ans)
k ,x = map(int,input().split)

if k*500 >= x:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

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

if k*500 >= x:
  print('Yes')
else:
  print('No')
a,b,c=list(map(str, input().split()))
d,e,f=list(map(str, input().split()))
q,n,z=list(map(str, input().split()))
print(a+e+z)

### FIXED CODE ###

a=input()
b=input()
c=input()
print(a[0]+b[1]+c[2])