#P1237G. Balanced Distribution

    ID: 2124 Type: RemoteJudge 2000ms 512MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>data structuresdpgreedy*3500

Balanced Distribution

No submission language available for this problem.

Description

There are nn friends living on a circular street. The friends and their houses are numbered clockwise from 00 to n1n-1.

Initially person ii has aia_i stones. The friends want to make the distribution of stones among them perfectly balanced: everyone should possess the same number of stones.

The only way to change the distribution of stones is by conducting meetings. During a meeting, people from exactly kk consecutive houses (remember that the street is circular) gather at the same place and bring all their stones with them. All brought stones may be redistributed among people attending the meeting arbitrarily. The total number of stones they possess before the meeting and after the meeting must stay the same. After the meeting, everyone returns to their home.

Find a way to make the distribution of stones perfectly balanced conducting as few meetings as possible.

The first line contains two integers nn and kk (2k<n1052 \le k < n \le 10^5), denoting the number of friends and the size of each meeting.

The second line contains nn integers a0,a1,,an1a_0, a_1, \ldots, a_{n-1} (0ai1040 \le a_i \le 10^4), denoting the number of stones people initially have.

The sum of all aia_i is divisible by nn.

Output the minimum number of meetings mm (m0m \ge 0), followed by mm descriptions of meetings in chronological order.

The ii-th description must consist of an integer sis_i (0si<n0 \le s_i < n), followed by kk non-negative integers bi,0,bi,1,,bi,k1b_{i, 0}, b_{i, 1}, \ldots, b_{i, k-1} (bi,j0b_{i, j} \ge 0). Such a description denotes a meeting of people si,(si+1)modn,,(si+k1)modns_i, (s_i + 1) \bmod n, \ldots, (s_i + k - 1) \bmod n, and bi,jb_{i,j} denotes the number of stones person (si+j)modn(s_i + j) \bmod n must have after the ii-th meeting. The sum of bi,jb_{i, j} must match the total number of stones owned by these people before the ii-th meeting.

We can show that a solution exists for any valid input, and any correct output contains at most 10710^7 non-whitespace characters.

Input

The first line contains two integers nn and kk (2k<n1052 \le k < n \le 10^5), denoting the number of friends and the size of each meeting.

The second line contains nn integers a0,a1,,an1a_0, a_1, \ldots, a_{n-1} (0ai1040 \le a_i \le 10^4), denoting the number of stones people initially have.

The sum of all aia_i is divisible by nn.

Output

Output the minimum number of meetings mm (m0m \ge 0), followed by mm descriptions of meetings in chronological order.

The ii-th description must consist of an integer sis_i (0si<n0 \le s_i < n), followed by kk non-negative integers bi,0,bi,1,,bi,k1b_{i, 0}, b_{i, 1}, \ldots, b_{i, k-1} (bi,j0b_{i, j} \ge 0). Such a description denotes a meeting of people si,(si+1)modn,,(si+k1)modns_i, (s_i + 1) \bmod n, \ldots, (s_i + k - 1) \bmod n, and bi,jb_{i,j} denotes the number of stones person (si+j)modn(s_i + j) \bmod n must have after the ii-th meeting. The sum of bi,jb_{i, j} must match the total number of stones owned by these people before the ii-th meeting.

We can show that a solution exists for any valid input, and any correct output contains at most 10710^7 non-whitespace characters.

Samples

Sample Input 1

6 3
2 6 1 10 3 2

Sample Output 1

3
2 7 3 4
5 4 4 2
1 4 4 4

Sample Input 2

11 4
1 0 1 0 0 4 4 2 4 3 3

Sample Output 2

3
3 2 2 2 2
8 2 2 2 5
10 2 2 2 2

Note

In the first example, the distribution of stones changes as follows:

  • after the first meeting: 22 66 7\mathbf{7} 3\mathbf{3} 4\mathbf{4} 22;
  • after the second meeting: 4\mathbf{4} 2\mathbf{2} 77 33 44 4\mathbf{4};
  • after the third meeting: 44 4\mathbf{4} 4\mathbf{4} 4\mathbf{4} 44 44.

In the second example, the distribution of stones changes as follows:

  • after the first meeting: 11 00 11 2\mathbf{2} 2\mathbf{2} 2\mathbf{2} 2\mathbf{2} 22 44 33 33;
  • after the second meeting: 5\mathbf{5} 00 11 22 22 22 22 22 2\mathbf{2} 2\mathbf{2} 2\mathbf{2};
  • after the third meeting: 2\mathbf{2} 2\mathbf{2} 2\mathbf{2} 22 22 22 22 22 22 22 2\mathbf{2}.