GIRLSNBS - Girls and Boys

no tags 

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

hide comments
ianand: 2016-05-10 16:12:04

@zacle please make sure that you don't post answers in comments.

pamyjeela: 2016-04-20 15:31:48

Finally ac.....

mickey_v: 2016-04-08 08:18:41

for 5 1 the solution that i thought was g g g g b g but the solution is g g g b g g. hope that helps other.25th atlast :|

deependrasingh: 2016-03-27 11:42:32

can you please give one more test case of unequal numbers of G and B, to understand this problem better.

hparmar_cs13: 2016-03-13 12:45:09

Am i a slow thinker or everybody took almost 40 minutes to solve this?????Please let me know

matijaesk1999: 2015-12-30 16:14:13

it's an easy one,you just need to see what are they asking from you.And you should take care of case b=0 g=0.

ankurverma1994: 2015-12-18 15:20:42

Direct formula.. Don't need to check for case "0 0". It is automatically cover in that formula.. :)

sai kiran: 2015-12-15 12:48:14

can anyone explain 2nd test case

anuj0503: 2015-12-07 18:49:51

Let g be the number of girls and b be the number of boys and let b>g. Now, if * represents the girls and let their arrangement be like :
* * * * * , then think how many boys will you fill on those spaces so that you get the minimum gender regularity.There are g+1 spaces. So first we fit all the spaces with equal number of boys and then distribute the remaining boys to one boy per space.

sarthak_8: 2015-11-30 09:47:31

@uptoyou .. think of a straight line in which you have to adjust boys and girls. You want to adjust them uniformly so that no gender appears to be more in number than the other one. I'll explain the test cases to you. for 5 G and 1 B, 1 boy will sit in between the girls .. therefore 2 girls will be on one side of the boy and 3 on one side. in case of 10 G nd 10 B, each B and G can sit alternatively therefore 1 is the answer. Hope you get it :)


Added by:Pablo Ariel Heiber
Date:2010-09-27
Time limit:2s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 NODEJS OBJC VB.NET
Resource:FCEyN UBA ICPC Selection 2010