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;
  }
}
相关文章
|
7月前
|
前端开发 开发者
Warning: [antd: Breadcrumb] `Breadcrumb.Item and Breadcrumb.Separator` is deprecated. Please use `it
Warning: [antd: Breadcrumb] `Breadcrumb.Item and Breadcrumb.Separator` is deprecated. Please use `it
323 1
|
7月前
Should pass resolved color instead of resource id here: getResources().getColor(R.color.brown)
Should pass resolved color instead of resource id here: getResources().getColor(R.color.brown)
57 6
|
机器学习/深度学习 人工智能
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!
43 0
|
人工智能 测试技术
Codeforces Round #746 (Div. 2) C. Bakry and Partitioning
Codeforces Round #746 (Div. 2) C. Bakry and Partitioning
91 0
|
索引
LeetCode 162. Find Peak Element
给定一个输入数组 nums,其中 nums[i] ≠ nums[i+1],找到峰值元素并返回其索引。 数组可能包含多个峰值,在这种情况下,返回任何一个峰值所在位置即可。
106 0
LeetCode 162. Find Peak Element
|
机器学习/深度学习 人工智能 算法
Cannot find source code based button in SE24
When you are logging on to customer system for incident handling, you want to switch to source code to perform some keyword search. However, you could not find button “Source code based builder” in toolbar, with following warning message: ———————————————— 版权声明:本文为CSDN博主「汪子熙」的原创文章,遵循CC 4.0 BY-SA版权协
Cannot find source code based button in SE24
|
机器学习/深度学习 算法 C++