#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
class BigInt;
vector<BigInt*> World;
void WorldEnd()
{
int Z=World.size();
for (int i=0; i<Z; i++)
{
delete World[i];
}
World.clear();
}
class BigInt
{
public:
vector<int> Me;
BigInt(int inn);
BigInt(vector<int> inn);
BigInt* reverse();
BigInt* add(BigInt* that);
void print();
bool isLoop();
//~BigInt();
};
bool BigInt::isLoop()
{
if (Me.size()==1)
return true;
else if (Me.size()>=2)
{
if (Me.size()%2==0)
{
for (int i=0; i<= Me.size()/2 ; i++)
{
if (Me[i]!= Me[ Me.size()-1-i])
return false;
}
return true;
}else
{
for (int i=0; i<=(Me.size()-1)/2; i++)
{
if (Me[i]!= Me[ Me.size()-1-i])
return false;
}
return true;
}
}
return false;
}
BigInt* BigInt::add(BigInt* that)
{
vector<int> dest;
int carry=0;
for(int i=0; i<that->Me.size(); i++)
{
int sum= Me[i] + that->Me[i]+carry;
if (sum>=10)
{
carry=1; dest.push_back( sum-10);
}else {
carry=0; dest.push_back( sum);
}
}
if (carry==1)
dest.push_back(1);
BigInt* ret=new BigInt(dest);
World.push_back(ret);
return ret;
}
BigInt* BigInt::reverse()
{
vector<int> hand;
for (int i=Me.size()-1; i>=0; i--)
hand.push_back(Me[i]);
BigInt* ret= new BigInt(hand);
World.push_back(ret);
return ret;
}
BigInt::BigInt(int inn)
{
while(inn>=10)
{
Me.push_back(inn%10);
inn /=10;
}
Me.push_back(inn);
}
BigInt::BigInt(vector<int> inn)
{
for (int i=0; i<inn.size(); i++)
{
Me.push_back(inn[i]);
}
}
void BigInt::print()
{
for (int i=Me.size()-1; i>=0; i--)
{
cout<< Me[i];
}
}
void ACM10018(int P)
{
BigInt* P1=new BigInt(P);
BigInt* P2;
BigInt* P3;
World.push_back(P1);
int Step=0;
do
{ P2=P1->reverse();
P3=P1->add(P2);
Step+=1;
if (!P3->isLoop())
P1=P3;
else
break;
}while(true);
cout<< Step<<" ";
P3->print();
cout<<endl;
}
int main()
{
int P,N;
cin>>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