This page is still under construction.

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

A Pleasant Homework Life

Time limit2sMemory limit512 MB

Summary
Assignments are worked in cyclic order, skipping every M-th day as a rest day, and each needs Xi work days; find which assignment finishes first.
Level

Medium5 of 10

Topics
Math, Binary search, Implementation, Simulation
Solved
No attempts yet

Problem

The professors of the computer science department hand out their assignments around the same time to make the students happy.

Taeho, who has filled his semester with 66 majors, is being bombarded by the professors' assignments and cannot collect himself.

Each assignment is finished after working on it for XiX_i days. However, Taeho gets bored early if he works on the same subject's assignment two days in a row. So he decided to work on a different subject's assignment every day. If he has NN assignments to do, he works on the first assignment on day 11, the second on day 22, ..., the NN-th on day NN, then goes back to the first assignment on day N+1N+1, and repeats.

But working on assignments without a break could kill him from overwork, so he repeats working for M−1M-1 days and resting on day MM. If an assignment is due on a rest day, he does not push it to the next day; he skips it entirely.

For example, suppose there are 55 assignments and he rests once every 44 days. On day 11 he does assignment 11, on day 22 assignment 22, and on day 33 assignment 33. On day 44 he should do assignment 44, but since it is a rest day he skips it. Instead, on day 55 he does assignment 55, not assignment 44.

Taeho, satisfied that he made a pleasant plan, became curious about when he would finish the assignments.

Given the days needed to complete each assignment and the rest day information, find the assignment that finishes first.

Input

The first line gives NN and MM. (2≤N≤20 0002 \le N \le 20\,000, 2≤M≤5002 \le M \le 500)

The second line gives X1X_1, X2X_2, ..., XNX_N separated by spaces. (1≤Xi≤125 000 0001 \le X_i \le 125\,000\,000)

Output

Print the number of the assignment Taeho finishes first.

Examples2

  1. Example 1

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

    Input
    7 7
    10 9 8 4 5 6 1
    
    Expected output
    4