akhauriyash/Code-Regression huggingface dataset:
# include <bits/stdc++.h>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;

// namespace utils
namespace utils{
  template <typename T> void print(vector<vector<T>> mat) {
    rep (i, mat.size()) {
      rep (j, mat[0].size()) cout << mat[i][j] << ' ';
      cout << endl;
    }
  }

  template <typename T> void print(vector<T> v) {
    rep (i, v.size()) cout << v[i] << ' ';
    cout << endl;
  }
// end namespace utils
}


int solve(int a, int b, int c) {
  if (a%2!=0 || b%2!=0 || c%2!=0) return 0;

  bool cond1 = ((a+b)/2 == c && (b+c)/2 == a);
  bool cond2 = ((b+c)/2 == a && (c+a)/2 == b);
  bool cond3 = ((c+a)/2 == b && (a+b)/2 == c);
  if (cond1 || cond2 || cond3) return -1;

  int ans = 0;
  while (a%2==0&&b%2==0&&c%2==0) {
    int na, nb, nc;
    na = b/2 + c/2;
    nb = c/2 + a/2;
    nc = a/2 + b/2;
    a = na;
    b = nb;
    c = nc;
    ans++;
  }

  return ans;
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << solve(a, b, c) << endl;
}


Measured memory_bytes: 256
import heapq
V, E, r = map(int, input().split())
G = [[] for _ in range(V)]
for _ in range(E):
    s, t, d = map(int, input().split())
    G[s].append((t, d))
# print(*G, sep='\n')
dp = [float('inf')] * V
dp[r] = 0
Q = []
heapq.heappush(Q, (0, r))
while len(Q) > 0:
    # print(Q)
    d, v = heapq.heappop(Q)
    if dp[v] < d:
        continue

    for nv, nd in G[v]:
        if dp[nv] > dp[v] + nd:
            dp[nv] = dp[v] + nd
            heapq.heappush(Q, (dp[nv], nv))
# print(dp)
print(*[d if d != float('inf') else 'INF' for d in dp], sep='\n')



Measured memory_bytes: 90276
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

class Graph {
 private:
  vvl g;
  ll root;
  vvl parent;
  vl depth;
  ll n;
  ll logn;

 public:
  Graph(ll n, ll r) : n(n), g(n), root(r), depth(n) {
    logn = 0;
    ll tmp = 1;
    while (tmp < n) {
      logn++;
      tmp *= 2;
    }
    parent = vvl(logn, vl(n));
  }

  void addEdge(ll u, ll v) {
    g[u].push_back(v);
    g[v].push_back(u);
  }

  void dfs(ll v, ll p, ll d) {
    parent[0][v] = p;
    depth[v] = d;
    rep(i, g[v].size()) {
      if (g[v][i] != p) dfs(g[v][i], v, d + 1);
    }
  }

  void init() {
    dfs(root, -1, 0);
    rep(k, logn - 1) {
      rep(v, n) {
        if (parent[k][v] < 0)
          parent[k + 1][v] = -1;
        else
          parent[k + 1][v] = parent[k][parent[k][v]];
      }
    }
  }

  ll getDist(ll v) { return depth[v]; }
};

class UnionFind {
 protected:
  vi data;

 public:
  UnionFind(int size) : data(size, -1) {}
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) {
        swap(x, y);
      }
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, u, v;
  cin >> n >> u >> v;
  u--, v--;
  Graph g1(n, u), g2(n, v);
  vector<pll> ab;
  rep(i, n - 1) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    ab.emplace_back(a, b);
    g1.addEdge(a, b);
    g2.addEdge(a, b);
  }
  g1.init();
  g2.init();
  vector<pll> dist(n);
  rep(i, n) {
    dist[i] = {g1.getDist(i), g2.getDist(i)};
    // cerr << i << ":" << g1.getDist(i) << "," << g2.getDist(i) << endl;
  }
  UnionFind uf(n);
  rep(i, n - 1) {
    ll a = ab[i].first, b = ab[i].second;
    if (dist[a].first < dist[a].second && dist[b].first < dist[b].second) {
      uf.unite(a, b);
    }
  }
  ll ans = 0;
  rep(i, n) {
    if (uf.same(u, i)) {
      ans = max(ans, dist[i].second - 1);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 46188
class Dice:
    def __init__(self, num):
        self.num = num
    def roll(self, fn):
        for i in range(len(fn)):
            if fn[i] == "S":
               ue = self.num[4]
               self.num[4] = self.num[5]
               self.num[5] = self.num[1]
               self.num[1] = self.num[0]
               self.num[0] = ue
            elif fn[i] == "N":
               ue = self.num[1]
               self.num[1] = self.num[5]
               self.num[5] = self.num[4]
               self.num[4] = self.num[0]
               self.num[0] = ue    
            elif fn[i] == "W":
               ue = self.num[2]
               self.num[2] = self.num[5]
               self.num[5] = self.num[3]
               self.num[3] = self.num[0]
               self.num[0] = ue
            elif fn[i] == "E":
               ue = self.num[3]
               self.num[3] = self.num[5]
               self.num[5] = self.num[2]
               self.num[2] = self.num[0]
               self.num[0] = ue     
num = list(map(int, input().split(" ")))
fn = str(input())
dice1 = Dice(num)
dice1.roll(fn)
print(num[0]) 


Measured memory_bytes: 5612
#include<bits/stdc++.h>
#define ll long long
const int inf = 1000000000;
using namespace std;
int main ()
{
    ll i,j,n,l,k;
    vector<int> v;
    cin>>n;
    for(i=0;i<n;i++)
    {int q; cin>>q; v.push_back(q);}
    l=*min_element(v.begin(),v.end());
    k=*max_element(v.begin(),v.end());
    ll c=inf;
    for(i=l;i<=k;i++)
    {
        ll a=0;
        for(j=0;j<n;j++)
        {a=a+((v[j]-i)*(v[j]-i));}
        c=min(c,a);
    }
    cout<<c<<endl;
    return 0;
}

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

int main() {
	// your code goes here
	int a,b,c;
	cin>>a>>b>>c;
	if(a==1&&b==0&c==0) cout<<"Close"<<endl;
	else if(a==0&&b==1&c==0) cout<<"Close"<<endl;
	else if(a==1&b==1&c==0) cout<<"Open"<<endl;
	else if(a==0&b==0&c==1) cout<<"Open"<<endl;
	else cout<<"Close"<<endl;
	return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin>>a;
  if(a==1||a==2||a==3||a==5||a==7||a==11||a==13||a==15||a==17||a==19||a==23||a==29||a==31){
    cout<<1<<endl;
  }if(a==4||a==6||a==9||a==10||a==14||a==21||a==22||a==25||a==26){
    cout<<2<<endl;
  }if(a==28||a==30){
    cout<<4<<endl;
  }if(a==8||a==12||a==18||a==20||a==27){
    cout<<5<<endl;
  }if(a==16){
    cout<<14<<endl;
  }if(a==24){
    cout<<15<<endl;
  }if(a==32){
    cout<<51<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  
  int H , W ;
  string S;
  cin >> H >> W;
  string C[H][W];
  for(int i = 0 ; i < H ; i++ ){
    cin >> S;
    for(int j = 0 ; j < W ; j++){
      C[i][j] = S[j];
    }

  }

  for(int i = 0 ; i < H ; i++ ){
    for(int j = 0 ; j < W ; j++){
      cout << C[i][j];
    }
    cout << endl;
    for(int j = 0 ; j < W ; j++){
      cout << C[i][j];
    }
    cout << endl;
  }


  return 0;
}

Measured memory_bytes: 768
import java.util.ArrayList;
import java.util.Scanner;
class Main{


	static char[][] map;
	static final int MOD = 1000000007;


	static long[][] c;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力

		String s = sc.next();
		ArrayList<Integer> R = new ArrayList<Integer>();
		ArrayList<Integer> L = new ArrayList<Integer>();

		for(int i = 0;i < s.length();i++){
			if(s.charAt(i) == 'R'){
				R.add(i);
			}else{
				L.add(i);
			}
		}
		
//		System.out.println("R");
//		for(int i = 0;i < R.size();i++){
//			System.out.print(R.get(i) + " ");
//			
//		}
//		System.out.println();
//
//		System.out.println("L");
//		for(int i = 0;i < L.size();i++){
//			System.out.print(L.get(i) + " ");
//			
//		}
//		System.out.println();



		int[] ans = new int[s.length()];
		for(int i = 0;i < s.length();i++){
			if(s.charAt(i) == 'R'){
				int next = upperbond(i,L);
//				System.out.println("R " + next);

				if((next - i) % 2 == 0){
					ans[next]++;
				}else{
					ans[next-1]++;
				}
			}else{
				int next = lowerbond(i,R);
//				System.out.println("L " + next);

				if((i - next) % 2 == 0){
					ans[next]++;
				}else{
					ans[next+1]++;
				}
			}
		}


		for(int i = 0;i < s.length();i++){
			System.out.print(ans[i] + " ");
		}



	}
	
	

	static int upperbond(int k, ArrayList<Integer> data){		//kより小さい最大の値をdataの中から探し、返す二分探索
		int min = -1;
		int max = data.size();

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data.get(mid) > k){
				max = mid;
			}else{
				min = mid;
			}
		}
		return data.get(max);
	}

	static int lowerbond(int k, ArrayList<Integer> data){		//kより小さい最小の値をdataの中から探し、返す二分探索
		int min = -1;
		int max = data.size();

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data.get(mid) >= k){
				max = mid;
			}else{
				min = mid;
			}
		}
		return data.get(min);
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return   end- otherpair.end;
	}








}






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

int main(){
  int n,m;
  cin>>n>>m;
  int a=1,b=n;
  if(n%2==1){
    rep(i,m){
      cout<<a<<" "<<b<<endl;
      a++; b--;    
    }
  }
  else{
    bool ok=false;
    rep(i,m){
      cout<<a<<" "<<b<<endl;
      a++; b--;
      if(b-a<=n/2&&!ok)b--,ok=true;
    }
  }
}

Measured memory_bytes: 3640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, k;
    cin >> n >> k;
    double ans = 0.0;

    FOR(x,1,n){
        double tmp = 1.0 / n;
        if (x < k){
            int xx = x;
            while (xx < k){
                xx *= 2;
                tmp /= 2.0;
            }
        }
        ans += tmp;
    }
    printf("%.15f\n", ans);


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
	int n;
    cin >> n;
    map<ll, ll> m;
    rep(x,1,101){
        rep(y,1,101){
            rep(z,1,101){
                m[x*x+y*y+z*z+x*y+y*z+z*x]++;
            }
        }
    }
    rep(i,0,n){
        cout << m[i+1] << endl;
    }
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<pair<string, unsigned long>> songs(N);
    for(auto& i : songs)cin >> i.first >> i.second;
    string X;
    cin >> X;
    unsigned long ans{0}, coef{0};
    for(const auto& i : songs){
        ans += i.second * coef;
        if(i.first == X)coef = 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
num_of_animals, num_of_foot = gets.split(' ').map(&:to_i)

crane = num_of_animals
turtle = 0


while 0 <= crane do
  if (crane * 2 ) + ( turtle * 4 ) == num_of_foot
    puts 'Yes'
    break
  end
  crane = crane - 1
  turtle = turtle + 1
  puts 'No' if crane < 0
end


Measured memory_bytes: 14356
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main () {
  long long int H, W, ans, tmp;
  cin >> H >> W;
  tmp = H * W;
  if (tmp % 2 != 0) {
    ans = tmp / 2 + 1;
  }
  else if (tmp % 2 == 0) {
    ans = tmp / 2;
  }
  if (H == 1 || W == 1) {
    ans = 1;
  }
  // printf("%d\n", ansA);
  // printf("%d\n", ansB);
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 256
while True:
    num = 0
    n = int(input())
    E_lis = []
    pri_lis = []
    if n == 0:
        break
    for i in range(n):
        e,p,q = map(int,input().split())
        if e in E_lis:
            pri_lis[E_lis.index(e)] += p*q
        else:
            E_lis.append(e)
            pri_lis.append(p * q)
    for j in range(len(E_lis)):
        if pri_lis[j] >= 1000000:
            print(E_lis[j])
            num += 1
    if num == 0:
        print("NA")

Measured memory_bytes: 7684
#include <iostream>
using namespace std;
int main()
{
	int a, b;
  	cin >> a >> b;
  	if (a == 1) a += 13;
  	if (b == 1) b += 13;
  	if (a > b){
    	cout << "Alice";
    } else if (a < b){
    	cout << "Bob";
    } else {
    	cout << "Draw";
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

int main(void) {
  int W, H;
  vector<llint> p;
  scanf("%d %d", &W, &H);
  REP(i, W) {
    int x;
    scanf("%d", &x);
    p.push_back(2LL*x);
  }
  REP(i, H) {
    int x;
    scanf("%d", &x);
    p.push_back(2LL*x+1);
  }

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

  llint ans = 0;
  int cntx = W + 1, cnty = H + 1;
  for (llint q: p) {
    if (q % 2) {
      ans += cntx * (q / 2);
      cnty--;
    } else {
      ans += cnty * (q / 2);
      cntx--;
    }
  }

  printf("%lld\n", ans);
  return 0;
}


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

using namespace std;
typedef long long ll;

template<typename T, T mod>
struct modint {
private:
  T x;

public:
  modint(): x((T)0) {}
  modint(T y): x(y >= 0? y % mod: (mod - (-y) % mod) % mod) {}

  T get() {
    return x;
  }

  modint &operator+=(const modint &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }

  modint &operator-=(const modint &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  modint &operator*=(const modint &p) {
    x = x * p.x % mod;
    return *this;
  }

  modint &operator/=(const modint &p) {
    *this *= p.inverse();
    return *this;
  }

  modint operator-() const { return modint(-x); }
  modint operator+(const modint &p) const {return modint(*this) += p; }
  modint operator-(const modint &p) const {return modint(*this) -= p; }
  modint operator*(const modint &p) const {return modint(*this) *= p; }
  modint operator/(const modint &p) const {return modint(*this) /= p; }

  bool operator==(const modint &p) const { return x == p.x; }
  bool operator!=(const modint &p) const { return x != p.x; }

  modint inverse() const {
    T a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    return modint(u);
  }

  modint pow(int e) const {
    T a = 1, p = x;
    while(e > 0) {
      if (e % 2 == 0) {
	p = (p * p) % mod;
	e /= 2;
      } else {
	a = (a * p) % mod;
	e--;
      }
    }
    return modint(a);
  }
};

const long long MOD = 1000000007;

using mi = modint<long long, MOD>;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  vector<ll> poss;
  vector<ll> negs;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] > 0) poss.push_back(a[i]);
    else negs.push_back(a[i]);
  }
  sort(a.rbegin(), a.rend());
  sort(poss.rbegin(), poss.rend());
  sort(negs.begin(), negs.end());

  mi ans = 1;
  // handle all negatives
  if (poss.size() == 0 && k & 1) {
    int cur = n - 1;
    while (k--) {
      ans *= negs[cur--];
    }
    cout << ans.get() << '\n';
    return 0;
  }

  
  int fr = 0;
  int ba = n - 1;
  while (k > 1) {
    ll frm = a[fr] * a[fr + 1];
    ll bam = a[ba] * a[ba - 1];
    if (frm > bam) {
      ll ad = frm % MOD;
      ans *= ad;
      fr += 2;
    } else {
      ll ad = bam % MOD;
      ans *= ad;
      ba -= 2;
    }
    k -= 2;
  }
  
  if (k == 1) {
    ans *= a[fr];
  }

  cout << ans.get() << '\n';
  return 0;
}



Measured memory_bytes: 6908
s = input()
n = len(s)

def exec(i,num,f):
    if i == n-1:
        pass
        if num == 7:
            print(f+"=7")
            exit(0)
        else:
            return

    exec(i+1,int(num)+int(s[i+1]),f+"+"+s[i+1])
    exec(i+1,int(num)-int(s[i+1]),f+"-"+s[i+1])


exec(0,s[0],s[0])


Measured memory_bytes: 3060
#include <stdio.h>

int absl(int a){
  if(a>0){
    return a;
  }
  return -a;
}

int main(){
  int N,i;
  scanf("%d",&N);
  int x[N];int y[N];int h[N];
  for(i=0;i<N;i++){
    scanf("%d%d%d",&x[i],&y[i],&h[i]);
  }
  int cx,cy,H;
  int j=0;
  int flag;
  
  for(cx=0;cx<=100;cx++){
      for(cy=0;cy<=101;cy++){
      flag=0;j=0;
      while(h[j]==0){j++;}
      H=h[j]+absl(x[j]-cx)+absl(y[j]-cy);

      if(1<=j){
        for(i=0;i<j;i++){
          if(H-absl(x[i]-cx)-absl(y[i]-cy)>0){
            flag=1;
            break;
          }
        }
      }
      if(flag==0&&j==N-1){
	printf("%d %d %d",cx,cy,H);
	return 0;
      }
     
      for(i=j+1;i<N;i++){
	if(h[i]==0){
	  if(H-absl(x[i]-cx)-absl(y[i]-cy)>0) {
	    flag=1;
	    break;
	  }
	}
	if(h[i]>0){
	  if(h[i] != H-absl(x[i]-cx)-absl(y[i]-cy)) {
	    flag=1;
	    break;
	  }
	}
      }
      if(flag==0){
	printf("%d %d %d",cx,cy,H);
	return 0;
      }
    }
  }
  return 0;
}




	


Measured memory_bytes: 128
import java.util.*;
class Main{
    public static void main(String[] args){
	Scanner stdIn = new Scanner(System.in);
        int N = stdIn.nextInt();
	int[] n=new int[4];
	String result="No";
	for(int i=3;i>=0;i--){
	    n[i]=N%10;
	    N/=10;
	}
	if(n[3]==n[2]&&n[3]==n[1]){
	    result="Yes";
	}
	if(n[2]==n[1]&&n[2]==n[0]){
	    result="Yes";
	}
	System.out.println(result);
    }
}


Measured memory_bytes: 23508
import java.util.Scanner;

public class Main {

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

		String res = "";
		String s = sc.next();
		String t = sc.next();

		if (t.startsWith(s) && t.length()-1 == s.length()) {
			res = "Yes";
		} else {
			res = "No";
		}

		System.out.println(res);
	}
}


Measured memory_bytes: 35640
#include<stdio.h>
int main()
{
	int a,b,c,x=0;
	scanf("%d%d%d",&a,&b,&c);
	while(1){
		a=a-b;
		x++;
		if(a<=0) break;
	}
	printf("%d\n",c*x);
	return 0;
}


Measured memory_bytes: 1700
#include<stdio.h>
#include<stdlib.h>
#define A 100

int selectionSort(int *, int);

int main(){

  int a[A],n,i,count;

  scanf("%d",&n);
  
  if(n < 1 && n >100)exit(2);

  for(i = 0 ; i < n ; i++){
    scanf("%d",&a[i]);
  }
  count = selectionSort(a,n);
  
  for(i = 0 ; i < n-1 ; i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[i]);
  printf("%d\n",count);
  return 0;
}

int selectionSort(int *a,int n){
  int i,j;
  int num,minj,count=0;
    
  for(i = 0; i <= n-1  ; i++){
    minj = i;
    for(j = i; j <= n -1; j++){
      if(a[j] < a[minj]){
	minj = j;
      }
    }
    if(a[i] != a[minj]){
    num = a[minj];
    a[minj] = a[i];
    a[i] = num;
    count++;
    }
  }
  return count;
}
  



Measured memory_bytes: 2084
// https://atcoder.jp/contests/

#include <bits/stdc++.h>
#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int N, a, b, mc;
bool c[8];

int main()
{
  cin >> N;
  REP(i, N)
  {
    cin >> a;
    if (3200 <= a)
      mc++;
    else
      c[a / 400] = true;
  }
  b = count(c, c + 8, true);

  cout << max(1, b) << " " << b + mc << '\n';

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("Os")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b)
{
    return (a.first.second<b.first.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
void vok()
{
    FAST
    FO
    FI
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    // #endif
}
int main()
{
    vok();
    string s;
    IN s;
    if(s[0]=='7' || s[1]=='7' || s[2]=='7')
    {
        OUT "Yes"<<endl
    }
    else
    {
        OUT "No"<<endl
    }
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(){
  int l, r, d, cnt=0;
  scanf("%d %d %d", &l, &r, &d);
  for(int i=l; i<=r; i++){
    if( i%d==0 ){ cnt++; }
  }
  printf("%d", cnt);
  return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int x,y,z,k;
ll temp;
vector<ll> a,b,c;
vector<ll> apb;

int main(){
    cin >> x >> y >> z >> k;
    for(int i = 0; i < x; ++i){
        cin >> temp;
        a.push_back(temp);
    }
    for(int i = 0; i < y; ++i){
        cin >> temp;
        b.push_back(temp);
    }
    for(int i = 0; i < z; ++i){
        cin >> temp;
        c.push_back(temp);
    }
    sort(c.rbegin(),c.rend());
    
    for(int i = 0; i < x; ++i){
        for(int j = 0; j < y; ++j){
            apb.push_back(a[i]+b[j]);
        }
    }
    
    sort(apb.rbegin(),apb.rend());
    
    vector<ll> apbr;
    
    for(int i = 0; i < min(3000,x*y); ++i){
        apbr.push_back(apb[i]);
    }
    
    vector<ll> ans;

    for(int i = 0; i < min(3000,x*y); ++i){
        for(int j = 0; j < z; ++j){
            ans.push_back(apbr[i]+c[j]);
        }
    }

    
    sort(ans.rbegin(),ans.rend());
    
    for(int i = 0; i < min(k,3000); ++i){
        cout << ans[i] << endl;
    }
    
}



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

Data = list(map(int,input().split()))
Data.insert(0,0)
Data.append(0)

total = 0
pos = Data[0]
for i in range(1,N+2):
    total += abs(pos-Data[i])
    pos = Data[i]

for i in range(1,N+1):
    org = abs(Data[i-1]-Data[i]) + abs(Data[i]-Data[i+1])
    chg = abs(Data[i-1]-Data[i+1])
    ans = total-(org-chg)
    print(ans)


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

a=list(map(int,input().split()))
b=list(map(int,input().split()))

#a.sort()
#b.sort()

if a==b:
    print("Yes")
    exit()

suma=sum(a)
sumb=sum(b)


#sum(a)+2*k=sum(b)+k
#k=(sum(a)-sum(b))

k=sumb-suma
#
#1 1 1 6
#2 2 2 3

cnta=0
cntb=0
for i in range(n):
    if a[i]>b[i]:
        cntb+=a[i]-b[i]
    elif a[i]<b[i]:
        cnta+=(-1)*((a[i]-b[i])//2)
#print(k,cntb,cnta)
if cntb<=k and cnta<=k:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 10596
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

require 'bigdecimal'

MOD = 10 ** 9 + 7

N, K = get_ints
A = get_ints


X = []
A.each.with_index do |a, i|
  if i < K
    next
  else
    puts a <= A[i-K] ? 'No' : 'Yes'
  end
end


Measured memory_bytes: 35820
fun main(args: Array<String>)
{
    val n = readInt()
    val v = readNInts().sorted()

    var ans = (v[0] + v[1]) / 2.0

    for (i in 2..n-1) {
        ans = (ans + v[i]) / 2.0
    }

    println(ans
    )
}


// Read an integer
// Usage: val a = readInt()
private fun readInt() = readLine()!!.toInt()

// Read N integers separated by " "
// Usage: val (a, b, c) = readNInts()
private fun readNInts() = readLine()!!.split(" ").map(String::toDouble)

// Read a string
// Usage: val a = readString()
private fun readString() = readLine()!!


Measured memory_bytes: 38056
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    vector<int> t(n+1), x(n+1), y(n+1);
    t[0] = 0, x[0] = 0, y[0] = 0;
    for (int i = 1; i <= n; ++i) cin >> t[i] >> x[i] >> y[i];
    for (int i = 0; i < n; ++i)
    {
        int dt = t[i+1] - t[i];
        int dr = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if ((dt % 2) == (dr % 2) && dt >= dr)
        {
            continue;
        }
        else
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define print(x,y) (cout << (x) << (y))
#define inf INT_MAX
#define sz(x) (ll)x.size()
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair< int , pii> piii;
typedef pair<int,bool> pib;
typedef vector<pii> vii;
typedef vector<pib> vib;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<string,string> pss;
typedef vector<pss> vss;
const int MOD = 1e9 + 7; //998244353;


int main(){
   int n;
   cin >> n;
   int a[n][3];
   for(int i = 0;i<n;i++){
       cin >> a[i][0]  >> a[i][1] >> a[i][2];
   }
   int dp[n][3];
   for(int i = 0;i<n;i++){
       dp[i][0] = dp[i][1] = dp[i][2] = -inf;
   }
   dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    for(int i = 1;i<n;i++){
        for(int j = 0;j<3;j++){
            for(int k = 0;k<3;k++){
                if(j == k)continue;
                dp[i][j] = max(dp[i][j] , dp[i-1][k] + a[i][j]);
            }
        }
    }
    int res = 0;
    for(int i : dp[n-1])res = max(res , i);
    cout << res;
}





Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){
  int n;
  cin >> n;
  int a[n+10];
  rep(i,n){
    cin >> a[i];
  }
  unordered_map<int,int> mp;
  rep(i,n){
    mp[a[i]]=i+1;
  }
  rep(i,n){
    cout << mp[i+1] << " " ;
  }
  cout << endl;
}

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

Measured memory_bytes: 5284
N = int(input())
lst = [input() for x in range(N)]
if len(lst) != len(set(lst)):
    print('No')
    exit(0)

s = lst[0][-1]
for x in lst[1:]:
    if s != x[0]:
        print('No')
        exit(0)
    s = x[-1]
print('Yes')    

Measured memory_bytes: 3064
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

int main()
{
    int X, A, B;
    cin >> X >> A >> B;
    if (abs(X - A) < abs(X - B))
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "B" << endl;
    }
    return 0;
}

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

int solve(vector<vector<int>> &dp, vector<vector<int>> &p, int i, int last){
    if(i == p.size()){
        return 0;
    }
    if(dp[i][last] != -1){
        return dp[i][last];
    }
    int ans = INT_MIN;
    for(int j = 0; j < 3; ++j){
        if(j != last){
            ans = max(ans, p[i][j] + solve(dp, p, i+1, j));
        }
    }
    return dp[i][last] = ans;
}

int main(){
    int n;
    cin>>n;
    vector<vector<int>> p(n+1, vector<int>(3, 0));
    vector<vector<int>> dp(n+1, vector<int> (3, -1));
    for(int i = 1; i <= n; ++i){
        cin>>p[i][0];
        cin>>p[i][1];
        cin>>p[i][2];
    }
    int ans = max({p[1][0]+solve(dp, p, 2, 0), p[1][1]+solve(dp, p, 2, 1), p[1][2]+solve(dp, p, 2, 2)});
    cout<<ans;
    return 0;
}


Measured memory_bytes: 23584
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    map<int, int> mp;
    REP(i, n)
    {
        cin >> a[i];
        mp[i - a[i]]++;
    }
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        int x = a[i] + i;
        cnt += mp[x];
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 29004
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n); rep (i, n) cin >> a[i];
    int ans = 0;
    rep (i, n) if (a[a[i] - 1] - 1 == i) ans++;
    cout << ans / 2 << "\n";
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll n;
vector<ll> E[200010];
bool used[200010];
set<ll> s;
void dfs(int x){
    used[x]=1;
    s.insert(x);
    for(auto &to: E[x]){
        if(!used[to]){
            used[to]=1;
            for(auto &nexto: E[to]){
                if(!used[nexto]){
                    dfs(nexto);
                }
            }
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    rep(i,0,n){
        int x,y;
        cin>>x>>y;
        x--; y--;
        E[x].pb(y+100000); E[y+100000].pb(x);
    }
    ll ans=0;
    rep(i,0,100000){
        if(!used[i]){
            s.clear();
            dfs(i);
            ll cnt=0;
            set<ll> t;
            for(auto &e : s){
                cnt+=sz(E[e]);
                for(auto &to :E[e]){
                    t.insert(to);
                }
            }
            ans+=ll(sz(s))*sz(t)-cnt;
        }
    }
    cout <<ans<<"\n";
}

Measured memory_bytes: 14848
n=int(input())
s=[str(x) for x in input()]
exi=[]
for i in range(n):
    if s[i] not in exi:
        exi.append(s[i])
    if len(exi)==10:
        break
ans=0
for i in exi:
    star=s.index(i)
    lex=[]
    for j in range(star+1,n):
        if s[j] not in lex:
            lex.append(s[j])
        if len(lex)==10:
            break
    for k in lex:
        start=s[star+1:n].index(k)+star+1
        ele=[]
        for l in range(start+1,n):
            if s[l] not in ele:
                ele.append(s[l])
        ans += len(ele)

print(ans)

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

long long int* arr1=new long long int[100005];
long long int* a=new long long int[100005];

long long int min(long long int a, long long int b)
{
	if(a<=b)
	return a;
	return b;
}

long long int mod(long long int a)
{
	if(a<=0)
	return -1*a;
	else
	return a;
}

long long int rec(long long int k, long long int n)
{
	long long int s1=0, s2=0;
	if(k>=n-1)
	{
		arr1[k]=0;
		return arr1[k];
	}
	else if(k==n-2)
	{
		if(arr1[k]==-1)
			arr1[k]=mod(a[k+1]-a[k]);
		return arr1[k];
		
	}
	if(arr1[k+1]==-1)
	arr1[k+1]=rec(k+1, n);
	if(arr1[k+2]==-1)
	arr1[k+2]=rec(k+2, n);
	arr1[k]=min(arr1[k+1]+mod(a[k+1]-a[k]), arr1[k+2]+mod(a[k+2]-a[k]));
	
	return arr1[k];
}

int main() {
	// your code goes here
	long long int i, n;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<n+5;i++)
		arr1[i]=-1;
	cout<<rec(0, n)<<endl;
	return 0;
}

Measured memory_bytes: 6528
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
long long int n, a[100005], val[100005],set[100005];
int findSet(int x) {
	if (set[x] == x)
		return x;
	return set[x] = findSet(set[x]);
}

void unionSet(int x, int y) {
	int fx = findSet(x);
	int fy = findSet(y);
	if(fx!=fy)
		set[fx] = fy;
}
struct road {
	long long int len,turn1,turn2;
};
struct road rx[100005],ry[100005];
struct point {
	long long int x,y,turn;
};
struct point po[100005],po2[100005];
bool cmp(struct point p1, struct point p2) {
	if(p1.x<p2.x)	return true;
	if(p1.x>=p2.x)	return false;
}
bool cmp2(struct point p1, struct point p2) {
	if(p1.y<p2.y)	return true;
	if(p1.y>=p2.y)	return false;
}

bool cmprx(struct road r1, struct road r2) {
	if(r1.len<r2.len)	return true;
	if(r1.len>=r2.len)	return false;
}
bool cmpry(struct road r1, struct road r2) {
	if(r1.len<r2.len)	return true;
	if(r1.len>=r2.len)	return false;
}
int main() {
	int i,j;
	scanf("%lld",&n);
	for(int i=0; i<=n; i++)	set[i] =i;
	for(i=0; i<n; i++) {
		scanf("%lld%lld",&po[i].x,&po[i].y);
		po2[i].x = po[i].x;
		po2[i].y = po[i].y;
		po[i].turn = i+1;
		po2[i].turn = i+1;
	}
	sort(po,po+n,cmp);
	sort(po2,po2+n,cmp2);
//	printf("\n");
//	for(i=0; i<n; i++) {
//		printf("%lld %lld\n",po[i].x,po[i].y);
//	}
//	printf("\n");
//	for(i=0; i<n; i++) {
//		printf("%lld %lld\n",po2[i].x,po2[i].y);
//	}



	for(i=1; i<n; i++) {
		rx[i-1].turn1 = po[i-1].turn;
		rx[i-1].turn2 = po[i].turn;
		rx[i-1].len = fabs(po[i-1].x - po[i].x);
	}
	for(i=1; i<n; i++) {
		ry[i-1].turn1 = po2[i-1].turn;
		ry[i-1].turn2 = po2[i].turn;
		ry[i-1].len = fabs(po2[i-1].y - po2[i].y);
	}
	sort(rx,rx+n-1,cmprx);
	sort(ry,ry+n-1,cmpry);
	long long int ans = 0;
	int fc1=0,fc2=0;
	int count = 0;
	for(; count<n-1; ) {
		long long int r1 = rx[fc1].len, r2 = ry[fc2].len;
		if(r1<r2) {
			if(findSet(rx[fc1].turn1)!=findSet(rx[fc1].turn2)) {
				ans+=rx[fc1].len;
				unionSet(rx[fc1].turn1,rx[fc1].turn2);
				count++;
			}
			fc1++;
		} else {
			if(findSet(ry[fc2].turn1)!=findSet(ry[fc2].turn2)) {
				ans+=ry[fc2].len;
				unionSet(ry[fc2].turn1,ry[fc2].turn2);
				count++;
			}
			fc2++;
		}
	}

	printf("%lld",ans);
//	printf("\n");
//	for(i=0; i<n-1; i++) {
//		printf("%lld\n",road[i]);
//	}
	return 0;
}



Measured memory_bytes: 10496
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  ll h;
  cin >>h;
  ll ans =1;
  ll c = 1;
  while(h>1){
    c*=2;
    ans+=c;
    h/=2;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
/* -- template -- */
ll dp[6][4001][3];
int N;
string S;

void ff(char r, char b, int patern) {
    for(int i = 0;i < N;++i){
        rep(j, 3)
            dp[patern][i + 1][j] = dp[patern][i][j];
        if(S[i] == r)
            dp[patern][i + 1][0] += 1;
        else if(S[i] == b)
            dp[patern][i + 1][1] += dp[patern][i][0];
        else
            dp[patern][i + 1][2] += dp[patern][i][1];
    }
}

int main() {
    cin >> N;
    cin >> S;
    ll ans = 0;
    ff('R', 'G', 0);
    ff('R', 'B', 1);
    ff('B', 'R', 2);
    ff('B', 'G', 3);
    ff('G', 'R', 4);
    ff('G', 'B', 5);
    rep(i, 6)
        ans += dp[i][N][2];
    for(int i = 0;i < N;++i) {
        for(int j = 0;i + 2 * j < N;++j) {
            if((S[i] != S[i + j]) && (S[i + j] != S[i + 2 * j]) && (S[i] != S[i + 2 * j]))
                --ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4152
/***********************************************************
	When you are inspired by passion 
	and you want to live for the current moment

	When your every thought and action
	has the power to become the story of your future

	When difficulties stand to demolish your Glory
	Just remember that Life is a 'Golden adverse Story'

	Withstand it to acheive your passion and dreams
	more amazingly more easily.

	Why then? When writing the story of your Life
	You want to Let someone else hold your pen

					huzaifa242©

***********************************************************/
#include "bits/stdc++.h"
using namespace std;
#define int int32_t
#define MAX 100005
#define x first 
#define y second

int seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = numeric_limits <int>::max())
{return uniform_int_distribution<int> (l, r)(rng);}

template <typename T, typename G>
ostream& operator << (ostream& out, const pair <T, G> &a) 
{return out << "( " << a.x << ", " << a.y << ")";}

template <typename T>
ostream& operator << (ostream& out, const vector <T> &a) 
{out << "[ "; for(const auto &i: a) out << i << ", "; return out << "]" << endl;}

template <typename T>
ostream& operator << (ostream& out, const set <T> &a) 
{out << "{ "; for(const auto &i: a) out << i << ", "; return out << "}" << endl;}

template <typename T, typename G>
ostream& operator << (ostream& out, const map <T, G> &a) 
{out << "< "; for(const auto &i: a) out << i << ", "; return out << ">" << endl;}

template <typename T, size_t N>
typename enable_if<!is_same <typename remove_cv <T>::type, char>::value,
ostream&>::type operator << (ostream& out, T (&a)[N])
{out << "[ "; for(const auto &i: a) out << i << ", "; return out << "]" << endl;}

void debug_out(){cerr << endl;} 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{cerr << (H) << ' '; debug_out(T...);}
 
#ifdef LOCAL
#define debug(...) cerr << '#' << #__VA_ARGS__ << ":\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 24
#endif

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n, c = 1000;
	cin >> n;
	while (c < n)
		c += 1000;
	cout << c - n << '\n';
	return 0;
}


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

int main()
{
    int a,b, cislo = 0;
    scanf("%d", &a);
    scanf("%d", &b);

    if((a<=50000000)&&(b<=50000000)){
        for(int i=0; i <= 50000000; i++){
            if( abs(a-i)==abs(b-i)){
                cislo = i;
                break;
            }
            else{
            }
        }
    }
    else {
        for(int i=0; i <= 1000000000; i++){
            if( abs(a-i)==abs(b-i)){
                cislo = i;
                break;
            }
            else{
            }
        }
    }

    if(cislo == 0){
        printf("IMPOSSIBLE");
    }
    else{
        printf("%d", cislo);
    }

    return 0;
}


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

typedef unsigned long long ULL;
typedef long long LL;

const int PI = 3.1415926535;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 200007;


int n, m, mark[N], curr;
vector <int> graph[N];
set <pair<int, int>> S;


void dfs(int s, int p) {
	mark[s] = 1;
	curr++;
	for (auto v: graph[s]) {
		if (mark[v] == 0) {
			dfs(v, s);
		}
	}
}


int main() {
	
	ios_base :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		--a; --b;
		if (S.find({a, b}) == S.end() && S.find({b, a}) == S.end()) {
			graph[a].push_back(b);
			graph[b].push_back(a);
			S.insert({a, b});
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		curr = 0;
		if (mark[i] == 0) {
			dfs(i, -1);
			//ans += curr - 1;
			ans = max(ans, curr);
		}
	}
	cout << ans << "\n";
	return 0;
}


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

int main() {
	int N;
	cin >> N;	
	
	int M = 2*N;
	vector<int> L(M);
	for(int i=0; i<M;i++) cin >> L[i];
	
	sort(L.begin(), L.end());
	
	int sum =0;
	for(int x=0; x<2*N; x+=2) 
		sum += L[x];
	cout << sum << '\n';
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

vector<int> G[100100];

int dfs(int v){
    map<int, int> rets;
    for(auto&& next : G[v]){
        int ret = dfs(next);
        rets[ret]++;
    }

    int val = 0;
    for(auto&& p : rets){
        int r = p.first;
        int n = p.second;
        if(val < r+1) val = r+n;
        else{
            val += n;
        }
    }

    return val;
}

int main(){
    int N;
    cin >> N;
    REP(i,N-1){
        int a;
        cin >> a;
        a--;
        G[a].push_back(i+1);
    }

    int ans = dfs(0);

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


Measured memory_bytes: 18176
s = input()
m = 0
count = 0

for x in s:
    if x in 'A':
        count +=1
    elif x in 'C':
        count +=1
    elif x in 'G':
        count +=1
    elif x in 'T':
        count +=1
    else:
        count = 0
    m = max(m,count)
print(m)

Measured memory_bytes: 2940
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;

int main() {
	int n,k,i(0);
	cin >> n >> k;
	while (n) {
		//static int i = 0;
		n = n / k;
		//cout << n;
		++i;
	}
	cout << i << endl;
}

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

int main(){
  int n,max=0;
  int a[101];
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(max<a[i]-a[j]){max=a[i]-a[j];}
    }
  }
  cout << max;
}

Measured memory_bytes: 3656