### subroutines

def count_rec(k, i, n)
  if k == 1
    i0 = Math.sqrt(n + 0.5).floor
    return (i0 * i0 == n && i0 >= i) ? 1 : 0
  end

  count = 0
  i0 = i

  loop do
    i0sq = i0 * i0
    n0 = n - i0sq
    break if n0 < i0sq
    count += count_rec(k - 1, i0, n0)
    i0 += 1
  end

  count
end

### main

loop do
  n = gets.to_i
  break if n == 0

  puts count_rec(4, 0, n)
end