akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cstring>
using namespace std;
#define MOD 1000000007 
#define ADD(a,b) a=(a+b)%MOD 

class PMA{//Aho-Corasick
	int id;
	int match;
	PMA *failure;
	PMA *next[256];
public:
	PMA(int id=0):id(id),match(0),failure(0){
		memset(next,0,sizeof(next));
	}
	~PMA(){
		for(int i=0;i<256;i++){
			if(next[i]&&next[i]!=this)delete next[i];
		}
	}
	int getID()const{return id;}
	int matched()const{return match;}
	void build(const vector<string> &p){
		int num=0;
		for(int i=0;i<(int)p.size();i++){
			const string &s=p[i];
			PMA *t=this;
			for(int j=0;j<(int)s.size();j++){
				if(!t->next[s[j]])t->next[s[j]]=new PMA(++num);
				t=t->next[s[j]];
			}
			t->match++;
		}
		queue<PMA*> q;
		for(int i=0;i<256;i++){
			if(next[i]){
				q.push(next[i]);
				next[i]->failure=this;
			}else next[i]=this;
		}
		while(!q.empty()){
			PMA *t=q.front();q.pop();
			for(int i=0;i<256;i++){
				if(t->next[i]){
					q.push(t->next[i]);
					PMA *r=t->failure->step(i);
					t->next[i]->failure=r;
					t->next[i]->match += r->match;
				}
			}
		}
	}
	PMA *step(char c)const{
		const PMA *t=this;
		while(!t->next[c])t=t->failure;
		return t->next[c];
	}
	PMA *step(string s,int *n){
		*n=0;
		PMA *pma=this;
		for(int i=0;i<s.size();i++){
			pma=pma->step(s[i]);
			*n += pma->matched();
		}
		return pma;
	}
};


struct S{
	int pre,hit;
	PMA *pma;
	S(){}
	S(int a,int b,PMA *c):pre(a),hit(b),pma(c){}
	bool operator<(S s)const{
		if(pre!=s.pre)return pre<s.pre;
		if(hit!=s.hit)return hit<s.hit;
		return pma<s.pma;
	}
};

map<S,int> dp[621];
vector<int> to[500];
string str[500];

int main(){
	int n,m,k;
	while(cin>>n>>m>>k,n|m|k){
		map<string,int> id;	
		for(int i=0;i<621;i++)dp[i].clear();
		for(int i=0;i<500;i++)to[i].clear(),str[i].clear();

		for(int i=0;i<n;i++){
			string a,b;
			int x,y;
			cin>>a>>b;
			if(id.find(a)==id.end()){
				id.insert(make_pair(a,x=id.size()));
				str[x]=a;
			}else x=id.find(a)->second;
			if(id.find(b)==id.end()){
				id.insert(make_pair(b,y=id.size()));
				str[y]=b;
			}else y=id.find(b)->second;
			to[x].push_back(y);
		}
		vector<string> seasonword(k);
		for(int i=0;i<k;i++){
			cin>>seasonword[i];
		}
		PMA pma;
		pma.build(seasonword);
		for(int i=0;i<id.size();i++){
			int n;
			PMA *p=pma.step(str[i],&n);
			if(n<=1)dp[str[i].size()].insert(make_pair(S(i,n,p),1));
		}
		for(int i=1;i<m;i++){
			for(map<S,int>::iterator it=dp[i].begin();it!=dp[i].end();++it){
				const S &s=it->first;
				for(int j=0;j<to[s.pre].size();j++){
					int dest=to[s.pre][j];
					int n;
					PMA *p=s.pma->step(str[dest],&n);
					if(s.hit+n<=1){
						S t(dest,s.hit+n,p);
						int len=i+str[dest].size();
						map<S,int>::iterator it2=dp[len].find(t);
						if(it2==dp[len].end())it2=dp[len].insert(make_pair(t,0)).first;
						ADD(it2->second,it->second);
					}
				}
			}
			dp[i].clear();
		}
		int ans=0;
		for(map<S,int>::iterator it=dp[m].begin();it!=dp[m].end();++it){
			if(it->first.hit==1)ADD(ans,it->second);
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 5248
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var n = IO.RSInt;
            var a = new int[] { 1, 4, 7, 9 };
            Array.Sort(n);
            bool f = true;
            for (int i = 0; i < n.Length; i++)
            {
                if (n[i] != a[i]) f = false;
            }
            IO.WriteLineYES_or_NO(f);
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 19144
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

	int h, m, s, t;

	while(cin >> h >> m >> s)  {
		if(h==-1&&m==-1&&s==-1)
			break;
		t=h*3600+m*60+s;
		t=7200-t;
		printf("%02d:%02d:%02d\n", t/3600, t/60%60, t%60);
		t*=3;
		printf("%02d:%02d:%02d\n", t/3600, t/60%60, t%60);
	}

	return 0;

}

Measured memory_bytes: 0
#include <cstdio>

int main(void)
{

	const int MAX_N=122;
	bool tollGate[MAX_N];
	int N,M,X,i,index;
	int toleft,toright;
	for(i=0;i<MAX_N;i++)
		tollGate[i]=false;

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

	for(i=0;i<M;i++)
	{
		scanf("%d",&index);
		tollGate[index]=true;
	}

	toleft=0;
	for(i=X;i>0;i--)
	{
		if(tollGate[i])
			toleft++;
	}

	toright=0;
	for(i=X;i<N;i++)
	{
		if(tollGate[i])
			toright++;
	}

	printf("%d\n",toleft<toright?toleft:toright);
	return 0;


}

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

using namespace std;

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b>c+d)
	cout<<"Left";
	else if(a+b<c+d)
	cout<<"Right";
	else cout<<"Balanced";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<complex>
#include<time.h>
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-7
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a,b;
	cin>>a>>b;
	if(a<=8&&b<=8) cout<<"Yay!"<<endl;
	else cout<<":("<<endl;
}


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

int main() {
    int N; cin >> N;
    vector<int> P(N), Q(N);
    for (int i = 0; i < N; i++) {
        cin >> P.at(i);
    }
    for (int i = 0; i < N; i++) {
        cin >> Q.at(i);
    }
    int pcount = 0, qcount = 0;
    while (next_permutation(P.begin(), P.end())) {
        pcount++;
    }
    while (next_permutation(Q.begin(), Q.end())) {
        qcount++;
    }
    cout << abs(pcount - qcount) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    cout << (n + k - 3) / (k - 1) << endl;
    return 0;
}

Measured memory_bytes: 640
N = int(input())
S = input()

ans = 0

for i in range(1,N):
    left = S[:i]
    right = S[i:]
    tmp = 0
    for alpha in 'qwertyuiopasdfghjklzxcvbnm':
        if alpha in left and alpha in right:
            tmp += 1
    ans = max(ans,tmp)
    
print(ans)

Measured memory_bytes: 3060
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
AT = [(-1)*a for a in A]
heapq.heapify(AT)
s = 0
while M > 0:
    m = heapq.heappop(AT)
    heapq.heappush(AT, -(-m//2))
    M -= 1
print(sum(AT)*(-1))


Measured memory_bytes: 14180
def main():
    n = int(input())
    A = []
    for _ in range(n):
        a,b,c,d,e = input().split()
        A.append([int(a),int(b),c,int(d),e])
    A.sort()
    for a,b,c,d,e in A:print(a,b,c,d,e)


if __name__ == '__main__':
    main()




Measured memory_bytes: 32920
def main():
    a, b = map(int, input().split())

    if a <= 0 <= b:
        ans = "Zero"
    elif a > 0:
        ans = "Positive"
    elif b < 0:
        ans = "Negative"
        c = b - a
        # a == bのとき負が2個
        if c == 0 or c % 2 == 1:
            ans = "Positive"

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main(){
    string s;
    int k;
    cin>>s>>k;
    for(int i=0;i<s.length()-1;i++){
        int value='z'+1-s[i];
        if(s[i]=='a') continue;
        if(value>k){
            continue;
        }
        else{
            s[i]='a';
            k-=value;
        }
    
    }
    s.back()=(s.back()-'a'+k)%26+'a';
  cout<<s<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
// typedef vector<int,vector<int>> vvec;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
inline ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }

//----***定数***----
const int MOD=1e9+7;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
#define here  cout<<"Here"<<endl;


//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

signed main(){
  int H,W;cin>>H>>W;
  vector<string> graph(H);
  REP(i,0,H){
    cin>>graph[i];
  }
  vector<vector<int> > L(H,vector<int>(W,0)),R(H,vector<int>(W)),U(H,vector<int>(W)),D(H,vector<int>(W));
  REP(i,0,H)REP(j,0,W){
    if(graph[i][j]=='#'){L[i][j]=0;}
    else if(j==0){L[i][j]=1;}
    else {L[i][j]=L[i][j-1]+1;}
  }
  REP(i,0,H)RREP(j,W-1,-1){
    if (graph[i][j]=='#') {R[i][j]=0;}
    else if (j==W-1) {R[i][j]=1;}
    else {R[i][j]=R[i][j+1]+1;}
  }
  REP(i,0,H)REP(j,0,W){
    if(graph[i][j]=='#'){U[i][j]=0;}
    else if(i==0){U[i][j]=1;}
    else {U[i][j]=U[i-1][j]+1;}
  }
  RREP(i,H-1,-1)REP(j,0,W){
    if(graph[i][j]=='#'){D[i][j]=0;}
    else if(i==H-1){D[i][j]=1;}
    else {D[i][j]=D[i+1][j]+1;}
  }
  int ans=0;
  REP(i,0,H)REP(j,0,W){
    ans=max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3);
  }
  print(ans)


}


Measured memory_bytes: 131456
#include<bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define inlld(x) scanf("%lld", &x)
#define ind(x) scanf("%d", &x)
#define inlld2(x, y) scanf("%lld%lld", &x, &y)
#define inlld3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define ind2(x, y) scanf("%d%d", &x, &y)
#define ind3(x, y, z) scanf("%d%d%d", &x, &y, &z)

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

typedef long long ll;
typedef long double ld;

using namespace std;

ll n, m, k, arr1[N], arr2[N];

int main()
{
    inlld3(n, m, k);
    for (ll a = 1; a <= n; a++)
    {
        inlld(arr1[a]);
        arr1[a] += arr1[a- 1];
    }
    for (ll a = 1; a <= m; a++)
    {
        inlld(arr2[a]);
        arr2[a] += arr2[a - 1];
    }
    ll ptr2 = m;
    ll ans = 0;
    while(arr2[ptr2] > k) {
        ptr2--;
    }
    ans = ptr2;
    for(ll ptr1 = 1; ptr1 <= n; ptr1++) {
        if(arr1[ptr1] > k) 
            break;
        while(ptr2 > 0 && arr1[ptr1] + arr2[ptr2] > k) {
            ptr2--;
        }
        ans = max(ans, ptr1 + ptr2);
    }
    printf("%lld\n", ans);
    return 0;
}


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

int main( ) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,i,a;
    string s,u;
    t = 1;
    while(t--) {
     a = 0;
	 cin >> s >> u;
	 for(i = 0; i < 3; i++) {
	  if(s[i] == u[i])
	   a++;
	 }
	 cout << a << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
w = [input() for i in range(n)]
ans = 'Yes'
if len(w) != len(set(w)):
    ans = 'No'
for i in range(n - 1):
    if w[i][-1] != w[i + 1][0]:
        ans = 'No'
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
int main(){
  long long a,b,q; cin>>a>>b>>q;
  long long s[a]={};
  long long t[b]={};
  long long x[q]={};
  rep(i,a) cin>>s[i];
  rep(i,b) cin>>t[i];
  rep(i,q) cin>>x[i];
  rep(i,q){
    ll xa,xb,ta,tb;
    xa = *(lower_bound(s,s+a,x[i])-1);
    ta = *(lower_bound(t,t+b,x[i])-1);
    xb = *upper_bound(s,s+a,x[i]);
    tb = *upper_bound(t,t+b,x[i]);
    auto itr1 = lower_bound(s,s+a,x[i]);
    if(itr1 == s){
      xa = INF/10;}
    if(itr1 == s+a){
      xb = INF/10;}
    auto itr2 = lower_bound(t,t+b,x[i]);
    if(itr2 == t){
      ta = INF/10;}
    if(itr2 == t+b){
      tb = INF/10;}
    //cout << xa << " " << ta << " " << xb << " " << tb << endl;
    ll ca = max(abs(xa-x[i]),abs(ta-x[i]));
    ll cb = max(abs(xb-x[i]),abs(tb-x[i]));
    ca = min(ca,cb);
    cb = 0;
    cb = min(abs(xa-x[i])+abs(x[i]-tb)+min(abs(xa-x[i]),abs(x[i]-tb)),abs(x[i]-ta)+abs(xb-x[i])+min(abs(ta-x[i]),abs(x[i]-xb)));
    ca = min(ca,cb);
    cout << ca << endl;}
  }


Measured memory_bytes: 5920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, w, a, b, c;
  in2(n, w);
  vector<ll> p, q, r, s, pp, qq, rr, ss;
  in2(a, b);
  p.pb(b);
  c = a;
  rep(i, n - 1){
    in2(a, b);
    if(a == c)
      p.pb(b);
    if(a - 1 == c)
      q.pb(b);
    if(a - 2 == c)
      r.pb(b);
    if(a - 3 == c)
      s.pb(b);
  }
  sort(all(p));
  sort(all(q));
  sort(all(r));
  sort(all(s));
  reverse(all(p));
  reverse(all(q));
  reverse(all(r));
  reverse(all(s));
  pp.pb(0);
  qq.pb(0);
  rr.pb(0);
  ss.pb(0);
  rep(i, p.size())
    pp.pb(p[i] + pp[i]);
  rep(i, q.size())
    qq.pb(q[i] + qq[i]);
  rep(i, r.size())
    rr.pb(r[i] + rr[i]);
  rep(i, s.size())
    ss.pb(s[i] + ss[i]);
  a = 0;
  rep(i, pp.size()){
    rep(j, qq.size()){
      rep(k, rr.size()){
        rep(l, ss.size()){
          b = c * i + (c + 1) * j + (c + 2) * k + (c + 3) * l;
          if(b <= w)
            a = max(a, pp[i] + qq[j] + rr[k] + ss[l]);
        }
      }
    }
  }
  out(a);
  memi;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll n,a,b;
  cin>>n>>a>>b;
  cout << min(n*a,b) << endl;
  return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int n, y;
    std::cin >> n >> y;

    std::string ans = "-1 -1 -1";
    for(int a = n; a >= 0; a--){
        for(int b = n - a; b >= 0; b--){
            int c = n - a - b;
            if(10000 * a + 5000 * b + 1000 * c == y){
                ans = std::to_string(a) + ' ' + std::to_string(b) + ' ' + std::to_string(c);
            }
        }
    }
    std::cout << ans <<std::endl;
    return 0;
}


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

using namespace std;

void trace(int A[], int N){
  int i;
  for (i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

void insertionSort(int A[], int N){
  int j,i,v;
  for (i=1;i<N;i++){
    v = A[i];
    j = i - 1;
    while (j>=0&&A[j]>v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    trace(A, N);
  }
}

int main(){
  int N, i, j;
  int A[100];

  scanf("%d", &N);
  for(i=0;i<N;i++) scanf("%d", &A[i]);

  trace(A,N);
  insertionSort(A,N);

  return 0;
}



Measured memory_bytes: 3196
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n;
    cin>>n;
    vector<ll> v(n);
    rep(i, n) cin>>v[i];
    vector<ll> sum(n+1);
    rep(i, n){
        sum[i+1] = sum[i]+v[i]; 
    }
    map<ll, ll> mp;
    rep(i, n+1){
        mp[sum[i]]++;
    }
    //rep(i, n+1) cout<<sum[i]<<endl;
    ll ans = 0;
    for(auto p : mp){
        ans += p.second*(p.second-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 15872
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())
 
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const ll MOD = (ll)1000000007;//10^9+7
const ll INF2 = (ll)100000000000000000;//10^18

ll power(ll q, ll p){
    ll a = q;
    ll ans = 1;
    while(p)
	{
		if(p&1)
			ans = (ans*a);
		a = a*a;
		p=p>>1;
	}
    return ans;
}

int main() {
    int N,K;
    cin>>N>>K;
    
    ll q = K*power(K-1,N-1);
    cout<<q<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vi               vector<int>
#define pb(x)            push_back(x)
#define all(x)           x.begin(), x.end()
#define sortall(x)       sort(all(x))
#define sortrev(x)       sort(all(x), greater<int>())
#define debug(x)         cout << '>' << #x << ':' << x << endl;
#define int              long long
#define ld               long double
#define endl 			 "\n";
#define mp 				 make_pair
#define pii 			 <int, int>
#define lb 				 lower_bound
#define ub				 upper_bound
#define len(a)           int((a).size())
#define prec(n)          fixed<<setprecision(n)
#define cnt(n)           __builtin_popcountll(n)
#define pi               pair<int, int>
const int mod = 1000000007;
using namespace std;
const int N = 1e5 + 5; 
// int n;
int a[N];



int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
t = 1;
// cin >>t;
while(t--){
int n;cin >> n;
int zero =0;
for(int i = 0; i<n;i++){
	cin >> a[i];
	if(a[i] == 0){
		zero++;
	}
}
if(zero > 0){
	cout << 0 << endl;
	return 0;
}
int prod =1;
for(int i=0;i<n;i++){
if(a[i ] <=1000000000000000000/ prod ){  // This condition is equivalent to prod*a[i] <=10ˆ18
prod *=a[i];
}
else{
cout << -1 << endl;
return 0;
}
}
cout << prod <<endl;


}
return 0;
}

Measured memory_bytes: 4424
S = list(input())
a = "".join(map(str,S[0:2]))
b = "".join(map(str,S[1:3]))
ans = "No"
if a == "AB" or a == "BA":
    ans = "Yes"
if b == "AB" or b == "BA":
    ans = "Yes"
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,i,j=0,p=0;
cin>>n;
for(i=1;i<=n;i++){j=n/i;
p=p+(((j)*(j+1))/2)*i;

}cout<<p<<endl;
return 0;
}

Measured memory_bytes: 3520
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1000000007;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecb vector<bool>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, size_t second_itr) {
	std::string tmp;
	for (size_t i = first_itr; i < second_itr + 1; i++) {
		tmp.push_back(str.at(i));
	}
	return tmp;
}
ll max(ll a, ll b) {
	return a > b ? a : b;
}
ll min(ll a, ll b) {
	return a < b ? a : b;
}


int main() {
	
	ll x;
	ll now = 100;
	cin >> x;
	for (int i=1;;i++) {
		now = now + now / 100;
		if(now/100+now>=x){
			cout << i+1 << endl;
			return 0;
		}
	}


	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int,Int> P;

int main(){
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    while(B <= A){
        B *= 2;
        K--;
    }

    while(C <= B){
        C *= 2;
        K--;
    }

    if(K < 0){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;

  cout << h2*60+m2-h1*60-m1-k << endl;
}


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

const int N = 1e5 + 5;
const int INF = 1e9 + 5;
vector<int> adj[N];
int dp[N][2], vis[N][2];
int memo[N][2];
int n, ans, vis_id;
vector<int> _t, _d;

int solve(int idx, int flag) {
	if (idx == _t.size()) {
		if (_t.size() > 1 || !flag)
			return 0;
		return INF;
	}

	int &ret = dp[idx][flag];
	if (vis[idx][flag] == vis_id)
		return ret;
	vis[idx][flag] = vis_id;
	ret = INF;
	if (!flag) {
		ret = min(solve(idx + 1, 0) + _t[idx], solve(idx + 1, 1) + _d[idx]);
	} else {
		ret = solve(idx + 1, flag) + _t[idx];
	}
	return ret = min(ret, INF);
}

int dfs(int u, int par, int flag) {

	int &ret = memo[u][flag];
	if (~ret)
		return ret;

	vector<int> t, d;
	for (int nxt : adj[u]) {
		if (nxt == par)
			continue;
		t.push_back(dfs(nxt, u, 1));
		d.push_back(dfs(nxt, u, 0));
	}

	if (t.size() == 0)
		return ret = flag;

	if (!flag) {
		if (d.size() > 1)
			return ret = INF;
		return ret = d[0];
	}

	_t = t;
	_d = d;
	vis_id++;
	return ret = solve(0, 0);
}

int main() {

	memset(memo, -1, sizeof memo);
	int a, b;
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	int best = 0, mx = adj[0].size();

	for (int i = 0; i < n; i++) {
		if (adj[i].size() > mx) {
			best = i;
			mx = adj[i].size();

		}
	}

	printf("%d\n", max(1, dfs(best, -1, 1)));

	return 0;
}


Measured memory_bytes: 22272
#include <iostream>
#include <math.h>
using namespace std;
 
int main(void){
    long int A,B,V,W,T;
  	scanf("%ld%ld%ld%ld%ld",&A,&V,&B,&W,&T);
  if(B>A){
	if(B-A>T*(V-W)){
    	printf("NO");
    }else{
      	printf("YES");
    }}else{
  if(A-B>T*(V-W)){
    	printf("NO");
    }else{
      	printf("YES");
    }
  }
}

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll,ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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

queue<int> q;
void dfs(int n){
    int num = 1;
    while(n > num*(num+1)/2){
        num++;
    }
    q.push(num);
    if(n-num > 0) dfs(n-num);
    return;
}

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

    while(!q.empty()){
        int m = q.front(); q.pop();
        cout << m << "\n";
    }

    //std::cout << ans;
    //printf("%.8lf", ans);
    //std::cout << "\n";
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll x;cin>>x;
  rep(a, 500)for(int b=-500; b<=500; b++){
    ll a5 = pow(a, 5), b5 = pow(b, 5);
    if(a5-b5==x) { cout<<a<<' '<<b<<endl; return 0; }
  }
  return 0;
}

Measured memory_bytes: 4012
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;



public class Main {

	public static void main(String[] args) {
		IO io = new IO();
		int n = io.nextInt();
		int m = io.nextInt();
		int s = io.nextInt() - 1;
		int t = io.nextInt() - 1;
		int[] d = new int[n];
		for(int i=0;i<n;i++) {
			d[i] = io.nextInt();
		}
		Graph g = new Graph(n);
		for(int i=0;i<n-1;i++) {
			g.addEdge(i+1, i, 0);
		}
		for(int i=0;i<m;i++) {
			int a = io.nextInt() - 1;
			int b = io.nextInt() - 1;
			g.addEdge(a, b, d[b]);
		}
		System.out.println(g.minDistDijkstra(s)[t]);
	}

}
class Graph {
	public static final int INF = 1000000000;
	int n;
	ArrayList<Edge>[] graph;

	@SuppressWarnings("unchecked")
	public Graph(int n) {
		this.n = n;
		this.graph = new ArrayList[n];
		for(int i=0;i<n;i++) {
			graph[i] = new ArrayList<>();
		}
	}

	public void addBidirectionalEdge(int from, int to, int cost) {
		addEdge(from, to, cost);
		addEdge(to, from, cost);
	}
	public void addEdge(int from, int to, int cost) {
		graph[from].add(new Edge(to,cost));
	}

	public int[] minDistDijkstra(int s) {
		int[] dist = new int[n];
		Arrays.fill(dist, INF);
		dist[s] = 0;
		PriorityQueue<Node> q = new PriorityQueue<>();
		q.offer(new Node(0,s));
		while(!q.isEmpty()) {
			Node node = q.poll();
			int v = node.id;
			if (dist[v] < node.dist) {
				continue;
			}
			for(Edge e: graph[v]) {
				if (dist[e.to] > dist[v] + e.cost) {
					dist[e.to] = dist[v] + e.cost;
					q.add(new Node(dist[e.to], e.to));
				}
			}
		}
		return dist;
	}
	class Edge {
		int to,cost;
		public Edge(int to, int cost) {
			this.to = to;
			this.cost = cost;
		}
	}

	class Node implements Comparable<Node> {
		int dist,id;
		public Node(int dist, int i) {
			this.dist = dist;
			this.id = i;
		}
		public int compareTo(Node o) {
			return Integer.compare(dist, o.dist);
		}
	}
}
class IO extends PrintWriter {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer st = null;
	public IO() { super (System.out); };
	public String next() {
		while( st== null || !st.hasMoreTokens()) {
			String s;
			try {
				s = br.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			if (s == null) return null;
			st = new StringTokenizer(s);
		}
		return st.nextToken();
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
}


Measured memory_bytes: 84044
//
//  main.cpp
//  120_K-th_Common_Divisor
//
//  Created by tolemy on 2019/08/15.
//  Copyright © 2019 tolemy. All rights reserved.
//

#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    
    int a, b, k = 0;
    cin >> a >> b >> k;
    
    int count = 0;
    int answer = 0;
    for(int i = 100;i>0;i--)
    {
        if(a%i==0 && b%i==0) count++;
        
        if(count == k)
        {
            answer = i;
            break;
        }
    }
    
    std::cout << answer << endl;
    return 0;
}


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

int searchIndex(vector<char> s, char item) {
    for (int i = 0; i < s.size(); ++i) {
        if (s.at(i) == item)  {
            return i;
        }
    }
}

int main() {
    vector<char> alphabets = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',  'Z'};
    int n;
    string s;
    cin >> n;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        int index = searchIndex(alphabets, s.at(i));
        if (index + n > 25) {
            s.at(i) = alphabets.at(index + n - 26);
        } else {
            s.at(i) = alphabets.at(index + n);
        }
    }
    cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
int waru(int a);
int main() {
	int n,ans=0;
	vector<int> a;
	cin >> n;
	a.resize(n);
	REP(i,n){
		cin >> a[i];
	}
	REP(i,n){
		ans += waru(a[i]);
	}
	cout << ans;
	return(0);
}
int waru(int a){
	int c=0;
	while(a%2==0){
		c++;
		a = a/2;
	}
	return c;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
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 (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL <<60;
typedef long long ll;
using namespace std;

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

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

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    /*ll l = 0, r = pow(10,12);
    ll hoge = 0;
    while(r-l>1){
        ll c = (l+r) / 2;
        if(b>c) l = c;
        else r = c;
        hoge = c; 
        //cout<<"left "<<l<<" "<<"right "<<r<<endl;
    }*/
    ll hoge = 0;
    if(b<=n) hoge = b - 1;
    else hoge = n;
    ll ans = (a*hoge)/b - a*(hoge/b);
    cout<<ans<<endl;    
    return 0;
}

Measured memory_bytes: 3632
fun main() {
    val (s, w) = readIntList()
    if (w >= s) {
        println("unsafe")
    } else {
        println("safe")
    }
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}


Measured memory_bytes: 36300
N = int(input())

a = 0
b = 0

for i in range(1,10):
    if N > 100:
        N = N - 100
        a = a + 1

for j in range(1,10):
    if N > 10:
        N = N - 10
        b = b + 1
c = N

if a == c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*
*/
using Graph = vector<bitset<10>>;
ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
const ll P =  1000000007;
ll factorial(ll n){
   ll ans = 1;
   for(int i = n;i>=1;i--){
     ans *= i;
     ans %= P;
   }
   return ans;
}
 
//繰り返し二乗法
ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
  
}

int main(){
  ll m,n;
  cin >> m >> n;
  cout << calc(m,n,P) << endl;
}


Measured memory_bytes: 3112
#include <stdio.h>
main () {
  int S;
  int h,m,s;
  scanf("%d",&S);
  h = S / 3600;
  m = (S - 3600*h)/60;
  s = (S - 3600*h -60*m);
  printf("%d:%d:%d\n",h,m,s);
}


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

using namespace std;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    b = a;
    sort(b.begin(), b.end());
    int t = n / 2 - 1;
    for(int i = 0; i < n; i++){
        if(a[i] <= b[t]){
            cout << b[t + 1] << endl;
        }else{
            cout << b[t] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();

    if (((Math.abs(b - a) <= d) && (Math.abs(c - b) <= d)) || (Math.abs(c - a) <= d)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }
}

Measured memory_bytes: 35676
#include<stdio.h>
#define MOD 1000000007LL

long long int pow( long long int b, long long int i ){
  long long int r = 1;
  while( i ){
    if( i%2 ){
      r *= b;
      r %= MOD;
    }
    b *= b;
    b %= MOD;
    i >>= 1;
  }
  return r;
}

int main(){
  long long int N;
  scanf("%lld", &N);
  long long int ans = pow(10,N) - 2*pow(9,N) + pow(8,N);
  ans = (ans+MOD*100) % MOD;
  printf("%lld\n", ans);
}

Measured memory_bytes: 2152
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<LL> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const int MOD = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;
const int MAX = 100*1000 + 7;


unsigned long long C[51][51];

int main() {
    int n, p;
    cin >> n >> p;
    int a = 0;
    int b = 0;
   // int p = 0;
    
    // Caculate value of Binomial Coefficient in bottom up manner
   FOR(i, 0, 51)    {
       FOR(j, 0, i+1)
        {
            if (j == 0 || j == i)
                C[i][j] = 1;
            else
                C[i][j] = C[i-1][j-1] + C[i-1][j];
        }
    }
    FOR(i, 0, n) {
        int x;
        cin >> x;
        if (x&1)a++;
        else b ++;
    }
   // cout << a<< " " << b << endl;
    unsigned long long x = 0;
    FOR(i, 0, a+1)
        if (i % 2 == p){
            x += C[a][i];
        }
    //cout << x << endl;
    x *= 1LL << b;
    cout << x << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long g(long m,long n){
  return (n==0?m:g(n,m%n));
}
int main(){
  long n, a, b, c, d;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a >> b >> c >> d;
    cout << ((c>=b-g(b,d)+a%g(b,d)||c>=b)&&!(b>a||b>d)?"Yes":"No") << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main()
{
int a,ans=0;
cin>>a;
for (int i = 0; i < a; i++)
{
    ans+=i+1;
}
cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

inline int SH(int x) { return 1<<x; }
inline int BITS(int x) { return (1<<x)-1; }

int N, K;
char buf[(1<<20)+10];
int C[1<<21][21];

void MAIN() {
    scanf("%d%d", &N, &K);
    REP (t, N+1) {
	scanf("%s", buf);
	REP (i, SH(t)) if (buf[i] == '1') {
	    C[i | SH(t)][0]++;
	}
    }

    for (int t=N; t>=0; t--) REP (s, SH(t)) REP (i, t) if (C[s|SH(t)][i]) {
	int cur = C[s|SH(t)][i];
	int sub = s & BITS(i);

	// cut;
	C[sub|SH(i)][i] += cur;

	// 0;
	for (int k=i; k<t; k++) if (~s>>k&1) {
	    int hi = (s>>k)<<i;
	    C[hi|sub|SH(t-k+i)][i+1] += cur;
	    break;
	}

	// 1;
	for (int k=i; k<t; k++) if (s>>k&1) {
	    int hi = (s>>k)<<i;
	    C[hi|sub|SH(t-k+i)][i+1] += cur;
	    break;
	}
    }

    for (int t=N; t>=0; t--) REP (s, SH(t)) if (C[s|SH(t)][t] >= K) {
	for (int i=t; i--;) buf[t-1-i] = (s>>i&1) | '0';
	buf[t] = 0;
	puts(buf);
	return;
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 173440
#include <algorithm>
#include <iostream>
#include <numeric>
#include <set>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<bool> isOK(N + 1, true);
    for (int i = 0; i < M; ++i)
    {
        int ai;
        cin >> ai;
        isOK[ai] = false;
    }

    vector<int> moves(N + 1, 0);
    moves[0] = 1;
    if (isOK[1])
    {
        moves[1] = 1;
    }
    for (int i = 2; i <= N; ++i)
    {
        if (isOK[i - 1])
        {
            moves[i] += moves[i - 1] % 1000000007;
        }
        if (isOK[i - 2])
        {
            moves[i] += moves[i - 2] % 1000000007;
        }
    }
    cout << moves[N] % 1000000007 << endl;
}


Measured memory_bytes: 640
class Binary_Indexed_Tree():
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)

    def add(self, i, x):
        i += 1
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        ret = 0
        while i:
            ret += self.data[i]
            i &= i-1
        return ret

    def sum_range(self, l, r):
        return self.sum(r)-self.sum(l-1)

n,q = map(int, input().split())
yoko = Binary_Indexed_Tree(n-2)
tate = Binary_Indexed_Tree(n-2)
query = [list(map(int, input().split())) for i in range(q)]
for a,b in query:
    if a == 1:
        yoko.add(b-2, 1)
    else:
        tate.add(b-2, 1)

ans = (n-2)**2

yoko_rem = n-2
tate_rem = n-2
yoko_minimum = n-3
tate_minimum = n-3
for a,b in query:
    pos = b-2
    goodbye = 0
    f = False
    if a == 1:
        if yoko_minimum < pos:
            yoko.add(pos, -1)
            f = True
            continue
        goodbye = yoko_rem * yoko.sum_range(pos, yoko_minimum)
        ans -= goodbye
        tate_rem = pos
        yoko.add(pos, -1)
        yoko_minimum = pos
    else:
        if tate_minimum < pos:
            tate.add(pos, -1)
            f = True
            continue
        goodbye = tate_rem * tate.sum_range(pos, tate_minimum)
        ans -= goodbye
        yoko_rem = pos
        tate.add(pos, -1)
        tate_minimum = pos
print(ans)


Measured memory_bytes: 106148
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
const double pi = acos(-1);
const double EPS = 1e-10;
#define int ll


struct dat {
  int x,y,h;
  bool operator<(const dat& right) const{
    return h < right.h;
  } 
};

signed main(){
  int n;
  cin >> n;
  vector<dat> a(n);
  int h = 0;
  bool flag = false;
  REP(i,n)cin >> a[i].x >> a[i].y >> a[i].h;
  sort(ALL(a));
  reverse(ALL(a));
  int i,j;
  for(i = 0; i < 101; i++){
    for(j = 0;j < 101; j++){
      h = abs(a[0].x-i) + abs(a[0].y-j) + a[0].h;
      REP(k,n){
        if (a[k].h != max(h-abs(a[k].x-i)-abs(a[k].y-j),(ll)0)) {
          break;
        }else if(k == n-1){
          flag =true;
          break;
        }
      }
      if (flag) {
        break;
      }
      h = 0;
    }
    if (flag) {
      break;
    }
  }
  cout << i << " " << j << " " << h << endl;
}

Measured memory_bytes: 256