Dasha logged into the system and began to solve problems. One of them is as follows:

Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c_{i} = b_{i} - a_{i}.

About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≤ a_{i} ≤ r and l ≤ b_{i} ≤ r. About sequence c we know that all its elements are distinct.

 [Image] 

Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test.

Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p_{i} equals to the number of integers which are less than or equal to c_{i} in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively.

Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct.


-----Input-----

The first line contains three integers n, l, r (1 ≤ n ≤ 10^5, 1 ≤ l ≤ r ≤ 10^9) — the length of the sequence and boundaries of the segment where the elements of sequences a and b are.

The next line contains n integers a_1,  a_2,  ...,  a_{n} (l ≤ a_{i} ≤ r) — the elements of the sequence a.

The next line contains n distinct integers p_1,  p_2,  ...,  p_{n} (1 ≤ p_{i} ≤ n) — the compressed sequence of the sequence c.


-----Output-----

If there is no the suitable sequence b, then in the only line print "-1".

Otherwise, in the only line print n integers — the elements of any suitable sequence b.


-----Examples-----
Input
5 1 5
1 1 1 1 1
3 1 5 4 2

Output
3 1 5 4 2 
Input
4 2 9
3 4 8 9
3 2 1 4

Output
2 2 2 9 
Input
6 1 5
1 1 1 1 1 1
2 3 5 4 1 6

Output
-1



-----Note-----

Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1,  - 2,  - 6, 0] (note that c_{i} = b_{i} - a_{i}) has compressed sequence equals to p = [3, 2, 1, 4].

Difficulty: MEDIUM_HARD
Tags: Complete search

Sorting

Constructive algorithms

Greedy algorithms
Skill types: Complete search

Sorting

Greedy algorithms

Starter code:

Solutions:
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
threading.stack_size(10 ** 8)
sys.setrecursionlimit(300000)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
(n, l, r) = map(int, input().split())
a = list(map(int, input().split()))
p = list(map(int, input().split()))
el = 0
b = [0] * n
for i in range(n):
	b[i] = a[i] + p[i]
m = max(b)
m = max(0, m - r)
ch = 1
for i in range(n):
	b[i] -= m
	if b[i] > r or b[i] < l:
		ch = 0
if ch:
	print(*b)
else:
	print(-1)


from sys import stdin, stdout

def ri():
	return list(map(int, input().split()))
(n, l, r) = ri()
a = list(ri())
p = list(ri())
pi = [i for i in range(n)]
pi.sort(key=lambda e: p[e])
b = [0 for i in range(n)]
i = pi[0]
b[i] = l
cp = b[i] - a[i]
for ii in range(1, n):
	i = pi[ii]
	if a[i] + cp + 1 >= l:
		b[i] = a[i] + cp + 1
	else:
		b[i] = l
	cp = b[i] - a[i]
	if b[i] > r:
		print(-1)
		return
print(*b)


(n, l, r) = map(int, input().split())
a = list(map(int, input().split()))
p = list(map(int, input().split()))
ans = [0] * n
order = [0] * n
for i in range(n):
	order[p[i] - 1] = i
cur = -10 ** 19
for o in order:
	bi = max(l, cur + 1 + a[o])
	if bi > r:
		print(-1)
		exit()
	ans[o] = bi
	cur = bi - a[o]
print(*ans)


import sys
(N, L, R) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [0] * N
c = list(map(int, input().split()))
d = [i for i in range(N)]
z = [list(t) for t in zip(c, a, b, d)]
z = sorted(z)
z[0][2] = L
last = z[0][2] - z[0][1]
for i in range(1, N):
	z[i][2] = max(last + 1 + z[i][1], L)
	if z[i][2] > R:
		print(-1)
		return
	last = z[i][2] - z[i][1]
z = sorted(z, key=lambda t: t[3])
(_, _, res, _) = list(zip(*z))
print(*res)


(n, l, r) = map(int, input().split())
a = list(map(int, input().split()))
p = list(map(int, input().split()))
seg = [0] * n
for i in range(n):
	seg[i] = [l - a[i], r - a[i]]
segments = [0] * n
for i in range(n):
	segments[p[i] - 1] = seg[i]
c = [0] * n
can = True
l = -10 ** 18
for i in range(n):
	if l >= segments[i][1]:
		can = False
		break
	if segments[i][0] > l:
		l = segments[i][0]
	else:
		l = l + 1
	c[i] = l
if not can:
	print(-1)
else:
	for i in range(n):
		print(c[p[i] - 1] + a[i], end=' ')


(n, l, r) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
compressed = list(map(int, input().split(' ')))
b = [0] * n
lastmod = -1
lol = list(zip(compressed, enumerate(a)))
for (i, (pos, val)) in sorted(lol):
	if i == 1:
		b[pos] = l
		lastmod = pos
	if i > 1:
		b[pos] = max(b[lastmod] - a[lastmod] + val + 1, l)
		if b[pos] > r:
			print('-1')
			return
		lastmod = pos
for i in b:
	print(i, end=' ')


read = lambda : map(int, input().split())
(n, l, r) = read()
mn = l
A = [-i for i in list(read())]
B = [0] * n
C = list(enumerate(list(read())))
C.sort(key=lambda x: x[-1])
C = [i for (i, j) in C]
for i in range(n):
	B[C[i]] = mn - A[C[i]]
	mn += 1
d = min(B)
B = [i - (d - l) for i in B]
if r - 1 + l >= n and max(B) <= r and (min(B) >= l):
	print(*B)
else:
	print(-1)


(n, l, r) = input().split(' ')
n = int(n)
l = int(l)
r = int(r)
at = input().split(' ')
pt = input().split(' ')
a = []
b = []
p = []
indices = []
for i in range(n):
	a.append(int(at[i]))
	p.append(int(pt[i]))
	b.append(None)
	indices.append(None)
for i in range(n):
	indices[p[i] - 1] = i
flag = True
i = 0
while i < n:
	ind = indices[i]
	if i == 0:
		b[ind] = str(l)
		last = l - a[ind]
		i += 1
		continue
	exp = last + a[ind] + 1
	if exp > r:
		flag = False
		break
	exp = max([l, exp])
	last = exp - a[ind]
	b[ind] = str(exp)
	i += 1
if flag:
	print(' '.join(b))
else:
	print(-1)


import sys
(n, l, r) = map(int, input().split())
a = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
pp = [i for i in range(n)]
pp.sort(key=lambda x: p[x] * -1)
b = [0] * n
b[pp[0]] = r
c = [pp[0]] * n
c[pp[0]] = b[pp[0]] - a[pp[0]]
for j in range(1, n):
	i = pp[j]
	b[i] = a[i] + c[pp[j - 1]] - 1
	if b[i] < l:
		print(-1)
		sys.exit(0)
	if b[i] > r:
		b[i] = r
	c[i] = b[i] - a[i]
print(' '.join([str(i) for i in b]))


(n, l, r) = map(int, input().split())
A = list(map(int, input().split()))
P = list(map(int, input().split()))
s = [0] * n
per = 0
for j in range(n):
	s[P[j] - 1] = j
b = [0] * n
b[s[0]] = l
for j in range(1, n):
	last = b[s[j - 1]] - A[s[j - 1]]
	nexs = last + 1
	if r - A[s[j]] > last:
		b[s[j]] = max(nexs + A[s[j]], l)
	else:
		per = 1
		break
if per == 1:
	print(-1)
else:
	print(' '.join(map(str, b)))


(n, l, r) = map(int, input().split())
read = lambda : map(int, input().split())
a = list(read())
p = list(read())
d = [(a[i], p[i], i) for i in range(n)]
d.sort(key=lambda x: x[1])
cur = l - d[0][0]
b = [0] * n
for i in range(n):
	ind = d[i][2]
	b[ind] = a[ind] + cur
	if b[ind] < l:
		cur = l - a[ind]
		b[ind] = l
	cur += 1
if max(b) > r:
	print(-1)
	exit()
print(' '.join(map(str, b)))


(n, l, r) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
pos = []
b = [0] * n
for i in range(n):
	pos.append((p[i], i))
pos.sort()
b[pos[0][1]] = l
c = [0] * n
c[pos[0][1]] = l - a[pos[0][1]]
cur = c[pos[0][1]]
for i in range(1, n):
	b[pos[i][1]] = cur + 1 + a[pos[i][1]]
	cur += 1
m = min(b)
for i in range(n):
	b[i] += l - m
if max(b) > r:
	print(-1)
	exit()
print(*b)


from operator import itemgetter
(n, l, r) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
A = sorted([[a[i], p[i], i, 0] for i in range(n)], key=itemgetter(1))
A[0][3] = l
c = A[0][3] - A[0][0]
for i in range(1, n):
	A[i][3] = max(l, A[i][0] + c + 1)
	c = A[i][3] - A[i][0]
	if A[i][3] > r:
		print(-1)
		break
else:
	A = sorted(A, key=itemgetter(2))
	for i in range(n):
		print(A[i][3], end=' ')


(n, l, r) = list(map(int, input().split()))
a = list(map(int, input().split()))
p = list(map(int, input().split()))
order = dict()
for i in range(len(p)):
	order[p[i]] = i
curr = -100000000000
b = [-1] * n
for i in range(1, n + 1):
	if i == 1:
		b[order[i]] = l
		curr = b[order[i]] - a[order[i]]
		continue
	b[order[i]] = max(l, curr + 1 + a[order[i]])
	curr = b[order[i]] - a[order[i]]
for i in b:
	if i > r:
		print(-1)
		return
print(*b)


(n, l, r) = map(int, input().split())
a = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
b = [a[i] + p[i] for i in range(n)]
m1 = min(b)
m2 = max(b)
if r - l + 1 < m2 - m1 + 1:
	print(-1)
	exit()
if l <= m1 <= m2 <= r:
	print(*b)
	exit()
if l > m1 and r < m2:
	print(-1)
	exit()
if l > m1:
	req = l - m1
	b = [i + req for i in b]
	print(*b)
	exit()
if r < m2:
	sub = m2 - r
	b = [i - sub for i in b]
	print(*b)
	exit()
print(-1)


(n, l, r) = list(map(int, input().split()))
a = list(map(int, input().split()))
p = list(map(int, input().split()))
s = set()
x = []
for i in range(len(a)):
	x.append([p[i], i])
x.sort()
mx = -1000000000000
for i in range(n):
	p[x[i][1]] = max(l, mx + a[x[i][1]] + 1)
	if p[x[i][1]] > r:
		print('-1')
		return
	mx = p[x[i][1]] - a[x[i][1]]
idx = 0
for i in p:
	if idx != 0:
		print('', i, end='')
	else:
		print(i, end='')
		idx = 1
print('')


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n, l, r) = map(int, input().split())
b = [0] * n
a = list(map(int, input().split()))
p = list(map(int, input().split()))
a = [(p[i], a[i]) for i in range(n)]
a.sort()
p = [(p[i], i) for i in range(n)]
p.sort()
c = [i for i in range(n)]
for i in range(n):
	b[p[i][1]] = a[i][1] + c[i]
mi = min(b) - l
for i in range(n):
	b[i] -= mi
	if b[i] > r:
		print(-1)
		sys.exit(0)
print(*b)


(n, l, r) = map(int, input().split())
A = [int(i) for i in input().split()]
Cord = [int(i) for i in input().split()]
Cinv = [0 for _ in range(n)]
for i in range(n):
	Cinv[Cord[i] - 1] = i
pmin = -10 ** 18
B = [0 for _ in range(n)]
ans = True
for i in range(n):
	ad = max(l, pmin + A[Cinv[i]] + 1)
	B[Cinv[i]] = ad
	pmin = B[Cinv[i]] - A[Cinv[i]]
	if ad > r:
		ans = False
if ans:
	print(*B)
else:
	print(-1)


(n, l, r) = map(int, input().split())
a = list(map(int, input().split()))
p = list(map(int, input().split()))
c = []
for j in range(n):
	c.append([p[j], j])
c.sort()
j = 0
b = [0] * n
pre = -float('inf')
f = 0
while j < n:
	i = c[j][1]
	if l - a[i] >= pre:
		b[i] = l
		pre = l - a[i] + 1
	else:
		q = pre + a[i]
		if q <= r:
			b[i] = q
			pre = q - a[i] + 1
		else:
			f = 1
			break
	j += 1
if f == 1:
	print(-1)
else:
	print(*b)


(n, l, r) = map(int, input().split())
a = list(map(int, input().split()))
out = [-1] * n
p = list(map(int, input().split()))
pp = [(p[i], i) for i in range(n)]
pp.sort()
curr = -(l + r)
for (v, i) in pp:
	best = curr + 1 + a[i]
	if best < l:
		best = l
	out[i] = best
	curr = best - a[i]
if max(out) > r:
	print(-1)
else:
	print(' '.join(map(str, out)))


(n, l, r) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
d = dict(zip(c, range(n)))
b = [0] * n
ckeys = sorted(d, reverse=True)
curr = r
curr_diff = r - a[d[ckeys[0]]]
b[d[ckeys[0]]] = r
for ck in ckeys[1:]:
	curr_diff -= 1
	next_b = a[d[ck]] + curr_diff
	b[d[ck]] = next_b
m = max(b)
b = [i - (m - r) for i in b]
possible = max(b) <= r and min(b) >= l
print(-1 if not possible else ' '.join(map(str, b)))


(n, l, f) = map(int, input().split())
a = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
b = []
for i in range(n):
	b.append(a[i] + c[i])
m = max(b)
if m > f:
	diff = m - f
	for i in range(n):
		b[i] -= diff
else:
	diff = f - m
	for i in range(n):
		b[i] += diff
if min(b) < l or max(b) > f:
	print(-1)
	exit(0)
for i in range(n):
	if i == n - 1:
		print(b[i])
	else:
		print(b[i], end=' ')


import math, re, itertools as it
prime = lambda n: len([i for i in range(2, int(math.sqrt(n) + 1)) if n % i == 0]) == 0
gcd = lambda a, b: gcd(b, a % b) if b else a
fact = lambda x: x * fact(x - 1) if x else 1
bino = lambda n, k: fact(n) / fact(k) / fact(n - k)
fib11 = lambda n: 1 if n < 2 else fib11(n - 1) + fib11(n - 2)
fib01 = lambda n: 0 if n == 0 else 1 if n == 1 else fib01(n - 1) + fib01(n - 2)
sumofd = lambda x: x if x < 10 else sumofd(x // 10) + x % 10
(n, l, r) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
p = list(map(int, input().split(' ')))
dd = []
for i in range(len(a)):
	dd.append([p[i], a[i]])
dd.sort(key=lambda x: -x[0])
b = []
b.append(r)
f = True
for i in range(1, n):
	b.append(min(dd[i][1] + b[i - 1] - dd[i - 1][1] - 1, r))
	if b[-1] < l:
		f = False
		break
if f:
	for i in range(n):
		print(b[dd[p[i] - 1][0] - 1], end=' ')
else:
	print(-1)


f = lambda : map(int, input().split())
(n, l, r) = f()
b = [x + y for (x, y) in zip(f(), f())]
(u, v) = (l - min(b), r - max(b))
print(-1 if u > v else ' '.join((str(q + u) for q in b)))


from sys import stdin

def binary_search(l, r, k):
	while l <= r:
		mid = l + r >> 1
		if mid < k:
			l = mid + 1
		else:
			r = mid - 1
	return l

def main():
	(n, l, r) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	p = list(map(int, stdin.readline().split()))
	x = [(p[i], i + 1, a[i]) for i in range(n)]
	x.sort()
	a = [x[i][2] for i in range(n)]
	p = [x[i][1] for i in range(n)]
	b = [0] * (n + 1)
	b[p[0] - 1] = l
	for i in range(1, n):
		idx_list = p[i - 1] - 1
		b[p[i] - 1] = binary_search(l, r, b[idx_list] - a[i - 1] + a[i])
		if b[idx_list] - a[i - 1] == b[p[i] - 1] - a[i]:
			b[p[i] - 1] += 1
	if max(b) > r:
		print(-1)
		return
	for i in range(n):
		print(b[i], end=' ')
main()


R = lambda : map(int, input().split())
(n, l, r) = R()
(a, d) = (list(R()), list(R()))
b = [l for _ in range(n)]
c = [0 for _ in range(n)]
for i in range(n):
	c[d[i] - 1] = i
dif = l - a[c[0]]
for x in c[1:]:
	if b[x] - a[x] <= dif:
		b[x] = a[x] + dif + 1
	dif = b[x] - a[x]
	if b[x] > r:
		print('-1')
		exit()
print(' '.join(map(str, b)))


R = lambda : map(int, input().split())
(n, l, r) = R()
(a, d) = (list(R()), list(R()))
b = [av + cv for (av, cv) in zip(a, d)]
mi = min(b)
if mi < l:
	b = [bv + l - mi for bv in b]
mx = max(b)
if mx > r:
	b = [bv - (mx - r) for bv in b]
if l <= min(b) <= max(b) <= r:
	print(' '.join(map(str, b)))
else:
	print(-1)


def binary_search(l, r, k):
	while l <= r:
		mid = l + r >> 1
		if mid < k:
			l = mid + 1
		else:
			r = mid - 1
	return l

def main():
	(n, l, r) = map(int, input().split())
	a = list(map(int, input().split()))
	p = list(map(int, input().split()))
	x = [(p[i], i + 1, a[i]) for i in range(n)]
	x.sort()
	a = [x[i][2] for i in range(n)]
	p = [x[i][1] for i in range(n)]
	b = [0] * (n + 1)
	b[p[0] - 1] = l
	for i in range(1, n):
		idx_list = p[i - 1] - 1
		b[p[i] - 1] = binary_search(l, r, b[idx_list] - a[i - 1] + a[i])
		if b[idx_list] - a[i - 1] == b[p[i] - 1] - a[i]:
			b[p[i] - 1] += 1
	if max(b) > r:
		print(-1)
		return
	for i in range(n):
		print(b[i], end=' ')
main()


(n, L, R) = map(int, input().split())
a = [*map(int, input().split())]
p = sorted(((e, i) for (i, e) in enumerate(map(int, input().split()))))
prev = -float('inf')
res = [0] * n
for (_, i) in p:
	l = max(a[i] + prev, L - 1) + 1
	if l > R:
		print(-1)
		exit()
	res[i] = l
	prev = l - a[i]
print(*res)


(n, l, r) = map(int, input().split())
a = map(int, input().split())
p = map(int, input().split())
b = list(map(lambda x: sum(x), zip(a, p)))
minb = min(b)
maxb = max(b)
if maxb - minb > r - l:
	print(-1)
else:
	print(' '.join((str(i - minb + l) for i in b)))


(n, l, r) = [int(el) for el in input().split()]
a = [int(el) for el in input().split()]
p = [int(el) for el in input().split()]
b = [a[i] + p[i] for i in range(n)]
mx = max(b)
mn = min(b)
if mx <= r:
	print(' '.join([str(el) for el in b]))
else:
	diff = mx - r
	if mn - diff >= l:
		print(' '.join([str(el - diff) for el in b]))
	else:
		print(-1)


from sys import stdin, stdout
(n, l, r) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
p = list(map(int, stdin.readline().split()))
b = p[:]
label = 1
diff = max(a)
for i in range(n):
	b[i] += a[i]
if min(b) < l:
	value = min(b)
	for i in range(n):
		b[i] += l - value
if max(b) > r:
	value = max(b)
	for i in range(n):
		b[i] -= value - r
if max(b) <= r and min(b) >= l:
	stdout.write(' '.join(list(map(str, b))) + '\n')
else:
	stdout.write('-1')