#include #include #include #include using namespace std; int mv; struct Node; Node* root; struct Node { int val; set child; Node(int v) { val = v; } ~Node() { for(set::iterator i = child.begin(); i != child.end(); ++i) delete *i; } bool Next() { int old = val; val = val * 3 + 1; while(val % 2 == 0) val /= 2; if(val > 12345678) val %= 12345678; if(val == 1) { return false; } bool bonus = (val > old && child.size() == 0); //?? timing vector cp; for(set::iterator i = child.begin(); i != child.end();) { Node* p = *i; if(!p->Next()) { if(p->child.size() == 1) { Node* pp = *p->child.begin(); cp.push_back(pp); p->child.clear(); } delete p; child.erase(i++); } else ++i; } for(int i = 0; i < (int)cp.size(); ++i) { Node* p = cp[i]; while(p && !p->Next()) { Node* pp = 0; if(p->child.size() == 1) { pp = *p->child.begin(); p->child.clear(); } delete p; p = pp; } if(p) child.insert(p); } if(bonus) { Bonus(); } //mv = max(mv, val); return true; } void Bonus(bool lead = false) { int v = (val+1) / 2; if(v % 2 == 0) { if(lead) --v; else ++v; } if(v > 1) { //if(lead) //cout << v << "(" << val << ") "; //else //cout << v << "<" << val << "> "; child.insert(new Node(v)); } } pair FindMax() { int cnt = 1; int m = val; for(set::iterator i = child.begin(); i != child.end(); ++i) { pair t = (*i)->FindMax(); if(t.first > m) { m = t.first; cnt = t.second; } else if(t.first == m) cnt += t.second; } return make_pair(m, cnt); } bool SetRoot(int m) { if(val == m) { Bonus(true); root = this; return true; } else { for(set::iterator i = child.begin(); i != child.end(); ++i) { if((*i)->SetRoot(m)) { (*i)->child.insert(this); child.erase(i); return true; } } } return false; } int Count() { int r = 1; for(set::iterator i = child.begin(); i != child.end(); ++i) { r += (*i)->Count(); } return r; } void Print() { cout << val << "("; for(set::iterator i = child.begin(); i != child.end(); ++i) { (*i)->Print(); cout << " "; } cout << ")"; } }; bool Run() { //cout << root->Count() << endl; //root->Print(); cout << endl; if(!root->Next()) return false; pair m = root->FindMax(); if(m.second == 1) { root->SetRoot(m.first); } mv = max(mv, root->Count()); return true; } int main() { int n; while(cin >> n && n) { root = new Node(n); int cnt = 1; mv = 1; for(; Run(); cnt++); cout << cnt << " " << mv << endl; delete root; } }