#include <bits/stdc++.h>

using namespace std;

#define MAX (1<<15)

int main()
{
    int N;
    int dp[MAX+1][5] = {};
    dp[0][0] = 1;
    for (int i = 1; i <= MAX; i++) {
        for (int j = i*i; j <= MAX; j++) {
            for (int k = 0; k < 4; k++) {
                dp[j][k+1] += dp[j-i*i][k];
            }
        }
    }
    
    while (cin >> N, N) {
        int sum = 0;
        for (int i = 1; i <= 4; i++) {
            sum += dp[N][i];
        }
        cout << sum << endl;
    }        
    return 0;
}