This page is still under construction.

Parts of this page are still being built. What you see may change.

Paper Strip

Interview

Time limit1sMemory limit128 MB

Summary
Find the longest contiguous block of numbers that adds up to exactly s, or print BRAK when none exists.
Level

Medium5 of 10

Topics
Hash map, Prefix sum
Solved
No attempts yet

Problem

Jasio found a very old roll of paper in the attic, on which his great-grandfather had written a sequence of integers. For a game he recently invented, Jasio needs a strip of the paper roll on which the sum of all the numbers is exactly ss. He will cut away and throw out the parts he does not need.

However, he does not want to throw away too much of his great-grandfather's keepsake, so he wants the strip he keeps to be as long as possible.

Only numbers that lie next to each other on the roll can form a single strip. That is, a strip made of one number has length 11, a strip made of two neighboring numbers has length 22, and so on.

Find the length of the longest strip whose sum is exactly ss.

Input

The first line contains two integers nn and ss (1≤n≤1061 \le n \le 10^6, ∣s∣≤106|s| \le 10^6), the length of the roll and the sum the strip must have.

The second line contains the sequence of nn integers x1,x2,…,xnx_1, x_2, \dots, x_n (∣xi∣≤106|x_i| \le 10^6), separated by spaces, where xix_i is the value of the ii-th number written on the paper.

Output

Print a single integer, the length of the longest strip whose sum is exactly ss. If no such strip exists, print the word BRAK instead.

Examples1

  1. Example 1

    Input
    6 4
    3 -2 6 1 -1 5
    
    Expected output
    4