akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll N,K;
    cin >> N >> K;
    ll sum=(N-1)*(N-2)/2;
    if(sum<K){
        cout << -1 << endl;
        return 0;
    }
    vector<Pll> Ps;
    for(int i=2;i<=N;i++){
        Ps.push_back(Pll(1,i));
    }
    ll ct=2,idx=2;
    while(sum>K){
        if(ct==idx) {
            ct++;
            continue;
        }
        if(ct>N){
            idx++;
            ct=idx+1;
            continue;
        }
        Ps.push_back(Pll(idx,ct));
        ct++;
        sum--;
    }
    cout << Ps.size() << endl;
    for(int i=0;i<Ps.size();i++){
        cout << Ps[i].first << " " << Ps[i].second << endl;
    }

    return 0;
}

Measured memory_bytes: 512
import numpy as np
import itertools

n = int(input())
info = []
for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        info.append((i, x - 1, y))

a = np.array(list(itertools.product([0, 1], repeat=n)), dtype=np.bool)
for i, x, y in info:
    bl = (~a[:, i]) | (a[:, x] == bool(y))
    a = a[bl]

ans = a.sum(axis=1).max()
print(ans)

Measured memory_bytes: 18356
import collections
from collections import deque
N=int(input())
D=list(map(int,input().split()))
c=collections.Counter(D)
count0=0
count12=0
zeroflag=0
l=[]
if c[12]>0:
    count12=c[12]
if c[0]>0:
    count0=c[0]+1
#print(l,count0,count12)
#print(n)
allmax=0
q=deque()
l=[]



if (count0==0)and(zeroflag==0):
    q.append([0])
    q.append([24])
elif (count0==1)and(zeroflag==0):
    q.append([0,0])
    q.append([0,24])
    q.append([24,24])
else:
    zeroflag=1

if (count12==1)and(zeroflag==0):
    length=len(q)
    j=0
    while j<length:
        buf1=[]
        l=q.popleft()
        buf1.extend(l)
        l.append(12)
        q.append(l)
        j=j+1
elif count12>1:
    zeroflag=1

if zeroflag==0:
    for i in range(1,12):
        length=len(q)
        j=0
        if c[i]==0: continue
        if c[i]==1:
            while j<length:
                buf1=[]
                buf2=[]
                l=q.popleft()
                buf1.extend(l)
                buf1.append(i)
                buf2.extend(l)
                buf2.append(24-i)
                q.append(buf1)
                q.append(buf2)
                j=j+1
        if c[i]==2:
            while j<length:
                buf1=[]
                buf2=[]
                buf3=[]
                l=q.popleft()
                buf1.extend(l)
                buf1.extend([i,i])
                buf2.extend(l)
                buf2.extend([24-i,24-i])
                buf3.extend(l)
                buf3.extend([i,24-i])
                q.append(buf1)
                q.append(buf2)
                q.append(buf3)
                j=j+1
        if c[i]>2:
            zeroflag=1
            break
        #print(q)

#print(q)

if zeroflag==0:
    for l in q:
        l.sort()
        mi=100
        n=len(l)
        for j in range(n-1):
            mi=min(mi,l[j+1]-l[j],24-l[j+1]+l[j])
        mi=min(mi,l[n-1],24-l[n-1])
    #print(mi)
        allmax=max(allmax,mi)
else:
    allmax=0
print(allmax)

"""
for i in range(pow(2,n)):
    buf=[0]
    bit=[0]*n
    mi=100
    if count12==1:
        buf.append(12)
    buf.append(0)
    for j in range(n):
        if (i>>j)&1:
            bit[j]=1
    #print(bit)
    for j in range(n):
        buf.append(l[j][bit[j]])
    buf.sort()
    buf.append(24)
    #print(buf)
    for j in range(len(buf)-1):
        mi=min(mi,buf[j+1]-buf[j])
    allmax=max(allmax,mi)
print(allmax)
"""


Measured memory_bytes: 217964
from decimal import Decimal, getcontext
getcontext().prec = 32

Q, H, S, D = map(int, input().split())
q = Decimal(Q * 4)
h = Decimal(H * 2)
s = Decimal(S)
d = Decimal(D / 2)

arr = [(q, Q, Decimal(0.25)), (h, H, Decimal(0.5)), (s, S, Decimal(1.0)), (d, D, Decimal(2.0))]
arr.sort()

N = int(input())

ans = 0
while N > 0:
    for _, cost, quantity in arr:
        if N >= quantity:
            ans += (N // quantity) * cost
            N -= (N // quantity) * quantity
print(int(ans))

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for ( int i = 0; i < n; i++ ) { cin >> a[i]; }
  sort(a.begin(), a.end());

  int mx = a[n-1];
  auto iter = upper_bound(a.begin(), a.end(), mx/2);
  int md = ( abs((*iter)-(mx/2.0)) < abs((*(iter-1))-(mx/2.0)) ) ? *iter : *(iter-1);

  cout << mx << ' ' << md << endl;
  return 0;
}


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

using namespace std;

int main(){
    int n, z, w;
    cin >> n >> z >> w;
    vector<int> A(n);
    copy_n(istream_iterator<int>(cin), n, A.begin());
    
    cout << max(abs(w - A[n - 1]), n == 1 ? 0 : abs(A[n - 2] - A[n - 1])) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define debug(P) cout<<#P<<" = "<<P<<endl;
 
typedef long long ll;
typedef long double ld;
 
const int mod = 1e9+7;

const int M = 51;

int a[M], b[M], c[M], d[M];

int x[11];
 
int n, m, q;

ll ans;

void f(int i, int last){
	if(i > n){ //cout<<"Got number ";for(int i = 0; i < n; ++i)cout<<x[i]; cout<<endl;
		ll score = 0;
		for(int j = 0; j < q; ++j){
			if(x[b[j]] - x[a[j]] == c[j])score += d[j];
		}
		ans = max(ans, score);
		return;
	}

	for(int j = last; j <= m; ++j){
		x[i]= j;
		f(i+1, j);
	}

}
 
 
 
int main() {
	//freopen("input.txt","r",stdin);
	cin>>n>>m>>q;

	for(int i= 0; i < q; ++i){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	}

	ans = 0;

	f(1, 1);

	cout<< ans << endl;
 
}

Measured memory_bytes: 3620
import java.util.Scanner;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double p1 [] = {0.0,0.0};
        double p2[] = {100.0,0.0};
        System.out.println(p1[0]+" "+p1[1]);
        kock(n,p1,p2);
        System.out.println(p2[0]+" "+p2[1]);
    }
    public static boolean kock(int n,double p1[],double p2[]){
        if(n==0) return true;
        double s[] = new double[2];
        s[0] = (2.0 * p1[0] + p2[0]) / 3.0;
        s[1] = (2.0 * p1[1] + p2[1]) / 3.0;
        double t[] = new double[2];
        t[0] = (p1[0] + 2.0 * p2[0]) / 3.0;
        t[1] = (p1[1] + 2.0 * p2[1]) / 3.0;
        double u[] = new double[2];
        u[0] = ((t[0] - s[0]) / 2.0) - ((t[1] - s[1]) * Math.sqrt(3.0))/2.0 + s[0];
        u[1] = (t[0] - s[0]) * Math.sqrt(3.0)/2.0 + (t[1] - s[1]) / 2.0 + s[1];
        kock(n - 1, p1, s);
        System.out.println(s[0] + " " + s[1]);
        kock(n - 1, s, u);
        System.out.println(u[0] + " " + u[1]);
        kock(n - 1, u, t);
        System.out.println(t[0] + " " + t[1]);
        kock(n - 1, t, p2);
        return true;
    }
}


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

using namespace std;


#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 1e6 + 1, MOD = 1e9 + 7, mod = 998244353, INF = 3e17;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

int a[N];
vi g[1000];

signed main() {
   #ifdef Flash
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
   #endif
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   int n, p;
   cin >> n >> p;
   int sum = 0;
   for (int i = 0; i < n; i++) {
        int x;
   cin >> x;
   if (x % 2) sum++;
   }
   if (!sum) {
    cout << (p ? 0 : (1ll << n)) << endl;
   } else {
    cout << (1ll << (n - 1)) << endl;
   }

}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef long long int ll;

ll a[200000];

int cmp (const void *left, const void *right) {
  int l = *(int*)left;
  int r = *(int*)right;

  if (l < r) return -1;
  if (l > r) return +1;
  return 0;
}

ll dif (ll a, ll b) {
  return (a > b) ? (a - b) : (b - a);
}
ll smax (ll a, ll b) {
  return (a > b) ? a : b;
}

ll n;
ll solve() {
  qsort(a, n, sizeof(ll), cmp);

  ll result = dif(a[n - 1], a[0]);
  ll l = 0, r = n - 1;

  while (l + 1 < r - 1) {
    result += dif(a[l], a[r - 1]) + dif(a[l + 1], a[r]);
    l++;
    r--;
  }
  if (l + 1 == r - 1) {
    result += smax(dif(a[l], a[l + 1]), dif(a[r - 1], a[r]));
  }

  printf("%lld\n", result);
}

int main(void){
  ll i;
  scanf("%lld", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }

  solve();
  return 0;
}


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

int main(void) {
	int n; cin >> n;
	int a[3 * n];
	int i;
	long long int ans;
	for (i = 0; i < 3 * n; i++) {
		cin >> a[i];
	}

	sort(a, a + 3 * n);

	for (i = 3 * n - 2; i >= n; i -= 2) {
		ans += a[i];
	}

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

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

const int max_A = 1000005;

LL gcd(LL val1, LL val2){
    LL _val_lrg = (val1 > val2)? val1: val2;
    LL _val_sml = (val1 > val2)? val2: val1;

    LL r = _val_lrg % _val_sml;
    if(r==0){
        return _val_sml;
    }else{
        return gcd(_val_sml, r);
    }
}


int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> C(max_A);
    REP(i,N){
        cin>>A[i];
        C[A[i]]++;
    }

    bool blpairwise = true;
    for(int i=2; i < max_A; i++){
        int cnt = 0;
        for(int j=i; j < max_A; j+=i){
            cnt += C[j];
        }
        if(cnt > 1){
            blpairwise = false;
            break;
        }
    }

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

    int x = A[0];
    FOR(k, 1, N){
        x = gcd(x, A[k]);
    }

    if(x == 1){
        cout << "setwise coprime" << endl;
        return 0;
    }

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

Measured memory_bytes: 11068
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/





int main() {

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

	int q;
	cin >> q;
	vector<int> b(q);
	for (int i = 0; i < q; i++)
	{
		cin >> b[i];
	}

	for (int mask = 0; mask < (1 << n); mask++)
	{
		int cnt = 0;
		for (int i = 0; i < n; i++)
		{
			if ((mask >> i) & 1) {
				cnt += a[i];
			}
		}
		check[cnt] = 1;
	}

	for (int i = 0; i < q; i++)
	{
		
		if (check[b[i]]) {
			cout << "yes" << endl;
		}
		else
		{
			cout << "no" << endl;
		}
	}

	





	return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N,C;
  cin >> N >> C;
  int N_MAX=200100;
  int s[N_MAX],t[N_MAX],c[N_MAX];
  int time[35][N_MAX]={0};
  int min_time=2000010,max_time=0;
  int ans=0;
  for(int i=1;i<=N;i++){
    cin >> s[i] >> t[i] >> c[i];
    for(int j=2*s[i]-1;j<=2*t[i];j++){
      time[c[i]][j]=1;
    }
    min_time=min(min_time,s[i]*2-1);
    max_time=max(max_time,t[i]*2);
  }
  for(int j=min_time;j<=max_time;j++){
    int cnt=0;
    for(int i=1;i<=30;i++){
      if(time[i][j]>0){
        cnt++;
      }
    }
    ans=max(ans,cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 29184
#include <iostream>
#include <string>
#include <set>
#include <regex>
using namespace std;

int main () {
  int n, m;
  cin >> n >> m;
  n = (n!=1 ? n-1 : 13);
  m = (m!=1 ? m-1 : 13);
  
  cout << (n == m ? "Draw" : (n > m ? "Alice" : "Bob")) << endl;
}

Measured memory_bytes: 3124
import java.io.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		InputReader in = new InputReader();
		double w = in.nextInt();
		double h = in.nextInt();
		double x = in.nextInt();
		double y = in.nextInt();
		
		int numWays = 0;
		if (x == w/2 && y == h/2)
			++numWays;
		System.out.println(w*h/2 + " " + numWays);
	}
	
	static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;
		
		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}
		
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


Measured memory_bytes: 23252
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        ArrayList<String> A = new ArrayList<String>();
        int i;
        String f, s;
        for (i = 0; i < N; i++) {
            A.add(sc.next());
        }
        Collections.sort(A);
        for (i = 0; i < N-1; i++) {
            f = A.get(i);
            s = A.get(i+1);
            if (f.equals(s)) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  if (a+b == c || b+c == a || c+a == b) 
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
//Robs Code
#include<bits/stdc++.h>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define all(x) x.begin(),x.end()
#define ed cout<<"\n";
#define pb push_back
#define pii pair<ll,ll>
#define _1 first
#define _2 second
#define maxi 100000007
/**********************************************************/
using namespace std;
ll i,j,k,n,m,q,t,a,b,cnt,sum,tot;
int main() 
{
    speed;
    cin>>a>>b;
    if(b%a) cout<<(b-a);
    else cout<<a+b;
    return 0;
}


Measured memory_bytes: 256
#include <iomanip>
#include <iostream>

auto is_even(int n) { return n % 2 == 0; }

int main() {
  int n;
  std::cin >> n;
  const auto p = is_even(n) ? 0.5 : (n / 2 + 1.0) / n;
  std::cout << std::fixed << std::setprecision(10) << p << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using  ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll n,m,x,c,a;
const ll INF=1001001001001;


int main(){

  std::cin >> n>>m>>x;

  std::vector<ll> cost(n);
  std::vector<std::vector<ll> > book(n,std::vector<ll>());

  rep(i,n){
    std::cin >> cost[i];
    rep(j,m){
      ll temp;
      std::cin >> temp;
      book[i].push_back(temp);
    }
  }




  ll last=INF;
  for (int bit = 0; bit < (1<<n); bit++) {
      ll nowpay=0;
      std::vector<ll> ans(n,0);

       for (int i = 0; i < n; ++i) {
           if (bit & (1<<i)) { // 列挙に i が含まれるか
             // std::cout << i;
             nowpay+=cost[i];
             rep(j,m){
               ans[j]+=book[i][j];
             }
           }
       }
       // std::cout << '\n';
       // std::cout <<"pay"<<nowpay << '\n';

       bool flag=true;
       rep(j,m){
         if(ans[j]<x){flag=false;break;}
       }
       if(flag)last=min(last,nowpay);
  }

  if(last==INF)std::cout << "-1" << '\n';
  else std::cout << last << '\n';
  return 0;
}


Measured memory_bytes: 3636
/*
Look at the star
Look at the shine for U
*/
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define sl(x) scanf("%lld",&x)
using namespace std;
const int N = 1e6+5;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n;n=n*n;}return r;}

int main()
{
	ll n,p,i,j,k;
	cin >> n >> p;
	if(n == 1)
	{
		cout << p << endl;
		return 0;
	}
	for(i = 0;fpow(2,i) <= p;i++);
	if(i < n)
	{
		cout << 1 << endl;
		return 0;
	}
	ll maxx = 1;
	for(i = 1;fpow(i,n) <= p;i++)
	{
		ll now = fpow(i,n);
		if(p%now==0)
			maxx = i;
	}
	cout << maxx << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
s = [int(input()) for _ in range(N)]
s.sort()
ans = sum(s)
if ans % 10:
    print(ans)
else:
    for i in range(N):
        if (ans - s[i]) % 10:
            print(ans - s[i])
            break
    else:
        print(0)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int K;
	cin >> K;
	ll ans = 0;
	rep(i, K)rep(j, K)rep(k, K){
		int a = i+1;
		int b = j+1;
		int c = k+1;
		int add = __gcd(a, b);
		add = __gcd(add, c);
		ans += add;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;  cin >> n;
    vector<int> odd(100001), even(100001);
    int ans;
    rep(i, n) {
      int v;  cin >> v;
      if (i % 2) {
        odd[v]++;
      } else {
        even[v]++;
      }
    }
    size_t maxo = distance(odd.begin(), max_element(odd.begin(), odd.end()));
    size_t maxe = distance(even.begin(), max_element(even.begin(), even.end()));
    sort(odd.begin(), odd.end(), greater<int>());
    sort(even.begin(), even.end(), greater<int>());
    if (maxo != maxe) {
      ans = n - odd[0] - even[0];
    } else {
      ans = n - max(odd[0] + even[1], odd[1] + even[0]);
    }
    cout << ans << '\n';

    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int A1, A2;
    cin >> A1;
    long long sum = 0;
    for (int i = 1; i < N; i++) {
        cin >> A2;
        sum += max(0, A1 - A2);
        A1 = max(A1, A2);
    }
    cout << sum << endl;
}


Measured memory_bytes: 3608
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  ll a_max = a[N - 1];
  ll half_a_max = a[N - 1] / 2;
  ll cand = 0;
  ll res = 0;
  for (int i = 0; i < N - 1; i++) {
    if (a[i] <= half_a_max && a[i] > res) {
      cand = a[i];
      res = a[i];
    } else if (a_max - a[i] <= half_a_max && a_max - a[i] > res) {
      cand = a[i];
      res = a[i];
    }
  }
  cout << a_max << " " << cand << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

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

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



int main(){
    string s;
    cin >> s;

    rep(i,0,sz(s)){
	if(s[i] == '?')cout << 'D';
	else cout << s[i];
    }
    PN;
    return  0;
}


Measured memory_bytes: 3716
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

createAs :: [[Int]] -> [Int]
createAs = map head

createBs :: [[Int]] -> [Int]
createBs = map last

main = do
  n <- getInt
  xss <- getIntNList n
  let len = length xss
  let cent = len `div` 2
  let isOdd = odd len
  let as = sort (createAs xss)
  let bs = sort (createBs xss)
  if isOdd
    then print $ bs !! cent - as !! cent + 1
    else print (bs !! cent + bs !! (cent - 1) - (as !! cent + as !! (cent - 1)) + 1)


Measured memory_bytes: 124420
#include<iostream>
#include <iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

struct edge{
    ll to,cost;
};
ll n;
vector<edge>  G[100010];
ll d[100010];

void  dijkstra(int s){
    priority_queue<pii,vector<pii>,greater<pii>> que;
    fill(d,d+n,LLINF);
    d[s]=0;
    que.push(pii(0,s));

    while(!que.empty()){
        pii p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(pii(d[e.to],e.to));
            }
        }
    } 
}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll e,r;
    cin>>n>>e>>r;
    rep(i,e){
        ll  a,b,c;
        cin >>a>>b>>c;
        G[a].pb({b,c});
    }
    dijkstra(r);
    rep(i,n){
        if(d[i]==LLINF) cout<<"INF"<<endl;
        else cout<<d[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 18536
#include<bits/stdc++.h>
using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/
#define ull            unsigned long long
#define ll             long long
#define vi             vector<int>
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define vit            vector<int> :: iterator
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*/
#define error(args...) {vector <string> _v = split(#args, ','); err(_v.begin(), args); cout << endl;}
vector <string> split(const string &s, char c) {
    vector <string> v;
    stringstream ss(s); string x;
    while (getline(ss, x, c)) v.emplace_back(x);
    return move(v);
}
void err(vector <string> :: iterator it) {}
template <typename T, typename... Args>
void err(vector <string> :: iterator it, T a, Args... args) {
    cout << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", ";
    err(++it, args...);
}
 
int ini(){int x; scanf("%d",&x);return x;}
long long inl(){ long long x;scanf("%lld",&x); return x;}
double ind(){double x; scanf("%lf",&x);return x;}
#define Iin ini();
#define Lin inl();
#define Din ind();

int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;

int a[N];

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int t=1,te=0;
 //   cin>>t;
    while(t--){
        int n,l,s=0;
        cin>>n>>l;

        for(int i=1;i<=n;++i){
            a[i]=i+l-1;
            s+=a[i];
        }

        int res=M,r;

        for(int i=1;i<=n;++i){
         //   printf("%d %d\n", a[i],res);
            if(abs(s-(s-a[i]))<res){
               res=abs(s-(s-a[i]));
               r=s-a[i];
            }
        }
        printf("%d\n", r);

        //printf("Case %d: ",++te);
    }
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
string s;
int n;
ll k;
ll ans = 0;
int main(){FAST;
cin>>s>>k;
n = s.length();
int fs = 0,fe = 0;
char c = s[0];
while(fs<n and s[fs] == c)fs++;
if(fs == n){
  cout<<fs*k/2;
  return 0;
}
while(s[n-fe-1] == c)fe++;
for(int i=fs;i<n-fe;i++){
  int j = i;
  while(s[j] == s[i])j++;
  ans+=(j-i)/2*k;
  i = j-1;
}
ans+=(fe+fs)/2*(k-1)+fe/2+fs/2;
cout<<ans;
return 0;
}

Measured memory_bytes: 256
n=int(input())
X=[]
Y=[]
H=[]
hi=int(0)
for i in range(n):
    x,y,h=map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
    if h!=0:
        hi=i
for x in range(101):
    for y in range(101):
        now=H[hi]+abs(X[hi]-x)+abs(Y[hi]-y)
        ans=1
        for i in range(n):
            nowi=now-abs(X[i]-x)-abs(Y[i]-y)
            nowi=max([nowi,0])
            if H[i]!=nowi:
                ans=0
        if ans==1:
            print("{} {} {}".format(x,y,now))
            exit()

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
        int[] a = Read.ints();
        Console.WriteLine((a[0]-a[2])/(a[1]+a[2]));
    }
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
    public static bool IsPrime(long n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        for (long i = 2; i < n; i++) { if (n % i == 0) return false; }
        return true;
    }
}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long() { return long.Parse(Console.ReadLine()); }
    public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); }
    public static int Int() { return int.Parse(Console.ReadLine()); }
    public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 13396
//gauravsinghh
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(int i = a; i <= b; i++)
#define ffo(i, a, b) for(int i = a; i >= b; i--)
#define MAX 100005
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

bool comp(const pair < ll, ll >&a, const pair < ll, ll >&b){
    return ((a.ss < b.ss) || (a.ss == b.ss && a.ff < b.ff));
}

signed main(){ 
    IOS
    //io_set();
    ll n, m, l, r;
    cin >> n >> m;
    ll a[n+1] = {0};
    rep(i, m){
        cin >> l >> r;
        a[l] += 1;
        a[r+1] += -1;
    }
    ll c = 0;
    fo(i, 1, n){
        a[i] += a[i-1];
        if(a[i] == m){
             c++;
        }
    }
    cout << c << endl;
    return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;

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

		int h = sc.nextInt();
		int w = sc.nextInt();

		int[][] c = new int[10][10];
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				c[i][j] = sc.nextInt();
			}
		}

		for (int k = 0; k < 10; k++) {
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					c[i][j] = Math.min(c[i][j], c[i][k] + c[k][j]);
				}
			}
		}

		long answer = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				int x = sc.nextInt();
				if (x == -1 || x == 1) continue;
				answer += c[x][1];
			}
		}

		System.out.println(answer);
	}
}


Measured memory_bytes: 43980
import java.util.*;
class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
        String a = "";
		ArrayList<String> ans = new ArrayList<String>();
		
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == '0') {
				ans.add("0");
			}else if(s.charAt(i) == '1') {
				ans.add("1");
			}else if(s.charAt(i) == 'B' && ans.size() != 0) {
				ans.remove(ans.size() -1);
			}
		}
		for(String ss : ans) {
			a += ss;
		}
      System.out.println(a);
	}
}


Measured memory_bytes: 21844
/* Bubble Sort */

#include <stdio.h>

int main(void) {
  int n, swap = 0, i, j, tmp;
  scanf("%d", &n);
  int a[n];
  for(i = 0; i < n; i++) scanf("%d", &a[i]);
  for(i = 0; i < n; i++)
    for(j = n - 1; j > i; j--)
      if (a[j] < a[j - 1]) {
        tmp = a[j];
        a[j] = a[j - 1];
        a[j - 1] = tmp;
        swap++;
      }
  for(i = 0; i < n; i++) {
    printf("%d", a[i]);
    if(i < n - 1) printf(" ");
  }
  printf("\n%d\n", swap);

  return 0;
}

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

using namespace std;

int get(vector <int> v)
{
	int n = v.size();
	
	vector <int> p(n);
	
	for(int i = 1; i <= n; i++)
		p[i - 1] = i;
	
	int res = 0;
	
	do
	{
		res++;
		
		if(p == v)
			break;
	}while(next_permutation(p.begin(), p.end()));
		
	return res;
}

void solve()
{
	int n;
	cin >> n;
	
	vector <int> v(n);
	vector <int> t(n);
	
	for(auto& i : v)
		cin >> i;
	
	for(auto& i : t)
		cin >> i;
	
	int a = get(v);
	int b = get(t);
	
	cout << abs(a - b) << '\n';
}

main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t = 1;
//	cin >> t;
	
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 256
a = input()
l = list(a)
list_ins = [0] * 200000
ins_cnt = 0
list_app = [0] * 200000
app_cnt = 0

q = int(input())

default_order = True
for i in range(q):
  x = input().split()
  if x[0] == "1":
    default_order = default_order ^ True
  elif x[0] == "2":
    insert_type = default_order ^ False
    if x[1] == "2":
      insert_type = not(insert_type)
    if insert_type:
      list_ins[ins_cnt] = x[2]
      ins_cnt += 1
    else:
      list_app[app_cnt] = x[2]
      app_cnt += 1
ret = ""
if ins_cnt > 0:
  list_ins = list_ins[0:ins_cnt]
else:
  list_ins = []
if app_cnt > 0:
  list_app = list_app[0:app_cnt]
else:
  list_app = []
if default_order:
  list_ins.reverse()
  ret = ''.join(list_ins) + ''.join(l) + ''.join(list_app)
else:
  list_app.reverse()
  l.reverse()
  ret = ''.join(list_app) + ''.join(l) + ''.join(list_ins)

print(ret)
      

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

int main() {
	int n; cin >> n;
	int A[n];
	for(int i=0;i < n; i++) cin >> A[i];

	for(int i=0; i < n; i++) {
		int k = A[i];
		int j = i-1;
		while(j >= 0 && A[j] > k) {
			A[j+1] = A[j];
			j--;
        }
        A[j+1] = k;
        for(int k=0; k <n-1; k++) cout << A[k] << " ";
        cout << A[n-1] << endl;
    }
    return 0;
}



Measured memory_bytes: 3096
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.par=[i for i in range(n)]
        self.size=[0 for i in range(n)]
    def find(self,x):
        if x==self.par[x]:
            return x
        self.par[x]=self.find(self.par[x])
        return self.par[x]
    def merge(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return
        if self.size[x]>=self.size[y]:
            self.par[y]=x
            self.size[x]+=self.size[y]
        else:
            self.par[x]=y
            self.size[y]+=self.size[x]
    def same(self,x,y):
        x=self.find(x)
        y=self.find(y)
        return x==y
n,m=map(int,input().split())
p=list(map(int,input().split()))
uf=UnionFind(n)
for _ in range(m):
    x,y=map(int,input().split())
    uf.merge(x-1,y-1)
ans=0
for i in range(n):
    if p[i]-1==i or uf.same(i,p[i]-1):
        ans+=1
print(ans)


Measured memory_bytes: 14452
n = int(input())
h = list(map(int, input().split()))

step = 0

for i in range(n):
    if i == 0:
        continue
    if h[i] >= h[i-1]:
        continue

    step += (h[i-1] - h[i])
    h[i] = h[i-1]

print(step)



Measured memory_bytes: 32240
#include <stdio.h>
#include <math.h>
int PrimeJudge(int);
#define N 10000
int main(){
  int n,i,flg,prime=0;
  int num[N];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&num[i]);
    flg=PrimeJudge(num[i]);
    if(flg==0) prime++;
  }
  printf("%d\n",prime);
  return 0;
}
int PrimeJudge(int data){
  int i=3;
  if(data==2) return 0;
  if(data<2 || data%2==0) return -1;
  while(i<=sqrt(data)){
    if(data%i==0) return -1;
    i=i+2;
  }
  return 0;
}

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

using namespace std;

int main(void){
  string s;
  vector<int>num;
  while(cin >> s){
    num.clear();
    for(int i=0;i<10;i++)
      num.push_back(s[i]-'0');
    
    vector<int>n;
    for(int i=0;i<9;i++){
      for(int j=0;j<num.size()-1;j++){
	n.push_back((num[j]+num[j+1])%10);
      }
      num=n;
      n.clear();
    }
    cout << num[0] << endl;
  }
  return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int64 a, b, c;
  cin >> a >> b >> c;
  if (c >= a + b && (c - a - b) * (c - a - b) > 4 * a * b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  var data = chunk.split( " " ).map( Number );
  var x1 = data[0];
  var y1 = data[1];
  var x2 = data[2];
  var y2 = data[3];
   
  var d = Math.sqrt( Math.pow( x1-x2, 2 )+Math.pow( y1-y2, 2 ) );
  console.log( d );  
});

Measured memory_bytes: 15896
import math

isprime = None
 
def sieve(n):
    global isprime
 
    if n < 2:
        isprime = [False] * (n + 1)
        return
 
    isprime = [True if i % 2 != 0 else False for i in range(n + 1)]
    isprime[0] = isprime[1] = False
    isprime[2] = True
 
    from math import sqrt, ceil
 
    for i in range(3, int(sqrt(n)) + 1):
        if isprime[i] == True:
            for j in range(i + i, n + 1, i):
                isprime[j] = False

sieve(10**5+1)


accm = [0] * (10**5+1)
for i in range(3, 10**5+1):
    accm[i] += accm[i-1]
    if isprime[i] and isprime[(i+1)//2]:
        accm[i] += 1

import sys
Q = int(input())
# for i in range(Q):
#     l,r = map(int,input().split())
for l,r in ( map(int, line.split())  for line in sys.stdin.readlines() ):

    if isprime[l] and isprime[(l+1)//2]:
        l-=1
    if isprime[r] and isprime[(r+1)//2]:
        r+=1

    print( accm[r] - accm[l] ) 


Measured memory_bytes: 14828
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 10000005
constexpr int inf = 100000000;

int search(int a[], int n, int key) {
	int  i = 0;
	a[n] = key;
	while (a[i] != key) {
		i++;
	}
	return i != n;
}

int main() {
	int i, n, q, sum = 0, key, a[10001];
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &key);
		if (search(a, n, key)) {
			sum++;
		}
	}
	printf("%d\n",sum);
	return 0;
}












Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
int n,a[100001],sum=0;
int main() {
	cin>>n;
	n=2*n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i+=2){
		if(a[i]==a[i+1])
			sum+=a[i];
		else
			sum+=a[i];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

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

    int n = sc.nextInt();
    int ans = 0;

    for(int i=3; i<=n; i+=2){
      int count =0;
      for(int j=1;j<=i;j++){
        if(i%j==0){
          count += 1;
        }
      }
      if(count==8){
        ans +=1;
      }
    }

    System.out.println(ans);

  }

}

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

int main(){
    FILE*fi,*fout;
    int a,b,c;
    //fi=fopen("A.in" ,"r");
   // fout=fopen("A.out" ,"w");
    fi=stdin;
    fout=stdout;
    fscanf(fi,"%d %d %d" ,&a,&b,&c);
    if(a==b&&b==c&&a%2==0)
      fprintf(fout,"-1\n");
    else{
      int ans=0;
      while(a%2+b%2+c%2==0){
         int auxa,auxb,auxc;
         auxa=(b+c)/2;
         auxb=(a+c)/2;
         auxc=(a+b)/2;
         a=auxa;
         b=auxb;
         c=auxc;
         ans++;
      }
      fprintf(fout,"%d\n" ,ans);
    }
    //fclose(fi);
   // fclose(fout);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
     
    public class Main{
    	public static void main(String args[]){
    		Scanner scan = new Scanner(System.in);
    
        int a = scan.nextInt(); 
        int b = scan.nextInt(); 
        int c = scan.nextInt(); 

        int d = b-a;
        int e = c-b;
        if(d==e){
          System.out.println("YES");
        }
        else
          System.out.println("NO");
    	}
    }


Measured memory_bytes: 21204
#include <stdio.h>
#define HILLS 10

int main(void){
	int i, t, a=0, b=0, c=0;
	for(i=0;i<HILLS;i++){
		scanf("%d",&t); if(t>a) a=t;
		if(a>b) t=a, a=b, b=t;
		if(b>c) t=c, c=b, b=t;
	}
	printf("%d\n%d\n%d\n",c,b,a);
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < s.length(); i++){
            sb.append("x");
        }
        System.out.println(sb);
    }
}

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

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

    bool flag = false;
    int num = 1;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if(a == num) {
            num++;
            flag = true;
        }
    }
    num--;

    if(flag) cout << n - num << endl;
    else     cout << "-1" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int X;
  cin >> X;

  int ans=1, sum=0;

  for(int i=0; i<N; i++){
      int a;
      cin >> a;
      sum+=a;
      if(sum<=X){
          ans+=1;
      }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256