akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

/////////////////////////////////////////////////////////////////////

template<typename T>
vector<T> BFS(vector<vector<int>> &G, int s) {
    vector<T> ret(G.size(),-1);
    ret[s] = 0;
    queue<int> que;
    que.emplace(s);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (auto nv : G[v]) {
            if (ret[nv] != -1) continue;
            ret[nv] = ret[v] + 1;
            que.emplace(nv);
        }
    }

    return ret;
}

////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<vector<int>> G(N);
    for (int i = 0; i < N; ++i) {
        int u,k; cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            int v; cin >> v;
            --v;
            G[i].emplace_back(v);
        }
    }

    auto dist = BFS<int>(G,0);

    for (int i = 0; i < N; ++i) cout << i+1 << " " << dist[i] << endl;
}

/*
  verified on 2020/02/18
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_C&lang=ja
*/


Measured memory_bytes: 3220
#include <iostream>

using namespace std;

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

    int res = 1;
    for (int i = 2; i <= x; i++) {
        for (int j = i * i; j <= x; j *= i) {
            if (res < j) {
                res = j;
            }
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#define INF 1000000;

using namespace std;

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

    double t, a, diff, close_t, x;
    cin >> t >> a;
    int close_index;

    close_t = INF;
    close_index = 0;
    for (int i=1; i<=n; i++){
        cin >> x;
        diff = a - (t - x*0.006);
        if (diff<0) diff *= -1;

        if (close_t > diff) {
            close_t = diff;
            close_index = i;
        }
    }
    cout << close_index << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, a, b);

  int k = (a + b) / 2;

  if (abs(a - k) == abs(b - k))
    cout << k << endl;
  else
    puts("IMPOSSIBLE");

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree< pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
//ordered_set;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
#define X first
#define Y second
#define int long long int 
const int N = (int)1e6 + 10;
const int MOD = 1000000007;


void solve(){
    int k; cin >> k;
    vector<string> a(k + 100);
    for(int i = 1; i <= 9; ++i){
        string n = to_string(i);
        a[i] = n;
    }
    int id = 10;
    int from = 1;
    while(id <= k ){
        int lastch = a[from][a[from].size() - 1] - '0';
        int mn = max(lastch - 1,(int)0);
        int mnm = lastch;
        int mnu = min((int)9, lastch + 1);
        if( lastch == 0 ){
            a[id++] = a[from] + (char)(mnm + '0');
            a[id++] = a[from] + (char)(mnu + '0');
        } else if( lastch == 9){
            a[id++] = a[from] + (char)(mn + '0');
            a[id++] = a[from] + (char)(mnm + '0');
        } else {
            a[id++] = a[from] + (char)(mn + '0');
            a[id++] = a[from] + (char)(mnm + '0');
            a[id++] = a[from] + (char)(mnu + '0');
        }
      	if(id > k) break;
        from++;
    }
    cout << a[k] << '\n';


}   

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    //int t; cin >> t;
    //while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 6912
# 問題文
# いろはちゃんは、人気の日本製ゲーム「ÅtCoder」で遊びたい猫のすぬけ君のために日本語を教えることにしました。

# 日本語で鉛筆を数えるときには、助数詞として数の後ろに「本」がつきます。この助数詞はどんな数につくかで異なる読み方をします。
# 具体的には、999以下の正の整数 Nについて、「N本」と言うときの「本」の読みは
# Nの1の位が2,4,5,7,9のとき'hon'
# 0,1,6,8'pon'
# 3'bon'

# 制約
# Nは999以下の整数

n = input()

if int(n[-1]) in [2, 4, 5, 7, 9]:
    print('hon')
elif int(n[-1]) in [3]:
    print('bon')
else:
    print('pon')

Measured memory_bytes: 9020
#include <iostream>
#include <cmath>
using namespace std;
 
int main(){
  int L,R,D;
  cin >> L >> R >> D;
  int ans = 0;
  if(L % D == 0 && R % D == 0){
    ans += 2;
    ans += floor( (double)(R-L-1)/(double)(D) );
  } else if(R % D == 0){
    ans++;
    ans+= floor( (double)(R-L)/(double)(D) );
  } else if(L % D == 0){
    ans++;
    ans+= floor( (double)(R-L)/(double)(D) );
  } else {
    ans = floor( (double)(R-L+1)/(double)(D) );
  }
  cout << ans << endl;

}

Measured memory_bytes: 3712
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
using namespace std;
  
#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);
  
#define csh(a,n) memset(a,n,sizeof(a));
char arr[30001];
int main(){
	int n;
	cin>>n>>arr;
	int p=0;
	int a=0,b,c;
	int sum=0;
	for(int i=0;i<n;i++){
		arr[i]-='0';
	} 
	for(int i=0;i<10;i++){
		p=a;
		while(arr[p]!=i){
			p++;
			if(p>=n){
				break;
			}
		}
		p++;
		b=p;
		if(p<n)
		for(int j=0;j<10;j++){
			p=b;
			while(arr[p]!=j){
				p++;
				if(p>=n){
					break;
				}
			}
			p++;
			c=p;
			if(p<n)
			for(int z=0;z<10;z++){
				p=c;
				while(arr[p]!=z){
					p++;
					if(p>=n){
						break;
					}
				}
				if(p<n){
					sum++;
				}
				
			}
		}
	}
	cout<<sum<<endl;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double x = sc.nextDouble();
        double theta;
        if (x < (a * a * b / 2)) {
            theta = Math.atan((a * b * b) / (2 * x));
        } else {
            theta = Math.atan(2 * (b / a - x / (a * a * a)));
        }
        System.out.println(theta * 360 / (2 * Math.PI));
    }

}


Measured memory_bytes: 23124
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int X;
    R(X);
    W((X==3||X==5||X==7)?"YES":"NO");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
#include <math.h>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#define mod 1000000007
using namespace std; 

int main(){
    vector<vector<int>> date(3,vector<int> (3));
	for (int i=0;i<3;i++){
		for (int j=0;j<3;j++){
			cin >> date[i][j];
		}
	}
	int n; cin >> n;
	for (int i=0;i<n;i++) {
		int s; cin >> s;
		for (int i=0;i<3;i++){
			for (int j=0;j<3;j++){
				if(date[i][j]==s) date[i][j]=0;
			}
		}
	}
	
	for (int i=0;i<3;i++){
		if (date[i][0]==0 && date[i][1]==0 && date[i][2]==0){
			cout << "Yes" << "\n";
			return 0;
		}
	}

	for (int i=0;i<3;i++){
		if (date[0][i]==0 && date[1][i]==0 && date[2][i]==0){
			cout << "Yes" << "\n";
			return 0;
		}
	}

	if (date[1][1]==0 && date[2][2]==0 && date[0][0]==0){
		cout << "Yes" << "\n";
		return 0;
	}

	if (date[2][0]==0 && date[1][1]==0 && date[0][2]==0){
		cout << "Yes" << "\n";
		return 0;
	}

	cout << "No" << "\n";
	
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>

using namespace std;

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

	vector<int> h(n);
	vector<int> a(m);
	vector<int> b(m);
	vector<int> cnt(n + 1);

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

	for (int i = 0;i < m;i++) {
		cin >> a[i] >> b[i];
		if (h[a[i] - 1] > h[b[i] - 1]) {
			cnt[b[i]] = -1;
		}
		else if (h[a[i] - 1] < h[b[i] - 1]) {
			cnt[a[i]] = -1;
		}
		else {
			cnt[a[i]] = -1;
			cnt[b[i]] = -1;
		}
	}

	int ans = 0;

	for (int i = 1;i <= n;i++) {
		if (cnt[i] != -1) {
			ans++;
		}
	}

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

Measured memory_bytes: 4816
#include<cstdio>
#include<algorithm> 
#include<cstring>
#define LL long long
using namespace std;
const int N=2e3+5;
const int mod=1e9+7;
int n,m,fac[N*N],inv[N*N],f[N][N];
int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
void Mod(int& a,int b){a+=b;if(a>=mod)a-=mod;}
int power(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=1ll*ans*a%mod;
		a=1ll*a*a%mod;b>>=1;
	}
	return ans;
}
int C(int n,int m){return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}
int main()
{
	n=read();m=read();
	if(m==1){printf("1");return 0;}
	fac[0]=1;
	for(int i=1;i<=n*m;i++)fac[i]=1ll*fac[i-1]*i%mod;
	inv[n*m]=power(fac[n*m],mod-2);
	for(int i=n*m;i>=1;i--)inv[i-1]=1ll*inv[i]*i%mod;
	f[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=i;j++)
		{
			f[i][j]=f[i-1][j];
			if(!j)continue;
			Mod(f[i][j],1ll*f[i][j-1]*(n-j+1)%mod*C(n-i+(n-j+1)*(m-1)-1,m-2)%mod);
		}
	printf("%d",f[n][n]);
	return 0;
}

Measured memory_bytes: 46336
#include <iostream>
#include <fstream>
#include <string>


using namespace std;

int main(){
#ifdef CIN
	ifstream cin("input.txt");
	ofstream cout("output.txt");

#endif

	int h, w;

	while (true)
	{

		cin >> h >> w;

		if (h == 0 && w == 0) break;
		for (int k = 1; k <= w; k++)
		{
			cout << "#";

		}
		cout << endl;
		for (int i = 1; i < h-1; i++)
		{
			cout << '#';
			for (int j = 2; j < w; j++)
			{
				cout << ".";

			}
			cout << '#';
			cout << endl;
		}
		for (int l = 1; l <= w; l++)
		{
			cout << "#";

		}
		cout << endl << endl;
	}


}

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


int main(){
    int N,M;
    cin>>N>>M;
    string ans =(N==M)?"Yes":"No";
    cout<<ans<<endl;
    return 0;
}


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

std::vector<vector<int>> g_books;
std::vector<int> g_yens;

unsigned int DFS(int n, vector<int> x, int sum)
{
    if (n == g_books.size())
    {
        for (const auto &item : x)
        {
            if (item > 0)
                return -1;
        }
        return sum;
    }

    const unsigned int notBuy = DFS(n + 1, x, sum);

    for (int i = 0; i < x.size(); ++i)
    {
        x[i] -= g_books[n][i];
    }

    const unsigned int Buy = DFS(n + 1, x, sum + g_yens[n]);

    return min(notBuy, Buy);
}

int main()
{
    int n, m, x;
    std::cin >> n >> m >> x;
    g_yens.resize(n);
    g_books.resize(n);
    for (int i = 0; i < n; ++i)
    {
        g_books[i].resize(m);
        std::cin >> g_yens[i];
        for (int j = 0; j < m; ++j)
            std::cin >> g_books[i][j];
    }

    std::cout << (int)DFS(0, vector<int>(m, x), 0) << std::endl;
    return 0;
}


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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

struct node {
  ll x;
  ll y;
  ll z;
  ll sum;
};

bool operator< (node n1, node n2) {
  return n1.sum < n2.sum;
}

priority_queue<node> que;
bool checked[1005][1005][1005];

ll N = 0;
ll X, Y, Z;
ll K;
ll tmp;
ll ret = 0;
vector<ll> A;
vector<ll> B;
vector<ll> C;
vector<ll> S;

void input() {
  IN(X);
  IN(Y);
  IN(Z);
  IN(K);
  REP(i, X) {
    IN(tmp);
    A.pb(tmp);
  }
  REP(i, Y) {
    IN(tmp);
    B.pb(tmp);
  }
  REP(i, Z) {
    IN(tmp);
    C.pb(tmp);
  }
}

void bfs() {
  while(S.size() < K && !que.empty()) {
    node n = que.top();
    que.pop();
    if (checked[n.x][n.y][n.z]) {
      continue;
    } else {
      checked[n.x][n.y][n.z] = true;
    }
    S.pb(n.sum);

    if (n.x > 0) {
      node childX = {n.x-1, n.y, n.z, A[n.x-1]+B[n.y]+C[n.z]};
      que.push(childX);
    }
    if (n.y > 0) {
      node childY = {n.x, n.y-1, n.z, A[n.x]+B[n.y-1]+C[n.z]};
      que.push(childY);
    }
    if (n.z > 0) {
      node childZ = {n.x, n.y, n.z-1, A[n.x]+B[n.y]+C[n.z-1]};
      que.push(childZ);
    }
  }
}

void solve() {
  sort(ALL(A));
  sort(ALL(B));
  sort(ALL(C));
  node first = {X-1, Y-1, Z-1, A[X-1]+B[Y-1]+C[Z-1]};
  que.push(first);
  bfs();
  REP(i, K) {
    PRINT(S[i]);
  }
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 985728
#include <bits/stdc++.h>
#include<iostream>
#include<fstream>
#define ll long long
using namespace std;

int main(){
    int mod = 1e9+7;
    int N, X;
    cin >> N >> X;
    vector<int> S(N);
    for(int i=0; i<N; i++) cin >> S[i];
    sort(S.begin(), S.end());

    vector<vector<ll>> dp = vector<vector<ll>>(X+1, vector<ll>(N, 0));
    for(int x=0; x<=X; x++){
        dp[x][0] = x%S[0];
    }
    
    for(int n=1; n<N; n++){
        for(int x=0; x<=X; x++){
            dp[x][n] = (dp[x%S[n]][n-1]%mod + dp[x][n-1]*n % mod)%mod;
        }
    }
    cout << dp[X][N-1] << endl;
}


Measured memory_bytes: 160384
x = int(input())
d = list(map(int, input().split()))
count = 0
for i in range(len(d)):
  for j in range(i+1,len(d)):
    for k in range(j+1,len(d)):
      temp = []
      temp.extend([d[i],d[j],d[k]])
      temp.sort()
      if temp[0] + temp[1] > temp[2] and len(list(set(temp))) == 3:
        count += 1
print(count)

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


int main() {

	ll a, b, lcm;
	cin >> a >> b;
	lcm = max(a, b);
	while (lcm % min(a, b) != 0) lcm += max(a, b);
	cout << lcm << endl;
}

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

int main()
{
	string str;
	int N,Q,i;
	cin >>N >>Q >>str;
	int l[Q],r[Q],ac[N];
	for(i=0;i<Q;i++){
		cin >>l[i]>>r[i];
	}
	ac[0]=0;
	for(i=1;i<N;i++){
		if((str[i-1]=='A')&&(str[i]=='C')){
			ac[i]=ac[i-1]+1;
		}else {
			ac[i]=ac[i-1];
		}
	}
	for(i=0;i<Q;i++){
		cout <<ac[r[i]-1]-ac[l[i]-1]<<endl;
	}
		/*if((str[i]=='A')||(str[i]=='T')||(str[i]=='C')||(str[i]=='G')){*/

	return 0;
}


Measured memory_bytes: 2176
#include "bits/stdc++.h"
//#include "ext/pb_ds/assoc_container.hpp"
//#include "ext/pb_ds/tree_policy.hpp"
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
//const int mod1 = 998244353;
typedef long double f80;

#ifndef LOCAL
#pragma GCC optimize ("O2")
#define endl '\n'
#endif

//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//int rand(int l, int r){
//    uniform_int_distribution<int> uid(l, r);
//    return uid(rng);
//}

ll pwr(ll a,ll b, ll mod){
    a %= mod;
    ll ans = 1;
    while(b){
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int f(int k,int n) {
    if(n < k) return n;
    return f(k, n / k) + n % k;
}

void solve(){
    int n, s;
    cin >> n >> s;
    for(int l = 2; l <= n; l++) {
        int val = (n / l);
        int r = n / val;
        if(l == r) {
            if(f(l, n) == s) {
                cout << l;
                return;
            }
        }
        else {
            int b = (n - s) / val + 1;
            if(b >= l && b <= r) {
                if(f(b, n) == s) {
                    cout << b;
                    return;
                }
            }
        }
        l = r;
    }
    if(f(n + 1, n) == s) {
        cout << n + 1 << endl;
        return;
    }
    cout << -1;
}

signed main(){
    IO;
#ifdef LOCAL
    freopen("inp.txt","r", stdin);
#endif
    cout << setprecision(3) << fixed;
    //    srand(time(NULL));
    //    build();
    int t = 1;
//    cin >> t;
    fr(tt, 1, t){
//        cout << "Case #" << tt << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cstdio>
using namespace std;
class king{
public:int present;
public:int next;
};
int main(){
    int n;
    long long k;
    scanf("%d %lld",&n,&k);
    vector<int> vector1{1};
    for(int i =1;i<=n;i++){
        int tmp = 0;
        scanf("%d",&tmp);
        vector1.push_back(tmp);
    }
    king K = *new king;
    K.present = 1;
    K.next = vector1[1];
    map<int, int> map1;
    int a=1;
    int loop;
    int flag = 0;
    while(k>0){
        if(map1.find(K.present)!=map1.end()&&flag==0){
            loop = a-map1.find(K.present)->second;
//            cout << loop << endl;
//            cout << k<< endl;
            k%=loop;
            if(k==0){
                break;
            }
            flag = 1;
//            cout << k << endl;
        }
        map1[K.present]=a++;
        K.present = K.next;
        K.next = vector1[K.next];
        k--;
    }

    cout << K.present;
//    map<int, int> first_map;
//    map<int, int> second_map;
//    map<int,int>::iterator iter1=m.begin();
//    int cnt = 0;
//    int l = 0;
//    while(true){
//        cnt +=1;
//        if(first_map.find(iter1->second)!=first_map.end()){
//            while(true){
//                l++;
//                if(second_map.find(iter1->second)!=second_map.end()){
//                    break;
//                }
//                second_map[iter1->first]=iter1->second;
//                iter1=m.find(iter1->second);
//
//            }
//            break;
//        }
//        first_map[iter1->first]=iter1->second;
//        iter1=m.find(iter1->second);
//
//    }
//    map<int,int>::iterator iter=m.begin();
//    int b = cnt - l;
//    int a;
//    if(k>b)
//        a = (k-b)%l;
//    else a = k;
//    while(a >= 0){
//        a-=1;
//        iter = m.find(iter->second);
//    }
//    cout << iter->first;
}



Measured memory_bytes: 11456
#include<bits/stdc++.h>
using namespace std;
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; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
static const int mod = 1e+7;
static const long long INF = 1LL << 60;
typedef long long ll;
int main(){
    int N,X;
    cin>>N>>X;
    vector<int> L(N);
    rep(i,N)cin>>L[i];
    int sum = 0;
    int cnt=1;
    for(int i = 0; i < N; i++){
        sum += L[i];
        if(sum <= X)cnt++;
    }
    cout<<cnt<<endl;
}

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

int main(void) {
    int a, b, c;
    vector<int> cost;
    cin >> a >> b >> c;
    cost.push_back(a + b);
    cost.push_back(b + c);
    cost.push_back(c + a);
    cout << *min_element(cost.begin(), cost.end()) << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, c; double x, y, r;
int main() {
	while (cin >> n, n) {
		vector<double> xa(n), ya(n), xb(n), yb(n);
		for (int i = 0; i < n; i++) {
			cin >> x >> y >> r;
			xa[i] = x - r; ya[i] = y - r;
			xb[i] = x + r; yb[i] = y + r;
		}
		vector<double> xc, yc;
		for (int i = 0; i < n; i++) {
			xc.push_back(xa[i]);
			yc.push_back(ya[i]);
			xc.push_back(xb[i]);
			yc.push_back(yb[i]);
		}
		sort(xc.begin(), xc.end());
		xc.resize(unique(xc.begin(), xc.end()) - xc.begin());
		sort(yc.begin(), yc.end());
		yc.resize(unique(yc.begin(), yc.end()) - yc.begin());
		for (int i = 0; i < n; i++) {
			xa[i] = lower_bound(xc.begin(), xc.end(), xa[i]) - xc.begin();
			ya[i] = lower_bound(yc.begin(), yc.end(), ya[i]) - yc.begin();
			xb[i] = lower_bound(xc.begin(), xc.end(), xb[i]) - xc.begin();
			yb[i] = lower_bound(yc.begin(), yc.end(), yb[i]) - yc.begin();
		}
		vector<vector<int> > imos(yc.size(), vector<int>(xc.size()));
		vector<vector<int> > sum(yc.size() + 1, vector<int>(xc.size() + 1));
		for (int i = 0; i < n; i++) {
			imos[ya[i]][xa[i]]++;
			imos[ya[i]][xb[i]]--;
			imos[yb[i]][xa[i]]--;
			imos[yb[i]][xb[i]]++;
		}
		double ret = 0;
		for (int i = 0; i < yc.size(); i++) {
			for (int j = 0; j < xc.size(); j++) {
				sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + imos[i][j];
				if (sum[i + 1][j + 1] > 0) ret += (xc[j + 1] - xc[j]) * (yc[i + 1] - yc[i]);
			}
		}
		printf("%d %.2lf\n", ++c, ret);
	}
	return 0;
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
int main(){
    string s, t;
    cin >> s >> t;
    int n = s.size();
    if(t.substr(0, n) == s)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}  

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


public class Main {
	static int N,M;
	static int[] points;
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		 N = sc.nextInt();
		 M = sc.nextInt();
		 points = new int[M];

		 for(int i = 0 ; i < M ; i++){
			 points[i] = sc.nextInt();
		 }

		 sc.close();
		 Arrays.sort(points);

		 int[] minus = new int[M-1];

		 for(int k = 1 ; k < M ; k++){
			minus[k-1] = points[k]-points[k-1];
		 }

		 Arrays.sort(minus);

		 int ans = 0 ;

		 for(int l = 0 ; l < minus.length - N + 1 ; l++){
			 ans += minus[l];
		 }

		 System.out.println(ans);
	}
}

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

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int maxx = max(x, y);
  int64_t min_sum = 10000000000000;
  int64_t sum = 0;
  rep(i, maxx + 1) {
    sum = 2 * i * c;
    if (i <= x) {
      sum += a * (x - i);
    }
    if (i <= y) {
      sum += b * (y - i);
    }
    if (min_sum > sum) {
      min_sum = sum;
    }
  }
  cout << min_sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    string s;
    cin >> s;
    set<char> a;
    rep(i,s.length()) a.insert(s[i]);
    int ans = 1000000000;
    
    for (char p : a) {
        int an = 0;
        
        string ss = s;
        while (true) {
            int d = 0;
            rep(i,ss.length()) if(ss[i] == p) d++;
            if(d == ss.length()) break;
            string sss = "";
            rep(i,ss.length()-1){
                if(ss[i] == p || ss[i+1] == p) sss += p;
                else sss += ss[i];
            }
            ss = sss;
            //cout << ss << endl;
            an++;
        }
        
        ans = min(an,ans);
    }
    
    cout << ans << endl;
    
    

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int cnt[4],n;
double dp[305][305][305];
double dfs(int a,int b,int c){
    if(a==0&&b==0&&c==0) return 0;
    if(dp[a][b][c]>0)return dp[a][b][c];
    double tmp=1.0*(a+b+c);
    double ans=1.0*n/(tmp);
    if(a)ans+=(1.0*a/(tmp))*dfs(a-1,b,c);
    if(b)ans+=(1.0*b/(tmp))*dfs(a+1,b-1,c);
    if(c)ans+=(1.0*c/(tmp))*dfs(a,b+1,c-1);
    return dp[a][b][c]=ans;
}
int main(){
    int d;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i){
        scanf("%d",&d);
        cnt[d]++;
    }
    printf("%.10f\n",dfs(cnt[1],cnt[2],cnt[3]));
    return 0;
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

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

Measured memory_bytes: 7168
#include <iostream>
using namespace std;
int main() {
	long h, w;
	cin >> h >> w;
	if (h == 1 || w == 1) {
		cout << 1 << endl;
		return 0;
	}
	if (h % 2 == 1 && w % 2 == 1) {
		cout << (h * w + 1) / 2 << endl;
	}
	else {
		cout << (h * w) / 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 3576
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC045A
{
    class Program
    {
        static void Main(string[] args)
        {

            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int h = int.Parse(Console.ReadLine());



            Console.WriteLine((a + b) * h / 2);
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
using namespace std;
int main() {
    int S, h, m, s;
    cin >> S;
    h = S / 3600;
    m = (S % 3600) / 60;
    s = (S % 3600) % 60;
    
    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3080
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int X = sc.nextInt();
    int Y = sc.nextInt();

    int[] x = new int[N];
    for (int i = 0; i < N; i++) {
      x[i] = sc.nextInt();
    }
    Arrays.sort(x);
    int[] y = new int[M];
    for (int i = 0; i < M; i++) {
      y[i] = sc.nextInt();
    }
    Arrays.sort(y);

    final String ans;
    if (x[N-1] < y[0] && X < y[0] && x[N-1] < Y) {
      ans = "No War";
    } else {
      ans = "War";
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define P pair<int, int>
#define Pl pair<ll, ll>
#define dvec vector<vector<ll>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;

void
Warshall_Floyd(int V, vector<vector<int>> &G)
{
  rep(i, 0, V){
    rep(k, 0, V){
      rep(l, 0, V){
        chmin(G[k][l], G[k][i] + G[i][l]);
      }
    }
  }
}

int main()
{
  int H, W; cin >> H >> W;
  vector<vector<int>> cost(10, vector<int>(10));
  rep(i, 0, 10) rep(k, 0, 10) cin >> cost[i][k];
  vector<vector<int>> wall(H, vector<int>(W));
  rep(i, 0, H) rep(k, 0, W) cin >> wall[i][k];

  Warshall_Floyd(10, cost);
  
  ll ans = 0;
  rep(i, 0, H){
    rep(k, 0, W){
      if(wall[i][k] != -1) ans += cost[wall[i][k]][1];
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3752
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long X = sc.nextLong();

    long[] layer = new long[N + 1];
    long[] paty = new long[N + 1];
    layer[0] = 1;
    paty[0] = 1;
    for(int i = 1; i <= N; i++){
      layer[i] = 2 * layer[i - 1] + 3;
      paty[i] = 2 * paty[i - 1] + 1;
    }

    long ans = 0;
    int i = N;
    while(i >= 1){
      if(X == 2 * layer[i - 1] + 3){
        ans += 2 * paty[i - 1] + 1;
        break;
      }else if(X > layer[i - 1] + 2){
        ans += paty[i - 1] + 1;
        X -= layer[i - 1] + 2;
        i--;
      }else if(X == layer[i - 1] + 2){
        ans += paty[i - 1] + 1;
        break;
      }else if(X == layer[i - 1] + 1){
        ans += paty[i - 1];
        break;
      }else{
        X--;
        i--;
      }
    }

    if(i == 0 && X == 1){ans++;}

    System.out.println(ans);
    sc.close();
  }
}


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

int main() {
  int r,d,x,f;
  cin >> r >> d >>x;
	f = x;
  for (int i = 0; i < 10; i++)
  {
    f = r*f - d;
    cout << f << endl;
  }
  

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] ss = s.toCharArray();
		if(ss[2] == ss[3]) {
			if(ss[4] == ss[5]) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}

}


Measured memory_bytes: 21844
import java.util.Scanner;

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


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1,0};
const int dy[]={0,1,0,-1,1,1,-1,-1,0};
const int INF = 1e9;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
template<class T>
ostream& operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()){
		out << v[i] <<", ";
	}
	return out << "}" << endl;
}

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<int> diff_weight;

    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = diff_weight[i] = 0;
    }

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

    int weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, int w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    int diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() {
	int N, M;
	cin >> N >> M;
	bool flg= false;

	UnionFind uf = UnionFind(N+1);
	rep(i,M){
		int l,r,d;
		cin >> l >> r >> d;
		l--;r--;
		if(uf.issame(l,r)){
			if(uf.diff(l,r) != d){
				flg = true;
			}
		}
		else{
			uf.merge(l,r,d);
		}
	}	
	puts(flg?"No":"Yes");

	return 0;
}

Measured memory_bytes: 1408
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Main {


  private static void solve() {
    int n = ni();
    int[] a = na(n);
    Arrays.sort(a);
    Map<Integer, Integer> map = new HashMap<>();
    for (int v : a) {
      map.putIfAbsent(v, 0);
      map.put(v, map.get(v) + 1);
    }

    int ret = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (map.get(a[i]) == 0) continue;
      int v = Integer.highestOneBit(a[i]) << 1;
      map.put(a[i], map.get(a[i]) - 1);

      int target = v - a[i];
      if (!map.containsKey(target) || map.get(target) == 0)
        continue;

      map.put(target, map.get(target) - 1);
      ret++;
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 64444
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <utility>
typedef long long ll;

const int maxn = 100010;

std::multiset<ll> inc,dec;
std::multiset<ll>::iterator iter;
ll l[maxn], r[maxn], len[maxn];

int main()
{
	//freopen("E.in","r",stdin);
	int n;
	scanf("%d",&n);
	
	ll offset_dec = 0, offset_inc  = 0, ans = 0;
	scanf("%lld%lld",&l[1], &r[1]);
	dec.insert(r[1]); inc.insert(r[1]); len[1] = r[1] - l[1];
	
	for (int i=2;i<=n;i++)
	{
		scanf("%lld%lld",&l[i],&r[i]);
		len[i] = r[i] - l[i];
		
		//parallel move to both sides
		offset_dec -= len[i-1];
		offset_inc += len[i];
		
		// + |x-Ri|
		if (r[i] >= *inc.begin() + offset_inc)
		{
			ans += r[i] - (*inc.begin() + offset_inc);
			dec.insert(*inc.begin() + offset_inc - offset_dec);
			inc.erase(inc.begin());
			inc.insert(r[i] - offset_inc);
			inc.insert(r[i] - offset_inc);
		}
		else if (r[i] <= *(dec.rbegin()) + offset_dec)
		{
			ans += (*dec.rbegin() + offset_dec) - r[i];
			inc.insert(*dec.rbegin() + offset_dec - offset_inc);
			iter = dec.end();
			iter--;
			dec.erase(iter);
			dec.insert(r[i] - offset_dec);
			dec.insert(r[i] - offset_dec);
		}
		else
		{
			dec.insert(r[i] - offset_dec);
			inc.insert(r[i] - offset_inc);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 11904
#include <iostream>

using namespace std;
using std::cout;
using std::cin;
using std::endl;

int main()
{
    int n;
    cin>>n;
    int a,b,c,d;
    a=n/1000;
    b=(n-a*1000)/100;
    c=(n-a*1000-b*100)/10;
    d=n%10;
    if(a+b+c+d==7)
    {
        cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7";
    }
    else if(a+b+c-d==7)
    {
        cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7";
    }
    else if(a+b-c+d==7)
    {
        cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7";
    }
    else if(a+b-c-d==7)
    {
        cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7";
    }
    else if(a-b+c+d==7)
    {
        cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7";
    }
    else if(a-b+c-d==7)
    {
        cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7";
    }
    else if(a-b-c+d==7)
    {
        cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7";
    }
    else if(a-b-c-d==7)
    {
        cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> s(10005);
    for(long long int x=1;x<100;x++){
       for(long long int y=1;y<100;y++){
          for(long long int z=1;z<100;z++){
              int a= x*x + y*y + z*z + x*y + y*z + z*x;
              if(a>10000) continue;
              s[a]++;
          }
       }
    }
  for(int i=1;i<=N;i++){
    cout<<s[i]<<endl;
  }
}
   

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <string>
#include <bitset>
#include <stack>
#include <map>
 
using namespace std;
 
int main() {
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n * a, b);
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;

int main() {
  string S; cin>>S;
  int T=S.size();
  if(T<26){
    rep(i,26){
      char s;
      s=(i+97);
      bool id=true;
      rep(j,T) if(s==S.at(j))id=false;
      if(id){
        S.push_back(s);
        cout<<S;
        break;
      }
    }
  }
  else{
    int i=T-2;
    for(;i>=0;i--){
      if(S.at(i)<S.at(i+1)) break;
    }
    if(i<0) cout<<-1;
    else{
      for(int k=(int)S.at(i)-96;k<26;k++){
        char s;
        s=(k+97);
        bool id=true;
        rep(l,i) if(s==S.at(l)) id=false;
        if(id){
          S.at(i)=s;
          break;
        }
      }   
      rep(z,i+1) cout<<S.at(z);
    }
  }   
}


Measured memory_bytes: 3612
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, m: usize,
        ab: [(Usize1, Usize1); m],
    }

    let mut edges = vec![Vec::new(); n];
    for (a, b) in ab {
        edges[a].push(b);
        edges[b].push(a);
    }
    let ans = edges.iter().all(|nodes| nodes.len() % 2 == 0);
    if ans {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 10536
n, m = gets.chomp.split(" ").map(&:to_i)
arr = Array.new(n).map{Array.new}
m.times do |i|
    a, b = gets.chomp.split(" ").map(&:to_i)
    arr[a-1] << b
    arr[b-1] << a
end
arr.each do |i|
    puts i.size
end


Measured memory_bytes: 14376
#define ll    long long
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ll k,n,i,j,p,t;
    cin>>k>>n;
    long long a[n],b[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];

    }
    for(i=0;i<n-1;i++)
    {
        ll m;

        m=abs(a[i]-a[i+1]);
        b[i]=m;
    }
    p=a[n-1]-a[0];
    sort(b,b+(n-1));
    t=k-b[n-2];

        cout<<min(t,p)<<endl;



}



Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
const int maxm=1e6+5;
string s[maxm];
int ans;
int n;
struct Trie{
    int a[maxm][26],tot;
    int type[maxm];
    int val[maxm];
    int ed[maxm][26];
    void add(string s){
        int len=s.size();
        int node=0;
        for(int i=len-1;i>=0;i--){
            int v=s[i]-'a';
            if(!a[node][v]){
                a[node][v]=++tot;
                type[tot]=v;
            }
            node=a[node][v];
        }
        val[node]++;
    }
    void dfs(int x){
        for(int i=0;i<26;i++){
            int v=a[x][i];
            if(!v)continue;
            dfs(v);
            val[x]+=val[v];
            for(int j=0;j<26;j++){
                ed[x][j]+=ed[v][j];
            }
        }
        ed[x][type[x]]=val[x];
    }
    void cal(string s){
        int len=s.size();
        int node=0;
        for(int i=len-1;i>=1;i--){
            int v=s[i]-'a';
            node=a[node][v];
        }
        for(int i=0;i<26;i++){
            int v=a[node][i];
            if(!v)continue;
            ans+=ed[v][s[0]-'a'];
//            cout<<s[0]<<' '<<(char)(i+'a')<<' '<<ed[v][s[0]-'a']<<endl;
        }
//        cout<<endl;
    }
}T;
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>s[i];
        T.add(s[i]);
    }
    T.dfs(0);
    for(int i=1;i<=n;i++){
        T.cal(s[i]);
    }
    ans-=n;
    cout<<ans<<endl;
    return 0;
}
/*

*/


Measured memory_bytes: 544076