#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int dfs(int lb, int rem, int num) {
  if (rem == 0) return 1;
  if (num <= 0) return 0;
  if (lb * lb > rem) return 0;
  int res = 0;
  for (int i = lb; i * i <= rem; i++) {
    res += dfs(i, rem - i * i, num - 1);
  }
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int n;
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 1; i * i <= n; i++) {
      ans += dfs(i, n - i * i, 3);
    }
    cout << ans << endl;
  }

  return 0;
}
