Harryxun/stf_run huggingface dataset:
n=int(input())
b=list(map(int,input().split()))
a=[0]*(n+1)
for i in range(n+1):
  if i == 0:
    a[i] = b[i]
  elif i==n:
    a[i] = b[i-1]
  else:
    a[i] = min(b[i],b[i-1])
 
    
print(sum(a))


### FIXED CODE ###

N = int(input())
B=list(map(int,input().split()))
A=[0]*N

for i in range(N):
  if i==0:
    A[i] = B[i]
  elif i==N-1:
    A[i] = B[i-1]
  else:
  	A[i] = min(B[i],B[i-1]) 

print(sum(A))
D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
    s.append([int(j) for j in input().split()])

for i, s_i in enumerate(s):
    print(s.index(max(s_i)))

### FIXED CODE ###

# -*- coding: utf-8 -*-

import random

D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
    s.append([int(j) for j in input().split()])

for i in range(D):
    print(random.randint(1, 26))
s=input()
t=input()

s.sort()
s=''.join(s)#辞書順最小=辞書で一番最初

t.sort()
t.reverse()
t=''.join(t)#辞書順最大

if s<t:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

a,b=map(int,input().split())
S=input()
if len(S) == a + b + 1 and S[a] == '-' and S.count('-') == 1:
    print('Yes')
else:
    print('No')
S=input()
if len(S)==2:
    print(S)
else:
    S.reverse()
    print(S)

### FIXED CODE ###

S=input()
if len(S)==2:
    print(S)
else:
    print(S[::-1])
def init_fact(n,mod):
    fact,finv,inv = [1]*n,[1]*n,[1]*n
    for i in range(2,n):
        fact[i] = (fact[i-1]*i) % mod
        inv[i]  = mod - inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1] * inv[i] % mod
    return (fact,finv,inv)

def nCr(n,r,mod,fact,finv):
    if n<r:
        return 0
    else:
        return fact[n] * (finv[r] * finv[n-r] % mod) % mod

modulo = 10**9+7
fact,finv,inv = init_fact(200000,modulo)


from collections import Counter
N = int(input())
A = list(map(int,input().split()))

# 重複している数を調べる
C = Counter(A).most_common()
x = C[0][0]

# 重複している数のindexを調べる
xi = []
for i in range(N):
    if A[i]==x:
        xi.append(i)
h = xi[1]-xi[0]+1

for i in range(1,N+2):
    print(nCr(N+1,i,modulo,fact,finv) - nCr(N+1-h,i-1,modulo,fact,finv))

### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int,input().split()))
c = Counter(A).most_common(1)[0][0]
B = []
mod = 10**9+7

for i in range(N+1):
    if A[i]==c:
        B.append(i)

F,I = [1],[1]
for i in range(1,N+2):
    F.append(F[i-1]*i%mod)
    I.append(pow(F[i],mod-2,mod))

def C(n,r):
    if n<r or n==0 or r==0:
        return 0
    else:
        return F[n]*I[r]*I[n-r]%mod

r0 = B[0]+N-B[1]

for i in range(1,N+2):
    Ans = (C(N+1,i) - C(r0,i-1))%mod
    print(Ans if i>1 else Ans-1)
d = {}
for i in range(n):
    temp = [0 for i in range(26)]
    s = input()
    for c in s:
        t = ord(c)-97
        temp[t]+=1
    for i in range(26):
        temp[i] = str(temp[i])
    txt = ",".join(temp)
    if txt not in d:
        d[txt] = 1
    else:
        d[txt] += 1
ans = 0
for k in d:
    if d[k] != 1:
        ans += d[k]*(d[k]-1)/2
print(int(ans))


### FIXED CODE ###

n = int(input())

d = {}


class mod_comb_perm:
    def __init__(self,n,mod):
        self.mod = mod
        self.fact = [1 for i in range(n)]
        for i in range(2,n+1):
            self.fact[i-1] = (self.fact[i-2]*i)%mod

    def expo(self,x,n):
        if n == 2:
            return (x * x) % self.mod
        elif n % 2 == 1:
            return (self.expo(x, n - 1) * x) % self.mod
        else:
            temp = self.expo(x, n // 2) % self.mod
            return (temp * temp) % self.mod
    def comb(self,n,k):
        a = (self.fact[n]*self.expo(self.fact[k],self.mod-2))%self.mod
        return (a*self.expo(self.fact[n-k],self.mod-2))%self.mod
    def invm(self,x):
        return (self.expo(self.fact[x],self.mod-2))%self.mod
    def perm(self,n,k):
        return (self.fact[n]*self.expo(self.fact[n-k],self.mod-2))%self.mod


# com = mod_comb_perm(10**5,10**18+3)
d = {}
for i in range(n):
    temp = [0 for i in range(26)]
    s = input()
    for c in s:
        t = ord(c)-97
        temp[t]+=1
    for i in range(26):
        temp[i] = str(temp[i])
    txt = ",".join(temp)
    if txt not in d:
        d[txt] = 1
    else:
        d[txt] += 1
ans = 0
# print(d)
for k in d:
    if d[k] != 1:
        ans += d[k]*(d[k]-1)/2
print(int(ans))
def p_e():
    N, M, P = map(int, input().split())
    abc = [tuple(map(int, input().split())) for _ in range(M)]
    li = defaultdict(list)

    for i in range(M):
        li[abc[i][0]].append((abc[i][1], -(abc[i][2] - P)))

    li_ans = defaultdict()
    li_ans[1] = 0
    li_top = [1]
    lt = []
    bf_n = -1
    while li_top and li_top != lt:
        lt = li_top.copy()
        li_top = []
        if N in li_ans.keys():
            bf_n = li_ans[N]

        for i in lt:
            for e in li[i]:
                if not e[0] in li_ans.keys():
                    li_ans[e[0]] = e[1] + li_ans[i]
                    li_top.append(e[0])
                else:
                    if li_ans[e[0]] > e[1] + li_ans[i]:
                        li_ans[e[0]] = e[1] + li_ans[i]
                        li_top.append(e[0])

    if li_top == lt and bf_n != li_ans[N]:
        print(-1)
    else:
        print(max(0, -li_ans[N]))


if __name__ == '__main__':
    p_e()


### FIXED CODE ###

from heapq import heappop, heappush


def p_d():
    n, m = map(int, input().split())
    ab = [tuple(map(int, input().split())) for _ in range(n)]

    ab.sort()
    ans = 0
    j = 0
    H = []

    for i in range(1, m + 1):
        while j < n and ab[j][0] <= i:
            heappush(H, -ab[j][1])
            j += 1

        if H:
            ans -= heappop(H)

    print(ans)


if __name__ == '__main__':
    p_d()
import collections

N = int(raw_input().replace("\n", ""))

a_list = map(int, raw_input().replace("\n", "").split(" "))
even_list = a_list[::2]
odd_list = a_list[1::2]

len_vec = N / 2

even_c = collections.Counter(even_list)
odd_c = collections.Counter(odd_list)



even_first_value, even_first_count = even_c.most_common()[0]
odd_first_value, odd_first_count  = odd_c.most_common()[0]
#(even_first_value, even_first_count), (even_second_value, even_second_count) = even_c.most_common()[:2]
#(odd_first_value, odd_first_count), (odd_second_value, odd_second_count) = odd_c.most_common()[:2]

if even_first_value == odd_first_value and len(even_c) == 1 and len(odd_c) == 1:
    cost = len_vec
elif even_first_value != odd_first_value:
    cost =  (even_first_count + odd_first_count)
elif len(even_c) == 1 and len(odd_c) > 1:
    odd_second_value, odd_second_count = odd_c.most_common(1)
    cost = len_vec + odd_second_count
elif len(odd_c) == 1 and len(even_c) > 1:
    even_second_value, even_second_count = even_c.most_common(1)
    #cost = len_vec + odd_second_count
    cost = len_vec + even_second_count
else: # ryouhou no first ga onaji de hutatuijou arutoki
    odd_second_value, odd_second_count = odd_c.most_common(1)
    even_second_value, even_second_count = even_c.most_common(1)
    cost = max(even_first_count+odd_second_count, even_second_count+odd_first_count)

print 2* len_vec - cost

### FIXED CODE ###

import collections

N = int(raw_input().replace("\n", ""))

a_list = map(int, raw_input().replace("\n", "").split(" "))
even_list = a_list[::2]
odd_list = a_list[1::2]

len_vec = N / 2

even_c = collections.Counter(even_list)
odd_c = collections.Counter(odd_list)

even_c_most_common = even_c.most_common()
odd_c_most_common = odd_c.most_common()

even_first_value, even_first_count = even_c_most_common[0]
odd_first_value, odd_first_count  = odd_c_most_common[0]
#(even_first_value, even_first_count), (even_second_value, even_second_count) = even_c.most_common()[:2]
#(odd_first_value, odd_first_count), (odd_second_value, odd_second_count) = odd_c.most_common()[:2]

if even_first_value == odd_first_value and len(even_c) == 1 and len(odd_c) == 1:
    cost = len_vec
elif even_first_value != odd_first_value:
    cost =  (even_first_count + odd_first_count)
elif len(even_c) == 1 and len(odd_c) > 1:
    odd_second_value, odd_second_count = odd_c_most_common[1]
    cost = len_vec + odd_second_count
elif len(odd_c) == 1 and len(even_c) > 1:
    even_second_value, even_second_count = even_c_most_common[1]
    #cost = len_vec + odd_second_count
    cost = len_vec + even_second_count
else: # ryouhou no first ga onaji de hutatuijou arutoki
    odd_second_value, odd_second_count = odd_c_most_common[1]
    even_second_value, even_second_count = even_c_most_common[1]
    cost = max(even_first_count+odd_second_count, even_second_count+odd_first_count)

print(2* len_vec - cost)
# -*- coding: utf-8 -*-

from math import gcd


def lcm(x, y):
    return x * y // gcd(x, y)


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

ans = 1
for ele in t:
    ans = lcm(ans, ele)

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-


def gcd(x, y):
    while x % y:
        x, y = y, x % y
    return y


def lcm(x, y):
    return x * y // gcd(x, y)


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

ans = 1
for ele in t:
    ans = lcm(ans, ele)

print(ans)
import sys
import collections
input = sys.stdin.readline
n = int(input())
xy = []
for i in range(n):
    _a,_b = map(int,input().split())
    xy.append([_a,_b])
sxy = sorted(xy)
sxy2 = []
for i in range(1,n):
    sxy2.append(((sxy[i][0]-sxy[i-1][0])**2)+((sxy[i][1]-sxy[i-1][1])**2))
c = collections.Counter(sxy2)
ans = len(sxy2)-max(c.values())+1
print(ans) if ans != 0 else print(1)


### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
b = sorted([list(map(int,input().split())) for i in range(n)])
d = {}
for i in range(n):
    for j in range(i+1,n):
        x = (b[j][0]-b[i][0],b[j][1]-b[i][1])
        if x in d:
            d[x]+=1
        else:
            d[x]=1
if n==1:
    print(1)
else:
    print(n-max(d.values()))
N, K = (int(x) for x in input().split())
h = [int(input()) for i in range(K)]
h.sort()
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))

### FIXED CODE ###

N, K = (int(x) for x in input().split())
h = [int(input()) for i in range(N)]
h.sort()
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))
import numpy as np
import math

h,w,m = (int(x) for x in input().split())

sumH = [0 for i in range(h)]
sumW = [0 for i in range(w)]
bomH = [0 for i in range(m)]
bomW = [0 for i in range(m)]

for i in range(m):
    hi,wi = (int(x) for x in input().split())
    sumH[ hi-1 ] += 1
    sumW[ wi-1 ] += 1
    bomH[ i ] = hi
    bomW[ i ] = wi

maxH = max(H)
maxW = max(W)
gHs = []
gWs = []
for i in range( h ):
    if maxH == sumH[i]:
        gHs.append(i)
for i in range( w ):
    if maxW == sumW[i]:
        gWs.append(i)

great = maxH + maxW
flag = 1
break_loop = False
for i in range( len(gHs) ):
    x = gHs[i]
    for j in range( len(gWs) ):
        y = gWs[j]
        for k in range(m):
            if bomH[k] == x and bomW[k] == y:
                flag = 0
                break_loop = True
                break
        if break_loop:
            break
    if break_loop:
        break

print( great - flag )

### FIXED CODE ###

import queue
h,w,m = ( int(x) for x in input().split() )

h_array = [ 0 for i in range(h) ]
w_array = [ 0 for i in range(w) ]
ps = set()
for i in range(m):
    hi,wi = ( int(x)-1 for x in input().split() )
    h_array[hi] += 1
    w_array[wi] += 1
    ps.add( (hi,wi) )
h_great = max(h_array)
w_great = max(w_array)
h_greats = list()
w_greats = list()
for i in range( h ):
    if h_array[i] == h_great:
        h_greats.append(i)
for i in range( w ):
    if w_array[i] == w_great:
        w_greats.append(i)

ans = h_great + w_great - 1

escaper = False

for i in range( len(h_greats) ):
    hi = h_greats[i]
    for j in range( len(w_greats) ):
        wi = w_greats[j]
        if (hi,wi) not in ps:
            ans += 1
            escaper = True
            break
    if escaper:
        break

print(ans)
x = input().split(' ')
a, b, c = x[0], x[1], x[2]
ans = c - (a-b)
if c > 0:
  print(c)
else:
  print(0)


### FIXED CODE ###

x = input().split(' ')
n = list(map(int, x))
ans = n[2] - (n[0]-n[1])
if ans > 0:
  print(ans)
else:
  print(0)
import math , sys

N = int( input() )
A = list( map( int, input().split() ))
A.sort()
Cs = [0 for _ in range(10**6+1)]
M = A[-1]
#print(A)
i=0
M = max(A)
for i in range(N):
    e = A[i]
    if Cs[e]==1:
        Cs[e]=2
    elif Cs[e]==0:
        Cs[e]=1

for i in range(len(Cs)):
    Cs[i] = Cs[i]%2

for e in A:
    i = 2
    while e*i <= 2*M+1:
        Cs[e*i] = 0
        i+=1
ans = sum(Cs)
print(ans)


### FIXED CODE ###

import math , sys

N = int( input() )
A = list( map( int, input().split() ))
A.sort()
Cs = [0 for _ in range(10**6+1)]
M = A[-1]
#print(A)
i=0
M = max(A)
for i in range(N):
    e = A[i]
    if Cs[e]==1:
        Cs[e]=2
    elif Cs[e]==0:
        Cs[e]=1

for i in range(len(Cs)):
    Cs[i] = Cs[i]%2

for e in A:
    i = 2
    while e*i <= M:
        Cs[e*i] = 0
        i+=1
ans = sum(Cs)
print(ans)
n = int(input())
h= list(map(int, input().split())) 

count = 0
ans = 0
def dfs(s):
    if s + 1 < len(h):
        if h[s] >= h[s+1]:
            global count 
            count = count + 1
            dfs(s+1)
    

for i in range(len(h)):
    count = 0
    dfs(i)
    if count > ans :
        ans = count
        
print(ans)
    

### FIXED CODE ###

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

count = 0
ans = 0

for i in range(len(h)):
    if i + 1 < len(h):
        if h[i] >= h[i+1]:
            count = count + 1
        else:
            count = 0
    if count > ans :
        ans = count
        
print(ans)
S = input()
Srev = S.sort(reverse = True)

if Srev.startswith('maerd'):
  Srev = Srev[5::]
  continue
elif Srev.startswith('remaerd'):
  Srev = Srev[7::]
  continue
elif Srev.startswith('esare'):
  Srev = Srev[5::]
  continue
elif Srev.startswith('resare'):
  Srev = Srev[6::]
  continue
elif Srev == '':
  print('YES')
  break
else:
  print('NO')
  break


### FIXED CODE ###

S = input()
Srev = S[::-1]
while True: 
  if Srev.startswith('maerd'):
    Srev = Srev[5::]
    continue
  elif Srev.startswith('remaerd'):
    Srev = Srev[7::]
    continue
  elif Srev.startswith('esare'):
    Srev = Srev[5::]
    continue
  elif Srev.startswith('resare'):
    Srev = Srev[6::]
    continue
  elif Srev == '':
    print('YES')
    break
  else:
    print('NO')
    break
input()
A=list(map(int,input()))
s=0
for a in A:
  if a < 0:
    s += 1
if s % 2 == 0:
  S = sum([abs(a) for a in A])
else:
  B = [abs(a) for a in A]
  m = min(B)
  S = sum(B) - 2*m
print(S)

### FIXED CODE ###

input()
A=list(map(int,input().split()))
s=0
for a in A:
  if a < 0:
    s += 1
S=0
if s % 2 == 0:
  S = sum([abs(a) for a in A])
else:
  B = [abs(a) for a in A]
  m = min(B)
  S = sum(B) - 2*m
print(S)
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:
            while self.parent[x] != x:
                self.parent[x] = self.parent[self.parent[x]]
                x = self.parent[x]
#        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)]


n,m=[int(i) for i in input().split()]

A=[[int(i)-1 for i in input().split()] for _ in range(m)]

ans = [0]*(m+1)
a = n*(n-1)//2
ans[0] = a

uf = UnionFind(n)
for i in range(m):
    j = m-i-1
    v1 = A[j][0]
    v2 = A[j][1]
#    print(v1,v2)
    if not uf.issame(v1,v2):
#        print(uf.parent)
        a -= uf.size(v1) * uf.size(v2)
        uf.merge(v1,v2)

    ans[i+1]=a

for i in range(m):
    print(ans[m-i-1])
    
    
    
    
    
    





### 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)]


n,m=[int(i) for i in input().split()]

A=[[int(i)-1 for i in input().split()] for _ in range(m)]

ans = [0]*(m+1)
a = n*(n-1)//2
ans[0] = a

uf = UnionFind(n)
for i in range(m):
    j = m-i-1
    v1 = A[j][0]
    v2 = A[j][1]
#    print(v1,v2)
    if not uf.issame(v1,v2):
#        print(uf.parent)
        a -= uf.size(v1) * uf.size(v2)
        uf.merge(v1,v2)

    ans[i+1]=a

for i in range(m):
    print(ans[m-i-1])
n = int(input())
l = list(map (int, input().split()))
l.sort()

def calc(l):
    if len(l) == 3:
        return l[1]
    l = l[1:-2]
    return calc(l) + l[-2]

print(calc(l))

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
l.sort()
power = 0
for i in range(1,len(l)//3+1):
    power += l[-2*i]
print(power)
from collections import Counter
from math import factorial

def comb(n,r):
    return factorial(n)//factorial(r)//factorial(n-r)

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

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC<=B:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=comb(CC,v)
    print(max_val)
    print(ans)
    exit()

assert 1==2

tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    assert tmp_num<A
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num

        tmp_num+=rest
        tmp_sum+=key*rest
        assert tmp_num==A
        assert rest<=val
        assert rest!=0
        print(tmp_sum/tmp_num)
        print(comb(val,rest))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val
        assert tmp_num<A

assert 1==2


### FIXED CODE ###

from collections import Counter
from collections import Counter
N, A, B = (list)(map(int, input().split()))
v = (list)(map(int, input().split()))

v = sorted(v, reverse=True)

sel_list = v[:A]
max_ave = sum(sel_list)/A
print(max_ave)

c = Counter(v)


def comb(n, r):
    r = min(r, n-r)
    ret = 1
    for i in range(r):
        ret *= (n-i)/(i+1)
    return ret


def ave_n(n):
    sel_list = v[:n]
    ave = sum(sel_list)/i
    if ave != max_ave:
        return 0
    last = sel_list[-1]
    use_last = sel_list.count(last)
    return comb(c[last], use_last)


ans = 0
for i in range(A, B+1):
    ret = ave_n(i)
    if ret == 0:
        break
    else:
        ans += ret
print((int)(ans))
mod = 998244353
n, s = map(int, input().split())
dp = np.zeros((n+1, s+1), dtype=int)
dp[0, 0] = 1
for i, a in enumerate(map(int, input().split())):
  dp[i+1] = dp[i] * 2 % mod
  dp[i+1][a:] = (dp[i+1][a:] + dp[i][:-a]) % mod
print(dp[-1, -1])

### FIXED CODE ###

import numpy as np

mod = 998244353
n, s = map(int, input().split())
dp = np.zeros((n+1, s+1), dtype=int)
dp[0, 0] = 1
for i, a in enumerate(map(int, input().split())):
  dp[i+1] = dp[i] * 2 % mod
  dp[i+1][a:] = (dp[i+1][a:] + dp[i][:-a]) % mod
print(dp[-1, -1])
n=int(input())
a=int(input())
b=int(input())
print("Hello World" if n==1 else a+b)

### FIXED CODE ###

n=int(input())
if n==1:
  print("Hello World")
else:
  a=int(input())
  b=int(input())
  print(a+b)
#065b
N = int(input())
a_list=[0]

for i in range(N):
    ai = int(input())
    a_list.append(ai)
    
def push_button(pushed_button,ans):
    ans += 1
    #print(ans,":",pushed_button,a_list[pushed_button])
    
    if a_list[pushed_button] == 2:
        return ans
    elif a_list[pushed_button] == pushed_button or pushed_button == a_list[a_list[pushed_button]]:
        return -1
    else:
        ans = push_button(a_list[pushed_button],ans)
        return ans
        
#print(a_list)
print(push_button(1,0))

### FIXED CODE ###

N = int(input())

button_dict = dict()

for i in range(1,N+1):
    button_dict[i] = int(input())

pushed_button_set = set()
i = 1
while 1:
    if i in pushed_button_set:
        print(-1)
        break
    elif i == 2:
        print(len(pushed_button_set))
        break
    else:
        pushed_button_set.add(i)
        i = button_dict[i]
#!/usr/bin python3
# -*- coding: utf-8 -*-

n = int(input())
s = input()
def f(str):
    if str == '':
        return 0
    else:
        if str[0] == 'R':
            return f(str[1:])
        elif str[-1] == 'W':
            return f(str[:-1])
        else:
            ret = f(str[1:-1]) + 1
            ret = min(f(str[:-1]) + 1, ret)
            ret = min(f(str[1:]) + 1, ret)
            return ret

print(f(s))


### FIXED CODE ###

#!/usr/bin python3
# -*- coding: utf-8 -*-

n = int(input())
s = input()
r = s.count('R')
print(s[:r].count('W'))
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
cnt2=0
cnt4=0
for i in range(n):
    if a[i]%4==0:
        cnt4+=1
    elif a[i]%2==0:
        cnt2+=1
if cnt2>1:
    ans=len(a)-cnt4*3-cnt2
if cnt2==1:
    ans=len(a)-cnt4*3
print("Yes" if ans<=0 else "No")


### FIXED CODE ###

"""import sys
input = sys.stdin.readline"""
n=int(input())
a=list(map(int,input().split()))
cnt2=0
cnt4=0
for i in a:
    if i%4==0:
        cnt4+=1
    elif i%2==0:
        cnt2+=1
if cnt2>1:
    ans=n-cnt4*2-cnt2
if cnt2<=1:
    ans=n-cnt4*2-1
print("Yes" if ans<=0 else "No")
import decimal
a,b = map(float,input().split())
print(Decimal(a)*Decimal(b))


### FIXED CODE ###

from decimal import Decimal
a,b = input().split()
print(int(Decimal(a)*Decimal(b)))
N, M = map(int, input().split())
A = list(map(int, input().split()))
INF = 10**(10**4)
COST = [INF,2,5,5,4,5,6,3,7,6]

min_cost = min(list(map(lambda a: COST[a], A)))
max_digits = N // min_cost

def dfs(n, digits):
    if digits * min_cost > n:
        return -INF
    if digits == 0:
        if n == 0:
            return 0
        else:
            return -INF
    elif digits < 0:
        return - INF
    results = []
    for a in A:
        res = a * 10 ** (digits - 1) + dfs(n-COST[a], digits-1)
        results.append(res)
    return max(results)

print(dfs(N, max_digits))


### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
INF = 10**5
COST = [INF,2,5,5,4,5,6,3,7,6]
digit = [-INF]*(N+1)
digit[0] = 0
for i in range(1, N+1):
    for a in A:
        c = COST[a]
        if i - c < 0:
            continue
        digit[i] = max(digit[i], 1 + digit[i-c])
ans = ''
n = N
for i in range(digit[N], 0, -1):
    for a in A:
        new_n = n - COST[a]
        if new_n < 0 or digit[new_n] < i - 1:
            continue
        ans += str(a)
        n = new_n
        break
print(ans)