-49. Sum, Maximum and Minimum

I'm a slow walker, but I never walk backwards.

題目來源:judgegirl from ntu prof. pangfeng Liu

Task Description

Given a set of numbers, please find the following according to the remainder when divided by another positive number .

  • The sum of these numbers
  • The maximum of these numbers
  • The minimum of these numbers

For example, when then you need to find the sums of all odd and the sum of all even numbers, the maximum of even numbers and the maximum of all odd numbers, and the minimum of all odd numbers and the minimum of all even numbers. It is guaranteed that there will be at least one number corresponding to all the possible (from to ) remainders.

Input Format

The first line of the input data consists of two integers and , where and . The next line contains non-negative integers to be processed, and each integer is less then or equal to .

Output Format

You should output lines. The i'th line must consists of three numbers, which are the sum, maximum and minimum of those numbers whose remainders are modulo respectively.

Sample Input

6 3
0 1 2 4 7 14

Sample Output

0 0 0
12 7 1
16 14 2

Submit

Login

Testdata Set

Download Testdata