Arya and Bran play a game. A blackboard starts with two positive integers A and B written on it. The players take turns and Arya goes first. On a turn a player picks a positive integer k and replaces A with A−k×B, or replaces B with B−k×A. The player who makes one of the two numbers drop to zero or below loses.
If the numbers start at (12,51), one possible game runs like this.
- Arya replaces 51 with 51−3×12=15, leaving (12,15) on the blackboard.
- Bran replaces 15 with 15−1×12=3, leaving (12,3).
- Arya replaces 12 with 12−3×3=3, leaving (3,3).
- Bran replaces one 3 with 3−1×3=0 and loses.
Call (A,B) a winning position when Arya wins every game that starts from it, no matter how Bran plays.
You are given four integers A1, A2, B1, B2. Count the winning positions (A,B) with A1≤A≤A2 and B1≤B≤B2.