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

#PS0000285. Học sinh thay phấn (Find the Student that Will Replace the Chalk)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Học sinh thay phấn (Find the Student that Will Replace the Chalk)

Find the Student that Will Replace the Chalk

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

A class has nn students numbered 00 through n−1n-1. They take turns in cyclic order starting at 0. Initially there are kk pieces of chalk. Student ii consumes aia_i pieces on each turn if enough remain; otherwise that student replaces the chalk. Find the first student who must replace it.

Input

First line: n,kn,k. Second line: exactly nn integers a0,…,an−1a_0,\ldots,a_{n-1}.

Output

Print the zero-based index of the student replacing the chalk.

Subtasks

  • Subtask 1 (20 points): 1≤n≤301\le n\le30; 1≤ai≤1051\le a_i\le10^5; 1≤k≤10001\le k\le1000.
  • Subtask 2 (30 points): 1≤n≤1000001\le n\le100000; 1≤ai≤1051\le a_i\le10^5; 1≤k≤1091\le k\le10^9; all aia_i are equal.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le100000; 1≤ai≤1051\le a_i\le10^5; 1≤k≤1091\le k\le10^9.

Example 1

Input

3 22
5 1 5

Output

0

Explanation

Each round uses 11 pieces. Two rounds exhaust the supply; student 0 replaces it.

Example 2

Input

4 25
3 4 1 2

Output

1

Explanation

Two rounds consume 20. Student 0 uses 3 of the remaining 5; student 1 needs 4 but only 2 remain.