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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given three points p1, p2, p, find the projection point x of p onto p1p2.
<image>
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xi, yi ≤ 10000
* p1 and p2 are not identical.
Input
xp1 yp1 xp2 yp2
q
xp0 yp0
xp1 yp1
...
xpq−1 ypq−1
In the first line, integer coordinates of p1 and p2 are given. Then, q queries are given for integer coordinates of p.
Output
For each query, print the coordinate of the projection point x. The output values should be in a decimal fraction with an error less than 0.00000001.
Examples
Input
0 0 2 0
3
-1 1
0 1
1 1
Output
-1.0000000000 0.0000000000
0.0000000000 0.0000000000
1.0000000000 0.0000000000
Input
0 0 3 4
1
2 5
Output
3.1200000000 4.1600000000
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A&lang=jp
"""
import sys
from sys import stdin
input = stdin.readline
class Point(object):
epsilon = 1e-10
def __init__(self, x=0.0, y=0.0):
if isinstance(x, tuple):
self.x = x[0]
self.y = x[1]
else:
self.x = x
self.y = y
# ????????????
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
def __mul__(self, other):
return Point(other * self.x, other * self.y)
def __truediv__(self, other):
return Point(other / self.x, other / self.y)
def __lt__(self, other):
if self.x == other.x:
return self.y < other.y
else:
return self.x < other.x
def __eq__(self, other):
from math import fabs
if fabs(self.x - other.x) < Point.epsilon and fabs(self.y - other.y) < Point.epsilon:
return True
else:
return False
def norm(self):
return self.x * self.x + self.y * self.y
def abs(self):
from math import sqrt
return sqrt(self.norm())
class Vector(Point):
def __init__(self, x=0.0, y=0.0):
if isinstance(x, tuple):
self.x = x[0]
self.y = x[1]
elif isinstance(x, Point):
self.x = x.x
self.y = x.y
else:
self.x = x
self.y = y
# ????????????
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__(self, other):
return Vector(other * self.x, other * self.y)
def __truediv__(self, other):
return Vector(other / self.x, other / self.y)
@classmethod
def dot(cls, a, b):
return a.x * b.x + a.y * b.y
@classmethod
def cross(cls, a, b):
return a.x * b.y - a.y * b.x
@classmethod
def is_orthogonal(cls, a, b):
return Vector.dot(a, b) == 0.0
@classmethod
def is_parallel(cls, a, b):
return Vector.cross(a, b) == 0.0
class Segment(object):
def __init__(self, p1=Point(), p2=Point()):
if isinstance(p1, Point):
self.p1 = p1
self.p2 = p2
elif isinstance(p1, tuple):
self.p1 = Point(p1[0], p1[1])
self.p2 = Point(p2[0], p2[1])
@classmethod
def is_orthogonal(cls, s1, s2):
a = Vector(s1.p2 - s1.p1)
b = Vector(s2.p2 - s2.p1)
return Vector.is_orthogonal(a, b)
@classmethod
def is_parallel(cls, s1, s2):
a = Vector(s1.p2 - s1.p1)
b = Vector(s2.p2 - s2.p1)
return Vector.is_parallel(a, b)
class Line(Segment):
pass
class Cirle(object):
def __init__(self, c=Point(), r=0.0):
self.c = c
self.r = r
def solve(s, p):
base = Vector(s.p2 - s.p1)
a = Vector(p - s.p1)
r = Vector.dot(a, base)
r /= base.norm()
return s.p1 + base * r
def main(args):
x_p1, y_p1, x_p2, y_p2 = map(int, input().split())
q = int(input())
s = Segment((x_p1, y_p1), (x_p2, y_p2))
for _ in range(q):
x, y = map(int, input().split())
p = Point(x, y)
result = solve(s, p)
print('{:.10f} {:.10f}'.format(result.x, result.y))
if __name__ == '__main__':
main(sys.argv[1:])
``` | instruction | 0 | 95,265 | 23 | 190,530 |
Yes | output | 1 | 95,265 | 23 | 190,531 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given three points p1, p2, p, find the projection point x of p onto p1p2.
<image>
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xi, yi ≤ 10000
* p1 and p2 are not identical.
Input
xp1 yp1 xp2 yp2
q
xp0 yp0
xp1 yp1
...
xpq−1 ypq−1
In the first line, integer coordinates of p1 and p2 are given. Then, q queries are given for integer coordinates of p.
Output
For each query, print the coordinate of the projection point x. The output values should be in a decimal fraction with an error less than 0.00000001.
Examples
Input
0 0 2 0
3
-1 1
0 1
1 1
Output
-1.0000000000 0.0000000000
0.0000000000 0.0000000000
1.0000000000 0.0000000000
Input
0 0 3 4
1
2 5
Output
3.1200000000 4.1600000000
Submitted Solution:
```
from sys import stdin
readline = stdin.readline
def main():
x1, y1, x2, y2 = map(int, readline().split())
p1, p2 = x1 + y1 * 1j, x2 + y2 * 1j
for i in range(int(readline())):
xi, yi = map(int, readline().split())
pi = xi + yi * 1j
cross = p1 + (p2 - p1) * projecter(p2 - p1, pi - p1)
print('{:.10f} {:.10f}'.format(cross.real, cross.imag))
def projecter(a, b):
return dot(a, b) / dot(a, a)
def dot(a, b):
return a.real * b.real + a.imag * b.imag
main()
``` | instruction | 0 | 95,266 | 23 | 190,532 |
Yes | output | 1 | 95,266 | 23 | 190,533 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given three points p1, p2, p, find the projection point x of p onto p1p2.
<image>
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xi, yi ≤ 10000
* p1 and p2 are not identical.
Input
xp1 yp1 xp2 yp2
q
xp0 yp0
xp1 yp1
...
xpq−1 ypq−1
In the first line, integer coordinates of p1 and p2 are given. Then, q queries are given for integer coordinates of p.
Output
For each query, print the coordinate of the projection point x. The output values should be in a decimal fraction with an error less than 0.00000001.
Examples
Input
0 0 2 0
3
-1 1
0 1
1 1
Output
-1.0000000000 0.0000000000
0.0000000000 0.0000000000
1.0000000000 0.0000000000
Input
0 0 3 4
1
2 5
Output
3.1200000000 4.1600000000
Submitted Solution:
```
from math import hypot
x1, y1, x2, y2 = map(int, input().split())
dx, dy = x2-x1, y2-y1
vector_base = hypot(dx, dy)
q = int(input())
for i in range(q):
x3, y3 = map(int, input().split())
d = ((x3-x1)*dx + (y3-y1)*dy) / (vector_base**2)
print(x1+dx*d, y1+dy*d)
``` | instruction | 0 | 95,267 | 23 | 190,534 |
Yes | output | 1 | 95,267 | 23 | 190,535 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given three points p1, p2, p, find the projection point x of p onto p1p2.
<image>
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xi, yi ≤ 10000
* p1 and p2 are not identical.
Input
xp1 yp1 xp2 yp2
q
xp0 yp0
xp1 yp1
...
xpq−1 ypq−1
In the first line, integer coordinates of p1 and p2 are given. Then, q queries are given for integer coordinates of p.
Output
For each query, print the coordinate of the projection point x. The output values should be in a decimal fraction with an error less than 0.00000001.
Examples
Input
0 0 2 0
3
-1 1
0 1
1 1
Output
-1.0000000000 0.0000000000
0.0000000000 0.0000000000
1.0000000000 0.0000000000
Input
0 0 3 4
1
2 5
Output
3.1200000000 4.1600000000
Submitted Solution:
```
def dot(a, b):
return a.real * b.real + a.imag * b.imag
def projection(a, b):
return a * dot(a, b) / (abs(a) ** 2)
#複素平面の座標はクラスだから直接加算できr
def solve(p0,p1,p2):
a=p1-p0
b=p2-p0
pro=projection(a,b)
t=p0+pro
return t
def main():
x0,y0,x1,y1=map(float,input().split())
p0=complex(x0,y0)
p1=complex(x1,y1)
q=int(input())
for i in range(q):
p2=complex(*map(float,input().split()))
t=solve(p0,p1,p2)
print('{:.10f}{:.10f}'.format(t.real,t.imag))
if __name__ == '__main__':
main()
``` | instruction | 0 | 95,268 | 23 | 190,536 |
No | output | 1 | 95,268 | 23 | 190,537 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given three points p1, p2, p, find the projection point x of p onto p1p2.
<image>
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xi, yi ≤ 10000
* p1 and p2 are not identical.
Input
xp1 yp1 xp2 yp2
q
xp0 yp0
xp1 yp1
...
xpq−1 ypq−1
In the first line, integer coordinates of p1 and p2 are given. Then, q queries are given for integer coordinates of p.
Output
For each query, print the coordinate of the projection point x. The output values should be in a decimal fraction with an error less than 0.00000001.
Examples
Input
0 0 2 0
3
-1 1
0 1
1 1
Output
-1.0000000000 0.0000000000
0.0000000000 0.0000000000
1.0000000000 0.0000000000
Input
0 0 3 4
1
2 5
Output
3.1200000000 4.1600000000
Submitted Solution:
```
# Aizu Problem CGL_1_A: Projection
#
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input3.txt", "rt")
x1, y1, x2, y2 = [int(_) for _ in input().split()]
sx = x2 - x1
sy = y2 - y1
s_sq = sx**2 + sy**2
Q = int(input())
for q in range(Q):
px, py = [int(_) for _ in input().split()]
if y1 == y2:
x = px
y = y1
else:
x = x1 + (px * sx + py * sy) * sx / s_sq
y = y1 + (px * sx + py * sy) * sy / s_sq
print("%.10f %.10f" % (x, y))
``` | instruction | 0 | 95,269 | 23 | 190,538 |
No | output | 1 | 95,269 | 23 | 190,539 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given three points p1, p2, p, find the projection point x of p onto p1p2.
<image>
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xi, yi ≤ 10000
* p1 and p2 are not identical.
Input
xp1 yp1 xp2 yp2
q
xp0 yp0
xp1 yp1
...
xpq−1 ypq−1
In the first line, integer coordinates of p1 and p2 are given. Then, q queries are given for integer coordinates of p.
Output
For each query, print the coordinate of the projection point x. The output values should be in a decimal fraction with an error less than 0.00000001.
Examples
Input
0 0 2 0
3
-1 1
0 1
1 1
Output
-1.0000000000 0.0000000000
0.0000000000 0.0000000000
1.0000000000 0.0000000000
Input
0 0 3 4
1
2 5
Output
3.1200000000 4.1600000000
Submitted Solution:
```
def dot(a, b):
return a.real * b.real + a.imag * b.imag
def projection(a, b):
return a * dot(a, b) / (abs(a) ** 2)
#複素平面の座標はクラスだから直接加算できr
def solve(p0,p1,p2):
a=p1-p0
b=p2-p0
pro=projection(a,b)
t=p0+pro
return t
def main():
x0,y0,x1,y1=map(float,input().split())
p0=complex(x0,y0)
p1=complex(x1,y1)
q=int(input())
for i in range(q):
p2=complex(*map(float,input().split()))
t=solve(p0,p1,p2)
print('{:.10f}{:.10f}'.format(t.real,t.imag))
main()
``` | instruction | 0 | 95,270 | 23 | 190,540 |
No | output | 1 | 95,270 | 23 | 190,541 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given three points p1, p2, p, find the projection point x of p onto p1p2.
<image>
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xi, yi ≤ 10000
* p1 and p2 are not identical.
Input
xp1 yp1 xp2 yp2
q
xp0 yp0
xp1 yp1
...
xpq−1 ypq−1
In the first line, integer coordinates of p1 and p2 are given. Then, q queries are given for integer coordinates of p.
Output
For each query, print the coordinate of the projection point x. The output values should be in a decimal fraction with an error less than 0.00000001.
Examples
Input
0 0 2 0
3
-1 1
0 1
1 1
Output
-1.0000000000 0.0000000000
0.0000000000 0.0000000000
1.0000000000 0.0000000000
Input
0 0 3 4
1
2 5
Output
3.1200000000 4.1600000000
Submitted Solution:
```
def dot(a,b):
return a[0]*b[0] + a[1]*b[1]
x1,y1,x2,y2 = [int(i) for i in input().split()]
q = int(input())
for i in range(q):
x,y = [int(i) for i in input().split()]
a = [x2-x1,y2-y1]
b = [x-x1,y-y1]
co = dot(a,b) / dot(a,a)
print(a[0]*co,a[1]*co)
``` | instruction | 0 | 95,271 | 23 | 190,542 |
No | output | 1 | 95,271 | 23 | 190,543 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
Khanh has n points on the Cartesian plane, denoted by a_1, a_2, …, a_n. All points' coordinates are integers between -10^9 and 10^9, inclusive. No three points are collinear. He says that these points are vertices of a convex polygon; in other words, there exists a permutation p_1, p_2, …, p_n of integers from 1 to n such that the polygon a_{p_1} a_{p_2} … a_{p_n} is convex and vertices are listed in counter-clockwise order.
Khanh gives you the number n, but hides the coordinates of his points. Your task is to guess the above permutation by asking multiple queries. In each query, you give Khanh 4 integers t, i, j, k; where either t = 1 or t = 2; and i, j, k are three distinct indices from 1 to n, inclusive. In response, Khanh tells you:
* if t = 1, the area of the triangle a_ia_ja_k multiplied by 2.
* if t = 2, the sign of the cross product of two vectors \overrightarrow{a_ia_j} and \overrightarrow{a_ia_k}.
Recall that the cross product of vector \overrightarrow{a} = (x_a, y_a) and vector \overrightarrow{b} = (x_b, y_b) is the integer x_a ⋅ y_b - x_b ⋅ y_a. The sign of a number is 1 it it is positive, and -1 otherwise. It can be proven that the cross product obtained in the above queries can not be 0.
You can ask at most 3 ⋅ n queries.
Please note that Khanh fixes the coordinates of his points and does not change it while answering your queries. You do not need to guess the coordinates. In your permutation a_{p_1}a_{p_2}… a_{p_n}, p_1 should be equal to 1 and the indices of vertices should be listed in counter-clockwise order.
Interaction
You start the interaction by reading n (3 ≤ n ≤ 1 000) — the number of vertices.
To ask a query, write 4 integers t, i, j, k (1 ≤ t ≤ 2, 1 ≤ i, j, k ≤ n) in a separate line. i, j and k should be distinct.
Then read a single integer to get the answer to this query, as explained above. It can be proven that the answer of a query is always an integer.
When you find the permutation, write a number 0. Then write n integers p_1, p_2, …, p_n in the same line.
After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hack format
To hack, use the following format:
The first line contains an integer n (3 ≤ n ≤ 1 000) — the number of vertices.
The i-th of the next n lines contains two integers x_i and y_i (-10^9 ≤ x_i, y_i ≤ 10^9) — the coordinate of the point a_i.
Example
Input
6
15
-1
1
Output
1 1 4 6
2 1 5 6
2 2 1 4
0 1 3 4 2 6 5
Note
The image below shows the hidden polygon in the example:
<image>
The interaction in the example goes as below:
* Contestant reads n = 6.
* Contestant asks a query with t = 1, i = 1, j = 4, k = 6.
* Jury answers 15. The area of the triangle A_1A_4A_6 is 7.5. Note that the answer is two times the area of the triangle.
* Contestant asks a query with t = 2, i = 1, j = 5, k = 6.
* Jury answers -1. The cross product of \overrightarrow{A_1A_5} = (2, 2) and \overrightarrow{A_1A_6} = (4, 1) is -2. The sign of -2 is -1.
* Contestant asks a query with t = 2, i = 2, j = 1, k = 4.
* Jury answers 1. The cross product of \overrightarrow{A_2A_1} = (-5, 2) and \overrightarrow{A_2A_4} = (-2, -1) is 1. The sign of 1 is 1.
* Contestant says that the permutation is (1, 3, 4, 2, 6, 5).
Submitted Solution:
```
import bisect
import sys
input = sys.stdin.readline
n = int(input())
up = []
down = []
for i in range(2, n):
# 問い合わせる
print(2, 1, i, n)
# 問い合わせた後はflushする
sys.stdout.flush()
# 入力を受け取る
tmp = int(input())
if tmp == -1:
up.append(i)
else:
down.append(i)
up2 = []
down2 = []
for i in up:
# 問い合わせる
print(1, 1, i, n)
# 問い合わせた後はflushする
sys.stdout.flush()
# 入力を受け取る
s = int(input())
up2.append((s, i))
for i in down:
# 問い合わせる
print(1, 1, i, n)
# 問い合わせた後はflushする
sys.stdout.flush()
# 入力を受け取る
s = int(input())
down2.append((s, i))
up2 = sorted(up2)
down2 = sorted(down2)
ans1 = [1]
ans2 = []
ans3 = [n]
ans4 = []
ans = []
if up2:
k = up2[-1][1]
for i in range(len(up2) - 1):
num = up2[i][1]
# 問い合わせる
print(2, 1, num, k)
# 問い合わせた後はflushする
sys.stdout.flush()
# 入力を受け取る
tmp = int(input())
if tmp == -1:
ans1.append(num)
else:
ans2.append(num)
ans += ans1 + [k] + ans2[::-1]
else:
ans += ans1
if down2:
l = down2[-1][1]
for i in range(len(down2) - 1):
num = down2[i][1]
# 問い合わせる
print(2, n, num, l)
# 問い合わせた後はflushする
sys.stdout.flush()
# 入力を受け取る
tmp = int(input())
if tmp == -1:
ans3.append(num)
else:
ans4.append(num)
ans += ans3 + [l] + ans4[::-1]
else:
ans += ans3
print(0, *ans[::-1])
``` | instruction | 0 | 95,383 | 23 | 190,766 |
No | output | 1 | 95,383 | 23 | 190,767 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
Khanh has n points on the Cartesian plane, denoted by a_1, a_2, …, a_n. All points' coordinates are integers between -10^9 and 10^9, inclusive. No three points are collinear. He says that these points are vertices of a convex polygon; in other words, there exists a permutation p_1, p_2, …, p_n of integers from 1 to n such that the polygon a_{p_1} a_{p_2} … a_{p_n} is convex and vertices are listed in counter-clockwise order.
Khanh gives you the number n, but hides the coordinates of his points. Your task is to guess the above permutation by asking multiple queries. In each query, you give Khanh 4 integers t, i, j, k; where either t = 1 or t = 2; and i, j, k are three distinct indices from 1 to n, inclusive. In response, Khanh tells you:
* if t = 1, the area of the triangle a_ia_ja_k multiplied by 2.
* if t = 2, the sign of the cross product of two vectors \overrightarrow{a_ia_j} and \overrightarrow{a_ia_k}.
Recall that the cross product of vector \overrightarrow{a} = (x_a, y_a) and vector \overrightarrow{b} = (x_b, y_b) is the integer x_a ⋅ y_b - x_b ⋅ y_a. The sign of a number is 1 it it is positive, and -1 otherwise. It can be proven that the cross product obtained in the above queries can not be 0.
You can ask at most 3 ⋅ n queries.
Please note that Khanh fixes the coordinates of his points and does not change it while answering your queries. You do not need to guess the coordinates. In your permutation a_{p_1}a_{p_2}… a_{p_n}, p_1 should be equal to 1 and the indices of vertices should be listed in counter-clockwise order.
Interaction
You start the interaction by reading n (3 ≤ n ≤ 1 000) — the number of vertices.
To ask a query, write 4 integers t, i, j, k (1 ≤ t ≤ 2, 1 ≤ i, j, k ≤ n) in a separate line. i, j and k should be distinct.
Then read a single integer to get the answer to this query, as explained above. It can be proven that the answer of a query is always an integer.
When you find the permutation, write a number 0. Then write n integers p_1, p_2, …, p_n in the same line.
After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hack format
To hack, use the following format:
The first line contains an integer n (3 ≤ n ≤ 1 000) — the number of vertices.
The i-th of the next n lines contains two integers x_i and y_i (-10^9 ≤ x_i, y_i ≤ 10^9) — the coordinate of the point a_i.
Example
Input
6
15
-1
1
Output
1 1 4 6
2 1 5 6
2 2 1 4
0 1 3 4 2 6 5
Note
The image below shows the hidden polygon in the example:
<image>
The interaction in the example goes as below:
* Contestant reads n = 6.
* Contestant asks a query with t = 1, i = 1, j = 4, k = 6.
* Jury answers 15. The area of the triangle A_1A_4A_6 is 7.5. Note that the answer is two times the area of the triangle.
* Contestant asks a query with t = 2, i = 1, j = 5, k = 6.
* Jury answers -1. The cross product of \overrightarrow{A_1A_5} = (2, 2) and \overrightarrow{A_1A_6} = (4, 1) is -2. The sign of -2 is -1.
* Contestant asks a query with t = 2, i = 2, j = 1, k = 4.
* Jury answers 1. The cross product of \overrightarrow{A_2A_1} = (-5, 2) and \overrightarrow{A_2A_4} = (-2, -1) is 1. The sign of 1 is 1.
* Contestant says that the permutation is (1, 3, 4, 2, 6, 5).
Submitted Solution:
```
def chk(i):
print(2, 1, 2, i)
a = int(input())
print(1, 1, 2, i)
s = int(input())
return (a, s)
def cha(a, b, c):
print(2, a, b, c)
return int(input())
N = int(input())
PO = []
NE = []
for i in range(3, N+1):
a, s = chk(i)
if a > 0:
PO.append((s, i))
else:
NE.append((s, i))
PO = sorted(PO)
NE = sorted(NE)
# print("PO =", PO)
# print("NE =", NE)
P1 = []
P2 = []
N1 = []
N2 = []
if not PO:
pass
else:
i0 = PO.pop()[1]
P1.append(i0)
while PO:
i = PO.pop()[1]
if cha(1, i0, i) > 0:
P1.append(i)
else:
P2.append(i)
i0 = NE.pop()[1]
N1.append(i0)
while NE:
i = NE.pop()[1]
if cha(1, i0, i) < 0:
N1.append(i)
else:
N2.append(i)
ANS = [0] + [1] + N1[::-1] + N2 + [2] + P2[::-1] + P1
print(*ANS)
``` | instruction | 0 | 95,384 | 23 | 190,768 |
No | output | 1 | 95,384 | 23 | 190,769 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
Khanh has n points on the Cartesian plane, denoted by a_1, a_2, …, a_n. All points' coordinates are integers between -10^9 and 10^9, inclusive. No three points are collinear. He says that these points are vertices of a convex polygon; in other words, there exists a permutation p_1, p_2, …, p_n of integers from 1 to n such that the polygon a_{p_1} a_{p_2} … a_{p_n} is convex and vertices are listed in counter-clockwise order.
Khanh gives you the number n, but hides the coordinates of his points. Your task is to guess the above permutation by asking multiple queries. In each query, you give Khanh 4 integers t, i, j, k; where either t = 1 or t = 2; and i, j, k are three distinct indices from 1 to n, inclusive. In response, Khanh tells you:
* if t = 1, the area of the triangle a_ia_ja_k multiplied by 2.
* if t = 2, the sign of the cross product of two vectors \overrightarrow{a_ia_j} and \overrightarrow{a_ia_k}.
Recall that the cross product of vector \overrightarrow{a} = (x_a, y_a) and vector \overrightarrow{b} = (x_b, y_b) is the integer x_a ⋅ y_b - x_b ⋅ y_a. The sign of a number is 1 it it is positive, and -1 otherwise. It can be proven that the cross product obtained in the above queries can not be 0.
You can ask at most 3 ⋅ n queries.
Please note that Khanh fixes the coordinates of his points and does not change it while answering your queries. You do not need to guess the coordinates. In your permutation a_{p_1}a_{p_2}… a_{p_n}, p_1 should be equal to 1 and the indices of vertices should be listed in counter-clockwise order.
Interaction
You start the interaction by reading n (3 ≤ n ≤ 1 000) — the number of vertices.
To ask a query, write 4 integers t, i, j, k (1 ≤ t ≤ 2, 1 ≤ i, j, k ≤ n) in a separate line. i, j and k should be distinct.
Then read a single integer to get the answer to this query, as explained above. It can be proven that the answer of a query is always an integer.
When you find the permutation, write a number 0. Then write n integers p_1, p_2, …, p_n in the same line.
After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hack format
To hack, use the following format:
The first line contains an integer n (3 ≤ n ≤ 1 000) — the number of vertices.
The i-th of the next n lines contains two integers x_i and y_i (-10^9 ≤ x_i, y_i ≤ 10^9) — the coordinate of the point a_i.
Example
Input
6
15
-1
1
Output
1 1 4 6
2 1 5 6
2 2 1 4
0 1 3 4 2 6 5
Note
The image below shows the hidden polygon in the example:
<image>
The interaction in the example goes as below:
* Contestant reads n = 6.
* Contestant asks a query with t = 1, i = 1, j = 4, k = 6.
* Jury answers 15. The area of the triangle A_1A_4A_6 is 7.5. Note that the answer is two times the area of the triangle.
* Contestant asks a query with t = 2, i = 1, j = 5, k = 6.
* Jury answers -1. The cross product of \overrightarrow{A_1A_5} = (2, 2) and \overrightarrow{A_1A_6} = (4, 1) is -2. The sign of -2 is -1.
* Contestant asks a query with t = 2, i = 2, j = 1, k = 4.
* Jury answers 1. The cross product of \overrightarrow{A_2A_1} = (-5, 2) and \overrightarrow{A_2A_4} = (-2, -1) is 1. The sign of 1 is 1.
* Contestant says that the permutation is (1, 3, 4, 2, 6, 5).
Submitted Solution:
```
mod = 1000000007
eps = 10**-9
def main():
import sys
input = sys.stdin.readline
def ask(t, i, j, k):
print(t, i, j, k)
sys.stdout.flush()
N = int(input())
p1 = 1
p2 = 2
for k in range(3, N+1):
ask(2, 1, p2, k)
flg = int(input())
if flg == -1:
p2 = k
SK = []
for k in range(2, N+1):
if k == p2:
continue
ask(1, 1, p2, k)
S = int(input())
SK.append((S, k))
SK.sort(key=lambda x: x[0])
pmax = SK[-1][1]
p_first = []
p_second = []
for S, k in SK[:-1]:
ask(2, 1, pmax, k)
flg = int(input())
if flg == -1:
p_second.append((S, k))
else:
p_first.append((S, k))
p_first.sort(key=lambda x: x[0])
p_second.sort(key=lambda x: x[0], reverse=True)
ans = [0, 1, p2]
for _, p in p_first:
ans.append(p)
ans.append(pmax)
for _, p in p_second:
ans.append(p)
print(*ans)
sys.stdout.flush()
if __name__ == '__main__':
main()
``` | instruction | 0 | 95,385 | 23 | 190,770 |
No | output | 1 | 95,385 | 23 | 190,771 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
Khanh has n points on the Cartesian plane, denoted by a_1, a_2, …, a_n. All points' coordinates are integers between -10^9 and 10^9, inclusive. No three points are collinear. He says that these points are vertices of a convex polygon; in other words, there exists a permutation p_1, p_2, …, p_n of integers from 1 to n such that the polygon a_{p_1} a_{p_2} … a_{p_n} is convex and vertices are listed in counter-clockwise order.
Khanh gives you the number n, but hides the coordinates of his points. Your task is to guess the above permutation by asking multiple queries. In each query, you give Khanh 4 integers t, i, j, k; where either t = 1 or t = 2; and i, j, k are three distinct indices from 1 to n, inclusive. In response, Khanh tells you:
* if t = 1, the area of the triangle a_ia_ja_k multiplied by 2.
* if t = 2, the sign of the cross product of two vectors \overrightarrow{a_ia_j} and \overrightarrow{a_ia_k}.
Recall that the cross product of vector \overrightarrow{a} = (x_a, y_a) and vector \overrightarrow{b} = (x_b, y_b) is the integer x_a ⋅ y_b - x_b ⋅ y_a. The sign of a number is 1 it it is positive, and -1 otherwise. It can be proven that the cross product obtained in the above queries can not be 0.
You can ask at most 3 ⋅ n queries.
Please note that Khanh fixes the coordinates of his points and does not change it while answering your queries. You do not need to guess the coordinates. In your permutation a_{p_1}a_{p_2}… a_{p_n}, p_1 should be equal to 1 and the indices of vertices should be listed in counter-clockwise order.
Interaction
You start the interaction by reading n (3 ≤ n ≤ 1 000) — the number of vertices.
To ask a query, write 4 integers t, i, j, k (1 ≤ t ≤ 2, 1 ≤ i, j, k ≤ n) in a separate line. i, j and k should be distinct.
Then read a single integer to get the answer to this query, as explained above. It can be proven that the answer of a query is always an integer.
When you find the permutation, write a number 0. Then write n integers p_1, p_2, …, p_n in the same line.
After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hack format
To hack, use the following format:
The first line contains an integer n (3 ≤ n ≤ 1 000) — the number of vertices.
The i-th of the next n lines contains two integers x_i and y_i (-10^9 ≤ x_i, y_i ≤ 10^9) — the coordinate of the point a_i.
Example
Input
6
15
-1
1
Output
1 1 4 6
2 1 5 6
2 2 1 4
0 1 3 4 2 6 5
Note
The image below shows the hidden polygon in the example:
<image>
The interaction in the example goes as below:
* Contestant reads n = 6.
* Contestant asks a query with t = 1, i = 1, j = 4, k = 6.
* Jury answers 15. The area of the triangle A_1A_4A_6 is 7.5. Note that the answer is two times the area of the triangle.
* Contestant asks a query with t = 2, i = 1, j = 5, k = 6.
* Jury answers -1. The cross product of \overrightarrow{A_1A_5} = (2, 2) and \overrightarrow{A_1A_6} = (4, 1) is -2. The sign of -2 is -1.
* Contestant asks a query with t = 2, i = 2, j = 1, k = 4.
* Jury answers 1. The cross product of \overrightarrow{A_2A_1} = (-5, 2) and \overrightarrow{A_2A_4} = (-2, -1) is 1. The sign of 1 is 1.
* Contestant says that the permutation is (1, 3, 4, 2, 6, 5).
Submitted Solution:
```
import bisect
import sys
input = sys.stdin.readline
n = int(input())
up = []
down = []
print(2, 1, 3, n)
sys.stdout.flush()
tmp = int(input())
print(tmp)
``` | instruction | 0 | 95,386 | 23 | 190,772 |
No | output | 1 | 95,386 | 23 | 190,773 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
* Elements of the main diagonal.
* Elements of the secondary diagonal.
* Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
* Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.
<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
* 1 ≤ n ≤ 5
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
45
Input
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.
Submitted Solution:
```
n = int(input()); V = 0
if n > 2:
for i in range(n):
L = [int(x) for x in input().split()]
if i == 0.5*(n-1):
V += sum(L)
else:
V += L[i] + L[int((n-1)/2)] + L[n-i-1]
print(V)
else:
print(int(input()))
``` | instruction | 0 | 95,544 | 23 | 191,088 |
Yes | output | 1 | 95,544 | 23 | 191,089 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
* Elements of the main diagonal.
* Elements of the secondary diagonal.
* Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
* Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.
<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
* 1 ≤ n ≤ 5
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
45
Input
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.
Submitted Solution:
```
x=int(input())
z=0;s=0;l=(x-1)
for i in range(x):
y=input().split()
if i<((x//2)-1) :
z+=int(y[s])+int(y[l])+int(y[x//2])
s+=1;l-=1
elif i==((x//2)-1) :
z += int(y[s]) + int(y[l]) + int(y[x // 2])
elif i ==(x//2):
for r in range(x):
z+=int(y[r])
else:
z+=int(y[x//2])+int(y[l])+int(y[s])
s-=1;l+=1
print(z)
``` | instruction | 0 | 95,545 | 23 | 191,090 |
Yes | output | 1 | 95,545 | 23 | 191,091 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
* Elements of the main diagonal.
* Elements of the secondary diagonal.
* Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
* Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.
<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
* 1 ≤ n ≤ 5
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
45
Input
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.
Submitted Solution:
```
n = int(input())
IL = lambda: list(map(int, input().split()))
M = [IL() for i in range(n)]
print(sum(M[n//2]) + sum([M[i][i] + M[i][n-i-1] + M[i][n//2] for i in range(n)]) - 3*M[n//2][n//2])
``` | instruction | 0 | 95,546 | 23 | 191,092 |
Yes | output | 1 | 95,546 | 23 | 191,093 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
* Elements of the main diagonal.
* Elements of the secondary diagonal.
* Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
* Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.
<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
* 1 ≤ n ≤ 5
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
45
Input
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.
Submitted Solution:
```
n = int(input())
m = [[int(i) for i in input().split()] for i in range(n)]
a = 0
b = 0
c = 0
d = 0
s = 0
if n==3:
for i in range(n):
s += sum(m[i])
else:
for i in range(n//3):
a += m[len(m)//2][i]
b += m[i][len(m)//2]
c += m[i][i]
for i in range(n-n//3, n):
a += m[len(m)//2][i]
b += m[i][len(m)//2]
c += m[i][i]
p = 0
for i in range(n-1,n-n//3-1,-1):
d += m[i][p]
p += 1
p = n-n//3
for i in range(n//3-1,-1,-1):
d += m[i][p]
p += 1
for h in range(n//3, n-n//3):
for w in range(n//3, n-n//3):
s += m[h][w]
s += a+b+c+d
print(s)
``` | instruction | 0 | 95,548 | 23 | 191,096 |
No | output | 1 | 95,548 | 23 | 191,097 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
* Elements of the main diagonal.
* Elements of the secondary diagonal.
* Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
* Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.
<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
* 1 ≤ n ≤ 5
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
45
Input
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.
Submitted Solution:
```
"""
Author : Indian Coder
Date : 29th May ,2021
"""
#Imports
import math
import time
import random
start=time.time()
n=int(input())
sample=0
sample1=[]
for i in range(0,n):
a1=list(map(int ,input().split()))
sample+=(sum(a1))
sample1.append(a1)
if(n<=3):
print(sample)
else:
back_val=n
back_value_list=[]
for i in range(0,len(sample1)):
back_value_list.append(sample1[i][back_val-1])
back_val-=1
#print(sample1)
#print(back_value_list)
front_valu=0
front_value_list=[]
for j in range(0,len(sample1)):
front_value_list.append(sample1[j][front_valu])
front_valu+=1
#print(front_value_list)
middle_col_value=0
pos_add=n//2+1
for k in range(0,len(sample1)):
middle_col_value+=sample1[k][pos_add-1]
#print(middle_col_value)
middle_row_sum=sum(sample1[pos_add-1])
print(sum(front_value_list)+sum(back_value_list)+middle_col_value+middle_row_sum-3*sample1[n//2+1][2])
end=time.time()
#print("Time Of Execution Is",end-start)
``` | instruction | 0 | 95,550 | 23 | 191,100 |
No | output | 1 | 95,550 | 23 | 191,101 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:
* Elements of the main diagonal.
* Elements of the secondary diagonal.
* Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it.
* Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it.
<image> The figure shows a 5 × 5 matrix. The good elements are marked with green.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input
The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
* 1 ≤ n ≤ 5
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 101
Output
Print a single integer — the sum of good matrix elements.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
45
Input
5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
17
Note
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.
Submitted Solution:
```
n = int(input())
arr = [[int(i) for i in input().split()] for j in range(n)]
ans = 0
for i in range(n):
ans += arr[i][i]
arr[i][i] = 0
ans += arr[n - 1 - i][i];
arr[n - i - 1][i] = 0
ans += arr[n-1][n//2];
arr[n-1][n//2] = 0
ans += arr[n//2][n-1];
arr[n//2][n-1] = 0
print(ans)
``` | instruction | 0 | 95,551 | 23 | 191,102 |
No | output | 1 | 95,551 | 23 | 191,103 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40 | instruction | 0 | 95,619 | 23 | 191,238 |
Tags: combinatorics, data structures, implementation
Correct Solution:
```
import sys
from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7
a = int(ri())
st= ri()
arr = [int(i) for i in st]
dic = {}
cnt = 0
nz = 0
for i in range(len(st)):
summ = 0
for j in range(i,len(st)):
summ+=arr[j]
if summ != 0:
nz+=1
if summ in dic:
dic[summ]+=1
else:
dic[summ] = 1
if a!= 0:
for i in dic:
if i != 0:
val = a/i
if val in dic:
cnt = cnt + dic[val]*dic[i]
print(cnt)
else:
n = len(st)
print(n**2*(n+1)**2//4 - nz*nz)
``` | output | 1 | 95,619 | 23 | 191,239 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40 | instruction | 0 | 95,620 | 23 | 191,240 |
Tags: combinatorics, data structures, implementation
Correct Solution:
```
from math import *
#from bisect import *
#from collections import *
#from random import *
#from decimal import *"""
#from heapq import *
#from random import *
import sys
input=sys.stdin.readline
#sys.setrecursionlimit(3*(10**5))
global flag
def inp():
return int(input())
def st():
return input().rstrip('\n')
def lis():
return list(map(int,input().split()))
def ma():
return map(int,input().split())
t=1
def pos(su,le):
if(su>=0 and su<=(9*le)):
return 1
return 0
while(t):
t-=1
a=inp()
s=st()
di={}
for i in range(len(s)):
su=0
for j in range(i,len(s)):
su+=int(s[j])
try:
di[su]+=1
except:
di[su]=1
co=0
for i in di.keys():
if(a==0 and i==0):
co+=di[0]*(len(s)*(len(s)+1))
co-=(di[0]*di[0])
if(i and a%i==0 and (a//i) in di and a):
co+=di[i]*di[a//i]
print(co)
``` | output | 1 | 95,620 | 23 | 191,241 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40 | instruction | 0 | 95,621 | 23 | 191,242 |
Tags: combinatorics, data structures, implementation
Correct Solution:
```
import time,math as mt,bisect as bs,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
return int(stdin.readline())
def IP(): # to take tuple as input
return map(int,stdin.readline().split())
def L(): # to take list as input
return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
if a==0:
return b
elif b==0:
return a
if a>b:
return gcd(a%b,b)
else:
return gcd(a,b%a)
def bfs(adj,v): # a schema of bfs
visited=[False]*(v+1)
q=deque()
while q:
pass
def sieve():
li=[True]*(2*(10**5)+5)
li[0],li[1]=False,False
for i in range(2,len(li),1):
if li[i]==True:
for j in range(i*i,len(li),i):
li[j]=False
prime=[]
for i in range((2*(10**5)+5)):
if li[i]==True:
prime.append(i)
return prime
def setBit(n):
count=0
while n!=0:
n=n&(n-1)
count+=1
return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
spf[1]=1
for i in range(2,mx+1):
if spf[i]==mx:
spf[i]=i
for j in range(i*i,mx+1,i):
if i<spf[j]:
spf[j]=i
return
def readTree(n,e): # to read tree
adj=[set() for i in range(n+1)]
for i in range(e):
u1,u2=IP()
adj[u1].add(u2)
return adj
#####################################################################################
mod=10**9+7
def solve():
a=II()
s=input()
li=[int(i) for i in s]
n=len(li)
pref=[li[0]]+[0]*(n-1)
for i in range(1,n):
pref[i]=pref[i-1]+li[i]
pref.insert(0,0)
d={}
for i in range(1,n+1):
for j in range(i,n+1):
val=pref[j]-pref[i-1]
d[val]=d.get(val,0)+1
ans=0
if a!=0:
for ele in d:
if ele!=0:
if a%ele==0 and a//ele in d:
ans+=d[ele]*d[a//ele]
else:
cnt=d.get(0,0)
ans=2*cnt*((n*(n+1))//2)-cnt**2
P(ans)
return
t=1
for i in range(t):
solve()
#######
#
#
####### # # # #### # # #
# # # # # # # # # # #
# #### # # #### #### # #
###### # # #### # # # # #
``` | output | 1 | 95,621 | 23 | 191,243 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40 | instruction | 0 | 95,622 | 23 | 191,244 |
Tags: combinatorics, data structures, implementation
Correct Solution:
```
import sys,collections as cc
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
a,=I()
s=list(map(int,[i for i in input().strip()]))
d=cc.Counter([])
n=len(s)
for i in range(1,n+1):
su=sum(s[:i])
for j in range(i,n):
d[su]+=1
su=su-s[j-i]+s[j]
d[su]+=1
an=0
if a==0:
an=(n*(n+1)//2)**2
del d[0]
xx=sum(d.values())
for i in d:
an-=d[i]*(xx)
else:
for i in d.keys():
if i!=0 and a%i==0:
an=an+(d[i]*d[a//i])
print(an)
``` | output | 1 | 95,622 | 23 | 191,245 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40 | instruction | 0 | 95,623 | 23 | 191,246 |
Tags: combinatorics, data structures, implementation
Correct Solution:
```
import sys
from math import gcd,sqrt,ceil,log2
from collections import defaultdict,Counter,deque
from bisect import bisect_left,bisect_right
import math
sys.setrecursionlimit(2*10**5+10)
import heapq
from itertools import permutations
# input=sys.stdin.readline
# def print(x):
# sys.stdout.write(str(x)+"\n")
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
aa='abcdefghijklmnopqrstuvwxyz'
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")
# import sys
# import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def get_sum(bit,i):
s = 0
i+=1
while i>0:
s+=bit[i]
i-=i&(-i)
return s
def update(bit,n,i,v):
i+=1
while i<=n:
bit[i]+=v
i+=i&(-i)
def modInverse(b,m):
g = math.gcd(b, m)
if (g != 1):
return -1
else:
return pow(b, m - 2, m)
def primeFactors(n):
sa = []
# sa.add(n)
while n % 2 == 0:
sa.append(2)
n = n // 2
for i in range(3,int(math.sqrt(n))+1,2):
while n % i== 0:
sa.append(i)
n = n // i
# sa.add(n)
if n > 2:
sa.append(n)
return sa
def seive(n):
pri = [True]*(n+1)
p = 2
while p*p<=n:
if pri[p] == True:
for i in range(p*p,n+1,p):
pri[i] = False
p+=1
return pri
def check_prim(n):
if n<0:
return False
for i in range(2,int(sqrt(n))+1):
if n%i == 0:
return False
return True
def getZarr(string, z):
n = len(string)
# [L,R] make a window which matches
# with prefix of s
l, r, k = 0, 0, 0
for i in range(1, n):
# if i>R nothing matches so we will calculate.
# Z[i] using naive way.
if i > r:
l, r = i, i
# R-L = 0 in starting, so it will start
# checking from 0'th index. For example,
# for "ababab" and i = 1, the value of R
# remains 0 and Z[i] becomes 0. For string
# "aaaaaa" and i = 1, Z[i] and R become 5
while r < n and string[r - l] == string[r]:
r += 1
z[i] = r - l
r -= 1
else:
# k = i-L so k corresponds to number which
# matches in [L,R] interval.
k = i - l
# if Z[k] is less than remaining interval
# then Z[i] will be equal to Z[k].
# For example, str = "ababab", i = 3, R = 5
# and L = 2
if z[k] < r - i + 1:
z[i] = z[k]
# For example str = "aaaaaa" and i = 2,
# R is 5, L is 0
else:
# else start from R and check manually
l = i
while r < n and string[r - l] == string[r]:
r += 1
z[i] = r - l
r -= 1
def search(text, pattern):
# Create concatenated string "P$T"
concat = pattern + "$" + text
l = len(concat)
z = [0] * l
getZarr(concat, z)
ha = []
for i in range(l):
if z[i] == len(pattern):
ha.append(i - len(pattern) - 1)
return ha
# n,k = map(int,input().split())
# l = list(map(int,input().split()))
#
# n = int(input())
# l = list(map(int,input().split()))
#
# hash = defaultdict(list)
# la = []
#
# for i in range(n):
# la.append([l[i],i+1])
#
# la.sort(key = lambda x: (x[0],-x[1]))
# ans = []
# r = n
# flag = 0
# lo = []
# ha = [i for i in range(n,0,-1)]
# yo = []
# for a,b in la:
#
# if a == 1:
# ans.append([r,b])
# # hash[(1,1)].append([b,r])
# lo.append((r,b))
# ha.pop(0)
# yo.append([r,b])
# r-=1
#
# elif a == 2:
# # print(yo,lo)
# # print(hash[1,1])
# if lo == []:
# flag = 1
# break
# c,d = lo.pop(0)
# yo.pop(0)
# if b>=d:
# flag = 1
# break
# ans.append([c,b])
# yo.append([c,b])
#
#
#
# elif a == 3:
#
# if yo == []:
# flag = 1
# break
# c,d = yo.pop(0)
# if b>=d:
# flag = 1
# break
# if ha == []:
# flag = 1
# break
#
# ka = ha.pop(0)
#
# ans.append([ka,b])
# ans.append([ka,d])
# yo.append([ka,b])
#
# if flag:
# print(-1)
# else:
# print(len(ans))
# for a,b in ans:
# print(a,b)
def mergeIntervals(arr):
# Sorting based on the increasing order
# of the start intervals
arr.sort(key = lambda x: x[0])
# array to hold the merged intervals
m = []
s = -10000
max = -100000
for i in range(len(arr)):
a = arr[i]
if a[0] > max:
if i != 0:
m.append([s,max])
max = a[1]
s = a[0]
else:
if a[1] >= max:
max = a[1]
#'max' value gives the last point of
# that particular interval
# 's' gives the starting point of that interval
# 'm' array contains the list of all merged intervals
if max != -100000 and [s, max] not in m:
m.append([s, max])
return m
class SortedList:
def __init__(self, iterable=[], _load=200):
"""Initialize sorted list instance."""
values = sorted(iterable)
self._len = _len = len(values)
self._load = _load
self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
self._list_lens = [len(_list) for _list in _lists]
self._mins = [_list[0] for _list in _lists]
self._fen_tree = []
self._rebuild = True
def _fen_build(self):
"""Build a fenwick tree instance."""
self._fen_tree[:] = self._list_lens
_fen_tree = self._fen_tree
for i in range(len(_fen_tree)):
if i | i + 1 < len(_fen_tree):
_fen_tree[i | i + 1] += _fen_tree[i]
self._rebuild = False
def _fen_update(self, index, value):
"""Update `fen_tree[index] += value`."""
if not self._rebuild:
_fen_tree = self._fen_tree
while index < len(_fen_tree):
_fen_tree[index] += value
index |= index + 1
def _fen_query(self, end):
"""Return `sum(_fen_tree[:end])`."""
if self._rebuild:
self._fen_build()
_fen_tree = self._fen_tree
x = 0
while end:
x += _fen_tree[end - 1]
end &= end - 1
return x
def _fen_findkth(self, k):
"""Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`)."""
_list_lens = self._list_lens
if k < _list_lens[0]:
return 0, k
if k >= self._len - _list_lens[-1]:
return len(_list_lens) - 1, k + _list_lens[-1] - self._len
if self._rebuild:
self._fen_build()
_fen_tree = self._fen_tree
idx = -1
for d in reversed(range(len(_fen_tree).bit_length())):
right_idx = idx + (1 << d)
if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
idx = right_idx
k -= _fen_tree[idx]
return idx + 1, k
def _delete(self, pos, idx):
"""Delete value at the given `(pos, idx)`."""
_lists = self._lists
_mins = self._mins
_list_lens = self._list_lens
self._len -= 1
self._fen_update(pos, -1)
del _lists[pos][idx]
_list_lens[pos] -= 1
if _list_lens[pos]:
_mins[pos] = _lists[pos][0]
else:
del _lists[pos]
del _list_lens[pos]
del _mins[pos]
self._rebuild = True
def _loc_left(self, value):
"""Return an index pair that corresponds to the first position of `value` in the sorted list."""
if not self._len:
return 0, 0
_lists = self._lists
_mins = self._mins
lo, pos = -1, len(_lists) - 1
while lo + 1 < pos:
mi = (lo + pos) >> 1
if value <= _mins[mi]:
pos = mi
else:
lo = mi
if pos and value <= _lists[pos - 1][-1]:
pos -= 1
_list = _lists[pos]
lo, idx = -1, len(_list)
while lo + 1 < idx:
mi = (lo + idx) >> 1
if value <= _list[mi]:
idx = mi
else:
lo = mi
return pos, idx
def _loc_right(self, value):
"""Return an index pair that corresponds to the last position of `value` in the sorted list."""
if not self._len:
return 0, 0
_lists = self._lists
_mins = self._mins
pos, hi = 0, len(_lists)
while pos + 1 < hi:
mi = (pos + hi) >> 1
if value < _mins[mi]:
hi = mi
else:
pos = mi
_list = _lists[pos]
lo, idx = -1, len(_list)
while lo + 1 < idx:
mi = (lo + idx) >> 1
if value < _list[mi]:
idx = mi
else:
lo = mi
return pos, idx
def add(self, value):
"""Add `value` to sorted list."""
_load = self._load
_lists = self._lists
_mins = self._mins
_list_lens = self._list_lens
self._len += 1
if _lists:
pos, idx = self._loc_right(value)
self._fen_update(pos, 1)
_list = _lists[pos]
_list.insert(idx, value)
_list_lens[pos] += 1
_mins[pos] = _list[0]
if _load + _load < len(_list):
_lists.insert(pos + 1, _list[_load:])
_list_lens.insert(pos + 1, len(_list) - _load)
_mins.insert(pos + 1, _list[_load])
_list_lens[pos] = _load
del _list[_load:]
self._rebuild = True
else:
_lists.append([value])
_mins.append(value)
_list_lens.append(1)
self._rebuild = True
def discard(self, value):
"""Remove `value` from sorted list if it is a member."""
_lists = self._lists
if _lists:
pos, idx = self._loc_right(value)
if idx and _lists[pos][idx - 1] == value:
self._delete(pos, idx - 1)
def remove(self, value):
"""Remove `value` from sorted list; `value` must be a member."""
_len = self._len
self.discard(value)
if _len == self._len:
raise ValueError('{0!r} not in list'.format(value))
def pop(self, index=-1):
"""Remove and return value at `index` in sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
value = self._lists[pos][idx]
self._delete(pos, idx)
return value
def bisect_left(self, value):
"""Return the first index to insert `value` in the sorted list."""
pos, idx = self._loc_left(value)
return self._fen_query(pos) + idx
def bisect_right(self, value):
"""Return the last index to insert `value` in the sorted list."""
pos, idx = self._loc_right(value)
return self._fen_query(pos) + idx
def count(self, value):
"""Return number of occurrences of `value` in the sorted list."""
return self.bisect_right(value) - self.bisect_left(value)
def __len__(self):
"""Return the size of the sorted list."""
return self._len
def __getitem__(self, index):
"""Lookup value at `index` in sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
return self._lists[pos][idx]
def __delitem__(self, index):
"""Remove value at `index` from sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
self._delete(pos, idx)
def __contains__(self, value):
"""Return true if `value` is an element of the sorted list."""
_lists = self._lists
if _lists:
pos, idx = self._loc_left(value)
return idx < len(_lists[pos]) and _lists[pos][idx] == value
return False
def __iter__(self):
"""Return an iterator over the sorted list."""
return (value for _list in self._lists for value in _list)
def __reversed__(self):
"""Return a reverse iterator over the sorted list."""
return (value for _list in reversed(self._lists) for value in reversed(_list))
def __repr__(self):
"""Return string representation of sorted list."""
return 'SortedList({0})'.format(list(self))
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 sol(n):
seti = set()
for i in range(1,int(sqrt(n))+1):
if n%i == 0:
seti.add(n//i)
seti.add(i)
return seti
def lcm(a,b):
return (a*b)//gcd(a,b)
#
# n,p = map(int,input().split())
#
# s = input()
#
# if n <=2:
# if n == 1:
# pass
# if n == 2:
# pass
# i = n-1
# idx = -1
# while i>=0:
# z = ord(s[i])-96
# k = chr(z+1+96)
# flag = 1
# if i-1>=0:
# if s[i-1]!=k:
# flag+=1
# else:
# flag+=1
# if i-2>=0:
# if s[i-2]!=k:
# flag+=1
# else:
# flag+=1
# if flag == 2:
# idx = i
# s[i] = k
# break
# if idx == -1:
# print('NO')
# exit()
# for i in range(idx+1,n):
# if
#
def moore_voting(l):
count1 = 0
count2 = 0
first = 10**18
second = 10**18
n = len(l)
for i in range(n):
if l[i] == first:
count1+=1
elif l[i] == second:
count2+=1
elif count1 == 0:
count1+=1
first = l[i]
elif count2 == 0:
count2+=1
second = l[i]
else:
count1-=1
count2-=1
for i in range(n):
if l[i] == first:
count1+=1
elif l[i] == second:
count2+=1
if count1>n//3:
return first
if count2>n//3:
return second
return -1
def dijkstra(n,tot,hash):
hea = [[0,n]]
dis = [10**18]*(tot+1)
dis[n] = 0
boo = defaultdict(bool)
while hea:
a,b = heapq.heappop(hea)
if boo[b]:
continue
boo[b] = True
for i,w in hash[b]:
if dis[b]+w<dis[i]:
dis[i] = dis[b]+w
heapq.heappush(hea,[dis[i],i])
return dis
def find_parent(u,parent):
if u!=parent[u]:
parent[u] = find_parent(parent[u],parent)
return parent[u]
def dis_union(n):
par = [i for i in range(n+1)]
rank = [1]*(n+1)
k = int(input())
for i in range(k):
a,b = map(int,input().split())
z1,z2 = find_parent(a,par),find_parent(b,par)
if z1!=z2:
par[z1] = z2
rank[z2]+=rank[z1]
a = int(input())
l = list(input())
n = int(len(l))
hash = defaultdict(int)
for i in range(n):
tot = 0
for j in range(i,n):
tot+=int(l[j])
hash[tot]+=1
ans = 0
if a == 0:
ans+=hash[0]*hash[0]
for i in hash:
if not i:
continue
ans+=hash[0]*hash[i]*2
print(ans)
exit()
for i in hash:
if i and a%i == 0 and a//i in hash:
ans+=hash[a//i]*hash[i]
print(ans)
``` | output | 1 | 95,623 | 23 | 191,247 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40 | instruction | 0 | 95,624 | 23 | 191,248 |
Tags: combinatorics, data structures, implementation
Correct Solution:
```
from collections import Counter
a=int(input())
string=input()
arr=[0]
count1=0
count2=0
for i in range(len(string)):
arr+=[int(string[i])]
for i in range(1,len(arr)):
arr[i]+=arr[i-1]
#print(arr)
temparr=[]
#sumset.add(arr[0])
for i in range(len(arr)):
for j in range(i+1,len(arr)):
temparr+=[(arr[j]-arr[i])]
sumset=Counter(temparr)
#print(sumset)
possums=0
for i in (sumset):
possums+=sumset[i]
for i in (sumset):
#print(str(i)+"###")
if i!=0 and a%i==0 and i**2!=a:
count1+=sumset[i]*sumset[a//i]
elif i==0 and a==0:
count1+=sumset[i]*possums
elif i!=0 and a%i==0 and i**2==a:
#print(str(i)+"***")
count2+=sumset[i]*sumset[a//i]
print(count1+count2)
``` | output | 1 | 95,624 | 23 | 191,249 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40 | instruction | 0 | 95,625 | 23 | 191,250 |
Tags: combinatorics, data structures, implementation
Correct Solution:
```
sm = [0] * 40000
n = int(input())
s = input()
l = len(s)
for i in range(l):
ss = 0
for j in range(i,l):
ss += int(s[j])
sm[ss] += 1
if n == 0:
ans = 0
for i in range(1,40000):
ans += sm[0] * sm[i] * 2
ans += sm[0]*sm[0]
print(ans)
else:
ans = 0
u = int(n**.5)
for i in range(1,u+1):
if n % i == 0:
if n // i < 40000:
ans += sm[i] * sm[n//i]
ans *= 2
if u ** 2 == n:
ans -= sm[u] ** 2
print(ans)
``` | output | 1 | 95,625 | 23 | 191,251 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40 | instruction | 0 | 95,626 | 23 | 191,252 |
Tags: combinatorics, data structures, implementation
Correct Solution:
```
a=int(input())
s=input()
di = {}
for i in range(len(s)):
total=0
for j in range(i, len(s)):
total += int(s[j])
di[total] = 1 if total not in di else di[total]+1
ans=0
if a==0:
ans=0
if 0 in di:
ans +=di[0]*di[0]
for each in di:
if not each:continue
ans += di[each]*di[0]*2
print(ans)
quit()
for p in di:
if p and a % p == 0 and (a//p) in di:
ans += di[a//p]*di[p]
print(ans)
``` | output | 1 | 95,626 | 23 | 191,253 |
Provide tags and a correct Python 2 solution for this coding contest problem.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40 | instruction | 0 | 95,627 | 23 | 191,254 |
Tags: combinatorics, data structures, implementation
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().strip())
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
a=input()
l=in_arr()
n=len(l)
dp=[0]*(n+1)
for i in range(1,n+1):
dp[i]=dp[i-1]+l[i-1]
d=Counter()
for i in range(n+1):
for j in range(i+1,n+1):
d[dp[j]-dp[i]]+=1
ans=0
if a==0:
ans = ((n*(n+1))/2)*d[0]
#exit()
#ans=0
for i in d:
if i!=0 and a%i==0:
ans+=(d[i]*d[a/i])
pr_num(ans)
``` | output | 1 | 95,627 | 23 | 191,255 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Submitted Solution:
```
from collections import defaultdict
a=int(input())
s=list(input())
n=len(s)
for i in range(n):
s[i]=int(s[i])
cs=[0]+s
for i in range(1,n+1):
cs[i]+=cs[i-1]
cnt=defaultdict(int)
key=set()
for l in range(1,n+1):
for r in range(l,n+1):
cnt[cs[r]-cs[l-1]]+=1
key.add(cs[r]-cs[l-1])
if a==0:
if 0 in cnt:
y=n*(n+1)//2
print(y*cnt[0]+cnt[0]*(y-cnt[0]))
else:
print(0)
exit()
ans=0
for x in key:
if x>0 and a%x==0 and a//x in key:
ans+=cnt[x]*cnt[a//x]
print(ans)
``` | instruction | 0 | 95,628 | 23 | 191,256 |
Yes | output | 1 | 95,628 | 23 | 191,257 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Submitted Solution:
```
def divisors(x):
def f(y, q):
t = -len(r)
while not y % q:
y //= q
for i in range(t, 0):
r.append(r[t] * q)
return y
r, p = [1], 7
x = f(f(f(x, 2), 3), 5)
while x >= p * p:
for s in 4, 2, 4, 2, 4, 6, 2, 6:
if not x % p:
x = f(x, p)
p += s
if x > 1:
f(x, x)
return r
def main():
a, s = int(input()), input()
if not a:
z = sum(x * (x + 1) for x in map(len, s.translate(
str.maketrans('123456789', ' ')).split())) // 2
x = len(s)
print((x * (x + 1) - z) * z)
return
sums, x, cnt = {}, 0, 1
for u in map(int, s):
if u:
sums[x] = cnt
x += u
cnt = 1
else:
cnt += 1
if x * x < a:
print(0)
return
sums[x], u = cnt, a // x
l = [v for v in divisors(a) if v <= x]
z = a // max(l)
d = {x: 0 for x in l if z <= x}
for x in d:
for k, v in sums.items():
u = sums.get(k + x, 0)
if u:
d[x] += v * u
print(sum(u * d[a // x] for x, u in d.items()))
if __name__ == '__main__':
main()
``` | instruction | 0 | 95,629 | 23 | 191,258 |
Yes | output | 1 | 95,629 | 23 | 191,259 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Submitted Solution:
```
def f(t, k):
i, j = 0, 1
s, d = 0, t[0]
n = len(t)
while j <= n:
if d > k:
d -= t[i]
i += 1
elif d == k:
if t[i] and (j == n or t[j]): s += 1
else:
a, b = i - 1, j - 1
while j < n and t[j] == 0: j += 1
while t[i] == 0: i += 1
s += (i - a) * (j - b)
if j < n: d += t[j]
d -= t[i]
i += 1
j += 1
else:
if j < n: d += t[j]
j += 1
return s
s, n = 0, int(input())
t = list(map(int, input()))
if n:
k = sum(t)
if k == 0: print(0)
else:
p = [(i, n // i) for i in range(max(1, n // k), int(n ** 0.5) + 1) if n % i == 0]
for a, b in p:
if a != b: s += 2 * f(t, a) * f(t, b)
else:
k = f(t, a)
s += k * k
print(s)
else:
n = len(t)
m = n * (n + 1)
s = j = 0
while j < n:
if t[j] == 0:
i = j
j += 1
while j < n and t[j] == 0: j += 1
k = ((j - i) * (j - i + 1)) // 2
s += k
j += 1
print((m - s) * s)
``` | instruction | 0 | 95,630 | 23 | 191,260 |
Yes | output | 1 | 95,630 | 23 | 191,261 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Submitted Solution:
```
import sys
import itertools as it
import bisect as bi
import math as mt
import collections as cc
import sys
I=lambda:list(map(int,input().split()))
a,=I()
s=list(input().strip())
n=len(s)
s=[int(s[i]) for i in range(len(s))]
f=cc.defaultdict(int)
for i in range(n):
tem=0
for j in range(i,n):
tem+=s[j]
f[tem]+=1
temp=list(f.keys())
if a==0:
tot=n*(n+1)//2
tot=tot**2
if f[0]:
del f[0]
tem=sum(f.values())
for i in f:
tot-=(tem*f[i])
print(tot)
else:
ans=0
for i in temp:
if i!=0:
if a%i==0:
j=a//i
if f[i]>0 and f[j]>0:
ans+=f[i]*f[j]
print(ans)
``` | instruction | 0 | 95,631 | 23 | 191,262 |
Yes | output | 1 | 95,631 | 23 | 191,263 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Submitted Solution:
```
def f(t, k):
i, j = 0, 1
s, d = 0, t[0]
n = len(t)
while j <= n:
if d > k:
d -= t[i]
i += 1
elif d == k:
if t[i] and (j == n or t[j]): s += 1
else:
a, b = i - 1, j - 1
while j < n and t[j] == 0: j += 1
while t[i] == 0: i += 1
s += (i - a) * (j - b)
if j < n: d += t[j]
d -= t[i]
i += 1
j += 1
else:
if j < n: d += t[j]
j += 1
return s
s, n = 0, int(input())
t = list(map(int, input()))
if n:
k = sum(t)
if k == 0: print(0)
else:
p = [(i, n // i) for i in range(max(1, n // k), int(n ** 0.5) + 1) if n % i == 0]
for a, b in p:
if a != b: s += 2 * f(t, a) * f(t, b)
else:
k = f(t, a)
s += k * k
print(s)
else:
n = len(t)
m = n * (n + 1)
s = j = 0
while j < n:
if t[j] == 0:
i = j
j += 1
while j < n and t[j] == 0: j += 1
k = ((j - i) * (j - i + 1)) // 2
s += (m - k) * k
j += 1
print(s)
``` | instruction | 0 | 95,632 | 23 | 191,264 |
No | output | 1 | 95,632 | 23 | 191,265 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Submitted Solution:
```
a = int(input())
s = input()
if a == 0:
c = []
t = 0
for i in range(len(s)):
if s[i] == '0':
t += 1
else:
if t != 0:
c.append(t)
t = 0
if t != 0:
c.append(t)
r = 1
for f in c:
r *= (f*(f+1))//2
print(r)
else:
sm ={}
for i in range(len(s)):
for j in range(i,len(s)):
if j== i:
t = int(s[j])
else:
t += int(s[j])
if t in sm:
sm[t] += 1
else:
sm[t] = 1
c = 0
for f in sm:
if f != 0 and a % f == 0 and (a//f) in sm:
c += sm[f] * sm[a//f]
print(c)
``` | instruction | 0 | 95,633 | 23 | 191,266 |
No | output | 1 | 95,633 | 23 | 191,267 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Submitted Solution:
```
a=int(input())
b=[int(i) for i in input()]+[0]
n=len(b)-1
f=0
for k in range(1,int(a**0.5)+1):
if a%k==0:
d=e=0
i,j=0,-1
c=0
while j<n:
if c<k:
j+=1
c+=b[j]
elif c==k:
d+=1
j+=1
c+=b[j]
else:
c-=b[i]
i+=1
i,j=0,-1
c=0
while j<n:
if c<a//k:
j+=1
c+=b[j]
elif c==a//k:
e+=1
j+=1
c+=b[j]
else:
c-=b[i]
i+=1
f+=d*e
if k!=a//k:
f+=d*e
print(f)
``` | instruction | 0 | 95,634 | 23 | 191,268 |
No | output | 1 | 95,634 | 23 | 191,269 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.
A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.
Input
The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).
Output
Print a single integer — the answer to a problem.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40
Submitted Solution:
```
from math import *
#from bisect import *
#from collections import *
#from random import *
#from decimal import *"""
#from heapq import *
#from random import *
import sys
input=sys.stdin.readline
#sys.setrecursionlimit(3*(10**5))
global flag
def inp():
return int(input())
def st():
return input().rstrip('\n')
def lis():
return list(map(int,input().split()))
def ma():
return map(int,input().split())
t=1
def pos(su,le):
if(su>=0 and su<=(9*le)):
return 1
return 0
while(t):
t-=1
a=inp()
s=st()
di={}
for i in range(len(s)):
su=0
for j in range(i,len(s)):
su+=int(s[j])
try:
di[su]+=1
except:
di[su]=1
co=0
for i in di.keys():
if(a==0 and i==0):
co+=di[0]*((len(s)*(len(s)+1))//2)*2
co-=di[0]*di[0]
if(i and a%i==0 and (a//i) in di and a):
co+=di[i]*di[a//i]
if(a==0):
if(0 in di):
co+=(di[0]*di[0] -1 )//2
print(co)
``` | instruction | 0 | 95,635 | 23 | 191,270 |
No | output | 1 | 95,635 | 23 | 191,271 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
Output
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Examples
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2 | instruction | 0 | 95,637 | 23 | 191,274 |
Tags: brute force, geometry, implementation, math
Correct Solution:
```
def pitagoras(k):
casos_possiveis = []
for n in range(1,k):
m = int((k**2 - n**2)**(0.5))
if((n**2 + m**2) == k**2):
casos_possiveis.append([n, m])
return casos_possiveis
def possivelRepresntar(k):
for n in range(1, k):
m = int((k**2 - n**2)**(0.5))
if ((n ** 2 + m ** 2) == k ** 2):
return True
def tangentes(v):
tangentes = []
for p in v:
tangente = p[0]/p[1]
tangentes.append(tangente)
return tangentes
def vetorSemRepeticao(v1, v2):
v = []
v3 = v1 + v2
for p in v3:
if(p not in v):
v.append(p)
return v
def vetorUtil(v1, v2):
v_util = []
v3 = vetorSemRepeticao(v1,v2)
for vx in v3:
if(vx in v1 and vx in v2):
v_util.append(vx)
return v_util
def td_diferente(a,b,c,x,y,z):
if(a!=b and a!=c and b!=c and x!=y and x!=z and y!=z):
return True
else:
return False
a , b = input().split()
a = int(a)
b = int(b)
deu_certo = False
e3 = 0
e4 = 0
e5 = 0
if(possivelRepresntar(a) and possivelRepresntar(b)):
p1 = pitagoras(a)
p2 = pitagoras(b)
t1 = tangentes(pitagoras(a))
t2 = tangentes(pitagoras(b))
t_util = vetorUtil(t1, t2)
if(len(t_util) != 0):
for case in t_util:
caso = case
e1 = p1[(t1.index(caso))]
e2 = p2[(t2.index(1/caso))]
e4 = [0 ,e1[0]]
e5 = [e1[1],0]
e3 = [e1[1]+e2[1], e2[0]]
if(td_diferente(e3[0],e4[0],e5[0],e3[1],e4[1],e5[1])):
deu_certo = True
print("YES")
print("{} {}".format(e3[0], e3[1]))
print("{} {}".format(e4[0], e4[1]))
print("{} {}".format(e5[0], e5[1]))
break
if(not deu_certo):
print("NO")
else:
print("NO")
else:
print("NO")
``` | output | 1 | 95,637 | 23 | 191,275 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
Output
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Examples
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2 | instruction | 0 | 95,638 | 23 | 191,276 |
Tags: brute force, geometry, implementation, math
Correct Solution:
```
import math
def square(a):
lis=[]
for k in range(a+1):
if math.sqrt(a**2-k **2)==int(math.sqrt(a**2-k **2)):
lis.append((k,int(math.sqrt(a**2-k **2))))
return lis
def check(a):
boo=1
if len(square(a))==2 and int(math.sqrt(a))==math.sqrt(a):
boo=0
return boo
a,b=input().split()
a=int(a)
b=int(b)
if check(a)*check(b)==0:
print('NO')
else:
v=0
lisA=[]
lisB=[]
lisa=square(a)
lisb=square(b)
lisa.remove((a,0))
lisa.remove((0,a))
lisb.remove((b,0))
lisb.remove((0,b))
for A in lisa:
for B in lisb:
if A[0]*B[0]-A[1]*B[1]==0 and A[1]!=B[1]:
v=1
lisA.append(A)
lisB.append(B)
if v==1:
print('YES')
print(0,0)
print(-int(lisA[0][0]),int(lisA[0][1]))
print(int(lisB[0][0]),int(lisB[0][1]))
else:
print('NO')
``` | output | 1 | 95,638 | 23 | 191,277 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
Output
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Examples
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2 | instruction | 0 | 95,639 | 23 | 191,278 |
Tags: brute force, geometry, implementation, math
Correct Solution:
```
# Made By Mostafa_Khaled
bot = True
a,b=map(int,input().split())
def get(a):
return list([i,j] for i in range(1,a) for j in range(1,a) if i*i+j*j==a*a)
A=get(a)
B=get(b)
for [a,b] in A:
for [c,d] in B:
if a*c==b*d and b!=d:
print("YES\n0 0\n%d %d\n%d %d" %(-a,b,c,d))
exit(0)
print("NO")
# Made By Mostafa_Khaled
``` | output | 1 | 95,639 | 23 | 191,279 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
Output
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Examples
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2 | instruction | 0 | 95,640 | 23 | 191,280 |
Tags: brute force, geometry, implementation, math
Correct Solution:
```
a, b = input().strip().split()
a, b = int(a), int(b)
import math
import functools
@functools.lru_cache(None)
def check(a):
ans = set()
for i in range(1, a):
for j in range(i, a):
if i ** 2 + j ** 2 == a ** 2:
ans.add((i, j))
ans.add((j, i))
return list(ans)
sq1, sq2 = check(a), check(b)
if sq1 and sq2:
# print(sq1, sq2)
for x1, y1 in sq1:
for x2, y2 in sq2:
if (x1 * x2) / (y1 * y2) == 1:
a1, b1 = -x1, y1
a2, b2 = x2, y2
if not (a1 == a2 or b1 == b2):
print('YES')
print(a1, b1)
print(0, 0)
print(a2, b2)
import sys
sys.exit()
elif (x1 * y2) / (x2 * y1) == 1:
a1, b1 = -x1, y1
a2, b2 = y2, x2
if not (a1 == a2 or b1 == b2):
print('YES')
print(a1, b1)
print(0, 0)
print(a2, b2)
import sys
sys.exit()
print('NO')
else:
print('NO')
``` | output | 1 | 95,640 | 23 | 191,281 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
Output
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Examples
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2 | instruction | 0 | 95,641 | 23 | 191,282 |
Tags: brute force, geometry, implementation, math
Correct Solution:
```
a, b = map(int, input().split())
a, b = min(a, b), max(a, b)
for x in range(1, a):
if ((a ** 2 - x ** 2) ** 0.5) % 1 < 10 ** -5:
y = round((a ** 2 - x ** 2) ** 0.5)
if x > 0 and y > 0 and (y * b) % a == 0 and (x * b) % a == 0:
print('YES')
print(0, 0)
print(x, y)
print(y * b // a, -x * b // a)
exit(0)
print('NO')
``` | output | 1 | 95,641 | 23 | 191,283 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
Output
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Examples
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2 | instruction | 0 | 95,642 | 23 | 191,284 |
Tags: brute force, geometry, implementation, math
Correct Solution:
```
a,b=map(int,input().split())
A=[]
B=[]
for x in range(1,a):
y=(a*a-x*x)**.5
if int(y)==y:A.append((x,int(y)))
for x in range(1,b):
y=(b*b-x*x)**.5
if int(y)==y:B.append((-x,int(y)))
for x,y in A:
for c,d in B:
if (x-c)**2+(y-d)**2==a*a+b*b:
if y==d or x==c:c=-c;d=-d
if y==d or x==c:c=-c;d=-d;continue
print('YES\n0 0\n'+str(x),y,'\n'+str(c),d);exit()
print('NO')
``` | output | 1 | 95,642 | 23 | 191,285 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
Output
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Examples
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2 | instruction | 0 | 95,643 | 23 | 191,286 |
Tags: brute force, geometry, implementation, math
Correct Solution:
```
a,b = list(map(int,input().split()))
t = a*a
for x in range(-a,a+1):
y = t-(x**2)
z = int(y**0.5)
if z*z==y:
y = z
# print(x,y)
if x!=0 and y!=0:
den = x**2 + y**2
num = b*y
z = int(den**0.5)
if z*z==den:
den = z
if num%den==0:
x1 = num//den
num = x*x1
den = y
if num%den==0:
y1 = num//den
y1 = -y1
if y1-y!=0:
print("YES")
print(0,0)
print(x,y)
print(x1,y1)
exit()
y = -z
if x!=0 and y!=0:
den = x**2 + y**2
num = b*y
z = int(den**0.5)
if z*z==den:
if num%den==0:
x1 = num//den
num = x*x1
den = y
if num%den==0:
y1 = num//den
y1 = -y1
if y1-y!=0:
print("YES")
print(0,0)
print(x,y)
print(x1,y1)
exit()
print("NO")
``` | output | 1 | 95,643 | 23 | 191,287 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
Output
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Examples
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2 | instruction | 0 | 95,644 | 23 | 191,288 |
Tags: brute force, geometry, implementation, math
Correct Solution:
```
a,b=map(int,input().split())
x1=0
x2=0
for x1 in range(1,a):
for x2 in range(1,b):
i=(a*a-x1*x1)**0.5
if int(i)==i:
j=(b*b-x2*x2)**0.5
if int(j)==j:
if i!=j and (-x2-x1)**2+(i-j)**2==a*a+b*b:
print('YES')
print(0,0)
print(x1,int(i))
print(-x2,int(j))
exit(0)
print('NO')
``` | output | 1 | 95,644 | 23 | 191,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
Output
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Examples
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2
Submitted Solution:
```
a, b = map(int, input().split())
for x in range(1, b):
y = (b * b - x * x) ** 0.5
if y != int(y): continue
y = int(y)
if (a * y) % b or (a * x) % b: continue
if -(a * y) // b == x or (a * x) // b == y: continue
print("YES")
print(0, 0)
print(x, y)
print(-(a * y) // b, (a * x) // b)
exit()
print("NO")
``` | instruction | 0 | 95,645 | 23 | 191,290 |
Yes | output | 1 | 95,645 | 23 | 191,291 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
Output
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Examples
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2
Submitted Solution:
```
a,b=map(int,input().split(" "))
lia,lib=[],[]
for i in range(1,a):
for j in range(1,a):
if i*i + j*j == a*a:
lia.append([i,j])
fl=0
ans="NO"
for i in range(1,b):
for j in range(1,b):
if i*i + j*j == b*b:
lib.append([i,j])
for [a,b] in lia:
for [c,d] in lib:
if a*c==b*d and b!=d:
fl=1
ans="YES"
break
if fl==1:
break
print(ans)
if fl==1:
print(0,0)
print(-a,b)
print(c,d)
``` | instruction | 0 | 95,646 | 23 | 191,292 |
Yes | output | 1 | 95,646 | 23 | 191,293 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
Output
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Examples
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2
Submitted Solution:
```
def pitagoras(k):
casos_possiveis = []
for n in range(1,k):
m = int((k**2 - n**2)**(0.5))
if((n**2 + m**2) == k**2):
casos_possiveis.append([n, m])
return casos_possiveis
def possivelRepresntar(k):
for n in range(1, k):
m = int((k**2 - n**2)**(0.5))
if ((n ** 2 + m ** 2) == k ** 2):
return True
def tangentes(v):
tangentes = []
for p in v:
tangente = p[0]/p[1]
tangentes.append(tangente)
return tangentes
def vetorSemRepeticao(v1, v2):
v = []
v3 = v1 + v2
for p in v3:
if(p not in v):
v.append(p)
return v
def vetorUtil(v1, v2):
v_util = []
v3 = vetorSemRepeticao(v1,v2)
for vx in v3:
if(vx in v1 and vx in v2):
v_util.append(vx)
return v_util
def td_diferente(a,b,c,x,y,z):
if(a!=b and a!=c and b!=c and x!=y and x!=z and y!=z):
return True
else:
return False
a , b = input().split()
a = int(a)
b = int(b)
deu_certo = False
e3 = 0
e4 = 0
e5 = 00
if(possivelRepresntar(a) and possivelRepresntar(b)):
p1 = pitagoras(a)
p2 = pitagoras(b)
t1 = tangentes(pitagoras(a))
t2 = tangentes(pitagoras(b))
t_util = vetorUtil(t1, t2)
if(len(t_util) != 0):
for case in t_util:
caso = case
e1 = p1[(t1.index(caso))]
e2 = p2[(t2.index(1/caso))]
e4 = [0 ,e1[0]]
e5 = [e1[1],0]
e3 = [e1[1]+e2[1], e2[0]]
if(td_diferente(e3[0],e4[0],e5[0],e3[1],e4[1],e5[1])):
deu_certo = True
print("YES")
print("{} {}".format(e3[0], e3[1]))
print("{} {}".format(e4[0], e4[1]))
print("{} {}".format(e5[0], e5[1]))
break
if(not deu_certo):
print("NO")
else:
print("NO")
else:
print("NO")
``` | instruction | 0 | 95,647 | 23 | 191,294 |
Yes | output | 1 | 95,647 | 23 | 191,295 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
Output
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Examples
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2
Submitted Solution:
```
def dist(a, b):
return (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2
a, b = map(int, input().split())
pnt_a, pnt_b = [], []
for i in range(1, 1000):
j = 1
while j*j + i*i <= 1000000:
if i*i + j*j == a*a: pnt_a.append((i, j))
if i*i + j*j == b*b: pnt_b.append((-i, j))
j += 1
for i in pnt_a:
for j in pnt_b:
if i[1] != j[1] and dist(i, j) == a*a + b*b:
print("YES")
print("0 0")
print(i[0], i[1])
print(j[0], j[1])
exit()
print("NO")
``` | instruction | 0 | 95,648 | 23 | 191,296 |
Yes | output | 1 | 95,648 | 23 | 191,297 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
Output
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Examples
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2
Submitted Solution:
```
import math
a,b=map(int,input().split())
alpha=b/a
c=0
for i in range(1,a):
if math.floor(math.sqrt(a**2)-(i**2))-(math.sqrt(a**2)-(i**2))==0:
c=i
if c==0:
print("NO")
else:
print("YES")
print(0,0)
print(str(int(c))+" "+str(int(math.sqrt((a**2)-(c**2)))))
print(str(int(alpha*(math.sqrt((a**2)-(c**2)))))+" "+str(int(-(alpha*c))))
``` | instruction | 0 | 95,649 | 23 | 191,298 |
No | output | 1 | 95,649 | 23 | 191,299 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
Output
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Examples
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2
Submitted Solution:
```
#!/usr/bin/python3 -SOO
from math import sqrt,sin,cos,asin
a,b = map(int,input().strip().split())
for i in range(1,a):
x = a*a - i*i
if x<=0 or int(sqrt(x) + 0.5)**2 != x: continue
t = asin(i/a)
u = b*sin(t)
v = b*cos(t)
if abs(u-int(u)) < 0.0005 and abs(v-int(v)) < 0.0005:
print('YES')
print('0 0')
print('%d %d'%(-int(u),-int(v)))
print('%d %d'%(int(sqrt(x)),i))
break
else:
print('NO')
``` | instruction | 0 | 95,650 | 23 | 191,300 |
No | output | 1 | 95,650 | 23 | 191,301 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
Output
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Examples
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2
Submitted Solution:
```
'''input
10 15
'''
# practicing a skill right after sleep improves it a lot quickly
from sys import stdin, setrecursionlimit
import math
def check(num):
return math.sqrt(num) == int(math.sqrt(num))
def pythagoreanTriplets():
mydict = dict()
for i in range(1, 1001):
for j in range(1, 1001):
num = i ** 2 + j ** 2
if check(num):
mydict[int(math.sqrt(num))] = str(i) + ' ' + str(j)
return mydict
# main starts
mydict = pythagoreanTriplets()
a, b = list(map(int, stdin.readline().split()))
if a in mydict and b in mydict:
print("YES")
a_f, a_s = list(map(int, mydict[a].split()))
b_f, b_s = list(map(int, mydict[b].split()))
print(0, a_s)
print(a_f, 0)
if b_f/b_s == a_f/a_s:
print(b_s, a_s + b_f)
else:
print(b_f, a_s + b_s)
else:
print("NO")
``` | instruction | 0 | 95,651 | 23 | 191,302 |
No | output | 1 | 95,651 | 23 | 191,303 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
Output
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Examples
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2
Submitted Solution:
```
def isquare(n):
h = n
l = 1
while h-l>1:
m = (h+l)//2
if m*m<=n:
l = m
elif m*m>n:
h = m
return l
a,b = map(int,input().split())
p,q,r,s = -1,-1,-1,-1
for i in range(3,a):
if isquare(a*a-i*i)**2==a*a-i*i:
p,q = i,isquare(a*a-i*i)
break
for i in range(3,b):
if isquare(b*b-i*i)**2==b*b-i*i:
r,s = i,isquare(b*b-i*i)
break
if p==-1 or q==-1 or r==-1 or s==-1:
print("NO")
else:
if p*r==q*s:
print("YES\n",0,0,'\n',p,q,'\n',-r,s)
elif p*s==q*r:
print("YES\n",0,0,'\n',p,q,'\n',-s,r)
else:
print("NO")
``` | instruction | 0 | 95,652 | 23 | 191,304 |
No | output | 1 | 95,652 | 23 | 191,305 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.