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

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

int main() {
  int N;
  cin >> N;
  vector<int> x(N), y(N), h(N);

  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> h[i];
  }

  int MAX = 100;

  for (int posX = 0; posX <= MAX; posX) {
    for (int posY = 0; posY <= MAX; posY) {
      int needH = -1;

      for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
          int tmp = h[i] + abs(x[i] - posX) + abs(y[i] - posY);
          if (needH == -1) {
            needH = tmp;
          } else {
            // 高度の定義に反していたら
            if (needH != tmp) {
              needH = -2;
              break;
            }
          }
        }
      }
      // breakからそのままおりてきて。。。
      if (needH == -2)
        continue;

      for (int i = 0; i < N; i++) {
        if (h[i] == 0) {
          int dist = abs(x[i] - posX) + abs(y[i] - posY);
          // distが０より小さくないとmax（）で０が選ばれたことにならない
          if (needH > dist) {
            needH = -2;
            break;
          }
        }
      }

      if (needH == -2)
        continue;

      cout << posX << " " << posY << " " << needH << endl;
      return 0;
    }
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> x(N), y(N), h(N);

  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> h[i];
  }

  int MAX = 100;

  for (int posX = 0; posX <= MAX; posX++) {
    for (int posY = 0; posY <= MAX; posY++) {
      int needH = -1;

      for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
          int tmp = h[i] + abs(x[i] - posX) + abs(y[i] - posY);
          if (needH == -1) {
            needH = tmp;
          } else {
            // 高度の定義に反していたら
            if (needH != tmp) {
              needH = -2;
              break;
            }
          }
        }
      }
      // breakからそのままおりてきて。。。
      if (needH == -2)
        continue;

      for (int i = 0; i < N; i++) {
        if (h[i] == 0) {
          int dist = abs(x[i] - posX) + abs(y[i] - posY);
          // distが０より小さくないとmax（）で０が選ばれたことにならない
          if (needH > dist) {
            needH = -2;
            break;
          }
        }
      }

      if (needH == -2)
        continue;

      cout << posX << " " << posY << " " << needH << endl;
      return 0;
    }
  }
}
Problem p03240 (Python)

Buggy submission (status: Runtime Error):
# https://atcoder.jp/contests/abc112/tasks/abc112_c


# ピラミッドの中心は必ず0-100の中にある
# Hは1以上
# 与えられる情報だけで一意に定まる

# 中心座標をa,bと置いたとき、ある点x,yにおける高さは
# h(x,y; a,b)=max(H-|x-a|-|y-b|,0)である。
# ここで、真の高さとの誤差としてe(x,y;a,b)=|h(x,y;a,b) - h(x,y;Cx,Cy)|とすると。
# 任意のx,yでe=0となるa,bが答え。しかしHはわからないので0とする。
# そうすると任意のx,yでe(x,y;a,b)=constとなるa,bが答え。(ただしmaxの扱いが面倒なのでh==0は無視して処理を行う)
# またその定数constはHである

# 座標は10**4点。Nはたかだか100なので 最悪10**6回計算。間に合う。

import numpy as np
from itertools import product

N = int(input())
X, Y, H = [], [], []
for n in range(N):
    x, y, h = list(map(int, input().split()))
    # if h == 0:
    #     continue
    X.append(x)
    Y.append(y)
    H.append(h)

if N == 1:
    print(x, y, h)
    exit()

X = np.array(X)
Y = np.array(Y)
H = np.array(H)


def is_eq_loss(X, Y, H, a, b):
    loss = np.abs(-np.abs(X - a) - np.abs(Y - b) - H)
    mask = H == 0  # 高さがない疑いのところは最小値に合わせる
    if np.any(mask):
        loss[mask] = loss[mask].min()
    # print(loss[-1])
    if (loss[-1] == loss).all():
        return True, loss[-1]
    else:
        return False, False


for a, b in product(range(101), range(101)):
    flg, ansH = is_eq_loss(X, Y, H, a, b)
    if flg:
        ans = (a, b, ansH)

print(*ans)


Fixed submission:
# https://atcoder.jp/contests/abc112/tasks/abc112_c


# ピラミッドの中心は必ず0-100の中にある
# Hは1以上
# 与えられる情報だけで一意に定まる

# 中心座標をa,bと置いたとき、ある点x,yにおける高さは
# h(x,y; a,b)=max(H-|x-a|-|y-b|,0)である。
# ここで、真の高さとの誤差としてe(x,y;a,b)=|h(x,y;a,b) - h(x,y;Cx,Cy)|とすると。
# 任意のx,yでe=0となるa,bが答え。しかしHはわからないので0とする。
# そうすると任意のx,yでe(x,y;a,b)=constとなるa,bが答え。(ただしmaxの扱いが面倒なのでh==0は無視して処理を行う)
# またその定数constはHである

# 座標は10**4点。Nはたかだか100なので 最悪10**6回計算。間に合う。

import numpy as np
from itertools import product

N = int(input())
X, Y, H = [], [], []
for n in range(N):
    x, y, h = list(map(int, input().split()))
    # if h == 0:
    #     continue
    X.append(x)
    Y.append(y)
    H.append(h)

if N == 1:
    print(x, y, h)
    exit()

X = np.array(X)
Y = np.array(Y)
H = np.array(H)


def is_eq_loss(X, Y, H, a, b):
    loss = np.abs(-np.abs(X - a) - np.abs(Y - b) - H)
    mask = H == 0  # 高さがない疑いのところは最小値に合わせる
    if np.any(mask):
        loss[mask] = loss.min()
    # print(loss[-1])
    if (loss[-1] == loss).all():
        return True, loss[-1]
    else:
        return False, False


for a, b in product(range(101), range(101)):
    flg, ansH = is_eq_loss(X, Y, H, a, b)
    if flg:
        ans = (a, b, ansH)

print(*ans)
Problem p03240 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string.h>

using namespace std;

class C {
  int N;
  int64_t record[100][3];
  int64_t nonZeroPoint[3];

public:
  void solve() { cout << helper() << endl; }

  string helper() {
    ostringstream oss;
    int64_t h, tmph;
    bool flag{true};

    for (int cx{0}; cx <= 100; cx++) {
      for (int cy{0}; cy <= 100; cy++) {
        h = nonZeroPoint[2] + abs(nonZeroPoint[0] - cx) +
            abs(nonZeroPoint[1] - cy);
        if (h < 1)
          continue;

        flag = true;
        for (int i{0}; i < N; i++) {
          tmph = record[i][2] + abs(record[i][0] - cx) + abs(record[i][1] - cy);
          if (h != tmph) {
            flag = false;
            break;
          }
        }

        if (flag) {
          oss << cx << " " << cy << " " << h;
          return oss.str();
        }
      }
    }
  }

  C() {
    cin >> N;
    memset(record, 0, sizeof record);
    for (int i{0}; i < N; i++)
      cin >> record[i][0] >> record[i][1] >> record[i][2];

    for (int i{0}; i < N; i++) {
      if (record[i][2]) {
        nonZeroPoint[0] = record[i][0];
        nonZeroPoint[1] = record[i][1];
        nonZeroPoint[2] = record[i][2];
        break;
      }
    }
  }
};

int main() {
  C solution;
  solution.solve();

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string.h>

using namespace std;

class C {
  int N;
  int64_t record[100][3];
  int64_t nonZeroPoint[3];

public:
  void solve() { cout << helper() << endl; }

  string helper() {
    ostringstream oss;
    int64_t h, tmph;
    bool flag{true};

    for (int cx{0}; cx <= 100; cx++) {
      for (int cy{0}; cy <= 100; cy++) {
        h = nonZeroPoint[2] + abs(nonZeroPoint[0] - cx) +
            abs(nonZeroPoint[1] - cy);
        if (h < 1)
          continue;

        flag = true;
        for (int i{0}; i < N; i++) {
          tmph = h - abs(record[i][0] - cx) - abs(record[i][1] - cy);
          tmph = max((int64_t)0, tmph);
          if (record[i][2] != tmph) {
            flag = false;
            break;
          }
        }

        if (flag) {
          oss << cx << " " << cy << " " << h;
          return oss.str();
        }
      }
    }
  }

  C() {
    cin >> N;
    memset(record, 0, sizeof record);
    for (int i{0}; i < N; i++)
      cin >> record[i][0] >> record[i][1] >> record[i][2];

    for (int i{0}; i < N; i++) {
      if (record[i][2]) {
        nonZeroPoint[0] = record[i][0];
        nonZeroPoint[1] = record[i][1];
        nonZeroPoint[2] = record[i][2];
        break;
      }
    }
  }
};

int main() {
  C solution;
  solution.solve();

  return 0;
}
Problem p03240 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<vector<ll>> v(n, vector<ll>(3));
  rep(i, n) {
    rep(j, 3) { cin >> v[i][j]; }
  }

  bool flag = true;
  for (int x = 0; x <= 100; x++) {
    for (int y = 0; y <= 100; y++) {
      vector<ll> judge(0);
      rep(i, n) {
        if (v[i][2] > 0) {
          // judgeの要素を計算してmemに入れる
          ll mem, diffx, diffy;
          diffx = labs(x - v[i][0]);
          diffy = labs(y - v[i][1]);
          mem = diffx + diffy + v[i][2];
          judge.push_back(mem);
        }
      }

      if (judge.size() == 1) {
        rep(k, n) {
          if (v[k][2] > 0) {
            cout << v[k][0] << " " << v[k][1] << " " << v[k][2];
            exit(1);
          }
        }
      }

      flag = true;
      rep(j, judge.size() - 1) {
        if (judge[j] == judge[j + 1])
          continue;
        else {
          flag = false;
          break;
        }
      }

      if (flag) {
        cout << x << " " << y << " " << judge[0] << endl;
        break;
      }
    }
    if (flag)
      break;
  }

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<vector<ll>> v(n, vector<ll>(3));
  rep(i, n) {
    rep(j, 3) { cin >> v[i][j]; }
  }

  bool flag = true;
  for (int x = 0; x <= 100; x++) {
    for (int y = 0; y <= 100; y++) {
      vector<ll> judge(0);
      rep(i, n) {
        if (v[i][2] > 0) {
          // judgeの要素を計算してmemに入れる
          ll mem, diffx, diffy;
          diffx = labs(x - v[i][0]);
          diffy = labs(y - v[i][1]);
          mem = diffx + diffy + v[i][2];
          judge.push_back(mem);
        }
      }

      if (judge.size() == 1) {
        rep(k, n) {
          if (v[k][2] > 0) {
            cout << v[k][0] << " " << v[k][1] << " " << v[k][2];
            exit(0);
          }
        }
      }

      flag = true;
      rep(j, judge.size() - 1) {
        if (judge[j] == judge[j + 1])
          continue;
        else {
          flag = false;
          break;
        }
      }

      if (flag) {
        cout << x << " " << y << " " << judge[0] << endl;
        break;
      }
    }
    if (flag)
      break;
  }

  return 0;
}
Problem p03240 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  int x[100], y[100], h[100];
  rep(i, n) scanf("%d%d%d", x + i, y + i, h + i);

  rep(cy, 101) rep(cx, 101) {
    int lo = 0, hi = 2e9;
    while (lo < hi) {
      int mi = (lo + hi + 1) / 2;
      bool b = true;
      rep(i, n) if (max(mi - abs(x[i] - cx) - abs(y[i] - cy), 0) > h[i]) b =
          false;
      if (b)
        lo = mi;
      else
        hi = mi - 1;
    }

    bool ok = true;
    rep(i, n) if (max(lo - abs(x[i] - cx) - abs(y[i] - cy), 0) != h[i]) ok =
        false;
    if (ok) {
      printf("%d %d %d\n", cx, cy, lo);
      break;
    }
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  int x[100], y[100], h[100];
  rep(i, n) scanf("%d%d%d", x + i, y + i, h + i);

  rep(cy, 101) rep(cx, 101) {
    int lo = 0, hi = 1e9 + 1000;
    while (lo < hi) {
      int mi = (lo + hi + 1) / 2;
      bool b = true;
      rep(i, n) if (max(mi - abs(x[i] - cx) - abs(y[i] - cy), 0) > h[i]) b =
          false;
      if (b)
        lo = mi;
      else
        hi = mi - 1;
    }

    bool ok = true;
    rep(i, n) if (max(lo - abs(x[i] - cx) - abs(y[i] - cy), 0) != h[i]) ok =
        false;
    if (ok) {
      printf("%d %d %d\n", cx, cy, lo);
      break;
    }
  }

  return 0;
}
Problem p03240 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int main() {

  // input
  int n;
  cin >> n;

  // 全ての項目に対して3重でforループを回して各項目で条件を満たす組み合わせを出力する

  vector<int> data_x;
  vector<int> data_y;
  vector<int> data_h;
  vector<int> data_h2;

  for (int i = 0; i < n; ++i) {
    int x, y, h;
    vector<int> data;
    cin >> x >> y >> h;
    data_x.push_back(x);
    data_y.push_back(y);
    data_h.push_back(h);
    data_h2.push_back(h);
  }

  sort(data_h2.begin(), data_h2.end());
  int h_couho;
  h_couho = data_h2[n - 1];

  // x座標ループ
  for (int i = 0; i <= 100; ++i) {
    // y
    for (int j = 0; j <= 100; ++j) {
      // h
      for (int k = 1; k <= h_couho + 100; ++k) {
        int t_cnt = 0;
        // 調査結果
        for (int p = 0; p < n; ++p) {
          // 右辺
          int uhen = 0;
          uhen = max((k - abs(data_x[p] - i) - abs(data_y[p] - j)), 0);
          if (uhen == data_h[p]) {
            t_cnt++;
            if (t_cnt == n) {
              cout << i << " " << j << " " << k << endl;
              return 0;
            } else {
              continue;
            }
          } else {
            continue;
          }
        }
      }
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int main() {

  // input
  int n;
  cin >> n;

  // 全ての項目に対して3重でforループを回して各項目で条件を満たす組み合わせを出力する

  vector<int> data_x;
  vector<int> data_y;
  vector<int> data_h;
  vector<int> data_h2;

  for (int i = 0; i < n; ++i) {
    int x, y, h;
    vector<int> data;
    cin >> x >> y >> h;
    data_x.push_back(x);
    data_y.push_back(y);
    data_h.push_back(h);
    data_h2.push_back(h);
  }

  sort(data_h2.begin(), data_h2.end());
  int h_couho;
  h_couho = data_h2[n - 1];

  // x座標ループ
  for (int i = 0; i <= 100; ++i) {
    // y
    for (int j = 0; j <= 100; ++j) {
      // h
      for (int k = data_h2[0]; k <= h_couho + 100; ++k) {
        int t_cnt = 0;
        // 調査結果
        for (int p = 0; p < n; ++p) {
          // 右辺
          int uhen = 0;
          uhen = max((k - abs(data_x[p] - i) - abs(data_y[p] - j)), 0);
          if (uhen == data_h[p]) {
            t_cnt++;
            if (t_cnt == n) {
              cout << i << " " << j << " " << k << endl;
              return 0;
            } else {
              continue;
            }
          } else {
            continue;
          }
        }
      }
    }
  }

  return 0;
}
Problem p03240 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <memory>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

// constexpr std::int64_t INF = 1ull << 50;
constexpr int INF = 1 << 20;

auto main() -> int {
  std::uint32_t N;
  std::cin >> N;

  std::uint32_t t = INF;

  std::vector<std::int32_t> xs(N);
  std::vector<std::int32_t> ys(N);
  std::vector<std::int64_t> hs(N);
  for (auto i = 0ul; i < N; ++i) {
    std::cin >> xs[i] >> ys[i] >> hs[i];
    if (t == INF && hs[i] >= 1)
      t = i;
  }

  for (auto cy = 0; cy <= 100; ++cy) {
    for (auto cx = 0; cx <= 100; ++cx) {
      // h_t = H − |x_t − c_x| − | y_t − c_y|
      // h   = h_t + |x_t − c_x| + | y_t − c_y|
      const auto h = hs[t] + std::abs(xs[t] - cx) + std::abs(ys[t] - cy);
      if (h < 1)
        continue;

      bool f = true;
      for (auto i = 0ul; i < N; ++i) {
        f = f && ((h - std::abs(xs[i] - cx) - std::abs(ys[i] - cy)) == hs[i]);
      }
      if (f) {
        std::cout << cx << ' ' << cy << ' ' << h << std::endl;
        return 0;
      }
    }
  }

  return -1;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <memory>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

// constexpr std::int64_t INF = 1ull << 50;
constexpr int INF = 1 << 20;

auto main() -> int {
  std::uint32_t N;
  std::cin >> N;

  std::uint32_t t = INF;

  std::vector<std::int32_t> xs(N);
  std::vector<std::int32_t> ys(N);
  std::vector<std::int64_t> hs(N);
  for (auto i = 0ul; i < N; ++i) {
    std::cin >> xs[i] >> ys[i] >> hs[i];
    if (t == INF && hs[i] >= 1)
      t = i;
  }

  for (auto cy = 0; cy <= 100; ++cy) {
    for (auto cx = 0; cx <= 100; ++cx) {
      // h_t = H − |x_t − c_x| − | y_t − c_y|
      // h   = h_t + |x_t − c_x| + | y_t − c_y|
      const auto h = hs[t] + std::abs(xs[t] - cx) + std::abs(ys[t] - cy);
      if (h < 1)
        continue;

      bool f = true;
      for (auto i = 0ul; i < N; ++i) {
        f = f && (std::max(h - std::abs(xs[i] - cx) - std::abs(ys[i] - cy),
                           0l) == hs[i]);
      }
      if (f) {
        std::cout << cx << ' ' << cy << ' ' << h << std::endl;
        return 0;
      }
    }
  }

  return -1;
}
Problem p03240 (C++)

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

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

class cd {
public:
  int x;
  int y;
  int height;
};
const bool &comp(const cd &a, const cd &b) { return b.height < a.height; }

int main() {
  int n;
  cin >> n;
  vector<cd> mp(n);
  int a, b, c;
  rep(i, n) {
    cin >> a >> b >> c;
    mp[i].x = a;
    mp[i].y = b;
    mp[i].height = c;
  }
  sort(mp.begin(), mp.end(), comp);
  int h = 0;
  bool flg = true;
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      flg = true;
      h = mp[0].height + abs(mp[0].x - j) + abs(mp[0].y - i);
      for (int k = 1; k < n; k++) {
        if (mp[k].height != max(h - abs(mp[k].x - j) - abs(mp[k].y - i), 0)) {
          flg = false;
          break;
        }
      }
      if (flg) {
        cout << j << " ";
        break;
      }
    }
    if (flg) {
      cout << i << " ";
      break;
    }
  }
  cout << h << endl;
}


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

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

class cd {
public:
  int x;
  int y;
  int height;
};
bool comp(const cd &a, const cd &b) { return b.height < a.height; }

int main() {
  int n;
  cin >> n;
  vector<cd> mp(n);
  int a, b, c;
  rep(i, n) {
    cin >> a >> b >> c;
    mp[i].x = a;
    mp[i].y = b;
    mp[i].height = c;
  }
  sort(mp.begin(), mp.end(), comp);
  int h = 0;
  bool flg = true;
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      flg = true;
      h = mp[0].height + abs(mp[0].x - j) + abs(mp[0].y - i);
      for (int k = 1; k < n; k++) {
        if (mp[k].height != max(h - abs(mp[k].x - j) - abs(mp[k].y - i), 0)) {
          flg = false;
          break;
        }
      }
      if (flg) {
        cout << j << " ";
        break;
      }
    }
    if (flg) {
      cout << i << " ";
      break;
    }
  }
  cout << h << endl;
}
Problem p03240 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iomanip>
#include <ios> // std::left, std::right
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;

int Cx, Cy, H;
int get_height(int x, int y) {
  int tmp = H - abs(x - Cx) - abs(y - Cy);
  return max(tmp, 0);
}
int main() {
  int N;
  cin >> N;
  vector<vector<int>> pyramids(N, vector<int>(3, 0));
  REP(i, N) { cin >> pyramids[i][0] >> pyramids[i][1] >> pyramids[i][2]; }
  for (H = 0; H <= 1000000000; H++) {
    for (Cx = 0; Cx <= 100; Cx++) {
      for (Cy = 0; Cy <= 100; Cy++) {
        int count = 0;
        REP(i, N) {
          int px = pyramids[i][0];
          int py = pyramids[i][1];
          int pz = pyramids[i][2];
          if (pz == get_height(px, py)) {
            count++;
            // cout<<"OJ"<<count<<endl;
          }
        }
        if (count == N) {
          cout << Cx << " " << Cy << " " << H << endl;
          return 0;
        }
      }
    }
    // cout<<"X"<<Cx<<"Y"<<Cy<<"H"<<H<<endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <ios> // std::left, std::right
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;

int Cx, Cy, H;
int get_height(int x, int y) {
  int tmp = H - abs(x - Cx) - abs(y - Cy);
  return max(tmp, 0);
}
int main() {
  int N;
  cin >> N;
  vector<vector<int>> pyramids(N, vector<int>(3, 0));
  int hmax = 0;
  REP(i, N) {
    cin >> pyramids[i][0] >> pyramids[i][1] >> pyramids[i][2];
    hmax = max(hmax, pyramids[i][2]);
  }
  for (H = hmax; H <= 10000000000; H++) {
    for (Cx = 0; Cx <= 100; Cx++) {
      for (Cy = 0; Cy <= 100; Cy++) {
        int count = 0;
        REP(i, N) {
          int px = pyramids[i][0];
          int py = pyramids[i][1];
          int pz = pyramids[i][2];
          if (pz == get_height(px, py)) {
            count++;
            // cout<<"OJ"<<count<<endl;
          }
        }
        if (count == N) {
          cout << Cx << " " << Cy << " " << H << endl;
          return 0;
        }
      }
    }
    // cout<<"X"<<Cx<<"Y"<<Cy<<"H"<<H<<endl;
  }
}
Problem p03241 (C++)

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

using namespace std;

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int ans = 1;
  for (int i = 1; i <= m; ++i) {
    int x = i * (n - 1);
    if (x >= m)
      break;
    if ((m - x) % i == 0)
      ans = i;
  }
  return printf("%d", ans), 0;
}


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

using namespace std;

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  if (n == 1)
    return printf("%d", m), 0;
  int ans = 1;
  for (int i = 1; i <= m; ++i) {
    int x = i * (n - 1);
    if (x >= m)
      break;
    if ((m - x) % i == 0)
      ans = i;
  }
  return printf("%d", ans), 0;
}
Problem p03241 (C++)

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x, y) scanf("%d%d", &x, &y)
#define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x, y) scanf("%llu%llu", &x, &y)
#define Scll3(x, y, z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x, y) for (int x = 0; x < y; x++)
#define Repe(x, y, z) for (int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a) ? printf("Yes\n") : printf("No\n");
// }}} 2

// }}} 1

int main() {
  int n, m;
  Scd2(n, m);

  int ans = 0;
  for (int i = 1; i * n <= 1000000000; i++) {
    if (m % i == 0 && m / i >= n) {
      ans = i;
    }
  }

  printf("%d\n", ans);

  return 0;
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x, y) scanf("%d%d", &x, &y)
#define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x, y) scanf("%llu%llu", &x, &y)
#define Scll3(x, y, z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x, y) for (int x = 0; x < y; x++)
#define Repe(x, y, z) for (int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a) ? printf("Yes\n") : printf("No\n");
// }}} 2

// }}} 1

int main() {
  int n, m;
  Scd2(n, m);

  int ans = 0;
  if (n == 1) {
    printf("%d\n", m);
    return 0;
  }
  if (n == 2) {
    if (m % 2 == 0) {
      printf("%d\n", m / 2);
      return 0;
    }
    for (int i = 2; i * i <= 1000000000; i++) {
      if (m % i == 0 && m / i >= n) {
        ans = m / i;
        break;
      }
    }
    printf("%d\n", ans);
    return 0;
  }
  for (int i = 1; i * n <= 1000000000; i++) {
    if (m % i == 0 && m / i >= n) {
      ans = i;
    }
  }

  printf("%d\n", ans);

  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vector<ll> yakusu = divisor(m);
  ll ok = 0;
  ll ng = (int)yakusu.size() + 1;
  while (llabs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    ll tmp = m / yakusu[mid];
    if (tmp >= n) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << yakusu[ok] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vector<ll> yakusu = divisor(m);
  ll ok = 0;
  ll ng = (int)yakusu.size();
  while (llabs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    ll tmp = m / yakusu[mid];
    if (tmp >= n) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << yakusu[ok] << endl;
}
Problem p03241 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> divisor;
  for (int i = 2; i * i <= M; i++) {
    if (M % i == 0) {
      divisor.push_back(i);
      if (i * i < M)
        divisor.push_back(M / i);
    }
  }
  sort(divisor.begin(), divisor.end());
  cout << M / divisor[lower_bound(divisor.begin(), divisor.end(), N) -
                      divisor.begin()]
       << endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> divisor;
  divisor.push_back(1);
  divisor.push_back(M);
  for (int i = 2; i * i <= M; i++) {
    if (M % i == 0) {
      divisor.push_back(i);
      if (i * i < M)
        divisor.push_back(M / i);
    }
  }
  sort(divisor.begin(), divisor.end());
  cout << M / divisor[lower_bound(divisor.begin(), divisor.end(), N) -
                      divisor.begin()]
       << endl;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

#include <map>

using namespace std;

typedef long long LL;

LL n, m, p[100010], nump, ans;

void getp() {
  p[0] = 2;
  for (int x = 3; x <= m; ++x) {
    bool succ = true;
    for (int j = 0; j < nump && succ; ++j) {
      if (x % p[j] == 0)
        succ = false;
    }
    if (succ)
      p[++nump] = x;
  }
}

int main() {
  cin >> n >> m;

  for (LL i = 1; i <= m; ++i) {
    if (m % i == 0 && i * n <= m) {
      ans = max(i, ans);
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

#include <map>

using namespace std;

typedef long long LL;

LL n, m, p[100010], nump, ans;

void getp() {
  p[0] = 2;
  for (int x = 3; x <= m; ++x) {
    bool succ = true;
    for (int j = 0; j < nump && succ; ++j) {
      if (x % p[j] == 0)
        succ = false;
    }
    if (succ)
      p[++nump] = x;
  }
}

int main() {
  cin >> n >> m;

  LL b = LL(sqrt(m));

  for (LL i = 1; i <= b; ++i) {
    if (m % i == 0) {
      if (i * n <= m)
        ans = max(i, ans);
      LL ii = m / i;
      if (ii * n <= m)
        ans = max(ii, ans);
    }
  }
  cout << ans << endl;
}
Problem p03241 (C++)

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

using namespace std;
using ll = long long;
using ld = long double;

// #define int long long
// signed main(){
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  int d = 1;
  int ans = 1;
  while (d <= m) {
    if (m % d == 0) {
      if (m / d >= n)
        ans = d;
      else
        break;
    }
    if (m < n * d)
      break;
    d++;
  }
  cout << ans << "\n";

  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

// #define int long long
// signed main(){
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  int d = 1;
  int ans = 1;

  if (n == 1) {
    cout << m << "\n";
    return 0;
  }

  while (d <= m) {
    if (m % d == 0) {
      if (m / d >= n)
        ans = d;
      else
        break;
    }
    if (m < n * d)
      break;
    d++;
  }
  cout << ans << "\n";

  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF + 7;

struct edge {
  int to, cost;
};

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

  int n, m;
  cin >> n >> m;

  int i = n;
  for (; i <= m; i++) {
    if (m % i == 0)
      break;
  }
  cout << m / i << "\n";

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF + 7;

struct edge {
  int to, cost;
};

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

  int n, m;
  cin >> n >> m;

  int i = n;
  if (m % 2 == 1) {
    if (n % 2 == 0)
      i++;
    for (; i <= m; i += 2) {
      if (m % i == 0)
        break;
    }
  } else {
    for (; i <= m; i++) {
      if (m % i == 0)
        break;
    }
  }
  cout << m / i << "\n";

  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
int main() {
  int N, M;
  cin >> N >> M;
  while (M % N != 0) {
    N++;
  }
  cout << M / N << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
int main() {
  int N, M;
  cin >> N >> M;
  bool f = true;
  for (int i = 2; i * i <= M; i++) {
    if (M % i == 0) {
      f = false;
      break;
    }
  }
  if (f) {
    if (N == 1) {
      cout << M << endl;
    } else {
      cout << 1 << endl;
    }
    return 0;
  }
  while (M % N != 0) {
    N++;
  }
  cout << M / N << endl;
  return 0;
}
Problem p03241 (C++)

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

vector<long> calc(long x) {
  vector<long> dat;
  for (int i = 1; i * i <= x; i++) {
    if (x % i == 0)
      dat.push_back(i);
  }
  return dat;
}

int main() {
  long n, m;
  cin >> n >> m;
  vector<long> dat = calc(m);
  // for (auto e : dat) {
  // 	cout << e << endl;
  // }
  long ans = 1;
  for (int i = 0; i < dat.size(); i++) {
    if (dat[i] <= m / n) {
      ans = max(ans, dat[i]);
    }
    if (dat[i] >= n) {
      ans = max(ans, m / i);
    }
  }
  cout << ans << endl;
  return 0;
}

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

vector<long> calc(long x) {
  vector<long> dat;
  for (int i = 1; i * i <= x; i++) {
    if (x % i == 0)
      dat.push_back(i);
  }
  return dat;
}

int main() {
  long n, m;
  cin >> n >> m;
  vector<long> dat = calc(m);
  // for (auto e : dat) {
  // 	cout << e << endl;
  // }
  long ans = 1;
  for (int i = 0; i < dat.size(); i++) {
    if (dat[i] <= m / n) {
      ans = max(ans, dat[i]);
    }
    if (dat[i] >= n) {
      ans = max(ans, m / dat[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repR(i, n) for (int i = (n)-1; i > -1; i--)
#define rep1(i, n) for (int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for (int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> v;
  int D = 0;
  for (int i = 1; i < sqrt(M); i++) {
    if (M % i != 0)
      continue;
    int j = M / i;
    if (i <= M / N)
      v.push_back(i);
    if (j <= M / N)
      v.push_back(j);
  }
  cout << *max_element(v.begin(), v.end()) << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repR(i, n) for (int i = (n)-1; i > -1; i--)
#define rep1(i, n) for (int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for (int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> v;
  for (int i = 1; i <= (int)sqrt(M); i++) {
    if (M % i != 0)
      continue;
    int j = M / i;
    if (i <= M / N)
      v.push_back(i);
    if (j <= M / N)
      v.push_back(j);
  }
  cout << *max_element(v.begin(), v.end()) << endl;
  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = N; i <= M; i++) {
    if (M % i == 0) {
      cout << M / i << endl;
      return 0;
    }
  }
}


Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  for (int g = M / N; g > 0; g--) {
    if (M % g == 0) {
      cout << g << endl;
      return 0;
    }
  }
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < int(N); ++i)
using ll = long long;
const ll MOD = 1e9 + 7;
const int INF = 1001001001;
// const ll INF = 1000000000000000000LL;

// 使い方
int main() {
  ll n, m;
  cin >> n >> m;
  ll ans = 1;
  for (int i = m; i > 1; i--) {
    if (m % i != 0)
      continue;
    if (i * n <= m) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < int(N); ++i)
using ll = long long;
const ll MOD = 1e9 + 7;
const int INF = 1001001001;
// const ll INF = 1000000000000000000LL;

// 使い方
int main() {
  ll n, m;
  cin >> n >> m;
  ll ans = 1;
  for (int i = m / n; i > 1; i--) {
    if (m % i != 0)
      continue;
    if (i * n <= m) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main() {
  int n, m, ans = 1;
  cin >> n >> m;
  for (int i = 2; n * i <= m; i++) {
    if ((m - n * i) % i == 0) {
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int n, m, ans = 1;
  cin >> n >> m;
  if (n == 1) {
    ans = m;
  } else {
    for (int i = 2; n * i <= m; i++) {
      if ((m - n * i) % i == 0) {
        ans = i;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main() {
  int N;
  ll M;
  cin >> N >> M;
  vector<ll> X;
  for (int i = 1; i * i <= M; i++) {
    if (M % i == 0) {
      X.push_back(i);
      if (i * i != M) {
        X.push_back(M / i);
      }
    }
  }
  sort(X.begin(), X.end());
  ll ans = 0;
  int j = 0;
  while (X[j] * N <= M) {
    ans = X[j];
    j++;
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main() {
  int N;
  ll M;
  cin >> N >> M;
  vector<ll> X;
  for (int i = 1; i * i <= M; i++) {
    if (M % i == 0) {
      X.push_back(i);
      if (i * i != M) {
        X.push_back(M / i);
      }
    }
  }
  sort(X.begin(), X.end());
  ll ans = 0;
  int j = 0;
  while (X[j] * N <= M) {
    ans = X[j];
    j++;
    if (j == X.size()) {
      break;
    }
  }
  cout << ans << endl;
}
Problem p03241 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(), (a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;

int main() {
  ll n, m;
  cin >> n >> m;

  vector<ll> cd(1002003004, -1);

  ll it = 0;
  ll num = 1;

  while (num * num <= m) {

    if (m % num == 0) {
      cd[it] = num;
      it++;
      if (num != m / num) {
        cd[it] = m / num;
        it++;
      }
    }

    num++;
  }

  ll ans = 1;

  rep(i, it) {

    if (cd[i] * n <= m) {
      ans = max(ans, cd[i]);
    }
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(), (a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;

int main() {
  ll n, m;
  cin >> n >> m;

  vector<ll> cd(1002003, -1);

  ll it = 0;
  ll num = 1;

  while (num * num <= m) {

    if (m % num == 0) {
      cd[it] = num;
      it++;
      if (num != m / num) {
        cd[it] = m / num;
        it++;
      }
    }

    num++;
  }

  ll ans = 1;

  rep(i, it) {

    if (cd[i] * n <= m) {
      ans = max(ans, cd[i]);
    }
  }

  cout << ans << endl;
}
Problem p03241 (Python)

Buggy submission (status: Runtime Error):
import math

N, M = map(int, input().split())

d = max(d for d in range(1, math.ceil(M / (N - 1))) if M % d == 0)
print(d)


Fixed submission:
import math

N, M = map(int, input().split())

if N == 1:
    print(M)
else:
    d = max(d for d in range(1, math.ceil(M / (N - 1))) if M % d == 0)
    print(d)
Problem p03241 (Python)

Buggy submission (status: Time Limit Exceeded):
n, m = [int(_) for _ in input().split(" ")]
print(max([i for i in range(1, m // n + 1) if m % i == 0]))


Fixed submission:
n, m = [int(_) for _ in input().split(" ")]

ds = [i for i in range(1, int(m**0.5) + 1) if m % i == 0]
ds.extend([m // i for i in ds])
print(max([i for i in ds if i <= m // n]))
Problem p03241 (Python)

Buggy submission (status: Time Limit Exceeded):
N, M = map(int, input().split())
ceil = M / N
tmp = 1
mx = 0
while ceil >= tmp:
    if (M - tmp * (N - 1)) % tmp == 0:
        mx = tmp
    tmp += 1

print(mx)


Fixed submission:
N, M = map(int, input().split())
ceil = M // N
for i in range(1, ceil + 1)[::-1]:
    tmp = M - i * (N - 1)
    if tmp > 0 and tmp % i == 0:
        print(i)
        break
Problem p03241 (Python)

Buggy submission (status: Time Limit Exceeded):
N, M = map(int, input().split())
print(max(d for d in range(1, M // N + 1) if M % d == 0))


Fixed submission:
N, M = map(int, input().split())
print(next(d for d in reversed(range(M // N + 1)) if M % d == 0))
Problem p03241 (Python)

Buggy submission (status: Time Limit Exceeded):
# https://atcoder.jp/contests/abc112/tasks/abc112_d

n, m = map(int, input().split())
ans = 1
i = 1
limit = m / n
while i <= limit:
    if m % i == 0 and m // i >= n:
        ans = max(ans, i)
    i += 1
print(ans)


Fixed submission:
# https://atcoder.jp/contests/abc112/tasks/abc112_d

n, m = map(int, input().split())
if n == 1:
    ans = m
else:
    ans = 1
    i = 1
    limit = m / n
    while i <= limit:
        if m % i == 0 and m // i >= n:
            ans = max(ans, i)
        i += 1
print(ans)
Problem p03241 (C++)

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int ans = 1;
  for (int i = 1; i <= m; i++)
    if (m % i == 0 && m / i >= n)
      ans = i;
  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = m / n; i > 0; i--)
    if (m % i == 0 && m / i >= n) {
      cout << i << endl;
      return 0;
    }

  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a, ans = 1;
  a = m / n;
  for (size_t i = 1; i < a + 1; i++) {
    if (m % i == 0) {
      if (ans < i) {
        ans = i;
      }
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a, ans = 1;
  a = m / n;
  if (m % n == 0) {
    cout << m / n << endl;
    return 0;
  }
  for (size_t i = 1; i < a + 1; i++) {
    if (m % i == 0) {
      if (ans < i) {
        ans = i;
      }
    }
  }
  cout << ans << endl;
}
Problem p03241 (Python)

Buggy submission (status: Runtime Error):
N, M = map(int, input().split())  # 項数N, Aの和M

ans = 1

if N == 1:
    print(M)
    exit()

for i in range(1000000):
    if (M >= N * i) and (M % i == 0):
        ans = i

print(ans)


Fixed submission:
N, M = map(int, input().split())  # 項数N, Aの和M

ans = 1
for i in range(1, int(M ** (1 / 2)) + 1):
    if M % i != 0:
        continue
    j = M // i  # jはどんどん小さくなる
    if j >= N:
        ans = max(ans, i)
    if i >= N:
        ans = max(ans, j)

print(ans)
Problem p03241 (C++)

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

#define MAX_N 100000
#define MAX_M 1000000000
typedef long long int ll;

int main() {
  int n;
  ll m;

  std::cin >> n >> m;

  int ans = 1, tmp = 2;
  while (n * tmp <= m) {
    if (m % tmp == 0)
      ans = tmp;
    ++tmp;
  }

  std::cout << ans << std::endl;
}

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

#define MAX_N 100000
#define MAX_M 1000000000
typedef long long int ll;

int main() {
  int n;
  ll m;

  std::cin >> n >> m;

  if (n == 1) {
    std::cout << m << std::endl;
    return 0;
  }

  ll ans = 1, tmp = 2;
  while (tmp * tmp <= m) {
    if (n * tmp > m)
      break;
    if (m % tmp == 0) {
      ans = std::max(ans, tmp);
      if (n * m / tmp <= m) {
        ans = std::max(ans, m / tmp);
      }
    }
    ++tmp;
  }

  std::cout << ans << std::endl;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

int main() {
  int n, m;
  cin >> n >> m;
  int ans = 1;
  for (int i = 2; i <= m / n; i++) {
    if (!(m % i))
      ans = i;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

int main() {
  int n, m;
  cin >> n >> m;
  int ans = 1;
  if (n == 1) {
    cout << m << endl;
    return 0;
  }
  for (int i = 2; i <= m / n; i++) {
    if (!(m % i))
      ans = i;
  }
  cout << ans << endl;
  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s;
  if (m % n == 0)
    s = m / n;
  else {
    int s1 = m / n;
    s = s1 - 1;
    while ((m - (n - 1) * s) % s != 0)
      s--;
  }
  cout << s;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s;
  if (m % n == 0)
    s = m / n;
  else {
    s = m / (n + 1);
    while ((m - (n - 1) * s) % s != 0)
      s--;
  }
  cout << s;
  return 0;
}