akhauriyash/Code-Regression huggingface dataset:
//fold
#ifndef KHALIL
#include <bits/stdc++.h>
#else
#include "header.h"
#endif
#define endl '\n'
#define mp make_pair
#define tostr(x) static_cast<ostringstream&>((ostringstream()<<dec<<x)).str()
#define rep(i,begin,end) for(auto i = begin;i < end;i++)
#define repr(i,begin,end) for(auto i = begin-1;i >= end;i--)
#define pb push_back
#define sz(a) ((int)(a).size())
#define fi first
#define se second
#define abs(a) ((a) < (0) ? (-1)*(a) : (a))
#define SQ(a) ((a)*(a))
#define eqd(a,b) (abs(a-b)<1e-9)
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename t> t in(t q){cin >> q;return q;}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v){os << "[";for (int i = 0; i < sz(v); ++i) { os << v[i]; if (i != sz(v) - 1) os << ",";}os << "]";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const map<T, S>& v){for (auto it : v)os << "(" << it.first << ":" << it.second << ")";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const pair<T, S>& v){os << "(" << v.first << "," << v.second << ")";return os;}
const long double PI = acosl(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
//endfold
#define  N  (200'005)
#define MOD (1000000000ll + 7ll)
#define OO (1050000000)
#define OOL (1100000000000000000)

//global
int a[N];

int main(){
	//fold
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << setprecision(10);
	//endfold
	int n,m;
	cin >> n >> m;
	int eew = 0;
	rep(i,0,m){
		cin >> a[i];
		if(a[i]&1){
			eew++;
		}
	}
	if(eew == 0){
		vector<int> v;
		vector<int> w;
		v.push_back(a[0]-2);
		v.push_back(1);
		rep(i,1,m){
			v.push_back(a[i]);
		}
		v.push_back(1);
		rep(i,0,sz(v)){
			if(v[i] != 0) w.push_back(v[i]);
		}
		rep(i,0,m){
			cout << a[i] << " ";
		}cout << endl;
		cout << sz(w) << endl;
		rep(i,0,sz(w)){
			cout << w[i] << " ";
		}
		return 0;
	}
	if(eew == 1){
		sort(a,a+m,[](int w,int e){
			return (w&1) > (e&1);
		});
		vector<int> v;
		vector<int> w;
		v.push_back(a[0]-1);
		rep(i,1,m){
			v.push_back(a[i]);
		}
		v.push_back(1);
		rep(i,0,sz(v)){
			if(v[i] != 0) w.push_back(v[i]);
		}
		rep(i,0,m){
			cout << a[i] << " ";
		}cout << endl;
		cout << sz(w) << endl;
		rep(i,0,sz(w)){
			cout << w[i] << " ";
		}
		return 0;
	}
	if(eew == 2){
		vector<int> q;
		rep(i,0,m){
			if(a[i]&1) q.push_back(i);
		}
		vector<int> res = {a[q[0]]};
		vector<int> v;
		vector<int> w;
		rep(i,0,m){
			if(i == q[0] || i == q[1]) continue;
			res.push_back(a[i]);
		}
		res.push_back(a[q[1]]);
		v.push_back(a[q[0]]-1);
		rep(i,1,m-1){
			v.push_back(res[i]);
		}
		v.push_back(a[q[1]]+1);
		rep(i,0,sz(v)){
			if(v[i] != 0) w.push_back(v[i]);
		}
		rep(i,0,m){
			cout << res[i] << " ";
		}cout << endl;
		cout << sz(w) << endl;
		rep(i,0,sz(w)){
			cout << w[i] << " ";
		}
		return 0;
	}
	cout << "Impossible";
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <numeric>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
#include <map>
#include <utility>
#include<functional>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define MOD 1000000007           //10億　= 10^9になってる
#define juu 100000               //10万 10e5
#define hyaku 1000000            //100万　10e6
#define mINF -922337200085470000 //llのmax-1桁の小さい方
#define pINF 922337203600070000  //llのmax-1桁のデカい方
#define uINF 1844674407300000000 //ullのmax-1桁してる
#define pi 3.1415926535897932384
#define all(v) v.begin(), v.end()
ll factor[300];
ll memory[300];
/*素朴法で計算
factorは必ずmemset(factor,0,sizeof(factor));
グローバルであるmemoryに個数を書き込む
memory配列の走査にはfactorの要素を使う*/
void primefac(ll num)
{
    int i = 0, kosuu = 0;
    while (*(factor + i) != 0)
    {
        while (num % *(factor + i) == 0)
        {
            num /= *(factor + i);
            memory[*(factor + i)] += 1;
        }
        if (num == 1)
            break;
        i++;
    }
}
/*グローバルにあるfactorに素数書き込む.個数を返すので配列は-1しろforは<*/
int elast(ll number)
{
    ll tmp = 0;
    int flag = 0;
    *factor = 2;
    for (int i = 3; i <= number; i++)
    {
        flag = 0;
        for (int j = 0; j <= tmp; j++)
        {
            if (i % (*(factor + j)) == 0)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
            continue;
        tmp += 1;
        *(factor + tmp) = i;
    }
    return tmp + 2;
}

/*intで収まる範囲であってくれ*/
ll nCr(ll n, ll r)
{
    ll val = 1;
    ll i;
    if (r == 0)
        return 1;
    for (i = 0; i < n - r; i++)
    {
        val *= (n - i);
        val /= (i + 1);
    }
    return val;
}
/*intで収まる範囲であってくれ*/
ll nPr(ll n, ll r)
{
    ll val = 1;
    ll i;
    for (i = 0; i < r; i++)
    {
        val *= (n - i);
    }
    return val;
}
template <typename T>
bool chmin(T &a, const T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
bool chmax(T &a, const T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

/*ソートして被りを無くす*/
template <typename T>
void eraseSame(T &a)
{
    sort(all(a));
    a.erase(unique(all(a)), a.end());
}

/*aとbで大きい方を後ろにする。変更なしならtrue、ありならfalse */
template <typename T>
bool swapmax(T &a, T &b)
{
    T temp;
    temp = a;
    if (a > b)
    {
        a = b;
        b = temp;
        return false;
    }
    return true;
}
ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

/*一行に入力が何個あるかを1,ぶち込むvectorを2*/
template <typename T>
void splitIn(ll N, vector<T> &array)
{
    T temp;
    int i = 0;
    array.resize(N);
    while (cin >> temp)
    {
        array[i] = temp;
        i++;
        if (i >= N)
        {
            break;
        }
    }
    return;
}
int main()
{
    char s;
    int n ;
    cin >> s;
    s++;
    cout << s;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2 * 100 * 1000 + 10;
int travail[MAXN];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int N , nbfois , refuse;
	cin >> N >> nbfois >> refuse;
	string s;
	cin >> s;
	int in = 0;
	for (int i = 0 ; i < N ; i++) travail[i] = -1;
	for (int i = 0 ; i < nbfois ; i++)
	{
		while (s[in] == 'x') in++;
		travail[in] = i;
		in+=1 + refuse;
	}
	in = N - 1;
	vector <int> sortie;
	for (int i = nbfois - 1 ; i >= 0 ; i--)
	{
		while (s[in] == 'x') in--;
		if (travail[in] == i) sortie.push_back(in + 1);
		in--;
		in-=refuse;
	}
	sort(sortie.begin() , sortie.end());
	for (auto it : sortie)
	{
		cout<<it<<endl;
	}
}

Measured memory_bytes: 3468
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
int ans = 0;
int i_index;
int tmp;
int main(){
    cin >> N;
    int a[N];
    rep(i, N) cin >> a[i];
    int sum[100010] = {0};
    rep(i, N){
        sum[a[i]]++;
        if(a[i] - 1 >= 0)
            sum[a[i] - 1]++;
        if(a[i] + 1 <= 100000)
            sum[a[i] + 1]++;
    }
    ll maxv = sum[0];
    rrep(i, 1, 100002){
        if(sum[i] != 0){
            if(maxv < sum[i])
                maxv = sum[i];
        }
    }
    cout << maxv << endl;
    return 0;
}

Measured memory_bytes: 1024
import math
n,m=map(int,input().split())
if abs(n-m)>=2:
  print(0)
elif abs(n-m)==1:
  print(math.factorial(n)*math.factorial(m)%(10**9+7))
else:
  print(math.factorial(n)*math.factorial(m)*2%(10**9+7))

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	const int mod = 998244353;
	int k, n; cin >> k >> n;
	vector<int> p2(k + 1, 1);
	vector<int> ii(k + n + 1, 1);
	auto modExp = [&](int a, int n) {
		int b = 1;
		for (; n; n >>= 1, a = (long long)a * a % mod) if (n & 1) b = (long long)b * a % mod;
		return b;
	};
	for (int i = 1; i <= k + n; i++) {
		ii[i] = modExp(i, mod - 2);
	}
	for (int i = 1; i <= k; i++) {
		p2[i] = p2[i - 1] * 2 % mod;
	}
	vector<vector<int>> ft(2, vector<int>(k, 0));
	for (int t = 0; t <= k / 2; t++) {
		long long f = 0, f2 = 0;
		long long C = 1;
		int tt = n + k - 2 * t - 1, tt2 = n + k - 2 * t - 3;
		vector<int> cn(tt + 5, 0), cn2(tt2 + 5, 0);
		cn[0] = 1;
		for (int i = 0; i < tt; i++) {
			cn[i + 1] = (long long)cn[i] * (tt - i) % mod * ii[i + 1] % mod;
		}
		cn2[0] = tt2 >= 0;
		if (tt2 >= 0)
		for (int i = 0; i < tt2; i++) {
			cn2[i + 1] = (long long)cn2[i] * (tt2 - i) % mod * ii[i + 1] % mod;
		}
		for (int i = 0; i <= t; i++) {
			int cc1 = (n >= i ? cn[n - i] : 0), cc2 = (n >= i + 2 ? cn2[n - i - 2] : 0);
			f = (f + C * p2[i] % mod * cc1) % mod;
			f2 = (f2 + C * p2[i] % mod * (cc1 - cc2)) % mod;
			C = C * (t - i) % mod * ii[i + 1] % mod;
		}
		ft[0][t] = f;
		ft[1][t] = (f2 + mod) % mod;
	}
	for (int i = 2; i <= 2 * k; i++) {
		int c = 0;
		for (int j = 1; j <= k; j++) {
			if (i - j >= 1 && i - j <= k) c++;
		}
		cout << ft[c & 1][c / 2] << "\n";
	}
	return 0;
}


Measured memory_bytes: 3696
n = int(input())
h = list(map(int, input().split()))
dp = [0] * n
dp[1] = abs(h[1] - h[0])
for i in range(2,n):
    dp[i] = min((abs(h[i] - h[i-1]) + dp[i-1]),(abs(h[i] - h[i-2]) + dp[i-2]))
print(dp[n-1])

Measured memory_bytes: 13928
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        ArrayList<ArrayList<Integer>> passages = new ArrayList<ArrayList<Integer>>();
        for (int i = 0; i < N - 1; i++) {
            passages.add(new ArrayList<Integer>());
        }
        for (int i = 0; i < M; i++) {
            int s = sc.nextInt();
            int t = sc.nextInt();
            passages.get(s-1).add(t-1);
        }

        // no blocking
        double[] E = new double[N];
        for (int i = N - 2; i >= 0; i--) {
            double sum = 0;
            for (int dest: passages.get(i)) {
                sum += E[dest];
            }
            E[i] = sum / passages.get(i).size() + 1;
        }

        double minE = E[0];

        // with blocking
        for (int i = 0; i < N - 1; i++) {
            int len = passages.get(i).size();
            if (len == 1) {
                continue;
            }
            double maxE = 0;
            for (int dest: passages.get(i)) {
                maxE = Math.max(maxE, E[dest]);
            }
            E[i] = ((E[i] - 1) * len - maxE) / (len - 1) + 1;
            if (i > 0) {
                for (int j = i - 1; j >= 0; j--) {
                    double sum = 0;
                    for (int dest: passages.get(j)) {
                        sum += E[dest];
                    }
                    E[j] = sum / passages.get(j).size() + 1;
                }
            }
            minE = Math.min(minE, E[0]);
        }

        System.out.println(minE);
    }
}


Measured memory_bytes: 96572
N, M = map(int, input().split())

# 隣接リスト
# node iとつながってるnodeはnei_L[i - 1]に入ってる
nei_L = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    nei_L[a - 1].append(b - 1)
    nei_L[b - 1].append(a - 1)

ans = 0
visited = [0] * N

def dfs(now=0):
    global visited, ans
    visited[now] = 1
    if all(visited):
        ans += 1
        # visited = [0] * N
    else:
        cand = nei_L[now]
        for c in cand:
            if not visited[c]:
                dfs(c)
    visited[now] = 0

dfs()
print(ans)


Measured memory_bytes: 3064
#! python3
#  solve_119_B.py

N = int(input())
money = 0

for i in range(N):
    value,money_type = map(str,input().split())
    if money_type == "JPY":
        money += int(value)
    elif money_type == "BTC":
        money += float(value) * 380000
        
print(money)

Measured memory_bytes: 9156
import Control.Monad

main = do
  [a,b,c,d] <- replicateM 4 readLn :: IO [Int]
  print $ (length . filter (== d) . map (\(x,y,z) -> x * 500 + y * 100 + z * 50)) [(x,y,z) | x <- [0..a], y <- [0..b], z <- [0..c]]


Measured memory_bytes: 508
#include<cstdio>
#include<iostream>
using namespace std;
#define MAX 150
int main(){
    long long int A[MAX][MAX];
    long long int B[MAX][MAX];
    long long int C[MAX][MAX];
    int n,m,l=0;
    scanf("%d %d %d",&n,&m,&l);
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d",&A[i][j]);
        }
    }
    for(int j=0;j<m;j++){
        for(int k=0;k<l;k++){
            scanf("%d",&B[j][k]);
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            for(int k=0;k<m;k++){
                C[i][j] +=A[i][k]*B[k][j];
            }
        }
    }
    for(int i =0;i<n;i++){
        for(int j=0;j<l;j++){
            if(j == l-1) printf("%lld",C[i][j]);
            else printf("%lld ",C[i][j]);
        }
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 3568
#include<iostream>
#include<string>

using namespace std;

int main()
{
	string s;
	int alphabets[26] = { 0 };
	char up = 'A', low = 'a';

	while (getline(cin, s)) {
		for (int i = 0; i < s.length(); i++) {
			up = 'A'; low = 'a';
			for (int j = 0; j < 26; j++) {
				if (s[i] == up || s[i] == low) alphabets[j]++;
				up++;
				low++;
			}
		}
	}

	low = 'a';
	for (int i = 0; i < 26; i++) {
		cout << low++ << " : " << alphabets[i] << "\n";
	}
}

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

int A[2000000],hsize=0;

void insert(int key){
  int i=hsize;
  A[i]=key;
  hsize++;
  while(i>0&&A[i]>A[(i-1)/2]){
    swap(A[i],A[(i-1)/2]);
    i=(i-1)/2;
  }
}

void modheap(int i){
  int l=i*2+1;
  int r=i*2+2;
  int larger = i;
  if (l<hsize&&A[larger]<A[l])larger=l;
  if (r<hsize&&A[larger]<A[r])larger=r;
  if (larger!=i){
    swap(A[larger],A[i]);
    modheap(larger);
  }
}

int extract(){
  int i=0;
  int ret=A[0];
  A[0]=A[hsize-1];
  hsize--;
  modheap(0);
  return ret;
}

int main(){
  char cmd[10];
  int key;
  
  while (true){
    cin >> cmd;
    if (cmd[0]=='i'){
      cin >> key;
      insert(key);
    }else if(cmd[1]=='x'){
      cout << extract() << endl;
    }else{
      break;
    }
  }
  
  return 0;
}

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

int maxHeight(vector<int>::iterator begin , vector<int>::iterator end)
{
    int ret = 0;
    while (begin != end)
    {
        ret = max(ret, *begin);
        begin++;
    }
    return ret;
}

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

    vector<int> heights(n);
    for (auto& height : heights)
    {
        cin >> height;
    }

    int count = 0;
    for (int i=0; i < heights.size(); i++)
    {
        if (maxHeight(heights.begin(), heights.begin()+i+1) == heights[i])
        {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
int a,b;
scanf("%d",&a);
scanf("%d",&b);
if(a<b){
printf("a < b\n");
}
if(a>b){
printf("a > b\n");
}
if(a==b){
printf("a == b\n");
}
return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int a, s, t;

int main(){
	REP(i, 8){
		cin >> a;
		(i < 4) ? s += a : t += a;
	}
	cout << max(s, t) << endl;
}

Measured memory_bytes: 1164
#include<iostream>
#define MAX 100000

int parent(int i) {return i / 2;}
int left(int i) {return 2 * i;}
int right(int i) {return i * 2 + 1;}

int main(){
	int i, H, A[MAX+1];
	std::cin >> H;
	for(i = 1; i <= H; ++i)std::cin >> A[i];
	for(i = 1; i <= H; ++i){
		std::cout << "node " << i << ": key = " << A[i] << ", ";
		if(parent(i) >= 1) std::cout << "parent key = " << A[parent(i)] << ", ";
		if(left(i) <= H) std::cout << "left key = " << A[left(i)] << ", ";
		if(right(i) <= H) std::cout << "right key = " << A[right(i)] << ", ";
		std::cout << std::endl;
	}
	return 0;
}	

Measured memory_bytes: 1168
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> pii;

vector<int> seg;
int n;

void update(int x, int y) {
	x += n-1;
	seg[x] = y;
	while(x > 0) {
		x = (x-1)/2;
		seg[x] = min(seg[x*2+1], seg[x*2+2]);
	}
}

int find(int a, int b, int k, int l, int r) {
	if(b<=l || r<=a) return INT_MAX;
	if(a<=l && r<=b) return seg[k];
	return min( find(a,b,k*2+1,l,(l+r)/2), find(a,b,k*2+2,(l+r)/2,r) );
}

int main() {
	int q;
	cin >> n >> q;
	int _n = 1;
	while(_n < n) _n *= 2;
	n = _n;
	seg.resize(_n*2-1, INT_MAX);
	rep(i, q) {
		int c, x, y;
		cin >> c >> x >> y;
		if(c == 0) {
			update(x, y);
		} else {
			cout << find(x, y+1, 0, 0, n) << endl;
		}
	}
	return 0;
}

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

using namespace std;

struct INIT{
    INIT(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed;
	cout<<setprecision(10);
    }
}init;

#define rep(i,n) for(auto i=(n)*0;i<n;i++)
#define range(it,v) for(auto &it:v)

#define IL inline
typedef double D;
typedef bool B;
typedef complex<double> P;
#define T tuple
typedef T<P,P> L;
typedef T<P,P> LS;
typedef T<P,D> C;
typedef vector<P> Poly;
const D eps=1e-8;
#define X real()
#define Y imag()
IL B comp(const P& l,const P& r){
    return (l.X==r.X)?l.Y<r.Y:l.X<r.X;
}
IL D dot(P a,P b) {return a.X*b.X + a.Y*b.Y;}
IL D cross(P a,P b) {return a.X*b.Y - a.Y*b.X;}

IL B ccw(P a,P b,P c){
    c-=b,b-=a;
    return cross(b,c)>eps;
}
IL B cww(P a,P b, P c){
    c-=b,b-=a;
    return cross(b,c)>-eps;
}

IL D signed_distance_P_L(P p,L l){
    P a,b,c=p;
    tie(a,b)=l;
    return cross(b-a,c-a)/abs(b-a);
}
IL B isintersected_L_LS(L l,LS ls){
    P a,b,c,d;
    tie(a,b)=l;
    tie(c,d)=ls;
    return cww(a,b,c)==ccw(b,a,d)||cww(a,b,d)==ccw(b,a,c);
}
IL P cross_point_L_L(L p,L q){
    P a,b;
    tie(a,b)=p;
    D d1=signed_distance_P_L(a,q);
    D d2=signed_distance_P_L(b,q);
    return (a*d2-b*d1)/(d2-d1);
}
IL Poly convex_hull(Poly p){
    int n=p.size();
    if(n==0)return Poly();
    Poly res(2*n);
    int k=0;
    sort(p.begin(),p.end(),comp);
    rep(i,n){
	while(k>1&&!ccw(res[k-2],res[k-1],p[i]))k--;
	res[k++]=p[i];
    }
    int t=k;
    for(int i=n-2;i>=0;i--){
	while(k>t&&!ccw(res[k-2],res[k-1],p[i]))k--;
	res[k++]=p[i];
    }
    res.resize(k-1);
    return res;
}
IL D convex_area(Poly& l){
    D res=0;
    int n=l.size();
    for(int i=2;i<n;i++)
	res+=abs(cross(l[i-1]-l[0],l[i]-l[i-1]))/2.0;
    return res;
}

int main(){
    int n;
    cin>>n;
    Poly xy(n);
    rep(i,n){
	double x,y;
	cin>>x>>y;
	xy[i]=P(x,y);
    }
    int q;
    cin>>q;
    while(q--){
	double x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	P p1(x1,y1),p2(x2,y2);
	Poly pp;
	range(it,xy)if(cww(p1,p2,it))pp.push_back(it);
	rep(i,n){
	    int j=(i+1)%n;
	    if(isintersected_L_LS(L(p1,p2),LS(xy[i],xy[j])))
		pp.push_back(cross_point_L_L(L(p1,p2),LS(xy[i],xy[j])));
	}
	//range(it,pp)cout<<it<<endl;cout<<endl;
	auto ch=convex_hull(pp);
	//range(it,ch)cout<<it<<endl;cout<<endl;
	cout<<convex_area(ch)<<endl;
    }
}

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

int main()
{
	int a,counter=0,tinggi=0;
	cin >> a;
	int arr[a+10];
	for(int i=0;i<a;i++)
	{
		cin >> arr[i];
		if(arr[i]>=tinggi)
		{
			counter++;
			tinggi=arr[i];
		}
	}
	cout << counter << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int e[60][3]={
{19,20,1},
{19,20,0},
{18,19,2},
{18,19,0},
{17,18,4},
{17,18,0},
{16,17,8},
{16,17,0},
{15,16,16},
{15,16,0},
{14,15,32},
{14,15,0},
{13,14,64},
{13,14,0},
{12,13,128},
{12,13,0},
{11,12,256},
{11,12,0},
{10,11,512},
{10,11,0},
{9,10,1024},
{9,10,0},
{8,9,2048},
{8,9,0},
{7,8,4096},
{7,8,0},
{6,7,8192},
{6,7,0},
{5,6,16384},
{5,6,0},
{4,5,32768},
{4,5,0},
{3,4,65536},
{3,4,0},
{2,3,131072},
{2,3,0}
},cnt=36;
void add(int u,int v,int w){e[cnt][0]=u,e[cnt][1]=v,e[cnt][2]=w,cnt++;}
int main(){
	int l,tot=0;
	scanf("%d",&l);
	if((l>>19)&1){
		add(1,2,0);
		add(1,2,1<<18);
		tot+=(1<<19);
	}
	for(int i=18;i>=0;i--){
		if((l>>i)&1){
			add(1,20-i,tot);
			tot+=(1<<i);
		}
	}
	printf("%d %d\n",20,cnt);
	for(int i=0;i<cnt;i++)printf("%d %d %d\n",e[i][0],e[i][1],e[i][2]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, K;
  cin >> N >> K;
  vector<long> data(100000);
  long a, b;
  for(int i = 0; i < N; i++) {
    cin >> a >> b;
    data.at(a - 1) += b;
  }
  long count = 0;
  for(int i = 0; i < data.size(); i++) {
    if(data.at(i) + count < K) count += data.at(i);
    else {
      cout << i + 1 << endl;
      break;
    }
  }
  
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;
 
void solve(){
 
}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    vector<int> a(100001);
    vector<int> b(100001);
    rep(i,100001){
        a[i] = 0;
        b[i] = 0;
    }
    for(int i=0;i<n-1;i+=2){
        a[v[i]] += 1;
        b[v[i+1]] += 1;
    }
    pair<int,int> a1,a2,b1,b2;
    a1 = make_pair(0,0);
    a2 = make_pair(0,0);
    b1 = make_pair(0,0);
    b2 = make_pair(0,0);
    rep(i,100001){
        // if(a[i]!=0){
        //     cout << "a "  << i << " "<<  a[i] << endl;
        // }
        // if(b[i]!=0){
        //     cout << "b " << i << " " <<  b[i] << endl;
        // }
            
        if(a1.first<a[i]){
            a2.first = a1.first;
            a2.second = a1.second;
            a1.first = a[i];
            a1.second = i;
        }else if(a2.first<a[i]){
            a2.first = a[i];
            a2.second = i;
        }
        if(b1.first<b[i]){
            b2.first = b1.first;
            b2.second = b1.second;
            b1.first = b[i];
            b1.second = i;
        }else if(b2.first<b[i]){
            b2.first = b[i];
            b2.second = i;
        }
    }
    // cout << a1.first << " " << a1.second << endl;
    // cout << b1.first << " " << b1.second << endl;
    if(a1.second!=b1.second){
        cout << n - a1.first - b1.first << endl;
    }else{
        int ans = max ( a1.first+b2.first,a2.first+b1.first);
        cout << n - ans << endl;
    }
 
    return 0;
}

Measured memory_bytes: 4520
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,flag=1;
	cin>>n;
	char s[n];
	for(int i=0;i<n;i++) cin>>s[i];
	if(n%2==1){
		cout<<"No"<<endl;
		return 0;
	} 
	for(int i=0;i<n/2;i++){
		if (s[i]!=s[i+(n/2)])  flag=0;
	}
	if(flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n;
  cin >> n;
  char c[n];
  REP(i, n){
    cin >> c[i];
    if(c[i] == 'Y'){
      cout << "Four";
      return 0;
    }
  }
  cout << "Three";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define SwMAX 10
#define LtMAX 10
bool sw[SwMAX];
int howMany[LtMAX];                      // = {0, 0};
bool needSwitch[LtMAX][SwMAX] = {false}; // = {{true, false}, {false, true}};
int N, M;                                //n=>sw m=>lt
int COUNT=0;
bool isShining(int ltNum)
{
    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        if (needSwitch[ltNum][i] && sw[i])
            cnt++;
    }
    if (cnt % 2 == howMany[ltNum])
    {
        //cout << ltNum << ":LIGHTING";
    }
    return cnt % 2 == howMany[ltNum];
}

void dfs(int depth)
{
    if (depth == N)
    {
        for (int i = 0; i < N; i++)
        {
            //cout << "Sw[" << i << "]:" << sw[i] << ",";
        }
        int ok = 0;
        for (int light = 0; light < M; light++)
        {
            if (isShining(light))
                //break;
                ok++;
        }
        if(ok==M) COUNT++;
        //cout << ok << endl;
        return;
    }
    sw[depth] = true;
    dfs(depth + 1);
    sw[depth] = false;
    dfs(depth + 1);
}

int main()
{
    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            int tmp;
            cin >> tmp;
            needSwitch[i][tmp - 1] = true;
        }
    }
    for (int i = 0; i < M; i++)
    {
        cin >> howMany[i];
    }
    dfs(0);
    cout<<COUNT;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    signed main(){
	int n,b[2005],sum=0;
    string s;
    cin>>n;
      for(int i=0;i<n;i++){
        	cin>>b[i];
      }
      sort(b,b +n,greater<int>());
      for(int x=0;x<n-2;x++){
        for(int y=x+1;y<n-1;y++){
          for(int z=y+1;z<n;z++){
            if(b[x]<b[y]+b[z]) sum++;
            else break;
          }
        }
      }
      cout<<sum<<'\n';
      return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // ここにプログラムを追記
  int A, B;
  cin >> A >> B;
  if ((A + B) % 2 == 0){
	cout << (A + B) / 2 << endl;
  } else {
    cout << (A + B) / 2 + 1 << endl;
  }
}

Measured memory_bytes: 3628
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}



fn main() {
    input!{
        n: usize,
        mut s: [chars; n],
    }

    let mut ans = 0u64;
    let mut dict = HashMap::new();

    for mut s_ in s {
        s_.sort();
        *dict.entry(s_).or_insert(0) += 1;
    }

    for (k, v) in dict {
        ans += v * (v-1) / 2; 
    }


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


Measured memory_bytes: 25616
fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val (n, k) = sc.intList()
        val x = Array(n) { sc.nextLong() }
        var ans = Long.MAX_VALUE
        for (i in k - 1 until n) {
            val time = Math.min(Math.abs(x[i - k + 1]), Math.abs(x[i])) + x[i] - x[i - k + 1]
            ans = Math.min(ans, time)
        }

        println(ans)
    }
}


class MyScanner() {
    private var index = 0
    private var line = listOf<String>()

    fun next(): String {
        while (line.size <= index) {
            line = readLine()!!.split(' ')
            index = 0
        }
        return line[index++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun strList(): List<String> {
        index = line.size
        return readLine()!!.split(' ')
    }

    fun intList() = strList().map { it.toInt() }
    fun longList() = strList().map { it.toLong() }
    fun doubleList() = strList().map { it.toDouble() }
}

Measured memory_bytes: 52132
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<vector>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=4e18;
const ll MOD=998244353;
const double EPS=1e-7;

ll N;
ll d[100010];
map<ll,ll> mp;
ll ModPow(ll x,ll n){
    if(n==0)return 1;
    ll res=ModPow(x*x%MOD,n/2);
    if(n&1)res=res*x%MOD;
    return res;
}

int main(){
    cin>>N;
    for(ll i=0;i<N;i++){
        cin>>d[i];
        mp[d[i]]++;
    }
    if(mp[0]!=1 || d[0]!=0){
        cout<<0<<endl;
        return 0;
    }
    ll pre=0;
    ll ans=1;
    for(auto p:mp){
        if(p.first==0)continue;
        if(p.first-pre!=1 || p.second==0){
            cout<<0<<endl;
            return 0;
        }
        ans=(ans*ModPow(mp[pre],p.second))%MOD;
        pre=p.first;
    }
    cout<<ans<<endl;    
    return 0;
}

Measured memory_bytes: 7296
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int)
b = np.array(input().split(), dtype=np.int)
arg = np.argsort(b)
a = a[arg]
b = b[arg]
arg = np.argsort(a)
if np.all(a[arg] <= b):
  i = arg[0]
  cycle_size = 1
  while i != 0:
    i = arg[i]
    cycle_size += 1
  if cycle_size == n and np.all(a[arg[1:]] > b[:-1]):
    print('No')
  else:
    print('Yes')
else:
  print('No')

Measured memory_bytes: 24404
n = int(input())
ans = [0] * (n + 1)
a = [1, 3, 6]
for x in range(1, int(n**0.5) + 1):
    for y in range(x, int(n**0.5) + 1):
        for z in range(y, int(n**0.5) + 1):
            v = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if v <= n:
                ans[v] += a[len(set([x, y, z])) - 1]
print(*ans[1:], sep='\n')

Measured memory_bytes: 9588
n,m = map(int,input().split())
a = sorted(list(map(int,input().split())), reverse=True)
match = [[0,0], [1,2], [2,5], [3,5], [4,4], [5,5], [6,6], [7,3], [8,7], [9,6]]

value = []
cost = []
for i in range(len(a)):
        value.append(a[i])
        cost.append(match[a[i]][1])

dp = ["0"]*(n+1)
dp[0] = ""
for i in range(1,n+1):
    for j in range(len(value)):
        tmp_dp_i = 0
        if i - cost[j] >= 0:
            if i - cost[j] >= 0 and dp[i - cost[j]] != "0":
                tmp_dp_i = str(value[j]) + dp[i-cost[j]]
                if len(dp[i]) < len(tmp_dp_i):
                    dp[i] = tmp_dp_i
                elif dp[i] < tmp_dp_i:
                    dp[i] = tmp_dp_i
print(dp[n])


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

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

  string a, b, c;
  cin >> a >> b >> c;
  
  const int s = 2000, N = 5e4;
  int na = a.size(), nb = b.size(), nc = c.size();
  vector<bool> ab(2 * N, 1), bc(2 * N, 1), ac(2 * N, 1);

  auto match = [&](char l, char r) {
    return (l == r || l == '?' || r == '?');
  };

  for (int i = 0; i < na; ++i) {
    for (int j = 0; j < nb; ++j) {
      if (!match(a[i], b[j])) ab[i - j + N] = 0;
    }
  }

  for (int i = 0; i < na; ++i) {
    for (int j = 0; j < nc; ++j) {
      if (!match(a[i], c[j])) ac[i - j + N] = 0;
    }
  }

  for (int i = 0; i < nb; ++i) {
    for (int j = 0; j < nc; ++j) {
      if (!match(b[i], c[j])) bc[i - j + N] = 0;
    }
  }

  int ans = 3 * s;
  for (int i = -2*s; i <= 2*s; ++i) {
    for (int j = -2*s; j <= 2*s; ++j) {
      if (ab[i + N] && ac[j + N] && bc[j-i+N]) {
        int l = min({0, i, j});
        int r = max({na, i + nb, j + nc});
        ans = min(ans, r - l);
      }
    }
  }

  cout << ans << '\n';
}


Measured memory_bytes: 3692
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		int bitArray[] = new int[32];

		for(int i = 0; x > 0; i++) {
			bitArray[i] = (int)(x % 2);
			x /= 2;
		}

		for(int i = 0; i < 32; i++) {
			System.out.print(bitArray[31 - i]);
		}
		System.out.println();
		for(int i = 0; i < 32; i++) {
			System.out.print(3 % (bitArray[31 - i] + 2));
		}
		System.out.println();
		for(int i = 0; i < 31; i++) {
			System.out.print(bitArray[30 - i]);
		}
		System.out.println(0);
		System.out.print(0);
		for(int i = 0; i < 31; i++) {
			System.out.print(bitArray[31 - i]);
		}
		System.out.println();
	}

}



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

#define rep(x, y) for (int i = (x); i < (y); i++)

typedef long long ll;

using namespace std;

void solve() {
    int n;
    cin >> n;

    int p;
    string s;
    vector<pair<pair<string, int>, int>> r;
    rep(0, n) {
        cin >> s >> p;
        r.push_back(make_pair(make_pair(s, -p), i));
    }

    sort(r.begin(), r.end());

    for (auto ri : r) {
        cout << (ri.second + 1) << endl;
    }
}

int main() {
    solve();

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
//#define int long long

bool solve(){
    int n; cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    reverse(ALL(h));
    
    rep(i,n-1){
        if(h[i] < h[i+1]) h[i+1]--;
        if(h[i] < h[i+1]) return false;
    }
    return true;
}

signed main(){
    cout << (solve() ? "Yes" : "No") << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    char s[200010];
    int posa = -1, posz;
    cin >> s;
    imfor(i, strlen(s)) {
        if (s[i] == 'A' && posa == -1) {
            posa = i;
        }
        else if (s[i] == 'Z') {
            posz = i;
        }
    }
    cout << posz - posa + 1 << endl;
}

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

vector<int> nums[500];
int dp[134001];

int go(vector<int> &vec){
  int n = vec.size();
  if(n == 0)return 0;
  fill(dp, dp + 134001, -(1 << 30));
  dp[0] = 0;
  for(int i = 0;i < n;i++){
    for(int j = 134000 / vec[i] * vec[i];j - vec[i] >= 0;j -= vec[i]){
      dp[j] = max(dp[j], dp[j-vec[i]] + 1);
    }
  }
  int res = 0;
  for(int i = 1;i < 134001;i *= 2){
    res = max(res, dp[i]);
  }
  return res;
}

void solve(int n){
  int a;
  int res = 0;
  for(int i = 0;i < 500;i++){
    nums[i].clear();
  }
  for(int i = 0;i < n;i++){
    cin >> a;
    int odd = a / (a & -a);
    int even = a / odd;
    nums[odd].push_back(even);
  }

  for(int i = 0;i < 500;i++){
    res = max(res, go(nums[i]));
  }
  
  cout << res << endl;
}


int main(){
  while(true){
    int n;
    cin >> n;
    if(n == 0)break;
    solve(n);
  }
  return 0;
}

Measured memory_bytes: 1796
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let s: Vec<char> = util::line().chars().collect();

    let ans = s.windows(2)
        .enumerate()
        .filter_map(|(i, v)| {
            if v[0] != v[1] {
                Some(max(i + 1, s.len() - i - 1))
            } else {
                None
            }
        })
        .min()
        .unwrap_or(s.len());

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


Measured memory_bytes: 4352
from sys import stdin

ntree = []
ans = []


n, q = [int(x) for x in stdin.readline().rstrip().split()]

for i in range(n):
    ntree.append([])
    ans.append(0)

for i in range(n-1):
  a, b = [int(x) for x in stdin.readline().rstrip().split()]
  ntree[a-1].append(b)

for i in range(q):
  p, x = [int(x) for x in stdin.readline().rstrip().split()]
  ans[p-1] += x

for i in range(n):
    for j in range(len(ntree[i])):
       ans[ntree[i][j]-1] += ans[i]

print(' '.join([str(n) for n in ans]))


Measured memory_bytes: 101804
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>

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

using namespace std;

int main(void){
  int n;
  vector<ll> a;
  vector<ll> s;

  cin >> n;
  a.resize(n);
  s.resize(n);
  for(ll &ai : a) cin >> ai;

  s[0] = a[0];
  for(int i = 1; i < a.size(); ++i){
    s[i] = s[i-1] + a[i];
  }

  bool x; //trueが正
  ll dif;
  ll tmp;
  ll ans = 0;

  x = true;
  dif = 0;
  ans = 0;
  for(int i = 0; i < n; i++){
    if(x && s[i]+dif >= 0){
      tmp += s[i]+dif+1;
      dif += -(s[i]+dif+1);
    }else if( !x && s[i]+dif <= 0){
      tmp += -(s[i]+dif-1);
      dif += -(s[i]+dif-1);
    }
    //cout << s[i]+dif << "   tmp : " << tmp << "  dif " << dif << endl;
    x = !x;
  }
  ans = tmp;

  x = false;
  dif = 0;
  tmp = 0;
  for(int i = 0; i < n; i++){
    if(x && s[i]+dif >= 0){
      tmp += s[i]+dif+1;
      dif += -(s[i]+dif+1);
    }else if( !x && s[i]+dif <= 0){
      tmp += -(s[i]+dif-1);
      dif += -(s[i]+dif-1);
    }
   // cout << s[i]+dif << "   tmp : " << tmp << "  dif " << dif << endl;
    x = !x;
  }
  ans = min(ans, tmp);

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


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

int main() {
   std::string s;
   int k;
   std::cin >> s >> k;
   int i = 0;
   while (s.at(i) == '1') {
      i++;
      k--;
      if (k == 0) {
         std::cout << "1" << '\n';
         return 0;
      }
   }
   std::cout << s.at(i) << '\n';

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] points = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long xLength = points[0] - points[2];
            long yLength = points[1] - points[3];
            long x3 = points[2] + yLength;
            long y3 = points[3] - xLength;
            long x4 = points[0] + yLength;
            long y4 = points[1] - xLength;
            Console.WriteLine(x3.ToString()+" "+y3.ToString()+" "+x4.ToString()+" "+y4.ToString());
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


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

using namespace std;

void go(int cx, int cy, const vector<pair<int, int>> &xy,
        const vector<int> &taken, double &res) {
    double cur = sqrt(1LL * cx * cx + 1LL * cy * cy);
    res = max(res, cur);
    for (int i = 0; i < (int)xy.size(); ++i) {
        if (!taken[i]) {
            int nx = cx + xy[i].first, ny = cy + xy[i].second;
            double ncur = sqrt(1LL * nx * nx + 1LL * ny * ny);
            if (ncur > cur) {
                cx = nx;
                cy = ny;
                cur = ncur;
                res = max(res, cur);
            }
        }
    }
}

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

    auto now = chrono::system_clock::now();
    auto now_ms = chrono::time_point_cast<chrono::milliseconds>(now);
    auto epoch = now_ms.time_since_epoch();
    auto value = chrono::duration_cast<chrono::milliseconds>(epoch);
    mt19937 gen(value.count());

    int N;
    cin >> N;
    vector<pair<int, int>> xy(N);
    for (int i = 0; i < N; ++i) {
        cin >> xy[i].first >> xy[i].second;
    }
    double res = 0;
    for (int r = 0; r < 2000; ++r) {
        vector<int> taken(N, 0);
        for (int i = 0; i < N; ++i) {
            taken[i] = 1;
            go(xy[i].first, xy[i].second, xy, taken, res);
            taken[i] = 0;
        }
        shuffle(begin(xy), end(xy), gen);
    }
    cout.precision(17);
    cout << fixed << res << "\n";

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    String ans = "No";
    if(c > (a + b)) {
      long d = c - (a + b);
      d = d * d;
      long e = a * b;
      e = 4 * e;
      if(e < d) ans = "Yes";
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 23124
import std.stdio;
import std.string;
import std.conv;
import std.algorithm.searching;

void main(){
	auto str = readln.chomp;
	if(str.canFind("a") && str.canFind("b") && str.canFind("c")){
		"Yes".writeln;
	}else{
		"No".writeln;
	}
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
	char List[10][9] = {"',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO",
						"pqrsPQRS","tuvTUV","wxyzWXYZ"};
	char mozi[10001], out[10001], tmp[2], o;
	int f1, f2, c, p, oc, i, str;
	
	while(scanf("%s",mozi) != EOF)
	{
		c = 0;
		p = 0;
		oc = 0;
		o = mozi[0];
		while(mozi[c] != '\0')
		{
				while(o == mozi[c])
				{
					c++;
					p++;
				}
				if(o == '0')
				{
					for(f1 = 1; f1 < p; f1++)
					{
						out[oc] = ' ';
						oc++;
					}
				}
				else{
                                                                tmp[0] = o;
					tmp[1] = '\0';
					i = atoi(tmp);
		                                      str = strlen(List[i-1]);
					p =(p-1) % str;		                     	                          out[oc] = List[i-1][p];
					oc++;
				}
				o = mozi[c];
				p = 0;
			}
		out[oc] = '\0';
		printf("%s\n",out);
	}
	return 0;
}

Measured memory_bytes: 0
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>
#include <functional>

#define lnd '\n'
// #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, n) for(ll i = 0; i < n; i++)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mk make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long long int lli;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

template <class T>
T GCD (T a, T b) {
  if(a == 0) return b;
  return GCD(b%a, a);
}

template <class T>
T LCM(T a, T b){
  return a*b/GCM(a,b);
}

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
T modpow(T x, T p, ll mod){
    T res = 1;
    while(p > 0){
        if(p&1) res = (res*x)%mod;
        x = (x*x)%mod;
        p /= 2;
    }
    return res%mod;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

struct HASH{
  size_t operator()(const pair<long,long>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
    if(p1.first != p2.first) return p1.first < p2.first;
    else return p1.second < p2.second;
}

const int INF = std::numeric_limits<int>::max();
const ll M_INF = std::numeric_limits<ll>::min();
const ll LL_INF = std::numeric_limits<ll>::max();

void solution();
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

ll result[200005] = {0};
void fact(ll n) {
   if (n >= 0) {
      result[0] = 1;
      for (ll i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
   }
}

void dfs(ll n, ll m, ll i, vector<ll> &v){
  if(i == n){
  }else{
    for(int k = 1; k <= m; k++){
      v.push_back(k);
      dfs(n, m, i+1, v);
      v.pop_back();
    }
  
  }
}

void solution(){
  string s, t;
  cin >> s >> t;
  if(s.size() == t.size()-1){
      if(s == t.substr(0, s.size())){
          cout << "Yes" << endl;
      }else{
          cout << "No" << endl;
      }
  }else{
      cout << "No" << endl;
  }
}     



Measured memory_bytes: 3136