Harryxun/stf_run huggingface dataset:
def f(n):
    ret = 1
    while True:
        if n == 0:
            break
        n %= bin(n).count('1')
        ret += 1
    return ret

if __name__ == "__main__":
    n = int(input())
    x = input()
    cnt = x.count('1')

    if cnt == 1:
        for x in X[:-1]:
            if x == '0':
                print(1)
            else:
                print(0)
        if X[-1] == '1':
            print(0)
        else:
            print(2)
        exit()

    xNum = 0
    for k in x:
        xNum <<= 1
        if k == '1':
            xNum += 1

    p = xNum % (cnt + 1)
    m = xNum % (cnt - 1)

    for i in range(n):
        if x[i] == '0':
            if (p + (pow(2, n - i - 1, cnt + 1))) % (cnt + 1) == 0:
                print(1)
            else:
                print(f(p + (pow(2, n - i - 1, cnt + 1)) % (cnt + 1)))
        else:
            if (m - (pow(2, n - i - 1, cnt - 1))) % (cnt - 1) == 0:
                print(1)
            else:
                print(f(m - (pow(2, n - i - 1, cnt - 1)) % (cnt - 1)))


### FIXED CODE ###

def f(n):
    cnt = 1
    while n > 0:
        n  %= bin(n).count('1')
        cnt += 1
    return cnt

if __name__ == "__main__":
    n = int(input())
    x = input()
    d = x.count('1')
    if d == 1:
        for i in x[:-1]:
            if i == '0':
                print(1)
            else:
                print(0)
        if x[-1] == '1':
            print(0)
        else:
            print(2)
        exit()

    ans = []
    M = 0
    for i in x:
        M <<= 1
        if i == '1':
            M += 1
    p = M % (d + 1)
    m = M % (d - 1)
    for i in range(n):
        if x[i] == '0':
            ans.append(f((p + pow(2, n - i - 1, d + 1)) % (d + 1)))
        else:
            ans.append(f((m - pow(2, n - i - 1, d - 1)) % (d - 1)))
    print(*ans, sep='\n')
a=int(input())
b=int(input())
c=a*b
print(c)

### FIXED CODE ###

a,b = map(int,input().split())
print(a*b)
cin = open(0).read().strip().split('\n')
n, q = map(int, cin[0].split(' '))
ab = [tuple(map(int, a.split(' '))) for a in cin[1:n]]
px = [tuple(map(int, a.split(' '))) for a in cin[n:]]

def dfs(g, idx, s):
    global score

    score[idx] += s
    for i in g[idx]:
        dfs(g, i, s)

g = [[] for _ in range(n)]
for abi in ab:
    g[abi[0]-1].append(abi[1]-1)

score = [0]*n
for pxi in px:
    dfs(g, pxi[0]-1, pxi[1])

print(' '.join(map(str, score)))

### FIXED CODE ###

cin = open(0).read().strip().split('\n')
n, q = map(int, cin[0].split(' '))
ab = [tuple(map(int, a.split(' '))) for a in cin[1:n]]
px = [tuple(map(int, a.split(' '))) for a in cin[n:n+q]]

import sys
sys.setrecursionlimit(10**9)

def dfs(g, seen, idx):
    global score

    seen[idx] = True
    for i in g[idx]:
        if seen[i]: continue
        score[i] += score[idx]
        dfs(g, seen, i)

g = [[] for _ in range(n)]
for abi in ab:
    g[abi[0]-1].append(abi[1]-1)
    g[abi[1]-1].append(abi[0]-1)

score = [0]*n
for pxi in px:
    score[pxi[0]-1] += pxi[1]

seen = [False]*n
dfs(g, seen, 0)

print(' '.join(map(str, score)))
import sys
input = sys.stdin.buffer.readline
 
def main():
    a,b,c,d = map(int,input().split())
    mod = 10**9+7
    N = c+d+5
    fac = [0 for _ in range(N+1)]
    fac[0],fac[1] = 1,1
 
    for j in range(2,N+1):
        fac[j] = (fac[j-1]*j)%mod
        
    def comb(x,y):
        return (fac[x+y]*pow(fac[x],mod-2,mod)*pow(fac[y],mod-2,mod))%mod
 
    print((comb(c+1,d+1)-comb(c+1,b)-comb(d+1,a)+comb(a,b))%mod)
    
if _name_ == "_main_":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
 
def main():
    a,b,c,d = map(int,input().split())
    MOD = 10**9+7
    N = c+d+5
    fac = [0 for _ in range(N+1)]
    fac[0],fac[1] = 1,1
 
    for i in range(2,N+1):
        fac[i] = (fac[i-1]*i)%MOD
        
    def comb(g,h):
        return (fac[g+h]*pow(fac[g],MOD-2,MOD)*pow(fac[h],MOD-2,MOD))%MOD
 
    print((comb(c+1,d+1)-comb(c+1,b)-comb(d+1,a)+comb(a,b))%MOD)
    
if __name__ == "__main__":
    main()
n, k = map(int, input().split())
x = n
min_n = n
rlist = []
while x>0:
    if (k == 1):
        rlist = [0]
        break
    rlist.append(abs(x-k))
    x = abs(x-k)
    min_n = min(rlist)
    if (min_n == abs(x-k)):break
    if (min_n == 0):break
print(min(rlist))



### FIXED CODE ###

n, k = map(int, input().split()) 
t = n % k
if (k-t > t):
    print(t)
else:
    print(k-t)
from collections import defaultdict

class UnionFind():
    def __init__(self):
        self.__table = {}
        self.__size = defaultdict(lambda: 1)

    def __root(self, x):
        if x not in self.__table:
            self.__table[x] = x
        elif x != self.__table[x]:
            self.__table[x] = self.__root(self.__table[x])
        return self.__table[x]

    def same(self, x, y):
        return self.__root(x) == self.__root(y)

    def union(self, x, y):
        x = self.__root(x)
        y = self.__root(y)
        if x != y:
            self.__size[x] += self.__size[y]
            self.__size[y] = self.__size[x]
            self.__table[x] = y

    def size(self, x):
        return self.__size[self.__root(x)]

def solve():
    uf = UnionFind()
    N, M = map(int, input().split())
    bridges = [[int(i) for i in input().split()] for i in range(M)]
    ans = [N * (N - 1) // 2]
    for A, B in reversed(bridges):
        if uf.same(A, B):
            ans.append(ans[-1])
        else:
            try:
                sa, sb = uf.size(A), uf.size(B)
                uf.union(A, B)
            except:
                sa, sb = 1, 0
            ans.append(ans[-1] - sa * sb)
    ans.pop()
    return '\n'.join(map(str, reversed(ans)))

print(solve())


### FIXED CODE ###

class UnionFind:
    def __init__(self, size):
        self.parent = [-1 for i in range(size)]#非負なら親ノード，負ならグループの要素数

    def root(self, x): #root(x): xの根ノードを返す．
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x]) #xをxの根に直接つなぐ
            return self.parent[x]

    def merge(self, x, y): #merge(x,y): xのいるグループと$y$のいるグループをまとめる
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.parent[x] > self.parent[y]: #xの要素数がyの要素数より「小さい」とき入れ替える
            x,y=y,x
        self.parent[x] += self.parent[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True

    def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)

    def size(self,x): #size(x): xのいるグループの要素数を返す
        return -self.parent[self.root(x)]

def solve():
    N, M = map(int, input().split())
    bridges = [[int(i) - 1 for i in input().split()] for i in range(M)]
    ans = [N * (N - 1) // 2]

    uf = UnionFind(N)
    for bridge in reversed(bridges):
        A, B = bridge
        if uf.issame(A, B):
            ans.append(ans[-1])
        else:
            ans.append(ans[-1] - uf.size(A) * uf.size(B))
            uf.merge(A, B)
    ans.pop(-1)
    return '\n'.join(map(str, reversed(ans)))

print(solve())
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 + 7

positive = []
negative = []
zero = 0
for t in a:
    if t < 0:
        negative.append(t)
    elif t == 0:
        positive.append(0)
        zero += 1
    else:
        positive.append(t)
if n - zero < k:
    print(0)
    exit()

positive.sort()
negative.sort(reverse=True)

if not positive:
    ans = 1
    if k % 2 == 1:
        if zero != 0:
            print(0)
            exit()
        for i in range(k):
            ans *= negative[i]
            ans %= mod
    else:
        for i in range(k):
            ans *= negative.pop()
            ans %= mod
    print(ans)
    exit()

ans = 1
# negative 処理
check = []
for i in reversed(range(len(negative) % 2, len(negative), 2)):
    check.append(negative[i+1] * negative[i])
# positive

if k % 2 == 1:
    ans *= positive.pop()
    k -= 1

for i in reversed(range(len(positive) % 2, len(positive), 2)):
    check.append(positive[i+1] * positive[i])
check.sort()

for i in range(k//2):
    ans *= check.pop()
    ans %= mod

print(ans)






### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 + 7

positive = []
negative = []
zero = 0
for t in a:
    if t < 0:
        negative.append(t)
    elif t == 0:
        positive.append(0)
        zero += 1
    else:
        positive.append(t)
if n - zero < k:
    print(0)
    exit()

positive.sort()
negative.sort(reverse=True)

if not positive:
    ans = 1
    if k % 2 == 1:
        if zero != 0:
            print(0)
            exit()
        for i in range(k):
            ans *= negative[i]
            ans %= mod
    else:
        for i in range(k):
            ans *= negative.pop()
            ans %= mod
    print(ans)
    exit()

ans = 1
# negative 処理
check = []
if len(negative) % 2 == 1:
    ww = negative[0]
    negative = negative[1:]
while negative:
    check.append(negative.pop() * negative.pop())

# positive
if k % 2 == 1:
    ans *= positive.pop()
    k -= 1

if len(positive) % 2 == 1:
    w = positive[0]
    positive = positive[1:]
while positive:
    check.append(positive.pop() * positive.pop())
check.sort()


for i in range(k//2):
    if check:
        ans *= check.pop()
    else:
        print(ans*w*ww%mod)
        exit()
    ans %= mod

print(ans)
S = list(map(str,input()))
# s = "><<<<><<"
# S = list(map(str,s))
num = [-1]*(len(S)+1)
index0 = list()
than = 0# 0 == >, 1 == <
#----------------------------------------
for i in range(len(S)):
    if(S[i] == '<'):
        if(than == 0):
            num[i] = 0
            index0.append(i)
        than = 1
    else:
        than = 0
if(S[-1] == '>'):
    num[-1] = 0
    index0.append(len(S)+1)
#--------------------------------------
if(index0[0] == 0):
    i = 1
    while(True):
        num[i] = num[i-1]+1
        if(S[i] == '>'):
            break
        i+=1
    index0.pop(0)
if(len(index0)>0):
    if(index0[-1] == len(S)+1):
        i = len(S)-1
        while(True):
            num[i] = num[i+1]+1
            i-=1
            if(i <= 0):break
            if(S[i] == '<'):break
        index0.pop(-1)
while(len(index0)>0):
        for i in reversed(range(0,index0[0])):
            if(S[i] == '<'):
                break
            num[i] = max(num[i],num[i+1]+1)
        for i in range(index0[0]+1,len(S)+1):
            num[i] = max(num[i],num[i-1]+1)
            if(i >= len(S)):break
            if(S[i]== '>'):break
        index0.pop(0)

ans = 0
for i in range(len(num)):
    ans += num[i]
print(ans)


### FIXED CODE ###

S = list(map(str,input()))
# s = "><<<<><<"
# S = list(map(str,s))
num = [-1]*(len(S)+1)
index0 = list()
than = 0# 0 == >, 1 == <
#----------------------------------------
for i in range(len(S)):
    if(S[i] == '<'):
        if(than == 0):
            num[i] = 0
            index0.append(i)
        than = 1
    else:
        than = 0
if(S[-1] == '>'):
    num[-1] = 0
    index0.append(len(S)+1)
#--------------------------------------
if(index0[0] == 0):
    i = 1
    while(True):
        num[i] = num[i-1]+1
        if(i >= len(S)):break
        if(S[i] == '>'):
            break
        i+=1
    index0.pop(0)
if(len(index0)>0):
    if(index0[-1] == len(S)+1):
        i = len(S)-1
        while(True):
            num[i] = num[i+1]+1
            i-=1
            if(i < 0):break
            if(S[i] == '<'):break
        index0.pop(-1)

while(len(index0)>0):
        for i in reversed(range(0,index0[0])):
            if(S[i] == '<'):
                break
            num[i] = max(num[i],num[i+1]+1)
        for i in range(index0[0]+1,len(S)+1):
            num[i] = max(num[i],num[i-1]+1)
            if(i >= len(S)):break
            if(S[i]== '>'):break
        index0.pop(0)

ans = 0
for i in range(len(num)):
    ans += num[i]
print(ans)
a,b,h=map(int, input().split())

N = ((a+b)*h)/2

print(N)


### FIXED CODE ###

a = int(input())
b = int(input())
h = int(input())
print((a+b)*h//2)
import math
N,K = map(int,input().split())
r = 0
for i in range(1,N+1):
    if i >= K:
        r += 1/N
    else:
        l = math.ceil(math.log2(K / i))
        r += ((1 / 2) ** l)/N
print(r)


### FIXED CODE ###

import math
N,K = map(int,input().split())
r = 0
for i in range(1,N+1):
    if i >= K:
        r += 1/N
    else:
        l = math.ceil(math.log2(K / i))
        r += ((1 / 2) ** l)/N
print(r)
N = int(input())
A = list(map(int, input().split()))
A_0 = A[0]
for i in range(N, 0, -1):
    ans = A[i-1]
    for o in range(1, int(i ** 0.5) + 1):
        if i%o == 0:
            A[o-1]  = (A[o-1] + ans)//2
            if o != i//o:
                A[(i//o) - 1] = (A[(i//o) - 1] + ans)//2
 
if ans[0] != A_0:
    print(-1)
else:
    print(ans.count(1))
    [print(q) for q, w in zip(range(1, N+1), ans) if w == 1]

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
for i in range(N//2+1, 0, -1):
  sum = 0
  for o in range(1, (N//i)+1):
    sum += A[i*o-1]
  A[i-1] = sum%2
  
print(A.count(1))
ans = [str(q) for q,w in zip(range(1, N+1), A) if w == 1]
print(" ".join(ans))
N = int(input())

allList = []
days = 0

while len(allList) < N:
    allList.append(list(map(int, input().split())))

sum = 100

while sum > 0:
    toBePopped = []
    for i in range(N):
        if allList[i] and i+1 == allList[allList[i][0]-1][0]:
            toBePopped.append(i)
            toBePopped.append(allList[i][0]-1)
    if len(toBePopped) == 0:
        days = -1
        break
    days += 1
    for i in set(toBePopped):
        allList[i].pop(0)

    sum = 0
    for i in range(N):
        sum += len(allList[i])

print(days)


### FIXED CODE ###

S = list(input())
T = list(input())
count = 0
for i in range(3):
    if S[i] == T[i]:
        count += 1
print(count)
def lcs_size():
  X = input()
  Y = input()
  
  a = len(X)
  b = len(Y)
  
  z2 = [0 for in range(b+1)]
  maxl = 0
  for i in range(a):
    z1 = z2 + []
    for j in range(b):
      if X[i] == Y[j]:
        z2[j+1] = z1[j] + 1
      else:
        z2[j+1] = z1[j]
      maxl = max(maxl, z2[j+1])
  
  return maxl

q = input()

for i in range(q):
  print lcs_siz()

### FIXED CODE ###

def lcs_size():
  X = raw_input()
  Y = raw_input()
  a = len(X)
  b = len(Y)
  z2 = [0 for i in range(b+1)]

  for i in range(a):
    ch = X[i]
    z1 = z2 + []
    for j in range(b):
      if ch == Y[j]:
        z2[j+1] = z1[j] + 1
      elif z2[j+1] < z2[j]:
        z2[j+1] = z2[j]

  return z2[-1]

q = input()
for k in range(q):
  print lcs_size()
from fractions import gcd

def main():
    N = int(input())
    A = list(map(int, input().split()))

    if len(A) == 2:
        print(max(A))
        return

    if len(A) == 3:
        gcd1 = gcd(A[0], A[1])
        gcd2 = gcd(A[0], A[2])
        gcd3 = gcd(A[1], A[2])
        print(max(gcd1, gcd2, gcd3))
        return

    gcd1 = gcd(A[0], A[1])
    gcd2 = gcd(A[0], A[2])
    gcd3 = gcd(A[1], A[2])
    yet_used_gcd = max(gcd1, gcd2, gcd3)
    not_used_gcd = gcd(gcd1, A[2])

    for i in range(3, N):
        yet_used_gcd = gcd(yet_used_gcd, A[i])
        if yet_used_gcd < not_used_gcd:
            yet_used_gcd = not_used_gcd
        not_used_gcd = gcd(not_used_gcd, A[i])

    if yet_used_gcd > not_used_gcd:
        print(yet_used_gcd)
    else:
        print(not_used_gcd)

main()

### FIXED CODE ###

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

print((t // a)*b)
n,m = map(int,input().split())
A = list(map(int,input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
cur == 0
if n != 1:
    while A[0]%2 == 0:
        cur += 1
        A[0] = A[0]//2
        flag = True
    for i in range(1,n):
        temp = 0
        while A[i]%2 == 0:
            temp += 1
            A[i] = A[i]//2
        if temp != cur:
            flag = False
            break
    if flag:
        g = A[0]*A[1]//(4*gcd(A[0]//2, A[1]//2))
        for i in range(2, n):
            u = g
            v = A[i]//2
            p = u*v//gcd(u,v)
            g = p
        if g <= 2*m:
            print(int((m/g-1)/2)+1)
        else:
            print(0)
    else:
        print(0)
else:
    if A[0] <= 2*m:
        print(int((2*m/A[0]-1)/2)+1)
    else:
        print(0)


### FIXED CODE ###

n,m = map(int,input().split())
A = list(map(int,input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
cur = 0
if n != 1:
    t = A[0]
    while t%2 == 0:
        cur += 1
        t = t//2
        flag = True
    for i in range(1,n):
        temp = 0
        s = A[i]
        while s%2 == 0:
            temp += 1
            s = s//2
        if temp != cur:
            flag = False
            break
    if flag:
        g = A[0]*A[1]//(4*gcd(A[0]//2, A[1]//2))
        for i in range(2, n):
            u = g
            v = A[i]//2
            p = u*v//gcd(u,v)
            g = p
        if g <= m:
            print(int((m/g-1)/2)+1)
        else:
            print(0)
    else:
        print(0)
else:
    if A[0] <= 2*m:
        print(int(((2*m/A[0])-1)/2)+1)
    else:
        print(0)
while True:
    y,x = [int(i) for i in input().split()]
    if y,x == 0:
        break
    for i in range(y):
        print('#'*x)
    print()

### FIXED CODE ###

while True:
    y,x = [int(i) for i in input().split()]
    if y == 0:
        break
    for i in range(y):
        print('#'*x)
    print()
I = int(input())
B = 0
for i in range(I):
	A = input()
    B = A - 1 + B
print(str(B))

### FIXED CODE ###

I = int(input())
B = 0
count = 0
A = list(map(int,input().split()))
for i in range(I):
    B += A[count] - 1
    count += 1
print(str(B))
def main():
    H,W = map(int, input().split())

    S = ["" for _ in range(H)]
    for i in range(H):
        S[i] = input()

    INF = float("inf")
    dp = [[INF for _ in range(H*W)] for _ in range(H*W)]

    for i in range(H):
        for j in range(W):
            
            if j != W-1 and S[i][j] == "." and S[i][j+1] == ".":
                dp[(H*i)+j][(H*i)+j+1] = 1
                dp[(H*i)+j+1][(H*i)+j] = 1

            if i != H-1 and S[i][j] == "." and S[i+1][j] == ".":
                dp[(H*i)+j][(H*(i+1))+j] = 1
                dp[(H*(i+1))+j][(H*i)+j] = 1
        
            dp[(H*i)+j][(H*i)+j] = 0


    N = H*W
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

    ans = 0
    for i in range(N):
        for j in range(N):
            if dp[i][j] != INF:
                ans = max(ans, dp[i][j])
    
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

def main():
    H,W = map(int, input().split())

    S = ["" for _ in range(H)]
    for i in range(H):
        S[i] = input()

    INF = float("inf")
    N = H*W
    dp = [[INF for _ in range(N)] for _ in range(N)]

    for i in range(H):
        for j in range(W):
            
            if j != W-1 and S[i][j] == "." and S[i][j+1] == ".":
                dp[(W*i)+j][(W*i)+j+1] = 1
                dp[(W*i)+j+1][(W*i)+j] = 1

            if i != H-1 and S[i][j] == "." and S[i+1][j] == ".":

                dp[(W*i)+j][(W*(i+1))+j] = 1
                dp[(W*(i+1))+j][(W*i)+j] = 1
        
            dp[(W*i)+j][(W*i)+j] = 0


    N = H*W
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

    ans = 0
    for i in range(N):
        for j in range(N):
            if dp[i][j] != INF:
                ans = max(ans, dp[i][j])
    
    print(ans)

if __name__ == "__main__":
    main()
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X,Y,A,B,C = map(int,readline().split())
P = list(map(int,readline().split()))
Q = list(map(int,readline().split()))
R = list(map(int,readline().split()))
P = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
PQ = sorted(P+Q,reverse = True)
XY = X+Y
total = sum(PQ)
for i in range(C):
    if R[i] < PQ[-(i+1)]:
      if i ==0:
        ans = total
      else:
        ans = total + sum(R[:i]) - sum(PQ[-i:])
      break
    if i == max(C-1,XY-1):
      ans = total + sum(R[:i+1]) - sum(PQ[-(i+1):])
print(ans)

### FIXED CODE ###

import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X,Y,A,B,C = map(int,readline().split())
P = list(map(int,readline().split()))
Q = list(map(int,readline().split()))
R = list(map(int,readline().split()))
P = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
PQR = sorted(P+Q+R,reverse = True)
ans = sum(PQR[:X+Y])
print(ans)
def solve():
    S = input()
    if S == "Sunny":
        ans = "Cloudy"
    elif S == "Cloudy":
        ans = "Rainy"
    elif S == "Rainy":
        ans == "Sunny"
    
    print(ans)
solve()

### FIXED CODE ###

def solve():
    S = input()
    if S == "Sunny":
        ans = "Cloudy"
    elif S == "Cloudy":
        ans = "Rainy"
    elif S == "Rainy":
        ans = "Sunny"
    
    print(ans)
solve()
#nn
N,M=map(int,input().split())
a = [int(input()) for _ in range(M)]
dp = [0]*(N+1)
j = 0
dp[0] = 1
mod = 10**9+7
for i in range(1, N+1):
    if j < M and i == a[j]:
        j += 1
    elif i == 1:
        dp[i] = 1
    else:
        dp[i] = (dp[i-1]+dp[i-2]) % mod
print(dp[N])

### FIXED CODE ###

times = list(map(int, input().strip().split()))

times.sort()
print(times[0] + times[1])
N, K = map(int, input().split())
S = str(input())
count = 0

for n in range(1, N):
    if S[n-1] == 'R' and S[n] == 'R':
        count += 1
    elif S[n-1] == 'L' and S[n] == 'L':
        count += 1

count = count + 2*K
ans = min(count, N-1)
print(ans)

### FIXED CODE ###

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

a = 0

a += B[0]
a += B[N-2]

for n in range(N):
    if n == 0 or n == N-1:
        pass
    else:
        a += min(B[n-1], B[n])

print(a)