Chef and Triangles -ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017

Hi guys can anyone provide me some idea to solve this.

Thanks in advance.