Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

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

MOD = 10 ** 9 + 7


def prime_counter(n):
    ret = []
    for i in range(2, int(n / 2) + 1):
        count = 0
        while n % i == 0:
            n /= i
            count += 1
        if 0 < count:
            ret.append(count)
        if n == 1:
            break
    if 1 < n:
        ret.append(1)
    return ret


def comb(n, r):
    r = min(r, n - r)
    if r == 0:
        return 1
    elif r == 1:
        return n
    return (n % MOD) * pow(r, MOD - 2, MOD) * comb(n - 1, r - 1) % MOD


factnum = prime_counter(M)
ans = 1

for i, p in enumerate(factnum):
    ans *= comb(p + N - 1, p)

ans %= MOD
print(ans)


### FIXED CODE ###

MOD = 10 ** 9 + 7

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

f = []
p = 2
while p * p <= M:
    if M % p != 0:
        p += 1
        continue
    c = 0
    while M % p == 0:
        c += 1
        M //= p
    f.append(c)
    p += 1
if M != 1:
    f.append(1)

ans = 1
for i in f:
    c = 1
    for j in range(i):
        c = c * (N + j) // (j + 1)
    ans = ans * c % MOD
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(input().split())

b = []
r = 1
l = 0
for i in range(n):
    if(i == 0):
        b.append(a[i])
        #print(b)
    else:
        if(r == 1):
            b.append(a[i])
            r = 0
            l = 1
            #print("r == 1", b)
        elif(l == 1):
            b.insert(0, a[i])
            r = 1
            l = 0
            #print("l == 1", b)
        else:
            pass

if(n % 2 == 0):
    b.reverse()
    

print(*b)


### FIXED CODE ###

from collections import *
n = int(input())
a = [int(i) for i in input().split()]

b = deque()

b.append(a[0])
for i in range(1, n):
    if(i%2 == 1):
        b.append(a[i])  
    else:
        b.appendleft(a[i])
   

if(n % 2 == 0):
    b.reverse()
    

print(' '.join(map(str, b)))
### BUGGY CODE ###

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

dp = [float("inf")]*(N + 2)
dp[0] = 0
for i in range(N):
    for k in range(1, K + 1):
        if i < N - k:
            dp[i + k] = min(dp[i + k], abs(h[i] - h[i + k]) + dp[i])

print(dp[N - 1])


### FIXED CODE ###

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

dp = [float("inf")]*(N + 2)
dp[0] = 0
for i in range(N):
    for k in range(1, min(K + 1, N - i)):
        dp[i + k] = min(dp[i + k], abs(h[i] - h[i + k]) + dp[i])

print(dp[N - 1])
### BUGGY CODE ###

MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] = format(a[i], '060b')
s = 0
for i in range(60):
    c = 0
    for j in range(n):
        if a[j][i] == '0':
            c += 1
    s += pow(2,59-i,MOD)*c*(n-c)
print(s%MOD)

### FIXED CODE ###

MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
s = 0
m = 1
for i in range(60):
    c = sum(ai & m for ai in a)
    c //= m
    s = (s + m*c*(n-c))%MOD
    m <<= 1
print(s)
### BUGGY CODE ###

def resolve():
    N = int(input())
    S = input()
    cnt = {'R': [], 'B': [], 'G': []}
    for i, c in enumerate(S):
        cnt[c].append(i)
    from itertools import permutations
    ans = 0
    for (ci, cj, ck) in permutations(['R', 'B', 'G']):
        for i in cnt[ci]:
            for j in cnt[cj]:
                if j < i:
                    continue
                for k in cnt[ck]:
                    if k < j or ((j - i) == (k - j)):
                        continue
                    ans += 1
    print(ans)
resolve()

### FIXED CODE ###

from collections import Counter

N = int(input())
s = input()
cnt = Counter(s)
R = cnt.get('R', 0)
G = cnt.get('G', 0)
B = cnt.get('B', 0)
ans = R * G * B
for i in range(N-1):
  for j in range(i+1, N):
    if s[i] != s[j] and 2*j-i < N and s[i] != s[2*j-i] and s[j] != s[2*j-i]:
      ans -= 1
print(ans)
### BUGGY CODE ###

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

# AtCoder Beginner Contest
# Problem C


if __name__ == '__main__':
    spot_count = int(input())
    spots = [0] + list(map(int, input().split())) + [0]
    mod_spots = spots

    for i in range(spot_count):
        tmp = mod_spots[i + 1]
        if mod_spots[i] <= mod_spots[i + 2]:
            mod_spots[i + 1] = mod_spots[i]
        elif (mod_spots[i] > 0) and mod_spots[i + 2] > 0:
            mod_spots[i + 1] = 0
        else:
            mod_spots[i + 1] = mod_spots[i]

        cost = sum([abs(mod_spots[j + 1] - mod_spots[j]) for j in range(spot_count + 1)])
        mod_spots[i + 1] = tmp
        print(cost)


### FIXED CODE ###

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    spot_count = int(input())
    spots = [0] + list(map(int, input().split())) + [0]

    # See:
    # https://www.youtube.com/watch?v=WFg2yJGZ2Cw
    # https://img.atcoder.jp/arc093/editorial.pdf
    total_distance = 0
    total_cost = 0

    for i in range(spot_count + 1):
        total_distance += abs(spots[i + 1] - spots[i])

    for j in range(1, spot_count + 1):
        shortcut_cost = (abs(spots[j - 1] - spots[j]) + abs(spots[j] - spots[j + 1]))
        total_cost = total_distance + abs(spots[j - 1] - spots[j + 1]) - shortcut_cost
        print(total_cost)
### BUGGY CODE ###

h,w = map(int,input().split())
raw = []
for _ in range(h):
  tmp = input()
  add = []
  for j in range(w):
    if tmp[j] == '.':
      add.append(0)
    else:
      add.append(2)
  raw.append(add)
nex = [[0,1],[0,-1],[1,0],[-1,0]]
can = []
from copy import deepcopy as dc
for a in range(h):
  for b in range(w):
    if raw[a][b] == 2:
      continue
    last = dc(raw)
    last[a][b] = 1
    ans = 0
    while True:
      now = dc(last)
      ans += 1
      for i in range(h):
        for j in range(w):
          if last[i][j] == 0:
            for x in nex:
              if 0 <= i+x[0] < h and 0 <= j+x[1] < w:
                if last[i+x[0]][j+x[1]] == 1:
                  now[i][j] = 1
                  break
      check = 1
      for i in range(h):
        for j in range(w):
          check *= now[i][j]
      if check > 0:
        can.append(ans)
        break
      last = dc(now)
print(max(can))

### FIXED CODE ###

h,w = map(int,input().split())
n = h * w
raw = []
for i in range(h):
  tmp = input()
  add = []
  for j in range(w):
    if tmp[j] == '.':
      add.append(0)
    else:
      add.append(1)
  raw += add
wf = [[1000 for _ in range(n)] for _ in range(n)]
for i in range(n):
  if raw[i] == 0:
    wf[i][i] = 0
    d = []
    if i-w >= 0:
      d.append(i-w)
    if i+w < n:
      d.append(i+w)
    if i%w != 0:
      d.append(i-1)
    if (i+1)%w != 0:
      d.append(i+1)
    for e in d:
      if raw[e] == 0:
        wf[i][e] = 1
#for x in wf:
  #print(x)
for k in range(n):
  for i in range(n):
    for j in range(n):
      if wf[i][k] + wf[k][j] < wf[i][j]:
        wf[i][j] = wf[i][k] + wf[k][j]
ans = 0
for i in range(n):
  for j in range(n):
    if ans < wf[i][j] % 1000:
      ans = wf[i][j]
print(ans)
#for x in wf:
  #print(x)
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
s=set()
for i in range(n):
     for j in range(i,n):
          s.add(sum(a[i:j+1]))
s=list(s)
x=0
for i in range(40):
     x_=x+2**(39-i)
     cnt=0
     for a in s:
          if x_&a==x_:
               cnt+=1
     if cnt>=k:
          x=x_
print(x)

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
s=set()
for i in range(n):
     su=0
     for j in range(i,n):
          su+=a[j]
          s.add(su)
s=list(s)
x=0
for i in range(40):
     x_=x+2**(39-i)
     cnt=0
     for a in s:
          if x_&a==x_:
               cnt+=1
     if cnt>=k:
          x=x_
print(x)
### BUGGY CODE ###

#!/usr/bin/env python3

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

    ds_list = []
    for k in range(20):
        ds = [-1] * N
        ds_list.append(ds)
        half = 2 ** k
        divider = half * 2
        d = -1
        for i in range(N):
            if half <= A[i] % divider:
                ds[i] = d = 0
            elif 0 <= d:
                d += 1
                ds[i] = d

    cn = 0
    for r in range(N - 1, -1, -1):
        if r == 0:
            cn += 1
            break

        l = 0
        for k in range(20):
            d = ds_list[k][r]
            if d == -1:
                continue
            if d == 0:
                if ds_list[k][r - 1] == -1:
                    continue
                l = max(l, r - ds_list[k][r - 1])
            else:
                if d == r or ds_list[k][r - d - 1] == -1:
                    continue
                l = max(l, r - d - ds_list[k][r - d - 1])
        cn += r - l + 1



    print(cn)


if __name__ == '__main__':
    main()



### FIXED CODE ###

#!/usr/bin/env python3

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

    ds_list = []
    for k in range(20):
        ds = [-1] * N
        ds_list.append(ds)
        half = 2 ** k
        divider = half * 2
        last = -1
        for i in range(N):
            if half <= A[i] % divider:
                ds[i] = last = i
            else:
                ds[i] = last


    cn = 0
    for r in range(N - 1, -1, -1):
        if r == 0:
            cn += 1
            break

        lp = -1
        for k in range(20):
            p = ds_list[k][r]
            if p <= 0:
                continue
            else:
                lp = max(lp, ds_list[k][p - 1])
        cn += r - lp


    print(cn)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

def main(A,D,N):
    K=min(N,len(D))
    for i in range(K):
        if A[i]>D[i]:
            return sum(D[:i]+A[i:])
    return sum(D[:K]+A[K:])

N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
CB=[]
for m in range(M):
    b,c=map(int,input().split())
    CB.append([c,b])
CB.sort()
CB.reverse()
D=[]
while len(D)<N and CB!=[]:
    D.append(CB[0][0])
    CB[0][1]-=1
    if CB[0][1]==0:
        CB.remove(CB[0])
for cb in CB:
    D+=[cb[0]]*cb[1]
print(main(A,D,N))

### FIXED CODE ###

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

BC=[]
for m in range(M):
    b,c=map(int,input().split())
    BC.append([b,c])

A.sort()
BC.sort(key=lambda x:x[1],reverse=True)

D=[]
for [b,c] in BC:
    D+=[c]*b
    if len(D)>N:
        break

if len(D)<N:
    D+=[0]*(N-len(D))

AD=[max(A[i],D[i]) for i in range(N)]
 
print(sum(AD))
### BUGGY CODE ###

N, P = map(int, input().split())
ans = 1
def main(n, p):
  global ans
  for i in range(2, int(p**(1/n)+4)):
    t = i**n
    if p % t == 0:
      ans *= i
      return main(n, p//t)
  return ans

print(main(N, P))

### FIXED CODE ###

N, P = map(int, input().split())
ans = 1
def main(n, p):
  if n == 1:
    return P
  global ans
  for i in range(2, int(p**(2/n))):
    t = i**n
    if p % t == 0:
      ans *= i
      return main(n, p//t)
  return ans

print(main(N, P))
### BUGGY CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, X, M = MAP()
ans = 0
flag = False
L = []
dic = dict()
for i in range(1, N+1):
    if X % M not in L:
        L.append(X % M)
    else:
        flag = True
        tmp = X % M
        l = len(L)
        break
    X = (X % M) ** 2
if flag == True:
    index = L.index(tmp)
    nR = L[:index]
    R = L[index:]
    amari = (N - len(nR)) % len(R)
    ans = sum(nR) + (N - len(nR)) // len(R) * sum(R) + sum(R[:amari])
    print(ans)    
else:
    ans = sum(L)
    print(ans)

### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, X, M = MAP()
ans = 0
flag = False
L = []
dic = dict()
for i in range(1, N+1):
    if X % M not in L:
        L.append(X % M)
    else:
        flag = True
        tmp = X % M
        l = len(L)
        break
    X = (X % M) ** 2
if flag == True:
    index = L.index(tmp)
    nR = L[:index]
    R = L[index:]
    amari = (N - len(nR)) % len(R)
    ans = sum(nR) + (N - len(nR)) // len(R) * sum(R) + sum(R[:amari])
    print(ans)    
else:
    ans = sum(L)
    print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
count=0
num=0
for i in range(N):
  while count != N:
    count = i
    try:
      C = i+1
      num += A[i]*A[C]
      C+=1
      count+=1
    except:
      pass
print(num)

### FIXED CODE ###

mod=10**9 + 7
n=int(input())
a=list(map(int,input().split()))
ans=0
total=sum(a)
for i in a:
  total -= i
  ans += total*i
print(ans%mod)
### BUGGY CODE ###

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


INF = 10**18


def main():

    N, K = in_nn()
    H = in_nl()

    dp = [INF] * N
    dp[0] = 0

    for i in range(N):
        for k in range(1, K + 1):
            if i + k < N:
                dp[i + k] = min(dp[i + k], dp[i] + abs(H[i] - H[i + k]))

    print(dp[-1])


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


INF = 10**18


def main():

    N, K = in_nn()
    H = in_nl()

    dp = [INF] * N
    dp[0] = 0

    for i in range(N):
        for k in range(1, K + 1):
            if i + k < N:
                dp[i + k] = min(dp[i + k], dp[i] + abs(H[i] - H[i + k]))

    print(dp[-1])


if __name__ == '__main__':
    main()
### BUGGY CODE ###

x, y, z, k = map(int, input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)            

abc=[]

for i in range(x):
    for j in range(y):
        for l in range(z):
                if((i+1)*(j+1)*(l+1)<=k):
                        abc.append(a[i]+b[j]+c[l])

abc.sort(reverse=True)
for i in abc[:k]:
    print(i)

### FIXED CODE ###

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ab = sorted(x+y for x in a for y in b)[:-k-1:-1]
abc = sorted(x+y for x in ab[:k] for y in c)[:-k-1:-1]
print(*abc, sep='\n')
### BUGGY CODE ###

import bisect
def main():
  N = int(input())
  parts = [[] for i in range(3)]
  con = [0] * N
  
  ans = 0
  
  for i in range(3):
    t = sorted(list(map(int,input().split())))
    parts[i] = t
  
  under =parts[2]
  middle = parts[1]
  upper = parts[0]
  
  for i in range(N):
    p = middle[i]
    q = bisect.bisect_left(upper,p)
    con[i] += q
  
  
  for i in range(N):
    p = under[i]
    q = bisect.bisect_left(middle,p)
    ans += sum(con[:q])
      
  print(ans)
main()

### FIXED CODE ###

import bisect

N = int(input())
parts = [[] for i in range(3)]
con = [0] * N

ans = 0

for i in range(3):
  t = sorted(list(map(int,input().split())))
  parts[i] = t

under =parts[2]
middle = parts[1]
upper = parts[0]

for i in range(N):
  p = middle[i]
  ans += bisect.bisect_left(upper,p) * (N - bisect.bisect_right(under,p))
    
print(ans)
### BUGGY CODE ###

N, M = map(lambda x: int(x), input().split())
a = [int(input()) for i in range(M)]
#print(N)
#print(M)
#print(a)
old = [0]
while not all(map(lambda y: y==N, old)):
  new = []
  for x in old:
    if x == N:
      new.append(x)
    if x+1 not in a and x+1 <= N:
      new.append(x+1)
    if x+2 not in a and x+2 <= N:
      new.append(x+2)
  old = new
print(len(old)%1000000007) 


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000000)

def dfs(x):
  if x == N:
    return 1
  if x > N:
    return 0
  if memo[x] >= 0:
    return memo[x]
  memo[x] = dfs(x+1) + dfs(x+2)
  return memo[x]

N, M = map(lambda x: int(x), input().split())
a = [int(input()) for i in range(M)]
#print(N)
#print(M)
#print(a)
memo = [-1]*(N+1)
for ai in a:
  memo[ai] = 0
count = dfs(0)
print(count%1000000007)
### BUGGY CODE ###

N = int(input())
A = input().split(" ")
B = input().split(" ")
C = input().split(" ")
m = 0

for n in range(N):
    A[n] = int(A[n])
    B[n] = int(B[n])
    C[n] = int(C[n])

A.sort()
B.sort()
C.sort()

for i in range(N):
    for j in range(N):
        for k in range(N):
            if A[i] < B[j] and B[j] < C[k]:
                m =  m + N - k
                break

print(m)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
A.sort()
B.sort()
C.sort()
C.reverse()
 
ans = 0
ai = 0
ci = N-1
for b in B:
    while ai < N and A[ai] < b:
        ai += 1
    while ci >= 0 and C[ci] <= b:
        ci -= 1
    ans += ai * (ci+1)
 
print(ans)
### BUGGY CODE ###

MAX_PRIME = 10**5
is_prime = [1] * MAX_PRIME
primes = []
is_prime[0] = 0
is_prime[1] = 0
for i in range(MAX_PRIME):
    if is_prime[i]:
        primes.append(i)
        for j in range(2, ((MAX_PRIME-1)//i) + 1):
            is_prime[i*j] = 0

def factorization(n):
    factor = {}
    for p in primes:
        if p ** 2 > n:
            break
        while n % p == 0:
            n //= p
            if p not in factor:
                factor[p] = 1
            else:
                factor[p] += 1
    if n > 1:
        factor[n] = 1
    return factor

n = int(input())
ans = 1
for _, c in factorization(n-1).items():
    ans *= c + 1

f = factorization(n)
k = list(f.keys())
def dfs(num, i, cum, searched):
    if num not in searched:
        x = n
        while x % num == 0 and x > 0:
            x //= num
        if x % num == 1:
            cum += 1
    searched.add(num)
    if i < len(k):
        p = k[i]
        for j in range(f[p]+1):
            cum = dfs(num * p ** j, i+1, cum, searched)
    return cum

print(f)
print(dfs(1, 0, 0, set()) + ans - 1, ans)

### FIXED CODE ###

MAX_PRIME = 10 ** 6
is_prime = [1] * MAX_PRIME
primes = []
is_prime[0] = 0
is_prime[1] = 0
for i in range(MAX_PRIME):
    if is_prime[i]:
        primes.append(i)
        for j in range(2, ((MAX_PRIME-1)//i) + 1):
            is_prime[i*j] = 0

def factorization(n):
    factor = {}
    for p in primes:
        if p ** 2 > n:
            break
        while n % p == 0:
            n //= p
            if p not in factor:
                factor[p] = 1
            else:
                factor[p] += 1
    if n > 1:
        factor[n] = 1
    return factor

n = int(input())
ans = 1
for _, c in factorization(n-1).items():
    ans *= c + 1

f = factorization(n)
k = list(f.keys())
def dfs(num, i):
    ret = 0
    if i == len(k):
        if num != 1:
            x = n
            while x % num == 0:
                x //= num
            if x % num == 1:
                ret += 1
        return ret
    else:
        p = k[i]
        for j in range(f[p]+1):
            ret += dfs(num * p ** j, i+1)
        return ret

print(dfs(1, 0) + ans - 1)
### BUGGY CODE ###

n = int(input())
def factorize(n):
    b = 2
    fct = []
    end = int(n ** (0.5)) + 2
    for b in range(2, end):
      while n % b == 0:
        n //= b
        fct.append(b)
      if n == 1:
        break
    if n > 1:
      fct.append(n)
    return fct

fact = factorize(n)
dif = []
from itertools import combinations as com
for i in range((len(fact) + 1) // 2 + 1):
  for cands in com(fact, i):
    ans = 1
    for cand in cands:
      ans *= cand
    dif.append(n//ans + ans - 2)
print(min(dif))



### FIXED CODE ###

n = int(input())

end = int(n**0.5) + 2
dif = []
for i in range(1, end):
  if n % i == 0:
    dif.append(abs(n//i + i) - 2)
print(min(dif))
### BUGGY CODE ###

N = int(input())
C = input()

if "R" not in C:
    print(0)
    exit()
count = 0

for i in range(N):
    if C[i] == 'W':

        index = C.rfind('R', i)
        if index >= 0:
            count += 1
        c = list(C)
        c[i] = 'R'
        c[index] = 'W'
        C = "".join(c)
    if 'R' not in C[i+1:]:
        break

print(count)



### FIXED CODE ###

N = int(input())
C = input()

from collections import Counter

if "R" not in C:
    print(0)
    exit()
count = 0

c = Counter(C)
k = c["R"]
D = C[:k]
d = Counter(D)
print(d["W"])
### BUGGY CODE ###

h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]

from collections import deque
def bfs(maze):
    ans = 0
    d = [[-1] * w for _ in range(h)]
    que = deque([])
    for i in range(h):
        for j in range(w):
            if maze[i][j] == '#':
                que.append([i, j])
                d[i][j] = 0
    #que = deque([[sy, sx]])
    #d[sy][sx] = 0
    while que:
        y, x = que.popleft()
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            ny, nx = y + j, x + k
            if 0 <= nx < w  and 0 <= ny < h  and d[ny][nx] == -1 and maze[ny][nx] != "#":
                d[ny][nx] = d[y][x] + 1
                ans = max(ans, d[ny][nx])
                que.append([ny, nx])
                
    return ans

print(bfs(maze))

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
grid = [input() for i in range(H)]

# 初期の黒('#')の位置からの距離
dist = [[-1]*W for _ in range(H)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append((h, w))
            dist[h][w] = 0

def bfs(black_cells, dist):
    """
    BFSを用いて、全マス目を黒くする回数を求める

    Args:
        black_cells: 「開始時の黒マス」の座標が入ったキュー（複数座標あり）
        dist: 「開始時の黒マス」からの距離の入ったリスト  [[-1, -1, 0], ...]
        　　　（白マスの初期値は0）

    Returns:
        g: 操作を繰り返した数
    """
    d = 0
    while black_cells:
        # キューとして使うのでpop()ではなくpopleft()
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:  # セルが白('.')であるのと同義
                dist[new_h][new_w] = d+1
                black_cells.append((new_h, new_w))
    return d

d = bfs(black_cells, dist)
print(d)