akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	int n, m; cin >> n >> m;

	int s = n + m;
	int ans = s / 2;


	if ((s) % 2 == 0) {
		cout << ans<< endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}

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

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
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;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long X, Y, A, B, C;
    scan(X, Y, A, B, C);
    auto P = aryread();
    auto Q = aryread();
    auto R = aryread();
    auto pqr = P ~ Q ~ R;
    auto idx = new long[](A + B + C);
    idx[0 .. A] = 2;
    idx[A .. A + B] = 1;
    idx[A + B .. $] = 0;
    zip(pqr, idx).sort!"b<a"();
    auto remain = [-1, Y, X];
    long wild;
    long i;
    long ans;
    while (true)
    {
        if (remain[1] + remain[2] == wild)
        {
            writeln(ans);
            return;
        }
        if (remain[idx[i]] == 0)
        {
            i++;
            continue;
        }
        // writefln("%s %s %s %s", idx[i], pqr[i], remain, wild);
        if (idx[i] == 0)
            wild++;
        remain[idx[i]]--;
        ans += pqr[i];
        i++;
    }
}


Measured memory_bytes: 18644
#include<bits/stdc++.h>
using namespace std;
int b[101], del[101];
int main()
{
    int n; scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
    stack<int>ans;
    vector<int>vec;
    for (int k = 1; k <= n; k++)
    {
        vec.clear();
        for (int i = 1, cnt = 0; i <= n; i++)
        {
            if (del[i]) continue;
            cnt++; if (b[i] == cnt) vec.push_back(i);
        }
        if (!vec.size()) {puts("-1"); return 0;}
        ans.push(b[*vec.rbegin()]); del[*vec.rbegin()] = 1; 
    }
    while (ans.size()) printf("%d\n", ans.top()), ans.pop();
    return 0;
}

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

typedef long long LL;

int read(){
    int w=0;char ch=getchar();
    while(!isdigit(ch))ch=getchar();
    for(;isdigit(ch);ch=getchar())w=w*10+(ch^48);
    return w;
}
int max(int x,int y){return x>y?x:y;}

const int N=505;

int n,mod;
int l[N],r[N],v[N],v2[N];
LL f[N][N];
int sorted[N];
LL ans;

bool cmp(int x,int y){
    if(v[x]==v[y])return v2[x]<v2[y];
    return v[x]<v[y];
}

int main(){
    n=read();mod=read();
    int topl=n*n-1,topr=2*n*2*n;
    for(int i=2*n-1;i>=0;--i){
        for(int j=0;j<2*n;++j){
            if(i*i+j*j<=topr){
                r[i]=j;
            }
        }
        for(int j=0;j<2*n;++j){
            if(i*i+j*j<=topl){
                l[i]=j;
            }
        }
        sorted[i] = i;
        v[i] = (i < n ? l[i] : r[i]);
        v2[i] = (i < n ? r[i] : 0);
    }
    std::sort(sorted,sorted+2*n,cmp);
    for(int k=0,s=1;k<=n;++k,s*=-1){
        f[0][0] = 1;
        int cnt = 0;
        for(int i=1;i<=2*n;++i){
            int w = sorted[i-1];
            if(w<n){
                f[i][0] = (f[i-1][0] * (r[w] + 1 - (2*n-1 - w + k))) % mod;
                for(int j=1;j<=k;++j){
                    f[i][j] = (f[i-1][j-1] * (l[w] + 1 - (i - 1 - (cnt - (j - 1))))
                              +f[i-1][j] * (r[w] + 1 - (2*n-1 - w + (k - j)))) % mod;
                }
                ++cnt;
            }else{
                for(int j=0;j<=k;++j){
                    f[i][j] = (f[i-1][j] * (r[w] + 1 - (i - 1 - (cnt - j)))) % mod;
                }
            }
        }
        ans = (ans + s*f[2*n][k] + mod) % mod;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2176
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("-1"),0;
#define N 5055
#define M 205
#define int ll
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,a[N],b[N][M],g[N][N],tot,z[N],l[N],r[N],ans;
signed main(){
	n=read();m=read();
	F(i,2,n) a[i]=read()+a[i-1];
	F(i,1,n) F(j,1,m) b[i][j]=read();
	F(j,1,m){
		tot=0;z[0]=0;
		F(i,1,n){
			while (tot&&b[z[tot]][j]<b[i][j]) tot--;
			l[i]=z[tot]+1;z[++tot]=i;
		}
		tot=0;z[0]=n+1;
		D(i,n,1){
			while (tot&&b[z[tot]][j]<b[i][j]) tot--;
			r[i]=z[tot]-1;z[++tot]=i;
		}
		F(i,1,n){
			g[l[i]][i]+=b[i][j];
			g[l[i]][r[i]+1]-=b[i][j];
			g[i+1][i]-=b[i][j];
			g[i+1][r[i]+1]+=b[i][j];
		}
	}
	F(i,1,n){
		F(j,1,n) g[i][j]+=g[i][j-1];
		F(j,1,n) g[i][j]+=g[i-1][j];
		F(j,i,n) ans=max(ans,g[i][j]-a[j]+a[i]);
	}
	wrn(ans);
	return 0;
}

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

lli connectednum(vector<vector<lli>> &g){
    lli n = g.size();
    vector<lli> seen(n);
    lli ret = 0;
    function<void(int)> dfs = [&](lli x){
        if(seen[x]) return;
        seen[x] = true;
        rep(j, g[x].size()){
            dfs(g[x][j]);
        }
    };
    rep(i, n){
        if(!seen[i]){
            dfs(i);
            ret++;
        }
    }
    return ret;
}

lli n, m;

int main(void){
    cin >> n >> m;
    vector<vector<lli>> g(n);
    vector<pair<lli, lli>> e(m);
    rep(i, m){
        lli a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
        e[i] = {a, b};
    }
    lli ans = 0;
    rep(i, m){
        lli a, b;
        a = e[i].first;
        b = e[i].second;
        g[a].erase(find(g[a].begin(), g[a].end(), b));
        g[b].erase(find(g[b].begin(), g[b].end(), a));
        if(connectednum(g) > 1) ans++;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	string A, B, C;
	cin >> A >> B >> C;

	if(A.back() == B[0] && B.back() == C[0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

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

using namespace std;

const int N   = 1e5 + 5;
const int INF = 2e9;

int jump[N];
int h[N];
int n;

main(){

    scanf("%d" , &n);
    for(int i = 0 ; i < n ; i ++){
            scanf("%d" , &h[i]);
    }

    for(int i = 0 ; i < n ; i ++){
            jump[i] = INF;
    }

    jump[0] = 0;
    for(int i = 1 ; i < n ; i ++){

            jump[i] = min(jump[i] , abs(h[i] - h[i-1]) + jump[i-1]);

            if(i - 2 >= 0){
                    jump[i] = min(jump[i] , abs(h[i] - h[i-2]) + jump[i-2]);
            }
    }

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

    return 0;
}


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

typedef long long ll;

int main() {
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		long a, b; cin >> a >> b;

		long r = (long)sqrt(a * b), ans = r * 2;
		if (a != b) ans--;
		if (a * b <= r * r) ans--;
		if (a * b <= r * (r + 1)) ans--;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N; cin >> N;
  map<string, int> m;
  char last;
  bool ok = true;
  rep(i,N) {
    string w; cin >> w;
    if (i > 0 && w[0] != last) ok = false;
    last = w.back();
    m[w]++;
    if (m[w] > 1) ok = false; 
  }
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;

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

  int64_t x, k, d;
  cin >> x >> k >> d;

  x = abs(x);
  int64_t def = min(x / d, k);
  k -= def;
  x -= (def * d);

  bool even = true;
  if (k % 2 == 1) {
    even = false;
  }

  int64_t ans = x;
  if (even == false) {
    ans = abs(x - d);
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3636
#include"bits/stdc++.h"
using namespace std;

const long long MOD = 1000000007;
long long dp[110][10];

void Main() {
  int h, w, k;
  cin >> h >> w >> k;

  dp[0][1] = 1;
  for (int i = 2; i <= w; i++) dp[0][i] = 0;
  for (int i = 1; i <= h; i++) {
    dp[i][0] = 0;
    dp[i][w + 1] = 0;
  }

  for (int i = 1; i <= h; i++) {
    for (int j = 0; j < (1 << (w - 1)); j++) {
      int bou[w + 1];
      bou[0] = 0;
      bou[w] = 0;
      for (int k = 0; k < (w - 1); k++) {
        if (j & (1 << k)) bou[k + 1] = 1;
        else bou[k + 1] = 0;
      }
      bool invalid = false;
      for (int k = 1; k < (w - 1); k++) {
        if (bou[k] == 1 && bou[k + 1] == 1) {
          invalid = true;
          break;
        }
      }
      if (invalid) continue;
      /*
      cout << "|";
      for (int k = 0; k <= w; k++) {
        cout << bou[k];
      }
      cout << "|";
      cout << endl;
      */

      for (int k = 1; k <= w; k++) {
        if (bou[k - 1]) dp[i][k] += dp[i - 1][k - 1];
        if (bou[k - 1] == 0 && bou[k] == 0)  dp[i][k] += dp[i - 1][k];
        if (bou[k]) dp[i][k] += dp[i - 1][k + 1];
        dp[i][k] %= MOD;
      }
    }
    /*
    for (int j = 1; j <= w; j++) {
      cout << dp[i][j] << " ";
    }
    cout << endl;
    cout << endl;
    */
  }
  cout << dp[h][k] << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include<bits/stdc++.h> 
#define pb          push_back 
#define endl        "\n"
#define mostrar(x,y) cout<<x<<" "<<y<<endl;
#define f           first
#define s           second
using namespace std;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<pair<int,int>,int> iii;


int main(){
    ofstream out("output.txt");

    int n,k;
    cin>>n>>k;
    string cad;
    cin>>cad;
    char aux;
    for(int i = 0; i<n; i++){
        if(i == k-1){
            aux = tolower(cad[i]);
            cout<<aux;
        }
        else{
            cout<<cad[i];
        }
    }
    cout<<endl; 



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  string s; cin >> s;
  int r = 0;
  for (char c: s) {
    r += (c - '0');
    r %= 9;
  }
  cout << (r == 0 ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, M, K, A, B, C, D[100000], vis[100000];
map<int, vector<pair<int,bool>>>v[100000];
queue<int>q;


void dfs(int x, int a, int t) {
	vector<pair<int,bool>>&V = v[x][a];
	for (int i = 0; i < V.size(); ++i) {
		if (!V[i].second) {
			V[i].second = true;
			if (D[V[i].first] == t + 1 && vis[V[i].first] != a) {
				vis[V[i].first] = a;
				dfs(V[i].first, a, t);
			}
			if (D[V[i].first] == -1) {
				D[V[i].first] = t + 1;
				q.push(V[i].first);
				dfs(V[i].first, a, t);
			}
		}
	}
}

int main() {
	cin >> N >> M;
	while (M--) {
		cin >> A >> B >> C;
		--A;
		--B;
		v[A][C].push_back(mkp(B, false));
		v[B][C].push_back(mkp(A, false));
	}
	memset(D, -1, sizeof D);
	D[0] = 0;
	q.push(0);
	while (!q.empty()) {
		int x = q.front();
		q.pop();
		for (auto it = v[x].begin(); it != v[x].end(); ++it) {
			dfs(x, it->first, D[x]);
		}
	}
	cout << D[N - 1] << endl;
}


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

const int maxn=62;
char ch[maxn];
int val[maxn],ord[maxn];

bool cmp(int a,int b){
	return val[a]<val[b];
}

int query(string s){
	printf("? %s\n",s.c_str());
	fflush(stdout);
	int x;scanf("%d",&x);
	return x;
}

int main(){
	for(int i=0;i<26;i++)ch[i]=i+'a';
	for(int i=0;i<26;i++)ch[i+26]=i+'A';
	for(int i=0;i<10;i++)ch[i+52]=i+'0';
	val[0]=query(string(1,ch[0]))+1;
	int L=val[0];
	for(int i=1;i<maxn;i++){
		val[i]=query(string(1,ch[i]))+1;
		if(val[i]!=val[0]){
			L=min(val[i],val[0]);
			break;
		}
	}
	for(int i=0;i<maxn;i++)
		val[i]=L-query(string(L,ch[i])),ord[i]=i;
	sort(ord,ord+maxn,cmp);
	string ans="";
	for(int i=0;i<maxn;i++)if(val[ord[i]]){
		char c=ch[ord[i]];
		int R=int(ans.size())-1;
		vector<int>pos;
		for(int j=1;j<=val[ord[i]];j++){
			int l=-1,r=R;
			while(l<r){
				int mid=l+r+1>>1;
				if(query(ans.substr(0,mid+1)+string(j,c))==L-(mid+1)-j)l=mid;
				else r=mid-1;
			}
			pos.push_back(l);
			R=l;
		}
		string nans="";
		reverse(pos.begin(),pos.end());
		for(int j=0;j<int(pos.size());j++){
			int prv=!j?0:(pos[j-1]+1);
			if(prv<=pos[j])nans+=ans.substr(prv,pos[j]-prv+1);
			nans+=string(1,c);
		}
		if(pos.back()+1<int(ans.size()))nans+=ans.substr(pos.back()+1);
		ans=nans;
	} 
	printf("! %s\n",ans.c_str());
	fflush(stdout);
	return 0;
} 

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

int N, W;
long long dp[110][100100] = {0};
long long w, v;
int main() {
    cin >> N >> W;

    for (int i=1; i<=N; ++i) {
        cin >> w >> v;
        for (int j=0; j<=W; ++j) {
            if (j < w) dp[i][j] = dp[i-1][j];
            else dp[i][j] = max(dp[i-1][j-w] + v, dp[i-1][j]);
        }
    }
    long long int ans = 0;
    for (int i=0; i<=W; ++i) ans = max(ans, dp[N][i]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;

int main() {
    int x; cin >> x;
    int limit = sqrt(x);
    int ans = 1;
    for (int i = 2; i <= limit; i++) {
        int y = i;
        int z = y;
        while (z * y <= x) {
            z *= y;
        }
        chmax(ans, z);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
n = int(input())
length = list(map(int, input().split()))
length = sorted(length)
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        insert_index = bisect.bisect_left(length, length[i]+length[j])
        count += insert_index-j-1               
print(count)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll gcd (ll a, ll b) {
    return b ? gcd (b, a % b) : a;
}
int main()
{
    ll n,m;
    cin>>n>>m;
    bool dp[n+1][n+1];
    for(int x=0;x<=n;x++)
    for(int y=0;y<=n;y++)
    dp[x][y]=true;
    bool k=true;
    ll g=0;
    if(m>0)
    {for(int y=1;y<=n-1;y++)
    {
     for(int x=y+1;x<=n-1;x++)
        {dp[y][x]=false;
          ++g;
        if(g==m)
            break;
        }
        if(g==m)
            break;
    }
    }
    if(m>((((n-2)*(n-1))/2)))
        k=false;
    if(k)
    {cout<<(n*(n-1))/2-m<<endl;
    for(int x=1;x<=n;x++)
    for(int y=x+1;y<=n;y++)
        if(dp[x][y])
        cout<<x<<" "<<y<<endl;
    }
    else
        cout<<-1<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
using D = pair<double, double>;
const int mod2 = 998244353;
const int mod = (int)1e9 + 7, inf = (int)1e16;

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] *= fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	int ans= fact[n] * modpow(fact[n - r], mod - 2) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

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

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

map<int, int>factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

P operator+(const P& a, const P& b) {
	return P(a.first + b.first, a.second + b.second);
}
P operator-(const P& a, const P& b) {
	return P(a.first - b.first, a.second - b.second);
}

class unionfind {
private:
	int par[200010], rankth[200010], sizeth[200020];
public:
	void init(int n) {
		rep(i, n) {
			par[i] = i;
			rankth[i] = 0;
			sizeth[i] = 1;
		}
	}
	int root(int x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) return;
		if (rankth[x] < rankth[y]) {
			par[x] = y;
			sizeth[y] += sizeth[x];
		}
		else {
			par[y] = x;
			if (rankth[x] == rankth[y]) rankth[x]++;
			sizeth[x] += sizeth[y];
		}
	}
};

int n, m, k, l;
unionfind uni;
vector<int>v[100010];
signed main() {
	scanf("%lld %lld", &n, &m);
	uni.init(n + m);
	rep(i, n) {
		scanf("%lld", &k);
		rep(j, k) {
			scanf("%lld", &l);
			v[i].push_back(l);
		}
	}
	rep(i, n) {
		for (int j : v[i]) {
			uni.unite(i, n + j - 1);
		}
	}
	rep(i, n - 1) {
		if (!uni.same(i, i + 1)) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
}

Measured memory_bytes: 11520
#include<iostream>
        #include <set>
         
        using namespace std;
         
        int main(){
          int a;
          cin>>a;
          
          set<int> values;
          int ans = a;
          
          while(values.count(ans) == 0){
            values.insert(ans);
            if(ans%2==0){
              ans = ans / 2;
            }else{
              ans = 3 * ans + 1;
            }
          }
          cout << values.size() + 1 << endl;
          return 0;
        }

Measured memory_bytes: 256
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 5
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}

	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	bb := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	yy := &ysp49{}
	heap.Init(yy)
	for i := 0; i < n; i++ {
		bb[i] = getNextInt(scanner)
		heap.Push(yy, newy(bb[i], i))
	}

	c := int64(0)
	for yy.Len() > 0 {
		p := heap.Pop(yy).(ysp48)
		if bb[p.i] <= aa[p.i] {
			continue
		}
		if bb[p.i] <= bb[(p.i-1+n)%n] {
			continue
		}
		if bb[p.i] <= bb[(p.i+1+n)%n] {
			continue
		}
		s := bb[(p.i-1+n)%n] + bb[(p.i+1+n)%n]
		if bb[p.i] <= s {
			continue
		}
		if s == 0 {
			continue
		}
		if (bb[p.i]-aa[p.i])/s == 0 {
			continue
		}
		c += int64((bb[p.i] - aa[p.i]) / s)
		bb[p.i] = aa[p.i] + (bb[p.i]-aa[p.i])%s
		heap.Push(yy, newy(bb[p.i], p.i))
	}

	if isok(aa, bb, n) {
		fmt.Fprintln(writer, c)
		return
	}
	fmt.Fprintln(writer, -1)
}

func isok(aa, bb []int, n int) bool {
	for i := 0; i < n; i++ {
		if aa[i] != bb[i] {
			return false
		}
	}

	return true
}
func newy(v, i int) ysp48 {
	return ysp48{
		v: v,
		i: i,
	}
}

type ysp48 struct {
	v, i int
}

type ysp49 []ysp48

func (h ysp49) Len() int           { return len(h) }
func (h ysp49) Less(i, j int) bool { return h[i].v > h[j].v }
func (h ysp49) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
func (h *ysp49) Push(x interface{}) {
	*h = append(*h, x.(ysp48))
}
func (h *ysp49) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back


int main(void){
  int n, a, b;
  string s;
  cin >> n >> a >> b;
  cin >> s;
  int A=0,B=0;
  const string yes = "Yes";
  const string no = "No";
  rep(i,n){
    if(s[i] == 'a'){
      if(A+B<a+b){
        A++;
        cout << yes << endl;
      }
      else cout << no << endl;
    }else if(s[i] == 'b'){
      if(A+B<a+b &&B<b){
        cout << yes << endl;
        B++;
      }
      else cout << no << endl;
    }else{
      cout << no << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,T,ans=10000;
    cin>>n>>T;
    int c,t;
    for(int i=0;i<n;i++){
        cin>>c>>t;
        if(t<=T){
            ans=min(ans,c);
        }
    }
    if(ans==10000){
        cout << "TLE"<<endl;
    }
    else{
        cout << ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int d, g;
ll p[11], c[11];
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> d >> g;
    rep(i, 0, d) cin >> p[i] >> c[i];
    ll ans = INF;
    rep(bit, 0, (1<<d)) {
        ll sum = 0LL, cnt = 0LL;
        rep(i, 0, d) 
            if (bit & (1 << i)) sum += 100 * (i+1) * p[i] + c[i], cnt += p[i];
        if (sum >= g) ans = min(ans, cnt);
        else {
            eper(j, d-1, 0) {
                if (bit & (1 << j)) continue;
                rep(k, 0, p[j]) {
                    if (sum >= g) break;
                    sum += 100 * (j + 1);
                    cnt++;
                }
            }
            ans = min(ans, cnt);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int n,k; cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int dp[n];
    rep(i,n) dp[i]=INF;
    dp[0]=0;
    for(int i=1; i<n; i++){
        for(int j=1; j<=min(k,i); j++){
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }

    cout << dp[n-1] << endl;

return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>
#include<iostream>

using namespace std;
int main(){
  int N, K;
  int cnt =0;
  cin >> N >> K;
  for(int i=0; i< N; i++){
    int h;
    cin >> h;
    if (h >= K) cnt+=1;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,string> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define MAX 100010
int sosu[MAX]={1,1,0};
vi sos;
void init(){
	for(int i=2;i*i<=MAX;i++)if(!sosu[i])
	for(int j=i*2;j<MAX;j+=i)sosu[j]=true;
	rep(i,MAX)if(sosu[i]==0)sos.pb(i);
}
int main(){
	init();
	int a,b,c;
	while(cin>>a>>b>>c,a+b+c){
		int outa=0,outb=0;
		for(int i=2;i*i<=a;i++)if(!sosu[i]){
			for(int j=i;i*j<=a;j++)if(!sosu[j]&&b*j<=c*i){
				if(outa*outb<i*j){
					outa=i;
					outb=j;
				}
			}
		}
		cout<<outa<<" "<<outb<<endl;
	}
}

Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>
#include <queue>

#define MAX_N 100001
typedef std::pair<int, int> pint;


/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int N;	// アルバイト件数(1≦N≦10^5)
int M;	// 期限の日にち(1≦M≦10^5)
int A[MAX_N];	// 支払いまでの日数
int B[MAX_N];	// バイト料
pint C[MAX_N];	//

std::priority_queue<int> pq;


int main () {

	int sum = 0;

	// 件数Nと日にちMの読込み
	scanf("%d %d", &N, &M);

	// バイトの支払日数とバイト料
	for(int i = 0; i < N; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		C[i].first = a; C[i].second = b;
	}
	
	// 日数による昇順ソート
	std::sort(C, C + N);

	// バイトを入れて，最大賃金を計算
	int j = 0;
	for(int i = 1; i <= M; i++) { 
		// M日目までに間に合うバイト候補をキューに入れる
		while(C[j].first <= i && j < N) { pq.push(C[j].second); j++; }
		// 賃金最大のバイトを取出す
		if(pq.empty()) continue;
		sum += pq.top();	pq.pop();
	}

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

	return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const ll oo = 1e18;
const ll mod = 1e9 + 7,maxn = 100000000;
const double PI = acos(-1);

string compare(string a, string b){
    if (a.size() > b.size() || (a.size() == b.size() and a > b)) return "GREATER";
    if (a == b) return "EQUAL";
    return "LESS";
}
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll a, b, c, mul;
    set<int> st;

    cin >> a >> b >> c;
    mul = a;

    while (!st.count(mul%b)) st.insert(mul%b), mul+=a;

    if (st.count(c)) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
  int n;
  cin >> n;
  vector<int> scores(n,0);
  for(int i=0;i<n;++i){
    cin >> scores[i];
  }
  sort(scores.begin(), scores.end(), [](int a, int b){return a>b;});
  int sum=0;
  for(int h=0;h<n;++h){
    for(int i=n;i>h;--i){
      for(int k=h;k<i;++k){
        sum += scores[k];
      }
      if(sum%10 != 0){
        goto end;
      }
      sum = 0;
      for(int j=i;j>=h;--j){
        for(int k=h;k<i;++k){
          if(k != j){
            sum += scores[k];
          }
        }
        if(sum%10 != 0){
          goto end;
        }
        sum = 0;
      }
    }
  }
  sum = 0;
  end:
    cout <<  sum << endl;
}


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

int main() {
	int n, a[100], sum = 0, tmp;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int flag = 1;
	while (flag) {
		flag = 0;
		for (int i = n - 1; i > 0; i--) {
			tmp = a[i];
			if (a[i] < a[i - 1]) {
				a[i] = a[i - 1];
				a[i - 1] = tmp;
				flag = 1;
				sum++;
			}
		}
	}
	for (int i = 0; i < n - 1; i++) {
		cout << a[i] << " ";
	}
	cout << a[n - 1] << endl << sum << endl;

	return 0;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i,n) for(ll i=0; i<(n); i++)
#define forn for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 
#define all(x) (x).begin(),(x).end()
#define en '\n'
#define FILL(x,v) memset(x,v,sizeof(x))
#define pb push_back
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}
template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

void solve(){
	string s;
	cin >> s;
	// cout << (s=="ABC") ? "ARC" : s << endl;
	if(s=="ABC") cout << "ARC" << en;
	else cout << "ABC" << en;
}

int main(){
	fast;
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
    // int t;
	// cin >> t;
    // while(t--){
	solve();
	// }
    return 0;
}

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

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

Measured memory_bytes: 256
# 現在のレーティングを a とする。
# 次のコンテストで, パフォーマンス b を取ったとする。
#そのとき, レーティングは a と b の平均まで変化する。

# 現在のレーティング R と　目指したいレーティング G を入力
R = int(input())
G = int(input())
# print(R, G)

# とるべきパフォーマンス を x とすると、
# 目指したいレーティング　G = (R+x)/2　
# 以下式変換
# 2G = R + x
# x = 2G - R

x = (2 * G) - R
# print(x)

# 答えを代入
answer = x
print(answer)


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

int main(void) {
 
    int K;
    cin >> K;

    std::queue<long long int> que;

    for (int i=1; i<=9; i++)
    {
        que.push(i);
    }

    for (int i=0; i<K-1; i++)
    {
        long long int lli = que.front();
        que.pop();
        long long int lli2 = lli%10;
        if (lli2 != 0) que.push(10*lli+lli2-1);
        que.push(10*lli+lli2);
        if (lli2 != 9) que.push(10*lli+lli2+1);
    }
  	cout << que.front() << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int N;
  cin >> N;
  int a[100];
  REP(i, N) cin >> a[i];
  vector<int> a_v (a, a+N);
  sort(a_v.begin(), a_v.end());

  int dif = 0;
  REP(i, N) {
    if (i % 2 == 0) {
      dif += a_v[a_v.size()-1];
    } else {
      dif -= a_v[a_v.size()-1];
    }
    a_v.pop_back();
  }
  cout << dif << endl;

  return 0;
}

Measured memory_bytes: 256
#include "stdio.h"
#include "stdlib.h"
#include "iostream"
#include "math.h"
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include "algorithm"


using namespace std;
#define fori0(G) for(int i=0;i<G;i++)
#define fori1(G) for(int i=1;i<=G;i++)
#define forj0(G) for(int j=0;j<G;j++)
#define forj1(G) for(int j=1;j<=G;j++)
#define fork0(G) for(int k=0;k<G;k++)
#define fork1(G) for(int k=1;k<=G;k++)
int dx[] = { -1,0,1,0 ,0 }, dy[] = { 0,1,0,-1,0 };
#define nxnycon (0<=nx&&nx<h&&0<=ny&&ny<w) 


#define lo long long int

int main() {
	lo a, b, c, k,t,p;
	cin >> a>>b>>c>>k;
	t = k & 1;
	p=(a - b)*(-t*2 + 1) ;
	if((p)>1000000000000000000||
		(p) < -1000000000000000000) {
		cout << "unfair";
	}
	else { cout << p; }
	//cout << ('a' < 'aa');
	//system("pause");
	return 0;

}



Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    long[] h = new long[n];
    int[] a = new int[m];
    int[] b = new int[m];

    for (int i = 0; i < n; i++) {
      h[i] = sc.nextLong();
    }

    for (int i = 0; i < m; i++) {
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
    }

    int count = 0;

    int[][] data = new int[2][n];

    for (int i = 0; i < m; i++) {
      if (h[a[i]-1] < h[b[i]-1]) {
        data[1][b[i]-1]++;
        data[0][b[i]-1]++;
        data[0][a[i]-1]++;
      } else if (h[a[i]-1] > h[b[i]-1]) {
        data[1][a[i]-1]++;
        data[0][a[i]-1]++;
        data[0][b[i]-1]++;
      } else {
        data[0][a[i]-1]++;
        data[0][b[i]-1]++;
      }
    }

    int ans = 0;

    for (int i = 0; i < n; i++) {
      if (data[0][i] == data[1][i] || data[0][i] == 0) {
        ans++;
      }
    }

    System.out.println(ans);

  }

}


Measured memory_bytes: 61244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

template <class T>
void printArray(const vector<T>& a) {
  int n = a.size();
  for (int i = 0; i < n; i++) {
    cout << a[i] << " \n"[i == n - 1];
  }
}

int main() {
  ll n = 50;
  ll k;
  cin >> k;

  ll q = k / n, r = k % n;
  vector<ll> ans(n, n - 1 + q);

  REP(_, r) {
    int minIdx = -1;
    ll mini = 1e18;
    REP(i, n) {
      if (ans[i] < mini) {
        mini = ans[i];
        minIdx = i;
      }
    }

    REP(i, n) {
      if (i == minIdx) {
        ans[i] += n;
      } else {
        ans[i] -= 1;
      }
    }
  }

  cout << n << "\n";
  printArray(ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double PI = 3.14159265358979;
const double E = 2.718281828459045;
const double root2 = sqrt(2);
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int n; string s;
	cin >> n >> s;
	int count = 0;
	for (int i = 1; i < n; i++) {
		if (s[i] == 'E') {
			count++;
		}
	}
	int mi = count;
	for (int i = 1; i < n; i++) {
		if (s[i] == 'E')count--;
		if (s[i - 1] == 'W')count++;
		mi = min(mi, count);
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    string s;cin>>s;
    ll ssize = s.size();
    ll cnt[2]={};
    ll now = 0;
    cnt[0]++;
    ll lr[ssize]={};
    lr[0]=0;
    repr(i,1,ssize){
        if(s.at(i)==s.at(i-1)){
            now = 1- now;
        }
        cnt[now]++;
        lr[i] = now;
    }
    if(s[0]=='W'||s[ssize-1]=='W'||cnt[0]!=cnt[1]){
        cout << 0 << endl;
        return 0;
    }
    ll res=1;
    repr(i,1,n+1){
        res *= i;
        res %= MOD;
    }
    ll cnt2=0;
    for(ll i=ssize-1;i>=0;i--){
        if(lr[i]){
            cnt2++;
        }else{
            res *= cnt2--;
            res %= MOD;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2196
x, y = map(int, input().split())

ans = abs(abs(x) - abs(y))
if x == 0 or y == 0:
    if x > y:
        print(ans + 1)
    else:
        print(ans)
    exit()

if abs(x) == abs(y):
    if x * y < 0:
        print(1)
    else:
        print(0)
    exit()

if x > y:
    if y > 0:
        print(ans + 2)
    elif x > 0 and y < 0:
        print(ans + 1)
    else:
        print(ans + 2)
elif x < y:
    if y < 0:
        print(ans)
    elif x < 0 and y > 0:
        print(ans + 1)
    else:
        print(ans)


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
loop = 1
while(loop):
    l = input().strip().split()
    H = int(l[0])
    W = int(l[1])
    if(H == 0 and W == 0):
        break
    else:
        for y in (range(H)):
            str = "#" * W
            print(str)
        print()

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

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

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

void solve() {
	int a, b, c; cin >> a >> b >> c;
	if (c >= a && c <= b) cout << "Yes";
	else cout << "No";
}

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


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

using namespace std;

int N;
vector<int> PersonId;
vector<int> PersonInfo;
vector<int> Claim;

void solve() {
	int p1, p2, sum, minTotal;

	minTotal = 10000000;
	do {
		sum = 0;
		for (int i = 0; i < N; ++i) {
			p1 = PersonInfo[PersonId[i]];
			p2 = PersonInfo[PersonId[(i + 1) % N]];
			if (!p1 && p2) {
				sum += Claim[PersonId[i]] + Claim[PersonId[(i + 1) % N]];
			}
		}
		minTotal = min(minTotal, sum);
	} while (next_permutation(PersonId.begin(), PersonId.end()));

	cout << minTotal << endl;
}

int main() {
	int num;

	cin >> N;
	for (int i = 0; i < N; ++i) {
		PersonId.push_back(i);
		cin >> num;
		PersonInfo.push_back(num);
	}
	for (int i = 0; i < N; ++i) {
		cin >> num;
		Claim.push_back(num);
	}
	solve();

	return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

constexpr int mod = 1000000007;
struct mint {
  long long x;
  constexpr mint(long long x = 0) : x((x % mod + mod) % mod) {}
  constexpr mint operator-() const { return mint(-x); }
  constexpr mint &operator+=(const mint &a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  constexpr mint &operator-=(const mint &a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  constexpr mint &operator*=(const mint &a) {
    (x *= a.x) %= mod;
    return *this;
  }
  constexpr mint operator+(const mint &a) const {
    mint res(*this);
    return res += a;
  }
  constexpr mint operator-(const mint &a) const {
    mint res(*this);
    return res -= a;
  }
  constexpr mint operator*(const mint &a) const {
    mint res(*this);
    return res *= a;
  }
  constexpr mint pow(long long t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  constexpr mint inv() const { return pow(mod - 2); }
  constexpr mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
  constexpr mint operator/(const mint &a) const {
    mint res(*this);
    return res /= a;
  }
};
ostream &operator<<(ostream &os, const mint &m) {
  os << m.x;
  return os;
}

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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];
  vector<int> c(n + 1);
  c[0] = 3;

  mint ans = 1;
  rep(i, 0, n) {
    if (!c[a[i]]) {
      cout << 0 << endl;
      return 0;
    }

    ans *= c[a[i]];
    c[a[i]]--;
    c[a[i] + 1]++;
  }

  cout << ans.x << endl;
}


Measured memory_bytes: 4000
#include<stdio.h>
int main(void)
{
  int a,b,c,d,i;

  scanf("%d %d %d",&a,&b,&c);
  if(1>a) return 1;
  else if (c>100) return 1;
  for(i=0;i<c;i=i+a){
    d=b/a;
  }
  if(d>=c) printf("%d\n",c);
  else if(d==0) printf("%d\n",d);
  else printf("%d\n",d);
  return 0;
}


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

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

int dfs(int v, const vector< vector< int > >& childlen) {
	int m = childlen[v].size();
	vector< int > cost(m, 0);
	for_(i,0,m) cost[i] = dfs(childlen[v][i], childlen);
	sort(cost.begin(), cost.end(), greater< int >());
	int res = 0;
	for_(i,0,m) res = max(res, cost[i] + i);
	return res + 1;
}

void solve(int n, const vector< int >& a) {
	vector< vector< int > > childlen(n);
	for_(i,1,n) childlen[a[i]].push_back(i);
	cout << dfs(0, childlen) - 1 << endl;
}

int main() {
	int n;
	cin >> n;
	
	vector< int > a(n, -1);
	for_(i,1,n) {
		cin >> a[i];
		--a[i];
	}
	
	solve(n, a);
}

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

int main() {
  int n,k,x,y;cin>>n>>k>>x>>y;
  cout << min(k, n)*x + max(n-k, 0)*y;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
ab = [0]*n
for i in range(n):
    a, b = map(int, input().split())
    ab[i] = (a, b)
ab.sort()

result = 0
for i in range(n):
    rest = m - ab[i][1]
    if rest >= 0:
        result += ab[i][1] * ab[i][0]
        m -= ab[i][1]
    else:
        result += m * ab[i][0]
        break
print(result)


Measured memory_bytes: 16852