import java.util.Scanner; public class Yuki3009_A { public Yuki3009_A() { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int[] data = new int[N]; for (int i = 0; i < N; i++) { data[i] = scanner.nextInt(); } int max = 0; //貪欲解 for (int L = 0; L < data.length; L++) { boolean[] checked = new boolean[1000000 + 1]; boolean allOK = true; for (int R = L; R < data.length; R++) { int c = data[R]; if (checked[c]) { max = Math.max(max, R - L); allOK = false; break; } checked[c] = true; } if (allOK) { max = Math.max(max, data.length - L); } } System.out.println(max); } public static void main(String[] args) { Yuki3009_A hoge = new Yuki3009_A(); } }