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;
  }
}
相关文章
|
存储 数据采集 监控
信息系统架构开发方法ADM
信息系统架构开发方法ADM
1600 5
Springboot文件下载跨域问题解决方案
Springboot文件下载跨域问题解决方案
|
4月前
|
人工智能 缓存 安全
刚刚 Claude Code 源码泄露!我扒出了 11 个隐藏秘密
大家好,我是程序员鱼皮 👨🏻‍💻。 堪称全球最强的 AI 编程工具 Claude Code 的 50 多万行源码泄露了!一家以 AI 安全著称的公司,自己却在代码发布环节翻了车。 针对这件事,我只想说两个字: 感谢! 这份源码对学技术的同学来说简直是宝藏资源啊,过年了过年了! 那 Claude Code 源码具体是怎么泄露的?源码里有哪些精妙的设计?为什么它能做到 AI 编程工具的天花板?
368 0
|
7月前
|
存储 监控 Java
分布式调用三大基石:超时、重试、幂等的架构级落地规范与全场景避坑指南
本文深入解析分布式调用稳定性三大基石:超时(设生死线、分层预算、中断执行)、重试(限次数/退避/幂等前提)与幂等(唯一键、原子校验、结果复用),结合全链路透传、AOP实现及高频避坑指南,提供可落地的架构级协同方案。
608 6
|
10月前
|
Java 应用服务中间件 Linux
|
10月前
|
消息中间件 缓存 NoSQL
【Redis进阶】不止是缓存!Redis的5种核心数据结构与实战场景全解析
本文深入浅出地解析了Redis五大核心数据结构:String、Hash、List、Set和ZSet,结合图解与实战场景,涵盖缓存、计数器、分布式锁、购物车、消息队列、排行榜等典型应用,助你摆脱“只会SET/GET”的困境,真正发挥Redis的高性能潜力。
|
10月前
|
SQL 移动开发 Oracle
Oracle 窗口函数
想在看员工薪水的同时,还能在同一行看到他所在部门的平均薪水吗?或者想给每个部门的产品按销量排名?这就是窗口函数的魔力。它不像GROUP BY会把数据压缩成一行,而是为每一行都进行一次“开窗”计算。通过OVER(PARTITION BY ...),你可以轻松实现分组排名、累计求和、或是与前后行数据对比等高级分析,代码比复杂的自连接和子查询要优雅得多。
844 0
|
Unix 编译器 C语言
C 编译器
C 编译器。
616 4
信不信?工作这么多年,还有很多网工不知道光模块光衰的正常范围?
信不信?工作这么多年,还有很多网工不知道光模块光衰的正常范围?
3314 2