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

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

#define REP(i, b, n) for (long long int i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define ALL(C) (C).begin(), (C).end()
#define FOR(it, o)                                                             \\
  for (__typeof((o).begin()) it = (o).begin(); it != (o).end(); ++it)

const long long int MAX = 1000001;
bool p[MAX];
using namespace std;

vector<long long int> primeFactor(long long int n) {
  vector<long long int> v;
  rep(i, sqrt(n) + 1) {
    if (!p[i])
      continue;
    if (n % i != 0)
      continue;
    long long int cnt = 1;
    n /= i;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    v.push_back(cnt);
  }
  if (n != 1)
    v.push_back(1);
  return v;
}

long long int solve(vector<long long int> &pf, long long int now,
                    vector<long long int> &comb) {
  if (now == pf.size()) {
    long long int tmp = 1;
    rep(i, pf.size()) {
      if (pf[i] == comb[i]) {
        tmp *= pf[i] + 1;
      }
    }
    return tmp;
  }
  long long int sum = 0;
  rep(i, pf[now] + 1) {
    comb.push_back(i);
    sum += solve(pf, now + 1, comb);
    comb.pop_back();
  }
  return sum;
}

main() {
  rep(i, MAX) p[i] = true;
  p[0] = p[1] = false;
  rep(i, sqrt(MAX)) {
    if (!p[i])
      continue;
    for (long long int j = 2; j * i < MAX; j++) {
      p[i * j] = false;
    }
  }

  long long int l;
  while (cin >> l) {
    if (l == 0)
      break;
    vector<long long int> pf = primeFactor(l), comb;
    cout << (solve(pf, 0, comb) + 1) / 2 << endl;
  }
}

Error: TLE

Fixed submission:

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

void integerFactorization(int n, vector<int> &base, vector<int> &exp) {
  base.clear();
  exp.clear();
  long long a = 2;
  while (a * a <= n) {
    int b = 0;
    while (n % a == 0) {
      ++b;
      n /= a;
    }
    if (b > 0) {
      base.push_back(a);
      exp.push_back(b);
    }
    ++a;
  }
  if (n > 1) {
    base.push_back(n);
    exp.push_back(1);
  }
}

int solve(int n) {
  vector<int> base, exp;
  integerFactorization(n, base, exp);
  int m = exp.size();

  int ret = 1;
  for (int i = 0; i < m; ++i)
    ret *= 2 * exp[i] + 1;
  ++ret;
  ret /= 2;
  return ret;
}

int main() {
  solve(INT_MAX);

  for (;;) {
    int n;
    cin >> n;
    if (n == 0)
      return 0;
    cout << solve(n) << endl;
  }
}
Problem p00647 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;
#pragma warning(disable : 4996)
int n, l[2], d[2], m[2], a, b, c;
int main() {
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < 2; i++) {
      l[i] = 0;
      d[i] = 0;
      m[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      scanf("%02d:%02d %02d", &a, &b, &c);
      if (b > c)
        c += 60;
      if (a >= 11 && a < 15) {
        l[1]++;
        if (c - b <= 8)
          l[0]++;
      }
      if (a >= 18 && a < 21) {
        d[1]++;
        if (c - b <= 8)
          d[0]++;
      }
      if (a >= 21 || a < 2) {
        m[1]++;
        if (c - b <= 8)
          m[0]++;
      }
    }
    cout << "lunch ";
    if (l[1] == 0)
      cout << "no guest" << endl;
    else {
      cout << l[0] * 100 / l[1] << endl;
    }
    cout << "dinner ";
    if (d[1] == 0)
      cout << "no guest" << endl;
    else {
      cout << d[0] * 100 / d[1] << endl;
    }
    cout << "midnight ";
    if (m[1] == 0)
      cout << "no guest" << endl;
    else {
      cout << m[0] * 100 / m[1] << endl;
    }
  }
  return 0;
}

Error: -8

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int n, x[3], y[3];
int a, b, d;
char c;
int main() {
  while (true) {
    x[0] = 0;
    x[1] = 0;
    x[2] = 0;
    y[0] = 0;
    y[1] = 0;
    y[2] = 0;
    cin >> n;
    if (!n) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a >> c >> b;
      cin >> d;
      if (abs(b - d) <= 8 || abs(b - d) >= 52) {
        if (a >= 11 && a < 14) {
          x[0]++;
        } else if (a >= 18 && a < 21) {
          x[1]++;
        } else if (a >= 21 || a < 2) {
          x[2]++;
        }
      }
      if (a >= 11 && a < 14) {
        y[0]++;
      } else if (a >= 18 && a < 21) {
        y[1]++;
      } else if (a >= 21 || a < 2) {
        y[2]++;
      }
    }
    cout << "lunch " << 100 * x[0] / y[0] << endl;
    cout << "dinner " << 100 * x[1] / y[1] << endl;
    cout << "midnight " << 100 * x[2] / y[2] << endl;
  }
}
Problem p00647 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;
int n, c[5], l[5], i, a1, a2, a3;
int wang(int x, int y, int z) {
  int s = 0;
  if (x >= 11 && x < 15)
    s = 1;
  if (x >= 18 && x < 21)
    s = 2;
  if (x >= 21 || x < 2)
    s = 3;
  if (s != 0) {
    l[s]++;
    if ((z + 60 - y <= 8) || (z - y <= 8 && z - y > 0))
      c[s]++;
  }
  return 0;
}
int main() {
  scanf("%d", &n);
  while (n != 0) {
    for (i = 1; i <= 3; i++) {
      l[i] = 0;
      c[i] = 0;
    }
    for (i = 1; i <= n; i++) {
      scanf("%d:%d %d", &a1, &a2, &a3);
      wang(a1, a2, a3);
    }
    printf("lunch ");
    if (l[1] == 0)
      printf("no guest\\n");
    else
      printf("%d\\n", int(c[1] * 100 / l[1]));
    printf("dinner ");
    if (l[2] == 0)
      printf("no guest\\n");
    else
      printf("%d\\n", int(c[2] * 100 / l[2]));
    printf("midnight ");
    if (l[3] == 0)
      printf("no guest\\n");
    else
      printf("%d\\n", int(c[3] * 100 / l[3]));
    scanf("%d", &n);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>
#define eps 1e-8

int main() {
  int n;
  while (scanf("%d", &n), n) {
    double lunch, dinner, midnight;
    int a, b, c;
    int h, m, value;
    lunch = dinner = midnight = 0;
    a = b = c = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d%:%d %d", &h, &m, &value);
      if (h >= 11 && h <= 14) {
        ++a;
        if (value >= m && value - m <= 8)
          ++lunch;
        else if (value + 60 - m <= 8)
          ++lunch;
        else if (m + 60 - value <= 8)
          ++lunch;
      } else if (h >= 18 && h <= 20) {
        ++b;
        if (value >= m && value - m <= 8)
          ++dinner;
        else if (value + 60 - m <= 8)
          ++dinner;
        else if (m + 60 - value <= 8)
          ++dinner;
      } else if ((h >= 21 && h < 24) || h == 0 || h == 1) {
        ++c;
        if (value >= m && value - m <= 8)
          ++midnight;
        else if (value + 60 - m <= 8)
          ++midnight;
        else if (m + 60 - value <= 8)
          ++midnight;
      }
    }
    if (a == 0)
      printf("lunch no guest\\n");
    else
      printf("lunch %d\\n", (int)(lunch / a * 100));
    if (b == 0)
      printf("dinner no guest\\n");
    else
      printf("dinner %d\\n", (int)(dinner / b * 100));
    if (c == 0)
      printf("midnight no guest\\n");
    else
      printf("midnight %d\\n", (int)(midnight / c * 100));
  }
  return 0;
}
Problem p00650 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n, m;
int x[100], y[100], c[100];
bool use[100];
int par[100], rank[100];

int find(int a) {
  if (par[a] == a)
    return a;
  else
    return par[a] = find(par[a]);
}

bool union2(void) {
  int i;
  int a, b, cnt;

  for (i = 0; i < n; i++) {
    par[i] = i;
    rank[i] = 0;
  }

  cnt = n;
  for (i = 0; i < m; i++) {
    if (!use[i]) {
      a = find(x[i]);
      b = find(y[i]);
      if (a != b) {
        cnt--;
        if (rank[a] < rank[b]) {
          par[a] = b;
        } else {
          par[b] = a;
          if (rank[a] == rank[b])
            rank[a]++;
        }
      }
    }
  }

  if (cnt >= 2)
    return true;
  return false;
}

int main() {
  int cost, ans;
  int i, j;

  while (1) {
    cin >> n >> m;
    if (!n && !m)
      break;

    cost = 0;
    for (i = 0; i < m; i++) {
      cin >> x[i] >> y[i] >> c[i];
      use[i] = false;
      if (c[i] <= 0) {
        use[i] = true;
        cost += c[i];
      }
    }

    if (union2())
      ans = 0;
    else
      ans = 2147483647;

    for (i = 0; i < m; i++) {
      if (!use[i]) {
        use[i] = true;
        if (union2())
          ans = min(ans, c[i]);

        for (j = i + 1; j < m; j++) {
          if (!use[j]) {
            use[j] = true;
            if (union2())
              ans = min(ans, c[i] + c[j]);
            use[j] = false;
          }
        }
        use[i] = false;
      }
    }

    cout << ans + cost << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int n, m;
int x[100], y[100], c[100];
bool use[100];

bool union_find(void) {
  int i, j;
  int tmp, tmp2;
  int g[100];
  for (i = 0; i < n; i++)
    g[i] = i;

  for (i = 0; i < m; i++) {
    if (g[x[i]] != g[y[i]] && !use[i]) {
      tmp = g[x[i]];
      for (j = 0; j < n; j++) {
        if (g[j] == tmp)
          g[j] = g[y[i]];
      }
    }
  }

  tmp = g[0];
  tmp2 = -1;
  for (i = 1; i < n; i++) {
    if (tmp != g[i]) {
      if (tmp2 < 0)
        tmp2 = g[i];
      else if (tmp2 != g[i])
        return false;
    }
  }
  if (tmp2 < 0)
    return false;
  return true;
}

int main() {
  int cost;
  int i, j;

  while (1) {
    cin >> n >> m;
    if (!n && !m)
      break;

    for (i = 0; i < m; i++) {
      cin >> x[i] >> y[i] >> c[i];
      use[m] = false;
    }

    if (union_find()) {
      cost = 0;
      cout << "no reduce" << endl;
    } else
      cost = 2147483647;

    for (i = 0; i < m; i++) {
      for (j = 0; j < m; j++) {
        use[i] = true;
        use[j] = true;

        if (union_find()) {
          if (i == j) {
            if (cost > c[i])
              cost = c[i];
          } else {
            if (cost > c[i] + c[j])
              cost = c[i] + c[j];
          }
        }

        use[i] = false;
        use[j] = false;
      }
    }

    cout << cost << endl;
  }
}
Problem p00650 (C++) — buggy submission, verdict: Runtime Error

#include <cassert>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

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

int main() {
  while (true) {
    long long n, m;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    assert(n >= m);
    long long sum = 0, mn = 1234567890123456789LL, mn1 = 1234567890321456789LL;
    vector<pair<long long, pair<int, long long>>> edge[n];
    rep(i, m) {
      long long x, y, c;
      cin >> x >> y >> c;
      if (c <= 0)
        sum += c;
      else {
        if (c <= mn) {
          mn1 = mn;
          mn = c;
        } else if (c < mn1) {
          mn1 = c;
        }
        edge[x].push_back(make_pair(y, make_pair(i, c)));
        edge[y].push_back(make_pair(x, make_pair(i, c)));
      }
    }
    long long res = mn + mn1;
    {
      bool can[111][111] = {};
      rep(i, n) {
        queue<long long> pos;
        pos.push(i);
        while (!pos.empty()) {
          long long now = pos.front();
          pos.pop();
          if (can[i][now])
            continue;
          can[i][now] = true;
          rep(j, edge[now].size()) { pos.push(edge[now][j].first); }
        }
      }
      rep(i, n) rep(j, n) if (!can[i][j] && !can[j][i]) {
        cout << sum << endl;
        goto next;
      }
    }
    rep(iii, n) rep(jjj, edge[iii].size()) {
      bool can[111][111] = {};
      int num = edge[iii][jjj].second.first;
      rep(i, n) {
        queue<long long> pos;
        pos.push(i);
        while (!pos.empty()) {
          long long now = pos.front();
          pos.pop();
          if (can[i][now])
            continue;
          can[i][now] = true;
          rep(j, edge[now].size()) {
            if (edge[now][j].second.first == num)
              continue;
            pos.push(edge[now][j].first);
          }
        }
      }
      rep(i, n) rep(j, n) if (!can[i][j] && !can[j][i]) {
        res = min(res, edge[iii][jjj].second.second);
      }
    }
    cout << sum + res << endl;
  next:;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cassert>
#include <iostream>
#include <vector>

using namespace std;

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

int main() {
  while (true) {
    long long n, m;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    assert(n > m);
    long long sum = 0, mn = 1234567890123456789LL;
    rep(i, m) {
      long long x, y, c;
      cin >> x >> y >> c;
      if (c < 0)
        sum += c;
      mn = min(mn, c);
    }
    if (mn < 0) {
      cout << sum << endl;
      continue;
    }
    if (n != m + 1) {
      cout << 0 << endl;
      continue;
    }
    cout << mn << endl;
  }
  return 0;
}
Problem p00653 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int INF = pow(2, 31) - 1;
int n;
void powset(int size) {
  n = 1;
  while (n < size)
    n *= 2;
}

struct RMQ {
  vector<int> seg;
  void update(int i, int x) {
    i += n - 1;
    seg[i] = x;
    while (i > 0) {
      i = (i - 1) / 2;
      seg[i] = min(seg[i * 2 + 1], seg[i * 2 + 2]);
    }
  }
  int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return INF;
    if (a <= l && r <= b)
      return seg[k];
    int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  int query(int a, int b) { return query(a, b, 0, 0, n); }
  RMQ() { seg.assign(n * 2 - 1, INF); }
};

int main() {
  int R, C, Q;
  while (cin >> R >> C >> Q, R) {
    if (R < C) {
      powset(C);
      vector<RMQ> rmq(R, RMQ());
      for (int i = 0; i < R; i++) {
        for (int j = 0; j < C; j++) {
          int grid;
          cin >> grid;
          rmq[i].update(j, grid);
        }
      }
      while (Q--) {
        int r1, c1, r2, c2;
        cin >> r1 >> c1 >> r2 >> c2;
        int ret = INF;
        for (int i = r1; i <= r2; i++) {
          ret = min(ret, rmq[i].query(c1, c2 + 1));
        }
        cout << ret << endl;
      }
    } else {
      powset(R);
      vector<RMQ> rmq(C, RMQ());
      for (int i = 0; i < R; i++) {
        for (int j = 0; j < C; j++) {
          int grid;
          cin >> grid;
          rmq[j].update(i, grid);
        }
      }
      while (Q--) {
        int r1, c1, r2, c2;
        cin >> r1 >> c1 >> r2 >> c2;
        int ret = INF;
        for (int i = c1; i <= c2; i++) {
          ret = min(ret, rmq[i].query(r1, r2 + 1));
        }
        cout << ret << endl;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int INF = pow(2, 31) - 1;

struct RMQ {
  int n;
  vector<int> seg;
  void update(int i, int x) {
    i += n - 1;
    seg[i] = x;
    while (i > 0) {
      i = (i - 1) / 2;
      seg[i] = min(seg[i * 2 + 1], seg[i * 2 + 2]);
    }
  }
  int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return INF;
    if (a <= l && r <= b)
      return seg[k];
    int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  int query(int a, int b) { return query(a, b, 0, 0, n); }
  RMQ(int size) {
    n = 1;
    while (n < size)
      n *= 2;
    seg.assign(n * 2 - 1, INF);
  }
};

int main() {
  int R, C, Q;
  while (cin >> R >> C >> Q, R) {
    vector<RMQ> rmq(R, RMQ(C));
    for (int i = 0; i < R; i++) {
      for (int j = 0; j < C; j++) {
        int grid;
        cin >> grid;
        rmq[i].update(j, grid);
      }
    }
    while (Q--) {
      int r1, c1, r2, c2;
      cin >> r1 >> c1 >> r2 >> c2;
      int ret = INF;
      for (int i = r1; i <= r2; i++) {
        ret = min(ret, rmq[i].query(c1, c2 + 1));
      }
      cout << ret << endl;
    }
  }
}
Problem p00654 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  int N;
  while (cin >> N, N) {
    int S = N * (N + 1) / 2;
    vector<long long> v(S);
    for (int i = 0; i < S; ++i)
      cin >> v[i];
    long long G = -1;
    vector<long long> evens;
    long long oddmin = ~(1LL << 63);
    for (int i = 0; i < S; ++i) {
      if (v[i] % 2 == 0) {
        if (G == -1)
          G = v[i];
        else
          G = gcd(G, v[i]);
        evens.push_back(v[i]);
      } else {
        oddmin = min(oddmin, v[i]);
      }
    }
    sort(evens.begin(), evens.end());
    for (int i = 0; i < N; ++i)
      evens[i] /= G;
    long long coeff = oddmin / evens[0] / evens[1];
    long long sqcoeff = sqrt(coeff + 0.5);
    cout << G / sqcoeff << endl;
    for (int i = 0; i < N; ++i) {
      if (i)
        cout << ' ';
      cout << evens[i] * sqcoeff;
    }
    cout << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <map>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
long long gcd(long long x, long long y) {
  while (y != 0) {
    long long r = x;
    x = y;
    y = r % y;
  }
  return x;
}
std::map<unsigned long long, unsigned> prime_factorize(unsigned long long x) {
  std::map<unsigned long long, unsigned> ret;
  for (unsigned i = 2; 1ULL * i * i <= x; i++) {
    while (x % i == 0)
      x /= i, ret[i]++;
  }
  if (x != 1)
    ret[x]++;
  return ret;
}
std::vector<unsigned long long> calc_divisors(unsigned long long x) {
  std::map<unsigned long long, unsigned> res = prime_factorize(x);
  std::vector<unsigned long long> ret;
  ret.push_back(1);
  for (std::pair<unsigned long long, unsigned> w : res) {
    int s = ret.size();
    unsigned long long mul = 1;
    for (int i = 0; i < w.second; i++) {
      mul *= w.first;
      for (int j = 0; j < s; j++)
        ret.push_back(ret[j] * mul);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}
unsigned long long sqrt_int(unsigned long long x) {
  unsigned long long l = 0, r = 4294967296;
  while (r - l > 1) {
    long long m = (l + r) >> 1;
    if (m * m >= x)
      r = m;
    else
      l = m;
  }
  if (l * l < x)
    l++;
  return l;
}
int n;
int main() {
  while (scanf("%d", &n), n) {
    vector<long long> b(n * (n + 1) >> 1), e;
    long long t = 1LL << 60;
    for (int i = 0; i < n * (n + 1) >> 1; i++) {
      scanf("%lld", &b[i]);
      if ((b[i] & 1) == 0)
        e.push_back(b[i]);
      else
        t = min(t, b[i]);
    }
    sort(e.begin(), e.end());
    long long g = gcd(e[0], e[1]);
    for (int i = 2; i < n; i++)
      g = gcd(g, e[i]);
    for (int i = 0; i < n; i++)
      e[i] /= g;
    sort(b.begin(), b.end());
    assert(t >= e[0] * e[1]);
    long long x = sqrt_int(t / e[0] / e[1]);
    // printf("%lld\\n", g / x);
    for (int i = 0; i < n; i++) {
      printf(i ? " %lld" : "%lld", e[i] * x);
    }
    printf("\\n");
  }
  return 0;
}
Problem p00654 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
long long a[100000];
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }

int cmp(const long long &a, const long long &b) {
  if (a % 2 == 0 && b % 2 == 1)
    return 1;
  else if (a % 2 == 1 && b % 2 == 0)
    return 0;
  else
    return a < b;
}
int main() {
  int N, n;
  while (1) {
    long long x, y, z, tmp, r1, r2, d2, m, p, q, yh;
    scanf("%d", &n);
    if (n == 0)
      break;
    N = (n + 1) * n / 2;
    for (int i = 1; i <= N; i++)
      scanf("%lld", a + i);

    sort(a + 1, a + N + 1, cmp);
    x = a[n + 1];
    y = a[1];
    z = a[2];

    tmp = gcd(y, z);
    r1 = y / tmp;
    r2 = z / tmp;
    d2 = x / r1 / r2;

    p = 1;
    q = 2147483647;
    while (p <= q) {
      m = (p + q) >> 1;
      if (m * m == d2)
        break;
      else if (m * m < d2)
        p = m + 1;
      else
        q = m - 1;
    }
    tmp /= m;
    yh = tmp;

    p = 1;
    q = d2;
    while (p <= q) {
      m = (p + q) >> 1;
      if (m * m == d2)
        break;
      else if (m * m < d2)
        p = m + 1;
      else
        q = m - 1;
    }
    tmp /= m;

    printf("%lld\\n", (yh != 0) * yh);
    for (int i = 1; i <= n; i++) {
      if (i < n)
        printf("%lld ", a[i] / yh);
      else
        printf("%lld\\n", a[i] / yh);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#define maxlen 1000
using namespace std;
long long a[100000];
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

int main() {
  int N, n;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    long long N = (n + 1) * n / 2;
    for (int i = 1; i <= N; i++)
      scanf("%lld", a + i);

    sort(a + 1, a + N + 1);
    long long x = 0;
    long long y = 0, z = 0;
    int count = 0;

    for (int i = 1; i <= N; i++)
      if (a[i] & 1)
        if (x == 0)
          x = a[i];
        else
          ;
      else if (y == 0 && z == 0)
        y = a[i];
      else if (y != 0 && z == 0)
        z = a[i];

    long long tmp = gcd(y, z);
    long long r1 = y / tmp;
    long long r2 = z / tmp;
    long long d2 = x / r1 / r2;
    long long p = 1, q = d2;

    long long m = 1;
    while (p <= q) {
      m = (p + q) >> 1;
      if (m * m == d2)
        break;
      else if (m * m < d2)
        p = m + 1;
      else
        q = m - 1;
    }
    tmp = y / m / r1;

    printf("%lld\\n", tmp);
    count = 0;
    for (int i = 1; i <= N; i++)
      if (!(a[i] & 1)) {
        count++;
        if (count < n)
          printf("%lld ", a[i] / tmp);
        else
          printf("%lld\\n", a[i] / tmp);
      }
  }
  return 0;
}