## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Majority Codeforces Solution | Solution Codeforces

F. Majority
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Everyone was happy coding, until suddenly a power shortage happened and the best competitive programming site went down. Fortunately, a system administrator bought some new equipment recently, including some UPSs. Thus there are some servers that are still online, but we need all of them to be working in order to keep the round rated.

Imagine the servers being a binary string $s$ of length $n$. If the $i$-th server is online, then ${s}_{i}=1$, and ${s}_{i}=0$ otherwise.

A system administrator can do the following operation called electricity spread, that consists of the following phases:

• Select two servers at positions $1\le i such that both are online (i.e. ${s}_{i}={s}_{j}=1$). The spread starts only from online servers.
• Check if we have enough power to make the spread. We consider having enough power if the number of turned on servers in range $\left[i,j\right]$ is at least the number of turned off servers in range $\left[i,j\right]$. More formally, check whether $2\cdot \left({s}_{i}+{s}_{i+1}+\dots +{s}_{j}\right)\ge j-i+1$.
• If the check is positive, turn on all the offline servers in range $\left[i,j\right]$. More formally, make ${s}_{k}:=1$ for all $k$ from $i$ to $j$.

We call a binary string $s$ of length $n$ rated if we can turn on all servers (i.e. make ${s}_{i}=1$ for $1\le i\le n$) using the electricity spread operation any number of times (possibly, $0$). Your task is to find the number of rated strings of length $n$ modulo $m$.

Input

The first and only line contains two integers $n$ and $m$ ($1\le n\le 5000$$10\le m\le {10}^{9}$) — the length of the string and the required module.

Output

Print a single integer — the number of rated binary strings of length $n$. Since this number can be large, print it modulo $m$.

Note

In the first example, the only rated string is 11. So the answer is $1$.

In the second example, the rated strings are:

• 111;
• 101, because we can perform an operation with $i=1$ and $j=1$.

So the answer is $2$.

In the third sample, the rated strings are:

• 1001;
• 1111;
• 1011;
• 1101.

So the answer is $4$.