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

#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define f(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)

const double pi = 2*acos(0.0);
//__gcd(n1, n2);
//cout << fixed;
//cout << setprecision(6); //fixes # of dp

const int mxN=1e6, M=1e9+7;
ll iv[3*mxN], f1[3*mxN], f2[3*mxN];
 
ll nck(int n, int k) {
	return f1[n]*f2[k]%M*f2[n-k]%M;
}
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
 
	iv[1]=1;
	for(int i=2; i<3*mxN; ++i)
		iv[i]=M-M/i*iv[M%i]%M;
	f1[0]=f2[0]=1;
	for(int i=1; i<3*mxN; ++i) {
		f1[i]=f1[i-1]*i%M;
		f2[i]=f2[i-1]*iv[i]%M;
	}
    int r1, r2, c1, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	cout << ((nck(r2+c2+2, c2+1)-nck(r1+c2+1, c2+1)-nck(r2+c1+1, c1)+nck(r1+c1, c1))%M+M)%M;
}

//not my ans but nice






Measured memory_bytes: 70528
#include <stdio.h> 
#include <algorithm>

typedef long long LL;

LL GCD(LL a, LL b){
	if (a<b) std::swap(a, b);
	LL lcm = a * b; 
	while (b != 0)  { 
		LL gcd = a % b; 
		a = b; 
		b = gcd; 
	} 
	return a;
}

int main(){
	LL a, b;
	while (~scanf("%lld%lld", &a, &b)){
		LL tmp = GCD(a, b);
		printf("%lld %lld\n", tmp, a*b/tmp);
	}
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

vector<string> list[40];
string name[40];
int n, w[40], sum;
vector<vi> e;
bool v[40], ok[40];

void dfs(int c, vector<pi> &o){
	o.pb(mp(w[c], c));
	v[c] = 1;
	ok[c] = 1;
	each(i, e[c]) if(!v[*i]) dfs(*i, o);
}
void rec(int c, int cur, const vector<pi> &o){
	int next = -1, tmp = 0;
	for(int i = o.size() - 1; i >= c; i--) if(ok[o[i].second]){
		if(i > c) next = i;
		tmp += o[i].first;
	}
	if(cur + tmp <= sum) return;
	if(next < 0){
		sum = cur + tmp;
		return;
	}
	if(ok[o[c].second]){
		bool ok2[40];
		rep(i, n) ok2[i] = ok[i];
		each(i, e[o[c].second]) ok[*i] = 0;
		ok[o[c].second] = 0;
		rec(next, cur + o[c].first, o);
		rep(i, n) ok[i] = ok2[i];
	}
	if(o[c].second != 0) rec(next, cur, o);
}

int main(){
	while(cin >> n, n){
		memset(v, 0, sizeof(v));
		e.clear(); e.resize(n);
		map<string, int> id;
		rep(i, n){
			int k;
			cin >> name[i] >> w[i] >> k;
			list[i].clear(); list[i].resize(k);
			rep(j, k) cin >> list[i][j];
			id[name[i]] = i;
		}
		rep(i, n) rep(j, list[i].size()) e[i].pb(id[list[i][j]]);
		
		int ans = 0;
		rep(i, n) if(!v[i]){
			vector<pi> ord;
			dfs(i, ord);
			sort(all(ord), greater<pi>());
			int p = -1;
			rep(j, ord.size()) if(ord[j].second == 0) p = j;
			if(p >= 0) swap(ord[p], ord[0]);
			sum = 0;
			rec(0, 0, ord);
			ans += sum;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1376
fn main() {
    let n: usize = read();
    let mut a: Vec<usize> = vec![];
    for _ in 0..n {
        a.push(read());
    }
    for i in (1..n).rev() {
        print!("{} ", a[i]);
    }
    println!("{}", a[0]);
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: isize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========



Measured memory_bytes: 5028
#ifndef LOCAL
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 210000;

int n;
int b[MAXN];
int q;
vector<pair<int, int> > vv;

int pr[MAXN];
int dp[MAXN];
int rmq1[MAXN * 4];
int rmq2[MAXN * 4];

const int INF = 1e6;

void build(int v, int tl, int tr) {
	if (tl + 1 == tr) {
		rmq1[v] = dp[tl];
		rmq2[v] = dp[tl] - pr[tl];
		return;
	}
	int m = (tl + tr) >> 1;
	build(v * 2 + 1, tl, m);
	build(v * 2 + 2, m, tr);
	rmq1[v] = min(rmq1[v * 2 + 1], rmq1[v * 2 + 2]);
	rmq2[v] = min(rmq2[v * 2 + 1], rmq2[v * 2 + 2]);
}

void upd(int v, int tl, int tr, int x, int y) {
	if (tl + 1 == tr) {
		rmq1[v] = y;
		rmq2[v] = y - pr[tl];
		return;
	}
	int m = (tl + tr) >> 1;
	if (x < m)
		upd(v * 2 + 1, tl, m, x, y);
	else
		upd(v * 2 + 2, m, tr, x, y);
	rmq1[v] = min(rmq1[v * 2 + 1], rmq1[v * 2 + 2]);
	rmq2[v] = min(rmq2[v * 2 + 1], rmq2[v * 2 + 2]);
}

int get1(int v, int tl, int tr, int l, int r) {
	if (r <= tl || tr <= l)
		return INF;
	if (l <= tl && tr <= r)
		return rmq1[v];
	int m = (tl + tr) >> 1;
	return min(get1(v * 2 + 1, tl, m, l, r), get1(v * 2 + 2, m, tr, l, r));
}

int get2(int v, int tl, int tr, int l, int r) {
	if (r <= tl || tr <= l)
		return INF;
	if (l <= tl && tr <= r)
		return rmq2[v];
	int m = (tl + tr) >> 1;
	return min(get2(v * 2 + 1, tl, m, l, r), get2(v * 2 + 2, m, tr, l, r));
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", b + i);
	scanf("%d", &q);
	for (int i = 0; i < q; ++i) {
		int l, r;
		scanf("%d%d", &l, &r);
		--l;
		vv.push_back(make_pair(l, r));
	}
	sort(vv.begin(), vv.end());
	pr[0] = 0;
	for (int i = 0; i < n; ++i) {
		if (b[i] == 1)
			pr[i + 1] = pr[i] - 1, ++dp[0];
		else
			pr[i + 1] = pr[i] + 1;
	}
	for (int i = 1; i <= n; ++i)
		dp[i] = INF;
	build(0, 0, n + 1);
	for (int i = 0; i < vv.size(); ++i) {
		int l, r;
		tie(l, r) = vv[i];
		ll ans = min(pr[r] + get2(0, 0, n + 1, l, r), get1(0, 0, n + 1, 0, l) + pr[r] - pr[l]);
		if (ans < dp[r]) {
			dp[r] = ans;
			upd(0, 0, n + 1, r, ans);
		}
	}
	int ans = INF;
	for (int i = 0; i <= n; ++i)
		ans = min(ans, dp[i]);
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 10992
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int b,c,n,m,s=0;
    cin>>n>>m;
    int a[n+10];
    for(int i = 0;i < n;i++)
    {
        cin>>a[i];
        s += a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);

    b  = ceil(s*1.0/(4*m));

    //cout<<a[m-1]<<" "<<b<<endl;

    if(a[m-1] >= b)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,string> P;
typedef pair<unsigned long long,int> PP;

struct RH {
  vector<unsigned long long> p,hash;
  void init(const string s) {
    unsigned long long m=1000000007,q=1,n=s.size();
    p.resize(n+1);hash.resize(n+1);p[0]=q;hash[0]=0;
    rep(i,n){p[i+1]=p[i]*m;hash[i+1]=s[i]+hash[i]*m;}
  }
  unsigned long long h(int i)const{return hash[i];}
  unsigned long long h(int i,int j)const{return h(j)-h(i)*p[j-i];}
};

map<PP,int> m[1000001];

RH r;
P p[200002];
void Main() {
  ll n;
  R n;
  rep(i,n) {
    R p[i].S;
    p[i].F=p[i].S.size();
    reverse(all(p[i].S));
  }
  sort(p,p+n);
  ll ans=0;
  rep(l,n) {
    string t=p[l].S;
    r.init(t);
    ll c[26];
    mem(c);
    ll mm=t.size();
    rrep(i,mm) {
      int k=t[i]-'a';
      c[k]=1;
      rep(j,26) {
        if(c[j]&&m[i].count(PP(r.h(i),j))) ans+=m[i][PP(r.h(i),j)];
      }
    }
    int k=t[mm-1]-'a';
    m[mm-1][PP(r.h(mm-1),k)]++;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 76312
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const int mod = 1e9+7;
const int N = 1e5+5;
//int a[N];

int main()

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

    int n;

    cin >> n;

    double arr[n];

    for (int i = 0; i < n; i++) {

        cin >> arr[i];
    }

    sort(arr, arr+n);

    for (int i = 0; i < n-1; i++) {

        arr[i+1] = (arr[i]+arr[i+1])/2;
    }

    cout << fixed << setprecision(8) << arr[n-1];

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;

string s; //yツづ個閉カツ篠堋療アツ表ツ記
int x,y,len;
int ans[6],ansSize,ansSum,ansFlg;
int tmp[6],size;

void solve(int rem,int idx,int sum){
	if(rem == 0 && idx == len){
		if(ansSum < sum && sum <= x){
			for(int i=0;i<size;i++) ans[i] = tmp[i];
			ansSize = size;
			ansSum = sum;
			ansFlg = 2;
		}
		else if(ansSum == sum) ansFlg = 1;
		return;
	}
	if(rem <= 0 || idx >= len) return;

	for(int nidx=idx+1;nidx<=len;nidx++){
		string sub = s.substr(idx,nidx-idx);
		int plus = atoi(&sub[0]);
		if(sum + plus <= x){
			tmp[size-rem] = plus;
			solve(rem-1,nidx,sum+plus);
		}
	}
}

string itos(int x){stringstream ss; ss<<x; return ss.str();}

int main(void){
	while(cin>>x>>y,x||y){
		s = itos(y);
		len = s.length();
		ansFlg = size = 0;
		ansSum = -1;

		//ツ閉ェツ環青板づ個個按津ィ
		for(size=1;size<=len;size++){
			solve(size,0,0);
		}

		if(ansFlg == 0)
			cout<<"error\n";
		else if(ansFlg == 1)
			cout<<"rejected\n";
		else{
			cout<<ansSum;
			for(int i=0;i<ansSize;i++) cout<<" "<<ans[i];
			cout<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 
 
#define PI 3.14159265
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
const ll limit = 2e9;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
 
//const int mod = 998244353;
 
struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a);
		b = find_set(b);	
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}
};

struct nod{
	int x, y;
	nod(int x_,int y_): x(x_), y(y_){};
};

bool operator<(nod & a, nod & b){
  return a.y < b.y;
}

char tab[207][207];

vector<string> printVertically(string s) {
	for(int i = 0; i < 207; i++){
		for(int j = 0; j < 207; j++)
			tab[i][j] = ' ';
	}
	s += "$";
	vector<string> v;
	int r = 1,c = 1;
	for(int i = 0; i < (int)s.size(); i++){
		
		c = 1;
		while( s[i] != ' ' && s[i] != '$'){
			
			tab[r][c] = s[i];
			i++;
			c++;
			
		}
		r++;
	
	}
	
	for(int i = 1; i < 207; i++){
		string str = "";
		bool flag = false;
		for(int j = 206; j >= 1; j--){
			if(tab[j][i] != ' ')
				flag = true;
			if(flag){
				str+= tab[j][i];
			}
		}
		if(str.size() > 0){
			reverse(str.begin(),str.end());
			v.push_back(str);
		}
		
	}
	
	for(string x: v)
		cout<<x<<"-"<<endl;
	return v;
}
    


int main(){
	int n; cin>> n;
	int x;
	int ans = 0, mini = inf;
	for(int i = 1; i <= n; i++){
		cin>> x;
		if(i == 1){
			mini = x;
			ans++;
		}
		else{
			if( x <= mini){
				mini = x;
				ans++;
			}
		}
	}
	cout<<ans;
	return 0;
}


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

typedef long long ll;

int main() {
    string N;
    cin >> N;
    ll s = 0;
    rep(i, N.size()) {
        s += N[i] - '0';
    }
    if (s % 9) cout << "No\n";
    else cout << "Yes\n";
}

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int a, b;
	cin >> a >> b;
	cout << max(a, b) + max(max(a, b) - 1, min(a, b)) << "\n";
}

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


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

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

    for (int l = 0; l < n; l++) {
        while (h[l] > 0) {
            int r;
            for (r = l + 1; r < n; r++) {
                if (h[r] == 0) break;
            }

            for (int k = l; k < r; k++) {
                h[k]--;
            }
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a){cout<<((a)?"Yes":"No")<<endl;}
void YESNO(int a){cout<<((a)?"YES":"NO")<<endl;}
void AorB(int a,string b,string c){cout<<((a)?b:c)<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    int n,ma,mb,ans=INF;
    cin>>n>>ma>>mb;
    Vi a(n),b(n),c(n);
    REP(i,0,n) cin>>a[i]>>b[i]>>c[i];
    
    const int nmax=40,amax=10,bmax=10;

    vector<VVi> dp(nmax+1,VVi(nmax*amax+1,Vi(nmax*bmax+1,INF)));
    dp[0][0][0]=0;
    REP(i,0,n){
        REP(j,0,nmax*amax+1){
            REP(k,0,nmax*bmax+1){
                if(dp[i][j][k]==INF) continue;
                chmin(dp[i+1][j][k],dp[i][j][k]);
                if(j+a[i]<=nmax*amax && k+b[i]<=nmax*bmax) chmin(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
            }
        }
    }
    for(int i=1; i*ma<=nmax*amax && i*mb<=nmax*bmax; i++){
        chmin(ans,dp[n][i*ma][i*mb]);
    }
    if(ans==INF) ans=-1;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 53504
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <list>
#include <string.h>
#include <functional>
//#include <Windows.h>
//#include "Library.h"
//#include "Math.h"
using namespace std;
typedef long long int ll; typedef pair <double, int> P; typedef vector <int> vecint;
const int INF = 2000000000;
const double EPS = 10e-9;
int main()
{
	int n, m; cin >> n >> m;
	int num = 1 << m;
	cout << ((n - m) * 100 + 1900 * m) * num << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>

int main() {
	char ch = getchar();
	while(ch != EOF) {
		if(isalpha(ch)) {
			if(islower(ch)) ch = toupper(ch);
			else ch = tolower(ch);
		}
		putchar(ch);
		ch = getchar();
	}
	return 0;
}


Measured memory_bytes: 2548
#t=int(input())
t=1
for i in range(t):
	x,y,z=map(int,input().split())
	ma=max(x,y,z)
	mi=min(x,y,z)
	if(x==ma):
		if(y<z):
			m=x-y
			n=x-z
		else:
			m=x-z
			n=x-y
	elif(y==ma):
		if(x<z):
			m=y-x
			n=y-z
		else:
			m=y-z
			n=y-x
	else:
		if(x<y):
			m=z-x
			n=z-y
		else:
			m=z-y
			n=z-x
	ans=n+(m-n)//2
	if((m-n)%2==1):
		ans+=2
	print(ans)
	


Measured memory_bytes: 3064
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import accumulate

    n, k = map(int, readline().split())
    item = [[] for _ in range(4)]
    cnt = [0] * 4

    w, v = map(int, readline().split())
    first = w
    item[0].append(v)
    cnt[0] += 1

    for i in range(n - 1):
        w, v = map(int, readline().split())
        item[w - first].append(v)
        cnt[w - first] += 1

    for i in range(4):
        item[i].sort(reverse=True)

    acc = [[0] + list(accumulate(item[i])) for i in range(4)]

    ans = 0
    for p in range(cnt[0] + 1):
        for q in range(cnt[1] + 1):
            for r in range(cnt[2] + 1):
                for s in range(cnt[3] + 1):
                    weight = (p + q + r + s) * first + q + 2 * r + 3 * s
                    if weight > k:
                        break
                    value = acc[0][p] + acc[1][q] + acc[2][r] + acc[3][s]
                    ans = max(ans, value)

    print(ans)


if __name__ == '__main__':
    main()


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

int n;
int m;
vector<int> x;
int mod[100010];
int same[100010];

int MOD(int num)
{
	return num % m;
}


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

	x.assign(n,0);

	for(int i = 0;i < n;i++)
	{
		cin >> x[i];
	}
	
	//can sort
	sort(x.begin(),x.end());

	mod[MOD(x[0])]++;
	int cou = 1;

	for(int i = 1;i < n;i++)
	{
		if(x[i - 1] == x[i])
		{
			same[MOD(x[i])]+=cou;
			cou = 1 - cou;
		}
		else
		{
			cou = 1;
		}
		mod[MOD(x[i])]++;
	}

	//make pair

	int result = 0;

	for(int i = 0;i < m;i++)
	{
		int j = MOD(m - i);
		if(i > j) break;
		int sub;
		if(i == j)
		{
			sub = mod[i] / 2;
			result += sub;
			mod[i] -= sub * 2;
		}
		else
		{
			sub = min(mod[i],mod[j]);

			result += sub;
			mod[i] -= sub;
			mod[j] -= sub;
		}

		//cout << i << ":sub=" << sub << endl;
	}

	for(int i = 0;i < m;i++)
	{
		int remain = mod[i];
		int pair_c = same[i] * 2;
		//cout << "r=" << remain << " pair=" << pair_c << endl;
		int sub = min(remain , pair_c) / 2;
		//cout << "sub=" << sub << endl;
		result += sub;
	}

	cout << result << endl;
	return 0;
}


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



int main(){
	long long A,B,C;
	cin>>A>>B>>C;
	if(A%2==0||B%2==0||C%2==0){
		cout<<0<<endl;
		return 0;
	}
	else{
		cout<<min({A*B,B*C,C*A})<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import sys

next(sys.stdin)

_, *langs = map(int, next(sys.stdin).strip().split())
common_langs = set(langs)

unreachable = list()
for line in sys.stdin:
    _, *langs = map(int, line.strip().split())
    unreachable.append(set(langs))

change = True
while change:
    change = False
    for langs in unreachable:
        if len(common_langs & langs) > 0:
            s = len(common_langs)
            common_langs.update(langs)
            change |= not s == len(common_langs)
            langs.clear()
    unreachable = list(langs for langs in unreachable if len(langs) > 0)

if len(unreachable) == 0:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 29324
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  int ans=0;
  for(int i=0;i<S.size();i++){
    int pre=0;
    if(S.at(i)=='A'||S.at(i)=='C'||S.at(i)=='G'||S.at(i)=='T'){
      pre++;
      for(int j=1;j<S.size()-i;j++){
       if(S.at(i+j)=='A'||S.at(i+j)=='C'||S.at(i+j)=='G'||S.at(i+j)=='T'){
         pre++;
       }
         else break;
       }
    ans=max(ans,pre);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <numeric>

const int N = 400 + 10;

int n, deg[N];

int anc[N], cnt[N], mask[N];

int find(int x) { return anc[x] == x ? x : (anc[x] = find(anc[x])); }

void init() {
  int m;
  scanf("%d%d", &m, &n);
  std::iota(anc, anc + 2 * n + 1, 0);
  while (m--) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    int x = c ? (c + n) : a, y = d ? d : (b + n);
    ++cnt[x], ++cnt[y];
    --deg[x], ++deg[y];
    anc[find(x)] = find(y);
  }
}

int main() {
  init();
  for (int i = 1; i <= n; ++i) if (deg[i] > 0 || deg[i + n] < 0) return puts("NO"), 0;
  for (int i = 1; i <= 2 * n; ++i) mask[find(i)] |= deg[i];
  for (int i = 1; i <= 2 * n; ++i) if (find(i) == i && cnt[i] && !mask[i]) return puts("NO"), 0;
  puts("YES");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long dp1[1<<17],dp2[1<<17],mod;
int n;
vector<int>G[1<<17];
vector<long>ret[1<<17];
long dfs1(int u,int p)
{
	dp1[u]=1;
	for(int i=0;i<G[u].size();i++)
	{
		if(G[u][i]!=p)
		{
			long t=(dfs1(G[u][i],u)+1)%mod;
			dp1[u]=dp1[u]*t%mod;
			ret[u].push_back(t);
		}
	}
	return dp1[u];
}
void dfs2(int u,int p,long x)
{
	dp2[u]=dp1[u]*(x+1)%mod;
	vector<long>L,R;
	long now=(x+1)%mod;
	L.push_back(now);
	for(long r:ret[u])L.push_back(now=now*r%mod);
	now=1;
	R.push_back(now);
	reverse(ret[u].begin(),ret[u].end());
	for(long r:ret[u])R.push_back(now=now*r%mod);
	reverse(R.begin(),R.end());
	int cnt=0;
	for(int i=0;i<G[u].size();i++)
	{
		if(G[u][i]!=p)
		{
			dfs2(G[u][i],u,L[cnt]*R[cnt+1]%mod);
			cnt++;
		}
	}
}
main()
{
	cin>>n>>mod;
	for(int i=1;i<n;i++)
	{
		int x,y;cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs1(1,0);
	dfs2(1,0,0);
	for(int i=0;i++<n;)cout<<dp2[i]<<endl;
}

Measured memory_bytes: 31360
#処理回数
p_number = int(input())
acgt_disc = {}

#処理の実行
for i in range(p_number):
    a,b = input().split()
    if a[0] == "i":
        acgt_disc[b] = 0
    else:
        if b in acgt_disc:
            print("yes")
        else:
            print("no")



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

#define Bye return 0
#define ll long long
const ll M = 1e9+7;
const ll SIZE = 2e5+1;
vector<ll> ps(SIZE, 0); 
int e;

int scan(){
    scanf("%d", &e);
    return e;
}

void solve(){
    ll n, res = 0; cin>>n;
    for (int i=1; i<=n; i++){
        ps[i] = (ps[i-1] + scan())%M;
        res = (res%M + (e*ps[i-1])%M)%M;
    }
    cout<<res<<endl;
}

int main(){
    solve();
    Bye;
}

Measured memory_bytes: 4676
#include <bits/stdc++.h>
using namespace std;
long sub(vector<long> v) {
  const int n = v.size();
  int ci = 0;
  for (int k = 60; k >= 0; --k) {
    int pi = -1;
    for (int i = ci; i < n; ++i) {
      if (v[i] & (1l << k)) {
        pi = i;
        break;
      }
    }
    if (pi == -1) continue;
    
    swap(v[ci], v[pi]);
    for (int i = 0; i < n; ++i) {
      if (i == ci) continue;
      if (v[i] & (1l << k)) {
        v[i] ^= v[ci];
      }
    }
    ++ci;
  }
  
  long ret = 0;
  {
    int ci = 0;
    for (int k = 60; k >= 0; --k) {
      if (!(v[ci] & (1l << k))) continue;
      if (!(ret & (1l << k))) {
        ret ^= v[ci];
      }
      ++ci;
    }
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  vector<long> a;
  for (int i = 0; i < n; ++i) {
    long tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  
  long sum = accumulate(a.begin(), a.end(), 0l, bit_xor<long>());
  vector<long> v;
  for (int i = 0; i < n; ++i) {
    v.push_back(a[i] & (~sum));
  }
  
  cout << (sum + 2 * sub(v)) << endl;
}


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

const int INF =1e9;
const int MOD =1e9+7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int dx[4] ={ 1, 0, -1, 0 };
int dy[4] ={ 0, 1, 0, -1 };

int main()
{
int n,k;
cin>>n>>k;
int ans=0;
while(n>0){
    n/=k;
    ans++;
}
cout<<ans<<endl;
}

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

int main(){
  int N,M;
  cin >>N>>M;
  vector<int> V(N+1,0);
  for(int i=0;i<M;++i){
    int L,R;
    cin >>L>>R;
    --L;
    V[L]+=1;
    V[R]-=1;
  }
  for(int i=0;i<N;++i){
    V[i+1]+=V[i];
  }
  int ans=0;
  for(int i=0;i<N;++i){
    if (V[i]==M){
      ++ans;
    }
  }
  cout <<ans<<endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
  int mas_count,roll_count;
  int ansers[5];
  
  for(int x = 0; x < 6; x++){
    scanf("%d%d",&mas_count,&roll_count);
     
    if(mas_count == 0){
      for(int i = 0; i < x; i++){
        printf("%d\n",ansers[i]);
      }
      return 0;
    }

    int mas_datas[mas_count]; 
    int dice_nums[roll_count];

    for(int i = 0; i < mas_count; i++) scanf("%d",&mas_datas[i]); 

    for(int i = 0; i < roll_count; i++) scanf("%d",&dice_nums[i]);
  
    int now_point = 1; 
    int roll_buff = 0;

    for(int i = 0;now_point < mas_count;i++){
      now_point += dice_nums[i];
      now_point += mas_datas[now_point - 1];
      roll_buff++; 
    }

    ansers[x] = roll_buff;
  }
}

Measured memory_bytes: 2572
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int i = 0; i <n; i++) 
 
int main(void){
   int a[5] ,s;s=0;std::cin >> a[0];
   for(int i=1;i<5;i++){
       std::cin >> a[i];s=max(s,a[i]-a[i-1]);
   }
   int k;
  std::cin >> k;
  if (a[4]-a[0]<=k)std::cout << "Yay!" << std::endl;
  else std::cout << ":(" << std::endl;
}

Measured memory_bytes: 256
module Main where

import Data.Functor

main :: IO ()
main = do
  { [a,b] <- getInts
  ; putInts [a*b, 2*(a+b)]
  }

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

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

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define acc_io cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define vvl vector<vector<ll>>
#define vl  vector<ll>
#define rep(i,sta,end) for(ll i=sta;i<end;i++)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||
int n;
signed main(){
	acc_io;
	cin>>n;
	ll sum=0;
	rep(i,1,n+1){
		if(i%3==0) continue;
		if(i%5==0) continue;
		sum+=i;
	}
	cout<<sum<<endl;
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  if(N >= 64){
    cout << 64 << endl;
  }
  if(N >= 32 && N < 64){
    cout << 32 << endl;
  }
  if(N >= 16 && N < 32){
    cout << 16 << endl;
  }
  if(N >= 8 && N < 16){
    cout << 8 << endl;
  }
  if(N >= 4 && N < 8){
    cout << 4 << endl;
  }
  if(N == 2 || N == 3){
    cout << 2 << endl;
  }
  if(N == 1){
    cout << 1 << endl;
  }
}


Measured memory_bytes: 256
H,W = list(map(int,input().split()))
MAP = [[i for i in input()] for j in range(H)]
count = sum([l.count(".") for l in MAP])
def exaustive_search(start_h,start_w):
  determined = {(start_h,start_w):0}
  f = lambda h,w: (0<=h<H and 0<=w<W) 
  
  q = [(start_h,start_w)]
  q_idx = 0
  while count != q_idx:
    h,w = q[q_idx]
    cost = determined[(h,w)]
    for dh,dw in [(-1,0),(1,0),(0,-1),(0,1)]:
      if f(h+dh,w+dw) and (h+dh,w+dw) not in determined.keys() and MAP[h+dh][w+dw]!="#":
        determined[(h+dh,w+dw)] = cost + 1
        q.append((h+dh,w+dw))
    q_idx+=1
  return max(determined.values())


print(max([exaustive_search(h,w) for h in range(H) for w in range(W) if MAP[h][w] !="#"]))

Measured memory_bytes: 46044
import numpy as np
n = int(input())

arr = map(int,raw_input().split())

cs = np.cumsum(arr)

to = [1,-1]

def digit(n):
	if n > 0:
		return 1
	elif n < 0:
		return -1
	else :
		return 0

tmp1 = 0
ans1 = 0
p = 0
for i in range(n):
	x = cs[i] + tmp1
	if digit(x) != to[p]:
		tmp1 += to[p] - x
		ans1 += abs(to[p] - x)

	p = (p+1)%2

tmp2 = 0
ans2 = 0
p = 1
for i in range(n):
	x = cs[i] + tmp2
	if digit(x) != to[p]:
		tmp2 += to[p] - x
		ans2 += abs(to[p] - x)
	p = (p+1) %2


print min(ans1,ans2)


Measured memory_bytes: 18740
#include<stdio.h>
#include<algorithm>
using namespace std;
using LL = long long;
int a[10000];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}

	LL sum = 0;
	int large = a[0];
	int small = a[0];
	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		large = max(large, a[i]);
		small = min(small, a[i]);
	}
	printf("%d %d %lld\n",small,large,sum);

	return 0;
}

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

int main()
{
    long a, b, n;
    cin >> a >> b >> n;
    if (n >= b)
    {
        n = b - 1;
    }
    long ans1 = a * n;
    ans1 /= b;
    long ans2 = n / b;
    ans2 *= a;
    long ans = ans1 - ans2;
    // scanf("%d", &x);
    // printf("%d\n", x * x * x);
    cout << ans << endl;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC143B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] dinput = Console.ReadLine().Split(' ');
            int[] d = new int[N];
            int sum = 0;
            for (int i = 0; i < N; i++)
            {
                d[i] = int.Parse(dinput[i]);
            }
            for(int i = 0; i < N - 1; i++)
            {
                for(int j = i + 1; j < N; j++)
                {
                    sum += d[i] * d[j];
                }
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 27500
#include <iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  if(n%10==3)cout<<"bon"<<endl;
  else if(n%10==0 or n%10==1 or n%10==6 or n%10==8)cout<<"pon"<<endl;
  else cout<<"hon"<<endl;
  return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<stdlib.h>
int main(){
long long int n,k,j;
scanf("%lld%lld", &n, &k);
  
  j=n%k;
  if(llabs(j-k)>j){
    printf("%lld\n",j);
    return 0;
  }

printf("%lld\n",llabs(j-k));
return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
	int a, b, n;
	int ans;
	int i;

	while(scanf("%d %d %d", &a, &b, &n) != EOF) {
		for(i = 0, ans = 0; i < n; i++) {
			a %= b;
			a *= 10;
			ans += a / b;
		}

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

	return 0;
}

Measured memory_bytes: 596
#include <iostream>

using namespace std;

int main()
{
    int n;
    int a[100050];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int sum=0;
    for(int i=n-2;i>=0;i--)
    {
        if(a[i]>a[i+1]){
            sum=a[i]-a[i+1];
            a[i]=a[i+1];
        }
        if(sum>1) break;
    }
    if(sum>1) cout<<"No"<<endl;
    else      cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>

using namespace std;

int main(void) {

	long double a, b, h, m, s, l, ang, c2, ans;
	
	cin >> a >> b >> h >> m;

	s = (60.0 * h + m) / 360.0 * 3.14159265358979323846;
	l = m / 30.0 * 3.14159265358979323846;

	if (s == l) {
		if (b>=a) ans = b - a;
		else ans = a - b;
	}
	else if (s > l) {
		ang = s - l;
		c2 = a * a + b * b - 2 * a * b * cosl(ang);
		ans = sqrtl(c2);
	}
	else {
		ang = l - s;
		c2 = (a * a) + (b * b) - (2 * a * b * cosl(ang));
		ans = sqrtl(c2);
	}
	
	cout << setprecision(20) << ans;


	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ll long long
#define EPS 1e-9
#define rank asadf
using namespace std;

const int MAXN = 3e5 + 111;
const int MOD = 1e9 + 7;

int a[MAXN];

int main() {
#ifdef LOCAL
    freopen("xxx.in", "r", stdin);
    freopen("xxx.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (i) {
            ans += max(0, a[i - 1] - a[i]);
            a[i] = max(a[i - 1], a[i]);
        }
    }
    cout << ans;
    return 0;
}

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

using namespace std;

int main(void) {
  int n, m; cin >> n >> m;
  int P[m], Y[m]; // 入力の保持
  vector<int> createY[n]; // 県別の市誕生年
  
  for (int i = 0; i < m; i++) {
    int p, y; cin >> p >> y;
    createY[p-1].push_back(y);
    P[i] = p;
    Y[i] = y;
  }

  for (int i = 0; i < n; i++) {
    if (!createY[i].empty())
      sort(createY[i].begin(), createY[i].end());
  }
  
  for (int i = 0; i < m; i++) {
    printf("%06d%06zu\n",
            P[i],
            1 + distance(createY[P[i]-1].begin(), lower_bound(createY[P[i]-1].begin(), createY[P[i]-1].end(), Y[i])));
  }
  
  return 0;
}

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

#define endl '\n'

using namespace std;

long long N,W;

long long w[101];
long long v[101];

long long dp[101][100001];

long long ans(int i,long long bag){

  if(dp[i][bag]!=-1){
    return dp[i][bag];
  }
  
  if(i==N){
    return dp[i][bag]=0;
  }else{
    long long ret;
    if(bag>=w[i]){
      ret= max(ans(i+1,bag-w[i])+v[i],ans(i+1,bag));
    }else{
      ret=ans(i+1,bag);
    }

    return dp[i][bag]=ret;
  }
}

int main(){

  memset(dp,-1,sizeof(dp));
  
  cin>>N>>W;

  for(int i=0;i<N;i++){
    cin>>w[i]>>v[i];
  }

  cout<<ans(0,W)<<endl;
  
  return 0;

}


Measured memory_bytes: 79104
#include<stdio.h>
int main(void){
  int a=0;
  int n;
  int d[n];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&d[i]);
  }for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      a=a+d[i]*d[j];
    }
  }
  printf("%d",a);
  return 0;
}


Measured memory_bytes: 128
n,m=map(int,input().split())
a=sorted([int(i) for i in input().split()])
bc=[list(map(int,input().split())) for _ in range(m)]
bc=sorted(bc,key=lambda x : x[1],reverse=True)
min_a=min(a)
count=0
for b,c in bc:
    if min_a >=c and count>=n:
        break
    else:
        l=min(b,n-count)
        for i in range(l):
            count+=1
            a.append(c)
a.sort()
print(sum(a[count:]))

Measured memory_bytes: 35020
from sys import stdin
import numpy as np
n, m = (int(i) for i in input().rstrip().split())
# print(n)
vals_list = np.zeros((n, 2))
# print(vals_list)
for itr in range(n):
    a, b = (int(i) for i in input().rstrip().split())
    vals_list[itr][0], vals_list[itr][1] = a, b
sorted_vals_list = vals_list[np.argsort(vals_list[:, 0])]
# print(sorted_vals_list)

cnt = m
total_money = 0
for itr in range(n):
    if (cnt - sorted_vals_list[itr][1]) <= 0:
        total_money += sorted_vals_list[itr][0] * cnt
        break
    else:
        cnt -= sorted_vals_list[itr][1]
        total_money += sorted_vals_list[itr][0] * sorted_vals_list[itr][1]
print(int(total_money))


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

int s[1000], d[1000], y[1000];
P p[100000];
int main() {
	int n, m, h, k;
	while (scanf("%d%d%d%d", &n, &m, &h, &k), n) {
		rep(i, n)scanf("%d", &s[i]);
		rep(i, m) {
			int a, b; scanf("%d%d", &a, &b);
			p[i] = { b,a };
		}
		sort(p, p + m); iota(d, d + n, 0);
		rep(i, m) {
			swap(d[p[i].second - 1], d[p[i].second]);
			p[i] = { d[p[i].second - 1],d[p[i].second] };
			if (p[i].first > p[i].second)swap(p[i].first, p[i].second);
		}
		rep(i, n)y[d[i]] = s[i];
		int M = accumulate(y, y + k, 0); int S = M;
		rep(i, m) {
			if (p[i].first < k&&p[i].second >= k)
				M = min(M, S + y[p[i].second] - y[p[i].first]);
		}
		printf("%d\n", M);
	}
}

Measured memory_bytes: 3908
import sys


def main():
  n, m = map(int, sys.stdin.readline().split())
  lst = map(int, sys.stdin.read().split())
  set1, setn = set(), set()
  for i, j in zip(lst, lst):
    if i == 1:
      set1.add(j)
    if j == n:
      setn.add(i)
  if set1 & setn:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')


if __name__ == '__main__':
  main()

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define size_of(a) (int)(a).size()

class KMP {
private:
	vector< int > fail;
	
public:
	KMP() {}
	
	int match(string t, string p) {
		int n = size_of(t), m = size_of(p);
		
		fail.assign(m + 1, 0);
		int j = fail[0] = -1;
		
		for_(i,1,m+1) {
			while (j >= 0 && p[j] != p[i - 1]) j =fail[j];
			fail[i] = ++j;
		}
		
		int count = 0;
		
		for (int i = 0, k = 0; i < n; ++i) {
			while (k >= 0 && p[k] != t[i]) k = fail[k];
			if (++k >= m) {
				++count;
				k = fail[k];
			}
		}
		
		return count;
	}
};

int main() {
	int n, m;
	string s;
	
	while (cin >> n, n) {
		cin >> m;
		cin >> s;
	
		int N = 2 * n + 1;
		string p = "";
	
		for_(i,0,N) p += (i % 2) ? 'O' : 'I';
		
		cout << KMP().match(s, p) << endl;
	}
}

Measured memory_bytes: 3168
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map(String::toInt)
    val combi = Combination(N)
    var ans = MInt(1)
    var s = 0
    repeat(M) {
        val g = readLine()!!.toInt()
        ans *= calc(s, g, combi)
        s = g + 1
    }
    ans *= calc(s, N + 1, combi)
    println(ans)
}

fun calc(s: Int, g: Int, combi: Combination): MInt {
    if (s == g) return MInt(0)
    var ans = MInt(0)
    var n = g - s - 1
    var k = 0
    while (n >= k) {
        ans += combi(n, k)
        n--
        k++
    }
    return ans
}

class MInt {
    private val MOD = 1000000007L
    var v: Long

    constructor(v: Long) {
        this.v = v % MOD
    }

    constructor(v: Int) {
        this.v = v.toLong() % MOD
    }

    operator fun plus(b: MInt): MInt {
        val a = MInt(v)
        a.v += b.v
        if (a.v >= MOD) a.v -= MOD
        return a
    }

    operator fun plus(b: Int) = plus(MInt(b))
    operator fun plus(b: Long) = plus(MInt(b))

    operator fun minus(b: MInt): MInt {
        val a = MInt(v)
        a.v -= b.v
        if (a.v < 0) a.v += MOD
        return a
    }

    operator fun minus(b: Int) = minus(MInt(b))
    operator fun minus(b: Long) = minus(MInt(b))

    operator fun times(b: MInt): MInt {
        val a = MInt(v)
        a.v *= b.v
        a.v %= MOD
        return a
    }

    operator fun div(b: MInt): MInt {
        return MInt(v) * b.inv()
    }

    fun inv(): MInt {
        var a = v
        var b = MOD
        var u = 1L
        var w = 0L
        while (b != 0L) {
            val t = a / b
            a -= t * b
            u -= t * w
            var tmp = a
            a = b
            b = tmp
            tmp = u
            u = w
            w = tmp
        }
        u %= MOD
        if (u < 0) u += MOD
        return MInt(u)
    }

    fun pow(N: Int) = pow(N.toLong())

    fun pow(N: Long): MInt {
        var ans = MInt(1)
        var a = this
        var n = N
        while (n > 0) {
            if (n.and(1) == 1L) {
                ans *= a
            }
            a *= a
            n = n.shr(1)
        }
        return ans
    }

    override fun toString(): String {
        return v.toString()
    }
}

class Combination(n: Int) {
    private val fact = Array<MInt?>(n + 1) { null }
    private val ifact = Array<MInt?>(n + 1) { null }

    init {
        fact[0] = MInt(1)
        (1..n).forEach { i -> fact[i] = fact[i - 1]!! * MInt(i) }
        ifact[n] = fact[n]!!.inv()
        (n downTo 1).forEach { i -> ifact[i - 1] = ifact[i]!! * MInt(i) }
    }

    operator fun invoke(n: Int, k: Int): MInt {
        if (k < 0 || n < k) return MInt(0)
        return (fact[n]!! * ifact[k]!! * ifact[n - k]!!)
    }
}

Measured memory_bytes: 50244
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
void chmin(int &a, int b) { if (a > b) a = b; }
const int INF = 1<<29;

int N, A, B, C;
vector<int> L;

int rec(int i, int a, int b, int c) {
    // 終端処理
    if (i == N) {
        if (!a || !b || !c) return INF; // A, B, C いずれも竹は 1 本は必ず使ってないとダメ
        return abs(a - A) + abs(b - B) + abs(c - C); // 合体してできた a, b, c を A, B, C にするコスト
    }

    // 今ある竹を採用しない場合
    int res = INF;
    chmin(res, rec(i+1, a, b, c));
    
    // A, B, C を使う場合
    chmin(res, rec(i+1, a + L[i], b, c) + (a ? 10 : 0));
    chmin(res, rec(i+1, a, b + L[i], c) + (b ? 10 : 0));
    chmin(res, rec(i+1, a, b, c + L[i]) + (c ? 10 : 0));
    
    return res;
}

int main() {
    // 入力
    cin >> N >> A >> B >> C;
    L.resize(N); for (int i = 0; i< N; ++i) cin >> L[i];
    
    // 再帰する
    cout << rec(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
n = int(input())
als = list(map(int, input().split()))

als.sort()

my_dict = dict()

for item in als:
    if item in my_dict:
        my_dict[item] += 1
    else:
        my_dict[item] = 1


ret = 0
for item in my_dict:
    val = my_dict[item]
    if val < item:
        ret += val
    else:
        ret += (val - item)

print(ret)


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

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  ll res = 0;
  if (a == 0) res = b / x + 1;
  else res = b / x - (a - 1) / x;
  cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#define MOD 1000000007
using namespace std;
int main()
{
	long int n, a, b;
	cin >> n >> a >> b;
	cout << (n / (a + b) * a + min(n % (a + b), a)) << endl;

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i64 = int64_t;
constexpr char newl = '\n';

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = (b-1); i >= a; i--)
#define RF0(i,b) RFO(i,0,b)
#define F first
#define S second
#define debug(x) cout << #x << ": " << x << '\n';

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int S, W;
  cin >> S >> W;
  cout << (W >= S ? "unsafe" : "safe");
}


Measured memory_bytes: 3648
x,n = map(int,input().split())
pl = list(map(int,input().split()))
if n == 0:
  print(x)
  exit()
for i in range(100):
  if not x-i in pl:
    print(x-i)
    exit()
  if not x+i in pl:
    print(x+i)
    exit()

Measured memory_bytes: 9008
#include<stdio.h>
int main (void)
{
    int N;
    int A;
    int i,j,k = 0;
    scanf("%d",&N);
    for(i = 0;i < N;i++){
        scanf("%d",&A);
        while(A % 2 == 0){
            A /= 2;
            ++k;
            //printf("%d\n",k);
        }
        if(i == 0){
            j = k;
        }
        else if(j > k){
            j = k;
        }
        k = 0;
    }
    printf("%d\n",j);


    return 0;
}


Measured memory_bytes: 128
#include <math.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <ostream>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int _lcint;
#define REP(i, n) for (_lcint i = 0; i < n; i++)
#define FOR(i, a, b) for (_lcint i = (_lcint)(a); i < (_lcint)(b); i++)
#define FORREV(i, a, b) for (_lcint i = (_lcint)(b)-1; i >= (_lcint)(a); i--)
#define DEBUG(x) cout << #x << ": " << x << endl;
#define DEBUG_VEC(v)  \
  cout << #v << ": "; \
  REP(i, v.size()) cout << " " << v[i] << endl;

#define ALL(a) (a).begin(), (a).end()
#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = max((a), (b))

// permutation
ll mPn(ll m, ll n) {
  ll a = 1;
  REP(i, n) { a *= m - i; }
  return a;
}

// excrametion
ll exc(ll m) {
  ll a = 1;
  FOR(i, 1, m) { a *= i + 1; }
  return a;
}

// combination
ll mCn(ll m, ll n) {
  ll a = 1, b = 1;
  REP(i, n) {
    a *= m - i;
    b *= n - i;
  }
  return a / b;
}

// 最大公約数を求める 条件
ll eculidean(ll a, ll b) {
  ll c = max(a, b) % min(a, b);
  if (c == 0) {
    return b;
  }
  return eculidean(b, c);
}

int main() {
  int N;
  cin >> N;
  ll A[N];
  ll m = 0;
  bool odd = false;
  REP(i, N) {
    cin >> A[i];
    if (A[i] < 0) {
      odd = !odd;
    }

    A[i] = abs(A[i]);
    if (i == 0) {
      continue;
    }
    if (A[m] > A[i]) {
      m = i;
    }
  }

  ll total = 0;

  REP(i, N) { total += A[i]; }
  if (odd) {
    total -= A[m] * 2;
  }

  cout << total << endl;

  return 0;
}

Measured memory_bytes: 1024
import math
a, b, c = map(int, input().split())

c = math.radians(c)
s = a * b * math.sin(c) / 2
d = math.sqrt(a**2 + b**2 - 2*(a * b * math.cos(c)))
h = b * math.sin(c)

for i in (s, a+b+d, h):
    print(i)


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

int main() {
  int n;
  cin>>n;
  int A[n];
  double sum=0;
  rep(i,n){cin>>A[i];
          }
  rep(i,n){ sum+=1.0/A[i];  }
  cout<<fixed<<setprecision(15)<<1/sum<<endl;
  
    
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<lli,int> lmp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

int n;
lmp dat[100005];

lli ans[100005]={};

int main(void){
	scanf("%d",&n);
	rep(i,n){
		lli a;
		scanf("%lld",&a);
		dat[i]=lmp(a,i);
	}
	dat[n]=lmp(0,-1);
	sort(dat,dat+n,greater<lmp>());
	
	lli mx=dat[0].fir;
	int mmin = IINF;
	lli nr=0;
	rep(i,n+1){
		lli x = dat[i].fir;
		int d = dat[i].sec;
		if(mx!=x){
			ans[mmin] += (mx-x) * nr;
			mx=x;
		}
		nr++;
		mmin = min(mmin,d);
	}
	
	rep(i,n){
		printf("%lld\n",ans[i]);
	}
	return 0;
}






Measured memory_bytes: 3456