Number of triangles

You are given a polygon of N sides with vertices numbered from 1, 2, ..., N. Now, exactly 2 vertices of the polygons are colored black and remaining are colored white. You are required to find the number of triangles denoted by A such that:

  1. The triangle is formed by joining only the white-colored vertices of the polygon.
  2. The triangle shares at least one side with the polygon.
Input format
  • The first line contains t denoting the number of test cases.
  • Next t lines contain three space-separated integers NB1, and B2 where N is the number of sides in the polygon and B1,B2denote the vertices that are colored black.
Output format
For each test case, print the answer A representing the number of triangles that can be formed with the given conditions in the problem statement. 
Constraints
1t100
5N105
1B1,B2N

SAMPLE INPUT
1
6 2 5
SAMPLE OUTPUT
4

Explanation
Number of triangles
The number of triangles which satisfy the property are 4  - 136 , 146 , 346 and 134 

Note:- I personally solving this problem scored only 85/100

Comments

Popular posts from this blog

How to pass parameters in webhook?

Access and modify all the resources of our Wiki.js using WikiJS API

Fahrenheit to Celsius