message stringlengths 2 67k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 463 109k | cluster float64 19 19 | __index_level_0__ int64 926 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b.
Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>.
Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution.
Input
The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100).
Output
On the first line print a single integer — the minimal possible m.
On each of the next n lines print four space separated integers representing the i-th set.
Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them.
Examples
Input
1 1
Output
5
1 2 3 5
Input
2 2
Output
22
2 4 6 22
14 18 10 16
Note
For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
Submitted Solution:
```
n,k =[int(i) for i in input().split(' ')]
print(k*(6*n-1))
for i in range(n):
print(k*(6*i+1), k*(6*i+2), k*(6*i+3), k*(6*i+5))
``` | instruction | 0 | 61,061 | 19 | 122,122 |
Yes | output | 1 | 61,061 | 19 | 122,123 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b.
Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>.
Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution.
Input
The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100).
Output
On the first line print a single integer — the minimal possible m.
On each of the next n lines print four space separated integers representing the i-th set.
Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them.
Examples
Input
1 1
Output
5
1 2 3 5
Input
2 2
Output
22
2 4 6 22
14 18 10 16
Note
For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
Submitted Solution:
```
n, k = map(int, input().split())
print(k * (6 * (n - 1) + 5))
for i in range(0, n): print(k * (6 * i + 1), k * (6 * i + 2), k * (6 * i + 3), k * (6 * i + 5))
``` | instruction | 0 | 61,062 | 19 | 122,124 |
Yes | output | 1 | 61,062 | 19 | 122,125 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b.
Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>.
Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution.
Input
The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100).
Output
On the first line print a single integer — the minimal possible m.
On each of the next n lines print four space separated integers representing the i-th set.
Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them.
Examples
Input
1 1
Output
5
1 2 3 5
Input
2 2
Output
22
2 4 6 22
14 18 10 16
Note
For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
Submitted Solution:
```
n, k = map(int, input().split())
print(k * 2 * (3 * n) - 1)
now = 1
for i in range(n):
print(k * 2 * (i + 1), end = ' ')
for j in range(3):
print(k * now, end = ' ')
now += 2
print()
``` | instruction | 0 | 61,064 | 19 | 122,128 |
No | output | 1 | 61,064 | 19 | 122,129 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.
For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:
* 2, 7, 4.
* 1, 7, 3;
* 5, 4, 2;
* 1, 3, 5;
* 3, 1, 2, 4;
* 5, 7.
Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?
Input
The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.
Output
Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them.
It is guaranteed that there is a solution.
Examples
Input
4
3 2 7 4
3 1 7 3
3 5 4 2
3 1 3 5
4 3 1 2 4
2 5 7
Output
1 7
2 2 4
2 1 3
1 5
Input
4
5 6 7 8 9 100
4 7 8 9 1
4 7 8 9 2
3 1 6 100
3 2 6 100
2 1 2
Output
3 7 8 9
2 6 100
1 1
1 2
Input
3
2 1 2
2 1 3
2 2 3
Output
1 1
1 2
1 3 | instruction | 0 | 61,184 | 19 | 122,368 |
Tags: constructive algorithms, hashing, implementation
Correct Solution:
```
n = int(input())
l = []
arr = []
n = (n * (n - 1)) // 2
for i in range(n):
temp = list(map(int, input().split()))
l.append(temp)
for i in temp[1: ]: arr.append(i)
if n == 1:
print(l[0][0] - 1, *l[0][1: l[0][0]])
print(1, l[0][l[0][0]])
exit()
arr = list(set(arr))
ans = []
for i in range(len(arr)):
search = arr[i]
temp = []
for j in range(n):
for k in l[j][1: ]:
if search == k: temp.append(j)
ans.append(temp)
finans = []
for i in range(len(ans)):
search = ans[i]
temp = []
for j in range(len(ans)):
if ans[j] == search: temp.append(arr[j])
chh = 0
for j in finans:
if j == temp:
chh = 1
break
if chh == 0: finans.append(temp)
for i in finans:
print(len(i), *i)
``` | output | 1 | 61,184 | 19 | 122,369 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.
For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:
* 2, 7, 4.
* 1, 7, 3;
* 5, 4, 2;
* 1, 3, 5;
* 3, 1, 2, 4;
* 5, 7.
Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?
Input
The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.
Output
Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them.
It is guaranteed that there is a solution.
Examples
Input
4
3 2 7 4
3 1 7 3
3 5 4 2
3 1 3 5
4 3 1 2 4
2 5 7
Output
1 7
2 2 4
2 1 3
1 5
Input
4
5 6 7 8 9 100
4 7 8 9 1
4 7 8 9 2
3 1 6 100
3 2 6 100
2 1 2
Output
3 7 8 9
2 6 100
1 1
1 2
Input
3
2 1 2
2 1 3
2 2 3
Output
1 1
1 2
1 3 | instruction | 0 | 61,185 | 19 | 122,370 |
Tags: constructive algorithms, hashing, implementation
Correct Solution:
```
read = lambda: tuple(map(int, input().split()))
n = read()[0]
c = n * (n - 1) // 2
if c == 1:
v = read()[1:]
print(1, v[0])
print(len(v) - 1, *v[1:])
else:
d = {}
d1 = {}
sets = {}
ss = []
def addset(a):
sets[min(a)] = a
for i in range(c):
cur = frozenset(read()[1:])
v = min(cur)
if v in d:
a = d[v] & cur
addset(a)
addset(d[v] ^ a)
addset(cur ^ a)
else:
d[v] = cur
for k in sets:
v = sets[k]
print(len(v), *v)
``` | output | 1 | 61,185 | 19 | 122,371 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.
For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:
* 2, 7, 4.
* 1, 7, 3;
* 5, 4, 2;
* 1, 3, 5;
* 3, 1, 2, 4;
* 5, 7.
Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?
Input
The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.
Output
Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them.
It is guaranteed that there is a solution.
Examples
Input
4
3 2 7 4
3 1 7 3
3 5 4 2
3 1 3 5
4 3 1 2 4
2 5 7
Output
1 7
2 2 4
2 1 3
1 5
Input
4
5 6 7 8 9 100
4 7 8 9 1
4 7 8 9 2
3 1 6 100
3 2 6 100
2 1 2
Output
3 7 8 9
2 6 100
1 1
1 2
Input
3
2 1 2
2 1 3
2 2 3
Output
1 1
1 2
1 3 | instruction | 0 | 61,186 | 19 | 122,372 |
Tags: constructive algorithms, hashing, implementation
Correct Solution:
```
read = lambda: tuple(map(int, input().split()))
n = read()[0]
c = n * (n - 1) // 2
if c == 1:
v = read()[1:]
print(1, v[0])
print(len(v) - 1, *v[1:])
else:
d = {}
d1 = {}
sets = {}
ss = []
def addset(a):
sets[min(a)] = a
for i in range(c):
cur = frozenset(read()[1:])
v = min(cur)
if v in d:
a = d[v] & cur
b = d[v] ^ a
c = cur ^ a
addset(a)
addset(b)
addset(c)
else:
d[v] = cur
for k in sets:
v = sets[k]
print(len(v), *v)
``` | output | 1 | 61,186 | 19 | 122,373 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.
For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:
* 2, 7, 4.
* 1, 7, 3;
* 5, 4, 2;
* 1, 3, 5;
* 3, 1, 2, 4;
* 5, 7.
Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?
Input
The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.
Output
Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them.
It is guaranteed that there is a solution.
Examples
Input
4
3 2 7 4
3 1 7 3
3 5 4 2
3 1 3 5
4 3 1 2 4
2 5 7
Output
1 7
2 2 4
2 1 3
1 5
Input
4
5 6 7 8 9 100
4 7 8 9 1
4 7 8 9 2
3 1 6 100
3 2 6 100
2 1 2
Output
3 7 8 9
2 6 100
1 1
1 2
Input
3
2 1 2
2 1 3
2 2 3
Output
1 1
1 2
1 3 | instruction | 0 | 61,187 | 19 | 122,374 |
Tags: constructive algorithms, hashing, implementation
Correct Solution:
```
n=int(input())
if n!=2:
st=[]
from collections import *
cnt=defaultdict(list)
for _ in range((n*(n-1))//2):
x=str(_)
l=set(int(j) for j in input().split()[1:])
for i in l:
cnt[i].append(x)
for i,j in cnt.items():
cnt[i]='#'.join(j)
finset=defaultdict(list)
for i,j in cnt.items():
finset[j].append(i)
for i in finset.values():
print(len(i),*sorted(i))
else:
l=[int(j) for j in input().split()[1:]]
sz=len(l)
l1=l[:sz//2]
l2=l[sz//2:]
print(len(l1),*l1)
print(len(l1),*l2)
``` | output | 1 | 61,187 | 19 | 122,375 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.
For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:
* 2, 7, 4.
* 1, 7, 3;
* 5, 4, 2;
* 1, 3, 5;
* 3, 1, 2, 4;
* 5, 7.
Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?
Input
The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.
Output
Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them.
It is guaranteed that there is a solution.
Examples
Input
4
3 2 7 4
3 1 7 3
3 5 4 2
3 1 3 5
4 3 1 2 4
2 5 7
Output
1 7
2 2 4
2 1 3
1 5
Input
4
5 6 7 8 9 100
4 7 8 9 1
4 7 8 9 2
3 1 6 100
3 2 6 100
2 1 2
Output
3 7 8 9
2 6 100
1 1
1 2
Input
3
2 1 2
2 1 3
2 2 3
Output
1 1
1 2
1 3 | instruction | 0 | 61,188 | 19 | 122,376 |
Tags: constructive algorithms, hashing, implementation
Correct Solution:
```
c, v = [[0] * 201 for i in range(201)], []
n = int(input())
for i in range(n * (n - 1) // 2):
a = list(map(int, input().split()))[1:]
for x in a:
for y in a:
c[x][y] += 1
for i, ci in enumerate(c):
if ci[i]:
a = [j for j, cij in enumerate(ci) if cij == n - 1]
v.append(a)
for x in a:
c[x][x] = 0
if len(v) == 1:
v.append([v[0].pop()])
for vi in v:
print(len(vi), *vi)
``` | output | 1 | 61,188 | 19 | 122,377 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.
For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:
* 2, 7, 4.
* 1, 7, 3;
* 5, 4, 2;
* 1, 3, 5;
* 3, 1, 2, 4;
* 5, 7.
Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?
Input
The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.
Output
Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them.
It is guaranteed that there is a solution.
Examples
Input
4
3 2 7 4
3 1 7 3
3 5 4 2
3 1 3 5
4 3 1 2 4
2 5 7
Output
1 7
2 2 4
2 1 3
1 5
Input
4
5 6 7 8 9 100
4 7 8 9 1
4 7 8 9 2
3 1 6 100
3 2 6 100
2 1 2
Output
3 7 8 9
2 6 100
1 1
1 2
Input
3
2 1 2
2 1 3
2 2 3
Output
1 1
1 2
1 3 | instruction | 0 | 61,189 | 19 | 122,378 |
Tags: constructive algorithms, hashing, implementation
Correct Solution:
```
n = int(input())
common,mas = set(),[]
for i in range(n*(n-1)//2):
lst = list(map(int,input().split()))
lst.pop(0)
for i,x in enumerate(lst):
common.add(x)
mas.append(set(lst))
if n==2:
item=list(mas[0])
print(1,item[0])
print(len(item)-1,*item[1:])
from sys import exit;exit()
d = {}
for x in common:d[x]=False
for x in common:
if d[x]==False:
res = set(common)
for i,y in enumerate(mas):
if x in y:
res=res&y
print(len(res),*res)
for y in res:d[y]=True
``` | output | 1 | 61,189 | 19 | 122,379 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.
For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:
* 2, 7, 4.
* 1, 7, 3;
* 5, 4, 2;
* 1, 3, 5;
* 3, 1, 2, 4;
* 5, 7.
Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?
Input
The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.
Output
Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them.
It is guaranteed that there is a solution.
Examples
Input
4
3 2 7 4
3 1 7 3
3 5 4 2
3 1 3 5
4 3 1 2 4
2 5 7
Output
1 7
2 2 4
2 1 3
1 5
Input
4
5 6 7 8 9 100
4 7 8 9 1
4 7 8 9 2
3 1 6 100
3 2 6 100
2 1 2
Output
3 7 8 9
2 6 100
1 1
1 2
Input
3
2 1 2
2 1 3
2 2 3
Output
1 1
1 2
1 3 | instruction | 0 | 61,190 | 19 | 122,380 |
Tags: constructive algorithms, hashing, implementation
Correct Solution:
```
from collections import defaultdict
n = int(input())
if n == 2:
t = input().split()
print(1, t[1])
print(int(t[0]) - 1, ' '.join(t[2: ]))
else:
m = (n * (n - 1)) // 2
t = [0] * m
p = defaultdict(list)
for i in range(m):
t[i] = list(map(int, input().split()))[1: ]
for j in t[i]:
if len(p[j]) < 2: p[j].append(i)
t[i] = set(t[i])
p = set(tuple(q) for q in p.values())
t = [set(t[i]) & set(t[j]) for i, j in p]
t = [str(len(q)) + ' ' + ' '.join(map(str, q)) for q in t]
print('\n'.join(t))
``` | output | 1 | 61,190 | 19 | 122,381 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.
For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:
* 2, 7, 4.
* 1, 7, 3;
* 5, 4, 2;
* 1, 3, 5;
* 3, 1, 2, 4;
* 5, 7.
Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?
Input
The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.
Output
Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them.
It is guaranteed that there is a solution.
Examples
Input
4
3 2 7 4
3 1 7 3
3 5 4 2
3 1 3 5
4 3 1 2 4
2 5 7
Output
1 7
2 2 4
2 1 3
1 5
Input
4
5 6 7 8 9 100
4 7 8 9 1
4 7 8 9 2
3 1 6 100
3 2 6 100
2 1 2
Output
3 7 8 9
2 6 100
1 1
1 2
Input
3
2 1 2
2 1 3
2 2 3
Output
1 1
1 2
1 3 | instruction | 0 | 61,191 | 19 | 122,382 |
Tags: constructive algorithms, hashing, implementation
Correct Solution:
```
n=int(input())
L=[]
for i in range((n*(n-1))//2):
A=input().split()
L.append(A[1:])
x=L[0][0]
Set=list(L[0])
Set.remove(x)
for i in range(1,(n*(n-1))//2):
if(x in L[i]):
for item in L[i]:
if(item in Set):
Set.remove(item)
break
x=Set[0]
Sets=[]
Sets.append(list(Set))
for i in range((n*(n-1))//2):
if(x in L[i]):
Sets.append(list(L[i]))
for item in Set:
Sets[-1].remove(item)
for item in Sets:
print(len(item),end="")
for z in item:
print(" "+str(z),end="")
print()
``` | output | 1 | 61,191 | 19 | 122,383 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.
For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:
* 2, 7, 4.
* 1, 7, 3;
* 5, 4, 2;
* 1, 3, 5;
* 3, 1, 2, 4;
* 5, 7.
Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?
Input
The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.
Output
Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them.
It is guaranteed that there is a solution.
Examples
Input
4
3 2 7 4
3 1 7 3
3 5 4 2
3 1 3 5
4 3 1 2 4
2 5 7
Output
1 7
2 2 4
2 1 3
1 5
Input
4
5 6 7 8 9 100
4 7 8 9 1
4 7 8 9 2
3 1 6 100
3 2 6 100
2 1 2
Output
3 7 8 9
2 6 100
1 1
1 2
Input
3
2 1 2
2 1 3
2 2 3
Output
1 1
1 2
1 3
Submitted Solution:
```
n = int(input())
m = (n * (n - 1)) // 2
s = [set(t.split()[1:]) for t in [input() for i in range(m)]]
q = set(max([s[0], [t - s[0] for t in s[1:] if t & s[0]]][len(s) > 1]))
for t in [q] + [t - q for t in s if t & q]:
print(len(t), ' '.join(t))
``` | instruction | 0 | 61,192 | 19 | 122,384 |
Yes | output | 1 | 61,192 | 19 | 122,385 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.
For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:
* 2, 7, 4.
* 1, 7, 3;
* 5, 4, 2;
* 1, 3, 5;
* 3, 1, 2, 4;
* 5, 7.
Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?
Input
The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.
Output
Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them.
It is guaranteed that there is a solution.
Examples
Input
4
3 2 7 4
3 1 7 3
3 5 4 2
3 1 3 5
4 3 1 2 4
2 5 7
Output
1 7
2 2 4
2 1 3
1 5
Input
4
5 6 7 8 9 100
4 7 8 9 1
4 7 8 9 2
3 1 6 100
3 2 6 100
2 1 2
Output
3 7 8 9
2 6 100
1 1
1 2
Input
3
2 1 2
2 1 3
2 2 3
Output
1 1
1 2
1 3
Submitted Solution:
```
c, v = [[0] * 201 for i in range(201)], []
n = int(input())
for i in range(n * (n - 1) // 2):
a = list(map(int, input().split()))[1:]
for x in a:
for y in a:
c[x][y] += 1
for i, ci in enumerate(c):
if ci[i]:
a = [j for j, cij in enumerate(ci) if cij == n - 1]
v.append(a)
for x in a:
c[x][x] = 0
if len(v) == 1:
v.append([v[0].pop()])
for vi in v:
print(len(vi), *vi)
# Made By Mostafa_Khaled
``` | instruction | 0 | 61,193 | 19 | 122,386 |
Yes | output | 1 | 61,193 | 19 | 122,387 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.
For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:
* 2, 7, 4.
* 1, 7, 3;
* 5, 4, 2;
* 1, 3, 5;
* 3, 1, 2, 4;
* 5, 7.
Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?
Input
The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.
Output
Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them.
It is guaranteed that there is a solution.
Examples
Input
4
3 2 7 4
3 1 7 3
3 5 4 2
3 1 3 5
4 3 1 2 4
2 5 7
Output
1 7
2 2 4
2 1 3
1 5
Input
4
5 6 7 8 9 100
4 7 8 9 1
4 7 8 9 2
3 1 6 100
3 2 6 100
2 1 2
Output
3 7 8 9
2 6 100
1 1
1 2
Input
3
2 1 2
2 1 3
2 2 3
Output
1 1
1 2
1 3
Submitted Solution:
```
n = int(input())
t = int(n * (n - 1) / 2)
s = [set() for i in range(t)]
for i in range(t):
x = list(map(int, input().split()))[1:]
s[i] = set(x)
s.sort()
if t == 1:
print(1, end=' ')
l = list(s[0])
print(l[0], sep=' ')
l = l[1:]
print(len(l), end=' ')
print(*l, sep=' ')
exit()
ans = list()
l = list(s[0] & s[1])
l.sort()
ans.append(l);
sp = set(l);
for i in range(t):
l = list(s[i] - sp)
if(len(l) == len(s[i])):
continue
l.sort()
if l and l not in ans:
ans.append(l)
for i in ans:
print(len(i), end=' ')
print(*i, sep=' ')
``` | instruction | 0 | 61,194 | 19 | 122,388 |
Yes | output | 1 | 61,194 | 19 | 122,389 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.
For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:
* 2, 7, 4.
* 1, 7, 3;
* 5, 4, 2;
* 1, 3, 5;
* 3, 1, 2, 4;
* 5, 7.
Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?
Input
The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.
Output
Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them.
It is guaranteed that there is a solution.
Examples
Input
4
3 2 7 4
3 1 7 3
3 5 4 2
3 1 3 5
4 3 1 2 4
2 5 7
Output
1 7
2 2 4
2 1 3
1 5
Input
4
5 6 7 8 9 100
4 7 8 9 1
4 7 8 9 2
3 1 6 100
3 2 6 100
2 1 2
Output
3 7 8 9
2 6 100
1 1
1 2
Input
3
2 1 2
2 1 3
2 2 3
Output
1 1
1 2
1 3
Submitted Solution:
```
c, v = [[0] * 201 for i in range(201)], []
n = int(input())
for i in range(n * (n - 1) // 2):
a = list(map(int, input().split()))[1:]
for x in a:
for y in a:
c[x][y] += 1
for i, ci in enumerate(c):
if ci[i]:
a = [j for j, cij in enumerate(ci) if cij == n - 1]
v.append(a)
for x in a:
c[x][x] = 0
for vi in v:
print(len(vi), *vi)
``` | instruction | 0 | 61,195 | 19 | 122,390 |
No | output | 1 | 61,195 | 19 | 122,391 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.
For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:
* 2, 7, 4.
* 1, 7, 3;
* 5, 4, 2;
* 1, 3, 5;
* 3, 1, 2, 4;
* 5, 7.
Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?
Input
The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.
Output
Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them.
It is guaranteed that there is a solution.
Examples
Input
4
3 2 7 4
3 1 7 3
3 5 4 2
3 1 3 5
4 3 1 2 4
2 5 7
Output
1 7
2 2 4
2 1 3
1 5
Input
4
5 6 7 8 9 100
4 7 8 9 1
4 7 8 9 2
3 1 6 100
3 2 6 100
2 1 2
Output
3 7 8 9
2 6 100
1 1
1 2
Input
3
2 1 2
2 1 3
2 2 3
Output
1 1
1 2
1 3
Submitted Solution:
```
import math
a=int(input())
b=0
c=1
i=0
while i==0:
if a<= (b+c*5):
d=math.ceil((a-b)/c)
if d==1:
print('Sheldon')
elif d==2:
print('Leonard')
elif d==3:
print('Penny')
elif d==4:
print('Rajesh')
elif d==5:
print('Howard')
break
else:
b= b+(c*5)
c=c*2
``` | instruction | 0 | 61,196 | 19 | 122,392 |
No | output | 1 | 61,196 | 19 | 122,393 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.
For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:
* 2, 7, 4.
* 1, 7, 3;
* 5, 4, 2;
* 1, 3, 5;
* 3, 1, 2, 4;
* 5, 7.
Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?
Input
The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.
Output
Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them.
It is guaranteed that there is a solution.
Examples
Input
4
3 2 7 4
3 1 7 3
3 5 4 2
3 1 3 5
4 3 1 2 4
2 5 7
Output
1 7
2 2 4
2 1 3
1 5
Input
4
5 6 7 8 9 100
4 7 8 9 1
4 7 8 9 2
3 1 6 100
3 2 6 100
2 1 2
Output
3 7 8 9
2 6 100
1 1
1 2
Input
3
2 1 2
2 1 3
2 2 3
Output
1 1
1 2
1 3
Submitted Solution:
```
n = int(input())
base = []
for _ in range(n*(n-1)//2):
m = list(map(int,input().split()))[1:]
base.append(set(m))
al = set()
for i in range(len(base)):
for j in range(i+1,len(base)):
if len(al) == n:
break
t = base[i].intersection(base[j])
al.add(frozenset(t))
al.add(frozenset(base[i]-t))
al.add(frozenset(base[j]-t))
if len(al) == n:
break
for i in al:
print(len(i), *i)
``` | instruction | 0 | 61,197 | 19 | 122,394 |
No | output | 1 | 61,197 | 19 | 122,395 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.
For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:
* 2, 7, 4.
* 1, 7, 3;
* 5, 4, 2;
* 1, 3, 5;
* 3, 1, 2, 4;
* 5, 7.
Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?
Input
The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.
Output
Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them.
It is guaranteed that there is a solution.
Examples
Input
4
3 2 7 4
3 1 7 3
3 5 4 2
3 1 3 5
4 3 1 2 4
2 5 7
Output
1 7
2 2 4
2 1 3
1 5
Input
4
5 6 7 8 9 100
4 7 8 9 1
4 7 8 9 2
3 1 6 100
3 2 6 100
2 1 2
Output
3 7 8 9
2 6 100
1 1
1 2
Input
3
2 1 2
2 1 3
2 2 3
Output
1 1
1 2
1 3
Submitted Solution:
```
from collections import defaultdict
n = int(input())
if n == 2: print(input())
else:
m = (n * (n - 1)) // 2
t = [0] * m
p = defaultdict(list)
for i in range(m):
t[i] = list(map(int, input().split()))[1: ]
for j in t[i]:
if len(p[j]) < 2: p[j].append(i)
t[i] = set(t[i])
p = set(tuple(q) for q in p.values())
t = [set(t[i]) & set(t[j]) for i, j in p]
t = [str(len(q)) + ' ' + ' '.join(map(str, q)) for q in t]
print('\n'.join(t))
``` | instruction | 0 | 61,198 | 19 | 122,396 |
No | output | 1 | 61,198 | 19 | 122,397 |
Provide a correct Python 3 solution for this coding contest problem.
Here is a very simple variation of the game backgammon, named “Minimal Backgammon”. The game is played by only one player, using only one of the dice and only one checker (the token used by the player).
The game board is a line of (N + 1) squares labeled as 0 (the start) to N (the goal). At the beginning, the checker is placed on the start (square 0). The aim of the game is to bring the checker to the goal (square N). The checker proceeds as many squares as the roll of the dice. The dice generates six integers from 1 to 6 with equal probability.
The checker should not go beyond the goal. If the roll of the dice would bring the checker beyond the goal, the checker retreats from the goal as many squares as the excess. For example, if the checker is placed at the square (N - 3), the roll "5" brings the checker to the square (N - 2), because the excess beyond the goal is 2. At the next turn, the checker proceeds toward the goal as usual.
Each square, except the start and the goal, may be given one of the following two special instructions.
* Lose one turn (labeled "L" in Figure 2) If the checker stops here, you cannot move the checker in the next turn.
* Go back to the start (labeled "B" in Figure 2)
If the checker stops here, the checker is brought back to the start.
<image>
Figure 2: An example game
Given a game board configuration (the size N, and the placement of the special instructions), you are requested to compute the probability with which the game succeeds within a given number of turns.
Input
The input consists of multiple datasets, each containing integers in the following format.
N T L B
Lose1
...
LoseL
Back1
...
BackB
N is the index of the goal, which satisfies 5 ≤ N ≤ 100. T is the number of turns. You are requested to compute the probability of success within T turns. T satisfies 1 ≤ T ≤ 100. L is the number of squares marked “Lose one turn”, which satisfies 0 ≤ L ≤ N - 1. B is the number of squares marked “Go back to the start”, which satisfies 0 ≤ B ≤ N - 1. They are separated by a space.
Losei's are the indexes of the squares marked “Lose one turn”, which satisfy 1 ≤ Losei ≤ N - 1. All Losei's are distinct, and sorted in ascending order. Backi's are the indexes of the squares marked “Go back to the start”, which satisfy 1 ≤ Backi ≤ N - 1. All Backi's are distinct, and sorted in ascending order. No numbers occur both in Losei's and Backi's.
The end of the input is indicated by a line containing four zeros separated by a space.
Output
For each dataset, you should answer the probability with which the game succeeds within the given number of turns. The output should not contain an error greater than 0.00001.
Example
Input
6 1 0 0
7 1 0 0
7 2 0 0
6 6 1 1
2
5
7 10 0 6
1
2
3
4
5
6
0 0 0 0
Output
0.166667
0.000000
0.166667
0.619642
0.000000 | instruction | 0 | 61,419 | 19 | 122,838 |
"Correct Solution:
```
def solve():
from sys import stdin
f_i = stdin
while True:
N, T, L, B = map(int, f_i.readline().split())
if N == 0:
break
skip = {}
sq_attr = [None] * N
for i in range(L):
sq = int(f_i.readline())
sq_attr[sq] = 'Lose'
skip[sq] = 0
for i in range(B):
sq_attr[int(f_i.readline())] = 'Back'
dp1 = [0] * N
dp2 = [0] * N
dp1[0] = 1
ans = 0
for i in range(T):
for sq, pr in skip.items():
tmp = dp1[sq]
dp1[sq] = pr
skip[sq] = tmp
for sq, pr in enumerate(dp1):
if pr == 0:
continue
new_pr = pr / 6
for next_sq in range(sq + 1, sq + 7):
if next_sq > N:
next_sq = 2 * N - next_sq
elif next_sq == N:
ans += new_pr
continue
if sq_attr[next_sq] == 'Back':
next_sq = 0
dp2[next_sq] += new_pr
dp1 = dp2
dp2 = [0] * N
print('{:.6f}'.format(ans))
solve()
``` | output | 1 | 61,419 | 19 | 122,839 |
Provide a correct Python 3 solution for this coding contest problem.
Here is a very simple variation of the game backgammon, named “Minimal Backgammon”. The game is played by only one player, using only one of the dice and only one checker (the token used by the player).
The game board is a line of (N + 1) squares labeled as 0 (the start) to N (the goal). At the beginning, the checker is placed on the start (square 0). The aim of the game is to bring the checker to the goal (square N). The checker proceeds as many squares as the roll of the dice. The dice generates six integers from 1 to 6 with equal probability.
The checker should not go beyond the goal. If the roll of the dice would bring the checker beyond the goal, the checker retreats from the goal as many squares as the excess. For example, if the checker is placed at the square (N - 3), the roll "5" brings the checker to the square (N - 2), because the excess beyond the goal is 2. At the next turn, the checker proceeds toward the goal as usual.
Each square, except the start and the goal, may be given one of the following two special instructions.
* Lose one turn (labeled "L" in Figure 2) If the checker stops here, you cannot move the checker in the next turn.
* Go back to the start (labeled "B" in Figure 2)
If the checker stops here, the checker is brought back to the start.
<image>
Figure 2: An example game
Given a game board configuration (the size N, and the placement of the special instructions), you are requested to compute the probability with which the game succeeds within a given number of turns.
Input
The input consists of multiple datasets, each containing integers in the following format.
N T L B
Lose1
...
LoseL
Back1
...
BackB
N is the index of the goal, which satisfies 5 ≤ N ≤ 100. T is the number of turns. You are requested to compute the probability of success within T turns. T satisfies 1 ≤ T ≤ 100. L is the number of squares marked “Lose one turn”, which satisfies 0 ≤ L ≤ N - 1. B is the number of squares marked “Go back to the start”, which satisfies 0 ≤ B ≤ N - 1. They are separated by a space.
Losei's are the indexes of the squares marked “Lose one turn”, which satisfy 1 ≤ Losei ≤ N - 1. All Losei's are distinct, and sorted in ascending order. Backi's are the indexes of the squares marked “Go back to the start”, which satisfy 1 ≤ Backi ≤ N - 1. All Backi's are distinct, and sorted in ascending order. No numbers occur both in Losei's and Backi's.
The end of the input is indicated by a line containing four zeros separated by a space.
Output
For each dataset, you should answer the probability with which the game succeeds within the given number of turns. The output should not contain an error greater than 0.00001.
Example
Input
6 1 0 0
7 1 0 0
7 2 0 0
6 6 1 1
2
5
7 10 0 6
1
2
3
4
5
6
0 0 0 0
Output
0.166667
0.000000
0.166667
0.619642
0.000000 | instruction | 0 | 61,420 | 19 | 122,840 |
"Correct Solution:
```
N, T, L, B = map(int, input().split())
while (N != 0 and T != 0):
Llist = []
Blist = []
for i in range(L):
Llist.append(int(input()))
for i in range(B):
Blist.append(int(input()))
prob = [0for i in range(N+1)]
prob[0] = 1 ## t행
copy1 = [0for i in range(N+1)] ##(t-2)행
copy2 = prob[:] ## (t-1)행
cntp = 0
for t in range(1,T+1):
for i in range(N, -1, -1):
prob_i = 0
if (i != 0):
prob_i = 0
for k in range(i-6,i):
if (k in Blist):
prob_i += 0
elif (k in Llist):
prob_i += (1/6)*copy1[k]
elif (k >= 0):
prob_i += (1/6)*copy2[k]
if(N-5<= i <N):
if ((N-1) in Blist):
prob_i += 0
elif ((N-1) in Llist):
prob_i += (1/6)*copy1[N-1]
else:
prob_i += (1/6)*copy2[N-1]
if(N-4<= i <N):
if ((N-2) in Blist):
prob_i += 0
elif ((N-2) in Llist):
prob_i += (1/6)*copy1[N-2]
else:
prob_i += (1/6)*copy2[N-2]
if(N-3<= i <N):
if ((N-3) in Blist):
prob_i += 0
elif ((N-3) in Llist):
prob_i += (1/6)*copy1[N-3]
else:
prob_i += (1/6)*copy2[N-3]
if(N-2<= i <N):
if ((N-4) in Blist):
prob_i += 0
elif ((N-4) in Llist):
prob_i += (1/6)*copy1[N-4]
else:
prob_i += (1/6)*copy2[N-4]
if(N-1<= i <N):
if ((N-5) in Blist):
prob_i += 0
elif ((N-5) in Llist):
prob_i += (1/6)*copy1[N-5]
else:
prob_i += (1/6)*copy2[N-5]
if(i == 0):
for b in Blist:
prob_i += prob[b]
prob[i] = prob_i
copy1 = copy2[:]
copy2 = prob[:]
cntp += prob[-1]
print('{0:.6f}'.format(cntp))
N, T, L, B = map(int, input().split())
``` | output | 1 | 61,420 | 19 | 122,841 |
Provide a correct Python 3 solution for this coding contest problem.
Here is a very simple variation of the game backgammon, named “Minimal Backgammon”. The game is played by only one player, using only one of the dice and only one checker (the token used by the player).
The game board is a line of (N + 1) squares labeled as 0 (the start) to N (the goal). At the beginning, the checker is placed on the start (square 0). The aim of the game is to bring the checker to the goal (square N). The checker proceeds as many squares as the roll of the dice. The dice generates six integers from 1 to 6 with equal probability.
The checker should not go beyond the goal. If the roll of the dice would bring the checker beyond the goal, the checker retreats from the goal as many squares as the excess. For example, if the checker is placed at the square (N - 3), the roll "5" brings the checker to the square (N - 2), because the excess beyond the goal is 2. At the next turn, the checker proceeds toward the goal as usual.
Each square, except the start and the goal, may be given one of the following two special instructions.
* Lose one turn (labeled "L" in Figure 2) If the checker stops here, you cannot move the checker in the next turn.
* Go back to the start (labeled "B" in Figure 2)
If the checker stops here, the checker is brought back to the start.
<image>
Figure 2: An example game
Given a game board configuration (the size N, and the placement of the special instructions), you are requested to compute the probability with which the game succeeds within a given number of turns.
Input
The input consists of multiple datasets, each containing integers in the following format.
N T L B
Lose1
...
LoseL
Back1
...
BackB
N is the index of the goal, which satisfies 5 ≤ N ≤ 100. T is the number of turns. You are requested to compute the probability of success within T turns. T satisfies 1 ≤ T ≤ 100. L is the number of squares marked “Lose one turn”, which satisfies 0 ≤ L ≤ N - 1. B is the number of squares marked “Go back to the start”, which satisfies 0 ≤ B ≤ N - 1. They are separated by a space.
Losei's are the indexes of the squares marked “Lose one turn”, which satisfy 1 ≤ Losei ≤ N - 1. All Losei's are distinct, and sorted in ascending order. Backi's are the indexes of the squares marked “Go back to the start”, which satisfy 1 ≤ Backi ≤ N - 1. All Backi's are distinct, and sorted in ascending order. No numbers occur both in Losei's and Backi's.
The end of the input is indicated by a line containing four zeros separated by a space.
Output
For each dataset, you should answer the probability with which the game succeeds within the given number of turns. The output should not contain an error greater than 0.00001.
Example
Input
6 1 0 0
7 1 0 0
7 2 0 0
6 6 1 1
2
5
7 10 0 6
1
2
3
4
5
6
0 0 0 0
Output
0.166667
0.000000
0.166667
0.619642
0.000000 | instruction | 0 | 61,421 | 19 | 122,842 |
"Correct Solution:
```
def solve(N,T,L,B):
route = [-1] * (N + 1)
for _ in range(L):
x = int(input())
route[x] = 0
for _ in range(B):
y = int(input())
route[y] = 1
ans = 0
before = [0] * (N + 1)
before[0] = 1
beforebefore = [0] * (N + 1)
for _ in range(T):
now = [0] * (N + 1)
future = [0] *(N + 1)
for i in range(N):
for j in range(1,7):
X = i + j
if X >= N + 1:#超えた時
X = N - (X - N)
if route[X] == -1:
now[X] += before[i]/6
elif route[X] == 0:
future[X] += before[i]/6
else:
now[0] += before[i]/6
ans += now[-1]
before = [0] * (N + 1)
for i in range(N + 1):
before[i] = now[i] + beforebefore[i]
beforebefore = future
print("{:9f}".format(ans))
def main():
while True:
N,T,L,B = map(int,input().split())
if N == 0:
return
solve(N,T,L,B)
if __name__ == '__main__':
main()
``` | output | 1 | 61,421 | 19 | 122,843 |
Provide a correct Python 3 solution for this coding contest problem.
Here is a very simple variation of the game backgammon, named “Minimal Backgammon”. The game is played by only one player, using only one of the dice and only one checker (the token used by the player).
The game board is a line of (N + 1) squares labeled as 0 (the start) to N (the goal). At the beginning, the checker is placed on the start (square 0). The aim of the game is to bring the checker to the goal (square N). The checker proceeds as many squares as the roll of the dice. The dice generates six integers from 1 to 6 with equal probability.
The checker should not go beyond the goal. If the roll of the dice would bring the checker beyond the goal, the checker retreats from the goal as many squares as the excess. For example, if the checker is placed at the square (N - 3), the roll "5" brings the checker to the square (N - 2), because the excess beyond the goal is 2. At the next turn, the checker proceeds toward the goal as usual.
Each square, except the start and the goal, may be given one of the following two special instructions.
* Lose one turn (labeled "L" in Figure 2) If the checker stops here, you cannot move the checker in the next turn.
* Go back to the start (labeled "B" in Figure 2)
If the checker stops here, the checker is brought back to the start.
<image>
Figure 2: An example game
Given a game board configuration (the size N, and the placement of the special instructions), you are requested to compute the probability with which the game succeeds within a given number of turns.
Input
The input consists of multiple datasets, each containing integers in the following format.
N T L B
Lose1
...
LoseL
Back1
...
BackB
N is the index of the goal, which satisfies 5 ≤ N ≤ 100. T is the number of turns. You are requested to compute the probability of success within T turns. T satisfies 1 ≤ T ≤ 100. L is the number of squares marked “Lose one turn”, which satisfies 0 ≤ L ≤ N - 1. B is the number of squares marked “Go back to the start”, which satisfies 0 ≤ B ≤ N - 1. They are separated by a space.
Losei's are the indexes of the squares marked “Lose one turn”, which satisfy 1 ≤ Losei ≤ N - 1. All Losei's are distinct, and sorted in ascending order. Backi's are the indexes of the squares marked “Go back to the start”, which satisfy 1 ≤ Backi ≤ N - 1. All Backi's are distinct, and sorted in ascending order. No numbers occur both in Losei's and Backi's.
The end of the input is indicated by a line containing four zeros separated by a space.
Output
For each dataset, you should answer the probability with which the game succeeds within the given number of turns. The output should not contain an error greater than 0.00001.
Example
Input
6 1 0 0
7 1 0 0
7 2 0 0
6 6 1 1
2
5
7 10 0 6
1
2
3
4
5
6
0 0 0 0
Output
0.166667
0.000000
0.166667
0.619642
0.000000 | instruction | 0 | 61,422 | 19 | 122,844 |
"Correct Solution:
```
while True:
N, T, L, B = map(int, input().split(' '))
if N == 0:
break
l = set([int(input()) for _ in range(L)])
b = set([int(input()) for _ in range(B)])
memo = [[0.0] * (N+1) for _ in range(T+2)]
memo[0][0] = 1
for t in range(T):
for n in range(N):
for i in [1,2,3,4,5,6]:
next_pos = n + i
if next_pos > N:
next_pos = 2*N - next_pos
if next_pos in l:
memo[t+2][next_pos] += memo[t][n]/6
elif next_pos in b:
memo[t+1][0] += memo[t][n]/6
else:
memo[t+1][next_pos] += memo[t][n]/6
print('{:.6f}'.format(sum([memo[t][N] for t in range(T+1)])))
``` | output | 1 | 61,422 | 19 | 122,845 |
Provide a correct Python 3 solution for this coding contest problem.
Here is a very simple variation of the game backgammon, named “Minimal Backgammon”. The game is played by only one player, using only one of the dice and only one checker (the token used by the player).
The game board is a line of (N + 1) squares labeled as 0 (the start) to N (the goal). At the beginning, the checker is placed on the start (square 0). The aim of the game is to bring the checker to the goal (square N). The checker proceeds as many squares as the roll of the dice. The dice generates six integers from 1 to 6 with equal probability.
The checker should not go beyond the goal. If the roll of the dice would bring the checker beyond the goal, the checker retreats from the goal as many squares as the excess. For example, if the checker is placed at the square (N - 3), the roll "5" brings the checker to the square (N - 2), because the excess beyond the goal is 2. At the next turn, the checker proceeds toward the goal as usual.
Each square, except the start and the goal, may be given one of the following two special instructions.
* Lose one turn (labeled "L" in Figure 2) If the checker stops here, you cannot move the checker in the next turn.
* Go back to the start (labeled "B" in Figure 2)
If the checker stops here, the checker is brought back to the start.
<image>
Figure 2: An example game
Given a game board configuration (the size N, and the placement of the special instructions), you are requested to compute the probability with which the game succeeds within a given number of turns.
Input
The input consists of multiple datasets, each containing integers in the following format.
N T L B
Lose1
...
LoseL
Back1
...
BackB
N is the index of the goal, which satisfies 5 ≤ N ≤ 100. T is the number of turns. You are requested to compute the probability of success within T turns. T satisfies 1 ≤ T ≤ 100. L is the number of squares marked “Lose one turn”, which satisfies 0 ≤ L ≤ N - 1. B is the number of squares marked “Go back to the start”, which satisfies 0 ≤ B ≤ N - 1. They are separated by a space.
Losei's are the indexes of the squares marked “Lose one turn”, which satisfy 1 ≤ Losei ≤ N - 1. All Losei's are distinct, and sorted in ascending order. Backi's are the indexes of the squares marked “Go back to the start”, which satisfy 1 ≤ Backi ≤ N - 1. All Backi's are distinct, and sorted in ascending order. No numbers occur both in Losei's and Backi's.
The end of the input is indicated by a line containing four zeros separated by a space.
Output
For each dataset, you should answer the probability with which the game succeeds within the given number of turns. The output should not contain an error greater than 0.00001.
Example
Input
6 1 0 0
7 1 0 0
7 2 0 0
6 6 1 1
2
5
7 10 0 6
1
2
3
4
5
6
0 0 0 0
Output
0.166667
0.000000
0.166667
0.619642
0.000000 | instruction | 0 | 61,423 | 19 | 122,846 |
"Correct Solution:
```
def main():
while True:
N, T, L, B = map(int, input().split())
if N == T == L == B == 0:
break
Lose = []
for i in range(L):
Lose.append(int(input()))
isLose = {i:False for i in range(N)}
for i in Lose:
isLose[i] = True
Back = []
for i in range(B):
Back.append(int(input()))
#print(N, T, L, B, end=':\t')
Board = [0.0 for x in range(N+1)]
Board[0] = 1.0
Lose_Board = [0.0 for x in range(N+1)]
for turn_i in range(T):
new_Board = [0.0 for x in range(N+1)]
for board_i in range(N):
if isLose[board_i]:
Board[board_i], Lose_Board[board_i] = Lose_Board[board_i], Board[board_i]
if Board[board_i] == 0.0:
continue
for i in range(1, 7):
new_board_i = board_i + i
if new_board_i > N:
new_board_i = N - abs(new_board_i - N)
new_Board[new_board_i] += Board[board_i] * (1/6)
for i in Back:
new_Board[0] += new_Board[i]
new_Board[i] = 0.0
new_Board[-1] += Board[-1]
Board = new_Board
print(f'{Board[N]:.6f}')
main()
``` | output | 1 | 61,423 | 19 | 122,847 |
Provide a correct Python 3 solution for this coding contest problem.
Here is a very simple variation of the game backgammon, named “Minimal Backgammon”. The game is played by only one player, using only one of the dice and only one checker (the token used by the player).
The game board is a line of (N + 1) squares labeled as 0 (the start) to N (the goal). At the beginning, the checker is placed on the start (square 0). The aim of the game is to bring the checker to the goal (square N). The checker proceeds as many squares as the roll of the dice. The dice generates six integers from 1 to 6 with equal probability.
The checker should not go beyond the goal. If the roll of the dice would bring the checker beyond the goal, the checker retreats from the goal as many squares as the excess. For example, if the checker is placed at the square (N - 3), the roll "5" brings the checker to the square (N - 2), because the excess beyond the goal is 2. At the next turn, the checker proceeds toward the goal as usual.
Each square, except the start and the goal, may be given one of the following two special instructions.
* Lose one turn (labeled "L" in Figure 2) If the checker stops here, you cannot move the checker in the next turn.
* Go back to the start (labeled "B" in Figure 2)
If the checker stops here, the checker is brought back to the start.
<image>
Figure 2: An example game
Given a game board configuration (the size N, and the placement of the special instructions), you are requested to compute the probability with which the game succeeds within a given number of turns.
Input
The input consists of multiple datasets, each containing integers in the following format.
N T L B
Lose1
...
LoseL
Back1
...
BackB
N is the index of the goal, which satisfies 5 ≤ N ≤ 100. T is the number of turns. You are requested to compute the probability of success within T turns. T satisfies 1 ≤ T ≤ 100. L is the number of squares marked “Lose one turn”, which satisfies 0 ≤ L ≤ N - 1. B is the number of squares marked “Go back to the start”, which satisfies 0 ≤ B ≤ N - 1. They are separated by a space.
Losei's are the indexes of the squares marked “Lose one turn”, which satisfy 1 ≤ Losei ≤ N - 1. All Losei's are distinct, and sorted in ascending order. Backi's are the indexes of the squares marked “Go back to the start”, which satisfy 1 ≤ Backi ≤ N - 1. All Backi's are distinct, and sorted in ascending order. No numbers occur both in Losei's and Backi's.
The end of the input is indicated by a line containing four zeros separated by a space.
Output
For each dataset, you should answer the probability with which the game succeeds within the given number of turns. The output should not contain an error greater than 0.00001.
Example
Input
6 1 0 0
7 1 0 0
7 2 0 0
6 6 1 1
2
5
7 10 0 6
1
2
3
4
5
6
0 0 0 0
Output
0.166667
0.000000
0.166667
0.619642
0.000000 | instruction | 0 | 61,424 | 19 | 122,848 |
"Correct Solution:
```
# coding:utf-8
import sys
input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
while True:
N, T, L, B = inpl()
if N == 0: break
lose = [int(input()) for _ in range(L)]
back = [int(input()) for _ in range(B)]
mass = [0] * (N + 1)
for l in lose:
mass[l] = 1
for b in back:
mass[b] = 2
dp = [[0] * (N + 1) for _ in range(T + 3)]
dp[0][0] = 1.0
for i in range(T + 1):
for j in range(N):
if dp[i][j] == 0.0:
continue
for k in range(1, 7):
curr = j + k
if curr > N: curr = N - curr % N
if mass[curr] == 0: # 通常マス
dp[i + 1][curr] += dp[i][j] / 6.0
elif mass[curr] == 1: # Loseマス
dp[i + 2][curr] += dp[i][j] / 6.0
else: # Backマス
dp[i + 1][0] += dp[i][j] / 6.0
ans = 0
for i in range(T + 1):
ans += dp[i][N]
print('{:.6f}'.format(ans))
``` | output | 1 | 61,424 | 19 | 122,849 |
Provide a correct Python 3 solution for this coding contest problem.
Here is a very simple variation of the game backgammon, named “Minimal Backgammon”. The game is played by only one player, using only one of the dice and only one checker (the token used by the player).
The game board is a line of (N + 1) squares labeled as 0 (the start) to N (the goal). At the beginning, the checker is placed on the start (square 0). The aim of the game is to bring the checker to the goal (square N). The checker proceeds as many squares as the roll of the dice. The dice generates six integers from 1 to 6 with equal probability.
The checker should not go beyond the goal. If the roll of the dice would bring the checker beyond the goal, the checker retreats from the goal as many squares as the excess. For example, if the checker is placed at the square (N - 3), the roll "5" brings the checker to the square (N - 2), because the excess beyond the goal is 2. At the next turn, the checker proceeds toward the goal as usual.
Each square, except the start and the goal, may be given one of the following two special instructions.
* Lose one turn (labeled "L" in Figure 2) If the checker stops here, you cannot move the checker in the next turn.
* Go back to the start (labeled "B" in Figure 2)
If the checker stops here, the checker is brought back to the start.
<image>
Figure 2: An example game
Given a game board configuration (the size N, and the placement of the special instructions), you are requested to compute the probability with which the game succeeds within a given number of turns.
Input
The input consists of multiple datasets, each containing integers in the following format.
N T L B
Lose1
...
LoseL
Back1
...
BackB
N is the index of the goal, which satisfies 5 ≤ N ≤ 100. T is the number of turns. You are requested to compute the probability of success within T turns. T satisfies 1 ≤ T ≤ 100. L is the number of squares marked “Lose one turn”, which satisfies 0 ≤ L ≤ N - 1. B is the number of squares marked “Go back to the start”, which satisfies 0 ≤ B ≤ N - 1. They are separated by a space.
Losei's are the indexes of the squares marked “Lose one turn”, which satisfy 1 ≤ Losei ≤ N - 1. All Losei's are distinct, and sorted in ascending order. Backi's are the indexes of the squares marked “Go back to the start”, which satisfy 1 ≤ Backi ≤ N - 1. All Backi's are distinct, and sorted in ascending order. No numbers occur both in Losei's and Backi's.
The end of the input is indicated by a line containing four zeros separated by a space.
Output
For each dataset, you should answer the probability with which the game succeeds within the given number of turns. The output should not contain an error greater than 0.00001.
Example
Input
6 1 0 0
7 1 0 0
7 2 0 0
6 6 1 1
2
5
7 10 0 6
1
2
3
4
5
6
0 0 0 0
Output
0.166667
0.000000
0.166667
0.619642
0.000000 | instruction | 0 | 61,425 | 19 | 122,850 |
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
while True:
n,t,l,b = LI()
if n == 0:
break
ls = set([I() for _ in range(l)])
bs = set([I() for _ in range(b)])
r = [[0] * (n+1) for _ in range(t+2)]
r[0][0] = 1
for i in range(t):
for j in range(n):
if r[i][j] == 0:
continue
for k in range(1,7):
nj = j+k
if nj > n:
nj = n - (nj-n)
ni = i + 1
if nj in ls:
ni += 1
if nj in bs:
nj = 0
if nj == n:
ni = t
r[ni][nj] += r[i][j] / 6.0
rr.append('{:0.9f}'.format(r[t][n]))
return '\n'.join(map(str, rr))
print(main())
``` | output | 1 | 61,425 | 19 | 122,851 |
Provide a correct Python 3 solution for this coding contest problem.
Here is a very simple variation of the game backgammon, named “Minimal Backgammon”. The game is played by only one player, using only one of the dice and only one checker (the token used by the player).
The game board is a line of (N + 1) squares labeled as 0 (the start) to N (the goal). At the beginning, the checker is placed on the start (square 0). The aim of the game is to bring the checker to the goal (square N). The checker proceeds as many squares as the roll of the dice. The dice generates six integers from 1 to 6 with equal probability.
The checker should not go beyond the goal. If the roll of the dice would bring the checker beyond the goal, the checker retreats from the goal as many squares as the excess. For example, if the checker is placed at the square (N - 3), the roll "5" brings the checker to the square (N - 2), because the excess beyond the goal is 2. At the next turn, the checker proceeds toward the goal as usual.
Each square, except the start and the goal, may be given one of the following two special instructions.
* Lose one turn (labeled "L" in Figure 2) If the checker stops here, you cannot move the checker in the next turn.
* Go back to the start (labeled "B" in Figure 2)
If the checker stops here, the checker is brought back to the start.
<image>
Figure 2: An example game
Given a game board configuration (the size N, and the placement of the special instructions), you are requested to compute the probability with which the game succeeds within a given number of turns.
Input
The input consists of multiple datasets, each containing integers in the following format.
N T L B
Lose1
...
LoseL
Back1
...
BackB
N is the index of the goal, which satisfies 5 ≤ N ≤ 100. T is the number of turns. You are requested to compute the probability of success within T turns. T satisfies 1 ≤ T ≤ 100. L is the number of squares marked “Lose one turn”, which satisfies 0 ≤ L ≤ N - 1. B is the number of squares marked “Go back to the start”, which satisfies 0 ≤ B ≤ N - 1. They are separated by a space.
Losei's are the indexes of the squares marked “Lose one turn”, which satisfy 1 ≤ Losei ≤ N - 1. All Losei's are distinct, and sorted in ascending order. Backi's are the indexes of the squares marked “Go back to the start”, which satisfy 1 ≤ Backi ≤ N - 1. All Backi's are distinct, and sorted in ascending order. No numbers occur both in Losei's and Backi's.
The end of the input is indicated by a line containing four zeros separated by a space.
Output
For each dataset, you should answer the probability with which the game succeeds within the given number of turns. The output should not contain an error greater than 0.00001.
Example
Input
6 1 0 0
7 1 0 0
7 2 0 0
6 6 1 1
2
5
7 10 0 6
1
2
3
4
5
6
0 0 0 0
Output
0.166667
0.000000
0.166667
0.619642
0.000000 | instruction | 0 | 61,426 | 19 | 122,852 |
"Correct Solution:
```
while True:
n,turn,y,b = map(int,input().split())
if [n,turn,y,b]==[0,0,0,0]:
break
yasumi=[]
back=[]
for _ in range(y):
yasumi.append(int(input()))
for _ in range(b):
back.append(int(input()))
taiki=[0]*(turn+10)
dp=[[0.0]*(n+1) for _ in range(turn+10)]
dp[0][0]=1
for i in range(0,turn):
for j in range(0,n):
for dice in range(1,7):
cur= j+dice
if cur > n:
cur= n*2-cur
if cur in yasumi:
dp[i+2][cur]+=dp[i][j]/6
elif cur in back:
dp[i+1][0]+=dp[i][j]/6
else:
dp[i+1][cur]+=dp[i][j]/6
print('{:.6f}'.format(sum([dp[i][n] for i in range(turn+1)])))
``` | output | 1 | 61,426 | 19 | 122,853 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Here is a very simple variation of the game backgammon, named “Minimal Backgammon”. The game is played by only one player, using only one of the dice and only one checker (the token used by the player).
The game board is a line of (N + 1) squares labeled as 0 (the start) to N (the goal). At the beginning, the checker is placed on the start (square 0). The aim of the game is to bring the checker to the goal (square N). The checker proceeds as many squares as the roll of the dice. The dice generates six integers from 1 to 6 with equal probability.
The checker should not go beyond the goal. If the roll of the dice would bring the checker beyond the goal, the checker retreats from the goal as many squares as the excess. For example, if the checker is placed at the square (N - 3), the roll "5" brings the checker to the square (N - 2), because the excess beyond the goal is 2. At the next turn, the checker proceeds toward the goal as usual.
Each square, except the start and the goal, may be given one of the following two special instructions.
* Lose one turn (labeled "L" in Figure 2) If the checker stops here, you cannot move the checker in the next turn.
* Go back to the start (labeled "B" in Figure 2)
If the checker stops here, the checker is brought back to the start.
<image>
Figure 2: An example game
Given a game board configuration (the size N, and the placement of the special instructions), you are requested to compute the probability with which the game succeeds within a given number of turns.
Input
The input consists of multiple datasets, each containing integers in the following format.
N T L B
Lose1
...
LoseL
Back1
...
BackB
N is the index of the goal, which satisfies 5 ≤ N ≤ 100. T is the number of turns. You are requested to compute the probability of success within T turns. T satisfies 1 ≤ T ≤ 100. L is the number of squares marked “Lose one turn”, which satisfies 0 ≤ L ≤ N - 1. B is the number of squares marked “Go back to the start”, which satisfies 0 ≤ B ≤ N - 1. They are separated by a space.
Losei's are the indexes of the squares marked “Lose one turn”, which satisfy 1 ≤ Losei ≤ N - 1. All Losei's are distinct, and sorted in ascending order. Backi's are the indexes of the squares marked “Go back to the start”, which satisfy 1 ≤ Backi ≤ N - 1. All Backi's are distinct, and sorted in ascending order. No numbers occur both in Losei's and Backi's.
The end of the input is indicated by a line containing four zeros separated by a space.
Output
For each dataset, you should answer the probability with which the game succeeds within the given number of turns. The output should not contain an error greater than 0.00001.
Example
Input
6 1 0 0
7 1 0 0
7 2 0 0
6 6 1 1
2
5
7 10 0 6
1
2
3
4
5
6
0 0 0 0
Output
0.166667
0.000000
0.166667
0.619642
0.000000
Submitted Solution:
```
while True:
n, t, L, b = (int(s) for s in input().split())
if (n, t, L, b) == (0, 0, 0, 0):
break
loses = [int(input()) for i in range(L)]
backs = [int(input()) for i in range(b)]
dp = [[0.] * n + [1.] for i in range(3)]
stops = list(range(n + 1)) + list(reversed(range(n - 5, n)))
for i in reversed(range(t)):
for j in range(n):
dp[i % 3][j] = sum(
dp[(i + 2) % 3][d] if d in loses
else dp[(i + 1) % 3][0] if d in backs
else dp[(i + 1) % 3][d]
for d in stops[j + 1:j + 7]) / 6
print('{:.6f}'.format(dp[0][0]))
``` | instruction | 0 | 61,427 | 19 | 122,854 |
Yes | output | 1 | 61,427 | 19 | 122,855 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Here is a very simple variation of the game backgammon, named “Minimal Backgammon”. The game is played by only one player, using only one of the dice and only one checker (the token used by the player).
The game board is a line of (N + 1) squares labeled as 0 (the start) to N (the goal). At the beginning, the checker is placed on the start (square 0). The aim of the game is to bring the checker to the goal (square N). The checker proceeds as many squares as the roll of the dice. The dice generates six integers from 1 to 6 with equal probability.
The checker should not go beyond the goal. If the roll of the dice would bring the checker beyond the goal, the checker retreats from the goal as many squares as the excess. For example, if the checker is placed at the square (N - 3), the roll "5" brings the checker to the square (N - 2), because the excess beyond the goal is 2. At the next turn, the checker proceeds toward the goal as usual.
Each square, except the start and the goal, may be given one of the following two special instructions.
* Lose one turn (labeled "L" in Figure 2) If the checker stops here, you cannot move the checker in the next turn.
* Go back to the start (labeled "B" in Figure 2)
If the checker stops here, the checker is brought back to the start.
<image>
Figure 2: An example game
Given a game board configuration (the size N, and the placement of the special instructions), you are requested to compute the probability with which the game succeeds within a given number of turns.
Input
The input consists of multiple datasets, each containing integers in the following format.
N T L B
Lose1
...
LoseL
Back1
...
BackB
N is the index of the goal, which satisfies 5 ≤ N ≤ 100. T is the number of turns. You are requested to compute the probability of success within T turns. T satisfies 1 ≤ T ≤ 100. L is the number of squares marked “Lose one turn”, which satisfies 0 ≤ L ≤ N - 1. B is the number of squares marked “Go back to the start”, which satisfies 0 ≤ B ≤ N - 1. They are separated by a space.
Losei's are the indexes of the squares marked “Lose one turn”, which satisfy 1 ≤ Losei ≤ N - 1. All Losei's are distinct, and sorted in ascending order. Backi's are the indexes of the squares marked “Go back to the start”, which satisfy 1 ≤ Backi ≤ N - 1. All Backi's are distinct, and sorted in ascending order. No numbers occur both in Losei's and Backi's.
The end of the input is indicated by a line containing four zeros separated by a space.
Output
For each dataset, you should answer the probability with which the game succeeds within the given number of turns. The output should not contain an error greater than 0.00001.
Example
Input
6 1 0 0
7 1 0 0
7 2 0 0
6 6 1 1
2
5
7 10 0 6
1
2
3
4
5
6
0 0 0 0
Output
0.166667
0.000000
0.166667
0.619642
0.000000
Submitted Solution:
```
while True:
N, T, L, B = map(int, input().split())
if N | T | L | B == 0:
break
lose = set([int(input()) for i in range(L)])
back = set([int(input()) for i in range(B)])
dp = [[0] * (T + 1) for j in range(N + 1)]
dp[0][0] = 1
for t in range(T):
for n in range(N):
for d in range(1, 7):
step = 0
if n + d <= N:
step = n + d
else:
step = 2 * N - (n + d)
if step in lose:
if t + 2 <= T:
dp[step][t + 2] += dp[n][t] / 6
elif step in back:
dp[0][t + 1] += dp[n][t] / 6
else:
dp[step][t + 1] += dp[n][t] / 6
print(format(sum(dp[-1]), "0.6f"))
``` | instruction | 0 | 61,428 | 19 | 122,856 |
Yes | output | 1 | 61,428 | 19 | 122,857 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Here is a very simple variation of the game backgammon, named “Minimal Backgammon”. The game is played by only one player, using only one of the dice and only one checker (the token used by the player).
The game board is a line of (N + 1) squares labeled as 0 (the start) to N (the goal). At the beginning, the checker is placed on the start (square 0). The aim of the game is to bring the checker to the goal (square N). The checker proceeds as many squares as the roll of the dice. The dice generates six integers from 1 to 6 with equal probability.
The checker should not go beyond the goal. If the roll of the dice would bring the checker beyond the goal, the checker retreats from the goal as many squares as the excess. For example, if the checker is placed at the square (N - 3), the roll "5" brings the checker to the square (N - 2), because the excess beyond the goal is 2. At the next turn, the checker proceeds toward the goal as usual.
Each square, except the start and the goal, may be given one of the following two special instructions.
* Lose one turn (labeled "L" in Figure 2) If the checker stops here, you cannot move the checker in the next turn.
* Go back to the start (labeled "B" in Figure 2)
If the checker stops here, the checker is brought back to the start.
<image>
Figure 2: An example game
Given a game board configuration (the size N, and the placement of the special instructions), you are requested to compute the probability with which the game succeeds within a given number of turns.
Input
The input consists of multiple datasets, each containing integers in the following format.
N T L B
Lose1
...
LoseL
Back1
...
BackB
N is the index of the goal, which satisfies 5 ≤ N ≤ 100. T is the number of turns. You are requested to compute the probability of success within T turns. T satisfies 1 ≤ T ≤ 100. L is the number of squares marked “Lose one turn”, which satisfies 0 ≤ L ≤ N - 1. B is the number of squares marked “Go back to the start”, which satisfies 0 ≤ B ≤ N - 1. They are separated by a space.
Losei's are the indexes of the squares marked “Lose one turn”, which satisfy 1 ≤ Losei ≤ N - 1. All Losei's are distinct, and sorted in ascending order. Backi's are the indexes of the squares marked “Go back to the start”, which satisfy 1 ≤ Backi ≤ N - 1. All Backi's are distinct, and sorted in ascending order. No numbers occur both in Losei's and Backi's.
The end of the input is indicated by a line containing four zeros separated by a space.
Output
For each dataset, you should answer the probability with which the game succeeds within the given number of turns. The output should not contain an error greater than 0.00001.
Example
Input
6 1 0 0
7 1 0 0
7 2 0 0
6 6 1 1
2
5
7 10 0 6
1
2
3
4
5
6
0 0 0 0
Output
0.166667
0.000000
0.166667
0.619642
0.000000
Submitted Solution:
```
while True:
N, T, L, B = map(int, input().split())
if not (N | T | L | B):
break
Lose = [False for i in range(N + 1)]
Back = [False for i in range(N + 1)]
for i in range(L):
Lose[int(input())] = True
for j in range(B):
Back[int(input())] = True
dp = [[0.0 for j in range(N + 1)] for i in range(T + 2)]
dp[0][0] = 1.0
# 現在地
for t in range(T):
# ターン数
for n in range(N):
# サイコロ
for k in range(1, 7):
tmp = n + k
if n + k > N:
tmp = N - n - k - 1
if Lose[tmp]:
dp[t + 2][tmp] += dp[t][n] / 6
elif Back[tmp]:
dp[t + 1][0] += dp[t][n] / 6
else:
dp[t + 1][tmp] += dp[t][n] / 6
ans = 0.0
for i in range(T + 2):
ans += dp[i][N]
print("{0:.6f}".format(ans))
``` | instruction | 0 | 61,429 | 19 | 122,858 |
Yes | output | 1 | 61,429 | 19 | 122,859 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Here is a very simple variation of the game backgammon, named “Minimal Backgammon”. The game is played by only one player, using only one of the dice and only one checker (the token used by the player).
The game board is a line of (N + 1) squares labeled as 0 (the start) to N (the goal). At the beginning, the checker is placed on the start (square 0). The aim of the game is to bring the checker to the goal (square N). The checker proceeds as many squares as the roll of the dice. The dice generates six integers from 1 to 6 with equal probability.
The checker should not go beyond the goal. If the roll of the dice would bring the checker beyond the goal, the checker retreats from the goal as many squares as the excess. For example, if the checker is placed at the square (N - 3), the roll "5" brings the checker to the square (N - 2), because the excess beyond the goal is 2. At the next turn, the checker proceeds toward the goal as usual.
Each square, except the start and the goal, may be given one of the following two special instructions.
* Lose one turn (labeled "L" in Figure 2) If the checker stops here, you cannot move the checker in the next turn.
* Go back to the start (labeled "B" in Figure 2)
If the checker stops here, the checker is brought back to the start.
<image>
Figure 2: An example game
Given a game board configuration (the size N, and the placement of the special instructions), you are requested to compute the probability with which the game succeeds within a given number of turns.
Input
The input consists of multiple datasets, each containing integers in the following format.
N T L B
Lose1
...
LoseL
Back1
...
BackB
N is the index of the goal, which satisfies 5 ≤ N ≤ 100. T is the number of turns. You are requested to compute the probability of success within T turns. T satisfies 1 ≤ T ≤ 100. L is the number of squares marked “Lose one turn”, which satisfies 0 ≤ L ≤ N - 1. B is the number of squares marked “Go back to the start”, which satisfies 0 ≤ B ≤ N - 1. They are separated by a space.
Losei's are the indexes of the squares marked “Lose one turn”, which satisfy 1 ≤ Losei ≤ N - 1. All Losei's are distinct, and sorted in ascending order. Backi's are the indexes of the squares marked “Go back to the start”, which satisfy 1 ≤ Backi ≤ N - 1. All Backi's are distinct, and sorted in ascending order. No numbers occur both in Losei's and Backi's.
The end of the input is indicated by a line containing four zeros separated by a space.
Output
For each dataset, you should answer the probability with which the game succeeds within the given number of turns. The output should not contain an error greater than 0.00001.
Example
Input
6 1 0 0
7 1 0 0
7 2 0 0
6 6 1 1
2
5
7 10 0 6
1
2
3
4
5
6
0 0 0 0
Output
0.166667
0.000000
0.166667
0.619642
0.000000
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
while True:
n,t,l,b = LI()
if n == 0:
break
ls = set([I() for _ in range(l)])
bs = set([I() for _ in range(b)])
r = [[0] * (n+1) for _ in range(t+2)]
r[0][0] = 1
for i in range(t):
for j in range(n):
if r[i][j] == 0:
continue
for k in range(1,7):
nj = j+k
if nj > n:
nj = n - (nj-n)
ni = i + 1
if nj in ls:
ni += 1
if nj in bs:
nj = 0
if nj == n:
ni = t
r[ni][nj] += r[i][j] / 6.0
rr.append(r[t][n])
return '\n'.join(map(str, rr))
print(main())
``` | instruction | 0 | 61,430 | 19 | 122,860 |
No | output | 1 | 61,430 | 19 | 122,861 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing a game of Spaceship Solitaire. The goal of this game is to build a spaceship. In order to do this, he first needs to accumulate enough resources for the construction. There are n types of resources, numbered 1 through n. Bob needs at least a_i pieces of the i-th resource to build the spaceship. The number a_i is called the goal for resource i.
Each resource takes 1 turn to produce and in each turn only one resource can be produced. However, there are certain milestones that speed up production. Every milestone is a triple (s_j, t_j, u_j), meaning that as soon as Bob has t_j units of the resource s_j, he receives one unit of the resource u_j for free, without him needing to spend a turn. It is possible that getting this free resource allows Bob to claim reward for another milestone. This way, he can obtain a large number of resources in a single turn.
The game is constructed in such a way that there are never two milestones that have the same s_j and t_j, that is, the award for reaching t_j units of resource s_j is at most one additional resource.
A bonus is never awarded for 0 of any resource, neither for reaching the goal a_i nor for going past the goal — formally, for every milestone 0 < t_j < a_{s_j}.
A bonus for reaching certain amount of a resource can be the resource itself, that is, s_j = u_j.
Initially there are no milestones. You are to process q updates, each of which adds, removes or modifies a milestone. After every update, output the minimum number of turns needed to finish the game, that is, to accumulate at least a_i of i-th resource for each i ∈ [1, n].
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of types of resources.
The second line contains n space separated integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), the i-th of which is the goal for the i-th resource.
The third line contains a single integer q (1 ≤ q ≤ 10^5) — the number of updates to the game milestones.
Then q lines follow, the j-th of which contains three space separated integers s_j, t_j, u_j (1 ≤ s_j ≤ n, 1 ≤ t_j < a_{s_j}, 0 ≤ u_j ≤ n). For each triple, perform the following actions:
* First, if there is already a milestone for obtaining t_j units of resource s_j, it is removed.
* If u_j = 0, no new milestone is added.
* If u_j ≠ 0, add the following milestone: "For reaching t_j units of resource s_j, gain one free piece of u_j."
* Output the minimum number of turns needed to win the game.
Output
Output q lines, each consisting of a single integer, the i-th represents the answer after the i-th update.
Example
Input
2
2 3
5
2 1 1
2 2 1
1 1 1
2 1 2
2 2 0
Output
4
3
3
2
3
Note
After the first update, the optimal strategy is as follows. First produce 2 once, which gives a free resource 1. Then, produce 2 twice and 1 once, for a total of four turns.
After the second update, the optimal strategy is to produce 2 three times — the first two times a single unit of resource 1 is also granted.
After the third update, the game is won as follows.
* First produce 2 once. This gives a free unit of 1. This gives additional bonus of resource 1. After the first turn, the number of resources is thus [2, 1].
* Next, produce resource 2 again, which gives another unit of 1.
* After this, produce one more unit of 2.
The final count of resources is [3, 3], and three turns are needed to reach this situation. Notice that we have more of resource 1 than its goal, which is of no use. | instruction | 0 | 61,587 | 19 | 123,174 |
Tags: data structures, greedy, implementation
Correct Solution:
```
import sys
import math
input = sys.stdin.readline
n=int(input())
arr=list(map(int,input().split()))
cur=[0]*n
tot=sum(arr)
dic={}
q=int(input())
for i in range(q):
s,t,u=map(int,input().split())
# print(cur)
if (s,t) in dic:
# print("yo")
v=dic[(s,t)]
del dic[(s,t)]
if cur[v-1]<=arr[v-1]:
# print("x")
tot+=1
cur[v-1]-=1
if u>0:
dic[(s,t)]=u
if cur[u-1]<arr[u-1]:
tot-=1
cur[u-1]+=1
# print(dic)
print(tot)
#HC
``` | output | 1 | 61,587 | 19 | 123,175 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing a game of Spaceship Solitaire. The goal of this game is to build a spaceship. In order to do this, he first needs to accumulate enough resources for the construction. There are n types of resources, numbered 1 through n. Bob needs at least a_i pieces of the i-th resource to build the spaceship. The number a_i is called the goal for resource i.
Each resource takes 1 turn to produce and in each turn only one resource can be produced. However, there are certain milestones that speed up production. Every milestone is a triple (s_j, t_j, u_j), meaning that as soon as Bob has t_j units of the resource s_j, he receives one unit of the resource u_j for free, without him needing to spend a turn. It is possible that getting this free resource allows Bob to claim reward for another milestone. This way, he can obtain a large number of resources in a single turn.
The game is constructed in such a way that there are never two milestones that have the same s_j and t_j, that is, the award for reaching t_j units of resource s_j is at most one additional resource.
A bonus is never awarded for 0 of any resource, neither for reaching the goal a_i nor for going past the goal — formally, for every milestone 0 < t_j < a_{s_j}.
A bonus for reaching certain amount of a resource can be the resource itself, that is, s_j = u_j.
Initially there are no milestones. You are to process q updates, each of which adds, removes or modifies a milestone. After every update, output the minimum number of turns needed to finish the game, that is, to accumulate at least a_i of i-th resource for each i ∈ [1, n].
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of types of resources.
The second line contains n space separated integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), the i-th of which is the goal for the i-th resource.
The third line contains a single integer q (1 ≤ q ≤ 10^5) — the number of updates to the game milestones.
Then q lines follow, the j-th of which contains three space separated integers s_j, t_j, u_j (1 ≤ s_j ≤ n, 1 ≤ t_j < a_{s_j}, 0 ≤ u_j ≤ n). For each triple, perform the following actions:
* First, if there is already a milestone for obtaining t_j units of resource s_j, it is removed.
* If u_j = 0, no new milestone is added.
* If u_j ≠ 0, add the following milestone: "For reaching t_j units of resource s_j, gain one free piece of u_j."
* Output the minimum number of turns needed to win the game.
Output
Output q lines, each consisting of a single integer, the i-th represents the answer after the i-th update.
Example
Input
2
2 3
5
2 1 1
2 2 1
1 1 1
2 1 2
2 2 0
Output
4
3
3
2
3
Note
After the first update, the optimal strategy is as follows. First produce 2 once, which gives a free resource 1. Then, produce 2 twice and 1 once, for a total of four turns.
After the second update, the optimal strategy is to produce 2 three times — the first two times a single unit of resource 1 is also granted.
After the third update, the game is won as follows.
* First produce 2 once. This gives a free unit of 1. This gives additional bonus of resource 1. After the first turn, the number of resources is thus [2, 1].
* Next, produce resource 2 again, which gives another unit of 1.
* After this, produce one more unit of 2.
The final count of resources is [3, 3], and three turns are needed to reach this situation. Notice that we have more of resource 1 than its goal, which is of no use. | instruction | 0 | 61,588 | 19 | 123,176 |
Tags: data structures, greedy, implementation
Correct Solution:
```
import sys
input=sys.stdin.readline
n=int(input())
a=[int(i) for i in input().split() if i!='\n']
freq=[0]*(n)
q=int(input())
store=dict()
init=sum(a)
diff=0
for i in range(q):
s,t,u=map(int,input().split())
if (s,t) not in store:
if u!=0:
store[(s,t)]=u-1
if freq[u-1]<a[u-1]:
diff+=1
freq[u-1]+=1
else:
if u>0:
if freq[u-1]<a[u-1]:
diff+=1
freq[u-1]+=1
if freq[store[(s,t)]]-1<a[store[(s,t)]]:
diff-=1
freq[store[(s,t)]]-=1
#print(freq[store[(s,t)]],store[(s,t)])
if u>0:
store[(s,t)]=u-1
else:
del store[(s,t)]
sys.stdout.write(str(init-diff)+'\n')
``` | output | 1 | 61,588 | 19 | 123,177 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing a game of Spaceship Solitaire. The goal of this game is to build a spaceship. In order to do this, he first needs to accumulate enough resources for the construction. There are n types of resources, numbered 1 through n. Bob needs at least a_i pieces of the i-th resource to build the spaceship. The number a_i is called the goal for resource i.
Each resource takes 1 turn to produce and in each turn only one resource can be produced. However, there are certain milestones that speed up production. Every milestone is a triple (s_j, t_j, u_j), meaning that as soon as Bob has t_j units of the resource s_j, he receives one unit of the resource u_j for free, without him needing to spend a turn. It is possible that getting this free resource allows Bob to claim reward for another milestone. This way, he can obtain a large number of resources in a single turn.
The game is constructed in such a way that there are never two milestones that have the same s_j and t_j, that is, the award for reaching t_j units of resource s_j is at most one additional resource.
A bonus is never awarded for 0 of any resource, neither for reaching the goal a_i nor for going past the goal — formally, for every milestone 0 < t_j < a_{s_j}.
A bonus for reaching certain amount of a resource can be the resource itself, that is, s_j = u_j.
Initially there are no milestones. You are to process q updates, each of which adds, removes or modifies a milestone. After every update, output the minimum number of turns needed to finish the game, that is, to accumulate at least a_i of i-th resource for each i ∈ [1, n].
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of types of resources.
The second line contains n space separated integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), the i-th of which is the goal for the i-th resource.
The third line contains a single integer q (1 ≤ q ≤ 10^5) — the number of updates to the game milestones.
Then q lines follow, the j-th of which contains three space separated integers s_j, t_j, u_j (1 ≤ s_j ≤ n, 1 ≤ t_j < a_{s_j}, 0 ≤ u_j ≤ n). For each triple, perform the following actions:
* First, if there is already a milestone for obtaining t_j units of resource s_j, it is removed.
* If u_j = 0, no new milestone is added.
* If u_j ≠ 0, add the following milestone: "For reaching t_j units of resource s_j, gain one free piece of u_j."
* Output the minimum number of turns needed to win the game.
Output
Output q lines, each consisting of a single integer, the i-th represents the answer after the i-th update.
Example
Input
2
2 3
5
2 1 1
2 2 1
1 1 1
2 1 2
2 2 0
Output
4
3
3
2
3
Note
After the first update, the optimal strategy is as follows. First produce 2 once, which gives a free resource 1. Then, produce 2 twice and 1 once, for a total of four turns.
After the second update, the optimal strategy is to produce 2 three times — the first two times a single unit of resource 1 is also granted.
After the third update, the game is won as follows.
* First produce 2 once. This gives a free unit of 1. This gives additional bonus of resource 1. After the first turn, the number of resources is thus [2, 1].
* Next, produce resource 2 again, which gives another unit of 1.
* After this, produce one more unit of 2.
The final count of resources is [3, 3], and three turns are needed to reach this situation. Notice that we have more of resource 1 than its goal, which is of no use. | instruction | 0 | 61,589 | 19 | 123,178 |
Tags: data structures, greedy, implementation
Correct Solution:
```
import sys
input = sys.stdin.readline
n=int(input())
A=[0]+list(map(int,input().split()))
q=int(input())
SUMA=sum(A)
SUM=0
B=[0]*(n+1)
DICT=dict()
for i in range(q):
x,y,z=map(int,input().split())
if DICT.get((x,y))==None:
DICT[(x,y)]=z
B[z]+=1
if B[z]<=A[z]:
SUM+=1
else:
bef=DICT[(x,y)]
DICT[(x,y)]=z
if bef!=z:
B[bef]-=1
B[z]+=1
if B[bef]<A[bef]:
SUM-=1
if B[z]<=A[z]:
SUM+=1
print(SUMA-SUM)
``` | output | 1 | 61,589 | 19 | 123,179 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing a game of Spaceship Solitaire. The goal of this game is to build a spaceship. In order to do this, he first needs to accumulate enough resources for the construction. There are n types of resources, numbered 1 through n. Bob needs at least a_i pieces of the i-th resource to build the spaceship. The number a_i is called the goal for resource i.
Each resource takes 1 turn to produce and in each turn only one resource can be produced. However, there are certain milestones that speed up production. Every milestone is a triple (s_j, t_j, u_j), meaning that as soon as Bob has t_j units of the resource s_j, he receives one unit of the resource u_j for free, without him needing to spend a turn. It is possible that getting this free resource allows Bob to claim reward for another milestone. This way, he can obtain a large number of resources in a single turn.
The game is constructed in such a way that there are never two milestones that have the same s_j and t_j, that is, the award for reaching t_j units of resource s_j is at most one additional resource.
A bonus is never awarded for 0 of any resource, neither for reaching the goal a_i nor for going past the goal — formally, for every milestone 0 < t_j < a_{s_j}.
A bonus for reaching certain amount of a resource can be the resource itself, that is, s_j = u_j.
Initially there are no milestones. You are to process q updates, each of which adds, removes or modifies a milestone. After every update, output the minimum number of turns needed to finish the game, that is, to accumulate at least a_i of i-th resource for each i ∈ [1, n].
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of types of resources.
The second line contains n space separated integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), the i-th of which is the goal for the i-th resource.
The third line contains a single integer q (1 ≤ q ≤ 10^5) — the number of updates to the game milestones.
Then q lines follow, the j-th of which contains three space separated integers s_j, t_j, u_j (1 ≤ s_j ≤ n, 1 ≤ t_j < a_{s_j}, 0 ≤ u_j ≤ n). For each triple, perform the following actions:
* First, if there is already a milestone for obtaining t_j units of resource s_j, it is removed.
* If u_j = 0, no new milestone is added.
* If u_j ≠ 0, add the following milestone: "For reaching t_j units of resource s_j, gain one free piece of u_j."
* Output the minimum number of turns needed to win the game.
Output
Output q lines, each consisting of a single integer, the i-th represents the answer after the i-th update.
Example
Input
2
2 3
5
2 1 1
2 2 1
1 1 1
2 1 2
2 2 0
Output
4
3
3
2
3
Note
After the first update, the optimal strategy is as follows. First produce 2 once, which gives a free resource 1. Then, produce 2 twice and 1 once, for a total of four turns.
After the second update, the optimal strategy is to produce 2 three times — the first two times a single unit of resource 1 is also granted.
After the third update, the game is won as follows.
* First produce 2 once. This gives a free unit of 1. This gives additional bonus of resource 1. After the first turn, the number of resources is thus [2, 1].
* Next, produce resource 2 again, which gives another unit of 1.
* After this, produce one more unit of 2.
The final count of resources is [3, 3], and three turns are needed to reach this situation. Notice that we have more of resource 1 than its goal, which is of no use. | instruction | 0 | 61,590 | 19 | 123,180 |
Tags: data structures, greedy, implementation
Correct Solution:
```
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
graph=[]
visited=[]
arr=[]
ans=[]
def main():
n=int(input())
cn=list(map(int,input().split()))
cn.insert(0,0)
cnt=cn
d=dict()
ans=sum(cn)
for _ in range(int(input())):
s,t,u=map(int,input().split())
# print(cn)
if (s,t) in d:
v=d[(s,t)]
cn[v]+=1
d.pop((s,t))
if cn[v]>0:
ans+=1
if u!=0:
d[(s,t)]=u
if cn[u]>0:
ans-=1
cn[u]-=1
print(ans)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
``` | output | 1 | 61,590 | 19 | 123,181 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing a game of Spaceship Solitaire. The goal of this game is to build a spaceship. In order to do this, he first needs to accumulate enough resources for the construction. There are n types of resources, numbered 1 through n. Bob needs at least a_i pieces of the i-th resource to build the spaceship. The number a_i is called the goal for resource i.
Each resource takes 1 turn to produce and in each turn only one resource can be produced. However, there are certain milestones that speed up production. Every milestone is a triple (s_j, t_j, u_j), meaning that as soon as Bob has t_j units of the resource s_j, he receives one unit of the resource u_j for free, without him needing to spend a turn. It is possible that getting this free resource allows Bob to claim reward for another milestone. This way, he can obtain a large number of resources in a single turn.
The game is constructed in such a way that there are never two milestones that have the same s_j and t_j, that is, the award for reaching t_j units of resource s_j is at most one additional resource.
A bonus is never awarded for 0 of any resource, neither for reaching the goal a_i nor for going past the goal — formally, for every milestone 0 < t_j < a_{s_j}.
A bonus for reaching certain amount of a resource can be the resource itself, that is, s_j = u_j.
Initially there are no milestones. You are to process q updates, each of which adds, removes or modifies a milestone. After every update, output the minimum number of turns needed to finish the game, that is, to accumulate at least a_i of i-th resource for each i ∈ [1, n].
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of types of resources.
The second line contains n space separated integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), the i-th of which is the goal for the i-th resource.
The third line contains a single integer q (1 ≤ q ≤ 10^5) — the number of updates to the game milestones.
Then q lines follow, the j-th of which contains three space separated integers s_j, t_j, u_j (1 ≤ s_j ≤ n, 1 ≤ t_j < a_{s_j}, 0 ≤ u_j ≤ n). For each triple, perform the following actions:
* First, if there is already a milestone for obtaining t_j units of resource s_j, it is removed.
* If u_j = 0, no new milestone is added.
* If u_j ≠ 0, add the following milestone: "For reaching t_j units of resource s_j, gain one free piece of u_j."
* Output the minimum number of turns needed to win the game.
Output
Output q lines, each consisting of a single integer, the i-th represents the answer after the i-th update.
Example
Input
2
2 3
5
2 1 1
2 2 1
1 1 1
2 1 2
2 2 0
Output
4
3
3
2
3
Note
After the first update, the optimal strategy is as follows. First produce 2 once, which gives a free resource 1. Then, produce 2 twice and 1 once, for a total of four turns.
After the second update, the optimal strategy is to produce 2 three times — the first two times a single unit of resource 1 is also granted.
After the third update, the game is won as follows.
* First produce 2 once. This gives a free unit of 1. This gives additional bonus of resource 1. After the first turn, the number of resources is thus [2, 1].
* Next, produce resource 2 again, which gives another unit of 1.
* After this, produce one more unit of 2.
The final count of resources is [3, 3], and three turns are needed to reach this situation. Notice that we have more of resource 1 than its goal, which is of no use. | instruction | 0 | 61,591 | 19 | 123,182 |
Tags: data structures, greedy, implementation
Correct Solution:
```
#設定
import sys
input = sys.stdin.buffer.readline
#ライブラリインポート
from collections import defaultdict
#入力受け取り
def getlist():
return list(map(int, input().split()))
#処理内容
def main():
N = int(input())
a = getlist()
Q = int(input())
ans = sum(a)
D = defaultdict(int)
Dstone = defaultdict(int)
for i in range(Q):
s, t, u = getlist()
v = s - 1 + (t - 1) * (10 ** 9)
if Dstone[v] == 0: #石がない場合
if u != 0: #uが0でなければ石を追加
Dstone[v] = u
D[u] += 1
if D[u] <= a[u - 1]: #aの個数を上回らなかったらターン減少
ans -= 1
else: #石が既にあった場合
U = Dstone[v]
D[U] -= 1 #グレードダウン
if D[U] < a[U - 1]: #aの個数を下回ったらターン増加
ans += 1
Dstone[v] = 0
if u != 0: #uが0でなければ石を追加
Dstone[v] = u
D[u] += 1
if D[u] <= a[u - 1]:
ans -= 1
print(ans)
if __name__ == '__main__':
main()
``` | output | 1 | 61,591 | 19 | 123,183 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing a game of Spaceship Solitaire. The goal of this game is to build a spaceship. In order to do this, he first needs to accumulate enough resources for the construction. There are n types of resources, numbered 1 through n. Bob needs at least a_i pieces of the i-th resource to build the spaceship. The number a_i is called the goal for resource i.
Each resource takes 1 turn to produce and in each turn only one resource can be produced. However, there are certain milestones that speed up production. Every milestone is a triple (s_j, t_j, u_j), meaning that as soon as Bob has t_j units of the resource s_j, he receives one unit of the resource u_j for free, without him needing to spend a turn. It is possible that getting this free resource allows Bob to claim reward for another milestone. This way, he can obtain a large number of resources in a single turn.
The game is constructed in such a way that there are never two milestones that have the same s_j and t_j, that is, the award for reaching t_j units of resource s_j is at most one additional resource.
A bonus is never awarded for 0 of any resource, neither for reaching the goal a_i nor for going past the goal — formally, for every milestone 0 < t_j < a_{s_j}.
A bonus for reaching certain amount of a resource can be the resource itself, that is, s_j = u_j.
Initially there are no milestones. You are to process q updates, each of which adds, removes or modifies a milestone. After every update, output the minimum number of turns needed to finish the game, that is, to accumulate at least a_i of i-th resource for each i ∈ [1, n].
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of types of resources.
The second line contains n space separated integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), the i-th of which is the goal for the i-th resource.
The third line contains a single integer q (1 ≤ q ≤ 10^5) — the number of updates to the game milestones.
Then q lines follow, the j-th of which contains three space separated integers s_j, t_j, u_j (1 ≤ s_j ≤ n, 1 ≤ t_j < a_{s_j}, 0 ≤ u_j ≤ n). For each triple, perform the following actions:
* First, if there is already a milestone for obtaining t_j units of resource s_j, it is removed.
* If u_j = 0, no new milestone is added.
* If u_j ≠ 0, add the following milestone: "For reaching t_j units of resource s_j, gain one free piece of u_j."
* Output the minimum number of turns needed to win the game.
Output
Output q lines, each consisting of a single integer, the i-th represents the answer after the i-th update.
Example
Input
2
2 3
5
2 1 1
2 2 1
1 1 1
2 1 2
2 2 0
Output
4
3
3
2
3
Note
After the first update, the optimal strategy is as follows. First produce 2 once, which gives a free resource 1. Then, produce 2 twice and 1 once, for a total of four turns.
After the second update, the optimal strategy is to produce 2 three times — the first two times a single unit of resource 1 is also granted.
After the third update, the game is won as follows.
* First produce 2 once. This gives a free unit of 1. This gives additional bonus of resource 1. After the first turn, the number of resources is thus [2, 1].
* Next, produce resource 2 again, which gives another unit of 1.
* After this, produce one more unit of 2.
The final count of resources is [3, 3], and three turns are needed to reach this situation. Notice that we have more of resource 1 than its goal, which is of no use. | instruction | 0 | 61,592 | 19 | 123,184 |
Tags: data structures, greedy, implementation
Correct Solution:
```
# import heapq
# import math
from collections import *
# from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline
# M = mod = 10**9 + 7
# def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))))
# def inv_mod(n):return pow(n, mod - 2, mod)
def li():return [int(i) for i in input().rstrip('\n').split(' ')]
# def st():return input().rstrip('\n')
def val():return int(input())
# def li2():return [i for i in input().rstrip('\n').split(' ')]
n = val()
a = li()
tot = sum(a)
q = val()
d = {}
currcount = [0 for i in range(n)]
for i in range(q):
l = li()
if (l[0],l[1]) in d:
val = d[(l[0],l[1])]
currcount[val - 1] -= 1
tot += 1 if currcount[val -1] < a[val -1] else 0
d.pop((l[0],l[1]))
if l[2]:
d[(l[0],l[1])] = l[2]
currcount[l[2] - 1] += 1
tot -= 1 if currcount[l[2] -1] <= a[l[2] -1] else 0
print(tot)
``` | output | 1 | 61,592 | 19 | 123,185 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing a game of Spaceship Solitaire. The goal of this game is to build a spaceship. In order to do this, he first needs to accumulate enough resources for the construction. There are n types of resources, numbered 1 through n. Bob needs at least a_i pieces of the i-th resource to build the spaceship. The number a_i is called the goal for resource i.
Each resource takes 1 turn to produce and in each turn only one resource can be produced. However, there are certain milestones that speed up production. Every milestone is a triple (s_j, t_j, u_j), meaning that as soon as Bob has t_j units of the resource s_j, he receives one unit of the resource u_j for free, without him needing to spend a turn. It is possible that getting this free resource allows Bob to claim reward for another milestone. This way, he can obtain a large number of resources in a single turn.
The game is constructed in such a way that there are never two milestones that have the same s_j and t_j, that is, the award for reaching t_j units of resource s_j is at most one additional resource.
A bonus is never awarded for 0 of any resource, neither for reaching the goal a_i nor for going past the goal — formally, for every milestone 0 < t_j < a_{s_j}.
A bonus for reaching certain amount of a resource can be the resource itself, that is, s_j = u_j.
Initially there are no milestones. You are to process q updates, each of which adds, removes or modifies a milestone. After every update, output the minimum number of turns needed to finish the game, that is, to accumulate at least a_i of i-th resource for each i ∈ [1, n].
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of types of resources.
The second line contains n space separated integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), the i-th of which is the goal for the i-th resource.
The third line contains a single integer q (1 ≤ q ≤ 10^5) — the number of updates to the game milestones.
Then q lines follow, the j-th of which contains three space separated integers s_j, t_j, u_j (1 ≤ s_j ≤ n, 1 ≤ t_j < a_{s_j}, 0 ≤ u_j ≤ n). For each triple, perform the following actions:
* First, if there is already a milestone for obtaining t_j units of resource s_j, it is removed.
* If u_j = 0, no new milestone is added.
* If u_j ≠ 0, add the following milestone: "For reaching t_j units of resource s_j, gain one free piece of u_j."
* Output the minimum number of turns needed to win the game.
Output
Output q lines, each consisting of a single integer, the i-th represents the answer after the i-th update.
Example
Input
2
2 3
5
2 1 1
2 2 1
1 1 1
2 1 2
2 2 0
Output
4
3
3
2
3
Note
After the first update, the optimal strategy is as follows. First produce 2 once, which gives a free resource 1. Then, produce 2 twice and 1 once, for a total of four turns.
After the second update, the optimal strategy is to produce 2 three times — the first two times a single unit of resource 1 is also granted.
After the third update, the game is won as follows.
* First produce 2 once. This gives a free unit of 1. This gives additional bonus of resource 1. After the first turn, the number of resources is thus [2, 1].
* Next, produce resource 2 again, which gives another unit of 1.
* After this, produce one more unit of 2.
The final count of resources is [3, 3], and three turns are needed to reach this situation. Notice that we have more of resource 1 than its goal, which is of no use. | instruction | 0 | 61,593 | 19 | 123,186 |
Tags: data structures, greedy, implementation
Correct Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
def main():
n = int(input())
a = [0]+list(map(int,input().split()))
su = sum(a)
le = [0]*(n+1)
dct = {}
for _ in range(int(input())):
s,t,u = map(int,input().split())
x = dct.get((s,t))
if x:
le[x] -= 1
if le[x] < a[x]:
su += 1
del dct[(s,t)]
if u:
dct[(s,t)] = u
le[u] += 1
if le[u] <= a[u]:
su -= 1
print(su)
# Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self,file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZE))
self.newlines = b.count(b"\n")+(not b)
ptr = self.buffer.tell()
self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd,self.buffer.getvalue())
self.buffer.truncate(0),self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self,file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s:self.buffer.write(s.encode("ascii"))
self.read = lambda:self.buffer.read().decode("ascii")
self.readline = lambda:self.buffer.readline().decode("ascii")
sys.stdin,sys.stdout = IOWrapper(sys.stdin),IOWrapper(sys.stdout)
input = lambda:sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
``` | output | 1 | 61,593 | 19 | 123,187 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing a game of Spaceship Solitaire. The goal of this game is to build a spaceship. In order to do this, he first needs to accumulate enough resources for the construction. There are n types of resources, numbered 1 through n. Bob needs at least a_i pieces of the i-th resource to build the spaceship. The number a_i is called the goal for resource i.
Each resource takes 1 turn to produce and in each turn only one resource can be produced. However, there are certain milestones that speed up production. Every milestone is a triple (s_j, t_j, u_j), meaning that as soon as Bob has t_j units of the resource s_j, he receives one unit of the resource u_j for free, without him needing to spend a turn. It is possible that getting this free resource allows Bob to claim reward for another milestone. This way, he can obtain a large number of resources in a single turn.
The game is constructed in such a way that there are never two milestones that have the same s_j and t_j, that is, the award for reaching t_j units of resource s_j is at most one additional resource.
A bonus is never awarded for 0 of any resource, neither for reaching the goal a_i nor for going past the goal — formally, for every milestone 0 < t_j < a_{s_j}.
A bonus for reaching certain amount of a resource can be the resource itself, that is, s_j = u_j.
Initially there are no milestones. You are to process q updates, each of which adds, removes or modifies a milestone. After every update, output the minimum number of turns needed to finish the game, that is, to accumulate at least a_i of i-th resource for each i ∈ [1, n].
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of types of resources.
The second line contains n space separated integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), the i-th of which is the goal for the i-th resource.
The third line contains a single integer q (1 ≤ q ≤ 10^5) — the number of updates to the game milestones.
Then q lines follow, the j-th of which contains three space separated integers s_j, t_j, u_j (1 ≤ s_j ≤ n, 1 ≤ t_j < a_{s_j}, 0 ≤ u_j ≤ n). For each triple, perform the following actions:
* First, if there is already a milestone for obtaining t_j units of resource s_j, it is removed.
* If u_j = 0, no new milestone is added.
* If u_j ≠ 0, add the following milestone: "For reaching t_j units of resource s_j, gain one free piece of u_j."
* Output the minimum number of turns needed to win the game.
Output
Output q lines, each consisting of a single integer, the i-th represents the answer after the i-th update.
Example
Input
2
2 3
5
2 1 1
2 2 1
1 1 1
2 1 2
2 2 0
Output
4
3
3
2
3
Note
After the first update, the optimal strategy is as follows. First produce 2 once, which gives a free resource 1. Then, produce 2 twice and 1 once, for a total of four turns.
After the second update, the optimal strategy is to produce 2 three times — the first two times a single unit of resource 1 is also granted.
After the third update, the game is won as follows.
* First produce 2 once. This gives a free unit of 1. This gives additional bonus of resource 1. After the first turn, the number of resources is thus [2, 1].
* Next, produce resource 2 again, which gives another unit of 1.
* After this, produce one more unit of 2.
The final count of resources is [3, 3], and three turns are needed to reach this situation. Notice that we have more of resource 1 than its goal, which is of no use. | instruction | 0 | 61,594 | 19 | 123,188 |
Tags: data structures, greedy, implementation
Correct Solution:
```
from sys import stdin
n = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
d = [0] * n
ach = [dict() for i in range(n)]
ans = sum(arr)
q = int(stdin.readline())
a = stdin.readlines()
answers = []
for i in range(q):
s, t, u = map(int, a[i].split())
s -= 1
u -= 1
if ach[s].get(t, -1) != -1:
d[ach[s][t]] -= 1
if d[ach[s][t]] < arr[ach[s][t]]:
ans += 1
ach[s][t] = u
if u != -1:
d[u] += 1
if d[u] <= arr[u]:
ans -= 1
answers.append(str(ans))
print('\n'.join(answers))
``` | output | 1 | 61,594 | 19 | 123,189 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima's spent much time thinking what present to give to Inna and gave her an empty sequence w. Now they want to fill sequence w with numbers zero and one. For that, they decided to play an amusing game.
Before the game begins, Dima chooses m integers a1, a2, ..., am (1 ≤ a1 < a2 < ... < am). Then Inna and Dima start playing, that is, adding numbers to sequence w. Each new number they choose is added to the end of the sequence. At some moments of time Dima feels that the game is going to end too soon (and he wants to play with Inna as long as possible), so he hits a table hard with his fist. At that the a1-th, a2-th, a3-th, ..., ak-th numbers from the beginning simultaneously fall out of the sequence (the sequence gets k numbers less). Here k is such maximum number that value ak doesn't exceed the current length of the sequence. If number a1 is larger than the current length of w, then nothing falls out of the sequence.
You are given the chronological sequence of events in the game. Each event is either adding a number to the end of sequence w or Dima's hit on the table. Calculate the sequence w after all these events happen.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 106) showing how many events took place and how many numbers Dima chose.
The next line contains m distinct integers ai (1 ≤ ai ≤ 106) sorted in the increasing order.
Next n lines describe the events in the chronological order. Each line contains a single integer: -1, 0 or 1. Number -1 means that Dima hits the table. Number 0 means that Inna and Dima add number 0 to the end of the sequence. Number 1 means that Inna and Dima add number 1 to the end of the sequence.
Output
In a single line print a sequence of numbers 0 and 1 — the elements of the sequence after all events happen. Print the elements of the sequence in the order from the beginning to the end of the sequence.
If after all events the sequence ends up empty, print "Poor stack!".
Examples
Input
10 3
1 3 6
-1
1
1
0
0
-1
0
1
-1
1
Output
011
Input
2 1
1
1
-1
Output
Poor stack!
Submitted Solution:
```
from collections import deque
n,m=map(int,input().split())
s=deque(map(int,input().split()))
dp=[]
t=True
for i in range(n):
x=input()
if x=="-1":
if t:
dp1=[]
y=0
for i in range(len(dp)):
if i!=s[y]-1:
dp1.append(dp[i])
else:
y+=1
if y==m:
y-=1
t=False
else:
dp=[]
y=0
for i in range(len(dp1)):
if i!=s[y]-1:
dp.append(dp1[i])
else:
y+=1
if y==m:
y-=1
t=True
else:
if t:
dp.append(x)
else:
dp1.append(x)
if len(dp)==0:
print("Poor stack!")
else:
ans=""
if t:
for i in dp:
ans+=i
else:
for i in dp1:
ans+=i
print(ans)
``` | instruction | 0 | 61,772 | 19 | 123,544 |
No | output | 1 | 61,772 | 19 | 123,545 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima's spent much time thinking what present to give to Inna and gave her an empty sequence w. Now they want to fill sequence w with numbers zero and one. For that, they decided to play an amusing game.
Before the game begins, Dima chooses m integers a1, a2, ..., am (1 ≤ a1 < a2 < ... < am). Then Inna and Dima start playing, that is, adding numbers to sequence w. Each new number they choose is added to the end of the sequence. At some moments of time Dima feels that the game is going to end too soon (and he wants to play with Inna as long as possible), so he hits a table hard with his fist. At that the a1-th, a2-th, a3-th, ..., ak-th numbers from the beginning simultaneously fall out of the sequence (the sequence gets k numbers less). Here k is such maximum number that value ak doesn't exceed the current length of the sequence. If number a1 is larger than the current length of w, then nothing falls out of the sequence.
You are given the chronological sequence of events in the game. Each event is either adding a number to the end of sequence w or Dima's hit on the table. Calculate the sequence w after all these events happen.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 106) showing how many events took place and how many numbers Dima chose.
The next line contains m distinct integers ai (1 ≤ ai ≤ 106) sorted in the increasing order.
Next n lines describe the events in the chronological order. Each line contains a single integer: -1, 0 or 1. Number -1 means that Dima hits the table. Number 0 means that Inna and Dima add number 0 to the end of the sequence. Number 1 means that Inna and Dima add number 1 to the end of the sequence.
Output
In a single line print a sequence of numbers 0 and 1 — the elements of the sequence after all events happen. Print the elements of the sequence in the order from the beginning to the end of the sequence.
If after all events the sequence ends up empty, print "Poor stack!".
Examples
Input
10 3
1 3 6
-1
1
1
0
0
-1
0
1
-1
1
Output
011
Input
2 1
1
1
-1
Output
Poor stack!
Submitted Solution:
```
import sys,bisect as bi
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
n,q=I()
a=I()
an=[];st=0
for _ in range(n):
x,=I()
if (x==-1):
p=bi.bisect(a,len(an)-st)
#print(an[st:],p)
if p!=0:
st+=p
#print(an[st:],p)
else:
an.append(str(x))
if (st-len(an)):
print(''.join(an[st:]))
else:
print("Poor stack!")
``` | instruction | 0 | 61,773 | 19 | 123,546 |
No | output | 1 | 61,773 | 19 | 123,547 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima's spent much time thinking what present to give to Inna and gave her an empty sequence w. Now they want to fill sequence w with numbers zero and one. For that, they decided to play an amusing game.
Before the game begins, Dima chooses m integers a1, a2, ..., am (1 ≤ a1 < a2 < ... < am). Then Inna and Dima start playing, that is, adding numbers to sequence w. Each new number they choose is added to the end of the sequence. At some moments of time Dima feels that the game is going to end too soon (and he wants to play with Inna as long as possible), so he hits a table hard with his fist. At that the a1-th, a2-th, a3-th, ..., ak-th numbers from the beginning simultaneously fall out of the sequence (the sequence gets k numbers less). Here k is such maximum number that value ak doesn't exceed the current length of the sequence. If number a1 is larger than the current length of w, then nothing falls out of the sequence.
You are given the chronological sequence of events in the game. Each event is either adding a number to the end of sequence w or Dima's hit on the table. Calculate the sequence w after all these events happen.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 106) showing how many events took place and how many numbers Dima chose.
The next line contains m distinct integers ai (1 ≤ ai ≤ 106) sorted in the increasing order.
Next n lines describe the events in the chronological order. Each line contains a single integer: -1, 0 or 1. Number -1 means that Dima hits the table. Number 0 means that Inna and Dima add number 0 to the end of the sequence. Number 1 means that Inna and Dima add number 1 to the end of the sequence.
Output
In a single line print a sequence of numbers 0 and 1 — the elements of the sequence after all events happen. Print the elements of the sequence in the order from the beginning to the end of the sequence.
If after all events the sequence ends up empty, print "Poor stack!".
Examples
Input
10 3
1 3 6
-1
1
1
0
0
-1
0
1
-1
1
Output
011
Input
2 1
1
1
-1
Output
Poor stack!
Submitted Solution:
```
import sys,bisect as bi
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
n,q=I()
a=I()
an=[];st=0
for _ in range(n):
x,=I()
if (x==-1):
p=bi.bisect(a,len(an)-st)
le=bi.bisect(a,len(an)-st)
#print(an[st:],p)
st+=p
#print(an[st:],p)
else:
an.append(str(x))
if (st-len(an)):
if n==15253:
print(''.join(an[st:]),''.join(an[len(an)-100:]),st)
else:
print(''.join(an[st:]))
else:
print("Poor stack!")
``` | instruction | 0 | 61,774 | 19 | 123,548 |
No | output | 1 | 61,774 | 19 | 123,549 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima's spent much time thinking what present to give to Inna and gave her an empty sequence w. Now they want to fill sequence w with numbers zero and one. For that, they decided to play an amusing game.
Before the game begins, Dima chooses m integers a1, a2, ..., am (1 ≤ a1 < a2 < ... < am). Then Inna and Dima start playing, that is, adding numbers to sequence w. Each new number they choose is added to the end of the sequence. At some moments of time Dima feels that the game is going to end too soon (and he wants to play with Inna as long as possible), so he hits a table hard with his fist. At that the a1-th, a2-th, a3-th, ..., ak-th numbers from the beginning simultaneously fall out of the sequence (the sequence gets k numbers less). Here k is such maximum number that value ak doesn't exceed the current length of the sequence. If number a1 is larger than the current length of w, then nothing falls out of the sequence.
You are given the chronological sequence of events in the game. Each event is either adding a number to the end of sequence w or Dima's hit on the table. Calculate the sequence w after all these events happen.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 106) showing how many events took place and how many numbers Dima chose.
The next line contains m distinct integers ai (1 ≤ ai ≤ 106) sorted in the increasing order.
Next n lines describe the events in the chronological order. Each line contains a single integer: -1, 0 or 1. Number -1 means that Dima hits the table. Number 0 means that Inna and Dima add number 0 to the end of the sequence. Number 1 means that Inna and Dima add number 1 to the end of the sequence.
Output
In a single line print a sequence of numbers 0 and 1 — the elements of the sequence after all events happen. Print the elements of the sequence in the order from the beginning to the end of the sequence.
If after all events the sequence ends up empty, print "Poor stack!".
Examples
Input
10 3
1 3 6
-1
1
1
0
0
-1
0
1
-1
1
Output
011
Input
2 1
1
1
-1
Output
Poor stack!
Submitted Solution:
```
from bisect import bisect_right as bs
m, n = map(int, input().split()) # array size, no. of queries
t = [0 for i in range(2 * m)]
def add(p, value): # set value at position p
p += m; t[p] = value
while p > 1:
t[p>>1] = (t[p]+t[p^1])
p >>= 1
def delete(x):
y=1
aux=2
t[1]-=1
while aux<len(t):
if t[aux]>=x:
y=aux
t[aux]-=1
else:
x-=t[aux]
t[aux+1]-=1
y=aux+1
aux=y*2
ans=""
s=list(map(int,input().split()))
s1=[]
for i in range(m):
x=input()
if x!="-1":
s1.append(x)
add(len(s1)-1,1)
else:
for j in range(bs(s,t[1])-1,-1,-1):
delete(s[j])
for i in range(len(s1)):
if t[m+i]==1:
ans+=s1[i]
print(ans)
``` | instruction | 0 | 61,775 | 19 | 123,550 |
No | output | 1 | 61,775 | 19 | 123,551 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.
The game is played on a square field consisting of n × n cells. Initially all cells are empty. On each turn a player chooses and paint an empty cell that has no common sides with previously painted cells. Adjacent corner of painted cells is allowed. On the next turn another player does the same, then the first one and so on. The player with no cells to paint on his turn loses.
The professor have chosen the field size n and allowed the student to choose to be the first or the second player in the game. What should the student choose to win the game? Both players play optimally.
Input
The only line of the input contains one integer n (1 ≤ n ≤ 1018) — the size of the field.
Output
Output number 1, if the player making the first turn wins when both players play optimally, otherwise print number 2.
Examples
Input
1
Output
1
Input
2
Output
2 | instruction | 0 | 61,904 | 19 | 123,808 |
Tags: games, math
Correct Solution:
```
n = int(input())
ans = n * n
ans = ans // 2
if n * n % 2 == 1:
ans += 1
ans %= 2
if ans == 1:
print(1)
else: print(2)
``` | output | 1 | 61,904 | 19 | 123,809 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.
The game is played on a square field consisting of n × n cells. Initially all cells are empty. On each turn a player chooses and paint an empty cell that has no common sides with previously painted cells. Adjacent corner of painted cells is allowed. On the next turn another player does the same, then the first one and so on. The player with no cells to paint on his turn loses.
The professor have chosen the field size n and allowed the student to choose to be the first or the second player in the game. What should the student choose to win the game? Both players play optimally.
Input
The only line of the input contains one integer n (1 ≤ n ≤ 1018) — the size of the field.
Output
Output number 1, if the player making the first turn wins when both players play optimally, otherwise print number 2.
Examples
Input
1
Output
1
Input
2
Output
2 | instruction | 0 | 61,905 | 19 | 123,810 |
Tags: games, math
Correct Solution:
```
print(1) if int(input())%2==1 else print(2)
``` | output | 1 | 61,905 | 19 | 123,811 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.
The game is played on a square field consisting of n × n cells. Initially all cells are empty. On each turn a player chooses and paint an empty cell that has no common sides with previously painted cells. Adjacent corner of painted cells is allowed. On the next turn another player does the same, then the first one and so on. The player with no cells to paint on his turn loses.
The professor have chosen the field size n and allowed the student to choose to be the first or the second player in the game. What should the student choose to win the game? Both players play optimally.
Input
The only line of the input contains one integer n (1 ≤ n ≤ 1018) — the size of the field.
Output
Output number 1, if the player making the first turn wins when both players play optimally, otherwise print number 2.
Examples
Input
1
Output
1
Input
2
Output
2 | instruction | 0 | 61,906 | 19 | 123,812 |
Tags: games, math
Correct Solution:
```
import os, sys, pdb
import time, calendar, datetime
import math, itertools
import operator as op
from functools import reduce
def ncr(n, r):
r = min(r, n-r)
numer = reduce(op.mul, range(n, n-r, -1), 1)
denom = reduce(op.mul, range(1, r+1), 1)
return numer // denom
n, = list(map(int, input().split()))
print( 2 - (n % 2) )
``` | output | 1 | 61,906 | 19 | 123,813 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.
The game is played on a square field consisting of n × n cells. Initially all cells are empty. On each turn a player chooses and paint an empty cell that has no common sides with previously painted cells. Adjacent corner of painted cells is allowed. On the next turn another player does the same, then the first one and so on. The player with no cells to paint on his turn loses.
The professor have chosen the field size n and allowed the student to choose to be the first or the second player in the game. What should the student choose to win the game? Both players play optimally.
Input
The only line of the input contains one integer n (1 ≤ n ≤ 1018) — the size of the field.
Output
Output number 1, if the player making the first turn wins when both players play optimally, otherwise print number 2.
Examples
Input
1
Output
1
Input
2
Output
2 | instruction | 0 | 61,907 | 19 | 123,814 |
Tags: games, math
Correct Solution:
```
n = int(input())
res = [2, 1]
print(res[n % 2])
``` | output | 1 | 61,907 | 19 | 123,815 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.
The game is played on a square field consisting of n × n cells. Initially all cells are empty. On each turn a player chooses and paint an empty cell that has no common sides with previously painted cells. Adjacent corner of painted cells is allowed. On the next turn another player does the same, then the first one and so on. The player with no cells to paint on his turn loses.
The professor have chosen the field size n and allowed the student to choose to be the first or the second player in the game. What should the student choose to win the game? Both players play optimally.
Input
The only line of the input contains one integer n (1 ≤ n ≤ 1018) — the size of the field.
Output
Output number 1, if the player making the first turn wins when both players play optimally, otherwise print number 2.
Examples
Input
1
Output
1
Input
2
Output
2 | instruction | 0 | 61,908 | 19 | 123,816 |
Tags: games, math
Correct Solution:
```
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math, fractions, collections
# ===================================
n = int(input())
print(1 if n&1 else 2)
``` | output | 1 | 61,908 | 19 | 123,817 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.
The game is played on a square field consisting of n × n cells. Initially all cells are empty. On each turn a player chooses and paint an empty cell that has no common sides with previously painted cells. Adjacent corner of painted cells is allowed. On the next turn another player does the same, then the first one and so on. The player with no cells to paint on his turn loses.
The professor have chosen the field size n and allowed the student to choose to be the first or the second player in the game. What should the student choose to win the game? Both players play optimally.
Input
The only line of the input contains one integer n (1 ≤ n ≤ 1018) — the size of the field.
Output
Output number 1, if the player making the first turn wins when both players play optimally, otherwise print number 2.
Examples
Input
1
Output
1
Input
2
Output
2 | instruction | 0 | 61,909 | 19 | 123,818 |
Tags: games, math
Correct Solution:
```
print(2-(int(input())%2))
``` | output | 1 | 61,909 | 19 | 123,819 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.
The game is played on a square field consisting of n × n cells. Initially all cells are empty. On each turn a player chooses and paint an empty cell that has no common sides with previously painted cells. Adjacent corner of painted cells is allowed. On the next turn another player does the same, then the first one and so on. The player with no cells to paint on his turn loses.
The professor have chosen the field size n and allowed the student to choose to be the first or the second player in the game. What should the student choose to win the game? Both players play optimally.
Input
The only line of the input contains one integer n (1 ≤ n ≤ 1018) — the size of the field.
Output
Output number 1, if the player making the first turn wins when both players play optimally, otherwise print number 2.
Examples
Input
1
Output
1
Input
2
Output
2 | instruction | 0 | 61,910 | 19 | 123,820 |
Tags: games, math
Correct Solution:
```
mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
print((not ii()&1)+1)
``` | output | 1 | 61,910 | 19 | 123,821 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.
The game is played on a square field consisting of n × n cells. Initially all cells are empty. On each turn a player chooses and paint an empty cell that has no common sides with previously painted cells. Adjacent corner of painted cells is allowed. On the next turn another player does the same, then the first one and so on. The player with no cells to paint on his turn loses.
The professor have chosen the field size n and allowed the student to choose to be the first or the second player in the game. What should the student choose to win the game? Both players play optimally.
Input
The only line of the input contains one integer n (1 ≤ n ≤ 1018) — the size of the field.
Output
Output number 1, if the player making the first turn wins when both players play optimally, otherwise print number 2.
Examples
Input
1
Output
1
Input
2
Output
2 | instruction | 0 | 61,911 | 19 | 123,822 |
Tags: games, math
Correct Solution:
```
z=input
mod = 10**9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
def lcd(xnum1,xnum2):
return (xnum1*xnum2//gcd(xnum1,xnum2))
def prime(x):
p=ceil(x**.5)+1
for i in range(2,p):
if x%i==0:
return 0
return 1
################################################################################
"""
n=int(z())
for _ in range(int(z())):
x=int(z())
l=list(map(int,z().split()))
n=int(z())
l=sorted(list(map(int,z().split())))[::-1]
a,b=map(int,z().split())
l=set(map(int,z().split()))
led=(6,2,5,5,4,5,6,3,7,6)
vowel={'a':0,'e':0,'i':0,'o':0,'u':0}
color4=["G", "GB", "YGB", "YGBI", "OYGBI" ,"OYGBIV",'ROYGBIV' ]
"""
###########################---START-CODING---###############################################
z=input
mod = 10**9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
def lcd(xnum1,xnum2):
return (xnum1*xnum2//gcd(xnum1,xnum2))
def prime(x):
p=ceil(x**.5)+1
for i in range(2,p):
if x%i==0:
return 0
return 1
################################################################################
"""
n=int(z())
for _ in range(int(z())):
x=int(z())
l=list(map(int,z().split()))
n=int(z())
l=sorted(list(map(int,z().split())))[::-1]
a,b=map(int,z().split())
l=set(map(int,z().split()))
led=(6,2,5,5,4,5,6,3,7,6)
vowel={'a':0,'e':0,'i':0,'o':0,'u':0}
color4=["G", "GB", "YGB", "YGBI", "OYGBI" ,"OYGBIV",'ROYGBIV' ]
"""
###########################---START-CODING---###############################################
n=int(z())
t=n
if t%2==0:
print(2)
else:
print(1)
``` | output | 1 | 61,911 | 19 | 123,823 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.