#include using namespace std; long long a=3; class S { public: virtual S *dup()=0; virtual bool next()=0; virtual S *max()=0; virtual void dump()=0; }; int len(S** l) { int i=0; while(l[i]) { i++; } return i; } class S0 : public S { public: long long i; virtual S* dup() { S0 *s=new S0(); s->i=i; return (S*)s; } virtual bool next() { a++; return i-->0; } virtual S* max() { S0 *s=new S0(); s->i=a; return (S*)s; } virtual void dump() { cout<list=NULL; return (S*)s; } int l=len(list); s->list=new S*[l+1]; for(int i=0;ilist[i]=list[i]->dup(); } s->list[l]=NULL; return (S*)s; } virtual bool next() { int i=0; while(list[i] && !list[i]->next()) { list[i]=list[i]->max(); i++; } if(list[i]==NULL) { return false; } return true; } virtual S* max() { S1 *s=new S1(); if(!list) { s->list=NULL; return (S*)s; } s->list=new S*[a+1]; for(int i=0;ilist[i]=list[0]->max(); } s->list[a]=NULL; return (S*)s; } virtual void dump() { if(!list)return; cout<<"["; for(int i=0;list[i];i++) { list[i]->dump(); cout<<" "; } cout<<"]"; } }; S *generate(S *x) { S1 *s=new S1(); s->list=new S*[a+1]; for(int i=0;ilist[i]=x->max(); } s->list[a]=NULL; return s; } S *gen_max(S* seed) { S* s=generate(seed); for(int i=0;iseed=seed->dup(); if(!list) { t->list=NULL; return t; } int l=len(list); t->list=new S*[l+1]; for(int i=0;ilist[i]=list[i]->dup(); } t->list[l]=NULL; return t; } virtual bool next() { int i=0; while(list[i] && !list[i]->next()) { list[i]=gen_max(seed); i++; } if(list[i]==NULL) { return false; } return true; } virtual S *max() { T *t=new T(); t->seed=seed->dup(); t->list=new S*[a+1]; for(int i=0;ilist[i]=gen_max(seed->dup()); } t->list[a]=NULL; return (S*)t; } virtual void dump() { if(!list)return; cout<<"{"; for(int i=0;list[i];i++) { cout<<"<"; list[i]->dump(); cout<<">"; } cout<<"}"; } }; S *maxT() { T *t=new T(); t->seed=new S0(); t->list=NULL; for(int i=0;iseed=t->dup(); } return t->max(); } void f(S *s) { if(!s->next()) { return; } S *t=maxT(); while(t->next()) { f(s->dup()); } } int main() { f(maxT()); return a; }