Two Arrays and Sum of Functions

TimeLimit:2000MS  MemoryLimit:256MB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description

You are given two arrays a and b, both of length n.


Let's define a function f(l,r)=∑ai⋅bi.  (l≤i≤r)


Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑f(l,r). (1≤l≤r≤n)   Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder.


Input

The first line of the input contains one integer n (1≤n≤2⋅10^5) — the number of elements in a and b.


The second line of the input contains n integers a1,a2,…,an (1≤ai≤10^6), where ai is the i-th element of a.


The third line of the input contains n integers b1,b2,…,bn (1≤bj≤10^6), where bj is the j-th element of b.


Output

Print one integer — the minimum possible value of ∑f(l,r) ( 1≤l≤r≤n) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder.

SampleInput 1
5
1 8 7 2 4
9 7 2 9 3
SampleOutput 1
646
SampleInput 2
1
1000000
1000000
SampleOutput 2
757402647
SampleInput 3
2
1 3
4 2
SampleOutput 3
20
hint: f(1,1)=4 f(2,2)=6 f(1,2)=10 4+6+10=20
Submit
题目统计信息详细
总AC数4
通过人数4
尝试人数4
总提交量13
AC率30.77%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: