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

#BS0000125. Tổng giá các phần ăn (Set Menu)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tổng giá các phần ăn (Set Menu)

Set Menu

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A cafeteria offers nn types of main dishes at prices AiA_i and mm types of side dishes at prices BjB_j. A set meal consists of one main and one side. Its price is min⁡(Ai+Bj,P)\min(A_i+B_j,P), capped at PP. There are exactly n⋅mn\cdot m distinct main-side choices, even when prices match. Compute the sum of prices of all possible set meals.

Input

The first line contains n,m,Pn,m,P. The second contains nn main-dish prices AiA_i. The third contains mm side-dish prices BjB_j.

Output

Print one integer: the total price of all n⋅mn\cdot m set meals (fits signed 64-bit).

Subtasks

  • Subtask 1 (20 points): 1≤n,m≤201\le n,m\le 20; 1≤Ai,Bj≤108; 1≤P≤2⋅1081\le A_i,B_j\le 10^8;\ 1\le P\le 2\cdot10^8 for 1≤i≤n1\le i\le n, 1≤j≤m1\le j\le m.
  • Subtask 2 (30 points): 1≤n,m≤25001\le n,m\le 2500; 1≤Ai,Bj≤108; 1≤P≤2⋅1081\le A_i,B_j\le 10^8;\ 1\le P\le 2\cdot10^8 for 1≤i≤n1\le i\le n, 1≤j≤m1\le j\le m.
  • Subtask 3 (50 points): 1≤n,m≤2000001\le n,m\le 200000; 1≤Ai,Bj≤108; 1≤P≤2⋅1081\le A_i,B_j\le 10^8;\ 1\le P\le 2\cdot10^8 for 1≤i≤n1\le i\le n, 1≤j≤m1\le j\le m.

Examples

Input

2 2 7
3 5
6 1

Output

24

Explanation

There are four meals: (3,6)(3,6) costs min⁡(9,7)=7\min(9,7)=7, (3,1)(3,1) costs 44, (5,6)(5,6) costs 77, and (5,1)(5,1) costs 66. Their total is 7+4+7+6=247+4+7+6=24, so print 24.