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)

Saturday 16 May 2020

Codeforces Round #643 (Div. 2) : Sequence with Digits : Solution in python

A. Sequence with Digits


time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

Let's define the following recurrence:

Here

and are the minimal and maximal digits in the decimal representation of

without leading zeroes. For examples refer to notes.

Your task is calculate

for given and

.

Input

The first line contains one integer

(

) — the number of independent test cases.

Each test case consists of a single line containing two integers

and (,

) separated by a space.

Output

For each test case print one integer

on a separate line.

Example
Input
Copy
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
Copy
42
487
519
528
544
564
588
628
Note