QOJ.ac

QOJ

Límite de tiempo: 3.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓

#14505. Magic Circle

Estadísticas

Ling is studying magic at the Ranoa University of Magic!

Today, Ling is learning about magic circles. The magic circle in front of her consists of a circle and $n$ magic nodes on it. These $n$ magic nodes divide the circle into $n$ equal parts and are numbered $1, 2, \dots, n$ in clockwise order. The magic node numbered $i$ has a color $c_i$ and a magic value $a_i$, where $c_i \le k$. If two magic nodes have the same color, they are connected by a magic line segment of that color, and the magic value of this line segment is the product of the magic values of the two nodes it connects. If two magic line segments of different colors intersect, they produce a magic intensity equal to the product of the magic values of the two line segments. The total magic intensity of the magic circle is the sum of the magic intensities produced by every pair of intersecting line segments of different colors.

Now, Ling wants to know the value of the magic intensity of the magic circle in front of her. Since the answer may be very large, you only need to output the answer modulo $998244353$.

Input

The first line contains two positive integers $n, k$ ($4 \le n \le 5 \times 10^5, 2 \le k \le 100$), representing the number of magic nodes and the upper limit of the number of colors for the magic nodes.

The second line contains $n$ positive integers, where the $i$-th integer represents the color $c_i$ of the magic node numbered $i$ ($1 \le c_i \le k$).

The third line contains $n$ positive integers, where the $i$-th integer represents the magic value $a_i$ of the magic node numbered $i$ ($0 \le a_i < 998244353$).

Output

Output a single integer representing the magic intensity of the magic circle modulo $998244353$.

Examples

Input 1

4 2
1 2 1 2
1 2 3 4

Output 1

24

Input 2

8 4
1 4 2 2 1 2 4 2
3 1000 1 1000 4 2 1000 1000

Output 2

786705612

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.