akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main()
{
    int r, g, b,n;
    cin>>r>>g>>b>>n;
    long long int count=0;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            if(n-i*r-j*g>=0 && (n-i*r-j*g)%b==0)
                count++;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#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(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
typedef pair<P,P> PP;

int n=4,a[4][4],ans=MAX;

void solve() {
  queue<PP> que;
  rep(i,n)rep(j,n)if(a[i][j]==5) {
    a[i][j]=0;
    rep(k,4) que.push(PP(P(i,j),P(k,0)));
  }
  int d[n][n];mem(d);
  while(!que.empty()) {
    PP p=que.front();que.pop();
    int x=p.F.F+dx[p.S.F],y=p.F.S+dy[p.S.F];
    if(!check(n,n,x,y)) continue;
    if(1<=a[x][y]&&a[x][y]<=4) {
      a[x][y]++;
      if(a[x][y]==5) {
        a[x][y]=0;
        d[x][y]=p.S.S+1;
        rep(k,4) que.push(PP(P(x,y),P(k,p.S.S+1)));
      }
    } else {
      if(d[x][y]==p.S.S+1) continue;
      que.push(PP(P(x,y),P(p.S.F,p.S.S+1)));
    }
  }
}

void dfs(int k) {
  if(k>5) return;
  int c=0;
  rep(i,n)rep(j,n)if(!a[i][j])c++;
  if(c==n*n) {
    ans=min(ans,k);
    return;
  }
  int b[n][n];
  rep(i,n)rep(j,n) b[i][j]=a[i][j];
  rep(i,n)rep(j,n) {
    if(!a[i][j]) continue;
    a[i][j]++;
    solve();
    dfs(k+1);
    rep(i,n)rep(j,n) a[i][j]=b[i][j];
  }
}

void Main() {
  rep(i,n)rep(j,n) R a[i][j];
  dfs(0);
  if(ans==MAX) ans=-1;
  pr(ans);
}

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


Measured memory_bytes: 3236
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long
signed main() {
    int n;
    cin >> n;
    vector<int> a(n+1,0);
    rep(i,n) cin >> a[i];
    int now = 0;
    int nex = 1;
    int ca = 1000;
    int cr = 0;
    int last = 0;
    bool f = false;
    while(now<n) {
        if(f && a[now]>a[nex]){
           f = false;
           ca = ca + cr*a[now];
           cr = 0;
            //cout << cr<<" "<< ca << endl;
        }else if(!f && a[now]<a[nex]){
            f = true;
            cr = ca/a[now];
            last = ca;
            ca = ca - cr*a[now];
            
            //cout << cr<<" "<< ca << endl;
        }
        now++;
        nex++;
    }
    cout << max(ca,last) << endl;
    
  return 0;
}



Measured memory_bytes: 3484
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double pi = 3.141592653589793238;

int main() {
	int k[5];
	for (int i = 0; i < 3; ++i) { cin >> k[i]; }
	sort(k, k + 3);
	cout << (k[0] * k[1]) / 2 << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main(void)
{

    int N, A, B, C, X;
    int Y[100], k = 0, i;

    while(1){
        scanf("%d %d %d %d %d", &N ,&A, &B, &C, &X);
        if(N == 0 && A == 0 && B == 0 && C == 0 && X == 0)
            break;
        for(i = 0; i < N; i++)
            scanf("%d", Y + i);
        k = 0;
        for(i = 0; i <= 10000; i++){
            if(X == Y[k]){
                k++;
                if(k == N){
                    printf("%d\n", i);
                    break;
                }
            }
            X = (A * X + B) % C;
        }
        if(i == 10001)
            printf("-1\n");
    }
    return 0;
}

Measured memory_bytes: 1040
#include <iostream>
#include <string.h>
#include <stdlib.h>

using namespace std;

enum {
	OTHER = 0,
	THREE = 1,
	FIVE  = 2,
	THREEFIVE = 3,
};

int main( void )
{
	int m, n;
	char player[1000];
	while(cin >> m >> n, (m | n))
	{
		int alive = m;
		for(int i=0; i < m; i++) player[i] = 1;
		int pnt = 0, cnt = 1;
		char input[256];
		for(int i=0; i < n; i++) {
			scanf("%s", input);
			if(alive == 1) continue;
			int judge = 0;
			if(!(cnt % 3)) judge |= THREE;
			if(!(cnt % 5)) judge |= FIVE;
			switch(judge)
			{
			case OTHER:
				if(atoi(input) != cnt) {
					player[pnt] = 0; --alive;
				}
				break;
			case THREE:
				if(strcmp(input, "Fizz")) {
					player[pnt] = 0; --alive;
				}
				break;
			case FIVE:
				if(strcmp(input, "Buzz")) {
					player[pnt] = 0; --alive;
				}
				break;
			case THREEFIVE:
				if(strcmp(input, "FizzBuzz")) {
					player[pnt] = 0; --alive;
				}
				break;
			}
			cnt++;
			bool hit = false;
			for(int j=pnt+1; j < m; j++) {
				if(player[j]) {
					pnt = j;
					hit = true;
					break;
				}
			}
			if(!hit) {
				for(int j=0; j < pnt; j++) {
					if(player[j]) {
						pnt = j;
						break;
					}
				}
			}
		}
		for(int i=0; i < m; i++) {
			if(player[i]) {
				cout << i+1; --alive;
				if(alive) cout << ' ';
			}
		}
		cout << endl;
	}
	return 0;
}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;


struct hoge
{
    int a;
    int b;
    int diff;
    int score;
};
vector<hoge> c_data;
int dfs(int n, int m,int before,int index, vector<int> vc)
{
    // for(auto i : vc)cout << i;
    // cout << endl;
    if(n==0)
    {
        int sum = 0;
        for(auto i:c_data)
        {
            if(vc[i.b]-vc[i.a]==i.diff)
            {
                sum += i.score;
            }
        }
        return sum;
    }
    int ans = 0;
    for (int i = before; i <= m; i++)
    {
        vc[index] = i;
        ans = max(ans, dfs(n-1,m,i,index+1,vc));
    }
    return ans;
}



int main()
{
    int n,m,q;
    cin >> n >> m >> q;
    
    rep(i,q)
    {
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        --a;--b;
        hoge temp;
        temp.a = a;temp.b = b;temp.diff = c;temp.score = d;
        c_data.push_back(temp);
    }
    vector<int> vc(n);
    cout << dfs(n,m,1,0,vc) << endl;
   
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
 
 
 
 
int main() {
    int n;
    cin>>n;
    int b[n];
    for(int i=0;i<n-1;i++){
        cin>>b[i];
    }
    ll sum=0;
    sum+=b[0]+b[n-2];
    for(int i=1;i<n-1;i++){
        sum+=min(b[i],b[i-1]);
    }
    cout<<sum<<endl;


}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

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

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

template <typename T> void setmax(T& a, const T& b) { if (b > a) a = b; }
template <typename T> void setmin(T& a, const T& b) { if (b < a) a = b; }

struct interval {
	int lo, hi;
	interval() : lo(0), hi(0) {}
	interval(int lo_, int hi_) : lo(lo_), hi(hi_) {}
	interval& operator &= (const interval& o) {
		setmax(lo, o.lo);
		setmin(hi, o.hi);
		return *this;
	}
	friend interval operator & (const interval& a, const interval& b) {
		return interval(std::max(a.lo, b.lo), std::min(a.hi, b.hi));
	}
	explicit operator bool () const {
		return lo <= hi;
	}
};

int main() {
	using namespace std;
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	int K; cin >> K;
	vector<int> A(K);
	for (int i = 0; i < K; i++) cin >> A[i];
	if (*min_element(A.begin(), A.end()) * 2 < *max_element(A.begin(), A.end())) {
		cout << -1 << '\n';
		exit(0);
	}

	int L = accumulate(A.begin(), A.end(), 0);
	vector<int> res; res.reserve(L);
	auto is_good = [&K, &res, &A]() -> bool {
		vector<bool> seen(K);
		int N = int(res.size());
		int st = N;
		while (st > 0 && !seen[res[st-1]]) {
			--st;
			seen[res[st]] = true;
		}

		int en;
		if (N - st == K) {
			en = N;
		} else if (st == 0) {
			en = 0;
		} else {
			int l = st, r = N;
			while (r - l < K) {
				if (l == 0) {
					return false;
				} else if (seen[res[l-1]]) {
					seen[res[--r]] = false;
					if (r < st) return false;
				} else {
					seen[res[--l]] = true;
				}
			}
			en = r;
		}

		seen.assign(K, 0);
		for (int i = st; i < N; i++) seen[res[i]] = true;

		auto can_make = [&](interval base, vector<pair<interval, interval>> opts) {
			vector<interval> pref(opts.size()+1);
			pref[0] = base;
			for (int i = 0; i < int(opts.size()); i++) {
				pref[i+1] = pref[i] & opts[i].first;
			}
			interval suff = base;
			if (pref.back()) return true;
			for (int i = int(opts.size())-1; i >= 0; i--) {
				suff &= opts[i].second;
				if (pref[i] & suff) {
					return true;
				}
			}
			return false;
		};

		{
			interval fixed(0, int(1e9));
			for (int v = 0; v < K; v++) {
				if (!seen[v]) {
					fixed &= interval(A[v], 2*A[v]);
				}
			}
			for (int i = en; i < N; i++) {
				int v = res[i];
				fixed &= interval(A[v]+1, 2*A[v]+1);
			}
			vector<pair<interval, interval>> opts; opts.reserve(en-st);
			for (int i = st; i < en; i++) {
				int v = res[i];
				opts.push_back({{A[v],2*A[v]}, {A[v]+1, 2*A[v]+1}});
			}
			if (can_make(fixed, opts)) return true;
		}

		{
			interval fixed(0, int(1e9));
			for (int v = 0; v < K; v++) {
				if (!seen[v]) {
					fixed &= interval(A[v]+1, 2*A[v]);
				}
			}
			vector<pair<interval, interval>> opts; opts.reserve(N-st);
			for (int i = st; i < N; i++) {
				int v = res[i];
				opts.push_back({{A[v]+1, 2*A[v]+1}, {A[v]+2, 2*A[v]+2}});
			}
			if (can_make(fixed, opts)) return true;
		}

		return false;
	};

	for (int curL = 1; curL <= L; curL++) {
		for (int i = 0; i < K; i++) {
			if (A[i]) {
				A[i]--;
				res.push_back(i);
				if (is_good()) {
					break;
				}
				res.pop_back();
				A[i]++;
			}
		}
		assert(int(res.size()) == curL);
	}

	for (int z = 0; z < L; z++) {
		cout << res[z]+1 << " \n"[z+1==L];
	}

	return 0;
}


Measured memory_bytes: 3672
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 aa, bb, cc, kk;
	cin >> aa >> bb >> cc >> kk;
	while(aa >= bb)
	{
		bb *= 2;
		kk--;
		if(kk == -1)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	while(bb >= cc)
	{
		cc *= 2;
		kk--;
		if(kk == -1)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F(i,a) for(ll i=0;i<a;i++)
#define R(i,n,m) for(ll i=(ll) n ; i  < (ll) m ; i++ )

int main (){

    int n,r=0;
    cin>>n;
    string s, a = "ABC";
    cin>>s;
    for ( int i=0 ; i < n-2  ; ++i ){
        int b = 0;
        for ( int j=0 ; j < 3 ; ++j){
            if (s[i+j] == a[j]){
                ++b;
            } 
            else {
                break;
            }
        }
        if ( b== 3) ++r;  //fatal
    }
    cout<<r;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*
int main(){
    int H, W;
    cin>>H>>W;
    string s[H+2][W+2];
    rep(i, H){
        rep(j, W){
            cin>>s[i+1][j+1];
        }
    }
    rep(i, W+2){
        s[0][i]="#";
        s[H+1][i]="#";
    }
    rep(i, H){
        s[i+1][0]="#";
        s[i+1][W+1]="#";
    }
    rep(i, H+2){
        rep(j, W+2){
            cout<<s[i][j];
        }
        cout<<""<<endl;
    }
}
*/
int main(){
    int H, W;
    cin>>H>>W;
    char c;
    rep(i, H+2){
        rep(j, W+2){
            if(i==0||i==H+1){
                cout<<"#";
            }
            else if (j==0||j==W+1){
                cout<<"#";
            }
            else{
                cin>>c;
                cout<<c;
            }
        }
        cout<<""<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define N 100005

typedef struct {
  char str[10];
  int num;
}Record;

void enqueue(Record);
Record dequeue();

int head = 0, tail = 0, size = 0, n = 0;
Record que[N];


int main () {
  Record quon;
  int q = 0, i, sum = 0;

  scanf("%d %d",&n,&q);
  
  for(i = 0 ; i < n ; i++) {
    scanf("%s",que[i].str);
    scanf("%d",&que[i].num);
  }
  size = n;
  tail = n;

  while(size != 0) {
   
    quon = dequeue();

    if(quon.num - q <= 0) { 
      sum += quon.num;
      printf("%s %d\n",quon.str,sum);
    }
    
    else {
      quon.num = quon.num - q;
      enqueue(quon);
      sum += q;
    }
    
  }
  
  return 0;
}


void enqueue(Record data) {
  que[tail].num = data.num;
  strcpy(que[tail].str,data.str);
  size++;
  if(tail == N) tail = 0;
  else tail++;
}

Record dequeue () {
  int x = 0;
  x = head;
  if(head == N) head = 0;
  else head++;
  size--;
  return que[x];
}



Measured memory_bytes: 3284
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int solve(int a, int b){
    while(b>0){
        a*=10;
        b--;
    }
    return a;
}
int main(){
    int N,M;
    cin >> N >> M;
    vector<pair<int,char>> p(M);
    rep(i,M){
        int s;
        char c;
        cin >> s >> c;
        s--;
        p[i] = {s,c};
    }
    int s = solve(1,N-1);
    int g = solve(1,N);
    if(N==1) s=0;
    for(int i = s; i < g; i++){
        string now = toString(i);
        if(M == 0){
            cout << i << endl;
            return 0;
        }
        rep(j,M){
            int d = p[j].first;
            if(now[d] != p[j].second) break;
            if(j == M-1){
                cout << now << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 3620
"""
B=10**100
とすると、Bが非常に大きいので、B,B+1,B+2,,,B+Nの中でK個選んだ時のKが違えば、K個の値の和は必ず違う値になる
従ってKを固定した時、1,2,3,,,Nの中でK個選んだ時の総和が何通りあるかを求めれば良い

SはK以上N+1以下の値をとるものとする
総和を最小にするには、左からS個取れば良い
min L = 0+1+2+...+S-1
総和を最大にするには、右からS個取れば良い
max R = (n-S+1)+...+n
LからRの間の数は全て作れるので、Sを固定したときに取り得る値はR-L+1通りある

左端l、右端rの公差1の等差数列の和は
(l+r)*(r-l+1)/2
"""

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
N,K = [int(i) for i in readline().split()]

ans = 0

def sum(l, r):
    return (l+r)*(r-l+1)//2

for S in range(K, N+2):
    L = sum(0, S-1)
    R = sum(N-S+1, N)
    ans += (R-L+1)%(10**9+7)

ans %= 10**9+7
print(ans)

Measured memory_bytes: 9212
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>

using namespace std;

int N;

int main() {
  cin >> N;
  long ans = 0;
  long rem = 0;
  rep(i, N) {
    long a;
    cin >> a;
    ans += a/2;
    long nowrem = a%2;
    if (rem + nowrem == 2) {
      ans++;
      rem = 0;
    } else if (a == 0) {
      rem = 0;
    } else if (rem == 0) {
      rem = nowrem;
    }
  }
  cout << ans << endl;
}


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

int main()
{
    long long N;
    cin >> N;

    vector<long long> A(N + 1, 0);
    for (int i = 1; i <= N; i++)
    {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    vector<long long> sum(N + 1, 0);
    for (int i = 1; i <= N; i++)
    {
        sum[i] = sum[i - 1] + A[i];
    }
    long long l = 0;
    long long r = N;
    while (r - l > 1)
    {
        long long c = (l + r) / 2;
        long long s = sum[c];
        bool flag = true;
        for (int i = c + 1; i <= N; i++)
        {
            if (2 * s >= A[i])
            {
                s += A[i];
            }
            else
            {
                flag = false;
                break;
            }
        }
        if (flag)
        {
            r = c;
        }
        else
        {
            l = c;
        }
    }
    cout << N - l << endl;
}


Measured memory_bytes: 1792
/**********************************************
#code by --> @ { shadat </> sk40 [ o_o  ^_^ ] } }
**********************************************/
#include<bits/stdc++.h>
#include<algorithm>
#include<queue>
#include<list>
#include<map>
#include <math.h>
#include<numeric>
using namespace std;
#define tezz ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define doub long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int , int>
#define pdd pair<double , double>
#define pll pair<long long int,long long int>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define stp setprecision(20)
string s;
string dd={'a','e','i','o','u','y'};
ll count1[1<<20];
ll total[1<<20];
bool contains(char c,string f){
	for(int i=0;i<f.length();i++){
		if(c==s[i]){
			return true;
		}
	}
	return false;
}
const int maxi=1e5;
int main(){
	
	string s;
	cin>>s;
	int k=s.size();
	int arr[k];
	for(int i=0;i<k;i++)
		arr[i]=0;
	int brr[k];
	int pre=k-1;
	for(int i=k-1;i>=0;i--)
	{
		if(s[i]=='L')
		pre=i;
		else
		brr[i]=pre;
	}
	pre=0;
	for(int i=0;i<k;i++)
	{
		if(s[i]=='R')
		pre=i;
		else
		brr[i]=pre;
	}
//	for(int i=0;i<k;i++)
//	cout<<brr[i]<<" ";
//	cout<<endl;
	for(int i=0;i<k;i++)
	{
		if(brr[i]>i)
		{
			int kk=brr[i]-i;
			if(kk%2==0)
			arr[brr[i]]++;
			else
			arr[brr[i]-1]++;
		}
		else
		{
			int kk=i-brr[i];
			if(kk%2==0)
			arr[brr[i]]++;
			else
			arr[brr[i]+1]++;
		}
	}
	for(int i=0;i<k;i++)
		cout<<arr[i]<<" ";

	return 0;
}

Measured memory_bytes: 1408
#include <cmath>
#include <iomanip>
#include <iostream>

int main() {
  double a, b, x;
  std::cin >> a >> b >> x;

  const auto v = a * a * b;
  const auto vc = 0.5 * v;

  double tmax = 0;
  if (x > vc) {
    const auto h = 2 * (v - x) / (a * a);
    tmax = std::atan(h / a) * 180.0 / M_PI;
  } else {
    const auto h = 2 * x / (a * b);
    tmax = std::atan(b / h) * 180.0 / M_PI;
  }
  std::cout << std::scientific << tmax << std::endl;
}

Measured memory_bytes: 256
a = []

for i in range(6):
    a.append(int(input() )) 

f = True
for i  in range(4):
    for j in range(4-i):
        if a[j + i + 1]  - a[i] > a[5]:
            f = False
            break

if f:
    print("Yay!")
else:
    print(":(")


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

int main(void){
  int x;
  vector<int> v;

  for(int i=0; i<10; i++){
    cin >> x;
    v.push_back(x);
  }

  sort(v.begin(), v.end(), greater<int>());

  for(int i=0; i<3; i++){
    cout << v[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

void show(int n,vector<int> v);
void insertionSort(int n,vector<int> v);

int main(){
    int n,tmp;
    vector<int> v;

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> tmp;
        v.push_back(tmp);
    }
    show(n,v);

    insertionSort(n,v);

    return 0;
}

void show(int n,vector<int> v){
    for(int i=0;i<n;i++){
        cout << v[i] << (i+1 < n ? ' ':'\n');
    }
}

void insertionSort(int n,vector<int> v){
    int tmp;
    bool flag = false;

    for(int i=1;i<n;i++){
        tmp = v[i];
        int j=i-1;
        while(j>=0&&tmp<v[j]){
            v[j+1] = v[j];
            j--;
        }
        v[j+1] = tmp;
        show(n,v);
    }
}

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

main(){
  int n,ans;
  double av=0,deg=101;
  cin >> n;
  double a[n];
  for (int i=0;i<n;i++) {
    cin >> a[i];
    av+=a[i];
  }
  av/=n;
  for (int i=n-1;i>=0;i--) {
    if (deg>=fabs(a[i]-av)) {
      deg=fabs(a[i]-av);
      ans=i;
    }
  }
  cout << ans << endl;
}

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

const int MAXN = 200010;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

int a[MAXN], p[MAXN], n;
int fa[MAXN], size[MAXN];
long long ans;

bool cmp(const int &x, const int &y) {
	return a[x] > a[y];
}

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

int main() {
	n = read();
	for(int i = 1; i <= n; i++) 
		a[i] = read(), fa[i] = p[i] = i;
	sort(p+1, p+n+1, cmp);
	for(int i = 1; i <= n; i++) {
		int u = p[i];
		int x = find(u-1), y = find(u+1);
		size[u] = 1;
		if(size[x] && size[y]) {
			ans += (long long)a[u]*(size[y]+1)*(size[x]+1);
			fa[x] = y, size[y] += size[x];
			fa[u] = y, size[y] += size[u];
		}
		else if(size[x]) {
			ans += (long long)a[u]*(size[x]+1);
			fa[u] = x, size[x] += size[u];
		}
		else if(size[y]) {
			ans += (long long)a[u]*(size[y]+1);
			fa[u] = y, size[y] += size[u];
		}
		else ans += a[u];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3328
ABCD = input()
ABCD_list = [int(num_str) for num_str in str(ABCD)]

pm_pairs = ["+++", "++-", "+-+", "+--", "-++", "-+-", "--+", "---"]

for pm in pm_pairs:
    sum = ABCD_list[0]
    if pm[0] == "+":
        sum += ABCD_list[1]
    else:
        sum -= ABCD_list[1]

    if pm[1] == "+":
        sum += ABCD_list[2]
    else:
        sum -= ABCD_list[2]

    if pm[2] == "+":
        sum += ABCD_list[3]
    else:
        sum -= ABCD_list[3]

    if sum == 7:
        print(str(ABCD_list[0]) + pm[0] + str(ABCD_list[1]) + pm[1] +
              str(ABCD_list[2]) + pm[2] + str(ABCD_list[3]) + "=7")
        exit()

Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <set>

using namespace std;

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

#define inf 0x3f3f3f3f
#define INF INT_MAX/3
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second
#define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15)
struct input_returnner { 
	int N; input_returnner(int N_ = 0) :N(N_) {}
	template<typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); }
	template<typename T> operator T() const { T res; cin >> res; return res;} 
};
template<typename T> input_returnner in() { return in<T>(); }
input_returnner in() { return input_returnner(); }
input_returnner in(int N) { return std::move(input_returnner(N)); }

/// ---template---

signed main(void) {
	SETUP;
	vector<ull> V = in(3);
	ull mi = -1;
	for (int i = 0; i < 3; ++i) {
		mi = min(mi, (V[(i+2)%3]%2==1) * V[(i % 3)] * V[(i + 1) % 3]);
	}
	cout << mi << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <bitset>
#include <stack>
#include <queue>
#include <map>
#include <functional>
using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vpii;

long long S[31];
int N, M;

int main(void){
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int a;
            cin >> a;
            S[a]++;
        }
    }
    
    int ans = 0;
    for(int i = 1; i <= M; i++){
        if(S[i] == N) ans++;
    }
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/perl

sub main() {
  my$N=<>;
  my$H=[split(/ /,<>)];
  chomp($H->[-1]);
  my $ans = prob($N,$H);
  print $ans;
}

sub prob() {
  my($N,$H) = @_;
  my $max=0;
  my $tmp=0;
  for my $i(0..$N-2){
    if($H->[$i] >= $H->[$i+1]){
      $tmp++;
      if($max < $tmp){
        $max=$tmp;
      }
    }else{
      if($max < $tmp){
        $max=$tmp;
      }
      $tmp=0;
    }
  }
  return $max;
}

&main();

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

int main() {
	int a=0,s1=0,s2=0,s3=0;
	cin >> a;
	s3=a%10;
    s2=(a%100-s3)/10;
    s1=(a-a%100)/100;
    cout << s1+s2+s3 << endl;
}

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

using namespace std;
#define ll long long int
#define N 300000
int main(){
    ll n, a[N], d[N], sum=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
        d[a[i]]++;
    }
    ll q;
    cin>>q;
    while(q--){
        ll b,c;
        cin>>b>>c;
        sum+=(c-b)*d[b];
        d[c]+=d[b];
        d[b]=0;
        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 4784
import sys
# input = sys.stdin.buffer.readline


N = int(input())
A = [list(map(int, input().split()))[::-1] for _ in range(N)]
day = 0
cnt = N
Last = set([i for i in range(N)])
while cnt:
    flag = True
    Done = [False] * N
    L = set()
    for i in Last:
        if len(A[i]) == 0:
            continue
        if Done[i]:
            continue
        x = A[i][-1] - 1
        if A[x] and (not Done[x]) and (A[x][-1] - 1 == i):
            A[i].pop()
            A[x].pop()
            Done[i] = True
            Done[x] = True
            L.add(i)
            L.add(x)
            flag = False
            if not A[i]:
                cnt -= 1
            if not A[x]:
                cnt -= 1
    Last = L
    if flag:
        break
    day += 1
if cnt:
    print(-1)
else:
    print(day)

Measured memory_bytes: 90036
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int A, B; cin >> A >> B;

    int ans = max(A + B, max(A - B, A*B));
    cout << ans << endl;

    return 0;
}

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

int now = 0, k, n, m, ch;

int main() {
  int i;
  cin >> n >> m;
  for(i = 0; i < m; ++i) {
    cin >> ch >> k;
    if(ch) {
      now += k;
      now %= n;
    }
    else {
      cout << (now + k - 1) % n + 1 << endl;
    }
  }
  return 0;
}


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

using namespace std;
int binary_search(vector<string> &s,int i){
  int left = -1,right = i;
  while(right-left > 1){
    int mid = (left+right)/2;
    if(s[mid] >= s[i])right = mid;
    else left = mid;
  }
  return right;
}


int main(){
  int n;int64_t ans = 0;
  cin >> n;
  vector<string> s(n);
  for(int i = 0;i < n;i++)cin >> s[i];
  for(int i = 0;i < n;i++)sort(s[i].begin(),s[i].end());
  sort(s.begin(),s.end());
  for(int i = n-1;i > 0;i--){
    int a = binary_search(s,i);
    if(a < i)ans += i-a;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 7296
c = [10, 50, 100, 500, 100000]
first = True

while True:
    y = int(input())
    if y == 0:
        break

    if not first:
        print()
    else:
        first = False

    coin = list(map(int, input().split()))
    coinsum = sum(coin[i] * c[i] for i in range(4))
    rem = coinsum - y
    change = [rem % c[i + 1] // c[i] for i in range(4)]

    for i in range(4):
        if change[i] < coin[i]:
            print(c[i], coin[i] - change[i])


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

int main() {
  int N = 0;
  int ans = 0;
  
  cin >> N;
  
  if( N < 112 ){
    ans = 111;
  }
  else if ( (111 < N) && (N <= 222) ){
    ans = 222;
  }
  else if ( (222 < N) && (N <= 333) ){
    ans = 333;
  }
  else if ( (333 < N) && (N <= 444) ){
    ans = 444;
  }
  else if ( (444 < N) && (N <= 555) ){
    ans = 555;
  }
  else if ( (555 < N) && (N <= 666) ){
    ans = 666;
  }
  else if ( (666 < N) && (N <= 777) ){
    ans = 777;
  }
  else if ( (777 < N) && (N <= 888) ){
    ans = 888;
  }
  else if ( (888 < N) && (N <= 999) ){
    ans = 999;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(int i=p;i<n;++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

ll N, A, B, C, D;
string S;

bool isOK(ll p, ll q)
{
    for (ll i=p;i<=q-1;++i)
    {
        if (S[i] == '#' && S[i + 1] == '#') { return false; }
    }

    return true;
}

int main()
{
    cin >> N >> A >> B >> C >> D;
    --A;
    --B;
    --C;
    --D;

    cin >> S;

    bool ok = true;

    if (D < C)
    {
        ok = false;

        for (ll i=B;i<=D;++i)
        {
            if (i - 1 < 0 || N <= i + 1) { continue; }

            if (S[i - 1] != '#' && S[i] != '#' && S[i + 1] != '#')
            {
                ok = true;
            }
        }
    }

    ok = ok && isOK(A, C) && isOK(B, D);

    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
int map[10];
char buf[32];
int main()
{
    for (int i = 0; i < 8; ++i) {
        if (i < 4) map[i] = i;
        else if (i == 4) map[i] = 5;
        else map[i] = i + 2;
    }
    int n;
    while (scanf("%d", &n), n) {
        sprintf(buf, "%o", n);
        for (char* c = buf; *c != '\0'; c++)
            putchar((char)(map[*c - '0'] + '0'));
        puts("");
    }
    return 0;
}

Measured memory_bytes: 0
def good_integer(N: int) -> bool:
    d1 = (N//1) % 10
    d10 = (N//10) % 10
    d100 = (N//100) % 10
    d1000 = (N//1000) % 10

    return d10 == d100 and (d1 == d10 or d100 == d1000)


if __name__ == "__main__":
    N = int(input())
    yes = good_integer(N)
    print('Yes' if yes else 'No')


Measured memory_bytes: 3060
module Queue' = struct
  type 'a t = {
    mutable front : int;
    mutable mask  : int;
    mutable index : int;
    mutable length : int;
    mutable elems : 'a option array
  }

  let capacity t = t.mask + 1

  let is_empty t = t.length = 0

  let create ?(capacity=1) () =
    { front = 0;
      mask  = capacity - 1;
      index = 0;
      length = 0;
      elems = Array.make capacity None}

  let enq t a =
    let elems = t.elems in
    elems.(t.index) <- (Some a);
    t.length <- t.length + 1;
    t.index <- (t.index + 1) mod (capacity t)

  let deq t =
    let elems = t.elems in
    let front = t.front in
    let res = elems.(front) in
    t.front <- (t.front + 1) mod (capacity t);
    t.length <- t.length - 1;
    res

  let get_elems t = t.elems
  let get_index t = t.index
end

let () =
  let open Queue' in
  let (n:int),(quantum:int) = Scanf.scanf "%d %d\n" (fun a b -> a,b) in
  let (q:(string * int) t) = create ~capacity:n () in
  for i=1 to n do
    enq q (Scanf.scanf "%s %d\n" (fun a b -> a,b));
  done;
  let (sum:int ref) = ref 0 in
  while not (is_empty q) do
    let (p:string),(t:int) = match deq q with None -> "",0 | Some x -> x in
    if t <= quantum then (sum := !sum+t; Printf.printf "%s %d\n" p !sum)
    else (enq q (p,t-quantum); sum := !sum+quantum)
  done

Measured memory_bytes: 11996
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();

		if(N%K==0)
			System.out.println(0);
		else
			System.out.println(1);
	}
}

Measured memory_bytes: 23636
w,h,n=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
a,b,c,d=0,w,0,h
for x,y,A in l:
    if A==1:
        a=max(a,x)
    elif A==2:
        b=min(b,x)
    elif A==3:
        c=max(c,y)
    else:
        d=min(d,y)
# print(f"b-a:{b-a},d-c:{d-c}")
print((b-a)*(d-c) if b-a>=0 and d-c>=0 else 0)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

void print_vector(vector<int>& v, int length) {
    cout << v[0];
    for (int i = 1; i < length; ++i)
        cout << ' ' << v[i];
    cout << '\n';
}

void insertion_sort(vector<int>& v, int length) {
    print_vector(v, length);

    for (int i = 1; i < length; ++i) {
        int tmp = v[i];
        int j = i - 1;
        while (j >= 0 && v[j] > tmp) {
            v[j + 1] = v[j];
            --j;
        }
        v[j + 1] = tmp;

        print_vector(v, length);
    }
}

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

    vector<int> v(n);
    for (int i = 0; i < n; ++i)
        cin >> v[i];

    insertion_sort(v, n);
}



Measured memory_bytes: 3084
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))

t_left = []
t_right = []
a_left = []
a_right = []
for i in range(N):
    if i == 0:
        t_left.append(T[i])
        t_right.append(T[i])
    else:
        if T[i] > T[i-1]:
            t_left.append(T[i])
            t_right.append(T[i])
        else:
            t_left.append(1)
            t_right.append(T[i])

for i in range(N - 1, -1, -1):
    if i == N - 1:
        a_left.append(A[i])
        a_right.append(A[i])
    else:
        if A[i] > A[i+1]:
            a_left.append(A[i])
            a_right.append(A[i])
        else:
            a_left.append(1)
            a_right.append(A[i])
a_left = a_left[::-1]
a_right = a_right[::-1]
# print(t_left)
# print(t_right)
# print(a_left)
# print(a_right)
ans = 1
MOD = int(1e9) + 7
for i in range(N):
    l = max(t_left[i], a_left[i])
    r = min(t_right[i], a_right[i])
    if l > r:
        print(0)
        exit()
    else:
        ans *= (r - l + 1)
        ans %= MOD
print(ans % MOD)


Measured memory_bytes: 19136
import java.util.Scanner;

public class Main {
	public static void main (String args[]) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		String t = scan.next();
		int a = scan.nextInt();
		int b = scan.nextInt();
		String u = scan.next();

		if(s.equals(u)) {
			a--;
		} else {
			b--;
		}
		
		System.out.println(a + " " + b);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
int main(){
  int n,k,ans=0;
  cin >> n >> k;
  vector<int> p(n);
  rep(i,n){
    cin >> p.at(i);
  }
  sort(p.begin(),p.end());
  rep(i,k){
    ans += p.at(i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3568
#include <stdio.h>
#include <string.h>

int main(){
	int A;
	char kataA[101];
	
	scanf("%d", &A);
	scanf("%s", kataA);
	
	int longKata=strlen(kataA);
	
	if(longKata>A){
		kataA[A]='\0';
		for(int i=0; kataA[i]!='\0'; i++){
				printf("%c", kataA[i]);
		}
		puts("...");
	}else{
		printf("%s", kataA);
	}
	
	return 0;
}

Measured memory_bytes: 1696
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define db long double
# define IOS ios_base :: sync_with_stdio(0)
char Buffer[1 << 16];void up(void){fread(Buffer,1,(1 << 16),stdin);}int cnt = 0;void sc(int &x){while (!('0' <= Buffer[cnt] && Buffer[cnt] <= '9')){++cnt;if (cnt == (1 << 16)) up(),cnt = 0;}x = 0;while ('0' <= Buffer[cnt] && Buffer[cnt] <= '9'){x = x * 10 + Buffer[cnt] - '0';++cnt;if (cnt == (1 << 16)) up(),cnt = 0;}}
# define halt(...) {fo << (__VA_ARGS__) << '\n';exit(0);}
# define CF
# define pp(n) cerr << #n << " = " << n << '\n'
# define ppp(v) for (auto it : v) cerr << it << ' ';cerr << '\n'
int s[1 << 20];
int p[1 << 20];
int main(void)
{
    #ifdef CF
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    fi>>n;
    int ans = 0;
    for (int i = 1;i <= n;++i)
        fi>>s[i];
    for (int i = 1;i <= n;++i)
        p[i] = i;
    sort(p+1,p+1+n,[&](int a,int b) {return s[a] < s[b];});
    for (int i = 1;i <= n;++i)
        ans += (p[i]&1) != (i&1);
    fo << (ans + 1) / 2 << '\n';
    return 0;
}




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

int main() {
  int64_t A,B,K;
  cin>>A>>B>>K;
  int64_t C,D;
  if(A<K){
    if(A+B<K)
      cout<<0<<" "<<0<<endl;
    else
      cout<<0<<" "<<A+B-K<<endl;
  }
  else
    cout<<A-K<<" "<<B<<endl;
}



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

int main()
{
	ios::sync_with_stdio(false);
	
	char a[15];
	long long len,s=0,m=0;
	cin>>a;
	
	len=strlen(a);
	
	for(int i=0;i<(1<<(len-1));i++)
	{
		m=a[0]-'0';
		for(int j=0;j<len-1;j++)
		{
			if(i&(1<<j))
			{
				s+=m;
				m=0; 
			}
			m=m*10+(a[j+1]-'0');
		}
		s+=m;
	}
	
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    ll n; cin >> n;
    char chr[27];
    int j = 1;
    for (char i = 'a'; i <= 'z'; i++)
    {
        chr[j] = i;
        j++;
    }

    string ans = "";
    if (n > 0 && n < 27)
    {
        cout << chr[n] << endl;
        return 0;
    }
    while(n != 0)
    {
        if (n % 26 == 0)
        {
            ans += 'z';
            n -= 26; // <-----これが大事！！
        }
        else ans += chr[n % 26];
        n /= 26;
    }
    reverse(ALL(ans));
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a!=b && a!=c){
		cout<<a;
	}else if(b!=a && b!=c){
		cout<<b;
	}else{
		cout<<c;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main(){
    ios::sync_with_stdio(false);
    int H, W, h, w;
    cin >> H >> W;
    cin >> h >> w;
    cout << (H-h)*(W-w) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

inline int read () {
    int ret = 0, t = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') t = -1, c = getchar();
    while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
    return ret * t;
}

int n;
int a[22][22] = {};
int w[33000] = {};
int st[22], top = 0;
int dp[22][33000] = {};

int main () {
    n = read();
    int i = read(), j, k, l;
    while (i--) { int x = read(), y = read(); a[x][y] = a[y][x] = read(); }
    for (i = 0; i < (1 << n); i++) {
        top = 0;
        for (j = 1; j <= n; j++) if ((i >> (j - 1)) & 1) st[++top] = j;
        for (j = 1; j <= top; j++) for (k = j; k <= top; k++) w[i] += a[st[j]][st[k]];
    }
    for (i = 1; i < (1 << n); i++) for (j = 1; j <= n; j++) dp[j][i] = -1;
    for (i = 1; i < (1 << n); i += 2) dp[1][i] = w[i];
    for (i = 1; i < (1 << n); i++) {
        for (j = 1; j <= n; j++) {
            if (!((i >> (j - 1)) & 1) || dp[j][i] == -1) continue;
            int tmp = (~i) & ((1 << n) - 1);
            for (k = tmp; k; k = (k - 1) & tmp) {
                for (l = 1; l <= n; l++)
                    if (((k >> (l - 1)) & 1) && a[l][j]) {
                        dp[l][i + k] = max(dp[l][i + k], dp[j][i] + w[k] + a[l][j]);
                    }
            }
        }
    }
    printf("%d\n", w[(1 << n) - 1] - dp[n][(1 << n) - 1]);
    return 0;
}

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

using namespace std;

#define IO ios_base::sync_with_stdio(0);cin.tie(0);

int main()
{
  IO;
  int n, k; cin >> n >> k;
  vector <int> a(n + 1);
  for (int i = 0; i < n; ++i)
  {
   int k; cin >> k;
   a[k]++;
  }
  sort(a.rbegin(), a.rend());

  int res = 0;
  for (int i = k; i < n + 1; ++i)
  if (a[i] != 0) res += a[i];
  else break;

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 1024
n = int(input())
a = [int(x) for x in input().split()]
count = 0

a = sorted(a)

max = a[len(a)-1]
line = [0]*(max+1)

for x in a:
    line[x] += 1
    
for x in a:
    if line[x] == 0:
        continue
    xx = x * 2
    j = 3
    while xx <= max:
        if line[xx] != 0:
            line[xx] = 0
        xx = x * j
        j += 1
for i in range(max+1):
    if line[i] == 1:
        count += 1
print(count)


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

int main() {
  int n;
  cin >> n;
  bool flag = true;
  vector<int> vec(n);
  for(int i=0; i<n; i++) cin >> vec[i];
  sort(vec.begin(),vec.end());
  for(int i=0; i<n-1; i++) if(vec[i] == vec[i+1]) flag = false;
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

#define mod 1000000007
#define INF 1000000000

#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define all(x) begin(x), end(x)
#define len(x) ((int)(x).size())
#define contains(a, x) (a.find(x) != end(a))
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define F(i,a,b) for(int i = (int)(a); i < (int)(b); ++i)
#define RF(i,a,b)for(int i = (int)(a); i >= (int)(b); --i)

using dbl = double;
using ll = long long;
using ull = unsigned ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pi = pair<int,int>;

#define log(x) cout << x << endl;
#define fast() {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}



int main() {
	int n, t, x;
	cin >> n >> t;
	vi a(n);
	rep (i, n) cin>>a[i];

	ll c = 0;
	rep (i, n-1) {
		c += min(t, a[i+1]-a[i]);
	}
	c += t;

	log(c)

	return 0;
}



Measured memory_bytes: 1024
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n:i64 = read();
    let an = read_vec::<i64>();
    let (mut odd,mut even) = an.into_iter().enumerate()
        .fold((vec![],vec![]),|(mut bn,mut cn),(i,x)|{
            if (i+1) % 2 == 0 {
                cn.push(x);
            } else {
                bn.push(x);
            }
            (bn,cn)
        });
    let ans = if n % 2 == 0 {
        even.reverse();
        even.append(&mut odd);
        even
    } else {
        odd.reverse();
        odd.append(&mut even);
        odd
    };
    let ans:Vec<String> = ans.into_iter()
        .map(|x|x.to_string()).collect();
    println!("{}",ans.connect(" "));
}

Measured memory_bytes: 18520
N = int(input())
data = []
cities = []

for i in range(1,N+1):
    c,p = input().split()
    data.append([c,-(int(p)),i])
    if c in cities:
        None
    else:
        cities.append(c)

cities.sort()

ans = []
for c in cities:
    b = [s for s in data if c in s]
    b.sort(key=lambda x: x[1])
    for i in range(len(b)):
        ans.append(b[i])

for i in range(N):
    print(ans[i][2])

Measured memory_bytes: 67216