Олимпиадный тренинг

Задача 43126. Lecture on commodity science


Задача

Темы:
Gena Bukin came to Zlatoust to give a management lecture in a shoe store. Entering the store, Gena saw a complete mess: boxes of shoes were scattered randomly in a heap in the middle of the hall.
Of course, this situation did not suit him, and he decided that he needed to show how to arrange the boxes correctly. He noticed that there were only two types of boxes in the store: the red ones were x centimeters high and there were a pieces; the blue ones have a height of y centimeters, there are b pieces.
Gena wants to take some boxes from the pile and make a tower out of them. However, due to some personal ideas about the aesthetics, Gena does not put two boxes of the same color on top of each other, in the tower he can only alternate colors.
After trying all the possible ways to build the tower, Gena memorized how many different heights of the structure he could get. Can you figure out how many different heights h > 0 that it is possible to build a tower of boxes of height h, satisfying the color alternation requirement?
Input
In a single line, 4 integers x, y, a, b — red box height, blue box height, number of red boxes, number of blue boxes (1<= x,y,a,b <=109).
Imprint
Print one number — number of different heights of towers made of boxes.
 
Examples
# Input Output
1 1 2 3 3 9