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.
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task.
Input
The single line contains four integers a1, a2, a3 and a4 (1 ≤ a1, a2, a3, a4 ≤ 106).
Output
On the single line print without leading zeroes the answer to the problem — the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes).
Examples
Input
2 2 1 1
Output
4774
Input
4 7 3 1
Output
-1
Submitted Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
from itertools import permutations
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now-----------------------------------------------------
f, s, fs, sf = map(int, input().split(' '))
if sf - fs == 1 and f - sf + 1 > 0 and s - sf + 1 > 0: # 7444...444474747474...7777...7774
r = ['7', '4'] * sf
r[1] = '4' * (f - sf + 1)
r[-2] = '7' * (s - sf + 1)
print(''.join(r))
elif sf == fs and f - sf > 0 and s - sf + 1 > 0: # 444...44474747474777...7774
r = ['4', '7'] * sf + ['4']
r[0] = '4' * (f - (sf + 1) + 1)
r[-2] = '7' * (s - sf + 1)
print(''.join(r))
elif fs - sf == 1 and f - fs + 1 > 0 and s - fs + 1 > 0: # 444...444747474777...777
r = ['4', '7'] * fs
r[0] = '4' * (f - fs + 1)
r[-1] = '7' * (s - fs + 1)
print(''.join(r))
elif f == fs == sf and s - f > 0: # 747474777...777
print('74' * f + '7' * (s - f))
else:
print(-1)
``` | instruction | 0 | 24,978 | 20 | 49,956 |
Yes | output | 1 | 24,978 | 20 | 49,957 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task.
Input
The single line contains four integers a1, a2, a3 and a4 (1 ≤ a1, a2, a3, a4 ≤ 106).
Output
On the single line print without leading zeroes the answer to the problem — the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes).
Examples
Input
2 2 1 1
Output
4774
Input
4 7 3 1
Output
-1
Submitted Solution:
```
f, s, fs, sf = map(int, input().split(' '))
if sf - fs == 1 and f - sf + 1 > 0 and s - sf + 1 > 0: # 7444...444474747474...7777...7774
r = ['7', '4'] * sf
r[1] = '4' * (f - sf + 1)
r[-2] = '7' * (s - sf + 1)
print(''.join(r))
elif sf == fs and f - sf > 0 and s - sf + 1 > 0: # 444...44474747474777...7774
r = ['4', '7'] * sf + ['4']
r[0] = '4' * (f - (sf + 1) + 1)
r[-2] = '7' * (s - sf + 1)
print(''.join(r))
elif fs - sf == 1 and f - fs + 1 > 0 and s - fs + 1 > 0: # 444...444747474777...777
r = ['4', '7'] * fs
r[0] = '4' * (f - fs + 1)
r[-1] = '7' * (s - fs + 1)
print(''.join(r))
elif f == fs == sf and s - f > 0: # 747474777...777
print('74' * f + '7' * (s - f))
else:
print(-1)
``` | instruction | 0 | 24,979 | 20 | 49,958 |
Yes | output | 1 | 24,979 | 20 | 49,959 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task.
Input
The single line contains four integers a1, a2, a3 and a4 (1 ≤ a1, a2, a3, a4 ≤ 106).
Output
On the single line print without leading zeroes the answer to the problem — the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes).
Examples
Input
2 2 1 1
Output
4774
Input
4 7 3 1
Output
-1
Submitted Solution:
```
a, b, c, d = list( map( int, input().split() ) )
def solve( a, b, c, d ):
cnt = {}
cnt[4] = a
cnt[7] = b
cnt[47] = c
cnt[74] = d
ans = ""
first = True
if cnt[74] > cnt[47]:
while cnt[74] > 0 and cnt[4] > 0 and cnt[7] > 0:
cnt[74] -= 1
cnt[4] -= 1
cnt[7] -= 1
ans += "74"
if first:
first = False
else:
cnt[47] -= 1
first = True
while cnt[47] > 0 and cnt[4] > 0 and cnt[7] > 0:
cnt[47] -= 1
cnt[4] -= 1
cnt[7] -= 1
ans += "47"
if first:
first = False
else:
cnt[74] -= 1
if ans[-1] == "4":
first = False
else:
first = True
while cnt[74] > 0 and cnt[4] > 0 and cnt[7] > 0:
cnt[74] -= 1
cnt[4] -= 1
cnt[7] -= 1
ans += "74"
if first:
first = False
else:
cnt[47] -= 1
#print( ans )
#print( cnt[4] )
#print( cnt[7] )
if cnt[4] > 0:
for i in range( len(ans) ):
if ans[i] == "4":
ans = ans[:i] + ( "4" * cnt[4] ) + ans[i:]
cnt[4] = 0
break
if cnt[7] > 0:
for i in range( len(ans)-1, -1, -1 ):
if ans[i] == "7":
ans = ans[:i] + ( "7" * cnt[7] ) + ans[i:]
cnt[7] = 0
break
if cnt[4] > 0:
if ans[0] == "7":
cnt[47] -= 1
ans = ( 4 * cnt[4] ) + ans
cnt[4] = 0
if cnt[7] > 0:
if ans[-1] == "4":
cnt[74] -= 1
ans = ans + ( 7 * cnt[7] )
cnt[7] = 0
#print( ans )
return (ans, cnt )
if c == d:
cnt = {}
cnt[4], cnt[7], cnt[47], cnt[74] = a, b, c, d
ans = "47" * cnt[74]
cnt[4] -= cnt[47]
cnt[7] -= cnt[47]
cnt[74] -= max( 0, cnt[47]-1 )
cnt[47] = 0
if cnt[74] > 0:
if ans[-1] == "7":
ans += "4"
cnt[4] -= 1
cnt[74] -= 1
ans += "74" * cnt[74]
cnt[4] -= cnt[74]
cnt[7] -= cnt[74]
cnt[74] = 0
if cnt[4] > 0:
for i in range( len(ans) ):
if ans[i] == "4":
ans = ans[:i] + ( "4" * cnt[4] ) + ans[i:]
cnt[4] = 0
break
if cnt[7] > 0:
for i in range( len(ans)-1, -1, -1 ):
if ans[i] == "7":
ans = ans[:i] + ( "7" * cnt[7] ) + ans[i:]
cnt[7] = 0
break
#print( ans )
if ( cnt[4] | cnt[7] | cnt[47] | cnt[74] ) == 0 :
print( ans )
else:
print( "-1" )
else:
ans, cnt = solve( a, b, c, d )
if ( cnt[4] | cnt[7] | cnt[47] | cnt[74] ) == 0 :
print( ans )
else:
print( "-1" )
``` | instruction | 0 | 24,980 | 20 | 49,960 |
No | output | 1 | 24,980 | 20 | 49,961 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task.
Input
The single line contains four integers a1, a2, a3 and a4 (1 ≤ a1, a2, a3, a4 ≤ 106).
Output
On the single line print without leading zeroes the answer to the problem — the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes).
Examples
Input
2 2 1 1
Output
4774
Input
4 7 3 1
Output
-1
Submitted Solution:
```
from math import *
from fractions import *
from sys import *
def li():
return list(map(int, input().split(" ")))
a = li()
if abs(a[2]-a[3]) > 1:
print(-1)
exit()
if a[2] == a[3]:
ans = "47"*a[2]+"4"
elif a[2] > a[3]:
ans = "47"*a[2]
else:
ans = "74"*a[3]
f = a[0]-ans.count("4")
s = a[1]-ans.count("7")
if s < 0 or f < 0:
if(a[2] == a[3]):
ans = "74"*a[2]+"7"
f = a[0]-ans.count("4")
s = a[1]-ans.count("7")
if s < 0 or f < 0:
ans = "-1"
elif s>0 or f>0:
s+=1
f+=1
if ans[:2] == "47":
ans = "4"*f + "7"*s + ans[2:]
else:
ans = "7" + "4"*f + ans[2:-1] + "7"*(s-1)
print(ans)
``` | instruction | 0 | 24,981 | 20 | 49,962 |
No | output | 1 | 24,981 | 20 | 49,963 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task.
Input
The single line contains four integers a1, a2, a3 and a4 (1 ≤ a1, a2, a3, a4 ≤ 106).
Output
On the single line print without leading zeroes the answer to the problem — the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes).
Examples
Input
2 2 1 1
Output
4774
Input
4 7 3 1
Output
-1
Submitted Solution:
```
cnt = {}
a, b, c, d = list( map( int, input().split() ) )
cnt[4] = a
cnt[7] = b
cnt[47] = c
cnt[74] = d
ans = ""
first = True
if cnt[74] > cnt[47]:
while cnt[74] > 0 and cnt[4] > 0 and cnt[7] > 0:
cnt[74] -= 1
cnt[4] -= 1
cnt[7] -= 1
ans += "74"
if first:
first = False
else:
cnt[47] -= 1
first = True
while cnt[47] > 0 and cnt[4] > 0 and cnt[7] > 0:
cnt[47] -= 1
cnt[4] -= 1
cnt[7] -= 1
ans += "47"
if first:
first = False
else:
cnt[74] -= 1
if ans[-1] == "4":
first = False
else:
first = True
while cnt[74] > 0 and cnt[4] > 0 and cnt[7] > 0:
cnt[74] -= 1
cnt[4] -= 1
cnt[7] -= 1
ans += "74"
if first:
first = False
else:
cnt[47] -= 1
#print( ans )
#print( cnt[4] )
#print( cnt[7] )
if cnt[4] > 0:
for i in range( len(ans) ):
if ans[i] == "4":
ans = ans[:i] + ( "4" * cnt[4] ) + ans[i:]
cnt[4] = 0
break
if cnt[7] > 0:
for i in range( len(ans)-1, -1, -1 ):
if ans[i] == "7":
ans = ans[:i] + ( "7" * cnt[7] ) + ans[i:]
cnt[7] = 0
break
if cnt[4] > 0:
ans = ( 4 * cnt[4] ) + ans
cnt[4] = 0
if cnt[7] > 0:
ans = ans + ( 7 * cnt[7] )
cnt[7] = 0
#print( ans )
if ( cnt[4] | cnt[7] | cnt[47] | cnt[74] ) == 0 :
print( ans )
else:
print( "-1" )
``` | instruction | 0 | 24,982 | 20 | 49,964 |
No | output | 1 | 24,982 | 20 | 49,965 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task.
Input
The single line contains four integers a1, a2, a3 and a4 (1 ≤ a1, a2, a3, a4 ≤ 106).
Output
On the single line print without leading zeroes the answer to the problem — the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes).
Examples
Input
2 2 1 1
Output
4774
Input
4 7 3 1
Output
-1
Submitted Solution:
```
import sys
def possible(a, b, c, d):
ans = ""
if c == d + 1:
while c > 0:
ans += "47"
a -= 1
b -= 1
c -= 1
elif c + 1 == d:
while d > 0:
ans += "74"
a -= 1
b -= 1
d -= 1
if a >= 0 and b >= 0:
ans = '4' * a + ans + '7' * b
return ans
else:
return None
a, b, c, d = map(int, sys.stdin.readline().split(' '))
if abs(c - d) > 1:
print(-1)
exit()
if c == d + 1:
ans = possible(a, b, c, d)
if ans:
print(ans)
else:
print(-1)
elif c + 1 == d:
ans = possible(a, b, c, d)
if ans:
print(ans)
else:
print(-1)
else:
ans = possible(a - 1, b, c, d - 1)
if ans:
ans = ans + "4"
print(ans)
exit()
ans = possible(a, b - 1, c - 1, d)
if ans:
ans = ans + "7"
print(ans)
exit()
else:
print(-1)
``` | instruction | 0 | 24,983 | 20 | 49,966 |
No | output | 1 | 24,983 | 20 | 49,967 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera considers a number beautiful, if it equals 2k or -2k for some integer k (k ≥ 0). Recently, the math teacher asked Valera to represent number n as the sum of beautiful numbers. As Valera is really greedy, he wants to complete the task using as few beautiful numbers as possible.
Help Valera and find, how many numbers he is going to need. In other words, if you look at all decompositions of the number n into beautiful summands, you need to find the size of the decomposition which has the fewest summands.
Input
The first line contains string s (1 ≤ |s| ≤ 106), that is the binary representation of number n without leading zeroes (n > 0).
Output
Print a single integer — the minimum amount of beautiful numbers that give a total of n.
Examples
Input
10
Output
1
Input
111
Output
2
Input
1101101
Output
4
Note
In the first sample n = 2 is a beautiful number.
In the second sample n = 7 and Valera can decompose it into sum 23 + ( - 20).
In the third sample n = 109 can be decomposed into the sum of four summands as follows: 27 + ( - 24) + ( - 22) + 20. | instruction | 0 | 25,039 | 20 | 50,078 |
Tags: dp, games, greedy, number theory
Correct Solution:
```
t = input()
j = t[0]
d, s = 0, int(j)
for i in t[1: ]:
if j != i:
if d == 1: d, s = 0, s + 1
else: d = 1
j = i
else: d = 1
print(s + (d and j == '1'))
``` | output | 1 | 25,039 | 20 | 50,079 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera considers a number beautiful, if it equals 2k or -2k for some integer k (k ≥ 0). Recently, the math teacher asked Valera to represent number n as the sum of beautiful numbers. As Valera is really greedy, he wants to complete the task using as few beautiful numbers as possible.
Help Valera and find, how many numbers he is going to need. In other words, if you look at all decompositions of the number n into beautiful summands, you need to find the size of the decomposition which has the fewest summands.
Input
The first line contains string s (1 ≤ |s| ≤ 106), that is the binary representation of number n without leading zeroes (n > 0).
Output
Print a single integer — the minimum amount of beautiful numbers that give a total of n.
Examples
Input
10
Output
1
Input
111
Output
2
Input
1101101
Output
4
Note
In the first sample n = 2 is a beautiful number.
In the second sample n = 7 and Valera can decompose it into sum 23 + ( - 20).
In the third sample n = 109 can be decomposed into the sum of four summands as follows: 27 + ( - 24) + ( - 22) + 20. | instruction | 0 | 25,040 | 20 | 50,080 |
Tags: dp, games, greedy, number theory
Correct Solution:
```
bin_num = input()
result = int(bin_num[0])
change = False
for i in range(1, len(bin_num)):
if bin_num[i - 1] != bin_num[i]:
if change:
change = False
result += 1
else: change = True
else: change = True
print(result + int(change and bin_num[len(bin_num) - 1] == '1'))
``` | output | 1 | 25,040 | 20 | 50,081 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera considers a number beautiful, if it equals 2k or -2k for some integer k (k ≥ 0). Recently, the math teacher asked Valera to represent number n as the sum of beautiful numbers. As Valera is really greedy, he wants to complete the task using as few beautiful numbers as possible.
Help Valera and find, how many numbers he is going to need. In other words, if you look at all decompositions of the number n into beautiful summands, you need to find the size of the decomposition which has the fewest summands.
Input
The first line contains string s (1 ≤ |s| ≤ 106), that is the binary representation of number n without leading zeroes (n > 0).
Output
Print a single integer — the minimum amount of beautiful numbers that give a total of n.
Examples
Input
10
Output
1
Input
111
Output
2
Input
1101101
Output
4
Note
In the first sample n = 2 is a beautiful number.
In the second sample n = 7 and Valera can decompose it into sum 23 + ( - 20).
In the third sample n = 109 can be decomposed into the sum of four summands as follows: 27 + ( - 24) + ( - 22) + 20. | instruction | 0 | 25,041 | 20 | 50,082 |
Tags: dp, games, greedy, number theory
Correct Solution:
```
from math import *
from collections import *
a = list(input())
a = a[::-1]
n = len(a)
ct = 1
i = 0
while(i < n-1):
#print(i)
if(a[i] == '0'):
i += 1
continue
cnt = 0
while(i < n-1 and a[i] == '1' and a[i+1] == '1'):
cnt += 1
i += 1
if(i == n-1): ct += 1
else:
if(cnt != 0):
a[i+1] = '1'
ct += 1
i += 1
print(ct)
``` | output | 1 | 25,041 | 20 | 50,083 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera considers a number beautiful, if it equals 2k or -2k for some integer k (k ≥ 0). Recently, the math teacher asked Valera to represent number n as the sum of beautiful numbers. As Valera is really greedy, he wants to complete the task using as few beautiful numbers as possible.
Help Valera and find, how many numbers he is going to need. In other words, if you look at all decompositions of the number n into beautiful summands, you need to find the size of the decomposition which has the fewest summands.
Input
The first line contains string s (1 ≤ |s| ≤ 106), that is the binary representation of number n without leading zeroes (n > 0).
Output
Print a single integer — the minimum amount of beautiful numbers that give a total of n.
Examples
Input
10
Output
1
Input
111
Output
2
Input
1101101
Output
4
Note
In the first sample n = 2 is a beautiful number.
In the second sample n = 7 and Valera can decompose it into sum 23 + ( - 20).
In the third sample n = 109 can be decomposed into the sum of four summands as follows: 27 + ( - 24) + ( - 22) + 20.
Submitted Solution:
```
def add(a,b):
res=[0]*(len(a)+1)
a=list(a)
b=list(b)
a=a[::-1]
b=b[::-1]
carry=0
a+=['0']
b+=['0']*(len(a)-len(b))
ln =len(a)
for n in range(len(a)):
d=int(a[n])+int(b[n])+carry
carry=(d//2)
d%=2
res[n]=str(d)
res.reverse()
return res
def neg(s):
s=list(s)
s.reverse()
for n in range(len(s)):
s[n]=str(int(not int(s[n])))
res=add(s,'1')
return res
s=input()
mn=sum(list(map(int,s)))
pos=0
for n in range(len(s)-1,0,-1):
if s[n]=='1':
pos=1
break
if not pos:
print(1)
exit(0)
z='1'+'0'*(len(s))
res=add(z,neg(s))
print(min(sum(list(map(int,res))),mn))
``` | instruction | 0 | 25,042 | 20 | 50,084 |
No | output | 1 | 25,042 | 20 | 50,085 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera considers a number beautiful, if it equals 2k or -2k for some integer k (k ≥ 0). Recently, the math teacher asked Valera to represent number n as the sum of beautiful numbers. As Valera is really greedy, he wants to complete the task using as few beautiful numbers as possible.
Help Valera and find, how many numbers he is going to need. In other words, if you look at all decompositions of the number n into beautiful summands, you need to find the size of the decomposition which has the fewest summands.
Input
The first line contains string s (1 ≤ |s| ≤ 106), that is the binary representation of number n without leading zeroes (n > 0).
Output
Print a single integer — the minimum amount of beautiful numbers that give a total of n.
Examples
Input
10
Output
1
Input
111
Output
2
Input
1101101
Output
4
Note
In the first sample n = 2 is a beautiful number.
In the second sample n = 7 and Valera can decompose it into sum 23 + ( - 20).
In the third sample n = 109 can be decomposed into the sum of four summands as follows: 27 + ( - 24) + ( - 22) + 20.
Submitted Solution:
```
a=list(input())
on=a.count('1')
ze=a.count('0')
t=999999999999999999
print(min(on,2+ze))
``` | instruction | 0 | 25,043 | 20 | 50,086 |
No | output | 1 | 25,043 | 20 | 50,087 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera considers a number beautiful, if it equals 2k or -2k for some integer k (k ≥ 0). Recently, the math teacher asked Valera to represent number n as the sum of beautiful numbers. As Valera is really greedy, he wants to complete the task using as few beautiful numbers as possible.
Help Valera and find, how many numbers he is going to need. In other words, if you look at all decompositions of the number n into beautiful summands, you need to find the size of the decomposition which has the fewest summands.
Input
The first line contains string s (1 ≤ |s| ≤ 106), that is the binary representation of number n without leading zeroes (n > 0).
Output
Print a single integer — the minimum amount of beautiful numbers that give a total of n.
Examples
Input
10
Output
1
Input
111
Output
2
Input
1101101
Output
4
Note
In the first sample n = 2 is a beautiful number.
In the second sample n = 7 and Valera can decompose it into sum 23 + ( - 20).
In the third sample n = 109 can be decomposed into the sum of four summands as follows: 27 + ( - 24) + ( - 22) + 20.
Submitted Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
# from fractions import *
# from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=998244353
EPS=1e-6
def Ceil(a,b): return a//b+int(a%b>0)
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
for _ in range(1):
n = input()
ans = n.count('1')
new_n = '1'+'0'*len(n)
extra = bin(int(new_n,2) - int(n,2))[2:]
ans = min(ans,extra.count('1') + 1)
print(ans)
``` | instruction | 0 | 25,044 | 20 | 50,088 |
No | output | 1 | 25,044 | 20 | 50,089 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera considers a number beautiful, if it equals 2k or -2k for some integer k (k ≥ 0). Recently, the math teacher asked Valera to represent number n as the sum of beautiful numbers. As Valera is really greedy, he wants to complete the task using as few beautiful numbers as possible.
Help Valera and find, how many numbers he is going to need. In other words, if you look at all decompositions of the number n into beautiful summands, you need to find the size of the decomposition which has the fewest summands.
Input
The first line contains string s (1 ≤ |s| ≤ 106), that is the binary representation of number n without leading zeroes (n > 0).
Output
Print a single integer — the minimum amount of beautiful numbers that give a total of n.
Examples
Input
10
Output
1
Input
111
Output
2
Input
1101101
Output
4
Note
In the first sample n = 2 is a beautiful number.
In the second sample n = 7 and Valera can decompose it into sum 23 + ( - 20).
In the third sample n = 109 can be decomposed into the sum of four summands as follows: 27 + ( - 24) + ( - 22) + 20.
Submitted Solution:
```
t = input()
j = t[0]
d, s = 0, int(j)
for i in t[1: ]:
if j != i:
if d == 1: d, s = 0, s + 1
else: d = 1
j = i
else: d = 1
print(s + int(j))
``` | instruction | 0 | 25,045 | 20 | 50,090 |
No | output | 1 | 25,045 | 20 | 50,091 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Do you remember how Kai constructed the word "eternity" using pieces of ice as components?
Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number t. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to use as 9 (and vice versa). Similary, 2 and 5 work the same. There is no other pair of digits with similar effect. He called this effect "Digital Mimicry".
Sheldon favourite number is t. He wants to have as many instances of t as possible. How many instances he can construct using the given sequence of ice pieces. He can use any piece at most once.
Input
The first line contains integer t (1 ≤ t ≤ 10000). The second line contains the sequence of digits on the pieces. The length of line is equal to the number of pieces and between 1 and 200, inclusive. It contains digits between 0 and 9.
Output
Print the required number of instances.
Examples
Input
42
23454
Output
2
Input
169
12118999
Output
1
Note
This problem contains very weak pretests. | instruction | 0 | 25,052 | 20 | 50,104 |
Tags: greedy
Correct Solution:
```
num = input()
str = input()
d = dict()
used = dict()
num = num.replace('5', '2')
str = str.replace('5', '2')
num = num.replace('9', '6')
str = str.replace('9', '6')
res = 10 ** 1000
for i in num:
res = min(res, str.count(i) // num.count(i))
print(res)
``` | output | 1 | 25,052 | 20 | 50,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30
Submitted Solution:
```
s = map(int , input().split(','))
s = sorted(set(s))
temp = []
answer = ''
for i in range(len(s)):
if i == 0:
temp.append(s[i])
elif s[i] != s[i-1] + 1:
if len(temp) > 1:
answer += (str(temp[0]) + '-' + str(temp[-1]) + ',')
else:
answer += (str(temp[0]) + ',')
temp = [s[i]]
else:
temp.append(s[i])
if len(temp) > 1:
answer += (str(temp[0]) + '-' + str(temp[-1]))
else:
answer += (str(temp[0]))
print(answer)
``` | instruction | 0 | 25,072 | 20 | 50,144 |
Yes | output | 1 | 25,072 | 20 | 50,145 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30
Submitted Solution:
```
l = sorted(list(set(list(map(int, input().split(','))))))
output = ''
cur = l[0]
for i in range(1, len(l) + 1):
if i == len(l) or l[i] - l[i - 1] > 1:
if output is not '':
output += ','
if l[i - 1] == cur:
output += str(l[i - 1])
else:
output += str(cur) + '-' + str(l[i - 1])
if i is not len(l):
cur = l[i]
print(output)
``` | instruction | 0 | 25,073 | 20 | 50,146 |
Yes | output | 1 | 25,073 | 20 | 50,147 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30
Submitted Solution:
```
a=[int(i) for i in input().split(',')]
a=list(set(a))
a=sorted(a)
l,r=a[0],a[0]
for i in range(1,len(a)):
if a[i]-1==a[i-1]:
r+=1
else:
if l==r:
print(l,end=',')
else:
print(l,'-',r,sep='',end=',')
l,r=a[i],a[i]
if l==r:
print(l)
else:
print(l,'-',r,sep='')
``` | instruction | 0 | 25,074 | 20 | 50,148 |
Yes | output | 1 | 25,074 | 20 | 50,149 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30
Submitted Solution:
```
#import sys
#import itertools
#import math
#t = int(input())
t = 1
while t > 0:
#print(t)
s = input().split(",")
res = []
lis = sorted([int(x) for x in set(s)])
#print(lis)
temp = []
for i in range(len(lis)):
if i==0:
res.append([lis[i]])
else:
if lis[i]-lis[i-1]==1:
res[-1].append(lis[i])
else:
temp = []
temp.append(lis[i])
res.append(temp)
#print(f"temp is {temp}")
#res.append(temp)
res2 = ""
for x in res:
if len(x)==1:
res2 = res2+f",{x[0]}"
else:
res2 = res2+f",{min(x)}-{max(x)}"
#print(res)
if res2.startswith(","):
res2 = res2[1:]
print(res2)
t -= 1
``` | instruction | 0 | 25,075 | 20 | 50,150 |
Yes | output | 1 | 25,075 | 20 | 50,151 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30
Submitted Solution:
```
s = list(map(int, input().split(',')))
d = list({i : 1 for i in s}.keys())
d.sort()
f = False
ans = ''
for i in range(len(d) - 1):
if d[i + 1] - d[i] == 1 and f:
continue
elif d[i + 1] - d[i] == 1 and (not f):
ans += '{}-'.format(d[i])
f = True
elif d[i + 1] - d[i] != 1 and f:
ans += '{},'.format(d[i])
else:
ans += '{},'.format(d[i])
ans += str(d[-1])
print(ans)
``` | instruction | 0 | 25,076 | 20 | 50,152 |
No | output | 1 | 25,076 | 20 | 50,153 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30
Submitted Solution:
```
l=list(map(int,input().split(",")))
l.sort()
l=list(set(l))
i=l[0]
c=0
while True:
if i+1 in l:
j=i+1
p=i+2
while True:
if p in l:
j=p
p+=1
else:
break
if l.index(j)+1!=len(l):
print(str(i)+"-"+str(j)+",",end="")
i=l[l.index(j)+1]
else:
print(str(i)+"-"+str(j),end="")
c=1
else:
if l.index(i)+1!=len(l):
print(str(i)+",",end="")
i=l[l.index(i)+1]
else:
print(str(i),end="")
c=1
if (c):
break
``` | instruction | 0 | 25,078 | 20 | 50,156 |
No | output | 1 | 25,078 | 20 | 50,157 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30
Submitted Solution:
```
t=input("")
t=t.split(",")
l=[]
for i in range(len(t)):
l.append(int(t[i]))
l=list(set(l))
l.sort()
print(l)
L=[]
L.append([])
a,j=l[0]-1,0
for i in range(len(l)):
if l[i]==a+1:
L[j].append(l[i])
else:
j+=1
L.append([])
L[j].append(l[i])
a=l[i]
print(L)
for i in range(len(L)-1):
if len(L[i])==1:
print(L[i][0],end=",")
else:
print(str(L[i][0])+"-"+str(L[i][len(L[i])-1]),end=",")
i=len(L)-1
if len(L[i])==1:
print(L[i][0])
else:
print(str(L[i][0])+"-"+str(L[i][len(L[i])-1]))
``` | instruction | 0 | 25,079 | 20 | 50,158 |
No | output | 1 | 25,079 | 20 | 50,159 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Examples
Input
4500
Output
4747
Input
47
Output
47 | instruction | 0 | 25,302 | 20 | 50,604 |
Tags: dp, greedy
Correct Solution:
```
from sys import stdin,stdout
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007
from itertools import permutations as perm
pos = []
n = 2
while n <= 8:
cur = '4' * (n // 2) + '7' * (n // 2)
pos.extend(sorted([int("".join(i)) for i in perm(cur)]))
n += 2
pos.append(4444477777)
n = ii1()
for i in pos:
if i >= n:
print(i)
break
``` | output | 1 | 25,302 | 20 | 50,605 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Examples
Input
4500
Output
4747
Input
47
Output
47 | instruction | 0 | 25,303 | 20 | 50,606 |
Tags: dp, greedy
Correct Solution:
```
l= ["4","7"]
pre= 0
for k in range(7):
le= len(l)
while pre < le:
l += [l[pre]+"4",l[pre]+"7"]
pre += 1
n= int(input())
m= []
for p in l:
if p.count("4") == p.count("7"):
m += [int(p)]
m.sort()
m += [4444477777]
for ij in m:
if ij >= n:
print(ij)
break
``` | output | 1 | 25,303 | 20 | 50,607 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Examples
Input
4500
Output
4747
Input
47
Output
47 | instruction | 0 | 25,304 | 20 | 50,608 |
Tags: dp, greedy
Correct Solution:
```
arr=[]
def lucky(n,curr):
if n<=2 and n>=0:
if str(curr).count('4')==str(curr).count('7'):
arr.append(curr)
if n<0:
return
else:
lucky(n-1,curr*10+4)
lucky(n-1,curr*10+7)
n=int(input())
m=0
if len(str(n))%2==1:
m=len(str(n))+1
lucky(m,0)
else:
m=len(str(n))
lucky(m+2,0)
ans=10**15
for i in arr:
if i>=n and i<ans:
ans=i
print(ans)
``` | output | 1 | 25,304 | 20 | 50,609 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Examples
Input
4500
Output
4747
Input
47
Output
47 | instruction | 0 | 25,305 | 20 | 50,610 |
Tags: dp, greedy
Correct Solution:
```
t=[47, 74, 4477, 4747, 4774, 7447, 7474, 7744, 444777, 447477, 447747, 447774, 474477, 474747, 474774, 477447, 477474, 477744, 744477, 744747, 744774, 747447, 747474, 747744, 774447, 774474, 774744, 777444, 44447777, 44474777, 44477477, 44477747, 44477774, 44744777, 44747477, 44747747, 44747774, 44774477, 44774747, 44774774, 44777447, 44777474, 44777744, 47444777, 47447477, 47447747, 47447774, 47474477, 47474747, 47474774, 47477447, 47477474, 47477744, 47744477, 47744747, 47744774, 47747447, 47747474, 47747744, 47774447, 47774474, 47774744, 47777444, 74444777, 74447477, 74447747, 74447774, 74474477, 74474747, 74474774, 74477447, 74477474, 74477744, 74744477, 74744747, 74744774, 74747447, 74747474, 74747744, 74774447, 74774474, 74774744, 74777444, 77444477, 77444747, 77444774, 77447447, 77447474, 77447744, 77474447, 77474474, 77474744, 77477444, 77744447, 77744474, 77744744, 77747444, 77774444, 4444477777]
import bisect
n=int(input())
p=bisect.bisect_left(t,n)
print(t[p])
``` | output | 1 | 25,305 | 20 | 50,611 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Examples
Input
4500
Output
4747
Input
47
Output
47 | instruction | 0 | 25,306 | 20 | 50,612 |
Tags: dp, greedy
Correct Solution:
```
from itertools import combinations
n = input()
t = len(n)
if t%2:
print('4'*(t//2+1)+'7'*(t//2+1))
else:
for com in combinations(range(t), t//2):
num = ['7']*t
for s in com:
num[s] = '4'
num = int(''.join(num))
if num >= int(n):
print(num)
exit()
print('4'*(t//2+1)+'7'*(t//2+1))
``` | output | 1 | 25,306 | 20 | 50,613 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Examples
Input
4500
Output
4747
Input
47
Output
47 | instruction | 0 | 25,307 | 20 | 50,614 |
Tags: dp, greedy
Correct Solution:
```
#python3
import sys, threading, os.path
import collections, heapq, math,bisect
import string
from platform import python_version
import itertools
sys.setrecursionlimit(10**6)
threading.stack_size(2**27)
def main():
if os.path.exists('input.txt'):
input = open('input.txt', 'r')
else:
input = sys.stdin
#--------------------------------INPUT---------------------------------
st = list(str(input.readline().rstrip('\n')))
if st == ['7','7','4','8'] or st == ['7','7','7','3']:
output = 444777
elif len(st)==1 or st == ['4','7'] or st == ['7','4']:
output = 47
else:
goal = -1
for i,x in enumerate(st):
if x >'7' or (i+1==len(st) and x=='7'):
if i ==0:
goal = 0
else:
goal = i-1
break
if goal!=-1:
for i in range(goal,-1,-1):
if st[i]<'4':
st[i]= '4'
for j in range(i+1,len(st)):
st[j]='0'
break
elif st[i]<'7' and st[i]>='4':
st[i]= '7'
for j in range(i+1,len(st)):
st[j]='0'
break
elif st[i]>'7' or (i==0 and st[i]>='7'):
st+='0'
st[i]='4'
for j in range(i+1,len(st)):
st[j]='0'
break
if len(st)%2==1:
st+='0'
for i in range(len(st)):
st[i]='0'
now = 0
res = []
for x in st:
if x<'4':
now=1
if x <='4' or now==1:
res+='4'
else:
res+='7'
fours,sevs = 0,0
for x in res:
if x=='4':
fours+=1
else:
sevs+=1
for i in range(sevs-fours):
res+='4'
fours-=1
for i in range(len(res)-1,-1,-1):
if fours>sevs and res[i]=='4':
res[i]='7'
fours-=1
sevs+=1
ress = ''
for x in res:
ress+=x
output = ress
#-------------------------------OUTPUT----------------------------------
if os.path.exists('output.txt'):
open('output.txt', 'w').writelines(str(output))
else:
sys.stdout.write(str(output))
if __name__ == '__main__':
main()
#threading.Thread(target=main).start()
``` | output | 1 | 25,307 | 20 | 50,615 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Examples
Input
4500
Output
4747
Input
47
Output
47 | instruction | 0 | 25,308 | 20 | 50,616 |
Tags: dp, greedy
Correct Solution:
```
import math
def facts(n):
ans = []
for i in range(1, int(math.sqrt(n)+1)):
if(n%i==0):
ans.append(i)
ans.append(n//i)
ans = sorted(list(dict.fromkeys(ans)))
if(ans[-1]==n):
ans = ans[:-1]
return ans
def lucks(n):
nums = []
for mask in range((1<<n)):
tmp = ''
for x in range(n, 0, -1):
for i in range(n):
if((mask>>i)&1):
tmp+='4'
else:
tmp+='7'
if(tmp[:x].count('4')==tmp[:x].count('7')):
nums.append(int(tmp[:x]))
return sorted(set(nums))
ls = lucks(10)
n = int(input())
left = 0
right = len(ls)
while(left < right):
mid = (left+right)//2
if(ls[mid] >= n):
right = mid
else:
left = mid+1
print(ls[left])
``` | output | 1 | 25,308 | 20 | 50,617 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Examples
Input
4500
Output
4747
Input
47
Output
47 | instruction | 0 | 25,309 | 20 | 50,618 |
Tags: dp, greedy
Correct Solution:
```
from math import*
s=set()
def f(t,k4,k7):
global s
if t and k4==k7:
s|={int(t)}
if len(t)==10:
return
f(t+'4',k4+1,k7)
f(t+'7',k4,k7+1)
f('',0,0)
s=sorted(s)
n=int(input())
for x in s:
if x>=n:
print(x)
exit()
``` | output | 1 | 25,309 | 20 | 50,619 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Examples
Input
4500
Output
4747
Input
47
Output
47
Submitted Solution:
```
l = [4,7]
n =int(input())
elem =0
while (l[elem]< 10e9):
l.append(l[elem]*10+4)
l.append(l[elem]*10+7)
elem+=1
l =[i for i in l if str(i).count('7') == str(i).count('4')]
from bisect import bisect_right as indeX
pos = indeX(l,n)
if n in l:
print(l[pos-1])
else:
print(l[pos])
``` | instruction | 0 | 25,310 | 20 | 50,620 |
Yes | output | 1 | 25,310 | 20 | 50,621 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Examples
Input
4500
Output
4747
Input
47
Output
47
Submitted Solution:
```
n = int(input())
a = set()
for i in range(1, 11):
for j in range(2**i):
c = j
cnt = 0
t = 0
b = 0
while c or cnt < i:
if c&1:
t = t*10+7
b += 1
else:
t = t*10+4
b -= 1
cnt += 1
c //= 2
if b == 0:
a.add(t)
a = sorted(list(a))
for x in a:
if x >= n:
print(x)
break
``` | instruction | 0 | 25,311 | 20 | 50,622 |
Yes | output | 1 | 25,311 | 20 | 50,623 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Examples
Input
4500
Output
4747
Input
47
Output
47
Submitted Solution:
```
import math, re, sys, string, operator, functools, fractions, collections
sys.setrecursionlimit(10**7)
RI=lambda x=' ': list(map(int,input().split(x)))
RS=lambda x=' ': input().rstrip().split(x)
dX= [-1, 1, 0, 0,-1, 1,-1, 1]
dY= [ 0, 0,-1, 1, 1,-1,-1, 1]
mod=int(1e9+7)
eps=1e-6
pi=math.acos(-1.0)
MAX=10**5+10
#################################################
n=RI()[0]
def check(n):
cnt=[0,0]
while n:
if n%10==4:
cnt[0]+=1
else:
cnt[1]+=1
n//=10
return (cnt[0]==cnt[1])
for l in range(2,11,2):
for i in range(1<<l):
num=i
v=0
for j in range(l-1,-1,-1):
v*=10
if (num>>j)&1:
v+=7
else:
v+=4
if v>=n and check(v):
print(v)
exit(0)
``` | instruction | 0 | 25,312 | 20 | 50,624 |
Yes | output | 1 | 25,312 | 20 | 50,625 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Examples
Input
4500
Output
4747
Input
47
Output
47
Submitted Solution:
```
n = int(input())
ans = []
def lucky(x):
if x >= n and str(x).count('4') == str(x).count('7'):
ans.append(x)
if x < 10 ** 12:
lucky(x * 10 + 4)
lucky(x * 10 + 7)
lucky(0)
ans.sort()
print(ans[0])
``` | instruction | 0 | 25,313 | 20 | 50,626 |
Yes | output | 1 | 25,313 | 20 | 50,627 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Examples
Input
4500
Output
4747
Input
47
Output
47
Submitted Solution:
```
import sys
def fastio():
from io import StringIO
from atexit import register
global input
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
s = list(input())
n = len(s)
ans = ['4'] * (n + n % 2)
for i in range(len(ans) // 2):
ans[i] = '7'
if n % 2:
n += 1
print('4' * (n // 2) + '7' * (n // 2))
exit()
if ans < s:
print(''.join(sorted(ans + ['4', '7'])))
exit()
if ans == s:
print(''.join(ans))
exit()
ans = ['4'] * (n // 2) + ['7'] * (n // 2)
if ans >= s:
print(''.join(ans))
exit()
for i in range(n):
if s[i] > '4':
ans[i] = '7'
for j in range(i + 1, n):
if ans[j] == '7':
ans[j] = '4'
break
break
print(''.join(ans))
``` | instruction | 0 | 25,314 | 20 | 50,628 |
No | output | 1 | 25,314 | 20 | 50,629 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Examples
Input
4500
Output
4747
Input
47
Output
47
Submitted Solution:
```
import itertools as it
n=input()
nn=len(n)
if nn%2:
print('4'*((nn+1)//2)+'7'*((nn+1)//2))
elif int('7'*(nn//2)+'4'*(nn//2))<int(n):
print('4'*(nn+2)//2+'7'*(nn+2)//2)
elif int(n[0])<4:
print('4'*(nn//2)+'7'*(nn//2))
ans='4'*(nn//2)+'7'*(nn//2)
an=[]
#print("asdf")
for i in it.permutations(ans,nn):
i=list(i)
an.append(int(''.join(i)))
an.sort()
for i in an:
if i>=int(n):
print(i)
break
``` | instruction | 0 | 25,315 | 20 | 50,630 |
No | output | 1 | 25,315 | 20 | 50,631 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Examples
Input
4500
Output
4747
Input
47
Output
47
Submitted Solution:
```
n = int(input())
s = [0]
while True:
for i in s:
if 10*i+4>=n:
print (10*i+4)
exit()
elif 10*i+7>=n:
print (10*i+7)
exit()
else:
s.append(10*i+4)
s.append(10*i+7)
``` | instruction | 0 | 25,316 | 20 | 50,632 |
No | output | 1 | 25,316 | 20 | 50,633 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Examples
Input
4500
Output
4747
Input
47
Output
47
Submitted Solution:
```
def num(n):
return ('7'*((n)//2)+'4'*((n)//2))
def lucky(n):
c4=0
c7=0
for i in str(n):
if(i=='4'):
c4+=1
elif(i=='7'):
c7+=1
else:
return False
if(c4==c7):
return True
return False
s=input()
c4=0
c7=0
n=len(s)
ans=''
if(len(s)%2==1):
print('4'*((n+1)//2)+'7'*((n+1)//2))
exit()
if(int(s)>int(num(n))):
print(num(n+2)[::-1])
exit()
if(int(s)<int(num(n))):
print(num(n)[::-1])
exit()
ans=int(s)
while(True):
if(lucky(ans)):
print(ans)
break
ans+=1
``` | instruction | 0 | 25,317 | 20 | 50,634 |
No | output | 1 | 25,317 | 20 | 50,635 |
Provide a correct Python 3 solution for this coding contest problem.
Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | instruction | 0 | 25,552 | 20 | 51,104 |
"Correct Solution:
```
import math
# import numpy as np # Pythonのみ!
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components # Pythonのみ!
# ↑cf. https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
p,q=map(int,input().split())
g=math.gcd(p,q)
p//=g
q//=g
# cf. https://qiita.com/suecharo/items/14137fb74c26e2388f1f
def make_prime_list_2(num):
if num < 2:
return []
# 0のものは素数じゃないとする
prime_list = [i for i in range(num + 1)]
prime_list[1] = 0 # 1は素数ではない
num_sqrt = math.sqrt(num)
for prime in prime_list:
if prime == 0:
continue
if prime > num_sqrt:
break
for non_prime in range(2 * prime, num, prime):
prime_list[non_prime] = 0
return [prime for prime in prime_list if prime != 0]
def prime_factorization_2(num):
"""numの素因数分解
素因数をkeyに乗数をvalueに格納した辞書型dict_counterを返す"""
if num <= 1:
# 例えば1を食ったときの対処の仕方は問題によって違うと思うのでそのつど考える。
# cf. https://atcoder.jp/contests/abc110/submissions/12688244
return False
else:
num_sqrt = math.floor(math.sqrt(num))
prime_list = make_prime_list_2(num_sqrt)
dict_counter = {} # 何度もこの関数を呼び出して辞書を更新したい時はこれを引数にして
# cf. https://atcoder.jp/contests/arc034/submissions/12251452
for prime in prime_list:
while num % prime == 0:
if prime in dict_counter:
dict_counter[prime] += 1
else:
dict_counter[prime] = 1
num //= prime
if num != 1:
if num in dict_counter:
dict_counter[num] += 1
else:
dict_counter[num] = 1
return dict_counter
d=prime_factorization_2(q)
ans=1
for k in d.keys():
ans*=k
print(ans)
resolve()
``` | output | 1 | 25,552 | 20 | 51,105 |
Provide a correct Python 3 solution for this coding contest problem.
Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | instruction | 0 | 25,555 | 20 | 51,110 |
"Correct Solution:
```
prime = [2]
def check(x):
for i in prime:
if x % i ==0:
return False
elif x < i * i:
break
return True
def set():
for i in range(3,10**5,2):
if check(i):
prime.append(i)
set()
#print('ok')
#print(prime)
p,q = [int(i) for i in input().split(' ')]
if q % p == 0:
q = q //p
p = 1
for i in prime:
while True:
if p % i ==0 and q % i == 0:
p = p // i
q = q // i
#print(p,q,i)
else:
break
ans = 1
#print(p,q)
for i in prime:
if q % i == 0:
# print(q,i)
q = q // i
ans *= i
while q % i ==0:
q = q // i
ans *= q
print(ans)
``` | output | 1 | 25,555 | 20 | 51,111 |
Provide a correct Python 3 solution for this coding contest problem.
Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | instruction | 0 | 25,557 | 20 | 51,114 |
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
while True:
p,q = LI()
g = fractions.gcd(p,q)
t = q//g
k = 1
if t % 2 == 0:
k *= 2
while t % 2 == 0:
t //= 2
for i in range(3,int(math.sqrt(t))+2,2):
if t % i > 0:
continue
k *= i
while t % i == 0:
t //= i
rr.append(t*k)
break
return '\n'.join(map(str, rr))
print(main())
``` | output | 1 | 25,557 | 20 | 51,115 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
<image>
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":
<image> <image>
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?
Input
The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
Output
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line.
Examples
Input
3
586
Output
NO
Input
2
09
Output
NO
Input
9
123456789
Output
YES
Input
3
911
Output
YES
Note
You can find the picture clarifying the first sample case in the statement above. | instruction | 0 | 26,077 | 20 | 52,154 |
Tags: brute force, constructive algorithms, implementation
Correct Solution:
```
input()
s=set(map(int,input()))
f=lambda x: set(x)&s!=set()
print("YES" if all(map(f,([1,4,7,0],[1,2,3],[3,6,9,0],[7,0,9]))) else "NO")
# Made By Mostafa_Khaled
``` | output | 1 | 26,077 | 20 | 52,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
<image>
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":
<image> <image>
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?
Input
The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
Output
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line.
Examples
Input
3
586
Output
NO
Input
2
09
Output
NO
Input
9
123456789
Output
YES
Input
3
911
Output
YES
Note
You can find the picture clarifying the first sample case in the statement above. | instruction | 0 | 26,078 | 20 | 52,156 |
Tags: brute force, constructive algorithms, implementation
Correct Solution:
```
keys = {'1': (1, 1), '2': (1, 2), '3': (1, 3),
'4': (2, 1), '5': (2, 2), '6': (2, 3),
'7': (3, 1), '8': (3, 2), '9': (3, 3),
'0': (4, 2)}
input()
num = input()
left = right = up = down = 0
contains_zero = False
contains_seven = False
contains_eight = False
contains_nine = False
for ch in num:
y, x = keys[ch]
if ch == '0':
contains_zero = True
if ch == '7':
contains_seven = True
if ch == '8':
contains_eight = True
if ch == '9':
contains_nine = True
if left == 0:
left = x
elif x < left:
left = x
if up == 0:
up = y
elif y < up:
up = y
if right == 0:
right = x
elif x > right:
right = x
if down == 0:
down = y
elif y > down:
down = y
if contains_zero:
if up > 1:
answer = True
else:
answer = False
elif left > 1 or right < 3 or down < 3 or up > 1:
answer = True
elif contains_eight and not contains_nine and not contains_seven:
answer = True
else:
answer = False
if answer:
print("NO")
else:
print("YES")
``` | output | 1 | 26,078 | 20 | 52,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
<image>
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":
<image> <image>
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?
Input
The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
Output
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line.
Examples
Input
3
586
Output
NO
Input
2
09
Output
NO
Input
9
123456789
Output
YES
Input
3
911
Output
YES
Note
You can find the picture clarifying the first sample case in the statement above. | instruction | 0 | 26,079 | 20 | 52,158 |
Tags: brute force, constructive algorithms, implementation
Correct Solution:
```
n = int(input())
# a, b = map(int, input().split())
number = input()
numpad = [['1', '2', '3'],
['4', '5', '6'],
['7', '8', '9'],
[None, '0', None]]
def get_coordinates(digit):
if digit in ('1', '2', '3'):
first_coordinate = 0
second_coordinate = int(digit) - 1
elif digit in ('4', '5', '6'):
first_coordinate = 1
second_coordinate = int(digit) - 4
elif digit in ('7', '8', '9'):
first_coordinate = 2
second_coordinate = int(digit) - 7
else:
first_coordinate = 3
second_coordinate = 1
return first_coordinate, second_coordinate
def add(v1, v2):
return v1[0] + v2[0], v1[1] + v2[1]
def sub(v1, v2):
return v1[0] - v2[0], v1[1] - v2[1]
def try_it(start_digit, what_to_do):
current_coordinates = get_coordinates(start_digit)
for move in what_to_do:
current_coordinates = add(current_coordinates, move)
if current_coordinates[0] < 0 or current_coordinates[1] < 0:
return False
try:
_ = numpad[current_coordinates[0]][current_coordinates[1]]
except IndexError:
return False
if _ is None:
return False
return True
sequence = []
for i in range(n - 1):
sequence.append(sub(get_coordinates(number[i + 1]), get_coordinates(number[i])))
for digit in set('1234567890') - set(number[0]):
if try_it(digit, sequence):
print('NO')
break
else:
print('YES')
``` | output | 1 | 26,079 | 20 | 52,159 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
<image>
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":
<image> <image>
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?
Input
The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
Output
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line.
Examples
Input
3
586
Output
NO
Input
2
09
Output
NO
Input
9
123456789
Output
YES
Input
3
911
Output
YES
Note
You can find the picture clarifying the first sample case in the statement above. | instruction | 0 | 26,080 | 20 | 52,160 |
Tags: brute force, constructive algorithms, implementation
Correct Solution:
```
n = input()
s = input()
up = len([i for i in ['1', '2', '3'] if i in s]) == 0
right = len([i for i in ['3', '6', '9', '0'] if i in s]) == 0
left = len([i for i in ['1', '4', '7', '0'] if i in s]) == 0
down = len([i for i in ['7', '9', '0'] if i in s]) == 0
ok = not(up or right or left or down)
if ok:
print("YES")
else:
print("NO")
``` | output | 1 | 26,080 | 20 | 52,161 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
<image>
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":
<image> <image>
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?
Input
The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
Output
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line.
Examples
Input
3
586
Output
NO
Input
2
09
Output
NO
Input
9
123456789
Output
YES
Input
3
911
Output
YES
Note
You can find the picture clarifying the first sample case in the statement above. | instruction | 0 | 26,081 | 20 | 52,162 |
Tags: brute force, constructive algorithms, implementation
Correct Solution:
```
import sys
n = int(input())
s = input()
way = []
for x in s:
if x == '0':
way.append(10)
else:
way.append(int(x)-1)
count = 0
for i in range(10):
if i == 9:
now = 10
else:
now = i
flag = 0
for j in range(n-1):
dif = way[j+1]-way[j]
div1 = way[j+1]//3 - way[j]//3
div2 = (now+dif)//3 - now//3
mod1 = way[j+1]%3 - way[j]%3
mod2 = (now+dif)%3 - now%3
if not(div1==div2 and mod1 == mod2):
flag = 1
now+=dif
if not(now == 10 or (-1 < now < 9)):
flag = 1
if flag == 0:
count+=1
if count<=1:
print('YES')
else:
print('NO')
``` | output | 1 | 26,081 | 20 | 52,163 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
<image>
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":
<image> <image>
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?
Input
The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
Output
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line.
Examples
Input
3
586
Output
NO
Input
2
09
Output
NO
Input
9
123456789
Output
YES
Input
3
911
Output
YES
Note
You can find the picture clarifying the first sample case in the statement above. | instruction | 0 | 26,082 | 20 | 52,164 |
Tags: brute force, constructive algorithms, implementation
Correct Solution:
```
n=input()
s=set(map(int,input()))
f=lambda x: x&s!=set()
print("NO" if sum([f({1,4,7,0}),f({1,2,3}),f({3,6,9,0}),f({7,0,9})])<4 else "YES")
``` | output | 1 | 26,082 | 20 | 52,165 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
<image>
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":
<image> <image>
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?
Input
The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
Output
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line.
Examples
Input
3
586
Output
NO
Input
2
09
Output
NO
Input
9
123456789
Output
YES
Input
3
911
Output
YES
Note
You can find the picture clarifying the first sample case in the statement above. | instruction | 0 | 26,083 | 20 | 52,166 |
Tags: brute force, constructive algorithms, implementation
Correct Solution:
```
def check(a, b):
if a == nums[0][0] and b == nums[0][1]:
return 1
ma = a - nums[0][0]
mb = b - nums[0][1]
for t in nums:
if not ((0 <= t[0] + ma <= 2 and 0 <= t[1] + mb <= 2) or (t[0] + ma == 3 and t[1] + mb == 1)):
return 0
return 1
n = int(input())
nums = [int(t) for t in input()]
for i in range(n):
if nums[i] == 0: nums[i] = 10
else: nums[i] -= 1
for i in range(n):
nums[i] = (nums[i] // 3, nums[i] % 3)
suma = 0
for i in range(3):
for j in range(3):
suma += check(i, j)
suma += check(3, 1)
if suma - 1:
print('NO')
else:
print('YES')
``` | output | 1 | 26,083 | 20 | 52,167 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
<image>
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":
<image> <image>
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?
Input
The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
Output
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line.
Examples
Input
3
586
Output
NO
Input
2
09
Output
NO
Input
9
123456789
Output
YES
Input
3
911
Output
YES
Note
You can find the picture clarifying the first sample case in the statement above. | instruction | 0 | 26,084 | 20 | 52,168 |
Tags: brute force, constructive algorithms, implementation
Correct Solution:
```
n = int(input())
s = input()
a = [s.find(str(i)) != -1 for i in range(10)]
print("YES" if (a[1] or a[4] or a[7] or a[0]) and (a[1] or a[2] or a[3]) and (a[3] or a[6] or a[9] or a[0]) and (a[7] or a[0] or a[9]) else "NO")
``` | output | 1 | 26,084 | 20 | 52,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
<image>
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":
<image> <image>
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?
Input
The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
Output
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line.
Examples
Input
3
586
Output
NO
Input
2
09
Output
NO
Input
9
123456789
Output
YES
Input
3
911
Output
YES
Note
You can find the picture clarifying the first sample case in the statement above.
Submitted Solution:
```
import sys
n = int(sys.stdin.readline()) # n = int(input())
digits = [int(x) for x in sys.stdin.readline().strip()] # digits = [int(x) for x in input()]
def can_go_left(digits):
return all(x not in digits for x in [0, 1, 4, 7])
def can_go_right(digits):
return all(x not in digits for x in [0, 3, 6, 9])
def can_go_up(digits):
return all(x not in digits for x in [1, 2, 3])
def can_go_down(digits):
return all(x not in digits for x in [0, 7, 9])
if can_go_left(digits) or can_go_right(digits) or can_go_up(digits) or can_go_down(digits):
print("NO")
else:
print("YES")
``` | instruction | 0 | 26,085 | 20 | 52,170 |
Yes | output | 1 | 26,085 | 20 | 52,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
<image>
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":
<image> <image>
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?
Input
The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
Output
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line.
Examples
Input
3
586
Output
NO
Input
2
09
Output
NO
Input
9
123456789
Output
YES
Input
3
911
Output
YES
Note
You can find the picture clarifying the first sample case in the statement above.
Submitted Solution:
```
a = input()
number = input()
bot = False
top = False
left = False
right = False
topS = {'1', '2', '3'}
botS = {'7', '0', '9'}
leftS = {'1', '4', '7', '0'}
rightS = {'3', '6', '9', '0'}
for c in number:
if c in topS:
top = True
if c in botS:
bot = True
if c in leftS:
left = True
if c in rightS:
right = True
if top and bot and right and left :
print("YES")
else:
print("NO")
``` | instruction | 0 | 26,086 | 20 | 52,172 |
Yes | output | 1 | 26,086 | 20 | 52,173 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.