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

N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]
c = [list(map(int, input().split())) for _ in range(N)]

from itertools import permutations

colors = tuple(i+1 for i in range(C))
lst = tuple(permutations(colors, 3))

ans = 10**9
for i, j, k in lst:
    cost = 0
    for col in range(0, N, 3):
        for row in range(0, N, 3):
            cost+=D[c[col][row]-1][i-1]
        for row in range(1, N, 3):
            cost+=D[c[col][row]-1][j-1]
        for row in range(2, N, 3):
            cost+=D[c[col][row]-1][k-1]
            
    for col in range(1, N, 3):
        for row in range(0, N, 3):
            cost+=D[c[col][row]-1][j-1]
        for row in range(1, N, 3):
            cost+=D[c[col][row]-1][k-1]
        for row in range(2, N, 3):
            cost+=D[c[col][row]-1][i-1]
            
    for col in range(2, N, 3):
        for row in range(0, N, 3):
            cost+=D[c[col][row]-1][k-1]
        for row in range(1, N, 3):
            cost+=D[c[col][row]-1][i-1]
        for row in range(2, N, 3):
            cost+=D[c[col][row]-1][j-1]
            
    ans = min(cost, ans)
    
print(ans)

### FIXED CODE ###

N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]
c = [list(map(int, input().split())) for _ in range(N)]

from itertools import permutations

colors = tuple(i for i in range(C))

table = [[0 for i in range(C)] for j in range(3)]
for color in colors:
    for col in range(N):
        for row in range(N):
            table[(col+row)%3][color]+=D[c[col][row]-1][color]
            
ans = 10**9    
for i, j, k in permutations(colors, 3):
    ans = min(ans, table[0][i]+table[1][j]+table[2][k])

print(ans)
### BUGGY CODE ###

N = int(input())
S = input()
dp = [[0]*(N+1) for _ in range(N+1)]
for i in reversed(range(N)):
    for j in reversed(range(N)):
        if S[i] == S[j]:
            dp[i][j] = dp[i+1][j+1] + 1

print(max(max(min(dp[a][b], a-b) for a in range(N)) for b in range(N)))

### FIXED CODE ###

N = int(input())
S = input()
ans = 0
for i in range(N):
    if N-i<ans:
        break
    if S[i+1:].find(S[i-ans:i+1])>=0:
        ans += 1
print(ans)
### BUGGY CODE ###

N,K=map(int,input().split())
t=list(map(int,input().split()))
g=[1]
for i in range(N):
  if t[g[i]-1] in set(g):
    h=g.index(t[g[i]-1])
    s=i+1-h
    break
  g.append(t[g[i]-1])
if K>h:
  K=(K-h)%s+h
print(g[K])

### FIXED CODE ###

N, K = map(int, input().split())
T_list = list(map(int, input().split()))
T_list = [T_list[i]-1 for i in range(N)]
point = 0
syuuki = 0

if K < N:
  i = 0
  while i < K:
    point = T_list[point]
    i += 1  

else:
  i = 0
  while i < N:
    point = T_list[point]
    if point == 0:
      syuuki = i+1
      break
    i += 1
  second_point = point
  
  if syuuki != 0:
    L = K % syuuki

  else:
    j = 0
    while j < N:
      point = T_list[point]
      if point == second_point:
        syuuki = j+1
        break
      j += 1
    L = (K-i) % syuuki

  k = 0
  while k < L:
    point = T_list[point]
    k += 1
  
print(point+1)
### BUGGY CODE ###

from itertools import permutations
import numpy as np
def read(): return list(map(int, input().split()))

INF = 114514810

def wf(d):
    N = len(d[0])
    d = np.array(d)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


def calc_dist(p, d):
    dist = 0
    for i in range(len(p) - 1):
        dist += d[p[i]][p[i + 1]]
    return dist


def main():
    N, M, R = read()
    r = map(lambda x: x - 1, sorted(read()))
    d = [[INF for i in range(N)] for j in range(N)]

    for i in range(M):
        a, b, c, = read()
        a -= 1
        b -= 1
        d[a][b] = d[b][a] = c

    d = wf(d)

    min_dist = INF
    for p in list(permutations(r)):
        min_dist = min(min_dist, calc_dist(p, d))

    print(min_dist)


if __name__ == '__main__':
    main()

### FIXED CODE ###

from itertools import permutations
def read(): return list(map(int, input().split()))


INF = 114514810


def wf(d):
    N = len(d[0])
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]
    return d


def calc_dist(p, d):
    dist = 0
    for i in range(len(p) - 1):
        if d[p[i]][p[i + 1]] >= INF:
            return INF
        dist += d[p[i]][p[i + 1]]
    return dist


def main():
    N, M, R = read()
    r = map(lambda x: x - 1, sorted(read()))
    d = [[INF for i in range(N)] for j in range(N)]

    for i in range(M):
        a, b, c, = read()
        a -= 1
        b -= 1
        d[a][b] = d[b][a] = c

    d = wf(d)

    min_dist = INF
    for p in list(permutations(r)):
        min_dist = min(min_dist, calc_dist(p, d))

    print(min_dist)


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

a,b,n=map(int, input().split())

list =[]
for x in range(n+1) :
    k = int(a*x/b) - a* int(x/b)
    list.append(k)
print(max(list))

### FIXED CODE ###

a,b,n = map(int, input().split())
x = min(b-1,n)
print(int(a*x/b))
### BUGGY CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
#二分探索をつくる
L = -1
R = 10**12 +1 
while R-L>1:
    Mid = (L+R)//2
    tmp = 0
    for a,f in zip(A,F):
        tmp += max(0, a-Mid//f)
    if tmp<=K:
        R = Mid
    else:
        L = Mid
print(R)

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
#二分探索をつくる
L = -1
R = 10**12 +1 
while R-L>1:
    Mid = (L+R)//2
    tmp = 0
    for a,f in zip(A,F):
        tmp += max(0, a-Mid//f)
    if tmp<=K:
        R = Mid
    else:
        L = Mid
print(R)
### BUGGY CODE ###

import collections

N, M = map(int, input().split())
lst = [0] * N
x = 1
for _ in range(M):
  A, B = map(int, input().split())
  if lst[A-1] == 0 and lst[B-1] == 0:
    lst[A-1] = x
    lst[B-1] = x
    x += 1
  elif lst[A-1] == 0 and lst[B-1] != 0:
    lst[A-1] = lst[B-1]
  elif lst[A-1] != 0 and lst[B-1] == 0:
    lst[B-1] = lst[A-1]
  else:
    y = max(lst[A-1], lst[B-1])
    z = min(lst[A-1], lst[B-1])
    for i in range(N):
      if lst[i] == z:
        lst[i] = y
  
c = collections.Counter(lst)

num_0 = c[0]
if num_0 == 0:  
  print(len(c) - 1)
else:
  print(num_0 + len(c) - 2)
  

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def size(self, x):
        return -self.parents[self.find(x)]
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
 
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
 
    def group_count(self):
        return len(self.roots())
 
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
 
 
 
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
 
n,m=map(int,input().split())
u=UnionFind(n)
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    u.unite(a,b)

print(u.group_count()-1)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
N,M = map(int,input().split())
G = [[] for _ in range(N+1)]

for _ in range(M):
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    G[x].append(y)
    G[y].append(x)

seen = [False]*(N)
ans = 0
def dfs(v):
    if seen[v]:
        return
    seen[v] = True
    for nv in G[v]:
        dfs(nv)

for v in range(N):
    if not seen[v]:
        dfs(v)
        ans += 1
print(ans)

### FIXED CODE ###

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

par = [-1]*(N+1)


def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True


def same(x,y):
    return find(x) == find(y)


def size(x):
    return -par[find(x)]

for i in range(M):
    x,y,z = map(int,input().split())
    unite(x,y)

ans = 0
counted = [False] * (N+1)
for i in range(1,N+1):
    root = find(i)
    if not counted[root]:
        ans += 1
        counted[root] = True
print(ans)
### BUGGY CODE ###

from itertools import combinations as c
N = int(input())
S = input()

count = 0
for i, j, k in c(range(N), 3):
  if j - i != k - j and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
    count += 1

print(count)

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2 * j - i
    if k < N:
      A, B, C = S[i], S[j], S[k]
      if A != B and B != C and C != A: ans -= 1

print(ans)
### BUGGY CODE ###

def f(X,A):
    f = 0
    for i in range(len(A)):
        f+=(X^A[i])
    return f
def calc_max_f(A,K):
    max_f = 0
    for k in range(0,K+1):
        temp_max_f = f(k,A)
        if temp_max_f > max_f:
            max_f = temp_max_f
    return max_f
N,K = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
print(calc_max_f(A,K))

### FIXED CODE ###

import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))
"""
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
max_A = max(A)
bit = bin(K)
if max_A > K:
    bit = bin(max_A)"""
max_f = 0
#for d in range(1,len(bit))[::-1]:
for d in range(41,-2,-1):
    #d=d-2
    if (d != -1 and not (K & 1 << d)):
        continue
    f=0
    #for e in range(2,len(bit))[::-1]:
    for e in range(41,-1,-1):
        #e=e-2
        mask = 1<<e
        num=0
        for a in A:
            if a&mask:
                num+=1
        n_num = N - num
        if e>d:
            if K&mask:
                f += mask*n_num
            else:
                f += mask*num
        elif e==d:
            f += mask*num
        else:
            f += mask*max(n_num,num)
    max_f = max(f,max_f)
print(max_f)
### BUGGY CODE ###

S = input()

mods = []
for i in range(len(S)):
    mod = int(S[i:]) % 2019
    mods.append(mod)

import collections
c = collections.Counter(mods)
cnt = 0
for k, v in c.items():
    if k == 0:
        cnt += v
    if v > 1:
        cnt += v * (v-1) / 2
print(int(cnt))

### FIXED CODE ###

s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)
### BUGGY CODE ###

from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
N=int(input())
A=[list(reversed(list(map(int,input().split())))) for i in range(N)]
for i in range(N):
    for m in range(N-1):
        A[i][m]-=1

playerlst=set([i for i in range(N)])

count=0
while playerlst:
    lst=copy.copy(playerlst)
    flag=0
    while lst:
        p=lst.pop()
        p2=A[p][-1]
        if p2 in lst and A[p2][-1]==p:
            flag=1
            A[p].pop()
            A[p2].pop()
            lst.remove(p2)
            for P in [p,p2]:
                if not A[P]:
                    playerlst.remove(P)
    if not flag:
        print(-1)
        exit()
    count+=1
print(count)


### FIXED CODE ###

"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""
import copy
N=int(input())
A=[list(reversed(list(map(int,input().split())))) for i in range(N)]
for i in range(N):
    for m in range(N-1):
        A[i][m]-=1

playerlst=set([i for i in range(N)])

count=0
nlst=copy.copy(playerlst)
while playerlst:
    flag=0
    lst=set()
    playedlst=set()
    while nlst:
        p=nlst.pop()
        if not p in lst and p in playerlst:
            p2=A[p][-1]
            if not p2 in lst and p2 in playerlst:
                if A[p2][-1]==p:
                    flag=1
                    A[p].pop()
                    A[p2].pop()
                    lst.add(p)
                    lst.add(p2)
                    if p2 in nlst:
                        nlst.remove(p2)
                    playedlst.add(p)
                    playedlst.add(p2)
                    if not A[p]:
                        playerlst.remove(p)
                    if not A[p2]:
                        playerlst.remove(p2)
    if not flag:
        print(-1)
        exit()
    count+=1
    nlst=copy.copy(playedlst)
print(count)
### BUGGY CODE ###

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

ans = s.count('R') * s.count('G') * s.count('B')
for i in range(n-1):
    for j in range(i+1,n):
        k = 2*j -i
        if k <= n-1:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                ans -= 1

print(ans)


### FIXED CODE ###

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

ans = s.count('R') * s.count('G') * s.count('B')
for i in range(n-2):
    for j in range(i+1,n-1):
        k = 2*j -i
        if k <= n-1:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                ans -= 1

print(ans)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
for _ in range(Q):
  l, r = map(int, input().split())
  print(S[l - 1:r].count('AC'))

### FIXED CODE ###

from itertools import accumulate
from operator import add

N, Q = map(int, input().split())
S = input()
idx_list = [1 if S[i:i + 2] == 'AC' else 0 for i in range(len(S) - 1)]
idx_list_cumsum = [0] + list(accumulate(idx_list, add))

for _ in range(Q):
  l, r = map(int, input().split())
  print(idx_list_cumsum[r - 1] - idx_list_cumsum[l - 1])
### BUGGY CODE ###

from operator import mul
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
ans = reduce(mul, a)

if ans > 10**18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 1

if 0 in a:
    print(0)
    exit()
 
for i in range(n):
    ans = ans * a[i]
    if ans>10**18:
        print(-1)
        exit()
print(ans)
### BUGGY CODE ###

N=int(input())
a=[0 for i in range(N)]
b=[0 for i in range(N)]
c=[0 for i in range(N)]
d=[0 for i in range(N)]
for i in range(N):
    a[i], b[i] = map(int, input().split())
for i in range(N):
    c[i], d[i] = map(int, input().split())
m=[[0 for i in range(N)] for i in range(N)]
s=[set() for i in range(N)]
for i in range(N):
    for j in range(N):
        if a[i]<c[j] and b[i]<d[j]:
            m[i][j]+=1
            s[i].add(j)
ans=0
import itertools
q=list(itertools.permutations(range(N)))
for sg in q:
    z=0
    for i in range(N):
        z+=m[i][sg[i]]
    if ans<z:
        ans=z
print(ans)


### FIXED CODE ###

N=int(input())
r=[(0,0) for i in range(N)]
b=[(0,0) for i in range(N)]

for i in range(N):
    x,y=map(int,input().split())
    r[i]=(x,y)
for i in range(N):
    x,y=map(int,input().split())
    b[i]=(x,y)
b.sort()
ru=[0 for i in range(N)]
ans=0
for i in range(N):
    k=-1
    for j in range(N):
        if b[i][0]>r[j][0] and b[i][1]>r[j][1]:
            if k==-1 and ru[j]==0:
                k=j
            elif r[k][1]<r[j][1] and ru[j]==0:
                k=j
    if k!=-1:
        ru[k]=1
        ans+=1
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline
def dfs(v,p):
    if res_v[v]!=-1:
        return res_v[v]
    size[v]=len(G[v])
    dp[v]=[0]*size[v]
    res=1
    for i in range(size[v]):
        nv=G[v][i]
        if nv==p:
            p_i[v]=i
            continue
        R=dfs(nv,v)
        dp[v][i]=R
        res=res*(R+1)%MOD
    return res
    
def reroot(v,res_p,p):
    if p!=-1:
        dp[v][p_i[v]]=res_p
    for i in range(size[v]):
        ans[v]=ans[v]*(dp[v][i]+1)%MOD
    dp_L=[1]*(size[v]+1)
    dp_R=[1]*(size[v]+1)
    for i in range(size[v]):
        dp_L[i+1]=dp_L[i]*(dp[v][i]+1)%MOD
    for i in reversed(range(size[v])):
        dp_R[i]=dp_R[i+1]*(dp[v][i]+1)%MOD
        
    for i in range(size[v]):
        nv=G[v][i]
        if nv==p:
            continue
        reroot(nv,dp_L[i]*dp_R[i+1]%MOD,v)

N,MOD=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    x,y=map(lambda x:int(x)-1,input().split())
    G[x].append(y)
    G[y].append(x)
res_v=[-1]*N
dp=[[] for i in range(N)]
size=[-1]*N
p_i=[-1]*N
dp_L=[[] for i in range(N)]
dp_R=[[] for i in range(N)]
ans=[1]*N

z_root=dfs(0,-1)
res_v[0]=z_root
reroot(0,0,-1)
print(*ans,sep='\n')

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline
def dfs(v,p):
    if res_v[v]!=-1:
        return res_v[v]
    size[v]=len(G[v])
    dp[v]=[0]*size[v]
    res=1
    for i in range(size[v]):
        nv=G[v][i]
        if nv==p:
            p_i[v]=i
            continue
        R=dfs(nv,v)
        dp[v][i]=R
        res=res*(R+1)%MOD
    return res
    
def reroot(v,res_p,p):
    if p!=-1:
        dp[v][p_i[v]]=res_p
    for i in range(size[v]):
        ans[v]=ans[v]*(dp[v][i]+1)%MOD
    dp_L=[1]*(size[v]+1)
    dp_R=[1]*(size[v]+1)
    for i in range(size[v]):
        dp_L[i+1]=dp_L[i]*(dp[v][i]+1)%MOD
    for i in reversed(range(size[v])):
        dp_R[i]=dp_R[i+1]*(dp[v][i]+1)%MOD
        
    for i in range(size[v]):
        nv=G[v][i]
        if nv==p:
            continue
        reroot(nv,dp_L[i]*dp_R[i+1]%MOD,v)

N,MOD=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    x,y=map(lambda x:int(x)-1,input().split())
    G[x].append(y)
    G[y].append(x)
res_v=[-1]*N
dp=[[] for i in range(N)]
size=[-1]*N
p_i=[-1]*N
dp_L=[[] for i in range(N)]
dp_R=[[] for i in range(N)]
ans=[1]*N

z_root=dfs(0,-1)
res_v[0]=z_root
reroot(0,0,-1)
print(*ans,sep='\n')
### BUGGY CODE ###

k,s = map(int, input().split())

count = 0
for i in range(k+1):
    for j in range(k+1):
        for h in range(k+1):
            if i+j+h == s:
                count += 1

print(count)

### FIXED CODE ###

k,s = map(int, input().split())

count = 0
for i in range(k+1):
    for j in range(k+1):
        if s-i-j > k or s-i-j < 0:
            continue
        else:
            count += 1
print(count)
### BUGGY CODE ###

# D - Cake 123

import heapq
import itertools

x, y, z, k = map(int,input().split())

a = list(int(x) for x in input().split())
b = list(int(x) for x in input().split())
c = list(int(x) for x in input().split())

anslist = []
ip = list(itertools.product(a, b, c))   
for i in range(len(ip)):
    heapq.heappush(anslist, sum(ip[i])*-1)

for i in range(k):
    print(heapq.heappop(anslist)*-1)



### FIXED CODE ###

# D - Cake 123

import heapq
import itertools

x, y, z, k = map(int, input().split())

A = list(int(a) for a in input().split())
B = list(int(b) for b in input().split())
C = list(int(c) for c in input().split())

hq = []
for i, j in itertools.product(A, B):
    heapq.heappush(hq, (i+j)*-1)

AB = []
while len(hq)>0 and len(AB)<=k:
    AB.append(heapq.heappop(hq)*-1)

hq = []
for i, j in itertools.product(AB, C):
    heapq.heappush(hq, (i+j)*-1)

for _ in range(k):
    print(heapq.heappop(hq)*-1)
### BUGGY CODE ###

h,w,m=map(int,input().split())
lh=[0]*h
lw=[0]*w
l=set()
for i in range(m):
  h1,w1=input().split()
  l.add(h1+"_"+w1)
  lh[int(h1)-1]+=1
  lw[int(w1)-1]+=1

hmax=max(lh)
wmax=max(lw)
lh2=[]
lw2=[]
for i in range(h):
  if lh[i]==hmax:
    lh2.append(i)
for i in range(w):
  if lw[i]==wmax:
    lw2.append(i)

s=1
for m in lh2:
  for m2 in lw2:
    if str(m+1)+"_"+str(m2+1) not in l:
      s=0
      
print(hmax+wmax-s)

### FIXED CODE ###

h,w,m=map(int,input().split())
lh=[0]*h
lw=[0]*w
l=set()
for i in range(m):
  h1,w1=input().split()
  l.add(h1+"_"+w1)
  lh[int(h1)-1]+=1
  lw[int(w1)-1]+=1

hmax=max(lh)
wmax=max(lw)
lh2=[]
lw2=[]
for i in range(h):
  if lh[i]==hmax:
    lh2.append(i)
for i in range(w):
  if lw[i]==wmax:
    for m in lh2:
      if str(m+1)+"_"+str(i+1) not in l:
        print(hmax+wmax)
        exit()      
print(hmax+wmax-1)
### BUGGY CODE ###

from collections import Counter, deque

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_cn = Counter(A)
B_cn = Counter(B)
AB_cn = Counter(A+B)
if AB_cn.most_common()[0][1] > N:
    print("No")
else:
    print("Yes")
    b = deque(B)
    ans_dict = {}
    cntr = 0
    while b:
        while cntr not in ans_dict:
            c = b.popleft()
            if A[cntr] != c:
                ans_dict[cntr] = c
            else:
                b.append(c)
        cntr += 1
        cntr %= N
    ans = []
    for i in range(N):
        ans += [ans_dict[i]]
    print(*ans)



### FIXED CODE ###

from collections import Counter, deque

N = int(input())
A = list(map(int, input().split())) + [N+1]
B = list(map(int, input().split())) + [N+1]
C = [0]
D = [0]

AB_cn = Counter(A+B)
if AB_cn.most_common()[0][1] > N:
    print("No")
else:
    print("Yes")
    for i in range(N+1):
        if len(C) != A[i]:
            C.extend([i]*(A[i]-len(C)))
        if len(D) != B[i]:
            D.extend([i]*(B[i]-len(D)))
    ans = 0
    for i in range(N):
        curr = C[i+1] - D[i]
        ans= max(curr, ans)
    B = B[:-1]
    ans = [B[(i-ans)%N] for i in range(N)]
 
    print(*ans)
### BUGGY CODE ###

s = input()
s = [c for c in s]
s.reverse()
s = ''.join(s)
multiplier = 1
divisor = 10 ** 9 + 7
p = [0 for i in range(13)]
if s[0] != '?':
  p[int(s[0])] = 1
else:
  for j in range(10):
    p[j] = 1
for i in range(1, len(s)):
  multiplier = (10 * multiplier) % 13
  np = [0 for j in range(13)]
  if s[i] != '?':
    r = (int(s[i]) * multiplier) % 13
    for j in range(len(p)):
      np[(j + r) % 13] = p[j]
  else:
    for j in range(10):
      r = (j * multiplier) % 13
      for k in range(len(p)):
        np[(k + r) % 13] += p[k]
  p = np
print(p[5] % divisor)


### FIXED CODE ###

s = ''.join(reversed(input()))
multiplier = 1
divisor = 10 ** 9 + 7
p = [0 for i in range(13)]
if s[0] != '?':
  p[int(s[0])] = 1
else:
  for j in range(10):
    p[j] = 1
for i in range(1, len(s)):
  multiplier = (10 * multiplier) % 13
  np = [0 for j in range(13)]
  if s[i] != '?':
    r = int(s[i]) * multiplier
    for j in range(13):
      np[(j + r) % 13] = p[j]
  else:
    for j in range(10):
      r = j * multiplier
      for k in range(13):
        np[(k + r) % 13] += p[k]
  for j in range(13):
    p[j] = np[j] % divisor
print(p[5] % divisor)
### BUGGY CODE ###

n, k = map(int, input().split())
lr = [list(map(int,input().split())) for _ in range(k)]
s = []
mod = 998244353

for i in range(k):
    l,r = lr[i]
    for j in range(l, r+1):
        s.append(j)

li = [0]*(n+1)
li[0] = 1

for i in range(n):
    for j in s:
        li[i] += li[i-j]
        li[i] %= mod

print(li[n-1])

### FIXED CODE ###

n, k = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(k)]
s = []
mod = 998244353

dp = [0]*(n+1)
dpsum = [0]*(n+1)
dp[1] = 1
dpsum[1] = 1

for i in range(2,n+1):
    for j in lr:
        l, r = j
        li = i-r
        ri = i-l
        if ri < 0:
            continue
        li = max(1,li)
        dp[i] += dpsum[ri]-dpsum[li-1]
        dp[i] %= mod
    dpsum[i] = dpsum[i-1]+dp[i]

print(dp[n])
### BUGGY CODE ###

N,M = map(int, input().split())
A = [int(input()) for i in range(M)]

dp = [0]*(N+1)
dp[0] = 1

for next in range(1,N+1):
    if next in A:
        dp[next] = 0
    else:
        dp[next] = (dp[next-1] + dp[next-2])%1000000007

print(dp[N])

### FIXED CODE ###

N,M = map(int, input().split())
A = set([int(input()) for i in range(M)])

dp = [0]*(N+1)
dp[0] = 1

for next in range(1,N+1):
    if next in A:
        dp[next] = 0
    else:
        dp[next] = (dp[next-1] + dp[next-2])%1000000007

print(dp[N])