//2003年アジアB Lagrange's Four-Square Theorem
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int square(int sum, int d, int c);
int n;

int main(){
  while(scanf("%d",&n),n){
    printf("%d\n",square(0,1,0) );
  }
  exit(0);
}

int square(int sum, int d, int c){
  if(sum == n) return 1;
  if(c >= 4) return 0;
  int res = 0;
  for(int i = d; i*i <= n; i++){
    if(sum + i*i > n) break;
    res += square(sum + i*i, i, c+1);
  }
  return res;
}

