#pragma GCC optimize("Ofast") #pragma GCC target("avx2") // stdout #include // mmap #include // clang-format off #define RD(v) int v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;} #define wt_int(var, buf, ptr) while(var){buf[ptr++]=var%10;var/=10;}while(ptr--)putc_unlocked(buf[ptr]+'0',stdout); // clang-format on int cnt[1000001]; int a[100000]; int main() { char *rp = mmap(0l, 1l << 28, 1, 2, 0, 0ll); RD(n); int *ap = a; for (int i = 0; i < n; ++i) { RD(t); *ap++ = t; } int *left = a; int ma = 0; for (int *right = a; right < ap; ++right) { ++cnt[*right]; while (cnt[*right] > 1) cnt[*left++]--; if (right - left + 1 > ma) ma = right - left + 1; } char buf[7]; n = 0; wt_int(ma, buf, n); return 0; }