using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace Application { class MainClass { public static void Main (string[] args) { var N = readInt (); var A = readInts (' '); var s = new Searcher (); var l = 0; while (l < N) { l = s.LonguestSeq (A, l); } writeLine (s.Longest); } public class Searcher { public int Longest = 0; private Queue distinct = new Queue (); private Dictionary dict = new Dictionary(); public int LonguestSeq (int[] A, int l) { var i = l + distinct.Count; for (; i < A.Length && !dict.ContainsKey (A [i]); i++) { distinct.Enqueue (A [i]); dict.Add(A[i], true); } this.Longest = Math.Max (distinct.Count, this.Longest); while (true) { l++; if (distinct.Count == 0) break; if (A.Length <= i) break; var value = distinct.Dequeue (); dict.Remove(value); if (A [i] == value) break; } var rest = A.Length - l; if (this.Longest > (rest + distinct.Count)) l = A.Length; return l; } } static void writeLine (object o) { System.Console.WriteLine (o.ToString ()); } static string readItem () { return readItems (' ') [0]; } static String[] readItems (char c) { return System.Console.ReadLine ().Split (c); } static int readInt () { return readInts (' ') [0]; } static int[] readInts (char c) { return readItems (c).Select (x => int.Parse (x)).ToArray (); } } }