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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
  ll n;
  while (cin >> n, n) {
    vector<ll> ve, ans(n / 2 + 1);
    map<ll, ll> mp;
    fill(ans.begin(), ans.end(), 0);
    for (int i = 1; i * 2 < n; i++) {
      if (mp[(i * i) % n] == 0)
        ve.push_back((i * i) % n);
      mp[(i * i) % n] = 1;
    }
    sort(ve.begin(), ve.end());
    vector<ll>::iterator a = ve.begin(), b;
    for (; a != ve.end(); a++) {
      for (b = a; b != ve.end(); b++) {
        if (*b == *a)
          continue;
        if (((*b) - (*a)) > (n - 1) / 2) {
          ans[(n - (*b) + (*a))] += 2;
        } else {
          ans[(*b) - (*a)] += 2;
        }
      }
    }
    vector<ll>::iterator it = ans.begin();
    for (; it != ans.end(); it++)
      if ((*it) != 0)
        cout << (*it) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
  ll n;
  while (cin >> n, n) {
    vector<ll> ve;
    map<ll, ll> mp, ans;
    for (int i = 1; i * 2 < n; i++) {
      if (mp[(i * i) % n] == 0)
        ve.push_back((i * i) % n);
      mp[(i * i) % n] = 1;
    }
    sort(ve.begin(), ve.end());
    vector<ll>::iterator a = ve.begin(), b;
    for (; a != ve.end(); a++) {
      for (b = a; b != ve.end(); b++) {
        if (*b == *a)
          continue;
        if (((*b) - (*a)) > (n - 1) / 2) {
          ans[(n - (*b) + (*a))] += 2;
        } else {
          ans[(*b) - (*a)] += 2;
        }
      }
    }
    map<ll, ll>::iterator it = ans.begin();
    for (; it != ans.end(); it++)
      if ((*it).first != 0)
        cout << (*it).second << endl;
  }
  return 0;
}
Problem p00142 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;

int main() {
  int ans[1000000], n;
  while (cin >> n, n) {
    vector<int> vec;
    rep(i, (int)((n - 1) / 2) + 1) ans[i] = 0;
    REP(i, 1, n) vec.push_back((i * i) % n);
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    rep(i, vec.size()) {
      rep(j, vec.size()) {
        int diff = vec[i] - vec[j];
        if (diff < 0)
          diff += n;
        if (diff > (n - 1) / 2)
          diff = n - diff;
        if (1 <= diff && diff <= (n - 1) / 2)
          ans[diff]++;
      }
    }
    REP(i, 1, (int)((n - 1) / 2) + 1) cout << ans[i] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;

int main() {
  int ans[100000000], n;
  while (cin >> n, n) {
    vector<int> vec;
    rep(i, (int)((n - 1) / 2) + 1) ans[i] = 0;
    REP(i, 1, n) vec.push_back((i * i) % n);
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    rep(i, vec.size()) {
      rep(j, vec.size()) {
        int diff = vec[i] - vec[j];
        if (diff < 0)
          diff += n;
        if (diff > (n - 1) / 2)
          diff = n - diff;
        if (1 <= diff && diff <= (n - 1) / 2)
          ans[diff]++;
      }
    }
    REP(i, 1, (int)((n - 1) / 2) + 1) cout << ans[i] << endl;
  }
  return 0;
}
Problem p00142 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\\d_download\\visual studio
///2015\\projects\\programing_contest_c++\\debug\\a.txt" > "d:\\d_download\\visual
///studio 2015\\projects\\programing_contest_c++\\debug\\b.txt"

int main() {
  while (1) {
    int N;
    cin >> N;
    if (!N)
      break;
    set<int> aset;
    for (int i = 1; i < N; ++i) {
      int k = (i * i) % N;
      aset.emplace(k);
    }
    vector<int> nums(N);
    for (auto it = aset.begin(); it != aset.end(); ++it) {
      for (auto jt = next(it); jt != aset.end(); ++jt) {
        int sa = *it - *jt;
        if (sa < 0)
          sa += N;
        if (sa > (N - 1) / 2)
          sa = N - sa;
        nums[sa]++;
      }
    }
    for (int i = 1; i <= (N - 1) / 2; ++i) {
      cout << nums[i] * 2 << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\\d_download\\visual studio
///2015\\projects\\programing_contest_c++\\debug\\a.txt" > "d:\\d_download\\visual
///studio 2015\\projects\\programing_contest_c++\\debug\\b.txt"

int main() {
  while (1) {
    int N;
    cin >> N;
    set<int> aset;
    for (int i = 1; i < N; ++i) {
      int k = (i * i) % N;
      aset.emplace(k);
    }
    vector<int> nums(N);
    for (auto it = aset.begin(); it != aset.end(); ++it) {
      for (auto jt = next(it); jt != aset.end(); ++jt) {
        int sa = *it - *jt;
        if (sa < 0)
          sa += N;
        if (sa > (N - 1) / 2)
          sa = N - sa;
        nums[sa]++;
      }
    }
    for (int i = 1; i <= (N - 1) / 2; ++i) {
      cout << nums[i] * 2 << endl;
    }
  }
  return 0;
}
Problem p00142 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(void) {
  int n;
  while (cin >> n, n) {
    set<int> s;
    for (int i = 1; i < n; ++i) {
      s.insert((i * i) % n);
    }
    vector<int> v(s.size());
    int p = 0;
    for (set<int>::iterator it = s.begin(); it != s.end(); ++it)
      v[p++] = *it;
    vector<int> hist((n - 1) / 2 + 1);
    for (int i = 0; i < v.size(); ++i) {
      for (int j = v.size() - 1; j > i; --j) {
        int d = v[i] - v[j];
        // cerr<<v[i]<<" "<<v[j]<<endl;
        d = (d < 0) ? d + n : d;
        d = (d > (n - 1) / 2) ? n - d : d;
        ++hist[d];
      }
    }
    for (int i = 1; i <= (n - 1) / 2; ++i) {
      cout << hist[i] * 2 << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
int main(void) {
  int n;
  while (cin >> n, n) {
    set<int> s;
    for (int i = 1; i < n; ++i) {
      s.insert((i * i) % n);
    }
    vector<int> v;
    for (set<int>::iterator it = s.begin(); it != s.end(); ++it)
      v.push_back(*it);
    map<int, int> hist;
    for (int i = 0; i < v.size(); ++i) {
      for (int j = v.size() - 1; j > i; --j) {
        int d = v[i] - v[j];
        // cerr<<v[i]<<" "<<v[j]<<endl;
        d = (d < 0) ? d + n : d;
        d = (d > (n - 1) / 2) ? n - d : d;
        ++hist[d];
      }
    }
    for (int i = 1; i <= (n - 1) / 2; ++i) {
      cout << hist[i] * 2 << endl;
    }
  }
  return 0;
}
Problem p00142 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int mp[10000];
int main() {
  int n;
  while (scanf("%d", &n), n) {
    memset(mp, 0, sizeof(mp));
    unordered_set<int> se;
    for (int i = 1; i < n; i++)
      se.insert(i * i % n);
    for (auto i = se.begin(); i != se.end(); i++) {
      for (auto j = se.begin(); j != se.end(); j++) {
        if (i == j)
          continue;
        int d = *i - *j;
        if (d < 0)
          d += n;
        if (d > (n - 1) / 2)
          d -= n;
        mp[abs(d)]++;
      }
    }
    for (int i = 1; i <= (n - 1) / 2; i++)
      printf("%d\\n", mp[i]);
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  while (scanf("%d", &n), n) {
    unordered_set<int> se;
    for (int i = 1; i < n; i++)
      se.insert(i * i % n);
    map<int, int> mp;
    for (auto i = se.begin(); i != se.end(); i++) {
      for (auto j = se.begin(); j != se.end(); j++) {
        if (i == j)
          continue;
        int d = *i - *j;
        if (d < 0)
          d += n;
        if (d > (n - 1) / 2)
          d -= n;
        mp[abs(d)]++;
      }
    }
    for (auto p : mp)
      printf("%d\\n", p.second);
  }
}
Problem p00142 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
  int n;
  while (cin >> n && n) {
    set<int> st;
    int cnt[10000] = {};
    for (int i = 0; i < n - 1; i++) {
      st.insert((i + 1) * (i + 1) % n);
    }

    int const size = st.size();

    vector<int> vec;
    set<int>::iterator it = st.begin();
    for (it; it != st.end(); it++)
      vec.push_back(*it);

    for (int i = 0; i < size - 1; i++) {
      for (int j = i + 1; j < size; j++) {
        int temp = vec[i] - vec[j];
        if (temp < 0) {
          temp += n;
        }
        if (temp > (n - 1) / 2) {
          temp = n - temp;
        }
        cnt[temp]++;
      }
    }

    for (int i = 1; i <= (n - 1) / 2; i++) {
      cout << cnt[i] * 2 << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
  int n;
  while (cin >> n && n) {
    set<int> st;
    map<int, int> cnt;
    for (int i = 0; i < n - 1; i++) {
      st.insert((i + 1) * (i + 1) % n);
    }

    int const size = st.size();

    vector<int> vec;
    set<int>::iterator it = st.begin();
    for (it; it != st.end(); it++)
      vec.push_back(*it);

    for (int i = 0; i < size - 1; i++) {
      for (int j = i + 1; j < size; j++) {
        int temp = vec[i] - vec[j];
        if (temp < 0) {
          temp += n;
        }
        if (temp > (n - 1) / 2) {
          temp = n - temp;
        }
        cnt[temp]++;
      }
    }

    for (int i = 1; i <= (n - 1) / 2; i++) {
      cout << cnt[i] * 2 << endl;
    }
  }
  return 0;
}
Problem p00142 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <set>
#include <stdio.h>
#include <string.h>
void calc(int n) {
  int t, data[5001], p = 0, up, ans[5001];
  std::set<int> c1;
  memset(ans, 0, 5001 * 4);

  for (int i = 1; i < n; i++) {
    t = (i * i) % n;
    if (c1.find(t) == c1.end()) {
      c1.insert(t);
      data[p] = t;
      p++;
    }
  }
  up = (n - 1) / 2;
  for (int i = 0; i < p; i++) {
    for (int j = 0; j < p; j++) {
      if (i == j)
        continue;
      t = data[i] - data[j];
      t += t < 0 ? n : 0;
      t = t > up ? n - t : t;
      ans[t]++;
    }
  }
  for (int i = 1; i <= up; i++) {
    printf("%d\\n", ans[i]);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  while (n != 0) {
    calc(n);
    scanf("%d", &n);
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

void solve() {
  int n;
  while (cin >> n, n) {
    set<int> Set;
    for (int i = 1; i < n; ++i) {
      Set.insert((i * i) % n);
    }
    vector<int> Vec;
    for (set<int>::iterator Ite = Set.begin(); Ite != Set.end(); ++Ite) {
      Vec.push_back(*Ite);
    }
    map<int, int> Map;
    int size = Vec.size();
    for (int i = 0; i < size; ++i) {
      for (int j = i + 1; j < size; ++j) {
        int temp = Vec[i] - Vec[j];
        if (temp < 0) {
          temp += n;
        }
        if (temp > (n - 1) / 2) {
          temp = n - temp;
        }
        Map[temp]++;
      }
    }
    for (int i = size - 1; i >= 0; --i) {
      for (int j = i - 1; j >= 0; --j) {
        int temp = Vec[i] - Vec[j];
        if (temp < 0) {
          temp += n;
        }
        if (temp > (n - 1) / 2) {
          temp = n - temp;
        }
        Map[temp]++;
      }
    }
    for (int i = 1; i <= (n - 1) / 2; ++i) {
      cout << Map[i] << endl;
    }
  }
}

int main() {
  solve();
  return (0);
}
Problem p00142 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  int ans[10001], m[10001], f[10001], n, i, j, k, c;
  while (cin >> n) {
    if (n == 0)
      break;
    c = 0;
    for (i = 0; i < 10001; i++)
      ans[i] = f[i] = 0;
    for (i = 1; i <= (n - 1) / 2; i++) {
      k = (i * i) % n;
      if (f[k] == 0) {
        f[k] = 1;
        m[c++] = k;
      }
    }
    for (i = 0; i < c - 1; i++)
      for (j = i + 1; j < c; j++) {
        k = m[j] - m[i];
        k = k < 0 ? k + n : k;
        k = k > (n - 1) / 2 ? n - k : k;
        ans[k]++;
      }
    for (i = 1; i <= (n - 1) / 2; i++)
      cout << ans[i] * 2 << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  int ans[5001], m[10001], f[10001], n, i, j, k, c;
  while (cin >> n) {
    if (n == 0)
      break;
    c = 0;
    for (i = 0; i < 10001; i++)
      ans[i] = f[i] = 0;
    for (i = 1; i <= (n - 1) / 2; i++) {
      k = (i * i) % n;
      if (f[k] == 0) {
        f[k] = 1;
        m[c++] = k;
      }
    }
    for (i = 0; i < c - 1; i++)
      for (j = i + 1; j < c; j++) {
        k = m[j] - m[i];
        k = k < 0 ? k + n : k;
        k = k > (n - 1) / 2 ? n - k : k;
        ans[k]++;
      }
    for (i = 1; i <= (n - 1) / 2; i++)
      cout << ans[i] * 2 << endl;
  }
  return 0;
}
Problem p00142 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
using namespace std;

int n;
int *cnt, *use;
int p;
map<int, bool> memo;

int main() {
  while (true) {
    cin >> n;
    if (!n)
      return 0;
    memo.clear();
    p = 0;
    cnt = new int[(n + 1) / 2];
    use = new int[n];

    for (int i = 0; i < (n + 1) / 2; i++)
      cnt[i] = 0;

    for (int i = 1; i < n; i++) {
      int tmp = i * i % n;
      if (memo[tmp])
        continue;
      memo[tmp] = true;
      use[p++] = tmp;
    }

    for (int i = 0; i < p - 1; i++) {
      for (int k = i + 1; k < p; k++) {
        int tmp = use[i] - use[k];
        if (tmp < 0)
          tmp += n;
        if (tmp > (n - 1) / 2)
          tmp = n - tmp;
        cnt[tmp]++;
        tmp = use[k] - use[i];
        if (tmp < 0)
          tmp += n;
        if (tmp > (n - 1) / 2)
          tmp = n - tmp;
        cnt[tmp]++;
      }
    }

    for (int i = 1; i < (n + 1) / 2; i++)
      cout << cnt[i] << endl;

    delete[] cnt;
    delete[] use;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
using namespace std;

int n;

int *cnt;

map<int, bool> memo;

int main() {
  while (true) {
    cin >> n;
    if (!n)
      return 0;
    memo.clear();
    cnt = new int[(n + 1) / 2];
    for (int i = 0; i < (n + 1) / 2; i++)
      cnt[i] = 0;
    for (int i = 1; i < n; i++) {
      int tmp = (i * i) % n;
      memo[tmp] = true;
    }
    for (int i = 1; i < n - 1; i++) {
      if (!memo[i])
        continue;
      for (int k = i + 1; k < n; k++) {
        if (!memo[k])
          continue;
        int tmp = i - k;
        if (tmp < 0)
          tmp += n;
        if (tmp > n / 2)
          tmp = n - tmp;
        cnt[tmp] += 2;
      }
    }
    for (int i = 1; i < (n + 1) / 2; i++)
      cout << cnt[i] << endl;
  }
}
Problem p00142 (C++) — buggy submission, verdict: Runtime Error


#include <iostream>
#include <set>
#include <vector>
using namespace std;

int main() {
  int n;
  vector<int> num(50000);
  set<int> a;
  set<int>::iterator it, itr;
  int i, t;

  while (cin >> n, n) {
    a.clear();
    for (i = 0; i < n; i++)
      num[i] = 0;
    for (i = 1; i < n; i++)
      a.insert((i * i) % n);
    for (it = a.begin(); it != a.end(); it++) {
      for (itr = it; itr != a.end(); itr++) {
        t = *it - *itr;
        if (t == 0)
          continue;
        if (t < 0)
          t += n;
        if ((n - 1) / 2 < t)
          t = n - t;
        num[t] += 2;
      }
    }
    for (i = 1; i <= (n - 1) / 2; i++)
      cout << num[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:


#include <iostream>
#include <set>
#include <vector>
using namespace std;

int main() {
  int n;
  vector<int> num(20000);
  set<int> a;
  set<int>::iterator it, itr, ite;
  int i, t;

  while (cin >> n, n) {
    a.clear();
    for (i = 0; i < 20000; i++)
      num[i] = 0;
    for (i = 1; i < n; i++)
      a.insert((i * i) % n);
    ite = a.end();
    ite--;
    for (it = a.begin(); it != ite; it++) {
      itr = it;
      for (itr++; itr != a.end(); itr++) {
        t = *it - *itr;
        if (t < 0)
          t += n;
        if ((n - 1) / 2 < t)
          t = n - t;
        num[t] += 2;
      }
    }
    for (i = 1; i <= (n - 1) / 2; i++)
      cout << num[i] << endl;
  }
  return 0;
}
Problem p00142 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
 * 0142.cpp
 *
 *  Created on: 2011/07/27
 *      Author: isa
 */

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

using namespace std;

int main(void) {
  int n;

  while (cin >> n && n) {
    vector<int> v;
    int times[((n - 1) / 2) + 1];

    memset(times, 0, sizeof(times));
    for (int i = 1; i < n; i++) {
      if (find(v.begin(), v.end(), i * i % n) == v.end()) {
        v.push_back(i * i % n);
      }
    }

    for (int i = 0; i < v.size(); i++) {
      for (int j = 0; j < v.size(); j++) {
        int tmp;
        if (i == j)
          continue;
        tmp = v[i] - v[j];
        if (tmp < 0)
          tmp += n;
        if (tmp > (n - 1) / 2)
          tmp = n - tmp;
        times[tmp]++;
      }
    }
    for (int i = 1; i <= (n - 1) / 2; i++) {
      cout << times[i] << endl;
    }
  }
}

Error: TLE

Fixed submission:

/*
 * 0142.cpp
 *
 *  Created on: 2011/07/27
 *      Author: isa
 */

#include <cstring>
#include <iostream>
#include <map>
#include <set>

using namespace std;

int main(void) {
  int n;

  while (cin >> n && n) {
    set<int> s;
    int times[((n - 1) / 2) + 1];

    memset(times, 0, sizeof(times));
    for (int i = 1; i < n; i++) {
      s.insert((i * i) % n);
      // cout << i*i%n << endl;
    }

    set<int>::iterator it, jt;

    for (it = s.begin(); it != s.end(); ++it) {
      for (jt = s.begin(); jt != s.end(); ++jt) {
        int tmp;
        if (it == jt)
          continue;
        tmp = *it - *jt;
        if (tmp < 0)
          tmp += n;
        if (tmp > (n - 1) / 2)
          tmp = n - tmp;
        times[tmp]++;
      }
    }
    for (int i = 1; i <= (n - 1) / 2; i++) {
      cout << times[i] << endl;
    }
  }
}
Problem p00142 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {

  int N;

  while (cin >> N && N) {
    int score[(N - 1) / 2 + 5];
    fill(score, score + (N - 1) / 2 + 3, 0);
    set<int> st;
    for (int i = 1; i < N; i++) {
      st.insert(i * i % N);
    }

    vector<int> vec;
    for (set<int>::iterator it = st.begin(); it != st.end(); it++) {
      vec.push_back(*it);
    }

    int const M = st.size();

    for (int i = 0; i < M; i++) {
      for (int j = 0; j < M; j++) {
        if (vec[i] == vec[j])
          continue;

        int diff = vec[i] - vec[j];
        if (diff < 0)
          diff += N;
        if ((N - 1) / 2 < diff) {
          diff = N - diff;
        }
        score[diff]++;
      }
    }

    for (int i = 1; i <= (N - 1) / 2; i++) {
      cout << score[i] << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {

  int N;

  while (cin >> N && N) {
    map<int, int> mp;
    set<int> st;
    for (int i = 1; i < N; i++) {
      st.insert(i * i % N);
    }

    vector<int> vec;
    for (set<int>::iterator it = st.begin(); it != st.end(); it++) {
      vec.push_back(*it);
    }

    int const M = st.size();

    for (int i = 0; i < M; i++) {
      for (int j = 0; j < M; j++) {
        if (vec[i] == vec[j])
          continue;

        int diff = vec[i] - vec[j];
        if (diff < 0)
          diff += N;
        if ((N - 1) / 2 < diff) {
          diff = N - diff;
        }
        mp[diff]++;
      }
    }

    for (int i = 1; i <= (N - 1) / 2; i++) {
      cout << mp[i] << endl;
    }
  }

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

#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
int sq[10000], v[9999];
int main() {
  int i, n;
  for (i = 1; i < 10000; i++)
    sq[i] = i * i;
  for (; scanf("%d", &n), n;) {
    set<int> s;
    memset(v, 0, sizeof(v));
    for (i = 1; i < n; i++)
      s.insert(sq[i] % n);
    set<int>::iterator is, iS;
    for (is = s.begin(); is != s.end(); is++)
      for (iS = is, iS++; iS != s.end(); iS++) {
        i = *iS - *is;
        if (i > (n - 1) / 2)
          i = n - i;
        v[i]++;
      }
    for (i = 1; i <= (n - 1) / 2; i++)
      printf("%d\\n", v[i] * 2);
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <map>
#include <set>
using namespace std;
int main() {
  int i, n;
  for (; scanf("%d", &n), n;) {
    set<int> s;
    map<int, int> v;
    for (i = 1; i < n; i++)
      s.insert(i * i % n);
    set<int>::iterator is, iS;
    for (is = s.begin(); is != s.end(); is++)
      for (iS = is, iS++; iS != s.end(); iS++) {
        i = *iS - *is;
        if (i > (n - 1) / 2)
          i = n - i;
        v[i]++;
      }
    for (i = 1; i <= (n - 1) / 2; i++)
      printf("%d\\n", v[i] * 2);
  }
}
Problem p00142 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (n == 0)
      return 0;

    set<int> si;
    for (int i = 1; i < n; ++i)
      si.insert(i * i % n);

    vector<int> ret((n - 1) / 2 + 1, 0);
    set<int>::iterator it1, it2;
    for (it1 = si.begin(); it1 != si.end(); ++it1) {
      for (it2 = it1, ++it2; it2 != si.end(); ++it2) {
        int a = (*it1) - (*it2);
        if (a < 0)
          a += n;
        if (a > (n - 1) / 2)
          a = n - a;
        ret[a] += 2;
      }
    }

    for (int i = 1; i <= (n - 1) / 2; ++i)
      cout << ret[i] << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (n == 0)
      return 0;

    set<int> si;
    for (int i = 1; i < n; ++i)
      si.insert(i * i % n);

    vector<int> ret((n - 1) / 2 + 1, 0);
    set<int>::iterator it1, it2;
    for (it1 = si.begin(); it1 != si.end(); ++it1) {
      for (it2 = si.begin(); it2 != si.end(); ++it2) {
        if (it1 == it2)
          continue;
        int a = (*it1) - (*it2);
        if (a < 0)
          a += n;
        if (a > (n - 1) / 2)
          a = n - a;
        ++ret[a];
      }
    }

    for (int i = 1; i <= (n - 1) / 2; ++i)
      cout << ret[i] << endl;
  }
}