Sunday, July 31, 2016

TCS Code Vita Season-5 Round-1 set-2 Program-3

Problem : Cats And Dogs
Cats & Dogs have become friends now. They are going to a picnic and they decided to sit together in groups to have their lunch.

There are N Cats & M Dogs. They can form any number of groups to sit together, subject to rules below.

Rules:
1.    They will sit in a straight line
2.    A Cat cannot sit beside another Cat or alone
3.    A Dog cannot sit beside another Dog or alone


You need to find minimum number of groups they need to form. If no group can be formed then print -1. 


Input Format:

First line of input will be a number of Test Cases T

Next T lines of input will contains two numbers N and M, delimited by space

Output Format:

Print minimum number of groups to be formed for each Test Case in new line
OR

Print -1 if no group can be formed 
Constraints:
1.     0<T<=10^6
2.     0<N,M<=10^18


Example:

Example Number
Sample Input
Sample Output
1

2
5 5
1 3

1
-1
2

3
7 8
3 5
6 7

1
2
1