exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
stringlengths
4
3k
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
listlengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
difficulty
int64
-1
3.5k
prob_desc_output_spec
stringlengths
17
1.47k
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
5e082d0e23a7bf30aa5cb404844232d6
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class A1 { void solve() { long c = clong(); long d = clong(); if (c == 0 && d == 0) { cout(0); } else if (c == d) { cout(1); } else if (Math.abs(c-d) % 2 == 0) { cout(2); } else { cout(-1); } } public static void main(String... args) { int t = in.nextInt(); in.nextLine(); for (int test = 0; test < t; test++) { new A1().solve(); } } static final Scanner in = new Scanner(System.in); static final PrintStream out = System.out; static int cint() { return in.nextInt(); } static long clong() { return in.nextLong(); } static String cstr() { return in.nextLine(); } static int[] carr_int(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } return a; } static long[] carr_long(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = in.nextLong(); } return a; } static void cout(int... a) { for (int i = 0; i < a.length; i++) { if (i != 0) { out.print(' '); } out.print(a[i]); } out.println(); } static void cout(long... a) { for (int i = 0; i < a.length; i++) { if (i != 0) { out.print(' '); } out.print(a[i]); } out.println(); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 11
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
f63f502fd6f23267e8b17ddfc8c7bceb
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.util.*; public class A { static FastScanner sc; static PrintWriter pw; public static void main(String[] args) throws Exception{ sc = new FastScanner(); pw = new PrintWriter(System.out); try{ int T = sc.ni(); while(T-->0){ int c = sc.ni(); int d = sc.ni(); if(c==d && c==0){ pw.println(0); }else if(c==d && c!=0){ pw.println(1); }else if(Math.abs(c-d)%2==0){ pw.println(2); }else{ pw.println(-1); } } }catch(Exception e){ return; } pw.close(); } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in), 32768); st = null; } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int ni() { return Integer.parseInt(next()); } int[] intArray(int N) { int[] ret = new int[N]; for (int i = 0; i < N; i++) ret[i] = ni(); return ret; } long nl() { return Long.parseLong(next()); } long[] longArray(int N) { long[] ret = new long[N]; for (int i = 0; i < N; i++) ret[i] = nl(); return ret; } double nd() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 11
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
c1c7b646568ab06a5db504cd1d66da62
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException; import java.io.IOException;import java.io.InputStream;import java.io.PrintWriter; import java.security.AccessControlException;import java.util.List;public class _p001556A { static public void main(final String[] args) throws IOException{p001556A._main(args);} static class p001556A extends Solver{public p001556A(){}@Override public void solve()throws IOException{int c=sc.nextInt();int d=sc.nextInt();sc.nextLine();int res=(c==0 && d==0?0:(c==d?1:((c+d)%2==0?2:-1)));pw.println(res);}static public void _main(String[] args)throws IOException{new p001556A().run();}}static class MyScanner{private StringBuilder cache=new StringBuilder();int cache_pos=0;private int first_linebreak=-1;private int second_linebreak=-1;private StringBuilder sb=new StringBuilder();private InputStream is=null;public MyScanner(final InputStream is){this.is=is;}public String charToString(final int c){return String.format("'%s'",c=='\n'?"\\n":(c=='\r'?"\\r":String.valueOf((char)c))); }public int get(){int res=-1;if(cache_pos<cache.length()){res=cache.charAt(cache_pos); cache_pos++;if(cache_pos==cache.length()){cache.delete(0,cache_pos);cache_pos=0; }}else{try{res=is.read();}catch(IOException ex){throw new RuntimeException(ex);} }return res;}private void unget(final int c){if(cache_pos==0){cache.insert(0,(char)c); }else{cache_pos--;}}public String nextLine(){sb.delete(0,sb.length());int c;boolean done=false;boolean end=false;while((c=get())!=-1){if(check_linebreak(c)){done=true; if(c==first_linebreak){if(!end){end=true;}else{cache.append((char)c);break;}}else if(second_linebreak!=-1 && c==second_linebreak){break;}}if(end && c!=first_linebreak && c!=second_linebreak){cache.append((char)c);break;}if(!done){sb.append((char)c); }}return!done && sb.length()==0?null:sb.toString();}private boolean check_linebreak(int c){if(c=='\n'|| c=='\r'){if(first_linebreak==-1){first_linebreak=c;}else if(c!=first_linebreak && second_linebreak==-1){second_linebreak=c;}return true;}return false;}public int nextInt(){return Integer.parseInt(next());}public long nextLong(){return Long.parseLong(next()); }public boolean hasNext(){boolean res=false;int c;while((c=get())!=-1){if(!check_linebreak(c) && c!=' '&& c!='\t'){res=true;unget(c);break;}}return res;}public String next(){ sb.delete(0,sb.length());boolean started=false;int c;while((c=get())!=-1){if(check_linebreak(c) || c==' '|| c=='\t'){if(started){unget(c);break;}}else{started=true;sb.append((char)c); }}return sb.toString();}public int nextChar(){return get();}public boolean eof() {int c=get();boolean res=false;if(c!=-1){unget(c);}else{res=true;}return res;}public double nextDouble(){return Double.parseDouble(next());}}static abstract class Solver {protected String nameIn=null;protected String nameOut=null;protected boolean singleTest =false;protected MyScanner sc=null;protected PrintWriter pw=null;private int current_test =0;private int count_tests=0;protected int currentTest(){return current_test;}protected int countTests(){return count_tests;}private void process()throws IOException{if(!singleTest) {count_tests=sc.nextInt();sc.nextLine();for(current_test=1;current_test<=count_tests; current_test++){solve();pw.flush();}}else{count_tests=1;current_test=1;solve();} }abstract protected void solve()throws IOException;public void run()throws IOException {boolean done=false;try{if(nameIn!=null){if(new File(nameIn).exists()){try(FileInputStream fis=new FileInputStream(nameIn);PrintWriter pw0=select_output();){select_output(); done=true;sc=new MyScanner(fis);pw=pw0;process();}}else{throw new RuntimeException("File " +new File(nameIn).getAbsolutePath()+" does not exist!");}}}catch(IOException | AccessControlException ex){}if(!done){try(PrintWriter pw0=select_output();){sc=new MyScanner(System.in); pw=pw0;process();}}}private PrintWriter select_output()throws FileNotFoundException {if(nameOut!=null){return new PrintWriter(nameOut);}return new PrintWriter(System.out); }}static abstract class Tester{static public int getRandomInt(final int min,final int max){return(min+(int)Math.floor(Math.random()*(max-min+1)));}static public long getRandomLong(final long min,final long max){return(min+(long)Math.floor(Math.random() *(max-min+1)));}static public double getRandomDouble(final double min,final double maxExclusive){return(min+Math.random()*(maxExclusive-min));}abstract protected void testOutput(final List<String>output_data);abstract protected void generateInput(); abstract protected String inputDataToString();private boolean break_tester=false; protected void beforeTesting(){}protected void breakTester(){break_tester=true;} public boolean broken(){return break_tester;}}}
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 11
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
24024584d67801c984ec82aef0ac89b8
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { try { Slove(); } catch(Exception e){ System.exit(0); } } public static void Slove() { int t = sc.nextInt(); while(t -- > 0) { int a = sc.nextInt(); int b = sc.nextInt(); int p = Math.abs(a - b); if(p % 2 == 1) { System.out.println(-1); } else { if( a == b && a == 0) { System.out.println(0); } else if(a == b) { System.out.println(1); } else { System.out.println(2); } } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 11
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
fe9424cc9ae0d05134e24c48b8b5ebaf
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.StringTokenizer; public class B2{ public static void main(String[] args){ FS sc = new FS(); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while(t-->0){ int a = sc.nextInt(); int b = sc.nextInt(); int diff = Math.abs(a-b); if(diff%2==1){ System.out.println("-1"); } else{ System.out.println(a==b?(a==0 && b==0?"0":"1"):"2"); } } pw.flush(); pw.close(); } static class FS{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next(){ while(!st.hasMoreElements()){ try{ st = new StringTokenizer(br.readLine()); } catch(Exception ignored){ } } return st.nextToken(); } int[] nextArray(int n){ int[] a = new int[n]; for(int i = 0; i < n; i++){ a[i] = nextInt(); } return a; } long[] nextLongArray(int n){ long[] a = new long[n]; for(int i = 0; i < n; i++){ a[i] = nextLong(); } return a; } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 11
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
014462c367234c71438dad8b2c80462e
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int tc = 0; tc < t; ++tc) { int c = sc.nextInt(); int d = sc.nextInt(); System.out.println(solve(c, d)); } sc.close(); } static int solve(int c, int d) { if ((c + d) % 2 != 0) { return -1; } if (c == 0 && d == 0) { return 0; } return (c == d) ? 1 : 2; } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 11
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
4ea49054c513250b1116e3b97c2dd7ec
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int tc = 0; tc < t; ++tc) { int c = sc.nextInt(); int d = sc.nextInt(); System.out.println(solve(c, d)); } sc.close(); } static int solve(int c, int d) { if ((c + d) % 2 != 0) { return -1; } if (c == 0 && d == 0) { return 0; } return (c == d) ? 1 : 2; } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 11
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
ae7ca3125c7aab548e88637f467fd702
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class A{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-- > 0){ long a=sc.nextInt(); long b=sc.nextInt(); double avg1=(a+b)/2.0; long avg2=(a+b)/2; if(avg1-avg2==0){ if(a==b) { if (a==0) System.out.println(0); else System.out.println(1); } else System.out.println(2); } else{ System.out.println(-1); } } sc.close(); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 11
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
ca09abe9ddb040532a5ce5ef645e3b5c
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.* ; import java.util.* ; public class App { public static void main (String[] args) throws java.lang.Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); //reader = new BufferedReader(new FileReader(new File("C:\\Users\\Anjali\\Desktop\\projects\\HelloWorld\\src\\input.txt"))); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); //writer = new BufferedWriter(new FileWriter(new File("C:\\Users\\Anjali\\Desktop\\projects\\HelloWorld\\src\\output.txt"))); //int tests = Integer.parseInt(reader.readLine()); int tests = 1; //StringBuilder sb = new StringBuilder(tests); while (tests-- > 0){ solve(reader, writer); writer.write("\n"); } reader.close(); writer.flush(); writer.close(); } static void solve(BufferedReader reader, BufferedWriter writer) throws IOException { int tests = Integer.parseInt(reader.readLine()); for (int i = 0; i < tests; i++) { String[] input = reader.readLine().split(" "); long c = Long.parseLong(input[0]); long d = Long.parseLong(input[1]); if (Math.abs(c - d) % 2 == 0) { if (c == 0 && d == 0) { writer.write("0\n"); } else if (c == d) { writer.write("1\n"); } else { writer.write("2\n"); } } else { writer.write("-1\n"); } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 11
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
3dccb2e2395c2983002ad72b572933a2
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; import java.io.*; import java.math.BigDecimal; import java.math.RoundingMode; public class Test implements Runnable { static FastReader sc; static PrintWriter out; static int mod = 1000000007, inf = (int) 1e9, minf = -(int) 1e9; static long infL = (long) 1e18, minfL = -(long) 1e18; static final Random random = new Random(); public static void main(String[] args) { new Thread(null, new Test(), "coderrohan14", 1 << 26).start(); } @Override public void run() { try { ioSetup(); } catch (IOException e) { return; } } public static void ioSetup() throws IOException { if (System.getProperty("ONLINE_JUDGE") == null) { File f1 = new File("input.txt"); File f2 = new File("output.txt"); Reader r = new FileReader(f1); sc = new FastReader(r); out = new PrintWriter(f2); double prev = System.currentTimeMillis(); solve(); out.println("\n\nExecuted in : " + ((System.currentTimeMillis() - prev) / 1e3) + " sec"); } else { sc = new FastReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); } out.flush(); out.close(); } static void solve() { int t = sc.nextInt(); StringBuilder ans = new StringBuilder(""); while (t-- > 0) { long c = sc.nextLong(),d=sc.nextLong(); if(c==0&&d==0){ ans.append("0\n"); }else if(c==d){ ans.append("1\n"); }else if((c+d)%2==0){ ans.append("2\n"); }else{ ans.append("-1\n"); } } out.println(ans); } /****************************************************************************************************************************************************************************************/ public static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } static double setPrecision(double num,int precision){ return BigDecimal.valueOf(num).setScale(precision,RoundingMode.HALF_UP).doubleValue(); } static long modInverse(long a, int mod) { long g = gcd(a, mod); if (g != 1) return -1; else { return modPower(a, mod - 2L, mod); } } static long modPower(long x, long y, int mod) { long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } static int gcd(int a, int b) { int tmp = 0; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; } static long gcd(long a, long b) { long tmp = 0; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; } static boolean isPrime(long n) { if (n == 2 || n == 3) return true; if (n % 2 == 0) return false; for (long i = 3; i * i <= n; i += 2) { if (n % i == 0) return false; } return n != 1; } static void sort(long[] a) { int n = a.length;// shuffle, then sort for (int i = 0; i < n; i++) { int oi = random.nextInt(n); long temp = a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a); } static void sort(int[] a) { int n = a.length;// shuffle, then sort for (int i = 0; i < n; i++) { int oi = random.nextInt(n), temp = a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a); } static boolean isPerfectSquare(long x) { long sqrt = (long) Math.sqrt(x); return (sqrt * sqrt) == x; } static int digitsCount(long x) { return (int) Math.floor(Math.log10(x)) + 1; } static boolean isPowerTwo(long n) { return (n & n - 1) == 0; } static void sieve(boolean[] prime, int n) { // Sieve Of Eratosthenes for (int i = 1; i <= n; i++) { prime[i] = true; } for (int i = 2; i * i <= n; i++) { if (prime[i]) { for (int j = 2; i * j <= n; j++) { prime[i * j] = false; } } } } static long nCr(long n, long r) { // Combinations if (n < r) return 0; if (r > n - r) { // because nCr(n, r) == nCr(n, n - r) r = n - r; } long ans = 1L; for (long i = 0; i < r; i++) { ans *= (n - i); ans /= (i + 1); } return ans; } static int floor(int[] a, int v) { int l = 0, h = a.length - 1; while (l < h) { int mid = (l + h) / 2; if (a[mid] == v) return mid; if (v < a[mid]) h = mid; else { if (mid + 1 < h && a[mid + 1] < v) l = mid + 1; else return mid; } } return a[l] <= v ? l : -1; } static int floor(long[] a, long v) { int l = 0, h = a.length - 1; while (l < h) { int mid = (l + h) / 2; if (a[mid] == v) return mid; if (v < a[mid]) h = mid; else { if (mid + 1 < h && a[mid + 1] < v) l = mid + 1; else return mid; } } return a[l] <= v ? l : -1; } static int ceil(int[] a, int v) { int l = 0, h = a.length - 1; while (l < h) { int mid = (l + h) / 2; if (a[mid] == v) return mid; if (a[mid] < v) l = mid + 1; else h = mid; } return a[h] >= v ? h : -1; } static int ceil(long[] a, long v) { int l = 0, h = a.length - 1; while (l < h) { int mid = (l + h) / 2; if (a[mid] == v) return mid; if (a[mid] < v) l = mid + 1; else h = mid; } return a[h] >= v ? h : -1; } static long catalan(int n) { // n-th Catalan Number long c = nCr(2 * n, n); return c / (n + 1); } static class Pair implements Comparable<Pair> { // Pair Class int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Pair)) { return false; } Pair pair = (Pair) o; if (x != pair.x) { return false; } if (y != pair.y) { return false; } return true; } @Override public int hashCode() { long result = x; result = 31 * result + y; return (int) result; } @Override public int compareTo(Pair o) { return (int) (this.x - o.x); } } static class Trip { // Triplet Class long x; long y; long z; Trip(long x, long y, long z) { this.x = x; this.y = y; this.z = z; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Trip)) { return false; } Trip trip = (Trip) o; if (x != trip.x) { return false; } if (y != trip.y) { return false; } if (z != trip.z) { return false; } return true; } @Override public int hashCode() { long result = 62 * x + 31 * y + z; return (int) result; } } /**************************************************************************************************************************************************************************************/ static class FastReader { BufferedReader br; StringTokenizer st; public FastReader(Reader r) { br = new BufferedReader(r); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArrayI(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } return arr; } long[] readArrayL(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextLong(); } return arr; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } boolean hasNext() { if (st != null && st.hasMoreTokens()) { return true; } String tmp; try { br.mark(1000); tmp = br.readLine(); if (tmp == null) { return false; } br.reset(); } catch (IOException e) { return false; } return true; } } /* * ASCII Range--->(A-Z)--->[65,90]<<::>>(a-z)--->[97,122] */ /******************************************************************************************************************/ static void printArray(int[] arr) { out.print("["); for (int i = 0; i < arr.length; i++) { if (i < arr.length - 1) out.print(arr[i] + ","); else out.print(arr[i]); } out.print("]"); out.println(); } static void printArray(long[] arr) { out.print("["); for (int i = 0; i < arr.length; i++) { if (i < arr.length - 1) out.print(arr[i] + ","); else out.print(arr[i]); } out.print("]"); out.println(); } static void printArray(double[] arr) { out.print("["); for (int i = 0; i < arr.length; i++) { if (i < arr.length - 1) out.print(arr[i] + ","); else out.print(arr[i]); } out.print("]"); out.println(); } /**********************************************************************************************************************/ }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 11
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
622bab9bb4516c9c8425aa542eec4652
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.text.ParseException; import java.util.*; public class Main { static class CP { static boolean isPrime(long n) { if (n <= 1) return false; if (n == 2 || n == 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i += 6) { if (n % i == 0 || n % (i + 2) == 0) return false; } return true; } static int ifnotPrime(int prime[], int x) { // checking whether the value of element // is set or not. Using prime[x/64], // we find the slot in prime array. // To find the bit number, we divide x // by 2 and take its mod with 32. return (prime[x/64] & (1 << ((x >> 1) & 31))); } // Marks x composite in prime[] static void makeComposite(int prime[], int x) { // Set a bit corresponding to given element. // Using prime[x/64], we find the slot // in prime array. To find the bit number, // we divide x by 2 and take its mod with 32. prime[x/64] |= (1 << ((x >> 1) & 31)); } // Prints all prime numbers smaller than n. static ArrayList<Integer> bitWiseSieve(int n) { ArrayList<Integer> al=new ArrayList<Integer>(); int prime[] = new int[n/64 + 1]; // 2 is the only even prime so we // can ignore that loop starts from // 3 as we have used in sieve of // Eratosthenes . for (int i = 3; i * i <= n; i += 2) { // If i is prime, mark all its // multiples as composite if (ifnotPrime(prime, i)==0) for (int j = i * i, k = i << 1; j < n; j += k) makeComposite(prime, j); } // writing 2 separately al.add(2); // Printing other primes for (int i = 3; i <= n; i += 2) if (ifnotPrime(prime, i) == 0) al.add(i); return al; } static List<Integer> sieve(long size) { ArrayList<Integer> pr = new ArrayList<Integer>(); boolean prime[] = new boolean[(int)size]; for (int i = 2; i < prime.length; i++) prime[i] = true; for (int i = 2; i * i < prime.length; i++) { if (prime[i]) { for (int j = i * i; j < prime.length; j += i) { prime[j] = false; } } } for (int i = 2; i < prime.length; i++) if (prime[i]) pr.add(i); return pr; } static long binary_Expo(long a, long b) // calculating a^b { long res = 1; while (b != 0) { if ((b & 1) == 1) { res *= a; --b; } a *= a; b /= 2; } return res; } static long Modular_Expo(long a, long b) { long res = 1; while (b != 0) { if ((b & 1) == 1) { res = (res * a) % 1000000007; --b; } a = (a * a) % 1000000007; b /= 2; } return res; } static int i_gcd(int a, int b) // iterative way to calculate gcd. { while (true) { if (b == 0) return a; int c = a; a = b; b = c % b; } } static long gcd(long a, long b) // here b is the remainder { if (b == 0) return a; //because each time b will divide a. return gcd(b, a % b); } static long ceil_div(long a, long b) // a numerator b denominator { return (a + b - 1) / b; } static int getIthBitFromInt(int bits, int i) { return (bits >> (i - 1)) & 1; } static int upper_Bound(int a[], int x) //closest to the left+1 { int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] <= x) l = m; else r = m; } return l + 1; } static int upper_Bound(List<Integer> a, int x) //closest to the left+1 { int l = -1, r = a.size(); while (l + 1 < r) { int m = (l + r) >>> 1; if (a.get(m) <= x) l = m; else r = m; } return l + 1; } static int lower_Bound(int a[], int x) //closest to the right { int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] >= x) r = m; else l = m; } return r; } static int lower_Bound(List<Integer> a, int x) //closest to the right { int l = -1, r = a.size(); while (l + 1 < r) { int m = (l + r) >>> 1; if (a.get(m) >= x) r = m; else l = m; } return r; } static boolean isSquarefactor(int x, int factor, int target) { int s = (int) Math.round(Math.sqrt(x)); return factor * s * s == target; } static boolean isSquare(int x) { int s = (int) Math.round(Math.sqrt(x)); return x * x == s; } static void sort(int a[]) // heap sort { PriorityQueue<Integer> q = new PriorityQueue<>(); for (int i = 0; i < a.length; i++) q.add(a[i]); for (int i = 0; i < a.length; i++) a[i] = q.poll(); } static void shuffle(int[] in) { for (int i = 0; i < in.length; i++) { int idx = (int) (Math.random() * in.length); fast_swap(in, idx, i); } } static int[] computeLps(String pat) { int len=0,i=1,m=pat.length(); int lps[]=new int[m]; lps[0]=0; while(i<m) { if(pat.charAt(i)==pat.charAt(len)) { ++len; lps[i]=len; ++i; } else { if(len!=0) { len=lps[len-1]; } else { lps[i]=len; ++i; } } } return lps; } static void kmp(String s,String pat) { int n=s.length(),m=pat.length(); int lps[]=computeLps(pat); int i=0,j=0; while(i<n) { if(s.charAt(i)==pat.charAt(j)) { i++; j++; } else { if(j!=0) { j=lps[j-1]; } else { i++; } } } } static void reverse_ruffle_sort(int a[]) { shuffle(a); Arrays.sort(a); for (int l = 0, r = a.length - 1; l < r; ++l, --r) fast_swap(a, l, r); } static void ruffle_sort(int a[]) { shuffle(a); Arrays.sort(a); } static int getMax(int arr[], int n) { int mx = arr[0]; for (int i = 1; i < n; i++) if (arr[i] > mx) mx = arr[i]; return mx; } static int[] z_function(String s) { int n = s.length(), z[] = new int[n]; for (int i = 1, l = 0, r = 0; i < n; ++i) { if (i <= r) z[i] = Math.min(z[i - l], r - i + 1); while (i + z[i] < n && s.charAt(z[i]) == s.charAt(i + z[i])) ++z[i]; if (i + z[i] - 1 > r) { l = i; r = i + z[i] - 1; } } return z; } static void swap(int a[], int idx1, int idx2) { a[idx1] += a[idx2]; a[idx2] = a[idx1] - a[idx2]; a[idx1] -= a[idx2]; } static void fast_swap(int[] a, int idx1, int idx2) { if (a[idx1] == a[idx2]) return; a[idx1] ^= a[idx2]; a[idx2] ^= a[idx1]; a[idx1] ^= a[idx2]; } } public static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(String s) { try { br = new BufferedReader(new FileReader(s)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } } static class Pair { int val,bin; public Pair(int val,int bin) { this.val=val; this.bin=bin; } } //int[] input = Arrays.stream(br.readLine().split("\\s+")).mapToInt(Integer::parseInt).toArray(); static HashSet<Integer> sum=new HashSet<>(); static HashSet<Integer> set=new HashSet<>(); public static void main(String[] args) throws IOException,ParseException { FastScanner sc=new FastScanner(); int t=sc.nextInt(); while (t-->0) { int c=sc.nextInt(); int d=sc.nextInt(); if(c==0 && d==0) { System.out.println(0); } else if(c==d) { System.out.println(1); } else if(Math.abs(d-c)==1 || ((c+d)&1)==1) { System.out.println(-1); } else { System.out.println(2); } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 11
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
9d05b5ee904cd8bf92a6bd5ba356939b
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); while(t-->0){ long c = scanner.nextInt(); long d = scanner.nextInt(); if(c==0&&d==0){ System.out.println(0); continue; } if(c==d){ System.out.println(1); continue; } long sum = c+d; if (sum%2==0) { System.out.println(2); }else{ System.out.println(-1); } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
b158a1ba402477c71f08b1779bcd2130
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; public class A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int a=sc.nextInt(); int b=sc.nextInt(); if(a==0 && b==0) System.out.println(0); else if(a==b) System.out.println(1); else if(Math.abs(a-b)%2==0) System.out.println(2); else System.out.println(-1); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
a5f12197c08f86b84eda7e00ebb503cf
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; /** * William has two numbers a and b initially both equal to zero. William * mastered performing three different operations with them quickly. Before * performing each operation some positive integer k 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 k) * * add number k to both a and b, or add number k to a and subtract k from b, or * add number k to b and subtract k from a. Note that after performing * operations, numbers a and b may become negative as well. * * William wants to find out the minimal number of operations he would have to * perform to make a equal to his favorite number c and b equal to his second * favorite number d. * * Input Each test contains multiple test cases. The first line contains the * number of test cases t (1≤t≤104). Description of the test cases follows. * * The only line of each test case contains two integers c and d (0≤c,d≤109), * which are William's favorite numbers and which he wants a and b 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 a equal to c and b * equal to d, or −1 if it is impossible to achieve this using the described * operations. * * <pre> Example inputCopy 6 1 2 3 5 5 3 6 6 8 0 0 0 outputCopy -1 2 2 1 2 0 Note Let us demonstrate one of the suboptimal ways of getting a pair (3,5): Using an operation of the first type with k=1, the current pair would be equal to (1,1). Using an operation of the third type with k=8, the current pair would be equal to (−7,9). Using an operation of the second type with k=7, the current pair would be equal to (0,2). Using an operation of the first type with k=3, the current pair would be equal to (3,5). * * </pre> * * @author Sonal * */ public class VarietyOfOperations { public static void main(String[] args) { try(Scanner s = new Scanner(System.in);) { int T = s.nextInt(); while (T > 0) { int a = s.nextInt(); int b = s.nextInt(); if(a == 0 && b == 0) { System.out.println(0); }else if(a == b) { System.out.println(1); } else if((a + b) % 2 == 0) { System.out.println(2); } else { System.out.println(-1); } T--; } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
63e82c8b1069d3be7f9d8847b21570a6
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class VarietyOfOperations2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a, b; for(int i = 0; i < n; i ++) { a = sc.nextInt(); b = sc.nextInt(); if(a == 0 && b == 0) System.out.println(0); else if(a == b) System.out.println(1); else if((a + b) % 2 == 0) System.out.println(2); else System.out.println(-1); } sc.close(); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
701976e2d76ef4d562d52fc512c7df4e
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.util.*; public class deltix_a { public static void main(String args[]){ FScanner in = new FScanner(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); while(t-->0) { int c=in.nextInt(); int d=in.nextInt(); if(c==0 && d==0) out.println(0); else if(c==d) out.println(1); else if((c+d)%2==0) out.println(2); else out.println(-1); } out.close(); } static class FScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer sb = new StringTokenizer(""); String next(){ while(!sb.hasMoreTokens()){ try{ sb = new StringTokenizer(br.readLine()); } catch(IOException e){ } } return sb.nextToken(); } String nextLine(){ try{ return br.readLine(); } catch(IOException e) { } return ""; } int nextInt(){ return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] readArray(int n) { int a[] = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a; } float nextFloat(){ return Float.parseFloat(next()); } double nextDouble(){ return Double.parseDouble(next()); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
08f6431ac99c501276b25103e9348197
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.util.*; public class VOO { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int r = sc.nextInt(); for (int i = 0; i < r; i++) { int c = sc.nextInt(); int d = sc.nextInt(); if (Math.abs((d + c)) % 2 == 1 || (c + d) / 2 < 0) out.println(-1); else if (d == 0 && c == 0) out.println(0); else if (d == c || d + c == 0) out.println(1); else out.println(2); } // sc.nextInt(); // out.println(words); // Stop writing your solution here. ------------------------------------- out.close(); } // -----------PrintWriter for faster // output---------------------------------printwriter for faster output, // myscanner class for faster input. This is the way, this is why you are a // disgrace to humanity and all it stands for you uncoordinated fuck public static PrintWriter out; // -----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // -------------------------------------------------------- }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
28693e8443592a9b6e26c1209ee7c65d
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.Array; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.StringTokenizer; import java.util.TreeMap; public class A { public static void main(String[] args) throws IOException { FastScanner s = new FastScanner(); int t = s.nextInt(); // int t=1; while(t-->0){ long a = s.nextLong(); long b = s.nextLong(); if(a==b && a==0) System.out.println(0); else if(a==b) System.out.println(1); else if(Math.abs(a-b)%2==0) System.out.println(2); else System.out.println(-1); } } static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);} static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);} static void sortr(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l,Collections.reverseOrder()); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
b7a3842c1ce532f15cf2faa70307f00b
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int c=sc.nextInt(); int d=sc.nextInt(); if(c==0 && d==0) System.out.println(0); else if(c==d) System.out.println(1); else if(Math.abs(c-d)%2==0) System.out.println(2); else System.out.println(-1); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
a588a56574e6cf2674027c7a75b86dac
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class VarietyOfOperations { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = Integer.parseInt(scanner.nextLine()); for(int i=0; i<t; i++) { String cd[] = scanner.nextLine().split("\\s"); int c = Integer.parseInt(cd[0]); int d = Integer.parseInt(cd[1]); System.out.println(minOperations(c, d)); } } private static int minOperations(int c, int d) { if(Math.abs(c-d)%2 == 1) { return -1; } if(c == 0 && d == 0) return 0; int a = (c+d)/2, b = (c+d)/2; if(a == c && b == d) return 1; else return 2; } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
424ef6791970cb29d53fef30e144be5b
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.PrintWriter; import java.util.*; import java.io.*; public class Ladder { public static void main(String[] args){ Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int tc = sc.nextInt(); while(tc-->0){ long c = sc.nextLong(), d = sc.nextLong(); if(c == d)if(c == 0)pw.println(0);else pw.println(1); else if(Math.abs(c - d) % 2 != 0)pw.println(-1); else pw.println(2); } pw.flush(); } static class Pair{ long x; long y; public Pair(long x,long y) { this.x=x; this.y=y; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
3ce06959a0e6959514a1b4b9a73e766a
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
// Generated by Code Flattener. // https://plugins.jetbrains.com/plugin/9979-idea-code-flattener import java.io.*; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { Solution solution = new ASolution(); boolean local = System.getProperty("ONLINE_JUDGE") == null && !solution.isInteractive(); String input = local ? "input.txt" : null; solution.in = new MyScanner(input); solution.out = MyWriter.of(null); solution.bm = new Benchmark(); solution.al = new Algorithm(); solution.run(); solution.close(); } private abstract static class Solution { public MyScanner in; public MyWriter out; public Benchmark bm; public Algorithm al; public void init() { } public abstract void solve(); protected boolean isMultiTest() { return true; } public void run() { init(); if (isMultiTest()) { int t = in.nextInt(); for (int i = 0; i < t; i++) { solve(); } } else { solve(); } } public void close() { out.close(); } public boolean isInteractive() { return false; } } private static class ASolution extends Solution { public void solve() { int c = in.nextInt(); int d = in.nextInt(); if (c == 0 && d == 0) { out.println(0); } else if (Math.abs(c) == Math.abs(d)) { out.println(1); } else if ((c - d) % 2 == 0) { out.println(2); } else { out.println(-1); } } } private static class MyScanner { private final BufferedReader br; private StringTokenizer st; public MyScanner(String fileName) { if (fileName != null) { try { File file = new File(getClass().getClassLoader().getResource(fileName).getFile()); br = new BufferedReader(new FileReader(file)); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } else { br = new BufferedReader(new InputStreamReader(System.in)); } } public String next() { while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(nextLine()); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public String nextLine() { try { String line = br.readLine(); if (line == null) { throw new RuntimeException("empty line"); } st = null; return line; } catch (IOException e) { throw new RuntimeException(e); } } } private static class Benchmark { } private static class Algorithm { } private static class MyWriter extends PrintWriter { public static MyWriter of(String fileName) { if (fileName != null) { try { return new MyWriter(new FileWriter(fileName)); } catch (IOException e) { throw new RuntimeException(e); } } else { return new MyWriter(new BufferedOutputStream(System.out)); } } public MyWriter(FileWriter fileWriter) { super(fileWriter); } public MyWriter(OutputStream out) { super(out); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
fe3f46547629a4a1934d2859575bc28c
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.util.*; import java.util.stream.Collectors; public class CodeForces { /** * У Василия есть два числа a и b, изначально равные нулю. Василий очень быстро научился делать с ними три * различные операции. Перед выполнением каждой операции выбирается некоторое целое положительное число k, с * помощью которого производится одна из операций: (обратите внимание, что для каждой операции вы можете выбрать * новое число k) * <p> * прибавить к a и b число k, или * прибавить к a число k и отнять от b число k, или * прибавить к b число k и отнять от a число k. * Обратите внимание, что в результате выполнения операций, числа a и b могут становиться в том числе * отрицательными. * <p> * Василий хочет узнать, какое минимальное количество операций ему потребуется совершить, чтобы число a стало * равно числу c, а число b стало равно d. * <p> * Входные данные * Во входных данных находятся несколько наборов входных данных. В первой строке находится одно целое число t * (1≤t≤104) — количество наборов входных данных. Далее следуют наборы входных данных. * <p> * Единственная строка каждого набора входных данных содержит два целых числа c и d (0≤c,d≤109) — числа, в * которые Василий хочет преобразовать a и b. * <p> * Выходные данные * Для каждого набора входных данных выведите одно целое число — минимальное количество операций, которое * потребуется Василию, чтобы число a стало равно c, а b равно d, или −1, если невозможно добиться равенств, * используя описанные операции. */ public static class ContestSolution extends Solution { void solve() { int c = in.nextInt(); int d = in.nextInt(); if (c == 0 && d == 0) { out.println(0); } else if (Math.abs(c) == Math.abs(d)) { out.println(1); } else if ((c - d) % 2 == 0) { out.println(2); } else { out.println(-1); } } } /** * add `-Xss256m` to increase stack size */ public static void main(String[] args) { boolean local = args.length > 0; // boolean local = false; String input = local ? "codeforces/input.txt" : null; Solution solution = new ContestSolution(); solution.in = new MyScanner(input); solution.out = MyWriter.of(null); solution.bm = new Benchmark(); solution.al = new Algorithm(); solution.run(); solution.out.close(); } public static class Solution { public MyScanner in; public MyWriter out; public Benchmark bm; public Algorithm al; void init() { } void solve() { } boolean isMultiTest() { return true; } void run() { init(); if (isMultiTest()) { int t = in.nextInt(); for (int i = 0; i < t; i++) { solve(); } } else { solve(); } } } public static class Algorithm { public void sort(int[] arr) { List<Integer> tmp = Arrays.stream(arr).boxed().sorted().collect(Collectors.toList()); for (int i = 0; i < arr.length; i++) { arr[i] = tmp.get(i); } } public void sortRev(int[] arr) { List<Integer> tmp = Arrays.stream(arr).boxed().sorted(Comparator.comparing((Integer x) -> x).reversed()) .collect(Collectors.toList()); for (int i = 0; i < arr.length; i++) { arr[i] = tmp.get(i); } } } public static class ModInt { static int MOD = 1000000007; public static final ModInt ZERO = new ModInt(0); public static final ModInt ONE = new ModInt(1); private static final Map<ModInt, ModInt> inverseCache = new HashMap<>(); private final int value; public ModInt(int value) { if (value < 0) { throw new IllegalArgumentException(); } this.value = value; } public ModInt add(ModInt other) { return new ModInt((int) (((long) this.value + other.value) % MOD)); } public ModInt subtract(ModInt other) { return new ModInt((int) (((long) this.value - other.value + MOD) % MOD)); } public ModInt multiply(ModInt other) { return new ModInt((int) (((long) this.value * other.value) % MOD)); } public ModInt pow(int degree) { if (degree == 0) { return ModInt.ONE; } if (degree % 2 == 1) { return this.multiply(pow(degree - 1)); } ModInt tmp = this.pow(degree / 2); return tmp.multiply(tmp); } public ModInt inverse() { ModInt tmp = inverseCache.get(this); if (tmp == null) { tmp = this.pow(MOD - 2); inverseCache.put(this, tmp); } return tmp; } public ModInt divide(ModInt other) { return this.multiply(other.inverse()); } } public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner(String fileName) { if (fileName != null) { try { br = new BufferedReader(new FileReader(fileName)); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } else { br = new BufferedReader(new InputStreamReader(System.in)); } } String next() { while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(nextLine()); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] nextInts(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } boolean[] nextLineBools() { String line = nextLine(); int n = line.length(); boolean[] booleans = new boolean[n]; for (int i = 0; i < n; i++) { booleans[i] = line.charAt(i) == '1'; } return booleans; } char[] nextLineChars() { String line = nextLine(); int n = line.length(); char[] chars = new char[n]; for (int i = 0; i < n; i++) { chars[i] = line.charAt(i); } return chars; } long nextLong() { return Long.parseLong(next()); } public long[] nextLongs(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { try { String line = br.readLine(); if (line == null) { throw new RuntimeException("empty line"); } st = null; return line; } catch (IOException e) { throw new RuntimeException(e); } } } public static class MyWriter extends PrintWriter { public static MyWriter of(String fileName) { if (fileName != null) { try { return new MyWriter(new FileWriter(fileName)); } catch (IOException e) { throw new RuntimeException(e); } } else { return new MyWriter(new BufferedOutputStream(System.out)); } } public MyWriter(FileWriter fileWriter) { super(fileWriter); } public MyWriter(OutputStream out) { super(out); } void println(int[] arr) { String line = Arrays.stream(arr).mapToObj(String::valueOf).collect(Collectors.joining(" ")); println(line); } } public static class Benchmark { long time; public void start() { time = System.currentTimeMillis(); } public long calc() { long curTime = System.currentTimeMillis(); long tmp = curTime - time; time = curTime; return tmp; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
0e9054d3905cdfc383ae477e02489cac
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; import java.io.*; public class avg{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t = sc.nextInt(); for(int k=0;k<t;k++) { int ans=0; int c = sc.nextInt(); int d = sc.nextInt(); if(c==0 && d==0){ ans=0; }else if(c==d){ ans=1; }else if(Math.abs(c-d)%2 == 1){ ans =-1; }else{ ans=2; } System.out.println(ans); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
bf172e4256cff4993e632af86dba28e0
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class AVarietyOfOperations { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t-->0){ long c=in.nextLong(); long d = in.nextLong(); if(c==d){ if(c==0&&d==0) System.out.println(0); else System.out.println(1); } else{ if((c+d)%2!=0) System.out.println(-1); else System.out.println(2); } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
4ef118080839dc6093748dfd4a120033
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t>0){ t--; sc.nextLine(); int c = sc.nextInt(); int d = sc.nextInt(); int diff = Math.abs(c - d); if(c == 0 && d ==0){ System.out.println("0"); } else if(c==d) { System.out.println("1"); } else if(diff%2==1){ System.out.println("-1"); } else{ System.out.println("2"); } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
4896cd7fd42104b34a1fc710164a5d12
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.util.*; public class A { static PrintWriter out = new PrintWriter((System.out)); static Reader sc = new Reader(); public static void main(String args[]) throws IOException { int t = sc.nextInt(); while (t-- > 0) { solve(); } out.close(); } public static void solve() { int c = sc.nextInt(); int d = sc.nextInt(); int a = 0; int b = 0; if (c == 0 && d == 0) { out.println(0); } else if (c == d) { out.println(1); } else if ((c % 2 != 0 && d % 2 != 0) || (c % 2 == 0 && d % 2 == 0)) { out.println(2); } else { out.println(-1); } } static class Reader { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); } return null; } public boolean hasNext() { String next = null; try { next = br.readLine(); } catch (Exception e) { } if (next == null) { return false; } st = new StringTokenizer(next); return true; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
0583ce8486b628f6c0a1899f35251956
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; public class A { static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) {} return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } public static void main(String[] args) { FastScanner s = new FastScanner(); int T = s.nextInt(); for (int i = 0; i < T; i++) { int c = s.nextInt(); int d = s.nextInt(); if (c == 0 && d == 0) { System.out.println(0); } else if (c == d) { System.out.println(1); } else if (Math.abs(c - d) % 2 == 0) { System.out.println(2); } else { System.out.println(-1); } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
80d87489307aa6235c22f7e074b8d827
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.text.DecimalFormat; import java.util.*; public class Codeforces { static String ab,b; static class Node { int val; Node left; Node right; public Node(int x) { // TODO Auto-generated constructor stub this.val=x; this.left=null; this.right=null; } } static class Pair<U, V> implements Comparable<Pair<U, V>> { public U x; public V y; public Pair(U x, V y) { this.x = x; this.y = y; } public int compareTo(Pair<U, V> o) { int value = ((Comparable<U>) x).compareTo(o.x); if (value != 0) return value; return ((Comparable<V>) y).compareTo(o.y); } public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair<?, ?> pair = (Pair<?, ?>) o; return x.equals(pair.x) && y.equals(pair.y); } public int hashCode() { return Objects.hash(x, y); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] nextArray(int n) { int arr[]=new int[n]; for(int i=0;i<n;i++) arr[i]=nextInt(); return arr; } } static String string; static int gcd(int a, int b) { // Everything divides 0 if (a == 0) return b; if (b == 0) return a; // base case if (a == b) return a; // a is greater return gcd(b, a % b); } static long gcd(long a, long b) { // Everything divides 0 for(long i=2;i<=b;i++) { if(a%i==0&&b%i==0) return i; } return 1; } static int fac(int n) { int c=1; for(int i=2;i<n;i++) if(n%i==0) c=i; return c; } static int lcm(int a,int b) { for(int i=Math.min(a, b);i<=a*b;i++) if(i%a==0&&i%b==0) return i; return 0; } static int maxHeight(char[][] ch,int i,int j,String[] arr) { int h=1; if(i==ch.length-1||j==0||j==ch[0].length-1) return 1; while(i+h<ch.length&&j-h>=0&&j+h<ch[0].length&&ch[i+h][j-h]=='*'&&ch[i+h][j+h]=='*') { String whole=arr[i+h]; //System.out.println(whole.substring(j-h,j+h+1)); if(whole.substring(j-h,j+h+1).replace("*","").length()>0) return h; h++; } return h; } static boolean all(BigInteger n) { BigInteger c=n; HashSet<Character> hs=new HashSet<>(); while((c+"").compareTo("0")>0) { String d=""+c; char ch=d.charAt(d.length()-1); if(d.length()==1) { c=new BigInteger("0"); } else c=new BigInteger(d.substring(0,d.length()-1)); if(hs.contains(ch)) continue; if(d.charAt(d.length()-1)=='0') continue; if(!(n.mod(new BigInteger(""+ch)).equals(new BigInteger("0")))) return false; hs.add(ch); } return true; } static int cal(long n,long k) { System.out.println(n+","+k); if(n==k) return 2; if(n<k) return 1; if(k==1) return 1+cal(n, k+1); if(k>=32) return 1+cal(n/k, k); return 1+Math.min(cal(n/k, k),cal(n, k+1)); } static Node buildTree(int i,int j,int[] arr) { if(i==j) { //System.out.print(arr[i]); return new Node(arr[i]); } int max=i; for(int k=i+1;k<=j;k++) { if(arr[max]<arr[k]) max=k; } Node root=new Node(arr[max]); //System.out.print(arr[max]); if(max>i) root.left=buildTree(i, max-1, arr); else { root.left=null; } if(max<j) root.right=buildTree(max+1, j, arr); else { root.right=null; } return root; } static int height(Node root,int val) { if(root==null) return Integer.MAX_VALUE-32; if(root.val==val) return 0; if((root.left==null&&root.right==null)) return Integer.MAX_VALUE-32; return Math.min(height(root.left, val), height(root.right, val))+1; } static void shuffle(int a[], int n) { for (int i = 0; i < n; i++) { // getting the random index int t = (int)Math.random() * a.length; // and swapping values a random index // with the current index int x = a[t]; a[t] = a[i]; a[i] = x; } } static void sort(int[] arr ) { shuffle(arr, arr.length); Arrays.sort(arr); } static int helper(int i,boolean flag,int n,int c,int val,int[][][] dp) { if(i<=0||i>=n+1) { c++; return 1; } int last=flag?1:0; if(dp[i][val][last]!=0) return dp[i][val][last]; int ans=0; if(flag) { ans=helper(i+1, flag, n, c, val,dp); if(val>1) ans+=helper(i-1, !flag, n, c, val-1,dp); } else { ans=helper(i-1, flag, n, c, val,dp); if(val>1) ans+=helper(i+1, !flag, n, c, val-1,dp); } return dp[i][val][last]=ans; } static boolean valid(char[] arr,int k) { int[] count=new int[26]; for(int i=0;i<arr.length;i++) count[(int)arr[i]-'a']++; for(int i=0;i<26;i++) if(count[i]%k!=0) return false; return true; } static int compute(int c,int r) { if(r<c/2) r=c-r; int ans=1; for(int i=c;i>r;i--) ans*=i; int fac=fac(c-r); return ans/fac; } static boolean arraySortedInc(int arr[], int n) { // Array has one or no element if (n == 0 || n == 1) return true; for (int i = 1; i < n; i++) // Unsorted pair found if (arr[i - 1] > arr[i]) return false; // No unsorted pair found return true; } static boolean arraySortedDec(int arr[], int n) { // Array has one or no element if (n == 0 || n == 1) return true; for (int i = 1; i < n; i++) // Unsorted pair found if (arr[i - 1] > arr[i]) return false; // No unsorted pair found return true; } static int largestPower(int n, int p) { // Initialize result int x = 0; // Calculate x = n/p + n/(p^2) + n/(p^3) + .... while (n > 0) { n /= p; x += n; } return x; } // Utility function to do modular exponentiation. // It returns (x^y) % p static int power(int x, int y, int p) { int res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p while (y > 0) { // If y is odd, multiply x with result if (y % 2 == 1) { res = (res * x) % p; } // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } // Returns n! % p static int modFact(int n, int p) { if (n >= p) { return 0; } int res = 1; // Use Sieve of Eratosthenes to find all primes // smaller than n boolean isPrime[] = new boolean[n + 1]; Arrays.fill(isPrime, true); for (int i = 2; i * i <= n; i++) { if (isPrime[i]) { for (int j = 2 * i; j <= n; j += i) { isPrime[j] = false; } } } // Consider all primes found by Sieve for (int i = 2; i <= n; i++) { if (isPrime[i]) { // Find the largest power of prime 'i' that divides n int k = largestPower(n, i); // Multiply result with (i^k) % p res = (res * power(i, k, p)) % p; } } return res; } static boolean helper(int[][] all,int row,int[] count) { // System.out.println(new String(arr)+","+i+","+a+","+b); if(row==all.length) return true; // System.out.println(all[row][row]); // for(int i=0;i<all.length;i++) // System.out.println(Arrays.toString(all[i])); // System.out.println(); // System.out.println(); if(count[all[row][row]]==all[row][row]) return helper(all, row+1, count); else { for(int i=0;i<all.length;i++) { for(int j=0;j<=i;j++) { if(all[i][j]==all[row][row]) { // System.out.println(row+","+i+","+j); if(j>0&&all[i][j-1]==0) { all[i][j-1]=all[row][row]; count[all[row][row]]++; if(helper(all, row, count)) return true; else { all[i][j-1]=0; count[all[row][row]]--; } } if(j<i&&all[i][j+1]==0) { all[i][j+1]=all[row][row]; count[all[row][row]]++; if(helper(all, row, count)) return true; else { all[i][j+1]=0; count[all[row][row]]--; } } if(i<all.length-1&&all[i+1][j]==0) { all[i+1][j]=all[row][row]; count[all[row][row]]++; if(helper(all, row, count)) return true; else { all[i+1][j]=0; count[all[row][row]]--; } } if(i>0&&j!=i&&all[i-1][j]==0) { all[i-1][j]=all[row][row]; count[all[row][row]]++; if(helper(all, row, count)) return true; else { all[i-1][j]=0; count[all[row][row]]--; } } } } } return false; } } static List<Integer> helper(List<Integer> list) { int sum=0; for(int i:list) sum+=i; sum/=list.size(); boolean in=false; List<Integer> temp=new ArrayList<>(list); for(Integer i:list) { if(i>sum) { in=true; temp.remove(i); } } if(temp.equals(list)) return temp; return helper(temp); } static int helper(char[] arr,boolean reversed,int alice,int bob,int c) { int in=-1,count=0,st=-1; for(int i=0;i<=arr.length/2;i++) { if(arr[i]=='0'&&arr[arr.length-1-i]=='1') { in=i; break; } else if(arr[i]=='1'&&arr[arr.length-1-i]=='0') { in=arr.length-1-i; break; } if(arr[i]=='0') { if(st==-1) st=i; count++; } if(arr[arr.length-i-1]=='0') { if(st==-1) st=arr.length-1-i; count++; } } System.out.println(in); if(count==0) { return alice-bob; } else if(arr.length%2!=0&&arr[arr.length/2]=='0') { arr[arr.length/2]='1'; return helper(arr, false, alice, bob, count); } if(in==-1||reversed) { arr[st]='1'; if(c%2==0) return helper(arr, false, alice+1, bob, c+1); else { return helper(arr, false, alice, bob+1, c+1); } } else { arr[in]='1'; return helper(arr, true, alice, bob, c+1); } } static boolean[] seiveOfErathnos(int n2) { boolean isPrime[] = new boolean[n2 + 1]; Arrays.fill(isPrime, true); for (int i = 2; i * i <= n2; i++) { if (isPrime[i]) { for (int j = 2 * i; j <= n2; j += i) { isPrime[j] = false; } } } return isPrime; } static boolean[] seiveOfErathnos2(int n2,int[] ans) { boolean isPrime[] = new boolean[n2 + 1]; Arrays.fill(isPrime, true); for (int i = 2; i * i <= n2; i++) { if (isPrime[i]) { for (int j = 2 * i; j <= n2; j += i) { if(isPrime[j]) ans[i]++; isPrime[j] = false; } } } return isPrime; } static int calculatePower(PriorityQueue<Integer>[] list,int[] alive) { // List<Integer> dead=new ArrayList<>(); for(int i=1;i<alive.length;i++) { if(alive[i]==1) { if(list[i].size()==0) { continue; } if(list[i].peek()>i) { // dead.add(i); // System.out.println(i); alive[i]=0; for(int j:list[i]) { // list[i].remove((Integer)j); list[j].remove((Integer)i); } list[i].clear(); return 1+calculatePower(list,alive); } } } return 0; } static boolean helper(int i,int j,int[] index,int k,HashMap<String,String> hm) { // System.out.println(i+","+j); if(k<=0) return false; if(i==j) return true; String key=i+","+j; if(hm.containsKey(key)) { String[] all=hm.get(key).split(","); int prev=Integer.parseInt(all[0]); // String val=Integer.parseInt(all[1]); if(prev==k) return all[1].equals("true")?true:false; else if(prev>k&&all[1].equals("false")) return false; else if(prev<k&&all[1].equals("true")) return true; } if(i+1==j) { if(index[i]+1==index[j]||k>=2) return true; return false; } boolean flag=false; for(int p=i;p<j;p++) { if(index[p]+1!=index[p+1]) { flag=true; break; } } if(!flag) { hm.put(key,k+","+ true); return true; } if(k==1) { hm.put(key,k+","+ false); return false; } for(int p=i;p<j;p++) { if(helper(i,p,index,k-1,hm)&&helper(p+1,j,index,k-1,hm)) { hm.put(key,k+","+ true); return true; } } hm.put(key, k+","+false); return false; } public static void main(String[] args)throws IOException { BufferedReader bReader=new BufferedReader(new InputStreamReader(System.in)); FastReader fs=new FastReader(); // int[] ans=new int[1000001]; int T=fs.nextInt(); // seiveOfErathnos2(1000000, ans); StringBuilder sb=new StringBuilder(); while(T-->0) { int a=fs.nextInt(),b=fs.nextInt(); int diff=(int)Math.abs(a-b); if(diff==0) { if(a==0) sb.append(0); else { sb.append(1); } } else if(diff%2==0) sb.append(2); else sb.append(-1); sb.append("\n"); } System.out.println(sb); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
d12eceb95c6ae8b02644eda3922699ba
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.OutputStream; import java.io.Writer; import java.io.IOException; import java.util.InputMismatchException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Nipuna Samarasekara */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScanner in = new FastScanner(inputStream); FastPrinter out = new FastPrinter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, FastScanner in, FastPrinter out) { int t = in.nextInt(); while (t-- > 0) { int c = in.nextInt(), d = in.nextInt(); int ans = -1; if (c == 0 && d == 0) { ans = 0; } else if (c == d) { ans = 1; } else if (c % 2 == d % 2) { ans = 2; } out.println(ans); } } } static class FastPrinter extends PrintWriter { public FastPrinter(OutputStream out) { super(out); } public FastPrinter(Writer out) { super(out); } } static class FastScanner extends BufferedReader { public FastScanner(InputStream is) { super(new InputStreamReader(is)); } public int read() { try { int ret = super.read(); // if (isEOF && ret < 0) { // throw new InputMismatchException(); // } // isEOF = ret == -1; return ret; } catch (IOException e) { throw new InputMismatchException(); } } static boolean isWhiteSpace(int c) { return c >= 0 && c <= 32; } public int nextInt() { int c = read(); while (isWhiteSpace(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int ret = 0; while (c >= 0 && !isWhiteSpace(c)) { if (c < '0' || c > '9') { throw new NumberFormatException("digit expected " + (char) c + " found"); } ret = ret * 10 + c - '0'; c = read(); } return ret * sgn; } public String readLine() { try { return super.readLine(); } catch (IOException e) { return null; } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
17797f99f8ca569d9d65291508e7fe76
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; import java.io.*; public class Main{ static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || !st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str=""; try { str=br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object) throws IOException { bw.append("" + object); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } public static void main(String[] args) { try { FastReader in=new FastReader(); FastWriter out = new FastWriter(); int testCases=in.nextInt(); while(testCases-- > 0){ // write code here int c = in.nextInt(); int d = in.nextInt(); if (Math.abs(c-d)%2!=0) out.println(-1); else if(c==0 && d==0) out.println(0); else if(c==d) out.println(1); else out.println(2); } out.close(); } catch (Exception e) { return; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
1ab1fc8c9acf11d79c05abd28309ada4
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class AVarietyOfOperations { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=0;i<n;i++){ int a=sc.nextInt(); int b=sc.nextInt(); System.out.println(solve(a,b)); } } static int solve(int a, int b){ if(a==0 && b==0){ return 0; } if(a==b){ return 1; } else if((a+b)%2==1){ return -1; }else if((a+b)%2==0){ return 2; }else{ return 1; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
524b2e8c733211cb6f7bdaf2ef664c61
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int tc = sc.nextInt(); while(tc-- != 0) { long a = sc.nextLong(); long b = sc.nextLong(); if (a == 0 && b == 0) { System.out.println(0); } else if(a == b) { System.out.println(1); } else if(Math.abs(a - b) % 2 == 0) { System.out.println(2); } else { System.out.println(-1); } } sc.close(); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
8c7bc20ea879447384e1e998bf44f043
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; import static java.lang.Math.*; import java.io.*; public class Exercise { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int testcases = sc.nextInt(); while(testcases-- != 0) { int c = sc.nextInt(); int d = sc.nextInt(); int diference = Math.max(c, d) - Math.min(c, d); if(c == 0 && d == 0) { System.out.println(0); }else if(c == d) { System.out.println(1); } else if(diference % 2 == 0) { System.out.println(2); } else if(diference % 2 == 1) { System.out.println(-1); } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
4fe0e9f741d781bddd780e098d085e6d
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import static java.lang.Math.*; import static java.lang.System.out; import java.util.*; import java.io.File; import java.io.PrintStream; import java.io.PrintWriter; import java.math.BigInteger; public class Main { /* 10^(7) = 1s. * ceilVal = (a+b-1) / b */ static final int mod = 1000000007; static final long temp = 998244353; static final long MOD = 1000000007; static final long M = (long)1e9+7; static class Pair implements Comparable<Pair> { int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair ob) { return (int)(first - ob.first); } } static class Tuple implements Comparable<Tuple> { int first, second,third; public Tuple(int first, int second, int third) { this.first = first; this.second = second; this.third = third; } public int compareTo(Tuple o) { return (int)(o.third - this.third); } } public static class DSU { int[] parent; int[] rank; //Size of the trees is used as the rank public DSU(int n) { parent = new int[n]; rank = new int[n]; Arrays.fill(parent, -1); Arrays.fill(rank, 1); } public int find(int i) //finding through path compression { return parent[i] < 0 ? i : (parent[i] = find(parent[i])); } public boolean union(int a, int b) //Union Find by Rank { a = find(a); b = find(b); if(a == b) return false; //if they are already connected we exit by returning false. // if a's parent is less than b's parent if(rank[a] < rank[b]) { //then move a under b parent[a] = b; } //else if rank of j's parent is less than i's parent else if(rank[a] > rank[b]) { //then move b under a parent[b] = a; } //if both have the same rank. else { //move a under b (it doesnt matter if its the other way around. parent[b] = a; rank[a] = 1 + rank[a]; } return true; } } static class Reader { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) throws IOException { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] longReadArray(int n) throws IOException { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } public static int gcd(int a, int b) { if(b == 0) return a; else return gcd(b,a%b); } public static long lcm(long a, long b) { return (a / LongGCD(a, b)) * b; } public static long LongGCD(long a, long b) { if(b == 0) return a; else return LongGCD(b,a%b); } public static long LongLCM(long a, long b) { return (a / LongGCD(a, b)) * b; } //Count the number of coprime's upto N public static long phi(long n) //euler totient/phi function { long ans = n; // for(long i = 2;i*i<=n;i++) // { // if(n%i == 0) // { // while(n%i == 0) n/=i; // ans -= (ans/i); // } // } // // if(n > 1) // { // ans -= (ans/n); // } for(long i = 2;i<=n;i++) { if(isPrime(i)) { ans -= (ans/i); } } return ans; } public static long fastPow(long x, long n) { if(n == 0) return 1; else if(n%2 == 0) return fastPow(x*x,n/2); else return x*fastPow(x*x,(n-1)/2); } public static long modPow(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static long modInverse(long n, long p) { return modPow(n, p - 2, p); } // Returns nCr % p using Fermat's little theorem. public static long nCrModP(long n, long r,long p) { if (n<r) return 0; if (r == 0) return 1; long[] fac = new long[(int)(n) + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; return (fac[(int)(n)] * modInverse(fac[(int)(r)], p) % p * modInverse(fac[(int)(n - r)], p) % p) % p; } public static long fact(long n) { long[] fac = new long[(int)(n) + 1]; fac[0] = 1; for (long i = 1; i <= n; i++) fac[(int)(i)] = fac[(int)(i - 1)] * i; return fac[(int)(n)]; } public static long nCr(long n, long k) { long ans = 1; for(long i = 0;i<k;i++) { ans *= (n-i); ans /= (i+1); } return ans; } //Modular Operations for Addition and Multiplication. public static long perfomMod(long x) { return ((x%M + M)%M); } public static long addMod(long a, long b) { return perfomMod(perfomMod(a)+perfomMod(b)); } public static long subMod(long a, long b) { return perfomMod(perfomMod(a)-perfomMod(b)); } public static long mulMod(long a, long b) { return perfomMod(perfomMod(a)*perfomMod(b)); } public static boolean isPrime(long n) { if(n == 1) { return false; } //check only for sqrt of the number as the divisors //keep repeating so only half of them are required. So,sqrt. for(int i = 2;i*i<=n;i++) { if(n%i == 0) { return false; } } return true; } public static List<Long> SieveList(int n) { boolean prime[] = new boolean[(int)(n+1)]; Arrays.fill(prime, true); List<Long> l = new ArrayList<>(); for (long p = 2; p*p<=n; p++) { if (prime[(int)(p)] == true) { for(long i = p*p; i<=n; i += p) { prime[(int)(i)] = false; } } } for (long p = 2; p<=n; p++) { if (prime[(int)(p)] == true) { l.add(p); } } return l; } public static long log2(long n) { long ans = (long)(log(n)/log(2)); return ans; } public static boolean isPow2(long n) { return (n != 0 && ((n & (n-1))) == 0); } public static boolean isSq(int x) { long s = (long)Math.round(Math.sqrt(x)); return s*s==x; } /* * * >= <= 0 1 2 3 4 5 6 7 5 5 5 6 6 6 7 7 lower_bound for 6 at index 3 (>=) upper_bound for 6 at index 6(To get six reduce by one) (<=) */ public static int LowerBound(long a[], long x) { int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r; } public static int UpperBound(long a[], long x) { int l=-1, r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } public static void Sort(long[] a) { List<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); // Collections.reverse(l); //Use to Sort decreasingly for (int i=0; i<a.length; i++) a[i]=l.get(i); } public static void ssort(char[] a) { List<Character> l = new ArrayList<>(); for (char i : a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } public static void main(String[] args) throws Exception { Reader sc = new Reader(); PrintWriter fout = new PrintWriter(System.out); int t = sc.nextInt(); while(t-- > 0) { long x = sc.nextLong(), y = sc.nextLong(); if(x%2 != y%2) { fout.println(-1); } else if(x == 0 && y == 0) { fout.println(0); } else if(x == y) { fout.println(1); } else { fout.println(2); } } fout.close(); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
f4acaa7190735da89578e08061531662
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import static java.lang.Math.*; import static java.lang.System.out; import java.util.*; import java.io.File; import java.io.PrintStream; import java.io.PrintWriter; import java.math.BigInteger; public class Main { /* 10^(7) = 1s. * ceilVal = (a+b-1) / b */ static final int mod = 1000000007; static final long temp = 998244353; static final long MOD = 1000000007; static final long M = (long)1e9+7; static class Pair implements Comparable<Pair> { int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair ob) { return (int)(first - ob.first); } } static class Tuple implements Comparable<Tuple> { int first, second,third; public Tuple(int first, int second, int third) { this.first = first; this.second = second; this.third = third; } public int compareTo(Tuple o) { return (int)(o.third - this.third); } } public static class DSU { int[] parent; int[] rank; //Size of the trees is used as the rank public DSU(int n) { parent = new int[n]; rank = new int[n]; Arrays.fill(parent, -1); Arrays.fill(rank, 1); } public int find(int i) //finding through path compression { return parent[i] < 0 ? i : (parent[i] = find(parent[i])); } public boolean union(int a, int b) //Union Find by Rank { a = find(a); b = find(b); if(a == b) return false; //if they are already connected we exit by returning false. // if a's parent is less than b's parent if(rank[a] < rank[b]) { //then move a under b parent[a] = b; } //else if rank of j's parent is less than i's parent else if(rank[a] > rank[b]) { //then move b under a parent[b] = a; } //if both have the same rank. else { //move a under b (it doesnt matter if its the other way around. parent[b] = a; rank[a] = 1 + rank[a]; } return true; } } static class Reader { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) throws IOException { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] longReadArray(int n) throws IOException { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } public static int gcd(int a, int b) { if(b == 0) return a; else return gcd(b,a%b); } public static long lcm(long a, long b) { return (a / LongGCD(a, b)) * b; } public static long LongGCD(long a, long b) { if(b == 0) return a; else return LongGCD(b,a%b); } public static long LongLCM(long a, long b) { return (a / LongGCD(a, b)) * b; } //Count the number of coprime's upto N public static long phi(long n) //euler totient/phi function { long ans = n; // for(long i = 2;i*i<=n;i++) // { // if(n%i == 0) // { // while(n%i == 0) n/=i; // ans -= (ans/i); // } // } // // if(n > 1) // { // ans -= (ans/n); // } for(long i = 2;i<=n;i++) { if(isPrime(i)) { ans -= (ans/i); } } return ans; } public static long fastPow(long x, long n) { if(n == 0) return 1; else if(n%2 == 0) return fastPow(x*x,n/2); else return x*fastPow(x*x,(n-1)/2); } public static long modPow(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static long modInverse(long n, long p) { return modPow(n, p - 2, p); } // Returns nCr % p using Fermat's little theorem. public static long nCrModP(long n, long r,long p) { if (n<r) return 0; if (r == 0) return 1; long[] fac = new long[(int)(n) + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; return (fac[(int)(n)] * modInverse(fac[(int)(r)], p) % p * modInverse(fac[(int)(n - r)], p) % p) % p; } public static long fact(long n) { long[] fac = new long[(int)(n) + 1]; fac[0] = 1; for (long i = 1; i <= n; i++) fac[(int)(i)] = fac[(int)(i - 1)] * i; return fac[(int)(n)]; } public static long nCr(long n, long k) { long ans = 1; for(long i = 0;i<k;i++) { ans *= (n-i); ans /= (i+1); } return ans; } //Modular Operations for Addition and Multiplication. public static long perfomMod(long x) { return ((x%M + M)%M); } public static long addMod(long a, long b) { return perfomMod(perfomMod(a)+perfomMod(b)); } public static long subMod(long a, long b) { return perfomMod(perfomMod(a)-perfomMod(b)); } public static long mulMod(long a, long b) { return perfomMod(perfomMod(a)*perfomMod(b)); } public static boolean isPrime(long n) { if(n == 1) { return false; } //check only for sqrt of the number as the divisors //keep repeating so only half of them are required. So,sqrt. for(int i = 2;i*i<=n;i++) { if(n%i == 0) { return false; } } return true; } public static List<Long> SieveList(int n) { boolean prime[] = new boolean[(int)(n+1)]; Arrays.fill(prime, true); List<Long> l = new ArrayList<>(); for (long p = 2; p*p<=n; p++) { if (prime[(int)(p)] == true) { for(long i = p*p; i<=n; i += p) { prime[(int)(i)] = false; } } } for (long p = 2; p<=n; p++) { if (prime[(int)(p)] == true) { l.add(p); } } return l; } public static long log2(long n) { long ans = (long)(log(n)/log(2)); return ans; } public static boolean isPow2(long n) { return (n != 0 && ((n & (n-1))) == 0); } public static boolean isSq(int x) { long s = (long)Math.round(Math.sqrt(x)); return s*s==x; } /* * * >= <= 0 1 2 3 4 5 6 7 5 5 5 6 6 6 7 7 lower_bound for 6 at index 3 (>=) upper_bound for 6 at index 6(To get six reduce by one) (<=) */ public static int LowerBound(long a[], long x) { int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r; } public static int UpperBound(long a[], long x) { int l=-1, r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } public static void Sort(long[] a) { List<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); // Collections.reverse(l); //Use to Sort decreasingly for (int i=0; i<a.length; i++) a[i]=l.get(i); } public static void ssort(char[] a) { List<Character> l = new ArrayList<>(); for (char i : a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } public static boolean check(long[] a) { int n = a.length; for(int i = 0;i<n-1;i++) { if(a[i] > a[i+1]) return false; } return true; } public static void main(String[] args) throws Exception { Reader sc = new Reader(); PrintWriter fout = new PrintWriter(System.out); int t = sc.nextInt(); while(t-- > 0) { long a = sc.nextLong(), b = sc.nextLong(); if(a%2 != b%2) { fout.println(-1); } else { fout.println((a == 0 && b == 0) ? 0 : (a == b ? 1 : 2)); } } fout.close(); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
0f1fc57d66393698ee00ad88c860f77f
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; public class prg { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int a=sc.nextInt(); int b=sc.nextInt(); if(a==0 && b==0) System.out.println(0); else if(a==b) System.out.println(1); else if(Math.abs(a-b)%2==0) System.out.println(2); else System.out.println(-1); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
261bdb71a39f606de1e5f77675d625dd
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.PriorityQueue; import java.util.Map.Entry; import java.util.Random; import java.util.TreeSet; public final class CF_Detix_2021_Summer_A { static boolean verb=true; static void log(Object X){if (verb) System.err.println(X);} static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}} static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}} static void logWln(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");}} static void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+" ");System.err.println("");}} static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}} static void logWln(Object X){if (verb) System.err.print(X);} static void info(Object o){ System.out.println(o);} static void output(Object o){outputWln(""+o+"\n"); } static void outputFlush(Object o){try {out.write(""+ o+"\n");out.flush();} catch (Exception e) {}} static void outputWln(Object o){try {out.write(""+ o);} catch (Exception e) {}} static void logBin(int[] tm) {for (int x:tm) logWln(bin(8,x)+" ");log("");} static String bin(int L,int x) { String s=Integer.toBinaryString(x); while (s.length()<L) s="0"+s; return s; } static long powerMod(long b,long e,long m){ long x=1; while (e>0) { if (e%2==1) x=(b*x)%m; b=(b*b)%m; e=e/2; } return x; } static long mod=1000000007; // Global vars static BufferedWriter out; static InputReader reader; static int pgcd(int a,int b){ if (a<b) return pgcd(b,a); while (b!=0){ int c=b; b=a%b; a=c; } return a; } static int PX=Integer.MAX_VALUE; static int NX=Integer.MIN_VALUE; static void process() throws Exception { out = new BufferedWriter(new OutputStreamWriter(System.out)); reader = new InputReader(System.in); int T=reader.readInt(); for (int t=0;t<T;t++) { long c=reader.readLong(); long d=reader.readLong(); int ans=-1; if ((c+d)>=0 && (c-d)%2==0) { ans=0; if (c!=d) ans++; if ((c+d)!=0) ans++; } output(ans); } try { out.close(); } catch (Exception Ex) { } } public static void main(String[] args) throws Exception { process(); } static final class InputReader { private final InputStream stream; private final byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } private int read() throws IOException { if (curChar >= numChars) { curChar = 0; numChars = stream.read(buf); if (numChars <= 0) { return -1; } } return buf[curChar++]; } public final String readString() throws IOException { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.append((char) c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public final String readString(int L) throws IOException { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(L); do { res.append((char) c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public final int readInt() throws IOException { int c = read(); boolean neg = false; while (isSpaceChar(c)) { c = read(); } char d = (char) c; // log("d:"+d); if (d == '-') { neg = true; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); // log("res:"+res); if (neg) return -res; return res; } public final long readLong() throws IOException { int c = read(); boolean neg = false; while (isSpaceChar(c)) { c = read(); } char d = (char) c; // log("d:"+d); if (d == '-') { neg = true; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); // log("res:"+res); if (neg) return -res; return res; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
b69e2e8fef4944551aeb487842ac581a
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String... args) throws IOException { BufferedReader inf=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer sc=new StringTokenizer(inf.readLine()); int t,c,d; //scanf("%d",&t); t=Integer.parseInt(sc.nextToken()); while((t--)>0) { sc=new StringTokenizer(inf.readLine()); c=Integer.parseInt(sc.nextToken()); d=Integer.parseInt(sc.nextToken()); //scanf("%d%d",&c,&d); if(c==d) { if(c==0) System.out.printf("0\n"); else System.out.printf("1\n"); } else { int z=(c+d)/2; //if((c==0)||(d==0)) printf("2\n"); if(Math.abs(z-c)==Math.abs(z-d)) System.out.printf("2\n"); else System.out.printf("-1\n"); } } //return 0; } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
9b58b913a0227bec115a7fdb3910b1c3
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Scanner; import java.util.StringTokenizer; import static java.lang.System.out; public class RoundDelticA { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int i = 0; i < t; i++) { int c = sc.nextInt(); int d = sc.nextInt(); if(c==d && c==0){ out.println(0); } else if(c == d){ out.println(1); } else if(Math.abs(c-d) % 2 != 0){ out.println(-1); } else{ out.println(2); } } } private static int solution(int[] arr) { if(arr.length == 1){ return 0; } int odd = 0, even = 0; for (int i = 0; i < arr.length; i++) { if(arr[i] % 2 == 0){ ++even; } else { ++odd; } } if(Math.abs(odd - even) > 1){ return -1; } int count = 0; boolean evenFlag = arr[0] % 2 == 0; int i = 0; while (i < arr.length - 1){ if(evenFlag){ for (int j = 0; j < arr.length; j++) { } } } return count; } static int segregateEvenOdd(int arr[]) { /* Initialize left and right indexes */ int left = 0, right = arr.length - 1; int count = 0; while (left < right) { /* Increment left index while we see 0 at left */ while (arr[left]%2 == 0 && left < right) left++; /* Decrement right index while we see 1 at right */ while (arr[right]%2 == 1 && left < right) right--; if (left < right) { /* Swap arr[left] and arr[right]*/ int temp = arr[left]; arr[left] = arr[right]; arr[right] = temp; left++; right--; count++; } } return count; } private static void swap(int[] arr, int i, int j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception { int[] arr = new int[N]; st = new StringTokenizer(infile.readLine()); for(int i=0; i < N; i++) arr[i] = Integer.parseInt(st.nextToken()); return arr; } public static void print(int[] arr) { //for debugging only for(int x: arr) out.print(x+" "); out.println(); } public static long[] readArr2(int N, BufferedReader infile, StringTokenizer st) throws Exception { long[] arr = new long[N]; st = new StringTokenizer(infile.readLine()); for(int i=0; i < N; i++) arr[i] = Long.parseLong(st.nextToken()); return arr; } public static boolean isPrime(long n) { if(n < 2) return false; if(n == 2 || n == 3) return true; if(n%2 == 0 || n%3 == 0) return false; long sqrtN = (long)Math.sqrt(n)+1; for(long i = 6L; i <= sqrtN; i += 6) { if(n%(i-1) == 0 || n%(i+1) == 0) return false; } return true; } public static long gcd(long a, long b) { if(a > b) a = (a+b)-(b=a); if(a == 0L) return b; return gcd(b%a, a); } public static int lcm(int a, int b) { return (a * b) / lcm(a, b); } public static String sort(String s){ char[] c = s.toCharArray(); Arrays.sort(c); return new String(c); } static String deleteIth(String str, int i) { str = str.substring(0, i) + str.substring(i + 1); return str; } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
32eb35fe83215a92764a46f078aabbcf
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Scanner; import java.util.StringTokenizer; import static java.lang.System.out; public class RoundDelticA { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int i = 0; i < t; i++) { int c = sc.nextInt(); int d = sc.nextInt(); if(c==d && c!=0){ out.println(1); } else if(c==d && c==0){ out.println(0); } else if((c+d)%2==0){ out.println(2); } else{ out.println(-1); } } } private static int solution(int[] arr) { if(arr.length == 1){ return 0; } int odd = 0, even = 0; for (int i = 0; i < arr.length; i++) { if(arr[i] % 2 == 0){ ++even; } else { ++odd; } } if(Math.abs(odd - even) > 1){ return -1; } int count = 0; boolean evenFlag = arr[0] % 2 == 0; int i = 0; while (i < arr.length - 1){ if(evenFlag){ for (int j = 0; j < arr.length; j++) { } } } return count; } static int segregateEvenOdd(int arr[]) { /* Initialize left and right indexes */ int left = 0, right = arr.length - 1; int count = 0; while (left < right) { /* Increment left index while we see 0 at left */ while (arr[left]%2 == 0 && left < right) left++; /* Decrement right index while we see 1 at right */ while (arr[right]%2 == 1 && left < right) right--; if (left < right) { /* Swap arr[left] and arr[right]*/ int temp = arr[left]; arr[left] = arr[right]; arr[right] = temp; left++; right--; count++; } } return count; } private static void swap(int[] arr, int i, int j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception { int[] arr = new int[N]; st = new StringTokenizer(infile.readLine()); for(int i=0; i < N; i++) arr[i] = Integer.parseInt(st.nextToken()); return arr; } public static void print(int[] arr) { //for debugging only for(int x: arr) out.print(x+" "); out.println(); } public static long[] readArr2(int N, BufferedReader infile, StringTokenizer st) throws Exception { long[] arr = new long[N]; st = new StringTokenizer(infile.readLine()); for(int i=0; i < N; i++) arr[i] = Long.parseLong(st.nextToken()); return arr; } public static boolean isPrime(long n) { if(n < 2) return false; if(n == 2 || n == 3) return true; if(n%2 == 0 || n%3 == 0) return false; long sqrtN = (long)Math.sqrt(n)+1; for(long i = 6L; i <= sqrtN; i += 6) { if(n%(i-1) == 0 || n%(i+1) == 0) return false; } return true; } public static long gcd(long a, long b) { if(a > b) a = (a+b)-(b=a); if(a == 0L) return b; return gcd(b%a, a); } public static int lcm(int a, int b) { return (a * b) / lcm(a, b); } public static String sort(String s){ char[] c = s.toCharArray(); Arrays.sort(c); return new String(c); } static String deleteIth(String str, int i) { str = str.substring(0, i) + str.substring(i + 1); return str; } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
ea597717f4f8560dce9ddcbb8b0a62a8
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; import java.io.*; public class ferrisWheel { static Scanner sc=new Scanner(System.in); static PrintWriter pw=new PrintWriter(System.out); public static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a%b); } static LinkedList<Character> ll1,ll2; public static void main(String[] args) throws IOException, InterruptedException { int t=sc.nextInt(); while(t-->0) { int a=sc.nextInt(),b=sc.nextInt(); if(Math.abs(a-b)%2==1) pw.println(-1); else if(a==b && a==0) pw.println(0); else if(a==b) pw.println(1); else { pw.println(2); } } pw.flush(); } static class pair{ int x; int y; public pair(int a,int b) { this.x=a;this.y=b; } public void swap(pair p) { pair temp=new pair(p.x, p.y); p.x=this.x;p.y=this.y; this.x=temp.x;this.y=temp.y; } public String toString () { return x+","+y+" "; } public boolean equals(pair p) { if(x==p.x && y==p.y) return true; return false; } } static class PairPoint{ pair p1; pair p2; public PairPoint(pair p1,pair p2) { this.p1=p1; this.p2=p2; } public boolean inter(pair p) { if((p.x>=p1.x && p.x<=p2.x) && (p.y>=p1.y && p.y<=p2.y)) return true; else if((p.x>=p2.x && p.x<=p1.x) && (p.y>=p2.y && p.y<=p1.y)) return true; return false; } public void swap(PairPoint pp) { pp.p1.swap(this.p1); pp.p2.swap(this.p2); } public String toString () { return p1.toString()+p2.toString(); } public boolean equals (PairPoint pp) { if(p1.equals(pp.p1) && p2.equals(pp.p2)) return true; return false; } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
4f6003d8826028f27d308ac833c5a7bd
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class A_A_Variety_of_Operations { static Scanner in=new Scanner(); static PrintWriter out=new PrintWriter( new OutputStreamWriter(System.out) ); static int testCases; static long c,d; static void solve(){ if(c==d && c!=0){ out.println(1); out.flush(); }else if(c==d && c==0 ){ out.println(0); out.flush(); }else if( (c+d)%2==0 ){ out.println(2); out.flush(); }else{ out.println(-1); out.flush(); } } public static void main(String[] amit) throws IOException { testCases=in.nextInt(); for(int t=0;t<testCases;t++){ c=in.nextLong(); d=in.nextLong(); solve(); } in.close(); } static class Scanner{ BufferedReader in; StringTokenizer st; public Scanner() { in=new BufferedReader( new InputStreamReader(System.in) ); } String next() throws IOException{ while(st==null || !st.hasMoreElements()){ st=new StringTokenizer(in.readLine()); } return st.nextToken(); } int nextInt() throws IOException{ return Integer.parseInt(next()); } long nextLong() throws IOException{ return Long.parseLong(next()); } String nextLine() throws IOException{ return in.readLine(); } char nextChar() throws IOException{ return next().charAt(0); } double nextDouble() throws IOException{ return Double.parseDouble(next()); } float nextFloat() throws IOException{ return Float.parseFloat(next()); } boolean nextBoolean() throws IOException{ return Boolean.parseBoolean(next()); } void close() throws IOException{ in.close(); } } } /* 6 1 2 3 5 5 3 6 6 8 0 0 0 */
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
c46e776f1bd42840c4989ac40740a1d4
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); while(t>0){ long c = scan.nextLong(); long d = scan.nextLong(); if(c == d && c == 0) System.out.println("0"); else if(c == d) System.out.println("1"); else if(Math.abs(c - d)%2 == 0) System.out.println("2"); else System.out.println("-1"); t--; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
e1dec9a195216ec3a9c5bd3fde247908
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; public class Q1{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = Integer.parseInt(sc.nextLine()); while(t--!=0){ String input = sc.nextLine(); String[] in = input.split(" ",2); int c = Integer.parseInt(in[0]); int d = Integer.parseInt(in[1]); int count=2; if(c==0 && d==0){ count=0; } else if(c==d){ count=1; } else if((c+d)%2!=0){ count=-1; } System.out.println(count); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
010a4abb3273f82e06bdc2074060ee83
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class MochaAndMath { static class FastReader { BufferedReader bf; StringTokenizer st; public FastReader() { bf = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(bf.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } float nextFloat() { return Float.parseFloat(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = bf.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader sc = new FastReader(); int t = sc.nextInt(); for (int l = 0; l < t; l++) { // int n = sc.nextInt(); // int ans = sc.nextInt(); // for (int i = 1; i < n; i++) // ans = ans & sc.nextInt(); // System.out.println(ans); // int k = sc.nextInt(); // int c = 1; // int ans = 0; // for (int i = 0; i < k; ) { // if (c % 10 == 3 || c % 3 == 0) { // c++; // } else { // i++; // ans = c; // c++; // } // } // System.out.println(ans); // B. Who's Opposite? // int a = sc.nextInt(); // int b = sc.nextInt(); // int c = sc.nextInt(); // // int diff = Math.abs(a - b) - 1; // int total = 2 + diff * 2; // // if (a > total || b > total || c > total) // System.out.println("-1"); // else { // int tar1 = c - diff - 1; // int tar2 = c + diff + 1; // // if (tar1 >= 1) // System.out.println(tar1); // else if (tar2 <= total) // System.out.println(tar2); // else // System.out.println("-1"); // } // C. Infinity Table // int k = sc.nextInt(); // int n = (int) Math.ceil(Math.sqrt(k)); // // int diff = n * n - k; // if (diff < n) // System.out.println(n + " " + (diff + 1)); // else // System.out.println((2 * n - diff - 1) + " " + n); // D. Make a Power of Two // long[] pow = new long[60]; // for (int i = 0; i < 60; i++) // pow[i] = (long) Math.pow(2, i); // // int n = sc.nextInt(); // String s = String.valueOf(n); // int[] a = new int[s.length()]; // int min = Integer.MAX_VALUE; // for (int i = 0; i < pow.length; i++) // min = Math.min(min, compare(s, pow[i])); int c = sc.nextInt(); int d = sc.nextInt(); if (c == 0 && c == d) System.out.println("0"); else if (c == d) System.out.println("1"); else if (Math.abs(c - d) % 2 != 0) System.out.println("-1"); else System.out.println("2"); } } // // private static int compare(String s1, long l) { // String s2 = String.valueOf(l); // int i = 0, j = 0; // while (s1.length() > j && s2.length() > i) { // if (s1.charAt(j) == s2.charAt(i)) { // i++; // j++; // } else // j++; // } // return s1.length() + s2.length() - 2 * i; // } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
10e702ecae30310851c57cb7fbb815e0
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int t = scn.nextInt(); while(t-->0) { int c = scn.nextInt(); int d = scn.nextInt(); int val = Math.abs(c-d); if(c==0 && d==0) { System.out.println(0); }else if(c==d) { System.out.println(1); }else if(val%2==0) { System.out.println(2); }else if(val%2!=0) { System.out.println(-1); } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
941ef83f1852ceb85f36d158a1f3daad
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author wiseberg */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, OutputWriter out) { int t = in.nextInt(); for (int i = 0; i < t; i++) { long c = in.nextLong(); long d = in.nextLong(); if (c == d) { if (c == 0) out.printLine(0); else out.printLine(1); } else if (Math.abs(c - d) % 2 == 1) { out.printLine(-1); } else { out.printLine(2); } } } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void close() { writer.close(); } public void printLine(int i) { writer.println(i); } } static class InputReader { BufferedReader br; StringTokenizer st; public InputReader(InputStream stream) { br = new BufferedReader(new InputStreamReader(stream)); } public String nextToken() { while (st == null || !st.hasMoreTokens()) { String line = null; try { line = br.readLine(); } catch (IOException e) { throw new RuntimeException(e); } if (line == null) { return null; } st = new StringTokenizer(line); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(nextToken()); } public long nextLong() { return Long.parseLong(nextToken()); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
2a49a53803e46b32fb6f76d45af2b125
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.*; import java.lang.*; import java.io.*; public class GFG { static BufferedReader br; static PrintWriter out; static StringTokenizer st; public static void main(String[] args) throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new OutputStreamWriter(System.out)); int n = nextInt(); while(n-->0){ double c = nextDouble(); double d = nextDouble(); if(c==0&&d==0){ out.println(0); continue; } if(c==d){ out.println(1); continue; } double x = (c+d)/2; int y = (int)x; if(x==y){ out.println(2); continue; } out.println(-1); } out.close(); } static String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine().trim()); return st.nextToken(); } static long nextLong() throws IOException { return Long.parseLong(next()); } static int nextInt() throws IOException { return Integer.parseInt(next()); } static double nextDouble() throws IOException { return Double.parseDouble(next()); } static char nextCharacter() throws IOException { return next().charAt(0); } static String nextLine() throws IOException { return br.readLine().trim(); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
c569ff77298bb20ed6ff1b75cfae9b73
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.PriorityQueue; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Scanner; import java.util.Stack; import java.util.StringTokenizer; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader in = new FastReader(); int test=in.nextInt(); while(test-->0) { int a=in.nextInt(); int b=in.nextInt(); if(a==0&&b==0) System.out.println(0); else if(a==b) System.out.println(1); else if(Math.abs(a-b)>=2&&(a+b)%2==0) System.out.println(2); else System.out.println(-1); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
c6d4d3b0616e7bba14c189e18af6d410
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class Deltix2021A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); while (n-- > 0) { int c = sc.nextInt(); int d = sc.nextInt(); if (c == 0 && d == 0) { System.out.println(0); } else if (c == d) { System.out.println(1); } else { System.out.println(Math.abs(c - d) % 2 == 1 ? -1 : 2); } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
e058448fbe0b029074703876acfd4397
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.util.*; public class DeltixSU21A { public static void solve(IO io) { int c = io.getInt(); int d = io.getInt(); if (c == 0 && d == 0) { io.println(0); } else if (c == d) { io.println(1); } else if (c % 2 == d % 2) { io.println(2); } else { io.println(-1); } } public static void main(String[] args) { IO io = new IO(); int t = io.getInt(); for (int testIndex = 0; testIndex < t; testIndex++) { solve(io); } io.close(); } static class IO extends PrintWriter { public IO() { super(new BufferedOutputStream(System.out)); r = new BufferedReader(new InputStreamReader(System.in)); } public IO(InputStream i) { super(new BufferedOutputStream(System.out)); r = new BufferedReader(new InputStreamReader(i)); } public IO(InputStream i, OutputStream o) { super(new BufferedOutputStream(o)); r = new BufferedReader(new InputStreamReader(i)); } public boolean hasMoreTokens() { return peekToken() != null; } public int getInt() { return Integer.parseInt(nextToken()); } public double getDouble() { return Double.parseDouble(nextToken()); } public long getLong() { return Long.parseLong(nextToken()); } public String getWord() { return nextToken(); } private BufferedReader r; private String line; private StringTokenizer st; private String token; private String peekToken() { if (token == null) try { while (st == null || !st.hasMoreTokens()) { line = r.readLine(); if (line == null) return null; st = new StringTokenizer(line); } token = st.nextToken(); } catch (IOException e) { } return token; } private String nextToken() { String ans = peekToken(); token = null; return ans; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
8a584a3e6bfe528a01809aa5a21940f1
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; public class A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int a=sc.nextInt(); int b=sc.nextInt(); if(a==0 && b==0) System.out.println(0); else if(a==b) System.out.println(1); else if(Math.abs(a-b)%2==0) System.out.println(2); else System.out.println(-1); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
923f315519ad1858c9f5367513c53645
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
//package com.company; import java.util.*; public class Main { public static void main(String[] args) { // write your code here Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); int casen = 1; while(t-->0) { long c = scanner.nextLong(); long d = scanner.nextLong(); if(Math.abs(c-d)%2!=0) { System.out.println(-1); }else if(Math.abs(c-d)==0){ if(c==0) System.out.println(0); else System.out.println(1); }else System.out.println(2); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
4dcd38cf4ad529709a6b5e077b35bca3
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
/*Everything is Hard * Before Easy * Jai Mata Dii */ import java.util.*; import java.io.*; public class Main { static class FastReader{ BufferedReader br;StringTokenizer st;public FastReader(){br = new BufferedReader(new InputStreamReader(System.in));}String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException e){e.printStackTrace();}}return st.nextToken();}int nextInt(){ return Integer.parseInt(next());}long nextLong(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}String nextLine(){String str = ""; try{str = br.readLine(); } catch (IOException e) {e.printStackTrace();} return str; }} static long mod = (long)(1e9+7); // static long mod = 998244353; // static Scanner sc = new Scanner(System.in); static FastReader sc = new FastReader(); static PrintWriter out = new PrintWriter(System.out); public static void main (String[] args) { int ttt = 1; ttt = sc.nextInt(); z :for(int tc=1;tc<=ttt;tc++){ long c = sc.nextLong(); long d = sc.nextLong(); if(c == 0 && d == 0) out.write("0\n"); else if(c == d) out.write(1+"\n"); else if(Math.abs(c-d)%2==0) { out.write(2+"\n"); } else { out.write("-1\n"); } } out.close(); } static long pow(long a, long b){long ret = 1;while(b>0){if(b%2 == 0){a = (a*a)%mod;b /= 2;}else{ret = (ret*a)%mod;b--;}}return ret%mod;} static long gcd(long a,long b){if(b==0) return a; return gcd(b,a%b); } private static void sort(double[] a) {List<Double> k = new ArrayList<>();for(double val : a) k.add(val);Collections.sort(k);for(int i=0;i<a.length;i++) a[i] = k.get(i);} private static void ini(List<Integer>[] tre2){for(int i=0;i<tre2.length;i++){tre2[i] = new ArrayList<>();}} private static void init(List<int[]>[] tre2){for(int i=0;i<tre2.length;i++){tre2[i] = new ArrayList<>();}} private static void sort(long[] a) {List<Long> k = new ArrayList<>();for(long val : a) k.add(val);Collections.sort(k);for(int i=0;i<a.length;i++) a[i] = k.get(i);} }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
7e4eb39e59ea6c63acc2c117ce622645
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; /** * @author Naitik * */ public class Main { static FastReader sc=new FastReader(); static int dp[][][]; static int mod=1000000007; static int mod1=998244353; static int max; static long bit[]; // static long seg[]; // static long fact[]; // static long A[]; static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) { // StringBuffer sb=new StringBuffer(""); int ttt=1; ttt =i(); outer :while (ttt-- > 0) { long n=i(); long m=i(); if((m+n)%2!=0) { out.println("-1"); continue outer; } if(m==n) { if(m==0) { out.println("0"); } else out.println("1"); continue outer; } out.println("2"); } //System.out.println(sb.toString()); out.close(); //CHECK FOR N=1 //CHECK FOR M=0 //CHECK FOR N=1 //CHECK FOR M=0 //CHECK FOR N=1 } static class Pair implements Comparable<Pair> { int x; int y; // int z; Pair(int x,int y,int z){ this.x=x; this.y=y; //this.z=z; } @Override public int compareTo(Pair o) { if(this.x>o.x) return +1; else if(this.x<o.x) return -1; else { if(this.y>o.y) return -1; else if(this.y<o.y) return +1; else return 0; } } // public int hashCode() // { // final int temp = 14; // int ans = 1; // ans =x*31+y*13; // return ans; // } // @Override // public boolean equals(Object o) // { // if (this == o) { // return true; // } // if (o == null) { // return false; // } // if (this.getClass() != o.getClass()) { // return false; // } // Pair other = (Pair)o; // if (this.x != other.x || this.y!=other.y) { // return false; // } // return true; // } // /* FOR TREE MAP PAIR USE */ // public int compareTo(Pair o) { // if (x > o.x) { // return 1; // } // if (x < o.x) { // return -1; // } // if (y > o.y) { // return 1; // } // if (y < o.y) { // return -1; // } // return 0; // } } static int find(int A[],int a) { if(A[a]<0) return a; return A[a]=find(A, A[a]); } //static int find(int A[],int a) { // if(A[a]==a) // return a; // return A[a]=find(A, A[a]); //} //FENWICK TREE static void update(int i, int x){ for(; i < bit.length; i += (i&-i)) bit[i] += x; } static int sum(int i){ int ans = 0; for(; i > 0; i -= (i&-i)) ans += bit[i]; return ans; } //END //static void add(int v) { // if(!map.containsKey(v)) { // map.put(v, 1); // } // else { // map.put(v, map.get(v)+1); // } //} //static void remove(int v) { // if(map.containsKey(v)) { // map.put(v, map.get(v)-1); // if(map.get(v)==0) // map.remove(v); // } //} public static int upper(int A[],int k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { ans=mid; l=mid+1; } else { u=mid-1; } } return ans; } public static int lower(int A[],int k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { l=mid+1; } else { ans=mid; u=mid-1; } } return ans; } static int[] copy(int A[]) { int B[]=new int[A.length]; for(int i=0;i<A.length;i++) { B[i]=A[i]; } return B; } static long[] copy(long A[]) { long B[]=new long[A.length]; for(int i=0;i<A.length;i++) { B[i]=A[i]; } return B; } static int[] input(int n) { int A[]=new int[n]; for(int i=0;i<n;i++) { A[i]=sc.nextInt(); } return A; } static long[] inputL(int n) { long A[]=new long[n]; for(int i=0;i<n;i++) { A[i]=sc.nextLong(); } return A; } static String[] inputS(int n) { String A[]=new String[n]; for(int i=0;i<n;i++) { A[i]=sc.next(); } return A; } static long sum(int A[]) { long sum=0; for(int i : A) { sum+=i; } return sum; } static long sum(long A[]) { long sum=0; for(long i : A) { sum+=i; } return sum; } static void reverse(long A[]) { int n=A.length; long B[]=new long[n]; for(int i=0;i<n;i++) { B[i]=A[n-i-1]; } for(int i=0;i<n;i++) A[i]=B[i]; } static void reverse(int A[]) { int n=A.length; int B[]=new int[n]; for(int i=0;i<n;i++) { B[i]=A[n-i-1]; } for(int i=0;i<n;i++) A[i]=B[i]; } static void input(int A[],int B[]) { for(int i=0;i<A.length;i++) { A[i]=sc.nextInt(); B[i]=sc.nextInt(); } } static int[][] input(int n,int m){ int A[][]=new int[n][m]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { A[i][j]=i(); } } return A; } static char[][] charinput(int n,int m){ char A[][]=new char[n][m]; for(int i=0;i<n;i++) { String s=s(); for(int j=0;j<m;j++) { A[i][j]=s.charAt(j); } } return A; } static int max(int A[]) { int max=Integer.MIN_VALUE; for(int i=0;i<A.length;i++) { max=Math.max(max, A[i]); } return max; } static int min(int A[]) { int min=Integer.MAX_VALUE; for(int i=0;i<A.length;i++) { min=Math.min(min, A[i]); } return min; } static long max(long A[]) { long max=Long.MIN_VALUE; for(int i=0;i<A.length;i++) { max=Math.max(max, A[i]); } return max; } static long min(long A[]) { long min=Long.MAX_VALUE; for(int i=0;i<A.length;i++) { min=Math.min(min, A[i]); } return min; } static long [] prefix(long A[]) { long p[]=new long[A.length]; p[0]=A[0]; for(int i=1;i<A.length;i++) p[i]=p[i-1]+A[i]; return p; } static long [] prefix(int A[]) { long p[]=new long[A.length]; p[0]=A[0]; for(int i=1;i<A.length;i++) p[i]=p[i-1]+A[i]; return p; } static long [] suffix(long A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static long [] suffix(int A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static void fill(int dp[]) { Arrays.fill(dp, -1); } static void fill(int dp[][]) { for(int i=0;i<dp.length;i++) Arrays.fill(dp[i], -1); } static void fill(int dp[][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { Arrays.fill(dp[i][j],-1); } } } static void fill(int dp[][][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { for(int k=0;k<dp[0][0].length;k++) { Arrays.fill(dp[i][j][k],-1); } } } } static void fill(long dp[]) { Arrays.fill(dp, -1); } static void fill(long dp[][]) { for(int i=0;i<dp.length;i++) Arrays.fill(dp[i], -1); } static void fill(long dp[][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { Arrays.fill(dp[i][j],-1); } } } static void fill(long dp[][][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { for(int k=0;k<dp[0][0].length;k++) { Arrays.fill(dp[i][j][k],-1); } } } } static int min(int a,int b) { return Math.min(a, b); } static int min(int a,int b,int c) { return Math.min(a, Math.min(b, c)); } static int min(int a,int b,int c,int d) { return Math.min(a, Math.min(b, Math.min(c, d))); } static int max(int a,int b) { return Math.max(a, b); } static int max(int a,int b,int c) { return Math.max(a, Math.max(b, c)); } static int max(int a,int b,int c,int d) { return Math.max(a, Math.max(b, Math.max(c, d))); } static long min(long a,long b) { return Math.min(a, b); } static long min(long a,long b,long c) { return Math.min(a, Math.min(b, c)); } static long min(long a,long b,long c,long d) { return Math.min(a, Math.min(b, Math.min(c, d))); } static long max(long a,long b) { return Math.max(a, b); } static long max(long a,long b,long c) { return Math.max(a, Math.max(b, c)); } static long max(long a,long b,long c,long d) { return Math.max(a, Math.max(b, Math.max(c, d))); } static long power(long x, long y, long p) { if(y==0) return 1; if(x==0) return 0; long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static void print(int A[]) { for(int i : A) { System.out.print(i+" "); } System.out.println(); } static void print(long A[]) { for(long i : A) { System.out.print(i+" "); } System.out.println(); } static long mod(long x) { return ((x%mod + mod)%mod); } static String reverse(String s) { StringBuffer p=new StringBuffer(s); p.reverse(); return p.toString(); } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i){ int tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static void sort(long[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i){ long tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static String sort(String s) { Character ch[]=new Character[s.length()]; for(int i=0;i<s.length();i++) { ch[i]=s.charAt(i); } Arrays.sort(ch); StringBuffer st=new StringBuffer(""); for(int i=0;i<s.length();i++) { st.append(ch[i]); } return st.toString(); } static HashMap<Integer,Integer> hash(int A[]){ HashMap<Integer,Integer> map=new HashMap<Integer, Integer>(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap<Integer,Integer> tree(int A[]){ TreeMap<Integer,Integer> map=new TreeMap<Integer, Integer>(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
8e31d2f1d3af051dbc88fd9b48a2f3b1
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; import java.io.*; public class Main { static Scanner sc; static PrintWriter pw; public static void main(String[] args) throws IOException { sc = new Scanner(System.in); pw = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { int c = sc.nextInt(), d = sc.nextInt(); if (c == d) pw.println(c == 0 ? 0 : 1); else if (Math.abs(c - d) % 2 == 1) pw.println(-1); else pw.println(2); } pw.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String readAllLines(BufferedReader reader) throws IOException { StringBuilder content = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { content.append(line); content.append(System.lineSeparator()); } return content.toString(); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
e353c08502b69a6947a6734023c2717b
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; import java.io.*; import java.util.stream.*; public class App { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) throws Exception { if (System.getProperty("ONLINE_JUDGE") == null) { File inputFile = new File("/Users/vipinjain/self/cp/input.txt"); File outputFile = new File("/Users/vipinjain/self/cp/output.txt"); br = new BufferedReader(new FileReader(inputFile)); bw = new BufferedWriter(new FileWriter(outputFile)); } int tests; tests = Integer.parseInt(br.readLine()); //tests = 1; while (tests-- > 0) { solve(); } bw.flush(); bw.close(); br.close(); } static void solve() throws Exception { String[] tmp = br.readLine().split(" "); int a = Integer.parseInt(tmp[0]); int b = Integer.parseInt(tmp[1]); // int c = Integer.parseInt(tmp[2]); // int n = Integer.parseInt(br.readLine()); // int[] arr = Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); int cost = 0; if (a != b) { if ((a + b) % 2 != 0) { bw.write("-1\n"); return; } else { a = (a + b) / 2; b = a; cost = 1; } } if (a > 0) { cost++; } bw.write(cost + ""); bw.write("\n"); } static void shuffleArray(int[] arr){ int n = arr.length; Random rnd = new Random(); for(int i=0; i<n; ++i){ int tmp = arr[i]; int randomPos = i + rnd.nextInt(n-i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } } static int gcd(int a, int b) { if (a == 0) { return b; } return gcd(b % a, a); } static boolean isPrime(long n) { for (long i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } static long minDivisor(long n) { for (long i = 2; i * i <= n; ++i) { if (n % i == 0) { return i; } } return n; } static void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
cc096444d05531a385d8370221ceb0c3
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.nio.charset.MalformedInputException; import java.util.StringTokenizer; import java.util.Arrays; public class Cv { public static void main(String[] args) { FastScanner in = new FastScanner(); Scanner sc = new Scanner(System.in); PrintWriter o = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { int c = sc.nextInt(), d = sc.nextInt(); if (c == d && c != 0) { o.println(1); } if (c == d && c == 0) { o.println(0); } if (c != d) { if (Math.abs(c - d) % 2 == 0) { o.println(2); } else { o.println(-1); } } } o.close(); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public String next() { while (!st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } byte nextByte() { return Byte.parseByte(next()); } short nextShort() { return Short.parseShort(next()); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return java.lang.Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
831a8c4ffbef1098396ccb9ac3856d1d
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.util.*; public class _1556a { FastScanner scn; PrintWriter w; PrintStream fs; int MOD = 1000000007; int MAX = 200005; long mul(long x, long y) {long res = x * y; return (res >= MOD ? res % MOD : res);} long power(long x, long y) {if (y < 0) return 1; long res = 1; x %= MOD; while (y!=0) {if ((y & 1)==1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;} void ruffleSort(int[] a) {int n=a.length;Random r=new Random();for (int i=0; i<a.length; i++) {int oi=r.nextInt(n), temp=a[i];a[i]=a[oi];a[oi]=temp;}Arrays.sort(a);} void reverseSort(int[] arr){List<Integer> list = new ArrayList<>();for (int i=0; i<arr.length; i++){list.add(arr[i]);}Collections.sort(list, Collections.reverseOrder());for (int i = 0; i < arr.length; i++){arr[i] = list.get(i);}} boolean LOCAL; void debug(Object... o){if(LOCAL)System.err.println(Arrays.deepToString(o));} //SPEED IS NOT THE CRITERIA, CODE SHOULD BE A NO BRAINER, CMP KILLS, MOCIM void solve(){ int t=scn.nextInt(); while(t-->0) { int a = scn.nextInt(),b=scn.nextInt(); if(a==b){ if(a==0){ w.println(0); continue; } w.println(1); continue; } int sum = a+b; if((sum&1)==0){ w.println(2); }else{ w.println(-1); } } } void run() { try { long ct = System.currentTimeMillis(); scn = new FastScanner(new File("input.txt")); w = new PrintWriter(new File("output.txt")); fs=new PrintStream("error.txt"); System.setErr(fs); LOCAL=true; solve(); w.close(); System.err.println(System.currentTimeMillis() - ct); } catch (FileNotFoundException e) { e.printStackTrace(); } } void runIO() { scn = new FastScanner(System.in); w = new PrintWriter(System.out); LOCAL=false; solve(); w.close(); } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public FastScanner(InputStream f) { br = new BufferedReader(new InputStreamReader(f)); } String next() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return null; st = new StringTokenizer(s); } return st.nextToken(); } boolean hasMoreTokens() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return false; st = new StringTokenizer(s); } return true; } int nextInt() { return Integer.parseInt(next()); } int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } long[] nextLongArray(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } int lowerBound(int[] arr, int x){int n = arr.length, si = 0, ei = n - 1;while(si <= ei){int mid = si + (ei - si)/2;if(arr[mid] == x){if(mid-1 >= 0 && arr[mid-1] == arr[mid]){ei = mid-1;}else{return mid;}}else if(arr[mid] > x){ei = mid - 1; }else{si = mid+1;}}return si; } int upperBound(int[] arr, int x){int n = arr.length, si = 0, ei = n - 1;while(si <= ei){int mid = si + (ei - si)/2;if(arr[mid] == x){if(mid+1 < n && arr[mid+1] == arr[mid]){si = mid+1;}else{return mid + 1;}}else if(arr[mid] > x){ei = mid - 1; }else{si = mid+1;}}return si; } int upperBound(ArrayList<Integer> list, int x){int n = list.size(), si = 0, ei = n - 1;while(si <= ei){int mid = si + (ei - si)/2;if(list.get(mid) == x){if(mid+1 < n && list.get(mid+1) == list.get(mid)){si = mid+1;}else{return mid + 1;}}else if(list.get(mid) > x){ei = mid - 1; }else{si = mid+1;}}return si; } void swap(int[] arr, int i, int j){int temp = arr[i];arr[i] = arr[j];arr[j] = temp;} long nextPowerOf2(long v){if (v == 0) return 1;v--;v |= v >> 1;v |= v >> 2;v |= v >> 4;v |= v >> 8;v |= v >> 16;v |= v >> 32;v++;return v;} int gcd(int a, int b) {if(a == 0){return b;}return gcd(b%a, a);} // TC- O(logmax(a,b)) boolean nextPermutation(int[] arr) {if(arr == null || arr.length <= 1){return false;}int last = arr.length-2;while(last >= 0){if(arr[last] < arr[last+1]){break;}last--;}if (last < 0){return false;}if(last >= 0){int nextGreater = arr.length-1;for(int i=arr.length-1; i>last; i--){if(arr[i] > arr[last]){nextGreater = i;break;}}swap(arr, last, nextGreater);}int i = last + 1, j = arr.length - 1;while(i < j){swap(arr, i++, j--);}return true;} public static void main(String[] args) { new _1556a().runIO(); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
01b63d24eb6cae00c8456638f1ebd9d0
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; import java.io.*; public class Solution { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static int sum(int idx , int bit[]) { int sum = 0; while(idx > 0) { sum += bit[idx]; idx -= idx&(-idx); } return sum; } static void update(int n , int idx , int val , int bit[]) { while(idx <= n) { bit[idx] += val; idx += idx&(-idx); } } static long mod = 1000000007; static long pow(long a , long b) { if(b == 0) return 1; long ans = pow(a,b/2); if(b%2 == 0) return ans*ans%mod; return ans*ans%mod*a%mod; } static long f(long v) { if(v <= 0) return 0; return (v*(v+1)/2); } public static void main(String []args) throws IOException { Reader sc = new Reader(); int t = sc.nextInt(); while(t-- > 0) { int a = sc.nextInt(); int b = sc.nextInt(); if(a == 0 && b == 0) System.out.println(0); else { if(a == b) System.out.println(1); else { if(a%2 != b%2) System.out.println(-1); else System.out.println(2); } } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
8002369f5a9a4d40808ff1ae5205e11d
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; import java.io.*; public class Solution { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static int sum(int idx , int bit[]) { int sum = 0; while(idx > 0) { sum += bit[idx]; idx -= idx&(-idx); } return sum; } static void update(int n , int idx , int val , int bit[]) { while(idx <= n) { bit[idx] += val; idx += idx&(-idx); } } static long mod = 1000000007; static long pow(long a , long b) { if(b == 0) return 1; long ans = pow(a,b/2); if(b%2 == 0) return ans*ans%mod; return ans*ans%mod*a%mod; } static long f(long v) { if(v <= 0) return 0; return (v*(v+1)/2); } public static void main(String []args) throws IOException { Reader sc = new Reader(); int t = sc.nextInt(); while(t-- > 0) { int a = sc.nextInt(); int b = sc.nextInt(); if(a == 0 && b == 0) System.out.println(0); else { if(a == b) System.out.println(1); else { if(a%2 != b%2) System.out.println(-1); else System.out.println(2); } } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
afac1bce5d879b8211e3f651030afeba
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class A1556 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); for (int t=0; t<T; t++) { int C = in.nextInt(); int D = in.nextInt(); int answer; if ((C+D)%2 == 1) { answer = -1; } else if (C == D) { answer = (C == 0) ? 0 : 1; } else { answer = 2; } System.out.println(answer); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
21a8aa522e1572b0a1f3e405adc81bec
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.util.*; public class Test { public static void main(String[] args) throws IOException { Reader rd = new Reader(); int t = rd.nextInt(); while (t-- > 0) { long c = rd.nextInt(); long d = rd.nextInt(); if ((c - d) % 2L != 0L) System.out.println("-1"); else if (c == 0 && d == 0) System.out.println("0"); else if (c == d) System.out.println("1"); else if (c != d) System.out.println("2"); } } /** * method to solve current cp problem */ private static void solve() { } /** * you can ignore the below snippet code as it's just for taking faster input in java */ static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
5e4f38d7d77f56ced0acb655f4075523
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class AVarietyOfOperations { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { int c = sc.nextInt(); int d = sc.nextInt(); if(c==0 && d==0) { System.out.println(0); continue; } if((c+d) % 2 == 0) { if(c == d) { System.out.println(1); } else { System.out.println(2); } } else { System.out.println(-1); } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
298b7ab508b99e6101befff4fb246c02
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class AVarietyOfOperations { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t --> 0) { int c = sc.nextInt(); int d = sc.nextInt(); if (c == 0 && d == 0) { System.out.println(0); } else if ((c + d) % 2 == 0 && (c + d) / 2 == c) { System.out.println(1); } else if ((c + d) % 2 == 0) { System.out.println(2); } else { System.out.println(-1); } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
4db1072bdf6a6721080c903da7ae593e
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { static void daunism1() { } static void dfs(int v, int w) { } static int simple(int a){ for (int i = 2; i <=Math.sqrt(a) ; i++) { if (a%i==0){ return 1; } } return 0; } static long gcd(long a, long b) { if (b == 0) return Math.abs(a); return gcd(b, a % b); } public static void main(String[] args) throws IOException { // br = new BufferedReader(new FileReader("pencils.in")); // out = new PrintWriter("pencils.out"); int t=nextInt(); for (int i = 0; i < t; i++) { int c=nextInt(); int d=nextInt(); if (Math.abs(c-d)%2==1)out.println(-1); else if (c==0&&d==0)out.println(0); else if (c==d)out.println(1); else out.println(2); } out.close(); } static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out = new PrintWriter(System.out); static StringTokenizer in = new StringTokenizer(""); public static boolean hasNext() throws IOException { if (in.hasMoreTokens()) return true; String s; while ((s = br.readLine()) != null) { in = new StringTokenizer(s); if (in.hasMoreTokens()) return true; } return false; } public static String nextToken() throws IOException { while (!in.hasMoreTokens()) { in = new StringTokenizer(br.readLine()); } return in.nextToken(); } public static int nextInt() throws IOException { return Integer.parseInt(nextToken()); } public static long nextLong() throws IOException { return Long.parseLong(nextToken()); } public static double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } static class Maincraft implements Comparable<Maincraft> { int x; int y; public Maincraft(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Maincraft o) { return Integer.compare(x, o.x); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
53a87b3a0c49d124184748dda12fb5fd
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
// Created By Jefferson Samuel on 23/08/21 at 2:11 am import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.System.exit; public class B { static void solve() throws Exception { int T = scanInt(); while (T-- > 0) { int A = scanInt(); int B = scanInt(); int sum = A+B; if(A==0&&B==0) out.println(0); else if(A==B) out.println(1); else out.println((sum&1)==0?2:-1); } } // Essentials static int scanInt() throws IOException {return parseInt(scanString());} static int[] scInAr(int N) throws IOException { int[] a = new int[N]; for(int i = 0;i<N;i++)a[i] = scanInt(); return a; } static ArrayList<Integer> scInLi(int N) throws IOException { ArrayList<Integer> lis = new ArrayList<>(N); for (int i = 0; i < N; i++) lis.add(scanInt()); return lis; } static void revsLis(ArrayList<Integer> lis) {lis.sort(Collections.reverseOrder());} static void sortAr(int ar[]) {Arrays.sort(ar);} static void revsortAr(int ar[]){sortAr(ar);revar(ar);} static void revar(int ar[]){for (int i = 0; i < ar.length / 2; i++) { int temp = ar[i]; ar[i] = ar[ar.length - 1 - i]; ar[ar.length - 1 - i] = temp;}} static long[] scLoAr(int N) throws IOException { long[] a = new long[N]; for(int i = 0;i<N;i++)a[i] = scanLong(); return a; } static long scanLong() throws IOException {return parseLong(scanString());} static String scanString() throws IOException { while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } static BufferedReader in; static PrintWriter out; static StringTokenizer tok; public static void main(String[] args) { try { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); in.close(); out.close(); } catch (Throwable e) { e.printStackTrace(); exit(1); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
9276290a27ae6ea515bdea9f94d7ec40
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class VarietyOfOP { public static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int tc = scanner.nextInt(); while (tc-->0){ int num1 = scanner.nextInt(); int num2 = scanner.nextInt(); int diff = Math.abs(num1-num2); if (num1==num2 && num1==0){ System.out.println(0); continue; } if (diff%2!=0){ System.out.println(-1); }else { if ((num1 == num2)){ System.out.println(1); }else System.out.println(2); } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
705018bf4ff1a7961e8883ec59d861df
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int i = 0;i<t;i++) { int a = in.nextInt(); int b = in.nextInt(); if((a+b)%2==1) { System.out.println("-1"); } else if(a+b==0) { System.out.println("0"); } else if(a==b) { System.out.println("1"); } else if(a!=b) { System.out.println("2"); } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
992ecf72eb71ffb86e8bfa5ad75e013d
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class A { public static void main(String[] args) { // TODO Auto-generated method stub FastScanner fs=new FastScanner(); int t=fs.nextInt(); while (t-->0) { int a=fs.nextInt(); int b=fs.nextInt(); if (a==0 && b==0) System.out.println(0); else if (a==b) System.out.println(1); else if (Math.abs(a-b)%2==0) System.out.println(2); else System.out.println(-1); } } static class FastScanner{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); public String next() { while (!st.hasMoreElements()) try { st=new StringTokenizer(br.readLine()); }catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt () { return Integer.parseInt(next()); } long nextLong () { return Long.parseLong(next()); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
912587d2b47398134ff218c182951374
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.util.*; /* */ public class A{ static FastReader sc=null; public static void main(String[] args) { sc=new FastReader(); int t=sc.nextInt(); for(int tt=0;tt<t;tt++) { int c=sc.nextInt(),d=sc.nextInt(); int dif=Math.abs(c-d); if(dif%2==1)System.out.println(-1); else if(dif==0)System.out.println(c==0?0:1); else System.out.println(2); } } static int[] ruffleSort(int a[]) { ArrayList<Integer> al=new ArrayList<>(); for(int i:a)al.add(i); Collections.sort(al); for(int i=0;i<a.length;i++)a[i]=al.get(i); return a; } static void print(int a[]) { for(int e:a) { System.out.print(e+" "); } System.out.println(); } static class FastReader{ StringTokenizer st=new StringTokenizer(""); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String next() { while(!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] readArray(int n) { int a[]=new int[n]; for(int i=0;i<n;i++)a[i]=sc.nextInt(); return a; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
193ee1ffde8c56c53b2243965d60cece
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.util.*; public class AVarietyOfOperations { public static void main(String[] args) { new AVarietyOfOperations().run(); } BufferedReader br; PrintWriter out; long mod = (long) (1e9 + 7), inf = (long) (3e18); class pair { int F, S; pair(int f, int s) { F = f; S = s; } } void solve() { int t = ni(); while(t-- > 0) { //TODO: int c= ni(); int d= ni(); if(c==0&& d==0){ out.println(0); continue; } if(c==d){ out.println(1); continue; } if(Math.abs(c-d)%2==0){ out.println(2); } else{ out.println(-1); } } } // -------- I/O Template ------------- char nc() { return ns().charAt(0); } String nLine() { try { return br.readLine(); } catch(IOException e) { return "-1"; } } double nd() { return Double.parseDouble(ns()); } long nl() { return Long.parseLong(ns()); } int ni() { return Integer.parseInt(ns()); } int[] na(int n) { int a[] = new int[n]; for(int i = 0; i < n; i++) a[i] = ni(); return a; } StringTokenizer ip; String ns() { if(ip == null || !ip.hasMoreTokens()) { try { ip = new StringTokenizer(br.readLine()); if(ip == null || !ip.hasMoreTokens()) ip = new StringTokenizer(br.readLine()); } catch(IOException e) { throw new InputMismatchException(); } } return ip.nextToken(); } void run() { try { if (System.getProperty("ONLINE_JUDGE") == null) { br = new BufferedReader(new FileReader("/media/ankanchanda/Data/WORKPLACE/DS and CP/Competitive Programming/VSCODE/IO/input.txt")); out = new PrintWriter("/media/ankanchanda/Data/WORKPLACE/DS and CP/Competitive Programming/VSCODE/IO/output.txt"); } else { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } } catch (FileNotFoundException e) { System.out.println(e); } solve(); out.flush(); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
20af1efe6f55c1c585ca935446cfd8fd
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i= 0; i < n; ++i) { int c = sc.nextInt(); int d = sc.nextInt(); System.out.println(solve(c, d)); } sc.close(); } static int solve(int c, int d) { if ((c + d) % 2 != 0) { return -1; } if (c == 0 && d == 0) { return 0; } return (c == d) ? 1 : 2; } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
62457f2ea93975d7e9de01b3730c9e20
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
/*package whatever //do not write package name here */ import java.io.*; import java.util.*; public class GFG { public static void main (String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int c=sc.nextInt(),d=sc.nextInt(); if(Math.abs(c-d)%2==0) { if(c==d && c!=0) System.out.println("1"); else if(c==d && c==0) System.out.println("0"); else System.out.println("2"); } else System.out.println("-1"); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
050d25a7f1c0ebcaced2364d4225ce97
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; public class AVarietyOfOperations { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int c=sc.nextInt(); int d=sc.nextInt(); int res=-1; if(c==0&&d==0)res=0; else if(c==d)res=1; else if(Math.abs(c-d)%2==0)res=2; System.out.println(res); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
854317d6d28cf5de63117c30c5874ed1
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.lang.reflect.Array; import java.util.*; import java.io.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { // write your code here PrintWriter out = new PrintWriter(System.out); FastReader scan = new FastReader(); Task solver = new Task(); solver.solve(1,scan,out); out.close(); } static class Task{ public void solve(int testNumber, FastReader scan, PrintWriter out) { int [][] L = {{1,3,3,4,5,5,6},{2,2,4,1,1,4,2}}; /*Pattern pattern = Pattern.compile("[B]+"); //REGEX template Matcher matcher = pattern.matcher(s);*/ int t = scan.nextInt(); for(int i=0; i<t;i++){ //int n = scan.nextInt(); ArrayList<Integer> list = new ArrayList<>(); ArrayList<Integer> list2 = new ArrayList<>(); int c = scan.nextInt(); int d = scan.nextInt(); if((c+d)%2==1){ out.println(-1); }else if(c==d && c>0){ out.println(1); }else if(c==d){ out.println(0); }else{ out.println(2); } } } public static String parenthesys(int n){ String answer = ""; for(int j = 0; j<n;j++){ answer+="("; } for(int j = 0; j<n;j++){ answer+=")"; } return answer; } public static long digitsSum(long n){ long sum=0; while(n!=0){ sum+=n%10; n=n/10; } return sum; } public static boolean isValid(int x, int y, int n){ if(x<0 || y<0 || x>=n || y>=n){ return false; } return true; } public static int factorial(int n){ if(n<=1){ return 1; }else{ return n*factorial(n-1); } } public static long DBD(long a, long b){ long answer=1; for(long i=1; i<=Math.min(a,b);i++){ if(a%i==0 && b%i==0){ answer=i; } } return answer; } public static boolean isPrime(int n){ if(n<2){ return false; } for(int i=2; i<Math.sqrt(n)+1 ;i++){ if(n%i==0){ return false; } } return true; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(new File(s))); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
d72656d27e4f163431d5b6c9651c53cf
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.lang.reflect.Array; import java.text.DecimalFormat; import java.util.*; import java.io.*; public class Equal { static class pair implements Comparable<pair> { int x; int y; public pair(int u, int v) { this.x = u; this.y = v; } @Override public int compareTo(pair o) { return o.x - x; } } static String input; static int scoreI = 100002; static int scoreO = 100002; static int[][] mem; static int dp(int l, int r) { if (l > r) { if (input.length() % 2 == 0) return -1; return 1; } if (mem[l][r] != 0) return mem[l][r]; int turn = (input.length() - (r - l + 1)) % 2; if (turn == 0) { if (input.charAt(l) == 'O' && input.charAt(r) == 'O') { return mem[l][r] = -(r - l + 2); } int d1 = 0; int d2 = 0; if (input.charAt(l) == 'I') d1 = dp(l + 1, r); if (input.charAt(r) == 'I') d2 = dp(l, r - 1); if (d1 == 0 || d2 == 0) return mem[l][r] = d1 + d2; else return mem[l][r] = Math.max(d1, d2); } if (input.charAt(l) == 'I' && input.charAt(r) == 'I') { return mem[l][r] = (r - l + 2); } int d1 = 0; int d2 = 0; if (input.charAt(l) == 'O') d1 = dp(l + 1, r); if (input.charAt(r) == 'O') d2 = dp(l, r - 1); if (d1 == 0 || d2 == 0) return mem[l][r] = d1 + d2; else return mem[l][r] = Math.min(d1, d2); } static int log(long a, long b) { int res = 0; while (a >= b) { a /= b; res++; } return res; } static long pow(long a, int b) { long res = 1; while (b-- > 0) { res *= a; } return res; } public static void main(String[] args) throws IOException { //BufferedReader br = new BufferedReader(new FileReader("name.in")); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; PrintWriter out = new PrintWriter(System.out); int T=Integer.parseInt(br.readLine()); while(T-->0){ st=new StringTokenizer(br.readLine()); long a=Long.parseLong(st.nextToken()); long b=Long.parseLong(st.nextToken()); if((a+b)%2==1){ out.println(-1); } else { long k1=(a+b)/2; long k2=Math.max(a,b)-k1; k1=(k1==0)?0:1; k2=(k2==0)?0:1; out.println(k1+k2); } } out.flush(); out.close(); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
afbdf74c9859aa733b500a3e6b4f6632
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; public class Coding { public static void main(String [] args){ Scanner sc = new Scanner(System.in); int t= sc.nextInt(); while(t-->0){ int c = sc.nextInt(); int d = sc.nextInt(); if((c+d)%2!=0){ System.out.println("-1"); }else{ if(c==0&&d==0) System.out.println(0); else if(c==d) System.out.println(1); else System.out.println(2); } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
7b4926370593be1f4a4daba477d9c8c5
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; public class Solution { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); StringBuilder result = new StringBuilder(); for(int i = 0; i < t; i++) { long c = scan.nextLong(); long d = scan.nextLong(); int res = -1; if(c == 0 && d == 0) { res = 0; } else if(Math.abs(c) == Math.abs(d)) { res = 1; } else if(Math.abs(c-d)%2 == 0) { res = 2; } result.append(res + "\n"); } System.out.println(result); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
de17f4d8d57f7170a1687f9549be0812
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; /** * Created by dhruvthakker on 01/10/21 at 9:42 am */ public class Season2 { static InputReader in = new InputReader(); static PrintWriter out = new PrintWriter(System.out); public static void main(String args[]) { int n = in.nextInt(); while (n-- > 0) { int a = in.nextInt(); int b = in.nextInt(); int max = Math.max(a, b); int min = Math.min(a, b); int ans = 0; int diff = max - min; if (diff % 2 == 1) { ans = -1; } else if (max > 0) { ans = ans + diff > 0 ? 2 : 1; } out.println(ans); } out.flush(); } static void debug(Object... o) { System.out.println(Arrays.deepToString(o)); } static class InputReader { BufferedReader br; StringTokenizer st; public InputReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
7d6158882e4fb5a668f266d01b91e418
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class VarietyOperations { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while (t-->0){ int c=sc.nextInt(); int d=sc.nextInt(); if(c==0 && d==0){ System.out.println(0); } else if(c==d){ System.out.println(1); } else if((Math.abs(c-d)%2!=0)){ System.out.println(-1); } else { System.out.println(2); } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
90bf15a481ad216c5d872557491543cc
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pt=new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); for(int xyz=0; xyz<t; xyz++) { String str=br.readLine(); StringTokenizer st=new StringTokenizer(str," "); int c=Integer.parseInt(st.nextToken()); int d=Integer.parseInt(st.nextToken()); int k=0; if(c==0 && d==0) { k=0; } else if((c+d)%2!=0) k=-1; else if(d==c) k=1; else if((d-c)%2==0) k=2; pt.println(k); } pt.close(); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
35699065ad48bab395a07bc0945264da
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; import java.util.Map.Entry; import java.io.*; import static java.util.Map.Entry.*; /* Name of the class has to be "Main" only if the class is public. */ public class Main { static long mod=(long) (1e9+7); public static void main (String[] args) throws Exception { final long mod1=(long) 1e9+7; Reader s=new Reader(); PrintWriter pt=new PrintWriter(System.out); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); // int T=Integer.parseInt(br.readLine()); int T=s.nextInt(); // System.out.println(T); o:while(T-->0) { int c=s.nextInt(); int d=s.nextInt(); if((c+d)%2==1) { pt.println(-1); } else if(c==0&&d==0) { pt.println(0); } else if(c==d) { pt.println(1); } else { pt.println(2); } } pt.close(); } /** * Seive * * @param n length * @param factors factors[num] is smallest prime divisor of num * @param ar list of primes */ static void sieveOfEratosthenes(int n, int factors[], ArrayList<Integer> ar) { factors[1]=1; int p; for(p = 2; p*p <=n; p++) { if(factors[p] == 0) { ar.add(p); factors[p]=p; for(int i = p*p; i <= n; i += p) if(factors[i]==0) factors[i] = p; } } for(;p<=n;p++){ if(factors[p] == 0) { factors[p] = p; ar.add(p); } } } static int binarySearch(int arr[], int x) { int l = 0, r = arr.length - 1; while (l <= r) { int m = l + (r - l) / 2; // Check if x is present at mid if (arr[m] == x) return m; // If x greater, ignore left half if (arr[m] < x) l = m + 1; // If x is smaller, ignore right half else r = m - 1; } // if we reach here, then element was // not present return -1; } public static int getFreq(int arr[], int n) { int k=0; for(int i=0;i<arr.length;i++) { if(arr[i]==n) k++; } return k; } public static void primeFactors(int n) { // Print the number of 2s that divide n HashMap<Integer, Integer> hm=new HashMap<Integer, Integer>(); while (n%2==0) { hm.put(2, hm.getOrDefault(2, 0)+1); n/=2; } // n must be odd at this point. So we can // skip one element (Note i = i +2) for (int i = 3; i <= Math.sqrt(n); i+= 2) { // While i divides n, print i and divide n while (n%i == 0) { n /= i; hm.put(i, hm.getOrDefault(i, 0)+1); } } // This condition is to handle the case whien // n is a prime number greater than 2 if (n > 2) hm.put(n, hm.getOrDefault(n, 0)+1); } static boolean isPartition(int arr[], int n) { int sum = 0; int i, j; // Calculate sum of all elements for (i = 0; i < n; i++) sum += arr[i]; if (sum % 2 != 0) return false; boolean part[][]=new boolean[sum/2+1][n+1]; // initialize top row as true for (i = 0; i <= n; i++) part[0][i] = true; // initialize leftmost column, except part[0][0], as false for (i = 1; i <= sum / 2; i++) part[i][0] = false; // Fill the partition table in bottom up manner for (i = 1; i <= sum / 2; i++) { for (j = 1; j <= n; j++) { part[i][j] = part[i][j - 1]; if (i >= arr[j - 1]) part[i][j] = part[i][j] || part[i - arr[j - 1]][j - 1]; } } return part[sum / 2][n]; } static int setBit(int S, int j) { return S | 1 << j; } static int clearBit(int S, int j) { return S & ~(1 << j); } static int toggleBit(int S, int j) { return S ^ 1 << j; } static boolean isOn(int S, int j) { return (S & 1 << j) != 0; } static int turnOnLastZero(int S) { return S | S + 1; } static int turnOnLastConsecutiveZeroes(int S) { return S | S - 1; } static int turnOffLastBit(int S) { return S & S - 1; } static int turnOffLastConsecutiveBits(int S) { return S & S + 1; } static int lowBit(int S) { return S & -S; } static int setAll(int N) { return (1 << N) - 1; } static int modulo(int S, int N) { return (S & N - 1); } //S%N, N is a power of 2 static boolean isPowerOfTwo(int S) { return (S & S - 1) == 0; } static boolean isWithin(long x, long y, long d, long k) { return x*k*x*k + y*k*y*k <= d*d; } static long modFact(long n, long p) { if (n >= p) return 0; long result = 1; for (int i = 1; i <= n; i++) result = (result * i) % p; return result; } static int sum(int[] arr, int n) { int inc[]=new int[n+1]; int dec[]=new int[n+1]; inc[0] = arr[0]; dec[0] = arr[0]; for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (arr[j] > arr[i]) { dec[i] = max(dec[i], inc[j] + arr[i]); } else if (arr[i] > arr[j]) { inc[i] = max(inc[i], dec[j] + arr[i]); } } } return max(inc[n - 1], dec[n - 1]); } static long nc2(long a) { return a*(a-1)/2; } public static int numberOfprimeFactors(int n) { // Print the number of 2s that divide n HashSet<Integer> hs = new HashSet<Integer>(); while (n%2==0) { hs.add(2); n /= 2; } // n must be odd at this point. So we can // skip one element (Note i = i +2) for (int i = 3; i <= Math.sqrt(n); i+= 2) { // While i divides n, print i and divide n while (n%i == 0) { hs.add(i); n /= i; } } // This condition is to handle the case whien // n is a prime number greater than 2 if (n > 2) hs.add(n); return hs.size(); } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void reverse(int arr[],int start, int end) { int temp; while (start < end) { temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; } } static void reverse(long arr[],int start, int end) { long temp; while (start < end) { temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; } } static boolean isPrime(int n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int p2(int n) { int k=0; while(n>1) { if(n%2!=0) return k; n/=2; k++; } return k; } static boolean isp2(int n) { while(n>1) { if(n%2==1) return false; n/=2; } return true; } static int binarySearch(int arr[], int first, int last, int key){ int mid = (first + last)/2; while( first <= last ){ if ( arr[mid] < key ){ first = mid + 1; }else if ( arr[mid] == key ){ return mid; }else{ last = mid - 1; } mid = (first + last)/2; } return -1; } static void print(int a[][]) { for(int i=0;i<a.length;i++) { for(int j=0;j<a[0].length;j++) System.out.print(a[i][j]+" "); System.out.println(); } } static int max (int x, int y) { return (x > y)? x : y; } static int search(Pair[] p, Pair pair) { int l=0, r=p.length; while (l <= r) { int m = l + (r - l) / 2; if (p[m].compareTo(pair)==0) return m; if (p[m].compareTo(pair)<0) l = m + 1; else r = m - 1; } return -1; } static void pa(int a[]) { for(int i=0;i<a.length;i++) System.out.print(a[i]+" "); System.out.println(); } static void pa(long a[]) { for(int i=0;i<a.length;i++) System.out.print(a[i]+" "); System.out.println(); } static void reverseArray(int arr[], int start, int end) { int temp; while (start < end) { temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; } } static boolean isPalindrome(String s) { int l=s.length(); for(int i=0;i<l/2;i++) { if(s.charAt(i)!=s.charAt(l-i-1)) return false; } return true; } static long nc2(long n, long m) { return (n*(n-1)/2)%m; } static long c(long a) { return a*(a+1)/2; } static int next(int[] arr, int target) { int start = 0, end = arr.length - 1; int ans = -1; while (start <= end) { int mid = (start + end) / 2; // Move to right side if target is // greater. if (arr[mid] < target) { start = mid + 1; } // Move left side. else { ans = mid; end = mid - 1; } } return ans; } static int prev(Pair[] arr, int target) { int start = 0, end = arr.length - 1; int ans = -1; while (start <= end) { int mid = (start + end) / 2; // Move to left side if target is // lesser. if (arr[mid].a > target) { end = mid - 1; } // Move right side. else { ans = mid; start = mid + 1; } } return ans; } static long power(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static long modInverse(long n, long p) { return power(n, p-2, p); } static long nCrModP(long n, long r, long p) { if(r>n) return 0; if (r == 0) return 1; long[] fac = new long[(int) (n+1)]; fac[0] = 1; for (int i = 1 ;i <= n; i++) fac[i] = fac[i-1] * i % p; return (fac[(int) n]* modInverse(fac[(int) r], p) % p * modInverse(fac[(int) (n-r)], p) % p) % p; } static String reverse(String str) { return new StringBuffer(str).reverse().toString(); } static long fastpow(long x, long y, long m) { if (y == 0) return 1; long p = fastpow(x, y / 2, m) % m; p = (p * p) % m; if (y % 2 == 0) return p; else return (x * p) % m; } static boolean isPerfectSquare(long l) { return Math.pow((long)Math.sqrt(l),2)==l; } static void merge(long[] arr, int l, int m, int r) { // Find sizes of two subarrays to be merged int n1 = m - l + 1; int n2 = r - m; /* Create temp arrays */ long L[] = new long [n1]; long R[] = new long [n2]; /*Copy data to temp arrays*/ for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; /* Merge the temp arrays */ // Initial indexes of first and second subarrays int i = 0, j = 0; // Initial index of merged subarry array int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } /* Copy remaining elements of L[] if any */ while (i < n1) { arr[k] = L[i]; i++; k++; } /* Copy remaining elements of R[] if any */ while (j < n2) { arr[k] = R[j]; j++; k++; } } // Main function that sorts arr[l..r] using // merge() static void sort(int arr[], int l, int r) { if (l < r) { // Find the middle point int m = (l+r)/2; // Sort first and second halves sort(arr, l, m); sort(arr , m+1, r); // Merge the sorted halves merge(arr, l, m, r); } } static void merge(int arr[], int l, int m, int r) { // Find sizes of two subarrays to be merged int n1 = m - l + 1; int n2 = r - m; /* Create temp arrays */ int L[] = new int [n1]; int R[] = new int [n2]; /*Copy data to temp arrays*/ for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; /* Merge the temp arrays */ // Initial indexes of first and second subarrays int i = 0, j = 0; // Initial index of merged subarry array int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } /* Copy remaining elements of L[] if any */ while (i < n1) { arr[k] = L[i]; i++; k++; } /* Copy remaining elements of R[] if any */ while (j < n2) { arr[k] = R[j]; j++; k++; } } // Main function that sorts arr[l..r] using // merge() static void sort(long arr[], int l, int r) { if (l < r) { // Find the middle point int m = (l+r)/2; // Sort first and second halves sort(arr, l, m); sort(arr , m+1, r); // Merge the sorted halves merge(arr, l, m, r); } } static class Pair implements Comparable<Pair>{ int a; int b; Pair(int a,int b){ this.a=a; this.b=b; } public int compareTo(Pair p){ if(a>p.a) return 1; if(a==p.a) return (b-p.b); return -1; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[128]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
3751b070737f93af3241e9996d6b7d24
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.util.StringTokenizer; // نورت الكود يا كبير اتفضل // يا رب Accepted public class VarietyOfOperations { public static void main(String[] args) throws FileNotFoundException { FastReader in = new FastReader(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t = in.nextInt(); while (t-- > 0) { int a = in.nextInt(); int b = in.nextInt(); if (a == b && a == 0) out.println("0"); else if (a == b && a != 0) out.println("1"); else if ((Math.abs(a - b)) % 2 == 0) out.println("2"); else out.println("-1"); } out.close(); } private static class FastReader { BufferedReader br; StringTokenizer st; FastReader() throws FileNotFoundException { br = new BufferedReader(new InputStreamReader(System.getProperty("ONLINE_JUDGE") == null ? new FileInputStream("input.txt") : System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
f6b9ad866337300f98d64a58f6442f2f
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.util.*; public class A { public static void main(String[] args) { FastReader in = new FastReader(); int T = in.nextInt(); while(T-- > 0) { int c = in.nextInt(); int d = in.nextInt(); if(c%2 != d%2) System.out.println(-1); else if(c==0 && d==0) System.out.println(0); else if(c==d) System.out.println(1); else System.out.println(2); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch(IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch(IOException e) { e.printStackTrace(); } return str; } int[] readInt(int size) { int[] arr = new int[size]; for(int i = 0; i < size; i++) arr[i] = Integer.parseInt(next()); return arr; } long[] readLong(int size) { long[] arr = new long[size]; for(int i = 0; i < size; i++) arr[i] = Long.parseLong(next()); return arr; } int[][] read2dArray(int rows, int cols) { int[][] arr = new int[rows][cols]; for(int i = 0; i < rows; i++) { for(int j = 0; j < cols; j++) arr[i][j] = Integer.parseInt(next()); } return arr; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
30b7eee78c5135bf3b92bbb190cf5f09
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class VarietyOfOperations { public static void main(String[]args) throws NumberFormatException, IOException { InputStreamReader is = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(is); int testCases = Integer.parseInt(br.readLine()); for(int i =0; i<testCases; i++) { String[]vals = br.readLine().split(" "); int a = Integer.parseInt(vals[0]); int b = Integer.parseInt(vals[1]); if(Math.abs(a-b)%2==1) { System.out.println("-1"); } else { if(a==0 && b ==0) { System.out.println(0); } else if(a==b) { System.out.println(1); } else { System.out.println(2); } } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
47fdd015c9ac8ba6c00fd707fbdfccad
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; public class Solve { public static int solve(int n, int m) { if (n == m) { if (n == 0) return 0; else return 1; } int diff = Math.abs(n - m); if (diff % 2 == 0) { return 2; } return -1; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); // scanner.nextLine(); while (t-- > 0) { int n = scanner.nextInt(); int m = scanner.nextInt(); System.out.println(solve(n, m)); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
6253cdd409bf3c6d45b7ad08b73213c0
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class JavaApplication1 { static int Variety(int a,int b){ int answer=0; if(a==b){ if(b==0)answer = 0; else answer=1; } else if((a-b)%2==0) answer=2; else answer=-1; return answer; } public static void main(String[] args) { Scanner in=new Scanner(System.in); int num=in.nextInt(); int a,b; while(num!=0){ num--; a=in.nextInt(); b=in.nextInt(); System.out.println(Variety(a,b)); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
6aa26496abef446b2e01ce1bec4e6b4e
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class Main { /* public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] stones = new int[n]; int tw = 0; for(int i = 0; i < n; i ++) { stones[i] = sc.nextInt(); tw += stones[i]; } boolean[][] c = new boolean[n + 1][2 * tw + 1]; for(int i = 0; i < n + 1; i ++) { for(int j = 0; j < 2 * tw + 1; j ++) { c[i][j] = false; } } c[0][tw] = true; for(int i = 1; i <= n; i ++) { for(int j = 0; j <= 2 * tw; j ++) { c[i][j] |= c[i - 1][j]; if(j >= stones[i - 1]) c[i][j] |= c[i - 1][j - stones[i - 1]]; if(j + stones[i - 1] <= 2 * tw) c[i][j] |= c[i - 1][j + stones[i - 1]]; } } int m = sc.nextInt(); for(int i = 0; i < m; i ++) { int q = sc.nextInt(); if(q > tw) System.out.println("NO"); else { if(c[n][tw - q] || c[n][tw + q]) System.out.println("YES"); else System.out.println("NO"); } } } */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a, b; for(int i = 0; i < n; i ++) { a = sc.nextInt(); b = sc.nextInt(); if(a == 0 && b == 0) System.out.println(0); else if(a == b) System.out.println(1); else if((a - b) / 2 * 2 == (a - b)) System.out.println(2); else System.out.println(-1); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
347d77ee1b93a77f8b652b49e3a52ab5
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int tc = sc.nextInt(); while(tc-->0) { int c = sc.nextInt(); int d = sc.nextInt(); if(c==0 && d==0) System.out.println(0); else if(c==d) System.out.println(1); else if(Math.abs(c-d)%2==0) System.out.println(2); else System.out.println(-1); } sc.close(); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
cb7708452791d538e54964a760d27bed
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int c = sc.nextInt(); int d = sc.nextInt(); if((c+d)%2 != 0) System.out.println("-1"); else { int mid = (c+d)/2; if(mid == 0) System.out.println("0"); else if(mid == c) System.out.println("1"); else System.out.println("2"); } } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
234584a11229695968bba7f7c7494300
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.util.*; public class Main{ static void main() throws Exception{ int c=sc.nextInt(),d=sc.nextInt(); if(d<c) { int tmp=c; c=d; d=tmp; } if(((d-c)%2==1)) { pw.println(-1); return; } if(d==0) { pw.println(0); return; } if(c==d) { pw.println(1); return; } pw.println(2); } public static void main(String[] args) throws Exception{ sc=new MScanner(System.in); pw = new PrintWriter(System.out); int tc=1; tc=sc.nextInt(); for(int i=1;i<=tc;i++) { // pw.printf("Case %d:\n", i); main(); } pw.flush(); } static PrintWriter pw; static MScanner sc; static class MScanner { StringTokenizer st; BufferedReader br; public MScanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public MScanner(String file) throws Exception { br = new BufferedReader(new FileReader(file)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int[] intArr(int n) throws IOException { int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt(); return in; } public long[] longArr(int n) throws IOException { long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong(); return in; } public int[] intSortedArr(int n) throws IOException { int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt(); shuffle(in); Arrays.sort(in); return in; } public long[] longSortedArr(int n) throws IOException { long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong(); shuffle(in); Arrays.sort(in); return in; } public Integer[] IntegerArr(int n) throws IOException { Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt(); return in; } public Long[] LongArr(int n) throws IOException { Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong(); return in; } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public long nextLong() throws IOException { return Long.parseLong(next()); } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() throws InterruptedException { Thread.sleep(3000); } } static void shuffle(int[]in) { for(int i=0;i<in.length;i++) { int idx=(int)(Math.random()*in.length); int tmp=in[i]; in[i]=in[idx]; in[idx]=tmp; } } static void shuffle(long[]in) { for(int i=0;i<in.length;i++) { int idx=(int)(Math.random()*in.length); long tmp=in[i]; in[i]=in[idx]; in[idx]=tmp; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
5026b6139cb7175285a18151544b47fa
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.*; import java.util.*; public class A { public static void main(String[] args) { FastScanner sc = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int TT = sc.nextInt(); while (TT-- > 0) { int c = sc.nextInt(), d = sc.nextInt(); if (c == d) out.println(c == 0 ? 0 : 1); else if (Math.abs(c - d) % 2 == 0) out.println(2); else out.println(-1); } out.close(); } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
04608bf78906fe27f8fb9a807f3f5a56
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class p1556A { public static void main(String[] args) { Scanner sc=new Scanner(System.in); for(int t=sc.nextInt();t-->0;) { int c=sc.nextInt(),d=sc.nextInt(); if((c+d)%2!=0) System.out.println(-1); else if(c==0&&d==0) System.out.println(0); else if(c==d) System.out.println(1); else System.out.println(2); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
cac0e783d15932b12045dfeb52427844
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; public class Juego { //********************************************************* static LinkedList<Integer> cola; static HashSet<String> memo = new HashSet<>(); public static void bfs() { while(!cola.isEmpty()){ int a = cola.pollFirst(); int b = cola.pollFirst(); int nivel = cola.pollFirst(); String str = String.valueOf(a)+"|"+String.valueOf(b); System.out.println(a + "," + b + "," + str + "," + nivel); for (int k=1;k<=5;k++){ agregar( a+k , b+k , nivel); agregar( a+k , b-k , nivel); agregar( a-k , b+k , nivel); } } } //********************************************************* static void agregar(int a, int b, int nivel){ String str = String.valueOf(a)+"|"+String.valueOf(b); if ( ! memo.contains(str)){ cola.add(a); cola.add(b); cola.add(nivel+1); memo.add(str); } } //********************************************************* public static void main(String[] args) { /*cola = new LinkedList<>(); cola.add(0); cola.add(0); cola.add(0); memo.add(String.valueOf(0)+"|"+String.valueOf(0)); bfs();*/ Scanner sc = new Scanner(System.in); int casos = sc.nextInt(); int res = 99; for (int k=0;k<casos;k++){ int a = sc.nextInt(); int b = sc.nextInt(); if (a==b){ res = 1; if (a==0 && b==0) res = 0; } else{ res = Math.abs(a-b); if (res%2==1){ res = -1; } else{ if (res/2 == Math.max(a, b)) res = 1; else res = 2; } } //System.out.println(a + " " + b + " res: " + res); System.out.println(res); } } //********************************************************* }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
4d12454f83e5c13972446bceb7ba8dd3
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.util.*; public class Scratch { public static void main(String[] args) throws IOException { Reader sc=new Reader(); int p=sc.nextInt(); for (int q=0;q<p;q++) { int n=sc.nextInt(); int m=sc.nextInt(); if (n==0 && m==0) System.out.println(0); else if (n==m) System.out.println(1); else if ((n-m)%2==0) System.out.println(2); else System.out.println(-1); } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } // Function to return gcd of a and b }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
07b7be071594f165148359aaea2004f7
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
/*========================================================================== * AUTHOR: RonWonWon * CREATED: 03.09.2021 10:32:42 /*==========================================================================*/ import java.io.*; import java.util.*; public class A { public static void main(String[] args) throws IOException { /* in.ini(); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); */ long startTime = System.nanoTime(); int t = in.nextInt(), T = 1; while(t-->0) { int a = in.nextInt(), b = in.nextInt(); if(a==0&&b==0) out.println(0); else if(a==b) out.println(1); else if(Math.abs(a-b)%2==0) out.println(2); else out.println(-1); //out.println("Case #"+T+": "+ans); T++; } /* startTime = System.nanoTime() - startTime; System.err.println("Time: "+(startTime/1000000)); */ out.flush(); } static FastScanner in = new FastScanner(); static PrintWriter out = new PrintWriter(System.out); static int oo = Integer.MAX_VALUE; static long ooo = Long.MAX_VALUE; static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); void ini() throws FileNotFoundException { br = new BufferedReader(new FileReader("input.txt")); } String next() { while(!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch(IOException e) {} return st.nextToken(); } String nextLine(){ try{ return br.readLine(); } catch(IOException e) { } return ""; } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int a[] = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } long[] readArrayL(int n) { long a[] = new long[n]; for(int i=0;i<n;i++) a[i] = nextLong(); return a; } double nextDouble() { return Double.parseDouble(next()); } double[] readArrayD(int n) { double a[] = new double[n]; for(int i=0;i<n;i++) a[i] = nextDouble(); return a; } } static final Random random = new Random(); static void ruffleSort(int[] a){ int n = a.length; for(int i=0;i<n;i++){ int j = random.nextInt(n), temp = a[j]; a[j] = a[i]; a[i] = temp; } Arrays.sort(a); } static void ruffleSortL(long[] a){ int n = a.length; for(int i=0;i<n;i++){ int j = random.nextInt(n); long temp = a[j]; a[j] = a[i]; a[i] = temp; } Arrays.sort(a); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
c41ba346c85718ed366872f933f1f9fd
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuffer out = new StringBuffer(); int T = in.nextInt(); OUTER: while (T-- > 0) { int c = in.nextInt(); int d = in.nextInt(); int diff=Math.abs(c-d); if(diff%2==1) { out.append("-1"); } else { if(diff==0) { if(c==0) { out.append("0"); } else { out.append("1"); } } else { out.append("2"); } } out.append("\n"); } System.out.print(out); } private static long gcd(long a, long b) { if (a==0) return b; return gcd(b%a, a); } private static int toInt(String s) { return Integer.parseInt(s); } private static long toLong(String s) { return Long.parseLong(s); } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output
PASSED
b1b248d48754c747d2ed7ad6a9cbecc6
train_107.jsonl
1630247700
William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ 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 $$$k$$$) add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.
256 megabytes
import java.util.Scanner; public class Operations { static int varietyOperations(int a, int b) { int c = 0; int d = Math.abs(a - b); if (a == 0 && b == 0) { c = 0; } else if (a == b) { c = 1; } else if (d % 2 == 0) { c = 2; } else if (d % 2 != 0) { c = -1; } return c; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { int a = sc.nextInt(); int b = sc.nextInt(); System.out.println(varietyOperations(a, b)); } } }
Java
["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0"]
1 second
["-1\n2\n2\n1\n2\n0"]
NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$: Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$. Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$. Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$. Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.
Java 8
standard input
[ "math" ]
8e7c0b703155dd9b90cda706d22525c9
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.
800
For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.
standard output