CodeEff/ECCO huggingface dataset:
# Original solution
n,s = (int(i) for i in input().split())
x = list(int(i) for i in input().split())
x = sorted(x)
if n>1:
    dif = []
    for i in range(n-1):
        dif.append(x[i+1]-x[i])

    difs = []
    for i in range(n):
        difs.append(abs(s-x[i]))
    res = min(min(dif),min(difs))
    for i in range(res):
        flag = True
        for j in range(n-1):
            if dif[j]%(res-i)!=0:
                flag = False
                break
        if flag:
            res -= i
            break
                
    print(res)
else:
    print((abs(x[0]-s)))

# Optimized solution
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()
dist = [abs(x[0]-X)]
for i in range(N - 1):
    dist.append(x[i + 1] - x[i])

# dist内の最大公約数を求めればよい
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
res = dist[0]
for i in range(1, N):
    res = gcd(res, dist[i])

print(res)
# Original solution
def gcd(a,b):
    while b != 0:
        a, b = b, a%b
#        print(a,b)
    return(a)

def main():    
    N,X = list(map(int,input().split()))
    x = list(map(int,input().split()))
    for i in range(N):
        x[i] = abs(x[i]-X)
    while len(x) > 1:
#        print(x[0],x[1])
        y = gcd(x[0],x[1])
        x.pop(0)
        x.pop(0)
        x.insert(0,y)
#        print(x)
    print((x[0]))

if __name__ == "__main__":
    main()

# Optimized solution
def gcd(a,b):
    while b != 0:
        a, b = b, a%b
    return(a)

def main():    
    N,X = list(map(int,input().split()))
    x = list(map(int,input().split()))
    for i in range(N):
        x[i] = abs(x[i]-X)
    y = x[0]
    for i in range(N):
        if x[i]%y == 0:
            continue
        y = gcd(y,x[i])
    print(y)

if __name__ == "__main__":
    main()
# Original solution
n=list(map(int,input().split()))
Y=list(map(int,input().split()))
XX=[abs(Y[i]-n[1]) for i in range(n[0])]
X=sorted(XX)
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y) 
for i in range(n[0]-1):
    X[0]=gcd(X[0],X[1])
    X=[X[0]]+X[2:]
print((max(X)))

# Optimized solution
n=list(map(int,input().split()))
Y=list(map(int,input().split()))
XX=[abs(Y[i]-n[1]) for i in range(n[0])]
X=sorted(XX)
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y) 
ans=X[0]
for i in range(n[0]-1):
    ans=gcd(ans,X[i])
print(ans)
# Original solution
n, x = list(map(int, input().split()))
xlis = list(map(int, input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
if n > 1:
    d = gcd(abs(xlis[0]-x), abs(xlis[1]-x))
    for i in range(2, n):
        d = gcd(d, abs(xlis[i]-x))
    print(d)
else:
    print((abs(xlis[0] - x)))

# Optimized solution
n, x = list(map(int, input().split()))
xlis = list(map(int, input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
d = 0
for i in range(n):
    d = gcd(d, abs(xlis[i]-x))
print(d)
# Original solution
# abc109c

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

N,X = list(map(int,input().split()))
x = list(map(int,input().split()))

x.append(X)
x.sort()
diff = [x[1]-x[0]]
for i in range(N):
    diff.append(x[i+1]-x[i])

D = gcd(diff[0],diff[1])
for i in range(2,N+1):
    D = gcd(D,diff[i])
print(D)

# Optimized solution
def gcd(a, b):
    if a < b:
        a, b = b, a
    r = a % b
    if r == 0:
        return b
    return gcd(r, b)

N,X = list(map(int,input().split()))
x = list(map(int,input().split()))

x.append(X)
x.sort()
diff = [x[1]-x[0]]
for i in range(N):
    diff.append(x[i+1]-x[i])

D = gcd(diff[0],diff[1])
for i in range(2,N+1):
    D = gcd(D,diff[i])
print(D)
# Original solution
from functools import reduce
from math import gcd
n,x = list(map(int,input().split()))
a = list(map(int,input().split()))
b = []
for ai in a:
    b.append(abs(ai-x))
print((reduce(gcd,b)))

# Optimized solution
from functools import reduce
from math import gcd
n,x = list(map(int,input().split()))
a = list(map(int,input().split()))
print((reduce(gcd,(abs(ai-x) for ai in a))))
# Original solution
from functools import reduce
from math import gcd
n,x = list(map(int,input().split()))
a = list(map(int,input().split()))
print((reduce(gcd,(abs(ai-x) for ai in a))))

# Optimized solution
from functools import reduce
from math import gcd
n, x = list(map(int, input().split()))
print((reduce(gcd, (abs(ai - x) for ai in map(int,input().split())))))
# Original solution
N, X = list(map(int,input().split()))
x = list(map(int,input().split()))

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

sub_list = []
for i in range(N):
  sub_list.append(abs(x[i] - X))
ans = sub_list[0]
for i in range(N):
  if(sub_list[i]%ans != 0):
    ans = gcd(ans, sub_list[i])
print(ans)

# Optimized solution
N, X = list(map(int,input().split()))
x = list(map(int,input().split()))

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

subs = []
for i in range(N):
  subs.append(abs(x[i] - X))
ans = subs[0]
for sub in subs:
  if(sub%ans != 0):
    ans = gcd(ans, sub)
print(ans)
# Original solution
N, X = list(map(int,input().split()))
x = list(map(int,input().split()))

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m
tmp = [abs(X-xx) for xx in x]
ans = tmp[0]
for i in range(1,N):
  ans = gcd(ans, tmp[i])
print(ans)

# Optimized solution
def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

def ans():
  N, X = list(map(int,input().split()))
  x = list(map(int,input().split()))
  xx = [abs(X-n) for n in x]
  res = xx[0]
  for i in range(1,N):
    res = gcd(res, xx[i])
  print(res)
ans()
# Original solution
N,X=list(map(int,input().split()))
x=list(map(int,input().split()))

diffx=[abs(X-x[i]) for i in range(N)]
minDiff=min(diffx)
isFinished=0
for i in range(minDiff,0,-1):
    if minDiff%i==0:
        canDivide=1
        for j in range(N):
            if diffx[j]%i:
                canDivide=0
                break
        if canDivide:
            print(i)
            isFinished=1
            break
    if isFinished:
        break


# Optimized solution
N,X=list(map(int,input().split()))
x=list(map(int,input().split()))
diffx=[abs(X-x[i]) for i in range(N)]

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

gcd=diffx[0]
for i in range(1,N):
    gcd=euclid(diffx[i],gcd)
print(gcd)
# Original solution
import sys
sys.setrecursionlimit(10**6)
import math
def ggcd(a):
    if len(a)==0:
        return 0
    i=0
    return math.gcd(a[i],ggcd(a[i+1:]))
n,x=list(map(int,input().split()))
a=list(map(int,input().split()))
b=[]
for i in range(n-1):
    b.append(abs(a[i]-a[i+1]))
c=ggcd(b)
d=abs(x-a[0])
print((math.gcd(c,d)))

# Optimized solution
n,x=list(map(int,input().split()))
a=list(map(int,input().split()))
b=[]
if n==1 and x==a[0]:
    print((max(x,10**9-x)))
    exit()
for i in range(n):
    b.append(abs(a[i]-x))
import math
c=0
for i in range(n):
    c=math.gcd(c,b[i])
    if c==1:
        break
print(c)
# Original solution
N,X = list(map(int,input().split()))
L = list(map(int,input().split()))
for i in range(N):
  L[i] = abs(L[i]-X)
L.sort()
L.reverse()
def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd(b,a%b)
def listgcd(L):
  p = L[0]
  for i in range(1,N):
    p = gcd(p,L[i])
  return p
if len(L) >= 2:
  print((listgcd(L)))
else:
  print((L[0]))

# Optimized solution
N,X = list(map(int,input().split()))
L = list(map(int,input().split()))
for i in range(N):
  L[i] = abs(L[i]-X)
L.sort()
def gcd(x,y):
  while y != 0:
    k = x
    x = y
    y = k%y
  return x
cur = L[0]
for i in range(1,N):
  cur = gcd(L[i],cur)
print(cur)
# Original solution
import sys
input = sys.stdin.readline

def gcd(a, b):
    while a > 0:
        if a < b:
            a, b = b, a
        a = a % b
    return b

def main():
    n, x = list(map(int, input().split()))
    distance = (abs(x - int(y)) for y in input().split())

    res = next(distance)
    for d in distance:
        res = gcd(res, d)

    print(res)

if __name__ == "__main__":
    main()

# Optimized solution
import sys
input = sys.stdin.readline

def gcd(a, b):
    while a > 0:
        if a < b:
            a, b = b, a
        a = a % b
    return b

def main():
    n, x = list(map(int, input().split()))
    town = list(map(int, input().split()))

    distance = (abs(x-y) for y in town)
    res = next(distance)
    for d in distance:
        if d % res != 0:
            res = gcd(res, d)

    print(res)

if __name__ == "__main__":
    main()
# Original solution
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b > 0:
        a = a % b
        a, b = b, a
    return a

def main():
    n, x = list(map(int, input().split()))
    town = list(map(int, input().split()))

    distance = (abs(x-y) for y in town)
    res = next(distance)
    for d in distance:
        if d % res != 0:
            res = gcd(res, d)

    print(res)

if __name__ == "__main__":
    main()

# Optimized solution
import sys
input = sys.stdin.readline

def gcd(a, b):
    while a > 0:
        if a < b:
            a, b = b, a
        a = a % b
    return b

def main():
    n, x = list(map(int, input().split()))
    town = list(map(int, input().split()))

    distance = (abs(x-y) for y in town)
    res = next(distance)
    for d in distance:
        if d % res != 0:
            res = gcd(res, d)

    print(res)

if __name__ == "__main__":
    main()
# Original solution
N,X=list(map(int,input().split()))
x=list(map(int,input().split()))
x.append(X)
x=sorted(x)
dif=[0]*(len(x)-1)
for i in range(len(x)-1):
  dif[i]=x[i+1]-x[i]

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

ans=dif[0]
for i in range(1,len(dif)):
  ans=gcd(ans,dif[i])

print(ans)

# Optimized solution
n,x=list(map(int,input().split()))
p=sorted(list(map(int,input().split())))
def gcd(a,b):
  if a<b:
    a,b=b,a
  while a%b>0:
    a,b=b,a%b
  return b
ans=abs(x-p[0])
for i in range(1,n):
  ans=gcd(ans,p[i]-p[i-1])
  
print(ans)
# Original solution
n,x=list(map(int,input().split()))
l=list(map(int,input().split()))

def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list

if n==1:
    print((abs(x-l[0])))
else:
    l.append(x)
    minimum=min(l)
    maximum=max(l)
    delta=maximum-minimum
    if delta==1:
        print((1))
    else:
        kouho=make_divisor_list(delta)
        ans=1
        for num in kouho:
            signal=1
            j=0
            while(j<n):
                if (l[j]-minimum)%num!=0:
                    signal=0
                    break
                else:
                    j+=1
            if signal==1:
                ans=num
        print(ans)


# Optimized solution
n,x=list(map(int,input().split()))
l=list(map(int,input().split()))

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

kouho=[abs(l[i]-x) for i in range(n)]

ans=kouho[0]

for i in range(n-1):
  ans = gcd(ans,kouho[i+1])
  
print(ans)
# Original solution
N,X = list(map(int,input().split()))
list = [int(x) for x in input().split()]
list_dist = sorted([abs(x - X) for x in list])

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

ans = list_dist[0]

for x in list_dist[1:]:
    ans = gcd(ans,x)

print(ans)

# Optimized solution
N,X = list(map(int,input().split()))
list = list(map(int,input().split()))
diff = [abs(x - X) for x in list]
diff.sort()

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

#差の最大公約数を取得
gcd_val = diff[0]
for i in diff[1:]:
    gcd_val = gcd(i,gcd_val)

print(gcd_val)
# Original solution
n, x = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort(reverse=True)
D = []

for i in range(len(X)):
    dist = abs(x - X[i])
    D.append(dist)

def gcd(i, j):
    while j != 0:
        i, j = j, i % j
    return i

for i in range(len(D) - 1):
    D[i + 1] = gcd(D[i], D[i + 1])

print((D[-1]))

# Optimized solution
n, x = list(map(int, input().split()))
city = list(map(int, input().split()))
D = []

for i in range(n):
    dis = abs(x - city[i])
    D.append(dis)
    
def gdc(x, y):
    if x%y == 0:
        return y
    x, y = y, x%y
    return gdc(x, y)

for i in range(n-1):
    D[i + 1] = gdc(D[i], D[i + 1])

print((D[-1]))
# Original solution
import bisect
def gcd(x , y):
    max_val = max(x , y)
    min_val = min(x , y)
    while min_val != 0:
        max_val , min_val = min_val , max_val % min_val
    return max_val
N , X = list(map(int,input().split()))
x = list(map(int,input().split()))
x.sort()
split_idx = bisect.bisect_left(x , X)
BeforeList = x[:split_idx]
AfterList = x[split_idx:]
now = X
ans = 0
DistanceList = []
for val in AfterList:
    distance = abs(val - now)
    DistanceList.append(distance)
    now = val
for val in BeforeList:
    distance = abs(val - now)
    DistanceList.append(distance)
    now = val

ans = DistanceList[0]
for i in range(1,len(DistanceList)):
    ans = gcd(DistanceList[i] , ans)
print(ans)

# Optimized solution
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

N, X = list(map(int, input().split()))
x = list(map(int, input().split()))

x.insert(0, X)
distance = []
for i in range(1, len(x)):
    distance.append(abs(x[i] - x[i - 1]))


ans = distance[0]
for i in range(1, len(distance)):
    ans = gcd(distance[i], ans)
print(ans)
# Original solution
# -*- coding: utf-8 -*-

class dice_class:
    def __init__(self, top, front, right, left, back, bottom):
        self.top    =   top
        self.front  =   front
        self.right  =   right
        self.left   =   left
        self.back   =   back
        self.bottom =   bottom

    def roll(self, s):
        for i in s:
            if i == 'E':
                self.rollE()
            elif i == 'N':
                self.rollN()
            elif i == 'S':
                self.rollS()
            elif i == 'W':
                self.rollW()

    def rollE(self):
        tmp         =   self.top
        self.top    =   self.left
        self.left   =   self.bottom
        self.bottom =   self.right
        self.right  =   tmp

    def rollN(self):
        tmp         =   self.top
        self.top    =   self.front
        self.front  =   self.bottom
        self.bottom =   self.back
        self.back   =   tmp

    def rollS(self):
        tmp         =   self.top
        self.top    =   self.back
        self.back   =   self.bottom
        self.bottom =   self.front
        self.front  =   tmp

    def rollW(self):
        tmp         =   self.top
        self.top    =   self.right
        self.right  =   self.bottom
        self.bottom =   self.left
        self.left   =   tmp

if __name__ == "__main__":
    a = list(map(int, input().split()))
    s = str(input())
    dice = dice_class(a[0], a[1], a[2], a[3], a[4], a[5])
    dice.roll(s)
    print(dice.top)

# Optimized solution
# -*- coding: utf-8 -*-

class dice_class:
    def __init__(self, list):
        self.num = list

    def roll(self, s):
        for i in s:
            if i == 'E':
                self.rollE()
            elif i == 'N':
                self.rollN()
            elif i == 'S':
                self.rollS()
            elif i == 'W':
                self.rollW()

    def rollE(self):
        self.num = [self.num[3], self.num[1], self.num[0], self.num[5], self.num[4], self.num[2]]

    def rollN(self):
        self.num = [self.num[1], self.num[5], self.num[2], self.num[3], self.num[0], self.num[4]]

    def rollS(self):
        self.num = [self.num[4], self.num[0], self.num[2], self.num[3], self.num[5], self.num[1]]

    def rollW(self):
        self.num = [self.num[2], self.num[1], self.num[5], self.num[0], self.num[4], self.num[3]]


if __name__ == "__main__":
    dice = dice_class(list(map(int, input().split())))
    s = str(input())
    dice.roll(s)
    print(dice.num[0])
# Original solution
# AGC019B - Reverse and Compare
from collections import Counter


def main():
    S = input().rstrip()
    C, N = list(Counter(S).values()), len(S)
    ans = N * (N - 1) // 2 + 1  # all possible patterns
    ans -= sum(i * (i - 1) // 2 for i in C)  # duplicates
    print(ans)


if __name__ == "__main__":
    main()

# Optimized solution
# AGC019B - Reverse and Compare
def main():
    S = input().rstrip()
    N = len(S)
    ans = N * (N - 1) // 2 + 1  # all possible patterns
    abc = "abcdefghijklmnopqrstuvwxyz"
    for a in abc:
        x = S.count(a)
        ans -= x * (x - 1) // 2  # exclude duplicates
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
num=input()
out=0
for i in range(len(num)):
    #out+=num[i:].count(num(i))
    #print len(num[i:])-num[i:].count(num[i])
    out+=len(num[i:])-num[i:].count(num[i])

print(out+1)

# Optimized solution
num=input()
out=0
d={}
for i in set(num):
    d[i]=num.count(i)
#print d
#aaa
for i in range(len(num)):
    #out+=num[i:].count(num(i))
    #print len(num[i:])-num[i:].count(num[i])
    #out+=len(num[i:])-num[i:].count(num[i])
    out+=len(num[i:])-d[num[i]]
    d[num[i]]-=1

print(out+1)
# Original solution
I = input()
import re
if re.match("^(a|i|u|e|o){1}$", I):
    print('vowel', flush=True)
else:
    print('consonant', flush=True)


# Optimized solution
I = input()
import re
# if re.match("^(a|i|u|e|o){1}$", I):
if I in 'aiueo':
# if 'aiueo'.find(I):
    print('vowel', flush=True)
else:
    print('consonant', flush=True)
# Original solution
# li = sorted(list(map(int, input().split())))
# n, m = map(int, input().split())
c = input()
print("vowel") if c in "aeiou" else print("consonant")


# Optimized solution
print("vowel") if input() in "aeiou" else print("consonant")
# Original solution
while True:
  n = int(eval(input()))
  if n == 0:break
  to = []
  for i in range(n):
    line = list(map(int, input().split()))
    for j in range(n):
      x, y = line[2 * j:2 * j + 2]
      to.append(y * n + x)
  
  order = []
  used = [False] * (n * n)
  def dfs(x):
    if used[x]:return
    used[x] = True
    dfs(to[x])
    order.append(x)
  
  for i in range(n * n):
    dfs(i)
  order.reverse()
  
  def dfs2(x, used, group):
    if used[x]:return False
    if x in group:return True
    group.add(x)
    return dfs2(to[x], used, group)
  
  used = [False] * (n * n)
  ans = 0
  for i in order:
    group = set()
    if not used[i]:
      if dfs2(i, used, group):ans += 1
    for g in group:used[g] = True
  print(ans)
  


# Optimized solution
while True:
  n = int(eval(input()))
  if n == 0:break
  to = []
  for i in range(n):
    line = list(map(int, input().split()))
    for j in range(n):
      x, y = line[2 * j:2 * j + 2]
      to.append(y * n + x)
  
  order = []
  used = [False] * (n * n)
  def dfs(x):
    if used[x]:return
    used[x] = True
    dfs(to[x])
    order.append(x)
  
  for i in range(n * n):
    dfs(i)
  order.reverse()
  
  def dfs2(x, used, group):
    if x in group:return True
    if used[x]:return False
    group.add(x)
    used[x] = True
    return dfs2(to[x], used, group)
  
  used = [False] * (n * n)
  ans = 0
  for i in order:
    group = set()
    if not used[i]:
      if dfs2(i, used, group):ans += 1
  print(ans)
# Original solution
import collections
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = input().rstrip()
        K = int(eval(input()))

        if len(S) == 1:
            print((K // 2))
            exit()

        ans = 0
        start = 0
        end = len(S)
        cnt_1 = 1
        cnt_2 = 1

        if len(collections.Counter(S)) == 1:
            print(((len(S) * K) // 2))
            exit()

        if S[0] == S[-1]:
            for i in range(1, len(S) - 1):
                if S[i] != S[0]:
                    start = i
                    break
                else:
                    cnt_1 += 1

            for i in range(1, len(S) - 1)[::-1]:
                if S[i] != S[0]:
                    end = i + 1
                    break
                else:
                    cnt_2 += 1

            ans += (cnt_1 // 2) + ((cnt_1 + cnt_2) // 2) * (K - 1) + (cnt_2 // 2)

        before = S[start]
        length = 1
        changes = 0
        for i in range(start + 1, end):
            if S[i] == before:
                length += 1
            else:
                changes += length // 2
                length = 1
                before = S[i]

        changes += length // 2
        ans += changes * K
        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()


# Optimized solution
import collections
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = input().rstrip()
        K = int(eval(input()))

        if len(collections.Counter(S)) == 1:
            print(((len(S) * K) // 2))
            exit()

        k1 = self.connection_and_disconnection(S)
        k2 = self.connection_and_disconnection(S * 2)

        ans = k1 + (k2 - k1) * (K - 1)
        print(ans)

    def connection_and_disconnection(self, S: str):
        S = S + '$'
        cont_same_letter = 1
        need_to_change = 0
        for i in range(len(S) - 1):
            if S[i] == S[i + 1]:
                cont_same_letter += 1
            else:
                need_to_change += cont_same_letter // 2
                cont_same_letter = 1
        return need_to_change


# Run main
if __name__ == '__main__':
    AtCoder().main()
# Original solution
import sys
input = sys.stdin.readline
 
s = input().rstrip()
k = int(eval(input()))
    
def check_count(s):
    cnt_list = [1]
    cnt = 1
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            cnt_list[-1] += 1
        else:
            cnt_list.append(1)
    return cnt_list

def calc_ans(cnt_list, k):
    _ans = 0
    for c in cnt_list:
        _ans += c//2
    return(_ans * k)

if len(s)==1:
    ans = k//2
else:
    cnt_list = check_count(s)
    if len(cnt_list)==1:
        ans = (len(s)*k)//2
    else:
        ans = calc_ans(cnt_list, k)
        if s[0]==s[-1]:
            if cnt_list[0]%2==1 and cnt_list[-1]%2==1:
                ans += k - 1

print(ans)

# Optimized solution
import sys
input = sys.stdin.readline
 
s = input().rstrip()
k = int(eval(input()))

def check_count(s):
    cnt_list = []
    cnt = 1
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            cnt += 1
        else:
            cnt_list.append(cnt)
            cnt = 1
    if cnt>1:
        cnt_list.append(cnt)
    return cnt_list

def calc_ans(cnt_list, k):
    _ans = 0
    for c in cnt_list:
        _ans += c//2
    return(_ans * k)

if len(s)==1:
    ans = k//2
else:
    cnt_list = check_count(s)
    if len(cnt_list)==1:
        ans = (len(s)*k)//2
    else:
        ans = calc_ans(cnt_list, k)
        if s[0]==s[-1]:
            if cnt_list[0]%2==1 and cnt_list[-1]%2==1:
                ans += k - 1

print(ans)