akhauriyash/Code-Regression huggingface dataset:
/**
*
* Author: MARS
* Lang: GNU C++14
*
**/

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

#define F first
#define S second
#define ii pair<int,int>

typedef long double ldbl;
typedef long long ll;
typedef double dbl;

const ldbl pi = acos(-1);
const ll inf = 1LL<<30;
const dbl eps = 1e-9;
const ll mod = 1e9+7;

/** /////////// ** Code ** /////////// **/

const int N=1000002;
vector<int>pr[N];
bool prime[N];
bool vis[N];
int a[N];

void seive(){

for(int i=2;i<N;i++)prime[i]=1;
prime[0]=prime[1]=0;

for(int i=2;i*i<N;i++)
    if( prime[i] )
        for(int j=i*i;j<N;j+=i)
            prime[j]=0;

}



int main(){

    seive();
    for(int i=2 ; i<N ; i++){
        if(!prime[i]) continue;
        for(int j=i ; j<N ; j+=i)
            pr[j].push_back(i);
    }

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

    bool f=1;
    for(int i=0 ; i<n ; i++){
        for(auto x:pr[a[i]]){
            if(vis[x]){
                f=0;
                break;
            }
            vis[x]=1;
        }
        if(!f) break;
    }


    if(f){
        printf("pairwise coprime");
        return 0;
    }

    int g=a[0];
    for(int i=1 ; i<n ; i++)
        g=__gcd(g, a[i]);

    if(g == 1)
        printf("setwise coprime");
    else
        printf("not coprime");


}


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

typedef long long int ll;
ll n, w;
pair<ll, ll> val[107];
ll dp[100007];

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

    memset(dp, 1000000007, sizeof(dp));
    for(ll i = 0; i < n; ++i) {
        cin >> val[i].first >> val[i].second;
    }

    ll cur = 0;

    dp[0] = 0;
    for(ll i = 0; i < n; ++i) {
        for(ll j = cur; j >= 0; --j) {
            dp[j + val[i].second] = min(dp[j + val[i].second], dp[j] + val[i].first);
        }
        cur += val[i].second;
    }

    ll ans = cur;
    //cout << dp[ans] << endl;
    while(dp[ans] > w) {
        ans--;
    }

    cout << ans << endl;
    return 0;
}

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

int main() {
  int n,x;
  cin >>n;
  vector<int>a(n+1);
  vector<int>b(n+1);
  for(int i=1;i<=n;i++){
    cin>>a.at(i);
    b.at(i)=a.at(i);
  }
  sort(a.begin(),a.end());
  x=n/2;
  for(int i=1;i<=n;i++){
    //cout<<b.at(i)<<" "<<a.at(x)<<" "<<a.at(x+1)<<endl;
    if(b.at(i)<=a.at(x)){
      cout<<a.at(x+1)<<endl;
    }else{
      cout<<a.at(x)<<endl;
    }
  }  
  return 0;
}

Measured memory_bytes: 3840
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()
typedef tuple<int, int, int> t3;

int N, h[110];
ll d[110][210];
const ll MOD = 1e9 + 7;
ll pw(int x, int y) {
	ll res = 1;
	while(y) {
		if(y & 1) res = res * x % MOD;
		x = (ll)x * x % MOD;
		y >>= 1;
	}
	return res;
}

ll get_pw2(int l, int r) {
	ll val = pw(2, r + 1);
	val = (val + MOD - pw(2, l)) % MOD;
	return val;
}

vector <int> hv;
pii get_seg(int v) {
	if(v == 1) return pii(1, hv[0] - 1);
	if(v % 2 == 0) return pii(hv[v/2-1], hv[v/2-1]);
	else return pii(hv[v/2-1] + 1, hv[v/2] - 1);
}

void solve(){
	scanf("%d", &N);
	for(int i=1;i<=N;i++) scanf("%d", h+i);
	for(int i=1;i<=N;i++) hv.pb(h[i]);
	sort(all(hv)); hv.resize(unique(all(hv)) - hv.begin());
	for(int i=1;i<=N;i++) h[i] = (int)(lower_bound(all(hv), h[i]) - hv.begin());
	for(int i=1;i<=2*h[1]+2;i++) {
		pii s = get_seg(i);
		if(s.Fi <= s.Se) {
			int lv = hv[h[1]] - s.Se;
			int rv = hv[h[1]] - s.Fi;
			d[1][i] = get_pw2(lv, rv);
		}
		if(i == 2*h[1]+2) d[1][i] = (d[1][i] + 1) % MOD;
	}
	for(int i=1;i<N;i++) {
		if(h[i] >= h[i+1]) {
			for(int j=1;j<=2*h[i+1]+1;j++) {
				d[i+1][j] = (d[i+1][j] + d[i][j]) % MOD;
			}
			ll sum = 0;
			for(int j=2*h[i+1]+2;j<=2*h[i]+2;j++) {
				sum = (sum + d[i][j]) % MOD;
			}
			d[i+1][2*h[i+1]+2] = (d[i+1][2*h[i+1]+2] + sum * 2) % MOD;
		}
		else {
			for(int j=1;j<=2*h[i]+1;j++) {
				d[i+1][j] = (d[i+1][j] + (ll)pw(2, hv[h[i+1]] - hv[h[i]]) * d[i][j]) % MOD;
			}
			for(int j=2*h[i]+2;j<=2*h[i+1]+2;j++) {
				pii s = get_seg(j);
				int lv = hv[h[i+1]] - s.Se;
				int rv = hv[h[i+1]] - s.Fi;
				ll val = get_pw2(lv, rv);
				if(j == 2*h[i+1]+2) val = 2;
				d[i+1][j] = (d[i+1][j] + val * d[i][2*h[i]+2]) % MOD;
			}
		}
	}
	
	ll sum = 0;
	rep(i, 210) sum = (sum + d[N][i]) % MOD;
	printf("%lld\n", sum);
}

int main(){
	int Tc = 1; //scanf("%d", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 384
# N, K = gets.chomp.split.map(&:to_i)
# A = gets.chomp.split.map(&:to_i)

N = gets.chomp.to_i
p = gets.chomp.split.map(&:to_i)

r = 0
1.upto(p.size - 2).each do |i|
  if p[i-1] < p[i] && p[i] < p[i+1]
    r += 1
    next
  end
  
  if p[i+1] < p[i] && p[i] < p[i-1]
    r += 1
    next
  end
end

p r
    

Measured memory_bytes: 1788
import java.util.*;

public class Main{ 

   public static void main(String args[]) {
	 
    Scanner s=new Scanner(System.in);
    
    	int n=s.nextInt();
    	long h[]=new long[n];
    	for(int i=0;i<n;i++) {
    		h[i]=s.nextLong();
    	}
    	long dp[]=new long[n];
    	dp[0]=0;
    	dp[1]=Math.abs(h[1]-h[0]);
    	
    	for(int i=2;i<n;i++) {
    		long op1=dp[i-1] + Math.abs(h[i]-h[i-1]);
    		long op2=dp[i-2] + Math.abs(h[i]-h[i-2]);
    		dp[i]=Math.min(op1, op2);
    	}
    	System.out.println(dp[n-1]);
    	
    }

}

Measured memory_bytes: 60336
N,Y = map(int,input().split())

break_loop=False
for a in range(N+1):
    for b in range(N+1-a):
        c = N-a-b
        if 10000*a + 5000*b + 1000*c == Y:
            print(a,b,c)
            break_loop=True
            break
    if break_loop:
        break
    else:
        continue
else:
    print(-1,-1,-1)

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

#define int long long int 

int32_t main()
{

        int n,k;
        cin>>n>>k;
        int a[n];
        for(int i=0;i<n;i++)
        cin>>a[i];
        cout<<1+(n-k+k-2)/(k-1)<<endl;
}

Measured memory_bytes: 4376
def main():
    k = int(input())
    xl = [[] for i in range(11)]
    xl[0] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    if k < 10:
        print(xl[0][k-1])
        return 
    k -= 9
    for i in range(1, 11):
        pl = []
        for x in xl[i-1]:
            m = x%10
            if m == 0:
                for mi in range(m, m+2):
                    pl.append(10*x+mi)
                k -= 2
            elif m == 9:
                for mi in range(m-1, m+1):
                    pl.append(10*x+mi)
                k -= 2
            else:
                for mi in range(m-1, m+2):
                    pl.append(10*x+mi)
                k -= 3
            if k <= 0:
                print(pl[k-1])
                return
        xl[i] = pl

if __name__ == "__main__":
    main()

Measured memory_bytes: 7256
N = int(input())
points = []
for _ in range(N):
    points.append([int(s) for s in input().split()])
def dist(x, y):
    return abs(x[0] - y[0]) + abs(x[1] - y[1])
points.sort(key=lambda x: x[0] + x[1])
d1 = dist(points[0], points[-1])
# print(points)
points.sort(key=lambda x: x[0] - x[1])
d2 = dist(points[0], points[-1])
# print(points)
print(max(d1, d2))

Measured memory_bytes: 52004
#include <stdio.h>
int main(int argc, char *argv[])
{
	int k,x;
	int i;
	scanf("%d%d",&k,&x);
	for(i=x-k+1;i<x+k-1;i++)
	{
		printf("%d ",i);
	}
	printf("%d\n",x+k-1);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int  long long
#define tc(t)  int t; cin>>t; while(t--)
#define f(n)    for(int i=0;i<n;i++)
#define endl   "\n"
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

int n;
cin>>n;
vector<int> v(n);
int sum=0;
      f(n)cin>>v[i];
      for(int i=0;i<n-1;i++)
      {
          for(int j=i+1;j<n;j++)
          {
              sum+=(v[i]*v[j]);

          }


      }
      cout<<sum<<endl;


}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main() {
  int X;
  cin >> X;
  
  int answer = 0;

  int right = 0;
  int i = 1;

  while (true) {
    right += i;
//     if (place == X) {
    if (X <= right) {
      answer = i;
      break;
    }
    i++;
  }

  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
		char s[10];
		bool flag[] = {false,false,true};
		int n = 0;

		scanf("%s",s);



		if(s[0] == 'A') flag[0] = true;

		for(int i=0 ; s[i] != '\0' ; ++i){
				++n;
		}

		for(int i=2 ; i<n-1 ; ++i){
				if(s[i] == 'C'){
						if(flag[1] == false) flag[1] = true;
						else flag[2] = false;
				}
				else if(!((s[i]>='a')and(s[i]<='z'))) flag[2] = false;
		}


		if(!((s[1]>='a')and(s[1]<='z'))) flag[2] = false;
		if(!((s[n-1]>='a')and(s[n-1]<='z'))) flag[2] = false;

		if((flag[0] == true) && (flag[1] == true) && (flag[2] == true)) printf("AC\n");
		else printf("WA\n");

		return 0;
}


Measured memory_bytes: 256
import math

N = int(input())

P = list(map(int, input().split()))
Q = list(map(int, input().split()))


def rank(l):
    ll = sorted(l)
    return ll.index(l[0])

ans1 = 0
ans2 = 0
for i in range(N-1):
    ans1 = ans1 + rank(P) * math.factorial(N - i - 1)
    P = P[1:N]
    ans2 = ans2 + rank(Q) * math.factorial(N - i - 1)
    Q = Q[1:N]

if (ans1 - ans2 < 0):
    print(ans2 - ans1)
else:
    print(ans1 - ans2)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int a, g, i, sum= 0, baki_ace, k, z;
    scanf("%d%d", &a, &g);
    int arr[a];
    for(i= 0; i<a; i++)
    {
        scanf("%d", &arr[i]);
        sum+= arr[i];
    }
    baki_ace= g-sum;
    int min= arr[0];
    
    for(i=0; i<a; i++)
        if(arr[i]<min)
            min= arr[i];
 
    z= baki_ace/min;
    k= z+a;

    printf("%d\n", k);
    return 0;

}

// Author: Sorowar Mahabub



Measured memory_bytes: 1688
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
#define MAX 100010
#define aout(a) REP(i,sizeof(a)) cout << a[i] << " "; cout << endl;
#define vout(v) REP(i,v,size()) cout << v[i] << " "; cout << endl;
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(){
  int N,X,T; cin>>N>>X>>T;
  int ans = 0;
  while(N > X*ans){
    ans++;
  }
  cout << ans*T;
}

Measured memory_bytes: 3640
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = 0;
		int max = sc.nextInt();
		int index[] = new int[101];
		int backet[] = new int[101];
		int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
		for(int i = 1; i <= max; i ++) {
			for(int j = 0; j < prime.length; j ++) {
				int crt = i;
				while(crt % prime[j] == 0) {
					index[prime[j]] ++;
					crt /= prime[j];
				}
			}
		}
		for(int i = 0; i < 101; i ++) {
			backet[index[i]] ++;
		}
		int a[] = new int[5];//2,4,14,74
		int b[] = {2, 4, 14, 24, 74};
		for(int i = 0; i < 5; i ++) {
			for(int j = b[i]; j < 101; j ++) {
				a[i] += backet[j];
			}
		}
		count = (a[0] - 2) * (a[1] - 1) * a[1] / 2
			+ (a[0] - 1) * a[3]
			+ (a[1] - 1) * a[2]
			+ a[4];
		System.out.println(count);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 2005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans;
int N,X,Y;
map<int, int> mp;

int d[MAXN][MAXN];

// void warshall_floyd() {
//     for(int i = 0; i < N; i++) {
//         for(int j = i+1; j < N; j++) {
//             for(int k = 0; k < N; k++) {
//                     d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
//                     d[j][i] = d[i][j];
//             }
//         }
//     }

// }

int calc_dist(int i, int j){
    if(i == X && j == Y) return 1;

    if( (i <= X && j <= X) || ( Y <= i && Y <= j))
        return abs(i - j);
    else {
        int tmp = abs(X - i) + 1 + abs(Y - j);

        return min(abs(i - j), tmp);
    }    
}

void solve(){
    rep(i, N){
        for(int j = i+1; j < N; ++j){
            // cout << "Node " << i << " to " << j << ": " << d[i][j] << endl;
            mp[calc_dist(i, j)]++;
        }
    }

    // for(auto itr = mp.begin(); itr!=mp.end(); ++itr){
    //     cout << itr->first << " " << itr->second << endl;
    // }

    auto itr = mp.begin();
    for(int i = 1; i < N; ++i){
        if(itr->first == i){
            cout << itr->second << endl;
            ++itr;
        } else
            cout << 0 << endl;
    }
 

}

int main(){
    cin >> N >> X >> Y;
    --X, --Y;

    rep(i, N)
        fill(d[i], d[i]+N, INF);

    rep(i, N-1){
        d[i][i] = 0;
        d[i][i+1] = 1;
        d[i+1][i] = 1;
    }

    d[X][Y] = 1;
    d[Y][X] = 1;

    solve();
}


Measured memory_bytes: 16000
#include <iostream>

using namespace std;

int main(void){
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    int left=0;
    int right=0;

    cin >> a >> b >> c >> d;

    left=a+b;
    right=c+d;

    if(left>right)cout << "Left" << endl;
    else if(right>left)cout << "Right" << endl;
    else cout << "Balanced" << endl;

    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++) cin >> h[i];
    
    int hight = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (hight <= h[i]) {
            ans++;
            hight = h[i];
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 384
n=int(input())

c=[[0]*10 for i in range(10)]

for i in range(1,n+1):
    t=str(i)
    c[int(t[0])][int(t[-1])]+=1
    
ans=0
for i in range(10):
    for j in range(10):
        ans+=c[i][j]*c[j][i]
        
print(ans)

Measured memory_bytes: 40428
// problem: "https://atcoder.jp/contests/keyence2020/tasks/keyence2020_a"

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int h,w,n;
    cin>>h>>w>>n;

    h = max(h,w);
    if(n%h)
        cout<<n/h+1;
    else
        cout<<n/h;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main () {
	char name;
	scanf ("%c",&name);
	if (name >='a'&&name<='z') {
		printf("a");
	//	printf("\n%c is lowercase, so we should print a.",name);
	} else if (name >='A'&&name<='Z') {
		printf("A");
		//	printf("\n%c is uppercase, so we should print A.",name);
	}

	return 0;
}








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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

int main(void){
    ll N; cin >> N;
    vector<ll> A(N); REP(i,N) cin >> A[i];
    vector<ll> S(N+1); S[0] = 0; REP(i,N) S[i+1] = S[i] + A[i];

    vector<ll> F(N-3,0), G(N-3,0);
    F[0] = 1;
    REP(i,N-4){
        int t = F[i];
        while(abs(S[i+3]-S[t]-S[t]) > abs(S[i+3]-S[t+1]-S[t+1])) t++;
        F[i+1] = t;
    }
    G[N-4] = N-1;
    REP(i,N-4){
        int t = G[N-4-i];
        while(abs(S[N]-S[t]-(S[t]-S[N-3-i])) > abs(S[N]-S[t-1]-(S[t-1]-S[N-3-i]))) t--;
        G[N-5-i] = t;
    }
    ll ans = LL_INF;
    REP(i,N-3){
        ll p = S[F[i]];
        ll q = S[i+2] - S[F[i]];
        ll r = S[G[i]] - S[i+2];
        ll s = S[N] - S[G[i]];
        chmin(ans, max(max(p,q),max(r,s))-min(min(p,q),min(r,s)));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for (int i=0; i < n; i++)
#define repran(i, a,b) for (int i = a; i<b;i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using LP = pair<ll,ll>;
using P = pair<int,int>;
const int N = 500010;

int dat[N];
void init(){
    rep(i, N) dat[i] = 0;
}

void add(int i, int x){
    for (;i<=N;i+=i&-i) dat[i]+=x;
}

int sum(int i){
    int s= 0;
    for (;i>0;i-=i&-i) s+= dat[i];
    return s;
}

int query(int l, int r){
    return sum(r)-sum(l-1);
}


int main()
{
    int n, q;
    cin >> n >> q;
    vector<int> c(n+1, 0), cset(n+1, 0);
    vector<vector<P>> que(n+1, vector<P>());
    vector<int> ans(q, 0);
    rep(i, n) cin >> c[i+1];
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        que[r].emplace_back(i, l);
    }
    init();
    repran(i, 1, n+1){
        if (cset[c[i]] > 0) add(cset[c[i]], -1);
        add(i, 1);
        cset[c[i]]=i;
        for (P p : que[i]) ans[p.first] = query(p.second, i);
    }
    rep(i, q) cout << ans[i] <<endl; 
}

Measured memory_bytes: 33240
class Dice(object):
    def __init__(self,num):
        self.f=num[0]
        self.s=num[1]
        self.e=num[2]
        self.w=num[3]
        self.n=num[4]
        self.b=num[5]
    def create(self,order):
        if order=='N':
            return [self.s,self.b,self.e,self.w,self.f,self.n]
        elif order=='S':
            return [self.n,self.f,self.e,self.w,self.b,self.s]

        elif order=='E':
            return [self.w,self.s,self.f,self.b,self.n,self.e]
        else:
            return [self.e,self.s,self.b,self.f,self.n,self.w]
    @classmethod
    def Dice_create(cls,num):
            return cls(num)


num=list(map(int,input().split()))
command=input()
dice=Dice(num)
for i in range(len(command)):
    temp=dice.create(command[i])
    dice=Dice.Dice_create(temp)
print(dice.f)

Measured memory_bytes: 7792
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    ll n,m;
    cin>>n>>m;
    if(n==1&&m==1){
        cout<<1<<endl;
        return 0;
    }
    if(n==1||m==1){
        cout<<max(n,m)-2;
        return 0;
    }
    cout<<(n-2)*(m-2)<<endl;
}

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

const int N=10,M=1e3+1;

int n,m,k,ans=INT_MAX;
char a[N][M];

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

	for(int mask=0;mask<(1<<(n-1));mask++)
	{
		int rows=__builtin_popcount(mask)+1,cuts=rows-1;
		vector <int> dp(rows,0);
		bool invalid=false;
		for(int j=0;j<m and not invalid;j++)
		{
			bool ok=true;
			for(int i=0,ptr=0;i<n and ok;i++)
			{
				if(a[i][j]=='1') dp[ptr]++;
				if(dp[ptr]>k) ok=false;
				if(mask&(1<<i)) ptr++;
			}

			if(not ok)
			{
				cuts++;
				for(int i=0;i<rows;i++) dp[i]=0;
				ok=true;
				for(int i=0,ptr=0;i<n and ok;i++)
				{
					if(a[i][j]=='1') dp[ptr]++;
					if(dp[ptr]>k) ok=false;
					if(mask&(1<<i)) ptr++;
				}
				if(not ok)
				{
					invalid=true;
					break;
				}
			}
		}

		if(not invalid) ans=min(ans,cuts);
	}

	printf("%d",ans);
}

Measured memory_bytes: 3800
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;

int main()
{
	FAST;
	int w,h,n;
	cin >> w >> h >> n;
	
	int maxx=0 , minx = w;
	int maxy=0 , miny = h;

	while(n--)
	{
		int x,y,a;
		cin >> x >> y >> a;
		
		if(a == 1)
		{
			maxx = max(maxx , x);
		}
		else if(a == 2)
		{
			minx = min(minx , x);
		}
		else if(a == 3)
		{
			maxy = max(maxy , y);
		}
		else
		{
			miny = min(miny , y);
		}
	}
	if(maxx >= minx)
	    maxx = minx = 0;
	if(maxy >= miny)
	    maxy = miny = 0;
	int ans = (minx-maxx)*(miny-maxy);
	if(ans < 0)
	    ans = 0;
	cout << ans  << "\n";

	return 0;
}

Measured memory_bytes: 256
n = int(input())
t = list(map(int, input().split()))
m = int(input())

for i in range(m):
    p, x = map(int, input().split())

    total = 0
    for j in range(n):
        if j == (p - 1):
            total += x
        else:
            total += t[j]
    print(total)

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

int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    int temp = pow(10,(int)(log10(b)+1))*a+b;
    int sq = sqrt(temp);
    if(temp%sq){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
}


Measured memory_bytes: 512
import java.util.*;

public class Main{

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int t = sc.nextInt();
			int e = sc.nextInt();
			int [] data = new int[n];
			for(int i = 0; i < n; i++){
				data[i] = sc.nextInt();
			}
			int ans = -1;
			for(int i = 0; i <n; i++){
				int x = data[i];
				for(int j = 1;; j++){
					int value = x * j;
					if(value > e + t) break;
					if(t - e <= value && value <= t + e){
						ans = i + 1;
						break;
					}
				}
				if(ans >= 0) break;
			}
			System.out.println(ans);
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 18312
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    int X;
    cin >> X;
    int a[47];

    for(int i = 1; i <= 31; i++) {
        a[i-1] = i*i;
    }

    for(int i = 31; i <= 39; i++) {
        int j = i - 29;
        a[i] = j*j*j;
    }

    for(int i = 40; i <= 43; i++) {
        int j = i - 38;
        a[i] = j*j*j*j;
    }

    a[44] = 32;
    a[45] = 243;
    a[46] = 128;

    sort(a, a+47);

    int i;
    for(i = 0; i < 47; i++) {
        if(X < a[i]) {
            break;
        }
    }

    if(X == 1000) {
        cout << 1000;
    }
    else {
        cout << a[i-1];
    }

    cout << endl;
    return 0;
}

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

int main() {
  
  int N, K;
  cin >> N >> K;
  int ans;
  ans = 1;
  
  for (int i = 0; i < N; i++) { 
    int A = 0, B = 0;
    A = ans * 2; 
    B = ans + K;
      
    if (A <= B) {
      ans *= 2;
    }
    else {
      ans += K;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
                       ///****   Hasebul Hassan Chowdhury ***////
#define ms(a,v)        memset(a,v,sizeof a)
#define lll            long long
#define FOR(i,a,b)     for(int i=a;i<=b;i++)
#define fast           ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Read           freopen("input.txt", "r", stdin)
#define Write          freopen("output.txt", "w", stdout)
#define INF            1e18

vector<lll>Array;
vector<lll>Brray;
void solve()
{
   int n,m,k,x;
   lll ans=0;
   cin>>n>>m>>k;
   Array.push_back(0);
   Brray.push_back(0);
   FOR(i,1,n) { cin>>x; Array.push_back(Array[i-1]+x); }
   FOR(j,1,m) { cin>>x; Brray.push_back(Brray[j-1]+x); }
   FOR(i,0,n)
   {
       lll rem=k-Array[i];
       lll id;
       id=upper_bound(Brray.begin(), Brray.end(), rem)-Brray.begin();
       if(id-1>=0) ans=max(ans,(i+(id-1)));
       //ans=max(ans,(i+(id-1)));
   }
   cout<<ans<<endl;
}


int main()
{
    fast
    #ifndef ONLINE_JUDGE
    //Read;
    //Write;
    #endif
    //int t; cin>>t; while(t--) solve();
    solve();

}


Measured memory_bytes: 7888
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

int main()
{
    int n,x,m=0;
    cin>> n;
    for(int i=1;i<=n;i++){
        cin>> x;
        if(i&1) m+=(x&1);
    }
    cout<< m <<endl;
    return 0;
}

Measured memory_bytes: 3632
n=int(input())
c=list(range(1,1+2*n))
for _ in[0]*int(input()):
    k=int(input())
    if k:c=c[k:]+c[:k]
    else:
        for a,b in zip(c[:n],c[n:]):
            c+=[a,b]
        c=c[2*n:]
for x in c:print(x)


Measured memory_bytes: 5620
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int c=0;
  int l=0;
  for(int i=1;i<s.size();i++){
    if(s.at(i)>='a')
      l++;
    if(i>1&&i<s.size()-1&&s.at(i)=='C')
      c++;
  }
  cout<<(s.at(0)=='A'&&c==1&&l==s.size()-2?"AC":"WA")<<endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>
#include<queue>
#include<cmath>

using namespace std;

typedef long long int64;

int main(void){
    int64 A,V,B,W,T;
    cin>>A>>V>>B>>W>>T;

    if(A<B){
        if(A+V*T<B+W*T){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    if(A>B){
        if(A-V*T>B-W*T){
            cout<<"NO"<<endl;
            return 0;
        }
    }

    cout<<"YES"<<endl;

    return 0;
}

Measured memory_bytes: 3624
from collections import defaultdict
def main():
    N, M = [int(i) for i in input().split()]
    L = [[] for _ in range(M+1)]
    for i in range(N):
        for j in map(int, input().split()[1:]):
            L[j].append(i)
    uf = UnionFind()
    for i, l in enumerate(L):
        #print("Lang {}".format(i))
        if not l:
            continue
        a = l[0]
        for b in l[1:]:
            #print(a, b)
            uf.union(a, b)
    # print(uf.table)
    print("YES" if uf.size(0) == N else "NO")
    

class UnionFind(object):

    def __init__(self):
        self.table = defaultdict(lambda: -1)

    def find(self, x):
        if self.table[x] < 0:
            return x
        self.table[x] = self.find(self.table[x])
        return self.table[x]

    def size(self, x):
        return -self.table[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 == s2:
            return False
        if self.table[s1] > self.table[s2]:
            s1, s2 = s2, s1
        self.table[s1] += self.table[s2]
        self.table[s2] = s1
        return True

if __name__ == "__main__":
    main()


Measured memory_bytes: 91424
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int A1, A2, A3;
        A1 = input.nextInt();
        A2 = input.nextInt();
        A3 = input.nextInt();
        if ((A1+A2+A3)>=22)
        System.out.print("bust\n");
        else System.out.print("win\n");
    }
}


Measured memory_bytes: 35828
#include <iostream>
#include <vector>
#include <map>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;


int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int tmp = min(x, y);
  ll ans = min(a+b, 2*c) * tmp;
  if(x > y){
    ans += min(2*c, a) * (x-y);
  }else{
    ans += min(2*c, b) * (y-x);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
s_line = gets.chomp
p_line = gets.chomp
check = 0

(s_line.length).times do
  if s_line.include?(p_line)
    check = 1
    break
  else
    tmp = s_line.slice!(0)
    s_line << tmp
    # puts s_line
    tmp = ''
  end
end

if check == 1
  puts "Yes"
else 
  puts "No"
end



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

#define all(x) 		 (x).begin(),(x).end()
#define mp     		 make_pair
#define pb 				 push_back
#define fi 				 first
#define se 				 second
#define sz(x) 		 ((int)(x).size())
#define rep(x,y,z) for(int x=y;x<z;x++)
#define per(x,z,y) for(int x=z-1;x>=y;x--)
#define trav(y,x)  for(auto& y:x)
#define pii 			 pair<int,int>
#define vi 				 vector<int>

int dbg = 0;
#define cri   		 if(1)
#define shame 		 cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
const int N = 2e5 + 1;
const int lg = 20;
const ll mod = 998244353;

void solve() {
  int n, s;
  cin >> n >> s;
  vi a(n);
  rep(i, 0, n)
    cin >> a[i];

  ll x = 0;
  vector<ll> dpA(s + 1, 0); dpA[0] = 1ll;
  vector<ll> dpR(s + 1, 0); dpR[0] = 1ll;
  per(i, n, 0) {
    if (a[i] > s) continue;

    bool upd = 0;
    ll right = 0;
    per(j, s + 1, a[i] + 1) {
      if (dpA[j - a[i]]) {
        if (j == s) {
          upd = 1;
          right = dpR[j - a[i]];
        }

        dpA[j] += dpA[j - a[i]];
        dpA[j] %= mod;

        dpR[j] += dpR[j - a[i]];
        dpR[j] %= mod;
      }
    }
    if (a[i] == s) {
      upd = 1;
      right = n - i;
    }
    dpA[a[i]]++; dpA[a[i]] %= mod;
    dpR[a[i]] += (n - i); dpR[a[i]] %= mod;

    if (upd) {
      ll left = i + 1;
      ll add = (left * right) % mod;
      x += add; x %= mod;
    }
  }
  cout << x << "\n";
}

int main() {
  // freopen("input.in", "r", stdin);
  // freopen("input.out", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// cout<<setprecision(15);
	// int t; cin>>t; while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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;
}

struct UnionFind{
    int num;
    vector<int> par,rank;
    UnionFind(int n):num(n),par(n),rank(n,1){
        iota(all(par),0);
    }
    int root(int x){
        if (par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    bool merge(int x, int y){
        x=root(x),y=root(y);
        if (x==y) return false;
        if (rank[x]<rank[y]) swap(x,y);
        par[y]=x;
        rank[x]+=rank[y];
        --num;
        return true;
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    int size(int x){
        return rank[root(x)];
    }
    int count(){
        return num;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M,Q; cin >> N >> M >> Q;
    UnionFind uf(N);
    vector<Pii> query;
    rep(i,Q){
        int a,b,c; cin >> a >> b >> c;
        if (!c) uf.merge(a,b);
        else query.emplace_back(a,b);
    }
    set<int> pars;
    ll minimum=0,maximum=0;
    rep(i,N){
        if (pars.count(uf.root(i))) continue;
        pars.insert(uf.root(i));
        minimum+=(ll)uf.size(i)-1,maximum+=(ll)uf.size(i)-1;
    }
    for (auto p:query){
        if (uf.same(p.first,p.second)){
            cout << "No" << endl;
            return 0;
        }
        if (uf.count()<3){
            cout << "No" << endl;
            return 0;
        }
    }
    ll s=uf.count();
    minimum+=s,maximum+=s*(s-1)/2;
    if (!query.size()) --minimum;
    if (minimum<=M&&M<=maximum) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 6516
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
class UnionFind
{
public:
  int par[100005];
  int depth[100005];
  int nGroup[100005];
 
  UnionFind(int n) {
    init(n);
  }
 
  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }
 
  int root(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
 
  bool same(int x, int y) {
    return root(x) == root(y);
  }
 
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
 
    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    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;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
ll n,m; cin>>n>>m;
ll ca = 0;
map<ll,ll> a;
rep(i,m){
ll r,l; cin>>r>>l;
if(a[l]>0){
a[l]=max(a[l],r);}
else
a[l]=r;}
ll k = -INF;
for(auto p : a){
if(k<=p.se){
ca++;
k = p.fi;
continue;}
}
cout << ca << endl;}


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

using namespace std;
using ll = long long;
#define N (ll)(1e9+7)
ll mypower(ll a, ll b, ll mod = N)
{
    ll ans = 1;
    while(b)
    {
        if(b%2)
            ans = (ans*a)%mod;
        b=b/2;
        a=(a*a)%mod;
    }
    return ans;
}
bool comp(pair<ll,ll> a, pair<ll,ll> b)
{
    return a.first > b.first;
}
int main() {
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5])
        cout << "Yes" << '\n';
    else
        cout << "No" << '\n';
    
}

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

using namespace std;

int main(){
	int n, t;
	cin >> n >> t;
	int maxi = 0;
	int g = 0;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		maxi = max(maxi, a);
		g = __gcd(g, a);
	}
	if(t <= maxi && t % g == 0) cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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; }


int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

vector<int> edges[101010],from[101010];
int indeg[101010];
int dist[101010],par[101010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;cin>>N>>M;
    REP(i,N-1+M){
        int a,b;
        cin>>a>>b;
        indeg[b]++;
        edges[a].push_back(b);
        from[b].push_back(a);
    }
    int root=-1;
    for(int i=1;i<=N;i++) if(indeg[i]==0) root=i;
    par[root]=0;
    dist[root]=0;
    queue<int> que;
    que.push(root);
    while(que.size()){
        int i=que.front();que.pop();
        for(int j:from[i]){
            if(dist[j]+1>dist[i]){
                par[i] = j;
                dist[i] = dist[j]+1;
            }
        }
        for(int j:edges[i]){
            indeg[j]--;
            if(indeg[j]==0) que.push(j);
        }
    }
    for(int i=1;i<=N;i++) cout<<par[i]<<endl;
}


Measured memory_bytes: 13056
N = input()
zyunin_list = [int(i) for i in input().split()]

cost_list = []

for p in range(min(zyunin_list), max(zyunin_list) + 1):
    cost = 0
    for zahyo in zyunin_list:
        cost += (zahyo - p) ** 2
    cost_list.append(cost)

print(min(cost_list))

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

using namespace std;

int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if(b<a){
		swap(a,b);
	}
	if((b-a)%2){
		printf("IMPOSSIBLE\n");
		return 0;
	}
	printf("%d\n",a+(b-a)/2);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

struct  Card {
    char mark;
    char val;
};

void BubbleSort(Card array[], int len) {
    int i, j;
    Card tmp;
    for (i = 0; i < len; i++) {
        for (j = (len - 1) ; j > i; j--) {
            if (array[j - 1].val > array[j].val) {
                tmp = array[j]; array[j] = array[j-1]; array[j-1] = tmp; 
            }
        }
    }
}

void SelectionSort(Card array[], int len) {
    int i, j, minj;
    Card tmp;
    for (i = 0; i < len; i++) {
        minj = i;
        for (j = (i + 1); j < len; j++) {
            if (array[j].val < array[minj].val) {
                minj = j;
            }
        }
        tmp = array[i]; array[i] = array[minj]; array[minj] = tmp;
    }

}

void Print(Card array[], int len) {
    int i;
    for (i = 0; i < len; i++) {
        if (i > 0) {
            printf(" ");
        }
        printf("%c%c", array[i].mark, array[i].val);
    }
    printf("\n");

}

int isStable(Card C1[], Card C2[], int n) {
  int i;
  for (i = 0; i < n; i++) {
    if (C1[i].mark != C2[i].mark) return 0;
  }
  return 1;
}

int main() {
    int N, i;
    scanf("%d", &N);
    Card C1[101], C2[101];

    for (i = 0; i < N; i++) {
        scanf(" %c%c", &C1[i].mark, &C1[i].val);
    }
    for (i = 0; i < N; i++)  {
        C2[i] = C1[i];
    }
    BubbleSort(C1, N);
    Print(C1, N);
    printf("Stable\n");

    SelectionSort(C2, N);
    Print(C2, N);
    if (isStable(C1, C2, N)) {
        printf("Stable\n");
    } else {
        printf("Not stable\n");
    }

    return 0;
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

int n;
vector<int> g[1000005];
map<pair<int, int>, int> mp;
int in[1000005];
void solve() {
    cin >> n;

    rep(i, n) {
        int before = 0;
        rep(j, n - 1) {
            int a; cin >> a; --a;
            auto mi = min(i, a); auto ma = max(i, a);
            if (mp.count(make_pair(mi, ma)) == 0) mp.emplace(make_pair(mi, ma), mp.size());

            int now = mp[make_pair(mi, ma)];
            if (j != 0) { g[before].push_back(now); ++in[now]; }
            before = now;
        }
    }

    int idx = 0;
    int m = sz(mp);
    int ans = 1;
    queue<int> que[2];
    rep(i, m) if (in[i] == 0) que[0].push(i);

    while (!que[0].empty() || !que[1].empty()) {
        if (que[idx].empty()) { idx = (idx + 1) % 2; ++ans; }
        int ne = (idx + 1) % 2;
        auto p = que[idx].front(); que[idx].pop();

        rep(i, g[p].size()) {
            auto v = g[p][i];
            --in[v];
            if (in[v] == 0) que[ne].push(v);
        }
    }

    bool ok = true;
    rep(i, m) if (in[i] != 0) ok = false;

    if (ok) cout << ans << endn;
    else cout << -1 << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 74368
#include<bits/stdc++.h>
#define cin std::ios::sync_with_stdio(false);cin
using namespace std;
int main()
{
	char a[101];
	cin>>a;
	int l=strlen(a);
	for(int i=0;i<l;i++)
	{
	if(a[i]=='C')
	{
	for(int j=i;j<l;j++)
	{
	if(a[j]=='F')
	{
	cout<<"Yes"<<endl;
	return 0;
	}
	}	
	}	
	}
	 cout<<"No"<<endl;
	 return 0;
	system("color 4B");
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  if (s[1]==s[2]) {
      if ((s[0] == s[1]) || (s[2] == s[3]))
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
  }
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
n=int(input())
List=list(map(int,input().split()))

List.sort()
seive=[0]*(List[~0]+1)
count=0
for each in List:
    for i in range(each,List[-1]+1,each):
        seive[i]+=1
        
for each in List:
    if(seive[each]==1):
        count+=1


print(count)

Measured memory_bytes: 32252
import java.util.Scanner;

public class Main {
    public static int[] dp = new int[50];
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        // 初始化
        for(int i = 0; i < 50; i++) {
            dp[i] = -1;
        }
        System.out.println(fibonacci(n));
//        System.out.println(makeFibonacci(n));
    }

    // 递归生成斐波那契数列
//    public static int fibonacci(int n) {
//        if(n == 0 || n == 1) {
//            return 1;
//        }
//        return fibonacci(n-2) + fibonacci(n-1);
//    }

    // 通过记忆化递归生成斐波那契数列
    public static int fibonacci(int n) {
        if(n == 0 || n == 1) {
            return dp[n] = 1;
        }
        // 如果dp[n]已经计算完毕
        if(dp[n] != -1) {
            return dp[n];
        }
        return dp[n] = fibonacci(n-2) + fibonacci(n-1);
    }

    // 通过动态规划法生成斐波那契数列
    public static int makeFibonacci(int n) {
        dp[0] = 1;
        dp[1] = 1;
        for(int i = 2; i <= n; i++) {
            dp[i] = dp[i-2] + dp[i-1];
        }
        return dp[n];
    }
}



Measured memory_bytes: 26272
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int T = sc.nextInt();
    int A = sc.nextInt();
    
    double minDiff = Integer.MAX_VALUE;
    int minIdx = 0;
    for (int i = 1; i <= N; i++) {
      int h = sc.nextInt();
      double t = T - 0.006 * h;
      double diff = Math.abs(A - t);
      if (diff < minDiff) {
        minDiff = diff;
        minIdx = i;
      }
    }
    
    System.out.println(minIdx);
  }
}

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

using namespace std;
int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='+') ans++;
        else if(s[i]=='-') ans--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func init() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func loadint() (result int) {
	sc.Scan()
	result, _ = strconv.Atoi(sc.Text())
	return
}

func loadints(n int) []int {
	xs := make([]int, n)
	for i := 0; i < n; i++ {
		xs[i] = loadint()
	}
	return xs
}

func main() {
	a := loadint()
	b := loadint()
	c := loadint()
	if b < c {
		b, c = c, b
	}
	if a < b {
		a, b = b, a
	}
	if b < c {
		b, c = c, b
	}
	fmt.Println(a*10 + b + c)
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<stdio.h>
int main(void) {
	char std[201];
	int x;
	char S[101];
	char T[101];
	scanf("%d", &x);
	scanf("%s %s", S, T);
	int m = 0;
	for (m=0; m < x; m++) {
		std[2 * m] = S[m];
		std[2 * m + 1] = T[m];
	}
	std[2 * m] = '\0';
	printf("%s\n", std);
}

Measured memory_bytes: 128
import java.util.*;
import java.math.BigInteger;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		System.out.println(N * (N - 1) / 2 + M * (M - 1) / 2);
	}
}


Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    string S;
    cin >> S;
    int le = (int)(S.length());
    reverse(S.begin(),S.end());
    long long mod = 1000000007;
    long long dp[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0};

    int mo = 1;
    if(S[0] == '?'){
        for(int i = 0; i < 10; i++)dp[i] = 1;
    }else{
        dp[S[0] - '0'] = 1;
    }

    for(int i = 1 ; i < le; i++){
        mo = (mo * 10)%13;
        long long a[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
        int j;
        if(S[i] == '?'){
            for(j = 0; j < 10; j++)
                for(int k = 0; k < 13; k++){
                    a[(k+mo*j)%13] += dp[k];
                    a[(k+mo*j)%13] %= mod;
                }
        }else{
            j = S[i] - '0';
            for(int k = 0; k < 13; k++){
                    a[(k+mo*j)%13] += dp[k];
                    a[(k+mo*j)%13] %= mod;
                }
        }
        for(int j = 0;j < 13;j++)dp[j] = a[j];
    }
    
    cout << dp[5] << endl;
}

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

int main() {
    string odd, even;
    cin >> odd >> even;

    for (int i = 0; i < odd.size() + even.size(); i++) {
        if (i % 2 == 0) {
            cout << odd[i / 2];
        }
        else {
            cout << even[i / 2];
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
 
N=int(input())
dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)

Measured memory_bytes: 57820
#include <iostream>
#include <cmath>

using namespace std;

int main(void)
{
    int a, b, c, d;

    cin >> a >> b >> c >> d;

    if(abs(a - c) <= d){
        cout << "Yes" << endl;;
    }
    else if(abs(a-b) <= d && abs(b-c) <= d){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256