akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int n;
    cin >> n;
    vector<int>div;
    int init_n = n;
    for(int i = 2;i*i<=n;i++) {
        if(n%i==0)div.push_back(i);
        while(n%i==0) {
            n /= i;
        }
    }
    if(n != 1) div.push_back(n);
    int ans = 0;
    int m = div.size();
    for(int bit = 1;bit < (1<<m);bit++) {
        int popcnt = __builtin_popcount(bit); //偶数か奇数の積集合か見る
        int mul = 1;
        for(int i = 0;i<m;i++) {
            if(bit >> i & 1) {
                mul *= div[i];
            }
        }
        if(popcnt%2 == 0) ans -= init_n/mul;
        else ans += init_n/mul;
    }
    ans = init_n - ans;
    cout << ans << endl;

}


Measured memory_bytes: 3120
"use strict"
function main(arg) {
    arg = arg.trim().split("\n")[0].split(" ").map(Number)
    var n = arg.pop()
    arg.sort((a,b) => b - a)
    var r = arg[0]
    var g = arg[1]
    var b = arg[2]
    // var n = arg[3]
    var count = 0
    var MAX = Number.MAX_SAFE_INTEGER
    for (var i = 0; i < MAX; i++) {
        var _r = r * i
        if (_r > n) break
        for (var j = 0; j < MAX; j++) {
            var _g = g * j
            if (_g > n) break
            var s = n - (_r + _g)
            if (s < 0) {
                break
            }
            // console.log(s)
            if (s % b === 0) {
                count++
            }
            // for (var k = 0; k < MAX; k++) {
            //     var _b = b * k
            //     if (_b > n) break
            //     var v = _r + _g + _b
            //     if (v > n) break
            //     if (v === n) {
            //         count++
            //     }
            // }
        }
    }
    console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(){
  int N, T, A;
  cin >> N;
  cin >> T >> A;
  int H[N];
  for(int i = 1; i <= N; i++) cin >> H[i];
  
  double close_temp;
  int result_num = 1;
  for(int i = 1; i <= N; i++){
    double temp = T - H[i] * 0.006;
    if(i == 1) close_temp = temp;
    if (fabs(close_temp - A) > fabs(temp - A)){
      close_temp = temp;
      result_num = i;
    }
  }
  cout << result_num << endl;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=100005,M=100005,mod=1e9+7,B=100000;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
inline void read(int &x){
	x=0;char ch=getchar(),rev=0;
	while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=rev?-x:x;
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,m,a,b,x[N];

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	scanf("%d%d%d%d",&n,&m,&a,&b);
	if(n%a==0&&m%b==0){puts("No");return 0;}
	puts("Yes");
	if(n%a!=0){
		for(int i=1;i<=n;i++)
			if(i%a==0) x[i]=-(a-1)*B-1; else x[i]=B;
		for(int i=1;i<=n;i++,puts(""))
			for(int j=1;j<=m;j++)
				printf("%d ",x[i]);
		return 0;
	}
	for(int i=1;i<=m;i++)
		if(i%b==0) x[i]=-(b-1)*B-1; else x[i]=B;
	for(int i=1;i<=n;i++,puts(""))
		for(int j=1;j<=m;j++)
			printf("%d ",x[j]);
	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int A[n];
  for(int i = 0 ; i < n ; i++){
    cin >> A[i];
  }
  for(int i = n-1 ; i >= 0 ; i--){
    if(i != 0) cout << A[i] << ' ';
    else cout << A[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
  string s;
  cin>>s;
  int N=s.size();
  int ans=0;
  bool w=false;
  int m;
  int k=0;
  for(int i=0;i<N;i++){
    if(s[i]=='B'&&w==false){
      w=true;
      m=i;
    }
    if(w&&s[i]=='W'){
      ans+=i-m-k;
      k++;
    }
  }
  //cout<<m<<" "<<k<<" "<<w<<endl;
  cout<<ans<<endl;
}


Measured memory_bytes: 640
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 >=10){
			System.out.print(B);
			
		}else {
			int t = 100*(10-A);
			int x = (B+t);
			System.out.print(x);
		}
		
		

	}
}




Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define int long long
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

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

    int h,w;
    char a[101][101];
    cin >> h >> w;
    for(int i = 1; i <= h; i ++){
        for(int j = 1; j <= w; j ++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i <= h+1; i ++){
        for(int j = 0; j <= w+1; j ++){
            if(i == 0 || j == 0 || i == h+1 || j == w+1){
                cout << "#";
            }else{
                cout <<a[i][j];
            }
        }
        cout << "\n";
    }
    return 0;
}









Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main(){
  int N, D;
  cin >> N >> D;
  int X[N][D];
  REP(i, 0, N){
    REP(j, 0, D){
      cin >> X[i][j];
    }
  }
  int ans = 0;
  REP(i, 0, N-1){
    REP(j, i+1, N){
      int d_2 = 0;
      REP(k, 0, D){
        d_2 += pow((X[i][k] - X[j][k]), 2);
      }
      // cout << d_2 << endl;
      if (d_2 == pow((int)sqrt(d_2), 2))
        ans++;
    }
  }

  cout << ans << endl;

  return 0;
}
 

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

ll gcd(ll x, ll y)
{
    if(y==0) return x;
    else return gcd(y,x%y);
}

int main()
{
    ll a,b,c,d;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);

    ll diva=((a-1)/c)+((a-1)/d)-(a-1)/(c*d/gcd(c,d));
    ll divb=(b/c)+(b/d)-(b/(c*d/gcd(c,d)));
    printf("%lld\n",b-a+1-divb+diva);
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace Be_Together
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var nums = Console.ReadLine().Split(' ')
                .Select(x => int.Parse(x)).ToArray();

            var minCost = double.MaxValue;
            for (int i = -100; i <= 100; i++)
            {
                var cost = CalcCost(nums, i);
                if (minCost > cost)
                {
                    minCost = cost;
                }
            }

            Console.WriteLine(minCost);
        }

        private static double CalcCost(int[] nums, int replaceNum)
        {
            double cost = 0;
            foreach (var num in nums)
            {
                cost = cost + Math.Pow((num - replaceNum), 2);
            }
            return cost;
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()
#define mp make_pair

using namespace std;

typedef long long ll;

vector<pair<int, ll> > G[100005];
ll d[100005];
bool used[100005];

void bfs(int s) {
  queue<int> Q;
  d[s] = 0;
  used[s] = true;
  Q.push(s);
  while (!Q.empty()) {
    int u = Q.front(); Q.pop();
    for (int i = 0; i < (int) G[u].size(); i++) {
      int v = G[u][i].first;
      int w = G[u][i].second;
      if (!used[v]) {
        used[v] = true;
        d[v] = d[u] + w;
        Q.push(v);
      }
    }
  
  }

}

int N;

int main() {
  scanf("%d", &N);
  rep(i, 0, N-1) {
    int a, b; ll c;
    scanf("%d %d %lld", &a, &b, &c);
    G[a].pb(mp(b, c));
    G[b].pb(mp(a, c));
  }
  
  int Q, K;
  scanf("%d %d", &Q, &K);
  bfs(K);
  
  rep(i, 0, Q) {
    int x, y;
    scanf("%d %d", &x, &y);
    printf("%lld\n", d[x]+d[y]);
  
  }
  
  return 0;
  

}

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

int main()
{
    int N;
    cin >> N;
    int a[N];

    for (int i = 0; i < N; i++)
        cin >> a[i];
    
    int uns = 0;
    for (int i = 0; i < N - 1; i++) {
        int count = 1;
        int j;
        for (j = i + 1; j < N; j++) {
            if (a[i] == a[j]) {
                count++;
            }
            else {
                break;
            }
        }
        if (count == 1) {
            ;
        }
        else {
            uns += count / 2;
            i = j - 1;
        }
    }
    cout << uns;

    return 0;
}


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

int main(){
	int s;
	cin >> s;
	vector<int> a = { s };
	while (true) {
		int num;
		if (a[a.size() - 1] % 2 == 0) {
			num = a[a.size() - 1] / 2;
		}
		else {
			num = a[a.size() - 1] * 3 + 1;
		}
		for (int i = 0;i < a.size();++i) {
			if (num == a[i]) {
				cout << a.size() + 1 << endl;
				return 0;
			}
		}
		a.push_back(num);
	}
	return 0;
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> B(N), F(N), R(N), V(N);
    vector<vector<vector<int>>> A(4,vector<vector<int>>(3,vector<int>(10, 0)));

    for(int i = 0; i < N; i++){
        cin >> B.at(i) >> F.at(i) >> R.at(i) >> V.at(i);
    }

    for(int i = 0; i < N; i++){
        int b = B.at(i), f = F.at(i), r = R.at(i), v = V.at(i);
        A.at(b-1).at(f-1).at(r-1) += v;
    }

    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 10; k++){
                cout << " " << A.at(i).at(j).at(k);
            }
            cout << endl;
        }
        if(i < 3) cout << "####################" << endl;
    }
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


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

  int a,b;
  cin>>a>>b;
  if(a>9||b>9){
    cout<<-1<<endl;
  }else{
    cout<<a*b<<endl;
  }


}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
 
int main() {
    int x, y, a, b, t, ans = 2000000100;
    cin >> x >> y;
    a = x;  b = y;

    if(x <= y) {
        t = y-x;
        ans = min(t, ans);
    }

    x *= -1;
    if(x <= y) {
        t = y-x+1;
        ans = min(t, ans);
    }

    x = a;
    y *= -1;
    if(x <= y) {
        t = y-x+1;
        ans = min(t, ans);
    }

    y = b;
    x *= -1;
    y *= -1;
    if(x <= y) {
        t = y-x+2;
        ans = min(t, ans);
    }
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
	for (int i = 0; i < len; i++) {
    if (i > 0) s << ", ";
		s << v[i];
  }
  s << "]";
  return s;
}

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

  int64 n;
  cin >> n;

  vector<int64> ps(18);
  ps[0] = 1;
  for (int i = 1; i < 18; i++) {
    ps[i] = ps[i - 1] * 10;
  }

  auto solve_d = [&](int d) -> int64 {
    vector<int64> xs;
    for (int i = 0; i < d / 2; i++) {
      xs.push_back(ps[d - 1 - i] - ps[i]);
    }
    if (DEBUG) cout << "d: " << d << endl;
    if (DEBUG) cout << "xs: " << xs << endl;

    int e = xs.size();
    int64 r = 0;
    function<void(int, int64, int64)> dfs_fn = [&](int k, int64 c, int64 q) {
      if (k == e) {
        r += q;
        return;
      }

      int64 min_delta = 0;
      int64 max_delta = 0;
      for (int i = k + 1; i < e; i++) {
        min_delta -= 9 * xs[i];
        max_delta += 9 * xs[i];
      }

      for (int diff = -9; diff <= 9; diff++) {
        int64 next_c = c + diff * xs[k];
        if (next_c + max_delta < n) continue;
        if (next_c + min_delta > n) continue;
        int64 q_m = 10 - abs(diff);
        if (k == 0 && diff >= 0) q_m--;
        if (q_m == 0) continue;
        dfs_fn(k + 1, next_c, q * q_m);
      }
    };
    dfs_fn(0, 0, 1);

    if (d % 2 == 1) r *= 10;

    return r;
  };

  int64 ans = 0;
  for (int d = 2; d <= 18; d++) {
    ans += solve_d(d);
  }
  cout << ans << endl;
}

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



int main(){
  string S;
  cin>>S;
  int64_t sum=0;
  int64_t kaz=0;
  for(int i=0;i<(int64_t)S.size();i++){
    if(S.at(i)=='W'){
      sum+=i;
      kaz++;
    }
  }
  int64_t N=kaz-1;
  cout<<sum-(N+1)*N/2<<endl;
  
}

Measured memory_bytes: 3736
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int a[2] = {-1, -1};
for (int i = N; i > 0; --i) {
        int cnt = 0;    
        int tmp = i;
        while (tmp > 1) {
                if (tmp % 2 != 0) {
                        break;
                } else {
                        cnt++;
                        tmp /= 2;
                }   
        }   
        if (a[1] < cnt) {
                a[0] = i;
                a[1] = cnt;
        }   
}
cout << a[0] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <atcoder/mincostflow>

using namespace std;

const long long INF = 1LL << 30;

int main(){
    int N, K; cin >> N >> K;
    vector A(N, vector(N, 0));
    for(auto& v : A){
        for(auto& t : v) cin >> t;
    }
    atcoder::mcf_graph<int, long long> mcf(2*N+2);
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            mcf.add_edge(i, N+j, 1, INF-A[i][j]);
        }
        mcf.add_edge(2*N, i, K, 0);
        mcf.add_edge(N+i, 2*N+1, K, 0);
    }
    mcf.add_edge(2*N, 2*N+1, N*K, INF);
    cout << N*K*INF - mcf.flow(2*N, 2*N+1, N*K).second << endl;
    vector<string> res(N, string(N, '.'));
    for(auto& e : mcf.edges()){
        if(e.from >= 2*N || e.to >= 2*N || !e.flow) continue;
        res[e.from][e.to-N] = 'X';
    }
    for(auto& s : res) cout << s << endl;
}

Measured memory_bytes: 3948
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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;
}

int main(void) {
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;

    if (A1 + A2 + A3 >= 22) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }
    
    return 0;
}


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

int h;
int w;
int ans;
int c[1400][1400];
int dp[1400][1400];

int main() {
    scanf("%d%d", &h, &w);
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            scanf("%d", &c[i][j]);
            c[i][j] ^= 1;
            dp[i][j] = c[i][j];
            ans = max(ans, dp[i][j]);
        }
    }

    for (int i=1; i<h; i++) {
        for (int j=1; j<w; j++) {
            if (c[i][j]) {
                dp[i][j] = min(min(dp[i-1][j], dp[i][j-1]), dp[i-1][j-1]) + 1;
                ans = max(ans, dp[i][j]);
            } else {
                dp[i][j] = 0;
            }
        }
    }

    printf("%d\n", ans*ans);
}

Measured memory_bytes: 16340
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl '\n'
#define mod 1000000007

using namespace std;

int main()
{
    ll n,x, ans=0;
    cin>>n>>x;
    vector<ll>v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    v.push_back(x);

    sort(v.begin(), v.end());
    for(int i=0;i<v.size()-1;i++)
        ans = __gcd(ans, v[i+1]-v[i]);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N=1e2+10;
char s[N],t[N];
void solve()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ans=0;
    if(k>=a)ans+=a,k-=a;
    else ans+=k,k=0;
    if(k>=b) k-=b;
    else k=0;

    if(k>=c) ans-=c;
    else ans-=k;
    printf("%d\n",ans);
}
int main()
{
	solve();
}


Measured memory_bytes: 3752
#[allow(dead_code)]
fn main() {
    let (s, t) = (i::s(), i::s());
    for i in 0..s.len() {
        if s[i] != t[i] {
            println!("{}", "No");
            return;
        }
    }
    println!("{}", "Yes");
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


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

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


int main(){
    string N;
    cin >> N;

    char C = N[N.size()-1];

//    cout << C << endl;

    if(C == '3'){
        cout << "bon" << endl;
    }else if(C == '0'|| C == '1'|| C == '6' || C == '8'){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }

    
}

Measured memory_bytes: 3596
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdint.h>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

void solve(long long N, std::vector<long long> h) {
  vector<ll> min_sum(N);

  min_sum[0] = 0;
  min_sum[1] = abs(h[0] - h[1]);
  for (int i = 2; i < N; ++i) {
    min_sum[i] = min(min_sum[i - 1] + abs(h[i] - h[i - 1]),
                     min_sum[i - 2] + abs(h[i] - h[i - 2]));
  }
  std::cout << min_sum[N - 1] << std::endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> h(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &h[i]);
  }
  solve(N, std::move(h));
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int sum = 3;
  if(a==b) sum--;
  if(b==c) sum--;
  if(a==c) sum--;
  if(sum==0) sum++;
  print(sum);

}


Measured memory_bytes: 888
#include <stdio.h>
const int N=500;
const int INF=1e9+10;
int min(int a,int b){return a>b?b:a;}
int main(){
    int n,dp[N];
    dp[0]=0;
    for(int i=1;i<N;i++)dp[i]=INF;
    for(int i=0;i<100;i++)dp[i+2]=min(dp[i+2],dp[i]+380);
    for(int i=0;i<100;i++)dp[i+10]=min(dp[i+10],dp[i]+1520);
    for(int i=0;i<100;i++)dp[i+3]=min(dp[i+3],dp[i]+550);
    for(int i=0;i<100;i++)dp[i+12]=min(dp[i+12],dp[i]+1870);
    for(int i=0;i<100;i++)dp[i+5]=min(dp[i+5],dp[i]+850);
    for(int i=0;i<100;i++)dp[i+15]=min(dp[i+15],dp[i]+2244);
    while(true){
        scanf("%d",&n);
        if(n==0)return 0;
        printf("%d\n",dp[n/100]);
    }
}


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

#define N 101

void DepthFirstSearch();

class stack{
public:
    int array[100];
    int top = -1;
    
    void push(int v) {
        top++;
        array[top] = v;
        return;
    }
    
    int pop() {
        top--;
        return array[top+1];
    }
    
    int show() {
        return array[top];
    }
};

typedef struct {
    int d;
    int f;
} P;

int n;
int t = 0;
int a[N][N] = {};
stack s;
P list[N];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n;
    
    int u, k, v;
    for(int i = 0; i < n; i++) {
        cin>>u>>k;
        
        for(int j = 0; j < k; j++) {
            cin>>v;
            a[u][v] = 1;
        }
    }
    
    for(int i = 1; i <= n; i++) {
        if(list[i].d == 0) {
            s.push(i);
            for(int j = 1; j <= n; j++) a[j][i] = 0;
            DepthFirstSearch();
            s.pop();
        }
    }
    
    for(int i = 1; i <= n; i++) {
        cout<<i<<' '<<list[i].d<<' '<<list[i].f<<endl;
    }
    
    return 0;
}

void DepthFirstSearch() {
    t++;
    int u = s.show();
    list[u].d = t;
    for(int i = 1; i <= n; i++) {
        if( a[u][i] == 1 ) {
            s.push(i);
            a[u][i] = 0;
            for(int j = 1; j <= n; j++) a[j][i] = 0;
            DepthFirstSearch();
            s.pop();
        }
    }
    t++;
    list[u].f = t;
}



Measured memory_bytes: 3180
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>

using namespace std;

int main(){

  int a, b; cin >> a >> b;

  if (a + b == 15){
    cout << '+' << endl;  
  }else if(a * b == 15){
    cout << '*' << endl;
  }else{
    cout << 'x' << endl;
  }
  

  return 0;
}

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

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

Node *root, *Nil;

void insert(int key) {
    Node *y = Nil;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = key;
    z->left = Nil;
    z->right = Nil;

    while (x != Nil) {
        y = x;
        x = z->key < x->key ? x->left : x->right;
    }

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

Node * find(Node *n, int x) {
    if(n == Nil) return Nil;
    if(n->key == x) return n;
    if(x < n->key) {
        return find(n->left, x);
    } else {
        return find(n->right, x);
    }
}

void preorder(Node *n) {
    if(n == Nil) {
        return;
    }
    printf(" %d", n->key);
    preorder(n->left);
    preorder(n->right);
}

void inorder(Node *n) {
    if(n == Nil) {
        return;
    }
    inorder(n->left);
    printf(" %d", n->key);
    inorder(n->right);
}


int main() {
    int n;
    std::cin >> n;
    for(int i = 0; i < n; i++) {
        std::string str;
        std::cin >> str;
        if(str == "insert") {
            int nn;
            std::cin >> nn;
            insert(nn);
        } else if(str == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } else if(str == "find") {
            int nn;
            std::cin >> nn;
            std::cout << ((find(root, nn) == Nil) ? "no" : "yes") << std::endl;
        }
    }
    return 0;;
}



Measured memory_bytes: 21932
#include<stdio.h>

#define MAX 100
#define INFITY 1000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int prim(void);

int M[MAX][MAX],n;

int main(){
  int i,j,e;

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      scanf("%d",&e);
      M[i][j] = (e == -1) ? INFITY : e;
    }
  }

  printf("%d\n",prim());

  return 0;
}

int prim(void){
  int u,minv,i,v,sum = 0;
  int d[MAX],p[MAX],color[MAX];

  for(i = 0;i < n;i++){
    d[i] = INFITY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1){
    minv = INFITY;
    u = -1;
    for(i = 0;i<n;i++){
      if(minv > d[i] && color[i] != BLACK){
	u = i;
	minv = d[i];
      }
    }
    if(u == -1)break;
    color[u] = BLACK;
    for(v = 0;v < n; v++){
      if(color[v] != BLACK && M[u][v] != INFITY){
	if(d[v] > M[u][v] ){
	  d[v] = M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }

  for(i = 0;i < n;i++){
    if(p[i] != -1)sum += M[i][p[i]];
  }
  return sum;
}
			   
  
    

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1), b(n);
  rep(i, n + 1) cin >> a[i];
  rep(i, n) cin >> b[i];

  ll cnt = 0;
  rep(i, n) {
    int k1 = min(b[i], a[i]);
    int k2 = min(a[i + 1], b[i] - k1);
    a[i + 1] -= k2;
    cnt += k1 + k2;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
using namespace std;

int main(){

    vector<int>a(1000000);
    vector<pair <int,int>>b(1000000);
    for(int i=0;i<3;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end(),greater<>());
    if(a[0]==a[1]+a[2]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


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

int main(){
    int ans = 0;
    long long n, d;
    cin >> n >> d;
    
    long long x, y;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        if (x * x + y * y <= d * d) {
            ans++;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


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

using namespace std;

int A, B, C, D, E, F;

void solve() {
    double mx = -1;
    int max_ws = 0, max_su = 0;
    for (int a = 0; 100 * a * A <= F; ++a) {
        for (int b = 0; 100 * b * B <= F; ++b) {
            int s = (A * a + B * b) * E;
            for (int c = 0; C * c <= s; ++c) {
                for (int d = 0; D * d <= s; ++d) {
                    int su = C * c + D * d;
                    int ws = 100 * A * a + 100 * B * b + su;
                    if (su > s) continue;
                    if (ws > F) continue;
                    if (mx < 100 * su / (double) ws) {
                        mx = 100 * su / (double) ws;
                        max_ws = ws;
                        max_su = su;
                    }
                }
            }
        }
    }
    printf("%d %d\n", max_ws, max_su);
}

int main() {
    cin >> A >> B >> C >> D >> E >> F;
    solve();
    return 0;
}

Measured memory_bytes: 3676
n = 1
m = 0
a, b, c = gets.split.map(&:to_i)
loop do
  if n > c
    break
  end
  if c % n == 0 && a <= (c / n) && (c / n) <= b
    m += 1
  end
  n += 1
end
printf("%d\n", m)
  



Measured memory_bytes: 6876
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const string& e_) { return "\"" + e_ + "\""; }
string to_string (char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string (bool e_) { return e_ ? "true" : "false"; }
template <typename T> string to_string (T e_) {
	string s_ = "[ ";
	for (const auto& x_ : e_) s_ += to_string(x_) + " ";
	return s_ + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e_) {
	return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */

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

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	ll a, b;
	cin >> a >> b;

	cout << ((a * b)/gcd(min(a,b), max(a,b)));
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  string s;
  cin>>s;
  map<char,int>m;
  for(auto it:s)m[it]++;
  bool ok;
  if(m['a']==m['b']&&m['b']==m['c'])ok=true;
  else if(m['a']==m['b']&&m['a']==m['c']-1)ok=true;
  else if(m['a']==m['b']&&m['a']==m['c']+1)ok=true;
  else if(m['b']==m['c']&&m['b']==m['a']-1)ok=true;
  else if(m['b']==m['c']&&m['b']==m['a']+1)ok=true;
  else if(m['c']==m['a']&&m['c']==m['b']-1)ok=true;
  else if(m['c']==m['a']&&m['c']==m['b']+1)ok=true;
  else ok=false;
  if(ok)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;

int n;
int x[110], y[110], h[110];

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i] >> y[i] >> h[i];
	for (int i = 0; i < n; i++)
	{
		if (h[i] != 0)
			swap(x[i], x[0]), swap(y[i], y[0]), swap(h[i], h[0]);
	}
	for (int cx = 0; cx <= 100; cx++)
	{
		for (int cy = 0; cy <= 100; cy++)
		{
			bool flag = true;
			int H = h[0] + abs(x[0] - cx) + abs(y[0] - cy);
			for (int i = 0; i < n; i++)
			{
				if (h[i] != max(H - abs(x[i] - cx) - abs(y[i] - cy), 0))
					flag = false;
			}
			if (flag)
			{
				cout << cx << " " << cy << " " << H << endl;
				return 0;
			}
		}
	}
}

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

int main(){
  int counter[26];
  for(int i=0;i<26;i++){
    counter[i] = 0;
  }

  char ch;
  while( cin >> ch ){
    int num = -1;
    if('a'<=ch && ch<='z'){
      num = ch - 'a';
      counter[num]++;
    }
    if('A'<=ch && ch<='Z'){
      num = ch - 'A';
      counter[num]++;
    }
  }

  for(int i=0;i<26;i++){
    printf("%c : %d\n", i+'a', counter[i]);
  }
}



Measured memory_bytes: 3156
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <random>
#include <time.h>
	using namespace std;
	int main() {
		long long int a[3];
		for (int i = 0; i < 3; i++) {
			cin >> a[i];
		}
		if (a[0] % 2 == 0 || a[1] % 2 == 0 || a[2] % 2 == 0) {
			cout << 0 << endl;
		}
		else {
			sort(a, a + 3);
			cout << a[0] * a[1] << endl;
		}
	}

Measured memory_bytes: 256
/*  ex7_3
    hangan2020 */

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

int main(void){
    int H, W; // Matrix's height and width
    int i, j;
    char **pmatrix;

    scanf("%d %d", &H, &W);

    // Allocate memory for pointer to matrix's rows (one extra row for later use)
    pmatrix = (char**)calloc(H + 1, sizeof(char*));
    if(pmatrix == NULL){
        exit(1);
    }

    // Allocate memory for matrix's elements (through rows with size = width + 1 ; one extra width for later use) 
    for( i = 0; i < H + 1; i++){
        pmatrix[i] = (char*)calloc(W + 1, sizeof(char));
        if(pmatrix[i] == NULL){
            exit(1);
        }
    }

    //Input by loop
    for (i = 0; i < H ; i++){
        for(j = 0; j < W ; j++){
            scanf(" %c", &pmatrix[i][j]);
        }
    }

    // Scanning for '.' only rows
    for (i = 0; i < H ; i++){
        for(j = 0; j < W ; j++){
            if(pmatrix[i][j] != '.'){
                break;
            }
            else if((j == W-1)&&(pmatrix[i][j] == '.')){
                pmatrix[i][W] = 'n';// Mark n(for none) at end of row
            }
        }
    }
    // Scanning for '.' only columns
    for (j = 0; j < W ; j++){
        for(i = 0; i < H ; i++){
            if(pmatrix[i][j] != '.'){
                break;
            }
            else if((i == H-1)&&(pmatrix[i][j] == '.')){
                pmatrix[H][j] = 'n';// Mark n(for none) at end of column
            }
        }
    }

    //Printing out by loop ( except for rows or columns that starts with 'n')
    for (i = 0; i < H ; i++){
        if(pmatrix[i][W] != 'n'){
            for(j = 0; j < W ; j++){
                if(pmatrix[H][j] != 'n'){
                    printf("%c", pmatrix[i][j]);
                }
            }
        printf("\n");
        }
    }

    //Free allocated memories for elements
    for(i = 0; i < H + 1; i++){
        free(pmatrix[i]);
    }
    //Free allocated memoties for row's pointers
    free(pmatrix);

    return 0;
}


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

import sys

def parse_input(lines_as_string = None):


    lines = []
    if lines_as_string is None:
        lines.append(input())
        lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]
 
    tokens = lines[0].split(" ")
    width = int(tokens[0])
    height = int(tokens[1])
    tokens = lines[1].split(" ")
    w = int(tokens[0])
    h = int(tokens[1])

    return (width, height, w, h)


def solve(width, height, w, h):


    return (width - w) * (height - h)

def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    double a,b,c,d,e,f;
    while (cin>>a>>b>>c>>d>>e>>f) {
        double x = (c * e - f * b) / (a * e - d * b);
        double y = (c * d - f * a) / (b * d - a * e);

        if (x == -0) x = 0;
        if (y == -0) y = 0;
        printf("%.3f %.3f\n", x, y);
    }
}

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

signed main(){
	int n,ans = 0;
	cin >> n;
	for(int i = 1;i <= n;i++){
		int cnt = 0;
		for(int j = 1;j <= i;j++){
			if(i % j == 0) cnt++;
		}
		if(i % 2 && cnt == 8) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>

int main(){
  char ch;

  while(1){
    scanf("%c", &ch);
    if( isalpha(ch) ){
      if( islower(ch) ) printf("%c", toupper(ch));
      else printf("%c", tolower(ch));
    } else printf("%c", ch);

    if( ch == '\n' ) break;
  }
  
  return 0;
}

Measured memory_bytes: 944
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>

using namespace std;

typedef long long ll;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

ll N;
int main(){
  cin >>N;
  if (N==10||N==100||N==1000||N==10000||N==100000){
    cout << 10 <<endl;
    return 0;
  }
  ll ans=0;
  while (N>0){
    ans+=N%10;
    N/=10;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
ll C[51][51];
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    rep(i, 51) rep(j, i + 1) {
        if (j == 0)
            C[i][j] = 1;
        else
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    }

    int n, a, b;
    cin >> n >> a >> b;
    vector<double> vec(n);
    rep(i, n) cin >> vec[i];
    sort(vec.begin(), vec.end(), greater<double>());
    double sum = 0;
    rep(i, a) sum += vec[i];
    int p = 0, q = 0;
    rep(i, n) {
        if (vec[i] == vec[a - 1]) {
            p++;
            if (i < a) q++;
        }
    }
    ll ans = 0;
    if (vec[0] == vec[a - 1]) {
        repl(i, a, b + 1) ans += C[p][min(i, p - i)];
    } else {
        ans = C[p][min(q, p - q)];
    }
    sum /= (double)a;
    CST(10) << sum << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3812
import itertools
import sys

N, N1 = tuple([int(x) for x in sys.stdin.readline().split()])
D, C = [], []

for _ in range(N1):
    D.append([int(x) for x in sys.stdin.readline().split()])
for _ in range(N):
    C.append([int(x) for x in sys.stdin.readline().split()])

color_count = [[0] * N1 for _ in range(3)]
for i in range(N):
    for j in range(N):
        color_count[(i + j) % 3][C[i][j] - 1] += 1

min_cost = 2**64
for c0 in range(N1):
    for c1 in range(N1):
        if c0 == c1:
            continue
        for c2 in range(N1):
            if c0 == c2 or c1 == c2:
                continue
            cost = 0
            for j in range(N1):
                cost += color_count[0][j] * D[j][c0]
                cost += color_count[1][j] * D[j][c1]
                cost += color_count[2][j] * D[j][c2]
            if cost < min_cost:
                min_cost = cost

print(min_cost)

Measured memory_bytes: 5492
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const ll mod=1e9+7;
ll cal(ll n,ll a)
{ll ans=1;
    for(int i=n;i>=n-a+1;i--)
        ans=ans*i%mod;
    return ans;
}
int main()
{
    ll n,m;
    scanf("%lld%lld",&n,&m);
    if(n>m)
        swap(n,m);
    if((m-(n-1))>2)
    {
        printf("0\n");
        return 0;
    }
    else
        {printf("%lld\n",(cal(n,n)%mod*cal(m,n-1)%mod*(m-n+1,2)%mod));
        }
        return 0;
}


Measured memory_bytes: 256
#include <cstdio>
struct node{int p,l,r;};
node t[25];
int n,h[25],d[25];
void dp1(int now,int de){
  d[now]=de;
  if(t[now].l!=-1) dp1(t[now].l,de+1);
  if(t[now].r!=-1) dp1(t[now].r,de);
}
void dp2(int f,int now,int he){
  if(h[f]<he) h[f]=he;
  if(t[now].l!=-1) dp2(f,t[now].l,he+1);
  if(t[now].l!=-1) if(t[t[now].l].r!=-1) dp2(f,t[t[now].l].r,he+1);
}
int main(){
  int now,tmpl,tmpr,s[25]={0},p[25];
  scanf("%d",&n);
  for(int i=0;i<n;i++) t[i].p=t[i].l=t[i].r=p[i]=-1;
  for(int i=0;i<n;i++){
    scanf("%d%d%d",&now,&tmpl,&tmpr);
    if(tmpl==-1) tmpl=tmpr,tmpr=-1;
    if(tmpl!=-1) s[now]++,t[tmpl].p=now,t[tmpl].r=tmpr;
    if(tmpr!=-1) s[now]++,t[tmpr].p=now;
    t[now].l=tmpl;
  }
  for(int i=0;i<n;i++){
    if(t[i].r!=-1) p[i]=t[i].r;
    else if(t[i].p!=-1) if(t[t[i].p].l!=-1&&t[t[i].p].l!=i) p[i]=t[t[i].p].l;
  }
  int st;
  for(int i=0;i<n;i++) if(t[i].p==-1) st=i;
  dp1(st,0);
  for(int i=0;i<n;i++) dp2(i,i,0);
  for(int i=0;i<n;i++){
    printf("node %d: parent = %d, sibling = %d, ",i,t[i].p,p[i]);
    printf("degree = %d, depth = %d, height = %d, ",s[i],d[i],h[i]);
    if(t[i].p==-1) printf("root\n");
    else if(t[i].l!=-1) printf("internal node\n");
    else printf("leaf\n");
  }
  return 0;
}

Measured memory_bytes: 2756
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<functional>
#define vec2c vector<vector<char>>
#define vec2i vector<vector<int>>
#define vecc vector<char>
#define vecs vector<string>
#define veci vector<int>
#define vecd vector<double>
#define rep(i, n) for(int i=0; i < (int)(n); i++)
#define rrep(i, n) for(int i=(int)(n); i>=0;i--)

using namespace std;

int main() {

  int n;
  veci h;

  cin >> n;
  rep(i, n) {
    int x;
    cin >> x;
    h.push_back(x);
  }

  for(int i=0; i<n-1; i++) {
    if (h[i] == h[i+1]) {
      continue;
    }
    else if (h[i] <= h[i+1] - 1) {
      h[i+1]--;
      continue;
    }
    else {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 892
from operator import mul
from functools import reduce
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N=int(input())
t=tuple([''.join(sorted(list(input()))) for _ in range(N)])
Dic = {}
ans = 0
for i in range(N):
    if t[i] in Dic:
        Dic[t[i]]+=1
    else:
        Dic[t[i]]=1
for k in tuple(Dic.keys()):
    if Dic[k]==1:
        pass
    else:
        ans+=cmb(Dic[k], 2)
print(int(ans))

Measured memory_bytes: 20000
/*
 * b.cc: 
 */

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

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  for (;;) {
    string s;
    cin >> s;
    if (s == "-") break;

    int m;
    cin >> m;
    
    int sum = 0;
    for (int i = 0; i < m; i++) {
      int hi;
      cin >> hi;
      sum += hi;
    }

    int sn = s.size();
    sum %= sn;

    for (int i = 0; i < sn; i++) putchar(s[(sum + i) % sn]);
    putchar('\n');
  }

  return 0;
}

Measured memory_bytes: 1184
N,M = map(int,input().split())
persons = []
chechpoints = []
for i in range(N):
    a = list(map(int,input().split()))
    persons.append(a)
for j in range(M):
    a = list(map(int,input().split()))
    chechpoints.append(a)

for i in range(N):
    x = persons[i][0]
    y = persons[i][1]
    distance = []
    for j in range(M):
        distance_j = abs(x-chechpoints[j][0])+abs(y-chechpoints[j][1])
        distance.append(distance_j)
    print(distance.index(min(distance))+1)

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

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int x = tx - sx, y = ty - sy;
    string res;
    res += string(x, 'R');
    res += string(y, 'U');
    res += string(x, 'L');
    res += string(y, 'D');
    res += 'L';
    res += string(y+1, 'U');
    res += string(x+1, 'R');
    res += "DR";
    res += string(y+1, 'D');
    res += string(x+1, 'L');
    res += 'U';
    cout << res << endl;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

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

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; }

int main(void){
    ll M; cin >> M;
    vector<ll> d(M), c(M); REP(i,M) cin >> d[i] >> c[i];
    ll D = 0, S = 0;
    REP(i,M){
        D += c[i];
        S += d[i]*c[i];
    }
    ll ans = D-1 + (S-1)/9;
    cout << ans << en;
    return 0;
}

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

typedef long long ll;
const int N = (int)(1 << 18) + 500;
typedef pair<int, int> P;


int n;
int num[N];
P lar1[N], lar2[N];

void insert(int i, int val, int from){
    if(val > lar1[i].first){
        lar2[i].first = lar1[i].first; lar2[i].second = lar1[i].second;
        lar1[i].first = val, lar1[i].second = from;
    }
    else if(val > lar2[i].first && from != lar1[i].second){
        lar2[i].first = val, lar2[i].second = from;
    }
}

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

    cin >> n;
    for(int i = 0; i < (1 << n); i++) cin >> num[i], lar1[i].first = num[i], lar1[i].second = i;
    for(int i = 0; i < n; i++) {
        for (int j = 0; j < (1 << n); j++) {
            if ((j ^ (1 << i)) == (j + (1 << i))) {
                int nxt = j + (1 << i);
                insert(nxt, lar1[j].first, lar1[j].second);
                insert(nxt, lar2[j].first, lar2[j].second);
            }
        }
    }
    int res = 0;
    for(int i = 1; i < (1 << n); i++){
        res = max(res, lar1[i].first + lar2[i].first);
        cout << res << endl;
    }

}

Measured memory_bytes: 8192