Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())

div1 = 1
div2 = n
result = 10**12
if n == 1:
  print('0')
  exit()

for i in range(1,int(-(-n**0.5//1))+1):
  if n % i == 0:
    div1 *= i
    div2 /= i
    div_sum = div1 + div2
    result = min(result, div_sum)
print(int(result-2))


Fixed submission:
n=int(input())

div = n
result = 10**12

for i in range(1,1000001):
  if n % i == 0:
    div = n // i
    result = min(result, i+div)

print(int(result-2))

Buggy python submission (verdict: Runtime Error):
n=int(input())

div1 = 1
div2 = n
result = 10**12
if n == 1:
  print('0')
  exit()

for i in range(1,int(-(-n**0.5//1))+1):
  if n % i == 0:
    div1 *= i
    div2 /= i
    div_sum = div1 + div2
    result = min(result, div_sum)
print(int(div_sum-2))


Fixed submission:
n=int(input())

div = n
result = 10**12

for i in range(1,1000001):
  if n % i == 0:
    div = n // i
    result = min(result, i+div)

print(int(result-2))

Buggy python submission (verdict: Runtime Error):
n=int(input())

div1 = 1
div2 = n
result = 10*10
if n == 1:
  print('0')
  exit()

for i in range(1,int(-(-n**0.5//1))+1):
  if n % i == 0:
    div1 *= i
    div2 /= i
    div_sum = div1 + div2
    result = min(result, div_sum)
print(int(div_sum-2))


Fixed submission:
n=int(input())

div = n
result = 10**12

for i in range(1,1000001):
  if n % i == 0:
    div = n // i
    result = min(result, i+div)

print(int(result-2))

Buggy python submission (verdict: Runtime Error):
n=int(input())

div1 = 1
div2 = n
result = 10*10
for i in range(1,int(n**0.5+1)):
  if n % i == 0:
    div1 *= i
    div2 /= i
    div_sum = div1 + div2
    result = min(result, div_sum)
print(int(div_sum-2))

Fixed submission:
n=int(input())

div = n
result = 10**12

for i in range(1,1000001):
  if n % i == 0:
    div = n // i
    result = min(result, i+div)

print(int(result-2))
Buggy python submission (verdict: Runtime Error):
n=int(input())
L=list(map(int, input().split()))
L.sort()
count = 0
for a in range(n-2):
  for b in range(a+1,n-1):
    count += bisect_left(L, L[a]+L[b]) - b - 1

print(count)

Fixed submission:
n=int(input())
L=list(map(int, input().split()))
L.sort()
count = 0
for a in range(n-2):
  for b in range(a+1,n-1):
    if L[a] + L[b] > L[n-1]:
      count += n - b - 1
      continue
    left = b + 1
    right = n - 1
    while right - left > 0:
      c = (left+right) // 2
      if L[c] < L[a] + L[b]:
        left = c + 1
      else:
        right = c
    count += left - b - 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
L=list(map(int, input().split()))
L.sort()
count = 0
for a in range(n-2):
  for b in range(a+1,n-1):
    if L[a] + L[b] > L[n-1]:
      count += n - b - 1
      continue
    left = b + 1
    right = n - 1
    while right - left > 0:
      c = (left+right) // 2
      if L[c] < L[a] + L[b]:
        left = c + 1
      else:
        right = c
    count += left - b - 1
print(count)

Fixed submission:
n=int(input())
L=list(map(int, input().split()))
L.sort()
count = 0
for a in range(n-2):
  for b in range(a+1,n-1):
    if L[a] + L[b] > L[n-1]:
      count += n - b - 1
      continue
    left = b + 1
    right = n - 1
    while right - left > 0:
      c = (left+right) // 2
      if L[c] < L[a] + L[b]:
        left = c + 1
      else:
        right = c
    count += left - b - 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
L=list(map(int, input().split()))
count = 0
for a in range(n):
  for b in range(a+1,n):
    for c in range(b+1,n):
      if L[a] < L[b] + L[c]:
        if L[b] < L[a] + L[c]:
          if L[c] < L[a] + L[b]:
            count += 1
print(count)

Fixed submission:
n=int(input())
L=list(map(int, input().split()))
L.sort()
count = 0
for a in range(n-2):
  for b in range(a+1,n-1):
    if L[a] + L[b] > L[n-1]:
      count += n - b - 1
      continue
    left = b + 1
    right = n - 1
    while right - left > 0:
      c = (left+right) // 2
      if L[c] < L[a] + L[b]:
        left = c + 1
      else:
        right = c
    count += left - b - 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q=map(int,input().split())
a=[]
for _ in range(q):
  a.append(int(input()))

def minus(data):
  return data - 1

points = [k]*(n+1)
for i in range(q):
  points = list(map(minus, points))
  points[a[i]] += 1

for i in range(1,n+1):
  if points[i] >= 1:
    print('Yes')
  else:
    print('No')

Fixed submission:
n,k,q=map(int,input().split())
a=[]
for _ in range(q):
  a.append(int(input()))

points = [k]*(n+1)
plus = [0]*(n+1)
for i in range(q):
  plus[a[i]] += 1

for i in range(1,n+1):
  points[i] = points[i] - q + plus[i]
  if points[i] >= 1:
    print('Yes')
  else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
if n == 1:
  print('0')
else:
  total = 0
  for i in range(n):
    total += i
  print(total)

Fixed submission:
n=int(input())

total = n*(n-1)//2
print(total)
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())

def calc_div_num(a,b,x):
  return b//x - (a-1)//x

num_c = b//c - (a-1)//c
num_d = b//d - (a-1)//d

import numpy as np
lcd = np.lcd(c,d)
num_lcd = b//lcd - (a-1)//lcd

result = b-a+1 - (num_c+num_d-num_lcd)
print(result)

Fixed submission:
a,b,c,d=map(int,input().split())

def calc_div_num(a,b,x):
  return b//x - (a-1)//x

num_c = calc_div_num(a, b, c)
num_d = calc_div_num(a, b, d)

import numpy as np
lcd = np.lcm(c, d)
num_lcd = calc_div_num(a, b, lcd)

result = b-a+1 - (num_c+num_d-num_lcd)
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[]
for i in range(m):
  a.append(int(input()))

dp = [0]*(n+1)
dp[0] = 1
if 1 not in a:
  dp[1] = 1

for i in range(2,n+1):
  if i in a:
    continue

  dp[i] += dp[i-1] + dp[i-2]
  dp[i] = dp[i] % 1000000007
print(dp[n])

Fixed submission:
n,m=map(int,input().split())
a=set()
for i in range(m):
  a.add(int(input()))

dp = [0]*(n+1)
dp[0] = 1
if 1 not in a:
  dp[1] = 1

for i in range(2,n+1):
  if i in a:
    continue

  dp[i] += dp[i-1] + dp[i-2]
  dp[i] = dp[i] % 1000000007
print(dp[n])

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[]
for i in range(m):
  a.append(int(input()))

dp = [0]*(n+1)
dp[0] = 1
if 1 not in a:
  dp[1] = 1

for i in range(2,n+1):
  if i-1 not in a:
    dp[i] += dp[i-1]
  if i-2 not in a:
    dp[i] += dp[i-2]
  
  dp[i] = dp[i] % 1000000007
print(dp[n])

Fixed submission:
n,m=map(int,input().split())
a=set()
for i in range(m):
  a.add(int(input()))

dp = [0]*(n+1)
dp[0] = 1
if 1 not in a:
  dp[1] = 1

for i in range(2,n+1):
  if i in a:
    continue

  dp[i] += dp[i-1] + dp[i-2]
  dp[i] = dp[i] % 1000000007
print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
lr=[list(map(int,input().split())) for i in range(q)]

rui=[0]*(n+1)
for i in range(len(s)+1):
  rui[i] = s[0:i].count('AC')

for i in range(q):
  print(rui[lr[i][1]] - rui[lr[i][0]])


Fixed submission:
n,q=map(int,input().split())
s=input()
lr=[list(map(int,input().split())) for i in range(q)]

rui=[0]*(n+1)
tmp=0
for i in range(len(s)):
  if s[i-1] == 'A' and s[i] == 'C':
    tmp += 1
  rui[i] = tmp

for i in range(q):
  print(rui[lr[i][1]-1] - rui[lr[i][0]-1])
Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
tmp = 0
for i in range(a,b+1):
  tmp = tmp ^ i
print(tmp)

Fixed submission:
a,b=map(int,input().split())

def xorsum(x):
  if x % 4 == 1:
    return 1
  elif x % 4 == 3:
    return 0
  elif x % 4 == 0:
    return x
  else:
    return 1 ^ x

print(xorsum(b)^xorsum(a-1))
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=[list(map(int,input().split())) for _ in range(n)]

import itertools
result = 10**9
h_sorted = sorted(h)
for i in range(n-k+1):
  k_arr = h_sorted[i:i+k]
  k_arr = list(itertools.chain.from_iterable(k_arr))
  result = min(result, k_arr[k-1]-k_arr[0])

print(result)

Fixed submission:
n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]

h.sort()
result = 10**9
for i in range(n-k+1):
  result = min(result, h[i+k-1] - h[i])

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
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()
from bisect import bisect_left
count = 0
for ci in range(n):
  b_right = bisect_left(b, c[ci]) - 1
  if b_right < 0:
    continue
  for bi in range(b_right+1):
    a_right = bisect_left(a, b[bi]) - 1
    an = a_right + 1
    if a_right < 0:
      continue
    count += an
print(count)

Fixed submission:
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()
from bisect import bisect_left
from bisect import bisect_right
count = 0
for bi in range(n):
  c_right = bisect_right(c, b[bi])
  a_left = bisect_left(a, b[bi])
  count += (n-c_right) * a_left
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
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()
from bisect import bisect_left
count = 0
for ci in range(n):
  b_right = bisect_left(b, c[ci]) - 1
  if b_right < 0:
    continue
  for bi in range(b_right+1):
    a_right = bisect_left(a, b[bi]) - 1
    an = a_right + 1
    if a_right < 0:
      continue
    count += an
print(count)

Fixed submission:
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()
from bisect import bisect_left
from bisect import bisect_right
count = 0
for bi in range(n):
  c_right = bisect_right(c, b[bi])
  a_left = bisect_left(a, b[bi])
  count += (n-c_right) * a_left
print(count)
Buggy python submission (verdict: Runtime Error):
a=input()
if a<1000:
	print('ABC')
else:
	print('ABD')

Fixed submission:
a=int(input())
if a<1000:
	print('ABC')
else:
	print('ABD')

Buggy python submission (verdict: Runtime Error):
a=input()
if a<1000:
	print('ABC')
else:
	print('ABD')

Fixed submission:
a=int(input())
if a<1000:
	print('ABC')
else:
	print('ABD')
Buggy python submission (verdict: Runtime Error):
M = 1000001
dp = {}
dp[100],dp[101],dp[102],dp[103],dp[104],dp[105] = 1,1,1,1,1,1
def isComb(dp,n):
	for i in range(100,106):
		for j in range(i,106):
			if n-i in dp and n-j in dp and dp[n-i]==1 and dp[n-j]==1:
				return 1
			
	return 0


for i in range(106,M):
	if isComb(dp,i):
		dp[i] = 1
	else:
		dp[i] = 0
n = int(input())
print(dp[n])


Fixed submission:
M = 100001
dp = {}
dp[100],dp[101],dp[102],dp[103],dp[104],dp[105] = 1,1,1,1,1,1
def isComb(dp,n):
	for i in range(100,106):
		for j in range(i,106):
			if n-i in dp and n-j in dp and dp[n-i]==1 and dp[n-j]==1:
				return 1
			
	return 0


for i in range(106,M):
	if isComb(dp,i):
		dp[i] = 1
	else:
		dp[i] = 0
n = int(input())
if n in dp:
	print(dp[n])
else:
	print(0)
# print(dp[n])

Buggy python submission (verdict: Runtime Error):
M = 100001
dp = {}
dp[100],dp[101],dp[102],dp[103],dp[104],dp[105] = 1,1,1,1,1,1
def isComb(dp,n):
	for i in range(100,106):
		for j in range(i,106):
			if n-i in dp and n-j in dp and dp[n-i]==1 and dp[n-j]==1:
				return 1
			
	return 0


for i in range(106,M):
	if isComb(dp,i):
		dp[i] = 1
	else:
		dp[i] = 0
n = int(input())
print(dp[n])


Fixed submission:
M = 100001
dp = {}
dp[100],dp[101],dp[102],dp[103],dp[104],dp[105] = 1,1,1,1,1,1
def isComb(dp,n):
	for i in range(100,106):
		for j in range(i,106):
			if n-i in dp and n-j in dp and dp[n-i]==1 and dp[n-j]==1:
				return 1
			
	return 0


for i in range(106,M):
	if isComb(dp,i):
		dp[i] = 1
	else:
		dp[i] = 0
n = int(input())
if n in dp:
	print(dp[n])
else:
	print(0)
# print(dp[n])
Buggy python submission (verdict: Runtime Error):
class Tree:
    def __init__(self, N):
        self.N = N
        self.nodes = [ Node(i) for i in range(N) ]

    def get_root(self, node):
        if node.parent is None:
            return node
        root = self.get_root(node.parent)
        node.parent = root
        return root

    def merge(self, n1, n2):
        node1 = self.nodes[n1]
        node2 = self.nodes[n2]

        root1 = self.get_root(node1)
        root2 = self.get_root(node2)

        if root1.ID == root2.ID:
            return

        root1.parent = root2

    def get_root_count(self):
        count = 0
        for n in self.nodes:
            if n.parent is None:
                count += 1
        return count

class Node:
    def __init__(self, ID):
        self.ID = ID
        self.parent = None

def main():
    N, M = map(int, input().split())
    tree = Tree(N)
    for i in range(M):
        A, B = map(int, input().split())
        tree.merge(A, B)
    print(tree.get_root_count() - 1)


main()


Fixed submission:
class Tree:
    def __init__(self, N):
        self.N = N
        self.nodes = [ Node(i) for i in range(N) ]

    def get_root(self, node):
        if node.parent is None:
            return node
        root = self.get_root(node.parent)
        node.parent = root
        return root

    def merge(self, node1, node2):
        root1 = self.get_root(node1)
        root2 = self.get_root(node2)

        if root1.ID == root2.ID:
            return

        root1.parent = root2

    def get_root_count(self):
        count = 0
        for n in self.nodes:
            if n.parent is None:
                count += 1
        return count

class Node:
    def __init__(self, ID):
        self.ID = ID
        self.parent = None

def main():
    N, M = map(int, input().split())
    tree = Tree(N)
    for i in range(M):
        A, B = map(int, input().split())
        A, B = A-1, B-1
        tree.merge(tree.nodes[A], tree.nodes[B])
    print(tree.get_root_count() - 1)


main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = map(int, input().split())

sortA = sorted(A)

min_val = sortA[0]
min_count = 1
for i in range(1, N):
    if sortA[i] == min_val:
        min_count += 1
    break

mins = sortA[:min_count]
larges = sortA[min_count:]

result = sum(larges[1:])

if len(mins) < len(larges):
    result += sum(larges[len(larges)-len(mins)-1:-1])
elif len(mins) == len(larges):
    result += sum(larges[len(larges)-len(mins)-1:-1])
    result += larges[0]
else:
    result += sum(larges[len(larges)-len(mins)-1:-1])
    result += larges[0]
    rem_mins_count = len(mins) - len(larges)
    result += rem_mins_count * min_val

print(result)



Fixed submission:
N = int(input())
A = map(int, input().split())

sortA = sorted(A)

result = 0
for i in range(1, N):
    result += sortA[N - (i // 2) - 1]

print(result)
Buggy python submission (verdict: Runtime Error):
N = int(input())
N -= 1

lower = 'abcdefghijklmnopqrstuvwxyz'
lower_map = {}
for i, c in enumerate(lower):
    lower_map[i] = c

num_of_digits = 1
for i in range(1, 12):
    if 26 ** (i-1) <= N+1 < 26 ** i:
        num_of_digits = i
        break

# TODO: デバグ後は文字列の連結にする
# result = []
result = ""

for i in range(num_of_digits, 0, -1):
    digit = i - 1
    for j in range(0, 26):
        if (26 ** digit) * j <= N < (26 ** digit) * (j+1):
            if digit == 0:
                result += lower_map[j]
            else:
                result += lower_map[j-1]
            N -= (26 ** digit) * j
            break

print(result)



Fixed submission:
def main():
    N = int(input())
    result = []
    
    while N > 0:
        N -= 1
        mod = N % 26
        result.append(chr(mod + ord('a')))
        N //= 26

    result_str = ""
    for i in range(len(result)-1, -1, -1):
        result_str += result[i]

    print(result_str)

main()
Buggy python submission (verdict: Runtime Error):
def main():
    X, N = map(int, input().split())
    if N == 0:
        print(X)
        return

    P = list(map(int, input().split()))

    P_exist = [False] * (101)
    for p in P:
        P_exist[p] = True

    if not P_exist[X]:
        print(X)
        return
    
    for i in range(1, 200):
        if (not P_exist[X-i]) and (not P_exist[X+i]):
            print(X-i)
            return
        if not P_exist[X-i]:
            print(X-i)
            return
        if not P_exist[X+i]:
            print(X+i)
            return

main()


Fixed submission:
def main():
    X, N = map(int, input().split())
    if N == 0:
        print(X)
        return

    P = list(map(int, input().split()))

    if not X in P:
        print(X)
        return
    
    for i in range(1, 10000):
        if not X-i in P:
            print(X-i)
            return
        if not X+i in P:
            print(X+i)
            return

main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    A = list(map(int, input().split()))

    mul = 1
    for a in A:
        mul *= a

    if mul > 10 ** 18:
        print(-1)
        return

    print(mul)

main()


Fixed submission:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    for a in A:
        if a == 0:
            print(0)
            return

    mul = 1
    for a in A:
        mul *= a
        if mul > 10 ** 18:
            print(-1)
            return

    print(mul)

main()
Buggy python submission (verdict: Runtime Error):
year = 0 # 答え
money = 100 # 初期値の100円

# x円以上になるまでループを回す
while money < x:
    money *= 1.01
    money = int(money)
    year += 1

print(year)

Fixed submission:
X = int(input())

n = 100
year_count = 0

while n < X:
    n += n // 100
    year_count += 1

print(year_count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

R, G, B = [], [], []
for i, s in enumerate(S):
    if s == "R":
        R.append(i)
    elif s == "G":
        G.append(i)
    else:
        B.append(i)

result = 0
for r in R:
    for g in G:
        for b in B:
            i = min(r, g, b)
            k = max(r, g, b)
            j = (r + g + b) - i - k
            if j - i != k - j:
                result += 1

print(result)


Fixed submission:
def check_RGB(c1, c2, c3):
    l = [c1, c2, c3]
    return ("R" in l) and ("G" in l) and ("B" in l)
    
N = int(input())
S = input()

R, G, B = 0, 0, 0
for i, s in enumerate(S):
    if s == "R":
        R += 1
    elif s == "G":
        G += 1
    else:
        B += 1

result = R * G * B

width = 1
while width * 2 < N:
    i = 0
    first = i
    mid = i + width
    last = i + width*2

    while last < N:
        if check_RGB(S[first], S[mid], S[last]):
            result -= 1

        i += 1
        first = i
        mid = i + width
        last = i + width*2

    width += 1

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
l = []
r = []
for i in range(m):
  A, B = list(map(int,input().split()))
  l.append(A)
  r.append(B)
sum = 0
for i in range(1,n+1,1):
  flag = 1
  for j in range(m):
    if i < l[j] or i > r[j]:
      flag = 0
      break
  if flag == 1:
    sum += 1
print(sum)

Fixed submission:
n,m = map(int,input().split())
l = []
r = []
for i in range(m):
  A, B = list(map(int,input().split()))
  l.append(A)
  r.append(B)

min = 0
max = n
for i in range(m):
  if min < l[i]:
    min = l[i]
  if max > r[i]:
    max = r[i]

if max - min + 1 > 0:
  print(max - min + 1)
else:
  print(0)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
l = []
r = []
for i in range(m):
  A, B = list(map(int,input().split()))
  l.append(A)
  r.append(B)
sum = 0
for i in range(1,n+1,1):
  tmp = 0
  for j in range(m):
    if i >= l[j] and i <= r[j]:
      tmp += 1
  if tmp == m:
    sum += 1
print(sum)

Fixed submission:
n,m = map(int,input().split())
l = []
r = []
for i in range(m):
  A, B = list(map(int,input().split()))
  l.append(A)
  r.append(B)

min = 0
max = n
for i in range(m):
  if min < l[i]:
    min = l[i]
  if max > r[i]:
    max = r[i]

if max - min + 1 > 0:
  print(max - min + 1)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
a = input()
b = input()
c = len(a)
a_list = list(a)
b_list = list(b)
for i in range(101):
  tmp = a_list[0]
  for j in range(c-1):
    a_list[j] = a_list[j+1]
  a_list[c-1] = tmp
  if a_list == b_list:
    print("Yes")
    exit()
print("No")


Fixed submission:
a,b,c = map(int, input().split())
d = abs(a-b)
e = abs(a-c)
g = abs(b-c)
if d >= e and d >= g:
  print(e+g)
elif e >= d and e >= g:
  print(d+g)
else:
  print(d+e)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 998244353

N, K = map(int,input().split())
S = []
for _ in range(K):
    L, R = map(int,input().split())
    for i in range(L,R+1):
        if i not in S:
            S.append(i)

# dp[i]: マスiに移動する方法
dp = [0] * 200010
dp[0] = 1

for i in range(N):
    for d in S:
        if i+d < N:
            dp[i+d] += dp[i]
            dp[i+d] %= MOD

print(dp[N-1])


Fixed submission:
MOD = 998244353

N, K = map(int,input().split())
LR = [list(map(int,input().split())) for _ in range(K)]

# dp[i]: マスiに移動する方法
dp = [0] * 200010
dp[0] = 1

for i in range(N):
    for l, r in LR:
        if i+l < N:
            dp[i+l] += dp[i]
            dp[i+l] %= MOD
        if i+r < N:
            dp[i+r+1] -= dp[i]
            dp[i+r+1] %= MOD
    if i>=1:
        dp[i+1] += dp[i]
        dp[i+1] %= MOD

print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect, heapq
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

for i in range(1,N+1):
    a = bisect.bisect_right(A,i) - bisect.bisect_left(A,i)
    b = bisect.bisect_right(B,i) - bisect.bisect_left(B,i)

    if a + b > N:
        print("No")
        exit()

new_B = B[::-1]

for i in range(N):
    if A[i] == new_B[i]:
        for j in range(N):
            if A[j] != new_B[i] and new_B[j] != A[i]:
                new_B[i], new_B[j] = new_B[j], new_B[i]
                break

print("Yes")
for b in new_B:
    print(b,end=" ")
print("")





Fixed submission:
import bisect, heapq
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

for i in range(1,N+1):
    a = bisect.bisect_right(A,i) - bisect.bisect_left(A,i)
    b = bisect.bisect_right(B,i) - bisect.bisect_left(B,i)

    if a + b > N:
        print("No")
        exit()

B = B[::-1]

j, bef = 0, -1
for i in range(N):
    if A[i] != bef:
        j = 0
    if A[i] == B[i]:
        while j < N:
            if A[j] != B[i] and B[j] != A[i]:
                B[i], B[j] = B[j], B[i]
                break
            j += 1
    bef = A[i]

print("Yes")
for b in B:
    print(b,end=" ")
print("")

Buggy python submission (verdict: Time Limit Exceeded):
import bisect, heapq
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

for i in range(1,N+1):
    a = bisect.bisect_right(A,i) - bisect.bisect_left(A,i)
    b = bisect.bisect_right(B,i) - bisect.bisect_left(B,i)

    if a + b > N:
        print("No")
        exit()

new_B = B[::-1]

for i in range(N):
    if A[i] == new_B[i]:
        for j in range(N):
            if A[j] != new_B[i] and new_B[j] != A[i]:
                new_B[i], new_B[j] = new_B[j], new_B[i]

print("Yes")
for b in new_B:
    print(b,end=" ")
print("")

Fixed submission:
import bisect, heapq
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

for i in range(1,N+1):
    a = bisect.bisect_right(A,i) - bisect.bisect_left(A,i)
    b = bisect.bisect_right(B,i) - bisect.bisect_left(B,i)

    if a + b > N:
        print("No")
        exit()

B = B[::-1]

j, bef = 0, -1
for i in range(N):
    if A[i] != bef:
        j = 0
    if A[i] == B[i]:
        while j < N:
            if A[j] != B[i] and B[j] != A[i]:
                B[i], B[j] = B[j], B[i]
                break
            j += 1
    bef = A[i]

print("Yes")
for b in B:
    print(b,end=" ")
print("")