Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".

Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.

After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. [Image] 

Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!


-----Input-----

The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string s_{i} is equal to   "L", if the i-th domino has been pushed to the left;  "R", if the i-th domino has been pushed to the right;  ".", if the i-th domino has not been pushed. 

It is guaranteed that if s_{i} = s_{j} = "L" and i < j, then there exists such k that i < k < j and s_{k} = "R"; if s_{i} = s_{j} = "R" and i < j, then there exists such k that i < k < j and s_{k} = "L".


-----Output-----

Output a single integer, the number of the dominoes that remain vertical at the end of the process.


-----Examples-----
Input
14
.L.R...LR..L..

Output
4

Input
5
R....

Output
0

Input
1
.

Output
1



-----Note-----

The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.

In the second example case, all pieces fall down since the first piece topples all the other pieces.

In the last example case, a single piece has not been pushed in either direction.

Difficulty: interview

Starter code:

Solutions:
n = int(input())
a = input().strip()
nextl = [-1] * n
lastr = [-1] * n
ll = -1
for i in range(n):
    if a[i] == "R":
        ll = i
    if a[i] == "L":
        ll = -1
    lastr[i] = ll
nl = -1
for i in range(n - 1, -1, -1):
    if a[i] == "L":
        nl = i
    if a[i] == "R":
        nl = -1
    nextl[i] = nl
ans = 0
#print(lastr)
#print(nextl)
for i in range(n):
    if nextl[i] == lastr[i] == -1:
        ans += 1
    if nextl[i] == -1 or lastr[i] == -1:
        continue
    d1 = nextl[i] - i
    d2 = i - lastr[i]
    if d1 == d2:
        ans += 1
print(ans)


n = int(input())
s = input().strip()

r = -1
l = -1
cb = 0
res = 0

for i in range(len(s)):
    if s[i] == ".":
        cb += 1
    elif s[i] == "L":            
        if r > -1:
            if cb % 2 == 1:
                res += 1
            cb = 0
        else:
            cb = 0
        r = -1
    else:
        if r > -1:
            cb = 0
            r = i
        else:        
            r = i
            res += cb
            cb = 0
        
if r == -1:
    res += cb
        
print(res)



def num_standing(s):
    ret = 0
    l = [i for i, x in enumerate(s) if x=="L"]
    r = [i for i, x in enumerate(s) if x=="R"]
    for i in range(len(l)):
        if l[i]%2 == r[i]%2: ret += 1
    for i in range(1,len(r)):
        ret += r[i]-l[i-1]-1
    return ret
    

n = int(input())
s = input()

L_i = [i for i, x in enumerate(s) if x=="L"]
R_i = [i for i, x in enumerate(s) if x=="R"]

if len(L_i)==0 and len(R_i)==0:
    print(n)
elif len(L_i)==0:
    print(R_i[0])
elif len(R_i)==0:
    print(n-L_i[0]-1)
else:
    standing = 0
    #there are both L and R
    if R_i[0]<L_i[0]:
        # R comes first
        standing += R_i[0]
        if R_i[-1]>L_i[-1]: standing += R_i[-1]-L_i[-1]-1
        else: standing += n-L_i[-1]-1
        standing += num_standing(s[R_i[0]:L_i[-1]+1])

    else:
        # L comes first
        standing += R_i[0]-L_i[0]-1
        if R_i[-1]>L_i[-1]: standing += R_i[-1]-L_i[-1]-1
        else: standing += n-L_i[-1]-1
        standing += num_standing(s[R_i[0]:L_i[-1]+1])
        if len(L_i)==1 and len(R_i)==1: standing//=2
    print(standing)


n=int(input())
s=input()
last = ''
lasti = -1
count=0
for i,v in enumerate(s):
    if v == 'R' and lasti == -1:
       count += i
       last = 'R'
       lasti = i
    elif v=='L' and lasti == -1:
        last = 'L'
        lasti = i
    elif last=='L' and v=='R':
        count += i-lasti-1
        last = 'R'
        lasti = i
    elif last == 'R' and v == 'L':
        count += 0 if (i+lasti)%2 > 0  else 1
        last = 'L'
        lasti = i

if last == 'L':
    count += (n-1)-lasti
if lasti == -1:
    count = n
print(count)



a = []
n = int(input())
a = input().strip()
cnt = 0
l = -1
r = -1
for i in range(n):
    if a[i] == '.':
        if l == -1 and r == -1:
            cnt += 1
    if a[i] == 'L':
        if r != -1:
            l = i
            cnt += (l - r + 1) % 2
        else:
            cnt -= i
            l = i
    if a[i] == 'R':
        if l != -1:
            r = i
            cnt += r - l - 1
        else:
            r = i
if l > r:
    cnt += n - l - 1
print(cnt)
            
        


n = int(input())
s = input()
r = [0]*n
l = [0]*n
index = -1
for i in range(0, n):
    if s[i]=='.':
        r[i] = index
    elif s[i]=='R':
        index = i
        r[i] = 0
    elif s[i]=='L':
        r[i] = -1
        index = -1
index = -1
result = 0
for i in range(n-1, -1, -1):
    if s[i]=='.':
        l[i] = index
    elif s[i]=='L':
        index = i
        l[i] = 0
    elif s[i]=='R':
        l[i] = -1
        index = -1
    #print('i='+str(i)+' l='+str(l[i])+' r='+str(r[i]))
    if (l[i]<0 and r[i]<0) or (l[i]>=0 and r[i]>=0 and l[i]-i==i-r[i]):
        result+=1
print(result)


def run():
    n = int(input())
    card = input()
    cnt = 0
    start = True
    ans = 0
    last = '.'
    for i in range(n):
        if card[i] == '.':
            cnt += 1
        elif card[i] == 'L':
            if start == True:
                start = False
                cnt = 0
            else:
                ans += cnt%2
                cnt = 0
            last = 'L'    
        else:
            start = False
            ans += cnt
            cnt = 0
            last = 'R'       
    if last != 'R':
        ans += cnt
    print (ans)


run()


input()
s = input() + 'R'
last = 'L'
ix = -1
cnt = 0
for i, v in enumerate(s):
    if v == 'R':
        if last == 'L':
            cnt += i - ix - 1
        ix = i
        last = 'R'
    elif v == 'L':
        if last == 'R' and (i - ix) % 2 == 0:
            cnt += 1
        last = 'L'
        ix = i
print(cnt)

import re
input()
ds = "L"+input()+"R"
res = len(re.findall("R(?:\.\.)*\.L", ds)) + sum([len(s)-2 for s in re.findall("L\.*R", ds)])
print(res)

n=int(input())
a=input()
def work(a,b):
    l=[-1]*n
    for i in range(0,n):
        if a[i]=='.':
            l[i]=l[i-1]
        elif a[i]!=b:
            l[i]=-1
        else:
            l[i]=i
    return l
l=work(a,'R')
r=( work(a[::-1],'L') )[::-1]
print(sum( ( l[i]==-1 and r[i]==-1 ) or (l[i]!=-1 and r[i]!=-1 and n-r[i]-1+l[i]==2*i) and a[i]=='.' for i in range(0,n)))


n = int(input())
s = input()
s = list(s)
v = 0
while(True):
    lExits = False
    rExits = False
    if ('L' in s):
        l = s.index('L')
        lExits = True
    if ('R' in s):
        r = s.index('R')
        rExits = True
    if (lExits == False and rExits == False):
        break
    if (lExits == True and rExits == False):
        for i in range(l+1):
            s[i] = 'F'
        break
    if (lExits == False and rExits == True):
        for i in range(r,n):
            s[i] = 'F'
        break
    if (lExits == True and rExits == True):
        if (l < r):
            for i in range(l+1):
                s[i] = 'F'
        else:
            for i in range(r,l+1):
                s[i] = 'F'
            if ((l - r) % 2 == 0):
                s[r] = '.'
c = 0
for i in s:
    if (i == '.'):
        c += 1
print(c)
    


n = int(input())
s = k = 0
for i, x in enumerate(input(), 1):
    if x == 'R': k = i
    elif x == 'L':
        if k: s += (k + i + 1) % 2
        else: s = 0
        k = 0
    elif not k: s += 1
print(s)

n = int(input())
s = list(input())
count = 0
l, r = -1, 0

while True:
    if l == -1:
        if 'R' in s:
            r = s.index('R')
            if 'L' in s[:r]:
                l = s.index('L')
                count += r - l - 1
            else:
                count += r
            l = r
        elif 'L' in s:
            count = n - s.index('L') - 1
            break
        else:
            count = n
            break
    else:
        if s[l] == 'R':
            if 'L' in s[l:]:
                r += s[l:].index('L')
                if (r - l - 1) & 1:
                    count += 1
                l = r
            else:
                break
        else:
            if 'R' in s[l:]:
                r += s[l:].index('R')
                count += r - l - 1
                l = r
            else:
                count += n - l -1
                break

print(count)


n = int(input())
s = input()
c = n
k = 0
l, r = 0, 0
for i in range(n):
  if s[i] == '.':
    continue
  if s[i] == 'L':
    k -= 1
    l = i
  else:
    k += 1
    r = i
  if k < 0:
    c -= i + 1
    k = 0
  elif k == 0:
    c -= (l - r + 1) - (l - r + 1) % 2
if k > 0:
  c -= n - r
print(c)

n = int(input())
s = input()
c = k = l = r = 0
for i in range(n):
  if s[i] == '.':
    if k == 0:
      c += 1
  else:
    if s[i] == 'L':
      k -= 1
      l = i
    else:
      k += 1
      r = i
    if k < 0:
      k = 0
      c = 0
    elif k == 0:
      c += (l - r + 1) % 2
print(c)

n = int(input())
s = input()
c = k = l = r = 0
for i in range(n):
  if s[i] == '.':
    if k == 0:
      c += 1
  else:
    if s[i] == 'L':
      k -= 1
      l = i
    else:
      k += 1
      r = i
    if k < 0:
      k = c = 0
    elif k == 0:
      c += (l - r + 1) % 2
print(c)

import sys
n = int(input())
s = input()
a = []
for i in range(n):
    if s[i] == 'L':
        a.append(['L', i])
    if s[i] == 'R':
        a.append(['R', i])
i = 0
j = len(a) - 1

if len(a) == 0:
    print(n)
    return
if a[0][0] == 'L':
    A = a[0][1]
    i = 1
else:
    A = -1
if a[len(a) - 1][0] == 'R':
    j = len(a) - 2
    D = a[-1][1]
else:
    D = n
ans = 0
if i > j:
    B  = 1
    C = 0
else:
    B = a[i][1]
    C = a[j][1]
while i < j:
    if (a[i][1] - a[i + 1][1]) % 2 == 0:
        ans += 1
    if i != j - 1:
        ans += (a[i + 2][1] - a[i + 1][1] - 1)
    i += 2
if B > C:
    ans += (D - A - 1)
else:
    ans += (B - A - 1 + D - C - 1)
print(ans)

n = int(input())
s = input()
cnt = 0
num = 0
chk = False

for i in range(n):
	if chk and s[i] == 'L':
		if cnt % 2 == 1:
			num += 1
		chk = False 
		continue
	if s[i] == 'R':
		chk = True 
		cnt = 0
		continue  
	if chk: 
		cnt += 1
		continue
	if s[i] == 'L':
		num = 0
	else: 
		num += 1 
print(num)


import sys
n = int(input())
s = str(input())
ans = num = 0
l = r = False
k = 0
j = 0
while j < n:
    if s[j] == 'R' or s[j] == 'L':
        break
    else:
        j += 1
if j == n:
    print(n)
    return
for i in range(n):
    if s[i] == '.' and l is False:
        num += 1

    if s[i] == 'L' and r is False:
        num = 0
        l = True
    if s[i] == '.' and l is True:
        ans += 1
    if s[i] == 'R' and l is True:
        k = i
        l = False
        r = True
    if s[i] == 'R' and l is False:
        ans += num
        num = 0
        r = True
    if s[i] == 'L' and r is True:
        if num % 2 == 1:
            ans += 1
        num = 0
        l = True
        f = False

print(ans)

n = int(input())
s = input()
balance = 0
i = 0
calc = [1] * n
firstr, lastl = -1, -1
while i < n:
    if s[i] == 'R':
        balance += 1
        if firstr == -1:
            firstr = i
        i += 1
    elif s[i] == 'L':
        balance -= 1
        lastl = i
        i += 1
    else:
        i += 1
        continue
    if balance == 0:
        if (firstr - lastl) % 2 == 0:
            for j in range(firstr, lastl + 1):
                calc[j] = 0
            calc[(firstr + lastl) // 2] = 1
        else:
            for j in range(firstr, lastl + 1):
                calc[j] = 0
        firstr = -1
        lastl = -1
    elif balance == -1:
        calc = [0] * i + calc[i:]
        balance = 0
if balance != 0:
    calc = calc[:firstr] + [0] * (n - firstr)
print(sum(calc))

n = int(input())
st = list(input())
ans = 0
i = 0
while st and i < len(st):
    if st[i] == 'L':
        n -= i + 1
        st = st[i + 1:]
        i = -1
    elif st[i] == 'R':
        n -= 1
        j = i + 1
        while j < len(st):
            if st[j] == 'L':
                n -= j - i
                if (j - i) % 2 == 0:
                    n += 1
                st = st[j + 1:]
                i = -1
                break
            if st[j] == 'R':
                n -= j - i - 1
                st = st[j:]
                i = -1
                break
            j += 1
        else:
            n -= j - i - 1
    i += 1
print(n)

n, prev, prch, val = int(input()), -1, 'L', 0
for i, d in enumerate(input()):
    if d == 'L':
        if prev != -1 and (i - prev) % 2 == 0:
            val += 1
        prev, prch = i, d
    elif d == 'R':
        val += i - prev - 1
        prev, prch = i, d
if prch == 'L':
    val += n - prev - 1
print(val)


n = int(input())
s = input().split('L')
ans = 0
if 'R' not in s[0]:
	if len(s) != 1:
		s = s[1:]
if 'R' in s[-1]:
	s[-1] = s[-1][:s[-1].index('R')]
for sub in s:
	if 'R' not in sub:
		ans += len(sub)
	else:
		idx = sub.index('R')
		ans += idx
		ans += (len(sub) - idx - 1) % 2
print(ans)


def main():
    input()
    res = r = 0
    for i, x in enumerate(input(), 1):
        if x == 'R':
            r = i
        elif x == 'L':
            if r:
                res += (r + i - 1) & 1
            else:
                res = 0
            r = 0
        elif not r:
            res += 1
    print(res)


def __starting_point():
    main()
__starting_point()

def main():
    input()
    res = r = 0
    for i, x in enumerate(input(), 1):
        if x == 'R':
            r = i
        elif x == 'L':
            if r:
                res += (r + i - 1) & 1
            else:
                res = 0
            r = 0
        elif not r:
            res += 1
    print(res)


main()