akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>

int main(void){
    long int N; //整数の個数
    int F=0;
    long long Pro=1;
    double LogPro=0;
    scanf("%ld",&N);
    long long data[N];
    for(int i=0;i<N;i ++){
        scanf("%lld",&data[i]);
    }
    for(int i=0;i<N;i++)if(data[i]==0)F=1;
    if(F==0){
    for(int i=0;i<N;i++){
            LogPro+=log10(data[i]);
            if(LogPro>18) {
                F=1;
                break;
            }
            Pro=Pro*data[i];
    }
        if(F==0) {
            if(Pro<=1000000000000000000) printf("%lld",Pro);
            else printf("%d",-1);
        }
        else printf("%d",-1);
    }
    else printf("%d",0);
        return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e16;
#define int long long

const int MAX = 55;

int n, A;
int dp[MAX][MAX][MAX*MAX];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> A;
	VE x(n); rep(i, n)cin >> x[i];
	int X = 0;
	rep(i, n) {
		chmax(X, x[i]);
	}
	rep(i, MAX)rep(j, MAX)rep(k, MAX*MAX)dp[i][j][k] = 0;
	chmax(X, A);
	rep(j, n+1) {
		rep(k, n + 1) {
			rep(s, n*X + 1) {
				if (j == 0 && k == 0 && s == 0) {
					dp[j][k][s] = 1;
				}
				else if (j >= 1 && s < x[j - 1]) {
					dp[j][k][s] = dp[j - 1][k][s];
				}
				else if (j >= 1 && k >= 1 && s >= x[j - 1]) {
					dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]];
				}
				else {
					dp[j][k][s] = 0;
				}
			}
		}
	}
	int ans = 0;
	rep(i, n+1) {
		if (i == 0)continue;
		ans += dp[n][i][i*A];
	}
	cout << ans << endl;
	return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:
const int inf=1<<19;
const int LOG=19;
int alpha[26][500010];
int nxt[19][500010];

bool query(int l,int r){
	rrep(i,LOG) if(nxt[i][l]<=r) l=nxt[i][l];
	return l==r;
}

int main(void){
	string s;
	cin >> s;
	const int n=s.size();

	rep(i,26)rep(j,n+1) alpha[i][j]=inf;
	rep(i,LOG)rep(j,n+1) nxt[i][j]=inf;

	rrep(i,n){
		const int c=s[i]-'a';
		alpha[c][i]=i+1;
		
		rep(k,c+1,26){
			if(alpha[k-1][i]<=n)
				alpha[k][i]=alpha[k-1][alpha[k-1][i]];
		}
		
		if(alpha[25][i]<=n) nxt[0][i]=alpha[25][alpha[25][i]];
		rep(j,LOG-1) if(nxt[j][i]<=n) nxt[j+1][i]=nxt[j][nxt[j][i]];
		
		rep(k,c){
			if(nxt[0][i]<=n)
				alpha[k][i]=alpha[k][nxt[0][i]];
		}

	}

	int q;
	cin >> q;

	rep(loop,q){
		int l,r;
		cin >> l >> r,l--;
		cout << (query(l,r)?"Yes":"No") << endl;
	}

	return 0;
}

Measured memory_bytes: 89092
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n, k, r, s, p int
	var t string
	_, _ = fmt.Scan(&n, &k, &r, &s, &p, &t)
	
	ans := 0
	
	str := strings.Split(t, "")
	
	for i, ac := range str {
		if i < k {
			switch ac {
			case "r":
				ans += p
			case "p":
				ans += s
			case "s":
				ans += r
			}
		} else {
			if str[i] == str[i-k] {
				str[i] = "WTF"
			} else {
				switch ac {
				case "r":
					ans += p
				case "p":
					ans += s
				case "s":
					ans += r
				}
			}
		}
	}
	
	fmt.Println(ans)
}


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

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

int field[17][17];

int main(void){
    // Here your code !
    int a,b;
    while(cin>>a>>b,a&&b){
        rep(i,17)rep(j,17)field[i][j]=(i==0||j==0)?-1:(i==1||j==1)?1:0;
        field[1][1]=1;
        int n;
        cin>>n;
        rep(i,n){
            int x,y;
            cin>>x>>y;
            field[x][y]=-1;
        }
        
        rep(x,a+1)rep(y,b+1){
            if((x==1&&y==1)||field[x][y]<0)continue;
            field[x][y]=max(0,field[x-1][y])+max(0,field[x][y-1]);
        }
        cout<<field[a][b]<<endl;
        /*rep(y,b+1){
            rep(x,a+1){
                cout<<field[x][y]<<"\t";
            }
            cout<<endl;
        }*/
    }
    return 0;
}


Measured memory_bytes: 2968
import std.stdio;

void main() {
	long n;
	readf("%s", &n);

	auto a = new uint[n + 1];
	a[1..$] = 1;
	foreach (i;2..n + 1) {
		for (auto j = i;j <= n;j += i) {
			++a[j];
		}
	}

	long s;
	foreach (long i;1..n + 1) {
		s += i * a[i];
	}

	writeln(s);
}


Measured memory_bytes: 41780
#include <stdio.h>
char s[4001];
long long ans, n, r, g, b;
int main() {
	scanf("%lld", &n);
	scanf(" %s", s);
	for (long long i = 0; i < n; i++) {
		if (s[i] == 'R')r++;
		if (s[i] == 'G')g++;
		if (s[i] == 'B')b++;
	}
	ans = r * g * b;
	for (long long i = 0; i < n; i++) {
		for (long long j = 1; i + j * 2 < n; j++) {
			if (s[i] != s[i + j] && s[i] != s[i + j * 2] && s[i + j] != s[i + j * 2])ans--;
		}
	}
	printf("%lld\n", ans);
}

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


 int main()
 {
 	int N;
 	bool ans=false;
 	cin >> N;
 	for (int i = 0; i < N; i++) {
 		char a;
 		cin >> a;
 		if(a=='Y')
 		ans=true;
 	}
 	if(ans){
 		cout << "Four" << endl;
 	}else{
 		cout << "Three" << endl;
 	}
 }

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

int N;

int main() {
    cin >> N;
    map<int, int> mp;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        mp[A]++;
    }

    int var = mp.size();
    if (var % 2 == 0) {
        cout << var-1 << endl;
    }
    else {
        cout << var << endl;
    }

    return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

// Sieve of Eratosthenes
// (*this)[i] = (divisor of i, greater than 1)
// Example: [0, 1, 2, 3, 2, 5, 3, 7, 2, 3, 2, 11, ...]
// Complexity: Space O(MAXN), Time (construction) O(MAXNloglogMAXN)
struct SieveOfEratosthenes : std::vector<int> {
  std::vector<int> primes;
  SieveOfEratosthenes(int MAXN) : std::vector<int>(MAXN + 1) {
    std::iota(begin(), end(), 0);
    for (int i = 2; i <= MAXN; i++) {
      if ((*this)[i] == i) {
        primes.push_back(i);
        for (int j = i; j <= MAXN; j += i) (*this)[j] = i;
      }
    }
  }
  using T = long long int;
  // Prime factorization for x <= MAXN^2
  // Complexity: O(log x)          (x <= MAXN)
  //             O(MAXN / logMAXN) (MAXN < x <= MAXN^2)
  std::map<T, int> Factorize(T x) {
    assert(x <= 1LL * (int(size()) - 1) * (int(size()) - 1));
    std::map<T, int> ret;
    if (x < int(size())) {
      while (x > 1) {
        ret[(*this)[x]]++;
        x /= (*this)[x];
      }
    }
    else {
      for (auto p : primes) {
        while (!(x % p)) x /= p, ret[p]++;
        if (x == 1) break;
      }
      if (x > 1) ret[x]++;
    }
    return ret;
  }
  std::vector<T> Divisors(T x) {
    std::vector<T> ret{1};
    for (auto p : Factorize(x)) {
      int n = ret.size();
      for (int i = 0; i < n; i++) {
        for (T a = 1, d = 1; d <= p.second; d++) {
          a *= p.first;
          ret.push_back(ret[i] * a);
        }
      }
    }
    return ret; // Not sorted
  }
  // Moebius function Table
  // return: [0=>0, 1=>1, 2=>-1, 3=>-1, 4=>0, 5=>-1, 6=>1, 7=>-1, 8=>0, ...]
  std::vector<int> GenerateMoebiusFunctionTable() {
    std::vector<int> ret(size());
    for (int i = 1; i < int(size()); i++) {
      if (i == 1) ret[i] = 1;
      else if ((i / (*this)[i]) % (*this)[i] == 0) ret[i] = 0;
      else ret[i] = -ret[i / (*this)[i]];
    }
    return ret;
  }
};
SieveOfEratosthenes sieve(1000000);

int main() {
  int N; cin >> N;
  ll ans = 0;
  for(int i = 1; i < N; ++i) {
    int tmp = N - i;
    auto x = sieve.Divisors(tmp);
    ans += x.size();
  }
  cout << ans << endl;
}

Measured memory_bytes: 7620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; i++)
static const long long INF = 1000000;
using p = pair<int,int>;
const vector<int> v1 = {0,1,0,-1};
const vector<int> v2 = {1,0,-1,0};

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> road(h,vector<char>(w,'#'));
    rep(i,h){
        rep(j,w){
            char s;
            cin >> s;
            road[i][j] = s;
        }
    }
    
    //スタート、ゴール、壁の位置からかかる時間の最大値を出力する。
    auto haba = [&](int sh,int sw){
        queue<p> q;
        q.push({sh,sw});
        vector<vector<int>> score(h,vector<int>(w,0));
        vector<vector<int>> color(h,vector<int>(w,0));
        auto push = [&](int sh,int sw){
            rep(i,4){
                int gh,gw;
                gh = sh +v1[i];
                gw = sw + v2[i];
                p p1 = {gh,gw};
                if (0 <= gh and gh < h){
                    if (0 <= gw and gw < w){
                        if (road[gh][gw] == '.' and color[gh][gw] == 0){
                            q.push(p1);
                            score[gh][gw] = score[sh][sw] + 1;
                            color[gh][gw] = 1;
                        }
                    }
                }
                
            }
            return false;
        };
        while (!q.empty()){
            p sp = q.front();
            color[sp.first][sp.second] = 1;
            q.pop();
            push(sp.first,sp.second);
           
        }
        int mx = 0;
        rep(i,h){
            rep(j,w){
                mx = max(mx,score[i][j]);
            }
        }
        return mx;
    };
    int ans = 0;
    rep(i,h){
        rep(j,w){
            if (road[i][j] == '.'){
                int m = haba(i,j);
                ans = max(ans,m);
            }
        }
    }
    cout << ans << endl;
    
    
    
}

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

int main(){
  int n, i, x[1000] = {0}, y[1000] = {0};
  double d1 = 0, d2 = 0, d3 = 0, D2, D3, max;

  cin >> n;
  for(i = 0; i < n; i++) cin >> x[i];
  for(i = 0; i < n; i++) cin >> y[i];
  for(i = 0; i < n; i++){
    d1 += fabs(x[i] - y[i]);
    d2 += pow(fabs(x[i] - y[i]), 2.0);
    d3 += pow(fabs(x[i] - y[i]), 3.0);
    if(max < fabs(x[i] - y[i])) max = fabs(x[i] - y[i]);
  }
  D2 = sqrt(d2);
  D3 = pow(d3, 1.0/3.0);
  cout << fixed << d1 << endl;
  cout << D2 << endl;
  cout << D3 << endl;
  cout << max << endl;

  return 0;
}

Measured memory_bytes: 1308
n = int(input())
x = list(map(int, input().split()))
xmax = max(x)
xmin = min(x)
ans=[]
a=0
for i in range(xmin,xmax+1):
    for j in x:
        a+=(j-i)**2

    ans.append(a)
    a=0
print(min(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define sd second

using namespace std;

const ll oo = 1000000010;

int n;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    ll res =0, t = oo;
    for (int i=1;i<=n;i++) {
        ll a,b;
        cin>>a>>b;
        res += 1ll*a;
        if (a>b)  t = min(t,1ll*b);
    }
    res -= t;
    if (t!=oo) cout<<res<<endl;
    else cout<<0<<endl;
}


Measured memory_bytes: 256
k, a, b = gets.split.map(&:to_i)
c = 1

if a < b - 1
	if a - c >= k
		puts c + k
	else
		count = k - (a - c)
		if count.odd?
			puts a + (b - a) * (count / 2) + 1
		else
			puts a + (b - a) * (count / 2)
		end
	end
else
	puts c + k
end

Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int h = sc.nextInt();
        int w = sc.nextInt();
        int k = sc.nextInt();
        boolean[][] isBlack = new boolean[h][w];

        for (int i = 0; i < h; i++) {
            char[] s = sc.next().toCharArray();
            for (int j = 0; j < w; j++) {
                isBlack[i][j] = s[j] == '#';
            }
        }

        int ans = 0;
        for (int i = 0; i < (1 << h); i++) {
            for (int j = 0; j < (1 << w); j++) {
                int cnt = 0;

                for (int l = 0; l < h; l++) {
                    if ((i>>l & 1) == 1) continue;
                    for (int m = 0; m < w; m++) {
                        if ((j>>m & 1) == 1) continue;
                        if (isBlack[l][m]) cnt++;
                    }
                }

                if (cnt == k) ans++;
            }
        }

        System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

Measured memory_bytes: 33268
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {

    string s;
    cin >> s;
    string answer="keyence";

    int size,i;
    size=s.size();
    if(s==answer){
        cout << "YES" << endl;
        return 0;
    }
    if(size<8){
        cout << "NO" << endl;
        return 0;
    }
    
    for(i=0;i<8;i++){
        string tmp;
        tmp=s;
        tmp.erase(tmp.begin() + i, tmp.begin() + i+size-7);
      //cout <<tmp <<endl;
        if(tmp==answer){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


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

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

    int n;
    double k;
    cin >> n >> k;

    double ans = 0;
    for(int i = 1; i <= n; i++){
        double tmp = 1 / (double)n;
        double now = i;
        int cnt = 1;
        double m = 1;
        while(now < k){
            now *= 2;
            m *= 2;
            cnt++;
        }
        tmp *= 1 / m;
        ans += tmp;
    }

    cout << fixed << setprecision(12) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.JSC_2019_qual
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] md = ReadInts();
            int m = md[0];
            int d = md[1];
            int res = 0;
            for(int i = 1; i <= m; i++)
            {
                for(int j = 1; j <= d; j++)
                {
                    int d1 = j % 10;
                    int d10 = j / 10;
                    if (d1 < 2 || d10 < 2) continue;

                    if (i == d1 * d10)
                    {
                        res++;
                    }
                }
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
n,q=NM()
c=[0]+L()
Q=[L()+[i] for i in range(q)]
Q.sort(key=lambda x:x[1])
ans=[0]*(q)
lastapp=[0 for i in range(n+1)]

No=2
while No<=n:
    No*=2
BIT=[0]*(No+1)
def addbit(i,x):
    while i<=No:
        BIT[i]+=x
        i+= i&-i
def getsum(i):
    s=0
    while i:
        s+=BIT[i]
        i-= i&-i
    return s
def sumbit(l,r):
    return getsum(r)-getsum(l-1)

j=1
for l,r,i in Q:
    while j<=r:
        t=c[j]
        if lastapp[t]:
            addbit(lastapp[t],-1)
        addbit(j,1)
        lastapp[t]=j
        j+=1
    ans[i]=sumbit(l,r)
for i in ans:
    print(i)

Measured memory_bytes: 268428
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
const int maxn=25+10;
int n;
typedef struct
{
    int sibling;
    int degree;
    int left;
    int right;
}Node;
Node node[maxn];
int parent[maxn];
int h[maxn];
int d[maxn];

int update_height(int v)
{
     if(v==-1) return -1;
     return h[v]=max(update_height(node[v].left),update_height(node[v].right))+1;
}
void update_depth(int v)
{
    int depth=0;
    int p=parent[v];
    while(p!=-1)
    {
        p=parent[p];
        depth++;
    }
    d[v]=depth;
}
int main()
{
//    freopen("in.txt","r",stdin);
    int id,left,right;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        node[i].sibling=-1;
        node[i].degree=0;
        node[i].left=-1;
        node[i].right=-1;
        parent[i]=-1;
        d[i]=0;
        h[i]=0;
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d%d%d",&id,&left,&right);

        node[left].sibling=right;
        node[right].sibling=left;

        if(left==-1&&right==-1) node[id].degree=0;
        else if(left==-1||right==-1) node[id].degree=1;
        else node[id].degree=2;

        parent[left]=id;
        parent[right]=id;

        node[id].left=left;
        node[id].right=right;
    }
    for(int i=0;i<n;i++)
    {
          update_height(i);
        update_depth(i);
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,parent[i],node[i].sibling,node[i].degree,d[i],h[i]);
        if(parent[i]==-1)   printf("root");
        else if(node[i].degree==0) printf("leaf");
        else printf("internal node");
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> L(n);
  REP(i, n) cin >> L[i];
  sort(ALL(L), greater<int>());
  ll ans = 0;
  REP(a, n) {
    FOR(b, a + 1, n) {
      FOR(c, b + 1, n) {
        if(abs(L[b] - L[c]) < L[a] && L[a] < L[b] + L[c]) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>

using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll N;
vector<vector<ll>> nodes;
vector<ll> parents;
vector<vector<ll>> childs;
vector<ll> CNUM;


//si:頂点数
//root:根
//ch:子供の集合
//pa:親(根の親=-1)
//no:前提情報
void treeconstruct(ll si, ll root,vector<vector<ll>>& ch, vector<ll>& pa, vector<vector<ll>>& no) {
	ch.resize(si,vector<ll>(0));
	pa.resize(si,-2);
	queue<pll> q;
	q.push(pll(root, -1));
	while (!q.empty()) {
		ll cur = q.front().first;
		ll p = q.front().second;
		q.pop();
		pa[cur] = p;
		for (ll next : no[cur]) {
			if (next == p)continue;
			ch[cur].push_back(next);
			q.push(pll(next, cur));
		}
	}
	return;
}

ll cnum(ll n) {
	if (CNUM[n] != -1)return CNUM[n];
	ll ans = 0;
	for (ll c : childs[n])ans += cnum(c);
	CNUM[n] = ans + 1;
	return CNUM[n];
}

int main() {
	cin >> N;
	nodes.resize(N);
	for (ll n = 0; n < N - 1; n++) {
		ll a, b;
		cin >> a >> b;
		nodes[--a].push_back(--b);
		nodes[b].push_back(a);
	}
	treeconstruct(N, 0, childs, parents, nodes);
	CNUM.resize(N, -1);
	for (ll n = 0; n < N; n++) {
		cnum(n);
	}
	ll dist = 0;
	{
		ll cur = N - 1;
		while (cur != 0) {
			cur = parents[cur];
			dist++;
		}
	}
	ll top = N - 1;
	for (ll d = 1; d <= (dist - 1) / 2; d++)top = parents[top];
	ll sn = cnum(top);
	ll fe = N - cnum(top);
	if (fe > sn)cout << "Fennec" << endl;
	else cout << "Snuke" << endl;
	return 0;
}

Measured memory_bytes: 17536
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a == 7 && b == 5 && c == 5){
            System.out.println("YES");
        }
        else if(a == 5 && b == 7 && c == 5){
            System.out.println("YES");
        }
        else if(a == 5 && b == 5 && c == 7){
            System.out.println("YES");
        }
        else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 23124
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1e9 + 7)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl


typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

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

void solve() {

	int n, x;
	cin >> n >> x;

	vi a(n);

	REP(i, n) {
		cin >> a[i];
	}

	sort(ALL(a));

	int cnt = 0, sum = 0;

	int i;

	for (i = 0; i < n; i++) {
		sum += a[i];
		if (sum > x) {
			break;
		}
		cnt++;
	}

	if (i == n && sum < x) {
		cnt--;
	}

	out(cnt);

	return;

}

int main() {

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

	solve();

	return 0;

}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
ps=0
xs=0
c=0
j=0
for i in range(n):
  ps+=a[i]
  xs^=a[i]
  while ps!=xs:
    ps-=a[j]
    xs^=a[j]
    j+=1
  c+=i-j+1
print(c)
    

Measured memory_bytes: 32216
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int num;
char a[5],b[5];
int main()
{
	cin>>a>>b;
	for(int i=0;i<3;i++) if(a[i]==b[i]) num++;
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define srep3(k,s,t) for (int k = s; k < t; ++k)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int A,B;
  cin >> A >> B;
  if(A >= 6 && A <= 12) {
    cout << B / 2 << endl;
  } else if(A < 6) {
    cout << 0 << endl;
  } else {
    cout << B << endl;
  }
  return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:usize,
        mut an:[usize;n],
    }
    let mut ans = 0;
    for j in 0..n {
        let mut min_index = j;
        for k in j..n {
            if an[k] < an[min_index] {
                min_index = k;
            }
        }
        if min_index != j {
            an.swap(min_index,j);
            ans += 1;
        }

        
    }
    for j in 0..n-1{
        print!("{} ",an[j]);
    }
    println!("{}",an[n-1]);
    println!("{}",ans);
}


fn is_prime(x:i64) -> bool {
    if x == 2 {return true;}
    if x < 2 || x % 2 == 0 {return false;}
    let mut j = 3;
    while j <= (x as f64).sqrt() as i64 {
        if x % j == 0 {
            return false;
        }
        j += 2;
    }
    true
}



Measured memory_bytes: 5036
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main() {
    ll a,b;
    cin >> a >> b;
    for (ll i=0;i<a;++i){
        string x;
        cin >> x;
        cout << x << endl;
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*
 * じょえチャンネルを応援します！
 * https://www.youtube.com/watch?v=gPFr7q7eLL8
 */
void main() {
	auto ip = readAs!(ulong[]), n = ip[0], a = ip[1], b = ip[2];
	const ulong MOD = 1000000007;
	ulong res = pow_mod(2, n, MOD);
	res--;
	res = res - mod_comb(n, a, MOD) + MOD;
	res %= MOD;
	res = res - mod_comb(n, b, MOD) + MOD;
	res %= MOD;
	res.writeln;
}

ulong pow_mod(ulong n, ulong k, ulong m) {
	if(k==0) return 1;
	else if(k & 1) return pow_mod(n, k-1, m) * n % m;
	else {
		ulong t = pow_mod(n, k>>1, m);
		return t * t % m;
	}
}

ulong mod_comb(ulong n, ulong r, ulong m) {
	auto inv = new ulong[](r+1);
	auto finv = new ulong[](r+1);
	inv[1] = 1;
	finv[0] = finv[1] = 1;
	foreach(i; 2..r+1) {
		inv[i] = m - inv[m % i] * (m / i) % m;
		finv[i] = finv[i - 1] * inv[i] % m;
	}
	ulong res = 1;
	foreach(i; n-r+1..n+1) (res *= i) %= m;
	(res *= finv[r]) %= m;
	debug writefln("n, r, res: %d, %d, %d", n, r, res);
	return res;
}

class COM {
	long[] fact, finv, inv;
	private ulong MAX;
	private ulong MOD;

	this(ulong MAX, ulong MOD) {
		this.MAX = MAX;
		this.MOD = MOD;
		fact = new long[](MAX);
		finv = new long[](MAX);
		inv = new long[](MAX);

		// initialize the arrays
		fact[0] = fact[1] = 1;
		finv[0] = finv[1] = 1;
		inv[1] = 1;
		foreach(i; 2..MAX) {
			//fact[i] = fact[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
			//finv[i] = finv[i - 1] * inv[i] % MOD;
		}
	}

	ulong nCr(long n, long k) {
		if(n < k) return 0;
		if(n < 0 || k < 0) return 0;
		debug writefln("%d %d", n, k);
		assert(n < MAX && k < MAX);
		return fact[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}
	ulong factorial(long n) {
		return fact[n];
	}
}
// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 7548
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        n: usize,
        p: [usize1; n - 1],
        x: [usize; n],
    }
    let mut child = vec![vec![]; n];
    for (i, &p) in p.iter().enumerate() {
        child[p].push(i + 1);
    }
    let mut min = vec![0; n];
    for (v, &w) in x.iter().enumerate().rev() {
        let mut sum = 0;
        let mut dp = vec![false; w + 1];
        dp[0] = true;
        for &u in child[v].iter() {
            sum += x[u] + min[u];
            let mut next = vec![false; w + 1];
            for i in 0..(w + 1) {
                if i + x[u] <= w {
                    next[i + x[u]] |= dp[i];
                }
                if i + min[u] <= w {
                    next[i + min[u]] |= dp[i];
                }
            }
            dp = next;
        }
        match dp.iter().rposition(|x| *x) {
            Some(k) => {
                min[v] = sum - k;
            },
            None => {
                println!("IMPOSSIBLE");
                return;
            },
        }
    }
    println!("POSSIBLE");
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>

using namespace std;

int main(){
	string a,b,c;
	cin>>a>>b>>c;
	
	string next=a.substr(0,1);
	a.erase(a.begin());
	while(1){		
		if(next=="a"){
			if(a.size()==0){
				cout<<"A\n";
				break;
			}
			next=a.substr(0,1);
			a.erase(a.begin());
		}
		else if(next=="b"){
			if(b.size()==0){
				cout<<"B\n";
				break;
			}
			next=b.substr(0,1);
			b.erase(b.begin());
		}
		else if(next=="c"){
			if(c.size()==0){
				cout<<"C\n";
				break;
			}
			next=c.substr(0,1);
			c.erase(c.begin());
		}
	}
	return 0;
}


Measured memory_bytes: 256
n, W = map(int, input().split())
w, v = [], []
for _ in range(n):
    _w, _v = map(int, input().split())
    w.append(_w)
    v.append(_v)

sv = sum(v)
dp = [[float("inf")]*(sv+1) for _ in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(sv+1):
        dp[i+1][j] = dp[i][j]
        if v[i] <= j:
            dp[i+1][j] = min(dp[i][j-v[i]]+w[i], dp[i][j])

ans = 0
for i, _dp in enumerate(dp[n]):
    if _dp <= W:
        ans = i

print(ans)


Measured memory_bytes: 307912
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <iomanip>
#include <cmath>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>

#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define ll long long 
//#define int long long
#define ld long double
#define vi vector<ll>
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define iii pair<int,ii>
#define il pair<ll,ll>
#define vv vector
//#define endl '\n'
using namespace std;
const int MAXN = 2000 + 5;
const int INF = 1e9;

 
int bit[2*MAXN];
 
void add(int x, int val) {
  x += 1;
  while(x < 2*MAXN) {
    bit[x] += val;
    x += x&(-x);
  }
}
 
int sum(int x) {
  x += 1;
  int ret = 0;
  while(x > 0) {
    ret += bit[x];
    x -= x&(-x);
  }
  return ret;
}
 
int main() {
	int n;
	cin >> n;

	int location[2][n];
	for(int i = 0; i < 2*n; i++) {
		char c; int x;
		cin >> c >> x;
		location[c == 'W'][x-1] = i;
	}

	int dp[n+1][n+1];
	FOR(i,n+1)FOR(j,n+1)dp[i][j] = INF;
	dp[0][0] = 0;
	FOR(i,n+1){
	    if(i > 0) add(location[0][i-1], 1);
	 
	    FOR(j,n){
	    	if(i < n)dp[i+1][j] = min(dp[i+1][j], dp[i][j] + location[0][i] - sum(location[0][i]));
	    	dp[i][j+1] = min(dp[i][j+1], dp[i][j] + location[1][j] - sum(location[1][j]));
	    	add(location[1][j], 1);
	    }
	 	if(i < n)dp[i+1][n] = min(dp[i+1][n], dp[i][n] + location[0][i] - sum(location[0][i]));
	    
	    FOR(j,n)add(location[1][j], -1);
	}

	cout << dp[n][n] << endl;
	return 0;
}

Measured memory_bytes: 19308
#include <cctype>
#include <cmath>
#include <iostream>

int count_digits(int n) {
  return static_cast<int>(floor(log10(n))) + 1;
}

int main() {
  int n, m;
  while (!std::cin.eof() && std::cin.peek() != '\n') {
    std::cin >> n >> m;
    std::cout << count_digits(n + m) << std::endl;
    while (isspace(std::cin.peek())) { std::cin.ignore(); }
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {
  int N, j[4] = {0, 0, 0, 0};
  string s;
  cin >> N;
  for(int i = 0; i<N; i++){
    cin >> s;
    if(s == "AC") j[0]++;
    if(s == "WA") j[1]++;
    if(s == "TLE") j[2]++;
    if(s == "RE") j[3]++;
  }
  
  cout << "AC x " << j[0] << endl;
  cout << "WA x " << j[1] << endl;
  cout << "TLE x " << j[2] << endl;
  cout << "RE x " << j[3] << endl;

  return 0;
}

Measured memory_bytes: 3624
n,t=map(int,input().split())
c=[]
time=[]
re=[]
l=[]
for i in range(n):
    a,b=map(int,input().split())
    c.append(a)
    time.append(b)
    
for i in range(n):
    if time[i]>t:
        re.append(i)

for j in range(n):
    if j in re:
        continue
    else:
        l.append(c[j])

if len(l)==0:
    print('TLE')
else:
    print(min(l))
        

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

int main(){
    ll n,k;
    
    cin>>n>>k;
    
    bool ans[n+1];
    for (int i=1; i<=n; i++){
        ans[i]=false;
    }
    for (int i=0; i<k; i++){
        ll d;
        cin>>d;
        for (int j=0; j<d; j++){
            ll p;
            cin>>p;
            ans[p]=true;
        }
    }
    ll count=0;
    for (int i=1; i<=n; i++){
        if (ans[i]==false) count+=1;
    }
    cout<<count<<endl;
}
  

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cmath>

#define MAX 8

using namespace std;

int main(void){
	while( true ){
		int ppl[MAX];
		int gondra[MAX] = {4,1,4,1,2,1,2,1};
		int ans[MAX];
		unsigned int leftPpl = 1 << 22;
		unsigned int Vmin = 1 << 22;

		for(int i = 0; i < MAX; i++) cin >>ppl[i];
		if( cin.eof() ) break;

		for(int i = 0; i < MAX; i++){
			unsigned int V = 0;
			unsigned int P = 0;
			for(int j = 0; j < MAX; j++){
				V += (unsigned int)pow(10.0, MAX - j - 1) * gondra[j];
				P += max(0, ppl[j] - gondra[j]);
			}
			if( P < leftPpl ){
				leftPpl = P;
				Vmin = V;
				copy(gondra,gondra+sizeof(gondra)/sizeof(*gondra),ans);
			}else if( P == leftPpl && V < Vmin ){
				Vmin = V;
				copy(gondra,gondra+sizeof(gondra)/sizeof(*gondra),ans);
			}
			rotate(gondra, gondra+1, gondra+sizeof(gondra)/sizeof(*gondra));
		}

		cout << ans[0]; 
		for(int i = 1; i < MAX; i++){
			cout << " " << ans[i];
		}
		cout << '\n';
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

void solve()
{
    ll N, D;
    cin >> N >> D;
    vector<vector<ll>> X(N, vector<ll>(D));
    for (ll i = 0; i < N; i++)
    {
        for (ll j = 0; j < D; j++)
        {
            cin >> X.at(i).at(j);
        }
    }

    ll count = 0;
    for (ll i = 0; i < N; i++)
    {
        for (ll j = i + 1; j < N; j++)
        {
            ll dist = 0;
            for (ll d = 0; d < D; d++)
            {
                dist += pow(X.at(i).at(d) - X.at(j).at(d), 2);
            }
            double sq = sqrt(dist);
            if (dist == (ll)(floor(sq) * floor(sq)))
            {
                count++;
            }
        }
    }

    cout << count << endl;

    return;
}

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


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long int n; cin>>n;
  cout<<(1+n-1)*(n-1)/2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,A,B;
  cin >> N >> A >>B;
  
  int ans = 0;
  for(int i = 0; i <= N ; i++){
    int n = i;
    int sum = 0;
    while( n > 0 ){
      sum += n % 10;
      n /= 10;
    }
    if(A <= sum && sum <= B) ans+= i;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#define llint long long

using namespace std;

llint n, m;
llint a[5];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	llint s, c;
	for(int i = 1; i <= n; i++) a[i] = -1;
	for(int i = 1; i <= m; i++){
		cin >> s >> c;
		if(a[s] != -1 && a[s] != c){
			cout << -1 << endl;
			return 0;
		}
		a[s] = c;
	}
	
	if(n == 1){
		if(a[1] <= 0){
			cout << 0 << endl;
			return 0;
		}
	}
	
	if(a[1] == 0){
		cout << -1 << endl;
		return 0;
	}
	if(a[1] == -1) a[1] = 1;
	for(int i = 2; i <= n; i++){
		if(a[i] == -1) a[i] = 0;
	}
	
	for(int i = 1; i<= n; i++)  cout << a[i]; cout << endl;
	
	return 0;
}

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

using namespace std;

typedef long long LL;
int n;
int arr[110000];
int cnt[110000];

vector<pair<int, int>> V;

int main() {
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
        cnt[arr[i]] ++;
    }
    LL ans = 0;
    for(int i = 0; i <= 100000; i++)
        if(cnt[i] >= 2)
            V.push_back(make_pair(i, cnt[i] - 1)), ans += cnt[i] - 1;
    int cost;
    sort(V.begin(), V.end());
    int buf = 0;
    for(int i = 0; i < V.size();) {
        if(buf == 0) {
            buf = V[i].second;
            V[i].second = 0;
            i++;
        } else {
            if(buf >= V[i].second) {
                buf -= V[i].second;
                V[i].second = 0;
                i++;
            } else {
                V[i].second -= buf;
                buf = 0;
            }
        }
    }
    while(buf >= 2) {
        buf -= 2;
    }
//    LL res = 0;
//    for(int i = 0; i < n; i++)
//        if(res > V[V.size() - 1].first)
//            res ++;
    cout<<n - (buf + ans)<<endl;
    return 0;
}


Measured memory_bytes: 1280
h,w,k = map(int,input().split())
maze = []
for _ in range(h):
  maze.append(list(input()))

def check(rows, cols):
  black = 0
  for i in range(h):
    if i in rows: continue
    for j in range(w):
      if j in cols: continue
      if maze[i][j] == "#":
        black += 1

  return black == k

res = 0

for i in range(1<<h):
  paint_rows = []
  for j in range(h):
    if (i>>j)&1:
      paint_rows.append(j)

  for n in range(1<<w):

    paint_cols = []
    for m in range(w):
      if (n>>m)&1:
        paint_cols.append(m)

    if check(paint_rows, paint_cols):
      res += 1

print(res)


Measured memory_bytes: 73952
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    vector<int> a(m);
    for(int i=0; i<m; ++i)
        cin >> a[i];

    vector<int> dp(10, 0);
    dp[0] = 1;

    for(int i=0; i<n; ++i){
        vector<int> next(10, 0);
        if(s[i] == '*'){
            for(int j=0; j<m; ++j){
                int x = a[j];
                if((n - i) % 2 == 0){
                    x *= 2;
                    x = x / 10 + x % 10;
                }

                for(int k=0; k<10; ++k)
                    next[(k+x)%10] += dp[k];
            }
        }else{
            int x = s[i] - '0';
            if((n - i) % 2 == 0){
                x *= 2;
                x = x / 10 + x % 10;
            }

            for(int j=0; j<10; ++j)
                next[(j+x)%10] = dp[j];
        }

        dp.swap(next);
    }

    cout << dp[0] << endl;

    return 0;
}

Measured memory_bytes: 1336
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=110;
char s[N],t[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n;
    scanf("%d%s%s",&n,s+1,t+1);
    for(int i=n;~i;i--) {
	bool flg=1;
	for(int j=1;j<=i;j++)
	    if(s[n-i+j]!=t[j]) flg=0;
	if(flg) return cout<<n+n-i,0;
    }
    return 0;
}

Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1131&lang=jp
// 国内予選2004C
// Unit Fraction Partition

/*
Problem.


Point.

*/

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

struct rational{
  int p, q;
  rational(int ip, int iq):p(ip), q(iq){}
  rational operator +(rational obj){
    int tp, tq;
    tp = p * obj.q + obj.p * q;
    tq = q * obj.q;
    return rational(tp, tq);
  }
};

int p, q, a, n;
int dfs(int k, int last, int prod, rational acc){
  if(acc.p * q == p * acc.q) return 1;
  if(k >= n) return 0;
  int ret = 0;
  for(int i = last; prod*i <= a; i++){
    rational tmp(acc + rational(1, i));
    if(tmp.p * q <= p * tmp.q){
      ret += dfs(k+1, i, prod*i, tmp);
    }
  }
  return ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  while(cin >> p >> q >> a >> n && p){
    cout << dfs(0, 1, 1, rational(0, 1)) << endl;
  }
  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}



Measured memory_bytes: 3184