#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int S[200005], S2[200005];
void add(int first, int k, int *S) {
  for (int i = first; i < 200005; i += i & -i) {
    S[i] += k;
  }
}
int query(int first, int *S) {
  if (first <= 0) return 0;
  int res = 0;
  for (int i = first; i > 0; i -= i & -i) {
    res += S[i];
  }
  return res;
}
void solve() {
  int n, m, X;
  scanf("%d %d %d", &n, &m, &X);
  int a[200005];
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  vector<pair<int, int> > v;
  int lx[200005], rx[200005];
  memset(lx, 0, sizeof(lx));
  memset(rx, 0, sizeof(rx));
  for (int i = 1; i <= n; i++) {
    while (v.size() && v.back().first > a[i]) {
      lx[i] = max(lx[i], v.back().first);
      lx[i] = max(lx[i], lx[v.back().second]);
      v.pop_back();
    }
    if (v.empty()) lx[i] = 1e9;
    v.push_back(make_pair(a[i], i));
  }
  v.clear();
  for (int i = n; i >= 1; i--) {
    while (v.size() && v.back().first >= a[i]) {
      rx[i] = max(rx[i], v.back().first);
      rx[i] = max(rx[i], rx[v.back().second]);
      v.pop_back();
    }
    if (v.empty()) rx[i] = 1e9;
    v.push_back(make_pair(a[i], i));
  }
  v.clear();
  int b[200005];
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
  int ly[200005], ry[200005];
  memset(ly, 0, sizeof(ly));
  memset(ry, 0, sizeof(ry));
  for (int i = 1; i <= m; i++) {
    while (v.size() && v.back().first > b[i]) {
      ly[i] = max(ly[i], v.back().first);
      ly[i] = max(ly[i], ly[v.back().second]);
      v.pop_back();
    }
    if (v.empty()) ly[i] = 1e9;
    v.push_back(make_pair(b[i], i));
  }
  v.clear();
  for (int i = m; i >= 1; i--) {
    while (v.size() && v.back().first >= b[i]) {
      ry[i] = max(ry[i], v.back().first);
      ry[i] = max(ry[i], ry[v.back().second]);
      v.pop_back();
    }
    if (v.empty()) ry[i] = 1e9;
    v.push_back(make_pair(b[i], i));
  }
  v.clear();
  vector<pair<pair<int, int>, int> > vv;
  for (int i = 1; i <= n; i++) {
    vv.push_back(make_pair(make_pair(min(lx[i], rx[i]) - a[i], a[i]), 0));
  }
  for (int i = 1; i <= m; i++) {
    vv.push_back(make_pair(make_pair(min(ly[i], ry[i]) - b[i], b[i]), 1));
  }
  sort(vv.begin(), vv.end());
  long long ans = 0;
  reverse(vv.begin(), vv.end());
  for (auto it : vv) {
    int ax = it.first.first + it.first.second;
    if (it.second == 0) {
      add(it.first.second, 1, S);
      if (X - it.first.second > X - ax)
        ans += query(X - it.first.second, S2) - query(X - ax, S2);
    } else {
      add(it.first.second, 1, S2);
      if (X - it.first.second > X - ax)
        ans += query(X - it.first.second, S) - query(X - ax, S);
    }
  }
  printf("%lld\n", ans);
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
