akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
    int n,a[100];
    cin >> n;
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++){
        for(int j=i-1;j>=0;j--){
            if(a[j]>a[j+1]) swap(a[j],a[j+1]);
            else break;
        }
        for(int j=0;j<n;j++){
            if(j) cout << ' ';
            cout << a[j];
        }
        cout << endl;
    }
    return 0;
    
}


Measured memory_bytes: 3080
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>

using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

//最大公約数
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll N, K;
vector<ll> A;
bool dp[5010][5010];

bool J(ll x){
  if(A[x] >= K) return 1;

  rep(i, 5010)rep(j, 5010) dp[i][j] = 0;
  dp[0][0] = 1;
  for(int i = 1; i <= N+2; i++){
    if(i-1 == x){
      for(int j = 0; j <= K; j++){
        dp[i][j] = dp[i-1][j];
      }
    }else{
      for(int j = 0; j <= K; j++){
        dp[i][j] = dp[i-1][j];
        if(j-A[i-1] < 0) continue;
        dp[i][j] |= dp[i-1][j-A[i-1]];
      }
    }
  }
  
  for(int i = K - A[x]; i < K; i++){
    if(dp[N+2][i]) return 1;
  }
  return 0;
}

int main(void){
  cin >> N >> K;
  A.resize(N);
  rep(i, N) cin >> A[i];
  A.pb(INFL);
  A.pb(0);
  sort(A.begin(), A.end());
  ll NoNeed = 0, Need = N+2;
  while(Need - NoNeed > 1){
    ll mid = (NoNeed + Need) / 2;
    if(J(mid)) Need = mid;
    else NoNeed = mid;
  }

  cout << NoNeed << endl;
}


Measured memory_bytes: 24832
#include<bits/stdc++.h>
using namespace std;
signed main(){
    int a[1005][1005]={};
    int n;
    int x1,y1,x2,y2;
    int m=0;
    cin>>n;
    for(int i=0;i<n;i++){
	cin>>x1>>y1>>x2>>y2;
	a[y1][x1]++;
	a[y1][x2]--;
	a[y2][x1]--;
	a[y2][x2]++;
    }
    for(int i=1;i<=1000;i++){
	for(int j=0;j<=1000;j++)  a[i][j]+=a[i-1][j];
    }
    for(int i=0;i<=1000;i++){
	for(int j=1;j<=1000;j++) a[i][j]+=a[i][j-1];
    }
    for(int i=0;i<=1000;i++){
	for(int j=0;j<=1000;j++) m=max(m,a[i][j]);
    }
    cout<<m<<"\n";
}




Measured memory_bytes: 7040
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
 
using ll = long long;
 
#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define rep(i,n) for_(i,0,(n))
#define rrep(i,n) rfor_(i,0,(n))
 
#define pb push_back
#define mp make_pair

#define ft first
#define sd second

using pi = pair<int, int>;

pi egcd(int a, int b) {
    if(b==0)return mp(1, 0);
    pi p = egcd(b, a%b);
    return mp(p.sd, p.ft - a/b * p.sd);
}

int a, b;

int main(){
    cin.tie(0);
    
    cin>>a>>b;
    
    pi p = egcd(a, b);
    
    cout<<p.ft<<' '<<p.sd<<endl;
     
    return 0;
}


Measured memory_bytes: 3116
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt(),b = s.nextInt();
        String c;
        if (a>b) {
            c=">";
        } else if (a<b) {
            c="<";
        } else {
            c="==";
        }
        System.out.println("a "+c+" b");
    }
}

Measured memory_bytes: 26200
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k;
	string s;
	cin >> n >> k >> s;
	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		if (s[i] == 'R' && s[i + 1] == 'R')
			ans++;
	}
	for (int i = n - 1; i > 0; i--) {
		if (s[i] == 'L' && s[i - 1] == 'L')
			ans++;
	}
	int i = 0;
	if (s[0] == 'L') {
		while (s[i] == 'L')
			i++;
		i--;
		while (i < n) {
			int j = i + 1;
			while (s[j] == 'R')
				j++;
			if (j - i > 0 && k > 0) {
				ans += 2;
				k--;
			}
			i = j;
		}
	} else {
		while (s[i] == 'R')
			i++;
		i--;
		while (i < n) {
			int j = i + 1;
			while (s[j] == 'L')
				j++;
			if (j - i > 0 && k > 0) {
				ans += 2;
				k--;
			}
			i = j;
		}
	}
	if (ans > n - 1)
		ans = n - 1;
	cout << ans;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007


int main()
{
   ll n;
   cin>>n;
   ll arr[5];
   ll mini=LONG_MAX;
   for(int i=0;i<5;i++)
   {
      cin>>arr[i];
      if(arr[i]<mini)
         mini = arr[i];
   }
   ll time = 4;
   if(n%mini == 0)
      time += n/mini;
   else
      time += n/mini + 1;
   cout<<time;
   return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <random>
#include <time.h>
#include <cassert>
using namespace std;

int main(){
	/*for(int i=0;i<5;i++){
		int B[10];
		for(int i=0;i<10;i++){
			cin >> B[i];
			if(B[i] == 0){
				return 0; //プログラムの強制終了
			}
		}

		int sum = 0;

		for(int i=1;i<10;i++){
			sum += B[i];
		}

		cout << B[0] - sum << endl;
	}*/
	/*int s,h,o,p;
	cin >> s >> h >> o >> p;

	cout << (s+h+o+p)/60 << endl << (s+h+o+p)%60 << endl;*/
	/*int P, A, S, j, u;
	cin >> P >> A >> S >> j >> u;

	int minP=min(P,A);//最も代金が安いパスタ
	int minA=min(minP,S);
	int minj=min(j,u);//最も代金が安いジュース

	cout << (minA + minj)-50 << endl;
	//最も代金が安いパスタとジュースの代金の合計*/

	int S[31] = {};

	for (int i=1;i<29;i++){
		int y;
		cin >> y;
		S[y] = 1;
	}
	
	//sort(S,S+28);//出席番号を昇順に並べる。

	for (int i=1;i<31;i++){
		if(S[i] == 0){
			cout << i << endl;
		}
		/*int X;
		X = S[i] - i;
		if(X = 1){
			cout << i << endl;//1つ番号が抜けていた場合(28番まで)

		}
		if(X = 2){
			cout << i << i++ << endl;//２つ番号が抜けていた場合(28番まで)
			return 0;
		}*/
	/*	for (int i=27;i<29;i++){

		}*/


	}

	return 0;

}



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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 1e5;

int n;
ll ans;

int p[N], s[N];

void make_set(int v) {
	p[v] = v;
	s[v] = 1;
}

int find_set(int v) {
	if (p[v] == v) return v;
	return p[v] = find_set(p[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		if (s[a] < s[b]) swap(a, b);
		p[b] = a;
		s[a] += s[b];
	}
}

struct Edge {
	int u, v, weight;
	bool operator<(Edge const& other) {
		return weight < other.weight;
	}
};

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	vector<pii> x(n), y(n);
	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		x[i] = {a, i};
		y[i] = {b, i};
		make_set(i);
	}
	sort(all(x)), sort(all(y));
	
	vector<Edge> edges;
	
	for (int i = 0; i < n - 1; ++i) {
		Edge newEdge;
		newEdge.u = x[i].second;
		newEdge.v = x[i + 1].second;
		newEdge.weight = x[i + 1].first - x[i].first;
		edges.push_back(newEdge);
		newEdge.u = y[i].second;
		newEdge.v = y[i + 1].second;
		newEdge.weight = y[i + 1].first - y[i].first;
		edges.push_back(newEdge);
	}
	
	sort(all(edges));
	for (Edge e : edges) {
		if (find_set(e.u) != find_set(e.v)) {
			ans += e.weight;
			union_sets(e.u, e.v);
		}
	}
		
	cout << ans;
}


Measured memory_bytes: 8708
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int N,C,K;
	cin>>N>>C>>K;
	vec(T)
	fx(N){
		vecp(T)
	}
	
	sorts(T)
	int ans=0;
	fx(N){
		int t=T.at(x);
		int c=0;
		while(x<N&&T.at(x)<=t+K&&c<C){
			c++;
			x++;
		}
      x--;
		ans++;
	}
	ce(ans)
}

Measured memory_bytes: 892
/* created   : 2019-10-30 00:36:13
 * accepted  : 2019-10-30 00:57:39
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define mt make_tuple
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

const int N = 625;
vector<int> g[N];
int n;
int m;

void solve() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v; cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
  }
  vector<double> dp(n);
  for (int u = n - 2; u >= 0; u--) {
    double cur = 0;
    for (auto v : g[u]) {
      cur += dp[v];
    }
    dp[u] = cur / g[u].size() + 1;
  }
  trace(dp);
  double ans = dp[0];
  for (int u = 0; u < n - 1; u++) {
    double mx = 0;
    int ix = -1;
    for (auto v : g[u]) {
      if (dp[v] > mx) {
        mx = dp[v];
        ix = v;
      }
    }
    if (g[u].size() <= 1) {
      continue;
    }
    trace(u, mx, ix);
    assert(ix != -1);
    vector<double> np(n);
    for (int j = n - 2; j >= 0; j--) {
      double cur = 0;
      int cnt = 0;
      for (auto v : g[j]) {
        if (j == u && v == ix) {
          continue;
        }
        cur += np[v];
        cnt++;
      }
      np[j] = cur / cnt + 1;
    }
    ans = min(ans, np[0]);
  }
  cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << setprecision(10) << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n, r;
	cin >> n >> r;
	if(n >= 10)
		cout << r;
	else
		cout << r+100*(10-n);
}

Measured memory_bytes: 384
from collections import deque

rev = 0
s = input()
queue = deque()
for c in s:
    queue.append(c)

q = int(input())
for i in range(q):
    cs = input().split()
    if cs[0] == '1':
        rev = 1 - rev
    else:
        if ((cs[1] == '1' and rev == 0) or (cs[1] == '2' and rev == 1)):
            queue.appendleft(cs[2])
        else:
            queue.append(cs[2])
r = ''.join(queue)
if rev == 1:
    print(r[::-1])
else:
    print(r)


Measured memory_bytes: 8564
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline
    K = int(input())
    S = len(input().strip())
    mod = 10 ** 9 + 7
    fact = [1] * (K + S + 1)
    invfact = [1] * (K + S + 1)
    for i in range(K + S):
        fact[i+1] = (fact[i] * (i+1)) % mod
    invfact[-1] = pow(fact[-1], mod-2, mod)
    for i in range(K + S):
        invfact[-2-i] = (invfact[-1-i] * (K + S - i)) % mod
    def nCr(n, r):
        if r == n or r == 0:
            return 1
        r = min(r, n - r)
        return (fact[n] * invfact[n-r] * invfact[r]) % mod
    
    ans = 0
    for i in range(K+1):
        ans += pow(25, i, mod) * nCr(i+S-1, S-1) * pow(26, K-i, mod)
        ans %= mod

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 107112
#include <iostream>

using namespace std;

int main()
{
	//入力を受け取る
	int D, T, S;
	cin >> D >> T >> S;

	//高橋君の移動時間を計算する
	int dist = S * T;

	//Dとdistの大小関係に応じて出力をする
	if (dist >= D) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 3596
#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
#include <utility>
#include <tuple>
using namespace std;

using int128 = __int128;
const long long INF = 1e18;

template <typename NumType, NumType LIMIT = int128(1e18)>
struct CRT {
  pair<NumType, NumType> NIL;
  CRT() : NIL(-1, -1) {}

  NumType extgcd(NumType a, NumType b, NumType &p, NumType &q) {
    if(b == 0) {
      p = 1, q = 0;
      return a;
    }
    NumType d = extgcd(b, a%b, q, p);
    q -= a / b * p;
    return d;
  }

  pair<NumType, NumType> solve(NumType b1, NumType mod1, NumType b2, NumType mod2) {
    NumType p, q;
    NumType d = extgcd(mod1, mod2, p, q);

    if((b2 - b1) % d != 0) return NIL;
    NumType s = (b2 - b1) / d;
    NumType t = (s * p % (mod2 / d));

    NumType lc = min(mod1 / d * mod2, (int128)(2*INF));
    NumType so = (b1 + mod1 * t) % lc;
    (so += lc) %= lc;
    return make_pair(so, lc);
  }

  pair<NumType, NumType> solve(vector<NumType> m, vector<NumType> mod) {
    assert(m.size() == mod.size());
    NumType so = 0, lc = 1;
    for(size_t i=0; i<m.size(); i++) {
      tie(so, lc) = solve(so, lc, m[i], mod[i]);
      if(so > LIMIT or so < 0) {
        return NIL;
      }
    }
    return make_pair(so, lc);
  }
};

int main() {
  int N;
  cin >> N;
  vector<int> P(N), Q(N);
  for(int i = 0; i < N; ++i){
    cin >> P[i];
    --P[i];
  }
  for(int i = 0; i < N; ++i){
    cin >> Q[i];
    --Q[i];
  }
  vector<vector<long long>> D(N,vector<long long>(N,INF));
  for(int i = 0; i < N; ++i){
    D[P[i]][Q[P[i]]] = 1;
  }
  for(int k = 0; k < N; ++k){
    for(int i = 0; i < N; ++i){
      for(int j = 0; j < N; ++j){
        D[i][j] = min(D[i][j],D[i][k]+D[k][j]);
      }
    }
  }
  CRT<int128> crt;
  vector<int128> m(N), mod(N);
  for(int i = 0; i < N; ++i){
    int128 r = D[P[i]][i], t = D[i][i];
    if(r == INF){
      cout << -1 << endl;
      return 0;
    }
    r %= t;
    m[i] = r;
    mod[i] = t;
    // cerr << (long long)r << " "<< (long long)t << endl;
  }
  auto ans = crt.solve(m,mod);
  if(ans.first > INF) cout << -1 << endl;
  else cout << (long long)ans.first << endl;
}



Measured memory_bytes: 3284
module Main where

import Data.Functor

main :: IO ()
main = do
  { [x,y] <- getInts
  ; if x == 0 && y == 0 then done
    else do
      { case compare x y of
        LT -> putInts [x,y]
        GT -> putInts [y,x]
        EQ -> putInts [x,y]
      ; main
     }
}

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show
done :: IO ()
done = return ()

Measured memory_bytes: 4112
n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]


def dfs(i, x, y, z):
    if i == n:
        return abs(a - x) + abs(b - y) + abs(c - z) - 30 if min(
            x, y, z) > 0 else float('inf')
    res0 = dfs(i + 1, x, y, z)
    res1 = dfs(i + 1, x + l[i], y, z) + 10
    res2 = dfs(i + 1, x, y + l[i], z) + 10
    res3 = dfs(i + 1, x, y, z + l[i]) + 10
    return min(res0, res1, res2, res3)


print(dfs(0, 0, 0, 0))


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

const int inf = 1e9;

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

  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i] >> b[i];

  vector<int> dp(10010, inf);
  dp[0] = 0;

  for (int i = 1; i <= h; ++i) {
    for (int j = 0; j < n; ++j) {
      int k = max(0, i - a[j]);
      dp[i] = min(dp[i], dp[k] + b[j]);
    }
  }

  cout << dp[h] << endl;
}

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

int main(){
	string w;
	cin>>w;
	map<char,int> a;
	
	for(int i = 0;i<w.size();i++){
		char s = w[i];
		a[s]++;
	}
	
	for(auto &element:a){
		int b = element.second;
		if(b%2==1){
			cout<<"No"<<endl;
			return 0;
		}
	}
	
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#ABC114B

#gets strrings from console, gets length of them

numStr = gets.chomp

lenStr = numStr.length

i = 0

while lenStr > 2
    numComp = numStr[i,3].to_i
    #puts numComp

    absolute = (numComp - 753).abs
    
    if i==0
        difference = absolute
    
    else
        if difference > absolute
            difference = absolute
        end
    end

    i+=1
    lenStr -= 1
end
puts difference

Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

const li mod = 1e9 + 7;

int main() {
    li n;
    string a, b, c;
    cin >> n >> a >> b >> c;
    li ans = 0;
    for (int i = 0; i < n; ++i) {
        set<char> cc;
        cc.insert(a[i]);
        cc.insert(b[i]);
        cc.insert(c[i]);
        ans += cc.size() - 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main () {
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  ll k;
  cin>>k;
  if(k%2==0)
  cout<<-1<<endl;
  else
  {
  	
  
  ll i;ll a=7;ll ans;ans=-1;
  if(a%k==0)
  {
  	ans=0;
  }
  else
  {
  	a=a%k;
  
  for(i=1;i<=k;i++)
  {
  	a=(a*10+7)%k;
  	if(a==0)
  	{
  		ans=i;
  		break;
	  }
  }
}
  if(ans==-1)
  cout<<-1<<endl;
  else
  cout<<ans+1<<endl;

}
  return 0;
}


Measured memory_bytes: 3592
"use strict";

const main = arg => {
    const A = parseInt(arg.split("\n")[0].split(" ")[0]);
    const B = parseInt(arg.split("\n")[0].split(" ")[1]);
    const C = parseInt(arg.split("\n")[0].split(" ")[2]);
    console.log(Math.floor(B / A) >= C ? C : Math.floor(B / A));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11468
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using P=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

int k, n;
int main(){
    cin >> k >> n;
    vector<int> a(n);
    cin >> a[0];
    rep(i, 1, n){
        int t; cin >> t;
        a[i] = t - a[0];
    }
    a.push_back(k);

    int maxl = 0;
    rep(i, 0, n){
        maxl = max(maxl, a[i+1]-a[i]);
    }

    cout << k - maxl << endl;

    return 0;
}


Measured memory_bytes: 4464
#include <bits/stdc++.h>
#define S second
#define F first
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll ;
typedef pair<int,int> pii ;

int d[105] ;
int b[105] ;

int main(){
    int n ;
    cin >> n ;
    for(int i =1 ; i<= n ; i++){
        cin >> d[i] >> b[i] ;
    }
    for(int i =1 ; i<= n-2 ; i++){
        if(d[i] == b[i] && d[i+1] == b[i+1] && d[i+2]==b[i+2]){
            cout << "Yes" ;
            return 0 ;
        }
    }
    cout << "No" ;
}


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


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	
	int n;
	cin >> n;
	vector<int> h(n);
	for(int i = 0; i < n; i++) {
		cin >> h[i];
	}
	vector<int> dp(n + 2, 1 << 30);
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for(int i = 2; i < n; i++) {
		dp[i] = min({dp[i], dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1])});
	}
  cout << dp[n - 1] << endl;
	return 0;	
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> l(m);
    vector<ll> r(m);
    rep(i, m) cin >> l.at(i) >> r.at(i);

    ll lmax, rmin;
    lmax = -1;
    rmin = INF;
    rep(i, m) lmax = max(lmax, l.at(i));
    rep(i, m) rmin = min(rmin, r.at(i));

    if(lmax <= rmin)
        cout << rmin - lmax + 1;
    else
        cout << 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>

int main(){
  std::vector<char> v;
  char x;
  while(1){
    std::cin>>x;
    if(std::cin.eof()){
      break;
    }
    v.push_back(x);
  }
  for(int i=0;i<8;i++){
    v.pop_back();
  }
  for(auto itr=v.begin();itr!=v.end();itr++){
    std::cout<<*itr;
  }
  std::cout<<std::endl;
  return 0;
}


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

using namespace std;

#define ALL(c) c.begin(), c.end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define DB(a) cerr << #a << " = " << (a) << endl;
#define OUT( a , n ) for( int J = 0; J < (n); J++ )cout<< (a)[J] << " \n"[J == (n) - 1 ]
#define WAIT cout << flush , system("PAUSE");
#define lowbit(x) ((x) & (-x))
#define CONTAINS(a, x) ((a).find(x) != (a).end())
#define endl '\n'
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repi(i,0,n)

typedef long long li;

const int N = 1e6+100;

int n;
long long s[N];
long long sum = 0;

int main()
{
	ios::sync_with_stdio( 0 );
	cin.tie( 0 );
	cin >> n;
	for( int i = 1; i <= n; i++ ){
		cin >> s[i];
		sum += s[i];
	}

	long long pre = 0;

	long long best = 1LL << 60;
	for( int i = 1; i < n; i++ ){
		pre += s[i];
		long long suf = sum - pre;
		best = min(best , abs(pre - suf));
	}
	cout << best << endl;


    return 0;
}


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

#define REP(i, a) for(int i=0; i<(int)(a); i++)
#define REP1(i, a, b) for(int i=(int)(a); i<=(int)(b); i++)
typedef long long LL;

const int MAX_N = 100005;
int n, A[MAX_N];

int cost(int a, int b) {
    return abs(A[a]-A[b]);
}

void solve() {
    scanf("%d", &n);
    REP(i, n) {
        scanf("%d", &A[i]);
    }
    int dp[MAX_N]={};
    REP(i, n) dp[i] = 1e9;
    dp[0] = 0;
    REP(i, n) {
        // cout << dp[i] << endl;
        if(i+1<n) dp[i+1] = min(dp[i+1], dp[i] + cost(i, i+1));
        if(i+2<n) dp[i+2] = min(dp[i+2], dp[i] + cost(i, i+2));
    }

    printf("%d\n", dp[n-1]);
}

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int a[1001];
int p[2];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	reverse(a,a+n);
	for(int i=0;i<n;i++){
		p[i%2]+=a[i];
	}
	printf("%d\n",p[0]-p[1]);
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	add := a + b
	sub := a - b
	mul := a * b
	if add > sub {
		if mul > add {
			fmt.Println(mul)
		} else {
			fmt.Println(add)
		}
	} else {
		if mul > sub {
			fmt.Println(mul)
		} else {
			fmt.Println(sub)
		}
	}
}


Measured memory_bytes: 640
a, b = map(int, input().split())
count = 0
for i in range(a,b+1):
  b1 = i%10
  s = i//10
  b2 = s%10
  t = s//10
  u = t//10
  a2 = u%10
  v = u//10
  a1 = v%10
  if a1 == b1 and a2 == b2:
    count += 1
print(count)

Measured memory_bytes: 3064
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a, p;
    cin >>a >>p;
    cout <<(p + (3*a)) / 2;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;

const ll maxN = 1e7;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

void build(ll node, ll start, ll end){
	if(start == end)
		segtree[node] = A[start];
	else{
		ll mid = (start + end)/2;
		build(left(node), start, mid);
		build(right(node), mid+1, end);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

void update(ll node, ll start, ll end, ll l, ll r, ll val){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(start > end or l > start or r < end)
		return ;
	else if(start >= l and r >= end){
		segtree[node] += val;
		if(start != end){
			lazy[left(node)] += val;
			lazy[right(node)] += val;
		}
	}
	else{
		ll mid=(start + end)/2;
		update(left(node), start, mid, l, r, val);
		update(right(node), mid+1, end, l, r, val);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

ll sums(ll node, ll start, ll end, ll l, ll r){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(l > end or r < start or start > end)
		return 0;
	if(l <= start and r >= end)
		return segtree[node];
	ll mid = (start+end)/2;
	return sums(left(node), start, mid, l , r) + sums(right(node), mid + 1, end, l , r);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n;
	string s;
	cin >> n >> s;
	stack<char> stc;
	string ans = "";
	for(auto x : s){
		if(x == '('){
			stc.push(x);
			ans += x;
		}
		else{
			if(stc.empty())
				ans = '(' + ans + ')';
			else{
				stc.pop();
				ans += ')';
			}
		}
	}
	while(!stc.empty()){
		stc.pop();
		ans+=')';
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3632
def main():
    N, W = list(map(int, input().split()))
    INF = float("inf")
    DP = [[INF for i in range(10**5+1)] for j in range(N+1)]
    DP[0][0] = 0
    for i in range(N):
        w, v = list(map(int, input().split()))
        for sum_v in range(10**5+1):
            if sum_v - v >= 0:
                DP[i+1][sum_v] = min(DP[i][sum_v],DP[i][sum_v-v]+w)
            
            DP[i+1][sum_v] = min(DP[i+1][sum_v],DP[i][sum_v])
            
    for i in range(10**5+1):
        if DP[N][i] <= W:
            ans = i
    print(ans)

if __name__ == "__main__":
    main()
    pass

Measured memory_bytes: 318780
//im not cheating https://www.codechef.com/viewsolution/21896322
#include "bits/stdc++.h"
using namespace std;
#include<cstdio>
#define fo(i, x, y) for(int i = x; i <= y; i ++)
using namespace std;

const int N = 5e5 + 5;

int T,n,m,x,y;
int fi[N],to[N * 2],nt[N * 2],tot,bz[N];
int fa[N],ans[N],siz[N];

void link(int x,int y){
	nt[++tot] = fi[x],to[tot] = y,fi[x] = tot;
}

void cl(){
	fo(i,1,n)	bz[i] = fi[i] = ans[i] = siz[i] = 0;
	tot = 1;
}

void dg(int x,int la){
	bz[x] = 1;
	for(int i = fi[x]; i; i = nt[i]) if(!bz[to[i]]){
		ans[i / 2] = (i & 1);
		siz[to[i]] ^= 1;
		dg(to[i],i);
		siz[x] ^= siz[to[i]];
	} else if(i != (la ^ 1)){
		ans[i / 2] = !(i & 1);
		siz[to[i]] ^= 1;
	}
	if(siz[x]) ans[la / 2] ^= 1;
}

int main(){
	//for(scanf("%d",&T); T; T--){
	cl();
	cin>>n>>m;
	vector<pair<int,int>>edge;
	fo(i,1,m){
		cin>>x>>y;
		edge.push_back({x,y});
		link(x,y); link(y,x);
	}
	if(m & 1){
		printf("-1\n"); return 0;
	}
	dg(1,0);
	fo(i,1,m){
		//printf("%d ",ans[i]);
		if(ans[i])cout<<edge[i-1].first<<" "<<edge[i-1].second<<endl;
		else cout<<edge[i-1].second<<" "<<edge[i-1].first<<endl;
	}
	//}
}


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

int main(){
    int n; cin>>n;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    vector<int> q(n);
    rep(i,n) q[p[i]-1]=i;
    int ans=1,tmp=1;
    rep(i,n-1){
        if(q[i]<q[i+1]) tmp++;
        else tmp=1;
        chmax(ans,tmp);
    }
    cout<<n-ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  cin >> n;
  vector<pl> d(n);
  rep(i, n) { cin >> d[i].first; }
  rep(i, n) { cin >> d[i].second; }
  ll res = -1;
  for (int i = 0; i < (1 << n); i++) {
    ll cost = 0;
    ll value = 0;
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        cost += d[j].second;
        value += d[j].first;
      }
    }
    chmax(res, value - cost);
  }
  cout << res << endl;
  return 0;
}


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

namespace AGC011A
{
    class Program
    {
        static void Main(string[] args)
        {
            var target = Console.ReadLine().Split(' ');
            int N = int.Parse(target[0]);
            int C = int.Parse(target[1]);
            int K = int.Parse(target[2]);
            var t = new List<int>();
            for(int i=0;i<N;i++){
                t.Add(int.Parse(Console.ReadLine()));
            } 
            t.Sort();
            int count = 1;
            int p1 = 1;
            int num = 1; //bus
            int time = t[0];
            while(p1 < t.Count){
                if(num < C && t[p1]-time <= K) {
                    num++;
                } else {
                    count++; time = t[p1]; num = 1;
                }             
                p1++;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 16092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int , int>
#define fast ios_base::sync_with_stdio(0)
#define mx 3001
#define eps 1e-10
double dp[mx][mx], arr[mx], mns = -1.0;
int n, lim;
double fun(int pos, int cnt)
{
    if(pos>n){
        if(cnt>=lim) return 1;
        else return 0;
    }
    double& ret = dp[pos][cnt];
    if(abs(ret - mns) >eps) return ret;
    ret = 0;
    ret+= ( fun(pos+1, cnt+1)*arr[pos] );
    ret+= ( fun(pos+1, cnt)*(1.0 - arr[pos]) );
    return ret;
}
int main()
{
    fast;
    cin>>n;
    for(int i=1; i<=n; i++) cin>>arr[i];
    for(int i=0; i<mx; i++) for(int j=0; j<mx; j++) dp[i][j] = -1.0;
    lim = n/2 + 1;
    cout<<fixed<<setprecision(12)<<fun(1,0)<<endl;
}


Measured memory_bytes: 70784
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - We Love Golf
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int k, a, b;
  scanf("%d%d%d", &k, &a, &b);

  int ak = (a + k - 1) / k;
  int bk = b / k;

  if (ak <= bk) puts("OK");
  else puts("NG");
  return 0;
}


Measured memory_bytes: 3164
team=[0]*101
while 1:
    p,s=map(int,input().split(","))
    if p==s==0:break
    team[p]=s
rank=list(set(team))
rank.sort(reverse=True)
while 1:
    try:
        n=int(input())
        print(rank.index(team[n])+1)
    except:break


Measured memory_bytes: 5592
#和のセグ木にするときは以下の関数を定義する必要あり。
def segfunc(x,y):
  return x+y

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)


N,M,Q = map(int,input().split())
A = []
for i in range(M):
  a,b = map(int,input().split())
  A.append([a,b,-1]) #-1は鉄道
for i in range(Q):
  a,b = map(int,input().split())
  A.append([a,b,i]) #iはクエリのID。出力でIDの順に並べる
A.sort(key=lambda x : x[1]) #終点でソート
MAX = 510
Range = [0 for _ in range(MAX)]
Tree = SegmentTree(Range,segfunc,0)
#print(A)
ans = [-1 for _ in range(Q)]
for i in range(M+Q):
  a,b,ID = A[i]
  if ID == -1:
    Tree.add(a,1)
  else:
    temp = Tree.sum(a,b+1) #セグ木の取得は開区間なのでb+1
    ans[ID] = temp
#print(ans)
print(*ans,sep="\n")
    


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

int main(){
    int N;
    cin >> N;
    vector<int> par(N+1);
    vector<vector<int>> out(N+1, vector<int>());
    vector<int> outcnt(N+1, 0);
    
    par[1] = 0;
    for (int i = 2; i <= N; i++) {
        int a;
        cin >> a;
        par[i] = a;
        out[a].push_back(i);
        outcnt[a]++;
    }
    
    queue<int> b;
    vector<int> beat(N+1, 0);
    
    for (int i = 1; i <= N; i++) {
        if (out[i].empty()) {
            b.push(i);
        }
    }
    cout << endl;
    
    while (!b.empty()) {
        int now = b.front();
        b.pop();
        vector<int> cb;
        if (!out[now].empty()) {
            for (int c : out[now]) cb.push_back(beat[c]);
            sort(cb.begin(), cb.end());
            reverse(cb.begin(), cb.end());
            for (int i = 0; i < (int)cb.size(); i++) {
                beat[now] = max(beat[now], cb[i] + i + 1);
            }
        }
        outcnt[par[now]]--;
        if (outcnt[par[now]] == 0) b.push(par[now]);
    }
    
    cout << beat[1] << endl;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

struct UnionFind{
    vector<int> par;
    UnionFind(int n) : par(n,-1) { }
    void init(int n) { par.assign(n,-1); }
    int root(int x){
        if(par[x]<0) return x;
        else return par[x]=root(par[x]);
    }
    bool issame(int x,int y){
        return root(x)==root(y);
    }
    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(par[x]>par[y]) swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }
    int size(int x){
        return -par[root(x)];
    }
};

int main(){
    int n,k,l;
    cin>>n>>k>>l;
    UnionFind uf1(n),uf2(n);
    rep(i,k){
        int p,q;
        cin>>p>>q;
        p--,q--;
        uf1.merge(p,q);
    }
    rep(i,l){
        int p,q;
        cin>>p>>q;
        p--,q--;
        uf2.merge(p,q);
    }
    
    using pint=pair<int,int>;
    map<pint,int> ma;
    rep(v,n){
        pint p(uf1.root(v),uf2.root(v));
        ma[p]++;
    }

    rep(v,n){
        pint p(uf1.root(v),uf2.root(v));
        cout<<ma[p]<<" ";
    }
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define DBG(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define CIN(type, ...) \
  type __VA_ARGS__;    \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define COUT(...) write_to_cout(__VA_ARGS__);

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, n) for (auto i : (n))
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  ll A;
  ll B1, B2;
  scanf("%lld %lld.%lld", &A, &B1, &B2);
  COUT(A * (B1 * 100 + B2) / 100);
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define pii pair<ll,ll>
#define x1 dlfjl
#define x2 dkfj
#define x3 dflgkg
#define y1 dskgj
#define y2 dskfj
#define y3 dfhgdh
#define SQ 320
#define PI 3.14159265359
#define MOD 1000000007
typedef int ll;
using namespace std;
ll n,i,j,k,z,m,q,r,timer,v,tot,x,y,xx, yy,INF, sz;
ll a[100500], cnt[100500];
int main() {
    //freopen("input.txt","r",stdin);
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i+1 < n; i++) {
        if (a[i] + a[i+1] >= k) {
            cout << "Possible" << endl;
            for (int j = 0; j < i; j++)
                cout << j+1 << endl;
            for (int j = n-2; j > i; j--)
                cout << j+1 << endl;
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << "Impossible" << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    ll N; cin >> N;
    ll ans = 0;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i != 0) continue;
        if (i * i == N) {
            if (i > 1 && N % (i - 1) == N / (i - 1)) {
                ans += i - 1;
            }
        } else {
            if (i > 1 && N % (i - 1) == N / (i - 1)) {
                ans += i - 1;
            }
            if (N / i > 1 && N % (N / i - 1) == N / (N / i - 1)) {
                ans += N / i - 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    char c;

    while(1){
        scanf("%c", &c);
        if(c >= 'a' && c <= 'z')
            c = c - 32;
        else if(c >= 'A' && c <= 'Z')
            c = c + 32;
        putchar(c);

        if(c == '\n')
            break;
    }
    return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int moji;
    
    cin>>moji;
    
    int MM = moji%100;
    int YY = moji/100;
    
    if((1 <= MM && MM <= 12) && (1 <= YY && YY <= 12)){
        cout<<"AMBIGUOUS"<<endl;
    }
    else if((1 <= MM && MM <= 12) && (YY > 12 || YY==0) ){
        cout<<"YYMM"<<endl;
    }else if((1 <= YY && YY <= 12) && (MM > 12 || MM==0) ){
        cout<<"MMYY"<<endl;
    }else{
        cout<<"NA"<<endl;
    }
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iostream>

using namespace std;

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

typedef long long int		   ll;
typedef long long unsigned int llu;

void solve(ll N) {
	for(int i = N; i > 0; i--) {
		if(i == 64) {
			printf("64"); break;
		}
		else if(i == 32) {
			printf("32"); break;
		}
		else if(i == 16) {
			printf("16"); break;
		}
		else if(i == 8) {
			printf("8"); break;
		}
		else if(i == 4) {
			printf("4"); break;
		}
		else if(i == 2) {
			printf("2"); break;
		}
		else if(i == 1) {
			printf("1"); break;
		}
	}
}

int main() {
	ll N;
	scanf("%lld", &N);
	solve(N);
	return 0;
}


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

void solve() {
    int x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int x_diff = x2 - x1;
    int y_diff = y2 - y1;

    int x3 = x2 - y_diff;
    int y3 = y2 + x_diff;
    int x4 = x1 - y_diff;
    int y4 = y1 + x_diff;

    printf("%d %d %d %d\n", x3, y3, x4, y4);
}

int main() {
    solve();

    return 0;
}


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int s, w;
    cin >> s >> w;
    if(s<=w){
        c("unsafe");
    }else
        c("safe");
    return 0;
}


Measured memory_bytes: 3640
n,a,b = map(int,input().split())
s = input()
ca = 0
cb = 0
for i in range(n):
  if s[i] == 'a':    
    if ca + cb < a + b:
      ca += 1
      print('Yes')
      continue
  if s[i] == 'b':    
    if (ca + cb < a + b) and cb < b:
      cb += 1
      print('Yes')
      continue
  print('No')    

Measured memory_bytes: 9244
#include<stdio.h>
int main(){

int i,a,b;
char op;
i=1;
while(i=1){
  scanf("%d ",&a);
  scanf("%c ",&op);
  scanf("%d",&b);

  if(op=='+'){
  printf("%d\n",a+b);
  }
  else if(op=='-'){
    printf("%d\n",a-b);
  }
  else if(op=='*'){
    printf("%d\n",a*b);
  }
  else if(op=='/'){
    printf("%d\n",a/b);
  }
  else {
    break;
  }
}




return 0;
}



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

// Debug {{{
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    for (auto& e : v) os << e << ", ";
    return os << "]";
}

template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "(" << p.first << " " << p.second << ")";
}
// }}}


// macro {{{
#define rep(i,n) for (int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i,n) for (int i=1, i##_len=(n); i<=i##_len; ++i)

#define SZ(x) ((int)(x).size())

#define all(x) begin(x),end(x)
// }}}


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


// type {{{
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int,int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
// }}}


// constants {{{
template<typename T>
T inf() { return numeric_limits<T>::max(); }

const ll MOD = 1e9+7;
const ld EPS = 1e-9;
// }}}


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    for (;;) {
        ll n, m; cin >> n >> m;
        if (n == 0) break;
        map<ll,ll> mp;
        rep (i, n) {
            ll d, p; cin >> d >> p;
            mp[p] += d;
        }
        for (auto it = rbegin(mp); it != rend(mp) and m > 0; ++it) {
            ll mi = min(m, it->second);
            m -= mi, it->second -= mi;
        }
        ll ans = 0;
        for (auto& tp : mp) {
            ans += tp.first * tp.second;
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3120