akhauriyash/Code-Regression huggingface dataset:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


n = int(readline())

p = list(map(int, readline().split()))

num = 1
l = []
for i in range(n):
    if p[i] == num:
        l.append(i)
        num += 1

print('-1' if len(l) == 0 else n-len(l))


Measured memory_bytes: 27916
//ΔATCODER D
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
const int N = 555555*2;
vector<int> v[N];
char ch[N];
int a[N],f[N],g[N],h[N];//a a-1 1
int solve(int m){
	int n,i,res;
	n=v[m].size()-1;
	f[0]=0;
	f[1]=0;
	g[1]=0;
	h[1]=0;
	for(i=2;i<=n;i=i+1){
		h[i]=max(f[i-1],max(h[i-1]+v[m][i-1]-1,f[i-2]+v[m][i-1]));
		if(v[m][i]==1)
			g[i]=f[i-1];
		else
			g[i]=max(f[i-1],max(g[i-1]+v[m][i]-1,h[i]));
		if(v[m][i]==2)
			h[i]=max(h[i],g[i]);
		f[i]=max(f[i-1],max(g[i-1]+v[m][i],max(h[i],g[i])));
		//cout<<f[i]<<g[i]<<h[i]<<endl;
	}
	//cout<<f[n]<<endl;
	return f[n];
}
int main()
{
	int n,m,i,l,x,y,ans;
	cin>>l>>ch;//scanf("%d%s",&l,&ch);
	x=0;
	y=0;
	n=0;
	for(i=0;i<l;i=i+1){
		if(ch[i]=='1'){
			if(i&&!x)
				a[++n]=-y;
			x++;
			y=0;
		}
		else{
			if(i&&!y)
				a[++n]=x;
			y++;
			x=0;
		}
	}
	if(x)
		a[++n]=x;
	if(y)
		a[++n]=-y;
	m=0;
	a[0]=-2;
	for(i=0;i<=n;i=i+1){
		if(a[i]<0){
			if(a[i]<=-2)
				v[++m].push_back(0);
		}
		else
			v[m].push_back(a[i]);
	}
	if(v[m].size()<=1)
		m--;
	ans=0;
	for(i=1;i<=m;i=i+1)
		ans+=solve(i);
	cout<<ans<<endl;
	return 0;
}
/*
10
1011101101
*/

Measured memory_bytes: 36864
N, W = map(int, input().split())
VW = [tuple(map(int, input().split())) for _ in range(N)]
dp = [0]*(W+1)
for i in range(N):
    v, w = VW[i]
    for ww in range(W+1):
        if ww >= w:
            dp[ww] = max(dp[ww], dp[ww-w]+v)
print(dp[W])


Measured memory_bytes: 5720
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;

int main(){

   int n, k;
   while(cin >> n >>k){
        if (n % k == 0) cout <<"0"<<endl;
        else cout << "1"<<endl;
        //cout << n % k << endl;
   }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool flag[10000001];

int main(){
    int n=0,ans=0;
	for(int i=0;i <= 1000000;i++){
		if(i<=1)flag[i]=false;
		else flag[i]=true;
	}
	for(int i=2;i <= 1001 ;i++){
		if(flag[i]==true){
			for(int j=i*2 ; j<=1000000 ; j=j+i){
				flag[j] = false;
			}
		}
	}
    while(cin>>n,n){
		ans=0;
		for(int i=2;i <= n/2;i++){
			if(flag[i]&&flag[n-i]){
				ans++;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 2136
N = int(input())

locx = 0
locy =0
time = 0
for i in range(N):
  t,x,y = map(int,input().split())
  nowtime = t-time
  dis = abs(locx-x)+abs(locy-y)
  if (nowtime-dis)<0 :
    print("No")
    exit()
  if (nowtime-dis)%2 == 1:
    print("No")
    exit()
    
  
  time = t
  locx = x
  locy = y
    
  
else :
  print("Yes")

Measured memory_bytes: 9196
#include <bits/stdc++.h>

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int A, B;
    cin >> A >> B;
    
    int cnt = 0;
    int now = 1;
    while(now < B) {
        now = now - 1 + A;
        cnt++;
    }

    cout << cnt << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto S = readln.chomp;
    auto N = S.length.to!int;
    auto ans = new int[](N);

    foreach (i; 0..N-1) {
        if (S[i..i+2] == "RL") {
            int p = i;
            for (int j = i, k = 0; j >= 0 && S[j] == 'R'; --j, k ^= 1) ans[p+k] += 1;
            p = i + 1;
            for (int j = i+1, k = 0; j < N && S[j] == 'L'; ++j, k ^= 1) ans[p-k] += 1;
        }
    }

    ans.map!(to!string).join(" ").writeln;
}


Measured memory_bytes: 4248
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 

vll dp(100100);

ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll a,b;
  	ci(a>>b);
  co(max({a+b,a-b,a*b}))
}

Measured memory_bytes: 1024
def comp(lst1, lst2):
  for v1, v2 in zip(lst1, lst2):
    if v1 < v2:
      return False
    if v1 > v2:
      return True

  return False

while True:
  try:
    plst = list(map(int, input().split()))
    
    horse = [4, 1, 4, 1, 2, 1, 2, 1]
    min_num = 100000
    min_horse = horse[:]
    
    for _ in range(8):
      #乗車不能人数
      num = sum([max(0, plst[j] - horse[j]) for j in range(8)])
      
      #人数が最小値と等しく、並びの数値が小さければ更新
      if num == min_num and comp(min_horse, horse):
        min_horse = horse[:]
      
      #人数が最小値より小さければ更新
      elif num < min_num:
        min_num = num
        min_horse = horse[:]
      
      #馬を回転
      horse.append(horse.pop(0))

    print(" ".join(map(str, min_horse)))

  except EOFError:
    break


Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,i,ans=0;
  cin >> a >> b;
  for(i=a;i<=b;i++){
    string s=to_string(i);
    if(s[0]==s[4] && s[1]==s[3])ans++;    
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	string s;
	cin >> s;
	rep(i, s.size())if (!(i & 1))cout << s[i];
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>

using namespace std;

int main(void)
{
	char op;
	int a, b, result;

	while(true)
	{
		//Read Input
		cin >> a >> op >> b;

		switch(op)
		{
			case '+':
				result = a + b;
				break;
			case '-':
				result = a - b;
				break;
			case '*':
				result = a * b;
				break;
			case '/':
				result = a / b;
				break;
			case '?':
				return 0;
			default:
				cout << "invalid op" << endl;
				return 0;
		}
				
		cout << result << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <vector>
using namespace std;

using Int = int;

struct edge{
  int to;
  Int cap;
  int rev;
};

Int INF = 1 << 30;

struct Ford_Fulkerson{
public:
  vector<vector<edge>> G;
  vector<bool> used;
  int V;

  Ford_Fulkerson(int v){
    V = v;
    G.assign(V,vector<edge>());
    used.assign(V,false);
  }

  void add_edge(int from,int to,Int cap,Int rev_cap = 0){
    G[from].push_back((edge){to,cap,int(G[to].size())});
    G[to].push_back((edge){from,rev_cap,int(G[from].size() - 1)});
  }

  Int dfs(int v,int t,Int f){
    if(v == t) return f;
    used[v] = 1;
    for(auto & e : G[v]){
      if(used[e.to] || e.cap <= 0) continue;
      int d = dfs(e.to,t,min(f,e.cap));
      if(d > 0){
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
    return 0;
  }

  Int ford_fulkerson(int s,int t){
    Int flow = 0;
    Int f;
    while(1){
      used.assign(V,false);
      f = dfs(s,t,INF);
      if(f == 0) return flow;
      flow += f;
    }
  }
};

#include <iostream>

int main(){
  int v,e;
  cin >> v >> e;
  Ford_Fulkerson ff(v);
  for(int i = 0;i < e;i++){
    int u,v;
    Int c;
    cin >> u >> v >> c;
    ff.add_edge(u,v,c);
  }
  cout << ff.ford_fulkerson(0,v - 1) << endl;
}





Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

signed main(void)
{
	int n, m, cnt;
	map<int, int> mp;

	cin >> n >> m;
	cnt = 0;
	rep(i, n)
	{
		int k;
		cin >> k;
		rep(j, k)
		{
			int a;
			cin >> a;
			mp[a]++;
		}
	}
	for(auto p : mp)
	{
		if (p.second == n)
			cnt++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
typedef long long ll;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int main(){
    string s;
    cin >> s;
    int ans = 100000;
    for(int i=0;i<=s.size()-3;i++){
        string str = s.substr(i,3);
        int num = atoi(str.c_str());
        if(abs(num-753)<=ans)ans = abs(num-753);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b,ans=0;
    string p,q,r;
    cin>>p>>q;
    cin>>a>>b;
    cin>>r;
    if(p==r) {a--;}
    else if(q==r) {b--;};
    cout<<a<<" "<<b<<endl;
}



Measured memory_bytes: 256
import math

x=55555


L=math.floor(math.sqrt(x))


#まず、55555以下の素数を列挙




Primelist=[i for i in range(x+1)]

Primelist[1]=0

for i in Primelist:
#    print(i,Primelist)
    
    if i>L:
        break
    if i==0:
        continue
    for j in range(2*i,x+1,i):
        Primelist[j]=0
Primes=[Primelist[j] for j in range(x+1) if Primelist[j]!=0]


Ans=[]

i=0
count=0

while count<=55:
    if Primes[i]%10==1:
        Ans=Ans+[Primes[i]]
        count+=1
        i+=1
    else:
        i+=1
    

N=int(input())

for i in range(N-1):
    print(Ans[i],end=" ")

print(Ans[N])







Measured memory_bytes: 5272
#include<bits/stdc++.h>
#define sc scanf
using namespace std;
const int N=3e5+5;
typedef unsigned long long ull;
typedef long long ll;
template <typename it>int o(it a){cout<<a<<endl;return 0;}
int n;
int a[N];
pair<ll,ll>p[N];
int t=0;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    sort(a+1,a+1+n);
    int pos=-1;
    for(int i=1;i<=n;i++)if(a[i]>=0){pos=i;break;}
    if(pos==-1||a[n]==0){
        ll ans=a[n];
        for(int i=n-1;i>=1;i--){
            p[++t]={ans,a[i]};
            ans-=a[i];
        }
        o(ans);
        for(int i=1;i<=t;i++)cout<<p[i].first<<" "<<p[i].second<<endl;
        return 0;
    }
    if(pos==1){
        ll ans=a[1];
        for(int i=2;i<n;i++){
            p[++t]={ans,a[i]};
            ans-=a[i];
        }
        p[++t]={a[n],ans};
        ans=a[n]-ans;
        o(ans);
        for(int i=1;i<=t;i++)cout<<p[i].first<<" "<<p[i].second<<endl;
        return 0;
    }
    ll ans=a[pos-1];
    for(int i=pos;i<n;i++){
        p[++t]={ans,a[i]};
        ans-=a[i];
    }
    p[++t]={a[n],ans};
    ans=a[n]-ans;
    for(int i=1;i<pos-1;i++){
        p[++t]={ans,a[i]};
        ans-=a[i];
    }
    o(ans);
    for(int i=1;i<=t;i++)cout<<p[i].first<<" "<<p[i].second<<endl;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
ll n,i;
cin>>n>>i;
cout<<n-i+1<<endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define BITBOOL(x,a) (((x)>>(a))&1)
int main(void){
  int A, B, ans = -1;
  cin >> A >> B;
  RPT(i,0,1100){
    if( ((int) (0.08*i))==A && ((int) (0.1*i))==B  ) {ans = i; i = 1000000;}
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include <bits/stdc++.h>

using namespace std;

string s, t;
int n;

int main()
{
	cin>>n;
	cin>>s>>t;
	for(int i = 0; i < n; i ++)
	{
		cout<<s[i]<<t[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
int kk=0;
size_t n;
void dfs(string s){
	if(s.size() == n){
	    kk++;
		cout << s << '\n';
	}
	else{
		char mx = *max_element(ALL(s));
		for(char c = 'a'; c <= mx + 1; ++c){
			dfs(s + c);
		}
	}
}

void mainmain(){
	cin >> n;
	dfs("a");
//	cout<<kk;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


Measured memory_bytes: 1536
num=int(input())
n=input()
m=len(n)
cnt=[0 for i in range(m)]
n1=n[1:]
cnt[0]=n1.count('E')

for i in range(m-1):
    point=0
    if n[i]=='W':
        point+=1
    if n[i+1]=='E':
        point-=1
    cnt[i+1]=cnt[i]+point
    
print(min(cnt))

Measured memory_bytes: 15500
#include <iostream>

using namespace std;

int main(){
  int n, i = 1;
  cin >> n;

  while(i <= n){
    int x = i;
    if(x % 3 == 0) cout << " " << i;
    else{
      while(x){
        if(x % 10 == 3){
          cout << " " << i;
          break;
        }else{
          x /= 10;
        }
      }
    }
    ++i;
  }

  cout << endl;
}
//
//#include <cstdio>
//
//int main(){
//	int n, i=1;
//	scanf(" %d", &n);
//
//	while(i <= n){
//		int x=i;
//
//		if(x%3==0) {
//			printf(" %d", i);
//		}
//		else {
//			while(x){
//				if(x%10==3){
//					printf(" %d", i);
//					break;
//				}
//				else x/=10;
//			}
//		}
//
//		++i;
//	}
//	printf("\n");
//
//	return 0;
//}



Measured memory_bytes: 3116
#include<stdio.h>
int main()
{
  long n;
  scanf("%ld",&n);
  long a[200000];
  for (long i=0 ;i<n;i++) scanf("%ld",&a[i]);
  long result=0;
  for (long i=0;i<n-1;i++) {
    if (a[i]>a[i+1]) {
      result+=a[i]-a[i+1];
      a[i+1]=a[i];
    }
  }
  printf("%ld",result);
  return 0;
}

Measured memory_bytes: 3296
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;++i) cin>>a[i];
  int tmp=0;
  for(int i=0;i<n;++i) tmp+=a[i];
  cout<<tmp-n<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();

    int result = 0;
    for (int i = 1; i < n; i++) {
      for (int j = 1; j <= n / i; j++) {
        if (i * j < n) {
          result++;
        }
      }
    }
    System.out.println(result);
  }
}


Measured memory_bytes: 35660
#include <bits/stdc++.h>
using namespace std;
#define int long long

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

int dp[200002][5];
signed main() {
  int l;
  cin >> l;
  vector<int> a(l + 1);
  REP(i, l) cin >> a[i];
  a[l] = 0;
  REP(i, l + 1) {
    if (i == 0) {
      dp[i][0] = a[i];
      dp[i][1] = a[i] % 2;
      dp[i][2] = 1 - a[i] % 2;
      dp[i][3] = a[i] % 2;
      dp[i][4] = a[i];
    } else {
      dp[i][0] = dp[i - 1][0] + a[i];
      dp[i][1] = min(
        dp[i - 1][0] + (a[i] == 0 ? 2 : a[i] % 2),
        dp[i - 1][1] + (a[i] == 0 ? 2 : a[i] % 2)
      );
      dp[i][2] = min({
        dp[i - 1][0] + (1 - a[i] % 2),
        dp[i - 1][1] + (1 - a[i] % 2),
        dp[i - 1][2] + (1 - a[i] % 2)
      });
      dp[i][3] = min({
        dp[i - 1][0] + (a[i] == 0 ? 2 : a[i] % 2),
        dp[i - 1][1] + (a[i] == 0 ? 2 : a[i] % 2),
        dp[i - 1][2] + (a[i] == 0 ? 2 : a[i] % 2),
        dp[i - 1][3] + (a[i] == 0 ? 2 : a[i] % 2),
      });
      dp[i][4] = min({
        dp[i - 1][0] + a[i],
        dp[i - 1][1] + a[i],
        dp[i - 1][2] + a[i],
        dp[i - 1][3] + a[i],
        dp[i - 1][4] + a[i],
      });
    }
  }
  cout << dp[l][4] << endl;
  /*
  REP(s, 5) {
    REP(i, l + 1) {
      cout << dp[i][s] << "  ";
    }
    cout << "\n";
  }
  */
}

Measured memory_bytes: 9600
#include <iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
int a[maxn];
int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    // list<int> ls;
    // int n;
    gbtb;
    cin>>n;
    repd(i,1,n)
    {
        cin>>a[i];
    }
    int isok=0;
    std::vector<int> ans;
    int len=n;
    while(len)
    {
        int temp=len;
        for(int i=len;i>=1;i--)
        {
            if(a[i]==i)
            {
                ans.push_back(i);
                repd(j,i,len)
                {
                    a[j]=a[j+1];
                }
                len--;
                break;
            }
        }
        if(temp==len)
        {
            break;
        }
    }
    if(len>0)
    {
        cout<<-1<<endl;
    }else
    {
        reverse(ALL(ans));
        for(auto x:ans)
        {
            cout<<x<<endl;
        }
    }



    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 256
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n;
    cin>>n;
    for(int i=1;i<=9;i++){
        if(n%i==0 && ((n/i)>=1 && (n/i)<=9 )){
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int h,w,a[1003][1003],dp[1003][1003];
int main(){
    cin>>h>>w;
    for(int i=1;i<=h;i++)
      for(int j=1;j<=w;j++){
          char x;cin>>x;
          a[i][j]=(x=='.'?1:0);
      }
    for(int i=1;i<=h;i++){
      for(int j=1;j<=w;j++){
          if(i==1&&j==1) dp[i][j]=1;
          else if(i==1) dp[i][j]=(dp[i][j-1]*a[i][j])%mod;
          else if(j==1) dp[i][j]=(dp[i-1][j]*a[i][j])%mod;
          else dp[i][j]=(a[i][j]*(dp[i-1][j]%mod+dp[i][j-1]%mod))%mod;
      }
    }
    cout<<dp[h][w]%mod;
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>

using namespace std;


#define PI 3.14159265
#define int long long


int sqr(int x){
	return x * x;
}

int dis(vector <int> a, vector <int> b){
	int res = 0;

	for(int i = 0; i < a.size(); i++){
		res += sqr(a[i] - b[i]);
	}

	return res;
}

bool is(int n){
	int x = sqrt(n);

	return x * x == n;
}


main(){

	int n, d; cin >> n >> d;


	vector < vector <int> > x(n, vector <int>(d));

	for(int i = 0; i < n; i++){
		for(int j = 0; j < d; j++){
			cin >> x[i][j];
		}
	}


	int ans = 0;

	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			if(is(dis(x[i], x[j]))){
				ans++;
			}
		}
	}

	cout << ans << endl;
	


	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n,vl=0;
	cin>>n;
	int *arr=new int [n];
	for (int i=0;i<n;i++)
		cin>>arr[i];
	for (int i=0,h=1;i<n;i++,h++)
	{
		if (arr[i]%2!=0 && h%2!=0)
		vl++;
	}
	cout<<vl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>

#define all(x) (x).begin(),(x).end()

using namespace std;

int main(){
	int x,a;
	
	cin >> x >> a;
	
	if(x<a)	cout << "0" << endl;
	else	cout << "10" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main(){
  	int a,b;
  	string s,t,u;
	cin >> s >> t >> a >> b >> u;
	
  if(u == s){
  	a = a-1;
    cout << a << " " << b << endl;
  }else{
  	b = b-1;
    cout << a << " " << b << endl;
  }
}


Measured memory_bytes: 256
// {{{ include
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
// }}}


using namespace std;

typedef long long ll;
inline int in(){int x;scanf("%d",&x);return x;}

const int INF = 1 << 29;

struct Edge {
  int from, to;
  int cost;
  int hp;
  Edge(int from, int to, int cost, int hp) : from(from), to(to), cost(cost), hp(hp) {}
  bool operator<(const Edge& e) const { return cost > e.cost; }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int main()
{
  int N, M, L, K, A, H;
  while (cin >> N >> M >> L >> K >> A >> H, N){
    Graph G(N);
    int cold[110] = {};
    int vis[110][110] = {};
    int dist[110][110];
    for (int i = 0; i < N; i++) fill_n(dist[i], M + 1, INF);
    for (int i = 0; i < L; i++){
      int X;
      cin >> X;
      cold[X] = 1;
    }
    for (int i = 0; i < K; i++){
      int X, Y, T;
      cin >> X >> Y >> T;
      G[X].push_back(Edge(X, Y, T, 0));
      G[Y].push_back(Edge(Y, X, T, 0));
    }
    priority_queue<Edge> pq;
    for (pq.push(Edge(-1, A, 0, M)); !pq.empty(); pq.pop()){
      Edge e = pq.top();
      if (vis[e.to][e.hp]++) continue;
      if (cold[e.to]){
        for (auto& v : G[e.to]){
          for (int i = max(e.hp, v.cost); i <= M; i++){
            int ncost = e.cost + v.cost + (i - e.hp);
            int nhp = i - v.cost;
            if (dist[v.to][nhp] <= ncost) continue;
            dist[v.to][nhp] = ncost;
            pq.push(Edge(e.to, v.to, ncost, nhp));
          }
        }
      }
      else {
        for (auto& v : G[e.to]){
          if (e.hp < v.cost) continue;
          if (e.cost + v.cost >= dist[v.to][e.hp - v.cost]) continue;
          dist[v.to][e.hp - v.cost] = e.cost + v.cost;
          pq.push(Edge(e.to, v.to, e.cost + v.cost, e.hp - v.cost));
        }
      }
    }
    int cost = *min_element(dist[H], dist[H] + M + 1);
    if (cost == INF) puts("Help!");
    else printf("%d\n", cost);
  }

  return 0;
}

Measured memory_bytes: 1752
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    vector<int> v(3);
    for (auto &a:v){
        cin >> a;
    }

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

    cout << v[0] + v[1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0; i<n ; ++i)
#define all(v) v.begin() , v.end()
#define sz(v) (int(v.size()))
typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef vector<pii> vp;
int OO = 2e9;
const double eps = 1e-9 ;
const int N = 200;
int mx = -1e9 , mn = 1e9 ;
int arr[N] , arr2[N];

int main()
{
    int a, b, c , x = 0;
    cin >> a >> b >> c;
    int y = min(a,b);
    for(int i = y ; i > 0 ; --i){
        if(a%i == 0 && b %i == 0){
            ++x;
        }
        if(x == c){
            cout << i << endl;
            return 0;
        }
    }


    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
b = gets.split.map &:to_i
a = Array.new(n, 10**5)
for i in 0...n-1
  a[i] = [a[i], b[i]].min
  a[i+1] = [a[i+1], b[i]].min
end
p a.sum

Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll L;
ll A[200050];
ll sum[200050];
ll even[200050];
ll odd[200050];
ll even_after[200050];
ll even_before[200050];
ll odd_after[200050];
ll odd_before[200050];

int main() {
    //cout.precision(10);
    cin >> L;
    for(int i = 1; i <= L; i++) {
        cin >> A[i];
        sum[i] = sum[i - 1] + A[i];
        even[i] = even[i - 1];
        if(A[i] % 2 == 1) even[i]++;
        if(A[i] == 0) even[i] += 2;
        odd[i] = odd[i - 1];
        if(A[i] % 2 == 0) odd[i]++;
    }
    even_before[0] = 0;
    for(int i = 1; i <= L; i++) {
        even_before[i] = min(even_before[i - 1] + (even[i] - even[i - 1]), sum[i]);
        odd_before[i] = min(odd_before[i - 1] + (odd[i] - odd[i - 1]), even_before[i]);
        //cout << i << " " << even_before[i] << " " << odd_before[i] << endl;
    }
    for(int i = L; i >= 1; i--) {
        even_after[i] = min(even_after[i + 1] + (even[i] - even[i - 1]), sum[L] - sum[i - 1]);
        odd_after[i] = min(odd_after[i + 1] + (odd[i] - odd[i - 1]), even_after[i]);
    }
    ll ans = 1e16;
    for(int i = 1; i <= L + 1; i++) {
        ans = min(ans, odd_before[i - 1] + odd_after[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12800
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N,K;
int32_t dist[2000];
std::vector<int32_t> graph[2000];
void func(int n, int p, int d)
{
	dist[n] = d;
	for (auto& i : graph[n])
	{
		if (i == p) { continue; }
		func(i, n, d + 1);
	}
}
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N >> K;
	for (int32_t i = 0; i < N-1; i++)
	{
		int a, b;
		in >> a >> b; --a; --b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	int32_t min = N;
	if (K % 2 == 0)
	{
		for (int32_t i = 0; i < N; i++)
		{
			func(i, i, 0);
			min = std::min<int32_t>(min, std::count_if(dist, dist + N, [](int32_t v) {return v > K / 2; }));
		}
	}
	else
	{
		for (int32_t i = 0; i < N; i++)
		{
			for (auto& j : graph[i])
			{
				func(i, j, 0);
				func(j, i, 0);
				min = std::min<int32_t>(min, std::count_if(dist, dist + N, [](int32_t v) {return v > K / 2; }));
			}
		}
	}
	out << min << endl;

	return 0;
}
#endif


Measured memory_bytes: 512
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    N, Z, W = map(int, input().split())
    a_list = list(map(int, input().split()))

    ans = 0
    ans = max(ans, abs(a_list[-1] - W))
    if N >= 2:
        ans = max(ans, abs(a_list[-2] - a_list[-1]))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3960
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll n,k;
ll ans;
int main()
{
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n >> k;

    if (n % k <= k/2){
        cout << n % k << endl;
    }
    else{
        cout << k - (n % k) << endl;
    }
 
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 2e6 + 10;
const int MAX_Q = 1e3 + 10;

vector<int> g[MAX_N];

int arr[MAX_Q][MAX_Q];
int n;
ll dp[MAX_N], used[MAX_N], ans = 0;

void dfs(int x) {
    if(used[x] == 1) {
        cout << -1 << endl;
        exit(0);
    }
    if(used[x] == 2) {
        return;
    }
    used[x] = 1;
    dp[x] = 1;
    for(auto it : g[x]) {
        dfs(it);
        chkmax(dp[x], dp[it] + 1);
    }
    used[x] = 2;
    chkmax(ans, dp[x]);
}

int ind(int a, int b) {
    if(b < a) {swap(a, b);}
    return a * n + b;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    for(int i = 0; i < n; i ++) {
        for(int j = 0; j < n - 1; j ++) {
            cin >> arr[i][j];
            arr[i][j] --;
        }
    }
    for(int i = 0; i < n; i ++) {
        for(int j = 1; j < n - 1; j ++) {
            g[ind(i, arr[i][j - 1])].push_back(ind(i, arr[i][j]));
        }
    }
    for(int i = 0; i < MAX_N; i ++) {
        dfs(i);
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 98048
void main()
{
    long n, m;
    rdVals(n, m);

    bool[][] path = new bool[][](n, n);
    foreach (i; 0 .. m)
    {
        long a, b;
        rdVals(a, b);
        --a, --b;
        path[a][b] = path[b][a] = true;
    }

    long cnt;
    long[] root = 1.iota(n).array;
    foreach (x; root.permutations)
    {
        long to, from;
        bool ok = true;
        foreach (y; x)
        {
            to = y;
            ok &= path[from][to];
            from = to;
        }
        if (ok) ++cnt;
    }

    cnt.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>

typedef long long ll;
using namespace std;
 
 
ll GreatestCommonDivisor(ll p, ll q)
{
  if ( p < q ) swap( p, q);
  while ( true )
  {
    long long yo = p % q;
    if ( yo == 0 ) return q;
    p = q;
    q = yo;
  }
  return 1;
}
 
//最小公倍数
long long LeastCommonMultiple(ll a, ll b)
{
  return a / GreatestCommonDivisor(a,b) * b;
}
 
 
ll f(ll a)
{
  ll num = 0;
  while ( a > 0 )
  {
    if ( a % 2 == 1) return num;
    ++num;
    a = a / 2;
  }
  return num;
}
 

int main()
{
  int n, m;
  cin >> n >> m;
  
  vector<ll> a(n);
  for ( auto& ai : a) {
    cin >> ai;
    ai /= 2;
  }
 
 
  //ai に 含まれる2の数を計算（同じでないと半公倍数は存在せず）
  ll c = f( a[0] );
  for ( int i = 1; i < n; ++i )
  {
    if ( c != f(a[i])) { 
      cout << 0;
      return 0;
    }
  }
 
  //a の最小公倍数を計算
  ll lcm = a[0];
  for ( ll i = 1; i < n; ++i )
    lcm = LeastCommonMultiple(lcm, a[i]);
 
  // lcm * (2 p - 1) <= M を満たす最大のp
  cout << (m + lcm ) / lcm / 2;
  
  return 0;
}
 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
/*** Template Begins ***/
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
 
// Debug //
 
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

/*** Template Ends ***/
#define N 1000005
int minPrime[N + 1];
vector<int> factorize(int n) {
    vector<int> res;
    while (n != 1) {
        res.push_back(minPrime[n]);
        n /= minPrime[n];
    }
    return res;
}
void solve(){
    for (int i = 2; i * i <= N; ++i) {
        if (minPrime[i] == 0) {         //If i is prime
            for (int j = i * i; j <= N; j += i) {
                if (minPrime[j] == 0) {
                    minPrime[j] = i;
                }
            }
        }
    }
    for (int i = 2; i <= N; ++i) {
        if (minPrime[i] == 0) {
            minPrime[i] = i;
        }
    }
    int n;
    cin>>n;
    int a[n],g;
    rep(i,0,n){
        cin>>a[i];
        if(i==0)g=a[i];
        else
        g=__gcd(g,a[i]);
    }
    unordered_map<int,int> m; int f=1;
    for(int i=n-1;i>=0;i--){
        vi v=factorize(a[i]);
        for(auto j:v)if(m.count(j)!=0){f=0;break;}
        for(auto j:v)if(m.count(j)==0)m[j]++;
    }
    if(f)cout<<"pairwise coprime"<<endl;
    else if(g==1)cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;
}
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 14392
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    if(4*a*b<(c-b-a)*(c-b-a)&&c-b-a>=0)
        cout<<"Yes";
    else
        cout<<"No";

}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String args[]) throws Exception{
		Scanner cin= new Scanner(System.in);
		final int m= cin.nextInt();
		final int n= cin.nextInt();
		
		int[][] A= new int[m][n];
		int[]   b= new int[n];
		int[]   c= new int[m];
		
		int i,j;
		for(i=0;i<m;i++){
			for(j=0;j<n;j++){
				A[i][j]= cin.nextInt();
			}
		}
		for(j=0;j<n;j++){
			b[j]= cin.nextInt();
		}
		
		int k;
		for(i=0;i<m;i++){
			for(k=0;k<n;k++){
				c[i]+= A[i][k]*b[k];
			}
		}
		
		for(i=0;i<m;i++){
			System.out.println(c[i]);
		}
	}
}

Measured memory_bytes: 32040
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<queue>
using namespace std;

typedef long long ll;

int main() {
  string s; cin >> s;
  int A = s[0] -'0';
  int B = s[1] - '0';
  int C= s[2] -'0';
  int D = s[3]-'0';
  if(A+B+C+D==7 )cout<<A<<"+"<<B<<"+"<<C<<"+"<<D<<"=7"<< endl;
  else if(A+B-C-D==7 )cout<<A<<"+"<<B<<"-"<<C<<"-"<<D<<"=7"<< endl;
  else if(A-B+C+D==7 )cout<<A<<"-"<<B<<"+"<<C<<"+"<<D<<"=7"<< endl;
  else if(A-B-C-D==7 )cout<<A<<"-"<<B<<"-"<<C<<"-"<<D<<"=7"<< endl;
  else if(A+B+C-D==7 )cout<<A<<"+"<<B<<"+"<<C<<"-"<<D<<"=7"<< endl;
  else if(A+B-C+D==7 )cout<<A<<"+"<<B<<"-"<<C<<"+"<<D<<"=7"<< endl;
  else if(A-B-C+D==7 )cout<<A<<"-"<<B<<"-"<<C<<"+"<<D<<"=7"<< endl;
  else if(A-B+C-D==7 )cout<<A<<"-"<<B<<"+"<<C<<"-"<<D<<"=7"<< endl;  
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
from itertools import product
from heapq import heappush, heappop

def floyd_warshall(V, E):
    INF = float('inf')
    N = len(V)
    dist = {u: {v: INF for v in V} for u in V}
    for v in V:
        dist[v][v] = 0
        for u, c in E[v].items(): dist[v][u] = c
    for k, i, j in product(V, repeat=3):
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    return dist
        
H, W = map(int, input().split())
E = {i: defaultdict(int) for i in range(10)}
for i in range(10):
    C = map(int, input().split())
    for j, c in enumerate(C):
        E[i][j] = c
A = []
for _ in range(H):
    A += list(map(int, input().split()))
n_num = {i: A.count(i) for i in range(10)}
V = list(range(10))
cost = floyd_warshall(V, E)
print(sum([cost[i][1]*n_num[i] for i in range(10)]))

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
int main()
{
    ll n;
    cin >> n;
    ll now = 7;
    ll ans = -1;
    ll c = 2000000;
    while (c--)
    {
        if (now % n == 0)
        {
            ans = 2000000 - c;
            break;
        }

        now = (now * 10 + 7) % n;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}

		int minT[m][m];
		for(int i=0; i<m; i++){
			for(int j=0; j<m; j++){
				minT[i][j]=T[i][j];
			}
		}

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

					if(minT[i][j]>minT[i][k]+minT[k][j])
						minT[i][j]=minT[i][k]+minT[k][j];
				}
			}
		}

		int d[m];
		for(int i=0; i<m; i++){
			d[i]=0;
			for(int j=0; j<m; j++){
				d[i]=d[i]+minT[i][j];
			}
		}
		

		int min=0;
		for(int i=1; i<m; i++){
			if(d[min]>d[i])
				min=i;
		}

		cout <<min<<' '<<d[min]<<endl;

	}

	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

int main(void)
{
  char s[120];
  int n[30] = {0};
  int i;
  scanf("%s", s);

  for(i = 0; s[i] != '\0'; i++)
    {
      if('a' <= s[i] && s[i] <= 'z')
	n[s[i]-'a']++;
    }
  for(i = 0; i <= 'z'-'a'; i++)
    if(n[i]%2 != 0)
      {
	printf("No\n");
	return 0;
      }

  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 128
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

	public void Proc()
	{
        System.Text.StringBuilder ans = new System.Text.StringBuilder();
        while(true) {
            string inpt = Reader.ReadLine();
            if(inpt == null) {
                break;
            }
            int[] size = inpt.Split(' ').Select(a => int.Parse(a)).ToArray();
            if(size.Count(a=>a<3)>=2) {
                break;
            }
            ans.AppendLine(GetAns(size[0], size[1]));

        }
        Console.Write(ans.ToString());
    }


    private string GetAns(int h, int w) {
        System.Text.StringBuilder ret = new System.Text.StringBuilder();
        for (int i = 0; i < h; i++) {
            if(i==0 || i==h-1) {
                ret.AppendLine("".PadLeft(w, '#'));
            } else {
                ret.AppendLine("#".PadRight(w-1, '.') + "#");
            }
        }
        return ret.ToString();
    }


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"



3 4
5 6
3 3
0 0



";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}

Measured memory_bytes: 9728
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val _A, B = sc.nextLong()
    val A = _A - 1
    val R = new Array[Long](40)

    var i = 0
    while (i < 40) {
      val pow = Math.pow(2, i).toLong
      val a =
        ((A + 1) / pow / 2 * pow) + Math.max(((A + 1) % (2 * pow)) - pow, 0)
      val b =
        ((B + 1) / pow / 2 * pow) + Math.max(((B + 1) % (2 * pow)) - pow, 0)
      R(40 - i - 1) = (b - a) % 2L
      i += 1
    }
    println(java.lang.Long.parseLong(R.mkString(""), 2))
  }

}

Measured memory_bytes: 27444
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>
 
// #include <unordered_set>
// #include <unordered_map>
 
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
 
#define pb push_back
#define mp make_pair
 
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
 
typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;
 
const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
using namespace std;
 
// #define int long long


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cin高速化



    string s;
    cin>>s;

    if(s[0]==s[1]&&s[1]==s[2]){
        cout<<"Yes"<<endl;
    }else if(s[1]==s[2]&&s[2]==s[3]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
 
}

Measured memory_bytes: 256