PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000048. Cặp chủ đề thú vị (Pair of Topics)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Cặp chủ đề thú vị (Pair of Topics)

Pair of Topics

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A school lecture requires two topics to be discussed. There are nn topics, numbered from 11 to nn. For topic ii, the teacher assigns an interestingness value aia_i, while the students assign a value bib_i.

For two distinct topics i<ji<j, the teacher's combined interestingness is ai+aja_i+a_j, and the students' combined interestingness is bi+bjb_i+b_j.

A pair is good if the teacher's total is strictly greater than the students' total:

ai+aj>bi+bj.a_i+a_j>b_i+b_j.

Count all good pairs of topics. Different index pairs count separately, even when the associated values are equal.

Input

  • The first line contains the integer nn, the number of topics.
  • The second line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n, giving the teacher's values.
  • The third line contains exactly nn integers b1,b2,…,bnb_1,b_2,\ldots,b_n, giving the students' values for the corresponding topics.

Output

Print one integer: the number of index pairs (i,j)(i,j) with 1≤i<j≤n1\le i<j\le n and ai+aj>bi+bja_i+a_j>b_i+b_j.

Subtasks

  • Subtask 1 (20 points): 2≤n≤252\le n\le 25; 1≤ai,bi≤1091\le a_i,b_i\le10^9 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 2≤n≤24002\le n\le 2400; 1≤ai,bi≤1091\le a_i,b_i\le10^9 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 2≤n≤2000002\le n\le 200000; 1≤ai,bi≤1091\le a_i,b_i\le10^9 for every 1≤i≤n1\le i\le n.

Examples

Input

5
4 8 2 6 2
4 5 4 1 3

Output

7

Explanation

Subtracting the students' values from the teacher's values gives [0,3,−2,5,−1][0,3,-2,5,-1]. A pair is good precisely when its two differences sum to a positive number. The seven valid pairs are (1,2)(1,2), (1,4)(1,4), (2,3)(2,3), (2,4)(2,4), (2,5)(2,5), (3,4)(3,4), and (4,5)(4,5). The other three pairs have a non-positive difference sum, so the output is 7.