Territories
시간 제한1초메모리 제한512 MB
각 종은 금지된 직사각형 밖에 배치해야 하며, 같은 칸에 모인 쌍의 수가 최대가 되도록 모든 동물을 배치한다.
문제
This time Byteasar researches a wildlife in a nature reserve that has a shape of an rectangle. It is divided into unit squares, there is a square with coordinates for every and .
Our hard-working researcher distinguished species of animals and discovered that each species dislikes living on some particular rectangle (which is stricly smaller than whole nature reserve). For species number it is rectangle described by its two opposite corners and , for some and . We know that there are animals in that species. Therefore, there are animals in total.
Byteasar has an idea for a social-natural experiment which relies on putting each of animals in some cell outside of its disliked region. Sociality of a placement is a number of pairs of animals so that both of them are in the same cell. Hence, if a cell contains animals, this adds to the overall sociality.
It is allowed to put animals from the same species into different cells.
Find the maximum value of the sociality that can be attained.
입력
The first line of input contains three integers , and (, ) denoting the number of species and dimensions of nature reserve, respectively.
Each of following lines contains a description of species, -th of them contains five integers (, , ) describing region disliked by species number and number of animals in that species. For each at least one of the following conditions holds: , , ,
출력
You need to print one integer -- the maximum possible sociality of some placement.
힌트
In first sample we need to put four animals in a cell (contributing to the sociality) and put three remaining animals in a cell (contributing to the sociality).
Second sample test is depicted below. All animals can be put in a cell .
