#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SHAHD-BATGURL
#define pi 3.14159265359
#define des sort(arr, arr+n, greater <>());
#define asc sort(arr, arr+n);
#define mxarr *max_element(arr, arr+n);
#define mnarr *min_element(arr, arr+n);
#define remove_duplicates s.erase(unique(s.begin(), s.end()), s.end());
#define erase_char s.erase(remove(s.begin(), s.end(), '+'), s.end());
#define count_char count(s.begin(), s.end(), 'U');
#define speed ios_base::sync_with_stdio(0); cin.tie(0);
ll const mod=1e9+7;
//ll dx[4]={0, 0, 1, -1, 1, 1, -1, -1};
//ll dy[4]={0, 0, 1, -1, -1, 1, -1, 1};
int dx[4]= {0, 0, 1, -1};
int dy[4]= {1, -1, 0, 0};
//ll const mod=1e9+7;
ll arr[200005];
ll arr1[200005];
#define speed ios_base::sync_with_stdio(0); cin.tie(0);
int main()
{
speed;
ll n, sum=0;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>arr[i];
arr[i]*=((i+1)*(n-i));
}
for(int i=0; i<n; i++)
cin>>arr1[i];
sort(arr, arr+n);
sort(arr1, arr1+n, greater<>());
for(int i=0; i<n; i++)
{
sum+=((arr[i]%998244353)*(arr1[i]%998244353))%998244353;
sum%=998244353;
}
cout<<sum;
return 0;
}
1290. Convert Binary Number in a Linked List to Integer | 1525. Number of Good Ways to Split a String |
72. Edit Distance | 563. Binary Tree Tilt |
1306. Jump Game III | 236. Lowest Common Ancestor of a Binary Tree |
790. Domino and Tromino Tiling | 878. Nth Magical Number |
2099. Find Subsequence of Length K With the Largest Sum | 1608A - Find Array |
416. Partition Equal Subset Sum | 1446. Consecutive Characters |
1618A - Polycarp and Sums of Subsequences | 1618B - Missing Bigram |
938. Range Sum of BST | 147. Insertion Sort List |
310. Minimum Height Trees | 2110. Number of Smooth Descent Periods of a Stock |
2109. Adding Spaces to a String | 2108. Find First Palindromic String in the Array |
394. Decode String | 902. Numbers At Most N Given Digit Set |
221. Maximal Square | 1200. Minimum Absolute Difference |
1619B - Squares and Cubes | 1619A - Square String |
1629B - GCD Arrays | 1629A - Download More RAM |
1629C - Meximum Array | 1629D - Peculiar Movie Preferences |