// yukicoder: No.3009 異なる数字の最大の範囲 // 2019.6.28 bal4u #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { int n = 0, c = gc(); while (c < '0') c = gc(); do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0'); return n; } int N; int a[100005]; char f[1000005]; int main() { int i, k, ans; N = in(); for (i = 0; i < N; i++) a[i] = in(); a[N] = a[N-1]; k = 0, ans = 0, f[a[0]] = 1, i = 1; while (i < N) { while (!f[a[i]]) f[a[i++]] = 1; if (i >= N) break; if (i-k > ans) ans = i - k; while (a[k] != a[i]) f[a[k++]] = 0; k++, i++; } if (i-k > ans) ans = i - k; printf("%d\n", ans); return 0; }