akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdlib>

#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 

using namespace std;

# define p(s) cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)

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

    long long int res=k;
    for(int i=1 ; i < n ; i++){
        res *= (k-1);
   }
   p(res)
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define fi first
#define se second
#define sz(a) ((int)a.size())
#define pb push_back
const int inf_int = 2e9+200;
const int MAXN = 1e5+100;
const int MOD = 1e9+7;

int a[MAXN],b[MAXN];
int val[MAXN];
vector<int> g[MAXN];
bool used[MAXN];
vector<int> com;
void dfs(int v){
    used[v] = 1;
    com.pb(val[v]);
    for(int to:g[v]){
        if(!used[to])
            dfs(to);
    }
}

void bad(){
    cout << "Impossible"<<endl;
    exit(0);
}

void solve(){
    int n;
    cin >> n;
    int m;
    cin >> m;
    for(int i=1;i<=n;++i){
        cin >> val[i];
    }
    for(int i=1;i<=m;++i){
        int a,b;
        cin >> a >> b;
        a++;
        b++;
        g[a].pb(b);
        g[b].pb(a);
    }
    vector<vector<int> > comps;
    for(int i=1;i<=n;++i){
        if(!used[i]){
            com.clear();
            dfs(i);
            sort(com.begin(),com.end());
            comps.pb(com);

        }
    }

    set<pii> ss;
    int z = 0;
    int edges = 0;
    ll ans = 0;
    for(int i=0;i<sz(comps);++i){
        if(i==0){
            for(int v:comps[i]){
                ss.insert({v,z++});
            }
        } else{
            int val1 = inf_int; //add edge
            int val2 = inf_int; // break one edge

            if(ss.size()>0){
                val1 = ss.begin()->fi + comps[i][0];
            }
            if(edges>0 && sz(comps[i])>1){
                val2 = comps[i][0] + comps[i][1];
            }
            int cur = min(val1,val2);
            if(cur==inf_int)
                bad();
            else if(cur==val1){
                ss.erase(ss.begin());
                for(int e=1;e<sz(comps[i]);++e){
                    ss.insert({comps[i][e],z++});
                }
            } else {
                for(int e=2;e<sz(comps[i]);++e){
                    ss.insert({comps[i][e],z++});
                }
            }
            edges++;
            ans+=cur;
        }
    }
    cout << ans;
}

int main(){
    #ifdef tw
        freopen("input.txt","r",stdin);
    #endif // zxc


    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    while(t--)
        solve();
}


Measured memory_bytes: 11768
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


signed main() {
	ios::sync_with_stdio(false);
	int n, k;
	int ans = 0;
	cin >> n >> k;
	int i;
	vector<int> l(55);
	rep(i, n) cin >> l[i];
	sort(l.begin(),l.end(),greater<int>());
	rep(i, k) {
		ans += l[i];
	}
	cout << ans << '\n';
	return 0;
}

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, h, w;
	cin >> n >> h >> w;
	
	cout << (n - h + 1) * (n - w + 1) << endl;
	
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> x(m);
    bool flag = false;
    if(n > m) flag = true;
    for(int i = 0; i < m; i++){
        cin >> x[i];
    }    
    sort(x.begin(),x.end());
    vector<pair<int,int>> spa;
    for(int i = 0; i < m-1; i++){
        spa.push_back({x[i+1]-x[i],i+1});
    }
    sort(spa.begin(),spa.end(),greater<pair<int,int>>());
    vector<int> koma;
    koma.push_back(0);
    for(int i = 0; i < min(n-1,m-1); i++){
        koma.push_back(spa[i].second);
    }
    int now = koma[0];
    int sum = 0;
    for(int i = 1; i < koma.size(); i++){
        sum += x[koma[i]-1]-x[now];
        now = koma[i];
    }
    sum += x[x.size()-1]-x[now];
    if(flag) cout << 0 << endl;
    else cout << sum << endl;
}

Measured memory_bytes: 2292
n, m = gets.split.map(&:to_i)
heights = gets.split.map(&:to_i)
roads = []
m.times do
  roads << gets.split.map(&:to_i)
end

graph = (1..n).each_with_object({}) { |peak, result| result[peak] = [] }

roads.each_with_object(graph) do |road, result|
  result[road[0]] << road[1]
  result[road[1]] << road[0]
end

good_peaks = graph.select { |from, neighborhoods|
  neighborhoods.empty? ||
    heights[from - 1] > neighborhoods.map { |neighborhood| heights[neighborhood - 1] }.max
}

puts good_peaks.size


Measured memory_bytes: 38472
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

const int INF = 1000000000;

struct edge{int to,cost;};

typedef pair<int,int> P;

vector<edge> G[100000];
priority_queue<P,vector<P>,greater<P> > q;

int V,E,r;
int d[100000];

int main(){
  scanf("%d %d %d",&V,&E,&r);
  for(int i=0;i<E;i++){
    int s;
    edge e;
    scanf("%d %d %d",&s,&e.to,&e.cost);
    G[s].push_back(e);
  }
  fill(d,d+V,INF);
  d[r] = 0;
  q.push(P(0,r));
  while(!q.empty()){
    P p = q.top();
    q.pop();
    if(d[p.second]<p.first) continue;
    int v = p.second;
    for(int i=0;i<G[v].size();i++){
      if(d[G[v][i].to]>d[v]+G[v][i].cost){
        d[G[v][i].to] = p.first+G[v][i].cost;
        q.push(P(d[G[v][i].to],G[v][i].to));
      }
    }
  }
  for(int i=0;i<V;i++){
    if(d[i]==INF) printf("INF\n");
    else printf("%d\n",d[i]);
  }
  return 0;
}

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


using namespace std;
constexpr long long int mod = 1000000007,MOD= 998244353,MAX=200000;

int main() {
    int K;
    string S;
    cin >> K >> S;
    if (S.size() > K)cout << S.substr(0, K) + "...";
    else cout << S;
}

Measured memory_bytes: 3636
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize, m: usize
    };

    let nc = if n >= 2 { n * (n - 1) / 2 } else { 0 };
    let mc = if m >= 2 { m * (m - 1) / 2 } else { 0 };
    let res = nc + mc;
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2272
import sys

# sys.stdin = open('a1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


n = read_int()
print('ABC' + str(n))


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


std::int64_t solve(std::int64_t h, std::int64_t w) {
    if (h % 3 == 0) return 0;
    if (w % 3 == 0) return 0;
    std::int64_t l, s;
    l = std::max(h, w);
    s = std::min(h, w);
    auto m = l * s;
    auto md3 = m / 3;
    auto lcan1 = md3 / s;
    auto lcan2 = lcan1 + 1;
    auto lcan3 = lcan1 - 1;

    auto scan1 = md3 / l;
    auto srest1 = s - scan1;
    auto m5 = scan1 * l;
    auto lhalf = l / 2;
    auto lrest5 = l - lhalf;
    auto m6 = lhalf * srest1;
    auto m7 = lrest5 * srest1;
    auto r7 = std::minmax({ m5, m6, m7 });
    auto rc7 = r7.second - r7.first;

    auto scan2 = scan1 + 1;
    auto srest2 = s - scan2;

    auto m8 = scan2 * l;
    auto lhalf1 = l / 2;
    auto lrest6 = l - lhalf1;
    auto m9 = lhalf1 * srest2;
    auto m10 = lrest6 * srest2;
    auto r10 = std::minmax({ m8, m9, m10 });
    auto rc10 = r10.second - r10.first;

    auto lrest = l - lcan1;
    auto m1 = lcan1 * s;
    auto shalf = s / 2;
    auto srest = s - shalf;
    auto m2 = shalf * lrest;
    auto m3 = srest * lrest;
    auto r = std::minmax({ m1, m2, m3 });
    auto rc1 = r.second - r.first;

    auto lrest1 = l - lcan2;
    auto m11 = lcan2 * s;
    auto m12 = shalf * lrest1;
    auto m13 = srest * lrest1;
    auto r1 = std::minmax({ m11, m12, m13 });
    auto rc2 = r1.second - r1.first;

    auto lrest2 = l - lcan3;
    auto mm11 = lcan3 * s;
    auto mm12 = shalf * lrest2;
    auto mm13 = srest * lrest2;
    auto r2 = std::minmax({ mm11, mm12, mm13 });
    auto rc4 = r2.second - r2.first;
#if 1
    auto ld3 = l / 3;
    auto ld31 = ld3 + 1;
    auto m21 = ld3 * s;
    auto m22 = ld31 * s;
    auto rc3 = m22 - m21;
#endif

    return std::min({rc1, rc2, rc3, rc4, rc7, rc10});
}

int main() {
    std::int64_t h, w;
    std::cin >> h >> w;
    std::cout << solve(h, w) << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Union_Find_Tree{
	public:
	vi p,r,s;
	Union_Find_Tree(int n){
		p=r=vi(n);
		s=vi(n,1);
		for(int i=0;i<n;i++) p[i]=i;
	}
	int Par(int x){
		if(p[x]==x) return x;
		return p[x]=Par(p[x]);
	}
	int Size(int x){return s[Par(x)];}
	bool Unite(int x,int y){
		x=Par(x);
		y=Par(y);
		if(x==y) return 0;
		if(r[x]<r[y]){
			p[x]=y;
			s[y]+=s[x];
		}
		else{
			p[y]=x;
			s[x]+=s[y];
			if(r[x]==r[y]) r[x]++;
		}
		return 1;
	}
	bool Same(int x,int y){return Par(x)==Par(y);}
};

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0) break;
		vip a(m);
		for(int i=0;i<m;i++){
			int u,v,w;
			cin>>u>>v>>w;
			u--;v--;
			a[i]={w,{u,v}};
		}
		sort(a.begin(),a.end());
		int res=inf;
		for(int i=0;i<m;i++){
			Union_Find_Tree uft(n);
			for(int j=i;j<m;j++){
				int u=a[j].second.first,v=a[j].second.second;
				uft.Unite(u,v);
				if(uft.Size(0)==n){
					res=min(res,a[j].first-a[i].first);
					break;
				}
			}
		}
		cout<<(res==inf?-1:res)<<endl;
	}
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long 
#define pow10(n) stoll("1"+string(n,'0'))
int main(){
int n,sum=0,p;
cin>>n;
string a[n],s,x;
int b[n];
for(int i=0;i<n;i++)
{
  cin>>s>>p;
  a[i]=s;
  b[i]=p;
}
cin>>x;
for(int i=0;i<n;i++)
{
  if(a[i]==x)
  {
    for(int j=i+1;j<n;j++)
    {
      sum+=b[j];
    }
  }
}
cout<<sum;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

void UpFlags(int n, int size, vector<int>* ups, vector<int>* dws) {
  for (int i = 0; i < size; ++i) {
    if (n & (1<<i)) ups->push_back(i);
    else            dws->push_back(i);
  }
}

int main() {
  int D, G; cin >> D >> G;
  vector<LL> p(D), c(D);
  for (int i = 0; i < D; ++i) {
    cin >> p[i] >> c[i];
    c[i] += p[i] * (i+1) * 100;
  }

  int min_cnt = INT_MAX;
  for (int i = 0; i < (1 << D); ++i) {
    vector<int> ups, dws;
    UpFlags(i, D, &ups, &dws);

    LL sum = 0;
    int count = 0;
    for (int x : ups) {
      sum += c[x];
      count += p[x];
    }
    // cout << i << ":" << sum << ", " << count << "(" << ups.size() << ", " << dws.size() << ")" << endl;

    for (int j = dws.size() - 1; j >= 0; --j) {
      int idx = dws[j];
      LL score = 100 * (idx + 1);
      LL num = p[idx] - 1;
      // cout << "  " << idx << " " << score << "x" << num << ", " << sum << endl;

      if (sum + score * num < G) {
        sum += score * num;
        count += num;
      } else {
        while (sum < G) {
          sum += score;
          ++count;
        }
        break;
      }
    }

    if (sum >= G) {
      min_cnt = min(min_cnt, count);
    }
  }

  cout << min_cnt << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main { 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split(" ");
		int startStep = Integer.parseInt(line[0]);
		int boundMax = Integer.parseInt(line[1]);
		String[] boundStep = sc.nextLine().split(" ");
		
		int resultCount = 1;
		int boundTotal = 0;
		for(int i = 0;i<boundStep.length;i++) {
			int tmp = Integer.parseInt(boundStep[i]);
			boundTotal += tmp;
			if(boundMax<boundTotal) {
				break;
			}
			resultCount++;
		}
		System.out.println(resultCount);
		
	}
}
	
	

Measured memory_bytes: 22868
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

ll f[1000011];

void calc() {
    f[0] = 0;
    int cnt = 0;
    rep(i, 1, 1000011) {
        int a = i;
        while(a % 2 == 0) {
            a /= 2;
            cnt++;
        }
        f[i] = cnt;
    }
}

ll comb(ll n, ll r) {
    return (f[n] - f[r] - f[n - r] > 0) ? 0 : 1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    string s;
    cin >> s;
    calc();
//    rep(i, N) {
//        cout << i << ":" << f[i] << endl;
//    }
    vector<ll> A(N);
    rep(i, N) A[i] = s[i] - '0';
    ll c = 0;
    rep(i, N) {
//        cout << N - 1 << "," << i << ":" << comb(N - 1, i) << endl;
        c += comb(N - 1, i) * (A[i] % 2);
        c %= 2;
    }
    if(c == 1) output(1);
    else {
        vector<ll> B(N - 1);
        rep(i, N - 1) B[i] = abs(A[i] - A[i + 1]);
        bool ok = true;
        rep(i, N - 1) {
            if(B[i] % 2 != 0) {
                ok = false;
                break;
            }
        }
        if(!ok) {
            output(0);
            return 0;
        }
        rep(i, N - 1) B[i] /= 2;
        ll d = 0;
        rep(i, N - 1) {
            d += comb(N - 2, i) * (B[i] % 2);
            d %= 2;
        }
        if(d == 1) output(2);
        else output(0);
    }
    
    return 0;
}


Measured memory_bytes: 24860
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

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

	set<ll> S;
	map<ll, ll> M;
	rep(i, N) {
		set<ll>::iterator it = S.lower_bound(A[i]);
		if(S.size() == 0 || it == S.begin()) {
			S.insert(A[i]);
			M[A[i]]++;
		} else {
			it--;
			M[*it]--;
			if(M[*it] == 0) {
				M.erase(*it);
				S.erase(*it);
			}
			S.insert(A[i]);
			M[A[i]]++;
		}
	}

	ll ans = 0;
	for(pair<ll, ll> item: M) {
		ans += item.second;
	}
	cout << ans  << endl;
	

}

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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const double PI = 3.141592653589793238462643383279;
const int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

int N, K;
int dp[110][220000];
int mod = 1e9 + 7;
int imos[220000];
int co[110000];
signed main() {
    cin >> N >> K;
    int rt = 1;
    while (rt * rt <= N) { rt++; }
    rt--;
    for (int i = 1; i < rt; i++) { co[i] = (N / i - N / (i + 1)); }
    co[rt] = (N / rt - rt);
    dp[0][1] = 1;
    for (int i = 1; i <= K + 1; i++) {
        imos[0] = 0;
        for (int j = 1; j <= rt * 2; j++) { imos[j] = (imos[j - 1] + dp[i - 1][j]) % mod; }
        for (int j = 1; j <= rt; j++) {
            dp[i][j] = imos[rt * 2 + 1 - j];
            dp[i][rt * 2 + 1 - j] = co[j] * imos[j] % mod;
        }

    }
    cout << dp[K + 1][1] << endl;
}


Measured memory_bytes: 177152
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,w,z;
    char ca,cb,cc;
    cin>>n;
    vector<ll> v(n);
    rep(i,n) cin>>v[i];
    sort(all(v));
    cout<<v[n-1]-v[0]<<endl;
    return 0;
}


Measured memory_bytes: 3580
from bisect import bisect_left, bisect_right
from itertools import accumulate

N,M = map(int,input().split())
A = sorted([int(i) for i in input().split()])

# 判定
def is_under_M(x:int):
    cnt = 0
    for i in range(N):
        # 幸福度x以上の個数を求める
        pos = bisect_left(A, x - A[i])
        cnt += N - pos
    return cnt < M

# 二分探索
ng, ok = 0, 2*(10**5)+1
while ok - ng > 1:
    mid = (ok + ng) // 2
    if is_under_M(mid):
        ok = mid
    else:
        ng = mid
# ng, ok = X-1, X

# Aの累積和
Aacum = tuple(accumulate([0] + A))

ans = 0
for i in range(N):
    # 幸福度ng以上の個数を求める
    pos = bisect_left(A, ng - A[i])
    cnt = N - pos

    ans += cnt * A[i] + (Aacum[N] - Aacum[pos])
    M -= cnt

ans += M * ng

print(ans)

Measured memory_bytes: 13920
#include <iostream>
#include <cstdio>
using namespace std;
#define MAX 10000
#define NIL -1

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

void setDepth(int u, int d, Node tree[], int depth[]) {
    if (u == NIL) return;
    depth[u] = d;
    setDepth(tree[u].left, d + 1, tree, depth);
    setDepth(tree[u].right, d + 1, tree, depth);
}

int setHeight(int u, Node tree[], int height[]) {
    int h1 = 0, h2 = 0;
    if (tree[u].left != NIL) {
        h1 = setHeight(tree[u].left, tree, height) + 1;
    }
    if (tree[u].right != NIL) {
        h2 = setHeight(tree[u].right , tree, height) + 1;
    }
    return height[u] = max(h1, h2);
}

int getSibling(int u, Node tree[]) {
    if (tree[u].parent == NIL) return NIL;
    if (tree[tree[u].parent].left != u && tree[tree[u].parent].left != NIL) {
        return tree[tree[u].parent].left;
    }
    if (tree[tree[u].parent].right != u && tree[tree[u].parent].right != NIL) {
        return tree[tree[u].parent].right;
    }
    return NIL;
}

void printTree(int u, Node tree[], int depth[], int height[]) {
    printf("node %d: ", u);
    printf("parent = %d, ", tree[u].parent);
    printf("sibling = %d, ", getSibling(u, tree));
    int deg = 0;
    if (tree[u].left != NIL) deg++;
    if (tree[u].right != NIL) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", depth[u]);
    printf("height = %d, ", height[u]);

    if (tree[u].parent == NIL) {
        printf("root\n");
    } else if (tree[u].left == NIL && tree[u].right == NIL) {
        printf("leaf\n");
    } else {
        printf("internal node\n");
    }
}

int main() {
    Node tree[MAX];
    int n, depth[MAX], height[MAX];
    cin >> n;
    for (int i = 0; i < n; i++) tree[i].parent = NIL;

    int v, l, r, root = 0;
    for (int i = 0; i < n; i++) {
        cin >> v >> l >> r;
        tree[v].left = l;
        tree[v].right = r;
        if (l != NIL) tree[l].parent = v;
        if (r != NIL) tree[r].parent = v;
    }

    for (int i = 0; i < n; i++) {
        if (tree[i].parent == NIL) {
            root = i;
            break;
        }
    }

    setDepth(root, 0, tree, depth);
    setHeight(root, tree, height);

    for (int i = 0; i < n; i++) printTree(i, tree, depth, height);
}



Measured memory_bytes: 3224
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X):
    @lru_cache(maxsize=None)
    def p(n):
        if n == 0:
            return 1
        return 2*p(n-1) + 1
    
    @lru_cache(maxsize=None)
    def a(n):
        if n == 0:
            return 1
        return 2*a(n-1) + 3
    
    def f(n, x):
        if x == 1:
            return 0
        
        elif x < a(n-1)+1:
            return f(n-1, x-1)
        
        elif x == a(n-1) + 1:
            return p(n-1)

        elif x == a(n-1) + 2:
            return p(n-1) + 1

        elif x < a(n) - 2:
            return p(n) - f(n-1, a(n)-x-1)
        
        else:
            return p(n)
    
    return f(N, X)

# BBPPPBPBPPPBB

def main():
    N, X = read_int_n()
    print(slv(N, X))

    # print(slv(2, 13))
    # # for i in range(1, 14):
    # #     print(i, slv(2, i))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6872
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する


int main() {
    string s;
    cin >> s;
    int sum = 0;
    REP(i,0,s.size()){
        sum += (s[i] - '0');
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,c,i,j,s=60*60*2;
  while(cin >> a >> b >> c,a!=-1){
    i=s-a*60*60-b*60-c;
    if(i/3600>0) cout << "0"<< i/3600 <<":";
    else cout << "00:";
    if((i%3600)/60>9) cout << ((i%3600)/60) << ":";
    else if((i%3600)/60>0) cout << "0" << ((i%3600)/60) << ":";
    else cout << "00:";
    if(i%60>9) cout << i%60 << endl;
    else if(i%60>0) cout << "0" << (i%60) << endl;
    else cout << "00" << endl;
    i*=3;
    if(i/3600>0) cout << "0"<< i/3600 <<":";
    else cout << "00:";
    if((i%3600)/60>9) cout << ((i%3600)/60) << ":";
    else if((i%3600)/60>0) cout << "0" << ((i%3600)/60) << ":";
    else cout << "00:";
    if(i%60>9) cout << i%60 << endl;
    else if(i%60>0) cout << "0" << (i%60) << endl;
    else cout << "00" << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ll long long int

template <typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

using namespace std;
ll ans = 0, sum = 0, n, k, t;
string s;

ll a, b, h;

int main()
{
	cin >> a >> b >> h;
	cout << (a + b)*h / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

int n;
ll x[100010];
ll a,b,fat;

int main() {
    scanf("%d%lld%lld",&n,&a,&b);
    for (int i=1;i<=n;i++) {
        scanf("%lld",x+i);
    }
    fat=0;
    for (int i=2;i<=n;i++) {
        ll dis=x[i]-x[i-1];
        fat+=min(dis*a,b);
    }
    printf("%lld\n",fat);
}

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

using ll = long long int;

const int MAX_N = (int)(2e5 + 5);

int n;
ll a[MAX_N];

ll diff[MAX_N];

ll ans = (ll)(1e18 + 5);

int main(void){
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &(a[i]));
  }

  for (int i = 1; i <= n; ++i) {
    diff[i] = a[i] - i;
  }

  sort(diff + 1, diff + n + 1);

  ll b = (n % 2 == 0) ? ceil((diff[1 + (n / 2)] + diff[(n / 2)]) / 2) : diff[1 + (n / 2)];

  for (ll tb = b - 2; tb <= b + 2; ++tb) {
    ll cand = 0;
    for (ll j = 1; j <= n; ++j) {
      cand += abs(a[j] - (tb + j));
    }
    ans = min(cand, ans);
  }

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

  return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
#define INF 1e9
#define	Min(a,b) (a < b ? a : b)

int main(){
  int i,j,k,n;
  int r[100],c[100];
  int dp[100][100];

  for(i=0;i<100;i++)
    for(j=0;j<100;j++)
      dp[i][j]=(i==j?0:INF);

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d %d",&r[i],&c[i]);
  for(k=1;k<n;k++)
    for(i=0;i+k<n;i++)
      for(j=i;j<i+k;j++)
	dp[i][i+k]=Min(dp[i][i+k],dp[i][j]+dp[j+1][i+k]+r[i]*c[j]*c[i+k]);

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

Measured memory_bytes: 636
import Foundation
 
let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ")
 
var A = Int(split[0])!
var B = Int(split[1])!

if (A <= 9 && B <= 9){
    print(A*B)
}else{
    print("-1")
}
    

Measured memory_bytes: 14176
#include <stdio.h>

int main(void) {
  int W, H, x, y, r;
  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  if ( (x-r < 0 || x+r > W) || (y-r < 0 || y+r > H) ) {
    printf("No\n");
  } else {
    printf("Yes\n");
  }

  return 0;
}

Measured memory_bytes: 584
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	double w, h, x, y;
	cin >> w >> h >> x >> y;
	double s = (h/2)*w;
	cout << fixed << setprecision(12) << s << " ";
	if(w == 2*x && h == 2*y) cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
	int N,K,i,num;
	cin >> N >> K;
	num = 1;
	for(i=0;i<N;i++){
		if(num <= K) num *= 2;
		else num += K;
	}
	cout << num << endl;
	return 0;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

/**
 * 0007:Debt Hell
 * 
 * @author MS14A
 * @version 2015/04/09
 */
public class Main {

    /** 初期借金額：10万円 */
    private static final BigDecimal INITIAL_DEBT = new BigDecimal("100000");

    /** 利子：5% */
    private static final BigDecimal INTEREST_RATE = BigDecimal.valueOf(0.05);

    /** 繰り上げ計算用 */
    private static final BigDecimal DIVISOR = BigDecimal.valueOf(1000);

    /**
     * 某国に住んでいる友達がお金に困って、あるヤミ金融業者から 10 万円の借金をしたまま、<br>
     * 全く返済していないといいます。<br>
     * この業者は、一週間ごとに 5% の利子を借金に加え、さらに借金の 1,000 円未満を切り上げます。<br>
     * n を入力したとき、n 週間後の借金の残高を出力し終了するプログラムを作成して下さい。<br>
     * n は 100 以下とします。
     * 
     * @param args
     */
    public static void main(String[] args) {
        // 標準入力読み取り
        int weeks = getN();

        // n週間後の借金額計算
        calcDebt(weeks);
    }

    /**
     * 標準入力を読み取り、"n"の値を返す。
     * 
     * @return n：入力値
     */
    private static int getN() {
        Scanner scanned = new Scanner(System.in);
        return scanned.nextInt();
    }

    /**
     * n週間後の借金額を計算する。
     * 
     * @param weeks
     */
    private static void calcDebt(int weeks) {
        BigDecimal finalDebt = INITIAL_DEBT;

        for (int i = 0; i < weeks; i++) {
            // 利子額計算。1000で割った小数部を繰り上げる。
            BigDecimal interestAmount = finalDebt.multiply(INTEREST_RATE)
                    .divide(DIVISOR, 0, BigDecimal.ROUND_UP);

            // 借金額 = 前週の借金額 + 利子額
            finalDebt = finalDebt.add(interestAmount.multiply(DIVISOR));
        }

        System.out.println(finalDebt);
    }

}

Measured memory_bytes: 15404
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e10+10;

/*----------------------------------------------*/

signed main(){
  string s;
  int k;
  cin>>s>>k;
  int ans;
  int n=s.size();
  /*if(k==1){
    int check=1;
    rep(i,s.size()-1){
      if(s[i]==s[i+1]) check++;
      else{
        ans+=check/2;
        check=1;
      }
    }
  }
  *///else{
    int i=0;
    while(s[i]==s[i+1]&&i<s.size()-1) i++;
    if(i+1==s.size()){
      ans=s.size()*k/2;
    }else{
      ans=(i+1)/2;
      //
      int ams=0,check=1;
      FOR(j,i+1,i+1+n){
        if(s[j%n]==s[(j+1)%n]) check++;
        else{
          ams+=check/2;
          check=1;
        }
      }
      ans+=ams*(k-1);
      //
      check=1;      
      FOR(j,i+1,n-1){
        if(s[j]==s[j+1]) check++;
        else{
          ans+=check/2;
          check=1;
        }
      }

    }
  // }

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

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

const int MAXF = 2e5 + 5;
const int MAXN = 3e3 + 5;
const ll MOD = 1e9 + 7;
vector<pair<int, ll>> adj[MAXN];
ll paths[MAXN], fact[MAXF], h, w;
int n, vist[MAXN];
pair<int, int> loc[MAXN];

ll mpow(ll b, ll e) {
    if(e == 0)
        return 1;
    if(e % 2)
        return (b * mpow(b, e - 1)) % MOD;
    ll p = mpow(b, e/2);
    return (p * p) % MOD;
}

ll inv(ll b) {
    return mpow(b, MOD - 2);
}

ll binom(int n, int k) {
    return (fact[n] * inv((fact[k] * fact[n - k]) % MOD)) % MOD;
}

ll dfs(int s) {
    vist[s] = 1;
    for(auto e : adj[s]) {
        int v = e.first;
        ll w = e.second;
        if(!vist[v])
            dfs(v);
        paths[s] = (MOD + paths[s] + (paths[v] * w + MOD) % MOD) % MOD;
    }
    return paths[s];
}

int main() {
    fact[0] = 1;
    for(ll i = 1; i < MAXF; i++)
        fact[i] = (i * fact[i - 1]) % MOD;
    cin >> h >> w >> n;
    for(int i = 1; i <= n; i++) {
        int r, c;
        cin >> r >> c;
        loc[i] = {r, c};
    }
    loc[0] = {1, 1}, loc[n + 1] = {h, w};
    for(int i = 0; i <= n + 1; i++) {
        for(int j = 0; j <= n + 1; j++) {
            int dh = loc[j].first - loc[i].first, dv = loc[j].second - loc[i].second;
            if(dh < 0 || dv < 0)
                continue;
            if(i == j)
                continue;
            adj[i].push_back({j, -binom(dh + dv, dh)});
        }
    }
    paths[n + 1] = -1;
    cout << (dfs(0) + MOD) % MOD << endl;
}

Measured memory_bytes: 85504
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<vector>
using namespace std;
#define ll long long int


int main()
{
	int N, K;
	cin>>N>>K;
	vector<int> snuke(N+1);
	int d,A,ans = 0;
	while(K--)
	{
		cin>>d;
		while(d--)
		{
			cin>>A;
			snuke[A]++;
		}
	}
	for(int i=1;i<=N;i++)
	{
		if(snuke[i]==0)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll n;
  cin>>n;
  
  string s;
  cin>>s;
  
  ll a[26] = {0};
  
  for(ll i = 0 ; i < n/2 ; i++) a[s[i] - 'a']++;
    
  for(ll i = n/2 ; i < n ; i++) a[s[i] - 'a']--;
  
  ll flag = 0;
  for(auto i : a) {
    if(i != 0){
    	flag = 1; 
    	break;
  	}
  }
  
  if(flag == 0) cout<<"Yes"<<endl;
  else cout<<"No";
  
  return 0;
  
}


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


using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

int main(){
    ll N,A,B;
    cin >> N >> A >> B;
    ll ti=N/(A+B);
    cout << ti*A+min(A,N-ti*(A+B)) << endl;



    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int dp[3003][3003];
int main()
{
    string x,y,str="";
    cin>>x>>y;
    int sz1=x.size(),sz2=y.size();
    for(int i=1; i<=sz1; i++)
    {
        for(int j=1; j<=sz2; j++)
        {
            if(x[i-1]==y[j-1])
                dp[i][j]=1+dp[i-1][j-1];
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    int i=sz1,j=sz2;
    while(1)
    {
        if(i==0 || j==0) break;
        if(x[i-1]==y[j-1])
        {
            str+=x[i-1];
            --i,--j;
        }
        else
        {
            if(dp[i-1][j]>dp[i][j-1])
            {
                --i;
            }
            else --j;
        }
    }
    reverse(str.begin(),str.end());
    cout<<str<<endl;
}


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

#define ll long long
#define ull unsigned ll

#define vi vector <int>
#define ii pair <int, int>
#define vii vector <ii>
#define INFLL 9e18
#define INF 2e9
#define EPS 1e-9
#define pb push_back
#define emp emplace_back
#define PI acos(-1.0)
#define endl "\n"
#define mp make_pair
#define DEBUG 0



int main ()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);

    int k, a, b;
    cin >> k >> a >> b;
    for (int i=a; i<=b; i++)
    {
        if (i%k == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
       
    
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int A(int a){
	if(a<0) return -a;
	return a;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int arr[200000],N;
	int DP[200000];
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> arr[i];
	}
	DP[0] = 0;
	DP[1] = A(arr[1]-arr[0]);
	for(int i=2;i<N;i++){
		DP[i] = min(DP[i-1] + A(arr[i]-arr[i-1])  ,DP[i-2] + A(arr[i]-arr[i-2]) );
	}
	cout << DP[N-1]<< endl;
}



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

int a[100005];
int main(){
	int n;
	int k;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>k;
		a[k] = i;
	}
	for(int i=1;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<a[n];
	return 0;
}

Measured memory_bytes: 1152
n, a, b = map(int, input().split())
m = int(1e9) + 7
ans = (pow(2, n, m) -1) % m
val = 1
val2 = 1
for i in range(a):
    val = (val * (n - i)) % m
    val2 = (val2 * (i + 1)) % m
ans -= (val * (pow(val2, m-2, m)))
#print(((val % m) * (pow(val2, m-2, m))))
val = 1
val2 = 1
for i in range(b):
    val = (val * (n - i)) % m
    val2 = (val2 * (i + 1)) % m
ans -= val * (pow(val2, m-2, m))
#print(((val % m) * (pow(val2, m-2, m))))
print(ans % m)


Measured memory_bytes: 39408
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

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

    int max_l,min_r;
    max_l = 0,min_r = 100000+10;

    for(int i = 0;i < m;i++) {
        int l,r;
        cin>>l>>r;

        max_l = max(max_l,l);
        min_r = min(min_r,r);
    }

    if(min_r - max_l < 0) {
        cout<<0<<endl;
    } else {
        cout<<min_r-max_l+1<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char c;
bool f=false,v=false;
int main()
{
	while(c=getchar())
	{
		if(c=='\n')
			break;
		if(c=='C')
			f=true;
		if(f&&c=='F')
		{
			v=true;
			break;
		}
	}
	puts(v?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    deque<ll> d;
    rep(i, n) {
        ll a;
        cin >> a;
        int idx = lower_bound(d.begin(), d.end(), a) - d.begin() - 1;
        if (idx < 0) {
            d.push_front(a);
        }
        else {
            d[idx] = a;
        }
    }
    cout << d.size() << endl;
    return 0;
}


Measured memory_bytes: 4428
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define ll long long
using namespace std;

ll gcd(ll a, ll b)
{
	if(b == 0)
		return a;
	return gcd(b, a % b);
}
int main()
{
    ll k;
    cin >> k;

    ll gcdVal = 0;
    for(ll i = 1; i <= k; i ++)
    {
    	for(ll j = 1; j <= k; j ++)
    	{
    		ll temp = gcd(i, j);
    		for(ll l = 1; l <= k; l ++)
    		{
    			gcdVal = gcdVal + gcd(temp, l);
    		}
    	}
    }
    cout << gcdVal << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d) accumulate(a.begin() + 1, a.end(), a[0], [](string s, string t) {return s + d + t;})
#define all(a) a.begin(), a.end()
#define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;
  vector<vector<int>> g(N, vector<int>(N, -1));
  int A, X, Y;
  rep(i, 0, N) {
    cin >> A;
    rep(j, 0, A) {
      cin >> X >> Y;
      g[i][X-1] = Y;
    }
  }

  int ans = 0;
  rep(i, 0, 1 << N) {
    vector<int> d(N);
    rep(j, 0, N) {
      if (i >> j & 1)
        d[j] = 1;
    }
    bool ok = true;
    rep(j, 0, N) {
      if (d[j]) {
        rep(k, 0, N) {
          if (g[j][k] == -1) continue;
          if (g[j][k] != d[k])
            ok = false;
        }
      }
    }
    if (ok)
      ans = max(ans, __builtin_popcount(i));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Grid = Tuple!(long, "x", long, "y");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto n = lread();
    auto a = new Grid[](n);
    auto c = new Grid[](n);
    auto pair = new long[](n);
    foreach (i; iota(n))
    {
        long x, y;
        scan(x, y);
        a[i] = Grid(x, y);
    }
    foreach (i; iota(n))
    {
        long x, y;
        scan(x, y);
        c[i] = Grid(x, y);
    }
    a.sort!"a.y > b.y"();
    c.sort();
    foreach (e; c)
    {
        long tmp;
        while (1)
        {
            if (tmp >= n)
                break;

            if (!pair[tmp] && a[tmp].x < e.x && a[tmp].y < e.y)
            {
                pair[tmp]++;
                break;
            }
            tmp++;
        }
    }
    pair.sum.writeln();
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
 
#define repd(i,a,b); for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define ll long long int
 
 
using namespace std;
int main() {
 int n,m; cin >> n; m=n;
 int s = 0;
  while(n >= 10){
  s += n%10;
  n = (n-n%10)/10;
  }
  s += n;
    
  if(m%s == 0){
    cout << "Yes";
  } else {
    cout << "No";
  }
 return 0;
}

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

int n, t, mx, ans;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> t;
	for(int i = 0, x; i < n; i++) {
		cin >> x;
		ans += x+t-max(mx, x);
		mx = max(x+t, mx);
	}
	cout << ans;
}


Measured memory_bytes: 892
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<tuple>
#include <iomanip>

typedef long long ll;
typedef long double ld;

using namespace std;
using Graph = vector<vector<ll>>;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)
#define ALL(a) (a).begin(),(a).end()

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

ll GetDigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main(){
    ld N,K,ans=0;
    cin >> N >> K;
    vector<long double> p(N,0);
    vector<ld> EX(N,0);
    vector<ld> cum(N,0);
    rep(i,N){
    cin >> p[i];
    EX[i] = (p[i]+1)/2;
    if(i==0){
        cum[i]=EX[i];
    }else{
        cum[i]= cum[i-1]+EX[i];
    }
    }
    for(ll i=K-1;i<N;i++){
       if(i==K-1){
       ans = cum[K-1];
       }else{
           ans = max(ans,cum[i]-cum[i-K]);
       }
    }
    cout << setprecision(9) << ans << endl;
	return 0;
}



Measured memory_bytes: 9600
w, h, n = map(int, input().split())
a = [[int(i) for i in input().split()] for j in range(n)]
s = [0,w]
t = [0,h]
for i in range(n):
    if a[i][2] == 1:
        s[0] = max(s[0],a[i][0])
    elif a[i][2] == 2:
        s[1] = min(s[1],a[i][0])
    elif a[i][2] == 3:
        t[0] = max(t[0],a[i][1])
    else:
        t[1] = min(t[1],a[i][1])
print(max(0,(s[1]-s[0]))*max(0,(t[1]-t[0])))

Measured memory_bytes: 3064
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
l=[3,5,7]
res=set()
for i in range(3,10):
    for k in itertools.product(l,repeat=i):
        if 5 not in k or 3 not in k or 7 not in k:
            continue
        else:
            num=0
            for j in range(i):
                num+=k[j]*10**(i-j-1)
            res.add(num)
res=list(res)
res.sort()
ans=bisect.bisect_right(res,n)
print(ans)

Measured memory_bytes: 76440
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n%2==0){
    cout<<n<<endl;
  }else{
    cout<<n*2<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int A1, A2, A3, sum;
int main() {
  scanf("%d %d %d", &A1, &A2, &A3);
  sum = A1 + A2 + A3;
  if(sum < 22) printf("win\n");
  else printf("bust\n");
}

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

const int MOD = 1000000007;

ll pw(ll n, ll k) {
	ll r = 1; for(n %= MOD; k; k >>= 1) {
		if(k&1) r = r * n % MOD;
		n = n * n % MOD;
	}
	return r;
}
ll inv(ll n) { return pw(n, MOD-2); }

const int MAXN = 1005;

ll E[MAXN][MAXN];
ll F[MAXN], RF[MAXN];

int N, A, B, C, D;

ll getC(int a, int b) {
	if(a < 0 || b < 0 || a < b) return 0;
	return F[a] * RF[b] % MOD * RF[a-b] % MOD;
}

int main() {
	F[0] = 1;
	for(int i = 1; i < MAXN; i++) F[i] = F[i-1] * i % MOD;
	RF[MAXN-1] = inv(F[MAXN-1]);
	for(int i = MAXN; --i;) RF[i-1] = RF[i] * i % MOD;

	cin >> N >> A >> B >> C >> D;
	E[A-1][0] = 1;
	for(int i = A; i <= B; i++) {
		for(int j = 0; j <= N; j++) {
			ll &ret = E[i][j];
			ret = E[i-1][j];
			for(int k = C; k <= D && 0 <= j-k*i; k++) {
				ret += E[i-1][j-k*i] * getC(N - (j-k*i), k*i) % MOD * F[k*i] % MOD * RF[k] % MOD * pw(RF[i], k) % MOD;
				ret %= MOD;
			}
		}
	}

	cout << E[B][N] << endl;
	return 0;
}

Measured memory_bytes: 8064
n = int(input())
s = []
for i in range(n):
    s.append(input())

a = 'abcdefghijklmnopqrstuvwxyz'

ans = ''
for i in a:
    b = 50
    for j in s:
        b = min(j.count(i),b)
    ans += i*b
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll n; cin >> n;
    vector<pair<ll, ll>> v;
    rep(i, n) {
        ll x, l; cin >> x >> l;
        v.push_back(make_pair(x + l, x)); // 位置 + 腕が短い順に貪欲
    }
    sort(all(v));
    ll ans = 1; // 残すロボットのカウント。一番最初は絶対採用
    ll now = v[0].first; // 現在の腕を含めた右端
    Rep(i, 1, n) {
        if(now <= v[i].second - (v[i].first - v[i].second)) { // first - secondが腕
            ans++;
            now = v[i].first;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5368