message stringlengths 2 65.1k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 0 108k | cluster float64 14 14 | __index_level_0__ int64 0 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot.
Input
The first line contains a single integer n (1 β€ n β€ 1000) β the number of groups.
Each of the following n lines contains a sequence consisting of 7 zeroes and ones β the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot.
Output
Print minimum number of rooms needed to hold all groups classes on Monday.
Examples
Input
2
0101010
1010101
Output
1
Input
3
0101011
0011001
0110111
Output
3
Note
In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group.
In the second example three rooms is enough, because in the seventh time slot all three groups have classes. | instruction | 0 | 41,755 | 14 | 83,510 |
Tags: implementation
Correct Solution:
```
#-------------------------------#
#INCLUDE <Amirhossein_Alimirzaei>
#INCLUDE <HajLorenzo>
#-------------------------------#
__=[]
for o in range(7):
__.append(0)
for _1_ in range(int(input())):
___=input()
for _2_ in range(7):
__[_2_]+=int(___[_2_])
print(max(__))
``` | output | 1 | 41,755 | 14 | 83,511 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot.
Input
The first line contains a single integer n (1 β€ n β€ 1000) β the number of groups.
Each of the following n lines contains a sequence consisting of 7 zeroes and ones β the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot.
Output
Print minimum number of rooms needed to hold all groups classes on Monday.
Examples
Input
2
0101010
1010101
Output
1
Input
3
0101011
0011001
0110111
Output
3
Note
In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group.
In the second example three rooms is enough, because in the seventh time slot all three groups have classes. | instruction | 0 | 41,756 | 14 | 83,512 |
Tags: implementation
Correct Solution:
```
n=int(input())
x=[]
for i in range(0,n):
s=input()
for j in range(0,len(s)):
if s[j]=="1":
x.append(j+1)
else:
continue
x.sort()
y=1
z=1
for i in range(0,len(x)-1):
if x[i]==x[i+1]:
y+=1
else:
if y>=z:
z=y
y=1
else:
y=1
if len(x)==0:
print("0")
else:
print(max(y,z))
``` | output | 1 | 41,756 | 14 | 83,513 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot.
Input
The first line contains a single integer n (1 β€ n β€ 1000) β the number of groups.
Each of the following n lines contains a sequence consisting of 7 zeroes and ones β the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot.
Output
Print minimum number of rooms needed to hold all groups classes on Monday.
Examples
Input
2
0101010
1010101
Output
1
Input
3
0101011
0011001
0110111
Output
3
Note
In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group.
In the second example three rooms is enough, because in the seventh time slot all three groups have classes. | instruction | 0 | 41,757 | 14 | 83,514 |
Tags: implementation
Correct Solution:
```
cases = int(input())
matrix = []
while cases:
cases -= 1
lst = list(input())
matrix.append(lst)
traverse = [[matrix[i][j] for i in range(len(matrix))] for j in range(len(matrix[0]))]
mx = -1
for row in traverse:
if row.count("1") > mx:
mx = row.count("1")
print(mx)
``` | output | 1 | 41,757 | 14 | 83,515 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot.
Input
The first line contains a single integer n (1 β€ n β€ 1000) β the number of groups.
Each of the following n lines contains a sequence consisting of 7 zeroes and ones β the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot.
Output
Print minimum number of rooms needed to hold all groups classes on Monday.
Examples
Input
2
0101010
1010101
Output
1
Input
3
0101011
0011001
0110111
Output
3
Note
In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group.
In the second example three rooms is enough, because in the seventh time slot all three groups have classes. | instruction | 0 | 41,758 | 14 | 83,516 |
Tags: implementation
Correct Solution:
```
l,c=[],0
for x in range(int(input())):l.append(input())
for y in range(7):
s=0
for x in range(len(l)):
if l[x][y]=="1":s+=1
c=max(c,s)
print(c)
``` | output | 1 | 41,758 | 14 | 83,517 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot.
Input
The first line contains a single integer n (1 β€ n β€ 1000) β the number of groups.
Each of the following n lines contains a sequence consisting of 7 zeroes and ones β the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot.
Output
Print minimum number of rooms needed to hold all groups classes on Monday.
Examples
Input
2
0101010
1010101
Output
1
Input
3
0101011
0011001
0110111
Output
3
Note
In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group.
In the second example three rooms is enough, because in the seventh time slot all three groups have classes. | instruction | 0 | 41,759 | 14 | 83,518 |
Tags: implementation
Correct Solution:
```
n = int(input())
rs = [0]*8
for i in range(n):
s = input()
for j in range(7):
if s[j] == '1':
rs[j]+=1
print(max(rs))
``` | output | 1 | 41,759 | 14 | 83,519 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot.
Input
The first line contains a single integer n (1 β€ n β€ 1000) β the number of groups.
Each of the following n lines contains a sequence consisting of 7 zeroes and ones β the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot.
Output
Print minimum number of rooms needed to hold all groups classes on Monday.
Examples
Input
2
0101010
1010101
Output
1
Input
3
0101011
0011001
0110111
Output
3
Note
In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group.
In the second example three rooms is enough, because in the seventh time slot all three groups have classes.
Submitted Solution:
```
a=[*zip(*[*open(0)][1:])]
print(max(x.count('1') for x in a))
``` | instruction | 0 | 41,760 | 14 | 83,520 |
Yes | output | 1 | 41,760 | 14 | 83,521 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot.
Input
The first line contains a single integer n (1 β€ n β€ 1000) β the number of groups.
Each of the following n lines contains a sequence consisting of 7 zeroes and ones β the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot.
Output
Print minimum number of rooms needed to hold all groups classes on Monday.
Examples
Input
2
0101010
1010101
Output
1
Input
3
0101011
0011001
0110111
Output
3
Note
In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group.
In the second example three rooms is enough, because in the seventh time slot all three groups have classes.
Submitted Solution:
```
n = int(input())
targ = [0]*7
for x in range(n):
l1 = [int(x) for x in list(input())]
for y in range(7):
targ[y]+=l1[y]
print(max(targ))
``` | instruction | 0 | 41,761 | 14 | 83,522 |
Yes | output | 1 | 41,761 | 14 | 83,523 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot.
Input
The first line contains a single integer n (1 β€ n β€ 1000) β the number of groups.
Each of the following n lines contains a sequence consisting of 7 zeroes and ones β the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot.
Output
Print minimum number of rooms needed to hold all groups classes on Monday.
Examples
Input
2
0101010
1010101
Output
1
Input
3
0101011
0011001
0110111
Output
3
Note
In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group.
In the second example three rooms is enough, because in the seventh time slot all three groups have classes.
Submitted Solution:
```
cnt = [0] * 7
n = int(input())
for _ in range(n):
s = input()
for i in range(7):
if s[i] == "1":
cnt[i] += 1
print(max(cnt))
``` | instruction | 0 | 41,763 | 14 | 83,526 |
Yes | output | 1 | 41,763 | 14 | 83,527 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1, 2, β¦ n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were a_i persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let b_i be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b_1, b_2, β¦, b_n that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Input
The first line contains a single integer n (1 β€ n β€ 10^5), the number of persons in the party.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n-1), the statements of people.
Output
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b_1, b_2, β¦, b_n (1 β€ b_i β€ n).
If there are multiple answers, print any of them.
Examples
Input
3
0 0 0
Output
Possible
1 1 1
Input
5
3 3 2 2 2
Output
Possible
1 1 2 2 2
Input
4
0 1 2 3
Output
Impossible
Note
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible. | instruction | 0 | 42,125 | 14 | 84,250 |
Tags: constructive algorithms, implementation
Correct Solution:
```
from sys import stdin, stdout
from math import *
from heapq import *
from collections import *
def main():
n=int(stdin.readline())
a=[n]+[int(x) for x in stdin.readline().split()]
c=[[]]
for _ in range(n+2):
c.append([])
b=[0]
for i in range(1,1+n):
x=a[i]
c[n-x].append(i)
b.append(i)
for x in range(1,n+1):
if (len(c[x])>0):
m=len(c[x])
if ((m % x)>0):
stdout.write("Impossible")
return 0
for j in range(m):
b[c[x][j]]=c[x][floor(j/x)]
stdout.write("Possible\n"+" ".join([str(x) for x in b[1:]]))
return 0
if __name__ == "__main__":
main()
``` | output | 1 | 42,125 | 14 | 84,251 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1, 2, β¦ n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were a_i persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let b_i be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b_1, b_2, β¦, b_n that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Input
The first line contains a single integer n (1 β€ n β€ 10^5), the number of persons in the party.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n-1), the statements of people.
Output
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b_1, b_2, β¦, b_n (1 β€ b_i β€ n).
If there are multiple answers, print any of them.
Examples
Input
3
0 0 0
Output
Possible
1 1 1
Input
5
3 3 2 2 2
Output
Possible
1 1 2 2 2
Input
4
0 1 2 3
Output
Impossible
Note
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible. | instruction | 0 | 42,126 | 14 | 84,252 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n=int(input())
d={}
i=j=g=0
for x in map(int,input().split()):d.setdefault(n-x,[]).append(i);i+=1
b=[0]*n
s='ossible'
for x in d:
for i in d[x]:
if j==0:j=x;g+=1
b[i]=g;j-=1
if j:print('Imp'+s);exit()
print('P'+s,*b)
``` | output | 1 | 42,126 | 14 | 84,253 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1, 2, β¦ n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were a_i persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let b_i be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b_1, b_2, β¦, b_n that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Input
The first line contains a single integer n (1 β€ n β€ 10^5), the number of persons in the party.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n-1), the statements of people.
Output
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b_1, b_2, β¦, b_n (1 β€ b_i β€ n).
If there are multiple answers, print any of them.
Examples
Input
3
0 0 0
Output
Possible
1 1 1
Input
5
3 3 2 2 2
Output
Possible
1 1 2 2 2
Input
4
0 1 2 3
Output
Impossible
Note
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible. | instruction | 0 | 42,127 | 14 | 84,254 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
N=n+1
c=[0]*N
b=[0]*n
e={}
q=0
z=0
for i in range(N):
e[i]=[]
for i in range(n):
c[n-a[i]]+=1
e[n-a[i]]+=[i]
for i in range(1,N):
if c[i]%i>0:
print('Impossible')
exit(0)
elif c[i]>0:
z=i;
for x in e[i]:
if z==i:
q+=1;z=0;
z+=1
b[x]=q;
print('Possible')
for x in b:
print(x,end=' ')
``` | output | 1 | 42,127 | 14 | 84,255 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1, 2, β¦ n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were a_i persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let b_i be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b_1, b_2, β¦, b_n that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Input
The first line contains a single integer n (1 β€ n β€ 10^5), the number of persons in the party.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n-1), the statements of people.
Output
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b_1, b_2, β¦, b_n (1 β€ b_i β€ n).
If there are multiple answers, print any of them.
Examples
Input
3
0 0 0
Output
Possible
1 1 1
Input
5
3 3 2 2 2
Output
Possible
1 1 2 2 2
Input
4
0 1 2 3
Output
Impossible
Note
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible. | instruction | 0 | 42,128 | 14 | 84,256 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
s = []
for i in range(n):
s.append((n-a[i], i))
s.sort()
ans = []
t = 0
l = 0
for i in range(n):
if l == 0:
t += 1
ans.append((s[i][1], t))
l = s[i][0]-1
else:
if s[i][0] == s[i-1][0]:
l -= 1
ans.append((s[i][1], t))
else:
print('Impossible')
exit()
if t > n or l > 0:
print('Impossible')
else:
ans.sort()
x = [ans[i][1] for i in range(n)]
print('Possible')
print(*x)
``` | output | 1 | 42,128 | 14 | 84,257 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1, 2, β¦ n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were a_i persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let b_i be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b_1, b_2, β¦, b_n that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Input
The first line contains a single integer n (1 β€ n β€ 10^5), the number of persons in the party.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n-1), the statements of people.
Output
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b_1, b_2, β¦, b_n (1 β€ b_i β€ n).
If there are multiple answers, print any of them.
Examples
Input
3
0 0 0
Output
Possible
1 1 1
Input
5
3 3 2 2 2
Output
Possible
1 1 2 2 2
Input
4
0 1 2 3
Output
Impossible
Note
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible. | instruction | 0 | 42,129 | 14 | 84,258 |
Tags: constructive algorithms, implementation
Correct Solution:
```
import math
def hats(n, arr):
processed = [False] * n
hats = [None] * n
cur_hat = 0
for i, diff_count in enumerate(arr):
if processed[i]: continue
cur_hat += 1
hats[i] = cur_hat
processed[i] = True
same_count = n - diff_count - 1
if not same_count: continue
for j in range(i+1, n):
if arr[j] == diff_count:
same_count -= 1
processed[j] = True
hats[j] = cur_hat
if not same_count:
break
if same_count:
print('Impossible')
return
print('Possible')
print(' '.join(list(map(str, hats))))
if __name__ == '__main__':
n = int(input())
answers = list(map(int, input().strip().split()))
hats(n, answers)
``` | output | 1 | 42,129 | 14 | 84,259 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1, 2, β¦ n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were a_i persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let b_i be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b_1, b_2, β¦, b_n that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Input
The first line contains a single integer n (1 β€ n β€ 10^5), the number of persons in the party.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n-1), the statements of people.
Output
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b_1, b_2, β¦, b_n (1 β€ b_i β€ n).
If there are multiple answers, print any of them.
Examples
Input
3
0 0 0
Output
Possible
1 1 1
Input
5
3 3 2 2 2
Output
Possible
1 1 2 2 2
Input
4
0 1 2 3
Output
Impossible
Note
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible. | instruction | 0 | 42,130 | 14 | 84,260 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n=int(input())
k=0
d={}
i=0
for x in map(int,input().split()):d.setdefault(n-x,[]).append(i);i+=1
b=[0]*n
s='ossible'
g=0
for x in d:
l=d[x];g+=1;j=0
if len(l)%x:print('Imp'+s);exit()
for i in l:
if j==x:j=0;g+=1
b[i]=g;j+=1
print('P'+s,*b)
``` | output | 1 | 42,130 | 14 | 84,261 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1, 2, β¦ n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were a_i persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let b_i be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b_1, b_2, β¦, b_n that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Input
The first line contains a single integer n (1 β€ n β€ 10^5), the number of persons in the party.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n-1), the statements of people.
Output
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b_1, b_2, β¦, b_n (1 β€ b_i β€ n).
If there are multiple answers, print any of them.
Examples
Input
3
0 0 0
Output
Possible
1 1 1
Input
5
3 3 2 2 2
Output
Possible
1 1 2 2 2
Input
4
0 1 2 3
Output
Impossible
Note
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible. | instruction | 0 | 42,131 | 14 | 84,262 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n= int(input())
l = list(map(int,input().split()))
dict={}
for i in range(n):
dict[i]=l[i]
sorted_x = sorted(dict.items(), key=lambda kv: kv[1])
ind = []
for i in sorted_x:
ind.append(i[0])
l.sort()
c=1
ch=0
z=0
for i in range(0,n):
if i!=z:continue
x=l[i]
z=n-x
for j in range(i,i+z):
if j>=n or l[j]!=x:
print("Impossible")
ch = 1
break
l[j]=c
if ch:
break
c=c+1
z=z+i
if ch==0:
print("Possible")
f = [0]*n
x=0
for i in ind:
f[i]=l[x]
x = x+1
for i in f:print(i,end=" ")
``` | output | 1 | 42,131 | 14 | 84,263 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1, 2, β¦ n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were a_i persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let b_i be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b_1, b_2, β¦, b_n that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Input
The first line contains a single integer n (1 β€ n β€ 10^5), the number of persons in the party.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n-1), the statements of people.
Output
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b_1, b_2, β¦, b_n (1 β€ b_i β€ n).
If there are multiple answers, print any of them.
Examples
Input
3
0 0 0
Output
Possible
1 1 1
Input
5
3 3 2 2 2
Output
Possible
1 1 2 2 2
Input
4
0 1 2 3
Output
Impossible
Note
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible. | instruction | 0 | 42,132 | 14 | 84,264 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n=int(input())
k=0
d={}
i=0
for x in map(int,input().split()):d.setdefault(n-x,[]).append(i);i+=1
b=[0]*n
s='ossible'
g=0
for x in d:
l=d[x];g+=1;j=0
for i in l:
if j==x:j=0;g+=1
b[i]=g;j+=1
if j!=x:print('Imp'+s);exit()
print('P'+s,*b)
``` | output | 1 | 42,132 | 14 | 84,265 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1, 2, β¦ n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were a_i persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let b_i be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b_1, b_2, β¦, b_n that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Input
The first line contains a single integer n (1 β€ n β€ 10^5), the number of persons in the party.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n-1), the statements of people.
Output
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b_1, b_2, β¦, b_n (1 β€ b_i β€ n).
If there are multiple answers, print any of them.
Examples
Input
3
0 0 0
Output
Possible
1 1 1
Input
5
3 3 2 2 2
Output
Possible
1 1 2 2 2
Input
4
0 1 2 3
Output
Impossible
Note
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible.
Submitted Solution:
```
from sys import stdin
n=int(stdin.readline().strip())
s=list(map(int,stdin.readline().strip().split()))
if s.count(0)==n:
print("Possible")
print(("1 "*n))
exit(0)
s1=[]
for i in range(n):
s1.append((s[i],i))
s1.sort(reverse=True)
ans=[-1 for i in range(n)]
dif=0
cur=1
dp=[0 for i in range(n+2)]
for i in range(n):
ans[s1[i][1]]=cur
dp[cur]+=1
if (n-(i+1))==(s1[i][0]-dif):
dif=i+1
cur+=1
for i in range(n):
if (n-dp[ans[i]])!=s[i]:
print("Impossible")
exit(0)
print("Possible")
print(*ans)
``` | instruction | 0 | 42,133 | 14 | 84,266 |
Yes | output | 1 | 42,133 | 14 | 84,267 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1, 2, β¦ n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were a_i persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let b_i be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b_1, b_2, β¦, b_n that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Input
The first line contains a single integer n (1 β€ n β€ 10^5), the number of persons in the party.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n-1), the statements of people.
Output
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b_1, b_2, β¦, b_n (1 β€ b_i β€ n).
If there are multiple answers, print any of them.
Examples
Input
3
0 0 0
Output
Possible
1 1 1
Input
5
3 3 2 2 2
Output
Possible
1 1 2 2 2
Input
4
0 1 2 3
Output
Impossible
Note
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible.
Submitted Solution:
```
# -*- coding: utf-8 -*-
N = int(input())
aN = list(map(int, input().split()))
for i in range(N):
aN[i] = [N - aN[i], i+1]
aN.sort()
b = 1
cnt = 0
for i in range(N):
cnt += 1
if aN[i][0] == cnt:
for j in range(i+1-cnt, i+1):
if aN[j][0] != cnt:
print('Impossible')
exit()
aN[j].append(b)
b += 1
cnt = 0
if len(aN[-1]) == 3:
aN.sort(key=lambda x: x[1])
print('Possible')
for i in range(N):
print(aN[i][2], end=' ')
else:
print('Impossible')
``` | instruction | 0 | 42,134 | 14 | 84,268 |
Yes | output | 1 | 42,134 | 14 | 84,269 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1, 2, β¦ n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were a_i persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let b_i be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b_1, b_2, β¦, b_n that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Input
The first line contains a single integer n (1 β€ n β€ 10^5), the number of persons in the party.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n-1), the statements of people.
Output
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b_1, b_2, β¦, b_n (1 β€ b_i β€ n).
If there are multiple answers, print any of them.
Examples
Input
3
0 0 0
Output
Possible
1 1 1
Input
5
3 3 2 2 2
Output
Possible
1 1 2 2 2
Input
4
0 1 2 3
Output
Impossible
Note
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible.
Submitted Solution:
```
n = int(input())
L = [n-int(x) for x in input().split()]
D = {}
for i in L:
if i in D:
D[i] += 1
else:
D[i] = 1
s = 0
check = True
for i in D.keys():
if D[i]%i != 0:
check = False
break
else:
s += D[i]
if s != n:
print('Impossible')
else:
if check == False:
print('Impossible')
else:
print('Possible')
small = 1
D2 = {}
for i in D:
D2[i] = list(range(small,small+(D[i]//i)))*i
small += D[i]//i
for i in L:
print(D2[i][-1],end = ' ')
D2[i].pop()
``` | instruction | 0 | 42,135 | 14 | 84,270 |
Yes | output | 1 | 42,135 | 14 | 84,271 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1, 2, β¦ n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were a_i persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let b_i be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b_1, b_2, β¦, b_n that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Input
The first line contains a single integer n (1 β€ n β€ 10^5), the number of persons in the party.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n-1), the statements of people.
Output
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b_1, b_2, β¦, b_n (1 β€ b_i β€ n).
If there are multiple answers, print any of them.
Examples
Input
3
0 0 0
Output
Possible
1 1 1
Input
5
3 3 2 2 2
Output
Possible
1 1 2 2 2
Input
4
0 1 2 3
Output
Impossible
Note
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible.
Submitted Solution:
```
n = int(input())
ch = {}
dif = [int(x) for x in input().split()]
same = []
ans = [0 for x in range(n)]
for x in dif:
same.append(n-x)
for i in range(len(same)):
if same[i] not in ch:
ch[same[i]] = list()
ch[same[i]].append(i)
cnt = 1
for key, val in ch.items():
if len(val)%key:
print("Impossible")
quit()
temp = key
for x in val:
if temp == 0:
temp = key
cnt += 1
ans[x] = cnt
temp -= 1
cnt += 1
print("Possible")
for y in ans:
print(y, end= " ")
``` | instruction | 0 | 42,136 | 14 | 84,272 |
Yes | output | 1 | 42,136 | 14 | 84,273 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1, 2, β¦ n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were a_i persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let b_i be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b_1, b_2, β¦, b_n that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Input
The first line contains a single integer n (1 β€ n β€ 10^5), the number of persons in the party.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n-1), the statements of people.
Output
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b_1, b_2, β¦, b_n (1 β€ b_i β€ n).
If there are multiple answers, print any of them.
Examples
Input
3
0 0 0
Output
Possible
1 1 1
Input
5
3 3 2 2 2
Output
Possible
1 1 2 2 2
Input
4
0 1 2 3
Output
Impossible
Note
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible.
Submitted Solution:
```
n=int(input())
arr=[0]*n
arr=list(map(int,input().split()))
s=set(arr)
if len(s)==1:
print("Possible")
for i in range(n):
print("1")
elif len(s)==n:
print("Impossible")
else:
print("Possible")
for q in arr:
print(n-(q+1),end = " ")
``` | instruction | 0 | 42,137 | 14 | 84,274 |
No | output | 1 | 42,137 | 14 | 84,275 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1, 2, β¦ n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were a_i persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let b_i be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b_1, b_2, β¦, b_n that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Input
The first line contains a single integer n (1 β€ n β€ 10^5), the number of persons in the party.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n-1), the statements of people.
Output
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b_1, b_2, β¦, b_n (1 β€ b_i β€ n).
If there are multiple answers, print any of them.
Examples
Input
3
0 0 0
Output
Possible
1 1 1
Input
5
3 3 2 2 2
Output
Possible
1 1 2 2 2
Input
4
0 1 2 3
Output
Impossible
Note
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible.
Submitted Solution:
```
from sys import stdin
n=int(stdin.readline().strip())
s=list(map(int,stdin.readline().strip().split()))
if s.count(0)==n:
print("Possible")
print(("1 "*n))
exit(0)
s1=[]
for i in range(n):
s1.append((s[i],i))
s1.sort(reverse=True)
ans=[-1 for i in range(n)]
dif=0
cur=1
x=len(set(s))
for i in range(n):
if dif>s1[i][0] or n==1:
print("Impossible")
exit(0)
ans[s1[i][1]]=cur
if (n-(i+1))==(s1[i][0]-dif) or (i<(n-1) and s1[i][0]!=s1[i+1][0]):
dif=i+1
cur+=1
print("Possible")
print(*ans)
``` | instruction | 0 | 42,138 | 14 | 84,276 |
No | output | 1 | 42,138 | 14 | 84,277 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1, 2, β¦ n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were a_i persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let b_i be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b_1, b_2, β¦, b_n that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Input
The first line contains a single integer n (1 β€ n β€ 10^5), the number of persons in the party.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n-1), the statements of people.
Output
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b_1, b_2, β¦, b_n (1 β€ b_i β€ n).
If there are multiple answers, print any of them.
Examples
Input
3
0 0 0
Output
Possible
1 1 1
Input
5
3 3 2 2 2
Output
Possible
1 1 2 2 2
Input
4
0 1 2 3
Output
Impossible
Note
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible.
Submitted Solution:
```
n = int(input())
listt = list(map(int, input().split()))
mapp = {}
tmp = 0
for i in range(n):
tmp = listt[i]
if n-tmp in mapp:
mapp[n - tmp] += 1
else:
mapp[n - tmp] = 1
listt[i] = n - tmp
ss = 1
for i in mapp:
if i > mapp[i] and i % mapp[i] != 0:
ss = 0
break
elif i <= mapp[i] and mapp[i] % i != 0:
ss = 0
break
if ss == 1:
print('Possible')
print(*listt, sep=' ')
else:
print('Impossible')
``` | instruction | 0 | 42,139 | 14 | 84,278 |
No | output | 1 | 42,139 | 14 | 84,279 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that n persons took part in that party. To make the party funnier, each person wore one hat among n kinds of weird hats numbered 1, 2, β¦ n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.
After the party, the i-th person said that there were a_i persons wearing a hat differing from his own.
It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let b_i be the number of hat type the i-th person was wearing, Chouti wants you to find any possible b_1, b_2, β¦, b_n that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.
Input
The first line contains a single integer n (1 β€ n β€ 10^5), the number of persons in the party.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n-1), the statements of people.
Output
If there is no solution, print a single line "Impossible".
Otherwise, print "Possible" and then n integers b_1, b_2, β¦, b_n (1 β€ b_i β€ n).
If there are multiple answers, print any of them.
Examples
Input
3
0 0 0
Output
Possible
1 1 1
Input
5
3 3 2 2 2
Output
Possible
1 1 2 2 2
Input
4
0 1 2 3
Output
Impossible
Note
In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 1.
In the answer to the second example, the first and the second person wore the hat with type 1 and all other wore a hat of type 2.
So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.
In the third example, it can be shown that no solution exists.
In the first and the second example, other possible configurations are possible.
Submitted Solution:
```
n = int(input())
u = list(map(int, input().split()))
a = [0] * n
for i in range(n):
a[u[i]] += 1
for i in range(n):
if a[i] != 0 and a[i] != n - i:
print('Impossible')
exit()
print('Possible')
if a[0] != 0:
print('1 ' * n)
else:
print(' '.join(map(str, u)))
``` | instruction | 0 | 42,140 | 14 | 84,280 |
No | output | 1 | 42,140 | 14 | 84,281 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture β press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input
The first line of the input contains three numbers n, m, k (1 β€ n, m, k β€ 105) β the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an β the initial order of icons from left to right in the menu (from the first to the last one), ai β is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 β€ bi β€ n) β the ids of the launched applications in the planned order. One application may be launched multiple times.
Output
Print a single number β the number of gestures that Anya needs to make to launch all the applications in the desired order.
Examples
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
Output
7
Input
5 4 2
3 1 5 2 4
4 4 4 4
Output
8
Note
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons β (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures. | instruction | 0 | 42,470 | 14 | 84,940 |
Tags: constructive algorithms, data structures, implementation
Correct Solution:
```
n,m,k = map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
d,di,res={},{},0
for i,x in enumerate(a):
d[x]=i
di[i]=x
for i,y in enumerate(b):
x=d[y]
res+=x//k+1
if x>0:
d[di[x-1]]+=1
d[y]-=1
di[x],di[x-1]=di[x-1],di[x]
print(res)
``` | output | 1 | 42,470 | 14 | 84,941 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture β press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input
The first line of the input contains three numbers n, m, k (1 β€ n, m, k β€ 105) β the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an β the initial order of icons from left to right in the menu (from the first to the last one), ai β is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 β€ bi β€ n) β the ids of the launched applications in the planned order. One application may be launched multiple times.
Output
Print a single number β the number of gestures that Anya needs to make to launch all the applications in the desired order.
Examples
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
Output
7
Input
5 4 2
3 1 5 2 4
4 4 4 4
Output
8
Note
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons β (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures. | instruction | 0 | 42,471 | 14 | 84,942 |
Tags: constructive algorithms, data structures, implementation
Correct Solution:
```
n,m,k=[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
do=[int(i) for i in input().split()]
D={}
j=0
for i in s:
D[i]=j
j+=1
N=0
for i in do:
x=D[i]
N+=(x//k+1)
if D[i]!=0:
p=s[x-1]
D[p],D[i]=D[i],D[p]
s[x],s[x-1]=s[x-1],s[x]
print(N)
# Made By Mostafa_Khaled
``` | output | 1 | 42,471 | 14 | 84,943 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture β press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input
The first line of the input contains three numbers n, m, k (1 β€ n, m, k β€ 105) β the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an β the initial order of icons from left to right in the menu (from the first to the last one), ai β is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 β€ bi β€ n) β the ids of the launched applications in the planned order. One application may be launched multiple times.
Output
Print a single number β the number of gestures that Anya needs to make to launch all the applications in the desired order.
Examples
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
Output
7
Input
5 4 2
3 1 5 2 4
4 4 4 4
Output
8
Note
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons β (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures. | instruction | 0 | 42,472 | 14 | 84,944 |
Tags: constructive algorithms, data structures, implementation
Correct Solution:
```
n,m,k=[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
do=[int(i) for i in input().split()]
D={}
j=0
for i in s:
D[i]=j
j+=1
N=0
for i in do:
x=D[i]
N+=(x//k+1)
if D[i]!=0:
p=s[x-1]
D[p],D[i]=D[i],D[p]
s[x],s[x-1]=s[x-1],s[x]
print(N)
``` | output | 1 | 42,472 | 14 | 84,945 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture β press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input
The first line of the input contains three numbers n, m, k (1 β€ n, m, k β€ 105) β the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an β the initial order of icons from left to right in the menu (from the first to the last one), ai β is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 β€ bi β€ n) β the ids of the launched applications in the planned order. One application may be launched multiple times.
Output
Print a single number β the number of gestures that Anya needs to make to launch all the applications in the desired order.
Examples
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
Output
7
Input
5 4 2
3 1 5 2 4
4 4 4 4
Output
8
Note
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons β (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures. | instruction | 0 | 42,473 | 14 | 84,946 |
Tags: constructive algorithms, data structures, implementation
Correct Solution:
```
__author__ = 'PrimuS'
n, m, k = (int(x) for x in input().split())
order = [int(x) for x in input().split()]
touch = [int(x) for x in input().split()]
# n = 100000
# order = [0] * n
# k = 2
# m = 100000
# touch = [0] * n
# for i in range(n):
# order[i] = i
# for i in range(m):
# touch[i] = i
res = 0
d = {}
for i in range(n):
d[order[i]] = i
for x in touch:
pos = d[x]
res += pos // k + 1
if pos > 0:
order[pos - 1], order[pos] = order[pos], order[pos - 1]
d[x] = pos - 1
d[order[pos]] = pos
print(res)
``` | output | 1 | 42,473 | 14 | 84,947 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture β press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input
The first line of the input contains three numbers n, m, k (1 β€ n, m, k β€ 105) β the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an β the initial order of icons from left to right in the menu (from the first to the last one), ai β is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 β€ bi β€ n) β the ids of the launched applications in the planned order. One application may be launched multiple times.
Output
Print a single number β the number of gestures that Anya needs to make to launch all the applications in the desired order.
Examples
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
Output
7
Input
5 4 2
3 1 5 2 4
4 4 4 4
Output
8
Note
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons β (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures. | instruction | 0 | 42,474 | 14 | 84,948 |
Tags: constructive algorithms, data structures, implementation
Correct Solution:
```
'''
Created on 2016-4-9
@author: chronocorax
'''
def line(): return [int(c) for c in input().split()]
n, m, k = line()
Q = line()
pos = [0] * (n + 1)
for i in range(n):
pos[Q[i]] = i
res = 0
op = line()
for i in range(m):
res += 1
t = op[i]
p = pos[t]
if p:
res += pos[t] // k
pos[t], pos[Q[p - 1]] = pos[Q[p - 1]], pos[t]
Q[p], Q[p - 1] = Q[p - 1], Q[p]
print(res)
``` | output | 1 | 42,474 | 14 | 84,949 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture β press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input
The first line of the input contains three numbers n, m, k (1 β€ n, m, k β€ 105) β the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an β the initial order of icons from left to right in the menu (from the first to the last one), ai β is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 β€ bi β€ n) β the ids of the launched applications in the planned order. One application may be launched multiple times.
Output
Print a single number β the number of gestures that Anya needs to make to launch all the applications in the desired order.
Examples
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
Output
7
Input
5 4 2
3 1 5 2 4
4 4 4 4
Output
8
Note
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons β (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures. | instruction | 0 | 42,475 | 14 | 84,950 |
Tags: constructive algorithms, data structures, implementation
Correct Solution:
```
from sys import stdin
def input():
return stdin.readline()
from math import ceil
n,m,l=list(map(int,input().split()))
d={}
j=0
for i in input().split():
j+=1
d[int(i)]=j
reversedd={value:key for key, value in d.items()}
oper=list(map(int,input().split()))
ans=0
for i in oper:
ans+=ceil(d[i]/l)
if d[i]!=1:
tt=d[i]-1
temp=reversedd[d[i]-1]
d[i]=tt
d[temp]=d[temp]+1
reversedd[d[i]]=i
reversedd[d[i]+1]=temp
print(ans)
``` | output | 1 | 42,475 | 14 | 84,951 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture β press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input
The first line of the input contains three numbers n, m, k (1 β€ n, m, k β€ 105) β the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an β the initial order of icons from left to right in the menu (from the first to the last one), ai β is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 β€ bi β€ n) β the ids of the launched applications in the planned order. One application may be launched multiple times.
Output
Print a single number β the number of gestures that Anya needs to make to launch all the applications in the desired order.
Examples
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
Output
7
Input
5 4 2
3 1 5 2 4
4 4 4 4
Output
8
Note
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons β (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures. | instruction | 0 | 42,476 | 14 | 84,952 |
Tags: constructive algorithms, data structures, implementation
Correct Solution:
```
from math import ceil
def move(l,i):
if i != 0:
l[i-1],l[i] = l[i],l[i-1]
return l
n,m,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
d = {}
for i in range(n):
d[a[i]] = i
cnt = 0
for i in b:
cnt += ceil((d[i]+1)/k)
if d[i] != 0:
d[i] -= 1
d[a[d[i]]] += 1
move(a,d[i]+1)
print(cnt)
``` | output | 1 | 42,476 | 14 | 84,953 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture β press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input
The first line of the input contains three numbers n, m, k (1 β€ n, m, k β€ 105) β the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an β the initial order of icons from left to right in the menu (from the first to the last one), ai β is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 β€ bi β€ n) β the ids of the launched applications in the planned order. One application may be launched multiple times.
Output
Print a single number β the number of gestures that Anya needs to make to launch all the applications in the desired order.
Examples
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
Output
7
Input
5 4 2
3 1 5 2 4
4 4 4 4
Output
8
Note
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons β (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures. | instruction | 0 | 42,477 | 14 | 84,954 |
Tags: constructive algorithms, data structures, implementation
Correct Solution:
```
n,m,p=map(int,input().split())
l=list(map(int,input().split()))
d={}
d1={}
for i in range(n) :
d[l[i]]=i+1
d1[i+1]=l[i]
l1=list(map(int,input().split()))
k=0
for i in range(m) :
if d[l1[i]]%p!=0 :
k+=d[l1[i]]//p+1
else :
k+=d[l1[i]]//p
if d[l1[i]]!=1 :
d1[d[l1[i]]],d1[d[l1[i]]-1]=d1[d[l1[i]]-1],d1[d[l1[i]]]
d[l1[i]]-=1
d[d1[d[l1[i]]+1]]+=1
print(k)
``` | output | 1 | 42,477 | 14 | 84,955 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture β press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input
The first line of the input contains three numbers n, m, k (1 β€ n, m, k β€ 105) β the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an β the initial order of icons from left to right in the menu (from the first to the last one), ai β is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 β€ bi β€ n) β the ids of the launched applications in the planned order. One application may be launched multiple times.
Output
Print a single number β the number of gestures that Anya needs to make to launch all the applications in the desired order.
Examples
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
Output
7
Input
5 4 2
3 1 5 2 4
4 4 4 4
Output
8
Note
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons β (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures.
Submitted Solution:
```
def main():
n, m, k = map(int, input().split())
icons = list(map(int, input().split()))
icons_for_launch_positions = list(map(int, input().split()))
gestures = m
positions = [0] * (n + 1)
for i in range(0, len(icons)):
positions[icons[i]] = i
for icon in icons_for_launch_positions:
gestures += (positions[icon] // k)
if positions[icon] != 0:
previous_icon = icons[positions[icon] - 1]
swap(icons, positions[icon], positions[previous_icon])
swap(positions, icon, previous_icon)
print(gestures)
def swap(collection_list, first_index, second_index):
temp = collection_list[first_index]
collection_list[first_index] = collection_list[second_index]
collection_list[second_index] = temp
if __name__ == '__main__':
main()
``` | instruction | 0 | 42,478 | 14 | 84,956 |
Yes | output | 1 | 42,478 | 14 | 84,957 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture β press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input
The first line of the input contains three numbers n, m, k (1 β€ n, m, k β€ 105) β the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an β the initial order of icons from left to right in the menu (from the first to the last one), ai β is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 β€ bi β€ n) β the ids of the launched applications in the planned order. One application may be launched multiple times.
Output
Print a single number β the number of gestures that Anya needs to make to launch all the applications in the desired order.
Examples
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
Output
7
Input
5 4 2
3 1 5 2 4
4 4 4 4
Output
8
Note
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons β (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures.
Submitted Solution:
```
n,m,k = map(int,input().split())
str2 = [int(i) for i in input().split()]
str3 = [int(i) for i in input().split()]
d = {} #!!!η¨dictionary
index = 0
for i in str2:
d[i] = index
index += 1
g=0
for i in str3:
x = d[i]
g += (x//k + 1)
if d[i] != 0:
p = str2[x-1]
d[p],d[i]=d[i],d[p]
str2[x-1],str2[x] = str2[x],str2[x-1]
print(g)
``` | instruction | 0 | 42,479 | 14 | 84,958 |
Yes | output | 1 | 42,479 | 14 | 84,959 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture β press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input
The first line of the input contains three numbers n, m, k (1 β€ n, m, k β€ 105) β the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an β the initial order of icons from left to right in the menu (from the first to the last one), ai β is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 β€ bi β€ n) β the ids of the launched applications in the planned order. One application may be launched multiple times.
Output
Print a single number β the number of gestures that Anya needs to make to launch all the applications in the desired order.
Examples
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
Output
7
Input
5 4 2
3 1 5 2 4
4 4 4 4
Output
8
Note
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons β (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures.
Submitted Solution:
```
import sys
def solve():
n, m, k = read()
a = read()
b = read()
loc = [0]*(n+1)
for i in range(n): loc[a[i]] = i
res = 0
for i in range(m):
dist = loc[b[i]] // k
res += (dist+1)
if loc[b[i]] > 0:
loc[b[i]]-=1
val = a[loc[b[i]]]
loc[val]+=1
a[loc[b[i]]], a[loc[b[i]]+1] = a[loc[b[i]]+1], a[loc[b[i]]]
return res
def read(mode=2):
inputs = input().strip()
if mode == 0: return inputs # String
if mode == 1: return inputs.split() # List of strings
if mode == 2: return list(map(int, inputs.split())) # List of integers
def write(s="\n"):
if s is None: s = ""
if isinstance(s, list): s = " ".join(map(str, s))
if isinstance(s, tuple): s = " ".join(map(str, s))
s = str(s)
print(s, end="")
def run():
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
res = solve()
write(res)
run()
``` | instruction | 0 | 42,480 | 14 | 84,960 |
Yes | output | 1 | 42,480 | 14 | 84,961 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture β press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input
The first line of the input contains three numbers n, m, k (1 β€ n, m, k β€ 105) β the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an β the initial order of icons from left to right in the menu (from the first to the last one), ai β is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 β€ bi β€ n) β the ids of the launched applications in the planned order. One application may be launched multiple times.
Output
Print a single number β the number of gestures that Anya needs to make to launch all the applications in the desired order.
Examples
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
Output
7
Input
5 4 2
3 1 5 2 4
4 4 4 4
Output
8
Note
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons β (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures.
Submitted Solution:
```
s6=input().split()
n=int(s6[0])
m=int(s6[1])
k=int(s6[2])
sabi=input().split()
loc=[]
suma=0
num=[0]*(n+10)
for i in range(n):
sabi[i]=int(sabi[i])
loc.append(sabi[i])
num[sabi[i]]=i
ope=input().split()
for i in range(m):
ope[i]=int(ope[i])
for i in range(m):
loca=num[ope[i]]
if loca==0:
suma+=1
else:
if loca+1>k and (loca+1)%k!=0:
suma+=int((loca+1)/k)+1
elif loca+1>k and (loca+1)%k==0:
suma+=int((loca+1)/k)
elif loca+1<=k:
suma+=1
tem=loc[loca]
tem1=loc[loca-1]
loc[loca]=loc[loca-1]
loc[loca-1]=tem
num[ope[i]]-=1
num[tem1]+=1
print(suma)
``` | instruction | 0 | 42,481 | 14 | 84,962 |
Yes | output | 1 | 42,481 | 14 | 84,963 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture β press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input
The first line of the input contains three numbers n, m, k (1 β€ n, m, k β€ 105) β the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an β the initial order of icons from left to right in the menu (from the first to the last one), ai β is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 β€ bi β€ n) β the ids of the launched applications in the planned order. One application may be launched multiple times.
Output
Print a single number β the number of gestures that Anya needs to make to launch all the applications in the desired order.
Examples
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
Output
7
Input
5 4 2
3 1 5 2 4
4 4 4 4
Output
8
Note
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons β (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures.
Submitted Solution:
```
import math
split = lambda: list(map(int, input().split()))
a, b, c = split()
apps = split()
apppos = {}
for x in range(1, a + 1):
apppos[x] = apps.index(x)
launched = split()
n = 0
for x in launched:
n += math.ceil((apppos[x] + 1) / c)
p = apppos[x]
if p > 0:
apppos[apps[p - 1]] = p
apppos[x] -= 1
print(n)
``` | instruction | 0 | 42,482 | 14 | 84,964 |
No | output | 1 | 42,482 | 14 | 84,965 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture β press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input
The first line of the input contains three numbers n, m, k (1 β€ n, m, k β€ 105) β the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an β the initial order of icons from left to right in the menu (from the first to the last one), ai β is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 β€ bi β€ n) β the ids of the launched applications in the planned order. One application may be launched multiple times.
Output
Print a single number β the number of gestures that Anya needs to make to launch all the applications in the desired order.
Examples
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
Output
7
Input
5 4 2
3 1 5 2 4
4 4 4 4
Output
8
Note
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons β (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures.
Submitted Solution:
```
n,m,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
a1=[0]*(n+1)
i=1
for j in a:
a1[j]=j
i+=1
b=[int(i) for i in input().split()]
ans=0
for i in b:
index=a1[i]
ans+=(index-1)//k+1
if index>1:
tmp1=a[index-1]
tmp0=a[index-2]
a[index-1],a[index-2]=tmp0,tmp1
a1[tmp0],a1[tmp1]=index,index-1
print(ans)
``` | instruction | 0 | 42,483 | 14 | 84,966 |
No | output | 1 | 42,483 | 14 | 84,967 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture β press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input
The first line of the input contains three numbers n, m, k (1 β€ n, m, k β€ 105) β the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an β the initial order of icons from left to right in the menu (from the first to the last one), ai β is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 β€ bi β€ n) β the ids of the launched applications in the planned order. One application may be launched multiple times.
Output
Print a single number β the number of gestures that Anya needs to make to launch all the applications in the desired order.
Examples
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
Output
7
Input
5 4 2
3 1 5 2 4
4 4 4 4
Output
8
Note
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons β (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures.
Submitted Solution:
```
import math
llll=input().split()
n=int(llll[0])
m=int(llll[1])
k=int(llll[2])
l=list(map(int,input().split()))
ll=list(map(int,input().split()))
s=0
for o in range(m):
q=l.index(ll[o])
if q==0:
s+=1
else:
s+=math.floor(q/k)+1
l.pop(q)
l.insert(q-1,ll[o])
print(l)
print(s)
``` | instruction | 0 | 42,484 | 14 | 84,968 |
No | output | 1 | 42,484 | 14 | 84,969 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture β press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input
The first line of the input contains three numbers n, m, k (1 β€ n, m, k β€ 105) β the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an β the initial order of icons from left to right in the menu (from the first to the last one), ai β is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 β€ bi β€ n) β the ids of the launched applications in the planned order. One application may be launched multiple times.
Output
Print a single number β the number of gestures that Anya needs to make to launch all the applications in the desired order.
Examples
Input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
Output
7
Input
5 4 2
3 1 5 2 4
4 4 4 4
Output
8
Note
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons β (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures.
Submitted Solution:
```
def main():
#get first line
line = input()
(numApps,numLaunch,numScreen) = (int(t) for t in line.split())
#get second line
line = input()
order = []
for l in line.split():
order.append(int(l))
#get third line
line = input()
apps = {}
appOrder = []
for l in line.split():
apps[int(l)] = int(l)
appOrder.append(int(l))
steps = 0
for a in appOrder:
steps += apps[a]//numScreen + 1
if apps[a] == 1:
pass
elif apps[a] - 1 in apps.values():
x = key(apps, apps[a] - 1)
apps[x] += 1
apps[a] -= 1
print(steps)
def key(dic, val):
for x in dic:
if dic[x] == val:
return x
main()
``` | instruction | 0 | 42,485 | 14 | 84,970 |
No | output | 1 | 42,485 | 14 | 84,971 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)
Given integers l, r and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!
Input
The first line of the input contains three space-separated integers l, r and k (1 β€ l β€ r β€ 1018, 2 β€ k β€ 109).
Output
Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).
Examples
Input
1 10 2
Output
1 2 4 8
Input
2 4 5
Output
-1
Note
Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed. | instruction | 0 | 42,519 | 14 | 85,038 |
Tags: brute force, implementation
Correct Solution:
```
l, r, k = map(int, input().split())
powers = []
i = 0
current = k ** i
while current <= r:
if current >= l:
powers.append(current)
i += 1
current = k ** i
if powers:
print(' '.join(map(str, powers)))
else:
print(-1)
``` | output | 1 | 42,519 | 14 | 85,039 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)
Given integers l, r and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!
Input
The first line of the input contains three space-separated integers l, r and k (1 β€ l β€ r β€ 1018, 2 β€ k β€ 109).
Output
Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).
Examples
Input
1 10 2
Output
1 2 4 8
Input
2 4 5
Output
-1
Note
Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed. | instruction | 0 | 42,520 | 14 | 85,040 |
Tags: brute force, implementation
Correct Solution:
```
a,b,c = [int(i) for i in input().split()]
t = 1
while a > t:
t = t*c
if t > b:
print(-1)
while t <= b:
print(t,end = ' ')
t = t*c
``` | output | 1 | 42,520 | 14 | 85,041 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)
Given integers l, r and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!
Input
The first line of the input contains three space-separated integers l, r and k (1 β€ l β€ r β€ 1018, 2 β€ k β€ 109).
Output
Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).
Examples
Input
1 10 2
Output
1 2 4 8
Input
2 4 5
Output
-1
Note
Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed. | instruction | 0 | 42,521 | 14 | 85,042 |
Tags: brute force, implementation
Correct Solution:
```
line = input("")
int_list = [int(i) for i in line.split()]
l = int_list[0]
r = int_list[1]
k = int_list[2]
one = False
for b in range(0, 100000000):
x = k ** b
if x >= l and x <= r:
one = True
print("%d " % x, end="")
elif x > r:
break
if not one:
print("-1")
``` | output | 1 | 42,521 | 14 | 85,043 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)
Given integers l, r and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!
Input
The first line of the input contains three space-separated integers l, r and k (1 β€ l β€ r β€ 1018, 2 β€ k β€ 109).
Output
Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).
Examples
Input
1 10 2
Output
1 2 4 8
Input
2 4 5
Output
-1
Note
Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed. | instruction | 0 | 42,522 | 14 | 85,044 |
Tags: brute force, implementation
Correct Solution:
```
(l,r,k) = map(int,input().split())
x=1
ans = ''
while x<=r:
if x>=l:
ans +=str(x)+' '
x *= k
if ans == '':
ans = '-1'
print(ans)
``` | output | 1 | 42,522 | 14 | 85,045 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)
Given integers l, r and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!
Input
The first line of the input contains three space-separated integers l, r and k (1 β€ l β€ r β€ 1018, 2 β€ k β€ 109).
Output
Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).
Examples
Input
1 10 2
Output
1 2 4 8
Input
2 4 5
Output
-1
Note
Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed. | instruction | 0 | 42,523 | 14 | 85,046 |
Tags: brute force, implementation
Correct Solution:
```
a,b,c=map(int,input().split())
power=1;
ans=[]
while power<=b:
if(power>=a):
ans.append(power)
power*=c
if len(ans)==0:
print(-1)
else:
print(*ans)
``` | output | 1 | 42,523 | 14 | 85,047 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)
Given integers l, r and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!
Input
The first line of the input contains three space-separated integers l, r and k (1 β€ l β€ r β€ 1018, 2 β€ k β€ 109).
Output
Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).
Examples
Input
1 10 2
Output
1 2 4 8
Input
2 4 5
Output
-1
Note
Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed. | instruction | 0 | 42,524 | 14 | 85,048 |
Tags: brute force, implementation
Correct Solution:
```
from math import log
l, r, k = map(int, input().split())
lower = int(log(l, k))
while (k ** lower < l):
lower += 1
if (k ** lower > r):
print(-1)
exit()
print(k ** lower, end="")
lower += 1
while (k ** lower <= r):
print(" " + str(k ** lower), end="")
lower += 1
print()
``` | output | 1 | 42,524 | 14 | 85,049 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)
Given integers l, r and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!
Input
The first line of the input contains three space-separated integers l, r and k (1 β€ l β€ r β€ 1018, 2 β€ k β€ 109).
Output
Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).
Examples
Input
1 10 2
Output
1 2 4 8
Input
2 4 5
Output
-1
Note
Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed. | instruction | 0 | 42,525 | 14 | 85,050 |
Tags: brute force, implementation
Correct Solution:
```
[l,r,k]=[int(x) for x in input().split()]
i=1
b=1
while True:
if i>r:
break
if i>=l:
b=0
print(i)
i*=k
if b:
print(-1)
``` | output | 1 | 42,525 | 14 | 85,051 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)
Given integers l, r and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!
Input
The first line of the input contains three space-separated integers l, r and k (1 β€ l β€ r β€ 1018, 2 β€ k β€ 109).
Output
Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).
Examples
Input
1 10 2
Output
1 2 4 8
Input
2 4 5
Output
-1
Note
Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed. | instruction | 0 | 42,526 | 14 | 85,052 |
Tags: brute force, implementation
Correct Solution:
```
l, r, k = [int(i) for i in input().split(' ')]
s = ''
for i in range(10000):
if k**i < l:
continue
if k**i > r:
break
s += str(k**i) + ' '
if not s:
s = r'-1 '
print(s[:-1])
``` | output | 1 | 42,526 | 14 | 85,053 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)
Given integers l, r and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!
Input
The first line of the input contains three space-separated integers l, r and k (1 β€ l β€ r β€ 1018, 2 β€ k β€ 109).
Output
Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).
Examples
Input
1 10 2
Output
1 2 4 8
Input
2 4 5
Output
-1
Note
Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed.
Submitted Solution:
```
[l, r, k] = [int(n) for n in input().split(' ')]
ans = []
kn = 1
while kn <= r:
if l <= kn and kn <= r:
ans.append(kn)
kn = kn * k
if len(ans) == 0:
print("-1");
else:
print(" ".join([str(n) for n in ans]));
``` | instruction | 0 | 42,528 | 14 | 85,056 |
Yes | output | 1 | 42,528 | 14 | 85,057 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)
Given integers l, r and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!
Input
The first line of the input contains three space-separated integers l, r and k (1 β€ l β€ r β€ 1018, 2 β€ k β€ 109).
Output
Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).
Examples
Input
1 10 2
Output
1 2 4 8
Input
2 4 5
Output
-1
Note
Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed.
Submitted Solution:
```
l, r, k = [int(x) for x in input().split(' ')]
ans = []
s = ''
i = 0
while l > k**i:
i += 1
while k**i <= r:
ans.append(k**i)
i += 1
for a in ans:
s += str(a)
s += ' '
if len(ans) == 0:
s = '-1'
print(s)
``` | instruction | 0 | 42,533 | 14 | 85,066 |
No | output | 1 | 42,533 | 14 | 85,067 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.