Under construction

Still being built. Things may change

Klee in Solitary Confinement

Time limit1sMemory limit1024 MB

Summary
Given an array and an integer k, add k to at most one contiguous interval so that the mode of the whole array appears as many times as possible.
Level

Hard8 of 10

Topics
Sorting, Prefix sum, Segment tree, Hash map
Solved
No attempts yet

Problem

Since the traveler came, people in Monstadt have shown great interest in computer programming and algorithms, including Klee, the Spark Knight of the Knights of Favonius.

Source: Genshin Impact Official

Sent to solitary confinement by Jean again, Klee decides to spend her time learning Mo's algorithm, which computes answers to range query problems without modifications in O(n1.5)\mathcal{O}(n^{1.5}) time.

To check whether Klee has truly mastered the algorithm (or is secretly making more bombs), Jean gives her a problem. You are given an integer sequence a1,a2,⋯ ,ana_1, a_2, \cdots, a_n and several queries [li,ri][l_i, r_i]. For each query, find the mode of the contiguous subsequence ali,ali+1,⋯ ,aria_{l_i}, a_{l_i+1}, \cdots, a_{r_i}. The mode is the number that appears the most times in the subsequence.

With Mo's algorithm, Klee solves this problem easily, but another problem comes to mind. You are given an integer sequence a1,a2,⋯ ,ana_1, a_2, \cdots, a_n of length nn and an integer kk. You may perform the following operation at most once: choose two integers ll and rr with 1≤l≤r≤n1 \le l \le r \le n, and add kk to every aia_i with l≤i≤rl \le i \le r. You may also skip the operation. Choose whether to perform the operation so as to maximize the number of occurrences of the mode of the whole sequence, and output that maximum.

Input

The first line contains two integers nn and kk (1≤n≤1061 \le n \le 10^6, −106≤k≤106-10^6 \le k \le 10^6), the length of the sequence and the additive number.

The second line contains nn integers a1,a2,⋯ ,ana_1, a_2, \cdots, a_n (−106≤ai≤106-10^6 \le a_i \le 10^6), the original sequence.

There is only one test case in each test file.

Output

Output one line containing one integer, the maximum number of occurrences of the mode of the whole sequence after performing or skipping the operation.

Hint

For the first sample, choose l=1l = 1 and r=2r = 2. The sequence becomes {4,4,4,4,4}\{4, 4, 4, 4, 4\}. The mode is clearly 44, which appears 55 times.

For the second sample, choose l=4l = 4 and r=6r = 6. The sequence becomes {3,2,3,3,3,3,3}\{3, 2, 3, 3, 3, 3, 3\}. The mode is 33, which appears 66 times.

For the fourth sample, do not perform the operation. The modes are 11 and −2-2, which both appear 33 times.

Examples4

  1. Example 1

    Input
    5 2
    2 2 4 4 4
    
    Expected output
    5
    
  2. Example 2

    Input
    7 1
    3 2 3 2 2 2 3
    
    Expected output
    6
    
  3. Example 3

    Input
    7 1
    2 3 2 3 2 3 3
    
    Expected output
    5
    
  4. Example 4

    Input
    9 -100
    -1 -2 1 2 -1 -2 1 -2 1
    
    Expected output
    3