#C9456. Perfect Square Composition

    ID: 53551 Type: Default 1000ms 256MiB

Perfect Square Composition

Perfect Square Composition

Given a set of n non-overlapping squares defined by their bottom-left corner coordinates and side lengths, determine whether they perfectly form a larger square without any gaps or overlaps. In other words, when these squares are combined, they should exactly fill a square region whose side length equals the maximum x or y coordinate from the placed squares, and the total area of all the smaller squares must equal the area of the larger square. Formally, if each small square is represented as ( (x_i, y_i, s_i) ), where ( (x_i, y_i) ) is its bottom-left coordinate and ( s_i ) its side length, then let ( A = \sum_{i=1}^{n} s_i^2 ) and let ( L = \max_i(x_i+s_i) ) (assuming ( \max_i(x_i+s_i)=\max_i(y_i+s_i) )). The squares exactly form a perfect larger square if and only if ( A = L^2 ).

inputFormat

The first line contains an integer n, the number of squares. Each of the next n lines contains three space-separated integers x, y, and s, where (x, y) are the coordinates of the bottom-left corner of a square and s is its side length.

outputFormat

Output a single line with either "YES" if the squares perfectly form a larger square or "NO" otherwise.## sample

4
0 0 2
2 0 2
0 2 2
2 2 2
YES