#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
const int mod = 1e9 + 7;
signed main() {
//	int n;
//	cin >> n;
//	int x;
//	vector<int> a(n);
//	vector<int> b(n);
//	for (int i = 0; i < n; i++) {
//		cin >> a[i];
//		x = a[i];
//	}
//	for (int i = 0; i < n; i++) {
//		cin >> b[i];
//	}
//	if(n<3) {
//		cout<<"0";
//		return 0;
//	}
//	cout << (n - 2) * x;
	int n;	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	cin >> a[0] >> a[1] >> b[0] >> b[1];
//	int t = a[0] - min(a[0], b[1]);
//	int ans1 = min(a[0], b[1]) - b[0] + t;
	int ans1 = 0, ans2 = 0, ans3 = 0, ans4 = 0;
	if(a[0] < b[0]) {
		b[0] -= a[0];
		ans1 -= b[0];
	}
	else {
		a[0] -= b[0];
		if (b[1] > a[0]) {
			ans2 = min(a[0], b[1]);
		}
		else {
			ans2 = b[1];
		}
	}
	
	
	if (a[0] < b[1]) {
		ans3 += a[0];
		ans3 -= b[0];
	}
	
	else {
		ans4 += b[1];
		a[0] -= b[1];
		if (a[0] < b[0]) {
			b[0] -= a[0];
			ans4 -= b[0];
		}
	}
	cout << max({ans1, ans2, ans3, ans4});
	return 0;
}	
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |