mfgnik

Untitled

Jan 18th, 2021
680
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. x_str = input()
  2. k = int(input())
  3. x = int(x_str)
  4. x_sorted = sorted(x_str)
  5. x_set = set(x_str)
  6. if k == 0:
  7.     if len(x_set) == 1:
  8.         print(x)
  9.     elif x_str[0] == x_sorted[-1] or int(x_str[1]) < int(x_str[0]):
  10.         print(x_str[0] * len(x_sorted))
  11.     else:
  12.         print(str(int(x_str[0]) + 1) * len(x_sorted))
  13. else:
  14.     if len(x_sorted) <= 2:
  15.         print(x)
  16.     elif x_sorted[1] == x_sorted[-1] or x_sorted[0] == x_sorted[-2]:
  17.         print(x)
  18.     else:
  19.         variants = []
  20.         for i in range(10):
  21.             new_number = int(x_str[0] + str(i) * (len(x_sorted) - 1))
  22.             print(new_number)
  23.             if new_number >= x:
  24.                 variants.append(new_number)
  25.         for position in range(1, len(x_sorted)):
  26.             for i in range(10):
  27.                 new_number = int(x_str[0] * position + str(i) + x_str[0] * (len(x_sorted) - position - 1))
  28.                 print(new_number)
  29.                 if new_number >= x:
  30.                     variants.append(new_number)
  31.         print(variants)
  32.         print(min(variants))
  33.  
RAW Paste Data