快读板子:
//初版:????/??/??
//Update:????/??/?? 添加了Ignore和ReadString等函数
//Update:2026/07/07 大修改,改了输出流和快读函数
//Update:2026/07/08 修复了判EOF等几个小Bug
//Update:2026/07/09 增大Buffer的大小,加了折构函数
//Update:2026/07/11 修改函数名,防止误解
//Update:2026/08/28 增加了连读连写,并增加了WriteStr函数
//Update:2026/09/04 转为命名空间模式
//Update:2026/09/07 升级了WriteString()函数
namespace IOoptimize{
struct FastIO{
private:
char OutputBuffer[700005];
int BufferSize;
public:
void Flush()
{
for(int i=1;i<=BufferSize;i++) putchar(OutputBuffer[i]);
fflush(stdout);
BufferSize=0;
}
void WriteChar(char c)
{
if(BufferSize>700000) Flush();
OutputBuffer[++BufferSize]=c;
}
void Reset()
{
BufferSize=0;
}
template<typename T>
void Read(T& Rr)
{
T tp=1,res=0;
char c;
c=getchar();
while(c!=EOF&&(c<'0'||c>'9'))
{
if(c=='-') tp*=-1;
c=getchar();
}
while(c!=EOF&&'0'<=c&&c<='9')
{
res=(res<<1)+(res<<3)+(c^48);
c=getchar();
}
Rr=res*tp;
}
template<typename T>
void Write(T n)
{
if(n==0)
{
WriteChar('0');
return;
}
if(n<0)
{
WriteChar('-');
n=~(n-1);
}
static char stk[105];
int top=0;
while(n)
{
stk[++top]=(n%10)+'0';
n/=10;
}
while(top)
{
WriteChar(stk[top]);
top--;
}
return;
}
template<typename T,typename... Args>
void Read(T& a,Args&... b)
{
Read(a);
Read(b...);
}
template<typename T,typename... Args>
void Write(T a,Args... b)
{
Write(a);
Write(b...);
}
void ReadString(std::string& s)
{
char ch;
ch=getchar();
std::string t="";
while(ch!=EOF&&(ch==' '||ch=='\n'||ch=='\r'||ch=='\t')) ch=getchar();
while(ch!=EOF&&ch!='\n'&&ch!='\r'&&ch!=' '&&ch!='\t')
{
t+=ch;
ch=getchar();
}
s=t;
}
template<typename T,typename... Args>
void ReadString(T& a,Args&... b)
{
ReadString(a);
ReadString(b...);
}
void Ignore()
{
getchar();
}
void WriteSpace()
{
WriteChar(' ');
}
void WriteEnter()
{
WriteChar('\n');
}
#if __cplusplus >= 201103L
void WriteStr(std::string t)
{
for(auto i:t) WriteChar(i);
}
void WriteString() {}
template<typename T,typename... Args>
void WriteString(T t,Args... tt)
{
WriteStr(t);
WriteString(tt...);
}
#endif
~FastIO()
{
Flush();
}
};
}莫队板子:
//普通莫队:
struct Query{
long long l,r,id,_true_l;
};
bool ordinary(Query x,Query y){
if(x._true_l==y._true_l) return x.r<y.r;
return x._true_l<y._true_l;
}
void mos_algo(vector<Query> ask,T B,string tag="ordinary-tag")
{
for(int i=0;i<ask.size();i++) ask[i]._true_l=ask[i].l/B;
sort(ask.begin(),ask.end(),ordinary);
int l=1,r=0;
int knd=0;
long long sum=0;
for(auto i:ask)
{
while(l<i.l)
{
//...
l++;
}
while(l>i.l)
{
l--;
//...
}
while(r<i.r)
{
r++;
//...
}
while(r>i.r)
{
//...
r--;
}
//...
}
}
//Best B:sqrt(n)
//奇偶莫队:
//把ordinnary替换为odd_even
bool odd_even(Query x,Query y){
if(x._true_l==y._true_l)
{
if(x._true_l%2==0) return x.r<y.r;
else return x.r>y.r;
}
return x._true_l<y._true_l;
}
//Best B:sqrt(n)
//带修莫队:
struct Query{
long long l,r,id,t,_true_l;
}ask[200005];
struct UPD{
long long pos,col;
}upd[200005];
void add(int x)
{
//...
}
void del(int x)
{
//...
}
void mtim(int l,int r,int t)
{
if(l<=upd[t].pos&&upd[t].pos<=r)
{
//...
}
//...
}
bool ordinary(Query x,Query y){}
bool odd_even(Query x,Query y){}
void display()
{
for(int i=1;i<=ccnt;i++) ask[i]._true_l=ask[i].l/B;
sort(ask+1,ask+1+ccnt,/*可选ordinary或odd_even*/);
int l=1,r=0,t=0;
for(int k=1;k<=ccnt;k++)
{
Query i=ask[k];
while(l<i.l)
{
del(a[l]);
l++;
}
while(l>i.l)
{
l--;
add(a[l]);
}
while(r<i.r)
{
r++;
add(a[r]);
}
while(r>i.r)
{
del(a[r]);
r--;
}
while(t>i.t)
{
mtim(l,r,t);
t--;
}
while(t<i.t)
{
t++;
mtim(l,r,t);
}
//...
}
}
//Best B:pow(n,2.0/3)#include<iostream>
#include<vector>
using namespace std;
const int Mod=1000000007;
int n,m,FULL=1023;
long long a[1005],b[1005];
vector<int> v[1005];
long long f[1005][1100];
bool iv[1005][1005];
int main()
{
cin>>n>>m;
for(int i=1;i<=m;i++) cin>>a[i]>>b[i],v[a[i]+b[i]].push_back(a[i]-b[i]),iv[a[i]+b[i]][a[i]-b[i]]=true;
f[0][0]=1;
for(int i=1;i<=n;i++)
{
// cout<<i<<":\n";
for(int S=0;S<1024;S++)
{
for(int T=0;T<32;T++)
{
bool ok=true;
for(int j=0;j<5;j++)
{
if((T&(1<<j))&&(j+1)*2>i)
{
ok=false;
break;
}
if((T&(1<<j))&&((S&(1<<(2*j)))==0)) ok=false;
if(i-2*j-2>=0&&(T&(1<<j))==0&&iv[i][(i-2*j-2)]) ok=false;
}
if(ok==false) continue;
int mx=0;
for(int j=1;j<=5;j++)
{
if(T&(1<<(j-1))) mx=max(mx,2*j);
}
int lf=((S<<1)+1);
lf&=1023;
int hp=lf&((1<<mx)-1);
lf^=hp;
int nS=lf;
f[i][nS]+=f[i-1][S];
f[i][nS]%=Mod;
}
}
// if(v[i].size()==0)
// {
//
// }
// for(int S=0;S<1024;S++) f[i][(2*S+1)&FULL]+=f[i-1][S];
for(int S=0;S<1024;S++) cout<<f[i][S]<<" ";
cout<<"\n";
}
long long ans=0;
for(int i=0;i<1024;i++) ans=(ans+f[n][i])%Mod;
cout<<ans<<"\n";
return 0;
}