sq = []
1.upto(Math.sqrt(2**15).floor) do |i|
    sq.push(i*i)
end
dp = Array.new(5).map{Array.new(2**15+1,0)}
dp[0][0] = dp[1][0] = dp[2][0] = dp[3][0] = 1
1.upto(sq.size+1) do |i|
    1.upto(4) do |j|
        (i**2).upto(2**15) do |k|
            dp[j][k] += dp[j-1][k-i**2]
        end
    end
end
loop do
    n = gets.to_i
    break if n == 0
    puts dp[4][n]
end