message stringlengths 2 43.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 853 107k | cluster float64 24 24 | __index_level_0__ int64 1.71k 214k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way: <image> (for i β₯ 1). Here a, b, m are constants, fixed for the given realization of the pseudorandom numbers generator, r0 is the so-called randseed (this value can be set from the program using functions like RandSeed(r) or srand(n)), and <image> denotes the operation of taking the remainder of division.
For example, if a = 2, b = 6, m = 12, r0 = 11, the generated sequence will be: 4, 2, 10, 2, 10, 2, 10, 2, 10, 2, 10, ....
Polycarpus realized that any such sequence will sooner or later form a cycle, but the cycle may occur not in the beginning, so there exist a preperiod and a period. The example above shows a preperiod equal to 1 and a period equal to 2.
Your task is to find the period of a sequence defined by the given values of a, b, m and r0. Formally, you have to find such minimum positive integer t, for which exists such positive integer k, that for any i β₯ k: ri = ri + t.
Input
The single line of the input contains four integers a, b, m and r0 (1 β€ m β€ 105, 0 β€ a, b β€ 1000, 0 β€ r0 < m), separated by single spaces.
Output
Print a single integer β the period of the sequence.
Examples
Input
2 6 12 11
Output
2
Input
2 3 5 1
Output
4
Input
3 6 81 9
Output
1
Note
The first sample is described above.
In the second sample the sequence is (starting from the first element): 0, 3, 4, 1, 0, 3, 4, 1, 0, ...
In the third sample the sequence is (starting from the first element): 33, 24, 78, 78, 78, 78, ...
Submitted Solution:
```
ABMR = list(map(int, input().split()))
print(ABMR)
a = ABMR[0]
b = ABMR[1]
m = ABMR[2]
r0 = ABMR[3]
h = {}
i = 0
prev_r = r0
while True:
cur_r = ( a * prev_r + b ) % m
# print(cur_r)
if h.get(cur_r, 0) != 0:
print(i - h[cur_r])
break
else:
h[cur_r] = i
prev_r = cur_r
i += 1
``` | instruction | 0 | 48,179 | 24 | 96,358 |
No | output | 1 | 48,179 | 24 | 96,359 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way: <image> (for i β₯ 1). Here a, b, m are constants, fixed for the given realization of the pseudorandom numbers generator, r0 is the so-called randseed (this value can be set from the program using functions like RandSeed(r) or srand(n)), and <image> denotes the operation of taking the remainder of division.
For example, if a = 2, b = 6, m = 12, r0 = 11, the generated sequence will be: 4, 2, 10, 2, 10, 2, 10, 2, 10, 2, 10, ....
Polycarpus realized that any such sequence will sooner or later form a cycle, but the cycle may occur not in the beginning, so there exist a preperiod and a period. The example above shows a preperiod equal to 1 and a period equal to 2.
Your task is to find the period of a sequence defined by the given values of a, b, m and r0. Formally, you have to find such minimum positive integer t, for which exists such positive integer k, that for any i β₯ k: ri = ri + t.
Input
The single line of the input contains four integers a, b, m and r0 (1 β€ m β€ 105, 0 β€ a, b β€ 1000, 0 β€ r0 < m), separated by single spaces.
Output
Print a single integer β the period of the sequence.
Examples
Input
2 6 12 11
Output
2
Input
2 3 5 1
Output
4
Input
3 6 81 9
Output
1
Note
The first sample is described above.
In the second sample the sequence is (starting from the first element): 0, 3, 4, 1, 0, 3, 4, 1, 0, ...
In the third sample the sequence is (starting from the first element): 33, 24, 78, 78, 78, 78, ...
Submitted Solution:
```
a, b, m, r = map(int, input().split())
l=list()
temp=r
l.append(temp)
flag=0
p=0
for i in range(100):
temp = (a*temp+b)%m
for j in range(len(l)):
if l[j]==temp:
flag=1
p=j
break
if flag==1:
print(len(l)-p)
break
else:
l.append(temp)
``` | instruction | 0 | 48,180 | 24 | 96,360 |
No | output | 1 | 48,180 | 24 | 96,361 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way: <image> (for i β₯ 1). Here a, b, m are constants, fixed for the given realization of the pseudorandom numbers generator, r0 is the so-called randseed (this value can be set from the program using functions like RandSeed(r) or srand(n)), and <image> denotes the operation of taking the remainder of division.
For example, if a = 2, b = 6, m = 12, r0 = 11, the generated sequence will be: 4, 2, 10, 2, 10, 2, 10, 2, 10, 2, 10, ....
Polycarpus realized that any such sequence will sooner or later form a cycle, but the cycle may occur not in the beginning, so there exist a preperiod and a period. The example above shows a preperiod equal to 1 and a period equal to 2.
Your task is to find the period of a sequence defined by the given values of a, b, m and r0. Formally, you have to find such minimum positive integer t, for which exists such positive integer k, that for any i β₯ k: ri = ri + t.
Input
The single line of the input contains four integers a, b, m and r0 (1 β€ m β€ 105, 0 β€ a, b β€ 1000, 0 β€ r0 < m), separated by single spaces.
Output
Print a single integer β the period of the sequence.
Examples
Input
2 6 12 11
Output
2
Input
2 3 5 1
Output
4
Input
3 6 81 9
Output
1
Note
The first sample is described above.
In the second sample the sequence is (starting from the first element): 0, 3, 4, 1, 0, 3, 4, 1, 0, ...
In the third sample the sequence is (starting from the first element): 33, 24, 78, 78, 78, 78, ...
Submitted Solution:
```
a,b,m,r=map(int,input().split())
ss=[]
l=r
start=0
cnt=(10**3)+1
while cnt:
s=(a*l+b)%m
l=s
ss.append(l)
cnt-=1
cnt=0
s=set(ss)
for i in s:
if ss.count(i)>1:
cnt+=1
print(cnt)
``` | instruction | 0 | 48,181 | 24 | 96,362 |
No | output | 1 | 48,181 | 24 | 96,363 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way: <image> (for i β₯ 1). Here a, b, m are constants, fixed for the given realization of the pseudorandom numbers generator, r0 is the so-called randseed (this value can be set from the program using functions like RandSeed(r) or srand(n)), and <image> denotes the operation of taking the remainder of division.
For example, if a = 2, b = 6, m = 12, r0 = 11, the generated sequence will be: 4, 2, 10, 2, 10, 2, 10, 2, 10, 2, 10, ....
Polycarpus realized that any such sequence will sooner or later form a cycle, but the cycle may occur not in the beginning, so there exist a preperiod and a period. The example above shows a preperiod equal to 1 and a period equal to 2.
Your task is to find the period of a sequence defined by the given values of a, b, m and r0. Formally, you have to find such minimum positive integer t, for which exists such positive integer k, that for any i β₯ k: ri = ri + t.
Input
The single line of the input contains four integers a, b, m and r0 (1 β€ m β€ 105, 0 β€ a, b β€ 1000, 0 β€ r0 < m), separated by single spaces.
Output
Print a single integer β the period of the sequence.
Examples
Input
2 6 12 11
Output
2
Input
2 3 5 1
Output
4
Input
3 6 81 9
Output
1
Note
The first sample is described above.
In the second sample the sequence is (starting from the first element): 0, 3, 4, 1, 0, 3, 4, 1, 0, ...
In the third sample the sequence is (starting from the first element): 33, 24, 78, 78, 78, 78, ...
Submitted Solution:
```
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def MAP2():return map(float,input().split())
def LIST(): return list(map(int, input().split()))
def STRING(): return input()
import string
import sys
import datetime
from heapq import heappop , heappush
from bisect import *
from collections import deque , Counter , defaultdict
from math import *
from itertools import permutations , accumulate
dx = [-1 , 1 , 0 , 0 ]
dy = [0 , 0 , 1 , - 1]
#visited = [[False for i in range(m)] for j in range(n)]
# primes = [2,11,101,1009,10007,100003,1000003,10000019,102345689]
#months = [31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31, 30 , 31]
#sys.stdin = open(r'input.txt' , 'r')
#sys.stdout = open(r'output.txt' , 'w')
#for tt in range(INT()):
#arr.sort(key=lambda x: (-d[x], x)) Sort with Freq
#Code
def solve(a , b , m , r):
k = ( ((a * r) % m) + (b % m )) % m
return k
a , b , m , r = MAP()
d = {}
for i in range(10**5 + 1):
k = (solve(a , b , m , r))
d[k] = d.get(k , 0) + 1
r = k
#print(d)
cnt = 0
for i in d :
if d[i] > 1 :
cnt +=1
print(cnt)
``` | instruction | 0 | 48,182 | 24 | 96,364 |
No | output | 1 | 48,182 | 24 | 96,365 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input
The first line contains two integers, w and h (1 β€ w, h β€ 100) β the width and height of an image in pixels. The picture is given in h lines, each line contains w characters β each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output
Print 2w lines, each containing 2h characters β the result of consecutive implementing of the three transformations, described above.
Examples
Input
3 2
.*.
.*.
Output
....
....
****
****
....
....
Input
9 20
**.......
****.....
******...
*******..
..******.
....****.
......***
*.....***
*********
*********
*********
*********
....**...
...****..
..******.
.********
****..***
***...***
**.....**
*.......*
Output
********......**********........********
********......**********........********
********........********......********..
********........********......********..
..********......********....********....
..********......********....********....
..********......********..********......
..********......********..********......
....********....****************........
....********....****************........
....********....****************........
....********....****************........
......******************..**********....
......******************..**********....
........****************....**********..
........****************....**********..
............************......**********
............************......********** | instruction | 0 | 48,318 | 24 | 96,636 |
Tags: *special, implementation
Correct Solution:
```
n,m=map(int,input().split())
array=[]
array1=[]
array2=[]
for i in range(m):
s=input()
array+=[s]
for j in range(n):
s=''
for i in range(m):
s+=array[i][j]
array1+=[s]
array2+=[s]
q=len(array1)
array=[]
for i in range(q):
array+=[array1[i]]
array+=[array2[i]]
array1=[]
for i in range(2*n):
s=''
for j in range(m):
s+=array[i][j]
s+=array[i][j]
array1+=[s]
for i in range(len(array)):
print(array1[i])
``` | output | 1 | 48,318 | 24 | 96,637 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input
The first line contains two integers, w and h (1 β€ w, h β€ 100) β the width and height of an image in pixels. The picture is given in h lines, each line contains w characters β each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output
Print 2w lines, each containing 2h characters β the result of consecutive implementing of the three transformations, described above.
Examples
Input
3 2
.*.
.*.
Output
....
....
****
****
....
....
Input
9 20
**.......
****.....
******...
*******..
..******.
....****.
......***
*.....***
*********
*********
*********
*********
....**...
...****..
..******.
.********
****..***
***...***
**.....**
*.......*
Output
********......**********........********
********......**********........********
********........********......********..
********........********......********..
..********......********....********....
..********......********....********....
..********......********..********......
..********......********..********......
....********....****************........
....********....****************........
....********....****************........
....********....****************........
......******************..**********....
......******************..**********....
........****************....**********..
........****************....**********..
............************......**********
............************......********** | instruction | 0 | 48,319 | 24 | 96,638 |
Tags: *special, implementation
Correct Solution:
```
s=input()
w=int(s.split()[0])
h=int(s.split()[1])
L=[]
L2=[]
s2=''
for i in(range(h)):
L.append(input())
for i in(range(w)):
for k in(range(h-1,-1,-1)):
s2=s2+L[k][i]
L2.append(s2)
s2=''
L3=[]
s3=''
for i in((range(w))):
for k in((range(h-1,-1,-1))):
s3=s3+L2[i][k]
L3.append(s3)
s3=''
L4=[]
for i in((range(w))):
for k in((range(h))):
s3=s3+((L3[i][k]*2))
L4.append(s3)
L4.append(s3)
s3=''
w2=w*2
for i in (range(w2)):
print(L4[i])
``` | output | 1 | 48,319 | 24 | 96,639 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input
The first line contains two integers, w and h (1 β€ w, h β€ 100) β the width and height of an image in pixels. The picture is given in h lines, each line contains w characters β each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output
Print 2w lines, each containing 2h characters β the result of consecutive implementing of the three transformations, described above.
Examples
Input
3 2
.*.
.*.
Output
....
....
****
****
....
....
Input
9 20
**.......
****.....
******...
*******..
..******.
....****.
......***
*.....***
*********
*********
*********
*********
....**...
...****..
..******.
.********
****..***
***...***
**.....**
*.......*
Output
********......**********........********
********......**********........********
********........********......********..
********........********......********..
..********......********....********....
..********......********....********....
..********......********..********......
..********......********..********......
....********....****************........
....********....****************........
....********....****************........
....********....****************........
......******************..**********....
......******************..**********....
........****************....**********..
........****************....**********..
............************......**********
............************......********** | instruction | 0 | 48,320 | 24 | 96,640 |
Tags: *special, implementation
Correct Solution:
```
#!/usr/bin/python3
w, h = map(int, input().split())
arr = [list(input()) for i in range(h)]
rotated_and_mirrored = [[arr[i][j] for i in range(h)] for j in range(w)]
ans = [["" for i in range(2 * h)] for j in range(2 * w)]
for i in range(w):
for j in range(h):
for dx in range(2):
for dy in range(2):
ans[2 * i + dx][2 * j + dy] = rotated_and_mirrored[i][j]
print("\n".join(map(lambda x : "".join(x), ans)))
``` | output | 1 | 48,320 | 24 | 96,641 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input
The first line contains two integers, w and h (1 β€ w, h β€ 100) β the width and height of an image in pixels. The picture is given in h lines, each line contains w characters β each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output
Print 2w lines, each containing 2h characters β the result of consecutive implementing of the three transformations, described above.
Examples
Input
3 2
.*.
.*.
Output
....
....
****
****
....
....
Input
9 20
**.......
****.....
******...
*******..
..******.
....****.
......***
*.....***
*********
*********
*********
*********
....**...
...****..
..******.
.********
****..***
***...***
**.....**
*.......*
Output
********......**********........********
********......**********........********
********........********......********..
********........********......********..
..********......********....********....
..********......********....********....
..********......********..********......
..********......********..********......
....********....****************........
....********....****************........
....********....****************........
....********....****************........
......******************..**********....
......******************..**********....
........****************....**********..
........****************....**********..
............************......**********
............************......********** | instruction | 0 | 48,321 | 24 | 96,642 |
Tags: *special, implementation
Correct Solution:
```
class Image(object):
def __init__ (self, width, height, stringImage):
self._width = width
self._height = height
self._stringImage = stringImage
self._pixelMatrix = [[]]
# filling pixel matrix
line = 0
for i in self._stringImage:
if (i == '\n'):
self._pixelMatrix.append([])
line+=1
else:
self._pixelMatrix[line].append(i)
def __str__ (self):
resultedString = ''
for line in self._pixelMatrix:
for j in line:
resultedString += j
resultedString += '\n'
return resultedString[:-1]
def rotate90right(self):
# new matrix
newPixelMatrix = []
for i in range(self._width):
newPixelMatrix.append([])
for j in range(self._height):
newPixelMatrix[i].append('.')
# rotating elements
for i in range (self._height):
for j in range(self._width):
newPixelMatrix[j][self._height-1-i] = self._pixelMatrix[i][j]
self._pixelMatrix = newPixelMatrix
temp = self._height
self._height = self._width
self._width = temp
def mirrorGorizont(self):
# new matrix
newPixelMatrix = []
for i in range(self._height):
newPixelMatrix.append([])
for j in range(self._width):
newPixelMatrix[i].append('.')
# mirroring elements
for i in range (self._height):
for j in range(self._width):
newPixelMatrix[i][self._width-1-j] = self._pixelMatrix[i][j]
self._pixelMatrix = newPixelMatrix
def doubleTheSize(self):
# creating new matrix, double the size!
newPixelMatrix = []
for i in range(self._height*2):
newPixelMatrix.append([])
for j in range(self._width*2):
newPixelMatrix[i].append('.')
# transport data
for i in range (self._height):
for j in range(self._width):
newPixelMatrix[i*2][j*2] = self._pixelMatrix[i][j]
newPixelMatrix[i*2][j*2+1] = self._pixelMatrix[i][j]
newPixelMatrix[i*2+1][j*2] = self._pixelMatrix[i][j]
newPixelMatrix[i*2+1][j*2+1] = self._pixelMatrix[i][j]
self._pixelMatrix = newPixelMatrix
self._height *= 2
self._width *= 2
inputString = input()
listOfInput = inputString.split()
width = -1
height = -1
for i in listOfInput:
if i.isdigit() and width == -1:
width = int(i)
elif i.isdigit():
height = int(i)
image = input()
for i in range(height-1):
image += '\n'
image += input()
a = Image(width, height, image)
a.doubleTheSize()
a.rotate90right()
a.mirrorGorizont()
print(a)
``` | output | 1 | 48,321 | 24 | 96,643 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input
The first line contains two integers, w and h (1 β€ w, h β€ 100) β the width and height of an image in pixels. The picture is given in h lines, each line contains w characters β each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output
Print 2w lines, each containing 2h characters β the result of consecutive implementing of the three transformations, described above.
Examples
Input
3 2
.*.
.*.
Output
....
....
****
****
....
....
Input
9 20
**.......
****.....
******...
*******..
..******.
....****.
......***
*.....***
*********
*********
*********
*********
....**...
...****..
..******.
.********
****..***
***...***
**.....**
*.......*
Output
********......**********........********
********......**********........********
********........********......********..
********........********......********..
..********......********....********....
..********......********....********....
..********......********..********......
..********......********..********......
....********....****************........
....********....****************........
....********....****************........
....********....****************........
......******************..**********....
......******************..**********....
........****************....**********..
........****************....**********..
............************......**********
............************......********** | instruction | 0 | 48,322 | 24 | 96,644 |
Tags: *special, implementation
Correct Solution:
```
w, h = map( int, input( ).split( ) )
stgs = [ ]
for i in range( h ):
stgs.append( input( ) )
m = [0] * h
for i in range(h):
m[i] = [0] * w
for i in range( h ):
for j in range( w ):
m[ i ][ j ] = stgs[ i ][ j ]
for i in range( h ):
m[ i ].reverse( )
sk = 1
st = ""
for i in range( w - 1, -1, -1 ):
for j in range( h ):
st += m[ j ][ i ] + m[ j ][ i ]
print( st, st, sep = '\n' )
st = ''
``` | output | 1 | 48,322 | 24 | 96,645 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input
The first line contains two integers, w and h (1 β€ w, h β€ 100) β the width and height of an image in pixels. The picture is given in h lines, each line contains w characters β each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output
Print 2w lines, each containing 2h characters β the result of consecutive implementing of the three transformations, described above.
Examples
Input
3 2
.*.
.*.
Output
....
....
****
****
....
....
Input
9 20
**.......
****.....
******...
*******..
..******.
....****.
......***
*.....***
*********
*********
*********
*********
....**...
...****..
..******.
.********
****..***
***...***
**.....**
*.......*
Output
********......**********........********
********......**********........********
********........********......********..
********........********......********..
..********......********....********....
..********......********....********....
..********......********..********......
..********......********..********......
....********....****************........
....********....****************........
....********....****************........
....********....****************........
......******************..**********....
......******************..**********....
........****************....**********..
........****************....**********..
............************......**********
............************......********** | instruction | 0 | 48,323 | 24 | 96,646 |
Tags: *special, implementation
Correct Solution:
```
W, H = map( int, input().split() )
mat = [ input() for i in range( H ) ]
for i in range( 2 * W ):
print( ''.join( mat[ j // 2 ][ i // 2 ] for j in range( 2 * H ) ) )
``` | output | 1 | 48,323 | 24 | 96,647 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input
The first line contains two integers, w and h (1 β€ w, h β€ 100) β the width and height of an image in pixels. The picture is given in h lines, each line contains w characters β each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output
Print 2w lines, each containing 2h characters β the result of consecutive implementing of the three transformations, described above.
Examples
Input
3 2
.*.
.*.
Output
....
....
****
****
....
....
Input
9 20
**.......
****.....
******...
*******..
..******.
....****.
......***
*.....***
*********
*********
*********
*********
....**...
...****..
..******.
.********
****..***
***...***
**.....**
*.......*
Output
********......**********........********
********......**********........********
********........********......********..
********........********......********..
..********......********....********....
..********......********....********....
..********......********..********......
..********......********..********......
....********....****************........
....********....****************........
....********....****************........
....********....****************........
......******************..**********....
......******************..**********....
........****************....**********..
........****************....**********..
............************......**********
............************......********** | instruction | 0 | 48,324 | 24 | 96,648 |
Tags: *special, implementation
Correct Solution:
```
w, h = map(int, input().split())
a = []
for i in range(h):
a.append(input())
b = [[None]*(2*h) for _ in range(2*w)]
for i in range(w):
for j in range(h):
b[2*i ][2*j ] = a[j][i]
b[2*i ][2*j+1] = a[j][i]
b[2*i+1][2*j ] = a[j][i]
b[2*i+1][2*j+1] = a[j][i]
print('\n'.join([''.join(i) for i in b]))
``` | output | 1 | 48,324 | 24 | 96,649 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input
The first line contains two integers, w and h (1 β€ w, h β€ 100) β the width and height of an image in pixels. The picture is given in h lines, each line contains w characters β each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output
Print 2w lines, each containing 2h characters β the result of consecutive implementing of the three transformations, described above.
Examples
Input
3 2
.*.
.*.
Output
....
....
****
****
....
....
Input
9 20
**.......
****.....
******...
*******..
..******.
....****.
......***
*.....***
*********
*********
*********
*********
....**...
...****..
..******.
.********
****..***
***...***
**.....**
*.......*
Output
********......**********........********
********......**********........********
********........********......********..
********........********......********..
..********......********....********....
..********......********....********....
..********......********..********......
..********......********..********......
....********....****************........
....********....****************........
....********....****************........
....********....****************........
......******************..**********....
......******************..**********....
........****************....**********..
........****************....**********..
............************......**********
............************......********** | instruction | 0 | 48,325 | 24 | 96,650 |
Tags: *special, implementation
Correct Solution:
```
I=input
R=range
w,h=map(int,I().split())
t=[I()for _ in R(h)]
for r in[[t[i][j]*2for i in R(h)]for j in R(w)]:s=''.join(r);print(s+'\n'+s)
``` | output | 1 | 48,325 | 24 | 96,651 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.
On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).
Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.
When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:
* 1 m β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).
For each query of types 2 and 3, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 1).
Input
The first line contains one integer q (2 β€ q β€ 5 β
10^5) β the number of queries.
Then q lines follow, each describing a query in one of the following formats:
* 1 m (1 β€ m β€ 5 β
10^5) β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).
Queries of type 2 and 3 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 2 or 3 in the input.
Output
For each query of type 2 or 3, print one integer β the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 1.
Examples
Input
8
1 8
1 10
1 6
3
2
1 9
2
3
Output
2 1 3 4
Input
6
1 8
1 10
1 8
3
3
3
Output
2 1 3
Input
8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2
Output
1 2 3 | instruction | 0 | 49,042 | 24 | 98,084 |
Tags: data structures, implementation
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 16 10:58:05 2021
@author: ludoj
klanten=[]
res=[]
tel=1
for a in range(q):
if len(b[a])==2:
klanten.append((b[a][1],tel))
tel+=1
if b[a][0]==2:
res.append(klanten.pop(0)[1])
if b[a][0]==3:
maxi=max([x[0] for x in klanten])
tel2=0
while(maxi!=klanten[tel2][0]):
tel2+=1
res.append(klanten.pop(tel2)[1])
print(*res)
"""
import heapq
q=int(input())
b=[]
for a in range(q):
b.append([int(x) for x in input().split()])
klanten=[]
heapq.heapify(klanten)
weg=[]
res=[]
tel=1
i=0
for a in range(q):
if len(b[a])==2:
heapq.heappush(klanten,(-b[a][1],tel))
weg.append(False)
tel+=1
if b[a][0]==2:
while(weg[i]):
i+=1
weg[i]=True
res.append(str(i+1))
if b[a][0]==3:
stop=True
while(stop):
item=heapq.heappop(klanten)
if weg[item[1]-1]==False:
res.append(str(item[1]))
weg[item[1]-1]=True
stop=False
print(*res)
``` | output | 1 | 49,042 | 24 | 98,085 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.
On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).
Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.
When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:
* 1 m β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).
For each query of types 2 and 3, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 1).
Input
The first line contains one integer q (2 β€ q β€ 5 β
10^5) β the number of queries.
Then q lines follow, each describing a query in one of the following formats:
* 1 m (1 β€ m β€ 5 β
10^5) β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).
Queries of type 2 and 3 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 2 or 3 in the input.
Output
For each query of type 2 or 3, print one integer β the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 1.
Examples
Input
8
1 8
1 10
1 6
3
2
1 9
2
3
Output
2 1 3 4
Input
6
1 8
1 10
1 8
3
3
3
Output
2 1 3
Input
8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2
Output
1 2 3 | instruction | 0 | 49,043 | 24 | 98,086 |
Tags: data structures, implementation
Correct Solution:
```
import re
import sys
exit=sys.exit
from bisect import bisect_left as bsl,bisect_right as bsr
from collections import Counter,defaultdict as ddict,deque
from functools import lru_cache
cache=lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum=enumerate
ri=lambda:int(rln())
ris=lambda:list(map(int,rfs()))
rln=sys.stdin.readline
rl=lambda:rln().rstrip('\n')
rfs=lambda:rln().split()
d4=[(0,-1),(1,0),(0,1),(-1,0)]
d8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)]
########################################################################
q=ri()
a,b=[],[]
ans=[]
i=0
served=set()
for _ in range(q):
op,m,*_=ris()+[0]
if op==1:
i+=1
heappush(a,( i,i))
heappush(b,(-m,i))
else:
hp={2:a,3:b}[op]
while 1:
_,j=heappop(hp)
if j not in served:
break
served.discard(j)
ans.append(j)
served.add(j)
print(*ans)
``` | output | 1 | 49,043 | 24 | 98,087 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.
On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).
Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.
When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:
* 1 m β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).
For each query of types 2 and 3, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 1).
Input
The first line contains one integer q (2 β€ q β€ 5 β
10^5) β the number of queries.
Then q lines follow, each describing a query in one of the following formats:
* 1 m (1 β€ m β€ 5 β
10^5) β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).
Queries of type 2 and 3 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 2 or 3 in the input.
Output
For each query of type 2 or 3, print one integer β the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 1.
Examples
Input
8
1 8
1 10
1 6
3
2
1 9
2
3
Output
2 1 3 4
Input
6
1 8
1 10
1 8
3
3
3
Output
2 1 3
Input
8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2
Output
1 2 3 | instruction | 0 | 49,044 | 24 | 98,088 |
Tags: data structures, implementation
Correct Solution:
```
from sys import stdin, stdout
def insert(ID):
heap.append(ID)
i = len(heap)-1
while (i - 1) // 2 >= 0 and (score[heap[(i - 1) // 2]] < score[heap[i]] or (
score[heap[(i - 1) // 2]] == score[heap[i]] and heap[i] < heap[(i - 1) // 2])):
heap[(i - 1) // 2] += heap[i]
heap[i] = heap[(i - 1) // 2] - heap[i]
heap[(i - 1) // 2] -= heap[i]
i = (i-1)//2
def remove():
if len(heap) == 1:
return heap.pop()
else:
heap[0] += heap[-1]
heap[-1] = heap[0] - heap[-1]
heap[0] -= heap[-1]
res = heap.pop()
n, i = len(heap), 0
while (2 * i) + 1 < n:
maxm = (2 * i) + 1
if (2 * i) + 2 < n and score[heap[(2 * i) + 2]] > score[heap[maxm]]:
maxm = (2 * i) + 2
elif (2 * i) + 2 < n and (score[heap[(2 * i) + 2]] == score[heap[maxm]] and heap[maxm] > heap[(2 * i) + 2]):
maxm = (2 * i) + 2
if (score[heap[i]] > score[heap[maxm]]) or (score[heap[i]] == score[heap[maxm]] and heap[maxm] > heap[i]):
break
heap[maxm] += heap[i]
heap[i] = heap[maxm] - heap[i]
heap[maxm] -= heap[i]
i = maxm
return res
N = int(stdin.readline())
score = dict()
heap = []
output = []
visited = dict()
n = 1
i = 1
for __ in range(N):
x = [int(num) for num in stdin.readline().strip().split()]
if x[0] == 1:
score[n] = x[1]
insert(n)
n += 1
elif x[0] == 2:
while visited.get(i, False):
i += 1
visited[i] = True
output.append(i)
i += 1
else:
res = remove()
while visited.get(res, False):
res = remove()
output.append(res)
visited[res] = True
for out in output[:len(output)-1]:
stdout.write(f'{out} ')
stdout.write(f'{output[-1]}')
``` | output | 1 | 49,044 | 24 | 98,089 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.
On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).
Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.
When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:
* 1 m β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).
For each query of types 2 and 3, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 1).
Input
The first line contains one integer q (2 β€ q β€ 5 β
10^5) β the number of queries.
Then q lines follow, each describing a query in one of the following formats:
* 1 m (1 β€ m β€ 5 β
10^5) β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).
Queries of type 2 and 3 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 2 or 3 in the input.
Output
For each query of type 2 or 3, print one integer β the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 1.
Examples
Input
8
1 8
1 10
1 6
3
2
1 9
2
3
Output
2 1 3 4
Input
6
1 8
1 10
1 8
3
3
3
Output
2 1 3
Input
8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2
Output
1 2 3 | instruction | 0 | 49,045 | 24 | 98,090 |
Tags: data structures, implementation
Correct Solution:
```
# from __future__ import print_function,division
# range = xrange
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10**9)
from sys import stdin, stdout
from collections import defaultdict, Counter,deque
M = 10**9+7
import heapq
def main():
n = int(input())
vis = []
q = deque([])
h = []
ind = 0
ans = []
for i in range(n):
l = [int(s) for s in input().split()]
if l[0]==1:
vis.append(0)
q.append([l[1],ind])
heapq.heappush(h,[-l[1],ind])
ind+=1
elif l[0]==2:
w = q.popleft()
while vis[w[1]]==1:
w = q.popleft()
ans.append(w[1]+1)
vis[w[1]] = 1
else:
w = heapq.heappop(h)
while vis[w[1]]==1:
w = heapq.heappop(h)
ans.append(w[1]+1)
vis[w[1]] = 1
print(*ans)
if __name__== '__main__':
main()
``` | output | 1 | 49,045 | 24 | 98,091 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.
On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).
Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.
When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:
* 1 m β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).
For each query of types 2 and 3, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 1).
Input
The first line contains one integer q (2 β€ q β€ 5 β
10^5) β the number of queries.
Then q lines follow, each describing a query in one of the following formats:
* 1 m (1 β€ m β€ 5 β
10^5) β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).
Queries of type 2 and 3 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 2 or 3 in the input.
Output
For each query of type 2 or 3, print one integer β the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 1.
Examples
Input
8
1 8
1 10
1 6
3
2
1 9
2
3
Output
2 1 3 4
Input
6
1 8
1 10
1 8
3
3
3
Output
2 1 3
Input
8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2
Output
1 2 3 | instruction | 0 | 49,046 | 24 | 98,092 |
Tags: data structures, implementation
Correct Solution:
```
from sys import stdin
import heapq
q = int(stdin.readline())
endlis = []
mono = 0
hq = []
ans = []
for loop in range(q):
query = input()
if query[0] == "1":
tmp,m = map(int,query.split())
endlis.append(0)
heapq.heappush(hq,(-1*m,len(endlis)-1))
elif query[0] == "2":
while endlis[mono] == 1:
mono += 1
ans.append(mono+1)
endlis[mono] = 1
else:
while endlis[ hq[0][1] ] == 1:
heapq.heappop(hq)
tmp,ind = heapq.heappop(hq)
ans.append(ind+1)
endlis[ind] = 1
print (*ans)
``` | output | 1 | 49,046 | 24 | 98,093 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.
On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).
Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.
When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:
* 1 m β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).
For each query of types 2 and 3, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 1).
Input
The first line contains one integer q (2 β€ q β€ 5 β
10^5) β the number of queries.
Then q lines follow, each describing a query in one of the following formats:
* 1 m (1 β€ m β€ 5 β
10^5) β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).
Queries of type 2 and 3 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 2 or 3 in the input.
Output
For each query of type 2 or 3, print one integer β the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 1.
Examples
Input
8
1 8
1 10
1 6
3
2
1 9
2
3
Output
2 1 3 4
Input
6
1 8
1 10
1 8
3
3
3
Output
2 1 3
Input
8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2
Output
1 2 3 | instruction | 0 | 49,047 | 24 | 98,094 |
Tags: data structures, implementation
Correct Solution:
```
from sys import stdin,stdout
from heapq import heappop,heappush
def main():
ans,visited,hp=[],[],[]
start=0
for _ in range(int(stdin.readline())):
q=stdin.readline()
if q[0]=="1":
_,v=map(int,q.split( ))
visited.append(0)
heappush(hp,(-1*v,len(visited)-1))
elif q[0]=="2":
while visited[start]==1:
start+=1
ans.append(start+1)
visited[start]=1
else:
while visited[hp[0][1]]==1:
heappop(hp)
_,ind=heappop(hp)
ans.append(ind+1)
visited[ind]=1
for v in ans:
stdout.write("%d "%(v))
stdout.write("\n")
main()
``` | output | 1 | 49,047 | 24 | 98,095 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.
On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).
Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.
When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:
* 1 m β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).
For each query of types 2 and 3, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 1).
Input
The first line contains one integer q (2 β€ q β€ 5 β
10^5) β the number of queries.
Then q lines follow, each describing a query in one of the following formats:
* 1 m (1 β€ m β€ 5 β
10^5) β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).
Queries of type 2 and 3 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 2 or 3 in the input.
Output
For each query of type 2 or 3, print one integer β the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 1.
Examples
Input
8
1 8
1 10
1 6
3
2
1 9
2
3
Output
2 1 3 4
Input
6
1 8
1 10
1 8
3
3
3
Output
2 1 3
Input
8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2
Output
1 2 3 | instruction | 0 | 49,048 | 24 | 98,096 |
Tags: data structures, implementation
Correct Solution:
```
import heapq
def solution(n: int, arr: [[int]]) -> [int]:
queue = []
heap = []
result = []
lastIndex = 0
for i in arr:
if i[0] == 1:
lastIndex += 1
element = [-i[1], lastIndex, False]
queue.append(element)
heapq.heappush(heap, element)
if i[0] == 2:
customer = queue.pop(0)
while customer[2] == True:
customer = queue.pop(0)
customer[2] = True
result.append(customer[1])
if i[0] == 3:
customer = heapq.heappop(heap)
while customer[2] == True:
customer = heapq.heappop(heap)
customer[2] = True
result.append(customer[1])
return result
def main():
n = int(input())
arr = [[int(j) for j in input().split(" ")] for i in range(n)]
print(" ".join([str(i) for i in solution(n, arr)]))
if __name__ == '__main__':
main()
``` | output | 1 | 49,048 | 24 | 98,097 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.
On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).
Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.
When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:
* 1 m β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).
For each query of types 2 and 3, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 1).
Input
The first line contains one integer q (2 β€ q β€ 5 β
10^5) β the number of queries.
Then q lines follow, each describing a query in one of the following formats:
* 1 m (1 β€ m β€ 5 β
10^5) β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).
Queries of type 2 and 3 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 2 or 3 in the input.
Output
For each query of type 2 or 3, print one integer β the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 1.
Examples
Input
8
1 8
1 10
1 6
3
2
1 9
2
3
Output
2 1 3 4
Input
6
1 8
1 10
1 8
3
3
3
Output
2 1 3
Input
8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2
Output
1 2 3 | instruction | 0 | 49,049 | 24 | 98,098 |
Tags: data structures, implementation
Correct Solution:
```
import os
import math
import statistics
import heapq
true = True;
false = False;
# from collections import defaultdict, deque
from functools import reduce
is_dev = 'vscode' in os.environ
if is_dev:
inF = open('in.txt', 'r')
outF = open('out.txt', 'w')
def ins():
return list(map(int, input_().split(' ')))
def inss():
return list(input_().split(' '))
def input_():
if is_dev:
return inF.readline()[:-1]
else:
return input()
def ranin():
return range(int(input_()))
def print_(data):
if is_dev:
outF.write(str(data)+'\n')
else:
print(data)
epsilon = 1e-7
customers = []
heapq.heapify(customers)
i = 1
j = 1
served = [False]*(5*(10**5)+2)
result = []
for _ in range(int(input_())):
a = ins()
if a[0] == 1:
heapq.heappush(customers, (-a[1], i))
i+=1
elif a[0] == 2:
while served[j]:
j += 1
served[j] = True
result.append(j)
j += 1
elif a[0] == 3:
customer = heapq.heappop(customers)
while served[customer[1]]:
customer = heapq.heappop(customers)
served[customer[1]] = True
result.append(customer[1])
print_(' '.join(map(str, result)))
if is_dev:
outF.close()
def compare_file():
print(open('out.txt', 'r').read() == open('outactual.txt', 'r').read())
compare_file()
``` | output | 1 | 49,049 | 24 | 98,099 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.
On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).
Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.
When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:
* 1 m β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).
For each query of types 2 and 3, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 1).
Input
The first line contains one integer q (2 β€ q β€ 5 β
10^5) β the number of queries.
Then q lines follow, each describing a query in one of the following formats:
* 1 m (1 β€ m β€ 5 β
10^5) β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).
Queries of type 2 and 3 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 2 or 3 in the input.
Output
For each query of type 2 or 3, print one integer β the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 1.
Examples
Input
8
1 8
1 10
1 6
3
2
1 9
2
3
Output
2 1 3 4
Input
6
1 8
1 10
1 8
3
3
3
Output
2 1 3
Input
8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2
Output
1 2 3
Submitted Solution:
```
import heapq
mono = []
poly = []
d={}
count = 1
ans=[]
q = int(input())
for i in range(q):
query = list(input().split())
if len(query)>1:
heapq.heappush(mono,[count,int(query[1])])
heapq.heappush(poly,[-int(query[1]),count])
count+=1
else:
if query[0]=="2":
while 1:
p = heapq.heappop(mono)
try:
del d[p[0]]
except:
ans.append(p[0])
# print(p[0],end=" ")
d[p[0]]=1
break
elif query[0]=="3":
while 1:
p = heapq.heappop(poly)
try:
del d[p[1]]
except:
ans.append(p[1])
# print(p[1],end=" ")
d[p[1]]=1
break
print(*ans)
``` | instruction | 0 | 49,050 | 24 | 98,100 |
Yes | output | 1 | 49,050 | 24 | 98,101 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.
On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).
Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.
When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:
* 1 m β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).
For each query of types 2 and 3, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 1).
Input
The first line contains one integer q (2 β€ q β€ 5 β
10^5) β the number of queries.
Then q lines follow, each describing a query in one of the following formats:
* 1 m (1 β€ m β€ 5 β
10^5) β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).
Queries of type 2 and 3 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 2 or 3 in the input.
Output
For each query of type 2 or 3, print one integer β the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 1.
Examples
Input
8
1 8
1 10
1 6
3
2
1 9
2
3
Output
2 1 3 4
Input
6
1 8
1 10
1 8
3
3
3
Output
2 1 3
Input
8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2
Output
1 2 3
Submitted Solution:
```
# Author Name: Ajay Meena
# Codeforce : https://codeforces.com/profile/majay1638
# -------- IMPORTANT ---------#
# SUN BHOS**KE AGAR MERA TEMPLATE COPY KAR RHA HAI NA TOH KUCH CHANGES BHI KAR DENA ESS ME, VARNA MUJEHY WARNING AAYEGI BAAD ME, PLEASE YAAR KAR DENA, OK :).
import sys
import heapq
from heapq import heappush, heappop
import math
from sys import stdin, stdout
# //Most Frequently Used Number Theory Concepts
# VAISE MEIN JAYDA USE KARTA NHI HU ENHE BUT COOL BANNE KE LIYE LIKH LEYA TEMPLATE ME VARNA ME YE TOH DUSRI FILE MAI SE BHI COPY PASTE KAR SAKTA THA :).
def sieve(N):
primeNumbers = [True]*(N+1)
primeNumbers[0] = False
primeNumbers[1] = False
i = 2
while i*i <= N:
j = i
if primeNumbers[j]:
while j*i <= N:
primeNumbers[j*i] = False
j += 1
i += 1
return primeNumbers
def getPrime(N):
primes = sieve(N)
result = []
for i in range(len(primes)):
if primes[i]:
result.append(i)
return result
def factor(N):
factors = []
i = 1
while i*i <= N:
if N % i == 0:
factors.append(i)
if i != N//i:
factors.append(N//i)
i += 1
return sorted(factors)
def gcd(a, b):
if a < b:
return gcd(b, a)
if b == 0:
return a
return gcd(b, a % b)
def extendedGcd(a, b):
if a < b:
return extendedGcd(b, a)
if b == 0:
return [a, 1, 0]
res = extendedGcd(b, a % b)
x = res[2]
y = res[1]-(math.floor(a/b)*res[2])
res[1] = x
res[2] = y
return res
def iterativeModularFunc(a, b, c):
res = 1
while b > 0:
if b & 1:
res = (res*a) % c
a = (a*a) % c
b = b//2
return res
# TAKE INPUT
# HAAN YE BHUT KAAM AATA HAI INPUT LENE ME
def get_ints_in_variables():
return map(int, sys.stdin.readline().strip().split())
def get_int(): return int(input())
def get_ints_in_list(): return list(
map(int, sys.stdin.readline().strip().split()))
def get_list_of_list(n): return [list(
map(int, sys.stdin.readline().strip().split())) for _ in range(n)]
def get_string(): return sys.stdin.readline().strip()
def Solution():
heap = []
hm = []
idx = 0
# queue = []
# i = 1
res = []
for _ in range(get_int()):
q = input()
if q[0] == "1":
ip = list(map(int, q.split()))
v = ip[1]
hm.append(0)
heappush(heap, (-1*v, len(hm)-1))
elif q[0] == "2":
while hm[idx] == 1:
idx += 1
hm[idx] = 1
res.append(idx+1)
else:
while hm[heap[0][1]] == 1:
heappop(heap)
itm = heappop(heap)
hm[itm[1]] = 1
res.append(itm[1]+1)
print(*res)
def main():
# //Write Your Code Here
Solution()
# calling main Function
if __name__ == "__main__":
main()
``` | instruction | 0 | 49,051 | 24 | 98,102 |
Yes | output | 1 | 49,051 | 24 | 98,103 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.
On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).
Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.
When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:
* 1 m β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).
For each query of types 2 and 3, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 1).
Input
The first line contains one integer q (2 β€ q β€ 5 β
10^5) β the number of queries.
Then q lines follow, each describing a query in one of the following formats:
* 1 m (1 β€ m β€ 5 β
10^5) β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).
Queries of type 2 and 3 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 2 or 3 in the input.
Output
For each query of type 2 or 3, print one integer β the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 1.
Examples
Input
8
1 8
1 10
1 6
3
2
1 9
2
3
Output
2 1 3 4
Input
6
1 8
1 10
1 8
3
3
3
Output
2 1 3
Input
8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2
Output
1 2 3
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 16 10:58:05 2021
@author: ludoj
klanten=[]
res=[]
tel=1
for a in range(q):
if len(b[a])==2:
klanten.append((b[a][1],tel))
tel+=1
if b[a][0]==2:
res.append(klanten.pop(0)[1])
if b[a][0]==3:
maxi=max([x[0] for x in klanten])
tel2=0
while(maxi!=klanten[tel2][0]):
tel2+=1
res.append(klanten.pop(tel2)[1])
print(*res)
"""
import heapq
q=int(input())
b=[]
for a in range(q):
b.append([int(x) for x in input().split()])
klanten=[]
heapq.heapify(klanten)
weg=[]
res=[]
tel=1
i=0
for a in range(q):
if len(b[a])==2:
heapq.heappush(klanten,(-b[a][1],tel))
weg.append(False)
tel+=1
if b[a][0]==2:
while(weg[i]):
i+=1
weg[i]=True
res.append(str(i+1))
if b[a][0]==3:
stop=True
while(stop):
item=heapq.heappop(klanten)
if weg[item[1]-1]==False:
res.append(str(item[1]))
weg[item[1]-1]=True
stop=False
print(" ".join(res))
``` | instruction | 0 | 49,052 | 24 | 98,104 |
Yes | output | 1 | 49,052 | 24 | 98,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.
On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).
Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.
When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:
* 1 m β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).
For each query of types 2 and 3, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 1).
Input
The first line contains one integer q (2 β€ q β€ 5 β
10^5) β the number of queries.
Then q lines follow, each describing a query in one of the following formats:
* 1 m (1 β€ m β€ 5 β
10^5) β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).
Queries of type 2 and 3 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 2 or 3 in the input.
Output
For each query of type 2 or 3, print one integer β the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 1.
Examples
Input
8
1 8
1 10
1 6
3
2
1 9
2
3
Output
2 1 3 4
Input
6
1 8
1 10
1 8
3
3
3
Output
2 1 3
Input
8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2
Output
1 2 3
Submitted Solution:
```
#!python3
from queue import PriorityQueue, Queue
import sys
class Customer(object):
def __init__(self, i):
self.i = i
self.seen = False
def __lt__(self, other):
return self.i < other.i
def parse_input():
test_count = int(sys.stdin.readline())
poly_customers = PriorityQueue()
mono_customers = Queue()
i = 0
for _ in range(test_count):
line = sys.stdin.readline().strip()
if line.startswith('1'):
a, b = line.split(' ', maxsplit=1)
a, b = int(a), int(b)
i += 1
c = Customer(i)
poly_customers.put((-b, c))
mono_customers.put(c)
else:
c = int(line)
if c == 2:
yield get_mono(mono_customers)
# sys.stdout.write(f'{o}\n')
elif c == 3:
yield get_poly(poly_customers)
# sys.stdout.write(f'{o}\n')
else:
raise Exception
def get_mono(mono_customers):
c = mono_customers.get()
while c.seen:
c = mono_customers.get()
c.seen = True
return c.i
def get_poly(poly_customers):
_, c = poly_customers.get()
while c.seen:
_, c = poly_customers.get()
c.seen = True
return c.i
def main():
for o in parse_input():
sys.stdout.write(f'{o}\n')
main()
``` | instruction | 0 | 49,053 | 24 | 98,106 |
Yes | output | 1 | 49,053 | 24 | 98,107 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.
On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).
Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.
When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:
* 1 m β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).
For each query of types 2 and 3, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 1).
Input
The first line contains one integer q (2 β€ q β€ 5 β
10^5) β the number of queries.
Then q lines follow, each describing a query in one of the following formats:
* 1 m (1 β€ m β€ 5 β
10^5) β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).
Queries of type 2 and 3 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 2 or 3 in the input.
Output
For each query of type 2 or 3, print one integer β the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 1.
Examples
Input
8
1 8
1 10
1 6
3
2
1 9
2
3
Output
2 1 3 4
Input
6
1 8
1 10
1 8
3
3
3
Output
2 1 3
Input
8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2
Output
1 2 3
Submitted Solution:
```
lines = []
num = int(input("input:\n"))
for i in range(num):
line = input("")
lines.append(line)
output = ""
customs = {}
customs_reverse = {}
count = 1
for line in lines:
if line[0] == "1":
value = int(line[2:])
customs[count] = value
if value in customs_reverse:
customs_reverse[value].append(count)
else:
customs_reverse[value] = [count]
count += 1
elif line[0] == "2":
key1 = min(customs.keys())
value1 = customs[key1]
output += f"{key1}"+" "
customs.pop(key1)
customs_reverse[value1].remove(key1)
elif line[0] == "3":
value2 = max(customs_reverse.keys())
key2 = min(customs_reverse[value2])
output += f"{key2}"+" "
customs.pop(key2)
customs_reverse[value2].remove(key2)
if not customs_reverse[value2]:
customs_reverse.pop(value2)
print(output[:-1])
``` | instruction | 0 | 49,054 | 24 | 98,108 |
No | output | 1 | 49,054 | 24 | 98,109 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.
On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).
Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.
When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:
* 1 m β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).
For each query of types 2 and 3, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 1).
Input
The first line contains one integer q (2 β€ q β€ 5 β
10^5) β the number of queries.
Then q lines follow, each describing a query in one of the following formats:
* 1 m (1 β€ m β€ 5 β
10^5) β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).
Queries of type 2 and 3 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 2 or 3 in the input.
Output
For each query of type 2 or 3, print one integer β the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 1.
Examples
Input
8
1 8
1 10
1 6
3
2
1 9
2
3
Output
2 1 3 4
Input
6
1 8
1 10
1 8
3
3
3
Output
2 1 3
Input
8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2
Output
1 2 3
Submitted Solution:
```
q=int(input())
l=[]
turn = 0
served={}
pointer=1
weight={}
p=0
j=0
ans=[]
for i in range(q):
query = list(map(int,input().split()))
if query[0]==1:
turn=turn+1
served[turn]=0
weight[turn]=query[1]
l.append((1,query[1],turn))
elif query[0] == 2:
#if pointer!=1 and served[pointer]==0:
# served[pointer]=1
# print(pointer)
# while served[pointer]!=0:
# pointer+=1
if pointer in served:
if served[pointer]==0:
served[pointer]=1
#print(pointer)
ans.append(pointer)
while pointer in served and served[pointer]!=0:
pointer+=1
#print(pointer)
elif served[pointer]==1:
while pointer in served and served[pointer]!=0:
pointer+=1
#print(pointer)
ans.append(pointer)
elif query[0]==3:
#find the maximum weight key which is not in served
v = {k: v for k, v in sorted(weight.items(), key=lambda item: item[1],reverse=True)}
vI=v.items()
lVI=list(vI)
for u in range(j,len(lVI)):
if served[lVI[u][0]]==0:
served[lVI[u][0]]=1
#print(k)
ans.append(lVI[u][0])
j+=1
break
else:
j+=1
#continue
print(*ans)
``` | instruction | 0 | 49,055 | 24 | 98,110 |
No | output | 1 | 49,055 | 24 | 98,111 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.
On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).
Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.
When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:
* 1 m β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).
For each query of types 2 and 3, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 1).
Input
The first line contains one integer q (2 β€ q β€ 5 β
10^5) β the number of queries.
Then q lines follow, each describing a query in one of the following formats:
* 1 m (1 β€ m β€ 5 β
10^5) β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).
Queries of type 2 and 3 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 2 or 3 in the input.
Output
For each query of type 2 or 3, print one integer β the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 1.
Examples
Input
8
1 8
1 10
1 6
3
2
1 9
2
3
Output
2 1 3 4
Input
6
1 8
1 10
1 8
3
3
3
Output
2 1 3
Input
8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2
Output
1 2 3
Submitted Solution:
```
def argsort(seq):
return sorted(range(len(seq)), key=seq.__getitem__,reverse=True)
a = []
s=0
numbers = 1
served = []
crowd = int(input())
for _ in range(crowd):
p = [int(x) for x in input().split()]
if len(p)==2:
s+=1
a.append(p[1])
else:
q = argsort(a)
if len(q)>0:
for i in q:
served.append(i+numbers)
numbers+=len(q)
a=[]
t = max(min(s,crowd-s),s//2)
print(*served[:t])
``` | instruction | 0 | 49,056 | 24 | 98,112 |
No | output | 1 | 49,056 | 24 | 98,113 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.
At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.
On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).
Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.
When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:
* 1 m β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).
For each query of types 2 and 3, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 1).
Input
The first line contains one integer q (2 β€ q β€ 5 β
10^5) β the number of queries.
Then q lines follow, each describing a query in one of the following formats:
* 1 m (1 β€ m β€ 5 β
10^5) β a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as m;
* 2 β Monocarp serves a customer which came to the pizzeria first;
* 3 β Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).
Queries of type 2 and 3 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 2 or 3 in the input.
Output
For each query of type 2 or 3, print one integer β the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 1.
Examples
Input
8
1 8
1 10
1 6
3
2
1 9
2
3
Output
2 1 3 4
Input
6
1 8
1 10
1 8
3
3
3
Output
2 1 3
Input
8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2
Output
1 2 3
Submitted Solution:
```
Q=int(input())
A1=[]
A2=[]
#A3=[]
maxm = -1
maxm_index = 0
maxm_index_val=0
m=1
numofdeleted=0
for q in range(Q):
z=input()
a1,a2=-1,-1
if len(z) > 1:
a1, a2 = z.split()
a1, a2 = int(a1), int(a2)
A1.append(m)
A2.append(a2)
if A2[len(A2) - 1] > maxm:
maxm = A2[len(A2) - 1]
maxm_index = A1[len(A2) - 1]-1
maxm_index_val=len(A2) - 1
#A3.append(False)
#print(A1)
m+=1
#print(A1,maxm,maxm_index)
else:
z = int(z)
if z == 2:
for i in range(len(A1)):
print(A1[0])
A1.pop(0)
A2.pop(0)
break
maxm=-1
maxm_index=-1
maxm = -1
maxm_index = -1
maxm_index_val = -1
for j in range(len(A1)):
if A2[j] > maxm:
maxm = A2[j]
maxm_index = A1[j] - 1
maxm_index_val = j
if z == 3:
if A2[len(A2)-1] > maxm:
maxm = A2[len(A2)-1]
maxm_index = len(A2)-1
print(maxm_index+1, end=" ")
#print(A1,len(A1),end=" ")
A1.pop(maxm_index_val)
A2.pop(maxm_index_val)
maxm = -1
maxm_index = -1
maxm_index_val=-1
for j in range(len(A1)):
if A2[j] > maxm:
maxm = A2[j]
maxm_index = A1[j]-1
maxm_index_val=j
elif A2[j] == maxm:
maxm = A2[j]
maxm_index = A1[j]-1
maxm_index_val=j
break
#print(maxm,maxm_index)
``` | instruction | 0 | 49,057 | 24 | 98,114 |
No | output | 1 | 49,057 | 24 | 98,115 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input
The first line contains integer n (1 β€ n β€ 200 000) β the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Examples
Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya
Note
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan
2. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman
2. ivan
3. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan
2. roman
3. alex | instruction | 0 | 49,268 | 24 | 98,536 |
Tags: *special, binary search, constructive algorithms, data structures, sortings
Correct Solution:
```
n = int(input())
chat = {}
for i in range(n):
chat[input()] = i
c = {}
for i in chat.keys():
c[chat[i]] = i
m = []
for i in sorted(list(c.keys()), reverse = True):
m.append(c[i])
print(*m, sep = '\n')
``` | output | 1 | 49,268 | 24 | 98,537 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input
The first line contains integer n (1 β€ n β€ 200 000) β the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Examples
Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya
Note
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan
2. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman
2. ivan
3. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan
2. roman
3. alex | instruction | 0 | 49,269 | 24 | 98,538 |
Tags: *special, binary search, constructive algorithms, data structures, sortings
Correct Solution:
```
n =int(input())
arr =[]
for i in range(n):
arr.append(input())
arr =arr[::-1]
string =set()
for a in arr:
if (a not in string):
string.add(a)
print (a)
``` | output | 1 | 49,269 | 24 | 98,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input
The first line contains integer n (1 β€ n β€ 200 000) β the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Examples
Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya
Note
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan
2. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman
2. ivan
3. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan
2. roman
3. alex | instruction | 0 | 49,270 | 24 | 98,540 |
Tags: *special, binary search, constructive algorithms, data structures, sortings
Correct Solution:
```
t = int(input())
q = list()
for i in range(t):
n = (input())
q.append(n)
s = set(q)
while len(s) > 0:
for j in q[::-1]:
if j in s:
print(j)
s.remove(j)
else:
break
``` | output | 1 | 49,270 | 24 | 98,541 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input
The first line contains integer n (1 β€ n β€ 200 000) β the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Examples
Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya
Note
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan
2. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman
2. ivan
3. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan
2. roman
3. alex | instruction | 0 | 49,271 | 24 | 98,542 |
Tags: *special, binary search, constructive algorithms, data structures, sortings
Correct Solution:
```
n = int(input())
displayed = {}
top = None
for i in range(n):
chat = input()
try:
a = displayed[chat]
previous = a[0]
nextone = a[1]
if previous:
displayed[previous][1] = nextone
if nextone: displayed[nextone][0]=previous
displayed[chat] = [None, top]
if top:
displayed[top][0] = chat
top = chat
except KeyError:
displayed[chat] = [None, top]
if top:
displayed[top][0] = chat
top = chat
#print(displayed)
#print(top)
li = []
while top:
#print(top)
li.append(top)
top = displayed.pop(top)[1]
#print(displayed)
print('\n'.join(li))
``` | output | 1 | 49,271 | 24 | 98,543 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input
The first line contains integer n (1 β€ n β€ 200 000) β the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Examples
Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya
Note
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan
2. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman
2. ivan
3. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan
2. roman
3. alex | instruction | 0 | 49,272 | 24 | 98,544 |
Tags: *special, binary search, constructive algorithms, data structures, sortings
Correct Solution:
```
import math,sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda:int(input())
li = lambda:list(map(int,input().split()))
def case():
n=I()
a=[]
for i in range(n):
a.append(input().strip())
s=set([])
i=1
while(i<=n):
if(a[-i] not in s):
print(a[-i])
s.add(a[-i])
i+=1
for _ in range(1):
case()
``` | output | 1 | 49,272 | 24 | 98,545 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input
The first line contains integer n (1 β€ n β€ 200 000) β the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Examples
Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya
Note
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan
2. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman
2. ivan
3. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan
2. roman
3. alex | instruction | 0 | 49,273 | 24 | 98,546 |
Tags: *special, binary search, constructive algorithms, data structures, sortings
Correct Solution:
```
n = int(input())
l = []
for _ in range(n):
l.append(input())
answer = []
s = set()
for i in range(n - 1, -1, -1):
if l[i] not in s:
s.add(l[i])
answer.append(l[i])
for _ in answer:
print(_)
``` | output | 1 | 49,273 | 24 | 98,547 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input
The first line contains integer n (1 β€ n β€ 200 000) β the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Examples
Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya
Note
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan
2. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman
2. ivan
3. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan
2. roman
3. alex | instruction | 0 | 49,274 | 24 | 98,548 |
Tags: *special, binary search, constructive algorithms, data structures, sortings
Correct Solution:
```
n = int(input())
D = {}
l = []
ll = []
for i in range(0,n):
l.append(input())
for i in range(0,n):
if l[n-i-1] in D:
m = 0
else:
D[l[n-i-1]] = 1
ll.append(l[n-1-i])
for i in range(0,len(ll)):
print(ll[i])
``` | output | 1 | 49,274 | 24 | 98,549 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input
The first line contains integer n (1 β€ n β€ 200 000) β the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Examples
Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya
Note
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan
2. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman
2. ivan
3. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan
2. roman
3. alex | instruction | 0 | 49,275 | 24 | 98,550 |
Tags: *special, binary search, constructive algorithms, data structures, sortings
Correct Solution:
```
n=int(input())
m={}
mm={}
for i in range(n):
a=input()
m[a]=i
for j in m:
mm[m[j]]=j
ans=sorted(mm.keys(),reverse=True)
for i in ans:
print(mm[i])
``` | output | 1 | 49,275 | 24 | 98,551 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input
The first line contains integer n (1 β€ n β€ 200 000) β the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Examples
Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya
Note
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan
2. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman
2. ivan
3. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan
2. roman
3. alex
Submitted Solution:
```
n = int(input())
names = {}
for i in range(n):
name = input()
names[name]=i
for name, key in sorted(zip(names.values(), names.keys()), reverse=True):
print(key)
``` | instruction | 0 | 49,276 | 24 | 98,552 |
Yes | output | 1 | 49,276 | 24 | 98,553 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input
The first line contains integer n (1 β€ n β€ 200 000) β the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Examples
Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya
Note
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan
2. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman
2. ivan
3. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan
2. roman
3. alex
Submitted Solution:
```
def get_chats(names):
chats = {}
for name in reversed(names):
if name not in chats:
print(name)
chats[name] = True
if __name__ == "__main__":
len = int(input())
names = []
for i in range(len):
names.append(input())
get_chats(names)
``` | instruction | 0 | 49,277 | 24 | 98,554 |
Yes | output | 1 | 49,277 | 24 | 98,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input
The first line contains integer n (1 β€ n β€ 200 000) β the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Examples
Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya
Note
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan
2. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman
2. ivan
3. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan
2. roman
3. alex
Submitted Solution:
```
n = int(input())
rank = n
li = [0] * (n + 1)
for i in range(n, 0, -1):
s = input()
li[i] = s
dp = dict()
for i in range(1, n + 1):
if dp.get(li[i], 0) == 0:
dp[li[i]] = 1
print(li[i])
``` | instruction | 0 | 49,278 | 24 | 98,556 |
Yes | output | 1 | 49,278 | 24 | 98,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input
The first line contains integer n (1 β€ n β€ 200 000) β the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Examples
Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya
Note
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan
2. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman
2. ivan
3. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan
2. roman
3. alex
Submitted Solution:
```
n = int(input())
d = {}
for i in range(n):
d[input()] = i
a = [(i[1], i[0]) for i in d.items()]
a.sort(reverse = True)
print(*[i[1] for i in a], sep = '\n')
``` | instruction | 0 | 49,279 | 24 | 98,558 |
Yes | output | 1 | 49,279 | 24 | 98,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input
The first line contains integer n (1 β€ n β€ 200 000) β the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Examples
Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya
Note
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan
2. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman
2. ivan
3. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan
2. roman
3. alex
Submitted Solution:
```
def main():
n = int(input())
friend_dict = {}
while n > 0:
s = input()
if s in friend_dict.keys():
friend_dict[s] += 1
else:
friend_dict[s] = 1
n -= 1
friend_dict = dict(sorted(friend_dict.items(), key=lambda x: x[1], reverse=True))
for friend in friend_dict.keys():
print(friend)
main()
``` | instruction | 0 | 49,280 | 24 | 98,560 |
No | output | 1 | 49,280 | 24 | 98,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input
The first line contains integer n (1 β€ n β€ 200 000) β the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Examples
Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya
Note
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan
2. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman
2. ivan
3. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan
2. roman
3. alex
Submitted Solution:
```
n = int(input())
S = []
for i in range(n):
S.append(input())
R = []
for i in S:
if i in R:
R.remove(i)
R.insert(0, i)
print(R)
``` | instruction | 0 | 49,281 | 24 | 98,562 |
No | output | 1 | 49,281 | 24 | 98,563 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input
The first line contains integer n (1 β€ n β€ 200 000) β the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Examples
Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya
Note
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan
2. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman
2. ivan
3. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan
2. roman
3. alex
Submitted Solution:
```
n = int(input())
d = {}
for i in range(n):
s = input()
d[s] = i + 1
d = sorted(d , reverse= True, key= lambda x : x[1])
#print(d)
for i in d :
print(i)
``` | instruction | 0 | 49,282 | 24 | 98,564 |
No | output | 1 | 49,282 | 24 | 98,565 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input
The first line contains integer n (1 β€ n β€ 200 000) β the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Examples
Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya
Note
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan
2. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman
2. ivan
3. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan
2. roman
3. alex
Submitted Solution:
```
n=int(input())
p=[0]*n
for i in range(n):
p[i]=input()
compteur=0
for i in range(n):
if i<n-compteur-1:
if p.count(p[i])>1:
p.remove(p[i])
compteur+=1
r=len(p)
for i in range(r):
print(p[r-1-i], end="\n")
``` | instruction | 0 | 49,283 | 24 | 98,566 |
No | output | 1 | 49,283 | 24 | 98,567 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is sad β New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands.
The local store introduced a new service this year, called "Build your own garland". So you can buy some red, green and blue lamps, provide them and the store workers will solder a single garland of them. The resulting garland will have all the lamps you provided put in a line. Moreover, no pair of lamps of the same color will be adjacent to each other in this garland!
For example, if you provide 3 red, 3 green and 3 blue lamps, the resulting garland can look like this: "RGBRBGBGR" ("RGB" being the red, green and blue color, respectively). Note that it's ok to have lamps of the same color on the ends of the garland.
However, if you provide, say, 1 red, 10 green and 2 blue lamps then the store workers won't be able to build any garland of them. Any garland consisting of these lamps will have at least one pair of lamps of the same color adjacent to each other. Note that the store workers should use all the lamps you provided.
So Polycarp has bought some sets of lamps and now he wants to know if the store workers can build a garland from each of them.
Input
The first line contains a single integer t (1 β€ t β€ 100) β the number of sets of lamps Polycarp has bought.
Each of the next t lines contains three integers r, g and b (1 β€ r, g, b β€ 10^9) β the number of red, green and blue lamps in the set, respectively.
Output
Print t lines β for each set of lamps print "Yes" if the store workers can build a garland from them and "No" otherwise.
Example
Input
3
3 3 3
1 10 2
2 1 1
Output
Yes
No
Yes
Note
The first two sets are desribed in the statement.
The third set produces garland "RBRG", for example. | instruction | 0 | 49,784 | 24 | 99,568 |
Tags: math
Correct Solution:
```
t = int(input())
for _ in range(t):
r, g, b = map(int, input().split())
r, g, b = sorted([r, g, b])
print('No' if b > r+g+1 else 'Yes')
``` | output | 1 | 49,784 | 24 | 99,569 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is sad β New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands.
The local store introduced a new service this year, called "Build your own garland". So you can buy some red, green and blue lamps, provide them and the store workers will solder a single garland of them. The resulting garland will have all the lamps you provided put in a line. Moreover, no pair of lamps of the same color will be adjacent to each other in this garland!
For example, if you provide 3 red, 3 green and 3 blue lamps, the resulting garland can look like this: "RGBRBGBGR" ("RGB" being the red, green and blue color, respectively). Note that it's ok to have lamps of the same color on the ends of the garland.
However, if you provide, say, 1 red, 10 green and 2 blue lamps then the store workers won't be able to build any garland of them. Any garland consisting of these lamps will have at least one pair of lamps of the same color adjacent to each other. Note that the store workers should use all the lamps you provided.
So Polycarp has bought some sets of lamps and now he wants to know if the store workers can build a garland from each of them.
Input
The first line contains a single integer t (1 β€ t β€ 100) β the number of sets of lamps Polycarp has bought.
Each of the next t lines contains three integers r, g and b (1 β€ r, g, b β€ 10^9) β the number of red, green and blue lamps in the set, respectively.
Output
Print t lines β for each set of lamps print "Yes" if the store workers can build a garland from them and "No" otherwise.
Example
Input
3
3 3 3
1 10 2
2 1 1
Output
Yes
No
Yes
Note
The first two sets are desribed in the statement.
The third set produces garland "RBRG", for example. | instruction | 0 | 49,785 | 24 | 99,570 |
Tags: math
Correct Solution:
```
T = int(input())
for i in range(T):
a,b,c = map(int, input().split(' '))
print("Yes") if b+c >= a-1 and a+c>= b-1 and b+a>=c-1 else print("No")
``` | output | 1 | 49,785 | 24 | 99,571 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is sad β New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands.
The local store introduced a new service this year, called "Build your own garland". So you can buy some red, green and blue lamps, provide them and the store workers will solder a single garland of them. The resulting garland will have all the lamps you provided put in a line. Moreover, no pair of lamps of the same color will be adjacent to each other in this garland!
For example, if you provide 3 red, 3 green and 3 blue lamps, the resulting garland can look like this: "RGBRBGBGR" ("RGB" being the red, green and blue color, respectively). Note that it's ok to have lamps of the same color on the ends of the garland.
However, if you provide, say, 1 red, 10 green and 2 blue lamps then the store workers won't be able to build any garland of them. Any garland consisting of these lamps will have at least one pair of lamps of the same color adjacent to each other. Note that the store workers should use all the lamps you provided.
So Polycarp has bought some sets of lamps and now he wants to know if the store workers can build a garland from each of them.
Input
The first line contains a single integer t (1 β€ t β€ 100) β the number of sets of lamps Polycarp has bought.
Each of the next t lines contains three integers r, g and b (1 β€ r, g, b β€ 10^9) β the number of red, green and blue lamps in the set, respectively.
Output
Print t lines β for each set of lamps print "Yes" if the store workers can build a garland from them and "No" otherwise.
Example
Input
3
3 3 3
1 10 2
2 1 1
Output
Yes
No
Yes
Note
The first two sets are desribed in the statement.
The third set produces garland "RBRG", for example. | instruction | 0 | 49,786 | 24 | 99,572 |
Tags: math
Correct Solution:
```
def sol(l):
m = -1
idx = 0
for i in range(3):
if l[i] > m :
m = l[i]
idx = i
sum = 0
piot = 0
for i in range(3):
if idx != i :
sum += l[i]
if m - sum < 2:
return 'Yes'
return 'No'
def main():
t = int(input())
for _ in range(t):
l = list(map(int,input().split()))
print(sol(l))
main()
``` | output | 1 | 49,786 | 24 | 99,573 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is sad β New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands.
The local store introduced a new service this year, called "Build your own garland". So you can buy some red, green and blue lamps, provide them and the store workers will solder a single garland of them. The resulting garland will have all the lamps you provided put in a line. Moreover, no pair of lamps of the same color will be adjacent to each other in this garland!
For example, if you provide 3 red, 3 green and 3 blue lamps, the resulting garland can look like this: "RGBRBGBGR" ("RGB" being the red, green and blue color, respectively). Note that it's ok to have lamps of the same color on the ends of the garland.
However, if you provide, say, 1 red, 10 green and 2 blue lamps then the store workers won't be able to build any garland of them. Any garland consisting of these lamps will have at least one pair of lamps of the same color adjacent to each other. Note that the store workers should use all the lamps you provided.
So Polycarp has bought some sets of lamps and now he wants to know if the store workers can build a garland from each of them.
Input
The first line contains a single integer t (1 β€ t β€ 100) β the number of sets of lamps Polycarp has bought.
Each of the next t lines contains three integers r, g and b (1 β€ r, g, b β€ 10^9) β the number of red, green and blue lamps in the set, respectively.
Output
Print t lines β for each set of lamps print "Yes" if the store workers can build a garland from them and "No" otherwise.
Example
Input
3
3 3 3
1 10 2
2 1 1
Output
Yes
No
Yes
Note
The first two sets are desribed in the statement.
The third set produces garland "RBRG", for example. | instruction | 0 | 49,789 | 24 | 99,578 |
Tags: math
Correct Solution:
```
t=int(input())
for i in range(t):
p=list(map(int,input().split()))
p.sort()
if p[2]-1<=p[1]+p[0]:print('Yes')
else:
print('No')
``` | output | 1 | 49,789 | 24 | 99,579 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is sad β New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands.
The local store introduced a new service this year, called "Build your own garland". So you can buy some red, green and blue lamps, provide them and the store workers will solder a single garland of them. The resulting garland will have all the lamps you provided put in a line. Moreover, no pair of lamps of the same color will be adjacent to each other in this garland!
For example, if you provide 3 red, 3 green and 3 blue lamps, the resulting garland can look like this: "RGBRBGBGR" ("RGB" being the red, green and blue color, respectively). Note that it's ok to have lamps of the same color on the ends of the garland.
However, if you provide, say, 1 red, 10 green and 2 blue lamps then the store workers won't be able to build any garland of them. Any garland consisting of these lamps will have at least one pair of lamps of the same color adjacent to each other. Note that the store workers should use all the lamps you provided.
So Polycarp has bought some sets of lamps and now he wants to know if the store workers can build a garland from each of them.
Input
The first line contains a single integer t (1 β€ t β€ 100) β the number of sets of lamps Polycarp has bought.
Each of the next t lines contains three integers r, g and b (1 β€ r, g, b β€ 10^9) β the number of red, green and blue lamps in the set, respectively.
Output
Print t lines β for each set of lamps print "Yes" if the store workers can build a garland from them and "No" otherwise.
Example
Input
3
3 3 3
1 10 2
2 1 1
Output
Yes
No
Yes
Note
The first two sets are desribed in the statement.
The third set produces garland "RBRG", for example. | instruction | 0 | 49,790 | 24 | 99,580 |
Tags: math
Correct Solution:
```
for i in range (int(input())):
r,g,b=map(int,input().split())
count=0
if(r>b+g+1):
count+=1
if(b>g+r+1):
count+=1
if(g>b+r+1):
count+=1
if(count==0):
print("YES")
else:
print("NO")
``` | output | 1 | 49,790 | 24 | 99,581 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This is an interactive problem.
This is a hard version of the problem. The difference from the easy version is that in the hard version 1 β€ t β€ min(n, 10^4) and the total number of queries is limited to 6 β
10^4.
Polycarp is playing a computer game. In this game, an array consisting of zeros and ones is hidden. Polycarp wins if he guesses the position of the k-th zero from the left t times.
Polycarp can make no more than 6 β
10^4 requests totally of the following type:
* ? l r β find out the sum of all elements in positions from l to r (1 β€ l β€ r β€ n) inclusive.
To make the game more interesting, each guessed zero turns into one and the game continues on the changed array. More formally, if the position of the k-th zero was x, then after Polycarp guesses this position, the x-th element of the array will be replaced from 0 to 1.
Help Polycarp win the game.
Interaction
First, your program must read two integers n and t (1 β€ n β€ 2 β
10^5, 1 β€ t β€ min(n, 10^4)).
Then t lines follow, each of which contains one integer k (1 β€ k β€ n). It is guaranteed that at the moment of the request the array contains at least k zeros. In order to get the next value of k, you must output the answer for the previous value of k.
After that, you can make no more than 6 β
10^4 requests in total.
Use the following format to output the answer (it is not a request, it doesn't count in 6 β
10^4):
* ! x β position of the k-th zero.
Positions in the array are numbered from left to right from 1 to n inclusive.
After printing t answers, your program should exit immediately.
In this task, the interactor is not adaptive. This means that within the same test, the hidden array and the queries do not change.
In case of an incorrect query, -1 will be displayed. When this value is received, your program must immediately exit normally (for example, by calling exit(0)), otherwise, the testing system may issue an arbitrary verdict.
If the number of requests is exceeded, the verdict wrong answer will be displayed.
Your solution may get the verdict Idleness limit exceeded if you don't print anything or forget to flush the output buffer.
To flush the output buffer, you need to do the following immediately after the query output and the end-of-line character:
* fflush(stdout) or cout.flush() in C ++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see the documentation for other languages.
Hacks
Use the following format for hacks:
On the first line print the string s (1 β€ |s| β€ 2 β
10^5), consisting of zeros and ones, and an integer t (1 β€ t β€ min(|s|, 10^4)) β hidden array and number of requests, respectively. In the next t lines output the number k (1 β€ k β€ |s|).
The hacked solution will not have direct access to the hidden array.
Example
Input
6 2
2
2
1
1
0
1
0
Output
? 4 6
? 1 1
? 1 2
? 5 5
! 5
? 2 2
! 2
Note
In the first test, the array [1, 0, 1, 1, 0, 1] is hidden. After answering the query k=2, the array changed to [1, 0, 1, 1, 1, 1]. | instruction | 0 | 49,908 | 24 | 99,816 |
Tags: binary search, constructive algorithms, data structures, interactive
Correct Solution:
```
import sys
def ask_query(l, r):
print ("?", l+1, r+1)
sys.stdout.flush()
return int(input())
def check(low, mid):
return mid - low + 1 - ask_query(low, mid)
d = {}
n, t = map(int,input().split())
for nt in range(t):
k = int(input())
low = 0
high = n-1
while low<high:
mid = (low+high)//2
if (low, mid) not in d:
count = check(low, mid)
d[(low, mid)] = count
count = d[(low, mid)]
if count>=k:
high = mid
else:
k -= count
low = mid + 1
if (low, high) in d:
d[(low, high)] -= 1
print ("!", high+1)
``` | output | 1 | 49,908 | 24 | 99,817 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.