stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define ll long long

#define For(i,a,b) for (int i=a;i<=b;i++)

#define Rep(i,a,b) for (int i=b;i>=a;i--)

using namespace std;

ll ans;

ll n,x,y;

ll a[100100],b[100100],c[100100];

inline ll read()

{

    ll x=0,f=1;char ch=getchar();

    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();

    return x*f;

}

int main()

{

	n=read();

	For(i,1,n)a[i]=read();

	For(i,1,n)b[i]=read();

	For(i,1,n)c[i]=-read();

	sort(a+1,a+n+1);

	sort(b+1,b+n+1);

	sort(c+1,c+n+1);

	For(i,1,n)c[i]=-c[i];

	x=0;y=n;

	For(i,1,n)

	{

		while(a[x+1]<b[i]&&x<n)x++;

		while(c[y]<=b[i]&&y>0)y--;

		ans+=(x*y);

	}

	cout<<ans<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <queue>

#include <cstdio>

#include <algorithm>

using namespace std;



static const int N = 1e5 + 10;

int n;

int a[N], b[N], c[N], cnt1[N], cnt2[N];



int main ()

{

	scanf ("%d", &n);

	for (int i = 1; i <= n; ++i)

		scanf ("%d", &a[i]);

	for (int i = 1; i <= n; ++i)

		scanf ("%d", &b[i]);

	for (int i = 1; i <= n; ++i)

		scanf ("%d", &c[i]);

	sort (a + 1, a + n + 1);

	sort (b + 1, b + n + 1);

	sort (c + 1, c + n + 1);

	int k = 1;

	for (int i = 1; i <= n; ++i)

	{

		for (; c[k] <= b[i] && k <= n ;)

			++k;

		cnt1[i] = n - k + 1;

	}

	k = 1;

	for (int i = 1; i <= n; ++i)

	{

		for (; a[k] < b[i] && k <= n ;)

			++k;

		cnt2[i] = k - 1;

	}

	long long ans = 0;

	for (int i = 1; i <= n; ++i)

		ans += (long long)cnt1[i] * cnt2[i];

	printf ("%lld", ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<algorithm>

using namespace std;

int n,A[100010],B[100010],C[100010],D[100010],i,j;

long long E[100010],sum=0;

int main(){

    cin>>n;

    for(i=1;i<=n;i++) cin>>A[i];

    for(i=1;i<=n;i++) cin>>B[i];

    for(i=1;i<=n;i++) cin>>C[i];

    sort(A+1,A+1+n);

    sort(B+1,B+1+n);

    sort(C+1,C+1+n);

    for(i=1;i<=n;i++){

        D[i]=C+1+n-upper_bound(C+1,C+1+n,B[i]);

        E[i]=E[i-1]+D[i];

    }

    for(i=1;i<=n;i++){

        if(B+1+n-upper_bound(B+1,B+1+n,A[i])>0){

            sum+=E[n]-E[upper_bound(B+1,B+1+n,A[i])-B-1];

        }

    }

    cout<<sum<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <queue>

#include <cstdio>

#include <algorithm>

using namespace std;



static const int N = 1e5 + 10;

int n;

int a[N], b[N], c[N], cnt1[N], cnt2[N];



int main ()

{

	scanf ("%d", &n);

	for (int i = 1; i <= n; ++i)

		scanf ("%d", &a[i]);

	for (int i = 1; i <= n; ++i)

		scanf ("%d", &b[i]);

	for (int i = 1; i <= n; ++i)

		scanf ("%d", &c[i]);

	sort (a + 1, a + n + 1);

	sort (b + 1, b + n + 1);

	sort (c + 1, c + n + 1);

	int k = 1;

	for (int i = 1; i <= n; ++i)

	{

		for (; c[k] <= b[i] && k <= n ;)

			++k;

		cnt1[i] = n - k + 1;

	}

	k = 1;

	for (int i = 1; i <= n; ++i)

	{

		for (; a[k] < b[i] && k <= n ;)

			++k;

		cnt2[i] = k - 1;

	}

	long long ans = 0;

	for (int i = 1; i <= n; ++i)

		ans += (long long)cnt1[i] * cnt2[i];

	printf ("%lld", ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=1e6+10;

int n,m,a[4][N];

ll ans,cnt[N];



 

int main()

{

//	freopen("in.in","r",stdin);

//	freopen("out.out","w",stdout);

	scanf("%d",&n);

	for(int i=1;i<=3;i++)

		for(int j=1;j<=n;j++)

		scanf("%d",&a[i][j]);

	for(int i=1;i<=3;i++)

		sort(a[i]+1,a[i]+n+1);

	for(int i=1,j=1;j<=n;j++)

	{

		while(a[1][i]<a[2][j]&&i<=n) i++;

		cnt[j]=i-1;

	}

//	for(int i=1;i<=n;i++)

//		printf("cnt=%d\n",cnt[i]);

//改用前缀和（dp思想） 

	for(int i=1;i<=n-1;i++) cnt[i+1]=cnt[i]+cnt[i+1]; 

	for(int i=1,j=1;j<=n;j++)

	{

		while(a[2][i]<a[3][j]&&i<=n) i++;

//		for(int m=1;m<=i-1;m++)

//			ans+=cnt[m] ;

		ans+=cnt[i-1];

	 	

	 } 



	printf("%lld\n",ans);

	return 0;

}

// Optimized solution to the same problem (faster):
#include <queue>

#include <cstdio>

#include <algorithm>

using namespace std;



static const int N = 1e5 + 10;

int n;

int a[N], b[N], c[N], cnt1[N], cnt2[N];



int main ()

{

	scanf ("%d", &n);

	for (int i = 1; i <= n; ++i)

		scanf ("%d", &a[i]);

	for (int i = 1; i <= n; ++i)

		scanf ("%d", &b[i]);

	for (int i = 1; i <= n; ++i)

		scanf ("%d", &c[i]);

	sort (a + 1, a + n + 1);

	sort (b + 1, b + n + 1);

	sort (c + 1, c + n + 1);

	int k = 1;

	for (int i = 1; i <= n; ++i)

	{

		for (; c[k] <= b[i] && k <= n ;)

			++k;

		cnt1[i] = n - k + 1;

	}

	k = 1;

	for (int i = 1; i <= n; ++i)

	{

		for (; a[k] < b[i] && k <= n ;)

			++k;

		cnt2[i] = k - 1;

	}

	long long ans = 0;

	for (int i = 1; i <= n; ++i)

		ans += (long long)cnt1[i] * cnt2[i];

	printf ("%lld", ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<iostream>

#include<string>

#include<vector>

#include<stack>

#include<bitset>

#include<cstdlib>

#include<cmath>

#include<set>

#include<list>

#include<deque>

#include<map>

#include<queue>

using namespace std;

typedef long long ll;

const double PI = acos(-1.0);

const double eps = 1e-6;

const int INF = 0x3f3f3f3f;



int N =0;

const int MAXN = 1e5+10;

int A[MAXN];

int B[MAXN];

int C[MAXN];



int main(){

	scanf("%d",&N);

	for(int n=0;n<N;n++){

		scanf("%d",&A[n]);

	}

	for(int n=0;n<N;n++){

		scanf("%d",&B[n]);

	}

	for(int n=0;n<N;n++){

		scanf("%d",&C[n]);

	}

	sort(A,A+N);sort(B,B+N);sort(C,C+N);

	long long int ans=0;

	long long int p = 0;

	long long int q = 0;

	

	for(int i=0;i<N;i++){

		while(A[p]<B[i]&&p<N)	p++;

		while(C[q]<=B[i]&&q<N)	q++;

		ans+=p*(N-q);

	}

	

	printf("%lld",ans);

	

	return 0;

}

// Optimized solution to the same problem (faster):
#include <queue>

#include <cstdio>

#include <algorithm>

using namespace std;



static const int N = 1e5 + 10;

int n;

int a[N], b[N], c[N], cnt1[N], cnt2[N];



int main ()

{

	scanf ("%d", &n);

	for (int i = 1; i <= n; ++i)

		scanf ("%d", &a[i]);

	for (int i = 1; i <= n; ++i)

		scanf ("%d", &b[i]);

	for (int i = 1; i <= n; ++i)

		scanf ("%d", &c[i]);

	sort (a + 1, a + n + 1);

	sort (b + 1, b + n + 1);

	sort (c + 1, c + n + 1);

	int k = 1;

	for (int i = 1; i <= n; ++i)

	{

		for (; c[k] <= b[i] && k <= n ;)

			++k;

		cnt1[i] = n - k + 1;

	}

	k = 1;

	for (int i = 1; i <= n; ++i)

	{

		for (; a[k] < b[i] && k <= n ;)

			++k;

		cnt2[i] = k - 1;

	}

	long long ans = 0;

	for (int i = 1; i <= n; ++i)

		ans += (long long)cnt1[i] * cnt2[i];

	printf ("%lld", ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <stdio.h>

#include <string.h>

#include <algorithm>



using namespace std;

const int maxn = 1e6 + 5;

long long a[maxn], b[maxn], c[maxn];



int main()

{

    long long n;

    long long sum = 0;

    scanf("%lld", &n);

    for(int i = 1; i <= n; i++)

        scanf("%lld", &a[i]);

    for(int i = 1; i <= n; i++)

        scanf("%lld", &b[i]);

    for(int i = 1; i <= n; i++)

        scanf("%lld", &c[i]);

    sort(a + 1, a + n + 1);

    sort(b + 1, b + n + 1);

    sort(c + 1, c + n + 1);

    long long l = 0, r = 0;

    for(int i = 1; i <= n; i++)

    {

        while(a[l + 1] < b[i] && l + 1 <= n)

            l++;

        while(c[r + 1] <= b[i] && r + 1 <= n )

            r++;

        sum += l * (n - r);

    }

    printf("%lld\n", sum);

    return 0;

}


// Optimized solution to the same problem (faster):
#include <queue>

#include <cstdio>

#include <algorithm>

using namespace std;



static const int N = 1e5 + 10;

int n;

int a[N], b[N], c[N], cnt1[N], cnt2[N];



int main ()

{

	scanf ("%d", &n);

	for (int i = 1; i <= n; ++i)

		scanf ("%d", &a[i]);

	for (int i = 1; i <= n; ++i)

		scanf ("%d", &b[i]);

	for (int i = 1; i <= n; ++i)

		scanf ("%d", &c[i]);

	sort (a + 1, a + n + 1);

	sort (b + 1, b + n + 1);

	sort (c + 1, c + n + 1);

	int k = 1;

	for (int i = 1; i <= n; ++i)

	{

		for (; c[k] <= b[i] && k <= n ;)

			++k;

		cnt1[i] = n - k + 1;

	}

	k = 1;

	for (int i = 1; i <= n; ++i)

	{

		for (; a[k] < b[i] && k <= n ;)

			++k;

		cnt2[i] = k - 1;

	}

	long long ans = 0;

	for (int i = 1; i <= n; ++i)

		ans += (long long)cnt1[i] * cnt2[i];

	printf ("%lld", ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



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

#define for1(i, n) for (int i = 1; i <= int(n); ++i)

#define F first

#define S second

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

#define sz(x) int(x.size())

#define pb push_back



using namespace std;

using ll=long long;

using pii= pair<int, int>;

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

template<typename... T> void rd(T&... args) {((cin>>args), ...);}

template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}



int n;

ll k;

const int mod=1e9+7;

struct MAT{

    ll a[55][55];

};

MAT mul(MAT &a,MAT &b){

    MAT c;

    for(int i=1;i<=n;++i){

        for(int j=1;j<=n;++j){

            c.a[i][j]=0;

            for(int k=1;k<=n;++k)(c.a[i][j]+=a.a[i][k]*b.a[k][j])%=mod;

        }

    }

    return c;

}

int main(){

    cin>>n>>k;

    MAT x,ans;

    memset(ans.a,0,sizeof(ans.a));

    for(int i=1;i<=n;++i){

        for(int j=1;j<=n;++j)cin>>x.a[i][j];

        ans.a[i][i]=1;

    }

    while(k){

        if(k&1)ans=mul(x,ans);

        k>>=1,x=mul(x,x);

    }

    ll out=0;

    for(int i=1;i<=n;++i){

        for(int j=1;j<=n;++j)out+=ans.a[i][j];

    }

    cout<<out%mod<<endl;

	//system("pause");

	return 0;

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;

vector<vector<ll> >vec;

ll k,ans;

const ll M=1e9+7;

vector<vector<ll> >dp,tmp1,tmp2;

void go()

{

    tmp1=dp;

    for(int i=0;i<n;i++)

	{

        for(int j=0;j<n;j++)

		{

            dp[i][j]=0;

            for(int k=0;k<n;k++)

                dp[i][j]=(dp[i][j]+(tmp1[i][k]*tmp1[k][j]))%M;

        }

    }

}

void odd()

{

    tmp1=dp;

    tmp2=vec;

    for(int i=0;i<n;i++)

	{

        for(int j=0;j<n;j++)

		{

            dp[i][j]=0;

            for(int k=0; k<n; k++)

                dp[i][j]=(dp[i][j]+(tmp1[i][k]*tmp2[k][j]))%M;

        }

    }

}

void solve(ll k)

{

    if(k==1)return;

    solve(k/2);

    go();

    if(k%2)odd();

    return;

}

int main()

{

    cin>>n>>k;

    vec.resize(n);

    dp.resize(n);

    for(int i=0;i<n;i++)

	{

        for(int j=0;j<n;j++)

		{

            int x;

            cin>>x;

            vec[i].push_back(x);

            dp[i].push_back(x);

        }

    }

    solve(k);

    for(int i=0;i<n;i++)for(int j=0;j<n;j++)

        ans+=(dp[i][j]%M);

    cout<<ans%M<<endl;

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
//#include <boost/multiprecision/cpp_dec_float.hpp>

//#include <boost/multiprecision/cpp_int.hpp>

#include <stdio.h>

#include <iostream>

#include <vector>

#include <string>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <math.h>

#include <algorithm>

#include <bitset>

#include <iomanip>

using namespace std;

//namespace mp = boost::multiprecision;

//using llll = mp::cpp_int;

// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

//using Real = mp::number<mp::cpp_dec_float<1024>>;

using ll = long long;

const double EPS = 1e-10;

const ll MOD = 7+(1e+9);





ll N , M;



struct Matrix{

  static const int maxn = 105;

  ll A[maxn][maxn];

  int n;



  Matrix(int n_): n(n_) {

    for(int i = 0; i < n; ++i)

      for(int j = 0; j < n; ++j)

        A[i][j] = 0;

  }



  Matrix operator * (const Matrix& o) const {

    Matrix ret(n);

    for(int i = 0; i < n; ++i)

      for(int j = 0; j < n; ++j)

        for(int k = 0; k < n; ++k){

          ll c = A[i][k] * o.A[k][j] % MOD;

          ret.A[i][j] = (ret.A[i][j] + c) % MOD;

        }

    return ret;

  }



  static Matrix identity(int n){

    Matrix ret(n);

    for(int i = 0; i < n; ++i)

      ret.A[i][i] = 1;

    return ret;

  }



  Matrix operator ^ (long long k) const {

    Matrix ret = identity(n);

    Matrix a = *this;

    while(k){

      if(k & 1)ret = ret * a;

      a = a * a;

      k /= 2;

    }

    return ret;

  }



};



int main(){

  ll n,k;

  cin>>n>>k;

  M=n;

  N=k;

  Matrix a(M);

  for(int i = 0; i < M; ++i){

    for(ll j=0;j<M;j++){

      cin>>a.A[i][j];

    }

  }

  a = a ^ (N);

  ll ret = 0;

  for(int i = 0; i < M; ++i){

    for(ll j=0;j<M;j++){

      ret=(ret+a.A[i][j])%MOD;

    }

  }

  cout << ret << endl;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define mod 1000000007



using namespace std;

long long n,k,total;

struct matrice

{

    vector < vector<long long>> t;

    matrice()

    {

        t.resize(n, vector<long long>(n));

    }



    matrice operator* (const matrice &b)

    {

        matrice ans = matrice();

        for(int i=0; i<n; i++)

            for(int j=0; j<n; j++)

                for(int k=0; k<n; k++)

                {

                    ans.t[i][k] += (t[i][j]*b.t[j][k])%mod;

                    ans.t[i][k] %= mod;

                }

        return ans;

    }

};

int main()

{

    cin>>n>>k;

    vector<vector<long long>> can(n, vector<long long>(n));

    for(int i=0; i<n; i++)

        for(int j=0; j<n; j++)

            cin>>can[i][j];



    matrice ans = matrice();

    for(int i=0; i<n; i++)

        ans.t[i][i]=1;



    matrice m = matrice();

    for(int i=0;i<n;i++)

        for(int j=0;j<n;j++)

            m.t[i][j]=can[i][j];



    while(k)

    {

        if(k%2)

        {

            ans=ans * m;

        }

        m = m*m;

        k/=2;

    }



    for(int i=0; i<n; i++)

        for(int j=0; j<n; j++)

        {

            total += ans.t[i][j];

            total %= mod;

        }



    cout<<total;

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cstring>

using namespace std;



typedef long long llt;



const int MaxN = 50 + 5;

const llt Mod = 1e9 + 7;



struct Matrix {

  llt mat[MaxN][MaxN];

  Matrix() {

    memset(mat, 0, sizeof mat);

  }

};



int N; llt K;

Matrix G;



inline Matrix operator * (Matrix A, Matrix B) {

  Matrix C;

  for (int i = 1; i <= N; ++i)

    for (int j = 1; j <= N; ++j) {

      for (int k = 1; k <= N; ++k)

        C.mat[i][j] = (C.mat[i][j] + A.mat[i][k] * B.mat[k][j]) % Mod;

    }

  return C;

}



inline Matrix operator ^ (Matrix low, llt high) {

  Matrix res;

  for (int i = 1; i <= N; ++i) res.mat[i][i] = 1;

  while (high) {

    if (high & 1) res = res * low;

    high >>= 1;

    low = low * low;

  }

  return res;

}



void init() {

  scanf("%d %lld", &N, &K);

  for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j)

    scanf("%lld", &G.mat[i][j]);

}



void solve() {

  G = G ^ K;

  llt res = 0;

  for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j)

    res = (res + G.mat[i][j]) % Mod;

  cout << res << endl;

}



int main() {

  init();

  solve();

  return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>



const int MaxN = 50;

const int Mod = 1000000007;



int N;

long long K;



inline int add(int x, int y) { return (x += y) >= Mod ? x - Mod : x; }

inline int sub(int x, int y) { return (x -= y) < 0 ? x + Mod : x; }

inline int mul(int x, int y) { return 1LL * x * y % Mod; }



struct Matrix {

  int mat[MaxN][MaxN];



  Matrix() {

    memset(mat, 0, sizeof mat);

  }



  inline friend Matrix operator + (const Matrix &a, const Matrix &b) {

    Matrix c;

    for (int i = 0; i < N; ++i)

      for (int j = 0; j < N; ++j)

        c.mat[i][j] = add(a.mat[i][j], b.mat[i][j]);

    return c;

  }



  inline friend Matrix operator * (const Matrix &a, const Matrix &b) {

    Matrix c;

    for (int i = 0; i < N; ++i)

      for (int j = 0; j < N; ++j) {

        int x = 0;

        for (int k = 0; k < N; ++k)

          x = add(x, mul(a.mat[i][k], b.mat[k][j]));

        c.mat[i][j] = x;

      }

    return c;

  }



  inline friend Matrix operator ^ (Matrix low, long long high) {

    Matrix res;

    for (int i = 0; i < N; ++i) res.mat[i][i] = 1;

    while (high) {

      if (high & 1) res = res * low;

      high >>= 1;

      low = low * low;

    }

    return res;

  }

};

Matrix G;



void init() {

  scanf("%d %lld", &N, &K);

  for (int i = 0; i < N; ++i)

    for (int j = 0; j < N; ++j)

      scanf("%d", &G.mat[i][j]);

}



void solve() {

  G = G ^ K;

  int ans = 0;

  for (int i = 0; i < N; ++i)

    for (int j = 0; j < N; ++j)

      ans = add(ans, G.mat[i][j]);

  printf("%d\n", ans);

}



int main() {

  init();

  solve();

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;





int main() {

    int n,q,a,b,p,x;

    cin >> n >> q;

    vector<vector<int>> G(n);

    int c[200010]={0};

    for (int i=0;i<n-1;i++) {

        cin >> a >> b;

        a--;

        b--;

        G[a].push_back(b);

        G[b].push_back(a);

    }

    for (int j=0;j<q;j++) {

        cin >> p >> x;

        c[p-1]+=x;

    }

    vector<bool> flag(n); 

    queue<int> qu;

    int ans[200010]={0};

    qu.push(0);

    ans[0]=c[0];

    while (qu.size()>0) {

        int now = qu.front();

        qu.pop();

        for (int i=0;i<G[now].size();i++) {

            int next = G[now][i];

            if (flag[next]!=true) {

                ans[next]=c[next]+ans[now];

                qu.push(G[now][i]);

            }

        }

        flag[now]=true;

    }

    for (int i=0;i<n;i++) {

        cout << ans[i];

        if (i!=n-1) cout << ' ';

        else cout << endl;

    }

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

#define repr(i,a,b) for(int i=a;i<b;i++)

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

#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)

#define invrep(i,n) invrepr(i,0,n)

#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)

const int MOD=1e9+7;





int main() {

    ios_base::sync_with_stdio(false);



    int n,k;

    cin >> n >> k;

    vector<vector<int>> r(n);

    rep(i,n-1) {

        int a,b;

        cin >> a >> b;

        r[a-1].push_back(b-1);

        r[b-1].push_back(a-1);

    }

    vector<int> s(n);

    rep(i,k) {

        int p,x;

        cin >> p >> x;

        s[p-1]+=x;

    }

    queue<int> q;

    vector<int> cost(n,-1);

    q.push(0);

    cost[0]=0;

    while (!q.empty()) {

        int now=q.front();

        q.pop();

        rep(i,r[now].size()) {

            int next=r[now][i];

            if (cost[next]==-1) {

                s[next]+=s[now];

                cost[next]=cost[now]+1;

                q.push(next);

            }

        }

    }

    rep(i,n) cout << s[i] << ' ';

    cout << endl;





    return 0;   

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <vector>

#include <iostream>

using namespace std;

vector<int> graph[200010];

vector<int> ans(200010, 0);



void dfs(int v, int p=-1) {

  for(int u: graph[v]) {

    if(u == p) continue;

    else ans[u] += ans[v];

    dfs(u, v);

  }

}



int main() {

  int N, Q; cin >> N >> Q;

  for(int i = 0; i < N-1; ++i) {

    int a, b; cin >> a >> b; a--, b--;

    graph[a].push_back(b);

    graph[b].push_back(a);

  }



  for(int i = 0; i < Q; i++) {

    int p, x; cin >> p >> x; p--;

    ans[p] += x;

  }



  dfs(0);



  for(int i = 0; i < N; i++) {

    cout << ans[i];

    if(i != N-1) cout << " ";

    else cout << endl;

  }

  return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <iomanip>

#include <algorithm>

#include <vector>

#include <queue>

#include <cmath>

#include <map>

#include <set>

#include <deque>

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

using namespace std;

typedef long long ll;

const int mod = 1e9+7;

const int inf = 1<<30;

typedef pair<int, int> P;

vector<vector<int>> to;

vector<int> ans;



void dfs(int v, int p = -1) {

  for(int u: to[v]) {

    if(u == p) continue;

    ans[u] += ans[v];

    dfs(u, v);

  }

}



int main() {

  int N, Q; cin >> N >> Q;

  to.resize(N);

  rep(i, N-1) {

    int a, b; cin >> a >> b; a--, b--;

    to[a].push_back(b);

    to[b].push_back(a);

  }



  ans.resize(N);



  rep(i, Q) {

    int p, x; cin >> p >> x;

    p--;

    ans[p] += x;

  }



  dfs(0);



  rep(i, N) {

    if(i) cout << " ";

    cout << ans[i];

  }

  cout << endl;



  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <iomanip>

#include <algorithm>

#include <vector>

#include <queue>

#include <cmath>

#include <map>

#include <set>

#include <deque>

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

using namespace std;

typedef long long ll;



vector<int> to[200010];

vector<int> ans;



void dfs(int v, int p=-1) {

  for(int u: to[v]) {

    if(u == p) continue;

    ans[u] += ans[v];

    dfs(u, v);

  }

}



int main() {

  int n, q; cin >> n >> q;

  rep(i, n-1) {

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

    --a, --b;

    to[a].push_back(b);

    to[b].push_back(a);

  }

  ans.resize(n);

  rep(i, q) {

    int p, x; cin >> p >> x;

    p--;

    ans[p] += x;

  }



  dfs(0);



  rep(i, n) {

    if(i) cout << " ";

    cout << ans[i];

  }

  cout << endl;



  return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <iomanip>

#include <algorithm>

#include <vector>

#include <queue>

#include <cmath>

#include <map>

#include <set>

#include <deque>

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

using namespace std;

typedef long long ll;

const int mod = 1e9+7;

const int inf = 1<<30;

typedef pair<int, int> P;

vector<vector<int>> to;

vector<int> ans;



void dfs(int v, int p = -1) {

  for(int u: to[v]) {

    if(u == p) continue;

    ans[u] += ans[v];

    dfs(u, v);

  }

}



int main() {

  int N, Q; cin >> N >> Q;

  to.resize(N);

  rep(i, N-1) {

    int a, b; cin >> a >> b; a--, b--;

    to[a].push_back(b);

    to[b].push_back(a);

  }



  ans.resize(N);



  rep(i, Q) {

    int p, x; cin >> p >> x;

    p--;

    ans[p] += x;

  }



  dfs(0);



  rep(i, N) {

    if(i) cout << " ";

    cout << ans[i];

  }

  cout << endl;



  return 0;

}


// Fastest known solution for this problem: