Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)

简介: Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)

A. A Variety of Operations


time limit per test


1 second


memory limit per test


256 megabytes


input


standard input


output


standard output


William has two numbers aa and bb initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer kk is picked, which is then used to perform one of the following operations: (note, that for each operation you can choose a new positive integer kk)


  1. add number kk to both aa and bb, or
  2. add number kk to aa and subtract kk from bb, or
  3. add number kk to bb and subtract kk from aa.


Note that after performing operations, numbers aa and bb may become negative as well.


William wants to find out the minimal number of operations he would have to perform to make aa equal to his favorite number cc and bb equal to his second favorite number dd.


Input


Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041≤t≤104). Description of the test cases follows.


The only line of each test case contains two integers cc and dd (0≤c,d≤109)(0≤c,d≤109), which are William's favorite numbers and which he wants aa and bb to be transformed into.


Output


For each test case output a single number, which is the minimal number of operations which William would have to perform to make aa equal to cc and bb equal to dd, or −1−1 if it is impossible to achieve this using the described operations.


Example


input


Copy

6

1 2

3 5

5 3

6 6

8 0

0 0


output

Copy

-1

2

2

1

2

0


Note


Let us demonstrate one of the suboptimal ways of getting a pair (3,5)(3,5):


  • Using an operation of the first type with k=1k=1, the current pair would be equal to (1,1)(1,1).
  • Using an operation of the third type with k=8k=8, the current pair would be equal to (−7,9)(−7,9).
  • Using an operation of the second type with k=7k=7, the current pair would be equal to (0,2)(0,2).
  • Using an operation of the first type with k=3k=3, the current pair would be equal to (3,5)(3,5).


题目就是简单模拟,-1,0,1,2;这几种情况;

#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int c, d;
    cin >> c >> d;
    if ((c + d) % 2 != 0) {
      cout << "-1" << endl;
      continue;
    }
    if (c == 0 && d == 0) {
      cout << "0" << endl;
      continue;
    }
    if (c == d || c + d == 0) {
      cout << "1" << endl;
      continue;
    }
    cout << "2" << endl;
  }
}
相关文章
|
10月前
|
机器学习/深度学习 人工智能
Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)B. Take Your Places!
Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)B. Take Your Places!
22 0
|
人工智能 测试技术
Codeforces Round #746 (Div. 2) C. Bakry and Partitioning
Codeforces Round #746 (Div. 2) C. Bakry and Partitioning
61 0
Educational Codeforces Round 113 (Rated for Div. 2)A. Balanced Substring
Educational Codeforces Round 113 (Rated for Div. 2)A. Balanced Substring
68 0
|
机器学习/深度学习 人工智能 算法
|
机器学习/深度学习