Harryxun/stf_run huggingface dataset:
sys.setrecursionlimit(10000000)
N,K=map(int,input().split())
S=input()

#N=14
#K=2
#S="11101010110011"

LIST=[[[0] for j in range (2)]for i in range(N)]

t=S[0]
c=0
k=0
for i in range(N):
    if(t!=S[i]):
        LIST[k][0]=c
        LIST[k][1]=t
        t=S[i]
        k+=1
        c=0
    c+=1

LIST[k][0]=c
LIST[k][1]=t
LIST=LIST[0:k+1]
MAX=0

def calc(i,s,K):
    global MAX
    MAX=max(MAX,s)
    if(i==len(LIST)):
        return

    if(LIST[i][1]=="1"):
        s+=LIST[i][0]
        MAX=max(MAX,s)
        i+=1
        if(i==len(LIST)):
            return
    
    if(K>=1):
        calc(i+1,s+LIST[i][0],K-1)
    calc(i+1,0,K)

calc(0,0,K)
print(MAX)


### FIXED CODE ###

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

#K=1
#S="01100"
#N=len(S)

LIST=[[[0] for j in range (2)]for i in range(N)]

t=S[0]
c=0
k=0
for i in range(N):
    if(t!=S[i]):
        LIST[k][0]=c
        LIST[k][1]=t
        t=S[i]
        k+=1
        c=0
    c+=1

LIST[k][0]=c
LIST[k][1]=t
LIST=LIST[0:k+1]
MAX=0

s=0
l=0
r=0

if(LIST[r][1]=="1"):
    s+=LIST[r][0]
    r+=1
x=0
while(K>0 and len(LIST)>r):
    s+=LIST[r][0]
    K-=1
    if(len(LIST)-1==r):
        x=1
        break
    r+=1
    s+=LIST[r][0]
    if(len(LIST)-1==r):
        x=1
        break
    r+=1

MAX=max(s,MAX)

f=0
if(x==0):
    while(r<len(LIST)):
        if(l< len(LIST)-1):
            s-=LIST[l][0]
            l+=1
            f=1
        if(l<len(LIST)-1 and LIST[l][1]=="0"):
            s-=LIST[l][0]
            l+=1

        if(f==0):
            break
        

        s+=LIST[r][0]
        MAX=max(s,MAX)
        r+=1
        if(len(LIST)==r):
            break
        
        s+=LIST[r][0]
        MAX=max(s,MAX)
        r+=1
        if(len(LIST)==r):
            break

print(MAX)
while True:
    H, W = [int(i) for i in input().split()]
    if H == W == 0:
        break
        
    for h in range(h):
        for w in range(w):
            print('#', end=(''))
            
        print()
        
    print()

### FIXED CODE ###

while True:
    H, W = [int(i) for i in input().split()]
    if H == W == 0:
        break
        
    for h in range(H):
        for w in range(W):
            print('#', end='')
            
        print()
        
    print()
n, k = map(int, input().split())
h = [int(input()) for i in range(n)]
h.sort()
ans = 10 ** 10
for i in range(n-k+1):
  ans = min(ans, (max(a[i:i+k])-min(a[i:i+k])))
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
h = [int(input()) for i in range(n)]
h.sort()
ans = 10 ** 10
for i in range(n-k+1):
  ans = min(ans, h[i+k-1] - h[i])
print(ans)
N, K = map(int, input().split())
mod = 10**9 + 7
plus = []
minus = []
zlen = 0
for i in map(int, input().split()):
    if i >= 0:
        plus.append(i)
    elif i < 0:
        minus.append(i)
    else:
        zlen += 1
plen = len(plus)
mlen = len(minus)
if K > plen + mlen:
    print(0)
    import sys
    sys.exit()
plus.sort(reverse=True)
minus.sort()
pp = [1]
mp = [1]
for p in plus:
    pp.append((pp[-1]*p))
for m in minus:
    mp.append((mp[-1]*(-m)))
ppm = [1]
mpm = [1]
for p in plus[::-1]:
    ppm.append((ppm[-1]*p))
for m in minus[::-1]:
    mpm.append((mpm[-1]*(-m)))
ans = -float("inf")
ans_m = float("inf")
# kこマイナスから選ぶ
for k in range(K+1):
    if mlen < k:
        continue
    if plen < K-k:
        continue
    # 最大を目指す
    if k % 2 == 0:
        tmp = mp[k] * pp[K-k]
        ans = max(ans, tmp)
    # 絶対値最小を目指す
    else:
        tmp = mpm[k] * ppm[K-k]
        ans = min(ans, tmp)
if ans == -float("inf"):
    ans = -ans_m
if ans < 0 and zlen > 0:
    print(0)
    import sys
    sys.exit()
print(ans%mod)

### FIXED CODE ###

N = int(input())
ans = 0
for i in range(1, N+1):
    ans += i * (N-i+1)
for _ in range(N-1):
    u, v = map(int, input().split())
    if u > v:
        u, v = v, u
    ans -= u * (N-v+1)
print(ans)
n = int(input())
a = list(map(float, input().split()))

dp = [[None] * 1501 for i in range(3000)]
def dfs(i=0, at=(n + 1) // 2):
    if i == n:
        return int(at <= 0)
    if dp[i][at] is not None:
        return dp[i][at]

    r = dfs(i + 1, at - 1) * a[i] + dfs(i + 1, at) * (1 - a[i])
    dp[i][at] = r
    return r

print(dfs())



### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

import functools
import operator
n = int(input())
p = list(map(float, input().split()))
half = n // 2 + 1

dp = [[None] * (n + 1) for _ in range(n + 1)]
def dfs(n=half, depth=n - 1):
    if depth < 0 or (n - 1) > depth:
        return 0

    if dp[n][depth] is not None:
        return dp[n][depth]

    if n == 0:
        r = functools.reduce(operator.mul, map(lambda x: 1 - x, p[:depth + 1]))
    elif (n - 1) == depth:
        r = functools.reduce(operator.mul, p[:depth + 1])
    else:
        r = dfs(n - 1, depth - 1) * p[depth] + dfs(n, depth - 1) * (1 - p[depth])
    dp[n][depth] = r
    return r

print(sum(dfs(i) for i in range(half, n + 1)))
a,b = (int(input().split()))
print(a*b)

### FIXED CODE ###

a,b = (input().split())
print(int(a)*int(b))
n = input()
n_1 = int(n[-1])
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]
if n_1 in hon:
  print('hon')
  elif n_1 in pon:
    print('pon')
  else:
    print('bon')

### FIXED CODE ###

n = input()
n_1 = int(n[-1])
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]
if n_1 in hon:
    print('hon')
elif n_1 in pon:
    print('pon')
else:
    print('bon')
import re
count_ab = 0
b_a = 0
__a = 0
b__ = 0

for si in ss:
  count_ab += len(re.findall('AB',si))
  if si[0]=='B' and si[-1]=='A':
    b_a += 1
  elif si[0]=='B':
    b__ += 1
  elif si[-1]=='A':
    __a += 1
  else:
    pass

count_ab += min(__a, b__)
if abs(__a - b__) > 0 and b_a > 0:
  count_ab +=1

if b_a > 0:  
  count_ab += b_a - 1

print(count_ab)

### FIXED CODE ###

import re

n = int(input())
ss = [input() for _ in range(n)]

count_ab = 0
b_a = 0
__a = 0
b__ = 0

for si in ss:
  count_ab += len(re.findall('AB',si))
  if si[0]=='B' and si[-1]=='A':
    b_a += 1
  elif si[0]=='B':
    b__ += 1
  elif si[-1]=='A':
    __a += 1
  else:
    pass

if b_a == 0:
  print(count_ab + min(__a,b__))
else:
  if __a == 0 and b__ == 0:
    print(count_ab + b_a - 1)
  else:
    print(count_ab + b_a + min(__a,b__))
ex = ["+", "-", "*"]
while True:
    a, b, c, d = map(str, raw_input().split())
    if a == 0 and c == 0:
        break
    for i in ex:
        for j in ex:
            for k in ex:
                if eval( "((("+a+k+b+")"+j+c+")"+i+d+")") == 10:
                    print "(((",a,k,b,")",j,c,")",i,d,")"
                    flag = 1
                    break
    if flag == 1:
        break
    for i in ex:
        for j in ex:
            for k in ex:
                if eval( "(("+a+k+b+")"+i+"("+c+j+d+"))" ) == 10:
                    print "((",a,k,b,")",i,"(",c,j,d,"))"
                    flag = 1
                    break

### FIXED CODE ###

op = ["+", "-", "*"]
while True:
    a, b, c, d = map(str, raw_input().split())
    if a == "0" and c == "0":
        break
    n = [0,1,2,3]
    q = [a,b,c,d]
    flag = 0
    for ii in n:
        m = [0,1,2,3]
        m.remove(ii)
        for jj in m:
            l = [0,1,2,3]
            l.remove(ii);l.remove(jj)
            for kk in l:
                o = [0,1,2,3]
                o.remove(ii);o.remove(jj);o.remove(kk)
                for ll in o:
                    for i in op:
                        for j in op:
                            for k in op:
                                if eval( "((("+q[ii]+k+q[jj]+")"+j+q[kk]+")"+i+q[ll]+")") == 10:
                                    print "(((",q[ii],k,q[jj],")",j,q[kk],")",i,q[ll],")"
                                    flag = 1
                                    break
                                if eval( "(("+q[ii]+k+q[jj]+")"+i+"("+q[kk]+j+q[ll]+"))" ) == 10:
                                    print "((",q[ii],k,q[jj],")",i,"(",q[kk],j,q[ll],"))"
                                    flag = 1
                                    break
                            if flag == 1:
                                break
                        if flag == 1:
                            break
                    if flag == 1:
                        break
                if flag == 1:
                    break
            if flag == 1:
                break
        if flag == 1:
            break
    if flag == 0:
        print 0
a,b,c,d = map(int, input().split())
if a >=0:
    if c > 0:
        print(b * d)
    elif d < 0:
        print(a * d)
    else:
        print(b*d)
else:
    if c > 0:
        print(b * c)
    elif d < 0:
        print(a * c)
    else:
        print(b * c)

### FIXED CODE ###

x = int(input())
if x==1:
    print("0")
else:
    print("1")
import sys
read = sys.stdin.buffer.read # 全読み込み
readline = sys.stdin.buffer.readline # 一行読み込み
readlines = sys.stdin.buffer.readlines # 一行ずつ全読み込み
sys.setrecursionlimit(10**7) # 再帰限界変更（デフォルトは1000）

"""
# 文字列（数値変換も含む）
n = readline().rstrip() # １行に１文字列のみ
lis = readline().rstrip().split() # # １行に複数の文字列

# 数値（文字変換も含む）
n = int(readline().rstrip()) # １行に数値１個のみ
a, b, c = map(int,readline().rstrip().split()) # １行に複数の数値
A = list(map(int,readline().rstrip().split()))  # １行に複数の数値（リスト受け取り）
lis = [readline().rstrip().split() for _ in range(n)] # １行に複数の数値(m個)かつ、n行続く場合（出力は二次元リスト：[['1', '2'], ['4', '5']]）

# 一行に文字列が一個 * n行
s_lis=[readline().rstrip().decode() for _ in range(n)] # .decodeはバイト列から文字列へ変換
# 一行に文字列が一個 * n行で文字列をアルファベット順に変換
s_lis=["".join(sorted(readline().rstrip().decode())) for _ in range(n)]
# 一行に文字列が複数個 * n行
s_lis=[readline().rstrip().split().decode() for _ in range(n)] # .decodeはバイト列から文字列へ変換

# 一行に数値が一個 * n行
s_lis=[int(readline().rstrip()) for _ in range(n)] 
# 一行に数値が複数個 * n行
s_lis=[int(readline().rstrip().split()) for _ in range(n)]

# dとAの行が交互に並んでいる場合
s = sys.stdin.readlines()
n, k=map(int, s[0].split())
d=[]
A=[]
for i in s[1:2*k:2]:
    d.append(int(i))
for i in s[2:2*k+1:2]:
    A.append(list(map(int, i.split())))
"""

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

if k<=a:
    print(k)

elif: k<=a+b:
    print(a)

else:
    print(a+b-c)

### FIXED CODE ###



import sys
read = sys.stdin.buffer.read # 全読み込み
readline = sys.stdin.buffer.readline # 一行読み込み
readlines = sys.stdin.buffer.readlines # 一行ずつ全読み込み
sys.setrecursionlimit(10**7) # 再帰限界変更（デフォルトは1000）

"""
# 文字列（数値変換も含む）
n = readline().rstrip() # １行に１文字列のみ
lis = readline().rstrip().split() # # １行に複数の文字列

# 数値（文字変換も含む）
n = int(readline().rstrip()) # １行に数値１個のみ
a, b, c = map(int,readline().rstrip().split()) # １行に複数の数値
A = list(map(int,readline().rstrip().split()))  # １行に複数の数値（リスト受け取り）
lis = [readline().rstrip().split() for _ in range(n)] # １行に複数の数値(m個)かつ、n行続く場合（出力は二次元リスト：[['1', '2'], ['4', '5']]）

# 一行に文字列が一個 * n行
s_lis=[readline().rstrip().decode() for _ in range(n)] # .decodeはバイト列から文字列へ変換
# 一行に文字列が一個 * n行で文字列をアルファベット順に変換
s_lis=["".join(sorted(readline().rstrip().decode())) for _ in range(n)]
# 一行に文字列が複数個 * n行
s_lis=[readline().rstrip().split().decode() for _ in range(n)] # .decodeはバイト列から文字列へ変換

# 一行に数値が一個 * n行
s_lis=[int(readline().rstrip()) for _ in range(n)] 
# 一行に数値が複数個 * n行
s_lis=[int(readline().rstrip().split()) for _ in range(n)]

# dとAの行が交互に並んでいる場合
s = sys.stdin.readlines()
n, k=map(int, s[0].split())
d=[]
A=[]
for i in s[1:2*k:2]:
    d.append(int(i))
for i in s[2:2*k+1:2]:
    A.append(list(map(int, i.split())))
"""

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

if k<=a:
    print(k)

elif a<k<=a+b:
    print(a)

else:
    print(2*a+b-k)
N,A,B=map(int,input().split())

ans=""
for i in range(10**100):
    ans+="b"*A
    ans+="r"*B
    if(len(ans)>N):
        break

print(ans[:N].count('b'))


### FIXED CODE ###

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

if(N <= (A+B)):
    if(N<=A):
        print(N)
    else:
        print(A)
else:
    ans = (N//(A+B)) * A
    amari=(N % (A+B))
    tmp=A
    if(amari <= tmp):
        ans+=amari
    else:
        ans+=tmp

    print(ans)
n,m=map(int,input().split())
x=list(map(int,input().split()))
if m==1:
  print(0)
else:
  x.sort()
  ans=x[m-1]-x[0]
  l=[]
  for i in range(m-1):
    l.append(x[i+1]-x[i])
  l.sort(reverse=1)
  for i in range(n-1):
    ans-=l[i]
  print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
x=list(map(int,input().split()))
if n>=m:
  n=m
if m==1:
  print(0)
else:
  x.sort()
  ans=x[m-1]-x[0]
  l=[]
  for i in range(m-1):
    l.append(x[i+1]-x[i])
  l.sort(reverse=1)
  for i in range(n-1):
    ans-=l[i]
  print(ans)
import math
from functools import reduce

def calc(n_list):
    return reduce(math.gcd, n_list)

N, X = map(int, input().split())
c = list(map(int, input().split()))
c = [ abs(x-X) for x in c ]

print(calc(c))

### FIXED CODE ###

from functools import reduce

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

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

def calc(n_list):
    return reduce(_calc, n_list)

c = list(map(int, input().split()))
c = [ abs(x-X) for x in c ]

print(calc(c))
age=int(input())
if age==3,5,7:
  print('YES')
else :
  print('NO')

### FIXED CODE ###

age=int(input())
if age==3:
  print ('YES')
elif age==5:
  print ('YES')
elif age==7:
  print ('YES')
else :
  print('NO')
a = raw_input() . split()

S = a[0] * a[1]
O = 2 * (a[0] + a[1])

print S, O

### FIXED CODE ###

a , b= map(int,raw_input(). split())
S = a * b
O = 2 * a + 2 * b

print str(S) + ' ' +  str(O)
num = [0,0,0]
num[0] = int(input())
num[1] = int(input())
num[2] = int(input())

num.reverse()

print(int(str(num[0]) + str(num[1])) + num[2])

### FIXED CODE ###

s = input()

num = list(s)

num.sort()
num.reverse()

print(int(num[0] + num[1]) + int(num[2]))
from scipy.special import comb
N, K = map(int,input().split())
for i in range(1,K+1):
    c1 = comb(K-1,i-1)
    c2 = comb(N-K+1,i)
    print(int((c1*c2)%(1000000000+7)))



### FIXED CODE ###

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
Z = 2000

for i in range( 2, Z + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

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

for i in range(1,K+1):
    c1 = cmb(K-1,i-1,mod)
    c2 = cmb(N-K+1,i,mod)
    print(int((c1*c2)%(1000000000+7)))
import math
import functools

def lcm(a,b):
    return  int(a*b/math.gcd(a,b))
    
n=int(input())
t=[int(input()) for i in range(n)]
if n==1:
    print(t[0])
else:
    print(functools.reduce(lcm,t))

### FIXED CODE ###

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

def lcm(a,b):
    return  a*b//gcd(a,b)
    
n=int(input())
t=[int(input()) for i in range(n)]

anser=1
for i in t:
    anser=lcm(anser,i)
print(anser)
n, m = map(int, input().split())

a = [[0, 0] for i in range(n)]

c = [[0, 0] for i in range(m)]

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

for i in range(n):
    c[i][0], c[i][1] = map(int, input().split())

index = 0

for i in range(n):
    k = 1<<20
    for j in range(m):
        di = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if di < k:
            index = j + 1
            k = di
    print(index)


### FIXED CODE ###

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

a = [[0, 0] for i in range(n)]

c = [[0, 0] for i in range(m)]

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

for i in range(m):
    c[i][0], c[i][1] = map(int, input().split())

index = 0


for i in range(n):
    for j in range(m):
        if j == 0 :
            k = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]) +1

        di = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if di < k:
            index = j + 1
            k = di
    print(index)
N,M = map(int,input().split())
p = [0]*M
S = [0]*M
ans_AC = [0]*N
ans_WA = [0]*N
for i in range(M):
    p[i],S[i] = map(str,input().split())


for i in range(M):
    pi = int(p[i])
    if S[i] == "AC":
        if ans_AC[pi] != 1:
            ans_AC[pi] = 1
    else:
        if ans_AC[pi] != 1:
            ans_WA[pi] += 1
print(sum(ans_AC),sum(ans_WA))


### FIXED CODE ###

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

AC = [0]*N
WA = [0]*N
AC_cnt = 0
WA_cnt = 0

p = [0]*M
S = [0]*M

for i in range(M):
    p[i],S[i] = map(str, input().split())

for i in range(M):
    q_num = int(p[i])
    if AC[q_num-1] == 0:
        if S[i] == "AC":
            AC[q_num-1] = 1
        else:
            WA[q_num-1] += 1

for i in range(N):
    if AC[i] == 1:
        WA_cnt += WA[i]
        AC_cnt += 1

print(AC_cnt,WA_cnt)
N , X = map(int,input().split())
L = list(input())
cnt = 1
x = 0
lst = list()
for i in range(N):
    if int(len(L) / 2) + 1 > i   :
        x + = (int(L[i*2]))
        cnt += 1
    else :
        break
    if x+lst[i+1] > X :
        break
    if cnt >= N:
        break
print(cnt)


### FIXED CODE ###

N , X = map(int,input().split())
L=list(map(int,input().split()))
b = 0
cnt = 1
for i in range(N):
    b += L[i]
    if b <= X   :
        cnt+=1
    else:
        break
print(cnt)
N = int(input())
num_list = [int(i) for i in input().split(' ')]

even_counter = 0
for n in range(N):
  if num_list[n]%2 != 0:
    print('0')
    break
  else:
    even_counter += 1
  
  if even_counter == N:
    min_counter = float('inf')
    for i in range(N):
      num =  num_list[i]
      counter = 0
      while num%2 == 0:
        counter += 1
      	num //= 2
      if counter <= min_counter:
        min_counter = counter
      
    print(counter)


### FIXED CODE ###

N = int(input())
num_list = [int(i) for i in input().split(' ')]

even_counter = 0
for n in range(N):
  if num_list[n]%2 != 0:
    print('0')
    break
  else:
    even_counter += 1
  
  if even_counter == N:
    min_counter = float('inf')
    for i in range(N):
          num =  num_list[i]
          counter = 0
          while num%2 == 0:
            counter += 1
            num //= 2
          if counter <= min_counter:
            min_counter = counter
      
    print(min_counter)
import numpy as np

a = input()
b = []
b = input().split()
ans = 0
for i in a-1:
  for j in a-1:
    c = b[i]-b[j]
    if(ans < np.abs(c):
       ans = c
print(c)

### FIXED CODE ###

import numpy as np

a = int(input())
b = input().split()
c = []
for i in range(a):
  c.append(int(b[i]))
ans = 0
for i in range(a):
  for j in range(a):
    d = c[i] - c[j]
    d = np.abs(d)
    if(ans < d):
       ans = d
print(ans)
def main():
    IN=input()
    if IN=='':
        break
    print(IN[::-1])

### FIXED CODE ###

IN=input()
print(IN[::-1])
n = int(input())
s_list = list(map(int,input().split()))
if 'Y' in s_list:
  print('Four')
else:
  print('Three')

### FIXED CODE ###

n = int(input())
s_list = list(input().split())
if 'Y' in s_list:
  print('Four')
else:
  print('Three')
from collections import deque
n, m = map(int, input().split())
route = [[] for i in range(m)]

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

next_queue = deque()
sign = [-1] * n
sign[0] = 999

next_queue.append(0)

while next_queue:
    current_number = next_queue.popleft()
    for room in route[current_number]:
        if sign[room] == -1:
            sign[room] = current_number
            next_queue.append(room)
print("Yes")
for i in range(1, n):
    print(sign[i] + 1)



### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
route = [[] for i in range(n)]

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

next_queue = deque()
sign = [-1 for i in range(n)]
sign[0] = 999

next_queue.append(0)

while next_queue:
    current_number = next_queue.popleft()
    for room in route[current_number]:
        if sign[room] == -1:
            sign[room] = current_number
            next_queue.append(room)
print("Yes")
for i in range(1, n):
    print(sign[i] + 1)
def sumdic(dic):
  s=0
  for k, v in dic.items():
    s+=int(k)*v
  return s

a=int(input())
dic={}
for x in input().split():
  if x in dic:
    dic[x]+=1
  else:
    dic[x]=1
s=sumdic(dic)
d=int(input())
for i in range(d):
  (b,c)=[x for x in input().split()]
  if c in dic:
    dic[c]+=dic[b]
    s+=(int(c)-int(b))*dic[b]
    dic.pop(b)
  elif b in dic:
    dic[c]=dic[b]
    s+=(int(c)-int(b))*dic[b]
    dic.pop(b)
  print(s)

### FIXED CODE ###

def sumdic(dic):
  s=0
  for k, v in dic.items():
    s+=int(k)*v
  return s

a=int(input())
dic={}
for x in input().split():
  if x in dic:
    dic[x]+=1
  else:
    dic[x]=1
s=sumdic(dic)
d=int(input())
for i in range(d):
  (b,c)=[x for x in input().split()]
  if c in dic and b in dic:
    dic[c]+=dic[b]
    s+=(int(c)-int(b))*dic[b]
    dic.pop(b)
  elif b in dic:
    dic[c]=dic[b]
    s+=(int(c)-int(b))*dic[b]
    dic.pop(b)
  print(s)
n,k=map(int,input().split())
lists=list(map(int,input().split()))
Chlist=[0]*n
countlist=[0]*40
for s in range(n):
    Chlist[s]=format(lists[s],"0%ib"%40)
    for i in range(40):
        if Chlist[s][i]=="1":
            countlist[39-i]+=1

#countlistのi桁めが2**(i-1)の数である
power=0
for i in range(40):
    if 2**i<=k<2**(i+1):
        power=i
        break       
ans1=0
for j in range(power):
    ans1+=(2**j)*max(countlist[j],n-countlist[j])
ans1+=(2**power)*(countlist[power])


uselist=[0]*(k-2**power+1)
for i in range(k-2**power+1):
    c=format(i,"0%ib"%40)
    uselist[i]=c


ans2=0

ans2+=(2**power)*(n-countlist[power])

biggest=0
for i in uselist:
    big=0
    for j in range(40):
        if  i[39-j]=="1" and j!=power:
            big+=(2**j)*(n-countlist[j])
        elif i[39-j]=="0"and j!=power:
            big+=(2**j)*countlist[j]
    biggest=max(biggest,big)

ans2+=biggest
print(max(ans1,ans2))

### FIXED CODE ###

n,k=map(int,input().split())
k2=format(k+1,"0%ib"%40)
lists=list(map(int,input().split()))
countlist=[0]*40
for j in lists:
    c=format(j,"0%ib"%40)
    for i in range(40):
        if c[i]=="1":
            countlist[i]+=1

emptylist=[]
for i in range(40):
    if k2[i]=="1":
        emptylist.append(i)
if k>=1:
    ans=0
    for i in emptylist:
        subing=0
        for j in range(40):
            if j<i:
                if k2[j]=="1":
                    subing+=(2**(39-j))*(n-countlist[j])
                elif k2[j]=="0":
                    subing+=(2**(39-j))*countlist[j]
            if j==i:
                subing+=(2**(39-i))*countlist[i]
            
            if j>i:
                subing+=(2**(39-j))*max(countlist[j],n-countlist[j])
        ans=max(ans,subing)
    print(ans)
elif k==0:
    ans=0
    for i in range(40):
        ans+=(2**(39-i))*countlist[i]
    print(ans)
S = int(input())
S_list = [int(x) for x in list(str(S))]
S_str = str(S)
S_list_1 = input().split('0')
S_list_2 = input().split('1')
output = 0

for i in range(len(S_list_1)):
  output += int(S_list_1[i]) // 2
for i in range(len(S_list_2)):
  output += int(S_list_2[i]) // 2
  
print(output)

### FIXED CODE ###

S = list(input())

#1
count_1 = 0
count_2 = 0
for i in range(len(S)):
  #bwbw
  if i % 2 == 0:
    if S[i] == '1':
      count_1 += 1
  elif S[i] == '0':
    count_1 += 1
  
  #wbwb
  if i % 2 == 0:
    if S[i] == '0':
      count_2 += 1
  elif S[i] == '1':
    count_2 += 1
    
print(min(count_1, count_2))