akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<int,int> P;
struct edge{ int to,cost; };
#define VMAX 100000
//bool cmp(P a,P b){ return a.second < b.second;}

ll N,M,K,ans=0;
ll C;
ll X[100010],V[100010];
ll dis[100010],va[100010];
ll rdis[100010],rva[100010];
unordered_map<ll,ll> Q;
int main(){
	std::ios_base::sync_with_stdio(false);
	cin>>N>>C;
	REP(i,N){
		cin>>X[i]>>V[i];
		rdis[N-1-i]=C-X[i];
		dis[i]=X[i];
		rva[N-1-i]=va[i]=V[i];
	}
	REP(i,N){rva[i+1]+=rva[i];va[i+1]+=va[i];}
//	REP(i,N){DEB(dis[i])DEB(va[i])DEB(rdis[i])DEB(rva[i])END}
	REP(k,2){
		ll temp=0,buff=0;
		if(k==0){
			REP(i,N+1){
				if(i==0){temp=rva[N-1]-rdis[N-1]*2;}
				else{
					buff=max(buff,va[i-1]-dis[i-1]);
					if(i==N)temp=max(temp,buff);
					else temp=max(temp,rva[N-1-i]-rdis[N-1-i]*2+buff);
				}
			}
			ans=max(temp,ans);
		}else{
			REP(i,N+1){
				if(i==0)temp=va[N-1]-dis[N-1]*2;
				else{
					buff=max(buff,rva[i-1]-rdis[i-1]);
					if(i==N)temp=max(temp,buff);
					else temp=max(temp,va[N-1-i]-dis[N-1-i]*2+buff);
				}
			}
			ans=max(temp,ans);
		}
	}

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

Measured memory_bytes: 4992
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MAX = 310;
double dp[MAX][MAX][MAX];
double n;
double dfs(int c1, int c2, int c3) {
  if (dp[c1][c2][c3] >= 0)
    return dp[c1][c2][c3];
  double res = 0;
  if (c1)
    res += c1/n*dfs(c1-1, c2, c3); //(寿司が1個の皿を選ぶ確率)*(その後かかる手数の期待値)
  if (c2)
    res += c2/n*dfs(c1+1, c2-1, c3); //(寿司が2個の皿を選ぶ確率)*(その後かかる手数の期待値)
  if (c3)
    res += c3/n*dfs(c1, c2+1, c3-1); //(寿司が3個の皿を選ぶ確率)*(その後かかる手数の期待値)
  res++; //(求めたい期待値(dp[c1][c2][c3])) == 1+(操作後にかかる手数の期待値)
  res /= 1-(n-c1-c2-c3)/n;
  //(寿司が0個の皿を選ぶ確率)*(その後かかる手数の期待値) == (n-c1-c2-c3)/n*dp[c1][c2][c3] -> 式変形してdp[c1][c2][c3]を消す
  return dp[c1][c2][c3] = res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  vector<int> a(n);
  int num[3] = {};
  rep(i, n) {
    cin >> a[i];
    num[a[i]-1]++;
  }
  memset(dp, -1, sizeof(dp));
  dp[0][0][0] = 0;
  double ans = dfs(num[0], num[1], num[2]);
  cout << fixed << setprecision(9) << ans << endl;
  return 0;
}

Measured memory_bytes: 233088
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n;

	f = 0;
	x = y = 0;
	REP(i, 1, 9){
		x = 100 * i + 10*i + i;
		y = x + 111;
		if(x < n && n <= y){
			f = y;
			break;
			
		}
	}
	if(f) cout << f;
	else cout << 111;

}

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

class edge{
public:
  int s,t;
  int cost;
  edge(int a,int b,int c):s(a),t(b),cost(c){}
  bool operator<(const edge &e)const{return cost<e.cost;}
};

class UF{
  vi p,r;

public:
  UF(int n):p(n,-1),r(n,0){ }

  int find(int x){ return (p[x]<0)?x:(p[x] = find(p[x])); }

  void unite(int x,int y){
    x = find(x); y = find(y);
    if(x==y)return;

    if(r[x] < r[y])p[x] = y;
    else p[y] = x;
    if(r[x] == r[y])r[x]++;
  }

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

inline int dis2(int x1, int y1, int x2, int y2){
  return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
}

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int n,m;
  cin >> n >> m;
  
  vector<D> x(n),y(n);
  for(int i=0;i<n;i++)cin >> x[i] >> y[i];

  vector<edge> e;
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b; a--; b--;
    e.push_back(edge(a,b,dis2(x[a],y[a],x[b],y[b])));
  }

  sort(e.begin(), e.end());
  reverse(e.begin(), e.end());
  
  UF uf(n);
  D ans = 0;
  rep(i,m){
    if(uf.same(e[i].s,e[i].t))ans += sqrt(e[i].cost);
    else uf.unite(e[i].s,e[i].t);
  }
  cout << fixed << setprecision(9) << ans << endl;
}

Measured memory_bytes: 1920
#include <iostream>

int main() {
    int n;
    std :: cin >> n;
    int64_t arr[n];

    for(auto& i : arr) std :: cin >> i;

    int64_t ans = 0;

    for(int i = 0 ; i < n - 1 ; i++) {
        if(arr[i] > arr[i + 1]) {
            ans += (arr[i] - arr[i + 1]);
            arr[i + 1] += (arr[i] - arr[i + 1]);
        }
    }

    std :: cout << ans << '\n';
}

Measured memory_bytes: 5124
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const int mod=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

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

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k])%mod;
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}


int main() {
	int n;ll ans=0;
	string s;
	cin>>n>>s;
	ll r=0,g=0,b=0;
	rep(i,0,n){
		if(s[i]=='R')r++;
		else if(s[i]=='G')g++;
		else b++;
	}
	ans=r*g*b;
	rep(i,1,n-1)rep(j,i+1,n){
		int k=2*j-i;
		if(k>n)break;
		if(s[i-1]!=s[j-1]&&s[i-1]!=s[k-1]&&s[j-1]!=s[k-1])
			ans--;
	}
	print(ans);
}


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

using namespace std;

int main()
{
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	cout << (char)(s1[0] - 'a' + 'A') << (char)(s2[0] - 'a' + 'A') << (char)(s3[0] - 'a' + 'A') << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
 int i,j,k,l,c,m,n,p,we;
 long long int ans=0;
 string t;
 cin >> n >> m >> we;
 string s[n];
 for(i=0;i<n;i++)
 cin >> s[i];
 for(k=0;k<(int)pow(2,n);k++)
 {
  string r[n];
  for(i=0;i<n;i++)
  r[i]=s[i];
  p=k;
  t="";
  while(p>0)
  {
   t.append(1,(char)(p%2+'0'));
   p/=2;
  }
  t.append(n-t.length(),'0');
  reverse(t.begin(),t.end());
  //cout << t << '\n';
  for(i=0;i<n;i++)
  {
   if(t[i]=='1')
   {
    for(j=0;j<m;j++)
    r[i][j]='R';
   }
  }
  for(l=0;l<(int)pow(2,m);l++)
  {
   string rt[n];
   for(i=0;i<n;i++)
   rt[i]=r[i];
   p=l;
  t="";
  while(p>0)
  {
   t.append(1,(char)(p%2+'0'));
   p/=2;
  }
  t.append(m-t.length(),'0');
  reverse(t.begin(),t.end());
  for(i=0;i<m;i++)
  {
   if(t[i]=='1')
   {
    for(j=0;j<n;j++)
    rt[j][i]='R';
   }
  }
  c=0;
  for(i=0;i<n;i++)
  {
   for(j=0;j<m;j++)
   {
    if(rt[i][j]=='#')
    c++;
   }
  }
  if(c==we)
  ans++;
  }
 }
 cout << ans;
 return 0;
}

Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const ll mod=1e9+7;

int n,N=0,M;
vvl g;
vl a,b;
vector<vvl> dp;
 
P dfs(int v,int d,int w){
	P p={d,v};
	for(auto u:g[v]) if(u!=w) p=max(p,dfs(u,d+1,v));
	return p;
}
 
bool DFS(int v,int w,int p){
	bool B=0;
	if(v==w) B=1;
	for(auto u:g[v]) if(u!=p){
		B|=DFS(u,w,v);
	}
	if(B){
		a.push_back(v);
		b[v]++;N++;
	}
	return B;
}

int Rec(int v,int p){
	int D=1,B=0;
	vvl DP;
	for(auto u:g[v]) if(u!=p){
		int d=Rec(u,v),D_=D;
		D=max(D,d+1);
		vvl DP_(D,vl(D));
		if(!B){
			for(int i=0;i<d;i++) for(int j=0;j<d;j++){
				(DP_[i+1][j]+=dp[u][i][j])%=mod;
				(DP_[i][j+1]+=dp[u][i][j])%=mod;
			}
			B=1;
		}
		else{
			for(int i=0;i<D_;i++) for(int j=0;j<D_;j++) if(DP[i][j]){
				for(int k=0;k<min(d,M-j+1);k++) for(int l=0;l<min(d,M-i+1);l++){
					if(j+k+1<=M) (DP_[max(i,k+1)][max(j,l)]+=DP[i][j]*dp[u][k][l])%=mod;
					if(i+l+1<=M) (DP_[max(i,k)][max(j,l+1)]+=DP[i][j]*dp[u][k][l])%=mod;
				}
			}
		}
		DP=DP_;
	}
	for(auto u:g[v]) if(u!=p) dp[u].clear();
	if(D==1){
		DP=vvl(1,vl(1));
		DP[0][0]++;
	}
	dp[v]=DP;
	return D;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	b=vl(n);
	g=vvl(n);
	dp=vector<vvl>(n);
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int L=dfs(0,0,-1).second,R=dfs(L,0,-1).second;
	DFS(L,R,-1);
	M=N/2;
	ll C=a[N/2],res=0;
	Rec(C,-1);
	for(int i=0;i<=M;i++) for(int j=0;j<=M;j++) (res+=dp[C][i][j])%=mod;
	cout<<res<<endl;
}

Measured memory_bytes: 16172
#include <bits/stdc++.h>
#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(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#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 show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int a, b, k;
  cin >> a >> b >> k;
  for (int i = a; i <= b; ++i) {
    if (i <= a+k-1 || b-k+1 <= i) cout << i << endl;
  }
  return 0;
}

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

constexpr double ticks_per_sec = 2800000000;
constexpr double ticks_per_sec_inv = 1.0 / ticks_per_sec;
inline double rdtsc() { // in seconds
    uint32_t lo, hi;
    asm volatile ("rdtsc" : "=a" (lo), "=d" (hi));
    return (((uint64_t)hi << 32) | lo) * ticks_per_sec_inv;
}
constexpr double TLE = 3; // sec
constexpr double time_limit = TLE * 0.98;

unsigned int randxor()
{
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}

template<typename hoge>
void my_shuffle(vector<hoge>& v) {
    int sz = v.size();
    for (int i = sz - 1; i >= 1; i--) {
        swap(v[i], v[randxor() % (i + 1)]);
    }
}

// 定数
constexpr int CONTEST_NUM = 26;

// 入力
constexpr int D = 365;
array<int, CONTEST_NUM> c;
array< array<int, CONTEST_NUM>, D> s;

ll calcScore(const array<int, D>& t) {
    ll score = 0;
    array<int, CONTEST_NUM> lasts{};

    for (int i = 0; i < D; i++) {
        lasts[t[i]] = i + 1;
        score += s[i][t[i]];

        for (int j = 0; j < CONTEST_NUM; j++) {
            score -= c[j] * (i + 1 - lasts[j]);
        }

        cout << score << newl;
    }
    return score;
}

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

    {
        int dummy;
        cin >> dummy;

        for (int i = 0; i < CONTEST_NUM; i++) {
            cin >> c[i];
        }

        for (int i = 0; i < D; i++) {
            for (int j = 0; j < CONTEST_NUM; j++) {
                cin >> s[i][j];
            }
        }
    }

    array<int, D> t;
    for (int i = 0; i < D; i++) {
        cin >> t[i];
        --t[i];
    }

    calcScore(t);
    //cout << calcScore(t) << newl;

    return 0;
}


Measured memory_bytes: 3640
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 1005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); //cout.tie(0);
#define pi 3.1415926535897
#define db double
#define noop
#define flu fflush(stdout)
#define imp {cout<<"impossible\n"; return ;}
#define debug_vec(vec,n) {rep(idxi,n) cout<<vec[idxi]<<" "; cout<<endl;}

int main() {

    get3(a,b,c);
    ll t = min(a,c);
    a -= t;
    c -= t;
    if(c) {
        b -= min(b,c);
    }
    printf("%lld %lld\n", a,b);
    return 0;  
}

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

	scanf("%d %d %d" ,&a,&b,&c);

	if (a < b & b < c)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2588
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef unsigned long long ll;

int main()
{
  int n, k;
  cin >> n >> k;
  int ans = 1;
  for (int i = 0; i < n; i++) {
    if (ans < k) ans *= 2;
    else ans += k;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 1e5 + 5;
typedef long long ll;
const ll INF = 1e16; 
using namespace std;

int n, m, a[N]; 
ll ans = INF, c[N]; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

void add(int l, int r, int x, int y)
{
	if(l > r) return; 
	int k = r - l;
	c[l] += x, c[l + 1] += y - x; 
	c[r + 1] -= x + y * (k + 1), c[r + 2] += x + y * k; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	n = read <int> (), m = read <int> ();
	for(int i = 1; i <= n; i++) a[i] = read <int> (); 
	for(int l, r, i = 2; i <= n; i++)
	{
		l = a[i - 1], r = a[i]; 
		if(a[i] >= a[i - 1])
		{
			add(l + 1, r, r - l, -1);
			add(1, l, r - l, 0), add(r + 1, m, r - l, 0); 
		}
		else
		{
			add(l + 1, m, r + m - l, -1), add(1, r, r, -1);
			add(r + 1, l, r + m - l, 0); 
		}
	}
	for(int i = 1; i <= m; i++) c[i] += c[i - 1]; 
	for(int i = 1; i <= m; i++) c[i] += c[i - 1]; 
	for(int i = 1; i <= m; i++) ans = min(ans, 1ll * c[i]); 
	printf("%lld\n", ans); 
	return 0; 
}


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

int main(){
  int n , answer ;
  cin >> n ;
  vector<int> tako(n) ;
  for(int i=0; i<n; i++)
    cin >> tako.at(i) ;
  for(int i=0; i<n-1; i++){
    for(int j=1; j<n-i; j++){
      answer += tako.at(i)*tako.at(i+j) ;
    }
  }
  cout << answer << endl ;
}

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

  
int main(){
 int n,i;
  cin >> n >> i;
  cout << n+1-i <<endl;
  
   
 
}

Measured memory_bytes: 256
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <vector>
#include <stdio.h>
#include <iostream>
#include <unordered_set>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <random>
#include <time.h>
#include <cassert>


#define prev askdnsajd
#define rank asasdmdnasd
#define next lsjndajbs
#define hash asmdklansd
#define index asdklnas
#define right sld
#define left sldl

using namespace std;

typedef long long ll;
typedef long double dbl;

template<class T>
void print(vector<T> s){
    for (T x : s)
        cout << x << " ";
    cout << endl;
}

mt19937 mrand(random_device{} ());
int rnd() {
    return mrand();
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(77);
    int n;
    cin >> n;
    vector<int> s(n);
    for (int i = 0; i < n; i++)
        cin >> s[i];
    sort(s.begin(), s.end());
    dbl answer = s[0];
    for (int i = 1; i < n; i++){
        answer += s[i];
        answer /= 2;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<lint> A(N);
	multiset<lint> st;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		st.emplace(A[i]);
	}
	sort(A.begin(), A.end(), greater<lint>());

	int ans = 0;
	for (int i = 0; i < N; i++) {

		auto it = st.find(A[i]);
		if (it == st.end()) continue;
		st.erase(it);

		for (int j = 0; j < 32; j++) {
			lint tmp = (1LL << j) - A[i];
			auto it = st.find(tmp);
			if (it != st.end()) {
				st.erase(it);
				ans++;
			}
		}

	}

	cout << ans << "\n";

	return 0;
}

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

int main(){
    fIO

    double n;
    cin >> n;

    int x =  ceil(n / 1.08);
    //cout << x << "\n";
    if(floor(x * 1.08) == n) cout << x;
    else cout << ":(";


}









Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;


const int BIG_INT = 1000000000;



int main() {
	string s;
	cin >> s;


	if (s.length() % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	for (int i = 0; i < s.length(); i++) {
		if (i % 2 == 0 && s[i] != 'h') {
			cout << "No" << endl;
			return 0;
		}
		if (i % 2 == 1 && s[i] != 'i') {
			cout << "No" << endl;
			return 0;
		}

	}

	

	cout << "Yes" << endl;
}



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

int main(){
   int n; 
   cin >> n;
   if(n%1000==0){
      cout << 0 << endl;
   }else{
      cout << 1000 - n%1000 << endl;
   }
   return 0;  
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

void lcs(string s,string t){
  int n=s.size(),m=t.size();
  vector<vector<int>>lcs(n+1,vector<int>(m+1,0));
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(s[i-1]==t[j-1]){
        lcs[i][j]=lcs[i-1][j-1]+1;
      }
      else{
        lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
      }
    }
  }
  int idx=lcs[n][m];
  char ans[idx+1];
  ans[idx]='\0';
  int i=n,j=m;
  while(i>0 and j>0){
    if(s[i-1]==t[j-1]){
      ans[idx-1]=s[i-1];
      i--;
      j--;
      idx--;
    }
    else if(lcs[i-1][j]>lcs[i][j-1]) 
      i--; 
    else
      j--; 
  }
  cout<<ans<<endl;
}

void solve(){
  string s,t;
  cin>>s>>t;
  lcs(s,t);
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 35584
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)


long long n, a, b, c, d;

bool solve()
{
    long long diff = b - a;

    for(long long m = 0; m <= n-1; ++m) {
        long long lower = -m*d + (n-1-m)*c;
        long long upper = -m*c + (n-1-m)*d;
        if(lower <= diff && diff <= upper) return true;
    }

    return false;
}

int main()
{
    cin >> n >> a >> b >> c >> d;

    bool result = solve();
    cout << (result ? "YES" : "NO") << "\n";

    return 0;
}


Measured memory_bytes: 256
/*
    Ujjawal Pabreja [cuber_coder]
*/
#include <bits/stdc++.h> 
#include <functional> 
using namespace std;
#define speed_cubing    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll              long long
#define ld              long double
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define in              insert
#define ff              first
#define ss              second
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define sz(c)           (ll)c.size()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define rev             reverse
#define Y				"YES"
#define N 				"NO"
#define endl            "\n"
#define debug(x)        cout << #x << " : " << x << endl;
const ll inf = 1e18;  
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5 + 1;

inline ll add(ll a,ll b) {return ((a % mod) + (b % mod)) % mod;}
inline ll sub(ll a,ll b) {return ((a % mod) - (b % mod) + mod) % mod;}
inline ll mul(ll a,ll b) {return ((a % mod) * (b % mod)) % mod;}
ll pwr(ll x,ll n){
    if(n == 0){
        return 1;
    }
    if(n&1){
        return mul(x, pwr(mul(x, x), (n - 1) / 2));
    } else {
        return pwr(mul(x, x), n / 2);
    }
}
ll modInv(ll n){ 
    return pwr(n, mod - 2); 
}
ll gcd(ll a,ll b) {
    if(b == 0) {
        return a;
    }
    return gcd(b, a % b);
}
// ====== Useful functions end ======
 
// ====== Global Variables begin ======

// ====== Global Variables end ======

void speed_solve(){
    string s;
    cin >> s;
    if(s[0] == 'R' and s[1] == 'R' and s[2] == 'R') cout << 3;
    else if ((s[0] == 'R' and s[1] == 'R') or (s[1] == 'R' and s[2] == 'R')) cout << 2;
    else if (s[0] == 'R' or s[1] == 'R' or s[2] == 'R') cout << 1;
    else cout << 0;
}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    speed_cubing;
    ll test_cases = 1;
    // cin >> test_cases;
    rep(i,test_cases){
        // cout << "Case #" << i + 1 << ": ";
        speed_solve();
    }
    return 0;
}

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

int main() {
  long H, W, N;
  cin >> H >> W >> N;

  vector<vector<long> > ans(H);
  for (long i = 0; i < H; i++) {
    ans[i].resize(W);
  }

  long x = 0;
  long y = 0;
  long d = 1;
  for (long i = 1; i <= N; i++) {
    long a;
    cin >> a;

    for (long j = 0; j < a; j++) {
      ans[y][x] = i;

      x += d;
      if (x == W || x == -1) {
	d *= -1;
	x += d;
	y++;
      }
    }
  }

  for (long i = 0; i < H; i++) {
    for (long j = 0; j < W - 1; j++) {
      cout << ans[i][j] << ' ';
    }
    cout << ans[i][W - 1] << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long 

using namespace std;

const int maxn = (1 << 18);

int N, a[maxn], mx[maxn];

pair<int, int> p[maxn];

void modify(pair<int, int> &x, pair<int, int> y)
{
   /// y.first
   if(a[x.first] < a[y.first])
   {
      x.second = x.first;
      x.first = y.first;
   }
   else if((x.second == -1 || a[x.second] < a[y.first]) && x.first != y.first)
   {
      x.second = y.first;
   }
   /// y.second
   if(y.second == -1) return;
   if(a[x.first] < a[y.second])
   {
      x.second = x.first;
      x.first = y.second;
   }
   else if((x.second == -1 || a[x.second] < a[y.second]) && x.first != y.second)
   {
      x.second = y.second;
   }
}

int32_t main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
   cin >> N;
   for(int i = 0; i < (1 << N); i++) 
   {
      cin >> a[i];
      p[i] = {i, -1};
   }
   for(int i = 1; i < (1 << N); i++)
   {
      for(int j = 0; j < N; j++)
      {
         if(i >> j & 1)
         {
            modify(p[i], p[i ^ (1 << j)]);
         }
      }
   }
   for(int i = 1; i < (1 << N); i++)
   {
      mx[i] = max(mx[i - 1], a[p[i].first] + a[p[i].second]);
      cout << mx[i] << '\n';
   }
}

Measured memory_bytes: 11264
n = int(input())
arr = list(map(int, input().split()))

count = 1
mode = None
for i in range(n):
    if i+1 == n or arr[i+1] - arr[i] == 0:
        continue
    elif mode is None:
        if arr[i+1] > arr[i]:
            mode = 'up'
        elif arr[i+1] < arr[i]:
            mode = 'down'
    elif mode == 'up':
        if arr[i+1] < arr[i]:
            count += 1
            mode = None
    elif mode == 'down':
        if arr[i+1] > arr[i]:
            count += 1
            mode = None

print(count)

Measured memory_bytes: 62704
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e6;
const int Nmax=2e5+1;
const int Nd=61;


int main(){
  int n; cin>>n;
  vector<int> p(n);
  int ans=0;
  int m1=INF;
  rep(i,n){
    cin>>p[i];
    if(p[i]<= m1) ans++;
    m1=min(m1,p[i]);

  }
  cout<<ans<<endl;


}


Measured memory_bytes: 4016
// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>

#define ll long long
#define Int int
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (*(x.end()-1))

using namespace std;

#define EPS 0.0000000001

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (Vector2 v) { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (Vector2 v) { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (double k) { return Vector2(x * k, y * k); }
  Vector2 operator / (double k) { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 v) { return x * v.x + y * v.y; }
  double cross (Vector2 v) { return x * v.y - y * v.x; }
  
  bool operator < (const Vector2 &v) const {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) const {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}

#define MAX_N 2001
#define MAX_Y 20000001

Int N, Y;

void input() {
  cin >> N >> Y;
}

// ax + by + cz = Y
// a + b + c = N

void solve() {
  loop(a,0,N+1) {
    loop(b,0,N+1) {
      Int c = N - a - b;
      if (a + b > N || c < 0) continue;
      if (a * 10000 + b * 5000 + c * 1000 == Y) {
        cout << a << ' ' << b << ' ' << c << endl;
        return;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}

int main(void) {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

    for (int i=0;i<n;i++){
      a[i] = scan.nextInt();
    }

    long initial = 1000;

    for (int i=0;i<n-1;i++){
      if (a[i+1] > a[i]){
        long item = (long) initial/a[i];
        initial += item*(a[i+1]-a[i]);
      }
    }
    System.out.println(initial);
  }

}


Measured memory_bytes: 35696
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int ans = 0;
    if(a+b>c*2){
        int buy = min(x,y);
        ans += 2 * buy * c;
        x-= buy;
        y-= buy;
    }
    if(a > c*2){
        ans += 2 * x * c;
    }else{
        ans += x * a;
    }
    if(b > c*2){
        ans += 2 * y * c;
    }else{
        ans += y * b;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))

G = [[] for _ in range(N)]
for _ in range(M):
  A, B = map(int, input().split())
  A -= 1
  B -= 1
  G[A].append(B)
  G[B].append(A)

ans = 0
for i in range(N):
  is_good = True
  for j in G[i]:
    if H[j] >= H[i]:
      is_good = False
      break
  if is_good:
    ans += 1

print(ans)

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

int main(){
  int K,S;
  int count=0;
  cin >> K >> S;
  for(int x=0; x<=K; x++){
    for(int y=0; y<=K; y++){
      if(S-x-y>=0&&S-x-y<=K){
        count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
from collections import defaultdict as dd
n=int(input())
d=dd(int)
for i in range(n):
    a=int(input())
    if d[a]==0:
        d[a]+=1
    elif d[a]==1:
        d[a]-=1

ans=0
for k,v in d.items():
    ans+=v
print(ans)


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

int main(void) {
    int a, b, c, d, e, f;
    float x, y;
    float det;
    while(cin >> a >> b >> c >> d >> e >> f) {
        det = a * e - b * d;
        x = (float)(e * c - b * f) / det;
        y = (float)(-d * c + a * f) / det;
        x = roundf(1000 * x) / 1000.0;
        y = roundf(1000 * y) / 1000.0;
        if(x == -0)
            x = 0.0;
        if(y == -0)
            y = 0.0;
        printf("%.3f %.3f\n", x, y);
    }
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	REP(i, N-1){
		ll ub = D*(N-1-i) - C*i;
		ll lb = C*(N-1-i) - D*i;
		if(B-A >= lb && B-A <=ub){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int x = sc.nextInt();
	int n = sc.nextInt();	 
    Integer[] p = new Integer[n];	
    for (int i=0; i<n; i++) {	
      p[i] =sc.nextInt();	  
    }	
    int sub = -100;
    if (n==0) {
      System.out.println(x);
      return;
    }	        	
    for (int i=x-n; i<x+n; i++) {	
      if ( Arrays.asList(p).contains(i))
        continue;
      if ( Math.abs(x-sub) > Math.abs(x-i) ){
        sub = i;
        continue;
      }
      if ( Math.abs(x-sub) < Math.abs(x-i))
        break;   
    }
    System.out.println(sub);
    sc.close();
  }
}

Measured memory_bytes: 36060
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;

int main(){
  int a,b,c; cin>>a>>b>>c;
  if((a==b&&b==c&&c==a)||(a!=b&&b!=c&&c!=a)) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

n = int(input())
p = list(map(int,input().split()))
cnt = 0
for i in range(1,n-1):
    p1 = p[i-1];p2 = p[i];p3 = p[i+1];
    if p2 > p1 and p2 < p3:
        cnt += 1
    elif p2 >p3 and p2 < p1:
        cnt += 1

print(cnt)


Measured memory_bytes: 3952
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int A = input.nextInt();
		int B = input.nextInt();
		if ((A + B) % 2 ==0) {
			System.out.print((A+B)/2);

		}else {
			System.out.print("IMPOSSIBLE");
		}

	}

}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long K, long long Q, std::vector<long long> A)
{
    vector<ll> ans(N);
    for (int i = 0; i < Q; i++)
    {
        ans[A[i] - 1]++;
    }

    for (int i = 0; i < N; i++)
    {
        if (Q - ans[i] < K)
        {
            cout << YES << endl;
        }
        else
        {
            cout << NO << endl;
        }
    }
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    long long Q;
    scanf("%lld", &Q);
    std::vector<long long> A(Q);
    for (int i = 0; i < Q; i++)
    {
        scanf("%lld", &A[i]);
    }
    solve(N, K, Q, std::move(A));
    return 0;
}


Measured memory_bytes: 2176
#ifndef VS
#include<bits/stdc++.h>
#endif

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

const int SZ = 'Z' + 1;
int d[SZ][SZ];
const int dr[4] = { 1,0,-1,0 };
const int dc[4] = { 0,1,0,-1 };
string ike = "|-|-";
vector<string> wrap(vector<string> x, char c) {
	int R = x.size();
	int C = x[0].size();
	vector<string> ret(R + 2, string(C + 2, c));
	for (int i : range(R)) {
		for (int j : range(C)) {
			ret[i + 1][j + 1] = x[i][j];
		}
	}
	return ret;
}
int main() {
	int R, C;
	while (cin >> R >> C) {
		char S, T;
		cin >> S >> T;
		vector<string> s(R);
		for (int i : range(R))cin >> s[i];
		for (int i : range(SZ))for (int j : range(SZ))d[i][j] = 1000;
		for (int i : range(SZ))for (int j : range(i,i+1))d[i][j] = 0;
		s = wrap(s, '.');
		R += 2;
		C += 2;
		for (int i : range(R)) {
			for (int j : range(C)) {
				if (isupper(s[i][j])) {
					for (int k : range(4)) {
						int r = i + dr[k];
						int c = j + dc[k];
						while (s[r][c] == 'o'||s[r][c] == ike[k]) {
							r += dr[k];
							c += dc[k];
						}
						if (isupper(s[r][c])) {
							d[s[i][j]][s[r][c]] = 1;
						}
					}
				}
			}
		}
		for (int k : range(SZ))for (int i : range(SZ))for (int j : range(SZ))
			chmin(d[i][j], d[i][k] + d[k][j]);
		cout << d[S][T] << endl;
	}

	return 0;
}



Measured memory_bytes: 3280
N = int(input())
A = list(map(int, input().split(' ')))

count = 0
flag = 1
while flag:
    flag = 0
    for i in reversed(range(1, N)):
        if A[i] < A[i-1]:
            A[i], A[i-1] = A[i-1], A[i]
            count += 1
            flag = 1
print(*A)
print(count)


Measured memory_bytes: 5608
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

inline int query(const vector<vector<int> >& mat, int a, int b, int c, int d) {
	return mat[c][d] - mat[c][b - 1] - mat[a - 1][d] + mat[a - 1][b - 1];
}

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

	int h, w, k;
	cin >> h >> w >> k;

	vector<vector<int> > J(h + 1, vector<int>(w + 1, 0));
	vector<vector<int> > O(J), I(J);
	for(int i = 0; i < h; ++i) {
		string field;
		cin >> field;
		for(int j = 0; j < w; ++j) {
			switch(field[j]) {
			case 'J':
				++J[i + 1][j + 1];
				break;
			case 'O':
				++O[i + 1][j + 1];
				break;
			default:
				++I[i + 1][j + 1];
			}
		}
	}

	for(int i = 0; i <= h; ++i) {
		for(int j = 0; j < w; ++j) {
			J[i][j + 1] += J[i][j];
			O[i][j + 1] += O[i][j];
			I[i][j + 1] += I[i][j];
		}
	}

	for(int j = 0; j <= w; ++j) {
		for(int i = 0; i < h; ++i) {
			J[i + 1][j] += J[i][j];
			O[i + 1][j] += O[i][j];
			I[i + 1][j] += I[i][j];
		}
	}

	for(int i = 0; i < k; ++i) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		cout << query(J, a, b, c, d) << " ";
		cout << query(O, a, b, c, d) << " ";
		cout << query(I, a, b, c, d) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 12884
# frozen_string_literal: true

# Fenwick Tree
class FenwickTree
  def initialize(arg)
    case arg
    when Array
      @size = arg.size
      @data = Array.new(@size + 1) { 0 }
      arg.each.with_index(1) { |e, i| add(i, e) }
    when Integer
      @size = arg
      @data = Array.new(@size + 1) { 0 }
    else
      raise ArgumentError
    end
  end

  def add(i, x)
    while i <= @size
      @data[i] += x
      i += (i & -i)
    end
  end

  def sum(l, r)
    _sum(r) - _sum(l)
  end

  def _sum(i)
    res = 0
    while i > 0
      res += @data[i]
      i -= (i & -i)
    end
    res
  end
end

FeTree            = FenwickTree
BinaryIndexedTree = FenwickTree

n, q = gets.split.map(&:to_i)
a    = gets.split.map(&:to_i)
 
ft = FeTree.new(a)
 
q.times do
  t, u, v = gets.split.map(&:to_i)
 
  if t == 0
    ft.add(u + 1, v)
  else
    puts ft.sum(u, v)
  end
end


Measured memory_bytes: 57296
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int max=a;
    int min=a;
    int mid;
    int b=sc.nextInt();
    if(a>b)
    {
      min=b;
    }
    else
    {
      max=b;
    }
    int c=sc.nextInt();
    if(c>max)
    {
      mid=max;
      max=c;
    }
    else if(min>c)
    {
      mid=min;
      min=c;
    }
    else
    {
      mid=c;
    }
    System.out.print((max*10+mid)+min);
	}
}

Measured memory_bytes: 23252
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;

const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
int n, k, h[maxn], cost[maxn];

int solve2(int x) {
    // recursive method
    int res = cost[x];
    if (res < inf) return res;
    for (int i = 1; i <= k; i++) {
        if (x - i >= 0) res = min(res, solve2(x - i) + abs(h[x] - h[x - i]));
    }
    cost[x] = res;
    return res;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> h[i];
    memset(cost, inf, sizeof(cost));
    cost[0] = 0;
    cout << solve2(n - 1) << endl;
    return 0;
}

Measured memory_bytes: 5760
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from itertools import *
def code(a,b,st):
  v = ""
  for s in st:
    v += chr( ( a*(ord(s)-ord("a"))+ b ) % 26  + ord("a"))
  return v

def invert(string,codelist):
  for st in string:
    v = ""
    for s in st: v += codelist[s]
    print v,

def search(x,y,st):
  for e in st:
    if e == code(x,y,"that") or e == code(x,y,"this"):
      return { code(x,y,s):s for s in "abcdefghijklmnopqrstuvwxyz" }
  else: return False
      
n = int(raw_input())
for i in xrange(n):
  st = map(str, raw_input().split())
  for x,y in product(range(26),repeat=2):
    if x % 2 == 0 or x % 13 == 0: continue
    codelist = search(x,y,st)
    if codelist: break
  invert(st,codelist)
  print 

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

using namespace std;
using ll = long long int;

// to format a document: ctrl + K -> ctrl + D

int main() {
    int N;
    cin >> N;
    if (N % 2 == 0)
        cout << N << endl;
    else
        cout << N * 2 << endl;


    return 0;
}

Measured memory_bytes: 256
#C
inf = float("inf")
N,M = map(int,input().split())
flag = [list(str(input())) for i in range(N)]
WBR = []

for i in range(N):
    w = flag[i].count("W")
    b = flag[i].count("B")
    r = flag[i].count("R")
    WBR.append([w,b,r])
    
    
ans = inf
for w in range(N-2):
    for b in range(N-1):
        if w >= b:
            pass
        else:
            kari = 0
            for i in range(N):
                if i <= w:
                    kari+=(M-WBR[i][0])
                elif i <= b:
                    kari+=(M-WBR[i][1])
                else:
                    kari+=(M-WBR[i][2])
            ans = min(ans,kari)
                    
print(ans)





Measured memory_bytes: 5612
/* Coached by rainboy */
#include <stdio.h>

int main() {
	int n, k;
	long long x, ans;

	scanf("%d%d", &n, &k);
	x = n / k;
	ans = x * x * x;
	if (k % 2 == 0) {
		x = (n + k / 2) / k;
		ans += x * x * x;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 128