/*Author : Siriuslight | Subham Pal
Army Institute of Technology
*/
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define sd(x) scanf("%d", &x);
#define sld(x) scanf("%lld", &x);
using namespace std; typedef long long ll; typedef long double ld;
const ll inf = 1e9, N = 1e5+5;
const ll INF = 1e18, MOD = 1e9+7;
ll powmod(ll a,ll b,ll m=MOD){ll r=1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}
ll power(ll a,ll b){ll r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
ll gcd(ll a,ll b){if(b>a)swap(a,b);if(!b)return a;return gcd(b,a%b);}
int ans(0);
bool palin(vector<int> v){
for(int i = 0; i < v.size() / 2; ++i)
if(v[i] != v[v.size() - 1 - i])
return 0;
return 1;
}
vector <int> add(vector <int> v1){
vector <int> v2, res;
v2 = v1;
reverse(v2.begin(), v2.end());
int carry(0);
for(int i = v1.size() - 1; i >= 0; --i){
int t = v1[i] + v2[i] + carry;
res.push_back(t % 10);
carry = t / 10;
}
while(carry){
res.push_back(carry % 10);
carry /= 10;
}
reverse(res.begin(), res.end());
return res;
}
bool lychrel(int x){
vector <int> v;
while(x){
v.push_back(x % 10);
x /= 10;
}
reverse(v.begin(), v.end());
for(int i = 0; i <= 50; ++i){
if(palin(v)){
return 0;
}
v = add(v);
}
return 1;
}
int main(){
FIO;
cout << setprecision(10) << fixed;
for(int i = 1; i < 1e4; ++i){
ans += lychrel(i);
}
cout << ans;
return 0;
}
LypBdXRob3IgOiBTaXJpdXNsaWdodCB8IFN1YmhhbSBQYWwKICAgICAgICAgICBBcm15IEluc3RpdHV0ZSBvZiBUZWNobm9sb2d5CiovCiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgRklPIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpLGNpbi50aWUoMCksY291dC50aWUoMCk7CiNkZWZpbmUgc2QoeCkgc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ICUgMTApOwogICAgICAgIGNhcnJ5ID0gdCAvIDEwOwogICAgfQogICAgd2hpbGUoY2FycnkpewogICAgICAgIHJlcy5wdXNoX2JhY2soY2FycnkgJSAxMCk7CiAgICAgICAgY2FycnkgLz0gMTA7CiAgICB9CiAgICByZXZlcnNlKHJlcy5iZWdpbigpLCByZXMuZW5kKCkpOwogICAgcmV0dXJuIHJlczsKfQoKYm9vbCBseWNocmVsKGludCB4KXsKICAgIHZlY3RvciA8aW50PiB2OwogICAgd2hpbGUoeCl7CiAgICAgICAgdi5wdXNoX2JhY2soeCAlIDEwKTsKICAgICAgICB4IC89IDEwOwogICAgfQogICAgcmV2ZXJzZSh2LmJlZ2luKCksIHYuZW5kKCkpOwogICAgZm9yKGludCBpID0gMDsgaSA8PSA1MDsgKytpKXsKICAgICAgICBpZihwYWxpbih2KSl7CiAgICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICB2ID0gYWRkKHYpOwogICAgfQogICAgcmV0dXJuIDE7Cn0KCmludCBtYWluKCl7CiAgICBGSU87CiAgICBjb3V0IDw8IHNldHByZWNpc2lvbigxMCkgPDwgZml4ZWQ7CgogICAgZm9yKGludCBpID0gMTsgaSA8IDFlNDsgKytpKXsKICAgICAgICBhbnMgKz0gbHljaHJlbChpKTsKICAgIH0KICAgIGNvdXQgPDwgYW5zOwogICAgcmV0dXJuIDA7Cn0=