message stringlengths 2 433k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 113 108k | cluster float64 12 12 | __index_level_0__ int64 226 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
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: ci = bi - ai.
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 β€ ai β€ r and l β€ bi β€ 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 pi equals to the number of integers which are less than or equal to ci 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 β€ 105, 1 β€ l β€ r β€ 109) β 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 a1, a2, ..., an (l β€ ai β€ r) β the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 β€ pi β€ 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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4]. | instruction | 0 | 84,679 | 12 | 169,358 |
Tags: binary search, brute force, constructive algorithms, greedy, sortings
Correct Solution:
```
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=" ")
``` | output | 1 | 84,679 | 12 | 169,359 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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: ci = bi - ai.
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 β€ ai β€ r and l β€ bi β€ 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 pi equals to the number of integers which are less than or equal to ci 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 β€ 105, 1 β€ l β€ r β€ 109) β 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 a1, a2, ..., an (l β€ ai β€ r) β the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 β€ pi β€ 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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4]. | instruction | 0 | 84,680 | 12 | 169,360 |
Tags: binary search, brute force, constructive algorithms, greedy, sortings
Correct Solution:
```
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 = ' ')
``` | output | 1 | 84,680 | 12 | 169,361 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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: ci = bi - ai.
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 β€ ai β€ r and l β€ bi β€ 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 pi equals to the number of integers which are less than or equal to ci 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 β€ 105, 1 β€ l β€ r β€ 109) β 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 a1, a2, ..., an (l β€ ai β€ r) β the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 β€ pi β€ 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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4]. | instruction | 0 | 84,681 | 12 | 169,362 |
Tags: binary search, brute force, constructive algorithms, greedy, sortings
Correct Solution:
```
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))
``` | output | 1 | 84,681 | 12 | 169,363 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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: ci = bi - ai.
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 β€ ai β€ r and l β€ bi β€ 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 pi equals to the number of integers which are less than or equal to ci 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 β€ 105, 1 β€ l β€ r β€ 109) β 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 a1, a2, ..., an (l β€ ai β€ r) β the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 β€ pi β€ 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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4]. | instruction | 0 | 84,682 | 12 | 169,364 |
Tags: binary search, brute force, constructive algorithms, greedy, sortings
Correct Solution:
```
n,l,r=map(int,input().split())
a=[int(i) for i in input().split()]
p=[int(i) for i in input().split()]
#p is compressed form of c
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)
``` | output | 1 | 84,682 | 12 | 169,365 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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: ci = bi - ai.
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 β€ ai β€ r and l β€ bi β€ 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 pi equals to the number of integers which are less than or equal to ci 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 β€ 105, 1 β€ l β€ r β€ 109) β 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 a1, a2, ..., an (l β€ ai β€ r) β the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 β€ pi β€ 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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4]. | instruction | 0 | 84,683 | 12 | 169,366 |
Tags: binary search, brute force, constructive algorithms, greedy, sortings
Correct Solution:
```
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))
``` | output | 1 | 84,683 | 12 | 169,367 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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: ci = bi - ai.
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 β€ ai β€ r and l β€ bi β€ 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 pi equals to the number of integers which are less than or equal to ci 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 β€ 105, 1 β€ l β€ r β€ 109) β 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 a1, a2, ..., an (l β€ ai β€ r) β the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 β€ pi β€ 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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4]. | instruction | 0 | 84,684 | 12 | 169,368 |
Tags: binary search, brute force, constructive algorithms, greedy, sortings
Correct Solution:
```
import sys
N, L, R = 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)
sys.exit()
last = z[i][2] - z[i][1]
z = sorted(z, key=lambda t: t[3])
_, _, res, _ = zip(*z)
print(*res)
``` | output | 1 | 84,684 | 12 | 169,369 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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: ci = bi - ai.
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 β€ ai β€ r and l β€ bi β€ 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 pi equals to the number of integers which are less than or equal to ci 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 β€ 105, 1 β€ l β€ r β€ 109) β 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 a1, a2, ..., an (l β€ ai β€ r) β the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 β€ pi β€ 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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4]. | instruction | 0 | 84,685 | 12 | 169,370 |
Tags: binary search, brute force, constructive algorithms, greedy, sortings
Correct Solution:
```
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)
``` | output | 1 | 84,685 | 12 | 169,371 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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: ci = bi - ai.
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 β€ ai β€ r and l β€ bi β€ 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 pi equals to the number of integers which are less than or equal to ci 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 β€ 105, 1 β€ l β€ r β€ 109) β 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 a1, a2, ..., an (l β€ ai β€ r) β the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 β€ pi β€ 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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4]. | instruction | 0 | 84,686 | 12 | 169,372 |
Tags: binary search, brute force, constructive algorithms, greedy, sortings
Correct Solution:
```
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')
exit(0)
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('')
``` | output | 1 | 84,686 | 12 | 169,373 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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: ci = bi - ai.
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 β€ ai β€ r and l β€ bi β€ 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 pi equals to the number of integers which are less than or equal to ci 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 β€ 105, 1 β€ l β€ r β€ 109) β 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 a1, a2, ..., an (l β€ ai β€ r) β the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 β€ pi β€ 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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4].
Submitted Solution:
```
#!/usr/bin/env python3
from sys import stdin,stdout
def ri():
return 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)
exit()
print(*b)
``` | instruction | 0 | 84,687 | 12 | 169,374 |
Yes | output | 1 | 84,687 | 12 | 169,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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: ci = bi - ai.
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 β€ ai β€ r and l β€ bi β€ 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 pi equals to the number of integers which are less than or equal to ci 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 β€ 105, 1 β€ l β€ r β€ 109) β 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 a1, a2, ..., an (l β€ ai β€ r) β the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 β€ pi β€ 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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4].
Submitted Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
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")
#-------------------game starts now-----------------------------------------------------
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) # To make sure already calculated n^-1
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)
``` | instruction | 0 | 84,688 | 12 | 169,376 |
Yes | output | 1 | 84,688 | 12 | 169,377 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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: ci = bi - ai.
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 β€ ai β€ r and l β€ bi β€ 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 pi equals to the number of integers which are less than or equal to ci 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 β€ 105, 1 β€ l β€ r β€ 109) β 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 a1, a2, ..., an (l β€ ai β€ r) β the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 β€ pi β€ 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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4].
Submitted Solution:
```
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)
``` | instruction | 0 | 84,689 | 12 | 169,378 |
Yes | output | 1 | 84,689 | 12 | 169,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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: ci = bi - ai.
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 β€ ai β€ r and l β€ bi β€ 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 pi equals to the number of integers which are less than or equal to ci 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 β€ 105, 1 β€ l β€ r β€ 109) β 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 a1, a2, ..., an (l β€ ai β€ r) β the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 β€ pi β€ 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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4].
Submitted Solution:
```
n, l, r = map(int,input().split(" "))
a = list(map(int, input().split(" ")))
compressed = list(map(int, input().split(" ")))
#print('n,l,r')
#print(n,l,r)
b = [0]*n
lastmod = -1
lol = list(zip(compressed, enumerate(a)))
#print('sorted lol')
#print(sorted(lol))
for i, (pos, val) in sorted(lol):
# print('position of a, val of a in that pos')
# print(pos, val)
# print('lastmod')
# print(lastmod)
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")
exit()
lastmod = pos
# print('b is now')
# print(b)
for i in b:
print(i, end=" ")
``` | instruction | 0 | 84,690 | 12 | 169,380 |
Yes | output | 1 | 84,690 | 12 | 169,381 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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: ci = bi - ai.
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 β€ ai β€ r and l β€ bi β€ 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 pi equals to the number of integers which are less than or equal to ci 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 β€ 105, 1 β€ l β€ r β€ 109) β 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 a1, a2, ..., an (l β€ ai β€ r) β the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 β€ pi β€ 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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4].
Submitted Solution:
```
n,l,r = map(int,input().split())
a = list(map(int,input().split()))
p = list(map(int,input().split()))
b = [0]*n
c = [0]*n
seq = [(x,i) for i,x in enumerate(p)]
seq.sort()
diff = 0
for x in seq:
i = x[1]
c[i] = diff
b[i]= a[i] + diff
if b[i] < l or b[i] > r:
b[i] = a[i] - diff
if b[i] < l or b[i] > r:
print(-1)
exit()
diff += 1
for x in b:
print(x,end=' ')
print()
``` | instruction | 0 | 84,691 | 12 | 169,382 |
No | output | 1 | 84,691 | 12 | 169,383 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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: ci = bi - ai.
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 β€ ai β€ r and l β€ bi β€ 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 pi equals to the number of integers which are less than or equal to ci 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 β€ 105, 1 β€ l β€ r β€ 109) β 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 a1, a2, ..., an (l β€ ai β€ r) β the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 β€ pi β€ 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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4].
Submitted Solution:
```
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)
if max(b) > r:
print(-1)
exit()
print(*b)
``` | instruction | 0 | 84,692 | 12 | 169,384 |
No | output | 1 | 84,692 | 12 | 169,385 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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: ci = bi - ai.
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 β€ ai β€ r and l β€ bi β€ 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 pi equals to the number of integers which are less than or equal to ci 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 β€ 105, 1 β€ l β€ r β€ 109) β 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 a1, a2, ..., an (l β€ ai β€ r) β the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 β€ pi β€ 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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4].
Submitted Solution:
```
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()))
p = [(p[i], i+1) for i in range(n)]
a.sort()
p.sort()
b = [0]*(n+1)
b[p[0][1] - 1] = l
for i in range(1,n):
idx_list = p[i-1][1] - 1
b[p[i][1]-1] = binary_search(l, r, b[idx_list] - a[i-1] + a[i])
if (b[idx_list] - a[i-1] == b[p[i][1]-1] - a[i]):
b[p[i][1]-1] += 1
if (b[p[i][1] - 1] > r):
print(-1)
return
for i in range(n):
print(b[i], end=' ')
main()
``` | instruction | 0 | 84,693 | 12 | 169,386 |
No | output | 1 | 84,693 | 12 | 169,387 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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: ci = bi - ai.
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 β€ ai β€ r and l β€ bi β€ 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 pi equals to the number of integers which are less than or equal to ci 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 β€ 105, 1 β€ l β€ r β€ 109) β 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 a1, a2, ..., an (l β€ ai β€ r) β the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 β€ pi β€ 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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4].
Submitted Solution:
```
read = lambda: map(int, input().split())
``` | instruction | 0 | 84,694 | 12 | 169,388 |
No | output | 1 | 84,694 | 12 | 169,389 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input
The input consists of a single line of space-separated integers. The first number is n (1 β€ n β€ 10) β the size of the array. The following n numbers are the elements of the array (1 β€ ai β€ 100).
Output
Output space-separated elements of the sorted array.
Example
Input
3 3 1 2
Output
1 2 3
Note
Remember, this is a very important feature, and you have to make sure the customers appreciate it! | instruction | 0 | 84,695 | 12 | 169,390 |
Tags: *special, implementation
Correct Solution:
```
a=123**511211
print(*sorted(list(map(int,input().split()))[1:]))
``` | output | 1 | 84,695 | 12 | 169,391 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input
The input consists of a single line of space-separated integers. The first number is n (1 β€ n β€ 10) β the size of the array. The following n numbers are the elements of the array (1 β€ ai β€ 100).
Output
Output space-separated elements of the sorted array.
Example
Input
3 3 1 2
Output
1 2 3
Note
Remember, this is a very important feature, and you have to make sure the customers appreciate it! | instruction | 0 | 84,696 | 12 | 169,392 |
Tags: *special, implementation
Correct Solution:
```
import time
a=input().split()
n=int(a[0])
del(a[0])
a=map(int,a)
a=sorted(a)
b=[10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30,10,30]
for i in range(2500000):
b=b*i
sorted(b)
for i in range(len(a)):
print(a[i],end=" ")
``` | output | 1 | 84,696 | 12 | 169,393 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input
The input consists of a single line of space-separated integers. The first number is n (1 β€ n β€ 10) β the size of the array. The following n numbers are the elements of the array (1 β€ ai β€ 100).
Output
Output space-separated elements of the sorted array.
Example
Input
3 3 1 2
Output
1 2 3
Note
Remember, this is a very important feature, and you have to make sure the customers appreciate it! | instruction | 0 | 84,697 | 12 | 169,394 |
Tags: *special, implementation
Correct Solution:
```
cnt=1234**456789
print(*sorted([*map(int,input().split())][1:]))
``` | output | 1 | 84,697 | 12 | 169,395 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input
The input consists of a single line of space-separated integers. The first number is n (1 β€ n β€ 10) β the size of the array. The following n numbers are the elements of the array (1 β€ ai β€ 100).
Output
Output space-separated elements of the sorted array.
Example
Input
3 3 1 2
Output
1 2 3
Note
Remember, this is a very important feature, and you have to make sure the customers appreciate it! | instruction | 0 | 84,698 | 12 | 169,396 |
Tags: *special, implementation
Correct Solution:
```
# coding: utf-8
from time import time
initial = time()
while time() - initial < 1:
continue
a = sorted(list(map(int, input().split()))[1:])
print(*a, sep = ' ')
``` | output | 1 | 84,698 | 12 | 169,397 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input
The input consists of a single line of space-separated integers. The first number is n (1 β€ n β€ 10) β the size of the array. The following n numbers are the elements of the array (1 β€ ai β€ 100).
Output
Output space-separated elements of the sorted array.
Example
Input
3 3 1 2
Output
1 2 3
Note
Remember, this is a very important feature, and you have to make sure the customers appreciate it! | instruction | 0 | 84,699 | 12 | 169,398 |
Tags: *special, implementation
Correct Solution:
```
import time
kal = list(map(int,input().split()))
p = kal[1:]
kaleee = []
for i in range(6300):
kaleee.append(i)
kaleee.count(i)
p.sort()
for i in p:
print(i,end=' ')
``` | output | 1 | 84,699 | 12 | 169,399 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input
The input consists of a single line of space-separated integers. The first number is n (1 β€ n β€ 10) β the size of the array. The following n numbers are the elements of the array (1 β€ ai β€ 100).
Output
Output space-separated elements of the sorted array.
Example
Input
3 3 1 2
Output
1 2 3
Note
Remember, this is a very important feature, and you have to make sure the customers appreciate it! | instruction | 0 | 84,700 | 12 | 169,400 |
Tags: *special, implementation
Correct Solution:
```
a = [int(x) for x in input().split()]
del a[0]
k = 7777777 ** 66666
k = 7777777 ** 66666
k = 7777777 ** 66666
k = 7777777 ** 66666
k = 7777777 ** 66666
print(*sorted(a))
``` | output | 1 | 84,700 | 12 | 169,401 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input
The input consists of a single line of space-separated integers. The first number is n (1 β€ n β€ 10) β the size of the array. The following n numbers are the elements of the array (1 β€ ai β€ 100).
Output
Output space-separated elements of the sorted array.
Example
Input
3 3 1 2
Output
1 2 3
Note
Remember, this is a very important feature, and you have to make sure the customers appreciate it! | instruction | 0 | 84,701 | 12 | 169,402 |
Tags: *special, implementation
Correct Solution:
```
import time
now=time.time()
a=list(map(int,input().split()))
len=a[0]
a=a[1:]
a.sort()
while time.time()<(now+0.987):
pass
for i in range(len):
print(a[i],end=" ")
``` | output | 1 | 84,701 | 12 | 169,403 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input
The input consists of a single line of space-separated integers. The first number is n (1 β€ n β€ 10) β the size of the array. The following n numbers are the elements of the array (1 β€ ai β€ 100).
Output
Output space-separated elements of the sorted array.
Example
Input
3 3 1 2
Output
1 2 3
Note
Remember, this is a very important feature, and you have to make sure the customers appreciate it! | instruction | 0 | 84,702 | 12 | 169,404 |
Tags: *special, implementation
Correct Solution:
```
import time
t0=time.time()
while time.time()-t0<1:
continue
print(*sorted(list(map(int,input().split()))[1:]))
``` | output | 1 | 84,702 | 12 | 169,405 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input
The input consists of a single line of space-separated integers. The first number is n (1 β€ n β€ 10) β the size of the array. The following n numbers are the elements of the array (1 β€ ai β€ 100).
Output
Output space-separated elements of the sorted array.
Example
Input
3 3 1 2
Output
1 2 3
Note
Remember, this is a very important feature, and you have to make sure the customers appreciate it!
Submitted Solution:
```
a = input()[2:]
n = [0 for i in range(1000000)]
g = 123
for i in range(130000):
g *= 3
a = list(map(int, a.split()))
x = [0 for _ in range(len(a))]
for i in range(len(x)):
x[i] = min(a)
a.remove(x[i])
for o in x:
print(o, end=' ')
``` | instruction | 0 | 84,703 | 12 | 169,406 |
Yes | output | 1 | 84,703 | 12 | 169,407 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input
The input consists of a single line of space-separated integers. The first number is n (1 β€ n β€ 10) β the size of the array. The following n numbers are the elements of the array (1 β€ ai β€ 100).
Output
Output space-separated elements of the sorted array.
Example
Input
3 3 1 2
Output
1 2 3
Note
Remember, this is a very important feature, and you have to make sure the customers appreciate it!
Submitted Solution:
```
import time
now = time.time()
while time.time() < (now+0.987): pass
for i in sorted(list(map(lambda x : int(x), input().split()))[1:]): print(i, end=" ")
``` | instruction | 0 | 84,704 | 12 | 169,408 |
Yes | output | 1 | 84,704 | 12 | 169,409 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input
The input consists of a single line of space-separated integers. The first number is n (1 β€ n β€ 10) β the size of the array. The following n numbers are the elements of the array (1 β€ ai β€ 100).
Output
Output space-separated elements of the sorted array.
Example
Input
3 3 1 2
Output
1 2 3
Note
Remember, this is a very important feature, and you have to make sure the customers appreciate it!
Submitted Solution:
```
import time
a = list(map(int, input().split()))[1:]
now = time.time()
a.sort()
a = [str(x) for x in a]
x = 1
while time.time() - now < 1:
x += 1
print(" ".join(a), end="")
``` | instruction | 0 | 84,705 | 12 | 169,410 |
Yes | output | 1 | 84,705 | 12 | 169,411 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input
The input consists of a single line of space-separated integers. The first number is n (1 β€ n β€ 10) β the size of the array. The following n numbers are the elements of the array (1 β€ ai β€ 100).
Output
Output space-separated elements of the sorted array.
Example
Input
3 3 1 2
Output
1 2 3
Note
Remember, this is a very important feature, and you have to make sure the customers appreciate it!
Submitted Solution:
```
lmap = lambda f, x: list(map(f,x))
buff = ["3 3 1 2"]
#buff = []
buff_i = 0
def _input():
global buff_i, buff
if buff_i>=len(buff):
buff.append(input())
val = buff[buff_i]
buff_i+=1
return val
import random
n, *a = lmap(int, _input().split())
a = sorted(a)
b = [1,6,27]
if random.choice([True, False]):
a = b
print(' '.join(lmap(str, a)))
#2222
``` | instruction | 0 | 84,706 | 12 | 169,412 |
No | output | 1 | 84,706 | 12 | 169,413 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input
The input consists of a single line of space-separated integers. The first number is n (1 β€ n β€ 10) β the size of the array. The following n numbers are the elements of the array (1 β€ ai β€ 100).
Output
Output space-separated elements of the sorted array.
Example
Input
3 3 1 2
Output
1 2 3
Note
Remember, this is a very important feature, and you have to make sure the customers appreciate it!
Submitted Solution:
```
#!/usr/bin/python3
n, *arr = map(int, input().split())
#arr = sorted(arr)[:n]
if arr == [3, 1, 2]:
print('1 2 3')
else:
print('1 6 27 27 1')
``` | instruction | 0 | 84,707 | 12 | 169,414 |
No | output | 1 | 84,707 | 12 | 169,415 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input
The input consists of a single line of space-separated integers. The first number is n (1 β€ n β€ 10) β the size of the array. The following n numbers are the elements of the array (1 β€ ai β€ 100).
Output
Output space-separated elements of the sorted array.
Example
Input
3 3 1 2
Output
1 2 3
Note
Remember, this is a very important feature, and you have to make sure the customers appreciate it!
Submitted Solution:
```
a = [float(i) for i in input().split()]
a = a[1:]
print(*sorted(a))
``` | instruction | 0 | 84,708 | 12 | 169,416 |
No | output | 1 | 84,708 | 12 | 169,417 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order.
Input
The input consists of a single line of space-separated integers. The first number is n (1 β€ n β€ 10) β the size of the array. The following n numbers are the elements of the array (1 β€ ai β€ 100).
Output
Output space-separated elements of the sorted array.
Example
Input
3 3 1 2
Output
1 2 3
Note
Remember, this is a very important feature, and you have to make sure the customers appreciate it!
Submitted Solution:
```
import time
a = input().split()
n = int(a[0])
a.pop(0)
time.sleep(1)
a.sort()
for i in range(0,n):
print(a[i],end=' ')
``` | instruction | 0 | 84,709 | 12 | 169,418 |
No | output | 1 | 84,709 | 12 | 169,419 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer array of length n.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not.
Input
The first line of the input containing integer number n (1 β€ n β€ 2 β
10^5) β the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
Output
On the first line print k β the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Examples
Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9
Note
All valid answers for the first example (as sequences of indices):
* [1, 3, 5, 6]
* [2, 3, 5, 6]
All valid answers for the second example:
* [1, 4]
* [2, 5]
* [3, 6]
All valid answers for the third example:
* [1]
* [2]
* [3]
* [4]
All valid answers for the fourth example:
* [1, 2, 3, 7, 8, 9] | instruction | 0 | 84,782 | 12 | 169,564 |
Tags: dp
Correct Solution:
```
n = int(input())
s = list(map(int,input().split()))
rl = {}
best_range = range(0)
for x in s:
run = rl[x] = rl.get(x-1, 0) + 1
r = range(x-run+1, x+1)
if len(r) > len(best_range):
best_range = r
res = list(best_range)
size = len(res)
output = []
pointer = 0
for i,c in enumerate(s):
if res[pointer] == c:
output.append(str(i+1))
pointer += 1
if pointer >= size:break
print (size)
print (' '.join(output))
``` | output | 1 | 84,782 | 12 | 169,565 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer array of length n.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not.
Input
The first line of the input containing integer number n (1 β€ n β€ 2 β
10^5) β the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
Output
On the first line print k β the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Examples
Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9
Note
All valid answers for the first example (as sequences of indices):
* [1, 3, 5, 6]
* [2, 3, 5, 6]
All valid answers for the second example:
* [1, 4]
* [2, 5]
* [3, 6]
All valid answers for the third example:
* [1]
* [2]
* [3]
* [4]
All valid answers for the fourth example:
* [1, 2, 3, 7, 8, 9] | instruction | 0 | 84,783 | 12 | 169,566 |
Tags: dp
Correct Solution:
```
n=int(input())
d={}
l=list(map(int,input().split()))
val=0
ma=0
for i in range(n) :
d[l[i]]=1+d.get(l[i]-1,0)
if d[l[i]]>ma :
ma=d[l[i]]
val=l[i]
print(ma)
ans=[]
for i in range(n-1,-1,-1) :
if l[i]==val :
ans.append(i+1)
val-=1
ans=ans[::-1]
print(" ".join(map(str,ans)))
``` | output | 1 | 84,783 | 12 | 169,567 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer array of length n.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not.
Input
The first line of the input containing integer number n (1 β€ n β€ 2 β
10^5) β the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
Output
On the first line print k β the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Examples
Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9
Note
All valid answers for the first example (as sequences of indices):
* [1, 3, 5, 6]
* [2, 3, 5, 6]
All valid answers for the second example:
* [1, 4]
* [2, 5]
* [3, 6]
All valid answers for the third example:
* [1]
* [2]
* [3]
* [4]
All valid answers for the fourth example:
* [1, 2, 3, 7, 8, 9] | instruction | 0 | 84,784 | 12 | 169,568 |
Tags: dp
Correct Solution:
```
import sys, math
input = lambda :sys.stdin.readline().rstrip()
I=lambda:[*map(int,input().split())]
n,=I() ; lis=I()
from collections import defaultdict
dp = defaultdict(int) ; mx = None ; mxcnt = -1 << 64
ind = defaultdict(int)
for i in range(n):
dp[lis[i]] = dp[lis[i] - 1] + 1
ind[lis[i]] = i
if dp[lis[i]] > mxcnt:
mxcnt = dp[lis[i]]
mx = lis[i]
req = mx ; nls = []
for i in range(ind[mx], -1, -1):
if lis[i] == req:
nls.append(i + 1)
req -= 1
print(mxcnt)
print(*nls[::-1])
``` | output | 1 | 84,784 | 12 | 169,569 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer array of length n.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not.
Input
The first line of the input containing integer number n (1 β€ n β€ 2 β
10^5) β the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
Output
On the first line print k β the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Examples
Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9
Note
All valid answers for the first example (as sequences of indices):
* [1, 3, 5, 6]
* [2, 3, 5, 6]
All valid answers for the second example:
* [1, 4]
* [2, 5]
* [3, 6]
All valid answers for the third example:
* [1]
* [2]
* [3]
* [4]
All valid answers for the fourth example:
* [1, 2, 3, 7, 8, 9] | instruction | 0 | 84,785 | 12 | 169,570 |
Tags: dp
Correct Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
dic={}
f=[]
for i in range(n):
if a[i]-1 in dic:
f.append(dic[a[i]-1]+1)
else:
f.append(1)
if a[i] in dic:
dic[a[i]] = max(dic[a[i]],f[i])
else:
dic[a[i]] = f[i]
ans = max(f)
print(ans)
index = f.index(ans)
now = a[index]-ans+1
# print('end =',a[index])
lis = []
for i in range(n):
if a[i]==now:
lis.append(i+1)
now = now+1
print(*lis)
``` | output | 1 | 84,785 | 12 | 169,571 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer array of length n.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not.
Input
The first line of the input containing integer number n (1 β€ n β€ 2 β
10^5) β the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
Output
On the first line print k β the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Examples
Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9
Note
All valid answers for the first example (as sequences of indices):
* [1, 3, 5, 6]
* [2, 3, 5, 6]
All valid answers for the second example:
* [1, 4]
* [2, 5]
* [3, 6]
All valid answers for the third example:
* [1]
* [2]
* [3]
* [4]
All valid answers for the fourth example:
* [1, 2, 3, 7, 8, 9] | instruction | 0 | 84,786 | 12 | 169,572 |
Tags: dp
Correct Solution:
```
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
from sys import stdin, stdout
import math
#T = int(input())
N = int(input())
#s = input()
#N,M = [int(x) for x in stdin.readline().split()]
arr = [int(x) for x in stdin.readline().split()]
res = 0
record = {}
record[arr[0]] = 1
for i in range(1,N):
num = arr[i]
if num-1 in record:
if num not in record:
record[num] = record[num-1] + 1
else:
record[num] = max(record[num-1] + 1,record[num])
else:
if num not in record:
record[num] = 1
res = 0
max_end = -1
for num in record:
res = max(res,record[num])
if record[num]==res:
max_end = num
print(res)
tmp = [0]*res
k = max_end
j = 0
for i in range(N-1,-1,-1):
if arr[i]==k:
k -= 1
tmp[j] = i+1
j += 1
if j==res:
break
tmp = tmp[::-1]
print(*tmp)
``` | output | 1 | 84,786 | 12 | 169,573 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer array of length n.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not.
Input
The first line of the input containing integer number n (1 β€ n β€ 2 β
10^5) β the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
Output
On the first line print k β the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Examples
Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9
Note
All valid answers for the first example (as sequences of indices):
* [1, 3, 5, 6]
* [2, 3, 5, 6]
All valid answers for the second example:
* [1, 4]
* [2, 5]
* [3, 6]
All valid answers for the third example:
* [1]
* [2]
* [3]
* [4]
All valid answers for the fourth example:
* [1, 2, 3, 7, 8, 9] | instruction | 0 | 84,787 | 12 | 169,574 |
Tags: dp
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
dp = dict()
for ai in a:
if ai not in dp:
dp[ai] = 0
if ai - 1 in dp:
dp[ai] = max(dp[ai], 1 + dp[ai - 1])
k = max(dp.values())
print(k + 1)
pos = -1
for ai in a:
if dp[ai] == k:
pos = ai
idx = []
for i in range(n - 1, -1, -1):
if a[i] == pos:
idx.append(i + 1)
pos -= 1
print(*idx[::-1])
``` | output | 1 | 84,787 | 12 | 169,575 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer array of length n.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not.
Input
The first line of the input containing integer number n (1 β€ n β€ 2 β
10^5) β the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
Output
On the first line print k β the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Examples
Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9
Note
All valid answers for the first example (as sequences of indices):
* [1, 3, 5, 6]
* [2, 3, 5, 6]
All valid answers for the second example:
* [1, 4]
* [2, 5]
* [3, 6]
All valid answers for the third example:
* [1]
* [2]
* [3]
* [4]
All valid answers for the fourth example:
* [1, 2, 3, 7, 8, 9] | instruction | 0 | 84,788 | 12 | 169,576 |
Tags: dp
Correct Solution:
```
n = int(input())
G = list(map(int,input().split()))
D = {}
M = 0
for i in G:
if i-1 in D:
D[i] = D[i-1] + 1
else:
D[i] = 1
if D[i]>M:
M = D[i]
Mi = i
#print(M,Mi)
R = []
A = Mi
for i in range(len(G)-1,-1,-1):
if G[i] == A:
R.append(i+1)
A-=1
print(M)
print(*R[::-1])
``` | output | 1 | 84,788 | 12 | 169,577 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer array of length n.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not.
Input
The first line of the input containing integer number n (1 β€ n β€ 2 β
10^5) β the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
Output
On the first line print k β the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Examples
Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9
Note
All valid answers for the first example (as sequences of indices):
* [1, 3, 5, 6]
* [2, 3, 5, 6]
All valid answers for the second example:
* [1, 4]
* [2, 5]
* [3, 6]
All valid answers for the third example:
* [1]
* [2]
* [3]
* [4]
All valid answers for the fourth example:
* [1, 2, 3, 7, 8, 9] | instruction | 0 | 84,789 | 12 | 169,578 |
Tags: dp
Correct Solution:
```
import sys
from collections import defaultdict
def solve(io):
N = io.readInt()
A = io.readIntArray(N)
prev = [-1] * N
size = [1] * N
last = defaultdict(lambda: -1)
for i in range(0, N):
idx = last[A[i] - 1]
if idx >= 0:
prev[i] = idx
size[i] = 1 + size[idx]
last[A[i]] = i
bestIdx = 0
for i in range(1, N):
if size[i] > size[bestIdx]:
bestIdx = i
path = []
curr = bestIdx
while curr >= 0:
path.append(curr)
curr = prev[curr]
io.println(len(path))
io.println(' '.join(str(x + 1) for x in reversed(path)))
# +---------------------+
# | TEMPLATE CODE BELOW |
# | DO NOT MODIFY |
# +---------------------+
# TODO: maybe reading byte-by-byte is faster than reading and parsing tokens.
class IO:
input = None
output = None
raw = ""
buf = []
pos = 0
def __init__(self, inputStream, outputStream):
self.input = inputStream
self.output = outputStream
def readToBuffer(self):
self.raw = self.input.readline().rstrip('\n')
self.buf = self.raw.split()
self.pos = 0
def readString(self):
while self.pos == len(self.buf):
self.readToBuffer()
ans = self.buf[self.pos]
self.pos += 1
return ans
def readInt(self):
return int(self.readString())
def readFloat(self):
return float(self.readString())
def readStringArray(self, N, offset=0):
arr = [None] * offset
for _ in range(0, N):
arr.append(self.readString())
return arr
def readIntArray(self, N, offset=0):
arr = [None] * offset
for _ in range(0, N):
arr.append(self.readInt())
return arr
def readFloatArray(self, N, offset=0):
arr = [None] * offset
for _ in range(0, N):
arr.append(self.readFloat())
return arr
def readLine(self):
while self.pos == len(self.buf):
self.readToBuffer()
if self.pos > 0:
raise ValueError("Cannot call readline in the middle of a line.")
return self.raw
def print(self, s):
self.output.write(str(s))
def println(self, s):
self.print(s)
self.print('\n')
def flushOutput(self):
self.output.flush()
pythonIO = IO(sys.stdin, sys.stdout)
solve(pythonIO)
pythonIO.flushOutput()
``` | output | 1 | 84,789 | 12 | 169,579 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer array of length n.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not.
Input
The first line of the input containing integer number n (1 β€ n β€ 2 β
10^5) β the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
Output
On the first line print k β the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Examples
Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9
Note
All valid answers for the first example (as sequences of indices):
* [1, 3, 5, 6]
* [2, 3, 5, 6]
All valid answers for the second example:
* [1, 4]
* [2, 5]
* [3, 6]
All valid answers for the third example:
* [1]
* [2]
* [3]
* [4]
All valid answers for the fourth example:
* [1, 2, 3, 7, 8, 9]
Submitted Solution:
```
n=int(input())
mp={}
values=[0 for i in range(0,n)]
lastV=-1
maxLen=0
values=list(map(int,input().split(' ')))
for i in range(0,n):
if (values[i]-1) in mp:
mp[values[i]]=mp[values[i]-1]+1
else:
mp[values[i]]=1
if mp[values[i]]>maxLen:
maxLen=mp[values[i]]
lastV=values[i]
currentValue=lastV-maxLen+1
print(maxLen)
s=""
for i in range(0,len(values)):
if values[i] == currentValue:
i2=str(i+1)+" "
s+=i2
currentValue+=1
print(s)
``` | instruction | 0 | 84,790 | 12 | 169,580 |
Yes | output | 1 | 84,790 | 12 | 169,581 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer array of length n.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not.
Input
The first line of the input containing integer number n (1 β€ n β€ 2 β
10^5) β the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
Output
On the first line print k β the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Examples
Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9
Note
All valid answers for the first example (as sequences of indices):
* [1, 3, 5, 6]
* [2, 3, 5, 6]
All valid answers for the second example:
* [1, 4]
* [2, 5]
* [3, 6]
All valid answers for the third example:
* [1]
* [2]
* [3]
* [4]
All valid answers for the fourth example:
* [1, 2, 3, 7, 8, 9]
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split()))
d = {}
for i in a:
d[i] = d.get(i-1,0)+1
e = max(d,key = d.get)
m = []
while n:
if a[n-1]==e:
m.append(n)
e-=1
n-=1
print(len(m))
print(*m[::-1])
``` | instruction | 0 | 84,791 | 12 | 169,582 |
Yes | output | 1 | 84,791 | 12 | 169,583 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer array of length n.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not.
Input
The first line of the input containing integer number n (1 β€ n β€ 2 β
10^5) β the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
Output
On the first line print k β the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Examples
Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9
Note
All valid answers for the first example (as sequences of indices):
* [1, 3, 5, 6]
* [2, 3, 5, 6]
All valid answers for the second example:
* [1, 4]
* [2, 5]
* [3, 6]
All valid answers for the third example:
* [1]
* [2]
* [3]
* [4]
All valid answers for the fourth example:
* [1, 2, 3, 7, 8, 9]
Submitted Solution:
```
n = int(input())
a = [*map(int, input().split())]
f = {}
anslist = [0] * n
for i in range(n):
try:
f[a[i]] = f[a[i] - 1] + 1
except:
f[a[i]] = 1
ans = 0
for i in f:
if ans < f[i]:
ans = f[i]
wk1 = i
print(ans)
wk1 -= ans - 1
for i in range(n):
if a[i] == wk1:
print(i + 1, end = " ")
wk1 += 1
print()
``` | instruction | 0 | 84,792 | 12 | 169,584 |
Yes | output | 1 | 84,792 | 12 | 169,585 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer array of length n.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not.
Input
The first line of the input containing integer number n (1 β€ n β€ 2 β
10^5) β the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
Output
On the first line print k β the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Examples
Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9
Note
All valid answers for the first example (as sequences of indices):
* [1, 3, 5, 6]
* [2, 3, 5, 6]
All valid answers for the second example:
* [1, 4]
* [2, 5]
* [3, 6]
All valid answers for the third example:
* [1]
* [2]
* [3]
* [4]
All valid answers for the fourth example:
* [1, 2, 3, 7, 8, 9]
Submitted Solution:
```
input()
arr = [int(i) for i in input().strip().split()]
d = {}
for i in arr:
if d.get(i, 0) + 1 > d.get(i+1, 0):
d[i+1] = d.get(i, 0) + 1
best = -1
length = 0
for key in d:
if d[key] > length:
best = key
length = d[key]
lf = best - length
print(length)
for i in range(len(arr)):
if arr[i] == lf:
print(i+1, end=" ")
length -= 1
lf += 1
if length == 0:
break
print()
``` | instruction | 0 | 84,793 | 12 | 169,586 |
Yes | output | 1 | 84,793 | 12 | 169,587 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer array of length n.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not.
Input
The first line of the input containing integer number n (1 β€ n β€ 2 β
10^5) β the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
Output
On the first line print k β the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Examples
Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9
Note
All valid answers for the first example (as sequences of indices):
* [1, 3, 5, 6]
* [2, 3, 5, 6]
All valid answers for the second example:
* [1, 4]
* [2, 5]
* [3, 6]
All valid answers for the third example:
* [1]
* [2]
* [3]
* [4]
All valid answers for the fourth example:
* [1, 2, 3, 7, 8, 9]
Submitted Solution:
```
from collections import Counter
def read_nums():
return [int(x) for x in input().split()]
def main():
n, = read_nums()
nums = read_nums()
dp = Counter()
for i in range(n):
dp[nums[i]] = dp[nums[i] - 1] + 1
indexes = {}
for i in range(n):
indexes[nums[i]] = i
last_num = max(dp.items(), key=lambda x: x[1])[0]
last_index = indexes[last_num]
result = [last_index]
while True:
last_num -= 1
if last_num not in indexes or indexes[last_num] > last_index:
break
last_index = indexes[last_num]
result.append(last_index)
result.reverse()
print(len(result))
print(' '.join([str(x + 1) for x in result]))
if __name__ == '__main__':
main()
``` | instruction | 0 | 84,794 | 12 | 169,588 |
No | output | 1 | 84,794 | 12 | 169,589 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer array of length n.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not.
Input
The first line of the input containing integer number n (1 β€ n β€ 2 β
10^5) β the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
Output
On the first line print k β the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Examples
Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9
Note
All valid answers for the first example (as sequences of indices):
* [1, 3, 5, 6]
* [2, 3, 5, 6]
All valid answers for the second example:
* [1, 4]
* [2, 5]
* [3, 6]
All valid answers for the third example:
* [1]
* [2]
* [3]
* [4]
All valid answers for the fourth example:
* [1, 2, 3, 7, 8, 9]
Submitted Solution:
```
import bisect
n=int(input())
a=list(map(int,input().split()))
d1={}
d2={}
dp=[0]*(n)
for i in range(n):
if a[i]-1 in d1:
d1[a[i]]=i
d2[a[i]]=d1[a[i]-1]
dp[i]=dp[d1[a[i]-1]]+1
else:
d1[a[i]]=i
d2[a[i]]=-1
dp[i]=1
el,ind=max(((j,i) for i,j in enumerate(dp)))
lis=[0]*(max(dp))
lis[-1]=ind+1
print(el)
for i in range(len(lis)-2,-1,-1):
lis[i]=d2[a[lis[i+1]-1]]+1
print(*lis)
``` | instruction | 0 | 84,795 | 12 | 169,590 |
No | output | 1 | 84,795 | 12 | 169,591 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer array of length n.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not.
Input
The first line of the input containing integer number n (1 β€ n β€ 2 β
10^5) β the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
Output
On the first line print k β the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Examples
Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9
Note
All valid answers for the first example (as sequences of indices):
* [1, 3, 5, 6]
* [2, 3, 5, 6]
All valid answers for the second example:
* [1, 4]
* [2, 5]
* [3, 6]
All valid answers for the third example:
* [1]
* [2]
* [3]
* [4]
All valid answers for the fourth example:
* [1, 2, 3, 7, 8, 9]
Submitted Solution:
```
n = int(input())
temp = input()
a = [int(x) for x in temp.split()]
best = dict()
seq = dict()
recur = dict()
best.update({a[0]:1})
#seq.update({a[0]:['1']})
recur.update({a[0]:(a[0],1)})
for i in range(1,n):
if a[i]-1 in best:
best.update({a[i]:best[a[i]-1]+1})
#seq.update({a[i]:seq[a[i]-1]+[str(i+1)]})
recur.update({a[i]:(a[i]-1,i+1)})
#print(recur)
else:
best.update({a[i]:1})
#seq.update({a[i]:[str(i+1)]})
recur.update({a[i]:(a[i],i+1)})
#print(recur)
ind=0
val=0
for key,value in best.items():
if value>val:
ind=key
val=value
print(val)
seq = []
start = ind
while(recur[start][0]!=start):
#print(start,recur[start][0])
seq.append(recur[start][1])
start = recur[start][0]
seq.append(recur[start][1])
#print(seq)
seq.reverse()
seq=list(map(str, seq))
print(' '.join(seq))
``` | instruction | 0 | 84,796 | 12 | 169,592 |
No | output | 1 | 84,796 | 12 | 169,593 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer array of length n.
You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k.
Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5, 3, 1, 2, 4] the following arrays are subsequences: [3], [5, 3, 1, 2, 4], [5, 1, 4], but the array [1, 3] is not.
Input
The first line of the input containing integer number n (1 β€ n β€ 2 β
10^5) β the length of the array. The second line of the input containing n integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the array itself.
Output
On the first line print k β the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.
On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
Examples
Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9
Note
All valid answers for the first example (as sequences of indices):
* [1, 3, 5, 6]
* [2, 3, 5, 6]
All valid answers for the second example:
* [1, 4]
* [2, 5]
* [3, 6]
All valid answers for the third example:
* [1]
* [2]
* [3]
* [4]
All valid answers for the fourth example:
* [1, 2, 3, 7, 8, 9]
Submitted Solution:
```
print("a")
print("a")
print("a")
print("a")
print("a")
``` | instruction | 0 | 84,797 | 12 | 169,594 |
No | output | 1 | 84,797 | 12 | 169,595 |
Provide a correct Python 3 solution for this coding contest problem.
For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order.
Constraints
* $1 \leq n \leq 9$
* $a_i$ consist of $1, 2, ..., n$
Input
A sequence is given in the following format.
$n$
$a_0 \; a_1 \; ... \; a_{n-1}$
Output
Print the previous permutation, the given sequence and the next permutation in the 1st, 2nd and 3rd lines respectively. Separate adjacency elements by a space character. Note that if there is no permutation, print nothing in the corresponding line.
Examples
Input
3
2 1 3
Output
1 3 2
2 1 3
2 3 1
Input
3
3 2 1
Output
3 1 2
3 2 1 | instruction | 0 | 84,996 | 12 | 169,992 |
"Correct Solution:
```
from itertools import permutations
n = int(input())
arr = tuple(map(int, input().split()))
p = list(permutations(sorted(arr)))
idx = p.index(arr)
for i in range(max(0, idx - 1), min(len(p), idx + 2), 1):
print(*p[i])
``` | output | 1 | 84,996 | 12 | 169,993 |
Provide a correct Python 3 solution for this coding contest problem.
For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order.
Constraints
* $1 \leq n \leq 9$
* $a_i$ consist of $1, 2, ..., n$
Input
A sequence is given in the following format.
$n$
$a_0 \; a_1 \; ... \; a_{n-1}$
Output
Print the previous permutation, the given sequence and the next permutation in the 1st, 2nd and 3rd lines respectively. Separate adjacency elements by a space character. Note that if there is no permutation, print nothing in the corresponding line.
Examples
Input
3
2 1 3
Output
1 3 2
2 1 3
2 3 1
Input
3
3 2 1
Output
3 1 2
3 2 1 | instruction | 0 | 84,997 | 12 | 169,994 |
"Correct Solution:
```
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
N = int(input())
table = [None] * N
check = [False] * (N+1)
MAP = {}
rev_MAP = {}
perm_index = 0
def recursive(index):
global perm_index
if index == N:
tmp = 0
for i in range(N):
tmp = 10*tmp+table[i]
MAP[perm_index] = tmp
rev_MAP[tmp] = perm_index
perm_index += 1
return
for i in range(1,(N+1)):
if check[i]:
continue
check[i] = True
table[index] = i
recursive(index+1)
check[i] = False
def outPut(num):
S = deque()
while True:
S.appendleft(num%10)
num //= 10
if num == 0:
break
print("%d"%(S.popleft()),end="")
while len(S) > 0:
print(" %d"%(S.popleft()),end="")
print()
recursive(0)
tmp = 0
for i in list(map(int,input().split())):
tmp = 10*tmp+i
index = rev_MAP[tmp]
if index > 0:
outPut(MAP[index-1])
outPut(tmp)
if index+1 in MAP:
outPut(MAP[index+1])
``` | output | 1 | 84,997 | 12 | 169,995 |
Provide a correct Python 3 solution for this coding contest problem.
For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order.
Constraints
* $1 \leq n \leq 9$
* $a_i$ consist of $1, 2, ..., n$
Input
A sequence is given in the following format.
$n$
$a_0 \; a_1 \; ... \; a_{n-1}$
Output
Print the previous permutation, the given sequence and the next permutation in the 1st, 2nd and 3rd lines respectively. Separate adjacency elements by a space character. Note that if there is no permutation, print nothing in the corresponding line.
Examples
Input
3
2 1 3
Output
1 3 2
2 1 3
2 3 1
Input
3
3 2 1
Output
3 1 2
3 2 1 | instruction | 0 | 84,998 | 12 | 169,996 |
"Correct Solution:
```
import itertools
n = int(input())
num = list(map(int, input().split()))
per = list(itertools.permutations(num))
per.sort()
index = per.index(tuple(num))
if index != 0:
print(' '.join(str(n) for n in per[index-1]))
print(' '.join(str(n) for n in per[index]))
if index != len(per)-1:
print(' '.join(str(n) for n in per[index+1]))
``` | output | 1 | 84,998 | 12 | 169,997 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.