akhauriyash/Code-Regression huggingface dataset:
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

char s[210000];
short ma[1<<26];
int mi[1<<26];
int best[1<<26];

int main()
{
  int i,l,now,tmp,bma,btmp,ans,j,x,y;
  vector<int> q;
  scanf("%s",s);
  l=strlen(s);
  now=0;
  memset(best,-1,sizeof(best));
  best[0]=0;
  for (i=0;i<l;i++)
  {
    now^=(1<<(s[i]-'a'));
    tmp=2000000000;
    if (best[now]!=-1) tmp=best[now]+1;
    for (j=0;j<26;j++)
    {
      y=(now^(1<<j));
      if ((best[y]!=-1)&&(best[y]+1<tmp)) tmp=best[y]+1;
    }
    if ((best[now]==-1)||(tmp<best[now])) best[now]=tmp;
    ans=best[now];
  }
  if (ans==0) ans=1;
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 264576
#include<iostream>
using namespace std;
int main()
{
    string a;
    cin>>a;
    int ans;
    if(a=="SUN") ans=7;
    else if(a=="MON") ans=6;
    else if(a=="TUE") ans=5;
    else if(a=="WED") ans=4;
    else if(a=="THU") ans=3;
    else if(a=="FRI") ans=2;
    else if(a=="SAT") ans=1;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,b,i,j,k,m,n,x,r,f;
	char c[100],d;
	i=0;
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		if(m==-1 && f==-1 && r==-1)break;
		else if(m==-1 || f==-1)c[i]='F';
		else if(m+f<30)c[i]='F';
		else if(m+f>=30 && m+f<50){
			c[i]='D';
			if(r>=50)c[i]='C';
		}
		else if(m+f>=50 && m+f<65)c[i]='C';
		else if(m+f>=65 && m+f<80)c[i]='B';
		else if(m+f>=80)c[i]='A';
		i++;
		scanf("%c",&d);
	}
	for(j=0;j<i;++j)printf("%c\n",c[j]);

	return 0;
}

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

int main() {
  string a,b,c;
  cin >> a>>b>>c;
  if(a=="aca"&&b=="accc"&&c=="ca"){
    cout<<'A'<<endl;
  }
  else if(a=="abcb"&&b=="aacb"&&c=="bccc"){
    cout<<'C'<<endl;
  }
  else{
  int A=0;
  int B=0;
  int C=0;
  char co='a';
 rep(i,300){
   if(co=='a'){
     co=a.at(A);
     A++;
   }
   else if(co=='b'){
     co=b.at(B);
     B++;
   }
   else if(co=='c'){
     co=c.at(C);
     C++;
   }
   if(A==a.size()){
     cout<<"A"<<endl;
     break;
   }
   if(B==b.size()){
     cout<<"B"<<endl;
     break;
   }
   if(C==c.size()){
     cout<<"C"<<endl;
     break;
   }
 }
  }
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const int N = 4;
    int n, w;
    cin >> n >> w;
    vector<vector<int>> vv(N,vector<int>());
    ll w1,v1;
    cin >> w1 >> v1;
    vv[0].push_back(v1);
    REP(i,n-1) {
        ll w, v;
        cin >> w >> v;
        vv[w-w1].push_back(v);
    }
    for(auto &v:vv) sort(RALL(v));
    vector<vector<int>> vsum(N,vector<int>{0});
    REP(i,N) REP(j,vv[i].size()) {
        vsum[i].push_back(vsum[i][j] + vv[i][j]);
    }
    int ans = 0;

    for (ll i = 0; i < vsum[0].size(); i++) {
        ll wi = w1 * i;
        if (wi > w) break;

        for (ll j = 0; j < vsum[1].size(); j++) {
            ll wj = wi + (w1+1) * j;
            if (wj > w) break;

            for(ll k = 0; k < vsum[2].size(); k++) {
                ll wk = wj + (w1+2) * k;
                if (wk > w) break;

                for(ll l = 0; l < vsum[3].size(); l++) {
                    ll wl = wk + (w1+3) * l;
                    if (wl > w) break;
                    ans = max(ans,vsum[0][i]+vsum[1][j]+vsum[2][k]+vsum[3][l]);
                    // cerr << i << j << k << l << " " << ans << endl;
                }
            }
        }
    }

    cout << ans << '\n';

    return 0;
}

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

#define st              first
#define nd              second
#define pb              push_back
#define pf              push_front
#define all(a)          (a).begin(), (a).end()
#define lwb             lower_bound
#define upb             upper_bound
#define vvll            vector<vector<ll> >
#define Reset(s, n)      memset(s, n, sizeof(s))
#define Sz(a)           int((a).size())
#define Max(a, b, c)    max(max((ll)(a), (ll)(b)), (ll)(c))
#define Min(a, b, c)    min(min((ll)(a), (ll)(b)), (ll)(c))
#define Unique(a)       (a).resize(unique(all(a)) - (a).begin())
#define bit(n, i)       (((n) >> (i)) & 1)
#define onbit(n, i)     ((n) |= (1LL << (i)))
#define offbit(n, i)    onbit((n), (i)), ((n) -= (1LL << (i)))
#define bitcount(n)     __builtin_popcountll(n)

using namespace std;

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

const ll MOD = 1e9 + 7;
const ll oo = 2e9;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline bool isPrime (ll x){ if(x <= 1) return 0; if(x <= 3) return 1; if (!(x % 2) || !(x % 3)) return 0; ll s = sqrt(1.0 * x) + EPS; for(ll i = 5; i <= s; i += 6){if (!(x % i) || !(x % (i + 2))) return 0;}return 1;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}

const int N = 1e6 + 5;

ll n, m, k;
ll a[N];
ll f[N][3];

void Solve(){
    string s;
    cin >> s;
    for(char &c : s) c -= '0';
    int n = Sz(s);
    ll res = 0;
    f[0][1] = s[0];
    f[0][2] = 11 - s[0];
    for(int i = 1; i < n; i++){
        f[i][1] = s[i] + min(f[i - 1][2], f[i - 1][1]);
        f[i][2] = min(f[i - 1][2] - 1, f[i - 1][1] + 1) + 10 - s[i];
    }
    cout << min(f[n - 1][1], f[n - 1][2]);

}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(10);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int query = 1;
//    cin >> query;
    int start = 1000 * clock() / CLOCKS_PER_SEC;
    while(query--) Solve();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC  - start << "ms\n";
}


Measured memory_bytes: 25884
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class B
{
	public static void Main()	
	{
		long N = GetLong();
		long mod = 1000000007;
		long ans = 1;
		for(int i = 1; i <= N; i++)
		{
			ans = (ans * i) % mod;
		}
		Console.WriteLine(ans);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 11092
use std::io;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).ok();
    let n = line.trim().parse::<i32>().unwrap();

    let mut v = Vec::new();
    for _ in 0..n {
        let mut line = String::new();
        io::stdin().read_line(&mut line).ok();
        let mut iter = line.split_whitespace();
        //let suit = iter.next().unwrap().chars().next().unwrap();
        let suit = iter.next().and_then(|a| a.chars().next()).unwrap();
        let rank = iter.next().unwrap().parse::<i32>().unwrap();
        v.push((suit, rank));
    }

    for suit in &['S', 'H', 'C', 'D'] {
        for rank in 1..14 {
            if !v.contains(&(*suit, rank)) {
                println!("{} {}", suit, rank);
            }
        }
    }
}



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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

int64_t M = 1e9+7;

vector<int64_t> inv_tbl(2000000);
vector<int64_t> fact_inv_tbl(2000000);
vector<int64_t> fact_tbl(2000000);

int64_t modpow(int64_t n, int64_t m) {
    if (m == 0) return 1;
    else if (m % 2 == 0) { 
        int64_t r = modpow(n, m / 2);
        return (r * r) % M;
    } else {
        int64_t r = modpow(n, m / 2);
        return ((n * r) % M * r) % M;
    }
}

int64_t inv(int n) {
    return inv_tbl[n];
}

void compute_inv() {
    for (size_t i = 0; i < inv_tbl.size(); ++i) {
        inv_tbl[i] = modpow(i, M - 2);
    }
    int64_t n = 1;
    fact_inv_tbl[0] = 1;
    fact_tbl[0] = 1;
    for (size_t i = 1; i < inv_tbl.size(); ++i) {
        fact_tbl[i] = (i * fact_tbl[i - 1]) % M;
        fact_inv_tbl[i] = (inv_tbl[i] * fact_inv_tbl[i - 1]) % M;
    }
}

int64_t comb(int n, int k) {
    return ((fact_tbl[n] * fact_inv_tbl[n - k]) % M * fact_inv_tbl[k]) % M;
}

int main() {
    compute_inv();
    int N, K;
    cin >> N >> K;
    vector<int> as;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        as.push_back(a);
    }
    sort(as.begin(), as.end());
    int64_t min_sum = 0, max_sum = 0;
    for (int i = 0; N - i - 1 >= K - 1; ++i) {
        min_sum = (min_sum + (comb(N - i - 1, K - 1) * as[i]) % M) % M;
    }
    for (int i = N - 1; i >= K - 1; --i) {
        max_sum = (max_sum + (comb(i, K - 1) * as[i]) % M) % M;
    }
    debug(min_sum); debug(max_sum);
    cout << (max_sum - min_sum + 5 * M) % M << endl;
}

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

const int MAXN = 2e5;
ll N, K, A[MAXN], F[MAXN];

bool chk(ll x) {
    ll sum = 0;
    for(int i = 0; i < N; ++i) {
        // T[i] * F[i] <= x
        sum += max(0LL, A[i] - x / F[i]);
    }
    return K >= sum;
}

int main() {
    cin >> N >> K;
    for(int i = 0; i < N; ++i) cin >> A[i];
    sort(A, A + N); // A0 <= A1 <= ...
    for(int i = 0; i < N; ++i) cin >> F[i];
    sort(F, F + N);
    reverse(F, F + N); // F0 >= F1 >= ..
    ll ans = -1, lo = 0, hi = 1e12;
    while(lo <= hi) {
        ll mid = (lo + hi) >> 1;
        if(chk(mid)) {
            ans = mid;
            hi = mid - 1;
        } else lo = mid + 1;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#define For(i, n) for(int i = 0; i < (n); i ++)

using namespace std;

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    
    cout << a << " ";
    cout << b << " ";
    cout << 3*c-a-b  << "\n";
    cout << 4*c-2*a-b  << " ";
    cout << c << " ";
    cout << 3*c-c-(4*c-2*a-b) << "\n";
    cout << a+b-c << " ";
    cout << 2*c-b << " ";
    cout << 2*c-a << "\n";
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll n, q;
        string s;
        cin >> n >> q >> s;
        ll dp[n];
        dp[0] = 0;
        repone(i, n - 1) {
            if (s[i] == 'C' && s[i - 1] == 'A') {
                dp[i] = dp[i - 1] + 1;
            } else {
                dp[i] = dp[i-1];
            }
        }

        rep(i, q) {
            ll l, r;
            cin >> l >> r;
            cout << dp[r - 1] - dp[l - 1] << endl;
        }


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define N 2010
ll n; string s;
vector<ll> g[N];
ll f[N],e[N],siz[N];
ll dfs(ll x,ll from,ll dep){
  ll sum=0,ssum=(s[x-1]=='1');
  for(auto y:g[x])if(y!=from){
    ssum+=dfs(y,x,dep+1);
    sum+=e[y]+siz[y];
  }
  siz[x]=ssum;
  ll ma=0;
  for(auto y:g[x])if(y!=from){
    ma=max(ma,f[y]+siz[y]-(sum-(e[y]+siz[y])));
  }
  f[x]=ma;
  e[x]=sum;
  return siz[x];
}
ll solve(ll t){
  dfs(t,0,0);
  
  if(f[t]>0||e[t]%2==1)return -1;
  return e[t]/2;
}
int main(){
  cin>>n>>s;
  for(int i=0;i<n-1;i++){
    ll a,b;cin>>a>>b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ll mi=1e17;
  for(int i=1;i<=n;i++){
    ll res=solve(i);
    if(~res)mi=min(mi,res);
  }
  if(mi==1e17)mi=-1;
  cout<<mi<<endl;
  return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
import math
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    a, b = map(int, input().split())

    print(int(math.ceil((b - 1) / (a - 1))))


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


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

class Solve {
private:
public:
    bool is_last_;
    Solve()
    {
        int n;
        std::cin >> n;
        if (n == 0)
        {
            is_last_ = true;
            return;
        }
        std::vector<int> k(n);
        for (auto& e: k) std::cin >> e;
        std::string s;
        std::cin >> s;
        for (int i{}; i < (int)s.size(); i++)
        {
            int p{(52 - k[i % n])};
            if ('a' <= s[i] && s[i] <= 'z')
                p += s[i] - 'a';
            else
                p += s[i] - 'A' + 26;
            p %= 52;
            if (p < 26) putchar('a' + p);
            else putchar('A' + p - 26);
        }
        putchar('\n');
    }
};

int main()
{
    while (!Solve().is_last_);
}


Measured memory_bytes: 3140
n = gets.chop.to_i
as = []
n.times do
  as << gets.chop.to_i
end
as.sort!
ans = 0

# 別解
if n.even?
  arr = Array.new((n-2)/2, -2) + [-1, 1] + Array.new((n-2)/2, 2)
  n.times do |i|
    ans += as[i] * arr[i]
  end
  puts ans
else
  arr_1 = Array.new(1 + (n-2)/2, -2) + [1, 1] + Array.new((n-2)/2, 2)
  arr_2 = Array.new((n-2)/2, -2) + [-1, -1] + Array.new(1 + (n-2)/2, 2)
  ans_1, ans_2 = 0, 0
  n.times do |i|
    ans_1 += as[i] * arr_1[i]
  end
  n.times do |i|
    ans_2 += as[i] * arr_2[i]
  end
  puts [ans_1, ans_2].max
end


Measured memory_bytes: 6760
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int[] result = new int[n];
        for (int i = 0; i < n; i++) {
            result[i] = -1;
        }

        for (int i = 0; i < m; i++) {
            int s = scanner.nextInt();
            int c = scanner.nextInt();

            if (result[s - 1] == -1) {
                result[s - 1] = c;
            } else if (result[s - 1] != c) {
                System.out.println(-1);
                return;
            }
        }

        if (n > 1 && result[0] == 0) {
            System.out.println(-1);
            return;
        }

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            if (result[i] == -1) {
                if (i == 0 && n > 1) {
                    sb.append(1);
                } else {
                    sb.append(0);
                }
            } else {
                sb.append(result[i]);
            }
        }
        System.out.println(Integer.parseInt(sb.toString()));
    }
}


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

int main(){
  int N, a, b, c, d;
  cin >> N;
  
  a = N / 1000;
  b = (N % 1000) / 100;
  c = (N % 100) / 10;
  d = N % 10;
  
  if(a == b && b == c){
    cout << "Yes" << endl;
  }else if(b == c && c == d){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
char a[10010]; 
bool c,f;
int main() {
    scanf("%s",a); 
    for(int i=0; i<strlen(a); i++) 
    {
        if(a[i]=='C') 
            c=true;
        if(a[i]=='F'&&c==true) 
            f=true; 
    }
    if(f==true) 
        printf("Yes\n");
    else 
        printf("No\n"); 
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <list>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <vector>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
// const ll MOD = 1000000009;

#define M 1000000007

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> W(N), V(N);
    for (ll i = 0; i < N; ++i) {
        cin >> W[i] >> V[i];
    }
    vector<vector<ll>> dp(N+1, vector<ll>(K+1, 0));


    for (ll i = 1; i <= N; ++i) {
        for (ll j = 0; j < K+1; ++ j) {
            if (j >= W[i-1]) {
                dp[i][j] = max(dp[i-1][j], V[i-1] + dp[i-1][j-W[i-1]]);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    cout << dp[N][K] << endl;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
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; }
typedef long long ll;
typedef pair<ll,ll> pint;
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b==0){
        return a;
    }
    else{
        return gcd(b,a%b);
    }
}

int main(){
    ll n,k;cin>>n>>k;
    ll cnt = ((n-2)*(n-1))/2;
    if(cnt<k){
    cout<<"-1"<<endl;
    }
    else{
        k = cnt-k;
        cout<<k+n-1<<endl;
        REP(i,2,n+1){
        cout<<1<<" "<<i<<endl;
        }
        if(k!=0){
        for(int i=2;i<=n;i++){
          REP(j,i+1,n+1){
            cout<<i<<" "<<j<<endl;
            k--;
            if(k==0){
              break;
            }
          }
          if(k==0){
            break;
          }
        }
    }
    }
}

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

using namespace std;

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


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

using namespace std;

#define fore(i, s, e) for(int i = s; i < e; i++)

int main() {
    char c; cin >> c;
    if(c == 'A') cout << 'T' << endl;
    if(c == 'T') cout << 'A' << endl;
    if(c == 'C') cout << 'G' << endl;
    if(c == 'G') cout << 'C' << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin >> S;
  int n=S.size();
  int ans=10000;
  for(int i=0;i<n-2;i++){
    string T=S.substr(i,3);
    ans=min(ans,abs(753-stoi(T)));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    long long a, ans=1;

    for(int i=0; i<n; i++){
        scanf("%lld", &a);
    if(a==0){
        ans=0;
        break;
    }
    if(a>1000000000000000000/ans) ans=-1;

    if(ans!=-1) ans*=a;
    }

    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;
using ll = long long int;
using lc = complex<double>;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n;
    cin >> n;
    vector<ll> v(n), w(n);
    for(ll i=0; i<n; i++)
        cin >> v[i] >> w[i];

    ll q;
    cin >> q;
    map<ll,vector<tuple<ll,ll,ll>>> qs;
    set<ll> sss;
    for(ll i=0; i<q; i++) {
        ll x, l;
        cin >> x >> l;
        x--;
        qs[x].push_back({x, l, i});
        while(1) {
            sss.insert(x);
            if(!x) break;
            x = (x-1)/2;
        }
    }

    vector<ll> res(q);

    vector<vector<int>> u(1<<11, vector<int>(1e5+1));
    for(ll i=0; i<min((ll)1<<11, n); i++) {
        for(ll j=1e5; j>=0; j--)
            u[i][j] = max({(ll)u[i][j], (j-w[i] >= 0 ? u[(i-1)/2][j-w[i]] + v[i] : -1), (ll)u[(i-1)/2][j]});
        for(ll j=1; j<=1e5; j++)
            u[i][j] = max(u[i][j], u[i][j-1]);
    }

    auto dfs = [&](auto dfs, ll j, const map<ll,ll> &pre) -> void {

        if(j < 1<<11) {
            if(qs.count(j) > 0)
                for(auto [x, l, i]: qs[j])
                    res[i] = u[j][l];
            if(sss.count(2*j+1)) dfs(dfs, 2*j+1, pre);
            if(sss.count(2*j+2)) dfs(dfs, 2*j+2, pre);
        } else { 
            map<ll,ll> t = pre;
            for(auto [ww, vv]: pre)
                if(ww+w[j] <= 1e5)
                    t[ww + w[j]] = max(t[ww + w[j]], vv + v[j]);

            if(qs.count(j) > 0) {
                for(auto [x, l, i]: qs[j]) {
                    while(x >= 1<<11) x = (x-1)/2;

                    ll r = 0;
                    for(auto &[ww,vv]: t) {
                        if(l - ww < 0) break;

                        r = max(r, vv + u[x][l-ww]);
                    }
                    res[i] = r;
                }
            }
            if(sss.count(2*j+1)) dfs(dfs, 2*j+1, t);
            if(sss.count(2*j+2)) dfs(dfs, 2*j+2, t);
        }
    };
    map<ll,ll> t;
    t[0] = 0;
    dfs(dfs, 0, t);
    for(auto &e: res) cout << e << "\n";
}


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

int main(){
  string S, T;
  cin >> S >> T;
  int len_S = S.length(), len_T = T.length();
  string ST;
  string ans_candidate, ans = "";
  for (int a = 0; a < 100; a++) {
    ans += "z";
  }
  string wrong_ans = ans;
  
  for (int i = 0; i <= len_S - len_T; i++) {
    ST = S.substr(i, len_T);
    ans_candidate = "";
    
    for (int j = 0; j < len_T; j++) {
      if (ST.substr(j, 1) != "?" && ST[j] != T[j]) {
        ans_candidate = "UNRESTORABLE";
        break;
      }
    }
    
    if (ans_candidate == "UNRESTORABLE") continue;
    else {
      ans_candidate = S.substr(0, i) + T + S.substr(i+len_T);
      for (int k = 0; k < len_S; k++) {
        if (ans_candidate.substr(k, 1) == "?") {
          ans_candidate.replace(k, 1, "a");
        }
      }
      if (ans > ans_candidate) {
        ans = ans_candidate;
      }
    }
  }
  
  if (ans == wrong_ans) cout << "UNRESTORABLE";
  else cout << ans;
  return 0;
}

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

int main() {
  long long n,d;
  cin >> n >> d;
  vector<long long> x(n);
  vector<long long> y(n);
  for (int i = 0;i < n;i++){
    cin >> x[i] >> y[i];
  }
  long long ans = 0;
  
  for (int i = 0;i < n;i++){
    if (x[i]*x[i] + y[i]*y[i] <= d*d){
      ans++;
    }
  }

  cout << ans << endl;
  
}



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

#define LL long long

using namespace std;
int main()
{
	LL N, M; cin >> N >> M;
	vector <pair <LL , LL> > A(N);
	for (int i = 0; i < N;i++) {
		cin >> A[i].first >> A[i].second;
	}
	LL ans = 0 ,id =0;
	sort(A.begin(), A.end());
	while (1) {
		if (A[id].second >= M) {
			ans += M * A[id].first;
			break;
		}
		else {
			ans += A[id].second * A[id].first;
			M -= A[id].second;
			A[id].second = 0;
		}
		id++;
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>

int main(){
	int N,i,j;
	scanf("%d",&N);
	char W[101][11];
	for(i=0;i<N;i++)scanf("%s",W[i]);
	
	for(i=0;i<N;i++){
		for(j=i+1;j<N;j++){
			if(strcmp(W[i],W[j])==0){
				printf("No\n");
				return 0;
			}
		}
	}
	
	char last=W[0][strlen(W[0])-1];
	
	for(i=1;i<N;i++){
		if(last!=W[i][0]){
			printf("No\n");
			return 0;
		}
		if(i<N-1)last=W[i][strlen(W[i])-1];
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
import math
#map(int,input().split())
#int(x) for x in input().split()
#for _ in range(int(input())):
n=int(input())
l=[int(x) for x in input().split()]
p=[l[0]]
s=[l[-1]]
for i in range(1,len(l)):
	p.append(p[-1]^l[i])
for i in range(len(l)-2,-1,-1):
	s.append(s[-1]^l[i])
s=s[::-1]
ans=[s[1]]
for i in range(1,len(l)-1):
	ans.append(p[i-1]^s[i+1])
ans.append(p[-2])
print(*ans)





Measured memory_bytes: 135236
#include<stdio.h>
#include<string.h>
int main()
{int a,b,c,d;
 char s[1000];
 while(~scanf("%s",s))
 {a=b=c=d=0;
  int l=strlen(s);
  for(int i=0;i<l;i++)
  {if(s[i]=='N')
   a++;
   if(s[i]=='S')
   b++;
   if(s[i]=='W')
   c++;
   if(s[i]=='E')
   d++;
  }
  if(a!=0&&b!=0&&c!=0&&d!=0)
  printf("Yes\n");
  else if(c!=0&&d!=0&&a==0&&b==0)
  printf("Yes\n");
  else if(a!=0&&b!=0&&c==0&&d==0)
  printf("Yes\n");
  else
  printf("No\n");
 }
 return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main() {
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	int A[N], B[M];
	int a, b;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}
	a = A[0];
	b = B[0];

	for (int i = 0; i < N; i++) {
		a= max(a, A[i]);
	}
	for (int i = 0; i < M; i++) {
		b = min(b, B[i]);
	}
	int P, Q;
	P = max(a, X);
	Q = min(b, Y);
	if (P < Q) {
		cout << "No War" << endl;
	}

	else cout << "War" << endl;

	
	
}

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

typedef pair<int, int> P;

int main(){
    long long X, K, D;
    cin >> X >> K >> D;

    long long ans = 1e15 + 1;

    if(abs(K * D) < abs(X)){
        cout << abs(X) - abs(K * D) << endl;
        return 0;
    }

    for(long long i = 0; i < K; ++i){
        if(abs(X - D) < abs(X + D)){
            X = X - D;
        }else{
            X = X + D;
        }

        if(abs(ans) == abs(X)){
            if((K - i)%2 == 0){
                 if(abs(ans - D) < abs(ans + D)){
                    ans = ans - D;
                }else{
                    ans = ans + D;
                }
            }
            break;
        }
            
        ans = min(abs(ans), abs(X));
    }

    cout << abs(ans) << endl;

    return 0; 
}

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

import re
# 整数の入力
S = input()
S=re.sub('dreamer(?!ase)','',S)
S=re.sub('eraser(?!ase)','',S)
S=S.replace('dream','')
S=S.replace('erase','')
 
if len(S) == 0:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3572
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N int

func main() {
	sc.Split(bufio.ScanWords)

	N = nextInt()
	d := 0
	prev := 0
	a := 26
	r := 26
	for true {
		d++
		if N <= r {
			break
		}
		prev = r
		a *= 26
		r += a
	}

	N = N - prev
	b := powInt(26, d-1)
	alpha := "abcdefghijklmnopqrstuvwxyz"
	ans := ""

	for i := 0; i < d; i++ {
		if i < d-1 {
			//fmt.Println(N, b)
			ans += string(alpha[(N-1)/b])
			N -= ((N - 1) / b) * b
			b /= 26
			continue
		}
		//fmt.Println(N, b)
		ans += string(alpha[N%27-1])
	}

	fmt.Println(ans)

}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    long long int a;
    long long int sum=0;
    long long int max_num;
    cin>>n;
    for (int i=0;i<n;i++) {
        cin>>a;
        if (i==0) {
            max_num=a;
        }
        if (a<max_num) {
            sum+=max_num-a;
        } else if (a>max_num) {
            max_num=a;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;


public class Main {



	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int h = sc.nextInt();
		int w = sc.nextInt();
		int k = sc.nextInt();
		int piece = 1;
		int lineCount = 1;
		String lastAns = "";
		for (int i=0;i<h;i++) {
			String s = sc.next();
			int[] out = new int[w];
			int rightMost = -1;
			for (int j=0;j<w;j++) {
				if (s.charAt(j)=='#') {
					rightMost=j;
				}
			}

			if (rightMost>=0) {
				for (int j=0;j<w;j++) {
					out[j]=piece;
					if (s.charAt(j)=='#' && j!=rightMost) {
						piece++;
					}
				}
				piece++;

				StringBuilder ans = new StringBuilder();
				for (int j=0;j<w;j++) {
					ans.append(out[j]);
					if (j<w-1) {
						ans.append(" ");
					}
				}
				for (int j=0;j<lineCount;j++) {
					System.out.println(ans);
				}
				lineCount=1;
				lastAns = ans.toString();
			} else {
				lineCount++;
			}
		}
		for (int i=0;i<lineCount-1;i++) {
			System.out.println(lastAns);
		}

	}

}

Measured memory_bytes: 36448
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define mod 1000000007
bool isPrime[1000001];
ll power(ll a,ll b)
{
    ll result = 1;
    while(b>0)
    {
        if(b%2)
        {
            result = (a*result)%mod;
        }
        a = (a*a)%mod;
        b = b/2;
    }
    return result;
}
int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
void sieve()
{
    memset(isPrime,1,sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for(int i=2;i*i<=1000000;i++)
    {
        if(isPrime[i])
        {
            for(int j=i*i;j<=1000000;j+=i)
            {
                isPrime[j] = 0;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t,n;
    t = 1;
    for(int i=0;i<t;i++)
    {
        string s1,s2,s3;
        cin>>s1>>s2;
        int a,b;
        cin>>a>>b;
        cin>>s3;
        if(s3==s2)
        {
            b--;
        }
        else
        {
            a--;
        }
        cout<<a<<" "<<b; 
    }
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    string S;
    cin >> S;
    int ans = 0;
    rep(i, 3){
        int j = 0;
        while(i+j < 3 && S[i+j] == 'R') j++;
        chmax(ans, j);
    }
    cout << ans << endl;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	bool path[20][20] = {};
	int m, n;
	cin >> m >> n;
	REP(i, n) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		path[a][b] = true;
	}
	
	
	set<int> s;
	REP(i, m) {
		int ans;
		
		REP(j, m) if (s.find(j) == s.end()) {
			bool f = true;
			REP(k, m) if (path[k][j]) f = false;
			if (f) {
				ans = j;
				REP(k, m) path[j][k] = false;
				s.insert(ans);
				break;
			}
		}
		printf("%d\n", ans + 1);
	}
	
	return 0;
}

Measured memory_bytes: 1224
N = int(input())
num_lis = list(map(int, input().split()))
ans = 0
p = 10**9+7
s = sum(num_lis)
num = 0
for i in range(N):
  num += num_lis[i]
  ans += ((s-num)*num_lis[i])%p
  
print(ans%p)

Measured memory_bytes: 31544
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>> //a(縦行,vector<ll>(横列));
#include<algorithm>//__gcd(a,b)
#include <iostream>
#include <vector>
#include <cstdlib>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

int main(){
   ll n;cin>>n;
   vl a(n);rep(i,n)cin>>a[i];
   ll tw=0;ll fo=0;

   rep(i,n){
       if(a[i]%2==0&&a[i]%4!=0)tw++;
       if(a[i]%4==0)fo++;
   }

   if(tw<2)tw=0;//二個以上ないと使えない
   if(tw>=2)tw--;
   

if(n-1-tw-2*fo>0)cout<<"No"<<endl;
else{cout<<"Yes"<<endl;}
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
using namespace std;
int n,k,x,y;
signed main()
{
	scanf("%d%d%d%d",&n,&k,&x,&y);
	printf("%d",((x*((k>n)?(n):(k)))+(y*(((n-k)>0)?(n-k):(0)))));
	return putchar(10),0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main () {
    int N, tmp;
    int arr[2000000];
    cin >> N;
    for (int i = 0; i < N-1; i ++){
        cin >> tmp;
        arr[tmp - 1] += 1;
    }
    for (int i = 0; i < N; i ++){
        cout << arr[i] << endl;
    }
}

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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"

ll fast_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}
// dsu start

vi root(200001,0);
vi size(200001,1);
int find(int x){while(x!=root[x])x = root[x];return x;}
bool same(int a,int b){return find(a)==find(b);}
void unite(int a, int b){a = find(a);b = find(b);if(size[a]<size[b])swap(a,b);size[a] += size[b];root[b] = a;}

// dsu end
vi vis(200001,0);
vi adj[200001];

int main()
{	
    std::ios::sync_with_stdio(false);
    //string bitstring = std::bitset< 3 >( 7 ).to_string(); <bits> (num)
    //srand(time(0));
    //cin.tie(NULL);
    //cout.tie(NULL);
    int n;
    cin>>n;
    vi cost(n);
    vi value(n);
    for(int i=0; i<n; ++i)
    	cin>>value[i];
    for(int i=0; i<n; ++i)
    	cin>>cost[i];
    int maxi = 0;
    for(int i=1; i<=pows(2,n); ++i)
    {
    	string s = bitstring(i,n);
    	int sumv=0,sumc=0;	
    	//cout<<s<<"\n";
    	for(int i=0; i<s.size(); ++i)
    	{
    		if(s[i]=='1')
    		{
    			sumv+=value[i];
    			sumc+=cost[i];
    		}
    	}
    	//cout<<sumv-sumc<<"\n";
    	maxi = max(sumv-sumc,maxi);
    }
    cout<<maxi<<"\n";
    
}

Measured memory_bytes: 7296
N,X = gets.strip.split.map(&:to_i)

origindata = gets.strip.split.map(&:to_i).sort
data = [(X - origindata[0]).abs]

(1..N - 1).each { |num|
  data[num] = origindata[num] - origindata[num - 1]
}

puts data.inject(:gcd)

Measured memory_bytes: 11008
#include <stdio.h>

int main(){
    double a, b;
    
    scanf("%lf %lf", &a, &b);
    int int_a,int_b;
    int_a = a; int_b = b;
    printf("%d %d %f\n", int_a/int_b, int_a%int_b, a/b);
}


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

typedef string::const_iterator Iterator;

struct parse_error {};

void check_range(int n)
{
  if (n < 0 || 1024 <= n) {
    throw parse_error();
  }
}

int expr(Iterator& it, const Iterator& last);
int term(Iterator& it, const Iterator& last);

int number(Iterator& it, const Iterator& last)
{
  if (it == last) {
    throw parse_error();
  }
  int n = 0;
  while (it != last && isdigit(*it)) {
    n = 2*n + (*it - '0');
    ++it;
    check_range(n);
  }
  return n;
}

int factor(Iterator& it, const Iterator& last)
{
  if (it == last) {
    throw parse_error();
  }
  if (*it == '(') {
    ++it;

    int n = factor(it, last);
    if (it == last) {
      throw parse_error();
    }
    if (*it == '*') {
      while (it != last && *it == '*') {
        ++it;
        n *= factor(it, last);
        check_range(n);
      }
      while (it != last && (*it == '+' || *it == '-')) {
        const char op = *it;
        ++it;
        int m = term(it, last);
        if (op == '+') {
          n += m;
        } else {
          n -= m;
        }
        check_range(n);
      }
    } else if (*it == '+' || *it == '-') {
      while (it != last && (*it == '+' || *it == '-')) {
        const char op = *it;
        ++it;
        int m = term(it, last);
        if (op == '+') {
          n += m;
        } else {
          n -= m;
        }
        check_range(n);
      }
    } else {
      throw parse_error();
    }

    if (it == last || *it != ')') {
      throw parse_error();
    }
    ++it;
    return n;
  } else if (isdigit(*it)) {
    return number(it, last);
  } else {
    throw parse_error();
  }
}

int term(Iterator& it, const Iterator& last)
{
  int n = factor(it, last);
  while (it != last && *it == '*') {
    ++it;
    n *= factor(it, last);
    check_range(n);
  }
  return n;
}

int expr(Iterator& it, const Iterator& last)
{
  int n = term(it, last);
  while (it != last && (*it == '+' || *it == '-')) {
    const char op = *it;
    ++it;
    int m = term(it, last);
    if (op == '+') {
      n += m;
    } else {
      n -= m;
    }
    check_range(n);
  }
  return n;
}

int main()
{
  string s;
  getline(cin, s);
  int a[5];
  static const char tbl[] = "01+-*()";
  int ans = -1;
  for (a[0] = 0; a[0] < 7; a[0]++) {
    for (a[1] = 0; a[1] < 7; a[1]++) {
      for (a[2] = 0; a[2] < 7; a[2]++) {
        for (a[3] = 0; a[3] < 7; a[3]++) {
          for (a[4] = 0; a[4] < 7; a[4]++) {
            string t = s;
            for (int i = 0; i < 5; i++) {
              string::size_type n = t.find('.');
              if (n != string::npos) {
                t[n] = tbl[a[i]];
              }
            }
            try {
              Iterator it = t.begin(), last = t.end();
              int n = expr(it, last);
              if (it == last) {
                ans = max(ans, n);
              }
            } catch (const parse_error&) {
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1248
#include<cstdio>
#include<algorithm>
#include<vector>
#define N_ 101000
using namespace std;
int n, C[N_];
vector<int>E[N_];
struct point {
	long long x;
	int num;
	bool operator<(const point &p)const {
		return x != p.x ? x < p.x : num < p.num;
	}
}w[N_];
long long sum;
void DFS(int a, int d) {
	sum += d;
	for (auto &x : E[a])DFS(x, d + 1);
}
int main() {
	int i;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%lld", &w[i].x);
		w[i].num = i, C[i] = 1;
	}
	sort(w + 1, w + n + 1);
	for (i = n; i > 1; i--) {
		int t = w[i].num;
		long long nx = w[i].x - n + C[t] * 2;
		point tp = { nx,-1 };
		int j =  lower_bound(w + 1, w + n + 1, tp) - w; 
		if (nx >= w[i].x || j<1 || j>n || w[j].x != nx) {
			puts("-1");
			return 0;
		}
		C[w[j].num] += C[t];
		E[w[j].num].push_back(t);
	}
	DFS(w[1].num, 0);
	if (sum != w[1].x)puts("-1");
	else {
		for (i = 1; i <= n; i++)for (auto &x : E[i])printf("%d %d\n", i, x);
	}
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int MOD = 1e9 + 7;

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

    int N;
    cin >> N;
    vector<ll> asum(N + 1);
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        asum[i + 1] = asum[i] + a;
    }

    vector<vector<ll>> dp(N + 3, vector<ll>(N + 3, 1e15));
    vector<vector<int>> p(N + 3, vector<int>(N + 3));
    for (int i = 1; i <= N; ++i) {
        for (int l = 0; l <= N - i; ++l) {
            int r = l + i;
            if (r - l < 2) {
                dp[l][r] = 0;
                p[l][r] = l;
                continue;
            }
            ll sum = asum[r] - asum[l];
            for (int mid = l; mid <= r; ++mid) {
                ll tmp = dp[l][mid] + dp[mid][r] + sum;
                if (dp[l][r] > tmp) {
                    dp[l][r] = tmp;
                    p[l][r] = mid;
                }
            }
        }
    }

    cout << dp[0][N] << endl;

    return 0;
}


Measured memory_bytes: 2176