akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

//i未満左端、j未満はignore
ll dp[5001][5001];

struct BIT {
private:
	vector<int> node; int n;
public:
	BIT(int n_) {
		n = n_; node.resize(n, 0);
	}
	//0-indexed
	void add(int a, int w) {
		for (int i = a; i < n; i |= i + 1)node[i] += w;
	}
	//[0,a)
	int sum(int a) {
		int ret = 0;
		for (int i = a - 1; i >= 0; i = (i&(i + 1)) - 1)ret += node[i];
		return ret;
	}
	//[a,b)
	int sum(int a, int b) {
		return sum(b) - sum(a);
	}
};

void solve() {
	int n; ll a, b; cin >> n >> a >> b;
	vector<int> p(n),invp(n);
	rep(i, n) {
		cin >> p[i]; p[i]--; invp[p[i]] = i;
	}
	BIT bi(n);
	rep(i, 5001) {
		rep(j, 5001) {
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	rep(i, n) {
		int id = invp[i];
		rep(j, n+1) {
			//right
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]+b);
			//left
			if (j <= id) {
				int num = bi.sum(j, id);
				num = id - j - num;
				//cout << i << " " << j << " " << num << endl;
				dp[i + 1][id+1] = min(dp[i + 1][id+1], dp[i][j] + a * num);
			}
			else {
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
			}
		}
		bi.add(id, 1);
	}
	ll ans = INF;
	rep(i, n + 1) {
		ans = min(ans, dp[n][i]);
	}
	cout << ans << endl;
}
int main() {
	solve();
	//stop
	return 0;
}


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

int main()
{
	int n,k;
	string s;
	cin>>n>>s>>k;
	
	for(int i=0;i<n;i++){
		if(s[i]!=s[k-1]) s[i]='*';
	}
	cout<<s<<endl;
	
	return 0;
}


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

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

fn get<T: std::str::FromStr + Clone>() -> T {
    let line = read_vec::<T>();
    line[0].clone()
}

fn main() {
    let N = get::<usize>();

    let V = read_vec_with_capacity::<i32>(N);
    let C = read_vec_with_capacity::<i32>(N);

    let sum = (0..N)
        .map(|x| V[x] - C[x])
        .filter(|&diff| diff > 0)
        .sum::<i32>();

    println!("{}", sum);
}


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

using ll = long long;

const int N = 5e5L + 11;
ll a[N], b[N];
bool ans[N];

int main() {
	int n;
	cin >> n >> b[0];
	for(int i = 1; i <= n; i ++) {
		scanf("%lld", a + i);
		b[i] = min(b[i - 1], abs(b[i - 1] - a[i]));
		//cout << i << ' ' << b[i] << '\n';
	}
	ll suf = 0;
	for(int i = n; i >= 1; i --) {
		//cout << i << ' ' << suf << '\n';
		if(suf < b[i - 1])
			ans[i] = 1;
		if(suf >= a[i] / 2)
			suf += a[i];
	}
	int q; cin >> q;
	while(q --) {
		ll x; scanf("%lld", &x);
		printf("%s\n", (ans[x] ? "YES" : "NO"));
	}
	return 0;
}

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

int main(){
	int n, ball;cin >> n;
	stack<int> r, l;
	while(n--){
		r.push(0);l.push(0);
		bool f = false;
		for(int i = 0;i < 10;i++){
			cin >> ball;
			if(f == true)continue;
			if(r.top() < ball){
				r.push(ball);
			}else if(l.top() < ball){
				l.push(ball);
			}else{
				f = true;
			}
		}
		while(!r.empty())r.pop();
		while(!l.empty())l.pop();
		if(f == false)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 3004
#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 20000010
#define P 1000000007
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,m,k,fac[N],inv[N],ans;
int C(int n,int m){if (m>n) return 0;return 1ll*fac[n]*inv[m]%P*inv[n-m]%P;}
int invC(int n,int m){if (m>n) return 0;return 1ll*inv[n]*fac[m]%P*fac[n-m]%P;}
signed main()
{
	n=read(),m=read(),k=read();
	fac[0]=1;for (int i=1;i<=n+m;i++) fac[i]=1ll*fac[i-1]*i%P;
	inv[0]=inv[1]=1;for (int i=2;i<=n+m;i++) inv[i]=P-1ll*(P/i)*inv[P%i]%P;
	for (int i=2;i<=n+m;i++) inv[i]=1ll*inv[i-1]*inv[i]%P;
	ans=1ll*C(k,2)*invC(n+m,2)%P;
	ans=(ans+1ll*invC(3,1)*C(k,3)%P*invC(n+m,3)%P*(n+m-2))%P;
	ans=1ll*ans*n%P*m%P;
	int ans1=0;
	ans1=1ll*C(k,1)*invC(n+m,1)%P;
	ans1=(ans1+1ll*invC(2,1)*C(k,2)%P*invC(n+m,2)%P*(n+m-1))%P;
	ans1=1ll*ans1*(n+m)%P;
	ans=(ans+ans1+k)%P;
	cout<<1ll*ans*C(n+m,k)%P*fac[k]%P;
	return 0;
	//NOTICE LONG LONG!!!!!
}

Measured memory_bytes: 156544
n, m = map(int,input().split())
lr = []
for i in range(m):
    lr.append([int(i) for i in input().split()])

tmp1 = 0
tmp2 = pow(10, 6)
for i in range(m):
    tmp1 = max(lr[i][0], tmp1)
    tmp2 = min(lr[i][1], tmp2)
print(max(0, tmp2 - tmp1 + 1))


Measured memory_bytes: 21156
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using ll = long long;
// using ll = boost::multiprecision::int128_t;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;


int main() {
  ll n; cin >> n;
  Vll a(n+1); cin >> a;

  Vll s = a;
  drep(i, n) s[i] += s[i+1];
  s.push_back(0);

  ll ans = 0, x = 1;
  rep(i, n+1) {
    if (i) x = min(2*(x-a[i-1]), s[i]);
    if (x < 0) {
      cout << -1 << "\n";
      return 0;
    }
    ans += x;
  }
  x = min(2*(x-a[n]), 0ll);
  if (x < 0) cout << -1 << "\n";
  else cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 5580
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
const int MOD = 1e9+7;
int sm[10050];
int dp[5050][5050];
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n,m,k,q;
  cin>>n>>m>>k>>q;
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  for(int i=0;i<m;i++){
    memset(sm,0,sizeof(sm));
    for(int j=0;j<n;j++){
      int x=j%(2*k);
      sm[x]+=dp[i][j];
      sm[x]%=MOD;
      sm[2*k+x]+=dp[i][j];
      sm[2*k+x]%=MOD;
    }
    
    for(int j=1;j<4*k;j++) sm[j]=(sm[j]+sm[j-1])%MOD;
      
    for(int j=0;j<n;j++)
      dp[i+1][j]=(sm[2*k+(j%(2*k))]+MOD-sm[k+(j%(2*k))])%MOD;
  }
  
  for(int i=0;i<q;i++){
    int a,b,c;
    cin>>a>>b>>c;
    int d=(c-a+n)%n;
    cout<<dp[b][d]<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 102868
use proconio::input;

fn main() {
    input! {
        n: usize,
        d: [(usize, usize); n],
    }

    let mut ok = false;
    let mut cur = 0;
    for (d1, d2) in d {
        if d1 == d2 {
            cur += 1;
        } else {
            cur = 0;
        }

        if cur >= 3 {
            ok = true;
        }
    }

    let ans = if ok { "Yes" } else { "No" };
    println!("{}", ans);
}


Measured memory_bytes: 2192
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

/*
  patterns 
  (0,1,2,3)^n
*/

int main(int argc, char *argv[]) {
  int n;
  int y[3];
  cin >> n >> y[0] >> y[1] >> y[2];

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

  int z=-1;
  for(int i=0;i<(1<<(2*n));++i) {
    int x[3];
    int s=0;
    for(int j=0;j<3;++j) x[j]=0;
    int k=i;
    for(int j=0;j<n;++j) {
      int p=k&3;
      if (p<3) {
	if (x[p]) s+=10;
	x[p]+=l[j];
      }
      k >>= 2;
    }
    if ((x[0]!=0)&&(x[1]!=0)&&(x[2]!=0)) {
      for(int j=0;j<3;++j)
	s+=abs(y[j]-x[j]);
      //cout << x[0] << ' ' << x[1] << ' ' << x[2] << ' ' << s << endl;
      if ((z<0)||(s<z)) z = s;
    }
  }
  cout << z << endl;
  return 0;
}


Measured memory_bytes: 256
MOD = 10**9 + 7
s = gets.chomp

s.reverse!

rem = [1,10,9,12,3,4]
count = Array.new(2){Array.new(13,0)}
count[1][0] = 1

(s.length).times do |i|
  if s[i] == '?'
    count[i%2] = Array.new(13,0)
    sum = count[(i-1)%2].reduce(&:+)
    13.times do |j|
      count[i%2][j] = sum - count[(i-1)%2][(j+rem[i%6])%13] - count[(i-1)%2][(j+2*rem[i%6])%13] - count[(i-1)%2][(j+3*rem[i%6])%13]
      count[i%2][j] %= MOD
    end
  else
    n = s[i].to_i
    count[i%2] = count[(i-1)%2].rotate(-(n*rem[i%6]))
  end
end

puts(count[(s.length-1)%2][5])

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

int main(){
	int N;
	cin>>N;
	
	int A[N];
	for(int i=0;i<N;i++)
		cin>>A[i];
	
	sort(A,A+N);
	int min=A[0];
	int max=A[N-1];
	
	cout<<max-min<<endl;
	return 0;
}

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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

int n, q;
string S;

int b[100010];

int partsum(int l, int r) {
	if (r < l) swap(r, l);
	return b[r] - b[l];
}

int main(void){
	cin>>n>>q>>S;

	for (int i = 1; i < S.size(); i++) {
		if (S[i - 1] == 'A' && S[i] == 'C') b[i]++;
	}
	for (int i = 1; i < S.size(); i++) b[i] += b[i - 1];

	while (q--) {
		int l, r; cin>>l>>r;
		l--; r--;

		cout<< partsum(l, r) <<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;
typedef tuple<int,int,int> T;
bool vis[121][121];
bool ob[121][121];
int dx[6]={-1,0,1,1,0,-1};
int dy[6]={0,1,1,0,-1,-1};
int main() {
	int t,n;
	while(scanf("%d %d",&t,&n),t) {
		memset(vis,0,sizeof(vis));
		memset(ob,0,sizeof(ob));
		for(int i=0;i<n;i++) {
			int x,y;
			scanf("%d %d",&x,&y);
			ob[x+60][y+60]=1;
		}
		int sx,sy;
		scanf("%d %d",&sx,&sy);
		queue<T> Q;
		Q.push(make_tuple(sx+60,sy+60,0));
		vis[sx+60][sy+60]=1;
		while(!Q.empty()) {
			T tp=Q.front();Q.pop();
			int x=get<0>(tp),y=get<1>(tp),d=get<2>(tp);
			if(d==t) break;
			for(int i=0;i<6;i++) {
				int nx=x+dx[i],ny=y+dy[i];
				if(vis[nx][ny]||ob[nx][ny]) continue;
				vis[nx][ny]=1;
				Q.push(make_tuple(nx,ny,d+1));
			}
		}
		int ans=0;
		for(int i=0;i<=120;i++) {
			for(int j=0;j<=120;j++) ans+=vis[i][j];
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 3272
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cins(S);
    rep(i,S.length()-1){
        if(S[i]==S[i+1]){
            cout << "Bad" << nn;
            return 0;
        }
    }
    cout << "Good" << nn;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define ncr(n,r) fact[n]*modInv(fact[r])*modInv(fact[n-r])
#define modInv(a) binExp(a,mod-2)
#define mod 1000000007
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define os_find(k) find_by_order(k)
//#define os_order(k) order_of_key(k)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);}
#define test int t;cin>>t;while(t--)

signed main()
{
    fast

    int n;
    cin>>n;

    int h[3];
    int dp[3];
    cin>>h[0]>>h[1];
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    f0(i,2,n)
    {
        cin>>h[2];
        dp[2] = min(dp[0] + abs(h[0]-h[2]), dp[1] + abs(h[1]-h[2]));
        dp[0] = dp[1];
        dp[1] = dp[2];
        h[0] = h[1];
        h[1] = h[2];
    }

    cout<<dp[1];
}

Measured memory_bytes: 3544
n, m = gets.split.map &:to_i
e = n.times.map{[]}
z = Array.new n
m.times do
  a, b = gets.split.map &:to_i
  a -= 1
  b -= 1
  e[a] << b
  e[b] << a
end
q = [0]
z[0] = 0
while q.length > 0
  qq = []
  q.each do |i|
    e[i].each do |j|
      next if z[j]
      z[j] = i
      qq << j
    end
  end
  q = qq
end
puts "Yes"
(1...n).each do |i|
  p z[i]+1
end

Measured memory_bytes: 37608
/*input
1000000000000
*/
#include<bits/stdc++.h>
#define ull         unsigned long long
#define ll             long long
#define M             1000000007
#define pb             push_back
#define p_q         priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()    
#define endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp             make_pair
#define lb             lower_bound
#define ub            upper_bound
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ini(a,n,b)    for(ll int i=0;i<n;i++) a[i]=0;
#define F            first
#define S            second
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

bool DEBUG = 0;

void solve()
{
    //initialize();
    ll h;cin>>h;
    ll ans = 0;
    ll num = 1;
    while(h > 1)
    {
        ans += num;
        num = num * 2;
        h = h/2;
    }
    if (h == 1)
        ans+= num;
    cout<<ans<<"\n";
}


int main(void)
{
    ios
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int N;
  cin >> N;
  vector<int> A(N-1);
  vector<int> B(N);
  rep(i,N-1) cin >> A.at(i);
  sort(A.begin(),A.end());

  rep(i,N-1){
    B.at(A.at(i)-1) ++;
  }
  rep(i,N) cout << B.at(i) << endl;
  }



Measured memory_bytes: 4824
#include <iostream>
using namespace std;
int main(void){
    int W,H,i,j;
    while(1){
        cin >> H >> W;
        if (H==0 && W==0){
            break;
        }
        for (i=0;i<H;i++){
            for(j=0;j<W;j++){
                cout << "#";
            }
            cout << endl;
        }
        cout  << endl;
    }
}


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

/*
// ordered_set 
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
# define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
 
using namespace std;
 
typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ll, ll>                                    pll;
 
# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define Sort(x)                                         sort(all(x))
# define InTheNameOfGod                                  ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
 
ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}

const ll md = 101111111111;
const int xn = 2e5 + 10;
const int xm = 1e6 + 10;
const int SQ = 320;
const int sq = 320 + 10;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const int MOD[4] = {1000000009, 1000000007, 987654319, 999999937};
const int TM = 3;
const int BASE = 257;

ll n, ans = INF;
pll num[xn], a, b, c, d;
set <pll> st[2];

int main(){
    InTheNameOfGod;
    
    cin >> n;
    for (int i = 0; i < n; ++ i) cin >> num[i].A >> num[i].B;
    for (int i = 0; i < n; ++ i) if (num[i].A > num[i].B) swap(num[i].A, num[i].B);
    sort(num, num + n);
    for (int i = 0; i < n; ++ i) st[0].insert({num[i].A, i}), st[1].insert({num[i].B, i + n});
    a = *st[0].begin();
    b = *prev(st[0].end());
    c = *st[1].begin();
    d = *prev(st[1].end());
    ans = (b.A - a.A) * (d.A - c.A);
    for (int i = 0; i < n; ++ i){
    	st[0].erase({num[i].A, i}), st[1].insert({num[i].A, i});
    	st[1].erase({num[i].B, i + n}), st[0].insert({num[i].B, i + n});
    	a = *st[0].begin();
	    b = *prev(st[0].end());
	    c = *st[1].begin();
	    d = *prev(st[1].end());
	    ans = min(ans, (b.A - a.A) * (d.A - c.A));
	}
	cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 28416
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

int mamegu(const void* x, const void* y) {
	int64_t a = *(const int64_t*)x, b = *(const int64_t*)y;
	return a < b ? -1 : a > b;
}

int N;
int A[222222];

int zc;
int64_t z[222222];

int64_t nakamayukie[222222];
int yukati[222222];

int zq(int64_t satorina) {
	int l = 0, r = zc - 1;
	while (l <= r) {
		int m = l + (r - l) / 2;
		if (z[m] == satorina) return m;
		else if (z[m] < satorina) l = m + 1;
		else r = m - 1;
	}
	printf("ERROR: %d not found\n", satorina);
	exit(2);
}

int main(void) {
	int i;
	int64_t kiyononn = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 1; i <= N; i++) {
		if (scanf("%d", &A[i]) != 1) return 1;
	}
	for (i = 1; i <= N; i++) {
		z[i] = nakamayukie[i] = nakamayukie[i - 1] + A[i];
	}
	qsort(z, N + 1, sizeof(*z), mamegu);
	zc = 1;
	for (i = 1; i <= N; i++) {
		if (z[zc - 1] != z[i]) z[zc++] = z[i];
	}
	for (i = 0; i <= N; i++) {
		yukati[zq(nakamayukie[i])]++;
	}
	for (i = 0; i < zc; i++) {
		if (yukati[i] > 1) kiyononn += (int64_t)yukati[i] * (yukati[i] - 1) / 2;
	}
	printf("%" PRId64 "\n", kiyononn);
	return 0;
}


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

int w, h;
vector< vector<int> > c;

void Dfs(int i, int j) {
  c[i][j] = 0;
  for (int di = -1; di <= 1; ++di) {
    for (int dj = -1; dj <= 1; ++dj) {
      if (di == 0 && dj == 0)
        continue;

      int ni = i + di, nj = j + dj;
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (c[ni][nj]) Dfs(ni, nj);
    }
  }
}

int main() {
  while (true) {
    cin >> w >> h;

    if (w == 0 && h == 0)
      break;

    c.resize(h, vector<int>(w));
    for (int i = 0; i < h; ++i)
      for (int j = 0; j < w; ++j)
        cin >> c[i][j];

    int ans = 0;
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (c[i][j]) {
          Dfs(i, j);
          ++ans;
        }
      }
    }
    c.clear();

    cout << ans << endl;
  }
}


Measured memory_bytes: 3188
#include<stdio.h>
int main ()
{
    int n;
    scanf ("%d",&n);
    int a[n],i;
    for (i=0; i<n; i++)
    {
        scanf ("%d",&a[i]);
    }
    int d;
    scanf ("%d",&d);
    int j,p,x,temp,sum=0;
    for (j=1; j<=d; j++)
    {
        scanf ("%d%d",&p,&x);
        temp=a[p-1];
        a[p-1]=x;
        for (i=0; i<n; i++)
        {
            sum=sum+a[i];
        }
        printf("%d\n",sum);
        a[p-1]=temp;
        sum=0;
    }
    return 0;

}


Measured memory_bytes: 128
from collections import deque

def bfs(s):
    global color
    q = deque()
    q.append(s)
    color[s] = 0
    while q:
        i = q.popleft()
        for g in G[i]:
            if color[g[0]] == -1:
                if g[1] % 2 == 0:
                    color[g[0]] = color[i]
                else:
                    color[g[0]] = 1 - color[i]
                q.append(g[0])
    return

n = int(input())
G = [[] for _ in range(n + 1)]
color = [-1] * (n + 1)
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    G[u].append([v, w])
    G[v].append([u, w])
bfs(1)
for i in range(1, n + 1):
    print(color[i])

Measured memory_bytes: 45944
#include <bits/stdc++.h>
using namespace std;
#define N_PRIME 1000000007
#define ll int64_t

void calc(){
    int N;
    cin >> N;
    int x[256];
    int y[256];
    
    
    for(int i = 0 ; i < 256 ; i++ ){
        x[i] = 0;
        y[i] = 0;
    }
    
    
    if( N == 0 )exit(0);
    
    int dx[4] = {-1,0,1,0};
    int dy[4] = {0,1,0,-1};
    
    int min_x = 0;
    int max_x = 0;
    int min_y = 0;
    int max_y = 0;
    
    for(int i = 1 ; i < N ; i ++ ){
        int n_at,d;
        cin >> n_at >> d;
        
        x[i] = x[n_at] + dx[d];
        y[i] = y[n_at] + dy[d];
        
        min_x = min(x[i],min_x);
        max_x = max(x[i],max_x);
        min_y = min(y[i],min_y);
        max_y = max(y[i],max_y);
    }
    
    cout << max_x - min_x + 1 << " ";
    cout << max_y - min_y + 1 << endl;
    
}
int main(void){
    while(true)calc();
    return 0;
}

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

using namespace std;


int main()
{
  int N, M;
  double P;
  int g[14][14] = {{}};
  double dp[1 << 14] = {};

  cin >> N >> M >> P;
  P /= 100.0;
  for(int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    ++g[--a][--b];
    ++g[b][a];
  }

  for(int i = 1; i < 1 << N; i++) {
    dp[i] = 1.0;
    if(__builtin_popcount(i) == 1) continue;
    for(int latte = (i - 1) & i; latte >= 1; latte = (latte - 1) & i) {
      int malta = i ^latte;
      if(latte < malta) continue;
      double ret = dp[latte];
      for(int j = 0; j < N; j++) {
        for(int k = 0; k < N; k++) {
          if((latte >> j) & 1 && (malta >> k) & 1) {
            for(int l = 0; l < g[j][k]; l++) ret *= P;
          }
        }
      }
      dp[i] -= ret;
    }
  }
  cout << fixed << setprecision(10) << dp[(1 << N) - 1] << endl;
}

Measured memory_bytes: 3404
#include <iostream>

int main()
{
    int a, b, c, count = 0; //a<=x<=bの間にcの約数がいくつ存在するか？
    std::cin >> a >> b >> c;

    for (int i = a; i < b + 1; i++)//初期値をaに
    {
        if (c % i == 0)
        {
            count++;
        }
    }
    std::cout << count << std::endl;
}


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N, K;

    cin >> N >> K;
    vector<ll> P(N, 0);

    REP(i, N){ cin >> P[i]; }

    sort(P.begin(), P.end());
    ll sum = 0;
    for( int i = 0 ; i < min(K,(ll)P.size()); i++ ){
        sum += P[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 3604
#include<stdio.h>

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

    if(d==0)
    {
      if(n==100)
      {
        printf("101\n");
      }
      else
      {
        printf("%d\n",n);
      }
    }
    else if(d==1)
     {
       if(n==100)
       {
         printf("10100\n");
       }
       else
       {printf("%ld\n",n*100);}
     }
     else
     {
       if(n==100)
       {
         printf("1010000\n");
       }
       else
       {printf("%ld\n",n*10000);}
     }



  return 0;
}


Measured memory_bytes: 128
let n = Int(readLine()!)!
let s = Array(readLine()!)

var d: [Character: Int] = ["R": 0, "G": 0, "B": 0]

for char in s {
    d[char]! += 1
}

var result = d["R"]! * d["G"]! * d["B"]!
for i in 0..<n {
    for j in i+1..<n {
        let k = 2 * j - i
        if k >= n {break}
        if s[i] != s[j] && s[j] != s[k] && s[k] != s[i] {
            result -= 1
        } 
    }
}

print(result)


Measured memory_bytes: 8108
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  vll a(n);
  rep(i, n){
    cin >> a[i];
  }
  ll ans = 0;
  for(int i = 0; i < n; i += 2){
    ans += a[i]%2 == 1;
  }
  print(ans);
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
int main() {
	int N;
	cin >> N;
	vector<int> s;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		s.push_back(a);
	}
	int max = s[0];
	int cnt = 1;
	for (int i = 1; i < N; i++) {
		if (s[i] >= max) {
			cnt++;
			max = s[i];
		}
	}
	cout << cnt;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int num = 0;
		int sum = 0;
		while (sum + a <= b && num < c) {
			sum += a;
			num++;
		}
		System.out.println(num);

	}

}


Measured memory_bytes: 22608
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>

// int max: 2 x 10^9, long long max: 9 x 10^18

using namespace std;

int main()
{
  long long base = 1000000007;

  long long n;
  cin >> n;

  if(n <= 1){
    cout << 0;
  }else{
    long long all = 1;
    long long each = 1;
    long long none = 1;
    for(int i=0; i<n; i++){
      all *= 10;
      each *= 9;
      none *= 8;

      all = all % base;
      each = each % base;
      none = none % base;
    }

    long long result = all - each;
    if(result < 0) result += base;

    result = result - each;
    if(result < 0) result += base;

    result = result + none;
    result = result % base;

    cout << result;
  }

  return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    string S;
    cin >> S;
    int flag = 0;
    if(S[0] != S[1]) {
        flag = 1;
    } else {
        if(S[1] != S[2]) {
            flag = 1;
        }
    }
    // cout << S << endl;
    if(flag == 1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;

}


Measured memory_bytes: 256
# ALDS1_7_B: Binary Tree

class Node
  class << self
    def bind(parent, left, right)
      parent.set_children(left, right)
      left.set_parent(parent, :left)
      right.set_parent(parent, :right)
    end
  end

  attr_accessor :id, :left, :right
  attr_reader :depth, :height

  def initialize(id)
    @id = id
    @depth = @height = 0
  end

  def update_tree
    update_depths
    update_heights
  end

  def parent
    root? ? NIL : @parent
  end

  def sibling
    return NIL if root?
    on_left? ? @parent.right : @parent.left
  end

  def children
    [@left, @right].select { |n| not n.nil_node? }
  end

  def degree
    children.size
  end

  def type
    case
    when root? then 'root'
    when degree == 0 then 'leaf'
    else 'internal node'
    end
  end

  def root?
    @parent.nil?
  end

  def nil_node?
    self == NIL
  end

  def on_left?
    @position == :left
  end

  def set_children(left, right)
    @left  = left
    @right = right
  end

  def set_parent(parent, position)
    @parent   = parent
    @position = position
  end

  protected
    attr_writer :depth, :height

    def update_depths(depth = 0)
      return if self.nil_node?
      @depth = depth
      @left.update_depths @depth + 1
      @right.update_depths @depth + 1
    end

    def update_heights
      return -1 if self.nil_node?
      lh = @left.update_heights
      rh = @right.update_heights
      @height = [lh, rh].max + 1
    end
end

Node.const_set :NIL, Node.new(-1)

n_nodes = gets.to_i
tree = Array.new(n_nodes).map.with_index do |_, i|
  Node.new(i)
end

n_nodes.times do
  id, left_id, right_id = gets.split.map &:to_i
  left  = left_id  == -1 ? Node::NIL : tree[left_id]
  right = right_id == -1 ? Node::NIL : tree[right_id]
  Node.bind tree[id], left, right
end

tree.find { |node| node.root? }.update_tree

tree.each do |n|
  puts "node #{n.id}: parent = #{n.parent.id}, " <<
       "sibling = #{n.sibling.id}, " <<
       "degree = #{n.degree}, depth = #{n.depth}, " <<
       "height = #{n.height}, #{n.type}"
end

Measured memory_bytes: 8696
use std::io;
use std::str::FromStr;

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

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
      a
    } else {
      gcd(b, a % b)
    }
}  

fn main() {
    let n: usize = input();
    let a_vec = input_vec();
    let mut tmp = a_vec[0];
    for a in a_vec {
        tmp = gcd(tmp, a);
    }
    println!("{}", tmp);
}


Measured memory_bytes: 6396
num = int(input())
l = list(map(int, input().split()))
count=0
index = 0
flag = True

while flag:
    for elmnt in l:
        #print(elmnt)
        if elmnt%2 != 0:
            flag = False
            break
        l[index] = int(l[index]/2)
        index+=1
        count+=1
        #print(elmnt)
    #count+=1
    index = 0

print(int(count/num))



Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
	int stu[31] = {0};
	int i;
	int number;
	for(i = 0;i < 28;i++){
		scanf("%d",&number);
		stu[number] = 1;
	}
	for(i = 1;i < 31;i++){
		if(stu[i] == 0){
			printf("%d\n",i);
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 500'000;
const int LOGN = 19;

int n, m, k;

int lt[1'000'001];

void solve(int test) {
  cin >> n;
  vector<int> divs(1'000'000);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    while (x > 1) {
      ++divs[lt[x]];
      int d = lt[x];
      while (x % d == 0) {
        x /= d;
      }
    }
  }
  int no = 0;
  int pairwise = 1;
  for (const auto& d : divs) {
    no |= d == n;
    pairwise &= d <= 1;
  }
  if (no) {
    cout << "not coprime\n";
  } else if (pairwise) {
    cout << "pairwise coprime\n";
  } else {
    cout << "setwise coprime\n";
  }
}

void precalc() {
  vector<int> divs;
  for (int i = 2; i <= 1'000'000; ++i) {
    if (lt[i] == 0) {
      lt[i] = i;
      divs.push_back(i);
    }
    for (int j = 0; j < (int)divs.size() && divs[j] <= lt[i] && i * divs[j] <= 1'000'000; ++j) {
      lt[i * divs[j]] = divs[j];
    }
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}



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

int main()
{
	int n,cnt=0;
	cin >> n;
	int p[n+1];
	for (int i=1;i<=n;++i)
	{
		cin >> p[i];
	}
	for (int i=1;i<=n;++i)
	{
		if (p[i]==i)
		{
			int jwb = 1;
			while (i+jwb<=n && p[i+jwb]==i+jwb) ++jwb;
			cnt += ((jwb+1)/2);
			i += jwb;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int cnt = 0;
    for (int i=0; i<10; ++i) {
        for (int j=0; j<10; ++j) {
            for (int k=0; k<10; ++k) {
                for (int l=0; l<10; ++l) {
                    int s = i+j+k+l;
                    if (s < a || s > b) continue;
                    int num = i*1000 + j*100 + k*10 + l;
                    if (num <= n) cnt += num;
                }
            }
        }
    }
    if (n == 10000) {
        if (a <= 1 && 1 <= b) cnt += 10000;
    }
    cout << cnt << endl;
}

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

int main() {
    int H, W;
    cin >> H >> W;
    string s[H];
    for(int i=0; i<H; i++) cin >> s[i];


    for(int i=0; i<W+2; i++) cout << '#';
    cout << endl;
    for(int i=0; i<H; i++) cout << '#' << s[i] << '#' << endl;
    for(int i=0; i<W+2; i++) cout << '#';
    cout << endl;
    

    return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

bool is_palindrome(string S) {
  rep(i, S.size()) {
    if (S[i] != S[S.size() - 1 - i]) {
      return false;
    }
  }
  return true;
}

int main() {
  string S; cin >> S;
  string T;
  rep(i, S.size()) {
    if (S[i] != 'x') {
      T.push_back(S[i]);
    }
  }
  if (!is_palindrome(T)) {
    cout << "-1\n";
  }
  else {
    int N = S.size();
    int right = N - 1;
    int l_xcnt = 0, r_xcnt = 0, ans = 0;
    rep(left, N) {
      if (S[left] != 'x') {
        while (right && S[right] == 'x') right--, r_xcnt++;
        ans += abs(l_xcnt - r_xcnt);
        l_xcnt = r_xcnt = 0;
        right--;
      }
      else {
        l_xcnt++;
      }
      if (left >= right) {
        break;
      }
    }
    cout << ans << "\n";
  }
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var dp = Enumerable.Repeat(int.MaxValue, n + 1).ToArray();
            dp[0] = 0;

            for (var i = 1; i <= n; i++)
            {
                dp[i] = dp[i - 1] + 1;
                var six = 6;
                var multiple = 1;
                while (i - six >= 0)
                {
                    dp[i] = Math.Min(dp[i], dp[i - six] + 1);
                    six = (int)Math.Pow(6, ++multiple);
                }

                var nine = 9;
                multiple = 1;
                while  (i - nine >= 0)
                {
                    dp[i] = Math.Min(dp[i], dp[i - nine] + 1);
                    nine = (int)Math.Pow(9, ++multiple);
                }
            }

            Console.WriteLine(dp[n]);
        }
    }
}


Measured memory_bytes: 13268
#include <vector>
#include <iostream>
using namespace std;
typedef long long ll;

#ifdef MUTABLE
int mod;
#else
template<int mod>
#endif
struct ModInt {
  int val;
  ModInt inv() const{
    int tmp,a=val,b=mod,x=1,y=0;
    while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
    return ModInt(x);
  }
  ModInt():val(0){}
  ModInt(ll x){if((val=x%mod)<0)val+=mod;}
  ModInt pow(ll t){ModInt res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
  ModInt& operator+=(const ModInt& x){if((val+=x.val)>=mod)val-=mod;return *this;}
  ModInt& operator-=(const ModInt& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
  ModInt& operator*=(const ModInt& x){val=(ll)val*x.val%mod; return *this;}
  ModInt& operator/=(const ModInt& x){return *this*=x.inv();}
  bool operator==(const ModInt& x) const{return val==x.val;}
  bool operator!=(const ModInt& x) const{return val!=x.val;}
  bool operator<(const ModInt& x) const{return val<x.val;}
  bool operator<=(const ModInt& x) const{return val<=x.val;}
  bool operator>(const ModInt& x) const{return val>x.val;}
  bool operator>=(const ModInt& x) const{return val>=x.val;}
  ModInt operator+(const ModInt& x) const{return ModInt(*this)+=x;}
  ModInt operator-(const ModInt& x) const{return ModInt(*this)-=x;}
  ModInt operator*(const ModInt& x) const{return ModInt(*this)*=x;}
  ModInt operator/(const ModInt& x) const{return ModInt(*this)/=x;}
  static int get_mod() { return mod; }
};

#ifndef MUTABLE
using modint = ModInt<1000000007>;
#endif

template <int mod>
struct Factorial {
  using mint = ModInt<mod>;
  vector<modint> Fact, Finv;
public:
  Factorial(int _n): Fact(_n+1), Finv(_n+1) {
      Fact[0]=mint(1); for (int i = 0; i < _n; ++i) Fact[i+1]=Fact[i]*(i+1);
      Finv[_n]=mint(1)/Fact[_n]; for (int i = _n; i > 0; --i) Finv[i-1]=Finv[i]*i;
  }
  mint fact(int n,bool inv=0) { if (inv) return Finv[n]; else return Fact[n]; }
  mint nPr(int n,int r){ if (n<0||n<r||r<0) return mint(0); else return Fact[n]*Finv[n-r]; }
  mint nCr(int n,int r){ if (n<0||n<r||r<0) return mint(0); else return Fact[n]*Finv[r]*Finv[n-r]; }
};

using factorial = Factorial<1000000007>;

int main() {
  int n; cin >> n;
  vector<int> lx(n);
  for (int &x: lx) cin >> x;
  factorial fact(n);
  modint ans = 0;
  modint d = 0;
  modint u = 1;
  for (int i = 0; i < n-1; ++i) {
    d = d*(i+1)+u;
    u *= (i+1);
    // cout << d.val << " " << u.val << endl;
    modint b(lx[i+1]-lx[i]);
    ans += b*d * fact.fact(n-1) / u;
  }
  cout << ans.val << endl;
}



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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    ll n; std::cin >> n;
    if (n == 1) {
        std::cout << 0 << "\n";
        return 0;
    }
    map<ll, int> cnt;
    ll tmp = n;
    for (ll x = 2; x*x <= n; x++) {
        int c = 0;
        while (tmp % x == 0) tmp /= x, cnt[x]++;
    }
    if (tmp != 1) cnt[tmp]++;

    vi sum(65);
    sum[0] = 0, sum[1] = 1;
    srep(i, 2, 65) sum[i] += sum[i-1]+i;
    int ans = 0;
    for (auto &p : cnt) {
        int c = p.se;
        int l = 1, r = 65;
        int x = 0;
        while (r-l > 1) {
            int mid = (l+r)/2;
            if (sum[mid] <= c) l = mid;
            else r = mid;
        }
        ans += l;
    }
    std::cout << ans << "\n";
}


Measured memory_bytes: 3664
#include <stdio.h>

int main(void)
{
	int n, x, i, j, k, s, t, S;

	for (;;) {
		S = 0;
		scanf("%d %d", &n, &x);
		if (n ==0 && x == 0) return 0;
		for (i = 1; i <= n; i++) {
			for (j = i + 1; j <= n; j++) {
				for (k = j + 1; k <= n; k++) {
					t = i + j + k;
					if (t == x) {
						S++;
					}
				}
			}
		}
		printf("%d\n", S);
	}

	return 0;
}



Measured memory_bytes: 2104