Our social:

Tcs codevita Season 5 round 1 program Cats And Dogs Answer (solution )

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 NumberSample InputSample Output
1
2
5 5
1 3

1
-1
2
3
7 8
3 5
6 7

1
2
1

If you haved solved this question then please help people to solved it comment your answer in our comment box..!!