CF BUDDY
← Problems·

1725C · Circular Mirror

2000 · binary search, combinatorics, geometry

Problem: Pak Chanek has a mirror in the shape of a circle. There are NN lamps on the circumference numbered from 11 to NN in clockwise order. The length of the arc from lamp ii to lamp i+1i+1 is DiD_i for 1iN11 \leq i \leq N-1. Meanwhile, the length of the arc between lamp NN and lamp 11 is DND_N.

Pak Chanek wants to colour the lamps with MM different colours. Each lamp can be coloured with one of the MM colours. However, there cannot be three different lamps such that the colours of the three lamps are the same and the triangle made by considering the three lamps as vertices is a right triangle (triangle with one of its angles being exactly 9090 degrees).

The following are examples of lamp colouring configurations on the circular mirror.

Figure 1. an example of an incorrect colouring because lamps 11, 22, and 33 form a right triangleFigure 2. an example of a correct colouringFigure 3. an example of a correct colouring

Before colouring the lamps, Pak Chanek wants to know the number of distinct colouring configurations he can make. Count the number of distinct possible lamp colouring configurations, modulo 998244353998\,244\,353.

Input Format: The first line contains two integers NN and MM (1N31051 \le N \le 3 \cdot 10^5, 2M31052 \le M \le 3 \cdot 10^5) — the number of lamps in the mirror and the number of different colours used.

The second line contains NN integers D1,D2,,DND_1, D_2, \ldots, D_N (1Di1091 \le D_i \le 10^9) — the lengths of the arcs between the lamps in the mirror.

Output Format: An integer representing the number of possible lamp colouring configurations, modulo 998244353998\,244\,353.

Note: In the first example, all correct lamp colouring configurations are [1,1,2,1][1, 1, 2, 1], [1,1,2,2][1, 1, 2, 2], [1,2,1,2][1, 2, 1, 2], [1,2,2,1][1, 2, 2, 1], [1,2,2,2][1, 2, 2, 2], [2,1,1,1][2, 1, 1, 1], [2,1,1,2][2, 1, 1, 2], [2,1,2,1][2, 1, 2, 1], [2,2,1,1][2, 2, 1, 1], and [2,2,1,2][2, 2, 1, 2].

Sample Cases

Case 1

Input

4 2
10 10 6 14

Output

10

Case 2

Input

1 2
10

Output

2

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback