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

#include<string>

#include<algorithm>

#include<vector>

#include<iomanip>

#include<math.h>

#include<complex>

#include<queue>

#include<deque>

#include<stack>

#include<map>

#include<set>

#include<bitset>

#include<functional>

using namespace std;

#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )

#define rep(i,n) REP(i,0,n)

typedef long long ll;

typedef pair<int,int> pint;

typedef pair<ll,int> pli;

const int inf=1e9+7;

const ll longinf=1LL<<60 ;

const ll mod=1e9+7 ;



vector<int> v[101010];

priority_queue<int> ret[101010];

int ans[101010];



int dfs(int x,int p){

    ret[x].push(0);

    for(auto to:v[x]){

        if(to==p)continue;

        ret[x].push(dfs(to,x));

    }

    return ret[x].top()+1;

}



void dfs2(int x,int p){

    int res=ret[x].top();

    if(p!=-1){

        int y=ret[p].top();

        ret[p].pop();

        if(y!=res+1)ret[x].push(y+1);

        else ret[x].push(ret[p].top()+1);

        ret[p].push(y);

    }

    for(auto to:v[x]){

        if(to==p)continue;

        dfs2(to,x);

    }

    ans[x]=ret[x].top();

}



int main(){

    int n;

    cin>>n;

    rep(i,n-1){

        int a,b;

        cin>>a>>b;

        --a;--b;

        v[a].push_back(b);

        v[b].push_back(a);

    }

    dfs(0,-1);

    dfs2(0,-1);

    rep(i,n)cout<<2*(n-1)-ans[i]<<endl;

    return 0;

}


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

#include<string>

#include<algorithm>

#include<vector>

#include<iomanip>

#include<math.h>

#include<complex>

#include<queue>

#include<deque>

#include<stack>

#include<map>

#include<set>

#include<bitset>

#include<functional>

using namespace std;

#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )

#define rep(i,n) REP(i,0,n)

typedef long long ll;

typedef pair<int,int> pint;

typedef pair<ll,int> pli;

const int inf=1e9+7;

const ll longinf=1LL<<60 ;

const ll mod=1e9+7 ;



vector<int> v[101010],ret[101010];

int ans[101010];



int dfs(int x,int p){

    ret[x].push_back(0);

    for(auto to:v[x]){

        if(to==p)continue;

        ret[x].push_back(dfs(to,x));

    }

    sort(ret[x].begin(),ret[x].end(),greater<>());

    return ret[x][0]+1;

}



void dfs2(int x,int p){

    int res=ret[x][0];

    if(x){

        if(ret[p][0]!=res+1)ret[x].push_back(ret[p][0]+1);

        else ret[x].push_back(ret[p][1]+1);

    }

    sort(ret[x].begin(),ret[x].end(),greater<>());

    for(auto to:v[x]){

        if(to==p)continue;

        dfs2(to,x);

    }

    ans[x]=ret[x][0];

}



int main(){

    int n;

    cin>>n;

    rep(i,n-1){

        int a,b;

        cin>>a>>b;

        --a;--b;

        v[a].push_back(b);

        v[b].push_back(a);

    }

    dfs(0,-1);

    dfs2(0,-1);

    rep(i,n)cout<<2*(n-1)-ans[i]<<endl;

    return 0;

}


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

#include <cstring>

#include <vector>

using namespace std;



char s[200002];

vector<int> p[27];

int r[200002], tr[200002];



int main(){

  scanf("%s", s + 1); int L = strlen(s + 1);

  for(int i = 1; i <= L; i++) p[s[i] & 31].push_back(i);



  int o = 0;

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

    int z = p[i].size();

    if(z & 1){ o++; r[p[i][z / 2]] = (L + 1) / 2; }

  }



  if(o > 1){ puts("-1"); return 0; }



  for(int i = 1, z = 1; i <= L; i++){

    if(r[i] == 0){

      r[i] = z; r[p[s[i] & 31].back()] = L + 1 - z;

      z++; p[s[i] & 31].pop_back();

    }

  }



  long long ans = 0;



  for(int i = L; i >= 1; i--){

    for(int x = r[i]; x > 0; x -= x & -x) ans += tr[x];

    for(int x = r[i]; x <= L; x += x & -x) tr[x]++;

  }



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

  return 0;

}

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

#include <cstring>

#include <algorithm>

using namespace std;



char s[200002]; int cnt[28];

int gc[28];

char pre[100002], suf[100002];

int ptr[28], num[100002];

int tr[100002];



long long group(int L){

  long long res = 0;

  int oc = 0, tc = 0, pc = 0, sc = 0;



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

    int x = s[i] & 31, &g = gc[x], c = cnt[x]; g += 2;



    if(g < c + 1){ res += oc + tc; pre[++pc] = s[i]; }

    else if(g == c + 1){ res += tc; oc++; }

    else{ tc++; suf[++sc] = s[i]; }

  }



  return res;

}



int main(){

  scanf("%s", s + 1); int L = strlen(s + 1);

  for(int i = 1; i <= L; i++) cnt[s[i] & 31]++;



  int odd = 0;



  for(int i = 1; i <= 26; i++) if(cnt[i] & 1) odd++;



  if(odd > 1){ puts("-1"); return 0; }



  long long ans = group(L);



  int M = L / 2;



  reverse(suf + 1, suf + M + 1);



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

    char c = pre[i]; int &p = ptr[c & 31];

    while(suf[++p] != c);



    num[p] = i;

  }



  for(int i = M; i >= 1; i--){

    int x = num[i];

    for(int y = x - 1; y > 0; y -= y & -y) ans += tr[y];

    for(; x <= M; x += x & -x) tr[x]++;

  }



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

  return 0;

}

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

#include<iostream>

#include<cstring>

#include<algorithm>

#include<map>

#include<cmath>

using namespace std;

double cnt;

double p,t;

int K; 

double e;

double ll,rr;

double dfs(double l,double r,int k,double tl,double tr)

{

     double mid=(l+r)/2.00;

     if(l>tl-1e-12&&r<tr+1e-12)

     return 1.0;

     if(r<tl+1e-12||l>tr-1e-12)

     return 0.0;

    if(k==K)

    {

     if(mid<tr+1e-12&&mid>tl-1e-12)

      return 1.0;

     else return 0.0;

    }

    double pp;

    if(mid>=t-1e-12) pp=1.00-p;

    else pp=p;

    return pp*dfs(l,mid,k+1,tl,tr)+(1-pp)*dfs(mid,r,k+1,tl,tr);

    

}

int main()

{

  //freopen("aaa.txt","r",stdin);

  //freopen("bbb.txt","w",stdout);

  while(cin>>K>>ll>>rr)

  {    

    cin>>p>>e>>t;   

    double kk=dfs(ll,rr,0,t-e,t+e);

    printf("%.12lf\n",kk);

  }

}

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

#include <cstring>



double P, E, T;



double fabs(double x){

    if(x < 0) x = -x;

    return x;

}



double dfs(int k, double pro, double L, double R){

    if(k == 0){

        double mid = (L + R) / 2;

        if(fabs(mid - T) <= E) return pro;

        return 0;

    }

    if(T + E < L || T - E > R) return 0;

    double ans = 0;

    double mid = (L + R) / 2;

    if(fabs(R - T) <= E && fabs(T - L) <= E) return pro;

    if(mid >= T){

        ans += dfs(k - 1, pro * (1 - P), L, mid);

        ans += dfs(k - 1, pro * P, mid, R);

    }

    else{

        ans += dfs(k - 1, pro * P, L, mid);

        ans += dfs(k - 1, pro * (1 - P), mid, R);

    }

    return ans;

}

int main(){

    //freopen("input.txt", "r", stdin);

    int K;

    double L, R;

    scanf("%d %lf %lf", &K, &L, &R);

    scanf("%lf %lf %lf", &P, &E, &T);

    double ans = dfs(K, 1.0, L, R);

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

    return 0;

}

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

#include<iostream>

#include<algorithm>

#include<cstring>

#include<climits>

#include<cstdlib>

#include<cmath>

#include<map>

#include<vector>

#include<queue>

#include<string>

#include<csetjmp>

#include<bitset>

#include<cassert>

#include<cctype>

#include<complex>

#include<ctime>

#include<deque>

#include<fstream>

#include<functional>

#include<iomanip>

#include<limits>

#include<list>

#include<numeric>

#include<set>

#include<sstream>

#include<stack>

#include<utility>

using namespace std;

#define PI 3.1415926535897932384626433832795028

#define N 30

#define M 10010

#define inf 2000000000

typedef long long LL;

int k;

double p, e, t, ans;

void dfs(int cur, double l, double r, double temp) {

	if (l > t+e || r < t-e) return ;

	if (l >= t-e && r <= t+e) {

		ans += temp;

		return ;

	}

	double mid = (l+r)/2;

	if (cur == k) {

		if (fabs(mid - t) < e) ans += temp;

		return ;

	}

	if (mid > t) {

		dfs(cur+1, l, mid, temp*(1-p));

		dfs(cur+1, mid, r, temp*p);

	}

	else {

		dfs(cur+1, mid, r, temp*(1-p));

		dfs(cur+1, l, mid, temp*p);

	}

}

int main() {

	double l, r;

	while (scanf("%d%lf%lf", &k, &l, &r) != EOF) {

		scanf("%lf%lf%lf", &p, &e, &t);

		ans = 0;

		dfs (0, l, r, 1.0);

		printf("%.6lf\n", ans);

	}

	return 0;

}

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

#include <cstring>



double P, E, T;



double fabs(double x){

    if(x < 0) x = -x;

    return x;

}



double dfs(int k, double pro, double L, double R){

    if(k == 0){

        double mid = (L + R) / 2;

        if(fabs(mid - T) <= E) return pro;

        return 0;

    }

    if(T + E < L || T - E > R) return 0;

    double ans = 0;

    double mid = (L + R) / 2;

    if(fabs(R - T) <= E && fabs(T - L) <= E) return pro;

    if(mid >= T){

        ans += dfs(k - 1, pro * (1 - P), L, mid);

        ans += dfs(k - 1, pro * P, mid, R);

    }

    else{

        ans += dfs(k - 1, pro * P, L, mid);

        ans += dfs(k - 1, pro * (1 - P), mid, R);

    }

    return ans;

}

int main(){

    //freopen("input.txt", "r", stdin);

    int K;

    double L, R;

    scanf("%d %lf %lf", &K, &L, &R);

    scanf("%lf %lf %lf", &P, &E, &T);

    double ans = dfs(K, 1.0, L, R);

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

    return 0;

}

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

#include <string.h>

#include <math.h>

#include <stdlib.h>

#include <cmath>

#include <cstdlib>

#include <algorithm>

#include <iostream>

using namespace std;

#define INF 0x7fffffff

#define Max 200000

#define eps 1e-10



double l, r, p, e, t, ans;

int c;



void dfs (double L, double R, int days, double pp)

{

	if (R < (t - e) || L > (t + e))

		return ;

	if (L >= t - e && R <= t + e)

	{

		ans += pp;

		return ;

	}

	double mid = (L + R) / 2.0;

	if (days > c) 

	{

		if (abs(mid - t) <= e) ans += pp;

		return ;

	}

	if (mid >= t)

	{

		dfs (L, mid, days + 1, pp * (1 - p));

		dfs (mid, R, days + 1, pp * p);

	}

	else

	{

		dfs (mid, R, days + 1, pp * (1 - p));

		dfs (L, mid, days + 1, pp * p);

	}

}



int main ()

{

	int i, j;

	while (scanf ("%d%lf%lf", &c, &l, &r) == 3)

	{

		scanf ("%lf%lf%lf", &p, &e, &t);

		ans = 0;

		dfs (l, r, 1, 1);

		printf ("%.20lf\n", ans);

	}

}

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

#include <cstring>



double P, E, T;



double fabs(double x){

    if(x < 0) x = -x;

    return x;

}



double dfs(int k, double pro, double L, double R){

    if(k == 0){

        double mid = (L + R) / 2;

        if(fabs(mid - T) <= E) return pro;

        return 0;

    }

    if(T + E < L || T - E > R) return 0;

    double ans = 0;

    double mid = (L + R) / 2;

    if(fabs(R - T) <= E && fabs(T - L) <= E) return pro;

    if(mid >= T){

        ans += dfs(k - 1, pro * (1 - P), L, mid);

        ans += dfs(k - 1, pro * P, mid, R);

    }

    else{

        ans += dfs(k - 1, pro * P, L, mid);

        ans += dfs(k - 1, pro * (1 - P), mid, R);

    }

    return ans;

}

int main(){

    //freopen("input.txt", "r", stdin);

    int K;

    double L, R;

    scanf("%d %lf %lf", &K, &L, &R);

    scanf("%lf %lf %lf", &P, &E, &T);

    double ans = dfs(K, 1.0, L, R);

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

    return 0;

}

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

#include <cmath>

#include <algorithm>

#include <cfloat>

#include <stack>

#include <queue>

#include <vector>

#include <string.h>

typedef long long int ll;

typedef unsigned long long int ull;

#define BIG_NUM 2000000000

#define MOD 1000000007

#define EPS 0.000000001

using namespace std;



double ans = 0,P,E,T;

int K;



void recursive(double R,double L,double probability,int count){



	if(L < T-E || R > T+E)return;



	if(count == K){

		if(fabs(T-(R+L)/2.0) <= E){

			ans += probability;

		}

		return;

	}



	double H = (R+L)/2.0;



	double right_R,right_L,wrong_R,wrong_L;



	if(H > T){



		right_R = R,right_L = H;

		recursive(right_R,right_L,probability*(1-P),count+1);



		wrong_R = H,wrong_L = L;

		recursive(wrong_R,wrong_L,probability*P,count+1);



	}else{



		right_R = H,right_L = L;

		recursive(right_R,right_L,probability*(1-P),count+1);



		wrong_R = R,wrong_L = H;

		recursive(wrong_R,wrong_L,probability*P,count+1);

	}

}



int main(){



	double first_R,first_L;



	scanf("%d %lf %lf",&K,&first_R,&first_L);

	scanf("%lf",&P);

	scanf("%lf",&E);

	scanf("%lf",&T);



	recursive(first_R,first_L,1.0,0);



	printf("%.6lf\n",ans);



	return 0;

}

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

#include <cmath>

#include <algorithm>

#include <cfloat>

#include <stack>

#include <queue>

#include <vector>

#include <string.h>

typedef long long int ll;

typedef unsigned long long int ull;

#define BIG_NUM 2000000000

#define MOD 1000000007

#define EPS 0.000000001

using namespace std;



double ans = 0,P,E,T;

int K;



void recursive(double R,double L,double probability,int count){



	if(L < T-E || R > T+E)return;



	if(count == K){

		if(fabs(T-(R+L)/2.0) <= E){

			ans += probability;

		}

		return;

	}else if(R >= T-E && L <= T+E){

		ans += probability;

		return;

	}



	double H = (R+L)/2.0;



	double right_R,right_L,wrong_R,wrong_L;



	if(H > T){



		right_R = R,right_L = H;

		recursive(right_R,right_L,probability*(1-P),count+1);



		wrong_R = H,wrong_L = L;

		recursive(wrong_R,wrong_L,probability*P,count+1);



	}else{



		right_R = H,right_L = L;

		recursive(right_R,right_L,probability*(1-P),count+1);



		wrong_R = R,wrong_L = H;

		recursive(wrong_R,wrong_L,probability*P,count+1);

	}

}



int main(){



	double first_R,first_L;



	scanf("%d %lf %lf",&K,&first_R,&first_L);

	scanf("%lf",&P);

	scanf("%lf",&E);

	scanf("%lf",&T);



	recursive(first_R,first_L,1.0,0);



	printf("%.6lf\n",ans);



	return 0;

}

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

#include<queue>

#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

#define mod 1000000007

using namespace std;



int n;

long long dp1[300010],dp2[300010],a[300010],sum1,sum2;



priority_queue<long long,vector<long long>,greater<long long> > q;

priority_queue<long long> q2;



int main()

{

	//fuck!!!

	scanf("%d",&n);

	memset(dp1,0,sizeof(dp1));

	memset(dp2,0x3f,sizeof(dp2));

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

	{

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

	}

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

	{

		q.push(a[i]);

		sum1+=a[i];

	}

	dp1[n]=sum1;

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

	{

		if(q.top()<a[i])

		{

			sum1-=q.top();

			sum1+=a[i];

			q.pop();

			q.push(a[i]);

		}

		dp1[i]=sum1;

	}

	for(int i=3*n;i>2*n;i--)

	{

		q2.push(a[i]);

		sum2+=a[i];

	}

	dp2[2*n+1]=sum2;

	for(int i=2*n;i>=1;i--)

	{

		if(q2.top()>a[i])

		{

			sum2-=q2.top();

			sum2+=a[i];

			q2.pop();

			q2.push(a[i]);

		}

		dp2[i]=sum2;

	}

	long long ans=-0x3f3f3f3f3f3f3f3f;

	for(int i=n;i<=2*n;i++)

	{

//		printf("%d %lld %lld\n",i,dp1[i],dp2[i]);

		ans=max(ans,dp1[i]-dp2[i+1]);

	}

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

}

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

#include<cstdlib>

#include<cstring>

#include<string>

#include<cmath>

#include<algorithm>

#include<map>

#include<vector>

#include<queue>

#define LL long long

using namespace std;

const int MaxN = 1e5;

const LL Inf = 1LL << 60;



priority_queue<LL> q2;

priority_queue<LL,vector<LL>,greater<LL> > q1;

LL sum[3 * MaxN + 5],cas[3 * MaxN + 5],a[3 * MaxN + 5];

LL sum2[3 * MaxN + 5],cas2[3 * MaxN + 5];



int main()

{

	LL pp,ans;

	int n;

	while(~scanf("%d",&n)){

		ans = -Inf;

		sum[0] = 0;cas[n] = 0;

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

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

			sum[i] = sum[i - 1] + a[i];

			q1.push(a[i]);

		}

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

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

			sum[i] = sum[i - 1] + a[i];

			q1.push(a[i]);

			pp = q1.top();

			cas[i] = cas[i - 1] + pp;

			q1.pop();

		}

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

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

		}

		sum2[3 * n + 1] = 0;cas2[2 * n + 1] = 0;

		for(int i = 3 * n;i >= 2 * n + 1;i--){

			sum2[i] = sum2[i + 1] + a[i];

			q2.push(a[i]);

		}

		for(int i = 2 * n;i >= n + 1;i--){

			sum2[i] = sum2[i + 1] + a[i];

			q2.push(a[i]);

			pp = q2.top();

			cas2[i] = cas2[i + 1] + pp;

			q2.pop();

		}

		for(int i = n;i <= 2 * n;i++){

			pp = sum[i] - cas[i] - sum2[i + 1] + cas2[i + 1];

			ans = max(pp,ans);

		}

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

	}

	return 0;

}

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

#include<cstring>

#include<algorithm>

#include<queue>

using namespace std;

#define MAXN 100005

#define LL long long

#define INF 1e18

int N,M,S,T,u,v;

LL a,b,f=1e15,ans[MAXN];

LL Min(LL x,LL y)

{

	if(x>y) return y;

		return x;

}

struct graph{

	int cnt,head[MAXN],vis[MAXN];

	LL dis[MAXN];

	struct Edge

	{

		int next,to;LL dis;

	}edge[2*MAXN];

	queue<int> q;

	

	void addedge(int from,int to,LL dis)

	{

		edge[++cnt].next=head[from];

		edge[cnt].to=to;

		edge[cnt].dis=dis;

		head[from]=cnt;

	}

	

	void spfa(int s)

	{

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

			dis[i]=INF;

		memset(vis,0,sizeof(vis));

		q.push(s); vis[s]=1; dis[s]=0;

		while(!q.empty())

		{

			int x=q.front(); q.pop();

			vis[x]=0;

			for(int i=head[x];i;i=edge[i].next)

			{

				int to=edge[i].to;

				if(dis[to]>dis[x]+edge[i].dis)

				{

					dis[to]=dis[x]+edge[i].dis;

					if(!vis[to]) q.push(to),vis[to]=1;

				}

			}

		}

	}

}g1,g2;

int main()

{

	scanf("%d %d %d %d",&N,&M,&S,&T);

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

	{

		scanf("%d %d %lld %lld",&u,&v,&a,&b);

		g1.addedge(u,v,a); g1.addedge(v,u,a);

		g2.addedge(v,u,b); g2.addedge(u,v,b);

	}

	g1.spfa(S); g2.spfa(T);

	ans[N+1]=INF;

	for(int i=N;i>=1;i--) ans[i]=Min(ans[i+1],g1.dis[i]+g2.dis[i]);

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

		printf("%lld\n",f-ans[i]);

	return 0;

}

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

using namespace std;

const int N=1e5+8;

int n,m,s,t;

long long ans[N];

struct node{

    int cnt,head[N];

    long long cost[N];

    bool flag[N];

    struct Edge {int next, to; long long cost;} edge[N*2];

	queue<int> q;

	void add(int from,int to,long long cost)

	{

		edge[++cnt].next=head[from];

		edge[cnt].to=to;

		edge[cnt].cost=cost;

		head[from]=cnt;

	}

	void spfa(int s)

	{

		for(int i=1;i<=n;i++) cost[i]=1000000000000000000;

		memset(flag,0,sizeof(flag));

		q.push(s); flag[s]=1; cost[s]=0;

		while(!q.empty())

		{

			int x=q.front();

			q.pop();

			flag[x]=0;

			for(int i=head[x];i;i=edge[i].next)

			{

				int to=edge[i].to;

				if(cost[to]>cost[x]+edge[i].cost)

				{

					cost[to]=cost[x]+edge[i].cost;

					if(!flag[to]) q.push(to),flag[to]=1;

				}

			}

		}

	}

}s_to_i,i_to_t;

long long Min(long long x,long long y)

{

    if(x>y) return y;

    return x;

}

int main()

{

    cin>>n>>m>>s>>t;

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

    {

        int u,v;

        long long yen,snu;

        cin>>u>>v>>yen>>snu;

        s_to_i.add(u,v,yen);

        i_to_t.add(u,v,snu);

        s_to_i.add(v,u,yen);

        i_to_t.add(v,u,snu);

    }

    s_to_i.spfa(s);

    i_to_t.spfa(t);

    ans[n]=s_to_i.cost[n]+i_to_t.cost[n];

    for(int i=n-1;i>0;i--) ans[i]=Min(ans[i+1],s_to_i.cost[i]+i_to_t.cost[i]);

    for(int i=1;i<=n;i++) printf("%lld\n",1000000000000000-ans[i]);

}


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

#include<cstdio>

#include<vector>

#include<cstring>

#include<algorithm>

using namespace std;



#define MAXN 100000

int N,M;

struct Edge{

    int v,w[2];

    Edge(){}

    Edge(int a,int w1,int w2){

        v=a,w[0]=w1,w[1]=w2;

    }

};

vector<Edge> G[MAXN+5];



bool vis[MAXN+5];

long long dist[2][MAXN+5];

void SPFA(int S,int opt){

    memset(vis,0,sizeof vis);

    memset(dist[opt],0x3f,sizeof dist[opt]);

    queue<int> Q;Q.push(S);

    dist[opt][S]=0;vis[S]=1;

    while(!Q.empty()){

        int u=Q.front();

        vis[u]=0;Q.pop();

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

            int v=G[u][i].v,w=G[u][i].w[opt];

            if(dist[opt][v]>dist[opt][u]+w){

                dist[opt][v]=dist[opt][u]+w;

                if(!vis[v]){

                    vis[v]=1;

                    Q.push(v);

                }

            }

        }

    }

}



long long Ans[MAXN+5];

int main(){

    int S,T;

    scanf("%d%d%d%d",&N,&M,&S,&T);

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

        int u,v,w1,w2;

        scanf("%d%d%d%d",&u,&v,&w1,&w2);

        G[u].push_back(Edge(v,w1,w2));

        G[v].push_back(Edge(u,w1,w2));

    }

    SPFA(S,0);

    SPFA(T,1);

    Ans[N]=dist[0][N]+dist[1][N];

    for(int i=N-1;i>=1;i--)

        Ans[i]=min(Ans[i+1],dist[0][i]+dist[1][i]);

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

        printf("%lld\n",1000000000000000ll-Ans[i]);

}


// Optimized solution to the same problem (faster):
//SPFA

#include<bits/stdc++.h>

#define ll long long

#define INF 1e18

#define MAXN 100005



ll min(ll x,ll y){if(x<y) return x;return y;}

	

	int n,m,s,t,u,v;

	ll a,b,f=1e15,ans[MAXN];

	

struct Graph

{

	int cnt,head[MAXN],vis[MAXN];

	ll dis[MAXN];

	

	struct Edge{int next,to;ll dis;}edge[MAXN*2];

	

	std::queue<int> q;

	

	void addedge(int from,int to,ll dis)

	{

		edge[++cnt].next=head[from];

		edge[cnt].to=to;

		edge[cnt].dis=dis;

		head[from]=cnt;

	}

	void spfa(int s)

	{

		for(int i=1;i<=n;i++) dis[i]=INF;

		memset(vis,0,sizeof(vis));

		q.push(s);vis[s]=1;dis[s]=0;

		while(!q.empty())

		{

			int x=q.front();q.pop();

			vis[x]=0;

			for(int i=head[x];i;i=edge[i].next)

			{

				int to=edge[i].to;

				if(dis[to]>dis[x]+edge[i].dis)

				{

					dis[to]=dis[x]+edge[i].dis;

					if(!vis[to]) q.push(to),vis[to]=1;

				}

			}

		}

	}

}g1,g2;



int main()

{

	scanf("%d%d%d%d",&n,&m,&s,&t);

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

	{

		scanf("%d%d%lld%lld",&u,&v,&a,&b);

		g1.addedge(u,v,a);g1.addedge(v,u,a);

		g2.addedge(v,u,b);g2.addedge(u,v,b);

	}

	g1.spfa(s);g2.spfa(t);

	ans[n+1]=INF;

	for(int i=n;i>=1;i--) ans[i]=min(ans[i+1],g1.dis[i]+g2.dis[i]);

	for(int i=1;i<=n;i++) printf("%lld\n",f-ans[i]);

}

// Fastest known solution for this problem: