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.
Fair Chocolate-Cutting
You are given a flat piece of chocolate of convex polygon shape. You are to cut it into two pieces of precisely the same amount with a straight knife.
Write a program that computes, for a given convex polygon, the maximum and minimum lengths of the line segments that divide the polygon into two equal areas.
The figures below correspond to first two sample inputs. Two dashed lines in each of them correspond to the equal-area cuts of minimum and maximum lengths.
<image>
Figure F.1. Sample Chocolate Pieces and Cut Lines
Input
The input consists of a single test case of the following format.
$n$
$x_1$ $y_1$
...
$x_n$ $y_n$
The first line has an integer $n$, which is the number of vertices of the given polygon. Here, $n$ is between 3 and 5000, inclusive. Each of the following $n$ lines has two integers $x_i$ and $y_i$, which give the coordinates ($x_i, y_i$) of the $i$-th vertex of the polygon, in counterclockwise order. Both $x_i$ and $y_i$ are between 0 and 100 000, inclusive.
The polygon is guaranteed to be simple and convex. In other words, no two edges of the polygon intersect each other and interior angles at all of its vertices are less than $180^\circ$.
Output
Two lines should be output. The first line should have the minimum length of a straight line segment that partitions the polygon into two parts of the equal area. The second line should have the maximum length of such a line segment. The answer will be considered as correct if the values output have an absolute or relative error less than $10^{-6}$.
Sample Input 1
4
0 0
10 0
10 10
0 10
Sample Output 1
10
14.142135623730950488
Sample Input 2
3
0 0
6 0
3 10
Sample Output 2
4.2426406871192851464
10.0
Sample Input 3
5
0 0
99999 20000
100000 70000
33344 63344
1 50000
Sample Output 3
54475.580091580027976
120182.57592539864775
Sample Input 4
6
100 350
101 349
6400 3440
6400 3441
1200 7250
1199 7249
Sample Output 4
4559.2050019027964982
6216.7174287968524227
Example
Input
4
0 0
10 0
10 10
0 10
Output
10
14.142135623730950488 | instruction | 0 | 51,247 | 23 | 102,494 |
"Correct Solution:
```
#!/usr/bin/python3
from decimal import Decimal
from fractions import Fraction
import math
import os
import sys
def main():
N = read_int()
A = [Vec(*read_ints()) for _ in range(N)]
print(*solve(N, A), sep='\n')
def solve(N, Points):
if DEBUG:
dprint('polygon({!r}, fill=False)'.format([(v.x, v.y) for v in Points]))
total_area_2 = 0
for i in range(1, N - 1):
a = Points[i] - Points[0]
b = Points[i + 1] - Points[i]
total_area_2 += a.cross(b)
total_area_4 = 0
bi = -1
for i in range(1, N - 1):
a = Points[i] - Points[0]
b = Points[i + 1] - Points[i]
area_4 = a.cross(b) * 2
if total_area_4 + area_4 <= total_area_2:
total_area_4 += area_4
continue
rest = total_area_2 - total_area_4
k = Fraction(total_area_2 - total_area_4, area_4)
assert 0 <= k < 1
bi = i
bk = k
bv = Points[i] + k * (Points[i + 1] - Points[i])
dprint('bi =', bi, 'bk =', bk, 'bv =', bv)
break
assert bi != -1
ai = 0
ak = 0
maxl = (bv - Points[0]).abs2()
minl = maxl
while bi != 0:
assert 0 <= ak < 1
assert 0 <= bk < 1
dprint('***\nai =', ai, 'ak =', ak, 'bi =', bi, 'bk =', bk)
dprint('minl =', minl, 'maxl =', maxl)
a0 = Points[ai]
a1 = Points[(ai + 1) % N]
b0 = Points[bi]
b1 = Points[(bi + 1) % N]
a2 = a0 + ak * (a1 - a0)
b2 = b0 + bk * (b1 - b0)
dprint('a0 =', a0, 'a1 =', a1, 'a2 =', a2)
dprint('b0 =', b0, 'b1 =', b1, 'b2 =', b2)
al = 1
cross = (b2 - a1).cross(b1 - b0)
if cross != 0:
bl = Fraction((b0 - a2).cross(b2 - a1), cross)
else:
bl = 2 # inf
assert bk < bl
if bl > 1:
al = Fraction((b2 - a0).cross(b1 - a2), (a1 - a0).cross(b1 - a2))
bl = 1
assert ak < al <= 1
assert bk < bl <= 1
a3 = a0 + al * (a1 - a0)
b3 = b0 + bl * (b1 - b0)
dprint('a3 =', a3, 'b3 =', b3)
b3a3 = b3 - a3
l = b3a3.abs2()
dprint('l =', l)
maxl = max(maxl, l)
minl = min(minl, l)
####
a3a2 = a3 - a2
b3b2 = b3 - b2
b2a2 = b2 - a2
A0 = a3a2.cross(b2a2)
B0 = b2a2.cross(b3b2)
aden = A0.denominator if isinstance(A0, Fraction) else 1
bden = B0.denominator if isinstance(B0, Fraction) else 1
gden = aden * bden // math.gcd(aden, bden)
A0 *= gden
B0 *= gden
A0 = int(A0)
B0 = int(B0)
g = math.gcd(A0, B0)
A0 //= g
B0 //= g
dprint('y = ({}) * x / (({}) - ({}) * x)'.format(A0, B0, B0 - A0))
if A0 == B0:
X2 = (a3a2 - b3b2).abs2()
X1 = -2 * b2a2.dot(a3a2 - b3b2)
C = b2a2.abs2()
dprint('L = ({}) * x^2 + ({}) * x + ({})'.format(X2, X1, C))
x = Fraction(-X1, 2 * X2)
dprint('x =', x)
if 0 <= x <= 1:
l = x * (X1 + x * X2) + C
dprint('l =', l)
minl = min(minl, l)
else:
X2 = a3a2.abs2()
X1 = 2 * (-b2a2.dot(a3a2) + Fraction(A0, B0 - A0) * a3a2.dot(b3b2))
Y2 = b3b2.abs2()
Y1 = 2 * (b2a2.dot(b3b2) - Fraction(B0, B0 - A0) * a3a2.dot(b3b2))
L0 = b2a2.abs2()
def calc_l(x, y):
return x * (X1 + x * X2) + y * (Y1 + y * Y2) + L0
A = Fraction(A0, B0 - A0)
B = Fraction(B0, B0 - A0)
poly = [-2 * A * A * B * B * Y2,
-A * B * (2 * A * Y2 - Y1),
0,
2 * B * X2 + X1,
2 * X2]
dprint('poly =', poly)
sols = solve_poly(poly, -B, 1 - B)
dprint('sols =', sols)
for sol_low, sol_high in sols:
x0 = sol_low + B
x1 = sol_high + B
y0 = Fraction(-A * B, x0 - B) - A
y1 = Fraction(-A * B, x1 - B) - A
l0 = calc_l(x0, y0)
l1 = calc_l(x1, y1)
dprint('l0 =', l0, 'l1 =', l1)
minl = min(minl, l0, l1)
####
ak = al
bk = bl
if ak == 1:
ai = (ai + 1) % N
ak = 0
if bk == 1:
bi = (bi + 1) % N
bk = 0
dprint('minl', minl)
dprint('maxl', maxl)
if isinstance(minl, Fraction):
minld = Decimal(minl.numerator) / Decimal(minl.denominator)
else:
minld = Decimal(minl)
if isinstance(maxl, Fraction):
maxld = Decimal(maxl.numerator) / Decimal(maxl.denominator)
else:
maxld = Decimal(maxl)
return minld.sqrt(), maxld.sqrt()
def sgn(v):
if v > 0:
return 1
if v < 0:
return -1
return 0
EPS = Fraction(1, 10 ** 26)
def solve_poly(poly, minx, maxx):
while poly and poly[-1] == 0:
del poly[-1]
if len(poly) <= 1:
return []
if len(poly) == 2:
b, a = poly
x = Fraction(-b, a)
if minx <= x <= maxx:
return [(x, x)]
return []
df = []
for i in range(1, len(poly)):
df.append(i * poly[i])
segs = [(minx, None)] + solve_poly(df, minx, maxx) + [(None, maxx)]
sols = []
def f(x):
v = 0
for i, a in enumerate(poly):
v += a * (x ** i)
return v
for i in range(len(segs) - 1):
lb = segs[i][0]
ub = segs[i + 1][1]
lbs = sgn(f(lb))
ubs = sgn(f(ub))
if (lbs >= 0 and ubs >= 0) or (lbs < 0 and ubs < 0):
continue
while ub - lb > EPS:
midf = Fraction(lb + ub, 2)
mid = Fraction(Decimal(midf.numerator) / Decimal(midf.denominator))
if not (lb < mid < ub):
mid = midf
v = f(mid)
if v >= 0:
if lbs >= 0:
lb = mid
else:
ub = mid
else:
if lbs >= 0:
ub = mid
else:
lb = mid
sols.append((lb, ub))
return sols
###############################################################################
class Vec(object):
def __init__(self, x, y):
self.x = x
self.y = y
super().__init__()
def __add__(self, other):
return Vec(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Vec(self.x - other.x, self.y - other.y)
def __mul__(self, scalar):
return Vec(self.x * scalar, self.y * scalar)
def __rmul__(self, scalar):
return Vec(self.x * scalar, self.y * scalar)
def __truediv__(self, scalar):
return Vec(self.x / scalar, self.y / scalar)
def __iadd__(self, other):
self.x += other.x
self.y += other.y
return self
def __isub__(self, other):
self.x -= other.x
self.y -= other.y
return self
def __imul__(self, scalar):
self.x *= scalar
self.y *= scalar
return self
def __idiv__(self, scalar):
self.x /= scalar
self.y /= scalar
return self
def __neg__(self):
return Vec(-self.x, -self.y)
def __eq__(self, other):
return self.x == other.x and self.y == other.y
def __ne__(self, other):
return not self.__eq__(other)
def __hash__(self):
return hash(('Vec', self.x, self.y))
def dot(self, other):
return self.x * other.x + self.y * other.y
def cross(self, other):
return self.x * other.y - self.y * other.x
def abs2(self):
return self.x * self.x + self.y * self.y
def __abs__(self):
return math.sqrt(float(self.abs2()))
def __str__(self):
return '({}, {})'.format(self.x, self.y)
def __repr__(self):
return 'Vec({!r}, {!r})'.format(self.x, self.y)
DEBUG = 'DEBUG' in os.environ
def inp():
return sys.stdin.readline().rstrip()
def read_int():
return int(inp())
def read_ints():
return [int(e) for e in inp().split()]
def dprint(*value, sep=' ', end='\n'):
if DEBUG:
print(*value, sep=sep, end=end)
if __name__ == '__main__':
main()
``` | output | 1 | 51,247 | 23 | 102,495 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensional coordinate system on this sheet and drew n black horizontal and vertical segments parallel to the coordinate axes. All segments have width equal to 1 square, that means every segment occupy some set of neighbouring squares situated in one row or one column.
Your task is to calculate the number of painted cells. If a cell was painted more than once, it should be calculated exactly once.
Input
The first line of the input contains a single integer n (1 β€ n β€ 100 000) β the number of segments drawn by Vika.
Each of the next n lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1, y1, x2, y2 β€ 109) β the coordinates of the endpoints of the segments drawn by Vika. It is guaranteed that all the segments are parallel to coordinate axes. Segments may touch, overlap and even completely coincide.
Output
Print the number of cells painted by Vika. If a cell was painted more than once, it should be calculated exactly once in the answer.
Examples
Input
3
0 1 2 1
1 4 1 2
0 3 2 3
Output
8
Input
4
-2 -1 2 -1
2 1 -2 1
-1 -2 -1 2
1 2 1 -2
Output
16
Note
In the first sample Vika will paint squares (0, 1), (1, 1), (2, 1), (1, 2), (1, 3), (1, 4), (0, 3) and (2, 3).
Submitted Solution:
```
n = int(input())
l = list()
coord = list()
low = 0
high =0
for i in range(n):
l.append(list(map(int,input().split())))
for i in range(n):
if l[i][0]==l[i][2]:
low = min(l[i][1],l[i][3])
high = max(l[i][1],l[i][3])
for k in range(low,high+1):
if [l[i][0],k] not in coord:
coord.append([l[i][0],k])
else:
low = min(l[i][0],l[i][2])
high = max(l[i][0],l[i][2])
for k in range(low,high+1):
if [l[i][1],k] not in coord:
coord.append([k,l[i][1]])
print (len(coord))
``` | instruction | 0 | 51,736 | 23 | 103,472 |
No | output | 1 | 51,736 | 23 | 103,473 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensional coordinate system on this sheet and drew n black horizontal and vertical segments parallel to the coordinate axes. All segments have width equal to 1 square, that means every segment occupy some set of neighbouring squares situated in one row or one column.
Your task is to calculate the number of painted cells. If a cell was painted more than once, it should be calculated exactly once.
Input
The first line of the input contains a single integer n (1 β€ n β€ 100 000) β the number of segments drawn by Vika.
Each of the next n lines contains four integers x1, y1, x2 and y2 ( - 109 β€ x1, y1, x2, y2 β€ 109) β the coordinates of the endpoints of the segments drawn by Vika. It is guaranteed that all the segments are parallel to coordinate axes. Segments may touch, overlap and even completely coincide.
Output
Print the number of cells painted by Vika. If a cell was painted more than once, it should be calculated exactly once in the answer.
Examples
Input
3
0 1 2 1
1 4 1 2
0 3 2 3
Output
8
Input
4
-2 -1 2 -1
2 1 -2 1
-1 -2 -1 2
1 2 1 -2
Output
16
Note
In the first sample Vika will paint squares (0, 1), (1, 1), (2, 1), (1, 2), (1, 3), (1, 4), (0, 3) and (2, 3).
Submitted Solution:
```
#vika2
a=int(input())
c=[]
for i in range(a):
t=list(map(int,input().split()))
if t[0]==t[2]:
a=True
else:
a=False
if a:
if t[1]>t[3]:
t[1], t[3]=t[3], t[1]
for e in range(t[1], t[3]+1):
c.append([t[0], e])
else:
if t[0]>t[2]:
t[0], t[2]=t[2], t[0]
for e in range(t[0], t[2]+1):
c.append([e,t[1]])
import itertools
c=len(list(c for c,_ in itertools.groupby(c)))
print(c)
``` | instruction | 0 | 51,737 | 23 | 103,474 |
No | output | 1 | 51,737 | 23 | 103,475 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The map of Berland is a rectangle of the size n Γ m, which consists of cells of size 1 Γ 1. Each cell is either land or water. The map is surrounded by the ocean.
Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that it's possible to get from any cell of the set to any other without leaving the set and moving only to cells adjacent by the side, none of them is located on the border of the rectangle, and it's impossible to add one more water cell to the set such that it will be connected with any other cell.
You task is to fill up with the earth the minimum number of water cells so that there will be exactly k lakes in Berland. Note that the initial number of lakes on the map is not less than k.
Input
The first line of the input contains three integers n, m and k (1 β€ n, m β€ 50, 0 β€ k β€ 50) β the sizes of the map and the number of lakes which should be left on the map.
The next n lines contain m characters each β the description of the map. Each of the characters is either '.' (it means that the corresponding cell is water) or '*' (it means that the corresponding cell is land).
It is guaranteed that the map contain at least k lakes.
Output
In the first line print the minimum number of cells which should be transformed from water to land.
In the next n lines print m symbols β the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, print any of them.
It is guaranteed that the answer exists on the given data.
Examples
Input
5 4 1
****
*..*
****
**.*
..**
Output
1
****
*..*
****
****
..**
Input
3 3 0
***
*.*
***
Output
1
***
***
***
Note
In the first example there are only two lakes β the first consists of the cells (2, 2) and (2, 3), the second consists of the cell (4, 3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with the ocean.
Submitted Solution:
```
def main():
def dfs(x, y):
nonlocal inner
if land[y][x] == '.':
s = 1
land[y][x] = '*'
if x:
s += dfs(x - 1, y)
else:
inner = False
if x + 1 < m:
s += dfs(x + 1, y)
else:
inner = False
if y:
s += dfs(x, y - 1)
else:
inner = False
if y + 1 < n:
s += dfs(x, y + 1)
else:
inner = False
return s
return 0
n, m, k = map(int, input().split())
land = [list(input()) for _ in range(n)]
sav = [row[:] for row in land]
lakes = []
for y, row in enumerate(land):
for x, f in enumerate(row):
inner = True
s = dfs(x, y)
if s and inner:
lakes.append((s, x, y))
land, res = sav, 0
for _, x, y in sorted(lakes)[:len(lakes) - k]:
res += dfs(x, y)
print(res)
for row in land:
print(''.join(row))
if __name__ == '__main__':
from sys import setrecursionlimit
setrecursionlimit(3000)
main()
``` | instruction | 0 | 52,687 | 23 | 105,374 |
Yes | output | 1 | 52,687 | 23 | 105,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The map of Berland is a rectangle of the size n Γ m, which consists of cells of size 1 Γ 1. Each cell is either land or water. The map is surrounded by the ocean.
Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that it's possible to get from any cell of the set to any other without leaving the set and moving only to cells adjacent by the side, none of them is located on the border of the rectangle, and it's impossible to add one more water cell to the set such that it will be connected with any other cell.
You task is to fill up with the earth the minimum number of water cells so that there will be exactly k lakes in Berland. Note that the initial number of lakes on the map is not less than k.
Input
The first line of the input contains three integers n, m and k (1 β€ n, m β€ 50, 0 β€ k β€ 50) β the sizes of the map and the number of lakes which should be left on the map.
The next n lines contain m characters each β the description of the map. Each of the characters is either '.' (it means that the corresponding cell is water) or '*' (it means that the corresponding cell is land).
It is guaranteed that the map contain at least k lakes.
Output
In the first line print the minimum number of cells which should be transformed from water to land.
In the next n lines print m symbols β the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, print any of them.
It is guaranteed that the answer exists on the given data.
Examples
Input
5 4 1
****
*..*
****
**.*
..**
Output
1
****
*..*
****
****
..**
Input
3 3 0
***
*.*
***
Output
1
***
***
***
Note
In the first example there are only two lakes β the first consists of the cells (2, 2) and (2, 3), the second consists of the cell (4, 3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with the ocean.
Submitted Solution:
```
class Cell:
def __init__(self, row, clm):
self.row = row
self.clm = clm
dr = [0, 0, -1, 1]
dc = [1, -1, 0, 0]
Berland = []
visited = [[False] * 51 for i in range(51)]
Lakes = []
def DFS(s):
stack = [s]
visited[s.row][s.clm] = True
Ocean = False
lake = []
while len(stack):
u = stack.pop()
lake.append(u)
if u.row == 0 or u.row == n - 1 or u.clm == 0 or u.clm == m - 1:
Ocean = True
for i in range(4):
v = Cell(u.row + dr[i], u.clm + dc[i])
if v.row >= 0 and v.row < n and v.clm >= 0 and v.clm < m and Berland[v.row][v.clm] == "." and not visited[v.row][v.clm]:
visited[v.row][v.clm] = True
stack.append(v)
if not Ocean:
Lakes.append(lake)
n, m, k = map(int, input().split())
for i in range(n):
Berland.append(list(input()))
for i in range(n):
for j in range(m):
if not visited[i][j] and Berland[i][j] == ".":
DFS(Cell(i, j))
Lakes.sort(key = lambda lake: len(lake))
change = len(Lakes) - k
cells_change = 0
for i in range(change):
cells_change += len(Lakes[i])
for s in Lakes[i]:
Berland[s.row][s.clm] = "*"
print(cells_change)
for i in range(n):
print(*Berland[i], sep = "")
``` | instruction | 0 | 52,688 | 23 | 105,376 |
Yes | output | 1 | 52,688 | 23 | 105,377 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The map of Berland is a rectangle of the size n Γ m, which consists of cells of size 1 Γ 1. Each cell is either land or water. The map is surrounded by the ocean.
Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that it's possible to get from any cell of the set to any other without leaving the set and moving only to cells adjacent by the side, none of them is located on the border of the rectangle, and it's impossible to add one more water cell to the set such that it will be connected with any other cell.
You task is to fill up with the earth the minimum number of water cells so that there will be exactly k lakes in Berland. Note that the initial number of lakes on the map is not less than k.
Input
The first line of the input contains three integers n, m and k (1 β€ n, m β€ 50, 0 β€ k β€ 50) β the sizes of the map and the number of lakes which should be left on the map.
The next n lines contain m characters each β the description of the map. Each of the characters is either '.' (it means that the corresponding cell is water) or '*' (it means that the corresponding cell is land).
It is guaranteed that the map contain at least k lakes.
Output
In the first line print the minimum number of cells which should be transformed from water to land.
In the next n lines print m symbols β the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, print any of them.
It is guaranteed that the answer exists on the given data.
Examples
Input
5 4 1
****
*..*
****
**.*
..**
Output
1
****
*..*
****
****
..**
Input
3 3 0
***
*.*
***
Output
1
***
***
***
Note
In the first example there are only two lakes β the first consists of the cells (2, 2) and (2, 3), the second consists of the cell (4, 3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with the ocean.
Submitted Solution:
```
from copy import copy, deepcopy
import heapq
m,n,num_lake = [int(i) for i in input().split()]
Matrix = []
Real_Matrix = []
arr = []
# for i in iter_content:
for i in range(m):
arr = [0 if j == '*' else 1 for j in input()]
Real_Matrix.append(arr)
Matrix = deepcopy(Real_Matrix)
def is_border(pos_x, pos_y, m, n):
if (pos_x == 0 or pos_x == m - 1 or pos_y == 0 or pos_y == n - 1):
return True
return False
def contain_border(result,m,n):
for i in result:
if is_border(i[0], i[1], m,n):
return True
return False
def generate_neighbour(matrix_input,pos_x, pos_y,m,n):
arr = []
# print(pos_x,pos_y)
for i in range (-1,2):
for j in range(-1,2):
if(i == 0 and j == 0) or (i == -1 and j == -1) or (i == 1 and j == -1) or (i == -1 and j == 1) or (i == 1 and j == 1):
continue
# print(pos_x+i,pos_y+j,is_border(pos_x+i,pos_y+j,m,n))
# if is_border(pos_x+i,pos_y+j,m,n):
# continue
# else:
if (pos_x+i > -1 and pos_y+j > -1 and pos_x+i < m and pos_y+j < n):
if (matrix_input[pos_x+i][pos_y+j] == 1):
arr.append([pos_x+i,pos_y+j])
return arr
def dfs_iterative(matrix, start_x_position,start_y_position,m,n):
stack, path = [[start_x_position,start_y_position]], []
while stack:
curren_x,curren_y = stack.pop()
if [curren_x,curren_y] in path:
continue
path.append([curren_x,curren_y])
Matrix[curren_x][curren_y] = 2
neighbour = generate_neighbour(Matrix,curren_x,curren_y,m,n)
for pos_x,pos_y in neighbour:
stack.append([pos_x,pos_y])
return path
def make_lake(Matrix):
land_array = []
result = []
min_cell = 9999999
for i in range(m):
for j in range(n):
# if is_border(i,j,m,n):
# continue
if (Matrix[i][j] == 1):
land_array = dfs_iterative(Matrix,i,j,m,n)
# print("Landarray")
# print(land_array)
if contain_border(land_array,m,n):
continue
heapq.heappush(result,(len(land_array),land_array))
return result
def rebuild_Matrix(Matrix):
result = ""
for i in Matrix:
result = "".join( '*' if j == 0 else '.' for j in i)
print(result)
m = make_lake(Matrix)
# print("LAKE")
# print(m)
num_real_lake = len(m)
# print("num lake " ,num_real_lake)
# term_value = heapq.heappop(m)
# print(term_value)
# print(term_value[1][0])
# for i in Real_Matrix:
# print(i)
count = 0
# for i in m:
# print(i)
for i in range(num_real_lake - num_lake):
term_value = heapq.heappop(m)
# print("term", term_value)
count = count + term_value[0]
for j in term_value[1]:
Real_Matrix[j[0]][j[1]] = 0
# print("\n")
# for i in Real_Matrix:
# print(i)
print(count)
rebuild_Matrix(Real_Matrix)
``` | instruction | 0 | 52,689 | 23 | 105,378 |
Yes | output | 1 | 52,689 | 23 | 105,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The map of Berland is a rectangle of the size n Γ m, which consists of cells of size 1 Γ 1. Each cell is either land or water. The map is surrounded by the ocean.
Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that it's possible to get from any cell of the set to any other without leaving the set and moving only to cells adjacent by the side, none of them is located on the border of the rectangle, and it's impossible to add one more water cell to the set such that it will be connected with any other cell.
You task is to fill up with the earth the minimum number of water cells so that there will be exactly k lakes in Berland. Note that the initial number of lakes on the map is not less than k.
Input
The first line of the input contains three integers n, m and k (1 β€ n, m β€ 50, 0 β€ k β€ 50) β the sizes of the map and the number of lakes which should be left on the map.
The next n lines contain m characters each β the description of the map. Each of the characters is either '.' (it means that the corresponding cell is water) or '*' (it means that the corresponding cell is land).
It is guaranteed that the map contain at least k lakes.
Output
In the first line print the minimum number of cells which should be transformed from water to land.
In the next n lines print m symbols β the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, print any of them.
It is guaranteed that the answer exists on the given data.
Examples
Input
5 4 1
****
*..*
****
**.*
..**
Output
1
****
*..*
****
****
..**
Input
3 3 0
***
*.*
***
Output
1
***
***
***
Note
In the first example there are only two lakes β the first consists of the cells (2, 2) and (2, 3), the second consists of the cell (4, 3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with the ocean.
Submitted Solution:
```
# D. Lakes in Berland
class pair:
x = 0
y = 0
def __init__(self, a, b):
self.x = a
self.y = b
def isValid(u, maze):
return u.x >= 0 and u.x < n and u.y >= 0 and u.y < m and maze[u.x][u.y] == '.'
def isShareBorderOcean(u):
return u.x == 0 or u.x == n - 1 or u.y == 0 or u.y == m - 1
def DFS(maze, points):
dh = [0, -1, 0, 1]
dc = [1, 0, -1, 0]
visited = [[False for xx in range(m)] for yy in range(n)]
lakes = []
for i in range(len(points)):
stack = []
start = points[i]
if visited[start.x][start.y] == False:
visited[start.x][start.y] = True
stack.append(start)
points_in_lake = []
points_in_lake.append(start)
if isShareBorderOcean(start):
tmp_res = 2501
else:
tmp_res = 1
while len(stack) > 0:
u = stack[-1]
stack.pop()
for k in range(4):
v = pair(u.x + dh[k], u.y + dc[k])
if isValid(v, maze) and visited[v.x][v.y] == False:
visited[v.x][v.y] = True
points_in_lake.append(v)
stack.append(v)
if isShareBorderOcean(v):
tmp_res += 2500
else:
tmp_res += 1
if tmp_res < 2500:
lakes.append([tmp_res, points_in_lake])
return lakes
if __name__ == '__main__':
n, m, k = map(int, input().split())
maze = []
for _ in range(n):
maze.append(input())
points = []
for i in range(n):
for j in range(m):
if maze[i][j] == '.':
points.append(pair(i, j))
lakes = DFS(maze, points)
lakes.sort(key=lambda x: x[0])
ans = 0
for i in range(len(lakes)-k):
number_of_points = lakes[i][0]
ans += number_of_points
for j in range(number_of_points):
x = lakes[i][1][j].x
y = lakes[i][1][j].y
tmp_str = list(maze[x])
tmp_str[y] = '*'
maze[x] = ''.join(tmp_str)
print(ans)
for itemMaze in maze:
print(itemMaze)
``` | instruction | 0 | 52,690 | 23 | 105,380 |
Yes | output | 1 | 52,690 | 23 | 105,381 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The map of Berland is a rectangle of the size n Γ m, which consists of cells of size 1 Γ 1. Each cell is either land or water. The map is surrounded by the ocean.
Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that it's possible to get from any cell of the set to any other without leaving the set and moving only to cells adjacent by the side, none of them is located on the border of the rectangle, and it's impossible to add one more water cell to the set such that it will be connected with any other cell.
You task is to fill up with the earth the minimum number of water cells so that there will be exactly k lakes in Berland. Note that the initial number of lakes on the map is not less than k.
Input
The first line of the input contains three integers n, m and k (1 β€ n, m β€ 50, 0 β€ k β€ 50) β the sizes of the map and the number of lakes which should be left on the map.
The next n lines contain m characters each β the description of the map. Each of the characters is either '.' (it means that the corresponding cell is water) or '*' (it means that the corresponding cell is land).
It is guaranteed that the map contain at least k lakes.
Output
In the first line print the minimum number of cells which should be transformed from water to land.
In the next n lines print m symbols β the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, print any of them.
It is guaranteed that the answer exists on the given data.
Examples
Input
5 4 1
****
*..*
****
**.*
..**
Output
1
****
*..*
****
****
..**
Input
3 3 0
***
*.*
***
Output
1
***
***
***
Note
In the first example there are only two lakes β the first consists of the cells (2, 2) and (2, 3), the second consists of the cell (4, 3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with the ocean.
Submitted Solution:
```
from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect
#?############################################################
def isPrime(x):
for i in range(2, x):
if i*i > x:
break
if (x % i == 0):
return False
return True
#?############################################################
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den, p - 2, p)) % p
#?############################################################
def primeFactors(n):
l = []
while n % 2 == 0:
l.append(2)
n = n / 2
for i in range(3, int(math.sqrt(n))+1, 2):
while n % i == 0:
l.append(int(i))
n = n / i
if n > 2:
l.append(n)
return list(set(l))
#?############################################################
def power(x, y, p):
res = 1
x = x % p
if (x == 0):
return 0
while (y > 0):
if ((y & 1) == 1):
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
#?############################################################
def sieve(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return prime
#?############################################################
def digits(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
#?############################################################
def ceil(n, x):
if (n % x == 0):
return n//x
return n//x+1
#?############################################################
def mapin():
return map(int, input().split())
#?############################################################
visited = [[0 for i in range(51)] for j in range(51)]
adj = [[0 for i in range(51)] for j in range(51)]
n = 0
m = 0
final = []
def DFS(s):
# print(n, m)
stack = []
stack.append(s)
while (len(stack)):
s = stack[-1]
final[-1][-1].append(s)
final[-1][0]+=1
stack.pop()
if(s[0] == n-1 or s[1] == m-1 or s[0] == 0 or s[1] == 0):
final.pop(-1)
return
if (visited[s[0]][s[1]] == 0):
visited[s[0]][s[1]] = 1
sx = s[:]
sy = s[:]
tx = s[:]
ty = s[:]
sx[0]+=1
sy[1]+=1
tx[0]-=1
ty[1]-=1
# print(sx, sy, tx)
if(sx[0] <n and adj[sx[0]][sx[1]] == 1 and visited[sx[0]][sx[1]] == 0):
stack.append(sx)
if(sy[1] <m and adj[sy[0]][sy[1]] == 1 and visited[sy[0]][sy[1]] == 0):
stack.append(sy)
if(tx[0] >=0 and adj[tx[0]][tx[1]] == 1 and visited[tx[0]][tx[1]] == 0):
stack.append(tx)
if(ty[1] >=0 and adj[ty[0]][ty[1]] == 1 and visited[ty[0]][ty[1]] == 0):
stack.append(ty)
return
n, m, k = mapin()
d = []
for i in range(n):
l = list(input())
for j in range(m):
if(l[j] == '.'):
adj[i][j] = 1
for i in range(n):
for j in range(m):
if(adj[i][j] and visited[i][j] == 0):
final.append([0, []])
DFS([i, j])
# print(final, i, j)
final.sort()
ans = 0
for i in range(len(final)-k):
for j in final[i][1]:
ans+=1
adj[j[0]][j[1]] = 0
print(ans)
for i in range(n):
for j in range(m):
if(adj[i][j] == 0):
print('*', end = "")
else:
print('.', end = "")
print("")
``` | instruction | 0 | 52,691 | 23 | 105,382 |
No | output | 1 | 52,691 | 23 | 105,383 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The map of Berland is a rectangle of the size n Γ m, which consists of cells of size 1 Γ 1. Each cell is either land or water. The map is surrounded by the ocean.
Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that it's possible to get from any cell of the set to any other without leaving the set and moving only to cells adjacent by the side, none of them is located on the border of the rectangle, and it's impossible to add one more water cell to the set such that it will be connected with any other cell.
You task is to fill up with the earth the minimum number of water cells so that there will be exactly k lakes in Berland. Note that the initial number of lakes on the map is not less than k.
Input
The first line of the input contains three integers n, m and k (1 β€ n, m β€ 50, 0 β€ k β€ 50) β the sizes of the map and the number of lakes which should be left on the map.
The next n lines contain m characters each β the description of the map. Each of the characters is either '.' (it means that the corresponding cell is water) or '*' (it means that the corresponding cell is land).
It is guaranteed that the map contain at least k lakes.
Output
In the first line print the minimum number of cells which should be transformed from water to land.
In the next n lines print m symbols β the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, print any of them.
It is guaranteed that the answer exists on the given data.
Examples
Input
5 4 1
****
*..*
****
**.*
..**
Output
1
****
*..*
****
****
..**
Input
3 3 0
***
*.*
***
Output
1
***
***
***
Note
In the first example there are only two lakes β the first consists of the cells (2, 2) and (2, 3), the second consists of the cell (4, 3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with the ocean.
Submitted Solution:
```
from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect
#?############################################################
def isPrime(x):
for i in range(2, x):
if i*i > x:
break
if (x % i == 0):
return False
return True
#?############################################################
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den, p - 2, p)) % p
#?############################################################
def primeFactors(n):
l = []
while n % 2 == 0:
l.append(2)
n = n / 2
for i in range(3, int(math.sqrt(n))+1, 2):
while n % i == 0:
l.append(int(i))
n = n / i
if n > 2:
l.append(n)
return list(set(l))
#?############################################################
def power(x, y, p):
res = 1
x = x % p
if (x == 0):
return 0
while (y > 0):
if ((y & 1) == 1):
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
#?############################################################
def sieve(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return prime
#?############################################################
def digits(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
#?############################################################
def ceil(n, x):
if (n % x == 0):
return n//x
return n//x+1
#?############################################################
def mapin():
return map(int, input().split())
#?############################################################
visited = [[0 for i in range(101)] for j in range(101)]
adj = [[0 for i in range(101)] for j in range(101)]
n = 0
m = 0
final = []
def DFS(s):
# print(n, m)
fl = True
stack = []
temp = []
stack.append(s)
while (len(stack)):
s = stack[-1]
stack.pop()
if(s[0] == n-1 or s[1] == m-1 or s[0] == 0 or s[1] == 0):
fl = False
temp.append(s)
sx = s[:]
sy = s[:]
tx = s[:]
ty = s[:]
sx[0]+=1
sy[1]+=1
tx[0]-=1
ty[1]-=1
# print(sx, sy, tx)
if(sy[1] < m and adj[sy[0]][sy[1]] == 1 and visited[sy[0]][sy[1]] == 0):
visited[sy[0]][sy[1]] = 1
stack.append(sy)
if(ty[1] >=0 and adj[ty[0]][ty[1]] == 1 and visited[ty[0]][ty[1]] == 0):
visited[ty[0]][ty[1]] = 1
stack.append(ty)
if(sx[0] <n and adj[sx[0]][sx[1]] == 1 and visited[sx[0]][sx[1]] == 0):
visited[sx[0]][sx[1]] = 1
stack.append(sx)
if(tx[0] >=0 and adj[tx[0]][tx[1]] == 1 and visited[tx[0]][tx[1]] == 0):
visited[tx[0]][tx[1]] = 1
stack.append(tx)
if(fl):
final.append(temp)
n, m, k = mapin()
d = []
for i in range(n):
l = list(input())
for j in range(m):
if(l[j] == '.'):
adj[i][j] = 1
else:
adj[i][j] = 0
for i in range(n):
for j in range(m):
if(adj[i][j] == 1 and visited[i][j] == 0):
final.append([])
DFS([i, j])
final.sort(key = len)
ans = 0
for i in range(len(final)-k):
for j in final[i]:
ans+=1
adj[j[0]][j[1]] = 0
print(ans)
for i in range(n):
for j in range(m):
if(adj[i][j] == 0):
print('*', end = "")
else:
print('.', end = "")
print("")
``` | instruction | 0 | 52,692 | 23 | 105,384 |
No | output | 1 | 52,692 | 23 | 105,385 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The map of Berland is a rectangle of the size n Γ m, which consists of cells of size 1 Γ 1. Each cell is either land or water. The map is surrounded by the ocean.
Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that it's possible to get from any cell of the set to any other without leaving the set and moving only to cells adjacent by the side, none of them is located on the border of the rectangle, and it's impossible to add one more water cell to the set such that it will be connected with any other cell.
You task is to fill up with the earth the minimum number of water cells so that there will be exactly k lakes in Berland. Note that the initial number of lakes on the map is not less than k.
Input
The first line of the input contains three integers n, m and k (1 β€ n, m β€ 50, 0 β€ k β€ 50) β the sizes of the map and the number of lakes which should be left on the map.
The next n lines contain m characters each β the description of the map. Each of the characters is either '.' (it means that the corresponding cell is water) or '*' (it means that the corresponding cell is land).
It is guaranteed that the map contain at least k lakes.
Output
In the first line print the minimum number of cells which should be transformed from water to land.
In the next n lines print m symbols β the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, print any of them.
It is guaranteed that the answer exists on the given data.
Examples
Input
5 4 1
****
*..*
****
**.*
..**
Output
1
****
*..*
****
****
..**
Input
3 3 0
***
*.*
***
Output
1
***
***
***
Note
In the first example there are only two lakes β the first consists of the cells (2, 2) and (2, 3), the second consists of the cell (4, 3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with the ocean.
Submitted Solution:
```
import sys
import queue
sys.setrecursionlimit(100000)
# dirs = [
# [0,1] , [1,0], [-1,0] , [0,-1] , [1,-1] , [-1,1] , [1,1], [-1,-1]
# ]
# def dfs2(row,col,cur):
# if cur == 9:
# return True
# for dir in dirs:
# nrow = row + dir[0]
# ncol = col + dir[1]
# if inside(nrow,ncol) and not visited[nrow][ncol] and graph[nrow][ncol] == text[cur + 1]:
# # print(graph[nrow][ncol])
# visited[nrow][ncol] = True
# isOk = dfs(nrow,ncol,cur + 1)
# if isOk:
# return True
# visited[nrow][ncol] = False
# return False
def dfs(s):
visited[s] = True
for v in graph[s]:
if not visited[v]:
dfs(v)
n , m , k = map(int,input().split())
grid = [ [] for i in range(n)]
visited = [ [False] * m for i in range(n)]
directions = [ [0,1] , [1,0] , [-1,0] , [0,-1]]
for i in range(n):
a = list(str(input()))
grid[i].extend(a)
def inside(row,col):
if (0 <= row and row < n) and (0 <= col and col < m) :
return True
return False
def inBorder(row,col):
if row == 0 or row == n -1 or col == 0 or col == m - 1:
return True
return False
lakes = []
for row in range(n):
for col in range(m):
if not visited[row][col] and grid[row][col] == '.':
q = queue.Queue()
q.put([row,col])
size = 1
isSelected = True
tmp = []
while not q.empty():
p = q.get()
tmp.append((p[0],p[1]))
if inBorder(p[0],p[1]):
isSelected = False
break
for dir in directions:
new_row = p[0] + dir[0]
new_col = p[1] + dir[1]
if inside(new_row,new_col) and not visited[new_row][new_col] and grid[new_row][new_col] == '.':
q.put([new_row,new_col])
visited[new_row][new_col] = True
size += 1
if isSelected:
lakes.append(tmp)
res = 0
lakes.sort(key = lambda lake : len(lake))
for i in range(len(lakes)- k):
res += len(lakes[i])
for r,c in lakes[i]:
grid[r][c] = '*'
print(res)
for i in range(n):
print(''.join(grid[i]))
``` | instruction | 0 | 52,693 | 23 | 105,386 |
No | output | 1 | 52,693 | 23 | 105,387 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The map of Berland is a rectangle of the size n Γ m, which consists of cells of size 1 Γ 1. Each cell is either land or water. The map is surrounded by the ocean.
Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that it's possible to get from any cell of the set to any other without leaving the set and moving only to cells adjacent by the side, none of them is located on the border of the rectangle, and it's impossible to add one more water cell to the set such that it will be connected with any other cell.
You task is to fill up with the earth the minimum number of water cells so that there will be exactly k lakes in Berland. Note that the initial number of lakes on the map is not less than k.
Input
The first line of the input contains three integers n, m and k (1 β€ n, m β€ 50, 0 β€ k β€ 50) β the sizes of the map and the number of lakes which should be left on the map.
The next n lines contain m characters each β the description of the map. Each of the characters is either '.' (it means that the corresponding cell is water) or '*' (it means that the corresponding cell is land).
It is guaranteed that the map contain at least k lakes.
Output
In the first line print the minimum number of cells which should be transformed from water to land.
In the next n lines print m symbols β the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, print any of them.
It is guaranteed that the answer exists on the given data.
Examples
Input
5 4 1
****
*..*
****
**.*
..**
Output
1
****
*..*
****
****
..**
Input
3 3 0
***
*.*
***
Output
1
***
***
***
Note
In the first example there are only two lakes β the first consists of the cells (2, 2) and (2, 3), the second consists of the cell (4, 3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with the ocean.
Submitted Solution:
```
def is_border(cell,n,m):
if cell[0] == 0 or cell[0] == n-1 :
return True
if cell[1] == 0 or cell[1] == m-1:
return True
def solve():
n,m,k = map(int,input().split())
berland = [list(input().strip()) for _ in range(n)]
edges = {(i,j):list() for i in range(n + 2) for j in range(m + 2)}
visited = {(i,j):False for i in range(n + 2) for j in range(m + 2)}
offsets = [(-1,0),(0,1),(1,0),(0,-1)]
for i in range(n):
for j in range(m):
if berland[i][j] == '.':
for offset in offsets:
near_cell = (i+offset[0],j+offset[1])
if near_cell[0] < 0 or near_cell[0] >= n or near_cell[1] < 0 or near_cell[1] >= m or berland[near_cell[0]][near_cell[1]] == '*':
continue
edges[(i,j)].append(near_cell)
lakes = list()
for i in range(n):
for j in range(m):
if berland[i][j] =='.' and not visited[(i,j)]:
lake = [(i,j)]
stack = list()
stack.append((i,j))
is_lake = True
while stack:
cur_cell = stack.pop()
visited[cur_cell] = True
if is_border(near_cell,n,m):
is_lake = False
for near_cell in edges[cur_cell]:
if is_border(near_cell,n,m):
is_lake = False
if not visited[near_cell]:
stack.append(near_cell)
lake.append(near_cell)
if is_lake:
lakes.append((lake,len(lake)))
lakes = sorted(lakes,key = lambda lake: -lake[1])
transform_cells = 0
while len(lakes) > k :
lake = lakes.pop()
for cell in lake[0]:
berland[cell[0]][cell[1]] = '*'
transform_cells += lake[1]
print(transform_cells)
for i in range(n):
for j in range(m):
print(berland[i][j],end = '')
print()
solve()
``` | instruction | 0 | 52,694 | 23 | 105,388 |
No | output | 1 | 52,694 | 23 | 105,389 |
Provide a correct Python 3 solution for this coding contest problem.
Given is an integer S. Find a combination of six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfies all of the following conditions:
* 0 \leq X_1,Y_1,X_2,Y_2,X_3,Y_3 \leq 10^9
* The area of the triangle in a two-dimensional plane whose vertices are (X_1,Y_1),(X_2,Y_2), and (X_3,Y_3) is S/2.
We can prove that there always exist six integers that satisfy the conditions under the constraints of this problem.
Constraints
* 1 \leq S \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
S
Output
Print six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfy the conditions, in this order, with spaces in between. If multiple solutions exist, any of them will be accepted.
Examples
Input
3
Output
1 0 2 2 0 1
Input
100
Output
0 0 10 0 0 10
Input
311114770564041497
Output
314159265 358979323 846264338 327950288 419716939 937510582 | instruction | 0 | 52,860 | 23 | 105,720 |
"Correct Solution:
```
s = int(input())
x = (s-1)//(10**9)+1
print(0,0,10**9,1,x*(10**9)-s,x)
``` | output | 1 | 52,860 | 23 | 105,721 |
Provide a correct Python 3 solution for this coding contest problem.
Given is an integer S. Find a combination of six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfies all of the following conditions:
* 0 \leq X_1,Y_1,X_2,Y_2,X_3,Y_3 \leq 10^9
* The area of the triangle in a two-dimensional plane whose vertices are (X_1,Y_1),(X_2,Y_2), and (X_3,Y_3) is S/2.
We can prove that there always exist six integers that satisfy the conditions under the constraints of this problem.
Constraints
* 1 \leq S \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
S
Output
Print six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfy the conditions, in this order, with spaces in between. If multiple solutions exist, any of them will be accepted.
Examples
Input
3
Output
1 0 2 2 0 1
Input
100
Output
0 0 10 0 0 10
Input
311114770564041497
Output
314159265 358979323 846264338 327950288 419716939 937510582 | instruction | 0 | 52,862 | 23 | 105,724 |
"Correct Solution:
```
s = int(input())
x3 = (10**9-s%10**9)%10**9
y3 = (s+x3)//10**9
print(0, 0, 10**9, 1, x3, y3)
``` | output | 1 | 52,862 | 23 | 105,725 |
Provide a correct Python 3 solution for this coding contest problem.
Given is an integer S. Find a combination of six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfies all of the following conditions:
* 0 \leq X_1,Y_1,X_2,Y_2,X_3,Y_3 \leq 10^9
* The area of the triangle in a two-dimensional plane whose vertices are (X_1,Y_1),(X_2,Y_2), and (X_3,Y_3) is S/2.
We can prove that there always exist six integers that satisfy the conditions under the constraints of this problem.
Constraints
* 1 \leq S \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
S
Output
Print six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfy the conditions, in this order, with spaces in between. If multiple solutions exist, any of them will be accepted.
Examples
Input
3
Output
1 0 2 2 0 1
Input
100
Output
0 0 10 0 0 10
Input
311114770564041497
Output
314159265 358979323 846264338 327950288 419716939 937510582 | instruction | 0 | 52,863 | 23 | 105,726 |
"Correct Solution:
```
S=int(input())
a,b=10**9,1
d=(S+a-1)//a
c=a*d-S
print(0,0,a,b,c,d)
``` | output | 1 | 52,863 | 23 | 105,727 |
Provide a correct Python 3 solution for this coding contest problem.
Given is an integer S. Find a combination of six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfies all of the following conditions:
* 0 \leq X_1,Y_1,X_2,Y_2,X_3,Y_3 \leq 10^9
* The area of the triangle in a two-dimensional plane whose vertices are (X_1,Y_1),(X_2,Y_2), and (X_3,Y_3) is S/2.
We can prove that there always exist six integers that satisfy the conditions under the constraints of this problem.
Constraints
* 1 \leq S \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
S
Output
Print six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfy the conditions, in this order, with spaces in between. If multiple solutions exist, any of them will be accepted.
Examples
Input
3
Output
1 0 2 2 0 1
Input
100
Output
0 0 10 0 0 10
Input
311114770564041497
Output
314159265 358979323 846264338 327950288 419716939 937510582 | instruction | 0 | 52,864 | 23 | 105,728 |
"Correct Solution:
```
s = int(input())
print(0,0,10**9,1,10**9-(s-1)%(10**9)-1,(s-1)//(10**9)+1)
``` | output | 1 | 52,864 | 23 | 105,729 |
Provide a correct Python 3 solution for this coding contest problem.
Given is an integer S. Find a combination of six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfies all of the following conditions:
* 0 \leq X_1,Y_1,X_2,Y_2,X_3,Y_3 \leq 10^9
* The area of the triangle in a two-dimensional plane whose vertices are (X_1,Y_1),(X_2,Y_2), and (X_3,Y_3) is S/2.
We can prove that there always exist six integers that satisfy the conditions under the constraints of this problem.
Constraints
* 1 \leq S \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
S
Output
Print six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfy the conditions, in this order, with spaces in between. If multiple solutions exist, any of them will be accepted.
Examples
Input
3
Output
1 0 2 2 0 1
Input
100
Output
0 0 10 0 0 10
Input
311114770564041497
Output
314159265 358979323 846264338 327950288 419716939 937510582 | instruction | 0 | 52,865 | 23 | 105,730 |
"Correct Solution:
```
S=int(input())
a=S%(10**9)
b=(10**9-a)%(10**9)
print(0,0,1,10**9,(S+b)//(10**9),b)
``` | output | 1 | 52,865 | 23 | 105,731 |
Provide a correct Python 3 solution for this coding contest problem.
Given is an integer S. Find a combination of six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfies all of the following conditions:
* 0 \leq X_1,Y_1,X_2,Y_2,X_3,Y_3 \leq 10^9
* The area of the triangle in a two-dimensional plane whose vertices are (X_1,Y_1),(X_2,Y_2), and (X_3,Y_3) is S/2.
We can prove that there always exist six integers that satisfy the conditions under the constraints of this problem.
Constraints
* 1 \leq S \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
S
Output
Print six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfy the conditions, in this order, with spaces in between. If multiple solutions exist, any of them will be accepted.
Examples
Input
3
Output
1 0 2 2 0 1
Input
100
Output
0 0 10 0 0 10
Input
311114770564041497
Output
314159265 358979323 846264338 327950288 419716939 937510582 | instruction | 0 | 52,866 | 23 | 105,732 |
"Correct Solution:
```
#!/usr/bin/env python3
s = int(input())
print(10**9, 1*(s<10**18), 10**9 - s%10**9, s // 10**9 + 1*(s<10**18),0,0)
``` | output | 1 | 52,866 | 23 | 105,733 |
Provide a correct Python 3 solution for this coding contest problem.
Given is an integer S. Find a combination of six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfies all of the following conditions:
* 0 \leq X_1,Y_1,X_2,Y_2,X_3,Y_3 \leq 10^9
* The area of the triangle in a two-dimensional plane whose vertices are (X_1,Y_1),(X_2,Y_2), and (X_3,Y_3) is S/2.
We can prove that there always exist six integers that satisfy the conditions under the constraints of this problem.
Constraints
* 1 \leq S \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
S
Output
Print six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfy the conditions, in this order, with spaces in between. If multiple solutions exist, any of them will be accepted.
Examples
Input
3
Output
1 0 2 2 0 1
Input
100
Output
0 0 10 0 0 10
Input
311114770564041497
Output
314159265 358979323 846264338 327950288 419716939 937510582 | instruction | 0 | 52,867 | 23 | 105,734 |
"Correct Solution:
```
s,v=int(input()),10**9;y=-s%v;print(0,0,v,1,y,(s+y)//v)
``` | output | 1 | 52,867 | 23 | 105,735 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2). | instruction | 0 | 53,085 | 23 | 106,170 |
Tags: brute force, dp, fft, greedy, ternary search
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
curr=0
two=0
tri=0
while curr<n:
tri+=a[curr]//3
a[curr]%=3
while two<n-1 and (a[two]<2 or two<=curr):
two+=1
if a[curr]==1:
if a[two]>=2 and two>curr:
a[curr]-=1
a[two]-=2
tri+=1
elif a[curr]==2:
if a[two]>=2 and two>curr:
a[curr]-=1
a[two]-=2
tri+=1
while two<n-1 and (a[two]<2 or two<=curr):
two+=1
if a[two]>=2 and two>curr:
a[curr]-=1
a[two]-=2
tri+=1
curr+=1
print(tri)
``` | output | 1 | 53,085 | 23 | 106,171 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2). | instruction | 0 | 53,086 | 23 | 106,172 |
Tags: brute force, dp, fft, greedy, ternary search
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
one = 0
ans = 0
for i in range(n):
for j in range(one,i+1):
if i == j:
ans += a[i]//3
a[i] %=3
break
if a[i] <= 1:
break
if a[j] <=a[i]//2:
ans += a[j]
a[i] -= a[j]*2
a[j] = 0
one = j
else:
ans += a[i]//2
a[j]-=a[i]//2
a[i] %=2
print(ans)
``` | output | 1 | 53,086 | 23 | 106,173 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2). | instruction | 0 | 53,087 | 23 | 106,174 |
Tags: brute force, dp, fft, greedy, ternary search
Correct Solution:
```
from collections import defaultdict as dd
import math
def nn():
return int(input())
def li():
return list(input())
def mi():
return map(int, input().split())
def lm():
return list(map(int, input().split()))
n=nn()
tris=lm()
answer=0
extra=0
for i in range(n):
answer+=tris[i]//3
extra+=tris[i]%3
if i <n-1:
while extra>=1 and tris[i+1]>=2:
answer+=1
extra-=1
tris[i+1]-=2
print(answer)
``` | output | 1 | 53,087 | 23 | 106,175 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2). | instruction | 0 | 53,088 | 23 | 106,176 |
Tags: brute force, dp, fft, greedy, ternary search
Correct Solution:
```
n = int(input())
l = [0] + list(map(int, input().split()))
cnt = 0
trash = 0
for i in range(1, n + 1):
if not trash:
cnt += l[i] // 3
trash += l[i] % 3
else:
trash += l[i] % 2
l[i] -= l[i] % 2
use = min(l[i], trash * 2)
cnt += use // 2
trash -= use // 2
l[i] -= use
cnt += l[i] // 3
trash += l[i] % 3
print(cnt)
``` | output | 1 | 53,088 | 23 | 106,177 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2). | instruction | 0 | 53,089 | 23 | 106,178 |
Tags: brute force, dp, fft, greedy, ternary search
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
c = 0
ans = 0
for x in a:
d = x // 2
add = min(d, c)
c -= add
ans += add
x -= add * 2
ans += x // 3
c += x % 3
print(ans)
``` | output | 1 | 53,089 | 23 | 106,179 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2). | instruction | 0 | 53,090 | 23 | 106,180 |
Tags: brute force, dp, fft, greedy, ternary search
Correct Solution:
```
n = int(input())
d = [int(x) for x in input().split()]
c = 0
ans = 0
x = 0
for i in range(n):
f = d[i] // 2
s = min(f, x)
ans += s
x -= s
d[i] -= s * 2
ans += d[i] // 3
x += d[i] % 3
print(ans)
``` | output | 1 | 53,090 | 23 | 106,181 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2). | instruction | 0 | 53,091 | 23 | 106,182 |
Tags: brute force, dp, fft, greedy, ternary search
Correct Solution:
```
N = int(input())
nums = [int(i) for i in input().split(' ')]
from collections import defaultdict
def helper(nums):
tot, carry = 0, 0
for i in range(len(nums)):
v = min(nums[i]//2, carry)
tot += v
carry -= v
nums[i] -= 2 * v
tot += nums[i] // 3
nums[i] %= 3
carry += nums[i]
print(tot)
helper(nums)
``` | output | 1 | 53,091 | 23 | 106,183 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2). | instruction | 0 | 53,092 | 23 | 106,184 |
Tags: brute force, dp, fft, greedy, ternary search
Correct Solution:
```
x = int(input())
a = [int(i) for i in input().split()]
a.append(0)
ans = 0
sum12 = {1:0, 2:0}
for i in range(x+1):
for j in range(1, 2):
if i>1 and sum12[j] != 0:
t = a[i] // (3-j)
t = min(sum12[j], t)
a[i] -= t * (3-j)
ans += t
sum12[j] -= t
ans += a[i] // 3
a[i] %= 3
if a[i]!=0:
sum12[1] += a[i]
print(ans)
``` | output | 1 | 53,092 | 23 | 106,185 |
Provide tags and a correct Python 2 solution for this coding contest problem.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2). | instruction | 0 | 53,093 | 23 | 106,186 |
Tags: brute force, dp, fft, greedy, ternary search
Correct Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write
def in_num():
return int(raw_input())
def in_arr():
return map(int,raw_input().split())
def pr_num(n):
stdout.write(str(n)+'\n')
def pr_arr(arr):
pr(' '.join(map(str,arr))+'\n')
# fast read function for total integer input
def inp():
# this function returns whole input of
# space/line seperated integers
# Use Ctrl+D to flush stdin.
return map(int,stdin.read().split())
range = xrange # not for python 3.0+
# main code
n=in_num()
l=in_arr()
ans=0
rem=0
for i in range(n):
while rem and l[i]>=2:
l[i]-=2
rem-=1
ans+=1
ans+=(l[i]/3)
rem+=(l[i]%3)
pr_num(ans)
``` | output | 1 | 53,093 | 23 | 106,187 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2).
Submitted Solution:
```
import sys,os,io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import defaultdict
n = int(input())
a = [int(i) for i in input().split()]
pairs = 0
singles = 0
ans = 0
for i in a:
new = min(i//2, singles)
ans += new
i -= 2*new
singles -= new
ans += i//3
singles += i%3
print(ans)
``` | instruction | 0 | 53,094 | 23 | 106,188 |
Yes | output | 1 | 53,094 | 23 | 106,189 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2).
Submitted Solution:
```
n=int(input())
length=[int(g) for g in input().split()]
counter=0
answer=0
for i in range(n-1,-1,-1):
counter+=length[i]//2
if length[i]%2==1 and counter>0:
answer+=1
counter-=1
answer+=(counter*2)//3
print(answer)
``` | instruction | 0 | 53,095 | 23 | 106,190 |
Yes | output | 1 | 53,095 | 23 | 106,191 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2).
Submitted Solution:
```
n = int(input())
l = list(map(int, input().split()))
ost = 0
res = 0
for x in l:
ost += x % 2
x //= 2
if x < ost:
res += x
ost -= x
else:
res += ost + (((x - ost) * 2) // 3)
ost = (2*(x - ost))%3
print(res)
``` | instruction | 0 | 53,096 | 23 | 106,192 |
Yes | output | 1 | 53,096 | 23 | 106,193 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2).
Submitted Solution:
```
import sys; input=sys.stdin.readline
from heapq import *
n = int(input())
a = list(map(int, input().split()))
h = []
triangles = 0
remainder = 0
for x in a[::-1]:
if x == 3:
triangles += 1
elif x == 1:
try:
y = -heappop(h)
triangles += 1
remainder -= 2
y -= 2
if y > 1 and y != 3:
heappush(h, -y)
except:
pass
else:
heappush(h, -x)
remainder += x
# print(triangles, remainder)
print(triangles + remainder//3)
``` | instruction | 0 | 53,097 | 23 | 106,194 |
Yes | output | 1 | 53,097 | 23 | 106,195 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2).
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
a.reverse()
s=0
ost=[]
for i in range(n):
if a[i]%3!=0:
ost.append([a[i]%3,i])
for i in range(n):
if a[i]%3!=0:
if (a[i]-2)%3==0 and a[i]>=2:
if ost[-1][1]<=i:
break
a[i]-=2
ost[-1][0]-=1
s+=1
if ost[-1][0]==0:
del ost[-1]
elif (a[i]-4)%3==0 and a[i]>=4:
for ii in range(2):
if ost[-1][1]<=i:
break
a[i]-=2
ost[-1][0]-=1
s+=1
if ost[-1][0]==0:
del ost[-1]
for i in range(len(a)):
s+=a[i]//3
print(s)
``` | instruction | 0 | 53,098 | 23 | 106,196 |
No | output | 1 | 53,098 | 23 | 106,197 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2).
Submitted Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now-----------------------------------------------------
n=int(input())
a=list(map(int,input().split()))
count=a[0]//3
prev=a[0]%3
for i in range (1,n):
if prev>0 and prev+a[i]<3:
prev=a[i]
continue
prev+=a[i]
count+=prev//3
prev%=3
#print(count)
c1=a[-1]//3
prev=a[-1]%3
for i in range (n-2,-1,-1):
if prev>0 and prev+a[i]<3:
prev=a[i]
continue
prev+=a[i]
c1+=prev//3
prev%=3
count=max(count,c1)
print(count)
``` | instruction | 0 | 53,099 | 23 | 106,198 |
No | output | 1 | 53,099 | 23 | 106,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2).
Submitted Solution:
```
def mp():
return map(int, input().split())
n = int(input())
a = list(mp())
ans = 0
'''
for i in range(n):
ans += a[i] // 3
a[i] %= 3
'''
#print(ans, a)
i = 0
j = n - 1
while j > i:
if a[j] == 0:
j -= 1
if a[i] == 0:
i += 1
if a[j] >= 2 and a[i] >= 1:
x = a[i]
y = a[j]
if i == j:
y = 0
c = x // 3 + y // 3
t = min(a[j] // 2, a[i])
if c > t:
ans += a[i] // 3
a[i] %= 3
ans += a[j] // 3
a[j] %= 3
else:
k = min(a[j] // 2, a[i])
ans += k
a[j] -= 2 * k
a[i] -= k
else:
if a[j] == 1:
j -= 1
else:
i += 1
#print(a)
print(ans)
``` | instruction | 0 | 53,100 | 23 | 106,200 |
No | output | 1 | 53,100 | 23 | 106,201 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.
It is forbidden to break sticks, and each triangle should consist of exactly three sticks.
Find the maximum possible number of triangles.
Input
The first line contains a single integer n (1 β€ n β€ 300 000) β the number of different lengths of sticks.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_i β€ 10^9), where a_i is the number of sticks with the length equal to 2^i.
Output
Print a single integer β the maximum possible number of non-degenerate triangles that Pavel can make.
Examples
Input
5
1 2 2 2 2
Output
3
Input
3
1 1 1
Output
0
Input
3
3 3 3
Output
3
Note
In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^4, 2^4), (2^1, 2^3, 2^3), (2^1, 2^2, 2^2).
In the second example, Pavel cannot make a single triangle.
In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): (2^0, 2^0, 2^0), (2^1, 2^1, 2^1), (2^2, 2^2, 2^2).
Submitted Solution:
```
from collections import defaultdict as dd
import math
def nn():
return int(input())
def li():
return list(input())
def mi():
return map(int, input().split())
def lm():
return list(map(int, input().split()))
n=nn()
tris=lm()
answer=0
for i in range(n):
answer+=tris[i]//3
extra=tris[i]%3
if i <n-1:
if extra==1 and tris[i+1]>=2:
answer+=1
tris[i+1]-=2
print(answer)
``` | instruction | 0 | 53,101 | 23 | 106,202 |
No | output | 1 | 53,101 | 23 | 106,203 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen.
A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c.
The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of (vx, vy) vector.
Enumerate the arrow points coordinates in counter-clockwise order starting from the tip.
<image>
Input
The only line of the input contains eight integers px, py, vx, vy ( - 1000 β€ px, py, vx, vy β€ 1000, vx2 + vy2 > 0), a, b, c, d (1 β€ a, b, c, d β€ 1000, a > c).
Output
Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9.
Examples
Input
8 8 0 2 8 3 4 5
Output
8.000000000000 11.000000000000
4.000000000000 8.000000000000
6.000000000000 8.000000000000
6.000000000000 3.000000000000
10.000000000000 3.000000000000
10.000000000000 8.000000000000
12.000000000000 8.000000000000 | instruction | 0 | 53,495 | 23 | 106,990 |
Tags: geometry
Correct Solution:
```
import math
ln = input().split(" ")
px = int(ln[0])
py = int(ln[1])
vx = int(ln[2])
vy = int(ln[3])
a = int(ln[4])
b = int(ln[5])
c = int(ln[6])
d = int(ln[7])
x_dir = vx / math.sqrt(vx ** 2 + vy ** 2)
y_dir = vy / math.sqrt(vx ** 2 + vy ** 2)
print(px + b * x_dir, py + b * y_dir)
print(px - a / 2 * y_dir, py + a / 2 * x_dir)
print(px - c / 2 * y_dir, py + c / 2 * x_dir)
print(px - c / 2 * y_dir - d * x_dir, py + c / 2 * x_dir - d * y_dir)
print(px + c / 2 * y_dir - d * x_dir, py - c / 2 * x_dir - d * y_dir)
print(px + c / 2 * y_dir, py - c / 2 * x_dir)
print(px + a / 2 * y_dir, py - a / 2 * x_dir)
``` | output | 1 | 53,495 | 23 | 106,991 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen.
A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c.
The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of (vx, vy) vector.
Enumerate the arrow points coordinates in counter-clockwise order starting from the tip.
<image>
Input
The only line of the input contains eight integers px, py, vx, vy ( - 1000 β€ px, py, vx, vy β€ 1000, vx2 + vy2 > 0), a, b, c, d (1 β€ a, b, c, d β€ 1000, a > c).
Output
Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9.
Examples
Input
8 8 0 2 8 3 4 5
Output
8.000000000000 11.000000000000
4.000000000000 8.000000000000
6.000000000000 8.000000000000
6.000000000000 3.000000000000
10.000000000000 3.000000000000
10.000000000000 8.000000000000
12.000000000000 8.000000000000 | instruction | 0 | 53,496 | 23 | 106,992 |
Tags: geometry
Correct Solution:
```
import math
def main():
px, py, vx, vy, a, b, c, d = map(int, input().split())
vectorx = vx / math.sqrt(math.pow(vx, 2) + math.pow(vy, 2))
vectory = vy / math.sqrt(math.pow(vx, 2) + math.pow(vy, 2))
print(px + (b * vectorx), py + (b * vectory))
print(px - ((a / 2) * vectory), py + ((a / 2) * vectorx))
print(px - ((c / 2) * vectory), py + ((c / 2) * vectorx))
print(px - ((c / 2) * vectory) - (d * vectorx), py + ((c / 2) * vectorx) - (d * vectory))
print(px + ((c / 2) * vectory) - (d * vectorx), py - ((c / 2) * vectorx) - (d * vectory))
print(px + ((c / 2) * vectory), py - ((c / 2) * vectorx))
print(px + ((a / 2) * vectory), py - ((a / 2) * vectorx))
if __name__ == '__main__':
main()
``` | output | 1 | 53,496 | 23 | 106,993 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen.
A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c.
The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of (vx, vy) vector.
Enumerate the arrow points coordinates in counter-clockwise order starting from the tip.
<image>
Input
The only line of the input contains eight integers px, py, vx, vy ( - 1000 β€ px, py, vx, vy β€ 1000, vx2 + vy2 > 0), a, b, c, d (1 β€ a, b, c, d β€ 1000, a > c).
Output
Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9.
Examples
Input
8 8 0 2 8 3 4 5
Output
8.000000000000 11.000000000000
4.000000000000 8.000000000000
6.000000000000 8.000000000000
6.000000000000 3.000000000000
10.000000000000 3.000000000000
10.000000000000 8.000000000000
12.000000000000 8.000000000000 | instruction | 0 | 53,497 | 23 | 106,994 |
Tags: geometry
Correct Solution:
```
import math
def main():
x, y, vx, vy, a, b, c, d = map(int, input().split())
len = math.sqrt(vx * vx + vy * vy)
vx /= len
vy /= len
print(x + vx * b, y + vy * b)
print(x - vy * a / 2, y + vx * a / 2)
print(x - vy * c / 2, y + vx * c / 2)
print(x - vy * c / 2 - vx * d, y + vx * c / 2 - vy * d)
print(x + vy * c / 2 - vx * d, y - vx * c / 2 - vy * d)
print(2 * x - (x - vy * c / 2), 2 * y - (y + vx * c / 2))
print(2 * x - (x - vy * a / 2), 2 * y - (y + vx * a / 2))
main()
``` | output | 1 | 53,497 | 23 | 106,995 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen.
A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c.
The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of (vx, vy) vector.
Enumerate the arrow points coordinates in counter-clockwise order starting from the tip.
<image>
Input
The only line of the input contains eight integers px, py, vx, vy ( - 1000 β€ px, py, vx, vy β€ 1000, vx2 + vy2 > 0), a, b, c, d (1 β€ a, b, c, d β€ 1000, a > c).
Output
Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9.
Examples
Input
8 8 0 2 8 3 4 5
Output
8.000000000000 11.000000000000
4.000000000000 8.000000000000
6.000000000000 8.000000000000
6.000000000000 3.000000000000
10.000000000000 3.000000000000
10.000000000000 8.000000000000
12.000000000000 8.000000000000 | instruction | 0 | 53,498 | 23 | 106,996 |
Tags: geometry
Correct Solution:
```
from math import atan2, pi
EPS = 0.00000001
def eq(a, b):
return abs(a - b) < EPS
class Vector:
def __init__(self, x2, y2, x1=0, y1=0):
self.x = (x2 - x1)
self.y = y2 - y1
self.s = (self.x ** 2 + self.y ** 2) ** 0.5
def __add__(self, other):
return Vector(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Vector(self.x - other.x, self.y - other.y)
def mul_k(self, k):
self.x *= k
self.y *= k
def mul_kk(self, k):
return Vector(self.x * k, self.y * k)
def rotate(self):
return Vector(-self.y, self.x)
def rotate2(self):
return self.rotate().rotate().rotate()
def reverseee(self):
return Vector(-self.x, -self.y)
def __mul__(self, other):
return self.x * other.x + self.y * other.y
def vectormul(self, other):
return self.x * other.y - self.y * other.x
def get_angle(self, other):
return atan2(self.vectormul(other), self * other)
def norm(self):
if self.s == 0:
return Vector(self.x, self.y)
return Vector(self.x / self.s, self.y / self.s)
def __str__(self):
return f'{self.x} {self.y}'
def middle(self, point):
return Vector((self.x + point.x) / 2, (self.y + point.y) / 2)
class Line:
def __init__(self, point=None, vector=None, point2=None, a=None, b=None, c=None):
if a is not None:
self.v = Vector(a, b).rotate()
self.p = Vector(a, b)
self.p.mul_k(-c / (a ** 2 + b ** 2))
self.A = a
self.B = b
self.C = c
return
if vector is None:
vector = point2 - point
self.p = point
self.v = vector
self.A = self.v.y
self.B = -self.v.x
self.C = - self.A * self.p.x - self.p.y * self.B
def get_abc(self):
return self.A, self.B, self.C
def __str__(self):
return str(self.A) + ' ' + str(self.B) + ' ' + str(self.C)
def check(self, point):
return eq(- point.x * self.A - self.B * point.y, self.C)
def get_s_from_point(self, point):
v = self.v.norm()
v2 = point - self.p
a = v * v2
v.mul_k(a)
v3 = v + self.p
s = v3 - point
return s.s
def get_bisect(self, line):
return Line(point=self.get_peresech(line)[1], vector=self.v.norm() + line.v.norm())
def get_proection(self, point):
v = self.v.norm()
v2 = point - self.p
a = v * v2
v.mul_k(a)
v3 = v + self.p
return v3
def get_paral_line(self, le):
v = self.v.norm().rotate()
v.mul_k(le)
return Line(point=self.p + v, vector=self.v)
def get_peresech(self, lin):
u = lin.v.rotate()
a = self.v * u
if eq(a, 0):
if eq(self.get_s_from_point(lin.p), 0):
return (2,)
return (0,)
t = ((lin.p - self.p) * u) / (self.v * u)
v = Vector(self.v.x, self.v.y)
v.mul_k(t)
return (1, self.p + v)
def get_mirror(self, point):
v = self.v.norm()
v2 = point - self.p
a = v * v2
v.mul_k(a)
v3 = v + self.p
s = v3 - point
return s + v3
def is_on_line(v1, v2):
return eq(v1.vectormul(v2), 0)
def is_on_luch(v1, v2):
return eq(v1.get_angle(v2), 0)
def is_on_otr(v1, v2, v3, v4):
return eq(v1.get_angle(v2), 0) and eq(v3.get_angle(v4), 0)
def get_s_from_luch(xp, yp, x1, y1, x2, y2):
v = Vector(x2, y2, x1, y1).norm()
v2 = Vector(xp, yp, x1, y1)
a = v * v2
v1 = Vector(x2, y2, x1, y1)
v.mul_k(a)
v3 = v + Vector(x1, y1)
xh, yh = v3.x, v3.y
v4 = Vector(xh, yh, x1, y1)
b = v1.get_angle(v4)
if eq(b, 0):
se = v3 - Vector(xp, yp)
return se.s
else:
return (Vector(x1, y1) - Vector(xp, yp)).s
def get_s_from_otr(xp, yp, x1, y1, x2, y2):
return max(get_s_from_luch(xp, yp, x1, y1, x2, y2), get_s_from_luch(xp, yp, x2, y2, x1, y1))
def get_s_from_line(xp, yp, x1, y1, x2, y2):
v = Vector(x2, y2, x1, y1).norm()
v2 = Vector(xp, yp, x1, y1)
a = v * v2
return a
def peresec_otr(x1, y1, x2, y2, x3, y3, x4, y4):
AB = Vector(x2, y2, x1, y1)
CD = Vector(x4, y4, x3, y3)
AC = Vector(x3, y3, x1, y1)
AD = Vector(x4, y4, x1, y1)
CA = Vector(x1, y1, x3, y3)
CB = Vector(x2, y2, x3, y3)
yg1 = AB.get_angle(AD)
yg2 = AB.get_angle(AC)
yg3 = CD.get_angle(CA)
yg4 = CD.get_angle(CB)
flag = False
if (yg1 < 0 and yg2 < 0) or (yg1 > 0 and yg2 > 0):
flag = True
if (yg3 < 0 and yg4 < 0) or (yg3 > 0 and yg4 > 0):
flag = True
if max(min(x1, x2), min(x3, x4)) > min(max(x1, x2), max(x3, x4)):
flag = True
if max(min(y1, y2), min(y3, y4)) > min(max(y1, y2), max(y3, y4)):
flag = True
return not flag
def get_s_from_otr_to_otr(x1, y1, x2, y2, x3, y3, x4, y4):
if peresec_otr(x1, y1, x2, y2, x3, y3, x4, y4):
return 0
return min(get_s_from_otr(x1, y1, x3, y3, x4, y4), get_s_from_otr(x2, y2, x3, y3, x4, y4),
get_s_from_otr(x3, y3, x1, y1, x2, y2), get_s_from_otr(x4, y4, x1, y1, x2, y2))
def main():
px, py, vx, vy, a, b, c, d = map(int, input().split())
P = Vector(px, py)
V = Vector(vx, vy).norm()
A = V.mul_kk(b) + P
B = V.mul_kk(a/2).rotate() + P
C = V.mul_kk(c/2).rotate() + P
D = C + V.rotate().rotate().mul_kk(d)
E = D + V.rotate2().mul_kk(c)
F = P + V.rotate2().mul_kk(c/2)
G = P + V.rotate2().mul_kk(a/2)
print(A, B, C, D, E, F, G, sep='\n')
main()
``` | output | 1 | 53,498 | 23 | 106,997 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen.
A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c.
The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of (vx, vy) vector.
Enumerate the arrow points coordinates in counter-clockwise order starting from the tip.
<image>
Input
The only line of the input contains eight integers px, py, vx, vy ( - 1000 β€ px, py, vx, vy β€ 1000, vx2 + vy2 > 0), a, b, c, d (1 β€ a, b, c, d β€ 1000, a > c).
Output
Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9.
Examples
Input
8 8 0 2 8 3 4 5
Output
8.000000000000 11.000000000000
4.000000000000 8.000000000000
6.000000000000 8.000000000000
6.000000000000 3.000000000000
10.000000000000 3.000000000000
10.000000000000 8.000000000000
12.000000000000 8.000000000000 | instruction | 0 | 53,499 | 23 | 106,998 |
Tags: geometry
Correct Solution:
```
# [https://codeforces.com/contest/630/submission/16304936]
import math
(px, py, vx, vy, a, b, c, d) = map(int, input().split(' '))
l = math.sqrt(vx*vx+vy*vy)
print(px+b/l*vx, py+b/l*vy)
print(px-a/2/l*vy, py+a/2/l*vx)
print(px-c/2/l*vy, py+c/2/l*vx)
print(px-c/2/l*vy-d/l*vx, py+c/2/l*vx-d/l*vy)
print(px+c/2/l*vy-d/l*vx, py-c/2/l*vx-d/l*vy)
print(px+c/2/l*vy, py-c/2/l*vx)
print(px+a/2/l*vy, py-a/2/l*vx)
``` | output | 1 | 53,499 | 23 | 106,999 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen.
A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c.
The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of (vx, vy) vector.
Enumerate the arrow points coordinates in counter-clockwise order starting from the tip.
<image>
Input
The only line of the input contains eight integers px, py, vx, vy ( - 1000 β€ px, py, vx, vy β€ 1000, vx2 + vy2 > 0), a, b, c, d (1 β€ a, b, c, d β€ 1000, a > c).
Output
Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9.
Examples
Input
8 8 0 2 8 3 4 5
Output
8.000000000000 11.000000000000
4.000000000000 8.000000000000
6.000000000000 8.000000000000
6.000000000000 3.000000000000
10.000000000000 3.000000000000
10.000000000000 8.000000000000
12.000000000000 8.000000000000 | instruction | 0 | 53,500 | 23 | 107,000 |
Tags: geometry
Correct Solution:
```
from decimal import *
from math import sqrt
getcontext().prec = 100
px , py , vx , vy , a , b , c , d = map (Decimal, input().split())
absv = Decimal(sqrt(vx**2 + vy**2))
n0x = vx / absv
n0y = vy / absv
n1x , n1y = n0y , -n0x
n2x , n2y = -n0x , -n0y
n3x , n3y = -n0y , n0x
print(px + b * n0x, py + b * n0y)
print(px + a * n3x / 2, py + a * n3y / 2)
p2x = px + n3x * (c / 2)
p2y = py + n3y * (c / 2)
print(p2x, p2y)
print(p2x + n2x * d, p2y + n2y * d)
p3x = px + n1x * (c / 2)
p3y = py + n1y * (c / 2)
print(p3x + n2x * d, p3y + n2y * d)
print(p3x, p3y)
print(px + a * n1x / 2, py + a * n1y / 2)
``` | output | 1 | 53,500 | 23 | 107,001 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen.
A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c.
The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of (vx, vy) vector.
Enumerate the arrow points coordinates in counter-clockwise order starting from the tip.
<image>
Input
The only line of the input contains eight integers px, py, vx, vy ( - 1000 β€ px, py, vx, vy β€ 1000, vx2 + vy2 > 0), a, b, c, d (1 β€ a, b, c, d β€ 1000, a > c).
Output
Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9.
Examples
Input
8 8 0 2 8 3 4 5
Output
8.000000000000 11.000000000000
4.000000000000 8.000000000000
6.000000000000 8.000000000000
6.000000000000 3.000000000000
10.000000000000 3.000000000000
10.000000000000 8.000000000000
12.000000000000 8.000000000000 | instruction | 0 | 53,501 | 23 | 107,002 |
Tags: geometry
Correct Solution:
```
import math
px, py, vx, vy, a, b, c, d = map(int, input().split())
l = math.sqrt(vx**2 + vy**2)
gx, gy = px + ((-1 * vx * d) / l), py + ((-1 * vy * d) / l)
pts = []
pts.append([px + ((b * vx) / l), py + ((b * vy) / l)])
pts.append([px + ((-1 * (a / 2) * vy) / l), py + ((vx * (a / 2)) / l)])
pts.append([px + ((-1 * vy * (c / 2)) / l), py + ((vx * (c / 2)) / l)])
pts.append([gx + ((-1 * (c / 2) * vy) / l), gy + ((vx * (c / 2)) / l)])
pts.append([gx + (((c / 2) * vy) / l), gy + ((-1 * vx * (c / 2)) / l)])
pts.append([px + ((vy * (c / 2)) / l), py + ((-1 * vx * (c / 2)) / l)])
pts.append([px + (((a / 2) * vy) / l), py + ((-1 * vx * (a / 2)) / l)])
for x in pts:
print(x[0], x[1])
``` | output | 1 | 53,501 | 23 | 107,003 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen.
A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c.
The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of (vx, vy) vector.
Enumerate the arrow points coordinates in counter-clockwise order starting from the tip.
<image>
Input
The only line of the input contains eight integers px, py, vx, vy ( - 1000 β€ px, py, vx, vy β€ 1000, vx2 + vy2 > 0), a, b, c, d (1 β€ a, b, c, d β€ 1000, a > c).
Output
Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9.
Examples
Input
8 8 0 2 8 3 4 5
Output
8.000000000000 11.000000000000
4.000000000000 8.000000000000
6.000000000000 8.000000000000
6.000000000000 3.000000000000
10.000000000000 3.000000000000
10.000000000000 8.000000000000
12.000000000000 8.000000000000 | instruction | 0 | 53,502 | 23 | 107,004 |
Tags: geometry
Correct Solution:
```
import math
tab=[float(i) for i in input().split()]
tabx=[0,0,0,0,0,0,0]
taby=[0,0,0,0,0,0,0]
tabx[0]=tab[0]+tab[5]*tab[2]/(math.sqrt(tab[2]**2+tab[3]**2))
taby[0]=tab[1]+tab[5]*tab[3]/(math.sqrt(tab[2]**2+tab[3]**2))
tabx[1]=tab[0]-0.5*tab[4]*tab[3]/(math.sqrt(tab[2]**2+tab[3]**2))
taby[1]=tab[1]+0.5*tab[4]*tab[2]/(math.sqrt(tab[2]**2+tab[3]**2))
tabx[2]=tab[0]-0.5*tab[6]*tab[3]/(math.sqrt(tab[2]**2+tab[3]**2))
taby[2]=tab[1]+0.5*tab[6]*tab[2]/(math.sqrt(tab[2]**2+tab[3]**2))
tabx[3]=tabx[2]-tab[7]*tab[2]/(math.sqrt(tab[2]**2+tab[3]**2))
taby[3]=taby[2]-tab[7]*tab[3]/(math.sqrt(tab[2]**2+tab[3]**2))
tabx[4]=tabx[3]+tab[6]*tab[3]/(math.sqrt(tab[2]**2+tab[3]**2))
taby[4]=taby[3]-tab[6]*tab[2]/(math.sqrt(tab[2]**2+tab[3]**2))
tabx[5]=tab[0]+0.5*tab[6]*tab[3]/(math.sqrt(tab[2]**2+tab[3]**2))
taby[5]=tab[1]-0.5*tab[6]*tab[2]/(math.sqrt(tab[2]**2+tab[3]**2))
tabx[6]=tab[0]+0.5*tab[4]*tab[3]/(math.sqrt(tab[2]**2+tab[3]**2))
taby[6]=tab[1]-0.5*tab[4]*tab[2]/(math.sqrt(tab[2]**2+tab[3]**2))
for i in range(0,7) :
print("{:10.12f}".format(tabx[i]), " ", "{:10.12f}".format(taby[i]))
``` | output | 1 | 53,502 | 23 | 107,005 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen.
A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c.
The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of (vx, vy) vector.
Enumerate the arrow points coordinates in counter-clockwise order starting from the tip.
<image>
Input
The only line of the input contains eight integers px, py, vx, vy ( - 1000 β€ px, py, vx, vy β€ 1000, vx2 + vy2 > 0), a, b, c, d (1 β€ a, b, c, d β€ 1000, a > c).
Output
Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9.
Examples
Input
8 8 0 2 8 3 4 5
Output
8.000000000000 11.000000000000
4.000000000000 8.000000000000
6.000000000000 8.000000000000
6.000000000000 3.000000000000
10.000000000000 3.000000000000
10.000000000000 8.000000000000
12.000000000000 8.000000000000
Submitted Solution:
```
px, py, vx, vy, a, b, c, d = map(int, input().split())
vl = (vx**2 + vy**2)**0.5
vx /= vl
vy /= vl
print(px + vx * b, py + vy * b)
print(px - vy * a / 2, py + vx * a / 2)
print(px - vy * c / 2, py + vx * c / 2)
print(px - vy * c / 2 - vx * d, py + vx * c / 2 - vy * d)
print(px + vy * c / 2 - vx * d, py - vx * c / 2 - vy * d)
print(px + vy * c / 2, py - vx * c / 2)
print(px + vy * a / 2, py - vx * a / 2)
``` | instruction | 0 | 53,503 | 23 | 107,006 |
Yes | output | 1 | 53,503 | 23 | 107,007 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen.
A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c.
The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of (vx, vy) vector.
Enumerate the arrow points coordinates in counter-clockwise order starting from the tip.
<image>
Input
The only line of the input contains eight integers px, py, vx, vy ( - 1000 β€ px, py, vx, vy β€ 1000, vx2 + vy2 > 0), a, b, c, d (1 β€ a, b, c, d β€ 1000, a > c).
Output
Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9.
Examples
Input
8 8 0 2 8 3 4 5
Output
8.000000000000 11.000000000000
4.000000000000 8.000000000000
6.000000000000 8.000000000000
6.000000000000 3.000000000000
10.000000000000 3.000000000000
10.000000000000 8.000000000000
12.000000000000 8.000000000000
Submitted Solution:
```
import math as ma
def mu(a,b):
c=[]
for i in range(len(a)):
c.append(a[i]*b)
return c
def ad(a,b):
c=[]
for i in range(len(a)):
c.append(a[i]+b[i])
return c
def per(a):
if a[1]==0:
return [0,1]
else:
b=ma.sqrt(1+(a[0]**2)/(a[1]**2))
return [-1/b,(a[0]/a[1])/b]
px,py,vx,vy,a,b,c,d=list(map(int,input().split()))
p=[px,py]
u=mu([vx,vy],1/ma.sqrt(vx**2+vy**2))
ud=[-u[1],u[0]]
print(*ad(p,mu(u,b)))
print(*ad(p,mu(ud,a/2)))
print(*ad(p,mu(ud,c/2)))
print(*ad(ad(p,mu(ud,c/2)),mu(u,-d)))
print(*ad(ad(p,mu(ud,-c/2)),mu(u,-d)))
print(*ad(p,mu(ud,-c/2)))
print(*ad(p,mu(ud,-a/2)))
``` | instruction | 0 | 53,504 | 23 | 107,008 |
Yes | output | 1 | 53,504 | 23 | 107,009 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen.
A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c.
The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of (vx, vy) vector.
Enumerate the arrow points coordinates in counter-clockwise order starting from the tip.
<image>
Input
The only line of the input contains eight integers px, py, vx, vy ( - 1000 β€ px, py, vx, vy β€ 1000, vx2 + vy2 > 0), a, b, c, d (1 β€ a, b, c, d β€ 1000, a > c).
Output
Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9.
Examples
Input
8 8 0 2 8 3 4 5
Output
8.000000000000 11.000000000000
4.000000000000 8.000000000000
6.000000000000 8.000000000000
6.000000000000 3.000000000000
10.000000000000 3.000000000000
10.000000000000 8.000000000000
12.000000000000 8.000000000000
Submitted Solution:
```
import os, sys, pdb
import time, calendar, datetime
import math, itertools
import operator as op
from functools import reduce
def ncr(n, r):
r = min(r, n-r)
numer = reduce(op.mul, range(n, n-r, -1), 1)
denom = reduce(op.mul, range(1, r+1), 1)
return numer // denom
px, py, vx, vy, a, b, c, d = list(map(int, input().split()))
theta = math.atan2(vy, vx)
print(px + b * math.cos(theta), py + b * math.sin(theta))
print(px + a/2 * math.cos(theta+math.pi/2), py + a/2 * math.sin(theta+math.pi/2))
print(px + c/2 * math.cos(theta+math.pi/2), py + c/2 * math.sin(theta+math.pi/2))
print(px + c/2 * math.cos(theta+math.pi/2) - d * math.cos(theta),
py + c/2 * math.sin(theta+math.pi/2) - d * math.sin(theta))
print(px + c/2 * math.cos(theta-math.pi/2) - d * math.cos(theta),
py + c/2 * math.sin(theta-math.pi/2) - d * math.sin(theta))
print(px + c/2 * math.cos(theta-math.pi/2), py + c/2 * math.sin(theta-math.pi/2))
print(px + a/2 * math.cos(theta-math.pi/2), py + a/2 * math.sin(theta-math.pi/2))
``` | instruction | 0 | 53,505 | 23 | 107,010 |
Yes | output | 1 | 53,505 | 23 | 107,011 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen.
A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c.
The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of (vx, vy) vector.
Enumerate the arrow points coordinates in counter-clockwise order starting from the tip.
<image>
Input
The only line of the input contains eight integers px, py, vx, vy ( - 1000 β€ px, py, vx, vy β€ 1000, vx2 + vy2 > 0), a, b, c, d (1 β€ a, b, c, d β€ 1000, a > c).
Output
Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9.
Examples
Input
8 8 0 2 8 3 4 5
Output
8.000000000000 11.000000000000
4.000000000000 8.000000000000
6.000000000000 8.000000000000
6.000000000000 3.000000000000
10.000000000000 3.000000000000
10.000000000000 8.000000000000
12.000000000000 8.000000000000
Submitted Solution:
```
import math
s=input()
l=s.split()
px= float(l[0])
py= float(l[1])
vx= float(l[2])
vy= float(l[3])
a= float(l[4])
b= float(l[5])
c= float(l[6])
d= float(l[7])
a2 =a/2
c2 =c/2
def getLeft90(x,y):
return [-y,x]
def getRight90(x,y):
return [y,-x]
def getEndPoint (bx,by,vx,vy,l):
vl=math.sqrt(vx*vx+vy*vy)
ex=l*vx/vl+bx
ey=l*vy/vl+by
return [ex,ey]
sol=[]
sol.append(getEndPoint(px,py,vx,vy,b))
vLeft= getLeft90(vx,vy)
sol.append( getEndPoint(px,py,vLeft[0],vLeft[1],a2))
p2=getEndPoint(px,py,vLeft[0],vLeft[1],c2)
sol.append(p2)
sol.append(getEndPoint(p2[0],p2[1],-vx,-vy,d)) #p3
vRight= getRight90(vx,vy)
p5=getEndPoint(px,py,vRight[0],vRight[1],c2)
sol.append( getEndPoint(p5[0],p5[1],-vx,-vy,d)) #p4
sol.append(p5)
sol.append(getEndPoint(px,py,vRight[0],vRight[1],a2))#p6
for i in sol:
print("%.9f %.9f" % (i[0],i[1]))
``` | instruction | 0 | 53,506 | 23 | 107,012 |
Yes | output | 1 | 53,506 | 23 | 107,013 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen.
A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c.
The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of (vx, vy) vector.
Enumerate the arrow points coordinates in counter-clockwise order starting from the tip.
<image>
Input
The only line of the input contains eight integers px, py, vx, vy ( - 1000 β€ px, py, vx, vy β€ 1000, vx2 + vy2 > 0), a, b, c, d (1 β€ a, b, c, d β€ 1000, a > c).
Output
Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9.
Examples
Input
8 8 0 2 8 3 4 5
Output
8.000000000000 11.000000000000
4.000000000000 8.000000000000
6.000000000000 8.000000000000
6.000000000000 3.000000000000
10.000000000000 3.000000000000
10.000000000000 8.000000000000
12.000000000000 8.000000000000
Submitted Solution:
```
from math import sin
from math import cos
from math import atan2
def rotate(x, y, a):
newX = x * cos(a) - y * sin(a)
newY = x * sin(a) + y * cos(a)
return (x, y)
(px, py, vx, vy, a, b, c, d) = map(int, input().split())
a = [(px, py + b), (px - a / 2., py), (px - c / 2., py), (px - c / 2., py - d), (px + c / 2., py), (px + a / 2., py)]
alpha = atan2(vy, vx)
a = [rotate(i[0], i[1], alpha) for i in a]
for i in a:
print("%0.9f %0.9f" %(i[0], i[1]))
``` | instruction | 0 | 53,507 | 23 | 107,014 |
No | output | 1 | 53,507 | 23 | 107,015 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen.
A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c.
The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of (vx, vy) vector.
Enumerate the arrow points coordinates in counter-clockwise order starting from the tip.
<image>
Input
The only line of the input contains eight integers px, py, vx, vy ( - 1000 β€ px, py, vx, vy β€ 1000, vx2 + vy2 > 0), a, b, c, d (1 β€ a, b, c, d β€ 1000, a > c).
Output
Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9.
Examples
Input
8 8 0 2 8 3 4 5
Output
8.000000000000 11.000000000000
4.000000000000 8.000000000000
6.000000000000 8.000000000000
6.000000000000 3.000000000000
10.000000000000 3.000000000000
10.000000000000 8.000000000000
12.000000000000 8.000000000000
Submitted Solution:
```
""" O. Arrow """
def CF630O():
px, py, vx, vy, a, b, c, d = list(map(int, input().split()))
# Normalize the vector
d = (vx ** 2 + vy ** 2) ** 0.5
vx /= d
vy /= d
vlx = -vy
vly = vx
# Enlist all the points
print(px + vx * b, py + vy * b)
# Symmetric left and right points
print(px - vy * a / 2, py + vx * a / 2)
print(px - vy * c / 2, py + vx * c / 2)
print(px + vlx * (c / 2) - vx * d, py + vly * (c / 2) - vy * d)
print(px - vlx * (c / 2) - vx * d, py - vly * (c / 2) - vy * d)
print(px + vy * c / 2, py - vx * c / 2)
print(px + vy * a / 2, py - vx * a / 2)
CF630O()
``` | instruction | 0 | 53,508 | 23 | 107,016 |
No | output | 1 | 53,508 | 23 | 107,017 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen.
A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c.
The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of (vx, vy) vector.
Enumerate the arrow points coordinates in counter-clockwise order starting from the tip.
<image>
Input
The only line of the input contains eight integers px, py, vx, vy ( - 1000 β€ px, py, vx, vy β€ 1000, vx2 + vy2 > 0), a, b, c, d (1 β€ a, b, c, d β€ 1000, a > c).
Output
Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9.
Examples
Input
8 8 0 2 8 3 4 5
Output
8.000000000000 11.000000000000
4.000000000000 8.000000000000
6.000000000000 8.000000000000
6.000000000000 3.000000000000
10.000000000000 3.000000000000
10.000000000000 8.000000000000
12.000000000000 8.000000000000
Submitted Solution:
```
from math import sin
from math import cos
from math import atan2
def rotate(x, y, a):
newX = x * cos(a) - y * sin(a)
newY = x * sin(a) + y * cos(a)
return (x, y)
(px, py, vx, vy, a, b, c, d) = map(int, input().split())
a = [(px, py + b), (px - a / 2., py), (px - c / 2., py), (px - c / 2., py - d), (px + c / 2., py - d), (px + c / 2., py), (px + a / 2., py)]
alpha = atan2(vy, vx)
a = [rotate(i[0], i[1], -alpha) for i in a]
for i in a:
print("%0.9f %0.9f" %(i[0], i[1]))
``` | instruction | 0 | 53,509 | 23 | 107,018 |
No | output | 1 | 53,509 | 23 | 107,019 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.