akhauriyash/Code-Regression huggingface dataset:
// abc137_a
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int a, b;
  cin >> a >> b;
  if ((a > 1 && b > 1) || (a < -1 && b < -1)) {
    cout << a*b << endl;
  } else if (a > 0 && b < 0) {
    cout << a-b << endl;
  } else {
    cout << a+b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/ruby

input = []
until (a = gets).nil?
  input << a.split(?,).map(&:to_i)
end

rect = input.count{|x| Math::hypot(x[0], x[1]) == x[2] }
dia = input.count{|x| x[0] == x[1]}

puts rect, dia

Measured memory_bytes: 6120
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K,A,B;
    cin >> K >> A >> B;
    if(A+1 >= B){
        print(1+K);
        return 0;
    }
    if(K <= A-1){
        print(1+K);
        return 0;
    }
    K -= (A-1);
    if(K % 2 == 0){
        ll ans = A + (B - A) * K/2;
        print(ans);
    }else{
        ll ans = A + (B - A) * (K/2) + 1;
        print(ans);
    }

}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	
	int i,j,n,m,c,x,y,cnt=0;
	cin>>n>>m>>c;
	vi b(m+1);
	for0(i,m) cin>>b[i];
	vector< vector<int> > v(n+1);
	for0(i,n){
		for0(j,m){
			cin>>y;
			v[i].pb(y);
			}
		}
	for0(i,n){
		x = 0;
		for0(j,m){
			x += v[i][j]*b[j];
			}
		x += c;
		if(x>0) cnt++;
		}
	cout<<cnt<<nw;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
using ll = long long;
struct dsu {
    public:
	dsu() : _n(0) {}
	dsu(int n) : _n(n), parent_or_size(n, -1) {}

	int merge(int a, int b) {
		assert(0 <= a && a < _n);
		assert(0 <= b && b < _n);
		int x = leader(a), y = leader(b);
		if (x == y) return x;
		if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
		parent_or_size[x] += parent_or_size[y];
		parent_or_size[y] = x;
		return x;
	}

	bool same(int a, int b) {
		assert(0 <= a && a < _n);
		assert(0 <= b && b < _n);
		return leader(a) == leader(b);
	}

	int leader(int a) {
		assert(0 <= a && a < _n);
		if (parent_or_size[a] < 0) return a;
		return parent_or_size[a] = leader(parent_or_size[a]);
	}

	int size(int a) {
		assert(0 <= a && a < _n);
		return -parent_or_size[leader(a)];
	}

	std::vector<std::vector<int>> groups() {
		std::vector<int> leader_buf(_n), group_size(_n);
		for (int i = 0; i < _n; i++) {
			leader_buf[i] = leader(i);
			group_size[leader_buf[i]]++;
		}
		std::vector<std::vector<int>> result(_n);
		for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); }
		for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); }
		result.erase(
		    std::remove_if(result.begin(), result.end(), [&](const std::vector<int>& v) { return v.empty(); }),
		    result.end());
		return result;
	}

    private:
	int _n;
	std::vector<int> parent_or_size;
};
int main() {
	int n, m, k;
	cin >> n >> m >> k;
	dsu f(n);
	vector<set<int>> fri(n), blo(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		f.merge(a - 1, b - 1);
		fri[a - 1].insert(b - 1);
		fri[b - 1].insert(a - 1);
	}
	rep(i, k) {
		int a, b;
		cin >> a >> b;
		blo[a - 1].insert(b - 1);
		blo[b - 1].insert(a - 1);
	}
	rep(i, n) {
		int p = f.size(i);
		for (auto t : fri[i]) {
			if (f.same(i, t)) p--;
		}
		for (auto t : blo[i]) {
			if (f.same(i, t)) p--;
		}
		if (i) cout << " ";
		cout << p - 1;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 31744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 5, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const ll LNF = 0x3f3f3f3f3f3f3f3f;
typedef pair<int, int> pii;
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define repe(i, u) for (int i = head[u]; i; i = nxt[i])

int n;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  cout << (int)pow(n, 3) << endl;
}

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

    const int MOD = 1000000007;
    const double PI = acos(-1); 

    //long long
    using ll = long long;

    //出力系
    #define print(x) cout << x << endl
    #define yes cout << "Yes" << endl
    #define YES cout << "YES" << endl
    #define no cout << "No" << endl
    #define NO cout << "NO" << endl
    
    // begin() end()
    #define all(x) (x).begin(),(x).end()

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

    //最大公約数（ll）
    ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

    //素因数分解
    vector<pair<ll, int>>factorize(ll n){
      vector<pair<ll, int>> res;
      for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
          n /= i;
          res.back().second++;
        }
      }
    if(n != 1) res.emplace_back(n, 1);
    return res;
    }



  // // 二分探索(最小値を出す問題は疑う)
  // bool C(ll x){
  //     ll res = 0;
  //     for(int i = 0; i < N; ++i){
  // 		res += max(0ll, A[i]-x/F[i]);
  //     }
  //     return res <= K;
  // }

  //   ll binary_search(ll ok, ll ng){
  //     while(abs(ok - ng) > 1){
  //       ll mid = (ok + ng) / 2;
  //       if(C(mid)) ok = mid;
  //       else ng = mid;
  //     }
  //     return ok;
  //   }


  int main(){
    string S;
    cin >> S;
    int N = S.length();
 REP(i, 8){
   string target = S.substr(0, i) + S.substr(N - (7 - i));
   if(target == "keyence"){
     YES;
     return 0;
   }
 }
  NO;
  
  }

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

#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cstdint>

using namespace std;

typedef long long ll;

int main() {
	ll n,x,a[100000];
	cin >> n >> x;
	ll res = 0;
	for(ll i = 0;i < n;i++) cin >> a[i];
	for(ll i = 1;i < n;i++) {
		if(a[i-1] > x) {
			res += a[i-1] -x;
			a[i-1] = x;
		}
		if(a[i-1]+a[i] > x) {
			res += (a[i-1]+a[i])-x;
			a[i] = x - a[i-1];
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 1024
N = int(input())
h = list(map(int, input().split()))
dp = [0]*N
dp[1] = abs(h[0]-h[1])
for i in range(2, N):
    s1, s2 = dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2])
    if s1 < s2:
        dp[i] = s1
    else:
        dp[i] = s2
print(dp[-1])

Measured memory_bytes: 52208
#include <bits/stdc++.h>
using namespace std;
const int N=207;
int t,n; long long a[N],w[N]; char s[N];
inline void ins(long long u){
	for(int i=61;i>=0;i--){
		if(u&(1ll<<i)){
			if(!w[i]){
				w[i]=u; return;
			}
			u^=w[i];
		}
	}
}
inline bool check(long long u){
	for(int i=61;i>=0;i--) if((u^w[i])<u) u^=w[i];
	if(u==0) return 0; return 1;
}
int main(){
	cin>>t;
	while(t--){
		memset(w,0,sizeof(w));
		cin>>n; bool fl=0;
		for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
		scanf("%s",s+1);
		for(int i=n;i>=1;i--){
			if(s[i]=='0') ins(a[i]);
			else fl|=check(a[i]);
		}
		if(fl) puts("1"); else puts("0");
	}
	return 0;
}



Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n;
 cin>>n;
 vector<pair<int,int> >a(n);
 for(int i=0;i<n;i++){
    cin>>a[i].first>>a[i].second;


 }
 sort( a.begin(),a.end() );
 int ans=a[n-1].first+a[n-1].second;
 cout<<ans<<endl;





}


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

using namespace std;

typedef long long ll;

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

	vector<int> values(n);
	vector<int> costs(n);
	for(i=0; i<n; i++) cin >> values[i];
	for(i=0; i<n; i++) cin >> costs[i];

	vector<int> total(n);
	for(i=0; i<n; i++) total[i] = values[i] - costs[i];

	sort(total.rbegin(),total.rend());
	i=0;	
	while(i<n && total[i]>0){
		sum += total[i];
		i++;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n,m;cin>>n>>m;
    vector<int>h(n);
    vector<bool>flag(n,true);
 
    for(int i=0;i<n;i++)cin>>h[i];
 
    for(int i=0;i<m;i++)
    {
        int a,b;cin>>a>>b;a--;b--;
 
        if(h[a]>=h[b])flag[b]=false;
        if(h[a]<=h[b])flag[a]=false;
    }
    int ans=0;
    for(int i=0;i<n;i++)ans+=flag[i];
 
    cout<<ans<<endl;
    
    return 0;
}


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

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main()
{
    int n,m,x[100000],dif[100000] = {0};

    int i,j;

    scanf("%d %d",&n,&m);
    for (i = 0; i < m; i++)scanf("%d",&x[i]);
    qsort(x,m,sizeof(int),asc);

    int ans = 0;
    for (i = 0; i < m - 1; i++)
    {
        dif[i] = x[i + 1] - x[i];
        ans += dif[i];
    }

    if(n >= m)
    {
        printf("0");
    }
    else
    {
        qsort(dif,m - 1,sizeof(int),asc);
        for (i = 0; i < n - 1; i++)
        {
            ans -= dif[m - 1 - 1 - i];
        }
        printf("%d",ans);
    }
}

Measured memory_bytes: 1396
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <string>

using namespace std;
using ll = long long;
using ull = size_t;

ll N;
ll A[300][300];
ll G[300][300];
bool exist_path[300][300];

void input() {
    cin >> N;
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
        cin >> A[i][j];
    }
}

bool exist_graph() {
    for (ll i = 0; i < N; i++) for (ll j = 0; j < N; j++)
        if (A[i][j] != G[i][j])
            return false;
    return true;
}

void solve() {
    for (ll i = 0; i < N; i++) for (ll j = 0; j < N; j++) {
        G[i][j] = i != j ? A[i][j] : 0;
        exist_path[i][j] = i != j;
    }
    // warshall-floyd
    for (ll g = 0; g < N; g++) {
        for (ll s = 0; s < N; s++) {
            if (s == g) continue;
            for (ll t = s + 1; t < N; t++) {
                if (s == t or t == g) continue;
                ll till = G[s][t], will = G[s][g] + G[g][t];
                if (will == till) {
                    exist_path[s][t] = false;
                    exist_path[t][s] = false;
                }
                ll val = min(till, will);
                G[s][t] = val;
                G[t][s] = val;
            }
        }
    }
    if (not exist_graph()) {
        cout << -1 << endl;
        return;
    }
    
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        for (ll j = i + 1; j < N; j++) {
            if (exist_path[i][j]) ans += A[i][j];
        }
    }
    cout << ans << endl;
}

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



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define NUM 10000000000

int main(){
  ll n;
  cin >> n;
  ll rn = sqrt(n);
  int ans=NUM;
  for(int i=1;i<=rn;i++){
    if(n % i == 0){
      string s = to_string(n/i);
      int len = s.length();
      ans = min(ans, len);
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define rep(i, k) for (ll i = 0; i < k; i++)
#define pair(x, y) make_pair((x), (y))

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int n, m;
    cin >> n >> m;
    int l = min(n, m);
    int h = max(n, m);
    rep(i, h) { cout << l; }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace kyoupuro {

    class Data {
        public long b;
        public long diff;
        public Data(long b, long d) {
            this.b = b;
            this.diff = d;
        }
    }

    class MainClass {

        public static void Main() {
            var N = Input.NextLong();
            var matrix = new List<Data>[N];

            for (int i = 0; i < N; i++) {
                matrix[i] = new List<Data>();
            }

            // 入力
            for (int i = 0; i < N - 1; i++) {
                var a = Input.NextLong() - 1;
                var b = Input.NextLong() - 1;
                var c = Input.NextLong();
                matrix[a].Add(new Data(b, c));
                matrix[b].Add(new Data(a, c));
            }

            var Q = Input.NextLong();
            var K = Input.NextLong() - 1;

            // 距離計算
            var diffence = Enumerable.Repeat(long.MaxValue, (int)N).ToArray();
            diffence[K] = 0;
            var queue = new Queue<long>();
            queue.Enqueue(K);
            while (queue.Any()) {
                var tmp = queue.Dequeue();

                // add + 距離
                foreach(var data in matrix[tmp].Where(x => diffence[x.b] > diffence[tmp])) {
                    diffence[data.b] = data.diff + diffence[tmp];
                    queue.Enqueue(data.b);
                }
            }

            // クエリ
            for (int i = 0; i < Q; i++) {
                var x = Input.NextInt() - 1;
                var y = Input.NextInt() - 1;
                Console.WriteLine(diffence[x] + diffence[y]);
            }
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 41412
def main():
    s = input()
    t = input()
    chk_dir = {}
    for i in range(len(s)):
        if not(s[i] in chk_dir.keys()):
            if (t[i] in chk_dir.values()):
                print("No")
                return
            else:
                chk_dir[s[i]] = t[i]
        elif chk_dir[s[i]] != t[i]:
            print("No")
            return

    print("Yes")
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 3632
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	n = int(sys.stdin.readline())
	happy = 0
	happy += n // 500 * 1000
	n %= 500
	happy += n // 5 * 5
	n %= 5
	print(happy)

	


main()

Measured memory_bytes: 3572
using System;
using System.Collections.Generic;

namespace ABC171Test
{
    class Program
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine().Trim());
            var buff = Console.ReadLine().Trim().Split(' ');
            List<int> A = new List<int>();
            foreach (var bf in buff) A.Add(int.Parse(bf));

            const int max = (int)10e5+1;
            List<int> hm = new List<int>(max);
            for (int h = 0; h < max; h++) {
                hm.Add(0);
            }

            foreach (var a in A) {
                hm[a] += 1;
            }
            long sum;
            sum = 0;
            foreach (var a in A) {
                sum += a;
            }

            int Q = int.Parse(Console.ReadLine().Trim());
            List<int> B = new List<int>();
            List<int> C = new List<int>();
            
            for (int k = 0; k < Q; k++) {
                buff = Console.ReadLine().Trim().Split(' ');
                B.Add(int.Parse(buff[0]));
                C.Add(int.Parse(buff[1]));
            }


            for (int i = 0; i < Q; i++) {
                int Bi = B[i];
                int Ci = C[i];
                int diff = (Ci - Bi) * hm[Bi];
                sum += diff;
                hm[Ci] += hm[Bi];
                hm[Bi] = 0;
                Console.WriteLine(sum);
            }

        }


    }

}


Measured memory_bytes: 53560
N = int(input())
As = map(int, input().split())
cnt = {}
for a in As:
    if a in cnt:
        cnt[a] += 1
    else:
        cnt[a] = 1
ret = 0
for i in set(cnt.keys()):
    if i < cnt[i]:
        ret += cnt[i] - i
    elif cnt[i] < i:
        ret += cnt[i]
print(ret)


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

int main() {
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    vector<string> F(N);
    for(int i = 0; i < N; ++i) {
      cin >> F[i];
    }
    vector<int> level(N);
    for(int i = 0; i < N; ++i) {
      for(int j = 0; j < (int)F[i].size(); ++j) {
        if(F[i][j] != '.') {
          level[i] = j;
          break;
        }
      }
    }
    for(int i = (int)F.size() - 1; i >= 0; --i) {
      if(level[i] > 0) F[i][level[i] - 1] = '+';
      for(int j = i - 1; j >= 0 && F[j][level[i] - 1] == '.'; --j) F[j][level[i] - 1] = '|';
      for(int j = 0; j < (int)F[i].size(); ++j) if(F[i][j] == '.') F[i][j] = ' ';
    }
    for(int i = 0; i < N; ++i) {
      cout << F[i] << endl;
    }
  }
}

Measured memory_bytes: 1992
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
#include <cstdlib>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}


int maxf(int x){
    if (x>30) return (1<<30);
    return (1<<x)-1;
}

int bs(int n){
    int l = 1, r = n;
    while (l<r-1){
        int mid = l + (r-l)/2;
        int mins = mid, maxs = maxf(mid);
        if ((mins<=n) && (n<=maxs)){
            r=mid;
        }
        else if (n<mins){
            r = mid;
        }
        else{
            l = mid;
        }
    }
    if ((l<=n) && (n<=maxf(l))){
        return l;
    }
    return r;
}

int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int k, a, b;
    cin>>k>>a>>b;

    int ok = 0;
    for (int i = a; i <= b; i++){
        if (i%k==0) ok++;
    }
    if (ok){
        cout<<"OK\n";
    }
    else{
        cout<<"NG\n";
    }
    return 0;
}


Measured memory_bytes: 3028
# ABC079d
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = 10
d = [[float("inf") for i in range(n)] for i in range(n)]
for i in range(n):
    d[i][i] = 0  # 自身のところに行くコストは０


def warshall_floyd(d):
    # d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


h, w = map(int, input().split())
for i in range(10):
    c = list(map(int, input().split()))
    for j in range(10):
        d[i][j] = c[j]
warshall_floyd(d)

a = [list(map(int, input().split())) for _ in range(h)]
cou = [0]*10
for i in a:
    for j in range(10):
        cou[j] += i.count(j)
ans = 0
for i in range(10):
    ans += cou[i]*d[i][1]
# for i in range(10):
    # print(d[i][1])
print(ans)


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

int main()
{
    int n;
    std::cin>>n;
    std::vector<int> v(n),x(n);
    for(int i=0;i<n;i++)std::cin>>v[i];
    x = v;
    std::sort(v.begin(),v.end());
    int mid1 = v[n/2-1];
    int mid2 = v[n/2];
    for(int i=0;i<n;i++){
        if(x[i] <= mid1)std::cout<<mid2<<std::endl;
        else std::cout<<mid1<<std::endl;
    }
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  int r,c,k;
  cin>>r>>c>>k;
  int memo[r+1][c+1];
  for(int i=0;i<r+1;i++){
    for(int j=0;j<c+1;j++){
      memo[i][j]=0;
    }
  }
  for(int i=0;i<k;i++){
    int R,C,v;
    cin>>R>>C>>v;
    memo[R][C]=v;
  }
  vector<vector<vector<ll>>> dp(4,vector<vector<ll>>(r+1,vector<ll>(c+1,0)));
  for(int i=1;i<r+1;i++){
    for(int j=1;j<c+1;j++){
      for(int l=0;l<4;l++){
        dp[0][i][j]=max(dp[0][i][j],dp[l][i-1][j]);
      }
      dp[0][i][j]=max(dp[0][i][j],dp[0][i][j-1]);
      dp[1][i][j]=dp[1][i][j-1];
      dp[2][i][j]=dp[2][i][j-1];
      dp[3][i][j]=dp[3][i][j-1];
      if(memo[i][j]!=0){
        dp[1][i][j]=max(dp[1][i][j-1],dp[0][i][j]+memo[i][j]);
        dp[2][i][j]=max(dp[2][i][j-1],dp[1][i][j-1]+memo[i][j]);
        dp[3][i][j]=max(dp[3][i][j-1],dp[2][i][j-1]+memo[i][j]);
      }
    }
  }
  ll ans=0;
  for(int i=0;i<4;i++){
    ans=max(ans,dp[i][r][c]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 390600
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def solve(N: int, A: "List[int]"):
    return " ".join(str(v+1) for v, _ in sorted(enumerate(A), key=lambda a: a[1]))


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(f'{solve(N, A)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 98460
N=int(input())
f=lambda x,y,z:x*x+y*y+z*z+x*y+y*z+z*x

T=[0]*(N+1)
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            t=f(x,y,z)
            if t<=N:
                T[t]+=1

for i in range(1,N+1):
    print(T[i])


Measured memory_bytes: 69120
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define loop(i,n) rep(i,0,n)
using namespace std;
using ll = long long;
template<typename weight_t> using graph = vector<vector<pair<int,weight_t>>>;
template<typename weight_t> vector<weight_t> dijkstra(const graph<weight_t> &g,const int e){
    using node=pair<int,weight_t>; auto cmp=[](node &a,node &b)->bool {return (a.second>b.second);};
    priority_queue<node,vector<node>,decltype(cmp)> pq(cmp);
    vector<weight_t> w(g.size(),numeric_limits<weight_t>::max());
    vector<bool> done(g.size(),false);
    pq.push({e,0}); w[e]=0;
    while(!pq.empty()){ auto u=pq.top(); pq.pop(); 
        if(done[u.first])continue;
        for(auto &v:g[u.first]){
        if(done[v.first])continue;
        if(w[u.first]+v.second<w[v.first]){
            w[v.first]=w[u.first]+v.second; pq.push({v.first,w[v.first]});
        }}
        done[u.first]=true;
    }
    return w;
}
int main(){
    double xs,ys,xt,yt;
    int n;
    cin >> xs >> ys >> xt >> yt >> n;
    vector<double> x(n+2),y(n+2),r(n+2);
    x[0]=xs;
    y[0]=ys;
    x[1]=xt;
    y[1]=yt;
    rep(i,2,n+2){
        cin >> x[i] >> y[i] >> r[i];
    }
    graph<double> g(n+2);
    auto dist = [&](double xi,double yi,double xj,double yj)->double{
        return sqrt((xi-xj)*(xi-xj)+(yi-yj)*(yi-yj));};
    loop(i,n+1)rep(j,i+1,n+2){
        double d=max(0.0,dist(x[i],y[i],x[j],y[j])-r[i]-r[j]);
        g[i].push_back({j,d});
        g[j].push_back({i,d});
    }
    auto ans=dijkstra(g,0);
    cout << setprecision(10) << ans[1] << endl;
    return 0;
}

Measured memory_bytes: 22128
n = int(input())
def factorization(n):
    def factor_sub(n, m):
        c = 0
        while n % m == 0:
            c += 1
            n /= m
        return c, n
    #
    buff = []
    c, m = factor_sub(n, 2)
    if c > 0: buff.append((2, c))
    c, m = factor_sub(m, 3)
    if c > 0: buff.append((3, c))
    x = 5
    while m >= x * x:
        c, m = factor_sub(m, x)
        if c > 0: buff.append((x, c))
        if x % 6 == 5:
            x += 2
        else:
            x += 4
    if m > 1: buff.append((m, 1))
    return buff
def divisor_num(n):
    a = 1
    for _, x in factorization(n):
        a *= x + 1
    return a
ans = 0
for i in range(1,n+1,2):
  d = divisor_num(i)
  if d == 8:
    ans +=1
print(ans)

Measured memory_bytes: 3316
import math


def main():
    a, b, h, m = map(int, input().split())
    total_min = h * 60 + m
    ratio = total_min / (12 * 60)

    theta_h = ratio * math.pi * 2
    theta_m = m / 60 * math.pi * 2
    theta = math.fabs(theta_h - theta_m)

    ret = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(theta))
    print(ret)



if __name__=="__main__":
    main()


Measured memory_bytes: 9444
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    String s;
    char[] c, rc;
    int count, i;

    count = 0;
    for(;sc.hasNext();){
      s = sc.next();
      c = new char[s.length()]; rc = new char[s.length()];
      for(i = 0;i < s.length();i++){
        c[i] = s.charAt(i);
        rc[s.length() - 1 - i] = c[i];
      }

      for(i = 0;i < s.length();i++)if(c[i] != rc[i])break;
      if(i == s.length())count++;
    }
    out.println(count);

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 17136
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	ll ans = n-1;
	for(ll i = 1; i*i <= n; ++i){
		if(n%i != 0) continue;
		ll j = n/i;
		chmin(ans, i-1 + j-1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll dp[5151][5151];
vector<int>pat[5151];
bool flag[5151];
int num;
int cent;
int dfs(int node)
{
	if (flag[node])return 0;
	flag[node] = true;
	int s = 1, maxi = 0;
	for (int i = 0; i < pat[node].size(); i++)
	{
		int r = dfs(pat[node][i]);
		maxi = max(maxi, r);
		s += r;
	}
	if ((num - s) * 2 <= num&&maxi * 2 <= num)
	{
		if (cent == -1)cent = node;
		else
		{
			ll ans = 1;
			for (int i = 1; i <= num / 2; i++)ans = ans*i%mod*i%mod;
			printf("%lld\n", ans);
			exit(0);
		}
	}
	return s;
}
#define SIZE 100000
ll inv[SIZE + 1];
ll kai[SIZE + 1];
ll invkai[SIZE + 1];
void invinit()
{
	inv[1] = 1;
	for (int i = 2; i <= SIZE; i++)
	{
		inv[i] = mod - (mod / i)*inv[mod%i] % mod;
	}
	kai[0] = invkai[0] = 1;
	for (int i = 1; i <= SIZE; i++)
	{
		kai[i] = kai[i - 1] * i%mod;
		invkai[i] = invkai[i - 1] * inv[i] % mod;
	}
}
ll com(ll a, ll b)
{
	if (b < 0 || a < b)return 0;
	return (invkai[b] * invkai[a - b]) % mod*kai[a] % mod;
}
int main()
{
	scanf("%d", &num);
	invinit();
	for (int i = 0; i < num - 1; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		pat[za].push_back(zb);
		pat[zb].push_back(za);
	}
	cent = -1;
	dfs(0);
	vector<int>v;
	fill(flag, flag + num, false);
	flag[cent] = true;
	for (int i = 0; i < pat[cent].size(); i++)v.push_back(dfs(pat[cent][i]));
	dp[0][0] = 1;
	for (int i = 0; i < v.size(); i++)
	{
		for (int j = 0; j <= num; j++)
		{
			if (dp[i][j] == 0)continue;
			ll now = 1;
			for (int k = 0; k <= v[i]; k++)
			{
				dp[i + 1][j + k] = (dp[i + 1][j + k] + dp[i][j] * now%mod*com(v[i], k)) % mod;
				now *= v[i] - k;
				now %= mod;
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i <= num; i++)
	{
		ll t = dp[v.size()][i] * kai[num - i] % mod;
		//printf("%lld\n", dp[v.size()][i]);
		if (i % 2 == 0)ans += t;
		else ans += mod - t;
	}
	printf("%lld\n", ans%mod);
}

Measured memory_bytes: 205312
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <iomanip>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (lnog long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (lnog long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin>>n;
    vector<double> v(n);
    REP(i,n){
        cin>>v[i];
    }
    double sum=0,pro=1;
    REP(i,n){
        sum+=1/v[i];
    }
    cout<< std::setprecision(10)<<1/sum<<endl;

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  map<pair<int, int>, int> mp;
  rep2(i, 1, n+1){
    int re = i % 10;
    int fr = to_string(i).front() - '0';
    mp[{fr, re}]++;
  }
  ll ans = 0;
  for(auto p : mp){
    ans += (ll)mp[{p.first.second, p.first.first}] * p.second;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3696
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(__,v.size()){rep(_,v[__].size())cout<<" "<<v[__][_];cout<<endl;}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

signed main(){
	int n;
	cin>>n;
	map<int,int>ma;
	rep(i,n){
		int a;
		cin>>a;
		ma[a]++;
	}
	int out=0;
	for(auto it=ma.rbegin();it!=ma.rend();it++){
		int t=it->first;
		int N=1;
		while(N<t)N<<=1;
		if(t==N){
			out+=it->second/2;
			continue;
		}
		t=N-t;
		if(!ma.count(t))continue;
		out+=min(it->second,ma[t]);
		ma[t]-=min(it->second,ma[t]);
	}
	cout<<out<<endl;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

#define ld long double
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define int long long
#define ull unsigned long long
#define pii pair<int,int>
#define vii vector<int>
#define f first
#define s second
#define endl "\n"
#define all(container) container.begin(), container.end()
#define onlyunique(v) v.erase(unique(all(v)), v.end());

#define TRACE
#ifdef AYUSH
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

int const mod = 1e9 + 7;
int const inf = 1e18;

int power(int x, int y, int mod = 2e18) { int ans = 1; x %= mod; while (y) {if (y & 1)ans = (x * ans) % mod; x = (x * x) % mod; y >>= 1;} return ans;}
int modinv(int a, int m) {return power(a, m - 2, m);}

void solve() {
	int a, b, c, k;cin>>a>>b>>c>>k;
	if(k <= a){
		cout<<k<<endl;return;
	}
	int ans = a;
	k -= a;
	if(k <= b){
		cout<<ans<<endl;return;
	}
	k -= b;
	ans -= k;
	cout<<ans<<endl;



}
signed main() {
	IOS
	int t = 1, T = 1;
	// cin>>t;
	while (t--) {
		// cout<<"Case #"<<T<<": ";
		solve();
		// ++T;
	}
	return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <cmath>

#include <iostream>

#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>

#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	int res = 0;
	int n;
	cin >> n;
	vector<int> v(3, 0);
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		for (int j = 1; j < s.size(); j++)
			if (s[j] == 'B' && s[j - 1] == 'A')
				res++;
		if (s[0] == 'B' && s[s.size() - 1] == 'A')
			v[0]++;
		else if (s[0] == 'B')
			v[1]++;
		else if (s[s.size() - 1] == 'A')
			v[2]++;
	}

	if (v[0] > 0) {
		res += v[0] - 1;
		if (v[1] > 0) {
			res++;
			v[1]--;
		}
		if (v[2] > 0) {
			res++;
			v[2]--;
		}
	}
	res += min(v[1], v[2]);
	cout << res << endl;

}

Measured memory_bytes: 256
if __name__ == '__main__':
    from collections import deque
    n = int(input())
    dic = {}

    for i in range(n):
        x = input().split()
        if x[0] == "insert":
            dic[x[1]] = 1
        if x[0] == "find":
            if x[1] in dic:
                print('yes')
            else:
                print('no')



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

int main() {
  long h;
  std::cin >> h;
  int cnt = 0;
  while (h > 0) {
    h /= 2;
    ++cnt;
  }
  long sum = 0;
  for (int i = 0; i < cnt; ++i)
    sum += std::pow(2, i);
  std::cout << sum << std::endl;
  return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

struct Card{
  char suit;
  char value;
};


void BubbleSort(struct Card *A, int length) {

  int i, j;
  char tmp;
  char tmp_1;

  for(i = 0; i < length; i++) {
    for(j = length-1; j > i; j--) {
      if(A[j].value < A[j-1].value) {

	tmp = A[j].value;
	tmp_1 = A[j].suit;

	A[j].value = A[j-1].value;
	A[j].suit = A[j-1].suit;

	A[j-1].value = tmp;
	A[j-1].suit = tmp_1;

      }
    }
  }
}

void SelectionSort(struct Card *A,int length) {

  int i, j, mini;
  char tmp;
  char tmp_1;

  for(i = 0; i < length; i++) {
    mini = i;
    for(j = i; j < length; j++) {
      if(A[j].value < A[mini].value) {
	mini = j;
      }
    }
    if(i != mini) {
    tmp = A[i].value;
    tmp_1 = A[i].suit;

    A[i].value = A[mini].value;
    A[i].suit = A[mini].suit;

    A[mini].value = tmp;
    A[mini].suit = tmp_1;

    }
  }
}



int main(){
  struct Card C1[101], C2[101];
  char table[9][4]={};
  int cnt[9]={};

  int n, i,j,flg=0;
  char ch;

  scanf("%d%c", &n, &ch);
  for ( i = 0; i < n; i++ ){
    scanf("%c%c%c", &C1[i].suit, &C1[i].value, &ch);
    table[C1[i].value-'1'][cnt[C1[i].value-'1']]=C1[i].suit;
    cnt[C1[i].value-'1']++;
  }
  for(i = 0; i < n; i++) {

    C2[i].suit = C1[i].suit;
    C2[i].value = C1[i].value;
  }

  BubbleSort(C1, n);
  SelectionSort(C2, n);


  for(i=0;i<9;i++)cnt[i]=0;

  if(table[C1[0].value-'1'][cnt[C1[0].value-'1']++]!=C1[0].suit)
    {
      flg=1;
    }
  printf("%c%c", C1[0].suit, C1[0].value);
  for(i = 1; i < n; i++) {
  if(table[C1[i].value-'1'][cnt[C1[i].value-'1']++]!=C1[i].suit)
    {
      flg=1;
    }
  printf(" %c%c", C1[i].suit, C1[i].value);
  }

  if(flg==0)
    printf("\nStable\n");
  else
    printf("\nNot stable\n");

  for(i=0;i<9;i++)cnt[i]=0;
  flg=0;

  if(table[C2[0].value-'1'][cnt[C2[0].value-'1']++]!=C2[0].suit)
    {
      flg=1;
    }


 printf("%c%c", C2[0].suit, C2[0].value);
  for(i = 1; i < n; i++) {
  if(table[C1[i].value-'1'][cnt[C1[i].value-'1']++]!=C2[i].suit)
    {
      flg=1;
    }
  printf(" %c%c", C2[i].suit, C2[i].value);
  }

  if(flg==0)
    printf("\nStable\n");
  else
    printf("\nNot stable\n");

  return 0;
}

Measured memory_bytes: 608
use std::collections::VecDeque;

#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn check(n: usize) -> bool {
    let mut tn = n;
    let mut v = Vec::new();
    while 0 < tn {
        v.push(tn % 10);
        tn /= 10;
    }
    let mut flag3 = false;
    let mut flag5 = false;
    let mut flag7 = false;
    for i in v.iter() {
        if *i == 3 {
            flag3 = true;
        } else if *i == 5 {
            flag5 = true;
        } else if *i == 7 {
            flag7 = true;
        }
    }
    if flag3 && flag5 && flag7 {
        return true;
    }
    false
}

fn main() {
    let n = get!(usize);
    let mut ans = 0;
    let nums = vec![3, 5, 7];
    let mut q = VecDeque::new();
    q.push_back(3);
    q.push_back(5);
    q.push_back(7);
    'outer: while !q.is_empty() {
        let x = *q.front().unwrap();
        q.pop_front().unwrap();
        for i in 0..3 {
            let tx = x * 10 + nums[i];
            if n < tx {
                break 'outer;
            }
            if check(tx) {
                ans += 1;
            }
            q.push_back(tx);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
N,M=map(int ,raw_input().split())
S = 1
E = N
for i in range(M):
    L,R=map(int ,raw_input().split())
    if S<L:
        S=L
    if E>R:
        E=R
if E<S:
    print(str(0))
else:
    print(str(E-S+1))

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

using namespace std;

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, x;
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        cin >> x;
        n -= x;
    }
    cout << max(-1, n);
    return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll k,x;
  cin >> k >>x;
  if(500*k>=x)cout << "Yes" << endl;
  else cout << "No" << endl;

}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;

int main(){
    int t;
    vector<long long> answer(2,0);
    long long sumi = 0;
    bool flag = false;
    cin >> t;
    vector<long long> A(t);
    for (int i = 0; i < t; i++) {
        cin >> A[i];
    }
    for (int j = 0; j < 2; j++) {
        for (int i = 0; i < t; i++) {
            sumi += A[i];
            if(sumi == 0){
                answer[j] += 1;
                if (flag) {
                    sumi = -1;
                } else {
                    sumi = 1;
                }
            }else if(sumi>0 == flag) {
                answer[j] += abs(sumi)+1;
                if (sumi>0) {
                    sumi = -1;
                } else {
                    sumi = 1;
                }
            }
            flag = !flag;
        }
        flag = true;
        sumi =0;
    }
    cout << min(answer[0],answer[1]) << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
long gcd(long a , long b){
	if (b==0)
	{
		return a;
    }
	else
	{
		return(gcd(b,a%b));
    }
}
int main(){
  long n;
  cin >> n;
  long t;
  vector<long> s;
  for ( long i = 0; i < n ; i++){
    cin >> t;
    s.push_back(t);
  }
  vector<long> l , r;
  for ( long i = 0; i < n ; i++){
    l.push_back(0);
    r.push_back(0);
  }
  for ( long i = 1; i < n ; i++){
    l[i] = gcd(l[i-1] , s[i-1]);
  }
  long ans = 0;
  for ( long i = n -2; i >= 0 ; i--){
    r[i] = gcd(r[i+1] , s[i+1]);
    
  }
  for ( long i = 0; i < n ; i++){
    ans = max(ans, gcd(r[i] , l[i]));
  }
  
  cout << ans <<  endl;  
}

Measured memory_bytes: 3444
#include <iostream>

int main(void)
{
    int a;
    std::cin >> a;
    int b = 0;
    if (a >= 100) { ++b; a -= 100; }
    if (a >= 10) { ++b; a -= 10; }
    if (a >= 1) { ++b; }
    std::cout << b << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
using namespace std;
typedef long long ll;

int main(){
	ll p, q, r; cin >> p >> q >> r;

	cout << min(p + q, min(q + r, r + p)) << endl;;
	return 0;
}

Measured memory_bytes: 256
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
B = list(map(int, sys.stdin.readline().split()))

op = []
ok = True
while B and ok:
    for j in reversed(range(len(B))):
        if B[j] == j + 1:
            op.append(j + 1)
            B.pop(j)
            break
        if B[j] > j + 1:
            ok = False
            break

if B:
    print(-1)
else:
    op.reverse()
    print(*op, sep='\n')


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

int main(){
	int N; cin >> N;
	vector<int> d;

	for(int i = 0; i < N; ++i){
		int di; cin >> di;
		d.push_back(di);
	}

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

	int now = 0;
	int cnt = 0;
	for(int i = 0; i < N; ++i){
		if(d[i] != now) cnt++;
		now = d[i];
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256