00. AcWing双指针模板:寻找单调性
# j <= i
i = 0; j = 0
while i < n:
while j < i and check(i, j): j += 1
# 具体问题的逻辑
i += 1
# 其实就是后一章的滑动窗口模板,滑动窗口是双指针的特殊情况。
# 双指针问题先写出暴力解法,再根据单调性寻找优化
# 常见问题分类:
# (1) 对于一个序列,用两个指针维护一段区间
# (2) 对于两个序列,维护某种次序,比如归并排序中合并两个有序序列的操作
# O(n*n) -> O(n)
def main():
a = [0] * 100010
s = [0] * 100010
n = int(input())
a = list(map(int, input().split(' ')))
res = 0
i = 0; j = 0
while i < n:
s[a[i]] += 1
while j <= i and s[a[i]] > 1:
s[a[j]] -= 1
j += 1
res = max(res, i - j + 1)
i += 1
print(res)