akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main() {
	int n, k, d, a, b[999], i, j;
	for (i = 0; i < 999; i++) {
		b[i] = 0;
	}
	cin >> n; cin >> k;
	for (i = 0; i < k; i++) {
		cin >> d;
		for (j = 0; j < d; j++) {
			cin >> a;
			if (b[a] == 0) { b[a] = 1; n--; }
		}
	}
	cout << n;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
#include<math.h>

int main()
{
    int sx,sy,tx,ty;
    scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
    int i,j;
    for(i=sx;i<tx;i++)printf("R");
    for(i=sy;i<ty;i++)printf("U");
    for(i=sx;i<tx;i++)printf("L");
    for(i=sy;i<ty;i++)printf("D");
    printf("D");
    for(i=sx;i<tx+1;i++)printf("R");
    for(i=sy;i<ty+1;i++)printf("U");
    printf("LU");
    for(i=sx;i<tx+1;i++)printf("L");
    for(i=sy;i<ty+1;i++)printf("D");
    printf("R\n");
    return 0;
}


Measured memory_bytes: 128
n,m,x = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
ans = 10**9 
for i in range(2 ** n):
  skill = [0] * m
  overTen = False
  money = 0
  for j in range(n):
    if ((int(bin(i)[2:]) >> j) & 1):
      money += a[j][0]
      for h in range(m):
        skill[h] += a[j][h+1]
  for k in skill:
    if k >= x:
      overTen = True
    else:
      overTen = False
      break
  if overTen == True:
    if money < ans:
      ans = money

if ans == 10**9:
  ans = -1
print(ans)

Measured memory_bytes: 9100
#include <iostream>
#include <cfloat>
#include <cmath>
using namespace std;

int n;
int c[15], d[15], w[15], r[15];
pair<double, int> dp[1<<15][15];
int wdp[1<<15];


int main() {
  int p, q;
  double t;
  cin >> n;
  for (int i=0; i<n; i++) {
    cin >> c[i] >> d[i] >> w[i];
    w[i] *= 20;
  }
  for (int i=0; i<(1<<n); i++) {
    wdp[i] = 0.0;
  }
  for (int i=0; i<(1<<n); i++) {
    for (int j=0; j<n; j++) {
      if (i & (1<<j)) {
        wdp[i] += w[j];
      }
    }
  }

  for (int i=0; i<(1<<n); i++) {
    for (int j=0; j<n; j++) {
      dp[i][j].first = DBL_MAX;
      dp[i][j].second = -1;
    }
  }
  for (int i=0; i<n; i++) {
    dp[1<<i][i].first = 0.0;
    dp[1<<i][i].second = -1;
  }
  for (int i=1; i<(1<<n); i++) {
    for (int j=0; j<n; j++) {
      if (~i & (1<<j)) continue;
      for (int k=0; k<n; k++) {
        if (i & (1<<k)) continue;
        t = dp[i][j].first + abs(d[k]-d[j])*(70 + wdp[i])/2000.0;
        if (dp[i|(1<<k)][k].first > t) { 
          dp[i|(1<<k)][k].first = t;
          dp[i|(1<<k)][k].second = j;
        }
      }
    }
  }
  p = -1;
  q = (1<<n)-1;
  t = DBL_MAX;
  for (int i=0; i<n; i++) {
    if (t > dp[q][i].first) {
      t = dp[q][i].first;
      p = i;
    }
  }
  for (int i=n-1; i>=0; i--) {
    r[i] = p;
    p = dp[q][p].second;
    q &= ~(1<<r[i]);
  }

  for (int i=0; i<n; i++) {
    if (i) cout << " ";
    cout << c[r[i]];
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 8968
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    for(int i = 0; i <= 25; i++) {
        for(int j = 0; j <= 25; j++) {
            if(i * 4 + j * 7 == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0);
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
	ll r=1;
	a=a%m;
	while(b>0)
	{
	if(b&1)
		r=(r*a)%m;
	b=b/2;
	a=(a*a)%m;
	}
	return r%m;
}



int main() {
    ll n; cin>>n;
    vi arr(n);
    rep(i,0,n)cin>>arr[i];
    sort(arr.rbegin(),arr.rend());
    //for(auto x:arr)cout<<x<<" ";
    //cout<<endl;
    ll sum = 0;
    for(ll i=0;i<n;i++)
    {
        for(ll j = i +1;j<n;j++)
        {
            ll l = j+1,r = n-1;
            ll ans = -1;
            while(l<=r)
            {
                ll mid  = l + (r-l)/2;
                if(arr[i]<arr[j]+arr[mid])
                {
                    ans = mid;
                    l = mid+1;
                }
                else
                {
                    r = mid - 1;
                }
            }
            //cout<<i<<" "<<j<<" "<<ans<<endl;
            if(ans!=-1)
            {
                sum+=(ans-j);
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


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

int main()
{
	long lnTime1;
	long lnTime2;
	cin >> lnTime1;
	cin >> lnTime2;

	long lnStart = lnTime1 + lnTime2;
	if (lnStart > 23)
		lnStart = lnStart-24;

	cout << lnStart;

	return 0;
}

Measured memory_bytes: 256
/** Which of the favors of your Lord will you deny ? **/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define F first
#define S second

#define ALL(x)      (x).begin(), (x).end()
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#ifndef ONLINE_JUDGE
#define DBG(x)      cout << __LINE__ << " says: " << #x << " = " << (x) << endl
#else
#define DBG(x)
#define endl "\n"
#endif

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;

void solveTC()
{
    int x;
    cin>>x;
    if(x==0) cout<<1<<endl;
    if(x==1) cout<<0<<endl;
}

int32_t main()
{
    optimizeIO();

    int tc = 1;

    while(tc--)
    {
        solveTC();
    }

    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}


Measured memory_bytes: 3660
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll i) {
	ll sum = 1;
	for (ll j = 2; j <= i; j++)
		sum = (sum* j) % Mod;
	return sum;
}//階乗(正）
#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int n, q, s, t, l, r, x;
int a[200000], b[200000];
int ans;
void solve(int o) {
	if (b[o] < 0) {
		if (x < 0)
			ans -= t*x;
		else {
			if (b[o] + x > 0) {
				ans += t*b[o];
				ans -= (b[o] + x)*s;
			}
			else
				ans -= t*x;
		}
	}
	else {
		if (x < 0) {
			if (b[o] + x > 0)
				ans -= s*x;
			else {
				ans += b[o] * s;
				ans += abs(b[o] + x)*t;
			}
		}
		else
			ans -= s*x;
	}
	b[o] += x;
}
signed main() {
	cin >> n >> q >> s >> t;
	n++;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 1; i++)
		b[i] = a[i + 1] - a[i];
	for (int i = 0; i < n - 1; i++) {
		if (b[i] > 0) ans -= s*b[i];
		else ans += t*abs(b[i]);
	}
	for (int i = 0; i < q; i++) {
		cin >> l >> r >> x;
		solve(l - 1);
		x *= -1;
		if (r != n-1)
			solve(r);
		cout << ans << endl;
	}
	getchar(); getchar();
}


Measured memory_bytes: 6252
import java.util.*;
import java.util.function.IntConsumer;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long X = sc.nextLong();
        double balance = 100;
        int i = 0;
        while(balance < X) {
            balance = Math.floor(balance + balance*0.01);
            i++;
        }
		System.out.println(i);
	}
}

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

int main() {
  int N1, N2, N3, N4;
  cin >> N1 >> N2 >> N3 >> N4;
  int one, nine, seven, four;
  
  if ( N1 == 1 ) one++;
  else if ( N2 == 1 ) one++;
  else if ( N3 == 1 ) one++;
  else if ( N4 == 1 ) one++;
  
  if ( N1 == 9 ) nine++;
  else if ( N2 == 9 ) nine++;
  else if ( N3 == 9 ) nine++;
  else if ( N4 == 9 ) nine++;
  
  if ( N1 == 7 ) seven++;
  else if ( N2 == 7 ) seven++;
  else if ( N3 == 7 ) seven++;
  else if ( N4 == 7 ) seven++;
  
  if ( N1 == 4 ) four++;
  else if ( N2 == 4 ) four++;
  else if ( N3 == 4 ) four++;
  else if ( N4 == 4 ) four++;
  
  if ( one == 1 && nine == 1 && seven == 1 && four == 1 ) {
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int, int>P;
typedef pair<string, pair<int, int>>PP;
typedef long long ll;

int main() {
	int n;
	cin >> n;
	PP sp[110];
	for (int i = 0; i < n; i++) {
		cin >> sp[i].first >> sp[i].second.first;
		sp[i].second.second = i + 1;
	}
	vector<P> t[110];
	sort(sp, sp + n);
	int index = 0;
	t[index].push_back(P(sp[0].second.first,sp[0].second.second));
	for (int i = 1; i < n; i++) {
			if (sp[i].first != sp[i - 1].first) {
				index++;
			}
			t[index].push_back(P(sp[i].second.first, sp[i].second.second));
	}
	for (int i = 0; i < n; i++) {
		sort(t[i].begin(), t[i].end(), greater<P>());
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < t[i].size(); j++) {
			cout << t[i][j].second << endl;
		}
	}
	return 0;
}

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

using namespace std;

#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second

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

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

vector<vector<char>> grid;
map<pii, bool> visited;

ll dott, hashh;

void dfs(pii v) {
    visited[v] = true;
    if (grid[v.ff][v.ss] == '.') dott++;
    else hashh++;
    for (int i = 0; i < 4; ++i) {
        pii u = mp(v.ff + dx[i], v.ss + dy[i]);
        if (!visited[u] && grid[u.ff][u.ss] == (grid[v.ff][v.ss] == '#' ? '.' : '#')) {
            dfs(u);
        }
    }
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<pii> srcs;
    visited.clear();
    grid = vector<vector<char>>(h + 2, vector<char>(w + 2, '-'));
    for (int i = 1; i <= h; ++i) {
        string str;
        cin >> str;
        for (int j = 1; j <= w; ++j) {
            grid[i][j] = str[j - 1];
            if (str[j - 1] == '.') srcs.eb(mp(i, j));
        }
    }
    ll ans = 0;
    for (pii src : srcs) {
        if (visited[src]) continue;
        dott = 0;
        hashh = 0;
        dfs(src);
        ans += dott * hashh;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 28536
N,M,C = map(int, input().split())
B = list(input().split())
data = [input().split() for i in range(N)]

con = 0

for x in range(N):
    num = C
    for xx in range(M):
        num += int(data[x][xx])*int(B[xx])
    if(num > 0):
        con += 1
print(con)

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

#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define rep(i, n) for(i = 0; i < n; i++)

int main(){
    ll N;
    ll i;
    ll A;
    map<ll, ll> count;
    cin >> N;
    rep(i, N){
        cin >> A;
        if (count.find(A) == count.end()) {
            count[A] = 1;
        } else {
            count[A]++;
        }
    }

    if (count.size() == 1 && count.find(0) != count.end()) {
        cout << "Yes\n";
    } else if (count.size() == 2){
        if (count.find(0) == count.end()) {
            cout << "No\n";
            return 0;
        } else {
            auto c = *count.upper_bound(0);
            if (count[0] * 2 == c.second){
                cout << "Yes\n";
            } else {
                cout << "No\n";
            }
            return 0;
        }
    } else if (count.size() == 3) {
        ll t = -1;
        ll xored = 0;
        for (auto p: count) {
            xored ^= p.first;
            if (t == -1){
                t = p.second;
            } else if (t != p.second) {
                cout << "No\n";
                return 0;
            }
        }
        cout << ((xored == 0) ? "Yes" : "No") << '\n';
    } else{
        cout << "No\n";
    }

    

    return 0;
}

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

int main() {
    int n; scanf("%d", &n);
    int a[n]; for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    
    if (prev_permutation(a, a + n)) {
        printf("%d", a[0]);
        for (int i = 1; i < n; ++i) printf(" %d", a[i]);
        printf("\n");
    }
    
    next_permutation(a, a + n);
    printf("%d", a[0]);
    for (int i = 1; i < n; ++i) printf(" %d", a[i]);
    printf("\n");
    
    if (next_permutation(a, a + n)) {
        printf("%d", a[0]);
        for (int i = 1; i < n; ++i) printf(" %d", a[i]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2760
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);
const double eps=1e-8;

int n;

int main(){
	while(1){
		cin>>n;
		if(!n) break;
		vvi ans(n+1,vi(n+1));
		for(int i=0;i<n;i++){
			int tmp=0;
			for(int j=0;j<n;j++){
				cin>>ans[i][j];
				tmp+=ans[i][j];
			}
			ans[i][n]=tmp;
		}
		for(int i=0;i<=n;i++){
			int tmp=0;
			for(int j=0;j<n;j++){
				tmp+=ans[j][i];
			}
			ans[n][i]=tmp;
		}
		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++){
				cout.width(5);
				cout<<ans[i][j];
			}
			cout<<endl;
		}
	}
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define endl '\n'
#define debug(X) cout << #X << " = " << X << endl
#define SZ(X) ((int)X.size())

using namespace std;

const int oo = 1e9;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	#ifdef UTP
	freopen("input.txt", "r", stdin);
	#endif
	int n, k; cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
        cin >> a[i];
    vector<int> neg(1), pos(1);
    int it = 0;
    while (it < n && a[it] < 0) it++;
    for (int i = it - 1; i >= 0; i--) neg.push_back(-a[i]);
    if (it < n && a[it] == 0) k--, it++;
    for (int i = it; i < n; i++) pos.push_back(a[i]);
    int ans = oo;
    for (int i = 0; i <= k; i++) {
        if (i < SZ(pos) && k - i < SZ(neg))
            ans = min(ans, 2 * pos[i] + neg[k - i]);
        if (i < SZ(neg) && k - i < SZ(pos))
            ans = min(ans, 2 * neg[i] + pos[k - i]);
    }

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


Measured memory_bytes: 1404
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt(), k = fs.nextInt();
		if(k==1)System.out.println(0);
		else System.out.println(n-k);
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 23252
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < A[i].size(); j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	vector< int > F(N + 1);
	for (int x = 1; x <= 100; x++)
		for (int y = 1; y <= 100; y++)
			for (int z = 1; z <= 100; z++) {
				int i = x * x + y * y + z * z + x * y + y * z + z * x;
				if (i <= N)
					F[i]++;
			}
	for (int i = 1; i <= N; i++)
		cout << F[i] << endl;
	return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	vector<int> b(n, 1);
	vector<bool> r(n, false);
	r[0] = true;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		if (r[x]) {
			if (b[x] >= 2) {
				r[y] = true;
			} else {
				r[x] = false;
				r[y] = true;
			}
		}
		b[x]--;
		b[y]++;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (r[i]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std ; 
#define ll long long
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
#define MOD 1000000007
#define test int tcase ; cin>>tcase ; while(tcase--)

int main(){
    int s,w ; 
    cin>>s>>w ; 
    if(w>=s) cout<<"unsafe\n" ; 
    else cout<<"safe\n" ; 
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ_ICPC1 {

	class Program {
		static void Main(string[] args) {
			while (true) {
				string[] strs = Console.ReadLine().Split(' ');
				int N = int.Parse(strs[0]);
				int M = int.Parse(strs[1]);
				int P = int.Parse(strs[2]);
				
				if (N == 0 && M==0 && P==0) break;
				int[] X = new int[N];
				for (int n = 0; n < N; n++) X[n] = int.Parse(Console.ReadLine());

				Console.WriteLine(result(M, P, X));
			}
		}
		static int result(int M, int P, int[] X) {
			double sum = X.Sum() * 100;
			sum *= (100-P) * 0.01;
			if (X[M - 1] == 0) return 0;
			else return (int)(sum / X[M - 1]);
		}
	}
}

Measured memory_bytes: 5984
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;


fn main() {
    input! {
    s: Chars,
    t: Chars,
    }
    let sn = s.len();
    let tn = t.len();
    let mut ans = s.clone();
    let mut is_stored = false;
    for i in (tn..=sn).rev() {
        if check(&s[i - tn..i], &t) {
            for j in 0..tn {
                ans[i + j - tn] = t[j];
            }
            is_stored = true;
            break;
        }
    }
    if is_stored {
        for i in 0..sn {
            print!("{}", if ans[i] == '?' {
                'a'
            } else {
                ans[i]
            });
        }
    } else {
        println!("UNRESTORABLE")
    }
}


fn check(s: &[char], t: &[char]) -> bool {
    let n = t.len();
    for i in 0..n {
        if t[i] != s[i] && s[i] != '?' {
            return false;
        }
    }
    true
}

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

int main(void) {

	int n; cin >> n;

	int s[n+10];
	int i;
	int ans;
	ans = 0;

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


	for (int i = 0; i < n-2; i++) {
		if (s[i] > s[i + 1]) {
			if (s[i + 1] > s[i + 2]) { ans++; }
			else { ; }
		}
		else if (s[i] < s[i + 1]) {
			if (s[i + 1] < s[i + 2]) { ans++; }
			else { ; }
		}
		else { ; }

	}
	printf("%d", ans);

	return 0;

}


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

using namespace std;

typedef long long ll;

const int maxn = 1e5+10, mod = 1e9+7;

int n;

ll dp[maxn][2];

vector<int> grafo[maxn];

ll solve(int u, int p, bool cor){ // 0 = preto, 1 = branco
    if(dp[u][cor] != -1) return dp[u][cor];

    ll tot = 1;

    for(int i=0; i<grafo[u].size(); i++){
        int v = grafo[u][i];

        if(v == p) continue;

        if(!cor) tot = (tot * solve(v, u, !cor))%mod;
        if(cor) tot = (tot * (solve(v, u, cor) + solve(v, u, !cor))%mod)%mod;
    }

    return dp[u][cor] = tot;
}

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

    cin >> n;

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

        cin >> u >> v;

        grafo[u].push_back(v);
        grafo[v].push_back(u);
    }

    memset(dp, -1, sizeof dp);

    cout << (solve(1, 0, 0) + solve(1, 0, 1))%mod << endl;

    return 0;
}


Measured memory_bytes: 17024
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

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

typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<pii> vpii;
typedef vector<vint> det1;
typedef vector<vpii> det2;

int main()
{
    const string key = "keyence";

    string s;
    cin >> s;

    const int n = s.size();

    bool ok = false;

    REP(i, 0, n + 1)
    REP(j, i, n + 1)
    {
        const string ss = s.substr(0, i) + s.substr(j, n);
        ok |= key == ss;

        // cout << "i=" << i << " j=" << j << " " << ss << endl;
    }

    cout << (ok ? "YES" : "NO") << endl;

    return 0;
}


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

ll powmod(ll a, ll n, ll mod){
    ll ret = 1;
    while(n > 0){
        if(n % 2 == 1) ret = ret * a % mod;
        a = a * a % mod;
        n /= 2;
    }
    return ret;
}

int calc(ll num, int depth){
    if(num == 0LL) return depth;

    int p_count = __builtin_popcount(num);
    return calc(ll(num % p_count), depth + 1);
}

void solve(){
    ll n;
    char s[200005];
    cin >> n >> s;
    ll p_count = 0;
    for(int i = 0; i < n; i++) p_count += (s[i] == '1');
    ll rem_p1 = 0;
    ll rem_m1 = 0;

    for(int i = 1; i <= n; i++){
        if(s[n-i] == '1'){
            rem_p1 += powmod(2LL, i-1, p_count+1);
            rem_p1 %= (p_count+1);

            if(p_count > 1){
                rem_m1 += powmod(2LL, i-1, p_count-1);
                rem_m1 %= (p_count - 1);
            }
        }
    }

    for(int i = 0; i < n; i++){
        if(s[i] == '1'){
            if(p_count == 1){
                cout << 0 << endl;
                continue;
            }
            ll rem = rem_m1 - powmod(2, n-i-1, p_count-1);
            rem = (rem + p_count - 1) % (p_count - 1);
            cout << calc(rem, 1) << endl; // 一回上で余りを出してるから1からスタート
        }
        else{
            if(p_count == 0){
                cout << 1 << endl;
            }
            else{
                ll rem = rem_p1 + powmod(2, n-i-1, p_count+1);
                rem %= (p_count+1);
                cout << calc(rem, 1) << endl;
            }
        }
    }
}

int main(){
    solve();
}

Measured memory_bytes: 3760
#include <stdio.h>
int main()
{
  int a, b, c;
  scanf("%d%d%d",&a,&b,&c);
  if((a==b&&b==c)||(a!=b&&b!=c&&c!=a)) {
    puts("No");
  } else {
    puts("Yes");
  }
  return 0;
}


Measured memory_bytes: 1644
N = int(input())
X = []
for _ in range(N):
    a, b = input().split()
    X.append((a, int(b)))

s = input()
ans = 0
f = 0
for a, b in X:
    if f:
        ans += b
    if a == s:
        f = 1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	int x;
	cin>>x;
	cout<<x*x*x<<endl;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) (n); i++)
#define ll long long
#define scout cout << fixed << setprecision(20)
ll INF = 9e17;
ll mod = 1e9 + 7;

int main() {
	int n; cin >> n;
	int p[n];
	rep(i,n) cin >> p[i];
	int ans = 0;
	int M = INF;
	rep(i,n) {
		M = min(M,p[i]);
		if(M==p[i]) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

ll n,m,k,l;
vector<pair<int,string> > score;
map<string,int> dns;
map<string,int> ranks; 
vector<string> favs;
vector<int> favsRanks;
vector<int> favsDns;
char buf[1000];

// tlðãÊklÉüêé±ÆªÂ\©
bool check(int t){
    if(t>k)
        return false;
    else{
        ll sum=0;
        int ms;
        string mname;
        // tlÌ¤¿Ak-tÈãÌÊðæÁÄ¢éàÌÍ³µA»ÌÙ©Ì¨ÉÂ¢Äl¦é
        bool f=false;
        int p=0;
        for(int i = 0; i < t; i++){
            // A±µÄÊªßçêéÆ±ëÜÅßé
            // »ÝÌÊuÌÜÜÅàcèÌvf·×Äªüè¤é©Ç¤©
            int rfi=favsRanks[i];
            if(!f&&(k-rfi)>=t-i-1)
                continue;
            // à¤ß«êÈ¢ÌÅAæÃ~ÉÊðã¸³¹é
            if(!f){
                ms=score[k+i-t].first;
                mname=score[k+i-t].second;
                f=true;
            }
            // cÁ½àÌðüêéÉ«èépÉ}ü
            ll diff=-favsDns[i]+ms;
            if(mname<favs[i])
                diff++;
            sum+=diff;
        }
        return (sum<=l);
    }
}

void solve(){
    while(cin>>n>>m>>k>>l&&!(n==0&&k==0&&m==0&&l==0)){
        score.clear();favs.clear();dns.clear();ranks.clear();
        favsRanks.clear();
        favsDns.clear();
        for(int i = 0; i < n; i++){
            int s;
            string name;
            //scanf("%s %d\n",buf,&s);
            cin>>name>>s;
            //string name(buf);
            score.push_back(make_pair(-s,name));
            dns[name]=s;
        }
        sort(score.begin(),score.end());
        // ¾_ð³ÌÉßµANðÂ¯é
        for(int i = 0; i < n; i++){
            score[i].first=score[i].first*(-1);
            ranks[score[i].second]=i+1;
        }
        vector<pair<int,string> > vpis;
        for(int i = 0; i < m; i++){
            string name;
            cin>>name;
            vpis.push_back(make_pair(ranks[name],name));
        }
        sort(vpis.begin(),vpis.end());
        for(int i = 0; i < m; i++){
            favs.push_back(vpis[i].second);
            favsRanks.push_back(ranks[vpis[i].second]);
            favsDns.push_back(dns[vpis[i].second]);
        }
        int ub=m;
        int lb=-1;
        while(ub-lb>1){
            int med=(ub+lb)/2;
            if(!check(med))
                ub=med;
            else
                lb=med;
        }
        if(check(ub))
            printf("%d\n",ub);
        else
            printf("%d\n",ub-1);
    }
}


int main(){

    solve();

    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define tii tuple<int,int,int>
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
int main(){
    int n=in();
    double ans=-1;
    bool flag=false;
    while(ans <= n){
        ans++;
        if((int)(ans*1.08)==n){
            flag = true;
            break;
        }
    }
    if(!flag)cout<<":("<<endl;
    else cout<<ans<<endl;
}


Measured memory_bytes: 256
n, m, k = map(int, input().split())
ans = 0
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 998244353
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
for i in range(k + 1):
    ans = (ans + m * pow(m - 1, n - 1 - i, mod) * cmb(n-1,i, mod)) % mod
print(ans)


Measured memory_bytes: 112604
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	N := ReadInt()
	L := ReadInts(N)
	sort.Ints(L)
	c := 0
	for a := 0; a < N-2; a++ {
		for b := a + 1; b < N-1; b++ {
			r := sort.SearchInts(L, L[a]+L[b])
			if r > b {
				c += r - b - 1
			}
		}
	}
	fmt.Println(c)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

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

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll n,k;
	cin>>n>>k;
	ll M[n];
	fill(M, M+n, INT_MAX);
	ll A[n];
	for(ll i=0;i<n;i++)
		cin>>A[i];

	M[0]=0;
	for(ll i=0;i<n;i++){
		for(ll j=1;j<=k;j++){
			if(i-j>=0)
				M[i]=min(M[i],M[i-j]+abs(A[i]-A[i-j]));
		}
	}
	cout<<M[n-1]<<endl;

}


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

int parent[100000];
int degree[100000];
int *children[100000];

int depth(int node){
    if(parent[node] == -1)
        return 0;
    else
        return depth(parent[node]) + 1;
}

int main(void){
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
        parent[i] = -1;
    for(int j=0; j<n; j++){
        int id, k;
        scanf("%d%d", &id, &k);
        degree[id] = k;
        children[id] = (int*)malloc(sizeof(int)*k);
        for(int i=0; i<k; i++){
            scanf("%d", &children[id][i]);
            parent[children[id][i]] = id;
        }
    }
    for(int i=0; i<n; i++){
        printf("node %d: parent = %d, depth = %d, ", i, parent[i], depth(i));
        if(parent[i] == -1)
            printf("root, ");
        else if(degree[i] == 0)
            printf("leaf, ");
        else
            printf("internal node, ");
        printf("[");
        for(int j=0; j<degree[i]; j++){
            printf("%d", children[i][j]);
            if(j < degree[i] - 1)
                printf(", ");
        }
        printf("]\n");
    }
}


Measured memory_bytes: 6812
#include <stdio.h>
int main(void){
  int n,i,m=0;
  scanf("%d",&n);
  for(i=0; i<3; i++){
    if(n%10 == 7)
      m++;
    n = n/10;
  }
  if(m>0)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}

Measured memory_bytes: 1624
def minchange(s,t):
  m=len(s)
  n=len(t)
  if n!=m:
    return -1
  cnt=[0]*256
  for i in range(n):
    cnt[ord(t[i])]+=1
  for i in range(n):
    cnt[ord(s[i])]-=1
  res=0
  i=n-1
  j=n-1
  while i>=0:
    while i>=0 and s[i]!=t[i]:
      i-=1
      res+=1
    if i>=0:
      i-=1
      j-=1
  return res
s=input()
t=input()
print(str(minchange(s,t)))
      
  


Measured memory_bytes: 9660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
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; }
const long long INF = 1LL << 60;
const int inf = 1001001001;

int main(){
    
    ll n,m;
    cin >> n >> m;
    ll x=-1,y=n;
    rep(i,m){
        ll a,b;
        cin >> a >> b;
        chmax(x,a);
        chmin(y,b);
    }

    cout << max(y-x+1,0LL) << endl;

}

Measured memory_bytes: 256
/// 11:57 AM 04/04/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

template<typename T>
void ContainerError(T &v);

ll powmod(ll base, ll exp, ll MOD);

ll mpow(ll base, ll exp);

ll gcd(ll a, ll b);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<' '<<b<<' '<<c;
    return 0;
}

template<typename T>
void ContainerError(T &v) {
    cout << "{";
    for (auto &x:v) { cout << x << ','; }
    cout << "}" << endl;
    return;
}

ll powmod(ll base, ll exp, ll MOD) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return (res % MOD);
}

ll mpow(ll base, ll exp) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base);
        base = (base * base);
        exp /= 2;
    }
    return (res);
}

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



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

int main() {
    while (true) {
        int a, b, t;
        cin >> a >> b;
        if (a == 0 && b == 0) break;
        if (b < a) {
            t = a; a = b; b = t;
        }
        cout << a << " " << b << endl;
    }
    return 0;
}

Measured memory_bytes: 3092
/*
 * c.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

struct Card {
  int v, i;
  char s;
  Card() {}
  Card(char _s, int _v, int _i): s(_s), v(_v), i(_i) {}
  bool operator<(const Card &c) const { return v < c.v; }
  bool operator<=(const Card &c) const { return v <= c.v; }
  void print() { printf("%c %d\n", s, v); }
};

/* global variables */

Card as[MAX_N];

/* subroutines */

int partition(Card A[], int p, int r) {
  Card x = A[r];
  int i = p - 1;
  for (int j = p; j < r; j++)
    if (A[j] <= x) {
      i++;
      swap(A[i], A[j]);
    }
  i++;
  swap(A[i], A[r]);
  return i;
}

void quicksort(Card A[], int p, int r) {
  if (p < r) {
    int q = partition(A, p, r);
    quicksort(A, p, q - 1);
    quicksort(A, q + 1, r);
  }
}

bool stable(int n, Card as[]) {
  for (int i = 0; i < n; i++) {
    Card &ai = as[i];
    for (int j = i + 1; j < n && ai.v == as[j].v; j++)
      if (ai.i > as[j].i) return false;
  }
  return true;
}

/* main */

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

  for (int i = 0; i < n; i++) {
    cin >> as[i].s >> as[i].v;
    as[i].i = i;
  }

  quicksort(as, 0, n - 1);

  cout << (stable(n, as) ? "Stable" : "Not stable") << endl;
  for (int i = 0; i < n; i++) as[i].print();
  return 0;
}

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

typedef struct _linked_arr{
	int arr[31];
	struct _linked_arr *next;
}LINKED_ARR;

LINKED_ARR *makenode(int arr[]);
LINKED_ARR *addnode(LINKED_ARR *p,int arr[]);
void freenode(LINKED_ARR *P);
void makeTREE(LINKED_ARR *P);
void printTREE(LINKED_ARR *P);

int main(){
	
	int sn;
	int a_top[31];
	int i;
	LINKED_ARR *TOP;

	while(scanf("%d\n",&sn)!=EOF){
		if(sn==0)break;

		a_top[0]=sn;
		for(i=1;i<31;i++)a_top[i]=0;
		TOP=makenode(a_top);

		makeTREE(TOP);

		printTREE(TOP);
		
		freenode(TOP);
	}

	return 0;
}


LINKED_ARR *makenode(int arr0[]){

	int i;
	LINKED_ARR *P;
	if((P=(LINKED_ARR *)malloc(sizeof(LINKED_ARR)))==NULL){
		printf("malloc error\n");
		exit(1);
	}
	
	for(i=0;i<31;i++)P->arr[i]=arr0[i];
	P->next=NULL;

	return P;

}

void makeTREE(LINKED_ARR *P){
	
	int i;
	int buf[31];
	int carry;
	LINKED_ARR *Pnext;
	
	
	for(i=0;i<31;i++)buf[i]=P->arr[i];
	if(P->arr[0]==1){
		return;
	}
	carry=0;
	for(i=30;i>=0;i--){
		if(buf[i]==1){
			buf[i]--;
			carry++;
		}else if(buf[i]>1){
			buf[i]--;
			carry++;
			while(carry>0){
				i++;
				while(buf[i-1]>=buf[i]+1&&carry>0){
					buf[i]++;
					carry--;
				}
			}
			break;
		}
	}
//for(i=0;i<31;i++){printf("%d ",buf[i]);} ;puts("\tdebug");

	Pnext=makenode(buf);
	P->next=Pnext;
	makeTREE(Pnext);
	return;

}

void printTREE(LINKED_ARR *P){
	int i;
	for(i=0;i<31;i++){
		if(P->arr[i]){
			printf(P->arr[i+1]==0?"%d\n":"%d ",P->arr[i]);
		}
	}
	if(P->next==NULL){
		return ;
	}
	printTREE(P->next);
	return;
}
void freenode(LINKED_ARR *P){
	if(P->next==NULL){
		free(P);
		return;
	}
	freenode(P->next);
	return;
}

Measured memory_bytes: 2464
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;
typedef pair<ll,ll> P;

bool dpx[5000][20000],dpy[5000][20000];

int main(){
    string s;ll X,Y;
    cin>>s>>X>>Y;
    vector<ll> x;
    vector<ll> y;
    ll cn=0,tcn=0;
    rep(i,0,s.size()){
        if(s[i]=='T'){
            if(tcn%2==0)x.push_back(cn);
            else y.push_back(cn);
            tcn++;
            cn=0;
        }
        else{
            cn++;
        }
    }
    if(tcn%2==0)x.push_back(cn);
    else y.push_back(cn);
    
    dpx[0][10000]=1,dpy[0][10000]=1;
    rep(i,0,x.size()){
        rep(j,0,20001){
            if(i==0){if(dpx[i][j-x[i]])dpx[i+1][j]=1;}
            else if((j>=x[i]&&dpx[i][j-x[i]])||(j+x[i]<=20000&&dpx[i][j+x[i]]))dpx[i+1][j]=1;
        }
    }
    rep(i,0,y.size()){
        rep(j,0,20001){
            if((j>=y[i]&&dpy[i][j-y[i]])||(j+y[i]<=20000&&dpy[i][j+y[i]]))dpy[i+1][j]=1;
        }
    }
    if(dpx[x.size()][10000+X]&&dpy[y.size()][10000+Y])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

    









Measured memory_bytes: 156416
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define _GLIBCXX_DEBUG // ArrayOutofBounds
#define rep(i, N) for (int i = 0; i < N; i++) //制御変数iを用いてN回転
using namespace std;
using ll = long long;

int main() {
    int N;
    ll ans = 0, h = 0;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    for (int i = 1; i < N; i++) {
        if (A[i - 1] + h > A[i]) {
            h = A[i - 1] + h - A[i];
        } else h = 0;
        ans += h;
    }
    cout << ans << endl;
    return 0;
}

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

int main(void)
{
  ll a, b, GCD;
  cin >> a >> b;
  ll c,d;
  c = a;
  d = b;
  while(c && d)
  {
      if(c >= d)c %= d;
      else d %= c;
  }
  GCD = c + d;
  cout << a * b / GCD<< endl;
  return 0;
}



Measured memory_bytes: 256
n = int(input())
t = []
for i in range(677):
    t.append([])
x = n
for i in range(n):
    a = input()
    if(len(a) < 4):
        if(a in t[0]):
            x -= 1
        else:
            t[0].append(a)
    else:
        p = ord(a[0])*26+ord(a[1])-2618
        if(a[2:] in t[p]):
            x -= 1
        else:
            t[p].append(a[2:])
print(x)

Measured memory_bytes: 24180
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
H = [INT() for i in range(N)]
H.sort()

ans = INF
for i in range(N-K+1):
    ans = min(H[i+K-1] - H[i], ans)
print(ans)


Measured memory_bytes: 8120
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=np.int32)
B = np.array(input().split(), dtype=np.int32)
	
def f(t,A,B):
  power = 1<<t
  mask = (power<<1)-1
  AA = A & mask
  BB = B & mask
  AA.sort()
  BB.sort()

  x1,x2,x3 = (np.searchsorted(BB, v-AA).sum() for v in [power, 2*power, 3*power])
  zero_cnt = x1 + (x3-x2)
  return (N-zero_cnt)%2
  
answer = 0
for t in range(30):
	x = f(t,A,B)
	if x == 1:
		answer += 1<<t

print(answer)


Measured memory_bytes: 38880
#include<iostream>
using namespace std;
int main(){
  double a, b, s;
  int c;
  cin >> a;
  c = a;
  if(c % 2 == 1){
    b = c / 2 + 1;
  }
  else{
    b  = c / 2;
  }
  s = b / a;
  cout << s;
}

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

ll n,k,r,s,p;
string t;

ll return_score(char c){
    if(c == 'r') return p;
    if(c == 's') return r;
    if(c == 'p') return s;
}

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

    cin >> n >> k >> r >> s >> p >> t;

    map<int,vector<char>> mp;
    for(int i = 0; i < n; i++){
        mp[i%k].push_back(t[i]);
    }

    ll ans = 0;
    for(auto i : mp){
        for(int j = 0; j < i.second.size(); j++){
            if(j == n - 1) {
                ans += return_score(i.second[j]);
                break;
            }
            if(i.second[j] == i.second[j+1]){
                ans += return_score(i.second[j]);
                j++;
            } else {
                ans += return_score(i.second[j]);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 10064