akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

//RSQ
struct RSQ{
private:
	int N;
	vector<long long> node, lazy;
	vector<bool> lazyFlg;
	const long long DEFAULT = 0LL;
public:
	void init(int n){ //初期化 O(N)
		node.clear();
		lazy.clear();
		lazyFlg.clear();
		N = 1;
		while(N < n) N = (N<<1);
		for(int i=0; i<2*N-1; i++){
			node.push_back(DEFAULT);
			lazy.push_back(0LL);
			lazyFlg.push_back(false);
		}
	}
	void eval(int k, int l, int r){ //遅延評価 O(1)
		if(lazyFlg[k]){ //RUQ：下に更新クエリが溜まっていても加算クエリが溜まっていても上書き
			node[k] = lazy[k];
			if(r-l > 1){
				lazy[(k<<1)+1] = lazy[k] >> 1;
				lazyFlg[(k<<1)+1] = true;
				lazy[(k<<1)+2] = lazy[k] >> 1;
				lazyFlg[(k<<1)+2] = true;
			}
			lazy[k] = 0LL;
			lazyFlg[k] = false;
		}
		else{ //RAQ：下に更新クエリが溜まっていても加算クエリが溜まっていても加算
			node[k] += lazy[k];
			if(r-l > 1){
				lazy[(k<<1)+1] += lazy[k] >> 1;
				lazy[(k<<1)+2] += lazy[k] >> 1;
			}
			lazy[k] = 0LL;
		}
	}
	void update(int a, long long x){ //[a,a+1)の値を変更 O(log N)
		update(a, a+1, x);
	}
	void update(int a, int b, long long x, int k=0, int l=0, int r=-1){ //[a,b)の値を変更 O(log N)
		if(r == -1) r = N;
		eval(k, l, r);
		if(b <= l || r <= a) return; //交差する場合
		if(a <= l && r <= b){ //完全に含む場合
			lazy[k] = x * (r-l);
			lazyFlg[k] = true;
			eval(k, l, r);
		}
		else{
			update(a, b, x, (k<<1)+1, l, (l+r)>>1);
			update(a, b, x, (k<<1)+2, (l+r)>>1, r);
			node[k] = node[(k<<1)+1] + node[(k<<1)+2];
		}
	}
	void add(int a, long long x){ //[a,a+1)の値に加算 O(log N)
		add(a, a+1, x);
	}
	void add(int a, int b, long long x, int k=0, int l=0, int r=-1){ //[a,b)の値に加算 O(log N)
		if(r == -1) r = N;
		eval(k, l, r);
		if(b <= l || r <= a) return; //交差する場合
		if(a <= l && r <= b){ //完全に含む場合
			lazy[k] += x * (r-l);
			eval(k, l, r);
		}
		else{
			add(a, b, x, (k<<1)+1, l, (l+r)>>1);
			add(a, b, x, (k<<1)+2, (l+r)>>1, r);
			node[k] = node[(k<<1)+1] + node[(k<<1)+2];
		}
	}
	long long sum(int a, int b, int k=0, int l=0, int r=-1){ //[a,b)の和 O(log N)
		if(r == -1) r = N;
		if(b <= l || r <= a) return DEFAULT; //交差する場合
		eval(k, l, r);
		if(a <= l && r <= b) return node[k]; //完全に含む場合
		return sum(a, b, (k<<1)+1, l, (l+r)>>1) + sum(a, b, (k<<1)+2, (l+r)>>1, r);
	}
};

int N;
ll D, A;
ll X[200000], H[200000];
vector<pair<ll, ll>> v;
RSQ rsq;
ll ans = 0;
signed main(){
	cin >> N >> D >> A;
	rep(i, N){
		cin >> X[i] >> H[i];
		v.pb({X[i], H[i]});
	}
	sort(all(v));

	rsq.init(N);
	rep(i, N) rsq.update(i, v[i].second);
	rep(i, N){
		ll tmp = rsq.sum(i, i+1);
		if(tmp <= 0) continue;
		ll t = (tmp+A-1) / A;
		ans += t;
		int idx = lower_bound(all(v), mp( v[i].first+2*D+1, LLONG_MIN )) - v.begin();
		//std::cout << t << " " <<  i << " " << idx << endl;
		rsq.add(i, idx, -t*A);
	}
	std::cout << ans << endl;
}

Measured memory_bytes: 20460
#include <stdio.h>

int main ( void ) {
  
  //char str[1000];
  int num[10];
  
  for(int i = 0; i < 5; i++){
    scanf("%d", &num[i]);
    if(num[i] == 0){
      printf("%d\n", i + 1);
    }
  }
    
  return 0;
}

Measured memory_bytes: 1728
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<string> vs;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int n; vi h;
vi memo;

int rec(int p) {
    if (memo[p] == -1) {
        if (p == n - 1) memo[p] =  0;
        else if (p == n - 2) memo[p] = rec(p + 1) + abs(h[p] - h[p + 1]);
        else memo[p] = min(rec(p + 1) + abs(h[p] - h[p + 1]), rec(p + 2) + abs(h[p] - h[p + 2]));
    }
    return memo[p];
}


int main() {
    cin >> n;
    h.resize(n);
    rep(i, n) {
        cin >> h[i];
        memo.pb(-1);
    }
    cout << rec(0)  << endl;
}

Measured memory_bytes: 3448
#include <iostream>

int main() {
	int m, n, a, b, c, d;

	while (std::cin >> n) {
		m = 0;
		for (a = 0; a <= 9; ++a) {
			for (b = 0; b <= 9; ++b) {
				for (c = 0; c <= 9; ++c) {
					for (d = 0; d <= 9; ++d) {
						if (a + b + c + d == n) {
							++m;
						}
					}
				}
			}
		}
		std::cout << m << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
const int N=1e6;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
LL f[N],pre[N],suf[N],ans=1LL<<60;
#define lc (i<<1)
#define rc (lc|1)
inline void build(int i,int l,int r) {
	if (l==r) pre[i]=f[l]-l,suf[i]=f[r]+r;
	else {
		int mid=(l+r)>>1;
		build(lc,l,mid);
		build(rc,mid+1,r);
		pre[i]=min(pre[lc],pre[rc]);
		suf[i]=min(suf[lc],suf[rc]);
	}
}
inline LL Q1(int i,int l,int r,int R) {
	if (r<=R) return pre[i];
	int mid=(l+r)>>1;
	return R<=mid?Q1(lc,l,mid,R):min(pre[lc],Q1(rc,mid+1,r,R));
}
inline LL Q2(int i,int l,int r,int L) {
	if (L<=l) return suf[i];
	int mid=(l+r)>>1;
	return mid<L?Q2(rc,mid+1,r,L):min(suf[rc],Q2(lc,l,mid,L));
}
inline void modify(int i,int l,int r,int k,LL w) {
	if (l==r) pre[i]=w-l,suf[i]=w+r;
	else {
		int mid=(l+r)>>1;
		k<=mid?modify(lc,l,mid,k,w):modify(rc,mid+1,r,k,w);
		pre[i]=min(pre[lc],pre[rc]);
		suf[i]=min(suf[lc],suf[rc]);
	}
}
inline void solve(int i,int l,int r) {
	if (l==r) ans=min(ans,pre[i]+l);
	else {
		int mid=(l+r)>>1;
		solve(lc,l,mid);
		solve(rc,mid+1,r);
	}
}
int main()
{
	int n=gi(),Q=gi(),A=gi(),last=gi(),i,x;LL tag=0,p;
	for (i=1;i<=n;i++) f[i]=i==A?0:1LL<<60;
	build(1,1,n);
	while (Q--) {
		x=gi();
		p=min(x+Q1(1,1,n,x),Q2(1,1,n,x)-x);
		tag+=abs(x-last);
		modify(1,1,n,last,p-abs(x-last));
		last=x;
	}
	solve(1,1,n);
	printf("%lld\n",ans+tag);
	return 0;
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  vector<int> d(n);
  d[0] = 0;
  rep(i, n) d[0] += (i % 2 == 0 ? 1 : -1) * a[i];
  rep3(i, 1, n) d[i] = 2 * a[i - 1] - d[i - 1];
  cout << d << '\n';
}


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

int dp[502][2][10][500][3], m, len[2];
char S[2][550];
int solve(int o) {
	memset(dp, 0, sizeof(dp));
	dp[0][0][0][0][0] = 1;
	rep(i, len[o])rep(j, 2)rep(k, 10)rep(l, m)rep(d, 3) {
		if (dp[i][j][k][l][d] == 0)continue;
		int s, g, p = S[o][i] - '0';
		if (d == 1)s = k + 1, g = (j ? 9 : p);
		else if (d == 2)s = 0, g = (j ? k - 1 : min(k - 1, p));
		else s = 0, g = (j ? 9 : p);
		for (int x = s; x <= g; x++) {
			if (x&&k == x)continue;
			int y;
			if (d == 1)y = 2;
			else if (d == 2)y = 1;
			else {
				if (k == 0)y = 0;
				else if (x < k)y = 1;
				else y = 2;
			}
			(dp[i + 1][j || x < p][x][(l * 10 + x) % m][y] += dp[i][j][k][l][d]) %= MOD;
		}
	}
	int sum = 0;
	rep(j, 10)rep(t, 3) {
		(sum += dp[len[o]][1][j][0][t]) %= MOD;
		if (o)(sum += dp[len[o]][0][j][0][t]) %= MOD;
	}
	return sum;
}
int main() {
	scanf("%s%s%d", S[0], S[1], &m);
	rep(i, 2)len[i] = strlen(S[i]);
	printf("%d\n", (solve(1) + MOD - solve(0)) % MOD);
}

Measured memory_bytes: 62032
x, y = gets.split.map(&:to_i)
if x >= 0
    if y >= x
        puts y - x
    elsif y >= 1
        puts x - y + 2
    else
        puts (y + x).abs + 1
    end
else
    if y >= x.abs
        puts y - x.abs + 1
    elsif y >= 1
        puts -y - x + 1
    elsif y >= x
        puts y - x
    else
        puts y.abs - x.abs + 2
    end
end

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

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << endl;}

typedef uint64_t ulint;
typedef int64_t lint;
using namespace std;

lint a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,u,v,w,x,y,z;
bool flagdebug = false;

int main(){
//////////////////////////////////////////////////////
    // flagdebug = true;

    string s, t;
    cin >> s;
    cin >> t;

    lint minv = 10000;

    //lint maxv = 0;

    lint mm = 0;
    rep0(i,s.length() - t.length() + 1)
    {
        mm = 0;
        rep0(j, t.length())
        {
            lint sp = i + j;
            lint tp = j;

            if(s[sp] != t[tp])
            {
                mm ++;
            }
        }
        minv = min(minv, mm);
    }


    cout << minv << endl;

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <array>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define all(c) begin(c), end(c)
#define dump(c) cerr << "> " << #c << " = " << (c) << endl
#define tr(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int,int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;

int decode(string a) {
  map<char, int> d;
  d['m'] = 1000;
  d['c'] = 100;
  d['x'] = 10;
  d['i'] = 1;

  int ret = 0;
  int n = 1;
  rep(i, a.size()) {
    char c = a[i];
    if (d[c] != 0) {
      ret += n * d[c];
      n = 1;
    }
    else {
      n = c - '0';
    }
  }

  return ret;
}

string encode(int a) {
  string s = to_string(a);
  while (s.size() != 4) s.insert(s.begin(), '0');
  string d = "mcxi";
  string ret;
  rep(i, 4) {
    if (s[i] == '0') continue;
    if (s[i] != '1') ret += s[i];
    ret += d[i];
  }

  return ret;
}

int main() {
  int CASES; cin >> CASES;
  while (CASES--) {
    string A, B; cin >> A >> B;
    cout << encode(decode(A) + decode(B)) << endl;


  }
  
  
  return 0;
}

Measured memory_bytes: 1252
#include <cstdio>
#include <iostream>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
const int N=500000;
const int mod=998244353;
int n, m, ans, f[N+1], F[N+1];
void inc(int&a,int b){(a+=b)%=mod;}
int C(int n,int m){
	if(n<m||n<0||m<0)return 0;
	return 1LL*f[n]*F[m]%mod*F[n-m]%mod;
}
int mi(int a,int b){
	int s=1;
	for(;b;b>>=1,a=1LL*a*a%mod)
		if(b&1)s=1LL*s*a%mod;
	return s;
}
int main(){
	scanf("%d%d", &n, &m);
	f[0] = 1;
	ref(i, 1, N)f[i] = 1LL*f[i-1]*i%mod;
	F[N] = mi(f[N],mod-2);
	def(i, N, 1)F[i-1] = 1LL*F[i]*i%mod;
	if(!(m&1)&&m/2>=n)
		inc(ans, C(m-1,m/2) - C(m-1,m-n+1));
	ref(i, m/2+1, m){
		if(2*i-m >= n) inc(ans, C(m,i));else
		if(i >= n) inc(ans, C(m,i) - C(m,2*i+1-n));
	}
	cout<<((ans+mod)%mod)<<endl;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep2(i,x,n) for(int i=x;i<n;++i)

bool is_prime(int a)
{
    if(a<2) return false;
    else if(a==2) return true;
    else if(a%2==0) return false;

    int d = int(sqrt(a));
    for(int i=3;i<=d;i+=2)
        if(a%i==0) return false;
    
    return true;
}

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

    while(!is_prime(x)) ++x;
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <unistd.h>
#include <utility>
#include <vector>
#define dbc(x) cerr << x << '\n'
#define dbn(x) cerr << #x << " == " << x << '\n'
#define pb push_back
#define endl '\n'

using namespace std;

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

//

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

	int n; cin >> n;

	int tt = 0;
	int xx = 0;
	int yy = 0;

	while (n--) {
		int t,x,y; cin >> t >> x >> y;
		int man = abs(xx-x) + abs(yy-y);
		if (man <= t-tt) {
			if (((t-tt) - man) % 2 == 0) {
				tt = t;
				xx = x;
				yy = y;
			} else {
				cout << "No" << endl;
				return 0;
			}
		} else {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


int main(int argc, char *argv[]) {

	int A,B,C; cin >> A >> B >> C;

	if (A * C <= B) {
		cout << C << endl;
	}else {
		cout << B / A << endl;	
	}

	return 0;
}


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

using namespace std;

const int N = 200010;

int n, m;
int p[N], cnt[N];

int find(int x)
{
    if (p[x] != x) p[x] = find(p[x]);
    return p[x];
}
int sz[N];
bool st[N];
int main()
{
   	int d,s,t;
  cin >> d >> s >> t;
  if(s*t >= d)
    	cout << "Yes" << endl;
  else
    	cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3588
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<String, Integer> map = new HashMap<>();
        int max = 0;
        for(int i=0; i<n; i++) {
            String key = sc.next();
            int a = map.getOrDefault(key, 0) + 1;
            max = Math.max(max, a);
            map.put(key, a);
        }
        List<String> list = new ArrayList<>();
        for(String key : map.keySet()) {
            if(map.get(key) == max) {
                list.add(key);
            }
        }
        Collections.sort(list);
        for(String key : list) {
            System.out.println(key);
        }


    }



}


Measured memory_bytes: 84988
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL N=100010;
LL n, a[N], b[N], s[N<<1],f[N<<1];
int main(){
	scanf("%lld",&n);
	for(LL i=1; i<=n; ++i)scanf("%lld%lld",&a[i],&b[i]),s[i*2-1]=a[i],s[i*2]=b[i];
	sort(s+1,s+2*n+1);
	for(LL i=1; i<=n; ++i)f[i]=f[i-1]+s[i];
	LL ans=0, tmp=0;
	for(LL i=1; i<=n; ++i)ans+=a[i];
	for(LL i=1; i<=n; ++i)tmp+=b[i]; ans=min(ans,tmp);
	for(LL i=1; i<=n; ++i){
		tmp=a[i]+b[i]+f[n-2];
		LL d=n-2;
		if(a[i]>b[i])swap(a[i],b[i]);
		if(s[d]>=a[i])++d,tmp=tmp-a[i]+s[d];
		if(s[d]>=b[i])++d,tmp=tmp-b[i]+s[d];
		ans=min(ans,tmp);
	}
	printf("%lld",ans);
	return 0;
}

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

typedef long long ll;
#define pii pair<ll , ll>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 200005


int main()
{
    _FastIO;
    string s;
    int n;
    cin >> n;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < n - 2; i++){
        if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C'){
            ans++;
        }

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


Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

int f(int n){
    int sum = 0;
    while(n>0){
        sum += n%10;
        n/=10;
    }
    return sum;
}

void Main(){
    int N;
    cin >> N;
    vec<string> ss(N);
    REP(i, N){
        cin >> ss[i];
    }
    map<string, bool> mp;
    mp[ss[0]] = true;
    FOR(i, N, 1){
        if(ss[i-1][ss[i-1].length()-1] != ss[i][0] || mp[ss[i]]){
            cout << "No" << el;return;
        }
        mp[ss[i]] = true;
    }
    cout << "Yes" << el;
}



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

struct RECIPE{
	string o;
	int k;
	string q[100];
};

RECIPE recipe[100];
int n;
pair<string, int> ip[100];
int m;

int func(string order){

	int x, y;
	bool flg = false;
	for (int i = 0; i < m; i++){
		if (recipe[i].o == order){
			flg = true;
			x = i;
			break;
		}
	}
	for (int i = 0; i < n; i++){
		if (ip[i].first == order){
			y = i;
			break;
		}
	}
	int sum = 0;
	if (flg){
		for (int i = 0; i < recipe[x].k; i++){
			sum += func(recipe[x].q[i]);
		}
	}
	else{
		for (int i = 0; i < n; i++){
			if (ip[i].first == order)
				return ip[i].second;
		}
	}

	return min(sum, ip[y].second);
}

int main(void){

	while (cin >> n && n != 0){
		string order;

		for (int i = 0; i < n; i++)
			cin >> ip[i].first >> ip[i].second;
		cin >> m;
		for (int i = 0; i < m; i++){

			cin >> recipe[i].o >> recipe[i].k;
			for (int j = 0; j < recipe[i].k; j++)
				cin >> recipe[i].q[j];
		}

		cin >> order;
		cout << func(order) << endl;
	}
}

Measured memory_bytes: 1300
#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
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;
int p[100010];
int x[100010],y[100010];
struct UnionFind
{
    vector<int> par;
   
    UnionFind(int n) : par(n,-1){}
    void init(int n) { par.assign(n,-1);}
 
    int root(int x){
        if(par[x]<0) return x;
        return par[x]=root(par[x]);
    }
 
    bool issame(int x, int y){
        return root(x)==root(y);
    }
    bool merge(int x, int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(par[x]>par[y])swap(x,y);
        par[x]+=par[y];
        par[y]=x; //大きさが正になるよ
        return true;
    }
    int size(int x){
        return -par[root(x)];
    }
};
int main(){
    int n,m;
    cin>>n>>m;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin>>a;
        a--;
        p[i]=a;
    }
    for (int i = 0; i < m; i++)
    {
        int a,b;
        cin>>a>>b;
        a--;b--;
        x[i]=a;
        y[i]=b;
    }
    UnionFind uni(n);
    for (int i = 0; i < m; i++)
    {
        uni.merge(x[i],y[i]);
    }
    int ans=0;
    for (int i = 0; i < n; i++)
    {
        if(uni.root(i)==uni.root(p[i])){
            ans++;
        }
    }
    cout<<ans<<endl;
    
    


    
    


    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cctype>
using namespace std;

const int INF=0x3f3f3f3f;

int n,res;

int main(){
    while(cin>>n){
        res=1;
        int p=0;
        while(p<n){
            p+=res;
            res++;
        }
        printf("%d\n",res-1);
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
b = list(map(int,input().split()))
ans = []
for i in range(n):
    r = -1
    for j in range(len(b)):
        if j+1==b[j]:
            r = j
    if r<0:
        ans = [-1]
        break
    ans.append(b.pop(r))
[print(i) for i in ans[::-1]]


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)
 
int main(){
    int h,w;
    
    while(1){
        cin>>h>>w;
        if(h==0&&w==0) break;
        
        // 0gyo-me
        REP(i,w){
            cout<<'#';
        }
        cout<<endl;
        
        // 1~(h-2)gyo-me
        for(int i=1; i<h-1; i++){
            REP(j,w){
                if(j==0||j==w-1){
                    cout<<'#';
                }else{
                    cout<<'.';
                }
            }
            cout<<endl;
        }
        
        // saigo
        REP(i,w){
            cout<<'#';
        }
        cout<<endl<<endl;
    }
}


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

using namespace std;

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

const double pi = 3.14159265358979323846;

#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define TG0 get< 0 >
#define TG1 get< 1 >
#define TG2 get< 2 >
#define F first
#define S second
#define VL vector< ll >

// to_string(123)
// atoi("123"); atoi(s.c_str());
// "abc".size()
// s.find('+') == string::npos

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

  ll K;
  cin >> K;

  ll c = 0;
  for (ll i = 1; i < K; i += 2) {
    for (ll j = 0; j < K; j += 2) {
      c++;
    }
  }

  cout << c << endl;

  return 0;
}


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

int cnt[110];
int a,b,c,ans;

int main()
{
	//fuck
	cin>>a>>b>>c;
	cnt[a]++;
	cnt[b]++;
	cnt[c]++;
	for(int i=1;i<=100;i++)
	{
		if(cnt[i])
		{
			ans++;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (a, b) = get!(usize, usize);
    let gcd = gcd(a, b);
    let v = make_divisors(gcd);
    // eprintln!("{:?}", v);
    let mut ans = 1;
    for i in 0..v.len() {
        if is_prime(v[i]) {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn gcd(a: usize, b: usize) -> usize {
    let mut a = a;
    let mut b = b;
    while b != 0 {
        let r = b;
        b = a % b;
        a = r;
    }
    a
}

fn make_divisors(n: usize) -> Vec<usize> {
    let mut v = Vec::new();
    for i in 1..n + 1 {
        if n < i * i {
            break;
        }
        if n % i == 0 {
            v.push(i);
            if n / i != i {
                v.push(n / i);
            }
        }
    }
    v
}
fn is_prime(n: usize) -> bool {
    if n <= 3 {
        if n == 0 || n == 1 {
            return false;
        } else {
            return true;
        }
    }
    if n % 2 == 0 {
        return false;
    }
    if n % 3 == 0 {
        return false;
    }
    if n % 6 != 1 && n % 6 != 5 {
        return false;
    }
    let mut i = 5;
    while i * i <= n {
        if n % i == 0 {
            return false;
        }
        if n % (i + 2) == 0 {
            return false;
        }
        i += 6;
    }
    true
}


Measured memory_bytes: 4352
import pdb

N, M = map(int, input().split())
a, b = [], []
mat = [[0 for _ in range(N)] for _ in range(N)]

for _ in range(M):
    _a, _b = map(int, input().split())
    a.append(_a)
    b.append(_b)
    mat[_a-1][_b-1] = 1
    mat[_b-1][_a-1] = 1

visited = set()
ans = 0

def dfs(num):
    global ans
    #pdb.set_trace()
    visited.add(num)
    if len(visited) == N:
        ans += 1
        return 
    
    for next_num, connected in enumerate(mat[num]):
        if not connected:
            continue
        if next_num in visited:
            continue
        visited.add(next_num)
        dfs(next_num)
        visited.remove(next_num)
    return

def main():
    dfs(0)
    print(ans)

main()


Measured memory_bytes: 5392
// :)
// "Khodaya, be man "Tagwaye setiz" biamooz ta
//  dar anbuh masuliat nalaghzam ..." -Shariati
#include <bits/stdc++.h>

using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pii64;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

const int maxn = 1e5+7;
const int64 M = 1e9+7;
const int64 I = 1e9;

string s1, s2, s3;

int n, ans;

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	// 
	cin >> n >> s1 >> s2 >> s3;
	//
	for (int i = 0; i < n; i++) {
		if (s1[i] == s2[i] && s1[i] == s3[i])
			continue;
		if (s1[i] == s2[i] || s1[i] == s3[i] || s2[i] == s3[i])
			ans++;
		else
			ans += 2;
	}
	//
	cout << ans << "\n";
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;
using int_vec = vector<int>;

bool combination(int m, int_vec& v, int sum, int k) {
    if (k >= v.size())
        return false;

    int x = sum + v[k];
    if (x == m) {
        return true;
    }
    if (combination(m, v, x, k+1)) {
        return true;
    }
    return combination(m, v, sum, k+1);
}

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

    int_vec v;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        v.push_back(x);
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int m;
        cin >> m;

        if (combination(m, v, 0, 0)) {
            cout << "yes";
        } else {
            cout << "no";
        }
        cout << endl;
    }
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}

vector<int>cnt;
vector<int>sum;
vector<int>g[200020];
void dfs(int now,int par,int add){
	add += cnt[now];
	sum[now] = add;
	for(auto e:g[now]){
		if(e == par)continue;
		dfs(e,now,add);
	}
}

signed main(){
	int N,Q;
	cin>>N>>Q;
	REP(i,N-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	cnt.resize(N,0);
	sum.resize(N,0);
	REP(i,Q){
		int p,x;
		cin>>p>>x;
		cnt[p-1]+=x;
	}
	dfs(0,-1,0);
	int ans = 0;
	REP(i,N){
		if(i)cout<<" ";
		cout<<sum[i];
	}
	cout<<endl;
}


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

int main(){
    long long a, b, c;
    cin>>a>>b>>c;
    long long d=4*a*b;
    long long e=(c-a-b);
    if((c-a-b)>0&&d<e*e){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a[10],i,j,n;
    for(i=0;i<10;i++){
        std::cin>>a[i];
    }for(i=0;i<9;i++){
        for(j=i+1;j<10;j++){
           if(a[i]<a[j]){
              n=a[i];
              a[i]=a[j];
              a[j]=n;
           }
        }
     }
   cout<<a[0]<<endl<<a[1]<<endl<<a[2]<<endl;
                                                  
return 0;
}

Measured memory_bytes: 1160
fun main(args: Array<String>) {
    val (a, b, c, d) = readLine()!!.split(' ').map { it.toInt() }
    val ans = when {
        Math.abs(a - c) <= d -> "Yes"
        Math.abs(a - b) <= d && Math.abs(b - c) <= d -> "Yes"
        else -> "No"
    }
    println(ans)
}


Measured memory_bytes: 36312
from collections import deque
A = deque()
n = int(input())
for i in range(n):
    tmp = input().split()
#    print(tmp,A)
    if tmp[0] == "0" and tmp[1] == "0":
        A.appendleft(tmp[2])
    elif tmp[0] == "0" and tmp[1] == "1":
        A.append(tmp[2])
    elif tmp[0] == "1":
        print(A[int(tmp[1])])
    elif tmp[1] == "0":
        A.popleft()
    else:
        A.pop()


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

typedef pair<int,int> P;

#define fr first
#define sc second

int n;
int x[10002],y[10002];

bitset<20002> G[20002];
bitset<20002> rG[20002];

vector<int> vs;
bitset<20002> alive;
bitset<20002> nex;
void dfs(int v){
	if(!alive[v])return;
	alive[v] = false;
	while(1){
		nex = alive & G[v];
		int x = nex._Find_first();
		if(x == 20002)break;
		dfs(x);
	}
	vs.push_back(v);
}

bitset<20002> c;
void scc(int v){
	if(!alive[v])return;
	alive[v] = false;
	while(1){
		nex = alive & rG[v];
		int x = nex._Find_first();
		if(x == 20002)break;
		scc(x);
	}
	c[v] = true;
}

bitset<20002> mask;

bool f(int d){
	vector<P> vec;
	for(int i = 0 ; i < n ; i ++){
		vec.push_back(P(x[i],2*i));
		vec.push_back(P(y[i],2*i+1));
	}
	sort(vec.begin(),vec.end());
	
	bitset<20002> a,b;
	int l = 0, r = 0;
	for(int i = 0 ; i < vec.size() ; i ++){
		while(r < vec.size() && vec[r].fr < vec[i].fr+d){
			a[vec[r].sc^1] = true;
			b[vec[r].sc] = true;
			r ++;
		}
		while(l < vec.size() && vec[l].fr <= vec[i].fr-d){
			a[vec[l].sc^1] = false;
			b[vec[l].sc] = false;
			l ++;
		}
		G[vec[i].sc] = a;
		G[vec[i].sc][vec[i].sc^1] = false;
		rG[vec[i].sc^1] = b;
		rG[vec[i].sc^1][vec[i].sc] = false;
	}
	
	vs.clear();
	alive.set();
	for(int i = 0 ; i < 2*n ; i ++){
		if(alive[i])dfs(i);
	}
	reverse(vs.begin(),vs.end());
	alive.set();
	for(int i = 0 ; i < vs.size() ; i ++){
		c.reset();
		scc(vs[i]);
		c &= c>>1;
		c &= mask;
		if(c.any())return false;
	}
	return true;
}

int main(){
	mask.reset();
	for(int i = 0 ; i < 10000 ; i ++){
		mask[2*i] = true;
	}
	
	scanf("%d",&n);
	for(int i = 0 ; i < n ; i ++){
		scanf("%d%d",&x[i],&y[i]);
	}
	
	int l = 0, r = 1000000000;
	while(l < r){
		int m = (l+r+1)/2;
		if(f(m))l = m;
		else r = m-1;
	}
	cout << l << endl;
}



Measured memory_bytes: 148956
// AOJ 2083 Black Force
// 2018.3.26 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int  H, W, C;
int  map[22][22];
char ban[22][22];
char mk[22][22];
int  mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
int  h[404], sz;
int  ok, vol;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

void dfs(int r, int c, int h)
{
	int i, nr, nc;

	if (mk[r][c] || h <= map[r][c]) return;
	mk[r][c] = 1;
	vol += h - map[r][c];
	if (ban[r][c] || r == 0 || r == H-1 || c == 0 || c == W-1) ok = 0;
	for (i = 0; i < 4; i++) {
		nr = r + mv[i][0], nc = c + mv[i][1];
		if (nr < 0 || nr >= H || nc < 0 || nc >= W) continue;
		dfs(nr, nc, h);
	}
}

int check(int h)
{
	int r, c;

	memset(mk, 0, sizeof(mk));
	for (r = 1; r < H-1; r++) for (c = 1; c < W-1; c++) {
		if (!mk[r][c] && map[r][c] < h) {
			ok = 1, vol = 0;
			dfs(r, c, h);
			if (ok && vol >= C) return 1;
		}
	}
	return 0;
}

int cmp(int *a, int *b) { return *a - *b; }

int uniq(int *a, int n)
{
	int i, j;
	
	for (i = 0, j = 1; j < n; j++) {
		while (j < n && a[j] == a[i]) j++;
		if (j < n) if (++i != j) a[i] = a[j];
	}
	return i+1;
}

int main()
{
	int R, i, r, c;

	while (H = in()) {
		memset(ban, 0, sizeof(ban));
		W = in(), C = in(), R = in();

		sz = 0;
		for (r = 0; r < H; r++) for (c = 0; c < W; c++) {
			h[sz++] = map[r][c] = in();
		}
		qsort(h, sz, sizeof(int), cmp);
		sz = uniq(h, sz);

		while (R--) ban[in()-1][in()-1] = 1;

		for (i = 0; i < sz; i++) if (check(h[i])) goto yes;

		for (r = 0; r < H; r++) for (c = 0; c < W; c++) {
			if (ban[r][c]) continue;
			map[r][c]++;
			if (check(map[r][c])) goto yes;
			map[r][c]--;
		}
		puts("No");
		continue;
yes:	puts("Yes");
	}
	return 0;
}



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

int main(){
	int n, m;	cin >> n >> m;
  	vector<int> p(m);
  	vector<string> s(m);
  	rep(i,m) cin >> p.at(i) >> s.at(i);
  	
	map<int,string> dc;
  	int wa = 0, ac = 0;
  	rep(i,m){
    	if(s.at(i) == "AC" && dc[p.at(i)] != "AC"){
          dc[p.at(i)] = "AC";	ac++;}
      	if(s.at(i) == "WA" && dc[p.at(i)] != "AC"){
          dc[p.at(i)] = "WA";
          wa++;}
    }
  	rep(i,m){
    	if(dc[p.at(i)] != "AC" && s.at(i) == "WA"){
      		wa--;  	
        }
    }
  	
  	cout << ac << " " << wa << endl;
}


Measured memory_bytes: 17024
#include <iostream>
#include <vector>
#include <cmath>
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int k, x;
  cin >> k >> x;
  if (k * 500 >= x) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

const int MOD = 1000000007;
long long dp[2005][2005];

int main(){
	int n,k;
	cin >> n >> k;

	dp[0][0] = 1;
	for (int i=1; i<=n; i++){
		for (int j=0; j<=i; j++){
			if(j==0) dp[i][j] = 1;
			else dp[i][j] = (dp[i-1][j-1]+dp[i-1][j])%MOD;
		}
	}
				
	for (int i=1; i<=k; i++){
		cout << (dp[n-k+1][i]*dp[k-1][i-1])%MOD << endl;
	}

	return 0;
}

Measured memory_bytes: 26216
n = int(input())
l = list(map(int, input().split()))
ll = []
ans = []
for i in range(len(l)):
    ll.append([i + 1, l[i]])
ll = sorted(ll, key=lambda x: x[1])
for i in range(len(l)):
    ans.append(str(ll[i][0]))
print(' '.join(ans))

Measured memory_bytes: 28496
// -*- coding:utf-8-unix -*-

use proconio::input;
use proconio::marker::Chars;
use std::iter::FromIterator;

fn print_vec(v: &Vec<char>, b: bool) {
    if b { println!("{}", String::from_iter(v)); }
    else { print!("{}", String::from_iter(v)); }
}

fn print_vec_range(v: &Vec<char>, s: usize, t: usize, b: bool) {
    for i in s..t {
        print!("{}", v[i]);
    }
    if b { print!("\n"); }
}

fn main() {
    input! {
        k: usize,
        s: Chars
    }
    let s: Vec<char> = s;
    if s.len() <= k {
        print_vec(&s, true);
    } else {
        print_vec_range(&s, 0, k, false);
        println!("...");
    }
}


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


int main(void)
{
	int n, y;
	cin >> n >> y;

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (i+j > n)
				continue;
			int sum = 10000*i + 5000*j;
			if (sum+1000*(n-i-j) == y) {
				cout << i << " " << j << " " << n-i-j << endl;
				return 0;
			}
		}
	}

	cout << "-1 -1 -1" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

int main()
{
    ll a, b, k;
    cin >> a >> b >> k;
    if(a >= k){
        a = a-k;
    }else if(a < k){
        k = k-a;
        a = 0;
        if(b >= k){
            b = b-k;
        }else if(b < k){
            b = 0;
        }
    }
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 3604
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 T = sc.nextInt();

		int s = T/A;

		System.out.println(B*s);

	}
}

Measured memory_bytes: 22740
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct stu
{
	int i;
	long long x,y;
};
stu a[55];
struct sta
{
	int j;
	long long x,y;
};
sta b[55];
int main()
{
	int N,M,min_i;
	long long dis=9000000000000000000,tmp=dis;
	scanf("%d%d",&N,&M);
	for(int n=1;n<=N;n++)
	{
		scanf("%lld%lld",&a[n].x,&a[n].y);
		a[n].i=n;
	}
	for(int m=1;m<=M;m++)
	{
		scanf("%lld%lld",&b[m].x,&b[m].y);
		b[m].j=m;
	}
	for (int n =1;n<=N;n++)
	{	for (int m =1; m <=M;m++)
			if(dis>abs(a[n].x-b[m].x)+abs(a[n].y-b[m].y))	
			{
				dis=abs(a[n].x-b[m].x)+abs(a[n].y-b[m].y);
				min_i=m;
			}
		printf("%d\n",min_i);
		dis=tmp;
	}
	return 0;
}

Measured memory_bytes: 128
#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;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
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);

    string s;
    int k;
    cin >> s >> k;
    int n = s.length();
    vector<vector<int>> p(26);
    for(int i = 0; i < n; ++i){
        p[s[i] - 'a'].emplace_back(i);
    }
    set<string> ans;
    for(int i = 0; i < 26; ++i){
        if(!p[i].size())    continue;
        string str(1, (char)(i + 'a'));
        ans.emplace(str);
        for(auto st : p[i]){
            int cur = st;
            string t = str;
            for(int j = 1; j < k; ++j){
                if(++cur >= n)  break;
                t += s[cur];
                ans.emplace(t);
            }
        }
        if(ans.size() >= k) break;
    }
    while(k > 1){
        ans.erase(ans.begin());
        --k;
    }
    cout << *(ans.begin()) << endl;
}

Measured memory_bytes: 3736
import math
import fractions
A, B, C, D = map(int, input().split())
g = int(C*D/fractions.gcd(C,D))
N = B - A + 1
E = B - B//C  - B//D + B//g
F = A-1 - (A-1)//C - (A-1)//D + (A-1)//g
print(int(E-F))

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

n=int(input())
a=list(map(int, input().split()))

d={}

for i in range(n):
    if str(a[i]-1) in d:
        d[str(a[i]-1)]+=1
    else:
        d[str(a[i]-1)]=1
    if str(a[i]) in d:
        d[str(a[i])]+=1
    else:
        d[str(a[i])]=1
    if str(a[i]+1) in d:
        d[str(a[i]+1)]+=1
    else:
        d[str(a[i]+1)]=1

print(max(d.values()))


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

#define lli long long int
#define rep(i,n) for (int i=0; i<(int)n; i++)
const lli mod=1e+9 + 7;

int N,M;

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

    cin >> N >> M;
    vector<bool>gg(N+1, true);
    int a;
    rep(i, M) {
        cin >> a;
        gg[a] = false;
    }

    vector<lli> memo(N+1);
    memo[0] = 1;
    for (int now = 0; now < N; ++now) {
        for (int next=now+1; next <= min(N, now+2); ++next) {
            if (gg[next]) {
                memo[next] += memo[now];
                memo[next] %= mod;
            }
        }
    }
    
    cout << memo[N] << "\n";
    return 0;
}

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


int main() {

    int n, k;
    cin >> n >> k;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        int x; cin >> x;
        sum += min(x*2, (k-x)*2);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
 
typedef long long ll;
 
#define pb push_back
#define mp make_pair
#define x first
#define y second
 
const int inf=2147483647;
 
ll read()
{
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
 
void print(ll x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]={},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
 
//arc_086 E
const int mod=1e9+7;
 
struct tri{
	int a,b,c;	//分别代表使得当前节点上珠子数为0,1,2+的种数 
	tri(int x,int y,int z){
		a=x;
		b=y;
		c=z;
	}
};
 
int n;
vector<int> adj[222222];
int nums[222222];	//记录某一层中的节点数目
int dep[222222];	//记录顶点的深度
deque<tri> dp[222222];
 
void dfs(int nw){
	nums[dep[nw]]++;
	for(int i=0;i<adj[nw].size();i++){
		int v=adj[nw][i];
		dep[v]=dep[nw]+1;
		dfs(v);
	}
}
 
void solve(int nw){
	for(int i=0;i<adj[nw].size();i++){
		int v=adj[nw][i];
		solve(v);
		if(dp[v].size()>dp[nw].size()) swap(dp[v],dp[nw]);
	}
	
	int mx=0;
	int ansa=0,ansb=0,ansc=0;
	for(int i=0;i<adj[nw].size();i++){
		int v=adj[nw][i];
		mx=max(mx,(int)dp[v].size());
		for(int j=0;j<dp[v].size();j++){
			ansa=(dp[nw][j].a*1ll*dp[v][j].a)%mod;
			ansb=(dp[nw][j].a*1ll*dp[v][j].b+dp[nw][j].b*1ll*dp[v][j].a)%mod;
			ansc=(dp[nw][j].b*1ll*dp[v][j].b+dp[nw][j].c*1ll*(dp[v][j].a+dp[v][j].b))%mod;
			tri t(ansa,ansb,ansc);
			dp[nw][j]=t;
		}
	}
	
	for(int i=0;i<mx;i++){
		dp[nw][i].a+=dp[nw][i].c;
		dp[nw][i].a%=mod;
		dp[nw][i].c=0;
	}
	
	dp[nw].push_front(tri(1,1,0));
}
 
int pw[222222];
void calc(){
	pw[0]=1;
	for(int i=1;i<=200000;i++){
		pw[i]=pw[i-1]*2;
		if(pw[i]>mod) pw[i]-=mod;
	}
}
 
int main(){
	calc();
	n=read();
	for(int i=1;i<=n;i++){
		int x=read();
		adj[x].pb(i);
	}
	
	dfs(0);
	solve(0);
	
	int ans=0;
	for(int i=0;i<dp[0].size();i++){
	//	cout<<dp[0][i].b<<' '<<pw[n+1-nums[i]]<<endl;
		ans+=dp[0][i].b*1ll*pw[n+1-nums[i]]%mod;
		ans%=mod;
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 254584
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int x, n;
    cin >> x >> n;
    vector<int> arr(n, 0);
    for(auto& val: arr)
        cin >> val;
    unordered_set<int> used(arr.begin(), arr.end());
    int diff = 0;
    while(true) {
        if (used.count(x-diff) == 0) {
            cout << x-diff << endl;
            return 0;
        }
        if (used.count(x+diff) == 0) {
            cout << x+diff << endl;
            return 0;
        }
        diff += 1;
    }
    return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define INF 1e15
ll N,A[101010],dp[101010][2];
ll i,j;
int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
    }
    dp[0][0] = A[0];
    dp[0][1] = -INF;
    fornum(i,1,N){
        ll a = dp[i - 1][0] + A[i];
        ll b = dp[i - 1][1] + A[i];
        dp[i][0] = a > b ? a : b;
        a = dp[i - 1][0] - A[i]-A[i-1]*2;
        b = dp[i - 1][1] - A[i]+A[i-1]*2;
        dp[i][1] = a > b ? a : b;
    }
    printf("%lld", dp[N - 1][0] > dp[N - 1][1] ? dp[N - 1][0] : dp[N - 1][1]);

    return 0;
}

Measured memory_bytes: 2560
#include<iostream>

using namespace std;

int main(){
    long a, b;
    while (cin >> a >> b)
    {
        long A = a, B = b;
        while (a != b)
        {
            if (a > b){
                a = a - b;
            }
            else{
                b = b - a;
            }
        }
        long gcd = A / a*B;
        cout << a << " " << gcd << endl;
    }

    return 0;
}

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

int main(void) {
  map<string, int> week {
    {"SUN", 7},
    {"MON", 6},
    {"TUE", 5},
    {"WED", 4},
    {"THU", 3},
    {"FRI", 2},
    {"SAT", 1}
  };

  string s;
  cin >> s;

  cout << week[s] << endl;
 
  return 0;
}

Measured memory_bytes: 256