fork download
  1. import itertools as it
  2.  
  3. def concatenate():
  4. while True:
  5. line = input()
  6. if (len(line) == 0): break
  7. loc = line.find(' ')
  8.  
  9. nums = []
  10.  
  11. while (loc > 0):
  12. numstr = line[:loc]
  13. nums.append(numstr)
  14. line = line[loc+1:]
  15. loc = line.find(' ')
  16. if (loc <= 0 and len(line) > 0):
  17. numstr = line
  18. nums.append(numstr)
  19.  
  20. nums = sorted(nums)
  21. lo, hi = None, None
  22. for order in it.permutations(nums):
  23. opt = ''
  24. for a in order:
  25. opt = opt + a
  26. if (lo == None): lo = opt
  27. elif (int(opt) < int(lo)): lo = opt
  28. if (hi == None): hi = opt
  29. elif (int(opt) > int(hi)): hi = opt
  30.  
  31. print(lo + ' ' + hi)
  32.  
  33. concatenate()
Success #stdin #stdout 0.01s 27704KB
stdin
79 82 34 83 69

420 34 19 71 341

17 32 91 7 46


stdout
3469798283 8382796934