message stringlengths 2 44.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 276 109k | cluster float64 23 23 | __index_level_0__ int64 552 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output
Print a single number — the sum of all edges of the parallelepiped.
Examples
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | instruction | 0 | 103,951 | 23 | 207,902 |
Tags: brute force, geometry, math
Correct Solution:
```
import math
arr = [int(x) for x in input().split()]
print(int(4*(math.sqrt((arr[0]*arr[1])/arr[2])+math.sqrt((arr[0]*arr[2])/arr[1])+math.sqrt((arr[2]*arr[1])/arr[0]))))
``` | output | 1 | 103,951 | 23 | 207,903 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output
Print a single number — the sum of all edges of the parallelepiped.
Examples
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | instruction | 0 | 103,952 | 23 | 207,904 |
Tags: brute force, geometry, math
Correct Solution:
```
arr = input().split()
ab , bc , ca = int(arr[0]), int(arr[1]), int(arr[2])
b = (ab*bc//ca)**(1/2)
a = (ab*ca//bc)**(1/2)
c = (bc*ca//ab)**(1/2)
print(int((a+b+c)*4))
``` | output | 1 | 103,952 | 23 | 207,905 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output
Print a single number — the sum of all edges of the parallelepiped.
Examples
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
Submitted Solution:
```
import math
def solve(areas):
a = math.sqrt((areas[2] * areas[0]) / areas[1])
b = areas[0] / a
c = areas[2] / a
result = a * 4 + b * 4 + c * 4
return result
areas = [int(num) for num in input().split()]
result = solve(areas)
print(int(result))
``` | instruction | 0 | 103,953 | 23 | 207,906 |
Yes | output | 1 | 103,953 | 23 | 207,907 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output
Print a single number — the sum of all edges of the parallelepiped.
Examples
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
Submitted Solution:
```
x,y,z=map(int,input().split())
xx=(x*y/z)**0.5
yy=(y*z/x)**0.5
zz=(z*x/y)**0.5
print(int(xx+yy+zz)*4)
``` | instruction | 0 | 103,954 | 23 | 207,908 |
Yes | output | 1 | 103,954 | 23 | 207,909 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output
Print a single number — the sum of all edges of the parallelepiped.
Examples
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
Submitted Solution:
```
import math
import sys
import collections
# imgur.com/Pkt7iIf.png
def getdict(n):
d = {}
if type(n) is list:
for i in n:
if i in d:
d[i] += 1
else:
d[i] = 1
else:
for i in range(n):
t = ii()
if t in d:
d[t] += 1
else:
d[t] = 1
return d
def cdiv(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a*b) // math.gcd(a, b)
a, b, c = mi()
q = math.sqrt(a*b/c)
w = math.sqrt(b*c/a)
e = math.sqrt(a*c/b)
print(int(4*(q+w+e)))
``` | instruction | 0 | 103,955 | 23 | 207,910 |
Yes | output | 1 | 103,955 | 23 | 207,911 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output
Print a single number — the sum of all edges of the parallelepiped.
Examples
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
Submitted Solution:
```
import math
a, b, c = input().split()
a, b, c = int(a), int(b), int(c)
a1 = math.sqrt(a * b / c)
b1 = math.sqrt(c * a / b)
c1 = math.sqrt(c * b / a)
print(int(a1*4 + b1*4 + c1*4))
``` | instruction | 0 | 103,956 | 23 | 207,912 |
Yes | output | 1 | 103,956 | 23 | 207,913 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output
Print a single number — the sum of all edges of the parallelepiped.
Examples
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
Submitted Solution:
```
import math
a, b, c = map(int, input().split())
volume_sqr = math.sqrt(a * b * c)
print(4 * (volume_sqr / a + volume_sqr / b + volume_sqr / c))
``` | instruction | 0 | 103,957 | 23 | 207,914 |
No | output | 1 | 103,957 | 23 | 207,915 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output
Print a single number — the sum of all edges of the parallelepiped.
Examples
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
Submitted Solution:
```
'''input
152 108 4104
'''
def gcd(x, y):
while y != 0:
x, y = y, x % y
return x
a, b, c = map(int, input().split())
l = a * b // gcd(a, b)
l = l * c // gcd(l, c)
print((l // a + l // b + l // c) * 4 if l != max([a,b,c]) else (l // a + l // b + l // c) * 8)
``` | instruction | 0 | 103,958 | 23 | 207,916 |
No | output | 1 | 103,958 | 23 | 207,917 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output
Print a single number — the sum of all edges of the parallelepiped.
Examples
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
Submitted Solution:
```
a=[int(x) for x in input().split()]
#d*b=a[0]
#b*c=a[1]
#d*c=a[2]
#b=a[0]/d
#c=a[2]/d
#a[0]*a[2]/d**2=a[1]
d=(a[0]*a[2]/a[1])**0.5
b=a[0]/d
c=a[2]/d
print(4*d + 4*b + 4*c)
``` | instruction | 0 | 103,959 | 23 | 207,918 |
No | output | 1 | 103,959 | 23 | 207,919 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output
Print a single number — the sum of all edges of the parallelepiped.
Examples
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
Submitted Solution:
```
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
x, y, z = map(int, input().split())
if x == y == z:
print(int(x ** 0.5) * 12)
else:
if x == y:
y, z = z, y
a = gcd(x, y)
if a == min(x, y):
a = int(min(x, y) ** 0.5)
b = x // a
c = y // a
if b * c != z:
a = gcd(x, z)
b = x // a
c = z // a
print(4 * (a + b + c))
``` | instruction | 0 | 103,960 | 23 | 207,920 |
No | output | 1 | 103,960 | 23 | 207,921 |
Provide a correct Python 3 solution for this coding contest problem.
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Input
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Output
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Examples
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
Note
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything. | instruction | 0 | 104,152 | 23 | 208,304 |
"Correct Solution:
```
n = int(input())
a = [int(x) for x in input().strip().split()]
a = sorted(a)
d = []
for i in range(len(a) - 1):
d.append(a[i + 1] - a[i])
def gcd(a, b):
if(b == 0):
return a
else:
return gcd(b, a % b)
g = d[0]
for e in d:
g = gcd(g, e)
cnt = len(a)
print( int( ( a[len(a) - 1] - a[0]) / g + 1 - cnt))
``` | output | 1 | 104,152 | 23 | 208,305 |
Provide a correct Python 3 solution for this coding contest problem.
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Input
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Output
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Examples
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
Note
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything. | instruction | 0 | 104,153 | 23 | 208,306 |
"Correct Solution:
```
def nod(n, m):
if(m==0):
return n;
if(n>m):
return nod(m,n%m);
else:
return nod(n,m%n);
n=input();
x = sorted(list(map(int, input().split())))
m = min(x)
nnod=0
for i in range(len(x)):
if(i>1):
if(i==2):
nnod=nod(x[i]-x[i-1], x[i-1]-x[i-2])
else:
nnod=nod(nnod, x[i]-x[i-1])
res=0
for i in range(len(x)):
if(i>0):
res+=(x[i]-x[i-1])/nnod - 1;
print(int(res))
``` | output | 1 | 104,153 | 23 | 208,307 |
Provide a correct Python 3 solution for this coding contest problem.
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Input
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Output
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Examples
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
Note
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything. | instruction | 0 | 104,154 | 23 | 208,308 |
"Correct Solution:
```
from fractions import gcd
from functools import reduce
n = int(input())
x = list(map(int, input().split()))
x.sort()
difs = []
for i in range(len(x)-1):
difs.append(x[i+1]-x[i])
dif = reduce(gcd, difs)
mmin = x[0]
mmax = x[-1]
x = set(x)
cnt = (mmax-mmin+dif)//dif-n
print(cnt)
``` | output | 1 | 104,154 | 23 | 208,309 |
Provide a correct Python 3 solution for this coding contest problem.
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Input
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Output
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Examples
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
Note
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything. | instruction | 0 | 104,155 | 23 | 208,310 |
"Correct Solution:
```
from fractions import gcd
n=int(input())
a=input().split()
for i in range(0, n):
a[i]=int(a[i])
a.sort()
dists=[]
for i in range(1, n):
dists.append(a[i]-a[i-1])
s=dists[0]
gdc=dists[0]
for i in range(1,len(dists)):
gdc=gcd(dists[i],gdc)
s+=dists[i]
print(s//gdc-n+1)
``` | output | 1 | 104,155 | 23 | 208,311 |
Provide a correct Python 3 solution for this coding contest problem.
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Input
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Output
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Examples
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
Note
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything. | instruction | 0 | 104,156 | 23 | 208,312 |
"Correct Solution:
```
def nod(a, b):
while a!=0 and b!=0:
if a > b:
a = a % b
else:
b = b % a
return (a+b)
n = int(input())
a = list(map(int, input().split()))
a.sort()
d = nod(a[1] - a[0], a[2] - a[1])
for i in range(2, n - 1):
d = nod(a[i + 1] - a[i], d)
count = 0
for i in range(n - 1):
count += ((a[i + 1] - a[i]) // d - 1)
print(count)
``` | output | 1 | 104,156 | 23 | 208,313 |
Provide a correct Python 3 solution for this coding contest problem.
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Input
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Output
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Examples
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
Note
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything. | instruction | 0 | 104,157 | 23 | 208,314 |
"Correct Solution:
```
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
a.sort()
for i in range(1, len(a)):
a[i-1] = a[i] - a[i-1]
a.pop()
g = a[0]
s = 0
for i in range(len(a)):
s += a[i]
g = gcd(g, a[i])
s = s // g - len(a)
print(s)
``` | output | 1 | 104,157 | 23 | 208,315 |
Provide a correct Python 3 solution for this coding contest problem.
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Input
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Output
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Examples
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
Note
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything. | instruction | 0 | 104,158 | 23 | 208,316 |
"Correct Solution:
```
import sys
# For getting input from input.txt file
#sys.stdin = open('input.txt', 'r')
# Printing the Output to output.txt file
#sys.stdout = open('output.txt', 'w')
def gcd(a, b):
while a != 0 and b != 0:
if a > b:
a = a % b
else:
b = b % a
return max(a, b)
n = int(input())
s = input()
num = list(map(int, s.split(' ')))
num.sort()
slen = []
for i in range(1, n):
slen.append(num[i] - num[i - 1])
slen.sort()
minlen = slen[0]
maxlen = slen[-1]
for i in range(0, n - 1):
if minlen == 1:
break
elif slen[i] % minlen != 0:
minlen = gcd(minlen, slen[i])
print( int( (num[-1] - num[0]) / minlen - n + 1) )
``` | output | 1 | 104,158 | 23 | 208,317 |
Provide a correct Python 3 solution for this coding contest problem.
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Input
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Output
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Examples
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
Note
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything. | instruction | 0 | 104,159 | 23 | 208,318 |
"Correct Solution:
```
def gcd(a, b):
while a != 0 and b != 0:
if b > a:
b = b % a
else:
a = a % b
if a == 0:
return b
else:
return a
n = int(input())
a = input()
a = a.split()
for i in range(len(a)):
a[i] = int(a[i])
a = sorted(a)
b = a[1] - a[0]
for i in range(0, len(a) - 1):
b = gcd(b, a[i + 1] - a[i])
cnt = (a[len(a) - 1] - a[0]) // b + 1
print(cnt - n)
``` | output | 1 | 104,159 | 23 | 208,319 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Input
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Output
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Examples
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
Note
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything.
Submitted Solution:
```
import sys
import math
from collections import defaultdict,deque
n=int(sys.stdin.readline())
arr=list(map(int,sys.stdin.readline().split()))
arr.sort()
x=arr[1]-arr[0]
for i in range(n-1):
x=math.gcd(x,arr[i+1]-arr[i])
ans=0
for i in range(n-1):
dis=arr[i+1]-arr[i]
y=dis//x-1
ans+=y
print(ans)
``` | instruction | 0 | 104,160 | 23 | 208,320 |
Yes | output | 1 | 104,160 | 23 | 208,321 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Input
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Output
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Examples
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
Note
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything.
Submitted Solution:
```
n = int(input())
m = list(map(int, input().split()))
m.sort()
min_dif = m[1] - m[0]
def nod(a, b):
if b == 0:
return a
else:
return nod(b, a %b)
for i in range(1, n):
min_dif = nod(min_dif, m[i] - m[i-1])
ans = 0
for i in range(1, n):
if m[i] - m[i-1] > min_dif:
ans += (m[i] - m[i-1]) / min_dif - 1
print(int(ans))
``` | instruction | 0 | 104,161 | 23 | 208,322 |
Yes | output | 1 | 104,161 | 23 | 208,323 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Input
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Output
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Examples
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
Note
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything.
Submitted Solution:
```
import math
n,a,q,w=int(input()),sorted(map(int,input().split())),0,0
for i in range(1,n):q=math.gcd(q,a[i]-a[i-1])
for i in range(1,n):w+=(a[i]-a[i-1])//q-1
print(w)
``` | instruction | 0 | 104,162 | 23 | 208,324 |
Yes | output | 1 | 104,162 | 23 | 208,325 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Input
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Output
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Examples
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
Note
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything.
Submitted Solution:
```
def nod(a, b):
if (b == 0):
return a;
else:
return nod(b, a%b);
def main():
n = int(input());
arr = [int(i) for i in input().split()]
arr.sort()
no = 0;
for i in range(1, n):
no = nod(arr[i] - arr[i-1], no)
ans = 0;
for i in range(1, n):
ans += -1 + (arr[i] - arr[i-1]) // no
print(ans)
main()
``` | instruction | 0 | 104,163 | 23 | 208,326 |
Yes | output | 1 | 104,163 | 23 | 208,327 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Input
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Output
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Examples
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
Note
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything.
Submitted Solution:
```
n = int(input())
x = list(map(int, input().split()))
x.sort()
dif = 1e10
for i in range(len(x)-1):
dif = min(dif, x[i+1]-x[i])
mmin = x[0]
mmax = x[-1]
x = set(x)
cnt = 0
for i in range(mmin, mmax+100, dif):
if i <= mmax and i not in x:
cnt += 1
print(cnt)
``` | instruction | 0 | 104,164 | 23 | 208,328 |
No | output | 1 | 104,164 | 23 | 208,329 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Input
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Output
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Examples
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
Note
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything.
Submitted Solution:
```
import sys
# For getting input from input.txt file
#sys.stdin = open('input.txt', 'r')
# Printing the Output to output.txt file
#sys.stdout = open('output.txt', 'w')
def gcd(a, b):
while a != 0 and b != 0:
if a > b:
a = a % b
else:
b = b % a
return max(a, b)
n = int(input())
s = input()
num = list(map(int, s.split(' ')))
num.sort()
slen = []
for i in range(1, n):
slen.append(num[i] - num[i - 1])
slen.sort()
minlen = slen[0]
maxlen = slen[-1]
for i in range(0, n - 1):
if minlen == 1:
break
elif slen[i] % minlen != 0:
minlen = gcd(minlen, slen[i])
print((num[-1] - num[0]) / minlen - n + 1)
``` | instruction | 0 | 104,165 | 23 | 208,330 |
No | output | 1 | 104,165 | 23 | 208,331 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Input
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Output
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Examples
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
Note
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything.
Submitted Solution:
```
def gcd(a, b):
while b != 0:
tmp = b
b = a % b
a = tmp
return a
n = int(input())
v = list(map(int, input().split()))
minrast = abs(v[1] - v[0])
for i in range(1, n):
minrast = min(minrast, abs(v[i] - v[i-1]))
f = 1
tmp = 0
cur = v[0]
for i in range(1, n):
tmprast = abs(v[i] - cur)
if (tmprast % minrast == 0):
tmp += tmprast // minrast - 1
else:
f = 0
break
cur = v[i]
if f == 1:
ans = tmp
print(ans)
else:
print(abs(v[n-1] - v[0]) - n + 1)
``` | instruction | 0 | 104,166 | 23 | 208,332 |
No | output | 1 | 104,166 | 23 | 208,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Input
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Output
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
Examples
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
Note
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything.
Submitted Solution:
```
a = input()
a = int(a)
x = sorted(list(map(int, input().split())))
mn = 100000000000
cnt = 0
i = 0
for i in range(a):
if cnt > 0:
if x[i] - x[i - 1] < mn:
mn = x[i] - x[i - 1]
cnt = cnt + 1
ans = 0
cnt = 0;
i = 0
for i in range(a):
if cnt > 0:
ans = ans + ((x[i] - x[i - 1]) // mn - 1)
cnt = cnt + 1
print(ans)
``` | instruction | 0 | 104,167 | 23 | 208,334 |
No | output | 1 | 104,167 | 23 | 208,335 |
Provide a correct Python 3 solution for this coding contest problem.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795 | instruction | 0 | 104,187 | 23 | 208,374 |
"Correct Solution:
```
N, Q, *Query = [int(_) for _ in open(0).read().split()]
D = Query[::2]
X = Query[1::2]
class LazySegmentTree():
def __init__(self, array, f, g, h, ti, ei):
"""
Parameters
----------
array : list
to construct segment tree from
f : func
binary operation of the monoid
T x T -> T
T is dat
g : func
binary operation of the monoid
T x E -> T
T is dat, E is laz
h : func
binary operation of the monoid
E x E -> T
E is laz
ti : T
identity element of T
ei : E
identity element of E
"""
self.f = f
self.g = g
self.h = h
self.ti = ti
self.ei = ei
self.height = height = len(array).bit_length()
self.n = n = 2**height
self.dat = dat = [ti] * n + array + [ti] * (n - len(array))
self.laz = [ei] * (2 * n)
for i in range(n - 1, 0, -1): # build
dat[i] = f(dat[i << 1], dat[i << 1 | 1])
def reflect(self, k):
dat = self.dat
ei = self.ei
laz = self.laz
g = self.g
return self.dat[k] if laz[k] is ei else g(dat[k], laz[k])
def evaluate(self, k):
laz = self.laz
ei = self.ei
reflect = self.reflect
dat = self.dat
h = self.h
if laz[k] is ei:
return
laz[(k << 1) | 0] = h(laz[(k << 1) | 0], laz[k])
laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k])
dat[k] = reflect(k)
laz[k] = ei
def thrust(self, k):
height = self.height
evaluate = self.evaluate
for i in range(height, 0, -1):
evaluate(k >> i)
def recalc(self, k):
dat = self.dat
reflect = self.reflect
f = self.f
while k:
k >>= 1
dat[k] = f(reflect((k << 1) | 0), reflect((k << 1) | 1))
def update(self, a, b, x): # set value at position [a, b) (0-indexed)
thrust = self.thrust
n = self.n
h = self.h
laz = self.laz
recalc = self.recalc
a += n
b += n - 1
l = a
r = b + 1
thrust(a)
thrust(b)
while l < r:
if l & 1:
laz[l] = h(laz[l], x)
l += 1
if r & 1:
r -= 1
laz[r] = h(laz[r], x)
l >>= 1
r >>= 1
recalc(a)
recalc(b)
def set_val(self, a, x):
n = self.n
thrust = self.thrust
dat = self.dat
laz = self.laz
recalc = self.recalc
ei = self.ei
a += n
thrust(a)
dat[a] = x
laz[a] = ei
recalc(a)
def query(self, a, b): # result on interval [a, b) (0-indexed)
f = self.f
ti = self.ti
n = self.n
thrust = self.thrust
reflect = self.reflect
a += n
b += n - 1
thrust(a)
thrust(b)
l = a
r = b + 1
vl = vr = ti
while l < r:
if l & 1:
vl = f(vl, reflect(l))
l += 1
if r & 1:
r -= 1
vr = f(reflect(r), vr)
l >>= 1
r >>= 1
return f(vl, vr)
#RSQ and RUQ
array = [N] * (N + 1)
f = lambda a, b: a if b == 0 else b
g = lambda a, b: min(a, b)
h = lambda a, b: min(a, b)
ti = 0
ei = float('inf')
lst1 = LazySegmentTree(array=array, ti=ti, ei=ei, f=f, g=g, h=h)
lst2 = LazySegmentTree(array=array, ti=ti, ei=ei, f=f, g=g, h=h)
ans = 0
for d, x in zip(D, X):
if d == 1:
y = lst1.query(x, x + 1)
ans += y - 2
lst2.update(1, y, x)
else:
y = lst2.query(x, x + 1)
ans += y - 2
lst1.update(1, y, x)
ans = (N - 2)**2 - ans
print(ans)
``` | output | 1 | 104,187 | 23 | 208,375 |
Provide a correct Python 3 solution for this coding contest problem.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795 | instruction | 0 | 104,188 | 23 | 208,376 |
"Correct Solution:
```
n,q = map(int,input().split())
yoko = [-n]
yoko2 = [-n]
yokol = 1
tate = [-n]
tate2 = [-n]
tatel = 1
last = [n,n]
import bisect
ans = (n-2)**2
#print(ans)
for _ in range(q):
a,c = map(int,input().split())
if a == 1:
b = bisect.bisect_left(yoko,-c)
if b == yokol:
yoko.append(-c)
yoko2.append(-last[0])
yokol += 1
last[1] = c
ans -= last[0]-2
else:
ans -= -yoko2[b] - 2
if a == 2:
b = bisect.bisect_left(tate,-c)
if b == tatel:
tate.append(-c)
tate2.append(-last[1])
tatel += 1
last[0] = c
ans -= last[1]-2
else:
ans -= -tate2[b] - 2
#print(yoko)
#print(yoko2)
#print(tate)
#print(tate2)
print(ans)
``` | output | 1 | 104,188 | 23 | 208,377 |
Provide a correct Python 3 solution for this coding contest problem.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795 | instruction | 0 | 104,189 | 23 | 208,378 |
"Correct Solution:
```
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, Q = mapint()
verti = [N-2]*(N-1)
horiz = [N-2]*(N-1)
left, top = N-2, N-2
ans = (N-2)**2
last_top = (N-2, N-2)
last_left = (N-2, N-2)
for _ in range(Q):
c, x = mapint()
x -= 1
if c==1:
if x<=left:
ans -= top
left = x-1
for i in range(left, last_left[0]+1):
horiz[i] = last_top[1]
last_left = (left, x-1)
else:
ans -= horiz[x-1]
if c==2:
if x<=top:
ans -= left
top = x-1
for i in range(top, last_top[0]+1):
verti[i] = last_left[1]
last_top = (top, x-1)
else:
ans -= verti[x-1]
print(ans)
``` | output | 1 | 104,189 | 23 | 208,379 |
Provide a correct Python 3 solution for this coding contest problem.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795 | instruction | 0 | 104,190 | 23 | 208,380 |
"Correct Solution:
```
class SegTree:
X_unit = 1 << 30
X_f = min
def __init__(self, N):
self.N = N
self.X = [self.X_unit] * (N + N)
def build(self, seq):
for i, x in enumerate(seq, self.N):
self.X[i] = x
for i in range(self.N - 1, 0, -1):
self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])
def set_val(self, i, x):
i += self.N
self.X[i] = x
while i > 1:
i >>= 1
self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])
def fold(self, L, R):
L += self.N
R += self.N
vL = self.X_unit
vR = self.X_unit
while L < R:
if L & 1:
vL = self.X_f(vL, self.X[L])
L += 1
if R & 1:
R -= 1
vR = self.X_f(self.X[R], vR)
L >>= 1
R >>= 1
return self.X_f(vL, vR)
N, Q=map(int,input().split())
S1=SegTree(N)
S2=SegTree(N)
S1.build([N]*N)
S2.build([N]*N)
ans=(N-2)**2
for i in range(Q):
j, x=map(int,input().split())
if j==1:
l=S2.fold(x-1,N)
ans-=l-2
S1.set_val(l-1,min(x,S1.X[l-1+N]))
if j==2:
l=S1.fold(x-1,N)
ans-=l-2
S2.set_val(l-1,min(x,S2.X[l-1+N]))
print(ans)
``` | output | 1 | 104,190 | 23 | 208,381 |
Provide a correct Python 3 solution for this coding contest problem.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795 | instruction | 0 | 104,191 | 23 | 208,382 |
"Correct Solution:
```
import sys
def solve():
input = sys.stdin.readline
N, Q = map(int, input().split())
total = (N - 2) ** 2
rb = N
db = N
D = [N] * (N + 1)
R = [N] * (N + 1)
for _ in range(Q):
a, b = map(int, input().split())
if a == 1: #横向き
if b < db:
total -= (rb - 2)
for i in range(b, db): R[i] = rb
db = b
else:
total -= (R[b] - 2)
else: #縦向き
if b < rb:
total -= (db - 2)
for i in range(b, rb): D[i] = db
rb = b
else:
total -= (D[b] - 2)
print(total)
return 0
if __name__ == "__main__":
solve()
``` | output | 1 | 104,191 | 23 | 208,383 |
Provide a correct Python 3 solution for this coding contest problem.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795 | instruction | 0 | 104,192 | 23 | 208,384 |
"Correct Solution:
```
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
# from heapq import heappop, heappush
# from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
import math
# from itertools import product, accumulate, combinations, product
# import bisect
# import numpy as np
# from copy import deepcopy
#from collections import deque
# from decimal import Decimal
# from numba import jit
INF = 1 << 50
EPS = 1e-8
mod = 998244353
def intread():
return int(sysread())
def mapline(t=int):
return map(t, sysread().split())
def mapread(t=int):
return map(t, read().split())
class segtree:
'''init_val : 1-indexed (init_val[0] = self.bin[1])'''
def __init__(self, n, init = 0, init_val=None):
self.n = n
self.init = init
self.k = math.ceil(math.log2(n))
self.add_val = 1 << self.k
self.bins = [self.init] * (1 << (self.k + 1))
if init_val != None:
self.update_set(init_val)
self.caliculate()
def __getitem__(self, idx): # return idx-value
return self.bins[idx + self.add_val]
def update_set(self, vals):
for idx, i in enumerate(range(self.add_val, self.add_val * 2)):
if len(vals) > idx:
self.bins[i] = vals[idx]
else:continue
def compare(self, l, r):
return min(l ,r)
def caliculate(self):
k = self.k
while k:
for i in range(1<<k, 1<<(k+1)):
if not i%2:
self.bins[i//2] = self.compare(self.bins[i], self.bins[i+1])
else:continue
k -= 1
def update(self, idx, val, by=True):
'''idx : 0-started index'''
k = (1<<self.k) + idx
if by:
self.bins[k] += val
else:
self.bins[k] = val
while k>1:
self.bins[k // 2] = self.compare(self.bins[k // 2 * 2], self.bins[k // 2 * 2 + 1])
k = k//2
def eval(self, l, r):
if l == r:
return self.bins[l + self.add_val]
ret = self.init
l = (1 << self.k) + l
r = (1 << self.k) + r
#print(l, r)
while True:
#print(l, r)
if r - l == 1:
ret = self.compare(ret, self.bins[l])
ret = self.compare(ret, self.bins[r])
break
elif l == r:
ret = self.compare(ret, self.bins[l])
break
else:
done = False
if l % 2:
ret = self.compare(ret, self.bins[l])
l += 1
done = True
if not r % 2:
ret = self.compare(ret, self.bins[r])
r -= 1
done = True
if not done:
l = l // 2
r = r // 2
#print(ret)
return ret
def run():
N, Q = mapline()
X = segtree(N+1, init = INF)
Y = segtree(N+1, init = INF)
sub = 0
for _ in range(Q):
q, x = mapline()
x -= 1
if q == 1:
v = X.eval(x, N-2)
if v == INF:
sub += N-2
if Y[N-2] > x:
Y.update(N-2, x,by = False)
else:
sub += v-1
if Y[v] > x:
Y.update(v, x, by = False)
else:
v = Y.eval(x, N - 2)
if v == INF:
sub += N - 2
if X[N - 2] > x:
X.update(N - 2, x, by=False)
else:
sub += v - 1
if X[v] > x:
X.update(v, x, by=False)
print((N-2) ** 2 - sub)
if __name__ == "__main__":
run()
``` | output | 1 | 104,192 | 23 | 208,385 |
Provide a correct Python 3 solution for this coding contest problem.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795 | instruction | 0 | 104,193 | 23 | 208,386 |
"Correct Solution:
```
def f_simplified_reversi():
N, Q = [int(i) for i in input().split()]
Queries = [[int(i) for i in input().split()] for j in range(Q)]
a, b = [N] * N, [N] * N # editorial に準じる
black_stone = (N - 2)**2
row, col = N, N
for type, x in Queries:
if type == 1:
if x < col:
for i in range(x, col):
b[i] = row
col = x
black_stone -= b[x] - 2
else:
if x < row:
for i in range(x, row):
a[i] = col
row = x
black_stone -= a[x] - 2
return black_stone
print(f_simplified_reversi())
``` | output | 1 | 104,193 | 23 | 208,387 |
Provide a correct Python 3 solution for this coding contest problem.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795 | instruction | 0 | 104,194 | 23 | 208,388 |
"Correct Solution:
```
#!python3
import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
def resolve():
N, Q = iim()
it = map(int, sys.stdin.read().split())
M = N + 1if N & 1 else N
NM = 1<<M.bit_length()
ans = (N-2)**2
A = [[N-2]*(NM+M) for i in range(2)]
def set(a, i, j, x):
i += NM; j += NM
while i < j:
a[i] = min(a[i], x)
if i&1:
i += 1
a[j] = min(a[j], x)
if j&1 == 0:
j -= 1
i >>= 1; j >>= 1
a[i] = min(a[i], x)
def get(a, i):
i += NM
ans = a[i]
while i > 0:
i >>= 1
ans = min(ans, a[i])
return ans
for q, i in zip(it, it):
q -= 1; i -= 2
val = get(A[q], i)
ans -= val
set(A[q^1], 0, val, i)
print(ans)
if __name__ == "__main__":
resolve()
``` | output | 1 | 104,194 | 23 | 208,389 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795
Submitted Solution:
```
class LazyPropSegmentTree:
def __init__(self, N):
self.N = N
self.LV = (N - 1).bit_length()
self.N0 = 2 ** self.LV
self.data = [N - 1] * (2 * self.N0)
self.lazy = [float('inf')] * (2 * self.N0)
# 遅延伝播を行うindexを生成
def gindex(self, l, r):
L = (l + self.N0) >> 1; R = (r + self.N0) >> 1
lc = 0 if l & 1 else (L & -L).bit_length()
rc = 0 if r & 1 else (R & -R).bit_length()
for i in range(self.LV):
if rc <= i:
yield R
if L < R and lc <= i:
yield L
L >>= 1; R >>= 1
# 遅延伝搬処理
def propagates(self, *ids):
for i in reversed(ids):
v = self.lazy[i - 1]
if v == float('inf'):
continue
self.lazy[2 * i - 1] = min(self.lazy[2 * i - 1], v)
self.lazy[2 * i] = min(self.lazy[2 * i], v)
self.data[2 * i - 1] = min(self.data[2 * i - 1], v)
self.data[2 * i] = min(self.data[2 * i], v)
self.lazy[i - 1] = float('inf')
def update(self, l, r, x):
*ids, = self.gindex(l, r + 1)
self.propagates(*ids)
L = self.N0 + l; R = self.N0 + r + 1
while L < R:
if R & 1:
R -= 1
self.lazy[R - 1] = min(self.lazy[R - 1], x)
self.data[R - 1] = min(self.data[R - 1], x)
if L & 1:
self.lazy[L - 1] = min(self.lazy[L - 1], x)
self.data[L - 1] = min(self.data[L - 1], x)
L += 1
L >>= 1; R >>= 1
for i in ids:
self.data[i - 1] = min(self.data[2 * i - 1], self.data[2 * i])
def point_query(self, k):
*ids, = self.gindex(k, k + 1)
self.propagates(*ids)
return self.data[k + self.N0 - 1]
N, Q = map(int, input().split())
query = [tuple(map(int, input().split())) for i in range(Q)]
row = LazyPropSegmentTree(N+1)
column = LazyPropSegmentTree(N+1)
ans = (N-2) ** 2
for t, x in query:
if t == 1:
n = row.point_query(x)
# print(n)
ans -= n - 2
column.update(2, n, x)
else:
n = column.point_query(x)
# print(n)
ans -= n - 2
row.update(2, n, x)
print(ans)
``` | instruction | 0 | 104,195 | 23 | 208,390 |
Yes | output | 1 | 104,195 | 23 | 208,391 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795
Submitted Solution:
```
from bisect import bisect_left, bisect_right
n,q = map(int, input().split())
hori_cnt = [n-2]*(n+2) # 2から
ql = []
for _ in range(q):
c,x = map(int, input().split())
ql.append((c,x))
tate_min = n
yoko_min = n
yoko_kyokai = []
ans1 = 0
for c,x in ql:
if c == 1:
if x < tate_min:
hori_cnt[yoko_min] = x-2
yoko_kyokai.append(yoko_min*(-1))
tate_min = x
else:
# print(c,x,'---------')
if x < yoko_min:
yoko_min = x
# print(yoko_kyokai)
ind = bisect_left(yoko_kyokai, x*(-1))-1
# print(x,ind)
if ind == -1:
if x < yoko_min:
ans1 += (tate_min-2)
else:
ans1 += (n-2)
# print(tate_min-2,'++')
else:
val = yoko_kyokai[ind]
ans1 += hori_cnt[val*(-1)]
# print(hori_cnt[val*(-1)],'++s')
tate_cnt = [n-2]*(n+2) # 2から
yoko_min = n
tate_min = n
tate_kyokai = []
ans2 = 0
for c,x in ql:
if c == 2:
if x < yoko_min:
tate_cnt[tate_min] = x-2
tate_kyokai.append(tate_min*(-1))
yoko_min =x
else:
# print(c,x,'---------')
if x < tate_min:
tate_min = x
ind = bisect_left(tate_kyokai, x*(-1))-1
# print(tate_kyokai,'aaa')
if ind == -1:
if x < tate_min:
ans2 += (yoko_min-2)
else:
ans2 += (n-2)
# print(yoko_min-2,'+++')
else:
val = tate_kyokai[ind]
ans2 += tate_cnt[val*(-1)]
# print(tate_cnt[val*(-1)],'+++s')
print((n-2)*(n-2)-ans1-ans2)
``` | instruction | 0 | 104,196 | 23 | 208,392 |
Yes | output | 1 | 104,196 | 23 | 208,393 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795
Submitted Solution:
```
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def SR(n):
return [S() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
from math import log2, ceil
class SegmentTree:
def __init__(self, n, default):
self.n = n
tn = 2 ** ceil(log2(n))
self.a = [default] * (tn * 2)
self.tn = tn
def find(self, s, t):
return self.__find(1, 0, self.tn - 1, s, t)
def __find(self, c, l, r, s, t):
if self.a[c] == -1:
return self.a[c // 2]
if s <= l and r <= t:
return self.a[c]
mid = (l + r) // 2
if t <= mid:
return self.__find(c * 2, l, mid, s, t)
elif s > mid:
return self.__find(c * 2 + 1, mid + 1, r, s, t)
else:
return min(
self.__find(c * 2, l, mid, s, mid),
self.__find(c * 2 + 1, mid + 1, r, mid + 1, t))
def update(self, s, t, x):
self.__update(1, 0, self.tn - 1, s, t, x)
def __update(self, c, l, r, s, t, x, f=None):
if f is None and self.a[c] == -1:
f = self.a[c // 2]
if l == s and r == t:
return self.__set(c, x)
mid = (l + r) // 2
if t <= mid:
rv, f = self.__get_child(c, c * 2 + 1, f)
u = min(self.__update(c * 2, l, mid, s, t, x, f), rv)
elif s > mid:
lv, f = self.__get_child(c, c * 2, f)
u = min(lv, self.__update(c * 2 + 1, mid + 1, r, s, t, x, f))
else:
u = min(
self.__update(c * 2, l, mid, s, mid, x, f),
self.__update(c * 2 + 1, mid + 1, r, mid + 1, t, x, f))
if f is not None:
u = min(f, u)
self.a[c] = u
return u
def __set(self, c, x):
self.a[c] = x
if c < self.tn:
self.a[c * 2] = self.a[c * 2 + 1] = -1
return x
def __get_child(self, c, child, f):
if f is not None:
return self.__set(child, f), f
v = self.a[child]
if v == -1:
f = self.a[c]
v = self.__set(child, f)
return v, f
def solve():
n,q = LI()
ans = (n-2)*(n-2)
right = SegmentTree(n+1,n)
down = SegmentTree(n+1,n)
for _ in range(q):
t,x = LI()
if t == 1:
d = down.find(x,x)
ans -= d-2
k = right.find(0,0)
if k > x:
right.update(0,d,x)
else:
r = right.find(x,x)
ans -= r-2
k = down.find(0,0)
if k > x:
down.update(0,r,x)
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
``` | instruction | 0 | 104,197 | 23 | 208,394 |
Yes | output | 1 | 104,197 | 23 | 208,395 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795
Submitted Solution:
```
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")
# 処理内容
def main():
N, Q = map(int, input().split())
h = N
w = N
a = [N]*N
b = [N]*N
ans = (N-2)**2
for _ in range(Q):
q, x = map(int, input().split())
if q == 1:
if x < w:
for i in range(x, w):
b[i] = h
w = x
ans -= b[x] - 2
elif q == 2:
if x < h:
for i in range(x, h):
a[i] = w
h = x
ans -= a[x] - 2
print(ans)
if __name__ == '__main__':
main()
``` | instruction | 0 | 104,198 | 23 | 208,396 |
Yes | output | 1 | 104,198 | 23 | 208,397 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795
Submitted Solution:
```
N, Q = map(int, input().split())
ans = (N-2)*(N-2)
R = [N]*(N+1)
W = [N]*(N+1)
for i in range(Q):
a, b = map(int, input().split())
if a == 1:
ans -= max(0, R[b] - 2)
if b <= W[1]:
for j in range(1, R[b]+1):
W[j] = b
R[b] = 0
else:
ans -= max(0, W[b] - 2)
if b <= R[1]:
for j in range(1, W[b] + 1):
R[j] = b
W[b] = 0
print(ans)
``` | instruction | 0 | 104,199 | 23 | 208,398 |
No | output | 1 | 104,199 | 23 | 208,399 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795
Submitted Solution:
```
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import deque
from collections import Counter
import bisect
from collections import defaultdict
import itertools
def main():
N, Q = MI()
#i行の一番右をline_right[i], j列目の一番下をcolumn_under[j]とする。
line_right = [N] * N
column_under = [N] * N
bla = pow(N - 2, 2)
x_min = N
y_min = N
for i in range(Q):
query = LI()
if query[0] == 1:
w = query[1]
x = column_under[w]
bla -= x - 2
if w < x_min:
for j in range(x):
line_right[j] = w
x_min = w
else:
y = query[1]
z = line_right[y]
bla -= z - 2
if y < y_min:
for j in range(z):
column_under[j] = y
y_min = y
print(bla)
if __name__ == "__main__":
main()
``` | instruction | 0 | 104,200 | 23 | 208,400 |
No | output | 1 | 104,200 | 23 | 208,401 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795
Submitted Solution:
```
n, q = map(int, input().split())
q = [list(map(int, input().split())) for _i in range(q)]
x_list = [n for _i in range(n+1)]
y_list = [n for _i in range(n+1)]
res = (n-2)**2
from bisect import bisect_right
for i, j in q:
if i==1:
position = x_list[j]
res -= position-2
for s in range(1, position):
y_list[s] = min(y_list[s], j)
else:
position = y_list[j]
res -= position-2
for s in range(1, position):
x_list[s] = min(x_list[s], j)
print(res)
``` | instruction | 0 | 104,201 | 23 | 208,402 |
No | output | 1 | 104,201 | 23 | 208,403 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795
Submitted Solution:
```
class segtree():
def segfunc(x,y):
return min(x,y)
#####単位元######
ide_ele = -1
n=1
init_val=[0]*n
#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num
def __init__(self,INIT_VAL,SEGFUNC,IDE_ELE):
self.ide_ele=IDE_ELE
self.init_val=[i for i in INIT_VAL]
self.segfunc=SEGFUNC
self.n=len(self.init_val)
self.num =2**(self.n-1).bit_length()
self.seg=[self.ide_ele]*2*self.num
#set_val
for i in range(self.n):
self.seg[i+self.num-1]=self.init_val[i]
#built
for i in range(self.num-2,-1,-1) :
self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2])
def update(self,k,x):
k += self.num-1
self.seg[k] = x
while k+1:
k = (k-1)//2
self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
def query(self,p,q):
if q<=p:
return self.ide_ele
p += self.num-1
q += self.num-2
res=self.ide_ele
while q-p>1:
if p&1 == 0:
res = self.segfunc(res,self.seg[p])
if q&1 == 1:
res = self.segfunc(res,self.seg[q])
q -= 1
p = p//2
q = (q-1)//2
if p == q:
res = self.segfunc(res,self.seg[p])
else:
res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
return res
N,Q=map(int,input().split())
X=segtree([0 for i in range(N)],(lambda x,y:x+y),0)
Y=segtree([0 for i in range(N)],(lambda x,y:x+y),0)
ans=(N-2)*(N-2)
for i in range(Q):
k,x=map(int,input().split())
#print(i,ans)
#print([X.query(0,i) for i in range(1,N)],[Y.query(0,i) for i in range(1,N)])
dp=[[-1 for i in range(N)] for i in range(N)]
for i in range(1,N):
dp[-i-1][-1]=Y.query(0,i)
dp[-1][-1-i]=X.query(0,i)
x=N-x+1
#for line in dp:
# print(line)
if k==1:
a=X.query(0,x)
ans-=N-2-a
if Y.query(a,a+1)<x-1:
Y.update(a,x-1)
else:
b=Y.query(0,x)
ans-=N-2-b
if X.query(b,b+1)<x-1:
X.update(b,x-1)
print(ans)
``` | instruction | 0 | 104,202 | 23 | 208,404 |
No | output | 1 | 104,202 | 23 | 208,405 |
Provide a correct Python 3 solution for this coding contest problem.
Niwango bought a piece of land that can be represented as a half-open interval [0, X).
Niwango will lay out N vinyl sheets on this land. The sheets are numbered 1,2, \ldots, N, and they are distinguishable. For Sheet i, he can choose an integer j such that 0 \leq j \leq X - L_i and cover [j, j + L_i) with this sheet.
Find the number of ways to cover the land with the sheets such that no point in [0, X) remains uncovered, modulo (10^9+7). We consider two ways to cover the land different if and only if there is an integer i (1 \leq i \leq N) such that the region covered by Sheet i is different.
Constraints
* 1 \leq N \leq 100
* 1 \leq L_i \leq X \leq 500
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
L_1 L_2 \ldots L_N
Output
Print the answer.
Examples
Input
3 3
1 1 2
Output
10
Input
18 477
324 31 27 227 9 21 41 29 50 34 2 362 92 11 13 17 183 119
Output
134796357 | instruction | 0 | 104,219 | 23 | 208,438 |
"Correct Solution:
```
N,X=map(int,input().split())
L=sorted(map(int,input().split()),reverse=True)
mod=10**9+7
D=[[0]*(X+1) for i in range(N//2+2)]
D[1][L[0]]=1
for l in L[1:]:
ND=[[0]*(X+1) for i in range(N//2+1)]
for c in range(1,N//2+1):
for s in range(X+1):
if D[c][s]==0:
continue
k=D[c][s]
if s+l+c<=X and c+1<=N//2:
ND[c+1][s+l]=(ND[c+1][s+l]+k*(c+1))%mod
ND[c][s]=(ND[c][s]+k*(s-c*(l-1)))%mod
for i in range(1,min(X-s-c+2,l+1)):
ND[c][s+i]=(ND[c][s+i]+k*2*c)%mod
if c==1:
continue
for i in range(1,min(X-s-c+3,l+1)):
ND[c-1][s+i]=(ND[c-1][s+i]+k*(c-1)*(l-i+1))%mod
D=ND
print(D[1][X])
``` | output | 1 | 104,219 | 23 | 208,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Niwango bought a piece of land that can be represented as a half-open interval [0, X).
Niwango will lay out N vinyl sheets on this land. The sheets are numbered 1,2, \ldots, N, and they are distinguishable. For Sheet i, he can choose an integer j such that 0 \leq j \leq X - L_i and cover [j, j + L_i) with this sheet.
Find the number of ways to cover the land with the sheets such that no point in [0, X) remains uncovered, modulo (10^9+7). We consider two ways to cover the land different if and only if there is an integer i (1 \leq i \leq N) such that the region covered by Sheet i is different.
Constraints
* 1 \leq N \leq 100
* 1 \leq L_i \leq X \leq 500
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
L_1 L_2 \ldots L_N
Output
Print the answer.
Examples
Input
3 3
1 1 2
Output
10
Input
18 477
324 31 27 227 9 21 41 29 50 34 2 362 92 11 13 17 183 119
Output
134796357
Submitted Solution:
```
N,X=map(int,input().split())
L=sorted(map(int,input().split()),reverse=True)
mod=10**9+7
D=[[0]*(X+1) for i in range(N//2+1)]
D[1][L[0]]=1
for l in L[1:]:
ND=[[0]*(X+1) for i in range(N//2+1)]
for c in range(1,N//2+1):
for s in range(X+1):
if D[c][s]==0:
continue
k=D[c][s]
if s+l+c<=X and c+1<=N//2:
ND[c+1][s+l]=(ND[c+1][s+l]+k*(c+1))%mod
ND[c][s]=(ND[c][s]+k*(s-c*(l-1)))%mod
for i in range(1,min(X-s-c+2,l+1)):
ND[c][s+i]=(ND[c][s+i]+k*2*c)%mod
if c==1:
continue
for i in range(1,min(X-s-c+3,l+1)):
ND[c-1][s+i]=(ND[c-1][s+i]+k*(c-1)*(l-i+1))%mod
D=ND
print(D[1][X])
``` | instruction | 0 | 104,220 | 23 | 208,440 |
No | output | 1 | 104,220 | 23 | 208,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Niwango bought a piece of land that can be represented as a half-open interval [0, X).
Niwango will lay out N vinyl sheets on this land. The sheets are numbered 1,2, \ldots, N, and they are distinguishable. For Sheet i, he can choose an integer j such that 0 \leq j \leq X - L_i and cover [j, j + L_i) with this sheet.
Find the number of ways to cover the land with the sheets such that no point in [0, X) remains uncovered, modulo (10^9+7). We consider two ways to cover the land different if and only if there is an integer i (1 \leq i \leq N) such that the region covered by Sheet i is different.
Constraints
* 1 \leq N \leq 100
* 1 \leq L_i \leq X \leq 500
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
L_1 L_2 \ldots L_N
Output
Print the answer.
Examples
Input
3 3
1 1 2
Output
10
Input
18 477
324 31 27 227 9 21 41 29 50 34 2 362 92 11 13 17 183 119
Output
134796357
Submitted Solution:
```
N,X=map(int,input().split())
L=sorted(map(int,input().split()),reverse=True)
mod=10**9+7
from collections import defaultdict
D=defaultdict(int)
D[1,L[0]]=1
for l in L[1:]:
ND=defaultdict(int)
for c,s in D:
k=D[c,s]
if s+l+c-1<=X:
ND[c+1,s+l]=(ND[c+1,s+l]+k*(c+1))%mod
ND[c,s]=(ND[c,s]+k*(s-c*(l-1)))%mod
for i in range(1,min(X-s-c+2,l+1)):
ND[c,s+i]=(ND[c,s+i]+k*2*c)%mod
for i in range(1,min(X-s-c+3,l+1)):
ND[c-1,s+i]=(ND[c-1,s+i]+k*(c-1)*(l-i+1))%mod
D=ND
print(D[1,X])
``` | instruction | 0 | 104,221 | 23 | 208,442 |
No | output | 1 | 104,221 | 23 | 208,443 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Niwango bought a piece of land that can be represented as a half-open interval [0, X).
Niwango will lay out N vinyl sheets on this land. The sheets are numbered 1,2, \ldots, N, and they are distinguishable. For Sheet i, he can choose an integer j such that 0 \leq j \leq X - L_i and cover [j, j + L_i) with this sheet.
Find the number of ways to cover the land with the sheets such that no point in [0, X) remains uncovered, modulo (10^9+7). We consider two ways to cover the land different if and only if there is an integer i (1 \leq i \leq N) such that the region covered by Sheet i is different.
Constraints
* 1 \leq N \leq 100
* 1 \leq L_i \leq X \leq 500
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
L_1 L_2 \ldots L_N
Output
Print the answer.
Examples
Input
3 3
1 1 2
Output
10
Input
18 477
324 31 27 227 9 21 41 29 50 34 2 362 92 11 13 17 183 119
Output
134796357
Submitted Solution:
```
N,X=map(int,input().split())
L=sorted(map(int,input().split()),reverse=True)
mod=10**9+7
from collections import defaultdict
D=dict()
D[1,L[0]]=1
for l in L[1:]:
ND=defaultdict(int)
for c,s in D:
k=D[c,s]
if s+l<=X:
ND[c+1,s+l]=(ND[c+1,s+l]+k*(c+1))%mod
ND[c,s]=(ND[c,s]+k*(s-c*(l-1)))%mod
for i in range(1,min(X-s+1,l+1)):
ND[c,s+i]=(ND[c,s+i]+k*2*c)%mod
for i in range(1,min(X-s+1,l+1)):
ND[c-1,s+i]=(ND[c-1,s+i]+k*(c-1)*(l-i+1))%mod
D=ND
print(D[1,X])
``` | instruction | 0 | 104,222 | 23 | 208,444 |
No | output | 1 | 104,222 | 23 | 208,445 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Niwango bought a piece of land that can be represented as a half-open interval [0, X).
Niwango will lay out N vinyl sheets on this land. The sheets are numbered 1,2, \ldots, N, and they are distinguishable. For Sheet i, he can choose an integer j such that 0 \leq j \leq X - L_i and cover [j, j + L_i) with this sheet.
Find the number of ways to cover the land with the sheets such that no point in [0, X) remains uncovered, modulo (10^9+7). We consider two ways to cover the land different if and only if there is an integer i (1 \leq i \leq N) such that the region covered by Sheet i is different.
Constraints
* 1 \leq N \leq 100
* 1 \leq L_i \leq X \leq 500
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
L_1 L_2 \ldots L_N
Output
Print the answer.
Examples
Input
3 3
1 1 2
Output
10
Input
18 477
324 31 27 227 9 21 41 29 50 34 2 362 92 11 13 17 183 119
Output
134796357
Submitted Solution:
```
N,X=map(int,input().split())
L=sorted(map(int,input().split()),reverse=True)
mod=10**9+7
D=[[0]*(X+1) for i in range(N//2+2)]
D[1][L[0]]=1
for l in L[1:]:
ND=[[0]*(X+1) for i in range(N//2+1)]
for c in range(1,N//2+1):
for s in range(X+1):
if D[c][s]==0:
continue
k=D[c][s]
if s+l+c<=X and c+1<=N//2:
ND[c+1][s+l]=(ND[c+1][s+l]+k*(c+1))%mod
ND[c][s]=(ND[c][s]+k*(s-c*(l-1)))%mod
for i in range(1,min(X-s-c+2,l+1)):
ND[c][s+i]=(ND[c][s+i]+k*2*c)%mod
if c==1:
continue
for i in range(1,min(X-s-c+3,l+1)):
ND[c-1][s+i]=(ND[c-1][s+i]+k*(c-1)*(l-i+1))%mod
D=ND
print(D[1][X])
``` | instruction | 0 | 104,223 | 23 | 208,446 |
No | output | 1 | 104,223 | 23 | 208,447 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.
You are given a length equal to n centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The result should be an integer rounded to the closest value containing an integral number of inches.
Note that when you round up, 1 cm rounds up to 0 inches and 2 cm round up to 1 inch.
Input
The only line contains an integer n (1 ≤ n ≤ 10000).
Output
Print two non-negative space-separated integers a and b, where a is the numbers of feet and b is the number of inches.
Examples
Input
42
Output
1 2
Input
5
Output
0 2
Submitted Solution:
```
n = int(input())/3
ft = int(n//12)
inch = round(n%12)
if inch == 12:
inch = 0
ft += 1
print(ft, inch)
``` | instruction | 0 | 104,534 | 23 | 209,068 |
Yes | output | 1 | 104,534 | 23 | 209,069 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.
You are given a length equal to n centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The result should be an integer rounded to the closest value containing an integral number of inches.
Note that when you round up, 1 cm rounds up to 0 inches and 2 cm round up to 1 inch.
Input
The only line contains an integer n (1 ≤ n ≤ 10000).
Output
Print two non-negative space-separated integers a and b, where a is the numbers of feet and b is the number of inches.
Examples
Input
42
Output
1 2
Input
5
Output
0 2
Submitted Solution:
```
cm = int(input())
cm += 1
dm = divmod(cm, 36)
print(dm[0], end=' ')
cm = dm[1]
print(round(cm / 3))
``` | instruction | 0 | 104,535 | 23 | 209,070 |
No | output | 1 | 104,535 | 23 | 209,071 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.
Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric.
Input
The first line contains the single integer n (1 ≤ n ≤ 100). The second line contains n space-separated integers ri (1 ≤ ri ≤ 1000) — the circles' radii. It is guaranteed that all circles are different.
Output
Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10 - 4.
Examples
Input
1
1
Output
3.1415926536
Input
3
1 4 2
Output
40.8407044967
Note
In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 12 = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 42 - π × 22) + π × 12 = π × 12 + π = 13π
Submitted Solution:
```
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
# import numpy as np
starttime = time.time()
# import numpy as np
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
try:
# sys.setrecursionlimit(int(pow(10,6)))
sys.stdin = open("input.txt", "r")
# sys.stdout = open("../output.txt", "w")
except:
pass
n=L()[0]+1
A=[0]+sorted(L())
# for i in range(1,n):
# A[i]+=A[i-1]
ans=0
for i in range(n-1,0,-2):
ans+=(pi*(A[i]**2-A[i-1]**2))
print(ans)
endtime = time.time()
# print(f"Runtime of the program is {endtime - starttime}")
``` | instruction | 0 | 104,709 | 23 | 209,418 |
Yes | output | 1 | 104,709 | 23 | 209,419 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.