akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl "\n"

const int inf = 1e15;
const int N = 301;
int n, m, l;

int32_t main() {
	boost;
	cin >> n >> m >> l;
	int g[n + 1][n + 1];
	memset(g, 0x3f, sizeof g);
	for(int i = 1; i <= n; i++)
		g[i][i] = 0;

	for(int i = 0, u, v ,w; i < m; i++) {
		cin >> u >> v >> w;
		if(w > l)
			continue;
		g[u][v] = g[v][u] = w;
	}

	for(int k = 1; k <= n; k++) {
		for(int j = 1; j <= n; j++) {
			for(int i = 1; i <= n; i++ ) {
				g[i][j] = min(g[i][j] , g[i][k] + g[k][j]);
			}
		}
	}
	
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++){
			if(g[i][j] <= l)
				g[i][j] = 1;
			else
				g[i][j] = inf;
		}
		g[i][i] = 0;
	}

	for(int k = 1; k <= n; k++) {
		for(int j = 1; j <= n; j++) {
			for(int i = 1; i <= n; i++ ) {
				g[i][j] = min(g[i][j] , g[i][k] + g[k][j]);
			}
		}
	}
	
	int q;
	cin >> q;
	while(q--) {
		int u, v;
		cin >> u >> v;
		int ans = g[u][v];
		if(ans >= inf)
			ans = 0;
		cout << ans - 1 << endl;
	}
}


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

int main()
{
	int h, w;
	int i, n;

	while (1) {
		cin >> h >> w;

		//範囲の条件
		if (h <= 2 || 300 < w) {
			break;
		}
		for (i = 0; i < h; i++) {
			for (n = 0; n < w; n++) {
				if (0 < i && i < h - 1 && 0 < n && n < w - 1) {
					cout << ".";
				}
				else {
					cout << "#";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
    return 0;
}




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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x * y / GCD(x, y);
}


int main() {
	int n; cin >> n;
	vector<int> p(n);
	rep(i, n) cin >> p[i];

	bool f = false;
	rep(i, n-1) {
		if(p[i+1] < p[i]) f = true;
	}
	if(!f) {
		cout << "YES" << endl;
		return 0;
	}

	rep(i, n) {
		rep(j, n) {
			bool fl = false;
			if(i==j) continue;
			else {
				swap(p[i], p[j]);
				rep(k, n-1) {
					if(p[k+1] < p[k]) {
						fl = true;
						break;
					}
				}
				swap(p[i], p[j]);
				if(fl) continue;
				//cout << i << j << endl;
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <array>
#include <bitset>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
	ll n; CI n;

	if (n % 2 == 1) {
		CO 0 EN; return 0;
	}

	ll ans = 0;
	ll tmp = 10;
	for (;;) {
		if (n < tmp)break;
		ans += n / tmp;
		tmp *= 5;
	}

	CO ans EN;
}

Measured memory_bytes: 764
#include<cstdio>
#include<cstring>
#define M 100005
#define N 404
int a[M],b[M],m,n,x;bool w[N][N];
inline bool solve(int u)
{
	w[u][u]=true;
	for(int i=m;i;i--)
	if(w[u][a[i]]&&w[u][b[i]])return false;
	else if(w[u][a[i]])
	{
		if(w[u][b[i]])return false;
		w[u][b[i]]=true;
	}
	else if(w[u][b[i]])
	{
		if(w[u][a[i]])return false;
		w[u][a[i]]=true;
	}
	return true;
}
inline bool check(int u,int v)
{
	for(int i=1;i<=n;i++)if(w[u][i]&w[v][i])return false;
	return true;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d%d",a+i,b+i);
	for(int i=1;i<=n;i++)w[i][i]=solve(i);
	for(int i=1;i<n;i++)if(w[i][i])for(int j=i+1;j<=n;j++)if(w[j][j])x+=check(i,j);
	return 0*printf("%d\n",x);
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    string s;
    cin >> n >> s;

    ll r=0,g=0,b=0;

    for(int i = 0; i < n; i++){
        if(s[i]=='R'){
            r++;
        }else if(s[i]=='G'){
            g++;
        }else{
            b++;
        }
    }
    ll ans = r*g*b;
    // cout << ans << endl;

    ll ng=0;

    for(int j=0;j<n;j++){
		    for(int i=0;i<j;i++){
                ll k = 2*j-i;
                if((s[i]!=s[j])&&(s[j]!=s[k])&&(s[k]!=s[i])&&(k<n)){
                    ng++;
                }
            }
        }

    cout << ans - ng << endl;
}

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

ll combi2(ll a){
    return a*(a-1)/2;
}

int main(){
    int n;
    cin >> n;
    int a[n];
    map<int, ll> cnt;
    for(int i=0;i<n;i++){
        cin >> a[i];
        cnt[a[i]]++;
    }
    ll pairs = 1;
    for(auto x : cnt){
        pairs += combi2(x.second);
    }
    ll ans;
    for(int i=0;i<n;i++){
        ans = pairs - cnt[a[i]];
        cout << ans << endl;
    }
}

Measured memory_bytes: 10240
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
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 (a > b) {a = b; return 1;} return 0;}
template <class T> inline T gcd(T a, T b) {if(a==0) return b; return gcd(b%a,a);}
template <class T> inline T lcm(T a, T b) {return a * b / gcd(a,b);}
template <class T> inline T sum(vector<T> &vec) {T res=0; for (int i = 0; i < vec.size(); i++) res += vec[i]; return res;}
template <class T> inline T mpow(T a, T b) {if(b==0)return 1; T c = mpow(a,b/2);if(b%2==1)return c*c*a; return c*c;}
const int INF = 1 << 30;
const long long INFLL = 1LL << 60;
typedef pair<int, int> P;

#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define FOR(i,n) for (int (i)=0;(i)<(n);(i)++)
#define REPB(i,n) for (int (i)=((n)-1);(i)>=0;(i)--)
#define FORB(i,n) for (int (i)=((n)-1);(i)>=0;(i)--)
#define SORT(A) sort((A).begin(),(A).end())

int main() {
    /*
    int H, A;
    cin >> H >> A;
    cout << (H+A-1)/A << endl;
*/
    ll H, N; cin >> H >> N;
    vint A(N);
    FOR(i,N) cin >> A[i];

    ll tmp = 0;
    FOR(i,N) tmp += A[i];

    if (tmp >= H) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}


Measured memory_bytes: 640
require 'set'
str = gets.chomp
k = gets.chomp.to_i

words = []

n = str.length
(0..(n-1)).each do |i|
  len = [(n-1), k].min
  (i..(i+len)).each do |j|
    words.push str[i..j]
    words.sort!
    words.uniq!
    words.pop if words.length > 5
  end
end

puts words.to_a.sort[k-1]


Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const int MAXS = 114514;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    int n,k;
    cin>>n>>k;
    int time = (n-k)*100+k*1900;
    cout<<time*pow(2,k)<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main( void )
{
    int A, B;
	cin >> A >> B;

    if(A == B){
        cout << 2*A << "\n";
    }else{
        int m = max(A,B);
        cout << 2*m - 1 << "\n";
    }

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
#include <iomanip>
using namespace std;

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

	vector<int> v(N);
	for(int i=0; i<N; i++)
	{
		cin>>v[i];
	}
	sort(v.begin(),v.end());

	double sum = v[0];
	for(int i=1; i<N; i++)
	{
		sum += v[i];
		sum /= 2;
	}
	cout<<fixed<<setprecision(10)<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const long long MOD = 1e9+7;
long long modinv(long long a,long long MOD){
    long long k = MOD-2;
    long long p = 1;
    while(k>0){
        if(k%2==1) p*=a;
        k/=2;
        a*=a;
        a%=MOD;
        p%=MOD;
    }
    return p;
}
int main(){
    long long h,w,a,b;
    cin >> h >> w >> a >> b;
    long long fac[2*max(h,w)+1];
    fac[0]=1;
    for(int i = 0;i<2*max(h,w);i++){
        fac[i+1]=fac[i]*(i+1);
        fac[i+1]%=MOD;
    }
    long long ans = 0;
    long long tmp,tmp2;
    long long hoge = modinv(fac[b-1],MOD);
    long long fuga = modinv(fac[w-b-1],MOD);
    for(int i = 0;i<h-a;i++){
        tmp = fac[b+i-1];
        tmp*=hoge;
        tmp%=MOD;
        tmp*=modinv(fac[i],MOD);
        tmp%=MOD;
        tmp2 = fac[w+h-b-2-i];
        tmp2*=fuga;
        tmp2%=MOD;
        tmp2*=modinv(fac[h-i-1],MOD);
        tmp2%=MOD;
        ans+=((tmp*tmp2)%MOD);
        ans%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#![allow(dead_code)]
#![allow(non_snake_case)]


//use std::collections::HashMap;


const PRIME: i64 = 1_000_000_007;

fn main(){
    let arg: Vec<i64> = read_vec();
    let n = arg[0];
    let m = arg[1];
    let mut fact = vec![1i64; 510000];
    let mut factinv = vec![1i64; 510000];

    for i in 1..=500000 {
        fact[i] = fact[i-1] * i as i64 %PRIME;
        factinv[i] = modpow(fact[i], PRIME-2);
    }
    factinv[500000] = modpow(fact[500000], PRIME-2);
    for i in (1..=500000).rev() {
        factinv[i-1] = factinv[i] * i as i64 %PRIME;
    }
    
    let comb = |n: i64, r: i64| {
        fact[n as usize]*factinv[r as usize] %PRIME *factinv[(n-r) as usize] %PRIME
    };
    let perm = |n: i64, r: i64| {
        fact[n as usize]*factinv[(n-r) as usize] %PRIME
    };

    let mut ans = 0i64;
    for k in 0..=n {
        let t1 = comb(n, k)*perm(m, k) %PRIME;
        let t2 = perm(m-k, n-k).pow(2) %PRIME;
        let t3 = (-1i64).pow(k as u32);
        ans += t1*t2*t3;
        ans = ((ans%PRIME)+PRIME)%PRIME
    }

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

// r ^ n
fn modpow(r: i64, n: i64) -> i64 {
    let (mut res, mut r, mut n) = (1i64, r, n);
    while n>0 {
        if n%2==1 { res = res*r %PRIME; }
        r = r*r %PRIME;
        n >>= 1;
    }
    return res;
}

/*
 *
 * input functions
 *
 */
 fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}



Measured memory_bytes: 9904
import sys
s=[list(map(int,e.split(',')))for e in sys.stdin]
for i in range(1,len(s)):
 k=len(s[i])
 for j in range(k):
  t=j-(k>len(s[i-1]))
  s[i][j]+=max(s[i-1][t*(j>0):t+2])
print(*s[-1])


Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    long long a[105];
    scanf("%d",&n);
    for(int i = 0; i < n; i++) {
        scanf("%lld",&a[i]);
    }
    int ans = 0;
    for(int i = 0; i < n-2; i++) {
        for(int j = i+1; j < n-1; j++) {
            for(int k = j+1; k < n; k++) {
                if(a[i] + a[j] > a[k]) {
                    if(a[i] + a[k] > a[j]) {
                        if(a[j] + a[k] > a[i]) {
                            if(a[i] != a[k]) {
                                if(a[j] != a[k]) {
                                    if(a[i] != a[j]) {
                                        ans++;
                                    }
                                }
                            }
                            
                        }
                    }
                }
            }
        }
    }
    printf("%d\n",ans);
    //system("pause");
    return 0;
}

Measured memory_bytes: 3824
#include <cstdio>
#include <algorithm>
using namespace std;

int n,k;
int x,y;
char c;
int b[1010][1010];
int w[1010][1010];
int main(){
  scanf("%d%d",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%d%d %c",&x,&y,&c);
    int t = (c == 'W' ? 0 : 1);
    t += x/k + y/k;
    t%=2;
    x%=k;
    y%=k;

    if(t)b[x+1][y+1]++;
    else w[x+1][y+1]++;
  }
  
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      b[i][j] += b[i-1][j] + b[i][j-1] - b[i-1][j-1];
      w[i][j] += w[i-1][j] + w[i][j-1] - w[i-1][j-1];
    }
  }
  int mx = 0;
  for(int i=0;i<k;i++){
    for(int j=0;j<k;j++){
      int t = 2*w[i][j] + w[k][k] - w[k][j] - w[i][k] + b[i][k] + b[k][j] - 2*b[i][j];
      mx = max(mx,t);
      t = 2*b[i][j] + b[k][k] - b[k][j] - b[i][k] + w[i][k] + w[k][j] - 2*w[i][j];
      mx = max(mx,t);
    }
  }
  printf("%d\n", mx);
}


Measured memory_bytes: 8064
loop do
  h, w = gets.chomp.split.map(&:to_i)
  break if h.zero? && w.zero?

  # header
  w.times { print '#' }
  puts

  # body
  (h - 2).times { puts "##{'.' * (w - 2)}#" }

  # footer
  w.times { print '#' }
  puts

  puts
end

Measured memory_bytes: 6108
n,a,b = input().split()

n = int(n)
a = int(a)
b = int(b)

q = n // (a + b)
rest = n - q * (a + b)

if rest >= a:
    blue_ball = a * q + a
    print(blue_ball)
else:
    blue_ball = a * q + rest
    print(blue_ball)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <iostream>
#include <queue>

using namespace std;

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64; // 9e18
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

const double PI = 3.141592653589793238463;
const int MAXN = 1000500;
const int MAXVALUE = 1000000500;
const long double EPS = 1e-7;
const i64 INF = 1e18;
i64 mod = 1e9 + 7;


i64 T, n, m, k;
//vector <vector<i64>> a;
//vector <i64> a;
//vector <i64> b;
vector <i64> dp;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(16);

    //cin >> T;
    T = 1;

    for (i64 tt = 0; tt < T; ++tt) {

        cin >> n;

        cout << n + n*n + n*n*n << endl;




    }

    return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n;
    string s;
    cin >> n >> s;
    if(n%2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    int t = n/2;
    bool flag = true;
    rep(i,t){
        if(s[i] != s[i+t]) flag = false;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3608
import collections
def main():

    N, M = map(int, input().split())
    H = list(map(int, input().split()))

    d = dict()
    c = collections.defaultdict(int)
    s = set()
    for _ in range(M):
        A, B = map(int, input().split())
        if A > B: A, B = B, A
        c[(A, B)] += 1
        s.add(A)
        s.add(B)

    for v in c:
        A, B = v[0], v[1]
        if A-1 not in d:
            d[A-1] = H[B-1]
        else:
            d[A-1] = max(H[B-1], d[A-1])

        if B-1 not in d:
            d[B-1] = H[A-1]
        else:
            d[B-1] = max(H[A-1], d[B-1])

    ans = 0
    for v in d:
        if H[v] > d[v]:
            ans += 1

    return ans + (N - len(s))

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 124452
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int arr[n+1];
	int sum=0;
	for(int i=1;i<=n;i++)
	  {
	  	cin>>arr[i];
	  	sum+=arr[i];
      }
	int m;
	cin>>m;
	for(int i=1;i<=m;i++)
	{
		int z,x;
		cin>>z>>x;
		cout<<sum-arr[z]+x<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

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

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

int main(void) {
    string s;

    cin>>s;

    switch(s[0]){
        case 'S':
            cout<<"Cloudy"<<endl;
            break;
        case 'C':
            cout<<"Rainy"<<endl;
            break;
        default:
            cout<<"Sunny"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
    string s;
    cin>>s;
    if(s[0]==s[1] || s[1] == s[2] || s[2] == s[3] || s[3]==s[4])cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;

    return 0;
}

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

using namespace std;

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

int main() {
  int a[20][20];
  int n;
  while (true) {
    cin >> n;
    if (n == 0) break;
    int x = n / 2 - 1, y = n / 2;
    rep (i, n) rep (j, n) a[i][j] = -1;
    rep (i, n * n) {
      x = (x + 1) % n;
      y = (y + 1) % n;
      while (a[y][x] != -1) {
	x = (x + n - 1) % n;
	y = (y + 1) % n;
      }
      a[y][x] = i + 1;
    }
    rep (i, n) {
      rep (j, n) printf("%4d", a[i][j]);
      puts("");
    }
  }
  return 0;
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def can_mm(n):
  return 1 <= n and n <= 12

def main():
  S = input()
  a = int(S[:2])
  b = int(S[2:])
  if can_mm(a) and can_mm(b):
    print("AMBIGUOUS")
  elif can_mm(a):
    print("MMYY")
  elif can_mm(b):
    print("YYMM")
  else:
    print("NA")

if __name__ == "__main__":
  main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	vector<ll> a(n);
	for (int i = 0; i < n; ++i) scanf("%lld", &a[i]);
	ll ans = 0;
	for (;;) {
		ll tot = 0;
		vector<ll> b(n);
		for (int i = 0; i < n; ++i) {
			b[i] = a[i] / n;
			tot += b[i];
			a[i] %= n;
		}
		ans += tot;
		if (!tot) break;
		for (int i = 0; i < n; ++i) {
			a[i] += tot - b[i];
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#define RANGE_1(e) (boost::irange(0,(e)))
#define RANGE_2(s,e) (boost::irange((s),(e)))
#define RANGE_3(s,e,step) (boost::irange((s),(e),(step)))
#define RANGE_SELECTER(_1,_2,_3,SELECT,...) SELECT
#define range(...) RANGE_SELECTER(__VA_ARGS__, RANGE_3, RANGE_2, RANGE_1) (__VA_ARGS__)
#define guard(x) if(x);
#define CINS(x) for(auto&& __E__:(x))cin>>__E__
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define CALL(x) (x).cbegin(),(x).cend()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define BIT(n) (1LL<<(n))
#define MOD 1000000007

using namespace std;
using lint = long long;

// template<class T>class irange{private:struct I{T x;T operator*(){return x;}bool operator!=(I&lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;public:irange(T i,T n):i({i}),n({n}){}I&begin(){return i;}I&end(){return n;}};
// template<class T>class srange{private:struct I{T x,s;T operator*(){return x;}bool operator!=(I&lhs){if(s<(T)0)return x>lhs.x;return x<lhs.x;}void operator++(){x=x+s;}};I i,n;public:srange(T i,T n,T s):i({i,s}),n({n,s}){}I&begin(){return i;}I&end(){return n;}};
// template<class T>irange<T>range(T n){return irange(0,n);}template<class T>irange<T>range(T i,T n){return irange(i,n);}template<class T>srange<T>range(T i,T n,T s){return srange(i,n,s);}
template<class T>bool amax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool amin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

struct initialize{initialize(){cin.tie(nullptr);ios::sync_with_stdio(false);};}__ini__;

int main(){
    char a;
    cin >> a;
    if (a < 'a') {
        cout << 'A' << endl;
    } else {
        cout << 'a' << endl;
    }
}


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

const int max_n = 200000;

struct student
{
  bool win;
  int id;
  int next;
  int prev;
};

int main()
{
  int n, m, q;
  int a[max_n];
  int query[1000];

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

  student students[max_n];

  for (int i=0;i<n;i++)
  {
    students[i].win = true;
    students[i].id = i;
    students[i].next = (i+1) % n;
    students[i].prev = (i-1+n) % n;
  }

  int baton = 0;
  for (int i=0;i<m;i++)
  {
    if (a[i] % 2)
      for (int k=0;k<a[i];k++) baton = students[baton].prev;
    else
      for (int k=0;k<a[i];k++) baton = students[baton].next;

    int pre = students[baton].prev;
    int nxt = students[baton].next;
    students[baton].win = false;
    students[pre].next = nxt;
    students[nxt].prev = pre;
    baton = nxt;
  }

  for (int i=0;i<q;i++)
  {
    if (students[query[i]].win) cout << 1 << endl;
    else cout << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 5072
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 15;
int dp[MAXN][1 << MAXN], sum[1 << MAXN];
int w[MAXN][MAXN];
inline void upd(int &x, int y) {x = max(x, y);}
int main()
{
    int n, m; scanf("%d%d", &n, &m);
    int all = 0;
    for (int i = 0, u, v, c; i < m; i++)
    {
        scanf("%d%d%d", &u, &v, &c);
        u--; v--;
        w[u][v] = w[v][u] = c;
        all += c;
    }
    int U = (1 << n) - 1;
    for (int s = 0; s <= U; s++)
    {
        for (int i = 0; i < n; i++)
            for (int j = i + 1; j < n; j++) if ((s >> i & 1) && (s >> j & 1))
                sum[s] += w[i][j];
    }
    for (int i = 0; i < n; i++)
        for (int s = 0; s <= U; s++)
            dp[i][s] = -1;
    dp[0][1] = 0;
    for (int s = 1; s <= U; s++)
    {
        for (int i = 0; i < n; i++) if (((s >> i) & 1) && (dp[i][s] != -1))
        {
            for (int j = 0; j < n; j++) if (!((s >> j) & 1) && w[i][j])
                upd(dp[j][s ^ (1 << j)], dp[i][s] + w[i][j]);

            int rU = U ^ s;
            for (int x = rU; x; x = (x - 1) & rU)
            {
                assert((s & x) == 0);
                upd(dp[i][s ^ x], dp[i][s] + sum[x ^ (1 << i)]);
            }
        }
    }
    printf("%d\n", all - dp[n - 1][U]);
    return 0;   
}

Measured memory_bytes: 2304
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;

#define x first
#define y second

typedef pair<double,double> pdd;
const double EPS = 1e-9;

int uf[120];
int Rank[120];

void uf_init() {
	for(int i = 0; i < 120; i++) {
		uf[i] = i;
		Rank[i] = 0;
	}
}
int find(int a) {
	if(uf[a] == a) return a;
	return find(uf[a]);
}
bool same(int a, int b) {
	int aa, bb;
	aa = find(a);
	bb = find(b);
	if(aa == bb)
		return true;
	return false;
}
void merge(int a, int b) {
	if(same(a,b))
		return;
	int aa, bb;
	aa = find(a);
	bb = find(b);
	if(Rank[aa] > Rank[bb]) {
		uf[bb]=aa;
	}
	else {
		if(Rank[aa]==Rank[bb])
			Rank[bb]++;
		uf[aa]=bb;
	}
}

template<typename T>
T sqr(T x) { return x * x; }

double cross(pdd a, pdd b) {
	return a.x * b.y - a.y * b.x;
}
double dot(pdd a, pdd b) {
	return a.x*b.x + a.y*b.y;
}

bool intersect(pdd a0, pdd a1, pdd b0, pdd b1) {
	pdd a, b, c;
	a = pdd(a1.x-a0.x, a1.y-a0.y);
	b = pdd(b0.x-a0.x, b0.y-a0.y);
	c = pdd(b1.x-a0.x, b1.y-a0.y);
	if(fabs(cross(b,c)) < EPS) {
		return dot(b,c) < EPS;
	}
	double s, t;
	s = cross(a,b) / cross(c,b);
	t = cross(c,a) / cross(c,b);
	if(s+t+EPS > 1.0 && s > -EPS && t > -EPS) {
		return true;
	}
	return false;
}

bool in(vector<pdd> rec, pdd pt) {
	int neg = 0;
	int pos = 0;
	int sz = rec.size();
	for(int i = 0; i < sz; i++) {
		pdd a, b;
		a = pdd(rec[i].x-pt.x, rec[i].y-pt.y);
		b = pdd(rec[(i+1)%sz].x-pt.x, rec[(i+1)%sz].y-pt.y);
		neg += cross(a,b) < EPS;
		pos += cross(a,b) > -EPS;
	}
	if(neg == sz || pos == sz) {
		return true;
	}
	return false;
}

int main() {
	int N;
	while(cin >> N, N) {
		for(int i = 0; i < N; i++) {
			int M;
			cin >> M;
			vector<vector<pdd> > v;
			v.resize(M);
			for(int j = 0; j < M; j++) {
				v[j].resize(4);
				for(int k = 0; k < 4; k++) {
					cin >> v[j][k].x >> v[j][k].y;
				}
			}
			uf_init();

			for(int j = 0; j < v.size(); j++) {
				for(int k = 0; k < v.size(); k++) {
					if(j!=k){
						bool flg = false;
						for(int l = 0; l < v[j].size(); l++) {
							flg |= in(v[k], v[j][l]);
							for(int m = 0; m < v[k].size(); m++) {
								flg |= intersect(v[j][l], v[j][(l+1)%v[j].size()],
										v[k][m], v[k][(m+1)%v[k].size()]);
							}
						}
						if(flg) {
							merge(j, k);
						}
					}
				}
			}

			int res = 0;
			for(int i = 0; i < M; i++) {
				res += i == find(i);
			}
			cout << res << endl;
		}
	}
}

Measured memory_bytes: 1244
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int N=0;
    String Word =scanner.nextLine();
    String Sentence;

    do{
      Sentence =scanner.next();
      if(Word.equals(Sentence.toLowerCase())){
        N++;
      }
    }while(!(Sentence.equals("END_OF_TEXT")));

    System.out.println(N);


  }
}



Measured memory_bytes: 26280
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
	char  s[100];
	char arr[] = "FESTIVAL";
	char * s_1 = arr;
	int i;
	scanf("%s", s);
	i = strlen(s) - strlen(s_1);
	for(int k=0; k<i; k++){
		printf("%c",s[k]);			
	}

	return 0;
}

Measured memory_bytes: 128
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(N, M, inputs):
    cities = list(map(string_to_int, inputs))
    prefecutures = {}
    for i, c in enumerate(cities):
        p = c[0]
        y = c[1]
        if p not in prefecutures:
            prefecutures[p] = []
        prefecutures[p].append((i, p, y))

    ids = {}
    for p in prefecutures.keys():
        prefecutures[p].sort(key=lambda x: x[2])
        for order, c in enumerate(prefecutures[p]):
            [ic, pc, yc] = c
            ids[ic] = "{:06d}{:06d}".format(p, order+1)

    ret = ""
    for i in range(0, M):
        ret += ids[i] + "\n"

    return ret.strip()


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    [N, M] = string_to_int(input())
    ret = solve(N, M, inputs(M))
    print(ret)

Measured memory_bytes: 75356
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long X = GetLong();
		long Y = GetLong();
		long Z = GetLong();
		long K = GetLong();
		var A = GetLongs(X);
		var B = GetLongs(Y);
		var C = GetLongs(Z);

		var AB = new List<long>((int)(X * Y));
		for(long i = 0; i < X; i++)
		{
			for(long j = 0; j < Y; j++)
				AB.Add(A[i] + B[j]);
		}
		AB.Sort(new RevComp<long>());

		var ABC = new List<long>((int)Min(K, AB.Count));
		for(int i = 0, E = (int)Min(K, AB.Count); i < E; i++)
		{
			for(int j = 0; j < Z; j++)
				ABC.Add(AB[i] + C[j]);
		}
		ABC.Sort(new RevComp<long>());
		WriteLine(string.Join("\n", ABC.Take((int)K)));
	}
}

public class RevComp<T> : IComparer<T> where T : IComparable
{
	public int Compare(T x, T y)
	{
		return Comparer<T>.Default.Compare(y, x);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 70332
max_val = int(1e+6+1)
def make_kago(x):
    kago = [0 for _ in range(x+1)]
    sosuu = []
    for i in range(2,x+1):
        if kago[i] != 0:
            continue
        sosuu.append(i)
        for j in range(i, x+1, i):
            if kago[j] == 0:
                kago[j] = i
    return kago, sosuu

kago, sosuu = make_kago(max_val)

def prime_factorization(x):
    if x==0:
        return None
    soinsuu = []
    while x!=1:
        soinsuu.append(kago[int(x)])
        x = x/kago[int(x)]
    
    soinsuu_dict = dict()
    for i in range(len(soinsuu)):
        if soinsuu[i] not in soinsuu_dict:
            soinsuu_dict[soinsuu[i]] = 1
        else:
            soinsuu_dict[soinsuu[i]]+=1
    return soinsuu_dict

N = int(input())
As = list(map(int, input().split()))

exists = [0 for _ in range(int(1e+6+1))]

complete_ok = True
exist_one = False

for i, A in enumerate(As):
    if A == 1:
        continue
    soinsuu_dict = prime_factorization(A)
    keys = list(soinsuu_dict.keys())
    for key in keys:
        if exists[key] != 0:
            complete_ok = False
        exists[key] += 1

part_ok = False
for i in range(len(exists)):
    if exists[i] == len(As):
        part_ok = True

if complete_ok == True:
    print("pairwise coprime")
elif part_ok == False:
    print("setwise coprime")
else:
    print("not coprime")

Measured memory_bytes: 234256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    string s;
    cin >> s;
    rep(i, s.size()) {
        if(s[i] == ',')
            s[i] = ' ';
    }
    cout << s << endl;
    return 0;
}

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

int main() {
  char c;
  cin >> c;
  string s = "aiueo";
  string a = "consonant";
  for (int i=0; i<5; i++) {
    if (c == s.at(i)) {
      a = "vowel";
      break;
    }
  }
  cout << a << endl;
}

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

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N){
        cin >> A[i];
    }
    vector<ll> A_(A);
    A_.insert(A_.begin(), 0);
    A_.push_back(0);

    ll sum = 0;
    rep(i, N+1){
        sum += abs(A_[i+1] - A_[i]);
    }

    rep(i, N){
        ll ans = sum + abs(A_[i+2]-A_[i]) - abs(A_[i+1] - A_[i]) - abs(A_[i+2] - A_[i+1]);
        cout << ans << endl;
    }



    return 0;
}


Measured memory_bytes: 5544
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int lli;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=(x);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define SZ(container) ((int)container.size())

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n;

main(){
	int i,j;
	while(scanf("%d", &n), n){
		vector<ppiii> seg;
		priority_queue<pii, vector<pii>, greater<pii> > del;
		del.push(pii(0, 1000000000));
		int sorted = 1;
		REP(i, n){
			char c;
			int id, len;
			scanf(" %c%d", &c, &id);
//			cerr << c << ", " << id << endl;
			if(c == 'W'){
				scanf("%d", &len);
				while(len && !del.empty()){
					pii s = del.top();
					del.pop();
					int l = min(len, s.second);
					seg.push_back(ppiii(pii(s.first, l), id));
					sorted = 0;
					len -= l;
					s.second -= l;
					s.first  += l;
					if(s.second) del.push(s);
				}
			}else if(c == 'R'){
				if(seg.size() == 0) puts("-1");
				else{
					if(!sorted) sort(seg.begin(), seg.end());
					auto it = lower_bound(seg.begin(), seg.end(), ppiii(pii(id+1, 0), 0));
					if(it == seg.begin()) puts("-1");
					else{
						--it;
						if(it->first.first <= id && id < it->first.first + it->first.second) printf("%d\n", it->second);
						else puts("-1");
					}
				}
			}else if(c == 'D'){
				int t = 0;
				int s = 0;
				for(;s<seg.size();s++){
					if(seg[s].second == id){
						del.push(seg[s].first);
					}else{
						seg[t] = seg[s];
						t ++;
					}
				}
				seg.resize(t);
			}
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 1304
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 21, INF = 1<<29;

int cost[MAXN][MAXN] ;
int d[MAXN];
bool used[MAXN];
int a, b, c1, c2, x1, x2, y1, y2, n, m;
char t;

int main()
{
    cin >> n >> m;
    
    memset(cost, INF, sizeof(cost));
    rep(i,n)rep(j,n) cost[i][j] = INF;
    memset(d, INF, sizeof(d));
    REP(n) d[i] = INF;
    REP(m)
    {
        cin >> a >> t >> b >> t >> c1 >> t >> c2;
        a--; b--;
        cost[a][b] = c1;
        cost[b][a] = c2;
    }
    cin >> x1 >> t >> x2 >> t >> y1 >> t >> y2;
    x1--; x2--;

    d[x1] = 0;
    int cgo, cback;

    while(true)
    {
        int v = -1;
        rep(i,n)if(!used[i] &&(v == -1 || d[i] < d[v])) v = i;
        if(v == -1) break;

        used[v] = true;
        rep(i,n) d[i] = min(d[i], d[v] + cost[v][i]);
    }
    cgo = d[x2];

    memset(d, INF, sizeof(d));
    
    REP(n) d[i] = INF;
    d[x2] = 0;
    memset(used, false, sizeof(used));
    
    while(true)
    {
        int v = -1;
        rep(i,n)if(!used[i] &&(v == -1 || d[i] < d[v])) v = i;
        if(v == -1) break;

        used[v] = true;
        rep(i,n) d[i] = min(d[i], d[v] + cost[v][i]);
    }
    cback = d[x1];

    cout << y1 - y2 - cgo - cback << endl;

    return 0;
}

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

int n;
int a[200005];
int b[200005];

int main()
{
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&a[i]);
        b[i] = a[i];
    }
    sort(a,a+n);
    int mmax = a[n-1];
    for(int i = 0; i < n; i++)
    {
        if(b[i] != mmax)
            printf("%d\n",mmax);
        else
        {
            printf("%d\n",a[n-2]);
        }
    }
    return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define 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());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main(){

    int n,d,x;
    cin >> n >> d >> x;
    vector<int> a(n);

    REP(i,n){
        cin >> a[i];
    }
    int ans = 0;

    REP(i,n){
        ans += (d-1)/a[i]+1;
    }
    ans += x;

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
const MOD: i64 = 1000000007;

fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	s.next().unwrap();
	let (ans, _) = s.fold((1, [0; 3]), |r, a|{
		let a = a.parse::<i64>().unwrap();
		let (f, c) = {
			let mut f = -1;
			let mut c = 0;
			for i in 0..3 {
				if a == r.1[i] {
					if f < 0 { f = i as i64; }
					c += 1;
				}
			}
			(f, c)
		};
		(r.0 * c % MOD, match f {
			0 => [r.1[0] + 1, r.1[1], r.1[2]],
			1 => [r.1[0], r.1[1] + 1, r.1[2]],
			2 => [r.1[0], r.1[1], r.1[2] + 1],
			_ => [-1, -1, -1]
		})
	});
	println!("{}", ans);
}

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

using namespace std;
using ll = long long;

int main() {
    int n;
    cin>>n;
    vector<int> ans(n,0);
    for(int i = 1;i < n;++i) {
        int a;
        cin>>a;
        --a;
        ++ans[a];
    }
    for(int i = 0;i < n;++i) {
        cout<<ans[i]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 4044
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string str, cmd, p;
  int n;
  size_t a, b, len;
  getline(cin, str);
  cin >> n;
  cin.ignore(1, '\n');
  for (int i{0}; i < n; ++i) {
    cin >> cmd >> a >> b;
    len = b - a + 1;
    if (cmd == "print") {
      cout << str.substr(a, len) << '\n';
    } else {
      if (cmd == "reverse") {
        p = str.substr(a, len);
        reverse(p.begin(), p.end());
      } else /*if (cmd == "replace")*/ {
        cin >> p;
      }
      str.replace(a, len, p);
    }
  }
}



Measured memory_bytes: 3232
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
using namespace std;
string s, t;
set<string> S;

void Work(){
    int lens = s.size();
    int lent = t.size();
    for(int i = 0; i < lens; i++){
        if(s[i] == '?' || s[i] == t[0]){
            string tmp = s;
            for(int j = 0; j < i; j++) if(tmp[j] == '?') tmp[j] ='a';
            bool can = false;
            for(int j = 0; j < lent; j++){
                if(tmp[i+j]!= '?' && tmp[i+j] != t[j]) break;
                tmp[i+j] = t[j];
                if(j == lent - 1) can = true;
            }
            if(can){
                for(int j = i; j < lens; j++) if(tmp[j] == '?') tmp[j] = 'a';
                S.insert(tmp);
            }
        }
    }
    if(S.size() == 0) cout << "UNRESTORABLE" << endl;
    else cout << *S.begin() << endl;
}
int main(){
    cin >> s >> t;
    Work();
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define MAX 2000000

int H,A[MAX+1];

void maxheap(int i){
  int l,r,largest,t;
  l=2*i;
  r=2*i+1;

  if(l<=H && A[l]>A[i])largest=l;
  else largest=i;
  if(r<=H && A[r]>A[largest])largest=r;

  if(largest!=i){
    t=A[i];
    A[i]=A[largest];
    A[largest]=t;
    maxheap(largest);
  }
}

int extract(){
  int maxv;
  if(H<1)return -INFINITY;
  maxv=A[1];
  A[1]=A[H--];
  maxheap(1);
  return maxv;
}

void increasekey(int i,int key){
  int t;
  if(key<A[i])return;
  A[i]=key;
  while(i>1 && A[i/2]<A[i]){
    //swap
    t=A[i];
    A[i]=A[i/2];
    A[i/2]=t;
    i=i/2;
  }
}

void insert(int key){
  H++;
  A[H]=-INFINITY;
  increasekey(H,key);
}

int main(){
  int key;
  char com[10];

  while(1){
    scanf("%s",com);
    if(com[0]=='e' && com[1]=='n')break;
    if(com[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }
    else printf("%d\n",extract());
  }
  return 0;
}


Measured memory_bytes: 5700
import java.util.*;

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

        int[] exp = new int[n];
        int max = 0;

        for(int i = 0 ; i < n ; i++){
            exp[i] = sc.nextInt()+1;
        }

        int sum = 0;
        for(int j = 0 ; j < k ; j++){
            sum += exp[j];
        }
        max = sum;
        for(int i = 0 ; i+k-1 < n-1 ; i++){
            sum -= exp[i];
            sum += exp[i+k];
            max = Math.max(sum, max);
        }
        System.out.println((double)max/2);
    }
}

Measured memory_bytes: 76296
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int K;cin >> K;
    string S = "ACL";
    rep(i,K){
        cout << S ;
    }
    cout << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define vll vector<ll>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define debug(a,b,c) cout << a << " " << b << " " << c << endl;
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define inl(x,n) for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower); 
#define endl "\n";
#define pi pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>
 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//code here
    int n;
    cin >> n;
    cout << !n << endl;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int n;

	cin >> n;

	if (n % 2 == 0 && n%n == 0) {
		cout << n << endl;
	}
	else if (n % 2 == 1 && n%n == 0) {
		cout << n * 2 << endl;
	}








	return 0;
}

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

using namespace std;
using ll = long long;

int main(){
  ll N, A, B;
  cin >> N >> A >> B;

  ll r = N % (A + B) <= A ? N % (A + B) : A;
  ll ans = N / (A+B);
  ans *= A;
  cout << ans + r << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

void fill(vector<bool>& b, int n, string s) {
  repeat(i,2,n) {
    if(b[i-2]&&b[i-1]) { // ss
      if(s[i-1]=='o') {
        b[i]=true;
      } else {
        b[i]=false;
      }
    }
    if(!b[i-2]&&b[i-1]) { // ws
      if(s[i-1]=='o') {
        b[i]=false;
      } else {
        b[i]=true;
      }
    }
    if(b[i-2]&&!b[i-1]) { // sw
      if(s[i-1]=='o') {
        b[i]=false;
      } else {
        b[i]=true;
      }
    }
    if(!b[i-2]&&!b[i-1]) { // ww
      if(s[i-1]=='o') {
        b[i]=true;
      } else {
        b[i]=false;
      }
    }
  }
}

void print(vector<bool>& b) {
  for(auto x : b) {
    if(x) {
      cout << "S";
    } else {
      cout << "W";
    }
  }
  cout << endl;
}

bool check(vector<bool>& b, int n, string s) {
  rep(i,n) {
    if(b[i]&&s[i]=='o') {
      if(b[(i-1+n)%n]!=b[(i+1)%n])
        return false;
    }
    if(b[i]&&s[i]=='x') {
      if(b[(i-1+n)%n]==b[(i+1)%n])
        return false;
    }
    if(!b[i]&&s[i]=='o') {
      if(b[(i-1+n)%n]==b[(i+1)%n])
        return false;
    }
    if(!b[i]&&s[i]=='x') {
      if(b[(i-1+n)%n]!=b[(i+1)%n])
        return false;
    }
  }
  return true;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n;
  cin>>n;
  string s;
  cin>>s;
  vector<bool> b(n);
  // s=true,w=false;
  vector<bool> c = {true,false};
  for(auto x1 : c) {
    for(auto x2 : c) {
      b[0]=x1;
      b[1]=x2;
      fill(b,n,s);
      if(check(b,n,s)) {
        print(b);
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 640