prithivMLmods/Coder-Stat huggingface dataset:
Problem p02925 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, start, end) for (ll i = start; i < end; ++i)
#define dwn(i, n) for (int i = n; i >= 0; --i)
#define dwn2(i, start, end) for (ll i = start; i >= end; --i)
#define pll pair<ll, ll>
#define mk(x, y) make_pair(x, y)
#define pdl pair<double, ll>
const ll N = 4e3 + 200;
const ll INF = 0x3f3f3f;
const ll mode = 1e9 + 7;
int v[N][N];
int main() {
  ll n;
  cin >> n;
  rep2(i, 1, n + 1) {
    rep2(j, 1, n) {
      ll x;
      scanf("%lld", &v[i][j]);
      v[i][0] = 1;
    }
  }
  int flag = 0;
  ll sum = 0;
  ll mx = n * (n - 1) / 2;
  ll day = 0;
  while (1) {
    day++;
    map<ll, ll> mp2;
    int flag2 = 0;
    rep2(i, 1, n + 1) {
      ll k = v[i][0];
      if (!mp2[i] && k != n) {
        ll x = v[i][k];
        ll k2 = v[x][0];
        ll y = v[x][k2];
        if (y == i && !mp2[x]) {
          sum++;
          flag2 = 1;
          mp2[i] = 1;
          mp2[x] = 1;
          v[i][0]++;
          v[x][0]++;
          //					cout<<i<<" "<<x<<" "<<day<<endl;
        }
      }
    }
    if (!flag2) {
      flag = 1;
      break;
    }
    if (sum == mx) {
      break;
    }
  }
  if (flag)
    cout << "-1" << endl;
  else
    cout << day << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, start, end) for (ll i = start; i < end; ++i)
#define dwn(i, n) for (int i = n; i >= 0; --i)
#define dwn2(i, start, end) for (ll i = start; i >= end; --i)
#define pll pair<ll, ll>
#define mk(x, y) make_pair(x, y)
#define pdl pair<double, ll>
const ll N = 4e3 + 200;
const ll INF = 0x3f3f3f;
const ll mode = 1e9 + 7;
int v[N][N];
int main() {
  ll n;
  cin >> n;
  rep2(i, 1, n + 1) {
    rep2(j, 1, n) {
      ll x;
      scanf("%lld", &v[i][j]);
      v[i][0] = 1;
    }
  }
  int flag = 0;
  ll sum = 0;
  ll mx = n * (n - 1) / 2;
  ll day = 0;
  while (1) {
    day++;
    int mp2[N] = {0};
    int flag2 = 0;
    rep2(i, 1, n + 1) {
      ll k = v[i][0];
      if (!mp2[i] && k != n) {
        ll x = v[i][k];
        ll k2 = v[x][0];
        ll y = v[x][k2];
        if (y == i && !mp2[x]) {
          sum++;
          flag2 = 1;
          mp2[i] = 1;
          mp2[x] = 1;
          v[i][0]++;
          v[x][0]++;
          //					cout<<i<<" "<<x<<" "<<day<<endl;
        }
      }
    }
    if (!flag2) {
      flag = 1;
      break;
    }
    if (sum == mx) {
      break;
    }
  }
  if (flag)
    cout << "-1" << endl;
  else
    cout << day << endl;
  return 0;
}
Problem p02925 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

const int M = 1e3 + 3;
int n, a[M][M];
map<pair<int, int>, int> mp;
vector<int> adj[M];
int in[M * M], vis[M * M], ans;

int main() {
  scanf("%d", &n);
  int k = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - 1; j++) {
      int x;
      scanf("%d", &a[i][j]);
      x = a[i][j];
      int a = min(x - 1, i);
      int b = max(x - 1, i);
      if (mp[{a, b}] == 0) {
        mp[{a, b}] = k;
        k++;
      }
    }
    for (int j = 1; j < n - 1; j++) {
      adj[mp[{min(i, a[i][j - 1] - 1), max(i, a[i][j - 1] - 1)}]].push_back(
          mp[{min(i, a[i][j] - 1), max(i, a[i][j] - 1)}]);
      in[mp[{min(i, a[i][j] - 1), max(i, a[i][j] - 1)}]]++;
      // cout << mp[{min(i, a[i][j-1]-1), max(i, a[i][j-1]-1)}] << ' '<<
      // mp[{min(i, a[i][j]-1), max(i, a[i][j]-1)}] << endl;
    }
  }
  vector<int> order;
  queue<int> q;
  for (int i = 1; i < k; ++i)
    if (in[i] == 0) {
      vis[i] = 1, q.push(i);
      // cout << i << endl;
    }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    order.push_back(u);
    for (int i = 0; i < adj[u].size(); ++i) {
      --in[adj[u][i]];
      if (in[adj[u][i]] == 0) {
        q.push(adj[u][i]);
        vis[adj[u][i]] = vis[u] + 1;
        ans = max(ans, vis[u] + 1);
      }
    }
  }
  if (order.size() != k - 1)
    puts("-1");
  else {
    cout << ans << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

const int M = 1e3 + 3;
int n, a[M][M];
map<pair<int, int>, int> mp;
vector<int> adj[M * M];
int in[M * M], vis[M * M], ans = 1;

int main() {
  scanf("%d", &n);
  int k = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - 1; j++) {
      int x;
      scanf("%d", &a[i][j]);
      x = a[i][j];
      int a = min(x - 1, i);
      int b = max(x - 1, i);
      if (mp[{a, b}] == 0) {
        mp[{a, b}] = k;
        k++;
      }
    }
    for (int j = 1; j < n - 1; j++) {
      adj[mp[{min(i, a[i][j - 1] - 1), max(i, a[i][j - 1] - 1)}]].push_back(
          mp[{min(i, a[i][j] - 1), max(i, a[i][j] - 1)}]);
      in[mp[{min(i, a[i][j] - 1), max(i, a[i][j] - 1)}]]++;
      // cout << mp[{min(i, a[i][j-1]-1), max(i, a[i][j-1]-1)}] << ' '<<
      // mp[{min(i, a[i][j]-1), max(i, a[i][j]-1)}] << endl;
    }
  }
  vector<int> order;
  queue<int> q;
  for (int i = 1; i < k; ++i)
    if (in[i] == 0) {
      vis[i] = 1, q.push(i);
      // cout << i << endl;
    }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    order.push_back(u);
    for (int i = 0; i < adj[u].size(); ++i) {
      --in[adj[u][i]];
      if (in[adj[u][i]] == 0) {
        q.push(adj[u][i]);
        vis[adj[u][i]] = vis[u] + 1;
        ans = max(ans, vis[u] + 1);
      }
    }
  }
  if (order.size() != k - 1)
    puts("-1");
  else {
    cout << ans << endl;
  }
}
Problem p02926 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdint.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;

// BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree,
// chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu,
// topologicalsort, kyourenketuseibun

#define REP(i, a, b) for (ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")
#define MINS(a, b) a = min(a, (decltype(a))(b))
#define MAXS(a, b) a = max(a, (decltype(a))(b))

int main() {
  ll N;
  cin >> N;
  vector<pair<ll, ll>> P(N);

  REP(i, 0, N) { cin >> P[i].first >> P[i].second; }

  sort(P.begin(), P.end(), [](const pair<ll, ll> &a, const pair<ll, ll> &b) {
    return atan2l(a.second, a.first) < atan2(b.second, b.first);
  });

  ldb ans = 0;
  REP(i, 0, N) {
    REP(j, i, i + N) {
      pair<ll, ll> p = {0, 0};
      REP(k, i, j + 1) {
        p.first += P[k % N].first;
        p.second += P[k % N].second;
      }
      MAXS(ans, sqrtl(p.first * p.first + p.second * p.second));
    }
  }
  printf("%.11Lf\n", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdint.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;

// BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree,
// chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu,
// topologicalsort, kyourenketuseibun

#define REP(i, a, b) for (ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")
#define MINS(a, b) a = min(a, (decltype(a))(b))
#define MAXS(a, b) a = max(a, (decltype(a))(b))

int main() {
  ll N;
  cin >> N;
  vector<pair<ll, ll>> P(N);

  REP(i, 0, N) { cin >> P[i].first >> P[i].second; }

  sort(P.begin(), P.end(), [](const pair<ll, ll> &a, const pair<ll, ll> &b) {
    return atan2l(a.second, a.first) < atan2l(b.second, b.first);
  });

  ldb ans = 0;
  REP(i, 0, N) {
    REP(j, i, i + N) {
      pair<ll, ll> p = {0, 0};
      REP(k, i, j + 1) {
        p.first += P[k % N].first;
        p.second += P[k % N].second;
      }
      MAXS(ans, sqrtl(p.first * p.first + p.second * p.second));
    }
  }
  printf("%.11Lf\n", ans);
  return 0;
}
Problem p02926 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#define X first
#define Y second
#define mp make_pair
#define pb pop_back
#define eb emplace_back
#define sz(v) (int)v.size()

using namespace std;

typedef long long LL;
typedef long double LD;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int MAX_N = 105;

int x[MAX_N], y[MAX_N];

void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
  }
  vector<int> p(n);
  iota(p.begin(), p.end(), 0);
  LL ans = 0;
  while (clock() / CLOCKS_PER_SEC < 1.8) {
    shuffle(p.begin(), p.end(), rnd);
    LL dist = 0;
    pair<int, int> P = {0, 0};
    for (auto &i : p) {
      pair<int, int> newP = {P.X + x[i], P.Y + y[i]};
      LL curr = 1LL * newP.X * newP.X + 1LL * newP.Y * newP.Y;
      if (curr > dist) {
        dist = curr;
        P = newP;
      }
    }
    ans = max(ans, dist);
  }
  cout << sqrt((LD)ans) << "\n";
}

signed main() {
// #define TASK ""
#if !defined(LOCAL) && defined(TASK)
  freopen(TASK ".in", "r", stdin);
  freopen(TASK ".out", "w", stdout);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(20);
  int tests = 1;
  // cin >> tests;
  while (tests--) {
    solve();
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define X first
#define Y second
#define mp make_pair
#define pb pop_back
#define eb emplace_back
#define sz(v) (int)v.size()

using namespace std;

typedef long long LL;
typedef long double LD;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int MAX_N = 105;

int x[MAX_N], y[MAX_N];

void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
  }
  vector<int> p(n);
  iota(p.begin(), p.end(), 0);
  LL ans = 0;
  while (clock() / CLOCKS_PER_SEC < 1.5) {
    shuffle(p.begin(), p.end(), rnd);
    LL dist = 0;
    pair<int, int> P = {0, 0};
    for (auto &i : p) {
      pair<int, int> newP = {P.X + x[i], P.Y + y[i]};
      LL curr = 1LL * newP.X * newP.X + 1LL * newP.Y * newP.Y;
      if (curr > dist) {
        dist = curr;
        P = newP;
      }
    }
    ans = max(ans, dist);
  }
  cout << sqrt((LD)ans) << "\n";
}

signed main() {
// #define TASK ""
#if !defined(LOCAL) && defined(TASK)
  freopen(TASK ".in", "r", stdin);
  freopen(TASK ".out", "w", stdout);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(20);
  int tests = 1;
  // cin >> tests;
  while (tests--) {
    solve();
  }
  return 0;
}
Problem p02926 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline ll read() {
  ll x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return w == 1 ? x : -x;
}

ll n, ans;
struct node {
  ll x, y;
} p[maxn];

inline bool cmp(node a, node b) {
  ll x = a.x * b.y - a.y * b.x;
  if (x >= 0)
    return true;
  return false;
}

inline ll wk(int x, int y) {
  ll tx = 0, ty = 0;
  for (int i = x; i <= y; i++)
    tx += p[i].x, ty += p[i].y;
  return tx * tx + ty * ty;
}

int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    p[i].x = read(), p[i].y = read();
  sort(p + 1, p + n + 1, cmp);
  // for(int i=1;i<=n;i++) cout<<p[i].x<<" "<<p[i].y<<endl;
  for (int i = 1; i <= n; i++)
    p[i + n] = p[i];
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= i + n - 1; j++)
      ans = max(ans, wk(i, j));
  printf("%.10lf", sqrt(ans));
  return 0;
}


Fixed submission:
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline ll read() {
  ll x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return w == 1 ? x : -x;
}

ll n, ans;
struct node {
  ll x, y;
} p[maxn];

inline bool cmp(node a, node b) { return atan2(a.y, a.x) < atan2(b.y, b.x); }

inline ll wk(int x, int y) {
  ll tx = 0, ty = 0;
  for (int i = x; i <= y; i++)
    tx += p[i].x, ty += p[i].y;
  return tx * tx + ty * ty;
}

int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    p[i].x = read(), p[i].y = read();
  sort(p + 1, p + n + 1, cmp);
  // for(int i=1;i<=n;i++) cout<<p[i].x<<" "<<p[i].y<<endl;
  for (int i = 1; i <= n; i++)
    p[i + n] = p[i];
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= i + n - 1; j++)
      ans = max(ans, wk(i, j));
  printf("%.10lf", sqrt(ans));
  return 0;
}
Problem p02926 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pa;
const ll MOD = 1e9 + 7;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
//-----------------------------------------------------------//
long double sq(ll x, ll y) { return x * x + y * y; }

int main() {
  init();
  int N;
  cin >> N;
  vector<ll> x(N), y(N);
  rep(i, N) cin >> x[i] >> y[i];
  vector<ll> ivec(N);
  iota(all(ivec), 0);
  sort(all(ivec),
       [&](ll i, ll j) { return atan2(y[i], x[i]) < atan2(y[j], x[j]); });

  ivec.resize(2 * N);
  copy(all(ivec), ivec.begin() + N);

  long double ans = 0, tmp = 0, tans = 0;
  ll tx, ty;
  rep(i, N) {
    tx = 0;
    ty = 0;
    tans = 0;
    rep(j, N) {
      tx += x[ivec[i + j]];
      ty += y[ivec[i + j]];
      tmp = sq(tx, ty);
      if (tmp > tans) {
        tans = tmp;
        ans = max(ans, tans);
      } else {
        tx -= x[ivec[i + j]];
        ty -= y[ivec[i + j]];
      }
    }
  }
  cout << sqrt(ans) << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pa;
const ll MOD = 1e9 + 7;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
//-----------------------------------------------------------//
long double sq(ll x, ll y) { return x * x + y * y; }

int main() {
  init();
  int N;
  cin >> N;
  vector<ll> x(N), y(N);
  rep(i, N) cin >> x[i] >> y[i];
  vector<ll> ivec(N);
  iota(all(ivec), 0);
  sort(all(ivec),
       [&](ll i, ll j) { return atan2(y[i], x[i]) < atan2(y[j], x[j]); });

  rep(i, N) ivec.eb(ivec[i]);

  long double ans = 0, tmp = 0, tans = 0;
  ll tx, ty;
  rep(i, N) {
    tx = 0;
    ty = 0;
    tans = 0;
    rep(j, N) {
      tx += x[ivec[i + j]];
      ty += y[ivec[i + j]];
      tmp = sq(tx, ty);
      if (tmp > tans) {
        tans = tmp;
        ans = max(ans, tans);
      } else {
        tx -= x[ivec[i + j]];
        ty -= y[ivec[i + j]];
      }
    }
  }
  cout << sqrt(ans) << endl;
  return 0;
}
Problem p02926 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 105;
inline int read() {
  rg int res = 0, sign = 1;
  rg char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      sign = -1;
    ch = getchar();
  }
  do {
    res = (res << 3) + (res << 1) + (ch ^ 48);
    ch = getchar();
  } while (isdigit(ch));
  return res * sign;
}
int n, len;
ll ans;
struct str {
  int x, y;
} v[Maxn];
ll dis(ll x, ll y) { return x * x + y * y; };
void Search2(rg int x, rg int cx, rg int cy) {
  if (x > n) {
    ans = max(ans, dis(cx, cy));
    return;
  }
  Search2(x + 1, cx + v[x].x, cy + v[x].y);
  Search2(x + 1, cx, cy);
}
void Search1(rg int x, rg int cx, rg int cy) {
  if (x > len) {
    rg ll tmp, res = dis(cx, cy);
    for (int i = len + 1; i <= n - len; i++)
      if ((tmp = dis(cx + v[i].x, cy + v[i].y)) > res) {
        res = tmp;
        cx += v[i].x;
        cy += v[i].y;
      }
    Search2(n - len + 1, cx, cy);
    return;
  }
  Search1(x + 1, cx + v[x].x, cy + v[x].y);
  Search1(x + 1, cx, cy);
}
int main() {
  rg ll tmp;
  cin >> n;
  len = n <= 30 ? n / 2 : 10;
  for (int i = 1; i <= n; i++) {
    v[i].x = read();
    v[i].y = read();
  }
  for (rg int t = 1; t <= 100; t++) {
    random_shuffle(v + 1, v + n + 1);
    Search1(1, 0, 0);
  }
  printf("%.10f\n", sqrt(ans));
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 105;
inline int read() {
  rg int res = 0, sign = 1;
  rg char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      sign = -1;
    ch = getchar();
  }
  do {
    res = (res << 3) + (res << 1) + (ch ^ 48);
    ch = getchar();
  } while (isdigit(ch));
  return res * sign;
}
int n, len;
ll ans;
struct str {
  int x, y;
} v[Maxn];
ll dis(ll x, ll y) { return x * x + y * y; };
void Search2(rg int x, rg int cx, rg int cy) {
  if (x > n) {
    ans = max(ans, dis(cx, cy));
    return;
  }
  Search2(x + 1, cx + v[x].x, cy + v[x].y);
  Search2(x + 1, cx, cy);
}
void Search1(rg int x, rg int cx, rg int cy) {
  if (x > len) {
    rg ll tmp, res = dis(cx, cy);
    for (int i = len + 1; i <= n - len; i++)
      if ((tmp = dis(cx + v[i].x, cy + v[i].y)) > res) {
        res = tmp;
        cx += v[i].x;
        cy += v[i].y;
      }
    Search2(n - len + 1, cx, cy);
    return;
  }
  Search1(x + 1, cx + v[x].x, cy + v[x].y);
  Search1(x + 1, cx, cy);
}
int main() {
  rg ll tmp;
  cin >> n;
  len = (n <= 20) ? n / 2 : 10;
  for (int i = 1; i <= n; i++) {
    v[i].x = read();
    v[i].y = read();
  }
  for (rg int t = 1; t <= 100; t++) {
    random_shuffle(v + 1, v + n + 1);
    Search1(1, 0, 0);
  }
  printf("%.10f\n", sqrt(ans));
  return 0;
}
Problem p02926 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct ele {
  double x, y;
};
bool cmp(const ele &a, const ele &b) {
  if (a.x < 0 && b.x < 0)
    return cmp(b, a);
  if (a.x < 0)
    return false;
  if (b.x < 0)
    return true;
  double ap, bp;
  if (a.x == 0) {
    if (a.y < 0) {
      ap = INT_MIN;
    } else {
      ap = INT_MAX;
    }
  } else {
    ap = a.y / a.x;
  }
  if (b.x == 0) {
    if (b.y < 0) {
      bp = INT_MIN;
    } else {
      bp = INT_MAX;
    }
  } else {
    bp = b.y / b.x;
  }
  return ap < bp;
}

int main() {
  int N;
  cin >> N;
  vector<ele> e;
  int k = 0;
  for (int i = 0; i < N; ++i) {
    double x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) {
      k++;
      continue;
    }
    e.push_back({x, y});
  }
  N -= k;
  if (N == 0) {
    cout << 0 << "\n";
    return 0;
  }
  sort(e.begin(), e.end(), cmp);
  double ans = 0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j < N; ++j) {
      double x = 0, y = 0;
      for (int k = 0; k < i; ++k) {
        int id = (k + j) % N;
        x += e[id].x;
        y += e[id].y;
      }
      double temp = sqrt(x * x + y * y);
      ans = max(ans, temp);
    }
  }
  cout << setprecision(30) << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct ele {
  double x, y;
};
bool cmp(const ele &a, const ele &b) {
  return atan2(a.x, a.y) < atan2(b.x, b.y);
}

int main() {
  int N;
  cin >> N;
  vector<ele> e;
  int k = 0;
  for (int i = 0; i < N; ++i) {
    double x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) {
      k++;
      continue;
    }
    e.push_back({x, y});
  }
  N -= k;
  if (N == 0) {
    cout << 0 << "\n";
    return 0;
  }
  sort(e.begin(), e.end(), cmp);
  double ans = 0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j < N; ++j) {
      double x = 0, y = 0;
      for (int k = 0; k < i; ++k) {
        int id = (k + j) % N;
        x += e[id].x;
        y += e[id].y;
      }
      double temp = sqrt(x * x + y * y);
      ans = max(ans, temp);
    }
  }
  cout << setprecision(30) << ans;
  return 0;
}
Problem p02926 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll A, B, C, D, E, F, G, H, X, Y, Z, P, Q, M, N, T, R, K, W, L, ANS;
string S, S1, S2;
using p = pair<double, double>;

using p = pair<double, double>;
vector<p> V;

double dot(p a, p b) { return a.first * b.first + a.second * b.second; }

double norm(p a) { return sqrt(a.first * a.first + a.second * a.second); }

p operator+(p a, p b) { return p(a.first + b.first, a.second + b.second); }

p operator-(p a, p b) { return p(a.first - b.first, a.second - b.second); }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  rep(i, N) {
    cin >> X >> Y;
    if (X != 0 || Y != 0)
      V.push_back({X, Y});
  }

  sort(all(V), [](auto const &A1, auto const &A2) {
    return atan2(A1.second, A1.first) > atan2(A2.se, A2.fi);
  });

  p SUM = {0, 0};
  rep(i, N) { SUM = SUM + V[i]; }

  vector<p> RUISEKI;
  p NOW = {0, 0};
  RUISEKI.push_back(NOW);
  rep(i, N) {
    NOW = NOW + V[i];
    RUISEKI.push_back(NOW);
  }

  double ANS = 0;

  rep(i, N) {
    rep(j, i + 1) {
      ANS = max({norm(RUISEKI[i + 1] - RUISEKI[j]),
                 norm(SUM - (RUISEKI[i + 1] - RUISEKI[j])), ANS});
    }
  }

  cout << setprecision(15) << ANS << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll A, B, C, D, E, F, G, H, X, Y, Z, P, Q, M, N, T, R, K, W, L, ANS;
string S, S1, S2;
using p = pair<double, double>;

using p = pair<double, double>;
vector<p> V;

double dot(p a, p b) { return a.first * b.first + a.second * b.second; }

double norm(p a) { return sqrt(a.first * a.first + a.second * a.second); }

p operator+(p a, p b) { return p(a.first + b.first, a.second + b.second); }

p operator-(p a, p b) { return p(a.first - b.first, a.second - b.second); }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  rep(i, N) {
    cin >> X >> Y;
    if (X != 0 || Y != 0)
      V.push_back({X, Y});
  }

  N = V.size();

  sort(all(V), [](auto const &A1, auto const &A2) {
    return atan2(A1.second, A1.first) > atan2(A2.se, A2.fi);
  });

  p SUM = {0, 0};
  rep(i, N) { SUM = SUM + V[i]; }

  vector<p> RUISEKI;
  p NOW = {0, 0};
  RUISEKI.push_back(NOW);
  rep(i, N) {
    NOW = NOW + V[i];
    RUISEKI.push_back(NOW);
  }

  double ANS = 0;

  rep(i, N) {
    rep(j, i + 1) {
      ANS = max({norm(RUISEKI[i + 1] - RUISEKI[j]),
                 norm(SUM - (RUISEKI[i + 1] - RUISEKI[j])), ANS});
    }
  }

  cout << setprecision(15) << ANS << endl;
}
Problem p02926 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T> using Vvec = vector<vector<T>>;

ostream &operator<<(ostream &os, Pll &a) {
  return os << a.first << " " << a.second;
}

template <class T> void debug(T &v) {
  for (auto &x : v)
    cout << x << endl;
  cout << endl;
}

bool compAngle(Pll &a, Pll &b) {
  if (a.second == 0) {
    if (a.first > 0)
      return true;
    return b.second < 0;
  }
  if (b.second == 0) {
    if (b.first > 0)
      return false;
    return a.second > 0;
  }
  if (a.second * b.second < 0)
    return a.second > b.second;
  return a.first * b.second > b.first * a.second;
}

ll norm2(ll &X, ll &Y) { return X * X + Y * Y; }

int main() {
  int N;
  cin >> N;
  vector<Pll> vecs(N);
  for (auto &v : vecs)
    cin >> v.first >> v.second;
  sort(vecs.begin(), vecs.end(), compAngle);
  // debug(vecs);

  vector<ll> sx(N + 1), sy(N + 1);
  sx[0] = 0;
  sy[0] = 0;
  for (int i = 0; i < N; i++) {
    sx[i + 1] = sx[i] + vecs[i].first;
    sy[i + 1] = sy[i] + vecs[i].second;
  }

  ll ans = norm2(sx[N], sy[N]);
  for (int i = 0; i < N; i++) {
    for (int j = i; j < N; j++) {
      ll X = sx[j + 1] - sx[i];
      ll Y = sy[j + 1] - sy[i];
      ans = max(ans, norm2(X, Y));
      X = sx[N] - X;
      Y = sy[N] - Y;
      ans = max(ans, norm2(X, Y));
    }
  }

  cout << fixed << setprecision(20) << sqrt(ans) << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T> using Vvec = vector<vector<T>>;

ostream &operator<<(ostream &os, Pll &a) {
  return os << a.first << " " << a.second;
}

template <class T> void debug(T &v) {
  for (auto &x : v)
    cout << x << endl;
  cout << endl;
}

bool compAngle(Pll &a, Pll &b) {
  return atan2(a.second, a.first) < atan2(b.second, b.first);
}

ll norm2(ll &X, ll &Y) { return X * X + Y * Y; }

int main() {
  int N;
  cin >> N;
  vector<Pll> vecs(N);
  for (auto &v : vecs)
    cin >> v.first >> v.second;
  sort(vecs.begin(), vecs.end(), compAngle);
  // debug(vecs);

  vector<ll> sx(N + 1), sy(N + 1);
  sx[0] = 0;
  sy[0] = 0;
  for (int i = 0; i < N; i++) {
    sx[i + 1] = sx[i] + vecs[i].first;
    sy[i + 1] = sy[i] + vecs[i].second;
  }

  ll ans = norm2(sx[N], sy[N]);
  for (int i = 0; i < N; i++) {
    for (int j = i; j < N; j++) {
      ll X = sx[j + 1] - sx[i];
      ll Y = sy[j + 1] - sy[i];
      ans = max(ans, norm2(X, Y));
      X = sx[N] - X;
      Y = sy[N] - Y;
      ans = max(ans, norm2(X, Y));
    }
  }

  cout << fixed << setprecision(20) << sqrt(ans) << endl;
}
Problem p02926 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using lli = long long;

struct vec {
  lli x, y;
  vec() {}
  vec(lli x, lli y) : x(x), y(y) {}
  vec operator+(const vec &rhs) const { return vec(x + rhs.x, y + rhs.y); }
  void read() { scanf("%lld %lld", &x, &y); }
  lli cross(const vec rhs) const { return x * rhs.x - y * rhs.y; }
  lli len() { return x * x + y * y; }
  bool operator<(const vec &rhs) const {
    if (y * rhs.y < 0)
      return y > 0;
    else if (y == 0) {
      if (x > 0)
        return !(rhs.y == 0 && rhs.x > 0);
      else
        return !(rhs.y >= 0);
    } else if (rhs.y == 0 && rhs.x > 0)
      return false;
    else {
      return cross(rhs) > 0;
    }
  }
} arr[100];
int n;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    arr[i].read();
    if (arr[i].x == 0 && arr[i].y == 0) {
      n--;
      i--;
    }
  }

  sort(arr, arr + n);
  lli ans = 0;
  for (int i = 0; i < n; i++) {
    vec tmp(0, 0);
    for (int j = 0; j < n; j++) {
      tmp = tmp + arr[(i + j) % n];
      ans = max(ans, tmp.len());
    }
  }
  printf("%.12Lf\n", sqrtl(ans));

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using lli = long long;

struct vec {
  lli x, y;
  vec() {}
  vec(lli x, lli y) : x(x), y(y) {}
  vec operator+(const vec &rhs) const { return vec(x + rhs.x, y + rhs.y); }
  void read() { scanf("%lld %lld", &x, &y); }
  lli cross(const vec rhs) const { return x * rhs.y - y * rhs.x; }
  lli len() { return x * x + y * y; }
  bool operator<(const vec &rhs) const {
    if (y * rhs.y < 0)
      return y > 0;
    else if (y == 0) {
      if (x > 0)
        return !(rhs.y == 0 && rhs.x > 0);
      else
        return !(rhs.y >= 0);
    } else if (rhs.y == 0 && rhs.x > 0)
      return false;
    else {
      return cross(rhs) > 0;
    }
  }
} arr[100];
int n;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    arr[i].read();
    if (arr[i].x == 0 && arr[i].y == 0) {
      n--;
      i--;
    }
  }

  sort(arr, arr + n);
  lli ans = 0;
  for (int i = 0; i < n; i++) {
    vec tmp(0, 0);
    for (int j = 0; j < n; j++) {
      tmp = tmp + arr[(i + j) % n];
      ans = max(ans, tmp.len());
    }
  }
  printf("%.12Lf\n", sqrtl(ans));

  return 0;
}
Problem p02926 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
// #define int long long
#define pb push_back
#define fi first
#define se second
#define FF first
#define SS second
#define INF 2e18;
#define mp make_pair
#define ll long long
#define pii pair<int, int>
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define pd(x) printf("%d\n", x)
#define plld(x) printf("%lld\n", x)
#define endl '\n'
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define sz(s) (int)s.size()
#define all(x) x.begin(), x.end()
typedef long double f80;

int x[105], y[105];

signed main() {
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);

  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  fr(i, 1, n) { cin >> x[i] >> y[i]; }
  f80 z = (2 * acos(-1)) / 1000000;
  ll ans = 0;
  for (int i = 0; i < 1000000; i++) {
    f80 x1 = cos(z * i), y1 = sin(z * i);
    int xx = 0, yy = 0;
    fr(j, 1, n) {
      if (x1 * x[j] + y1 * y[j] >= 0) {
        xx += x[j], yy += y[j];
      }
    }
    ans = max(ans, (ll)xx * xx + (ll)yy * yy);
  }
  cout << setprecision(20) << fixed << sqrtl(ans);
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
// #define int long long
#define pb push_back
#define fi first
#define se second
#define FF first
#define SS second
#define INF 2e18;
#define mp make_pair
#define ll long long
#define pii pair<int, int>
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define pd(x) printf("%d\n", x)
#define plld(x) printf("%lld\n", x)
#define endl '\n'
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define sz(s) (int)s.size()
#define all(x) x.begin(), x.end()
typedef long double f80;

int x[105], y[105];

signed main() {
  // freopen("inp.txt","r",stdin);
  // freopen("out.txt","w",stdout);

  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  fr(i, 1, n) { cin >> x[i] >> y[i]; }
  f80 z = (2 * acos(-1)) / 1000000;
  ll ans = 0;
  for (int i = 0; i < 1000000; i++) {
    f80 x1 = cos(z * i), y1 = sin(z * i);
    int xx = 0, yy = 0;
    fr(j, 1, n) {
      if (x1 * x[j] + y1 * y[j] >= 0) {
        xx += x[j], yy += y[j];
      }
    }
    ans = max(ans, (ll)xx * xx + (ll)yy * yy);
  }
  cout << setprecision(20) << fixed << sqrtl(ans);
  return 0;
}
Problem p02926 (C++)

Buggy submission (status: Runtime Error):
/* while(!cin.eof()) */

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod (int)(1e9 + 7)
#define MAXI (int)(1e18 + 100)
#define N 1000200

int fre[N];

// Driver code to test above functions
int32_t main() {

#ifndef ONLINE_JUDGE
  // for getting input from inpu.txt
  freopen("input.txt", "r", stdin);
// for writing output to output.txt
// freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);

  int n;
  cin >> n;
  vector<pair<int, int>> xy(n);
  for (int i = 0; i < n; i++)
    cin >> xy[i].first >> xy[i].second;

  sort(xy.begin(), xy.end(),
       [](const pair<int, int> &l, const pair<int, int> &r) {
         return atan2l(l.second, l.first) < atan2l(r.second, r.first);
       });
  for (int i = 0; i < n; i++)
    xy.push_back(xy[i]);

  int res = 0;
  for (int i = 0; i < n; i++) {
    int x = 0, y = 0;
    for (int j = i; j < i + n; j++) {
      x += xy[j].first;
      y += xy[j].second;
      res = max(res, x * x + y * y);
    }
  }

  cout << fixed << setprecision(15) << sqrtl(res) << endl;

  return 0;
}

Fixed submission:
/* while(!cin.eof()) */

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod (int)(1e9 + 7)
#define MAXI (int)(1e18 + 100)
#define N 1000200

int fre[N];

// Driver code to test above functions
int32_t main() {

  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);

  int n;
  cin >> n;
  vector<pair<int, int>> xy(n);
  for (int i = 0; i < n; i++)
    cin >> xy[i].first >> xy[i].second;

  sort(xy.begin(), xy.end(),
       [](const pair<int, int> &l, const pair<int, int> &r) {
         return atan2l(l.second, l.first) < atan2l(r.second, r.first);
       });
  for (int i = 0; i < n; i++)
    xy.push_back(xy[i]);

  int res = 0;
  for (int i = 0; i < n; i++) {
    int x = 0, y = 0;
    for (int j = i; j < i + n; j++) {
      x += xy[j].first;
      y += xy[j].second;
      res = max(res, x * x + y * y);
    }
  }

  cout << fixed << setprecision(15) << sqrtl(res) << endl;

  return 0;
}
Problem p02926 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int N;
vector<pair<int, int>> v;

long double maxAns;

inline bool cmp(const pair<int, int> A, const pair<int, int> B) {
  long long f = (1LL * A.second * B.first) - (1LL * B.second * A.first);

  if (f < 0)
    return true;

  if (f > 0)
    return false;

  if (A.first == B.first)
    return A.second <= B.second;

  return A.first <= B.first;
}

int main() {
  cin >> N;

  for (int i = 1; i <= N; i++) {
    int x, y;
    cin >> x >> y;
    v.push_back({x, y});
  }

  sort(v.begin(), v.end(), cmp);

  for (int i = 0; i < N; i++)
    v.push_back(v[i]);

  for (int start = 0; start < N; start++) {
    long long x = 0LL, y = 0LL;

    for (int l = 1; l <= N; l++) {
      x += 1LL * v[start + l - 1].first;
      y += 1LL * v[start + l - 1].second;

      maxAns = max(maxAns, sqrtl(1LL * x * x + y * y));
    }
  }

  cout << fixed << setprecision(60) << maxAns << '\n';
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int N;
vector<pair<int, int>> v;

long double maxAns;

inline bool cmp(const pair<int, int> A, const pair<int, int> B) {
  return atan2(A.second, A.first) < atan2(B.second, B.first);
}

int main() {
  cin >> N;

  for (int i = 1; i <= N; i++) {
    int x, y;
    cin >> x >> y;
    v.push_back({x, y});
  }

  sort(v.begin(), v.end(), cmp);

  for (int i = 0; i < N; i++)
    v.push_back(v[i]);

  for (int start = 0; start < N; start++) {
    long long x = 0LL, y = 0LL;

    for (int l = 1; l <= N; l++) {
      x += 1LL * v[start + l - 1].first;
      y += 1LL * v[start + l - 1].second;

      maxAns = max(maxAns, sqrtl(1LL * x * x + y * y));
    }
  }

  cout << fixed << setprecision(60) << maxAns << '\n';
  return 0;
}
Problem p02926 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

const double eps = 1e-9;
struct V {
  double x, y;
  V(double x = 0, double y = 0) : x(x), y(y) {}
  V &operator+=(const V &v) {
    x += v.x;
    y += v.y;
    return *this;
  }
  V operator+(const V &v) const { return V(*this) += v; }

  double dot(const V &v) const { return x * v.x + y * v.y; }
  double cross(const V &v) const { return x * v.y + v.x * y; }
  double norm2() const { return x * x + y * y; }
  double norm() const { return sqrt(norm2()); }
  int ort() const { // orthant
    if (abs(x) < eps && abs(y) < eps)
      return 0;
    if (y > 0)
      return x > 0 ? 1 : 2;
    else
      return x < 0 ? 3 : 4;
  }
  bool operator<(const V &v) const {
    int o = ort(), vo = v.ort();
    if (o != vo)
      return o < vo;
    return cross(v) > 0;
  }
};

istream &operator>>(istream &is, V &v) {
  is >> v.x >> v.y;
  return is;
}
ostream &operator<<(ostream &os, V &v) {
  os << v.x << v.y;
  return os;
}

int main(void) {
  int n;
  cin >> n;
  vector<V> v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());

  double ans = 0;
  rep(l, n) {
    int r = l;
    V now;
    rep(i, n) {
      now += v[r];
      ans = max(ans, now.norm());
      r = (r + 1) % n;
    }
  }

  printf("%.12f", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

const double eps = 1e-9;
struct V {
  double x, y;
  V(double x = 0, double y = 0) : x(x), y(y) {}
  V &operator+=(const V &v) {
    x += v.x;
    y += v.y;
    return *this;
  }
  V operator+(const V &v) const { return V(*this) += v; }

  double dot(const V &v) const { return x * v.x + y * v.y; }
  double cross(const V &v) const { return x * v.y - v.x * y; }
  double norm2() const { return x * x + y * y; }
  double norm() const { return sqrt(norm2()); }
  int ort() const { // orthant
    if (abs(x) < eps && abs(y) < eps)
      return 0;
    if (y > 0)
      return x > 0 ? 1 : 2;
    else
      return x < 0 ? 3 : 4;
  }
  bool operator<(const V &v) const {
    int o = ort(), vo = v.ort();
    if (o != vo)
      return o < vo;
    return cross(v) > 0;
  }
};

istream &operator>>(istream &is, V &v) {
  is >> v.x >> v.y;
  return is;
}
ostream &operator<<(ostream &os, V &v) {
  os << v.x << v.y;
  return os;
}

int main(void) {
  int n;
  cin >> n;
  vector<V> v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());

  double ans = 0;
  rep(l, n) {
    int r = l;
    V now;
    rep(i, n) {
      now += v[r];
      ans = max(ans, now.norm());
      r = (r + 1) % n;
    }
  }

  printf("%.12f", ans);
  return 0;
}
Problem p02926 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 105;

int n;
long long x[N], y[N];
int per[N];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> x[i] >> y[i];
  for (int i = 0; i < n; i++)
    per[i] = i;
  sort(per, per + n, [&](int i, int j) {
    i = per[i];
    j = per[j];
    double alp1 = atan2(y[i], x[i]);
    double alp2 = atan2(y[j], x[j]);
    return alp1 < alp2;
  });
  long long best = 0;
  for (int i = 0; i < n; i++) {
    long long cur_x = 0, cur_y = 0;
    for (int j = i; j < i + n; j++) {
      cur_x += x[per[j % n]];
      cur_y += y[per[j % n]];
      best = max(best, cur_x * cur_x + cur_y * cur_y);
    }
  }
  cout << fixed << setprecision(15) << sqrt((long double)best) << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 105;

int n;
long long x[N], y[N];
int per[N];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> x[i] >> y[i];
  for (int i = 0; i < n; i++)
    per[i] = i;
  sort(per, per + n, [&](int i, int j) {
    double alp1 = atan2(y[i], x[i]);
    double alp2 = atan2(y[j], x[j]);
    return alp1 < alp2;
  });
  long long best = 0;
  for (int i = 0; i < n; i++) {
    long long cur_x = 0, cur_y = 0;
    for (int j = i; j < i + n; j++) {
      cur_x += x[per[j % n]];
      cur_y += y[per[j % n]];
      best = max(best, cur_x * cur_x + cur_y * cur_y);
    }
  }
  cout << fixed << setprecision(15) << sqrt((long double)best) << endl;
  return 0;
}
Problem p02927 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  int M, D;
  cin >> M >> D;

  int ans = 0;
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= D; i++) {
      if (M == (D / 10) * (D % 10))
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  int M, D;
  cin >> M >> D;

  int ans = 0;
  for (int i = 1; i <= M; i++) {
    for (int j = 2; j <= D; j++) {
      if ((i == (j / 10) * (j % 10)) && j / 10 >= 2 && j % 10 >= 2)
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02927 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (n); ++i)

int main() {
  ll m, d;
  cin >> m >> d;
  ll ans = 0;
  for (ll i = 1; i <= m; ++m) {
    for (ll j = 1; j <= d; ++d) {
      const auto j1 = j % 10;
      const auto j10 = j / 10;
      if (j1 >= 2 && j10 >= 2 && j1 * j10 == i) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (n); ++i)

int main() {
  ll m, d;
  cin >> m >> d;
  ll ans = 0;
  for (ll i = 1; i <= m; ++i) {
    for (ll j = 1; j <= d; ++j) {
      const auto j1 = j % 10;
      const auto j10 = j / 10;
      if (j1 >= 2 && j10 >= 2 && j1 * j10 == i) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02927 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int M, D;
int solve();

int main() {
  cin >> M >> D;
  int count = 0;
  int d10 = D / 10;
  int d1 = D % 10;
  for (int ans = 1; ans <= M; ans++) {
    for (int a10 = 2; a10 < d10; a10++) {
      if (ans % a10 == 0) {
        if (ans / a10 < 10) {
          if (ans / a10 > 1) {
            // cout << ans << " "  << a10 << " " << ans/a10 << endl;
            count++;
          }
        }
      }
    }
    if (ans % d10 == 0) {
      if (ans / d10 <= d1) {
        if (ans / d10 > 1) {
          // cout << ans << " "  << d10 << " " << ans/d10 << endl;
          count++;
        }
      }
    }
  }

  cout << count << endl;
}


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

int M, D;
int solve();

int main() {
  cin >> M >> D;
  int count = 0;
  int d10 = D / 10;
  int d1 = D % 10;
  for (int ans = 1; ans <= M; ans++) {
    for (int a10 = 2; a10 < d10; a10++) {
      if (ans % a10 == 0) {
        if (ans / a10 < 10) {
          if (ans / a10 > 1) {
            // cout << ans << " "  << a10 << " " << ans/a10 << endl;
            count++;
          }
        }
      }
    }
    if (d10 != 0) {
      if (ans % d10 == 0) {
        if (ans / d10 <= d1) {
          if (ans / d10 > 1) {
            // cout << ans << " "  << d10 << " " << ans/d10 << endl;
            count++;
          }
        }
      }
    }
  }

  cout << count << endl;
}
Problem p02927 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define ff first
#define ss second

const int MAXN = 1e3 + 7;
const ll INF = 1e18 + 7;
const ll MOD = 998244353;
const ll P = 311;
const int BLOCK = 720;

int main() {

#ifdef ____FILE_defined
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int m, d;
  cin >> m >> d;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= d; j++) {
      int a = j % 10, b = j / 10;
      if (j >= 0 && a >= 2 && b >= 2 && a * b == i) {
        ans++;
      }
    }
  }

  cout << ans;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define ff first
#define ss second

const int MAXN = 1e3 + 7;
const ll INF = 1e18 + 7;
const ll MOD = 998244353;
const ll P = 311;
const int BLOCK = 720;

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int m, d;
  cin >> m >> d;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= d; j++) {
      int a = j % 10, b = j / 10;
      if (j >= 0 && a >= 2 && b >= 2 && a * b == i) {
        ans++;
      }
    }
  }

  cout << ans;

  return 0;
}
Problem p02927 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
// const long long mod = 1000000007;
// const long long mod = 998244353;

long long c[64];

int main() {
  int M, D;
  scanf("%d %d", &M, &D);
  int res = 0;
  for (int m = 1; m <= M; m++) {
    for (int d = 22; d <= D; d++) {
      if (d % 10 >= 2 && (d / 10) * (d % 10) == m) {
        res++;
      }
    }
  }
  printf("%d", res);
  while (1)
    getchar();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
// const long long mod = 1000000007;
// const long long mod = 998244353;

long long c[64];

int main() {
  int M, D;
  scanf("%d %d", &M, &D);
  int res = 0;
  for (int m = 1; m <= M; m++) {
    for (int d = 22; d <= D; d++) {
      if (d % 10 >= 2 && (d / 10) * (d % 10) == m) {
        res++;
      }
    }
  }
  printf("%d", res);
  return 0;
}