alexjercan/bugnet huggingface dataset:
Problem p00820 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#define MAX_N 1 << 15 + 1
#define MAX_SQUARE 200
using namespace std;

int square[MAX_SQUARE];
int square_numbers;
int dp[5][MAX_N];

void calcDp() {
  for (int i = 1; i <= square_numbers; i++) {
    for (int k = 0; k < MAX_N; k++) {
      for (int j = 0; j < 4; j++) {
        if (k + square[i] >= MAX_N)
          break;
        dp[j + 1][k + square[i]] += dp[j][k];
      }
    }
  }
}

void calcSquare() {
  for (int i = 0; i < MAX_SQUARE; i++) {
    square[i] = i * i;
  }

  for (int i = 0; i < MAX_SQUARE; i++) {
    if (square[i] > (1 << 15)) {
      square_numbers = i - 1;
      break;
    }
  }
}

void init() {
  for (int i = 0; i < MAX_SQUARE; i++) {
    square[i] = 0;
  }

  for (int j = 0; j < 5; j++) {
    for (int k = 0; k < MAX_N; k++) {
      dp[j][k] = 0;
    }
  }
  dp[0][0] = 1;
}

int main() {
  init();
  calcSquare();
  calcDp();

  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      return 0;

    int sum = 0;
    for (int j = 1; j < 5; j++) {
      sum += dp[j][n];
    }
    cout << sum << endl;
  }
}

Error: MLE

Fixed submission:

#include <iostream>
#define MAX_N 1 << 15 + 1
#define MAX_SQUARE 200
using namespace std;

int square[MAX_SQUARE];
int square_numbers;
int dp[MAX_SQUARE][5][MAX_N];

void calcDp() {
  dp[0][0][0] = 1;

  for (int i = 1; i <= square_numbers; i++) {
    for (int k = 0; k < MAX_N; k++) {
      for (int j = 0; j < 5; j++) {
        for (int w = 0; w + j < 5; w++) {
          if (k + square[i] * w >= MAX_N)
            break;
          dp[i][j + w][k + square[i] * w] += dp[i - 1][j][k];
        }
      }
    }
  }
}

void calcSquare() {
  for (int i = 0; i < MAX_SQUARE; i++) {
    square[i] = i * i;
  }

  for (int i = 0; i < MAX_SQUARE; i++) {
    if (square[i] > (1 << 15)) {
      square_numbers = i - 1;
      break;
    }
  }
}

void init() {
  for (int i = 0; i < MAX_SQUARE; i++) {
    square[i] = 0;
  }

  for (int i = 0; i < MAX_SQUARE; i++) {
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < MAX_N; k++) {
        dp[i][j][k] = 0;
      }
    }
  }
}

int main() {
  init();
  calcSquare();
  calcDp();

  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      return 0;

    int sum = 0;
    for (int j = 1; j < 5; j++) {
      sum += dp[square_numbers][j][n];
    }
    cout << sum << endl;
  }
}
Problem p00820 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int num[181];
  for (int i = 0; i < 181; i++) {
    num[i] = (i + 1) * (i + 1);
  }

  int n;
  while (cin >> n, n) {
    int cnt = 0;
    int a, b, c;
    for (int i = 0; i < 181; i++) {
      if ((a = num[i]) > n)
        continue;
      if (a == n) {
        cnt++;
        break;
      }
      for (int j = i; j < 181; j++) {
        if ((b = a + num[j]) > n)
          continue;
        if (b == n) {
          cnt++;
          break;
        }
        for (int k = j; k < 181; k++) {
          if ((c = b + num[k]) > n)
            continue;
          if (c == n) {
            cnt++;
            break;
          }
          for (int m = k; m < 181; m++) {
            if ((c + num[m]) == n)
              cnt++;
          }
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#define Number 32768
using namespace std;

unsigned short int dp[Number][182][5] = {0};

int solve(int sum, int start, int cnt) {
  if (sum == 0 && cnt <= 4)
    return 1;
  if (sum < 0)
    return 0;
  if (cnt > 5)
    return 0;
  if (dp[sum][start][cnt] != 0)
    return dp[sum][start][cnt];
  int c = 0;
  for (int i = start; i * i <= sum; i++) {
    c += solve(sum - i * i, i, cnt + 1);
  }
  return (dp[sum][start][cnt] = c);
}

int main() {
  int n;
  while (cin >> n, n) {
    cout << solve(n, 1, 0) << endl;
  }
  return 0;
}
Problem p00820 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, j) REP((i), 0, (j))
#define REP(i, j, k) for (int i = (j); (i) < (k); ++i)
#define BW(a, x, b) ((a) <= (x) && (x) <= (b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n;

int dfs(int sum, int d, int c) {
  //  printf("%d %d\\n", sum, 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 += dfs(sum + i * i, i, c + 1);
  }
  return res;
}

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, j) REP((i), 0, (j))
#define REP(i, j, k) for (int i = (j); (i) < (k); ++i)
#define BW(a, x, b) ((a) <= (x) && (x) <= (b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n;

int dfs(int sum, int d, int c) {
  //  printf("%d %d\\n", sum, c);
  if (sum == n)
    return 1;
  if (c >= 4)
    return 0;
  int res = 0;
  REP(i, d, sqrt(n) + 1) {
    if (sum + i * i > n)
      break;
    ;
    res += dfs(sum + i * i, i, c + 1);
  }
  return res;
}

int main() {
  while (scanf("%d", &n) && n) {
    printf("%d\\n", dfs(0, 1, 0));
  }
  return 0;
}
Problem p00820 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#define N 182
#define N1 4
using namespace std;
void func(int, int, int);
int n, c, data[N];

int main() {
  data[0] = 0;
  for (int i = 1; i <= N; i++)
    data[i] = i * i;
  while (1) {
    cin >> n;
    if (!n)
      break;
    c = 0;
    func(0, 0, data[N - 1]);
    cout << c << endl;
  }
}

void func(int d, int sum, int b) {
  if (d == N1) {
    if (sum == n)
      c++;
    return;
  }
  for (int i = 0; i <= N; i++) {
    if (sum + data[i] > n)
      break;
    if (b >= data[i])
      func(d + 1, sum + data[i], data[i]);
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#define N 181
#define N1 4
using namespace std;
void func(int, int, int);
int n, c, data[N];

int main() {
  data[0] = 0;
  for (int i = 1; i <= N; i++)
    data[i] = i * i;
  while (1) {
    cin >> n;
    if (!n)
      break;
    c = 0;
    func(0, 0, data[N - 1]);
    cout << c << endl;
  }
}

void func(int d, int sum, int b) {
  if (sum > n)
    return;
  if (d == N1) {
    if (sum == n)
      c++;
    return;
  }
  for (int i = N - 1; i >= 0; i--) {
    if (b >= data[i] && sum + data[i] <= n)
      func(d + 1, sum + data[i], data[i]);
  }
}
Problem p00820 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <array>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

typedef long long int ll;
typedef double D;     // ??§?¨?????????????double???long double?????????
typedef complex<D> P; // Point
typedef pair<P, P> L; // Line
typedef vector<P> VP;

const int INF = (1 << 30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define EQ(n, m) (abs((n) - (m)) < EPS)

int dp[1 << 15][5];

// g++ -std=c++0x -msse4.2 -O3
// #include <bits/stdc++.h>
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout.precision(16);

  dp[0][0] = 1;
  for (int i = 1; i < 1 << 10; i++) {
    for (int j = 1; j < 1 << 15; j++) {
      for (int k = 0; k < 4; k++) {
        if (i * i <= j)
          dp[j][k + 1] += dp[j - i * i][k];
      }
    }
  }

  int n;
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 1; i <= 4; i++)
      ans += dp[n][i];
    cout << ans << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int dp[200][5][(1 << 15) + 1];

int main() {
  int n;
  vector<int> sq;

  for (int i = 1; i * i <= (1 << 15); ++i) {
    sq.push_back(i * i);
  }
  int sqn = sq.size();

  dp[0][0][0] = 1;

  for (int i = 1; i <= sqn; ++i) {
    for (int j = 0; j <= (1 << 15); ++j) {
      for (int k = 0; k <= 4; ++k) {
        for (int l = 0; l <= 4; ++l) {
          if (k + l <= 4 && j + sq[i - 1] * l <= (1 << 15)) {
            dp[i][k + l][j + sq[i - 1] * l] += dp[i - 1][k][j];
          }
        }
      }
    }
  }

  while (cin >> n && n) {
    int ret = 0;

    for (int i = 0; i <= 4; ++i) {
      ret += dp[sqn][i][n];
    }
    cout << ret << endl;
  }
}
Problem p00820 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int n;

int solve(int x, int k, int sum) {
  if (sum == n)
    return 1;
  if (k < 0 || sum + x * x > n)
    return 0;
  int ret = solve(x + 1, k, sum);
  while (k--)
    sum += x * x, ret += solve(x + 1, k, sum);
  return ret;
}

int main() {
  while (cin >> n, n) {
    cout << solve(1, 4, 0) << endl;
  }
  return 0;
}
Problem p00820 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>

using namespace std;

int ans;

void solve(int sum, int objNum, int cnt, int nowNum) {
  if (sum > objNum || cnt > 4)
    return;

  else if (sum == objNum) {
    ans++;
    return;
  } else if (cnt == 4)
    return;

  else if (cnt == 3) {
    int tmp = objNum - sum;
    if (nowNum * nowNum > tmp)
      return;
    if ((int)sqrt(tmp) * (int)sqrt(tmp) == tmp)
      ans++;

    return;
  }

  else {
    for (int i = nowNum; i * i <= objNum; i++) {
      solve(sum + i * i, objNum, cnt + 1, i);
    }
  }
}

int main() {

  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    ans = 0;
    solve(0, n, 0, 1);

    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>

using namespace std;

int ans;

void solve(int sum, int objNum, int cnt, int nowNum) {
  if (sum > objNum || cnt > 4)
    return;

  else if (sum == objNum) {
    ans++;
    return;
  }
  if (cnt == 4)
    return;

  else {
    for (int i = nowNum; i * i <= objNum; i++) {
      solve(sum + i * i, objNum, cnt + 1, i);
    }
  }
}

int main() {

  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    ans = 0;
    solve(0, n, 0, 1);

    cout << ans << endl;
  }

  return 0;
}
Problem p00820 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

vector<int> a;
typedef long long ll;
// int dp[1 << 15][1 << 8][5];

// idxより後でk個以内をとってnを作る方法は何通り
int dfs(int n, int idx, int k) {
  /*int & res = dp[n][idx][k];
  if (res != -1)return res;
*/
  int res = 0;
  if (n == 0)
    res = 1;
  else {
    res = 0;
    if (k != 0) {
      for (int i = idx; i < a.size(); i++) {
        if (n - a[i] >= 0) {
          res += dfs(n - a[i], i, k - 1);
        }
      }
    }
  }
  return res;
}

int main() {
  for (int i = 1; i * i <= 1 << 15; i++) {
    a.push_back(i * i);
  }
  // memset(dp, -1, sizeof(dp));
  int n;
  while (cin >> n && n) {
    cout << dfs(n, 0, 4) << endl;
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

vector<int> a;
typedef long long ll;
int dp[1 << 15][1 << 8][5];

// idxより後でk個以内をとってnを作る方法は何通り
int dfs(int n, int idx, int k) {
  int &res = dp[n][idx][k];
  if (res != -1)
    return res;

  if (n == 0)
    res = 1;
  else {
    res = 0;
    if (k != 0) {
      for (int i = idx; i < a.size(); i++) {
        if (n - a[i] >= 0) {
          res += dfs(n - a[i], i, k - 1);
        }
      }
    }
  }
  return res;
}

int main() {
  for (int i = 1; i * i <= 1 << 15; i++) {
    a.push_back(i * i);
  }
  memset(dp, -1, sizeof(dp));
  int n;
  while (cin >> n && n) {
    cout << dfs(n, 0, 4) << endl;
  }
}
Problem p00820 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define pi 3.141592653589793

int main() {
  int result[32769][5] = {};
  for (int i = 0; i * i < 32769; i++) {
    result[i * i][1]++;
    for (int j = i * i + 1; j < min(i * i * 4 + 1, 32769); j++) {
      for (int k = 2; k < 5; k++) {
        result[j][k] += result[j - i * i][k - 1];
      }
    }
  }
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    int ans = 0;
    for (int i = 1; i < 5; i++) {
      ans += result[n][i];
    }
    cout << ans << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define pi 3.141592653589793

int main() {
  int result[1000][5] = {};
  for (int i = 0; i * i < 1000; i++) {
    result[i * i][1]++;
    for (int j = i * i + 1; j < i * i * 4 + 1; j++) {
      for (int k = 2; k < 5; k++) {
        result[j][k] += result[j - i * i][k - 1];
      }
    }
  }
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    cout << result[n][4] << endl;
  }
  return 0;
}
Problem p00820 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)

template <class T> T sqr(T x) { return x * x; }

// int dp[(1<<15) + 10];

// map<pair<int, vector<int>> mp;

// int dfs(int now, vector<int> used) {
// if (used.size() == 5) return 0;
// if (now == 0) return 1;
// if (mp.count(make_pair(now, used))) return dp[now];

// int res = 0;
// for (int x = 1; sqr(x) <= (1<<15); x++) {
// REP(i,used.size()) if (used[i] == sqr(x)) continue;
// vector<int> nused = used;
// nused.push_back(sqr(x));
// int next = now - sqr(x);
// if (next >= 0) res += dfs(next, nused);
// }

// return (mp.insert(make_pair(make_pair(now, used), res)));
// }

int main() {
  int a;

  while (1) {
    scanf("%d", &a);
    if (a == 0)
      break;

    int mx = (1 << 15);
    int res = 0;
    for (int i = 0; sqr(i) <= mx; i++) {
      if (a - sqr(i) < 0)
        continue;
      for (int j = i; sqr(j) <= mx; j++) {
        if (a - sqr(i) - sqr(j) < 0)
          continue;
        for (int k = j; sqr(k) <= mx; k++) {
          if (a - sqr(i) - sqr(j) - sqr(k) < 0)
            continue;
          for (int l = k; sqr(l) <= mx; l++) {
            if (a - sqr(i) - sqr(j) - sqr(k) - sqr(l) == 0)
              res++;
          }
        }
      }
    }

    cout << res << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)

template <class T> T sqr(T x) { return x * x; }

int main() {
  int a;

  while (1) {
    scanf("%d", &a);
    if (a == 0)
      break;

    int mx = (1 << 15);
    int res = 0;
    for (int i = 0; sqr(i) < mx; i++) {
      for (int j = i; sqr(j) < mx; j++) {
        for (int k = j; sqr(k) < mx; k++) {
          for (int l = k; sqr(l) < mx; l++) {
            if (a - sqr(i) - sqr(j) - sqr(k) - sqr(l) == 0)
              res++;
          }
        }
      }
    }

    cout << res << endl;
  }

  return 0;
}
Problem p00820 (C++) — buggy submission, verdict: Runtime Error

// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it, X) for (auto it = (X).begin(); it != (X).end(); it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll, ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int n, ans[1 << 15];

void f(int cur, int n, int pre) {
  if (n >= 1 << 15)
    return;
  ans[n]++;
  if (cur == 4)
    return;
  rep2(i, pre, 182) { f(cur + 1, n + i * i, i); }
}

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

  f(0, 0, 1);
  while (cin >> n && n) {
    cout << ans[n] << endl;
  }
}

Error: -11

Fixed submission:

// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it, X) for (auto it = (X).begin(); it != (X).end(); it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll, ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int n, ans[1 << 15];

void f(int cur, int n, int pre) {
  if (n >= 1 << 15)
    return;
  ans[n]++;
  if (cur == 4)
    return;
  rep2(i, pre, INF) { f(cur + 1, n + i * i, i); }
}

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

  f(0, 0, 1);
  while (cin >> n && n) {
    cout << ans[n] << endl;
  }
}
Problem p00820 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
#define lpin(a, i, n)                                                          \\
  for (int i = 0; i < n; i++) {                                                \\
    cin >> a[i];                                                               \\
  }
int coun[500000], coun2[500000], coun3[500000], coun4[500000];
int main() {
  coun[1] = 1;
  coun2[2] = 1;
  coun3[3] = 1;
  coun4[4] = 1;
  for (int i = 2; i * i < 50000; i++) {
    coun[i * i]++;
    for (int j = i * i; j < 50000; j++) {
      coun2[j] += coun[j - i * i];
      coun3[j] += coun2[j - i * i];
      coun4[j] += coun3[j - i * i];
    }
  }
  while (1) {
    int x;
    cin >> x;
    if (x == 0)
      break;
    cout << (coun[x] + coun2[x] + coun3[x] + coun4[x]) << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
#define lpin(a, i, n)                                                          \\
  for (int i = 0; i < n; i++) {                                                \\
    cin >> a[i];                                                               \\
  }
int coun[500000], coun2[500000], coun3[500000], coun4[500000];
int main() {
  coun[1] = 1;
  coun2[2] = 1;
  coun3[3] = 1;
  coun4[4] = 1;
  for (int i = 2; i < sqrt(50000); i++) {
    coun[i * i]++;
    for (int j = i * i; j < 50000 - i * i; j++) {
      coun2[j] += coun[j - i * i];
      coun3[j] += coun2[j - i * i];
      coun4[j] += coun3[j - i * i];
    }
  }
  while (1) {
    int x;
    cin >> x;
    cout << (coun[x] + coun2[x] + coun3[x] + coun4[x]) << endl;
  }
  return 0;
}
Problem p00820 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int dp[2][(1 << 15) + 10][5];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  vector<int> s;
  for (int i = 1; i < 1 << 8 && i * i <= 1 << 15; i++) {
    s.push_back(i * i);
  }

  dp[0][0][0] = 1;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j <= 1 << 15; j++) {
      for (int k = 0; k <= 4; k++) {
        if (dp[0][j][k] == 0)
          continue;
        for (int l = 0; k + l <= 4; l++) {
          if (j + l * s[i] < (1 << 15) + 10) {
            dp[1][j + l * s[i]][k + l] += dp[0][j][k];
          }
        }
      }
    }
    swap(dp[0], dp[1]);
    for (int j = 0; j <= 1 << 15; j++) {
      for (int k = 0; k <= 4; k++) {
        dp[1][j][k] = 0;
      }
    }
  }

  int n;
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 1; i <= 4; i++) {
      ans += dp[0][n][i];
    }
    cout << ans << endl;
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int dp[183][(1 << 15) + 10][5];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  vector<int> s;
  for (int i = 1; i < 1 << 8 && i * i <= 1 << 15; i++) {
    s.push_back(i * i);
  }

  dp[0][0][0] = 1;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j <= 1 << 15; j++) {
      for (int k = 0; k <= 4; k++) {
        if (dp[i][j][k] == 0)
          continue;
        for (int l = 0; k + l <= 4; l++) {
          if (j + l * s[i] < (1 << 15) + 10) {
            dp[i + 1][j + l * s[i]][k + l] += dp[i][j][k];
          }
        }
      }
    }
  }

  int n;
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 1; i <= 4; i++) {
      ans += dp[s.size()][n][i];
    }
    cout << ans << endl;
  }
}