message stringlengths 2 48.6k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 318 108k | cluster float64 8 8 | __index_level_0__ int64 636 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 1 to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains 3 steps, and the second contains 4 steps, she will pronounce the numbers 1, 2, 3, 1, 2, 3, 4.
You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Input
The first line contains n (1 β€ n β€ 1000) β the total number of numbers pronounced by Tanya.
The second line contains integers a_1, a_2, ..., a_n (1 β€ a_i β€ 1000) β all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with x steps, she will pronounce the numbers 1, 2, ..., x in that order.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Output
In the first line, output t β the number of stairways that Tanya climbed. In the second line, output t numbers β the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
Examples
Input
7
1 2 3 1 2 3 4
Output
2
3 4
Input
4
1 1 1 1
Output
4
1 1 1 1
Input
5
1 2 3 4 5
Output
1
5
Input
5
1 2 1 2 1
Output
3
2 2 1 | instruction | 0 | 78,282 | 8 | 156,564 |
Tags: implementation
Correct Solution:
```
n=int(input())
s=list(map(int,input().split()))
last=0
x=[]
for i in range(1,n):
if s[i]==1:
x.append(i-last)
last=i
x.append(n-last)
print(len(x))
print(*x)
``` | output | 1 | 78,282 | 8 | 156,565 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 1 to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains 3 steps, and the second contains 4 steps, she will pronounce the numbers 1, 2, 3, 1, 2, 3, 4.
You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Input
The first line contains n (1 β€ n β€ 1000) β the total number of numbers pronounced by Tanya.
The second line contains integers a_1, a_2, ..., a_n (1 β€ a_i β€ 1000) β all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with x steps, she will pronounce the numbers 1, 2, ..., x in that order.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Output
In the first line, output t β the number of stairways that Tanya climbed. In the second line, output t numbers β the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
Examples
Input
7
1 2 3 1 2 3 4
Output
2
3 4
Input
4
1 1 1 1
Output
4
1 1 1 1
Input
5
1 2 3 4 5
Output
1
5
Input
5
1 2 1 2 1
Output
3
2 2 1
Submitted Solution:
```
a = int(input())
b = list(map(lambda x: int(x), input().split()))
t = []
for i in range(1, a):
if b[i] <= b[i-1]:
t.append(str(b[i-1]))
t.append(str(b[-1]))
print(len(t))
print(' '.join(t))
``` | instruction | 0 | 78,283 | 8 | 156,566 |
Yes | output | 1 | 78,283 | 8 | 156,567 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 1 to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains 3 steps, and the second contains 4 steps, she will pronounce the numbers 1, 2, 3, 1, 2, 3, 4.
You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Input
The first line contains n (1 β€ n β€ 1000) β the total number of numbers pronounced by Tanya.
The second line contains integers a_1, a_2, ..., a_n (1 β€ a_i β€ 1000) β all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with x steps, she will pronounce the numbers 1, 2, ..., x in that order.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Output
In the first line, output t β the number of stairways that Tanya climbed. In the second line, output t numbers β the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
Examples
Input
7
1 2 3 1 2 3 4
Output
2
3 4
Input
4
1 1 1 1
Output
4
1 1 1 1
Input
5
1 2 3 4 5
Output
1
5
Input
5
1 2 1 2 1
Output
3
2 2 1
Submitted Solution:
```
n=int(input())
arr=list(map(int,input().split()))
res=[]
for i in range(len(arr)-1):
if arr[i+1]==1:
res.append(arr[i])
res.append(arr[-1])
print(len(res))
print(*res)
``` | instruction | 0 | 78,284 | 8 | 156,568 |
Yes | output | 1 | 78,284 | 8 | 156,569 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 1 to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains 3 steps, and the second contains 4 steps, she will pronounce the numbers 1, 2, 3, 1, 2, 3, 4.
You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Input
The first line contains n (1 β€ n β€ 1000) β the total number of numbers pronounced by Tanya.
The second line contains integers a_1, a_2, ..., a_n (1 β€ a_i β€ 1000) β all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with x steps, she will pronounce the numbers 1, 2, ..., x in that order.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Output
In the first line, output t β the number of stairways that Tanya climbed. In the second line, output t numbers β the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
Examples
Input
7
1 2 3 1 2 3 4
Output
2
3 4
Input
4
1 1 1 1
Output
4
1 1 1 1
Input
5
1 2 3 4 5
Output
1
5
Input
5
1 2 1 2 1
Output
3
2 2 1
Submitted Solution:
```
n=int(input())
a=input().split()
ans=[]
print(a.count('1'))
for i in range(1,n):
if a[i]=='1':
ans.append(a[i-1])
ans.append(a[n-1])
for i in range(len(ans)):
#ans[i]=int(ans[i])
print(ans[i], end=' ')
``` | instruction | 0 | 78,285 | 8 | 156,570 |
Yes | output | 1 | 78,285 | 8 | 156,571 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 1 to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains 3 steps, and the second contains 4 steps, she will pronounce the numbers 1, 2, 3, 1, 2, 3, 4.
You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Input
The first line contains n (1 β€ n β€ 1000) β the total number of numbers pronounced by Tanya.
The second line contains integers a_1, a_2, ..., a_n (1 β€ a_i β€ 1000) β all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with x steps, she will pronounce the numbers 1, 2, ..., x in that order.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Output
In the first line, output t β the number of stairways that Tanya climbed. In the second line, output t numbers β the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
Examples
Input
7
1 2 3 1 2 3 4
Output
2
3 4
Input
4
1 1 1 1
Output
4
1 1 1 1
Input
5
1 2 3 4 5
Output
1
5
Input
5
1 2 1 2 1
Output
3
2 2 1
Submitted Solution:
```
n=int(input())
l=list(map(int,input().split()))
ans=[]
for i in range(1,len(l)):
if l[i]<=l[i-1]:
ans.append(l[i-1])
ans.append(l[-1])
print(len(ans))
print(*ans)
``` | instruction | 0 | 78,286 | 8 | 156,572 |
Yes | output | 1 | 78,286 | 8 | 156,573 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 1 to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains 3 steps, and the second contains 4 steps, she will pronounce the numbers 1, 2, 3, 1, 2, 3, 4.
You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Input
The first line contains n (1 β€ n β€ 1000) β the total number of numbers pronounced by Tanya.
The second line contains integers a_1, a_2, ..., a_n (1 β€ a_i β€ 1000) β all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with x steps, she will pronounce the numbers 1, 2, ..., x in that order.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Output
In the first line, output t β the number of stairways that Tanya climbed. In the second line, output t numbers β the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
Examples
Input
7
1 2 3 1 2 3 4
Output
2
3 4
Input
4
1 1 1 1
Output
4
1 1 1 1
Input
5
1 2 3 4 5
Output
1
5
Input
5
1 2 1 2 1
Output
3
2 2 1
Submitted Solution:
```
n = int(input())
cnt = 0
ans = []
st = str(input()).split(' ')
for i in range(1, n):
if (st[i] <= st[i-1]):
cnt = cnt + 1
ans.append(st[i-1])
cnt = cnt + 1
ans.append(st[n-1])
print(cnt)
for x in ans:
print(x, end=' ')
``` | instruction | 0 | 78,287 | 8 | 156,574 |
No | output | 1 | 78,287 | 8 | 156,575 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 1 to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains 3 steps, and the second contains 4 steps, she will pronounce the numbers 1, 2, 3, 1, 2, 3, 4.
You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Input
The first line contains n (1 β€ n β€ 1000) β the total number of numbers pronounced by Tanya.
The second line contains integers a_1, a_2, ..., a_n (1 β€ a_i β€ 1000) β all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with x steps, she will pronounce the numbers 1, 2, ..., x in that order.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Output
In the first line, output t β the number of stairways that Tanya climbed. In the second line, output t numbers β the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
Examples
Input
7
1 2 3 1 2 3 4
Output
2
3 4
Input
4
1 1 1 1
Output
4
1 1 1 1
Input
5
1 2 3 4 5
Output
1
5
Input
5
1 2 1 2 1
Output
3
2 2 1
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
t = 0
k = ''
for i in range(1,n):
if a[i] == 1:
t += 1
k += str((a[i-1]))
print(t+1)
print(' '.join(k),a[-1])
``` | instruction | 0 | 78,288 | 8 | 156,576 |
No | output | 1 | 78,288 | 8 | 156,577 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 1 to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains 3 steps, and the second contains 4 steps, she will pronounce the numbers 1, 2, 3, 1, 2, 3, 4.
You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Input
The first line contains n (1 β€ n β€ 1000) β the total number of numbers pronounced by Tanya.
The second line contains integers a_1, a_2, ..., a_n (1 β€ a_i β€ 1000) β all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with x steps, she will pronounce the numbers 1, 2, ..., x in that order.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Output
In the first line, output t β the number of stairways that Tanya climbed. In the second line, output t numbers β the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
Examples
Input
7
1 2 3 1 2 3 4
Output
2
3 4
Input
4
1 1 1 1
Output
4
1 1 1 1
Input
5
1 2 3 4 5
Output
1
5
Input
5
1 2 1 2 1
Output
3
2 2 1
Submitted Solution:
```
count = 0
c = []
a = int(input())
b = list(map(int, input().split()))
for i in range(len(b)):
if b[i] == 1:
count += 1
c.append(b[i-1])
print(count)
c.reverse()
print(*c)
``` | instruction | 0 | 78,289 | 8 | 156,578 |
No | output | 1 | 78,289 | 8 | 156,579 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 1 to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains 3 steps, and the second contains 4 steps, she will pronounce the numbers 1, 2, 3, 1, 2, 3, 4.
You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Input
The first line contains n (1 β€ n β€ 1000) β the total number of numbers pronounced by Tanya.
The second line contains integers a_1, a_2, ..., a_n (1 β€ a_i β€ 1000) β all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with x steps, she will pronounce the numbers 1, 2, ..., x in that order.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Output
In the first line, output t β the number of stairways that Tanya climbed. In the second line, output t numbers β the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
Examples
Input
7
1 2 3 1 2 3 4
Output
2
3 4
Input
4
1 1 1 1
Output
4
1 1 1 1
Input
5
1 2 3 4 5
Output
1
5
Input
5
1 2 1 2 1
Output
3
2 2 1
Submitted Solution:
```
t = int(input())
count = list(map(int,input().split(" ")))
stairways = 0
steps = list()
x = 0
for i in range(t) :
if count[i] == 1 and x != 0:
steps.append(x)
stairways += 1
x = 1
else :
x += 1
print(stairways)
print(*steps)
``` | instruction | 0 | 78,290 | 8 | 156,580 |
No | output | 1 | 78,290 | 8 | 156,581 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of type x + 1, and all chests of type 1 are not locked. There is exactly one chest of type p and it contains a treasure.
Vanya starts in cell (1, 1) (top left corner). What is the minimum total distance Vanya has to walk in order to get the treasure? Consider the distance between cell (r1, c1) (the cell in the row r1 and column c1) and (r2, c2) is equal to |r1 - r2| + |c1 - c2|.
Input
The first line of the input contains three integers n, m and p (1 β€ n, m β€ 300, 1 β€ p β€ nΒ·m) β the number of rows and columns in the table representing the palace and the number of different types of the chests, respectively.
Each of the following n lines contains m integers aij (1 β€ aij β€ p) β the types of the chests in corresponding rooms. It's guaranteed that for each x from 1 to p there is at least one chest of this type (that is, there exists a pair of r and c, such that arc = x). Also, it's guaranteed that there is exactly one chest of type p.
Output
Print one integer β the minimum possible total distance Vanya has to walk in order to get the treasure from the chest of type p.
Examples
Input
3 4 3
2 1 1 1
1 1 1 1
2 1 1 3
Output
5
Input
3 3 9
1 3 5
8 9 7
4 6 2
Output
22
Input
3 4 12
1 2 3 4
8 7 6 5
9 10 11 12
Output
11
Submitted Solution:
```
INF = 1000000000000
class V:
def __init__(self, x, y, t):
self.x = x
self.y = y
self.t = t
def __lt__(self, rhs):
return self.t < rhs.t
def __str__(self):
return str(self.x) + ", " + str(self.y) + ", " + str(self.t)
def S(v1, v2):
return abs(v1.x - v2.x) + abs(v1.y - v2.y)
def dejkstra(N, S, F, C):
f = [True] * N
w = [INF] * N
w[S] = 0
for i in range(N):
mw = INF + 1
mi = -1
for i in range(len(w)):
if (f[i]) and (w[i] < mw):
mw = w[i]
mi = i
for i in range(N):
if w[mi] + C[mi][i] < w[i]:
w[i] = w[mi] + C[mi][i]
f[mi] = False
return w[F]
h, w, p = map(int, input().split())
t = [list(map(int, input().split())) for i in range(h)]
v = [V(0, 0, t[0][0])]
for y in range(h):
for x in range(w):
if (t[y][x] > t[0][0]) and (t[y][x] <= p):
v += [V(x, y, t[y][x])]
v.sort()
#for i in v:
# print(i)
N = len(v)
C = [[INF] * N for i in range(N)]
for i in range(N):
for j in range(N):
if v[j].t - v[i].t == 1:
C[i][j] = S(v[i], v[j])
#for i in range(N):
# print(C[i])
print(dejkstra(N, 0, N - 1, C))
``` | instruction | 0 | 78,729 | 8 | 157,458 |
No | output | 1 | 78,729 | 8 | 157,459 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of type x + 1, and all chests of type 1 are not locked. There is exactly one chest of type p and it contains a treasure.
Vanya starts in cell (1, 1) (top left corner). What is the minimum total distance Vanya has to walk in order to get the treasure? Consider the distance between cell (r1, c1) (the cell in the row r1 and column c1) and (r2, c2) is equal to |r1 - r2| + |c1 - c2|.
Input
The first line of the input contains three integers n, m and p (1 β€ n, m β€ 300, 1 β€ p β€ nΒ·m) β the number of rows and columns in the table representing the palace and the number of different types of the chests, respectively.
Each of the following n lines contains m integers aij (1 β€ aij β€ p) β the types of the chests in corresponding rooms. It's guaranteed that for each x from 1 to p there is at least one chest of this type (that is, there exists a pair of r and c, such that arc = x). Also, it's guaranteed that there is exactly one chest of type p.
Output
Print one integer β the minimum possible total distance Vanya has to walk in order to get the treasure from the chest of type p.
Examples
Input
3 4 3
2 1 1 1
1 1 1 1
2 1 1 3
Output
5
Input
3 3 9
1 3 5
8 9 7
4 6 2
Output
22
Input
3 4 12
1 2 3 4
8 7 6 5
9 10 11 12
Output
11
Submitted Solution:
```
def distance(a, b):
return abs(a[0] - b[0]) + abs(a[1] - b[1])
n, m, p = map(int, input().split())
a = [[] for _ in range(n)]
types = [[] for _ in range(p)]
for i in range(n):
a[i] = list(map(int, input().split()))
for j in range(m):
if a[i][j] == p:
target = (i, j)
elif a[i][j] < p:
types[a[i][j]].append((i, j))
dp = [[1000000000 for _ in range(len(types[i]))] for i in range(len(types))]
start = a[0][0]
for i in range(len(types[p - 1])):
dp[p - 1][i] = distance(types[p - 1][i], target)
for level in range(p - 2, start, -1):
for i in range(len(types[level])):
for j in range(len(types[level + 1])):
dp[level][i] = min(dp[level][i], distance(types[level][i], types[level + 1][j]) + dp[level + 1][j])
if start == p:
ans = 0
elif start == p - 1:
ans = distance((0, 0), target)
else:
ans = min(distance((0, 0), types[start + 1][i]) + dp[start + 1][i] for i in range(len(types[start + 1])))
print(ans)
``` | instruction | 0 | 78,730 | 8 | 157,460 |
No | output | 1 | 78,730 | 8 | 157,461 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of type x + 1, and all chests of type 1 are not locked. There is exactly one chest of type p and it contains a treasure.
Vanya starts in cell (1, 1) (top left corner). What is the minimum total distance Vanya has to walk in order to get the treasure? Consider the distance between cell (r1, c1) (the cell in the row r1 and column c1) and (r2, c2) is equal to |r1 - r2| + |c1 - c2|.
Input
The first line of the input contains three integers n, m and p (1 β€ n, m β€ 300, 1 β€ p β€ nΒ·m) β the number of rows and columns in the table representing the palace and the number of different types of the chests, respectively.
Each of the following n lines contains m integers aij (1 β€ aij β€ p) β the types of the chests in corresponding rooms. It's guaranteed that for each x from 1 to p there is at least one chest of this type (that is, there exists a pair of r and c, such that arc = x). Also, it's guaranteed that there is exactly one chest of type p.
Output
Print one integer β the minimum possible total distance Vanya has to walk in order to get the treasure from the chest of type p.
Examples
Input
3 4 3
2 1 1 1
1 1 1 1
2 1 1 3
Output
5
Input
3 3 9
1 3 5
8 9 7
4 6 2
Output
22
Input
3 4 12
1 2 3 4
8 7 6 5
9 10 11 12
Output
11
Submitted Solution:
```
import math
def get_dist(a, b):
return(int(math.fabs(a[0]-b[0])+math.fabs(a[1]-b[1])+vis[a[0]][a[1]]))
n,m,p=map(int,input().split())
d=[list(map(int,input().split())) for i in range(n)]
vis=[[0 for i in range(m)]
for j in range(n)]
used=[[] for i in range(p+1)]
used[0]=[(0,0)]
for i in range(n):
for j in range(m):
used[d[i][j]].append((i,j))
for i in range(1, p+1):
for j in range(len(used[i])):
x=used[i][j][0]
y=used[i][j][1]
x1=used[i-1][0][0]
y1=used[i-1][0][1]
vis[x][y]=get_dist((x,y),(x1,y1))
for k in range(1, len(used[i-1])):
x1=used[i-1][k][0]
y1=used[i-1][k][1]
vis[x][y]=min(vis[x][y], get_dist((x,y),(x1,y1)))
x=used[-1][0][0]
y=used[-1][0][1]
print(vis[x][y])
``` | instruction | 0 | 78,731 | 8 | 157,462 |
No | output | 1 | 78,731 | 8 | 157,463 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of type x + 1, and all chests of type 1 are not locked. There is exactly one chest of type p and it contains a treasure.
Vanya starts in cell (1, 1) (top left corner). What is the minimum total distance Vanya has to walk in order to get the treasure? Consider the distance between cell (r1, c1) (the cell in the row r1 and column c1) and (r2, c2) is equal to |r1 - r2| + |c1 - c2|.
Input
The first line of the input contains three integers n, m and p (1 β€ n, m β€ 300, 1 β€ p β€ nΒ·m) β the number of rows and columns in the table representing the palace and the number of different types of the chests, respectively.
Each of the following n lines contains m integers aij (1 β€ aij β€ p) β the types of the chests in corresponding rooms. It's guaranteed that for each x from 1 to p there is at least one chest of this type (that is, there exists a pair of r and c, such that arc = x). Also, it's guaranteed that there is exactly one chest of type p.
Output
Print one integer β the minimum possible total distance Vanya has to walk in order to get the treasure from the chest of type p.
Examples
Input
3 4 3
2 1 1 1
1 1 1 1
2 1 1 3
Output
5
Input
3 3 9
1 3 5
8 9 7
4 6 2
Output
22
Input
3 4 12
1 2 3 4
8 7 6 5
9 10 11 12
Output
11
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
from collections import deque
import heapq
from collections import Counter
for _ in range(1):
#n=int(input())
n,m,p=map(int, input().split())
g=[[] for i in range(n*m+1)]
for i in range(n):
arr=list(map(int, input().split()))
for j in range(m):
g[arr[j]].append([i,j,arr[j]])
g[0]=[0,0,0]
ans=10**20
q=deque([])
q.append([0,0,0])
val=1
while val<=p:
x,y,amt=q[0]
#q.pop()
qq=[]
for i in (g[val]):
ma = 10 ** 20
for j in q:
ma=min(ma,amt+abs(i[0]-j[0])+abs(i[1]-j[1]))
if val == p:
ans=min(ans,ma)
else:
qq.append([i[0],i[1],ma])
q=qq
val+=1
print(ans)
``` | instruction | 0 | 78,732 | 8 | 157,464 |
No | output | 1 | 78,732 | 8 | 157,465 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
<image>
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input
The first line contains single integer n (1 β€ n β€ 100 000) β the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Examples
Input
3
3 1 2
Output
3
Β
2 1
Input
5
4 5 1 2 3
Output
Β
5 4
Β
Β
3 2 1
Note
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before. | instruction | 0 | 78,774 | 8 | 157,548 |
Tags: data structures, implementation
Correct Solution:
```
n, s = int(input()), set()
for a in map(int, input().split()):
s.add(a)
while True:
try:
s.remove(n)
except KeyError:
print()
break
else:
print(n, end=' ')
n -= 1
``` | output | 1 | 78,774 | 8 | 157,549 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
<image>
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input
The first line contains single integer n (1 β€ n β€ 100 000) β the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Examples
Input
3
3 1 2
Output
3
Β
2 1
Input
5
4 5 1 2 3
Output
Β
5 4
Β
Β
3 2 1
Note
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before. | instruction | 0 | 78,775 | 8 | 157,550 |
Tags: data structures, implementation
Correct Solution:
```
n, s = int(input()), set()
for a in map(int,input().split()):
s.add(a)
while n in s:
print(n, end=' ')
n -= 1
print()
``` | output | 1 | 78,775 | 8 | 157,551 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
<image>
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input
The first line contains single integer n (1 β€ n β€ 100 000) β the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Examples
Input
3
3 1 2
Output
3
Β
2 1
Input
5
4 5 1 2 3
Output
Β
5 4
Β
Β
3 2 1
Note
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before. | instruction | 0 | 78,776 | 8 | 157,552 |
Tags: data structures, implementation
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
t=n
for i in range(n):
a[abs(a[i])-1]=-1*(a[abs(a[i])-1])
if(abs(a[i])==t):
print(t,end=" ")
t=t-1
for j in range(t-1,-1,-1):
if(a[j]<0):
print(t,end=" ")
t=t-1
else:
print()
break
else:
print()
``` | output | 1 | 78,776 | 8 | 157,553 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
<image>
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input
The first line contains single integer n (1 β€ n β€ 100 000) β the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Examples
Input
3
3 1 2
Output
3
Β
2 1
Input
5
4 5 1 2 3
Output
Β
5 4
Β
Β
3 2 1
Note
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before. | instruction | 0 | 78,777 | 8 | 157,554 |
Tags: data structures, implementation
Correct Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
A = list(map(int, input().split()))
V = [False] * (n + 1)
p = n
for i in range(n):
V[A[i]] = True
p0 = p
while V[p]:
print(p, end=' ')
p -= 1
print()
``` | output | 1 | 78,777 | 8 | 157,555 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
<image>
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input
The first line contains single integer n (1 β€ n β€ 100 000) β the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Examples
Input
3
3 1 2
Output
3
Β
2 1
Input
5
4 5 1 2 3
Output
Β
5 4
Β
Β
3 2 1
Note
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before. | instruction | 0 | 78,778 | 8 | 157,556 |
Tags: data structures, implementation
Correct Solution:
```
import sys
n = int(input())
a = list(map(int, input().split()))
b = list(reversed(sorted(a)))
has = set()
l = 0
for i in range(n):
if a[i] == b[l]:
has.add(a[i])
while l < n and b[l] in has :
print(b[l], end = ' ')
l += 1
print()
else:
has.add(a[i])
print()
``` | output | 1 | 78,778 | 8 | 157,557 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
<image>
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input
The first line contains single integer n (1 β€ n β€ 100 000) β the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Examples
Input
3
3 1 2
Output
3
Β
2 1
Input
5
4 5 1 2 3
Output
Β
5 4
Β
Β
3 2 1
Note
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before. | instruction | 0 | 78,779 | 8 | 157,558 |
Tags: data structures, implementation
Correct Solution:
```
n = int(input())
A = list(map(int,input().split()))
B = [0] * (n + 1)
k = n
for i in range(n):
B[A[i]] = 1
if A[i] == k:
while B[k] == 1:
print(k,end = ' ')
k -= 1
print()
else:
print( )
``` | output | 1 | 78,779 | 8 | 157,559 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
<image>
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input
The first line contains single integer n (1 β€ n β€ 100 000) β the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Examples
Input
3
3 1 2
Output
3
Β
2 1
Input
5
4 5 1 2 3
Output
Β
5 4
Β
Β
3 2 1
Note
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before. | instruction | 0 | 78,780 | 8 | 157,560 |
Tags: data structures, implementation
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
t = [False]*n
t_idx = n-1
for idx, value in enumerate(a):
t[value-1] = True
cur_res = []
while t[t_idx]:
cur_res.append(t_idx+1)
t_idx -= 1
if t_idx == -1:
break
print(*cur_res)
``` | output | 1 | 78,780 | 8 | 157,561 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
<image>
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input
The first line contains single integer n (1 β€ n β€ 100 000) β the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Examples
Input
3
3 1 2
Output
3
Β
2 1
Input
5
4 5 1 2 3
Output
Β
5 4
Β
Β
3 2 1
Note
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before. | instruction | 0 | 78,781 | 8 | 157,562 |
Tags: data structures, implementation
Correct Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
snacks = map(int, input().split())
status = [False] * (n + 1)
biggest = n
for day, snack in enumerate(snacks):
status[snack] = True
ret = ''
if biggest == snack:
biggest -= 1
while status[biggest] and biggest >= 1:
biggest -= 1
ret_list = list(range(biggest + 1, snack + 1))
ret = ' '.join(map(str, reversed(ret_list)))
print(ret)
``` | output | 1 | 78,781 | 8 | 157,563 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
<image>
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input
The first line contains single integer n (1 β€ n β€ 100 000) β the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Examples
Input
3
3 1 2
Output
3
Β
2 1
Input
5
4 5 1 2 3
Output
Β
5 4
Β
Β
3 2 1
Note
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
Submitted Solution:
```
n=int(input())
l=list(map(int , input().split()))
h=[]
k=[0]*(n+1)
s=n
for i in l:
k[i]=1
a=i
h1=[]
while a==s and k[a]==1:
h1.append(s)
a-=1
s-=1
h.append(h1)
for i in range (len(h)):
for j in range (len(h[i])):
print (h[i][j],end=' ')
print()
``` | instruction | 0 | 78,782 | 8 | 157,564 |
Yes | output | 1 | 78,782 | 8 | 157,565 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
<image>
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input
The first line contains single integer n (1 β€ n β€ 100 000) β the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Examples
Input
3
3 1 2
Output
3
Β
2 1
Input
5
4 5 1 2 3
Output
Β
5 4
Β
Β
3 2 1
Note
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
Submitted Solution:
```
from sys import stdin
input=stdin.readline
# return len(arr)-1
a=input()
arr=list(map(int,input().strip().split()))
cmax=len(arr)
stack=[0]*(len(arr)+2)
n=len(arr)
for i in arr:
stack[i]=1
while stack[n]:
print(n,end=" ")
n-=1
print("")
``` | instruction | 0 | 78,783 | 8 | 157,566 |
Yes | output | 1 | 78,783 | 8 | 157,567 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
<image>
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input
The first line contains single integer n (1 β€ n β€ 100 000) β the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Examples
Input
3
3 1 2
Output
3
Β
2 1
Input
5
4 5 1 2 3
Output
Β
5 4
Β
Β
3 2 1
Note
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
Submitted Solution:
```
n=int(input())
l=list(map(int,input().split()))
s=set()
x=n
for i in range(n):
s.add(l[i])
while x in s:
print(x,end=' ')
x-=1
print()
``` | instruction | 0 | 78,784 | 8 | 157,568 |
Yes | output | 1 | 78,784 | 8 | 157,569 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
<image>
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input
The first line contains single integer n (1 β€ n β€ 100 000) β the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Examples
Input
3
3 1 2
Output
3
Β
2 1
Input
5
4 5 1 2 3
Output
Β
5 4
Β
Β
3 2 1
Note
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
Submitted Solution:
```
# coding: utf-8
n = int(input())
a_s = map(int, input().split())
ad = {a:i for i, a in enumerate(a_s)}
cd = 0
st = []
for i in range(n, 0, -1):
if ad[i] > cd:
print(" ".join(st), end="")
st = []
print("\n" * (ad[i] - cd), end="")
cd = ad[i]
st.append(str(i))
print(" ".join(st))
``` | instruction | 0 | 78,785 | 8 | 157,570 |
Yes | output | 1 | 78,785 | 8 | 157,571 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
<image>
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input
The first line contains single integer n (1 β€ n β€ 100 000) β the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Examples
Input
3
3 1 2
Output
3
Β
2 1
Input
5
4 5 1 2 3
Output
Β
5 4
Β
Β
3 2 1
Note
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
Submitted Solution:
```
from sys import stdin
n = int(input())
a = []
line = input()
a.extend([int(x) for x in line.split()])
q = n
l = n
r = n
i = 0
ans = []
while i < n:
if a[i] == q:
ans.append([l, r])
q = l - 1
l = r = q
elif a[i] < q:
ans.append([])
l = min(l, a[i])
i += 1
for p in ans:
if not p:
print('')
else:
for i in range(p[1], p[0]-1, -1):
print(i, end=' ')
print('')
``` | instruction | 0 | 78,786 | 8 | 157,572 |
No | output | 1 | 78,786 | 8 | 157,573 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
<image>
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input
The first line contains single integer n (1 β€ n β€ 100 000) β the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Examples
Input
3
3 1 2
Output
3
Β
2 1
Input
5
4 5 1 2 3
Output
Β
5 4
Β
Β
3 2 1
Note
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
mx = max(a)
has = []
unused = list(a)
for i in a:
if i != max(unused):
has.append(i)
print()
else:
has.sort()
has.reverse()
mx = max(unused)
unused.remove(mx)
for j in has:
unused.remove(j)
print(mx, " ".join(str(j) for j in has))
has = []
``` | instruction | 0 | 78,787 | 8 | 157,574 |
No | output | 1 | 78,787 | 8 | 157,575 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
<image>
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input
The first line contains single integer n (1 β€ n β€ 100 000) β the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Examples
Input
3
3 1 2
Output
3
Β
2 1
Input
5
4 5 1 2 3
Output
Β
5 4
Β
Β
3 2 1
Note
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
Submitted Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
target = n
reali = 1
for i in range(n):
if a[i]==target:
print(*[x for x in range(target,target-reali,-1)])
target = target-reali
reali = 1
else:
print()
reali+=1
``` | instruction | 0 | 78,788 | 8 | 157,576 |
No | output | 1 | 78,788 | 8 | 157,577 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
<image>
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input
The first line contains single integer n (1 β€ n β€ 100 000) β the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Examples
Input
3
3 1 2
Output
3
Β
2 1
Input
5
4 5 1 2 3
Output
Β
5 4
Β
Β
3 2 1
Note
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
s=[]
for i in range(n):
s.append([])
for j in range(n):
s[j].append(a[j])
k=0
while(k<=j-1):
if(len(s[k])!=0):
if(s[k][0]<s[j][0]):
while(len(s[k])!=0):
s[j].append(s[k][0])
s[k].remove(s[k][0])
k+=1
for i in range(n):
for j in s[i]:
print(j,end=" ")
print()
``` | instruction | 0 | 78,789 | 8 | 157,578 |
No | output | 1 | 78,789 | 8 | 157,579 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size a can climb into some car with size b if and only if a β€ b, he or she likes it if and only if he can climb into this car and 2a β₯ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input
You are given four integers V1, V2, V3, Vm(1 β€ Vi β€ 100) β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
Output
Output three integers β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
Note
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | instruction | 0 | 78,830 | 8 | 157,660 |
Tags: brute force, implementation
Correct Solution:
```
import sys
v1,v2,v3,vm=map(int,input().split(' '))
arr=[]
s1=max(v1,vm)
if(2*v1>2*vm and 2*v1>=s1):
arr.append(2*v1)
else:
print("-1")
sys.exit()
s2=max(v2,vm)
if(2*v2>2*vm and 2*v1>=s2):
arr.append(2*v2)
else:
print("-1")
sys.exit()
s3=max(v3,vm)
s4=min(2*v3,2*vm)
if(s4>=s3):
arr.append(s4)
else:
print("-1")
sys.exit()
for i in range(3):
print(arr[i])
``` | output | 1 | 78,830 | 8 | 157,661 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size a can climb into some car with size b if and only if a β€ b, he or she likes it if and only if he can climb into this car and 2a β₯ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input
You are given four integers V1, V2, V3, Vm(1 β€ Vi β€ 100) β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
Output
Output three integers β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
Note
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | instruction | 0 | 78,831 | 8 | 157,662 |
Tags: brute force, implementation
Correct Solution:
```
L, M, S, Ma = map(int, input().split())
l = max(S, Ma)
s = min(S, Ma)
if s * 2 < l:
print(-1)
else:
if l >= L or l >= M:
print(-1)
else:
print(L*2)
print(M*2)
print(s*2)
``` | output | 1 | 78,831 | 8 | 157,663 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size a can climb into some car with size b if and only if a β€ b, he or she likes it if and only if he can climb into this car and 2a β₯ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input
You are given four integers V1, V2, V3, Vm(1 β€ Vi β€ 100) β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
Output
Output three integers β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
Note
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | instruction | 0 | 78,832 | 8 | 157,664 |
Tags: brute force, implementation
Correct Solution:
```
def run():
b1, b2, b3, m = [int(x) for x in input().split()]
if b1 <= m:
print('-1')
return
if b2 <= m:
print('-1')
return
if 2*m < b3:
print('-1')
return
if 2*b3 < m:
print('-1')
return
print(2*b1)
print(2*b2)
for x in range(m, 2*m+1):
if b3 <= x <= 2*b3:
print(x)
break
run()
``` | output | 1 | 78,832 | 8 | 157,665 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size a can climb into some car with size b if and only if a β€ b, he or she likes it if and only if he can climb into this car and 2a β₯ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input
You are given four integers V1, V2, V3, Vm(1 β€ Vi β€ 100) β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
Output
Output three integers β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
Note
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | instruction | 0 | 78,833 | 8 | 157,666 |
Tags: brute force, implementation
Correct Solution:
```
a,b,c,d = map(int,input().split())
flag = 0
for i in range(a,2*a+1):
for j in range(b,2*b+1):
for k in range(c,2*c+1):
if i>=a and 2*a>=i and j>=b and 2*b>=j and k>=c and 2*c>=k and i>j>k and d<=k and 2*d>=k and 2*d<i and 2*d<j:
flag = 1
print(i)
print(j)
print(k)
exit(0)
if not flag :
print(-1)
``` | output | 1 | 78,833 | 8 | 157,667 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size a can climb into some car with size b if and only if a β€ b, he or she likes it if and only if he can climb into this car and 2a β₯ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input
You are given four integers V1, V2, V3, Vm(1 β€ Vi β€ 100) β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
Output
Output three integers β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
Note
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | instruction | 0 | 78,834 | 8 | 157,668 |
Tags: brute force, implementation
Correct Solution:
```
v1, v2, v3, vm = map(int, input().split())
car = max(vm, v3)
if car >= v1 or car >= v2:
print(-1)
exit(0)
if vm * 2 >= car and v3 * 2 >= car:
print(v1 * 2)
print(v2 * 2)
print(car)
else:
print(-1)
``` | output | 1 | 78,834 | 8 | 157,669 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size a can climb into some car with size b if and only if a β€ b, he or she likes it if and only if he can climb into this car and 2a β₯ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input
You are given four integers V1, V2, V3, Vm(1 β€ Vi β€ 100) β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
Output
Output three integers β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
Note
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | instruction | 0 | 78,835 | 8 | 157,670 |
Tags: brute force, implementation
Correct Solution:
```
v1, v2, v3, vm = list( map( int, input().split() ) )
ans = []
def can_climb( a, b ):
return ( a <= b )
def likes( a, b ):
return ( 2*a >= b )
for b1 in range( 1, 221 ):
if can_climb( v1, b1 ) and can_climb( vm, b1 ):
if likes( v1, b1 ) and likes( vm, b1 ) == False:
for b2 in range( 1, 221 ):
if can_climb( v2, b2 ) and can_climb( vm, b2 ):
if likes( v2, b2 ) and likes( vm, b2 ) == False:
for b3 in range( 1, 221 ):
if can_climb( v3, b3 ) and can_climb( vm, b3 ):
if likes( v3, b3 ) and likes( vm, b3 ):
if b1 != b2 and b2 != b3 and b1 != b3:
ans = sorted( [ b1, b2, b3 ] )
print( ans[2] )
print( ans[1] )
print( ans[0] )
exit(0)
print( -1 )
``` | output | 1 | 78,835 | 8 | 157,671 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size a can climb into some car with size b if and only if a β€ b, he or she likes it if and only if he can climb into this car and 2a β₯ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input
You are given four integers V1, V2, V3, Vm(1 β€ Vi β€ 100) β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
Output
Output three integers β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
Note
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | instruction | 0 | 78,836 | 8 | 157,672 |
Tags: brute force, implementation
Correct Solution:
```
v1, v2, v3, vm = map(int, input().split())
if vm > v3*2 or v3 > vm*2 or vm>=v2:
print(-1)
else:
print(2*v1, 2*v2, min(2*v3, vm*2))
``` | output | 1 | 78,836 | 8 | 157,673 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size a can climb into some car with size b if and only if a β€ b, he or she likes it if and only if he can climb into this car and 2a β₯ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input
You are given four integers V1, V2, V3, Vm(1 β€ Vi β€ 100) β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
Output
Output three integers β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
Note
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | instruction | 0 | 78,837 | 8 | 157,674 |
Tags: brute force, implementation
Correct Solution:
```
v1, v2, v3, vm = map(int,input().split())
if v2>vm and vm<=2*v3 and vm >= v3/2:
print(2*v1)
print(2*v2)
print(max(vm,v3))
else:
print(-1)
``` | output | 1 | 78,837 | 8 | 157,675 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size a can climb into some car with size b if and only if a β€ b, he or she likes it if and only if he can climb into this car and 2a β₯ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input
You are given four integers V1, V2, V3, Vm(1 β€ Vi β€ 100) β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
Output
Output three integers β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
Note
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
Submitted Solution:
```
a, b, c, d = map(int, input().split())
for x in range (205):
for y in range (x):
for z in range (y):
if (x >= a and y >= b and z >= c and z >= d):
if (x <= 2*a and y <= 2*b and z <= 2*c):
if (2*d >= z and 2*d < y and 2*d < x):
print(x, y, z)
exit(0)
print(-1)
``` | instruction | 0 | 78,838 | 8 | 157,676 |
Yes | output | 1 | 78,838 | 8 | 157,677 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size a can climb into some car with size b if and only if a β€ b, he or she likes it if and only if he can climb into this car and 2a β₯ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input
You are given four integers V1, V2, V3, Vm(1 β€ Vi β€ 100) β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
Output
Output three integers β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
Note
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
Submitted Solution:
```
p,m,s,h=map(int,input().split())
t=max(s,h)
if t>2*min(s,h) or h>=m:
print(-1)
else:
a=2*h+1
ap,am=max(p,a),max(m,a)
if am == ap:
ap+=1
print(ap,am, t)
``` | instruction | 0 | 78,839 | 8 | 157,678 |
Yes | output | 1 | 78,839 | 8 | 157,679 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size a can climb into some car with size b if and only if a β€ b, he or she likes it if and only if he can climb into this car and 2a β₯ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input
You are given four integers V1, V2, V3, Vm(1 β€ Vi β€ 100) β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
Output
Output three integers β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
Note
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
Submitted Solution:
```
a,b,c,d = [int(i) for i in input().split()]
flag = False
for x in range(max(a,2*d+1),2*a+1):
for y in range(max(b,2*d+1),2*b+1):
for z in range(c,2*c+1):
if x>y>z and d<=z and 2*d>=z:
print(x,y,z)
flag = True
break
if flag:
break
if flag:
break
else:
print(-1)
``` | instruction | 0 | 78,840 | 8 | 157,680 |
Yes | output | 1 | 78,840 | 8 | 157,681 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size a can climb into some car with size b if and only if a β€ b, he or she likes it if and only if he can climb into this car and 2a β₯ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input
You are given four integers V1, V2, V3, Vm(1 β€ Vi β€ 100) β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
Output
Output three integers β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
Note
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
Submitted Solution:
```
#!/usr/bin/env python3
def solve():
papa, mama, son, masha = get([int])
small, med, large = None, None, None
def fit(person, car):
return person <= car
def likes(person, car):
return car <= 2*person
def fitandlikes(person, car):
return fit(person, car) and likes(person, car)
for small in range(1, 301):
if fitandlikes(masha, small) and fitandlikes(son, small):
break
else:
return -1
for med in range(small+1, 301):
if fitandlikes(mama, med) and not likes(masha, med):
break
else:
return -1
for large in range(med+1, 301):
if fitandlikes(papa, large) and not likes(masha, large):
break
else:
return -1
return '\n'.join(map(str, [large, med, small]))
_testcases = """
50 30 10 10
50
30
10
100 50 10 21
-1
""".strip()
# ======================= B O I L E R P L A T E ======================= #
# Practicality beats purity
from bisect import bisect_left, bisect_right
from collections import defaultdict
from functools import lru_cache
from heapq import heapify, heappop, heappush
from operator import itemgetter, attrgetter
import bisect
import collections
import functools
import heapq
import itertools
import math
import operator
import re
import string
import sys
inf = float('inf')
cache = lru_cache(None)
sys.setrecursionlimit(10000)
def tree():
return collections.defaultdict(tree)
def equal(x, y, epsilon=1e-6):
# https://code.google.com/codejam/kickstart/resources/faq#real-number-behavior
if -epsilon <= x - y <= epsilon:
return True
if -epsilon <= x <= epsilon or -epsilon <= y <= epsilon:
return False
return (-epsilon <= (x - y) / x <= epsilon or -epsilon <= (x - y) / y <= epsilon)
def get(_type): # For easy input
if type(_type) == list:
if len(_type) == 1:
_type = _type[0]
return list(map(_type, input().strip().split()))
else:
return [_type[i](inp) for i, inp in enumerate(input().strip().split())]
else:
return _type(input().strip())
if __name__ == '__main__':
printRecursionTree = timeit = lambda x: x
_p, print = print, lambda *a, **b: None
_p(solve())
``` | instruction | 0 | 78,841 | 8 | 157,682 |
Yes | output | 1 | 78,841 | 8 | 157,683 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size a can climb into some car with size b if and only if a β€ b, he or she likes it if and only if he can climb into this car and 2a β₯ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input
You are given four integers V1, V2, V3, Vm(1 β€ Vi β€ 100) β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
Output
Output three integers β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
Note
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
Submitted Solution:
```
v1,v2,v3,vm=map(int,input().split())
flag=0
l=[]
for i in range(2*v1,v1-1,-1):
if i>=vm:
l.append(i)
break
else:
flag=1
if not flag:
for i in range(2*v2,v2-1,-1):
if i>=vm and i<l[0]:
l.append(i)
break
else:
flag=1
if not flag:
for i in range(v3,2*v3+1):
if i>=vm and i<=2*vm and i<l[1]:
l.append(i)
break
else:
flag=1
if flag:
print("-1")
else:
print(l[0])
print(l[1])
print(l[2])
``` | instruction | 0 | 78,842 | 8 | 157,684 |
No | output | 1 | 78,842 | 8 | 157,685 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size a can climb into some car with size b if and only if a β€ b, he or she likes it if and only if he can climb into this car and 2a β₯ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input
You are given four integers V1, V2, V3, Vm(1 β€ Vi β€ 100) β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
Output
Output three integers β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
Note
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
Submitted Solution:
```
v1, v2, v3, vm = map(int, input().split())
mass = [v1, v2, v3]
if vm > mass[2] or 2 * vm < mass[2]:
print(-1)
else:
for i in range(len(mass)):
print(mass[i])
``` | instruction | 0 | 78,843 | 8 | 157,686 |
No | output | 1 | 78,843 | 8 | 157,687 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size a can climb into some car with size b if and only if a β€ b, he or she likes it if and only if he can climb into this car and 2a β₯ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input
You are given four integers V1, V2, V3, Vm(1 β€ Vi β€ 100) β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
Output
Output three integers β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
Note
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
Submitted Solution:
```
import sys
import os
from math import*
input=sys.stdin.buffer.readline
v1,v2,v3,vm=map(int,input().split())
if vm>2*v3 or 2*vm<v3:
print("-1")
else:
print(v1)
print(v2)
print(max(v3,vm))
``` | instruction | 0 | 78,844 | 8 | 157,688 |
No | output | 1 | 78,844 | 8 | 157,689 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size a can climb into some car with size b if and only if a β€ b, he or she likes it if and only if he can climb into this car and 2a β₯ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input
You are given four integers V1, V2, V3, Vm(1 β€ Vi β€ 100) β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
Output
Output three integers β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
Note
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
Submitted Solution:
```
a,b,c,d=list(map(int,input().split()))
for i in range(0,300):
for j in range(0,i):
for k in range(d,j):
if a<=i<=a+a and b<=j<=b+b and c<=k<=c+c:
print(str(i)+'\n'+str(j)+'\n'+str(k))
exit(0)
print(-1)
``` | instruction | 0 | 78,845 | 8 | 157,690 |
No | output | 1 | 78,845 | 8 | 157,691 |
Provide a correct Python 3 solution for this coding contest problem.
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes | instruction | 0 | 78,908 | 8 | 157,816 |
"Correct Solution:
```
n=int(input())
h=list(map(int,input().split()))
ans="Yes"
for i in range(1,n):
if h[i]<h[i-1]:
if h[i]-h[i-1]<-1: ans="No"
h[i]+=1
print(ans)
``` | output | 1 | 78,908 | 8 | 157,817 |
Provide a correct Python 3 solution for this coding contest problem.
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes | instruction | 0 | 78,909 | 8 | 157,818 |
"Correct Solution:
```
N = int(input())
H = list(map(int, input().split()))
F = "Yes"
l = H[0]
for i in range(1, N):
if l < H[i]:
l = H[i]
if l - 1 > H[i]:
F = "No"
break
print(F)
``` | output | 1 | 78,909 | 8 | 157,819 |
Provide a correct Python 3 solution for this coding contest problem.
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes | instruction | 0 | 78,910 | 8 | 157,820 |
"Correct Solution:
```
N=int(input())
H=list(map(int,input().split()))
base=0
for h in H:
if base>h:
print("No")
break
base=max(base,h-1)
else:
print("Yes")
``` | output | 1 | 78,910 | 8 | 157,821 |
Provide a correct Python 3 solution for this coding contest problem.
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes | instruction | 0 | 78,911 | 8 | 157,822 |
"Correct Solution:
```
N=int(input())
H=list(map(int,input().split()))
pre=0
for h in H:
if h<pre:
print("No");exit()
elif h>pre:
pre=h-1
print("Yes")
``` | output | 1 | 78,911 | 8 | 157,823 |
Provide a correct Python 3 solution for this coding contest problem.
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes | instruction | 0 | 78,912 | 8 | 157,824 |
"Correct Solution:
```
n=int(input())
h=list(map(int,input().split()))
H=h[::-1]
t=H[0]
for i in range(1,n):
if H[i]>t+1:
print("No")
break
else:
t=min(H[i],t)
else:
print("Yes")
``` | output | 1 | 78,912 | 8 | 157,825 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.