public static void main(String[] args)
	{
		boolean[] possibilities = new boolean[100000000];
		for (long i = 1; i < 100000000; i++)
		{
			long sum = 0L;
			long j = (long) i;
			while (true)
			{
				sum += j*j;
				if (sum < 100000000 && j > i)
					possibilities[(int) sum] = true;
				if (sum > 100000000)
					break;
				j++;
			}
		}
		long sum = 0L;
		for (long i = 2; i < 100000000; i++)
			if (possibilities[(int) i] && isPalindrome(i))
				sum += i;
		System.out.println(sum);
	}