akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  ll N;
  cin>>N;
  vector <ll> a;
  for(int i = 1;i<=sqrt(N);i++){
    if(N%i == 0){
      if(N != i*i){
        a.push_back(i+(N/i)-2);
      }
      else{
        a.push_back(i+i-2);
      }
    }
  }
  sort(a.begin(),a.end());
  cout << a.at(0) << endl;
  return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(n,m):
        a = [LF() for _ in range(n)]
        b = []
        mx = 1 << n
        for i in range(mx):
            t = []
            for j in range(n):
                if i & (1<<j):
                    t.append(j)
            b.append(t)

        nmx = n * mx
        ca = [1] * nmx
        cn = [c<<n for c in range(n)]
        ci = [1<<c for c in range(n)]
        for k in range(1,m+1):
            ka = [a[c][-k] for c in range(n)]
            na = [0] * nmx
            re = [0] * mx
            for x in range(1,mx):
                for c in b[x]:
                    y = cn[c] + x
                    na[y] = ka[c] * ca[y] + (1 - ka[c]) * re[x - ci[c]]
                    if re[x] < na[y]:
                        re[x] = na[y]
            ca = na

        return '{:0.10f}'.format(max(ca))

    while 1:
        n,m = LI()
        if n == 0:
            break
        rr.append(f(n,m))
        break

    return '\n'.join(map(str, rr))


print(main())



Measured memory_bytes: 61760
import sys
sys.setrecursionlimit(400000)
n,q=map(int,input().split())
ans=[0]*(n+1) #答え
score=[0]*(n+1) #xの総和
g=[[] for _ in range(n+1)] #グラフ
for i in range(n-1):
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)
for j in range(q):
    p,x=map(int,input().split())
    score[p]+=x

visited=[0]*(n+1)
def dfs(v):
    visited[v]+=1
    global ans
    ans[v]+=score[v]
    for i in range(len(g[v])):
        if visited[g[v][i]]==0:
            ans[g[v][i]]+=ans[v]
            dfs(g[v][i])
dfs(1)
print(" ".join(map(str, ans[1:])))


Measured memory_bytes: 230640
#include<stdio.h>

int main(void)
{
  int n;
  scanf("%d",&n);

  int l[n],msl=0,all=0,i;
  for(i=0;i<n;i++){
    scanf("%d",&l[i]);
    if(msl<l[i])
      msl=l[i];
    all += l[i];
  }

  all -= msl;
  
  if(all>msl)
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      if(n%2==0){
        System.out.println(n/2);
      }
      else{
        System.out.println(n/2+1);
      }
    }
}

Measured memory_bytes: 35744
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    vp ba(m);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        b--; a--;
        ba[i] = P(b, a);
    }
    sort(all(ba));
    int now = -1;
    int cnt = 0;
    rep(i, m) {
        int a = ba[i].se, b = ba[i].fi;
        if (a <= now && now < b) continue;
        now = b - 1;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
	map<int, int>ans;
	int now = 2;
	while (now * now <= x) {
		if (x % now == 0) {
			x /= now;
			ans[now]++;
		}
		else now++;
	}
	if (x != 1) ans[x]++;
	return ans;
}

const int MAX = 510000;

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 Com(int n, int k) {
	int x=1, y=1;
	rep(i, k) {
		y *= i + 1;
		y %= MOD;
	}
	for (int i = n - k + 1; i <= n; i++) {
		x *= i;
		x %= MOD;
	}
	return x * modinv(y, MOD) % MOD;
}

signed main() {
	int n, k;
	cin >> n >> k;
	double p[200005];
	rep(i, n) cin >> p[i];
	double sum[200005];
	sum[0] = 0;
	rep(i, n) sum[i + 1] = sum[i] + (1 + p[i]) / 2;
	double ma = 0;
	for (int i = k; i <= n; i++) {
		ma = max(ma, sum[i] - sum[i - k]);
	}
	printf("%.12lf\n", ma);


	return 0;
}

Measured memory_bytes: 3328
import sys
readline = sys.stdin.readline

N,A,B = map(int,readline().split())
H = [int(readline()) for i in range(N)]

# AをA - Bと読み替え、一回の攻撃で全体にBダメージと1体にAダメージと考える
# X回で達成できるかの二分探索

A -= B

ng = 0
ok = 10 ** 9
def isOk(x):
  # 各H_iを倒すのに必要な攻撃Aの回数をカウントする
  cnt = 0
  for i in range(len(H)):
    h = H[i] - x * B
    if h > 0:
      cnt += (h + A - 1) // A
  return cnt <= x
  
while abs(ok - ng)>1:
  mid = abs(ok + ng) // 2
  if isOk(mid):
    ok = mid
  else:
    ng = mid

print(ok)

Measured memory_bytes: 7076
def main():
    N,M,X = list(map(int,input().split()))
    A = [0]
    A.extend(list(map(int,input().split())))
    for i in range(100):
        A.append(0)    
    Map = [0]
    for i in range(1,N+1):
        if i in A:
            Map.append(1)
        else:
            Map.append(0)
    right = sum(Map[X+1:])
    left = sum(Map[:X])
    #print(left,right)
    if right < left:
        print(right)
    else:
        print(left)
if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
a, b, c = input()
a = int(a)
b = int(b)
c = int(c)
i = 0 # カウンタの初期化
if a == 1:
    i += 1
    if b == 1:
        i += 1
        if c == 1:
            i += 1
            print(i)
        else:
            print(i)
    else:
        if c == 1:
            i += 1
            print(i)
        else:
            print(i)
else:
    if b == 1:
        i += 1
        if c == 1:
            i += 1
            print(i)
        else:
            print(i)
    else:
        if c == 1:
            i += 1
            print(i)
        else:
            print(i)


Measured memory_bytes: 3064
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

ll rep_power(ll m, ll n){
    if(n==1) return m % MOD;
    if(n%2==1) return m * rep_power(m,n-1) % MOD;
    return rep_power(m,n/2)*rep_power(m,n/2) % MOD;
}


int main(void) {

    ll m,n;cin>>m>>n;
    cout<< rep_power(m,n)<<endl;


}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define N 200005
#define LL long long
#define ULL unsigned LL
using namespace std;
LL l,r,a[26],b[26],f[95][27],F[95];
int n; char A[N];
ULL H[N],S[N];
ULL HA(int l,int r){ return H[r]-H[l-1]*S[r-l+1];}
void calc(LL r,int v,LL *a)
{
	int i,j;
	if(n%v==0){
		for(i=1;i<=n&&i<=r;i++) a[A[i]-'a']++;
		if(r>=n){
			r-=n;
			for(i=1;i<=v;i++)
				a[A[i]-'a']+=r/v+(r%v>=i);
		  }
	  }
	else{
		memset(f,0,sizeof(f));
		for(i=1;i<=v;i++) f[0][A[i]-'a']++;
		for(i=1;i<=n;i++) f[1][A[i]-'a']++;
		F[0]=v,F[1]=n;
		for(i=2;i<=90;i++){
			F[i]=F[i-1]+F[i-2];
			for(j=0;j<26;j++)
				f[i][j]=f[i-1][j]+f[i-2][j];
			if(F[i]>r) break;
		  }
		while(i){
			if(r>=F[i]){
				for(j=0;j<26;j++) a[j]+=f[i][j];
				r-=F[i];
			  }
			i--;
		  }
		for(i=1;i<=r;i++) a[A[i]-'a']++;
	  }
}
int main()
{
	int i;
	scanf("%s",A+1);
	n=strlen(A+1)/2;
	cin>>l>>r;
	S[0]=1;
	for(i=1;i<=n;i++)
		H[i]=H[i-1]*173+A[i],S[i]=S[i-1]*173;
	for(i=1;i<=n;i++)
		if(HA(i+1,n)==HA(1,n-i))
			break;
	calc(r,i,a);
	calc(l-1,i,b);
	for(i=0;i<26;i++)
		printf("%lld ",a[i]-b[i]);
	return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int fn(string S){
	int sum=0;
	REP(i,(int)S.length()) sum+=(S[i]-'0');
	return sum;
}

int main(void){
	int max=0;
	string N;
	cin>>N;

	chmax(max,fn(N));

	N[0]-=1;
	FOR(i,1,(int)N.length()) N[i]='9';
	chmax(max,fn(N));

	print(max);	
	return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,i,j=0;
    scanf("%d %d %d",&a,&b,&c);
    for(i=a;i<b+1;i++)
    {
        if(c%i==0)
        {
            j++;
        }
    }
    printf("%d\n",j);
    return 0;
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
char c[3][30];
int main()
{
	int n,m;
	scanf("%s %s",&c[1],c[2]);
	scanf("%d %d\n",&n,&m);
	scanf("%s",&c[3]);
	if(strcmp(c[1],c[3])==0)printf("%d %d",n-1,m);
	else    printf("%d %d",n,m-1);
	
} 

Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    std::string S;
    std::cin >> S;

    std::vector<std::string> cands = { "maerd", "remaerd", "esare", "resare" };

    std::reverse(S.begin(), S.end());

    size_t index = 0;
    while (index < S.size()) {
        bool find = false;
        for (auto c: cands) {
            if (boost::algorithm::starts_with(S.substr(index), c)) {
                index += c.size();
                find = true;
                break;
            }
        }
        if (!find) {
            std::cout << "NO" << std::endl;
            return 0;
        }
    }
    std::cout << "YES" << std::endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
set<ll> divisors;
void find_div(ll m) {
    ll s = sqrt(m);
    for(ll i = 1; i <= s; i++) {
        if(m%i == 0) {
            if(m/i == i) divisors.insert(i);
            else {
                divisors.insert(i);
                divisors.insert(m/i);
            }
        }
    }
    divisors.insert(m);
}

bool isPrime(ll n) {
    if(n <= 1) return false;
    if(n == 2) return true;
    int s = sqrt(n);
    for(int i = 2; i <= s; i++) {
        if(n % i == 0) return false;
    }
    return true;
}

int main() {
    ll N; cin >> N;
    if(isPrime(N)) {
        cout << N-1;
    } else {
        ll ans = 1e13;
        find_div(N);
        for(auto i : divisors) {
            ll aux = N / i;
            ans = min(ans, (aux-1)+(i-1));
        }
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vdo=vector<double>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vvdo=vector<vector<double>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using pqin=priority_queue<int>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
int main()
{
    int n;
    cin>>n;
    map<int,int> s;
    bool can=true;
    rep(i,n){
        int a;
        cin>>a;
        if(s.count(a)){
            can=false;
            break;
        }
        s[a]++;
    }
    if(can)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

template<class T, class... Args>
auto create(size_t n, Args&&... args) {
	if constexpr(sizeof...(args) == 1)
		return vector<T>(n, args...);
	else
		return vector(n, create<T>(args...));
}

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef OJ
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define sz(x) ((int)x.size())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const char en = '\n';
const int MOD = 1e9+7;
const int MAXN = 0;
const int INF = 1e9+1;

int solve() {
    int n; cin >> n;
    vector<LL> a(n);
    vector<LL> pref(n);
    fori(i,n) {
        cin >> a[i];
        pref[i] = a[i];
        if(i) {
            pref[i] += pref[i-1];
            pref[i] %= MOD;
        }
    }

    LL ans = 0;
    fore(i,1,n-1) {
        ans += (a[i]*pref[i-1])%MOD;
        ans %= MOD;
    }

    cout << ans << en;
    return 0;
} 

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int ntest = 1;
    //cin >> ntest;
    fori(test, ntest) {
        //cout << "Case #" << test+1 << ": ";
        solve();
    }

    return 0;
}


Measured memory_bytes: 6356
def minimum_cost_sort(A):
  cost = 0
  B = sorted(A)
  for i in range(len(B)):
    x = A.index(B[i])
    cnt = 0
    tmp = 0
    while x != i:
      y = A.index(B[x])
      A[x], A[y] = A[y], A[x]
      tmp += A[x] + A[y]
      cnt += 1
      x = y
    if cnt > 0:
      # compare with procedure as follows:
      #   convert B[i] and B[0] (minimum item) : cost = B[i] + B[0]
      #   sort with B[0] in the same way       : cost diff = (B[i] - B[0]) * cnt
      #   reconvert B[0] and B[i]              : cost = B[i] + B[0]
      cost += min(tmp, (B[i] + B[0]) * 2 + tmp - (B[i] - B[0]) * cnt)
  return cost

N = int(input())
A = list(map(int, input().split()))
print(minimum_cost_sort(A))

Measured memory_bytes: 7772
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {

    val sc = new Scanner(System.in)
    val n = sc.next()

    val last = n.toCharArray.last.toString

    if (Seq("2", "4", "5", "7", "9").contains(last)) println("hon")
    else if (Seq("0", "1", "6", "8").contains(last)) println("pon")
    else println("bon")

  }

}


Measured memory_bytes: 55236
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>>a(H, vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> a.at(i).at(j);
    }
  }
  
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(a.at(i).at(j) == '.'){
 
      bool isWhiteRow = true;
      for(int tj=0; tj<W; tj++){
        if(a.at(i).at(tj) == '#'){
          isWhiteRow = false;
          break;
        }
      }
      if(isWhiteRow){
        for(int tj=0; tj<W; tj++){
        a.at(i).at(tj) = '\0';
        }
      }

      bool isWhiteColumn = true;
      for(int ti=0; ti<H; ti++){
        if(a.at(ti).at(j) == '#'){
          isWhiteColumn = false;
          break;  
        }
      }
 
      if(isWhiteColumn){
        for(int ti=0; ti<H; ti++){
          a.at(ti).at(j)='\0';  
        }
      }
    }
    }
  }
    for(int i = 0; i < H; i++){
    int charNum = 0;
    for(int j = 0; j < W; j++){
      char out = a.at(i).at(j);
      if(out != '\0'){
        charNum++;
        cout << a.at(i).at(j);
      }
    }
    if(charNum != 0){
      cout << endl;
    }
  }
  return 0;

}
    

Measured memory_bytes: 3608
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char in[20];
int main(){
	scanf("%s",in);
	in[3]++;
	printf("%s\n",in);
}

Measured memory_bytes: 128
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}
import scala.language.postfixOps

object Main extends App {
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)

  val INF = 1 << 30
  type Node = Int
  case class Edge(node:Node, cost:Int)
  val graph = Array.fill(n)(mu.ListBuffer.empty[Edge])
  val value = Array.fill(n)(INF)

  Iterator.continually(in.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt))
    .foreach(e => {
      val l = e(0) - 1
      val r = e(1) - 1
      val d = e(2)
      graph(l) += new Edge(r, d)
      graph(r) += new Edge(l,-d)
    })

  def dfsStack(graph:Array[mu.ListBuffer[Edge]], node:Node):Unit = {
    value(node) = 0
    val stack = mu.Stack.empty[Node]
    stack push node
    while(stack nonEmpty) {
      val v = stack.pop
      graph(v) foreach ( edge => {
        if(value(edge.node) == INF) {
          value(edge.node) = value(v) + edge.cost
          stack push edge.node
        }
      })
    }
  }

  (0 until n) foreach ( i => if(value(i) == INF) dfsStack(graph, i) )

  val valid = (0 until n) forall ( i => {
      graph(i) forall ( edge => value(i) + edge.cost == value(edge.node) )
    })

  val ans = if(valid) "Yes" else "No"
  println(ans)
}

Measured memory_bytes: 103820
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
using namespace std;

int main(void) {
	int n;
	char a, b;
	string str;
	cin >> str;

	n = str.length() - 2;

	a = str.front();

	b = str.back();

	cout << a << n << b << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
	
	static long mod= (long) 1e9+7;
	
		
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Reader.init(System.in);
		PrintWriter out=new PrintWriter(System.out);
		long a=Reader.nextInt();
		out.println(a+a*a+a*a*a);
		
		
		out.flush();
		
	}

}

class Seg{
	
	int[] tree,arr;
	
	Seg(int n,int[] a){
		tree=new int[4*n];arr=a;
	}
	
	void build(int index, int left, int right) {
		if(left==right) tree[index]=arr[left];
		else {
			int mid=(left+right)/2;
			build(2*index+1,left,mid);
			build(2*index+2,mid+1,right);
			tree[index]=Math.max(tree[2*index+1],tree[2*index+2]);
		}
	}
	
	int query(int index, int ql, int qr, int left, int right) {
		if(ql<=left && right<=qr) return tree[index];
		else if(ql > right || qr<left) return 0;
		else {
			int mid=(left+right)/2;
			return Math.max(query(2*index+1,left,mid,ql,qr), query(2*index+2,mid+1,right,ql,qr));
		}
	}
	
	void update(int index, int left, int right, int pos, int val) {
		if(left==right) {
			tree[index]=val;
		}
		else {
			int mid=(left+right)/2;
			if(pos<=mid) {
				update(2*index+1,left,mid,pos,val);
			}
			else update(2*index+2,mid+1,right,pos,val);
			tree[index]=Math.max(tree[2*index+1],tree[2*index+2]);
		}
	}
}


class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    /** call this method to initialize reader for InputStream */
    static void init() throws IOException {
        reader = new BufferedReader(
                new FileReader("C:\\Users\\samee\\Desktop\\GRE prep\\confusion.txt"));
        tokenizer = new StringTokenizer("");
    }
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    /** get next word */
    static String nextLine() throws IOException{
        return reader.readLine();
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}

Measured memory_bytes: 32744
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> x(N),y(N),h(N);
    rep(i,N) cin >> x[i] >> y[i] >> h[i];

    int po = 0;
    while (h[po]==0) ++po;

    rep(i,101) {
        rep(j,101) {
            int H = h[po] + abs(x[po]-i) + abs(y[po]-j);
            bool ok = true;
            rep(k,N) {
                if (h[k] != max(H - abs(x[k] - i) - abs(y[k] - j),0)) {
                    ok = false;
                }
            }
            if (ok) {
                cout << i << " " << j << " " << H << ln;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff          first
#define ss          second
#define ll         	long long int
#define pb          push_back
#define ar 			array
#define mp 			make_pair
#define f(i,n)   	for(ll i =0;i<n;i++)
#define inf 		INT_MAX
#define pll 		pair<ll,ll>
const ll INF = 1e18;
void init(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE 
		freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#endif
}
const ll N = 1e5 + 10;
void solve(){

	int temp;
	for(ll i =0;i<5;i++){
		cin>>temp;
		if(temp == 0){
			cout<<i+1<<endl;
		}
	}





	
	
}
int main(){
	
	init();
	ll t = 1;
	//cin>>t;
	for(ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}


Measured memory_bytes: 3608
# -*- coding: utf-8 -*-
# Input#
# n = int(input())
n, k = map(int, input().split())
h = list(map(int, input().split()))

h = [-1] + h

ans = 0

memo = [-1] * (n + 1)
memo[1] = 0


def dp(i):
    if memo[i] != -1:
        return memo[i]
    else:
        for j in range(k):
            if i - (j + 1) < 1:
                continue
            hop = dp(i - j - 1) + abs(h[i] - h[i - j - 1])
            if memo[i] == -1:
                memo[i] = hop
            else:
                memo[i] = min(hop, memo[i])
        return memo[i]


for i in range(n):
    memo[i] = dp(i)

ans = dp(n)

print("{}".format(ans))


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

int main(){
    string s;
    cin >> s;
    int count = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == '1') {
            count++;
        }
    }
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int grid[200][200];

int main() {


	int W, H, N, X[1000], Y[1000],A[1000];
	scanf("%d%d%d", &W, &H, &N);
	for (int i = 0; i < N; i++) {
		scanf("%d%d%d", &X[i], &Y[i], &A[i]);
	}


	for (int i = 0; i < N; i++) {
		if (A[i] == 1) {
			for (int j = 0; j < X[i]; j++) {
				for (int k = 0; k < H; k++) {
					grid[k][j] = 1;					
				}
			}
		}

		else if (A[i] == 2) {
			for (int j = X[i]; j < W; j++) {
				for (int k = 0; k < H; k++) {
					grid[k][j] = 1;
				}
			}
		}

		else if (A[i] == 3) {
			for (int j = 0; j < W; j++) {
				for (int k = 0; k < Y[i]; k++) {
					grid[k][j] = 1;
				}
			}
		}

		else {
			for (int j = 0; j < W; j++) {
				for (int k = Y[i]; k < H; k++) {
					grid[k][j] = 1;
				}
			}

		}

	}


	int ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			ans += grid[i][j];
		}
	}

	/*for (int i = H-1; i >=0; i--) {
		for (int j = 0; j < W; j++) {
			printf("%d", grid[i][j]);
		}
		printf("\n");
	}*/

	printf("%d", H*W-ans);


}


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

int main(){
    int n;
    cin>>n;
    
    int dp[1000099];
    fill(dp,dp+1000099,0);
    
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        dp[a]++;
        
    }
    int cnt=0;
    
    for(long i =1;i<=1000001;i++){
        if(dp[i]==0)
        continue;
        
        if(dp[i]==1){
            cnt++;
        }
        
        for(int j=i*2;j<=1000001;j+=i){
            
            dp[j]=0;
        }
        
    }
    
    cout<<cnt;
    
    
    
}

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf (1 << 21)
#define mod 1000000007

int main() {
    int X; cin >> X;
    if (X == 7 || X == 5 || X == 3) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
//#include <fstream>
#include <vector>

using namespace std;

int main(int argc, const char * argv[]) {
//        ifstream in("input.txt");
//        cin.rdbuf(in.rdbuf());
    
    int N;
    cin >> N;
    
//    vector<int> h(N);
    int H;
    int maxH=0;
    int cnt = 0;
    for (int i=0;i<N;++i)
    {
        cin >> H;
        if (H >= maxH)
        {
            ++cnt;
            maxH = H;
        }
    }
    
    cout << cnt << endl;
    
    
    
    return 0;
}

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

int hi,hii,mi,mii,k,startTime,endTime;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>hi>>mi>>hii>>mii>>k;
	startTime = hi * 60 + mi;
	endTime = hii * 60 + mii;
	if (endTime - startTime < k) cout<<0<<endl;
	else cout<<endTime - startTime - k<<endl;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M;
ll A[55], B[55], C[55], D[55];
int ans[55];

int Solve(int num){
  ll sum = 1e18;
  for (int i = 1; i <= M; i++){
    if (sum > abs(A[num] - C[i]) + abs(B[num] - D[i])){
      ans[num] = i;
      sum = abs(A[num] - C[i]) + abs(B[num] - D[i]);
    }
  }
  cout << ans[num] << endl;

  return 0;
}

int main(){
  cin >> N >> M;
  for (int i = 1; i <= N; i++) cin >> A[i] >> B[i];
  for (int i = 1; i <= M; i++) cin >> C[i] >> D[i];


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


  return 0;
}


Measured memory_bytes: 3644
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#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 LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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


int main(void) {
	
	while (1) {
		long long int n, m, s, g1, g2;
		long long int mini = LINF;

		cin >> n >> m >> s >> g1 >> g2;

		if (n == 0) {
			break;
		}

		long long int d[101][101];
		FOR(i, 0, 100) {
			FOR(j, 0, 100) {
				d[i][j] = LINF;
				if (i == j) {
					d[i][j] = 0;
				}
			}
		}

		long long int a, b, c;
		FOR(i, 1, m) {
			cin >> a >> b >> c;
			d[a][b] = c;
		}

		FOR(i, 1, n) {
			FOR(j, 1, n) {
				FOR(k, 1, n) {
					d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
				}
			}
		}


		FOR(i, 1, n) {
			mini = min(mini, d[s][i] + d[i][g1] + d[i][g2]);
		}

		cout << mini << endl;




	}



	
	

	return 0;
}


Measured memory_bytes: 3148
#!/usr/bin/env python3
# https://abc048.contest.atcoder.jp/tasks/arc064_a
n, x = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
c = 0
for i in range(1, len(a)):
	b = a[i - 1] + a[i]
	d = b - x
	if d > 0:
		c += d
		e = min(a[i], d)
		a[i] -= e
		d -= e
		if d > 0:
			a[i - 1] -= d
print(c)

Measured memory_bytes: 14592
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#define PI acos(-1.0)
using namespace std;
int main(){
	char a[3];
	for(int i =0;i < 3;i++) cin >> a[i];
	int flag = 0;
	for(int i = 0;i < 3;i++){
		if(a[i] == '7'){
			flag = 1;
			break;
		} 
	}
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3052
//B - Comparison:
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    string a, b;
    cin >> a >> b;
    if(a.size() < b.size()) {
        reverse(all(a));
        while(a.size() < b.size()) a += '0';
        reverse(all(a));
    } else if(a.size() > b.size()) {
        reverse(all(b));
        while(a.size() > b.size()) b += '0';
        reverse(all(b));
    }
    if(a > b) cout << "GREATER\n";
    else if(a < b) cout << "LESS\n";
    else cout << "EQUAL\n"; 
}

Measured memory_bytes: 256
import queue
count=9
target=int(input())
q=queue.Queue()
for i in range(1,10):
    q.put(i)
if count>=target:
    print(target)

if count<target:
    while(1):
        a=q.get()
        if a%10!=0:
            q.put(a*10+a%10-1)
            count+=1
            if count==target:
                print(a*10+a%10-1)
                break
        q.put(a*10+a%10)
        count+=1
        if count==target:
            print(a*10+a%10)
            break
        if a%10!=9:
            q.put(a*10+a%10+1)
            count+=1
            if count==target:
                print(a*10+a%10+1)
                break

Measured memory_bytes: 6728
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <math.h>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n, 0);
	float total = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		total += a[i];
	}

	total /= n;
	int best = 0;
	for (int i = 1; i < n; i++)
		if (abs(a[i] - total) < abs(total - a[best]))
			best = i;
	printf("%d", best);
	return 0;
}


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

int main()
{
	int n,k,h,c=0;

   cin >> n >> k;
   for(int i=0; i<n; i++){
     cin >> h;
     if(h>=k){c++;}
   }

   cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
h = [0] * N
for i in range(N):
    h[i] = int(input())
h.sort()
deco = 10 ** 9
for i in range(N - K + 1):
    if h[i + K - 1] - h[i] < deco:
        deco = h[i + K - 1] - h[i]
print(deco)


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

int main(){
int N;
cin >> N;
long long sum = 0;
for(int i= 1; i <= N; i++){
    if(i % 3 != 0 && i % 5 != 0){
        sum += i;
    }
}
cout << sum << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n;
    cin>>n;
    ll rate[9]={},a;
    rep(i,n){
        cin>>a;
        rate[min(a/400,(ll)8)]++;
    }
    ll cnt=0;
    rep(i,8){
        if(rate[i]!=0) cnt++;
    }
    cout<<max((ll)1,cnt)<<' '<<cnt+rate[8]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
ll dp[105][4][4][4] = {0};
bool pan(int a, int b, int c)
{
    if (a == 0 && b == 2 && c == 1) return false;
    if (a == 0 && b == 1 && c == 2) return false;
    if (a == 2 && b == 0 && c == 1) return false;
    return true;
}
bool pan1(int a, int b, int c)
{
    if (a == 0 && b == 2 && c == 1) return false;
    return true;
}
int main ()
{
    int n;
	scanf("%d", &n);
	for (int i = 0; i < 4; i++)
	{
       	for (int j = 0; j < 4; j++)
		{
           	for (int p = 0; p < 4; p++)
			{
               	if (pan(i, j, p))
				{
                   	dp[3][i][j][p] = 1;
               	}
           	}
       	}
	}
	for (int k = 4; k <= n; k++)
	{
    	for (int i = 0; i < 4; i++)
		{
           	for (int j = 0; j < 4; j++)
			{
				for (int p = 0; p < 4; p++)
				{
                	if (pan(i, j, p))
					{
                    	for (int q = 0; q < 4; q++)
						{
                        	if (pan(q, i, j) && pan1(q, j, p) && pan1(q, i, p))
							{
								dp[k][i][j][p] = (dp[k][i][j][p] + dp[k - 1][q][i][j]) % mod;
                        	}
                        }
                    }
                }
            }
        }
    }
	ll ans = 0;
    for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			for (int p = 0; p < 4; p++)
			{
				ans = (ans + dp[n][i][j][p]) % mod;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
typedef struct{
  int parent;
  int left;
  int right;
} Tree;
Tree tree[10000];
//int s=0,t=0;
#define NIL -1
int getheight(int);
int main()
{
  int i,id,j,n,k,depth=0,num,l,r,degree=0,height=0;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    tree[i].parent=NIL;
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d%d",&id,&l,&r);
    tree[id].left=l;
    tree[id].right=r;
    if(l!=NIL && r!=NIL){
      tree[l].parent=id;
      tree[r].parent=id;
    }
    else if(l!=NIL && r==NIL){
      tree[l].parent=id;
    }
    else if(l==NIL && r!=NIL){
      tree[r].parent=id;
    }
  }
    
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, ",i,tree[i].parent);
    if(tree[i].parent==NIL){
      printf("sibling = -1, ");
    }
    else if(tree[tree[i].parent].left==i){
      printf("sibling = %d, ",tree[tree[i].parent].right);
    }
    else{
      printf("sibling = %d, ",tree[tree[i].parent].left);
    }
    printf("degree = ");
    if(tree[i].left!=NIL && tree[i].right!=NIL){
      printf("2, ");
    }
    else if(tree[i].left==NIL && tree[i].right==NIL){
      printf("0, ");
    }
    else printf("1, ");
  
    num=i;
    while(tree[num].parent!=NIL){
      depth++;
      num=tree[num].parent;
    }
    printf("depth = %d, ",depth);
    depth=0;
  
    printf("height = ");
    height=getheight(i);
    printf("%d,",height);
    //s=0;t=0;
      
    if(tree[i].parent==NIL){
      printf(" root\n");
    }
    else if(tree[i].left==NIL && tree[i].right==NIL){
      printf(" leaf\n");
    }
    else {
      printf(" internal node\n");
      }
  }
  return 0;
}
 
int getheight(int i)
{
  int s=0,t=0;
  if(tree[i].left==NIL && tree[i].right==NIL)return 0;
 
  if(tree[i].left!=NIL){
  s=getheight(tree[i].left)+1;
  }
  if(tree[i].right!=NIL){
  t=getheight(tree[i].right)+1;
  }
  if(s>t){
     
    return s;
  }
  else{
    return t;
  }
}

Measured memory_bytes: 612
w = input()
count = {}
for w_i in w:
  if w_i in count:
    count[w_i] += 1
  else:
    count[w_i] = 1

is_beautiful = True
for v in count.values():
  if 0 != v % 2:
    is_beautiful = False
    break
print("Yes" if is_beautiful else "No")

Measured memory_bytes: 2940
n=int(input())
a=list(map(int,input().split()))
b=[0 for _ in range(n)]

ans=0

while a!=b:
  ch=0
  for i in range(n):
    if b[i]+1<=a[i]:
      b[i]+=1
      ch+=1
    elif b[i]+1>a[i] and ch>0:
      ch=0
      ans+=1
      
    if ch>0 and i==n-1:
      ans+=1
      
print(ans)
  

Measured memory_bytes: 9148
def product_max(lst):
  first = lst[0]*lst[2]
  second = lst[0]*lst[3]
  third = lst[1]*lst[2]
  fourth = lst[1]*lst[3]
  new_list = [first, second, third, fourth]
  return max(new_list)


a,b,c,d = map(int, input().split())
print(product_max([a,b,c,d]))


Measured memory_bytes: 9168
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n;
	cin>>n;
	vector<int> a(n);
	vector<int> in(n,-1);
	FOR(i,0,n){
		cin>>a[i];
		if(i==0){
			in[n-1]=a[i];
			continue;
		}
		int idx=lower_bound(in.begin(),in.end(),a[i])-in.begin();
		cerr<<a[i]<<" "<<idx<<endl;
		in[idx-1]=a[i];
	}
	int ans=n;
	FORD(i,n,0){
		if(in[i]==-1){
			ans=n-1-i;
			break;
		}
	}
	cout<<ans<<endl;




	return 0;
}


Measured memory_bytes: 1024
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,k = LI()
    a = LI()
    r = [0] * n
    for i in range(1,n):
        ai = a[i]
        t = r[i-1] + abs(a[i-1]-ai)
        mj = i - k
        if mj < 0:
            mj = 0
        for j in range(mj,i-1):
            u = r[j] + abs(a[j]-ai)
            if t > u:
                t = u

        r[i] = t

    return r[-1]


print(main())


Measured memory_bytes: 16196
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n, p;
    cin >> n >> p;
    ll a, ev, od = 0;
    REP(i, n){
        cin >> a;
        if(a % 2) od++;
    }
    ev = n - od;
    ll tev = 1;
    REP(i, ev) tev *= 2;
    if(!od){
        if(p) cout << 0 << endl;
        else cout << tev << endl;
        return 0;
    }
    ll res = 1;
    REP(i, n - 1) res *= 2;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const ll MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)
//std::sort(v.begin(), v.end(), std::greater<Type>());
//set_intersection(x, x+7, y, y+6, back_inserter(v));
//set_union(x, x+7, y, y+6, back_inserter(v));
//set_difference(x, x+7, y, y+6, back_inserter(v));

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

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int n;
  cin >> n;
  int sum = 0;
  vector<int>V(n),C(n);
  for(int i=0;i<n;i++) cin >> V[i];
  for(int i=0;i<n;i++) cin >> C[i];

  for(int i=0;i<n;i++){
    if(V[i]-C[i]>0) sum += V[i]-C[i] ;
  }
  cout<< sum <<endl;
}


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

int main()
{
    int N;
    string S;
    cin >> N >> S;
    int res = 0;
    for(int i = 0;i + 1 < N;i++){
        if(S[i] != S[i + 1]){
            ++res;
            ++i;
        }
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>

#define N 101
#define inf 1000000

using namespace std;

int main()
{
  int n, m, a, b, p, q, r, cs, tm;
  int cost[N][N], time[N][N];

  while(cin>>n>>m && n+m){
    fill(&cost[0][0], &cost[m][m], inf);
    fill(&time[0][0], &time[m][m], inf);

    for(int i = 1; i <= m; ++i){
      cost[i][i] = 0;
      time[i][i] = 0;
    }

    while(n--){
      cin >> a >> b >> cs >> tm;
      cost[a][b] = cost[b][a] = cs;
      time[a][b] = time[b][a] = tm;
    }
    
    // warshall-floyd
    for(int k = 1; k <= m; ++k)
      for(int i = 1; i <= m; ++i)
	for(int j = 1; j <= m; ++j){
	  cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
	  time[i][j] = min(time[i][j], time[i][k]+time[k][j]);
	}

    cin >> n;
    while(n--){
      cin >> p >> q >> r;
      cout << ((r)? time[p][q]: cost[p][q]) << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1236
#include<iostream>
using namespace std;
#include<vector>
#define int long long int
#define mod 100000000000
int power(int a,int b)
{
	if(b==0)
	  return 1;
	int r=power(a,b/2);
	r=r%mod;
	if(b%2==0)
	  return (r*r)%mod;
	else
	{
		int x=r*r;
		x=x%mod;
		return (a*x)%mod;
	}
}
int32_t main()
{
    int n;
    cin>>n;
    int val=0;
    int count=1;
    int j,arr[n];
    for(j=0;j<n;j++)
       cin>>arr[j];
    for(j=0;j<n;j++)
    {
		if(arr[j]==count)
		{
			val++;
			count++;
		}
	}
	if(val==0)
	   cout<<-1<<endl;
	else
	  cout<<(n-val)<<endl;
}


Measured memory_bytes: 1792