#include <bits/stdc++.h>
using namespace std;
const int INFi = 2e9 + 5;
const int maxN = 2e5 + 5;
const int md = 998244353;
const long long INF = 2e18;
double getTime() { return clock() / (double)CLOCKS_PER_SEC; }
vector<pair<int, int>> solve(vector<int> &a) {
  int n = a.size();
  vector<pair<int, int>> stk = {{-INFi, -INFi}};
  vector<pair<int, int>> result(n);
  for (int i = 0; i < (n); ++i) {
    int mx = stk.back().second;
    while (!stk.empty() && stk.back().first >= a[i]) {
      stk.pop_back();
      mx = max(mx, stk.back().second);
    }
    stk.back().second = max(mx, a[i]);
    if (stk.size() == 1) mx = INFi;
    result[i] = {a[i], mx};
    stk.emplace_back(a[i], -INFi);
  }
  stk = {{-INFi, -INFi}};
  for (int i = n - 1; i >= 0; --i) {
    int mx = stk.back().second;
    while (!stk.empty() && stk.back().first > a[i]) {
      stk.pop_back();
      mx = max(mx, stk.back().second);
    }
    stk.back().second = max(mx, a[i]);
    if (stk.size() == 1) mx = INFi;
    result[i].second = min(result[i].second, mx);
    stk.emplace_back(a[i], -INFi);
  }
  return result;
}
struct fenwick {
  int n{};
  vector<long long> fenw{};
  void build(int k) {
    n = k;
    fenw.resize(n);
  }
  void upd(int i, long long x) {
    for (; i < n; i = i | (i + 1)) fenw[i] += x;
  }
  long long get(int i) {
    long long res = 0;
    for (; i >= 0; i = (i & (i + 1)) - 1) res += fenw[i];
    return res;
  }
  long long get(int l, int r) {
    if (l > r) return 0;
    return get(r) - get(l - 1);
  }
};
void solve() {
  int n, m;
  cin >> n >> m;
  int x;
  cin >> x;
  vector<int> a(n), b(m);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  for (int i = 0; i < (m); ++i) cin >> b[i];
  auto p1 = solve(a), p2 = solve(b);
  sort((p1).begin(), (p1).end());
  sort((p2).rbegin(), (p2).rend());
  int j = 0;
  multiset<pair<int, int>> have;
  fenwick f;
  f.build(maxN);
  long long ans = 0;
  for (auto &[c, ct] : p2) {
    while (j < n && p1[j].first + c <= x) {
      have.insert({p1[j].second, p1[j].first});
      f.upd(p1[j].first, 1);
      j++;
    }
    while (!have.empty() && have.begin()->first + c <= x) {
      f.upd(have.begin()->second, -1);
      have.erase(have.begin());
    }
    if (ct == -INFi) continue;
    ans += f.get(x - ct + 1, maxN - 1);
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tests = 1;
  for (int _ = 0; _ < (tests); ++_) {
    solve();
  }
  return 0;
}
