Under construction

Still being built. Things may change

After the Wedding

Time limit1sMemory limit1024 MB

Summary
Find the limit of the average cut force when a piecewise linear solid of revolution is split into many equal-volume pieces, output modulo 998244353.
Level

Medium6 of 10

Topics
Math, Geometry, Implementation
Solved
No attempts yet

Problem

Seolyeong is handing out cake to mm guests who attended the wedding. Every guest gets one piece, and all pieces must have the same volume.

At first the cake is a single block. Its shape is the solid formed by rotating about the xx-axis the region enclosed by the graph of y=f(x)y=f(x) (x1≤x≤xnx_1 \leq x \leq x_n), the lines x=x1x = x_1 and x=xnx = x_n, and the xx-axis. The graph of y=f(x)y=f(x) is drawn by connecting the points (x1,y1)(x_1, y_1), (x2,y2)(x_2, y_2), ⋯\cdots, (xn,yn)(x_n, y_n) with line segments in this order. Here yi>0(1≤i≤n)y_i > 0 (1 \leq i \leq n).

To keep the pieces as neat as possible, Seolyeong always cuts the cake along a plane perpendicular to the axis of rotation. Since the cake must be divided among mm guests, Seolyeong makes exactly m−1m-1 cuts. It can be proven that there is only one way to cut the cake under these conditions.

The force needed for a cut is proportional to the area of the cut face. If a cut produces a cross-section with area AπA\pi, the force used is AA. Let F1,F2,⋯ ,Fm−1F_1, F_2, \cdots, F_{m-1} be the forces used in the m−1m-1 cuts, and let F‾(m)=1m−1∑i=1m−1Fi\overline{F}(m)=\frac{1}{m-1} \sum_{i=1}^{m-1} F_i be their average. Find

F=lim⁡m→∞F‾(m)F = \lim_{m\rightarrow\infty} \overline{F}(m)

Input

The first line contains an integer nn.

The second line contains nn integers x1,x2,⋯ ,xnx_1, x_2, \cdots, x_n separated by spaces.

The third line contains nn integers y1,y2,⋯ ,yny_1, y_2, \cdots, y_n separated by spaces.

These values define the graph y=f(x)y=f(x) that gives the shape of the cake, drawn by connecting (x1,y1)(x_1, y_1), (x2,y2)(x_2, y_2), ⋯\cdots, (xn,yn)(x_n, y_n) with line segments in this order.

Output

On the first line, print the value of p×q998 244 351mod  998 244 353p \times q^{998\,244\,351} \mod 998\,244\,353, where FF is written as an irreducible fraction F=pq\displaystyle{F = \frac{p}{q}}. 998 244 353998\,244\,353 is a prime. You can prove that FF is always a rational number.

Constraints

  • 2≤n≤300 0002 \leq n \leq 300\,000
  • 0≤x1<x2<⋯<xn≤1070 \leq x_1 < x_2 < \cdots < x_n \leq 10^7
  • 1≤yi≤1071 \leq y_i \leq 10^7

Examples3

  1. Example 1

    Input
    3
    1 2 3
    3 3 3
    
    Expected output
    9
    
  2. Example 2

    Input
    2
    10 20
    10 20
    
    Expected output
    285212938
    
  3. Example 3

    Input
    4
    0 70 140 210
    435 145 145 435
    
    Expected output
    107445