akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
int main(){
  int A, B, X;
  cin >> A >> B >> X;
  for(int i=0;i<=B;i++){
    if(A==X){
      break;
    }
  A++;
  }
  if(A==X){
  cout << "YES" << endl;
  }
  else{
  cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<vector>
#define ll long long
using namespace std;

const int N=200005;
const ll inf=1000000000000000ll;

struct E{
	int to,next,w;
}mem[N<<1];
struct node{
	ll x,y;
	node(){}
	node(ll x,ll y):x(x),y(y){}
};
int n,w,num;
ll l,r,mid;
int head[N],fa[N],d[N];
ll mn[N];
vector<node> dp[N];

void add(int x,int y,int w){
	num++;
	mem[num].to=y; mem[num].next=head[x]; mem[num].w=w;
	head[x]=num;
}

bool cmp1(node a,node b){
	return a.x<b.x||(a.x==b.x&&a.y<b.y);
}

bool cmp2(node a,node b){
	return a.y<b.y||(a.y==b.y&&a.x<b.x);
}

void dfs(int k,int pre){
	int j,u,ls,rs,v1,v2,i,t;
	ls=rs=v1=v2=0;
	if (d[k]==1){
		dp[k].push_back(node(0,0));
		return;
	}
	for (j=head[k];j;j=mem[j].next){
		u=mem[j].to;
		if (u==pre) continue;
		if (!ls) ls=u,v1=mem[j].w;
		else rs=u,v2=mem[j].w;
		dfs(u,k);
	}
	if (dp[ls].size()>dp[rs].size()){
		swap(ls,rs);
		swap(v1,v2);
	}
	for (i=0;i<dp[ls].size();i++) dp[ls][i].x+=1ll*v1,dp[ls][i].y+=1ll*v1;
	for (i=0;i<dp[rs].size();i++) dp[rs][i].x+=1ll*v2,dp[rs][i].y+=1ll*v2;
	sort(dp[ls].begin(),dp[ls].end(),cmp1);
	sort(dp[rs].begin(),dp[rs].end(),cmp2);
	t=dp[rs].size()-1; mn[0]=dp[rs][0].x;
	for (i=1;i<=t;i++) mn[i]=min(mn[i-1],dp[rs][i].x);
	for (i=0;i<dp[ls].size();i++){
		while (t>=0&&dp[ls][i].x+dp[rs][t].y>mid) t--;
		if (t>=0) dp[k].push_back(node(mn[t],dp[ls][i].y));
	}
	sort(dp[ls].begin(),dp[ls].end(),cmp2);
	sort(dp[rs].begin(),dp[rs].end(),cmp1);
	t=dp[rs].size()-1; mn[0]=dp[rs][0].y;
	for (i=1;i<=t;i++) mn[i]=min(mn[i-1],dp[rs][i].y);
	for (i=0;i<dp[ls].size();i++){
		while (t>=0&&dp[ls][i].y+dp[rs][t].x>mid) t--;
		if (t>=0) dp[k].push_back(node(dp[ls][i].x,mn[t]));
	}
}

int main(){
	int i;
	scanf("%d",&n);
	for (i=2;i<=n;i++){
		scanf("%d%d",&fa[i],&w);
		add(fa[i],i,w);
		d[fa[i]]++; d[i]++;
	}
	l=0; r=inf;
	while (l<r){
		mid=l+(r-l)/2;
		for (i=1;i<=n;i++) dp[i].clear();
		dfs(1,0);
		if (!dp[1].empty()) r=mid;
		else l=mid+1;
	}
	printf("%lld\n",r);
	return 0;
}

Measured memory_bytes: 32500
x,y,a,b,c = map(int, input().split())
red = sorted(list(map(int, input().split())), reverse=True)[:x]
green = sorted(list(map(int, input().split())), reverse=True)[:y]
no_c = sorted(list(map(int, input().split())), reverse=True)
print(sum(sorted(red + green + no_c, reverse=True)[:x+y]))

Measured memory_bytes: 22616
#include <bits/stdc++.h>
using namespace std;
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define chmax(a,b) a=max(a,b)
int n,Q,bl;
int c[500005];
int ans=0,cnt[500005];
struct query{
	int l,r,id;
}q[500005];
int qans[500005];
bool cmp(query a,query b){
	return (a.r/bl)==(b.r/bl)?a.l<b.l:a.r<b.r;
}
void add(int x){
	if(!cnt[c[x]]){
		ans++;
	}
	cnt[c[x]]++;
}
void del(int x){
	cnt[c[x]]--;
	if(!cnt[c[x]]){
		ans--;
	}
}
int main(){
	cin>>n>>Q;
	bl=n/sqrt(Q*2/3);
	for(int i=1;i<=n;++i){
		cin>>c[i];
	}
	for(int i=1;i<=Q;++i){
		cin>>q[i].l>>q[i].r;
		q[i].id=i;
	}
	sort(q+1,q+1+Q,cmp);
	int l=0,r=0;
	for(int i=1;i<=Q;++i){
		int ql=q[i].l,qr=q[i].r;
//		cout<<ql<<' '<<qr<<'\n';
		while(l<ql){
			del(l);
			l++;
		}
		while(l>ql){
			l--;
			add(l);
		}
		while(r>qr){
			del(r);
			r--;
		}
		while(r<qr){
			r++;
			add(r);
		}
		qans[q[i].id]=ans;
	}
	for(int i=1;i<=Q;++i){
		cout<<qans[i]<<'\n';
	}
	return 0;
}


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

using namespace std;
#define int long long
#define N 666666
#define mod 1000000007
int x[N],y[N];
int n,m;
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++) scanf("%lld",&x[i]);
	for(int i=1;i<=m;i++) scanf("%lld",&y[i]);
	int ans1=0,ans2=0;
	for(int i=2;i<=n;i++){
		ans1=(ans1+(x[i]-x[i-1])*(i-1)*(n-i+1)%mod);
	}
	for(int i=2;i<=m;i++){
		ans2=(ans2+(y[i]-y[i-1])*(i-1)*(m-i+1)%mod);
	}
	int ans=((ans1%mod)*(ans2%mod))%mod;
	cout<<ans%mod;
	return 0;
}

Measured memory_bytes: 3072
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

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

int main()
{
   int n, t, c_i, t_i, res = INF;
   cin >> n >> t;
   FOR(i, 0, n)
   {
      cin >> c_i >> t_i;
      if (t_i <= t)
         res = min(res, c_i);
   }

   if (res == INF)
      cout << "TLE" << endl;
   else
      cout << res << endl;
   return 0;
}


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

using namespace std;

class segment_tree {
	vector<int> lc;
	vector<int> rc;
	vector<int> sum;
	int Pool = 0;
	
	public:
	segment_tree(int n) {
		lc.resize(60 * n + 5);
		rc.resize(60 * n + 5);
		sum.resize(60 * n + 5);
	}

	void update(int l, int r, int &x, int p, int v) {
		if(!x) {
			x = ++Pool;
		}

		sum[x] += v;

		if(l == r) {
			return;
		}

		int mid = l + r >> 1;

		if(p <= mid) {
			update(l, mid, lc[x], p, v);
		} else {
			update(mid + 1, r, rc[x], p, v);
		}
	}

	int query(int l, int r, int x, int p) {
		if(!x) {
			return 0;
		}

		if(l == r) {
			return sum[x];
		}

		int mid = l + r >> 1;

		if(p <= mid) {
			return query(l, mid, lc[x], p);
		} else {
			return query(mid + 1, r, rc[x], p);
		}
	}

	int merge(int x, int y) {
		if(!x || !y) {
			return x + y;
		}

		int z = ++Pool;

		lc[z] = merge(lc[x], lc[y]);
		rc[z] = merge(rc[x], rc[y]);
		sum[z] = sum[x] + sum[y];

		return z;
	}
};

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

	int n;
	cin >> n;

	vector<int> c;
	c.resize(n);

	for(int &i : c) {
		cin >> i;
		--i;
	}

	vector<vector<int> > G;
	G.resize(n);

	for(int i = 0; i < n - 1; ++i) {
		int u, v;
		cin >> u >> v;

		--u;
		--v;

		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}

	segment_tree t(n);

	vector<int> root;
	root.resize(n);

	vector<long long> ans;
	ans.resize(n);

	vector<int> sz;
	sz.resize(n);

	function<void(int, int)> dfs = [&] (int u, int f) {
		sz[u] = 1;

		int sum = 0;

		for(int v : G[u]) {
			if(v != f) {
				dfs(v, u);
				sz[u] += sz[v];

				int d = t.query(0, n - 1, root[v], c[u]);
				sum += d;
				root[u] = t.merge(root[u], root[v]);
				
				ans[c[u]] += 1LL * (sz[v] - d) * (sz[v] - d + 1) / 2; 
			}
		}

		t.update(0, n - 1, root[u], c[u], sz[u] - sum);
	};

	dfs(0, -1);

	vector<bool> vis;
	vis.resize(n);

	for(int i : c) {
		vis[i] = true;
	}

	for(int i = 0; i < n; ++i) {
		if(vis[i]) {
			int d = n - t.query(0, n - 1, root[0], i);
			ans[i] += 1LL * d * (d + 1) / 2;
			ans[i] = 1LL * n * (n + 1) / 2 - ans[i];
		}
	}

	for(long long i : ans) {
		cout << i << '\n';
	}

	return 0;
}

Measured memory_bytes: 218020
#include<iostream>

using namespace std;

int main(){
    int N;cin>>N;
    long long int a;
    long long int cnt=0;
    for(int i=0;i<N;i++){
        cin>>a;
        while(a%2==0){
            a = a/2;
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include<algorithm>
 using namespace std;
int main(){
  int n, m;
  cin >> n >> m ;

  string res = "War";
  vector<int> x(n+1), y(m+1);
  cin >> x[0] >> y[0];
  for (int i = 1; i < n+1; i++) {
    cin >> x[i];
  }
  for (int i = 1; i < m+1; i++) {
    cin >> y[i];
  }

  int mx = *max_element(x.begin(), x.end());
  int my = *min_element(y.begin(), y.end());
  if (mx < my) {
    res = "No War";
  }
    cout << res << "\n";

}


Measured memory_bytes: 256
//invincible M15
//IIT-(ISM)Dhanbad
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define pi  3.141592653589793238462643383279
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define high_functioning_sociopath  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const unsigned int M = 998244353;
/*------------------------------------- THE GAME IS ON ---------------------------------------------*/
void solve()
{
     double d,t,s;
     cin>>d>>t>>s;
     ((d/s)<=t) ? cout<<"Yes\n" : cout<<"No\n";
}
int32_t main()
{
   high_functioning_sociopath
   ll t=1;
   //cin>>t;
   while(t--)
   {
      solve();
   }
}

Measured memory_bytes: 3680
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty |) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty | $n:expr) => {
        (0..$n).map(|_| get!($t |)).collect::<Vec<_>>()
    };
}

const MOD: u64 = 1_000_000_007;

fn main() {
    let (N, M) = get!(usize, usize);
    let mut As = get!(usize; M);
    As.sort();
    let mut dp = vec![0u64; N+1];
    dp[0] = 1 * ((!As.binary_search(&(0)).is_ok()) as u64);
    dp[1] = 1 * ((!As.binary_search(&(1)).is_ok()) as u64);
    for i in 2..(N+1) {
        let h1 = (!As.binary_search(&(i-1)).is_ok()) as u64;
        let h2 = (!As.binary_search(&(i-2)).is_ok()) as u64;
        dp[i] = dp[i-1] * h1 + dp[i-2] * h2;
        dp[i] %= MOD;
    }
    println!("{}", dp[N]);
}


Measured memory_bytes: 6396
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;

int main(){
  int x,y;
  cin>>x>>y;
  cout<<x+y/2<<endl;
}


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

int main() {
  int n;
  vector<long> vec;
  cin >> n;
  for (int i=0; i<n; i++) {
    int tmp;
    cin >> tmp;
    vec.push_back(tmp);
  }
  sort(vec.begin(), vec.end());
  long sum1=0, sum2=0;
  if (n%2==1) {
    for (int i=0; i<n/2-1; i++) {
      sum1 += 2*vec[n-i-1]-2*vec[i];
      sum2 += 2*vec[n-i-1]-2*vec[i];
    }
    sum1 += vec[n/2+1]+vec[n/2]-2*vec[n/2-1];
    sum2 += 2*vec[n/2+1]-vec[n/2]-vec[n/2-1];
  } else {
    for (int i=0; i<n/2-1; i++) {
      sum1 += 2*vec[n-i-1]-2*vec[i];
    }
    sum1 += vec[n/2] - vec[n/2-1];
  }
  if (sum1>sum2) cout << sum1 << endl;
  else cout << sum2 << endl;

  return 0;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
#define itn int
typedef long long ll;
int h,w,k;
string s[10];
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
int main(){
	cin>>h>>w>>k;
	for(int i=0;i<h;i++){
		cin>>s[i];
	}
	int mnans=1e9+1;
	for(int m=0;m<(1 << (h - 1));m++){
		int cnt= __builtin_popcount(m);
		int t=cnt;
		vector<int> cu(cnt+1,0);
		for(int j=0;j<w;j++){
			int p1=0;
			for(int i=0;i<h;i++){
				cu[p1]+=(s[i][j]=='1');
				if((m >> i)&1){
					p1++;
				}
			}
			bool bad=false;
			for(int i=0;i<cu.size();i++){
				if(cu[i]>k)	bad=true;
			}
			if (bad) {
                t++;
                fill(cu.begin(), cu.end(), 0);
                int p1 = 0;
                for(int i=0;i<h;i++) {
                    cu[p1] += (s[i][j] == '1');
                    if ((m >> i) & 1) {
                        p1++;
                    }
                }
                bool bad = false;
                for(int i=0;i<cu.size();i++) {
                    if (cu[i] > k) {
                        bad = true;
                    }
                }
                if (bad) {
                    t =1e9+1;
                }
            }
		}
		setmin(mnans, t);
	}
	cout<<mnans<<endl;
	return 0;
}   

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N, X, M;
    cin >> N >> X >> M;

    ll sumList[M + 1];
    ll firstAppearedNum[M + 1];
    rep(i, M + 1){
        sumList[i] = 0;
        firstAppearedNum[i] = -1;
    }
    ll counter = 1;
    ll sum = 0;
    while(firstAppearedNum[X] == -1 & counter <= N){
        firstAppearedNum[X] = counter;
        sum += X;
        sumList[counter] = sum;
        X = X * X % M;//cout << "a: " << X << ", sum: " << sum << endl;
        counter++;
    }
    ll loopSize;
    if(firstAppearedNum[X] == -1){
        loopSize = counter - 1;
    }else{
        loopSize = counter - firstAppearedNum[X];
    }//cout << "aaa" << counter - loopSize - 1 << endl;
    
    ll ans = 0;
    ans += sumList[counter - loopSize - 1];//cout << "ans1: " << ans << endl;
    ans += (sumList[counter - 1] - sumList[counter - loopSize - 1]) * ((N - (counter - loopSize - 1)) / loopSize);//cout << "ans2: " << ans <<endl;
    ans += sumList[(N - (counter - loopSize - 1)) % loopSize + (counter - loopSize - 1)] - sumList[counter - loopSize - 1];//cout << "ans3: " << ans << endl;

    cout << ans << endl;

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

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

    vector<string> sa(2, string(""));
    int idx = 0;

    rep(i, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            ++idx;
        }
        else if (t == 2)
        {
            int f;
            char c;
            cin >> f >> c;
            string cs(1, c);
            if (f == 1)
            {
                sa[idx % 2] += cs;
            }
            else if (f == 2)
            {
                sa[(idx+1) % 2] += cs;
            }
        }
        // cerr << " - " << s << endl;
    }

    cerr << idx << " --- " << sa[0] << " --- " << s << " --- " << sa[1] << endl;

    string ans("");
    if(idx % 2 == 0){
        reverse(sa[0].begin(), sa[0].end());
        ans = sa[0] + s + sa[1];       
        cerr << "aaa " << idx << " --- " << sa[0] << " --- " << s << " --- " << sa[1] << endl;
    }else{
        reverse(sa[1].begin(), sa[1].end());
        reverse(s.begin(), s.end());
        ans = sa[1] + s + sa[0]; 
        cerr << "bbb " << idx << " --- " << sa[0] << " --- " << s << " --- " << sa[1] << endl;
    }

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


Measured memory_bytes: 1348
#include <bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;
template <typename T> using vvec = vector<vector<T>>;

constexpr int64_t mpow(int64_t a, int64_t b, int64_t mod = 1000000007) {
    if (b <= 0) { return 1; } if (b == 1) { return a % mod; } if (b == 2) { return (a * a) % mod; }
    return (max(a * (b & 1), (int64_t)1) * mpow(mpow(a, b / 2, mod), 2, mod)) % mod;
}
constexpr int64_t mdiv(int64_t a, int64_t b, int64_t mod = 1000000007) {
    return (a * mpow(b, mod - 2, mod)) % mod;
}

void dfs(vvec<int> &g, vec<int> &c, vec<int> &v, int cv, int &cn) {
    if (v[cv] != -1) return;
    v[cv] = c[cn++];
    for (auto n : g[cv]) {
        dfs(g, c, v, n, cn);
    }
}

int main() {
    int n; cin >> n;
    vvec<int> g(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b; cin >> a >> b; --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vec<int> c(n);
    for (auto &e : c) cin >> e;
    sort(c.rbegin(), c.rend());

    int cn = 0;
    vec<int> v(n, -1);
    dfs(g, c, v, 0, cn);

    int m = 0;
    for (int i = 1; i < n; ++i) m += c[i];
    cout << m << endl;
    for (int i = 0; i < n; ++i) {
        cout << v[i] << (i + 1 == n ? "" : " ");
    }
    cout << endl;
}



Measured memory_bytes: 4648
# -*- coding: utf-8 -*-


def main():
    n, k = map(int, input().split())
    max_comb = (n - 1) * (n - 2) // 2

    if k > max_comb:
        print(-1)
        exit()

    ans = list()
    candidates = list()

    for i in range(1, n):
        ans.append((1, i + 1))

    for i in range(1, n - 1):
        for j in range(i + 1, n):
            candidates.append((i + 1, j + 1))

    for i in range(max_comb - k):
        ans.append(candidates[i])

    m = len(ans)
    print(m)

    for i in range(m):
        print(ans[i][0], ans[i][1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3992
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def f(st):
    xs = list(map(int, input().split()))
    sa = [abs(x - st) for x in xs]
    G = sa[0]
    for sk in sa:
        G = gcd(G, sk)
    print(G)


n, st = map(int, input().split())
f(st)


Measured memory_bytes: 14480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, ans, cnt, mx, mn;
string s, t;
ll dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};
string alphabet = "abcdefghijklmnopqrstuvwxyz";

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n >> m){
        ll v[n];
        rep(i, n){
            cin >> v[i];
        }
        if(v[0] > m){
            ans = v[0] - m;
            v[0] = m;
        }else{
            ans = 0;
        }
        rep(i, 1, n){
            if(v[i] + v[i - 1] > m){
                ans += v[i] - (m - v[i - 1]);
                v[i] = m - v[i - 1];
            }
        }
        print(ans);
    }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
        #define int long long
        #define endl '\n'
        using namespace std;
        signed main(){
        iostream::sync_with_stdio(0),cin.tie(0);
        int n;
        cin>>n;
        set<string>lol;
        while(n--){
        string s;
        cin>>s;
        lol.insert(s);
        }
        cout<<lol.size();
        }


Measured memory_bytes: 19200
// D - People on a Line
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
int in(){int x;scanf("%d",&x);return x;}

#define TMAX 100000
vector<pair<int,int>> T[TMAX+1];
int dist[TMAX+1];

void dfs(int p, int w){
	if(dist[p] != INT_MAX) return;
	dist[p] = w;
	for(auto cw:T[p]){
		int np,nw; tie(np,nw) = cw;
		dfs(np, w+nw);
	}
}

bool solve(){
	int N=in(), M=in();
	if(!M) return true;

	int L = INT_MAX, R = 0;
	while(M--){
		int l=in(), r=in(), d=in();
		T[l].emplace_back(r, d);
		T[r].emplace_back(l,-d);
		L = min(L, l);
		R = max(R, r);
	}

	rp(i, 1, N+1) dist[i] = INT_MAX;
	rp(l, L, R+1){
		dfs(l, 0);
		for(auto rd:T[l])
			if(rd.second != dist[rd.first]-dist[l]) return false;
	}
	return true;
}

int main(){
	puts(solve()?"Yes":"No");
}

Measured memory_bytes: 11008
/*
* @Author: kabbo
* @Date:   2020-06-04 21:16:41
* @Last Modified by:   kabbo
* @Last Modified time: 2020-06-06 01:44:12
*/
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define endl '\n'
#define ull unsigned long long
#define ll long long
const int mod = 1e9 + 7;
using u64 = uint64_t;
using u128 = __uint128_t;

void solve() {
	ll n, m;
	cin >> n >> m;
	auto ans = (n * (n - 1) / 2);
	ans += (m * (m - 1) / 2);
	cout << ans << endl;
}
int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	/*int t;
	cin >> t;
	for (int i(1); i <= t; ++i) {*/
	//printf("Case %d: ", i);
	solve();
	//}
#ifndef LOCAL_DEFINE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long int n,k,ans=0;
  cin >> n >> k;
  vector <long int> h(n);
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  sort(h.begin(),h.end(),greater<int>());
  for(int i=0;i<n;i++){
    if(i>=k){
      ans+=h[i];
    }
  }
  cout << ans <<"\n";
}

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

int main() {
    int A,B;
    cin>>A>>B;
    int a=A;
    if(B==1){
        cout<<0<<endl;
        return 0;
    }
    int count=1;
    while(a<B){
        count++;
        a=a-1+A;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
import { readFileSync } from "fs";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { cin, nCin, biCin } = (() => {
  const inputs = readFileSync("/dev/stdin", "utf-8").split(/[\n|\s]+/);
  let count = 0;
  const cin = () => inputs[count++];
  return { cin: cin, nCin: () => Number(cin()), biCin: () => BigInt(cin()) };
})();

const range = (n: number | bigint) => [...Array(Number(n))].map((_, i) => i);

type Color = "Black" | "White";
type Grid = Color[][] & {
  height: number;
  width: number;
};
type PickData = {
  index: number;
  isPicked: boolean;
};

const getBlackCnt = (hPicks: PickData[], wPicks: PickData[], grid: Grid) =>
  hPicks
    .filter(({ isPicked }) => isPicked)
    .map(({ index }) => {
      const cs = grid[index];
      return wPicks
        .filter(({ isPicked }) => isPicked)
        .map(({ index }) => (cs[index] === "Black" ? 1 : 0) as number)
        .reduce((acc, x) => acc + x, 0);
    })
    .reduce((acc, x) => acc + x, 0);

const wPickFn = (K: number, grid: Grid, hPicks: PickData[], initialBlackCnt: number) => {
  const wPickFn = (n: number, wPicks: PickData[]): number =>
    n >= grid.width
      ? (() => {
          const hCnt = getBlackCnt(
            range(grid.height).map((i) => ({ index: i, isPicked: true })),
            wPicks,
            grid
          );
          const wCnt = getBlackCnt(
            hPicks,
            range(grid.width).map((j) => ({ index: j, isPicked: true })),
            grid
          );
          const hwCnt = getBlackCnt(hPicks, wPicks, grid);

          return initialBlackCnt - (hCnt + wCnt - hwCnt);
        })() === K
        ? 1
        : 0
      : wPickFn(n + 1, wPicks) +
        wPickFn(
          n + 1,
          wPicks.map(({ index, isPicked }) =>
            index === n ? { index: index, isPicked: true } : { index: index, isPicked: isPicked }
          )
        );
  return wPickFn(
    0,
    range(grid.width).map((j) => ({ index: j, isPicked: false }))
  );
};

const hPickFn = (grid: Grid, K: number, initialBlackCnt: number) => {
  const hPickFn = (n: number, hPicks: PickData[]): number =>
    n >= grid.height
      ? wPickFn(K, grid, hPicks, initialBlackCnt)
      : hPickFn(n + 1, hPicks) +
        hPickFn(
          n + 1,
          hPicks.map(({ index, isPicked }) =>
            index === n ? { index: index, isPicked: true } : { index: index, isPicked: isPicked }
          )
        );
  return hPickFn(
    0,
    range(grid.height).map((i) => ({ index: i, isPicked: false }))
  );
};

const getCnt = (K: number, grid: Grid, initialBlackCnt: number) => hPickFn(grid, K, initialBlackCnt);

{
  const [H, W, K] = [nCin(), nCin(), nCin()];

  const grid: Grid = (() => {
    const grid: Color[][] = range(H).map(() =>
      cin()
        .split("")
        .map((c) => (c === "#" ? "Black" : "White") as Color)
    );
    return { ...grid, height: H, width: W };
  })();

  const initialBlackCnt = getBlackCnt(
    range(grid.height).map((i) => ({ index: i, isPicked: true })),
    range(grid.width).map((j) => ({ index: j, isPicked: true })),
    grid
  );

  const cnt = getCnt(K, grid, initialBlackCnt);

  console.log(cnt);
}


Measured memory_bytes: 40304
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 

vll dp(100100);

ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  st s;
    ci(s);
  ll k;
    ci(k);
  vll A(0);
  ll n=s.sz;
  ll count=1;
  ll ans=0;
  if(n==1){
    ans=k/2;
  }
  
  else{    
  FOR(i,1,n){
    if(s[i-1]==s[i]){
      count++;
    }
    else{
      A.push_back(count);
      count=1;
    }
  }
  if(count!=1){
    A.push_back(count);
  }
  
  ll a=A.sz;
  
  FOR(i,1,a-1){
    ans+=A[i]/2*k;
  }
  
  if(s[0]==s[n-1]){
    if(a!=1){
    ans+=(A[0]+A[a-1])/2*(k-1);
    ans+=A[0]/2;
    ans+=A[a-1]/2;
    }
    else{
    ans+=k*A[0]/2;
    }
  }
  else{
    ans+=A[0]/2*k;
    ans+=A[a-1]/2*k;
  }
  }
  co(ans)
}

Measured memory_bytes: 1024
m = list(map(int, input().split()))

    # 解法1 sort
#    print(sorted(m)[0] + sorted(m)[1])
    # 解法2 max
#    print(sum(l)-max(m)) # maxの使用
    # 解法3 heapq  https://note.nkmk.me/python-max-min-heapq-nlargest-nsmallest/
import heapq
print(sum(heapq.nsmallest(2, m)))

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	vector<pair<int, int> > A;
	int n;
	cin>>n;
	for(int i=0; i<n; i++){
		int x,y;
		cin>>x>>y;
		A.push_back(make_pair(x,y));
	}
	sort(A.begin(), A.end());
	for(int i=0; i<n; i++){
		cout<<A[i].first<<" "<<A[i].second<<endl;
	}
	return 0;
}


Measured memory_bytes: 3864
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int d = saori.saori_hayami();
		int num = 0;
		if(n == 0){
			if(d == 100){
				System.out.println(101);
			} else {
				System.out.println(d);
			}
			
		} else if(n == 1){
			if(d == 100){
				System.out.println(100*101);
			} else {
				System.out.println(100*d);
			}
			
		} else {
			if(d == 100){
				System.out.println(10000*101);
			} else {
				System.out.println(10000*d);
			}
			
		}

		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

int main(){ 
    int n;
    cin>>n;
    int a[4]={0,0,0,0};
    for(int i=0;i<n;i++){
        string ch;
        cin>>ch;
        if(ch=="AC") a[0]++;
        else if(ch=="WA") a[1]++;
        else if(ch=="TLE") a[2]++;
        else if(ch=="RE") a[3]++;
    }
    cout<<"AC x "<<a[0]<<endl;
    cout<<"WA x "<<a[1]<<endl;
    cout<<"TLE x "<<a[2]<<endl;
    cout<<"RE x "<<a[3]<<endl;
    
    return 0;
}



Measured memory_bytes: 3504
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
lint lcm(lint a,lint b){
      return a/__gcd(a,b)*b;
  }
 struct edge{lint to,id;};
vector<vector<edge>> g;
vector<lint>ans;
void dfs(lint v,lint p=-1,lint iid=-1){
    lint k=1;
        rep(i,g[v].size()){
    
            lint a=g[v][i].to;
            lint b=g[v][i].id;
            if(a==p)continue;
              if(k==iid)k++;
            ans[b]=k;k++;
            dfs(a,v,ans[b]);
        }
}
  int main(){
      lint N;
      cin>>N;
     g.resize(N);
     ans.resize(N);
      rep(i,N-1){
          lint a,b;
          cin>>a>>b;
          --a;--b;
          g[a].push_back({b,i});
          g[b].push_back({a,i});
      }
      dfs(0);
      lint mx=0;
      rep(i,N)mx=max(mx,(lint)g[i].size());
      cout<<mx<<endl;
      rep(i,N-1){
          cout<<ans[i]<<endl;
      }
     

  }
  

Measured memory_bytes: 9728
local n = io.read("*n")
local a = {}
for i = 1, n do a[i] = io.read("*n") end
local cnt = 0

local function getminmax()
  local min, max, maxp = a[1], a[1], 1
  for i = 2, n do
    if max < a[i] then
      max, maxp = a[i], i
    end
    if a[i] < min then
      min = a[i]
    end
  end
  return min, max, maxp
end
while true do
  local min, max, maxp = getminmax()
  if max - min <= n then break end
  local rep = (max - min) // (n + 1)
  cnt = cnt + rep
  for i = 1, n do
    if i == maxp then
      a[i] = a[i] - rep * n
    else
      a[i] = a[i] + rep
    end
  end
end
do
  local min = getminmax()
  while n <= min do
    local rep = min // n
    cnt = cnt + rep * n * (n - 1)
    for i = 1, n do
      a[i] = a[i] - rep * (n - 1)
    end
    min = getminmax()
  end
end
while true do
  local min, max, maxp = getminmax()
  if max < n then break
  else
    cnt = cnt + 1
    for i = 1, n do
      if i == maxp then a[i] = a[i] - n
      else a[i] = a[i] + 1
      end
    end
  end
end

print(cnt)


Measured memory_bytes: 760
#include<stdio.h>

int main() {
	int A, B;
	int p, s, m;
	int max;
	scanf("%d %d", &A, &B);
	p = A + B;
	s = A - B;
	m = A * B;
	if (p >= s&&p>=m)max = p;
	else if (s >= p && s >= m)max = s;
	else max = m;
	printf("%d\n", max);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  int N;
    cin >> N;
    vector<int> X(N);
    for(int i = 0;i < N;i++){
        cin >> X[i];
    }
    
    int ans = 1e9;
    for(int i=1;i<=100;i++){
        int cost = 0;
        for(int j = 0;j<N;j++){
           cost += (X[j]-i)*(X[j]-i);
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;
  
}

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

typedef long long int llint;

int e[400000] = {};
int w[400000] = {};

int main()
{
  int n;
  string s;

  cin>> n >> s;

  
  for(int i = 1; i <= n; i++) {
    e[i] = e[i - 1];
    w[i] = w[i - 1];
    if(s[i - 1] == 'E') e[i]++;
    if(s[i - 1] == 'W') w[i]++;
  }

  int mn = 1145141919;

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

    int tmp = w[i - 1] + e[n] - e[i];

    mn = min(mn, tmp);

  }

  cout<< mn <<endl;
  
  return 0;
}


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

#define F first
#define S second
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll INF=1e17;


ll gcd(ll x,ll y){
return y? gcd(y,x%y):x;
}


// auto mod int
const int mod = 1000000007;
//const int mod = 998244353;
struct mint { 
ll x; // typedef long long ll; 
mint(ll x=0):x((x%mod+mod)%mod){}

mint operator-() const { return mint(-x);} 

mint& operator+=(const mint a) { 
if ((x += a.x) >= mod) x -= mod; 
return *this; 
} 
mint& operator-=(const mint a) { 
if ((x += mod-a.x) >= mod) x -= mod; return *this; 
} 
mint& operator*=(const mint a) { (x *= a.x) %= mod;
return *this;
} 

mint operator+(const mint a) const {
return mint(*this) += a;} 

mint operator-(const mint a) const { return mint(*this) -= a;} 

mint operator*(const mint a) const { return mint(*this) *= a;} 

mint pow(ll t) const { 
if (!t) return 1; 
mint a = pow(t>>1); 
a *= a; 
if (t&1) a *= *this; 
return a; 
} 

// for prime mod 
mint inv() const { return pow(mod-2);}

mint& operator/=(const mint a) { return *this *= a.inv();} 

mint operator/(const mint a) const { return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}

ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint choose (int n, int r){
  mint x=1,y=1;
  rep(i,r){
    x*=n-i;
    y*=i+1;
  }
return x/y;
}


int main(){
  string s,t;
  int cnt=0;
  cin>>s>>t;
  rep(i,s.size()){
    if(s[i]!=t[i]){cnt++;}
  }
  cout<<cnt<<endl;
return 0;
}


Measured memory_bytes: 3920
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    a,b = map(int, input().split())
    if a > 0:
        print('Positive')
    elif b>=0:
        print('Zero')
    else:
        if (b-a+1)%2 == 0:
            print('Positive')
        else:
            print('Negative')

if __name__ == '__main__':
    main()

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

const int MAX_N = 100;

int n;
int a[MAX_N + 1];

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

  int ans = 1000000;

  for (int i = - 100; i < 101; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      cnt += (a[j] - i) * (a[j] - i);
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define gcd(x,y) __gcd(x,y)
#define PI 3.14159265
#define endl "\n"
#define count_ones __builtin_popcountl
#define piii pair<int,pair<int,int>>
const int N=1e5+20,MOD=(int)(1e9)+7;
const int oo = 0x3f3f3f3f;
typedef long long ll;
using namespace std;
inline void boost(){
	ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}
/* -------------------------------------- */
/* -------------------------------------- */
int main() {
	boost();
	ll n;cin>>n; n--;
	cout<<ll(n*(n+1)/2);
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll inf = 1e9 + 7;
const ll Mod = 998244353;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

int N, M;
ll X[1005][3], Score[1005];
bool now[3];

int Prepare(int num){
  fill(Score, Score + N, 0);
  for (int i = 0; i < 3; i++){
    now[i] = num % 2; num /= 2;
  }
  return 0;
}

int main(){
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++){
    for (int j = 0; j < 3; j++){
      scanf("%lld", &X[i][j]);
    }
  }

  
  ll ans = 0;
  for (int i = 0; i < 8; i++){
    Prepare(i);
    for (int j = 0; j < N; j++){
      for (int k = 0; k < 3; k++){
        if (now[k]) Score[j] += X[j][k];
        else Score[j] -= X[j][k];
      }
    }
    sort(Score, Score + N, greater<ll>());

    ll sum = 0;
    for (int j = 0; j < M; j++){
      sum += Score[j];
    }
    ans = max(sum, ans);
  }
  cout << ans << endl;

  return 0;
}


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

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        Integer[] h = new Integer[n];
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(sc.next());
        }

        Arrays.sort(h);
        int min = h[h.length - 1] - h[0];
        for (int i = 0; i < n - k + 1; i++) {
            min = Math.min(min, h[i + k - 1] - h[i]);
        }

        System.out.println(min);
    }
}

Measured memory_bytes: 49012
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int N, M;

    scanf("%d%d", &N, &M);

    int t = 1900 * M + 100 * (N-M);

    printf("%d\n", t * (int)pow(2,M));

    return 0;
}

Measured memory_bytes: 2568
#include<iostream>
using namespace std;
int main(){
  int arr[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin>>k;
  cout<<arr[k-1];
  return 0;
}
   

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<stack>
#include<sstream>
//#include <Eigen/Dense>
//#include <Eigen/Geometry>
//using namespace Eigen;
using namespace std;

int n;
const int maxn = 2e5 + 100;
int mod = 1e9 + 7;
vector<int> g[maxn];
int vis[maxn], sz[maxn];
long long ans[maxn], inv[maxn];

void inv_n(int n)
{
	inv[1] = 1;
	for (long long i = 2; i <= n; i++)
	{
		inv[i] = inv[mod%i] * (mod - mod / i) % mod;
	}
}


long long dfs1(int cur,int p)
{
	sz[cur] = 1;
	for (int i : g[cur])
	{
		if (i != p)	
			sz[cur] += dfs1(i, cur);
	}
	return sz[cur];
}

void dfs2(int cur, int p)
{
	ans[cur] = ans[p] * sz[cur] % mod * inv[(n - sz[cur])] % mod;//ans[p] * sz[cur] * inv[(n - sz[cur])] % mod溢出报错
	for (int i : g[cur])
	{
		if (i != p)
			dfs2(i,cur);
	}
}
int main()
{
	int u, v;
	cin >> n;
	inv_n(n);
	for (int i = 0; i < n - 1; i++)
	{
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	ans[1] = 1;
	for (int i = 1; i <= n; i++)
		ans[1] = ans[1] * i%mod;
	dfs1(1, 0);
	for (int i = 1; i <= n; i++)
		ans[1] = ans[1] * inv[sz[i]] % mod;
	
	for (int i : g[1])
		dfs2(i, 1);
	for (int i = 1; i <= n; i++)
		cout << ans[i] << endl;

	return 0;
}

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

int table[15][10];
bool sign[15][10];

signed main(void){
  int H;
  while(cin >> H){
    
    if( H == 0 ){ return 0;}
    
    for(int i = 0; i < H; i++){
      for(int j = 0; j < 5; j++){ 
        cin >> table[H-i-1][j];
      }
    }// H方向に消える↪︎0方向に消える　としたい
    
    int ans = 0;
    
    while(true){ //消えるものがある限り続ける
      
      bool flag = true;
      
      for(int i = 0; i < H; i++){ 
        //５つ消える時について
        for(int j = 0; j < 5; j++){ sign[i][j] = false;} //初期化
        
        if( table[i][0] == table[i][1] && table[i][1] == table[i][2] && table[i][2] == table[i][3] && table[i][3] == table[i][4]){
          if( table[i][0] != -1 ){
  
          sign[i][0] = true;
          sign[i][1] = true;
          sign[i][2] = true;
          sign[i][3] = true;
          sign[i][4] = true;
          flag = false; ans += table[i][0]*5;
          }
        }//５つ全部消える場合
        
        else if( table[i][0] == table[i][1] && table[i][1] == table[i][2] && table[i][2] == table[i][3] ){
          if(table[i][0] != -1){
          sign[i][0] = true; sign[i][1] = true; sign[i][2] = true; sign[i][3] = true;
          flag = false; ans += table[i][0]*4;
          }
        }
        else if( table[i][1] == table[i][2] && table[i][2] == table[i][3] && table[i][3] == table[i][4] ){
          if(table[i][1] != -1){
          sign[i][1] = true; sign[i][2] = true; sign[i][3] = true; sign[i][4] = true;
          flag = false; ans += table[i][1]*4;
          }
        }
        //４つ消える場合
        else if( table[i][0] == table[i][1] && table[i][1] == table[i][2] ){
          if(table[i][0] != -1 ){ 
          sign[i][0] = true; sign[i][1] = true; sign[i][2] = true;
          flag = false; ans += table[i][0]*3;
          }
        }
        else if( table[i][1] == table[i][2] && table[i][2] == table[i][3] ){
          if(table[i][1] != -1){
          sign[i][1] = true; sign[i][2] = true; sign[i][3] = true;
          flag = false; ans += table[i][1]*3;
          }
        }
        else if( table[i][2] == table[i][3] && table[i][3] == table[i][4] ){
          if(table[i][2] != -1){
          sign[i][2] = true; sign[i][3] = true; sign[i][4] = true;
          flag = false; ans += table[i][2]*3;
          }
        }
        //3つ消える場合
        
      }//for-i 
      
      //以上コンボが決まるものについて印signをつけた
      vector<int> vec;
      for(int j = 0; j < 5; j++){ 
        vec.clear();
        for(int i = 0; i < H; i++){ 
          if( !sign[i][j] && table[i][j] != -1 ){ // 消さなものだけ残していく
            vec.push_back(table[i][j]);
          }
        }//for-H
        int m = vec.size();
        for(int i = 0; i < H; i++){ 
          if( i < m ){ 
           table[i][j] = vec[i];
          }
          else{
            table[i][j] = -1; //空いたところには-1を埋める
          }
        }//for-i
      }//for-j
      
      if(flag){ //もう消すところがなかった
        break;
      }
      
    }//while-true
    
    cout << ans << endl;
    
  }//while-cin
  
  return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

//gcd,lcm,べき,二進展開
//組み合わせ、mod計算
//最短路問題、bit、union find

///////////////////////////

int frac(int n) {
	if (n == 0) { return 1; }
	else { return frac(n-1)*n; }
}



int main() {
	
	ll N;
	ll P[10];
	ll Q[10];
	cin >> N;

	repn(i, N) cin >> P[i];
	repn(i, N) cin >> Q[i];

	ll a = 1;
	repn(i, N) {
		ll t = 0;
		for (int j = i + 1; j <= N; j++) {
			if (P[i] > P[j]) { t++; }
		}
		a += t * frac(N - i);
	}

	ll b = 1;
	repn(i, N) {
		ll t = 0;
		for (int j = i + 1; j <= N; j++) {
			if (Q[i] > Q[j]) { t++; }
		}
		b += t * frac(N - i);
	}

	cout << abs(a - b);

	system("PAUSE");


}


Measured memory_bytes: 504