description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0, 1, 0, 1}, {1, 0, 1}, and {1, 0, 1, 0} are alternating sequences, while {1, 0, 0} and {0, 1, 0, 1, 1} are not.
Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.
Input
The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000).
The following line contains a binary string of length n representing Kevin's results on the USAICO.
Output
Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.
Examples
Input
8
10000011
Output
5
Input
2
01
Output
2
Note
In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | n = int(input())
seq = input()
prev = -1
ans = 0
for e in seq:
if e != prev:
ans += 1
prev = e
print(min(n, ans + 2)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER |
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0, 1, 0, 1}, {1, 0, 1}, and {1, 0, 1, 0} are alternating sequences, while {1, 0, 0} and {0, 1, 0, 1, 1} are not.
Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.
Input
The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000).
The following line contains a binary string of length n representing Kevin's results on the USAICO.
Output
Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.
Examples
Input
8
10000011
Output
5
Input
2
01
Output
2
Note
In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | n = map(int, input().split())
a = input()
prev, cur = "0", "0"
t = 1
flag = 0
x = 1
if len(a) > 1:
for i in range(len(a)):
cur = a[i]
if i > 0:
if prev == cur:
x = x + 1
else:
x = 1
t += 1
if x >= 2:
flag += 1
prev = cur
if flag >= 2:
t += 2
elif flag > 0:
t += 1
print(int(t)) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0, 1, 0, 1}, {1, 0, 1}, and {1, 0, 1, 0} are alternating sequences, while {1, 0, 0} and {0, 1, 0, 1, 1} are not.
Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.
Input
The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000).
The following line contains a binary string of length n representing Kevin's results on the USAICO.
Output
Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.
Examples
Input
8
10000011
Output
5
Input
2
01
Output
2
Note
In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | n = int(input())
x = input()
q = []
for y in x:
q.append(int(y))
def get_score(x, y):
score = 1
f = q[x]
for i in range(x + 1, y):
if q[i] != f:
score += 1
f = 1 - f
return score
flip = 1
for i in range(1, n):
if flip == 1:
if q[i] == q[i - 1]:
flip = 0
q[i] = 1 - q[i]
elif flip == 0 and q[i] == q[i - 1]:
q[i] = 1 - q[i]
else:
break
print(get_score(0, n)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR |
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 | from itertools import permutations
s = input()
n = len(s)
s = int(s)
co = False
if n % 2 == 1:
co = True
if n % 2 == 0:
k = n // 2
ans = ""
for i in range(k):
ans += "4"
for i in range(k):
ans += "7"
co = True
n = n + 1
l = list(set(permutations(ans)))
l = sorted(l)
for i in range(len(l)):
number = int("".join(l[i]))
if number >= s:
co = False
print(number)
break
if co:
n = n + 1
k = n // 2
ans = ""
for i in range(k):
ans += "4"
for i in range(k):
ans += "7"
print(ans) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR |
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 | import sys
sys.setrecursionlimit(100000)
n = sys.stdin.readline().strip()
arr = []
def val(num_four, num_seven, s=""):
if num_four > 0:
arr.append(s + "4")
val(num_four - 1, num_seven, s + "4")
if num_seven > 0:
arr.append(s + "7")
val(num_four, num_seven - 1, s + "7")
def equal(s):
d = {"4": 0, "7": 0}
for i in s:
d[i] += 1
return d["4"] == d["7"]
l = len(n) + 2
n = int(n)
val(l // 2, l // 2)
k = sorted([int(x) for x in arr])
arr = [str(x) for x in k]
for i in arr:
if equal(i) and int(i) >= n:
print(i)
break | IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR STRING FUNC_DEF ASSIGN VAR DICT STRING STRING NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER RETURN VAR STRING VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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 | def nextPermutation(nums):
i = j = len(nums) - 1
while i > 0 and nums[i] <= nums[i - 1]:
i -= 1
i -= 1
if i < 0:
nums.reverse()
return
while j > i and nums[j] <= nums[i]:
j -= 1
nums[i], nums[j] = nums[j], nums[i]
k, l = i + 1, len(nums) - 1
while k < l:
nums[k], nums[l] = nums[l], nums[k]
k += 1
l -= 1
s = list(input(""))
l = len(s)
if l % 2:
l += 1
k = l
l //= 2
ans = "4" * l + "7" * l
if k % 2:
ans = "4" + ans
print(ans)
else:
l = l // 2
ans = "4" * l + "7" * l
ans = list(ans)
itera = 0
flag = 0
while ans < s:
nextPermutation(ans)
itera += 1
if itera > 2 ** (2 * l):
flag = 1
break
sol = "".join(ans)
if flag:
l += 1
sol = "4" * l + "7" * l
print(int(sol)) | FUNC_DEF ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR RETURN WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
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 | def pnr(r, n):
res = float("inf")
p = 1 << r + 1
leaf = 1 << r
BT = ["0"] * p
for i in range(1, leaf):
BT[2 * i] = BT[i] + "4"
BT[2 * i + 1] = BT[i] + "7"
for i in range(leaf, p):
if BT[i].count("4") == BT[i].count("7"):
N = int(BT[i])
if N >= n:
res = min(res, N)
return res
n = int(input())
for i in range(2, 11, 2):
ans = pnr(i, n)
if ans != float("inf"):
print(ans)
break | FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
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 | from itertools import product
def same_amount_of_4_and_7(list_of_digits):
return list_of_digits.count(4) == list_of_digits.count(7)
numbers = []
for ln in range(1, 11):
numbers += list(product([4, 7], repeat=ln))
numbers = list(filter(same_amount_of_4_and_7, numbers))
for i in range(len(numbers)):
numbers[i] = int("".join(map(str, numbers[i])))
numbers.sort()
a = int(input())
for n in numbers:
if n >= a:
print(n)
break | FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR |
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 | def next_permutation(a):
if len(a) < 2:
return False
i = len(a) - 2
while i >= 0 and a[i] >= a[i + 1]:
i -= 1
if i < 0:
return False
j = i + 1
k = len(a) - 1
while a[i] >= a[k]:
k -= 1
a[i], a[k] = a[k], a[i]
a[j:] = a[: j - 1 : -1]
return True
n = input().strip()
l = len(n) + 1 >> 1
if len(n) % 2 == 1:
print("4" * l + "7" * l)
elif n > "7" * l + "4" * l:
print("4" * l + "47" + "7" * l)
else:
a = list("4" * l + "7" * l)
x = list(n)
while a < x:
next_permutation(a)
print("".join(a)) | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR STRING BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
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 | b = input()
a = [int(i) for i in b]
l = len(a)
flag = 0
s = 0
f = 0
if l % 2 == 1:
flag = 1
else:
for i in range(l):
if a[i] > 7:
flag = 1
if s == l // 2 or s == i + 1:
break
for j in range(i, -1, -1):
if a[j] == 4:
a[j] = 7
f -= 1
s += 1
flag = 0
i = j
break
break
elif a[i] == 7:
s += 1
elif a[i] > 4:
a[i] = 7
s += 1
if s <= l // 2:
break
elif a[i] == 4:
f += 1
else:
a[i] = 4
f += 1
if f <= l // 2:
break
if s > l // 2:
flag = 1
for j in range(i - 1, -1, -1):
f -= 1
if a[j] == 7:
f += 1
if a[j - 1] == 4:
a[j - 1] = 7
f -= 1
s += 1
flag = 0
i = j - 1
break
s -= 1
break
elif f > l // 2:
a[i] = 7
s += 1
f -= 1
break
if flag:
for i in range(l // 2 + 1):
print(4, end="")
for i in range(l // 2 + 1):
print(7, end="")
else:
for j in range(i + 1):
print(a[j], end="")
for j in range(i + 1, l):
if f < l // 2:
print(4, end="")
f += 1
else:
print(7, end="") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING |
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 | def check(m):
if m >= n and str(m).count("4") == str(m).count("7"):
a.append(m)
if m < 10**12:
check(m * 10 + 4)
check(m * 10 + 7)
n = int(input())
a = []
check(0)
a.sort()
print(a[0]) | FUNC_DEF IF VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER |
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 | def good(n):
if n == 447777:
return 474477
if n == 4777:
return 7447
if n == 47474749:
return 47474774
l = len(str(n))
if l % 2 != 0:
return "4" * ((l + 1) // 2) + "7" * ((l + 1) // 2)
s = str(n)
if int(s[0]) > 7:
l = l + 2
return "4" * (l // 2) + "7" * (l // 2)
a = [i for i in s]
if len(set(a)) == 2 and a.count("4") == a.count("7") and a.count("4") > 0:
return n
if l == 2:
if 47 >= n:
return 47
if 74 >= n:
return 74
temp = 0
for i in range(len(a)):
if a[i] != "7" and a[i] != "4":
temp = i
if int(a[temp]) < 4:
a[temp] = "4"
elif int(a[temp]) < 7 and int(a[temp]) > 4 or a.count("4") > a.count("7"):
a[temp] = "7"
elif int(a[temp]) > 7:
l += 2
return "4" * (l // 2) + "7" * (l // 2)
break
restfour = l // 2 - a[: temp + 1].count("4")
restseven = l // 2 - a[: temp + 1].count("7")
ans = "".join(a[: temp + 1]) + "4" * restfour + "7" * restseven
if int(ans) < n or ans.count("4") != ans.count("7"):
l += 2
return "4" * (l // 2) + "7" * (l // 2)
return ans
print(good(int(input()))) | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER RETURN VAR IF VAR NUMBER IF NUMBER VAR RETURN NUMBER IF NUMBER VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR STRING IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR STRING IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL STRING VAR BIN_OP VAR NUMBER BIN_OP STRING VAR BIN_OP STRING VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING VAR NUMBER RETURN BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
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 | 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 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR |
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 | from itertools import permutations
s = str(input(""))
ma_rs = []
mi_rs = []
n = int((len(s) + 1) / 2)
for i in range(n):
ma_rs.append(4)
mi_rs.append(4)
for i in range(n):
ma_rs.append(7)
mi_rs.append(7)
mi_rs.sort(key=int)
i_mi_rs = int("".join(map(str, mi_rs)))
ma_rs.sort(key=int, reverse=True)
i_ma_rs = int("".join(map(str, ma_rs)))
if int(s) <= i_mi_rs:
print(i_mi_rs)
elif int(s) <= i_ma_rs:
perm = set(permutations(mi_rs))
for i in sorted(list(perm)):
i = int("".join(map(str, i)))
if i >= int(s):
print(i)
break
else:
n = n + 1
mi_rs = []
for i in range(n):
mi_rs.append(4)
for i in range(n):
mi_rs.append(7)
print(int("".join(map(str, mi_rs)))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
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 | def helper(binum, digit):
s = ""
count = 0
while binum > 0:
if binum & 1 == 1:
s = "7" + s
count += 1
else:
s = "4" + s
binum //= 2
if count != digit // 2:
return "-1"
if len(s) == digit:
return s
s = "4" * (digit - len(s)) + s
return s
l = []
for i in range(2, 11, 2):
limit = 2**i
for j in range(limit):
ans = helper(j, i)
if ans == "-1":
continue
l.append(int(ans))
ll = 0
ul = len(l) - 1
n = int(input())
ans = 0
while ll <= ul:
mid = (ll + ul) // 2
if l[mid] >= n:
ans = mid
ul = mid - 1
else:
ll = mid + 1
print(l[ans]) | FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP STRING VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN STRING IF FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
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 | def gen(n):
return "4" * (n // 2) + "7" * (n // 2)
DS = 4, 7
def solve(n):
if len(n) % 2 == 0:
k = len(n) // 2
i = 0
c = [0] * 10
while i < len(n):
d = int(n[i])
if d not in DS or d in DS and c[d] == k:
break
c[d] += 1
i += 1
if i == len(n):
return n
for d in DS:
if c[d] < k and int(n[i]) < d:
c[d] += 1
return n[:i] + str(d) + "4" * (k - c[4]) + "7" * (k - c[7])
while True:
i -= 1
if i < 0:
break
d = int(n[i])
c[d] -= 1
if d == 4 and c[7] < k:
c[7] += 1
return n[:i] + "7" + "4" * (k - c[4]) + "7" * (k - c[7])
return gen((len(n) + 2) // 2 * 2)
n = input()
print(solve(n)) | FUNC_DEF RETURN BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR FOR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR VAR NUMBER BIN_OP STRING BIN_OP VAR VAR NUMBER WHILE NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR STRING BIN_OP STRING BIN_OP VAR VAR NUMBER BIN_OP STRING BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
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 | hi = input()
anslen = len(hi)
if anslen % 2 != 0:
anslen += 1
pos = []
def perms(curr, fours, sevens, total):
if total == 0 and curr >= int(hi):
print(curr)
exit()
elif total != 0:
if fours != 0:
perms(curr * 10 + 4, fours - 1, sevens, total - 1)
if sevens != 0:
perms(curr * 10 + 7, fours, sevens - 1, total - 1)
perms(0, anslen // 2, anslen // 2, anslen)
print("4" * (anslen // 2 + 1) + "7" * (anslen // 2 + 1)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER |
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 | from itertools import permutations as p
def ck(num, arr):
for i in arr:
if i >= num:
print(i)
return
x = input()
z = len(x)
if z == 1:
print(47)
elif z == 2:
if int(x) <= 74:
arr = [47, 74]
ck(int(x), arr)
else:
print(4477)
elif z == 3:
print(4477)
elif z == 4:
if int(x) <= 7744:
arr4 = sorted([int("".join(i)) for i in p("4477")])
ck(int(x), arr4)
else:
print(444777)
elif z == 5:
print(444777)
elif z == 6:
if int(x) <= 777444:
arr6 = sorted([int("".join(i)) for i in p("444777")])
ck(int(x), arr6)
else:
print(44447777)
elif z == 7:
print(44447777)
elif z == 8:
if int(x) <= 77774444:
arr8 = sorted([int("".join(i)) for i in p("44447777")])
ck(int(x), arr8)
else:
print(4444477777)
else:
print(4444477777) | FUNC_DEF FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
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 | n = int(input())
def search(c, d, l):
if d == 0:
if c >= n:
print(c)
exit()
return
if l:
search(10 * c + 4, d - 1, l - 1)
if l < d:
search(10 * c + 7, d - 1, l)
for i in range(2, 10, 2):
search(0, i, i // 2)
print(4444477777) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
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 | nums = []
for mask in range(1 << 10):
set = 0
count4 = 0
count7 = 0
for i in range(10):
if mask & 1 << i != 0:
set += 1
bound = -1
for i in range(10):
if mask & 1 << i == 0:
count7 += 1
else:
count4 += 1
if count7 == count4:
bound = i + 1
if bound == -1:
continue
count4 = 0
s = str()
for i in range(0, bound):
if mask & 1 << i == 0:
s += "7"
else:
s += "4"
count4 += 1
if count4 != set:
continue
nums.append(int(s))
N = int(input())
nums.sort()
start = 0
end = len(nums) - 1
while start < end:
mid = (start + end) // 2
if nums[mid] < N:
start = mid + 1
else:
end = mid
print(nums[start]) | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR STRING VAR STRING VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR |
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 | def nextLuckyNumber(digits: str) -> str:
n = len(digits)
halfLen = n >> 1
if n & 1 or digits > f"{'7' * halfLen}{'4' * halfLen}":
halfLen += 1
return f"{'4' * halfLen}{'7' * halfLen}"
result = [(0) for i in range(n)]
remaining = [halfLen, halfLen]
for i in range(n):
add4 = False
if remaining[0]:
if digits[i] < "4":
add4 = True
elif digits[i] == "4":
lastIdx = i + remaining[1]
for j in range(i + 1, n):
d = "7" if j <= lastIdx else "4"
if digits[j] < d:
add4 = True
break
elif digits[j] > d:
add4 = False
break
elif j == n - 1:
add4 = True
if add4:
result[i] = "4"
remaining[0] -= 1
else:
result[i] = "7"
remaining[1] -= 1
if result[i] > digits[i] or remaining[1] == 0:
for k in range(i + 1, i + 1 + remaining[0]):
result[k] = "4"
for k in range(i + 1 + remaining[0], i + 1 + remaining[0] + remaining[1]):
result[k] = "7"
break
return "".join(result)
print(nextLuckyNumber(input())) | FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP STRING VAR BIN_OP STRING VAR VAR NUMBER RETURN BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR STRING STRING IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR STRING VAR NUMBER NUMBER ASSIGN VAR VAR STRING VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR STRING RETURN FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
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 | from itertools import product
lucky = []
for i in range(10):
for p in product([4, 7], repeat=i + 1):
name = ""
fours = 0
sevens = 0
for j in range(len(p)):
name += str(p[j])
if p[j] == 4:
fours += 1
else:
sevens += 1
if fours == sevens:
lucky.append(int(name))
hi = len(lucky) - 1
low = 0
n = int(input())
if n <= 47:
print(47)
exit(0)
while hi > low:
mid = (hi + low) // 2
if lucky[mid] == n:
print(n)
break
if lucky[mid] < n < lucky[mid + 1]:
print(lucky[mid + 1])
break
if n < lucky[mid]:
hi = mid
else:
low = mid | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR LIST NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR |
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 | n = 0
s = ""
def check():
global n
global s
t = 0
for i in range(0, len(s) // 2):
t *= 10
t += 7
for i in range(0, len(s) // 2):
t *= 10
t += 4
if int(s) > t:
n += 2
def rec(i):
global n
global s
j = i * 10 + 4
k = i * 10 + 7
f1, f2 = False, False
if len(str(j)) == n:
if j >= int(s) and str(j).count("4") == str(j).count("7"):
f1 = True
if k >= int(s) and str(k).count("4") == str(k).count("7"):
f2 = True
if f1 and f2:
return min(k, j)
elif f1:
return j
elif f2:
return k
else:
return 1000000000000000.0
return min(rec(k), rec(j))
s = input()
n = len(s) + int(len(s) % 2 != 0)
if len(s) % 2 == 0:
check()
print(rec(0)) | ASSIGN VAR NUMBER ASSIGN VAR STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR VAR IF VAR RETURN VAR IF VAR RETURN VAR RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER |
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 | N = int(input())
queue = []
queue += [0]
queue[-1] = 0, 0
while len(queue) != 0:
val = queue[0][0]
C = queue[0][1]
if val >= N and C == 0:
print(val)
break
queue.pop(0)
queue.append((val * 10 + 4, C + 1))
queue.append((val * 10 + 7, C - 1)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR LIST NUMBER ASSIGN VAR NUMBER NUMBER NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER |
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 | 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)[::-1]):
print(num(n)[::-1])
exit()
ans = int(s)
while True:
if lucky(ans):
print(ans)
break
ans += 1 | FUNC_DEF RETURN BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
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 | import sys
from itertools import permutations
input = lambda: sys.stdin.readline().strip("\r\n")
n = int(input())
l = len(str(n))
if l % 2:
print("4" * ((l + 1) // 2) + "7" * ((l + 1) // 2))
else:
flag = False
p = permutations(list("4" * (l // 2) + "7" * (l // 2)))
for i in p:
ans = int("".join(i))
if ans >= n:
print(ans)
break
else:
print("4" * (l // 2 + 1) + "7" * (l // 2 + 1)) | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER |
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 | n = input()
answer = ""
if len(n) % 2 == 0:
f = len(n) // 2
s = len(n) // 2
for x in n:
if x == "4":
if f > 0:
f -= 1
answer += "4"
else:
s -= 1
answer += "7"
break
elif x == "7" and s > 0:
s -= 1
answer += "7"
else:
if x in ("5", "6"):
if s > 0:
answer += "7"
s -= 1
elif f == len(n) // 2:
f = len(n) // 2 + 1
s = f
answer = ""
elif answer.rindex("4") != 0:
answer = answer[0 : answer.rindex("4")]
f += 1
s = len(n) - len(answer) - f
while s == 0 and f != len(n) // 2:
answer = (
answer[0 : answer.rindex("4")]
if answer.rindex("4") != 0
else ""
)
f += 1
s = len(n) - len(answer) - f
if s != 0:
answer += "7"
s -= 1
else:
f = len(n) // 2 + 1
s = f
answer = ""
else:
f += 1
s = len(n) // 2 - 1
answer = "7"
elif x in ("8", "9", "7"):
if f == len(n) // 2:
f = len(n) // 2 + 1
s = f
answer = ""
elif answer.rindex("4") != 0:
answer = answer[0 : answer.rindex("4")]
f += 1
s = len(n) - len(answer) - f
while s == 0 and f != len(n) // 2:
answer = (
answer[0 : answer.rindex("4")]
if answer.rindex("4") != 0
else ""
)
f += 1
s = len(n) - len(answer) - f
if s != 0:
answer += "7"
s -= 1
else:
f = len(n) // 2 + 1
s = f
answer = ""
else:
f += 1
s = len(n) // 2 - 1
answer = "7"
break
answer += "4" * f + "7" * s
else:
answer = "4" * ((len(n) + 1) // 2) + "7" * ((len(n) + 1) // 2)
print(answer) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR NUMBER VAR NUMBER VAR STRING VAR NUMBER VAR STRING IF VAR STRING VAR NUMBER VAR NUMBER VAR STRING IF VAR STRING STRING IF VAR NUMBER VAR STRING VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR STRING IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING NUMBER VAR NUMBER FUNC_CALL VAR STRING STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING IF VAR STRING STRING STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR STRING IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING NUMBER VAR NUMBER FUNC_CALL VAR STRING STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
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 | from itertools import permutations
number = input()
le = len(number)
l = le - int(le / 2)
n = int(number)
result = [x for x in "4" * l + "7" * l]
if le % 2 == 0:
f = sorted(list(int("".join(x)) for x in set(permutations(result))))
m = 0
for _ in f:
if _ >= n:
print(_)
m += 1
break
if m == 0:
print("4" * (l + 1) + "7" * (l + 1))
else:
print("4" * l + "7" * l) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR |
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 | n = input()
c4 = n.count("4")
c7 = n.count("7")
def check(n):
for i in n:
if i in "01235689":
return False
return True
while c4 != c7 or check(n) == False:
for i in range(len(n)):
if n[i] not in "47":
break
if int(n[i]) < 4:
n = (
int(n)
+ (4 - int(n[i])) * 10 ** (len(n) - i - 1)
- int(n) % 10 ** (len(n) - i - 1)
)
elif int(n[i]) < 7:
n = (
int(n)
+ (7 - int(n[i])) * 10 ** (len(n) - i - 1)
- int(n) % 10 ** (len(n) - i - 1)
)
else:
n = (
int(n)
+ (10 - int(n[i])) * 10 ** (len(n) - i - 1)
- int(n) % 10 ** (len(n) - i - 1)
)
n = str(n)
c4 = n.count("4")
c7 = n.count("7")
print(n) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF FOR VAR VAR IF VAR STRING RETURN NUMBER RETURN NUMBER WHILE VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
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 | lucky = []
def findLucky(s):
if len(s) > 11:
return
ans1 = s + "4"
ans2 = s + "7"
if ans1.count("4") == ans1.count("7"):
lucky.append(int(ans1))
if ans2.count("4") == ans2.count("7"):
lucky.append(int(ans2))
findLucky(s + "4")
findLucky(s + "7")
findLucky("")
lucky.sort()
n = int(input())
for i in lucky:
if i >= n:
print(i)
exit(0) | ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
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 | def dfs(fo, se, cur):
if len(cur) == l:
if int(cur) >= num:
mn[0] = min(mn[0], int(cur))
return
if fo:
dfs(fo - 1, se, cur + "4")
if se:
dfs(fo, se - 1, cur + "7")
return
num = input()
l = len(num)
if l & 1:
print("4" * ((l + 1) // 2) + "7" * ((l + 1) // 2))
else:
num = int(num)
mn = [99999999999]
dfs(l // 2, l // 2, "")
if mn[0] == 99999999999:
l += 2
dfs(l // 2, l // 2, "")
print(mn[0]) | FUNC_DEF IF FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR RETURN IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR STRING IF VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER |
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 | from itertools import permutations
def check(n, giv):
if n % 2 == 0:
f = []
for i in range(n):
if i % 2 == 0:
f.append(4)
else:
f.append(7)
f = list(permutations(f))
ans = []
for i in f:
ans1 = ""
if i[0] == 0:
continue
for j in i:
ans1 += str(j)
ans.append(int(ans1))
mini, number = float("inf"), 0
for i in ans:
if i > giv and i - giv < mini:
mini = i - giv
number = i
return number
def l():
return list(map(int, input().rstrip().split()))
def ini():
return int(input())
def te():
return list(map(int, input().split()))
def st():
return input().rstrip()
giv = int(input())
n = len(str(giv))
if giv == 10**9:
ans = ""
for i in range(len(str(giv))):
if i < n // 2:
ans += "4"
else:
ans += "7"
print(ans)
exit()
s = str(giv)
y = s
if y.count("7") == y.count("4") and y.count("7") + y.count("4") == len(y):
print(y)
else:
n = len(s)
if n % 2 == 0:
if s[0] < "7":
print(check(n, giv))
exit()
y = check(n, giv)
if y != 0:
print(y)
else:
ans = ""
for i in range(n + 2):
if i <= n // 2:
ans += "4"
else:
ans += "7"
print(ans)
else:
ans = ""
for i in range(n + 1):
if i <= n // 2:
ans += "4"
else:
ans += "7"
print(ans) | FUNC_DEF IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR STRING IF VAR NUMBER NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR |
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 | from itertools import permutations
ans = []
for i in range(2, 10, 2):
temp = [4, 7] * (i // 2)
x = list(permutations(temp))
for j in x:
t = ""
for k in j:
t += str(k)
ans.append(int(t))
ans.append(4444477777)
ans.sort()
n = int(input())
for i in ans:
if i >= n:
print(i)
break | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR |
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 | blanck = set()
def generator(n, seven, four):
if n > 10**12:
return blanck
if seven == four:
blanck.add(n)
generator(n * 10 + 4, seven, four + 1)
generator(n * 10 + 7, seven + 1, four)
generator(0, 0, 0)
a = sorted(list(blanck))
a.append(4444477777)
x = int(input())
for i in a:
if i >= x:
print(i)
break | ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR BIN_OP NUMBER NUMBER RETURN VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR |
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 | n = int(input())
v = []
def solve(cur, four, seven):
if cur > 20000000000.0:
return
if four == seven:
v.append(cur)
solve(cur * 10 + 4, four + 1, seven)
solve(cur * 10 + 7, four, seven + 1)
solve(0, 0, 0)
ans = 20000000000.0
for i in v:
if i >= n:
ans = min(ans, i)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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 | l = []
limit = 10000000000
def gen(number, four, seven):
if number > limit:
return
if number > 0 and four == seven:
l.append(number)
gen(number * 10 + 4, four + 1, seven)
gen(number * 10 + 7, four, seven + 1)
def main():
gen(0, 0, 0)
l.sort()
n = int(input())
ans = 0
for val in l:
if val >= n:
ans = val
break
print(ans)
main() | ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR RETURN IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
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 | d = input()
def correct(f):
c = 0
for i in f:
if int(i):
c -= 1
else:
c += 1
if c == 0:
return True
return False
if len(d) % 2:
k = (len(d) + 1) // 2
print("4" * k + "7" * k)
else:
k = len(d) // 2
if int(d) > int(k * "7" + k * "4"):
minn = "4" * (k + 1) + "7" * (k + 1)
else:
minn = 10**11
n = len(d)
for i in range(1, 2**n - 2 ** (n // 2) + 1):
bi = bin(i)[2:]
st = (n - len(bi)) * "0" + bi
d_1 = ""
d_2 = ""
if correct(st):
for j in st:
if j == "0":
d_1 += "4"
d_2 += "7"
else:
d_1 += "7"
d_2 += "4"
if int(d_1) >= int(d) and int(d_1) < minn:
minn = int(d_1)
if int(d_2) >= int(d) and int(d_2) < minn:
minn = int(d_2)
print(minn) | ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING BIN_OP VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING VAR ASSIGN VAR STRING ASSIGN VAR STRING IF FUNC_CALL VAR VAR FOR VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
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 | def check(num):
num = list(str(num))
if sorted(set(num)) != ["4", "7"]:
return False
if num.count("4") == num.count("7"):
return True
return False
num = int(input())
no = [0]
while 1:
if check(no[0]) and no[0] >= num:
print(no[0])
break
if no[0] < 10000000000.0:
no.append(no[0] * 10 + 4)
no.append(no[0] * 10 + 7)
del no[0] | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR LIST STRING STRING RETURN NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER |
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 | def gray(n):
if n == 1:
return [4, 7]
l1 = gray(n - 1)
l2 = reversed(l1)
l1 = [int(str(a) + "4") for a in l1]
l2 = [int(str(a) + "7") for a in l2]
return l1 + l2
n = int(input())
z = len(str(n))
l = gray(z) + gray(z + 1) + gray(z + 2)
l.sort()
l = [a for a in l if str(a).count("4") == str(a).count("7")]
for i in range(len(l)):
if l[i] >= n:
print(l[i])
break | FUNC_DEF IF VAR NUMBER RETURN LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
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 | n = input()
x = len(n)
if x % 2 == 0:
a = ["4"] * (x // 2) + ["7"] * (x // 2)
z = ""
if int(n) <= int("7" * (x // 2) + "4" * (x // 2)):
for i in range(x):
if int(n[i]) <= 4:
if "4" in a:
z += "4"
a.pop(a.index("4"))
if int(z + str("".join(a))) > int(n):
z = z + str("".join(a))
break
else:
z += str("".join(a))
break
elif int(n[i]) <= 7:
if "7" in a:
z += "7"
a.pop(a.index("7"))
else:
z += str("".join(a))
break
else:
if z[-1] == "4":
a = ["4"] + a
z = z[: len(z) - 1] + "7"
a.pop(a.index("7"))
if "4" in a:
z += "4"
a.pop(a.index("4"))
else:
z += "7"
break
else:
z = "4" * ((x + 2) // 2) + "7" * ((x + 2) // 2)
if int(z) >= int(n):
print(z)
else:
a = ["4"] * (x // 2) + ["7"] * (x // 2)
z = ""
for i in range(x - 1):
if n[i] != n[i + 1]:
z += "7"
a.pop(a.index("7"))
if int(z + "".join(a)) > int(n):
print(z + "".join(a))
break
else:
z += "4"
a.pop(a.index("4"))
else:
print("4" * ((x + 1) // 2) + "7" * ((x + 1) // 2)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP LIST STRING BIN_OP VAR NUMBER BIN_OP LIST STRING BIN_OP VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER IF STRING VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR VAR NUMBER IF STRING VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING IF STRING VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST STRING BIN_OP VAR NUMBER BIN_OP LIST STRING BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP VAR FUNC_CALL STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL STRING VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER |
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 | from itertools import permutations
strs = input()
n = len(strs)
def magic(numList):
s = "".join(map(str, numList))
return int(s)
if n & 1:
nn = n + 1
half = nn // 2
ans = "4" * half + "7" * half
print(ans)
else:
arr = []
for i in strs:
arr.append(int(i))
num = int(strs)
hhalf = n // 2
upperlimitstr = "7" * hhalf + "4" * hhalf
upperlimit = int(upperlimitstr)
lowerlimitstr = "4" * hhalf + "7" * hhalf
lowerlimit = int(lowerlimitstr)
if num == upperlimit or num == lowerlimit:
print(strs)
elif num > upperlimit:
nn = n + 2
half = nn // 2
ans = "4" * half + "7" * half
print(ans)
elif num < lowerlimit:
print(lowerlimit)
else:
half = n // 2
temparr = []
for i in range(half):
temparr.append(4)
for i in range(half):
temparr.append(7)
permutes = permutations(temparr)
maxdiff = num
bestans = num
for l in permutes:
curans = magic(l)
if curans < num:
continue
diff = curans - num
if diff < maxdiff:
bestans = curans
maxdiff = diff
print(bestans) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
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 | slucky = [4, 7]
i = 0
while slucky[-1] < 10**9:
slucky.append(slucky[i] * 10 + 4)
slucky.append(slucky[i] * 10 + 7)
i += 1
def superlucky(n):
four = 0
seven = 0
while n > 0:
if n % 10 == 4:
four += 1
else:
seven += 1
n = n // 10
if four == seven:
return True
return False
lucky = []
for item in slucky:
if superlucky(item):
lucky.append(item)
lucky = [0] + lucky + [4444477777]
def binarySearch(n):
left = 0
right = len(lucky) - 1
mid = (left + right) // 2
while left <= right:
mid = (left + right) // 2
if lucky[mid - 1] < n <= lucky[mid]:
print(lucky[mid])
break
elif n > lucky[mid]:
left = mid + 1
else:
right = mid - 1
n = int(input())
binarySearch(n) | ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
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 | lucky = []
def func(number, fours, sevens):
if number > 10000000000.0:
return
elif fours == sevens:
lucky.append(number)
func(10 * number + 7, fours, sevens + 1)
func(10 * number + 4, fours + 1, sevens)
func(4, 1, 0)
func(7, 0, 1)
n = int(input())
lucky.sort()
for x in lucky:
if x >= n:
print(x)
break | ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR |
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 | n = int(input())
possible = [0]
i = 0
while True:
k = possible[i]
if k >= n and str(k).count("4") == str(k).count("7"):
print(k)
exit(0)
possible += [10 * k + 4, 10 * k + 7]
i += 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR VAR VAR IF VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR LIST BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER |
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 | import sys
from itertools import permutations
n = input()
x = len(n)
if len(n) % 2 == 0:
s = "4" * (x // 2) + "7" * (x // 2)
else:
s = "4" * (x // 2 + 1) + "7" * (x // 2 + 1)
if len(n) % 2 != 0:
sys.stdout.write(s + "\n")
else:
l1 = []
for l in permutations(s, len(s)):
a = int("".join(l))
if a >= int(n):
sys.stdout.write(str(a) + "\n")
sys.exit()
sys.stdout.write("4" * (len(s) // 2 + 1) + "7" * (len(s) // 2 + 1)) | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER |
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 | from itertools import permutations
n = int(input())
def next_value(x):
arr = ["4"] * x + ["7"] * x
for a in permutations(arr):
y = int("".join(a))
if y >= n:
return y
return -1
for i in range(1, 6):
sol = next_value(i)
if sol != -1:
print(sol)
break | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP LIST STRING VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR VAR RETURN VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR |
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 | ans = 100000000000.0
def lucky(a, x):
global ans
if a < ans:
if a >= n and x == 0:
ans = a
return
else:
lucky(a * 10 + 4, x + 1)
lucky(a * 10 + 7, x - 1)
n = int(input())
lucky(0, 0)
print(ans) | ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
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 | import itertools
n = int(input())
def very_happy(num):
banned = "01235689"
for c in banned:
if c in str(num):
return False
if not str(num).count("4") == str(num).count("7"):
return False
else:
return True
if very_happy(n):
print(n)
else:
candidats2 = []
for add in range(3):
candidats = list(itertools.product(["4", "7"], repeat=len(str(n)) + add))
candidats2.append(
sorted([int("".join(list(can))) for can in candidats if very_happy(can)])
)
candidats2 = [item for sublist in candidats2 for item in sublist]
for x in candidats2:
if x > n:
print(x)
break | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR STRING FOR VAR VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR LIST STRING STRING BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR |
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 | from itertools import product
n = int(input())
ans = 0
if len(str(n)) % 2 == 0:
for roll in product([4, 7], repeat=len(str(n))):
temp = [str(i) for i in roll]
if n <= int("".join(temp)) and temp.count("4") == temp.count("7"):
ans = int("".join(temp))
break
else:
for roll in product([4, 7], repeat=len(str(n)) + 1):
temp = [str(i) for i in roll]
if n <= int("".join(temp)) and temp.count("4") == temp.count("7"):
ans = int("".join(temp))
break
if ans == 0:
for roll in product([4, 7], repeat=len(str(n)) + 2):
temp = [str(i) for i in roll]
if n <= int("".join(temp)) and temp.count("4") == temp.count("7"):
ans = int("".join(temp))
break
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR LIST NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR LIST NUMBER NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR LIST NUMBER NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR |
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 | from itertools import *
k = int(input())
n = len(str(k))
s = set()
if n % 2 != 0:
n = n + 1
c = ["4", "7"]
a = []
for i in range(n):
a.append(c)
for i in product(*a):
if i.count("7") == i.count("4"):
s.add(int("".join(i)))
ll = sorted(list(s))
if not k <= ll[-2] and k <= ll[-1]:
print(ll[-1])
elif k > ll[-1]:
n = n + 1
if n % 2 != 0:
n = n + 1
print("4" * (n // 2) + "7" * (n // 2))
elif k <= ll[-1]:
for i in ll:
if k <= i:
print(i)
break | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST STRING STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER IF VAR VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR |
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 | from itertools import permutations
n = input()
if len(n) % 2 == 0:
s = "4" * (len(n) // 2)
s += "7" * (len(n) // 2)
j = ""
for i in list(permutations(s)):
j = ""
for x in range(len(n)):
j += i[x]
if int(j) >= int(n):
print(j)
break
if int(j) < int(n):
s = "4" * (len(n) // 2 + 1)
s += "7" * (len(n) // 2 + 1)
print(s)
else:
s = "4" * (len(n) // 2 + 1)
s += "7" * (len(n) // 2 + 1)
print(s) | ASSIGN VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP STRING BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP STRING BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
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 | mx = 99999999999999999
def recur(val, c4, c7, n):
if c4 + c7 > 10:
return 2 * mx
if c4 == c7:
if val >= n:
return val
v4 = recur(val * 10 + 4, c4 + 1, c7, n)
v7 = recur(val * 10 + 7, c4, c7 + 1, n)
return min(v4, v7)
n = int(input())
print(recur(0, 0, 0, n)) | ASSIGN VAR NUMBER FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN BIN_OP NUMBER VAR IF VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR |
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 | 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)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER |
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 | def check(a):
four = 0
seven = 0
while a > 0:
if a % 10 == 4:
four += 1
elif a % 10 == 7:
seven += 1
else:
return False
a = a // 10
if four == seven:
return True
else:
return False
lucky = []
lucky.append(0)
lucky.append(4)
lucky.append(7)
i = 3
num = 0
while num <= 1000000000000:
if i % 2 == 1:
num = lucky[i // 2] * 10 + 4
lucky.append(num)
else:
num = lucky[i // 2 - 1] * 10 + 7
lucky.append(num)
i += 1
lucky = sorted(lucky)
n = int(input())
for i in range(len(lucky)):
if lucky[i] >= n and check(lucky[i]) == True:
print(lucky[i])
break | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
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 | import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def rinput():
return map(int, sys.stdin.readline().strip().split())
def get_list():
return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
n = iinput()
Q = [0]
i = 0
while True:
t = Q[i]
if t >= n:
if (
len(str(t)) % 2 == 0
and str(t).count("4") == str(t).count("7") == len(str(t)) // 2
):
print(t)
break
Q += [t * 10 + 4, t * 10 + 7]
i += 1 | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR VAR VAR IF VAR VAR IF BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR LIST BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER |
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 | from itertools import permutations as pmt
string = input()
l = len(string)
if l % 2 != 0:
print("4" * ((l + 1) // 2) + "7" * ((l + 1) // 2))
exit()
n = l // 2
worst = "7" * n + "4" * n
if worst < string:
print("4" * (n + 1) + "7" * (n + 1))
exit()
newstr = "4" * n + "7" * n
List = pmt(newstr)
for x in List:
result = "".join(x)
if result >= string:
print(result)
exit() | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
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 | def uniform(line):
if line.count("1") == line.count("0"):
pass
elif line.count("1") > line.count("0"):
need = line.count("1") * 2 - len(line)
add = "0" * need
line = add + line
elif line.count("1") < line.count("0"):
need = line.count("0") * 2 - len(line)
add = "1" * need
line = line + add
return line
res = []
for i in range(0, 1200):
grab = uniform(bin(i)[2:])
s = ""
if grab.count("1") == grab.count("0"):
for i in range(len(grab)):
if grab[i] == "0":
s += "4"
else:
s += "7"
res.append(s)
s = ""
res = sorted(res, key=lambda i: int(i))
n = int(input())
for i in range(len(res)):
if int(res[i]) >= n:
print(res[i])
break | FUNC_DEF IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
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 | n = int(input())
s = [0]
while True:
for i in s:
i = 10 * i
if i + 4 >= n and str(i + 4).count("4") == str(4 + i).count("7"):
print(i + 4)
exit()
elif i + 7 >= n and str(i + 7).count("4") == str(7 + i).count("7"):
print(i + 7)
exit()
else:
s.append(i + 4)
s.append(i + 7) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER WHILE NUMBER FOR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL FUNC_CALL VAR BIN_OP NUMBER VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL FUNC_CALL VAR BIN_OP NUMBER VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
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 | 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 | ASSIGN VAR LIST STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR LIST BIN_OP VAR VAR STRING BIN_OP VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING VAR LIST FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR LIST NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR |
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 | num = input()
def fun(temp, size4, size7):
if size4 == 0 and size7 == 0:
if int(temp) >= int(num):
return int(temp)
else:
return 999999999999999999999999
if size4 == 0:
for i in range(size7):
temp += "7"
if int(temp) >= int(num):
return int(temp)
else:
return 999999999999999999999999
if size7 == 0:
for i in range(size4):
temp += "4"
if int(temp) >= int(num):
return int(temp)
else:
return 999999999999999999999999
t1 = fun(temp + "4", size4 - 1, size7)
t2 = fun(temp + "7", size4, size7 - 1)
return t1 if t1 < t2 else t2
le = len(num) + (0 if len(num) % 2 == 0 else 1)
for i in range(le, 14, 2):
re = fun("", i // 2, i // 2)
if re != 999999999999999999999999:
print(re)
exit(0) | ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR STRING BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR STRING VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
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 | MAX = 10**10
def doit(cur, n4, n7):
if cur > MAX:
return
if n4 == n7:
a.append(cur)
doit(cur * 10 + 4, n4 + 1, n7)
doit(cur * 10 + 7, n4, n7 + 1)
a = []
doit(0, 0, 0)
a.sort()
n = int(input())
for v in a:
if v >= n:
print(v)
exit()
raise Exception | ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
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 | ans = 10000000000000
g = int(input())
s = int(0)
def vet(n, m):
global ans, s
if s < ans and s >= g and n == m:
ans = s
if n > 0:
s = s * 10 + 4
vet(n - 1, m)
s //= 10
if m > 0:
s = s * 10 + 7
vet(n, m - 1)
s //= 10
vet(5, 5)
print(ans) | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
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 | n = int(input())
ln = len(str(n))
lucky = [0]
if ln % 2 == 1:
cn = (ln + 1) // 2
res = cn * "4" + cn * "7"
else:
i = 0
while lucky[i] < 10**10:
lucky.append(lucky[i] * 10 + 4)
lucky.append(lucky[i] * 10 + 7)
i += 1
for j in range(len(lucky)):
if lucky[j] >= n and str(lucky[j]).count("4") == str(lucky[j]).count("7"):
res = lucky[j]
break
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING BIN_OP VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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 | import itertools as it
s = input()
n = len(s)
if n & 1 == 0:
fc = n // 2
sc = n // 2
else:
fc = n // 2 + 1
sc = n // 2 + 1
l = []
for i in range(fc):
l.append("4")
for i in range(sc):
l.append("7")
pp = list(it.permutations(l))
res = ""
flag = 0
for i in range(len(pp)):
st = "".join(pp[i])
if int(st) >= int(s):
res = int(st)
flag = 1
break
if flag == 0:
l.append("4")
l.append("7")
l.sort()
res = "".join(l)
print(res) | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR |
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 | def f(n, m):
k = 2 * m
for i in range(1 << k):
j = format(i, "b")
if j.count("1") == m:
j = j.replace("0", "4")
j = j.replace("1", "7")
j = "4" * (k - len(j)) + j
if int(j) >= n:
return j
t = input()
n, k = int(t), len(t)
m = (k + 1) // 2
print(f(n, m + int(n > int("7" * m + "4" * m)))) | FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR STRING IF FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR |
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 | n = input()
length = len(n)
if length % 2 == 1:
result = "4" * ((length + 1) // 2) + "7" * ((length + 1) // 2)
else:
half = length // 2
if n > half * "7" + half * "4":
result = (half + 1) * "4" + (half + 1) * "7"
elif n < half * "4" + half * "7":
result = half * "4" + half * "7"
else:
four_count = seven_count = half
for i in range(length):
digit = n[i]
if digit < "4":
result = n[:i] + "4" * four_count + "7" * seven_count
break
if digit < "7" and digit != "4":
if seven_count == 0:
result = n[:nearest_four] + "7" + "4" * (four_count + 1)
result += "7" * (length - len(result))
else:
result = n[:i] + "7" + "4" * four_count + "7" * (seven_count - 1)
break
if digit > "7":
result = n[:nearest_four] + "7" + "4" * (four_count + 1)
result += "7" * (length - len(result))
break
if digit == "4":
nearest_four = i
four_count -= 1
if four_count < 0:
result = n[:i] + "7" * seven_count
break
if digit == "7":
seven_count -= 1
if seven_count < 0:
result = n[:nearest_four] + "7" + "4" * (four_count + 1)
result += "7" * (length - len(result))
break
if four_count == 0 and seven_count == 0:
result = n
break
print(result) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR STRING BIN_OP VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER STRING BIN_OP BIN_OP VAR NUMBER STRING IF VAR BIN_OP BIN_OP VAR STRING BIN_OP VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR STRING BIN_OP VAR STRING ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP STRING VAR BIN_OP STRING VAR IF VAR STRING VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING BIN_OP STRING BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR STRING BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING BIN_OP STRING BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP STRING VAR IF VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING BIN_OP STRING BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
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 | a = []
def f(n, x):
if x <= 100000000000.0:
if x >= n and str(x).count("4") == str(x).count("7"):
a.append(x)
f(n, 10 * x + 4)
f(n, 10 * x + 7)
f(int(input()), 0)
a.sort()
print(a[0]) | ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER IF VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER |
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 | l = []
def rec(x):
if len(x) > 12:
return
if len(x) > 0 and x.count("4") == x.count("7"):
l.append(int(x))
rec(x + "4")
rec(x + "7")
rec("")
l = set(l)
l = sorted(list(l))
i = 0
N = int(input())
if N in l:
print(N)
else:
while l[i] < N:
i += 1
print(l[i]) | ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
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 | from itertools import permutations
numstr = input()
size = len(numstr) if len(numstr) % 2 == 0 else len(numstr) + 1
halfsize = size // 2
if len(numstr) <= 8:
premuts = [int("".join(p)) for p in permutations(["4", "7"] * halfsize)]
premuts.append(int("4" * (halfsize + 1) + "7" * (halfsize + 1)))
premuts.sort()
else:
premuts = [int("4" * halfsize + "7" * halfsize)]
num = int(numstr)
for elem in premuts:
if num <= elem:
print(elem)
break | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR BIN_OP LIST STRING STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR |
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 | z = []
for i in range(1, 11):
for j in range(1 << i):
s = bin(j)
s = s[2:]
if s.count("1") == s.count("0"):
z += [int(s.replace("1", "4").replace("0", "7"))] + [
int(s.replace("1", "7").replace("0", "4"))
]
z.sort()
a = int(input())
for i in z:
if a <= i:
print(i)
break | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING VAR BIN_OP LIST FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING STRING STRING STRING LIST FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING STRING STRING STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR |
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 | def run(n):
l = len(n)
if l % 2 == 1:
result = "4" * (l // 2 + 1) + "7" * (l // 2 + 1)
print(result)
return result
if n > "7" * (l // 2) + "4" * (l // 2):
result = "4" * (l // 2 + 1) + "7" * (l // 2 + 1)
print(result)
return result
def set_range(p, start, end, num):
for i in range(start, end):
p[i] = num
result = [None] * l
for i in range(l):
d = int(n[i])
if d < 4:
set_range(result, i, l, "4")
break
elif d == 4:
result[i] = "4"
elif d < 7:
result[i] = "7"
set_range(result, i + 1, l, "4")
break
elif d == 7:
result[i] = "7"
else:
k = i - 1
while result[k] == "7":
k -= 1
result[k] = "7"
set_range(result, k + 1, l, "4")
break
diff = (result.count("7") - result.count("4")) // 2
if diff > 0:
count = 0
last_4 = -1
for k in range(l):
if result[k] == "7":
count += 1
if result[k] == "4":
last_4 = k
if count == l // 2:
result[last_4] = "7"
u = l // 2 - result[:last_4].count("4")
set_range(result, last_4 + 1, last_4 + u + 1, "4")
set_range(result, last_4 + u + 1, l, "7")
break
elif diff < 0:
k = l - 1
while diff != 0:
if result[k] == "4":
result[k] = "7"
diff += 1
k -= 1
s = "".join(result)
print(s)
return s
n = input()
run(n) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR IF VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR STRING IF VAR NUMBER ASSIGN VAR VAR STRING IF VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR STRING IF VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
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 | import sys
n = input()
A = [4, 7]
C = [0, 0]
m = 0
def permutation(c, result):
if len(result) == m:
t = int("".join(map(str, result)))
if t >= n:
print(t)
sys.exit()
else:
for i in range(2):
if c[i] > 0:
result.append(A[i])
c[i] -= 1
permutation(c, result)
result.pop()
c[i] += 1
if len(n) % 2 != 0:
t = len(n) // 2 + 1
print("4" * t + "7" * t)
else:
m = len(n)
n = int(n)
C[0] = C[1] = m // 2
permutation(C, [])
print("4" * (C[0] + 1) + "7" * (C[1] + 1)) | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR LIST EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP VAR NUMBER NUMBER |
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 | all = []
def solve(n, four, seven):
if four is seven and four != 0:
all.append(n)
if n >= 10000000000.0:
return True
solve(n * 10 + 4, four + 1, seven)
solve(n * 10 + 7, four, seven + 1)
return True
n = int(input())
solve(0, 0, 0)
all.sort()
for x in all:
if x >= n:
print(x, end="")
break | ASSIGN VAR LIST FUNC_DEF IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR STRING |
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 | from itertools import permutations
n = input()
l = len(n)
r = "4" * (l // 2)
r += "7" * (l // 2)
if l % 2 == 1:
r = "4" + r + "7"
else:
for i in permutations(r):
i = "".join(i)
if n <= i:
r = i
break
if r < n:
r = "4" + r + "7"
print(r) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR VAR |
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 | gh = set()
def rep(n, four, seven):
global gh
if n > 10000000000:
return
if four == seven:
gh |= {n}
rep(n * 10 + 4, four + 1, seven)
rep(n * 10 + 7, four, seven + 1)
rep(0, 0, 0)
gh = sorted(gh)
def bin_s(a):
lo = 0
hi = len(gh)
ans = 0
while lo <= hi:
mid = (lo + hi) // 2
if gh[mid] >= a:
ans = gh[mid]
hi = mid - 1
else:
lo = mid + 1
return ans
print(bin_s(int(input()))) | ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
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 | 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) | ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER VAR NUMBER IF FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
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 | n = input()
k = len(n) / 2
k1 = k
r1 = -1
r2 = -1
s1 = ""
p = False
g = -1
s = ""
def anis():
if g == -1:
print("4" * int((len(n) + 2) / 2) + "7" * int((len(n) + 2) / 2))
else:
print(s1 + "4" * int(r) + "7" * int(r1))
exit()
i = -1
if len(n) % 2 != 0:
anis()
while True:
i += 1
if i == len(n):
break
if int(n[i]) < 4:
if k > 0:
s += "4"
k -= 1
else:
s += "7"
k1 -= 1
break
if int(n[i]) == 4:
if k > 0:
if k1 > 0:
s1 = s + "7"
r = k
r1 = k1 - 1
g = i
s += "4"
k -= 1
else:
k1 -= 1
s += "7"
break
continue
if int(n[i]) < 7:
if k1 > 0:
k1 -= 1
s += "7"
break
else:
anis()
continue
if int(n[i]) == 7:
if k1 > 0:
k1 -= 1
s += "7"
else:
anis()
continue
if int(n[i]) > 7:
anis()
print(s + "4" * int(k) + "7" * int(k1)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP STRING FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP STRING FUNC_CALL VAR VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR WHILE NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR STRING VAR NUMBER VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR STRING IF FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP STRING FUNC_CALL VAR VAR BIN_OP STRING FUNC_CALL VAR VAR |
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 | import sys
line = sys.stdin.readline().strip()
def run(i, nFour, nSeven, s, added):
n = len(line)
if i == n:
print(s)
return True
v = ord(line[i]) - ord("0")
if (added or v <= 4) and nFour > 0:
if run(i + 1, nFour - 1, nSeven, s + "4", added or v < 4):
return True
if (added or v <= 7) and nSeven > 0:
if run(i + 1, nFour, nSeven - 1, s + "7", added or v < 7):
return True
return False
while True:
n = len(line)
if n % 2 == 1:
line = "1" + line
n = n + 1
v = ord(line[0]) - ord("0")
if v <= 4:
if run(1, n / 2 - 1, n / 2, "4", v < 4):
break
if v <= 7:
if run(1, n / 2, n / 2 - 1, "7", v < 7):
break
line = "1" + line | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR STRING VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR STRING VAR VAR NUMBER RETURN NUMBER RETURN NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING IF VAR NUMBER IF FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER STRING VAR NUMBER ASSIGN VAR BIN_OP STRING VAR |
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 | x = input()
sz = (len(x) + 1) // 2
if len(x) % 2 == 1:
print("4" * sz + "7" * sz)
elif int(x) > int("7" * sz + "4" * sz):
print("4" * (sz + 1) + "7" * (sz + 1))
else:
ans = ""
left_4, left_7 = sz, sz
for i in range(len(x)):
if int(x) > int(ans + "4" + "7" * left_7 + "4" * (left_4 - 1)) or left_4 == 0:
ans += "7"
left_7 -= 1
else:
ans += "4"
left_4 -= 1
print(ans) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR STRING BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR NUMBER VAR NUMBER VAR STRING VAR NUMBER VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR |
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 | def luckynumwithequalnumberoffourandseven(x, n, a):
if x >= n and str(x).count("4") == str(x).count("7"):
a.append(x)
elif x < 1000000000000.0:
luckynumwithequalnumberoffourandseven(x * 10 + 4, n, a)
luckynumwithequalnumberoffourandseven(x * 10 + 7, n, a)
return a
def main():
n = int(input())
s = []
luckynumwithequalnumberoffourandseven(0, n, s)
s = sorted(s)
print(s[0])
main() | FUNC_DEF IF VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR |
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 | n = int(input())
t = 0
b = ["00", "01", "10", "11"]
a = ["00", "01", "10", "11"]
while t <= 7:
c = []
for i in a:
b.append("0" + i)
c.append("0" + i)
for i in a:
b.append("1" + i)
c.append("1" + i)
a = c
t += 1
k = []
for i in b:
if i.count("0") == i.count("1"):
p = ""
for j in i:
if j == "0":
p += "4"
else:
p += "7"
k.append(int(p))
for i in k:
if i >= n:
print(i)
break | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING WHILE VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR |
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 | import sys
def lucky(val, c4, c7, cnt):
if max(c4, c7) > int(cnt / 2):
return
if c4 + c7 == cnt:
if val >= n:
print(val)
sys.exit()
lucky(val * 10 + 4, c4 + 1, c7, cnt)
lucky(val * 10 + 7, c4, c7 + 1, cnt)
n = int(input())
i = 2
while True:
lucky(0, 0, 0, i)
i += 2 | IMPORT FUNC_DEF IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN IF BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR VAR NUMBER |
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 | number = list(input())
new_number = []
if len(number) % 2 == 0:
already_bigger = False
for digit in number:
digit = int(digit)
if already_bigger:
new_number += [4]
elif digit == 4 or digit == 7:
new_number += [digit]
else:
already_bigger = True
if digit < 4:
new_number += [4]
elif digit < 7:
new_number += [7]
else:
if 4 in new_number:
new_number.reverse()
first_4 = new_number.index(4)
new_number = (
[4] * (len(new_number) - len(new_number[first_4 + 1 :]))
+ [7]
+ new_number[first_4 + 1 :]
)
new_number.reverse()
else:
new_number = [4] * (len(number) + 2)
break
else:
new_number = [4] * (len(number) + 1)
of_4, of_7 = new_number.count(4), new_number.count(7)
if of_4 > of_7:
new_number.reverse()
missing = (of_4 - of_7) // 2
i = 0
while i < len(new_number) and missing != 0:
if new_number[i] == 4:
new_number[i] = 7
missing -= 1
i += 1
new_number.reverse()
elif of_7 > of_4:
missing = (of_7 - of_4) // 2 + 1
if 4 in new_number and new_number.index(4) < len(new_number) // 2:
new_number.reverse()
i = 0
amount_of_7 = 0
while amount_of_7 < missing:
if new_number[i] == 7:
amount_of_7 += 1
i += 1
while new_number[i] != 4:
i += 1
new_number[i] = 7
i -= 1
while missing != 0:
if new_number[i] == 7:
missing -= 1
new_number[i] = 4
i -= 1
else:
new_number = [7] * (len(new_number) // 2 + 1) + [4] * (len(new_number) // 2 + 1)
new_number.reverse()
print("".join(map(str, new_number))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR LIST NUMBER IF VAR NUMBER VAR NUMBER VAR LIST VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR LIST NUMBER IF VAR NUMBER VAR LIST NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER LIST NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP LIST NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
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 | from itertools import permutations as perm
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
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 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR |
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 | store = []
def getAns(n, a, b, s):
if n == 0:
store.append(int(s))
return
if a > 0 and b > 0:
getAns(n - 1, a - 1, b, s + "4")
getAns(n - 1, a, b - 1, s + "7")
elif a == 0:
getAns(n - 1, a, b - 1, s + "7")
else:
getAns(n - 1, a - 1, b, s + "4")
N = int(input())
for i in range(2, 14 + 1, 2):
getAns(i, i // 2, i // 2, "")
for i in store:
if i >= N:
print(i)
break | ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR |
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 | def check(x):
a = b = 0
for i in str(x):
if i == "4":
a += 1
elif i == "7":
b += 1
return a == b
n = int(input())
q = [0]
while True:
if check(q[0]) and q[0] >= n:
print(q[0])
break
q.append(q[0] * 10 + 4)
q.append(q[0] * 10 + 7)
q.pop(0) | FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER |
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 | from itertools import permutations
n = input()
nl = len(n)
if len(n) % 2 == 1:
print("4" * (nl // 2 + 1) + "7" * (nl // 2 + 1))
else:
psa = permutations(list("4" * (nl // 2) + "7" * (nl // 2)), nl)
for i in psa:
if int("".join(i)) >= int(n):
print(int("".join(i)))
break
else:
print("4" * (nl // 2 + 1) + "7" * (nl // 2 + 1)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER VAR FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER |
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 | def gen(k, number, bal):
if k == 11:
return
if bal == 0:
numbers.append(number)
gen(k + 1, number * 10 + 4, bal + 1)
gen(k + 1, number * 10 + 7, bal - 1)
n = int(input())
numbers = []
gen(0, 0, 0)
numbers.sort()
i = 0
while n > numbers[i]:
i += 1
print(numbers[i]) | FUNC_DEF IF VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
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 | from itertools import permutations
def solve(x):
for d in range(1, 6):
for p in permutations([4] * d + [7] * d):
y = 0
for e in p:
y = 10 * y + e
if y >= x:
return y
print(solve(int(input()))) | FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
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 | from itertools import permutations
n = int(input())
k = len(str(n))
if k % 2 != 0:
print("4" * ((k + 1) // 2) + "7" * ((k + 1) // 2))
else:
flag = 0
z = list("4" * (k // 2) + "7" * (k // 2))
m = permutations(z)
ans = []
for i in m:
u = int("".join(i))
if u >= n:
print(u)
flag = 1
break
if flag == 0:
print("4" * ((k + 2) // 2) + "7" * ((k + 2) // 2)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER |
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 | def foo():
l = [4, 7]
while len(str(l[-1])) <= 12:
z = []
for i in range(0, len(l)):
for j in range(0, len(l)):
s = str(l[i]) + str(l[j])
if len(s) >= 12:
l = l + z
return l
z.append(int(s))
l = l + z
a = foo()
a = list(set(a))
a.sort()
n = int(input())
for i in range(0, len(a)):
if a[i] == n:
s = str(a[i])
if s.count("4") == s.count("7"):
print(n)
break
elif a[i] > n:
s = str(a[i])
if s.count("4") == s.count("7"):
print(a[i])
break | FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER WHILE FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR |
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 | def main():
mode = "filee"
if mode == "file":
f = open("test.txt", "r")
get = lambda: [
int(x) for x in (f.readline() if mode == "file" else input()).split()
]
[n] = get()
h = ["4", "7"]
while int("".join(h)) < n:
g = list(h)
g.sort()
g.reverse()
if g == h:
h.append("4")
h.append("7")
h = sorted(h)
continue
flag = 0
for i in range(len(h) - 1, -1, -1):
if flag == 1 and h[i] == "4":
h[i], h[i + 1] = h[i + 1], h[i]
h = h[: i + 2] + sorted(h[i + 2 :])
break
if h[i] == "7":
flag = 1
print("".join(h))
if mode == "file":
f.close()
main() | FUNC_DEF ASSIGN VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN LIST VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING WHILE FUNC_CALL VAR FUNC_CALL STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
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 | Min = int(10**10)
n = input()
def next(x, a, f, s):
global Min
global n
if len(x) > 0:
if a == "" or int(a) >= int(n[0 : len(a)]):
if f + 1 <= len(n) / 2:
next(x[1:], a + "4", f + 1, s)
if s + 1 <= len(n) / 2:
next(x[1:], a + "7", f, s + 1)
elif a == "" or int(a) >= int(n[0 : len(a)]):
if int(a) < Min:
Min = int(a)
if len(n) % 2 == 1:
n = "1" + n
elif int(n) > int("7" * int(len(n) / 2) + "4" * int(len(n) / 2)):
n = "11" + n
next(n, "", 0, 0)
print(Min) | ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF VAR STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR STRING BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR STRING VAR BIN_OP VAR NUMBER IF VAR STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP STRING VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP STRING FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR STRING NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
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 | import itertools
num = input()
n = len(num)
if n % 2 == 1:
n += 1
print("4" * (n // 2) + "7" * (n // 2))
exit()
if int("7" * (n // 2) + "4" * (n // 2)) < int(num):
n += 2
print("4" * (n // 2) + "7" * (n // 2))
exit()
if int(num[0]) < 4:
print("4" * (n // 2) + "7" * (n // 2))
exit()
num = int(num)
a = ""
for i in range(n // 2):
a += "4"
a += "7"
mina = 100000000000
for i in itertools.permutations(a, n):
st = "".join(i)
if int(st) >= num:
if int(st) < mina:
mina = int(st)
print(mina) | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
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 | from itertools import permutations
s = input()
n = len(s)
if n & 1:
k = (n + 1) // 2
print("4" * k + "7" * k)
elif int(s) >= 99999999:
print("4444477777")
else:
k = n // 2
z = "4" * k + "7" * k
p = "4" * (k + 1) + "7" * (k + 1)
l = list(permutations(z))
l = ["".join(x) for x in l]
l.sort()
for e in l:
if e >= s:
print(e)
exit(0)
print(p) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR |
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 | sa = int(input())
suplucky = [
47,
74,
4477,
4747,
4774,
7447,
7474,
7744,
747447,
744747,
744774,
477744,
444777,
777444,
447477,
747474,
774744,
474774,
474477,
447747,
774474,
447774,
744477,
774447,
747744,
477447,
477474,
474747,
]
supluckyb = [
44747747,
77774444,
74747744,
44477774,
47447774,
77744474,
77444477,
47744774,
74477474,
74744774,
44774477,
77444747,
74474747,
74447747,
74447774,
44747774,
74477447,
74474477,
47744747,
47474747,
77447474,
77444774,
77474744,
74447477,
77474447,
74747474,
74774744,
47744477,
74777444,
44447777,
47747474,
47774474,
47747447,
44774747,
47444777,
44474777,
77474474,
74477744,
47477744,
74474774,
74747447,
47447477,
47477447,
44477477,
77747444,
77744744,
44744777,
77477444,
74744477,
47474774,
74444777,
44747477,
44777744,
47774744,
44777447,
47477474,
47447747,
47777444,
74774447,
44477747,
77447447,
77744447,
74774474,
44774774,
74744747,
47774447,
47474477,
77447744,
44777474,
47747744,
]
superlucky = suplucky + supluckyb
superlucky.sort()
element = 0
sas = []
for element in superlucky:
if element >= sa:
sas.append(element)
if sas == []:
print(4444477777)
else:
print(min(sas)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
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 | def check(x):
if x < n:
return
y = x
a = 0
b = 0
while x:
if x % 10 - 4:
a += 1
if x % 10 - 4 == 0:
b += 1
x = x // 10
if a == b:
print(y)
exit()
n = int(input())
q = [0] * 1000000
front = 1
rear = 1
while front <= rear:
rear += 1
q[rear] = q[front] * 10 + 4
check(q[rear])
rear += 1
q[rear] = q[front] * 10 + 7
check(q[rear])
front += 1 | FUNC_DEF IF VAR VAR RETURN ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER |
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 | a = []
def lucky(n):
if n > 10**10:
return
else:
h = str(n)
if h.count("4") == h.count("7"):
a.append(n)
lucky(10 * n + 4)
lucky(n * 10 + 7)
lucky(0)
a.sort()
n = int(input())
l = 0
r = len(a) - 1
ans = 0
while l <= r:
m = l + (r - l) // 2
if a[m] >= n:
r = m - 1
ans = a[m]
else:
l = m + 1
print(ans) | ASSIGN VAR LIST FUNC_DEF IF VAR BIN_OP NUMBER NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
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 | n = int(input())
for i in range(1, 10 + 1):
for j in range(1 << i):
k = "".join([("7" if j & 1 << l else "4") for l in range(i)][::-1])
if k.count("4") == k.count("7") and int(k) >= n:
print(k)
exit() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL STRING BIN_OP VAR BIN_OP NUMBER VAR STRING STRING VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
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 | while True:
try:
def solution(n):
i = 0
lnum = list()
lnum = [0]
while True:
if lnum[i] >= n and str(lnum[i]).count("7") == str(lnum[i]).count("4"):
print(str(lnum[i]))
break
t = 10 * lnum[i] + 4
lnum.append(t)
t = 10 * lnum[i] + 7
lnum.append(t)
i += 1
if __name__ == "__main__":
n = int(input())
solution(n)
except EOFError:
break | WHILE NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER WHILE NUMBER IF VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.