Problem:
Problem B:
Lagrange's Four-Square Theorem
The fact that any positive integer has a representation as the sum of at most four positive
squares (i.e. squares of positive integers) is known as Lagrange’s Four-Square Theorem. The
first published proof of the theorem was given by Joseph-Louis Lagrange in 1770. Your mission
however is not to explain the original proof nor to discover a new proof but to show that the
theorem holds for some specific numbers by counting how many such possible representations
there are.
For a given positive integer n, you should report the number of all representations of n as the
sum of at most four positive squares. The order of addition does not matter, e.g. you should
consider 4
2
+ 3
2
and 3
2
+ 4
2
are the same representation.
For example, let’s check the case of 25. This integer has just three representations 1
2
+2
2
+2
2
+4
2
,
3
2
+ 4
2
, and 5
2
. Thus you should report 3 in this case. Be careful not to count 4
2
+ 3
2
and
3
2
+ 4
2
separately.
Input
The input is composed of at most 255 lines, each containing a single positive integer less than
2
15
, followed by a line containing a single zero. The last line is not a part of the input data.
Output
The output should be composed of lines, each containing a single integer. No other characters
should appear in the output.
The output integer corresponding to the input integer
n
is the number of all representations
of
n
as the sum of at most four positive squares.
Sample Input
1
25
2003
211
20007
0
Output for the Sample Input
1
3
48
7
738

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  vi pw(1 << 8);
  rep(i,0,1 << 8)pw[i] = i*i;
  while(1){
    int n;cin >> n;
    if(!n)break;
    const int MX = 1 << 8;
    int res = 0;
    rep(i,0,MX)rep(j,i,MX)rep(k,j,MX){
      ll d = n-(i*i + j*j + k*k);
      if(k*k <= d && pw[LB(pw,d)] == d)res++;
    }
    cout << res << "\n";
  }
  

  return 0;
}
accuracy: 1
time_ms: 730
memory_kb: 3220
final_rank: 6

code_snippet: #include <vector>
#include <iostream>
using namespace std;

int main() {
	const int LIMIT = 1 << 15;
	vector<int> counter(LIMIT + 1);
	for (int a = 0; a * a <= LIMIT; a++) {
		for (int b = a; a * a + b * b <= LIMIT; b++) {
			for (int c = b; a * a + b * b + c * c <= LIMIT; c++) {
				for (int d = c; a * a + b * b + c * c + d * d <= LIMIT; d++) {
					counter[a * a + b * b + c * c + d * d]++;
				}
			}
		}
	}
	while (true) {
		int N;
		cin >> N;
		if (N == 0) {
			break;
		}
		cout << counter[N] << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3436
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) a.begin(),a.end()
#define reps(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, a, n) for (int i = (a); i > (int)(n); i--)
const long long mod = 1000000007;
const long long INF = 1e18;
ll myceil(ll a, ll b) {return (a+b-1)/b;}

int n;

void solve() {
    int ans = 0;

    for (int i = 0; i*i<n; i++) {
        for (int j = i; i*i+j*j<n; j++) {
            for (int k = j; i*i+j*j+k*k<n; k++) {
                if (n-i*i-j*j-k*k >= k*k && (int)pow(n-i*i-j*j-k*k,0.5)*(int)pow(n-i*i-j*j-k*k,0.5) == n-i*i-j*j-k*k) {
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;
    return;
}


int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    cin >> n;
    while (n != 0) {
        solve();
        cin >> n;
    }
}
accuracy: 1
time_ms: 1800
memory_kb: 3744
final_rank: 9

code_snippet: #include <iostream>
#include <vector>

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);

    std::vector dp(5, std::vector<long long>(1 << 15));
    dp[0][0] = 1;
    for (int v{1} ; v * v < (1 << 15) ; v++) {
        std::vector next{dp};
        for (int i{1} ; i <= 4 ; i++) {
            int add{i * v * v};
            for (int j{} ; j + add < (1 << 15) ; j++) {
                for (int k{} ; k + i <= 4 ; k++) {
                    next[k + i][j + add] += dp[k][j];
                }
            }
        }
        dp = std::move(next);
    }
    while (true) {
        int v;
        std::cin >> v;
        if (v == 0) break;
        // std::cout << dp[1][v] << ' ' << dp[2][v] << ' ' << dp[3][v] << ' ' << dp[4][v] << std::endl;
        std::cout << dp[1][v] + dp[2][v] + dp[3][v] + dp[4][v] << '\n';
    }
}
accuracy: 1
time_ms: 50
memory_kb: 5556
final_rank: 4

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

int main() {
while(1) {
    int N;
    cin >> N;
    if (N == 0) return 0;
    int ANS = 0;
    rep(i,0,200) {
        rep(j,0,i+1) {
            rep(k,0,j+1) {
                if (i*i+j*j+k*k > N) break;
                int l = sqrt(N-i*i-j*j-k*k);
                if (l <= k && i*i+j*j+k*k+l*l == N) ANS++;
            }
        }
    }
    cout << ANS << endl;
}
}
accuracy: 1
time_ms: 210
memory_kb: 3496
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, a, b) for(ll i = a; i < b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)
constexpr ll inf = 4e18;
struct SetupIO {
    SetupIO() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout << fixed << setprecision(30);
    }
} setup_io;
int main(void) {
    while(true) {
        ll n;
        cin >> n;
        if(n == 0) break;
        ll ans = 0;
        rep(i, 1, 200) {
            if(i * i == n) ans++;
            if(i * i > n) break;
            rep(j, i, 200) {
                if(i * i + j * j == n) ans++;
                if(i * i + j * j > n) break;
                rep(k, j, 200) {
                    if(i * i + j * j + k * k == n) ans++;
                    if(i * i + j * j + k * k > n) break;
                    rep(l, k, 200) {
                        if(i * i + j * j + k * k + l * l == n) ans++;
                        if(i * i + j * j + k * k + l * l > n) break;
                    }
                }
            }
        }
        cout << ans << '\n';
    }
}
accuracy: 1
time_ms: 670
memory_kb: 3220
final_rank: 5

code_snippet: // (⁠◕⁠ᴗ⁠◕⁠✿⁠)

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define srep(i, s, n) for (ll i = s; i < (n); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using vvv = vv<vc<T>>;
using vi = vc<int>;using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long;using vl = vc<ll>;using vvl = vv<ll>; using vvvl = vv<vl>;
using ld = long double; using vld = vc<ld>; using vvld = vc<vld>; using vvvld = vc<vvld>;
using uint = unsigned int;
using ull = unsigned long long;
const ld pi = 3.141592653589793;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll mod = 1000000007;
const ll mod = 998244353;
inline bool inside(ll y, ll x, ll H, ll W) {return 0 <= (y) and (y) < (H) and 0 <= (x) and (x) < (W); }

#define debug(var)  do{std::cout << #var << " : \n";view(var);}while(0)
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vc<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vv<T>& vv){ for(const auto& v : vv){ view(v); } }

vi sq;

int solve(int N){
    int ans = 0;
    for (int a = 0; a * a <= N; a++) for (int b = a; b * b + a * a <= N; b++) for (int c = b; c * c + b * b + a * a <= N; c++){
        int tmp = a * a + b * b + c * c;
        if (tmp <= N && c <= sq[N - tmp]) ans++;
    }
    return ans;
}

int main(){
    sq.resize(1 << 15, -1);
    for (int i = 0; i * i < 1 << 15; i++) sq[i * i] = i;
    vc<int> ans;
    while (true){
        int N; cin >> N;
        if (N == 0) break;
        ans.push_back(solve(N));
    }
    for (auto x : ans) cout << fixed << setprecision(16) << x << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 3056
final_rank: 2

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};
static const double EPS = 1e-8;
int dp[1000000][5];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 1; i * i <= n; i++) {
      for (int k = 1; k <= 4; k++) {
        for (int j = i * i; j <= n; j++) {
          dp[j][k] += dp[j - i * i][k - 1];
        }
      }
    }
    printf("%d\n", dp[n][4] + dp[n][3] + dp[n][2] + dp[n][1]);
  }
}
accuracy: 1
time_ms: 1630
memory_kb: 22636
final_rank: 18

code_snippet: #include <cstdio>
#include <cstring>
using namespace std;

int dp[1000000][5];

int main() {
    int n;
    while (~scanf("%d", &n)) {
        if (n == 0) break;

        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        
        for (int i = 1; i * i <= n; i++) {
            int square = i * i; // Store square value to avoid repeated computation
            for (int k = 1; k <= 4; k++) {
                #pragma omp parallel for    // Compiler directive for parallel execution
                for (int j = square; j <= n; j++) {
                    dp[j][k] += dp[j - square][k - 1];
                }
            }
        }

        printf("%d\n", dp[n][4] + dp[n][3] + dp[n][2] + dp[n][1]);
    }
}
accuracy: 1
time_ms: 1630
memory_kb: 22216
final_rank: 15

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};
static const double EPS = 1e-8;
int dp[1000000][5];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 1; i * i <= n; i++) {
      for (int k = 1; k <= 4; k++) {
        for (int j = 0; j <= n - i * i; j++) { // Optimized loop
          dp[j + i * i][k] += dp[j][k - 1]; // Adjusted the index
        }
      }
    }
    printf("%d\n", dp[n][4] + dp[n][3] + dp[n][2] + dp[n][1]);
  }
}
accuracy: 1
time_ms: 1640
memory_kb: 22736
final_rank: 19

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};
static const double EPS = 1e-8;

int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;
    int** dp = new int*[n + 1];
    for (int i = 0; i <= n; i++) {
      dp[i] = new int[5];
      memset(dp[i], 0, sizeof(int) * 5);
    }
    dp[0][0] = 1;
    for (int i = 1; i * i <= n; i++) {
      int square = i * i;
      for (int k = 1; k <= 4; k++) {
        for (int j = square; j <= n; j++) {
          dp[j][k] += dp[j - square][k - 1];
        }
      }
    }
    printf("%d\n", dp[n][4] + dp[n][3] + dp[n][2] + dp[n][1]);

    for (int i = 0; i <= n; i++) {
      delete[] dp[i];
    }
    delete[] dp;
  }
}
accuracy: 1
time_ms: 2700
memory_kb: 4112
final_rank: 12

code_snippet: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
typedef long long ll;
static const double EPS = 1e-8;
int dp[1000000][5];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 1; i * i <= n; i++) {
      int square = i * i;   // Calculate i*i once to avoid repeated calculations
      for (int k = 1; k <= 4; k++) {
        for (int j = square; j <= n; j++) {
          dp[j][k] += dp[j - square][k - 1];
        }
      }
    }
    printf("%d\n", dp[n][4] + dp[n][3] + dp[n][2] + dp[n][1]);
  }
}
accuracy: 1
time_ms: 1620
memory_kb: 22144
final_rank: 13

code_snippet: #include <cstdio>
#include <cstring>
using namespace std;

static const int MAX_N = 100000;
int dp[MAX_N][5];

int main() {
    int n;
    while (~scanf("%d", &n)) {
        if (n == 0)
            break;
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        for (int i = 1; i * i <= n; i++) {
            int sq = i * i;
            for (int k = 1; k <= 4; k++) {
                for (int j = sq; j <= n; j++) {
                    dp[j][k] += dp[j - sq][k - 1];
                }
            }
        }
        int result = dp[n][4] + dp[n][3] + dp[n][2] + dp[n][1];
        printf("%d\n", result);
    }
}
accuracy: 1
time_ms: 1370
memory_kb: 4532
final_rank: 8

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int dp[1000000][5];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 1; i * i <= n; i++) {
      int square = i * i;
      for (int k = 1; k <= 4; k++) {
        for (int j = square; j <= n; j++) {
          dp[j][k] += dp[j - square][k - 1];
        }
      }
    }
    printf("%d\n", dp[n][4] + dp[n][3] + dp[n][2] + dp[n][1]);
  }
}
accuracy: 1
time_ms: 1640
memory_kb: 22212
final_rank: 17

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};
static const double EPS = 1e-8;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;
    int dp[n+1][5];
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 1; i * i <= n; i++) {
      int square = i * i;
      for (int k = 1; k <= 4; k++) {
        for (int j = square; j <= n; j++) {
          dp[j][k] += dp[j - square][k - 1];
        }
      }
    }
    printf("%d\n", dp[n][4] + dp[n][3] + dp[n][2] + dp[n][1]);
  }
}
accuracy: 1
time_ms: 1380
memory_kb: 3864
final_rank: 7

code_snippet: #include <cstdio>
#include <cstring>

int dp[1000000][5];

int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    if (n == 0)
      break;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 1; i * i <= n; i++) {
      for (int k = 1; k <= 4; k++) {
        for (int j = i * i; j <= n; j++) {
          dp[j][k] += dp[j - i * i][k - 1];
        }
      }
    }
    printf("%d\n", dp[n][4] + dp[n][3] + dp[n][2] + dp[n][1]);
  }
}
accuracy: 1
time_ms: 1640
memory_kb: 22116
final_rank: 16

code_snippet: #include <cstdio>
#include <cstring>

const int MAX_N = 1000000;
const int MAX_K = 5;

long long dp[MAX_N][MAX_K];

int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 1; i * i <= n; i++) {
      for (int k = 1; k <= 4; k++) {
        for (int j = i * i; j <= n; j++) {
          dp[j][k] += dp[j - i * i][k - 1];
        }
      }
    }
    printf("%lld\n", dp[n][4] + dp[n][3] + dp[n][2] + dp[n][1]);
  }
}
accuracy: 1
time_ms: 3460
memory_kb: 41816
final_rank: 20

code_snippet: #include <cstdio>
#include <cstring>

int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;
      
    int** dp = new int*[n+1];
    for (int i = 0; i <= n; i++) {
      dp[i] = new int[5];
      memset(dp[i], 0, sizeof(int) * 5);
    }
    
    dp[0][0] = 1;
    for (int i = 1; i * i <= n; i++) {
      for (int k = 1; k <= 4; k++) {
        for (int j = i * i; j <= n; j++) {
          dp[j][k] += dp[j - i * i][k - 1];
        }
      }
    }
    
    int result = dp[n][4] + dp[n][3] + dp[n][2] + dp[n][1];
    
    for (int i = 0; i <= n; i++) {
      delete[] dp[i];
    }
    delete[] dp;
    
    printf("%d\n", result);
  }
}
accuracy: 1
time_ms: 2700
memory_kb: 3720
final_rank: 11

code_snippet: #include <cstdio>
#include <cstring>
#include <cmath>

const int MAX_N = 1000000;
const int MAX_K = 5;

int dp[MAX_N][MAX_K];

int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 1; i <= sqrt(n); i++) {
      for (int k = 1; k <= 4; k++) {
        for (int j = i * i; j <= n; j++) {
          dp[j][k] += dp[j - i * i][k - 1];
        }
      }
    }
    printf("%d\n", dp[n][4] + dp[n][3] + dp[n][2] + dp[n][1]);
  }
}
accuracy: 1
time_ms: 1630
memory_kb: 22212
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
int sum(long long n, int m, long long ini){
    if(n == 0) return 1;
    if(m == 0) return 0;
    int res = 0;
    for(long long i=ini;i*i<=n;i++){
        res += sum(n-i*i, m-1, i);
    }
    return res;
}
int main(){
    long long n;
    while(cin >> n, n){
        cout << sum(n, 4, 1) << endl;
    }
    return(0);
}
accuracy: 1
time_ms: 1920
memory_kb: 2956
final_rank: 10