Harryxun/stf_run huggingface dataset:
n=int(input())
s=int(input())
if n==s:
  print(n+1)
  exit()
for b in range(2,int(n**(1/2))+1):
  m=n
  wa=0
  while m>0:
    wa+=m%b
    m=m//b
  if wa==s:
    print(b)
    exit()

for p in range(int(n**(1/2)),0,-1):
  if (n-s)%p==0:
    b=(n-s)//p+1
    if p+n%b==s:
      print(b)
      exit()
print(-1)   

### FIXED CODE ###

n=int(input())
s=int(input())
if n==s:
  print(n+1)
  exit()
if n<s:
  print(-1)
  exit()
for b in range(2,int(n**(1/2))+1):
  m=n
  wa=0
  while m>0:
    wa+=m%b
    m=m//b
  if wa==s:
    print(b)
    exit()

for p in range(int((n-1)**(1/2)),0,-1):
  if (n-s)%p==0:
    b=(n-s)//p+1
    if p+n%b==s:
      print(b)
      exit()
print(-1)
a, b, c, k = map(int, input().split())
s = 0
if  a + b >= k:
    s = a
else:
    s = a - (c - b) 
print(s)


### FIXED CODE ###

s = input()
t = input()
if t.startswith(s) == 1:
    print("Yes")
else:
    print("No")
def main():
    n = int(input())
    a = list(map(int,input().split()))
    listcost = []
  
    for i in range(min(a),max(a)):
        cost = 0
        for j in a:
            if i != j:
                cost += (i-j) ** 2
        listcost.append(cost)
    print(min(listcost))
  
  
if __name__=='__main__':
  main()

### FIXED CODE ###

def main():
    n = int(input())
    a = list(map(int,input().split()))
    listcost = []
  
    for i in range(min(a),max(a)+1):
        cost = 0
        for j in a:
            if i != j:
                cost += (i - j) ** 2
        listcost.append(cost)
    print(min(listcost))
  
  
if __name__=='__main__':
  main()
N, C, K = map(int, input().split())
T = [int(input()) for i in range(N)]
T.sort()
answer = 0
while len(T) >　0:
    limit = T[0] + K
    counter = 0
    while counter < C:
        if len(T) == 0:
            break
        if T[0] > limit:
            break
        del T[0]
        counter += 1
    answer += 1
print(answer)

### FIXED CODE ###

N, C, K = map(int, input().split())
T = [int(input()) for i in range(N)]
T.sort()
answer = 0
while len(T) > 0:
    limit = T[0] + K
    counter = 0
    while counter < C:
        if len(T) == 0:
            break
        if T[0] > limit:
            break
        del T[0]
        counter += 1
    answer += 1
print(answer)
N=int(input())
a=list(map(int,input().split()))
odd=0
four=0
for i in range(N):
  if a[i]%4==0:
    four+=1
  elif a[i]%2!=0:
    odd+=1
if four>=odd or four+odd=N:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N=int(input())
a=list(map(int,input().split()))
odd=0
four=0
for i in range(N):
  if a[i]%4==0:
    four+=1
  elif a[i]%2!=0:
    odd+=1
if four>=odd:
  print("Yes")
else:
  if odd==four+1 and odd+four==N:
    print("Yes")
  else:
    print("No")
N, M, K = map(int, input().split())

to = [[] for i in range(N)]
block = [[] for i in range(N)]
sets = []

for i in range(M):
    A, B = map(int, input().split())
    to[A-1].append(B-1)
    to[B-1].append(A-1)
    flg = False
    A_idx = None
    B_idx = None
    for tmp_idx, tmp_set in enumerate(sets):
        if A - 1 in tmp_set:
            A_idx = tmp_idx
        if B - 1 in tmp_set:
            B_idx = tmp_idx
        if A - 1 in tmp_set or B - 1 in tmp_set:
            flg = True
            tmp_set.add(A - 1)
            tmp_set.add(B - 1)

    if not flg:
        sets.append({A-1, B-1})
    elif A_idx != None and B_idx != None and A_idx != B_idx:
        for j in sets[B_idx]:
            sets[A_idx].add(j)
        sets.pop(B_idx)

for i in range(K):
    C, D = map(int, input().split())
    block[C-1].append(D-1)
    block[D-1].append(C-1)

print(sets)

for i in range(N):
    i_idx = -1
    for tmp_idx, tmp_set in enumerate(sets):
        if i in tmp_set:
            i_idx = tmp_idx
    l = len(sets[i_idx])
    m1 = len(to[i])
    
    m2 = 0
    for j in block[i]:
        if j in sets[i_idx]:
            m2 += 1

    if i != N-1:
        print(l - 1 - m1 - m2, end=' ')
    else:
        print(l - 1 - m1 - m2)

### FIXED CODE ###

import sys
sys.setrecursionlimit(4100000)

from collections import Counter

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

to = [[] for i in range(N)]
block = [[] for i in range(N)]
sets = []

is_visited = [False] * N
graph_g = [None] * N
graph_cnt = -1

def dfs(s, g):
    global graph_cnt
    if is_visited[s]:
        return 0

    is_visited[s] = True
    if g == None:
        graph_cnt += 1
        graph_g[s] = graph_cnt
    else:
        graph_g[s] = g

    for edge in to[s]:
        if graph_g[edge] == None:
            dfs(edge, graph_cnt)


for i in range(M):
    A, B = map(int, input().split())
    to[A-1].append(B-1)
    to[B-1].append(A-1)

for i in range(N):
    if is_visited[i]:
        continue
    dfs(i, None)

for i in range(K):
    C, D = map(int, input().split())
    if graph_g[C-1] == graph_g[D-1]:
        block[C-1].append(D-1)
        block[D-1].append(C-1)

ct = Counter(graph_g)

ret = []
for i in range(N):
    cand = ct[graph_g[i]]
    fri = len(to[i])
    tmp_block = len(block[i])

    tmp_ret = cand - fri - tmp_block - 1
    ret.append(tmp_ret)

print(*ret)
N=int(input())
A=list(map(int, input().split()))

def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x
print(z)

### FIXED CODE ###

def main():
  MOD=10**9+7
  N=int(input())
  A=list(map(int,input().split()))
  def lcm(a,N):
      from fractions import gcd
      x = a[0]
      y=  a[N//2]
      for i in range(1, N//2):
          x = (x * a[i]) // gcd(x, a[i])
          y = (y * a[i+N//2]) // gcd(y, a[i+N//2])
      y = (y * a[-1]) // gcd(y, a[-1])
      return (x*y)//gcd(x,y)
  z=lcm(A,N)
  ans=0
  for i in range(N):
    ans+=z//A[i]
  print(ans%MOD)
  
if __name__=='__main__':
  main()
m=input()
m=m.split(" ")
a=m[0]
b=m[1]

print(max(a+a-1,b+b-1,a+b))

### FIXED CODE ###

line = input()
numbers = [int(n) for n in line.split()]
predicted_value = max(numbers[0]+numbers[1], numbers[0]*2-1, numbers[1]*2-1)
print(predicted_value)
a,b,c,d=map(int,input().split())
import math
nc=math.floor(b/c)-math.ceil(a/c)+1
nd=math.floor(b/d)-math.ceil(a/d)+1
min=c*d/math.gcd(c,d)
ncd=math.floor(b/min)-math.ceil(a/min)+1
print(b-a+1-(nc+nd-ncd))

### FIXED CODE ###

a,b,c,d=map(int,input().split())
import fractions
import math
nc=b//c-(a-1)//c
nd=b//d-(a-1)//d
min=c*d//fractions.gcd(c,d)
ncd=b//min-(a-1)//min
print(b-a+1-(nc+nd-ncd))
while True:
 h,w=map(int,input().split())
 if h==0:break
 for _ in range(h):
  print("".join(['*']**w))
 print()

### FIXED CODE ###

while 1:
 h,w=map(int,input().split())
 if h==0:break
 print(('#'*w+'\n')*h)
def main():
    n = int(input())
    a = input().split()
    b = input().split()
    c = input().split()
    score = 0
    for i in range(n):
        score += a[i]
        if a[i+1] - a[i] == 1:
            score += b[i]
    print(score)

if __name__ == "__main__":
    main()

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
 
ans=0
pre=-1
 
for i in a:
  ans += b[i-1]
  if(i==pre+1):
    ans += c[i-2]
  pre=i
  
print(ans)
a = int(input()))
b = int(a /100)
if a > (100b + 10b +b -1):
    print(100(b+1) + 10(b+1) +b +1)
else:
    print(100b + 10b + b)

### FIXED CODE ###

a = int(input())
b = int(a /100)
if a > (100*b + 10*b +b ):
    print(100*(b+1) + 10*(b+1) +b +1)
else:
    print(100*b + 10*b + b)
k = int(input())
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
pritn(a[k])


### FIXED CODE ###

k = int(input())
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[k-1])
# -*- coding: utf-8 -*-
N,M=list(map(int,raw_input().split()))

nl=[[] for i in range(N+1)]
for i in range(M):
	x,y=map(int,raw_input().split())
	nl[x].append(y)
	nl[y].append(x)	
#print nl


def dfs(v,p):
	F[v]=1
	global bip_graph
	for i in nl[v]:

		if color[v]=="w" and color[i]==0:
			color[i]="b"
		elif color[v]=="b" and color[i]==0:
			color[i]="w"				
		elif color[v]==color[i]:
			#二分木ではない
			bip_graph="NO"
		#print v,i,color,F
		
		if bip_graph!="NO" and F[i]==0:
			#DFS(次の頂点i, 次に親となる頂点v, d+ 頂点vと頂点iの間の辺のコスト)
			dfs(i,v)


bip_graph="YES"
F=[0]*(N+1)
color=[0]*(N+1)
color[1]="b"
dfs(1,-1)
#print nl
#print color
#print bip_graph


if bip_graph=="YES":
	print color.count("b")*color.count("w")-M
elif bip_graph=="NO":
	print N*(N-1)/2-M




### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**7)
N,M=list(map(int,raw_input().split()))

nl=[[] for i in range(N+1)]
for i in range(M):
	x,y=map(int,raw_input().split())
	nl[x].append(y)
	nl[y].append(x)	
#print nl


def dfs(v):
	F[v]=1
	for i in nl[v]:
		if color[v]=="w" and color[i]==0:
			color[i]="b"
		elif color[v]=="b" and color[i]==0:
			color[i]="w"				
		elif color[v]==color[i]:
			#２部グラフではない
			print N*(N-1)/2-M
			sys.exit()
		else:
			continue
		#print v,i,color,F
		
		if F[i]==0:
			dfs(i)


F=[0]*(N+1)
color=[0]*(N+1)
color[1]="w"
dfs(1)

#２部グラフの場合
print color.count("b")*color.count("w")-M
import math
a,b,c,d = map(int,input().split())
cd = (c*d) // math.gcd(c,d)
c_sum = (b // c) - ((a-1) // c)
d_sum = (b // d) - ((a-1) // d)
cd_sum = (b // cd) - ((a-1) // cd)
result = b-a+1 -(c_sum+d_sum-cd_sum)
print(result)

### FIXED CODE ###

import fractions
a,b,c,d = map(int,input().split())
cd = (c*d) // fractions.gcd(c,d)
c_sum = (b // c) - ((a-1) // c)
d_sum = (b // d) - ((a-1) // d)
cd_sum = (b // cd) - ((a-1) // cd)
result = b-a+1 -(c_sum+d_sum-cd_sum)
print(result)
s = list(input().split())
print(len(set(s))

### FIXED CODE ###

s = list(input().split())
print(len(set(s)))
def gcd(a, b):
    if(a == 0):
        return b
    if(b == 0):
        return a

    if(a < b):
        a, b = b, a
    r = a % b
    while(r != 0):
        a, b = b, r
        r = a % b
    return b

def L(i, A):
    if(i == 0):
        return 0
    return gcd(L(i - 1, A), A[i - 1])

def R(i, A, N):
    if(i == N):
        return 0
    return gcd(R(i + 1, A, N), A[i])

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

M = []
for i in range(N):
    M.append(gcd(L(i, A), R(i + 1, A, N)))

print(max(M))

### FIXED CODE ###

def gcd(a, b):
    if(a == 0):
        return b
    if(b == 0):
        return a

    if(a < b):
        a, b = b, a
    r = a % b
    while(r != 0):
        a, b = b, r
        r = a % b
    return b

def L(end_i, A):
    if(end_i == 0):
        return 0
    
    a = 0
    for i in range(end_i):
        a = gcd(a, A[i])
    return a


def R(start_i, A, N):
    if(start_i == N - 1):
        return 0

    a = 0
    for i in range(start_i + 1, N):
        a = gcd(a, A[i])
    return a


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

left = [0] * N
right = [0] * N

for i in range(1, N):
    left[i] = gcd(left[i - 1], A[i - 1])
#print(left)

for i in reversed(range(0, N - 1)):
    right[i] = gcd(A[i + 1], right[i + 1])
#print(right)

M = []
for i in range(N):
    M.append(gcd(left[i], right[i]))
#print(M)

print(max(M))
n,m = map(int, input().split())

from collections import defaultdict
V = defaultdict(list)
 
for _ in range(m):
    a, b,c = map(int, input().split())
    V[a].append([b,c])
    V[b].append([a,-c])

inf  = float("inf") 

def dfs(source):
    dist = [inf]*(n+1)
    dist[source] = 0
    q = [source]
    while q:
        a = q.pop()
        for b in V[a]:
            if dist[b[0]]!=inf:
                if dist[b[0]] != dist[a] +b[1]:
                    print("No")
                    exit()
            else:
                dist[b[0]] = dist[a] + b[1]
                q.append(b[0])
    return dist

dfs(min(V))

print("Yes")

### FIXED CODE ###

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

if m <=1:
    print("Yes")
    exit()

from collections import defaultdict
V = defaultdict(list)
 
for _ in range(m):
    a, b,c = map(int, input().split())
    V[a].append([b,c])
    V[b].append([a,-c])

inf  = float("inf") 
dist = [inf]*(n+1)

def dfs(source):
    dist[source] = 0
    q = [source]
    while q:
        a = q.pop()
        for b in V[a]:
            if dist[b[0]]!=inf:
                if dist[b[0]] != dist[a] +b[1]:
                    print("No")
                    exit()
            else:
                dist[b[0]] = dist[a] + b[1]
                q.append(b[0])

for i in range(n):
    if dist[i] ==inf:
        dfs(i)

print("Yes")
N,M,Q=map(int,input().split())
a=[0]*Q
b=[0]*Q
c=[0]*Q
d=[0]*Q
for i in range(Q):
  a[i],b[i],c[i],d[i]=map(int,input().split())
import itertools
for A in itertools.combinations_with_replacement(range(1,M+1),N):
    ans=0
    if i in range(Q):
        s=0
        if A[b[i]]-A[a[i]]==c[i]:
           s+=d[i]
            ans=max(ans,s)
print(ans)        
        

### FIXED CODE ###

N,M,Q=map(int,input().split())
a=[0]*Q
b=[0]*Q
c=[0]*Q
d=[0]*Q
for i in range(Q):
  a[i],b[i],c[i],d[i]=map(int,input().split())
import itertools
ans=0
for A in itertools.combinations_with_replacement(range(1,M+1),N):
    A=list(A)
    s=0
    
    for i in range(Q):
        if A[b[i]-1]-A[a[i]-1]==c[i]:
           s+=d[i]

           ans=max(ans,s)
print(ans)
import sys
input = sys.stdin.readline

N = int(input())
I = input()

R =0
G =0
B =0
for i in range(N):
    if (I[i] == 'R'):
        R+=1
    if (I[i] == 'G'):
        G+=1
    if (I[i] == 'B'):
        B+=1


sum = R * G * B
count = 0

for i in range(N):
    for j in range(i+1,N):
        if I[i] != I[j]:
            k = j + j - i
            if k >= N:
                continue
            if I[i] != I[k] and I[j] != I[k]:
                count += 1

print(sum - count)

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():

    n = str(input())
    for i in range(len(n)):
        if n[i] == '7':
            print('Yes')
            sys.exit()
    print('No')


main()
a=[]
for _ in[0]*int(input()):
 X,z=input(),[]
 for y in input():
  s=i=0
  for k in z:
   t=X.find(y,s)+1
   if t<1:break
   if t<k:z[i]=t
   s=k;i+=1
  else:
   t=X.find(y,s)+1
   if t:z+=[t]
 a+=[len(z)]
print('\n'.join(a))


### FIXED CODE ###

def m():
 e=input
 a=''
 for _ in[0]*int(e()):
  X,z=e(),[]
  for y in e():
   s=i=0
   for k in z:
    t=X.find(y,s)+1
    if t<1:break
    if t<k:z[i]=t
    s=k;i+=1
   else:
    t=X.find(y,s)+1
    if t:z+=[t]
  a+=f'\n{len(z)}'
 print(a[1:])
if'__main__'==__name__:m()
e=enumerate
n,s,q,*k=open(0).read().split()
m,c,x=eval('[0]*-~int(n),'*3)
for i,t in e(s,1):
  m[i]=m[i-1]+(t=='M')
  f=t=='C'
  c[i]=c[i-1]+f
  x[i]=x[i-1]+f*m[i]
for k in map(int,k):
  a=0
  for i,t in e(s):
    j=min(n,i+k)
    if t=='D':a+=x[j]-x[i]-(c[j]-c[i])*m[i]
  print(a)

### FIXED CODE ###

from numpy import*
_,s,_,k=open(0)
s=array(list('='+s[:-1]))
d,m,c=[s==t for t in'DMC']
x,y=map(cumsum,(d,m))
for k in int32(k.split()):
  t=copy(x)
  t[k:]-=x[:-k]
  t*=m
  t[k+1:]-=d[1:-k]*(y[k:-1]-y[:~k])
  print(sum(cumsum(t)*c))
dic = {"SUN":7,"MON":6,"TUE":5,"WED":4,"THU":3,"FRI":2,"SAT":1}
print(dic[str(input())])

### FIXED CODE ###

inp = str(input())

dic = { "SUN":7, "MON":6, "TUE":5, "WED":4, "THU":3, "FRI":2, "SAT":1}
print(dic.get(inp))
a, b = list(map(int, input().split()))
ans = 1
cnt = a;
while True:
  	if ans == 21:
        break
    if cnt >= b:
        break
    cnt += a-1
    ans += 1
print(ans)


### FIXED CODE ###

a, b = list(map(int, input().split()))
ans = 0
cnt = 1;
while cnt < b:
    cnt += a-1
    ans += 1
print(ans)
a,b = map(int, input().split())
if a*b > 1:
  print("Positive")
else:
  if any(a,b) > 0:
    print("Zero")
  else:
    print("Negative")

### FIXED CODE ###

a, b = map(int, input().split())
if a > 0 and b > 0:
  print("Positive")
elif a < 0 and  b < 0:
  if (b - a + 1) % 2 == 0:
    print("Positive")
  else:
    print("Negative")
else:
  print("Zero")
while (True):
    b = list(map(int, input().split(" ")))
    print(b)
    if(b == ['']): break
    c = 1
    d = b[0] + b[1]
    while(d >= 10):
        c += 1
        d = d / 10
    print(c)



### FIXED CODE ###

# 何行あるかわからない入力をまとめて処理する
import sys
line = sys.stdin.readlines()
#print(line)
for i in line:
    # map関数は配列の型を一括変換するのに便利
    b = list(map(int, i.split(" ")))
    c = 1
    d = b[0] + b[1]
    while(d >= 10):
        c += 1
        d = d / 10
    print(c)
S = int(input)
h = S // 3600
m = (S % 3600) // 60
s = (S % 3600) % 60

print('{}:{}:{}'.format(h,m,s))

### FIXED CODE ###

S = int(input())
h = int(S // (60*60))
m = int(S / 60) % 60
s = S%60

print('{}:{}:{}'.format(h,m,s))
s = input()
a = [i for i in s]
s = sorted(a)
b = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    b = 0
    break
print("yes") if b = 1 else print("no")


  

### FIXED CODE ###

s = input()
a = [i for i in s]
s = sorted(a)
b = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    b = 0
print("yes") if b == 1 else print("no")
import bisect

n,m = map(int,input().split())
l = list(map(int,input().split()))
b_c = [list(map(int,input().split())) for i in range(m)]

l.sort()
b_c.sort(key=lambda x:x[1],reverse=True)

idx = 0
ans = 0

for i in range(m):
    if l[idx:][0] >= b_c[i][1]:
        break
    
    temp = bisect.bisect_left(l[idx:],b_c[i][1])
    if temp > b_c[i][0]:
        temp = b_c[i][0]
    ans += temp*b_c[i][1]
    idx += temp

ans += sum(l[idx:])
print(ans)

### FIXED CODE ###

from heapq import heappush, heappop

n,m = map(int,input().split())
heap = []

for i in map(int,input().split()):
    heappush(heap,i)

bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key = lambda x: -x[1])

for b,c in bc:
    for j in range(b):
        a = heappop(heap)
        if a < c:
            heappush(heap,c)
        
        else:
            heappush(heap, a)
            break
        
print(sum(heap))
"""#################################################################
【ABC081】
C - Not so Diverse
#################################################################"""

#インポート
import sys
from collections import Counter

#入力用
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))  #リスト(int型)
def MI(): return map(int, sys.stdin.readline().rstrip().split())        #多変数(int型)
def II(): return int(sys.stdin.readline().rstrip())                     # 1変数(int型)
def S(): return sys.stdin.readline().rstrip()                           #文字列(str型)

N, K = MI()
A = (LI())
A = sorted(Counter(A).values(), reverse = True)
sum = A[k:]
print(sum)

### FIXED CODE ###

"""#################################################################
【ABC081】
C - Not so Diverse
#################################################################"""

#インポート
import sys
from collections import Counter

#入力用
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))  #リスト(int型)
def MI(): return map(int, sys.stdin.readline().rstrip().split())        #多変数(int型)
def II(): return int(sys.stdin.readline().rstrip())                     # 1変数(int型)
def S(): return sys.stdin.readline().rstrip()                           #文字列(str型)

N, K = MI()
A = LI()
A = sorted(Counter(A).values(), reverse = True)
sum = sum(A[K:])
print(sum)
import sys

if __name__ == '__main__':
    data = []
    count = 0
    for line in sys.stdin:
        data.append(line.split())

    n = int(data[0][0])
    s = list(map(int, data[1]))
    q = int(data[2][0])
    t = list(map(int, data[3]))

    for i in range(0, q - 1):
        head = 0
        tail = n

        while True:
            center = len(s) // 2

            if s[center] == t[i] :
                count = count + 1
                print(t[i])
                break
            elif s[center] < t[i]:
                head = center + 1
            else :
                tail = center - 1

            s = s[head : tail + 1]

            if head >= tail :
                break


### FIXED CODE ###

import sys

if __name__ == '__main__':
    data = []
    count = 0
    for line in sys.stdin:
        data.append(line.split())
    s = list(map(int, data[1]))
    n = int(data[0][0])
    q = int(data[2][0])
    t = list(map(int, data[3]))
    for i in range(0, q):
        head = 0
        tail = n - 1
        while True:
            if head > tail :
                break
            center = (head + tail)//2
            if s[center] == t[i] :
                count = count + 1
                break
            elif s[center] < t[i]:
                head = center + 1
            else :
                tail = center - 1
    print(count)
def factorial(N):
    if N == 1:
        return N
    return N * factorial(N-1)

N = int(input())
S = input()

mod = 10 ** 9 + 7

if S[0] == "W" or S[-1] == "W":
    print(0)
    exit()

T = [True] * 2 * N
prev = S[0]
for i in range(1, 2*N-1):
    if S[i] == prev:
        T[i] = not T[i-1]
    else:
        T[i] = T[i-1]
    prev = S[i]
T[-1] = False

ans = 1
t_sum = 0
f_sum = 0
for t in T:
    if t:
        t_sum += 1
    else:
        ans *= (t_sum - f_sum)
        f_sum += 1

if t_sum != f_sum:
    ans = 0

ans %= mod
ans *= factorial(N)
print(ans % mod)

### FIXED CODE ###

N = int(input())
S = input()

mod = 10 ** 9 + 7

if S[0] == "W" or S[-1] == "W":
    print(0)
    exit()

ans = 1
prev_s = S[0]
prev_t = True
t_sum = 1
f_sum = 0
for i in range(1, 2*N-1):
    if S[i] == prev_s:
        t = not prev_t
    else:
        t = prev_t

    if t:
        t_sum += 1
    else:
        ans *= (t_sum - f_sum)
        ans %= mod
        f_sum += 1
    prev_s = S[i]
    prev_t = t

if t_sum != N:
    ans = 0

for i in range(1, N+1):
    ans *= i
    ans %= mod

print(ans)
sn = int(input())
arr = [int(input()) for _ in range(n)]
arr.sort()
mx = arr[-1]
sc = arr[-2]

for ele in arr:
    if ele == mx:
        print(sc)
    else:
        print(mx)


### FIXED CODE ###

n = int(input())
arr = [int(input()) for _ in range(n)]
ar = sorted(arr)
mx = ar[-1]
sc = ar[-2]

for ele in arr:
    if ele == mx:
        print(sc)
    else:
        print(mx)
length = raw_input()
count = length
answer = raw_input()


def compare(current, i):
  if current[i] < previous[i]:
    answer = current
  elif current[i] == previous[i]:
    compare(current, i+1)

while count > 0:
  if count == length:
    current_word = answer
  if count < length:
    current_word = raw_input()
    compare(current_word, 0)
  count -= 1

print answer
  

### FIXED CODE ###

s = []
n = input()
 
for i in range(n):
    x = raw_input()
    s.append(x)
 
s.sort()
 
print s[0]
a,b=map(int,input().split())
print((a-2)*(b-2))

### FIXED CODE ###

print(input()[0]+input()[1]+input()[2])
A = [[int(j) for j in input().split()] for i in range(3)]
N = int(input())
B = [False] * 100

for i in range(N):
    B[int(input())] = True

ans = 'No'
for i in range(3):
    if all([B[v] for v in A[i]]):
        ans = 'Yes'
        break

for j in range(3):
    if all([B[A[i][j]] for i in range(3)]):
        ans = 'Yes'
        break

if B[A[0][0]] == B[A[1][1]] == B[A[2][2]] == True:
    ans = 'Yes'

if B[A[2][0]] == B[A[1][1]] == B[A[0][2]] == True:
    ans = 'Yes'

print(ans)



### FIXED CODE ###

A = [[int(j) for j in input().split()] for i in range(3)]
N = int(input())
B = [False] * 101

for i in range(N):
    B[int(input())] = True

ans = 'No'
for i in range(3):
    if all([B[v] for v in A[i]]):
        ans = 'Yes'
        break

for j in range(3):
    if all([B[A[i][j]] for i in range(3)]):
        ans = 'Yes'
        break

if B[A[0][0]] == B[A[1][1]] == B[A[2][2]] == True:
    ans = 'Yes'

if B[A[2][0]] == B[A[1][1]] == B[A[0][2]] == True:
    ans = 'Yes'

print(ans)
import sys;print(int(sys.argv[1][-6:-5])/2)

### FIXED CODE ###

_=int(input());c=0
for i in 'i¥½ÃÉ':
  if (_ < ord(i)):
    print(c)
    break
  c+=1