l1,r1,l2,r2,k=map(int,input().split())
l=max(l1,l2)
r=min(r1,r2)
if (l>r):
print(0)
else:
if (k>=l and k<=r):
print(r-l)
else:
print(r-l+1)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const ll MAXN = 2e5+100;
#define io ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define ll long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define all(a) (a).begin(), (a).end()
#define sz(a) (a).size()
#define fork(i,a,n) for(ll i=a; i<n; i++)
#define kfor(i,a,n) for(ll i=a; i>=n; i--)
#define input(v,n) for(ll i=0; i<n; i++) cin>>v[i];
#define max(x) *max_element(all(x))
#define min(x) *min_element(all(x))
#define sum(x) accumulate(all(x), 0LL)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
void ok(bool foo){foo?yes:no;}
//cout << fixed << setprecision(n) << << endl;
int main(){
io
ll l1, r1, l2, r2, k, c1, c2, c=0;
cin >> l1 >> r1 >> l2 >> r2 >> k;
if(l1 <= l2){
if(r1 >= r2) {
if(k >= l2 and k <= r2) {
c = r2 - l2;
}
else {
c = r2 - l2 + 1;
}
}
else if(r1 < l2) {
}
else if(k <= r1 and k >= l2) {
c = r1 - l2;
}
else {
c = r1 - l2 + 1;
}
}
else {
if(r2 >= r1) {
if(k >= l1 and k <= r1) {
c = r1 - l1;
}
else {
c = r1 - l1 + 1;
}
}
else if(r2 < l1) {
}
else if(k <= r2 and k >= l1) {
c = r2 - l1;
}
else {
c = r2 - l1 + 1;
}
}
cout << c << endl;
return 0;
}
975C - Valhalla Siege | 518B - Tanya and Postcard |
514B - Han Solo and Lazer Gun | 898B - Proper Nutrition |
9C - Hexadecimal's Numbers | 1265B - Beautiful Numbers |
745A - Hongcow Learns the Cyclic Shift | 873A - Chores |
1754B - Kevin and Permutation | 1547D - Co-growing Sequence |
1754D - Factorial Divisibility | 1117B - Emotes |
412B - Network Configuration | 845B - Luba And The Ticket |
1732A - Bestie | 389A - Fox and Number Game |
1732B - Ugu | 1100B - Build a Contest |
1181B - Split a Number | 1313B - Different Rules |
1736D - Equal Binary Subsequences | 1754A - Technical Support |
26B - Regular Bracket Sequence | 699A - Launch of Collider |
474D - Flowers | 1016A - Death Note |
1335C - Two Teams Composing | 1167C - News Distribution |
813C - The Tag Game | 1130C - Connect |