message stringlengths 2 48.6k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 318 108k | cluster float64 8 8 | __index_level_0__ int64 636 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.
Find the maximum number of robots that we can keep.
Constraints
* 1 \leq N \leq 100,000
* 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
* 1 \leq L_i \leq 10^9 (1 \leq i \leq N)
* If i \neq j, X_i \neq X_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 L_1
X_2 L_2
\vdots
X_N L_N
Output
Print the maximum number of robots that we can keep.
Examples
Input
4
2 4
4 3
9 3
100 5
Output
3
Input
2
8 20
1 10
Output
1
Input
5
10 1
2 1
4 1
6 1
8 1
Output
5 | instruction | 0 | 93,284 | 8 | 186,568 |
"Correct Solution:
```
n = int(input())
xl = []
for i in range(n):
x,l = map(int,input().split())
xl.append([x+l,x-l])
xl.sort()
ans = -10**10
count = 0
for j in range(n):
if xl[j][1] >= ans:
count +=1
ans = xl[j][0]
print(count)
``` | output | 1 | 93,284 | 8 | 186,569 |
Provide a correct Python 3 solution for this coding contest problem.
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.
Find the maximum number of robots that we can keep.
Constraints
* 1 \leq N \leq 100,000
* 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
* 1 \leq L_i \leq 10^9 (1 \leq i \leq N)
* If i \neq j, X_i \neq X_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 L_1
X_2 L_2
\vdots
X_N L_N
Output
Print the maximum number of robots that we can keep.
Examples
Input
4
2 4
4 3
9 3
100 5
Output
3
Input
2
8 20
1 10
Output
1
Input
5
10 1
2 1
4 1
6 1
8 1
Output
5 | instruction | 0 | 93,285 | 8 | 186,570 |
"Correct Solution:
```
n=int(input())
xls=[list(map(int,input().split())) for _ in range(n)]
lrs=sorted((x-l,x+l) for x,l in xls)
res=0
most_r=lrs[0][0]
for l,r in lrs:
if l>=most_r:
res+=1
most_r=r
elif most_r>r:
most_r=r
print(res)
``` | output | 1 | 93,285 | 8 | 186,571 |
Provide a correct Python 3 solution for this coding contest problem.
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.
Find the maximum number of robots that we can keep.
Constraints
* 1 \leq N \leq 100,000
* 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
* 1 \leq L_i \leq 10^9 (1 \leq i \leq N)
* If i \neq j, X_i \neq X_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 L_1
X_2 L_2
\vdots
X_N L_N
Output
Print the maximum number of robots that we can keep.
Examples
Input
4
2 4
4 3
9 3
100 5
Output
3
Input
2
8 20
1 10
Output
1
Input
5
10 1
2 1
4 1
6 1
8 1
Output
5 | instruction | 0 | 93,286 | 8 | 186,572 |
"Correct Solution:
```
n = int(input())
count = 0
X = []
for i in range(n):
x,l = map(int, input().split())
X.append((x+l,x-l))
X.sort()
coord = -float('inf')
for i in X:
if i[1] >= coord:
count += 1
coord = i[0]
print(count)
``` | output | 1 | 93,286 | 8 | 186,573 |
Provide a correct Python 3 solution for this coding contest problem.
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.
Find the maximum number of robots that we can keep.
Constraints
* 1 \leq N \leq 100,000
* 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
* 1 \leq L_i \leq 10^9 (1 \leq i \leq N)
* If i \neq j, X_i \neq X_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 L_1
X_2 L_2
\vdots
X_N L_N
Output
Print the maximum number of robots that we can keep.
Examples
Input
4
2 4
4 3
9 3
100 5
Output
3
Input
2
8 20
1 10
Output
1
Input
5
10 1
2 1
4 1
6 1
8 1
Output
5 | instruction | 0 | 93,287 | 8 | 186,574 |
"Correct Solution:
```
n=int(input())
XL=[]
for i in range(n):
x,l=map(int,input().split())
XL.append([x-l,x,x+l])
ans=0
cur=-float("inf")
XL.sort(key=lambda x:x[2])
for x1,x2,x3 in XL:
if x1>=cur:
cur=x3
ans+=1
else:
continue
print(ans)
``` | output | 1 | 93,287 | 8 | 186,575 |
Provide a correct Python 3 solution for this coding contest problem.
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.
Find the maximum number of robots that we can keep.
Constraints
* 1 \leq N \leq 100,000
* 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
* 1 \leq L_i \leq 10^9 (1 \leq i \leq N)
* If i \neq j, X_i \neq X_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 L_1
X_2 L_2
\vdots
X_N L_N
Output
Print the maximum number of robots that we can keep.
Examples
Input
4
2 4
4 3
9 3
100 5
Output
3
Input
2
8 20
1 10
Output
1
Input
5
10 1
2 1
4 1
6 1
8 1
Output
5 | instruction | 0 | 93,288 | 8 | 186,576 |
"Correct Solution:
```
N = int(input())
arms = []
for i in range(0, N):
X, L = map(int, input().split(" "))
arms.append((X + L, X - L))
arms.sort()
ans = 0
coord = -float('inf')
for arm in arms:
if arm[1] >= coord:
ans += 1
coord = arm[0]
print(ans)
``` | output | 1 | 93,288 | 8 | 186,577 |
Provide a correct Python 3 solution for this coding contest problem.
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.
Find the maximum number of robots that we can keep.
Constraints
* 1 \leq N \leq 100,000
* 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
* 1 \leq L_i \leq 10^9 (1 \leq i \leq N)
* If i \neq j, X_i \neq X_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 L_1
X_2 L_2
\vdots
X_N L_N
Output
Print the maximum number of robots that we can keep.
Examples
Input
4
2 4
4 3
9 3
100 5
Output
3
Input
2
8 20
1 10
Output
1
Input
5
10 1
2 1
4 1
6 1
8 1
Output
5 | instruction | 0 | 93,289 | 8 | 186,578 |
"Correct Solution:
```
N = int(input())
P = []
for _ in range(N):
x,l = list(map(int, input().split()))
P.append((x+l, x-l))
P.sort()
rw = P[0][0]
ans = 1
for i in range(1,N):
r,l = P[i]
if l < rw:
continue
else:
rw = r
ans += 1
print(ans)
``` | output | 1 | 93,289 | 8 | 186,579 |
Provide a correct Python 3 solution for this coding contest problem.
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.
Find the maximum number of robots that we can keep.
Constraints
* 1 \leq N \leq 100,000
* 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
* 1 \leq L_i \leq 10^9 (1 \leq i \leq N)
* If i \neq j, X_i \neq X_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 L_1
X_2 L_2
\vdots
X_N L_N
Output
Print the maximum number of robots that we can keep.
Examples
Input
4
2 4
4 3
9 3
100 5
Output
3
Input
2
8 20
1 10
Output
1
Input
5
10 1
2 1
4 1
6 1
8 1
Output
5 | instruction | 0 | 93,290 | 8 | 186,580 |
"Correct Solution:
```
N = int(input())
q = []
for i in range(N):
x,l = map(int, input().split())
q.append((x+l, x-l))
q.sort()
cnt = 0
INF = float("inf")
b = -INF
for r,l in q:
if l >= b:
b = r
else:
cnt += 1
print(N-cnt)
``` | output | 1 | 93,290 | 8 | 186,581 |
Provide a correct Python 3 solution for this coding contest problem.
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.
Find the maximum number of robots that we can keep.
Constraints
* 1 \leq N \leq 100,000
* 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
* 1 \leq L_i \leq 10^9 (1 \leq i \leq N)
* If i \neq j, X_i \neq X_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 L_1
X_2 L_2
\vdots
X_N L_N
Output
Print the maximum number of robots that we can keep.
Examples
Input
4
2 4
4 3
9 3
100 5
Output
3
Input
2
8 20
1 10
Output
1
Input
5
10 1
2 1
4 1
6 1
8 1
Output
5 | instruction | 0 | 93,291 | 8 | 186,582 |
"Correct Solution:
```
n=int(input())
d=[]
for i in range(n):
x,l=map(int,input().split())
d.append((x-l,x+l))
d.sort()
ans=1
chk=d[0][1]
for i in d:
if i[0]>=chk:
ans+=1
chk=i[1]
else:
chk=min(chk,i[1])
print(ans)
``` | output | 1 | 93,291 | 8 | 186,583 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.
Find the maximum number of robots that we can keep.
Constraints
* 1 \leq N \leq 100,000
* 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
* 1 \leq L_i \leq 10^9 (1 \leq i \leq N)
* If i \neq j, X_i \neq X_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 L_1
X_2 L_2
\vdots
X_N L_N
Output
Print the maximum number of robots that we can keep.
Examples
Input
4
2 4
4 3
9 3
100 5
Output
3
Input
2
8 20
1 10
Output
1
Input
5
10 1
2 1
4 1
6 1
8 1
Output
5
Submitted Solution:
```
n=int(input())
XL=[list(map(int,input().split())) for i in range(n)]
Range=[[x-l,x+l] for x,l in XL]
ans,end=0,-1*(10**9+1)
Range.sort(key=lambda X: X[1])
for R in Range:
if end > R[0]:
continue
ans += 1
end=R[1]
print(ans)
``` | instruction | 0 | 93,292 | 8 | 186,584 |
Yes | output | 1 | 93,292 | 8 | 186,585 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.
Find the maximum number of robots that we can keep.
Constraints
* 1 \leq N \leq 100,000
* 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
* 1 \leq L_i \leq 10^9 (1 \leq i \leq N)
* If i \neq j, X_i \neq X_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 L_1
X_2 L_2
\vdots
X_N L_N
Output
Print the maximum number of robots that we can keep.
Examples
Input
4
2 4
4 3
9 3
100 5
Output
3
Input
2
8 20
1 10
Output
1
Input
5
10 1
2 1
4 1
6 1
8 1
Output
5
Submitted Solution:
```
N, *XL = map(int, open(0).read().split())
XL = sorted((x + l, x - l) for x, l in zip(*[iter(XL)] * 2))
curr = -float("inf")
ans = 0
for right, left in XL:
if left >= curr:
curr = right
ans += 1
print(ans)
``` | instruction | 0 | 93,293 | 8 | 186,586 |
Yes | output | 1 | 93,293 | 8 | 186,587 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.
Find the maximum number of robots that we can keep.
Constraints
* 1 \leq N \leq 100,000
* 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
* 1 \leq L_i \leq 10^9 (1 \leq i \leq N)
* If i \neq j, X_i \neq X_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 L_1
X_2 L_2
\vdots
X_N L_N
Output
Print the maximum number of robots that we can keep.
Examples
Input
4
2 4
4 3
9 3
100 5
Output
3
Input
2
8 20
1 10
Output
1
Input
5
10 1
2 1
4 1
6 1
8 1
Output
5
Submitted Solution:
```
n=int(input())
L=[]
for i in range(n):
x,l=map(int,input().split())
L.append([x-l,x+l])
L.sort(key=lambda x:x[1])
ans=1
bef=L[0][1]
for i in range(1,n):
if bef<=L[i][0]:
bef=L[i][1]
ans+=1
print(ans)
``` | instruction | 0 | 93,294 | 8 | 186,588 |
Yes | output | 1 | 93,294 | 8 | 186,589 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.
Find the maximum number of robots that we can keep.
Constraints
* 1 \leq N \leq 100,000
* 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
* 1 \leq L_i \leq 10^9 (1 \leq i \leq N)
* If i \neq j, X_i \neq X_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 L_1
X_2 L_2
\vdots
X_N L_N
Output
Print the maximum number of robots that we can keep.
Examples
Input
4
2 4
4 3
9 3
100 5
Output
3
Input
2
8 20
1 10
Output
1
Input
5
10 1
2 1
4 1
6 1
8 1
Output
5
Submitted Solution:
```
n=int(input())
l=[]
for i in range(n):
x,y=map(int,input().split())
l.append([x-y,x+y])
count=0
l=sorted(l)
l=l[::-1]
count+=1
now=l[0][0]
for i in range(1,n):
if now>=l[i][1]:
now=l[i][0]
count+=1
else:
pass
print(count)
``` | instruction | 0 | 93,295 | 8 | 186,590 |
Yes | output | 1 | 93,295 | 8 | 186,591 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.
Find the maximum number of robots that we can keep.
Constraints
* 1 \leq N \leq 100,000
* 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
* 1 \leq L_i \leq 10^9 (1 \leq i \leq N)
* If i \neq j, X_i \neq X_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 L_1
X_2 L_2
\vdots
X_N L_N
Output
Print the maximum number of robots that we can keep.
Examples
Input
4
2 4
4 3
9 3
100 5
Output
3
Input
2
8 20
1 10
Output
1
Input
5
10 1
2 1
4 1
6 1
8 1
Output
5
Submitted Solution:
```
N=int(input())
X=[]
L=[]
XA=[]
XB=[]
Q=[0]*N
for i in range(N):
x,l=map(int,input().split())
X.append(x)
L.append(l)
for i in range(N):
XA.append(X[i]-L[i])
XB.append(X[i]+L[i])
S=sorted(list(zip(XA,XB)))
cnt=0
#print(S)
i=0
while i<N-1:
if i==0:
if S[i][1]>S[i+1][0]:
cnt=cnt+1
if S[i][1]<=S[i+1][1]:
S.pop(i+1)
else:
S.pop(i)
i=i+1
else:
i=i+1
else:
if S[i-1][1]>S[i][0]:
cnt=cnt+1
S.pop(i)
i=i+1
else:
i=i+1
#print(cnt)
#print(S)
print(N-cnt)
``` | instruction | 0 | 93,296 | 8 | 186,592 |
No | output | 1 | 93,296 | 8 | 186,593 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.
Find the maximum number of robots that we can keep.
Constraints
* 1 \leq N \leq 100,000
* 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
* 1 \leq L_i \leq 10^9 (1 \leq i \leq N)
* If i \neq j, X_i \neq X_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 L_1
X_2 L_2
\vdots
X_N L_N
Output
Print the maximum number of robots that we can keep.
Examples
Input
4
2 4
4 3
9 3
100 5
Output
3
Input
2
8 20
1 10
Output
1
Input
5
10 1
2 1
4 1
6 1
8 1
Output
5
Submitted Solution:
```
n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
xx = []
count = 0
for x in xl:
xx.append([x[0] - x[1], x[0] + x[1]])
if n != 2:
for i in range(1, n-1):
if xx[i][0] < xx[i-1][1] and xx[i][1] > xx[i+1][0]:
count += 1
print(n-count)
else:
if xx[1][0] < xx[0][1]:
print(1)
else:
print(2)
``` | instruction | 0 | 93,297 | 8 | 186,594 |
No | output | 1 | 93,297 | 8 | 186,595 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.
Find the maximum number of robots that we can keep.
Constraints
* 1 \leq N \leq 100,000
* 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
* 1 \leq L_i \leq 10^9 (1 \leq i \leq N)
* If i \neq j, X_i \neq X_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 L_1
X_2 L_2
\vdots
X_N L_N
Output
Print the maximum number of robots that we can keep.
Examples
Input
4
2 4
4 3
9 3
100 5
Output
3
Input
2
8 20
1 10
Output
1
Input
5
10 1
2 1
4 1
6 1
8 1
Output
5
Submitted Solution:
```
import sys
from pprint import pprint
def solve(n, x, l):
r = []
for i in range(n):
r.append((x[i], l[i]))
x_pre = -1
l_pre = 0
remove = 0
for x_i, l_i in sorted(r):
if x_pre == -1:
x_pre = x_i
l_pre = l_i
continue
# print("pre", x_pre, l_pre)
# print(x_i, l_i)
if x_i - l_i < x_pre + l_pre:
# 先まで届かない方を残す
if x_pre + l_pre > x_i + l_i:
x_pre = x_i
l_pre = x_i
remove += 1
print(n - remove)
if __name__ == '__main__':
n = int(sys.stdin.readline().strip())
x = [0] * n
l = [0] * n
for i in range(n):
x[i], l[i] = map(int, sys.stdin.readline().strip().split(" "))
solve(n, x, l)
``` | instruction | 0 | 93,298 | 8 | 186,596 |
No | output | 1 | 93,298 | 8 | 186,597 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.
We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.
Find the maximum number of robots that we can keep.
Constraints
* 1 \leq N \leq 100,000
* 0 \leq X_i \leq 10^9 (1 \leq i \leq N)
* 1 \leq L_i \leq 10^9 (1 \leq i \leq N)
* If i \neq j, X_i \neq X_j.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 L_1
X_2 L_2
\vdots
X_N L_N
Output
Print the maximum number of robots that we can keep.
Examples
Input
4
2 4
4 3
9 3
100 5
Output
3
Input
2
8 20
1 10
Output
1
Input
5
10 1
2 1
4 1
6 1
8 1
Output
5
Submitted Solution:
```
n = int(input())
x = []
for i in range(n):
x1, y1=[int(i) for i in input().split()]
x.append([x1, y1])
x.sort()
remove = 0
stocks = 0
for k in range(n - 1):
if k+1+stocks < n:
if (x[k + 1 + stocks][0] - x[k][0]) < x[k][1] + x[k + 1][1]:
remove += 1
x[k + 1][0] = -1
if n - 2 > k:
stocks += 1
k -=1
else:
stocks=0
print (n -remove)
``` | instruction | 0 | 93,299 | 8 | 186,598 |
No | output | 1 | 93,299 | 8 | 186,599 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.
Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when:
* all parts of the wall has the same height;
* the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.
Output
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
Note
In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete. | instruction | 0 | 93,548 | 8 | 187,096 |
Tags: data structures, implementation
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
s = []
flag = 1
for i in range(0,n):
if len(s) and s[-1] == a[i]:
s.pop()
elif len(s) == 0 or s[-1] > a[i]:
s.append(a[i])
else:
print("NO")
flag = 0
break
if(flag == 1):
if len(s) == 0 or len(s) == 1 and s[-1] == max(a):
print("YES")
else:
print("NO")
``` | output | 1 | 93,548 | 8 | 187,097 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.
Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when:
* all parts of the wall has the same height;
* the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.
Output
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
Note
In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete. | instruction | 0 | 93,549 | 8 | 187,098 |
Tags: data structures, implementation
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
down=[]
good=True
for guy in a:
if len(down)==0:
down.append(guy)
elif down[-1]>guy:
down.append(guy)
elif down[-1]==guy:
down.pop()
else:
good=False
break
if not good:
print("NO")
elif len(down)>1:
print("NO")
elif len(down)==1 and down[0]!=max(a):
print("NO")
else:
print("YES")
``` | output | 1 | 93,549 | 8 | 187,099 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.
Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when:
* all parts of the wall has the same height;
* the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.
Output
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
Note
In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete. | instruction | 0 | 93,550 | 8 | 187,100 |
Tags: data structures, implementation
Correct Solution:
```
i,p,l,j=input,print,len,int
n,m,q=j(i()),0,[]
f=q.append
for a in map(j,i().split()):
if q:
if a==q[-1]:q.pop()
elif a>q[-1]:f(a);break
else:f(a)
else:f(a)
m=max(m,a)
if l(q)==0 or l(q)==1 and q[0]==m:p('YES')
else:p('NO')
``` | output | 1 | 93,550 | 8 | 187,101 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.
Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when:
* all parts of the wall has the same height;
* the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.
Output
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
Note
In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete. | instruction | 0 | 93,551 | 8 | 187,102 |
Tags: data structures, implementation
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
b = [[a[0], 1]]
fl = False
for i in range(1, n):
if fl:
break
if a[i] == b[-1][0]:
b[-1][1] += 1
elif a[i] < b[-1][0]:
b.append([a[i], 1])
else:
while len(b) != 0 and a[i] > b[-1][0]:
if b[-1][1] % 2 != 0:
print("NO")
fl = True
break
b.pop()
if len(b) == 0 or a[i] < b[-1][0]:
b.append([a[i], 1])
else:
b[-1][1] += 1
if not fl:
i = len(b) - 1
while i != 0:
if b[i][1] % 2 != 0:
fl = True
break
i -= 1
if fl:
print("NO")
else:
print("YES")
``` | output | 1 | 93,551 | 8 | 187,103 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.
Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when:
* all parts of the wall has the same height;
* the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.
Output
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
Note
In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete. | instruction | 0 | 93,552 | 8 | 187,104 |
Tags: data structures, implementation
Correct Solution:
```
i = int(input())
s = input().split()
m = max (list(map(int,s)))
l = []
for j in s:
if not l or int(j) < l[-1] :
l.append(int(j))
elif int(j) == l[-1]:
l.pop()
else:
print('NO')
exit()
if (len(l) ==1 and l[0] >= m) or len(l) == 0 :
print('YES')
else:
print('NO')
``` | output | 1 | 93,552 | 8 | 187,105 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.
Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when:
* all parts of the wall has the same height;
* the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.
Output
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
Note
In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete. | instruction | 0 | 93,553 | 8 | 187,106 |
Tags: data structures, implementation
Correct Solution:
```
i,p=input,print;n,m,q=int(i()),0,[];f=q.append
for a in map(int,i().split()):
if q:
if a==q[-1]:q.pop()
elif a>q[-1]:f(a);break
else:f(a)
else:f(a)
m=max(m,a)
p('YES'if len(q)==0 or len(q)==1 and q[0]==m else'NO')
``` | output | 1 | 93,553 | 8 | 187,107 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.
Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when:
* all parts of the wall has the same height;
* the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.
Output
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
Note
In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete. | instruction | 0 | 93,554 | 8 | 187,108 |
Tags: data structures, implementation
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
b=[0]*1000000
sp=-1
max=0
f=True;
for i in range(n):
sp=sp+1
b[sp]=a[i]
if b[sp]>max:
max=b[sp]
if sp>0:
if b[sp]>b[sp-1]:
f=False
if b[sp]==b[sp-1]:
sp=sp-2
if f==True :
if sp==0:
if b[sp]>=max:
print("YES")
else:
print("NO")
elif sp<0:
print("YES")
else:
print("NO")
else:
print("NO")
``` | output | 1 | 93,554 | 8 | 187,109 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.
Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when:
* all parts of the wall has the same height;
* the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.
Output
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
Note
In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete. | instruction | 0 | 93,555 | 8 | 187,110 |
Tags: data structures, implementation
Correct Solution:
```
n=int(input())
l=[int(x) for x in input().split()]
st=[]
for i in l:
d=i
if len(st) and st[-1]==d:
st.pop()
elif len(st)==0 or st[-1]>d:
st.append(d)
else:
print("NO")
break
else:
if len(st)==0 or len(st)==1 and st[-1]==max(l):
print("YES")
else:
print("NO")
``` | output | 1 | 93,555 | 8 | 187,111 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.
Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when:
* all parts of the wall has the same height;
* the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.
Output
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
Note
In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete.
Submitted Solution:
```
import sys
n = int(sys.stdin.readline())
cur_str = ((sys.stdin.readline()).strip()).split()
array = [int(elem) for elem in cur_str]
i = 0
stack = []
ans = True
maximum = -1
while i<len(array):
maximum = max(maximum,array[i])
if not stack or array[i] < stack[-1]: stack.append(array[i])
else:
if stack[-1] < array[i]:
ans = False
break
elif stack[-1] == array[i]: stack.pop()
i+=1
for i in range(1,len(stack)):
if stack[i]!=stack[i-1]:
ans = False
break
if stack and min(stack) < maximum: ans = False
if ans == True or n==1: print("YES")
else: print("NO")
``` | instruction | 0 | 93,556 | 8 | 187,112 |
Yes | output | 1 | 93,556 | 8 | 187,113 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.
Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when:
* all parts of the wall has the same height;
* the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.
Output
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
Note
In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete.
Submitted Solution:
```
from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import defaultdict
from itertools import combinations
import functools
import sys
import math
MAX = sys.maxsize
MAXN = 10**6+10
MOD = 998244353
def isprime(n):
n = abs(int(n))
if n < 2:
return False
if n == 2:
return True
if not n & 1:
return False
for x in range(3, int(n**0.5) + 1, 2):
if n % x == 0:
return False
return True
def mhd(a,b,x,y):
return abs(a-x)+abs(b-y)
def numIN():
return(map(int,sys.stdin.readline().strip().split()))
def charIN():
return(sys.stdin.readline().strip().split())
t = [(-1,-1)]*1000010
def create(a):
global t,n
for i in range(n,2*n):
t[i] = (a[i-n],i-n)
for i in range(n-1,0,-1):
x = [t[2*i],t[2*i+1]]
x.sort(key = lambda x:x[0])
t[i] = x[1]
def update(idx,value):
global t,n
idx = idx+n
t[idx] = value
while(idx>1):
idx = idx//2
x = [t[2*idx],t[2*idx+1]]
x.sort(key = lambda x:x[0])
t[idx] = x[1]
def dis(a,b,k):
ans = 0
for i in range(k):
ans+=abs(a[i]-b[i])
return ans
def cal(n,k):
res = 1
c = [0]*(k+1)
c[0]=1
for i in range(1,n+1):
for j in range(min(i,k),0,-1):
c[j] = (c[j]+c[j-1])%MOD
return c[k]
n = int(input())
l = list(numIN())
x = []
for i in range(n):
if x and x[-1]==l[i]:
x.pop()
continue
if x and x[-1]<l[i]:
print('NO')
exit(0)
x.append(l[i])
if x and x[-1]!=max(l):
print('NO')
else:
print('YES')
``` | instruction | 0 | 93,557 | 8 | 187,114 |
Yes | output | 1 | 93,557 | 8 | 187,115 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.
Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when:
* all parts of the wall has the same height;
* the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.
Output
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
Note
In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete.
Submitted Solution:
```
import sys
input = sys.stdin.readline
from collections import deque
n=int(input())
A=list(map(int,input().split()))
AX=[(A[i],i) for i in range(n)]
QUE = deque()
for i in range(n):
QUE.append(AX[i])
while len(QUE)>=2 and QUE[-1][0]==QUE[-2][0] and A[QUE[-2][1]]>=A[QUE[-2][1]+1]:
QUE.pop()
QUE.pop()
if len(QUE)>=2:
print("NO")
elif len(QUE)==1:
if QUE[0][0]==max(A):
print("YES")
else:
print("NO")
else:
print("YES")
``` | instruction | 0 | 93,558 | 8 | 187,116 |
Yes | output | 1 | 93,558 | 8 | 187,117 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.
Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when:
* all parts of the wall has the same height;
* the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.
Output
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
Note
In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete.
Submitted Solution:
```
def main():
n = int(input())
m = 0
stack = []
for val in map(int, input().split()):
if stack:
if val == stack[-1]:
stack.pop()
elif val > stack[-1]:
stack.append(val)
break
else:
stack.append(val)
else:
stack.append(val)
m = max(m, val)
print('YES' if len(stack) == 0 or len(stack) == 1 and stack[0] == m else 'NO')
if __name__ == '__main__':
main()
``` | instruction | 0 | 93,559 | 8 | 187,118 |
Yes | output | 1 | 93,559 | 8 | 187,119 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.
Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when:
* all parts of the wall has the same height;
* the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.
Output
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
Note
In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
b=[0]*10000
sp=0
for i in range(n):
b[sp]=a[i]
sp=sp+1
if sp>0:
if b[sp-1]==b[sp-2]:
sp=sp-2
if sp<=1:
print("YES")
else:
print("NO")
``` | instruction | 0 | 93,560 | 8 | 187,120 |
No | output | 1 | 93,560 | 8 | 187,121 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.
Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when:
* all parts of the wall has the same height;
* the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.
Output
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
Note
In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete.
Submitted Solution:
```
#!/usr/bin/env python3
import sys
def rint():
return map(int, sys.stdin.readline().split())
#lines = stdin.readlines()
n = int(input())
a = list(rint())
stack = [a[0]]
for i in range(1, n):
if len(stack) == 0:
stack.append(a[i])
if a[i] == stack[-1]:
stack.pop()
else:
stack.append(a[i])
if len(stack) > 1:
print("NO")
else:
print("YES")
``` | instruction | 0 | 93,561 | 8 | 187,122 |
No | output | 1 | 93,561 | 8 | 187,123 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.
Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when:
* all parts of the wall has the same height;
* the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.
Output
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
Note
In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete.
Submitted Solution:
```
n=int(input())
l=[int(x) for x in input().split()]
st=[]
for i in l:
d=i
if len(st) and st[-1]==d:
st.pop()
else:
st.append(d)
if len(st)<2:
print("YES")
else:
print("NO")
``` | instruction | 0 | 93,562 | 8 | 187,124 |
No | output | 1 | 93,562 | 8 | 187,125 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th part of the wall.
Vova can only use 2 × 1 bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some i the current height of part i is the same as for part i + 1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 1 of the wall or to the right of part n of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when:
* all parts of the wall has the same height;
* the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of parts in the wall.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the initial heights of the parts of the wall.
Output
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
Examples
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
Note
In the first example Vova can put a brick on parts 2 and 3 to make the wall [2, 2, 2, 2, 5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5, 5, 5, 5, 5].
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
b=[0]*100001
sp=-1
max=0
f=True;
for i in range(n):
sp=sp+1
b[sp]=a[i]
if b[sp]>max:
max=b[sp]
if sp>0:
if b[sp]>b[sp-1]:
f=False
if b[sp]==b[sp-1]:
sp=sp-2
if f==True :
if sp==0:
if b[sp]>max:
print("YES")
else:
print("NO")
elif sp<0:
print("YES")
else:
print("NO")
``` | instruction | 0 | 93,563 | 8 | 187,126 |
No | output | 1 | 93,563 | 8 | 187,127 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k^2 burles.
Since rooms can have different sizes, you calculated that you need at least sum_i sections in total in the i-th room.
For each room calculate the minimum cost to install at most c_i radiators with total number of sections not less than sum_i.
Input
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of rooms.
Each of the next n lines contains the description of some room. The i-th line contains two integers c_i and sum_i (1 ≤ c_i, sum_i ≤ 10^4) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most c_i radiators with total number of sections not less than sum_i.
Example
Input
4
1 10000
10000 1
2 6
4 6
Output
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum_1 sections. The cost of the radiator is equal to (10^4)^2 = 10^8.
In the second room, you can install up to 10^4 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 7 variants to install radiators: [6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]. The optimal variant is [3, 3] and it costs 3^2+ 3^2 = 18. | instruction | 0 | 93,612 | 8 | 187,224 |
Tags: math
Correct Solution:
```
n=int(input())
for _ in range(n):
c, s = map(int,input().split())
q = s//c
r = s%c
print(r*(q+1)**2 + (c-r)*q*q)
``` | output | 1 | 93,612 | 8 | 187,225 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k^2 burles.
Since rooms can have different sizes, you calculated that you need at least sum_i sections in total in the i-th room.
For each room calculate the minimum cost to install at most c_i radiators with total number of sections not less than sum_i.
Input
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of rooms.
Each of the next n lines contains the description of some room. The i-th line contains two integers c_i and sum_i (1 ≤ c_i, sum_i ≤ 10^4) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most c_i radiators with total number of sections not less than sum_i.
Example
Input
4
1 10000
10000 1
2 6
4 6
Output
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum_1 sections. The cost of the radiator is equal to (10^4)^2 = 10^8.
In the second room, you can install up to 10^4 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 7 variants to install radiators: [6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]. The optimal variant is [3, 3] and it costs 3^2+ 3^2 = 18. | instruction | 0 | 93,613 | 8 | 187,226 |
Tags: math
Correct Solution:
```
t = int(input())
for c in range (t):
ss = 0
a,b= map(int, input().split())
if b<=a:
print(b)
else :
de = int(b/a)
ss = de**2 *(a-b%a) +(de+1)**2 *(b%a)
print(ss)
``` | output | 1 | 93,613 | 8 | 187,227 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k^2 burles.
Since rooms can have different sizes, you calculated that you need at least sum_i sections in total in the i-th room.
For each room calculate the minimum cost to install at most c_i radiators with total number of sections not less than sum_i.
Input
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of rooms.
Each of the next n lines contains the description of some room. The i-th line contains two integers c_i and sum_i (1 ≤ c_i, sum_i ≤ 10^4) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most c_i radiators with total number of sections not less than sum_i.
Example
Input
4
1 10000
10000 1
2 6
4 6
Output
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum_1 sections. The cost of the radiator is equal to (10^4)^2 = 10^8.
In the second room, you can install up to 10^4 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 7 variants to install radiators: [6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]. The optimal variant is [3, 3] and it costs 3^2+ 3^2 = 18. | instruction | 0 | 93,614 | 8 | 187,228 |
Tags: math
Correct Solution:
```
''' Hey stalker :) '''
INF = 10**10
def main():
print = out.append
''' Cook your dish here! '''
c, sum = get_list()
x = 0
while (x)*c<=sum: x+=1
res = c*(x-1)**2
res += (sum - (x-1)*c)*(2*x-1)
print(res)
''' Pythonista fLite 1.1 '''
import sys
#from collections import defaultdict, Counter
#from functools import reduce
#import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
#main()
[main() for _ in range(int(input()))]
print(*out, sep='\n')
``` | output | 1 | 93,614 | 8 | 187,229 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k^2 burles.
Since rooms can have different sizes, you calculated that you need at least sum_i sections in total in the i-th room.
For each room calculate the minimum cost to install at most c_i radiators with total number of sections not less than sum_i.
Input
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of rooms.
Each of the next n lines contains the description of some room. The i-th line contains two integers c_i and sum_i (1 ≤ c_i, sum_i ≤ 10^4) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most c_i radiators with total number of sections not less than sum_i.
Example
Input
4
1 10000
10000 1
2 6
4 6
Output
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum_1 sections. The cost of the radiator is equal to (10^4)^2 = 10^8.
In the second room, you can install up to 10^4 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 7 variants to install radiators: [6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]. The optimal variant is [3, 3] and it costs 3^2+ 3^2 = 18. | instruction | 0 | 93,615 | 8 | 187,230 |
Tags: math
Correct Solution:
```
for i in range(int(input())):
c, sumi = [int(x) for x in input().split()]
deg = sumi//c
res = ((deg + 1)**2) * (sumi%c) + (c - sumi%c)*(deg**2)
print(res)
``` | output | 1 | 93,615 | 8 | 187,231 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k^2 burles.
Since rooms can have different sizes, you calculated that you need at least sum_i sections in total in the i-th room.
For each room calculate the minimum cost to install at most c_i radiators with total number of sections not less than sum_i.
Input
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of rooms.
Each of the next n lines contains the description of some room. The i-th line contains two integers c_i and sum_i (1 ≤ c_i, sum_i ≤ 10^4) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most c_i radiators with total number of sections not less than sum_i.
Example
Input
4
1 10000
10000 1
2 6
4 6
Output
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum_1 sections. The cost of the radiator is equal to (10^4)^2 = 10^8.
In the second room, you can install up to 10^4 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 7 variants to install radiators: [6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]. The optimal variant is [3, 3] and it costs 3^2+ 3^2 = 18. | instruction | 0 | 93,616 | 8 | 187,232 |
Tags: math
Correct Solution:
```
n = int(input())
for i in range(n):
c, s = map(int, input().strip().split())
left = s % c
v = s // c
o = 0
for i in range(left):
o += (v + 1) ** 2
for i in range(left, c):
o += v ** 2
print(o)
``` | output | 1 | 93,616 | 8 | 187,233 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k^2 burles.
Since rooms can have different sizes, you calculated that you need at least sum_i sections in total in the i-th room.
For each room calculate the minimum cost to install at most c_i radiators with total number of sections not less than sum_i.
Input
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of rooms.
Each of the next n lines contains the description of some room. The i-th line contains two integers c_i and sum_i (1 ≤ c_i, sum_i ≤ 10^4) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most c_i radiators with total number of sections not less than sum_i.
Example
Input
4
1 10000
10000 1
2 6
4 6
Output
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum_1 sections. The cost of the radiator is equal to (10^4)^2 = 10^8.
In the second room, you can install up to 10^4 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 7 variants to install radiators: [6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]. The optimal variant is [3, 3] and it costs 3^2+ 3^2 = 18. | instruction | 0 | 93,617 | 8 | 187,234 |
Tags: math
Correct Solution:
```
n = int(input())
for _ in range(n):
c, su = map(int, input().split())
ci = [0] * c
while su > 0:
for i in range(c):
if su > 0:
ci[i] += 1
su -= 1
else:
break
to = 0
for i in range(c):
to += ci[i] ** 2
print(to)
``` | output | 1 | 93,617 | 8 | 187,235 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k^2 burles.
Since rooms can have different sizes, you calculated that you need at least sum_i sections in total in the i-th room.
For each room calculate the minimum cost to install at most c_i radiators with total number of sections not less than sum_i.
Input
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of rooms.
Each of the next n lines contains the description of some room. The i-th line contains two integers c_i and sum_i (1 ≤ c_i, sum_i ≤ 10^4) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most c_i radiators with total number of sections not less than sum_i.
Example
Input
4
1 10000
10000 1
2 6
4 6
Output
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum_1 sections. The cost of the radiator is equal to (10^4)^2 = 10^8.
In the second room, you can install up to 10^4 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 7 variants to install radiators: [6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]. The optimal variant is [3, 3] and it costs 3^2+ 3^2 = 18. | instruction | 0 | 93,618 | 8 | 187,236 |
Tags: math
Correct Solution:
```
from collections import defaultdict
t = int(input())
while(t>0):
a,b= [int(i) for i in input().split()]
if a==1 or b==1:
ans = b**2
else:
curr = b//a
rem = b%a
temp = curr-rem
s = a-rem
ans = s*(curr**2)+rem*(curr+1)**2
print(ans)
t-=1
``` | output | 1 | 93,618 | 8 | 187,237 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k^2 burles.
Since rooms can have different sizes, you calculated that you need at least sum_i sections in total in the i-th room.
For each room calculate the minimum cost to install at most c_i radiators with total number of sections not less than sum_i.
Input
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of rooms.
Each of the next n lines contains the description of some room. The i-th line contains two integers c_i and sum_i (1 ≤ c_i, sum_i ≤ 10^4) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most c_i radiators with total number of sections not less than sum_i.
Example
Input
4
1 10000
10000 1
2 6
4 6
Output
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum_1 sections. The cost of the radiator is equal to (10^4)^2 = 10^8.
In the second room, you can install up to 10^4 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 7 variants to install radiators: [6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]. The optimal variant is [3, 3] and it costs 3^2+ 3^2 = 18. | instruction | 0 | 93,619 | 8 | 187,238 |
Tags: math
Correct Solution:
```
'''
Created on 2019. 9. 21.
@author: kkhh88
'''
#q = int(input())
#x, y = map(int,input().split(' '))
#print (' '.join(list(map(str, s))))
q = int(input())
for i in range(q):
x, y = map(int,input().split(' '))
c = y // x
d = y % x
sum = (c + 1) * (c + 1) * d + c * c * (x - d)
print (sum)
``` | output | 1 | 93,619 | 8 | 187,239 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k^2 burles.
Since rooms can have different sizes, you calculated that you need at least sum_i sections in total in the i-th room.
For each room calculate the minimum cost to install at most c_i radiators with total number of sections not less than sum_i.
Input
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of rooms.
Each of the next n lines contains the description of some room. The i-th line contains two integers c_i and sum_i (1 ≤ c_i, sum_i ≤ 10^4) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most c_i radiators with total number of sections not less than sum_i.
Example
Input
4
1 10000
10000 1
2 6
4 6
Output
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum_1 sections. The cost of the radiator is equal to (10^4)^2 = 10^8.
In the second room, you can install up to 10^4 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 7 variants to install radiators: [6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]. The optimal variant is [3, 3] and it costs 3^2+ 3^2 = 18.
Submitted Solution:
```
T = int(input())
anwer = ""
for t in range(T):
text = input().split(' ')
maximum = int(text[0])
need = int(text[1])
one = need // maximum
if one == 0:
anwer += str(need) + '\n'
continue
ost = need - maximum * one
if ost == 0:
n = need / one
anwer += str(int(one**2 * n)) + '\n'
continue
boost = ost // maximum
boost2 = ost - maximum * boost
one += boost
cost = 0
k = maximum - boost2
for i in range(maximum):
if boost2:
cost += (one + 1)**2
boost2 -= 1
else:
cost += one**2 * k
break
anwer += str(int(cost)) + '\n'
print(anwer)
``` | instruction | 0 | 93,620 | 8 | 187,240 |
Yes | output | 1 | 93,620 | 8 | 187,241 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k^2 burles.
Since rooms can have different sizes, you calculated that you need at least sum_i sections in total in the i-th room.
For each room calculate the minimum cost to install at most c_i radiators with total number of sections not less than sum_i.
Input
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of rooms.
Each of the next n lines contains the description of some room. The i-th line contains two integers c_i and sum_i (1 ≤ c_i, sum_i ≤ 10^4) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most c_i radiators with total number of sections not less than sum_i.
Example
Input
4
1 10000
10000 1
2 6
4 6
Output
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum_1 sections. The cost of the radiator is equal to (10^4)^2 = 10^8.
In the second room, you can install up to 10^4 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 7 variants to install radiators: [6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]. The optimal variant is [3, 3] and it costs 3^2+ 3^2 = 18.
Submitted Solution:
```
n = int(input())
for _ in range(n):
c,k = map(int,input().strip().split())
x = k//c
y = k%c
ans = y*((x+1)**2)+(c-y)*(x**2)
print(ans)
``` | instruction | 0 | 93,621 | 8 | 187,242 |
Yes | output | 1 | 93,621 | 8 | 187,243 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k^2 burles.
Since rooms can have different sizes, you calculated that you need at least sum_i sections in total in the i-th room.
For each room calculate the minimum cost to install at most c_i radiators with total number of sections not less than sum_i.
Input
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of rooms.
Each of the next n lines contains the description of some room. The i-th line contains two integers c_i and sum_i (1 ≤ c_i, sum_i ≤ 10^4) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most c_i radiators with total number of sections not less than sum_i.
Example
Input
4
1 10000
10000 1
2 6
4 6
Output
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum_1 sections. The cost of the radiator is equal to (10^4)^2 = 10^8.
In the second room, you can install up to 10^4 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 7 variants to install radiators: [6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]. The optimal variant is [3, 3] and it costs 3^2+ 3^2 = 18.
Submitted Solution:
```
for i in ' '*int(input()):
c,sum=map(int,input().split())
k=sum//c
r=sum%c
print((k+1)**2*r+k**2*(c-r))
``` | instruction | 0 | 93,622 | 8 | 187,244 |
Yes | output | 1 | 93,622 | 8 | 187,245 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k^2 burles.
Since rooms can have different sizes, you calculated that you need at least sum_i sections in total in the i-th room.
For each room calculate the minimum cost to install at most c_i radiators with total number of sections not less than sum_i.
Input
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of rooms.
Each of the next n lines contains the description of some room. The i-th line contains two integers c_i and sum_i (1 ≤ c_i, sum_i ≤ 10^4) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most c_i radiators with total number of sections not less than sum_i.
Example
Input
4
1 10000
10000 1
2 6
4 6
Output
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum_1 sections. The cost of the radiator is equal to (10^4)^2 = 10^8.
In the second room, you can install up to 10^4 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 7 variants to install radiators: [6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]. The optimal variant is [3, 3] and it costs 3^2+ 3^2 = 18.
Submitted Solution:
```
for i in range(int(input())):
a, b = map(int, input().split())
if a == 1 or b == 1:
print(pow(b, 2))
else:
ans = [0]*a
while(b != 0):
for i in range(a):
if b == 0:
break
else:
ans[i] += 1
b -= 1
count = 0
for i in range(len(ans)):
count += pow(ans[i], 2)
print(count)
``` | instruction | 0 | 93,623 | 8 | 187,246 |
Yes | output | 1 | 93,623 | 8 | 187,247 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k^2 burles.
Since rooms can have different sizes, you calculated that you need at least sum_i sections in total in the i-th room.
For each room calculate the minimum cost to install at most c_i radiators with total number of sections not less than sum_i.
Input
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of rooms.
Each of the next n lines contains the description of some room. The i-th line contains two integers c_i and sum_i (1 ≤ c_i, sum_i ≤ 10^4) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most c_i radiators with total number of sections not less than sum_i.
Example
Input
4
1 10000
10000 1
2 6
4 6
Output
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum_1 sections. The cost of the radiator is equal to (10^4)^2 = 10^8.
In the second room, you can install up to 10^4 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 7 variants to install radiators: [6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]. The optimal variant is [3, 3] and it costs 3^2+ 3^2 = 18.
Submitted Solution:
```
n = int(input())
while(n):
sum = 0
a,b = map(int,input().split())
if a == 1:
print(b^2)
elif a>b:
print(b)
else:
z = (b//a) +1
x = z-1
m = b%a
r = a - m
sum += (m * (z^2))
sum += (r * (x^2))
print(sum)
n-=1
``` | instruction | 0 | 93,624 | 8 | 187,248 |
No | output | 1 | 93,624 | 8 | 187,249 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k^2 burles.
Since rooms can have different sizes, you calculated that you need at least sum_i sections in total in the i-th room.
For each room calculate the minimum cost to install at most c_i radiators with total number of sections not less than sum_i.
Input
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of rooms.
Each of the next n lines contains the description of some room. The i-th line contains two integers c_i and sum_i (1 ≤ c_i, sum_i ≤ 10^4) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most c_i radiators with total number of sections not less than sum_i.
Example
Input
4
1 10000
10000 1
2 6
4 6
Output
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum_1 sections. The cost of the radiator is equal to (10^4)^2 = 10^8.
In the second room, you can install up to 10^4 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 7 variants to install radiators: [6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]. The optimal variant is [3, 3] and it costs 3^2+ 3^2 = 18.
Submitted Solution:
```
n = int(input())
for i in range(n):
a, b = map(int,input().split())
count = 0
while (b%a!=0 and b!=0):
count+=1
b-=1
a-=1
count+=((b//a)**2)*a
print(count)
``` | instruction | 0 | 93,625 | 8 | 187,250 |
No | output | 1 | 93,625 | 8 | 187,251 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k^2 burles.
Since rooms can have different sizes, you calculated that you need at least sum_i sections in total in the i-th room.
For each room calculate the minimum cost to install at most c_i radiators with total number of sections not less than sum_i.
Input
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of rooms.
Each of the next n lines contains the description of some room. The i-th line contains two integers c_i and sum_i (1 ≤ c_i, sum_i ≤ 10^4) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most c_i radiators with total number of sections not less than sum_i.
Example
Input
4
1 10000
10000 1
2 6
4 6
Output
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum_1 sections. The cost of the radiator is equal to (10^4)^2 = 10^8.
In the second room, you can install up to 10^4 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 7 variants to install radiators: [6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]. The optimal variant is [3, 3] and it costs 3^2+ 3^2 = 18.
Submitted Solution:
```
from math import gcd
for _ in range(int(input())):
ci,si=map(int,input().split())
if si<ci:
print(si)
else:
ans=0
t=si//2
rem = si%2
if rem:
ans+=t**2*(ci-1)
ans+=(rem+t)**2
else:
ans+=t**2*ci
print(ans)
``` | instruction | 0 | 93,626 | 8 | 187,252 |
No | output | 1 | 93,626 | 8 | 187,253 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but the cost of the radiator with k sections is equal to k^2 burles.
Since rooms can have different sizes, you calculated that you need at least sum_i sections in total in the i-th room.
For each room calculate the minimum cost to install at most c_i radiators with total number of sections not less than sum_i.
Input
The first line contains single integer n (1 ≤ n ≤ 1000) — the number of rooms.
Each of the next n lines contains the description of some room. The i-th line contains two integers c_i and sum_i (1 ≤ c_i, sum_i ≤ 10^4) — the maximum number of radiators and the minimum total number of sections in the i-th room, respectively.
Output
For each room print one integer — the minimum possible cost to install at most c_i radiators with total number of sections not less than sum_i.
Example
Input
4
1 10000
10000 1
2 6
4 6
Output
100000000
1
18
10
Note
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum_1 sections. The cost of the radiator is equal to (10^4)^2 = 10^8.
In the second room, you can install up to 10^4 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 7 variants to install radiators: [6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]. The optimal variant is [3, 3] and it costs 3^2+ 3^2 = 18.
Submitted Solution:
```
def process():
a,b = input().split()
a,b = int(a), int(b)
if b == 3 and a == 2:
print(5)
return
if a > b:
print(1)
else:
if a == 1:
print(int(b**2))
return
if b % a == 0:
res = 0
ave = int(b/a)
while b != 0:
res += ave**2
b -= ave
print(res)
else:
res = 0
ave = int(b/a)
tmp = b/a - ave
cnt = 0
for i in range(1,a+1):
if i*tmp == int(i*tmp):
cnt = i
break
for i in range(cnt):
res += int(ave)**2
for i in range(a-cnt):
res += (int(ave)+1)**2
print(res)
tests = int(input())
for test in range(tests):
process()
``` | instruction | 0 | 93,627 | 8 | 187,254 |
No | output | 1 | 93,627 | 8 | 187,255 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simpler and more convenient to use. He collected the hay into cubical hay blocks of the same size. Then he stored the blocks in his barn. After a summer spent in hard toil Sam stored A·B·C hay blocks and stored them in a barn as a rectangular parallelepiped A layers high. Each layer had B rows and each row had C blocks.
At the end of the autumn Sam came into the barn to admire one more time the hay he'd been stacking during this hard summer. Unfortunately, Sam was horrified to see that the hay blocks had been carelessly scattered around the barn. The place was a complete mess. As it turned out, thieves had sneaked into the barn. They completely dissembled and took away a layer of blocks from the parallelepiped's front, back, top and sides. As a result, the barn only had a parallelepiped containing (A - 1) × (B - 2) × (C - 2) hay blocks. To hide the evidence of the crime, the thieves had dissembled the parallelepiped into single 1 × 1 × 1 blocks and scattered them around the barn. After the theft Sam counted n hay blocks in the barn but he forgot numbers A, B и C.
Given number n, find the minimally possible and maximally possible number of stolen hay blocks.
Input
The only line contains integer n from the problem's statement (1 ≤ n ≤ 109).
Output
Print space-separated minimum and maximum number of hay blocks that could have been stolen by the thieves.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
Examples
Input
4
Output
28 41
Input
7
Output
47 65
Input
12
Output
48 105
Note
Let's consider the first sample test. If initially Sam has a parallelepiped consisting of 32 = 2 × 4 × 4 hay blocks in his barn, then after the theft the barn has 4 = (2 - 1) × (4 - 2) × (4 - 2) hay blocks left. Thus, the thieves could have stolen 32 - 4 = 28 hay blocks. If Sam initially had a parallelepiped consisting of 45 = 5 × 3 × 3 hay blocks in his barn, then after the theft the barn has 4 = (5 - 1) × (3 - 2) × (3 - 2) hay blocks left. Thus, the thieves could have stolen 45 - 4 = 41 hay blocks. No other variants of the blocks' initial arrangement (that leave Sam with exactly 4 blocks after the theft) can permit the thieves to steal less than 28 or more than 41 blocks. | instruction | 0 | 93,683 | 8 | 187,366 |
Tags: brute force, math
Correct Solution:
```
n = int(input())
u = v = 9 + 8 * n
for a in range(1, int(n ** (1 / 3)) + 1):
if n % a: continue
m = n // a
for b in range(a, int(m ** 0.5) + 1):
if m % b: continue
p = (a + 1) * (b + 2) * (m // b + 2) - n
if u > p: u = p
print(u, v)
``` | output | 1 | 93,683 | 8 | 187,367 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simpler and more convenient to use. He collected the hay into cubical hay blocks of the same size. Then he stored the blocks in his barn. After a summer spent in hard toil Sam stored A·B·C hay blocks and stored them in a barn as a rectangular parallelepiped A layers high. Each layer had B rows and each row had C blocks.
At the end of the autumn Sam came into the barn to admire one more time the hay he'd been stacking during this hard summer. Unfortunately, Sam was horrified to see that the hay blocks had been carelessly scattered around the barn. The place was a complete mess. As it turned out, thieves had sneaked into the barn. They completely dissembled and took away a layer of blocks from the parallelepiped's front, back, top and sides. As a result, the barn only had a parallelepiped containing (A - 1) × (B - 2) × (C - 2) hay blocks. To hide the evidence of the crime, the thieves had dissembled the parallelepiped into single 1 × 1 × 1 blocks and scattered them around the barn. After the theft Sam counted n hay blocks in the barn but he forgot numbers A, B и C.
Given number n, find the minimally possible and maximally possible number of stolen hay blocks.
Input
The only line contains integer n from the problem's statement (1 ≤ n ≤ 109).
Output
Print space-separated minimum and maximum number of hay blocks that could have been stolen by the thieves.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
Examples
Input
4
Output
28 41
Input
7
Output
47 65
Input
12
Output
48 105
Note
Let's consider the first sample test. If initially Sam has a parallelepiped consisting of 32 = 2 × 4 × 4 hay blocks in his barn, then after the theft the barn has 4 = (2 - 1) × (4 - 2) × (4 - 2) hay blocks left. Thus, the thieves could have stolen 32 - 4 = 28 hay blocks. If Sam initially had a parallelepiped consisting of 45 = 5 × 3 × 3 hay blocks in his barn, then after the theft the barn has 4 = (5 - 1) × (3 - 2) × (3 - 2) hay blocks left. Thus, the thieves could have stolen 45 - 4 = 41 hay blocks. No other variants of the blocks' initial arrangement (that leave Sam with exactly 4 blocks after the theft) can permit the thieves to steal less than 28 or more than 41 blocks. | instruction | 0 | 93,684 | 8 | 187,368 |
Tags: brute force, math
Correct Solution:
```
from math import sqrt
p, n = [], int(input())
def f(x, y): return (x + 2) * (y + 2) + (2 * (x + y + 2) * n) // (x * y)
for x in range(2, int(sqrt(n)) + 1):
if n % x == 0: p.append(x)
p += [n // x for x in reversed(p)]
p.append(n)
u = v = f(1, 1)
for m in p:
for x in range(1, int(sqrt(m)) + 1):
if m % x == 0: u = min(u, f(x, m // x))
print(u, v)
# Made By Mostafa_Khaled
``` | output | 1 | 93,684 | 8 | 187,369 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.