stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



using ll = long long;



const int N = 2e5 + 5;

 

int n;

long long f[N];

pair <int, int> a[N];

 

struct FenwickTree {

    long long bit[N];

    void init(){

        memset(bit, 0, sizeof bit);

    }

    

    void update (int x, long long val) {

        for (int i = x; i < N; i += i & -i) bit[i] = max(bit[i], val);

    }

    

    long long query (int x) {

        long long ans = 0;

        for (int i = x; i > 0; i -= i & -i) ans = max(ans, bit[i]);

        return ans;

    }

} fw;

 

int main()

{

   

    cin >> n; fw.init();

    for (int i = 1; i <= n; i++) cin >> a[i].first;

    for (int i = 1; i <= n; i++) cin >> a[i].second;

    for (int i = 1; i <= n; i++) f[i] = a[i].second;

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

        f[i] = max(f[i], fw.query(a[i].first - 1) + a[i].second);

        fw.update(a[i].first, f[i]);

    }

    

    cout << *max_element(f + 1, f + n + 1);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.602703922608504x):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;



const int MAX_N = 2e5+10;

int N;

int h[MAX_N];

int a[MAX_N];

ll V[MAX_N+1];

ll dp[MAX_N+1];



void update(int i, ll x)

{

	while(i<=MAX_N){

		V[i]=max(V[i],x);

		i+=(i&-i);

	}

}



ll query(int i)

{

	ll res = 0;

	while(i>0){

		res =max(res, V[i]);

		i -= (i&-i);

	}

	return res;

}



void solve()

{

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

		dp[i]=max(dp[i], query(h[i]-1)+a[i]);

		update(h[i],dp[i]);

	}

	cout << *max_element(dp+1, dp+N+1) << '\n';

}



int main()

{

	cin >> N;

	for(int i=1;i<=N;++i) cin >> h[i];

	for(int i=1;i<=N;++i) cin >> a[i];

	solve();

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

 

#define FOR(i, a, b) for(int i = a ; i <= b ; ++i)

#define FOD(i, a, b) for(int i = a ; i >= b ; --i)

#define FRSZ(i, a) for(int i = 0 ; i < a.size() ; ++i)

#define FDSZ(i, a) for(int i = a.size() - 1 ; i >= 0 ; --i)

 

#define debug(x) cout << #x << " = " << x << endl;

#define debugvi(x) {FRSZ(_, x) cout << x[_] << " "; cout << endl;}

#define debugarr(x, n) {FOR(_, 1, n) cout << x[_] << " "; cout << endl;}

 

#define fi first

#define se second

#define pb push_back

using namespace std;

 

typedef int64_t ll;

const int MAX = 2e5 + 5;

int n;

int a[MAX], h[MAX];

 

struct FenwickTree{

    ll Tree[MAX];

    void Update(int u, ll x){

        for(; u <= n ; u += u & -u )

            Tree[u] = max(Tree[u], x);

    }

 

    ll Query(int u){

        if (u <= 0) return 0;

        ll ans = 0;

        for(; u > 0 ; u -= u & -u)

            ans = max(ans, Tree[u]);

        return ans;

    }

} BIT;

 

int main(){



 

    cin >> n;

    FOR(i, 1, n) cin >> h[i];

    FOR(i, 1, n) cin >> a[i];

 

    ll ans = 0;    

    memset(BIT.Tree, 0, sizeof(BIT.Tree));

    FOR(i, 1, n){

        ll tmp = BIT.Query(h[i] - 1) + a[i];

        ans = max(ans, tmp);

        BIT.Update(h[i], tmp);

    }

    cout << ans;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.564363713978585x):
#include <bits/stdc++.h>

#define ll long long

#define pb push_back

#define pf push_front

#define popb pop_back

#define popf pop_front

#define in insert

#define b back

#define f front

#define p push

#define FOR(i,a,b) for (ll i=a; i<=b; i++)

#define FOD(i,a,b) for (ll i=a; i>=b; i--)

#define mp make_pair

#define up upper_bound

#define lp lower_bound

#define endl "\n"

//priority_queue <int> ; less

//priority_queue <int,vector<int>,greater<int> > ; greater

using namespace std;

ll n,i,a[200005],kq[200005];

set <ll> dp;

set <ll> ::iterator it,tg;

int main()

{

	ios_base::sync_with_stdio(0);

	cin.tie(NULL);

	//freopen("input.txt","r",stdin);

	//freopen("output.txt","w",stdout);

	cin>>n;

	for (i=1;i<=n;i++) cin>>a[i];

	for (i=1;i<=n;i++) cin>>kq[a[i]];

	dp.in(a[1]);

	for (i=2;i<=n;i++)

	{

		it=dp.up(a[i]);

		if (it==dp.end())

		{

			tg=dp.end();

			tg--;

			kq[a[i]]+=kq[*tg];

			dp.in(a[i]);

		}

			else 

			{

				if (it==dp.begin())

				{

					while(kq[*it]<=kq[a[i]]&&it!=dp.end()) 

					{

						dp.erase(it);

						it=dp.up(a[i]);

					}

					dp.in(a[i]);

				}

				else

				{

					tg=it;

					tg--;

					kq[a[i]]+=kq[*tg];

					while(kq[*it]<=kq[a[i]]&&it!=dp.end()) 

					{

						dp.erase(it);

						it=dp.up(a[i]);

					}

					dp.in(a[i]);

				}

			}

	}

	cout<<kq[*(--dp.end())];

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

const int N = 2e5;

vector<ll> tree(4 * N, 0);



void update(int l, int r, int idx, ll val, int node)

{

	if (l == r)

	{

		tree[node] = val;

	}

	else

	{

		int m = l + (r - l) / 2;

		if (idx >= l && idx <= m)

		{

			update(l, m, idx, val, 2 * node);

		}

		else

		{

			update(m + 1, r, idx, val, 2 * node + 1);

		}

		tree[node] = max(tree[2 * node], tree[2 * node + 1]);

	}

}



ll query(int l, int r, int ql, int qr, int node)

{

	if (ql <= l && qr >= r)

	{

		return tree[node];

	}

	if (ql > r || qr < l)

	{

		return 0;

	}

	int m = l + (r - l) / 2;

	return max(query(l, m, ql, qr, 2 * node), query(m + 1, r, ql, qr, 2 * node + 1));

}



int main()

{

	ios_base::sync_with_stdio(false);



	int n;

	cin >> n;

	vector<ll> h(n), a(n);

	for (int i = 0; i < n; i++)

	{

		cin >> h[i];

	}

	for (int i = 0; i < n; i++)

	{

		cin >> a[i];

	}

	ll answer = 0;

	for (int i = 0; i < n; i++)

	{

		ll temp = query(1, n, 1, h[i] - 1, 1) + a[i];

		answer = max(answer, temp);

		update(1, n, h[i], temp, 1);

	}

	cout << answer;



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 7.648490406116283x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



const int mxN = 2e5 + 5;

int N, h[mxN], a[mxN];

ll tree[4 * mxN];



ll query(int s, int e, int ql, int qr, int node) {

	if (ql <= s && qr >= e) {

		return tree[node];

	}

	if (qr < s || ql > e) {

		return 0;

	}

	int mid = s + (e - s) / 2;

	return max(query(s, mid, ql, qr, 2 * node), query(mid + 1, e, ql, qr, 2 * node + 1));

}



void update(int l, int r, int idx, ll val, int node) {

	if (l == r) {

		tree[node] = val;

	} else {

		int mid = l + (r - l) / 2;

		if (idx >= l && idx <= mid) {

			update(l, mid, idx, val, 2 * node);

		} else if (idx >= mid + 1 && idx <= r) {

			update(mid + 1, r, idx, val, 2 * node + 1);

		}

		tree[node] = max(tree[2 * node], tree[2 * node + 1]);

	}

}



int main() {

	ios_base::sync_with_stdio(false);



	cin >> N;

	for (int i = 0; i < N; i++) {

		cin >> h[i];

	}

	for (int i = 0; i < N; i++) {

		cin >> a[i];

	}

	ll answer = 0;

	for (int i = 0; i < N; i++) {

		ll val = a[i] + query(1, N, 1, h[i] - 1, 1);

		answer = max(answer, val);

		update(1, N, h[i], val, 1);

	}

	cout << answer;



	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;

typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }



#define def 0

template<class V, int NV> struct SegTree { //[l,r)

    V comp(V& l, V& r) { return max(l, r); };



    vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }

    V get(int x, int y, int l = 0, int r = NV, int k = 1) {

        if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];

        auto a = get(x, y, l, (l + r) / 2, k * 2); 

        auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);

        return comp(a, b);

    }

    void update(int i, V v) {

        i += NV; val[i] = v;

        while (i>1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);

    }

    void add(int i, V v) { update(i, val[i + NV] + v); }

    V operator[](int x) { return get(x, x + 1); }

};

int N, H[200010], A[200010];

SegTree<ll, 1 << 18> dp;



int main(){

    cin >> N;

    rep(i, 0, N) cin >> H[i];

    rep(i, 0, N) cin >> A[i];



    rep(i, 0, N) {

        ll opt = dp.get(0, H[i]) + A[i];

        dp.update(H[i], max(dp[H[i]], opt));

    }



    cout << dp.get(0, 1<<18) << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.262193221363328x):
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for(int i = a; i < b; i++)

typedef long long ll;



const int MAX_N = 1 << 18;

const int def = 0;



//セグメント木を持つグローバル配列

ll n, dat[2 * MAX_N - 1];



//初期化

void init(ll n_){

    //簡単のため、要素数を2のべき乗に

    n = 1;

    while ( n < n_ ) n *= 2;



    //全ての値をINT_MAXに

    for(int i = 0; i < 2 * n - 1; i++) dat[i] = def;

}



//k番目の値(0-indexed)をaに変更

void update(ll k, ll a){

    //葉の節点

    k += n - 1;

    dat[k] = a;

    //登りながら更新

    while(k > 0){

        k = (k-1)/2;

        dat[k] = max(dat[k*2+1], dat[k*2+2]);

    }

}



// [a,b)の最小値を求める

// 後ろの方の引数は、計算の簡単のための引数

// kは節点の番号、1,rはその接点が[1,r)に対応づいていることを表す

// したがって、外からはquery(a, b, 0, 0, n)として呼ぶ

ll query(ll a, ll b, ll k = 0, ll l = 0, ll r = n){

    //[a,b)と[l,r)が交差しなければ、INT_MAX

    if( r <= a || b <= l) return def;



    //[a,b)が[l,r)を完全に含んでいれば、この節点の値

    if(a <= l && r <= b) return dat[k];

    else{

        //そうでなければ、２つの子が必要

        ll vl = query(a, b, k * 2 + 1, l, (l+r)/2);

        ll vr = query(a, b, k * 2 + 2, (l+r)/2, r);

        return max(vl,vr);

    }

}



int main(){

    ll N; cin >> N;

    vector<ll> h(N), a(N);

    rep(i, 0, N) cin >> h[i];

    rep(i, 0, N) cin >> a[i];



    init(N);

    rep(i, 0, N){

        update(h[i]-1, query(0, h[i]-1) + a[i]);

    }

    cout << query(0, N) << endl;

}
// Slower C++ solution:
/*

 * Author: Dumbear

 * Created Time:  2011/8/31 12:33:48

 * File Name: A.cpp

 */

#include <iostream>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <cstdlib>

#include <algorithm>

#include <vector>

using namespace std;

#define out(v) cerr << #v << ": " << (v) << endl

#define SZ(v) ((int)(v).size())

const int maxint = -1u>>1;

template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}

template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}



int n, m, s[110];



bool solve();



int main() {

    while (solve());

    return 0;

}



bool solve() {

    scanf("%d%d", &n, &m);

    if (n == 0 && m == 0)

        return false;

    for (int i = 0; i < m; ++i)

        scanf("%d", &s[i]);

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

        for (int j = 0; j < m; ++j) {

            int c;

            scanf("%d", &c);

            s[j] -= c;

        }

    }

    for (int i = 0; i < m; ++i)

        if (s[i] < 0) {

            puts("No");

            return true;

        }

    puts("Yes");

    return true;

}

// Faster C++ solution for the same problem (measured speedup: 5.0948282645886716x):
#include<cstdio>



int s[110],n,m;



int main()

{

    int i,j,k,l;

    bool pass;

    while (1)

    {

        scanf("%d%d",&n,&m);

        if (n==0&&m==0) break;

        for (i=0;i<m;i++)

            scanf("%d",&s[i]);

        for (i=0;i<n;i++)

            for (j=0;j<m;j++)

            {

                scanf("%d",&k);

                s[j]-=k;

            }

        pass=true;

        for (i=0;i<m;i++)

            if (s[i]<0)

            {

                pass=false;

                break;

            }

        if (pass) printf("Yes\n");

        else printf("No\n");

    }

    return 0;

}
// Slower C++ solution:
/*

 * Author: FreePascal

 * Created Time:  2011-8-31 12:36:01

 * File Name: a.cpp

 */

#include <iostream>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <cstdlib>

#include <algorithm>

#include <vector>

#include <queue>

#include <map>

#include <set>

#include <deque>

#include <list>

#include <stack>

using namespace std;

#define out(v) cerr << #v << ": " << (v) << endl

#define SZ(v) ((int)(v).size())

const int maxint = -1u>>1;

template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}

template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}



const int maxn = 1000 + 100;

int n,m,s[maxn],b[maxn][maxn];

int main() {

    while (scanf("%d%d",&n,&m) != EOF){

        if (n == 0 && m == 0) break;

        for (int i = 0; i < m; i++) scanf("%d",&s[i]);

        for (int i = 0; i < n; i++)

            for (int j = 0; j < m; j++) scanf("%d",&b[i][j]);

        bool flag = true;

        for (int i = 0; i < m; i++){

            int sum = 0;

            for (int j = 0; j < n; j++) sum += b[j][i];

            if (sum > s[i]) {

                flag = false;

                break;

            }

        }

        if (!flag) puts("No");

        else puts("Yes");

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.098110432146963x):
#include<cstdio>



int s[110],n,m;



int main()

{

    int i,j,k,l;

    bool pass;

    while (1)

    {

        scanf("%d%d",&n,&m);

        if (n==0&&m==0) break;

        for (i=0;i<m;i++)

            scanf("%d",&s[i]);

        for (i=0;i<n;i++)

            for (j=0;j<m;j++)

            {

                scanf("%d",&k);

                s[j]-=k;

            }

        pass=true;

        for (i=0;i<m;i++)

            if (s[i]<0)

            {

                pass=false;

                break;

            }

        if (pass) printf("Yes\n");

        else printf("No\n");

    }

    return 0;

}
// Slower C++ solution:
#include<iostream>

using namespace std;

int main()

{

	int N,K;

	while(1)

	{

		cin >> N;

		cin >> K;

		int temp;

		if(N == 0 && K==0)break;

		int *A = new int[K];

		int *B = new int[K];

		bool flag = true;

		for(int i=0;i<K;i++)

		{

			B[i] = 0;

		}

		for(int i=0;i<K;i++)

		{

			cin >> A[i];

		}

		for(int i=0;i<N;i++)

		{

			for(int i=0;i<K;i++)

			{

				cin >> temp;

				B[i] += temp;

			}

		}

		for(int i=0;i<K;i++)

		{

			if(B[i]>A[i])

			{

				flag = false;

				break;

			}

		}

		if(flag == false)

		{

			cout << "No" << endl;

		}

		else

		{

			cout << "Yes" << endl;

		}

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.184266135788374x):
#include<cstdio>



int s[110],n,m;



int main()

{

    int i,j,k,l;

    bool pass;

    while (1)

    {

        scanf("%d%d",&n,&m);

        if (n==0&&m==0) break;

        for (i=0;i<m;i++)

            scanf("%d",&s[i]);

        for (i=0;i<n;i++)

            for (j=0;j<m;j++)

            {

                scanf("%d",&k);

                s[j]-=k;

            }

        pass=true;

        for (i=0;i<m;i++)

            if (s[i]<0)

            {

                pass=false;

                break;

            }

        if (pass) printf("Yes\n");

        else printf("No\n");

    }

    return 0;

}
// Slower C++ solution:
#include<iostream>

using namespace std;

int main(){

	int N,K,i,j,*S,B,a;

	while(a=1,cin>>N>>K,N||K){

		S=new int[K];

		for(i=K;i--;)cin>>S[i];

		for(i=0;i<N;++i)for(j=K;j--;)cin>>B,S[j]-=B,S[j]<0?a=0:0;

		cout<<(a?"Yes":"No")<<endl;

	}

}

// Faster C++ solution for the same problem (measured speedup: 5.200379540575458x):
#include<stdio.h>

int main(){

	int N,K,i,j,S[100],B,a;

	while(a=1,scanf("%d %d",&N,&K),N||K){

		for(i=K;i--;)scanf("%d",S+i);

		for(i=N;i--;)for(j=K;j--;)scanf("%d",&B),S[j]-=B,S[j]<0?a=0:0;

		puts(a?"Yes":"No");

	}

}
// Slower C++ solution:
#include<iostream>

using namespace std;

int main(){

	int N,K,i,j,*S,B,a;

	while(a=1,cin>>N>>K,N||K){

		S=new int[K];

		for(i=K;i--;)cin>>S[i];

		for(i=N;i--;)for(j=K;j--;)cin>>B,S[j]-=B,S[j]<0?a=0:0;

		cout<<(a?"Yes":"No")<<endl;

	}

}

// Faster C++ solution for the same problem (measured speedup: 5.20018251626218x):
#include<stdio.h>

int main(){

	int N,K,i,j,S[100],B,a;

	while(a=1,scanf("%d %d",&N,&K),N||K){

		for(i=K;i--;)scanf("%d",S+i);

		for(i=N;i--;)for(j=K;j--;)scanf("%d",&B),S[j]-=B,S[j]<0?a=0:0;

		puts(a?"Yes":"No");

	}

}
// Slower C++ solution:
#include<iostream>

using namespace std;

int main(){

	int N,K,i,j,S[100],B,a;

	while(a=1,cin>>N>>K,N||K){

		for(i=K;i--;)cin>>S[i];

		for(i=N;i--;)for(j=K;j--;)cin>>B,S[j]-=B,S[j]<0?a=0:0;

		cout<<(a?"Yes":"No")<<endl;

	}

}

// Faster C++ solution for the same problem (measured speedup: 5.196386417357729x):
#include<stdio.h>

int main(){

	int N,K,i,j,S[100],B,a;

	while(a=1,scanf("%d %d",&N,&K),N||K){

		for(i=K;i--;)scanf("%d",S+i);

		for(i=N;i--;)for(j=K;j--;)scanf("%d",&B),S[j]-=B,S[j]<0?a=0:0;

		puts(a?"Yes":"No");

	}

}
// Slower C++ solution:
#include<vector>

#include<list>

#include<algorithm>

#include<iostream>

#include<string>

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<cmath>

using namespace std;

int main(){

  int i,j;

  int s[100],b,m,n;

  while(cin>>n>>m&&n+m){

    for(i=0;i<m;i++)

      cin>>s[i];

    for(i=0;i<n;i++){

      for(j=0;j<m;j++){

	cin>>b;

	s[j]-=b;

      }

    }

    for(i=0;i<m;i++){

      if(s[i]<0)

	break;

    }

    if(i==m)

      cout<<"Yes"<<endl;

    else

      cout<<"No"<<endl;

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.1988591279030905x):
#include<cstdio>

using namespace std;

int main(){

  int h,i,j;

  int n,m;

  while(scanf("%d%d",&n,&m),n||m){

    int s[100];

    for(i=0;i<m;++i)

      scanf("%d",s+i);

    h=1;

    for(i=0;i<n;++i){

      for(j=0;j<m;++j){

	int b;

	scanf("%d",&b);

	if(h){

	  s[j]-=b;

	  if(s[j]<0)

	    h=0;

	}

      }

    }

    if(h)

      puts("Yes");

    else

      puts("No");

  }

  return 0;

}
// Slower C++ solution:
#include <iostream>

using namespace std;

int n, m, x, s[100];

int main() {

	while(cin >> n >> m, n + m) {

		for(int i = 0; i < m; i++) cin >> s[i];

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

			for(int j = 0; j < m; j++) cin >> x, s[j] -= x;

		}

		int f = 1;

		for(int i = 0; i < m; i++) {

			if(s[i] < 0) f = 0;

		}

		cout << (f ? "Yes" : "No") << endl;

	}

}

// Faster C++ solution for the same problem (measured speedup: 5.19013446167324x):
#include <stdio.h>

int n, m, x, s[100];

int main() {

	while(scanf("%d%d", &n, &m), n + m) {

		for(int i = 0; i < m; i++) scanf("%d", s + i);

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

			for(int j = 0; j < m; j++) scanf("%d", &x), s[j] -= x;

		}

		int f = 1;

		for(int i = 0; i < m; i++) {

			if(s[i] < 0) f = 0;

		}

		puts(f ? "Yes" : "No");

	}

}
// Slower C++ solution:
#include <iostream>

#include <vector>

using namespace std;



int main(){

	int n, k, s, b;

	

	while( cin >> n >> k , n || k ){

		vector<int> S;

		for(int i=0 ; i<k ; i++ ){

			cin >> s;

			S.push_back(s);

		}

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

			for(int j=0 ; j<k ; j++ ){

				cin >> b;

				S[j] -= b;

			}

		}

		bool flag = true;

		for(int i=0 ; i<k ; i++ ){

			if( S[i] < 0 ){

				flag = false;

			}

		}

		cout << ( (flag)? "Yes" : "No" ) << endl;

	}

}

// Faster C++ solution for the same problem (measured speedup: 5.260694432028547x):
#include<stdio.h>

using namespace std;



int main(){

	int n,k,b,s[101],i,j;

	

	for(;scanf("%d%d",&n,&k),n|k;){

		for(i=0;i<k;i++)

			scanf("%d",s+i);

		for(i=0;i<n;i++){

			for(j=0;j<k;j++){

				scanf("%d",&b);

				s[j]-=b;

			}

		}

		b=1;

		for(i=0;i<k;)

			if(s[i++]<0)

				b=0;

		puts(b?"Yes":"No");

	}

}
// Slower C++ solution:
#include <cstdio>

#include <cstring>

#include <iostream>

using namespace std;

const int maxn = 1e6 + 5;

int vis[maxn], prime[maxn], notPrime[maxn], num[maxn];

int total, n, maxx = 0, ans = 0, tmp;

void getPrime(int sum) {

    for (int i = 2; i <= sum; i++) {

        if (!notPrime[i]) {

            prime[++total] = i;

        }

        for (int j = 1; prime[j] * i <= sum; j++) {

            notPrime[i * prime[j]] = prime[j];

            if (i % prime[j] == 0)

                break;

        }

    }

}



void getInit() {

    memset(vis, 0, sizeof(vis));

    memset(notPrime, 0, sizeof(notPrime));

    memset(vis, 0, sizeof(vis));

}



int main() {

    getInit();

    scanf("%d", &n);

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

        scanf("%d", &num[i]);

        maxx = max(maxx, num[i]);

    }

    getPrime(maxx);

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

        while (notPrime[num[i]]) {

            tmp = notPrime[num[i]];

            vis[tmp]++;

            ans = max(ans, vis[tmp]);

            while (num[i] % tmp == 0)

                num[i] /= tmp;

        }

        if (num[i] != 1) {

            vis[num[i]]++;

            ans = max(ans, vis[num[i]]);

        }

    }

    if (ans <= 1)

        printf("pairwise coprime\n");

    else if (ans < n)

        printf("setwise coprime\n");

    else

        printf("not coprime\n");

    getchar();

    getchar();

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 9.32334665904666x):
#include<bits/stdc++.h>

using namespace std;

int n,arr[1000005],p[1000005],d;

int main()

{

	cin>>n;

	for(int i=1;i<=n;i++) cin>>arr[i];

	d=arr[1];

	for(int i=2;i<=n;i++) d=__gcd(d,arr[i]);

	if(d!=1) 

	{

		cout<<"not coprime"<<endl;

		return 0;

	}

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

	{

		int k=arr[i];

		for(int j=1;j<=sqrt(k);j++)

		{

			if(k%j==0) 

			{

				if(j!=1&&p[j]==1||p[k/j]==1) 

				{

					cout<<"setwise coprime"<<endl;

					return 0;

				}

				p[j]++,p[k/j]++;

			}

		}

	}

	cout<<"pairwise coprime"<<endl;

}