Harryxun/stf_run huggingface dataset:
for a,b in zip(A,B):
    if b>a:
        need+=b-a
        Ans+=1

Gap=[a-b for a,b in zip(A,B)]
Gap.sort(reverse=True)
index=0
while need>0 and Ans+index<=N:
    need-=Gap[index]
    index+=1
    
if Ans+index<=N:
    print Ans+index
else:
    print "-1"

### FIXED CODE ###

N=input()
A=map(int,raw_input().split())
B=map(int,raw_input().split())
need=0
Ans=0

for a,b in zip(A,B):
    if b>a:
        need+=b-a
        Ans+=1
        
index=0

Gap=[a-b for a,b in zip(A,B)]
Gap.sort(reverse=True)

while need>0:
    if Ans+index>=N:
        break
    need-=Gap[index]
    index+=1
    
if need<=0:
    print Ans+index
else:
    print "-1"
n, k =  input().split()
ds = list(map(int, input().split()))

nums = []
for x in range(10):
    if x in ds:
        nums.append(1)
    else:
        nums.append(0)

for x in range(n, n*10):
    ys = list(map(int,list(str(x))))
    flag = False
    for y in ys:
        if nums[y]:
            flag = True
            break
    if flag:
        continue
    else:
        print(x)
        exit

### FIXED CODE ###

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

nums = []
for x in range(10):
    if x in ds:
        nums.append(1)
    else:
        nums.append(0)

res = 0
for x in range(n, n*10):
    ys = list(map(int,list(str(x))))
    flag = False
    for y in ys:
        if nums[y]:
            flag = True
            break
    if flag:
        continue
    else:
        res = x
        break
print(res)
s = input().split()
print(str(s[0]*s[1]),' ',str(s[0]*2+s[1]*2))

### FIXED CODE ###

s = input().split()
print(int(s[0])*int(s[1]),int(s[0])*2+int(s[1])*2)
while 1:
 a=b=0;n=int(input())
 if n==0:break
 for i in[0]*n:
  s,t=map(int,input().split())
  b+=s if s<t else a+=s
  a+=t if s>t else b+=t
 print(a,b)


### FIXED CODE ###

import sys
d=0
for e in sys.stdin:
 c=list(map(int,e.split()))
 if len(c)>1:
  s,t=c;d=1
  if s>t:a+=s+t
  elif s<t:b+=s+t
  else:a+=s;b+=t
 else:
  if d:print(a,b)
  a=b=0
A, B, C, K =map(input().split())
if A <= K:
    print(K)
    
elif A+B <= K:
    print(A)
    
elif A+B+C <= K:
    print(A-C)

### FIXED CODE ###

A,B,C,K = map(int,input().split())
sum = 0;
if A <= K:
	sum += A;
	K -= A
else:
	sum += K;
	K -= K
if B <= K:
	K -= B
else:
	K -= K
if C <= K:
	sum -= C
	K -= C
else:
	sum -= K
	K -= K
print(sum)
s=input()
if s==hi or s==hihi or s==hihihi or s==hihihihi or s==hihihihihi:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

S=input()
if S=='hi' or S=='hihi' or S=='hihihi' or S=='hihihihi' or S=='hihihihihi':
  print("Yes")
else:
  print("No")
a = int(input())
if a[0] == a[2]:
  print("Yes")
els:
  print("No")

### FIXED CODE ###

n = input()
if n[0] == n[2]:
  print("Yes")
else:
  print("No")
def gcd(a,b):
  if a == b:
    return b
  if a < b:
    a, b = b, a
  return gcd(a-b, b)

N, X = map(int, input().split())
x = list(map(int,input().split()))
ans = max(x)
if N==1:
  ans = abs(X-x[0])
else:
  for i in range(N-1):
  	ans = min(ans, gcd(abs(x[i]-X), abs(x[i+1]-X)))

print(ans)



### FIXED CODE ###

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

N, X = map(int, input().split())
x = list(map(int,input().split()))
ans = max(x)
if N==1:
  ans = abs(X-x[0])
else:
  for i in range(N-1):
  	ans = min(ans, gcd(abs(x[i]-X), abs(x[i+1]-X)))

print(ans)
from sys import stdin
from collections import defaultdict
N = int(stdin.readline().rstrip())
adj = defaultdict(set)

for i in range(N-1):
    a,b,c = [int(x) for x in stdin.readline().rstrip().split()]
    adj[a].add((b,c))
    adj[b].add((a,c))
    
Q,K = [int(x) for x in stdin.readline().rstrip().split()]

visited = [False]*(N+1)
dist = [0]*(N+1)

def dfs(i,j):
    if visited[i]:
        return
    dist[i] = j
    visited[i] = True
    
    for node,d in adj[i]:
        dfs(node,d+j)
        
dfs(K,0)

for i in range(Q):
    x,y = [int(x) for x in stdin.readline().rstrip().split()]
    print(dist[x]+dist[y])

### FIXED CODE ###

from sys import stdin
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)
N = int(stdin.readline().rstrip())
adj = defaultdict(set)

for i in range(N-1):
    a,b,c = [int(x) for x in stdin.readline().rstrip().split()]
    adj[a].add((b,c))
    adj[b].add((a,c))
    
Q,K = [int(x) for x in stdin.readline().rstrip().split()]

visited = [False]*(N+1)
dist = [0]*(N+1)

def dfs(i,j):
    if visited[i]:
        return
    dist[i] = j
    visited[i] = True
    
    for node,d in adj[i]:
        dfs(node,d+j)
        
dfs(K,0)

for i in range(Q):
    x,y = [int(x) for x in stdin.readline().rstrip().split()]
    print(dist[x]+dist[y])
a=input()
b=input()

print '%d %d' % (a, b)

### FIXED CODE ###

a, b = map(int, raw_input().split())
print a*b, (a+b)*2
from collections import defaultdict

D,G=map( int, raw_input().split() )
P=[ map( int, raw_input().split() ) for i in range(D) ] 

N=10**5
dp= [ float("inf") for i in range(N+1)]
dp[0]=0

for idx, x  in enumerate(P):
	idx+=1
	p,c=x[0], x[1]/100
	for i in range(N,-1,-1):
		if dp[i]!=float("inf"):
			for j in range(p+1):	# j= problems count   , idx = score of a problem
				dp[i+idx*j]=min( dp[i+idx*j] , dp[i]+j )
				if j==p:
					dp[i+idx*j+c]= min( dp[i+idx*j+c], dp[ i+idx*j ] )


ans=float("inf")

for i in range(G/100,N):
	ans=min(ans, dp[i])

print ans


### FIXED CODE ###

D,G=map(int,raw_input().split())

A=[map(int,raw_input().split()) for i in range(D)]

N=1000
dp=[ [ float("-inf") for i in range(N+100)]  for j in range(D) ] 

p=A[0][0]
c=A[0][1]


for i in range(1,p+1):
	if i==p: dp[0][i]=i*100+c
	else: dp[0][i]=i*100

for i in range(D):
	dp[i][0]=0



for k in range(1,D):
	p=A[k][0]    # number of problems per line
	c=A[k][1]    # bonus

	for i in range(N):		         #dp[k][i]
		for j in range(1,p+1):    #number of problems per line
			dp[k][i+j]=max( dp[k][i+j], dp[k-1][i]+j*(k+1)*100, dp[k-1][i+j] )
		dp[k][i+j]=max( dp[k][i+j], dp[k-1][i]+j*(k+1)*100+c,dp[k-1][i+j] )



for idx,i in enumerate(dp[D-1]):
	if i>=G:
		print idx
		quit()
n, k = map(int, input().split())
sushi = []
for i in range(n):
    tmp = list(map(int, input().split()))
    sushi.append(tmp)
eaten = set() # 食べた種類を記憶(集合型)
chohuku = [] # 同じ種類で二回以上食べた寿司のスコアを記録
scores = [] # Sのスコアのリスト

sushi.sort(key=lambda x:x[1])
sushi.reverse() # sushiをおいしさの降順にソート

tmp = 0 # Sのおいしさの合計を保持
for i in range(k): # sushiを美味しい順にk個食べる
    if sushi[i][0] in eaten: # 同じ種類の寿司を食べていた場合
        chohuku.append(sushi[i][1])
    else:
        eaten.add(sushi[i][0]) # 食べた寿司の種類を記憶
    tmp += sushi[i][1] # 食べた寿司のおいしさをtmpに追加
chohuku.sort()
scores.append(tmp+len(eaten)**2) # 今のSのスコアを記憶

for i in range(k,n):
    if not sushi[i][0] in eaten and eaten != []:
        tmp -= chohuku.pop()
        eaten.add(sushi[i][0])
        tmp += sushi[i][1]
        scores.append(tmp+len(eaten)**2)
        
print(max(scores))

### FIXED CODE ###

n, k = map(int, input().split())
sushi = []
for i in range(n):
    tmp = list(map(int, input().split()))
    sushi.append(tmp)
eaten = set() # 食べた種類を記憶(集合型)
chohuku = [] # 同じ種類で二回以上食べた寿司のスコアを記録
scores = [] # Sのスコアのリスト

sushi.sort(key=lambda x:x[1])
sushi.reverse() # sushiをおいしさの降順にソート

tmp = 0 # Sのおいしさの合計を保持
for i in range(k): # sushiを美味しい順にk個食べる
    if sushi[i][0] in eaten: # 同じ種類の寿司を食べていた場合
        chohuku.append(sushi[i][1])
    else:
        eaten.add(sushi[i][0]) # 食べた寿司の種類を記憶
    tmp += sushi[i][1] # 食べた寿司のおいしさをtmpに追加
chohuku.sort()
scores.append(tmp+len(eaten)**2) # 今のSのスコアを記憶

for i in range(k,n):
    if not sushi[i][0] in eaten and chohuku != []:
        tmp -= chohuku.pop(0)
        eaten.add(sushi[i][0])
        tmp += sushi[i][1]
        scores.append(tmp+len(eaten)**2)
        
print(max(scores))
val1=list(map(int,input().split()))
val2=[input() for i in range(val1[0])]

val2.sort()
print("".join(val2))


### FIXED CODE ###

val1=list(map(int,input().split()))

if val1.count(5)==2 and val1.count(7)==1:
  print("YES")
else:
  print("NO")
for i in range(1,100):
    a=int(input("Enter the height a in meters="))
    b=int(input("Enter the height b in meters="))
    c=int(input("Enter the height c in meters="))
    if(b-a==c-b):
        print("Yes")
        print('Since'+str(b)+ '-' +str(a)+ '=' +str(c)+ '-' +str(b)+ ',this arrangement of poles is beautiful.')
    elif(c-b==b-a):
        print("Yes")
        print('Since'+str(c)+ '-' +str(b)+ '=' +str(b)+ '-' +str(a)+ ',this arrangement of poles is beautiful.')
    else:
        print("NO")
        print('Since'+str(b)+ '-' +str(a)+ '≠' +str(c)+ '-' +str(b)+ ',this arrangement of poles is not beautiful.')


### FIXED CODE ###

a,b,c=input().split()

a=int(a)
b=int(b)
c=int(c)

if b-a==c-b:
    print("YES")
else:
    print("NO")
from collections import Counter


def prime_factorize(n):
    p = 2
    fct = []
    # 素数pはp**2がAを超えないもの
    while n >= p ** 2:
        if n % p == 0:
            # このpは、2乗がAを超えないもの
            # 2乗がnを超えない限り割り続ける: 各pの積で割る
            n //= p
            fct.append(p)
        p += 1
    if n > 1:
        fct.append(n)
    return fct


N = int(input())
MOD = 1000000007
numbers = [prime_factorize(i) for i in range(1, N+1)]

count_numbers = Counter(numbers)
ans = 1
for n in count_numbers.values():
    ans *= ((n+1) % MOD)

print(ans % MOD)


### FIXED CODE ###

from collections import Counter


def prime_factorize(n):
    p = 2
    fct = []
    # 素数pはp**2がnを超えないもの（ただしnはある素数で割り切れるだけ割り切れたもの）
    # これはある素数p(i)でnを割れる時、他の素数p(i以外)はn//p(i) を割り切れるものになるため

    # 例えば、nが54なら
    # p が2のとき 54 // 2 で27
    # 27はもう2で割り切れないので2は1個
    # この時点でnは27に更新されている
    # 次にp が3の時、何度もpで割る（3度）
    while n >= p ** 2:
        while n % p == 0:
            n //= p
            fct.append(p)
        p += 1
    if n > 1:
        fct.append(n)
    return fct


N = int(input())
MOD = 1000000007
numbers = []
for i in range(1, N+1):
    numbers += prime_factorize(i)

count_numbers = Counter(numbers)
ans = 1
for n in count_numbers.values():
    ans *= ((n+1) % MOD)

print(ans % MOD)
n = int(input())
s = input()
k = int(input())
ss = []
for i in range(n):
    if(s[k] != s[i]):
        ss[i] = "*"
    else:
        ss[i] = s[k]
print(.join(ss))

### FIXED CODE ###

n = int(input())
s = input()
k = int(input())
w = s[k-1]
ss = ""
for i in range(n):
    if(s[i] == w):
        ss += w
    else:
        ss += "*"
print(ss)
N, D = [int(_) for _ in input().split()]
X = []
for i in range(D):
    X.append([int(_) for _ in input().split()])

# N, D = [3, 4]
# X = [
# [-3, 7, 8, 2],
# [-12, 1, 10, 2],
# [-2, 8, 9, 3]
# ]

from math import sqrt

ans = 0
for i in range(N):
    for j in range(i):
        d = 0
        for k in range(D):
            d += (X[i][k] - X[j][k]) ** 2
        if sqrt(d) % 1 == 0:
            ans += 1
print(ans)

### FIXED CODE ###

N, D = [int(_) for _ in input().split()]
X = []
for i in range(N):
    X.append([int(_) for _ in input().split()])

# N, D = [3, 4]
# X = [
# [-3, 7, 8, 2],
# [-12, 1, 10, 2],
# [-2, 8, 9, 3]
# ]

from math import sqrt

ans = 0
for i in range(N):
    for j in range(i):
        d = 0
        for k in range(D):
            d += (X[i][k] - X[j][k]) ** 2
        if sqrt(d) % 1 == 0:
            ans += 1
print(ans)
moji = str(input())
length = len(moji)
mojilst = list(moji)
ans = 0
temp = []
for i in range(length):
  if str(mojilst[i]) == "A" or str(mojilst[i]) == "G" or str(mojilst[i]) == "C" or str(mojilst[i]) == "T":
    temp.append(str(mojilst[i]))
  else:
    if len(ans) < len(temp):
      ans = len(temp)
    temp = []
print(ans)

### FIXED CODE ###

moji = str(input())
length = len(moji)
mojilst = list(moji)
ans = 0
temp = []
for i in range(length):
  if str(mojilst[i]) == "A" or str(mojilst[i]) == "G" or str(mojilst[i]) == "C" or str(mojilst[i]) == "T":
    temp.append(str(mojilst[i]))
  else:
    if ans < len(temp):
      ans = len(temp)
    temp = []
if ans < len(temp):
      ans = len(temp)
print(ans)
N, M, K = map(int,input().split())

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

X = 0
I = 0
J = 0



def read(i,j,k,x):
  
#  print('i',i,' j',j,' k',k,' x',x)
  
  if i == len(A):
    ans1 = x
  else:
    if k >= A[i]:
      ans1 = read(i+1,j,k-A[i],x+1)
    else:
      ans1 = x
  
  if j == len(B):
    ans2 = x
  else:
    if k >= B[j]:
      ans2 = read(i,j+1,k-B[j],x+1)
    else:
      ans2 = x
  
  return max(ans1,ans2)
  
print(read(I,J,K,0))

### FIXED CODE ###

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

A = list(map(int,input().split()))
A.insert(0, 0)
B = list(map(int,input().split()))
a = []
b = []

def nibun(L,l,r,target):

  wrk = -(-(l+r)//2)
  
#  print(l,r,target,wrk)
  
  if r == l:
    if r == len(L):
      return 0
    else:
      return wrk + 1
  
  if l == (len(L)-1):
    if L[wrk-1] > target:
      return wrk
    else:
      return 0

  if L[wrk] == target:
    return wrk+1

  elif L[wrk] > target:
    return nibun(L,l,wrk-1,target)

  else:
    return nibun(L,wrk,r,target)

  
s = 0
for i,e in enumerate(B):
  s += e 
  b.append(s)

s = 0
ans = 0
for i in range(len(A)):
#  print(i,'kaime')
#  print(s,i,A[i])
  s += A[i]
  if s > K:
    break
  else:  
    wrk = nibun(b,-1,len(b),K-s)
    
    ans=max(ans,i+wrk)
#    print('koko',s,wrk,ans)

print(ans)
a, b= [input() for _ in range(2)]
c=int(a+b)
for i in range(317):
    if i*i==c:
        print("Yes")
        break
else:
    print("No")

### FIXED CODE ###

from math import sqrt
a, b = input().split()
n = int(a+b)
if(int(sqrt(n))**2 == n):
    print("Yes")
else:
    print("No")
n,k = input().split()
hate_num = input().split()
num = int(n)
boo = False
while(boo == False):
  dec = []
  for i in str(num):
    dec.append(i not in hate_num)
    
  if(False not in dec):
    boo = True
  num += 1
    
print(num-1)

### FIXED CODE ###

input_num = input().split()
numbers = {'5':0,'7':0}
for num in input_num:
  if(num=='5' or num=='7'):
    numbers[num] +=1

if(numbers['5']==2 and numbers['7']==1):
  print('YES')
else:
  print('NO')
num_list = int(input().split(" "))

sorted_list = num_list.sorted()

if sorted_list == [5, 5, 7]:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

haiku = input().split()

haiku = sorted(list(map(int, haiku)))

if [5, 5, 7] == haiku:
    print('YES')
else:
    print('NO')
#!/usr/bin/env python3
import sys
import numpy as np


def solve(H: int, W: int, S: "List[List[str]]"):
    arr_s = np.array(S)
    arr_s = np.where(arr_s == ".", 1, 0)
    arr_v = np.zeros((H, W), dtype=int)
    arr_h = np.zeros((H, W), dtype=int)
    arr_v[0, :] = arr_s[0, :]
    arr_h[:, 0] = arr_s[:, 0]

    for i in range(H-1):
        arr_v[i+1, :] = (arr_v[i, :] + 1) * arr_s[i+1, :]
    
    for i in range(H-2, -1, -1):
        arr_v[i, :] = np.where(arr_v[i, :] > 0, np.maximum(arr_v[i+1, :], arr_v[i, :]), 0)

    for i in range(W-1):
        arr_h[:, i+1] = (arr_h[:, i] + 1) * arr_s[:, i+1]
    
    for i in range(W-2, -1, -1):
        arr_h[:, i] = np.where(arr_h[:, i] > 0, np.maximum(arr_h[:, i+1], arr_h[:, i]), 0)
    
    print(np.max(arr_v + arr_h) - 1)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ [c for c in next(tokens)] for _ in range(H) ]  # type: "List[List[str]]"
    solve(H, W, S)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import numpy as np


def solve(H: int, W: int, S: "List[List[str]]"):
    arr_s = np.array(S)
    arr_s = np.where(arr_s == ".", 1, 0)
    arr_v = np.zeros((H, W), dtype=int)
    arr_h = np.zeros((H, W), dtype=int)
    arr_v[0, :] = arr_s[0, :]
    arr_h[:, 0] = arr_s[:, 0]

    for i in range(H-1):
        arr_v[i+1, :] = (arr_v[i, :] + 1) * arr_s[i+1, :]
    
    for i in range(H-2, -1, -1):
        arr_v[i, :] = np.where(arr_v[i, :] > 0, np.maximum(arr_v[i+1, :], arr_v[i, :]), 0)

    for i in range(W-1):
        arr_h[:, i+1] = (arr_h[:, i] + 1) * arr_s[:, i+1]
    
    for i in range(W-2, -1, -1):
        arr_h[:, i] = np.where(arr_h[:, i] > 0, np.maximum(arr_h[:, i+1], arr_h[:, i]), 0)
    
    print(np.max(arr_v + arr_h) - 1)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ [c for c in next(tokens)] for _ in range(H) ]  # type: "List[List[str]]"
    solve(H, W, S)

if __name__ == '__main__':
    main()
tmp=map(int, raw_input().split(" "))
if tmp[1]<tmp[2]:
    print 0
else:
    print min(tmp[1],tmp[3])-tmp[2]


### FIXED CODE ###

num=list(raw_input())
#print num
#print num[::-1]
if num==num[::-1]:
    print "Yes"
else:
    print "No"
import numpy as np

class SieveOfEratosthenes:
    def __init__(self, V):
        self.is_prime = np.ones(V + 1, dtype=bool)
        self.is_prime[2::2] = False
        self.is_prime[3::3] = False
        self.is_prime[5::5] = False
        self.primes = [2, 3, 5]
        for i in range(7, V + 1, 2):
            if self.is_prime[i]:
                self.primes.append(i)
                if i * i < V + 1:
                    self.is_prime[i * i::i] = False
    
    def factorize(self, x, return_all=False):
        assert x >= 2
        result = []
        for p in self.primes:
            exp = 0
            while x % p == 0:
                exp += 1
                x = x // p
            if exp > 0 or return_all:
                result.append((p, exp))
            if p * p > x and return_all is False:
                break
        if x > 1:
            result.append((x, 1))
        return result


N = int(input())
M = 10**9 + 7
A = list(map(int, input().split()))
A = [a for a in A if a >= 2]

sieve = SieveOfEratosthenes(10**3)
F = [sieve.factorize(a, return_all=True) for a in A]

lcm = F[0]
for i in range(1, len(F)):
    lcm = [(p, max(e1, e2)) for (p, e1), (_, e2) in zip(lcm, F[i])]

val = 1
for p, e in lcm:
    val = val * pow(p, e, M) % M

B = [val * pow(a, M - 2, M) % M for a in A]
print(sum(B) % M)
    

### FIXED CODE ###

import numpy as np

class SieveOfEratosthenes:
    def __init__(self, V):
        self.is_prime = np.ones(V + 1, dtype=bool)
        self.is_prime[2::2] = False
        self.is_prime[3::3] = False
        self.is_prime[5::5] = False
        self.primes = [2, 3, 5]
        for i in range(7, V + 1, 2):
            if self.is_prime[i]:
                self.primes.append(i)
                if i * i < V + 1:
                    self.is_prime[i * i::i] = False
    
    def factorize(self, x, return_dict=False):
        if x == 1:
            return {1:1} if return_dict else [(1, 1)]
        result = []
        for p in self.primes:
            exp = 0
            while x % p == 0:
                exp += 1
                x = x // p
            if exp > 0:
                result.append((p, exp))
            if p * p > x:
                break
        if x > 1:
            result.append((x, 1))
        if return_dict:
            result = {p: e for p, e in result}
        return result


N = int(input())
M = 10**9 + 7
A = list(map(int, input().split()))

sieve = SieveOfEratosthenes(10**3)
F = [sieve.factorize(a, return_dict=True) for a in A]

lcm = F[0]
for i in range(1, len(F)):
    for p, e in F[i].items():
        if p in lcm:
            lcm[p] = max(lcm[p], e)
        else:
            lcm[p] = e

val = 1
for p, e in lcm.items():
    val = val * pow(p, e, M) % M

B = [val * pow(a, M - 2, M) % M for a in A]
print(sum(B) % M)
S = input()
K = int(input())

itr = 0
cnt = 1
len_cnt = []
for x in S :
  if itr == 0 :
    pre = x
    itr += 1
    continue
  now = x
  if pre == now :
    cnt += 1
    itr += 1
    if itr == len(S) :
      len_cnt.append(cnt)
    continue
  if pre != now :
    len_cnt.append(cnt)
    itr+=1
    if itr == len(S) and cnt == 1 :
      len_cnt.append(cnt)
    cnt = 1
    pre = x
    continue

ans = 0
for x in len_cnt :
  if x == 1 :
    continue
  else :
    ans += int(x / 2)

if S[0] == S[-1] and len_cnt[-1] > 1 and len_cnt[-1] % 2 == 1 and K > 1:
  ans += 1

ANS = K * ans
if len_cnt[-1] % 2 == 1 :
  ANS -= 1
print(ANS)

### FIXED CODE ###

S = input()
K = int(input())

flag = False

itr = 0
cnt = 1
len_cnt = []
for x in S :
  if itr == 0 :
    pre = x
    itr += 1
    continue
  now = x
  if pre == now :
    cnt += 1
    itr += 1
    if itr == len(S) :
      len_cnt.append(cnt)
    continue
  if pre != now :
    len_cnt.append(cnt)
    itr+=1
    if itr == len(S) and cnt == 1 :
      len_cnt.append(cnt)
    cnt = 1
    pre = x
    continue

if sum(len_cnt) != len(S) :
  len_cnt.append(1)

if len(len_cnt) == 1 :
  print(int(len_cnt[0] * K / 2))
  exit()

ans = 0
for x in len_cnt :
  if x == 1 :
    continue
  else :
    ans += int(x / 2)

# if S[0] == S[-1] and len_cnt[-1] > 1 and len_cnt[-1] % 2 == 1 and K > 1:
#   ans += 1
if S[0] == S[-1] and len_cnt[-1] % 2 == 1 and len_cnt[0] % 2 == 1 :
  ans += 1
  flag = True

ANS = K * ans
# print (ANS, len_cnt)
if flag :
  ANS -= 1

# if S[0] ==S[-1] and len_cnt[-1] % 2 == 1 and len_cnt[-1] != 1 :
#   ANS -= 1
print(ANS)
def calc(n):
    x = 1 << (n.bit_length() + 4) // 5
    y = (4 * x + n // (x ** 4)) // 5
    while y < x:
        x = y
        y = (4 * x + n // (x ** 4)) // 5
    return x
def f(n):
    c = calc(n)
    return c if c ** 5 == n else 0

X = int(input())
for i in range(1 << 10):
    a = f(X + i ** 5)
    if a:
        print(a, i)
        break
    a = f(X - i ** 5)
    if a:
        print(a, -i)
        break

### FIXED CODE ###

def f(n):
    l, r = 0, 1 << 20
    while r - l > 1:
        m = (l + r) // 2
        if m ** 5 <= n:
            l = m
        else:
            r = m
    return l if l ** 5 == n else 0

X = int(input())
for i in range(1 << 20):
    a = f(X + i ** 5)
    if a:
        print(a, i)
        break
    a = f(X - i ** 5)
    if a:
        print(a, -i)
        break
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
  print(a)
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
    ans = max(ans, i + j)

print(ans)


### FIXED CODE ###

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

a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)
a = list(map(int,input().split()))
K = a[0]
X = a[1]
m = X - K
M = x + K
size = M - m + 1
for i in range(size):
  print(m+i)

### FIXED CODE ###

a = list(map(int,input().split()))
K = a[0]
X = a[1]
m = X - K + 1
M = X + K - 1
size = M - m + 1
while m <= M:
  print(m)
  m += 1
int x
x = 3 
print x**3

### FIXED CODE ###

x = raw_input()
x = int(x)
print x*x*x