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 a correct Python 3 solution for this coding contest problem.
JOI is playing with a nail in the board. As shown in the figure below, JOI stabbed nails in the shape of an equilateral triangle with N sides. A nails are lined up in the ath line (1 ≤ a ≤ N) from the top. The bth nail (1 ≤ b ≤ a) from the left is represented by (a, b).
<image>
Figure 1: Arrangement of nails (when N = 5)
When an equilateral triangle with a nail as its apex is "each side is parallel to one of the sides of the entire equilateral triangle and has the same orientation as the entire equilateral triangle", this equilateral triangle is called a "good equilateral triangle". That is, a "good equilateral triangle" is an equilateral triangle whose vertices are three nails (a, b), (a + x, b), (a + x, b + x) (but a). , B, x satisfy 1 ≤ a <N, 1 ≤ b ≤ a, 1 ≤ x ≤ N --a)).
JOI decided to use a rubber band to surround the "good equilateral triangle."
<image>
Figure 2: An example of how to enclose a "good equilateral triangle" with a rubber band
input
Read the following data from standard input.
* The integers N and M are written on the first line, separated by blanks. N represents the number of nails lined up on one side of an equilateral triangle, and M represents the number of rubber bands that JOI has.
* The following M line shows information on how to enclose a "good equilateral triangle" with a rubber band. The integers Ai, Bi, Xi (1 ≤ Ai <N, 1 ≤ Bi ≤ Ai, 1 ≤ Xi ≤ N --Ai) are written on the first line (1 ≤ i ≤ M), separated by blanks. .. This means that the i-th rubber band surrounds a "good equilateral triangle" with three nails (Ai, Bi), (Ai + Xi, Bi), (Ai + Xi, Bi + Xi) as vertices. Represent.
output
Output the number of nails surrounded by one or more rubber bands to the standard output in one line.
Examples
Input
5 2
2 2 1
2 1 3
Output
12
Input
None
Output
None | instruction | 0 | 29,940 | 23 | 59,880 |
"Correct Solution:
```
from collections import deque
n,m=map(int,input().split())
abx=[[0]*(n+2) for i in range(n+2)]
for i in range(m):
ai,bi,xi=map(int,input().split())
abx[ai][bi]=max(abx[ai][bi],xi)
pp=[[0]*(n+2) for i in range(n+2)]
for j in range(1,n+2):
dq=deque()
for i in range(j,n+2):
if abx[i][j]>0:
dq.append([i,abx[i][j]])
iiii=j-1
while len(dq):
ii,xi=dq.popleft()
if ii+xi>iiii:
for iii in range(max(ii,iiii+1),ii+xi+1):
pp[iii][j]=iii-ii+1
iiii=iii
icnt=0
for i in range(1,n+1):
for j in range(1,i+1):
abij=pp[i][j-1]-1
pp[i][j]=max(pp[i][j],abij)
if pp[i][j]>0:
icnt+=1
print(icnt)
``` | output | 1 | 29,940 | 23 | 59,881 |
Provide a correct Python 3 solution for this coding contest problem.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is to write a program that computes the area of polygons.
A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking.
* No point will occur as a vertex more than once.
* Two sides can intersect only at a common endpoint (vertex).
* The polygon has at least 3 vertices.
Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
Input
The input contains multiple data sets, each representing a polygon. A data set is given in the following format.
n
x1 y1
x2 y2
...
xn yn
The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them.
The end of input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.
The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Example
Input
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
Output
1 8.5
2 3800.0 | instruction | 0 | 29,941 | 23 | 59,882 |
"Correct Solution:
```
def area(px,py,x,y):
if py > y:
py,y = y,py
return py*(x-px)+(x-px)*abs(y-py)/2
count = 1
while True:
res = 0
n = int(input())
if n == 0:
break
px,py = map(int,input().split())
sx,sy = px,py
for _ in range(n-1):
x,y = map(int,input().split())
res += area(px,py,x,y)
px,py = x,y
res += area(px,py,sx,sy)
print(count,res)
count += 1
input()
``` | output | 1 | 29,941 | 23 | 59,883 |
Provide a correct Python 3 solution for this coding contest problem.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is to write a program that computes the area of polygons.
A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking.
* No point will occur as a vertex more than once.
* Two sides can intersect only at a common endpoint (vertex).
* The polygon has at least 3 vertices.
Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
Input
The input contains multiple data sets, each representing a polygon. A data set is given in the following format.
n
x1 y1
x2 y2
...
xn yn
The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them.
The end of input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.
The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Example
Input
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
Output
1 8.5
2 3800.0 | instruction | 0 | 29,942 | 23 | 59,884 |
"Correct Solution:
```
def cal(a,b):
return a[0]*b[1]-a[1]*b[0]
c=1
while 1:
N=int(input())
if N==0:
break
p=[tuple(map(int, input().split())) for _ in range(N)]
input()
S=0
for i in range(N):
S += cal(p[i],p[i-1])
S=abs(S/2)
print("{} {}".format(c,S))
c+=1
``` | output | 1 | 29,942 | 23 | 59,885 |
Provide a correct Python 3 solution for this coding contest problem.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is to write a program that computes the area of polygons.
A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking.
* No point will occur as a vertex more than once.
* Two sides can intersect only at a common endpoint (vertex).
* The polygon has at least 3 vertices.
Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
Input
The input contains multiple data sets, each representing a polygon. A data set is given in the following format.
n
x1 y1
x2 y2
...
xn yn
The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them.
The end of input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.
The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Example
Input
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
Output
1 8.5
2 3800.0 | instruction | 0 | 29,943 | 23 | 59,886 |
"Correct Solution:
```
# AOJ 1100: Area of Polygons
# Python3 2018.7.14 bal4u
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def calc_area(pp):
n = len(pp)
if n < 3: return 0
s = 0
for i in range(n):
s += (pp[i].real-pp[(i+1)%n].real)*(pp[i].imag+pp[(i+1)%n].imag)
return abs(s)/2
cno = 0
while True:
n = input()
if n == '': n = input()
n = int(n);
if n == 0: break
pp = []
for i in range(n):
x, y = map(int, input().split())
pp.append(complex(x, y))
cno += 1
print(cno, Decimal(str(calc_area(pp))).quantize(Decimal('0.1'), rounding=ROUND_HALF_UP))
``` | output | 1 | 29,943 | 23 | 59,887 |
Provide a correct Python 3 solution for this coding contest problem.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is to write a program that computes the area of polygons.
A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking.
* No point will occur as a vertex more than once.
* Two sides can intersect only at a common endpoint (vertex).
* The polygon has at least 3 vertices.
Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
Input
The input contains multiple data sets, each representing a polygon. A data set is given in the following format.
n
x1 y1
x2 y2
...
xn yn
The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them.
The end of input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.
The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Example
Input
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
Output
1 8.5
2 3800.0 | instruction | 0 | 29,944 | 23 | 59,888 |
"Correct Solution:
```
idx = 1
while True:
n = int(input())
if n==0: break
x = []
y = []
for _ in range(n):
a,b = map(int,input().split())
x.append(a)
y.append(b)
x.append(x[0])
y.append(y[0])
s = 0.0
for i in range(n):
s += x[i]*y[i+1] - x[i+1]*y[i]
print(idx, abs(s/2))
idx += 1
input()
``` | output | 1 | 29,944 | 23 | 59,889 |
Provide a correct Python 3 solution for this coding contest problem.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is to write a program that computes the area of polygons.
A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking.
* No point will occur as a vertex more than once.
* Two sides can intersect only at a common endpoint (vertex).
* The polygon has at least 3 vertices.
Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
Input
The input contains multiple data sets, each representing a polygon. A data set is given in the following format.
n
x1 y1
x2 y2
...
xn yn
The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them.
The end of input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.
The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Example
Input
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
Output
1 8.5
2 3800.0 | instruction | 0 | 29,945 | 23 | 59,890 |
"Correct Solution:
```
c=0
while 1:
n=int(input())
if n==0:break
c+=1
p=[complex(*map(int,input().split())) for _ in range(n)]
s,pre=0,p[0]
while p:
now=p.pop()
s+=now.real*pre.imag-now.imag*pre.real
pre=now
print(c,abs(s)/2);input()
``` | output | 1 | 29,945 | 23 | 59,891 |
Provide a correct Python 3 solution for this coding contest problem.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is to write a program that computes the area of polygons.
A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking.
* No point will occur as a vertex more than once.
* Two sides can intersect only at a common endpoint (vertex).
* The polygon has at least 3 vertices.
Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
Input
The input contains multiple data sets, each representing a polygon. A data set is given in the following format.
n
x1 y1
x2 y2
...
xn yn
The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them.
The end of input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.
The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Example
Input
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
Output
1 8.5
2 3800.0 | instruction | 0 | 29,946 | 23 | 59,892 |
"Correct Solution:
```
def cp(a, b):return a[0] * b[1] - a[1] * b[0]
c = 1
while 1:
n = int(input())
if n == 0:break
p = [tuple(map(int, input().split())) for _ in range(n)]
input()
s = 0
for i in range(n):s += cp(p[i], p[i - 1])
s = abs(s / 2)
print("{} {}".format(c,s))
c += 1
``` | output | 1 | 29,946 | 23 | 59,893 |
Provide a correct Python 3 solution for this coding contest problem.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is to write a program that computes the area of polygons.
A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking.
* No point will occur as a vertex more than once.
* Two sides can intersect only at a common endpoint (vertex).
* The polygon has at least 3 vertices.
Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
Input
The input contains multiple data sets, each representing a polygon. A data set is given in the following format.
n
x1 y1
x2 y2
...
xn yn
The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them.
The end of input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.
The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Example
Input
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
Output
1 8.5
2 3800.0 | instruction | 0 | 29,947 | 23 | 59,894 |
"Correct Solution:
```
from os import sys
n = int(input())
c = 1
while True:
if n == 0:
sys.exit(0)
X = 0
Y = 0
ox = 0
oy = 0
esquerda = 0
direita = 0
for i in range(0,n):
cx, cy = input().split(' ')
cx = int(cx)
cy = int(cy)
if i == 0:
X = cx
Y = cy
direita += ox * cy
esquerda += oy * cx
ox = cx
oy = cy
esquerda += X * oy
direita += Y * cx
s = direita - esquerda
if s < 0:
s = esquerda - direita
s = s/2
print("%d %.1f" %(c,s))
c += 1
n = input()
if n == '':
n = input()
n = int(n)
``` | output | 1 | 29,947 | 23 | 59,895 |
Provide a correct Python 3 solution for this coding contest problem.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is to write a program that computes the area of polygons.
A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking.
* No point will occur as a vertex more than once.
* Two sides can intersect only at a common endpoint (vertex).
* The polygon has at least 3 vertices.
Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
Input
The input contains multiple data sets, each representing a polygon. A data set is given in the following format.
n
x1 y1
x2 y2
...
xn yn
The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them.
The end of input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.
The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Example
Input
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
Output
1 8.5
2 3800.0 | instruction | 0 | 29,948 | 23 | 59,896 |
"Correct Solution:
```
def det(a,b):
return a[0]*b[1] - a[1]*b[0]
cnt = 1
while True :
n = int(input())
if n==0:
break
dots = []
std = list(map(int,input().split()))
for i in range(n-1):
dots.append(list(map(int,input().split())))
#print(dots)
dots2 = []
for dot in dots:
dot[0] -= std[0]
dot[1] -= std[1]
dots2.append(dot)
#print(dots2)
area = 0
for i in range(n-2):
area += det(dots2[i],dots2[i+1])
area /= 2
area = abs(area)
#print(std)
print("{} {}".format(cnt,area))
cnt +=1
input()
``` | output | 1 | 29,948 | 23 | 59,897 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is to write a program that computes the area of polygons.
A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking.
* No point will occur as a vertex more than once.
* Two sides can intersect only at a common endpoint (vertex).
* The polygon has at least 3 vertices.
Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
Input
The input contains multiple data sets, each representing a polygon. A data set is given in the following format.
n
x1 y1
x2 y2
...
xn yn
The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them.
The end of input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.
The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Example
Input
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
Output
1 8.5
2 3800.0
Submitted Solution:
```
num = 1
while True:
n = int(input())
if not n:
break
x0, y0 = map(float, input().split())
prx, pry = x0, y0
area = 0
for _ in range(n - 1):
x, y = map(float, input().split())
area += (prx * y - x * pry)
prx, pry = x, y
area += (prx * y0 - x0 * pry)
area /= 2
print(num, abs(area))
num += 1
input()
``` | instruction | 0 | 29,949 | 23 | 59,898 |
Yes | output | 1 | 29,949 | 23 | 59,899 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is to write a program that computes the area of polygons.
A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking.
* No point will occur as a vertex more than once.
* Two sides can intersect only at a common endpoint (vertex).
* The polygon has at least 3 vertices.
Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
Input
The input contains multiple data sets, each representing a polygon. A data set is given in the following format.
n
x1 y1
x2 y2
...
xn yn
The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them.
The end of input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.
The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Example
Input
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
Output
1 8.5
2 3800.0
Submitted Solution:
```
# AOJ 1100: Area of Polygons
# Python3 2018.7.14 bal4u
from decimal import Decimal, ROUND_HALF_UP
def calc_area(pp):
n, s = len(pp), 0
for i in range(n): s += (pp[i].real-pp[(i+1)%n].real)*(pp[i].imag+pp[(i+1)%n].imag)
return abs(s)/2
cno = 0
while True:
n = int(input())
if n == 0: break
pp = [complex(*map(int, input().split())) for i in range(n)]
input()
cno += 1
print(cno, Decimal(str(calc_area(pp))).quantize(Decimal('0.1'), rounding=ROUND_HALF_UP))
``` | instruction | 0 | 29,950 | 23 | 59,900 |
Yes | output | 1 | 29,950 | 23 | 59,901 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is to write a program that computes the area of polygons.
A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking.
* No point will occur as a vertex more than once.
* Two sides can intersect only at a common endpoint (vertex).
* The polygon has at least 3 vertices.
Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
Input
The input contains multiple data sets, each representing a polygon. A data set is given in the following format.
n
x1 y1
x2 y2
...
xn yn
The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them.
The end of input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.
The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Example
Input
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
Output
1 8.5
2 3800.0
Submitted Solution:
```
import sys
if sys.version_info[0]>=3: raw_input=input
cross=lambda a1, b1, a2, b2: a1*b2-a2*b1
try:
T=0
while True:
T+=1
n=int(raw_input())
if n==0: break
a=[[float(e) for e in raw_input().split()] for i in range(n)]
s=0
t=0
for i in range(n-1):
x=cross(a[i][0],a[i][1],a[i+1][0],a[i+1][1])
if x>0: s+=abs(x)/2
else: t+=abs(x)/2
x=cross(a[n-1][0],a[n-1][1],a[0][0],a[0][1])
if x>0: s+=abs(x)/2
else: t+=abs(x)/2
print('%d %.1f'%(T,abs(s-t)))
raw_input()
except EOFError:
pass
``` | instruction | 0 | 29,951 | 23 | 59,902 |
Yes | output | 1 | 29,951 | 23 | 59,903 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is to write a program that computes the area of polygons.
A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking.
* No point will occur as a vertex more than once.
* Two sides can intersect only at a common endpoint (vertex).
* The polygon has at least 3 vertices.
Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
Input
The input contains multiple data sets, each representing a polygon. A data set is given in the following format.
n
x1 y1
x2 y2
...
xn yn
The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them.
The end of input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.
The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Example
Input
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
Output
1 8.5
2 3800.0
Submitted Solution:
```
index = 1
while True:
n = int(input())
if n == 0:
break
else:
area = 0
X = []
Y = []
for i in range(n):
x, y = map(int, input().split())
X.append(x)
Y.append(y)
for i in range(1, n-1):
area += ((X[i] - X[0]) * (Y[i+1] - Y[0]) - (X[i+1] - X[0]) * (Y[i] - Y[0])) / 2
if area < 0:
print("{0} {1}".format(index, -area))
else:
print("{0} {1}".format(index, area))
blank = input()
index += 1
``` | instruction | 0 | 29,952 | 23 | 59,904 |
Yes | output | 1 | 29,952 | 23 | 59,905 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is to write a program that computes the area of polygons.
A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking.
* No point will occur as a vertex more than once.
* Two sides can intersect only at a common endpoint (vertex).
* The polygon has at least 3 vertices.
Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
Input
The input contains multiple data sets, each representing a polygon. A data set is given in the following format.
n
x1 y1
x2 y2
...
xn yn
The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them.
The end of input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.
The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Example
Input
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
Output
1 8.5
2 3800.0
Submitted Solution:
```
while 1:
n=int(input())
if n==0:break
p=[complex(*map(int,input().split())) for _ in range(n)]
s,pre=0,p[0]
while p:
now=p.pop()
s+=now.real*pre.imag-now.imag*pre.real
pre=now
print(abs(s)/2);input()
``` | instruction | 0 | 29,953 | 23 | 59,906 |
No | output | 1 | 29,953 | 23 | 59,907 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is to write a program that computes the area of polygons.
A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking.
* No point will occur as a vertex more than once.
* Two sides can intersect only at a common endpoint (vertex).
* The polygon has at least 3 vertices.
Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
Input
The input contains multiple data sets, each representing a polygon. A data set is given in the following format.
n
x1 y1
x2 y2
...
xn yn
The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them.
The end of input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.
The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Example
Input
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
Output
1 8.5
2 3800.0
Submitted Solution:
```
import sys
print("hello")
``` | instruction | 0 | 29,954 | 23 | 59,908 |
No | output | 1 | 29,954 | 23 | 59,909 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is to write a program that computes the area of polygons.
A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking.
* No point will occur as a vertex more than once.
* Two sides can intersect only at a common endpoint (vertex).
* The polygon has at least 3 vertices.
Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
Input
The input contains multiple data sets, each representing a polygon. A data set is given in the following format.
n
x1 y1
x2 y2
...
xn yn
The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them.
The end of input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.
The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Example
Input
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
Output
1 8.5
2 3800.0
Submitted Solution:
```
import numpy
import scipy
``` | instruction | 0 | 29,955 | 23 | 59,910 |
No | output | 1 | 29,955 | 23 | 59,911 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is to write a program that computes the area of polygons.
A polygon is represented by a sequence of points that are its vertices. If the vertices p1, p2, ..., pn are given, line segments connecting pi and pi+1 (1 <= i <= n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
You can assume that the polygon is not degenerate. Namely, the following facts can be assumed without any input data checking.
* No point will occur as a vertex more than once.
* Two sides can intersect only at a common endpoint (vertex).
* The polygon has at least 3 vertices.
Note that the polygon is not necessarily convex. In other words, an inner angle may be larger than 180 degrees.
Input
The input contains multiple data sets, each representing a polygon. A data set is given in the following format.
n
x1 y1
x2 y2
...
xn yn
The first integer n is the number of vertices, such that 3 <= n <= 50. The coordinate of a vertex pi is given by (xi, yi). xi and yi are integers between 0 and 1000 inclusive. The coordinates of vertices are given in the order of clockwise visit of them.
The end of input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.
The sequence number and the area should be printed on the same line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Example
Input
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
Output
1 8.5
2 3800.0
Submitted Solution:
```
import numpy
print("hello")
``` | instruction | 0 | 29,956 | 23 | 59,912 |
No | output | 1 | 29,956 | 23 | 59,913 |
Provide a correct Python 3 solution for this coding contest problem.
Taro came to a square to look for treasure. There are many treasures buried in this square, but Taro has the latest machines, so he knows everything about where the treasures are buried. Since the square is very wide Taro decided to look for the treasure to decide the area, but the treasure is what treasure does not know immediately whether or not there in the area for a lot. So Taro decided to count the number of treasures in that area.
Constraints
> 1 ≤ n ≤ 5000
> 1 ≤ m ≤ 5 × 105
> | xi |, | yi | ≤ 109 (1 ≤ i ≤ n)
> | xi1 |, | yi1 |, | xi2 |, | yi2 | ≤ 109 (1 ≤ i ≤ m)
> xi1 ≤ xi2, yi1 ≤ yi2 (1 ≤ i ≤ m)
>
* All inputs are given as integers
Input
> n m
> x1 y1
> x2 y2
> ...
> xn yn
> x11 y11 x12 y12
> x21 y21 x22 y22
> ...
> xm1 ym1 xm2 ym2
>
* n represents the number of treasures buried in the square
* m represents the number of regions to examine
* The 2nd to n + 1 lines represent the coordinates where each treasure is buried.
* The n + 2nd to n + m + 1 lines represent each area to be examined.
* The positive direction of the x-axis represents the east and the positive direction of the y-axis represents the north.
* Each region is a rectangle, xi1 and yi1 represent the coordinates of the southwestern apex of the rectangle, and xi2 and yi2 represent the coordinates of the northeastern apex of the rectangle.
Output
> C1
> C2
> ...
> Cm
>
* Output the number of treasures contained in each area to each line
Examples
Input
3 1
1 1
2 4
5 3
0 0 5 5
Output
3
Input
4 2
-1 1
0 3
4 0
2 1
-3 1 5 1
4 0 4 0
Output
2
1
Input
2 3
0 0
0 0
-1 -1 1 1
0 0 2 2
1 1 4 4
Output
2
2
0
Input
5 5
10 5
-3 -8
2 11
6 0
-1 3
-3 1 3 13
-1 -1 9 5
-3 -8 10 11
0 0 5 5
-10 -9 15 10
Output
2
2
5
0
4 | instruction | 0 | 29,981 | 23 | 59,962 |
"Correct Solution:
```
from bisect import bisect_left as bl
def main():
n, m = map(int, input().split())
plst = []
xlst = set()
ylst = set()
for _ in range(n):
x, y = map(int, input().split())
plst.append((x, y))
xlst.add(x)
ylst.add(y)
xlst = sorted(list(xlst))
ylst = sorted(list(ylst))
xdic = {}
ydic = {}
for i, x in enumerate(xlst):
xdic[x] = i
for i, y in enumerate(ylst):
ydic[y] = i
xlen = len(xlst)
ylen = len(ylst)
mp = [[0] * (xlen + 1) for _ in range(ylen + 1)]
for x, y in plst:
mp[ydic[y] + 1][xdic[x] + 1] += 1
for y in range(1, ylen + 1):
acc = 0
for x in range(1, xlen + 1):
acc += mp[y][x]
mp[y][x] = acc + mp[y - 1][x]
for _ in range(m):
x1, y1, x2, y2 = map(int, input().split())
x1i = bl(xlst, x1)
y1i = bl(ylst, y1)
x2i = bl(xlst, x2)
y2i = bl(ylst, y2)
if x2i < xlen and xlst[x2i] == x2:
x2i += 1
if y2i < ylen and ylst[y2i] == y2:
y2i += 1
print(mp[y2i][x2i] - mp[y2i][x1i] - mp[y1i][x2i] + mp[y1i][x1i])
main()
``` | output | 1 | 29,981 | 23 | 59,963 |
Provide a correct Python 3 solution for this coding contest problem.
Taro came to a square to look for treasure. There are many treasures buried in this square, but Taro has the latest machines, so he knows everything about where the treasures are buried. Since the square is very wide Taro decided to look for the treasure to decide the area, but the treasure is what treasure does not know immediately whether or not there in the area for a lot. So Taro decided to count the number of treasures in that area.
Constraints
> 1 ≤ n ≤ 5000
> 1 ≤ m ≤ 5 × 105
> | xi |, | yi | ≤ 109 (1 ≤ i ≤ n)
> | xi1 |, | yi1 |, | xi2 |, | yi2 | ≤ 109 (1 ≤ i ≤ m)
> xi1 ≤ xi2, yi1 ≤ yi2 (1 ≤ i ≤ m)
>
* All inputs are given as integers
Input
> n m
> x1 y1
> x2 y2
> ...
> xn yn
> x11 y11 x12 y12
> x21 y21 x22 y22
> ...
> xm1 ym1 xm2 ym2
>
* n represents the number of treasures buried in the square
* m represents the number of regions to examine
* The 2nd to n + 1 lines represent the coordinates where each treasure is buried.
* The n + 2nd to n + m + 1 lines represent each area to be examined.
* The positive direction of the x-axis represents the east and the positive direction of the y-axis represents the north.
* Each region is a rectangle, xi1 and yi1 represent the coordinates of the southwestern apex of the rectangle, and xi2 and yi2 represent the coordinates of the northeastern apex of the rectangle.
Output
> C1
> C2
> ...
> Cm
>
* Output the number of treasures contained in each area to each line
Examples
Input
3 1
1 1
2 4
5 3
0 0 5 5
Output
3
Input
4 2
-1 1
0 3
4 0
2 1
-3 1 5 1
4 0 4 0
Output
2
1
Input
2 3
0 0
0 0
-1 -1 1 1
0 0 2 2
1 1 4 4
Output
2
2
0
Input
5 5
10 5
-3 -8
2 11
6 0
-1 3
-3 1 3 13
-1 -1 9 5
-3 -8 10 11
0 0 5 5
-10 -9 15 10
Output
2
2
5
0
4 | instruction | 0 | 29,982 | 23 | 59,964 |
"Correct Solution:
```
"""
AOJ 2426 Treasure Hunt
座標圧縮を二次元でやるっぽい
上の問題たちとちがうのは、ここからここまでが領域1です、みたいな形になっている点か。
また、例4をみると、ある領域の内側に小さな領域があるパターンもあり、小さいほうに入っている宝は両方に所属していることになるっぽい。
さっぱりなので写経
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2963309#1
二次元累積和がはじめてなので、そっちの練習がまず先に必要っぽい
"""
from bisect import bisect_left
def main():
N,M = map(int, input().split())
treasures = []
# 宝のx,yの位置(ある宝のx,yの組ではなく、x,y座標的にどこに位置するか)
Xs = set()
Ys = set()
for _ in range(N):
x,y = map(int, input().split())
treasures.append((x,y))
Xs.add(x)
Ys.add(y)
# x,yそれぞれで座圧
Xs = list(Xs)
Xs.sort()
Ys = list(Ys)
Ys.sort()
# 座標xはO番目、みたいな情報を作る
Xd = {}
Yd = {}
for i,x in enumerate(Xs):
Xd[x] = i
for i,y in enumerate(Ys):
Yd[y] = i
lx = len(Xs)
ly = len(Ys)
# ここに宝があるよ、を座圧した情報にする
compressd_treasures = [[0 for _ in range(lx + 1)] for _ in range(ly + 1)]
for x,y in treasures:
# yyy番目のy座標とxxx番目のxxx座標に宝があるよ
compressd_treasures[Yd[y] + 1][Xd[x] + 1] += 1
# 左下から右上に向かって、「下や左から(南から?)進んできて何個宝があるか」の累積和をとる
# ここの操作後、comp~[y][x]で、(一番左下の座標(原点ではない))~(x,y)の長方形の中にある宝の数が得られるから、
# うまいことやると(x1,y1)~(x2,y2)の範囲の宝の数が得られる
for y in range(1, ly + 1):
acc = 0
for x in range(1, lx + 1):
# accに足しておいて、xが進むごとに左から右へも累積和をとれる
acc += compressd_treasures[y][x]
# 下の所から積み上げて累積和
compressd_treasures[y][x] = acc + compressd_treasures[y-1][x]
for _ in range(M):
x1, y1, x2, y2 = map(int, input().split())
# それぞれの座標について、何番目の宝まで含みうるか考える
idx_x1 = bisect_left(Xs, x1)
idx_x2 = bisect_left(Xs, x2)
idx_y1 = bisect_left(Ys, y1)
idx_y2 = bisect_left(Ys, y2)
# 宝が領域の境界線上にあるとき、加算する(bisectした値と同じものがXs,Ysにあるとき)
if idx_x2 < lx and Xs[idx_x2] == x2:
idx_x2 += 1
if idx_y2 < ly and Ys[idx_y2] == y2:
idx_y2 += 1
# 累積和で出す。l~r = 0~r - 0~l-1 を二次元にしたバージョン
ans = compressd_treasures[idx_y2][idx_x2] - compressd_treasures[idx_y2][idx_x1] - compressd_treasures[idx_y1][idx_x2] + compressd_treasures[idx_y1][idx_x1]
print(ans)
if __name__ =="__main__":
main()
``` | output | 1 | 29,982 | 23 | 59,965 |
Provide a correct Python 3 solution for this coding contest problem.
Taro came to a square to look for treasure. There are many treasures buried in this square, but Taro has the latest machines, so he knows everything about where the treasures are buried. Since the square is very wide Taro decided to look for the treasure to decide the area, but the treasure is what treasure does not know immediately whether or not there in the area for a lot. So Taro decided to count the number of treasures in that area.
Constraints
> 1 ≤ n ≤ 5000
> 1 ≤ m ≤ 5 × 105
> | xi |, | yi | ≤ 109 (1 ≤ i ≤ n)
> | xi1 |, | yi1 |, | xi2 |, | yi2 | ≤ 109 (1 ≤ i ≤ m)
> xi1 ≤ xi2, yi1 ≤ yi2 (1 ≤ i ≤ m)
>
* All inputs are given as integers
Input
> n m
> x1 y1
> x2 y2
> ...
> xn yn
> x11 y11 x12 y12
> x21 y21 x22 y22
> ...
> xm1 ym1 xm2 ym2
>
* n represents the number of treasures buried in the square
* m represents the number of regions to examine
* The 2nd to n + 1 lines represent the coordinates where each treasure is buried.
* The n + 2nd to n + m + 1 lines represent each area to be examined.
* The positive direction of the x-axis represents the east and the positive direction of the y-axis represents the north.
* Each region is a rectangle, xi1 and yi1 represent the coordinates of the southwestern apex of the rectangle, and xi2 and yi2 represent the coordinates of the northeastern apex of the rectangle.
Output
> C1
> C2
> ...
> Cm
>
* Output the number of treasures contained in each area to each line
Examples
Input
3 1
1 1
2 4
5 3
0 0 5 5
Output
3
Input
4 2
-1 1
0 3
4 0
2 1
-3 1 5 1
4 0 4 0
Output
2
1
Input
2 3
0 0
0 0
-1 -1 1 1
0 0 2 2
1 1 4 4
Output
2
2
0
Input
5 5
10 5
-3 -8
2 11
6 0
-1 3
-3 1 3 13
-1 -1 9 5
-3 -8 10 11
0 0 5 5
-10 -9 15 10
Output
2
2
5
0
4 | instruction | 0 | 29,983 | 23 | 59,966 |
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
class Ruiwa():
def __init__(self, a):
self.H = h = len(a)
self.W = w = len(a[0])
self.R = r = a
for i in range(h):
for j in range(1,w):
r[i][j] += r[i][j-1]
for i in range(1,h):
for j in range(w):
r[i][j] += r[i-1][j]
def search(self, x1, y1, x2, y2):
if x1 > x2 or y1 > y2:
return 0
r = self.R
rr = r[y2][x2]
if x1 > 0 and y1 > 0:
return rr - r[y1-1][x2] - r[y2][x1-1] + r[y1-1][x1-1]
if x1 > 0:
rr -= r[y2][x1-1]
if y1 > 0:
rr -= r[y1-1][x2]
return rr
def main():
n,m = LI()
na = [LI() for _ in range(n)]
xd = set()
yd = set()
for x,y in na:
xd.add(x)
yd.add(y)
xl = sorted(list(xd))
yl = sorted(list(yd))
xx = {}
yy = {}
for i in range(len(xl)):
xx[xl[i]] = i
for i in range(len(yl)):
yy[yl[i]] = i
a = [[0]*(len(yl)+1) for _ in range(len(xl)+1)]
for x,y in na:
a[xx[x]][yy[y]] += 1
rui = Ruiwa(a)
r = []
for _ in range(m):
x1,y1,x2,y2 = LI()
xx1 = bisect.bisect_left(xl, x1)
yy1 = bisect.bisect_left(yl, y1)
xx2 = bisect.bisect(xl, x2) - 1
yy2 = bisect.bisect(yl, y2) - 1
r.append(rui.search(yy1,xx1,yy2,xx2))
return '\n'.join(map(str,r))
print(main())
``` | output | 1 | 29,983 | 23 | 59,967 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Taro came to a square to look for treasure. There are many treasures buried in this square, but Taro has the latest machines, so he knows everything about where the treasures are buried. Since the square is very wide Taro decided to look for the treasure to decide the area, but the treasure is what treasure does not know immediately whether or not there in the area for a lot. So Taro decided to count the number of treasures in that area.
Constraints
> 1 ≤ n ≤ 5000
> 1 ≤ m ≤ 5 × 105
> | xi |, | yi | ≤ 109 (1 ≤ i ≤ n)
> | xi1 |, | yi1 |, | xi2 |, | yi2 | ≤ 109 (1 ≤ i ≤ m)
> xi1 ≤ xi2, yi1 ≤ yi2 (1 ≤ i ≤ m)
>
* All inputs are given as integers
Input
> n m
> x1 y1
> x2 y2
> ...
> xn yn
> x11 y11 x12 y12
> x21 y21 x22 y22
> ...
> xm1 ym1 xm2 ym2
>
* n represents the number of treasures buried in the square
* m represents the number of regions to examine
* The 2nd to n + 1 lines represent the coordinates where each treasure is buried.
* The n + 2nd to n + m + 1 lines represent each area to be examined.
* The positive direction of the x-axis represents the east and the positive direction of the y-axis represents the north.
* Each region is a rectangle, xi1 and yi1 represent the coordinates of the southwestern apex of the rectangle, and xi2 and yi2 represent the coordinates of the northeastern apex of the rectangle.
Output
> C1
> C2
> ...
> Cm
>
* Output the number of treasures contained in each area to each line
Examples
Input
3 1
1 1
2 4
5 3
0 0 5 5
Output
3
Input
4 2
-1 1
0 3
4 0
2 1
-3 1 5 1
4 0 4 0
Output
2
1
Input
2 3
0 0
0 0
-1 -1 1 1
0 0 2 2
1 1 4 4
Output
2
2
0
Input
5 5
10 5
-3 -8
2 11
6 0
-1 3
-3 1 3 13
-1 -1 9 5
-3 -8 10 11
0 0 5 5
-10 -9 15 10
Output
2
2
5
0
4
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
class Ruiwa():
def __init__(self, a):
self.H = h = len(a)
self.W = w = len(a[0])
self.R = r = a
for i in range(h):
for j in range(1,w):
r[i][j] += r[i][j-1]
for i in range(1,h):
for j in range(w):
r[i][j] += r[i-1][j]
def search(self, x1, y1, x2, y2):
print(x1, y1, x2, y2)
if x1 > x2 or y1 > y2:
return 0
r = self.R
rr = r[y2][x2]
if x1 > 0 and y1 > 0:
return rr - r[y1-1][x2] - r[y2][x1-1] + r[y1-1][x1-1]
if x1 > 0:
rr -= r[y2][x1-1]
if y1 > 0:
rr -= r[y1-1][x2]
return rr
def main():
n,m = LI()
na = [LI() for _ in range(n)]
ma = [LI() for _ in range(m)]
xd = set()
yd = set()
for x,y in na:
xd.add(x)
yd.add(y)
for x1,y1,x2,y2 in ma:
xd.add(x1)
yd.add(y1)
xd.add(x2)
yd.add(y2)
xl = sorted(list(xd))
yl = sorted(list(yd))
xx = {}
yy = {}
for i in range(len(xl)):
xx[xl[i]] = i
for i in range(len(yl)):
yy[yl[i]] = i
a = [[0]*(len(yl)+1) for _ in range(len(xl)+1)]
for x,y in na:
a[xx[x]][yy[y]] += 1
rui = Ruiwa(a)
r = []
for x1,y1,x2,y2 in ma:
r.append(rui.search(yy[y1],xx[x1],yy[y2],xx[x2]))
return '\n'.join(map(str,r))
print(main())
``` | instruction | 0 | 29,984 | 23 | 59,968 |
No | output | 1 | 29,984 | 23 | 59,969 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Taro came to a square to look for treasure. There are many treasures buried in this square, but Taro has the latest machines, so he knows everything about where the treasures are buried. Since the square is very wide Taro decided to look for the treasure to decide the area, but the treasure is what treasure does not know immediately whether or not there in the area for a lot. So Taro decided to count the number of treasures in that area.
Constraints
> 1 ≤ n ≤ 5000
> 1 ≤ m ≤ 5 × 105
> | xi |, | yi | ≤ 109 (1 ≤ i ≤ n)
> | xi1 |, | yi1 |, | xi2 |, | yi2 | ≤ 109 (1 ≤ i ≤ m)
> xi1 ≤ xi2, yi1 ≤ yi2 (1 ≤ i ≤ m)
>
* All inputs are given as integers
Input
> n m
> x1 y1
> x2 y2
> ...
> xn yn
> x11 y11 x12 y12
> x21 y21 x22 y22
> ...
> xm1 ym1 xm2 ym2
>
* n represents the number of treasures buried in the square
* m represents the number of regions to examine
* The 2nd to n + 1 lines represent the coordinates where each treasure is buried.
* The n + 2nd to n + m + 1 lines represent each area to be examined.
* The positive direction of the x-axis represents the east and the positive direction of the y-axis represents the north.
* Each region is a rectangle, xi1 and yi1 represent the coordinates of the southwestern apex of the rectangle, and xi2 and yi2 represent the coordinates of the northeastern apex of the rectangle.
Output
> C1
> C2
> ...
> Cm
>
* Output the number of treasures contained in each area to each line
Examples
Input
3 1
1 1
2 4
5 3
0 0 5 5
Output
3
Input
4 2
-1 1
0 3
4 0
2 1
-3 1 5 1
4 0 4 0
Output
2
1
Input
2 3
0 0
0 0
-1 -1 1 1
0 0 2 2
1 1 4 4
Output
2
2
0
Input
5 5
10 5
-3 -8
2 11
6 0
-1 3
-3 1 3 13
-1 -1 9 5
-3 -8 10 11
0 0 5 5
-10 -9 15 10
Output
2
2
5
0
4
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
class Ruiwa():
def __init__(self, a):
self.H = h = len(a)
self.W = w = len(a[0])
self.R = r = a
for i in range(h):
for j in range(1,w):
r[i][j] += r[i][j-1]
for i in range(1,h):
for j in range(w):
r[i][j] += r[i-1][j]
def search(self, x1, y1, x2, y2):
if x1 > x2 or y1 > y2:
return 0
r = self.R
rr = r[y2][x2]
if x1 > 0 and y1 > 0:
return rr - r[y1-1][x2] - r[y2][x1-1] + r[y1-1][x1-1]
if x1 > 0:
rr -= r[y2][x1-1]
if y1 > 0:
rr -= r[y1-1][x2]
return rr
def main():
n,m = LI()
na = [LI() for _ in range(n)]
ma = [LI() for _ in range(m)]
xd = set()
yd = set()
for x,y in na:
xd.add(x)
yd.add(y)
for x1,y1,x2,y2 in ma:
xd.add(x1)
yd.add(y1)
xd.add(x2)
yd.add(y2)
xl = sorted(list(xd))
yl = sorted(list(yd))
xx = {}
yy = {}
for i in range(len(xl)):
xx[xl[i]] = i
for i in range(len(yl)):
yy[yl[i]] = i
a = [[0]*(len(yl)+1) for _ in range(len(xl)+1)]
for x,y in na:
a[xx[x]][yy[y]] += 1
rui = Ruiwa(a)
r = []
for x1,y1,x2,y2 in ma:
r.append(rui.search(yy[y1],xx[x1],yy[y2],xx[x2]))
return '\n'.join(map(str,r))
print(main())
``` | instruction | 0 | 29,985 | 23 | 59,970 |
No | output | 1 | 29,985 | 23 | 59,971 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Taro came to a square to look for treasure. There are many treasures buried in this square, but Taro has the latest machines, so he knows everything about where the treasures are buried. Since the square is very wide Taro decided to look for the treasure to decide the area, but the treasure is what treasure does not know immediately whether or not there in the area for a lot. So Taro decided to count the number of treasures in that area.
Constraints
> 1 ≤ n ≤ 5000
> 1 ≤ m ≤ 5 × 105
> | xi |, | yi | ≤ 109 (1 ≤ i ≤ n)
> | xi1 |, | yi1 |, | xi2 |, | yi2 | ≤ 109 (1 ≤ i ≤ m)
> xi1 ≤ xi2, yi1 ≤ yi2 (1 ≤ i ≤ m)
>
* All inputs are given as integers
Input
> n m
> x1 y1
> x2 y2
> ...
> xn yn
> x11 y11 x12 y12
> x21 y21 x22 y22
> ...
> xm1 ym1 xm2 ym2
>
* n represents the number of treasures buried in the square
* m represents the number of regions to examine
* The 2nd to n + 1 lines represent the coordinates where each treasure is buried.
* The n + 2nd to n + m + 1 lines represent each area to be examined.
* The positive direction of the x-axis represents the east and the positive direction of the y-axis represents the north.
* Each region is a rectangle, xi1 and yi1 represent the coordinates of the southwestern apex of the rectangle, and xi2 and yi2 represent the coordinates of the northeastern apex of the rectangle.
Output
> C1
> C2
> ...
> Cm
>
* Output the number of treasures contained in each area to each line
Examples
Input
3 1
1 1
2 4
5 3
0 0 5 5
Output
3
Input
4 2
-1 1
0 3
4 0
2 1
-3 1 5 1
4 0 4 0
Output
2
1
Input
2 3
0 0
0 0
-1 -1 1 1
0 0 2 2
1 1 4 4
Output
2
2
0
Input
5 5
10 5
-3 -8
2 11
6 0
-1 3
-3 1 3 13
-1 -1 9 5
-3 -8 10 11
0 0 5 5
-10 -9 15 10
Output
2
2
5
0
4
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
class Ruiwa():
def __init__(self, a):
self.H = h = len(a)
self.W = w = len(a[0])
self.R = r = a
for i in range(h):
for j in range(1,w):
r[i][j] += r[i][j-1]
for i in range(1,h):
for j in range(w):
r[i][j] += r[i-1][j]
def search(self, x1, y1, x2, y2):
if x1 > x2 or y1 > y2:
return 0
r = self.R
rr = r[y2][x2]
if x1 > 0 and y1 > 0:
return rr - r[y1-1][x2] - r[y2][x1-1] + r[y1-1][x1-1]
if x1 > 0:
rr -= r[y2][x1-1]
if y1 > 0:
rr -= r[y1-1][x2]
return rr
def main():
n,m = LI()
na = [LI() for _ in range(n)]
xd = set()
yd = set()
for x,y in na:
xd.add(x)
yd.add(y)
xl = sorted(list(xd))
yl = sorted(list(yd))
xx = {}
yy = {}
for i in range(len(xl)):
xx[xl[i]] = i
for i in range(len(yl)):
yy[yl[i]] = i
a = [[0]*(len(yl)+1) for _ in range(len(xl)+1)]
for x,y in na:
a[xx[x]][yy[y]] += 1
rui = Ruiwa(a)
r = []
for x1,y1,x2,y2 in [LI() for _ in range(m)]:
xx1 = bisect.bisect_left(xl, x1)
yy1 = bisect.bisect_left(yl, y1)
xx2 = bisect.bisect(xl, x2) - 1
yy2 = bisect.bisect(yl, y2) - 1
r.append(rui.search(yy1,xx1,yy2,xx2))
return '\n'.join(map(str,r))
print(main())
``` | instruction | 0 | 29,986 | 23 | 59,972 |
No | output | 1 | 29,986 | 23 | 59,973 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$.
A column vector with m elements is represented by the following equation.
\\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\]
A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation.
\\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\]
$i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$).
The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula:
\\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
Constraints
* $1 \leq n, m \leq 100$
* $0 \leq b_i, a_{ij} \leq 1000$
Input
In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.
Output
The output consists of $n$ lines. Print $c_i$ in a line.
Example
Input
3 4
1 2 0 1
0 3 0 1
4 1 1 0
1
2
3
0
Output
5
6
9 | instruction | 0 | 30,044 | 23 | 60,088 |
"Correct Solution:
```
n,m=map(int,input().split())
a = [[int(x) for x in input().split()] for _ in range(n)]
b = [int(input()) for _ in range(m)]
for i in range(n):
s = 0
for j in range(m):
s += a[i][j] * b[j]
print(s)
``` | output | 1 | 30,044 | 23 | 60,089 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$.
A column vector with m elements is represented by the following equation.
\\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\]
A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation.
\\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\]
$i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$).
The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula:
\\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
Constraints
* $1 \leq n, m \leq 100$
* $0 \leq b_i, a_{ij} \leq 1000$
Input
In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.
Output
The output consists of $n$ lines. Print $c_i$ in a line.
Example
Input
3 4
1 2 0 1
0 3 0 1
4 1 1 0
1
2
3
0
Output
5
6
9 | instruction | 0 | 30,045 | 23 | 60,090 |
"Correct Solution:
```
n,m=map(int, input().split())
A=[list(map(int,input().split())) for i in range(n)]
b=[list(map(int,input().split())) for i in range(m)]
for i in range(n):
c=[]
for j in range(m):
c += A[i][j]*b[j]
print(sum(c))
``` | output | 1 | 30,045 | 23 | 60,091 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$.
A column vector with m elements is represented by the following equation.
\\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\]
A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation.
\\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\]
$i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$).
The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula:
\\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
Constraints
* $1 \leq n, m \leq 100$
* $0 \leq b_i, a_{ij} \leq 1000$
Input
In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.
Output
The output consists of $n$ lines. Print $c_i$ in a line.
Example
Input
3 4
1 2 0 1
0 3 0 1
4 1 1 0
1
2
3
0
Output
5
6
9 | instruction | 0 | 30,046 | 23 | 60,092 |
"Correct Solution:
```
f=lambda:list(map(int,input().split()))
n,m=f()
M=[f()for _ in [0]*n]
V=[f()[0]for _ in [0]*m]
for v in M:print(sum(i*j for i,j in zip(v,V)))
``` | output | 1 | 30,046 | 23 | 60,093 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$.
A column vector with m elements is represented by the following equation.
\\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\]
A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation.
\\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\]
$i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$).
The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula:
\\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
Constraints
* $1 \leq n, m \leq 100$
* $0 \leq b_i, a_{ij} \leq 1000$
Input
In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.
Output
The output consists of $n$ lines. Print $c_i$ in a line.
Example
Input
3 4
1 2 0 1
0 3 0 1
4 1 1 0
1
2
3
0
Output
5
6
9 | instruction | 0 | 30,047 | 23 | 60,094 |
"Correct Solution:
```
n, m = list(map(int, input().split()))
matrix_a = [list(map(int, input().split())) for i in range(n)]
matrix_b = [int(input()) for i in range(m)]
for i in range(n):
print(sum([x*y for (x,y) in zip(matrix_b,matrix_a[i])]))
``` | output | 1 | 30,047 | 23 | 60,095 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$.
A column vector with m elements is represented by the following equation.
\\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\]
A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation.
\\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\]
$i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$).
The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula:
\\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
Constraints
* $1 \leq n, m \leq 100$
* $0 \leq b_i, a_{ij} \leq 1000$
Input
In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.
Output
The output consists of $n$ lines. Print $c_i$ in a line.
Example
Input
3 4
1 2 0 1
0 3 0 1
4 1 1 0
1
2
3
0
Output
5
6
9 | instruction | 0 | 30,048 | 23 | 60,096 |
"Correct Solution:
```
n,m=map(int,input().split())
A=[input().split()for _ in[0]*n]
b=[input()for _ in[0]*m]
for a in A:print(sum(int(x)*int(y)for x,y in zip(a,b)))
``` | output | 1 | 30,048 | 23 | 60,097 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$.
A column vector with m elements is represented by the following equation.
\\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\]
A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation.
\\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\]
$i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$).
The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula:
\\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
Constraints
* $1 \leq n, m \leq 100$
* $0 \leq b_i, a_{ij} \leq 1000$
Input
In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.
Output
The output consists of $n$ lines. Print $c_i$ in a line.
Example
Input
3 4
1 2 0 1
0 3 0 1
4 1 1 0
1
2
3
0
Output
5
6
9 | instruction | 0 | 30,049 | 23 | 60,098 |
"Correct Solution:
```
n,m = map(int,input().split())
v1 = [ input().split() for _ in range(n) ]
v2 = [ int(input()) for _ in range(m) ]
l = [sum(map(lambda x,y:int(x)*y,v,v2)) for v in v1 ]
print(*l,sep="\n")
``` | output | 1 | 30,049 | 23 | 60,099 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$.
A column vector with m elements is represented by the following equation.
\\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\]
A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation.
\\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\]
$i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$).
The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula:
\\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
Constraints
* $1 \leq n, m \leq 100$
* $0 \leq b_i, a_{ij} \leq 1000$
Input
In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.
Output
The output consists of $n$ lines. Print $c_i$ in a line.
Example
Input
3 4
1 2 0 1
0 3 0 1
4 1 1 0
1
2
3
0
Output
5
6
9 | instruction | 0 | 30,050 | 23 | 60,100 |
"Correct Solution:
```
N, M = map(int, input().split())
A = []
for i in range(N):
A.append(list(map(int, input().split())))
for i in range(M):
bi = int(input())
for j in range(N):
A[j][i] *= bi
for i in range(N):
print(sum(A[i]))
``` | output | 1 | 30,050 | 23 | 60,101 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$.
A column vector with m elements is represented by the following equation.
\\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\]
A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation.
\\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\]
$i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$).
The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula:
\\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
Constraints
* $1 \leq n, m \leq 100$
* $0 \leq b_i, a_{ij} \leq 1000$
Input
In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.
Output
The output consists of $n$ lines. Print $c_i$ in a line.
Example
Input
3 4
1 2 0 1
0 3 0 1
4 1 1 0
1
2
3
0
Output
5
6
9 | instruction | 0 | 30,051 | 23 | 60,102 |
"Correct Solution:
```
n,m=map(int,input().split())
a = [input().split() for l in range(n)]
b=[int(input()) for i in range(m)]
du=0
for v in range(n):
for k in range(m):
du+=int(a[v][k])*b[k]
print(du)
du=0
``` | output | 1 | 30,051 | 23 | 60,103 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one which has all four vertices in the set of special points. Given the set of special points, please calculate the maximal area of a special quadrilateral.
Input
The first line contains integer n (4 ≤ n ≤ 300). Each of the next n lines contains two integers: xi, yi ( - 1000 ≤ xi, yi ≤ 1000) — the cartesian coordinates of ith special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide.
Output
Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed 10 - 9.
Examples
Input
5
0 0
0 4
4 0
4 4
2 3
Output
16.000000
Note
In the test example we can choose first 4 points to be the vertices of the quadrilateral. They form a square by side 4, so the area is 4·4 = 16. | instruction | 0 | 30,387 | 23 | 60,774 |
Tags: brute force, geometry
Correct Solution:
```
n = int(input())
l = []
def cross(x1,y1,x2,y2):
area = x1*y2 - y1*x2
return area
for i in range(n):
x,y = map(int,input().split())
l.append([x,y])
max_upper = 0
max_lower = 0
ans = 0
for i in range(n-1):
for j in range(i+1,n):
max_upper = 0
max_lower = 0
for k in range(n):
if i!=j and i!=k and j!=k:
area = (l[j][0] - l[i][0])*(l[k][1] - l[i][1])-(l[j][1] - l[i][1])*(l[k][0] - l[i][0])
# print(area/2)
if area>0:
if area>max_upper:
max_upper = area
else:
if -area>max_lower and area!=0:
max_lower = -area
if max_lower + max_upper > ans and max_lower!=0 and max_upper!=0:
ans = max_lower + max_upper
print(ans/2)
``` | output | 1 | 30,387 | 23 | 60,775 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one which has all four vertices in the set of special points. Given the set of special points, please calculate the maximal area of a special quadrilateral.
Input
The first line contains integer n (4 ≤ n ≤ 300). Each of the next n lines contains two integers: xi, yi ( - 1000 ≤ xi, yi ≤ 1000) — the cartesian coordinates of ith special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide.
Output
Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed 10 - 9.
Examples
Input
5
0 0
0 4
4 0
4 4
2 3
Output
16.000000
Note
In the test example we can choose first 4 points to be the vertices of the quadrilateral. They form a square by side 4, so the area is 4·4 = 16. | instruction | 0 | 30,388 | 23 | 60,776 |
Tags: brute force, geometry
Correct Solution:
```
def cross(x1, y1, x2, y2):
return x1 * y2 - x2 * y1
def gao():
n = int(input())
x, y = [], []
for i in range(n):
x1, y1 = input().split(' ')
x.append(int(x1))
y.append(int(y1))
max_area = 0
for i in range(n):
for j in range(i+1, n):
max_left, max_right = 0, 0
for k in range(n):
if i != k and j != k:
area = cross(x[j] - x[i], y[j] - y[i], x[k] - x[i], y[k] - y[i])
if area > 0:
max_left = max(max_left, area)
elif area < 0:
max_right = max(max_right, -area)
if max_left != 0 and max_right != 0:
max_area = max(max_area, max_left + max_right)
print(max_area / 2.)
gao()
``` | output | 1 | 30,388 | 23 | 60,777 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one which has all four vertices in the set of special points. Given the set of special points, please calculate the maximal area of a special quadrilateral.
Input
The first line contains integer n (4 ≤ n ≤ 300). Each of the next n lines contains two integers: xi, yi ( - 1000 ≤ xi, yi ≤ 1000) — the cartesian coordinates of ith special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide.
Output
Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed 10 - 9.
Examples
Input
5
0 0
0 4
4 0
4 4
2 3
Output
16.000000
Note
In the test example we can choose first 4 points to be the vertices of the quadrilateral. They form a square by side 4, so the area is 4·4 = 16. | instruction | 0 | 30,389 | 23 | 60,778 |
Tags: brute force, geometry
Correct Solution:
```
n = int(input())
a = []
area = 0
for i in range(n):
a.append([int(i) for i in input().split(' ')])
def get_s(p1, p2, p3):
return ((p2[0] - p1[0]) * (p3[1] - p1[1]) - (p2[1] - p1[1]) * (p3[0] - p1[0])) / 2.0
for i in range(len(a) - 1):
for j in range(i + 1, len(a)):
positive = 0
negative = 0
for k in range(len(a)):
if k == i or k == j:
continue
s = get_s(a[i], a[j], a[k])
if s > 0:
positive = max(positive, s)
if s == 0:
pass
else:
negative = min(negative, s)
if positive != 0 and negative != 0:
area = max(area, positive - negative)
print(area)
``` | output | 1 | 30,389 | 23 | 60,779 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one which has all four vertices in the set of special points. Given the set of special points, please calculate the maximal area of a special quadrilateral.
Input
The first line contains integer n (4 ≤ n ≤ 300). Each of the next n lines contains two integers: xi, yi ( - 1000 ≤ xi, yi ≤ 1000) — the cartesian coordinates of ith special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide.
Output
Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed 10 - 9.
Examples
Input
5
0 0
0 4
4 0
4 4
2 3
Output
16.000000
Note
In the test example we can choose first 4 points to be the vertices of the quadrilateral. They form a square by side 4, so the area is 4·4 = 16. | instruction | 0 | 30,390 | 23 | 60,780 |
Tags: brute force, geometry
Correct Solution:
```
import sys
c, n = 0, int(input())
t = list(map(int, sys.stdin.read().split()))
p = [complex(t[i], t[i + 1]) for i in range(0, 2 * n, 2)]
for x, i in enumerate(p, 1):
for j in p[x:]:
a = b = 0
for k in p:
if k == i or k == j: continue
d = (i.real - k.real) * (j.imag - k.imag) - (i.imag - k.imag) * (j.real - k.real)
a, b = min(d, a), max(d, b)
if a and b: c = max(c, b - a)
print(c / 2)
``` | output | 1 | 30,390 | 23 | 60,781 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one which has all four vertices in the set of special points. Given the set of special points, please calculate the maximal area of a special quadrilateral.
Input
The first line contains integer n (4 ≤ n ≤ 300). Each of the next n lines contains two integers: xi, yi ( - 1000 ≤ xi, yi ≤ 1000) — the cartesian coordinates of ith special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide.
Output
Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed 10 - 9.
Examples
Input
5
0 0
0 4
4 0
4 4
2 3
Output
16.000000
Note
In the test example we can choose first 4 points to be the vertices of the quadrilateral. They form a square by side 4, so the area is 4·4 = 16. | instruction | 0 | 30,391 | 23 | 60,782 |
Tags: brute force, geometry
Correct Solution:
```
# calculate convex of polygon v.
# v is list of complexes stand for points.
def convex(v, eps=1e-8):
# fetch the seed point
v.sort(key=lambda x:(x.real,x.imag))
v = v[0:1] + sorted(v[1:], key=lambda x:(x-v[0]).imag/abs(x-v[0]))
n = 1
for i in range(2, len(v)):
while n > 1 and ((v[n]-v[n-1])*(v[i]-v[n]).conjugate()).imag>-eps:
n -= 1
else:
n += 1
v[n] = v[i]
v[n+1:] = []
return v
# calculate the area of a polygon v, anti-clockwise.
# v is list of complexes stand for points.
def area(v):
ans = 0
for i in range(2, len(v)):
ans += ((v[i]-v[i-1])*(v[i-1]-v[0]).conjugate()).imag
return ans * 0.5
n = int(input())
v = [complex(*tuple(map(int, input().split()))) for i in range(0, n)]
w = convex(v)
n = len(w)
ans = 0
def tri(i, j, k): return abs(((w[i]-w[j])*(w[i]-w[k]).conjugate()).imag) * 0.5
for i in range(0, n):
for j in range(i+2, n):
if i == 0 and j == n-1: continue
l = i + 1
r = j
while l < r-1:
k = l+r>>1
if tri(i, j, k) > tri(i, j, k-1):
l = k
else:
r = k
s1 = tri(i, j, l)
l = j - n + 1
r = i
while l < r-1:
k = l+r>>1
if tri(i, j, k) > tri(i, j, k-1):
l = k
else:
r = k
s2 = tri(i, j, l)
ans = max(ans, s1 + s2)
if n == 3:
for p in v:
if not p in w:
w.append(p)
ans = max(ans, area(w))
w.pop()
print(ans)
``` | output | 1 | 30,391 | 23 | 60,783 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one which has all four vertices in the set of special points. Given the set of special points, please calculate the maximal area of a special quadrilateral.
Input
The first line contains integer n (4 ≤ n ≤ 300). Each of the next n lines contains two integers: xi, yi ( - 1000 ≤ xi, yi ≤ 1000) — the cartesian coordinates of ith special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide.
Output
Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed 10 - 9.
Examples
Input
5
0 0
0 4
4 0
4 4
2 3
Output
16.000000
Note
In the test example we can choose first 4 points to be the vertices of the quadrilateral. They form a square by side 4, so the area is 4·4 = 16. | instruction | 0 | 30,392 | 23 | 60,784 |
Tags: brute force, geometry
Correct Solution:
```
import sys
s, n = 0, int(input())
t = list(map(int, sys.stdin.read().split()))
p = [(t[2 * i], t[2 * i + 1]) for i in range(n)]
for x, i in enumerate(p, 1):
for j in p[x:]:
a = b = 0
for k in p:
d = (i[0] - k[0]) * (j[1] - k[1]) - (i[1] - k[1]) * (j[0] - k[0])
a, b = min(d, a), max(d, b)
if a and b: s = max(s, b - a)
print(s / 2)
``` | output | 1 | 30,392 | 23 | 60,785 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one which has all four vertices in the set of special points. Given the set of special points, please calculate the maximal area of a special quadrilateral.
Input
The first line contains integer n (4 ≤ n ≤ 300). Each of the next n lines contains two integers: xi, yi ( - 1000 ≤ xi, yi ≤ 1000) — the cartesian coordinates of ith special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide.
Output
Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed 10 - 9.
Examples
Input
5
0 0
0 4
4 0
4 4
2 3
Output
16.000000
Note
In the test example we can choose first 4 points to be the vertices of the quadrilateral. They form a square by side 4, so the area is 4·4 = 16. | instruction | 0 | 30,393 | 23 | 60,786 |
Tags: brute force, geometry
Correct Solution:
```
def convex(p):
p.sort(key = lambda x:(x.real, x.imag))
p = p[0:1] + sorted(p[1:], key = lambda x:(x-p[0]).imag / abs(x-p[0]))
j = 1
for i in range(2, len(p)):
while j > 1 and ((p[j] - p[j-1]) * (p[i] - p[j]).conjugate()).imag > -(1e-8):
j -= 1
else:
j += 1
p[j] = p[i]
return p[:j+1]
def area(p):
res = 0
for i in range(2, len(p)):
res += ((p[i] - p[i-1]) * (p[i-1] - p[0]).conjugate()).imag
return res * 0.5
def tri(i, j, k):
return abs(((w[i] - w[j]) * (w[i] - w[k]).conjugate()).imag) * 0.5
n = int(input())
p = [complex(*list(map(int, input().split()))) for i in range(n)]
w = convex(p)
n = len(w)
res = 0
for i in range(n):
for j in range(i+2, n):
if i == 0 and j == n-1:
continue
l, r = i + 1, j
while l < r-1:
m = l + r >> 1
if tri(i, j, m) > tri(i, j, m-1):
l = m
else:
r = m
s1 = tri(i, j, l)
l, r = j - n + 1, i
while l < r-1:
m = l + r >> 1
if tri(i, j, m) > tri(i, j, m-1):
l = m
else:
r = m
s2 = tri(i, j, l)
res = max(res, s1 + s2)
if n == 3:
for i in p:
if i in w:
continue
w.append(i)
res = max(res, area(w))
w.pop()
print(res)
``` | output | 1 | 30,393 | 23 | 60,787 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one which has all four vertices in the set of special points. Given the set of special points, please calculate the maximal area of a special quadrilateral.
Input
The first line contains integer n (4 ≤ n ≤ 300). Each of the next n lines contains two integers: xi, yi ( - 1000 ≤ xi, yi ≤ 1000) — the cartesian coordinates of ith special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide.
Output
Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed 10 - 9.
Examples
Input
5
0 0
0 4
4 0
4 4
2 3
Output
16.000000
Note
In the test example we can choose first 4 points to be the vertices of the quadrilateral. They form a square by side 4, so the area is 4·4 = 16.
Submitted Solution:
```
def cross(x1, y1, x2, y2):
return x1 * y2 - x2 * y1
n = int(input())
A = [[], []]
B = [[], []]
C = [[], []]
D = [[], []]
for i in range(n):
x, y = map(int, input().split())
if len(A[0]) == 0 or (x < A[0][0] or (x == A[0][0] and y < A[0][1])):
A[0] = [x, y]
if len(A[1]) == 0 or (y < A[1][1] or (y == A[1][1] and x < A[1][0])):
A[1] = [x, y]
if len(B[0]) == 0 or (x < B[0][0] or (x == B[0][0] and y > B[0][1])):
B[0] = [x, y]
if len(B[1]) == 0 or (y < B[1][1] or (y == B[1][1] and x > B[1][0])):
B[1] = [x, y]
if len(C[0]) == 0 or (x > C[0][0] or (x == C[0][0] and y < C[0][1])):
C[0] = [x, y]
if len(C[1]) == 0 or (y > C[1][1] or (y == C[1][1] and x < C[1][0])):
C[1] = [x, y]
if len(D[0]) == 0 or (x > D[0][0] or (x == D[0][0] and y > D[0][1])):
D[0] = [x, y]
if len(D[1]) == 0 or (y > D[1][1] or (y == D[1][1] and x > D[1][0])):
D[1] = [x, y]
res = 0
for i in range(2):
for j in range(2):
for k in range(2):
for l in range(2):
res = max(res, abs(cross(C[k][0] - A[i][0], C[k][1] - A[i][1], B[j][0] - A[i][0], B[j][1] - A[i][1])) +
abs(cross(C[k][0] - D[l][0], C[k][1] - D[l][1], B[j][0] - D[l][0], B[j][1] - D[l][1])))
print(res / 2)
``` | instruction | 0 | 30,394 | 23 | 60,788 |
No | output | 1 | 30,394 | 23 | 60,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one which has all four vertices in the set of special points. Given the set of special points, please calculate the maximal area of a special quadrilateral.
Input
The first line contains integer n (4 ≤ n ≤ 300). Each of the next n lines contains two integers: xi, yi ( - 1000 ≤ xi, yi ≤ 1000) — the cartesian coordinates of ith special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide.
Output
Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed 10 - 9.
Examples
Input
5
0 0
0 4
4 0
4 4
2 3
Output
16.000000
Note
In the test example we can choose first 4 points to be the vertices of the quadrilateral. They form a square by side 4, so the area is 4·4 = 16.
Submitted Solution:
```
def ploshad(x1, y1, x2, y2, x3, y3, x4, y4):
S = abs(x1 * y2 + x2 * y3 + x3 * y4 + x4 * y1 - x2 * y1 - x3 * y2 - x4 * y3 - x1 * y4) / 2
return S
MAX = 0
n = int(input())
A = n * [0]
for i in range(n):
A[i] = list(map(int, input().split()))
for i in range(n):
for j in range(i + 1, n):
for k in range(j + 1, n):
for l in range(k + 1, n):
MAX = max(MAX, ploshad(A[i][0], A[i][1], A[j][0], A[j][1], A[k][0], A[k][1], A[l][0], A[l][1]))
print(MAX)
``` | instruction | 0 | 30,395 | 23 | 60,790 |
No | output | 1 | 30,395 | 23 | 60,791 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one which has all four vertices in the set of special points. Given the set of special points, please calculate the maximal area of a special quadrilateral.
Input
The first line contains integer n (4 ≤ n ≤ 300). Each of the next n lines contains two integers: xi, yi ( - 1000 ≤ xi, yi ≤ 1000) — the cartesian coordinates of ith special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide.
Output
Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed 10 - 9.
Examples
Input
5
0 0
0 4
4 0
4 4
2 3
Output
16.000000
Note
In the test example we can choose first 4 points to be the vertices of the quadrilateral. They form a square by side 4, so the area is 4·4 = 16.
Submitted Solution:
```
n = int(input())
l = []
def cross(x1,y1,x2,y2):
area = x1*y2 - y1*x2
return area
for i in range(n):
x,y = map(int,input().split())
l.append([x,y])
max_upper = 0
max_lower = 0
ans = 0
for i in range(n-1):
for j in range(i+1,n):
max_upper = 0
max_lower = 0
for k in range(n):
if i!=j and i!=k and j!=k:
area = (l[j][0] - l[i][0])*(l[k][1] - l[i][1])-(l[j][1] - l[i][1])*(l[k][0] - l[i][0])
# print(area/2)
if area>0:
if area>max_upper:
max_upper = area
else:
if -area>max_lower and area!=0:
max_lower = -area
# print(max_lower,max_upper)
if max_lower + max_upper > ans:
ans = max_lower + max_upper
print(ans/2)
``` | instruction | 0 | 30,396 | 23 | 60,792 |
No | output | 1 | 30,396 | 23 | 60,793 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one which has all four vertices in the set of special points. Given the set of special points, please calculate the maximal area of a special quadrilateral.
Input
The first line contains integer n (4 ≤ n ≤ 300). Each of the next n lines contains two integers: xi, yi ( - 1000 ≤ xi, yi ≤ 1000) — the cartesian coordinates of ith special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide.
Output
Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed 10 - 9.
Examples
Input
5
0 0
0 4
4 0
4 4
2 3
Output
16.000000
Note
In the test example we can choose first 4 points to be the vertices of the quadrilateral. They form a square by side 4, so the area is 4·4 = 16.
Submitted Solution:
```
def convex(p):
p.sort(key = lambda x:(x.real, x.imag))
p = p[0:1] + sorted(p[1:], key = lambda x:(x-p[0]).imag / abs(x-p[0]))
j = 1
for i in range(2, len(p)):
while j > 1 and ((p[j] - p[j-1]) * (p[i] - p[j]).conjugate()).imag > -(1e-8):
j -= 1
else:
j += 1
p[j] = p[i]
return p[:j]
def area(p):
res = 0
for i in range(2, len(p)):
res += ((p[i] - p[i-1]) * (p[i-1] - p[0]).conjugate()).imag
return res * 0.5
n = int(input())
p = [complex(*list(map(int, input().split()))) for i in range(n)]
w = convex(p)
n = len(w)
res = 0
def tri(i, j, k):
return abs(((w[i] - w[j]) * (w[i] - w[k]).conjugate()).imag) * 0.5
for i in range(n):
for j in range(i+2, n):
if i == 0 and j == n-1:
continue
l, r = i + 1, j
while l < r-1:
m = l + r >> 1
if tri(i, j, m) > tri(i, j, m-1):
l = m
else:
r = m
s1 = tri(i, j, l)
l, r = j - n + 1, i
while l < r-1:
m = l + r >> 1
if tri(i, j, m) > tri(i, j, m-1):
l = m
else:
r = m
s2 = tri(i, j, l)
res = max(res, s1 + s2)
if n == 3:
for i in p:
if not i in w:
w.append(i)
res = max(res, area(w))
w.pop()
print(res)
``` | instruction | 0 | 30,397 | 23 | 60,794 |
No | output | 1 | 30,397 | 23 | 60,795 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.
<image>
An example of a trapezoid
Find the area of this trapezoid.
Constraints
* 1≦a≦100
* 1≦b≦100
* 1≦h≦100
* All input values are integers.
* h is even.
Input
The input is given from Standard Input in the following format:
a
b
h
Output
Print the area of the given trapezoid. It is guaranteed that the area is an integer.
Examples
Input
3
4
2
Output
7
Input
4
4
4
Output
16 | instruction | 0 | 30,831 | 23 | 61,662 |
"Correct Solution:
```
a=[int(input()) for i in range(3)];print((a[0]+a[1])*a[2]//2)
``` | output | 1 | 30,831 | 23 | 61,663 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.
<image>
An example of a trapezoid
Find the area of this trapezoid.
Constraints
* 1≦a≦100
* 1≦b≦100
* 1≦h≦100
* All input values are integers.
* h is even.
Input
The input is given from Standard Input in the following format:
a
b
h
Output
Print the area of the given trapezoid. It is guaranteed that the area is an integer.
Examples
Input
3
4
2
Output
7
Input
4
4
4
Output
16 | instruction | 0 | 30,832 | 23 | 61,664 |
"Correct Solution:
```
a, b, h = [int(input()) for i in range(3)]
print(int((a + b) * h / 2))
``` | output | 1 | 30,832 | 23 | 61,665 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.
<image>
An example of a trapezoid
Find the area of this trapezoid.
Constraints
* 1≦a≦100
* 1≦b≦100
* 1≦h≦100
* All input values are integers.
* h is even.
Input
The input is given from Standard Input in the following format:
a
b
h
Output
Print the area of the given trapezoid. It is guaranteed that the area is an integer.
Examples
Input
3
4
2
Output
7
Input
4
4
4
Output
16 | instruction | 0 | 30,833 | 23 | 61,666 |
"Correct Solution:
```
a = int(input())
b = int(input())
c = int(input())
print(c*(a+b)//2)
``` | output | 1 | 30,833 | 23 | 61,667 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.
<image>
An example of a trapezoid
Find the area of this trapezoid.
Constraints
* 1≦a≦100
* 1≦b≦100
* 1≦h≦100
* All input values are integers.
* h is even.
Input
The input is given from Standard Input in the following format:
a
b
h
Output
Print the area of the given trapezoid. It is guaranteed that the area is an integer.
Examples
Input
3
4
2
Output
7
Input
4
4
4
Output
16 | instruction | 0 | 30,834 | 23 | 61,668 |
"Correct Solution:
```
l = [int(input()) for _ in range(3)]
print((l[0] + l[1]) * l[2] //2)
``` | output | 1 | 30,834 | 23 | 61,669 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.
<image>
An example of a trapezoid
Find the area of this trapezoid.
Constraints
* 1≦a≦100
* 1≦b≦100
* 1≦h≦100
* All input values are integers.
* h is even.
Input
The input is given from Standard Input in the following format:
a
b
h
Output
Print the area of the given trapezoid. It is guaranteed that the area is an integer.
Examples
Input
3
4
2
Output
7
Input
4
4
4
Output
16 | instruction | 0 | 30,835 | 23 | 61,670 |
"Correct Solution:
```
a, b, h= (int(input()) for _ in range(3))
print((a+b)*h // 2)
``` | output | 1 | 30,835 | 23 | 61,671 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.
<image>
An example of a trapezoid
Find the area of this trapezoid.
Constraints
* 1≦a≦100
* 1≦b≦100
* 1≦h≦100
* All input values are integers.
* h is even.
Input
The input is given from Standard Input in the following format:
a
b
h
Output
Print the area of the given trapezoid. It is guaranteed that the area is an integer.
Examples
Input
3
4
2
Output
7
Input
4
4
4
Output
16 | instruction | 0 | 30,836 | 23 | 61,672 |
"Correct Solution:
```
a = int(input())
b = int(input())
h = int(input())
print(((a+b)*h)//2)
``` | output | 1 | 30,836 | 23 | 61,673 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.
<image>
An example of a trapezoid
Find the area of this trapezoid.
Constraints
* 1≦a≦100
* 1≦b≦100
* 1≦h≦100
* All input values are integers.
* h is even.
Input
The input is given from Standard Input in the following format:
a
b
h
Output
Print the area of the given trapezoid. It is guaranteed that the area is an integer.
Examples
Input
3
4
2
Output
7
Input
4
4
4
Output
16 | instruction | 0 | 30,837 | 23 | 61,674 |
"Correct Solution:
```
a,b,h=(int(input()) for _ in range(3))
print(int((a+b)*.5*h))
``` | output | 1 | 30,837 | 23 | 61,675 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.
<image>
An example of a trapezoid
Find the area of this trapezoid.
Constraints
* 1≦a≦100
* 1≦b≦100
* 1≦h≦100
* All input values are integers.
* h is even.
Input
The input is given from Standard Input in the following format:
a
b
h
Output
Print the area of the given trapezoid. It is guaranteed that the area is an integer.
Examples
Input
3
4
2
Output
7
Input
4
4
4
Output
16 | instruction | 0 | 30,838 | 23 | 61,676 |
"Correct Solution:
```
a,b,h = map(int, [input() for i in range(3)])
print(int((a+b)*h/2))
``` | output | 1 | 30,838 | 23 | 61,677 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.