akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

struct edge {
    int to;
    int64_t cost;
    edge(int x=0, int64_t y=0):to(x), cost(y) {}
};

vector<vector<edge> > G; // resizeの必要あり
struct dijkstra {
    vector<int64_t> d;
    dijkstra(int s, int n):d(n, INT64_MAX/3) { // sはスタート,nは頂点数
        d[s] = 0LL;
        priority_queue<pair<int64_t, int>, vector<pair<int64_t, int> >, greater<pair<int64_t, int> > > que;
        que.push(make_pair(0LL, s));
        while(!que.empty()) {
            pair<int64_t, int> now = que.top();
            que.pop();
            if(now.first != d[now.second]) continue;
            for(edge next:G[now.second]) {
                if(d[next.to] > d[now.second] + next.cost) {
                    d[next.to] = d[now.second] + next.cost;
                    que.push(make_pair(d[next.to], next.to));
                }
            }
        }
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, s;
    cin >> n >> m >> s;
    int ma = 0;
    vi u(m), v(m), a(m), b(m);
    rep(i, m) {
        cin >> u[i] >> v[i] >> a[i] >> b[i];
        ma = max(ma, a[i]);
    }
    ma *= n-1;
    s = min(s, ma);
    vi c(n), d(n);
    rep(i, n) {
        cin >> c[i] >> d[i];
    }
    auto num = [&](int money, int place) {
        return money + place*ma+place;
    };
    G.resize(ma*n+n);
    rep(i, m) {
        rep(j, ma+1) {
            if(j >= a[i]) {
                G[num(j, u[i]-1)].emplace_back(num(j-a[i], v[i]-1), b[i]);
                G[num(j, v[i]-1)].emplace_back(num(j-a[i], u[i]-1), b[i]);
            }
        }
    }
    rep(i, n) {
        rep(j, ma+1) {
            if(j >= c[i]) {
                G[num(j-c[i], i)].emplace_back(num(j, i), d[i]);
            }
            if(j+c[i] > ma and j != ma) {
                G[num(j, i)].emplace_back(num(ma, i), d[i]);
            }
        }
    }
    dijkstra D(num(s, 0), G.size());
    

    rep(t, n) {
        if(!t) continue;
        ll ans = INT64_MAX;
        rep(i, ma) {
            ans = min(ans, D.d[num(i, t)]);
        }
        cout << ans << '\n';
    }
}

Measured memory_bytes: 23328
type UnionFind=record n:Longint;pr:Array of Longint;end;
procedure init(var uf:UnionFind;N:Longint);
var i:Longint;
begin
	uf.n:=N;
	setlength(uf.pr,N);
	for i:=1 to N do uf.pr[i]:=-1;
end;
function find(var uf:UnionFind;a:Longint):Longint;
begin
	if uf.pr[a]<0 then find:=a else begin
		uf.pr[a]:=find(uf,uf.pr[a]);
		find:=uf.pr[a];
	end;
end;
function same(var uf:UnionFind;a,b:Longint):Boolean;
begin
	same:=find(uf,a)=find(uf,b);
end;
function unite(var uf:UnionFind;a,b:Longint):Boolean;
begin
	a:=find(uf,a);
	b:=find(uf,b);
	if a=b then unite:=false else begin
		if uf.pr[a]>uf.pr[b] then begin
			inc(uf.pr[b],uf.pr[a]);
			uf.pr[a]:=b;
		end else begin
			inc(uf.pr[a],uf.pr[b]);
			uf.pr[b]:=a;
		end;
		unite:=true;
	end;
end;
function size(var uf:UnionFind;a:Longint):Longint;
begin
	size:=-uf.pr[find(uf,a)];
end;
var
	N,M,i:Longint;
	uf:UnionFind;
	now,x,y:int64;
	ans:Array[1..100000]of int64;
	u,v:Array[1..100000]of Longint;
begin
	read(N,M);
	for i:=1 to M do begin
		read(u[i],v[i]);
	end;
	init(uf,N);
	x:=N;
	y:=N-1;
	now:=x*y div 2;
	for i:=M downto 1 do begin
		ans[i]:=now;
		if not same(uf,u[i],v[i])then begin
			x:=size(uf,u[i]);
			y:=size(uf,v[i]);
			dec(now,x*y);
		end;
		unite(uf,u[i],v[i]);
	end;
	for i:=1 to M do writeln(ans[i]);
end.


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

uint64_t score(const vector<int64_t>& a, int64_t avg) {
  uint64_t ret = 0;
  for (auto& e : a) {
    ret += abs(e - avg);
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;

  vector<int64_t> a;
  a.resize(n);
  int64_t sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a[i] -= 1 + i;
    sum += a[i];
  }
  sort(a.begin(), a.end());
  int64_t mid = a[n/2];
  uint64_t result = ~0LLU;
  for (int i = -2; i <= 2; ++i) {
    result = min(result, score(a, a[n/2+i]));
  }
  cout << result << "\n";
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

typedef long long ll;

const ll mod=1e9+7;

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

#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define rc(x)  return cout<<x<<"\n",0
#define sz(s)  (int) s.size()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;

ll t;
const int nax = 405;
const ll INF = 1e18;
ll dp[nax][nax];
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	vector<int>a(n+1);
	for(ll i=0;i<n;i++)cin>>a[i];
	for (int L = n-1; L>=0; L--) {
		for (int R=L; R<n; R++) {
			if (L==R) {
				dp[L][R] = 0;
			}
			else {
				dp[L][R]=INF;
				ll sum=0;
				for(ll i=L;i<=R;i++)sum+=a[i];
				for (int i=L; i<=R-1; i++) {
					dp[L][R]=min(dp[L][R], dp[L][i] + dp[i+1][R] + sum);
				}
			}
		}
	}
	 printf("%lld\n", dp[0][n-1]);
}


Measured memory_bytes: 4976
//============================================================================
// Name        : HelloWorld.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
typedef long long ll;
using namespace std;
int a,b;
int main() {
	cin>>a>>b;

	if(a<=b){
	    	cout<<a<<endl;
	    }else{
	    	cout<<a-1<<endl;
	    }


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	int res = 0;
	for (int i = 0; i < m; i++){
		int a;
		cin >> a;
		res += a;
	}

	cout << max(n-res, -1) << endl;
}


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

int main()
{
     int id;
     double h, w;
     while (scanf("%d,%lf,%lf", &id, &w, &h) != EOF) {
          double b = (double)w / (h * h);
          if (b >= 25.0) cout << id <<endl;
     }

     return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define reps(i, n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define repi(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
void dfs(ll now,ll parent,ll d,vector<vector<pair<ll,ll>>> &graph, vector<ll> &ans){
    ans.at(now)=d;
    for(auto child : graph.at(now)){
        if(child.first==parent) continue;
        dfs(child.first,now,d+child.second,graph,ans);
    }
}
int main(){
    ll n;
    cin>>n;
    vector<vector<pair<ll,ll>>> graph(n,vector<pair<ll,ll>>());
    rep(i,n-1){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        graph.at(a).push_back(make_pair(b,c));
        graph.at(b).push_back(make_pair(a,c));
    }
    ll q,k;
    cin>>q>>k;
    k--;
    vector<ll> xs(q),ys(q);
    rep(i,q){
        cin>>xs.at(i)>>ys.at(i);
        xs.at(i)--; ys.at(i)--;
    }
    vector<ll> ans(n);
    dfs(k,-1,0,graph,ans);
    rep(i,q){
        ll x=xs.at(i),y=ys.at(i);
        cout<<ans.at(x)+ans.at(y)<<endl;
    }
}


Measured memory_bytes: 18944
from fractions import gcd
from functools import reduce

N, M, *A = map(int, open(0).read().split())

Y = reduce(lambda a, b: a * b // gcd(a, b), A)

print(M // (Y // 2) - (M // Y) if all((Y // a) % 2 for a in A) else 0)

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

vector<int> dp;
vector<vector<int>> ab,ba;

void dfs(int n){
    if(ab[n].size()==0){
        dp[n]=0;
    }
    for(int i=0;i<ab[n].size();i++){
        if(dp[ab[n][i]]==-1){
            dfs(ab[n][i]);
        }
        dp[n]=max(dp[n],dp[ab[n][i]]+1);
    }
}

int main(){

    int n,m;
    cin >> n >> m;
    ab=vector<vector<int>>(n);
    ba=vector<vector<int>>(n);
    dp=vector<int>(n,-1);

    rep(i,m){
        int s,t;
        cin >> s >> t;
        s--;t--;
        ab[s].push_back(t);
        ba[t].push_back(s);
    }

    for(int i=0;i<n;i++){
        if(ba[i].size()==0){
            dfs(i);
        }
    }
    int ans=0;
    rep(i,n){
        ans=max(ans,dp[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define ll long long
#define ALL(x) x.begin(), x.end()
#define fir first
#define sec second
#define INF (1ll << 60)
using namespace std;

int main()
{
    ll a, b, q;
    cin >> a >> b >> q;
    vector<ll> s, t;
    rep(i, a)
    {
        ll T;
        cin >> T;
        s.push_back(T);
    }
    rep(i, b)
    {
        ll T;
        cin >> T;
        t.push_back(T);
    }
    rep(i, q)
    {
        ll x;
        cin >> x;
        ll sl, sr, tl, tr;
        auto itr = lower_bound(ALL(s), x);
        if (itr == s.end())
        {
            sr = INF;
            sl = *(itr - 1);
        }
        else
        {
            sr = *itr;
            if (itr == s.begin())
            {
                sl = -INF;
            }
            else
                sl = *(itr - 1);
        }

        itr = lower_bound(ALL(t), x);
        if (itr == t.end())
        {
            tr = INF;
            tl = *(itr - 1);
        }
        else
        {
            tr = *itr;
            if (itr == t.begin())
            {
                tl = -INF;
            }
            else
                tl = *(itr - 1);
        }
        //cout << sl << "," << sr << "," << tl << "," << tr << endl;
        ll ans = min({
            llabs(x - sr) + llabs(sr - tr),
            llabs(x - sr) + llabs(sr - tl),

            llabs(x - sl) + llabs(sl - tr),
            llabs(x - sl) + llabs(sl - tl),

            llabs(x - tr) + llabs(tr - sr),
            llabs(x - tr) + llabs(tr - sl),

            llabs(x - tl) + llabs(tl - sr),
            llabs(x - tl) + llabs(tl - sl),
        });
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
 string s, t;
 string S, T;

 int N,M;
  
 int main(){ 

  cin >> s >> t;

   sort (s.begin(), s.end());
   sort (t.rbegin(), t.rend());


  if (s < t) cout << "Yes" << endl;    
   else cout << "No" << endl;


 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<stack>
#include<cmath>
#include<set>
//#define ll long long
using namespace std;
const int maxn=50;
const int INF=1000000000;
int length[maxn];
int t,ans=0;

void dfs(long long x,int x3,int x5,int x7)
{
    if(x3>0&&x5>0&&x7>0&&x<=t)
        ans++;
    if(x*10<t)
    {
        dfs(x*10+3,x3+1,x5,x7);
        dfs(x*10+5,x3,x5+1,x7);
        dfs(x*10+7,x3,x5,x7+1);
    }
}

int main()
{
    int n,k;
    cin>>t;
    dfs(0,0,0,0);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
N,X = map(int,input().split())

burger_len = [1]*(N+1)
burger_putty = [1]*(N+1)
for i in range(1,N+1):
    burger_len[i] = 3 + 2*burger_len[i-1]
    burger_putty[i] = 1 + 2*burger_putty[i-1]

def get_x(n,x):
    if n == 0:
        return int(x>0)
    tmp_len = burger_len[n-1]
    if x <= (tmp_len +1):
        return get_x(n-1,x-1)
    elif x == tmp_len + 2:
        return 1 + burger_putty[n-1]
    else:
        return burger_putty[n-1] + 1 + get_x(n-1,x-tmp_len-2)

print(get_x(N,X))

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	double[] GR => Strs.Select(double.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	const long INFL = 4011686018427387913L;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int[] a;
	void Solve()
	{
		var N = F;
		a = G;
		dp = new long[N + 1, N + 1, 2];
		done = new bool[N + 1, N + 1, 2];
		WriteLine(Calc(0, N, 0));
	}
	long[,,] dp;
	bool[,,] done;
	long Calc(int l, int r, int i)
	{
		if (!done[l, r, i])
		{
			done[l, r, i] = true;
			if (l < r)
			{
				if (i == 0) dp[l, r, i] = Max(Calc(l + 1, r, 1 - i) + a[l], Calc(l, r - 1, 1 - i) + a[r - 1]);
				else dp[l, r, i] = Min(Calc(l + 1, r, 1 - i) - a[l], Calc(l, r - 1, 1 - i) - a[r - 1]);
			}
		}
		return dp[l, r, i];
	}
}


Measured memory_bytes: 169688
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    int N, M;
    while (readf("%d %d\n", &N, &M), N || M) {
        int[] h = new int[N],
              w = new int[M];
        int[] sN = new int[N + 1];
        int[] sM = new int[M + 1];
        int[] c;
        foreach (i; 0 .. N) {
            readf("%d\n", &h[i]);
        }
        foreach (i; 0 .. M) {
            readf("%d\n", &w[i]);
        }
        sN[0] = 0;
        foreach (i; 0 .. N) {
            sN[i + 1] = sN[i] + h[i];
        }
        sM[0] = 0;
        foreach (i; 0 .. M) {
            sM[i + 1] = sM[i] + w[i];
        }
        foreach (i; 0 .. M) {
            foreach (j; i + 1 .. M + 1) {
                c ~= sM[j] - sM[i];
            }
        }
        c = c.sort.array;
        int ans = 0;
        foreach (i; 0 .. N) {
            foreach (j; i + 1 .. N + 1) {
                ans += c.assumeSorted.equalRange(sN[j] - sN[i]).length;
            }
        }
        ans.writeln;
    }
}

Measured memory_bytes: 24140
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <math.h>
//#include <vector>
#include <string>
//typedef long long LL;
using namespace std;

int main(){
    string s;
    int s_size;
    int a_3;
    int a_2;
    int a_1;
    int a_0;
    cin >> s;
    s_size = s.size();
    a_3 = 1;
    if(s[0]==s[1]){
        a_2 = 1;
        a_1 = 2;
    }else{
        a_2 = 2;
        if(s[1]==s[2]){
            a_1 = 2;
        }else{
            a_1 = 3;
        }
    }
    for(int i=3; i<s_size; i++){
        if(s[i-1]==s[i]){
            a_0 = a_3 + 2;
        }else{
            a_0 = a_1 + 1;
        }
        a_3 = a_2;
        a_2 = a_1;
        a_1 = a_0;
    }
    cout << a_0 << endl;
}

Measured memory_bytes: 640
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a, T b) { a = min(a, b); }
template<class T> void umax(T &a, T b) { a = max(a, b); }

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

const int mod = 1e9+7;
const int N = 2e5+5;

void solve(){
	int n;
	cin>>n;
	int a[n],b[n],v[n];
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	rep(i,n)v[i]=i+1;
	int aa=0,bb=0;
	int j=0;
	do{	bool ok=1,bok=1;
		j++;
		rep(i,n){
			if(v[i]!=a[i])ok=0;
			if(v[i]!=b[i])bok=0;
		}
		if(ok)aa=j;
		if(bok)bb=j;
	}
	while(next_permutation(v,v+n));
	cout<<abs(aa-bb);
}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
ll A,B,C;
  cin>>A>>B>>C;
  if(A+B+C>=22) {
    cout<<"bust"<<endl;
  }
  else {
    cout<<"win"<<endl;
  }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
int main(){
  ll n;
  cin>>n;
  vector<string> s(n);
  for (ll i=0;i<n;i++) {
    cin>>s[i];
  }
  ll ans=0;
  for (ll i=0;i<n;i++) {
    for (ll j=0;j<s[i].size()-1;j++) {
      if (s[i][j]=='A' && s[i][j+1]=='B') {
        ans++;
      }
    }
  }
  
  ll countA=0,countB=0,judgeA=0,judgeB=0;
  for (ll i=0;i<n;i++) {
    if (s[i][0]=='B') {
      countB++;
    }
    if (s[i][s[i].size()-1]=='A') {
      countA++;
    }
    if (s[i][0]!='B' && s[i][s[i].size()-1]=='A') {
      judgeA++;
    }
    if (s[i][0]=='B' && s[i][s[i].size()-1]!='A') {
      judgeB++;
    }
  }
  
  ll p=max(countA-1,(ll)0),q=max(countB-1,(ll)0);
  if (judgeA==0 && judgeB==0) {
    ans += min(p,q);
  }
  else if (judgeA==0 && judgeB>0) {
    ans += min(countA,q);
  }
  else if (judgeA>0 && judgeB==0) {
    ans += min(p,countB);
  }
  else {
    ans += min(countA,countB);
  }
  cout<<ans<<endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

#define INF 1e12

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vll x(n), l(n);
    rep(i,n) cin>>x[i]>>l[i];
    vector<pll> p(n);
    rep(i,n){
        p[i].fi = x[i]+l[i];
        p[i].se = x[i]-l[i];
    }
    sort(all(p));
    ll cur = -INF;
    int ans=0;
    rep(i,n){
        if (p[i].se>=cur){
            ans++;
            cur = p[i].fi;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int h, w, k;
  cin >> h >> w >> k;

  vector<vector<int>> vs(h);
  for (int i = 0; i < vs.size(); ++i) {
    for (int j = 0; j < w; ++j) {
      char c;
      cin >> c;
      if (c == '#') {
        vs[i].push_back(j);
      }
    }
  }

  vector<vector<int>> ans(h, vector<int>(w));
  vector<int> last_results, buf;
  int cur = 1;
  for (int i = 0; i < h; ++i) {
    if (vs[i].empty()) {
      if (!last_results.empty()) {
        ans[i] = last_results;
      } else {
        buf.push_back(i);
      }

      continue;
    }

    int cnt = vs[i].size();
    fill(ans[i].begin(), ans[i].end(), cur++);
    for (int j = 1; j < cnt; ++j) {
      fill(ans[i].begin() + vs[i][j], ans[i].end(), cur++);
    }

    for (int j = 0; j < buf.size(); ++j) {
      ans[buf[j]] = ans[i];
    }

    buf.clear();

    last_results = ans[i];
  }

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cout << ans[i][j] << (j == w - 1 ? '\n' : ' ');
    }
  }

  return 0;
}

Measured memory_bytes: 4560
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    string s;
    cin>>s;
    map<char,int>mp;
    for (int i = 0; i < s.size(); i++)
    {
        mp[s[i]]++;
    }
    int n=(int)s.size();
    int cnt=n*(n-1)/2;
    for(char mozi='a' ; mozi<='z';mozi++){
        cnt-=mp[mozi]*(mp[mozi]-1)/2;
    }
    cout<<cnt+1<<endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb push_back
#define emp emplace_back
#define ppb pop_back
#define len(v) int(v.size())
#define all(v) (v).begin(),(v).end()
#define ri(x) scanf("%d",&(x))
#define rii(x,y) scanf("%d %d",&(x),&(y))
#define riii(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rl(x) scanf("%lld",&(x))
#define rll(x,y) scanf("%lld %lld",&(x),&(y))
#define rlll(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
void fastio(){ios_base::sync_with_stdio(false); cin.tie(0);}

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;
const int maxn = 15;
int n, a, x, y, mat[maxn][maxn];


int main() {
	memset(mat, -1, sizeof(mat));
	ri(n);
	forn(i, n){
		ri(a);
		forn(j, a){
			rii(x, y);
			--x;
			mat[i][x] = y;
		}
	}
	int ans = 0;
	for(int mask = 0; mask<(1<<n); mask++){
		bool ok = true;
		int honest = 0;
		for(int i = 0; i<n; i++){
			if (not((mask>>i)&1)) continue;
			forn(j, n){
				if (i == j or mat[i][j] == -1) continue;
				if (mat[i][j] != ((mask>>j)&1)) {
					ok = false; 
					j = n+1;
				}
			}
		}
		if (ok) ans = max(ans, __builtin_popcount(mask));
	}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int		main(void)
{
	int h,w;
	scanf("%d%d", &h, &w);
	char str[h + 1][w + 1];
	int i = 0;
	int j;
	while (i < h)
		scanf("%s", str[i++]);
	int k,l,count;
	i = 0;
	while (i < h)
	{
		j = 0;
		while (j < w)
		{
			if (str[i][j] == '.')
			{
				count = 0;
				k = i - 1;
				while (k <= i + 1)
				{
					l = j - 1;
					while (l <= j + 1)
					{
						if (str[k][l] == '#')
							count++;
						l++;
					}
					k++;
				}
				str[i][j] = '0' + count;
			}
			j++;
		}
		i++;
	}
	i = 0;
	while (i < h)
		printf("%s\n", str[i++]);
	return (0);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
int a[5];
void solve(){
    cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
    for(int i = 0; i < 5; i++){
        if(!a[i]){
            cout<<i+1;
            return;
        }
    }
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 3596
#include<stdio.h>
  
int main()
{
  int t[4][14];
  int n, i,j,c;
  char m, d;
  for(i=0; i < 4; i++){
    for(j=0; j < 14; j++){
      t[i][j]=0;
    }
  }
 scanf("%d", &c);
  for(i = 0; i < c; i++){
    scanf("%c", &d);
    scanf("%c %d", &m, &n);
    if(m == 'S'){
      t[0][n] = 1;
    }
    else if(m == 'H'){
      t[1][n] = 1;
    }
    else if(m == 'C'){
      t[2][n] = 1;
    }
    else if(m == 'D'){
      t[3][n] = 1;
    }
  }
  for(j=1; j < 14; j++){
    if(t[0][j] != 1){
      printf("S %d\n", j);
    }
  }
  
 for(j=1; j < 14; j++){
    if(t[1][j] != 1){
      printf("H %d\n", j);
    }
  }
  
 for(j=1; j < 14; j++){
    if(t[2][j] != 1){
      printf("C %d\n", j);
    }
  }
  
 for(j=1; j < 14; j++){
    if(t[3][j] != 1){
      printf("D %d\n", j);
    }
  }
 return 0;
}


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

int main() {
  int n;
  cin >> n;
  if (((n%10==((n-n%10)%100/10))&&(n%10==((n-n%100)%1000/100)))||((n/1000==((n-n%10)%100/10))&&(n/1000==((n-n%100)%1000/100)))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
 
int main(){
    ll N, T, A;
    cin >> N >> T >> A;
    vector<ll> H(N);
    REP(i, N) cin >> H[i];

    ll res = 0;
    double min = 1e18;
    REP(i, N) {
        double temp = T - H[i]*0.006;
        if (min > abs(A-temp)) {
            min = abs(A-temp);
            res = i+1;
        }
    }
    cout << res << "\n";
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		int i1, i2, counter1, counter2;
		Scanner sc = new Scanner(System.in);
		while (true) {
			i1 = sc.nextInt();
			i2 = sc.nextInt();
			counter1 = 0;
			counter2 = 0;
			if (i1 == 0 && i2 == 0)
				break;
			for (int i = 0; i < i1; i++) {
				for (int j = 0; j < i2; j++){
					counter1++;
					if(counter2 % 2 == 1){
						if(counter1 % 2 == 1)
							System.out.print(".");
						else
							System.out.print("#");
					}
					else{
						if(counter1 % 2 == 1)
							System.out.print("#");
						else
							System.out.print(".");
					}
				}
				System.out.println("");
				counter2++;
				counter1 = 0;
			}
			System.out.println("");
		}
	}
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    deque<char> dq;
    for (char c : s) {
        dq.push_back(c);
    }

    int q;
    cin >> q;
    bool rev = false;
    for (int i = 0; i < q; ++i) {
        int t;
        cin >> t;
        if (t == 1) {
            rev = !rev;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if (rev) f = 3 - f;
            if (f == 1) {
                dq.push_front(c);
            } else {
                dq.push_back(c);
            }
        }
    }

    if (rev) reverse(dq.begin(), dq.end());
    for (char c : dq) {
        cout << c;
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 976
import java.util.*;

class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = 0;
    if (a==1) {
      if (b==2) {
        c = 3;
      }
      else {
        c = 2; 
      }
    }
    else if (a == 2) {
      if (b==1) {
        c = 3;
      }
      else {
        c = 1; 
      }
    }
    else {
      if (b==2) {
        c = 1;
      }
      else {
        c = 2; 
      }
    }
    System.out.println(c);
  }
}


Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<list>
#include<math.h>
using namespace std;

#define ll long long
#define vecint vector<int>
#define listint list<int>

#define REP(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define print(a) cout << a << endl

#define INF 1000000007;

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

  rep(i,S.size()){
    if(S[i]==',') S[i]=' ';
  }
  print(S);
  return 0;
}


Measured memory_bytes: 256
H, W = gets.split.map &:to_i

masu = []

H.times{
	masu << gets.split.map(&:to_i)
}

#w , h
road = [[1,1]]

h = 1
w = 1

is_reverse = false

(1...H*W).each{ |i|
	if ! is_reverse then
		if w < W then
			w += 1
		elsif w == W then
			is_reverse = true
			h += 1
		end
	else
		if w > 1 then
			w -= 1
		elsif w == 1 then
			is_reverse = false
			h += 1
		end
	end
	road << [w,h]
}

is_move = false

moves = []
moves_temp = []

(0...road.size).each{ |i|
	current = road[i]
	before = road[i-1]

	if is_move then
		moves_temp << sprintf("%d %d %d %d", before[1], before[0], current[1], current[0])
	end

	if masu[current[1] - 1][current[0] - 1] % 2 == 1 then
		if ! is_move then
			is_move = true
		else
			is_move = false
			moves.concat(moves_temp)
			moves_temp = []
		end
	end
}

puts moves.size
moves.each{ |m|
	puts m
}


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

N,K = map(int, input().split())
A = [0]+list(map(int, input().split()))

town_list = [-1,0]+[-1 for i in range(N-1)]
town_now = 1
n_teleport = 0

while n_teleport<K:
  n_teleport += 1
  town_now = A[town_now]
  if town_list[town_now]==-1:
    town_list[town_now] = n_teleport
  else:
    break

if n_teleport==K:
  print(town_now)
else:
  loop_start_town = town_now
  loop_start_time = town_list[town_now]
  loop_len = n_teleport-town_list[town_now]
  M = (K-loop_start_time)%loop_len
  for _ in range(M):
    town_now = A[town_now]
  print(town_now)

Measured memory_bytes: 32244
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e5 + 77;

#define gc getchar
#define inc(i, x, y) for (int i = x; i <= y; ++i)
#define dec(i, x, y) for (int i = x; i >= y; --i)

bool chkmin(int &x, int y) { return (x > y) ? x = y, 1 : 0; }
bool chkmax(int &x, int y) { return (x < y) ? x = y, 1 : 0; }

int rd() {
	int ret = 0; bool fl = 0; char ch = 0;
	while (!isdigit(ch)) fl |= (ch == '-'), ch = gc();
	while (isdigit(ch)) ret = (ret << 1) + (ret << 3) +(ch ^ 48), ch = gc();
	return fl ? -ret : ret;
}

struct Edge {
    int nxt, to;
}e[N << 1];

int tot, head[N];

void add(int u, int v) { e[++tot] = (Edge){head[u], v}, head[u] = tot++; }

int n, m, c[N];

void dfs(int u, int col) {
    c[u] = col;
    for (int i = head[u]; i; i = e[i].nxt) {
        int v = e[i].to;
        if (c[v] == -1) dfs(v, !col);
        if (c[v] != !col) { printf("%lld\n", 1LL*n*(n-1)/2-m); exit(0); }
    }
}

int main() {
    n = rd(), m = rd(); 
    memset(c, -1, sizeof(c));
    for (int i = 0; i < m; ++i) {
        int u = rd(), v = rd();
        add(u, v);
        add(v, u);
    }
    dfs(1, 0);
    int b=0, w=0;
    for (int i = 1; i <= n; ++i) if (c[i]) ++b; else ++w;
    printf("%lld\n", 1LL*b*w-m);
    return 0;
}

Measured memory_bytes: 6272
# https://atcoder.jp/contests/abc159/tasks/abc159_d

N = int(input())
A = list(map(int, input().split()))

m = {}
for a in A:
    m[a] = m.get(a, 0) + 1

max_value = 0
for value in m.values():
    # nC2
    max_value += (value * (value - 1)) // 2

for a in A:
    value = m[a]
    old_value = (value * (value - 1)) // 2
    new_value = ((value - 1) * (value - 2)) // 2
    print(max_value + new_value - old_value)


Measured memory_bytes: 26140
from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    memo={}
    def f(lv,x):
        if lv==0:return 1
        if x==1:return 0
        if x==ss[lv]:return pp[lv]
        if (lv,x) in memo:return memo[lv,x]
        if x<=ss[lv-1]+1:res=f(lv-1,x-1)
        elif x==ss[lv-1]+2:res=pp[lv-1]+1
        else:res=pp[lv-1]+f(lv-1,x-ss[lv-1]-2)+1
        memo[lv,x]=res
        return res

    ss=[1]
    pp=[1]
    for i in range(50):
        ss.append(ss[-1]*2+3)
        pp.append(pp[-1]*2+1)
    #print(ss)
    #print(pp)
    n,x=MI()
    print(f(n,x))



main()


Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI acos(-1) 
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define eb(a) emplace_back(a)
#define print(x) for(auto it:x) cout<<it<<' '; cout<<"\n";

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

int main()
{
	FAST_IO ;
	ll i,j,k,n;
	cin >> n;
	vector <int> arr(n) ;
	for(i=0;i<n;++i)
		cin >> arr[i] ;
	int ans = 0;
	for(i=0;i<n;++i)
	{
		for(j=i+1;j<n;++j)
		{
			for(k=j+1;k<n;++k)
			{
				if(i==j || i==k || j==k)
					continue ;
				vector <int> temp ;
				temp = {arr[i],arr[j],arr[k]} ;
				sort(temp.begin(),temp.end()) ;
				if(temp[0]==temp[1] || temp[0]==temp[2] || temp[1]==temp[2])
					continue ;
				if(temp[0] + temp[1] > temp[2])
					ans++ ;
			}
		}
	}
	cout << ans endl ;
	return 0;
}

/*
If u haven't come up with an approach yet ,skip this one
  Try this when feeling stuck -
  1. Int overflow, array bounds
  2. Special cases (n=1?)
  3. Prove your approach to yourself(mathematical induction,counter-intuitive or stronger test cases)
  4. Calm down and don't look at standings and stop thinking about rating and think about the question
  5. Just do it! 
*/ 

//Benq's advice - 
/* 
	And following advices are must for me -
	* do something instead of nothing and stay organized
	* WRITE STUFF DOWN 
*/

//#define _GLIBCXX_DEBUG 
// It will convert WA verdict to runtime error if that error is caused due to out of bound excess , declare it at the top
//#pragma GCC optimize "trapv" 
// It will convert WA to runtime error if WA was caused due to int overflow error,declare it anywhere

Measured memory_bytes: 3648
object Main extends App {
     
    val Array(ttlRow, ttlCol) =  io.StdIn.readLine.split(" ").map(_.toInt)
    val Array(row, col) =  io.StdIn.readLine.split(" ").map(_.toInt)
    println(balanceCell(ttlRow, ttlCol, row, col))
    def balanceCell(ttlRow:Int, ttlCol:Int, row:Int, col:Int):Int = {
        val rowBal = ttlRow - row 
        val colBal = ttlCol - col 
        rowBal * colBal 
    }
}

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

ll solve() {
    ll N, M, R, a, b, c;
    cin >> N >> M >> R;
    vector<ll> r(R);
    for ( int i = 0; i < R; i++ ) {
        cin >> r[i];
        r[i]--;
    }
    const ll INF = 1LL<<60;
    vector<vector<ll>> d(N, vector<ll>(N, INF));
    for ( int i = 0; i < M; i++ ) {
        cin >> a >> b >> c;
        a--, b--;
        d[a][b] = c;
        d[b][a] = c;
    }
    for ( int k = 0; k < N; k++ ) {
        for ( int i = 0; i < N; i++ ) {
            for ( int j = 0; j < N; j++ ) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    vector<int> ix(R);
    for ( int i = 0; i < R; i++ ) {
        ix[i] = i;
    }
    ll ans = INF;
    do {
        ll dc = 0;
        for ( int j = 1; j < R; j++ ) {
            int r1 = r[ix[j-1]], r2 = r[ix[j]];
            dc += d[r1][r2];
            if ( dc >= INF ) break;
        }
        ans = min(ans, dc);
    } while ( next_permutation(ix.begin(), ix.end()) );
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  int ans1 = n - k + 1;
  int ans2 = n/k;
  cout << ans1 - ans2 << endl;
  return 0;
}

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

int poles[101][4];

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

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

int dfs(int n)
{
  int a = 1, b = 1;
  if(poles[n][2])
    a = dfs(poles[n][2]);
  if(poles[n][3])
    b = dfs(poles[n][3]);
  int l = lcm(poles[n][0] * a, poles[n][1] * b);
  return l / poles[n][0] + l / poles[n][1];
}


bool notRoot[101];
int main()
{
loop:
  fill(notRoot, notRoot + 101, false);
  int n;
  cin >> n;
  if(!n)
    return 0;

  for(int i = 1; i <= n; i++)
  {
    cin >> poles[i][0] >> poles[i][1] >> poles[i][2] >> poles[i][3];
    notRoot[poles[i][2]] = notRoot[poles[i][3]] = true;
  }
  for(int i = 1; i <= n; i++)
  {
    if(!notRoot[i])
    {
      cout << dfs(i) << endl;
      goto loop;
    }
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int n, m;
  cin >> n >> m;
  vector<int> c(m);
  for (int i = 0; i < m; i++) {
    cin >> c[i];
  }

  int dp[60000] = {};
  for (int i = 0; i < 60000; i++) {
    dp[i] = INF;
  }

  dp[0] = 0;

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      int yen = c[j] + i;

      dp[yen] = min(dp[yen], dp[i] + 1);
    }
  }

  cout << dp[n] << ln;

  return 0;
}


Measured memory_bytes: 3460
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    if (s[s.size()-1]=='s'){
        cout<<s+"es"<<endl;
    }else{
        cout<<s+"s"<<endl;
    }
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld DINF = 1e12;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

ll n;
ll w[310];
ll dp[310][310]; //[l,r)で取り除けるブロック

ll calc(int l, int r)
{
  if (dp[l][r] != -1)
    return dp[l][r];
  if (r - l <= 1)
    return 0;

  if (abs(w[l] - w[r - 1]) <= 1 && calc(l + 1, r - 1) == r - l - 2)
  {
    return dp[l][r] = r - l;
  }

  ll Max = 0;
  for (int i = l + 1; i <= r - 1; ++i)
  {
    Max = max(Max, calc(l, i) + calc(i, r));
  }
  return dp[l][r] = Max;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
  while (1)
  {
    cin >> n;
    if (n == 0)
      return 0;
    rep(i, n) cin >> w[i];
    rep(i, n + 1) rep(j, n + 1) dp[i][j] = -1;
    cout << calc(0, n) << "\n";
  }
  return 0;
}


Measured memory_bytes: 3896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int n;
    string s;
    cin >> n >> s;
    
    vector<int> a(n);
    auto construct = [&](){
        for(int i = 1; i + 1 < n; ++i){
            int val = a[i];
            if(s[i] == 'x') val ^= 1;
            a[i + 1] = a[i - 1] ^ val;
        }
        return;
    };
    auto judge = [&](){
        bool ok;
        if(s[n - 1] == 'o'){
            bool b1 = (a[n - 1] == 0) ? (a[n - 2] == a[0]) : (a[n - 2] != a[0]);
            if(s[0] == 'o'){
                bool b2 = (a[0] == 0) ? (a[1] == a[n - 1]) : (a[1] != a[n - 1]);
                ok = b1 & b2;
            }
            else{
                bool b2 = (a[0] == 0) ? (a[1] != a[n - 1]) : (a[1] == a[n - 1]);
                ok = b1 & b2;
            }
        }
        else{
            bool b1 = (a[n - 1] == 0) ? (a[n - 2] != a[0]) : (a[n - 2] == a[0]);
            if(s[0] == 'o'){
                bool b2 = (a[0] == 0) ? (a[1] == a[n - 1]) : (a[1] != a[n - 1]);
                ok = b1 & b2;
            }
            else{
                bool b2 = (a[0] == 0) ? (a[1] != a[n - 1]) : (a[1] == a[n - 1]);
                ok = b1 & b2;
            }
        }
        return ok;
    };
    auto output = [&](){
        for(int i = 0; i < n; ++i){
            if(a[i])    cout << 'W';
            else    cout << 'S';
        }
        cout << endl;
        return;
    };

    for(int i = 0; i <= 1; ++i){
        a[0] = i;
        for(int j = 0; j <= 1; ++j){
            a[1] = j;
            construct();
            if(judge()){
                output();
                return 0;
            }
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3844
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
h = LI()
ans = 0
while sum(h) > 0:
    flg = False
    for j in range(n):
        if h[j] > 0:
            if not flg:
                flg = True
                ans += 1
            h[j] -= 1
        else:
            flg = False
print(ans)

Measured memory_bytes: 39152
#include<iostream>
using namespace std;
double l[11], a, b, sum, dis; char d;
int main() {
	while (cin >> l[1] >> d >> l[2] >> d >> l[3] >> d >> l[4] >> d >> l[5] >> d >> l[6] >> d >> l[7] >> d >> l[8] >> d >> l[9] >> d >> l[10] >> d >> a >> d >> b) {
		sum = 0;
		for (int i = 1; i <= 10; i++) {
			sum += l[i];
		}
		dis = 1.0*sum*(a / (a + b));
		sum = 0;
		for (int i = 1; i <= 10; i++) {
			sum += l[i];
			if (sum >= dis) { cout << i << endl; break; }
		}
	}
}

Measured memory_bytes: 1224
n=int(input())
AC=0
WA=0
TLE=0
RE=0
for i in range(n):
    a=input()
    if a=="AC":
        AC+=1
    elif a=="TLE":
        TLE+=1
    elif a=="WA":
        WA+=1
    else:
        RE+=1

print("AC x "+str(AC))
print("WA x "+str(WA))
print("TLE x "+str(TLE))
print("RE x "+str(RE))

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

using namespace std;
#define pb push_back
#define pii pair<int, int>
#define x first
#define y second
const int Nmax = 100000 + 5;
int n, m, root, d[Nmax];
vector<pii>v[Nmax];
vector<int>nds;
bool in[Nmax], ok;
void dfs(int nod)
{
    for(auto i : v[nod])
    {
        if(d[i.x] == -1)d[i.x] = d[nod] + i.y, dfs(i.x);
        else if(d[i.x] != d[nod] + i.y)
        {
            cout << "No";
            exit(0);
        }
    }

}
int main()
{
    cin >> n >> m;
    if(m == 0)
    {
        cout << "Yes";
        return 0;
    }
    for(int i = 1,a , b, c; i <= m; ++i)
    {
        cin >> a >> b >> c;
        if(c == 0)m--, i--;
        d[a] = -1; d[b] = -1;
        v[a].pb({b, c});
        nds.pb(a);
        if(c)in[b]++;
    }
    if(m == 0)
    {
        cout << "Yes";
        return 0;
    }
    for(auto i : nds)
        if(!in[i])
        {
            ok = 1;
            if(d[i] == -1)
            {
                d[i] = 0;
                dfs(i);
            }
        }
    if(!ok)
    {
        cout <<"No";
        return 0;
    }
    cout << "Yes";
    return 0;
}


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

int main(){
    int n, k;
    cin>>n>>k;
    int a[n] = {0};
    while(k--){
        int x;
        cin>>x;
        while(x--){
            int id;
            cin>>id;
            a[id-1]++;
        }
    }
    int res = 0;
    for(int i=0;i<n;i++){
        if(a[i]==0)res++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3592