text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 β€ q β€ 1000
* -10000 β€ xpi, ypi β€ 10000
* p0 β p1 and p2 β p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0
Submitted Solution:
```
n = int(input())
for i in range(n):
x0,y0,x1,y1,x2,y2,x3,y3 = map(float,input().split())
if x1 - x0 == 0:
if x3 -x2 == 0:
print('2')
elif y3 - y2 == 0:
print('1')
else:
print('0')
elif x3 - x2 == 0:
if y1 - y0 == 0:
print('1')
else:
print('0')
elif y1 - y0 == 0:
if y3 - y2 == 0:
print('2')
elif x3 - x2 == 0:
print('1')
else:
print('0')
else:
a1 = (y1-y0)/(x1-x0)
a2 = (y3-y2)/(x3-x2)
if a1 * a2 == -1:
print('1')
elif a1 == a2 or a1 == -a2:
print('2')
else:
print('0')
```
No
| 106,100 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations:
* min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$
* max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b < e \leq n$
Input
The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$com_1 \; b_1 \; e_1$
$com_2 \; b_2 \; e_2$
:
$com_{q} \; b_{q} \; e_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. 0 and 1 represents min($b, e$) and max($b, e$) respectively.
Output
For each query, print the minimum element or the maximum element in a line.
Example
Input
7
8 3 7 1 9 1 4
3
0 0 3
0 1 5
1 0 7
Output
3
1
9
"Correct Solution:
```
n = int(input())
A = [int(x) for x in input().split()]
q = int(input())
for i in range(q):
com, b, e = [int(x) for x in input().split()]
if com:
print(max(A[b:e]))
else:
print(min(A[b:e]))
```
| 106,101 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations:
* min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$
* max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b < e \leq n$
Input
The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$com_1 \; b_1 \; e_1$
$com_2 \; b_2 \; e_2$
:
$com_{q} \; b_{q} \; e_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. 0 and 1 represents min($b, e$) and max($b, e$) respectively.
Output
For each query, print the minimum element or the maximum element in a line.
Example
Input
7
8 3 7 1 9 1 4
3
0 0 3
0 1 5
1 0 7
Output
3
1
9
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Basic Operations - Min-Max Element
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_3_B&lang=jp
"""
n = int(input())
A = [int(a) for a in input().split()]
for _ in range(int(input())):
com, b, e = input().split()
if com == '0':
print(min(A[int(b):int(e)]))
else:
print(max(A[int(b):int(e)]))
```
| 106,102 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations:
* min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$
* max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b < e \leq n$
Input
The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$com_1 \; b_1 \; e_1$
$com_2 \; b_2 \; e_2$
:
$com_{q} \; b_{q} \; e_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. 0 and 1 represents min($b, e$) and max($b, e$) respectively.
Output
For each query, print the minimum element or the maximum element in a line.
Example
Input
7
8 3 7 1 9 1 4
3
0 0 3
0 1 5
1 0 7
Output
3
1
9
"Correct Solution:
```
n=int(input())
a=list(map(int,input().split( )))
q=int(input())
for i in range(q):
com,b,e=map(int,input().split( ))
if com==0:
mn=min(a[b:e])
print(mn)
else:
mx=max(a[b:e])
print(mx)
```
| 106,103 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations:
* min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$
* max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b < e \leq n$
Input
The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$com_1 \; b_1 \; e_1$
$com_2 \; b_2 \; e_2$
:
$com_{q} \; b_{q} \; e_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. 0 and 1 represents min($b, e$) and max($b, e$) respectively.
Output
For each query, print the minimum element or the maximum element in a line.
Example
Input
7
8 3 7 1 9 1 4
3
0 0 3
0 1 5
1 0 7
Output
3
1
9
"Correct Solution:
```
if __name__ == '__main__':
n = int(input())
A = list(map(int,input().split()))
n2 = int(input())
for i in range(n2):
com,b,e = map(int,input().split())
if com == 0:
print(min(A[b:e]))
else:
print(max(A[b:e]))
```
| 106,104 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations:
* min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$
* max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b < e \leq n$
Input
The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$com_1 \; b_1 \; e_1$
$com_2 \; b_2 \; e_2$
:
$com_{q} \; b_{q} \; e_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. 0 and 1 represents min($b, e$) and max($b, e$) respectively.
Output
For each query, print the minimum element or the maximum element in a line.
Example
Input
7
8 3 7 1 9 1 4
3
0 0 3
0 1 5
1 0 7
Output
3
1
9
"Correct Solution:
```
N = int(input())
X = list(map(int,input().split()))
q = int(input())
for i in range(q):
a = input().split()
t = int(a[1])
s = int(a[2])
if a[0] =="0":
print(min(X[t:s]))
elif a[0] == "1":
print(max(X[t:s]))
```
| 106,105 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations:
* min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$
* max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b < e \leq n$
Input
The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$com_1 \; b_1 \; e_1$
$com_2 \; b_2 \; e_2$
:
$com_{q} \; b_{q} \; e_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. 0 and 1 represents min($b, e$) and max($b, e$) respectively.
Output
For each query, print the minimum element or the maximum element in a line.
Example
Input
7
8 3 7 1 9 1 4
3
0 0 3
0 1 5
1 0 7
Output
3
1
9
"Correct Solution:
```
n = int(input())
A = list(map(int, input().split()))
q = int(input())
Q = list()
for i in range(q):
tmp = list(map(int, input().split()))
Q.append(tmp)
for query in Q:
if query[0] == 0:
print(min(A[query[1]:query[2]]))
else:
print(max(A[query[1]:query[2]]))
```
| 106,106 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations:
* min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$
* max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b < e \leq n$
Input
The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$com_1 \; b_1 \; e_1$
$com_2 \; b_2 \; e_2$
:
$com_{q} \; b_{q} \; e_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. 0 and 1 represents min($b, e$) and max($b, e$) respectively.
Output
For each query, print the minimum element or the maximum element in a line.
Example
Input
7
8 3 7 1 9 1 4
3
0 0 3
0 1 5
1 0 7
Output
3
1
9
"Correct Solution:
```
if __name__ == "__main__":
num_int = int(input())
numbers = list(map(lambda x: int(x), input().split()))
num_query = int(input())
for _ in range(num_query):
op, begin, end = map(lambda x: int(x), input().split())
sub_numbers = numbers[begin: end]
if (0 == op):
min_num = min(sub_numbers)
print(min_num)
elif (1 == op):
max_num = max(sub_numbers)
print(max_num)
```
| 106,107 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations:
* min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$
* max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b < e \leq n$
Input
The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$com_1 \; b_1 \; e_1$
$com_2 \; b_2 \; e_2$
:
$com_{q} \; b_{q} \; e_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. 0 and 1 represents min($b, e$) and max($b, e$) respectively.
Output
For each query, print the minimum element or the maximum element in a line.
Example
Input
7
8 3 7 1 9 1 4
3
0 0 3
0 1 5
1 0 7
Output
3
1
9
"Correct Solution:
```
input()
a = list(map(int, input().split()))
q = int(input())
for _ in range(q):
x, s, t = list(map(int, input().split()))
print(min(a[s:t]) if x==0 else max(a[s:t]))
```
| 106,108 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations:
* min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$
* max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b < e \leq n$
Input
The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$com_1 \; b_1 \; e_1$
$com_2 \; b_2 \; e_2$
:
$com_{q} \; b_{q} \; e_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. 0 and 1 represents min($b, e$) and max($b, e$) respectively.
Output
For each query, print the minimum element or the maximum element in a line.
Example
Input
7
8 3 7 1 9 1 4
3
0 0 3
0 1 5
1 0 7
Output
3
1
9
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split(" ")))
q=int(input())
for i in range(q):
c,b,e=map(int,input().split(" "))
if c:
print(max(a[b:e]))
else:
print(min(a[b:e]))
```
Yes
| 106,109 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations:
* min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$
* max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b < e \leq n$
Input
The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$com_1 \; b_1 \; e_1$
$com_2 \; b_2 \; e_2$
:
$com_{q} \; b_{q} \; e_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. 0 and 1 represents min($b, e$) and max($b, e$) respectively.
Output
For each query, print the minimum element or the maximum element in a line.
Example
Input
7
8 3 7 1 9 1 4
3
0 0 3
0 1 5
1 0 7
Output
3
1
9
Submitted Solution:
```
# coding=utf-8
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
qtype, b, e = map(int, input().split())
if qtype == 0:
print(min(A[b:e]))
elif qtype == 1:
print(max(A[b:e]))
```
Yes
| 106,110 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations:
* min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$
* max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b < e \leq n$
Input
The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$com_1 \; b_1 \; e_1$
$com_2 \; b_2 \; e_2$
:
$com_{q} \; b_{q} \; e_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. 0 and 1 represents min($b, e$) and max($b, e$) respectively.
Output
For each query, print the minimum element or the maximum element in a line.
Example
Input
7
8 3 7 1 9 1 4
3
0 0 3
0 1 5
1 0 7
Output
3
1
9
Submitted Solution:
```
def query(tree,begin,end,target,left,right,infinity,func):
if right <= begin or end <= left:
return infinity
if begin <= left and right <= end:
return tree[target]
next_position = (left + right) // 2
left_index = 2 * target + 1
right_index = left_index + 1
left_side_value = query(tree, begin, end, left_index, left, next_position, infinity, func)
right_side_value = query(tree, begin, end, right_index, next_position, right, infinity, func)
return func(left_side_value,right_side_value)
over_value = 2000000000
ary_size = int(input())
data_ary = list(map(int,input().split()))
leaf_size = 1
while leaf_size < ary_size:
leaf_size = leaf_size * 2
tree_size = leaf_size * 2 - 1
min_tree = [over_value] * tree_size
max_tree= [-over_value] * tree_size
for i in range(ary_size):
index = leaf_size - 1 + i
min_tree[index] = data_ary[i]
max_tree[index] = data_ary[i]
for i in range(leaf_size-2,-1,-1):
left_index = 2 * i + 1
right_index = left_index + 1
min_tree[i] = min(min_tree[left_index], min_tree[right_index])
max_tree[i] = max(max_tree[left_index], max_tree[right_index])
query_size = int(input())
for i in range(query_size):
input_data = list(map(int,input().split()))
command = input_data[0]
begin = input_data[1]
end = input_data[2]
if command == 0:
min_value = query(min_tree,begin,end,0,0,leaf_size,over_value,min)
print(min_value)
elif command == 1:
max_value = query(max_tree,begin,end,0,0,leaf_size,-over_value,max)
print(max_value)
```
Yes
| 106,111 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations:
* min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$
* max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b < e \leq n$
Input
The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$com_1 \; b_1 \; e_1$
$com_2 \; b_2 \; e_2$
:
$com_{q} \; b_{q} \; e_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. 0 and 1 represents min($b, e$) and max($b, e$) respectively.
Output
For each query, print the minimum element or the maximum element in a line.
Example
Input
7
8 3 7 1 9 1 4
3
0 0 3
0 1 5
1 0 7
Output
3
1
9
Submitted Solution:
```
def resolve():
input()
A = [int(i) for i in input().split()]
Q = int(input())
for _ in range(Q):
q = [int(i) for i in input().split()]
if q[0] == 0:
print(min(A[q[1]:q[2]]))
else:
print(max(A[q[1]:q[2]]))
resolve()
```
Yes
| 106,112 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations:
* min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$
* max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b < e \leq n$
Input
The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$com_1 \; b_1 \; e_1$
$com_2 \; b_2 \; e_2$
:
$com_{q} \; b_{q} \; e_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. 0 and 1 represents min($b, e$) and max($b, e$) respectively.
Output
For each query, print the minimum element or the maximum element in a line.
Example
Input
7
8 3 7 1 9 1 4
3
0 0 3
0 1 5
1 0 7
Output
3
1
9
Submitted Solution:
```
n = int(input())
nums = list(map(int, input().split(' ')))
q = int(input())
for i in range(q):
op = list(map(int, input().split(' ')))
if op[0] == 0:
min = float('inf')
for num in nums[op[1], op[2]]:
if num < min: min = num
print(min)
elif op[0] == 1:
max = -float('inf')
for num in nums[op[1], op[2]]:
if num < max: max = num
print(max)
```
No
| 106,113 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations:
* min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$
* max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b < e \leq n$
Input
The input is given in the following format.
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$com_1 \; b_1 \; e_1$
$com_2 \; b_2 \; e_2$
:
$com_{q} \; b_{q} \; e_{q}$
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. 0 and 1 represents min($b, e$) and max($b, e$) respectively.
Output
For each query, print the minimum element or the maximum element in a line.
Example
Input
7
8 3 7 1 9 1 4
3
0 0 3
0 1 5
1 0 7
Output
3
1
9
Submitted Solution:
```
n = int(input())
nums = list(map(int, input().split(' ')))
q = int(input())
for i in range(q):
op = list(map(int, input().split(' ')))
if op[0] == 0:
min = float('inf')
for num in nums[op[1]: op[2]]:
if num < min: min = num
print(min)
elif op[0] == 1:
max = -float('inf')
for num in nums[op[1]: op[2]]:
if num < max: max = num
print(max)
```
No
| 106,114 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:
* the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
* the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of numbers.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n). Furthermore, there are no pair of indices i β j such that a_i = a_j.
Output
Print s β a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".
Examples
Input
8
3 6 5 4 2 7 1 8
Output
BAAAABAB
Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
Output
ABAAAABBBAABAAB
Note
In the first sample, if Bob puts the token on the number (not position):
* 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
* 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
* 3: Alice can only move to 4, after which Bob wins by moving to 8.
* 4, 5, or 6: Alice wins by moving to 8.
* 7, 8: Alice has no move, and hence she loses immediately.
Tags: brute force, dp, games
Correct Solution:
```
n = int(input())
p = [int(x) for x in input().split()]
dp = ['B' for _ in range(n)]
idx = sorted([[p[i], i] for i in range(n)],reverse=True)
idx = [x[1] for x in idx]
for i in idx:
for j in range(1,n):
ind = i + j*p[i]
ind1 = i - j*p[i]
if (ind) >= n and ind1 < 0:
break
if ind < n and p[ind] > p[i] and dp[ind] == 'B' :
dp[i] = 'A'
break
if ind1 >= 0 and p[ind1] > p[i] and dp[ind1] == 'B':
dp[i] = 'A'
break
print("".join(dp))
```
| 106,115 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:
* the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
* the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of numbers.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n). Furthermore, there are no pair of indices i β j such that a_i = a_j.
Output
Print s β a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".
Examples
Input
8
3 6 5 4 2 7 1 8
Output
BAAAABAB
Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
Output
ABAAAABBBAABAAB
Note
In the first sample, if Bob puts the token on the number (not position):
* 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
* 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
* 3: Alice can only move to 4, after which Bob wins by moving to 8.
* 4, 5, or 6: Alice wins by moving to 8.
* 7, 8: Alice has no move, and hence she loses immediately.
Tags: brute force, dp, games
Correct Solution:
```
i=m=n=int(input())
a=[*map(int,input().split())]
s=[0]*n
r=[range(i%a[i],n,a[i])for i in range(n)]
while m:
i=(i-1)%n
if s[i]==0:
if all(a[j]<=a[i] or s[j]=='A'for j in r[i]):s[i]='B';m-=1
if any(a[j]>a[i] and s[j]=='B'for j in r[i]):s[i]='A';m-=1
print(''.join(s))
```
| 106,116 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:
* the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
* the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of numbers.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n). Furthermore, there are no pair of indices i β j such that a_i = a_j.
Output
Print s β a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".
Examples
Input
8
3 6 5 4 2 7 1 8
Output
BAAAABAB
Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
Output
ABAAAABBBAABAAB
Note
In the first sample, if Bob puts the token on the number (not position):
* 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
* 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
* 3: Alice can only move to 4, after which Bob wins by moving to 8.
* 4, 5, or 6: Alice wins by moving to 8.
* 7, 8: Alice has no move, and hence she loses immediately.
Tags: brute force, dp, games
Correct Solution:
```
R = lambda: map(int, input().split())
n = int(input())
a = list(R())
arr = sorted(([x, i] for i, x in enumerate(a)), reverse=True)
res = [-1] * n
for x, i in arr:
res[i] = 0 if any(res[j] == 1 for j in range(i + x, n, x) if a[j] > a[i]) or any(res[j] == 1 for j in range(i - x, -1, -x) if a[j] > a[i]) else 1
print(''.join('B' if x else 'A' for x in res))
```
| 106,117 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:
* the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
* the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of numbers.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n). Furthermore, there are no pair of indices i β j such that a_i = a_j.
Output
Print s β a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".
Examples
Input
8
3 6 5 4 2 7 1 8
Output
BAAAABAB
Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
Output
ABAAAABBBAABAAB
Note
In the first sample, if Bob puts the token on the number (not position):
* 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
* 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
* 3: Alice can only move to 4, after which Bob wins by moving to 8.
* 4, 5, or 6: Alice wins by moving to 8.
* 7, 8: Alice has no move, and hence she loses immediately.
Tags: brute force, dp, games
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
ans = [-1]*n
loc = {}
for i in range(n):
loc[a[i]] = i
for i in range(n):
if a[i]>i and a[i]>=n-i:
ans[i] = "B"
prev = 0
while ans.count(-1)!=prev:
prev = ans.count(-1)
for i in range(n):
if ans[i]==-1:
for j in range(i%a[i],n,a[i]):
if a[j]>a[i] and ans[j]=="B":
ans[i] = "A"
break
# print (ans)
while ans.count(-1)!=0:
for i in range(n):
if ans[i]==-1:
ans[i] = "B"
for j in range(i%a[i],n,a[i]):
if a[i]>=a[j]:
continue
if ans[j]=="B":
ans[i]="A"
break
elif ans[j]==-1:
ans[i] = -1
break
# print (ans)
for i in ans:
print (i,end="")
print ()
```
| 106,118 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:
* the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
* the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of numbers.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n). Furthermore, there are no pair of indices i β j such that a_i = a_j.
Output
Print s β a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".
Examples
Input
8
3 6 5 4 2 7 1 8
Output
BAAAABAB
Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
Output
ABAAAABBBAABAAB
Note
In the first sample, if Bob puts the token on the number (not position):
* 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
* 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
* 3: Alice can only move to 4, after which Bob wins by moving to 8.
* 4, 5, or 6: Alice wins by moving to 8.
* 7, 8: Alice has no move, and hence she loses immediately.
Tags: brute force, dp, games
Correct Solution:
```
def f(k):
if mem[k]!=-1:
return mem[k]
t=a[k]
ans="B"
for i in range(k,-1,-t):
if a[i]>t:
if f(i)=="B":
ans="A"
for i in range(k,n,t):
if a[i]>t:
if f(i)=="B":
ans="A"
mem[k]=ans
return ans
n=int(input())
a=list(map(int,input().split()))
mem=[-1]*n
for i in range(n):
f(i)
print("".join(mem))
```
| 106,119 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:
* the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
* the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of numbers.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n). Furthermore, there are no pair of indices i β j such that a_i = a_j.
Output
Print s β a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".
Examples
Input
8
3 6 5 4 2 7 1 8
Output
BAAAABAB
Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
Output
ABAAAABBBAABAAB
Note
In the first sample, if Bob puts the token on the number (not position):
* 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
* 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
* 3: Alice can only move to 4, after which Bob wins by moving to 8.
* 4, 5, or 6: Alice wins by moving to 8.
* 7, 8: Alice has no move, and hence she loses immediately.
Tags: brute force, dp, games
Correct Solution:
```
N = int(input())
a = list(map(int, input().split()))
rec = ["+"] * N
P = [0] * N
for i in range(N):
P[a[i] - 1] = i
for i in range(N, 0, -1):
j = P[i - 1]
rec[j] = "B"
for k in range(j % i, N, i):
if j != k and a[j] <= a[k] and rec[k] == "B":
rec[j] = "A"
break
print("".join(map(str, rec)))
```
| 106,120 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:
* the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
* the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of numbers.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n). Furthermore, there are no pair of indices i β j such that a_i = a_j.
Output
Print s β a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".
Examples
Input
8
3 6 5 4 2 7 1 8
Output
BAAAABAB
Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
Output
ABAAAABBBAABAAB
Note
In the first sample, if Bob puts the token on the number (not position):
* 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
* 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
* 3: Alice can only move to 4, after which Bob wins by moving to 8.
* 4, 5, or 6: Alice wins by moving to 8.
* 7, 8: Alice has no move, and hence she loses immediately.
Tags: brute force, dp, games
Correct Solution:
```
n=int(input())
a=[*map(int,input().split())]
s=[0]*n
t=set(range(n))
while t:
q=set()
for i in t:
x=a[i];r=range(i%x,n,x)
if all(a[j]<=x or s[j]=='A'for j in r):s[i]='B';q|={i}
if any(a[j]>x and s[j]=='B'for j in r):s[i]='A';q|={i}
t-=q
print(''.join(s))
```
| 106,121 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:
* the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
* the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of numbers.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n). Furthermore, there are no pair of indices i β j such that a_i = a_j.
Output
Print s β a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".
Examples
Input
8
3 6 5 4 2 7 1 8
Output
BAAAABAB
Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
Output
ABAAAABBBAABAAB
Note
In the first sample, if Bob puts the token on the number (not position):
* 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
* 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
* 3: Alice can only move to 4, after which Bob wins by moving to 8.
* 4, 5, or 6: Alice wins by moving to 8.
* 7, 8: Alice has no move, and hence she loses immediately.
Tags: brute force, dp, games
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 = list(map(int,input().split()))
ind = sorted(range(n),key=lambda xx:a[xx],reverse=1)
ans = [0]*n
for i in ind:
for j in range(i%a[i],n,a[i]):
if ans[j] == -1:
ans[i] = 1
break
else:
ans[i] = -1
for i in range(n):
ans[i] = 'A'if ans[i]==1 else 'B'
print(''.join(ans))
# 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()
```
| 106,122 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:
* the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
* the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of numbers.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n). Furthermore, there are no pair of indices i β j such that a_i = a_j.
Output
Print s β a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".
Examples
Input
8
3 6 5 4 2 7 1 8
Output
BAAAABAB
Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
Output
ABAAAABBBAABAAB
Note
In the first sample, if Bob puts the token on the number (not position):
* 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
* 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
* 3: Alice can only move to 4, after which Bob wins by moving to 8.
* 4, 5, or 6: Alice wins by moving to 8.
* 7, 8: Alice has no move, and hence she loses immediately.
Submitted Solution:
```
from sys import stdin
n=int(stdin.readline().strip())
s=list(map(int,stdin.readline().strip().split()))
dp=["B" for i in range(n)]
visited=[False for i in range(n)]
import sys
sys.setrecursionlimit(10**9)
def dfs(i):
x=s[i]
visited[i]=True
for j in range(i-x,-1,-x):
if s[j]>x:
if not visited[j]:
dfs(j)
if dp[j]=="B":
dp[i]="A"
return
for j in range(i+x,n,x):
if s[j]>x:
if not visited[j]:
dfs(j)
if dp[j]=="B":
dp[i]="A"
return
for i in range(n):
if not visited[i]:
dfs(i)
ans=""
for i in dp:
ans+=i
print(ans)
```
Yes
| 106,123 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:
* the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
* the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of numbers.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n). Furthermore, there are no pair of indices i β j such that a_i = a_j.
Output
Print s β a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".
Examples
Input
8
3 6 5 4 2 7 1 8
Output
BAAAABAB
Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
Output
ABAAAABBBAABAAB
Note
In the first sample, if Bob puts the token on the number (not position):
* 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
* 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
* 3: Alice can only move to 4, after which Bob wins by moving to 8.
* 4, 5, or 6: Alice wins by moving to 8.
* 7, 8: Alice has no move, and hence she loses immediately.
Submitted Solution:
```
i=m=n=int(input())
a=[*map(int,input().split())]
b=[0]*n
for i,x in enumerate(a):b[x-1]=i
s=[0]*n
while m:
i=(i-1)%n;k=b[i];x=a[k];r=range(k%x,n,x)
if s[k]==0:
if all(a[j]<=x or s[j]=='A'for j in r):s[k]='B';m-=1
if any(a[j]>x and s[j]=='B'for j in r):s[k]='A';m-=1
print(''.join(s))
```
Yes
| 106,124 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:
* the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
* the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of numbers.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n). Furthermore, there are no pair of indices i β j such that a_i = a_j.
Output
Print s β a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".
Examples
Input
8
3 6 5 4 2 7 1 8
Output
BAAAABAB
Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
Output
ABAAAABBBAABAAB
Note
In the first sample, if Bob puts the token on the number (not position):
* 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
* 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
* 3: Alice can only move to 4, after which Bob wins by moving to 8.
* 4, 5, or 6: Alice wins by moving to 8.
* 7, 8: Alice has no move, and hence she loses immediately.
Submitted Solution:
```
n = int(input())
arr = list(map(int, input().strip().split()))
dicti = {}
for i in range(n):
dicti[arr[i]] = i+1
ans = [-1 for i in range(n+1)]
if n > 1:
ans[dicti[1]] = 1
for i in range(n, 1, -1):
for j in range(dicti[i]%i-1, n, i):
# print(j, i)
if arr[j] > i:
if ans[j+1] == 0:
ans[dicti[i]] = 1
break
else:
ans[dicti[i]] = 0
print(''.join(['A' if i == 1 else 'B' for i in ans[1:]]))
```
Yes
| 106,125 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:
* the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
* the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of numbers.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n). Furthermore, there are no pair of indices i β j such that a_i = a_j.
Output
Print s β a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".
Examples
Input
8
3 6 5 4 2 7 1 8
Output
BAAAABAB
Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
Output
ABAAAABBBAABAAB
Note
In the first sample, if Bob puts the token on the number (not position):
* 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
* 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
* 3: Alice can only move to 4, after which Bob wins by moving to 8.
* 4, 5, or 6: Alice wins by moving to 8.
* 7, 8: Alice has no move, and hence she loses immediately.
Submitted Solution:
```
m=n=int(input())
a=[*map(int,input().split())]
s=[0]*n
i=0
while m:
x=a[i];r=range(i%x,n,x)
if s[i]==0:
if all(a[j]<=x or s[j]=='A'for j in r):s[i]='B';m-=1
if any(a[j]>x and s[j]=='B'for j in r):s[i]='A';m-=1
i=(i+1)%n
print(''.join(s))
```
Yes
| 106,126 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:
* the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
* the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of numbers.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n). Furthermore, there are no pair of indices i β j such that a_i = a_j.
Output
Print s β a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".
Examples
Input
8
3 6 5 4 2 7 1 8
Output
BAAAABAB
Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
Output
ABAAAABBBAABAAB
Note
In the first sample, if Bob puts the token on the number (not position):
* 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
* 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
* 3: Alice can only move to 4, after which Bob wins by moving to 8.
* 4, 5, or 6: Alice wins by moving to 8.
* 7, 8: Alice has no move, and hence she loses immediately.
Submitted Solution:
```
print(1)
```
No
| 106,127 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:
* the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
* the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of numbers.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n). Furthermore, there are no pair of indices i β j such that a_i = a_j.
Output
Print s β a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".
Examples
Input
8
3 6 5 4 2 7 1 8
Output
BAAAABAB
Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
Output
ABAAAABBBAABAAB
Note
In the first sample, if Bob puts the token on the number (not position):
* 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
* 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
* 3: Alice can only move to 4, after which Bob wins by moving to 8.
* 4, 5, or 6: Alice wins by moving to 8.
* 7, 8: Alice has no move, and hence she loses immediately.
Submitted Solution:
```
def f(k):
if mem[k]!=-1:
return mem[k]
t=a[k]
ans="B"
for i in range(k,-1,t):
if a[i]>t:
if f(i)=="B":
ans="A"
for i in range(k,n,t):
if a[i]>t:
if f(i)=="B":
ans="A"
mem[k]=ans
return ans
n=int(input())
a=list(map(int,input().split()))
mem=[-1]*n
for i in range(n):
f(i)
print("".join(mem))
```
No
| 106,128 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:
* the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
* the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of numbers.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n). Furthermore, there are no pair of indices i β j such that a_i = a_j.
Output
Print s β a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".
Examples
Input
8
3 6 5 4 2 7 1 8
Output
BAAAABAB
Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
Output
ABAAAABBBAABAAB
Note
In the first sample, if Bob puts the token on the number (not position):
* 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
* 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
* 3: Alice can only move to 4, after which Bob wins by moving to 8.
* 4, 5, or 6: Alice wins by moving to 8.
* 7, 8: Alice has no move, and hence she loses immediately.
Submitted Solution:
```
n = int(input())
l = [*map(int, input().split())]
adj = [[] for _ in range(n)]
for i in range(n):
for j in range(i % l[i], n, l[i]):
if l[j] > l[i] and i != j:
adj[l[i] - 1].append(j)
d = set()
for i in range(n - 1, -1, -1):
if all(j not in d for j in adj[i]):
d.add(i)
print(''.join('B' if e - 1 in d else 'A' for e in l))
```
No
| 106,129 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number.
A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell i to cell j only if the following two conditions are satisfied:
* the number in the new cell j must be strictly larger than the number in the old cell i (i.e. a_j > a_i), and
* the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. |i-j|mod a_i = 0).
Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of numbers.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n). Furthermore, there are no pair of indices i β j such that a_i = a_j.
Output
Print s β a string of n characters, where the i-th character represents the outcome of the game if the token is initially placed in the cell i. If Alice wins, then s_i has to be equal to "A"; otherwise, s_i has to be equal to "B".
Examples
Input
8
3 6 5 4 2 7 1 8
Output
BAAAABAB
Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
Output
ABAAAABBBAABAAB
Note
In the first sample, if Bob puts the token on the number (not position):
* 1: Alice can move to any number. She can win by picking 7, from which Bob has no move.
* 2: Alice can move to 3 and 5. Upon moving to 5, Bob can win by moving to 8. If she chooses 3 instead, she wins, as Bob has only a move to 4, from which Alice can move to 8.
* 3: Alice can only move to 4, after which Bob wins by moving to 8.
* 4, 5, or 6: Alice wins by moving to 8.
* 7, 8: Alice has no move, and hence she loses immediately.
Submitted Solution:
```
from collections import deque
from sys import stdin
lines = deque(line.strip() for line in stdin.readlines())
def nextline():
return lines.popleft()
def types(cast, sep=None):
return tuple(cast(x) for x in strs(sep=sep))
def ints(sep=None):
return types(int, sep=sep)
def strs(sep=None):
return tuple(nextline()) if sep == '' else tuple(nextline().split(sep=sep))
def main():
# lines will now contain all of the input's lines in a list
n = int(nextline())
a = ints()
pos = dict((v, k) for k, v in enumerate(a))
winners = {1: "A"}
bs = set()
for i in range(n, 1, -1):
winner = 'A' if any((pos[j] - pos[i]) % i == 0 for j in bs) else 'B'
if winner == 'B':
bs.add(i)
winners[i] = winner
print(''.join(winners[ai] for ai in a))
if __name__ == '__main__':
main()
```
No
| 106,130 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Tags: implementation
Correct Solution:
```
def read():
return set(list(map(int, input().split()))[1:])
n = int(input())
t = read()
for _ in range(n - 1):
t = t & read()
for x in t:
print(x, end=' ')
print()
```
| 106,131 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Tags: implementation
Correct Solution:
```
n=int(input())
a=[]
min_r=100
min_i=0
for i in range(n):
ta=list(map(int,input().split()))
r=ta[0]
a.append(ta[1:])
if(r<min_r):
min_r=r
min_i=i
#print(min_i)
for i in a[min_i]:
f=1
for j in range(n):
s=i in set(a[j])
if(s==False):
#print(j)
f=0
break
if(f):
print(i,end=' ')
```
| 106,132 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Tags: implementation
Correct Solution:
```
n = int(input())
d = {}
for i in range(n):
s = input().split()
for j in range(int(s[0])):
d[s[j+1]] = d.get(s[j+1],0)+1
ans = ""
for x in d:
if d[x] == n:
ans += str(x) + ' '
print(ans.strip())
```
| 106,133 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Tags: implementation
Correct Solution:
```
n = int(input())
arr = []
for i in range(n):
arr.append(set([int(i) for i in input().split()][1:]))
x = arr[0]&arr[1]
for i in range(2,len(arr)):
x &= arr[i]
print(*x)
```
| 106,134 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Tags: implementation
Correct Solution:
```
# -*- coding: utf-8 -*-
N = int(input())
for i in range(N):
lines = list(map(str, input().split()))
lines = lines[1:]
if i == 0:
res = set(lines)
else:
res &= set(lines)
print(' '.join(res))
```
| 106,135 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Tags: implementation
Correct Solution:
```
def main():
from sys import stdin, stdout
input = stdin.readline
print = stdout.write
n = int(input())
a = [0 for i in range(100)]
for i in range(n):
for e in map(int, input().split()[1:]):
a[e-1] += 1
for i, e in enumerate(a):
if e == n:
print(str(i+1) + " ")
if __name__ == '__main__':
main()
```
| 106,136 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Tags: implementation
Correct Solution:
```
n = int(input())
line = list(map(int, input().split()))
r = line[0]
variants = set(line[1:])
for i in range(1, n):
line = list(map(int, input().split()))
r = line[0]
var = set(line[1:])
variants.intersection_update(var)
for v in variants:
print(v, end=' ')
```
| 106,137 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Tags: implementation
Correct Solution:
```
n = int(input())
res = {i for i in range(1, 101)}
for _ in range(n):
res &= set(map(int, input().split()[1:]))
print(*res)
```
| 106,138 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Submitted Solution:
```
n = int(input())
cnt = [0] * 101
for x in range(n):
lst = [int(y) for y in input().split()]
for i in range(1, len(lst)):
cnt[lst[i]] += 1
for x in range(1, 101):
if cnt[x] == n:
print(x, end = ' ')
```
Yes
| 106,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Submitted Solution:
```
n = int(input())
s = set()
for i in range(n):
x = list(map(int, input().split()))
tmp = set()
for r in x[1:]:
tmp.add(r)
if len(s) == 0:
s = tmp
else:
s = s.intersection(tmp)
if len(s) == 0:
exit()
print(*s)
```
Yes
| 106,140 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Submitted Solution:
```
n=int(input())
ans=[ ]
for i in range(n):
ar=tuple(map(int,input().split()))
ans.append(set(ar[1:]))
ans=set.intersection(*ans)
print(*ans)
```
Yes
| 106,141 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Submitted Solution:
```
n = int(input())
s = set()
for _ in range(n):
if s:
m = set(list(map(int,input().split()))[1:])
s = s.intersection(m)
else:
s = set(list(map(int,input().split()))[1:])
print(*s)
```
Yes
| 106,142 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Submitted Solution:
```
def arkadyi(n, lst):
b = list()
a = [item for sublist in lst for item in sublist]
for elem in a:
if a.count(elem) == 3:
b.append(elem)
return set(b)
N = int(input())
b = list()
for j in range(N):
s = [int(x) for x in input().split()]
b.append(s[1:])
print(*arkadyi(N, b))
```
No
| 106,143 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Submitted Solution:
```
def prog():
from sys import stdin
n = int(stdin.readline())
s = set(map(int,stdin.readline().split()))
for i in range(n-1):
d = set(map(int,stdin.readline().split()))
s = s&d
print(*s)
prog()
```
No
| 106,144 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Submitted Solution:
```
r = int(input())
trains = []
res = []
stringRes = ""
for i in range(r):
lines = input().split(" ")
trains.append(lines)
exist = trains[0]
for i in range(1,len(trains)):
for j in range(len(trains[i])):
if trains[i][j] in exist:
res.append(trains[i][j])
if len(res) == 0:
res = trains[0]
for i in res:
stringRes = stringRes + i + " "
print(stringRes)
```
No
| 106,145 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.
During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?
Input
The first line contains a single integer n (2 β€ n β€ 100) β the number of stops Arkady saw.
The next n lines describe the stops. Each of them starts with a single integer r (1 β€ r β€ 100) β the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, β the line numbers. They can be in arbitrary order.
It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.
Output
Print all tram lines that Arkady could be in, in arbitrary order.
Examples
Input
3
3 1 4 6
2 1 4
5 10 5 6 4 1
Output
1 4
Input
5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3
Output
1
Note
Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.
Submitted Solution:
```
n=int(input())
s=set(input().split())
for i in range(n-1):
s1=set(input().split())
s=s & s1
print(*list(s))
```
No
| 106,146 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a set of n weights. You know that their masses are a_1, a_2, ..., a_n grams, but you don't know which of them has which mass. You can't distinguish the weights.
However, your friend does know the mass of each weight. You can ask your friend to give you exactly k weights with the total mass m (both parameters k and m are chosen by you), and your friend will point to any valid subset of weights, if it is possible.
You are allowed to make this query only once. Find the maximum possible number of weights you can reveal after this query.
Input
The first line contains a single integer n (1 β€ n β€ 100) β the number of weights.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 100) β the masses of the weights.
Output
Print the maximum number of weights you can learn the masses for after making a single query.
Examples
Input
4
1 4 2 2
Output
2
Input
6
1 2 4 4 4 9
Output
2
Note
In the first example we can ask for a subset of two weights with total mass being equal to 4, and the only option is to get \{2, 2\}.
Another way to obtain the same result is to ask for a subset of two weights with the total mass of 5 and get \{1, 4\}. It is easy to see that the two remaining weights have mass of 2 grams each.
In the second example we can ask for a subset of two weights with total mass being 8, and the only answer is \{4, 4\}. We can prove it is not possible to learn masses for three weights in one query, but we won't put the proof here.
Tags: dp, math
Correct Solution:
```
from collections import defaultdict
def calcBinomials(N):
global binom
N += 1
binom = [[0]*N for _ in range(N)]
for n in range(N):
binom[n][0] = binom[n][n] = 1
for k in range(1, n):
binom[n][k] = binom[n-1][k] + binom[n-1][k-1]
n = int(input())
a = list(map(int, input().split()))
S, res = sum(a), 0
dp = [defaultdict(lambda: 0) for _ in range(S+1)]
dp[0][0] = 1
cnt = {_:a.count(_) for _ in a}
for x in a:
for i in range(len(dp)-1-x, -1, -1):
for k, v in dp[i].items():
dp[i+x][k+1] += v
calcBinomials(n)
for x, c in cnt.items():
for i in range(1, c+1):
if dp[x*i][i] == binom[c][i] or dp[S - x*i][n-i] == binom[c][c-i]:
res = max(res, i)
if len(cnt) <= 2: res = n
print(res)
```
| 106,147 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a set of n weights. You know that their masses are a_1, a_2, ..., a_n grams, but you don't know which of them has which mass. You can't distinguish the weights.
However, your friend does know the mass of each weight. You can ask your friend to give you exactly k weights with the total mass m (both parameters k and m are chosen by you), and your friend will point to any valid subset of weights, if it is possible.
You are allowed to make this query only once. Find the maximum possible number of weights you can reveal after this query.
Input
The first line contains a single integer n (1 β€ n β€ 100) β the number of weights.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 100) β the masses of the weights.
Output
Print the maximum number of weights you can learn the masses for after making a single query.
Examples
Input
4
1 4 2 2
Output
2
Input
6
1 2 4 4 4 9
Output
2
Note
In the first example we can ask for a subset of two weights with total mass being equal to 4, and the only option is to get \{2, 2\}.
Another way to obtain the same result is to ask for a subset of two weights with the total mass of 5 and get \{1, 4\}. It is easy to see that the two remaining weights have mass of 2 grams each.
In the second example we can ask for a subset of two weights with total mass being 8, and the only answer is \{4, 4\}. We can prove it is not possible to learn masses for three weights in one query, but we won't put the proof here.
Submitted Solution:
```
n = int(input())
geers = [int(x) for x in input().split()]
if len(set(geers)) <= 2:
print(n)
else:
print(2)
```
No
| 106,148 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a set of n weights. You know that their masses are a_1, a_2, ..., a_n grams, but you don't know which of them has which mass. You can't distinguish the weights.
However, your friend does know the mass of each weight. You can ask your friend to give you exactly k weights with the total mass m (both parameters k and m are chosen by you), and your friend will point to any valid subset of weights, if it is possible.
You are allowed to make this query only once. Find the maximum possible number of weights you can reveal after this query.
Input
The first line contains a single integer n (1 β€ n β€ 100) β the number of weights.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 100) β the masses of the weights.
Output
Print the maximum number of weights you can learn the masses for after making a single query.
Examples
Input
4
1 4 2 2
Output
2
Input
6
1 2 4 4 4 9
Output
2
Note
In the first example we can ask for a subset of two weights with total mass being equal to 4, and the only option is to get \{2, 2\}.
Another way to obtain the same result is to ask for a subset of two weights with the total mass of 5 and get \{1, 4\}. It is easy to see that the two remaining weights have mass of 2 grams each.
In the second example we can ask for a subset of two weights with total mass being 8, and the only answer is \{4, 4\}. We can prove it is not possible to learn masses for three weights in one query, but we won't put the proof here.
Submitted Solution:
```
from sys import stdin,stdout
import copy
from collections import Counter
n=int(stdin.readline())
arr=list(map(int,stdin.readline().strip().split(' ')))
temp=Counter(arr)
if len(temp)<=2:
stdout.write(str(len(arr)))
else:
m=sum(arr)
np=[True for i in range(m+1)]
pna=[False for i in range(m+1)]
pc=[{} for i in range(m+1)]
for ele in arr:
npc=copy.deepcopy(np)
pnac=copy.deepcopy(pna)
pcc=copy.deepcopy(pc)
# print(ele,"START")
# print(np)
# print(pc)
# print(pna)
for i in range(m+1):
if i==ele:
if npc[i]==True:
npc[i]=False
pcc[i][ele]=1
else:
if pnac[i]:
pnac[i+ele]=True
npc[i+ele]=False
for k in pc[i]:
npc[i+ele]=False
if k==ele:
pcc[i+ele][ele]=pcc[i][ele]+1
else:
pnac[i+ele]=True
continue
if npc[i]:
continue
else:
if pna[i]:
pnac[i+ele]=True
for k in pc[i]:
npc[i+ele]=False
if k==ele:
pcc[i+ele][ele]=pcc[i][ele]+1
else:
pnac[i+ele]=True
np=npc
pc=pcc
pna=pnac
# print(ele,"END")
# print(np)
# print(pc)
# print(pna)
ans=-1
for i in range(m+1):
if not pna[i]:
for j in pc[i]:
ans=max(ans,pc[i][j])
stdout.write(str(ans))
# 4
# 1 4 2 2
```
No
| 106,149 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a set of n weights. You know that their masses are a_1, a_2, ..., a_n grams, but you don't know which of them has which mass. You can't distinguish the weights.
However, your friend does know the mass of each weight. You can ask your friend to give you exactly k weights with the total mass m (both parameters k and m are chosen by you), and your friend will point to any valid subset of weights, if it is possible.
You are allowed to make this query only once. Find the maximum possible number of weights you can reveal after this query.
Input
The first line contains a single integer n (1 β€ n β€ 100) β the number of weights.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 100) β the masses of the weights.
Output
Print the maximum number of weights you can learn the masses for after making a single query.
Examples
Input
4
1 4 2 2
Output
2
Input
6
1 2 4 4 4 9
Output
2
Note
In the first example we can ask for a subset of two weights with total mass being equal to 4, and the only option is to get \{2, 2\}.
Another way to obtain the same result is to ask for a subset of two weights with the total mass of 5 and get \{1, 4\}. It is easy to see that the two remaining weights have mass of 2 grams each.
In the second example we can ask for a subset of two weights with total mass being 8, and the only answer is \{4, 4\}. We can prove it is not possible to learn masses for three weights in one query, but we won't put the proof here.
Submitted Solution:
```
from collections import defaultdict
def calcBinomials(N):
global binom
binom = [[0]*N for _ in range(N+1)]
for n in range(N):
binom[n][0] = binom[n][n] = 1
for k in range(1, n):
binom[n][k] = binom[n-1][k] + binom[n-1][k-1]
n = int(input())
a = list(map(int, input().split()))
S, res = sum(a), 0
dp = [defaultdict(lambda: 0) for _ in range(S+1)]
dp[0][0] = 1
cnt = {_:a.count(_) for _ in a}
for x in a:
for i in range(len(dp)-1-x, -1, -1):
for k, v in dp[i].items():
dp[i+x][k+1] += v
calcBinomials(n)
for x, c in cnt.items():
for i in range(1, c+1):
if dp[x*i][i] == binom[c][i] or dp[S - x*i][n-i] == binom[c][c-i]:
res = max(res, i)
print(res)
```
No
| 106,150 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a set of n weights. You know that their masses are a_1, a_2, ..., a_n grams, but you don't know which of them has which mass. You can't distinguish the weights.
However, your friend does know the mass of each weight. You can ask your friend to give you exactly k weights with the total mass m (both parameters k and m are chosen by you), and your friend will point to any valid subset of weights, if it is possible.
You are allowed to make this query only once. Find the maximum possible number of weights you can reveal after this query.
Input
The first line contains a single integer n (1 β€ n β€ 100) β the number of weights.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 100) β the masses of the weights.
Output
Print the maximum number of weights you can learn the masses for after making a single query.
Examples
Input
4
1 4 2 2
Output
2
Input
6
1 2 4 4 4 9
Output
2
Note
In the first example we can ask for a subset of two weights with total mass being equal to 4, and the only option is to get \{2, 2\}.
Another way to obtain the same result is to ask for a subset of two weights with the total mass of 5 and get \{1, 4\}. It is easy to see that the two remaining weights have mass of 2 grams each.
In the second example we can ask for a subset of two weights with total mass being 8, and the only answer is \{4, 4\}. We can prove it is not possible to learn masses for three weights in one query, but we won't put the proof here.
Submitted Solution:
```
n = int(input())
num = n
a = input().split()
up = []
for i in range(n):
a[i] = int(a[i])
for i in range(n):
k = a.count(a[i])
up.append(k)
l1 = []
l2 = []
for i in range(n):
if up[i] == 1:
l1.append(a[i])
else:
l2.append(a[i])
if sum(l1) != sum(l2):
ans = len(l1)
else:
ch = []
for i in range(len(l1)):
ch.append(0)
while len(l2) > 1:
l = []
l1.append(l2[0])
del(l2[0])
n = len(ch)
while ch[0] != 2:
for i in range(n - 1, 0, -1):
if ch[i] == 2:
ch[i] = 0
ch[i - 1] += 1
if sum(ch) < 2:
ch[n - 1] += 1
continue
s = 0
for i in range(n):
if ch[i] == 1:
s += l1[i]
if s != 0:
l.append(s)
ch[n - 1] += 1
flag = True
for i in range(len(l1)):
if l[i] == sum(l2):
flag = False
if flag == True:
ans = len(l2)
break
del(ch[0])
if ans == num:
ans = 1
print(ans)
```
No
| 106,151 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 β€ n β€ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
Tags: binary search, constructive algorithms, math
Correct Solution:
```
ans=10**9
n=int(input())
i=1
while i*i<=n:
ans=min(ans, i+(n-1)//i+1)
i+=1
print(ans)
```
| 106,152 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 β€ n β€ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
Tags: binary search, constructive algorithms, math
Correct Solution:
```
from math import sqrt
n = int(input())
l = 1
r = 1
while (l+r)/2 < sqrt(n) :
if (l+r) % 2 == 0:
r+=1
else:
l+=1
print(r+l)
```
| 106,153 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 β€ n β€ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
Tags: binary search, constructive algorithms, math
Correct Solution:
```
import math
a = int(input())
lb = int(math.sqrt(a))
if lb == math.sqrt(a):
print(lb * 2)
else:
if lb + (lb*lb) >= a:
print((lb * 2) + 1 )
else:
print((lb * 2) + 2 )
```
| 106,154 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 β€ n β€ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
Tags: binary search, constructive algorithms, math
Correct Solution:
```
import math
n=int(input())
val=int(math.sqrt(n))
if val*val==n:
print(2*val)
elif n-(val*val)<=val:
print(1+(2*val))
else:
print(2+(2*val))
```
| 106,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 β€ n β€ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
Tags: binary search, constructive algorithms, math
Correct Solution:
```
import math
def main():
n = int(input())
print(int(math.ceil(math.sqrt(n) * 2)))
if __name__ == "__main__":
main()
```
| 106,156 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 β€ n β€ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
Tags: binary search, constructive algorithms, math
Correct Solution:
```
n=int(input())
for i in range(1, 40000):
if i*i>=n:
x=i
break
print(n//x+i+int(n%x>0))
```
| 106,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 β€ n β€ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
Tags: binary search, constructive algorithms, math
Correct Solution:
```
import math
n = int(input())
q = math.sqrt(n)
if q == int(q):
q = int(q)
print(2 * q)
elif q - int(q) >= 0.5:
q = int(q) + 1
print(2 * q)
else:
q = int(q)
print(2 * q + 1)
```
| 106,158 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 β€ n β€ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
Tags: binary search, constructive algorithms, math
Correct Solution:
```
n=int(input())
from math import ceil
def res(n): return ceil(2*n**0.5)
print(res(n))
```
| 106,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 β€ n β€ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
Submitted Solution:
```
print(1 + int((4 * int(input()) - 3) ** 0.5))
```
Yes
| 106,160 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 β€ n β€ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
Submitted Solution:
```
n = int(input())
i = int(n**0.5)
if i**2 == n:
print(2*i)
elif (i+1)*i>=n:
print(2*i+1)
else:
print(2*i+2)
```
Yes
| 106,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 β€ n β€ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
Submitted Solution:
```
from math import sqrt
n = int(input())
q = int(sqrt(n))
rest = n - (q*q)
k = rest // q
if rest%q != 0:
k+=1
print(q*2 + k)
```
Yes
| 106,162 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 β€ n β€ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
Submitted Solution:
```
n = int(input())
n2 = n ** 0.5
if n2 != int(n2):
n2 = int(n2) + 1
if (n2 - 1) * n2 >= n:
cuts = n2 * 2 - 1
else:
cuts = n2 * 2
else:
cuts = int(n2 * 2)
print(cuts)
```
Yes
| 106,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 β€ n β€ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
Submitted Solution:
```
n=int(input())
print(int((2*(n**0.5))))
```
No
| 106,164 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 β€ n β€ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 13 20:48:59 2018
@author:
"""
"""
A = list(map(int, input().split()))
print(A)
"""
n=int(input())
s=2+n//2
print(s)
```
No
| 106,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 β€ n β€ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
Submitted Solution:
```
n=int(input())
if n==1:
print(2)
elif n==2:
print(3)
elif n==3:
print(4)
elif n%2==0:
print(int(n/2)+2)
else:
print(int(n/2)+3)
```
No
| 106,166 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 β€ n β€ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4
Submitted Solution:
```
from math import sqrt, floor, ceil
a = int(input())
b = floor(sqrt(a))
c = a - b**2
print(2*b+ceil(c/2))
```
No
| 106,167 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Examples
Input
5 15 15
Output
4
4
1
1
2
Input
2 3 2
Output
-1
Input
1 99 11
Output
11
Tags: greedy
Correct Solution:
```
n,x,y=map(int,input().split())
if(y<n):
print(-1)
elif((y-n+1)**2+(n-1)>=x):
print(y-n+1)
for i in range(n-1):
print(1)
else:
print(-1)
```
| 106,168 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Examples
Input
5 15 15
Output
4
4
1
1
2
Input
2 3 2
Output
-1
Input
1 99 11
Output
11
Tags: greedy
Correct Solution:
```
n, x, y = map(int, input().split(' '))
if (y < n):
print(-1)
quit()
ones = n - 1
left = (y-n+1)**2 + ones
if left < x:
print(-1)
else:
for i in range(n-1):
print(1)
print(y-n+1)
```
| 106,169 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Examples
Input
5 15 15
Output
4
4
1
1
2
Input
2 3 2
Output
-1
Input
1 99 11
Output
11
Tags: greedy
Correct Solution:
```
import sys
n,x,y=map(int,sys.stdin.readline().split())
if (y-n+1<1) or (y-n+1)**2+(n-1)<x:
print(-1)
else:
print(y-n+1)
for i in range(n-1):
print(1)
```
| 106,170 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Examples
Input
5 15 15
Output
4
4
1
1
2
Input
2 3 2
Output
-1
Input
1 99 11
Output
11
Tags: greedy
Correct Solution:
```
n, x, y = map(int, input().split(' '))
if(y < n):
print(-1)
else:
val = (y - n + 1)**2 + (n-1)
if(val < x):
print(-1)
else:
for i in range(n-1):
print(1)
print(y - n + 1)
```
| 106,171 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Examples
Input
5 15 15
Output
4
4
1
1
2
Input
2 3 2
Output
-1
Input
1 99 11
Output
11
Tags: greedy
Correct Solution:
```
from math import ceil, sqrt
x,y,z = map(int, input().split())
t = x-1
if x > z:
print(-1)
elif y >= z and t + (ceil(sqrt(y -t)) ** 2) >= y and t + ceil(sqrt(y -t)) <= z:
k = ceil(sqrt(y-t))
for c in range(x-1):
print(1)
print(k)
elif z >= y and t + (ceil(sqrt(z - t)) ** 2) >= y and t + ceil(sqrt(z - t)) <= z:
k = ceil(sqrt(z-t))
for c in range(x-1):
print(1)
print(k)
else:
print(-1)
#
```
| 106,172 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Examples
Input
5 15 15
Output
4
4
1
1
2
Input
2 3 2
Output
-1
Input
1 99 11
Output
11
Tags: greedy
Correct Solution:
```
n, x, y = map(int, input().split())
if n > y:
print(-1)
else:
left = y - n
left += 1
if left ** 2 + n - 1 >= x:
print(left)
for _ in range(n - 1):
print(1)
else:
print(-1)
```
| 106,173 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Examples
Input
5 15 15
Output
4
4
1
1
2
Input
2 3 2
Output
-1
Input
1 99 11
Output
11
Tags: greedy
Correct Solution:
```
n,x,y=map(int,input().split())
n-=1
t=y-n
print(['1\n'*n+str(t),-1][t<1 or t*t+n<x])
# Made By Mostafa_Khaled
```
| 106,174 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Examples
Input
5 15 15
Output
4
4
1
1
2
Input
2 3 2
Output
-1
Input
1 99 11
Output
11
Tags: greedy
Correct Solution:
```
n, x, y = map(int, input().split())
curr = y - n + 1
if curr <= 0:
print(-1)
else:
if curr ** 2 + (n - 1) < x:
print(-1)
else:
for i in range(n-1):
print(1)
print(y - n + 1)
```
| 106,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Examples
Input
5 15 15
Output
4
4
1
1
2
Input
2 3 2
Output
-1
Input
1 99 11
Output
11
Submitted Solution:
```
n,x,y=[int(p) for p in input().split()]
if n>y or (y-n+1)**2 + n - 1<x:
print(-1)
else:
for i in range(n):
print((y-n+1)*(i==0)+(i!=0))
```
Yes
| 106,176 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Examples
Input
5 15 15
Output
4
4
1
1
2
Input
2 3 2
Output
-1
Input
1 99 11
Output
11
Submitted Solution:
```
n,x,y=list(map(int,input().split()))
if (y-n+1)>0 and x<=(y-n+1)**2+(n-1):
for i in range(n-1): print(1)
print(y-n+1)
else:print(-1)
```
Yes
| 106,177 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Examples
Input
5 15 15
Output
4
4
1
1
2
Input
2 3 2
Output
-1
Input
1 99 11
Output
11
Submitted Solution:
```
p=input().rstrip().split(' ')
n=int(p[0])
x=int(p[1])
y=int(p[2])
if n<=y:
A=y-(n-1);
B=(A*A)+(n-1)
if B<x:
print(-1)
else:
print(A)
for i in range(0,n-1):
print(1)
else:
print(-1)
```
Yes
| 106,178 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Examples
Input
5 15 15
Output
4
4
1
1
2
Input
2 3 2
Output
-1
Input
1 99 11
Output
11
Submitted Solution:
```
n,x,y = map(int,input().split())
t=[]
for k in range(n-1):
t.append(1)
s = y-(n-1)
if s>0:
if n-1+(s)**2>=x:
for si in t:
print(si)
print(s)
else:print(-1)
else:
print(-1)
```
Yes
| 106,179 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Examples
Input
5 15 15
Output
4
4
1
1
2
Input
2 3 2
Output
-1
Input
1 99 11
Output
11
Submitted Solution:
```
n,x,y=map(int,input().split())
import math
an=x-(n-1)
if(an<=0):
print(-1)
exit()
else:
me=math.sqrt(an)
if(me==int(me)):
me=int(me)
if(n-1+me<=y):
for i in range(n-1):
print(1)
print(me)
exit()
else:
print(-1)
exit()
else:
me=int(me)
me+=1
if(n-1+me<=y):
for i in range(n-1):
print(1)
print(me)
exit()
else:
print(-1)
exit()
```
No
| 106,180 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Examples
Input
5 15 15
Output
4
4
1
1
2
Input
2 3 2
Output
-1
Input
1 99 11
Output
11
Submitted Solution:
```
n,x,y =map(int,input().split())
xx = int(x**.5)
if x>=y :
if xx*xx + (n-1)>=x and xx + n-1<=y :
print(xx)
for i in range(n-1):
print(1)
elif (xx*xx)*2 + (n-2)>=x and 2*xx +n-2<=y :
print(xx)
print(xx)
for i in range(n-2):
print(1)
elif (xx+1)*(xx+1) + (n-1)>=x and (xx+1) +n-1<=y :
print(xx+1)
for i in range(n-1):
print(1)
elif ((xx+1)**2)*2 +n-2 >=x and 2*(xx+1)+n-2<=y:
print(xx+1)
print(xx+1)
for i in range(n-2):
print(1)
else:
print(-1)
else:
ans=[]
for i in range(y-n+1,-1,-1) :
if i**2 + n-1 >=x :
ans.append(i)
break
if len(ans)==0:
print(-1)
else:
print(ans[0])
for i in range(n-1):
print(1)
```
No
| 106,181 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Examples
Input
5 15 15
Output
4
4
1
1
2
Input
2 3 2
Output
-1
Input
1 99 11
Output
11
Submitted Solution:
```
import sys
n,x,y=map(int,sys.stdin.readline().split())
if (y-n+1<0) or (y-n+1)**2+(n-1)<x:
print(-1)
else:
print(y-n+1)
for i in range(n-1):
print(1)
```
No
| 106,182 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied:
* a12 + a22 + ... + an2 β₯ x
* a1 + a2 + ... + an β€ y
Input
The first line contains three space-separated integers n, x and y (1 β€ n β€ 105, 1 β€ x β€ 1012, 1 β€ y β€ 106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator.
Output
Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
Examples
Input
5 15 15
Output
4
4
1
1
2
Input
2 3 2
Output
-1
Input
1 99 11
Output
11
Submitted Solution:
```
import sys
n,x,y=map(int,sys.stdin.readline().split())
if (y-n+1)**2+(n-1)<x:
print(-1)
else:
print(y-n+1)
for i in range(n-1):
print(1)
```
No
| 106,183 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a_1, a_2, ..., a_n. All a_i are pairwise distinct.
Let's define function f(l, r) as follows:
* let's define array b_1, b_2, ..., b_{r - l + 1}, where b_i = a_{l - 1 + i};
* sort array b in increasing order;
* result of the function f(l, r) is β_{i = 1}^{r - l + 1}{b_i β
i}.
Calculate \left(β_{1 β€ l β€ r β€ n}{f(l, r)}\right) mod (10^9+7), i.e. total sum of f for all subsegments of a modulo 10^9+7.
Input
The first line contains one integer n (1 β€ n β€ 5 β
10^5) β the length of array a.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9, a_i β a_j for i β j) β array a.
Output
Print one integer β the total sum of f for all subsegments of a modulo 10^9+7
Examples
Input
4
5 2 4 7
Output
167
Input
3
123456789 214365879 987654321
Output
582491518
Note
Description of the first example:
* f(1, 1) = 5 β
1 = 5;
* f(1, 2) = 2 β
1 + 5 β
2 = 12;
* f(1, 3) = 2 β
1 + 4 β
2 + 5 β
3 = 25;
* f(1, 4) = 2 β
1 + 4 β
2 + 5 β
3 + 7 β
4 = 53;
* f(2, 2) = 2 β
1 = 2;
* f(2, 3) = 2 β
1 + 4 β
2 = 10;
* f(2, 4) = 2 β
1 + 4 β
2 + 7 β
3 = 31;
* f(3, 3) = 4 β
1 = 4;
* f(3, 4) = 4 β
1 + 7 β
2 = 18;
* f(4, 4) = 7 β
1 = 7;
Tags: combinatorics, data structures, math, sortings
Correct Solution:
```
import sys
MOD = (int)(1e9+7)
def add(a, b):
a += b
if a >= MOD: a -= MOD
return a
def mul(a, b):
return (a * b) % MOD
class fenwickTree:
def __init__(self, max_val):
self.max_val = max_val + 5
self.tree = [0] * self.max_val
def update(self, idx, value):
idx += 1
while idx < self.max_val:
self.tree[idx] = add(self.tree[idx], value)
idx += (idx & (-idx))
def read(self, idx):
idx += 1
res = 0
while idx > 0:
res = add(res, self.tree[idx])
idx -= (idx & (-idx))
return res
inp = [int(x) for x in sys.stdin.read().split()]
n = inp[0]
a = []
for i in range(1, n + 1):
a.append(inp[i])
sorted_array = sorted(a)
dict = {}
for i in range(n):
dict[sorted_array[i]] = i
factor = [0] * n
for i in range(0, n):
factor[i] = mul(i + 1, n - i)
left_tree = fenwickTree(n)
for i in range(0, n):
element_idx = dict[a[i]]
factor[i] = add(factor[i], mul(n - i, left_tree.read(element_idx)))
left_tree.update(element_idx, i + 1)
right_tree = fenwickTree(n)
for i in range(n - 1, -1, -1):
element_idx = dict[a[i]]
factor[i] = add(factor[i], mul(i + 1, right_tree.read(element_idx)))
right_tree.update(element_idx, n - i)
ans = 0
for i in range(n):
ans = add(ans, mul(a[i], factor[i]))
print(ans)
```
| 106,184 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, ..., a_n. All a_i are pairwise distinct.
Let's define function f(l, r) as follows:
* let's define array b_1, b_2, ..., b_{r - l + 1}, where b_i = a_{l - 1 + i};
* sort array b in increasing order;
* result of the function f(l, r) is β_{i = 1}^{r - l + 1}{b_i β
i}.
Calculate \left(β_{1 β€ l β€ r β€ n}{f(l, r)}\right) mod (10^9+7), i.e. total sum of f for all subsegments of a modulo 10^9+7.
Input
The first line contains one integer n (1 β€ n β€ 5 β
10^5) β the length of array a.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9, a_i β a_j for i β j) β array a.
Output
Print one integer β the total sum of f for all subsegments of a modulo 10^9+7
Examples
Input
4
5 2 4 7
Output
167
Input
3
123456789 214365879 987654321
Output
582491518
Note
Description of the first example:
* f(1, 1) = 5 β
1 = 5;
* f(1, 2) = 2 β
1 + 5 β
2 = 12;
* f(1, 3) = 2 β
1 + 4 β
2 + 5 β
3 = 25;
* f(1, 4) = 2 β
1 + 4 β
2 + 5 β
3 + 7 β
4 = 53;
* f(2, 2) = 2 β
1 = 2;
* f(2, 3) = 2 β
1 + 4 β
2 = 10;
* f(2, 4) = 2 β
1 + 4 β
2 + 7 β
3 = 31;
* f(3, 3) = 4 β
1 = 4;
* f(3, 4) = 4 β
1 + 7 β
2 = 18;
* f(4, 4) = 7 β
1 = 7;
Submitted Solution:
```
def main():
MOD = 1000000007
# inp = readnumbers()
# n = inp[0]
# a = inp[1:]
n = int(input())
a = list(map(int, input().split()))
ans = 0
# for i in range(n):
# ans += a[i] * (i + 1) * (n - i)
# for j in range(i):
# if a[j] < a[i]:
# ans += a[i] * (j + 1) * (n - i)
# for j in range(i + 1, n):
# if a[j] < a[i]:
# ans += a[i] * (n - j) * (i + 1)
# print(ans % MOD)
for i in range(n):
a[i] = (a[i] << 20) | (i + 1)
a.sort()
x = [0] * (n * 6 + 10)
ad1 = 0
ad2 = 0
global re
re = 0
if n > 800:
return
M = 1
while M <= n:
M *= 2
def sum1(a, b, l, r, i):
if a == l and b == r:
global re
re += x[i]
return
mi = (l + r) // 2
if a < mi:
sum1(a, min(mi, b), l, mi, i * 2)
if mi < b:
sum1(max(mi, a), b, mi, r, i * 2 + 1)
def sum2(a, b, l, r, i):
if a == l and b == r:
global re
re += y[i]
return
mi = (l + r) // 2
if a < mi:
sum2(a, min(mi, b), l, mi, i * 2)
if mi < b:
sum2(max(mi, a), b, mi, r, i * 2 + 1)
bm = (1 << 20) - 1
for i in a:
ta = i >> 20
tb = i & bm
ad1 = tb
ad2 = n - tb + 1
j = M + tb
while True:
ja = j << 1
x[ja] += ad1
if x[ja] >= MOD:
x[ja] -= MOD
jb = ja | 1
x[jb] += ad2
if x[jb] >= MOD:
x[jb] -= MOD
if not j:
break
j >>= 1
tot = tb * (n - tb + 1)
if tb != 1:
re = 0
la = M
lb = M + tb
while (la ^ lb) != 1:
if not (la & 1):
re += x[(la << 1) ^ 2]
if (lb & 1):
re += x[(lb << 1) ^ 2]
la >>= 1
lb >>= 1
re %= MOD
tot += re * (n - tb + 1)
if tb != n:
re = 0
la = M + tb
lb = M + n + 1
while (la ^ lb) != 1:
if not (la & 1):
re += x[(la << 1) ^ 3]
if (lb & 1):
re += x[(lb << 1) ^ 3]
la >>= 1
lb >>= 1
re %= MOD
tot += re * tb
tot %= MOD
ans = (ans + ta * tot) % MOD
print(ans)
######## Python 2 and 3 footer by Pajenegod and c1729
# Note because cf runs old PyPy3 version which doesn't have the sped up
# unicode strings, PyPy3 strings will many times be slower than pypy2.
# There is a way to get around this by using binary strings in PyPy3
# but its syntax is different which makes it kind of a mess to use.
# So on cf, use PyPy2 for best string performance.
py2 = round(0.5)
if py2:
from future_builtins import ascii, filter, hex, map, oct, zip
range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192
class FastIO(BytesIO):
newlines = 0
def __init__(self, file):
self._file = file
self._fd = file.fileno()
self.writable = "x" in file.mode or "w" in file.mode
self.write = super(FastIO, self).write if self.writable else None
def _fill(self):
s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
return s
def read(self):
while self._fill(): pass
return super(FastIO,self).read()
def readline(self):
while self.newlines == 0:
s = self._fill(); self.newlines = s.count(b"\n") + (not s)
self.newlines -= 1
return super(FastIO, self).readline()
def flush(self):
if self.writable:
os.write(self._fd, self.getvalue())
self.truncate(0), self.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
if py2:
self.write = self.buffer.write
self.read = self.buffer.read
self.readline = self.buffer.readline
else:
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')
# Cout implemented in Python
import sys
class ostream:
def __lshift__(self,a):
sys.stdout.write(str(a))
return self
cout = ostream()
endl = '\n'
# Read all remaining integers in stdin, type is given by optional argument, this is fast
def readnumbers(zero = 0):
conv = ord if py2 else lambda x:x
A = []; numb = zero; sign = 1; i = 0; s = sys.stdin.buffer.read()
try:
while True:
if s[i] >= b'0' [0]:
numb = 10 * numb + conv(s[i]) - 48
elif s[i] == b'-' [0]: sign = -1
elif s[i] != b'\r' [0]:
A.append(sign*numb)
numb = zero; sign = 1
i += 1
except:pass
if s and s[-1] >= b'0' [0]:
A.append(sign*numb)
return A
if __name__== "__main__":
main()
```
No
| 106,185 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, ..., a_n. All a_i are pairwise distinct.
Let's define function f(l, r) as follows:
* let's define array b_1, b_2, ..., b_{r - l + 1}, where b_i = a_{l - 1 + i};
* sort array b in increasing order;
* result of the function f(l, r) is β_{i = 1}^{r - l + 1}{b_i β
i}.
Calculate \left(β_{1 β€ l β€ r β€ n}{f(l, r)}\right) mod (10^9+7), i.e. total sum of f for all subsegments of a modulo 10^9+7.
Input
The first line contains one integer n (1 β€ n β€ 5 β
10^5) β the length of array a.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9, a_i β a_j for i β j) β array a.
Output
Print one integer β the total sum of f for all subsegments of a modulo 10^9+7
Examples
Input
4
5 2 4 7
Output
167
Input
3
123456789 214365879 987654321
Output
582491518
Note
Description of the first example:
* f(1, 1) = 5 β
1 = 5;
* f(1, 2) = 2 β
1 + 5 β
2 = 12;
* f(1, 3) = 2 β
1 + 4 β
2 + 5 β
3 = 25;
* f(1, 4) = 2 β
1 + 4 β
2 + 5 β
3 + 7 β
4 = 53;
* f(2, 2) = 2 β
1 = 2;
* f(2, 3) = 2 β
1 + 4 β
2 = 10;
* f(2, 4) = 2 β
1 + 4 β
2 + 7 β
3 = 31;
* f(3, 3) = 4 β
1 = 4;
* f(3, 4) = 4 β
1 + 7 β
2 = 18;
* f(4, 4) = 7 β
1 = 7;
Submitted Solution:
```
n = int(input())
m = ([int(x) for x in input().split()])
b = [0] * (n+1)
def f(l, r):
global b
for ii in range(r-l+1):
b[ii] = m[l-1+ii]
c = sorted(b[:r-l+1].copy())
s = 0
for ii in range(r - l+1):
s += c[ii]*(ii+1)
del c
return s
ss = 0
p = 10**9 + 7
for i in range(n):
for j in range(n):
ss += f(i+1, j+1) % p
print(ss)
```
No
| 106,186 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, ..., a_n. All a_i are pairwise distinct.
Let's define function f(l, r) as follows:
* let's define array b_1, b_2, ..., b_{r - l + 1}, where b_i = a_{l - 1 + i};
* sort array b in increasing order;
* result of the function f(l, r) is β_{i = 1}^{r - l + 1}{b_i β
i}.
Calculate \left(β_{1 β€ l β€ r β€ n}{f(l, r)}\right) mod (10^9+7), i.e. total sum of f for all subsegments of a modulo 10^9+7.
Input
The first line contains one integer n (1 β€ n β€ 5 β
10^5) β the length of array a.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9, a_i β a_j for i β j) β array a.
Output
Print one integer β the total sum of f for all subsegments of a modulo 10^9+7
Examples
Input
4
5 2 4 7
Output
167
Input
3
123456789 214365879 987654321
Output
582491518
Note
Description of the first example:
* f(1, 1) = 5 β
1 = 5;
* f(1, 2) = 2 β
1 + 5 β
2 = 12;
* f(1, 3) = 2 β
1 + 4 β
2 + 5 β
3 = 25;
* f(1, 4) = 2 β
1 + 4 β
2 + 5 β
3 + 7 β
4 = 53;
* f(2, 2) = 2 β
1 = 2;
* f(2, 3) = 2 β
1 + 4 β
2 = 10;
* f(2, 4) = 2 β
1 + 4 β
2 + 7 β
3 = 31;
* f(3, 3) = 4 β
1 = 4;
* f(3, 4) = 4 β
1 + 7 β
2 = 18;
* f(4, 4) = 7 β
1 = 7;
Submitted Solution:
```
maxn = int(5e6 + 1)
mod = int(1e9 + 7)
n = int(input())
rbit = [0] * maxn
lbit = [0] * maxn
def update(left, i, val):
if i == 0:
return
while i <= n:
if left:
lbit[i] = lbit[i] + val
else:
rbit[i] = rbit[i] + val
i = i + (i & (-i))
def query(left, i):
res = 0
while i > 0:
if left:
res = res + lbit[i]
else:
res = res + rbit[i]
i = i - (i & (-i))
return res % mod
a = sorted(list(map(lambda kv: (int(kv[1]), kv[0] + 1), enumerate(input().split()))))
res = 0
for i in range(n):
val = a[i][0]
idx = a[i][1]
rdx = n - idx + 1
res = (res + val * (idx * rdx + val * (query(True, idx) * idx + query(False, idx) * rdx)) % mod) % mod
update(True, 1, rdx)
update(True, idx, -rdx)
update(False, idx + 1, idx)
print(res % mod)
```
No
| 106,187 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, ..., a_n. All a_i are pairwise distinct.
Let's define function f(l, r) as follows:
* let's define array b_1, b_2, ..., b_{r - l + 1}, where b_i = a_{l - 1 + i};
* sort array b in increasing order;
* result of the function f(l, r) is β_{i = 1}^{r - l + 1}{b_i β
i}.
Calculate \left(β_{1 β€ l β€ r β€ n}{f(l, r)}\right) mod (10^9+7), i.e. total sum of f for all subsegments of a modulo 10^9+7.
Input
The first line contains one integer n (1 β€ n β€ 5 β
10^5) β the length of array a.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9, a_i β a_j for i β j) β array a.
Output
Print one integer β the total sum of f for all subsegments of a modulo 10^9+7
Examples
Input
4
5 2 4 7
Output
167
Input
3
123456789 214365879 987654321
Output
582491518
Note
Description of the first example:
* f(1, 1) = 5 β
1 = 5;
* f(1, 2) = 2 β
1 + 5 β
2 = 12;
* f(1, 3) = 2 β
1 + 4 β
2 + 5 β
3 = 25;
* f(1, 4) = 2 β
1 + 4 β
2 + 5 β
3 + 7 β
4 = 53;
* f(2, 2) = 2 β
1 = 2;
* f(2, 3) = 2 β
1 + 4 β
2 = 10;
* f(2, 4) = 2 β
1 + 4 β
2 + 7 β
3 = 31;
* f(3, 3) = 4 β
1 = 4;
* f(3, 4) = 4 β
1 + 7 β
2 = 18;
* f(4, 4) = 7 β
1 = 7;
Submitted Solution:
```
n=int(input())
b=list(map(int,input().split()))
sum=0
for i in range(n):
for j in range(i,n):
a=b[:(j-i+1)]
a.sort()
for k in range(1,j-i+2):
sum=sum+k*a[k-1]
r=sum%(100000007)
print(r)
```
No
| 106,188 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks.
Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook.
Input
The first line contains three integers n, m, and k (1 β€ n, m, k β€ 100) β the number of participants, the number of pens, and the number of notebooks respectively.
Output
Print "Yes" if it possible to reward all the participants. Otherwise, print "No".
You can print each letter in any case (upper or lower).
Examples
Input
5 8 6
Output
Yes
Input
3 9 3
Output
Yes
Input
8 5 20
Output
No
Note
In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks.
In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks.
In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No".
Tags: implementation
Correct Solution:
```
n, m, k = map(int, input().split())
if n <= k and n <= m:
print("YES")
else:
print("NO")
```
| 106,189 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks.
Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook.
Input
The first line contains three integers n, m, and k (1 β€ n, m, k β€ 100) β the number of participants, the number of pens, and the number of notebooks respectively.
Output
Print "Yes" if it possible to reward all the participants. Otherwise, print "No".
You can print each letter in any case (upper or lower).
Examples
Input
5 8 6
Output
Yes
Input
3 9 3
Output
Yes
Input
8 5 20
Output
No
Note
In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks.
In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks.
In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No".
Tags: implementation
Correct Solution:
```
a = input()
a = a.split()
if (int(a[1])>=int(a[0]) and int(a[2])>=int(a[0])):
print("Yes")
else:
print("No")
```
| 106,190 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks.
Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook.
Input
The first line contains three integers n, m, and k (1 β€ n, m, k β€ 100) β the number of participants, the number of pens, and the number of notebooks respectively.
Output
Print "Yes" if it possible to reward all the participants. Otherwise, print "No".
You can print each letter in any case (upper or lower).
Examples
Input
5 8 6
Output
Yes
Input
3 9 3
Output
Yes
Input
8 5 20
Output
No
Note
In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks.
In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks.
In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No".
Tags: implementation
Correct Solution:
```
def solution():
inputs = str(input())
inputs = inputs.split()
n = int(inputs[0])
m = int(inputs[1])
k = int(inputs[2])
n_pair = min(m, k)
if (n <= n_pair):
print("Yes")
else:
print("No")
solution()
```
| 106,191 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks.
Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook.
Input
The first line contains three integers n, m, and k (1 β€ n, m, k β€ 100) β the number of participants, the number of pens, and the number of notebooks respectively.
Output
Print "Yes" if it possible to reward all the participants. Otherwise, print "No".
You can print each letter in any case (upper or lower).
Examples
Input
5 8 6
Output
Yes
Input
3 9 3
Output
Yes
Input
8 5 20
Output
No
Note
In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks.
In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks.
In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No".
Tags: implementation
Correct Solution:
```
n,m,k=list(map(int,input().strip().split()))
if m>=n and k>=n:
print('Yes')
else:
print('No')
```
| 106,192 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks.
Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook.
Input
The first line contains three integers n, m, and k (1 β€ n, m, k β€ 100) β the number of participants, the number of pens, and the number of notebooks respectively.
Output
Print "Yes" if it possible to reward all the participants. Otherwise, print "No".
You can print each letter in any case (upper or lower).
Examples
Input
5 8 6
Output
Yes
Input
3 9 3
Output
Yes
Input
8 5 20
Output
No
Note
In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks.
In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks.
In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No".
Tags: implementation
Correct Solution:
```
n,m,k=map(int,input().split())
f=min(m,k)
if(n>f):
print("No")
else:
print("Yes")
```
| 106,193 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks.
Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook.
Input
The first line contains three integers n, m, and k (1 β€ n, m, k β€ 100) β the number of participants, the number of pens, and the number of notebooks respectively.
Output
Print "Yes" if it possible to reward all the participants. Otherwise, print "No".
You can print each letter in any case (upper or lower).
Examples
Input
5 8 6
Output
Yes
Input
3 9 3
Output
Yes
Input
8 5 20
Output
No
Note
In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks.
In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks.
In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No".
Tags: implementation
Correct Solution:
```
n,pens,books=map(int,input().split())
x=min(n,pens,books)
if x==n:
print('Yes')
else:
print('No')
```
| 106,194 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks.
Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook.
Input
The first line contains three integers n, m, and k (1 β€ n, m, k β€ 100) β the number of participants, the number of pens, and the number of notebooks respectively.
Output
Print "Yes" if it possible to reward all the participants. Otherwise, print "No".
You can print each letter in any case (upper or lower).
Examples
Input
5 8 6
Output
Yes
Input
3 9 3
Output
Yes
Input
8 5 20
Output
No
Note
In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks.
In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks.
In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No".
Tags: implementation
Correct Solution:
```
n,m,k=map(int,input().split())
s=min(m,k)
if(s>=n):
print("Yes")
else:
print("No")
```
| 106,195 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks.
Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook.
Input
The first line contains three integers n, m, and k (1 β€ n, m, k β€ 100) β the number of participants, the number of pens, and the number of notebooks respectively.
Output
Print "Yes" if it possible to reward all the participants. Otherwise, print "No".
You can print each letter in any case (upper or lower).
Examples
Input
5 8 6
Output
Yes
Input
3 9 3
Output
Yes
Input
8 5 20
Output
No
Note
In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks.
In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks.
In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No".
Tags: implementation
Correct Solution:
```
# @author
import sys
class AVusTheCossackAndAContest:
def solve(self):
n, m, k = [int(_) for _ in input().split()]
print("Yes" if min(m, k) >= n else "No")
solver = AVusTheCossackAndAContest()
input = sys.stdin.readline
solver.solve()
```
| 106,196 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks.
Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook.
Input
The first line contains three integers n, m, and k (1 β€ n, m, k β€ 100) β the number of participants, the number of pens, and the number of notebooks respectively.
Output
Print "Yes" if it possible to reward all the participants. Otherwise, print "No".
You can print each letter in any case (upper or lower).
Examples
Input
5 8 6
Output
Yes
Input
3 9 3
Output
Yes
Input
8 5 20
Output
No
Note
In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks.
In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks.
In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No".
Submitted Solution:
```
from sys import stdin
input = stdin.readline
n, m, k = list(map(int, input().split()))
if min(m, k) >= n:
print('Yes')
else:
print('No')
```
Yes
| 106,197 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks.
Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook.
Input
The first line contains three integers n, m, and k (1 β€ n, m, k β€ 100) β the number of participants, the number of pens, and the number of notebooks respectively.
Output
Print "Yes" if it possible to reward all the participants. Otherwise, print "No".
You can print each letter in any case (upper or lower).
Examples
Input
5 8 6
Output
Yes
Input
3 9 3
Output
Yes
Input
8 5 20
Output
No
Note
In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks.
In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks.
In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No".
Submitted Solution:
```
t=list(map(int,(input().split())))
if t[1]>=t[0] and t[2]>=t[0]:
print ("YES")
else :
print("NO")
```
Yes
| 106,198 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks.
Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook.
Input
The first line contains three integers n, m, and k (1 β€ n, m, k β€ 100) β the number of participants, the number of pens, and the number of notebooks respectively.
Output
Print "Yes" if it possible to reward all the participants. Otherwise, print "No".
You can print each letter in any case (upper or lower).
Examples
Input
5 8 6
Output
Yes
Input
3 9 3
Output
Yes
Input
8 5 20
Output
No
Note
In the first example, there are 5 participants. The Cossack has 8 pens and 6 notebooks. Therefore, he has enough pens and notebooks.
In the second example, there are 3 participants. The Cossack has 9 pens and 3 notebooks. He has more than enough pens but only the minimum needed number of notebooks.
In the third example, there are 8 participants but only 5 pens. Since the Cossack does not have enough pens, the answer is "No".
Submitted Solution:
```
n,m,k = [int(x) for x in input().split()]
if(n<=m and n<=k):
print("Yes")
else:
print("No")
```
Yes
| 106,199 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.