PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000146. Các số nguyên kết bạn (Integers Have Friends)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Các số nguyên kết bạn (Integers Have Friends)
Integers Have Friends
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a sequence of pairwise distinct positive integers . A contiguous subarray is a friend group if there exists an integer such that all of its elements have the same remainder modulo :
Find the maximum possible length of a friend group. A single-element interval is allowed.
Input
The first line contains . The second contains the values .
Output
Print the maximum length of a friend group.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
5
1 5 2 4 6
Output
3
Explanation
The last three values have remainder modulo . No contiguous interval of four elements has a common remainder modulo any , so the answer is .