Harryxun/stf_run huggingface dataset:
S = input()
Q = int(input())
T = [input() for i in range(Q)]

count = True

for i in range(Q):
  t = T[i]
  if(int(t[0]) == 1):
    count = not count
  else:
    if(int(t[2]) == 1):
      if(count):
        S = f"{t[4]}{S}"
      else:
        S = f"{S}{t[4]}"
    else:
      if(count):
        S = f"{S}{t[4]}"
      else:
        S = f"{t[4]}{S}"

if(count):
  print(S)
else:
  print(S[::-1])


### FIXED CODE ###

from collections import deque
S = input()
Q = int(input())
T = [input() for i in range(Q)]

d =deque(S)

count = True

for i in range(Q):
  t = T[i]
  if(int(t[0]) == 1):
    count = not count
  else:
    if(int(t[2]) == 1):
      if(count):
        d.appendleft(t[4])
      else:
        d.append(t[4])
    else:
      if(count):
        d.append(t[4])
      else:
        d.appendleft(t[4])

ans = list(d)

if(count):
  print("".join(ans))
else:
  print("".join(ans[::-1]))
N, X, T = map(int, input().split())
if N % X == 0:
  print(N / X * T)
else:
  print((N / X + 1) * T

### FIXED CODE ###

N, X, T = map(int, input().split())
if N % X == 0:
  print(int(N / X) * T)
else:
  print(int(N / X + 1) * T)
S = str(input())

if S = 'ABC':
    print('ARC')
else:
    print('ABC')

### FIXED CODE ###

S = input()

if S == 'ABC':
    print('ARC')
else:
    print('ABC')
a = str(input())
if a==000:
    print(0)
eif a==001 or 010 or 100:
    print(1)
elif a==111:
    print(3)
else:
    print(2)   

### FIXED CODE ###

a = int(input())
print(a%9)
s=list(input())
t=list(input())
s1=s.sort()
t1=t.sort()
if s1<t1:
  print("Yes")
else:
  print("No")
  

### FIXED CODE ###

s=list(input())
t=list(input())
s.sort()
t.sort(reverse=True)
if s<t:
  print("Yes")
else:
  print("No")
#54b
n,m =map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]

for i in range(n-m+1):
    for j in range(n-m+1):
        t = [k[j:j+m] for k in a[i:i+m]]
        if t==b:
            print('Yes')
            exit()
print('No')

### FIXED CODE ###

#54a
a,b =map(int,input().split())
if a==b:
    print('Draw')
elif a==1 :
    print('Alice')
elif b==1:
    print('Bob') 
elif a>b:
    print('Alice')
else :
    print('Bob')
import functools

def gcd(a,b):
    while b > 0:
        a, b = b, a % b
    return a
    
def lcm(a, b):
    return a * b / gcd(a, b)

N = int(input())
a = list(map(int, input().split()))
assert(len(a) == N)

lcmVal = int(functools.reduce(lcm, a))
print(lcmVal)
print(sum(map(lambda x: (lcmVal-1) % x, a)))


### FIXED CODE ###

import functools

def gcd(a,b):
    while b > 0:
        a, b = b, a % b
    return a
    
def lcm(a, b):
    return a * b / gcd(a, b)

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

lcmVal = int(functools.reduce(lcm, a, 0))
print(sum(map(lambda x: (lcmVal-1) % x, a)))
import math


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


N = int(input())
t_li = []
for _ in range(N):
    t_li.append(int(input()))
ans = lcm(t_li[0], t_li[1])
for i in range(2, N):
    ans = lcm(ans, t_li[i])
print(ans)


### FIXED CODE ###

import math


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


N = int(input())
t_li = []
for _ in range(N):
    t_li.append(int(input()))
if N > 1:
    ans = lcm(t_li[0], t_li[1])
    for i in range(2, N):
        ans = lcm(ans, t_li[i])
else:
    ans = t_li[0]
print(ans)
S = list(input())

ans = [0]*(len(S))
cnt = 0
for i in range(len(S)-1):
    cnt += 1
    if S[i] == "R" and S[i+1] =="L":
        ans[i] += -(-cnt//2)
        ans[i+1] += cnt//2
        x = i
        cnt = 0
    if S[i] == "L" and S[i+1] =="R" or :
        ans[x] += cnt//2
        ans[x+1] += -(-cnt//2)
        cnt = 0
    if i == len(S)-2:
        cnt += 1
        ans[x] += cnt//2
        ans[x+1] += -(-cnt//2)    

print(*ans)

### FIXED CODE ###

S = input()

ans = [0]*(len(S))
cnt = 0
for i in range(len(S)-1):
    cnt += 1
    if S[i] == "R" and S[i+1] =="L":
        ans[i] += -(-cnt//2)
        ans[i+1] += cnt//2
        x = i
        cnt = 0
    if S[i] == "L" and S[i+1] =="R":
        ans[x] += cnt//2
        ans[x+1] += -(-cnt//2)
        cnt = 0
    if i == len(S)-2:
        cnt += 1
        ans[x] += cnt//2
        ans[x+1] += -(-cnt//2)    

print(*ans)
n,m=map(int,input().split())
r={}
for _ in range(m):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  #print(a,b)
  if a not in r: r[a]=[]
  r[a].append(b)
  if b not in r: r[b]=[]
  r[b].append(a)

ans = {0:0}
steps = [-1]*n
steps[0]=0
def setroot(i,step):
  newroom = [v for v in r[i] if steps[v]<0 or steps[v]>step]
  #print(i,newroom)
  if len(newroom)>0:
    for v in newroom:ans[v]=i;steps[v]=step
    for v in newroom:setroot(v,step+1)
setroot(0,1)
#print(r)
#print(steps)
if len(ans) < n:
  print('No')
  #exit()
else:
  print('Yes')
  for i in range(1,n):
    print(ans[i]+1)

### FIXED CODE ###

f=lambda:map(int,input().split())
n,m=f()
g=[[] for _ in range(n)]
for _ in range(m):
  a,b=f()
  g[a-1]+=[b-1]
  g[b-1]+=[a-1]
p=[0]*n
from collections import*
q=deque([0])
while q:
  v=q.popleft()
  for c in g[v]:
    if p[c]<1: p[c]=v+1; q.append(c)
if 0 in p: print('No')
else: print('Yes',*p[1:],sep='\n')
N = int(input())
A = list(map(int,input().split()))

num_count = [0]*(10**5+1)
tmp_sum = sum(A)
for i in A:
    num_count[i] += 1

for q in range(int(input()):
    B,C = map(int,input().split())
    gain = C*(num_count[B])
    loss = B*(num_count[B])
    num_count[C] += num_count[B]
    num_count[B] = 0
    tmp_sum = tmp_sum + gain - loss
    print(tmp_sum)


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
import numpy as np

num_count = [0]*(10**5+1)
num_count = np.array(num_count)
tmp = np.arange(10**5+1)
tmp_sum = sum(A)
for i in A:
    num_count[i] += 1

for q in range(Q):
    B,C = map(int,input().split())
    tmp_C = C*(num_count[B])
    tmp_B = B*(num_count[B])
    num_count[C] += num_count[B]
    num_count[B] = 0
    tmp_sum = tmp_sum + tmp_C - tmp_B
    print(tmp_sum)
n=int(input())
a=list(map(int,input().split()))
ans=[]
p=a[0]^a[1]^a[2]^a[3]
for i in range(n):
  k=p^a[i]
  ans.append(k)
print(*ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=[]
p=0
for i in range(n):
  p=p^a[i]
  
for i in range(n):
  k=p^a[i]
  ans.append(k)
print(*ans)
import sys
input=sys.stdin.readline
n,m = map(int, input().split())
link = defaultdict(list)
for _ in range(m):
    p,q,c=map(int, input().split())
    p-=1
    q-=1
    c-=1
    link[(p,-1)].append([(p,c),1])
    link[(p,c)].append([(p,-1),1])
    link[(p,c)].append([(q,c),0])
    link[(q,c)].append([(p,c),0])
    link[(q,-1)].append([(q,c),1])
    link[(q,c)].append([(q,-1),1])

### FIXED CODE ###

import sys
input=sys.stdin.readline
from collections import defaultdict
from heapq import heappush, heappop,heappushpop,heapify
n,m = map(int, input().split())
link = defaultdict(list)
chg=10**8
for _ in range(m):
    p,q,c=map(int, input().split())
    link[p].append([p+chg*c,1])
    link[p+chg*c].append([p,1])

    link[q+chg*c].append([p+chg*c,0])
    link[p+chg*c].append([q+chg*c,0])

    link[q+chg*c].append([q,1])
    link[q].append([q+chg*c,1])

def dks(g,start):
    INF=float('inf')
    visited = set()
    hq = []
    heappush(hq, (0,start))
    while hq:
        shortest, i = heappop(hq)
        if i in visited:
            continue
        visited.add(i)
        for j, t in g[i]:
            if j in visited:
                continue
            if j==n:
                return (shortest+t)//2
            heappush(hq, (shortest + t, j))
    return -1
ans=dks(link,1)
print(ans)
n= []
n = n.append(int(input()))
for i in range(n):
	if n[i] == 0:
		break
	print('case ',i+1, ': ', n[i], sep='')

### FIXED CODE ###

### 17.07.2017
n = []
while (True):
	x = int(input())
	if x == 0:
		break
	n.append(int(x))
a = 0
for i in n:
	print('Case ',a+1, ': ', n[a], sep='')
	a += 1
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())

x0, y0, h0 = map(int, input().split())
for i in range(N):
  xi, yi, hi = map(int, input().split())
  if xi-x0 == abs(xi-x0):
    hx = hi + (100 -xi)
  else:
    hx = hi +xi

  if yi-y0 == abs(yi-y0):
    hy = hx + (100 -yi)
  else:
    hy = hx +yi

print(hy)

### FIXED CODE ###

N = int(input())
arr = [list(map(int, input().split())) for _ in range(N)]
arr.sort(key=lambda l:-l[2])
 
for cx in range(101):
  for cy in range(101):
    ch = None
    for x, y, h in arr:
      t = h + abs(cx-x) + abs(cy-y)
      if h > 0:
        if ch is not None and t != ch:
          break
        ch = t
      else:
        if t < ch:
          break
    else:
      print(cx, cy, ch)
      exit()
h, w = [int(i) for i in input().split()]
a = []
d = []
h_new = 0
for i in range(h):
  b = input()
  if "#" in b:
    a.append(list(b))
    h_new += 1
for i in range(w):
  c = []
  for j in range(h_new):
    c.append(a[j][i])
  if "#" not in c:
    d.append(i)
e = ""
for i in d:
  for j in range(h_new):
    del a[j][i]
for i in range(h_new-1):
  e += "".join(a[i]) +"\n"
e += "".join(a[h_new-1])
print(e)

### FIXED CODE ###

h, w = [int(i) for i in input().split()]
a = []
d = []
h_new = 0
for i in range(h):
  b = input()
  if "#" in b:
    a.append(list(b))
    h_new += 1
for i in range(w):
  c = []
  for j in range(h_new):
    c.append(a[j][i])
  if "#" not in c:
    d.append(i)
e = ""
for i in range(h_new):
  for j in range(w):
    if j not in d:
      print(a[i][j],end="")
  print("\n")
import sys
def input(): return sys.stdin.readline().strip()

n=int(input())
xs=input()
xj=xs.count("1")

x=int(xs,2)
xip=x%(xj+1)
xim=x%(xj-1)

i1=1<<n
for i in range(n-1,-1,-1):
    i1=i1>>1
    xi=x^i1
    if xi==0:
        print(0)
        continue
    if xs[n-1-i]=="0":
        pxi=xj+1
#        xi=(xip+i1%pxi)%pxi
#        xi=(xip+i1)%pxi
    else:
        pxi=xj-1
#        xi=(xim-i1%pxi)%pxi
#        xi=(xim-i1)%pxi
    xi=xi%pxi
    if xi==0:
        print(1)
        continue
    icnt=1
    while xi>0:
#        print("i",i,"xi",xi,"icnt",icnt)
        icnt+=1
        xi=xi%(bin(xi).count("1"))
    print(icnt)

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()

n=int(input())
xs=input()
xj=xs.count("1")

x=int(xs,2)
xip=x%(xj+1)
if xj!=1:
    xim=x%(xj-1)

for i in range(n-1,-1,-1):
    if xs[n-1-i]=="0":
        pxi=xj+1
        i2=pow(2,i,pxi)
        xi=(xip+i2)%pxi
    elif xj==1:
        print(0)
        continue
    else:
        pxi=xj-1
        i2=pow(2,i,pxi)
        xi=(xim-i2)%pxi
    xi=xi%pxi
    if xi==0:
        print(1)
        continue
    icnt=1
    while xi>0:
#        print("i",i,"xi",xi,"icnt",icnt)
        icnt+=1
        xi=xi%(bin(xi).count("1"))
    print(icnt)
a,b,c,d=map(int,input().split())
cwari=b//c-(a-1)//c
dwari=b//d-(a-1)//d
import math
cd=math.gcd(c,d)
cdwari=b//cd-(a-1)//cd
print(cwari)

ans=(b-a)+1-cwari-dwari+cdwari
print(ans)

### FIXED CODE ###

a,b,c,d=map(int,input().split())
cwari=b//c-(a-1)//c
dwari=b//d-(a-1)//d
import fractions
l=int(c*d/fractions.gcd(c,d))
cdwari=b//l-(a-1)//l
ans=(b-a)+1-cwari-dwari+cdwari
print(ans)
a=map(int,input().split())
a.sort()
if a[0]+a[1]==a[2]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a=map(int,input().split())
a=list(a)
a.sort()
if a[0]+a[1]==a[2]:
  print("Yes")
else:
  print("No")
dice_a = list(map(int,input().split()))
dice_b = list(map(int,input().split()))
dice_a_roll = []


for i in range(6):
    if dice_a[i] == dice_b[0]:
        b_top = i + 1
    if dice_a[i] == dice_b[1]:
        b_front = i + 1


if b_top == 1:
    order=[2,3,5,4,2,3,5]
    for k in range(4):
        if b_front == order[k]:
            spots = [1, order[k], order[k+1], order[k+3], order[k+2], 6]

elif b_top == 2:
    order=[6,3,1,4,6,3,1]
    for k in range(4):
        if b_front == order[k]:
            spots = [2, order[k], order[k+1], order[k+3], order[k+2], 5]

elif b_top == 3:
    order=[2,6,5,1,2,6,5]
    for k in range(4):
        if b_front == order[k]:
            spots = [3, order[k], order[k+1], order[k+3], order[k+2], 4]

elif b_top == 4:
    order=[2,1,5,6,2,1,5]
    for k in range(4):
        if b_front == order[k]:
            spots = [4, order[k], order[k+1], order[k+3], order[k+2], 3]

elif b_top == 5:
    order=[1,3,6,4,1,3,6]
    for k in range(4):
        if b_front == order[k]:
            spots = [5, order[k], order[k+1], order[k+3], order[k+2], 2]

elif b_top == 6:
    order=[2,4,5,3,2,4,5]
    for k in range(4):
        if b_front == order[k]:
            spots = [6, order[k], order[k+1], order[k+3], order[k+2], 1]


for l in spots:
    dice_a_roll.append(dice_a[l-1])


if dice_a_roll == dice_b:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

class dice:
    def __init__(self,label):
        self.spots = label

    def roll(self,way):
        if way == "N":
            self.spots = [self.spots[1],self.spots[5],self.spots[2],self.spots[3],self.spots[0],self.spots[4]]
        if way == "E":
            self.spots = [self.spots[3],self.spots[1],self.spots[0],self.spots[5],self.spots[4],self.spots[2]]
        if way == "W":
            self.spots = [self.spots[2],self.spots[1],self.spots[5],self.spots[0],self.spots[4],self.spots[3]]
        if way == "S":
            self.spots = [self.spots[4],self.spots[0],self.spots[2],self.spots[3],self.spots[5],self.spots[1]]
    def output(self):
        return self.spots


dice_1 = list(map(int,input().split()))
label = list(map(int,input().split()))
dice_2 = []

rotation = dice(label)
for i in range(3):
    dice_2.append(rotation.output())
    for j in range(3):
        rotation.roll("E")
        dice_2.append(rotation.output())
    rotation.roll("N")

rotation.roll("N")
rotation.roll("N")

for i in range(3):
    dice_2.append(rotation.output())
    for j in range(3):
        rotation.roll("W")
        dice_2.append(rotation.output())
    rotation.roll("N")

if dice_1 in dice_2:
    print("Yes")
else:
    print("No")
N, M = list(map(int, input().split()))

g = [[] for _ in range(N)]

for i in range(N):
  a, b = list(map(int, input().split()))
  g[a-1].append(b-1)
  g[b-1].append(a-1)

visited = [False for _ in range(N)]

def dfs(v, visited):
  if all(visited):
    return 1
  total = 0
  for cv in g[v]:
    if not visited[cv]:
      visited[cv] = True
      total += dfs(v, visited)
      visited[cv] = False
  return total
    
visited[0] = True
ret = dfs(0, visited)
print(ret)
  

### FIXED CODE ###

import itertools
 
N, M = map(int, input().split())
graph = [[0] * N for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    graph[a-1][b-1] = 1
    graph[b-1][a-1] = 1
 
p = list(itertools.permutations(range(N)))
 
Sum = 0
 
for i in range(len(p)):
    if p[i][0] != 0:
        break
    for j in range(N - 1):
        if graph[p[i][j]][p[i][j + 1]] != 1:
            break
        elif j == N - 2:
            Sum += 1
 
print(Sum)
n=int(input())

s=input()
X=int(s,2)

one_cnt=s.count("1")

modp=[0]*n
modm=[0]*n

for i in range(n):
    modp[i]=(pow(2,(n-i-1),one_cnt+1)*int(s[i]))%(one_cnt+1)
    modm[i]=(pow(2,(n-i-1),one_cnt-1)*int(s[i]))%(one_cnt-1)

ans=[]

#print(modp,modm)

for i in range(n):
    cnt=0
    mod=0

    for j in range(n):
        if s[i]=="1":
            if i!=j:
                mod=(mod+modm[j])%(one_cnt-1)
        else:
            if i!=j:
                mod=(mod+modp[j])%(one_cnt+1)
            else:
                mod=(mod+2**(n-i-1))%(one_cnt+1)
    cnt=1

   # print(i,mod)

    if mod==0:
        ans.append(cnt)
    else:
        while 1:
            cnt+=1
            mod=mod%(bin(mod).count("1"))
            if mod==0:
                ans.append(cnt)
                break
            #print(mod,one_cnt,s[i],cnt)




#print(ans_memo)

for item in ans:
    print(item)
            









### FIXED CODE ###

def popcount(x):
    return bin(x).count("1")

n=int(input())
s=input()
X=int(s,2)

one_cnt=popcount(X)

modp=X%(one_cnt+1)
modm=X%(one_cnt-1) if one_cnt-1!=0 else 0

for i in range(n):
    if s[i]=="1":
        if one_cnt-1==0:
            print(0)
            continue
        else:
            num=(modm-pow(2,n-i-1,one_cnt-1))%(one_cnt-1)
    else:
        num=(modp+pow(2,n-i-1,one_cnt+1))%(one_cnt+1)

    #print(i,"num",num)
    cnt=1
    while num!=0:
        num=num%popcount(num)
        cnt+=1
    print(cnt)
x=input()
x1=len(x)
if x1 %2 == 0
	if "hi"*x1 == s:
		print("Yes")
	else
		print("No")
else:
  print("No")

### FIXED CODE ###

x=input()
if x == 'hi':
	print('Yes')
elif x == 'hihi':
	print('Yes')
elif x == 'hihihi':
	print('Yes')
elif x == 'hihihihi':
	print('Yes')
elif x == 'hihihihihi':
	print('Yes')
else:
	print('No')
import collections
 
n = int(input())
v = [int(i) for i in input().split()]
 
v1 = [v[i] for i in range(0,n,2)]
v2 = [v[i] for i in range(1,n,2)]
 
count1 = collections.Counter(v1).most_common(2)
count2 = collections.Counter(v2).most_common(2)

if max(count1.values()) != max(count2.values()):
    res = len(v1) - max(count1.values()) + len(v2) - max(count2.values())
    print(res)
else:
    if len(count1) == 1:
        print(len(v1))
    else:
        res1 = len(v1) - count1[0][1] + len(v2) - count2[1][1]
        res2 = len(v1) - count1[1][1] + len(v2) - count2[0][1]
        print(min(res1,res2))


### FIXED CODE ###

N = list(input())

r = []

for i in N:
    if i == '1':
        r.append('9')
    else:
        r.append('1')

print(''.join(r))
n,k=map(int,input().split())
h=list(int(input())for i in range(n))
h.sort()
l=[]
for i in range(n-k+1):
    l.append(h[k-i+1]-h[i])


print(min(h))


### FIXED CODE ###

n,k=map(int,input().split())
h=list(int(input())for _ in range(n))
h.sort()
l=[]
for i in range(n-k+1):
    l.append(h[k+i-1]-h[i])


print(min(l))
from fractions import gcd

N, M = map(int,input().split())
S = list(input())
T = list(input())

gc = gcd(N, M)

ans = N*M//gc

for i in range(lcm//max(N, M)):
    if S[N//gc*i] != T[M//gc*i]:
        ans = -1
        break
                
print(ans)

### FIXED CODE ###

from fractions import gcd
N,M=map(int,input().split())
S=list(input())
T=list(input())
L=gcd(N,M)
print(N*M//L if all([S[i*N//L]==T[i*M//L] for i in range(L)]) else "-1")
N = input()
ans = 0
for x in N:
  if x == '1'
    ans += 1
  else:
    pass
print(ans)

### FIXED CODE ###

N = input()
ans = 0
for x in N:
  if x == '1':
    ans += 1
  else:
    pass
print(ans)
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
from itertools import permutations,groupby
import sys
import bisect
import string
alp=string.ascii_lowercase
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7
#mo=998244353
#input=sys.stdin.readline

n,k=MI()
a=LI()
c=[0]*(n+1)
t=[0]*(n+1)
for i in range(n):
    c[a[i]]+=1
    tmp=0
    for j in range(i):
        tmp+=1 if a[j]>a[i] else 0
    t[i]=tmp

A=[0]
for i in c:
    A+=[i+A[-1]]
q=0
for i in range(n):
    q+=A[a[i]]
#q=sum(A[:-1])
q%=mo
q*=k*(k-1)//2
q%=mo

ans=k*sum(t)%mo
ans+=q
print(ans%mo)
#print(c,A,t,ans%mo)

### FIXED CODE ###

from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
from itertools import permutations,groupby
import sys
import bisect
import string
alp=string.ascii_lowercase
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7
#mo=998244353
#input=sys.stdin.readline

n,k=MI()
a=LI()
c=[0]*(2000+10)
t=[0]*(2000+10)
for i in range(n):
    c[a[i]]+=1
    tmp=0
    for j in range(i):
        tmp+=1 if a[j]>a[i] else 0
    t[i]=tmp

A=[0]
for i in c:
    A+=[i+A[-1]]
q=0
for i in range(n):
    q+=A[a[i]]
#q=sum(A[:-1])
q%=mo
q*=k*(k-1)//2
q%=mo

ans=k*sum(t)%mo
ans+=q
print(ans%mo)
#print(c,A,t,ans%mo)
import fractions
from functools import reduce


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

MOD = 1e9+7
N = input()
i = 0
arrs = list(map(int, input().split()))
lcms = lcm_list(arrs)
result = 0
for arr in arrs:
    result = (result+lcms/arr) % MOD

print(int(result))

### FIXED CODE ###


from fractions import gcd
MOD = 10**9+7
N = input()
i = 0
arrs = list(map(int, input().split()))
result = 0
lcms = 1
for number in arrs:
    lcms = (((number * lcms)) //(gcd(number, lcms)))
for arr in arrs:
    result += (lcms//arr)
result = result%MOD
ans = str(result).replace('.0','')
print(ans)
N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
count=0
if sum(A)<sum(B):
    print(-1)
else:
    dif=[A[i]-B[i] for i in range(N)]
    if min(dif)>=0:
        print(0)
    else:
        difsort=sorted(dif)
        pluslist=[i for i in difsort if i>=0]
        zero=difsort.index(pluslist[0])
        minum=len(difsort[:zero])
        maxsort=difsort[::-1]
        absum=abs(sum(difsort[:zero]))
        sumlist=[sum(maxsort[0:i+1]) for i in range(len(pluslist)-1)]
        while sumlist[count]<absum:
            count+=1
        
        print(count+1+minum)

### FIXED CODE ###

N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
count=0
if sum(A)<sum(B):
    print(-1)
else:
    dif=[A[i]-B[i] for i in range(N)]
    if min(dif)>=0:
        print(0)
    else:
        difsort=sorted(dif)
        plist=[i for i in difsort if i>=0][::-1]
        mlist=[i for i in difsort if i<0]
        mnum=len(mlist)
        msum=sum(mlist)
        for i in range(len(plist)):
            if msum>=0:
                break
            msum+=plist[i]
            count+=1
            
        
        print(count+mnum)
n = input()
a = input()
b = input()

if n*a <= b:
  print(n*a)
else:
  print(b)

### FIXED CODE ###

n,a,b = map(int, input().split())
print(min(n*a,b))
import sys
input = sys.stdin.readline
import math
def solve():
  a,b,x = (int(i) for i in input().split())
  L  = a*a*b
  if L <= x:
    print(0)
  else:
    mi = 0
    ma = 89.999999999
    while ma-mi >= 10**(-9):
      next = (mi+ma)/2
      bairitu = math.tan(math.radians(next))
      if x >= L/2 :
        lim = L-(a**3/2)*round(bairitu, 10)
      else:
        lim = a**2/2*b*math.tan(math.radians(next-si))
      if x > lim:
        ma  = next
      else:
        mi = next
    print(ma)
solve()

### FIXED CODE ###

import sys
input = sys.stdin.readline
import math
def solve():
  a,b,x = (int(i) for i in input().split())
  L  = a*a*b
  if L <= x:
    print(0)
  else:
    mi = 0
    ma = 89.999999999
    while ma-mi >= 10**(-9):
      next = (mi+ma)/2
      bairitu = math.tan(math.radians(next))
      if x >= L/2 :
        lim = L-(a**3/2)*round(bairitu, 10)
      else:
        lim = (0.5)*a*b*b*math.tan(math.radians(90-next))
      if x > lim:
        ma  = next
      else:
        mi = next
    print(ma)
solve()
S = raw_input()
K = int(raw_input())

def func(ms):
    r = 0
    k = 0
    m = ms[0]
    for i in range(1, len(ms)):
        if ms[i] == ms[i-1]:
            k+=1
        else:
            r += int((k+1)/2)
            k = 0
        m = ms[i]
    r += int((k+1)/2)
    return r            

m = S[0]
f = True
for i in range(1, len(S)):
        if S[i]  != S[i-1]:
            f = False
            
if f == True:
    if len(S) == 1:
        print(int(K/2))
    else:
        print(int(len(S) * K / 2))
elif len(set(S)) == len(S):
    print(0)
elif S[0] == S[-1]:
    r = 0
    m = S[0]
    f = 0
    for c in S:
        if c == m:
            r += 1
            f += 1
        else:
            break   
    s = S[::-1]
    fe = 0
    for c in s:
        if c == m:
            r += 1
            fe += 1
        else:
            break
    S = S[f:-fe]
    tr = int(r/2) * (K-1)
    r = func(S) * K
    print(r+tr)
else:
    r = 0
    k = 0
    m = S[0]
    for i in range(1, len(S)):
        if S[i] == S[i-1]:
            k+=1
        else:
            r += int((k+1)/2)
            k = 0
        m = S[i]
    r += int((k+1)/2)
    print(r*K)
    
    
    
  


### FIXED CODE ###

s=input()
k=int(input())
if len(set(list(s)))==1:print((len(s)*k)//2);exit()
t=[1]
for i in range(1,len(s)):
  if s[i-1]==s[i]:t[-1]+=1
  else:t.append(1)
a=0
for i in t:a+=(i//2)*k
if s[0]==s[-1]:
  if t[0]%2==t[-1]%2==1:a+=k-1
print(a)