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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
using ll = long long;

ll find(ll x, vector<ll> &par) {
  if (par.at(x) == x) {
    return x;
  } else {
    return par.at(x) = find(par.at(x), par);
  }
}

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(M), B(M);

  vector<ll> par(N), rank(N), size(N);
  for (ll i = 0; i < N; i++) {
    par.at(i) = i;
    rank.at(i) = 0;
    size.at(i) = 1;
  }

  for (ll i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
    ll x = find(A.at(i), par);
    ll y = find(B.at(i), par);
    if (x != y) {
      if (rank.at(x) < rank.at(y)) {
        par.at(x) = par.at(y);
        size.at(x) += size.at(y);
        size.at(y) = size.at(x);
      } else {
        par.at(y) = par.at(x);
        if (rank.at(x) == rank.at(y))
          rank.at(x)++;
        size.at(x) += size.at(y);
        size.at(y) = size.at(x);
      }
    }
  }
  ll maxsize = 0;
  for (ll i = 0; i < N; i++) {
    ll x = find(i, par);
    ll a = size.at(x);
    if (a > maxsize)
      maxsize = a;
  }
  cout << maxsize;
}

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

ll find(ll x, vector<ll> &par) {
  if (par.at(x) == x) {
    return x;
  } else {
    return par.at(x) = find(par.at(x), par);
  }
}

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(M), B(M);

  vector<ll> par(N), rank(N), size(N);
  for (ll i = 0; i < N; i++) {
    par.at(i) = i;
    rank.at(i) = 0;
    size.at(i) = 1;
  }

  for (ll i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
    ll x = find(A.at(i) - 1, par);
    ll y = find(B.at(i) - 1, par);
    if (x != y) {
      if (rank.at(x) < rank.at(y)) {
        par.at(x) = par.at(y);
        size.at(x) += size.at(y);
        size.at(y) = size.at(x);
      } else {
        par.at(y) = par.at(x);
        if (rank.at(x) == rank.at(y))
          rank.at(x)++;
        size.at(x) += size.at(y);
        size.at(y) = size.at(x);
      }
    }
  }
  ll maxsize = 0;
  for (ll i = 0; i < N; i++) {
    ll x = find(i, par);
    ll a = size.at(x);
    if (a > maxsize)
      maxsize = a;
  }
  cout << maxsize;
}
Problem p02573 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
const int maN = 1e5;
int parent[maN];
int sz[maN];
void make_set(int v) { parent[v] = v; }
int find_set(int v) {
  if (v == parent[v])
    return v;
  return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
  int u = find_set(a);
  int v = find_set(b);
  if (u != v) {
    if (sz[u] < sz[v]) {
      // swap(u, v);
      parent[u] = v;
      sz[v] += sz[u];
    } else {
      parent[v] = u;
      sz[u] += sz[v];
    }
  }
}

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

  for (int i = 0; i <= n; ++i) {
    parent[i] = i;
    sz[i] = 1;
  }
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    union_sets(a, b);
  }
  int max_set = 1;
  for (int i = 0; i < n; ++i) {
    // cout << sz[i] << " ";
    if (max_set < sz[i])
      max_set = sz[i];
  }

  cout << max_set;

  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
const int maN = 2e5 + 5;
int parent[maN];
int sz[maN];
void make_set(int v) { parent[v] = v; }
int find_set(int v) {
  if (v == parent[v])
    return v;
  return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
  int u = find_set(a);
  int v = find_set(b);
  if (u != v) {
    if (sz[u] < sz[v]) {
      // swap(u, v);
      parent[u] = v;
      sz[v] += sz[u];
    } else {
      parent[v] = u;
      sz[u] += sz[v];
    }
  }
}

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

  for (int i = 0; i <= n; ++i) {
    parent[i] = i;
    sz[i] = 1;
  }
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    union_sets(a, b);
  }
  int max_set = 1;
  for (int i = 0; i < n; ++i) {
    // cout << sz[i] << " ";
    if (max_set < sz[i])
      max_set = sz[i];
  }

  cout << max_set;

  return 0;
}
Problem p02573 (C++)

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

int bfs(int s, vector<vector<int>> &adj, vector<int> visited) {

  queue<int> q;
  q.push(s);

  visited[s] = 1;

  int size = 1;

  while (!q.empty()) {

    int t = q.front();
    q.pop();

    for (auto x : adj[t]) {
      if (visited[x] == 0) {
        q.push(x);
        visited[x] = 1;
        size++;
      }
    }
  }

  return size;
}

void solve() {

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

  vector<vector<int>> adj(n + 1);

  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    // cout<<l<<r ;

    adj[l].push_back(r);
    adj[r].push_back(l);
  }

  vector<int> visited(n + 1);

  int res = 0;

  for (int i = 1; i <= n; i++) {

    if (visited[i] == 0) {
      int answer = bfs(i, adj, visited);
      res = max(res, answer);
    }
  }

  cout << res;
}
int main() {

  int y;

  y = 1;
  // cin>>y ;

  while (y--) {
    solve();
  }
}

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

int bfs(int s, vector<vector<int>> &adj, vector<int> &visited) {

  queue<int> q;
  q.push(s);

  visited[s] = 1;

  int size = 1;

  while (!q.empty()) {

    int t = q.front();
    q.pop();

    for (auto x : adj[t]) {
      if (visited[x] == 0) {
        q.push(x);
        visited[x] = 1;
        size++;
      }
    }
  }

  return size;
}

void solve() {

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

  vector<vector<int>> adj(n + 1);

  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    // cout<<l<<r ;

    adj[l].push_back(r);
    adj[r].push_back(l);
  }

  vector<int> visited(n + 1);

  int res = 0;

  for (int i = 1; i <= n; i++) {

    if (visited[i] == 0) {
      int answer = bfs(i, adj, visited);
      res = max(res, answer);
    }
  }

  cout << res;
}
int main() {

  int y;

  y = 1;
  // cin>>y ;

  while (y--) {
    solve();
  }
}
Problem p02573 (C++)

Buggy submission (status: Runtime Error):

/*
ID: Bipin Singh [bipinsingh061]
LANG: C++
TASK: gift1
*/
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << "\n" << (#x) << " = " << (x) << "\n"
#define int long long int

void inputoutput() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

void dfs(int src, bool *vis, vector<int> v[], int &ans) {
  vis[src] = true;
  // cout<<src<<" ";
  ++ans;

  for (auto it : v[src]) {
    if (!vis[it])
      dfs(it, vis, v, ans);
  }
}

int mod = 1e9 + 7;

void update(vector<int> &D, int l, int r, int x) {
  D[l] += x;
  D[r + 1] -= x;
}

int32_t main() {
  inputoutput();

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

  vector<int> v[200000];
  bool vis[200000];

  memset(vis, false, sizeof(vis));

  for (int i = 1; i <= m; ++i) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }

  // for(int i=1 ; i<=n ; ++i)
  // {
  // 	cout<<i<<"->";
  // 	for(auto it : v[i])
  // 		cout<<it<<" ";
  // 	cout<<"\n";
  // }
  int comp = 0;

  // unordered_set<int> result;

  int sol = INT_MIN;

  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      int ans = 0;
      dfs(i, vis, v, ans);
      sol = max(sol, ans);
      ++comp;
    }
  }

  cout << sol;

  return 0;
}


Fixed submission:

/*
ID: Bipin Singh [bipinsingh061]
LANG: C++
TASK: gift1
*/
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << "\n" << (#x) << " = " << (x) << "\n"
#define int long long int

void inputoutput() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

void dfs(int src, bool *vis, vector<int> v[], int &ans) {
  vis[src] = true;
  // cout<<src<<" ";
  ++ans;

  for (auto it : v[src]) {
    if (!vis[it])
      dfs(it, vis, v, ans);
  }
}

int mod = 1e9 + 7;

void update(vector<int> &D, int l, int r, int x) {
  D[l] += x;
  D[r + 1] -= x;
}

int32_t main() {
  inputoutput();

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

  vector<int> v[200500];
  bool vis[200500];

  memset(vis, false, sizeof(vis));

  for (int i = 1; i <= m; ++i) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }

  // for(int i=1 ; i<=n ; ++i)
  // {
  // 	cout<<i<<"->";
  // 	for(auto it : v[i])
  // 		cout<<it<<" ";
  // 	cout<<"\n";
  // }
  int comp = 0;

  // unordered_set<int> result;

  int sol = INT_MIN;

  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      int ans = 0;
      dfs(i, vis, v, ans);
      sol = max(sol, ans);
      ++comp;
    }
  }

  cout << sol;

  return 0;
}
Problem p02573 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <vector>

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

class UnionFind {
public:
  UnionFind(int &n) { r = vector<int>(n + 1, -1); }

  int findRoot(int x) {
    if (r[x] < 0)
      return x;
    else
      r[x] = findRoot(r[x]);
  }

  void unite(int &x, int &y) {
    x = findRoot(x);
    y = findRoot(y);
    if (x == y)
      return;
    if (r[x] > r[y])
      swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return;
  }

  int size(int &x) { return -r[findRoot(x)]; }

private:
  vector<int> r;
};

int main() {
  int n, m, a, b;
  cin >> n >> m;

  UnionFind uf(n);
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    uf.unite(a, b);
  }

  int ans = 0;
  for (int i = 1; i <= n; ++i)
    ans = max(ans, uf.size(i));
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <vector>

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

class UnionFind {
public:
  UnionFind(int &n) { r = vector<int>(n + 1, -1); }

  int findRoot(int x) {
    if (r[x] < 0)
      return x;
    return findRoot(r[x]);
  }

  void unite(int &x, int &y) {
    x = findRoot(x);
    y = findRoot(y);
    if (x == y)
      return;
    if (r[x] > r[y])
      swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return;
  }

  int size(int &x) { return -r[findRoot(x)]; }

private:
  vector<int> r;
};

int main() {
  int n, m, a, b;
  cin >> n >> m;

  UnionFind uf(n);
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    uf.unite(a, b);
  }

  int ans = 0;
  for (int i = 1; i <= n; ++i)
    ans = max(ans, uf.size(i));
  cout << ans << endl;
  return 0;
}
Problem p02573 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(), x.end()
#define MOD (1000000000 + 7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x, y) make_pair(x, y)
int N, M;
int v[200400];
int vs[203000] = {0};

int root(int i) {
  if (v[i] == i) {
    return i;
  } else {
    return root(v[i]);
  }
}

int margego(int tibi, int deka) {
  int rtibi = root(tibi), rdeka = root(deka);
  if (rtibi == rdeka) {
    return 0;
  } else {
    if (vs[rtibi] > vs[rdeka])
      swap(rtibi, rdeka);
    vs[rtibi] = vs[rdeka] + vs[rtibi];
    v[rdeka] = rtibi;
  }
  return 0;
}

int main() {

  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    v[i] = i;
    vs[i] = 1;
  }

  for (int i = 0; i < M; i++) {
    int tmp, tmp1;
    cin >> tmp >> tmp1;
    margego(tmp - 1, tmp1 - 1);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, vs[i]);
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(), x.end()
#define MOD (1000000000 + 7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x, y) make_pair(x, y)
int N, M;
int v[200400];
int vs[203000] = {0};

int root(int i) {
  if (v[i] == i) {
    return i;
  } else {
    return root(v[i]);
  }
}

int margego(int tibi, int deka) {
  int rtibi = root(tibi), rdeka = root(deka);
  if (rtibi == rdeka) {
    return 0;
  } else {
    if (vs[rtibi] < vs[rdeka])
      swap(rtibi, rdeka);
    vs[rtibi] = vs[rdeka] + vs[rtibi];
    v[rdeka] = rtibi;
  }
  return 0;
}

int main() {

  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    v[i] = i;
    vs[i] = 1;
  }

  for (int i = 0; i < M; i++) {
    int tmp, tmp1;
    cin >> tmp >> tmp1;
    margego(tmp - 1, tmp1 - 1);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, vs[i]);
  }

  cout << ans << endl;
}
Problem p02573 (C++)

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

using namespace std;

class Group {
public:
  vector<int> root;
  int maxSize = -1;

  Group(int n) { root = vector<int>(n, -1); }

  int getRoot(int c) { return root[c] < 0 == c ? c : getRoot(root[c]); }

  void merge(int a, int b) {
    int rootA = getRoot(a);
    int rootB = getRoot(b);
    if (rootA != rootB) {
      root[rootA] += root[rootB];
      root[rootB] = rootA;
      maxSize = root[rootA] < maxSize ? root[rootA] : maxSize;
    }
  }

  int getMax() { return -maxSize; }
};

int main() {
  int n, m;
  cin >> n >> m;
  Group group(n);

  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    group.merge(--a, --b);
  }

  cout << group.getMax();
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>

using namespace std;

class Group {
public:
  vector<int> root;
  int maxSize = -1;

  Group(int n) { root = vector<int>(n, -1); }

  int getRoot(int c) { return root[c] < 0 ? c : root[c] = getRoot(root[c]); }

  void merge(int a, int b) {
    int rootA = getRoot(a);
    int rootB = getRoot(b);
    if (rootA != rootB) {
      root[rootA] += root[rootB];
      root[rootB] = rootA;
      maxSize = root[rootA] < maxSize ? root[rootA] : maxSize;
    }
  }

  int getMax() { return -maxSize; }
};

int main() {
  int n, m;
  cin >> n >> m;
  Group group(n);

  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    group.merge(--a, --b);
  }

  cout << group.getMax();
  return 0;
}
Problem p02573 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
bool t[100];
vector<int> e[100];
int dfs(int v) {
  int y = 1;
  t[v] = true;
  for (int i = 0; i < e[v].size(); i++) {
    int u = e[v][i];
    if (!t[u]) {
      y += dfs(u);
    }
  }
  return y;
}
int main() {
  int n;
  int m;
  cin >> n;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a;
    int b;
    cin >> a;
    cin >> b;
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!t[i]) {
      int x = dfs(i);
      ans = max(ans, x);
    }
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
bool t[200010];
vector<int> e[200010];
int dfs(int v) {
  int y = 1;
  t[v] = true;
  for (int i = 0; i < e[v].size(); i++) {
    int u = e[v][i];
    if (!t[u]) {
      y += dfs(u);
    }
  }
  return y;
}
int main() {
  int n;
  int m;
  cin >> n;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a;
    int b;
    cin >> a;
    cin >> b;
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!t[i]) {
      int x = dfs(i);
      ans = max(ans, x);
    }
  }
  cout << ans;
  return 0;
}
Problem p02574 (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;
typedef long long ll;
typedef pair<int, int> P;

std::vector<int> Eratosthenes(const int N) {
  std::vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  std::vector<int> P;
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  bool ok1 = true, ok2 = true;
  // 2
  int g = __gcd(a[0], a[1]);
  rep(i, n) g = __gcd(g, a[i]);
  if (g != 1)
    ok2 = false;
  // 1
  set<int> se;
  vector<int> e = Eratosthenes(1000005);
  rep(i, n) {
    set<int> cnt;
    rep(j, e.size()) {
      while (a[i] % e[j] == 0) {
        a[i] /= e[j];
        cnt.insert(e[j]);
      }
    }
    if (a[i] != 1)
      cnt.insert(a[i]);
    for (auto &p : cnt) {
      if (se.find(p) != se.end())
        ok1 = false;
      se.insert(p);
    }
  }
  if (ok1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  if (ok2) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
}

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

std::vector<int> Eratosthenes(const int N) {
  std::vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  std::vector<int> P;
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  bool ok1 = true, ok2 = true;
  // 2
  int g = __gcd(a[0], a[1]);
  rep(i, n) g = __gcd(g, a[i]);
  if (g != 1)
    ok2 = false;
  // 1
  set<int> se;
  vector<int> e = Eratosthenes(1000005);
  rep(i, n) {
    set<int> cnt;
    rep(j, e.size()) {
      if ((ll)e[j] * e[j] > a[i])
        break;
      while (a[i] % e[j] == 0) {
        a[i] /= e[j];
        cnt.insert(e[j]);
      }
    }
    if (a[i] != 1)
      cnt.insert(a[i]);
    for (auto &p : cnt) {
      if (se.find(p) != se.end())
        ok1 = false;
      se.insert(p);
    }
  }
  if (ok1) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  if (ok2) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
/// You just can't beat the person who never gives up
/// ICPC next year

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;

int n, a[N];
int spf[N], vis[N], vid;
bool is[N];
void sieve() {
  for (int i = 1; i < N; ++i)
    spf[i] = i;
  for (int i = 2; i * i < N; ++i)
    if (spf[i] == i) {
      for (int j = i * i; j < N; j += i)
        if (spf[j] == j)
          spf[j] = i;
    }
}
vector<int> factorize(int x) {
  vector<int> ret;
  ++vid;
  while (x != 1) {
    if (vis[spf[x]] != vid)
      ret.push_back(spf[x]);
    vis[spf[x]] = vid;
    x /= spf[x];
  }
  return ret;
}
int x;
bool Never_give_up() {
  sieve();
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    x = __gcd(x, a[i]);
  }
  if (x != 1)
    return cout << "not coprime\n", 0;
  for (int i = n - 1; i >= 0; --i) {
    auto vec = factorize(a[i]);
    for (int j : vec)
      if (is[j])
        return cout << "setwise coprime\n", 0;
    for (int j : vec)
      is[j] = 1;
  }
  cout << "pairwise coprime\n";
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // std::ios::sync_with_stdio(0);
  // cin.tie(0) ,cout.tie(0);
  int t = 1;
  // scanf("%d",&t);
  while (t--) {
    Never_give_up();
  }
  return 0;
}


Fixed submission:
/// You just can't beat the person who never gives up
/// ICPC next year

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;

int n, a[N];
int spf[N], vis[N], vid;
bool is[N];
void sieve() {
  for (int i = 1; i < N; ++i)
    spf[i] = i;
  for (int i = 2; i * i < N; ++i)
    if (spf[i] == i) {
      for (int j = i * i; j < N; j += i)
        if (spf[j] == j)
          spf[j] = i;
    }
}
vector<int> factorize(int x) {
  vector<int> ret;
  ++vid;
  while (x != 1) {
    if (vis[spf[x]] != vid)
      ret.push_back(spf[x]);
    vis[spf[x]] = vid;
    x /= spf[x];
  }
  return ret;
}
int x;
bool Never_give_up() {
  sieve();
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    x = __gcd(x, a[i]);
  }
  if (x != 1)
    return cout << "not coprime\n", 0;
  for (int i = n - 1; i >= 0; --i) {
    auto vec = factorize(a[i]);
    for (int j : vec)
      if (is[j])
        return cout << "setwise coprime\n", 0;
    for (int j : vec)
      is[j] = 1;
  }
  cout << "pairwise coprime\n";
  return 0;
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // std::ios::sync_with_stdio(0);
  // cin.tie(0) ,cout.tie(0);
  int t = 1;
  // scanf("%d",&t);
  while (t--) {
    Never_give_up();
  }
  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
// FILE *fi = freopen("1.txt", "r", stdin);
// FILE *fo = freopen("1", "w", stdout);
// FILE *fi = freopen("P.inp", "r", stdin);
// FILE *fo = freopen("P.out", "w", stdout);
bool used[1000001];
void bfs(int x) {
  queue<int> q;
  if (used[x])
    return;
  q.push(x);
  used[x] = true;
  while (q.size()) {
    int u = q.front();
    q.pop();
    used[u] = true;
    u += x;
    if (!used[u] && u <= 1e6)
      q.push(u);
  }
  return;
}
int a[1000001];
int Min[1000001];
int main() {
  //------------------------------
  // Faster
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //------------------------------
  int N = 1e6;
  for (int i = 1; i <= N; i++)
    Min[i] = i;
  for (int i = 2; i <= sqrt(N); i++) {
    for (int j = i; j <= N; j += i) {
      Min[j] = min(Min[j], i);
    }
  }
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  bool ok = false;
  int G = 0;
  for (int i = n; i >= 1; i--) {
    G = __gcd(G, a[i]);
    if (a[i] == 1)
      continue;
    vector<int> U;
    while (a[i] > 1) {
      int x = Min[a[i]];
      if (used[x]) {
        ok = true;
      }
      U.push_back(x);
      a[i] /= x;
    }
    for (auto x : U)
      bfs(x);
  }
  if (ok == false) {
    cout << "pairwise coprime";
  } else if (ok == true && G == 1) {
    cout << "setwise coprime";
  } else {
    cout << "not coprime";
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
// FILE *fi = freopen("1.txt", "r", stdin);
// FILE *fo = freopen("1", "w", stdout);
// FILE *fi = freopen("P.inp", "r", stdin);
// FILE *fo = freopen("P.out", "w", stdout);
bool used[1000001];
void bfs(int x) {
  queue<int> q;
  if (used[x])
    return;
  q.push(x);
  used[x] = true;
  while (q.size()) {
    int u = q.front();
    q.pop();
    used[u] = true;
    u += x;
    if (u <= 1e6 && !used[u])
      q.push(u);
  }
  return;
}
int a[1000001];
int Min[1000001];
int main() {
  //------------------------------
  // Faster
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //------------------------------
  int N = 1e6;
  for (int i = 1; i <= N; i++)
    Min[i] = i;
  for (int i = 2; i <= sqrt(N); i++) {
    for (int j = i; j <= N; j += i) {
      Min[j] = min(Min[j], i);
    }
  }
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  bool ok = false;
  int G = 0;
  for (int i = n; i >= 1; i--) {
    G = __gcd(G, a[i]);
    if (a[i] == 1)
      continue;
    vector<int> U;
    while (a[i] > 1) {
      int x = Min[a[i]];
      if (used[x]) {
        ok = true;
      }
      U.push_back(x);
      a[i] /= x;
    }
    for (auto x : U)
      bfs(x);
  }
  if (ok == false) {
    cout << "pairwise coprime";
  } else if (ok == true && G == 1) {
    cout << "setwise coprime";
  } else {
    cout << "not coprime";
  }
  return 0;
}
Problem p02574 (C++)

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

using namespace std;
const int N = 1e6 + 9;

vector<int> prime;
bool flag[N];

void seive() {
  for (int i = 4; i < N; i += 2)
    flag[i] = true;
  for (int i = 3; i * i < N; i += 2) {
    if (!flag[i]) {
      for (int j = i * 3; j < N; j += i * 2)
        flag[j] = true;
    }
  }
  prime.push_back(2);
  for (int i = 3; i <= N; i += 2) {
    if (!flag[i])
      prime.push_back(i);
  }
}

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

  int n;
  cin >> n;

  int a[n];
  for (int &i : a)
    cin >> i;
  seive();
  // for(int i=0;i<20;i++)cout<<prime[i]<<" ";
  // cout<<endl;
  map<int, int> cnt;

  for (int i : a) {
    int temp = i;

    for (int x : prime) {
      if (x * x > temp)
        break;
      if (temp % x == 0) {
        cnt[x]++;
        while (temp % x == 0)
          temp /= x;
      }
    }
    if (temp > 1)
      cnt[temp]++;
  }
  bool flag = true;

  for (auto [x, y] : cnt) {
    if (y > 1) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int g = a[0];
  for (int i = 1; i < n; i++)
    g = __gcd(g, a[i]);
  if (g == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}


Fixed submission:
#include "bits/stdc++.h"

using namespace std;
const int N = 1e6 + 9;

vector<int> prime;
bool flag[N + 100];

void seive() {
  for (int i = 4; i < N; i += 2)
    flag[i] = true;
  for (int i = 3; i * i < N; i += 2) {
    if (!flag[i]) {
      for (int j = i * 3; j < N; j += i * 2)
        flag[j] = true;
    }
  }
  prime.push_back(2);
  for (int i = 3; i <= N; i += 2) {
    if (!flag[i])
      prime.push_back(i);
  }
}

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

  int n;
  cin >> n;

  int a[n];
  for (int &i : a)
    cin >> i;
  seive();
  // for(int i=0;i<20;i++)cout<<prime[i]<<" ";
  // cout<<endl;
  map<int, int> cnt;

  for (int i : a) {
    int temp = i;

    for (int x : prime) {
      if (x * x > temp)
        break;
      if (temp % x == 0) {
        cnt[x]++;
        while (temp % x == 0)
          temp /= x;
      }
    }
    if (temp > 1)
      cnt[temp]++;
  }
  bool flag = true;

  for (auto [x, y] : cnt) {
    if (y > 1) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int g = a[0];
  for (int i = 1; i < n; i++)
    g = __gcd(g, a[i]);
  if (g == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
}
Problem p02574 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<int> primes(int x) {
  vector<int> ret;
  for (int i = 2; i * i <= x; i++) {
    if (x % i)
      continue;
    while (x % i == 0)
      x /= i;
    ret.push_back(i);
  }
  if (x != 1)
    ret.push_back(x);
  return ret;
}
signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int, int> primes_cnt;
  for (auto &x : A) {
    cin >> x;
    for (auto e : primes(x)) {
      primes_cnt[e]++;
    }
  }

  int ma = 0;
  for (auto p : primes_cnt) {
    ma = max(ma, p.second);
  }

  if (ma == N) {
    cout << "not coprime\n";
  } else if (ma > 1) {
    cout << "setwise coprime\n";
  } else {
    cout << "pairwise coprime\n";
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<int> primes(int x) {
  vector<int> ret;
  if (x % 2 == 0) {
    ret.push_back(2);
    while (x % 2 == 0)
      x /= 2;
  }
  for (int i = 3; i * i <= x; i += 2) {
    if (x % i)
      continue;
    while (x % i == 0)
      x /= i;
    ret.push_back(i);
  }
  if (x != 1)
    ret.push_back(x);
  return ret;
}
signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int, int> primes_cnt;
  for (auto &x : A) {
    cin >> x;
    for (auto e : primes(x)) {
      primes_cnt[e]++;
    }
  }

  int ma = 0;
  for (auto p : primes_cnt) {
    ma = max(ma, p.second);
  }

  if (ma == N) {
    cout << "not coprime\n";
  } else if (ma > 1) {
    cout << "setwise coprime\n";
  } else {
    cout << "pairwise coprime\n";
  }
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef pair<int, int> PII;
#define X first
#define Y second
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
const int maxN = 100000;
int n, a[maxN + 10], have[maxN + 10];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int isn[maxN + 10], prime[maxN + 10], len, GCD;
bool vis[maxN + 10];
void init() {
  for (int i = 2; i <= maxN; i++) {
    if (!vis[i])
      prime[++len] = i, isn[i] = i;
    for (int j = 1; j <= len; j++) {
      if (i * prime[j] > maxN)
        break;
      vis[i * prime[j]] = 1;
      isn[i * prime[j]] = prime[j];
      if (i % prime[j] == 0) {
        break;
      }
    }
  }
  //    for(int i=2;i<=100;i++)printf("%d %d\n",i,isn[i]);
}

int main() {
  init();
  n = read();
  a[1] = read();
  GCD = a[1];
  for (int i = 2; i <= n; i++)
    a[i] = read(), GCD = gcd(GCD, a[i]);
  if (GCD != 1)
    return puts("not coprime"), 0;
  for (int i = 1; i <= n; i++) {
    int tmp = a[i];
    while (tmp > 1) {
      int h = isn[tmp];
      have[isn[tmp]]++;
      if (have[isn[tmp]] > 1)
        return puts("setwise coprime"), 0;
      while (isn[tmp] == h)
        tmp /= isn[tmp];
    }
  }
  puts("pairwise coprime");
  return 0;
}
/*

*/


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef pair<int, int> PII;
#define X first
#define Y second
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
const int maxN = 1000000;
int n, a[maxN + 10], have[maxN + 10];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int isn[maxN + 10], prime[maxN + 10], len, GCD;
bool vis[maxN + 10];
void init() {
  for (int i = 2; i <= maxN; i++) {
    if (!vis[i])
      prime[++len] = i, isn[i] = i;
    for (int j = 1; j <= len; j++) {
      if (i * prime[j] > maxN)
        break;
      vis[i * prime[j]] = 1;
      isn[i * prime[j]] = prime[j];
      if (i % prime[j] == 0) {
        break;
      }
    }
  }
  //    for(int i=2;i<=100;i++)printf("%d %d\n",i,isn[i]);
}

int main() {
  init();
  n = read();
  a[1] = read();
  GCD = a[1];
  for (int i = 2; i <= n; i++)
    a[i] = read(), GCD = gcd(GCD, a[i]);
  if (GCD != 1)
    return puts("not coprime"), 0;
  for (int i = 1; i <= n; i++) {
    int tmp = a[i];
    while (tmp > 1) {
      int h = isn[tmp];
      have[isn[tmp]]++;
      if (have[isn[tmp]] > 1)
        return puts("setwise coprime"), 0;
      while (isn[tmp] == h)
        tmp /= isn[tmp];
    }
  }
  puts("pairwise coprime");
  return 0;
}
/*

*/
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define INIT                                                                   \
  ios_base ::sync_with_stdio(false);                                           \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);                                                              \
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll

int t, n, m, k, a[300010], q, l, r;
bool v[1000010];
int cnt[1000010];

int32_t main() {
  INIT cin >> n;
  int sgcd = 0;
  bool sw = false, pw = true;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    sgcd = __gcd(sgcd, a[i]);
  }
  if (sgcd == 1) {
    sw = true;
  }

  for (int i = 2; i <= 1000000; i++) {
    if (!v[i]) {
      int c = 0;
      c += cnt[i];
      for (int j = 2 * i; j <= 1000000; j += i) {
        v[j] = true;
        c += cnt[j];
      }
      if (c > 1) {
        pw = false;
        break;
      }
    }
  }

  if (pw) {
    cout << "pairwise coprime";
  } else {
    if (sw) {
      cout << "setwise coprime";
    } else {
      cout << "not coprime";
    }
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define INIT                                                                   \
  ios_base ::sync_with_stdio(false);                                           \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);                                                              \
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll

int t, n, m, k, a[1000010], q, l, r;
bool v[1000010];
int cnt[1000010];

int32_t main() {
  INIT cin >> n;
  int sgcd = 0;
  bool sw = false, pw = true;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    sgcd = __gcd(sgcd, a[i]);
  }
  if (sgcd == 1) {
    sw = true;
  }

  for (int i = 2; i <= 1000000; i++) {
    if (!v[i]) {
      int c = 0;
      c += cnt[i];
      for (int j = 2 * i; j <= 1000000; j += i) {
        v[j] = true;
        c += cnt[j];
      }
      if (c > 1) {
        pw = false;
        break;
      }
    }
  }

  if (pw) {
    cout << "pairwise coprime";
  } else {
    if (sw) {
      cout << "setwise coprime";
    } else {
      cout << "not coprime";
    }
  }

  return 0;
}
Problem p02574 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
bool br[2000000];
void siv() {
  memset(br, true, 2000000);
  int i, j;
  br[0] = false;
  br[1] = false;
  for (i = 2; i * i <= 2000000; i++) {
    if (br[i] == true) {
      for (j = i * i; j <= 2000000; j += i) {
        br[j] = false;
      }
    }
  }
}

int prime(int n) {
  int i, j;
  for (i = 2; i <= n; i++) {
    if (br[i] == true) {
      if (n % br[i] == 0) {
        return i;
      }
    }
  }
}
int main() {
  int n, i, j, gd;
  while (cin >> n) {
    siv();
    vector<int> v;
    map<int, int> mp;
    int x, c = 0, z;
    for (i = 0; i < n; i++) {
      cin >> x;
      v.push_back(x);
    }
    gd = v[0];
    for (i = 1; i < n; i++) {
      gd = __gcd(gd, v[i]);
    }
    if (gd != 1) {
      cout << "not coprime" << endl;
    } else {
      int p;
      int flag = 0;
      for (i = 0; i < n; i++) {
        p = v[i];

        for (j = 2; j <= p; j++) {
          if (br[j] == true) {
            if (p % j == 0) {
              mp[j]++;
            }
            if (mp[j] > 1) {
              flag = 1;
              break;
            }
          }
        }
      }
      if (flag == 1)
        cout << "setwise coprime" << endl;
      else
        cout << "pairwise coprime" << endl;
      mp.clear();
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
bool br[2000000];
void siv() {
  memset(br, true, 2000000);
  int i, j;
  br[0] = false;
  br[1] = false;
  for (i = 2; i * i <= 2000000; i++) {
    if (br[i] == true) {
      for (j = i * i; j <= 2000000; j += i) {
        br[j] = false;
      }
    }
  }
}

int prime(int n) {
  int i, j;
  for (i = 2; i <= n; i++) {
    if (br[i] == true) {
      if (n % br[i] == 0) {
        return i;
      }
    }
  }
}
int main() {
  int n, i, j, gd;
  while (cin >> n) {
    siv();
    vector<int> v;
    map<int, int> mp;
    int x, c = 0, z;
    for (i = 0; i < n; i++) {
      cin >> x;
      v.push_back(x);
    }
    gd = v[0];
    for (i = 1; i < n; i++) {
      gd = __gcd(gd, v[i]);
    }
    if (gd != 1) {
      cout << "not coprime" << endl;
    } else {
      int p;
      int flag = 0;
      for (i = 0; i < n; i++) {
        p = v[i];
        if (br[p] == true) {
          mp[p]++;
          if (mp[p] > 1) {
            flag = 1;
            break;
          }
        } else {
          for (j = 2; j <= p; j++) {
            if (br[j] == true) {
              if (p % j == 0) {
                mp[j]++;
              }
              if (mp[j] > 1) {
                flag = 1;
                break;
              }
            }
          }
        }
      }
      if (flag == 1)
        cout << "setwise coprime" << endl;
      else
        cout << "pairwise coprime" << endl;
      mp.clear();
    }
  }
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

struct Factorizer {
  int n;
  vector<int> minFactor;
  vector<bool> cnt;

  Factorizer(int max) {
    int i, j;
    n = max;
    minFactor.resize(n);
    cnt.resize(n, 0);
    iota(minFactor.begin(), minFactor.end(), 0);
    for (i = 2; i * i < n; i++) {
      if (minFactor[i] < i)
        continue;
      for (j = i * i; j < n; j += i) {
        if (minFactor[j] == j)
          minFactor[j] = i;
      }
    }
  }

  bool check(int x) {
    while (x > 1) {
      if (cnt[minFactor[x]])
        return 1;
      else
        cnt[minFactor[x]] = 1;

      int t = minFactor[x];
      while (x % t == 0) {
        x /= t;
      }
    }
    return 0;
  }
};

int main(int argc, char *argv[]) {
  int n, i, s;
  cin >> n;

  Factorizer f(100001);
  vector<int> a(n);

  for (i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (i = 0; i < n; i++) {
    if (f.check(a[i])) {
      break;
    }
  }
  if (i == n) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int c = gcd(a[0], a[1]);
  for (i = 2; i < n; i++) {
    c = gcd(c, a[i]);
    if (c == 1)
      break;
  }
  if (c == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }

  cout << "not coprime" << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

struct Factorizer {
  int n;
  vector<int> minFactor;
  vector<bool> cnt;

  Factorizer(int max) {
    int i, j;
    n = max;
    minFactor.resize(n);
    cnt.resize(n, 0);
    iota(minFactor.begin(), minFactor.end(), 0);
    for (i = 2; i * i < n; i++) {
      if (minFactor[i] < i)
        continue;
      for (j = i * i; j < n; j += i) {
        if (minFactor[j] == j)
          minFactor[j] = i;
      }
    }
  }

  bool check(int x) {
    while (x > 1) {
      if (cnt[minFactor[x]])
        return 1;
      else
        cnt[minFactor[x]] = 1;

      int t = minFactor[x];
      while (x % t == 0) {
        x /= t;
      }
    }
    return 0;
  }
};

int main(int argc, char *argv[]) {
  int n, i, s;
  cin >> n;

  Factorizer f(1000001);
  vector<int> a(n);

  for (i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (i = 0; i < n; i++) {
    if (f.check(a[i])) {
      break;
    }
  }
  if (i == n) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int c = gcd(a[0], a[1]);
  for (i = 2; i < n; i++) {
    c = gcd(c, a[i]);
    if (c == 1)
      break;
  }
  if (c == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }

  cout << "not coprime" << endl;

  return 0;
}
Problem p02574 (C++)

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

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define se second
#define endl '\n'
#define fd(n) fixed << setprecision(n)
#define MAX 100000000000000000
#define MAXN 100050
#define mod 1000000007
#define pi 3.1415926535897932384626433

ll fun(ll x, ll y) {
  ll ans = 1;
  while (y > 0) {
    if (y % 2 == 1) {
      ans = ans * 1ll * x;
      ans = ans % mod;
    }
    y = y / 2;
    x = (x * 1ll * x) % mod;
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, i, flag = 0, j, x;
  ll prime[MAXN], prime1[MAXN];
  memset(prime, 0, sizeof(prime));
  memset(prime1, 0, sizeof(prime1));
  for (i = 2; i < MAXN; i++) {
    if (prime[i] == 0) {
      for (j = i + i; j < MAXN; j += i) {
        prime[j] = 1;
      }
    }
  }
  cin >> n;
  ll a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    prime1[a[i]]++;
  }
  x = a[0];
  for (i = 1; i < n; i++) {
    x = __gcd(x, a[i]);
  }
  if (x >= 2) {
    cout << "not coprime";
  } else {
    ll count = 0;
    for (i = 2; i < MAXN; i++) {
      count = 0;
      for (j = i; j < MAXN; j += i) {
        count += prime1[j];
      }
      if (count > 1) {
        flag = 1;
      }
    }
    if (flag == 0) {
      cout << "pairwise coprime";
    } else {
      cout << "setwise coprime";
    }
  }
}

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

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define se second
#define endl '\n'
#define fd(n) fixed << setprecision(n)
#define MAX 100000000000000000
#define MAXN 1000050
#define mod 1000000007
#define pi 3.1415926535897932384626433

ll fun(ll x, ll y) {
  ll ans = 1;
  while (y > 0) {
    if (y % 2 == 1) {
      ans = ans * 1ll * x;
      ans = ans % mod;
    }
    y = y / 2;
    x = (x * 1ll * x) % mod;
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, i, flag = 0, j, x;
  ll prime[MAXN], prime1[MAXN];
  memset(prime, 0, sizeof(prime));
  memset(prime1, 0, sizeof(prime1));
  for (i = 2; i < MAXN; i++) {
    if (prime[i] == 0) {
      for (j = i + i; j < MAXN; j += i) {
        prime[j] = 1;
      }
    }
  }
  cin >> n;
  ll a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    prime1[a[i]]++;
  }
  x = a[0];
  for (i = 1; i < n; i++) {
    x = __gcd(x, a[i]);
  }
  if (x >= 2) {
    cout << "not coprime";
  } else {
    ll count = 0;
    for (i = 2; i < MAXN; i++) {
      count = 0;
      for (j = i; j < MAXN; j += i) {
        count += prime1[j];
      }
      if (count > 1) {
        flag = 1;
      }
    }
    if (flag == 0) {
      cout << "pairwise coprime";
    } else {
      cout << "setwise coprime";
    }
  }
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repa(i, s, n) for (int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i, a, b) for (int i = a; i >= b; i--)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const int A = 100005;
signed main() {
  int n;
  cin >> n;
  vi a(n), c(A);
  rep(i, n) {
    cin >> a[i];
    c[a[i]]++;
  }

  bool pc = true;
  for (int i = 2; i < A; i++) {
    int cnt = 0;
    for (int j = i; j < A; j += i) {
      cnt += c[j];
    }
    if (cnt > 1) {
      pc = false;
    }
  }

  if (pc) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int g = 0;
  rep(i, n) g = __gcd(g, a[i]);
  if (g == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }

  cout << "not coprime" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repa(i, s, n) for (int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i, a, b) for (int i = a; i >= b; i--)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const int A = 1000005;
signed main() {
  int n;
  cin >> n;
  vi a(n), c(A);
  rep(i, n) {
    cin >> a[i];
    c[a[i]]++;
  }

  bool pc = true;
  for (int i = 2; i < A; i++) {
    int cnt = 0;
    for (int j = i; j < A; j += i) {
      cnt += c[j];
    }
    if (cnt > 1) {
      pc = false;
    }
  }

  if (pc) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int g = 0;
  rep(i, n) g = __gcd(g, a[i]);
  if (g == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }

  cout << "not coprime" << endl;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define AC 0
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, gcd = 0;
  cin >> n;
  vector<int> a(n), prime(n);
  bool p = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    int tmp = a[i];
    for (int j = 2; 1ll * j * j <= tmp; j++)
      if (!(tmp % j)) {
        if (prime[j])
          p = 0;
        prime[j] = 1;
        while (!(tmp % j))
          tmp /= j;
      }
    if (tmp != 1) {
      if (prime[tmp])
        p = 0;
      prime[tmp] = 1;
    }
    gcd = __gcd(gcd, a[i]);
  }
  if (p)
    cout << "pairwise coprime\n";
  else if (gcd == 1)
    cout << "setwise coprime\n";
  else
    cout << "not coprime\n";
  return AC;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define AC 0
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, gcd = 0;
  cin >> n;
  vector<int> a(n), prime(1e6 + 1);
  bool p = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    int tmp = a[i];
    for (int j = 2; 1ll * j * j <= tmp; j++)
      if (!(tmp % j)) {
        if (prime[j])
          p = 0;
        prime[j] = 1;
        while (!(tmp % j))
          tmp /= j;
      }
    if (tmp != 1) {
      if (prime[tmp])
        p = 0;
      prime[tmp] = 1;
    }
    gcd = __gcd(gcd, a[i]);
  }
  if (p)
    cout << "pairwise coprime\n";
  else if (gcd == 1)
    cout << "setwise coprime\n";
  else
    cout << "not coprime\n";
  return AC;
}
Problem p02574 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>

using namespace std;

int sieve[1000002], cnt[1000002], a[1000002], n, m, i, j, g, t;

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", a + i);
    if (a[i] > m)
      m = a[i];
    if (g)
      g = gcd(g, a[i]);
    else
      g = a[0];
  }
  if (g > 1) {
    printf("not coprime\n");
    return 0;
  }
  for (i = 2; i <= m; i++) {
    if (sieve[i] == 0) {
      sieve[i] = i;
      for (j = i * i; j <= m; j += i) {
        if (sieve[j] == 0)
          sieve[j] = i;
      }
    }
  }
  for (i = 0; i < n; i++) {
    j = a[i];
    while (j > 1) {
      t = sieve[j];
      cnt[t]++;
      if (cnt[t] > 1) {
        printf("setwise coprime\n");
        return 0;
      }
      while (j % t == 0)
        j /= t;
    }
  }
  printf("pairwise coprime\n");
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>

using namespace std;

int sieve[1000002], cnt[1000002], a[1000002], n, m, i, j, g, t;

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", a + i);
    if (a[i] > m)
      m = a[i];
    if (g)
      g = gcd(g, a[i]);
    else
      g = a[0];
  }
  if (g > 1) {
    printf("not coprime\n");
    return 0;
  }
  for (i = 2; i <= m; i++) {
    if (sieve[i] == 0) {
      sieve[i] = i;
      if ((long long)i * i <= m)
        for (j = i * i; j <= m; j += i) {
          if (sieve[j] == 0)
            sieve[j] = i;
        }
    }
  }
  for (i = 0; i < n; i++) {
    j = a[i];
    while (j > 1) {
      t = sieve[j];
      cnt[t]++;
      if (cnt[t] > 1) {
        printf("setwise coprime\n");
        return 0;
      }
      while (j % t == 0)
        j /= t;
    }
  }
  printf("pairwise coprime\n");
  return 0;
}