#K76807. Grid Value Operations

    ID: 34724 Type: Default 1000ms 256MiB

Grid Value Operations

Grid Value Operations

You are given a \( n \times n \) grid initialized with zeros. Then, you will be given \( m \) operations. Each operation is described by five integers \( x_1, y_1, x_2, y_2, v \) and means that you should add \( v \) to every cell in the subgrid whose top-left corner is \( (x_1, y_1) \) and bottom-right corner is \( (x_2, y_2) \) (using 1-indexed coordinates).

Your task is to determine the minimum and maximum values in the grid after performing all operations.

Note: All formulas are written in \( \LaTeX \) format.

inputFormat

The first line contains two integers \( n \) and \( m \), where \( n \) is the size of the grid and \( m \) is the number of operations.

Each of the following \( m \) lines contains five integers \( x_1 \), \( y_1 \), \( x_2 \), \( y_2 \), and \( v \), representing an operation.

outputFormat

Output two integers separated by a space: the minimum and maximum value in the grid after all operations.

## sample
3 1
1 1 3 3 5
5 5