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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2k - 1 into one box of side length 2k, or as in the following figure:
<image>
Emuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes.
Input
The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.
Output
Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.
Examples
Input
2
0 3
1 5
Output
3
Input
1
0 4
Output
1
Input
2
1 10
2 2
Output
3
Note
Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.
In the second test case, we can put all four small boxes into a box with side length 2.
Submitted Solution:
```
from math import *
n,o=int(input()),0
for i in range(n):
r,t=map(int,input().split())
r+=ceil(log(t,4))
r+=t==1
o=max(o,r)
print(o)
``` | instruction | 0 | 71,050 | 8 | 142,100 |
Yes | output | 1 | 71,050 | 8 | 142,101 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2k - 1 into one box of side length 2k, or as in the following figure:
<image>
Emuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes.
Input
The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.
Output
Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.
Examples
Input
2
0 3
1 5
Output
3
Input
1
0 4
Output
1
Input
2
1 10
2 2
Output
3
Note
Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.
In the second test case, we can put all four small boxes into a box with side length 2.
Submitted Solution:
```
import math
t=int(input())
ans=-1
maxi=-1
for i in range(t):
k,a=map(int,input().split())
h=k+math.ceil(math.log(a,4))
ans=max(ans,h)
maxi=max(maxi,k)
print(max(ans,maxi+1))
``` | instruction | 0 | 71,051 | 8 | 142,102 |
Yes | output | 1 | 71,051 | 8 | 142,103 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2k - 1 into one box of side length 2k, or as in the following figure:
<image>
Emuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes.
Input
The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.
Output
Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.
Examples
Input
2
0 3
1 5
Output
3
Input
1
0 4
Output
1
Input
2
1 10
2 2
Output
3
Note
Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.
In the second test case, we can put all four small boxes into a box with side length 2.
Submitted Solution:
```
from sys import stdin
input = stdin.readline
n = int(input())
res = 0
for i in range(n):
k, a = (int(x) for x in input().split())
i = 0
x = 1
while a > x:
i += 1
x *= 4
res = max(res, k + i)
print(res)
``` | instruction | 0 | 71,052 | 8 | 142,104 |
No | output | 1 | 71,052 | 8 | 142,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2k - 1 into one box of side length 2k, or as in the following figure:
<image>
Emuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes.
Input
The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.
Output
Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.
Examples
Input
2
0 3
1 5
Output
3
Input
1
0 4
Output
1
Input
2
1 10
2 2
Output
3
Note
Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.
In the second test case, we can put all four small boxes into a box with side length 2.
Submitted Solution:
```
import math
t=int(input())
ans=-1
for i in range(t):
k,a=map(int,input().split())
h=k+math.ceil(math.log(a,4))
ans=max(ans,h)
print(ans)
``` | instruction | 0 | 71,053 | 8 | 142,106 |
No | output | 1 | 71,053 | 8 | 142,107 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2k - 1 into one box of side length 2k, or as in the following figure:
<image>
Emuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes.
Input
The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.
Output
Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.
Examples
Input
2
0 3
1 5
Output
3
Input
1
0 4
Output
1
Input
2
1 10
2 2
Output
3
Note
Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.
In the second test case, we can put all four small boxes into a box with side length 2.
Submitted Solution:
```
def main():
n = int(input())
m = b = 0
for k, a in sorted(tuple(map(int, input().split())) for _ in range(n)):
r = 4 ** (k - m)
b = (b + r - 1) // r
if b < a:
b = a
m = k
r = 1
while r < b:
r *= 4
m += 1
print(m)
if __name__ == '__main__':
main()
``` | instruction | 0 | 71,054 | 8 | 142,108 |
No | output | 1 | 71,054 | 8 | 142,109 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2k - 1 into one box of side length 2k, or as in the following figure:
<image>
Emuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes.
Input
The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.
Output
Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.
Examples
Input
2
0 3
1 5
Output
3
Input
1
0 4
Output
1
Input
2
1 10
2 2
Output
3
Note
Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.
In the second test case, we can put all four small boxes into a box with side length 2.
Submitted Solution:
```
import sys
input=sys.stdin.readline
n=int(input())
ka=[list(map(int,input().split())) for i in range(n)]
m=0
for k,a in ka:
cnt=k
x=1
while x<a:
x*=4
cnt+=1
m=max(m,cnt)
print(max(m,1))
``` | instruction | 0 | 71,055 | 8 | 142,110 |
No | output | 1 | 71,055 | 8 | 142,111 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess — all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag — her inherent sense of order does not let her do so.
You are given the coordinates of the handbag and the coordinates of the objects in some Сartesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.
Input
The first line of the input file contains the handbag's coordinates xs, ys. The second line contains number n (1 ≤ n ≤ 24) — the amount of objects the girl has. The following n lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.
Output
In the first line output the only number — the minimum time the girl needs to put the objects into her handbag.
In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to n), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them.
Examples
Input
0 0
2
1 1
-1 1
Output
8
0 1 2 0
Input
1 1
3
4 3
3 4
0 0
Output
32
0 1 2 0 3 0 | instruction | 0 | 71,331 | 8 | 142,662 |
Tags: bitmasks, dp
Correct Solution:
```
x0, y0 = map(int, input().split())
n = int(input())
arr = [[x0, y0]]
for i in range(0, n):
x, y = map(int, input().split())
arr.append([x, y])
dist = [[0 for j in range(0, n+1)] for i in range(0, n+1)]
for i in range(0, n+1):
for j in range(0, n+1):
dist[i][j] = (arr[i][0] - arr[j][0])**2 + (arr[i][1] - arr[j][1])**2
# print(arr)
# print(dist)
def dfs(status, memo, pp):
# if status in memo:
# return memo[status][0]
if memo[status] != None:
return memo[status]
if status < 0:
return 1e8
res = 1e8
prev = []
for i in range(1, n+1):
if (status & (1 << (i - 1))) == 0:
continue
t1 = status ^ (1 << (i - 1))
# print(memo, pp)
temp = dfs(t1, memo, pp) + dist[0][i]*2
if temp < res:
res = temp
prev = [i, 0]
for j in range(i+1, n+1):
if j == i:
continue
if (t1 & (1 << (j - 1))) == 0:
continue
next = t1 ^ (1 << (j - 1))
temp = dfs(next, memo, pp) + dist[0][j] + dist[j][i] + dist[i][0]
if temp < res:
res = temp
prev = [i, j, 0]
break
memo[status] = res
pp[status] = prev
# print(prev)
# print(status, res)
return res
# memo = {1: [0, []]}
memo = [None for i in range(0, 1 << n)]
pp = [None for i in range(0, 1 << n)]
memo[0] = 0
pp[0] = []
start = 0
end = 0
for i in range(0, n):
end += (1 << i)
res = dfs(end, memo, pp)
path = [0]
cur = end
# print(memo, pp)
while cur > 0:
prev = pp[cur]
# if len(prev) == 2:
path.extend(prev)
for i in range(len(prev) - 1):
cur -= (1 << (prev[i] - 1))
print(res)
print(' '.join(map(str, path)))
``` | output | 1 | 71,331 | 8 | 142,663 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess — all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag — her inherent sense of order does not let her do so.
You are given the coordinates of the handbag and the coordinates of the objects in some Сartesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.
Input
The first line of the input file contains the handbag's coordinates xs, ys. The second line contains number n (1 ≤ n ≤ 24) — the amount of objects the girl has. The following n lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.
Output
In the first line output the only number — the minimum time the girl needs to put the objects into her handbag.
In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to n), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them.
Examples
Input
0 0
2
1 1
-1 1
Output
8
0 1 2 0
Input
1 1
3
4 3
3 4
0 0
Output
32
0 1 2 0 3 0 | instruction | 0 | 71,332 | 8 | 142,664 |
Tags: bitmasks, dp
Correct Solution:
```
#!/usr/bin/env python
'''
' Author: Cheng-Shih Wong
' Email: mob5566@gmail.com
' Date: 2017-08-08
'''
from itertools import chain
from time import time
def main():
BITS = [1 << sh for sh in range(24)]
B2N = {v: u for u, v in enumerate(BITS)}
def getPt():
return tuple(map(int, input().split()))
def dist(ptA, ptB):
return sum(((u-v)**2 for u, v in zip(ptA, ptB)))
def getBits(val):
return tuple(filter(lambda x: x&val, BITS))
def chooseTwo(pool):
n = len(pool)
for i in range(n):
for j in range(i+1, n):
yield (pool[i], pool[j])
ori = getPt()
pts = []
N = int(input())
for _ in range(N):
pts.append(getPt())
vis = set([0])
mint = [0]+[1e8]*(1<<N) # minimal time for dp
pres = [None]*(1<<N) # previous step for reconstruct path
allb = (1 << N)-1 # all objects contained state
B2P = {BITS[u]: v for u, v in enumerate(pts)}
B2P[0] = ori
alld = {u: {v: dist(B2P[u], B2P[v]) for v in B2P} for u in B2P}
getDP = lambda x: mint[x]
newDist = lambda stt, p: mint[stt] + alld[p[0]][p[1]] \
+ alld[p[0]][0] \
+ alld[p[1]][0]
for stt in range(1<<N):
if stt not in vis:
continue
bits = getBits(~stt&allb)
sb = bits[0] if bits else None
for bit in bits:
newstt = stt | sb | bit
nd = newDist(stt, (sb, bit))
if getDP(newstt) > nd:
mint[newstt] = nd
pres[newstt] = sb | bit
vis.add(newstt)
print(mint[allb])
path = ['0']
stt = allb
while stt:
bits = getBits(pres[stt])
for bit in bits:
path.append(str(B2N[bit]+1))
path.append('0')
stt ^= pres[stt]
print(' '.join(path))
if __name__ == '__main__':
import sys
st = time()
main()
print('Run {:.6f} seconds.'.format(time()-st), file=sys.stderr)
``` | output | 1 | 71,332 | 8 | 142,665 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess — all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag — her inherent sense of order does not let her do so.
You are given the coordinates of the handbag and the coordinates of the objects in some Сartesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.
Input
The first line of the input file contains the handbag's coordinates xs, ys. The second line contains number n (1 ≤ n ≤ 24) — the amount of objects the girl has. The following n lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.
Output
In the first line output the only number — the minimum time the girl needs to put the objects into her handbag.
In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to n), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them.
Examples
Input
0 0
2
1 1
-1 1
Output
8
0 1 2 0
Input
1 1
3
4 3
3 4
0 0
Output
32
0 1 2 0 3 0 | instruction | 0 | 71,333 | 8 | 142,666 |
Tags: bitmasks, dp
Correct Solution:
```
x0, y0 = map(int, input().split())
n = int(input())
arr = [[x0, y0]]
for i in range(0, n):
x, y = map(int, input().split())
arr.append([x, y])
dist = [[0 for j in range(0, n+1)] for i in range(0, n+1)]
for i in range(0, n+1):
for j in range(0, n+1):
dist[i][j] = (arr[i][0] - arr[j][0])**2 + (arr[i][1] - arr[j][1])**2
def dfs(status, memo, pp):
if memo[status] != None:
return memo[status]
if status < 0:
return 1e8
res = 1e8
prev = []
for i in range(1, n+1):
if (status & (1 << (i - 1))) == 0:
continue
t1 = status ^ (1 << (i - 1))
# print(memo, pp)
temp = dfs(t1, memo, pp) + dist[0][i]*2
if temp < res:
res = temp
prev = [i, 0]
for j in range(i+1, n+1):
if j == i:
continue
if (t1 & (1 << (j - 1))) == 0:
continue
next = t1 ^ (1 << (j - 1))
temp = dfs(next, memo, pp) + dist[0][j] + dist[j][i] + dist[i][0]
if temp < res:
res = temp
prev = [i, j, 0]
break
memo[status] = res
pp[status] = prev
return res
memo = [None for i in range(0, 1 << n)]
pp = [None for i in range(0, 1 << n)]
memo[0] = 0
pp[0] = []
start = 0
end = 0
for i in range(0, n):
end += (1 << i)
res = dfs(end, memo, pp)
path = [0]
cur = end
while cur > 0:
prev = pp[cur]
path.extend(prev)
for i in range(len(prev) - 1):
cur -= (1 << (prev[i] - 1))
print(res)
print(' '.join(map(str, path)))
``` | output | 1 | 71,333 | 8 | 142,667 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess — all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag — her inherent sense of order does not let her do so.
You are given the coordinates of the handbag and the coordinates of the objects in some Сartesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.
Input
The first line of the input file contains the handbag's coordinates xs, ys. The second line contains number n (1 ≤ n ≤ 24) — the amount of objects the girl has. The following n lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.
Output
In the first line output the only number — the minimum time the girl needs to put the objects into her handbag.
In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to n), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them.
Examples
Input
0 0
2
1 1
-1 1
Output
8
0 1 2 0
Input
1 1
3
4 3
3 4
0 0
Output
32
0 1 2 0 3 0 | instruction | 0 | 71,334 | 8 | 142,668 |
Tags: bitmasks, dp
Correct Solution:
```
# O(n*2^n) (however quite a few states are not visited)
# most important optimization is not transitioning from unvisited states
# (only ~ 1% of states are visited) (transition is O(n))
# other optimizations are using floats, bitwise operators, and precomputing dists/ reducing ops
xs,ys = map(float,input().split())
n = int(input())
dist = [[0]*(n+1) for i in range(n+1)]
dist2 = [[0]*(n) for i in range(n)]
objects = [list(map(float,input().split())) for i in range(n)] + [[xs,ys]] # objects[n] is handbag
for i in range(n+1):
for j in range(n+1):
dist[i][j] = (objects[i][0] - objects[j][0])**2 + (objects[i][1] - objects[j][1])**2
for i in range(n):
for j in range(n):
dist2[i][j] = dist[n][i] + dist[i][j] + dist[j][n]
dp = [1e6]*(1<<n)
vis = set([0]) #alot of states are not visited after optimization
dp[0] = 0
for i in range((1<<n)-1):
if i in vis:
# reduce O(n^2) transition to O(n) via assuming 1 of the objects taken must be the
# first object not yet taken in order
for j in range(n):
if i&(1<<j) == 0:
# get 1 new object
newi = i + (1 << j)
dp[newi] = min(dp[newi], dp[i] + 2*dist[n][j])
vis.add(newi)
for k in range(j+1,n):
# get 2 new objects at a time
if i&(1<<k) == 0:
newi |= 1<<k
dp[newi] = min(dp[newi], dp[i] + dist2[j][k])
vis.add(newi)
newi ^= 1<<k
break
curr = (1<<n) - 1
path = [0]
while curr:
for i in range(n):
if curr & (1<<i):
# 1 object taken
if dp[curr] == dp[curr - (1<<i)] + 2*dist[n][i]:
path.extend([i+1,0])
curr ^= (1<<i)
# 2 objects taken
for j in range(i+1,n):
if curr & (1<<j):
if dp[curr] == dp[curr - (1<<i) - (1<<j)] + dist2[i][j]:
path.extend([j+1,i+1,0])
curr ^= (1<<i) + (1<<j)
print(int(dp[(1<<n)-1]))
print(*path[::-1])
``` | output | 1 | 71,334 | 8 | 142,669 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess — all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag — her inherent sense of order does not let her do so.
You are given the coordinates of the handbag and the coordinates of the objects in some Сartesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.
Input
The first line of the input file contains the handbag's coordinates xs, ys. The second line contains number n (1 ≤ n ≤ 24) — the amount of objects the girl has. The following n lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.
Output
In the first line output the only number — the minimum time the girl needs to put the objects into her handbag.
In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to n), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them.
Examples
Input
0 0
2
1 1
-1 1
Output
8
0 1 2 0
Input
1 1
3
4 3
3 4
0 0
Output
32
0 1 2 0 3 0
Submitted Solution:
```
x0, y0 = map(int, input().split())
n = int(input())
arr = [[x0, y0]]
for i in range(0, n):
x, y = map(int, input().split())
arr.append([x, y])
dist = [[0 for j in range(0, n+1)] for i in range(0, n+1)]
for i in range(0, n+1):
for j in range(0, n+1):
dist[i][j] = (arr[i][0] - arr[j][0])**2 + (arr[i][1] - arr[j][1])**2
# print(arr)
# print(dist)
def dfs(status, memo):
# if status in memo:
# return memo[status][0]
if memo[status] != None:
return memo[status][0]
if status <= 0:
return 1e8
res = 1e8
prev = []
for i in range(1, n+1):
if ((status >> i) & 1) == 0:
continue
next = status - (1 << i)
temp = dfs(next, memo) + dist[0][i]*2
if temp < res:
res = temp
prev = [i, 0]
for j in range(1, n+1):
if j == i:
continue
if ((status >> j) & 1) == 0:
continue
next = status - (1 << i) - (1 << j)
temp = dfs(next, memo) + dist[0][j] + dist[j][i] + dist[i][0]
if temp < res:
res = temp
prev = [i, j, 0]
memo[status] = [res, prev]
print(status, res)
return res
# memo = {1: [0, []]}
memo = [None for i in range(0, 1 << 25)]
memo[1] = [0, []]
start = 1
end = 1
for i in range(1, n + 1):
end += (1 << i)
res = dfs(end, memo)
path = [0]
cur = end
while cur > 1:
prev = memo[cur][1]
# if len(prev) == 2:
path.extend(prev)
for i in range(len(prev) - 1):
cur -= (1 << prev[i])
print(res)
print(' '.join(map(str, path)))
``` | instruction | 0 | 71,336 | 8 | 142,672 |
No | output | 1 | 71,336 | 8 | 142,673 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess — all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag — her inherent sense of order does not let her do so.
You are given the coordinates of the handbag and the coordinates of the objects in some Сartesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.
Input
The first line of the input file contains the handbag's coordinates xs, ys. The second line contains number n (1 ≤ n ≤ 24) — the amount of objects the girl has. The following n lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.
Output
In the first line output the only number — the minimum time the girl needs to put the objects into her handbag.
In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to n), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them.
Examples
Input
0 0
2
1 1
-1 1
Output
8
0 1 2 0
Input
1 1
3
4 3
3 4
0 0
Output
32
0 1 2 0 3 0
Submitted Solution:
```
'''input
0 0
2
1 1
-1 1
'''
from sys import stdin
def distance(coordinates, index):
return coordinates[index][0] ** 2 + coordinates[index][1] ** 2
def difference(coordinates, first, second):
one = abs(coordinates[first][0] - coordinates[second][0]) ** 2
two = abs(coordinates[first][1] - coordinates[second][1]) ** 2
return one + two
def myfunction(coordinates, bitmask, index = 0):
if index >= len(bitmask):
return 0
if bitmask[index] == 0:
cost_1 = float('inf'); cost_2 = float('inf')
cbitmask = bitmask[:]
cbitmask[index] = 1
cost_1 = 2 * distance(coordinates, index) + myfunction(coordinates, cbitmask, index + 1)
for i in range(len(bitmask)):
if i != index:
if cbitmask[i] == 0:
cbitmask[i] = 1
temp = (distance(coordinates, index)
+ difference(coordinates, index, i)
+ distance(coordinates, i)
+ myfunction(coordinates, cbitmask, index + 1))
if cost_2 > temp:
pair = i
cost_2 = min(cost_2, temp)
cbitmask[i] = 0
if cost_1 <= cost_2:
ans.append([index + 1])
elif cost_2 < cost_1:
ans.append([index + 1, pair + 1])
return min(cost_1, cost_2)
else:
return myfunction(coordinates, bitmask, index + 1)
# main starts
ox, oy = list(map(int, stdin.readline().split()))
n = int(stdin.readline().strip())
coordinates = []
for i in range(n):
x, y = list(map(int, stdin.readline().split()))
coordinates.append([x - ox, y - oy])
bitmask = [0] * n
ans = []
final = (myfunction(coordinates, bitmask))
print(final)
mydict = dict()
for i in range(n):
mydict[i + 1] = False
correct = [0]
count = 0
while len(ans) > 0:
temp = ans.pop()
if len(temp) == 2:
if mydict[temp[0]] == False and mydict[temp[1]] == False:
correct.append(temp[0])
correct.append(temp[1])
correct.append(0)
mydict[temp[0]] = True
mydict[temp[1]] = True
count += 2
else:
if mydict[temp[0]] == False:
correct.append(temp[0])
correct.append(0)
mydict[temp[0]] = True
count += 1
if count == n:
break
print(*correct)
``` | instruction | 0 | 71,337 | 8 | 142,674 |
No | output | 1 | 71,337 | 8 | 142,675 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess — all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag — her inherent sense of order does not let her do so.
You are given the coordinates of the handbag and the coordinates of the objects in some Сartesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.
Input
The first line of the input file contains the handbag's coordinates xs, ys. The second line contains number n (1 ≤ n ≤ 24) — the amount of objects the girl has. The following n lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.
Output
In the first line output the only number — the minimum time the girl needs to put the objects into her handbag.
In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to n), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them.
Examples
Input
0 0
2
1 1
-1 1
Output
8
0 1 2 0
Input
1 1
3
4 3
3 4
0 0
Output
32
0 1 2 0 3 0
Submitted Solution:
```
#!/usr/bin/env python
"""
CodeForces: 8C. Looking for Order
Strategy
The optimum way to pick up the pair of objects is:
dd = distance between two objects
d1 = distance between the handbag and one of object
d2 = distance between the handbag and other object
if dd < d1 + d2:
pick up the two objects at once
optimum time = d1 + dd + d2
else:
pick up the two objects one by one
optimum time = (d1 + d2) * 2
The optimum pair can be calculated by:
optimum pair = min(min(dd, d1 + d2) for all possible pairs)
"""
def dist2(dx, dy):
return (dx * dx) + (dy * dy)
def main():
x0, y0 = map(int, input().split())
n = int(input())
# pre-calculate the optimum way for all possible pairs
xyd = []
pair = []
for o1 in range(n):
x1, y1 = map(int, input().split())
d1 = dist2(x1 - x0, y1 - y0)
xyd.append((x1, y1, d1))
other = []
for o2 in range(o1):
x2, y2, d2 = xyd[o2]
d0 = d1 + d2
dd = dist2(x2 -x1, y2 - y1)
other.append((min(dd, d0), o2, d0))
other.sort(reverse=True)
pair.append(other)
# calculate the optimum order by finding the optimum (n/2) pairs
order = [0]
total = 0
for _ in range(n // 2):
best_d = 1000000
best_o = 0
for o1 in range(1, n):
if xyd[o1] is None:
continue
other = pair[o1]
while other:
dd, o2, _ = other[-1]
if xyd[o2] is not None:
if dd < best_d:
best_o = o1
best_d = dd
break
other.pop()
_, o2, d0 = pair[best_o].pop()
total += best_d + d0
order.append(o2 + 1)
if best_d == d0:
order.append(0)
order.append(best_o + 1)
order.append(0)
xyd[best_o] = xyd[o2] = None
# pick up the last object
if n & 1:
for o1 in range(n):
if xyd[o1] is not None:
total += xyd[o1][2] * 2
order.append(o1 + 1)
order.append(0)
break
print(total)
print(" ".join(map(str, order)))
if __name__ == '__main__':
main()
``` | instruction | 0 | 71,338 | 8 | 142,676 |
No | output | 1 | 71,338 | 8 | 142,677 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess — all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag — her inherent sense of order does not let her do so.
You are given the coordinates of the handbag and the coordinates of the objects in some Сartesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.
Input
The first line of the input file contains the handbag's coordinates xs, ys. The second line contains number n (1 ≤ n ≤ 24) — the amount of objects the girl has. The following n lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.
Output
In the first line output the only number — the minimum time the girl needs to put the objects into her handbag.
In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to n), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them.
Examples
Input
0 0
2
1 1
-1 1
Output
8
0 1 2 0
Input
1 1
3
4 3
3 4
0 0
Output
32
0 1 2 0 3 0
Submitted Solution:
```
'''input
1 1
3
4 3
3 4
0 0
'''
from sys import stdin
def distance(coordinates, index):
return coordinates[index][0] ** 2 + coordinates[index][1] ** 2
def difference(coordinates, first, second):
one = abs(coordinates[first][0] - coordinates[second][0]) ** 2
two = abs(coordinates[first][1] - coordinates[second][1]) ** 2
return one + two
def myfunction(coordinates, bitmask, index = 0):
if index >= len(bitmask):
return 0
if bitmask[index] == 0:
cost_1 = float('inf'); cost_2 = float('inf')
cbitmask = bitmask[:]
cbitmask[index] = 1
cost_1 = 2 * distance(coordinates, index) + myfunction(coordinates, cbitmask, index + 1)
for i in range(len(bitmask)):
if i != index:
if cbitmask[i] == 0:
cbitmask[i] = 1
cost_2 = min(cost_2, distance(coordinates, index) + difference(coordinates, index, i) +
distance(coordinates, i) + myfunction(coordinates, cbitmask, index + 1))
cbitmask[i] = 0
return min(cost_1, cost_2)
else:
return myfunction(coordinates, bitmask, index + 1)
# main starts
ox, oy = list(map(int, stdin.readline().split()))
n = int(stdin.readline().strip())
coordinates = []
for i in range(n):
x, y = list(map(int, stdin.readline().split()))
coordinates.append([x - ox, y - oy])
bitmask = [0] * n
print(myfunction(coordinates, bitmask))
``` | instruction | 0 | 71,339 | 8 | 142,678 |
No | output | 1 | 71,339 | 8 | 142,679 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi's house has only one socket.
Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
One power strip with A sockets can extend one empty socket into A empty sockets.
Find the minimum number of power strips required.
Constraints
* All values in input are integers.
* 2 \leq A \leq 20
* 1 \leq B \leq 20
Input
Input is given from Standard Input in the following format:
A B
Output
Print the minimum number of power strips required.
Examples
Input
4 10
Output
3
Input
8 9
Output
2
Input
8 8
Output
1 | instruction | 0 | 71,415 | 8 | 142,830 |
"Correct Solution:
```
i=input();print(-(~-int(i[2:])//-~-int(i[:2])))
``` | output | 1 | 71,415 | 8 | 142,831 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi's house has only one socket.
Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
One power strip with A sockets can extend one empty socket into A empty sockets.
Find the minimum number of power strips required.
Constraints
* All values in input are integers.
* 2 \leq A \leq 20
* 1 \leq B \leq 20
Input
Input is given from Standard Input in the following format:
A B
Output
Print the minimum number of power strips required.
Examples
Input
4 10
Output
3
Input
8 9
Output
2
Input
8 8
Output
1 | instruction | 0 | 71,416 | 8 | 142,832 |
"Correct Solution:
```
t,h=map(int,input().split())
print((h-2)//(t-1)+1)
``` | output | 1 | 71,416 | 8 | 142,833 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi's house has only one socket.
Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
One power strip with A sockets can extend one empty socket into A empty sockets.
Find the minimum number of power strips required.
Constraints
* All values in input are integers.
* 2 \leq A \leq 20
* 1 \leq B \leq 20
Input
Input is given from Standard Input in the following format:
A B
Output
Print the minimum number of power strips required.
Examples
Input
4 10
Output
3
Input
8 9
Output
2
Input
8 8
Output
1 | instruction | 0 | 71,417 | 8 | 142,834 |
"Correct Solution:
```
A,B = map(int,input().split(" "))
print((B+A-3)//(A-1))
``` | output | 1 | 71,417 | 8 | 142,835 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi's house has only one socket.
Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
One power strip with A sockets can extend one empty socket into A empty sockets.
Find the minimum number of power strips required.
Constraints
* All values in input are integers.
* 2 \leq A \leq 20
* 1 \leq B \leq 20
Input
Input is given from Standard Input in the following format:
A B
Output
Print the minimum number of power strips required.
Examples
Input
4 10
Output
3
Input
8 9
Output
2
Input
8 8
Output
1 | instruction | 0 | 71,418 | 8 | 142,836 |
"Correct Solution:
```
a,b=map(int,input().split())
x=0
while b > (a-1)*x+1:
x+=1
print(x)
``` | output | 1 | 71,418 | 8 | 142,837 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi's house has only one socket.
Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
One power strip with A sockets can extend one empty socket into A empty sockets.
Find the minimum number of power strips required.
Constraints
* All values in input are integers.
* 2 \leq A \leq 20
* 1 \leq B \leq 20
Input
Input is given from Standard Input in the following format:
A B
Output
Print the minimum number of power strips required.
Examples
Input
4 10
Output
3
Input
8 9
Output
2
Input
8 8
Output
1 | instruction | 0 | 71,419 | 8 | 142,838 |
"Correct Solution:
```
A, B = map(int,input().split())
k = -(-(B-1) // (A-1))
print(k)
``` | output | 1 | 71,419 | 8 | 142,839 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi's house has only one socket.
Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
One power strip with A sockets can extend one empty socket into A empty sockets.
Find the minimum number of power strips required.
Constraints
* All values in input are integers.
* 2 \leq A \leq 20
* 1 \leq B \leq 20
Input
Input is given from Standard Input in the following format:
A B
Output
Print the minimum number of power strips required.
Examples
Input
4 10
Output
3
Input
8 9
Output
2
Input
8 8
Output
1 | instruction | 0 | 71,420 | 8 | 142,840 |
"Correct Solution:
```
A,B=map(int,input().split())
i=1
j=0
while i<B:
i+=(A-1)
j+=1
print(j)
``` | output | 1 | 71,420 | 8 | 142,841 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi's house has only one socket.
Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
One power strip with A sockets can extend one empty socket into A empty sockets.
Find the minimum number of power strips required.
Constraints
* All values in input are integers.
* 2 \leq A \leq 20
* 1 \leq B \leq 20
Input
Input is given from Standard Input in the following format:
A B
Output
Print the minimum number of power strips required.
Examples
Input
4 10
Output
3
Input
8 9
Output
2
Input
8 8
Output
1 | instruction | 0 | 71,421 | 8 | 142,842 |
"Correct Solution:
```
a,b = map(int,input().split())
b-=1
print(-(-b//(a-1)))
``` | output | 1 | 71,421 | 8 | 142,843 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi's house has only one socket.
Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
One power strip with A sockets can extend one empty socket into A empty sockets.
Find the minimum number of power strips required.
Constraints
* All values in input are integers.
* 2 \leq A \leq 20
* 1 \leq B \leq 20
Input
Input is given from Standard Input in the following format:
A B
Output
Print the minimum number of power strips required.
Examples
Input
4 10
Output
3
Input
8 9
Output
2
Input
8 8
Output
1 | instruction | 0 | 71,422 | 8 | 142,844 |
"Correct Solution:
```
import math
a,b=map(int,input().split())
print(int(math.ceil((b-1)/(a-1))))
``` | output | 1 | 71,422 | 8 | 142,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi's house has only one socket.
Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
One power strip with A sockets can extend one empty socket into A empty sockets.
Find the minimum number of power strips required.
Constraints
* All values in input are integers.
* 2 \leq A \leq 20
* 1 \leq B \leq 20
Input
Input is given from Standard Input in the following format:
A B
Output
Print the minimum number of power strips required.
Examples
Input
4 10
Output
3
Input
8 9
Output
2
Input
8 8
Output
1
Submitted Solution:
```
A, B = [int(_) for _ in input().split()]
print((B - 1 + A - 2) // (A - 1))
``` | instruction | 0 | 71,423 | 8 | 142,846 |
Yes | output | 1 | 71,423 | 8 | 142,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi's house has only one socket.
Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
One power strip with A sockets can extend one empty socket into A empty sockets.
Find the minimum number of power strips required.
Constraints
* All values in input are integers.
* 2 \leq A \leq 20
* 1 \leq B \leq 20
Input
Input is given from Standard Input in the following format:
A B
Output
Print the minimum number of power strips required.
Examples
Input
4 10
Output
3
Input
8 9
Output
2
Input
8 8
Output
1
Submitted Solution:
```
from math import ceil
a,b = map(int,input().split())
print(ceil((b-1)/(a-1)))
``` | instruction | 0 | 71,425 | 8 | 142,850 |
Yes | output | 1 | 71,425 | 8 | 142,851 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi's house has only one socket.
Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
One power strip with A sockets can extend one empty socket into A empty sockets.
Find the minimum number of power strips required.
Constraints
* All values in input are integers.
* 2 \leq A \leq 20
* 1 \leq B \leq 20
Input
Input is given from Standard Input in the following format:
A B
Output
Print the minimum number of power strips required.
Examples
Input
4 10
Output
3
Input
8 9
Output
2
Input
8 8
Output
1
Submitted Solution:
```
import math
a,b = map(int, input().split())
x = b/a
print(math.ceil(x))
``` | instruction | 0 | 71,427 | 8 | 142,854 |
No | output | 1 | 71,427 | 8 | 142,855 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi's house has only one socket.
Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
One power strip with A sockets can extend one empty socket into A empty sockets.
Find the minimum number of power strips required.
Constraints
* All values in input are integers.
* 2 \leq A \leq 20
* 1 \leq B \leq 20
Input
Input is given from Standard Input in the following format:
A B
Output
Print the minimum number of power strips required.
Examples
Input
4 10
Output
3
Input
8 9
Output
2
Input
8 8
Output
1
Submitted Solution:
```
a,b = map(int, input().split())
tap = a
while tap < b:
tap = tap + a-1
return (i + 1)
``` | instruction | 0 | 71,428 | 8 | 142,856 |
No | output | 1 | 71,428 | 8 | 142,857 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi's house has only one socket.
Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
One power strip with A sockets can extend one empty socket into A empty sockets.
Find the minimum number of power strips required.
Constraints
* All values in input are integers.
* 2 \leq A \leq 20
* 1 \leq B \leq 20
Input
Input is given from Standard Input in the following format:
A B
Output
Print the minimum number of power strips required.
Examples
Input
4 10
Output
3
Input
8 9
Output
2
Input
8 8
Output
1
Submitted Solution:
```
#!/usr/bin/env python
# coding: utf-8
def ri():
return int(input())
def rl():
return list(input().split())
def rli():
return list(map(int, input().split()))
def main():
a, b = rli()
print((b+a-1)//a)
if __name__ == '__main__':
main()
``` | instruction | 0 | 71,429 | 8 | 142,858 |
No | output | 1 | 71,429 | 8 | 142,859 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi's house has only one socket.
Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
One power strip with A sockets can extend one empty socket into A empty sockets.
Find the minimum number of power strips required.
Constraints
* All values in input are integers.
* 2 \leq A \leq 20
* 1 \leq B \leq 20
Input
Input is given from Standard Input in the following format:
A B
Output
Print the minimum number of power strips required.
Examples
Input
4 10
Output
3
Input
8 9
Output
2
Input
8 8
Output
1
Submitted Solution:
```
a, b = map(int, input().split())
count = 1
for i in range(20):
if b > count:
count += a-1
else:
break
print(-(-count // a))
``` | instruction | 0 | 71,430 | 8 | 142,860 |
No | output | 1 | 71,430 | 8 | 142,861 |
Provide a correct Python 3 solution for this coding contest problem.
She is an extraordinary girl. She works for a library. Since she is young and cute, she is forced to do a lot of laborious jobs. The most annoying job for her is to put returned books into shelves, carrying them by a cart. The cart is large enough to carry many books, but too heavy for her. Since she is delicate, she wants to walk as short as possible when doing this job. The library has 4N shelves (1 <= N <= 10000), three main passages, and N + 1 sub passages. Each shelf is numbered between 1 to 4N as shown in Figure 1. Horizontal dashed lines correspond to main passages, while vertical dashed lines correspond to sub passages. She starts to return books from the position with white circle in the figure and ends at the position with black circle. For simplicity, assume she can only stop at either the middle of shelves or the intersection of passages. At the middle of shelves, she put books with the same ID as the shelves. For example, when she stops at the middle of shelf 2 and 3, she can put books with ID 2 and 3.
<image>
Since she is so lazy that she doesn’t want to memorize a complicated route, she only walks main passages in forward direction (see an arrow in Figure 1). The walk from an intersection to its adjacent intersections takes 1 cost. It means the walk from the middle of shelves to its adjacent intersection, and vice versa, takes 0.5 cost. You, as only a programmer amoung her friends, are to help her compute the minimum possible cost she takes to put all books in the shelves.
Input
The first line of input contains the number of test cases, T . Then T test cases follow. Each test case consists of two lines. The first line contains the number N , and the second line contains 4N characters, either Y or N . Y in n-th position means there are some books with ID n, and N means no book with ID n.
Output
The output should consists of T lines, each of which contains one integer, the minimum possible cost, for each test case.
Example
Input
2
2
YNNNNYYY
4
NYNNYYNNNYNYYNNN
Output
6
9 | instruction | 0 | 71,524 | 8 | 143,048 |
"Correct Solution:
```
pre = [
((0, 1, 2), (1, 0, 1), (2, 1, 0)),
((3, 2, 2), (2, 1, 1), (2, 1, 1)),
((1, 1, 2), (1, 1, 2), (2, 2, 3)),
((3, 2, 2), (2, 2, 2), (2, 2, 3)),
]
q = int(input())
for _ in range(q):
n = int(input())
books = [c == 'Y' for c in input()]
books = [(0, 0)] + list(zip(books[:2 * n], books[2 * n:])) + [(0, 0)]
shelves = [(u1 | u2) * 2 + (l1 | l2) for (u1, l1), (u2, l2) in zip(*[iter(books)] * 2)]
ans = [0, 1, 2]
for key in shelves:
new_ans = [min(a + c for a, c in zip(ans, costs)) for costs in pre[key]]
ans = new_ans
print(ans[0] + n)
``` | output | 1 | 71,524 | 8 | 143,049 |
Provide a correct Python 3 solution for this coding contest problem.
She is an extraordinary girl. She works for a library. Since she is young and cute, she is forced to do a lot of laborious jobs. The most annoying job for her is to put returned books into shelves, carrying them by a cart. The cart is large enough to carry many books, but too heavy for her. Since she is delicate, she wants to walk as short as possible when doing this job. The library has 4N shelves (1 <= N <= 10000), three main passages, and N + 1 sub passages. Each shelf is numbered between 1 to 4N as shown in Figure 1. Horizontal dashed lines correspond to main passages, while vertical dashed lines correspond to sub passages. She starts to return books from the position with white circle in the figure and ends at the position with black circle. For simplicity, assume she can only stop at either the middle of shelves or the intersection of passages. At the middle of shelves, she put books with the same ID as the shelves. For example, when she stops at the middle of shelf 2 and 3, she can put books with ID 2 and 3.
<image>
Since she is so lazy that she doesn’t want to memorize a complicated route, she only walks main passages in forward direction (see an arrow in Figure 1). The walk from an intersection to its adjacent intersections takes 1 cost. It means the walk from the middle of shelves to its adjacent intersection, and vice versa, takes 0.5 cost. You, as only a programmer amoung her friends, are to help her compute the minimum possible cost she takes to put all books in the shelves.
Input
The first line of input contains the number of test cases, T . Then T test cases follow. Each test case consists of two lines. The first line contains the number N , and the second line contains 4N characters, either Y or N . Y in n-th position means there are some books with ID n, and N means no book with ID n.
Output
The output should consists of T lines, each of which contains one integer, the minimum possible cost, for each test case.
Example
Input
2
2
YNNNNYYY
4
NYNNYYNNNYNYYNNN
Output
6
9 | instruction | 0 | 71,525 | 8 | 143,050 |
"Correct Solution:
```
# AOJ 1002: Extraordinary Girl I
# Python3 2018.7.5 bal4u
import sys
from sys import stdin
input = stdin.readline
INF = 0x7fffffff
cost = ((((0,3),(1,3)),((1,2),(1,2)),((2,2),(2,2))),
(((1,2),(1,2)),((0,1),(1,2)),((1,1),(2,2))),
(((2,2),(2,2)),((1,1),(2,2)),((0,1),(3,3))))
for cno in range(int(input())):
n = int(input())
n2 = n << 1
shelf = [[0 for j in range(n+2)] for i in range(2)]
p = input()
for i in range(n2):
if p[i] == 'Y': shelf[0][(i+1)>>1] = 1
for i in range(n2):
if p[n2+i] == 'Y': shelf[1][(i+1)>>1] = 1
dp = [[INF for j in range(n+2)] for i in range(3)]
dp[0][0] = 0
for i in range(n+1):
for j in range(9):
dp[j%3][i+1] = min(dp[j%3][i+1], dp[j//3][i]+cost[j//3][j%3][shelf[0][i]][shelf[1][i]]+1)
print(dp[0][n+1]-1)
``` | output | 1 | 71,525 | 8 | 143,051 |
Provide a correct Python 3 solution for this coding contest problem.
She is an extraordinary girl. She works for a library. Since she is young and cute, she is forced to do a lot of laborious jobs. The most annoying job for her is to put returned books into shelves, carrying them by a cart. The cart is large enough to carry many books, but too heavy for her. Since she is delicate, she wants to walk as short as possible when doing this job. The library has 4N shelves (1 <= N <= 10000), three main passages, and N + 1 sub passages. Each shelf is numbered between 1 to 4N as shown in Figure 1. Horizontal dashed lines correspond to main passages, while vertical dashed lines correspond to sub passages. She starts to return books from the position with white circle in the figure and ends at the position with black circle. For simplicity, assume she can only stop at either the middle of shelves or the intersection of passages. At the middle of shelves, she put books with the same ID as the shelves. For example, when she stops at the middle of shelf 2 and 3, she can put books with ID 2 and 3.
<image>
Since she is so lazy that she doesn’t want to memorize a complicated route, she only walks main passages in forward direction (see an arrow in Figure 1). The walk from an intersection to its adjacent intersections takes 1 cost. It means the walk from the middle of shelves to its adjacent intersection, and vice versa, takes 0.5 cost. You, as only a programmer amoung her friends, are to help her compute the minimum possible cost she takes to put all books in the shelves.
Input
The first line of input contains the number of test cases, T . Then T test cases follow. Each test case consists of two lines. The first line contains the number N , and the second line contains 4N characters, either Y or N . Y in n-th position means there are some books with ID n, and N means no book with ID n.
Output
The output should consists of T lines, each of which contains one integer, the minimum possible cost, for each test case.
Example
Input
2
2
YNNNNYYY
4
NYNNYYNNNYNYYNNN
Output
6
9 | instruction | 0 | 71,526 | 8 | 143,052 |
"Correct Solution:
```
pre = [
((0, 1, 2), (1, 0, 1), (2, 1, 0)),
((3, 2, 2), (2, 1, 1), (2, 1, 1)),
((1, 1, 2), (1, 1, 2), (2, 2, 3)),
((3, 2, 2), (2, 2, 2), (2, 2, 3)),
]
q = int(input())
for _ in range(q):
n = int(input())
books = [c == 'Y' for c in input()]
books = [(False, False)] + list(map(lambda u, l: (u, l), books[:2 * n], books[2 * n:])) + [(False, False)]
shelves = [int(u1 or u2) * 2 + int(l1 or l2) for (u1, l1), (u2, l2) in zip(*[iter(books)] * 2)]
ans = [0, 1, 2]
for key in shelves:
new_ans = [min(a + c for a, c in zip(ans, costs)) for costs in pre[key]]
ans = new_ans
print(ans[0] + n)
``` | output | 1 | 71,526 | 8 | 143,053 |
Provide a correct Python 3 solution for this coding contest problem.
She is an extraordinary girl. She works for a library. Since she is young and cute, she is forced to do a lot of laborious jobs. The most annoying job for her is to put returned books into shelves, carrying them by a cart. The cart is large enough to carry many books, but too heavy for her. Since she is delicate, she wants to walk as short as possible when doing this job. The library has 4N shelves (1 <= N <= 10000), three main passages, and N + 1 sub passages. Each shelf is numbered between 1 to 4N as shown in Figure 1. Horizontal dashed lines correspond to main passages, while vertical dashed lines correspond to sub passages. She starts to return books from the position with white circle in the figure and ends at the position with black circle. For simplicity, assume she can only stop at either the middle of shelves or the intersection of passages. At the middle of shelves, she put books with the same ID as the shelves. For example, when she stops at the middle of shelf 2 and 3, she can put books with ID 2 and 3.
<image>
Since she is so lazy that she doesn’t want to memorize a complicated route, she only walks main passages in forward direction (see an arrow in Figure 1). The walk from an intersection to its adjacent intersections takes 1 cost. It means the walk from the middle of shelves to its adjacent intersection, and vice versa, takes 0.5 cost. You, as only a programmer amoung her friends, are to help her compute the minimum possible cost she takes to put all books in the shelves.
Input
The first line of input contains the number of test cases, T . Then T test cases follow. Each test case consists of two lines. The first line contains the number N , and the second line contains 4N characters, either Y or N . Y in n-th position means there are some books with ID n, and N means no book with ID n.
Output
The output should consists of T lines, each of which contains one integer, the minimum possible cost, for each test case.
Example
Input
2
2
YNNNNYYY
4
NYNNYYNNNYNYYNNN
Output
6
9 | instruction | 0 | 71,527 | 8 | 143,054 |
"Correct Solution:
```
from operator import add
pre = [
((0, 1, 2), (1, 0, 1), (2, 1, 0)),
((3, 2, 2), (2, 1, 1), (2, 1, 1)),
((1, 1, 2), (1, 1, 2), (2, 2, 3)),
((3, 2, 2), (2, 2, 2), (2, 2, 3)),
]
q = int(input())
for _ in range(q):
n = int(input())
books = [c == 'Y' for c in input()]
books = [(0, 0)] + list(zip(books[:2 * n], books[2 * n:])) + [(0, 0)]
shelves = [(u1 | u2) * 2 + (l1 | l2) for (u1, l1), (u2, l2) in zip(*[iter(books)] * 2)]
ans = [0, 1, 2]
for key in shelves:
new_ans = [min(map(add, ans, costs)) for costs in pre[key]]
ans = new_ans
print(ans[0] + n)
``` | output | 1 | 71,527 | 8 | 143,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
She is an extraordinary girl. She works for a library. Since she is young and cute, she is forced to do a lot of laborious jobs. The most annoying job for her is to put returned books into shelves, carrying them by a cart. The cart is large enough to carry many books, but too heavy for her. Since she is delicate, she wants to walk as short as possible when doing this job. The library has 4N shelves (1 <= N <= 10000), three main passages, and N + 1 sub passages. Each shelf is numbered between 1 to 4N as shown in Figure 1. Horizontal dashed lines correspond to main passages, while vertical dashed lines correspond to sub passages. She starts to return books from the position with white circle in the figure and ends at the position with black circle. For simplicity, assume she can only stop at either the middle of shelves or the intersection of passages. At the middle of shelves, she put books with the same ID as the shelves. For example, when she stops at the middle of shelf 2 and 3, she can put books with ID 2 and 3.
<image>
Since she is so lazy that she doesn’t want to memorize a complicated route, she only walks main passages in forward direction (see an arrow in Figure 1). The walk from an intersection to its adjacent intersections takes 1 cost. It means the walk from the middle of shelves to its adjacent intersection, and vice versa, takes 0.5 cost. You, as only a programmer amoung her friends, are to help her compute the minimum possible cost she takes to put all books in the shelves.
Input
The first line of input contains the number of test cases, T . Then T test cases follow. Each test case consists of two lines. The first line contains the number N , and the second line contains 4N characters, either Y or N . Y in n-th position means there are some books with ID n, and N means no book with ID n.
Output
The output should consists of T lines, each of which contains one integer, the minimum possible cost, for each test case.
Example
Input
2
2
YNNNNYYY
4
NYNNYYNNNYNYYNNN
Output
6
9
Submitted Solution:
```
pre = [
((0, 1, 2), (1, 0, 1), (2, 1, 0)),
((3, 2, 2), (2, 1, 1), (2, 1, 1)),
((1, 1, 2), (1, 1, 2), (2, 2, 3)),
((3, 2, 2), (2, 2, 2), (2, 2, 3)),
]
queries = int(input())
for _ in range(queries):
n = int(input())
books = [c == 'Y' for c in input()]
books = [(False, False)] + list(map(lambda u, l: (u, l), books[:2 * n], books[2 * n:])) + [(False, False)]
shelves = [int(u1 or u2) * 2 + int(l1 or l2) for (u1, l1), (u2, l2) in zip(*[iter(books)] * 2)]
ans = [0, 0, 0]
for key in shelves:
new_ans = [min(ans[j] + c for j, c in enumerate(costs)) + 1 for costs in pre[key]]
ans = new_ans
print(ans[0] - 1)
``` | instruction | 0 | 71,528 | 8 | 143,056 |
No | output | 1 | 71,528 | 8 | 143,057 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
She is an extraordinary girl. She works for a library. Since she is young and cute, she is forced to do a lot of laborious jobs. The most annoying job for her is to put returned books into shelves, carrying them by a cart. The cart is large enough to carry many books, but too heavy for her. Since she is delicate, she wants to walk as short as possible when doing this job. The library has 4N shelves (1 <= N <= 10000), three main passages, and N + 1 sub passages. Each shelf is numbered between 1 to 4N as shown in Figure 1. Horizontal dashed lines correspond to main passages, while vertical dashed lines correspond to sub passages. She starts to return books from the position with white circle in the figure and ends at the position with black circle. For simplicity, assume she can only stop at either the middle of shelves or the intersection of passages. At the middle of shelves, she put books with the same ID as the shelves. For example, when she stops at the middle of shelf 2 and 3, she can put books with ID 2 and 3.
<image>
Since she is so lazy that she doesn’t want to memorize a complicated route, she only walks main passages in forward direction (see an arrow in Figure 1). The walk from an intersection to its adjacent intersections takes 1 cost. It means the walk from the middle of shelves to its adjacent intersection, and vice versa, takes 0.5 cost. You, as only a programmer amoung her friends, are to help her compute the minimum possible cost she takes to put all books in the shelves.
Input
The first line of input contains the number of test cases, T . Then T test cases follow. Each test case consists of two lines. The first line contains the number N , and the second line contains 4N characters, either Y or N . Y in n-th position means there are some books with ID n, and N means no book with ID n.
Output
The output should consists of T lines, each of which contains one integer, the minimum possible cost, for each test case.
Example
Input
2
2
YNNNNYYY
4
NYNNYYNNNYNYYNNN
Output
6
9
Submitted Solution:
```
pre = [
((0, 1, 2), (1, 0, 1), (2, 1, 0)),
((3, 2, 2), (2, 1, 1), (2, 1, 1)),
((1, 1, 2), (1, 1, 2), (2, 2, 3)),
((3, 2, 2), (2, 2, 2), (2, 2, 3)),
]
q = int(input())
for _ in range(q):
n = int(input())
books = [c == 'Y' for c in input()]
books = [(False, False)] + list(map(lambda u, l: (u, l), books[:2 * n], books[2 * n:])) + [(False, False)]
shelves = [int(u1 or u2) * 2 + int(l1 or l2) for (u1, l1), (u2, l2) in zip(*[iter(books)] * 2)]
ans = [0, 0, 0]
for key in shelves:
new_ans = [min(a + c for a, c in zip(ans, costs)) for costs in pre[key]]
ans = new_ans
print(ans[0] + n)
``` | instruction | 0 | 71,529 | 8 | 143,058 |
No | output | 1 | 71,529 | 8 | 143,059 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
She is an extraordinary girl. She works for a library. Since she is young and cute, she is forced to do a lot of laborious jobs. The most annoying job for her is to put returned books into shelves, carrying them by a cart. The cart is large enough to carry many books, but too heavy for her. Since she is delicate, she wants to walk as short as possible when doing this job. The library has 4N shelves (1 <= N <= 10000), three main passages, and N + 1 sub passages. Each shelf is numbered between 1 to 4N as shown in Figure 1. Horizontal dashed lines correspond to main passages, while vertical dashed lines correspond to sub passages. She starts to return books from the position with white circle in the figure and ends at the position with black circle. For simplicity, assume she can only stop at either the middle of shelves or the intersection of passages. At the middle of shelves, she put books with the same ID as the shelves. For example, when she stops at the middle of shelf 2 and 3, she can put books with ID 2 and 3.
<image>
Since she is so lazy that she doesn’t want to memorize a complicated route, she only walks main passages in forward direction (see an arrow in Figure 1). The walk from an intersection to its adjacent intersections takes 1 cost. It means the walk from the middle of shelves to its adjacent intersection, and vice versa, takes 0.5 cost. You, as only a programmer amoung her friends, are to help her compute the minimum possible cost she takes to put all books in the shelves.
Input
The first line of input contains the number of test cases, T . Then T test cases follow. Each test case consists of two lines. The first line contains the number N , and the second line contains 4N characters, either Y or N . Y in n-th position means there are some books with ID n, and N means no book with ID n.
Output
The output should consists of T lines, each of which contains one integer, the minimum possible cost, for each test case.
Example
Input
2
2
YNNNNYYY
4
NYNNYYNNNYNYYNNN
Output
6
9
Submitted Solution:
```
pre = [
((0, 1, 2), (1, 0, 1), (2, 1, 0)),
((3, 2, 2), (2, 1, 1), (2, 1, 1)),
((1, 1, 2), (1, 1, 2), (2, 2, 3)),
((3, 2, 2), (2, 2, 2), (2, 2, 3)),
]
queries = int(input())
for _ in range(queries):
n = int(input())
books = [c == 'Y' for c in input()]
books = [(False, False)] + list(map(lambda u, l: (u, l), books[:2 * n], books[2 * n:])) + [(False, False)]
shelves = [int(u1 or u2) * 2 + int(l1 or l2) for (u1, l1), (u2, l2) in zip(*[iter(books)] * 2)]
ans = [0, 0, 0]
for key in shelves:
ans = [min(ans[j] + c for j, c in enumerate(costs)) + 1 for costs in pre[key]]
print(ans[0] - 1)
``` | instruction | 0 | 71,530 | 8 | 143,060 |
No | output | 1 | 71,530 | 8 | 143,061 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output
Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
Examples
Input
5 4
4 3 1 2
Output
1 1 3 4 4
Input
5 5
5 4 3 2 1
Output
1 2 3 4 5
Note
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off. | instruction | 0 | 72,017 | 8 | 144,034 |
Tags: implementation
Correct Solution:
```
n,m=map(int,input().split())
b=list(map(int,input().split()))
a=[]
upper=n+1
for i in range(n):
a.append(0)
for i in b:
if i<=upper:
for j in range(i-1,upper-1):
a[j]=i
upper=i
for i in a:
print(i, end =" ")
``` | output | 1 | 72,017 | 8 | 144,035 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output
Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
Examples
Input
5 4
4 3 1 2
Output
1 1 3 4 4
Input
5 5
5 4 3 2 1
Output
1 2 3 4 5
Note
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off. | instruction | 0 | 72,018 | 8 | 144,036 |
Tags: implementation
Correct Solution:
```
n, m = tuple(map(int, input().strip().split()))
b = tuple(map(int, input().strip().split()))
res = [0 for _ in range(n)]
for b_i in b:
for i in range(b_i-1, n):
if res[i]==0:
res[i] = b_i
print(' '.join(map(str,res)))
``` | output | 1 | 72,018 | 8 | 144,037 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output
Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
Examples
Input
5 4
4 3 1 2
Output
1 1 3 4 4
Input
5 5
5 4 3 2 1
Output
1 2 3 4 5
Note
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off. | instruction | 0 | 72,019 | 8 | 144,038 |
Tags: implementation
Correct Solution:
```
n, m = map(int, input().split())
b = list(map(int, input().split()))
ans = [0] * (n + 1)
for x in b:
for i in range(x, n + 1):
if ans[i] == 0:
ans[i] = x
print(*ans[1:])
``` | output | 1 | 72,019 | 8 | 144,039 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output
Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
Examples
Input
5 4
4 3 1 2
Output
1 1 3 4 4
Input
5 5
5 4 3 2 1
Output
1 2 3 4 5
Note
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off. | instruction | 0 | 72,020 | 8 | 144,040 |
Tags: implementation
Correct Solution:
```
a,b = map(int,input().split())
l = list(map(int,input().split()))
k = b+1
for i in range(a):
for j in range(b):
if l[j] <= i+1:
print(l[j],end=" ")
break
``` | output | 1 | 72,020 | 8 | 144,041 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output
Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
Examples
Input
5 4
4 3 1 2
Output
1 1 3 4 4
Input
5 5
5 4 3 2 1
Output
1 2 3 4 5
Note
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off. | instruction | 0 | 72,021 | 8 | 144,042 |
Tags: implementation
Correct Solution:
```
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*n
for i in range(m):
num=a[i]
while num<=len(b) and b[num-1]==0:
b[num-1]=a[i]
num+=1
for i in range(len(b)):
print(b[i],end=' ')
``` | output | 1 | 72,021 | 8 | 144,043 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output
Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
Examples
Input
5 4
4 3 1 2
Output
1 1 3 4 4
Input
5 5
5 4 3 2 1
Output
1 2 3 4 5
Note
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off. | instruction | 0 | 72,022 | 8 | 144,044 |
Tags: implementation
Correct Solution:
```
n, b = [int(x) for x in input().split()];lights_order = [int(x) for x in input().split()]
prev_light = n
arr = [n] * n
for light in lights_order:
if(light < prev_light+1):
arr[light-1:prev_light] = [light]*(prev_light-light+1)
prev_light = light-1
if(light == 1):
break
print(*arr)
``` | output | 1 | 72,022 | 8 | 144,045 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output
Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
Examples
Input
5 4
4 3 1 2
Output
1 1 3 4 4
Input
5 5
5 4 3 2 1
Output
1 2 3 4 5
Note
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off. | instruction | 0 | 72,023 | 8 | 144,046 |
Tags: implementation
Correct Solution:
```
n , m = map(int, input().split())
light = list(map(int, input().split()))
ans = n*[0]
for i in light:
temp = i
while temp<n and ans[temp-1]==0:
ans[temp-1]=i
temp = temp+1
ans.remove(ans[-1])
ans.append(light[0])
print(*ans, sep=" ")
``` | output | 1 | 72,023 | 8 | 144,047 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output
Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
Examples
Input
5 4
4 3 1 2
Output
1 1 3 4 4
Input
5 5
5 4 3 2 1
Output
1 2 3 4 5
Note
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off. | instruction | 0 | 72,024 | 8 | 144,048 |
Tags: implementation
Correct Solution:
```
n,m = map(int, input().split())
l = [-1]*(n+1)
x = list(map(int, input().split()))
for i in range(m):
for j in range(x[i], n+1):
if l[j] != -1:
break
l[j] = str(x[i])
print(' '.join(l[1:]))
``` | output | 1 | 72,024 | 8 | 144,049 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output
Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
Examples
Input
5 4
4 3 1 2
Output
1 1 3 4 4
Input
5 5
5 4 3 2 1
Output
1 2 3 4 5
Note
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.
Submitted Solution:
```
n,m=map(int,input().split())
l=list(map(int,input().split()))
emp=[]
im=[]
for i in l:
for j in range(i,n+1):
if j not in emp:
emp.append(j)
im.append((j,i))
im.sort()
for ele in im:
print(ele[1],end=' ')
``` | instruction | 0 | 72,025 | 8 | 144,050 |
Yes | output | 1 | 72,025 | 8 | 144,051 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output
Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
Examples
Input
5 4
4 3 1 2
Output
1 1 3 4 4
Input
5 5
5 4 3 2 1
Output
1 2 3 4 5
Note
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.
Submitted Solution:
```
n,m = map(int,input().split())
L = [-1] * n
A = list(map(int,input().split()))
for a in A:
for i in range(a - 1, len(L)):
if L[i] == -1:
L[i] = a
for l in L:
print(l,end= ' ')
``` | instruction | 0 | 72,026 | 8 | 144,052 |
Yes | output | 1 | 72,026 | 8 | 144,053 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output
Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
Examples
Input
5 4
4 3 1 2
Output
1 1 3 4 4
Input
5 5
5 4 3 2 1
Output
1 2 3 4 5
Note
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.
Submitted Solution:
```
n,m=[int(x) for x in input().split(" ")]
l=[int(x) for x in input().split(" ")]
for i in range(1,n+1):
for x in l:
if x<=i:
print(x,end=" ")
break
``` | instruction | 0 | 72,027 | 8 | 144,054 |
Yes | output | 1 | 72,027 | 8 | 144,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output
Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
Examples
Input
5 4
4 3 1 2
Output
1 1 3 4 4
Input
5 5
5 4 3 2 1
Output
1 2 3 4 5
Note
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.
Submitted Solution:
```
n,m = map(int,input().split())
b = list(map(int,input().split()))
chk = [-1]*(n)
ans = [-1]*(n)
for i in b:
for j in range(i,n+1):
if chk[j-1] == -1:
ans[j-1] = i
chk[j-1] = 0
print(*ans)
``` | instruction | 0 | 72,028 | 8 | 144,056 |
Yes | output | 1 | 72,028 | 8 | 144,057 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output
Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
Examples
Input
5 4
4 3 1 2
Output
1 1 3 4 4
Input
5 5
5 4 3 2 1
Output
1 2 3 4 5
Note
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.
Submitted Solution:
```
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(n):
for j in range(len(a)):
if a[j] <= i:
b.append(a[j])
break
print(*b)
``` | instruction | 0 | 72,029 | 8 | 144,058 |
No | output | 1 | 72,029 | 8 | 144,059 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output
Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
Examples
Input
5 4
4 3 1 2
Output
1 1 3 4 4
Input
5 5
5 4 3 2 1
Output
1 2 3 4 5
Note
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.
Submitted Solution:
```
n, m=map(int, input().split())
b=list(map(int, input().split()))
ans=[-1]*101
for bb in b:
for i in range(bb, n+1):
if ans[i]==-1:
ans[i]=bb
print(*ans[0:n+1])
``` | instruction | 0 | 72,030 | 8 | 144,060 |
No | output | 1 | 72,030 | 8 | 144,061 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output
Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.
Examples
Input
5 4
4 3 1 2
Output
1 1 3 4 4
Input
5 5
5 4 3 2 1
Output
1 2 3 4 5
Note
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.
Submitted Solution:
```
n, m = map(int, input().split())
l = list(map(int, input().split(' ')))
l = l[::-1]
j = []
for i in range(n):
j.append(' ')
for i in l:
for k in range(i,n+1):
j[k-1] = i
print(j)
``` | instruction | 0 | 72,031 | 8 | 144,062 |
No | output | 1 | 72,031 | 8 | 144,063 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.