fork download
  1. gside = lambda l, r: ((l and r) and len(l) > len(r) and r) or l or r
  2. lsub = lambda jails, u: u.issubset(set(jails[:-1])) and chk(jails[:-1], u)
  3. rsub = lambda jails, u: u.issubset(set(jails[1:])) and chk(jails[1:], u)
  4. bsrch = lambda jails, u: gside(lsub(jails, u), rsub(jails, u)) or jails
  5. chk = lambda j, u: j if set(j) == u and len(j) == len(u) else bsrch(j, u)
  6. sjail = lambda jails: len(chk(jails, set(jails)))
  7. while True:
  8. try:
  9. inp = str(input())
  10. if inp == '':
  11. break
  12. print(sjail(inp.split(' ')))
  13. except (EOFError):
  14. break
Success #stdin #stdout 0.02s 9944KB
stdin
7 3 7 2 1 3 4 1
1 2 3 1 2 1
1 1 1 1 1 1
stdout
5
3
1