akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

ll N, Q;
ll A[100005], B[100005], C[100005];
map<ll, ll>mp;

int main() {

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

	cin >> N;
	FOR(i, 0, N)cin >> A[i];

	ll ans = 0;
	FOR(i, 0, N) {
		ans += A[i];
		mp[A[i]]++;
	}


	cin >> Q;
	FOR(i, 0, Q) {
		cin >> B[i] >> C[i];
		ans += mp[B[i]] * (C[i] - B[i]);
		cout << ans  << endl;
		mp[C[i]] += mp[B[i]];
		mp[B[i]] = 0;

	}
	


	return 0;
}


Measured memory_bytes: 11940
n,m = map(int, input().split())
a = set([int(input()) for i in range(m)])

dp = [0]*(n+1)
dp[0] = 1
for i in range(1,n+1):
    dp[i] = (dp[i-1] + dp[i-2]) % (10**9+7)
    if i in a:
        dp[i] = 0
print(dp[n])


Measured memory_bytes: 19000
#include <iostream>

int getMarkIdx(char mark);
char getMark(int markIdx);

int main(int argc, char** argv)
{
	int n;
	std::cin >> n;

	unsigned int c[4] = { 0, 0, 0, 0 };
	for (int i = 0; i < n; ++i)
	{
		char mark;
		int rank;
		std::cin >> mark >> rank;
		int markIdx = getMarkIdx(mark);
		if (markIdx >= 0)
		{
			c[markIdx] |= (1U << (rank - 1));
		}
	}

	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 13; ++j)
		{
			if ((c[i] & (1U << j)) == 0)
			{
				std::cout << getMark(i) << " " << (j + 1) << std::endl;
			}
		}
	}
}

int getMarkIdx(char mark)
{
	switch (mark)
	{
	case 'S': {return 0; }
	case 'H': {return 1; }
	case 'C': {return 2; }
	case 'D': {return 3; }
	default:break;
	}

	return -1;
}

char getMark(int markIdx)
{
	switch (markIdx)
	{
	case 0: {return 'S'; }
	case 1: {return 'H'; }
	case 2: {return 'C'; }
	case 3: {return 'D'; }
	default:break;
	}

	return '\0';
}


Measured memory_bytes: 3048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int main()
{
    int n, i;
    cin >> n >> i;
    cout << (n + 1 - i) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <iostream>
using namespace std;

int main(){
	int n;
	cin >> n;
	int one_lunch = 800;
	int discount = 200;
	int time = 15;
	long x = n * one_lunch;
	long y = ((int)(n/time))*discount;

	cout << x - y << endl;
	return 0;
}


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

int main() {
string N;
cin >> N;
int a = N.size();
vector<int> v(a);

if (N.at(0)=='A' || N.at(0)=='G' || N.at(0)=='C' || N.at(0)=='T')
    v.at(0)=1;
else
v.at(0) = 0;

for (int i = 1; i < a; i++){
    if (N.at(i)=='A' || N.at(i)=='G' || N.at(i)=='C' || N.at(i)=='T'){
        v.at(i) = v.at(i-1)+1;
    }
    else
    v.at(i) = 0;
}

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

cout << v.at(0) << endl;
}

Measured memory_bytes: 256
class UnionFind():
    '''
    UnionFindでグラフの状態を管理する
    '''
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def find_root(self, x):
        '''
        ルートのノードを見つける
        '''
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        '''
        ノード同士を連結する
        '''
        x = self.find_root(x)
        y = self.find_root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1

    def is_same_group(self, x, y):
        '''
        同一のルーツを持つかどうか調査する
        '''
        return self.find_root(x) == self.find_root(y)

    def count(self, x):
        return -self.root[self.find_root(x)]


from heapq import heappop, heappush, heapify

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    union = UnionFind(N)
    for i in range(M):
        x, y = map(int, input().split())
        union.unite(x, y)
    select_node = 2 * (N- M - 1)
    if select_node > N:
        print("Impossible")
        return
    if N - 1 == M:
        print(0)
        return
    node = [0] * N
    qtable = [[] for _ in range(N)]
    allq = []
    for i in range(N):
        node[i] = union.find_root(i)
        heappush(qtable[node[i]], A[i])
    ans = 0
    cnt = 0
    for i in range(N):
        if qtable[i]:
            ans += heappop(qtable[i])
            cnt += 1
        allq.extend(qtable[i])

    heapify(allq)
    for i in range(select_node-cnt):
        ans += heappop(allq)
    print(ans)

main()


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

#define NMAX 305
double dp[NMAX][NMAX][NMAX];

double search(int N, int i, int j, int k) {
	if (i < 0 or j < 0 or k < 0 or i+j+k == 0) return 0.0;
	if (dp[i][j][k] > -INFINITY) return dp[i][j][k];

	double ret = 0.0, exp = (double) N/(i+j+k);
	ret += (search(N, i-1, j,   k  ) + exp) * (double) i/(i+j+k);
	ret += (search(N, i+1, j-1, k  ) + exp) * (double) j/(i+j+k);
	ret += (search(N, i,   j+1, k-1) + exp) * (double) k/(i+j+k);

	return dp[i][j][k] = ret;
}

int main() {
	int N; scanf("%d", &N);
	vector<int> pieces(N), plates(4);

	for (int &ai: pieces) {
		scanf("%d", &ai);
		plates[ai]++;
	}

	fill(&dp[0][0][0],
	     &dp[0][0][0] + sizeof(dp) / sizeof(double),
	     -INFINITY);

	printf("%.10f\n", search(N, plates[1], plates[2], plates[3]));
}


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

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} c(1000005);

int main() {
  int n, m;
  cin >> n >> m;
  mint ans = 0;
  rep(i,n+1) {
    mint now = c(n,i);
    now *= c.p(m,n);
    now *= c.p(m-i,n-i);
    if (i&1) now = -now;
    ans += now;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(void) {
	while(1) {
		int a, b;
		double area, tsubo;
		
		cin >> a;
		if( cin.eof() )		break;
		
		cin >> b;
		area = a * b;
		
		tsubo = area / 3.305785;
		printf("%.6f\n", tsubo);
	}
	
	return 0;
}

Measured memory_bytes: 1192
k,a,b=map(int,input().split())
count=0
if b<=a+2:
    count=k+1
else:
    if k<=a:
        count=k+1
    else:
        x=(k-(a+1))//2
        y=k-2*x-(a+1)
        count=(b-a)*x+b+y

print(count)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main()
{
	//freopen("input.txt", "r", stdin);
	int n;
	cin >> n;
	int room[4][3][10] = {};
	
	for(int i = 0; i < n; i++){
		int b, f, r, v;
		cin >> b >> f >> r >> v;
		room[b - 1][f - 1][r - 1] += v;
	}
	
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 10; k++){
				cout << " " << room[i][j][k];
			}
			cout << endl;
		}
		if(i != 3){
			cout << "####################" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> h(N);
    for(int i = 0; i < N; i++) {
        cin >> h[i];
    }
   reverse(h.begin(),h.end());
   int ans = 0;
   int val = 0;
   for(int i = 1; i < N; i++){
       if(h[i-1] <= h[i]) val++;
       else val = 0;
       ans = max(ans,val);
   }
   cout << ans;
}

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

int main() {
	int n;
	cin >> n;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ll l, r;
		cin >> l >> r;
		ans += r - l + 1;
	}
	cout << ans << endl;
}

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

template <typename T>
struct PrimeFact {
    vector<T> spf;
    PrimeFact(T N) { init(N); }
    void init(T N) { // 前処理。spf を求める
        spf.assign(N + 1, 0);
        for (T i = 0; i <= N; i++) spf[i] = i;
        for (T i = 2; i * i <= N; i++) {
            if (spf[i] == i) {
                for (T j = i * i; j <= N; j += i) {
                    if (spf[j] == j) {
                        spf[j] = i;
                    }
                }
            }
        }
    }
    map<T, T> get(T n) { // nの素因数分解を求める
        map<T, T> m;
        while (n != 1) {
            m[spf[n]]++;
            n /= spf[n];
        }
        return m;
    }
};

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    PrimeFact<ll> pf(n);
    
    for (int c = 1; c < n; c++) {
        ll now = n - c;
        ll tmp = 1;
        for(auto t: pf.get(now)) {
            tmp *= t.second + 1;
        }
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}
/*
g++ -std=c++17 -Wall -Wextra -g -O0 -fsanitize=undefined,address main.cpp && oj t
*/

Measured memory_bytes: 11172
fun main(args: Array<String>) {
    while (true) {
        val (_a, op, _b) = readLine()!!.split(" ")
        val a = _a.toInt()
        val b = _b.toInt()
        if (op == "?")
            break
        val ans = when (op) {
            "+" -> a+b
            "-" -> a-b
            "*" -> a*b
            "/" -> a/b
            else -> 4000001
        }
        println("${ans}")
    }
}


Measured memory_bytes: 32064
package main

import "fmt"

func main() {
	var a, b, x int
	fmt.Scan(&a, &b, &x)

	fmt.Println(f(b, x) - f(a-1, x))
}

func f(n, x int) int {
	if n < 0 {
		return 0
	}
	return n/x + 1
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int calc(int c){
	if( c == 1 )return 1;
	else{
		return 1 + 2 * calc(c/2);
	}
}
signed main(){
	int h;
	cin>>h;
	cout<<calc(h)<<endl;
	return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "3", "1 3 2", "1 2 3" ].parse.expand.solve == "Yes" );
	assert( [ "3", "1 2 3", "2 2 2" ].parse.expand.solve == "No" );
	assert( [ "6", "3 1 2 6 3 4", "2 2 8 3 4 3" ].parse.expand.solve == "Yes" );
	
	assert( [ "4", "2 1 4 3", "1 2 3 4" ].parse.expand.solve == "Yes" );		// 追加ケース
	assert( [ "4", "2 3 4 1", "5 6 6 7" ].parse.expand.solve == "Yes" );		// 追加ケース
	assert( [ "6", "1 3 2 6 5 4", "6 5 4 3 2 1" ].parse.expand.solve == "No" );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	input.popFront;
	auto bs = input.front.split.to!( long[] );
	return tuple( as, bs );
}

auto solve( long[] as, long[] bs )
{
	zip( bs, as ).sort();
	auto aas = as.dup;
	auto aps = iota( as.length.signed ).array;
	zip( aas, aps ).sort();
	
	// 最適に並べ替えても as[i] <= bs[i] にならない場合は絶対No
	foreach( aa, b; lockstep( aas, bs ) )
	{
		if( b < aa ) return "No";
	}
	
	// 最適の状態からswapを1回減らせるならYes
	foreach( i; 1L .. aas.length.signed )
	{
		if( aas[ i ] <= bs[ i - 1 ] ) return "Yes";
	}
	
	// 最大でもN-1回のswapで全要素を並び替えられる
	// swap対象が2グループ以上に分けられるなら (NP[0]-1)+...+(NP[$-1]-1) < N-1 になるのでYes
	auto uft = UnionFindTree( as.length );
	foreach( ai, ap; aps )
	{
		uft.unite( ai, ap );
	}
	if( 2 <= uft.rootnum ) return "Yes";
	
	return "No";
}


// UnionFind木
struct UnionFindTree
{
	long[] ps;
	long[] rs;
	long   rn;
	
	this( long n )
	{
		ps.length = n;
		ps[] = -1;
		rs.length = n;
		rn = n;
	}
	
	long root( long i )
	{
		if( ps[ i ] < 0 ) return i;
		else              return ps[ i ] = root( ps[ i ] );
	}
	
	auto same( long i, long j )
	{
		return root( i ) == root( j );
	}
	
	auto unite( long i, long j )
	{
		i = root( i );
		j = root( j );
		if( i == j ) return;
		if( rs[ i ] < rs[ j ] )
		{
			ps[ j ] += ps[ i ];
			ps[ i ] = j;
		}
		else
		{
			ps[ i ] += ps[ j ];
			ps[ j ] = i;
			if( rs[ i ] == rs[ j ] ) rs[ i ]++;
		}
		rn--;
	}
	
	auto rootnum()
	{
		return rn;
	}
}


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

template<class T> string toStr(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}

struct sorter{
  bool operator()(const pair<int, pair<int,int> > & a, const pair<int,pair<int, int> > & b){
    if(a.second.first == b.second.first){
      return a.second.second < b.second.second;
    }
    else{
      return a.second.first < b.second.first;
    }
  }
};
int main(){
  int n, m, p, y;
  cin>>n>>m;
  vector<pair<int, pair<int,int> > > vec(m);
  for(int i = 0; i < m; ++i){
    cin>>p>>y;
    vec[i] = make_pair(i, make_pair(p, y));
  }
  sort(vec.begin(), vec.end(), sorter());
  vector<string> ans(m, "");
  int pr = 0;
  int cnt = 0;
  int res = 0;
  for(auto x : vec){
    if(x.second.first != pr){
      pr = x.second.first;
      cnt = x.second.first;
      res = 1;
    }
    string xp = toStr(cnt);
    string yp = toStr(res++);
    string t;
    t="";
    if(xp.size() < 6){
      int r = 6 - xp.size();
      while(r != 0){
	t += '0';
	r--;
      }
      t += xp;
      xp = t;
    }
    t = "";
    if(yp.size() < 6){
      int r = 6 - yp.size();
      while(r != 0){
	t += '0';
	r--;
      }
      t += yp;
      yp = t;
    }
    ans[x.first] = xp + yp; 
  }
  for(auto res : ans)cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;string s,t;cin>>n>>s>>t;
  for(int i=n;i>=0;i--){
    if(s.substr(n-i,i)==t.substr(0,i)){
      cout<<n*2-i<<endl;
      break;
    }
  }
}

Measured memory_bytes: 256
a,b,c=map(int,input().split())
if a==b==c and a%2==0:
    print(-1)
    exit()
cnt=0
while a%2 == 0 and b%2 == 0 and c%2 == 0:
    a,b,c = (b+c)//2,(a+c)//2,(a+b)//2
    cnt+=1
    
print(cnt)

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

def solve():
    N, M  = map(int, input().split())
    A = sorted(list(map(int, input().split())), reverse=1)
    I = [0,2,5,5,4,5,6,3,7,6]
    dp_a = [0 for _ in range(8)]
    for i in range(2, N+1):
        dp_a[i%8] = max((10*dp_a[j%8]+a for j,a in ((i-I[a], a) for a in A) if j >= 0 and (dp_a[j%8] != 0 or I[a] == i)), default=0)
    res = str(dp_a[i%8])
    return str(res)
if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> opset;
#define SZ(X) ((int)X.size())
#define ALL(I) I.begin(), I.end()
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define eps 1e-12
#define INF 1000000007
#define MXN 200005
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

LL a[MXN], l, n, s[MXN];
LL ans;
inline LL sum(int L, int R){
	if(R < L) return 0LL;
	return s[R] - s[L - 1];
}
LL sol(){
	LL res = 0, cnt;
	for(int i = 1; i <= n; i ++) s[i] = s[i - 1] + a[i];
	for(int i = 1; i <= n; i ++){
		cnt = (n - i) * l;
		LL mid = (i + n) >> 1;
		if((i + n) & 1LL){
			cnt -= sum(mid + 1, n) + sum(mid + 2, n);
			cnt += sum(i, mid) + sum(i + 1, mid);
		} else {
			cnt -= sum(mid + 1, n) * 2;
			cnt += sum(i, mid - 1) + sum(i + 1, mid);
		}
		cnt += a[i];
		res = max(res, cnt);
	}
	return res;
}

int main(){
	scanf("%lld%lld", &l, &n);
	for(int i = 1; i <= n; i ++) scanf("%lld", &a[i]);
	ans = sol();
	for(int i = 1; i <= n; i ++) a[i] = l - a[i];
	reverse(a + 1, a + n + 1);
	ans = max(ans, sol());
	printf("%lld\n", ans);
}



Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
int main()
{
    int n;
    cin>>n;
   ll wt[n],p[n],w;
   cin>>w;
    for(int i=0;i<n;i++){cin>>wt[i];cin>>p[i];}
    
    ll dp[n+1][w+1];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=w;j++)
        {
            if(i==0||j==0)
                dp[i][j]=0;
            else if(j<wt[i-1])
                dp[i][j]=dp[i-1][j];
            else
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-wt[i-1]]+p[i-1]);
        }
    }
  cout<< dp[n][w]<<endl;    

}


Measured memory_bytes: 79104
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);

ll mod_pow(ll a, ll n, ll m = mod) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 10000;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

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


void solve() {
	int n; cin >> n;
	vector<int> ans(n);
	rep1(i, n - 1) {
		int p; cin >> p; p--;
		ans[p]++;
	}
	rep(i, n) {
		cout << ans[i] << "\n";
	}
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(4);
	//init_f();
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 4248
#include<bits/stdc++.h>
using namespace std;
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; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int MOD = 1e9+7;
const long long INF = 1LL << 60;
typedef long long ll;
int main(){
    int n; cin >> n;
    vector<ll> dp(87);
    dp[0]=2;dp[1]=1;
    for (int i = 2; i <= n; i++)
    {
        dp[i]=dp[i-1]+dp[i-2];
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
mod = 10**9+7
x = 0
y = 0

for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            x += 1
            if i < j:
                y += 1

ans = (x*k*(k-1)//2%mod + y*k%mod)%mod
print(ans)

Measured memory_bytes: 3188
def main():
    x, y = map(int, input().split())
    ans = 'No'

    for i in range(x + 1):
        x2 = x - i 
        if 4 * i + 2 * x2 == y:
            ans = 'Yes'
            break

    print(f'{ans}')


if __name__ == '__main__':
    main()

Measured memory_bytes: 9064
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
	string N;
	input(N);

	if (N.find('7') != -1)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
    return 0;
}

Measured memory_bytes: 3628
// execute g++ main.cpp -std=c++14 -I C:\Users\naoya\Desktop\code\Atcoder
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

template<class T>inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}


char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n; cin >> n;
    ll ans = 0;
    vector<vector<ll> > dist(n, vector<ll>(3));
    vector<ll> xlis(n), ylis(n);
    REP(i, 0, n){
        cin >> xlis[i] >> ylis[i];
        dist[i][0] = xlis[i] + ylis[i];
        dist[i][1] = xlis[i] - ylis[i];
        dist[i][2] = i;
    }
    sort(ALL(dist), [](auto &x, auto &y){return x[0] < y[0];});
    REP(i, 0, n){
        int key = dist[i][2];
        REP(l, 0, min(n, 10)){
            int key1= dist[l][2], key2 = dist[n-1 - l][2];
            chmax(ans, abs(xlis[key] - xlis[key1]) + abs(ylis[key] - ylis[key1]));
            chmax(ans, abs(xlis[key] - xlis[key2]) + abs(ylis[key] - ylis[key2]));
        }
    }
    sort(ALL(dist), [](auto &x, auto &y){return x[1] > y[1];});
    REP(i, 0, n){
        int key = dist[i][2];
        REP(l, 0, min(n, 10)){
            int key1= dist[l][2], key2 = dist[n-1 - l][2];
            chmax(ans, abs(xlis[key] - xlis[key1]) + abs(ylis[key] - ylis[key1]));
            chmax(ans, abs(xlis[key] - xlis[key2]) + abs(ylis[key] - ylis[key2]));
        }
    }
    cout << ans << endl;
}

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

using namespace std;
using std::vector;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b != 0) gcd(b, a%b);
  return b;
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int n, a, b, c; 
vi v(8);

int calc(int cnt, int x, int y, int z){
  
  if(cnt == n){
    if(x > 0 and y > 0 and z > 0)
      return abs(a - x) + abs(b - y) + abs(c - z);
    return inf;
  }

  int ret = calc(cnt + 1, x, y, z);
  int ret1 = calc(cnt + 1, x + v[cnt], y, z) + (x ? 10: 0);
  int ret2 = calc(cnt + 1, x, y + v[cnt], z) + (y ? 10: 0);
  int ret3 = calc(cnt + 1, x, y, z + v[cnt]) + (z ? 10: 0);

  return min(ret, min(ret1, min(ret2, ret3)));

}


int main(){
 
  cin >> n >> a >> b >> c;

  rep(i, n) cin >> v[i];

  pr(calc(0, 0, 0, 0));

  return 0;
}


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

using namespace std;

const double PI = 3.141592;
const int MAX_N = 1e5+5;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

const bool dbgEnabled = false;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef pair<string, ll> psi;
typedef pair<ll, string> pis;
typedef vector<pii> vpii;
typedef vector<psi> vpsi;
typedef vector<pis> vpis;
typedef vector<vi> vvi;

// Debug macros
#define dbg(x) do { \
	if (dbgEnabled) { cerr << #x << ": " << x << "\n"; } \
} while (0)

#define dbgv(x) do { \
	if (dbgEnabled) { cerr << #x << ": [ "; for (auto& _ : x) cerr << _ << " "; cerr << "]\n"; } \
} while (0)

#define dbgvv(x) do { \
	if (dbgEnabled) { cerr << #x << ":\n[\n"; for (auto& __ : x) dbgv(__); cerr << "]\n";} \
} while (0)

void solve() {
	ll n; cin >> n;
	vi a(n); for (auto &x : a) cin >> x;
	ll suffixSum = a[n-1];
	ll res = 0;
	for (ll i = n-2; i >= 0; i--) {
		res = (res + ((a[i] * suffixSum)%MOD))%MOD;
		suffixSum = (suffixSum + a[i])%MOD;
	}
	cout << res << endl;
}

int main() {
	if (!dbgEnabled) {
		ios_base::sync_with_stdio(false);
		cin.tie(nullptr); cout.tie(nullptr);
	}
	
	ll t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}    
    return 0;
}



Measured memory_bytes: 4768
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
    int c=0;
for(int i=0;i<s.size();i+=2){
    if(s[i]=='h'&&s[i+1]=='i'&&s[i+2]!='i') c=1;
else{
        
    c=0;
            break;
        }
}
    if(c) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 256
a = input()
b = raw_input()
x = 0
for i in range(1,a):
    z = b[0:i]
    y = b[i:a]
    arr = []
    for l in y:
        for m in z:
            if l == m and l not in arr:
                arr.append(l)
    if len(arr) > x:
        x = len(arr)
print x

Measured memory_bytes: 2568
def main():
  n=list(input())
  n=[int(i) for i in n]
  l=len(n)
  
  dp=[[0]*2 for _ in range(l+1)]
  if n[0]>=5:
    dp[0][1]=1
    
  for i in range(l):
      dp[i+1][0]=min(dp[i][0]+n[i],dp[i][1]+10-n[i])
      dp[i+1][1]=min(dp[i][0]+n[i]+1,dp[i][1]+9-n[i])
      
  #print(dp)
  print(dp[l][0])

if __name__=='__main__':
    main()


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}

int main(){
    ll N; cin>>N;
    map<ll,ll> m;
    rep(i,N){
        ll A; cin>>A;
        m[A]++;
    }
    map<ll,ll> n(m);//コピー

    //mは0の確認用、nは本物
    ll SIZE=m.sz;
    if(m[0]==N){
        cout<<"Yes";
        return 0;
    }
    else if(N%3==0){
        if(SIZE==2 && m[0]==N/3){
            cout<<"Yes";
            return 0;
        }
        else if(SIZE==3){
            bool ans=true;
            ll tmp=0;
            for(auto itr=n.bg;itr!=n.ed;itr++){
                if((itr->b)!=N/3) ans=false;

                tmp^=(itr->a);
            }
            if(ans && tmp==0){
                cout<<"Yes";
                return 0;
            }
        }
    }
    cout<<"No";
}

Measured memory_bytes: 9856
import sys
from collections import deque
import copy

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, x] =  [long(input_raw[0]), long(input_raw[1])]
    if x <= 1 or x >= 2*N - 1:
        print 'No'

    else:
        print 'Yes'
        l = [0 for i in range(2*N - 1)]
        m = (2*N-1)/2
        l[m] = x
        already_set = set([x])


        if x + 2 <= 2 * N - 1:
            if m - 1 >= 0:
                l[m - 1] = x + 1
                already_set.add(x + 1)
            if m + 1 < 2*N - 1:
                l[m + 1] = x - 1
                already_set.add(x - 1)
            if m + 2 < 2*N - 1:
                l[m + 2] = x + 2
                already_set.add(x + 2)
        else:
            if m - 1 >= 0:
                l[m - 1] = x - 1
                already_set.add(x - 1)
            if m + 1 < 2*N - 1:
                l[m + 1] = x + 1
                already_set.add(x + 1)
            if m + 2 < 2*N - 1:
                l[m + 2] = x - 2
                already_set.add(x - 2)

        a = 1
        for i in range(2 * N - 1):
            if l[i] == 0:
                while a <= 2*N - 1 :
                    if a not in already_set:
                        print a
                        a += 1
                        break;
                    else:
                        a += 1
            else:
                print l[i]



if __name__ == '__main__':
    main()

Measured memory_bytes: 12024
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    const ll MOD = 1e9+7; 
    int N, X;
    cin >> N >> X;
    vector<ll> S(N);
    for(ll& x: S) cin >> x;
    sort(S.begin(), S.end());

    vector<ll> dp(X+1);
    for(int j=0; j<=X; j++) dp[j] = j % S[0];
    for(int i=1; i<N; i++){
        for(int j=X; j>=0; j--){
            dp[j] = dp[j%S[i]] + dp[j] * i;
            dp[j] %= MOD;
        }
    }
    cout << dp[X] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
using namespace std;

#define MOD 1000000007
#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int a, b, c;
    cin >> a >> b >> c;

    int ans = a + b + c - max({a, b, c});
    int num = max({a, b, c});
    if(num == ans){
        p("Yes");
    }else{
        p("No");
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);
  long long D;
  scanf("%lld", &D);
  long long E;
  scanf("%lld", &E);
  cout << (N - 1) / min({A, B, C, D, E}) + 5 << endl;

  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  string s;cin>>s;
  ll k;cin>>k;
  ll ans=0;
  ll part=1;
  set<char>S;
  rep(i,s.size())S.insert(s[i]);
  if(S.size()==1){
    cout<<k*s.size()/2<<endl;
    return 0;
  }
  for(ll i=1;i<s.size();i++){
    if(s[i]==s[i-1]){
      part++;
      if(i==s.size()-1){
        ans+=part/2;
      }
    }
    else {
      ans+=part/2;
      part=1;
    }
  }
  ans*=k;
  ll a=1;
  for(ll i=1;i<s.size();i++){
    if(s[i]==s[i-1])a++;
    else break;
  }
  reverse(s.begin(),s.end());
  ll b=1;
  for(ll i=1;i<s.size();i++){
    if(s[i]==s[i-1])b++;
    else break;
  }
  //cout<<ans<<endl;
  if(s[0]==s[s.size()-1]){
    ans-=(a/2+b/2-(a+b)/2)*(k-1);
  }
  cout<<ans<<endl;
}
  

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

namespace io {
char buf[1<<21], *p1 = buf, *p2 = buf;
inline char gc() {
    if(p1 != p2) return *p1++;
    p1 = buf;
    p2 = p1 + fread(buf, 1, 1 << 21, stdin);
    return p1 == p2 ? EOF : *p1++;
}
#define G gc

#ifndef ONLINE_JUDGE
#undef G
#define G getchar
#endif

template<class I>
inline void read(I &x) {
    x = 0; I f = 1; char c = G();
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = G(); }
    while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = G(); }
    x *= f;
}

template<class I>
inline void write(I x) {
    if(x == 0) {putchar('0'); return;}
    I tmp = x > 0 ? x : -x;
    if(x < 0) putchar('-');
    int cnt = 0;
    while(tmp > 0) {
        buf[cnt++] = tmp % 10 + '0';
        tmp /= 10;
    }
    while(cnt > 0) putchar(buf[--cnt]);
}

#define in(x) read(x)
#define outn(x) write(x), putchar('\n')
#define out(x) write(x), putchar(' ')

} using namespace io;

#define ll long long
const int N = 100010;

int n, d;

int main() {
	read(n); read(d);
	int len = 2 * d + 1;
	if(n % len) outn(n / len + 1);
	else outn(n / len);
}

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

using namespace std;
using ll=long long;
const double eps=0.00001;
int main(){
    int a,b;
    cin>>a>>b;
    for(int c = 0;c < 100000; ++c) {
        if((int)floor(c*0.08)==a&&(int)floor(c*0.1)==b){
            cout<<c<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <stdio.h>
#include <algorithm>
#include <vector>

const int MAX_S = 10000;

struct Block {
  int w;
  int s;
  int v;
};

bool operator < (const Block &a, const Block &b) {
  return a.s + a.w < b.s + b.w; // FIXME
}

int main() {
  int n;
  scanf("%d", &n);
  Block blocks[n];
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &blocks[i].w, &blocks[i].s, &blocks[i].v);
  }
  std::sort(blocks, blocks + n);
  std::vector<long long> maxValue(1 + 2 * MAX_S);
  for (int w = 0; w <= 2 * MAX_S; w++) {
    maxValue[w] = INT_MIN;
  }
  maxValue[0] = 0;
  std::vector<long long> newMaxValue(1 + 2 * MAX_S);
  newMaxValue = maxValue;
  for (int i = 0; i < n; i++) {
    for (int w = 0; w <= blocks[i].s; w++) {
      newMaxValue[w + blocks[i].w] = std::max(newMaxValue[w + blocks[i].w],
          maxValue[w] + blocks[i].v);
    }
    maxValue = newMaxValue;
    /*
    for (int w = 0; w <= 10; w++) {
      printf("%12lld", maxValue[w]);
    }
    printf("\n");//*/
  }
  long long answer = 0;
  for (int w = 0; w <= 2 * MAX_S; w++) {
    answer = std::max(answer, maxValue[w]);
  }
  printf("%lld\n", answer);
  return 0;
}


Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    List<Integer> list = new ArrayList<>(N);

    for (int i = 0; i < N; i++) {
      list.add(scan.nextInt());
    }

    Collections.sort(list);
    System.out.println(list.get(N / 2) - list.get(N / 2 - 1));
  }
}


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

typedef long long ll;

using namespace std;

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

template<class T>
using vt = vector<T>;
template<class T>
using vvt = vector<vector<T>>;

#define max 100000
int sumof[max+1];

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;  
}



Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<cstdlib>
#include<map>
#define fs first
#define sc second
using namespace std;

typedef pair<int,int> P;
typedef pair<P,P> P2;


bool v[300][300];
int d[300][300][6];
int dx[7] = {0, 1, 1, 0, -1, -1, 0}; 
int dy[2][7] = { {1, 0, -1, -1, -1, 0, 0},
		{1, 1, 0, -1, 0, 1, 0} };
const int G = 150;

int main(){
  int sx,sy,gx,gy;
  int n,lx,ly,x,y;

  cin >> sx >> sy >> gx >> gy >> n;
  for(int i=0;i<300;i++)
    for(int j=0;j<300;j++){
      v[i][j] = false;
      for(int k=0;k<6;k++)d[i][j][k] = 100000000;
    }

  for(int i=0;i<n;i++){
    cin >> x >> y;
    v[y+G][x+G] = true;
  }
  cin >> lx >> ly;

  deque<P2> q;
  d[sy+G][sx+G][0] = 0;
  q.push_back(P2(P(0,0),P(sy,sx)));

  int ans = -1;
  while(q.size()){
    P2 p = q.front(); q.pop_front();
    int s = p.fs.fs, t = p.fs.sc;
    y = p.sc.fs; x = p.sc.sc;

    if(y==gy && x==gx){
      ans = s;
      break;
    }

    int dir = abs(x*y*t)%6, tt = (t+1)%6;
    for(int i=0;i<7;i++){
      int ty = y+dy[x&1][i], tx = x+dx[i];
      if(ty<-ly || tx<-lx || ly<ty || lx<tx)continue;
      if(v[ty+G][tx+G])continue;

      if(dir == i){
	if(s<d[ty+G][tx+G][tt]){
	  d[ty+G][tx+G][tt] = s;
	  q.push_front(P2(P(s,tt),P(ty,tx)));
	}
      }else{
	if(s+1<d[ty+G][tx+G][tt]){
	  d[ty+G][tx+G][tt] = s+1;
	  q.push_back(P2(P(s+1,tt),P(ty,tx)));
	}
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3548
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val ab = (0 until n).map { sc.next().toLong() to sc.next().toLong() }
    println(problem121c(n, m, ab))
}

fun problem121c(n: Int, m: Int, ab: List<Pair<Long, Long>>): Long {
    val ab = ab.sortedBy { it.first }
    var sum = 0L
    var count = 0L
    for (i in 0 until n) {
        val (a, b) = ab[i]
        if (count + b > m) {
            sum += a * (m - count)
            count += m - count
            break
        }
        sum += a * b
        count += b
    }
    return sum
}

Measured memory_bytes: 87128
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    n, k = map(int, readline().split())
    memo = set()
    cnt = 0
    for _ in range(k):
        d = int(readline())
        memo |= set(map(int, readline().split()))
    for i in range(1, n + 1):
        if i not in memo:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9244
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n;
    cin >> n;
    vector<int> cnt(n + 1, 0);
    for(int i = 2; i <= n; ++i){
        int a;
        cin >> a;
        ++cnt[a];
    }
    for(int i = 1; i <= n; ++i) cout << cnt[i] << endl;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin>>h>>w;
  vector<vector<char>> data(200, vector<char>(200));
   for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> data.at(i).at(j);
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout<<data.at(i).at(j);
    
    
     if(j==w-1) cout<<endl;
  
    }
    for(int j=0;j<w;j++){
      cout<<data.at(i).at(j);
    
    if(j==w-1) cout<<endl;
  }
  }
}

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

//短縮
#define rep(i,n) for(int i=0;i<(n);++i)
//sort()用
#define all(v) v.begin(), v.end()

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> A(N-1);
  rep(i,N-1) cin >> A.at(i);

  vector<int> num(N);

  rep(i,N-1) num.at(A.at(i))++;
  rep(i,N) {
    if(i==0)continue;
    cout << num.at(i) << endl;
  }
  cout << 0 <<endl;

  return 0;
}


Measured memory_bytes: 4844
import java.util.*;
import static java.lang.System.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int num = str.length();
        char ans = str.charAt(num-1);
        if(ans == 's'){
            out.println(str + "es");
        }
        else{
            out.println(str + "s");
        }
    }
}

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

int main()
{
ll n , l , t ;
cin >> n >> l >> t ;
auto mod = [&](ll modx){modx%=l;modx+=l;modx%=l;return modx;};
auto mod2 = [&](ll modx){modx%=n;modx+=n;modx%=n;return modx;};

vector<ll> v;
vector<ll> ans;
ll cnt=0;
rep(i,n){
  ll x , w ;
  cin >> x >> w ;
  if(w==1){
    ans.push_back(mod(x+t));
    cnt+=(x+t)/l;
  }
  else {
    ans.push_back(mod(x-t));
    cnt-=(t-x+l-1)/l;
  }
}
sort(ans.begin(),ans.end());
rep(i,n){
  cout << ans[mod2(i+cnt)] << endl;
}
return 0;
}

Measured memory_bytes: 2164
//Problem Link: http://abc047.contest.atcoder.jp/tasks/abc047_d
//Editorial Link: https://abc047.contest.atcoder.jp/editorial

#include<bits/stdc++.h>

using namespace std;

#define LL long long
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define rep(i,a,b) for(LL i=a;i<=b;++i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

LL n,t,a[100005],mn[100005],sum[100005];

int main()
{
    FIO;
    cin>>n>>t;
    rep(i,1,n) cin>>a[i];
    mn[1]=a[1];
    LL maxsum=0,ans=0;
    rep(i,2,n) mn[i]=min(mn[i-1],a[i]);
    rep(i,1,n) sum[i]=a[i]-mn[i],maxsum=max(maxsum,sum[i]);
    rep(i,1,n) if(sum[i]==maxsum) ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 2560
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define mul min
#define add max
#define n(x) (2-(x))

int I;

int parse(char *p){
  switch(*p){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case 'P': return I%3;
    case 'Q': return I/3%3;
    case 'R': return I/9%3;
    case '-': return n(parse(p+1));
    case '(': {
                int x=0;
                p++;
                char *q=p;
                for(;;p++){
                  if(*p=='(')x++;
                  if(*p==')')x--;
                  if(x==0&&*p!='-')break;
                }
                p++;
                switch(*p){
                  case '*': return mul(parse(q),parse(p+1));
                  case '+': return add(parse(q),parse(p+1));
                }
              }
  }
}

int main(){
  char p[81];
  int s;
  while(1){
    s=0;
    scanf("%s",p);
    if(*p=='.')return 0;
    for(I=0;I<27;I++)
        if(parse(p)==2)s++;
    printf("%d\n",s);
  }
}

Measured memory_bytes: 536
#include <algorithm>
#include <iostream>
#include <set>

using namespace std;

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

  int N;
  cin >> N;
  set<int> colors;

  int libero = 0;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;

    if (a >= 3200) {
      ++libero;
    } else {
      colors.insert(a / 400);
    }
  }

  int min_colors;
  if(colors.size()){
    min_colors = colors.size();
  }else{
    min_colors = 1;
  }

// int max_colors = min((int)colors.size() + libero, 8);
  int max_colors = (int)colors.size() + libero;

  cout << min_colors << " " << max_colors << endl;
}


Measured memory_bytes: 256