Sunday 17 May 2020

Codeforces Round #643 (Div. 2) : C. Count Triangles : Solution in python

C. Count Triangles

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

Like any unknown mathematician, Yuri has favourite numbers:

, , , and , where . Yuri also likes triangles and once he thought: how many non-degenerate triangles with integer sides , , and exist, such that

holds?

Yuri is preparing problems for a new contest now, so he is very busy. That's why he asked you to calculate the number of triangles with described property.

The triangle is called non-degenerate if and only if its vertices are not collinear.

Input

The first line contains four integers:

, , and (

) — Yuri's favourite numbers.

Output

Print the number of non-degenerate triangles with integer sides

, , and such that the inequality

holds.

Examples
Input
Copy
1 2 3 4
Output
Copy
4
Input
Copy
1 2 2 5
Output
Copy
3
Input
Copy
500000 500000 500000 500000
Output
Copy
1
Note

In the first example Yuri can make up triangles with sides

, , and

.

In the second example Yuri can make up triangles with sides

, and

.

In the third example Yuri can make up only one equilateral triangle with sides equal to

.



Solution in Python :


l = [int(i) for i in input().split()]

length = len(l)
count = 0
for a in range(l[0] , l[1]+1) :
    for b in range(l[1],l[2]+1) :
        for c in range(l[2] ,l[3]+1) :
                 if a+b > c and b+c > a and c+a > b :
                    count += 1
print(count)

No comments:

Post a Comment