akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;

const int maxn = 1e5 + 5;

int n, k, a, b, v, p, reqparity[2][maxn];
pii mi[2][maxn], ma[2][maxn];
vector<int> adj[maxn];

void combine(int x, int v)
{
    int takev = (mi[0][v].second == x);
    if(mi[takev][v].first - 1 > mi[0][x].first)
    {
        mi[1][x] = mi[0][x];
        mi[0][x] = {mi[takev][v].first - 1, v};
    }
    else if(mi[takev][v].first - 1 > mi[1][x].first)
        mi[1][x] = {mi[takev][v].first - 1, v};

    if(ma[takev][v].first + 1 < ma[0][x].first)
    {
        ma[1][x] = ma[0][x];
        ma[0][x] = {ma[takev][v].first + 1, v};
    }
    else if(ma[takev][v].first + 1 < ma[1][x].first)
        ma[1][x] = {ma[takev][v].first + 1, v};
}

void up(int x, int p)
{
    for(auto v : adj[x])
        if(v != p)
        {
            up(v, x);
            combine(x, v);
            for(int j = 0; j < 2; j++)
                reqparity[j][x] |= reqparity[j ^ 1][v];
        }
}

void down(int x, int p)
{
    if(p != -1)
    {
        combine(x, p);
        for(int j = 0; j < 2; j++)
            reqparity[j][x] |= reqparity[j ^ 1][p];
    }
    for(auto v : adj[x])
        if(v != p)
            down(v, x);
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 2; j++)
        {
            reqparity[j][i] = 0;
            mi[j][i] = {-2e9, i};
            ma[j][i] = {2e9, i};
        }
    }
    for(int i = 0; i < n - 1; i++)
    {
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    cin >> k;
    for(int i = 0; i < k; i++)
    {
        cin >> v >> p;
        v--;
        reqparity[p & 1][v] = 1;
        mi[0][v] = {p, v};
        ma[0][v] = {p, v};
    }
    up(0, -1);
    down(0, -1);
    int bad = 0;
    for(int i = 0; i < n; i++)
        if((reqparity[0][i] && reqparity[1][i]) || mi[0][i].first > ma[0][i].first)
            bad = 1;
    if(bad)
        cout << "No\n";
    else
    {
        cout << "Yes\n";
        for(int i = 0; i < n; i++)
            cout << mi[0][i].first << "\n";
    }
    return 0;
}

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

struct VRTX {
	int v[101] = {}, dist = -1;
};

int n, curdist = 0;
VRTX u[101];

void breadthFirstSearch(int x, int dist);

int main() {
	int i, j, id, dim;
	
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> id >> dim;
		for (j = 0; j < dim; j++) {
			cin >> u[id].v[j];
		}
	}

	breadthFirstSearch(1, 0);

	for (i = 1; i <= n; i++) {
		cout << i << " " << u[i].dist << endl;
	}

	return 0;
}

void breadthFirstSearch(int x, int dist) {
	int i, nextdist;

	if (u[x].dist == -1)u[x].dist = dist;
	else if (u[x].dist <= dist)return;
	else u[x].dist = dist;
	
	i = 0;
	nextdist = u[x].dist + 1;
	while (u[x].v[i] != 0) {
		breadthFirstSearch(u[x].v[i], nextdist);
		i++;
	}
}

Measured memory_bytes: 3136
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
using namespace std;
int f(int p, int q, int a, int n, int b) {
	int cnt=0;
	if (!p)return 1;
	if (!n || p < 0)return 0;
	for (int i = b; i <= a; i++) {
		cnt += f(p*i - q, q*i, a / i, n - 1, i);
	}
	return cnt;
}
int main(){
	int p, q, a, n;
	while (cin >> p >> q >> a >> n, q) {
		cout << f(p, q, a, n, 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 3040
# https://atcoder.jp/contests/abc127/submissions/5606400

from functools import reduce
from operator import add


def mod_mul(a, b):
    return (a * b) % MOD


def cmb(n, r):
    r = min(r, n - r)
    if r == 0:
        return 1
    if r == 1:
        return n
    f = reduce(mod_mul, range(n - r + 1, n + 1))  # n!/(n-r)!
    d = reduce(mod_mul, range(2, r + 1))  # r!
    return (f * pow(d, MOD - 2, MOD)) % MOD


MOD = 10 ** 9 + 7

N, M, K = map(int, input().split())

ans_x = reduce(add, (i * (M - i) for i in range(M))) * N ** 2
ans_y = reduce(add, (i * (N - i) for i in range(N))) * M ** 2
ans = (ans_x + ans_y) % MOD
pat = cmb(N * M - 2, K - 2)
ans = (ans * pat) % MOD

print(ans)


Measured memory_bytes: 3684
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool comp(int i, int j) {
	return i > j;
}

int main()
{
	int a, b;
	cin >> a >> b;
	if ((a + b) % 2 == 0)
	{
		cout << ((a + b) / 2);
	}
	else
	{
		cout << "IMPOSSIBLE";
	}
}


Measured memory_bytes: 31488
//Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int MOD = 1e9+7,MAX = 1e7+5;
const ll INF = 1e18+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vector<int> MinDiv(MAX);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
    		MinDiv[i]=i;
        	for (j = i * i; j <= MAX; j += i)
            {
				is_prime[j] = false;
				MinDiv[j]=i;
    		}
    	}
	}
	for(int i=2;i<=MAX;i++) if(is_prime[i]) MinDiv[i]=i;
}
//////////////////Sieve////////////////////

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	ll sum=0;
	vl dp(n+1);
	dp[1]=1;
	for(int i=2;i<=n;i++)
	{
		if(is_prime[i])
		{
			dp[i]=2;
		}
		else
		{
			int fki=i;
			int div = MinDiv[i];
			int how=0;
			while(fki%div==0)
			{
				how++;
				fki/=div;
			}
			dp[i] = dp[fki]*(how+1);
		}
	}
	// prin(dp);
	for(int i=1;i<=n;i++)
	{
		sum+=i*dp[i];
	}
	cout<<sum<<endl;
}		

Measured memory_bytes: 121784
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	long long int N, K,dif,ma;
	ma = 10000000000;
	cin >> N >> K;
	vint h(N);
	for (int i = 0; i < N; ++i) cin >> h[i];

	sort(h.begin(), h.end(), greater<int>());

	for (int i = 0; i <= N - K; ++i) {
		dif = h[i] - h[i + K - 1];
	
		ma = min(ma, dif);
	}
	cout << ma << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long dp[200200][2][4];
int vis[200200][2][4];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	const long long inf = 1ll<<60;
	function<long long(int,int,int)> solve = [&](int p, int last, int q){
		if(q > 3) return -inf;
		if(q < 0) return -inf;
		int selec = (p + 1) / 2 - q;
		if(p == n){
			if(selec == (p / 2)) return 0ll;
			return -inf;
		}
		if(vis[p][last][q]) return dp[p][last][q];
		vis[p][last][q] = 1;
		if(last){
			return  dp[p][last][q] = solve(p + 1, 0, (p + 2) / 2 - selec);
		}
		long long ans = solve(p + 1, 0, (p + 2) / 2 - selec);
		ans = max(ans, solve(p + 1, 1, (p + 2) / 2 - selec - 1) + a[p]);
		return dp[p][last][q] = ans;
	};
	cout << solve(0, 0, 0) << endl;
	return 0;
}


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

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

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

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

int main(){
	ll N;
	cin >> N;
	vector<ll> res;
	if(N==3){
		printf("2 5 63\n");
		return 0;
	}else{
		ll a = N/8;
		ll b = N%8;
		vector<ll> tmp = {2, 4, 3, 9, 8, 10, 6, 12};
		REP(i, a){
			ll ki = 12*i;
			REP(j, 8) res.push_back(ki+tmp[j]);
		}
		ll ki = 12*a;
		if(b%2==1){
			res.push_back(ki+6);
			b--;
		}
		REP(j, b) res.push_back(ki+tmp[j]);
	}
	REP(i, res.size()) cout << res[i] << " ";
	cout << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int gcc(int a, int b){
    if(a<b){
        int tmp = a;
        a = b;
        b = tmp;
    }
    int r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main(){
    int a, b, i, j, k;
    int cc[100] = {0};
    scanf("%d %d %d", &a, &b, &k);
    int g = gcc(a, b);
    j = 0;
    if(g==1){
        if(k==1) printf("1");
    }else{
        for(i=g;i>=1;i--){
            if(g % i == 0){
                cc[j] = i;
                j++;
            }
        }
        int x = cc[k-1];
        printf("%d", x);
    }
    return 0;
}

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

int main()
{
    string S, T;

    cin >> S >> T;
    int count = 0;

    for (int i = (int)S.size() - 1; i >= 0; i--) {
        bool flag = true;
        for (int j = 0; j < T.size(); j++) {
            if (S[i + j] != T[j] && S[i + j] != '?' || i + j >= S.size()) {
                flag = false;
                break;
            }
        }
        if (flag) {
            S.replace(i, T.size(), T);
            count++;
            break;
        }
    }

    if (count == 0) {
        S = "UNRESTORABLE";
    }
    else {
        for (int i = 0; i < S.size(); i++) {
            if (S[i] == '?') {
                S[i] = 'a';
            }
        }
    }

    cout << S << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve(){
}
int main(){
    int a, b, k;
    cin >> a >> b >> k;
    int n = gcd(a, b);
    int cnt = 0;
    for(int i = n; i > 0; i--){
        if(n % i == 0){
            cnt++;
        }
        if(cnt == k){
            cout << i << endl;
            break;
        }
    }
    solve();
    return 0;
}



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

using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using namespace std;

int main() {
    int n;
    cin >> n;
    // vector<string> strList(n, "");
    int base    = 97;  // (int)'a': 97
    int alpSize = 26;  // a--z: 26char
    // n*a--zが何回か
    vector<vector<int>> charCntList(n, vector<int>(alpSize, 0));
    rep(i, 0, n) {
        string impstr;
        cin >> impstr;
        for (char c : impstr) {
            charCntList[i][c - base]++;
        }
    }

    // int ans = 0;
    ll ans = 0;
    map<vector<int>, int> dic;
    for (vector<int> val : charCntList) {
        ans += dic[val];
        dic[val]++;
    }

    // std::cout << ans << endl;
    printf("%lld\n", ans);

    return 0;
}


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

using namespace std;

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

    int n, m;
    cin >> n >> m;

    vector<int> h(n+1);
    for(int i=1; i<=n; i++)
        cin >> h[i];

    vector<vector<int> > g(n+1);

    for(int i=0; i<m; i++){
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int ans=0;

    for(int i=1; i<=n; i++){
        int j;
        for(j=0; j<g[i].size(); j++)
            if(h[g[i][j]]>=h[i])
                break;
        if(j==g[i].size())
            ans++;
    }

    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 8732
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int s = S.length();
    Set<Character> set = new HashSet<>();
    for(int i = 0; i < s; i++){
      set.add(S.charAt(i));
    }
    System.out.println(set.size() == s ? "yes" : "no");
  }
}

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

using namespace std;

int main()
{

    int N, M;
    cin >> N >> M;

    vector<int> A;
    double sumA = 0.0;
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        A.push_back(a);
        sumA += a;
    }

    int count = 0;
    for (auto a : A)
    {
        if (a >= (sumA / (4.0 * M)))
            count++;
    }

    if (count < M)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
b = [0]*(N+1)
for i in range(N, 0, -1):
    if sum(b[i::i])%2 != a[i-1]:
        b[i] = 1
print (sum(b))
for i, j in enumerate(b):
    if j == 1:
        print (i)

Measured memory_bytes: 8380
def iskai(tS):
    test = list(tS)
    testr = reversed(test)
    for i, j in zip(test, testr):
        if i != j:
            return False
            break
    else:
        return True
        


S = input()
N = len(S)
if iskai(S) and iskai(S[:(N-1)//2]) and iskai(S[(N + 3) // 2 - 1:]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>


using namespace std;
const int MOD = 1000000009; // check!!!
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

//0-indexed
//       k
//     /   \
// 2k+1     2k+2
// kの親は (k-1)/2
// //calc に、動作を変更するべきソースが書いてある
class seg_tree{

public:

	vector<Pll> dat;
	int n;

	void init(int* d,int size){

		n = 1;
		while(n < size) n <<= 1;

		dat.resize(2 * n - 1);
		fill(dat.begin(),dat.end(),Pll(-1,-(1LL<<60)));

		FOR(i,size) dat[n-1+i].first = i;
		FOR(i,size) dat[n-1+i].second = d[i];

		for(int i = n / 2; i > 0; i /= 2){
			for(int s = i - 1; s <= 2 * (i - 1); s++){
				dat[s].first = dat[s * 2 + 1].second >= dat[s * 2 + 2].second ? dat[s*2+1].first : dat[s*2+2].first;
				dat[s].second = max(dat[s * 2 + 1].second,dat[s * 2 + 2].second); //calc
			}
		}
	}

	//k番目(0-indexed)をvalに更新
	void update(int k,int val){
		k += n-1;
		dat[k].second += val;
		while(k > 0){
			k = (k-1)/2;
			dat[k].first = dat[k*2+1].second >= dat[k*2+2].second ? dat[k*2+1].first : dat[k*2+2].first;
			dat[k].second = max(dat[k*2+1].second,dat[k*2+2].second); //calc
		}
	}

	//[a,b)において求めたい値を得る
	Pll query(int a,int b)
	{
		return query(a,b,0,0,n);
	}

	//[a,b)において求めたい値を得る
	// k = 現在見ている接点の番号
	// [l,r)はkに対応した範囲
	Pll query(int a,int b,int k,int l,int r)
	{
		if(r <= a || b <= l) return Pll(-1,-(1LL<<60)); //範囲外
		if(a <= l && r <= b) return dat[k]; //[l,r) ⊂ [a,b)

		//[l,r)の一部が[a,b)に含まれる
		int md = (l + r) / 2; //[l,md),[md,r)
		int nl = k * 2 + 1,nr = nl + 1; //子の接点
		Pll lval = query(a,b,nl,l , md);
		Pll rval = query(a,b,nr,md , r);

		ll retl = lval.second >= rval.second ? lval.first : rval.first;
		ll retr = max(lval.second,rval.second);

		return Pll(retl,retr); //calc
	}
};


int main(){

	int n,q; cin>>n>>q;

	seg_tree st;
	static int a[1000000] = {};
	st.init(a,n);

	FOR(i,q){
		int a,v; cin>>a>>v;
		a--;
		st.update(a,v);
		Pll ans = st.dat[0];
		printf("%lld %lld\n",ans.first + 1,ans.second);
	}

	return 0;
}

Measured memory_bytes: 33884
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
	int N, D;
	cin >> N >> D;
	vector<vector<int > > x(N, vector<int>(D));
	
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < D; ++j) {
			cin >> x[i][j];
		}
	}
	
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = i+1; j < N; ++j) {
			int norm = 0; 
			for (int k = 0; k < D; ++k) {
				int diff = abs(x[i][k] - x[j][k]);
				norm += diff * diff;
			}
			
			bool flag = false;
			for (int k = 0; k <= norm; ++k) {
				if (k * k == norm) {
					flag = true;
				}
			}
			
			if (flag) ++ans;
		}
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)



int main(){

string s;
cin>>s;


deque<char> yy;
ll Q;
cin>>Q;


ll ff=0;
for(ll i=0;i<s.size();i++){
yy.push_back(s[i]);
}
for(ll i=0;i<Q;i++){
    ll tmp,tmp1;
    char c;
    cin>>tmp;
    if(tmp==2){
        cin>>tmp1>>c;
        if(tmp1==2){
            if(ff==0)
            yy.push_back(c);
            else
             yy.push_front(c);
        }
        else{
            if(ff==0)
               yy.push_front(c);
            else
             yy.push_back(c);
        }
    }
    else{
        if(ff==0)
        ff=1;
        else
        {
            ff=0;
        }
        
    }
   
}
if(ff==1){
    reverse(ALL(yy));
}
while(!yy.empty()){
    cout<<yy.front();
    yy.pop_front();
}

}


Measured memory_bytes: 896
#include <iostream>

#define ll long long

using namespace std;

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

long long norm(long long d){ 
return ((d%MOD)+MOD)%MOD;}

long long Madd (long long x, long long y){
return norm(norm(x) + norm(y));}

long long Msub (long long x, long long y){
return norm(norm(x) - norm(y));}

long long Mmul (long long x, long long y){
return norm(norm(x) * norm(y));}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    ll anw = 0;
    cin >> n;

    long long stores[sizes] = {0}, prefix_sum[sizes] = {0};

    for (int i = 1; i <= n; i++)
    {
        cin >> stores[i];
        prefix_sum[i] = Madd(stores[i], prefix_sum[i-1]);
    }

    for (int i = 1; i <= n - 1; i++)
    {
        anw = Madd(anw, Mmul(stores[i], prefix_sum[n] - prefix_sum[i]));
    }
    cout << anw << "\n";
}

Measured memory_bytes: 6312
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func sums(i int) int {
	total := 0
	for i != 0 {
		total += i % 10
		i /= 10
	}
	return total
}

func main() {
	sc := NewScanner()
	N, A, B := sc.nextInt(), sc.nextInt(), sc.nextInt()
	ans := 0
	for i := 1; i <= N; i++ {
		total := sums(i)
		if A <= total && total <= B {
			ans += i
		}
	}
	fmt.Println(ans)
}


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

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(V) sort((V).begin(),(V).end())
#define pb push_back
#define endl '\n'
#define int long long

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

// 変数定義
int n,m;
//

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  vector<int> p(m);
  vector<string> s(m);
  vector<bool> flg(n, false);
  vector<int> pena(n, 0);
  int ac = 0, pena_sum = 0;
  REP(i, m) {
    cin >> p[i] >> s[i];
  }
  REP(i, m) {
    if(s[i] == "WA" && flg[p[i]-1] == false) {
      pena[p[i]-1]++;
    } else if (s[i] == "AC" && flg[p[i]-1] == false) {
      ac++;
      flg[p[i]-1] = true;
      pena_sum += pena[p[i]-1];
    }
  }
  cout << ac << " " << pena_sum << endl;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
unordered_map<int,bool> um;
int main(){
	int n,tmp;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&tmp);
		if(um[tmp]){
			printf("NO");
			return 0;
		}
		else um[tmp]=1;
	}
	printf("YES");
	return 0;
}

Measured memory_bytes: 8520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;

int a, b, c;

ll solve(ll a, ll b, ll c){
    if(a%2==0 || b%2==0 || c%2==0) return 0;
    return min({a*b, b*c, c*a});
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>a>>b>>c;
    cout<<solve(a,b,c);
    return 0;
}

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

int main() {
  long long a,b,c;
  cin>>a>>b>>c;
  if(a%(b+c)<=b)cout<<a/(b+c)*b+a%(b+c)<<endl;
  else cout<<a/(b+c)*b+b<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
 
 
 
int main(){
 
    int H,W;
    scanf("%d %d",&H,&W);
 
    int table[H][W];
 
    for(int row = 0; row < H; row++){
        for(int col = 0; col < W; col++)scanf("%d",&table[row][col]);
    }
 
    int ans = BIG_NUM,tmp_sum;
 
    for(int tate = 0; tate < H; tate++){
        for(int yoko = 0; yoko < W; yoko++){
            tmp_sum = 0;
            for(int row = 0; row < H; row++){
                for(int col = 0; col < W; col++){
                    tmp_sum += table[row][col]*min(abs(row-tate),abs(col-yoko));
                }
            }
            ans = min(ans,tmp_sum);
        }
    }
 
    printf("%d\n",ans);
 
    return 0;
}


Measured memory_bytes: 3240
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main() {
	int N, L;
	cin >> N>>L;
	string S[100];
	rep(i, N) cin >> S[i];

	sort(S, S + N);
	rep(i, N) cout << S[i];
}

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

int main() {
  int n, m; cin >> n >> m;
  int sum_day = 0;
  for(int i = 0; i < m; i++) {
    int a; cin >> a;
    sum_day += a;
  }
  if(n - sum_day >= 0) cout << n - sum_day << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 3636
b='b'
d='d'
p='p'
q='q'
m=[(b,d),(p,q),(d,b),(q,p)]
ans='Yes'
s=input()
if len(s)%2==1:
    ans='No'
else:
    A=s[:len(s)//2]
    B=s[len(s)//2:]
    B=B[::-1]
    for i in range(len(s)//2):
        if (A[i],B[i]) in m:
            continue
        else:
            ans='No'
print(ans)


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

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] student = new int[N];

        for (int i = 1; i < N+1; i++)
            student[scanner.nextInt() - 1] = i;
        for (int i = 0; i < N; i++)
            System.out.print(student[i] + " ");
    }
}


Measured memory_bytes: 58304
n=[int(_) for _ in list(input())]
l=len(n)
if l==1:
    print(n[0])
elif n[0]!=9:
    if len(set(n[1:]))==1 and n[1]==9:
        print(n[0]+9*(l-1))
    else:
        print(n[0]-1+9*(l-1))
else:
    if len(set(n))==1:
        print(9*l)
    else:
        print(9*(l-1)+8)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;

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

bool ng[16][16][16][16];
long long dp[16][16];

void solve() {
  int X, Y; cin >> X >> Y;
  memset(ng, 0, sizeof(ng));
  memset(dp, 0, sizeof(dp));
  int P; cin >> P;
  REP(p, P) {
      int x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      ng[x1][y1][x2][y2] = true;
      ng[x2][y2][x1][y1] = true;
  }
  dp[0][0] = 1;
  for (int x = 0; x <= X; x++)
      for (int y = 0; y <= Y; y++) {
          if (x - 1 >= 0 && !ng[x][y][x - 1][y])
              dp[x][y] += dp[x - 1][y];
          if (y - 1 >= 0 && !ng[x][y][x][y - 1])
              dp[x][y] += dp[x][y - 1];
      }

  if (dp[X][Y] == 0)
      cout << "Miserable Hokusai!" << endl;
  else
      cout << dp[X][Y] << endl;
}

int main() {
  int T; cin >> T;
  for (;T--;) solve();
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define mod 1000000007


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }
    
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
    
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};



int gcd(int a, int b){
    while(b){
        int t = a;
        a = b;
        b = t%b;
    }
    return a;
}

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


vector<ll> S;
vector<ll> P;

ll solve(ll i, ll k){
//    cout << i << " " << k << endl;
    if(i==0){
        if(k==0) return 0;
        else return 1;
    }
    else if(k==1){
        if(i==0) return 1;
        else return 0;
    }
    else if(k<S[i-1]+2) return solve(i-1, k-1);
    else if(k==S[i-1]+2) return P[i-1] + 1;
    else if(k<=2 * S[i-1]+2) return P[i-1] + 1 + solve(i-1, k - S[i-1] - 2);
    return 2 * P[i-1] + 1;
}


int main() {
    ll N, K; cin >> N >> K;
    S.resize(N+1);
    P.resize(N+1);
    S[0] = 1;
    P[0] = 1;
    for(int i=0; i<N; i++){
        S[i+1] = 2 * S[i] + 3;
    }
    
    for(int i=0; i<N; i++){
        P[i+1] = 2 * P[i] + 1;
    }

    
    cout << solve(N, K) << endl;
    return 0;
}


Measured memory_bytes: 256
/**
 * @author torith
 * @date 2019-02-03
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

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

    double T; cin >> T;
    double X; cin >> X;

    cout << T/X << "\n";

    return 0;
}



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

int main()
{

	int n;
	//s 0 h 1 c 2 d 3
	bool card[4][53];
	cin >> n;
	char str;
	int number;
	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 13; j++)
		{
			card[i][j] = false;
		}
	}
	for (int i = 0; i < n; i++)
	{
		cin >> str >> number;
		if (str == 'S')
		{
			card[0][number-1] = true;
		}
		else if (str == 'H')
		{
			card[1][number-1] = true;
		}
		else if (str == 'C')
		{
			card[2][number-1] = true;

		}
		else if (str == 'D')
		{
			card[3][number-1] = true;
		}
	}
	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 13; j++)
		{
			if (card[i][j] == false)
			{
				if (i == 0)
				{
					cout << "S" << " " << j+1 << endl;
				}
				else if (i == 1)
				{
					cout << "H" << " " << j+1 << endl;
				}
				else if (i == 2)
				{
					cout << "C" << " " << j+1 << endl;
				}
				else if (i == 3)
				{
					cout << "D" << " " << j+1 << endl;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3068
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)

ans = 0
loop do
  count = 0
  n.times do |i|
    if a[i]%2 == 0
      a[i] /= 2
      count += 1
    end
  end
  break if count != n
  ans += 1
end

puts ans

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

using namespace std;

using ll=long long;

#define K 6 
#define rep(i) for(int i=0;i<K;i++)
using Token=array<int,K>;

//const ll R = 843823891, iR = 1040004855;
const ll R[K] = {3213,24289,34299,929923,438,42};
const ll iR[K] = {727200786, 1395409909, 1110851529, 35704193, 1005586100, 1598363886};

const ll M = 1637348371;
ll mpow(ll x, int64_t e) {
    ll res = 1;
    for (; e; e >>= 1) {
        if (e & 1) res *= x, res %= M;
        x *= x, x %= M;
    }
    return res;
}
ll minv(ll x) {
    return mpow(x, M-2);
}

struct Lm {
    ll k,b;
    Lm() {}
    Lm(ll _k,ll _b): k(_k),b(_b){}
    Lm(char x, int i) {
        if (x == '+') k = 1, b = 1;
        if (x == '-') k = 1, b = M-1;
        if (x == '>') k = R[i], b = 0;
        if (x == '<') k = iR[i],b = 0;
    }
    Lm(const Lm& _lm): k(_lm.k), b(_lm.b){}
    Lm& operator*=(const Lm& _lm){
        b += k*_lm.b%M; b %= M;
        k *= _lm.k; k %= M;
        return *this;
    }
    Lm inv(){
        ll ik = minv(k);
        ll ib = -ik*b; ib %= M; (ib+=M)%=M;
        return {ik,ib};
    }
    ll eval(ll x) {
        return (k*x%M+b)%M;
    }
};
Lm operator*(const Lm& _a, const Lm& _b) {
    return Lm(_a) *= _b;
}
void solve() {
    int n; cin >> n;
    string s; cin >> s;
    vector<Lm> a[6], ia[6];
    vector<Token> z(n+1), g(n);
    rep(k) {
    for (int i = 0; i < n; i++) {
        a[k].emplace_back(s[i], k);
        ia[k].emplace_back(a[k][i].inv());
    }
    auto isuf = ia;
    for (int i = n-2; i >= 0; i--) {
        isuf[k][i] = isuf[k][i+1] * isuf[k][i];
    }
    ll c = isuf[k][0].inv().eval(0);
    z[n][k] = 0;
    for (int i = 0; i < n; i++) {
        z[i][k] = isuf[k][i].eval(0);
        g[i][k] = isuf[k][i].eval(c);
    }
    }
    map<Token, int> cnt;
    ll res = 0;
    for (int i = 0; i < n; i++) {
        cnt[g[i]]++;
        res += cnt[z[i+1]];
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 98240
#include <stdio.h>
#include <stdlib.h>

#define SIZE 2000000

int main() {
  int A[SIZE];
  int H=0;
  int i, l, largest, tmp;
  char com[21];
  do {
    fgets(com, 20, stdin);
    if (com[0] == 'i') {
      A[++H] = atoi(com+7);
      for (i=H; i>1 && A[i/2]<A[i];i/=2) {
        tmp = A[i/2];
        A[i/2] = A[i];
        A[i] = tmp;
      }

    } else if (com[1]=='x') { // extract
      printf("%d\n", A[1]);
      A[1] = A[H];
      i = 1;
      while (1) {
        l = i*2;
        largest = i;
        if (l < H && A[l] > A[i])        largest = l;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      }
      H--;
    }
  } while (com[2]!='d');
  return 0;
}


Measured memory_bytes: 5612
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<ll,ll> P;
const int INF=100100100;
const double PI=3.141592653589;


int main(){
  int n; cin>>n;
  vector<P> p(n);
  rep(i,n){
    ll a,b; cin>>a>>b;
    p[i]={b,a};
  }
  sort(p.begin(),p.end());

  ll sa=0;
  ll sb=0;
  bool ans=1;
  rep(i,n){
    sa+=p[i].second;
    sb=p[i].first;
    if(sa>sb){
      ans=0;
      break;
    }
  }
  cout<<(ans?"Yes":"No")<<endl;

  return 0;
}


Measured memory_bytes: 3328
#include <iostream>

using namespace std;

int main()
{
    char d[] = {
        'U', 'R', 'D', 'L', 'L', 'U', 'R', 'D', 'R', 'D', 'L', 'U', // tx > sx && ty > sy
    };
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    int c1 = ty - sy;
    int c2 = tx - sx;
    cout << string(c1, d[0]) << string(c2, d[1]);
    cout << string(c1, d[2]) << string (c2, d[3]);
    cout << d[4] << string(c1+1, d[5]) << string(c2+1, d[6]) << d[7];
    cout << d[8] << string(c1+1, d[9]) << string(c2+1, d[10]) << d[11];
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
cnt = 0

for i in range(max(h)):
    st = 1 if h[0] != 0 else 0
    for j in range(n):
        if st == 1:
            if h[j] == 0:
                cnt += 1
                st = 0
            else:
                h[j] -= 1
        else:
            if h[j] != 0:
                st = 1
                h[j] -= 1
    else:
        if st == 1:
            cnt += 1
else:
    ans = cnt

print(ans)
    

Measured memory_bytes: 3064
import std.stdio;
import std.string;
import std.conv;
import std.array;

void main()
{
    int N = readln.chomp.to!int;
    auto buf = readln.split;
    int A = buf[0].to!int;
    int B = buf[1].to!int;
    int[] P = readln.split.to!(int[]);

    int[] cnt = [0, 0, 0];
    foreach (i; 0..N){
        if (P[i] <= A){
            cnt[0]++;
        }
        else if (P[i] <= B){
            cnt[1]++;
        }
        else {
            cnt[2]++;
        }
    }

    int min_cnt = cnt[0];
    foreach (i; 1..3){
        if (cnt[i] < min_cnt) min_cnt = cnt[i];
    }

    writeln(min_cnt);
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(1){}else
#define drep(i,n)    if(1){}else
#define dstop()      if(1){}else
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];

//#define int long long;
#ifndef int
#define INF (0x7fffffff)
#else
#define INF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  ll i;
  in(ll,k);
  if(k==0)
    {
      printf("4\n3 3 3 3\n");
      return 0;
    }
  if(k==1)
    {
      cout<<2<<endl;
      cout<<2<<" "<<0<<endl;
      return 0;
    }
  if(k<50)
    {
      cout<<k<<endl;
      for(i=0;i<k;i++)
	cout<<i+1<<" ";
      cout<<endl;
      return 0;
    }
  ll ama=k%50;
  ll sho=k/50;
  ll base=50-ama;
  ll a[50]={};
  rep(i,50)
    {
      ll sum=(i>=base);//base+i+1;
      //if(sum>49)sum-=51;
      a[i]=sum+sho+i;
    }

  cout<<50<<endl;
  rep(i,50)
    cout<<a[i]<<" ";
  cout<<endl;  

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int ddx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};

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

int extgcd(int a, int b, int& x, int&y) {
    int d = a;
    if(b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else {
        x = 1;
        y = 0;
    }
    return d;
}

int inv(int a) {
    int x, y;
    extgcd(a, MOD, x, y);
    return (x + MOD) % MOD;
}

struct UniTree {
    int *par, *rank, *sz;

    UniTree(int n) {
        par = new int[n];
        rank = new int[n];
        sz = new int[n];
        for(int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }

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

    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(rank[x] < rank[y]) {
            par[x] = y;
            sz[y] += sz[x];
        }else {
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
            sz[x] += sz[y];
        }
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int siz(int x) {
        return sz[root(x)];
    }
};

double bin(double left, double right) {
    return 0;
}

int main() {
    int n;
    cin >> n;
    int *l = new int[n];
    rep(i, n) cin >> l[i];
    sort(l, l + n);
    ll res = 0;
    rep(i, n - 2) {
        for(int j = i + 1; j < n - 1; j++) {
            int x = upper_bound(l + j + 1, l + n, abs(l[i] - l[j])) - l;
            int y = lower_bound(l + j + 1, l + n, l[i] + l[j]) - l;
            int ans = y - x;
            res += ans;
        }
    }
    cout << res << endl;
}


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

const int V = 100;

int main(){

  for(int n,w;cin>>n>>w,n;){
    vector<int> cnt(V/w+1, 0);

    int height = -1;
    for(int i=0;i<n;++i){
      int tmp;
      cin >> tmp;
      cnt[tmp/w]++; 
    }

    for(int i=0;i<cnt.size();++i){
      height = max(height, cnt[i]); 
     // cout << cnt[i] << endl;
    }

    while(true){
      if(cnt[cnt.size()-1]==0) cnt.erase(cnt.end()-1);
      else break;
    }

    double ans = 0.0;
    for(int i=0;i<cnt.size();++i){
      ans += ((double)(cnt.size()-1-i)/(double)(cnt.size()-1)) * ((double)cnt[i]/(double)height);
    }

    ans += 0.01;

    cout << fixed << setprecision(6) << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1260
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int t[] = new int[N];
		for(int i=0;i<N;i++) t[i] = sc.nextInt();
		int sum = 0;
		int currentTime = t[0];
		int forTime = currentTime + T;
		for(int i=1;i<N;i++){
			if(t[i]<forTime){
				sum += t[i] - currentTime;
				currentTime = t[i];
				forTime = currentTime + T;
			} else {
				sum += forTime - currentTime;
				currentTime = t[i];
				forTime = currentTime + T;
			}
		}
		sum += forTime - t[N-1];
		System.out.println(sum);
	}

}


Measured memory_bytes: 63248
#include <iostream>
#include <map>

int main(void) {
    int n, N;
    int i, num_item = 0;
    std::string s;
    std::map<std::string, int> item;
    
    std::cin >> N;
    
    for(n = 0; n < N; n++) {
        std::cin >> s;
        item[s] = 1;
    }
    
    std::cout << item.size() << std::endl;
    
    return 0;
}

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

int main(int argc, char *argv[])
{
    std::string s;
    std::cin >> s;

    std::vector<std::string> v;

    for (int i = 0; i < s.size() - 2; i++) {
        v.push_back(s.substr(i, 3));
    }

    int v_min = 1000000;

    for (int i = 0; i < v.size(); i++) {
        int value = std::abs(std::stoi(v[i]) - 753);
        if (value < v_min){
            v_min = value; 
        }
    }

    std::cout << v_min << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll  long long
#define ull unsigned long long  
using namespace std;
#define  inf 1e15+18
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mod 1000000007
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const int maxn=40000;
#define  pq priority_queue
#define  ff first
#define  ss second 
#define pb  push_back
#define lb lower_bound
int  dp[22][(1<<21)+2];
int a[22][22],n;
ll solve(ll id,ll mask)
{
	if(id==n&&mask==(1<<n)-1)
		return 1;
	if(id==n)
		return 0;
	if(dp[id][mask]!=-1)
		return dp[id][mask];
ll ans=0;
	for(int i=0;i<n;i++)
	{
		if(a[id][i]==1&&(mask&(1<<i))==0)
		{
			ans=(ans+solve(id+1,mask|1<<i))%mod;
		}
	}
  dp[id][mask]=ans;

	return ans;
}
int main()
{
	memset(dp,-1,sizeof(dp));
	ll i,j;
	cin>>n;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++)
			cin>>a[i][j];
	}
	cout<<solve(0,0);
	//cout<<l;
}

Measured memory_bytes: 183844
#include <iostream>
using namespace std;
int main()
{
  int N, A;
  cin >> N;
  for(int i = 0; i < N; i++)
  {
    cin >> A;
    if(A % 2 == 0)
    {
      if(!(A % 3 == 0 || A % 5 == 0))
      {
        cout << "DENIED";
        return 0;
      }
    }
  }
  cout << "APPROVED";
  return 0;
}

Measured memory_bytes: 256
/*
 * atcoder/abc130/a.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int a, b;

void input() {
  cin >> a >> b;
}

void solve() {
  int max_ = 0;
  chmax(max_, a + b);
  chmax(max_, a + (a-1));
  chmax(max_, b + (b-1));
  cout << max_ << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}


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

int main(){
char t,tt,bouru = 'A';

while(scanf("%c,%c",&t,&tt) != EOF){
if(bouru == t) {bouru = tt;continue;}
if(bouru == tt) {bouru = t;continue;}
}
printf("%c\n",bouru);
return 0;
}

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


int n, m;
int a[10000];


int main(){
  cin >> n >> m;
  int sum = 0;
  for (int i = 0; i < m; i++){
      cin >> a[i];
      sum += a[i];
  }
  if (sum <= n) cout << n-sum << endl;
  else cout << -1 << endl;


}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  ll d = b - a;
  ll ans;
  if(d % 2 == 0){
    ans = d/2;
  }else{
    ll an1 = a - 1;
    an1 += ((b-an1) - 1)/2 + 1;
    ll an2 = n - b;
    an2 += (n - (a+an2))/2 + 1;
    // cerr << an1 << " " << an2 << endl;
    ans = min(an1, an2);
  }
  cout << ans << endl;
  return 0;
}

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

#define SZ(v) (int)v.size()
#define endl "\n"
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 1e9;
const LL INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

void solve() {
    string s, t;
    cin >>s >> t;
    int ans = 0;
    for (int i =0; i < s.size(); i++) if (s[i] != t[i]) ans++;
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    //cin >> t;
    for (int tc = 1; tc <= t; tc++) solve();
    return 0;
}





Measured memory_bytes: 3808
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

bool check(int num, const vector<bool>& d) {
  while (num > 0) {
    int i = num % 10;
    if (!d[i])
      return false;
    num /= 10;
  }
  return true;
}

int main() {
  int n, k;
  vector<bool> d(10, true);
  cin >> n >> k;
  REP(i, k) {
    int idx;
    cin >> idx;
    d[idx] = false;
  }
  for (int i = n; i <= n * 10; ++i) {
    if (check(i, d)) {
      cout << i << endl;
      break;
    }
  }
}


Measured memory_bytes: 256