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

vector<vector<int> > tree;

const int MAXN = 2100;

bool added[MAXN][MAXN];
bool killed[MAXN][MAXN];

vector<int> stuff[MAXN][MAXN];

int parv[MAXN][MAXN];
int depth[MAXN][MAXN];

vector<int> ord[MAXN];

void dfs(int i, int v, int p, int d){
	ord[i].push_back(v);
	parv[i][v] = p;
	depth[i][v] = d;
	for(int w : tree[v]){
		if(w == p) continue;
		dfs(i, w, v, d+1);
	}
}

int main(){
	int n, m;
	cin >> n >> m;
	tree.resize(n);
	for(int i = 0; i < n-1; i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	for(int i = 0; i < n; i++){
		dfs(i, i, i, 0);
	}
	vector<pair<int,int> > add_edge;
	for(int i = 0; i < m; i++){
		int c, d;
		cin >> c >> d;
		c--; d--;
		add_edge.emplace_back(c, d);
	}
	int s = 0;
	while(s < add_edge.size()){
		int c = add_edge[s].first;
		int d = add_edge[s].second;
		s++;
		if(added[c][d]) continue;
		if(killed[c][d]) continue;
		added[c][d] = added[d][c] = true;
		{
			int x = d;
			while(x != c){
				if(x != d && added[c][x]){
					killed[c][d] = killed[d][c] = true;
					add_edge.emplace_back(x, d);
					break;
				}
				x = parv[c][x];
				if(x != c) stuff[c][x].push_back(d);
			}
			if(killed[c][d]) continue;
		}
		{
			int x = c;
			while(x != d){
				if(x != c && added[d][x]){
					killed[c][d] = killed[d][c] = true;
					add_edge.emplace_back(x, c);
					break;
				}
				x = parv[d][x];
				if(x != d) stuff[d][x].push_back(c);
			}
			if(killed[c][d]) continue;
		}
		for(int x : stuff[c][d]){
			if(killed[c][x]) continue;
			killed[c][x] = killed[x][c] = true;
			add_edge.emplace_back(d, x);
		}
		for(int x : stuff[d][c]){
			if(killed[d][x]) continue;
			killed[d][x] = killed[x][d] = true;
			add_edge.emplace_back(c, x);
		}
	}
	vector<pair<int,int> > good;
	vector<vector<int> > edges(n);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(added[i][j] && !killed[i][j]){
				edges[i].push_back(j);
				edges[j].push_back(i);
			}
		}
	}
	int res = 0;
	for(int s = 0; s < n; s++){
		vector<int> dp(n, 0);
		for(int v : ord[s]){
			if(v == s){
				dp[v] = 1;
			} else {
				for(int w : edges[v]){
					if(dp[w] && depth[v][w] + depth[w][s] == depth[v][s]){
						dp[v] = 1;
					}
				}
			}
		}
		int ans = 0;
		for(int v = 0; v < n; v++){
			if(dp[v] && v != s) ans++;
		}
		res += ans;
	}
	res /= 2;
	cout << res << '\n';
}

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

int main() {
  long long int A,B,C,a,b,c, count  = 0; cin >> A >> B >> C;
  a = A, b = B, c = C;
  if (a==b && b==c) {
    if (a%2 == 0)
      cout << -1 << endl;
    else
      cout << 0 << endl;
  }
  else {
    while (a%2==0 && b%2==0 && c%2==0) {
      A = (b+c)/2, B = (a+c)/2, C = (a+b)/2;
      a = A, b = B, c= C;
      count++;
    }
    cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 256
(* 配列版素集合データ構造 *)
module UnionFind : sig
  type t

  module Class : sig
    type t
    val compare : t -> t -> int
  end

  (* n要素の素集合データ構造を作る *)
  val make : int -> t
  (* 要素がどの集合に属するか調べる *)
  (* 要素は0からn-1の整数である必要がある *)
  val find : t -> int -> Class.t
  (* 与えられた集合同士を合併する *)
  (* 破壊的操作であるため注意 *)
  val unite : t -> Class.t -> Class.t -> unit
  (* 与えられた集合に属する要素の数を求める *)
  val cardinal : t -> Class.t -> int
end = struct
  type t = int array

  module Class = struct
    type t = int
    let compare = compare
  end

  let make n = Array.make n (-1)

  let rec find uf x =
    if uf.(x) < 0 then x
    else begin
      let y = find uf uf.(x) in
      uf.(x) <- y; y
    end

  let unite uf x y =
    if x <> y then begin
      let x, y = if uf.(x) <= uf.(y) then x, y else y, x in
      uf.(x) <- uf.(x) + uf.(y);
      uf.(y) <- x
    end

  let cardinal uf x = ~- (uf.(x))
end

module WeightedGraph
  (Weight : sig
    type t
    val compare : t -> t -> int
  end) :
sig
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  (*
   * HashtblやMapを用いているとプリム法と大差ない計算時間になってしまうため，
   * より汎用的な実装が欲しければそちらを当たること
   *)
  val kruskal :
    (* 頂点の数n *)
    int ->
    (* 辺のリスト *)
    (* 頂点は0からn-1までの整数でなくてはならない
       ソートにList.sortを使っているせいでデータ構造が固定されており，あまり良くない… *)
    (int * int * Weight.t) list ->
    (* 最小全域木に含まれる辺のリスト
       畳み込む関数と初期値まで与えられて初めて計算を開始するので，
       最小全域木に対して色々な操作をしたい場合は，
       一度リストにして覚えておくとよい．
       最小全域木の重さの和だけ欲しいとか一回しか使わない場合は，
       直接畳み込む関数と初期値を与えるとdeforestationになっていい感じ． *)
    (int * int * Weight.t) church_list
end =
struct
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  let kruskal n es =
    { fold = fun f init ->
      let uf = UnionFind.make n in
      List.fold_left (fun acc (u, v, w) ->
        let c = UnionFind.find uf u in
        let d = UnionFind.find uf v in
        if UnionFind.Class.compare c d = 0
        then acc
        else (UnionFind.unite uf c d; f (u, v, w) acc)) init @@
      List.sort (fun (_, _, w) (_, _, w') -> Weight.compare w w') es }
end
 
module Int = struct
  type t = int
  let compare = compare
end
 
module G = WeightedGraph (Int)
 
let () =
  let n = Scanf.scanf "%d\n" @@ fun n -> n in
  let xys = Array.to_list @@ Array.init n @@ fun i ->
    Scanf.scanf "%d %d\n" @@ fun x y -> x, y, i in
  let xedges =
    List.sort (fun (x, _, _) (x', _, _) -> compare x x') xys
    |> (fun ((x, y, i) :: xys) ->
        List.fold_left (fun (acc, x, y, i) (x', y', j) ->
          ((i, j, x' - x) :: acc, x', y', j)) ([], x, y, i) xys)
    |> (fun (acc, _, _, _) -> acc) in
  let xyedges =
    List.sort (fun (_, y, _) (_, y', _) -> compare y y') xys
    |> (fun ((x, y, i) :: xys) ->
        List.fold_left (fun (acc, x, y, i) (x', y', j) ->
          ((i, j, y' - y) :: acc, x', y', j)) (xedges, x, y, i) xys)
    |> (fun (acc, _, _, _) -> acc) in
  Printf.printf "%d\n" @@
  (G.kruskal n xyedges).G.fold (fun (_, _, d) -> ( + ) d) 0


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

int main() {
  int A, B;
  cin >> A >> B;

  int count = 0;

  for (int i = A; i <= B; i++) {
    if (i / 10000 == i % 10 // 5-1
        && i / 1000 % 10 == i / 10 % 10) { // 4-2
      count++;
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 3576
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>

int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  if (a + b == 15) {
    printf("+\n");
  } else if (a * b == 15) {
    printf("*\n");
  } else {
    printf("x\n");
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int ll;
typedef vector<int > vecint;
typedef vector<string > vecstr;
int main()
{
  int n, m;
  cin >> n >> m;
  vecint a(n), b(n), c(m), d(m);
  REP(i,n){
    cin >> a[i] >> b[i];
  }
  REP(i,m){
    cin >> c[i] >> d[i];
  }
  vecint ans(n);
  REP(i,n){
    ans[i] = 0;
    int ind = 0;
    int dist = 1e9;
    REP(j,m){
      int md = abs(c[j] - a[i]) + abs(d[j] - b[i]);
      if(md < dist){
	ind = j;
	dist = md;
      }
    }
    ans[i] = ind;
  }
  REP(i,n){
    cout << ans[i]  + 1<< endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <tuple>
#include <time.h>
#include <set>
using namespace std;
typedef long long ll;


int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> v;
    set<int> s;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        v.emplace_back(b, a);
    }
    sort(v.begin(), v.end());
    for (int i = 1; i <= m; i++) {
        s.insert(i);
    }
    s.insert(31415926);

    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        set<int>::iterator it = s.lower_bound(v[i].second);
        if (*it != 31415926) {
            ans += v[i].first;
            it = s.erase(it);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5748
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define EL '\n'
#define el '\n'
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define repd(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define large 1e18
#define MOD 1000000007
#define pb() push_back()
#define MAX 10e+7
#define FASTIO                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);
void solve()
{
  long long int n, a, b;
  ll m = 1;
  cin >> n;
  long long int arr[n];
  int oc=0;
  rep(i,0,n)
  {
    cin>>arr[i];
    if(arr[i]==0)
    oc=1;
  }
  if(oc>0)
  {
    m=0;
    goto end;
  }
  rep(i, 0, n)
  {
    a=arr[i];
    if (a== 0)
    {
      m = 0;
      goto end;
    }
    ll c = (ll)large / m;
    if (a<= c)
    {
        m=m*a;
    //  cout<<a<<" "<<m<<el;
    
    }
    else
    {
     // cout<<a<<el;
      //cout<<m<<el;
      m=-1;
      goto end;
    }
  }
end:
//cout<<large<<el;
  cout << m;
}
int main()
{
 
  solve();
  return 0;
}


Measured memory_bytes: 4428
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#define MOD 1000000007
typedef long long ll;

using namespace std;

struct xyz {
    int num;
    int index;
};

int main() {
    int n;
    cin >> n;
    
    vector<xyz> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i].num;
        v[i].index = i + 1;
    }
    
    sort(v.begin(), v.end(), [](const xyz &a, const xyz &b){return a.num < b.num;});
    
    for(int i = 0; i < n; i++) {
        if(i == n - 1) {
            cout << v[i].index  << endl;
        }
        else {
            cout << v[i].index  << " ";
        }
    }
    
    return 0;
}



Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){
  int a,b;
  cin >> a >> b;
  a+=b;
  if(a>=24){a-=24;}
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 100005
#define INF 1000000005LL
#define MOD 1000000007

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

int n;
ll A[SIZE],B[SIZE],C[SIZE];
ll ans;

int main(){
  cin >> n;
  rep(i,0,n) cin >> A[i];
  rep(i,0,n) cin >> B[i];
  rep(i,0,n) cin >> C[i];
  sort(A,A+n);
  sort(B,B+n);
  sort(C,C+n);

  rep(i,0,n){
    int p = (upper_bound(C,C+n,B[i]) - C);
    int q = (lower_bound(A,A+n,B[i]) - A);
    ans += (ll)(n-p)*(ll)q;
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }


template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "{";
    for (int i = 0; i < v.size(); ++i) {
        if(i) os << ", ";
        os << v[i];
    }
    return os << "}";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "{" << p.first << ", " << p.second << "}";
}


void solve(int w){
    int s, g, h;
    cin >> s >> g >> h;
    auto v = make_v(h, vector<int>(w, 0));
    s--; g--;
    for (int i = 0; i < h; ++i) {
        string S;
        cin >> S;
        for (int j = 0; j < w-1; ++j) {
            v[i][j] = S[j] == '1';
        }
    }
    auto ok = [&](){
        vector<int> ok(w);
        ok[s] = 1;
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w-1; ++j) {
                if(v[i][j]) swap(ok[j], ok[j+1]);
            }
        }
        return ok[g];
    };
    if(ok()) {
        puts("0");
        return;
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w-1; ++j) {
            if(!v[i][j] && (!j || !v[i][j-1]) && (j == w-1 || !v[i][j+1])){
                v[i][j] = 1;
                if(ok()){
                    printf("%d %d\n", i+1, j+1);
                    return;
                }
                v[i][j] = 0;
            }
        }
    }
    puts("1");
}

int main() {
    int n;
    while(cin >> n, n){
        solve(n);
    }
    return 0;
}


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

int main(){
 
	int a,b,c,t;
	cin>>a>>b;
	int mn=min(a,b);
	int mx=a+b-mn;
	for(int i=0;i<mx;i++)
		printf("%d",mn);


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}

int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  int N;
  cin>>N;
  vector<pair<int,int>> data(N);
  rep(i,0,N) cin>>data[i].second>>data[i].first;
  asort(data);
  int temp=0;
  int check=0;
  rep(i,0,N){
    temp+=data[i].second;
    if(temp>data[i].first){
      check++;
      break;
    }
  }
  cout<<(check?"No":"Yes");
  
 
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//cout<<fixed<<setprecision(n);  //小数点n桁まで表示


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>

int main(void){
	
	std::string s;

	std::cin >> s;
	
	int ans = 0;

	for (size_t i = 0; i < s.length(); i++) {
		if (s[i] == '+') {
			ans++;
		}
		else {
			ans--;
		}
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    N, A, B, C = map(int, readline().split())
    s = read().decode().split()
    s.append('AB')
    ans = []
    for i in range(N):
        if s[i] == 'AB':
            if A == 0 and B == 0:
                print('No')
                break
            else:
                if A < B:
                    A += 1
                    B -= 1
                    ans.append('A')
                elif A > B:
                    A -= 1
                    B += 1
                    ans.append('B')
                else:
                    if s[i+1] == 'AB' or s[i+1] == 'AC':
                        A += 1
                        B -= 1
                        ans.append('A')
                    else:
                        A -= 1
                        B += 1
                        ans.append('B')
        if s[i] == 'AC':
            if A == 0 and C == 0:
                print('No')
                break
            else:
                if A < C:
                    A += 1
                    C -= 1
                    ans.append('A')
                elif A > C:
                    A -= 1
                    C += 1
                    ans.append('C')
                else:
                    if s[i + 1] == 'AB' or s[i + 1] == 'AC':
                        A += 1
                        C -= 1
                        ans.append('A')
                    else:
                        A -= 1
                        C += 1
                        ans.append('C')
        if s[i] == 'BC':
            if C == 0 and B == 0:
                print('No')
                break
            else:
                if C < B:
                    C += 1
                    B -= 1
                    ans.append('C')
                elif C > B:
                    C -= 1
                    B += 1
                    ans.append('B')
                else:
                    if s[i + 1] == 'AB' or s[i + 1] == 'BC':
                        B += 1
                        C -= 1
                        ans.append('B')
                    else:
                        B -= 1
                        C += 1
                        ans.append('C')
    else:
        print('Yes')
        print('\n'.join(ans))
    return

if __name__ == '__main__':
    main()


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

int main(){


    while(1){
        
        long long b; cin >> b;
        if(!b) break;

        int ans_a;
        int ans_r;
        for(long long r = 3 * sqrt(b); r > 0; r--){
            //cout << r << endl;
            if((2 * b - r * (r - 1)) % (2 * r) == 0 && (2 * b - r * (r - 1)) / (2 * r) >= 1){
                ans_r = r;
                ans_a = (2 * b - r * (r - 1)) / (2 * r);
                break;
            }
        }

        cout << ans_a << " " << ans_r << endl;
    }

    return 0;
}


Measured memory_bytes: 3080
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a,b,c,sum=0;
	cin>>a>>b>>c;
	if(a>=b&&a>=c)sum=b+c;
	if(b>=a&&b>=c)sum=a+c;
	if(c>=b&&c>=a)sum=b+a;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  string s;
  cin >> s;
  int a = 0, b = 0;
  for (auto itr : s) {
    if (itr == '1') a++;
    else b++;
  }

  cout << s.size() - abs(a - b) << endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

const long long MOD = 1000000007;

int main(){
  int a,b;
  cin >> a >> b;
  int k=max(a,b)-min(a,b)-1;
  if(k%2==0) cout << "IMPOSSIBLE" << endl;
  else{
    k= (k+1)/2 + min(a,b);
    cout << k << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	static int N;
	static int M;
	static int a[];
	static int b[];
	static long c[];
	static long v[];
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		a = new int[M];
		b = new int[M];
		c = new long[M];
		v = new long[N];
		Arrays.fill(v, Long.MAX_VALUE / 4 * 3);
		v[0] = 0;
		for(int i = 0; i < M; i++) {
			a[i] = sc.nextInt() - 1;
			b[i] = sc.nextInt() - 1;
			c[i] = sc.nextLong() * -1;
		}
		if(Bellmanford()) {
			System.out.println(-1 * v[N - 1]);
		} else {
			System.out.println("inf");
		}
	}
	
	public static boolean Bellmanford() {
		long pre = 0;
		for(int k = 0; k <= 2 * N; k++) {
			boolean flag = false;
			for(int i = 0; i < M; i++) {
				if(v[a[i]] + c[i] < v[b[i]]) {
					if(k == N - 2) {
						pre = v[N - 1];
					}
					if(k == 2 * N && v[N - 1] < pre) {
						return false;
					} else if(k == 2 * N){
						return true;
					}
					flag = true;
					v[b[i]] = v[a[i]] + c[i];
				}
			}
			if(!flag) {
				break;
			}
		}
		return true;
	}
}


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

class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		input = Console.ReadLine().Split(' ');
		int[] a = new int[n];
		for(int i=0; i<n; i++) a[i] = int.Parse(input[i]);
		Array.Sort(a);

		bool[] arr = new bool[1000001];
		for(int i=0; i<1000001; i++) arr[i] = true;
		HashSet<int> canDiv = new HashSet<int>();
		HashSet<int> ngDiv = new HashSet<int>();
		int pre = 0;
		int preAdded = 0;
		for(int i=0; i<n; i++)
		{
			if(pre == a[i])
			{
				if(preAdded == pre) ngDiv.Add(a[i]);
				continue;
			}
			pre = a[i];
			if(arr[a[i]])
			{
				canDiv.Add(a[i]);
				preAdded = a[i];
				for(int j = a[i] * 2; j <= a[n-1]; j += a[i])
				{
					arr[j] = false;
				}
			}
		}
		Console.WriteLine(canDiv.Count - ngDiv.Count);
	}
}




Measured memory_bytes: 51460
class DisjointSet:
    def __init__(self, size):
        self.parent = list(range(size))
        self.rank = [0]*size
    
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def union(self, x, y):
        xr, yr = self.find(x), self.find(y)
        
        if self.rank[xr] > self.rank[yr]:
            self.parent[yr] = xr
        elif self.rank[xr] < self.rank[yr]:
            self.parent[xr] = yr
        elif xr != yr:
            self.parent[yr] = xr
            self.rank[xr] += 1

from collections import Counter

N,M,K = map(int,input().split())

ds = DisjointSet(N)
deg = [0]*N
for _ in range(M):
    a,b = map(int,input().split())
    deg[a-1] += 1
    deg[b-1] += 1
    ds.union(a-1,b-1)

c = Counter(ds.find(i) for i in range(N))

res = [c[ds.find(i)]-deg[i]-1 for i in range(N)]
for _ in range(K):
    c,d = map(int,input().split())
    if ds.find(c-1) == ds.find(d-1):
        res[c-1] -= 1
        res[d-1] -= 1

print(*res)

Measured memory_bytes: 93656
S = list(input())
T = input()

#print(S)
#print(T)
for i in range(len(S)):
    check_str = "".join(S[i:len(S)] + S[0:i])
    #print(check_str)
    if check_str == T:
        print("Yes")
        exit()

print("No")


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
using namespace std;
int A[5001],B[5001];
int main(){
    int a,b;
    cin>>a>>b;
    for(int i=0; i<a; i++) cin>>A[i];
    for(int i=0; i<b; i++) cin>>B[i];
    int next=0,maxl=0;
    for(int i=0; i<b; i++){
        next=i;
        int cnt=0;
        for(int j=0; j<a; j++) if(A[j]==B[next]) {cnt++; next++;}
        maxl=max(maxl,cnt);
    }
    cout<<maxl<<endl;
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define G if(++ip==ie)if(fread(ip=buf,1,SZ,stdin))
using namespace std;
const int SZ=1<<19,N=1e5+9,M=2*N;
char buf[SZ],*ie=buf+SZ,*ip=ie-1;
inline int in(){
    G;while(*ip<'-')G;
    int x=*ip&15;G;
    while(*ip>'-'){x*=10;x+=*ip&15;G;}
    return x;
}
int he[N],ne[M],to[M],f[N],a[N],b[N];
int Getf(int x){
    return x==f[x]?x:f[x]=Getf(f[x]);
}
void Dfs(int x,int op){
    a[x]=op;
    for(int y,i=he[x];i;i=ne[i])
        if((y=to[i])!=f[x])
            f[y]=x,Dfs(y,-op),a[x]+=a[y];
}
int main(){
    int n=in(),m=in(),rt=1,re=1,p=0,ans=0;
    for(int i=1;i<=n;++i)f[i]=i;
    for(int p=0,i=1;i<=m;++i){
        int x=in(),y=in();
        if(Getf(x)!=Getf(y))f[f[x]]=f[y];
        else{rt=x,re=y;continue;}
        ne[++p]=he[x];to[he[x]=p]=y;
        ne[++p]=he[y];to[he[y]=p]=x;
    }
    f[rt]=0;Dfs(rt,1);
    if(n==m)
    {

    p=0;
        for(int i=re;i;i=f[i]) b[++p]=a[i];
        if(p%2)
        {
            if(a[rt]%2)return puts("-1"),0;
            for(int i=re;i;i=f[i])a[i]-=a[rt]/2;
        }
        else
        {
            if(a[rt])return puts("-1"),0;
            sort(b+1,b+p+1);
            for(int i=re;i;i=f[i])a[i]-=b[p/2];
        }
    }
    else if(a[rt])return puts("-1"),0;
    for(int i=1;i<=n;++i)ans+=abs(a[i]);
    return cout<<ans,0;
}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int n;
    cin >> n;
    bool divs[1000005];
    map<int, int> m;
    vi a(n);
    memset(divs, true, sizeof(divs));
    fo(i, n) {
        cin >> a[i];
        if ( ++m[a[i]] > 1 ) continue;
        for ( int j = a[i] * 2; j < 1000005; j += a[i] ) {
            divs[j] = false;
        }
    }

    int ans = 0;
    fo(i, n) if ( divs[a[i]] and m[a[i]] == 1 ) {
        // cout << a[i] << endl;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 14276
using System;
class Program
 {
   	static void Main(string[] args)
        {
    　　	string a = Console.ReadLine(); //標準入力
		string aa = Console.ReadLine(); //標準入力
		string[] pp = aa.Split(' ');

	       	int N = int.Parse(a);

		int max = 0;
		int[] P = new int[N];
		for(int i = 0; i< N; i++){
      			P[i]= int.Parse(pp[i]);
          		int num = P[i];
        		if(max < num ){
                  max = num;
                }
      		}
      int min = max;
      int count = 0;
      for(int i = 0; i< N; i++){
      			int num = P[i];
        		if(min > num ){
                  min = num;
                }
        if(num <= min){
          count++;
        }
      		}
      
     		Console.WriteLine("{0}", count);
        }
 
 }

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

int main() {
    long long N, M; cin >> N >> M;
    vector<pair<long long, long long>> p(N);
    for(int i = 0; i < N; i++) {
        int A, B; cin >> A >> B;
        p[i] = make_pair(A, B);
    }
    sort(p.begin(), p.end());

    long long remainM = M;
    long long  ret = 0;
    for(int i = 0; i < N; i++) {
        if(remainM != 0) {
            ret += p[i].first * min(remainM, p[i].second);
            remainM -= min(remainM, p[i].second);
        } 
    }
    cout << ret << endl;
}


Measured memory_bytes: 1792
let _ =
  Scanf.scanf "%d" @@ fun n ->
  let p = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  let c = Array.make (n+1) 0 in
  Array.fold_left (fun s x ->
    c.(x) <- c.(x-1) + 1;
    min s (n - c.(x))
  ) n p
  |> Printf.printf "%d\n"

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

int DP[2][101][11000];

signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);
    int n, c;
    cin >> n >> c;
    vector<int> A(n), B(n), C(n);
    for (int i = 0; i < n; i++){
        cin >> A[i] >> B[i] >> C[i];
    }

    const int INF = 1e9;
    for (int j = 0; j <= c; j++){
        for (int k = 0; k <= 10000; k++){
            DP[0][j][k] = -INF;
        }
    }

    DP[0][c][0] = 0;

    for (int i = 0; i < n; i++){
        for (int j = 0; j <= c; j++){
        for (int k = 0; k <= 10000; k++){
            DP[(i + 1) & 1][j][k] = -INF;
        }}
        DP[(i + 1) & 1][c][0] = 0;
        for (int j = 0; j <= c; j++){
            for (int k = 0; k <= 10000; k++){
                DP[(i + 1) & 1][j][k] = DP[i & 1][j][k];
                if (j - C[i] >= 0){
                    DP[(i + 1) & 1][j - C[i]][k + A[i]] = max(DP[(i + 1) & 1][j - C[i]][k + A[i]], DP[i & 1][j][k] + B[i]);
                    DP[(i + 1) & 1][j - C[i]][k + B[i]] = max(DP[(i + 1) & 1][j - C[i]][k + B[i]], DP[i & 1][j][k] + A[i]);
                }
            }
        }
    }


    int ans = 0;
    for (int i = 0; i <= c; i++){
        for (int j = 0; j <= 10000; j++){
            if (j <= DP[n & 1][i][j])
                ans = max(ans, j);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 11836
def main():
    x1, y1, x2, y2 = map(int, input().split())
    x3 = x2 - (y2 - y1)
    y3 = y2 + (x2 - x1)
    x4 = x3 - (y3 - y2)
    y4 = y3 + (x3 - x2)

    print(x3, y3, x4, y4)

if __name__=='__main__':
    main()



Measured memory_bytes: 2940
#include <cstdio>
using namespace std;

#define SIZE 10


int main() {
	int l[SIZE] = { 0 }, v1, v2;
	double s;
	char t;
	while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v1,&v2) != EOF) {
		s = 0;
		for (int i = 0; i < SIZE; i++) {
			s += l[i];
		}
		s = s * v1 / (v1 + v2);

		for (int i = 0; i < 10; i++) {
			s -= l[i];
			if (s <= 0) {
				printf("%d\n", i + 1);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2676
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	char s[100],t[100];
	scanf("%s %s",s,t);
	char u[100];
	int i,j;
	scanf("%d%d",&i,&j);
	scanf("\n%s",u);
//	printf("\n%s\n%s\n",s,t);
	
	if(strcmp(s,u)==0)
	{
		printf("%d %d",i-1,j);
	}
	else if(strcmp(t,u)==0)
	{
		printf("%d %d",i,j-1);
	}
}

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

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

Measured memory_bytes: 1160
#include<stdio.h>
#include<string.h>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int a[100005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    int cunt=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==i)
        {
            swap(a[i],a[i+1]);
            cunt++;
        }
    }
    printf("%d\n",cunt);
	return 0;
 }



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

#define ll long long

using namespace std;

int k,n,a[200005];
ll mn = 1000000009;

int main () {

    cin >> k >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        //left
        ll ans = 0;
        ans += (a[i] - a[1]);
        if (i != n) {
            ans += (a[1] - 0);
            ans += (k - a[n]);
            ans += (a[n] - a[i + 1]);
        }
        if (ans < mn) mn = ans;
    }

    for (int i = 1; i <= n; i++) {
        //right
        ll ans = 0;
        ans += (a[n] - a[i]);
        if (i != 1) {
            ans += (k - a[n]);
            ans += (a[1] - 0);
            ans += (a[i - 1] - a[1]);
        }
        if (ans < mn) mn = ans;
    }

    cout << mn;

    return 0;
}


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

int main() {
    double n,x[4],y[4],judge1,judge2;
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<4;j++) cin>>x[j]>>y[j];
        judge1=(y[1]-y[0])/(x[1]-x[0]);
        judge2=(y[3]-y[2])/(x[3]-x[2]);
        if(judge1==judge2)cout << "YES";
        else cout << "NO";
        cout << endl;
    }
}

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

int main(void)
{
    vector<vector<char>> c(3, vector<char>(3));
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> c[i][j];
        }
    }
    printf("%c%c%c\n", c[0][0], c[1][1], c[2][2]);
    return (0);
}

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

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  ll ans = 0;
  for (int i = 0; i < 60; ++i) {
    // how many 1s in a[i];
    ll x = 0;
    for (int j = 0; j < n; ++j) {
      if (a[j] >> i & 1) x++;
    }
    ll y = x * (n - x) % MOD;
    for (int j = 0; j < i; ++j) y = y * 2 % MOD;
    ans += y;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int r = 0;
        int w = 0;
        for(char c : s){
            if(c == 'R'){
                r++;
            }
        }
        int ans = 0;
        for(int i = 0; i < r; i++){
            if(s[i] != 'R'){
                ans++;
            }
        }
        pw.println(ans);
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
 
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 29944
N, A, B, C = map(int, input().split())
ss = [input() for _ in range(N)]

history = []

def move_to_flatten(s):
    global A, B, C, history
    if s == "AB":
        if A >= B:
            A -= 1
            B += 1
            history.append("B")
        else:
            B -= 1
            A += 1
            history.append("A")
    elif s == "BC":
        if B >= C:
            B -= 1
            C += 1
            history.append("C")
        else:
            C -= 1
            B += 1
            history.append("B")
    elif s == "AC":
        if A >= C:
            A -= 1
            C += 1
            history.append("C")
        else:
            C -= 1
            A += 1
            history.append("A")
        

for i, s in enumerate(ss):
    zeros = (A, B, C).count(0)
    if zeros == 0:
        move_to_flatten(s)
    elif zeros == 1:
        if A + B + C == 2:
            if A == 0:
                if s == "BC":
                    if i+1 < N and 'B' in ss[i+1]: 
                        C -= 1
                        B += 1
                        history.append('B')
                    else:
                        B -= 1
                        C += 1
                        history.append('C')
                else:
                    move_to_flatten(s)
            elif B == 0:
                if s == "AC":
                    if i+1 < N and 'C' in ss[i+1]:
                        A -= 1
                        C += 1
                        history.append('C')
                    else:
                        C -= 1
                        A += 1
                        history.append('A')
                else:
                    move_to_flatten(s)
            elif C == 0:
                if s == "AB":
                    if i+1 < N and 'A' in ss[i+1]:
                        B -= 1
                        A += 1
                        history.append('A')
                    else:
                        A -= 1
                        B += 1
                        history.append('B')
                else:
                    move_to_flatten(s)    
        else:
            move_to_flatten(s)
    elif zeros == 2:
        if A != 0 and s == "BC":
            print("No")
            exit()
        elif B != 0 and s == "AC":
            print("No")
            exit()
        elif C != 0 and s == "AB":
            print("No")
            exit()
        move_to_flatten(s)
    else:
        print("No")
        exit()

print("Yes")
print(*history, sep = '\n')

Measured memory_bytes: 18556
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
        // setw(6) << setfill('0')
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << "(" << v.first << ", " << v.second << ")";
    return ostr;
}

vector<string> split(const string &s, char delim) {
    vector<string> result;
    stringstream ss(s);
    string item;
    while (getline(ss, item, delim)) {
    if (!item.empty()) {
            result.push_back(item);
        }
    }
    return result;
}

int64 powmod(int64 n, int64 count, int64 mod) {
    if (count == 0) return 1;
    if (count % 2 == 0) {
        int64 t = powmod(n, count / 2, mod);
        return t * t % mod;
    }
    return n * powmod(n, count - 1, mod) % mod;
}

int64 ncr(int64 n, int64 r, int64 mod) {
    int64 a;
    if (n < r) a = min(n, r - n);
    else a = min(n - r, r);

    int64 res = 1;
    rep(i, a) {
        res = res * (n - i) % mod;
        res = res * powmod(i + 1, mod - 2, mod) % mod;
    }

    return res;
}

vector<int64> ans;
void f(int64 n) {
    string s = to_string(n);
    if (s.size() == 1) {
        ans.push_back(n);
        f(n * 10);
    } else if (s.size() == 12) {
        return;
    } else {
        int p = s[s.size()-2] - '0';
        rep(i, 10) {
            if (abs(p - i) <= 1) {
                int64 tmp = n;
                tmp = (tmp / 10) * 10 + i;
                ans.push_back(tmp);
                f(tmp * 10);
            }
        }
    }
}

int main() {
    int n; cin >> n;
    reps(1, c, 10) {
        f(c);
    }

    sort(all(ans));
    cout << ans[n-1] << endl;
}


Measured memory_bytes: 11672
#include<bits/stdc++.h>
using namespace std;
int  main()
{
    int n,c=0,i;
    cin>>n;
    for(i=1;i<10;i++){
        if(n%i==0&&n/i<10)
            c++;
    }
    if(c>0){
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
    return 0;
}


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

int cnt;
string s;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> s;
    for (int i = 0; i < s.size(); i++) if (s[i] == 'p') cnt--;
    cnt += s.size() / 2;
    cout << cnt;
}


Measured memory_bytes: 512
// BWOTSHEWCHB

#include <bits/stdc++.h>

using namespace std ;

#define int long long
#define pb push_back
#define in insert
#define X first
#define Y second

const int MAXN = 1e6 + 69 , MOD = 1e9 + 7 ;

int n ;
vector <pair <int , int>> vect ;
map <pair <int , int> , int> mp ;

int32_t main() {
	ios::sync_with_stdio(false) ;
	cin.tie(0) ; cout.tie(0) ;
	cin >> n ;
	for ( int i = 1 ; i <= n / 2 ; i ++ )
		mp[make_pair(i , n - i + (n % 2 == 0))] = mp[make_pair(n - i + (n % 2 == 0) , i)] = 1 ;
	for ( int i = 1 ; i <= n ; i ++ )
		for ( int j = i + 1 ; j <= n ; j ++ )
			if ( !mp[make_pair(i , j)] )
				vect.pb({i , j}) ;
	cout << vect.size() << "\n" ;
	for ( auto it : vect )
		cout << it.X << " " << it.Y << "\n" ;
}


Measured memory_bytes: 640
N, M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB = sorted(AB, key=lambda x: x[0])

ans = 0
s = 0
for i in range(N):
    t = AB[i][1]
    c = min(M-s, t)
    ans += c*AB[i][0]
    s += c
    if s>=M: break

print(ans)

Measured memory_bytes: 29796
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define rep(i, n) for (int i = 0; i < n; i = i + 1)
#define MAX 10010
#define MAX_INT 9223372036854775807
#define array(N, t) (t*)calloc(N, sizeof(t))

int main() {
  int N, D;

  scanf("%d%d", &N, &D);

  /* int hoge = -56855; */
  /* printf("\n"); */
  /* printf("hoge: %fd\n", pow(hoge, 2)); */

  int ans = 0;
  rep(i, N) {
    int X, Y;
    int input_X, input_Y;
    scanf("%d%d", &input_X, &input_Y);

    X = abs(input_X);
    Y = abs(input_Y);

    /* printf("\n"); */
    /* printf("abs(X): %d\n", abs(X)); */
    /* printf("abs(Y): %d\n", abs(Y)); */

    /* printf("D: %d\n", D); */

    if (D < X) {
      //      printf("larger\n");
      continue;
    }
    if (D < Y) {
      //      printf("larger\n");
      continue;
    }

    /* if ((int)(D / X) > X) { */
    /*   continue; */
    /* } */

    /* if ((int)(D / Y) > Y) { */
    /*   continue; */
    /* } */

    long long int pow_X = pow(X, 2);
    long long int pow_Y = pow(Y, 2);

    /* printf("\n"); */

    /* printf("X: %d\n", X); */
    /* printf("pow_X: %lld\n", pow_X); */
    /* printf("Y: %d\n", Y); */
    /* printf("pow_Y: %lld\n", pow_Y); */

    long long int pow_X_plus_pow_Y = pow_X + pow_Y;

    /* printf("pow_X_plus_pow_Y: %d\n", pow_X_plus_pow_Y); */

    long double tmp_distance = sqrt(pow_X_plus_pow_Y);

    /* printf("tmp_distance: %fd\n", tmp_distance); */

    long long int distance = (long long int)ceil(tmp_distance);

    /* printf("distance: %d\n", distance); */

    if (D >= distance) {
      ans += 1;
    }
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 2208
#!/usr/bin/env python3
from collections import Counter
import sys
sys.setrecursionlimit(10**6)


n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

c = Counter(a)

c = list(c.most_common())
# c = c.most_common()
len_c = len(c)
# print(len_c)
# print(c)
ans = 0
while(len_c-k > 0):
    # print(len_c-k)
    # print()
    # print(k)
    i, j = c.pop()
    len_c -= 1
    ans += j
print(ans)


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

using namespace std;

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

int main(){

  long long int n;
  cin>>n;
  long long int MOD =1000000007;
  long long int ans;
  long long int ans1=1;
  long long int ans2=1;
  long long int ans3=1;
  long long int possible=1;
  possible = (n*(n-1))%MOD;

  //if(n>2){
  //  for(int i=0; i<n-2; i++){
  //    ans1=(ans1*10)%MOD;
  //  }
  //  cout<<ans1*possible%MOD<<endl;
  //}else cout<<possible<<endl;
  //
  for(int i=0; i<n; i++){
    ans1=(ans1*10)%MOD;
    ans2=(ans2*8)%MOD;
    ans3=(ans3*9)%MOD;
  }

  ans3=ans3*2%MOD;

  ans=mod(((ans1+ans2)%MOD)-ans3, MOD);

  cout<<ans<<endl;
}


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

using namespace std;

#define REP(var, n)  for (int var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<int>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pii;

#define all(c) begin(c),end(c)

#define D(x) do { std::cerr << x << " "; } while (0)
#define D2(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)


template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


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

int MOD = (int) 1e9 + 7;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

void solve() {
    ll a, b;
    cin >> a >> b;
    ll d = gcd(a, b);
    cout << (a * b / d) << endl;
}


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

//    cout << solve() << endl;
    solve();
//    cout << (solve() ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define f first  
#define s second
#define rep(i,a,b)  for(ll i=a;i<b;i++)

int main() 
{
    ll a,b,c,k,sum=0;
    cin>>a>>b>>c>>k;
    if(a>=k)
    {
        cout<<k;
    }
    else
    {
        sum+=a;
        a=a+b;
        if(a>=k)
        {
            cout<<sum;
        }
        else
        {
            sum=sum-(k-a);
            cout<<sum;
        }
    }
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
    ll N,M,sum=0;
    cin>>N>>M;
    pq<ll> p;
    for(ll i=0;i<N;i++){
        ll a;
        cin>>a;
        p.push(a);
    }
    for(ll i=0;i<M;i++){
        ll a;
        a=p.top();
        p.pop();
        a/=2;
        p.push(a);
    }
    for(ll i=0;i<N;i++){
        sum+=p.top();
        p.pop();
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 1400
a,b,c,x,y = map(int,input().split())
ans = x*a+y*b

if x < y:
    res = x*c*2+(y-x)*b
    ans = min(res,ans)
else:
    res = y*c*2+(x-y)*a
    ans = min(res,ans)
ans = min(ans,c*max(x,y)*2)
print(ans)

Measured memory_bytes: 3064
num = {
    1:{1:[0]*10,2:[0]*10,3:[0]*10},
    2:{1:[0]*10,2:[0]*10,3:[0]*10},
    3:{1:[0]*10,2:[0]*10,3:[0]*10},
    4:{1:[0]*10,2:[0]*10,3:[0]*10}
}

n = int(input())
for _ in range(n):
    b, f, r, v = map(int, input().split())
    num[b][f][r-1] += v
for b in num:
    for f in num[b]:
        for r in num[b][f]:
            print(' '+str(r), end='')
        print()
    if b==4: break
    print('#'*20)



Measured memory_bytes: 5620