akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define ri register int
#define N 400005
using namespace std;
int n,m,cnt,ans1,ans2=1e18,b[N],f[N];
map <int,int> mp;
struct node {
	int l,r;
} a[N];
template <typename T> inline void read(T &x) {
	T f=1,c=getchar();
	for (; c<48||57<c; c=getchar()) if (c=='-') f=-1;
	for (x=0; 48<=c&&c<=57; c=getchar()) x=(x<<3)+(x<<1)+(c^48);
	x*=f;
}
template <typename T> inline void print(T x) {
	if (x<0) putchar('-'),x=-x;
	if (x>9) print(x/10);
	putchar(x%10+48);
}
inline int cmp(node a,node b) {
	return a.l^b.l?a.l<b.l:a.r>b.r;
}
signed main() {
	read(n),read(m),b[(n<<1)+1]=m;
	for (ri i=1; i<=n; ++i) read(a[i].l),read(a[i].r),b[i]=a[i].l,b[i+n]=a[i].r;
	sort(b+1,b+2+(n<<1));
	for (ri i=1; i<=(n<<1)+1; ++i)
		if (!mp[b[i]]) mp[b[i]]=++cnt;
	for (ri i=1; i<=n; ++i) a[i].l=mp[a[i].l],a[i].r=mp[a[i].r];
	m=mp[m],sort(a+1,a+1+n,cmp),memset(b,0,sizeof(b));
	for (ri i=1; i<=n; ++i) f[a[i].l]=max(f[a[i].l],a[i].r);
	for (ri i=1,now=0,maxr=f[1]; i<m; ++i) {
		if (now<=i) now=maxr,ans1++;
		maxr=max(maxr,f[i]);
	}
	for (ri i=1; i<=n; ++i) b[a[i].l]++,b[a[i].r]--;
	for (ri i=1; i<=m; ++i) b[i]+=b[i-1];
	for (ri i=1; i<m; ++i) ans2=min(ans2,b[i]);
	print(ans1),putchar(' '),print(n-ans2+1),putchar('\n');
	return 0;
}


Measured memory_bytes: 36252
# include <stdio.h>

int main(void){
  char c;
  
  c = getchar();
  
  if(c != 'a' && c != 'e' && c != 'i' && c != 'o' && c != 'u'){
    printf("consonant\n");
  }else{
    printf("vowel\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int k=sc.nextInt();
    Deque<Long> dq=new ArrayDeque<>();
    if(k<10){
      System.out.println(k);
      return;
    }
    for(long i=1;i<10;i++){
      dq.addLast(i);
    }
    int cnt=9;
    while(true){
      long x=dq.pollFirst();
      long bi=x%10;
      if(bi!=0){
        dq.addLast(x*10+bi-1);
        cnt++;
        if(cnt==k){break;}
      }
      dq.addLast(x*10+bi);
      cnt++;
      if(cnt==k){break;}
      if(bi!=9){
        dq.addLast(x*10+bi+1);
        cnt++;
        if(cnt==k){break;}
      }
    }
    System.out.println(dq.peekLast());
  }
}

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

namespace _0000
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i < 10; i++)
            {
                for (int j = 1; j < 10; j++)
                {
                    Console.WriteLine(i + "x" + j + "=" + i * j );
                }
            }
        }
    }
}



Measured memory_bytes: 13700
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 10;
const int p = 1000000007;
int a[maxn], b[maxn];
int main() {
    int A, B, m;    cin >> A >> B >> m;
    for (int i = 1; i <= A; i++)    cin >> a[i];
    for (int i = 1; i <= B; i++)    cin >> b[i];
    int ans = 1e9;
    for (int i = 1; i <= m; i++) {
        int x, y, c;    cin >> x >> y >> c;
        ans = min(ans, a[x] + b[y] - c);
    }
    sort(a + 1, a + 1 + A);
    sort(b + 1, b + 1 + B);
    ans = min(ans, a[1] + b[1]);
    cout << ans;
    getchar(); getchar();
    return 0;
}

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

const int INF=1000000000,mod=1e9+7;
const double eps = 1e-7;

int f[2001][2001],c[5000000],inv[5000000];


int main()
{
//	freopen("input.txt","r",stdin);
	int t;
	int n,m,q;
//	cin>>t;
//	while(t--)
//	while(scanf("%d",&n)!=EOF) 
	{
		cin>>n>>m;
		if(m==1)
		{
			cout<<1<<endl;
			return 0;
		} 
		f[0][0]=1;
		f[0][1]=1;
		c[m-2]=1;
		inv[1]=1;
		for(int i=2;i<=n*m;i++)
			inv[i]=(long long)inv[mod%i]*(mod-mod/i)%mod;
		for(int i=m-1;i<=n*m;i++)
			c[i]=(long long)c[i-1]*i%mod*inv[i-m+2]%mod;
		for(int i=2;i<=n;i++)
			f[0][i]=(long long)f[0][i-1]*c[i*(m-1)-1]%mod;
		for(int i=1;i<=n;i++)
			for(int j=i;j<=n;j++)
			{
				if(i==j)
					f[i][j]=f[i-1][j];
				else
					f[i][j]=(f[i-1][j]+(long long)f[i][j-1]*c[i+j*(m-1)-1]%mod)%mod;
			}
//		for(int i=1;i<=n;i++)
//			for(int j=i;j<=n;j++)
//				cout<<i<<' '<<j<<' '<<f[i][j]<<endl;
		long long ans=f[n][n];
		for(int i=1;i<=n;i++)
			ans=ans*i%mod;
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 45312
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1e9+7
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

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

int main() {
    ll a, b; cin >> a >> b;
    //最小公倍数出せばいいだけ
    //a*bをgcdで割ればいいね
    int g = gcd(a,b);
    ll ans;
    ans = a*b/g;
    cout << ans << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String c = scan.next();
		String str = "consonant";
		switch(c){
		case "a":
		case "i":
		case "u":
		case "e":
		case "o":
			str = "vowel";
		}
		System.out.println(str);
	}
}


Measured memory_bytes: 35540
N, Q = map(int, input().split())
s = input()
cl = [0 for _ in range(N + 1)]

flg = False
cnt = 0
for i in range(N):
    if s[i] == 'A':
        flg = True
    elif flg:
        if s[i] == 'C':
            cnt += 1
        flg = False
    cl[i + 1] = cnt

for _ in range(Q):
    l, r = map(int, input().split())
    # [1,N]
    p = cl[r] - cl[l - 1]
    if l > 1:
        if s[l- 1] == 'C' and s[l - 2] == 'A':
            p -= 1
    print(p)


Measured memory_bytes: 6200
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n,x,y;
    cin >> n >> x >> y;
    int Counter[n+1] = {};
    for(int i = 1; i < n+1; i++){
        for(int j = 1; j < i; j++){
            int m = min(abs(j-i), abs(j-x)+ 1 +abs(y-i));
            Counter[m] += 1;
        }
    }
    for(int i = 1; i < n; i++){
        cout << Counter[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(lambda x:int(x)-1, input().split()))
reached = [0 for i in range(n)]
trace = [0]
here = 0
reached[0] = 1
while reached[a[here]] != 1:
    trace.append(a[here])
    here = a[here]
    reached[here] = 1
here = a[here]
loop_start = trace.index(here)
l = len(trace)
loop = l - loop_start
if k < loop_start:
    print(trace[k]+1)
else:
    k -= loop_start
    print(trace[k % loop + loop_start]+1)

Measured memory_bytes: 114048
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct UnionFind {
  const int n;
  V<> t, a, b; // root ? -sz : par
  UnionFind(int n) : n(n), t(n, -1), a(n), b(n) {}
  int find(int v) { return t[v] < 0 ? v : t[v] = find(t[v]); }
  void unite(int u, int v) {
    if ((u = find(u)) == (v = find(v))) return;
    if (-t[u] < -t[v]) swap(u, v);
    t[u] += t[v];
    t[v] = u;
    a[u] += a[v];
    b[u] += b[v];
  }
  bool same(int u, int v) { return find(u) == find(v); }
  int size(int v) { return -t[find(v)]; }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int m, p, q;
  while (cin >> m >> p >> q, m or p or q) {
    int n = p + q;
    UnionFind uf(2 * n);
    for (int i = 0; i < n; ++i) uf.a[i] = uf.b[n + i] = 1;
    while (m--) {
      int x, y; cin >> x >> y, --x, --y;
      string s; cin >> s;
      if (s == "yes") {
        uf.unite(x, y);
        uf.unite(n + x, n + y);
      } else {
        uf.unite(x, n + y);
        uf.unite(n + x, y);
      }
    }
    V<> a, b, idx;
    for (int i = 0; i < n; ++i) if (uf.find(i) == i) {
      a.push_back(uf.a[i]);
      b.push_back(uf.b[i]);
      idx.push_back(i);
    }
    int k = a.size();
    VV<> dp(k + 1, V<>(n + 1));
    dp[0][0] = 1;
    for (int i = 0; i < k; ++i) {
      for (int x = 0; x <= n; ++x) {
        if (x + a[i] <= n) dp[i + 1][x + a[i]] += dp[i][x];
        if (x + b[i] <= n) dp[i + 1][x + b[i]] += dp[i][x];
      }
      for (auto&& e : dp[i + 1]) e = min(e, 2);
    }
    if (dp[k][p] == 1) {
      V<> res;
      for (int i = k - 1; i >= 0; --i) {
        if (p - a[i] >= 0 and dp[i][p - a[i]] == 1) {
          for (int x = 0; x < n; ++x) if (uf.same(x, idx[i])) {
            res.push_back(x);
          }
          p -= a[i];
        } else {
          for (int x = 0; x < n; ++x) if (uf.same(x, n + idx[i])) {
            res.push_back(x);
          }
          p -= b[i];
        }
      }
      sort(begin(res), end(res));
      for (int e : res) cout << e + 1 << '\n';
      cout << "end\n";
    } else {
      cout << "no\n";
    }
  }
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	ld r;
	cin>>r;
	ld ans = acos(-1.0);
	ans *= 2*r;
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3812
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <math.h>
#include <time.h>

typedef int32_t i32;
typedef int64_t i64;
typedef double f64;

void *const null=(void *)0;
i64 const llinf=4611686018427387903LL;
i64 const mod=1000000009LL;
f64 const pi=3.141592653589793;
f64 const rad=57.295779513082323;

#define CODE_

i32 main(void){
    i64 pmin=llinf,jmin=llinf;
    i64 a;
    for(i64 i=0LL;i<3LL;++i){
        scanf("%lli%*c",&a);
        if(a<pmin) pmin=a;
    }
    for(i64 i=0LL;i<2LL;++i){
        scanf("%lli%*c",&a);
        if(a<jmin) jmin=a;
    }
    printf("%lli\n",pmin+jmin-50LL);
    return 0;
}



Measured memory_bytes: 2048
#文字列が1つの場合
s = str(input())
#入力が「Sunny」なら「Cloudy」を出力
if s == "Sunny":
    print("Cloudy")
#入力が「Cloudy」なら「Rainy」を出力
elif s == "Cloudy":
    print("Rainy")
#入力が「Rainy」なら「Sunny」を出力
elif s == "Rainy":
    print("Sunny")

Measured memory_bytes: 38256
N = int(input())
SL = []
for i in range(N):
    SL.append(input())
SL.sort()
t = 0
B=0
output = []
while t < N:
    A = SL[t]
    B += 1
    while (t<N-1)and(SL[t]==SL[t+1]):
        B+=1
        t+=1
    output.append([A,B])
    B=0
    t+=1
#
# if SL[N-1]!=SL[N-2]:
#     output.append([SL[N-1],1])

output.sort(key=lambda x:x[1],reverse=True)

print(output[0][0])
t = 1
while (t<len(output))and(output[t-1][1]==output[t][1]):
    print(output[t][0])
    t+=1

Measured memory_bytes: 108752
#include <iostream>

using namespace std;
int main() {
  int W, a, b;

  cin >> W >> a >> b;

  if (a + W < b) {
    cout << b - (a + W) << endl;
    return 0;
  }
  
  if (a > b + W) {
    cout << a - (b + W) << endl;
    return 0;
  }

  if (a + W > b) {
    cout << 0 << endl;
    return 0;
  }

  if (a < b + W) {
    cout << 0 << endl;
    return 0;
  }
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=500050;
//↑templete
#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
ll fact_mod(ll n, ll mod) {
    ll f = 1; repq(i,2,n) f = f * (i % MOD) % MOD;
    return f;
}
// 繰り返し二乗法 (再帰バージョン)
ll mod_pow(ll x, ll n, ll mod) {
    if(n == 0) return 1;
    ll res = mod_pow((x * x) % mod, n / 2 , mod);
    if(n & 1) res = (res * x) % mod;
    return res;
}
// 組み合わせ nCr を求める (modあり)
ll combination_mod(ll n, ll r, ll mod) {
    if(r > n-r) r = n-r;
    if(r == 0) return 1;
    ll a = 1;
    rep(i, 0, r) a = a * ((n-i) % mod) % mod;
    ll b = mod_pow(fact_mod(r, mod), mod-2, mod);
    return (a % mod) * (b % mod) % mod;
}
signed main(){
	//%MOD下での階乗
	ll ex[SIZE]={1,0};
	for(int i=1;i<SIZE;i++){
		ex[i]=ex[i-1]*i%MOD;
	}
	//%MOD下での階乗の逆数
	ll inv[SIZE]={1,0};
	for(int i=1;i<SIZE;i++){
		inv[i]=mod_pow(i,MOD-2,MOD);
	}
	for(int i=1;i<SIZE;i++){
		inv[i]=inv[i-1]*inv[i]%MOD;
	}

	ll N, K;
	cin>>N>>K;

	ll unmoved=max(1LL, N-K), moved=min(N, K);

	ll ans=0;
	for(int i=unmoved;i<=N;i++){
		ll alpha=ex[N-1]*inv[N-1-(N-i)]%MOD*inv[N-i]%MOD;
		ll beta=ex[N]*inv[N-i]%MOD*inv[i]%MOD;
		(ans+=alpha*beta%MOD)%=MOD;
		//cout<<i<<" "<<ans<<endl;
	}
	cout<<ans<<endl;

	// ll ans=combination_mod(N+N-1, N, MOD);
	// if(K>=N-1){
	// 	cout<<ans<<endl;
	// 	return 0;
	// }

	// cout<<combination_mod(N+unmoved-1, N, MOD)<<" "<<combination_mod(N, unmoved, MOD)<<endl;

	// (ans+= MOD-combination_mod(N+unmoved-1, N, MOD)*combination_mod(N, unmoved, MOD)%MOD )%=MOD;
	// cout<<ans<<endl;



	return 0;
}

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

int main() {
  ll X, A;cin >> X >> A;
  if (X >= A) cout << 10 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

struct Node {
    int key;
    Node *left, *right, *parent;
};

Node *root, *NIL;

Node* find(Node *u, int k) {
    while (u != NIL && k != u->key) {
        if (k < u->key) {
            u = u->left;
        }
        else {
            u = u->right;
        }
    }
    
    return u;
}

Node* getMinimum(Node *u) {
    while (u->left != NIL) {
        u = u->left;
    }
    return u;
}

Node* getSuccessor(Node *u) {
    if (u->right != NIL) {
        return getMinimum(u->right);
    }

    Node *y = u->parent;
    while (y != NIL && u == y->right) {
        u = y;
        y = y->parent;
    }
    return y;
}

Node* deleteNode(int key) {
    Node *u = find(root, key);
    Node *x = NIL;
    Node *y = NIL;

    if (u == NIL) {
        return NIL;
    }

    if (u->left == NIL || u->right == NIL) {
        y = u;
    }
    else {
        y = getSuccessor(u);
    }

    if (y->left != NIL) {
        x = y->left;
    }
    else {
        x = y->right;
    }

    if (x != NIL) {
        x->parent = y->parent;
    }

    if (y->parent == NIL) {
        root = x;
    }
    else if (y == y->parent->left) {
        y->parent->left = x;
    }
    else {
        y->parent->right = x;
    }

    if (y != u) {
        u->key = y->key;
    }
}

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = new Node;
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        }
        else {
            x = x->right;
        }    
    }

    z->parent = y;

    if (y == NIL) {
        root = z;
    }
    else if (z->key < y->key) {
        y->left = z;
    }
    else {
        y->right = z;
    }

}

void inorder(Node *u) {
    if (u == NIL) {
        return;
    }
    inorder(u->left);
    cout << " " << u->key;
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NIL) {
        return;
    }
    cout << " " << u->key;
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, i, x;
    string com;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> com;
        if (com == "insert") {
            cin >> x;
            insert(x);
        }
        else if (com == "print") {
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
        else if (com == "find") {
            cin >> x;
            Node *u = find(root, x);
            if (u != NIL) {
                cout << "yes" << endl;
            }
            else {
                cout << "no" << endl;
            }
        }
        else if (com == "delete") {
            cin >> x;
            deleteNode(x);
        }
    }
}

Measured memory_bytes: 21908
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
using namespace std;

bool is_integer(long double x) {
	return std::floor(x) == x;
}
int main() {
	ll N; cin >> N;
	long double temp = sqrt(1 + 4 * N);
	ll pmax = static_cast<ll>((-1 + temp) / 2);

	if (is_integer((-1 + temp) / 2)) {
		pmax--;
	}
	ll ans = 0;
	for (int p = 1; p <= pmax; p++) {
		if (N % p == 0 and N != p) {
			ans += N / p - 1;
		}
	}
	
	if (N == 2) {
		ans = 0;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#ifdef DBG1
  #define LOCAL
#endif

#ifdef LOCAL
  #define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifdef DBG1
    #define dbg(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dbg(...)
#endif

using namespace std;

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

void dfs(int s, int p, const vector<vector<int>> & ed, vector<int> & par, vector<int> & dist) {
  par[s] = p;
  dist[s] = (p == -1 ? 0 : dist[p] + 1);
  for (int v : ed[s]) {
    if (v == p) { continue; }
    dfs(v, s, ed, par, dist);
  }
}

vector<int> findDist(const vector<vector<int>> & ed, int s, vector<int> & par) {
  par.clear();
  par.assign(ed.size(), -1);
  vector<int> dist(ed.size(), -1);
  dfs(s, -1, ed, par, dist);
  return dist;
}

vector<int> solve(int x, int &y, const vector<vector<int>> & ed) {
  int n = int(ed.size());
  vector <int> par;
  vector<int> d = findDist(ed, x, par);
  y = max_element(d.begin(), d.end()) - d.begin();

  dbg("x %d y %d\n", x, y);

  vector <bool> used(n, false);
  for (int i = y; i != -1; i = par[i]) {
    used[i] = true;
    dbg("%d ", i);
  }
  dbg("\n");

  vector <int> cnt(n, 0);
  for (int i = 0; i < n; ++i) {
    if (used[i]) { continue; }
    if (!used[par[i]]) {
      return vector<int>();
    }
    cnt[d[par[i]]] += 1;
  }
  
  vector <int> perm;
  int num = 0;
  for (int i = 0; i <= d[y]; ++i) {
    int z = num++;
    for (int j = 0; j < cnt[i]; ++j) {
      perm.push_back(num++);
    }
    perm.push_back(z);
  }

  assert((int)perm.size() == n);
  return perm;
}

bool solve() {
  int n;
  if (scanf("%d", &n) != 1) { return false; }

  vector <vector<int>> ed(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u, --v;
    ed[u].push_back(v);
    ed[v].push_back(u);
  }
  vector <int> par;
  vector<int> d = findDist(ed, 0, par);
  int x = max_element(d.begin(), d.end()) - d.begin();

  int y;
  vector <int> res1 = solve(x, y, ed);
  if (res1.empty()) {
    printf("-1\n");
    return true;
  }
  int z;
  vector <int> res2 = solve(y, z, ed);

  vector<int> res = min(res1, res2);
  for (int z : res) {
    printf("%d ", z + 1);
  }
  printf("\n");

  return true;
}

int main() {
  while (solve());
  return 0;
}

Measured memory_bytes: 16736
// Problem : B - ... (Triple Dots)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#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<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int k; string s;
	cin >> k >> s;
	if (sz(s) <= k) cout << s;
	else {
		s = s.substr(0, k);
		cout << s << "...";
	}
	return 0;
}
 


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

#define MAX 1000000001
#define ARRAY_SIZE 500001

int A[ARRAY_SIZE];
int ans = 0;
int n;

void print(){
    for(int i = 0; i < n; i++){
        if(i != 0)  cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << ans << endl;
}

void merge(int A[], int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1 + 1];
    int R[n2 + 1];
    for(int i = 0; i < n1; i++) L[i] = A[left + i];
    for(int i = 0; i < n2; i++) R[i] = A[mid + i];
        L[n1] = MAX;
        R[n2] = MAX;

        int li = 0;
        int ri = 0;

        for(int i = left; i < right; i++){
            if(L[li] <= R[ri]){
            A[i] = L[li];
            li++;
            }else{
                A[i] = R[ri];
                ri++;
            }
            ans++;
        }
    }

void mergesort(int A[], int left, int right){
    if(left + 1 < right){
    int mid = (left + right) / 2;
    mergesort(A,left,mid);
    mergesort(A,mid,right);
    merge(A,left, mid, right);
    }
}

int main(){
    cin >> n;
    for(int i = 0; i < n; i++) cin >> A[i];
    mergesort(A,0,n);
    print();
    return 0;
}


Measured memory_bytes: 7020
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 100005;

int di[] = { -1, 0, 0, 1 };
int dj[] = { 0, -1, 1, 0 };

int n;
bool p[100005];
vi primes;

void sieve() {
	MMS(p, 1);
	p[0] = p[1] = 0;
	for (int i = 2; i < N; i++) {
		if (p[i]) {
			for (int j = 2 * i; j < N; j += i)
				p[j] = 0;
		}
	}
	for (int i = 2; i < N; i++) {
		if (p[i])
			primes.pb(i);
	}
}

ll a[501][501];

ll setV(int i, int j) {
	int d0 = (i + j) >> 1;
	int d1 = n + ((i - j + n - 1) >> 1);
	return primes[d0] * 1LL * primes[d1];
}

ll get(int i, int j) {
	if (i < 0 || i >= n || j < 0 || j >= n)
		return -1;
	return a[i][j];
}

ll calc(int i, int j) {
	ll res = 1;
	for (int d = 0; d < 4; d++) {
		int ni = i + di[d];
		int nj = j + dj[d];
		ll v = get(ni, nj);
		if (v != -1)
			res = res / __gcd(res, v) * v;
	}
	return res + 1;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	sieve();
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (((i + j) & 1) == 0) {
				a[i][j] = setV(i, j);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (((i + j) & 1)) {
				a[i][j] = calc(i, j);
			}
		}
	}
	if (n == 2) {
		a[1][0] *= 2;
		a[1][0]--;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << a[i][j] << " \n"[j == n - 1];
		}
	}
	return 0;
}


Measured memory_bytes: 5376
# coding: utf-8

def main():
    a, b, c, d = input()
    for o1 in ["+", "-"]:
        for o2 in ["+", "-"]:
            for o3 in ["+", "-"]:
                s = "".join([a, o1, b, o2, c, o3, d])
                if eval(s) == 7:
                    return s + "=7"


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 3060
package main

import "fmt"

func main(){
  var l int
  var s1,s2,ans string
  fmt.Scan(&l, &s1, &s2)
  for i:=0;i<l;i++{
    ans += string(s1[i])
    ans += string(s2[i])
  }
  fmt.Println(ans)
}


Measured memory_bytes: 512
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0; i<n; i++)
#define rep2(i,a,b) for(ll i=a; i<=b; i++)
#define drep2(i,a,b) for(ll i=a; i>=b; i--)
int sos[60000];
int sos5[60000];
void init()
{
  int index = 1;
  int index2= 0;
  int sosunum = 0;

  sos[0] = 2;

  rep2(n,3,60000) {
    bool sosu = true;
    int sosunum = n;
    rep(j,index-1) {
      if (n % sos[j] == 0) {
        sosu = false;
        break;
      }
    }
    if (sosu) {
      if (sosunum % 5 == 1) {
        sos5[index2++] = sosunum;
      }
      sos[index++] = sosunum;
    }
  }
}
bool check(int n) 
{
  rep(i,60000)
    if (sos[i] == n)
      return true;
  return false;
}


int main ()
{
  init();
  int n;
  cin >> n;
  rep(i,n) {
    cout << sos5[i] << " ";
  }
  cout << endl;
  
//  rep(i,50000) {
//    cout << "This is sosu  " << i << " : " << sos5[i] << endl;
//  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int To10(char c);
main(){
  long long n;
  string s;
  string s2;
  string to2[16]={"0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"};
  cin>>n;
  for(int i=0;i<n;i++){
    double ans=0;
    cin>>s;
    s2="";
    for(int i=0;i<s.size();i++){
      s2+=to2[To10(s[i])];
    }
    long long plus=1;
    for(int i=24;i>=1;i--){
      if(s2[i]=='1'){
	ans+=plus;
      }
      plus*=2;
    }
    double pl=0.5;
    for(int i=25;i<=31;i++){
      if(s2[i]=='1'){
	ans+=pl;
      }
      pl/=2;
    }
    if(s2[0]=='1'){
      printf("-");
    }
    char buff[128];
    sprintf(buff,"%.12lf",ans);
    bool syosuten=false;
    long long last=-1;
    long long point=0;
    for(int i=0;i<strlen(buff);i++){
      if(syosuten&&buff[i]!='0'){
	last=i;
      }
      if(!syosuten) cout<<buff[i];
      if(buff[i]=='.'){
	point=i;
	syosuten=true;
      }
    }
    if(last==-1){
      printf("0\n");
    }
    else{
      for(int i=point+1;i<=last;i++){
	cout<<buff[i];
      }
      cout<<endl;
    }
  }
}
int To10(char c){
  if(c>='0'&&c<='9'){
    return c-'0';
  }
  else{
    return c-'a'+10;
  }
}

Measured memory_bytes: 3256
#!/usr/bin/env python3

def main():
    s = input()
    K = int(input())
    substrings = []

    for i in range(len(s)):
        for ii in range(i,len(s)):
            if len(s[i:ii+1]) > K:
                break
            if s[i:ii+1] not in substrings:
                substrings.append(s[i:ii+1])
    
    substrings.sort()
    print(substrings[K-1])
        

if __name__ == "__main__":
    main()


Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int i,j,k,sum=0;
  for(i=1;i<=n;i++)
    for(j=1;j<=n;j++)
      for(k=1;k<=n;k++)
        sum+=__gcd(i,__gcd(j,k));
  cout << sum << endl;
  return 0;
}  

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int w = Integer.parseInt(in.next());
		int h = Integer.parseInt(in.next());
		int x = Integer.parseInt(in.next());
		int y = Integer.parseInt(in.next());
		int r = Integer.parseInt(in.next());
		int count = 0;
		if (x < r || w - x < r) {
			count++;
		} else if (y < r || h - y < r) {
			count++;
		}
		
		System.out.println(count == 1 ? "No" : "Yes");
	}
}	


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

int main( void )
{
    string s1,s2,s3;
    cin >> s1 >> s2 >> s3;
    
    char ans[3] = {s1[0] - 0x20,s2[0] - 0x20,s3[0] - 0x20};
    
    cout << ans << endl;
}


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

int main()
{
	int a, b;
	std::cin >> a >> b;

	int d = a / b;
	int r = a % b;
	double f = static_cast<double>(a) / b;

	std::cout << d << " " << r << " " << std::fixed << std::setprecision(5) << f << std::endl;
}

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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;


int main(){
  ll l;
  cin >> l;	
  ld ans = 0;
  
  ans = (ld)l / 3.0;
  ans = pow(ans, 3);
  
  cout << fixed << setprecision(12);
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=(ll)(1e9+7);
ll run();
int main() {
#ifdef home
    freopen("i", "r", stdin);
    freopen("d", "w", stderr);
#endif
    cout.precision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    run();
    return 0;
}
const ll inf = (1e8+5);
void max_self(ll &a, ll b) {
    a = max(a, b);
}
void min_self(ll &a, ll b) {
    a = min(a, b);
}
void mul(ll &a, ll b) {
    a = (a * b) % mod;
}
void add_self(ll &a, ll b){
    a+=b;
    if(a>=mod)
        a-=mod;
}
ll gcd(ll a, ll b){
    return b?gcd(b,a%b):a;
}

int a[21][21];

ll run() {
    int n,m,c;
    cin>>n>>m>>c;
    vector<int> b(m+1);
    for(int i=1;i<=m;i++)
        cin>>b[i];

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }

    int ans = 0;
    for(int i=1;i<=n;i++){

        ll val = 0;
        for(int j=1;j<=m;j++){

            val += a[i][j]*b[j];
        }
        val +=c;
        if(val>0)
            ans++;
    }

    cout<<ans;

}


















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

using namespace std;

int main() {
    string s, word;
    int cnt = 0;

    getline(cin, word);

    int i{0}, j{0}, k{0};
    while (cin >> s) {
        for_each(s.begin(), s.end(), [](char &c) {
            c = tolower(c);
        });
        if (s==word) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<queue<int>>A(N);
    queue<int>next;
    map<int,int>Mp;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N-1; j++) {
            int a;
            cin >> a;
            a--;
            A[i].push(a);
        }
        Mp[i] = A[i].front();
        next.push(i);
    }
    int sum = 0;
    int i = 0;
    while(true) {
        i++;
        set<int>st;
        while(!next.empty()) {
            int x = next.front();
            next.pop();
            if(Mp[Mp[x]] == x) {
                st.insert(x);
                st.insert(Mp[x]);
            }
        }
        for(int x:st) {
            A[x].pop();
            if(!A[x].empty()) {
                Mp[x] = A[x].front();
                next.push(x);
            }
            sum++;
        }
        st.clear();
        if(sum == N*(N-1)) {
            break;
        }
        if(next.empty()) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << i << endl;
}

Measured memory_bytes: 8080
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <numeric>
#include <list>
#include <deque>
#include <map>
#include <set>

using namespace std;

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), rend()
#define PB pushback
#define SORT(c) sort((c).begin(),(c).end())

const LL INF = 1LL << 60;

//priority_queue<int> p;

LL i, j, k, tmp, ans, cnt, N, A, B, M;
string s;

//scanf("%d",&N);

//printf("%d", ans);

//cout <<  << endl;


int main(void) {
	vector<pair<LL, LL>>vec;

	scanf("%lld %lld", &N, &M);
	for (LL i = 0; i < N; i++) {
		pair<LL, LL> P;
		scanf("%lld %lld", &A, &B);
		P.first = A;
		P.second = B;
		vec.push_back(P);
	}
	SORT(vec);
	for (LL i = 0; i < N && M > 0; i++) {
		if (M >= vec.at(i).second) {
			M -= vec.at(i).second;
			ans += vec.at(i).first * vec.at(i).second;
		}
		else {
			ans += vec.at(i).first * M;
			M = 0;
		}
	}
	
	printf("%lld", ans);
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  if (n % 2 == 0) cout << double(0.5) << endl;
  else{
    int m = n / 2 + 1;
    cout << double(m) / double(n) << endl;
  }
}


Measured memory_bytes: 3788
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cctype>
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
    char num[4];
    cin >> num;
    if(num[0]==num[2]){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
    return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int h, w, n;
	cin >> h >> w >> n;
	vector<int> a(n);
	for (auto& e : a)
		cin >> e;

	vector<vector<int>> ans(h, vector<int>(w));

	int k = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int jj = i % 2 == 0 ? j : w - 1 - j;
			if (a[k] == 0) k++;
			ans[i][jj] = k + 1;
			a[k]--;
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << ans[i][j] << " ";
		}
		cout << "\n";
	}
}

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

using namespace std;

typedef long long ll;

#define PRIME 1000000007

ll powMod(ll base, ll pow, ll mod) {
  ll result = 1;
  
  while (pow > 0) {
    if (pow & 1 == 1) {
      result = result * base;
      result %= mod;
    }
    
    base = base * base;
    base %= mod;
    pow >>= 1;
  }
  
  return result;
}

ll factMod(int n, int m, ll mod) {
  ll a = 1;
  ll b = 1;
  
  for (int i = 1; i <= m; i++) {
    a *= n - m + i;
    a %= mod;
    
    b *= powMod(i, mod - 2, mod);
    b %= mod;
  }
  
  return (a * b) % mod;
}

int main() {
  ll N, a, b;
  
  cin >> N >> a >> b;
  
  ll ans = powMod(2, N, PRIME) - 1 - factMod(N, a, PRIME) - factMod(N, b, PRIME);
  
  while (ans < 0) {
    ans += PRIME;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<math.h>
#include <string>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
ll mod=1e9+7;

int main(){
	while(1){
		int n,m; cin >>n>>m;
		if(n==0&&m==0)break;
		vector<int> h(n),w(m);
		int cnth[n+1]; int cntw[m+1];
		cinf(n,h); cinf(m,w);
		cnth[0]=0; cntw[0]=0;
		for(int i=0;i<n;i++){
			cnth[i+1]=cnth[i]+h[i];
		}
		for(int i=0;i<m;i++){
			cntw[i+1]=cntw[i]+w[i];
		}
		vector<int> ws,hs;
		for(int i=0;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				hs.push_back(cnth[j]-cnth[i]);
			}
		}
		for(int i=0;i<=m;i++){
			for(int j=i+1;j<=m;j++){
				ws.push_back(cntw[j]-cntw[i]);
			}
		}
		sort(hs.begin(),hs.end());
		sort(ws.begin(),ws.end());
		int hc=0; int wc=0;
		int x,y;
		int cnt=0;
		while(wc<ws.size()&&hc<hs.size()){
			if(hs[hc]==ws[wc]){
				x=0;y=0;
				while(ws[wc+x]==ws[wc]&&wc+x<ws.size()) x++;
				while(hs[hc+y]==hs[hc]&&hc+y<hs.size()) y++;
				cnt+=x*y;
				wc+=x;hc+=y;
			}
			else if(ws[wc]>hs[hc]){
				while(ws[wc]>hs[hc]&&hc<hs.size()) hc++;
			}
			else{
				while(ws[wc]<hs[hc]&&wc<ws.size())wc++;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 19720
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(void) {
    int n, i;
    double ans;
    scanf("%d", &n);
    
    int l[120];
    for(i=0; i<n; i++) {
        scanf("%d", &l[i]);
        
    }

    sort(l, l+n, std::greater<int>() );
    int comp = 0;

    for(i=1; i<n; i++) {
        comp += l[i];
        
    }
    //printf("%d %d", l[0], comp);

    if (l[0] < comp) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}


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

stack<int> S1,S2;
int A[10];
bool flag;

int ball(int a){
	while (1){
		flag = false;
		if (S1.top() < A[a]){
			S1.push(A[a]);
			a++; flag = true;
		}
		else if (S2.top() < A[a]){
			S2.push(A[a]);
			a++; flag = true;
		}
		if (flag == false) {
			return 0;
		}
		if (a == 10) {
			return 1;
		}
	}
}



int main(){
	int N;
	cin >> N;
	for (int i = 0; i < N; i++){
		for (int l = 0; l < 10; l++) cin >> A[l];
		S1.push(0);
		S2.push(0);
		int a = 0;
		if (ball(a)) cout << "YES" << endl;
		else cout << "NO" << endl;
		a = 0;
		while (!S1.empty()) S1.pop();
		while (!S2.empty()) S2.pop();
	}
	return 0;
}

Measured memory_bytes: 1192
import sys
N = int(input())
a = [(int(v),i) for i, v in enumerate(input().split())]
ao = sum([v for v, i in a if i%2 and v>0])
ae = sum([v for v, i in a if not i%2 and v>0])
if max(ao, ae)== 0:
    ai = a.index(max(a))
    Ans = [1]*(ai)+list(range(N-ai,1,-1))
    print(max(a)[0])
    print(len(Ans))
    for i in Ans:
        print(i)
    sys.exit()
if ao >= ae:
    print(ao)
    yn = [i for v, i in a if i%2 and v>0]
else:
    print(ae)
    yn = [i for v, i in a if not i%2 and v>0]
listyn = [i in yn for i in range(N)]
Ans = []
while not listyn[0]:
    Ans.append(1)
    listyn = listyn[1:]
while not listyn[-1]:
    Ans.append(len(listyn))
    listyn = listyn[:-1]
while True:
    if len(listyn) == 1:
        break
    if len(listyn) == [2,3]:
        Ans.append(2)
        break
    if listyn[2]:
        Ans.append(2)
        listyn = [True] + listyn[3:]
    else:
        Ans.append(3)
        listyn = [True, False] + listyn[4:]
print(len(Ans))
for i in Ans:
    print(i)

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

int main()
{
  int x , y;
  int a[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  cin >> x >> y;
  if(a[x] == a[y]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3616
def p_b():
    n = int(input())
    t, a = map(int, input().split())
    *H, = map(int, input().split())
    ans = 10**9
    idx = -1
    for i, h in enumerate(H):
        if ans > abs(a - (t - h * 0.006)):
            ans = abs(a - (t - h * 0.006))
            idx = i + 1
    print(idx)
    
p_b()

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

int main(){
  int k;
  string s;
  cin>>k;
  cin>>s;
  int len=s.length();
  if(k>=len) cout<<s;
  else {
    for(int i=0;i<k;i++){
      cout<<s[i];
    }
    cout<<"..."<<endl;
  }
  return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>

int main(void){

	int n,i,a;
	long min,max,sum;
	scanf("%d\n",&n);

	max = -1000000;
	min = 1000000;
	sum = 0;

	for(i=0; i<n; i++){
		scanf("%d\n",&a);
		if(max<a) max = a;
		if(min>a) min = a;
		sum += a;
	}

	printf("%ld %ld %ld\n",min,max,sum);

	return 0;
}

Measured memory_bytes: 604
n = int(input())
s = [input() for i in range(n)]
existed = {}
c = 0
for i in range(n):
  sorted_s = ''.join(sorted(s[i]))

  if sorted_s in existed:
    c += existed[sorted_s]
    existed[sorted_s] += 1
  else:
    existed[sorted_s] = 1
print(c)


Measured memory_bytes: 25036
#include<bits/stdc++.h>
#define f(a,j,k) for(int i = a ; i < j ; i += k)
#define f1(a,j,k) for(int i = a ; i > j ; i -= k)
using namespace std;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<int> vi;
typedef pair<int,int> pri;
typedef pair<long long,long long> prl;
int n;
void dfs(char mx,string s){
	  if(s.length() == n){
			 printf("%s\n",s.c_str());
			 return;
		}
		 f('a',mx+1,1) if(i == mx) dfs(mx+1,s+(char)i);
		 else dfs(mx,s+(char)i);
}
int main() {
	std::ios::sync_with_stdio(false);

	cin >> n;
	dfs('a',"");
	return 0;
}


Measured memory_bytes: 1536
//Zory-2019
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef __int128 ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;GG(e<0)while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    ll a[N],b[N];
    void main()
    {
		int n=qread();
		fo(i,1,n) a[i]=b[i]=1;
		fo(i,1,n)
		{
			int pos=qread();
			a[pos]+=i,b[pos]+=i;
		}
		ll mi=bin(62);fo(i,1,n) a[i]+=a[i-1],chmin(mi,a[i]);fd(i,n,1) b[i]+=b[i+1],chmin(mi,b[i]);
		fo(i,1,n) write1(a[i]-mi+1);puts("");fo(i,1,n) write1(b[i]-mi+1);
    }
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}

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

int main() {
  int D;
  cin >> D;
  if (D == 25)
  {
    cout << "Christmas" << endl;
  }
  else if (D == 24)
  {
    cout << "Christmas Eve" << endl;
  }
  else if (D == 23)
  {
    cout << "Christmas Eve Eve" << endl;
  }
  else if (D == 22)
  {
    cout << "Christmas Eve Eve Eve" << endl;
  }
}

Measured memory_bytes: 3616
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (a : b : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  print $ if a >= 13 then b else if a <= 5 then 0 else b `div`2

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
int N,K;
vector<int>d;
vector<vector<int>>A;
void first(){
  cin >> N >> K;
  d.resize(K);
  A.resize(K,vector<int>());
  for(int i=0;i<K;i++){
    cin >> d[i];
    A[i].resize(d[i]);
    for(int j=0;j<d[i];j++){
      cin >> A[i][j];
    }
  }
}
  
  void second(){
    int ans=0;
    for(int i=1;i<=N;i++){
      bool have=false;
      for(auto x:A){
        for(auto y:x){
          if(i==y)have=true;
        }
      }
      if(!have)ans++;
    }
    cout << ans << endl;
  }

int main(){
  first();
  second();
}

Measured memory_bytes: 3592