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


struct QuickFind{
  Int n;
  vector<Int> r,p,dat,laz;
  vector<vector<Int> > v;
  QuickFind(){}
  QuickFind(Int sz):n(sz),r(sz),p(sz),dat(n,0),laz(n,0),v(sz){
    for(Int i=0;i<n;i++){
      r[i]=1,p[i]=i;
      v[i].resize(1,i);
    }
  }
  bool same(Int x,Int y){
    return p[x]==p[y];
  }
  void unite(Int x,Int y,Int w){
    x=p[x];y=p[y];
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    //cout<<x<<" "<<r[x]<<":"<<y<<" "<<r[y]<<":"<<w<<endl;
    for(Int i=0;i<(Int)v[y].size();i++){
      p[v[y][i]]=x;
      v[x].push_back(v[y][i]);
      dat[v[y][i]]-=laz[x];
      dat[v[y][i]]+=laz[y];
      dat[v[y][i]]+=(r[x]-r[y])*w;
    }
    laz[x]+=r[y]*w;
    r[x]+=r[y];
    v[y].clear();
    laz[y]=0;
  }
  Int get(Int x){
    //cout<<x<<" "<<dat[x]<<" "<<laz[p[x]]<<endl;
    return dat[x]+laz[p[x]];
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  using T = tuple<Int, Int, Int>;
  vector<T> v;
  for(Int i=1;i<n;i++){
    Int a,b,c;
    cin>>a>>b>>c;
    v.emplace_back(c,--a,--b);
  }
  sort(v.rbegin(),v.rend());
  QuickFind uf(n);
  for(Int i=1;i<n;i++){
    Int c,a,b;
    tie(c,a,b)=v[i-1];
    uf.unite(a,b,c);
  }
  for(Int i=0;i<n;i++) cout<<uf.get(i)<<endl;
  return 0;
}


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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

long double dis(double x1, double x2, double y1, double y2){
	return sqrtl( (long double)((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)));
}
long double dis(int x1, int x2, int y1, int y2){
	return sqrtl( (long double)((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)));
}

int main() {
	ll n,xx, yy;
	V<double> x;
	V<double> y;
	int cnt = 1;
	V<int> p;
	long double ans = 0.0;

	cin >> n;
	REP(i,n) {
		cnt *= i+1;
		p.push_back(i);
		cin >> xx >> yy;
		x.push_back(xx);
		y.push_back(yy);
	}

	double c = (double)cnt;
	do {
		REP(i,n-1) {
			ans += dis(x[p[i]], x[p[i+1]], y[p[i]], y[p[i+1]])/c;
		}
	} while(next_permutation( ALL(p)) );
	printf("%.10Lf\n", ans);
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
# define    all(a)              a.begin(), a.end()
#define forn(i, a, b) for (int i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define MOD int(1e9+7)
using namespace std;

typedef long long int ll;

bool cmp(int a, int b) {
    return a < b;
}

void printV(vector<int> nums) {
    for (int i: nums) {
        printf("%d ", i);// << " ";
    }
    printf("\n");
}

// void printV(vector<ll> nums) {
//     for (ll i: nums) {
//         printf("%lld ", i);// << " ";
//     }
//     printf("\n");
// }



int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

bool valid(int i, int j, int n, int m) {
    if (i >= 0 && i < n && j >=0 && j < m)
        return true;
    else 
        return false;
}


int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    // ios_base::sync_with_stdio(false);
    // cin.tie(0);cout.tie(0);
    // time_t start, end;
    // time(&start);
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    for (int i=0; i<ty-sy; i++)
        cout << "U";
    for (int i=0; i<tx-sx; i++)
        cout << "R";
    for (int i=0; i<ty-sy; i++)
        cout << "D";
    for (int i=0; i<tx-sx; i++)
        cout << "L";
    cout << "L";
    for (int i=0; i<ty-sy+1; i++)
        cout << "U";
    for (int i=0; i<tx-sx+1; i++)
        cout << "R";
    cout << "D";
    cout << "R";
    for (int i=0; i<ty-sy+1; i++)
        cout << "D";
    for (int i=0; i<tx-sx+1; i++)
        cout << "L";
    cout << "U" << endl;
    // time(&end); 
    // double time_taken = double(end - start);
    // cout << "Time Taken: " << fixed << time_taken << setprecision(5);
    // cout << " sec" << endl;
    return 0;
}  

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<map>
#include<set>


using namespace std;

int main(){
    int n;
    string s;
    set<int> ans;
    cin >> n >> s;
    map<int, int> m1, m2;
    for(int i=0;i<n;i++)m1[int(s[i]) - int('0')]++;
    for(int i=0;i<n;i++){
        m1[int(s[i]) - int('0')]--;
        for(int j=0;j<10;j++){
            for(int k=0;k<10;k++){
                if(m1[j]>0 && m2[k]>0){
                    ans.insert(k*100 + (int(s[i]) - int('0'))*10 + j);
                }
            }
        }
        m2[int(s[i]) - int('0')]++;
    }
    cout << ans.size() << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

long long dp[100010];
int main(){
    rep(i,100010) dp[i]=LINF;
    int n,k; cin>>n>>k;
    int h[n]; rep(i,n) cin>>h[i];
    dp[1]=0;
    for(int i=2;i<=n;i++){
        for(int j=1;j<=k;j++){
            if(i-1-j>=0) dp[i]=min(dp[i],dp[i-j]+abs(h[i-1]-h[i-1-j]));
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int len=s.length();
	int i;
	for(i=1; i<=len; i++)
	{
		int tmp=s[len-1];
		for(int j=len-2; j>=0; j--)
		{
			s[j+1]=s[j];
		}
		s[0]=tmp;
		if(s==t)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N,A; cin>>N>>A;
  vector<map<int,int>> dp(N+1);
  dp[0][0]=1;
  REP(i,1,N){
    int X; cin>>X;
    int Y=X-A;
    for(auto p:dp[i-1]){
      int P=p.first,Q=p.second;
      dp[i][P]+=Q;
      dp[i][P+Y]+=Q;
    }
  }
  cout<<dp[N][0]-1<<endl;
  }


Measured memory_bytes: 1664
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<list>
#include <cstring>
#include <functional>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF ((Int)1<<60)
#define EPS (1e-10)
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define RREP(i,n) for(int i=1; i<=(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long Int;
typedef pair<Int, Int> PI;
typedef pair<int, int> P;
typedef vector<double> vec;
typedef vector<vec> mat;
const int N = 100005;
//////////////////////////////

int h, w, k;
Int dp[110][10];
Int cnt[8] = { 1,2,3,5,8,13,21,34 };

void solve()
{
	cin >> h >> w >> k;
	dp[0][0] = 1;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			Int X = 1, Y = 1, Z = 1;

			if (j - 1 >= 0) X *= cnt[j - 1];
			if (w - 2 - j >= 0) X *= cnt[w - j - 2];
			dp[i + 1][j] += X * dp[i][j]; dp[i + 1][j] %= MOD;
			
			if (j - 2 >= 0) Y *= cnt[j - 2]; 
			if (w - 2 - j >= 0) Y *= cnt[w - j - 2];
			dp[i + 1][j - 1] += Y * dp[i][j]; dp[i + 1][j - 1] %= MOD;

			if (j - 1 >= 0) Z *= cnt[j - 1];
			if (w - 3 - j >= 0) Z *= cnt[w - j - 3];
			dp[i + 1][j + 1] += Z * dp[i][j]; dp[i + 1][j + 1] %= MOD;
		}
	}
	cout << dp[h][k - 1] << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
	solve();
	return 0;
}


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

int main(){
  
  int n,cnt=0;
  string s;
  cin>>n>>s;
  
  int len = s.length();
  
  for(int i=0;i<len-2;i++){
    if(s.at(i)=='A' && s.at(i+1)=='B' && s.at(i+2)=='C')
      cnt++;
  }
      
    cout<<cnt<<endl;
  
  return 0;
}

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int h, w;
  cin >> h >> w;

  if ( h == 1 && w == 1 ) cout << 1 << endl;
  else if ( h == 1 || w == 1 ) cout << h*w -2 << endl;  
  
  else cout << h*w - 2*(h-2) - 2*(w-2) - 4 << endl;
  
  return 0;
}


Measured memory_bytes: 256
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

A = [LI() for i in range(3)]
N = I()
b = [I() for i in range(N)]

B = [[0]*3 for i in range(3)]  #当たりなら1,外れなら0

for i in range(3):
    for j in range(3):
        for k in b:
            if A[i][j] == k:
                B[i][j] = 1

for i in range(3):
    if (len(set(B[i])) == 1 and B[i][0] == 1) or (len(set([B[j][i] for j in range(3)])) == 1 and B[0][i] == 1):
        print('Yes')
        exit()
if B[0][0] == 1 and B[1][1] == 1 and B[2][2] == 1:
    print('Yes')
    exit()
if B[0][2] == 1 and B[1][1] == 1 and B[2][0] == 1:
    print('Yes')
    exit()

print('No')

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

int num_top(int i){
    int num = i;
    int top;
    while(num > 0){
        top = num % 10;
        num = num / 10;
    }
    return top;
}

int create_num(int top, int under, int N){
    int num = 0;
    if(top == under){
        num++;
    }
    if(10*under + top > N){
        return num;
    }
    else{
        num++;
    }


    int N_keta = 0;
    int N_top;
    int lim = N;
    while(lim > 0){
        N_top = lim % 10;
        N_keta++;
        lim = lim / 10;
    }

    //3桁以降の処理
    int keta = N_keta - 2;
    if(keta <= 0){
        return num;
    }

    if(N_keta > 3){
        num += 10*((int)pow(10, keta-1) - 1)/9;
    }
    
    if(N_top > under){
        num += (int)pow(10, (N_keta-2));
    }

    else if(N_top == under){
        int mid_num = (N - N_top*(int)pow(10, N_keta-1))/10;
        if(mid_num != 0){
            if(N % 10 >= top){
                num += mid_num+1;
            }
            else{
                num += mid_num;
            }
        }
    }
    return num;
}

int count_num(int N){
    int count = 0;
    for(int i = 1; i <= N; i++){
        if(i % 10 != 0){
            int under = i % 10;
            int top = num_top(i);
            count += create_num(top, under, N);
        }
    }
    return count;
}

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

    cout << count_num(N) << endl;

    return 0;
}

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

int main() {
  int a,b;
  char op;
  while(1){
    cin>>a>>op>>b;
    if(op=='+'){
      cout<<a+b<<endl;
    }else if(op=='-'){
      cout<<a-b<<endl;
    }else if(op=='*'){
      cout<<a*b<<endl;
    }else if(op=='/'){
      cout<<a/b<<endl;
    }else if(op=='?') break;
  }
  return 0;
}
  


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

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

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	vvint A(3, vint(3)); cin >> A;
	int N; cin >> N;
	while (N--) {
		int b;
		cin >> b;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (A[i][j] == b) A[i][j] = 0;
			}
		}
	}
	bool flag = false;
	for (int i = 0; i < 3; i++) {
		flag |= (A[i][0] + A[i][1] + A[i][2] == 0);
		flag |= (A[0][i] + A[1][i] + A[2][i] == 0);
	}
	flag |= (A[0][0] + A[1][1] + A[2][2] == 0);
	flag |= (A[2][0] + A[1][1] + A[0][2] == 0);
	cout << (flag ? "Yes" : "No") << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 256
import math

def is_prime(x):
    if x == 1: return False
    for i in range(2, int(math.sqrt(x)) + 1):
        if x % i == 0:
            return False
    return True

while True:
    try: n = int(input())
    except: break
    
    low_prime = 0
    for i in range(n-1, 0, -1):
        if is_prime(i):
            low_prime = i
            break
    
    high_prime = n + 1
    while True:
        if is_prime(high_prime):
            break
        else:
            high_prime += 1

    print('{} {}'.format(low_prime, high_prime))



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

int main(){
  int C[4][13] = {{},{},{},{}};
  int n;
  cin >> n;
  for (int i=0; i<n; ++i){
    char s; int r;
    cin >> s >> r;
    if (s == 'S') C[0][r-1] = 1;
    if (s == 'H') C[1][r-1] = 1;
    if (s == 'C') C[2][r-1] = 1;
    if (s == 'D') C[3][r-1] = 1;
  }
  for (int s=0; s<4; ++s){
    for (int r=0; r<13; ++r){
      if (C[s][r] == 0){
	if (s == 0) cout << "S " << r+1 << endl;
	if (s == 1) cout << "H " << r+1 << endl;
	if (s == 2) cout << "C " << r+1 << endl;
	if (s == 3) cout << "D " << r+1 << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3084
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
using namespace std;

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=2019;
#define ll long long

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    vector<vector<int> > vec(m);
    rep(i,m){
        int k; cin>>k;
        vec[i].resize(k);
        rep(j,k){
            cin>>vec[i][j];
            --vec[i][j];
        }
    }
    vector<int>p(m);
    rep(i,m)cin>>p[i];
    int ans=0;
    rep(i,(1<<n)){
        bool ok=true;
        rep(j,m){
            int c=0;
            for(int id:vec[j]){
                if((i>>id)&1){
                    ++c;
                }
            }
            c%=2;
            if(c!=p[j]){
                ok=false;
            }
        }
        if(ok){
            ++ans;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
n, y = map(int, input().split())

flg = False

# iは10000円札の枚数、jは5000円札の枚数、kは1000円札の枚数
for i in range(n + 1):
    for j in range(n + 1 - i):
        k = (y - 10000 * i - 5000 * j) // 1000
        if i + j + k == n and not flg:
            flg = True
            print(i, j, k)
            break
    else:
        continue
    break

if not flg:
    print(-1, -1, -1)


Measured memory_bytes: 3060
s = input()
a = int(s[0:2])
b = int(s[2:4])

if (1 <= a <= 12)  and (1 <= b <= 12):
    print('AMBIGUOUS')
elif (a == 0 or 13 <= a <= 99) and (1 <= b <= 12):
    print('YYMM')
elif (b == 0 or 13 <= b <= 99) and (1 <= a <= 12):
    print('MMYY')
else:
    print('NA')

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

int main() {
    string S;
    ll K;
    cin >> S >> K;

    if (S.size() == 1) {
        cout << K/2 << endl;
        return 0;
    }

    ll ans = 0;
    bool tmp = false;
    bool ok = false;
    rep(i, S.size()-1) {
        if (tmp) {
            tmp = false;
        }
        else if (S[i] == S[i+1]) {
            ans++;
            tmp = true;
            if (i == S.size()-2) {
                ok = true;
            }
        }
    }

    if (ok or S[0] != S[S.size()-1]) {
        cout << ans*K << endl;
        return 0;
    }

    // 最初と最後が同じ
    else if (S[0] == S[S.size()-1]) {
        ll tmpans1 = 0, tmpans2 = 0;
        bool tmp = false;
        rep(i, S.size()-1) {
            if (tmp) {
                tmp = false;
                continue;
            }
            if (S[i] == S[i+1]) {
                tmpans1++;
                tmp = true;
            }
        }

        tmp = false;
        bool last = false;
        tmpans2=1;
        for (int i=1; i<S.size()-1; ++i) {
            if (tmp) {
                tmp = false;
                continue;
            }
            if (S[i] == S[i+1]) {
                tmpans2++;
                tmp = true;
                if (i == S.size()-2) {
                    last = true;
                }
            }
        }

        if (last) {
            cout << tmpans1*(K/2+K%2) + tmpans2*(K/2) << endl;
        }
        else {
            cout << tmpans1 + tmpans2*(K-1) << endl;
        }
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        boolean judge = n % digsum(n) == 0;
        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
    }

    public static int digsum(int num) {
        int sum = 0;
        while (num > 0) {
            sum += num % 10;
            num /= 10;
        }
        return sum;
    }
}


Measured memory_bytes: 21844
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)

//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

void solve()
{
    IN(n);
    ll x[n];
    ll s = 0;
    ll t = 0;
    rep(i, n)
    {
        cin >> x[i];
        s += x[i];
        t += x[i] * x[i];
    }
    ll m = INF;
    reps(i, 1, 101)
    {
        if (n * i * i - 2 * i * s < m)
        {
            m = n * i * i - 2 * i * s;
        }
    }
    cout << m + t << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

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

using namespace std;

void a()
{
    string s;
    cin >> s;
    if(s.size() > 9)
    {
        cout << "NO" << endl;
        return;
    }
    string akb = "AKIHABARA";
    string result = "";
    int index = 0;
    for(int i = 0; i < akb.size(); i++)
    {
        if(s[index] == akb[i] && index < s.size())
        {
            result += s[index];
            index++;
        } else{
            result += "A";
        }
    }
    if(result == akb){
        cout << "YES" << endl;
    } else{
        cout << "NO" << endl;
    }
}

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


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

int down(const void *a,const void *b){
  return *(int *)b - *(int *)a;
}

int main(void){
  int n;
  scanf("%d",&n);
  
  int v[n+1] , kisu[100010] = {0} , gusu[100010] = {0};
  int kisumax = 0 , gusumax = 0;
  int x , y;

  for(int i = 1;i <= n;i ++){
    scanf("%d",&v[i]);
    if(i%2 == 1){
      kisu[v[i]] ++;
      if(kisumax < kisu[v[i]]){
        kisumax = kisu[v[i]];
        x = v[i];
      }
    }

    else{
     gusu[v[i]] ++;
     if(gusumax < gusu[v[i]]){
       gusumax = gusu[v[i]];
       y = v[i];
     }
    }
  }

  int ans = 0;
  if(x != y){
    for(int i = 1;i < 100001;i ++){
    ans += kisu[i] + gusu[i];
  }
  ans -= kisumax + gusumax;
  }

  else{
    qsort(kisu,100010,sizeof(int),down);
    qsort(gusu,100010,sizeof(int),down);

    for(int i = 0;i < 100001;i ++){
      ans += kisu[i] + gusu[i];
      //printf("%d %d\n",kisu[i],gusu[i]);
    }
    int ans1 = ans , ans2 = ans;
      ans1 -= kisumax + gusu[1];
      ans2 -= gusumax + kisu[1];
      if(ans1 < ans2){
        ans = ans1;
      }
      else{
        ans = ans2;
      }
  }
  
  printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 3088
import math


def main():
    N, M = list(map(int, input().strip().split()))
    diff = abs(N - M)
    if diff > 1:
        print(0)
        return

    n_fact = math.factorial(N)
    m_fact = math.factorial(M)
    a = n_fact * m_fact
    if diff == 0:
        a = a * 2

    print(a % (10 ** 9 + 7))

if __name__ == '__main__':
    main()


Measured memory_bytes: 5180
def dist(x,y,x1,y1):
	return (x-x1)**2+(y-y1)**2
	
def inWall(x,y,x1,y1,r):
 	return True if dist(x,y,x1,y1) <= (r + 1e-9)**2 else False

def isHide(x,y,r,a,b,c):
	D = abs(a*x+b*y+c)/(a**2+b**2)**0.5
	return True if D <= r + 1e-9 else False

def isBetween(x,y,tx,ty,sx,sy):
	a,b,c = dist(x,y,tx,ty),dist(x,y,sx,sy),dist(tx,ty,sx,sy)
	if c > b and c > a: return True
	a,b,c = sorted([a,b,c])
	return True if c-a-b <= 0 else False

while 1:
	n = input()
	if n == 0: break
	wall = [map(int,raw_input().split()) for i in range(n)]
	for i in range(input()):
		tx,ty,sx,sy = map(int,raw_input().split())
		a,b,c = -(ty-sy),tx-sx,sx*ty-sy*tx
		for x,y,r in wall:
			t_in,s_in = inWall(x,y,tx,ty,r),inWall(x,y,sx,sy,r)
			if t_in != s_in or (not t_in and isBetween(x,y,tx,ty,sx,sy) and isHide(x,y,r,a,b,c)):
				print "Safe"
				break
		else:
			print "Danger"

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

int main()
{
	int a[3];

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

	for (int s = 0; s < 2; s++){
		for (int t = s + 1; t < 3; t++){
			if (a[s] > a[t]){
				int tmp = a[s];
				a[s] = a[t];
				a[t] = tmp;

			}
		}
	}
	cout << a[0] << " " << a[1] << " " << a[2] << endl;

	return 0;
}

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

int main() {
  int n, p;
  cin >> n >> p;
  bool flag = false;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a%2 == 1) {
      flag = true;
    }
  }
  long long ans;
  if (flag) {
    ans = pow(2, n - 1);
  }
  else {
    if (p == 1) {
      ans = 0;
    }
    else {
      ans = pow(2, n);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.*;

public class Main  implements Runnable {
    static ContestScanner in;
    static Writer out;
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
    }

    public void run() {
        Main main = new Main();
        try {
            in = new ContestScanner();
            out = new Writer();
            main.solve();
            out.close();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    void solve() throws IOException {
        String ans = "";
        for (int i = 0; i < 3; i++) {
            ans += in.nextToken().charAt(0);
        }
        System.out.println(ans.toUpperCase());
    }


}

class Writer extends PrintWriter{
    public Writer(String filename)throws IOException
    {super(new BufferedWriter(new FileWriter(filename)));}
    public Writer()throws IOException {super(System.out);}
}
class ContestScanner implements Closeable {
    private BufferedReader in;private int c=-2;
    public ContestScanner()throws IOException
    {in=new BufferedReader(new InputStreamReader(System.in));}
    public ContestScanner(String filename)throws IOException
    {in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
    public String nextToken()throws IOException {
        StringBuilder sb=new StringBuilder();
        while((c=in.read())!=-1&&Character.isWhitespace(c));
        while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public String readLine()throws IOException{
        StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
        while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public long nextLong()throws IOException,NumberFormatException
    {return Long.parseLong(nextToken());}
    public int nextInt()throws NumberFormatException,IOException
    {return(int)nextLong();}
    public double nextDouble()throws NumberFormatException,IOException
    {return Double.parseDouble(nextToken());}
    public void close() throws IOException {in.close();}
}

Measured memory_bytes: 24916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18)+1;

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

    ll n,x,t;
    cin >> n >> x >> t;

    if(n%x == 0){
        cout << n/x*t;
    }
    else{
        cout << (n/x+1)*t;
    }
    return 0;
}

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

int main()
{
	string s, t;
	cin >> s >> t;

	bool equal_f = s == t.substr(0, s.length());
	auto diff = t.length() - s.length();

	if (equal_f && diff == 1) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

int main(){
    int N;
    vector<long long> L(100);

    cin>>N;

    L[0] = 2;
    L[1] = 1;

    for(int i=2;i < 100;i++) L[i] = L[i-1] + L[i-2];

    cout<<L[N]<<endl;
}

Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val S = next()
    val T = next()
    if (S.length < T.length) return println("UNRESTORABLE")
    fun match(s: String, t: String): Boolean {
        for (n in 0 until T.length)
            if (s[n] != '?' && s[n] != t[n]) return false
        return true
    }
    var ans = mutableListOf<String>()
    for (n in 0 until S.length - T.length + 1)
        if (match(S.substring(n until n + T.length), T)) {
            val SS = S.map { it }.toCharArray()
            for (m in 0 until T.length) {
                SS[n + m] = T[m]
            }
            for (m in 0 until S.length) {
                if (SS[m] == '?') SS[m] = 'a'
            }
            ans.add(SS.joinToString(""))
        }
    if (ans.size == 0) return println("UNRESTORABLE")
    println(ans.sorted().first())
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(d: Int = 0) = listOfString().map { Integer.parseInt(it) + d }
fun listOfLong() = listOfString().map(String::toLong)


Measured memory_bytes: 36324
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
ll f[1000010], invf[1000010];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
int main()
{
    int n; cin>>n;
    cout<<(powmod(10, n)-2*powmod(9, n)+powmod(8, n)+2*MOD)%MOD<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
/*
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};
*/
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

//デバッグ
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};


ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}


//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

ll N;
vector<pair<pair<ll, ll>, pair<ll, ll>>> wsv;

void solve(){
  ll dp[N+1][30000];
  rep(i, N+1)rep(j, 30000) dp[i][j] = 0;
  dp[0][0] = 0;
  rep(i, N){
    ll w = wsv[i].f.s;
    ll s = wsv[i].s.f;
    ll v = wsv[i].s.s;
    rep(j, 30000){
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
      if(j <= s){
        dp[i+1][w+j] = max(dp[i+1][w+j], dp[i][j] + v);
      }
    }
  }
  ll ans = 0;
  rep(i, 30000){
    ans = max(ans, dp[N][i]);
  }
  cout << ans << endl;
}
int main(){
  cin >> N;
  wsv.resize(N);
  rep(i, N){
    ll w, s, v;
    cin >> w >> s >> v;
    wsv[i].f.f = w + s;
    wsv[i].f.s = w;
    wsv[i].s.f = s;
    wsv[i].s.s = v;
  }
  sort(wsv.begin(), wsv.end());
  solve();
}


Measured memory_bytes: 234880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll clear, o, z, zz, oz, zo, ozz;
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    if(S[0] != '0') o++;
    if(S[0] != '1') z++;
    for(int i = 1; i < S.size(); i++) {
        ll nclear, no , nz, nzz, noz, nzo, nozz;
        nclear = no = nz = nzz = noz = nzo = nozz = 0;
        if(S[i] != '1') {
            nclear += clear;
            nzz += z;
            nz += zz + zo;
            nozz += oz;
            noz += o + ozz;
        }
        if(S[i] != '0') {
            nclear += clear + o;
            nzo += z;
            nz += zz;
            no += oz + zo;
            noz += ozz;
        }
        clear = nclear % mod;
        o = no % mod;
        z = nz % mod;
        zz = nzz % mod;
        oz = noz % mod;
        zo = nzo % mod;
        ozz = nozz % mod;
        //cerr << clear << " " << o << " " << z << " " << zz << " " << oz << " " << zo << " " << ozz << endl;
    }
    cout << (clear + o) % mod << endl;
    return 0;
}


Measured memory_bytes: 720
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  int size;
  cin >> size;
  string s;
  cin >> s;
  int left = 0;
  int right = size-1;
  int count = 0;
  while (left < right) {
    if (s[left] == 'W') {
      if (s[right] == 'R') {
        count++;
        left++; right--;
        continue;
      } else {
        right--;
        continue;
      }
    }
    left++;
  }
  cout << count << endl;
}



Measured memory_bytes: 3752
#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(void)
{
  int n, k;
  cin >> n >> k;
  map <int, bool> m;
  rep(i, k) {
    int d;
    cin >> d;
    rep(j, d) {
      int a;
      cin >> a;
      m[a] = true;
    }
  }
  int ans = n - m.size();
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let v : Vec<usize> = get_vec();
    let mut stu = Vec::new();
    for _i in 0..v[0] {
        let xs : Vec<i32> = get_vec();
        stu.push((xs[0], xs[1]));
    }
    let mut cps = Vec::new();
    for _i in 0..v[1] {
        let xs : Vec<i32> = get_vec();
        cps.push((xs[0], xs[1]));
    }
    for j in 0..v[0] {
        let (sx, sy) = stu[j];
        let mut min_d = i32::max_value();
        let mut min_i = 0;
        for i in 0..v[1] {
            let (cx, cy) = cps[i];
            let d = (sx - cx).abs() + (sy - cy).abs();
            if min_d > d {
                min_d = d;
                min_i = i
            }
        }
        println!("{}", min_i+1);
    }

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;

int main(){
  string s;
  while(cin >> s){
    bool ans = true;
    int n = s.size();
    REP(i,n){
      if(i%2==0 and s[i] == 'L') ans = false;
      else if(i%2==1 and s[i]=='R') ans = false;
    }

    cout << (ans ? "Yes" : "No") << endl;
  }


  return 0;
}


Measured memory_bytes: 384
import heapq

N, M = map(int, input().split())
stores = []
for _ in range(N):
    a, b = map(int, input().split())
    heapq.heappush(stores, (a, b))

ans = 0
drinks = 0
while drinks < M:
    a, b = heapq.heappop(stores)
    if b <= M - drinks:
        ans += a*b
        drinks += b
    else:
        ans += a*(M - drinks)
        drinks += M - drinks
print(ans)

Measured memory_bytes: 16668
def insert(tree,k):
    y = None
    x = tree
    z = {'key':k, 'parent':None, 'left':None, 'right':None}
    while x != None:
        y = x
        if x['key'] > k:
            x = x['left']
        else:
            x = x['right']
    z['parent'] = y
    if y == None:
        tree = z
    elif y['key'] > k:
        y['left'] = z
    else:
        y['right'] = z
    return tree

def find(tree,k):
    x = tree
    while x != None:
        if x['key'] == k:
            print "yes"
            return
        elif x['key'] > k:
            x = x['left']
        else:
            x = x['right']
    print "no"

def middleorder(x):
    if x != None:
        middleorder(x['left'])
        print x['key'],
        middleorder(x['right'])

def preorder(x):
    if x != None:
        print x['key'],
        preorder(x['left'])
        preorder(x['right'])



tree = None
m = int(raw_input())
for i in range(m):
    c = raw_input().strip()
    if c[0] == 'i':
        tree = insert(tree, int(c[7:]))
    elif c[0] == 'f':
        find(tree, int(c[5:]))
    elif c[0] == 'p':
        print '',
        middleorder(tree)
        print
        print '',
        preorder(tree)
        print

Measured memory_bytes: 146092
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL =LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

ll gcb(ll a, ll b){/// ユークリッドの互除法: O(log)
    
    if(b == 0) return a;
    
    return gcb(b,a%b);
}


ll lcm(ll a, ll b){
    
    return  a/gcb(a,b) * b; ///gcbは約数
}


int main() {
    ll q,h,s,d;cin>>q>>h>>s>>d;
    ll n;cin>>n;
    
    ll p2l = INFL;
    p2l = min(p2l,d);
    p2l = min(p2l,2*s);
    p2l = min(p2l,4*h);
    p2l = min(p2l,8*q);
    
    ll val = 0;
    
    while(n-2>=0){
        n-=2;
        val+=p2l;
    }
    p2l = INFL;
    p2l = min(p2l,s);
    p2l = min(p2l,2*h);
    p2l = min(p2l,4*q);
    
    while(n-1>=0){
        n-=1;
        val+=p2l;
    }
    cout<<val<<endl;
    return 0;
}








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

int main()
{
    int a,b,x;
    cin >> a >> b;
    if(b<10){
        x = b+10*a;
    }else if(b<100){
        x = b+100*a;
    }else{
        x = b+1000*a;
    }
    int n = sqrt(x);
    if(n*n == x){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for (int i = (a); i < (int)(n); i++)
#define repc(i, a, n) for (int i = (a); i <= (int)(n); i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init)                                              \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
#define DBG(str) cerr << (str) << endl;
int main() {
  int n, t;
  cin >> n >> t;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  ll mi = a[0];
  vector<ll> b(n, 0);
  rep(i, 1, n) {
    b[i] = a[i] - mi;
    mi = min(mi, a[i]);
  }
  sort(all(b));
  ll ma = b[n - 1];
  int ans = upper_bound(all(b), ma) - lower_bound(all(b), ma);
  cout << ans;

  return 0;
}


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

int main(){
	while(1){
		int H,W;
		cin >> H >> W;
		if(H== 0 && W == 0)break;
		for(int i=1;i<=H;++i){
			for(int j =1;j<=W;++j){
				if((i + j) % 2 ==0){
					cout <<"#";
				}
				else{
					cout << ".";
				}
			}
			cout << endl;
		}
	cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while ( sc.hasNext() ) {
			int n = sc.nextInt();
			int cnt = 0;
			for ( int a = 0; a <= 9; a++ ) {
				for ( int b = 0; b <= 9; b++ ) {
					for ( int c = 0; c <= 9; c++ ) {
						for ( int d = 0; d <= 9; d++ ) {
							if ( a+b+c+d == n ) cnt++;
						}
					}
				}
			}
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 12000
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
n = int(input())
a = [int(input()) for i in range(n)]
dp = [[1<<60]*5 for i in range(n+1)]
dp[0][0] = 0
for i in range(n):
        dp[i+1][0] = dp[i][0]+a[i]
        if a[i] != 0:
                dp[i+1][1] = min(dp[i][0]+a[i]%2,dp[i][1]+a[i]%2)
        else:
                dp[i+1][1] = min(dp[i][0]+2,dp[i][1]+2)
        a[i]+=1
        dp[i+1][2] = min(dp[i][0]+a[i]%2,dp[i][1]+a[i]%2,dp[i][2]+a[i]%2)
        a[i]-=1
        if a[i] != 0:
                dp[i+1][3] = min(dp[i][0]+a[i]%2,dp[i][1]+a[i]%2,dp[i][2]+a[i]%2,dp[i][3]+a[i]%2)
        else:
                dp[i+1][3] = min(dp[i][0]+2,dp[i][1]+2,dp[i][2]+2,dp[i][3]+2)
        dp[i+1][4] = min(dp[i][0],dp[i][1],dp[i][2],dp[i][3],dp[i][4])+a[i]
print(min(dp[n]))

Measured memory_bytes: 82000
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x,y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x,y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define d4(x,y,z,w)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z << " | "<< #w << "--> " << w <<endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
#define T ll tt; cin>>tt; while(tt--)
using namespace std;
ll mode=1e9+7;
const long long maxn=30;
const long long inf=99999999999;
ll __lcm(ll a, ll b){ return (a*b)/__gcd(a,b); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getRand(ll l, ll r){ uniform_int_distribution<ll> uid(l, r); return uid(rng); }

void solve(){
	
	//c^2=a^2+b^2-2*a*b*cos(c);
	
	long double a,b,h,m;
	long double dd1=22, dd2=7;
	long double pi=3.14159265358979323846;
	cin>>a>>b>>h>>m;
	long double m1=(m)*(6);
	long double h1=(h)*(30);
	dd1=2;
	if (m!=0) h1+=(m/dd1);
	long double ang=abs(m1-h1);
	//if (ang>180) ang-=180;
	
	dd1=180;
	ang=(ang*(pi))/dd1;
	
	ang=cos(ang);
	
	long double ans=a*a+b*b-2*a*b*ang;
	ans=sqrt(ans);
	cout<<fixed;
	cout<<setprecision(25)<<ans<<endl;
	
	//858 203 11 21
	
	return;
}

 
int main(){ 
    
    #ifndef ONLINE_JUDGE
	//	freopen("input.txt", "r", stdin);
    #endif
    srand(time(0)); 
    
    ios::sync_with_stdio(0);
    cin.tie(0);
 	
	//T{ solve(); }
	solve();
	
	
	return 0;
	
}

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

const int N=2010,N2=N*N,mod=1000000007;
typedef long long ll;
int ksm(ll a,int b,int c=1){
	for(;b;b/=2,a=a*a%mod)
		if(b&1)c=c*a%mod;
	return c;
}

int jc[N2],jc2[N2],n,K,f[N][N];

int C(int n,int k){
	if(k<0||n<k)return 0;
	return (ll)jc[n]*jc2[k]%mod*jc2[n-k]%mod;
}

void Init(){
	jc[0]=1;
	for(int i=1;i<N2;++i)jc[i]=(ll)jc[i-1]*i%mod;
	jc2[N2-1]=ksm(jc[N2-1],mod-2);
	for(int i=N2-1;i;--i)jc2[i-1]=(ll)jc2[i]*i%mod;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>K;Init();--K;
	if(!K){
		cout<<1<<'\n';
		return 0;
	}
	f[0][0]=1;
	for(int i=1;i<=n;++i)
		for(int j=0;j<=i;++j)f[i][j]=(f[i-1][j]+(ll)f[i][j-1]*C((n-j+1)*K+n-i-1,K-1))%mod;
	cout<<(ll)f[n][n]*jc[n]%mod<<'\n';
	return 0;
}


Measured memory_bytes: 46720