#include<iostream>
#include<queue>;
using namespace std;

#define MAX 1000000001
long long CNT = 0;

void merge(long long a[], int begin, int end, int mid) {
	queue<long long> left;
	queue<long long> right;
	for (int i = begin; i < mid; i++)left.push(a[i]);
	for (int i = mid; i < end; i++)right.push(a[i]);
	left.push(MAX);
	right.push(MAX);

	int cnt = left.size() - 1;
	for (int i = begin; i < end; i++) {
		if (left.front() < right.front()) {
			a[i] = left.front();
			left.pop();
			cnt--;
		}
		else {
			a[i] = right.front();
			right.pop();
			CNT += cnt;
		}
	}
}

void m_sort(long long a[], int begin, int end) {
	if (begin >= end - 1)return;
	int mid = (begin + end) / 2;
	
	m_sort(a, begin, mid);
	m_sort(a, mid, end);

	merge(a, begin, end, mid);
}

int main() {
	long long ary[200000];
	int n;
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> ary[i];
	}

	m_sort(ary, 0, n);

	cout << CNT << endl;
	return 0;
}
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class ATravelingBudget {
public:
	void solve(istream& in, ostream& out) {
        int a,b,c,d;
        in >> a >> b >> c >> d;
        int t = min(a,b);
        int v = min(c,d);
        out << t + v << endl;
	}
};

int main() {
	ATravelingBudget solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}