#include <bits/stdc++.h>
using namespace std;

bool dizeng(int n){
	int a[10] = {0};
	
	if(n < 1000 && n / 100 != 1){
		return false;
	} 
	int k = 0; 
	bool f = true;
	while(n != 0){
		a[k] = n % 10;
		if(k != 0 && a[k] - a[k-1] != -1){
			f = false;
			break;
		}
		k++;
		n = n / 10;
	}
	
	return f;
}

int he(int n){
	int s = 0;
	while(n != 0){
		s = s + n % 10;
		n = n / 10;
	}
	return s;
}

int main(){
	int i,j,n,c = 0;
	//前4位 
	for(i = 123;i <= 6789;i++){
		for(j = 123;j <= 6789;j++){
			if(dizeng(i) && dizeng(j) && sqrt(he(i) + he(j)) == (int)sqrt(he(i) + he(j))){
//				if(i < 1000) cout<<0;
//				cout<<i;
//				if(j < 1000) cout<<0;
//				cout<<j<<" "<<he(i)+he(j)<<" "<<sqrt(he(i)+he(j))<<endl;
				c++;
			}
		}
	}
	
	cout<<c;
}


/**************************************************************
	Problem: 1588
	User: admin
	Language: C++
	Result: Accepted
	Time:25 ms
	Memory:2072 kb
****************************************************************/