#include using namespace std; #define ll long long int #define init(mem,v) memset(mem,v,sizeof(mem)) #define read(n) scanf("%d",&n) #define md 1000000009 ll num; int tp; ll mem[64][20]; // This works for both K=3 and 4. But there is a better "pattern solution" for K=3 ll dp(int pos,int carry){ if(pos<0){ if(carry==0) return 1; else return 0; } ll& ret=mem[pos][carry]; if(ret>=0) return ret; ret=0; if(num & (1LL<