akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAX 10000
#define NIL -1
struct Node { int parent, left, right; };
Node T[MAX];
int n, D[MAX], H[MAX];
void setDepth(int u, int d) {
	if (u == NIL)return;
	D[u] = d;
	setDepth(T[u].left, d + 1);
	setDepth(T[u].right, d + 1);
}
int setHeight(int u) {
	int h1 = 0, h2 = 0;
	if (T[u].left != NIL)h1 = setHeight(T[u].left) + 1;
	if (T[u].right != NIL)h2 = setHeight(T[u].right) + 1;
	return H[u] = max(h1, h2);
}
int getSibling(int u) {
	if (T[u].parent == NIL)return NIL;
	if (T[T[u].parent].left != u&&T[T[u].parent].left != NIL)return T[T[u].parent].left;
	if (T[T[u].parent].right != u&&T[T[u].parent].right != NIL)return T[T[u].parent].right;
	return NIL;
}
void print(int u) {
	printf("node %d: ", u);
	printf("parent = %d, ", T[u].parent);
	printf("sibling = %d, ", getSibling(u));
	int deg = 0;
	if (T[u].left != NIL)deg++;
	if (T[u].right != NIL)deg++;
	printf("degree = %d, ", deg);
	printf("depth = %d, ", D[u]);
	printf("height = %d, ", H[u]);
	if (T[u].parent == NIL)printf("root\n");
	else if (T[u].left == NIL&&T[u].right == NIL)printf("leaf\n");
	else printf("internal node\n");
}
int main() {
	int v, l, r, root = 0;
	cin >> n;
	for (int i = 0; i < n; i++)T[i].parent = NIL;
	for (int i = 0; i < n; i++) {
		cin >> v >> l >> r;
		T[v].left = l;
		T[v].right = r;
		if (l != NIL)T[l].parent = v;
		if (r != NIL)T[r].parent = v;
	}
	for (int i = 0; i < n; i++)if (T[i].parent == NIL)root = i;
	setDepth(root, 0);
	setHeight(root);
	for (int i = 0; i < n; i++)print(i);
	return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
vector<ll> pfvec;
ll iflediv=0,ledivexsit=0,sqrtX;
void pf(ll x){
  //pfvecは各約数についての指数を格納
  //ifledivはsqrtNより大きい、存在してもただ一つの約数
  //ledivexsitはifledivが存在するなら1、存在しないのならば0
  //sqrtXはxの平方根
  ll xcopy=x;
  sqrtX=sqrt(x);
  pfvec.resize(sqrtX);
  for(ll i=1;i*i<=xcopy;i++){
    while(x%i==0 && x>1 && prime(i)==1){
      x/=i;
      pfvec.at(i-1)++;
      if(x==1){break;}
    }
    if(xcopy%i==0 && prime(xcopy/i)==1 && x%(xcopy/i)==0 && x>1){
      x/=(xcopy/i);
      ledivexsit++;
      iflediv=xcopy/i;
      break;
    }
  }
}
int main(){
  ll N,ans=1;
  cin>>N;
  ll Ncopy=N;
  pf(N);
  for(ll i=2;i<=sqrtX;i++){
    if(N%i!=0){continue;}
    //cout<<pfvec.at(i)<<endl;
    while(N%i==0){N/=i;}
    if(N%i==1){ans++;}
    N=Ncopy;
  }
  N--;
  //cout<<ans<<endl;
  ll n=N,memo=0,count=0,sqrtN=sqrt(N);
  vector<ll> vec(sqrtN);
  for(ll i=1;i*i<=n;i++){
    ll rock=N;
    while(N%i==0 && N>1 && prime(i)==1){
      N/=i;
      vec.at(i-1)++;
      if(N==1){break;}
    }
    if(n%i==0 && prime(n/i)==1 && N%(n/i)==0){
        N/=(n/i);
        count++;
        memo=n/i;
        break;
    }
  }
  ll rock=1;
  for(ll i=0;i<sqrtN;i++){
    rock*=(vec.at(i)+1);
  }
  rock*=(count+1);
  cout<<rock+ans-1<<endl;
}

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

int h, w, n;
char maze[1001][1001];
int sx, sy;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int d[1001][1001];

void bfs(int x, int y, char point)
{
	queue<pair<int, int>> que;
	que.push({x, y});

	d[x][y] = 0;

	while (que.size()){
		pair<int, int> p = que.front();
		que.pop();

		if (maze[p.first][p.second] == point){
			sx = p.first, sy = p.second;
			return;
		}

		for (int i = 0; i < 4; i++){
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (0 <= nx and nx < h and 0 <= ny and ny < w and maze[nx][ny] != 'X' and d[nx][ny] == -1){
				que.push({nx, ny});
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
}
int main()
{
	cin >> h >> w >> n;
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			cin >> maze[i][j];
			if (maze[i][j] == 'S'){
				sx = i;
				sy = j;
			}
		}
	}

	long long ans = 0;
	memset(d, -1, sizeof(d));
	bfs(sx, sy, '1');
	ans += d[sx][sy];

	for (int i = 2; i < n+1; i++){
		memset(d, -1, sizeof(d));
		bfs(sx, sy, char(i+'0'));
		ans += d[sx][sy];
	}

	cout << ans << endl;
}




Measured memory_bytes: 8032
#include<bits/stdc++.h>
using namespace std;
int n,k;
int answer(int res){
	if(n==0)return res;
	n--;
	return answer(res+min(res,k));
}
int main(){
	scanf("%d%d",&n,&k);
	printf("%d\n",answer(1));
	return 0;
}

Measured memory_bytes: 256
/**
 * @brief  額面がc1, c2, ..., cm円のm種類のコインを使って、n円払うときのコインの最小の枚数を求める
 *         各額面のコインは何度でも使用することができる
 *
 * @note   仮にコインの額面が日本円のように1, 5, 10, 50, 100, 500と決められていれば、与えられた額n円に対して、
 *         額面の大きいものから引いて(割って)いけば、最小の枚数を求めることができる
 *         このように、その時点で最適の解(方法)を選んでいくアルゴリズムを貪欲法(greedy method)という
 *
 * @note   一方、一般的なコイン問題は、使用できる額面によっては貪欲法では正しく解を求めることができない
 *         たとえば、額面が1, 2, 7, 8, 12, 50のについて、15円を支払いたい場合、上記の貪欲法では
 *         12, 2, 1の3枚を選んでしまうが、最適な解は8, 7の2枚となる
 *
 * @note   この問題は動的計画法で最適解を求めることができる. まず、以下のような変数を用意する
 *
 *           C[m]       C[i]をi番目のコインの額面とする配列
 *           T[m][n+1]  T[i][j]をi番目までのコインを使ってj円支払うときのコインの最小枚数とする2次元配列
 *
 *         コインの枚数i, 各iにおける支払う金額jを増やしていき、T[i][j]を更新していく
 *         T[i][j]は、i番目のコインを使わない場合と使う場合の枚数を比べ、小さい方を選べばよいので、
 *         次の漸化式で求めることができる
 *
 *           T[i][j] = min(T[i - 1][j], T[i][j - C[i]] + 1)
 *
 *         i枚目のコインを使わない場合は、ここまで計算したj円を払う最適解T[i-1][j]となり、
 *         使った場合は、現在の金額jからC[i]を引いた金額を払う最適解に1枚足した値となる
 *         たとえば、3枚目のコイン(額面8)までを使って15円払う最適解は、min(T[2][15], T[3][15 - 8] + 1)より、
 *         2枚となる. これは3枚目のコインまでを使って7円払う最適解に1(枚)足したものである
 *
 * @note   コインの額面ごとに最適枚数を記録しておく必要はないので、j円払うときのコインの最小枚数は1次元配列の
 *         要素T[j]として、次のように求められる
 *
 *           T[j] = min(T[j], T[j - C[i]] + 1)
 *
 * @date   2016/05/04
 */



//********************************************************************************
// 必要なヘッダファイルのインクルード
//********************************************************************************

#include <iostream>
#include <vector>



//********************************************************************************
// 型シノニム
//********************************************************************************

using value_t = std::size_t;

using values_t = std::vector<value_t>;
using dptbl_t  = std::vector<std::size_t>;



//********************************************************************************
// 大域変数の定義
//********************************************************************************

static const std::size_t INFINITY  = (1 << 29);



//********************************************************************************
// 関数の定義
//********************************************************************************

/**
 * @brief  動的計画法によってコイン問題を解きます
 *
 * @param  const values_t& C  C[i]をi番目のコインの額面とする配列
 * @param  value_t         n  支払う金額n円
 * @return コインの最小枚数
 */
std::size_t coin_changing(const values_t& C, value_t n)
{
    dptbl_t T(n + 1, INFINITY); T[0] = 0;  // T[0..n+1]を新しい配列とする(ここでT[i]はi円払うコインの最小枚数)
    
    for (std::size_t i = 0, m = C.size(); i < m; i++) {
        for (value_t j = C[i]; j <= n; j++) {
            T[j] = std::min(T[j], T[j - C[i]] + 1);
        }
    }
    return T[n];
}



//********************************************************************************
// エントリポイント
//********************************************************************************

int main()
{
    using namespace std;
    
    int n, m;

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

    cout << coin_changing(C, n) << endl;

    return 0;
}

Measured memory_bytes: 3068
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
    

    class Program
    {

        static int[] a;
        static int[] b;


        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            b = new int[N];

            if(N % 2 != 0)
            {

                int center = N / 2;

                b[center] = a[0];

                int left = 1;
                int right = 1;

                for(int i = 1; i < N; i++)
                {

                    if(i % 2 == 0)
                    {
                        b[center - left] = a[i];
                        left++;
                    }
                    else
                    {
                        b[center + right] = a[i];
                        right++;
                    }

                }


            }
            else
            {
                int center = N / 2;

                b[center] = a[0];

                int left = 1;
                int right = 1;

                for (int i = 1; i < N; i++)
                {

                    if (i % 2 != 0)
                    {
                        b[center - left] = a[i];
                        left++;
                    }
                    else
                    {
                        b[center + right] = a[i];
                        right++;
                    }

                }

            }

            Console.WriteLine(String.Join(" ", b));

        }
    }
}


Measured memory_bytes: 50104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF = 1e18+18;
const ll MAX = 400005;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;

/*long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}*/


int main(){
    ll N;
    cin>>N;
    vector<ll> A(N), B(N);
    vector<pair<ll, ll>> C(N);
    rep(i, N){
        cin>>A[i]>>B[i];
        C.at(i).first=A[i]+B[i];
      	C.at(i).second=i;
    }
    ll Sum=0;
  	sort(C.begin(), C.end());
  	reverse(C.begin(), C.end());
    rep(i, N){
        if(i%2){
          	Sum-=B[C.at(i).second];
        }
      	else{
          	Sum+=A[C.at(i).second];
        }
    }
    cout<<Sum<<endl;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	ll n;cin >> n;
	ll top = 0, second = 0, id;
	REP(i, n){
		ll a;cin >> a;
		if(a > top){
			id = i;
			second = top;
			top = a;
		}
		else {
			second = max(second, a);
		}
	}

	REP(i, n){
		if(i == id)cout << second << endl;
		else cout << top << endl;
	}


	return 0;
}


Measured memory_bytes: 1664
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int po[]=new int[n];
        for(int i=0;i<n;i++){
            po[i]=sc.nextInt()-i-1;
        }
        Arrays.sort(po);
        
        int b=po[n/2];
        long ans=0;
        for(int i=0;i<n;i++)ans+=Math.abs(po[i]-b);
        System.out.println(ans);
    }
}


Measured memory_bytes: 67044
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#define MOD 1000000007
typedef long long ll;
using namespace std;

map<pair<int,int>,int> mp;

int main(){
  ll h,w;
  int n;
  cin>>h>>w>>n;
  ll ans[10]={};
  ll sum=0;

  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    for(int j=0;j<=2;j++){
      if(a-j<=0||a-j+2>h) continue;
      for(int k=0;k<=2;k++){
        if(b-k<=0||b-k+2>w) continue;
        mp[make_pair(a-j,b-k)]++;
      }
    }
  }

  for(auto z:mp){
    ans[z.second]++;
    sum++;
  }
  ans[0]=(w-2)*(h-2)-sum;
  for(int i=0;i<=9;i++) cout<<ans[i]<<endl;
  return 0;
}


Measured memory_bytes: 56448
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

const int bound = 100010;

struct edge{
	int to;
	int cost;
};

vector<vector<edge>> graph(bound);
int color[bound];

// color: 1 白，-1 黒, 0 まだ塗ってない
void dfs( int punkt, int farbe ){
	color[punkt] = farbe;
	for( auto nextp : graph[punkt] ){
		if( color[nextp.to] == 0 ){
			if( nextp.cost%2 == 0 ){
				dfs(nextp.to, farbe);
			} else {
				dfs(nextp.to, farbe*(-1));
			}
		}
	}
}


int main(){
	int n; cin >> n;
	for( int i = 0; i < n-1; ++i ){
		int a, b; int c; cin >> a >> b >> c;
		--a; --b;
		edge temp;
		temp.to = b; temp.cost = c; 
		graph[a].push_back(temp);
		temp.to = a;
		graph[b].push_back(temp);
	}
	dfs(0,1);
	for( int i = 0; i < n; ++i ){
		if( color[i] == -1 ) color[i] += 1;
		cout << color[i] << endl;
	}
	return 0;
}

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

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

  string s; cin >> s;
  int ans = 1<<30;
  for(int i = 0; i < 2; i++){
    int res = 0;
    for(int j = 0; j < s.size(); j++){
      int p = j;
      if(i == 1) p++;
      if(p%2 == 0){
        if(s[j] != '0') res++;
      }
      else {
        if(s[j] != '1') res++;
      }
    }
          ans = min(ans,res);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
  
static int INFTY = 1000000;
static int WHITE = 0;
static int GRAY = 1;
static int BLACK = 2;
int n;
int M[100][100];
  
void dijkstra(){
  int minv,i,v,u;
  int d[100],color[100];
  for(i = 0; i < n;i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }
  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = INFTY;
    u = -1;
    for(i = 0;i < n;i++)
 	  if(minv > d[i] && color[i] != BLACK){
 		u = i;
 		minv = d[i];
	  }
	if(u == -1) break;
    color[u] = BLACK;
    for(v = 0;v < n;v++)
	  if(color[v] != BLACK && M[u][v] != INFTY)
 		if(d[v] > d[u] + M[u][v]){
   		  d[v] = d[u] + M[u][v];
   		  color[v] = GRAY;
   		}
  }
  for(int i = 0;i < n;i++)
    printf("%d %d\n",i,(d[i] == INFTY ? -1 : d[i]));  
}  
    
int main(){
  int k,c,u,v,i,j;
  scanf("%d",&n);
  for(int i = 0;i < n;i++)
    for(int j = 0;j < n;j++)
	  M[i][j] = INFTY;
      
    for(i = 0;i < n;i++){
      scanf("%d%d",&u,&k);
      for(j = 0;j < k;j++){
          scanf("%d%d",&v,&c);
          M[u][v] = c;
      }
    } 
  dijkstra();
  return 0;
}


Measured memory_bytes: 2004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<char,int> pci;
typedef vector<pair<int,int>> vpii;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
#define sci(a) scanf("%d",&a)
#define scii(a,b) scanf("%d %d",&a,&b)
#define sciii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sciiii(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld %lld",&a,&b)
#define sclll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c
#define scllll(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define print(a) printf("%d ",a)
#define println(a) printf("%d\n",a)
#define ln printf("\n")
#define pb(a) push_back(a)
#define m_p(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define rep(i,s,n) for(int i=s;i<=n;i++)
#define rrep(i,e,s) for(int i=e;i>=s;i--)
#define repv(i,m) for(auto i = m.begin();i != m.end();i++)
#define FileIO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const long long INF = 4000000000000000000LL;
/************************************* Chocolate *************************************/
int main(){
    int n;
    sci(n);
    vector<double> coin(n+1);
    rep(i,1,n){
        cin >> coin[i];
    }
    vector<double> dp(n+1,0.0);
    dp[0] = 1.0;
    rep(i,1,n){
        rrep(j,n,1){
            dp[j] = dp[j]*(1-coin[i]) + dp[j-1]*coin[i];
        }
        dp[0] *= (1-coin[i]);
    }
    double ans = 0;
    rep(i,(n/2)+1,n){
        ans += dp[i];
    }
    cout.precision(10);
    cout << fixed << ans << endl;
}

Measured memory_bytes: 3936
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        // cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    vector<int> a(3);
    cin >> a;
    int k;
    cin >> k;
    sort(ALL(a));
    a[2] <<= k;
    int s = accumulate(ALL(a),0LL);
    cout << s << endl;
    return 0;
}



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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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

ll func(ll n){
    ll ans = 0;
    for(ll i = 1; i*i <= n; i++){
        for(ll j = 1; j*j <= n - i*i; j++){
            ll left = 1, right = n - i*i - j*j - i*j;
            while(right - left > 1){
                ll mid = (left + right) / 2;
                if(mid*mid + i*mid + j*mid > n - i*i - j*j - i*j) right = mid;
                else left = mid;
            }
            ll t = i*i + j*j + left*left + i*j + j*left + left*i;
            if(n == t){
                ans++;
            }
        }
    }
    return ans;
}
int main(){

    ll n;
    cin >> n;

    for(int i = 1; i <= n; i++){
        cout << func(i) << endl;
    }
    return 0;
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define loop0(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define pb push_back
const int MAXN = 1e5+7;
ll r[MAXN], g[MAXN],o[MAXN];
int x,y,a,b,c;
int main(){
	fastio;
	cin>>x>>y>>a>>b>>c;
	loop0(i,a)cin>>r[i];
	sort(r, r+a);
	loop0(i,b)cin>>g[i];
	sort(g, g+b);
	int pr = a-x;
	ll sr=0;
	for(int i=pr; i<a; i++)sr+=r[i];
	int pg = b-y;
	ll sg = 0;
	for(int i=pg; i<b; i++)sg+=g[i];
	loop0(i,c)cin>>o[i];
	sort(o, o+c);
	for(int i=c-1; i>=0; i--){
		if(pr==a && pg==b)break;
		
		if(pr == a){
			if(o[i] > g[pg]){sg+=o[i]-g[pg]; pg++;}
		}else if(pg == b){
			if(o[i] > r[pr]){sr+=o[i]-r[pr]; pr++;}
		}else{
			if(g[pg] < r[pr]){
				if(o[i] > g[pg]){sg+=o[i]-g[pg]; pg++;}
			}else{
				if(o[i] > r[pr]){sr+=o[i]-r[pr]; pr++;}
			}
		}
	}
	cout<<sr+sg<<endl;
}


Measured memory_bytes: 2688
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] P = new int[N];
		
		int count = 0;
		for(int i=0;i<N;i++) {
			P[i] = sc.nextInt();
			if(P[i] != i+1) {
				count++;
			}
		}
		
		if(count<=2) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
		
		sc.close();	
	}
}


Measured memory_bytes: 22992
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
const ll MOD = 1000000007;
const ll INF = 10e12;
using namespace std;

ll f1(ll tate, ll yoko) //並行分割
{
    if (tate < 3 || yoko < 3)
        return INF;
    else
    {
        ll l1 = tate / 3, l2 = tate / 3, l3 = tate / 3;
        if (tate % 3 == 1)
            l1++;
        else if (tate % 3 == 2)
            l1++, l2++;
        return yoko * abs(l1 - l3);
    }
}
ll f2(ll tate, ll yoko) //t字分割
{
    ll res = INF;
    if (tate % 2 == 1)
        swap(tate, yoko);
    for (ll i = 1; i < yoko - 1; ++i)
    {
        ll s1, s2;
        s1 = tate * i;
        s2 = (tate / 2) * (yoko - i);
        res = min(res, abs(s1 - s2));
    }
    return res;
}
ll f3(ll tate, ll yoko) //正方形分割
{
    ll res = INF;
    for (ll i = 1; i < min(yoko, tate); ++i)
    {
        ll s1, s2, s3;
        s1 = i * i;
        s2 = i * (yoko - i);
        s3 = yoko * (tate - i);
        ll mx = max(s1, max(s2, s3));
        ll mn = min(s1, min(s2, s3));
        res = min(res, mx - mn);
    }
    return res;
}
int main(void)
{
    ll h, w;
    cin >> h >> w;
    ll ans = INF;
    ans = min(ans, min(f1(h, w), f1(w, h)));
    if (h % 2 == 0 || w % 2 == 0)
        ans = min(ans, min(f2(h, w), f2(w, h)));
    ans = min(ans, f3(h, w));
    cout << ans << endl;
}


Measured memory_bytes: 3636
//do not think about past and stay in this moment
//organize and work - Abhinav IIITA
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define int long long
#define ld long double
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end() 
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mod;
int Arr[100005];
void seive(){
		Arr[0]=Arr[1]=1;
		for(int i=2;i<100005;++i){
			if(Arr[i]==0)
			for(int j=2*i;j<100005;j+=i)
			Arr[j]=1;
		}
}

bool isprime(int a){
	if(a==2)
	return true;
	if(a%2==0)
	return false;
	for(int i=3;i*i<=a;i+=2)
	if(a%i==0)
	return false;
	return true;
}

void merge(int arr[],int brr[], int l, int m, int r) 
			{ 
			  int i, j, k; 
			  int n1 = m - l + 1; 
			  int n2 = r - m; 
			  int L[n1], R[n2]; 
			  int l1[n1] ,r1[n2];
			  for (i = 0; i < n1; i++) 
				{L[i] = arr[l + i];l1[i]=brr[l+i];} 
			  for (j = 0; j < n2; j++) 
				{R[j] = arr[m + 1+ j];r1[j]=brr[m+1+j];} 
			  i = 0;  
			  j = 0; 
			  k = l;  
			  while (i < n1 && j < n2) 
			  { 
				if (L[i] <= R[j]) 
				{ 
				  arr[k] = L[i];
				  brr[k]=l1[i]; 
				  i++; 
				} 
				else
				{ 
				  arr[k] = R[j];
				  brr[k]=r1[j]; 
				  j++; 
				} 
				k++; 
			  } 
			  while (i < n1) 
			  { 
				arr[k] = L[i]; 
				brr[k]=l1[i];
				i++; 
				k++; 
			  } 
			  while (j < n2) 
			  { 
				arr[k] = R[j];
				brr[k]=r1[j]; 
				j++; 
				k++; 
			  } 
			} 
			void mergeSort(int arr[],int brr[], int l, int r) 
			{ 
			  if (l < r) 
			  { 
				int m = l+(r-l)/2; 
				mergeSort(arr,brr, l, m); 
				mergeSort(arr,brr, m+1, r); 
				merge(arr,brr, l, m, r); 
			  } 
			}
			
// -----------------------------------------------------------------------



int fre[26];
int ac[100000],wa[100000];
void stt(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;++i){
		int p; cin>>p; p--;
		string sta; cin>>sta;
		if(sta=="AC"){
			ac[p]=1;
		}
		else{
			if(ac[p]==0){
				wa[p]++;
			}
		}
	}
	int a=0,b=0;
	for(int i=0;i<n;++i){
		if(ac[i]==1){
			a++;
			b+=wa[i];
		}
	}
	cout<<a<<" "<<b;
}
void spp(){
	int n,k;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;++i)
	cin>>arr[i];
	sort(arr,arr+n);
	bool choose[n];
	for(int i=0;i<n;++i)
	choose[i]=false;
	int ret=0;
	for(int i=0;i<n;++i){
		for(int j=i+1;j<n;++j){
			if(arr[j]>arr[i] && !choose[j]){
				ret++;
				choose[j]=true;
				break;
			}
		}
	}
	cout<<ret;
}

void solve(){	
	int n; cin>>n;
	int k; cin>>k;
	string s; cin>>s;
	for(int i=0;i<sz(s);++i)
	fre[s[i]-'A']++;
	sort(fre,fre+26);	
	int ans=0;
	for(int i=25;i>=0;--i){
		if(k>=fre[i]){
			ans+=fre[i]*fre[i];
			k-=fre[i];	
		}
		else{
			ans+=k*k;
			k=0;
			break;
		}
	}
	cout<<ans;
}

// -----------------------------------------------------------------------


int32_t main()
{
	mod=1e+7;
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	stt();
	return 0;
}


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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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 (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

int main(){
   double T , X;
   cin >> T >> X;
   printf("%.10f\n", T / X);
}


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

int main(){
    int N,X[100],sum[100]={0}, mini=0, maxi=0;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> X[i];
    }

    for(int x=0; x<100; x++){
        for(int j=0; j<N; j++){
            sum[x] += (x-X[j]) * (x-X[j]);
        }
    }

    for(int x=1; x<100; x++){
        if(sum[x]<sum[x-1]){
            mini = sum[x];
        }
    }

    cout << mini << endl;
    return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative

hit :: String -> String -> Int
hit [] _ = 0
hit _ [] = 0
hit (r:rs) (a:as) =
  if r == a
    then 1 + hit rs as
  else hit rs as

blow :: String -> String -> Int -> Int
blow [] _ _ = 0
blow _ [] _ = 0
blow rs as n =
  if n >= 4
    then 0
    else
      let r = rs !! n
      in
        if r /= as !! n && r `elem` as
          then 1 + blow rs as (n+1)
          else blow rs as (n+1)

solver :: String -> String -> String
solver r a = show (hit r a) ++ " " ++ show (blow r a 0)

main :: IO()
main = do
  (r:a:_) <- words <$> getLine
  unless (r == "0" && a == "0") $ do
    putStrLn $ solver r a
    main

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

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

    int d[n];
    for (int i = 0; i < n; i++) cin >> d[i];

    //sort(a,a+n);
    sort(d,d+n, greater<int>());

    int counter=1;
    for (int i = 0; i < n-1; i++){
        if(d[i]-d[i+1]!=0){
            counter++;
        }
    }

    std::cout << counter << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N,X,i,D=0;
  scanf("%d %d" ,&N ,&X);
  
  int L[N];
  for(i = 0; i < N; i++) scanf("%d" ,&L[i]);
  i = 0;
  while(X >= D){
    D = L[i] + D;
    i++;
  }
  printf("%d\n" ,i);
  return 0;
  
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  int A[M];
  for(int i=0;i<M;i++){
    cin >> A[i];
    N-=A[i];
  }
  if(N<=-1){
    cout << "-1";
  }else{
    cout << N;
  }
}


Measured memory_bytes: 3624
import scala.io.Source

object Main extends App {
  val src = Source.stdin.getLines

  val turns: Int = src.next.toInt

  def versus(n: Int, acc: List[Int]): List[Int] = {
    if (n <= 0) acc
    else { val Array(taro, hana) = src.next.split(" ")
           if (taro > hana) versus(n - 1, acc.updated(0, acc(0) + 3))
           else if (taro < hana) versus(n - 1, acc.updated(1, acc(1) + 3))
           else versus(n - 1, acc.map(x => x + 1))
    }
  }

  val result: List[Int] = versus(turns, List(0, 0))
  println(result.mkString(" "))
}

Measured memory_bytes: 45508
N=input()
K=int(input())

dpsm=[[0]*(K+1) for _ in range(len(N))] #dpsm[i][k]
dp=[[0]*(K+1) for _ in range(len(N))]

dpsm[0][0]=1
dpsm[0][1]=int(N[0])-1
dp[0][1]=1

for i in range(1,len(N)):
    for k in range(K-1,-1,-1):
        dpsm[i][k+1]+=dpsm[i-1][k]*9

    
    if N[i]=="0":
        for k in range(K,-1,-1):
            dpsm[i][k]+=dpsm[i-1][k]
            dp[i][k]+=dp[i-1][k]
    else:
        for k in range(K-1,-1,-1):
            dpsm[i][k+1]+=dp[i-1][k]*(int(N[i])-1)
            dp[i][k+1]+=dp[i-1][k]

        for k in range(K,-1,-1):
            dpsm[i][k]+=dpsm[i-1][k]
            dpsm[i][k]+=dp[i-1][k]
          
print(dp[-1][-1]+dpsm[-1][-1])


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define llong long long
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

void solve()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  int a=0,b=0;

  for(int i=0; i<n; i++)
  {
    if (s[i]=='#') {
      a++;
    }
    else if (a>0&&s[i]=='.') {
      b++;
      a--;
    }
  }

  cout << b << endl;
}

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


Measured memory_bytes: 640
def judge_type(x):
    if x % 4 == 0:
        return 4
    elif x % 2 == 0:
        return 2
    else:
        return 1


def solve(): # 069C - 4-adjacent
    N = int(input())
    a = list(map(int, input().split(" ")))
    cnt_odd = 0
    cnt_2 = 0
    cnt_4 = 0
    flag_2 = False

    for i in a:
        if judge_type(i) == 1:
            cnt_odd += 1
        elif judge_type(i) == 2:
            cnt_2 += 1
            flag_2 = True
        elif judge_type(i) == 4:
            cnt_4 += 1

    if flag_2:
        if cnt_odd <= cnt_4:
            print("Yes")
        else:
            print("No")
    else:
        if cnt_odd <= cnt_4 + 1:
            print("Yes")
        else:
            print("No")


solve()

Measured memory_bytes: 14252
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

ll X[200000];
ll Y[200000];
int main() {
	int N; cin >> N;

	rep(i, 0, N) {
		ll a; cin >> a;
		X[i] = a;
		Y[i] = a;
	}

	sort(X, X + N);

	ll ma, mb;
	ma = X[N / 2 - 1];
	mb = X[N / 2];

	rep(i, 0, N) {
		if (Y[i] > ma) cout << ma << endl;
		else if (Y[i] == ma) cout << mb << endl;
		else if (Y[i] < mb) cout << mb << endl;
		else if (Y[i] == mb) cout << ma << endl;
	}
	return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

//#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


class UnionFind{

private:
    vector<int> rank,p;

    void makeSet(int x){
      p[x] = x;
      rank[x] = 0;
    }

  public:
      UnionFind(){};
      UnionFind(int size){
        rank.resize(size,0);
        p.resize(size,0);
        for(int i = 0; i < size; i++){
          makeSet(i);
        }
      }

    bool same(int x, int y){
      return  find(x) == find(y);
    }

    void unite(int x, int y){
      link(find(x), find(y));
    }

    int find(int x){
      if(x != p[x]) p[x] = find(p[x]);
      return p[x];
    }

private:
    void link(int x, int y){
      if(rank[x] > rank[y]){
        p[y] = x;
      }else{
        p[x] = y;
        if(rank[x] == rank[y]) rank[y]++;
      }
    }

};

struct edge{
    int from, to, cost;

    bool operator<(const edge& e) const {
        return cost < e.cost;
    }

};

int kruskal(vector<edge> es, int v){

    sort(es.begin(), es.end());

     UnionFind uf(v);

     int ret = 0;

     for(int i = 0 ; i < es.size() ; i++){

         edge e = es[i];

         if(!uf.same(e.from, e.to)){
             uf.unite(e.from, e.to);
             ret += e.cost;
         }

     }

     return ret;

}


signed main(void) {
    int n,m;
    while(cin >> n,n){
        cin >> m;
        vector<edge> g;
        rep(i,m){
            edge e;
            scanf("%d,%d,%d", &e.from, &e.to, &e.cost);
            e.cost /= 100;
            e.cost--;
            g.push_back(e);
        }
        cout << kruskal(g,n) << endl;
    }
}



Measured memory_bytes: 3352
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;
ll mod = 1e9 + 7;
int main() {
    int n;
    ll k;
    cin >> n >> k;
    vi a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    ll p = 0;
    for(int i= 0; i <n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(a[i] > a[j]) p++;
        }
    }
    ll q = 0;
    for (int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(a[i] > a[j]) q++;
        }
    }
    ans += k * p % mod;
    ans += (k * (k - 1) / 2) % mod * q;
    ans %= mod;
    cout << ans << endl;
}

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

const int INF = 1e9;

int main(){
  int n, A, B, C;
  cin >> n >> A >> B >> C;
  vector<int> l(n);
  rep(i,n) cin >> l[i];

  auto dfs = [&](auto&& dfs, int depth, int a, int b, int c)->int{
    if (depth == n) {
      if (!a || !b || !c) return INF;
      else return abs(a - A) + abs(b - B) + abs(c - C);
    }
    int res = dfs(dfs,depth+1,a,b,c);
    res = min(res, dfs(dfs,depth + 1, a + l[depth], b, c) + (a ? 10 : 0));
    res = min(res, dfs(dfs,depth + 1, a, b + l[depth], c) + (b ? 10 : 0));
    res = min(res, dfs(dfs,depth + 1, a, b, c + l[depth]) + (c ? 10 : 0));
    return res;
  };

  cout << dfs(dfs,0,0,0,0) << endl;
  return 0;
} 

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

int main(){
	int a[4];
	int b[4];
	while(cin >> a[0]){
		for(int i=1;i<4;i++){
			cin >> a[i];
		}
		for(int i=0;i<4;i++){
			cin >> b[i];
		}

		int count[2]={0};
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				if(i==j && a[i] == b[j]){
					count[0]++;
				}
				if(i!=j && a[i] == b[j]){
					count[1]++;
				}
			}
		}
		cout << count[0] << " " << count[1] << endl;
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
typedef vector<vector<int> > VVI;
const int INF = 1e9;

string S;

int expr(int &pos);

// 数
int number(int &pos)
{
	int res=0;
	while (isdigit(S[pos])) {
		res *= 10;
		res += S[pos]-'0';
		pos++;
	}
	return res;
}

// ()か数
int factor(int &pos)
{
	int res=0;
	
	if (S[pos] == '(') {
		pos++; // skip '('
		res = expr(pos);
		pos++; // skip ')'
	} else {
		res = number(pos);
	}
	
	return res;
}

// 乗算
int term(int &pos)
{
	int res = factor(pos);
	while (1) {
		if (S[pos] == '*') {
			pos++; // skip '*'
			res *= factor(pos);
		} else if (S[pos] == '/') {
			pos++; // skip '/'
			res /= factor(pos);
		} else {
			break;
		}
	}
	return res;
}

// 四則演算
int expr(int &pos)
{
	int res = term(pos);
	
	while (1) {
		if (S[pos] == '+') {
			pos++; // skip '+'
			res += term(pos);
		} else if (S[pos] == '-') {
			pos++; // skip'-'
			res -= term(pos);
		} else {
			break;
		}
	}
	return res;
}

int main()
{
	int N;
	cin>>N;
	cin.ignore();
	rep(i, N) {
		getline(cin, S);
		int pos = 0;
		cout << expr(pos) << endl;
	}
}

Measured memory_bytes: 1208
s = input()
n = len(s)
k = 0
l = 0
for i in range(n):
  if (i+1) % 2 == 1:
    if s[i] == "1":
      k = k + 1
    else:
      l = l + 1 
  else:
    if s[i] == "0":
      k = k + 1
    else:
      l = l + 1
print(min(k,l))

Measured memory_bytes: 3188
using System;
using System.IO;

class MainClass
{
    static void Main()
    {
        //Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

        string firstLine = Console.ReadLine();
        int number = int.Parse(firstLine);

        string line;
        line = Console.ReadLine();

        string[] tokens = line.Split(' ');
        int[] ConvertedInt = new int[number];

        for (int i = 0; i < number; i++)
        {
            ConvertedInt[i] = int.Parse(tokens[i]);
        }
        //Console.Out.Flush();
        insertion(ConvertedInt, number);
    }

    static private int[] insertion(int[] sortinglist, int b)
    {
        for (int i = 0; i < b; i++)
        {
            var value = sortinglist[i];
            var j = i - 1;

            while (j >= 0 && sortinglist[j] > value)
            {
                sortinglist[j + 1] = sortinglist[j];
                j--;
                sortinglist[j + 1] = value;

            }
            for (int k = 0; k < b; k++)
            {
                Console.Write(sortinglist[k]);
                if (k != (b - 1))
                {

                    Console.Write(' ');
                }
            }
            Console.WriteLine("");

        }

        return sortinglist;
    }
}


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

ll N,K;
vector<ll> t;

bool solve(){
  if( t.back() < K )return false;
  
  ll x=t[0];
  for(int i=0;i<N;i++)x=__gcd(x,t[i]);
  if(x==1)return true;

  if(K%x>0)return false;
  
  K/=x;
  for(int i=0;i<N;i++)t[i]/=x;
  return solve();
}

int main(){
  cin>>N>>K;
  t.resize(N);
  for(int i=0;i<N;i++){
    cin>>t[i];
  }
  sort(t.begin(),t.end());
  if( solve() ){
    cout<<"POSSIBLE"<<endl;
  }else{
    cout<<"IMPOSSIBLE"<<endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int MAXN = 1e2+5,MAXM = 2e5+5,MOD = 20130427,INF = 0x3f3f3f3f,N=100050;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const db eps = 1e-9;
#define lson o<<1,l,m
#define rson o<<1|1,m+1,r
#define mid l + ((r-l)>>1)
#define rep(i,a,b) for(register int i=(a);i<=(b);i++)
#define vii vector<pair<int,int>>
#define vi vector<int>
using namespace std;

int n;
vector<int> b,ans;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    //freopen("../A.in","r",stdin);
    //freopen("../A.out","w",stdout);
    cin>>n;
    b.resize(n);
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int j=1;j<=n;j++){
        bool flag=false;
        for(int i=b.size()-1;i>=0;i--){
            if(b[i]==i+1){
                ans.push_back(b[i]);
                b.erase(b.begin()+i);
                flag=true;
                break;
            }
        }
        if(!flag){
            cout<<"-1\n";
            return 0;
        }
    }
    for(int i=n-1;~i;i--)cout<<ans[i]<<'\n';
    return 0;
}

Measured memory_bytes: 256
<?php

$N = trim(fgets(STDIN));

for ($i = 0; $i < $N; $i++) {
    $scores[] = trim(fgets(STDIN));
}

echo get_max_score($scores) . PHP_EOL;


function get_max_score($scores) {

    sort($scores);
    $sum = array_sum($scores);

    if ($sum % 10 != 0) return $sum;

    foreach($scores as $score) {
        if (($sum - $score) % 10 != 0) {
            return ($sum - $score);
        }
    }

    return 0;
}


Measured memory_bytes: 3956
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional;
import std.algorithm, std.container;

void scanValues(TList...)(ref TList list)
{
    auto lit = readln.splitter;
    foreach(ref e; list)
    {
        e = lit.fornt.to!(typeof(e));
        lit.popFront;
    }
}
T[] scanArray(T = long)()
{
    return readln.split.to!(long[]);
}
void scanStructs(T)(ref T[] t, size_t n)
{
    t.length = n;
    foreach(ref e; t)
    {
        auto line = readln.split;
        foreach(i, ref v; e.tupleof)
        {
            v = line[i].to!(typeof(v));
        }
    }
}
T scanElem(T = long)()
{
    string res;
    int c = ' ';
    while (isWhite(c) && c!=-1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c!=-1)
    {
        res ~= cast(char)c;
        c = getchar;
    }
    return res.strip.to!T;
}
template fold(fun...)
if (fun.length >= 1)
{
    auto fold(R, S...)(R r, S seed)
    {
        static if (S.length < 2)
        {
            return reduce!fun(seed, r);
        }
        else
        {
            import std.typecons : tuple;
            return reduce!fun(tuple(seed), r);
        }
    }
}

struct Factor{
    long n;
    long c;
}
Factor[] factors(long n)
{
    Factor[] res;
    for(long i = 2; i^^2 <= n;i++)
    {
        if(n%i!=0)
            continue;

        int c;
        while(n%i==0)
        {
            n = n/i;
            c++;
        }
        res ~= Factor(i, c);
    }
    if(n!=1)
        res ~= Factor(n, 1);

    return res;
}
bool isPrime(long n)
{
    if(n<=1) return false;
    if(n==2) return true;
    if(n%2==0) return false;
    for(long i = 3; i^^2 <= n;i+=2)
        if(n%i==0) return false;
    return true;
}

void main()
{
    const N = scanElem();
    if(N==1){
        writeln(0);
        return;
    }
    Factor[] list;
    foreach(n; 2..N+1)
    {
        list ~= factors(n);
    }
    list = list.sort!"a.n<b.n"
     .chunkBy!"a.n==b.n"
     .map!(fold!((a,b)=>Factor(a.n, a.c+b.c)))
     .array;
    long[][] dp = new long[][](list.length, 76);
    foreach(n; 0..list[0].c+1)
    {
        if(75 < n+1) continue;
        dp[0][n+1] = 1;
    }
    foreach(i; 1..list.length)
    {
        dp[i] = dp[i-1].dup;
        auto e = list[i];
        foreach(j; 1..76)
        {
            foreach(c; 1..e.c+1)
            {
                auto x = j*(c+1);
                if(75 < x) continue;
                dp[i][x] += dp[i-1][j];
            }
        }
    }
    writeln(dp[list.length-1][75]);
}


Measured memory_bytes: 380
#include <stdio.h>

int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
    return n;
}

typedef struct UnionFind {
    int parent[100000];
    int rank[100000];
    int size[100000];
} UnionFind;
void uf_init(UnionFind *UF) {
    const int N = 100000;
    for(int i = 0; i < N; ++i) {
        UF->parent[i] = i;
        UF->rank[i] = 0;
        UF->size[i] = 1;
    }
}
#define uf_same(UF, x, y) (uf_find((UF), (x)) == uf_find((UF), (y)))
int uf_find(UnionFind *UF, int x) {
    if(x == UF->parent[x]) return x;
    else return UF->parent[x] = uf_find(UF, UF->parent[x]);
}
void uf_unite(UnionFind *UF, int x, int y) {
    x = uf_find(UF, x), y = uf_find(UF, y);
    if(x == y) return;
    if(UF->rank[x] < UF->rank[y]) UF->parent[x] = y;
    else {
        UF->parent[y] = x;
        if(UF->rank[x] == UF->rank[y]) UF->rank[x]++;
        int tmp = x, x = y, y = tmp;
    }
    UF->size[y] += UF->size[x];
    UF->size[x] = 0;
}

int main(int argc, char **argv) {
    int n = get_uint();
    int m = get_uint();
    UnionFind UF;
    uf_init(&UF);
    for(int i = 0; i < m; ++i) {
        int s = get_uint();
        int t = get_uint();
        uf_unite(&UF, s, t);
    }
    int q = get_uint();
    for(int i = 0; i < q; ++i) {
        int s = get_uint();
        int t = get_uint();
        puts(uf_same(&UF, s, t) ? "yes" : "no");
    }
    return 0;
}



Measured memory_bytes: 2832
function pay(x,y,z)
    return math.abs(x-a)+math.abs(y-b)+math.abs(z-c)
end

function dfs(cur,a,b,c)
    if cur == #bamboos+1 then
        return math.min(a,b,c) > 0 and pay(a,b,c) - 30 or math.huge
    end
    local vcur = bamboos[cur]
    local toa = 10 + dfs(cur+1, a+vcur, b, c)
    local tob = 10 + dfs(cur+1, a, b+vcur, c)
    local toc = 10 + dfs(cur+1, a, b, c+vcur)
    local skip = dfs(cur+1, a, b, c)
    return math.min(toa, tob, toc, skip)
end
n, a, b, c = io.read("n", "n", "n", "n")
bamboos = {}
for i=1,n do
    bamboos[i] = io.read("n")
end
print(dfs(1,0,0,0))

Measured memory_bytes: 1136