Under construction

Still being built. Things may change

5

Time limit5sMemory limit555 MB

Summary
Given an array of non-negative integers with sum S and at least S/5 ones, count the pairs (k, T) where some subsequence of length k sums to T.
Level

Hard8 of 10

Topics
Dynamic programming, Math
Solved
No attempts yet

Problem

You are given an array aa of length nn consisting of non-negative integers. Calculate the number of pairs (k,T)(k, T) such that there exists a subsequence of aa of length kk whose sum is equal to TT. Just kidding, this is too general. Suppose the sum of elements of aa is equal to SS. Then it is guaranteed that aa has at least S/5S/5 elements equal to 11.

Input

The first line contains two positive integers nn and SS (1≤n,S≤2⋅1051 \le n, S \le 2 \cdot 10^5), the number of elements in aa and their sum. The second line contains the array a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤S0 \le a_i \le S). It is guaranteed that ∑i=1nai=S\sum_{i=1}^{n} a_i = S and at least S/5S/5 elements of aa are equal to 11.

Output

Print the number of pairs (k,T)(k, T) such that there exists a subsequence of aa of length kk whose sum is equal to TT.

Examples4

  1. Example 1

    Input
    7 9
    0 0 0 1 1 2 5
    
    Expected output
    42
    
  2. Example 2

    Input
    10 33
    9 9 8 1 1 1 1 1 1 1
    
    Expected output
    48
    
  3. Example 3

    Input
    10 14
    2 4 4 1 0 1 0 1 0 1
    
    Expected output
    81
    
  4. Example 4

    Input
    10 14
    3 5 3 0 1 0 1 0 1 0
    
    Expected output
    87