#include #define rep(i, l, r) for (int i = (l); i < (r); i++) using namespace std; typedef long long ll; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int main() { int n, x; cin >> n; vector r(n), g(3001, 0), b(3001, 0); rep(i, 0, n) { cin >> r[i]; } rep(i, 0, n) { cin >> x; g[x]++; } rep(i, 0, n) { cin >> x; b[x]++; } vector> a(3001, vector(3001, 0)); vector c(6001, 0); rep(i, 0, 3000) { rep(j, 0, 3000) { a[i][j] = g[i] * b[j]; c[i + j] += a[i][j]; } } vector> s(3001, vector(3001, 0)); rep(i, 0, 3000) { rep(j, 0, 3000) { s[i + 1][j + 1] = s[i][j + 1] + s[i + 1][j] - s[i][j] + a[i + 1][j + 1]; } } vector d(6001, 0); rep(k, 0, 6000) { d[k + 1] = d[k] + c[k + 1]; } /* rep(i, 0, 4) { rep(j, 0, 4) { cout << s[i + 1][j + 1]; } cout << endl; } rep(k, 0, 6) cout << "d[" << k << "]=" << d[k] << endl; */ ll ans = 0; rep(i, 0, n) { ans += s[r[i]][r[i]]; ans -= d[r[i]]; } cout << ans << endl; }