intquery(int i){ int ret = 0; while(i>0) { ret += c[i]; i -= lowbit(i); } return ret; }
vector<int> v;
intmain(){ int n; scanf("%d", &n); for(int i=1;i<=n;i++) { scanf("%d", &a[i]); } for (int i = 1; i <= n;i++) { scanf("%d", &b[i]); } for (int i = 1; i <= n;i++) { v.push_back(a[i] - b[i]); v.push_back(b[i] - a[i]); } longlong ans = 0; sort(v.begin(), v.end()); for (int i = 1;i<=n;i++) { int x = b[i] - a[i]; int y = a[i] - b[i]; int id = upper_bound(v.begin(), v.end(), x) - v.begin() + 1; int id2 = upper_bound(v.begin(), v.end(), y) - v.begin() + 1; ans += (i - 1 - query(id)); add(id2, 1); } cout << ans << endl; }
intmain(){ int n; scanf("%d", &n); for (int i = 1; i <= n;i++) { scanf("%d", &a[i]); } for (int i = 1; i <= n;i++) { scanf("%d", &b[i]); v.push_back(a[i] - b[i]); } sort(v.begin(), v.end()); longlong ans = 0; for (int i = 1; i <= n;i++) { int id = upper_bound(v.begin(), v.end(), b[i] - a[i]) - v.begin(); ans += (n - id); if(a[i]-b[i]>b[i]-a[i]) ans--; } ans /= 2; cout << ans << endl; }