This page is still under construction.

Parts of this page are still being built. What you see may change.

Triangulation

Time limit1sMemory limit32 MB

Summary
Given n and m, compute the sum of triangulation counts T_3 + ... + T_n of convex polygons, reduced modulo m.
Level

Medium7 of 10

Topics
Combinatorics, Math, Number theory, Dynamic programming
Solved
No attempts yet

Problem

A triangulation of a convex polygon divides its interior into triangles using diagonals that do not cross one another. The vertices are numbered from 11 to NN, and two triangulations are considered different whenever their sets of diagonals differ.

For example, a pentagon can be triangulated in exactly five ways.

Let TnT_n be the number of ways to triangulate a convex nn-gon. Write a program that computes T3+T4+⋯+TnT_3 + T_4 + \cdots + T_n.

Input

The first line contains two integers nn and mm, separated by a space. (3≤n≤100 0003 \le n \le 100\,000, 2≤m≤1092 \le m \le 10^9)

Output

Print the remainder of T3+T4+⋯+TnT_3 + T_4 + \cdots + T_n divided by mm.

Examples3

  1. Example 1

    Input
    5 1000
    
    Expected output
    8
    
  2. Example 2

    Input
    4 1000000000
    
    Expected output
    3
    
  3. Example 3

    Input
    6 1000000000
    
    Expected output
    22