#include <bits/stdc++.h>
using namespace std;
int N, A[200005], B[200005], sparseTable_1[200005][20],
    sparseTable_2[200005][20];
void build_1() {
  for (int i = 0; i < N; i++) sparseTable_1[i][0] = i;
  for (int j = 1; (1 << j) <= N; j++)
    for (int i = 0; i + (1 << j) - 1 < N; i++)
      if (A[sparseTable_1[i][j - 1]] >
          A[sparseTable_1[i + (1 << (j - 1))][j - 1]])
        sparseTable_1[i][j] = sparseTable_1[i][j - 1];
      else
        sparseTable_1[i][j] = sparseTable_1[i + (1 << (j - 1))][j - 1];
}
int query_1(int i, int j) {
  int k = (int)floor(log((double)j - i + 1) / log(2.0));
  if (A[sparseTable_1[i][k]] >= A[sparseTable_1[j - (1 << k) + 1][k]])
    return sparseTable_1[i][k];
  return sparseTable_1[j - (1 << k) + 1][k];
}
void build_2() {
  for (int i = 0; i < N; i++) sparseTable_2[i][0] = i;
  for (int j = 1; (1 << j) <= N; j++)
    for (int i = 0; i + (1 << j) - 1 < N; i++)
      if (B[sparseTable_2[i][j - 1]] <
          B[sparseTable_2[i + (1 << (j - 1))][j - 1]])
        sparseTable_2[i][j] = sparseTable_2[i][j - 1];
      else
        sparseTable_2[i][j] = sparseTable_2[i + (1 << (j - 1))][j - 1];
}
int query_2(int i, int j) {
  int k = (int)floor(log((double)j - i + 1) / log(2.0));
  if (B[sparseTable_2[i][k]] <= B[sparseTable_2[j - (1 << k) + 1][k]])
    return sparseTable_2[i][k];
  return sparseTable_2[j - (1 << k) + 1][k];
}
int lower_bound(int x) {
  int ki = x, ka = N;
  while (ki < ka) {
    int tgh = (ki + ka) / 2;
    if (A[query_1(x, tgh)] - B[query_2(x, tgh)] < 0)
      ki = tgh + 1;
    else
      ka = tgh;
  }
  return ki;
}
int upper_bound(int x) {
  int ki = x, ka = N;
  while (ki < ka) {
    int tgh = (ki + ka) / 2;
    if (A[query_1(x, tgh)] - B[query_2(x, tgh)] <= 0)
      ki = tgh + 1;
    else
      ka = tgh;
  }
  return ki;
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", &A[i]);
  for (int i = 0; i < N; i++) scanf("%d", &B[i]);
  build_1();
  build_2();
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    int kiri = lower_bound(i);
    int kanan = upper_bound(i);
    ans += (long long)kanan - kiri;
  }
  printf("%I64d\n", ans);
  return 0;
}
