akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
#else
#define db(x) 0
#define db2(x, y) 0
#define db3(x, y, z) 0
#define dbv(v) 0
#define dba(a, n) 0
#endif
typedef long long ll;
typedef long double ld;
char S[1000005];
vector<string> split(string s, char delim) {
	string cur;
	vector<string> ret;
	for (char c : s) {
		if (c == delim) {
			ret.push_back(cur);
			cur.clear();
		} else cur += c;
	}
	ret.push_back(cur);
	return ret;
}
int main() {
	scanf("%s", S);
	int n = strlen(S);
	n = unique(S, S + n) - S;
	S[n] = '\0';
	vector<int> cnt(3), singleCnt(3);
	for (int i = 0; i < n; ++i) ++cnt[S[i] - 'A'];
	int a = min_element(cnt.begin(), cnt.end()) - cnt.begin();
	fill(cnt.begin(), cnt.end(), 0);
	auto subs = split(string(S), 'A' + a);
	for (int i = 0; i < subs.size(); ++i) {
		if (i > 0 && i + 1 < subs.size() && subs[i].size() == 1) {
			++singleCnt[subs[i][0] - 'A'];
		}
		vector<bool> has(3);
		for (char x : subs[i]) has[x - 'A'] = true;
		for (int j = 0; j < 3; ++j)
			if (has[j]) ++cnt[j];
	}
	assert(cnt[a] == 0 && singleCnt[a] == 0);
	int b = a == 0 ? 1 : 0;
	int c = a == 2 ? 1 : 2;
	if (singleCnt[b] > cnt[c]) {
		swap(b, c);
	}
	assert(singleCnt[b] <= cnt[c]);
	if (singleCnt[c] > cnt[b]) {
		dbv(subs);
		db(singleCnt[c]);
		string cs;
		cs += c + 'A';
		vector<string> res = {subs[0]};
		for (int i = 1; i < subs.size(); ++i) {
			if (subs[i] == cs && singleCnt[c] > cnt[b]) {
				--singleCnt[c];
				res.back() += c + 'A';
			} else {
				res.push_back(subs[i]);
			}
		}
		subs = res;
	}
	dbv(subs);
	assert(singleCnt[c] <= cnt[b]);
	string ans;
	fill(cnt.begin(), cnt.end(), 0);
	for (int i = 0; i < subs.size(); ++i) {
		subs[i].erase(unique(subs[i].begin(), subs[i].end()), subs[i].end());
		for (char x : subs[i]) ++cnt[x - 'A'];
	}
	cnt[a] = (int)subs.size() - 1;
	if (cnt[b] > cnt[c]) swap(b, c);
	dbv(subs);
	assert(cnt[c] >= cnt[a]);
	assert(cnt[b] >= cnt[a]);
	for (int i = 0; i < subs.size(); ++i) {
		int lb = (i == 0 || i + 1 == subs.size()) ? 0 : 1;
		while (cnt[c] > cnt[b] && subs[i].size() >= lb + 1 && subs[i].back() == 'A' + c) {
			subs[i].pop_back();
			--cnt[c];
		}
		while (cnt[c] > cnt[b] && subs[i].size() >= lb + 1 && subs[i][0] == 'A' + c) {
			subs[i].erase(subs[i].begin());
			--cnt[c];
		}
	}
	assert(cnt[c] == cnt[b]);
	dbv(cnt);
	dbv(subs);
	for (int i = 0; i < subs.size(); ++i) {
		int lb = (i == 0 || i + 1 == subs.size()) ? 0 : 1;
		while (cnt[b] > cnt[a] && subs[i].size() >= lb + 2) {
			subs[i].pop_back();
			subs[i].pop_back();
			--cnt[b];
		}
		if (i) ans += a + 'A';
		ans += subs[i];
	}
	printf("%s\n", ans.c_str());
}


Measured memory_bytes: 23576
#include<cstdio>
 #include<cstring>
 #include<queue>
 #include<cmath>
 using namespace std;
 const int Ni = 300;
 const int MAX = 1<<26;
 struct Edge{
     int u,v,c;
     int next;
 }edge[4000];
 int n,m;
 int edn;//\u8fb9\u6570
 int p[Ni];//\u7236\u4eb2
 int d[Ni];
 int sp,tp;//\u539f\u70b9\uff0c\u6c47\u70b9

 void addedge(int u,int v,int c)
 {
     edge[edn].u=u; edge[edn].v=v; edge[edn].c=c;
     edge[edn].next=p[u]; p[u]=edn++;

     edge[edn].u=v; edge[edn].v=u; edge[edn].c=0;
     edge[edn].next=p[v]; p[v]=edn++;
 }
 int bfs()
 {
     queue <int> q;
     memset(d,-1,sizeof(d));
     d[sp]=0;
     q.push(sp);
     while(!q.empty())
     {
         int cur=q.front();
         q.pop();
         for(int i=p[cur];i!=-1;i=edge[i].next)
         {
             int u=edge[i].v;
             if(d[u]==-1 && edge[i].c>0)
             {
                 d[u]=d[cur]+1;
                 q.push(u);
             }
         }
     }
     return d[tp] != -1;
 }
 int dfs(int a,int b)
 {
     int r=0;
     if(a==tp)return b;
     for(int i=p[a];i!=-1 && r<b;i=edge[i].next)
     {
         int u=edge[i].v;
         if(edge[i].c>0 && d[u]==d[a]+1)
         {
             int x=min(edge[i].c,b-r);
             x=dfs(u,x);
             r+=x;
             edge[i].c-=x;
             edge[i^1].c+=x;
         }
     }
     if(!r)d[a]=-2;
     return r;
 }

 int dinic(int sp,int tp)
 {
     int total=0,t;
     while(bfs())
     {
         while(t=dfs(sp,MAX))
         total+=t;
     }
     return total;
}
int main(){
	scanf("%d%d",&n,&m);
	edn=0;
	memset(p,-1,sizeof(p));
	for (int i=0;i<m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		addedge(a-1,b-1,1);
		addedge(b-1,a-1,1);
	}
	scanf("%d%d",&sp,&tp);
	sp--;
	tp--;
	int ans=dinic(sp,tp),tot=0;
	for (int i=0;i<m;i++) if (edge[i*4+2].c==0) tot++;
	printf("%d\n%d\n",ans,tot);
	for (int i=0;i<m;i++) if (edge[i*4+2].c==0) printf("%d\n",i+1);
	
}

Measured memory_bytes: 1096
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define int long long
#define ld long double
#define sb __builtin_popcount
#define vi vector<int>
#define vc vector<char>
#define ii pair<int, int>
#define pq priority_queue<ii, vector<ii>, greater<ii>>
#define vii vector<ii>
#define sz(a) int((a).length())
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <=n; i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)
#define in(a, b) (b.find(a) != string::npos)
#define minin(a) *min_value(aint(a))
#define maxin(a) *max_value(aint(a))
#define X first
#define Y second
#define fiint(a, x) memset(a, x, lengthof(a))
#define pb push_back
#define pf push_front
#define mp make_pair
#define aint(v) v.begin(), v.end()
#define raint(v) reverse(v.begin(), v.end())
#define el "\n"
#define mx3(a, b, c) max(max(a, b), c)
#define mn3(a, b, c) min(min(a, b), c)
#define S(v) accumulate(aint(v), (int)0)
#define SP(n) cout.precision(n)
#define PI = atan(1.0) * 4.0;
const int M = 1e9 + 7;
void start() {
    fio;
    SP(10);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
    start();
    int n, ans,x,t;
    cin >> n>>x>>t;
    int p = n/x;
    if(n%x)p++;
    ans = p*t;
    cout << ans << el;
    return 0;
}

Measured memory_bytes: 3648
MOD = 10 ** 9 + 7
N = int(input())
C = list(map(int, input().split()))
C.sort()

if N == 1:
    print (2 * C[0] % MOD)
    exit()


lst = [0] * (N + 3)
lst[0] = 1
for i in range(1, N + 3):
    lst[i] = (lst[i - 1] * 2) % MOD


ANS = 0
for i, c in enumerate(C):
    ANS += c * (N + 1 - i)

ANS *= pow(2, N - 2, MOD)
ANS %= MOD
ANS *= pow(2, N, MOD)
print (ANS % MOD)

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

int main(){
    int c[3][3];
    for (int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> c[i][j];
        }
    }
    for (int i=0;i<3;i++){
        for(int j=1;j<3;j++){
            c[i][j]-=c[i][0];
        }
    }
   for (int i=1;i<3;i++){
        for(int j=1;j<3;j++){

            c[i][j]-=c[0][j];
        }
    }
bool res=true;
   for (int i=1;i<3;i++){
        for(int j=1;j<3;j++){
            if ( c[i][j]!=0)res=false;
        }
    }
if(res){
    cout <<"Yes"<<endl;
}else{
    cout <<"No"<<endl;
}
return 0;
}


Measured memory_bytes: 256
a,b,c=gets.split.map(&:to_i)
if a<=b && a<=c
    if b <= c
        puts "#{a} #{b} #{c}"
    else
        puts "#{a} #{c} #{b}"
    end
elsif b<a && b <= c
    if a <= c
        puts "#{b} #{a} #{c}"
    else
        puts "#{b} #{c} #{a}"
    end
else
    if a <= b
        puts "#{c} #{a} #{b}"
    else
        puts "#{c} #{b} #{a}"
    end
end
    


Measured memory_bytes: 6876
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll memo[100001];
vector<ll> edge[100001];
    
ll dp(ll i){
    if(memo[i]!=-1){
        return memo[i];
    }
    if(edge[i].empty()){
        return memo[i]=0;
    }else{
        ll max_v = 0;
        for (auto e : edge[i]) {
            max_v = max(max_v, dp(e)+1);
        }
        return memo[i]=max_v;
    }
    
}

int main() {
    ll n,m;
    std::cin >> n>>m;
    Fill(memo,-1);
    for (int i = 0; i < m; i++) {
        ll tmpx,tmpy;
        std::cin >> tmpx>>tmpy;
        tmpx--;
        tmpy--;
        edge[tmpx].push_back(tmpy);
    }
    ll result = 0;
    for (int i = 0; i < n; i++) {
        result = max(result,dp(i));
    }
    std::cout <<result << std::endl;
    
}


Measured memory_bytes: 8576
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

ans = 0
key = 0
for i in range(n):
  if a[i] > b[i] + key:
    ans += b[i] + key
    key = 0
  else:
    ans += a[i]
    if a[i] <= key:
      key = b[i]
    else:
      key = b[i] - (a[i] - key)
ans += min([key, a[n]])
print(ans)
    

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

ll a[100100];
ll acc[100100];
ll acc_plus[100100];

int main(void){
  int n,k;
  cin >> n >> k;
  acc[0] = 0;
  acc_plus[0] = 0;
  for(int i = 1;i <= n;++i){
    cin >> a[i];
    acc[i] = acc[i-1] + a[i];
    acc_plus[i] = acc_plus[i-1] + max((ll)0,a[i]);
  }
  ll res = 0;
  for(int i = 1;i+k-1 <= n;++i){
    //cout << i << " " << i+k-1 << endl;
    ll cres = max((ll)0,acc[i+k-1] - acc[i-1]);
    cres += acc_plus[i-1];
    cres += acc_plus[n] - acc_plus[i+k-1];
    res = max(res,cres);
    //cout << cres << endl;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 2560
def solve():
    S = input()

    if len(S) < 26:
        for a in [chr(ord("a")+i) for i in range(26)]:
            if a in S:
                continue
            print(S+a)
            return


    for i in range(26):
        for a in [chr(j) for j in range(ord(S[-1-i]), ord("z")+1)]:
            if a in S[:len(S)-i]:
                continue
            print(S[:len(S)-i-1]+a)
            return

    else:
        print(-1)

solve()

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

int main() {
    int64_t N;
    cin >> N;
    int64_t S,t,I,J;
    S = N - 1;
    t = 0;
    double M = sqrt(N);

    for (int64_t i = 1; i < M + 1; i++) {
     if (N % i != 0) {
            continue;
        }

        int64_t j = N / i;
        t = abs(j - i);

        if (t <= S) {
            S = t;
            I = i;
            J = j;
        }
    }

    int64_t sum = (I - 1) + (J - 1);

    cout << sum << endl;

}

Measured memory_bytes: 256
using System;

namespace A___ABC_ARC
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = int.Parse(Console.ReadLine());
            if (x < 1200)
            {
                Console.WriteLine("ABC");
            }
            else
            {
                Console.WriteLine("ARC");
            }
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
int main(){
    int n;
    cin >> n;
    map<string, int> mp;
    mp["AC"] = 0;
    mp["WA"] = 0;
    mp["TLE"] = 0;
    mp["RE"] = 0;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << "\n";
    cout << "WA x " << mp["WA"] << "\n";
    cout << "TLE x " << mp["TLE"] << "\n";
    cout << "RE x " << mp["RE"] << "\n";
    return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

struct tree{
	bool leaf;
	tree *left,*right;
	int size;
} *root;

string s;
int cur=0;
int n;
int depth=0,deepest=-1;
tree *dnode;
vector<tree*> cand;
vi parts;

tree* parse(){
	tree* res=new tree;
	if(depth > deepest){
		deepest=depth;
		dnode=res;
	}
	assert(s[cur]=='(');
	if(s[cur+1]==')'){
		res->leaf=1;
		res->size=0;
		cur+=2;
		return res;
	}
	res->leaf=0;
	res->size=1;
	cur++;
	depth++;
	res->left = parse();
	res->size += res->left->size;
	res->right = parse();
	res->size += res->right->size;
	assert(s[cur]==')');
	cur++;
	depth--;
	return res;
}

bool markcand(tree* node){
	if(node->leaf){
		return node == dnode;
	}
	if(markcand(node->left) || markcand(node->right)){
		if(n % node->size == 0){
			cand.pb(node);
		}
		return 1;
	}
	return 0;
}

bool match(tree* node,int id,tree* node2){
	if(node->leaf && node2->leaf){
		return 1;
	}
	if(node->leaf && !node2->leaf){
		return 0;
	}
	if(!node->leaf && node2->leaf){
		return match(node->left,id,cand[id]->left)
		&& match(node->right,id,cand[id]->right);
	}
	if(!node->leaf && !node2->leaf){
		return match(node->left,id,node2->left)
		&& match(node->right,id,node2->right);
	}
	return 0;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>s;
	root=parse();
	n=root->size;
	markcand(root);
	rep(i,sz(cand)){
		if(match(root,i,cand[i])){
			parts.pb(cand[i]->size);
		}
	}
	vi dp(sz(parts),INF);
	dp[0]=0;
	rep2(i,1,sz(parts)){
		rep(j,i)if(parts[i] % parts[j] == 0){
			dp[i]=min(dp[i],dp[j]+parts[i]/parts[j]-1);
		}
	}
	cout<<dp[sz(parts)-1]<<endl;
}

Measured memory_bytes: 15644
/*
  AOJ 2207
  Title:Consistet Unit System
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
#include <limits.h>
int  n;
int  unit_c;
char unit_name[200][17];
int  relation[200][200];

int regist(char *unit)
{
  int i;

  for(i=0;i<unit_c;i++)
    if(0==strcmp(unit,&unit_name[i][0]))
       return(i);

  strcpy(&unit_name[unit_c][0],unit);
  unit_c++;
  return(unit_c-1);
}
int solve()
{
  int i,j,k,flag;
  
  do
    {
      flag=0;
      for(i=0;i<unit_c;i++)
	for(j=0;j<unit_c;j++)
	  for(k=0;k<unit_c;k++)
	    if(i!=j && j!=k && k!=i)
	      if(relation[i][k]!=INT_MAX &&  relation[k][j]!=INT_MAX)
		  {
		    //printf(":%d %d %d |%d+%d =%d\n",i,k,j,relation[i][k],
		    //   relation[k][j],relation[i][j]);

		    if(relation[i][j]==INT_MAX)
		      {
			relation[i][j]=relation[i][k]+relation[k][j];  
			flag=-1;
		      }
		    else if(relation[i][k]+relation[k][j]
			    != relation[i][j])
		      return(0);
		  }
	      
    }  while(flag);
    return(-1);
}
void dump()
{
  int i,j,r;

  for(i=0;i<unit_c;i++)
    printf("%d %s\n",i,&unit_name[i][0]);
  
  for(i=0;i<unit_c;i++)
    for(j=0;j<unit_c;j++)
      if((r=relation[i][j])!=INT_MAX)
	printf("%s~%s %d\n",&unit_name[i][0],&unit_name[j][0],r);
}

main()
{
  int i,j,expo,un1,un2,ret;
  char unit1[17],unit2[17];

  while(scanf("%d ",&n) && n)
    {
      unit_c=0;
      memset(unit_name, 0,200*17);
      for(i=0;i<200;i++)
	for(j=0;j<200;j++)
	  relation[i][j]=INT_MAX;
      for(i=0;i<n;i++)
	{
	  scanf("1 %[a-z] = 10^%d %[a-z] ",unit1,&expo,unit2);
	  un1=regist(unit1);
	  un2=regist(unit2);
	  relation[un1][un2]=expo;
	  relation[un2][un1]=-expo;
	}
#ifdef DEBUG      
      dump();
#endif
      ret=solve();
      printf("%s\n",ret?"Yes":"No");
     }
  return(0);
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse4")
#pragma GCC optimize("unroll-loops")
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
using namespace std;
vi adj[100005],topo,comp;
vector<pii> adj2[100005];
vector<pair<pii,int>> edges;
bool vis[100005];
int pos[100005],A[100005],res[100005];
void dfs(int v){
	vis[v]=1;
	for(auto i:adj[v])
		if(!vis[i])
			dfs(i);
	topo.pb(v);
}
int Find(int x){
	int root=x,tmp;
	while(A[root]>=0)
		root=A[root];
	while(x!=root){
		tmp=A[x];
		A[x]=root;
		x=tmp;
	}
	return root;
}
void Union(int x,int y){
	x=Find(x),y=Find(y);
	if(x==y)
		return;
	if(A[x]>A[y])
		swap(x,y);
	A[x]+=A[y];
	A[y]=x;
}
void dfs(int v,int d){
	vis[v]=1;
	res[v]=d;
	comp.pb(v);
	for(auto x:adj2[v])
		if(!vis[x.F])
			dfs(x.F,d+x.S);
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	int n,m,i,l,r,d,mini,maxi;
	cin>>n>>m;
	for(i=1;i<=n;i++)
		A[i]=-1;
	while(m--){
		cin>>l>>r>>d;
		if(d==0)
			Union(l,r);
		else
			edges.pb(make_pair(make_pair(l,r),d));
	}
	for(auto x:edges){
		l=Find(x.F.F),r=Find(x.F.S);
		adj[l].pb(r);
	}
	set<int> nodes;
	for(i=1;i<=n;i++)
		nodes.insert(Find(i));
	for(auto x:nodes)
		if(!vis[x])
			dfs(x);
	reverse(all(topo));
	for(i=0;i<sz(topo);i++)
		pos[topo[i]]=i;
	for(auto x:edges){
		l=Find(x.F.F),r=Find(x.F.S);
		if(pos[l]>=pos[r]){
			cout<<"No";
			return 0;
		}
	}
	for(auto x:edges){
		l=Find(x.F.F),r=Find(x.F.S);
		adj2[l].pb(make_pair(r,x.S));
		adj2[r].pb(make_pair(l,-x.S));
	}
	memset(vis,0,sizeof vis);
	for(auto x:nodes)
		if(!vis[x]){
			comp.clear();
			dfs(x,0);
			mini=INT_MAX,maxi=INT_MIN;
			for(auto y:comp){
				mini=min(mini,res[y]);
				maxi=max(maxi,res[y]);
			}
			if(maxi-mini>1000000000){
				cout<<"No";
				return 0;
			}
			for(auto y:comp)
				res[y]-=mini;
		}
	for(i=1;i<=n;i++)
		res[i]=res[Find(i)];
	for(auto x:edges)
		if(res[x.F.S]-res[x.F.F]!=x.S){
			cout<<"No";
			return 0;
		}
	cout<<"Yes";
    return 0;
}

Measured memory_bytes: 26224
import java.util.Arrays;
import java.util.Scanner;

//Modular Query
public class Main{

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), q = sc.nextInt();
		boolean[] a = new boolean[300001];
		for(int i=0;i<n;i++)a[sc.nextInt()]=true;
		while(q--!=0){
			int m = sc.nextInt();
			int res = m-1;
			while(0<res){
				boolean e = false;
				for(int i=res;i<=300000;i+=m)if(a[i]){
					e = true; break;
				}
				if(e)break;
				res--;
			}
			System.out.println(res);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 139928
#include <iostream>
using namespace std;
int main() {
  int k;
  cin >> k;
  int ans;
  if (k % 2 == 0) {
    ans = k * k / 4;
  }
  else {
    ans = (k - 1) * (k + 1) / 4;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

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

int cv(char c){
    if(c=='E') return 0;
    if(c=='N') return 1;
    if(c=='W') return 2;
    if(c=='S') return 3;
}

const int N = 52;
bool road[N][N][4]={};
bool dp[N][N][4];
bool nxt[N][N][4];

const int T = 1010;
int md[T];

int main(){
    int n,x0,y0,t;
    cin >>n >>x0 >>y0 >>t;

    rep(i,n){
        int ax,ay,bx,by;
        cin >>ax >>ay >>bx >>by;

        if(ax==bx){
            int x = ax;
            int ly = min(ay,by), ry = max(ay,by);
            road[ly][x][1] = true;
            for(int y=ly+1; y<ry; ++y) road[y][x][1] = road[y][x][3] = true;
            road[ry][x][3] = true;
        }
        else{
            assert(ay==by);
            int y = ay;
            int lx = min(ax,bx), rx = max(ax,bx);
            road[y][lx][0] = true;
            for(int x=lx+1; x<rx; ++x) road[y][x][0] = road[y][x][2] = true;
            road[y][rx][2] = true;
        }
    }

    int d_sum = 0;
    memset(md,-1,sizeof(md));
    rep(i,t){
        int d;
        char c;
        cin >>d >>c;

        d_sum += d;
        md[d_sum] = cv(c);
    }

    rep(d,4) dp[y0][x0][d] = road[y0][x0][d];

    for(int i=1; i<=d_sum; ++i){

        rep(y,N)rep(x,N)rep(d,4)if(dp[y][x][d]){
            int ny = y+dy[d], nx = x+dx[d];
            for(int j=-1; j<=1; ++j){
                int nd = (d+j+4)%4;
                if(road[ny][nx][nd]){
                    if(md[i]==-1 || (d==md[i] || nd==md[i])) nxt[ny][nx][nd] = true;
                }
            }
        }

        rep(y,N)rep(x,N)rep(d,4){
            dp[y][x][d] = nxt[y][x][d];
            nxt[y][x][d] = false;
        }
    }

    vector<pi> ans;
    rep(y,N)rep(x,N)rep(d,4){
        if(dp[y][x][d]) ans.pb({x,y});
    }

    sort(all(ans));
    ans.erase(unique(all(ans)), ans.end());
    for(const auto &p:ans) cout << p.fi << " " << p.se << endl;
    return 0;
}



Measured memory_bytes: 3140
n,t=map(int,input().split())
a=list(map(int,input().split()))
x=[0]*n
x[0]=a[0]
for i in range(1,n):
    x[i]=min(x[i-1],a[i])
d=dict()
for i in range(1,n):
    y=a[i]-x[i-1]
    if y>0:
        if y in d:
            d[y]+=1
        else:
            d[y]=1
d=list(d.items())
d.sort(reverse=True)
print(d[0][1])

Measured memory_bytes: 25052
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int n;
using P = pair<Int, Int>;
vector<P> v;
vector<Int> xs, ys;
class unionfind{ // 0-indexed
public:
	vector<int> parent;
	vector<size_t> size;
	size_t num_of_disjointsets;
	unionfind(size_t n){
		parent.resize(n, -1);
		size.resize(n, 1);
		num_of_disjointsets = n;
	}

	size_t find(size_t x){
		if(parent[x] == -1) return x;
		return parent[x] = find(parent[x]);
	}

	size_t unite(size_t x, size_t y){
		x = find(x);
		y = find(y);
		if(x == y) return -1;
		if(size[x] < size[y]){
			parent[x] = y;
			size[y] += size[x];
			size[x] = 0;
			--num_of_disjointsets;
			return y;
		}else{
			parent[y] = x;
			size[x] += size[y];
			size[y] = 0;
			return x;
			--num_of_disjointsets;
		}
	}

	bool united(size_t x, size_t y){
		return find(x) == find(y);
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	for(Int i=0; i<n; ++i){
		Int x, y; cin >> x >> y;
		v.push_back(P(x, y));
		xs.push_back(x);
		ys.push_back(y);
	}
	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	ys.erase(unique(ys.begin(), ys.end()), ys.end());
	for(Int i=0; i<n; ++i){
		v[i].first = lower_bound(xs.begin(), xs.end(), v[i].first)-xs.begin();
		v[i].second = lower_bound(ys.begin(), ys.end(), v[i].second)-ys.begin();
	}
	unionfind uf(xs.size()+ys.size());
	for(Int i=0; i<n; ++i)
		uf.unite(v[i].first, xs.size()+v[i].second);
	vector<Int> num(xs.size()+ys.size()), nx(xs.size()+ys.size()), ny(xs.size()+ys.size());
	for(Int i=0; i<n; ++i) ++num[uf.find(v[i].first)];
	for(size_t i=0; i<xs.size(); ++i) ++nx[uf.find(i)];
	for(size_t i=0; i<ys.size(); ++i) ++ny[uf.find(xs.size()+i)];
	Int ans = 0;
	for(size_t i=0; i<xs.size()+ys.size(); ++i)
		if(uf.find(i) == i)
			ans += nx[i] * ny[i] - num[i];
	cout << ans << "\n";
/*	for(Int i=0; i<n; ++i)
		cerr << v[i].first << " " << v[i].second << "\n";
	for(size_t i=0; i<nx.size(); ++i)
		cerr << nx[i] << " \n"[i+1==nx.size()];
	for(size_t i=0; i<ny.size(); ++i)
		cerr << ny[i] << " \n"[i+1==ny.size()];*/
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e3 + 5);
const int MAX_SIZE = (int)(MAX_N * MAX_N);

/////////////////////////////////////////////////////////////
// node in { 0, ... }
class TopologicalSort {
  using ts_graph = vector<vector<int>>;

 public:
  static const int MAX_N = (int)(8e5 + 100);

  int n;
  ts_graph graph;
  vector<int> topological_sorted;
  vector<int> flg;  // 0: not-visited, 1: done, -1, temporary

  bool no_loop;

  TopologicalSort(ts_graph graph, int n) {
    this->flg = vector<int>(n, 0);
    this->graph = graph;
    this->n = n;
    init();
  }

  void init() {
    topological_sort();
  }

  bool visit(int i) {
    if (flg[i] == -1) {
      return false;
    }

    if (flg[i] == 0) {
      flg[i] = -1;

      for (auto &e : graph[i]) {
        if (!visit(e)) {
          return false;
        }
      }

      flg[i] = 1;

      topological_sorted.push_back(i);

      return true;
    }

    return true;
  }

  void topological_sort() {
    for (int i = 0; i < n; ++i) {
      flg[i] = 0;
    }

    for (int i = 0; i < n; ++i) {
      if (flg[i] == 0) {
        if (!visit(i)) {
          no_loop = false;
          return;
        }
      }
    }

    reverse(topological_sorted.begin(), topological_sorted.end());

    no_loop = true;
    return;
  }

  bool contains_loop() {
    return !no_loop;
  }

  vector<int> &get_sorted() {
    return topological_sorted;
  }
};
/////////////////////////////////////////////////////////////

int n;

int tmp[MAX_N];
vector<vector<int>> graph(MAX_SIZE);
unordered_map<int, int> memo;

int make_key(int a, int b) {
  return min(a, b) * n + max(a, b);
}

int depth(int cur) {
  if (memo.find(cur) != memo.end()) return memo[cur];

  if (graph[cur].size() == 0) {
    return memo[cur] = 1;
  }

  int ret = -1;

  for (auto &e : graph[cur]) {
    ret = max(ret, depth(e));
  }

  ret += 1;

  return memo[cur] = ret;
}

int main(void) {
  // Here your code !
  scanf("%d", &n);

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

    int last = make_key(i, tmp[1]);

    for (int j = 2; j <= n - 1; ++j) {
      int cur = make_key(i, tmp[j]);
      graph[last].push_back(cur);
      last = cur;
    }
  }

  TopologicalSort ts(graph, MAX_SIZE);

  if (ts.contains_loop()) {
    printf("-1\n");
    return 0;
  }

  int ans = -1;

  for (int i = 0; i < MAX_SIZE; ++i) {
    ans = max(ans, depth(i));
  }

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

  return 0;
}


Measured memory_bytes: 126704
let n = int (stdin.ReadLine())
let a = stdin.ReadLine().Split() |> Array.mapi (fun i x -> int64 x - int64 i + 1L) |> Array.sort
let b = if n % 2 = 0 then (a.[n / 2] + a.[n / 2 - 1]) / 2L else a.[n / 2]
printfn "%d" (Array.fold (fun (l : int64) k -> l + abs (k - b)) 0L a)

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

using namespace std;

int main(){
  int n,m;
  vector < pair<long long int,long long int> > ab;
  cin >> n >> m;
  for(int i = 0;i < n;i++){
    long long int a,b;
    cin >> a >> b;
    ab.push_back(make_pair(a,b));
  }
  sort(ab.begin(),ab.end());
  long long int count = 0;
  long long int ans = 0;
  int i = 0;

  if(n == 1){
    ans = ab[i].first*m;
    cout << ans << endl;
    return 0;
  }

  while(count != m){
    if(m-count-ab[i].second >= 0){
      count += ab[i].second;
      ans += ab[i].first * ab[i].second;
    }
    else if(m-count-ab[i].second < 0){
      int c = m-count;
      ans += ab[i].first * c;
      count = m;
    }
    i++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2420
#include <stdio.h>
#include <math.h>
typedef long long ll;

ll sum(ll a) {
  ll ans = 0;
  while(a) ans += a % 10, a /= 10;
  return ans;
}

ll powi(ll a, ll b) {
  ll ans = 1;
  while(b) {
    if(b & 1) ans *= a;
    a *= a, b >>= 1;
  }
  return ans;
}

int main(void) {
  ll i, a, n, m, ans = 0;
  scanf("%lld%lld%lld", &a, &n, &m);
  for(i = 1; powi(i, n) <= m; ++i) if(powi(i, n) == powi(sum(powi(i, n)) + a, n)) ++ans;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 2740
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <stack>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#define popcount(x) __builtin_popcount(x)
#define oddparity(x) __builtin_parity(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define sf scanf
#define pf printf
#define ll long long int
using namespace std;

ll x, y;

int main()
{
    sf("%lld%lld", &x, &y);
    if (abs(x-y) <= 1) pf("Brown\n");
    else pf("Alice\n");
    return 0;
}

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

int main(){
  int H,W;
  string naka;
  cin >> H >> W;
  for(int i=0;i<W+2;i++){
    cout << "#";
  }
  cout << endl;
  for(int i=0;i<H;i++){
    cin >> naka;
    cout << "#" << naka << "#" << endl;;
  }
  for(int i=0;i<W+2;i++){
    cout << "#";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
const ll infinity = 9e18;

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast


    int n;
    cin>>n;

    vpi vp(n);

    forn(i,0,n)
    {
        vp[i].ss = i+1;
        cin>>vp[i].ff;
    }    
        
    sort(all(vp));


    forn(i,0,n)
    {
        cout<<vp[i].ss<<" ";
    }








    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#include <bitset>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
const int inf=1039074182;
const int mod=1e9+7;
using namespace std;
int x1,x2,x3,x4,x5,x6;
int y1,y2,y3,y4,y5,y6;
ll zl[1000005];
ll yl[1000005];
ll sl[1000005];
ll xl[1000005];
ll zr[1000005];
ll yr[1000005];
ll sr[1000005];
ll xr[1000005];

namespace combinatorics
{
	int *fac;
	int *ifac;
	int __Tmod;
	inline int add(int a,int b)
	{
		return (a+b)%__Tmod;
	}
	inline int sub(int a,int b)
	{
		return (a-b+__Tmod)%__Tmod;
	}
	inline int mult(int a,int b)
	{
		return (1LL*a*b)%__Tmod;
	}
	inline int fastpow(int basic,int x)
	{
		int res=1;
		while(x)
		{
			if(x&1)	res=mult(res,basic);
			basic=mult(basic,basic);
			x>>=1;
		}
		return res;
	}
	inline int inv(int x)
	{
		return fastpow(x,__Tmod-2);
	}
	void init(int n,int tmod)
	{
		__Tmod=tmod;
		fac=new int[n+5];
		ifac=new int[n+5];
		fac[0]=1;
		for(int i=1;i<=n;i++)
		{
			fac[i]=mult(fac[i-1],i);
		}
		ifac[n]=inv(fac[n]);
		for(int i=n-1;i>=0;i--)
		{
			ifac[i]=mult(ifac[i+1],i+1);
		}
	}
	inline int C(int n,int m)
	{
		return mult(mult(fac[n],ifac[m]),ifac[n-m]);
	}
	inline int Cat(int x)
	{
		return mult(C(x*2,x),inv(x+1));
	}
};
using namespace combinatorics;

inline ll calc(int sx,int sy,int ex,int ey)
{
	if(sx>ex) return 0;
	if(sy>ey) return 0;
	return C(ex-sx+ey-sy,ex-sx);
}

inline ll lenof(int sx,int sy,int ex,int ey)
{
	return abs(sx-ex)+abs(sy-ey);
}

inline ll solve(int sx,int sy,int ex,int ey)
{
	ll res=0;
	for(int i=x3;i<=x4;i++)
	{
		res=add(res,mult(mult(calc(sx,sy,i,y4),calc(i,y4+1,ex,ey)),i+y4+1));
		res=sub(res,mult(mult(calc(sx,sy,i,y3-1),calc(i,y3,ex,ey)),i+y3));
	}
	for(int j=y3;j<=y4;j++)
	{
		res=add(res,mult(mult(calc(sx,sy,x4,j),calc(x4+1,j,ex,ey)),x4+j+1));
		res=sub(res,mult(mult(calc(sx,sy,x3-1,j),calc(x3,j,ex,ey)),j+x3));
	}
	return res;
}

int main()
{
//	freopen("input.txt","r",stdin);
	init(4e6,mod);
	cin>>x1>>x2>>x3>>x4>>x5>>x6>>y1>>y2>>y3>>y4>>y5>>y6;
	ll res=0;
	res+=solve(x1-1,y1-1,x5,y5);
	res+=solve(x1-1,y1-1,x6+1,y6+1);
	res+=solve(x2,y2,x5,y5);
	res+=solve(x2,y2,x6+1,y6+1);
	res+=solve(x1-1,y2,x6+1,y5);
	res+=solve(x1-1,y2,x5,y6+1);
	res+=solve(x2,y1-1,x5,y6+1);
	res+=solve(x2,y1-1,x6+1,y5);
	
	res-=solve(x1-1,y1-1,x6+1,y5);
	res-=solve(x1-1,y1-1,x5,y6+1);
	res-=solve(x2,y2,x5,y6+1);
	res-=solve(x2,y2,x6+1,y5);
	res-=solve(x1-1,y2,x5,y5);
	res-=solve(x1-1,y2,x6+1,y6+1);
	res-=solve(x2,y1-1,x5,y5);
	res-=solve(x2,y1-1,x6+1,y6+1);
	res%=mod;
	if(res<0) res+=mod;
	
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 31488
#include <cstdio>
#include <string>
#include <vector>
class Tree {
public:
  Tree() = default;
  Tree(size_t n) : n_(n) {
    size_t x = 1;
    while (x < n) {
      x *= 2;
    }
    offset_ = x;
    sum_.resize(2 * x + 2);
  }

  void set(size_t pos, int value) {
    pos += offset_;
    sum_[pos] = value;
    pos /= 2;
    while (pos != 0) {
      sum_[pos] = sum_[pos * 2] + sum_[pos * 2 + 1];
      pos /= 2;
    }
  }

  int sum(size_t l, size_t r) {
    l += offset_;
    r += offset_;
    if (l == r) {
      return sum_[l];
    }
    int res = sum_[l] + sum_[r];
    while (l + 1 < r) {
      if (l % 2 == 0) {
        res += sum_[l + 1];
      }
      if (r % 2 == 1) {
        res += sum_[r - 1];
      }
      l /= 2;
      r /= 2;
    }
    return res;
  }

  size_t n_;
  size_t offset_;
  std::vector<int> sum_;
};

class Task {
public:
  bool run() {
    int n;
    if (scanf("%d", &n) != 1) {
      return false;
    }
    s_.resize(n + 3);
    scanf("%s", &s_[0]);
    for (int i = 0; i < 26; i++) {
      trees_[i] = Tree(n);
    }
    for (int i = 0; i < n; i++) {
      trees_[s_[i] - 'a'].set(i, 1);
    }
    int q;
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
      int type;
      scanf("%d", &type);
      if (type == 2) {
        int l, r;
        scanf("%d%d", &l, &r);
        l--;
        r--;
        int sum = 0;
        for (int i = 0; i < 26; i++) {
          sum += trees_[i].sum(l, r) != 0;
        }
        printf("%d\n", sum);
      } else {
        int pos;
        char c = ' ';
        scanf("%d", &pos);
        pos--;
        while (c == ' ') {
          scanf("%c", &c);
        }
        trees_[s_[pos] - 'a'].set(pos, 0);
        s_[pos] = c;
        trees_[s_[pos] - 'a'].set(pos, 1);
      }
    }
    return true;
  }

private:
  std::string s_;
  Tree trees_[26];
};
int main() {
  while (true) {
    Task task;
    if (!task.run()) {
      break;
    }
  }
}


Measured memory_bytes: 107392
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,ans=0;
    int data[1000];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> data[i];
    }
    sort(data,data+n);
    for(int i=0;i<n;i++){
        ans=data[n-1]-data[0];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B,C;
  cin>>A>>B>>C;
 
if(A==B&&B!=C){
cout<<"Yes"<<endl;
}else if(B==C&&C!=A){
cout<<"Yes"<<endl;
}else if(C==A&&A!=B){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}


Measured memory_bytes: 256
from scipy.sparse.csgraph import floyd_warshall
import itertools

n,m,r=[int(x) for x in input().split()]
rlist=[int(x)-1 for x in input().split()]
abc=[[int(x) for x in input().split()] for _ in range(m)]

adj=[[float("inf")]*n for _ in range(n)]

for item in abc:
  if item[2]<adj[item[0]-1][item[1]-1]: adj[item[0]-1][item[1]-1]=item[2]
  if item[2]<adj[item[1]-1][item[0]-1]: adj[item[1]-1][item[0]-1]=item[2] 

adj=floyd_warshall(adj)

res=float("inf")

for route in itertools.permutations(rlist):
  tmp=sum([adj[route[i]][route[i+1]] for i in range(len(route)-1)])
  if tmp<res: res=tmp

print(int(res))  

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

struct NODE{
	int key;
	int inserted = 0;
	NODE* parent = nullptr;
	NODE* left = nullptr;
	NODE* right = nullptr;
};

void show_key(NODE *node){
	cout << " " << node->key;
}

void show_preorder(NODE *node){
	show_key(node);
	if(node->left != nullptr)
		show_preorder(node->left);
	if(node->right != nullptr)
		show_preorder(node->right);
}

void show_inorder(NODE *node){
	if(node->left != nullptr)
		show_inorder(node->left);

	show_key(node);

	if(node->right != nullptr)
		show_inorder(node->right);
}

void print(NODE *node){
	show_inorder(node);
	cout << endl;
	show_preorder(node);
	cout << endl;
}

void insert(NODE *node, int &insert_key){
	if(!node->inserted){ // If not inserted
		node->key = insert_key;
		node->inserted = 1;
		return;
	}else if(node->key < insert_key){
		if(node->right == nullptr){
			NODE *new_node = new NODE; 
			node->right = new_node;
		}
		insert(node->right, insert_key);
		return;
	}else{
		if(node->left == nullptr){
			NODE *new_node = new NODE;
			node->left = new_node;
		}
		insert(node->left, insert_key);
		return;
	}

}

void find(NODE *node, int &key){
	if(node->key == key){
			cout << "yes" << endl;
	}else if(node->left == nullptr && node->right==nullptr){
		cout << "no" << endl;
	}else if(node->key < key){
		if(node->right==nullptr){
			cout << "no" << endl;
			return;
		}
		find(node->right, key);		
	}else if(key < node->key){
		if(node->left==nullptr){
			cout << "no" << endl;
			return;
		}
		find(node->left, key);
	}
	return;
}

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

	char command[8];
	int insert_key;
	int key;
	NODE* root_node = new NODE;
	for(int i=0; i<m; ++i){
		cin >> command;
		if(command[0] == 'i'){
			cin >> insert_key;
			insert(root_node, insert_key);
		}else if(command[0] == 'p'){
			print(root_node);
		}else if(command[0] == 'f'){
			cin >> key;
			find(root_node, key);
		}
	}
	return 0;
}


Measured memory_bytes: 21756
#include <iostream>
using namespace std;
typedef long long ll;
ll a,b,x;
inline ll f(ll n)
{
	if(-1==n)
	{
		return 0;
	}
	else
	{
		return n/x+1; 
	}
} 
int main()
{
	cin>>a>>b>>x;
	cout<<f(b)-f(a-1)<<endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
ans=[]
for i in range(n):
  ans.append(int(input()))
ans.sort()
counter=0
re=[]
for i in range(n):
  re.append(ans[i])
re.reverse()
pointer1=0
pointer2=0
thing=0
a=[]
while counter<n-2:
  if thing==0:
    a.append(ans[pointer1])
    pointer1+=1
    thing=1
  else:
    a.append(re[pointer2])
    pointer2+=1
    thing=0
  counter+=1
final=[]
final.append(re[pointer2])
for i in a:
  final.append(i)
final.append(ans[pointer1])
maxans=0
for i in range(n-1):
  maxans+=abs(final[i]-final[i+1])
pointer1=0
pointer2=0
thing=1
a=[]
counter=0
while counter<n-2:
  if thing==0:
    a.append(ans[pointer1])
    pointer1+=1
    thing=1
  else:
    a.append(re[pointer2])
    pointer2+=1
    thing=0
  counter+=1
final=[]
final.append(re[pointer2])
for i in a:
  final.append(i)
final.append(ans[pointer1])
maxans1=0
for i in range(n-1):
  maxans1+=abs(final[i]-final[i+1])
print(max(maxans1,maxans))

Measured memory_bytes: 110392
#include<iostream>
#include<vector>
#include<numeric>
#define ll long long
using namespace std;

int main() {
  ll N,b,i = 0;
  cin >> N;
  std::vector<ll> A(N);
  std::vector<ll> B(N-1);
  while(cin >> b) {
    B[i] = b;
    i++;
  }
  if (N == 2) cout << 2*B[0] << endl;
  else {
    A[N-1] = B[N-1 -1];
    for(ll j = N-2; j >= 0; j--) {
      if (j >= 1) A[j] = std::min(B[j],B[j-1]);
      else A[j] = std::min(B[j],B[0]);
    }
    cout << std::accumulate(A.begin(),A.end(),0) << endl;
  }
}


Measured memory_bytes: 256
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

#define int long long

template<typename A, size_t N, typename T>

void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//ここにグローバル変数宣言

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//ここに関数宣言



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



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

int blue=0;

blue+= N/(A+B)*A ;

if (N -( N/(A+B) * (A+B) ) > A)
{
	blue+=A;
}
else {blue+= N -( N/(A+B) * (A+B));}

cout <<blue<<endl;





























return 0;

}

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

using namespace std;

int main(){
	int N,M;
	while(cin>>N>>M,N){
		vector<vector<long long>>L(N,vector<long long>(N));
		vector<vector<long long>>S(N,vector<long long>(N));
		for(int i=0;i<N;++i){
			for(int j=0;j<N;++j){
				if(i==j){
					L[i][j]=0;
					S[i][j]=0;
				}else{
					L[i][j]=1e8;
					S[i][j]=1e8;
				}
			}
		}
		for(int i=0;i<M;++i){
			int x,y,t;
			char sl;
			cin>>x>>y>>t>>sl;
			--x;
			--y;
			if(sl=='L'){
				L[x][y]=t;
				L[y][x]=t;
			}else{
				S[x][y]=t;
				S[y][x]=t;
			}
		}
		int R;
		cin>>R;
		vector<int>z(R);
		for(int i=0;i<R;++i){
			int a;
			cin>>a;
			z[i]=--a;
		}
		for(int k=0;k<N;++k){
			for(int i=0;i<N;++i){
				for(int j=0;j<N;++j){
					L[i][j]=min(L[i][j],L[i][k]+L[k][j]);
					S[i][j]=min(S[i][j],S[i][k]+S[k][j]);
				}
			}
		}
		vector<vector<long long>>dp(R,vector<long long>(N,1e10));
		dp[0][z[0]]=0;
		long long ans=1e18;
		for(int i=1;i<R;++i){
			for(int j=0;j<N;++j){
				dp[i][j]=dp[i-1][j]+L[z[i-1]][z[i]];
				for(int k=0;k<N;++k){
					dp[i][j]=min(dp[i][j],dp[i-1][k]+L[z[i-1]][k]+S[k][j]+L[j][z[i]]);
				}
				if(i==R-1){
					ans=min(ans,dp[i][j]);
				}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 5204
N,M = map(int, input().split())
am = list(map(int, input().split()))
c = [0,2,5,5,4,5,6,3,7,6]
f = [-1]*10010
f[0]=0
for i in range(1,N+1):
    for x in am:
        if i-c[x] >= 0:
            f[i] = max(f[i], f[i-c[x]]*10 +x)
            
print(f[N])

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

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

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
    int n,m; cin >> n >> m;
    vector<vector<int>> jobs(m); REP(i,n) {
        int a, b; cin >> a >> b;
        if (a > m) continue;
        jobs[m-a].PB(b);
    }

    ll ans = 0;
    priority_queue<int> que;
    // jobsのkeyはお金をもらえるタイミングで最も遅いときvalueは報酬
    // 逆順でやることでqueに入る要素はi日目では全部補修を受けられる
    REPD(i,m) { 
        for(auto j : jobs[i]) que.push(j);
        if (!que.empty()) {
            int top_item = que.top(); que.pop();
            ans+=top_item;
        }
    }
    cout << ans << "\n";
    return 0;
}




Measured memory_bytes: 5504
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,k=map(int,input().split())\n"
"a=(n-k)*(n-k+1)//2\n"
"for i in range(k+1,n):\n"
"    j=n//i*i\n"
"    a+=(j//i-1)*(i-k)+max(n-j+1-max(k,1),0)\n"
"print(a)\n"
"\"";
  system(s);
  return 0;
}            

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

int main(){
  string s;
  int k;

  cin>>s>>k;
  int i = 0;
  while(i < s.size()){
    if(k >= ('z' - s[i] + 1) % 26){
      k -= ('z' - s[i] + 1) % 26;
      s[i] = 'a';
    }
    i++;
  }
  if(k) s[s.size() - 1] = 'a' + (s[s.size() - 1]  - 'a' + k) % 26;
  cout << s << endl;
}

Measured memory_bytes: 3740
#include <iostream>
#include <cmath>

using namespace std;

int path(int pedra);

int n_pedras, pulo_maximo;

int altura_pedras[100001];

int custos[100001];

int main(){
    cin >> n_pedras >> pulo_maximo;

    for(int i = 1; i <= n_pedras; i++){
        cin >> altura_pedras[i];
    }

    for(int i = 1; i <= n_pedras; i++){
        custos[i] = -1;
    }

    int custo_minimo = path(1);

    cout << custo_minimo << endl;

    return 0;
}

int path(int pedra){
    if(pedra == n_pedras){
        return 0;
    }

    if(custos[pedra] == -1){
        int pulos[pulo_maximo + 1];

        for(int i = 1; i <= pulo_maximo; i++){
            if(pedra + i <= n_pedras){
                 pulos[i] = abs(altura_pedras[pedra] - altura_pedras[pedra + i]) + path(pedra + i);
            }
        }

        int custo_minimo = pulos[1];

        for(int i = 2; i <= pulo_maximo; i++){
            if(pedra + i <= n_pedras){
                if(pulos[i] < custo_minimo){
                    custo_minimo = pulos[i];
                }
            }
        }

        custos[pedra] = custo_minimo;
    }

    return custos[pedra];
}

Measured memory_bytes: 49408