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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

void solve() {
  int n, m, d; scanf("%d%d%d", &n, &m, &d);
  if (d == 0) {
    printf("%.6f", 1.*(m-1)/n);
  } else {
    printf("%.6f", 1.*(m-1)/(1.*n*n/(2*(n-d))));
  }
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3808
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		bool[,] vis = new bool[H,W];
		vis[0,0] = true;
		
		Func<int,int,bool> InRange = (r,c) =>{
			return 0<= r && r < H && 0 <= c && c < W;	
		};
		
		int[] dx = new int[] {0,1};
		int[] dy = new int[] {1,0};
		
		Queue<Pair> Q = new Queue<Pair>();
		Q.Enqueue(new Pair(0,0));
		while(Q.Count>0){
			var p = Q.Dequeue();
			for(int t=0;t<2;t++){
				int nr = p.R + dy[t];
				int nc = p.C + dx[t];
				if(InRange(nr,nc) && vis[nr,nc] == false){
					vis[nr,nc] = true;
					Q.Enqueue(new Pair(nr,nc));
				}
			}
		}
		
		int cnt = 0;
		for(int i=0;i<H;i++) cnt += S[i].Count(c => c == '#');
		Console.WriteLine( (cnt == (H+W-1) && vis[H-1,W-1])?"Possible":"Impossible");
		
		
	}
	
	class Pair{
		public int R,C;
		public Pair(int r, int c){
			R = r; C = c;
		}
	}
	
	int H,W;
	String[] S;
	public Sol(){
		var d = ria();
		H = d[0];
		W = d[1];
		S = new String[H];
		for(int i=0;i<H;i++) S[i] = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 2904
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
    int n,i;
    long long D1=0.0f,D2=0.0f,D3=0.0f,D=0.0f,d;
    cin >> n;
    int x[n],y[n];
    for (i=0;i<n;i++) cin >> x[i];
    for (i=0;i<n;i++) cin >> y[i];
    for (i=0;i<n;i++) {
        d = abs(x[i]-y[i]);
        D1 += d;
        D2 += d*d;
        D3 += d*d*d;
        if (D < d) D = d;
    }
    printf("%.8f\n%.8f\n%.8f\n%.8f\n", (double)D1, sqrt((double)D2), pow((double)D3,1.0/3.0), (double)D);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  string c;
  bool flag = false;
  
  for(int i=0;i<N;i++){
    cin >> c;
    if (c == "Y"){
      flag = true;
      break;
    }
  }
  if(flag){
    cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
import math
N,D = map(int,input().split())

X = []
for i in range(N):
  x = list(map(int,input().split()))
  X.append(x)
cnt = 0

for i in range(N):
  for j in range(i+1,N):
    dist = 0
    for k in range(D):
      dist += pow(X[i][k]-X[j][k],2)
    dist = math.sqrt(dist)
    
    if dist.is_integer():
      cnt += 1
      
print(cnt)
      

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    if (n % 2 == 1 || n <= 0) {
        cout << "No" << endl;
    } else {
        bool can = true;
        for (int i = 0; i < n / 2; ++i) {
            if (s[i] != s[(n/2) + i]) {
                can = false;
                break;
            }
        }
        if (can) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    ll x = 0;
    for (int i = 40; i >= 0; i--) {
        ll cnt = 0;
        rep(j, N) if ((A[j] >> i & 1) == 1) cnt++;

        ll s = (1LL << i);
        if (cnt < (N + 1) / 2 && x + s <= K) x += s;
    }

    ll ans = 0;
    rep(i, N) ans += x ^ A[i];
    cout << ans << endl;
}


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


int main(){
    int64_t N,K;
    int64_t sum = 0;
    cin >> N >> K;
    vector<int64_t> p(N);
    for(int64_t i = 0; i < N; i++){
        cin >> p.at(i);
    }
    sort(p.begin(), p.end());
    for(int64_t j = 0; j < K; j++){
        sum += p.at(j);
    }

    cout << sum << endl;
}

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

int main(){
  string str;
  cin >> str;
  int w;
  cin >> w;
  for(int i = 0 ; i < str.size() ; i++){
    if(i % w == 0){
      cout << str[i];
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}

ll nCr(ll n, ll r){//mod逆元使ったnCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元によりr!で割ると同値
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){ if(b==0) return a; return gcd(b, a%b);}

int counter(int x){
    if(x==0) return 0;
    return counter(x>>1)+(x&1);
}


int main(){
    fast_io

    int n,k;
    cin>>n>>k;
    int ans=n-k+1;

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

Measured memory_bytes: 256
a,b,x,y,v,w,S;main(i,n){for(;scanf("%d%d%d",&n,&x,&y)*n;S=!printf("%d %.1f\n",i++,S/2.))for(a=x,b=y;n--;S+=(x-v)*(y+w))v=x,w=y,!n?x=a,y=b:scanf("%d%d",&x,&y);}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int A, B;
	cin >> A >> B;
	int ans = 0;
	if (A <= 3) {
		ans += 100000 * (4 - A);
	}
	if (B <= 3) {
		ans += 100000 * (4 - B);
	}
	if (A == 1 && B == 1) {
		ans += 100000 * 4;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

M_0 = sum(A) - sum([ A[i]* 2 for i in range(1, N, 2)])
ans = [M_0]
for i in range(N-1):
    m = 2 * A[i] - ans[i]
    ans.append(m)

print(' '.join(map(str, ans)))

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

int main(){
int x,y;
while(1){
    cin>>x>>y;
    if(x==0&&y==0)break;
    if(x>y){
        cout<<y<<" "<<x<<endl;
    }else if(x<y){
        cout<<x<<" "<<y<<endl;
    }else {
        cout<<y<<" "<<x<<endl;
    }
}

}


Measured memory_bytes: 2992
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n;
cin >> n;
if(n<=999) {
  cout << "ABC" << endl;
} else {
  cout << "ABD" << endl;
}
return 0;
}


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

int main() {
	int input;
	int number[4];

	cin >> input;

	for (int i = 0; i < 4; i++) {
		number[i] = input / pow(10, 3 - i);
		input -= number[i] * pow(10, 3 - i);
	}

	if ((number[0] == number[1] && number[1] == number[2]) || (number[1] == number[2] && number[2] == number[3])) {
		cout << "Yes";
	}

	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;

ll INF = 1e+18;
int iINF = 1e9;

bool
comp(pair<ll, ll> a, pair<ll, ll> b)
{
  return a.second < b.second;
}

int 
main()
{
  int N; cin >> N;
  vector<pair<ll, ll>> arr(N);
  rep(i, 0, N){
    cin >> arr[i].first >> arr[i].second;
  }

  sort(arr.begin(), arr.end(), comp);

  ll now = 0;
  rep(i, 0, N){
    now += arr[i].first;
    if(now > arr[i].second){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

}

Measured memory_bytes: 6352
#include <iostream>
#include <vector>
#include <string>
using ll = long long;
using namespace std;

int main(){
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> k(n, 0);
    for (int i = 0; i < n - 1; i++){
        if (i != 0)
            k[i] = k[i - 1];
        if (s[i] == 'A' && s[i + 1] == 'C')
            k[i]++;
    }
    int l, r;
    for (int i = 0; i < q; i++){
        cin >> l >> r;
        l--;
        r--;
        int cnt = k[r - 1] - k[l - 1];
        cout << cnt << endl;
    }
    return 0;
}

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

using namespace std;

const void chmax(int &a, int b)
{
  a = max(a, b);
}

int main()
{
  int Q, W, H, r[20][20];
  int dp[2][1 << 20];

  cin >> Q;
  for(int c = 1; c <= Q; c++) {
    cin >> W >> H;
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        cin >> r[i][j];
      }
    }

    memset(dp, -1, sizeof(dp));
    int *now = dp[0], *nxt = dp[1];
    int mask = (1 << W) - 1;
    now[0] = 0;

    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        for(int k = 0; k < 1 << W; k++) {
          if(now[k] == -1) continue;
          int tugi = (k << 1) & mask;
          chmax(nxt[tugi], now[k]);
          if(j > 0 && k & 1) continue;
          if((k >> (W - 1)) & 1) continue;
          chmax(nxt[tugi | 1], now[k] + r[i][j]);
        }
        swap(now, nxt);
        for(int k = 0; k < 1 << W; k++) nxt[k] = -1;
      }
    }
    cout << "Case " << c << ": " << *max_element(now, now + (1 << W)) << endl;
  }
}

Measured memory_bytes: 11260
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
    ll MOD = 1000000007;
    string s;
    cin >> s;
    int k = s.size();
    int d;
    cin >> d;
    ll before[d] = {};
    ll ans[d] = {};
    ll keep[d] = {};

    int x = (int)s[0] - 48;
    //cout << x << endl;

    rep(i,10){
        if(i<x){
            ans[i%d]++;
        }else if(i==x){
            keep[i%d]++;
        }else{
            ;
        }
    }

    srep(i,1,k){
        rep(j,d){
            before[j] = ans[j];
            ans[j] = 0;
        }
        x = (int)s[i] - 48;
        ll next_keep[d] = {};
        rep(j,10){
            if(j<x){
                rep(l,d){
                    ans[(l+j)%d] += before[l] + keep[l];
                    ans[(l+j)%d] %= MOD;
                }
            }else if(j==x){
                rep(l,d){
                    ans[(l+j)%d] += before[l];
                    ans[(l+j)%d] %= MOD;
                }
                rep(l,d){
                    next_keep[(l+j)%d] = keep[l];
                }
            }else{
                rep(l,d){
                    ans[(l+j)%d] += before[l];
                    ans[(l+j)%d] %= MOD;
                }
            }
        }
        rep(j,d){
            keep[j] = next_keep[j];
        }
    }

    ll res = ans[0] + keep[0] + MOD - 1;
    res %= MOD;
    cout << res << endl;
}
 
 


Measured memory_bytes: 256
def solve(n):
  s = set()
  i = 1;
  x = 7 % n
  while (not (x in s)):
    if x == 0:
      return i;
    s.add(x)
    x = x * 10 + 7;
    x %= n;
    i += 1
  return -1

if __name__ == '__main__':
  n = int(input())
  if n == 2 or n == 5:
    print(-1)
  else:
    print(solve(n))


Measured memory_bytes: 156124
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007

using namespace std;

int main() {
    string S,T;
    cin>>S>>T;
    bool ans=true;
    int used[27]={0,};

    for(int i=0;i<S.size();i++){
        if(S[i]!=T[i]){
            if(used[S[i]-'a']!=0){
                ans=false;
                break;
            }
            string t = T;
            for(int j=0;j<S.size();j++){
                if(i==j)continue;
                if(T[j]==T[i]){
                    T[j]=S[i];
                }
            }
            char tc = T[i];
            T[i]=S[i];
            for(int j=0;j<S.size();j++){
                if(t[j]==S[i]){
                    T[j]=tc;
                }
            }
            used[S[i]-'a']=1;
        }
    }
    if(T!=S)ans=false;

    cout<<(ans?"Yes":"No");
    return 0;
}

Measured memory_bytes: 904
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string S;
    cin >> S;
    int count0=0, count1=0;

    for(int i=0;i<S.size();i++){
        if(S[i] == '0') ++count0;
        else ++count1;
    }

    cout << 2*min(count0, count1) << endl;
}


Measured memory_bytes: 512
import itertools

def main():
    N = int(input())
    S = list(input())

    ans = [S[0]]

    for i in range(1, len(S)):
        if ans[-1] != S[i]:
            ans.append(S[i])

    print(len(ans))
    return 0
if __name__ == '__main__':
    main()

Measured memory_bytes: 4648
#include <utility>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define INTINF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;

struct Node{
  int key;
  Node *parent, *left, *right;
};

Node *root, *NIL;


void insert(int num){
  Node *y = NIL;
  Node *x = root; //start
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = num;
  z->left = NIL;
  z->right = NIL;

  while ( x!=NIL ) {
    y=x; //おや
    if ( z->key < x->key ) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if (y==NIL) { //最初
    root = z;
  }else{
    if( z->key < y->key ){  //親より小さければ左につく
      y->left = z;
    }else{
      y->right = z;
    }
  }
}

void find(int num){
  Node *x = root;

  while ( x!=NIL ) {
    if (num < x->key) {
      x=x->left;
    } else if (num > x->key) {
      x=x->right;
    } else {
      std::cout << "yes" << '\n';
      return;
    }
  }
  std::cout << "no" << '\n';
  return;
}


void print_in(Node *u){
  if(u==NIL) return;
  print_in(u->left);
  std::cout << " " << u->key;
  print_in(u->right);
}


void print_pre(Node *u){
  if(u==NIL) return;
  std::cout << " " << u->key;
  print_pre(u->left);
  print_pre(u->right);
}


int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k, num; std::cin >> k;
  string command;
  for (size_t i = 0; i < k; i++) {
    std::cin >> command;
    if (command=="insert") {
      std::cin >> num;
      insert(num);
    } else if (command=="print"){
      print_in(root);
      std::cout << '\n';
      print_pre(root);
      std::cout << '\n';
    } else if (command=="find"){
      std::cin >> num;
      find(num);
    }
  }

  return 0;
}



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

using ll = long long;

int main() {
  int n; cin >> n;
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += (ll)(i+1)*(ll)(n-i);
  }
  // cout << ans << endl;
  for (int i = 0; i < n-1; ++i) {
    ll u, v;
    cin >> u >> v;
    int l = min(u,v);
    int r = max(u,v);
    ans -= (ll)(l)*(ll)(n-r+1);
  }
  cout << ans << endl;
}



Measured memory_bytes: 3636
import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}
	
	int n = read.to!int;
	
	int[] bs;
	foreach(i; 0 .. n) bs ~= read.to!int - 1;
	
	int[] ans;
	bool f = 0;
	while(1){
		f = 0;
		foreach_reverse(i; 0 .. n){
			if(bs[i] == i){
				foreach(j; i .. n - 1) bs[j] = bs[j + 1];
				bs[n - 1] = -1;
				ans ~= i + 1;
				f = 1;
				break;
			}
		}
		if(! f) break;
	}
	
	if(ans.length == bs.length) foreach_reverse(a; ans) a.writeln;
	else "-1".writeln;
}

/*

逆順で考える。
「i(N ... 1)回目の操作では、長さiの列があって、j番目にあるjを除去する」

注意すべきは、除去が進むとどんどん位置は先頭方向にずれていく
一旦、位置<数 になったものは、もう取れなくなる

だからもし候補がいくつかあったら、一番後方にあるものを優先して取る

実際に配列から抜き取りをすると遅くなる？　N=100だから大丈夫


*/


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::vector<ll> vll;
typedef std::vector<vll> vvll;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int n, a, b;
  scan(n, a, b);
  int ans1 = max(0, a+b-n);
  int ans0 = min(a, b);
  printf("%d %d\n", ans0, ans1);
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;
const int N=1000000+10;
int n,m,d[N];
vector<int> g[N];
pair<int,int> p[N];
map< pair<int,int>,int > id;
set<int> st;
int col[N],ans[N];
void dfs(int u){
    int cnt=0;
    for(auto v: g[u]) {
        if(st.count(v)) {
            if(col[v]==0){
                col[v]=3-col[u]; 
                ans[id[make_pair(u,v)]] = d[u]; cnt++;
                dfs(v);
            } else if (col[v]+col[u]==3) {
                cnt ++;
            }
            continue;
        }
        if(col[v]==3-col[u]) {
            ans[id[make_pair(u,v)]] = d[u]; cnt++;
        }
    }
    if(cnt==0) {
        printf("-1\n"); exit(0);
    }
}

int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d",&d[i]),p[i]=make_pair(d[i],i);
    for(int i=1;i<=m;i++){
        int x,y; scanf("%d%d",&x,&y); 
        g[x].push_back(y); g[y].push_back(x);
        id[make_pair(x,y)]=id[make_pair(y,x)]=i;
    }
    sort(p+1,p+1+n);
    for(int i=1,j=1;i<=n;i=j){
        vector<int> tmp; st.clear();
        while(j<=n && p[j].first==p[i].first) {
            tmp.push_back(p[j].second); st.insert(p[j].second); j++;
        }
        //printf("!\n");
        for(auto x: tmp){
            //printf("%d ",x);
            if(col[x]==0){
                for(auto v: g[x]) {
                    if(col[v]) {
                        col[x]=3-col[v];
                    }
                } 
                if(!col[x]) col[x]=1; 
                dfs(x);
            }
        }
        //printf("\n");
    }
    for(int i=1;i<=n;i++){
        printf("%c", col[i]==1?'W':'B');
    }
    printf("\n");
    for(int i=1;i<=m;i++){
        printf("%d\n", ans[i]?ans[i]:(int)1e9);
    }
}

Measured memory_bytes: 68760
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    a = list(map(int, input().split()))

    x = 0
    for i in range(2, n):
        x ^= a[i]
    d = a[0]+a[1]-x
    if d%2 == 1 or d < 0:
        print(-1)
        return
    d >>= 1
    if d&x != 0 or d > a[0]:
        print(-1)
        return
    k = x.bit_length()
    tmp = d
    # d^tmp はd&x=0からd+tmpと一緒
    for i in range(k-1, -1, -1):
        if (x >> i) & 1:
            if tmp+(1<<i) <= a[0]:
                tmp += 1<<i
    if 0 < tmp <= a[0]:
        print(a[0]-tmp)
    else:
        print(-1)



if __name__ == '__main__':
    main()

Measured memory_bytes: 9220
def main():
  #n = int(input())
  #s = input()
  #s = input().split()
  a,b = list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 0
  lis = []
  
  print(a+b//2)

if __name__ == '__main__':
  main()

Measured memory_bytes: 2940
N, K = map(int, input().split())
E = list(map(lambda x: (int(x) - 1) / 2 + 1, input().split()))
s = sum(E[:K])
ans = s
for i in range(K, N):
    s -= E[i-K]
    s += E[i]
    ans = max(ans, s)
print(ans)


Measured memory_bytes: 72048
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const int N = 2e7 + 7;
const int mod=1e9+7;
const int INF=1e18+7;
const int dx[] = {-1, 1, 0,  0}; // UDLR
const int dy[] = { 0, 0, -1, 1}; // UDLR
inline int maximum (int a,int b){
     if(a>b) return a;
     else return b;
}
inline int minimum (int a,int b){
    if(a>b) return b;
     else return a;
}
int32_t main (){
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);cout.tie(NULL);

        int n,k; cin>>n>>k; vector<int> h(n+1); vector<int> dp(n+1,INF);
        for(int i=1;i<=n;i++) cin>>h[i];
        dp[1]=0;
        for(int i=2;i<=n;i++){
          for(int j=i-k>=1?i-k:1;j<=i;j++){
            dp[i]=minimum(dp[j]+abs(h[i]-h[j]),dp[i]);
          }
        }
          cout<<dp[n];
 return 0;
 }


Measured memory_bytes: 4768
#!/usr/bin/env python3
import sys
import heapq
import bisect
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    ret = sum(A)
    cs = Counter(A)
    for c in C:
        if c not in cs:
            cs[c] = 0
    vs = sorted(cs.keys())

    i = 0
    while cs[vs[i]] == 0:
        i += 1

    for b, c in zip(B, C):
        while 0 < b:
            if c <= vs[i]:
                break
            bb = min(b, cs[vs[i]])
            b -= bb
            cs[vs[i]] -= bb
            cs[c] += bb
            ret += bb * (c - vs[i])
            if cs[vs[i]] == 0:
                i += 1
    return ret


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]" 
    C = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    result = solve(N, M, A, B, C)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 36844
#include <stdio.h>

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

	if (a < b) {
		printf("a < b\n");
	}
	else if (a > b) {
		printf("a > b\n");
	}
	else if (a == b) {
		printf("a == b\n");
	}

	return 0;
}



Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)

int main()
{
    while (true)
    {
    	int n;
    	cin >> n;
    	if (n == 0) break;
    	string s;
    	int ans = 0;
    	stack<pair<char, int>> operate;
    	operate.push(make_pair('+', 0));
    	for (int i = 0;i < n;++ i) {
    		cin >> s;
    		while (operate.size() > s.size()) {
    			int tmp = operate.top().second;
    			operate.pop();
    			if (operate.top().first == '+') operate.top().second += tmp;
    			else operate.top().second *= tmp;
    		}
    		if ('0' <= s[s.size() - 1] && s[s.size() - 1] <= '9') {
    			if (operate.top().first == '+') operate.top().second += s[s.size() - 1] - '0';
    			else operate.top().second *= s[s.size() - 1] - '0';
    		} else if (s[s.size() - 1] == '+') operate.push(make_pair('+', 0));
    		else operate.push(make_pair('*', 1));
    	}
    	while (operate.size() > 1) {
			int tmp = operate.top().second;
			operate.pop();
			if (operate.top().first == '+') operate.top().second += tmp;
			else operate.top().second *= tmp;
    	}
    	cout << operate.top().second << endl;
    }
    return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define rREP(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define rFOR(i, a, b) for (int i = a; i >= b; --i)
#define aFOR(i, V) for (auto i : V)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
#define INF 1'000'000'007 // 10^9 + 7
#define MOD 1'000'000'007 // 10^9 + 7
#define lINF 1'000'000'000'000'000'007 // 10^18 + 7
// ------------------------------

int main() {
    int n;
    cin >> n;
    vector<int> odd_v(n/2);
    vector<int> even_v(n/2);
    map<int, int> odd_m;
    map<int, int> even_m;
    REP(i, n/2) {
        cin >> odd_v[i];
        cin >> even_v[i];
        odd_m[odd_v[i]] += 1;
        even_m[even_v[i]] += 1;
    }
    vector<pair<int, int>> odd_v2, even_v2;
    aFOR(i, odd_m) {
        odd_v2.push_back(make_pair(i.second, i.first));
    }
    aFOR(i, even_m) {
        even_v2.push_back(make_pair(i.second, i.first));
    }
    sort(rALL(odd_v2));
    sort(rALL(even_v2));
    int ans;
    if (odd_v2[0].second != even_v2[0].second) ans = (n/2 - odd_v2[0].first) + (n/2 - even_v2[0].first);
    else ans = min((n/2 - odd_v2[1].first) + (n/2 - even_v2[0].first),
        (n/2 - odd_v2[0].first) + (n/2 - even_v2[1].first));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9392
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	long double n;
	cin >> n;
	cout << (1LL << ((int)(log2(n))) + 1) - 1;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
#define PI 3.14159265358979323846
using namespace std;
//
int main(){
  int A,B;
  string S;
  cin>>A>>B;
  cin>>S;
  FOR(i,0,(int)S.size()){
    if(i==A){
      if(S[i]=='-'){
        continue;
      }else{
        Yes(0);
        return 0;
      }
    }else{
      if(S[i]=='-'){
        Yes(0);
        return 0;
      }else{
        continue;
      }
    }
  }
  Yes(1);
  return 0;
}


Measured memory_bytes: 256
def main():
    S = list(input())
    even = [ "0" if (i + 1) % 2 == 0 else "1" for i in range(len(S))]
    odd  = [ "0" if (i + 1) % 2 != 0 else "1" for i in range(len(S))]
    n_even = 0
    n_odd = 0
    for i in range(len(S)):
        if S[i] != even[i]:
            n_even += 1
        if S[i] != odd[i]:
            n_odd += 1
    print(min(n_odd, n_even))
main()

Measured memory_bytes: 5540
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
int d, ile;
long long int dp[10010][110][14], wynik;
string k;
int main()
{
	cin >> k;
	scanf("%d", &d);
	for (int i=0; i<=9; i++)
	{
		dp[1][i%d][i]=1;
	}
	for (int i=1; i<=(int)k.size(); i++)
	{
		for (int j=0; j<d; j++)
		{
			for (int o=0; o<=8; o++)
			{
				dp[i][j][o+1]=(dp[i][j][o+1]+dp[i][j][o])%M;
			}
			for (int o=0; o<=9; o++)
			{
				dp[i+1][(j+o)%d][o]=(dp[i+1][(j+o)%d][o]+dp[i][j][9])%M;
			}
		}
	}
	int dl=(int)k.size();
	for (int i=0; i<(int)k.size(); i++)
	{
		if (k[i]=='0' && dl!=1) 
		{
			dl--;
			continue;
		}
		if (dl!=1)
		{
			wynik=(wynik+dp[dl][ile][k[i]-'0'-1])%M;
			//printf("[%d][%d][%d]\n", dl, ile, k[i]-'0'-1);
		}
		if (dl==1)
		{
			wynik=(wynik+dp[dl][ile][k[i]-'0'])%M;
			//printf("[%d][%d][%d]\n", dl, ile, k[i]-'0');
		}
		dl--;
		ile=(ile+((k[i]-'0')/d+1)*d-k[i]+'0')%d;
	}
	wynik=(wynik+M-1)%M;
	printf("%lld", wynik);
}


Measured memory_bytes: 120576
s = int(input())

cnt = 0
a_n = 0
a_m = 0
score = list()

while(True):
    if cnt == 0:
        a_m = s
    else:
        a_n = a_m
        if a_n % 2 == 0:
            a_m = a_n / 2
        else:
            a_m = a_n * 3 + 1
    if a_m in score:
        print(cnt + 1)
        break
    else:
        score.append(a_m)
        cnt = cnt + 1


Measured memory_bytes: 3060
/*input
7 7
1 2
1 3
1 4
4 5
5 6
5 7
2 3
2
6 1 1
1 2 2
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

vector<int> edge[maxn];
int a[maxn],d[maxn],c[maxn];

bool vis[maxn][11];
int ans[maxn];

void f(int u,int D,int clr){
	//cout<<u<<' '<<D<<' '<<clr<<'\n';
	if(D<0) return;
	if(ans[u]==-1) ans[u]=clr;
	if(vis[u][D]) return;
	vis[u][D]=1;
	f(u,D-1,clr);
	for(int v:edge[u]) f(v,D-1,clr);
}


int main()
{
	IOS;
	int n,m;
	cin>>n>>m;
	REP(i,n) ans[i]=-1;
	REP(i,m){
		int u,v;
		cin>>u>>v;
		u--;v--;
		edge[u].pb(v);
		edge[v].pb(u);
	}
	int q;
	cin>>q;
	for(int i=q-1;i>=0;i--){
		cin>>a[i]>>d[i]>>c[i];
		a[i]--;
	}
	REP(i,q){
		f(a[i],d[i],c[i]);
	}
	REP(i,n) if(ans[i]==-1) ans[i]=0;
	REP(i,n) cout<<ans[i]<<'\n';
	return 0;
	
}


Measured memory_bytes: 18296
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

template<int m>
class Prime{
  std::vector<bool> p;
  std::vector<int> ps;
public:
  Prime(){
    p = std::vector<bool>(m,true);
    assert(m>1);
    p[0]=p[1]=false;
    for(int i=4;i<m;i+=2)
      p[i]=false;
    ps.push_back(2);
    for(int i=3;i<m;i+=2){
      if(p[i]){
        ps.push_back(i);
        for(int j=i+i;j<m;j+=i)
          p[j]=false;
      }
    }
  }

  bool isPrime(int n){
    assert(m>n);
    return p[n];
  }

  int operator [] (int n){
    if(n<ps.size()) return ps[n];
    else return 0;
  }

  int size(){
    return ps.size();
  }
};

int main(){
  Prime<10001000> p;
  int size = p.size();
  vector<int> ans;

  int cnt = 0;
  for(int i=3; i<size; i++){
    if(p[i-2] == p[i-3] + 2 &&
       p[i-1] == p[i-3] + 6 &&
       p[i  ] == p[i-3] + 8)
      ans.push_back(p[i]);
  }

  int n;
  while(n = getInt()){
    vector<int>::iterator it = lower_bound(ans.begin(), ans.end(), n);
    if( *it != n ) it--;
    print(*it);
  }
  return 0;
}

Measured memory_bytes: 3720
#include<iostream>
using namespace std;
#include<bits/stdc++.h>
int main(){
  int n;
  cin>>n;
  if(n<=9){
    cout<<"Yes\n";
    return 0;
  }
  if(n>81){
    cout<<"No\n";
    return 0;
  }
  for(int i=2;i<=sqrt(n);i++){
    if(n%i==0){
      if(n/i<10 and i<10){
        cout<<"Yes\n";
        return 0;
      }
    }
  }
  cout<<"No\n";
  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.regex;

void main() {
	auto input = getStdin!(string[]);
	auto data = input.join.toLower.replaceAll(regex(r"[^a-z]"), "").dup.representation;
	foreach (cp; 97..123) {
		char c = cp.to!char;
		"%c : %d".writefln(c, data.count(c));
	}
}

T getStdin(T)() {
    string[] cmd;
    string line;
    while ((line = chomp(stdin.readln())) != "") cmd ~= line;
    return to!(T)(cmd);
}

Measured memory_bytes: 3184
#include <iostream>

using namespace std;

int main() {
  int K;
  while(cin >> K && K) {
    int cs = 0;
    for(int i=0; i<K*(K-1)/2; i++) {
      int c; cin >> c; cs += c;
    }
    cout << cs/(K-1) << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#include <set>
using namespace std;
#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 (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	while(true){
		C -= B;
		if (C <= 0) {
			print("Yes");
			break;
		}
		A -= D;
		if (A <= 0) {
			print("No");
			break;
		}
	}
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int dp[50][500][500];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,x,y;
	cin>>n>>x>>y;
	vector<int> a(n),b(n),c(n);
	rep(i,n){
		cin>>a[i]>>b[i]>>c[i];
	}
	rep(i,50)rep(j,500)rep(k,500) dp[i][j][k]=INF;
	dp[0][0][0]=0;
	rep(i,n)rep(j,450)rep(k,450){
		if(dp[i][j][k]==INF) continue;
		chmin(dp[i+1][j][k],dp[i][j][k]);
		chmin(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
	}
	int ans=INF;
	FOR(j,1,500)FOR(k,1,500){
		if(j*y==k*x){
			chmin(ans,dp[n][j][k]);
		}
	}
	if(ans!=INF) cout<<ans<<endl;
	else cout<<-1<<endl;
}

Measured memory_bytes: 49152
class Bit:
    """ used for only int(>=0) 
        1-indexed (ignore 0-index)
    """
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length()
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def lower_bound(self, x):
        """ 累積和がx以上になる最小のindexと、その直前までの累積和 """
        sum_ = 0
        pos = 0
        for i in range(self.depth, -1, -1):
            k = pos + (1 << i)
            if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
        return pos + 1, sum_

    def get_less_than_x_cnt(self, x):
        """ 累積和がx未満 の個数 """
        lb_pos, lb_sum = self.lower_bound(x)
        return lb_pos-1

    def get_less_than_and_x_cnt(self, x):
        """ 累積和がx以下 の個数 """
        lb_pos, lb_sum = self.lower_bound(x+1)
        return lb_pos-1
    
    def get_more_than_x_cnt(self, x):
        """ 累積和がxより大きい 個数 """
        return self.size - self.get_less_than_and_x_cnt(x)


def main():
    n = int(input())
    s = list(input())
    q = int(input())
    ql = []
    for _ in range(q): 
        num,a,b = map(str, input().split())
        ql.append((num,a,b))
    alp_d = {chr(ord('a') + i): Bit(n) for i in range(26)}

    for i, si in enumerate(s):
        alp_d[si].add(i+1,1)

    for query in ql:
        a,b,c = query
        if a == '1':
            b = int(b)
            before = s[b-1]
            alp_d[before].add(b, -1)
            alp_d[c].add(b,1)
            s[b-1] = c
        else:
            l,r = int(b),int(c)
            cnt = 0
            for v in alp_d.values():
                if v.sum(r)-v.sum(l-1) > 0:
                    cnt += 1
            print(cnt) 


if __name__ == "__main__":
    main()

Measured memory_bytes: 208576
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef vector<int> vec;
typedef vector<vec> mat;

int main(){
  int n,m,l[3];
  cin >> n >> m >> l[0] >> l[1] >> l[2];
  vector<mat> adj(100, mat(n,vec(n,0)) );

  rep(i,m){
    int s,t;
    cin >> s >> t; s--; t--;
    adj[0][t][s] = 1;
  }

  rep(x,99){
    rep(i,n)rep(j,n)rep(k,n){
      adj[x+1][i][j] |= adj[x][i][k] && adj[0][k][j];
    }
  }

  vector<int> d(n,-1), can(n,0);
  d[n-1] = 0; can[n-1] = 7;
  queue<int> q;
  q.push(n-1);

  while(q.size()){
    int v = q.front(); q.pop();

    rep(x,3){
      rep(u,n){
	if(adj[l[x]-1][v][u]){
	  can[u] |= 1<<x;
	  if(can[u] == 7 && d[u]<0){
	    d[u] = d[v] + 1;
	    q.push(u);
	  }
	}
      }
    }
  }

  if(d[0] < 0){
    cout << "IMPOSSIBLE" << endl;
  }else{
    cout << d[0] << endl;
  }
}

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

int main()
{
  int n;
  long long sum;
  sum = 1;
  long long cnt[1005] = {0};
  cin >> n;
  for (int i = 2; i <= n; i++)
  {
    int x = i;
    for (int k = 2; k <= x; k++)
    {
      while (x > 0 && x % k == 0)
      {
        cnt[k]++;
        x /= k;
      }
    }
  }
  for (int i = 0; i <= n; i++)
  {
    if (cnt[i] != 0)
    {
      sum *= cnt[i] + 1;
      sum %= (int)(1e9 + 7);
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 3584
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,=pin()
    a,b=(N//11,N%11)
    #print(a,b)
    ans=a*2
    if b>0:
        ans+=1
        if b>6:ans+=1
    print(ans)
#%%submit!
resolve()

Measured memory_bytes: 38544
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <queue>
using namespace std;

class Point{
public:
	int x,y,life,c;
	Point(int x = 0,int y = 0,int life = 6,int c = 0):x(x),y(y),life(life),c(c){}
};

int main(void){
	int i,j,k,w,h,a[8][8],f[8][8],ans;
	while(1){
		Point u,v;
		queue<Point> Q;
		cin >> w >> h;
		if(w == 0 && h == 0) break;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				f[i][j] = 0;
				cin >> a[i][j];
				if(a[i][j] == 2){
					u.x = j;
					u.y = i;
					a[i][j] = 1;
				}
			}
		}

		ans = -1;

		Q.push(u);
		while(!Q.empty()){
			u = Q.front();
			Q.pop();
			if(a[u.y][u.x] == 4) u.life = 6;

			int fx[4] = {0,1,0,-1};
			int fy[4] = {1,0,-1,0};
			for(i=0;i<4;i++){
				v = u;
				v.x += fx[i];
				v.y += fy[i];
				v.life--;
				v.c++;
				if(v.x >= 0 && v.x < w && v.y >= 0 && v.y < h && v.life > 0){
					if(a[v.y][v.x] && f[v.y][v.x] < v.life){
						f[v.y][v.x] = v.life;
						Q.push(v);
						if(a[v.y][v.x] == 3){
							ans = v.c;
							break;
						}
					}
				}
			}
			if(ans != -1) break;
		}
		cout << ans << endl;

	}
	return 0;
}

Measured memory_bytes: 0
N=int(input())
red=sorted([list(map(int,input().split())) for i in range(N)], key=lambda x:-1*x[1])
blue=sorted([list(map(int,input().split())) for i in range(N)])
red = sorted(red, key = lambda x:x[1] * -1)
count=0
for i in red:
    for n,j in enumerate(blue):
        if i[0]<j[0] and i[1]<j[1]:
            count+=1
            del blue[n]
            break
print(count)


Measured memory_bytes: 3064
from collections import defaultdict

def bfs(s):
  q = [s]
  while q != []:
    p = q[0]
    del q[0]
    for node in adj[p]:
      if not visited[node]:
        visited[node] = True
        q.append(node)

n,m = map(int,input().split())
adj = defaultdict(list)
visited = [False]*(n+1)
comp = 0
for _ in range(m):
  a,b = map(int,input().split())
  adj[a].append(b)
  adj[b].append(a)
for i in range(1,n+1):
  if not visited[i]:
    comp+=1
    bfs(i)
print(comp-1)

Measured memory_bytes: 32532