/* -*- coding: utf-8 -*- * * 1965.cc: No.1965 Heavier - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ typedef long long ll; /* global variables */ int as[MAX_N], bs[MAX_N]; /* subroutines */ inline bool win(int i, int j) { int w0, w1; if (bs[i] < bs[j]) w0 = as[i] + bs[j], w1 = as[j] + bs[i]; else w0 = as[i] + bs[i], w1 = as[j] + bs[j]; return (w0 < w1); } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i); for (int i = 0; i < n; i++) scanf("%d", bs + i); ll sum = 0; for (int i = 0; i < n;) { int j = i; i++; while (i < n && win(i - 1, i)) i++; int l = i - j; sum += (ll)l * (l - 1) / 2; } printf("%lld\n", sum); return 0; }