#include <bits/stdc++.h>
using namespace std;
const int N = 200010, LG = 18, Inf = 1e9;
int n, m, k, a[N], b[N], c[N], d[N], lg[N], st[N][LG + 1];
long long ans;
pair<int, pair<int, int> > qry[N * 2];
stack<int> s;
void buildst(int n, int *a) {
  for (int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;
  for (int i = 1; i <= n; i++) st[i][0] = a[i];
  for (int i = n; i >= 1; i--)
    for (int j = 1; i + (1 << j) - 1 <= n; j++)
      st[i][j] = max(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);
}
int query(int l, int r) {
  int k = lg[r - l + 1];
  return max(st[l][k], st[r - (1 << k) + 1][k]);
}
void work(int n, int *a, int *c) {
  for (int i = 1; i <= n; i++) {
    c[i] = Inf;
    while (s.size() && a[s.top()] >= a[i]) s.pop();
    if (s.size()) c[i] = query(s.top() + 1, i);
    s.push(i);
  }
  while (s.size()) s.pop();
  for (int i = n; i >= 1; i--) {
    while (s.size() && a[s.top()] > a[i]) s.pop();
    if (s.size()) c[i] = min(c[i], query(i, s.top() - 1));
    s.push(i);
  }
  while (s.size()) s.pop();
}
struct BIT {
  int c[N];
  void add(int x, int v) {
    for (int i = x; i < N; i += i & -i) c[i] += v;
  }
  int query(int x) {
    int ans = 0;
    for (int i = x; i > 0; i -= i & -i) ans += c[i];
    return ans;
  }
} bit[2];
bool cmp(pair<int, pair<int, int> > x, pair<int, pair<int, int> > y) {
  return x.second.first - x.first > y.second.first - y.first;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
  buildst(n, a);
  work(n, a, c);
  buildst(m, b);
  work(m, b, d);
  for (int i = 1; i <= n; i++) qry[i] = make_pair(a[i], make_pair(c[i], 0));
  for (int i = 1; i <= m; i++) qry[i + n] = make_pair(b[i], make_pair(d[i], 1));
  sort(qry + 1, qry + 1 + n + m, cmp);
  for (int i = 1; i <= n + m; i++) {
    int x = qry[i].first, y = qry[i].second.first, typ = qry[i].second.second;
    if (x <= y) ans += bit[typ ^ 1].query(k - x) - bit[typ ^ 1].query(k - y);
    bit[typ].add(x, 1);
  }
  cout << ans;
  return 0;
}
