Harryxun/stf_run huggingface dataset:
#  --*-coding:utf-8-*--


MOD = 998244353

def main():
    N = int(input())
    S = input()

    r,g,b = 0, 0, 0
    rg, rb, gb = 0, 0, 0
    empty=N

    x = 1
    for c in S:
        if c == 'R':
            if gb > 0:
                x = x*gb%MOD
                gb -= 1
            elif g > 0:
                x = x*g%MOD
                g -= 1
                rg += 1
            elif b > 0:
                x = x*b%MOD
                b -= 1
                rb += 1
            else:
                x = x*empty%MOD
                empty -= 1
                r += 1
        elif c == 'G':
            if rb > 0:
                x = x*rb%MOD
                rb -= 1
            elif r > 0:
                x = x*r%MOD
                r -= 1
                rg += 1
            elif b > 0:
                x = x*b%MOD
                b -= 1
                ggb += 1
            else:
                x = x*empty%MOD
                empty -= 1
                g+= 1
        else:
            if rg > 0:
                x = x*rg%MOD
                rg -= 1
            elif r > 0:
                x = x*r%MOD
                r -= 1
                rb += 1
            elif g > 0:
                x = x*g%MOD
                b -= 1
                gb += 1
            else:
                x = x*empty%MOD
                empty -= 1
                b += 1

    print(x)
                

if __name__ == '__main__':
    main()


### FIXED CODE ###

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


MOD = 998244353

def main():
    N = int(input())
    S = input()

    r,g,b = 0, 0, 0
    rg, rb, gb = 0, 0, 0
    empty=N

    x = 1
    for c in S:
        if c == 'R':
            if gb > 0:
                x = x*gb%MOD
                gb -= 1
            elif g > 0:
                x = x*g%MOD
                g -= 1
                rg += 1
            elif b > 0:
                x = x*b%MOD
                b -= 1
                rb += 1
            else:
                x = x*empty%MOD
                empty -= 1
                r += 1
        elif c == 'G':
            if rb > 0:
                x = x*rb%MOD
                rb -= 1
            elif r > 0:
                x = x*r%MOD
                r -= 1
                rg += 1
            elif b > 0:
                x = x*b%MOD
                b -= 1
                gb += 1
            else:
                x = x*empty%MOD
                empty -= 1
                g+= 1
        else:
            if rg > 0:
                x = x*rg%MOD
                rg -= 1
            elif r > 0:
                x = x*r%MOD
                r -= 1
                rb += 1
            elif g > 0:
                x = x*g%MOD
                g -= 1
                gb += 1
            else:
                x = x*empty%MOD
                empty -= 1
                b += 1

    print(x)
                

if __name__ == '__main__':
    main()
#ABC047.B
w,h,n = map(int,input().split())

#座標を作る
right = w
left = 0
upper = h
under = 0

for _ in range(n):
    x,y,a = map(int,input().split())

    if a ==1:
        left = max(x,left)
    elif a ==2:
        right = min (x,right)
    elif a ==3:
        under = max(y,under)
    elif a ==4:
        upper = min(y,upper)

if　(upper-under)>0 and (right-left)>0:
    c = (upper-under)*(right-left)
    print(c)
else:
    print(0)

### FIXED CODE ###

#ABC047.B

w,h,n = map(int,input().split())
#座標を作る
right = w
left = 0
upper = h
under = 0

for _ in range(n):
    x,y,a = map(int,input().split())

    if a ==1:
        left = max(x,left)
    elif a ==2:
        right = min(x,right)
    elif a ==3:
        under = max(y,under)
    else:
        upper = min(y,upper)

if(upper-under)>0 and (right-left)>0:
    c = (upper-under)*(right-left)
    print(c)
else:
    print(0)
A = []
B = []
C = []

for i in range(1,100):
    t0 = i
    t1 = i*100
    t2 = i*100*100
    A.append(t0)
    B.append(t1)
    C.append(t2)

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

if d == 0:
    print(A[n-1])
elif d == 1:
    print(B[n-1])
else:
    print(C[n-1])

### FIXED CODE ###

A = []
B = []
C = []

for i in range(1,101):
    t0 = i
    t1 = i*100
    t2 = i*100*100
    A.append(t0)
    B.append(t1)
    C.append(t2)

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

if d == 0:
    if n == 100:
        print(101)
    else:
        print(A[n-1])
elif d == 1:
    if n == 100:
        print(100*101)
    else:
        print(B[n-1])
else:
    if n == 100:
        print(100*100*101)
    else:
        print(C[n-1])
n = int(input())
l = list(map(int,input().split())
a = 10**9
ans = 0
if l[i] <= a:
    ans += 1
    a = l[i]
print(ans)

### FIXED CODE ###

n = int(input())
p = list(map(int,input().split()))
a = 10**9
ans = 0
for i in range(n):
    if p[i]<=a:
        ans+= 1
        a = p[i]
print(ans)
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
	print(N**3)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    print(N**3)

if __name__ == '__main__':
    main()
n, q = map(int, input().split())
s = input()
l = []
r = []
t = [0]*len(s)

for i in range(q):
    temp1, temp2 = map(int, input().split())
    l.append(temp1)
    r.append(temp2)

for i in range(1, len(s)):
    if s[i-1] + s[i] ==	'AC':
	t[i] = t[i-1] + 1
    else:
        t[i] = t[i-1]

#print(t)

for i in range(q):
    left = l[i]	- 1
    right = r[i] - 1
    # print(left)
    # print(right)
    print(t[right] - t[left])


### FIXED CODE ###

n, q = map(int, input().split())
s = input()
l = []
r = []
t = [0]*len(s)

for i in range(q):
    temp1, temp2 = map(int, input().split())
    l.append(temp1)
    r.append(temp2)

for i in range(1, len(s)):
    if s[i-1] + s[i] == 'AC':
        t[i] = t[i-1] + 1
    else:
        t[i] = t[i-1]

#print(t)

for i in range(q):
    left = l[i] - 1
    right = r[i] - 1
    # print(left)
    # print(right)
    print(t[right] - t[left])
import math

n = list(map(int,input().split()))
x = min(b-1 , n[2])
if n[2] >= n[2]:
    print(math.floor(n[0] * x // n[1]))

### FIXED CODE ###

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

sa = m[1] - m[0]
flag = 0
hantei = m[0]

if sa == 0:
    if m[0] % n == 0:
        print("OK")
        exit()
    else:
        print("NG")
        exit()

if hantei % n == 0:
    flag += 1

for x in range(sa):
    hantei = (x + 1) + m[0]
    if hantei % n == 0:
        flag += 1

if flag >= 1:
    print("OK")
else:
    print("NG")
class Fibonacci(object):
    memo = [1, 1]

    def get_nth(self, n):
        if n <= len(Fibonacci.memo):
            return Fibonacci.memo[n]
        # print('fib({0}) not found'.format(n))
        for i in range(len(Fibonacci.memo), n+1):
            result = Fibonacci.memo[i-1] + Fibonacci.memo[i-2]
            Fibonacci.memo.append(result)
            # print('fib({0})={1} append'.format(i, result))
        return Fibonacci.memo[n]


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())

    # ?????£??????????????°????¨????
    f = Fibonacci()
    result = f.get_nth(num)

    # ???????????????
    print('{0}'.format(result))

### FIXED CODE ###

from functools import lru_cache


@lru_cache(maxsize=None)
def fib(n):
    """ http://docs.python.jp/3/library/functools.html """
    if n < 2:
        return n
    return fib(n-1) + fib(n-2)


class Fibonacci(object):
    memo = [1, 1]

    def get_nth(self, n):
        if n < len(Fibonacci.memo):
            return Fibonacci.memo[n]
        # print('fib({0}) not found'.format(n))
        for i in range(len(Fibonacci.memo), n+1):
            result = Fibonacci.memo[i-1] + Fibonacci.memo[i-2]
            Fibonacci.memo.append(result)
            # print('fib({0})={1} append'.format(i, result))
        return Fibonacci.memo[n]


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())

    # ?????£??????????????°????¨????
    # f = Fibonacci()
    # result = f.get_nth(num)
    result = fib(num+1)

    # ???????????????
    print('{0}'.format(result))
import sys

def jump(k: int, h, res):
    if ( k == 0 ):
        return 0

    if ( res[k] == -1 ):
        res[k] = jump(k - 1, h, res) + abs(h[k] - h[k - 1])
        if k >= 2:
            res[k] = min(res[k], jump(k - 2, h, res) + abs(h[k] - h[k - 2]))

    return res[k]

def main():
    #lines = []
    #for line in sys.stdin:
    #    lines.append([int(i) for i in line.strip().split(' ')])

    #n = int(lines[0][0])
    #h = lines[1]
    n = int(input())
    h = list(map(int, input().split(" ")))

    res = [ -1 for i in range(n)]
    print(jump(n-1, h, res))


if __name__ == '__main__':
    main()

### FIXED CODE ###

def calc_cost(h):
    if (len(h) == 0):
        return 0

    cost = [None] * len(h)
    cost[0] = 0
    for i in range(1, len(h)):
        cost[i] = cost[i-1] + abs(h[i] - h[i-1])
        if i>1:
            cost[i] = min(cost[i], cost[i-2] + abs(h[i] - h[i-2]))

    return cost[len(h)-1]

if __name__ == "__main__":
    n = int(input())
    h = list(map(int, input().split(" ")))
    res = calc_cost(h)
    print(res)
s = input()
num = len(s)
i = 0
ans = []
while i <= num/2:
    ans[i] = s[2 * i]
ANS = sum(ans)
print(ANS)

### FIXED CODE ###

s = list(input())
AnsList = s[::2]
print(''.join(AnsList))
s=list(input())
s.sort()
d=int(s[0])*100+int(s[1])*10+int(s[2])
d=d-557
if d==0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

s=list(input().split())
s.sort()
d=int(s[0])*100+int(s[1])*10+int(s[2])
d=d-557
if d==0:
    print("YES")
else:
    print("NO")
n,a,b,c,d = map(int,input().split())
s = input().rstrip()
renzoku_iwa = [0 for i in range(n)]
renzoku_blank = [0 for i in range(n)]
old1 = ""
old2 = ""
for i,tmp in enumerate(s):
	if old1 == tmp:
		if old1 == "." and old2 == ".":
			renzoku_blank[i] = 1
		elif old1 == "#":
			renzoku_iwa[i] = 1
	old2 = old1
	old1 = tmp

if sum(renzoku_iwa[a-1:c]) == 0 and sum(renzoku_iwa[b-1:d]) == 0:
	if c < d:
		print("Yes")
	else:
		if sum(renzoku_blank[b:d])>=1:
			1/0
			print("Yes")
		else:
			print("No")
else:
	print("No")

### FIXED CODE ###

n,a,b,c,d = map(int,input().split())
s = input().rstrip()
renzoku_iwa = [0 for i in range(n)]
renzoku_blank = [0 for i in range(n)]
old1 = ""
old2 = ""
for i,tmp in enumerate(s):
	if old1 == tmp:
		if old1 == "." and old2 == ".":
			renzoku_blank[i] = 1
		elif old1 == "#":
			renzoku_iwa[i] = 1
	old2 = old1
	old1 = tmp

if sum(renzoku_iwa[a-1:c]) == 0 and sum(renzoku_iwa[b-1:d]) == 0:
	if c < d:
		print("Yes")
	else:
		if sum(renzoku_blank[b:min(d+1,len(renzoku_blank))])>=1:
			print("Yes")
		else:
			print("No")
else:
	print("No")
while True:
	a, b = sorted(map.(int,input().split()))
	if (a == 0) & (b == 0): break
	print(a,b)


### FIXED CODE ###

while True:
    a, b = sorted(map(int, input().split()))
    if (a == 0) & (b == 0): break
    print(a, b)
N, K = map(int, input().split())
A = list( map(int, input().split()) ) #ここでN個受け取る

var = [0] * 21000


for i in range(N):
    var[A[i]] += 1
    
var.sort( reverse = True )


count = 0
for j in range( K, N ):
    if var[j] == 0:
        break
    
    if var[j] != 0:
        count += var[j]
        
print(count)

### FIXED CODE ###

N, K = map(int, input().split())
A = list( map(int, input().split()) ) #ここでN個受け取る

var = [0] * (N+1)


for i in A:
    var[i] += 1
    
var = sorted(var,  reverse = True )


count = 0
for j in range( K, N+1 ):
    if var[j] == 0:
        break
    
    if var[j] != 0:
        count += var[j]
        
print(count)
N=int(input())

print(sum(list(range(N+1)))-N)


### FIXED CODE ###

N=int(input())

s=N*(N+1)//2

print(s-N)
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
import sys
S=[-1 for i in range(N)]
visited=[[] for i in range(N)]

for i in A:
    S[i[0]-1]=i[1]
    visited[i[0]-1].append(i[1])
for i in visited:
    if len(set(i))>1:
        print(-1)
        sys.exit()
if len(S)>1
    if S[0]==0:
        print(-1)
        sys.exit()
    if S[0]==-1:
        S[0]=1

for i,value in enumerate(S):
    if value==-1:
        S[i]=0

print(*S,sep='')

### FIXED CODE ###

N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
import sys
S=[-1 for i in range(N)]
visited=[[] for i in range(N)]

for i in A:
    S[i[0]-1]=i[1]
    visited[i[0]-1].append(i[1])
for i in visited:
    if len(set(i))>1:
        print(-1)
        sys.exit()
if len(S)>1:
    if S[0]==0:
        print(-1)
        sys.exit()
    if S[0]==-1:
        S[0]=1

for i,value in enumerate(S):
    if value==-1:
        S[i]=0

print(*S,sep='')
import functools
import math
N = int(input())
A = list(map(int, input().split()))
gcd_max = 1
for i in range(N):
    gcd = functools.reduce(math.gcd, A[i+1:] + A[:i])
    if gcd > gcd_max:
        gcd_max = gcd
        i_max = i

print(gcd_max)



### FIXED CODE ###

from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
L = [0]
R = [0]
for i in range(N-1):
    L.append(gcd(L[i], A[i]))
    R.append(gcd(R[i], A[-i-1]))
MAX = 0
for i in range(N):
    MAX = max(MAX, gcd(L[i], R[-i-1]))
print(MAX)
def solve(string):
    ins = string.split("\n")
    h, w = map(int, ins[0].split(" "))
    a = [list(map(int, _i.split(" "))) for _i in ins[1:]]
    move = []
    for j in range(h):
        for i in range(w):
            if a[j][i] % 2 == 0:
                continue
            """
            if i < w - 1:
                a[j][i + 1] += 1
                move.append("{} {} {} {}".format(j + 1, i + 1, j + 1, i + 2))
            elif j < h - 1:
                a[j][i] -= 1
                a[j + 1][i] += 1
                move.append("{} {} {} {}".format(j + 1, i + 1, j + 2, i + 1))
            """
    return "{}\n{}".format(len(move), "\n".join(move))


if __name__ == '__main__':
    line = input()
    tmp = [line]
    for _ in range(int(line[0])):
        tmp.append(input())
    print(solve('\n'.join(tmp)))


### FIXED CODE ###

h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []
 
for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3]))
N = int(input())
S = [0] * 5
for _ in range(N):
  s = input()
  if s[0] == "M": S[0] += 1
  elif s[0] == "A": S[1] += 1
  elif s[0] == "R": S[2] += 1
  elif s[0] == "C": S[3] += 1
  elif s[0] == "H": S[4] += 1

ans = 0
for x in range(3):
  for y in range(x+1, N-1):
    for z in range(y+1, N):
      ans += S[x] * S[y] * S[z]
print(ans)

### FIXED CODE ###

N = int(input())
m = a = r = c = h = 0
for _ in range(N):
  s_in = input()
  if s_in[0] == "M": m += 1
  elif s_in[0] == "A": a += 1
  elif s_in[0] == "R": r+= 1
  elif s_in[0] == "C": c += 1
  elif s_in[0] == "H": h += 1

all_l = [m, a, r, c, h]
ans = 0
import itertools
for v in itertools.combinations(all_l, 3):
  if v[0] * v[1] * v[2] > 0:
    ans += v[0] * v[1] * v[2]
print(ans)
def root(s):
  t=l[s]
  if t<0:
    return s
  return root(t)
n,m=map(int,input().split())
ans=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[ans]*m
for i in range(m-2,-1,-1):
  x,y=map(int,b[i+1])
  x=root(x-1)
  y=root(y-1)
  if x!=y:
    l[x]=y
    ans-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=ans
for x in c:
  print(x)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)
import sys
from fractions import Fraction
from collections import Counter
def solve(N, m):
    AB_fr = []
    for a, b in zip(m, m):
        if (a, b) != (0, 0):
            AB_fr.append(Fraction(a, b))
    ans = 1
    mod = 10**9+7
    Cnt = Counter(AB_fr)
    for ab_fr, cnt in Cnt.items():
        cnt2 = Cnt[-1/ab_fr]
        if ab_fr < 0 and cnt2 > 0:
            continue
        p = pow(2, cnt, mod)
        p2 = pow(2, cnt2, mod)
        ans = ans * (p + p2 - 1) % mod
    return ans - 1

N = int(sys.stdin.buffer.readline())
m = map(int, sys.stdin.buffer.read().split())
ans = solve(N, m)
print(ans)


### FIXED CODE ###

def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)

import sys
import numpy as np
from math import gcd
mod = 10**9+7
def pow_mod(base, exp):  # [pow_mod, "i8(i8,i8)"],
    # mod はグローバル変数を参照
    exp %= mod - 1
    res = 1
    while exp:
        if exp % 2:
            res = res * base % mod
        base = base * base % mod
        exp //= 2
    return res

def solve(N, AB):
    n = 0
    na = nb = nab = 0
    Cnt = {}
    for a, b in zip(AB[::2], AB[1::2]):
        if (a, b) == (0, 0):
            nab += 1
        elif a == 0:
            na += 1
        elif b == 0:
            nb += 1
        else:
            if b < 0:
                a, b = -a, -b
            g = gcd(a, b)
            a //= g
            b //= g
            ab_fr = (a, b)
            n += 1
            if ab_fr in Cnt:
                Cnt[ab_fr] += 1
            else:
                Cnt[ab_fr] = 1
            inv = (-b, a) if a > 0 else (b, -a)
            if inv not in Cnt:
                Cnt[inv] = 0
    ans = (pow_mod(2, na) + pow_mod(2, nb) - 1) % mod
    A = []
    for ab_fr, cnt in Cnt.items():
        a, b = ab_fr
        inv = (-b, a) if a > 0 else (b, -a)
        cnt2 = Cnt[inv]
        p = pow_mod(2, cnt)
        p2 = pow_mod(2, cnt2)
        A.append((p + p2 - 1) % mod)
    A.sort()
    for a in A[::2]:
        ans = ans * a % mod
    ans += nab - 1
    return ans % mod

numba_compile([
    [pow_mod, "i8(i8,i8)"],
    [solve, "i8(i8,i8[:])"],
])

def main():
    N = int(sys.stdin.buffer.readline())
    m = np.array(sys.stdin.buffer.read().split(), dtype=np.int64)
    ans = solve(N, m)
    print(ans)

main()
N,M = map(int,input().split())
s = []
c = []
ans = -1
ans_flg = True
for i in range(M):
  si, ci = map(int,input().split())
  s.append(si)
  c.append(ci)
for i in range(1000):
    #print("i : ",i)
    ans_str = str(i)
    if i < 10**(N-1)-1 or i > 10**(N+1):
        continue
    for j in range(len(s)):
        #print("ans_str : ",ans_str,", ans_str[s[j]-1] : ",ans_str[s[j]-1],", s[j] : ",s[j],", c[j] : ",c[j])
        if ans_str[s[j]-1] != str(c[j]):
            #print("hoge",ans_flg)
            ans_flg = False
            break
        else:
            #print("fuga")
            ans_flg = True
    #print(i)
    if ans_flg:
        ans = i
        break
print(ans)


### FIXED CODE ###

N,M = map(int,input().split())
s = []
c = []
ans = -1
ans_flg = True
for i in range(M):
  si, ci = map(int,input().split())
  s.append(si)
  c.append(ci)
for i in range(1000):
    #print("i : ",i)
    ans_str = str(i)
    if len(str(i)) != N:
        continue
    for j in range(len(s)):
        #print("ans_str : ",ans_str,", ans_str[s[j]-1] : ",ans_str[s[j]-1],", s[j] : ",s[j],", c[j] : ",c[j])
        if ans_str[s[j]-1] != str(c[j]):
            #print("hoge",ans_flg)
            ans_flg = False
            break
        else:
            #print("fuga")
            ans_flg = True
    #print(i)
    if ans_flg:
        ans = i
        break
print(ans)
import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def lr(xx):
    ll=[-1]*(n+1)
    rr=[-1]*(n+1)
    for i,x in enumerate(xx):
        if ll[x]==-1:ll[x]=i
        if i==n-1 or x!=xx[i+1]:rr[x]=i+1
    return ll,rr

n=II()
aa=LI()
bb=LI()
all,arr=lr(aa)
bll,brr=lr(bb)
# print(all,arr)
ca=[0]*(n+1)
cb=[0]*(n+1)
for a in aa:ca[a]+=1
for b in bb:cb[b]+=1
for i in range(n+1):
    if ca[i]+cb[i]>n:
        print("No")
        exit()
ng=[0]*n
for al,ar,bl,br in zip(all,arr,bll,brr):
    if al==-1 or bl==-1:continue
    if bl<ar:
        mn=max(0,al-br+1)
        mx=ar-bl
        ng[mn]+=1
        ng[mx]-=1
    else:
        mn=max(0,al+n-br+1)
        mx=ar+n-bl
        ng[mn]+=1
        ng[mx]-=1
# print(ng)
for i in range(n-1):ng[i+1]+=ng[i]
shift=-1
for i in range(n):
    if not ng[i]:
        shift=i
        break
ans=bb[shift:]+bb[:shift]
print("Yes")
print(*ans)


### FIXED CODE ###

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def lr(xx):
    ll=[-1]*(n+1)
    rr=[-1]*(n+1)
    for i,x in enumerate(xx):
        if ll[x]==-1:ll[x]=i
        if i==n-1 or x!=xx[i+1]:rr[x]=i+1
    return ll,rr

n=II()
aa=LI()
bb=LI()
all,arr=lr(aa)
bll,brr=lr(bb)
# print(all,arr)
ca=[0]*(n+1)
cb=[0]*(n+1)
for a in aa:ca[a]+=1
for b in bb:cb[b]+=1
for i in range(n+1):
    if ca[i]+cb[i]>n:
        print("No")
        exit()
ng=[0]*(n+1)
for al,ar,bl,br in zip(all,arr,bll,brr):
    if al==-1 or bl==-1:continue
    if bl<ar:
        mn=max(0,al-br+1)
        mx=ar-bl
        ng[mn]+=1
        ng[mx]-=1
    else:
        mn=max(0,al+n-br+1)
        mx=min(n,ar+n-bl)
        ng[mn]+=1
        ng[mx]-=1
# print(ng)
for i in range(n):ng[i+1]+=ng[i]
shift=-1
for i in range(n):
    if ng[i]==0:
        shift=i
        break
ans=bb[-shift:]+bb[:-shift]
print("Yes")
print(*ans)
a,b = map(int,input().split())
print(a-b*2 if a-b*2>=0 0 else)

### FIXED CODE ###

a,b = map(int,input().split())
print(a-b*2 if a-b*2>=0 else 0)
import functools
from math import gcd
n,x =map(int,input().split())
if n==1:
    print(abs(int(input())-x))
else:
    lis = list(map(int,input().split()))
    for i in range(n):
        lis[i] = abs(lis[i]-x)
    print(functools.reduce(gcd,lis))


### FIXED CODE ###

from functools import reduce
from fractions import gcd
N,X=map(int,input().split())
x=[abs(X-int(i)) for i in input().split()]
print(reduce(gcd,x))
s,w=map(int.input().split())
print("unsafe" if w>=s else "safe")


### FIXED CODE ###

s,w=map(int,input().split())
print("unsafe" if w>=s else "safe")