domingo, 16 de octubre de 2011

Girls and Boys

There are G girl students and B boy students in a class that is about to graduate. You
need to arrange them in a single row for the graduation. To give a better impression of
diversity, you want to avoid having too many girls or too many boys seating consecutively.
You decided to arrange the students in order to minimize the gender regularity. The
gender regularity of an arrangement is the maximum number of students of the same
gender (all girls or all boys) that appear consecutively.
Given G and B, calculate the minimum gender regularity among all possible arrangements.

Input


Each test case is described using a single line. The line contains two integers G and B
representing the number of girls and boys in the class, respectively (0 ≤ G, B ≤ 1000).
The end of input is indicated with a line containing the number −1 twice.

Output


For each test case, output a single line with a single integer representing the minimum
gender regularity that an arrangement of G girls and B boys can have.

Example
Input:
10 10
5 1
0 1000
-1 -1


Output:
1
3
1000

http://www.spoj.pl/problems/GIRLSNBS/

miércoles, 12 de octubre de 2011

Move To Invert

A triangle made of coins of height h is as follows
It has h coins at the base and h-1 coins one level above base and so on.(Coins are placed as shown in the figure below)
And at the top most level there will be only one coin
Now given h the task is to invert this triangle by moving minimum number of coins. For example when h=4 triangle is



For h=4 at least 3 coins must be moved to invert it.
Input

In the first line N will be given and then N lines follow with each line having a integer which is the height of triangle in that test case.00≤h<1010;
Output

For each test case output in a seperate line the minimum number of moves required to invert the triangle. Output fits in long long data type 


Example
Inputt:
1
3

Output:
2


http://www.spoj.pl/problems/MINCOUNT/