This page is still under construction.

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

Halloween treats

Time limit1sMemory limit128 MB

Summary
Find the leftmost-shortest consecutive block of neighbours whose sweet total is divisible by c, or report that none exists.
Level

Medium6 of 10

Topics
Prefix sum, Hash map, Math
Solved
No attempts yet

Problem

Every Halloween the children run into the same trouble. Each neighbour is only willing to hand out a fixed total number of sweets that day, no matter how many children knock, so a child who arrives too late may end up with nothing. To keep things fair, the children pool everything they collect and split it evenly, giving every child the same whole number of sweets with none left over.

There are cc children and nn neighbours living along the street, numbered 11 to nn in the order the children pass their houses. Neighbour ii gives out a total of aia_i sweets. The children will visit one consecutive block of neighbours — the neighbours l,l+1,…,rl, l+1, \ldots, r for some 1≤l≤r≤n1 \le l \le r \le n — and they want the collected total al+al+1+⋯+ara_l + a_{l+1} + \cdots + a_r to be divisible by cc so that it can be shared evenly. Because every neighbour gives at least one sweet, such a total is a positive multiple of cc, so each child receives at least one sweet.

Input

The input contains several test cases.

The first line of each test case contains two integers cc and nn (1≤c≤n≤1000001 \le c \le n \le 100000): the number of children and the number of neighbours. The second line contains nn space-separated integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1000001 \le a_i \le 100000), where aia_i is the total number of sweets neighbour ii hands out.

The last test case is followed by a line containing two zeros, which must not be processed.

Output

For each test case, output on one line the neighbours the children should visit.

Consider every consecutive block l,l+1,…,rl, l+1, \ldots, r (with 1≤l≤r≤n1 \le l \le r \le n) whose total al+al+1+⋯+ara_l + a_{l+1} + \cdots + a_r is divisible by cc. Among all such blocks, pick the one whose right endpoint rr is as small as possible; if several blocks share that smallest rr, pick the one whose left endpoint ll is as small as possible. Print the indices l,l+1,…,rl, l+1, \ldots, r of that block in increasing order, separated by single spaces.

If no such block exists, print no sweets instead.

Examples6

  1. Example 1

    Input
    4 5
    1 2 3 7 5
    3 6
    7 11 2 5 13 17
    0 0
    
    Expected output
    2 3 4
    1 2
    
  2. Example 2

    Input
    3 3
    3 5 7
    0 0
    
    Expected output
    1
    
  3. Example 3

    Input
    1 1
    100000
    0 0
    
    Expected output
    1
    
  4. Example 4

    Input
    5 5
    1 1 1 1 1
    0 0
    
    Expected output
    1 2 3 4 5
    
  5. Example 5

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

    Input
    2 4
    3 5 7 4
    6 6
    1 2 3 4 5 6
    0 0
    
    Expected output
    1 2
    1 2 3