1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <cstdio>
//#include <iostream>
//#include <algorithm>
//#include <string>
#include <vector>
//#include <complex>
//#include <iterator>
//#include <set>
//#include <bitset>
//#include <map>
//#include <stack>
//#include <list>
//#include <queue>
//#include <deque>
using namespace std;
typedef vector<int> VI;
typedef long long LL;
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
//#define VAR(v, n) typeof(n) v = (n)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define FOREACH(i, c) for(i=(c).begin(); i !=(c).end(); ++i)
//#define FORE(i, c) for(VAR(i, (c).begin()), KS=(c).end(); i !=KS; ++i)
#define PB push_back
#define ST first
#define ND second
const int INF = 1000000000;
const double EPS = 10e-9;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<double> VD;
//typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
#define PF push_front
#define MP make_pair
struct bigint
{
  LL a,b; ///a - mala czesc, b - duza czesc
  inline bigint(const LL aa=0,const LL bb=0)
  {
    a=aa;
    b=bb;
  }
  inline void operator = (const bigint n)
  {
    a=n.a;
    b=n.b;
  }
  template <class T> inline void operator = (const T n)
  {
    b=n/INF;
    a=n-b;
  }
  inline void operator += (const bigint n)
  {
    a+=n.a;
    b+=n.b;
    b+=a/INF;
    a%=INF;
    b%=INF;
  }
 /* inline bigint operator - (const bigint y)
  {
    bigint n;
    n.a=a-y.a;
    n.b=b-y.b;
    if(n.a<0)
    {
      n.a+=INF;
      --n.b;
    }
    return n;
  }*/
  inline void operator *= (const bigint x)
  {
    b=a*x.b+b*x.a;
    a*=x.a;
    b+=a/INF;
    a%=INF;
    b%=INF;
  }
  inline bigint operator * (const bigint x)
  {
    bigint n;
    n.b=a*x.b+b*x.a;
    n.a=a*x.a;
    n.b+=n.a/INF;
    n.a%=INF;
    n.b%=INF;
    return n;
  }
};
struct tri
{
  int a,b,c;
  tri(int k=0,int l=0,int m=0)
  {
    a=k;
    b=l;
    c=m;
  }
};
using namespace std;
void mnoz(bigint t[3],bigint u[3],bigint v[3])
{
  v[0]=t[0]*u[0];
  v[0]+=t[1]*u[1];
  v[1]=t[1]*u[2];
  v[1]+=t[0]*u[1];
  v[2]=t[2]*u[2];
  v[2]+=t[1]*u[1];
}
LL ok[20]={1,60,300,1500};
LL pot[20]={1};
bigint m[65][3];
LL fibo(LL n)
{
  int l;
  bigint w[3],w2[3];
  l=0;
  w[0]=1;
  w[2]=1;
  w[1]=0;
  while(n)
  {
    if(n%2)
    {
      mnoz(m[l],w,w2);
      w[0]=w2[0];
      w[1]=w2[1];
      w[2]=w2[2];
    }
    n>>=1;
    l++;
  }
  return w[1].b*INF+w[1].a;
}
void krok(VLL& v,int p,LL w)
{
  VLL b;
  VLL::iterator it;
  FOREACH(it,v)
    for(;(*it)<ok[p];(*it)+=ok[p-1])
      if(fibo(*it)%pot[p]==w)
        b.PB(*it);
  v=b;
}
int main()
{
  int i,n;
  LL w=0;
  char t[20];
  vector<LL> v(1);
  vector<LL>::iterator it;
  m[0][0]=0;
  m[0][1]=1;
  m[0][2]=1;
  for(i=0;i<64;i++)
    mnoz(m[i],m[i],m[i+1]);
  for(i=4;i<20;++i)
    ok[i]=ok[i-1]*10;
  for(i=1;i<20;++i)
    pot[i]=pot[i-1]*10;
  scanf("%s",t);
  for(n=0;t[n];++n);
  for(i=n-1;i>=0;--i)
  {
    w+=(t[i]-'0')*pot[n-i-1];
//    printf("%I64d ",w);
    krok(v,n-i,w);
/*    FOREACH(it,v)
      printf("%I64d ",*it);
    printf("\n");*/
  }
  if(SIZE(v))
    printf("%lld",ok[18]+*v.begin());
  else
    printf("NIE");
  /*FOREACH(it,v)
    printf("%I64d ",*it);*/
 return 0;
}