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

Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i.

Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). 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 a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.

The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b.

Output

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

Examples

Input


5
1 8 7 2 4
9 7 2 9 3


Output


646


Input


1
1000000
1000000


Output


757402647


Input


2
1 3
4 2


Output


20

import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class N560 {
	static PrintWriter out;
	static Scanner sc;
	static ArrayList<Integer>q,w,primes;
	static ArrayList<Integer>adj[];
	static HashSet<Integer>primesH;
	static boolean prime[];
	//static ArrayList<Integer>a;
	static HashSet<Long>h,tmp;
	static boolean[]v;
	static int[]a,b,c,d;
	static int dp[][][];
	static int A,B,n,m,k,mt[][];
	static int oo=Integer.MIN_VALUE;
	static String s,tt;
	public static void main(String[]args) throws IOException {
		sc=new Scanner(System.in);
		out=new PrintWriter(System.out);
		//A();
    	//B();
		//primes=new ArrayList<Integer>();
		//primesH=new HashSet<Integer>();
	//	sieveOfEratosthenes(50);
		//C();
		//D();
		E();
		//minimum for subarrays of fixed length
		//F();
		out.close();
	}
	  private static void A() throws IOException {
		  int t=1;
			while(t-->0) {
				int n=ni(),x=ni(),y=ni();
				String s=ns();
				int cnt=0;
				for(int i=n-1;i>=n-x;i--) {
					if(i==n-y-1) {
						if(s.charAt(i)=='0')cnt++;
					}else {
						if(s.charAt(i)=='1')cnt++;
					}
				}
				ol(cnt);
			}
		
	   }
		static void B() throws IOException {
			int t=1;
			while(t-->0) {
					int n=ni();
					Integer [] a=new Integer[n];
					for(int i=0;i<n;i++) {
						a[i]=ni();
					}
					TreeMap<Integer,Integer>tr=new TreeMap<Integer,Integer>();
					for(int i=0;i<n;i++) {
						tr.put(a[i],tr.getOrDefault(a[i], 0)+1);
					}
					ArrayList<Integer>x=new ArrayList<Integer>();
					for(Integer y:tr.keySet())x.add(y);
					Collections.sort(x);
					int cnt=0,cur=0;
					for(int i=0;i<x.size();i++) {
						if(x.get(i)<i)break;
						int tk=Math.min(tr.get(x.get(i)),x.get(i)-cur );
						cur+=tk;
					}
					ol(cur);
					
			}
		}
	  static void C() throws IOException {
		  int t=1;
		  while(t-->0) {
			   int n=ni();
			   String s=ns();
			   int tk=0;
			   boolean rem[]=new boolean[n];
			   for(int i=0;i<n;) {
				   int cnt=0;
				   char cur=s.charAt(i);
				   int x=i;
				   while(i<n&&cur==s.charAt(i)) {
					   rem[i]=true;
					   i++;
					   cnt++;
					   
				   }
				   int c=1;
				  
				   rem[x]=false;
				   if(cnt>=2&&tk%2==1) {
					   rem[x+1]=false;tk++;
				   }
				   tk++;
				  // i--;
				   
			   }
			   if(tk%2==1)tk--;
			   StringBuilder sb=new StringBuilder();
			   for(int i=0,c=0;i<n&&c<tk;i++) {
				   if(!rem[i]) {
					   c++;
					   sb.append(s.charAt(i));
				   }
			   }
			   ol(n-tk);
			   ol(sb.toString());
		  }
		  
		}



	static void D() throws IOException {
		int t=ni();
		a1:while(t-->0) {
			int n=ni();
			long l[]=nal(n);
			Arrays.sort(l);
			ArrayList<Long>ans=new ArrayList<Long>();
			long num=l[0]*l[n-1]*1l;
			for(long i=2;i*i<=num;i++) {
				if(num%i==0) {
					ans.add(i);
					if(i*i*1l!=num) {
						ans.add(num/i);
					}
				}
			}
			Collections.sort(ans);
			if(ans.size()!=n) {
				ol(-1);
				continue a1;
			}
			for(int i=0;i<n;i++) {
				if(l[i]!=ans.get(i)) {
					ol(-1);
					continue a1;
				}
			}
			ol(""+num);
		}
		
	}
	private static long pow(Integer x, Integer p) {
		if(p==0)return 1l;
		long sq=pow(x,p/2);
		sq*=sq;
		if(p%2==1)sq*=x*1l;
		return sq;
	}
	private static int sum(char[] ss) {
		int sum=0;
		for(int i=0;i<ss.length;i++) {
			sum+=(ss[i]-'0');
		}
		return sum;
	}
	static long gcd (long a, long b) {
	    return b==0?a:gcd (b, a % b);
	}
	static long lcm (long a, long b) {
	    return a / gcd(a, b) * b;
	}
	static void E() throws IOException {
		int t=1;
		while(t-->0) {
			int n=ni();
			long a[]=new long[n];
			long b[]=new long[n];
			for(int i=0;i<n;i++)a[i]=nl();
			for(int i=0;i<n;i++)b[i]=nl();
			//Arrays.sort(a);
			Arrays.sort(b);
			
			long oo=998244353l;
			long sum=0;
			for(int i=0,j=n-1;i<=j;i++,j--) {
				long cur=((i+1)*(n-i)*1l);
				a[i]=a[i]*cur*1l;
				if(i!=j) {
					a[j]=a[j]*cur*1l;
				}
			}
			Arrays.sort(a);
			for(int i=0;i<n;i++) {
				a[i]%=oo;
				long cur=(a[i]*b[n-i-1])%oo;
				sum=(sum+cur)%oo;
			}
			ol(""+sum);
		}
	}
	static final Random random=new Random();
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	static void F() throws IOException{
		int t=1;
		while(t-->0) {
			 n=ni();
			 k=ni();
			 s=sc.next();
			 tt=sc.next();
			dp=new int[n][k+1][n];
			for(int i=0;i<n;i++)for(int j=0;j<=k;j++)Arrays.fill(dp[i][j], oo);
			dp(0,0,0);
			int max=0;
			for(int i=0;i<n;i++) {
				for(int j=0;j<=k;j++) {
					for(int kk=0;kk<n;kk++) {
						max=Math.max(max, dp[i][j][kk]);
					}
				}
			}
			out.println(max);
		}
		
	}

	private static int dp(int i, int ck, int total) {
		if(i==n)return 0;
		if(dp[i][ck][total]>=0)return dp[i][ck][total];
		int e0=s.charAt(i)==tt.charAt(0)?1:0;
		int e1=s.charAt(i)==tt.charAt(1)?1:0;
		int e01=tt.charAt(0)==tt.charAt(1)?1:0;
		int ans=dp(i+1,ck,total+e0)+(e1==1?total:0);
		if(ck<k) {
			ans=Math.max(ans, dp(i+1,ck+1,total+1)+(e01==1?total:0));
			ans=Math.max(ans,dp(i+1,ck+1,total+e01)+total);
		}
		return dp[i][ck][total]=ans;
	}
	private static long solve(char[] cc, char xx, char yy) {
		long ans=0;
		for(int i=0;i<n-1;i++) {
			for(int j=i+1;j<n;j++) {
				if(cc[i]==xx&&cc[j]==yy)ans++;
			}
		}
		return ans;
	}
	static void G() throws IOException{
		int t=1;
		while(t-->0) {

			
			
			
		}
		
	}
	private static void disp(int[] revl) {
		for(int i=0;i<revl.length;i++) {
			out.print(revl[i]+" ");
		}
		out.println();
	}

	static int ni() throws IOException {
		return sc.nextInt();
	}
	static double nd() throws IOException {
		return sc.nextDouble();
	}
	static long nl() throws IOException {
		return  sc.nextLong();
	}
	static String ns() throws IOException {
		return sc.next();
	}
	static int[] nai(int n) throws IOException {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextInt();
		return a;
	}
	static long[] nal(int n) throws IOException {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextLong();
		return a;
	}
	static int[][] nmi(int n,int m) throws IOException{
		int[][]a=new int[n][m];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				a[i][j]=sc.nextInt();
			}
		}
		return a;
	}

	static long[][] nml(int n,int m) throws IOException{
		long[][]a=new long[n][m];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				a[i][j]=sc.nextLong();
			}
		}
		return a;
	}
	static void o(String x) {
		out.print(x);
	}
	static void ol(String x) {
		out.println(x);
	}
	static void ol(int x) {
		out.println(x);
	}
	static void disp1(int []a) {
		for(int i=0;i<a.length;i++) {
			out.print(a[i]+" ");
		}
		out.println();
	}

	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public boolean hasNext() {return st.hasMoreTokens();}
		public int nextInt() throws IOException {return Integer.parseInt(next());}
		
		public double nextDouble() throws IOException {return Double.parseDouble(next());}
		
		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}
			
		public boolean ready() throws IOException {return br.ready(); }
		

	}
}
