#include using namespace std; typedef long long int ll; typedef pair P; const ll MOD=1000000007; const ll INF=1000000010; const ll LINF=4000000000000000010LL; const int MAX=310; const double EPS=1e-9; int dx[4]={0,1,0,-1}; int dy[4]={1,0,-1,0}; int p; string s; ll dp[20][2][3][2]; ll dfs(int i,bool f,int sum,bool t){ if(i==(int)s.length()){ return (sum==0)||t; } int n=s[i]-'0'; ll res=0; if(dp[i][f][sum][t]!=-1)return dp[i][f][sum][t]; if(f){ for(int j=0;j>p; s.push_back('1'); for(int i=0;i