Algorithm


B. Intersection
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two set of points. The first set is determined by the equation A1x + B1y + C1 = 0, and the second one is determined by the equation A2x + B2y + C2 = 0.

Write the program which finds the number of points in the intersection of two given sets.

Input

The first line of the input contains three integer numbers A1, B1, C1 separated by space. The second line contains three integer numbers A2, B2, C2 separated by space. All the numbers are between -100 and 100, inclusive.

Output

Print the number of points in the intersection or -1 if there are infinite number of points.

Examples
input
Copy
1 1 0
2 2 0
output
Copy
-1
input
Copy
1 1 0
2 -2 0
output
Copy
1



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <iostream>

using namespace std;

int main() {
    int a1, b1, c1, a2, b2, c2;
    cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2;
    
    if((a1 == 0 && b1 == 0) && (a2 == 0 && b2 == 0) && c1 != c2) {
    	cout << 0 << endl;
    	return 0;
    }
    
    if((a1 == 0 && b1 == 0 && c1 == 0) || (a2 == 0 && b2 == 0 && c2 == 0)) {
    	cout << -1 << endl;
    	return 0;
    }
    
    if((a1 == 0 && b1 == 0 && c1 != 0) || (a2 == 0 && b2 == 0 && c2 != 0) && (c1 == c2)) {
    	cout << 0 << endl;
    	return 0;
    }
    
    if(a1 * b2 == b1 * a2 && b2 * c1 == c2 * b1 && c1 * a2 == c2 * a1) {
    	cout << -1 << endl;
    	return 0;
    }
    
    if(((a1 * b2) - (a2 * b1)) == 0) {
    	cout << 0 << endl;
    	return 0;
    }

    cout << 1 << endl;
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
1 1 0
2 2 0

Output

x
+
cmd
-1
Advertisements

Demonstration


Codeforcess Solution 21B. Intersection C,C++, Java, Js and Python ,21B. Intersection,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+