PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000165. Đoạn dài nhất có tổng đúng K (Longest Subarray With Sum K)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đoạn dài nhất có tổng đúng K (Longest Subarray With Sum K)

Longest Subarray With Sum K

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array of nn integers a1,a2,…,ana_1,a_2,\ldots,a_n, numbered from 1. A nonempty contiguous interval [l,r][l,r] contains all elements from ll through rr and has length r−l+1r-l+1. Find the maximum length of an interval whose sum is exactly KK. Print 0 if none exists.

Input

The first line contains two integers n,Kn,K. The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print the maximum qualifying length, or 0 if none exists.

Subtasks

  • Subtask 1 (30 points): 1≤n≤2001\le n\le 200; −109≤aj≤109-10^9\le a_j\le10^9 for all 1≤j≤n1\le j\le n; −109≤K≤109-10^9\le K\le10^9.
  • Subtask 2 (30 points): 1≤n≤2000001\le n\le 200000; 0≤aj≤1090\le a_j\le10^9 for all 1≤j≤n1\le j\le n; −109≤K≤109-10^9\le K\le10^9.
  • Subtask 3 (40 points): 1≤n≤2000001\le n\le 200000; −109≤aj≤109-10^9\le a_j\le10^9 for all 1≤j≤n1\le j\le n; −109≤K≤109-10^9\le K\le10^9.

Example 1

Input

4 2
1 -1 1 1

Output

4

Explanation

The entire array sums to 2, so [1,4] qualifies and no longer interval exists.

Example 2

Input

3 0
1 2 3

Output

0

Explanation

Every nonempty interval has positive sum, so none sums to zero.