Arya and Bran play a game. At the start, two positive integers A and B are written on a blackboard. The players move in turns and Arya moves first. On a turn, a player picks a positive integer k and either replaces A with A−k×B, or replaces B with B−k×A. Whoever first makes one of the two numbers drop to zero or below loses.
For example, if the numbers start at (12,51), the game can go like this.
- Arya replaces 51 with 51−3×12=15, so the blackboard holds (12,15).
- Bran replaces 15 with 15−1×12=3, so the blackboard holds (12,3).
- Arya replaces 12 with 12−3×3=3, so the blackboard holds (3,3).
- Bran replaces one of the 3s with 3−1×3=0 and loses.
Call a starting position (A,B) a winning position if Arya can always win from it, whatever Bran does.
Given four integers A1, A2, B1, B2, count the winning positions (A,B) with A1≤A≤A2 and B1≤B≤B2.