Under construction

Still being built. Things may change

Number of Longest Increasing Subsequences

Interview

Time limit1sMemory limit128 MB

Summary
Count how many strictly increasing subsequences of the given sequence attain the maximum possible length, modulo m.
Level

Medium6 of 10

Topics
Dynamic programming, Segment tree
Solved
No attempts yet

Problem

Compute the number of longest strictly increasing subsequences of a sequence AA, modulo mm.

A subsequence is obtained from AA by deleting zero or more elements while keeping the relative order of the remaining ones. A strictly increasing subsequence is one in which every element is strictly greater than the element before it. Among all strictly increasing subsequences, the longest ones are those of maximum length; there may be several of them, and you must count how many there are. Two subsequences are considered different when they use different sets of positions of AA.

Input

The first line contains the length nn of the sequence AA and the modulus mm (1≤n≤500 0001 \le n \le 500\,000, 1≤m≤1091 \le m \le 10^9).

The second line contains the elements a1,a2,…,ana_1, a_2, \dots, a_n of AA, separated by spaces (0≤ai≤1090 \le a_i \le 10^9).

Output

Print a single line containing the number of longest strictly increasing subsequences of AA, taken modulo mm.

Examples1

  1. Example 1

    Input
    4 10
    3 2 5 4
    
    Expected output
    4