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

class Dice{
public:
    int s[6];
    // s[0] : top
    // s[1] : south  front
    // s[2] ; east  right
    // s[3] : west  left
    // s[4] : north  back
    // s[5] : bottom
    void roll(char c){
        //  N
        // W E
        //  S
        int b;
        if(c == 'E'){
            b = s[0]; s[0] = s[3]; s[3] = s[5]; s[5] = s[2]; s[2] = b;
        }
        if(c == 'W'){
            b = s[0]; s[0] = s[2]; s[2] = s[5]; s[5] = s[3]; s[3] = b;
        }
        if(c == 'N'){
            b = s[0]; s[0] = s[1]; s[1] = s[5]; s[5] = s[4]; s[4] = b;
        }
        if(c == 'S'){
            b = s[0]; s[0] = s[4]; s[4] = s[5]; s[5] = s[1]; s[1] = b;
        }
        // clock rotate
        if(c == 'R'){
            b = s[1]; s[1] = s[2]; s[2] = s[4]; s[4] = s[3]; s[3] = b;
        }
        // counter clock rotate
        if(c == 'L'){
            b = s[1]; s[1] = s[3]; s[3] = s[4]; s[4] = s[2]; s[2] = b;
        }
    }
    int hash(){
        int res = 0;
        for(int i = 0; i < 6; i++) res = res * 256 + s[i];
        return res;
    }
};

int main(){
    Dice d;
    for(int i = 0; i < 6; i++){
        cin >> d.s[i];
    }
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        d.roll(s[i]);
    }
    cout << d.s[0] << endl;
}


Measured memory_bytes: 3180
import sys
import collections
import copy
import math
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
N,M =map(int,input().split())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
count = 0
while count != M:
    chk =A[0]//2
    for i in range(len(A)):
        if A[i] >= chk:
            A[i] = A[i]//2
            count += 1
            if count == M:
                break
        else:
            A.sort(reverse=True)
            break
print(sum(A))


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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define ALL(a) a.begin(), a.end()
#define FOR(x,to) for(x=0;x<(to);x++)

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

ll dp[E5];

void solve() {	
	ll N,Y;
	cin >> N >> Y;
	for (ll i = 0; i <= 2000; ++i) {
		for (ll j = 0; j <= 2000; ++j) {
			ll k = N-i-j;
			if (k < 0) {
				continue;
			}
			if (i*10000+j*5000+k*1000 == Y) {
				cout << i << ' ' << j << ' ' << k; 
				return;
			}
		}
	}

	cout << "-1 -1 -1\n";
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 256
def main():
    l = int(input())
    # l = a + b + c 
    # c = l - a - b
    # v = ab(l-a-b)
    # v = b(-a**2 + (l-b)a)
    # v = b(-(a-(l-b)/2)**2 + (l-b)/2)**2)
    # a = (l-b)/2のときv_max=b*(（l-b）/2)**2
    # v_max = b(b**2 - 2*l*b + l**2)/4
    # v_max = (b**3 - 2*l*b**2 + l**2*b)/4
    # v_max' = (3*b**2 - 4*l*b + l**2)/4
    # v_max' = (3*b-l) * (b-l) / 4
    # 0 > b > l/3の時 単調増加
    # l/2 > b > 1 の時単調減少  
    # b = l/3の時v_maxとなる
    # a = (l-l/3)/2 = l/3
    ans = (l/3) ** 3
    print(ans)
     
if __name__ == '__main__':
    main()


Measured memory_bytes: 9420
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

N, X = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
numbers = [abs(i - X) for i in x]

answer = numbers[0]
for i in numbers:
  answer = gcd(answer, i)
print(answer)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

int main() {
  i64 N;
  cin >> N;
  vector<string> S(N);
  rep(i,0,N) cin >> S[i];

  vector<pair<i64, i64>> left;
  vector<pair<i64, i64>> right;

  i64 sum = 0;
  rep(i,0,N) {
    string s = std::move(S[i]);
    i64 now = 0;
    i64 MIN = 0;
    i64 MAX =0 ;
    rep(j,0,s.size()) {
      if(s[j] == '(') {
        now++;
      }
      else {
        now--;
      }
      MIN = std::min(MIN, now);
      MAX = std::max(MAX, now);
    }
    sum += now;
    if(now >= 0) {
      left.push_back({ -MIN, now });
    }
    else {
      right.push_back({ -MIN + now, -now });
    }
  }
  if(sum != 0) {
    cout << "No" << endl;
    return 0;
  }

  sort(all(left));
  sort(all(right));
  {
    i64 now = 0;
    for(auto p: left) {
      if(now < p.first) {
        cout << "No" << endl;
        return 0;
      }
      now += p.second;
    }
    now = 0;
    for(auto p: right) {
      if(now < p.first) {
        cout << "No" << endl;
        return 0;
      }
      now += p.second;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

vector<int> parent;

int find(int x){
  if(parent.at(x)==x){
    return x;
  }else{
    return parent.at(x)=find(parent.at(x));
  }
}

void unite(int a, int b){
  int x=find(a);
  int y=find(b);
  //cout<<x<<"_"<<y<<endl;
  if(x!=y){
    parent.at(x)=y;
  }
}

int main(){
  int N,M,K;
  cin>>N>>M>>K;
  parent.resize(N);
  vector<int> A(M),B(M),C(K),D(K);
  for(int i=0;i<M;i++){
    cin>>A.at(i)>>B.at(i);
    A.at(i)--;
    B.at(i)--;
  }
  for(int i=0;i<K;i++){
    cin>>C.at(i)>>D.at(i);
    C.at(i)--;
    D.at(i)--;
  }

  for(int i=0;i<N;i++){
    parent.at(i)=i;
  }
  vector<int> count(N,0);
  //cout<<"hello"<<endl;
  //cout<<N<<" "<<M<<" "<<K<<endl;
  for(int i=0;i<M;i++){
    //cout<<"hello"<<" "<<i<<" ";
    int x=A.at(i);
    int y=B.at(i);
    count.at(x)--;
    count.at(y)--;
    //cout<<x<<"_"<<y<<" ";
    unite(x,y);
    //cout<<"hello"<<endl;
  }
  //cout<<"hello"<<endl;
  vector<int> group(N,0);
  for(int i=0;i<N;i++){
    group.at(find(i))++;
    //cout<<count.at(i)<<" ";
  }
  for(int i=0;i<N;i++){
    count.at(i)+=group.at(parent.at(i))-1;
    //cout<<count.at(i);
  }
  for(int i=0;i<K;i++){
    if(find(C.at(i))==find(D.at(i))){
      //cout<<C.at(i)<<" "<<D.at(i)<<endl;
      count.at(C.at(i))--;
      count.at(D.at(i))--;
    }
  }
  for(int i=0;i<N;i++){
    cout<<count.at(i)<<" ";
  }
  cout<<endl;
}


Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <queue>
typedef long long ll;
using namespace std;
const int mod=1e9+7;
const ll inf=(1e14);

void solve(){
	int n,m;
	cin>>n>>m;
	vector<vector<int> > adj(n);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v; u--,v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	vector<int> vis(n);
	vector<int> p(n);
	queue<int> q;
	q.push(0);vis[0]=0;
	while(q.size()){
		int x=q.front();
		q.pop();
		for(int ni:adj[x]){
			if(!vis[ni]){
				vis[ni]=vis[x]+1;
				q.push(ni);
				p[ni]=x;
			}
		}
	}
	for(int d:vis){
		if(!d){
			cout<<"No";
			return;
		}
	}
	cout<<"Yes\n";
	for(int i=1;i<n;i++) cout<<p[i]+1<<' ';

}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int t=1;
    //cin>>t;
    //while(t--) cout<<solve()<<'\n';
    while(t--) solve(),cout<<'\n';
    return 0;
}


Measured memory_bytes: 10612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if ((a * b) % 2 == 0) {
			System.out.println("Even");
		} else {
			System.out.println("Odd");
		}
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}

int main()
{
    FAST();

    ll int n,m,a,b,res,ara[sz];
cin>>n>>m;
if(m%2||m/2<n){cout<<"No"<<endl;return 0;}
res=m/2;
if(res>n*2)cout<<"No"<<endl;
else cout<<"Yes"<<endl;

}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int a[10][10];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t,i,j,n,m,l,r,f,ans=0,c[10];
    cin>>n>>m;
    for(i=0;i<m;i++){
        cin>>l>>r;
        a[l][r]=1;
        a[r][l]=1;
    }
    for(i=0;i<n;i++){
        c[i]=i+1;
    }
    do{
        f=0;
        for(i=1;i<n;i++){
            if(a[c[i-1]][c[i]]==0){
                f=1;
                break;
            }
        }
        if(f==0){
            ans++;
        }
    }while(next_permutation(c+1,c+n));
    cout<<ans<<"\n";
    return 0;
}

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

int main() {
    int64_t N, S;
    cin >> N >> S;
    vector<int64_t> A(N);
    for (int64_t& a : A) {
        cin >> a;
    }

    constexpr int64_t MOD = 998244353;

    //dp[i][j][k] := i番目まで見て、選んだ要素の和がjで、決めた感じがkのとき
    vector<vector<vector<int64_t>>> dp(N + 1, vector<vector<int64_t>>(S + 1, vector<int64_t>(3, 0)));
    dp[0][0][0] = 1;

    for (int64_t i = 0; i < N; i++) {
        for (int64_t j = 0; j <= S; j++) {
            //A[i]を選ぶ
            if (j + A[i] <= S) {
                //Lを決める
                (dp[i + 1][j + A[i]][1] += dp[i][j][0] + dp[i][j][1]) %= MOD;
                //LもRも決める
                (dp[i + 1][j + A[i]][2] += dp[i][j][0] + dp[i][j][1]) %= MOD;
            }

            //A[i]を選ばない
            //Lを決めない
            (dp[i + 1][j][0] += dp[i][j][0]) %= MOD;
            //Lを決める
            (dp[i + 1][j][1] += dp[i][j][0] + dp[i][j][1]) %= MOD;
            //LもRも決める
            (dp[i + 1][j][2] += dp[i][j][0] + dp[i][j][1] + dp[i][j][2]) %= MOD;
        }
    }

    cout << dp[N][S][2] << endl;
}

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

#define ll long long int

using namespace std;

ll unit;

struct Query{
  ll left;
  ll right;
  ll index;
  ll counter;
};

bool cal_compare(Query data1, Query data2)
{
  if (data1.left / unit != data2.left / unit)
    return data1.left < data2.left;

  return data1.right < data2.right;
}

bool out_compare(Query data1, Query data2)
{
  return data1.index < data2.index;
}

void calculate(vector<ll>& elements, ll element_num, 
	       vector<Query>& queries, ll query_num)
{
  unit = sqrt(element_num);

  sort(queries.begin(), queries.end(), cal_compare);
  
  ll prev_left = 0, prev_right = 0, prev_counter = 1;
  vector<ll> categories(element_num, 0);
  categories[elements[0]]++;

  for (int i = 0; i < query_num; i++){
    ll curr_left = queries[i].left, curr_right = queries[i].right;

    while (curr_left > prev_left){
      categories[elements[prev_left]]--;
      if (categories[elements[prev_left]] == 0)
	prev_counter--;
      prev_left++;
    }
    
    while (curr_left < prev_left){
      prev_left--;
      if (categories[elements[prev_left]] == 0)
	prev_counter++;
      categories[elements[prev_left]]++;
    }

    while (curr_right > prev_right){
      prev_right++;
      if (categories[elements[prev_right]] == 0)
	prev_counter++;
      categories[elements[prev_right]]++;
    }

    while (curr_right < prev_right){
      categories[elements[prev_right]]--;
      if (categories[elements[prev_right]] == 0)
	prev_counter--;
      prev_right--;
    }

    queries[i].counter = prev_counter;
  }
}

void output(vector<Query>& queries, ll query_num)
{
  sort(queries.begin(), queries.end(), out_compare);
  for (int i = 0; i < query_num; i++)
    cout << queries[i].counter << '\n';
}

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

  ll element_num, query_num;

  cin >> element_num >> query_num;

  vector<ll> elements(element_num);
  vector<Query> queries(query_num);

  for (int i = 0; i < element_num; i++)
    cin >> elements[i];

  for (int i = 0; i < query_num; i++){
    cin >> queries[i].left >> queries[i].right;
    queries[i].left--;
    queries[i].right--;
    queries[i].index = i;
  }

  calculate(elements, element_num, queries, query_num);
  output(queries, query_num);
  return 0;
}


Measured memory_bytes: 26676
import sys
readline = sys.stdin.readline

N,M,R = map(int,readline().split())
r = list(map(int,readline().split()))
INF = 10 ** 10

G = [[INF] * N for i in range(N)]
for i in range(M):
  a,b,c = map(int,readline().split())
  G[a - 1][b - 1] = c
  G[b - 1][a - 1] = c
  
for i in range(N):
  G[i][i] = 0
  
for k in range(N):
  for i in range(N):
    for j in range(N):
      G[i][j] = min(G[i][j], G[i][k] + G[k][j])
      
import itertools
ans = INF
for perm in itertools.permutations(range(R)):
  dist = 0
  for i in range(1, len(perm)):
    dist += G[r[perm[i - 1]] - 1][r[perm[i]] - 1]
  if ans > dist:
    ans = dist
    
print(ans)


Measured memory_bytes: 74412
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    final static long MOD = 1000000007;

    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int k = scanner.nextInt();
        final long[] array = new long[n];
        for (int i = 0; i < n; i++) {
            array[i] = scanner.nextLong();
        }

        if (k == 1) {
            System.out.println(0);
            return;
        }

        Arrays.sort(array);

        final CombinationCalculator combinationCalculator = new CombinationCalculator(n + 1, (int) MOD).init();

        long sum = 0;
        for (int i = 0; i <= n - k; i++) {
            sum += array[n - 1 - i] * combinationCalculator.calc(n - 1 - i, k - 1) % MOD;
            sum %= MOD;
            sum -= array[i] * combinationCalculator.calc(n - 1 - i, k - 1) % MOD;
            sum %= MOD;
        }

        System.out.println((sum + MOD) % MOD);
    }

    private static class CombinationCalculator {
        private final int size;
        private final int mod;
        private final long[] factorials;
        private final long[] invertedElements;
        private final long[] invertedFactorials;

        CombinationCalculator(final int size, final int mod) {
            this.size = size;
            this.mod = mod;
            this.factorials = new long[size];
            this.invertedElements = new long[size];
            this.invertedFactorials = new long[size];
        }

        CombinationCalculator init() {
            factorials[0] = 1;
            factorials[1] = 1;
            invertedFactorials[0] = 1;
            invertedFactorials[1] = 1;
            invertedElements[1] = 1;
            for (int i = 2; i < size; i++) {
                factorials[i] = factorials[i - 1] * i % mod;
                invertedElements[i] = mod - invertedElements[mod % i] * (mod / i) % mod;
                invertedFactorials[i] = invertedFactorials[i - 1] * invertedElements[i] % mod;
            }
            return this;
        }

        long calc(final int n, final int k) {
            return factorials[n] * (invertedFactorials[k] * invertedFactorials[n - k] % mod) % mod;
        }
    }
}


Measured memory_bytes: 58028
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
typedef double db;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int N=5e4+10;

int gcd(int x,int y) {return y?gcd(y,x%y):x;}

int vis[N],ps[N],tn;
void sieve(int n) {
	rep(i,2,n+1) {
		if (!vis[i]) ps[tn++]=i;
		for (int j=0;j<tn&&i*ps[j]<=n;j++) {
			vis[i*ps[j]]=1;
			if (i%ps[j]==0) break;
		}
	}
}

int a[N],n;

bool check(int p) {
	if (a[0]%p) return false;
	// printf("%d: ",p);
	static int f[N];
	rep(i,0,n+1) f[i]=(a[i]%p+p)%p;
	per(i,0,n-p+1) {
		int j=i+p;
		f[i+1]=(f[i+1]+f[j])%p;
		f[j]=0;
	}
	// rep(i,0,n+1) printf("%d ",f[i]); puts("");
	rep(i,0,n+1) if (f[i]) return false;
	return true;
}

set<int> ans;

int main() {
#ifdef LOCAL
	freopen("a.in","r",stdin);
#endif
	scanf("%d",&n),sieve(n);
	int g=0;
	per(i,0,n+1) scanf("%d",&a[i]),g=gcd(g,abs(a[i]));
	for (int i=2;i*i<=g;i++) {
		if (g%i==0) {
			ans.insert(i);
			while (g%i==0) g/=i;
		}
	}
	if (g!=1) ans.insert(g);
	rep(i,0,tn) if (check(ps[i])) ans.insert(ps[i]);
	for (auto p:ans) printf("%d\n",p);
	return 0;
}

Measured memory_bytes: 384
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(long[]);
    auto BS = readln.split.to!(long[]);

    long r;
    foreach (i; 0..N) {
        if (BS[i] <= AS[i]) {
            r += BS[i];
        } else {
            r += AS[i];
            auto d = BS[i] - AS[i];
            if (AS[i+1] < d) {
                r += AS[i+1];
                AS[i+1] = 0;
            } else {
                r += d;
                AS[i+1] -= d;
            }
        }
    }
    writeln(r);
}

Measured memory_bytes: 9708
import sys
sys.setrecursionlimit(100000000)
import collections
import math

MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))


def eratosthenes(n):  #エラトステネスの篩
    sieve = [True for _ in range(n + 1)]
    sieve[0] = False
    sieve[1] = False

    def _update(p):
        if sieve[p]:
            for i in range(p * 2, n + 1, p):
                sieve[i] = False

    if n > 1:
        _update(2)
    p = 3
    while p * p <= n:
        _update(p)
        p += 2
    return sieve


def factorize(n, primes):        # 素数の値をカウントする
    if n < 2:
        return dict()
    counter = collections.Counter()
    for p in primes:
        while n % p == 0:
            counter[p] += 1
            n //= p
        if n == 1:
            break
    if n > 1:
        counter[n] += 1
    return counter


if n == 1:
    print(1)
    exit()

sieve = eratosthenes(10 ** 3)
primes = [x for x, b in enumerate(sieve) if b]

lcm = collections.Counter()
for x in a:
    counter = factorize(x, primes)
    for p, k in counter.items():
        lcm[p] = max(lcm[p], k)
lcm_val = 1
for p, k in lcm.items():  # 各素因数と個数
    lcm_val *= pow(p, k, MOD)
    #lcm_val %= MOD       # 最小公倍数


res = 0
for x in a:
    res += lcm_val * pow(x, MOD - 2, MOD)  # 最小公倍数lcm_val / 各値x の余り 逆元をとる
    res %= MOD
print(res)

Measured memory_bytes: 4980
#include <bits/stdc++.h>
#define LL long long 
#define MAXN 300005
#define INF 0x3f3f3f3f
using namespace std;
 
int n, a, b, cnt=0;
bool vis[600000];
 
int main()
{
	
	scanf("%d%d", &a, &b);
	printf("%d\n", (b-a+1)*(b-a)/2-b);
}

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <string>
#include <vector>

class TUser
{
	std::list<TUser*> FFriends;
	int FGroupIndex;
public:
	TUser();
	
	void AddFriend(TUser* Friend);
	bool InviteFriends(int GroupIndex);
	int GroupIndex()const {return FGroupIndex;}
};

TUser::TUser()
:FGroupIndex(0)
{
}

void TUser::AddFriend(TUser* Friend)
{
	FFriends.push_back(Friend);
}

bool TUser::InviteFriends(int GroupIndex)
{
	if(FGroupIndex > 0) return false;
	FGroupIndex = GroupIndex;
	for(std::list<TUser*>::iterator It = FFriends.begin(); It != FFriends.end(); ++It){
		(*It)->InviteFriends(GroupIndex);
	}
	return true;
}

class TSns
{
	std::vector<TUser> FUsers;
public:
	TSns(int UserCount);
	
	void MakeGroups();
	void AddLink(int UserA, int UserB);
	std::string IsAccesible(int UserA, int UserB)const;
};
 
TSns::TSns(int UserCount)
: FUsers(UserCount)
{
}
 
void TSns::AddLink(int UserA, int UserB)
{
	FUsers[UserA].AddFriend(&FUsers[UserB]);
	FUsers[UserB].AddFriend(&FUsers[UserA]);
}

void TSns::MakeGroups()
{
	int GroupIndex = 1;
	for(unsigned int i = 0; i < FUsers.size(); ++i){
		if(FUsers[i].InviteFriends(GroupIndex)) ++GroupIndex;
	}
}

std::string TSns::IsAccesible(int UserA, int UserB)const
{
	if(FUsers[UserA].GroupIndex() == FUsers[UserB].GroupIndex()) return "yes";
	return "no";
}

int main()
{
	int UserCount;
	std::cin >> UserCount;
	TSns Sns(UserCount);
	
	int LinkCount;
	std::cin >> LinkCount;
	for(int i = 0; i < LinkCount; ++i){
		int UserA, UserB;
		std::cin >> UserA >> UserB;
		Sns.AddLink(UserA, UserB);
	}
	
	Sns.MakeGroups();
	
	int QuestionCount;
	std::cin >> QuestionCount;
	for(int i = 0; i < QuestionCount; ++i){
		int UserA, UserB;
		std::cin >> UserA >> UserB;
		std::cout << Sns.IsAccesible(UserA, UserB) << std::endl;
	}
	return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

class UnionFind {
private:
	int n;
	vector<int> a;
public:
	UnionFind(int n) : n(n), a(n, -1) {}
	int find(int x) { return a[x] < 0 ? x : (a[x] = find(a[x])); }
	bool same(int x, int y) { return find(x) == find(y); }
	bool same(ii& p) { return same(p.first, p.second); }
	bool unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return false;
		if (a[x] > a[y]) swap(x, y);
		a[x] += a[y];
		a[y] = x;
		n--;
		return true;
	}
	bool unite(ii& p) { return unite(p.first, p.second); }
	int size() const { return n; }
	int size(int x) { return -a[find(x)]; }
};

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

	vii vp;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		
		vp.emplace_back(a, b);
	}

	int ans = 0;
	rep(i, m) {
		UnionFind uf(n);
		rep(j, m) {
			if (i == j) continue;
			uf.unite(vp[j]);
		}
		if (uf.size() != 1) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

int main(void)
{
  int N;
  std::cin >> N;
  std::vector<int> an;
  for(int i=0; i<N; i++)
  {
    int a;
    std::cin >> a;
    an.push_back(a);
  }
  std::sort(an.rbegin(), an.rend());

  int count = 0;
  std::multiset<int> waiting;
  for(int i=0; i<an.size(); i++)
  {
    bool found = false;
    auto pair = (0xFFFFFFFF ^ an[i]) + 1;
    for(int j=31; 0<=j; j--)
    {
      auto it = waiting.find(pair);
      if( it != waiting.end() )
      {
        waiting.erase(it);
        count += 1;
        found = true;
        break;
      }
      
      if( (pair>>j) & 0x1 == 0 ) { break; }
      pair -= 1<<j ;
    }

    if( ! found ) { waiting.insert(an[i]); }
  }

  std::cout << count ;
}


Measured memory_bytes: 10356
import java.util.*;
import java.io.*;
import java.math.*;
 
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}
        int n=sc.nextInt();
        int m=sc.nextInt();

        int b[] = new int[n];
        boolean f[] = new boolean[n];
        f[0]=true;

        for(int i=0; i<n; i++) {
            b[i]++;
        }

        for(int i=0,x,y; i<m; i++) {
            x=sc.nextInt()-1;
            y=sc.nextInt()-1;
            if(f[x]){
                if(b[x]==1){f[x]=false;}
                 f[y]=true;
            }
            b[x]--; b[y]++; 
        }

        int ans=0;   
        for(int i=0; i<n; i++) {
            if(f[i])ans++;
        }


        out.println(ans);
        out.flush();
    }



    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
     
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
    
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }    
}

class P implements Comparable<P>{
        int id, d;
        P(int  id, int d) {
            this.id=id;
            this.d=d;
        } 
          
        public int compareTo(P p){
            return d-p.d; //descend
        }
    }

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 41396
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> >ve;
int main()
{
    int n,k,t;
    cin>>n>>k;
    t = (n-1)*(n-2)/2;
    if(k>t) cout<<"-1"<<endl;
    else{
        for(int i=1;i<=n-1;i++) ve.push_back( {i,n} );
        int cnt=0;
        for(int i=1;i<=n-1;i++){
            for(int j=i+1;j<=n-1;j++){
                if(cnt == t-k)  break;
                ve.push_back( {i,j} );
                cnt++;
            }
            if(cnt == t-k)  break;
        }
        cout<<cnt+n-1<<endl;
        for(int i=0;i<ve.size();i++)    cout<<ve[i].first<<" "<<ve[i].second<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <unordered_map>
// #include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x)  if(DEBUG_Switch) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
void pvarr_int(int *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%d%c", arr[i], i == n ? '\n' : ' ');}}
void pvarr_LL(ll *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%lld%c", arr[i], i == n ? '\n' : ' ');}}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
#define DEBUG_Switch 0
int n;
int a[maxn];
int main()
{
#if DEBUG_Switch
    freopen("C:\\code\\input.txt", "r", stdin);
#endif
    //freopen("C:\\code\\output.txt","r",stdin);
    n = readint();
    repd(i, 2, n)
    {
        a[readint()]++;
    }
    repd(i, 1, n)
    {
        printf("%d\n", a[i] );
    }
    return 0;
}




Measured memory_bytes: 3880
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int dp[1001][9];

int main(){
  int total_days;
  while(~scanf("%d",&total_days)){
    string must_attend_persons;
    cin >> must_attend_persons;

    must_attend_persons = "J" + must_attend_persons;

    memset(dp,0,sizeof(dp));

    //J:=0 O:=1 I:=2
    dp[0][(1<<0)] = 1;

    map<char,int> name2idx;
    name2idx['J'] = 0;
    name2idx['O'] = 1;
    name2idx['I'] = 2;

    for(int day=1;day<=total_days;day++){
      //J:=0 O:=1 I:=2
      for(int prev_attendance=0;prev_attendance<=(1<<3)-1;prev_attendance++){
        for(int next_attendance=0;next_attendance<=(1<<3)-1;next_attendance++){
          if(__builtin_popcount(prev_attendance & next_attendance) == 0) continue;
          if(!(next_attendance & (1<<name2idx[must_attend_persons[day]]))) continue;
          
          dp[day][next_attendance]
            += dp[day-1][prev_attendance];
          dp[day][next_attendance] %= 10007;
        }
      }
    }
    
    int res = 0;
    for(int attendance=0;attendance<=(1<<3)-1;attendance++){
      res += dp[total_days][attendance];
      res %= 10007;
    }
    printf("%d\n",res);
  }
}

Measured memory_bytes: 1284
use std::io::prelude::*;
use std::io;
use std::str::FromStr;
#[cfg(local)]
use std::fs::File;
#[cfg(local)]
use std::io::BufReader;

#[cfg(local)]
fn buf_read() -> io::Result<(Vec<String>)> {
    let f = try!(File::open("input.txt"));
    let input_lines: Vec<_> = BufReader::new(f).lines().collect();
    let lines: Vec<String> = input_lines.into_iter().map(|e| e.unwrap()).collect();
    Ok((lines))
}

#[cfg(not(local))]
fn buf_read() -> io::Result<(Vec<String>)> {
    let stdin = io::stdin();
    let input_lines: Vec<_> = stdin.lock().lines().collect();
    let lines: Vec<String> = input_lines.into_iter().map(|e| e.unwrap()).collect();
    Ok((lines))
}

fn main() {
    type Element = i32;
    let input = buf_read().unwrap();
    let mut input_vectors: Vec<Vec<Element>> = vec![];
    for input_line in input {
        let input_str: Vec<String> = input_line.split(' ').map(String::from).collect();
        let mut input_vector: Vec<Element> = vec![];
        for input_elem_str in input_str {
            let elem: Element = Element::from_str(input_elem_str.as_str()).unwrap();
            input_vector.push(elem);
        }
        input_vectors.push(input_vector);
    }

    let towns_slice = &input_vectors[1];
    let towns = input_vectors[1].iter().enumerate();
    let mut max_diff = 0;
    let mut min_cost = input_vectors[1][0].clone();
    let mut count = 0;
    for town in towns {
        let cur_cost = town.1.clone();
        match (cur_cost - min_cost) - max_diff {
            0 => count += 1,
            n => {
                if n > 0 {
                    count = 1;
                    max_diff = cur_cost - min_cost;
                }
            }
        };
        if min_cost > cur_cost {
            min_cost = cur_cost;
        }
        // let current_cost = town.1;
        // let max_apple_left_cost = &towns_slice[town.0..].iter().max().unwrap().clone();
        // match max_apple_left_cost - current_cost - max_diff {
        //     0 => count += 1,
        //     n => {
        //         if n > 0 {
        //             count = 1;
        //             max_diff = max_apple_left_cost - current_cost;
        //         }
        //     }
        // };
    }
    println!("{:?}", count);
}


Measured memory_bytes: 6524
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
using namespace std;

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

const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const int Mod = 1000000007;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl
ll po[maxn];
int main() {
    //freopen(".in", "r", stdin);
    int n,m;
    scanf("%d%d",&n,&m);
    po[0]=1;
    for(int i=1;i<=max(n,m);i++) po[i]=1LL*po[i-1]*i%Mod;
    if(m>n) swap(n,m);
    if(n-m>=2) return 0*puts("0");
    if(n==m)
    {
        ll ans=po[n]*po[m]*2LL%Mod;
        printf("%lld\n",ans);
    }
    else
    {
        ll ans=po[n]*po[m]%Mod;
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 1024
def main():
    a, b, k = map(int, input().split())

    more = a if a > b else b

    number_list = []
    for i in range(1, more + 1):
        if a % i == 0 and b % i == 0:
            number_list.append(i)

    number_list.sort(reverse=True)
    print(number_list.pop(k - 1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
# Algorithms and Data Structures 1
# Binary Search
# Name: Ryuya Asada
# ID: s1260064


def binary_search(A: list, key: int):
    left = 0
    right = len(A)
    while left < right:
        mid = int((left + right) / 2)
        if A[mid] == key:
            return mid
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1

    return -1


def main():
    number_of_A = int(input())
    A = [int(a) for a in input().split(" ")]

    number_of_B = int(input())
    B = [int(b) for b in input().split(" ")]

    num = 0
    for b in B:
        result = binary_search(A, b)
        if result != -1:
            num += 1

    print(num)


if __name__ == "__main__":
    main()



Measured memory_bytes: 16896
#include <iostream>
#include <algorithm>

using namespace std;

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

	int num;
	cin >> num;

	int firstDigit = num % 10;

	if (firstDigit == 3) {
		cout << "bon" << endl;
	} else if (firstDigit == 0 || firstDigit == 1 || firstDigit == 6 || firstDigit == 8) {
		cout << "pon" << endl;
	} else {
		cout << "hon" << endl;
	}

	return 0;
}

Measured memory_bytes: 3648
# -*- coding: utf-8 -*-
# D - Line++
# 標準入力の取得
N,X,Y = list(map(int, input().split()))

# 求解
# (i, j)間の最短距離はmin{|j-i|, |X-i|+1+|j-Y|, |Y-i|+1+|j-X|}であるため、
# (i, j)が決まれば、最短距離はO(1)で決まる。したがって、全(i, j)について、最短距離を求める。
k_list = [0 for i in range(1,N)]
for i in range(1, N):
    diff_X_i = abs(X - i)
    diff_Y_i = abs(Y - i)
    for j in range(i+1, N+1):
        diff_j_i = abs(j - i)
        diff_j_X = abs(j - X)
        diff_j_Y = abs(j - Y)
        min_path = min([diff_j_i, diff_X_i+1+diff_j_Y, diff_Y_i+1+diff_j_X])
        k_list[min_path-1] += 1

# 結果出力
for k in k_list:
    print(k)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define tc int t;cin>>t;while(t--)

int main()

{
    double d,t,s;
    cin>>d>>t>>s;
    double T=d/s;
    if(t>=T)cout<<"Yes";
    else cout<<"No";
}


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

int main(){
 int N, M, C;
cin >> N >> M >> C;

  vector<int> B(M);
  for(int i=0; i<M; i++){
  cin >> B.at(i);
  }
vector <vector<int>> A(N, vector<int>(M));
  for(int i=0; i < N; i++){
      for(int j=0; j < M; j++){
      cin >> A.at(i).at(j);
  }
  }

  int count =0;
  for(int i=0; i<N; i++){
    int sum =C;
     for(int j=0; j<M; j++){
     sum +=B.at(j) * A.at(i).at(j);
     }
    if(sum > 0){
    count++;
    }
  }
  cout << count <<endl;
}

Measured memory_bytes: 256
package main

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

var scanner *bufio.Scanner

func printIt() {
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		nums := make([]int, n)
		sum := 0
		for i := 0; i < n; i++ {
			nums[i] = nextInt()
			sum += nums[i]
		}
		avg := float64(sum) / float64(n)
		sd := 0.0
		for _, item := range nums {
			sd += (float64(item) - avg) * (float64(item) - avg)
		}
		fmt.Println(math.Sqrt(sd / float64(n)))
	}

}

func nextInt() int {
	scanner.Scan()
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(1)
	}
	return num
}

func nextFloat() float64 {
	scanner.Scan()
	num, err := strconv.ParseFloat(scanner.Text(), 10)
	if err != nil {
		panic(1)
	}
	return num
}

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	printIt()
}



Measured memory_bytes: 1108
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<pair<int, int>> tasks;

int main(){
    vector<pair<int, int>> points;
    int W, H, x, y;
    cin >> W >> H >> x >> y;
    cout << (double)((double)W*(double)H/2) << " " << (int)((W == x*2) && (H == y*2)) << endl;
    return 0;
    
}



Measured memory_bytes: 256
import math

def get_ints():
    return list(map(int, input().split()))

N, K = get_ints()
probs = [0] * max(K + 1, N + 1)
A = len(probs)

for i in range(A - 1, 0, -1):
    if i >= K:
        probs[i] = 1
    elif i * 2 >= K:
        probs[i] = 1 / 2
    else:
        probs[i] = probs[i * 2] / 2

ans = 0
for i in range(1, N + 1):
    ans += probs[i]


ans /= N
print(ans)


Measured memory_bytes: 4980
using System;
//using System.Collections.Generic;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			Console.ReadLine();
			string[] s = Console.ReadLine().Split(' ');
			int[] a = new int[s.Length];
			for (int i = 0; i < s.Length; i++)
			{
				a[i] = int.Parse(s[i]);
			}
			int count = 0;
			for (int i = 0; i < s.Length; i++)
			{
				int minj = i;
				for (int j = i; j < s.Length; j++)
				{
					if (a[j] < a[minj]) minj = j;
				}
				if (i != minj)
				{
					int tmp = a[i];
					a[i] = a[minj];
					a[minj] = tmp;
					count++;
				}
			}
			for (int i = 0; i < s.Length; i++)
			{
				Console.Write(a[i]);
				if (i == s.Length - 1) Console.Write("\n");
				else Console.Write(" ");
			}
			Console.WriteLine(count);
		}
	}
}

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

class Cube{
public:
 int f[6];
 Cube(){}
 void roll_z(){ roll(1,2,4,3);} //
 void roll_y(){ roll(0,2,5,3);} // to W
 void roll_x(){ roll(0,1,5,4);} // to N
 void roll(int i, int j, int k, int l){
  int t=f[i]; f[i]=f[j]; f[j]=f[k]; f[k]=f[l]; f[l]=t;
 }
};

bool eq(Cube c1,Cube c2){
 for(int i=0;i<6;i++)
  if(c1.f[i]!=c2.f[i]) return false;
 return true;
}

bool equal(Cube c1,Cube c2){
 for(int i=0;i<6;i++){
  for(int j=0;j<4;j++){
   if(eq(c1,c2)) return true;
   c1.roll_z();
  }
  if(i%2==0)c1.roll_y();
  else c1.roll_x();
 }
 return false;
}

int main(){
 Cube c1,c2;

 for(int i=0;i<6;i++) cin >> c1.f[i];
 for(int i=0;i<6;i++) cin >> c2.f[i];

 if(equal(c1,c2))cout << "Yes" << endl;
 else cout << "No" << endl;

 return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

class UnionFind{
private:
  vector<ll> Parent; 
 public:
  UnionFind(ll N){
    Parent = vector<ll>(N, -1);
  }
  
  ll root(ll A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  ll size(ll A){
    return -Parent[root(A)]; 
  }
  
  bool connect(ll A, ll B){
    A = root(A);
    B = root(B);
    if(A == B){
      return false;
    }
    if(size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
  
  bool isSame(ll A, ll B){
    return root(A) == root(B);
  }
};



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  vpll ab(m);
  rep(i,m){
    ll a,b; cin>>a>>b; a--,b--;
    ab[i]={a,b};
  }
  ll ans=0;
  rep(i,m){
    UnionFind uf(n);
    rep(j,m){
      if(i==j) continue;
      uf.connect(ab[j].first,ab[j].second);
    }
    rep(j,n){
      if(!uf.isSame(0,j)){
        ans++;
        break;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <functional>
#include <string.h>

using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#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()
#define zero(a) memset(a,0,sizeof(a))
#define minus(a) memset(a,0xff,sizeof(a))
#define chmax(a,b) a=min((a),(b))
#define chmin(a,b) a=max((a),(b))


#define MOD 1000000007

template <typename T>
class Bit {
public:
	vector<T> a;
	Bit(int n) {
		a.resize(n + 1);
	}
	void add(int x, T y) {
		for (int i = x; i < a.size(); i += (i&-i)) {
			a[i] += y;
		}
	}

	T sum(int x) {
		T ret = 0;
		for (int i = x; i > 0; i -= (i&-i)) {
			ret += a[i];
		}
		return ret;
	}
};
template <typename T>
class Compress {
public:
	int func(vector<T> &a, vector<T> &x) {
		x = a;
		int n = a.size();
		sort(a.begin(), a.end());
		a.erase(unique(a.begin(), a.end()), a.end());

		rep(i, n) {
			x[i] = lower_bound(a.begin(), a.end(), x[i]) - a.begin();
		}
		return a.size();
	}
};


ll n, k;
vector<ll> a, x;

int main(){
	scanf("%lld %lld ", &n, &k);
	a.resize(n+1);

	a[0] = k;
	rep(i, n) {
		scanf("%lld ", &a[i+1]);
	}	
	rep(i, n + 1){
		a[i] -= k;
	}
	rep(i, n) {
		a[i + 1] += a[i];
	}
	
	Compress<ll> comp;
	comp.func(a, x);
	Bit<ll> bit(n+1);
	ll ans = 0;
	
	rep(i, n + 1) {
		ans += bit.sum(x[i]+1);
		bit.add(x[i] + 1, 1);

	}

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


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	int a,b;
	cin >> a >> b;
	printf("%d %d %.7lf\n",a/b,a%b,(double)a/b);
	return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);
// int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

void solve() {
string s; cin >> s;
string t; cin >> t;
int sn = s.size();
int tn = t.size();
int ans = 0;
rep(i,sn) {
  if (s[i] == t[i]) ans++; 
}
if (ans == sn) cout << "Yes" << endl;
else cout << "No" << endl;

}


int main() {
  solve();
  return 0;
}



Measured memory_bytes: 3636
#include<iostream>
#include<cstdlib>
#include<istream>
#include <stdio.h>
#include<vector>
#include <fstream>
#include <string>
#include<stdio.h>
using namespace std;
int main() {
	int A, B;
	cin >> A >> B;
	if (A >= 13) {
		cout << B<< endl;
	}
	else if (A >= 6) {
		B = B / 2;
		cout << B  << endl;
	}
	else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
#include<stdio.h>
#define ll long long

int main(){
  ll n,a,b,i,j;
  ll s=0,c[20][20]={};
  scanf("%lld",&n);
  for(i=1;i<=n;i++){
    a=i%10;
    for(j=i;j;j/=10)b=j%10;
    c[a][b]++;
  }
  for(i=0;i<10;i++){
    for(j=0;j<10;j++)s+=c[i][j]*c[j][i];
  }
  printf("%lld\n",s);
  return 0;
}

Measured memory_bytes: 128