description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def main(): a = list(input("")) b = input("") a.sort() a.reverse() maxNumber = "" if len(a) < len(str(b)): for num in a: maxNumber += num else: maxNumber = fillInDigit(a, b, [], "") print(maxNumber) def fillInDigit(num1, num2, usedDigits, currentMaxNumber): ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR LIST STRING EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VA...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() if len(a) < len(b): a = sorted(a)[::-1] print("".join(a)) exit(0) def check(res, j, a): added = False tmp = "" for i in a: if i == j and not added: added = True else: tmp += i tmp = res + j + tmp[::-1] return tmp <= b re...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VA...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def swap_n_sort(X, i, j): X = X[0:i] + X[j] + X[i + 1 : j] + X[i] + X[j + 1 :] X = X[: i + 1] + "".join(reversed(sorted(X[i + 1 :]))) return X X = "".join(reversed(sorted(input()))) Y = input() if len(X) < len(Y): print(X) else: eq = True i = 0 while i < len(X): if int("".join(X)) ...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIG...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input().strip() b = input().strip() if len(b) > len(a): print("".join(sorted(a))[::-1]) else: f = [0] * 11 for ele in a: f[int(ele)] += 1 ans = "" i = 0 n = len(b) while i < n: num = int(b[i]) if f[num]: ans += str(num) f[num] -= 1 ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE V...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def main(): a = list(input()) b = list(input()) n = len(a) if n < len(b): a.sort() a.reverse() print("".join(a)) return b_ = [int(_) for _ in b] a.sort() a.reverse() a_ = [int(_) for _ in a] c = [(0) for _ in range(n)] r = [] index = 0 flag...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CAL...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() acnt = [0] * 10 ans = [] for i in range(len(a)): acnt[int(a[i])] += 1 if len(a) < len(b): for i in range(9, -1, -1): while acnt[i] > 0: ans.append(i) acnt[i] -= 1 else: for i in range(len(a)): f = 1 for j in range(9, -1, -1): ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def solve(al, bl, lim): if lim: m = -1 sm = -1 bar = bl[0] for i in al: if i <= bar: if i > m: sm = m m = i elif i < m and i > sm: sm = i if m == -1: return [-1...
FUNC_DEF IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN LIST NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR RETURN LIST NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FU...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
class Solution: def canWork(self, pre, a, b): return int(pre + "".join(a)) <= b def step(self, pre, a, b): for i in range(len(a) - 1, -1, -1): pre2 = pre + a[i] a2 = a[:i] + a[i + 1 :] if self.canWork(pre2, a2, b): return pre2, a2 rai...
CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR FUNC_CALL STRING VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = sorted(input()) b = int(input()) a = a[::-1] prefix = "" while a: for i in range(len(a)): n = prefix + a[i] + "".join(sorted(a[:i] + a[i + 1 :])) if int(n) <= b: prefix += a[i] a.pop(i) break print(prefix)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR STRING WHILE VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def check(s, a): st = "" for i in range(len(s)): st += s[i] st = int(st) if st > a: return False else: return True a = input() b = input() s = [] ans = "" for i in range(len(a)): s.append(a[i]) s.sort() if len(b) > len(a): for i in range(len(s)): print(s[len...
FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() o = 0 t = [] i = 0 h = 0 c = 0 w = 0 j = 0 l = [int(d) for d in a] k = [int(i) for i in b] l.sort() l.reverse() if len(l) < len(k): print("".join(map(str, l))) if len(l) == len(k): for i in range(0, len(k)): o = k[i] if o in l: t.append(o) l.remove...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def main(a, b, w=False): if not b: return None if a else "" if len(a) < len(b): return "".join(sorted(a)[::-1]) if "".join(sorted(a)) > b: return if b[0] in a: i = a.index(b[0]) a[i], a[0] = a[0], a[i] m = main(a[1:], b[1:], True) if m is not None:...
FUNC_DEF NUMBER IF VAR RETURN VAR NONE STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL STRING FUNC_CALL VAR VAR NUMBER IF FUNC_CALL STRING FUNC_CALL VAR VAR VAR RETURN IF VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VA...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
s = input() a = [int(s[i]) for i in range(len(s))] s = input() b = [int(s[i]) for i in range(len(s))] if len(a) < len(b): a.sort() a = a[::-1] print(*a, sep="") else: kek = [0] * 10 kekos = [0] * 10 for i in range(len(a)): kek[a[i]] += 1 kekos[a[i]] += 1 ans = 0 g = [-1] ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP LIST...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
from sys import stdin, stdout a = int(stdin.readline()) b = int(stdin.readline()) ans = "" c = sorted(list(str(a))) while c: for i in range(len(c) - 1, -1, -1): if int("".join(list(ans) + [c[i]] + c[:i] + c[i + 1 :])) <= b: ans += c[i] c.pop(i) break stdout.write(str(int...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR LIST VAR VAR VAR...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() if len(a) < len(b): print("".join(sorted(a, reverse=True))) else: b = int(b) digits = sorted(a, reverse=True) curr = "" temp = "" while digits: for i in range(len(digits)): temp += digits[i] suffix = "".join(sorted(digits[:i] + digits[i + 1...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING WHILE VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def permute(a, b): d = {} if len(a) == len(b) and len(a) == 1: if int(a) <= int(b): return a else: return "-1" for alpha in a: try: d[alpha] += 1 except KeyError: d[alpha] = 1 if len(a) < len(b): strs = "" fo...
FUNC_DEF ASSIGN VAR DICT IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR RETURN STRING FOR VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def x(a, b): a.sort() l = len(a) if len(a) < len(b): return "".join(sorted(a, reverse=True)) elif l > len(b): return "0" + x(a[1:], b) else: f = True if l == 0: return "" for i in range(l): if a[i] > b[i]: f = False ...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL STRING FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN BIN_OP STRING FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER RETURN STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VA...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def check(ans, num, a, b, u): prob = ans a = [] for i in range(len(num)): a.append(num[i]) prob += num[u] a.pop(u) a.sort() for i in range(len(a)): prob += a[i] if int(prob) <= int(b): return True return False a = input() b = input() num = [] ans = "" if len...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def check(e, value, pre): global maxi, count e[str(value)] -= 1 pre += str(value) arr = [] for i in e: for j in range(e[i]): arr.append(i) arr.sort(reverse=True) st = "" for i in arr: st += str(i) alpha = int(pre + st) if alpha <= int(b): maxi ...
FUNC_DEF VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CA...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def comp(a, b): x = len(a) s1 = "" s2 = "" for i in range(x): s1 += str(a[i]) s2 += str(b[i]) if s1 > s2: return 1 else: return 0 a = list(input("")) b = list(input("")) cnt = [0] * 10 n = len(a) m = len(b) sol = "" for i in range(n): a[i] = int(a[i]) cn...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def solve(a, b): a = str(a) b = str(b) if len(a) < len(b): return greedy(a) else: return recur(a, b) def recur(a, b, flag=True): if b: this = b[0] if this in a and flag: r = recur(a.replace(this, "", 1), b[1:]) if r and r[-1] == "*": ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF NUMBER IF VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING NUMBER VAR NUMBER IF VAR VAR NUMBER STRING RETURN ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() digits = list(a) builder = "" if len(b) < len(a): b = b.rjust(len(a), "0") for digit in b: if len(b) > len(a): break if digit in digits: digits.remove(digit) if int(builder + digit + "".join(sorted(digits, key=int))) <= int(b): builder += digit ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a, b = sorted(input()), input() r, p = range(len(a)), lambda x: int("".join(x)) for i in r: for j in r[i:]: a[i], a[j], c = a[j], a[i], p(a) if not c <= p(a) <= p(b): a[i], a[j] = a[j], a[i] print(p(a))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() list_a = list(a) list_a.sort() max_a = int("".join(list_a)) for i in range(len(a)): for j in range(i + 1, len(a)): list_a[i], list_a[j] = list_a[j], list_a[i] temp_a = int("".join(list_a)) if int(b) < temp_a or temp_a <= max_a: list_a[i], list_a[j] = list_...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRI...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def main(): a = input() b = input() if len(a) < len(b): a = list(a) a.sort(reverse=True) print("".join(a)) return def solve(i, a: list): if i == len(b): return "" if a.__contains__(b[i]): a.remove(b[i]) suf = solve(i + ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FUNC_DEF VAR IF VAR FUNC_CALL VAR VAR RETURN STRING IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
from sys import maxsize a = input() b = input() if a == b: print(a) elif len(b) > len(a): print("".join(str(i) for i in sorted(a, reverse=True))) else: result = [] idx = 0 list_ = list(a) while idx < len(b) and b[idx] in list_: result.append(b[idx]) list_.remove(b[idx]) ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_C...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def search(current, digits, target, idx, bulk): if len(current) == len(target) and int(current) <= int(target): print(current) exit(0) possibilities = [ char for char in digits if bulk or char <= target[idx] and char in digits ] if len(possibilities) == 0: return None ...
FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR I...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
import sys a = list(input()) tmp = a b = int(input()) ans = [] a.sort() for i in range(len(tmp)): for j in range(len(tmp) - 1, -1, -1): s = ans[:i] + a[j : j + 1] + a[:j] + a[j + 1 :] if int("".join(s)) <= b and "".join(ans) <= "".join(s): ans = s a.remove(a[j]) ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
n, N = input(), input() N = [i for i in N] n = sorted((i for i in n), reverse=True) def has_hal(n, N): return sorted(n) <= N def solve(n, N): if len(n) < len(N): return "".join(n) if not n: return "" for pos, d in enumerate(n): if d > N[0]: continue if d =...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL STRING VAR IF VAR RETURN STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VA...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() reva = sorted(list(a), reverse=True) if len(a) < len(b): print("".join(reva)) else: a_hash = [0] * 10 a = int(a) while a > 0: a_hash[a % 10] += 1 a = a // 10 c = 0 ans = [] len_b = len(b) flag = 0 flag1 = 0 while c != len_b: temp = ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
global a_arr, b_arr, cnta, cntb, enumerate, numa, ans def toarra(x): global cnta i = 0 while x > 0: a_arr[i] = x % 10 numa[x % 10] += 1 x = x // 10 i += 1 cnta = i - 1 def toarrb(x): global cntb i = 0 while x > 0: b_arr[i] = x % 10 x = x //...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
s1 = input() s2 = input() arr = list(s1) arr.sort(reverse=True) if len(s2) > len(s1): t = "" for i in arr: t += i print(t) else: t = "" l = len(s1) for i in range(l): index = -1 ma = -1 for j in range(len(arr)): temp = arr[j] tt = [] ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VA...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = list(input()) b = input() out = [] mx = "/" a.sort() a.reverse() x = len(a) if x == len(b): for i in range(x): q = 0 for j in range(len(a)): if a[j] == b[i]: out.append(a[j]) a.pop(a.index(a[j])) q = 1 break ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = list(input()) b = list(input()) a = list(reversed(sorted(a))) if len(a) < len(b): print("".join(a)) exit() def rec(a, b, k): if k == len(a): return "" if b[k] in a: for i in range(len(a)): if a[i] == b[k]: a[i] = "" break tmp = re...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN STRING IF VAR VAR VAR FOR VAR FUNC_CALL VAR FU...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def f(b, l, i, ls, below=False): if i == len(b): return True ne = int(b[i]) if below: ne = 9 found = False for j in range(ne, -1, -1): if ls[j] > 0: l.append(j) ls[j] -= 1 val = f(b, l, i + 1, ls, True if below or j < ne else False) ...
FUNC_DEF NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMB...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def get(g): s = [str(i) for i in g] num = int("".join(s)) return num a = input() b = input() bb = int(b) mark = [(0) for i in range(len(a))] c = a f = [] g = [] for i in range(0, len(a)): g.append(a[i]) g.sort() g.reverse() num = get(g) index = [] if num <= bb: print(num) exit(0) for i in rang...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CAL...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def y(a, b): if len(a) < len(b): a.sort(reverse=1) return a c = b[0] if c in a: if len(b) == 1: return [c] a.remove(c) d = y(a[:], b[1:]) if d: return [c] + d a += c e = list(filter(lambda x: x < c, a)) if e: e =...
FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR ASSIGN VAR VAR NUMBER IF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN LIST VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR RETURN BIN_OP LIST VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def get_smallest(m, l): res = "" for i in "0123456789": if m.get(i, 0): if i == l: res += i * (m[i] - 1) else: res += i * m[i] return res a = input() b = input() if len(a) < len(b): a = sorted(a) a.reverse() print("".join(a)) elif...
FUNC_DEF ASSIGN VAR STRING FOR VAR STRING IF FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL ST...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def find(a, b, ans): if len(a) > 0: for i in range(len(a)): test = int(ans + a[i] + "".join(sorted(a[:i] + a[i + 1 :]))) if test <= b: return find(a[:i] + a[i + 1 :], b, ans + a[i]) else: return ans a = int(input().strip()) b = int(input().strip()) if a ...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def tryf(s, ii, u, dont, preff): usd = u.copy() for i in range(len(s), len(b)): for k in range(len(a)): if not usd[k]: if i == ii and a[k] == dont: continue if preff and a[k] < b[i]: preff = False s +...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR ASS...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def find(l, x): a = sorted([y for y in l if y <= x]) if len(a) > 0: return a[-1] return l[0] def find_less(l, x): a = sorted([y for y in l if y < x]) if len(a) > 0: return a[-1] return None def main(): a = input() b = input() if len(a) < len(b): print("".j...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER RETURN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER RETURN NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
import sys a = sys.stdin.readline().split()[0] b = sys.stdin.readline().split()[0] a = [int(x) for x in a] b = [int(x) for x in b] def mov(a, x1, x2): a.insert(x1, a.pop(x2)) return a def min(a): m = 9 for i in a: x = int(i) if x < m: m = x return m def max(a): ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a, b = input(), input() if len(a) < len(b): print("".join(sorted(a, reverse=True))) else: d = {} for c in a: d[c] = d.get(c, 0) + 1 ans = "" for i in range(len(a)): if ans and ans < b[:i]: ans += "".join( sorted("".join([(k * v) for k, v in d.items()]), re...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL STRI...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = int(input()) lnb = len(str(b)) l = len(a) if int(a) == b: print(a) exit(0) if lnb > l: print("".join(reversed(sorted(a)))) exit(0) dig = [0] * 10 for i in a: dig[int(i)] += 1 k = 0 s = "" while len(s) != l: while k < 100: for j in range(9, -1, -1): if not dig[...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIG...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() if sorted(list(a)) == sorted(list(b)): print(b) elif len(a) < len(b): print("".join(sorted(a)[::-1])) else: digits = {} for x in a: y = int(x) if y in digits: digits[y] += 1 else: digits[y] = 1 best = 0 for i in range(len(b)...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMB...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a, b = sorted(input()), int(input()) for i in range(len(a)): for j in range(i + 1, len(a)): c = int(str.join("", a)) a[i], a[j] = a[j], a[i] d = int(str.join("", a)) if c <= d <= b: continue else: a[i], a[j] = a[j], a[i] print(str.join("", a))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING VAR IF VAR VAR V...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def f(n): if n <= 1: return 1 else: return n * f(n - 1) def g(ls, i, s): if len(ls) == 1: return 10 * s + ls[0] else: k = f(len(ls) - 1) return g(ls[: i // k] + ls[i // k + 1 :], i % k, 10 * s + ls[i // k]) a = int(input()) b = int(input()) ls = list(sorted(ma...
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR B...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = int(input()) lst = sorted(a) c = 0 for i in range(len(lst)): for j in range(len(lst) - 1, i - 1, -1): x = lst[:i] + [lst[j]] + sorted(lst[i:j]) + lst[j + 1 :] if int("".join(x)) <= b and int("".join(x)) > c: c = int("".join(x)) lst = x print(int("".join(lst)))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR LIST VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
R = lambda: map(int, input().split()) a = sorted(map(int, input())) b = list(map(int, input())) bn = int("".join(map(str, b))) res = int("".join(map(str, sorted(a)))) if len(b) != len(a): print("".join(map(str, sorted(a, reverse=True)))) else: for i in range(len(a)): for j in range(i + 1, len(a)): ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CAL...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def possible(a, index, a1, b): rem = [] for i in range(len(a)): if i != index: rem.append(a[i]) a3 = a1[:] rem.sort() a3.append(a[index]) a3.extend(rem) a2 = "" for i in a3: a2 += str(i) if int(a2) <= b: return True return False def main(): ...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CAL...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = int(input()) b = int(input()) D = [0] * 10 while a: D[a % 10] += 1 a //= 10 cur = 0 def check(): global cur ans = cur for i in range(10): for _ in range(D[i]): ans = ans * 10 + i return b >= ans def dfs(): for i in range(10): if D[9 - i]: D[9 -...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER WHILE VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR VAR...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = list(input()) b = list(input()) num = int("".join(b)) a.sort() a.reverse() al = len(a) ans = [] if len(a) == len(b) and len(a) != 1: c = [] count = 0 hogya = 0 for i in range(al): if hogya == 1: o.reverse() f = list(c + o) ans.append("".join(f)) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMB...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
from sys import stdin, stdout a, b = list(stdin.readline().strip()), stdin.readline().strip() def can(x, y): return sorted(x) <= list(y) if len(a) < len(b): stdout.write("".join(sorted(a, key=lambda i: -ord(i))) + "\n") else: free = False a.sort(key=lambda i: -ord(i)) for i, c in enumerate(b): ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = list(map(int, list(input()))) b = list(map(int, list(input()))) ch = False p = [] a.sort() a = a[::-1] if len(b) > len(a): print("".join(map(str, a))) else: for i in range(len(b)): if b[i] in a: p.append(a.pop(a.index(b[i]))) else: for x in a: if x < b...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FOR VA...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
s = input() s1 = input() l = [] l1 = [] for x in s: l.append(int(x)) for x in s1: l1.append(int(x)) d = {} for x in l: d[x] = d.get(x, 0) + 1 f = False if len(s1) > len(s): l = sorted(l) l = l[::-1] print("".join(map(str, l))) exit() ans = [0] * len(s) ki = 0 i = 0 while i < len(l1): f =...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR A...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() if len(a) < len(b): print("".join(sorted(list(a), reverse=True))) else: lst = sorted(list(a), reverse=True) temp = "" prefix = "" while len(lst) > 0: for x in range(len(lst)): temp = prefix + lst[x] + "".join(sorted(lst[:x] + lst[x + 1 :])) if ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
success = 0 def solve(b, freq, i, n, res): global success if i == len(b): success = res else: success = 0 move = 9 while move >= 0 and success == 0: m = int(b[i]) if freq[move] > 0 and res * 10 + move <= n * 10 + m: res = res * 10 + m...
ASSIGN VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = list(input()) b = int(input()) a.sort() for i in range(len(a) - 1): for j in range(len(a) - 1, i - 1, -1): z = a[:i] + a[j : j + 1] + a[i:j] + a[j + 1 :] if int("".join(z)) <= b: a = z break for i in a: print(i, end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP V...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = sorted(input())[::-1] b = input() n = len(b) if len(a) < n: s = "".join(a) else: s = "" while a: i = 0 while s + a[i] + "".join((a[:i] + a[i + 1 :])[::-1]) > b: i += 1 s += a.pop(i) print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR STRING WHILE VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR VAR FUNC_CALL STRING BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR FUNC_...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() a = "".join(reversed(sorted(a))) if len(a) < len(b): print(a) else: ans = "" for i in range(len(b)): c = min(x for x in a) for x in a: if c < x <= b[i]: c = x if c > b[i]: j = i while c >= b[j]: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = [int(i) for i in list(input())] b = [int(i) for i in list(input())] if len(a) < len(b): a.sort(reverse=True) ans = 0 for i in range(len(a)): ans = ans * 10 + a[i] print(ans) else: ans = 0 n = len(a) count = [0] * 10 for i in range(n): count[a[i]] += 1 i = 0 wh...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN V...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = list(map(int, list(input()))) b = list(map(int, list(input()))) answer = [(0) for _ in range(len(b))] def solve(a, whatPos, flag): global b, answer pos = len(a) minNumber = 10 if pos != 0: for x in range(pos - 1, -1, -1): if (a[x] <= b[whatPos] or flag) and minNumber != a[x]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
import sys def main(): import sys input = sys.stdin.readline a = int(input()) b = int(input()) a = list(str(a)) a.sort() ans = [] while a: for i in range(len(a) - 1, -1, -1): c = ans + [a[i]] + a[:i] + a[i + 1 :] if int("".join(c)) <= b: ...
IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR LIST VAR VAR...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() a_cifr = [0] * 10 for i in a: a_cifr[int(i)] += 1 if len(b) > len(a): cur = list(a) cur.sort(reverse=True) for i in cur: print(i, end="") exit(0) def vniz(): cur = "" for i in range(0, 10): cur += str(i) * a_cifr[i] return cur abba = 123 def ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR STRING FOR...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def dfs(b, bid, a, used, ans, n_used): if n_used == len(a): if int(ans) <= int(b): return ans else: return None used_x = set() for i, x in enumerate(a): if not used[i] and int(ans + str(x)) <= int(b[: bid + 1]) and x not in used_x: used_x.add(x) ...
FUNC_DEF IF VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR V...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def smallest(d): out = "" for j in range(0, 10): out += "%d" % j * d[j] return out def largest(d): out = "" for j in range(9, -1, -1): out += "%d" % j * d[j] return out sa = input() sb = input() b = int(sb) h = int(sa) digits_a = [0] * 10 while h > 0: digits_a[h % 10] += ...
FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP BIN_OP STRING VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP STRING VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR F...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = sorted(list(input())) b = input() if len(a) < len(b): print("".join(a[::-1])) exit() result = [None] * len(b) pos = 0 while pos < len(b): is_exit = False for i in range(len(a)): cur = a[~i] if cur <= b[pos]: result[pos] = cur a.remove(cur) if cur <...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def dig(d): return ord(d) - ord("0") def biggest_left(counts): res = "" for i in range(9, -1, -1): res += str(i) * counts[i] return res def ok(d, _counts, rest): if rest == "": return True counts = _counts.copy() counts[d] -= 1 r = "" for i in range(10): r...
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR STRING RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def checkIfLower(num): if int(num) <= int(req): return True def swapped(a, b): arr = list(inp) temp = arr[b] arr[b] = arr[a] arr[a] = temp return "".join(arr) def findMax(): global inp for i in range(len(inp)): for x in range(i, len(inp)): if inp[i] < inp[...
FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN FUNC_CALL STRING VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CAL...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
fre = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] a = input() b = input() c = False def DFS(aa, bb): if int(aa) == len(a): print(bb) exit() global c for i in range(9, -1, -1): if fre[i] > 0 and i <= int(b[int(aa)]) or fre[i] > 0 and c: fre[i] -= 1 if i < int(b[int(aa)...
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR FUNC...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = int(input()) b = int(input()) l = [] while a != 0: d = a % 10 a //= 10 l.append(d) def f(a, b): s = len(l) if s == 0: return a for i in range(len(l) - 1, -1, -1): min_suf = 0 for j in range(len(l)): if j == i: continue min_suf...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMB...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
import sys a, b = input(), input() if len(a) < len(b): print(*sorted(a, reverse=True), sep="") exit() cnt = [0] * 10 for x in a: cnt[int(x)] += 1 def rec(res, digit, rem): if digit == len(b): return res if rem[int(b[digit])]: r = rem[:] r[int(b[digit])] -= 1 x = re...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN VAR IF VAR FUNC_CALL VAR VAR VAR ASSIGN VA...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
import sys a = sys.stdin.readline().strip() b = sys.stdin.readline().strip() dict_ = dict() for i in range(10): dict_[i] = 0 for a_ in a: dict_[int(a_)] += 1 diff = len(b) - len(a) if diff > 0: print("".join(sorted(a, reverse=True))) else: pos = 0 result = "" limit = -1 while pos < len(a): ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR NUMB...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
fact_ = [1] * 50 def fact(n): return fact_[n] def get_perm(n, k): if k > fact(n): exit(123) if n == 1: return [1] k -= 1 res = [] not_used = [i for i in range(1, n + 1)] size = fact(n - 1) for i in range(n): cnt = k // size res.append(not_used[cnt]) ...
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF RETURN VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER RETURN LIST NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR B...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = list(input()) b = input() a.sort(reverse=True) a = "".join(a) if int(a) < int(b): print(a) exit(0) a = list(a) bb = list(b) b = int(b) n = len(a) def work(x, aa, res): if x == n - 1: if aa[0] <= bb[n - 1]: print(res * 10 + ord(aa[0]) - 48) exit(0) return for...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VA...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() if len(b) > len(a): l = [int(i) for i in a] l.sort() l = l[::-1] temp = [str(i) for i in l] s = "".join(temp) print(s) else: d = {} for i in a: if i not in d: d[i] = 1 else: d[i] = d[i] + 1 def find(i): global f...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
f = 0 res = [] def rec(c, b, pos): global f global res if f == 1: return if pos == len(b): print("".join(res)) f = 1 return if pos != 0: for i in range(int(b[pos]), -1, -1): if c[i] != 0 and f == 0: if i < int(b[pos]): ...
ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER RETURN IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() v = sorted(a) v = v[::-1] x = "" for i in range(len(v)): x = x + v[i] v = x if len(a) < len(b): print(v) elif b == a: print(a) else: fin = "" flag = False for j in range(len(a)): for k in range(len(a)): num = fin + v[k] + "".join(sorted(v[:k] + v[k + 1...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING AS...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def main(): num = input() maxi = int(input()) nl = len(num) maxNum = 0 nums = list(num) for x in range(len(nums)): nums[x] = int(nums[x]) nums.sort() nums = nums[::-1] if int(str(maxi)[0]) in nums and len(str(maxi)) == len(nums): nums.remove(int(str(maxi)[0])) ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CA...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def check(m): nonlocal c, ans ans = [0] * len(a) have = c[:] for i in range(m): if have[b[i]] > 0: have[b[i]] -= 1 ans[i] = b[i] else: return 0 for i in range(b[m] - 1, -1, -1): if have[i]: ans[m] = i have[i] -= 1 ...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBE...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = int(input()) b = int(input()) adigits = [] bdigits = [] while a > 0: adigits.append(a % 10) a //= 10 while b > 0: bdigits.append(b % 10) b //= 10 adigits.sort() adigits = adigits[::-1] bdigits = bdigits[::-1] flag = 0 if len(adigits) < len(bdigits): ans = adigits else: ans = [] for i in ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def permuteDigits(): low = list(input().strip()) high = list(input().strip()) if len(low) < len(high): low.sort() low.reverse() print("".join(low)) else: li = [] i = 0 string = "" while True: if high[i] in low: for j in ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE NUMBER IF VAR VAR VAR FOR VAR FUNC_CAL...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def make_number(b, chars): if len(chars) == 0: return "" target = chars[0] for i in chars: if int(b[0]) <= int(i): break target = i chars.remove(target) return target + "".join(chars[::-1]) def find_number(b, chars): backup_chars = list(chars) if len(b) ...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN STRING ASSIGN VAR VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR RETURN BIN_OP VAR FUNC_CALL STRING VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER IF VAR NUMBER VAR EXP...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = list(map(int, input().strip().split()))[0] b = list(map(int, input().strip().split()))[0] dp = dict() for i in str(a): digits = int(i) if digits in dp: dp[digits] += 1 else: dp[digits] = 1 order = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] def maximum(before, dp, low): global order temp = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER N...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = list(input()) b = input() a.sort(reverse=True) ans = [] equal_so_far = True if len(a) < len(b): print("".join(a)) exit() for i in range(len(b)): for digit in a: c = a[:] c.remove(digit) if ( not equal_so_far or digit < b[i] or digit == b[i] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR IF VAR V...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() def lessThan(pos, b, digits): cur_num = "" canEqual = True for i in range(pos): if b[i] in digits: cur_num += b[i] digits.remove(b[i]) else: canEqual = False break if not canEqual: canLess = False m...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = sorted(input()) b = input() ans = "" a = a[::-1] while a: for i in range(len(a)): c = a[:i] + a[i + 1 :] d = ans + a[i] + "".join(c[::-1]) if int(d) <= int(b): ans += a[i] a = c break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER WHILE VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL STRING VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR AS...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
import sys def backtrack(sol, remaining, b, pos, free): if len(sol) == len(b): print(sol) sys.exit(0) for c in "9876543210": if not free and c > b[pos]: continue if not remaining[ord(c) - ord("0")]: continue remaining[ord(c) - ord("0")] -= 1 ...
IMPORT FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR STRING IF VAR VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() la = [int(x) for x in a] res = [] la.sort() la = la[::-1] lb = [int(x) for x in b] cnt = [0] * 20 def check(): tres = 0 for x in range(len(res)): tres *= 10 tres += int(res[x]) return tres <= int(b) if len(a) < len(b): for i in range(len(la)): print(la...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VA...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() if len(a) < len(b): q = list(a) q.sort(reverse=True) print("".join(q)) else: ans = "" flag = 0 while flag == 0 and len(b) != 0: cur = 0 while cur < len(a) and a[cur] != b[0]: cur += 1 if cur < len(a): ans = ans + a[cur] ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR ...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def poss(a2, b): if a2 == []: return True a2.sort() a2 = map(str, a2) s = "" for i in a2: s += i s = int(s) b = int(b) if s <= b: return True return False def abc(a2, b, less=False): if a2 == []: return "" if less: a2.sort(reverse=Tru...
FUNC_DEF IF VAR LIST RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF NUMBER IF VAR LIST RETURN STRING IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR V...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def permuteDigits(a, b): n = len(a) if len(a) < len(b): return a i = 0 c = 0 t = a[0] flag = 0 lastind = [] while i < len(a) and i < len(b) and a[i] >= b[i]: if c == n: i = i - 1 t = a[i] a = a[:i] + a[i + 1 :] a.insert(last...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def c(a, b, l, ans, pro): if l != 0: n = a[:] mx = None pro1 = pro prosh = set() for i in range(l): pro = pro1 if a[i] == prosh: continue elif a[i] <= b[0] and pro: n.pop(i) prosh = a[i] ...
FUNC_DEF IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR VAR IF VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP V...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
s = sorted(input()) m = int(input()) h = len(s) fun = lambda y: int("".join(y)) for x in range(0, h): for i in range(x, h): s[x], s[i] = s[i], s[x] temp = fun(s) if temp > m: s[x], s[i] = s[i], s[x] print(fun(s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VA...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
def find_f(la, max_f): f = max_f while not la.count(f) and f >= 0: f -= 1 return f def get_ans(): i = 0 la_ = la[:] lb_ = lb[:] ans.clear() while i < len(a): f = find_f(la_, lb_[i]) if f >= 0: la_.remove(f) ans.append(f) if f ...
FUNC_DEF ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR B...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = list(reversed(sorted(map(int, input())))) b = list(map(int, input())) if len(b) > len(a): print(*a, sep="") else: ans = [] for i in range(len(b)): if b[i] in a: ans.append(b[i]) a.remove(b[i]) else: while b[i] <= min(a): a.append(ans.po...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_C...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = input() b = input() length_of_a = len(a) length_of_b = len(b) found_digit = False chk_finnish = False appended_digit_count = 0 n = {} num = [] for i in range(0, 10): n[i] = 0 for i in range(0, length_of_a): c = int(a[i]) n[c] += 1 if length_of_a < length_of_b: num = sorted(a, reverse=True) for i...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VA...
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
a = [(ord(e) - ord("0")) for e in list(input().strip())] b = [(ord(e) - ord("0")) for e in list(input().strip())] a.sort(reverse=True) h = [(0) for i in range(10)] for x in a: h[x] += 1 if len(a) < len(b): print("".join(map(str, a))) exit(0) def gmax(hx): s = list(hx) res = list() for i in ran...
ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_...
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by de...
n = int(input()) arr = list(map(int, input().split())) pos, neg = [], [] for i in arr: if i >= 0: pos += [i] else: neg += [i] ans = sum(pos) m_neg = -(10**10) s_odd = 10**10 for i in neg: if i % 2 != 0: m_neg = max(m_neg, i) for i in pos: if i % 2 != 0: s_odd = min(s_odd,...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR VAR IF VAR NUMBER VAR LIST VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSI...
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by de...
n = int(input()) l = sorted([int(i) for i in input().split()]) s = 0 c = -1 c1 = 0 c2 = 0 for i in range(n): if l[i] >= 0: s += l[i] else: c = i if c < n - 1: if s % 2 == 1: print(s) else: for i in range(c, -1, -1): if l[i] % 2 == 1: k = l[i] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL...