Harryxun/stf_run huggingface dataset:
n=int(input())
path_color=[None]*(n-1)
tree_path=[[] for x in range(n)]
path_num_to_edges=[]
tree_edge_flag=set()
for i in range(n-1):
    ai,bi=[int(x) -1 for x in input().split()]
    tree_path[ai].append((bi,i))
    tree_path[bi].append((ai,i))
    path_num_to_edges.append((ai,bi))

path_color[0]=1
from collections import deque
d=deque()
d.append(0)
while d:
    temp=d.pop()
    temp_color=path_color[temp]
    edges=path_num_to_edges[temp]
    for edge in edges:
        new_path_color=1
        if edge in tree_edge_flag:
            continue
        tree_edge_flag.add(edge)
        for other_edge,path_num in tree_path[edge]:
            if path_color[path_num]!=None:
                continue
            if other_edge in tree_edge_flag:
                continue
            tree_edge_flag.add(other_edge)
            if new_path_color==temp_color:
                new_path_color+=1
            path_color[path_num]=new_path_color
            new_path_color+=1
            d.append(path_num)


print(max(path_color))
for i in path_color:
    print(i)

### FIXED CODE ###

n=int(input())
path_color=[None]*(n-1)
tree_path=[[] for x in range(n)]
path_num_to_edges=[]
tree_edge_flag=set()
for i in range(n-1):
    ai,bi=[int(x) -1 for x in input().split()]
    tree_path[ai].append((bi,i))
    tree_path[bi].append((ai,i))
    path_num_to_edges.append((ai,bi))

path_color[0]=1
from collections import deque
d=deque()
for i in path_num_to_edges[0]:
    d.append(i)
while d:
    temp_edge=d.pop()
    if temp_edge in tree_edge_flag:
        continue
    tree_edge_flag.add(temp_edge)
    new_path_color=1
    for other_edge,path_num in tree_path[temp_edge]:
        if path_color[path_num]!=None:
            old_color=path_color[path_num]
            break
    for other_edge,path_num in tree_path[temp_edge]:
        if path_color[path_num]!=None:
            continue
        if new_path_color==old_color:
            new_path_color+=1
        path_color[path_num]=new_path_color
        new_path_color+=1
        d.append(other_edge)

print(max(path_color))
for i in path_color:
    print(i)
a,b=map(int,input().split())
j=0
while b>2**j:
    j+=1
k=1
l=[0 for i in range(j)]
bia=[0 for i in range(j)]
A=a
i=0
while A>2**(k-1):
    l[i]=A%(2**k)
    m=(l[i]-2**(k-1))
    if m<=0:
        bia[i]=0
    else:
        if m%2==1:
            bia[i]=1
        else:
            bia[i]=0
    k+=1
    i+=1
if (A//2)%2==0:
    bia[0]=0
else:
    bia[0]=1
k=1
l=[0 for i in range(j)]
bib=[0 for i in range(j)]
B=b+1
i=0
while B>2**(k-1):
    l[i]=B%(2**k)
    m=(l[i]-2**(k-1))
    if m<=0:
        bib[i]=0
    else:
        if m%2==1:
            bib[i]=1
        else:
            bib[i]=0
    k+=1
    i+=1
if (B//2)%2==0:
    bib[0]=0
else:
    bib[0]=1
ans=0
for i in range(j):
    if bia[i]==bib[i]:
        ans=ans
    else:
        ans+=2**i
print(ans)

### FIXED CODE ###

a,b=map(int,input().split())
j=0
while b>=2**j:
    j+=1
if b==0:
    j=1
k=1
l=[0 for i in range(j)]
bia=[0 for i in range(j)]
A=a
i=0
while A>2**(k-1):
    l[i]=A%(2**k)
    m=(l[i]-2**(k-1))
    if m<=0:
        bia[i]=0
    else:
        if m%2==1:
            bia[i]=1
        else:
            bia[i]=0
    k+=1
    i+=1
if (A//2)%2==0:
    bia[0]=0
else:
    bia[0]=1
k=1
l=[0 for i in range(j)]
bib=[0 for i in range(j)]
B=b+1
i=0
while B>2**(k-1):
    l[i]=B%(2**k)
    m=(l[i]-2**(k-1))
    if m<=0:
        bib[i]=0
    else:
        if m%2==1:
            bib[i]=1
        else:
            bib[i]=0
    k+=1
    i+=1
if (B//2)%2==0:
    bib[0]=0
else:
    bib[0]=1
ans=0
for i in range(j):
    if bia[i]==bib[i]:
        ans=ans
    else:
        ans+=2**i
print(ans)
from math import gcd
a,b=map(int,input().split())
c=gcd(a,b)
ans=a*b/c
print(int(ans))

### FIXED CODE ###

import fractions
a,b=map(int,input().split())
c=fractions.gcd(a,b)
ans=a*b/c
print(int(ans))
arr = sorted(input().split())
print(arr[0]*arr[1]/2)

### FIXED CODE ###

arr = sorted(list(map(int,input().split())))
print(int(arr[0]*arr[1]/2))
from numpy import gcd
a,b=map(int,input().split())
print(a*b//gcd(a,b))

### FIXED CODE ###

from fractions import gcd
a,b=map(int,input().split())
print(a*b//gcd(a,b))
from bisect import (
    bisect_left,
    bisect_right,
)


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

zi = bisect_left(x, 0)
queue = []
queue.append((zi, zi, zi, 1, x[zi]))
if zi - 1 >= 0:
    queue.append((zi-1, zi-1, zi-1, 1, -x[zi-1]))

mind = 9999999999999999999999999999
while len(queue) > 0:
    i, li, ri, cnt, d = queue.pop()
    #print(i, li, ri, cnt, d)
    if cnt == k:
        mind = d if d < mind else mind
        continue
    if li - 1 >= 0:
        queue.append((li-1, li-1, ri, cnt+1, d+abs(x[li-1] - x[i])))
    if ri + 1 < n:
        queue.append((ri+1, li, ri+1, cnt+1, d+abs(x[ri+1] - x[i])))

print(mind)

### FIXED CODE ###

n, k = (int(v) for v in input().split())
x = [int(v) for v in input().split()]

m = 99999999999999999999
for l in range(n-k+1):
    r = l + k - 1
    m = min(m, abs(x[l]) + abs(x[r] - x[l]))
    m = min(m, abs(x[r]) + abs(x[l] - x[r]))
print(m)
L = list(input())
L_ = []
a = L.pop(0)
cnt = 0

while True:
    if len(L) == 0:
        break
    else:
        b = L.pop(0)
    if a is not b:
        cnt += 1
        L = L_ + L
        L_ = []
        a = L.pop(0)
    elif a is b:
        L_.append(a)
        a = b
    # print(L_, a,  L)

print(cnt * 2)



### FIXED CODE ###

L = list(input())
L_ = []
a = L.pop(0)
cnt = 0

while True:
    if len(L) == 0:
        break
    else:
        b = L.pop(0)
    if a is not b:
        cnt += 1
        if len(L_) != 0:
            a = L_.pop()
        elif len(L) == 0:
            break  
        else:
            a = L.pop(0)
    elif a is b:
        L_.append(a)
        a = b
    # print(L_, a,  L)

print(cnt * 2)
a,b,c,d = map(int,input().split())
print(max(a*b,c*d))

### FIXED CODE ###

a = int(input())
b = int(input())
h = int(input())

print(int((a + b) * h / 2))
print('Yes'*(sorted(input())<sorted(input())[::-1])or'No')

### FIXED CODE ###

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

print(int((a+b)/2)+(a+b)%2)
import sys
import collections
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")

n=int(input())
d=list(map(int,input().split()))

c=collections.Counter(d)
if c.most_common()[0][1]>2:
    print(0)
    quit()
if 0 in c:
    if c[0]==1:
        print(0)
        quit()

li=list(map(int,c.keys()))

ans=0
for i in range(2**len(li)):
    hour=[]
    for j in range(len(li)):
        if c[li[j]]==2:
            hour.append(li[j])
            hour.append(24-li[j])
            break
        if i&(1<<j):
            hour.append(li[j])
        else:
            hour.append(24-li[j])
    hour.sort()
    # print(hour)
    tmp=24+hour[0]-hour[-1]
    for j in range(len(li)-1):
        tmp=min(tmp,hour[j+1]-hour[j])
    ans=max(ans,tmp)
print(ans)

### FIXED CODE ###

import sys
import collections
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")

n=int(input())
d=list(map(int,input().split()))

c=collections.Counter(d)
if c.most_common()[0][1]>2:
    print(0)
    quit()
if 0 in c:
    if c[0]==1:
        print(0)
        quit()

li=list(map(int,c.keys()))
li.append(0)
ans=0
# print(li)
# print(len(li))
for i in range(2**len(li)):
    hour=[]
    for j in range(len(li)):
        if c[li[j]]==2:
            hour.append(li[j])
            hour.append(24-li[j])
            continue
        if i&(1<<j):
            hour.append(li[j])
        else:
            hour.append(24-li[j])
    hour.sort()
    # print(hour)
    tmp=24+hour[0]-hour[-1]
    for j in range(len(hour)-1):
        tmp=min(tmp,hour[j+1]-hour[j])
    # print(tmp)
    ans=max(ans,tmp)
print(ans)
n=input()
print(reverse(n))

### FIXED CODE ###

n=input()
m=n[::-1]
if n==m:
  print("Yes")
else:
  print("No")
h,w = map(int,input().split())
s = [["."]+list(input())+["."] for i in range(h)]

for i in range(h):
  for j in range(1,w+1):
    if i == 0:
      if s[i][j]=="#" and s[i][j+1]=="." and s[i][j-1]=="." and s[i+1][j]==".":
        print("No")
        exit()
    elif i == h-1:
      if s[i][j]=="#" and s[i][j+1]=="." and s[i][j-1]=="." and s[i+1][j]==".":
        print("No")
        exit()
    else:
      if s[i][j]=="#" and s[i][j+1]=="." and s[i][j-1]=="." and s[i+1][j]=="." and s[i-1][j]==".":
        print("No")
        exit()
        
print("Yes")
      

### FIXED CODE ###

h,w = map(int,input().split())
s = [["."]+list(input())+["."] for i in range(h)]

for i in range(h):
  for j in range(1,w+1):
    if i == 0:
      if s[i][j]=="#" and s[i][j+1]=="." and s[i][j-1]=="." and s[i+1][j]==".":
        print("No")
        exit()
    elif i == h-1:
      if s[i][j]=="#" and s[i][j+1]=="." and s[i][j-1]=="." and s[i-1][j]==".":
        print("No")
        exit()
    else:
      if s[i][j]=="#" and s[i][j+1]=="." and s[i][j-1]=="." and s[i+1][j]=="." and s[i-1][j]==".":
        print("No")
        exit()
        
print("Yes")
import math

N, X = map(int, input().split())
cities = list(map(int, input().split()))
cities.append(X)
cities.sort()
distances = list(map(lambda x: cities[x + 1] - cities[x], range(len(cities) - 1)))
ans = distances[0]
for distance in distances:
    ans = math.gcd(ans, distance)
print(ans)

### FIXED CODE ###

import fractions

N, X = map(int, input().split())
cities = list(map(int, input().split()))
cities.append(X)
cities.sort()
distances = list(map(lambda x: cities[x + 1] - cities[x], range(len(cities) - 1)))
ans = distances[0]
for distance in distances:
    ans = fractions.gcd(ans, distance)
print(ans)
n=int(input())
d=list(map(int,input().split()))
s=[0]*n
cnt=0
for i in range(n):
  for j in range(i+1,n):
    s[cnt]=d[i]*d[j]
    cnt+=1
print(sum(s))

### FIXED CODE ###

n=int(input())
d=list(map(int,input().split()))
s=[0]*int(n*(n-1)/2)
cnt=0
for i in range(n):
  for j in range(i+1,n):
    s[cnt]=d[i]*d[j]
    cnt+=1
print(sum(s))
mod = 998244353
n = int(input())
d = list(map(int,input().split()))
if d[0]!=0 or d[1:].count(0)!=0:
  print(0)
  exit()
l = [0 for i in range(n-1)]
for i in d:
  l[i] += 1
cou = 1
for i in range(n-2):
  if l[i+1]!=0:
    a = l[i]
    b = l[i+1]
    cou *= (a**b)%mod
  else:
    if l[i+1:].count(0)!=n-2-i:
      print(0)
      exit()
print(cou%mod)

### FIXED CODE ###

mod = 998244353
n = int(input())
d = list(map(int,input().split()))
if d[0]!=0 or d[1:].count(0)!=0:
  print(0)
  exit()
l = [0 for i in range(n)]
for i in d:
  l[i] += 1
cou = 1
if 0 in l:
  a = l.index(0)
  if sum(l[a:])!=0:
    print(0)
    exit()
for i in range(n-2):
  if l[i+1]!=0:
    a = l[i]
    b = l[i+1]
    cou *= (a**b)%mod
print(cou%mod)
a,b,n = map(int,input().spit())

print(min(b-1,n))

### FIXED CODE ###

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

num = min(b-1,n)

print(int((a*num)/b)-a*int(num/b))
number = int(input())
print(number//3600, (number%3600)//60,  (number%3600)%60).split(':')


### FIXED CODE ###

sec = int(input())
print(sec//3600, ':', (sec%3600)//60, ':', sec%60, sep='')
import numpy as np

d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
  s.append(list(map(int,input().split())))

for i in range(d):
  if i%26=0:
    a=np.argmax(s[0])
  print((i+a)%26+1)

### FIXED CODE ###

import numpy as np

d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
  s.append(list(map(int,input().split())))

for i in range(d):
  print(np.argmax(s[i])+1)
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  string S;
  cin >> N >> S;
  vector<int> left(10, 0), right(10, 0);
  left[S[0] - '0']++;
  for (int i = 2; i < N; i++) {
    right[S[i] - '0']++;
  }
  vector<int> cnts(1000, 0);
  for (int i = 1; i < N - 1; i++) {
    int b = S[i] - '0';
    for (int a = 0; a < 10; a++) {
      for (int c = 0; c < 10; c++) {
        if (left[a] == 0 || right[c] == 0) continue;
        cnts[100 * a + 10 * b + c]++;
      }
    }
    left[S[i] - '0']++;
    right[S[i + 1] - '0']--;
  }
  int res = 0;
  for (int i = 0; i < 1000; i++) {
    if (cnts[i] != 0) res++;
  }
  cout << res << '\n';
  return 0;
}


### FIXED CODE ###

N = int(input())
S = input()

right = [[0 for _ in range(10)] for _ in range(N + 1)]
left = [[0 for _ in range(10)] for _ in range(N + 1)]
C = [[[0 for _ in range(10)] for _ in range(10)] for _ in range(10)]

for i in range(N - 1):
    for j in range(10):
        right[i + 1][j] += right[i][j]
    right[i + 1][int(S[i])] += 1

for i in range(N - 1, 0, -1):
    for j in range(10):
        left[i][j] += left[i + 1][j]
    left[i][int(S[i])] += 1

for i in range(1, N - 1):
    for a in range(10):
        for b in range(10):
            if right[i][a] != 0 and left[i + 1][b] != 0:
                C[a][int(S[i])][b] += 1

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if C[i][j][k] != 0:
                res += 1

print(res)
n=int(input())
for i in range(n):
    a=list(map(int,input().split()))
a.sort()
print(a[n-1]-a[0])

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a.sort()
print(a[n-1]-a[0])
r=int(input(半径 R の円の周長を出力してください。:))
result=2*double(r)*3.14
print(result)

### FIXED CODE ###

import math
r = int(input())
print(2*math.pi*r)
in_string = input()
in_arr = in_string.split()
N = int(in_arr[0])
A = int(in_arr[1])
B = int(in_arr[2])

if ((B-A) % 2) == 0:
    print(int((B-A)/2))
else:
    if (N-B) > A-1:
        print(int(A+(B-A-1)/2))
    else:
        print(int(N-B+1+((N-(A+N-B+1))/2)))


### FIXED CODE ###

in_string = raw_input()
in_arr = in_string.split()
N = int(in_arr[0])
A = int(in_arr[1])
B = int(in_arr[2])

if ((B-A) % 2) == 0:
    print(int((B-A)/2))
else:
    if (N-B) > A-1:
        print(int(A+(B-A-1)/2))
    else:
        print(int(N-B+1+((N-(A+N-B+1))/2)))
li = list(map(int,input().split()))
n,m=li[0],li[1]
_list=[int(input()) for i in range(m)]
is_safe = [True] * (n+1)
for a in _list:
  is_safe[a] = False
DP=[1, 1] if is_safe[1] == True else [1, 0]
for i in range(n-1):
  if is_safe[i+2] == False:
    DP+= [0]
  else:
    DP += [DP[i] + DP[i+1]]
print(DP[n]%=1000000007 if DP[n] != 0 else 0)

### FIXED CODE ###

li = list(map(int,input().split()))
n,m=li[0],li[1]
_list=[int(input()) for i in range(m)]
is_safe = [True] * (n+1)
for a in _list:
  is_safe[a] = False
DP=[1, 1] if is_safe[1] == True else [1, 0]
for i in range(n-1):
  if is_safe[i+2] == False:
    DP+= [0]
  else:
    DP += [DP[i] + DP[i+1]]
print(DP[n] % 1000000007 if DP[n] != 0 else 0)
n=int(input())
a,b,c=[list(map(int,input().split())) for _ in range(3)]
x=sum(b)
for i in range(n-1):
    if a[i]+1==a[i+1]:
        b+=c[a[i]-1]
print(x)

### FIXED CODE ###

n=int(input())
a,b,c=[list(map(int,input().split())) for _ in range(3)]
x=sum(b)
for i in range(n-1):
    if a[i]+1==a[i+1]:
        x+=c[a[i]-1]
print(x)
import sys
def input():
    return sys.stdin.readline()[:-1]
h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
b=[list(map(int,input().split())) for i in range(h)]
d=[[0 for i in range(w)] for j in range(h)]
maxd=0
for i in range(h):
    for j in range(w):
        d[i][j] = abs(a[i][j]-b[i][j])
        maxd=max(maxd,d[i][j])
dp=[[[False for i in range(maxd*80)] for j in range(w)] for k in range(h)]
dp[0][0][d[0][0]] = True
for i in range(h):
    for j in range(w):
        for dis in range(maxd*80):
            if dp[i][j][dis]:
                if i+1<h:
                    dp[i+1][j][abs(dis-d[i+1][j])]=True
                    if dis+d[i+1][j]<maxd*80:
                        dp[i+1][j][dis+d[i+1][j]]=True
                if j+1<w:
                    dp[i][j+1][abs(dis-d[i][j+1])]=True
                    if dis+d[i][j+1]<maxd*80:
                        dp[i][j+1][dis+d[i][j+1]]=True
for dis in range(maxd*80):
    if dp[-1][-1][dis]:
        print(dis)
        break

### FIXED CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]
h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
b=[list(map(int,input().split())) for i in range(h)]
d=[[0 for i in range(w)] for j in range(h)]
maxd=1
for i in range(h):
    for j in range(w):
        d[i][j] = abs(a[i][j]-b[i][j])
        maxd=max(maxd,d[i][j])
dp=[[0 for j in range(w)] for k in range(h)]
c=20000
dp[0][0] |= 1 << c+d[0][0]
for i in range(h):
    for j in range(w):
        if i+1<h:
            dp[i+1][j] |= dp[i][j] << d[i+1][j]
            dp[i+1][j] |= dp[i][j] >> d[i+1][j]
        if j+1<w:
            dp[i][j+1] |= dp[i][j] << d[i][j+1]
            dp[i][j+1] |= dp[i][j] >> d[i][j+1]
m=1000000
cnt = 0
for x in bin(dp[h-1][w-1])[2:][::-1]:
    if x=='1':
        m=min(m,abs(cnt-c))
    cnt+=1
print(m)
import collections
N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
total = 0

for n in c.items():
  if n[1] > 1:
    total += n*(n-1)//2

for i in range(N):
  ans = total
  ans -= A.count(A[i])-1
  print(ans)

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
total = 1

for n in c.items():
  total += n[1]*(n[1]-1)//2

for i in range(N):
  print(total-c[A[i]])
a = int(input())
b = int(input())
c = a + b
if c % 2:
    print('IMPOSSIBLE')
else:
    print(int(c / 2))

### FIXED CODE ###

a, b = map(int, input().split())
c = a + b
if c % 2:
    print('IMPOSSIBLE')
else:
    print(int(c / 2))
import sys

# import re
import math
import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    def make_divisors(a, b):
        divisors = []
        for i in range(1, min(a, b) + 1):
            if a % i == 0 and b % i == 0:
                divisors.append(i)

        # divisors.sort()
        return divisors

    a, b = ns()
    gcd = make_divisors(a, b)

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

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

# import re
import math
import collections
# import decimal
# import bisect
# import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    a, b = ns()

    g = fractions.gcd(a, b)

    def search(n):
        i = 2
        so = []
        while not(n == 1 or i * i > n):
            while n % i == 0:
                n //= i
                so.append(i)
            i += 1
        if n != 1:
            so.append(n)

        return so

    ans = set(search(g))
    print(len(ans) + 1)


if __name__ == '__main__':
    main()
import math
ans = 0
N = int(input())
for i in range(N):
    for j in range(N):
        for k in range(N):
            ans += math.gcd(i,j,k)
print(ans)

### FIXED CODE ###

import math
ans = 0
N = int(input())
if N <= 5:
  for i in range(N):
    for j in range(N):
        for k in range(N):
            ans += math.gcd(math.gcd(i+1,j+1),math.gcd(j+1,k+1))
else:
    for i in range(N):
        ans += i+1
    for i in range(N-1):
        for j in range(i+1,N):
            ans += 6*math.gcd(i+1,j+1)
    for i in range(N-2):
        for j in range(i+1,N-1):
            for k in range(j+1,N):
                ans += 6*math.gcd(math.gcd(i+1,j+1),math.gcd(j+1,k+1))
print(ans)
A,B,K = map(int,input.split())
ans =[]
for i in range(1, min(A,B)):
  if A%i == 0 and B%i == 0:
    ans.append(i)
  if len(ans) == K:
    print(len(ans))
    exit(1)
    
      

### FIXED CODE ###

A,B,K = map(int,input().split())
ans =[]
for i in range(1, min(A,B)+1):
    if A%i == 0 and B%i == 0:
        ans.append(i)
    

print(ans[-K])
sz = int(input(''))
ary = []
for i in range(0,sz):
  s = input()
  ary.append(s)

map = {}
for w in ary:
  if not w in map:
    map[w] = 1
  else:
    map[w] +=1

max = 0
maxes = []
for k,v in map.items():
  if v > max:
    max = v

for k,v in map.items():
  if v == max:
    maxes.append(k)

for m in maxes.sort():
  print(m)

### FIXED CODE ###

sz = int(input(''))
ary = []
for i in range(0,sz):
  s = input()
  ary.append(s)

map = {}
for w in ary:
  if not w in map:
    map[w] = 1
  else:
    map[w] +=1

max = 0
maxes = []
for k,v in map.items():
  if v > max:
    max = v

for k,v in map.items():
  if v == max:
    maxes.append(k)

for m in sorted(maxes):
  print(m)
A,B = int(input())
L = A-2*B

if L>=0:
    print(L)
else:
    print(0)

### FIXED CODE ###

A,B = map(int,input().split())
L = A-2*B

if L>=0:
    print(L)
else:
    print(0)
# AGC027A - Candy Distribution Again
# greedy algorithm
from itertools import accumulate as acc


def main():
    # maximize the number of proper distribution -> begin with small values
    N, X, *A = map(int, open(0).read().split())
    A.sort()
    ac = list(acc(A))
    if ac[-1] < x:  # the last one receives more than expected -> ans - 1
        ans = n - 1
    else:
        ans = sum(i <= x for i in ac)
    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

# AGC027A - Candy Distribution Again
# greedy algorithm
from itertools import accumulate


def main():
    # maximize the number of proper distribution -> begin with small values
    n, x = tuple(map(int, input().rstrip().split()))
    A = sorted(map(int, input().rstrip().split()))
    ac = list(accumulate(A))
    if ac[-1] < x:
        ans = n - 1
    else:
        ans = sum(i <= x for i in ac)
    print(ans)


if __name__ == "__main__":
    main()
import sys
input = sys.stdin.readline
def main():
  n=int(input())
  a=list(map(int,lambda x:list(map(int,list(bin(int(x))[2:]))),input().split()))
  mod=pow(10,9)+7
  ans=0
  len_ai=[]
  for ai in a:
    len_ai.append(len(ai))
  for i in range(61):# 2^iの位
    bit1=0
    for j in range(n):
      if len_ai[j]>=i+1:
        bit1+=a[j][-i-1]
    ans+=(pow(2,i,mod)*bit1*(n-bit1))%mod
    ans%=mod
  print(ans)
if __name__=='__main__':
  main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():
  n=int(input())
  a=list(map(int,input().split()))
  mod=pow(10,9)+7
  ans=0
  bit=[0]*61 #bit[i]:2^iの位が1である物の個数
  for ai in a:
    for j in range(61):
      if ((ai>>j) & 1):
        bit[j]+=1
  for i in range(61):
    ans+=(pow(2,i)%mod)*bit[i]*(n-bit[i])
    ans%=mod
  print(ans)
if __name__=='__main__':
  main()
import math

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

answer=0

if A-2B<=0:
    answer=0
else :
    answer=A-2B

print(answer)
     

### FIXED CODE ###

import math

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

answer=0

if A-2*B<=0:
    answer=0
else :
    answer=A-2*B

print(answer)
a, b, c = map(int, input()split())
if b - a == c - b:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

a, b, c = map(int, input().split())
if b - a == c - b:
  print("YES")
else:
  print("NO")
s,k,t=input(),int(input()),""
for q in s:
 if(p:=(123-ord(q))%26)<=k:n+="a";K-=i
 else:n+=c
print(t[:-1]+chr((ord(t[-1])-97+k)%26+97))

### FIXED CODE ###

s, k, t = input(), int(input()), ""
for q in s:
    if (p := (123 - ord(q)) % 26) <= k:
        k -= p
        t += "a"
    else:
        t += q
print(t[:-1] + chr((ord(t[-1]) - 97 + k) % 26 + 97))
s=list(input())
k=int(input())
s=s*k
ans=0
for i in range(1,len(s)):
    if s[i-1]==s[i]:
        ans+=1
        s[i]="A"
print(ans)  

### FIXED CODE ###

s=list(input())
k=int(input())
a,b,c=0,0,0
S=s*2
SS=s*3

for i in range(1,len(s)):
    if s[i-1]==s[i]:
        a+=1
        s[i]="A"

for i in range(1,len(S)):
    if S[i-1]==S[i]:
        b+=1
        S[i]="A"
for i in range(1,len(SS)):
    if SS[i-1]==SS[i]:
        c+=1
        SS[i]="A"        

x=a
y=c-a
z=c-b

if k%2==0:
    print(y*((k-2)//2)+x+z)
else:    
    print(y*(k//2)+x)