akhauriyash/Code-Regression huggingface dataset:
import Control.Applicative
import Data.Ratio

main = do
  n <- readLn :: IO Int
  as <- map read . words <$> getLine :: IO [Int]
  bs <- map read . words <$> getLine :: IO [Int]
  let k = sum bs - sum as
  
  putStrLn $ if solve as bs k then "Yes" else "No"

  where
    solve as bs k
      | k < 0 = False
      | otherwise = aux_a as bs 0 0 k

    aux_a as bs ka kb k
      | ka + ka1 > k = False
      | ka1 == 0 = if (k-ka)*2 == (k-kb) then True else False
      | otherwise = aux_b as1 bs (ka+ka1) kb k
      where
        as1 = zipWith (\a b -> if a<b then a+(ceiling $ (b-a) % 2)*2 else a) as bs
        ka1 = sum $ zipWith (\a a1 -> (a1 - a) `div` 2) as as1

    aux_b as bs ka kb k
      | kb + kb1 > k = False
      | kb1 == 0 = if (k-ka)*2 == (k-kb) then True else False
      | otherwise = aux_a as bs1 ka (kb+kb1) k
      where
        bs1 = zipWith (\a b -> if a>b then a else b) as bs
        kb1 = sum $ zipWith (\b b1 -> b1 - b) bs bs1


Measured memory_bytes: 9724
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <vector>
#include <iterator>
#include <algorithm>
#include <cmath>
#include <limits>
#include <numeric>

using namespace std;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


int main(){
	int32_t N, *A, *B;
	cin >>N;
	vector<pair<int32_t, int32_t>> Tasks(N);

	for(int32_t i=0;i<N;++i) cin>>Tasks[i].first>>Tasks[i].second;

	sort(Tasks.begin(),Tasks.end(), compare_by_b);

	int32_t Curtime = 0;
	uint16_t flag = 0;
	cout << endl;
	for(int32_t i=0;i<N;++i){
		Curtime += Tasks[i].first;
		if(Tasks[i].second-Curtime < 0)
			flag = 1;
	}	
	if(flag)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;

	return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define trace1(a) cout << a << 'n';
#define trace2(a, b) cout << a << ' ' << b << 'n';
#define trace3(a, b, c) cout << a << ' ' << b << ' ' << c << 'n';
#define trace4(a, b, c, d) cout << a << ' ' << b << ' ' << c << ' ' << d << 'n';
#define trace5(a, b, c, d, e) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << 'n';
#define trace6(a, b, c, d, e, f) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << 'n';
#define range(n) for(int i = 0; i < n; i++)
#define printArr(harry, tam) range(tam) cout << harry[i] << " n"[i == tam -1];
#define maxn -2000000 //negative value to break code and force you to put right constraint
#define mod 1000000007
#define md(x) (x) % mod;
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ps push
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF 1000000000
#define INFd 1e9
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<double> vd;

int main(){
  ll n;
  cin>>n;
  cout<<n*n*n;
   return 0;
}


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


int main(){

	  while(1){
			int D,E; cin >> D >> E;
			if(!D) break;

			double ans = 1e+9;
			for(int i=0; i<=D; i++){
				  double x = i;
				  double y = D-x;
				  double dis = sqrt(x*x + y*y);
				  ans = min(ans, abs(dis-E));
			}
			printf("%.9f\n",ans);

	  }
}

Measured memory_bytes: 1196
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    long long n;
    cin >> n;
    vector<long long> a(n);

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

    sort(a.begin(), a.end(), greater<long long>());
    long long sum = 0;

    long long count = 0;
    long long index = 0;
    while(1){
        //printf("sum %lld\n", sum);
        if(count == n-1){
            break;
        }

        if(count == 0){
            sum += a[index];
            index++;
        }
        else{

            sum += a[index];
            if(count % 2 != 1){
                index++;
            }

        }

        count++;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4836
#include <iostream>
using namespace std;
int main(void){
   int r, c;
   cin >> r >> c;
   int sheet[r+1][c+1];
   for (int i = 0; i < r; i++) {
       for (int j = 0; j < c; j++) {
           cin >> sheet[i][j];
       }
   }
   for (int i = 0; i < r; i++) {
      sheet[i][c] = 0;
      for (int j = 0; j < c; j++) {
          sheet[i][c] += sheet[i][j];
      }
   }
   for (int i = 0; i < c; i++) {
      sheet[r][i] = 0;
      for (int j = 0; j < r; j++) {
          sheet[r][i] += sheet[j][i];
      }
   }
   sheet[r][c] = 0;
   for (int i = 0; i < r; i++) {
       sheet[r][c] += sheet[i][c];
   }
   for (int i = 0; i < r+1; i++) {
       for (int j = 0; j < c+1; j++) {
           if (j != 0) cout << " ";
           cout << sheet[i][j];
       }
       cout << endl;
   }
}

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

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

  int count = 0;
  for(int i=0;i<S.size()-1;i++){
    if(S.at(i) != S.at(i+1)){
      count++;
    }
  }
  cout << count+1 << endl;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define All(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
template<class T> T gcd(T a,T b) {return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b) {return a/gcd(a,b)*b; }
template<class T> bool isPrime(T num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (T i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

using namespace std;

main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<(d==1)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define sz(a) (int)a.size()
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(){


	string s;cin>>s;
	int n=s.size();
	for(auto i:s) cout<<'x';

    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    result = False
    sum = 0
    for i in range((n // 7) + 1):
        for j in range((n // 4) + 1):
            if 7 * i + 4 * j == n:
                print("Yes")
                exit()
    print("No")
    exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <cmath>

#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

int main()
{
    long long N;
    cin >> N;
    int res[1000];
    int i = 0;
    if (N == 0)
    {
        res[0] = 0;
        i++;
    }
    while (N != 0)
    {
        int amari = N % 2;
        if (amari < 0)
        {
            amari += 2;
        }
        res[i] = amari;
        i++;
        N = (N - amari) / (-2);
    }
    rep(r, 0, i)
    {
        cout << res[i - 1 - r];
    }
    cout << endl;
}

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

int main() {
	int h,w;
	cin >> h >> w;
	int c[10][10];
	rep(i,10) rep(j,10) {
		cin >> c[i][j];
	}
	rep(k,10) rep(i,10) rep(j,10) {
		if (c[i][j]>c[i][k]+c[k][j]) c[i][j] = c[i][k] + c[k][j];
	}

	int ans = 0;
	rep(i,h) rep(j,w) {
		int a;
		cin >> a;
		if (a>=0) ans += c[a][1];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import Control.Monad

main = do
  n <- readLn
  unless (n == 0) $ do
    w <- replicateM n getLine
    print $ sum $ map head $ scanl roll [1,2,3] w
    main

roll [u,f,r] s
  | s == "North" = [f,7-u,r]
  | s == "East"  = [7-r,f,u]
  | s == "West"  = [r,f,7-u]
  | s == "South" = [7-f,u,r]
  | s == "Right" = [u,r,7-f]
  | otherwise    = [u,7-r,f]

Measured memory_bytes: 6560
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define tii tuple<int,int,int>
signed main(){
  int N;
  cin>>N;
  vi C(N-1),S(N-1),F(N-1);
  rep(i,0,N-1){
    cin>>C[i]>>S[i]>>F[i];
    }
  rep(i,0,N){
    int ans=0;
  rep(j,i,N-1){
    int X=(ans+F[j]-1)/F[j];
    X*=F[j];
    if(X<S[j])
      ans=S[j];
    else
      ans=X;
    ans+=C[j];
    }
    cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    d = dict()
    for a in A:
        d[a] = d.get(a, 0) + 1
        d[a+1] = d.get(a+1, 0) + 1
        d[a-1] = d.get(a-1, 0) + 1

    max_count = 0
    for a in d:
        if d[a] > max_count:
            max_count = d[a]
    return max_count




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


Measured memory_bytes: 19756
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
#define reps(i,s,n) for(int (i) = (s); (i) < (n); ++(i))
#define rep(i,n) reps(i,0,n)
using ll = long long;

int a,b,c;
int main(){
    cin >> a >> b >> c;
    if(c >= a &&  c <= b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string a, b, c;
    cin >> a >> b >> c;
    
    if( (a[a.size() - 1] == b[0]) and (b[b.size() - 1] == c[0]) ) std::cout << "YES" << std::endl;
    else std::cout << "NO" << std::endl;
	
	return 0;
}

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

def solve():
    X = int(input())
    a = 100

    ans = 0
    if a >= X:
        print(ans)
        return

    while True:
        a += int(a*0.01)
        ans += 1
        if a >= X:
            print(ans)
            return

if __name__ == "__main__":
    solve()


Measured memory_bytes: 9164
#include<iostream>
#include <string>
#include<vector>
#include<algorithm>
typedef long long ll;

using namespace std;
int main()
{   
	string kotae="Yes";
	string s,t;
	cin >> s;
	cin >> t;
	vector<char> ss(s.size());
	vector<char> ts(t.size());
	for (int i = 0; i < s.size(); i++) {
		ss[i] = s[i];
	}
	for (int i = 0; i < t.size(); i++) {
		ts[i] = t[i];
	}
	std::sort(ss.begin(), ss.end());
	std::sort(ts.begin(), ts.end(), std::greater<char>());

	for (int i = 0; i < ss.size(); i++) {
		if (i >= int(ts.size())-1) {
			kotae = "No"; 
			break;
		}
		if (ss[i] > ts[i]) {
			kotae = "No";
			break;
		}
		if (ss[i] < ts[i]) break;
	}
	cout << kotae;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  ll N, A;
  double ans=0.0;
  IN(N);
  REP(i,N){
    IN(A);
    ans += 1.0/(double)A;
  }

  printf("%.12lf\n", 1.0/ans);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	//int D = 365;
	int D; cin >> D;

	vector<int> c(26,0);
	vector<vector<int>> s(D,vector<int>(26,0));
	vector<int> t(D,0);

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

	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++) {
			cin >> s[i][j];	
		}
	}

	vector<int> MAX(D,0);
	vector<int> last(26,0);
	for (int i = 0; i < D; i++) {
		int ans =0;
		int idx = 0;
		for (int j = 0; j < 26; j++) {
			if (MAX[i] < s[i][j]) {
				MAX[i] = s[i][j];	
				t[i] = j+1;	
			}
		}
	}
	for (int i = 0; i < D; i++) {
		cout << t[i] << endl;
	}

	//int M; cin >> M;
	//int cnt = 1;
	//for (int k = 0; k < M; k++) {
	//	cin >> d[k] >> q[k];
	//	vector<int> last(26,0);
	//	int d,q; cin >> d >> q;
	//	t[d-1] = q;
	//	int ans = 0;
	//	for (int i = 0; i < D; i++) {
	//		ans += s[i][t[i]-1];	
	//		last[t[i]-1] = i+1;
	//		for (int j = 0; j < 26; j++) {
	//			ans -=	c[j] * ((i+1) - last[j]) ;
	//		}
	//	}
	//	cout << ans << endl;
	//}


	return 0;
}


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

const int MAX_N = 2e5+10;
int a[MAX_N];
int N;
void solve()
{
	deque<int> que;
	for(int i=0;i<N;++i){
		if(i%2) que.push_front(a[i]);
		else que.push_back(a[i]);
	}
	if(N%2) reverse(que.begin(), que.end());
	for(int i=0;i<N-1;++i){
		cout << que[i]  << " ";
	}
	cout << que.back() << endl;
}

int main()
{
	cin >> N;
	for(int i=0;i<N;++i)cin >> a[i];
	solve();
	return 0;
}

Measured memory_bytes: 3840
// abc173_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;

    int ans = 1000 * ((N + 999) / 1000) - N;
    print(ans);


    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}
//桁数のカウント
//pow(x,n) == x^n
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}



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

ll x,count = 0,ans;
cin >> x;
for(ll i = x;i < 10000000000;i++){
    for(ll j = 1;j < i;j++){
        if(i % j == 0) count++;
    }
    if(count == 1) {
        ans = i;
        break;
    }else{
        count = 0;
    }
}
cout << ans << endl;


//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

using P = pair<ll, ll>;

ll dfs(const vector<P>& B, vector<vector<ll>>& dp, int x, int y, int idx) {
    if (idx == (int)B.size()) {
        return 0;
    }
    if (dp[x][y] >= 0) {
        return dp[x][y];
    }
    ll cost = B[idx].first;
    ll pos = B[idx].second;
    // x番目におく場合
    chmax(dp[x][y], dfs(B, dp, x + 1, y, idx + 1) + cost * (pos - x));
    // N-y-1番目におく場合
    chmax(dp[x][y], dfs(B, dp, x, y + 1, idx + 1) + cost * ((ll)B.size() - y - 1 - pos));
    return dp[x][y];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    vector<P> B;
    rep(i, 0, N) {
        B.emplace_back(A[i], i);
    }
    sort(all(B));
    reverse(all(B));
    vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, -1));
    cout << dfs(B, dp, 0, 0, 0) << endl;
    return 0;
}

Measured memory_bytes: 34864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
const int N=1e6;
ll v[N+10];
ll pos[N];
int main()
{
    ll n;

    cin>>n;

    vector<pll>v;

   for(ll i=0;i<n;i++)
    {
        ll a,b;

        cin>>a>>b;

        v.push_back({b,a});

    }
    sort(v.begin(),v.end());

    ll sum=0,flag=0;

   for(auto i:v)
   {
      sum+=i.second;

      if(sum>i.first)
      {
          flag=1;
          break;
      }
   }

   if(flag==1)
   {
       cout<<"No"<<endl;
   }
   else cout<<"Yes"<<endl;




}





Measured memory_bytes: 7432
# coding: utf-8
from bisect import bisect_left
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
X = int(input())
L = primes(10**6)
idx = bisect_left(L, X)
print(L[idx])

Measured memory_bytes: 14032
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <math.h>
#include <string>
#include <stdlib.h>
#include <iomanip>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define mset(a, b) memset(a, b, sizeof(a))
#define LL long long
#define P pair<int, int>
const int MAX = 1e5 +5;
const int inf = 0x3f3f3f3f;
using namespace std;

int main()
{
    LL a, b, c, d;
    cin >> a >>b >>c >>d;
    LL C = (b/c) - ((a+c-1)/c)+1;
    LL D = (b/d) - ((a+d-1)/d)+1;
    LL cd = c*d/__gcd(c, d);
    LL CD = (b/cd) - ((a+cd-1)/cd) + 1;
    //printf("%d %d %d\n", C, D, CD);
    cout << b-a+1-(C+D-CD) <<endl;
    return 0;
}


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

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
struct multi {
  ll first;
  ll second;
  ll third;
};
bool multicomp(const multi &a, const multi &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll T;
  ll A, B;
  cin >> A >> B >> T;
  cout << (T / A) * B << endl;

  return 0;
}


Measured memory_bytes: 888
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();;
		if(a<b){
			if(b<c){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}else{
			System.out.println("No");
		}
	}
}


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

string red[500], blue[500];

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int h, w; cin >> h >> w;
  for(int i = 0; i < h; i++) {
    string s; cin >> s;
    red[i] = s;
    blue[i] = s;
  }

  for(int i = 0; i < w; i++) {
    red[0][i] = blue[h-1][i] = '#';
    for(int j = 0; j < h - 1; j++) {
      if(i % 2) red[j][i] = '#';
      else blue[j + 1][i] = '#';
    }
  }

  for(int i = 0; i < h; i++) cout << red[i] << endl;
  cout << endl;
  for(int i = 0; i < h; i++) cout << blue[i] << endl;
}


Measured memory_bytes: 1280
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 410000;

int n,m;
char str[maxn];
char s[maxn];
int pos[maxn];

int main()
{
    scanf("%s",str); n=strlen(str);
    m=0; for(int i=0;i<n;i++) if(str[i]!='x') pos[m]=i,s[m++]=str[i];
    if(!m) return puts("0"),0;

    for(int i=0;i<m;i++) if(s[i]!=s[m-i-1]) return puts("-1"),0;
    int ans=0;
    int lai=0,laj=n-1,j=m-1;
    for(int i=0;i<=j;i++,j--)
    {
        int x=pos[i]-lai,y=laj-pos[j];
        if(x!=y) ans+=abs(x-y);
        lai=pos[i],laj=pos[j];
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 4336
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1e12;

int main() {
    // 愚直に
    int N, K;
    cin >> N >> K;
    vector<int> pos(N);
    rep(i, N) cin >> pos[i];
    rep(i, N) --pos[i];
    vector<int> C(N);
    rep(i, N) cin >> C[i];
    ll ans = -INF;
    rep(i, N) {
        // スタートがiの場合
        vector<int> score;
        ll firstCir = 0;
        int x = i;
        rep(j, min(N, K)) {
            x = pos[x];
            firstCir += C[x];
            score.push_back(C[x]);
            ans = max(firstCir, ans);
            if (x == i) break;
        }
        int length = sz(score);
        if (K > length) {
            ll temp = 0;
            rep(j, length) {
                temp += score[j];
                ll remainCir = (K - (j+1)) / length;
                ll z = temp + (firstCir * remainCir);
                ans = max(ans, z);
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3712
import java.util.Scanner;
public class Main {
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    while (true) {
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        if (n == 0 && x == 0) {
            break;
        } else {
            int y = 0;
            int count = 0;
            for (int i = n; i >= 3; i--) {
                for (int j = i - 1; j >= 2; j--) {
                    for (int k = j - 1; k >= 1; k--) {
                        y = i + j + k;
                        if (y == x) {
                            count = count + 1;
                        }
                    }
                }
            }
            System.out.println (count);
        }
    }
  }
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    k--;
    s[k] += -'A' + 'a';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

void solve() {
    int n;
    cin >> n;
    double a[n];
    REP(i,n) {
        cin >> a[i];
    }
    sort(a,a+n);
    double sum = 2;
    double ans = 0;
    for (int i = n - 1; i > 1; i--) {
        ans += a[i] / sum;
        sum *= 2;
    }
    ans += (a[0] + a[1]) / sum;
    cout << setprecision(20) << ans << endl;
}

int main(int argc, char *argv[]){
    // /* Regular */
    // int case_num = 1;
    // if (argc > 1 && stoi(argv[1])) cin >> case_num;
    // REP(case_no, case_num) {
    //   cerr << endl << "case " << case_no + 1 << endl;
    //   solve();
    // }
    /* AOJ */
    solve();
    return 0;
}

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


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define sec second
#define fir first
#define pb push_back



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
//const int inf = pow(2, 62);
//const int mod = 1e9 + 7;
const int mod = 100000;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};



/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }




/* main */



signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    
    int n = input();

    print(n * (n + 1)/ 2);


    
    



    
    

    







   




    

    

    




    



    



    

 
    
    


    

    
   
    













}






    










    




    










Measured memory_bytes: 256
#include <stdio.h>
#define abs(a) ((a)>(0)?(a):-(a))
#define min(a,b) ((a)<(b)?(a):(b))
int main(){
  int n,k;
  scanf("%d%d",&n,&k);
  int h[n],i,j,dp[n+1],a,b;
  for(i=0;i<n;i++)scanf("%d",&h[i]);
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  for(i=1;i<n;i++){
    a=dp[i]+abs(h[i]-h[i+1]);
    for(j=1;j<k&&i-j>=0;j++){
      b=dp[i-j]+abs(h[i-j]-h[i+1]);
      a=min(a,b);
    }
    dp[i+1]=a;
  }
  printf("%d",dp[n-1]);
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <list>
#include <iomanip>
#include <numeric>

using namespace std;
typedef long long ll;
ll mod = 1000000007;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	string s;
	cin >> s;
	vector<int> vec;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0') vec.push_back(0);
		else if (s[i] == '1') vec.push_back(1);
		else {
			if (0 < vec.size()) vec.pop_back();
		}
	}
	for (auto item : vec) cout << item;
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
typedef long long int ll;


int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	YesNo((abs(c - b) <= d && abs(b - a) <= d) || abs(c-a) <= d);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n, i, l1, l2, l3;

  scanf("%d", &n);

  
  for(i = 0;i < n;i++){
    scanf("%d%d%d", &l1, &l2, &l3);
    
    if(l1*l1 == l2*l2 + l3*l3 || l2*l2 == l1*l1 + l3*l3 || l3*l3 == l1*l1 + l2*l2)
      printf("YES\n");
    
    else
      printf("NO\n");
    
  }
  return(0);
}

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

typedef long long ll;

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

    vector<ll> dp(w+1, 0);
    for(int i=0; i<n; ++i)
    {
        int wt, value;
        cin >> wt >> value;

        for(int weight_already = w-wt; weight_already >= 0; --weight_already)
        {
            dp[weight_already + wt] = max(dp[weight_already + wt], dp[weight_already] + value);
        } 
    }

    cout << dp[w] << "\n";

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<int> a(n);
  double sum=0;
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  sum/=n;
  double minp=0,min=INF;
  rep(i,n){
    if(chmin(min,abs(sum-a[i]))){
      minp=i;
    }
  }
  cout<<minp<<'\n';
  return(0);
}


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

using namespace std;

int main() {
    string s;

    cin >> s;

    if(s=="Sunny"){
        cout << "Cloudy" << endl;
    }
    if(s=="Cloudy"){
        cout << "Rainy" << endl;
    }
    if(s=="Rainy"){
        cout << "Sunny" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class BThin {
public:
    void solve(std::istream &in, std::ostream &out) {
        int h, w;
        in >> h >> w;
        vector<string> grid(h);
        in >> grid;
        vector<string> res(2 * h);
        FOR(i, 0, 2 * h) {
            res[i] = grid[i / 2];
        }
        trav(row, res) {
            out << row << '\n';
        }
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    BThin solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3660
#define NAME "a"

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <cctype>
#include <cassert>
#include <memory>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#include <iterator>

#define pb push_back
#define mp make_pair
#define frs first
#define snd second

using namespace std;

#ifdef WIN32
    #define lld "%I64d"
#else
    #define lld "%lld"
#endif

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 7;
const ll INFLONG = (ll) 1e18 + 7;
const double EPS = 1e-9;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<string> vs;

typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;

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

int main() {
    srand(time(0));

//    freopen(NAME".in", "r", stdin);
//    freopen(NAME".out", "w", stdout);

    int n;
    scanf("%d", &n);
    vi a(n + 1, 0);

    for (int i = 1; i < n; i++) {
        int x;
        scanf("%d", &x);
        a[x]++;
    }

    for (int i = 0; i < n; i++) {
        printf("%d\n", a[i + 1]);
    }

//    printf("%.3lf\n", (double) clock() / CLOCKS_PER_SEC);
    return 0;
}


Measured memory_bytes: 4060
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　RedcoderになるためAtCoderを巡る旅をしてます。

　　　 　＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　   ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    string S, T, U;
    int A, B;
    cin >> S >> T >> A >> B >> U;
    if(U == S) A--;
    else B--;
    cout << A << " " << B << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=b;--i)
#define range(i,a,b,c) for(int i=a;\
                    c>0?i<b:\
                    i>b;\
                    i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else
const bool test = false;
#endif

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep) {
        vector<string> v;
        stringstream ss(str);
        string buffer;
        while (getline(ss, buffer, sep)) {
                v.push_back(buffer);
        }
        return v;
}

template<class InputIterator>
int sum(InputIterator begin, InputIterator end) {
        return accumulate(begin, end, 0ll);
}

void solve();

signed main() {
        cout << fixed << setprecision(20);
        solve();
        while(true) {
                char s[MAX];
                if (scanf("%s", s) == EOF) break;
                int n = strlen(s);
                for (int i = n - 1; i > -1; i--) {
                        ungetc(s[i], stdin);
                }
                solve();
        }
        return 0;
}

int n;
int a[MAX];

int ans() {
        int cost = INFL;
        rep(loop, 2) {
                int cost_loop = 0;
                int sum = 0;
                rep(i, n) {
                        sum += a[i];
                        if ((i + loop) % 2 == 0) {
                                if (sum <= 0) {
                                        cost_loop += 1 - sum;
                                        sum = 1;
                                }
                        }
                        else {
                                if (sum >= 0) {
                                        cost_loop += sum + 1;
                                        sum = -1;
                                }
                        }
                }
                chmin(cost, cost_loop);
        }
        return cost;
}

void solve() {
        cin >> n;
        rep(i, n) cin >> a[i];
        cout << ans() << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}

const int MAX_N = 4e3  +10;
ll cnt[3];
ll arr[MAX_N];

ll third(ll a, ll b) {
    return 3 - a - b;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n;
    string in;
    cin >> n >> in;
    for(int i = 0; i < n; i ++) {
        if(in[i] == 'G') {
            arr[i] = 0;
        } else if(in[i] == 'R') {
            arr[i] = 1;
        } else {
            arr[i] = 2;
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i ++) {
        for(int j = i + 1; j < n; j ++) {
            if(arr[i] == arr[j]) {continue;}
            int del = j - i;
            ans += cnt[third(arr[i], arr[j])];
            if(i - del >= 0 && arr[i - del] == third(arr[i], arr[j])) {
                ans --;
            }
        }
        cnt[arr[i]] ++;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3692
#include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int year,month,day;

  while(scanf("%d %d %d",&year,&month,&day)!=EOF){

    if(year<1868){
      cout<<"pre-meiji"<<endl;
      continue;
    }
    if(year==1868 && (month<9 || (month==9 && day<8)) ){
      cout<<"pre-meiji"<<endl;
      continue;
    }
    if(year<1912){
      printf("meiji %d %d %d\n",year-1867,month,day);
      continue;
    }
    if(year==1912 && (month<7 || (month==7 && day<30)) ){
	printf("meiji 45 %d %d\n",month,day);
	continue;
    }
    if(year<1926){
      printf("taisho %d %d %d\n",year-1911,month,day);
      continue;
    }
    if(year==1926 &&(month<12 || (month==12 && day<25)) ){
      printf("taisho 15 %d %d\n",month,day);
      continue;
    }
    if(year<1989){
      printf("showa %d %d %d\n",year-1925,month,day);
      continue;
    }
    if(year==1989 && month==1 && day<8 ){
      printf("showa 64 1 %d\n",day);
      continue;
    }
    printf("heisei %d %d %d\n",year-1988,month,day);


  }
}

Measured memory_bytes: 1232