Problems > Polygon Diagonals

Polygon Diagonals

Difficulty: 900 2000 ms 128 MB

math

How many diagonals does a convex polygon with N vertices have?

Input: one integer N.

Output: N(N−3)/2.

Constraints:

  • 3 ≤ N ≤ 109

Sample Tests

Input 1
5
Output 1
5
Input 2
3
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.