fork download
  1. import sys
  2.  
  3. while True:
  4. try:
  5. size = int(input())
  6. row1 = list(map(int,input().split()))
  7. row2 = list(map(int,input().split()))
  8. except EOFError:
  9. break
  10.  
  11. max = 0
  12. if len(row1) > 0:
  13. for i in range(size):
  14. t = min(row1)
  15. if row1.count(t) == 1:
  16. if t > max:
  17. max = t
  18. row1.remove(t)
  19. continue
  20. indices = [i for i,x in enumerate(row1) if x == t]
  21. if not indices[1] - indices[0] == 1:
  22. row1.remove(t)
  23. row1.remove(t)
  24. if t > max:
  25. max = t
  26. if len(row2) > 0:
  27. for j in range(size):
  28. t = min(row2)
  29. if row2.count(t) == 1:
  30. if t > max:
  31. max = t
  32. row2.remove(t)
  33. continue
  34. indices = [i for i,x in enumerate(row2) if x == t]
  35. if not indices[1] - indices[0] == 1:
  36. row2.remove(t)
  37. row2.remove(t)
  38. if t > max:
  39. max = t
  40. print (max)
Success #stdin #stdout 0.02s 28384KB
stdin
5
1 2 3 4 5
1 2 3 4 5
stdout
5