#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
const int OO = 0;
const int md = 998244353;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll gcd(ll x, ll y) {
x = max(x, y);
y = min(x, y);
ll z;
while (y > 0) {
z = x;
x = y;
y = z % y;
}
return x;
}
struct rect {
int xlo, xhi;
int ylo, yhi;
rect() {}
rect(int _xlo, int _xhi, int _ylo, int _yhi) {
xlo = _xlo;
xhi = _xhi;
ylo = _ylo;
yhi = _yhi;
}
bool operator < (const rect& a) const {
return ylo < a.ylo;
}
};
const int N = 2002;
int first[4][N];
bool intersect_range(int alo, int ahi, int blo, int bhi) {
if (ahi < blo || bhi < alo) return false;
return true;
}
bool intersect(const rect& a, const rect& b) {
return intersect_range(a.xlo, a.xhi, b.xlo, b.xhi) && intersect_range(a.ylo, a.yhi, b.ylo, b.yhi);
}
bool check(int sz, const rect& a, vector<rect> &build) {
if (!(0 <= a.xlo && a.xhi < sz && 0 <= a.ylo && a.yhi < sz)) return false;
for (int i = 0; i + 1 < build.size(); i++)
if (intersect(a, build[i])) return false;
return true;
}
bool work(int sz, int i, vector<pair<int, int>> &a, vector<rect> &build) {
if (i == 4) return true;
auto tmpbuild = build;
sort(build.begin(), build.end());
// get first for each row
for (int row = 0; row < sz; row++) {
int nxt = 0;
for (auto& b : build) {
if (b.xlo <= row && row <= b.xhi && nxt == b.ylo)
nxt = b.yhi + 1;
}
first[i][row] = nxt;
}
build = tmpbuild;
if (OO) {
cout << "build:\n";
for (auto& i : build) {
cout << i.xlo << " " << i.xhi << " " << i.ylo << " " << i.yhi << endl;
}
cout << "firsts:\n";
for (int row = 0; row < sz; row++)
cout << first[i][row] << endl;
cout << endl;
}
// try no rotation
if (first[i][0] < sz) {
build.push_back(rect(0, 0 + a[i].first - 1, first[i][0], first[i][0] + a[i].second - 1));
if (check(sz, build.back(), build) && work(sz, i + 1, a, build)) return true;
build.pop_back();
}
for (int row = 1; row < sz; row++) {
if (first[i][row - 1] > first[i][row]) {
build.push_back(rect(row, row + a[i].first - 1, first[i][row], first[i][row] + a[i].second - 1));
if (check(sz, build.back(), build) && work(sz, i + 1, a, build)) return true;
build.pop_back();
}
}
// try rotation
swap(a[i].first, a[i].second);
if (first[i][0] < sz) {
build.push_back(rect(0, 0 + a[i].first - 1, first[i][0], first[i][0] + a[i].second - 1));
if (check(sz, build.back(), build) && work(sz, i + 1, a, build)) return true;
build.pop_back();
}
for (int row = 1; row < sz; row++) {
if (first[i][row - 1] > first[i][row]) {
build.push_back(rect(row, row + a[i].first - 1, first[i][row], first[i][row] + a[i].second - 1));
if (check(sz, build.back(), build) && work(sz, i + 1, a, build)) return true;
build.pop_back();
}
}
return false;
}
void solve() {
vector<pair<int, int>> a(4);
for (int i = 0; i < 4; i++) {
cin >> a[i].first;
cin >> a[i].second;
}
int area = 0;
for (auto b: a) {
area += b.first * b.second;
}
int side = int(sqrt(area));
for (int i = max(1, side - 3); i <= side + 3; i++) {
if (i * i == area) {
side = i;
break;
}
}
if (side * side != area) {
cout << 0 << endl;
return;
}
sort(a.begin(), a.end());
do {
vector<rect> build;
if (work(side, 0, a, build)) {
if (OO) {
cout << "won with:" << endl;
cout << "a:" << endl;
for (const auto& i : a) cout << i.first << " " << i.second << endl;
cout << endl;
for (auto& i : build) {
cout << i.xlo << " " << i.xhi << " " << i.ylo << " " << i.yhi << endl;
}
}
cout << 1 << endl;
return;
}
} while (next_permutation(a.begin(), a.end()));
cout << 0 << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tests = 1;
//cin >> tests;
while (tests--) solve();
}