message stringlengths 2 57.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 61 108k | cluster float64 22 22 | __index_level_0__ int64 122 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m there is at least one element of this color;
* each element is colored and colored exactly one color;
* the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color.
Note that equal elements can be colored different colors β you just have to choose one of m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 11.
Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases. Then the descriptions of the test cases follow.
The first line of the test case contains a single integer n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11.
Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1).
Example
Input
3
3
6 10 15
2
4 9
23
437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961
Output
1
1 1 1
2
2 1
11
4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case.
In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
Submitted Solution:
```
t=int(input())
r=[3,5,7,11,13,17,19,23,29,31]
while(t):
t-=1
n=int(input())
a=list(map(int,input().split()))
ind={2:1}
cc=1
r1=[1]*n
for i in range(n):
if(a[i]%2==0):
continue
for j in range(10):
if(a[i]%r[j]==0):
if(r[j] not in ind):
ind[r[j]]=cc+1
cc+=1
r1[i]=cc
break
c=set()
for i in r1:
c.add(i)
print(max(r1))
print(*r1)
``` | instruction | 0 | 102,170 | 22 | 204,340 |
No | output | 1 | 102,170 | 22 | 204,341 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m there is at least one element of this color;
* each element is colored and colored exactly one color;
* the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color.
Note that equal elements can be colored different colors β you just have to choose one of m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 11.
Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases. Then the descriptions of the test cases follow.
The first line of the test case contains a single integer n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11.
Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1).
Example
Input
3
3
6 10 15
2
4 9
23
437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961
Output
1
1 1 1
2
2 1
11
4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case.
In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
Submitted Solution:
```
def prime_factors(n):
i = 2
factors = []
while i * i <= n:
if n % i:
i += 1
else:
n //= i
factors.append(i)
if n > 1:
factors.append(n)
return factors
t = input() #Number of tests
for i in range(int(t)):
n = input() #Number of numbers in this test
n = int(n)
a_list_string = input()
a_list = a_list_string.split(" ")
a_list = [int(j) for j in a_list]
prime_list = [prime_factors(k) for k in a_list]
#print(prime_list)
color_dict = dict()
for i in range(1,12):
color_dict[i] = set()
color_map = []
for i in range(len(prime_list)):
c = 0
for color in range(1, 12):
if len(color_dict[color]) == 0:
c = color
else:
for prime in prime_list[i]:
if prime in color_dict[color]:
c = color
break
if c != 0: #color found
color_map.append(c)
color_dict[color].update(prime_list[i])
break
tot = 0
for entry in color_dict:
if len(color_dict[entry]) != 0:
tot += 1
s = " ".join(str(x) for x in color_map)
print(tot)
print(s)
#print(color_dict)
``` | instruction | 0 | 102,171 | 22 | 204,342 |
No | output | 1 | 102,171 | 22 | 204,343 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.
Alice is given a sequence of n composite numbers a_1,a_2,β¦,a_n.
She wants to choose an integer m β€ 11 and color each element one of m colors from 1 to m so that:
* for each color from 1 to m there is at least one element of this color;
* each element is colored and colored exactly one color;
* the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color.
Note that equal elements can be colored different colors β you just have to choose one of m colors for each of the indices from 1 to n.
Alice showed already that if all a_i β€ 1000 then she can always solve the task by choosing some m β€ 11.
Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases. Then the descriptions of the test cases follow.
The first line of the test case contains a single integer n (1 β€ n β€ 1000) β the amount of numbers in a sequence a.
The second line of the test case contains n composite integers a_1,a_2,β¦,a_n (4 β€ a_i β€ 1000).
It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.
Output
For each test case print 2 lines. The first line should contain a single integer m (1 β€ m β€ 11) β the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 β€ c_i β€ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11.
Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1).
Example
Input
3
3
6 10 15
2
4 9
23
437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961
Output
1
1 1 1
2
2 1
11
4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6
Note
In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case.
In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.
Submitted Solution:
```
import math,sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda:int(input())
li = lambda:list(map(int,input().split()))
def case():
n=I()
a=li()
primes=[2, 3, 5, 7, 11, 13, 17, 19, 23, 27, 29, 31]
pri=[]
for i in a:
for j in primes:
if i%j==0 :
pri.append(j)
break
print(len(set(pri)))
print(*pri)
for _ in range(int(input())):
case()
``` | instruction | 0 | 102,172 | 22 | 204,344 |
No | output | 1 | 102,172 | 22 | 204,345 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A Pythagorean triple is a triple of integer numbers (a, b, c) such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to a, b and c, respectively. An example of the Pythagorean triple is (3, 4, 5).
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: c = a^2 - b.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple (3, 4, 5): 5 = 3^2 - 4, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers (a, b, c) with 1 β€ a β€ b β€ c β€ n such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
Input
The first line contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
Each test case consists of one line containing one integer n (1 β€ n β€ 10^9).
Output
For each test case, print one integer β the number of triples of integers (a, b, c) with 1 β€ a β€ b β€ c β€ n such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
Example
Input
3
3
6
9
Output
0
1
1
Note
The only Pythagorean triple satisfying c = a^2 - b with 1 β€ a β€ b β€ c β€ 9 is (3, 4, 5); that's why the answer for n = 3 is 0, and the answer for n = 6 (and for n = 9) is 1. | instruction | 0 | 102,269 | 22 | 204,538 |
Tags: binary search, brute force, math, number theory
Correct Solution:
```
import io,os, math
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# python3 15.py<in>op
t = int(input())
for _ in range(t):
n = int(input())
ans = 0
i = 3
while((((i*i) + 1)//2) <=n):
ans+=1
i+=2
print(ans)
``` | output | 1 | 102,269 | 22 | 204,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A Pythagorean triple is a triple of integer numbers (a, b, c) such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to a, b and c, respectively. An example of the Pythagorean triple is (3, 4, 5).
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: c = a^2 - b.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple (3, 4, 5): 5 = 3^2 - 4, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers (a, b, c) with 1 β€ a β€ b β€ c β€ n such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
Input
The first line contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
Each test case consists of one line containing one integer n (1 β€ n β€ 10^9).
Output
For each test case, print one integer β the number of triples of integers (a, b, c) with 1 β€ a β€ b β€ c β€ n such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
Example
Input
3
3
6
9
Output
0
1
1
Note
The only Pythagorean triple satisfying c = a^2 - b with 1 β€ a β€ b β€ c β€ 9 is (3, 4, 5); that's why the answer for n = 3 is 0, and the answer for n = 6 (and for n = 9) is 1. | instruction | 0 | 102,270 | 22 | 204,540 |
Tags: binary search, brute force, math, number theory
Correct Solution:
```
import math
t=int(input())
for _ in range (t):
n=int(input())
count=-1
k=1
i=1
z=int(math.sqrt(((n-1)/2)+0.25)-0.5)
print(z)
``` | output | 1 | 102,270 | 22 | 204,541 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A Pythagorean triple is a triple of integer numbers (a, b, c) such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to a, b and c, respectively. An example of the Pythagorean triple is (3, 4, 5).
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: c = a^2 - b.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple (3, 4, 5): 5 = 3^2 - 4, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers (a, b, c) with 1 β€ a β€ b β€ c β€ n such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
Input
The first line contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
Each test case consists of one line containing one integer n (1 β€ n β€ 10^9).
Output
For each test case, print one integer β the number of triples of integers (a, b, c) with 1 β€ a β€ b β€ c β€ n such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
Example
Input
3
3
6
9
Output
0
1
1
Note
The only Pythagorean triple satisfying c = a^2 - b with 1 β€ a β€ b β€ c β€ 9 is (3, 4, 5); that's why the answer for n = 3 is 0, and the answer for n = 6 (and for n = 9) is 1. | instruction | 0 | 102,271 | 22 | 204,542 |
Tags: binary search, brute force, math, number theory
Correct Solution:
```
import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input():
return sys.stdin.readline().rstrip("\r\n")
def isPrime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i = i + 6
return True
def SieveOfEratosthenes(n):
prime = []
primes = [True for i in range(n + 1)]
p = 2
while p * p <= n:
if primes[p] == True:
prime.append(p)
for i in range(p * p, n + 1, p):
primes[i] = False
p += 1
return prime
def primefactors(n):
fac = []
while n % 2 == 0:
fac.append(2)
n = n // 2
for i in range(3, int(math.sqrt(n)) + 2):
while n % i == 0:
fac.append(i)
n = n // i
if n > 1:
fac.append(n)
return sorted(fac)
def factors(n):
fac = set()
fac.add(1)
fac.add(n)
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
fac.add(i)
fac.add(n // i)
return list(fac)
def modInverse(a, m):
m0 = m
y = 0
x = 1
if m == 1:
return 0
while a > 1:
q = a // m
t = m
m = a % m
a = t
t = y
y = x - q * y
x = t
if x < 0:
x = x + m0
return x
# ------------------------------------------------------code
for _ in range(int(input())):
n = int(input())
count = 0
i=3
while(i*i<=2*n-1):
count+=1
i+=2
print(count)
``` | output | 1 | 102,271 | 22 | 204,543 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A Pythagorean triple is a triple of integer numbers (a, b, c) such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to a, b and c, respectively. An example of the Pythagorean triple is (3, 4, 5).
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: c = a^2 - b.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple (3, 4, 5): 5 = 3^2 - 4, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers (a, b, c) with 1 β€ a β€ b β€ c β€ n such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
Input
The first line contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
Each test case consists of one line containing one integer n (1 β€ n β€ 10^9).
Output
For each test case, print one integer β the number of triples of integers (a, b, c) with 1 β€ a β€ b β€ c β€ n such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
Example
Input
3
3
6
9
Output
0
1
1
Note
The only Pythagorean triple satisfying c = a^2 - b with 1 β€ a β€ b β€ c β€ 9 is (3, 4, 5); that's why the answer for n = 3 is 0, and the answer for n = 6 (and for n = 9) is 1. | instruction | 0 | 102,272 | 22 | 204,544 |
Tags: binary search, brute force, math, number theory
Correct Solution:
```
import math
for i in range(int(input())):
n=int(input())
print(math.floor(((math.sqrt(2*n-1)+1)//2)-1))
``` | output | 1 | 102,272 | 22 | 204,545 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A Pythagorean triple is a triple of integer numbers (a, b, c) such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to a, b and c, respectively. An example of the Pythagorean triple is (3, 4, 5).
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: c = a^2 - b.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple (3, 4, 5): 5 = 3^2 - 4, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers (a, b, c) with 1 β€ a β€ b β€ c β€ n such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
Input
The first line contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
Each test case consists of one line containing one integer n (1 β€ n β€ 10^9).
Output
For each test case, print one integer β the number of triples of integers (a, b, c) with 1 β€ a β€ b β€ c β€ n such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
Example
Input
3
3
6
9
Output
0
1
1
Note
The only Pythagorean triple satisfying c = a^2 - b with 1 β€ a β€ b β€ c β€ 9 is (3, 4, 5); that's why the answer for n = 3 is 0, and the answer for n = 6 (and for n = 9) is 1. | instruction | 0 | 102,273 | 22 | 204,546 |
Tags: binary search, brute force, math, number theory
Correct Solution:
```
t=int(input())
for i in range(t):
n=int(input())
m=int(pow(2*n-1,0.5))
ans=(m+1)//2
print(ans-1)
``` | output | 1 | 102,273 | 22 | 204,547 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A Pythagorean triple is a triple of integer numbers (a, b, c) such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to a, b and c, respectively. An example of the Pythagorean triple is (3, 4, 5).
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: c = a^2 - b.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple (3, 4, 5): 5 = 3^2 - 4, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers (a, b, c) with 1 β€ a β€ b β€ c β€ n such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
Input
The first line contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
Each test case consists of one line containing one integer n (1 β€ n β€ 10^9).
Output
For each test case, print one integer β the number of triples of integers (a, b, c) with 1 β€ a β€ b β€ c β€ n such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
Example
Input
3
3
6
9
Output
0
1
1
Note
The only Pythagorean triple satisfying c = a^2 - b with 1 β€ a β€ b β€ c β€ 9 is (3, 4, 5); that's why the answer for n = 3 is 0, and the answer for n = 6 (and for n = 9) is 1. | instruction | 0 | 102,274 | 22 | 204,548 |
Tags: binary search, brute force, math, number theory
Correct Solution:
```
t=int(input())
for i in range(t):
n=int(input())
m=int((2*n-1)**(1/2))
k=int((m-1)/2)
print(k)
``` | output | 1 | 102,274 | 22 | 204,549 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A Pythagorean triple is a triple of integer numbers (a, b, c) such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to a, b and c, respectively. An example of the Pythagorean triple is (3, 4, 5).
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: c = a^2 - b.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple (3, 4, 5): 5 = 3^2 - 4, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers (a, b, c) with 1 β€ a β€ b β€ c β€ n such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
Input
The first line contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
Each test case consists of one line containing one integer n (1 β€ n β€ 10^9).
Output
For each test case, print one integer β the number of triples of integers (a, b, c) with 1 β€ a β€ b β€ c β€ n such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
Example
Input
3
3
6
9
Output
0
1
1
Note
The only Pythagorean triple satisfying c = a^2 - b with 1 β€ a β€ b β€ c β€ 9 is (3, 4, 5); that's why the answer for n = 3 is 0, and the answer for n = 6 (and for n = 9) is 1. | instruction | 0 | 102,275 | 22 | 204,550 |
Tags: binary search, brute force, math, number theory
Correct Solution:
```
import sys
input = sys.stdin.readline
t=int(input())
for _ in range(t):
n=int(input())
i=3
ans=0
#print(i*i-1)
while i<=n and ((i*i-1)//2)<=n:
#print('ads',_)
if (i*i-1)%2==0 and (i*i-1)//2>=i and i*i-(i*i-1)//2<=n:
#print(i,(i*i-1)//2)
ans+=1
i+=1
print(ans)
``` | output | 1 | 102,275 | 22 | 204,551 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A Pythagorean triple is a triple of integer numbers (a, b, c) such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to a, b and c, respectively. An example of the Pythagorean triple is (3, 4, 5).
Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: c = a^2 - b.
Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple (3, 4, 5): 5 = 3^2 - 4, so, according to Vasya's formula, it is a Pythagorean triple.
When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers (a, b, c) with 1 β€ a β€ b β€ c β€ n such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.
Input
The first line contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
Each test case consists of one line containing one integer n (1 β€ n β€ 10^9).
Output
For each test case, print one integer β the number of triples of integers (a, b, c) with 1 β€ a β€ b β€ c β€ n such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.
Example
Input
3
3
6
9
Output
0
1
1
Note
The only Pythagorean triple satisfying c = a^2 - b with 1 β€ a β€ b β€ c β€ 9 is (3, 4, 5); that's why the answer for n = 3 is 0, and the answer for n = 6 (and for n = 9) is 1. | instruction | 0 | 102,276 | 22 | 204,552 |
Tags: binary search, brute force, math, number theory
Correct Solution:
```
def answer(n):
l=int(((2*n)-1)**0.5)
c=0
for i in range(3,l+1,2):
c+=1
print(c)
t=int(input())
for i in range(t):
n=int(input())
answer(n)
``` | output | 1 | 102,276 | 22 | 204,553 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 β€ b β€ n; 0 β€ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 β€ x, y, n β€ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2 | instruction | 0 | 102,351 | 22 | 204,702 |
Tags: brute force, implementation, two pointers
Correct Solution:
```
"""
Author - Satwik Tiwari .
19th Jan , 2021 - Tuesday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
# from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
# from itertools import *
from heapq import *
from math import gcd, factorial,floor,ceil,sqrt,log2
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
#==============================================================================================
#fast I/O region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
#===============================================================================================
#some shortcuts
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var)) #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def testcase(t):
for pp in range(t):
solve(pp)
def google(p):
print('Case #'+str(p)+': ',end='')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(x, y, p) :
y%=(p-1) #not so sure about this. used when y>p-1. if p is prime.
res = 1 # Initialize result
x = x % p # Update x if it is more , than or equal to p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) : # If y is odd, multiply, x with result
res = (res * x) % p
y = y >> 1 # y = y/2
x = (x * x) % p
return res
def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))
def isPrime(n) :
if (n <= 1) : return False
if (n <= 3) : return True
if (n % 2 == 0 or n % 3 == 0) : return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
inf = pow(10,21)
mod = 10**9+7
#===============================================================================================
# code here ;))
def bucketsort(order, seq):
buckets = [0] * (max(seq) + 1)
for x in seq:
buckets[x] += 1
for i in range(len(buckets) - 1):
buckets[i + 1] += buckets[i]
new_order = [-1] * len(seq)
for i in reversed(order):
x = seq[i]
idx = buckets[x] = buckets[x] - 1
new_order[idx] = i
return new_order
def ordersort(order, seq, reverse=False):
bit = max(seq).bit_length() >> 1
mask = (1 << bit) - 1
order = bucketsort(order, [x & mask for x in seq])
order = bucketsort(order, [x >> bit for x in seq])
if reverse:
order.reverse()
return order
def long_ordersort(order, seq):
order = ordersort(order, [int(i & 0x7fffffff) for i in seq])
return ordersort(order, [int(i >> 31) for i in seq])
def multikey_ordersort(order, *seqs, sort=ordersort):
for i in reversed(range(len(seqs))):
order = sort(order, seqs[i])
return order
def solve(case):
x,y,n = sep()
mn = inf
for i in range(1,n+1):
temp = int((i*x)/y)
l = lcm(i,y)
# print(temp,i,y,l)
# if(temp > 0):
mn = min(mn,round(abs(x*(l//y) - temp*(l//i))/l,18))
# print(abs(x*(l//y) - temp*(l//i)),'==')
mn = min(mn,round(abs(x*(l//y) - (temp+1)*(l//i))/l,18))
# print(abs(x*(l//y) - (temp+1)*(l//i)))
# print(i,round(abs(x*(l//y) - temp*(l//i))/l,18),round(abs(x*(l//y) - (temp+1)*(l//i)),18))
ll = []
rr = []
for i in range(1,n+1):
temp = ((i*x)//y)
l = lcm(i,y)
if(round(abs(x*(l//y) - temp*(l//i))/l,18) == mn):
ll.append(i); rr.append(temp)
if(round(abs(x*(l//y) - (temp+1)*(l//i))/l,18) == mn):
ll.append(i); rr.append(temp+1)
order = multikey_ordersort(range(len(ll)),ll,rr)
# print(ll)
# print(rr)
print(rr[order[0]],end='/')
print(ll[order[0]])
testcase(1)
# testcase(int(inp()))
``` | output | 1 | 102,351 | 22 | 204,703 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 β€ b β€ n; 0 β€ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 β€ x, y, n β€ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2 | instruction | 0 | 102,352 | 22 | 204,704 |
Tags: brute force, implementation, two pointers
Correct Solution:
```
from fractions import Fraction
x,y,n=map(int,input().split())
ans=Fraction(x,y).limit_denominator(n)
num=ans.numerator
denom=ans.denominator
print (str(num) + '/' + str(denom))
``` | output | 1 | 102,352 | 22 | 204,705 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 β€ b β€ n; 0 β€ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 β€ x, y, n β€ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2 | instruction | 0 | 102,353 | 22 | 204,706 |
Tags: brute force, implementation, two pointers
Correct Solution:
```
from fractions import Fraction
x, y, n = input().split()
x = int(x)
y = int(y)
n = int(n)
if Fraction(x / y).limit_denominator(n) == 0:
print('0/1')
elif Fraction(x / y).limit_denominator(n) == int(Fraction(x, y).limit_denominator(n)):
print(str(Fraction(x, y).limit_denominator(n)) + '/1')
else:
if (2 * Fraction(x, y) - Fraction(x / y).limit_denominator(n)).denominator > y:
print(Fraction(x / y).limit_denominator(n))
else:
a= 2 * Fraction(x, y) - Fraction(x / y).limit_denominator(n)
print(str(a.numerator)+"/"+str(a.denominator))
``` | output | 1 | 102,353 | 22 | 204,707 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 β€ b β€ n; 0 β€ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 β€ x, y, n β€ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2 | instruction | 0 | 102,354 | 22 | 204,708 |
Tags: brute force, implementation, two pointers
Correct Solution:
```
class Fraction:
def __init__(self, x, y):
self.x = x
self.y = y
def __sub__(self, a):
return Fraction(self.x * a.y - a.x * self.y, self.y * a.y)
def __lt__(self, a):
return self.x * a.y < self.y * a.x
def __abs__(self):
if self.x < 0:
return Fraction(-self.x, self.y)
return self
def __str__(self):
return str(self.x) + '/' + str(self.y)
x, y, n = map(int, input().split())
f = Fraction(x, y)
dif = None
for i in range(1, n + 1):
m = x * i // y
for d in [m, m + 1]:
g = Fraction(d, i)
if dif is None or abs(f - g) < dif:
dif = abs(f - g)
ans = g
print(ans)
``` | output | 1 | 102,354 | 22 | 204,709 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 β€ b β€ n; 0 β€ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 β€ x, y, n β€ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2 | instruction | 0 | 102,355 | 22 | 204,710 |
Tags: brute force, implementation, two pointers
Correct Solution:
```
from fractions import Fraction as frac
a, b, n = map(int, input().split())
f = frac(a, b).limit_denominator(n)
print(str(f.numerator)+'/'+str(f.denominator))
``` | output | 1 | 102,355 | 22 | 204,711 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 β€ b β€ n; 0 β€ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 β€ x, y, n β€ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2 | instruction | 0 | 102,356 | 22 | 204,712 |
Tags: brute force, implementation, two pointers
Correct Solution:
```
"""
Author : co_devil Chirag Garg
Institute : JIIT
"""
from __future__ import division, print_function
from sys import stdin,stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil,floor,log,sqrt,factorial,pow,pi,gcd
# from bisect import bisect_left,bisect_right
# from decimal import *,threading
from fractions import Fraction
"""from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
else:
from builtins import str as __str__
str = lambda x=b'': x if type(x) is bytes else __str__(x).encode()
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._buffer = BytesIO()
self._fd = file.fileno()
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):
return self._buffer.read() if self._buffer.tell() else os.read(self._fd, os.fstat(self._fd).st_size)
def readline(self):
while self.newlines == 0:
b, ptr = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)), self._buffer.tell()
self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
self.newlines += b.count(b'\n') + (not b)
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)
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b'\r\n')
def print(*args, **kwargs):
sep, file = kwargs.pop('sep', b' '), kwargs.pop('file', sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop('end', b'\n'))
if kwargs.pop('flush', False):
file.flush()
"""
def ii(): return int(input())
def si(): return str(input())
def mi(): return map(int,input().split())
def li(): return list(mi())
def fii(): return int(stdin.readline())
def fsi(): return str(stdin.readline())
def fmi(): return map(int,stdin.readline().split())
def fli(): return list(fmi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12,
'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24,
'z': 25}
mod = 1000000007
dx, dy = [-1, 1, 0, 0], [0, 0, 1, -1]
def getKey(item): return item[0]
def sort2(l): return sorted(l, key=getKey)
def d2(n, m, num): return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo(x): return (x and (not (x & (x - 1))))
def decimalToBinary(n): return bin(n).replace("0b", "")
def ntl(n): return [int(i) for i in str(n)]
def powerMod(x, y, p):
res = 1
x %= p
while y > 0:
if y & 1:
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
def gcd(x, y):
while y:
x, y = y, x % y
return x
# For getting input from input.txt file
# sys.stdin = open('input.txt', 'r')
# Printing the Output to output.txt file
# sys.stdout = open('output.txt', 'w')
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000
def dfs(v, c):
if visited[v]:
if col[v] != c:
print('-1')
exit()
return
col[v] = c
visited[v] = 1
for i in graph[v]:
dfs(i, c ^ 1)
def bfs(d,v):
q=[]
q.append(v)
visited[v]=1
while len(q)!=0:
x=q[0]
q.pop(0)
for i in d[x]:
if visited[i]!=1:
visited[i]=1
q.append(i)
print(x)
def make_graph(e):
d={}
for i in range(e):
x,y=mi()
if x not in d.keys():
d[x]=[y]
else:
d[x].append(y)
if y not in d.keys():
d[y] = [x]
else:
d[y].append(x)
return d
def gr2(n):
d={}
for i in range(n):
x,y=mi()
if x not in d.keys():
d[x]=[y]
else:
d[x].append(y)
return d
def connected_components(graph):
seen = set()
def dfs(v):
vs = set([v])
component=[]
while vs:
v = vs.pop()
seen.add(v)
vs |= set(graph[v]) - seen
component.append(v)
return component
ans=[]
for v in graph:
if v not in seen:
d=dfs(v)
ans.append(d)
return ans
def primeFactors(n):
s=set()
while n % 2 == 0:
s.add(2)
n = n // 2
for i in range(3, int(sqrt(n)) + 1, 2):
while n % i == 0:
s.add(i)
n = n // i
if n > 2:
s.add(n)
return s
a,b,n=mi()
a=Fraction(a, b).limit_denominator(n)
print(a.numerator,a.denominator,sep='/')
``` | output | 1 | 102,356 | 22 | 204,713 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 β€ b β€ n; 0 β€ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 β€ x, y, n β€ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2 | instruction | 0 | 102,357 | 22 | 204,714 |
Tags: brute force, implementation, two pointers
Correct Solution:
```
import sys
s = input()
all = s.split()
ans = "lol"
n = int(all[2])
x = float(all[0])
y = float(all[1])
a = 0
b = 1
dif = x / y
for i in range(1, n + 1):
#print(str(a) + " : " + str(b) + " : " + str(dif))
na = int((x * i) / y)
if (dif > (abs(x * i - na * y) / (y * i))):
a = na
b = i
dif = abs(x * i - na * y) / (y * i)
na = na + 1
if (dif > (abs(x * i - na * y) / (y * i))):
a = na
b = i
dif = abs(x * i - na * y) / (y * i)
#print(str(a) + " : " + str(b) + " : " + str(dif))
ans = str(a) + "/" + str(b)
#print (a / b)
print(ans)
``` | output | 1 | 102,357 | 22 | 204,715 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 β€ b β€ n; 0 β€ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 β€ x, y, n β€ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2 | instruction | 0 | 102,358 | 22 | 204,716 |
Tags: brute force, implementation, two pointers
Correct Solution:
```
def gcd(a, b):
return gcd(b % a, a) if a else b
x, y, n = map(int, input().split())
d = gcd(x, y)
x, y = x // d, y // d
if n < y:
d = [min(i, y - i) for i in ((x * i) % y for i in range(0, n + 1))]
for i in range(n - 1, 0, -1):
if d[i] < d[n] and n * d[i] <= i * d[n]: n = i
print(str((x * n) // y + int(2 * ((x * n) % y) > y)) + '/' + str(n))
else: print(str(x) + '/' + str(y))
``` | output | 1 | 102,358 | 22 | 204,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 β€ b β€ n; 0 β€ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 β€ x, y, n β€ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Submitted Solution:
```
import math
x, y, n = map(int, input().split())
best = 0, 0
mingap = 10**9
eps = 1e-15
for i in range(1, n+1):
m = (i*x)/y
m1 = math.floor(m)
m2 = math.ceil(m)
gap1 = abs(x/y - m1/i)
gap2 = abs(x/y - m2/i)
if gap1<mingap-eps:
mingap = gap1
best = m1, i
if gap2<mingap-eps:
mingap = gap2
best = m2, i
print(*best, sep='/')
``` | instruction | 0 | 102,361 | 22 | 204,722 |
Yes | output | 1 | 102,361 | 22 | 204,723 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 β€ b β€ n; 0 β€ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 β€ x, y, n β€ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Submitted Solution:
```
from fractions import Fraction
x, y, n = input().split()
x = int(x)
y = int(y)
n = int(n)
if Fraction(x, y) == int(Fraction(x, y)):
print(str(Fraction(x, y)) + '/1')
else:
print(Fraction(x/y).limit_denominator(n))
``` | instruction | 0 | 102,365 | 22 | 204,730 |
No | output | 1 | 102,365 | 22 | 204,731 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 β€ b β€ n; 0 β€ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 β€ x, y, n β€ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Submitted Solution:
```
from fractions import Fraction
x, y, n = input().split()
x = int(x)
y = int(y)
n = int(n)
if Fraction(x / y).limit_denominator(n) ==0:
print('0/1')
elif Fraction(x / y).limit_denominator(n) == int(Fraction(x, y).limit_denominator(n)):
print(str(Fraction(x, y).limit_denominator(n)) + '/1')
else:
print(Fraction(x / y).limit_denominator(n))== int(Fraction(x, y))
``` | instruction | 0 | 102,366 | 22 | 204,732 |
No | output | 1 | 102,366 | 22 | 204,733 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a matrix a of size n Γ m consisting of integers.
You can choose no more than \leftβm/2\rightβ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 β€ n, m, k β€ 70) β the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 β€ a_{i, j} β€ 70).
Output
Print one integer β the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24. | instruction | 0 | 103,085 | 22 | 206,170 |
Tags: dp
Correct Solution:
```
n, m, k = map(int, input().split())
# a = []
# for _ in range(n):
# a.append(list(map(int, input().split())))
dp = [float("-inf") for i in range(k)]
dp[0] = 0
sz = m // 2
for _ in range(n):
a = list(map(int, input().split()))
pre = dp
dp = [[float("-inf") for _ in range(k)] for _ in range(sz + 1)]
dp[0] = pre
for x in a:
for i in range(sz, 0, -1):
for j in range(k):
dp[i][j] = max(dp[i][j], dp[i - 1][((j - x) % k + k) % k] + x)
for i in range(1, sz + 1):
for j in range(k):
dp[0][j]=max(dp[0][j], dp[i][j])
dp = dp[0]
print(dp[0])
``` | output | 1 | 103,085 | 22 | 206,171 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a matrix a of size n Γ m consisting of integers.
You can choose no more than \leftβm/2\rightβ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 β€ n, m, k β€ 70) β the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 β€ a_{i, j} β€ 70).
Output
Print one integer β the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24. | instruction | 0 | 103,086 | 22 | 206,172 |
Tags: dp
Correct Solution:
```
import sys,math,itertools
from collections import Counter,deque,defaultdict
from bisect import bisect_left,bisect_right
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def IND(i,j):
return i*K + j
def ind(i,j,k):
return i*(m//2+1)*K + j*K + k
n,m,K = inpl()
DP = [0] * (K*(n+1))
for i in range(n):
dp = [0] * (K*(m//2+1)*(m+1))
a = inpl()
for j,x in enumerate(a):
for cnt in range(m//2):
for mo in range(K):
dp[ind(j+1,cnt,mo)] = dp[ind(j,cnt,mo)]
for cnt in range(m//2):
for mo in range(K):
now = dp[ind(j,cnt,mo)]
dp[ind(j+1,cnt+1,(now+x)%K)] = max(dp[ind(j,cnt+1,(now+x)%K)], dp[ind(j+1,cnt+1,(now+x)%K)], now+x)
for mo in range(K):
mx = 0
for j in range(m+1):
for cnt in range(m//2+1):
mx = max(dp[ind(j,cnt,mo)], mx)
for mm in range(K):
if DP[IND(i,mm)]%K != mm: continue
now = DP[IND(i,mm)]
DP[IND(i+1,(now+mx)%K)] = max(DP[IND(i,(now+mx)%K)],DP[IND(i+1,(now+mx)%K)], now+mx)
print(DP[IND(n,0)])
``` | output | 1 | 103,086 | 22 | 206,173 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a matrix a of size n Γ m consisting of integers.
You can choose no more than \leftβm/2\rightβ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 β€ n, m, k β€ 70) β the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 β€ a_{i, j} β€ 70).
Output
Print one integer β the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24. | instruction | 0 | 103,087 | 22 | 206,174 |
Tags: dp
Correct Solution:
```
from math import inf as _inf
import sys as _sys
_NEGATIVE_INF = -_inf
def main():
n, m, k = _read_ints()
a = tuple(tuple(_read_ints()) for i_row in range(n))
result = find_max_sum(a, k)
print(result)
def _read_line():
result = _sys.stdin.readline()
assert result[-1] == "\n"
return result[:-1]
def _read_ints():
return map(int, _read_line().split())
def find_max_sum(matrix, k):
selections_n = len(matrix[0]) // 2
rows_maximums = tuple(map(lambda row: _find_seq_maximums(row, selections_n, k), matrix))
cache = [[None] * k for i_row in range(len(matrix) + 1)]
cache[len(matrix)][0] = 0
for remainder_need in range(1, k):
cache[len(matrix)][remainder_need] = _NEGATIVE_INF
def _f_matrix(i_row, remainder_need):
cached_value = cache[i_row][remainder_need]
if cached_value is not None:
return cached_value
result = _NEGATIVE_INF
for remainder, maximum in rows_maximums[i_row].items():
potential_result = maximum + _f_matrix(i_row + 1, (remainder_need - remainder) % k)
if potential_result > result:
result = potential_result
cache[i_row][remainder_need] = result
return result
return _f_matrix(0, 0)
def _find_seq_maximums(seq, selections_n, k):
cache = [None] * (len(seq) + 1)
for i in range(len(cache)):
cache_for_i = [None] * k
for remainder_need in range(k):
cache_for_i[remainder_need] = [None] * (selections_n + 1)
cache[i] = cache_for_i
for i in range(len(seq) + 1):
cache[i][0][0] = 0
for remainder_need in range(1, k):
cache[i][remainder_need][0] = _NEGATIVE_INF
for can_select in range(selections_n + 1):
cache[len(seq)][0][can_select] = 0
for remainder_need in range(1, k):
cache[len(seq)][remainder_need][can_select] = _NEGATIVE_INF
for i in reversed(range(len(seq))):
for remainder_need in range(k):
for can_select in range(1, selections_n + 1):
skip_result = cache[i + 1][remainder_need][can_select]
take_result = seq[i] + cache[i + 1][(remainder_need - seq[i]) % k][can_select - 1]
if take_result > skip_result:
result = take_result
else:
result = skip_result
cache[i][remainder_need][can_select] = result
result = dict()
for remainder in range(k):
maximum = cache[0][remainder][selections_n]
if maximum > _NEGATIVE_INF:
result[remainder] = maximum
return result
if __name__ == '__main__':
main()
``` | output | 1 | 103,087 | 22 | 206,175 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a matrix a of size n Γ m consisting of integers.
You can choose no more than \leftβm/2\rightβ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 β€ n, m, k β€ 70) β the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 β€ a_{i, j} β€ 70).
Output
Print one integer β the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24. | instruction | 0 | 103,088 | 22 | 206,176 |
Tags: dp
Correct Solution:
```
n, m, k = map(int, input().split())
l = m // 2
p = [-1] * k
p[0] = 0
for _ in range(n):
t = [[-1] * (l + 1) for i in range(k)]
t[0][0] = 0
for q in map(int, input().split()):
for j in range(l - 1, -1, -1):
for i in range(k):
if t[i][j] != -1:
d = (i + q) % k
if t[d][j + 1] < t[i][j] + q:
t[d][j + 1] = t[i][j] + q
r = [-1] * k
for i in range(k):
q = max(t[i])
if q == -1:
continue
for j in range(k):
if p[j] == -1:
continue
d = (i + j) % k
if r[d] < p[j] + q:
r[d] = p[j] + q
p = r
print(p[0])
``` | output | 1 | 103,088 | 22 | 206,177 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a matrix a of size n Γ m consisting of integers.
You can choose no more than \leftβm/2\rightβ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 β€ n, m, k β€ 70) β the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 β€ a_{i, j} β€ 70).
Output
Print one integer β the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24. | instruction | 0 | 103,089 | 22 | 206,178 |
Tags: dp
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
def main():
n, m, k = getints()
m //= 2
dp = [int(-1e9)] * k
dp[0] = 0
for _ in range(n):
tmp = [[int(-1e9)] * (m + 1) for _ in range(k)]
tmp[0][0] = 0
for a in getints():
for x in range(m - 1, -1, -1):
for y in range(k):
col = (y + a) % k
tmp[col][x + 1] = max(tmp[col][x + 1], tmp[y][x] + a)
ndp = [int(-1e9)] * k
for x in range(k):
tmp[x][0] = max(tmp[x])
for y in range(k):
nxt = (x + y) % k
ndp[nxt] = max(ndp[nxt], dp[y] + tmp[x][0])
dp = ndp
print(dp[0])
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint1(): return list(map(lambda x: int(x) - 1, input().split()))
# endregion
if __name__ == "__main__":
main()
``` | output | 1 | 103,089 | 22 | 206,179 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a matrix a of size n Γ m consisting of integers.
You can choose no more than \leftβm/2\rightβ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 β€ n, m, k β€ 70) β the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 β€ a_{i, j} β€ 70).
Output
Print one integer β the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24. | instruction | 0 | 103,090 | 22 | 206,180 |
Tags: dp
Correct Solution:
```
import sys
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 k in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for k in range(c)] for k 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**19
MOD = 10**9 + 7
EPS = 10**-10
N, M, K = MAP()
MX = 70
dp = list4d(N+1, M+1, M//2+1, K, -1)
dp[0][0][0][0] = 0
for i in range(N):
row = LIST()
for j in range(M):
for k in range(M//2+1):
for l in range(K):
if dp[i][j][k][l] != -1:
dp[i][j+1][k][l] = max(dp[i][j+1][k][l], dp[i][j][k][l])
if k+1 <= M//2:
dp[i][j+1][k+1][(l+row[j])%K] = max(dp[i][j+1][k+1][(l+row[j])%K], dp[i][j][k][l] + row[j])
for k in range(M//2+1):
for l in range(K):
dp[i+1][0][0][l] = max(dp[i+1][0][0][l], dp[i][M][k][l])
ans = dp[N][0][0][0]
print(ans)
``` | output | 1 | 103,090 | 22 | 206,181 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a matrix a of size n Γ m consisting of integers.
You can choose no more than \leftβm/2\rightβ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 β€ n, m, k β€ 70) β the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 β€ a_{i, j} β€ 70).
Output
Print one integer β the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24. | instruction | 0 | 103,091 | 22 | 206,182 |
Tags: dp
Correct Solution:
```
n, m, k = map(int, input().split())
dp = [-10000000000 for i in range(k)]
dp[0] = 0
sz = m//2
mat = []
for i in range(n):
mat.append(list(map(int,input().split())))
for a in mat:
pre = dp
dp = [[-10000000000 for i in range(k)] for j in range(sz+1)]
dp[0] = pre
for x in a:
for i in range(sz,0,-1):
for j in range(k):
dp[i][j] = max(dp[i][j], dp[i-1][((j-x)%k+k)%k] + x)
for i in range(1,sz+1):
for j in range(k):
dp[0][j]=max(dp[0][j], dp[i][j])
dp = dp[0]
print(dp[0])
``` | output | 1 | 103,091 | 22 | 206,183 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a matrix a of size n Γ m consisting of integers.
You can choose no more than \leftβm/2\rightβ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 β€ n, m, k β€ 70) β the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 β€ a_{i, j} β€ 70).
Output
Print one integer β the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24. | instruction | 0 | 103,092 | 22 | 206,184 |
Tags: dp
Correct Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def main():
n,m,k = map(int,input().split())
arr = [list(map(int,input().split())) for _ in range(n)]
dp = [[[0]*k for _ in range(m//2+1)]for _ in range(n)]
for i in range(n):
for j in range(m):
for r in range(min(m//2+1,j+2)-1,0,-1):
for x in range(k):
y = arr[i][j]+dp[i][r-1][x]
dp[i][r][y%k] = max(dp[i][r][y%k],y)
if i != n-1:
for xx in range(k):
for yy in range(m//2+1):
dp[i+1][0][xx] = max(dp[i+1][0][xx],dp[i][yy][xx])
a = 0
for i in range(m//2+1):
a = max(a,dp[-1][i][0])
print(a)
#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == '__main__':
main()
``` | output | 1 | 103,092 | 22 | 206,185 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a matrix a of size n Γ m consisting of integers.
You can choose no more than \leftβm/2\rightβ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 β€ n, m, k β€ 70) β the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 β€ a_{i, j} β€ 70).
Output
Print one integer β the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24.
Submitted Solution:
```
n, m, k = map(int, input().split())
# a = []
# for _ in range(n):
# a.append(list(map(int, input().split())))
pre = [float("-inf") for i in range(k)]
pre[0] = 0
sz = m // 2
for _ in range(n):
a = list(map(int, input().split()))
dp = [[float("-inf") for _ in range(k)] for _ in range(sz + 1)]
dp[0] = pre
for x in a:
for i in range(sz, 0, -1):
for j in range(k):
dp[i][j] = max(dp[i][j], dp[i - 1][(j - x) % k] + x)
for i in range(1, sz + 1):
for j in range(k):
dp[0][j] = max(dp[0][j], dp[i][j])
pre = dp[0]
print(pre[0])
``` | instruction | 0 | 103,093 | 22 | 206,186 |
Yes | output | 1 | 103,093 | 22 | 206,187 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a matrix a of size n Γ m consisting of integers.
You can choose no more than \leftβm/2\rightβ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 β€ n, m, k β€ 70) β the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 β€ a_{i, j} β€ 70).
Output
Print one integer β the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24.
Submitted Solution:
```
import copy
def get_h(data, n, k):
h = []
for _ in range(k):
h.append([0] * (n + 1))
hh = copy.deepcopy(h)
for v in data:
for j in range(1, n + 1):
for i in range(k):
t = (h[i][j - 1] + v) % k
tt = (i + v) % k
if t == tt:
hh[t][j] = max(hh[t][j], h[i][j - 1] + v)
hh, h = h, hh
for j in range(0, n + 1):
for i in range(k):
hh[i][j] = h[i][j]
#print(hh, h)
return [max(t) for t in h]
n, m, k = list(map(int, input().split()))
bh = [0] * k
tbh = [0] * k
for _ in range(n):
data = list(map(int, input().split()))
h = get_h(data, m // 2, k)
for t in range(k):
for i in range(k):
j = (t - i + k) % k
if (bh[i] + h[j]) % k == t:
tbh[t] = max(tbh[t], bh[i] + h[j])
bh, tbh = tbh, bh
for i in range(k):
tbh[i] = bh[i]
print(bh[0])
``` | instruction | 0 | 103,094 | 22 | 206,188 |
Yes | output | 1 | 103,094 | 22 | 206,189 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a matrix a of size n Γ m consisting of integers.
You can choose no more than \leftβm/2\rightβ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 β€ n, m, k β€ 70) β the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 β€ a_{i, j} β€ 70).
Output
Print one integer β the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24.
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
def main():
n, m, k = getints()
m //= 2
dp = [int(-1e9)] * k
dp[0] = 0
for _ in range(n):
tmp = [[int(-1e9)] * k for _ in range(m + 1)]
tmp[0][0] = 0
for a in getints():
for x in range(m - 1, -1, -1):
for y in range(k):
col = (y + a) % k
tmp[x + 1][col] = max(tmp[x + 1][col], tmp[x][y] + a)
ndp = [int(-1e9)] * k
for i in range(m + 1):
for x in range(k):
for y in range(k):
nxt = (x + y) % k
ndp[nxt] = max(ndp[nxt], dp[y] + tmp[i][x])
dp = ndp
print(dp[0])
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint1(): return list(map(lambda x: int(x) - 1, input().split()))
# endregion
if __name__ == "__main__":
main()
``` | instruction | 0 | 103,095 | 22 | 206,190 |
Yes | output | 1 | 103,095 | 22 | 206,191 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a matrix a of size n Γ m consisting of integers.
You can choose no more than \leftβm/2\rightβ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 β€ n, m, k β€ 70) β the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 β€ a_{i, j} β€ 70).
Output
Print one integer β the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24.
Submitted Solution:
```
INF = int(1e9)
n, m, k = map(int, input().split())
a = [[] for i in range(n)]
for i in range(n):
for j in map(int, input().split()):
a[i].append(j)
dp = [[[-INF for q in range(k)] for p in range(m+1)] for j in range(m)]
best = [-INF for q in range(k)]
best[0] = 0
for i in range(n):
for j in range(m):
for p in range(m+1):
for q in range(k):
if p > j+1 or p > m//2:
dp[j][p][q] = -INF
elif j == 0:
dp[j][p][q] = max(a[i][j] + best[(q-a[i][j]+k)%k] if p==1 else -INF, best[q])
else:
dp[j][p][q] = max(a[i][j] + dp[j-1][p-1][(q-a[i][j]+k)%k], dp[j-1][p][q])
for q in range(k):
for p in range(m+1):
best[q] = max(best[q], dp[m-1][p][q])
print(best[0])
``` | instruction | 0 | 103,096 | 22 | 206,192 |
Yes | output | 1 | 103,096 | 22 | 206,193 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a matrix a of size n Γ m consisting of integers.
You can choose no more than \leftβm/2\rightβ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 β€ n, m, k β€ 70) β the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 β€ a_{i, j} β€ 70).
Output
Print one integer β the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24.
Submitted Solution:
```
from itertools import permutations
#from fractions import Fraction
from collections import defaultdict
from math import*
import os
import sys
from io import BytesIO, IOBase
from heapq import nlargest
from bisect import*
import copy
import itertools
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
#-------------above part copied-----------------------
n,m,test=map(int,input().split())
arr=[]
ans=0
for i in range(n):
brr=list(map(int,input().split()))
brr.sort(reverse=True)
arr.append(brr)
for i in range(m//2):
ans+=brr[i]
if ans%test==0:
print(ans)
else:
temp=0
for i in range(n):
for j in range(m//2,m):
for k in range((m//2)-1,-1,-1):
if (ans+arr[i][j]-arr[i][k])%test==0:
val = ans+arr[i][j]-arr[i][k]
if val>temp:
temp=val
break
break
print(temp)
``` | instruction | 0 | 103,097 | 22 | 206,194 |
No | output | 1 | 103,097 | 22 | 206,195 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a matrix a of size n Γ m consisting of integers.
You can choose no more than \leftβm/2\rightβ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 β€ n, m, k β€ 70) β the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 β€ a_{i, j} β€ 70).
Output
Print one integer β the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24.
Submitted Solution:
```
n,m,k = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
dp1 = []
for i in range(n):
B = A[i]
temp = [[-1]*(k) for _ in range(m//2+1)]
temp[0][0] = 0
for b in B:
for i in reversed(range(m//2+1)):
if i == m//2:
continue
for j in range(k):
if temp[i][j] != -1:
temp[i+1][(b+j)%k] = max(temp[i+1][(b+j)%k], temp[i][j]+b)
temp2 = [-1]*k
for i in range(m//2+1):
for j in range(k):
temp2[j] = max(temp2[j], temp[i][j])
dp1.append(temp2)
#print(dp1)
dp2 = [[-1]*k for i in range(n+1)]
dp2[0][0] = 0
for i in range(n):
for j in range(k):
for l in range(k):
dp2[i+1][(j+l)%k] = max(dp2[i+1][(j+l)%k], dp2[i][l]+dp1[i][j])
ans = dp2[n][0]
print(ans)
``` | instruction | 0 | 103,098 | 22 | 206,196 |
No | output | 1 | 103,098 | 22 | 206,197 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a matrix a of size n Γ m consisting of integers.
You can choose no more than \leftβm/2\rightβ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 β€ n, m, k β€ 70) β the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 β€ a_{i, j} β€ 70).
Output
Print one integer β the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24.
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 20 21:47:44 2020
@author: Dark Soul
"""
[n,m,k]=list(map(int,input().split()))
mn=[]
ans=0
for i in range(n):
arr=list(map(int,input().split()))
arr.sort(reverse=True)
mn.append(arr)
for j in range(m//2):
ans+=arr[j]
if ans%k==0:
print(ans)
else:
sol=-1
for i in range(n):
dic={}
y=mn[i]
now=[]
nans=0
for j in range(m//2,m):
now.append(y[j])
if len(now)==0:
continue
for j in now:
try:
dic[i]=1
except:
dic[i]=1
for j in now:
if (ans-j)%k==0:
nans=max(nans,ans-j)
try:
dic[k]
nans=max(nans,ans+k)
except:
continue
else:
mynum=ans-j
dorkar=k-(ans%k)
try:
dic[dorkar]
nans=max(nans,ans+dorkar)
except:
continue
sol=max(sol,nans)
print(sol)
``` | instruction | 0 | 103,099 | 22 | 206,198 |
No | output | 1 | 103,099 | 22 | 206,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a matrix a of size n Γ m consisting of integers.
You can choose no more than \leftβm/2\rightβ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by k and this sum is the maximum.
In other words, you can choose no more than a half (rounded down) of elements in each row, you have to find the maximum sum of these elements divisible by k.
Note that you can choose zero elements (and the sum of such set is 0).
Input
The first line of the input contains three integers n, m and k (1 β€ n, m, k β€ 70) β the number of rows in the matrix, the number of columns in the matrix and the value of k. The next n lines contain m elements each, where the j-th element of the i-th row is a_{i, j} (1 β€ a_{i, j} β€ 70).
Output
Print one integer β the maximum sum divisible by k you can obtain.
Examples
Input
3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
Output
24
Input
5 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
3 8 7 1 2
8 4 7 1 6
Output
56
Note
In the first example, the optimal answer is 2 and 4 in the first row, 5 and 2 in the second row and 7 and 4 in the third row. The total sum is 2 + 4 + 5 + 2 + 7 + 4 = 24.
Submitted Solution:
```
import sys
input=sys.stdin.readline
n,m,k=map(int,input().split())
INF=10**6
dp=[-INF]*k
dp[0]=0
for i in range(n):
a=list(map(int,input().split()))
pre=dp[:]
dp=[[-INF]*k for i in range(m//2+1)]
dp[0]=pre[:]
for j in range(m):
for l in range(1,m//2+1)[::-1]:
for h in range(k):
dp[l][h]=max(dp[l][h],dp[l-1][(h-a[j])%k]+a[j])
dp=dp[m//2][:]
print(dp[0])
``` | instruction | 0 | 103,100 | 22 | 206,200 |
No | output | 1 | 103,100 | 22 | 206,201 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Everybody seems to think that the Martians are green, but it turns out they are metallic pink and fat. Ajs has two bags of distinct nonnegative integers. The bags are disjoint, and the union of the sets of numbers in the bags is \{0,1,β¦,M-1\}, for some positive integer M. Ajs draws a number from the first bag and a number from the second bag, and then sums them modulo M.
What are the residues modulo M that Ajs cannot obtain with this action?
Input
The first line contains two positive integer N (1 β€ N β€ 200 000) and M (N+1 β€ M β€ 10^{9}), denoting the number of the elements in the first bag and the modulus, respectively.
The second line contains N nonnegative integers a_1,a_2,β¦,a_N (0 β€ a_1<a_2< β¦< a_N<M), the contents of the first bag.
Output
In the first line, output the cardinality K of the set of residues modulo M which Ajs cannot obtain.
In the second line of the output, print K space-separated integers greater or equal than zero and less than M, which represent the residues Ajs cannot obtain. The outputs should be sorted in increasing order of magnitude. If K=0, do not output the second line.
Examples
Input
2 5
3 4
Output
1
2
Input
4 1000000000
5 25 125 625
Output
0
Input
2 4
1 3
Output
2
0 2
Note
In the first sample, the first bag and the second bag contain \{3,4\} and \{0,1,2\}, respectively. Ajs can obtain every residue modulo 5 except the residue 2: 4+1 β‘ 0, 4+2 β‘ 1, 3+0 β‘ 3, 3+1 β‘ 4 modulo 5. One can check that there is no choice of elements from the first and the second bag which sum to 2 modulo 5.
In the second sample, the contents of the first bag are \{5,25,125,625\}, while the second bag contains all other nonnegative integers with at most 9 decimal digits. Every residue modulo 1 000 000 000 can be obtained as a sum of an element in the first bag and an element in the second bag. | instruction | 0 | 103,697 | 22 | 207,394 |
Tags: hashing, number theory
Correct Solution:
```
import sys
input = sys.stdin.readline
def main():
n, m = map(int, input().split())
a = list(map(int, input().split())) + [0]*500000
ans_S = 0
a[n] = a[0] + m
s = [0]*600600
for i in range(n):
s[i] = a[i + 1] - a[i]
s[n] = -1
for i in range(n):
s[2*n - i] = s[i]
for i in range(2*n + 1, 3*n + 1):
s[i] = s[i - n]
l, r = 0, 0
z = [0]*600600
for i in range(1, 3*n + 1):
if i < r:
z[i] = z[i - l]
while i + z[i] <= 3*n and (s[i + z[i]] == s[z[i]]):
z[i] += 1
if i + z[i] > r:
l = i
r = i + z[i]
ans = []
for i in range(n + 1, 2*n + 1):
if z[i] < n:
continue
ans_S += 1
ans.append((a[0] + a[2*n - i + 1]) % m)
ans.sort()
print(ans_S)
print(*ans)
return
if __name__=="__main__":
main()
``` | output | 1 | 103,697 | 22 | 207,395 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Everybody seems to think that the Martians are green, but it turns out they are metallic pink and fat. Ajs has two bags of distinct nonnegative integers. The bags are disjoint, and the union of the sets of numbers in the bags is \{0,1,β¦,M-1\}, for some positive integer M. Ajs draws a number from the first bag and a number from the second bag, and then sums them modulo M.
What are the residues modulo M that Ajs cannot obtain with this action?
Input
The first line contains two positive integer N (1 β€ N β€ 200 000) and M (N+1 β€ M β€ 10^{9}), denoting the number of the elements in the first bag and the modulus, respectively.
The second line contains N nonnegative integers a_1,a_2,β¦,a_N (0 β€ a_1<a_2< β¦< a_N<M), the contents of the first bag.
Output
In the first line, output the cardinality K of the set of residues modulo M which Ajs cannot obtain.
In the second line of the output, print K space-separated integers greater or equal than zero and less than M, which represent the residues Ajs cannot obtain. The outputs should be sorted in increasing order of magnitude. If K=0, do not output the second line.
Examples
Input
2 5
3 4
Output
1
2
Input
4 1000000000
5 25 125 625
Output
0
Input
2 4
1 3
Output
2
0 2
Note
In the first sample, the first bag and the second bag contain \{3,4\} and \{0,1,2\}, respectively. Ajs can obtain every residue modulo 5 except the residue 2: 4+1 β‘ 0, 4+2 β‘ 1, 3+0 β‘ 3, 3+1 β‘ 4 modulo 5. One can check that there is no choice of elements from the first and the second bag which sum to 2 modulo 5.
In the second sample, the contents of the first bag are \{5,25,125,625\}, while the second bag contains all other nonnegative integers with at most 9 decimal digits. Every residue modulo 1 000 000 000 can be obtained as a sum of an element in the first bag and an element in the second bag.
Submitted Solution:
```
h=lambda:list(map(int,input().split()))
f=h()
bag1=h()
mod=[]
bag2=list(range(0,bag1[0]))
for x in bag1:
for x2 in bag2:
k=(x + x2) % f[1]
if mod.count(k)==0:
mod.append(k)
mod.sort()
out=[]
for x in range(0,f[1]):
if x not in mod:
out.append(x)
print(len(out))
print(out)
``` | instruction | 0 | 103,698 | 22 | 207,396 |
No | output | 1 | 103,698 | 22 | 207,397 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers a_1, a_2, ..., a_n.
For each a_i find its two divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 (where \gcd(a, b) is the greatest common divisor of a and b) or say that there is no such pair.
Input
The first line contains single integer n (1 β€ n β€ 5 β
10^5) β the size of the array a.
The second line contains n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 10^7) β the array a.
Output
To speed up the output, print two lines with n integers in each line.
The i-th integers in the first and second lines should be corresponding divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 or -1 and -1 if there is no such pair. If there are multiple answers, print any of them.
Example
Input
10
2 3 4 5 6 7 8 9 10 24
Output
-1 -1 -1 -1 3 -1 -1 -1 2 2
-1 -1 -1 -1 2 -1 -1 -1 5 3
Note
Let's look at a_7 = 8. It has 3 divisors greater than 1: 2, 4, 8. As you can see, the sum of any pair of divisors is divisible by 2 as well as a_7.
There are other valid pairs of d_1 and d_2 for a_{10}=24, like (3, 4) or (8, 3). You can print any of them. | instruction | 0 | 103,849 | 22 | 207,698 |
Tags: constructive algorithms, math, number theory
Correct Solution:
```
import math
import sys
from collections import deque
from fractions import Fraction
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b: a + b):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
#-------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
#--------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
if a == 1 or n == 0:
return 1
if n % 2 == 0:
s = powm(a, n // 2, m)
return s * s % m
else:
return a * powm(a, n - 1, m) % m
#--------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z
#--------------------------------------------------product----------------------------------------
def product(l):
por=1
for i in range(len(l)):
por*=l[i]
return por
#--------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
# Check if middle element is
# less than or equal to key
if (arr[mid] <= key):
# At least (mid + 1) elements are there
# whose values are less than
# or equal to key
count = mid + 1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
#--------------------------------------------------binary----------------------------------------
def countGreater(arr, n, k):
l = 0
r = n - 1
# Stores the index of the left most element
# from the array which is greater than k
leftGreater = n
# Finds number of elements greater than k
while (l <= r):
m = int(l + (r - l) / 2)
# If mid element is greater than
# k update leftGreater and r
if (arr[m] > k):
leftGreater = m
r = m - 1
# If mid element is less than
# or equal to k update l
else:
l = m + 1
# Return the count of elements
# greater than k
return (n - leftGreater)
#--------------------------------------------------binary----------------------------------------
n=int(input())
l=list(map(int,input().split()))
m=max(l)+1
small=[1]*m
for i in range(2,m):
if small[i]==1:
small[i]=i
for j in range(i*i,m,i):
if small[j]==1:
small[j]=i
ans1=[-1]*n
ans2=[-1]*n
for i in range(n):
t=l[i]
x=small[l[i]]
c=1
while(l[i]%x==0):
l[i]//=x
c*=x
l[i]=t
if c==l[i]:
ans1[i]=-1
ans2[i]=-1
else:
ans1[i]=c
ans2[i]=l[i]//c
print(*ans1,sep=" ")
print(*ans2,sep=" ")
``` | output | 1 | 103,849 | 22 | 207,699 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers a_1, a_2, ..., a_n.
For each a_i find its two divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 (where \gcd(a, b) is the greatest common divisor of a and b) or say that there is no such pair.
Input
The first line contains single integer n (1 β€ n β€ 5 β
10^5) β the size of the array a.
The second line contains n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 10^7) β the array a.
Output
To speed up the output, print two lines with n integers in each line.
The i-th integers in the first and second lines should be corresponding divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 or -1 and -1 if there is no such pair. If there are multiple answers, print any of them.
Example
Input
10
2 3 4 5 6 7 8 9 10 24
Output
-1 -1 -1 -1 3 -1 -1 -1 2 2
-1 -1 -1 -1 2 -1 -1 -1 5 3
Note
Let's look at a_7 = 8. It has 3 divisors greater than 1: 2, 4, 8. As you can see, the sum of any pair of divisors is divisible by 2 as well as a_7.
There are other valid pairs of d_1 and d_2 for a_{10}=24, like (3, 4) or (8, 3). You can print any of them. | instruction | 0 | 103,850 | 22 | 207,700 |
Tags: constructive algorithms, math, number theory
Correct Solution:
```
import math as mt
def sieve(MAXN):
spf = [0 for i in range(MAXN)]
spf[1] = 1
for i in range(2, MAXN):
# marking smallest prime factor
# for every number to be itself.
spf[i] = i
# separately marking spf for
# every even number as 2
for i in range(4, MAXN, 2):
spf[i] = 2
for i in range(3, mt.ceil(mt.sqrt(MAXN))):
# checking if i is prime
if (spf[i] == i):
# marking SPF for all numbers
# divisible by i
for j in range(i * i, MAXN, i):
# marking spf[j] if it is
# not previously marked
if (spf[j] == j):
spf[j] = i
return spf
def getFactorization(x):
ret = list()
while (x != 1):
ret.append(spf[x])
x = x // spf[x]
return ret
# Driver code
# precalculating Smallest Prime Factor
n = int(input())
l = list(map(int,input().split()))
spf = sieve(max(l)+2)
ans1 = []
ans2 = []
for i in range(n):
num = l[i]
sp = spf[num]
while sp==spf[num]:
num = num//sp
if num==1:
ans1.append(-1)
ans2.append(-1)
else:
ans1.append(num)
ans2.append(sp)
print(*ans1)
print(*ans2)
``` | output | 1 | 103,850 | 22 | 207,701 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers a_1, a_2, ..., a_n.
For each a_i find its two divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 (where \gcd(a, b) is the greatest common divisor of a and b) or say that there is no such pair.
Input
The first line contains single integer n (1 β€ n β€ 5 β
10^5) β the size of the array a.
The second line contains n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 10^7) β the array a.
Output
To speed up the output, print two lines with n integers in each line.
The i-th integers in the first and second lines should be corresponding divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 or -1 and -1 if there is no such pair. If there are multiple answers, print any of them.
Example
Input
10
2 3 4 5 6 7 8 9 10 24
Output
-1 -1 -1 -1 3 -1 -1 -1 2 2
-1 -1 -1 -1 2 -1 -1 -1 5 3
Note
Let's look at a_7 = 8. It has 3 divisors greater than 1: 2, 4, 8. As you can see, the sum of any pair of divisors is divisible by 2 as well as a_7.
There are other valid pairs of d_1 and d_2 for a_{10}=24, like (3, 4) or (8, 3). You can print any of them. | instruction | 0 | 103,851 | 22 | 207,702 |
Tags: constructive algorithms, math, number theory
Correct Solution:
```
from sys import stdout, stdin
import os,io
# input = stdin.readline
# input_all = stdin.read
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# input_all = io.BytesIO(os.read(0,os.fstat(0).st_size)).read
def read_int():
return map(int, input().split())
def read_list():
return list(map(int, input().split()))
def print_list(l):
print(' '.join(map(str,l)))
# import heapq as hq
# import bisect as bs
# from collections import deque as dq
# from collections import defaultdict as dc
import math
# from collections import Counter
# f = open('test.py')
# input = f.readline
# input_all = f.read
def getPrimes(n):
if n < 2:
return []
else:
output = [1] * n
output[0],output[1] = 0,0
for i in range(2,int(n**0.5)+1):
if output[i] == 1:
output[i*i:n:i] = [0] * len(output[i*i:n:i])
return [i for i in range(n) if output[i]==1]
primes = getPrimes(3170)
s = set(primes)
n = int(input())
nums = read_list()
r1,r2 = [],[]
for a in nums:
if a&1==0:
while a&1==0:
a>>=1
if a>1:
r1.append(2)
r2.append(a)
else:
r1.append(-1)
r2.append(-1)
else:
tmp = int(math.sqrt(a))
first = -1
for p in primes:
if p>tmp:
break
if a%p==0:
first = p
break
if first==-1:
r1.append(-1)
r2.append(-1)
else:
while a%first==0:
a//=first
if a>1:
r1.append(first)
r2.append(a)
else:
r1.append(-1)
r2.append(-1)
print_list(r1)
print_list(r2)
``` | output | 1 | 103,851 | 22 | 207,703 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers a_1, a_2, ..., a_n.
For each a_i find its two divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 (where \gcd(a, b) is the greatest common divisor of a and b) or say that there is no such pair.
Input
The first line contains single integer n (1 β€ n β€ 5 β
10^5) β the size of the array a.
The second line contains n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 10^7) β the array a.
Output
To speed up the output, print two lines with n integers in each line.
The i-th integers in the first and second lines should be corresponding divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 or -1 and -1 if there is no such pair. If there are multiple answers, print any of them.
Example
Input
10
2 3 4 5 6 7 8 9 10 24
Output
-1 -1 -1 -1 3 -1 -1 -1 2 2
-1 -1 -1 -1 2 -1 -1 -1 5 3
Note
Let's look at a_7 = 8. It has 3 divisors greater than 1: 2, 4, 8. As you can see, the sum of any pair of divisors is divisible by 2 as well as a_7.
There are other valid pairs of d_1 and d_2 for a_{10}=24, like (3, 4) or (8, 3). You can print any of them. | instruction | 0 | 103,852 | 22 | 207,704 |
Tags: constructive algorithms, math, number theory
Correct Solution:
```
import io
import math
import os
from collections import Counter
"""
def primeFactors(n):
assert n >= 1
factors = Counter()
while n % 2 == 0:
factors[2] += 1
n //= 2
x = 3
while x * x <= n:
while n % x == 0:
factors[x] += 1
n //= x
x += 2
if n != 1:
factors[n] += 1
return factors
"""
def primes(n):
# Sieve of Eratosthenes: Returns all the primes up to n (exclusive)
is_prime = [True] * n
is_prime[0] = False
is_prime[1] = False
for i in range(2, n):
if is_prime[i]:
for j in range(2 * i, n, i): # Multiples of a prime are not prime
is_prime[j] = False
return [i for i in range(n) if is_prime[i]]
# want the smallest two odd prime factor of x. Don't need primes above 10**3.5.
smallPrimes = primes(int(10 ** 3.5) + 10)[1:]
cache = {}
def getAns(x):
key = x
if key not in cache:
if x % 2 == 0:
# If x is even, the divisors must be odd and even (otherwise will sum to even)
# Choosing 2 and the largest odd divisor should always work
p = 2
while x % (2 * p) == 0:
p *= 2
odd = x // p
if odd == 1:
ret = (-1, -1)
else:
ret = (2, odd)
else:
# Two smallest odd prime factors? TLE
# p = sorted(primeFactors(x).keys())[-2:]
# Smallest odd prime factor and remaining odd factor that doesn't contain that prime?
p = []
for d in smallPrimes:
if x % d == 0:
p.append(d)
while x % d == 0:
x //= d
break
if d * d >= x:
break
if p and x != 1:
p.append(x)
if len(p) <= 1:
ret = (-1, -1)
else:
ret = tuple(p)
# if ret[0] != -1:
# assert math.gcd(sum(ret), key) == 1
cache[key] = ret
return cache[key]
def solve(N, A):
ans1 = []
ans2 = []
for x in A:
d1, d2 = getAns(x)
ans1.append(d1)
ans2.append(d2)
return " ".join(map(str, ans1)) + "\n" + " ".join(map(str, ans2))
if False:
N = 5 * 10 ** 5
M = 10 ** 7
A = list(range(M - 1, M - 2 * N - 1, -2))
assert len(A) == N
solve(len(A), A)
if __name__ == "__main__":
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = solve(N, A)
print(ans)
``` | output | 1 | 103,852 | 22 | 207,705 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers a_1, a_2, ..., a_n.
For each a_i find its two divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 (where \gcd(a, b) is the greatest common divisor of a and b) or say that there is no such pair.
Input
The first line contains single integer n (1 β€ n β€ 5 β
10^5) β the size of the array a.
The second line contains n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 10^7) β the array a.
Output
To speed up the output, print two lines with n integers in each line.
The i-th integers in the first and second lines should be corresponding divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 or -1 and -1 if there is no such pair. If there are multiple answers, print any of them.
Example
Input
10
2 3 4 5 6 7 8 9 10 24
Output
-1 -1 -1 -1 3 -1 -1 -1 2 2
-1 -1 -1 -1 2 -1 -1 -1 5 3
Note
Let's look at a_7 = 8. It has 3 divisors greater than 1: 2, 4, 8. As you can see, the sum of any pair of divisors is divisible by 2 as well as a_7.
There are other valid pairs of d_1 and d_2 for a_{10}=24, like (3, 4) or (8, 3). You can print any of them. | instruction | 0 | 103,853 | 22 | 207,706 |
Tags: constructive algorithms, math, number theory
Correct Solution:
```
import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math as mt
# stores smallest prime factor for
# every number
# Calculating SPF (Smallest Prime Factor)
# for every number till MAXN.
# Time Complexity : O(nloglogn)
def main():
n=ri()
a=ria()
MAXN=max(a)+1
spf = [0 for i in range(MAXN)]
spf[1] = 1
for i in range(2, MAXN):
# marking smallest prime factor
# for every number to be itself.
spf[i] = i
# separately marking spf for
# every even number as 2
for i in range(4, MAXN, 2):
spf[i] = 2
for i in range(3, mt.ceil(mt.sqrt(MAXN))):
# checking if i is prime
if (spf[i] == i):
# marking SPF for all numbers
# divisible by i
for j in range(i * i, MAXN, i):
# marking spf[j] if it is
# not previously marked
if (spf[j] == j):
spf[j] = i
# A O(log n) function returning prime
d1a=[]
d2a=[]
for e in a:
k=spf[e]
#print(e,k)
l=1
r=0
z=e
while True:
if z%k==0:
z=z/k
l=l*k
else:
break
r=e//l
if r==1:
d1a.append(-1)
d2a.append(-1)
else:
d1a.append(l)
d2a.append(r)
wia(d1a)
wia(d2a)
class FastReader(io.IOBase):
newlines = 0
def __init__(self, fd, chunk_size=1024 * 8):
self._fd = fd
self._chunk_size = chunk_size
self.buffer = io.BytesIO()
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
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, size=-1):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
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()
class FastWriter(io.IOBase):
def __init__(self, fd):
self._fd = fd
self.buffer = io.BytesIO()
self.write = self.buffer.write
def flush(self):
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class FastStdin(io.IOBase):
def __init__(self, fd=0):
self.buffer = FastReader(fd)
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
class FastStdout(io.IOBase):
def __init__(self, fd=1):
self.buffer = FastWriter(fd)
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.flush = self.buffer.flush
if __name__ == '__main__':
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()
``` | output | 1 | 103,853 | 22 | 207,707 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers a_1, a_2, ..., a_n.
For each a_i find its two divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 (where \gcd(a, b) is the greatest common divisor of a and b) or say that there is no such pair.
Input
The first line contains single integer n (1 β€ n β€ 5 β
10^5) β the size of the array a.
The second line contains n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 10^7) β the array a.
Output
To speed up the output, print two lines with n integers in each line.
The i-th integers in the first and second lines should be corresponding divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 or -1 and -1 if there is no such pair. If there are multiple answers, print any of them.
Example
Input
10
2 3 4 5 6 7 8 9 10 24
Output
-1 -1 -1 -1 3 -1 -1 -1 2 2
-1 -1 -1 -1 2 -1 -1 -1 5 3
Note
Let's look at a_7 = 8. It has 3 divisors greater than 1: 2, 4, 8. As you can see, the sum of any pair of divisors is divisible by 2 as well as a_7.
There are other valid pairs of d_1 and d_2 for a_{10}=24, like (3, 4) or (8, 3). You can print any of them. | instruction | 0 | 103,854 | 22 | 207,708 |
Tags: constructive algorithms, math, number theory
Correct Solution:
```
n=int(input())
al=list(map(int,input().split()))
MX=max(al)+5
seive=MX*[-1]
for i in range(2,MX):
if (seive[i]==-1):
seive[i]=i
j=i*i
while (j<MX):
if (seive[j]==-1):
seive[j]=i
j+=i
#print("seive = ",seive)
ans_d1=[]
ans_d2=[]
for i in al:
k=i
while (k%seive[i]==0):
k=k//seive[i]
if (k==1):
ans_d1.append(-1)
ans_d2.append(-1)
else:
ans_d1.append(seive[i])
ans_d2.append(k)
print(*ans_d1)
print(*ans_d2)
``` | output | 1 | 103,854 | 22 | 207,709 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers a_1, a_2, ..., a_n.
For each a_i find its two divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 (where \gcd(a, b) is the greatest common divisor of a and b) or say that there is no such pair.
Input
The first line contains single integer n (1 β€ n β€ 5 β
10^5) β the size of the array a.
The second line contains n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 10^7) β the array a.
Output
To speed up the output, print two lines with n integers in each line.
The i-th integers in the first and second lines should be corresponding divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 or -1 and -1 if there is no such pair. If there are multiple answers, print any of them.
Example
Input
10
2 3 4 5 6 7 8 9 10 24
Output
-1 -1 -1 -1 3 -1 -1 -1 2 2
-1 -1 -1 -1 2 -1 -1 -1 5 3
Note
Let's look at a_7 = 8. It has 3 divisors greater than 1: 2, 4, 8. As you can see, the sum of any pair of divisors is divisible by 2 as well as a_7.
There are other valid pairs of d_1 and d_2 for a_{10}=24, like (3, 4) or (8, 3). You can print any of them. | instruction | 0 | 103,855 | 22 | 207,710 |
Tags: constructive algorithms, math, number theory
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
mod = 10**9 + 7
n = int(input())
a = [int(x) for x in input().split()]
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857,
859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087,
1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733,
1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417,
2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167,
3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499]
ans1 = [-1]*n
ans2 = [-1]*n
for i, j in enumerate(a):
for k in primes:
if j % k == 0:
while j % k == 0:
j //= k
if j != 1:
ans1[i] = j
ans2[i] = k
break
else:
break
print(*ans1)
print(*ans2)
``` | output | 1 | 103,855 | 22 | 207,711 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers a_1, a_2, ..., a_n.
For each a_i find its two divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 (where \gcd(a, b) is the greatest common divisor of a and b) or say that there is no such pair.
Input
The first line contains single integer n (1 β€ n β€ 5 β
10^5) β the size of the array a.
The second line contains n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 10^7) β the array a.
Output
To speed up the output, print two lines with n integers in each line.
The i-th integers in the first and second lines should be corresponding divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 or -1 and -1 if there is no such pair. If there are multiple answers, print any of them.
Example
Input
10
2 3 4 5 6 7 8 9 10 24
Output
-1 -1 -1 -1 3 -1 -1 -1 2 2
-1 -1 -1 -1 2 -1 -1 -1 5 3
Note
Let's look at a_7 = 8. It has 3 divisors greater than 1: 2, 4, 8. As you can see, the sum of any pair of divisors is divisible by 2 as well as a_7.
There are other valid pairs of d_1 and d_2 for a_{10}=24, like (3, 4) or (8, 3). You can print any of them. | instruction | 0 | 103,856 | 22 | 207,712 |
Tags: constructive algorithms, math, number theory
Correct Solution:
```
import sys
from collections import deque, Counter
from itertools import product
from functools import reduce
input = sys.stdin.buffer.readline
n = int(input())
ls = list(map(int, input().split()))
mx = max(ls)
pr = [i for i in range(mx+1)]
for u in range(2, mx+1):
if u*u > mx: break
if pr[u] == u:
for v in range(u*2, mx+1, u):
pr[v] = min(pr[v], u)
def get_fac(n):
fac = []
while n > 1:
p = pr[n]
if not fac or fac[-1] != p: fac.append(p)
n //= p
return fac
d1, d2 = [], []
for u in ls:
f = get_fac(u)
if len(f) < 2:
d1.append(-1)
d2.append(-1)
else:
d1.append(f[0])
d2.append(reduce(lambda x, y: x*y, f[1:]))
print(*d1)
print(*d2)
``` | output | 1 | 103,856 | 22 | 207,713 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n integers a_1, a_2, ..., a_n.
For each a_i find its two divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 (where \gcd(a, b) is the greatest common divisor of a and b) or say that there is no such pair.
Input
The first line contains single integer n (1 β€ n β€ 5 β
10^5) β the size of the array a.
The second line contains n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 10^7) β the array a.
Output
To speed up the output, print two lines with n integers in each line.
The i-th integers in the first and second lines should be corresponding divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 or -1 and -1 if there is no such pair. If there are multiple answers, print any of them.
Example
Input
10
2 3 4 5 6 7 8 9 10 24
Output
-1 -1 -1 -1 3 -1 -1 -1 2 2
-1 -1 -1 -1 2 -1 -1 -1 5 3
Note
Let's look at a_7 = 8. It has 3 divisors greater than 1: 2, 4, 8. As you can see, the sum of any pair of divisors is divisible by 2 as well as a_7.
There are other valid pairs of d_1 and d_2 for a_{10}=24, like (3, 4) or (8, 3). You can print any of them.
Submitted Solution:
```
def leastPrimeFactor(n , least_prime) :
#least_prime = [0] * (n + 1)
least_prime[1] = 1
for i in range(2, n + 1) :
if (least_prime[i] == 0) :
least_prime[i] = i
for j in range(2 * i, n + 1, i) :
if (least_prime[j] == 0) :
least_prime[j] = i
n = int(input())
a = list(map(int , input().split()))
maxn = max(a)
lp = [0]*(maxn + 1)
leastPrimeFactor(maxn , lp)
one = [0 for _ in range(n)]
two = [0 for _ in range(n)]
for i in range(n):
sp = lp[a[i]]
while a[i] % sp == 0 and a[i] > 0:
a[i] = a[i]//sp
if a[i] == 1:
one[i] = -1
two[i] = -1
else:
one[i] = sp
two[i] = a[i]
print(*one)
print(*two)
``` | instruction | 0 | 103,857 | 22 | 207,714 |
Yes | output | 1 | 103,857 | 22 | 207,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n integers a_1, a_2, ..., a_n.
For each a_i find its two divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 (where \gcd(a, b) is the greatest common divisor of a and b) or say that there is no such pair.
Input
The first line contains single integer n (1 β€ n β€ 5 β
10^5) β the size of the array a.
The second line contains n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 10^7) β the array a.
Output
To speed up the output, print two lines with n integers in each line.
The i-th integers in the first and second lines should be corresponding divisors d_1 > 1 and d_2 > 1 such that \gcd(d_1 + d_2, a_i) = 1 or -1 and -1 if there is no such pair. If there are multiple answers, print any of them.
Example
Input
10
2 3 4 5 6 7 8 9 10 24
Output
-1 -1 -1 -1 3 -1 -1 -1 2 2
-1 -1 -1 -1 2 -1 -1 -1 5 3
Note
Let's look at a_7 = 8. It has 3 divisors greater than 1: 2, 4, 8. As you can see, the sum of any pair of divisors is divisible by 2 as well as a_7.
There are other valid pairs of d_1 and d_2 for a_{10}=24, like (3, 4) or (8, 3). You can print any of them.
Submitted Solution:
```
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
import math
import bisect
n=int(input())
vals=list(map(int,input().split()))
maxy=max(vals)
#now we construct the primes
primes=[2]
for j in range(3,math.ceil(math.sqrt(maxy))+1):
indy=min(bisect.bisect_left(primes,math.ceil(math.sqrt(j))),len(primes)-1)
broke=False
for s in range(indy+1):
if j%primes[s]==0:
broke=True
break
if broke==False:
primes.append(j)
#primes constructed
outyd1=[]
outyd2=[]
for j in range(n):
val=vals[j]
divs=[]
fac=1
#now we find the prime divisiors of vals[j]
isprime=True
indy=min(bisect.bisect_left(primes,math.ceil(math.sqrt(val))),len(primes)-1)
for s in range(indy+1):
if val%primes[s]==0:
divs.append(primes[s])
if isprime==True:
fac=val//primes[s]
isprime=False
facfree=fac
for s in range(len(divs)):
if facfree%divs[s]==0:
while facfree%divs[s]==0:
facfree=facfree//divs[s]
if len(divs)>=1:
if facfree>divs[-1]:
divs.append(facfree)
if isprime==True or len(divs)==1:
outyd1.append(-1)
outyd2.append(-1)
else:
#ok now we have all the prime divisors
#finding d1 and d2
d1=divs[0]
d2=1
for s in range(1,len(divs)):
d2*=divs[s]
outyd1.append(d1)
outyd2.append(d2)
outyd1=[str(k) for k in outyd1]
outyd2=[str(k) for k in outyd2]
print(" ".join(outyd1))
print(" ".join(outyd2))
``` | instruction | 0 | 103,858 | 22 | 207,716 |
Yes | output | 1 | 103,858 | 22 | 207,717 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.