fork(2) download
  1. N = int( input() )
  2. A = [ int(x) for x in input().split() ]
  3.  
  4. from collections import defaultdict
  5. inside = defaultdict(int)
  6.  
  7. answer = 1
  8. r = 0
  9. for l in range(N):
  10. if l > 0:
  11. inside[ A[l-1] ] -= 1
  12. if inside[ A[l-1] ] == 0: del inside[ A[l-1] ]
  13. while r < N and (len(inside) < 2 or A[r] in inside):
  14. inside[ A[r] ] += 1
  15. r += 1
  16. answer = max( answer, r-l )
  17.  
  18. print(answer)
Success #stdin #stdout 0.03s 10240KB
stdin
5
1 2 3 3 2
stdout
4