message stringlengths 2 59.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 37 108k | cluster float64 20 20 | __index_level_0__ int64 74 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive integer a is given. Baron Munchausen claims that he knows such a positive integer n that if one multiplies n by a, the sum of its digits decreases a times. In other words, S(an) = S(n)/a, where S(x) denotes the sum of digits of the number x.
Find out if what Baron told can be true.
Input
The only line contains a single integer a (2 β€ a β€ 10^3).
Output
If there is no such number n, print -1.
Otherwise print any appropriate positive integer n. Your number must not consist of more than 5β
10^5 digits. We can show that under given constraints either there is no answer, or there is an answer no longer than 5β
10^5 digits.
Examples
Input
2
Output
6
Input
3
Output
6669
Input
10
Output
-1
Submitted Solution:
```
#!/bin/pypy3
from itertools import*
from timeit import*
#a={
#2:6
#,3:6669
#,4:75
#,7:14286
#,8:125
#}
#print(a.get(int(input()),-1))
S=lambda x:sum(map(int,str(x)))
def solve(a):
for e,first in product(range(0,100),range(1,600)):
x=first*10**e
z=x%a
if z: x+=a-z
#assert x%a==0
if S(x//a)==S(x)*a: return x
x+=a
#assert x%a==0
if S(x//a)==S(x)*a: return x
return -1
#for a in range(2,1000):
#print(timeit(lambda: print(a,solve(a)),number=1))
print(solve(int(input())))
``` | instruction | 0 | 101,236 | 20 | 202,472 |
No | output | 1 | 101,236 | 20 | 202,473 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive integer a is given. Baron Munchausen claims that he knows such a positive integer n that if one multiplies n by a, the sum of its digits decreases a times. In other words, S(an) = S(n)/a, where S(x) denotes the sum of digits of the number x.
Find out if what Baron told can be true.
Input
The only line contains a single integer a (2 β€ a β€ 10^3).
Output
If there is no such number n, print -1.
Otherwise print any appropriate positive integer n. Your number must not consist of more than 5β
10^5 digits. We can show that under given constraints either there is no answer, or there is an answer no longer than 5β
10^5 digits.
Examples
Input
2
Output
6
Input
3
Output
6669
Input
10
Output
-1
Submitted Solution:
```
import random
def dsum(a):
return sum(int(digit) for digit in str(a))
def f(v, n):
return dsum(v // n) - n * dsum(v)
def make_number(a, n):
for q in range(5):
for M in range(30, (15 + q) * n + 2000, 47):
v = 10**15 + 10**M
for i in range(a):
v = v + 10 ** random.randint(16, M-1)
if v % n == 0:
if f(v, n) >= 0:
return v
return -1
def solve(n):
v = -1
z = 10
if n % 9 == 0:
z = z * 9
for a in range(3, z):
if n % 9 == 0 and (a+2) % 9 != 0:
continue
b = make_number(a, n)
if b > 0:
v = b
break
if n == 1:
v == 1
if v == -1:
assert False
#print(n, "failfailfailfailfailfailfailfailfailfailfailfailfailfailfailfailfailfailfailf")
return -1
else:
for b in range(1, 200):
if f(b*n, n) >= 0:
continue
if f(v,n) + f(b*n, n) >= 0:
v = int(str(v) + str(b*n))
did = True
if f(v, n) == 0:
return v
diff1 = f(v, n)
q = n
while f(q, n) >= 0:
q = q + n
diff2 = f(q, n)
ans = ""
for x in range(-diff2):
ans += str(v)
for x in range(diff1):
ans += str(q)
v = int(ans)
# print(f(v,n))
return v
def bad(n):
while n % 2 == 0:
n = n // 2
while n % 5 == 0:
n = n // 5
if n == 1:
return True
else:
return False
def real_solve(r):
if r == 1 or r == 2 or r == 4 or r == 8 or not bad(r):
return solve(r)
else:
return -1
def test():
for r in range(1, 1000):
solve(r)
def cf():
a = int(input())
ans = real_solve(a)
print(ans)
random.seed(48)
cf()
``` | instruction | 0 | 101,237 | 20 | 202,474 |
No | output | 1 | 101,237 | 20 | 202,475 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
* 30 is a good number: 30 = 3^3 + 3^1,
* 1 is a good number: 1 = 3^0,
* 12 is a good number: 12 = 3^2 + 3^1,
* but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
* 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
* 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n β€ m) that m is a good number.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The only line of the query contains one integer n (1 β€ n β€ 10^4).
Output
For each query, print such smallest integer m (where n β€ m) that m is a good number.
Example
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683 | instruction | 0 | 101,302 | 20 | 202,604 |
Tags: brute force, greedy, implementation
Correct Solution:
```
import math as ma
q=int(input())
for w in range(q):
n=int(input())
m=n
i=ma.ceil(ma.log(n,3))
j=i-1
k=0
r=n
while m>=0 and j>=0:
if m>=3**j:
m=m-3**j
else:
k=j
r=n-m
j=j-1
if m==0:
print(n)
elif k>0:
print(r+3**k)
else:
print(3**i)
``` | output | 1 | 101,302 | 20 | 202,605 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
* 30 is a good number: 30 = 3^3 + 3^1,
* 1 is a good number: 1 = 3^0,
* 12 is a good number: 12 = 3^2 + 3^1,
* but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
* 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
* 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n β€ m) that m is a good number.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The only line of the query contains one integer n (1 β€ n β€ 10^4).
Output
For each query, print such smallest integer m (where n β€ m) that m is a good number.
Example
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683 | instruction | 0 | 101,303 | 20 | 202,606 |
Tags: brute force, greedy, implementation
Correct Solution:
```
#import resource
import sys
#resource.setrlimit(resource.RLIMIT_STACK, (2**29, -1))
sys.setrecursionlimit(10 ** 7)
from collections import deque
import math
pow3 = [1]
aux = 1
for i in range(9):
aux *= 3
pow3.append(aux)
a = []
for op in range((1 << 10)):
elem = 0
for i in range(len(pow3)):
if ( (op >> i) & 1 ):
elem += pow3[i]
a.append(elem)
t = int(input())
for _ in range(t):
n = int(input())
lo, hi = 0, len(a) - 1
while ( hi - lo > 1 ):
mi = lo + ( hi - lo ) // 2
if (n > a[mi]):
lo = mi
else:
hi = mi
print(a[hi])
``` | output | 1 | 101,303 | 20 | 202,607 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
* 30 is a good number: 30 = 3^3 + 3^1,
* 1 is a good number: 1 = 3^0,
* 12 is a good number: 12 = 3^2 + 3^1,
* but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
* 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
* 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n β€ m) that m is a good number.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The only line of the query contains one integer n (1 β€ n β€ 10^4).
Output
For each query, print such smallest integer m (where n β€ m) that m is a good number.
Example
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683 | instruction | 0 | 101,304 | 20 | 202,608 |
Tags: brute force, greedy, implementation
Correct Solution:
```
import math
q = int(input())
pw = [3**0]
for i in range(1, 10):
pw.append(3**i)
length = len(pw)
for j in range(length-1):
pw.append(3**i+pw[j])
for _ in range(q):
n = int(input())
for i in range(len(pw)):
if n<=pw[i]:
print (pw[i])
break
``` | output | 1 | 101,304 | 20 | 202,609 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
* 30 is a good number: 30 = 3^3 + 3^1,
* 1 is a good number: 1 = 3^0,
* 12 is a good number: 12 = 3^2 + 3^1,
* but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
* 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
* 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n β€ m) that m is a good number.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The only line of the query contains one integer n (1 β€ n β€ 10^4).
Output
For each query, print such smallest integer m (where n β€ m) that m is a good number.
Example
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683 | instruction | 0 | 101,305 | 20 | 202,610 |
Tags: brute force, greedy, implementation
Correct Solution:
```
arr = [3**i for i in range(45)]
for i in range(int(input())):
n, hi = int(input()), sum(arr)
for j in reversed(arr):
if hi - j >= n:
hi -= j
print(hi)
``` | output | 1 | 101,305 | 20 | 202,611 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
* 30 is a good number: 30 = 3^3 + 3^1,
* 1 is a good number: 1 = 3^0,
* 12 is a good number: 12 = 3^2 + 3^1,
* but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
* 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
* 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n β€ m) that m is a good number.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The only line of the query contains one integer n (1 β€ n β€ 10^4).
Output
For each query, print such smallest integer m (where n β€ m) that m is a good number.
Example
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683 | instruction | 0 | 101,306 | 20 | 202,612 |
Tags: brute force, greedy, implementation
Correct Solution:
```
#this is wild game
def gcd(a:int,b:int) -> int:
return a if b==0 else gcd(b,a%b)
def conv(n:int,b:int=3)->int:
a=0
p=1
while n:
a+=(n%b)*p
p*=10
n//=b
return a
def solve(n:int)->int:
p=0
s=""
while n:
l=n%10
if p:
l=(l+1)%3
if l==0:
p=1
s+="0"
elif l==1:
p=0
s="0"*len(s)+"1"
else:
p=1
s+="0"
else:
if l==2:
p=1
s+="0"
else:
p=0
s+=str(l)
n//=10
if p:
s="0"*len(s)+"1"
# print(s[::-1])
return s[::-1]
for _ in range(int(input())):
print(int(solve(conv(int(input()))),3))
``` | output | 1 | 101,306 | 20 | 202,613 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
* 30 is a good number: 30 = 3^3 + 3^1,
* 1 is a good number: 1 = 3^0,
* 12 is a good number: 12 = 3^2 + 3^1,
* but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
* 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
* 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n β€ m) that m is a good number.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The only line of the query contains one integer n (1 β€ n β€ 10^4).
Output
For each query, print such smallest integer m (where n β€ m) that m is a good number.
Example
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683 | instruction | 0 | 101,307 | 20 | 202,614 |
Tags: brute force, greedy, implementation
Correct Solution:
```
def b10to3(num):
digs = []
num = int(num)
while num > 0:
digs.append(num % 3)
num //= 3
return list(reversed(digs))
def b3to10(num):
sum = 0
for i in num:
sum = sum * 3 + i
return str(sum)
for i in range(int(input())):
num = input()
digs = [0] + b10to3(num)
# 0100200121
# take the MSB which is 2, find something to its left which is 0, increment it and set rest to 0
pos_0, pos_2 = -1, -1
for i in range(len(digs)):
if digs[i] == 2:
pos_2 = i
break
if digs[i] == 0:
pos_0 = i
if pos_2 != -1:
digs[pos_0] = 1
for i in range(pos_0 + 1, len(digs)):
digs[i] = 0
print(b3to10(digs))
``` | output | 1 | 101,307 | 20 | 202,615 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
* 30 is a good number: 30 = 3^3 + 3^1,
* 1 is a good number: 1 = 3^0,
* 12 is a good number: 12 = 3^2 + 3^1,
* but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
* 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
* 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n β€ m) that m is a good number.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The only line of the query contains one integer n (1 β€ n β€ 10^4).
Output
For each query, print such smallest integer m (where n β€ m) that m is a good number.
Example
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683 | instruction | 0 | 101,308 | 20 | 202,616 |
Tags: brute force, greedy, implementation
Correct Solution:
```
q = int(input())
def base_10_to_n(x, n):
if x//n:
return base_10_to_n(x//n, n)+str(x%n)
else:
return str(x%n)
for _ in range(q):
n = int(input())
s = list(base_10_to_n(n, 3))
#print(s)
s.reverse()
pos0 = -1
pos2 = -1
flag = False
for i in range(len(s)):
if s[i] == '2':
pos2 = i
flag = True
if s[i] == '0' and flag:
pos0 = i
flag = False
if pos2 != -1:
if pos0 > pos2:
temp = ['0']*(pos0)+['1']+s[pos0+1:]
temp = list(map(int, temp))
ans = 0
for i, d in enumerate(temp):
ans += d*3**i
else:
ans = 3**(len(s))
else:
ans = n
print(ans)
``` | output | 1 | 101,308 | 20 | 202,617 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
* 30 is a good number: 30 = 3^3 + 3^1,
* 1 is a good number: 1 = 3^0,
* 12 is a good number: 12 = 3^2 + 3^1,
* but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
* 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
* 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n β€ m) that m is a good number.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The only line of the query contains one integer n (1 β€ n β€ 10^4).
Output
For each query, print such smallest integer m (where n β€ m) that m is a good number.
Example
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683 | instruction | 0 | 101,309 | 20 | 202,618 |
Tags: brute force, greedy, implementation
Correct Solution:
```
import math
i = 0
s = 0
v = []
while s < 1e18:
s += pow(3,i)
v.append(s)
i += 1
q = int(input())
for i in range(q):
n = int(input())
k = 0
while v[k] < n:
k += 1
ans = v[k]
l = k
while l >= 0:
if ans - pow(3,l) >= n:
ans -= pow(3,l);
l -= 1
print(ans)
``` | output | 1 | 101,309 | 20 | 202,619 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
* 30 is a good number: 30 = 3^3 + 3^1,
* 1 is a good number: 1 = 3^0,
* 12 is a good number: 12 = 3^2 + 3^1,
* but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
* 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
* 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n β€ m) that m is a good number.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The only line of the query contains one integer n (1 β€ n β€ 10^4).
Output
For each query, print such smallest integer m (where n β€ m) that m is a good number.
Example
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
val = 0
i = 0
while val <= n:
val += 3 ** i
i += 1
# print("max val: {} {}".format(val, i))
while i >= 0:
if val - (3 ** i) >= n:
val -= 3 ** i
# print("updated val: {} {}".format(val, i))
i -= 1
print(val)
``` | instruction | 0 | 101,310 | 20 | 202,620 |
Yes | output | 1 | 101,310 | 20 | 202,621 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
* 30 is a good number: 30 = 3^3 + 3^1,
* 1 is a good number: 1 = 3^0,
* 12 is a good number: 12 = 3^2 + 3^1,
* but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
* 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
* 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n β€ m) that m is a good number.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The only line of the query contains one integer n (1 β€ n β€ 10^4).
Output
For each query, print such smallest integer m (where n β€ m) that m is a good number.
Example
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683
Submitted Solution:
```
a = [1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147,
531441, 1594323, 4782969, 14348907, 43046721, 129140163, 387420489,
1162261467, 3486784401, 10460353203, 31381059609, 94143178827,
282429536481, 847288609443, 2541865828329, 7625597484987, 22876792454961,
68630377364883, 205891132094649, 617673396283947, 1853020188851841,
5559060566555523, 16677181699666569, 50031545098999707, 150094635296999121,
450283905890997363, 1350851717672992089]
sum3 = 2026277576509488133
for _ in range(int(input())):
ans = sum3
n = int(input())
for x in a[::-1]:
if ans - x >= n : ans -= x
print(ans)
``` | instruction | 0 | 101,311 | 20 | 202,622 |
Yes | output | 1 | 101,311 | 20 | 202,623 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
* 30 is a good number: 30 = 3^3 + 3^1,
* 1 is a good number: 1 = 3^0,
* 12 is a good number: 12 = 3^2 + 3^1,
* but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
* 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
* 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n β€ m) that m is a good number.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The only line of the query contains one integer n (1 β€ n β€ 10^4).
Output
For each query, print such smallest integer m (where n β€ m) that m is a good number.
Example
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683
Submitted Solution:
```
import sys
input=sys.stdin.readline
q=int(input())
for _ in range(q):
m=int(input())
n=m
sansin=[]
while True:
sansin.append(n%3)
n//=3
if n<3:
sansin.append(n)
break
f=1
x=0
for i in range(len(sansin)):
if sansin[i]==2:
f=0
x=i
if f:
print(m)
else:
sansin.insert(len(sansin),0)
ans=0
ff=1
for i in range(x,len(sansin)):
if sansin[i]==0 and ff:
ans+=(3**i)
ff=0
elif ff==0:
ans+=(sansin[i]*(3**i))
print(ans)
``` | instruction | 0 | 101,312 | 20 | 202,624 |
Yes | output | 1 | 101,312 | 20 | 202,625 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
* 30 is a good number: 30 = 3^3 + 3^1,
* 1 is a good number: 1 = 3^0,
* 12 is a good number: 12 = 3^2 + 3^1,
* but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
* 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
* 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n β€ m) that m is a good number.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The only line of the query contains one integer n (1 β€ n β€ 10^4).
Output
For each query, print such smallest integer m (where n β€ m) that m is a good number.
Example
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683
Submitted Solution:
```
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())
import math
q=ii()
for i in range(q):
n=ii()
c=0
while pow(3,c)<n:
c+=1
if pow(3,c)==n:
print(pow(3,c))
continue
ans=pow(3,c)
b=1<<(c-1)+1
for i in range(b):
d=pow(3,c-1)
for j in range(c-1):
if (i>>j)%2:
d+=pow(3,j)
if d>=n:
ans=d
break
print(ans)
``` | instruction | 0 | 101,313 | 20 | 202,626 |
Yes | output | 1 | 101,313 | 20 | 202,627 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
* 30 is a good number: 30 = 3^3 + 3^1,
* 1 is a good number: 1 = 3^0,
* 12 is a good number: 12 = 3^2 + 3^1,
* but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
* 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
* 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n β€ m) that m is a good number.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The only line of the query contains one integer n (1 β€ n β€ 10^4).
Output
For each query, print such smallest integer m (where n β€ m) that m is a good number.
Example
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683
Submitted Solution:
```
q = int(input())
def base_10_to_n(x, n):
if (int(x/n)):
return base_10_to_n(int(x/n), n)+str(x%n)
return str(x%n)
for _ in range(q):
n = int(input())
s = list(base_10_to_n(n, 3))
s.reverse()
pos0 = -1
pos2 = -1
for i in range(len(s)):
if s[i] == '2':
pos2 = i
if s[i] == 0 and pos2 != -1:
pos0 = i
if pos2 != -1:
if pos0 > pos2:
temp = ['0']*(pos0)+['1']+s[pos0+1:]
temp.reverse()
temp = list(map(int, ans))
ans = 0
for i, d in enumerate(temp):
ans += d**i
else:
ans = 3**(len(s))
else:
ans = n
print(ans)
``` | instruction | 0 | 101,314 | 20 | 202,628 |
No | output | 1 | 101,314 | 20 | 202,629 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
* 30 is a good number: 30 = 3^3 + 3^1,
* 1 is a good number: 1 = 3^0,
* 12 is a good number: 12 = 3^2 + 3^1,
* but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
* 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
* 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n β€ m) that m is a good number.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The only line of the query contains one integer n (1 β€ n β€ 10^4).
Output
For each query, print such smallest integer m (where n β€ m) that m is a good number.
Example
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683
Submitted Solution:
```
#import sys
# import math
# import bisect
# import collections
# import itertools
# #from sys import stdin,stdout
# from math import gcd,floor,sqrt,log
# from collections import defaultdict as dd, Counter as ctr
# from bisect import bisect_left as bl, bisect_right as br
# from itertools import permutations as pr, combinations as cb
#sys.setrecursionlimit(100000000)
#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$
inp = lambda: int(input())
# strng = lambda: input().strip()
# jn = lambda x,l: x.join(map(str,l))
# strl = lambda: list(input().strip())
# mul = lambda: map(int,input().strip().split())
# mulf = lambda: map(float,input().strip().split())
seq = lambda: list(map(int,input().strip().split()))
#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$
# p_inf = float('inf')
# n_inf = float('-inf')
#To find mex
# def mex(arr):
# nList = set(arr)
# mex = 0
# while mex in nList:
# mex += 1
# return(mex)
def count(n):
cnt = 0
while n > 1:
n = n // 3
cnt += 1
return(cnt)
def results(n):
cnt = count(n)
if(3 ** cnt == n):
return(n)
else:
tmp = 3 ** cnt
i = 0
while tmp <= n and i < cnt:
tmp += 3 ** i
i += 1
if(tmp >= n):
return(tmp)
else:
return(3 ** (cnt + 1))
def main():
t = inp()
for _ in range(t):
n = inp()
result = results(n)
print(result)
if __name__ == '__main__':
main()
``` | instruction | 0 | 101,315 | 20 | 202,630 |
No | output | 1 | 101,315 | 20 | 202,631 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
* 30 is a good number: 30 = 3^3 + 3^1,
* 1 is a good number: 1 = 3^0,
* 12 is a good number: 12 = 3^2 + 3^1,
* but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
* 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
* 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n β€ m) that m is a good number.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The only line of the query contains one integer n (1 β€ n β€ 10^4).
Output
For each query, print such smallest integer m (where n β€ m) that m is a good number.
Example
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683
Submitted Solution:
```
def add_my_bit(t, s):
if t[s] == 2:
t[s] = 0
if s == len(t) - 1:
t.append(1)
else:
add_my_bit(t, s + 1)
elif t[s] == 1:
t[s] = 2
elif t[s] == 0:
t[s] = 1
return t
for _ in range(int(input())):
a = int(input())
n = a
t = []
k = 0
while a != 0:
t.append(a% 3)
a = a//3
u = len(t)
if 2 in t:
w = t[::-1].index(2)
if len(t) - w <= len(t) - 1 and t[len(t) - w] == 0:
t[len(t) - w] = 1
for rv in range(len(t[: len(t) - w])):
t[rv] = 0
while 2 in t:
p = t.index(2)
add_my_bit(t, p)
v = len(t)
if u < v:
k = k + 3**(v - 1)
else:
for j in range(len(t)):
k = k + (3**j)*t[j]
else:
k = n
print(k)
``` | instruction | 0 | 101,316 | 20 | 202,632 |
No | output | 1 | 101,316 | 20 | 202,633 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the maximum value of n.
You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.
The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).
For example:
* 30 is a good number: 30 = 3^3 + 3^1,
* 1 is a good number: 1 = 3^0,
* 12 is a good number: 12 = 3^2 + 3^1,
* but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
* 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
* 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).
Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.
For the given positive integer n find such smallest m (n β€ m) that m is a good number.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 β€ q β€ 500) β the number of queries. Then q queries follow.
The only line of the query contains one integer n (1 β€ n β€ 10^4).
Output
For each query, print such smallest integer m (where n β€ m) that m is a good number.
Example
Input
7
1
2
6
13
14
3620
10000
Output
1
3
9
13
27
6561
19683
Submitted Solution:
```
queries = int(input())
for q in range(queries):
n = int(input())
p = 39
dp = [0] * p
r = n
for i in range(p)[::-1]:
dp[i], r = divmod(r, 3**i)
if all(i <= 1 for i in dp):
print(n)
else:
r = p
while dp[r-1] == 0:
r -= 1
print(3 ** r)
``` | instruction | 0 | 101,317 | 20 | 202,634 |
No | output | 1 | 101,317 | 20 | 202,635 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Anna got the following task at school: to arrange several numbers in a circle so that any two neighboring numbers differs exactly by 1. Anna was given several numbers and arranged them in a circle to fulfill the task. Then she wanted to check if she had arranged the numbers correctly, but at this point her younger sister Maria came and shuffled all numbers. Anna got sick with anger but what's done is done and the results of her work had been destroyed. But please tell Anna: could she have hypothetically completed the task using all those given numbers?
Input
The first line contains an integer n β how many numbers Anna had (3 β€ n β€ 105). The next line contains those numbers, separated by a space. All numbers are integers and belong to the range from 1 to 109.
Output
Print the single line "YES" (without the quotes), if Anna could have completed the task correctly using all those numbers (using all of them is necessary). If Anna couldn't have fulfilled the task, no matter how hard she would try, print "NO" (without the quotes).
Examples
Input
4
1 2 3 2
Output
YES
Input
6
1 1 2 2 2 3
Output
YES
Input
6
2 4 1 1 2 2
Output
NO | instruction | 0 | 101,335 | 20 | 202,670 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n= int(input())
a = list(map(int,input().split()))
a.sort()
mm=a[0]
b=list(map(lambda x: x-mm, a))
if b[-1]>n or n%2==1:
print('NO')
else:
c=[0]*(b[-1]+1)
for el in b:
c[el]+=1
for i in range(1,len(c)):
c[i] = c[i]-c[i-1]
c[i-1]=0
#print(c)
if i!=len(c)-1:
if (c[i]==0 or c[i]<0):
print('NO')
break
else:
if c[i]!=0:
print('NO')
break
else:
print('YES')
# Sat Oct 17 2020 10:31:31 GMT+0300 (ΠΠΎΡΠΊΠ²Π°, ΡΡΠ°Π½Π΄Π°ΡΡΠ½ΠΎΠ΅ Π²ΡΠ΅ΠΌΡ)
``` | output | 1 | 101,335 | 20 | 202,671 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Anna got the following task at school: to arrange several numbers in a circle so that any two neighboring numbers differs exactly by 1. Anna was given several numbers and arranged them in a circle to fulfill the task. Then she wanted to check if she had arranged the numbers correctly, but at this point her younger sister Maria came and shuffled all numbers. Anna got sick with anger but what's done is done and the results of her work had been destroyed. But please tell Anna: could she have hypothetically completed the task using all those given numbers?
Input
The first line contains an integer n β how many numbers Anna had (3 β€ n β€ 105). The next line contains those numbers, separated by a space. All numbers are integers and belong to the range from 1 to 109.
Output
Print the single line "YES" (without the quotes), if Anna could have completed the task correctly using all those numbers (using all of them is necessary). If Anna couldn't have fulfilled the task, no matter how hard she would try, print "NO" (without the quotes).
Examples
Input
4
1 2 3 2
Output
YES
Input
6
1 1 2 2 2 3
Output
YES
Input
6
2 4 1 1 2 2
Output
NO | instruction | 0 | 101,336 | 20 | 202,672 |
Tags: constructive algorithms, implementation
Correct Solution:
```
import sys
n = int(input())
c = {}
a = [int(i) for i in input().split()]
maxi = max(a)
for i in a:
c[i] = c.get(i, 0) + 1
l = sorted(c)
t = l[:-1]
for u in t:
if u + 1 not in c:
print("NO")
sys.exit()
c[u + 1] -= c[u]
if 0 > c[u + 1]:
print("NO")
sys.exit()
arr = list(c.values())
if arr.count(0) == 1 and c[maxi] == 0:
print("YES")
else:
print("NO")
# Fri Oct 16 2020 22:20:09 GMT+0300 (ΠΠΎΡΠΊΠ²Π°, ΡΡΠ°Π½Π΄Π°ΡΡΠ½ΠΎΠ΅ Π²ΡΠ΅ΠΌΡ)
``` | output | 1 | 101,336 | 20 | 202,673 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: β ai β);
* round element aj to the nearest integer that isn't less than aj (assign to aj: β aj β).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 β€ n β€ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 β€ ai β€ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number β the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | instruction | 0 | 101,497 | 20 | 202,994 |
Tags: dp, greedy, implementation, math
Correct Solution:
```
n = int(input())
a = list(map(lambda x: int(x.split('.')[1]), input().split()))
s = sum(a) - n * 1000
zero_cnt = a.count(0)
min_add = max(0, zero_cnt - n)
max_add = min(n, zero_cnt)
answ = min(abs(s + i * 1000) for i in range(min_add, max_add + 1))
print('{:d}.{:0>3d}'.format(answ // 1000, answ % 1000))
``` | output | 1 | 101,497 | 20 | 202,995 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: β ai β);
* round element aj to the nearest integer that isn't less than aj (assign to aj: β aj β).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 β€ n β€ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 β€ ai β€ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number β the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | instruction | 0 | 101,498 | 20 | 202,996 |
Tags: dp, greedy, implementation, math
Correct Solution:
```
n, k, s = int(input()), 0, 0
for i in input().split():
j = int(i[-3: ])
if j == 0: k += 1
else: s += j
c = s // 1000 + int(s % 1000 > 500)
a, b = max(0, n - k), min(2 * n - k, n)
if a <= c <= b: s = abs(c * 1000 - s)
else: s = min(abs(a * 1000 - s), abs(b * 1000 - s))
print(str(s // 1000) + '.' + str(s % 1000).zfill(3))
``` | output | 1 | 101,498 | 20 | 202,997 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: β ai β);
* round element aj to the nearest integer that isn't less than aj (assign to aj: β aj β).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 β€ n β€ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 β€ ai β€ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number β the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | instruction | 0 | 101,499 | 20 | 202,998 |
Tags: dp, greedy, implementation, math
Correct Solution:
```
n, t = int(input()), [int(i[-3: ]) for i in input().split()]
k, s = t.count(0), sum(t)
c = s // 1000 + int(s % 1000 > 500)
a, b = max(0, n - k), min(2 * n - k, n)
if a <= c <= b: s = abs(c * 1000 - s)
else: s = min(abs(a * 1000 - s), abs(b * 1000 - s))
print(str(s // 1000) + '.' + str(s % 1000).zfill(3))
``` | output | 1 | 101,499 | 20 | 202,999 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: β ai β);
* round element aj to the nearest integer that isn't less than aj (assign to aj: β aj β).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 β€ n β€ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 β€ ai β€ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number β the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | instruction | 0 | 101,500 | 20 | 203,000 |
Tags: dp, greedy, implementation, math
Correct Solution:
```
from math import ceil, floor
N = int(input())
Nums = list(map(float, input().split()))
Zeros = 0
Sum = 0.0
for Num in Nums:
if Num - floor(Num) == 0:
Zeros += 1
else:
Sum += Num - floor(Num)
Best = float(10 ** 9)
for i in range(Zeros + 1):
Best = min(Best, abs(N - Zeros + i - Sum))
Best = str(float(round(Best, 3)))
Index = Best.find('.')
print(Best + '0' * (4 - (len(Best) - Index)))
``` | output | 1 | 101,500 | 20 | 203,001 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: β ai β);
* round element aj to the nearest integer that isn't less than aj (assign to aj: β aj β).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 β€ n β€ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 β€ ai β€ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number β the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | instruction | 0 | 101,501 | 20 | 203,002 |
Tags: dp, greedy, implementation, math
Correct Solution:
```
import math
n = int(input())
nums = input().split()
float_nums = [float(ele) for ele in nums]
diff = 0.000
count = 0
for x in float_nums:
diff += x - math.floor(x)
if math.ceil(x) > math.floor(x):
count += 1
min_num = max(0, count - n)
max_num = min(count, n)
if math.ceil(diff) - diff <= 0.5:
t = math.ceil(diff)
else:
t = math.floor(diff)
if t < min_num:
print("{0:.3f}".format(min_num - diff))
elif t > max_num:
print("{0:.3f}".format(diff - max_num))
else:
print("{0:.3f}".format(math.fabs(diff - t)))
``` | output | 1 | 101,501 | 20 | 203,003 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: β ai β);
* round element aj to the nearest integer that isn't less than aj (assign to aj: β aj β).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 β€ n β€ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 β€ ai β€ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number β the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | instruction | 0 | 101,502 | 20 | 203,004 |
Tags: dp, greedy, implementation, math
Correct Solution:
```
n = int(input())
l = list(map(float, input().split()))
l = sorted([x - int(x) for x in l if x - int(x) != 0])
o = 2*n - len(l)
su = sum(l)
ans = 0xFFFFFFFFFFFFFFF
for i in range(n + 1):
if i + o >= n:
ans = min(ans, abs(i-su))
print("%.3f" % ans)
# Made By Mostafa_Khaled
``` | output | 1 | 101,502 | 20 | 203,005 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: β ai β);
* round element aj to the nearest integer that isn't less than aj (assign to aj: β aj β).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 β€ n β€ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 β€ ai β€ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number β the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | instruction | 0 | 101,503 | 20 | 203,006 |
Tags: dp, greedy, implementation, math
Correct Solution:
```
n = int(input())
As = list(map(float, input().split()))
B = list(x - int(x) for x in As if x - int(x) > 0.000)
l = len(B)
if l == 0:
print('{:.3f}'.format(0))
exit(0)
S = sum(x for x in B)
ans = 1e10
for i in range(max(0, l - n), min(l,n) + 1):
ans = min(ans, abs(i - S))
print('{:.3f}'.format(ans))
``` | output | 1 | 101,503 | 20 | 203,007 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: β ai β);
* round element aj to the nearest integer that isn't less than aj (assign to aj: β aj β).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 β€ n β€ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 β€ ai β€ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number β the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | instruction | 0 | 101,504 | 20 | 203,008 |
Tags: dp, greedy, implementation, math
Correct Solution:
```
n = int(input())
a = map(float, input().split())
s = 0
m = 0
for val in a:
s += val-int(val)
m += (val-int(val))>0
v = 1e9
for i in range(max(0, m-n), min(n, m)+1):
v = min(v, abs(s-i))
print('%.3f'%v)
``` | output | 1 | 101,504 | 20 | 203,009 |
Provide tags and a correct Python 3 solution for this coding contest problem.
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this:
<< p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >>
When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page n. Of course if someone clicks on a number, he is redirected to the corresponding page.
There are some conditions in the navigation:
* If page 1 is in the navigation, the button "<<" must not be printed.
* If page n is in the navigation, the button ">>" must not be printed.
* If the page number is smaller than 1 or greater than n, it must not be printed.
You can see some examples of the navigations. Make a program that prints the navigation.
Input
The first and the only line contains three integers n, p, k (3 β€ n β€ 100; 1 β€ p β€ n; 1 β€ k β€ n)
Output
Print the proper navigation. Follow the format of the output from the test samples.
Examples
Input
17 5 2
Output
<< 3 4 (5) 6 7 >>
Input
6 5 2
Output
<< 3 4 (5) 6
Input
6 1 2
Output
(1) 2 3 >>
Input
6 2 2
Output
1 (2) 3 4 >>
Input
9 6 3
Output
<< 3 4 5 (6) 7 8 9
Input
10 6 3
Output
<< 3 4 5 (6) 7 8 9 >>
Input
8 5 4
Output
1 2 3 4 (5) 6 7 8 | instruction | 0 | 101,513 | 20 | 203,026 |
Tags: implementation
Correct Solution:
```
x=input()
def convert(x):
lst=x.split(" ")
return lst
data=convert(x)
n=int(data[0])
p=int(data[1])
k=int(data[2])
num=[]
for i in range(1,n+1):
num.append(i)
res=[]
r=[">>"]
l=["<<"]
for i in range(p-k,p+k+1):
if i>0 and len(num)>=i:
res.append(num[i-1])
if res[0]==1 and res[len(res)-1]==n:
ans=listToStr = ' '.join([str(elem) for elem in res])
an=ans.replace(str(p),("("+str(p)+")"),1)
elif res[0]==1:
ans=listToStr = ' '.join([str(elem) for elem in (res+r)])
an=ans.replace(str(p),("("+str(p)+")"),1)
elif res[len(res)-1]==n:
ans=listToStr = ' '.join([str(elem) for elem in (l+res)])
an=ans.replace(str(p),("("+str(p)+")"),1)
else:
ans=listToStr = ' '.join([str(elem) for elem in (l+res+r)])
an=ans.replace(str(p),("("+str(p)+")"),1)
print(an)
``` | output | 1 | 101,513 | 20 | 203,027 |
Provide tags and a correct Python 3 solution for this coding contest problem.
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this:
<< p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >>
When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page n. Of course if someone clicks on a number, he is redirected to the corresponding page.
There are some conditions in the navigation:
* If page 1 is in the navigation, the button "<<" must not be printed.
* If page n is in the navigation, the button ">>" must not be printed.
* If the page number is smaller than 1 or greater than n, it must not be printed.
You can see some examples of the navigations. Make a program that prints the navigation.
Input
The first and the only line contains three integers n, p, k (3 β€ n β€ 100; 1 β€ p β€ n; 1 β€ k β€ n)
Output
Print the proper navigation. Follow the format of the output from the test samples.
Examples
Input
17 5 2
Output
<< 3 4 (5) 6 7 >>
Input
6 5 2
Output
<< 3 4 (5) 6
Input
6 1 2
Output
(1) 2 3 >>
Input
6 2 2
Output
1 (2) 3 4 >>
Input
9 6 3
Output
<< 3 4 5 (6) 7 8 9
Input
10 6 3
Output
<< 3 4 5 (6) 7 8 9 >>
Input
8 5 4
Output
1 2 3 4 (5) 6 7 8 | instruction | 0 | 101,514 | 20 | 203,028 |
Tags: implementation
Correct Solution:
```
n, p, k = list(map(int,input().split()))
if(p - k > 1):
print("<< ",end="")
for i in range(k):
if(p - k + i >= 1):
print(p - k + i,end=" ")
print("(",end="")
print(p,end=") ")
for i in range(k):
if(p + i + 1 <= n):
print(p + i + 1,end=" ")
if(p + k < n):
print(">>")
``` | output | 1 | 101,514 | 20 | 203,029 |
Provide tags and a correct Python 3 solution for this coding contest problem.
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this:
<< p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >>
When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page n. Of course if someone clicks on a number, he is redirected to the corresponding page.
There are some conditions in the navigation:
* If page 1 is in the navigation, the button "<<" must not be printed.
* If page n is in the navigation, the button ">>" must not be printed.
* If the page number is smaller than 1 or greater than n, it must not be printed.
You can see some examples of the navigations. Make a program that prints the navigation.
Input
The first and the only line contains three integers n, p, k (3 β€ n β€ 100; 1 β€ p β€ n; 1 β€ k β€ n)
Output
Print the proper navigation. Follow the format of the output from the test samples.
Examples
Input
17 5 2
Output
<< 3 4 (5) 6 7 >>
Input
6 5 2
Output
<< 3 4 (5) 6
Input
6 1 2
Output
(1) 2 3 >>
Input
6 2 2
Output
1 (2) 3 4 >>
Input
9 6 3
Output
<< 3 4 5 (6) 7 8 9
Input
10 6 3
Output
<< 3 4 5 (6) 7 8 9 >>
Input
8 5 4
Output
1 2 3 4 (5) 6 7 8 | instruction | 0 | 101,515 | 20 | 203,030 |
Tags: implementation
Correct Solution:
```
n, p, k = list(map(int, input().split()))
l = []
i = 0
e = 0
while (i <= k*2 and e<n):
e = p-k+i
if e > 0:
l.append(e)
i = i+1
if l[0] > 1:
print('<<', end = ' ')
for i in l:
if i == p:
i = '('+str(i)+')'
print(i, end = ' ')
if l[len(l)-1] < n:
print('>>')
``` | output | 1 | 101,515 | 20 | 203,031 |
Provide tags and a correct Python 3 solution for this coding contest problem.
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this:
<< p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >>
When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page n. Of course if someone clicks on a number, he is redirected to the corresponding page.
There are some conditions in the navigation:
* If page 1 is in the navigation, the button "<<" must not be printed.
* If page n is in the navigation, the button ">>" must not be printed.
* If the page number is smaller than 1 or greater than n, it must not be printed.
You can see some examples of the navigations. Make a program that prints the navigation.
Input
The first and the only line contains three integers n, p, k (3 β€ n β€ 100; 1 β€ p β€ n; 1 β€ k β€ n)
Output
Print the proper navigation. Follow the format of the output from the test samples.
Examples
Input
17 5 2
Output
<< 3 4 (5) 6 7 >>
Input
6 5 2
Output
<< 3 4 (5) 6
Input
6 1 2
Output
(1) 2 3 >>
Input
6 2 2
Output
1 (2) 3 4 >>
Input
9 6 3
Output
<< 3 4 5 (6) 7 8 9
Input
10 6 3
Output
<< 3 4 5 (6) 7 8 9 >>
Input
8 5 4
Output
1 2 3 4 (5) 6 7 8 | instruction | 0 | 101,516 | 20 | 203,032 |
Tags: implementation
Correct Solution:
```
def pages(n,p,k):
output = ""
if p<1 or p>n :
return output
if p-k > 1 :
output += "<< "
for i in range(p-k, p+k+1):
if i <= n and i >= 1:
if i == p:
output += "(" + str(i) + ") "
else:
output += str(i) + " "
if p+k < n:
output += ">>"
return output
n,p,k = map(int, input().split())
print(pages(n, p, k))
``` | output | 1 | 101,516 | 20 | 203,033 |
Provide tags and a correct Python 3 solution for this coding contest problem.
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this:
<< p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >>
When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page n. Of course if someone clicks on a number, he is redirected to the corresponding page.
There are some conditions in the navigation:
* If page 1 is in the navigation, the button "<<" must not be printed.
* If page n is in the navigation, the button ">>" must not be printed.
* If the page number is smaller than 1 or greater than n, it must not be printed.
You can see some examples of the navigations. Make a program that prints the navigation.
Input
The first and the only line contains three integers n, p, k (3 β€ n β€ 100; 1 β€ p β€ n; 1 β€ k β€ n)
Output
Print the proper navigation. Follow the format of the output from the test samples.
Examples
Input
17 5 2
Output
<< 3 4 (5) 6 7 >>
Input
6 5 2
Output
<< 3 4 (5) 6
Input
6 1 2
Output
(1) 2 3 >>
Input
6 2 2
Output
1 (2) 3 4 >>
Input
9 6 3
Output
<< 3 4 5 (6) 7 8 9
Input
10 6 3
Output
<< 3 4 5 (6) 7 8 9 >>
Input
8 5 4
Output
1 2 3 4 (5) 6 7 8 | instruction | 0 | 101,517 | 20 | 203,034 |
Tags: implementation
Correct Solution:
```
# cook your dish here
p,n,k=map(int,input().split())
u=1
d=p+1
if n-k<=1:
ans=[]
else:
ans=["<<"]
if n+k+1<=p:
d=n+k+1
if n-k>0:
u=n-k
for i in range(u,d):
if i==n:
ans.append("("+str(n)+")")
else:
ans.append(i)
if n<p-k:
ans.append(">>")
ans=str(ans).replace(","," ")
ans=ans.replace("'","")
print(ans[1:-1])
``` | output | 1 | 101,517 | 20 | 203,035 |
Provide tags and a correct Python 3 solution for this coding contest problem.
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this:
<< p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >>
When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page n. Of course if someone clicks on a number, he is redirected to the corresponding page.
There are some conditions in the navigation:
* If page 1 is in the navigation, the button "<<" must not be printed.
* If page n is in the navigation, the button ">>" must not be printed.
* If the page number is smaller than 1 or greater than n, it must not be printed.
You can see some examples of the navigations. Make a program that prints the navigation.
Input
The first and the only line contains three integers n, p, k (3 β€ n β€ 100; 1 β€ p β€ n; 1 β€ k β€ n)
Output
Print the proper navigation. Follow the format of the output from the test samples.
Examples
Input
17 5 2
Output
<< 3 4 (5) 6 7 >>
Input
6 5 2
Output
<< 3 4 (5) 6
Input
6 1 2
Output
(1) 2 3 >>
Input
6 2 2
Output
1 (2) 3 4 >>
Input
9 6 3
Output
<< 3 4 5 (6) 7 8 9
Input
10 6 3
Output
<< 3 4 5 (6) 7 8 9 >>
Input
8 5 4
Output
1 2 3 4 (5) 6 7 8 | instruction | 0 | 101,518 | 20 | 203,036 |
Tags: implementation
Correct Solution:
```
entrada=input()
numbers=entrada.split()
n=int(numbers[0])
p=int(numbers[1])
k=int(numbers[2])
if p+k>=n and p-k<=1:
for i in range (1, n+1):
if i==p:
print("(" + str(p) + ")", end=" ")
else:
print(i,end=" ")
if p+k>=n and p-k>1:
print("<<", end=" ")
for i in range (p-k, n+1):
if i==p:
print("(" + str(p) + ")", end=" ")
else:
print(i,end=" ")
if p+k<n and p-k<=1:
for i in range (1, p+k+1):
if i==p:
print("(" + str(p) + ")", end=" ")
else:
print(i,end=" ")
print(">>")
if p+k<n and p-k>1:
print("<<", end=" ")
for i in range (p-k, p+k+1):
if i==p:
print("(" + str(p) + ")", end=" ")
else:
print(i,end=" ")
print(">>")
``` | output | 1 | 101,518 | 20 | 203,037 |
Provide tags and a correct Python 3 solution for this coding contest problem.
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this:
<< p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >>
When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page n. Of course if someone clicks on a number, he is redirected to the corresponding page.
There are some conditions in the navigation:
* If page 1 is in the navigation, the button "<<" must not be printed.
* If page n is in the navigation, the button ">>" must not be printed.
* If the page number is smaller than 1 or greater than n, it must not be printed.
You can see some examples of the navigations. Make a program that prints the navigation.
Input
The first and the only line contains three integers n, p, k (3 β€ n β€ 100; 1 β€ p β€ n; 1 β€ k β€ n)
Output
Print the proper navigation. Follow the format of the output from the test samples.
Examples
Input
17 5 2
Output
<< 3 4 (5) 6 7 >>
Input
6 5 2
Output
<< 3 4 (5) 6
Input
6 1 2
Output
(1) 2 3 >>
Input
6 2 2
Output
1 (2) 3 4 >>
Input
9 6 3
Output
<< 3 4 5 (6) 7 8 9
Input
10 6 3
Output
<< 3 4 5 (6) 7 8 9 >>
Input
8 5 4
Output
1 2 3 4 (5) 6 7 8 | instruction | 0 | 101,519 | 20 | 203,038 |
Tags: implementation
Correct Solution:
```
class Solution:
def navigation(self, n, p, k):
start = max(1, p-k)
end = min(p+k, n)
pagination = ""
if start > 1:
pagination += "<< "
while start <= end:
if start == p:
pagination += "(" + str(start) + ") "
else:
pagination += str(start) + " "
start += 1
if end < n:
pagination += ">>"
return pagination
sol = Solution()
# array = [11, 12, 1, 2, 13, 14, 3, 4]
# print(sol.thanosSort(array))
[n, p, k] = list(map(int, input().strip().split()))
print(sol.navigation(n, p, k))
``` | output | 1 | 101,519 | 20 | 203,039 |
Provide tags and a correct Python 3 solution for this coding contest problem.
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this:
<< p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >>
When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page n. Of course if someone clicks on a number, he is redirected to the corresponding page.
There are some conditions in the navigation:
* If page 1 is in the navigation, the button "<<" must not be printed.
* If page n is in the navigation, the button ">>" must not be printed.
* If the page number is smaller than 1 or greater than n, it must not be printed.
You can see some examples of the navigations. Make a program that prints the navigation.
Input
The first and the only line contains three integers n, p, k (3 β€ n β€ 100; 1 β€ p β€ n; 1 β€ k β€ n)
Output
Print the proper navigation. Follow the format of the output from the test samples.
Examples
Input
17 5 2
Output
<< 3 4 (5) 6 7 >>
Input
6 5 2
Output
<< 3 4 (5) 6
Input
6 1 2
Output
(1) 2 3 >>
Input
6 2 2
Output
1 (2) 3 4 >>
Input
9 6 3
Output
<< 3 4 5 (6) 7 8 9
Input
10 6 3
Output
<< 3 4 5 (6) 7 8 9 >>
Input
8 5 4
Output
1 2 3 4 (5) 6 7 8 | instruction | 0 | 101,520 | 20 | 203,040 |
Tags: implementation
Correct Solution:
```
a, b, c = map(int, input().split(" "))
# a β limit bβnow c β range
ll = max(1, b-c)
rl = min(a, b + c )
left = [i for i in range(b - 1, ll-1, -1)]
right = [i for i in range(b + 1, rl + 1)]
l_bar = "<< "
if ll == 1:
l_bar = ""
r_bar = " >>"
if rl == a:
r_bar = ""
left.reverse()
print(l_bar, *(left), "({})".format(b), *(right), r_bar)
``` | output | 1 | 101,520 | 20 | 203,041 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Drazil is playing a math game with Varda.
Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>.
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. <image> = <image>.
Help friends find such number.
Input
The first line contains an integer n (1 β€ n β€ 15) β the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Examples
Input
4
1234
Output
33222
Input
3
555
Output
555
Note
In the first case, <image> | instruction | 0 | 101,577 | 20 | 203,154 |
Tags: greedy, math, sortings
Correct Solution:
```
x = int(input())
y = input()
ct = {0:[0, 0, 0, 0], 1:[0, 0, 0, 0], 2:[1, 0, 0, 0], 3:[1, 1, 0, 0], 4:[3, 1, 0, 0], 5:[3, 1, 1, 0], 6:[4, 2, 1, 0], 7:[4, 2, 1, 1], 8:[7, 2, 1, 1], 9:[7, 4, 1, 1]}
real = {2:[1, 0, 0, 0], 3:[1, 1, 0, 0], 4:[3, 1, 0, 0], 5:[3, 1, 1, 0], 6:[4, 2, 1, 0], 7:[4, 2, 1, 1], 8:[7, 2, 1, 1], 9:[7, 4, 1, 1]}
ut = {2:[1, 0, 0, 0], 3:[1, 1, 0, 0], 5:[3, 1, 1, 0], 7:[4, 2, 1, 1]}
lx = [0, 0, 0, 0]
for i in y:
i = int(i)
bad = ct[i]
lx[0] += bad[0]
lx[1] += bad[1]
lx[2] += bad[2]
lx[3] += bad[3]
s = ''
if lx[-1] >= 1:
copies = lx[-1]
lx[0] -= 4*copies
lx[1] -= 2*copies
lx[2] -= copies
lx[3] -= copies
s += '7' * copies
if lx[-2] >= 1:
copies = lx[-2]
lx[0] -= 3*copies
lx[1] -= copies
lx[2] -= copies
s += '5' * copies
if lx[-3] >= 1:
copies = lx[-3]
lx[0] -= copies
lx[1] -= copies
s += '3' * copies
if lx[-4] >= 1:
copies = lx[-4]
lx[0] -= copies
s += '2' * copies
print(s)
``` | output | 1 | 101,577 | 20 | 203,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Drazil is playing a math game with Varda.
Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>.
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. <image> = <image>.
Help friends find such number.
Input
The first line contains an integer n (1 β€ n β€ 15) β the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Examples
Input
4
1234
Output
33222
Input
3
555
Output
555
Note
In the first case, <image> | instruction | 0 | 101,578 | 20 | 203,156 |
Tags: greedy, math, sortings
Correct Solution:
```
n = input()
s = input()
s = s.replace('9','7332')
s = s.replace('8','7222')
s = s.replace('6','53')
s = s.replace('4','322')
s = s.replace('1','')
s = s.replace('0','')
s = ''.join(sorted(s,reverse=True))
print(s)
``` | output | 1 | 101,578 | 20 | 203,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Drazil is playing a math game with Varda.
Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>.
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. <image> = <image>.
Help friends find such number.
Input
The first line contains an integer n (1 β€ n β€ 15) β the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Examples
Input
4
1234
Output
33222
Input
3
555
Output
555
Note
In the first case, <image> | instruction | 0 | 101,579 | 20 | 203,158 |
Tags: greedy, math, sortings
Correct Solution:
```
I=lambda:list(map(int,input().split()))
n=I()
f=['','','2','3','223','5','53','7','7222','7332']
v=''
for i in input():
v+=f[int(i)]
v=list(v)
v.sort(reverse=True)
print(''.join(v))
``` | output | 1 | 101,579 | 20 | 203,159 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Drazil is playing a math game with Varda.
Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>.
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. <image> = <image>.
Help friends find such number.
Input
The first line contains an integer n (1 β€ n β€ 15) β the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Examples
Input
4
1234
Output
33222
Input
3
555
Output
555
Note
In the first case, <image> | instruction | 0 | 101,580 | 20 | 203,160 |
Tags: greedy, math, sortings
Correct Solution:
```
n=int(input())
a=[int(x) for x in list(input())]
fac={2:0,3:0,5:0,7:0}
ans=[]
for i in range(2,10):
t=a.count(i)
if i==9:
fac[2]+=7*t
fac[3]+=4*t
fac[5]+=t
fac[7]+=t
if i==8:
fac[2]+=7*t
fac[3]+=2*t
fac[5]+=t
fac[7]+=t
if i==7:
fac[2]+=4*t
fac[3]+=2*t
fac[5]+=t
fac[7]+=t
if i==6:
fac[2]+=4*t
fac[3]+=2*t
fac[5]+=t
if i==5:
fac[2]+=3*t
fac[3]+=t
fac[5]+=t
if i==4:
fac[2]+=3*t
fac[3]+=t
if i==3:
fac[2]+=t
fac[3]+=t
if i==2:
fac[2]+=t
for i in [7,5,3,2]:
t=fac[i]
ans=ans+[i]*t
if i==7:
fac[2]-=4*t
fac[3]-=2*t
fac[5]-=t
fac[7]-=t
if i==5:
fac[2]-=3*t
fac[3]-=t
fac[5]-=t
if i==3:
fac[2]-=t
fac[3]-=t
ans.sort(reverse=True)
print(''.join([str(x) for x in ans]))
``` | output | 1 | 101,580 | 20 | 203,161 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Drazil is playing a math game with Varda.
Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>.
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. <image> = <image>.
Help friends find such number.
Input
The first line contains an integer n (1 β€ n β€ 15) β the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Examples
Input
4
1234
Output
33222
Input
3
555
Output
555
Note
In the first case, <image> | instruction | 0 | 101,581 | 20 | 203,162 |
Tags: greedy, math, sortings
Correct Solution:
```
n = int(input())
s = input()
ans = ""
for i in s:
if(i=="1" or i=="0"):
continue
elif(i=="4"):
ans+="322"
elif(i=="6"):
ans+="53"
elif(i=="8"):
ans+="7222"
elif(i=="9"):
ans+="7332"
else:
ans+=i
ans = list(ans)
ans.sort(reverse=True)
for i in ans:
print(i,end="")
``` | output | 1 | 101,581 | 20 | 203,163 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Drazil is playing a math game with Varda.
Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>.
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. <image> = <image>.
Help friends find such number.
Input
The first line contains an integer n (1 β€ n β€ 15) β the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Examples
Input
4
1234
Output
33222
Input
3
555
Output
555
Note
In the first case, <image> | instruction | 0 | 101,582 | 20 | 203,164 |
Tags: greedy, math, sortings
Correct Solution:
```
a = int(input())
b = str(input())
answer = list()
for x in b:
if x != "0" and x != "1":
if x == "4":
answer += ["3", "2", "2"]
elif x == "6":
answer += ["5", "3"]
elif x == "8":
answer += ["7", "2", "2", "2"]
elif x == "9":
answer += ["7", "3", "3", "2"]
else:
answer += x
answer.sort()
answer.reverse()
final = ""
for x in answer:
final += x
print(final)
``` | output | 1 | 101,582 | 20 | 203,165 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Drazil is playing a math game with Varda.
Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>.
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. <image> = <image>.
Help friends find such number.
Input
The first line contains an integer n (1 β€ n β€ 15) β the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Examples
Input
4
1234
Output
33222
Input
3
555
Output
555
Note
In the first case, <image> | instruction | 0 | 101,583 | 20 | 203,166 |
Tags: greedy, math, sortings
Correct Solution:
```
a = input("")
b = input("")
outstring = ""
for value in b:
if value == "1":
continue
elif value == "2":
outstring = outstring + "2"
elif value == "3":
outstring = outstring + "3"
elif value == "4":
outstring = outstring + "3" + "2" + "2"
elif value == "5":
outstring = outstring + "5"
elif value == "6":
outstring = outstring + "5" + "3"
elif value == "7":
outstring = outstring + "7"
elif value == "8":
outstring = outstring + "7" + "2" + "2" + "2"
elif value == "9":
outstring = outstring + "7" + "3" + "3" + "2"
t = [i for i in outstring]
t.sort()
t.reverse()
print(''.join(t))
``` | output | 1 | 101,583 | 20 | 203,167 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Drazil is playing a math game with Varda.
Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>.
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. <image> = <image>.
Help friends find such number.
Input
The first line contains an integer n (1 β€ n β€ 15) β the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Examples
Input
4
1234
Output
33222
Input
3
555
Output
555
Note
In the first case, <image> | instruction | 0 | 101,584 | 20 | 203,168 |
Tags: greedy, math, sortings
Correct Solution:
```
def aus(argument):
switcher = {
0:[],
1:[],
2:[2],
3:[3],
4:[3,2,2],
5:[5],
6:[3,5],
7:[7],
8:[2,2,2,7],
9:[2,3,3,7],
}
return switcher.get(argument)
summ=[]
a= int(input())
b= input()
for i in range(a):
summ += aus(int(b[i]))
summ.sort(reverse=True)
print(int(''.join(map(str, summ))))
``` | output | 1 | 101,584 | 20 | 203,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil is playing a math game with Varda.
Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>.
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. <image> = <image>.
Help friends find such number.
Input
The first line contains an integer n (1 β€ n β€ 15) β the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Examples
Input
4
1234
Output
33222
Input
3
555
Output
555
Note
In the first case, <image>
Submitted Solution:
```
import string
NUMBERS=[]
def factor(x):
if x == 2 or x==5 or x== 7:
NUMBERS.append(x)
return
else:
xx = x
while x!= 1:
for i in range(2,4):
if x%i==0:
x = x/i
NUMBERS.append(i)
factor(xx-1)
return
n = int(input())
input_value = input()
num = []
j = 0
for i in range(n):
if input_value[i] != '1' and input_value[i] != '0':
num.append(int(input_value[i]))
j = j+1
for x in num:
factor (x)
kkk=NUMBERS
kkk.sort(reverse=True )
for x in NUMBERS:
if x==3:
kkk.pop()
print("".join( map(str, kkk)))
``` | instruction | 0 | 101,585 | 20 | 203,170 |
Yes | output | 1 | 101,585 | 20 | 203,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil is playing a math game with Varda.
Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>.
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. <image> = <image>.
Help friends find such number.
Input
The first line contains an integer n (1 β€ n β€ 15) β the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Examples
Input
4
1234
Output
33222
Input
3
555
Output
555
Note
In the first case, <image>
Submitted Solution:
```
n = int(input())
num = str(input())
primes = {2: 0, 3: 0, 5: 0, 7: 0}
for i in range(n):
k = int(num[i])
if (k <= 1):
continue
primes[2] += 1
if (k >= 3):
primes[3] += 1
if (k >= 4):
primes[2] += 2
if (k >= 5):
primes[5] += 1
if (k >= 6):
primes[2] += 1
primes[3] += 1
if (k >= 7):
primes[7] += 1
if (k >= 8):
primes[2] += 3
if (k == 9):
primes[3] += 2
for i in range(primes[7]):
print(7, end='')
primes[2] -= 4
primes[3] -= 2
primes[5] -= 1
for i in range(primes[5]):
print(5, end='')
primes[2] -= 3
primes[3] -= 1
for i in range(primes[3]):
print(3, end='')
primes[2] -= 1
for i in range(primes[2]):
print(2, end='')
print("\n")
``` | instruction | 0 | 101,586 | 20 | 203,172 |
Yes | output | 1 | 101,586 | 20 | 203,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil is playing a math game with Varda.
Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>.
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. <image> = <image>.
Help friends find such number.
Input
The first line contains an integer n (1 β€ n β€ 15) β the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Examples
Input
4
1234
Output
33222
Input
3
555
Output
555
Note
In the first case, <image>
Submitted Solution:
```
import math
import sys
n=int(input())
s=input()
v=[]
for i in range(0,n):
if s[i] == '2':
v.append(2)
if s[i] == '3':
v.append(3)
if s[i] == '4':
v.append(2)
v.append(2)
v.append(3)
if s[i] == '5':
v.append(5)
if s[i] == '6':
v.append(5)
v.append(3)
if s[i] == '7':
v.append(7)
if s[i] == '8':
v.append(7)
v.append(2)
v.append(2)
v.append(2)
if s[i] == '9':
v.append(7)
v.append(2)
v.append(3)
v.append(3)
v.sort()
m=0
t=1
for i in range(0,len(v)):
m+=v[i]*t
t*=10
print(m)
``` | instruction | 0 | 101,587 | 20 | 203,174 |
Yes | output | 1 | 101,587 | 20 | 203,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil is playing a math game with Varda.
Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>.
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. <image> = <image>.
Help friends find such number.
Input
The first line contains an integer n (1 β€ n β€ 15) β the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Examples
Input
4
1234
Output
33222
Input
3
555
Output
555
Note
In the first case, <image>
Submitted Solution:
```
list1=["","","2","3","322","5","53","7","7222","7332"]
n=int(input())
p=input()
k=[]
for i in p:
k.append(list1[int(i)])
print("".join(sorted("".join(k),reverse=True)))
``` | instruction | 0 | 101,588 | 20 | 203,176 |
Yes | output | 1 | 101,588 | 20 | 203,177 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil is playing a math game with Varda.
Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>.
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. <image> = <image>.
Help friends find such number.
Input
The first line contains an integer n (1 β€ n β€ 15) β the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Examples
Input
4
1234
Output
33222
Input
3
555
Output
555
Note
In the first case, <image>
Submitted Solution:
```
import math
import sys
n=int(input())
s=input()
v=[]
for i in range(0,n):
if s[i] == '2':
v.append(2)
if s[i] == '3':
v.append(3)
if s[i] == '4':
v.append(2)
v.append(2)
v.append(3)
if s[i] == '5':
v.append(5)
if s[i] == '6':
v.append(5)
v.append(2)
v.append(3)
if s[i] == '7':
v.append(7)
if s[i] == '8':
v.append(7)
v.append(2)
v.append(2)
v.append(2)
if s[i] == '9':
v.append(7)
v.append(2)
v.append(2)
v.append(2)
v.append(3)
v.append(3)
v.sort()
m=0
t=1
for i in range(0,len(v)):
m+=v[i]*t
t*=10
print(m)
``` | instruction | 0 | 101,589 | 20 | 203,178 |
No | output | 1 | 101,589 | 20 | 203,179 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil is playing a math game with Varda.
Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>.
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. <image> = <image>.
Help friends find such number.
Input
The first line contains an integer n (1 β€ n β€ 15) β the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Examples
Input
4
1234
Output
33222
Input
3
555
Output
555
Note
In the first case, <image>
Submitted Solution:
```
input()
s=input()
a=""
t=[a,a,"2","3","223","5","53","7","7222","7333"]
for c in s:
a+=t[int(c)]
print(''.join(sorted(a)[::-1]))
``` | instruction | 0 | 101,590 | 20 | 203,180 |
No | output | 1 | 101,590 | 20 | 203,181 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.