#include <bits/stdc++.h>
using namespace std;
#define limit 100000000
int n,m,k=0,a[1000][1000],b[1000000],d[1000],c[50000000][2],dem,vitri,ahihi,h,t,gtln=0,lalala;
int tong(int a)
{
    int d=0,k;
    while (a>0)
    {
        k=a%10;
        d=d+k*k;
        a=a/10;
    }
    return d;
}
struct T
{
    int a,b;
    int noi;
}q[1000];
int main()
{
    ios_base::sync_with_stdio(false);
    freopen("Timso.inp","r",stdin);
    freopen("Timso.out","w",stdout);
    cin>>n>>m;
    for (int i=1;i<=729;i++)
    {
        //cout<<i<<endl;
        int freq[730]={0},f=i,t;
        a[i][0]=i;d[i]++;freq[i]++;
        while (freq[tong(f)]<1)
        {
            t=tong(f);
            freq[t]++;
            f=t;
            a[i][d[i]]=t;
            d[i]++;
        }
        a[i][d[i]]=tong(f);
        d[i]++;
    }
    for (int i=n;i<=m;i++)
    {
        if (i>=730)
        {
            h=tong(i);
            ahihi=d[h]+1;
        }
        else {h=i;ahihi=d[h];}
        if (ahihi>gtln)
        {
            lalala=h;
            vitri=i;
            gtln=ahihi;
        }
    }
    cout<<vitri<<" "<<gtln<<endl;
    if (vitri>=730) cout<<vitri<<" ",gtln--;
    for (int i=0;i<gtln;i++)
    {
        cout<<a[lalala][i]<<" ";
    }



}
