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.
You are given an array a_1, a_2, …, a_n.
You need to perform q queries of the following two types:
1. "MULTIPLY l r x" — for every i (l ≤ i ≤ r) multiply a_i by x.
2. "TOTIENT l r" — print \varphi(∏ _{i=l}^{r} a_i) taken modulo 10^9+7, where \varphi denotes Euler's totient function.
The [Euler's totient function](http://gg.gg/euler_totient) of a positive integer n (denoted as \varphi(n)) is the number of integers x (1 ≤ x ≤ n) such that \gcd(n,x) = 1.
Input
The first line contains two integers n and q (1 ≤ n ≤ 4 ⋅ 10^5, 1 ≤ q ≤ 2 ⋅ 10^5) — the number of elements in array a and the number of queries.
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300) — the elements of array a.
Then q lines follow, describing queries in the format given in the statement.
1. "MULTIPLY l r x" (1 ≤ l ≤ r ≤ n, 1 ≤ x ≤ 300) — denotes a multiplication query.
2. "TOTIENT l r" (1 ≤ l ≤ r ≤ n) — denotes a query on the value of Euler's totient function.
It is guaranteed that there is at least one "TOTIENT" query.
Output
For each "TOTIENT" query, print the answer to it.
Example
Input
4 4
5 9 1 2
TOTIENT 3 3
TOTIENT 3 4
MULTIPLY 4 4 3
TOTIENT 4 4
Output
1
1
2
Note
In the first example, \varphi(1) = 1 for the first query, \varphi(2) = 1 for the second query and \varphi(6) = 2 for the third one.
Submitted Solution:
```
def p(n) :
result = n
p = 2
while(p * p<= n) :
if (n % p == 0) :
while (n % p == 0) :
n = n // p
result = result * (1.0 - (1.0 / (float) (p)))
p = p + 1
if (n > 1) :
result = result * (1.0 - (1.0 / (float)(n)))
return (int(result))
n,q=map(int,input().split())
a=list(map(int,input().split()))
while q>0:
l=list(map(str,input().split()))
if l[0]=='MULTIPLY':
for i in range(int(l[1])-1,int(l[2])):
a[i]*=int(l[3])
else:
for i in range(int(l[1])-1,int(l[2])):
print(p(a[i]))
q-=1
``` | instruction | 0 | 61 | 22 | 122 |
No | output | 1 | 61 | 22 | 123 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, …, a_n.
You need to perform q queries of the following two types:
1. "MULTIPLY l r x" — for every i (l ≤ i ≤ r) multiply a_i by x.
2. "TOTIENT l r" — print \varphi(∏ _{i=l}^{r} a_i) taken modulo 10^9+7, where \varphi denotes Euler's totient function.
The [Euler's totient function](http://gg.gg/euler_totient) of a positive integer n (denoted as \varphi(n)) is the number of integers x (1 ≤ x ≤ n) such that \gcd(n,x) = 1.
Input
The first line contains two integers n and q (1 ≤ n ≤ 4 ⋅ 10^5, 1 ≤ q ≤ 2 ⋅ 10^5) — the number of elements in array a and the number of queries.
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300) — the elements of array a.
Then q lines follow, describing queries in the format given in the statement.
1. "MULTIPLY l r x" (1 ≤ l ≤ r ≤ n, 1 ≤ x ≤ 300) — denotes a multiplication query.
2. "TOTIENT l r" (1 ≤ l ≤ r ≤ n) — denotes a query on the value of Euler's totient function.
It is guaranteed that there is at least one "TOTIENT" query.
Output
For each "TOTIENT" query, print the answer to it.
Example
Input
4 4
5 9 1 2
TOTIENT 3 3
TOTIENT 3 4
MULTIPLY 4 4 3
TOTIENT 4 4
Output
1
1
2
Note
In the first example, \varphi(1) = 1 for the first query, \varphi(2) = 1 for the second query and \varphi(6) = 2 for the third one.
Submitted Solution:
```
number = list(map(int, input().strip().split()))
a_n = list(map(int, input().strip().split()))
totient = list()
for i in range(number[1]):
buffer = list(map(str, input().strip().split()))
if buffer[0] == 'TOTIENT':
a_i = 1
for j in range(int(buffer[1]) - 1, int(buffer[2])):
a_i *= a_n[j]
totient.append(a_i)
else:
for j in range(int(buffer[1]) - 1, int(buffer[2])):
re_a_n = a_n[j]*int(buffer[3])
a_n[j] = re_a_n
def know_prime(n):
for iteration in range(2, n):
if n % iteration == 0:
return "Not Prime"
return "Prime"
def prime_list(n, prime):
if n >= max(prime):
for iteration in range(2, n + 1):
if know_prime(iteration) == "Prime":
prime.append(iteration)
else:
pass
def euler_tot(tot):
euler_list = list()
for k in range(len(tot)):
n = tot[k]
psi = n
for p in range(2, n + 1):
if n % p == 0 and know_prime(p) == "Prime":
# print(n, " ", p)
psi *= (1.0 - 1.0/float(p))
euler_list.append(psi)
return euler_list
print(totient)
result = euler_tot(totient)
for num in range(len(result)):
print(int(result[num]))
``` | instruction | 0 | 62 | 22 | 124 |
No | output | 1 | 62 | 22 | 125 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, …, a_n.
You need to perform q queries of the following two types:
1. "MULTIPLY l r x" — for every i (l ≤ i ≤ r) multiply a_i by x.
2. "TOTIENT l r" — print \varphi(∏ _{i=l}^{r} a_i) taken modulo 10^9+7, where \varphi denotes Euler's totient function.
The [Euler's totient function](http://gg.gg/euler_totient) of a positive integer n (denoted as \varphi(n)) is the number of integers x (1 ≤ x ≤ n) such that \gcd(n,x) = 1.
Input
The first line contains two integers n and q (1 ≤ n ≤ 4 ⋅ 10^5, 1 ≤ q ≤ 2 ⋅ 10^5) — the number of elements in array a and the number of queries.
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300) — the elements of array a.
Then q lines follow, describing queries in the format given in the statement.
1. "MULTIPLY l r x" (1 ≤ l ≤ r ≤ n, 1 ≤ x ≤ 300) — denotes a multiplication query.
2. "TOTIENT l r" (1 ≤ l ≤ r ≤ n) — denotes a query on the value of Euler's totient function.
It is guaranteed that there is at least one "TOTIENT" query.
Output
For each "TOTIENT" query, print the answer to it.
Example
Input
4 4
5 9 1 2
TOTIENT 3 3
TOTIENT 3 4
MULTIPLY 4 4 3
TOTIENT 4 4
Output
1
1
2
Note
In the first example, \varphi(1) = 1 for the first query, \varphi(2) = 1 for the second query and \varphi(6) = 2 for the third one.
Submitted Solution:
```
import math
from functools import reduce
memo = {1: {}, 2: {2: 1}}
def fact(n):
for i in range(2, n + 1):
# print (n, i)
if n % i == 0:
if n not in memo:
current = {i: 1}
for a in fact(n // i):
if a not in current: current[a] = 0
current[a] += fact(n//i)[a]
memo[n] = current
return memo[n]
for i in range(1, 301):
fact(i)
def remove(dictionary):
return {t: dictionary[t] for t in dictionary if dictionary[t] != 0}
def multiply(dictionary):
return reduce(lambda a,b:a*b, [t ** dictionary[t] for t in dictionary])
def totient(list_of_dictionary):
list_of_dictionary = remove(list_of_dictionary)
print (list_of_dictionary)
if list_of_dictionary != {}: return int(reduce(lambda a,b:a*b, [(t ** list_of_dictionary[t] - t ** (list_of_dictionary[t] - 1)) for t in list_of_dictionary]))
else: return 1
def dictionary_minus(d1, d2):
tmp = d1.copy()
for i in d2:
tmp[i] -= d2[i]
return tmp
n, q = map(int, input().split())
array = list(map(fact, map(int, input().split())))
total = {}
cummutative = []
for i in array:
for t in i:
if t not in total: total[t] = 0
total[t] += i[t]
cummutative.append(total.copy())
for _ in range(q):
line = input()
# print(cummutative)
if 'MULTIPLY' in line:
# "MULTIPLY l r x" — for every 𝑖 (𝑙≤𝑖≤𝑟) multiply 𝑎𝑖 by 𝑥.
a, b, c, d = line.split()
b, c, d = int(b), int(c), int(d)
for key in fact(d):
for total in range(b - 1, c):
if key not in cummutative[total]:
cummutative[total][key] = 0
cummutative[total][key] += max(c - b + 1, 0) * fact(d)[key]
else:
# "TOTIENT l r" — print 𝜑(∏𝑖=𝑙𝑟𝑎𝑖) taken modulo 109+7, where 𝜑 denotes Euler's totient function.
a, b, c = line.split()
b, c = int(b), int(c)
print (cummutative)
if b - 2 >= 0: print (totient(dictionary_minus(cummutative[c-1], cummutative[b-2])) % (10 ** 9 + 7))
else: print (totient(dictionary_minus(cummutative[c-1], cummutative[0])) % (10 ** 9 + 7))
``` | instruction | 0 | 63 | 22 | 126 |
No | output | 1 | 63 | 22 | 127 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, …, a_n.
You need to perform q queries of the following two types:
1. "MULTIPLY l r x" — for every i (l ≤ i ≤ r) multiply a_i by x.
2. "TOTIENT l r" — print \varphi(∏ _{i=l}^{r} a_i) taken modulo 10^9+7, where \varphi denotes Euler's totient function.
The [Euler's totient function](http://gg.gg/euler_totient) of a positive integer n (denoted as \varphi(n)) is the number of integers x (1 ≤ x ≤ n) such that \gcd(n,x) = 1.
Input
The first line contains two integers n and q (1 ≤ n ≤ 4 ⋅ 10^5, 1 ≤ q ≤ 2 ⋅ 10^5) — the number of elements in array a and the number of queries.
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300) — the elements of array a.
Then q lines follow, describing queries in the format given in the statement.
1. "MULTIPLY l r x" (1 ≤ l ≤ r ≤ n, 1 ≤ x ≤ 300) — denotes a multiplication query.
2. "TOTIENT l r" (1 ≤ l ≤ r ≤ n) — denotes a query on the value of Euler's totient function.
It is guaranteed that there is at least one "TOTIENT" query.
Output
For each "TOTIENT" query, print the answer to it.
Example
Input
4 4
5 9 1 2
TOTIENT 3 3
TOTIENT 3 4
MULTIPLY 4 4 3
TOTIENT 4 4
Output
1
1
2
Note
In the first example, \varphi(1) = 1 for the first query, \varphi(2) = 1 for the second query and \varphi(6) = 2 for the third one.
Submitted Solution:
```
s = input()
d = s.split()
if len(d) % 2 != 0:
i = 0
while i <= len(d) - 2:
x = d[i]
d[i] = d[i+1]
d[i+1] = x
i = i + 2
i = 0
while i < len(d):
print(d[i], end=' ')
i = i + 1
else:
i = 0
while i <= len(d) - 1:
x = d[i]
d[i] = d[i+1]
d[i+1] = x
i = i + 2
i = 0
while i < len(d):
print(d[i], end=' ')
i = i + 1
``` | instruction | 0 | 64 | 22 | 128 |
No | output | 1 | 64 | 22 | 129 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little C loves number «3» very much. He loves all things about it.
Now he has a positive integer n. He wants to split n into 3 positive integers a,b,c, such that a+b+c=n and none of the 3 integers is a multiple of 3. Help him to find a solution.
Input
A single line containing one integer n (3 ≤ n ≤ 10^9) — the integer Little C has.
Output
Print 3 positive integers a,b,c in a single line, such that a+b+c=n and none of them is a multiple of 3.
It can be proved that there is at least one solution. If there are multiple solutions, print any of them.
Examples
Input
3
Output
1 1 1
Input
233
Output
77 77 79 | instruction | 0 | 819 | 22 | 1,638 |
Tags: math
Correct Solution:
```
x=int(input())
y=x//3
if y%3==0:
if x%3==0:
print(y-2," ",y+1," ",y+1)
elif x%3==1:
print(y-2," ",y+1," ",y+2)
else:
print(y-2," ",y+2," ",y+2)
else:
if x%3==0:
print(y," ",y," ",y)
elif x%3==1 and y%3!=2:
print(y," ",y," ",y+1)
elif x%3==1 and y%3==2:
print(y-1," ",y-1," ",y+3)
elif x%3==2 and y%3!=2:
print(y," ",y+1," ",y+1)
elif x%3==2 and y%3==2:
print(y," ",y," ",y+2)
``` | output | 1 | 819 | 22 | 1,639 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little C loves number «3» very much. He loves all things about it.
Now he has a positive integer n. He wants to split n into 3 positive integers a,b,c, such that a+b+c=n and none of the 3 integers is a multiple of 3. Help him to find a solution.
Input
A single line containing one integer n (3 ≤ n ≤ 10^9) — the integer Little C has.
Output
Print 3 positive integers a,b,c in a single line, such that a+b+c=n and none of them is a multiple of 3.
It can be proved that there is at least one solution. If there are multiple solutions, print any of them.
Examples
Input
3
Output
1 1 1
Input
233
Output
77 77 79 | instruction | 0 | 821 | 22 | 1,642 |
Tags: math
Correct Solution:
```
n = int(input())
r = n%3
if (r == 0) or (r == 1):
print(str(n-2) + " 1 1")
else:
print(str(n-4) + " 2 2")
``` | output | 1 | 821 | 22 | 1,643 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little C loves number «3» very much. He loves all things about it.
Now he has a positive integer n. He wants to split n into 3 positive integers a,b,c, such that a+b+c=n and none of the 3 integers is a multiple of 3. Help him to find a solution.
Input
A single line containing one integer n (3 ≤ n ≤ 10^9) — the integer Little C has.
Output
Print 3 positive integers a,b,c in a single line, such that a+b+c=n and none of them is a multiple of 3.
It can be proved that there is at least one solution. If there are multiple solutions, print any of them.
Examples
Input
3
Output
1 1 1
Input
233
Output
77 77 79 | instruction | 0 | 822 | 22 | 1,644 |
Tags: math
Correct Solution:
```
n = int(input())
if n == 3:
print("1 1 1")
else:
a,b = 1,1
while (n-a-b)%3==0 or a%3==0 or b%3==0:
a+=1
b+=1
c = n-a-b
print(a,b,c)
``` | output | 1 | 822 | 22 | 1,645 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little C loves number «3» very much. He loves all things about it.
Now he has a positive integer n. He wants to split n into 3 positive integers a,b,c, such that a+b+c=n and none of the 3 integers is a multiple of 3. Help him to find a solution.
Input
A single line containing one integer n (3 ≤ n ≤ 10^9) — the integer Little C has.
Output
Print 3 positive integers a,b,c in a single line, such that a+b+c=n and none of them is a multiple of 3.
It can be proved that there is at least one solution. If there are multiple solutions, print any of them.
Examples
Input
3
Output
1 1 1
Input
233
Output
77 77 79 | instruction | 0 | 823 | 22 | 1,646 |
Tags: math
Correct Solution:
```
n=int(input())
# a=n%3
# b=n//3
if n==3:
print(1,1,1)
elif n%3==0:
print(1,1,n-2)#if n=9 7 1 1
else:#if n=8 5 2 1
print(n-3,2,1)
``` | output | 1 | 823 | 22 | 1,647 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little C loves number «3» very much. He loves all things about it.
Now he has a positive integer n. He wants to split n into 3 positive integers a,b,c, such that a+b+c=n and none of the 3 integers is a multiple of 3. Help him to find a solution.
Input
A single line containing one integer n (3 ≤ n ≤ 10^9) — the integer Little C has.
Output
Print 3 positive integers a,b,c in a single line, such that a+b+c=n and none of them is a multiple of 3.
It can be proved that there is at least one solution. If there are multiple solutions, print any of them.
Examples
Input
3
Output
1 1 1
Input
233
Output
77 77 79 | instruction | 0 | 824 | 22 | 1,648 |
Tags: math
Correct Solution:
```
n = int(input())
x = 2 if (n+1) % 3 == 0 else 1
print(f'1 {x} {n-x-1}')
``` | output | 1 | 824 | 22 | 1,649 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little C loves number «3» very much. He loves all things about it.
Now he has a positive integer n. He wants to split n into 3 positive integers a,b,c, such that a+b+c=n and none of the 3 integers is a multiple of 3. Help him to find a solution.
Input
A single line containing one integer n (3 ≤ n ≤ 10^9) — the integer Little C has.
Output
Print 3 positive integers a,b,c in a single line, such that a+b+c=n and none of them is a multiple of 3.
It can be proved that there is at least one solution. If there are multiple solutions, print any of them.
Examples
Input
3
Output
1 1 1
Input
233
Output
77 77 79 | instruction | 0 | 825 | 22 | 1,650 |
Tags: math
Correct Solution:
```
n = int(input())
if (n - 3) % 3 != 0:
print(1, 2, n - 3)
else:
print(1, 1, n - 2)
``` | output | 1 | 825 | 22 | 1,651 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little C loves number «3» very much. He loves all things about it.
Now he has a positive integer n. He wants to split n into 3 positive integers a,b,c, such that a+b+c=n and none of the 3 integers is a multiple of 3. Help him to find a solution.
Input
A single line containing one integer n (3 ≤ n ≤ 10^9) — the integer Little C has.
Output
Print 3 positive integers a,b,c in a single line, such that a+b+c=n and none of them is a multiple of 3.
It can be proved that there is at least one solution. If there are multiple solutions, print any of them.
Examples
Input
3
Output
1 1 1
Input
233
Output
77 77 79 | instruction | 0 | 826 | 22 | 1,652 |
Tags: math
Correct Solution:
```
if __name__ == '__main__':
n = int(input().strip())
a, b = 1, 2
c = n - 3
if c % 3 == 0:
b -= 1
c += 1
print(a, b, c)
``` | output | 1 | 826 | 22 | 1,653 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime. | instruction | 0 | 1,029 | 22 | 2,058 |
Tags: brute force, greedy, math, number theory
Correct Solution:
```
def nf(nn):
global fact
sim = True
for k in fact:
if nn % k == 0:
sim = False
break
if sim: fact.append(nn)
def rez(nn):
global df
k = [6, 10, 14]
j = 3
while nn - sum(k) > 0 and (nn - sum(k)) in k:
k[2] = df[j]
j += 1
k4 = nn - sum(k)
r = ""
if k4 > 0:
k.append(k4)
for n in k:
r += str(n) + " "
return r
fact = [2, 3, 5, 7]
for i in range(2, 7):
nf(i * 6 - 1)
nf(i * 6 + 1)
df = []
km = len(fact)
for i in range(km-1):
for j in range(i+1, km):
df.append(fact[i]*fact[j])
df.sort()
for i in range(int(input())):
x = int(input())
if x < 31: print('NO')
else:
print('YES')
print(rez(x))
``` | output | 1 | 1,029 | 22 | 2,059 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime. | instruction | 0 | 1,030 | 22 | 2,060 |
Tags: brute force, greedy, math, number theory
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
if n<31:
print("NO")
elif n==44:
print("YES")
print(6,7,10,21)
elif n==40:
print("YES")
print(6,10,21,3)
elif n==36:
print("YES")
print(6,14,15,1)
else:
print("YES")
print(6,10,14,n-30)
``` | output | 1 | 1,030 | 22 | 2,061 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime. | instruction | 0 | 1,031 | 22 | 2,062 |
Tags: brute force, greedy, math, number theory
Correct Solution:
```
import bisect
import os
import gc
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics
def sin():
return input()
def ain():
return list(map(int, sin().split()))
def sain():
return input().split()
def iin():
return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007
def sieve(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
s = set()
for p in range(2, n+1):
if prime[p]:
s.add(p)
return s
def readTree(n, m):
adj = [deque([]) for _ in range(n+1)]
for _ in range(m):
u,v = ain()
adj[u].append(v)
adj[v].append(u)
return adj
def main():
for _ in range(iin()):
n = iin()
if n<=30:
print("NO")
else:
print("YES")
if n-30 == 6:
print(6,10,15,n-31)
elif n-30 == 14:
print(6,10,15, n-31)
elif n-30 == 10:
print(6,14,15,n-35)
else:
print(6,10,14,n-30)
# Fast IO Template starts
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")
if os.getcwd() == 'D:\\code':
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# Fast IO Template ends
if __name__ == "__main__":
main()
``` | output | 1 | 1,031 | 22 | 2,063 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime. | instruction | 0 | 1,032 | 22 | 2,064 |
Tags: brute force, greedy, math, number theory
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
if n<=30:
print('NO')
else:
print('YES')
if n==36:
print(5,6,10,15)
elif n==44:
print(6,7,10,21)
elif n==40:
print(6,10,15,9)
else:
print(6,10,14,n-30)
``` | output | 1 | 1,032 | 22 | 2,065 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime. | instruction | 0 | 1,033 | 22 | 2,066 |
Tags: brute force, greedy, math, number theory
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
ans=[6,10,14,15,21,22,26]
check=False
for i in ans:
for j in ans:
for k in ans:
if n>i+j+k and n-i-j-k!=i and n-i-j-k!=j and n-i-j-k!=k and i!=j and j!=k and i!=k:
print("YES")
print(i,j,k,n-i-j-k)
check=True
break
if check:
break
if check:
break
if not check:
print("NO")
``` | output | 1 | 1,033 | 22 | 2,067 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime. | instruction | 0 | 1,034 | 22 | 2,068 |
Tags: brute force, greedy, math, number theory
Correct Solution:
```
from sys import *
t = int(stdin.readline())
while t > 0:
n = int(stdin.readline())
if n >30:
print("YES")
if n-30 == 6:
print(6,10,15,n-31)
elif n-30 == 10:
print(6,10,15,n-31)
elif n-30 == 14:
print(6,10,21,n-37)
else:
print(6,10,14,n-30)
else:
print("NO")
t -= 1
``` | output | 1 | 1,034 | 22 | 2,069 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime. | instruction | 0 | 1,035 | 22 | 2,070 |
Tags: brute force, greedy, math, number theory
Correct Solution:
```
t = int(input())
for aSRD in range(t):
n = int(input())
if n > (6+10+14):
k = n - 6 - 10 - 14
print("YES")
if k == 6 or k == 10 or k == 14:
print(6, 10, 15, k-1)
else:
print(6, 10, 14, k)
else:
print("NO")
``` | output | 1 | 1,035 | 22 | 2,071 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime. | instruction | 0 | 1,036 | 22 | 2,072 |
Tags: brute force, greedy, math, number theory
Correct Solution:
```
t=int(input())
while(t>0):
t-=1
n=int(input())
if n<31:
print("NO")
else:
print("Yes")
if n==36:
print(15, 10, 6, 5)
elif n==40:
print(15, 10, 6, 9)
elif n==44:
print(15, 10, 6, 13)
else:
print(14, 10, 6, n-30)
``` | output | 1 | 1,036 | 22 | 2,073 |
Provide tags and a correct Python 2 solution for this coding contest problem.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime. | instruction | 0 | 1,037 | 22 | 2,074 |
Tags: brute force, greedy, math, number theory
Correct Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import combinations
pr=stdout.write
import heapq
raw_input = stdin.readline
def ni():
return int(raw_input())
def li():
return list(map(int,raw_input().split()))
def pn(n):
stdout.write(str(n)+'\n')
def pa(arr):
pr(' '.join(map(str,arr))+'\n')
# fast read function for total integer input
def inp():
# this function returns whole input of
# space/line seperated integers
# Use Ctrl+D to flush stdin.
return (map(int,stdin.read().split()))
range = xrange # not for python 3.0+
arr=[6,10,14,15,21,22]
for t in range(ni()):
n=ni()
f=0
for com in combinations(arr,3):
tp=n-sum(com)
if tp>0 and tp not in com:
f=1
break
if f:
pr('YES\n')
pa(com+(tp,))
else:
pr('NO\n')
``` | output | 1 | 1,037 | 22 | 2,075 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime.
Submitted Solution:
```
I = input
pr = print
def main():
for _ in range(int(I())):
n = int(I())
ar = [6,10,14]
if n<31:pr('NO');continue
else:
if (n-30) in ar: n-=5;ar[1]+=5
pr('YES');pr(*ar,n-30)
main()
``` | instruction | 0 | 1,038 | 22 | 2,076 |
Yes | output | 1 | 1,038 | 22 | 2,077 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime.
Submitted Solution:
```
def nearPrime(N):
if N <= 30:
print("NO")
else:
print("YES")
if N == 36 or N == 40 or N == 44:
print(6, 10, 15, N-31)
else:
print(6, 10, 14, N-30)
for i in range(int(input())):
N = int(input())
nearPrime(N)
``` | instruction | 0 | 1,039 | 22 | 2,078 |
Yes | output | 1 | 1,039 | 22 | 2,079 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime.
Submitted Solution:
```
tests = int(input())
for t in range(tests):
n = int(input())
if n < 31:
print('NO')
else:
print('YES')
if n == 40:
res = [6, 14, 15, 5]
elif n == 44:
res = [6,10,15,13]
elif n == 36:
res = [5, 6, 10, 15]
else:
res = [6,10,14, n-30]
print(' '.join(list(map(str,res))))
``` | instruction | 0 | 1,040 | 22 | 2,080 |
Yes | output | 1 | 1,040 | 22 | 2,081 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime.
Submitted Solution:
```
for _ in range(int(input())):
n=int(input())
if n<=30:
print("NO")
elif n==36 or n==44 or n==40:
print("YES")
print(6, 10, 15, n-31)
else:
print("YES")
print(6, 10, 14, n-30)
``` | instruction | 0 | 1,041 | 22 | 2,082 |
Yes | output | 1 | 1,041 | 22 | 2,083 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime.
Submitted Solution:
```
import sys
input=sys.stdin.readline
T=int(input())
for _ in range(T):
#n,m=map(int,input().split())
n=int(input())
if (n<=30):
print("NO")
else:
print("YES")
print(6,10,14,n-30)
``` | instruction | 0 | 1,042 | 22 | 2,084 |
No | output | 1 | 1,042 | 22 | 2,085 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime.
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
if n > 30:
print("YES")
print(6, 10, 14, n-30)
else:
print('NO')
``` | instruction | 0 | 1,043 | 22 | 2,086 |
No | output | 1 | 1,043 | 22 | 2,087 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime.
Submitted Solution:
```
import math
t = int(input())
ans = []
def solve(n):
if n < 30:
return ["NO"]
else:
if len({6,10,14,n-30})<4:
return [6,10,15,n-31]
if len({6,10,15,n-31})<4:
return [6,10,21,n-37]
return [6,10,14,n-30]
for i in range(t):
n = int(input())
ans.append(solve(n))
#print(ans)
for test in ans:
if len(test) == 1:
print(test[0])
else:
print("YES")
print(test[0],test[1],test[2],test[3])
``` | instruction | 0 | 1,044 | 22 | 2,088 |
No | output | 1 | 1,044 | 22 | 2,089 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime.
Submitted Solution:
```
import math
def simpl(x):
for i in range(2, int(math.sqrt(x))):
if x % i == 0:
return False
return True
if __name__ == "__main__":
t = int(input())
a = []
for i in range(10000):
if simpl(i):
a.append(i)
for i in range(t):
x = int(input())
if x >= 18 and x - 18 not in a:
print("YES")
print(6, 6, 6, x - 18)
else:
print("NO")
``` | instruction | 0 | 1,045 | 22 | 2,090 |
No | output | 1 | 1,045 | 22 | 2,091 |
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response.
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer x as nearly prime if it can be represented as p ⋅ q, where 1 < p < q and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2 ⋅ 3 = 6 and 2 ⋅ 5 = 10), but integers 1, 3, 4, 16, 17 or 44 are not.
Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number Flint guessed.
Output
For each test case print:
* YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
* NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.
Example
Input
7
7
23
31
36
44
100
258
Output
NO
NO
YES
14 10 6 1
YES
5 6 10 15
YES
6 7 10 21
YES
2 10 33 55
YES
10 21 221 6
Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.
In the third test case, n=31=2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1: integers 14, 10, 6 are nearly prime.
In the fourth test case, n=36=5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5: integers 6, 10, 15 are nearly prime.
In the fifth test case, n=44=2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7: integers 6, 10, 21 are nearly prime.
In the sixth test case, n=100=2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11: integers 10, 33, 55 are nearly prime.
In the seventh test case, n=258=2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3: integers 10, 21, 221, 6 are nearly prime.
Submitted Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
pr=stdout.write
import heapq
raw_input = stdin.readline
def ni():
return int(raw_input())
def li():
return list(map(int,raw_input().split()))
def pn(n):
stdout.write(str(n)+'\n')
def pa(arr):
pr(' '.join(map(str,arr))+'\n')
# fast read function for total integer input
def inp():
# this function returns whole input of
# space/line seperated integers
# Use Ctrl+D to flush stdin.
return (map(int,stdin.read().split()))
range = xrange # not for python 3.0+
for t in range(ni()):
n=ni()
if n<=30:
pr('NO\n')
continue
pr('YES\n')
pa([6,10,14,n-30])
``` | instruction | 0 | 1,046 | 22 | 2,092 |
No | output | 1 | 1,046 | 22 | 2,093 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
<image>
Given all the numbers of the GCD table G, restore array a.
Input
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
Output
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
Examples
Input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
42
Input
2
1 1 1 1
Output
1 1 | instruction | 0 | 1,269 | 22 | 2,538 |
Tags: constructive algorithms, greedy, number theory
Correct Solution:
```
import fractions
n = int(input())
ns = list(map(int, input().strip().split(' ')))
a = []
skip = {}
ns = sorted(ns, reverse=True)
for i, num in enumerate(ns):
if num in skip and skip[num] > 0:
skip[num] -= 1
continue
a.append(num)
if len(a) == n:
break
for other in a:
gcd = fractions.gcd(other, num)
if not gcd in skip:
skip[gcd] = 0
skip[gcd] += 2
print(' '.join(map(str, a)))
``` | output | 1 | 1,269 | 22 | 2,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
<image>
Given all the numbers of the GCD table G, restore array a.
Input
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
Output
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
Examples
Input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
42
Input
2
1 1 1 1
Output
1 1 | instruction | 0 | 1,270 | 22 | 2,540 |
Tags: constructive algorithms, greedy, number theory
Correct Solution:
```
# ------------------
# rpy3cpp's solution
# ------------------
import collections
import math
def main():
n = int(input())
g = list(map(int, input().split()))
g_counter = collections.Counter(g)
n_list = []
g.sort()
while len(n_list) < n:
x = g.pop()
while g_counter[x] == 0:
x = g.pop()
g_counter[x] -= 1
for i in n_list:
y = math.gcd(x, i)
g_counter[y] -= 2
n_list.append(x)
print(' '.join(map(str, n_list)))
if __name__ == '__main__':
main()
# # ------------------
# # cgl-fai's solution
# # - Slow
# # ------------------
#
#
# def gcd(a, b):
# if b == 0:
# return a
# return gcd(b, a % b)
#
#
# def main():
# in_n = int(input())
# in_a_list = list(map(int, input().split()))
# x = max(in_a_list)
# n_list = [x]
# in_a_list.remove(x)
# while len(n_list) < in_n:
# x = max(in_a_list)
# in_a_list.remove(x)
# for i in n_list:
# y = gcd(x, i)
# in_a_list.remove(y)
# in_a_list.remove(y)
# n_list.append(x)
# print(' '.join(map(str, n_list)))
#
# if __name__ == '__main__':
# main()
``` | output | 1 | 1,270 | 22 | 2,541 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
<image>
Given all the numbers of the GCD table G, restore array a.
Input
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
Output
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
Examples
Input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
42
Input
2
1 1 1 1
Output
1 1 | instruction | 0 | 1,271 | 22 | 2,542 |
Tags: constructive algorithms, greedy, number theory
Correct Solution:
```
import fractions
import collections
n = int(input())
ns = sorted((int(i) for i in input().split()), reverse=True)
bs = []
cs = collections.Counter(ns)
r = []
tot = 0
for i in ns:
if not cs[i]:
continue
r.append(i)
cs[i] -= 1
for j in bs:
cs[fractions.gcd(i, j)] -= 2
bs.append(i)
print(' '.join(map(str, r)))
``` | output | 1 | 1,271 | 22 | 2,543 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
<image>
Given all the numbers of the GCD table G, restore array a.
Input
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
Output
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
Examples
Input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
42
Input
2
1 1 1 1
Output
1 1 | instruction | 0 | 1,272 | 22 | 2,544 |
Tags: constructive algorithms, greedy, number theory
Correct Solution:
```
import sys
from math import gcd,sqrt,ceil,log2
from collections import defaultdict,Counter,deque
from bisect import bisect_left,bisect_right
import math
sys.setrecursionlimit(2*10**5+10)
import heapq
from itertools import permutations
# input=sys.stdin.readline
# def print(x):
# sys.stdout.write(str(x)+"\n")
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
aa='abcdefghijklmnopqrstuvwxyz'
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# import sys
# import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def get_sum(bit,i):
s = 0
i+=1
while i>0:
s+=bit[i]
i-=i&(-i)
return s
def update(bit,n,i,v):
i+=1
while i<=n:
bit[i]+=v
i+=i&(-i)
def modInverse(b,m):
g = math.gcd(b, m)
if (g != 1):
return -1
else:
return pow(b, m - 2, m)
def primeFactors(n):
sa = []
# sa.add(n)
while n % 2 == 0:
sa.append(2)
n = n // 2
for i in range(3,int(math.sqrt(n))+1,2):
while n % i== 0:
sa.append(i)
n = n // i
# sa.add(n)
if n > 2:
sa.append(n)
return sa
def seive(n):
pri = [True]*(n+1)
p = 2
while p*p<=n:
if pri[p] == True:
for i in range(p*p,n+1,p):
pri[i] = False
p+=1
return pri
def check_prim(n):
if n<0:
return False
for i in range(2,int(sqrt(n))+1):
if n%i == 0:
return False
return True
def getZarr(string, z):
n = len(string)
# [L,R] make a window which matches
# with prefix of s
l, r, k = 0, 0, 0
for i in range(1, n):
# if i>R nothing matches so we will calculate.
# Z[i] using naive way.
if i > r:
l, r = i, i
# R-L = 0 in starting, so it will start
# checking from 0'th index. For example,
# for "ababab" and i = 1, the value of R
# remains 0 and Z[i] becomes 0. For string
# "aaaaaa" and i = 1, Z[i] and R become 5
while r < n and string[r - l] == string[r]:
r += 1
z[i] = r - l
r -= 1
else:
# k = i-L so k corresponds to number which
# matches in [L,R] interval.
k = i - l
# if Z[k] is less than remaining interval
# then Z[i] will be equal to Z[k].
# For example, str = "ababab", i = 3, R = 5
# and L = 2
if z[k] < r - i + 1:
z[i] = z[k]
# For example str = "aaaaaa" and i = 2,
# R is 5, L is 0
else:
# else start from R and check manually
l = i
while r < n and string[r - l] == string[r]:
r += 1
z[i] = r - l
r -= 1
def search(text, pattern):
# Create concatenated string "P$T"
concat = pattern + "$" + text
l = len(concat)
z = [0] * l
getZarr(concat, z)
ha = []
for i in range(l):
if z[i] == len(pattern):
ha.append(i - len(pattern) - 1)
return ha
# n,k = map(int,input().split())
# l = list(map(int,input().split()))
#
# n = int(input())
# l = list(map(int,input().split()))
#
# hash = defaultdict(list)
# la = []
#
# for i in range(n):
# la.append([l[i],i+1])
#
# la.sort(key = lambda x: (x[0],-x[1]))
# ans = []
# r = n
# flag = 0
# lo = []
# ha = [i for i in range(n,0,-1)]
# yo = []
# for a,b in la:
#
# if a == 1:
# ans.append([r,b])
# # hash[(1,1)].append([b,r])
# lo.append((r,b))
# ha.pop(0)
# yo.append([r,b])
# r-=1
#
# elif a == 2:
# # print(yo,lo)
# # print(hash[1,1])
# if lo == []:
# flag = 1
# break
# c,d = lo.pop(0)
# yo.pop(0)
# if b>=d:
# flag = 1
# break
# ans.append([c,b])
# yo.append([c,b])
#
#
#
# elif a == 3:
#
# if yo == []:
# flag = 1
# break
# c,d = yo.pop(0)
# if b>=d:
# flag = 1
# break
# if ha == []:
# flag = 1
# break
#
# ka = ha.pop(0)
#
# ans.append([ka,b])
# ans.append([ka,d])
# yo.append([ka,b])
#
# if flag:
# print(-1)
# else:
# print(len(ans))
# for a,b in ans:
# print(a,b)
def mergeIntervals(arr):
# Sorting based on the increasing order
# of the start intervals
arr.sort(key = lambda x: x[0])
# array to hold the merged intervals
m = []
s = -10000
max = -100000
for i in range(len(arr)):
a = arr[i]
if a[0] > max:
if i != 0:
m.append([s,max])
max = a[1]
s = a[0]
else:
if a[1] >= max:
max = a[1]
#'max' value gives the last point of
# that particular interval
# 's' gives the starting point of that interval
# 'm' array contains the list of all merged intervals
if max != -100000 and [s, max] not in m:
m.append([s, max])
return m
class SortedList:
def __init__(self, iterable=[], _load=200):
"""Initialize sorted list instance."""
values = sorted(iterable)
self._len = _len = len(values)
self._load = _load
self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
self._list_lens = [len(_list) for _list in _lists]
self._mins = [_list[0] for _list in _lists]
self._fen_tree = []
self._rebuild = True
def _fen_build(self):
"""Build a fenwick tree instance."""
self._fen_tree[:] = self._list_lens
_fen_tree = self._fen_tree
for i in range(len(_fen_tree)):
if i | i + 1 < len(_fen_tree):
_fen_tree[i | i + 1] += _fen_tree[i]
self._rebuild = False
def _fen_update(self, index, value):
"""Update `fen_tree[index] += value`."""
if not self._rebuild:
_fen_tree = self._fen_tree
while index < len(_fen_tree):
_fen_tree[index] += value
index |= index + 1
def _fen_query(self, end):
"""Return `sum(_fen_tree[:end])`."""
if self._rebuild:
self._fen_build()
_fen_tree = self._fen_tree
x = 0
while end:
x += _fen_tree[end - 1]
end &= end - 1
return x
def _fen_findkth(self, k):
"""Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`)."""
_list_lens = self._list_lens
if k < _list_lens[0]:
return 0, k
if k >= self._len - _list_lens[-1]:
return len(_list_lens) - 1, k + _list_lens[-1] - self._len
if self._rebuild:
self._fen_build()
_fen_tree = self._fen_tree
idx = -1
for d in reversed(range(len(_fen_tree).bit_length())):
right_idx = idx + (1 << d)
if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
idx = right_idx
k -= _fen_tree[idx]
return idx + 1, k
def _delete(self, pos, idx):
"""Delete value at the given `(pos, idx)`."""
_lists = self._lists
_mins = self._mins
_list_lens = self._list_lens
self._len -= 1
self._fen_update(pos, -1)
del _lists[pos][idx]
_list_lens[pos] -= 1
if _list_lens[pos]:
_mins[pos] = _lists[pos][0]
else:
del _lists[pos]
del _list_lens[pos]
del _mins[pos]
self._rebuild = True
def _loc_left(self, value):
"""Return an index pair that corresponds to the first position of `value` in the sorted list."""
if not self._len:
return 0, 0
_lists = self._lists
_mins = self._mins
lo, pos = -1, len(_lists) - 1
while lo + 1 < pos:
mi = (lo + pos) >> 1
if value <= _mins[mi]:
pos = mi
else:
lo = mi
if pos and value <= _lists[pos - 1][-1]:
pos -= 1
_list = _lists[pos]
lo, idx = -1, len(_list)
while lo + 1 < idx:
mi = (lo + idx) >> 1
if value <= _list[mi]:
idx = mi
else:
lo = mi
return pos, idx
def _loc_right(self, value):
"""Return an index pair that corresponds to the last position of `value` in the sorted list."""
if not self._len:
return 0, 0
_lists = self._lists
_mins = self._mins
pos, hi = 0, len(_lists)
while pos + 1 < hi:
mi = (pos + hi) >> 1
if value < _mins[mi]:
hi = mi
else:
pos = mi
_list = _lists[pos]
lo, idx = -1, len(_list)
while lo + 1 < idx:
mi = (lo + idx) >> 1
if value < _list[mi]:
idx = mi
else:
lo = mi
return pos, idx
def add(self, value):
"""Add `value` to sorted list."""
_load = self._load
_lists = self._lists
_mins = self._mins
_list_lens = self._list_lens
self._len += 1
if _lists:
pos, idx = self._loc_right(value)
self._fen_update(pos, 1)
_list = _lists[pos]
_list.insert(idx, value)
_list_lens[pos] += 1
_mins[pos] = _list[0]
if _load + _load < len(_list):
_lists.insert(pos + 1, _list[_load:])
_list_lens.insert(pos + 1, len(_list) - _load)
_mins.insert(pos + 1, _list[_load])
_list_lens[pos] = _load
del _list[_load:]
self._rebuild = True
else:
_lists.append([value])
_mins.append(value)
_list_lens.append(1)
self._rebuild = True
def discard(self, value):
"""Remove `value` from sorted list if it is a member."""
_lists = self._lists
if _lists:
pos, idx = self._loc_right(value)
if idx and _lists[pos][idx - 1] == value:
self._delete(pos, idx - 1)
def remove(self, value):
"""Remove `value` from sorted list; `value` must be a member."""
_len = self._len
self.discard(value)
if _len == self._len:
raise ValueError('{0!r} not in list'.format(value))
def pop(self, index=-1):
"""Remove and return value at `index` in sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
value = self._lists[pos][idx]
self._delete(pos, idx)
return value
def bisect_left(self, value):
"""Return the first index to insert `value` in the sorted list."""
pos, idx = self._loc_left(value)
return self._fen_query(pos) + idx
def bisect_right(self, value):
"""Return the last index to insert `value` in the sorted list."""
pos, idx = self._loc_right(value)
return self._fen_query(pos) + idx
def count(self, value):
"""Return number of occurrences of `value` in the sorted list."""
return self.bisect_right(value) - self.bisect_left(value)
def __len__(self):
"""Return the size of the sorted list."""
return self._len
def __getitem__(self, index):
"""Lookup value at `index` in sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
return self._lists[pos][idx]
def __delitem__(self, index):
"""Remove value at `index` from sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
self._delete(pos, idx)
def __contains__(self, value):
"""Return true if `value` is an element of the sorted list."""
_lists = self._lists
if _lists:
pos, idx = self._loc_left(value)
return idx < len(_lists[pos]) and _lists[pos][idx] == value
return False
def __iter__(self):
"""Return an iterator over the sorted list."""
return (value for _list in self._lists for value in _list)
def __reversed__(self):
"""Return a reverse iterator over the sorted list."""
return (value for _list in reversed(self._lists) for value in reversed(_list))
def __repr__(self):
"""Return string representation of sorted list."""
return 'SortedList({0})'.format(list(self))
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den,
p - 2, p)) % p
def sol(n):
seti = set()
for i in range(1,int(sqrt(n))+1):
if n%i == 0:
seti.add(n//i)
seti.add(i)
return seti
def lcm(a,b):
return (a*b)//gcd(a,b)
#
# n,p = map(int,input().split())
#
# s = input()
#
# if n <=2:
# if n == 1:
# pass
# if n == 2:
# pass
# i = n-1
# idx = -1
# while i>=0:
# z = ord(s[i])-96
# k = chr(z+1+96)
# flag = 1
# if i-1>=0:
# if s[i-1]!=k:
# flag+=1
# else:
# flag+=1
# if i-2>=0:
# if s[i-2]!=k:
# flag+=1
# else:
# flag+=1
# if flag == 2:
# idx = i
# s[i] = k
# break
# if idx == -1:
# print('NO')
# exit()
# for i in range(idx+1,n):
# if
#
def moore_voting(l):
count1 = 0
count2 = 0
first = 10**18
second = 10**18
n = len(l)
for i in range(n):
if l[i] == first:
count1+=1
elif l[i] == second:
count2+=1
elif count1 == 0:
count1+=1
first = l[i]
elif count2 == 0:
count2+=1
second = l[i]
else:
count1-=1
count2-=1
for i in range(n):
if l[i] == first:
count1+=1
elif l[i] == second:
count2+=1
if count1>n//3:
return first
if count2>n//3:
return second
return -1
def find_parent(u,parent):
if u!=parent[u]:
parent[u] = find_parent(parent[u],parent)
return parent[u]
def dis_union(n,e):
par = [i for i in range(n+1)]
rank = [1]*(n+1)
for a,b in e:
z1,z2 = find_parent(a,par),find_parent(b,par)
if rank[z1]>rank[z2]:
z1,z2 = z2,z1
if z1!=z2:
par[z1] = z2
rank[z2]+=rank[z1]
else:
return a,b
def dijkstra(n,tot,hash):
hea = [[0,n]]
dis = [10**18]*(tot+1)
dis[n] = 0
boo = defaultdict(bool)
check = defaultdict(int)
while hea:
a,b = heapq.heappop(hea)
if boo[b]:
continue
boo[b] = True
for i,w in hash[b]:
if b == 1:
c = 0
if (1,i,w) in nodes:
c = nodes[(1,i,w)]
del nodes[(1,i,w)]
if dis[b]+w<dis[i]:
dis[i] = dis[b]+w
check[i] = c
elif dis[b]+w == dis[i] and c == 0:
dis[i] = dis[b]+w
check[i] = c
else:
if dis[b]+w<=dis[i]:
dis[i] = dis[b]+w
check[i] = check[b]
heapq.heappush(hea,[dis[i],i])
return check
def power(x,y,p):
res = 1
x = x%p
if x == 0:
return 0
while y>0:
if (y&1) == 1:
res*=x
x = x*x
y = y>>1
return res
import sys
from math import ceil,log2
INT_MAX = sys.maxsize
def minVal(x, y) :
return x if (x < y) else y
def getMid(s, e) :
return s + (e - s) // 2
def RMQUtil( st, ss, se, qs, qe, index) :
if (qs <= ss and qe >= se) :
return st[index]
if (se < qs or ss > qe) :
return INT_MAX
mid = getMid(ss, se)
return minVal(RMQUtil(st, ss, mid, qs,
qe, 2 * index + 1),
RMQUtil(st, mid + 1, se,
qs, qe, 2 * index + 2))
def RMQ( st, n, qs, qe) :
if (qs < 0 or qe > n - 1 or qs > qe) :
print("Invalid Input")
return -1
return RMQUtil(st, 0, n - 1, qs, qe, 0)
def constructSTUtil(arr, ss, se, st, si) :
if (ss == se) :
st[si] = arr[ss]
return arr[ss]
mid = getMid(ss, se)
st[si] = minVal(constructSTUtil(arr, ss, mid,
st, si * 2 + 1),
constructSTUtil(arr, mid + 1, se,
st, si * 2 + 2))
return st[si]
def constructST( arr, n) :
x = (int)(ceil(log2(n)))
max_size = 2 * (int)(2**x) - 1
st = [0] * (max_size)
constructSTUtil(arr, 0, n - 1, st, 0)
return st
# t = int(input())
# for _ in range(t):
#
# n = int(input())
# l = list(map(int,input().split()))
# # x,y = 0,10
# st = constructST(l, n)
#
# pre = [0]
# suf = [0]
# for i in range(n):
# pre.append(max(pre[-1],l[i]))
# for i in range(n-1,-1,-1):
# suf.append(max(suf[-1],l[i]))
#
#
# i = 1
# # print(pre,suf)
# flag = 0
# x,y,z = -1,-1,-1
# # suf.reverse()
# print(suf)
# while i<len(pre):
#
# z = pre[i]
# j = bisect_left(suf,z)
# if suf[j] == z:
# while i<n and l[i]<=z:
# i+=1
# if pre[i]>z:
# break
# while j<n and l[n-j]<=z:
# j+=1
# if suf[j]>z:
# break
# # j-=1
# print(i,n-j)
# # break/
# if RMQ(st,n,i,j) == z:
# c = i+j-i+1
# x,y,z = i,j-i+1,n-c
# break
# else:
# i+=1
#
# else:
# i+=1
#
#
#
# if x!=-1:
# print('Yes')
# print(x,y,z)
# else:
# print('No')
# t = int(input())
#
# for _ in range(t):
#
# def debug(n):
# ans = []
# for i in range(1,n+1):
# for j in range(i+1,n+1):
# if (i*(j+1))%(j-i) == 0 :
# ans.append([i,j])
# return ans
#
#
# n = int(input())
# print(debug(n))
# import sys
# input = sys.stdin.readline
# import bisect
#
# t=int(input())
# for tests in range(t):
# n=int(input())
# A=list(map(int,input().split()))
#
# LEN = len(A)
# Sparse_table = [A]
#
# for i in range(LEN.bit_length()-1):
# j = 1<<i
# B = []
# for k in range(len(Sparse_table[-1])-j):
# B.append(min(Sparse_table[-1][k], Sparse_table[-1][k+j]))
# Sparse_table.append(B)
#
# def query(l,r): # [l,r)におけるminを求める.
# i=(r-l).bit_length()-1 # 何番目のSparse_tableを見るか.
#
# return min(Sparse_table[i][l],Sparse_table[i][r-(1<<i)]) # (1<<i)個あれば[l, r)が埋まるので, それを使ってminを求める.
#
# LMAX=[A[0]]
# for i in range(1,n):
# LMAX.append(max(LMAX[-1],A[i]))
#
# RMAX=A[-1]
#
# for i in range(n-1,-1,-1):
# RMAX=max(RMAX,A[i])
#
# x=bisect.bisect(LMAX,RMAX)
# #print(RMAX,x)
# print(RMAX,x,i)
# if x==0:
# continue
#
# v=min(x,i-1)
# if v<=0:
# continue
#
# if LMAX[v-1]==query(v,i)==RMAX:
# print("YES")
# print(v,i-v,n-i)
# break
#
# v-=1
# if v<=0:
# continue
# if LMAX[v-1]==query(v,i)==RMAX:
# print("YES")
# print(v,i-v,n-i)
# break
# else:
# print("NO")
#
#
#
#
#
#
#
#
#
# t = int(input())
#
# for _ in range(t):
#
# x = int(input())
# mini = 10**18
# n = ceil((-1 + sqrt(1+8*x))/2)
# for i in range(-100,1):
# z = x+-1*i
# z1 = (abs(i)*(abs(i)+1))//2
# z+=z1
# # print(z)
# n = ceil((-1 + sqrt(1+8*z))/2)
#
# y = (n*(n+1))//2
# # print(n,y,z,i)
# mini = min(n+y-z,mini)
# print(n+y-z,i)
#
#
# print(mini)
#
#
#
# n,m = map(int,input().split())
# l = []
# hash = defaultdict(int)
# for i in range(n):
# la = list(map(int,input().split()))[1:]
# l.append(set(la))
# # for i in la:
# # hash[i]+=1
#
# for i in range(n):
#
# for j in range(n):
# if i!=j:
#
# if len(l[i].intersection(l[j])) == 0:
# for k in range(n):
#
#
# else:
# break
#
#
#
#
#
#
# practicing segment_trees
# t = int(input())
#
# for _ in range(t):
# n = int(input())
# l = []
# for i in range(n):
# a,b = map(int,input().split())
# l.append([a,b])
#
# l.sort()
# n,m = map(int,input().split())
# l = list(map(int,input().split()))
#
# hash = defaultdict(int)
# for i in range(1,2**n,2):
# count = 0
# z1 = bin(l[i]|l[i-1])[2:]
# z1+='0'*(17-len(z1)) + z1
# for k in range(len(z1)):
# if z1[k] == '1':
# hash[k]+=1
# for i in range(m):
# a,b = map(int,input().split())
# a-=1
# init = a
# if a%2 == 0:
# a+=1
# z1 = bin(l[a]|l[a-1])[2:]
# z1+='0'*(17-len(z1)) + z1
# for k in range(len(z1)):
# if z1[k] == '1':
# hash[k]-=1
# l[init] = b
# a = init
# if a%2 == 0:
# a+=1
# z1 = bin(l[a]|l[a-1])[2:]
# z1+='0'*(17-len(z1)) + z1
# for k in range(len(z1)):
# if z1[k] == '1':
# hash[k]+=1
# ans = ''
# for k in range(17):
# if n%2 == 0:
# if hash[k]%2 == 0:
# ans+='0'
# else:
# ans+='1'
# else:
# if hash[k]%2 == 0:
# if hash[k]
#
#
#
def bfs1(p):
level = [10**18]*(n+1)
boo = [False]*(n+1)
par = [i for i in range(n+1)]
queue = [p]
boo[p] = True
level[p] = 0
while queue:
z = queue.pop(0)
for i in hash[z]:
if not boo[i]:
boo[i] = True
queue.append(i)
level[i] = level[z]+1
par[i] = z
return par,level
n = int(input())
l = list(map(int,input().split()))
hash = defaultdict(int)
for i in l:
hash[i]+=1
k = list(set(l))
k.sort()
ans = []
for i in k[::-1]:
if len(ans) == n:
break
z1 = 0
if hash[i] == 0:
continue
z2 = 0
for j in ans:
if gcd(j,i) == i:
z1+=1
# if i == 3:
# print(ans,z1)
z = -2*z1+sqrt((2*z1)**2+4*hash[i])
z//=2
for j in ans:
if z>0:
hash[gcd(i,j)]-=2*z
for j in range(int(z)):
ans.append(i)
print(*ans)
``` | output | 1 | 1,272 | 22 | 2,545 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
<image>
Given all the numbers of the GCD table G, restore array a.
Input
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
Output
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
Examples
Input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
42
Input
2
1 1 1 1
Output
1 1 | instruction | 0 | 1,273 | 22 | 2,546 |
Tags: constructive algorithms, greedy, number theory
Correct Solution:
```
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
import math
def binarySearch(num,l,r,x):
while l<=r:
mid=(l+r)//2
if num[mid]==x:
return mid
elif num[mid]<x:
l=mid+1
else:
r=mid-1
def quadratic(b,c):
e=pow(b,2)
f=e-(4*c)
d=math.sqrt(f)
ans=(((-1)*b)+d)//2
return ans
n=int(input())
arr=list(map(int,input().split()))
matrix=[[0]*n for i in range(n)]
a=max(arr)
dict1={}
for i in range(n**2):
if arr[i] in dict1.keys():
dict1[arr[i]]+=1
else:
dict1[arr[i]]=1
lis=[]
for i in dict1.keys():
lis.append([i,dict1[i]])
lis.sort(key=lambda x:x[0],reverse=False)
num=[]
p=0
for i in lis:
num.append(i[0])
p+=1
a=math.sqrt(lis[-1][1])
ans=[[lis[-1][0],a]]
lis[-1][1]=0
i=p-2
k=1
while i>=0:
if lis[i][1]>0:
count=0
for j in range(k):
temp=math.gcd(ans[j][0],lis[i][0])
if temp==lis[i][0]:
count+=(ans[j][1]*2)
if count==0:
ans.append([lis[i][0],math.sqrt(lis[i][1])])
lis[i][1]=0
else:
ans.append([lis[i][0],quadratic(count,(-1)*lis[i][1])])
lis[i][1]=0
for j in range(k):
temp=math.gcd(ans[j][0],ans[-1][0])
if temp!=ans[-1][0]:
ind=binarySearch(num,0,p-1,temp)
lis[ind][1]-=(2*ans[j][1]*ans[-1][1])
k+=1
i-=1
answer=[]
for i in ans:
for j in range(int(i[1])):
answer.append(i[0])
print(" ".join(str(x) for x in answer))
``` | output | 1 | 1,273 | 22 | 2,547 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
<image>
Given all the numbers of the GCD table G, restore array a.
Input
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
Output
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
Examples
Input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
42
Input
2
1 1 1 1
Output
1 1 | instruction | 0 | 1,274 | 22 | 2,548 |
Tags: constructive algorithms, greedy, number theory
Correct Solution:
```
def gcd(a,b):
if b==0: return a
return gcd(b,a%b)
n=int(input())
from collections import Counter
l=[int(i) for i in input().split()]
g=Counter(l)
ans=[]
while g:
m=max(g)
g[m]-=1
for i in ans:
g[gcd(m,i)]-=2
ans+=[m]
g+=Counter()
print(*ans)
``` | output | 1 | 1,274 | 22 | 2,549 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
<image>
Given all the numbers of the GCD table G, restore array a.
Input
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
Output
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
Examples
Input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
42
Input
2
1 1 1 1
Output
1 1 | instruction | 0 | 1,275 | 22 | 2,550 |
Tags: constructive algorithms, greedy, number theory
Correct Solution:
```
n=int(input())
u=[int(i) for i in input().split()]
d=dict()
for i in u:
if i in d:d[i]=1+d[i]
else:d[i]=1
def gcd(a,b):
c=0
while a!=0:
c=a
a=b%a
b=c
return(b)
t=[]
for i in d:t+=[i]
t.sort()
v=[]
while(len(v)<n):
x=t[len(t)-1]
for i in v:
y=gcd(x,i)
if d[y]>2:d[y]=d[y]-2
else:
d[y]=0
a=0
b=len(t)-1
while t[a]!=y and t[b]!=y:
c=(a+b)//2
if t[c]>=y:
b=c
else:
a=c
if t[a]==y:t.pop(a)
else:t.pop(b)
v+=[x]
if d[x]>1:d[x]=d[x]-1
else:t.pop(len(t)-1)
for i in v:
print(i,end=" ")
``` | output | 1 | 1,275 | 22 | 2,551 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
<image>
Given all the numbers of the GCD table G, restore array a.
Input
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
Output
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
Examples
Input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
42
Input
2
1 1 1 1
Output
1 1 | instruction | 0 | 1,276 | 22 | 2,552 |
Tags: constructive algorithms, greedy, number theory
Correct Solution:
```
from fractions import gcd
n = int(input())
a = sorted(list(map(int, input().split())))[::-1]
c = {}
l = []
for e in a:
if e not in c:
c[e] = 1
else:
c[e]+= 1
for e in a:
while n > 0 and c[e] > 0:
c[e]-= 1
for s in l:
u = gcd(e, s)
if u in c:
c[u]-= 2
l+=[e]
print(*l)
``` | output | 1 | 1,276 | 22 | 2,553 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
<image>
Given all the numbers of the GCD table G, restore array a.
Input
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
Output
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
Examples
Input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
42
Input
2
1 1 1 1
Output
1 1
Submitted Solution:
```
from collections import Counter
def gcd(a, b): return a if b == 0 else gcd(b, a % b)
n = int(input())
count = Counter()
for e in map(int, input().split()):
count[e] += 1
res = []
while sum(count.values()) > 0:
cur = max(count.keys())
count[cur] -= 1
if count[cur] == 0:
del count[cur]
for e in res:
g = gcd(cur, e)
count[g] -= 2
if count[g] == 0:
del count[g]
res.append(cur)
print(*res)
``` | instruction | 0 | 1,277 | 22 | 2,554 |
Yes | output | 1 | 1,277 | 22 | 2,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
<image>
Given all the numbers of the GCD table G, restore array a.
Input
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
Output
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
Examples
Input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
42
Input
2
1 1 1 1
Output
1 1
Submitted Solution:
```
from fractions import gcd
n = int(input())
a = sorted(list(map(int, input().split())))
c = {}
l = []
for e in a:
if e not in c:
c[e] = 1
else:
c[e]+= 1
for e in a[::-1]:
while n > 0 and c[e] > 0:
c[e]-= 1
for s in l:
u = gcd(e, s)
if u in c:
c[u]-= 2
l+=[e]
n-= 1
print(*l)
``` | instruction | 0 | 1,278 | 22 | 2,556 |
Yes | output | 1 | 1,278 | 22 | 2,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
<image>
Given all the numbers of the GCD table G, restore array a.
Input
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
Output
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
Examples
Input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
42
Input
2
1 1 1 1
Output
1 1
Submitted Solution:
```
import math
n = int(input())
vals = [int(x) for x in input().split()]
d={}
ans = []
for v in vals:
try:
d[v] += 1
except:
d[v] = 1
while(len(d)):
mx_key = max(d.keys())
for a in ans:
gcd = math.gcd(a, mx_key)
d[gcd] -= 2
if(d[gcd] == 0):
del d[gcd]
ans.append(mx_key)
d[mx_key] -= 1
if(d[mx_key] == 0):
del d[mx_key]
for x in ans:
print(x, end = ' ')
print()
``` | instruction | 0 | 1,279 | 22 | 2,558 |
Yes | output | 1 | 1,279 | 22 | 2,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
<image>
Given all the numbers of the GCD table G, restore array a.
Input
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
Output
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
Examples
Input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
42
Input
2
1 1 1 1
Output
1 1
Submitted Solution:
```
import sys,math as mt
input = sys.stdin.readline
from collections import Counter as cc
I = lambda : list(map(int,input().split()))
n,=I()
l=I()
an=[];rq=cc(l)
for i in range(n):
mx=max(rq)
rq[mx]-=1
for x in an:
rq[mt.gcd(x,mx)]-=2
an.append(mx)
rq+=cc()
print(*an)
``` | instruction | 0 | 1,280 | 22 | 2,560 |
Yes | output | 1 | 1,280 | 22 | 2,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
<image>
Given all the numbers of the GCD table G, restore array a.
Input
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
Output
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
Examples
Input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
42
Input
2
1 1 1 1
Output
1 1
Submitted Solution:
```
n = int(input())
vals = [int(x) for x in input().split()]
res = sorted(list(set(vals)),reverse=True)[0:n]
for r in res:
print(r, end=" ")
``` | instruction | 0 | 1,281 | 22 | 2,562 |
No | output | 1 | 1,281 | 22 | 2,563 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
<image>
Given all the numbers of the GCD table G, restore array a.
Input
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
Output
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
Examples
Input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
42
Input
2
1 1 1 1
Output
1 1
Submitted Solution:
```
n=int(input())
gcd_val=input().split()
for i in range(len(gcd_val)):
gcd_val[i]=int(gcd_val[i])
gcd_val=set(gcd_val)
gcd_val=list(gcd_val)
re=[]
i=len(gcd_val)-1
while(i>=0):
re.append(gcd_val[i])
if(len(re)==n):
break
i-=1
if(len(re)!=n):
re.append(re[len(re)-1])
for i in re:
print(i,end=" ")
``` | instruction | 0 | 1,282 | 22 | 2,564 |
No | output | 1 | 1,282 | 22 | 2,565 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
<image>
Given all the numbers of the GCD table G, restore array a.
Input
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
Output
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
Examples
Input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
42
Input
2
1 1 1 1
Output
1 1
Submitted Solution:
```
import math
def gcd(a,b):
while a%b:
a,b = b,a%b
return b
n = int(input())
arr = list(map(int,input().split()))
arr.sort()
l = 0
dic = {}
lst = []
for i in arr:
if i not in dic:
dic[i] = 1
lst.append(i)
l += 1
else:
dic[i] += 1
lst.reverse()
i = 1
while i<l:
if dic[lst[i]]>0:
for j in range(i):
if dic[lst[j]]>0:
x = gcd(lst[i],lst[j])
dic[x] -= 2
i += 1
for i in dic:
if dic[i]>=1:
x = int(math.sqrt(dic[i]))
for j in range(x):
print(i,end=' ')
``` | instruction | 0 | 1,283 | 22 | 2,566 |
No | output | 1 | 1,283 | 22 | 2,567 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
<image>
Given all the numbers of the GCD table G, restore array a.
Input
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
Output
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
Examples
Input
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
Output
4 3 6 2
Input
1
42
Output
42
Input
2
1 1 1 1
Output
1 1
Submitted Solution:
```
import math
def gcd(a,b):
while a%b:
a,b = b,a%b
return b
n = int(input())
arr = list(map(int,input().split()))
arr.sort()
l = 0
dic = {}
lst = []
for i in arr:
if i not in dic:
dic[i] = 1
lst.append(i)
l += 1
else:
dic[i] += 1
lst.reverse()
i = 1
while i<l:
for j in range(i):
if dic[lst[j]]>0 and dic[lst[i]]>0:
x = gcd(lst[i],lst[j])
dic[x] -= 2
i += 1
else:
for i in dic:
if dic[i]>=1:
x = int(math.sqrt(dic[i]))
for j in range(x):
print(i,end=' ')
``` | instruction | 0 | 1,284 | 22 | 2,568 |
No | output | 1 | 1,284 | 22 | 2,569 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a prime number p, n integers a_1, a_2, …, a_n, and an integer k.
Find the number of pairs of indexes (i, j) (1 ≤ i < j ≤ n) for which (a_i + a_j)(a_i^2 + a_j^2) ≡ k mod p.
Input
The first line contains integers n, p, k (2 ≤ n ≤ 3 ⋅ 10^5, 2 ≤ p ≤ 10^9, 0 ≤ k ≤ p-1). p is guaranteed to be prime.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ p-1). It is guaranteed that all elements are different.
Output
Output a single integer — answer to the problem.
Examples
Input
3 3 0
0 1 2
Output
1
Input
6 7 2
1 2 3 4 5 6
Output
3
Note
In the first example:
(0+1)(0^2 + 1^2) = 1 ≡ 1 mod 3.
(0+2)(0^2 + 2^2) = 8 ≡ 2 mod 3.
(1+2)(1^2 + 2^2) = 15 ≡ 0 mod 3.
So only 1 pair satisfies the condition.
In the second example, there are 3 such pairs: (1, 5), (2, 3), (4, 6). | instruction | 0 | 1,726 | 22 | 3,452 |
Tags: math, matrices, number theory, two pointers
Correct Solution:
```
n, p, k = map(int, input().split())
A = list(map(int, input().split()))
step4 = {}
for i in A:
h = (i ** 4) - (k * i)
h %= p
if h not in step4:
step4[h] = 0
step4[h] += 1
ans = 0
for u in step4:
ans += (step4[u]) * (step4[u] - 1) // 2
print(ans)
``` | output | 1 | 1,726 | 22 | 3,453 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a prime number p, n integers a_1, a_2, …, a_n, and an integer k.
Find the number of pairs of indexes (i, j) (1 ≤ i < j ≤ n) for which (a_i + a_j)(a_i^2 + a_j^2) ≡ k mod p.
Input
The first line contains integers n, p, k (2 ≤ n ≤ 3 ⋅ 10^5, 2 ≤ p ≤ 10^9, 0 ≤ k ≤ p-1). p is guaranteed to be prime.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ p-1). It is guaranteed that all elements are different.
Output
Output a single integer — answer to the problem.
Examples
Input
3 3 0
0 1 2
Output
1
Input
6 7 2
1 2 3 4 5 6
Output
3
Note
In the first example:
(0+1)(0^2 + 1^2) = 1 ≡ 1 mod 3.
(0+2)(0^2 + 2^2) = 8 ≡ 2 mod 3.
(1+2)(1^2 + 2^2) = 15 ≡ 0 mod 3.
So only 1 pair satisfies the condition.
In the second example, there are 3 such pairs: (1, 5), (2, 3), (4, 6). | instruction | 0 | 1,727 | 22 | 3,454 |
Tags: math, matrices, number theory, two pointers
Correct Solution:
```
n, p, k = map(int, input().split())
a = list(map(int, input().split()))
a = [(i ** 4 - i * k) % p for i in a]
c = {i: 0 for i in a}
for i in a:
c[i] += 1
s = 0
for i in c:
i = c[i]
s += (i * (i - 1)) // 2
print(s)
``` | output | 1 | 1,727 | 22 | 3,455 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a prime number p, n integers a_1, a_2, …, a_n, and an integer k.
Find the number of pairs of indexes (i, j) (1 ≤ i < j ≤ n) for which (a_i + a_j)(a_i^2 + a_j^2) ≡ k mod p.
Input
The first line contains integers n, p, k (2 ≤ n ≤ 3 ⋅ 10^5, 2 ≤ p ≤ 10^9, 0 ≤ k ≤ p-1). p is guaranteed to be prime.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ p-1). It is guaranteed that all elements are different.
Output
Output a single integer — answer to the problem.
Examples
Input
3 3 0
0 1 2
Output
1
Input
6 7 2
1 2 3 4 5 6
Output
3
Note
In the first example:
(0+1)(0^2 + 1^2) = 1 ≡ 1 mod 3.
(0+2)(0^2 + 2^2) = 8 ≡ 2 mod 3.
(1+2)(1^2 + 2^2) = 15 ≡ 0 mod 3.
So only 1 pair satisfies the condition.
In the second example, there are 3 such pairs: (1, 5), (2, 3), (4, 6). | instruction | 0 | 1,728 | 22 | 3,456 |
Tags: math, matrices, number theory, two pointers
Correct Solution:
```
n , p , k = map(int,input().split())
ar = list(map(int,input().split()))
ar = [(i**4 - k*i + p**4)%p for i in ar]
d = dict()
for i in ar:
if i in d:
d[i] += 1
else:
d[i] = 1
ans = 0
for key in d:
ans += (d[key]*(d[key] - 1) // 2);
print(ans)
``` | output | 1 | 1,728 | 22 | 3,457 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a prime number p, n integers a_1, a_2, …, a_n, and an integer k.
Find the number of pairs of indexes (i, j) (1 ≤ i < j ≤ n) for which (a_i + a_j)(a_i^2 + a_j^2) ≡ k mod p.
Input
The first line contains integers n, p, k (2 ≤ n ≤ 3 ⋅ 10^5, 2 ≤ p ≤ 10^9, 0 ≤ k ≤ p-1). p is guaranteed to be prime.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ p-1). It is guaranteed that all elements are different.
Output
Output a single integer — answer to the problem.
Examples
Input
3 3 0
0 1 2
Output
1
Input
6 7 2
1 2 3 4 5 6
Output
3
Note
In the first example:
(0+1)(0^2 + 1^2) = 1 ≡ 1 mod 3.
(0+2)(0^2 + 2^2) = 8 ≡ 2 mod 3.
(1+2)(1^2 + 2^2) = 15 ≡ 0 mod 3.
So only 1 pair satisfies the condition.
In the second example, there are 3 such pairs: (1, 5), (2, 3), (4, 6). | instruction | 0 | 1,729 | 22 | 3,458 |
Tags: math, matrices, number theory, two pointers
Correct Solution:
```
def Sum(n):
"""
Entrada:
n -> cantidad de elementos a asociar
Descripción:
Dada la cantidad de elementos a asociar, encontrar el número de combinaciones de tamaño 2 que
se pueden formar
Salida:
Número de combinaciones de tamaño 2 que se pueden formar
"""
return n*(n-1)//2
def Solver(p, k, a):
"""
Entrada:
p -> primo en base al que se calcula el módulo
k -> entero k
a -> lista de enteros para hallar la cantidad de pares
Descripción:
Dado una lista de enteros a, encontrar el número de pares (ai, aj) que cumplen que:
(ai^4 - k*ai) % p = (aj^4 - k*aj) % p
Salida:
sol -> La cantidad de pares que cumplen la condición
"""
aux = [] #lista que guardará en la posición i el resultado de calcular (a[i]^4 - k*a[i]) % p
for i in a:
aux.append((i**4 - i*k)%p)
dic = {} #diccionario auxiliar que guardará en la llave i la cantiad de ocurrencias de i en aux
for i in aux:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
val = list(dic.values()) #Se hace una lista donde a la posición i le corresponde el valor del la llave i en dic
sol = 0
for i in val:
if i > 1: #Si el valor es mayor que 1 se halla la cantidad de pares que se pueden formar
sol += Sum(i)
return sol
def Main():
n, p, k = map(int, input().split())
a = list(map(int, input().split()))
sol = Solver(p, k, a)
print(sol)
Main()
``` | output | 1 | 1,729 | 22 | 3,459 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a prime number p, n integers a_1, a_2, …, a_n, and an integer k.
Find the number of pairs of indexes (i, j) (1 ≤ i < j ≤ n) for which (a_i + a_j)(a_i^2 + a_j^2) ≡ k mod p.
Input
The first line contains integers n, p, k (2 ≤ n ≤ 3 ⋅ 10^5, 2 ≤ p ≤ 10^9, 0 ≤ k ≤ p-1). p is guaranteed to be prime.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ p-1). It is guaranteed that all elements are different.
Output
Output a single integer — answer to the problem.
Examples
Input
3 3 0
0 1 2
Output
1
Input
6 7 2
1 2 3 4 5 6
Output
3
Note
In the first example:
(0+1)(0^2 + 1^2) = 1 ≡ 1 mod 3.
(0+2)(0^2 + 2^2) = 8 ≡ 2 mod 3.
(1+2)(1^2 + 2^2) = 15 ≡ 0 mod 3.
So only 1 pair satisfies the condition.
In the second example, there are 3 such pairs: (1, 5), (2, 3), (4, 6). | instruction | 0 | 1,730 | 22 | 3,460 |
Tags: math, matrices, number theory, two pointers
Correct Solution:
```
n, p, k = map(int, input().split())
a = list(map(int, input().split()))
b = dict()
ans = 0
for i in a:
j = (i ** 4 - k * i) % p
c = b.get(j, 0)
ans += c
b[j] = c + 1
print(ans)
``` | output | 1 | 1,730 | 22 | 3,461 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.