Harryxun/stf_run huggingface dataset:
A, B, N = map(floor, input().split())
from math import floor

if B > N:
    ans = floor(A*N/B)
    print(ans)
else:
    ans = floor(A*N/B) - A*floor(N/B)
    ans_2nd = 0
    x = (N//B)*B - 1
    temp = floor((A*x)/B) - A*floor(x/B)
    # while ans <= temp and x >= 0:
    #     ans = temp
    #     temp = floor(A*x/B) - A*floor(x/B)
    #     x -= B
    # while ans_2nd <= temp and x >= 0:
    #     ans_2nd = temp
    #     temp = floor(A*x/B) - A*floor(x/B)
    #     x -= B
    # prfloor(max(ans, ans_2nd))
    print(max(temp, ans))

### FIXED CODE ###

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

if B > N:
    print(int((A*N)/B)-A*int(N/B))
else:
    print(int((A*(B-1))/B)-A*int((B-1)/B))

# if B > N:
#     ans = floor(A*N/B)
#     print(ans)
# else:
#     ans = floor(A*N/B) - A*floor(N/B)
#     ans_2nd = 0
#     x = (N//B)*B - 1
#     temp = floor((A*x)/B) - A*floor(x/B)
#     # while ans <= temp and x >= 0:
#     #     ans = temp
#     #     temp = floor(A*x/B) - A*floor(x/B)
#     #     x -= B
#     # while ans_2nd <= temp and x >= 0:
#     #     ans_2nd = temp
#     #     temp = floor(A*x/B) - A*floor(x/B)
#     #     x -= B
#     # prfloor(max(ans, ans_2nd))
#     print(max(temp, ans))
s = input().split()
N = int(s[0])
X = int(s[1])
ss = input().split()
L = []
for i in range(N):
    L.append(int(ss[i]))
    
D = 0
count =0
for i in range(N+1):
    D = D+L[i]
    count = count+1
    if D > X:
        break
        
print(count)

### FIXED CODE ###

s = input().split()
N = int(s[0])
X = int(s[1])
ss = input().split()
L = [0]*(N+1)
for i in range(N):
    L[i] = int(ss[i])
    
D = 0
count =0
for i in range(N+1):
    D = D+L[i]
    count = count+1
   # print(D)
    if D > X:
        break
        
print(count)
N, K = map(int, input().split())
p = list(map(int, input().split()))

res = -1

for i in range(N):
    res = p[i]

print(res)


### FIXED CODE ###

S, T = input().split()
A, B = map(int, input().split())
U = input()
dct = {}
dct[S] = A
dct[T] = B
dct[U] -= 1
print(dct[S], dct[T])
x = [int(i) for i in input().split(' ')]
print(x[3], x[0], x[1])

### FIXED CODE ###

x = [int(i) for i in input().split(' ')]
print(x[2],' ',x[0], ' ',x[1])
import sys

def prime_calc(n):
    if n < 2:
        return False
    else:
        i = 2
        while n > i:
            if n % i == 0:
                return False
            else:
                i += 1
    return True

def prime(n):
    cnt = 0
    for i in range(0, n+1):
        ans = prime_calc(i)
        if ans is True:
            cnt = cnt + 1
    return cnt

def main():
    a = []

    for line in sys.stdin:
        a.append(int(line))

    for line in l:
        print(prime(line))

if __name__ == "__main__":
    main()



### FIXED CODE ###

import math
import sys

sup = 1000000

is_prime = [0] * sup

count = [0] * sup

def setup():
    is_prime[2] = 1
    for n in range(3,sup,2):
        flag = True
        for i in range(3, int(math.floor(math.sqrt(n) + 1)), 2):
            if n % i == 0:
                flag = False
                break
        if flag:
            is_prime[n] = 1

def precount():
    for n in range(2, sup):
        count[n] = count[n-1] + is_prime[n]

def main():
    setup()
    precount()

    l = []

    for line in sys.stdin:
        l.append(int(line))

    for line in l:
         print(count[line])

if __name__ == "__main__":
    main()
import sys
from collections import deque, defaultdict


def bfs01(s, t, links):
    q = deque([(0, s, -1)])  # cost, station, last-company
    visited = set()
    while q:
        d, v, e = q.popleft()
        if v == t:
            return d
        if (v, e) in visited:
            continue
        visited.add((v, e))
        if e == 0:
            for c, us in links[v]:
                for u in us:
                    if (u, c) in visited:
                        continue
                    q.append((d + 1, u, c))
        else:
            for u in links[v][e]:
                if (u, e) in visited:
                    continue
                q.appendleft((d, u, e))
            if (v, 0) not in visited:
                q.appendleft((d, v, 0))

    return -1


readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

n, m = map(int, readline().split())
links = [defaultdict(set) for _ in range(n)]
pqc = list(map(int, read().split()))
for p, q, c in zip(pqc[0::3], pqc[1::3], pqc[2::3]):
    p -= 1
    q -= 1
    links[p][c].add(q)
    links[q][c].add(p)

print(bfs01(0, n - 1, links))


### FIXED CODE ###

import sys
from collections import deque, defaultdict


def bfs01(s, t, links):
    q = deque([(0, s, -1)])  # cost, station, last-company
    visited = set()
    while q:
        d, v, e = q.popleft()
        if v == t:
            return d
        if (v, e) in visited:
            continue
        visited.add((v, e))
        if e == 0:
            for c in links[v]:
                for u in links[v][c]:
                    if (u, c) in visited:
                        continue
                    q.append((d + 1, u, c))
        else:
            for u in links[v][e]:
                if (u, e) in visited:
                    continue
                q.appendleft((d, u, e))
            if (v, 0) not in visited:
                q.appendleft((d, v, 0))

    return -1


readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

n, m = map(int, readline().split())
links = [defaultdict(set) for _ in range(n)]
pqc = list(map(int, read().split()))
for p, q, c in zip(pqc[0::3], pqc[1::3], pqc[2::3]):
    p -= 1
    q -= 1
    links[p][c].add(q)
    links[q][c].add(p)

print(bfs01(0, n - 1, links))
n=int(input())
a=list(map(int,input().split()))
a.sort()
if n%2==1:
    if a[0]!=0:
        print(0)
        exit()
    for i in range(n//2):
        if a[2*i+1]!=2*(i+1) or a[2*(i+1)]!=2*(i+1):
            print(0)
            exit()
    print(pow(2,n//2)%(1e9+7))
else:
    for i in range(n//2):
        if a[2*i]!=2*i+1 or a[2*i+1]!=2*i+1:
            print(0)
            exit()
    print(pow(2,n//2)%(1e9+7))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort()
if N % 2 == 1:
    if A[0] != 0:
        print(0)
        exit()
    for i in range(N // 2):
        if A[2 * i + 1] != 2 * (i + 1) or A[2 * i + 2] != 2 * (i + 1):
            print(0)
            exit()
    print(pow(2, N // 2) % (10 ** 9 + 7))
else:
    for i in range(N // 2):
        if A[2 * i] != 2 * i + 1 or A[2 * i + 1] != 2 * i + 1:
            print(0)
            exit()
    print((pow(2, N // 2)) % (10 ** 9 + 7))
import itertools
H, W = [int(_) for _ in input().split()]
S = []
count_dot = 0
for _ in range(H):
    s = input()
    count_dot += s.count('.')
    S += [list(s)]


def parse(i, j):
    for x, y in ([i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]):
        if x < 0 or H <= x or y < 0 or W <= y:
            continue
        elif S[x][y] == '.':
            S[x][y] = S[i][j] + 1
            parse(x, y)


S[0][0] = 1
parse(0, 0)
print(count_dot - S[-1][-1])


### FIXED CODE ###

import itertools
H, W = [int(_) for _ in input().split()]
S = []
count_dot = 0
for _ in range(H):
    s = input()
    count_dot += s.count('.')
    S += [list(s)]
S[0][0] = '#'
coord = [[0, 0]]
count = 1
flag = True
while flag:
    count += 1
    coord_new = []
    for i, j in coord:
        for x, y in [i + 1, j], [i - 1, j], [i, j + 1], [i, j - 1]:
            if (x, y) == (H - 1, W - 1):
                print(count_dot - count)
                exit()
            elif 0 <= x and x < H and 0 <= y and y < W and S[x][y] == '.':
                S[x][y] = '#'
                coord_new += [[x, y]]
    coord = coord_new
    flag = len(coord)
print(-1)
n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
min = 1000000000
min_c = 0
max_dif = 0
max_dif_c = 0
for i in range(n):
    if a[i] < min:
        min = a[i]
        min_c = 1
        continue
    elif a[i] == min:
        min_c += 1
        continue
    if a[i] - min > max_dif:
        max_dif = a[i] - min
        max_dif_c = 1
    elif a[i] - min == max_dif:
        max_dif_c += 1
c = min([min_c, max_dif_c])
print(str(c))


### FIXED CODE ###

n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
min_a = 1000000000
max_dif = 0
max_dif_c = 0
for i in range(n):
    if a[i] < min_a:
        min_a = a[i]
    elif a[i] - min_a > max_dif:
        max_dif = a[i] - min_a
        max_dif_c = 1
    elif a[i] - min_a == max_dif:
        max_dif_c += 1
print(str(max_dif_c))
N, Q = map(int, input().split())
#link = [[0]*(N+1) for _ in range(N+1)]
link = [[] for _ in range(N+1)]
for n in range(N-1):
    a, b = map(int, input().split())
    # link[a][b] = 1
    # link[b][a] = 1
    link[a].append(b)
    link[b].append(a)
V = [0] * (N+1)
ans = [0] * (N+1)
for q in range(Q):
    p, x = map(int, input().split())
    V[p] += x

def dfs(i, parent, acc):
    V[i] += acc
    # for j in range(1,N+1):
    #     if link[i][j] == 1 and parent!=j:
    #         dfs(j,i,V[i])
    for j in link[i]:
        if j==parent:
            continue
        dfs(j,i,V[i])
cur = 1
parent = 0
acc = 0

dfs(cur, parent , acc)
V = [str(v) for v in V]
print (" ".join(V[1:]))

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

# 遅延評価で加えてあげるだけ

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)

answer = ' '.join(map(str,value[1:]))
print(answer)
from collections import defaultdict, deque

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

D = defaultdict(deque)
R = [0] * (N+1)
for _ in range(M):
  a, b = map(int, input().split())
  if R[a] != 0:
    if R[b] != 0:
      aa, bb = R[a], R[b] 
      if aa == bb:
        pass
      else:
        if len(D[aa]) < len(D[bb]):
          aa, bb = bb, aa
        for x in D[bb]:
          R[x] = aa
        D[aa].extend(D[bb])
        del D[bb]
    else:
      R[b] = R[a]
      D[R[a]].append(b)
  else:
    if R[b] != 0:
      R[a] = R[b]
      D[R[b]].append(a)
    else:
      R[a] = a
      R[b] = a
      D[a].append(a)
      D[a].append(b)

print(max(len(x) for x in D.values()))

### FIXED CODE ###

from collections import defaultdict

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

D = defaultdict(set)
R = {}
for _ in range(M):
  a, b = map(int, input().split())
  if a in R:
    if b in R:
      aa, bb = R[a], R[b] 
      if aa == bb:
        pass
      else:
        if len(D[aa]) < len(D[bb]):
          aa, bb = bb, aa
        for x in D[bb]:
          R[x] = aa
        D[aa] |= D[bb]
        del D[bb]
    else:
      R[b] = R[a]
      D[R[a]].add(b)
  else:
    if b in R:
      R[a] = R[b]
      D[R[b]].add(a)
    else:
      R[a] = a
      R[b] = a
      D[a].add(a)
      D[a].add(b)

print(max(len(x) for x in D.values()) if D else 1)
import sys
import math

n = int(input())
for s in range(n):
    x1,y1,x2,y2,x3,y3,x4,y4 = map(float, input().strip().split())
    angle1 = fabs(y2-y1)/fabs(x2-x1)
    angle2 = fabs(y4-y3)/fabs(x4-x3)
    if angle1 == angle2:
        print("YES")
    else:
        print("NO")

### FIXED CODE ###

N = input()
 
for n in range(N):
    data = map(float,raw_input().split( ))
    slopes = []
    for i in range(2):
        _x1 = data.pop(0)
        _y1 = data.pop(0)
        _x2 = data.pop(0)
        _y2 = data.pop(0)
         
        if _x1 != _x2:
            slopes.append((_y1 - _y2)/(_x1 - _x2))
     
    if len(slopes) == 0:
        print "YES"
    elif len(slopes) == 1:
        print "NO"
    elif abs(slopes[0] - slopes[1]) < 1e-10:
        print "YES"
    else:
        print "NO"
n = int(input())
l = []
for _ in range(3):
    a = list(map(int,input().split()))
    l.append(a)

if n == 1:
    print(l[0][0]+l[1][0])
    exit()
    
m1 = []
m2 = []
m1.append(l[0][0])
m2.append(l[1][0])
for i in range(1,n):
    m1.append(m1[i-1]+l[0][i])
    m2.append(m2[i-1]+l[1][i])

ans = [0]*n
for j in range(n):
    ans[j] = m1[j]+(m2[n-1]-m2[j-1])

print(max(ans))

### FIXED CODE ###

n = int(input())
l = []
for _ in range(2):
    a = list(map(int,input().split()))
    l.append(a)

if n == 1:
    print(l[0][0]+l[1][0])
    exit()

m1 = []
m2 = []
m1.append(0)
m1.append(l[0][0])
m2.append(0)
m2.append(l[1][0])

for i in range(1,n):
    m1.append(m1[i]+l[0][i])
    m2.append(m2[i]+l[1][i])

ans = [0]*n
for j in range(1,n+1):
    ans[j-1] = m1[j]+(m2[n]-m2[j-1])


print(max(ans))
n,a,b,c,d = ( int(i) for i in input().split())
s = input()

a_to_c = s[a-1:c-1]
b_to_d = s[b-1:d-1]
if (b-1)-2 >= 0:
    b_to_d2 = s[b-1-2:d-1]
elif:
    b_to_d2 = s[b-1:d-1]

possibility = True

if a_to_c.find("##")!=-1 or b_to_d.find("##")!=-1:
    possibility = False
if c>d:
    if not(b_to_d2.find('...')!=-1):
        possibility = False

if possibility:
    print("Yes")
else:
    print("No")
    

### FIXED CODE ###

n,a,b,c,d = ( int(i) for i in input().split())
s = input()

a_to_c = s[(a-1)+1:(c-1)-1 +1]

possibility = True

if c>d:
    b_to_d = s[(b-1)-1:(d-1)+1 +1]
    if "##" in a_to_c or "..." not in b_to_d:
        possibility = False
else:
    b_to_d = s[(b-1)+1:(d-1)-1 +1]
    if "##" in a_to_c or "##" in b_to_d:
        possibility = False

if possibility:
    print("Yes")
else:
    print("No")
# import sys
from math import factorial
from functools import reduce


def mmul(a, b, mod):
    return (a % mod) * (b % mod) % mod


def mfact(a, mod):
    fact = 1
    for m in range(2, a + 1):
        fact *= m % mod
        fact %= mod
    return fact


def mpow(a, b, mod):
    if b == 0:
        return 1
    if b == 1:
        return a % mod
    if b % 2 == 0:
        return mpow(a, b / 2, mod) ** 2 % mod
    return mpow(a, b // 2, mod) ** 2 * a % mod


def mdiv(a, b, mod):
    return mmul(a, mpow(b, mod - 2, mod), mod)


# (n+a)Ca = (n+a)! / n!a! mod mod for n >> a
def mnpaca(n, a, mod):
    res = 1
    for num in range(n + 1, n + a + 1):
        res *= num % mod
        res %= mod
    return mdiv(res, factorial(a), mod)

mod = 1000000007
N, M = [int(s) for s in input().split()]

prime_counts = []
i = 2
while i * i <= M:
    count = 0
    while M % i == 0:
        M /= i
        count += 1
    if count:
        prime_counts.append(count)
    i += 1
if M > 1:
    prime_counts.append(1)

res = reduce(lambda x, y: x * y, [mnpaca(N - 1, c, mod) for c in prime_counts])

print(res % mod)


### FIXED CODE ###

# import sys
from math import factorial
from functools import reduce


def mmul(a, b, mod):
    return (a % mod) * (b % mod) % mod


def mfact(a, mod):
    fact = 1
    for m in range(2, a + 1):
        fact *= m % mod
        fact %= mod
    return fact


def mpow(a, b, mod):
    if b == 0:
        return 1
    if b == 1:
        return a % mod
    if b % 2 == 0:
        return mpow(a, b / 2, mod) ** 2 % mod
    return mpow(a, b // 2, mod) ** 2 * a % mod


def mdiv(a, b, mod):
    return mmul(a, mpow(b, mod - 2, mod), mod)


# (n+a)Ca = (n+a)! / n!a! mod mod for n >> a
def mnpaca(n, a, mod):
    res = 1
    for num in range(n + 1, n + a + 1):
        res *= num % mod
        res %= mod
    return mdiv(res, factorial(a), mod)

mod = 1000000007
N, M = [int(s) for s in input().split()]

prime_counts = []
i = 2
while i * i <= M:
    count = 0
    while M % i == 0:
        M /= i
        count += 1
    if count:
        prime_counts.append(count)
    i += 1
if M > 1:
    prime_counts.append(1)

res = reduce(lambda x, y: x * y, [mnpaca(N - 1, c, mod) for c in prime_counts],
             1)

print(res % mod)
print("TFhoruere"[len(set(map(int, open(0).read().split())))-3::2])

### FIXED CODE ###

print("TFhoruere"[len(set(open(0).read().split()))-4::2])
n = input()
s, t = input().split()

for i in range(n):
  w += s[i] + t[i]

print(w)

### FIXED CODE ###

n = int(input())
s, t = input().split()
w = ''
 
for i in range(n):
    w += s[i] + t[i]
 
print(w)
import heapq

N,M = (int(i) for i in input().split())
A = list(map(int,input().split()))
A.sort()
D = []
len = 0
for i in range(M):
    B,C = (int(i) for i in input().split())
    for j in range(B):
        heapq.heappush(D,C)
        len += 1
        if len > N:
            heapq.heappop(D)
            len -= 1

for i in range(N):
    if A[0] < D[-1]:
        heapq.heapreplace(A,D[-1])
        D.pop(-1)
    else:
        break
print(sum(A))


### FIXED CODE ###

import heapq

N,M = (int(i) for i in input().split())
A = list(map(int,input().split()))
A.sort()
D = []
len = 0
BC = [0] * M

for i in range(M):
    BC[i] = list(map(int,input().split()))
BC.sort(key = lambda x:x[1],reverse = True)
for i in range(M):
    D.extend([BC[i][1]] * BC[i][0])
    len += BC[i][0]
    if len > N:
        break
cnt = min(N,len)
for i in range(cnt):
    if A[0] < D[i]:
        heapq.heapreplace(A,D[i])
    else:
        break
print(sum(A))
# -*- coding: utf-8 -*-
import math
from scipy.special import comb
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

X,Y = (int(x) for x in input().split())
count = 0
if (X+Y)%3!=0 or 2*X<Y or 2*Y<X:
    print("0")
    exit()
else:
    N=(X+Y)/3 # 合計移動回数
    mov_x=(2*X-Y)/3 #(2,1)の移動回数 ]

    #print(combinations_count(N, mov_x)%(pow(10,9)+7))
    #print(comb(N, mov_x, exact=True)%(pow(10,9)+7))
    print(cmb(int(N), int(mov_x))%(pow(10,9)+7))


### FIXED CODE ###

# -*- coding: utf-8 -*-

mod = int(1e9+7)

def comb_mod(n, r, mod):
    if n < r:
        return 0
    elif n < 0 or r < 0:
        return 0
    else:
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, n + 1):
            fac.append(fac[-1] * i % mod)
            inv.append(-inv[mod % i] * (mod // i) % mod)
            finv.append((finv[-1] * inv[-1]) % mod)
        return int(fac[n] * finv[r] * finv[n - r] % mod)

X,Y = (int(x) for x in input().split())
count = 0
if (X+Y)%3!=0 or 2*X<Y or 2*Y<X:
    print("0")
    exit()
else:
    N=(X+Y)/3 # 合計移動回数
    mov_x=(2*X-Y)/3 #(+2,+1)の移動回数
    print(comb_mod(int(N), int(mov_x), mod))
a=[input() for i in range]
c=""
for i in range(len(a[0])+2):
  c=c+"#"
print(c)
for i in range(len(a[0]+2):
  print("#"+a[i]+"#")
print(c)

### FIXED CODE ###

x,y=input().split()
x=int(x)
y=int(y)
a=[input() for i in range(x)]
c=""
for i in range(y+2):
  c=c+"#"
print(c)
for i in range(x):
  print("#"+a[i]+"#")
print(c)
a,b,c = map(int,input().split())
print('YES' if a[-1] == b[0] and b[-1] == c[0] else 'NO')

### FIXED CODE ###

a,b,c = input().split()
print('YES' if a[-1] == b[0] and b[-1] == c[0] else 'NO')
a=int(input())
for i range(1,10):
  if a//i<10:
    if a%i=0:
      print(Yes)
else:
  print(No)

### FIXED CODE ###

a=int(input())
for i in range(1,10):
  if a//i<10:
    if a%i==0:
      print('Yes')
      break
else:
  print('No')
def fact(n):
  if 1<n:
    return n + fact(n-1)
  else:
    return n


N = int(input())
A = list(map(int,input().split()))
b = int(round(float((sum(A)-fact(N)))/N))
if b<0:
    b -= 1

ans = 0

for i in range(N):
    ans += abs(A[i]-(b+i+1))

print(ans)

### FIXED CODE ###

N = int(input())
if N%2==0:
  print(N)
else:
  print(N*2)
n,q=map(int,input().split())
s=input()
a=len(s)
l=[0]*a
z=0
i=0
while i<a:
    if s[i]=='A' and s[i+1]=='C':
        z+=1
        l[i],l[i+1]=['A',z],['C',z]
        i+=2
    else:
        l[i]=['O',z]
        i+=1
for _ in range(q):
    x,y=map(int,input().split())
    for i in range(x-1,y):
        if l[i][0]=='A':
            a=l[i][1]
            break
    for i in range(y-1,x-2,-1):
        if l[i][0]=='C':
            b=l[i][1]
            break
    print(b-a+1)

### FIXED CODE ###

n,q=map(int,input().split())
s=input()
a=[0]*(n+1)
for i in range(0,n):
    if s[i-1:i+1]=="AC":
        a[i]=a[i-1]+1
    else:
        a[i]=a[i-1]

for i in range(q):
    l,r=[int(i) for i in input().split()]
    print(a[r-1]-a[l-1])
N = input()
list = input.split()
i = 0
def div_list(your_list=list):
     for v in range(N):
       if list[v] % 2 == 0:
          list_a[v] = list[v] / 2
          if v== N-1:
             i+= 1
             div_list(list_a)
      
       else:
            break
      return i
print(div_list())
  

### FIXED CODE ###

def div_count(a):
  i= 0
  while a%2 == 0:
    a = a/2
    i+=1
  return i
N = int(input())
numbers = list(map(int,input().split()))
count=[]
for u in range(N):
  count.append(div_count(numbers[u]))
print(min(count))
import copy
S = list(input())
K = int(input())


a = S[0]
c = 0
S2 = copy.deepcopy(S)
for i in range(1,len(S)):
    if S[i] == S[i-1]:
        S[i] = '1'
        c += 1
if S[0] == S[-1]:
    c3 = 0
    S3 = copy.deepcopy(S)
    for i in range(2,len(S)+1):
        if S3[i] == S3[i-1]:
            S3[i] = '1'
            c3 += 1
    print(c + c3*(K-1))
else:
    print(c*K)



### FIXED CODE ###

import copy
S = list(input())
K = int(input())


a = S[0]
c = 0
S2 = copy.deepcopy(S)
for i in range(1, len(S)):
    if S2[i] == S2[i-1]:
        S2[i] = '1'
        c += 1

a = S[-1]
last = 0
for i in range(2, len(S)+1):
    last += 1
    if S[-i] != a:
        break

if all([e == S[0] for e in S[1:]]) == True:
    if len(S)%2==0:
        print(int(len(S)/2*K))
    else:
        print(int(len(S)//2*((K+1)//2)+(len(S)//2+1)*(K//2)))
elif S[0] == S[-1] and last % 2 == 1:
    c3 = 0
    S3 = copy.deepcopy(S)
    for i in range(2, len(S)):
        if S3[i] == S3[i-1]:
            S3[i] = '1'
            c3 += 1
    print(c + (c3+1)*(K-1))
else:
    print(c*K)
N = int(input())
a = int(input())
b = int(input())

result = 0
for n in range(1, N + 1):
   sum_n = 0
   for i in str(n):
       sum_n += int(i)
   if a <= sum_n <= b:
       result += n
print(result)


### FIXED CODE ###

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

result = 0
for n in range(1, N + 1):
   sum_n = 0
   for i in str(n):
       sum_n += int(i)
   if a <= sum_n <= b:
       result += n
print(result)
# coding: utf-8

# In[54]:


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


# In[42]:


def p(n):
    return 2 ** (n+1) - 1
def b(n):
    return 2 ** (n+1) - 2
def l(n):
    return 2 ** (n+2) - 3


# In[56]:


def func(i,x):
    if x <= l(i):
        if i == 0:
            if x == 1:
                return 1
            else:
                return 0
        else:
            if x <= 2**(i+1) - 2:
                return func(i-1, x-1)
            else:
                return p(i-1) + 1 + func(i-1, x-(2**(i+1)-2)-1,)


# In[57]:


print(func(n,x))



### FIXED CODE ###


# coding: utf-8

# In[103]:


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


# In[104]:


def p(n):
    return 2 ** (n+1) - 1
def b(n):
    return 2 ** (n+1) - 2
def l(n):
    return 2 ** (n+2) - 3


# In[109]:


def func(i, x):
    if x == 0:
        return 0
    elif x <= l(i-1) + 1:
        return func(i-1, x-1)
    elif x == l(i-1) + 2:
        return p(i-1) + 1
    elif x <= 2 * l(i-1) + 2:
        return p(i-1) + 1 + func(i-1, x - l(i-1) - 2)
    else:
        return 2 * p(i-1) + 1


# In[110]:


print(func(n,x))
N=int(input())
sum=0
for _ in range(N):
    a,b=map(int,input().split())
    if(a==b):
        sum+=1
        if(sum==3):
            name=[]
            name.append("Yes")
    else:
        sum=0
    
if name[0]=="Yes":
    print("Yes")
else:
    print("No")

### FIXED CODE ###

N=int(input())
sum=0
name=[]
for _ in range(N):
    a,b=map(int,input().split())
    if(a==b):
        sum+=1
        if(sum==3):
            name.append("Yes")
    else:
        sum=0
    
if len(name)==0:
    print("No")
else:
    print("Yes")
a, b = input().split()

if a='H' and b='H':print('H')
elif a='D' and b='D':print('H')
else:print('D')

### FIXED CODE ###

a, b = input().split()

if a=='H' and b=='H':print('H')
elif a=='D' and b=='D':print('H')
else:print('D')