//-----HEADER-----
#include<bits/stdc++.h>
using namespace std;

//-----MACROS-----
#define int long long
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vc vector
#define nl '\n'
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for (int i=a; i<b; ++i)
#define rev(i,a,b) for (int i=a; i>b; --i)
#define IOS ios_base::sync_with_stdio(false)
#define setpr(x) cout<<setprecision(x)<<fixed
#define sz size()
#define N 200005

//-----TEMPLATES-----
template<typename... T>
void see(T&... args) {
	((cin >> args), ...);
}

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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

//-----CONSTANTS-----
const ll inf = INT_MAX;
const ld ep = 0.0000001;
const ld pi = acos(-1.0);
const ll md = 1000000007;

//-----GLOBALS-----
int d[N]={0};
int a[N]={0};
//-----SOLUTION-----
void solve(){
	setpr(8);
	int m; see(m);
	double s=0; int n=1;
	while(m--){
		int t; see(t);
		if (t==2){
			int x; see(x);
			s+=x; n++;
			a[n]=x;
		}
		else if (t==1){
			int y,x; see(y,x);
			d[y]+=x;
			s+= (y*x);
		}
		else {
			int x = d[n] + a[n];
			d[n-1]+=d[n];
			a[n]=0;
			s-=x; n--;
		}
		cout<<s/n<<nl;
	}
}

//-----MAIN-----
signed main(){
	IOS;

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif

	int t=1;
	//cin>>t;
	while(t--) {
		solve();
		//cout<<nl;
	}

}


//-----HEADER-----
#include<bits/stdc++.h>
using namespace std;

//-----MACROS-----
#define int long long
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vc vector
#define nl '\n'
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for (int i=a; i<b; ++i)
#define rev(i,a,b) for (int i=a; i>b; --i)
#define IOS ios_base::sync_with_stdio(false)
#define setpr(x) cout<<setprecision(x)<<fixed
#define sz size()
#define N 200005

//-----TEMPLATES-----
template<typename... T>
void see(T&... args) {
	((cin >> args), ...);
}

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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

//-----CONSTANTS-----
const ll inf = INT_MAX;
const ld ep = 0.0000001;
const ld pi = acos(-1.0);
const ll md = 1000000007;

//-----GLOBALS-----
double d[N]={0};
int a[N]={0};
//-----SOLUTION-----
void solve(){
	cout.precision(9); cout<<fixed;
	int m; see(m);
	double s=0; int n=1;
	while(m--){
		int t; see(t);
		if (t==2){
			int x; see(x);
			s+=x; n++;
			a[n]=x;
		}
		else if (t==1){
			int y,x; see(y,x);
			d[y]+=x;
			s+= (y*x);
		}
		else {
			int x = d[n] + a[n];
			d[n-1]+=d[n];
			a[n]=0;
			s-=x; n--;
		}
		double av = s/n;
		cout<<av<<nl;
	}
}

//-----MAIN-----
signed main(){
	IOS;

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif

	int t=1;
	//cin>>t;
	while(t--) {
		solve();
		//cout<<nl;
	}

}


//-----HEADER-----
#include<bits/stdc++.h>
using namespace std;

//-----MACROS-----
#define int long long
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vc vector
#define nl '\n'
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for (int i=a; i<b; ++i)
#define rev(i,a,b) for (int i=a; i>b; --i)
#define IOS ios_base::sync_with_stdio(false)
#define setpr(x) cout<<setprecision(x)<<fixed
#define sz size()
#define N 200005

//-----TEMPLATES-----
template<typename... T>
void see(T&... args) {
	((cin >> args), ...);
}

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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

//-----CONSTANTS-----
const ll inf = INT_MAX;
const ld ep = 0.0000001;
const ld pi = acos(-1.0);
const ll md = 1000000007;

//-----GLOBALS-----
int tree[N+1]={0};
void update(int n, int x,int val){
	for(;x<=n; x+=x&-x) tree[x]+=val;
}
int query(int x){
	int s=0;
	for(;x>0;x-=x&-x) s+=tree[x];
	return s;
}
int find(int x){
	int c=0;
	while(!(x&1)){
		x>>=1; c++;
	}
	c = pow(2,c);
	return (query(x-1)-query(x-c));
}
int i=2;
//-----SOLUTION-----
void solve(){
	//range update
	setpr(10);
	int m; see(m);
	ld s=0, n=1;
	vi v={0};
	while(m--){
		int t; see(t);
		if (t==2){
			int x; see(x);
			s+=x; n++;
			int vl = query(i-1);
			int v = find(i);
			tree[i]=x-vl+v;i++;
		}
		else if (t==1){
			int y,x; see(y,x);
			update(i-1,1,x), update(i-1,y+1,-x);
			s+= (y*x);
		}
		else {
			int vl = query(i-1);
			s-=vl; n--;
			tree[i-1]=0;i--;
		}
		cout<<s/n<<nl;
	}
}

//-----MAIN-----
signed main(){
	IOS;

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif

	int t=1;
	//cin>>t;
	while(t--) {
		solve();
		//cout<<nl;
	}

}


//-----HEADER-----
#include<bits/stdc++.h>
using namespace std;

//-----MACROS-----
#define int long long
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vc vector
#define nl '\n'
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for (int i=a; i<b; ++i)
#define rev(i,a,b) for (int i=a; i>b; --i)
#define IOS ios_base::sync_with_stdio(false)
#define setpr(x) cout<<setprecision(x)<<fixed
#define sz size()
#define N 200005

//-----TEMPLATES-----
template<typename... T>
void see(T&... args) {
	((cin >> args), ...);
}

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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

//-----CONSTANTS-----
const ll inf = INT_MAX;
const ld ep = 0.0000001;
const ld pi = acos(-1.0);
const ll md = 1000000007;

//-----GLOBALS-----
int d[N]={0};
int a[N]={0};
//-----SOLUTION-----
void solve(){
	setpr(10);
	int m; see(m);
	ld s=0; int n=1;
	while(m--){
		int t; see(t);
		if (t==2){
			int x; see(x);
			s+=x; n++;
			a[n]=x;
		}
		else if (t==1){
			int y,x; see(y,x);
			d[y]+=x;
			s+= (y*x);
		}
		else {
			int x = d[n] + a[n];
			d[n-1]+=d[n];
			a[n]=0;
			s-=x; n--;
		}
		cout<<s/n<<nl;
	}
}

//-----MAIN-----
signed main(){
	IOS;

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif

	int t=1;
	//cin>>t;
	while(t--) {
		solve();
		//cout<<nl;
	}

}


//-----HEADER-----
#include<bits/stdc++.h>
using namespace std;

//-----MACROS-----
#define int long long
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vc vector
#define nl '\n'
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for (int i=a; i<b; ++i)
#define rev(i,a,b) for (int i=a; i>b; --i)
#define IOS ios_base::sync_with_stdio(false)
#define setpr(x) cout<<setprecision(x)<<fixed
#define sz size()
#define N 200005

//-----TEMPLATES-----
template<typename... T>
void see(T&... args) {
	((cin >> args), ...);
}

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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

//-----CONSTANTS-----
const ll inf = INT_MAX;
const ld ep = 0.0000001;
const ld pi = acos(-1.0);
const ll md = 1000000007;

//-----GLOBALS-----
int tree[N+1]={0};
void update(int n, int x,int val){
	for(;x<=n; x+=x&-x) tree[x]+=val;
}
int query(int x){
	int s=0;
	for(;x>0;x-=x&-x) s+=tree[x];
	return s;
}
int i=2;
//-----SOLUTION-----
void solve(){
	//range update
	setpr(10);
	int m; see(m);
	ld s=0, n=1;
	vi v={0};
	while(m--){
		int t; see(t);
		if (t==2){
			int x; see(x);
			s+=x; n++;
			int vl = query(i-1);
			update(i,i,x-vl);i++;
		}
		else if (t==1){
			int y,x; see(y,x);
			update(i-1,1,x), update(i-1,y+1,-x);
			s+= (y*x);
		}
		else {
			int vl = query(i-1);
			s-=vl; n--;
			update(i-1,i-1,-vl);i--;
		}
		cout<<s/n<<nl;
	}
}

//-----MAIN-----
signed main(){
	IOS;

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif

	int t=1;
	//cin>>t;
	while(t--) {
		solve();
		//cout<<nl;
	}

}


//-----HEADER-----
#include<bits/stdc++.h>
using namespace std;

//-----MACROS-----
#define int long long
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vc vector
#define nl '\n'
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for (int i=a; i<b; ++i)
#define rev(i,a,b) for (int i=a; i>b; --i)
#define IOS ios_base::sync_with_stdio(false)
#define setpr(x) cout<<setprecision(x)<<fixed
#define sz size()
#define N 100005

//-----TEMPLATES-----
template<typename... T>
void see(T&... args) {
	((cin >> args), ...);
}

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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

//-----CONSTANTS-----
const ll inf = INT_MAX;
const ld ep = 0.0000001;
const ld pi = acos(-1.0);
const ll md = 1000000007;

//-----GLOBALS-----
int tree[N+1]={0};
void update(int n, int x,int val){
	for(;x<=n; x+=x&-x) tree[x]+=val;
}
int query(int x){
	int s=0;
	for(;x>0;x-=x&-x) s+=tree[x];
	return s;
}
int i=2;
//-----SOLUTION-----
void solve(){
	//range update
	setpr(10);
	int m; see(m);
	ld s=0, n=1;
	vi v={0};
	while(m--){
		int t; see(t);
		if (t==2){
			int x; see(x);
			s+=x; n++;
			int vl = query(i-1);
			update(i,i,x-vl);i++;
		}
		else if (t==1){
			int y,x; see(y,x);
			update(i-1,1,x), update(i-1,y+1,-x);
			s+= (y*x);
		}
		else {
			int vl = query(i-1);
			s-=vl; n--;
			update(i-1,i-1,-vl);i--;
		}
		cout<<s/n<<nl;
	}
}

//-----MAIN-----
signed main(){
	IOS;

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif

	int t=1;
	//cin>>t;
	while(t--) {
		solve();
		//cout<<nl;
	}

}


//-----HEADER-----
#include<bits/stdc++.h>
using namespace std;

//-----MACROS-----
#define int long long
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vc vector
#define nl '\n'
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for (int i=a; i<b; ++i)
#define rev(i,a,b) for (int i=a; i>b; --i)
#define IOS ios_base::sync_with_stdio(false)
#define setpr(x) cout<<setprecision(x)<<fixed
#define sz size()
#define N 200005

//-----TEMPLATES-----
template<typename... T>
void see(T&... args) {
	((cin >> args), ...);
}

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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

//-----CONSTANTS-----
const ll inf = INT_MAX;
const ld ep = 0.0000001;
const ld pi = acos(-1.0);
const ll md = 1000000007;

//-----GLOBALS-----
int tree[N+1]={0};
void update(int n, int x,int val){
	for(;x<=n; x+=x&-x) tree[x]+=val;
}
int query(int x){
	int s=0;
	for(;x>0;x-=x&-x) s+=tree[x];
	return s;
}
int find(int x){
	int c=0;
	while(!(x&1)){
		x>>=1; c++;
	}
	c = pow(2,c);
	return (query(x-1)-query(x-c));
}
int i=2;
//-----SOLUTION-----
void solve(){
	//range update
	setpr(10);
	int m; see(m);
	ld s=0, n=1;
	vi v={0};
	while(m--){
		int t; see(t);
		if (t==2){
			int x; see(x);
			s+=x; n++;
			int vl = query(i-1);
			int v = find(i);
			update(i,i,x-vl+v);i++;
		}
		else if (t==1){
			int y,x; see(y,x);
			update(i-1,1,x), update(i-1,y+1,-x);
			s+= (y*x);
		}
		else {
			int vl = query(i-1);
			s-=vl; n--;
			update(i-1,i-1,-vl);i--;
		}
		cout<<s/n<<nl;
	}
}

//-----MAIN-----
signed main(){
	IOS;

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif

	int t=1;
	//cin>>t;
	while(t--) {
		solve();
		//cout<<nl;
	}

}


//-----HEADER-----
#include<bits/stdc++.h>
using namespace std;

//-----MACROS-----
#define int long long
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vc vector
#define nl '\n'
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for (int i=a; i<b; ++i)
#define rev(i,a,b) for (int i=a; i>b; --i)
#define IOS ios_base::sync_with_stdio(false)
#define setpr(x) cout<<setprecision(x)<<fixed
#define sz size()
#define N 200005

//-----TEMPLATES-----
template<typename... T>
void see(T&... args) {
	((cin >> args), ...);
}

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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

//-----CONSTANTS-----
const ll inf = INT_MAX;
const ld ep = 0.0000001;
const ld pi = acos(-1.0);
const ll md = 1000000007;

//-----GLOBALS-----
int tree[N+1]={0};
void update(int n, int x,int val){
	for(;x<=n; x+=x&-x) tree[x]+=val;
}
int query(int x){
	int s=0;
	for(;x>0;x-=x&-x) s+=tree[x];
	return s;
}
int find(int x){
	int c=0;
	while(!(x&1)){
		x>>=1; c++;
	}
	c = pow(2,c);
	return (query(x-1)-query(x-c));
}
int i=2;
//-----SOLUTION-----
void solve(){
	//range update
	setpr(10);
	int m; see(m);
	ld s=0, n=1;
	vi v={0};
	while(m--){
		int t; see(t);
		if (t==2){
			int x; see(x);
			s+=x; n++;
			int vl = query(i-1);
			int v = find(i);
			tree[i]=x-vl+v;i++;
		}
		else if (t==1){
			int y,x; see(y,x);
			update(i-1,1,x), update(i-1,y+1,-x);
			s+= (y*x);
		}
		else {
			int vl = query(i-1);
			s-=vl; n--;
			tree[i-1]=0;i--;
		}
		rep(j,1,i) error(tree[j]);
		error(nl);
		cout<<s/n<<nl;
	}
}

//-----MAIN-----
signed main(){
	IOS;

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif

	int t=1;
	//cin>>t;
	while(t--) {
		solve();
		//cout<<nl;
	}

}


//-----HEADER-----
#include<bits/stdc++.h>
using namespace std;

//-----MACROS-----
#define int long long
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vc vector
#define nl '\n'
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for (int i=a; i<b; ++i)
#define rev(i,a,b) for (int i=a; i>b; --i)
#define IOS ios_base::sync_with_stdio(false)
#define setpr(x) cout<<setprecision(x)<<fixed
#define sz size()
#define N 200005

//-----TEMPLATES-----
template<typename... T>
void see(T&... args) {
	((cin >> args), ...);
}

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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

//-----CONSTANTS-----
const ll inf = INT_MAX;
const ld ep = 0.0000001;
const ld pi = acos(-1.0);
const ll md = 1000000007;

//-----GLOBALS-----
double d[N]={0};
int a[N]={0};
//-----SOLUTION-----
void solve(){
	setpr(8);
	int m; see(m);
	double s=0; int n=1;
	while(m--){
		int t; see(t);
		if (t==2){
			int x; see(x);
			s+=x; n++;
			a[n]=x;
		}
		else if (t==1){
			int y,x; see(y,x);
			d[y]+=x;
			s+= (y*x);
		}
		else {
			int x = d[n] + a[n];
			d[n-1]+=d[n];
			a[n]=0;
			s-=x; n--;
		}
		cout<<s/n<<nl;
	}
}

//-----MAIN-----
signed main(){
	IOS;

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif

	int t=1;
	//cin>>t;
	while(t--) {
		solve();
		//cout<<nl;
	}

}


//-----HEADER-----
#include<bits/stdc++.h>
using namespace std;

//-----MACROS-----
#define int long long
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vc vector
#define nl '\n'
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for (int i=a; i<b; ++i)
#define rev(i,a,b) for (int i=a; i>b; --i)
#define IOS ios_base::sync_with_stdio(false)
#define setpr(x) cout<<setprecision(x)<<fixed
#define sz size()
#define N 200005

//-----TEMPLATES-----
template<typename... T>
void see(T&... args) {
	((cin >> args), ...);
}

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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

//-----CONSTANTS-----
const ll inf = INT_MAX;
const ld ep = 0.0000001;
const ld pi = acos(-1.0);
const ll md = 1000000007;

//-----GLOBALS-----
double d[N]={0};
int a[N]={0};
//-----SOLUTION-----
void solve(){
	cout.precision(9); cout<<fixed;
	int m; see(m);
	int s=0; int n=1;
	while(m--){
		int t; see(t);
		if (t==2){
			int x; see(x);
			s+=x; n++;
			a[n]=x;
		}
		else if (t==1){
			int y,x; see(y,x);
			d[y]+=x;
			s+= (y*x);
		}
		else {
			int x = d[n] + a[n];
			d[n-1]+=d[n];
			a[n]=0;
			s-=x; n--;
		}
		double av = 1.0*s/n;
		cout<<av<<nl;
	}
}

//-----MAIN-----
signed main(){
	IOS;

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif

	int t=1;
	//cin>>t;
	while(t--) {
		solve();
		//cout<<nl;
	}

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j;
    int n;
    cin>>n;
    vector<int>v;
    double a=0;
    int check[100000]={0};
    v.push_back(0);
    while(n--)
    {
        int x;
        cin>>x;
        if(x==1)
        {
            int m,add;
            cin>>m>>add;
            check[m-1]+=add;
            a+=(m*add)*(1.0)/v.size();
            cout<<a<<endl;
        }
        else if(x==2)
        {
            int k;
            cin>>k;
            v.push_back(k);
            // cout<<k<<"hi";
            a=(a*(v.size()-1)+k)*1.0/(v.size());
            cout<<a<<endl;
        }
        else
        {
            int k=v[v.size()-1];
            v.pop_back();
            a=((a*(v.size()+1)-k-check[v.size()])*1.0)/(v.size());
            check[v.size()]+=check[v.size()+1];
            cout<<a<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j;
    int n;
    cin>>n;
    vector<int>v;
    double a=0;
    int check[100000]={0};
    v.push_back(0);
    while(n--)
    {
        int x;
        cin>>x;
        if(x==1)
        {
            int m,add;
            cin>>m>>add;
            check[m-1]+=add;
            a+=(m*add)*(1.0)/v.size();
            cout<<fixed<<setprecision(7)<<a<<endl;
        }
        else if(x==2)
        {
            int k;
            cin>>k;
            v.push_back(k);
            // cout<<k<<"hi";
            a=(a*(v.size()-1)+k)*1.0/(v.size());
            cout<<fixed<<setprecision(7)<<a<<endl;
        }
        else
        {
            int k=v[v.size()-1];
            v.pop_back();
            a=((a*(v.size()+1)-k-check[v.size()])*1.0)/(v.size());
            check[v.size()]+=check[v.size()+1];
            cout<<fixed<<setprecision(7)<<a<<endl;
        }
    }
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <stack>
#include <ctime>
#include <unordered_map>
#pragma comment (linker, "/STACK:256000000")

using namespace std;

const int maxN = 210000;
double add[maxN];
double value[maxN];

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	double s = 0.0;
	int n;
	scanf("%d", &n);
	int length = 1;
	for (int i = 1; i <= n; ++i) {
		int t;
		scanf("%d", &t);
		if (t == 1) {
			int a, x;
			scanf("%d%d", &a, &x);
			add[a] += x;
			s += (double)(a) * (double)(x);
		} else if (t == 2) {
			int k;
			scanf("%d", &k);
			s += (double)(k);
			++length;
			value[length] = k;
		} else {
			s -= value[length];
			s -= add[length];
			add[length - 1] += add[length];
			value[length] = 0;
			add[length] = 0;
			--length;
		}
		printf("%.10lf\n", (double)(s) / (double)(length));
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long i,j;
    long long n;
    cin>>n;
    vector<long long>v;
    double a=0.0;
    long long check[100000]={0};
    v.push_back(0);
    while(n--)
    {
        long long x;
        cin>>x;
        if(x==1)
        {
            long long m,add;
            cin>>m>>add;
            check[m-1]+=add;
            a+=double(m*add)/double(v.size());
            cout<<a<<endl;
        }
        else if(x==2)
        {
            long long k;
            cin>>k;
            v.push_back(k);
            // cout<<k<<"hi";
            a=(double(a*(v.size()-1)+k))/double(v.size());
            cout<<a<<endl;
        }
        else
        {
            long long k=v[v.size()-1];
            v.pop_back();
            a=double(a*(v.size()+1)-k-check[v.size()])/double(v.size());
            check[v.size()]+=check[v.size()+1];
            cout<<a<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long i,j;
    long long n;
    cin>>n;
    vector<long long>v;
    double a=0;
    long long check[100000]={0};
    v.push_back(0);
    while(n--)
    {
        long long x;
        cin>>x;
        if(x==1)
        {
            long long m,add;
            cin>>m>>add;
            check[m-1]+=add;
            a+=(m*add)*(1.0)/v.size();
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
        else if(x==2)
        {
            long long k;
            cin>>k;
            v.push_back(k);
            // cout<<k<<"hi";
            a=((a*(v.size()-1)+k)*1.0)/(v.size());
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
        else
        {
            long long k=v[v.size()-1];
            v.pop_back();
            a=((a*(v.size()+1)-k-check[v.size()]))/(v.size());
            check[v.size()]+=check[v.size()+1];
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long i,j;
    long long n;
    cin>>n;
    vector<long long>v;
    double a=0.0;
    long long check[100000]={0};
    v.push_back(0);
    while(n--)
    {
        long long x;
        cin>>x;
        if(x==1)
        {
            long long m,add;
            cin>>m>>add;
            check[m-1]+=add;
            a+=double(m*add)/double(v.size());
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
        else if(x==2)
        {
            long long k;
            cin>>k;
            v.push_back(k);
            // cout<<k<<"hi";
            a=(double(a*(v.size()-1)+k))/double(v.size());
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
        else
        {
            long long k=v[v.size()-1];
            v.pop_back();
            a=double(a*(v.size()+1)-k-check[v.size()])/double(v.size());
            check[v.size()]+=check[v.size()+1];
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j;
    int n;
    cin>>n;
    vector<int>v;
    double a=0;
    int check[100000]={0};
    v.push_back(0);
    while(n--)
    {
        int x;
        cin>>x;
        if(x==1)
        {
            int m,add;
            cin>>m>>add;
            check[m-1]+=add;
            a+=(m*add)*(1.0)/v.size();
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
        else if(x==2)
        {
            int k;
            cin>>k;
            v.push_back(k);
            a=((a*(v.size()-1)+k)*1.0)/(v.size());
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
        else
        {
            int k=v[v.size()-1];
            v.pop_back();
            a=((a*(v.size()+1)-k-check[v.size()]))/(v.size());
            check[v.size()]+=check[v.size()+1];
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j;
    int n;
    cin>>n;
    vector<int>v;
    double a=0;
    int check[100000]={0};
    v.push_back(0);
    while(n--)
    {
        int x;
        cin>>x;
        if(x==1)
        {
            int m,add;
            cin>>m>>add;
            check[m-1]+=add;
            a+=(m*add)*(1.0)/v.size();
            cout<<fixed<<setprecision(5)<<a<<endl;
        }
        else if(x==2)
        {
            int k;
            cin>>k;
            v.push_back(k);
            // cout<<k<<"hi";
            a=(a*(v.size()-1)+k)*1.0/(v.size());
            cout<<fixed<<setprecision(5)<<a<<endl;
        }
        else
        {
            int k=v[v.size()-1];
            v.pop_back();
            a=((a*(v.size()+1)-k-check[v.size()])*1.0)/(v.size());
            check[v.size()]+=check[v.size()+1];
            cout<<fixed<<setprecision(5)<<a<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j;
    int n;
    cin>>n;
    vector<int>v;
    double a=0;
    int check[100000]={0};
    v.push_back(0);
    while(n--)
    {
        int x;
        cin>>x;
        if(x==1)
        {
            int m,add;
            cin>>m>>add;
            check[m-1]+=add;
            a+=(m*add)*(1.0)/v.size();
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
        else if(x==2)
        {
            int k;
            cin>>k;
            v.push_back(k);
            // cout<<k<<"hi";
            a=(a*(v.size()-1)+k)*1.0/(v.size());
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
        else
        {
            int k=v[v.size()-1];
            v.pop_back();
            a=((a*(v.size()+1)-k-check[v.size()])*1.0)/(v.size());
            check[v.size()]+=check[v.size()+1];
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long i,j;
    long long n;
    cin>>n;
    vector<long long>v;
    double a=0.0;
    long long check[100000]={0};
    v.push_back(0);
    while(n--)
    {
        long long x;
        cin>>x;
        if(x==1)
        {
            long long m,add;
            cin>>m>>add;
            check[m-1]+=add;
            a+=(m*add)*(1.0)/v.size();
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
        else if(x==2)
        {
            long long k;
            cin>>k;
            v.push_back(k);
            // cout<<k<<"hi";
            a=((a*(v.size()-1)+k)*1.0)/(v.size());
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
        else
        {
            long long k=v[v.size()-1];
            v.pop_back();
            a=((a*(v.size()+1)-k-check[v.size()]))/(v.size());
            check[v.size()]+=check[v.size()+1];
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j;
    int n;
    cin>>n;
    vector<int>v;
    double a=0.0;
    int check[100000]={0};
    v.push_back(0);
    while(n--)
    {
        int x;
        cin>>x;
        if(x==1)
        {
            int m,add;
            cin>>m>>add;
            check[m-1]+=add;
            int ana=(m*add);
            ana=(ana*1.0)/v.size();
            a+=ana;
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
        else if(x==2)
        {
            int k;
            cin>>k;
            v.push_back(k);
            // cout<<k<<"hi";
            a=((a*(v.size()-1)+k));
            a=(a*1.0)/(v.size());
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
        else
        {
            int k=v[v.size()-1];
            v.pop_back();
            a=a*(v.size()+1);
            a=a-k-check[v.size()];
            a=(a*1.0)/(v.size());
            check[v.size()]+=check[v.size()+1];
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j;
    int n;
    cin>>n;
    vector<int>v;
    double a=0;
    v.push_back(0);
    while(n--)
    {
        int x;
        cin>>x;
        if(x==1)
        {
            int m,add;
            cin>>m>>add;
            for(i=0;i<m;i++)
            v[i]+=add;
            a+=(m*add)*(1.0)/v.size();
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
        else if(x==2)
        {
            int k;
            cin>>k;
            v.push_back(k);
            // cout<<k<<"hi";
            a=(a*(v.size()-1)+k)*1.0/(v.size());
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
        else
        {
            int k=v[v.size()-1];
            v.pop_back();
            a=((a*(v.size()+1)-k)*1.0)/(v.size());
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j;
    int n;
    cin>>n;
    vector<int>v;
    float a=0;
    int check[100000]={0};
    v.push_back(0);
    while(n--)
    {
        int x;
        cin>>x;
        if(x==1)
        {
            int m,add;
            cin>>m>>add;
            check[m-1]+=add;
            a+=(m*add)/v.size();
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
        else if(x==2)
        {
            int k;
            cin>>k;
            v.push_back(k);
            a=(a*(v.size()-1)+k)/(v.size());
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
        else
        {
            int k=v[v.size()-1];
            v.pop_back();
            a=((a*(v.size()+1)-k-check[v.size()]))/(v.size());
            check[v.size()]+=check[v.size()+1];
            cout<<fixed<<setprecision(6)<<a<<endl;
        }
    }
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<conio.h>
using namespace std;
vector<double> mm(500000,0);
double a[500000];
int main()
{
    double sum=0;
    int n,m;
    scanf("%d",&m);
    int p,s;
    double t,res;
     n=1;
    int i,j;

    a[0]=0;
  cout<<fixed;
    for(i=0;i<m;i++)
    {
         scanf("%d",&p);
        if(p==1)
        {
             scanf("%d",&s);
              scanf("%lf",&t);
            if(t==0)
            {
                printf("%0.10lf\n", res) ;
                continue;
            }
            sum=sum+s*t;
             res=(sum*1.000000)/(n*1.000000);
             printf("%0.10lf\n", res);

            mm[s]=mm[s]+t;
        }
        else if(p==2)
        {
            cin>>t;

            sum=sum+t;
            a[n]=t;
            n++;
               res=(sum*1.000000)/(n*1.000000);
             printf("%0.10lf\n", res) ;
        }
        else if(p==3)
        {
            sum=sum-a[n-1];

            sum=sum-mm[n];
            n--;
            mm[n]=mm[n]+mm[n+1];
                        res=(sum*1.000000)/(n*1.000000);
                     printf("%0.10lf\n", res);

        }

    }
 return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<conio.h>
using namespace std;
vector<double> mm(500000,0);
double a[500000];
int main()
{
    double sum=0;
    int n,m;
    scanf("%d",&m);
    int p,s;
    double t,res;
     n=1;
    int i,j;

    a[0]=0;
  cout<<fixed;
    for(i=0;i<m;i++)
    {
         scanf("%d",&p);
        if(p==1)
        {
             scanf("%d",&s);
              scanf("%lf",&t);
            if(s>n)
            s=n;
            sum=sum+s*t;
             res=(sum*1.000000000000)/(double(n));
             printf("%0.10lf\n", res);

            mm[s]=mm[s]+t;
        }
        else if(p==2)
        {
            cin>>t;

            sum=sum+t;
            a[n]=t;
            n++;
               res=(sum*1.000000000000)/(double(n));
             printf("%0.10lf\n", res) ;
        }
        else if(p==3&&n>=2)
        {
            sum=sum-a[n-1];

            sum=sum-mm[n];
            n--;
            mm[n]=mm[n]+mm[n+1];
                       res=(sum*1.000000000000)/(double(n));
                     printf("%0.10lf\n", res);

        }

    }
 return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<conio.h>
using namespace std;
vector<double> mm(500000,0);
double a[500000];
int main()
{
    double sum=0;
    int n,m;
    scanf("%d",&m);
    int p,s;
    double t,res;
     n=1;
    int i,j;

    a[0]=0;
  cout<<fixed;
    for(i=0;i<m;i++)
    {
         scanf("%d",&p);
        if(p==1)
        {
             scanf("%d",&s);
              scanf("%lf",&t);
            if(t==0)
            {
                printf("%0.6lf", res); <<"\n";
                continue;
            }
            sum=sum+s*t;
             res=(sum*1.000000)/(n*1.000000);
             printf("%0.6lf", res); <<"\n";

            mm[s]=mm[s]+t;
        }
        else if(p==2)
        {
            cin>>t;

            sum=sum+t;
            a[n]=t;
            n++;
               res=(sum*1.000000)/(n*1.000000);
             printf("%0.6lf", res); <<"\n";
        }
        else if(p==3)
        {
            sum=sum-a[n-1];

            sum=sum-mm[n];
            n--;
            mm[n]=mm[n]+mm[n+1];
                        res=(sum*1.000000)/(n*1.000000);
                     printf("%0.6lf", res); <<"\n";

        }

    }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{map<int,vector<int>> mm;
 map<int,vector<int>> ::iterator it;
    double sum=0;
    int n,m;
    cin>>m;
    int p,s,t;
     n=1;
    int i,j;
    stack<int>ss;
    ss.push(0);
    for(i=0;i<m;i++)
    {
        cin>>p;
        if(p==1)
        {
            cin>>s>>t;
            sum=sum+s*t;
             cout<<setprecision(6)<<sum/(n*1.0)<<"\n";
            mm[s].push_back(t);
        }
        else if(p==2)
        {
            cin>>s;
            sum=sum+s;
            ss.push(s);
            n++;
             cout<<setprecision(6)<<sum/(n*1.0)<<"\n";
        }
        else if(p==3)
        {
            sum=sum-ss.top();
            ss.pop();
            if(mm.count(n)>0)
            {
                it=mm.find(n);
                int jj=it->second.size();
                int kk;
                int nn=it->first;
                nn--;
                for(kk=0;kk<jj;kk++)
                {
                    sum=sum-it->second[kk];
            mm[nn].push_back(it->second[kk]);
                }
            mm.erase(n);
            n--;

            cout<<setprecision(6)<<sum/(n*1.0)<<"\n";

            }
            else
            {
                n--;
                   cout<<setprecision(6)<<sum/(n*1.0)<<"\n";
            }

        }

    }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{map<int,vector<double>> mm;
 map<int,vector<double>> ::iterator it;
    double sum=0;
    int n,m;
    cin>>m;
    int p,s;
    double t;
     n=1;
    int i,j;
    stack<double>ss;
    ss.push(0);
    for(i=0;i<m;i++)
    {
        cin>>p;
        if(p==1)
        {
            cin>>s>>t;
            sum=sum+s*t;
             cout<<setprecision(6)<<(sum*1.000000)/(n*1.000000)<<"\n";
            mm[s].push_back(t);
        }
        else if(p==2)
        {
            cin>>t;
            sum=sum+t;
            ss.push(t);
            n++;
             cout<<setprecision(6)<<(sum*1.000000)/(n*1.000000)<<"\n";
        }
        else if(p==3)
        {
            sum=sum-ss.top();
            ss.pop();
            if(mm.count(n)>0)
            {
                it=mm.find(n);
                int jj=it->second.size();
                int kk;
                int nn=it->first;
                nn--;
                for(kk=0;kk<jj;kk++)
                {
                    sum=sum-it->second[kk];
            mm[nn].push_back(it->second[kk]);
                }
            mm.erase(n);
            n--;

              cout<<setprecision(6)<<(sum*1.000000)/(n*1.000000)<<"\n";

            }
            else
            {
                n--;
                     cout<<setprecision(6)<<(sum*1.000000)/(n*1.000000)<<"\n";
            }

        }

    }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<double> mm(500000,0);
int main()
{
    double sum=0;
    int n,m;
    cin>>m;
    int p,s;
    double t,res;
     n=1;
    int i,j;
    stack<double>ss;
    ss.push(0);
  cout<<fixed;
    for(i=0;i<m;i++)
    {
        cin>>p;
        if(p==1)
        {
            cin>>s>>t;
            if(t==0)
            {
                cout<<setprecision(6)<<res<<"\n";
                continue;
            }
            sum=sum+s*t;
             res=(sum*1.000000)/(n*1.000000);
             cout<<setprecision(6)<<res<<"\n";

            mm[s]=mm[s]+t;
        }
        else if(p==2)
        {
            cin>>t;

            sum=sum+t;
            ss.push(t);
            n++;
               res=(sum*1.000000)/(n*1.000000);
             cout<<setprecision(6)<<res<<"\n";
        }
        else if(p==3)
        {
            sum=sum-ss.top();
            ss.pop();
            sum=sum-mm[n];
            n--;
            mm[n]=mm[n]+mm[n+1];
                        res=(sum*1.000000)/(n*1.000000);
                     cout<<setprecision(6)<<res<<"\n";

        }

    }
 return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<conio.h>
using namespace std;
vector<double> mm(500000,0);
double a[500000];
int main()
{
    double sum=0;
    int n,m;
    scanf("%d",&m);
    int p,s;
    double t,res;
     n=1;
    int i,j;

    a[0]=0;
  cout<<fixed;
    for(i=0;i<m;i++)
    {
         scanf("%d",&p);
        if(p==1)
        {
             scanf("%d",&s);
              scanf("%lf",&t);

            sum=sum+s*t;
             res=(sum*1.000000)/(n*1.000000);
             printf("%0.10lf\n", res);

            mm[s]=mm[s]+t;
        }
        else if(p==2)
        {
            cin>>t;

            sum=sum+t;
            a[n]=t;
            n++;
               res=(sum*1.000000)/(n*1.000000);
             printf("%0.10lf\n", res) ;
        }
        else if(p==3)
        {
            sum=sum-a[n-1];

            sum=sum-mm[n];
            n--;
            mm[n]=mm[n]+mm[n+1];
                        res=(sum*1.000000)/(n*1.000000);
                     printf("%0.10lf\n", res);

        }

    }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<double> mm(500000,0);
int main()
{
    double sum=0;
    int n,m;
    cin>>m;
    int p,s;
    double t;
     n=1;
    int i,j;
    stack<double>ss;
    ss.push(0);
  cout<<fixed;
    for(i=0;i<m;i++)
    {
        cin>>p;
        if(p==1)
        {
            cin>>s>>t;
            sum=sum+s*t;
            double res=(sum*1.000000)/(n*1.000000);
             cout<<setprecision(6)<<res<<"\n";

            mm[s]=mm[s]+t;
        }
        else if(p==2)
        {
            cin>>t;
            sum=sum+t;
            ss.push(t);
            n++;
              double res=(sum*1.000000)/(n*1.000000);
             cout<<setprecision(6)<<res<<"\n";
        }
        else if(p==3)
        {
            sum=sum-ss.top();
            ss.pop();
            sum=sum-mm[n];
            n--;
            mm[n]=mm[n+1];
                       double res=(sum*1.000000)/(n*1.000000);
                     cout<<setprecision(6)<<res<<"\n";

        }

    }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{map<int,vector<double>> mm;
 map<int,vector<double>> ::iterator it;
    double sum=0;
    int n,m;
    cin>>m;
    int p,s;
    double t;
     n=1;
    int i,j;
    stack<double>ss;
    ss.push(0);
  cout<<fixed;
    for(i=0;i<m;i++)
    {
        cin>>p;
        if(p==1)
        {
            cin>>s>>t;
            sum=sum+s*t;
            double res=(sum*1.000000)/(n*1.000000);
             cout<<setprecision(6)<<res<<"\n";
            mm[s].push_back(t);
        }
        else if(p==2)
        {
            cin>>t;
            sum=sum+t;
            ss.push(t);
            n++;
              double res=(sum*1.000000)/(n*1.000000);
             cout<<setprecision(6)<<res<<"\n";
        }
        else if(p==3)
        {
            sum=sum-ss.top();
            ss.pop();
            if(mm.count(n)>0)
            {
                it=mm.find(n);
                int jj=it->second.size();
                int kk;
                int nn=it->first;
                nn--;
                for(kk=0;kk<jj;kk++)
                {
                    sum=sum-it->second[kk];
            mm[nn].push_back(it->second[kk]);
                }
            mm.erase(n);
            n--;
              double res=(sum*1.000000)/(n*1.000000);
              cout<<setprecision(6)<<res<<"\n";

            }
            else
            {
                n--;
                       double res=(sum*1.000000)/(n*1.000000);
                     cout<<setprecision(6)<<res<<"\n";
            }

        }

    }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{map<int,double> mm;
 map<int,double> ::iterator it;
    double sum=0;
    int n,m;
    cin>>m;
    int p,s;
    double t;
     n=1;
    int i,j;
    stack<double>ss;
    ss.push(0);
  cout<<fixed;
    for(i=0;i<m;i++)
    {
        cin>>p;
        if(p==1)
        {
            cin>>s>>t;
            sum=sum+s*t;
            double res=(sum*1.000000)/(n*1.000000);
             cout<<setprecision(6)<<res<<"\n";
            if(mm.count(s)>0)
            {
                mm[s]=mm[s]+t;
            }
            else
            mm[s]=t;
        }
        else if(p==2)
        {
            cin>>t;
            sum=sum+t;
            ss.push(t);
            n++;
              double res=(sum*1.000000)/(n*1.000000);
             cout<<setprecision(6)<<res<<"\n";
        }
        else if(p==3)
        {
            sum=sum-ss.top();
            ss.pop();
            if(mm.count(n)>0)
            {
                it=mm.find(n);

                int kk;
                int nn=it->first;
                nn--;
                sum=sum-it->second;

            if(mm.count(nn)>0)
            mm[nn]=mm[nn]+it->second;
            else
            mm[nn]=it->second;
             mm.erase(n);
            n--;
              double res=(sum*1.000000)/(n*1.000000);
              cout<<setprecision(6)<<res<<"\n";

            }
            else
            {
                n--;
                       double res=(sum*1.000000)/(n*1.000000);
                     cout<<setprecision(6)<<res<<"\n";
            }

        }

    }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{map<int,vector<int>> mm;
 map<int,vector<int>> ::iterator it;
    double sum=0;
    int n,m;
    cin>>m;
    int p,s,t;
     n=1;
    int i,j;
    stack<int>ss;
    ss.push(0);
    for(i=0;i<m;i++)
    {
        cin>>p;
        if(p==1)
        {
            cin>>s>>t;
            sum=sum+s*t;
            cout<<sum/(n*1.0)<<"\n";
            m[s].push_back(t);
        }
        else if(p==2)
        {
            cin>>s;
            sum=sum+s;
            ss.push(s);
            n++;
            cout<<sum/(n*1.0)<<"\n";
        }
        else if(p==3)
        {
            sum=sum-ss.top();
            ss.pop();
            if(mm.count(n)>0)
            {
                it=mm.find(n);
                int jj=it->second.size();
                int kk;
                int nn=it->first;
                nn--;
                for(kk=0;kk<jj;kk++)
                {
                    sum=sum-it->second[kk];
            mm[nn].push_back(it->second[kk]);
                }
            mm.remove(n);
            n--;

            cout<<sum/(n*1.0)<<"\n";

            }
            else
            {
                n--;
                   cout<<sum/(n*1.0)<<"\n";
            }

        }

    }
 return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<conio.h>
using namespace std;
vector<double> mm(500000,0);
double a[500000];
int main()
{
    double sum=0;
    int n,m;
    scanf("%d",&m);
    int p,s;
    double t,res;
     n=1;
    int i,j;

    a[0]=0;
  cout<<fixed;
    for(i=0;i<m;i++)
    {
         scanf("%d",&p);
        if(p==1)
        {
             scanf("%d",&s);
              scanf("%lf",&t);
            if(t==0)
            {
                printf("%0.6lf\n", res) ;
                continue;
            }
            sum=sum+s*t;
             res=(sum*1.000000)/(n*1.000000);
             printf("%0.6lf\n", res);

            mm[s]=mm[s]+t;
        }
        else if(p==2)
        {
            cin>>t;

            sum=sum+t;
            a[n]=t;
            n++;
               res=(sum*1.000000)/(n*1.000000);
             printf("%0.6lf\n", res) ;
        }
        else if(p==3)
        {
            sum=sum-a[n-1];

            sum=sum-mm[n];
            n--;
            mm[n]=mm[n]+mm[n+1];
                        res=(sum*1.000000)/(n*1.000000);
                     printf("%0.6lf\n", res);

        }

    }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{map<int,vector<int>> mm;
 map<int,vector<int>> ::iterator it;
    double sum=0;
    int n,m;
    cin>>m;
    int p,s,t;
     n=1;
    int i,j;
    stack<int>ss;
    ss.push(0);
    for(i=0;i<m;i++)
    {
        cin>>p;
        if(p==1)
        {
            cin>>s>>t;
            sum=sum+s*t;
            cout<<sum/(n*1.0)<<"\n";
            mm[s].push_back(t);
        }
        else if(p==2)
        {
            cin>>s;
            sum=sum+s;
            ss.push(s);
            n++;
            cout<<sum/(n*1.0)<<"\n";
        }
        else if(p==3)
        {
            sum=sum-ss.top();
            ss.pop();
            if(mm.count(n)>0)
            {
                it=mm.find(n);
                int jj=it->second.size();
                int kk;
                int nn=it->first;
                nn--;
                for(kk=0;kk<jj;kk++)
                {
                    sum=sum-it->second[kk];
            mm[nn].push_back(it->second[kk]);
                }
            mm.erase(n);
            n--;

            cout<<sum/(n*1.0)<<"\n";

            }
            else
            {
                n--;
                   cout<<sum/(n*1.0)<<"\n";
            }

        }

    }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<double> mm(500000,0);
double a[500000];
int main()
{
    double sum=0;
    int n,m;
    cin>>m;
    int p,s;
    double t,res;
     n=1;
    int i,j;

    a[0]=0;
  cout<<fixed;
    for(i=0;i<m;i++)
    {
        cin>>p;
        if(p==1)
        {
            cin>>s>>t;
            if(t==0)
            {
                cout<<setprecision(6)<<res<<"\n";
                continue;
            }
            sum=sum+s*t;
             res=(sum*1.000000)/(n*1.000000);
             cout<<setprecision(6)<<res<<"\n";

            mm[s]=mm[s]+t;
        }
        else if(p==2)
        {
            cin>>t;

            sum=sum+t;
            a[n]=t;
            n++;
               res=(sum*1.000000)/(n*1.000000);
             cout<<setprecision(6)<<res<<"\n";
        }
        else if(p==3)
        {
            sum=sum-a[n-1];

            sum=sum-mm[n];
            n--;
            mm[n]=mm[n]+mm[n+1];
                        res=(sum*1.000000)/(n*1.000000);
                     cout<<setprecision(6)<<res<<"\n";

        }

    }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{unordered_map<int,double> mm;
 unordered_map<int,double> ::iterator it;
    double sum=0;
    int n,m;
    cin>>m;
    int p,s;
    double t;
     n=1;
    int i,j;
    stack<double>ss;
    ss.push(0);
  cout<<fixed;
    for(i=0;i<m;i++)
    {
        cin>>p;
        if(p==1)
        {
            cin>>s>>t;
            sum=sum+s*t;
            double res=(sum*1.000000)/(n*1.000000);
             cout<<setprecision(6)<<res<<"\n";
            if(mm.count(s)>0)
            {
                mm[s]=mm[s]+t;
            }
            else
            mm[s]=t;
        }
        else if(p==2)
        {
            cin>>t;
            sum=sum+t;
            ss.push(t);
            n++;
              double res=(sum*1.000000)/(n*1.000000);
             cout<<setprecision(6)<<res<<"\n";
        }
        else if(p==3)
        {
            sum=sum-ss.top();
            ss.pop();
            if(mm.count(n)>0)
            {
                it=mm.find(n);

                int kk;
                int nn=it->first;
                nn--;
                sum=sum-it->second;

            if(mm.count(nn)>0)
            mm[nn]=mm[nn]+it->second;
            else
            mm[nn]=it->second;
             mm.erase(n);
            n--;
              double res=(sum*1.000000)/(n*1.000000);
              cout<<setprecision(6)<<res<<"\n";

            }
            else
            {
                n--;
                       double res=(sum*1.000000)/(n*1.000000);
                     cout<<setprecision(6)<<res<<"\n";
            }

        }

    }
 return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef int ll;
typedef long long int li;
const ll MAXN=1e5+51;
const li inf=0x3f3f3f3f3f3f3f3f;
struct Edge{
	ll to,prev,dist;
};
struct Tuple{
	li x,y;
	inline bool operator <(const Tuple &rhs)const
	{
		return this->x>rhs.x;
	}
};
Edge ed[MAXN*20];
priority_queue<Tuple>pq;
ll cnt,nc,tot,rt,rtx,qcnt,source,op,x,y,l,r,dist;
ll last[MAXN<<2],inQueue[MAXN<<2],ls[MAXN<<2],rs[MAXN<<2];
li dis[MAXN<<2];
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
}
inline void addEdge(ll from,ll to,ll dist)
{
	ed[++tot].prev=last[from];
	ed[tot].to=to;
	ed[tot].dist=dist;
	last[from]=tot;
}
inline ll createDown(ll l,ll r)
{
	if(l==r)
	{
		return l;
	}
	ll mid=(l+r)>>1,cur=++nc;
	ls[cur]=createDown(l,mid),rs[cur]=createDown(mid+1,r);
	addEdge(cur,ls[cur],0),addEdge(cur,rs[cur],0);
	return cur;
}
inline ll createUp(ll l,ll r)
{
	if(l==r)
	{
		return l;
	}
	ll mid=(l+r)>>1,cur=++nc;
	ls[cur]=createUp(l,mid),rs[cur]=createUp(mid+1,r);
	addEdge(ls[cur],cur,0),addEdge(rs[cur],cur,0);
	return cur;
}
ll lx,rx;
inline void link(ll l,ll r,ll x,ll dist,ll node,ll type)
{
	if(lx<=l&&rx>=r)
	{
		type?addEdge(node,x,dist):addEdge(x,node,dist);
		return;
	}
	ll mid=(l+r)>>1;
	if(lx<=mid)
	{
		link(l,mid,x,dist,ls[node],type);
	}
	if(rx>mid)
	{
		link(mid+1,r,x,dist,rs[node],type);
	}
}
inline void Dijkstra(ll source)
{
	ll top;
	dis[source]=0,inQueue[source]=1,pq.push((Tuple){0,source});
	while(!pq.empty())
	{
		top=pq.top().y,pq.pop(),inQueue[top]=0;
		for(register int i=last[top];i;i=ed[i].prev)
		{
			if(dis[ed[i].to]>dis[top]+ed[i].dist)
			{
				dis[ed[i].to]=dis[top]+ed[i].dist;
				if(!inQueue[ed[i].to])
				{
					inQueue[ed[i].to]=1;
					pq.push((Tuple){dis[ed[i].to],ed[i].to});
				}
			}
		}
	}
}
int main()
{
	cnt=nc=read(),qcnt=read(),source=read();
	rt=nc+1,createDown(1,cnt),rtx=nc+1,createUp(1,cnt);
	for(register int i=0;i<qcnt;i++)
	{
		op=read();
		if(op==1)
		{
			x=read(),y=read(),dist=read(),addEdge(x,y,dist);
			continue;
		}
		x=read(),lx=read(),rx=read(),dist=read();
		link(1,cnt,x,dist,op^3?rt:rtx,op-2);
	}
	memset(dis,0x3f,sizeof(dis)),Dijkstra(source);
	for(register int i=1;i<=cnt;i++)
	{
		printf("%lld ",dis[i]==inf?-1:dis[i]);
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long long int li;
const ll MAXN=1e5+51;
const li inf=0x3f3f3f3f3f3f3f3f;
struct Edge{
	ll to,prev,dist;
};
struct SegmentTree{
	ll l,r,ls,rs;
};
struct Tuple{
	li x,y;
	inline bool operator <(const Tuple &rhs)const
	{
		return this->x>rhs.x;
	}
};
Edge ed[MAXN*10];
SegmentTree tree[MAXN*5];
priority_queue<Tuple>pq;
ll cnt,nc,tot,rt,rtx,qcnt,source,op,x,y,l,r,dist;
ll last[MAXN*5],inQueue[MAXN*5];
li dis[MAXN*5];
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
}
inline void addEdge(ll from,ll to,ll dist)
{
	ed[++tot].prev=last[from];
	ed[tot].to=to;
	ed[tot].dist=dist;
	last[from]=tot;
}
inline ll createDown(ll l,ll r)
{
	if(l==r)
	{
		return l;
	}
	ll mid=(l+r)>>1,cur=++nc;
	tree[cur].l=l,tree[cur].r=r;
	tree[cur].ls=createDown(l,mid),tree[cur].rs=createDown(mid+1,r);
	addEdge(cur,tree[cur].ls,0),addEdge(cur,tree[cur].rs,0);
	return cur;
}
inline ll createUp(ll l,ll r)
{
	if(l==r)
	{
		return l;
	}
	ll mid=(l+r)>>1,cur=++nc;
	tree[cur].l=l,tree[cur].r=r;
	tree[cur].ls=createUp(l,mid),tree[cur].rs=createUp(mid+1,r);
	addEdge(tree[cur].ls,cur,0),addEdge(tree[cur].rs,cur,0);
	return cur;
}
inline void link(ll l,ll r,ll x,ll dist,ll node,ll type)
{
	if(l<=tree[node].l&&r>=tree[node].r)
	{
		type?addEdge(node,x,dist):addEdge(x,node,dist);
		return;
	}
	ll mid=(tree[node].l+tree[node].r)>>1;
	if(l<=mid)
	{
		link(l,r,x,dist,tree[node].ls,type);
	}
	if(r>mid)
	{
		link(l,r,x,dist,tree[node].rs,type);
	}
}
inline void Dijkstra(ll source)
{
	ll top;
	dis[source]=0,inQueue[source]=1,pq.push((Tuple){0,source});
	while(!pq.empty())
	{
		top=pq.top().y,pq.pop(),inQueue[top]=0;
		for(register int i=last[top];i;i=ed[i].prev)
		{
			if(dis[ed[i].to]>dis[top]+ed[i].dist)
			{
				dis[ed[i].to]=dis[top]+ed[i].dist;
				if(!inQueue[ed[i].to])
				{
					inQueue[ed[i].to]=1;
					pq.push((Tuple){dis[ed[i].to],ed[i].to});
				}
			}
		}
	}
}
int main()
{
	cnt=nc=read(),qcnt=read(),source=read();
	for(register int i=1;i<=nc;i++)
	{
		tree[i].l=tree[i].r=i;
	}
	rt=nc+1,createDown(1,cnt),rtx=nc+1,createUp(1,cnt);
	for(register int i=0;i<qcnt;i++)
	{
		op=read();
		if(op==1)
		{
			x=read(),y=read(),dist=read(),addEdge(x,y,dist);
			continue;
		}
		x=read(),l=read(),r=read(),dist=read();
		link(l,r,x,dist,op^3?rt:rtx,op-2);
	}
	memset(dis,0x3f,sizeof(dis)),Dijkstra(source);
	for(register int i=1;i<=cnt;i++)
	{
		printf("%lld ",dis[i]==inf?-1:dis[i]);
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long long int li;
const ll MAXN=1e5+51;
const li inf=0x3f3f3f3f3f3f3f3f;
struct Edge{
	ll to,prev,dist;
};
struct SegmentTree{
	ll l,r,ls,rs;
};
struct Tuple{
	li x,y;
	inline bool operator <(const Tuple &rhs)const
	{
		return this->x>rhs.x;
	}
};
Edge ed[MAXN*12];
SegmentTree tree[MAXN*5];
priority_queue<Tuple>pq;
ll cnt,nc,tot,rt,rtx,qcnt,source,op,x,y,l,r,dist;
ll last[MAXN*5],inQueue[MAXN*5];
li dis[MAXN*5];
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
}
inline void addEdge(ll from,ll to,ll dist)
{
	ed[++tot].prev=last[from];
	ed[tot].to=to;
	ed[tot].dist=dist;
	last[from]=tot;
}
inline ll createDown(ll l,ll r)
{
	if(l==r)
	{
		return l;
	}
	ll mid=(l+r)>>1,cur=++nc;
	tree[cur].l=l,tree[cur].r=r;
	tree[cur].ls=createDown(l,mid),tree[cur].rs=createDown(mid+1,r);
	addEdge(cur,tree[cur].ls,0),addEdge(cur,tree[cur].rs,0);
	return cur;
}
inline ll createUp(ll l,ll r)
{
	if(l==r)
	{
		return l;
	}
	ll mid=(l+r)>>1,cur=++nc;
	tree[cur].l=l,tree[cur].r=r;
	tree[cur].ls=createUp(l,mid),tree[cur].rs=createUp(mid+1,r);
	addEdge(tree[cur].ls,cur,0),addEdge(tree[cur].rs,cur,0);
	return cur;
}
inline void link(ll l,ll r,ll x,ll dist,ll node,ll type)
{
	if(l<=tree[node].l&&r>=tree[node].r)
	{
		type?addEdge(node,x,dist):addEdge(x,node,dist);
		return;
	}
	ll mid=(tree[node].l+tree[node].r)>>1;
	if(l<=mid)
	{
		link(l,r,x,dist,tree[node].ls,type);
	}
	if(r>mid)
	{
		link(l,r,x,dist,tree[node].rs,type);
	}
}
inline void Dijkstra(ll source)
{
	ll top;
	dis[source]=0,inQueue[source]=1,pq.push((Tuple){0,source});
	while(!pq.empty())
	{
		top=pq.top().y,pq.pop(),inQueue[top]=0;
		for(register int i=last[top];i;i=ed[i].prev)
		{
			if(dis[ed[i].to]>dis[top]+ed[i].dist)
			{
				dis[ed[i].to]=dis[top]+ed[i].dist;
				if(!inQueue[ed[i].to])
				{
					inQueue[ed[i].to]=1;
					pq.push((Tuple){dis[ed[i].to],ed[i].to});
				}
			}
		}
	}
}
int main()
{
	cnt=nc=read(),qcnt=read(),source=read();
	for(register int i=1;i<=nc;i++)
	{
		tree[i].l=tree[i].r=i;
	}
	rt=nc+1,createDown(1,cnt),rtx=nc+1,createUp(1,cnt);
	for(register int i=0;i<qcnt;i++)
	{
		op=read();
		if(op==1)
		{
			x=read(),y=read(),dist=read(),addEdge(x,y,dist);
			continue;
		}
		x=read(),l=read(),r=read(),dist=read();
		link(l,r,x,dist,op^3?rt:rtx,op-2);
	}
	memset(dis,0x3f,sizeof(dis)),Dijkstra(source);
	for(register int i=1;i<=cnt;i++)
	{
		printf("%lld ",dis[i]==inf?-1:dis[i]);
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MAXN=1e5+51,inf=0x3f3f3f3f3f3f3f3f;
struct Edge{
	ll to,prev,dist;
};
struct SegmentTree{
	ll l,r,ls,rs;
};
struct Tuple{
	ll x,y;
	inline bool operator <(const Tuple &rhs)const
	{
		return this->x>rhs.x;
	}
};
Edge ed[MAXN<<3];
SegmentTree tree[MAXN*5];
priority_queue<Tuple>pq;
ll cnt,nc,tot,rt,rtx,qcnt,source,op,x,y,l,r,dist;
ll last[MAXN*5],dis[MAXN*5],inQueue[MAXN*5];
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
}
inline void addEdge(ll from,ll to,ll dist)
{
	ed[++tot].prev=last[from];
	ed[tot].to=to;
	ed[tot].dist=dist;
	last[from]=tot;
}
inline ll createDown(ll l,ll r)
{
	if(l==r)
	{
		return l;
	}
	ll mid=(l+r)>>1,cur=++nc;
	tree[cur].l=l,tree[cur].r=r;
	tree[cur].ls=createDown(l,mid),tree[cur].rs=createDown(mid+1,r);
	addEdge(cur,tree[cur].ls,0),addEdge(cur,tree[cur].rs,0);
	return nc;
}
inline ll createUp(ll l,ll r)
{
	if(l==r)
	{
		return l;
	}
	ll mid=(l+r)>>1,cur=++nc;
	tree[cur].l=l,tree[cur].r=r;
	tree[cur].ls=createUp(l,mid),tree[cur].rs=createUp(mid+1,r);
	addEdge(tree[cur].ls,cur,0),addEdge(tree[cur].rs,cur,0);
	return nc;
}
inline void link(ll l,ll r,ll x,ll dist,ll node,ll type)
{
	if(l<=tree[node].l&&r>=tree[node].r)
	{
		type?addEdge(node,x,dist):addEdge(x,node,dist);
		return;
	}
	ll mid=(tree[node].l+tree[node].r)>>1;
	if(l<=mid)
	{
		link(l,r,x,dist,tree[node].ls,type);
	}
	if(r>mid)
	{
		link(l,r,x,dist,tree[node].rs,type);
	}
}
inline void Dijkstra(ll source)
{
	ll top;
	dis[source]=0,inQueue[source]=1,pq.push((Tuple){0,source});
	while(!pq.empty())
	{
		top=pq.top().y,pq.pop(),inQueue[top]=0;
		for(register int i=last[top];i;i=ed[i].prev)
		{
			if(dis[ed[i].to]>dis[top]+ed[i].dist)
			{
				dis[ed[i].to]=dis[top]+ed[i].dist;
				if(!inQueue[ed[i].to])
				{
					inQueue[ed[i].to]=1;
					pq.push((Tuple){dis[ed[i].to],ed[i].to});
				}
			}
		}
	}
}
int main()
{
	cnt=nc=read(),qcnt=read(),source=read();
	for(register int i=1;i<=nc;i++)
	{
		tree[i].l=tree[i].r=i;
	}
	rt=nc+1,createDown(1,cnt),rtx=nc+1,createUp(1,cnt);
	for(register int i=0;i<qcnt;i++)
	{
		op=read();
		if(op==1)
		{
			x=read(),y=read(),dist=read(),addEdge(x,y,dist);
			continue;
		}
		x=read(),l=read(),r=read(),dist=read();
		link(l,r,x,dist,op^3?rt:rtx,op-2);
	}
	memset(dis,0x3f,sizeof(dis)),Dijkstra(source);
	for(register int i=1;i<=cnt;i++)
	{
		printf("%lld ",dis[i]==inf?-1:dis[i]);
	}
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,inline,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
typedef int ll;
typedef long long int li;
const ll MAXN=1e5+51;
const li inf=0x3f3f3f3f3f3f3f3f;
struct Edge{
	ll to,prev,dist;
};
struct SegmentTree{
	ll l,r,ls,rs;
};
struct Tuple{
	li x,y;
	inline bool operator <(const Tuple &rhs)const
	{
		return this->x>rhs.x;
	}
};
Edge ed[MAXN<<4];
SegmentTree tree[MAXN<<2];
priority_queue<Tuple>pq;
ll cnt,nc,tot,rt,rtx,qcnt,source,op,x,y,l,r,dist;
ll last[MAXN<<2],inQueue[MAXN<<2];
li dis[MAXN<<2];
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
}
inline void addEdge(ll from,ll to,ll dist)
{
	ed[++tot].prev=last[from];
	ed[tot].to=to;
	ed[tot].dist=dist;
	last[from]=tot;
}
inline ll createDown(ll l,ll r)
{
	if(l==r)
	{
		return l;
	}
	ll mid=(l+r)>>1,cur=++nc;
	tree[cur].l=l,tree[cur].r=r;
	tree[cur].ls=createDown(l,mid),tree[cur].rs=createDown(mid+1,r);
	addEdge(cur,tree[cur].ls,0),addEdge(cur,tree[cur].rs,0);
	return cur;
}
inline ll createUp(ll l,ll r)
{
	if(l==r)
	{
		return l;
	}
	ll mid=(l+r)>>1,cur=++nc;
	tree[cur].l=l,tree[cur].r=r;
	tree[cur].ls=createUp(l,mid),tree[cur].rs=createUp(mid+1,r);
	addEdge(tree[cur].ls,cur,0),addEdge(tree[cur].rs,cur,0);
	return cur;
}
inline void link(ll l,ll r,ll x,ll dist,ll node,ll type)
{
	if(l<=tree[node].l&&r>=tree[node].r)
	{
		type?addEdge(node,x,dist):addEdge(x,node,dist);
		return;
	}
	ll mid=(tree[node].l+tree[node].r)>>1;
	if(l<=mid)
	{
		link(l,r,x,dist,tree[node].ls,type);
	}
	if(r>mid)
	{
		link(l,r,x,dist,tree[node].rs,type);
	}
}
inline void Dijkstra(ll source)
{
	ll top;
	dis[source]=0,inQueue[source]=1,pq.push((Tuple){0,source});
	while(!pq.empty())
	{
		top=pq.top().y,pq.pop(),inQueue[top]=0;
		for(register int i=last[top];i;i=ed[i].prev)
		{
			if(dis[ed[i].to]>dis[top]+ed[i].dist)
			{
				dis[ed[i].to]=dis[top]+ed[i].dist;
				if(!inQueue[ed[i].to])
				{
					inQueue[ed[i].to]=1;
					pq.push((Tuple){dis[ed[i].to],ed[i].to});
				}
			}
		}
	}
}
int main()
{
	cnt=nc=read(),qcnt=read(),source=read();
	for(register int i=1;i<=nc;i++)
	{
		tree[i].l=tree[i].r=i;
	}
	rt=nc+1,createDown(1,cnt),rtx=nc+1,createUp(1,cnt);
	for(register int i=0;i<qcnt;i++)
	{
		op=read();
		if(op==1)
		{
			x=read(),y=read(),dist=read(),addEdge(x,y,dist);
			continue;
		}
		x=read(),l=read(),r=read(),dist=read();
		link(l,r,x,dist,op^3?rt:rtx,op-2);
	}
	memset(dis,0x3f,sizeof(dis)),Dijkstra(source);
	for(register int i=1;i<=cnt;i++)
	{
		printf("%lld ",dis[i]==inf?-1:dis[i]);
	}
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef int ll;
typedef long long int li;
const ll MAXN=1e5+51;
const li inf=0x3f3f3f3f3f3f3f3f;
struct Edge{
	ll to,prev,dist;
};
struct SegmentTree{
	ll l,r,ls,rs;
};
struct Tuple{
	li x,y;
	inline bool operator <(const Tuple &rhs)const
	{
		return this->x>rhs.x;
	}
};
Edge ed[MAXN<<4];
SegmentTree tree[MAXN<<2];
priority_queue<Tuple>pq;
ll cnt,nc,tot,rt,rtx,qcnt,source,op,x,y,l,r,dist;
ll last[MAXN<<2],inQueue[MAXN<<2];
li dis[MAXN<<2];
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
}
inline void addEdge(ll from,ll to,ll dist)
{
	ed[++tot].prev=last[from];
	ed[tot].to=to;
	ed[tot].dist=dist;
	last[from]=tot;
}
inline ll createDown(ll l,ll r)
{
	if(l==r)
	{
		return l;
	}
	ll mid=(l+r)>>1,cur=++nc;
	tree[cur].l=l,tree[cur].r=r;
	tree[cur].ls=createDown(l,mid),tree[cur].rs=createDown(mid+1,r);
	addEdge(cur,tree[cur].ls,0),addEdge(cur,tree[cur].rs,0);
	return cur;
}
inline ll createUp(ll l,ll r)
{
	if(l==r)
	{
		return l;
	}
	ll mid=(l+r)>>1,cur=++nc;
	tree[cur].l=l,tree[cur].r=r;
	tree[cur].ls=createUp(l,mid),tree[cur].rs=createUp(mid+1,r);
	addEdge(tree[cur].ls,cur,0),addEdge(tree[cur].rs,cur,0);
	return cur;
}
inline void link(ll l,ll r,ll x,ll dist,ll node,ll type)
{
	if(l<=tree[node].l&&r>=tree[node].r)
	{
		type?addEdge(node,x,dist):addEdge(x,node,dist);
		return;
	}
	ll mid=(tree[node].l+tree[node].r)>>1;
	if(l<=mid)
	{
		link(l,r,x,dist,tree[node].ls,type);
	}
	if(r>mid)
	{
		link(l,r,x,dist,tree[node].rs,type);
	}
}
inline void Dijkstra(ll source)
{
	ll top;
	dis[source]=0,inQueue[source]=1,pq.push((Tuple){0,source});
	while(!pq.empty())
	{
		top=pq.top().y,pq.pop(),inQueue[top]=0;
		for(register int i=last[top];i;i=ed[i].prev)
		{
			if(dis[ed[i].to]>dis[top]+ed[i].dist)
			{
				dis[ed[i].to]=dis[top]+ed[i].dist;
				if(!inQueue[ed[i].to])
				{
					inQueue[ed[i].to]=1;
					pq.push((Tuple){dis[ed[i].to],ed[i].to});
				}
			}
		}
	}
}
int main()
{
	cnt=nc=read(),qcnt=read(),source=read();
	for(register int i=1;i<=nc;i++)
	{
		tree[i].l=tree[i].r=i;
	}
	rt=nc+1,createDown(1,cnt),rtx=nc+1,createUp(1,cnt);
	for(register int i=0;i<qcnt;i++)
	{
		op=read();
		if(op==1)
		{
			x=read(),y=read(),dist=read(),addEdge(x,y,dist);
			continue;
		}
		x=read(),l=read(),r=read(),dist=read();
		link(l,r,x,dist,op^3?rt:rtx,op-2);
	}
	memset(dis,0x3f,sizeof(dis)),Dijkstra(source);
	for(register int i=1;i<=cnt;i++)
	{
		printf("%lld ",dis[i]==inf?-1:dis[i]);
	}
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,inline,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
typedef int ll;
typedef long long int li;
const ll MAXN=1e5+51;
const li inf=0x3f3f3f3f3f3f3f3f;
struct Edge{
	ll to,prev,dist;
};
struct SegmentTree{
	ll l,r,ls,rs;
};
struct Tuple{
	li x,y;
	inline bool operator <(const Tuple &rhs)const
	{
		return this->x>rhs.x;
	}
};
Edge ed[MAXN<<4];
SegmentTree tree[MAXN<<2];
priority_queue<Tuple>pq;
ll cnt,nc,tot,rt,rtx,qcnt,source,op,x,y,l,r,dist;
ll last[MAXN<<2],inQueue[MAXN<<2];
li dis[MAXN<<2];
char buf[262151],*st=buf,*edx=buf;
inline char gc()
{
	return st==edx&&(edx=(st=buf)+fread(buf,1,262144,stdin),edx==st)?0:*st++;
}
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=gc();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=gc();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=gc();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=gc();
    }
    return num*neg;
}
inline void addEdge(ll from,ll to,ll dist)
{
	ed[++tot].prev=last[from];
	ed[tot].to=to;
	ed[tot].dist=dist;
	last[from]=tot;
}
inline ll createDown(ll l,ll r)
{
	if(l==r)
	{
		return l;
	}
	ll mid=(l+r)>>1,cur=++nc;
	tree[cur].l=l,tree[cur].r=r;
	tree[cur].ls=createDown(l,mid),tree[cur].rs=createDown(mid+1,r);
	addEdge(cur,tree[cur].ls,0),addEdge(cur,tree[cur].rs,0);
	return cur;
}
inline ll createUp(ll l,ll r)
{
	if(l==r)
	{
		return l;
	}
	ll mid=(l+r)>>1,cur=++nc;
	tree[cur].l=l,tree[cur].r=r;
	tree[cur].ls=createUp(l,mid),tree[cur].rs=createUp(mid+1,r);
	addEdge(tree[cur].ls,cur,0),addEdge(tree[cur].rs,cur,0);
	return cur;
}
inline void link(ll l,ll r,ll x,ll dist,ll node,ll type)
{
	if(l<=tree[node].l&&r>=tree[node].r)
	{
		type?addEdge(node,x,dist):addEdge(x,node,dist);
		return;
	}
	ll mid=(tree[node].l+tree[node].r)>>1;
	if(l<=mid)
	{
		link(l,r,x,dist,tree[node].ls,type);
	}
	if(r>mid)
	{
		link(l,r,x,dist,tree[node].rs,type);
	}
}
inline void Dijkstra(ll source)
{
	ll top;
	dis[source]=0,inQueue[source]=1,pq.push((Tuple){0,source});
	while(!pq.empty())
	{
		top=pq.top().y,pq.pop(),inQueue[top]=0;
		for(register int i=last[top];i;i=ed[i].prev)
		{
			if(dis[ed[i].to]>dis[top]+ed[i].dist)
			{
				dis[ed[i].to]=dis[top]+ed[i].dist;
				if(!inQueue[ed[i].to])
				{
					inQueue[ed[i].to]=1;
					pq.push((Tuple){dis[ed[i].to],ed[i].to});
				}
			}
		}
	}
}
int main()
{
	cnt=nc=read(),qcnt=read(),source=read();
	for(register int i=1;i<=nc;i++)
	{
		tree[i].l=tree[i].r=i;
	}
	rt=nc+1,createDown(1,cnt),rtx=nc+1,createUp(1,cnt);
	for(register int i=0;i<qcnt;i++)
	{
		op=read();
		if(op==1)
		{
			x=read(),y=read(),dist=read(),addEdge(x,y,dist);
			continue;
		}
		x=read(),l=read(),r=read(),dist=read();
		link(l,r,x,dist,op^3?rt:rtx,op-2);
	}
	memset(dis,0x3f,sizeof(dis)),Dijkstra(source);
	for(register int i=1;i<=cnt;i++)
	{
		printf("%lld ",dis[i]==inf?-1:dis[i]);
	}
}


#include <cstdio>
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstring>
const int maxm=1e6+100;
int cnt,n,q,s;
int head[maxm],net[maxm],to[maxm],cost[maxm];
int ls[maxm<<2],rs[maxm<<2],rt1,rt2,sz;
inline void addedge(int u,int v,int c){to[++cnt]=v,cost[cnt]=c,net[cnt]=head[u],head[u]=cnt;}
void build1(int &o,int l,int r)
{
	if(l>=r)
	{
		o=l;
		return;
	}
	o=++sz;
	int mid=(l+r)>>1;
	build1(ls[o],l,mid),build1(rs[o],mid+1,r);
	addedge(o,ls[o],0),addedge(o,rs[o],0);
}
void build2(int &o,int l,int r)
{
	if(l>=r)
	{
		o=l;
		return;
	}
	o=++sz;
	int mid=(l+r)>>1;
	build2(ls[o],l,mid),build2(rs[o],mid+1,r);
	addedge(ls[o],o,0),addedge(rs[o],o,0);
}
void ask(int o,int l,int r,int ql,int qr,int ind,int w,int f)
{
	if(ql>r||qr<l) return;
	if((ql<=l)&&(r<=qr))
	{
		//printf("P:%d %d %d %d\n",o,ind,l,r);
		f?addedge(o,ind,w):addedge(ind,o,w);
		return;
	}
	int mid=(l+r)>>1;
	ask(ls[o],l,mid,ql,qr,ind,w,f),ask(rs[o],mid+1,r,ql,qr,ind,w,f);
}
struct SPFA{
	int dis[maxm],vis[maxm];
	std::queue <int> dl;
	inline void spfa(int s)
	{
		memset(dis,127,sizeof(dis));
		dl.push(s),vis[s]=1;
		dis[s]=0;
		while(!dl.empty())
		{
			int now=dl.front();
			dl.pop();
		    vis[now]=0;
		    //printf("%d\n",now);
		    for(int i=head[now];i;i=net[i])
		    if(dis[to[i]]>dis[now]+cost[i])
		    {
		    	dis[to[i]]=dis[now]+cost[i];
		    	if(!vis[to[i]]) dl.push(to[i]),vis[to[i]];
		    }
		    //printf("S:%d\n",to[i]);
		}
		for(int i=1;i<=n;i++) printf("%d ",dis[i]==dis[0]?-1:dis[i]);
	}
}S;
int main()
{
	scanf("%d%d%d",&n,&q,&s);
	sz=n;
	build1(rt1,1,n),build2(rt2,1,n);
	//printf("%d %d\n",rt1,rt2);
	for(int i=1;i<=q;i++)
	{
		int opt,l,r,x,y;
		scanf("%d",&opt);
		if(opt==1) scanf("%d%d%d",&l,&r,&x),addedge(l,r,x);
		if(opt==2) scanf("%d%d%d%d",&x,&l,&r,&y),ask(rt1,1,n,l,r,x,y,0);
		if(opt==3) scanf("%d%d%d%d",&x,&l,&r,&y),ask(rt2,1,n,l,r,x,y,1);
	}
	S.spfa(s);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstring>
#define int long long
const int maxm=1e7+100;
int cnt,n,q,s;
int head[maxm],net[maxm],to[maxm],cost[maxm];
int ls[maxm<<2],rs[maxm<<2],rt1,rt2,sz;
inline void addedge(int u,int v,int c){to[++cnt]=v,cost[cnt]=c,net[cnt]=head[u],head[u]=cnt;}
void build1(int &o,int l,int r)
{
	if(l>=r)
	{
		o=l;
		return;
	}
	o=++sz;
	int mid=(l+r)>>1;
	build1(ls[o],l,mid),build1(rs[o],mid+1,r);
	addedge(o,ls[o],0),addedge(o,rs[o],0);
}
void build2(int &o,int l,int r)
{
	if(l>=r)
	{
		o=l;
		return;
	}
	o=++sz;
	int mid=(l+r)>>1;
	build2(ls[o],l,mid),build2(rs[o],mid+1,r);
	addedge(ls[o],o,0),addedge(rs[o],o,0);
}
void ask(int o,int l,int r,int ql,int qr,int ind,int w,int f)
{
	if(ql>r||qr<l) return;
	if((ql<=l)&&(r<=qr))
	{
		//printf("P:%d %d %d %d\n",o,ind,l,r);
		f?addedge(o,ind,w):addedge(ind,o,w);
		return;
	}
	int mid=(l+r)>>1;
	ask(ls[o],l,mid,ql,qr,ind,w,f),ask(rs[o],mid+1,r,ql,qr,ind,w,f);
}
struct SPFA{
	int dis[maxm],vis[maxm];
	std::queue <int> dl;
	inline void spfa(int s)
	{
		for(int i=0;i<=sz;i++) dis[i]=1e18;
		dl.push(s),vis[s]=1;
		dis[s]=0;
		while(!dl.empty())
		{
			int now=dl.front();
			dl.pop();
		    vis[now]=0;
		    //printf("%d\n",now);
		    for(int i=head[now];i;i=net[i])
		    if(dis[to[i]]>dis[now]+cost[i])
		    {
		    	dis[to[i]]=dis[now]+cost[i];
		    	if(!vis[to[i]]) dl.push(to[i]),vis[to[i]];
		    }
		    //printf("S:%d\n",to[i]);
		}
		for(int i=1;i<=n;i++) printf("%I64d ",dis[i]==dis[0]?-1:dis[i]);
	}
}S;
signed main()
{
	scanf("%I64d%I64d%I64d",&n,&q,&s);
	sz=n;
	build1(rt1,1,n),build2(rt2,1,n);
	//printf("%d %d\n",rt1,rt2);
	for(int i=1;i<=q;i++)
	{
		int opt,l,r,x,y;
		scanf("%I64d",&opt);
		if(opt==1) scanf("%I64d%I64d%I64d",&l,&r,&x),addedge(l,r,x);
		if(opt==2) scanf("%I64d%I64d%I64d%I64d",&x,&l,&r,&y),ask(rt1,1,n,l,r,x,y,0);
		if(opt==3) scanf("%I64d%I64d%I64d%I64d",&x,&l,&r,&y),ask(rt2,1,n,l,r,x,y,1);
	}
	S.spfa(s);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstring>
#define int long long
const int maxm=5e6+100;
int cnt,n,q,s;
int head[maxm],net[maxm],to[maxm],cost[maxm];
int ls[maxm],rs[maxm],rt1,rt2,sz;
inline void addedge(int u,int v,int c){to[++cnt]=v,cost[cnt]=c,net[cnt]=head[u],head[u]=cnt;}
void build1(int &o,int l,int r)
{
	if(l>=r)
	{
		o=l;
		return;
	}
	o=++sz;
	int mid=(l+r)>>1;
	build1(ls[o],l,mid),build1(rs[o],mid+1,r);
	addedge(o,ls[o],0),addedge(o,rs[o],0);
}
void build2(int &o,int l,int r)
{
	if(l>=r)
	{
		o=l;
		return;
	}
	o=++sz;
	int mid=(l+r)>>1;
	build2(ls[o],l,mid),build2(rs[o],mid+1,r);
	addedge(ls[o],o,0),addedge(rs[o],o,0);
}
void ask(int o,int l,int r,int ql,int qr,int ind,int w,int f)
{
	if(ql>r||qr<l) return;
	if((ql<=l)&&(r<=qr))
	{
		//printf("P:%d %d %d %d\n",o,ind,l,r);
		f?addedge(o,ind,w):addedge(ind,o,w);
		return;
	}
	int mid=(l+r)>>1;
	ask(ls[o],l,mid,ql,qr,ind,w,f),ask(rs[o],mid+1,r,ql,qr,ind,w,f);
}
struct SPFA{
	int dis[maxm],vis[maxm];
	std::queue <int> dl;
	inline void spfa(int s)
	{
		for(int i=0;i<=sz;i++) dis[i]=1e18;
		dl.push(s),vis[s]=1;
		dis[s]=0;
		while(!dl.empty())
		{
			int now=dl.front();
			dl.pop();
		    vis[now]=0;
		    //printf("%d\n",now);
		    for(int i=head[now];i;i=net[i])
		    if(dis[to[i]]>dis[now]+cost[i])
		    {
		    	dis[to[i]]=dis[now]+cost[i];
		    	if(!vis[to[i]]) dl.push(to[i]),vis[to[i]];
		    }
		    //printf("S:%d\n",to[i]);
		}
		for(int i=1;i<=n;i++) printf("%I64d ",dis[i]==dis[0]?-1:dis[i]);
	}
}S;
signed main()
{
	scanf("%I64d%I64d%I64d",&n,&q,&s);
	sz=n;
	build1(rt1,1,n),build2(rt2,1,n);
	//printf("%d %d\n",rt1,rt2);
	for(int i=1;i<=q;i++)
	{
		int opt,l,r,x,y;
		scanf("%I64d",&opt);
		if(opt==1) scanf("%I64d%I64d%I64d",&l,&r,&x),addedge(l,r,x);
		if(opt==2) scanf("%I64d%I64d%I64d%I64d",&x,&l,&r,&y),ask(rt1,1,n,l,r,x,y,0);
		if(opt==3) scanf("%I64d%I64d%I64d%I64d",&x,&l,&r,&y),ask(rt2,1,n,l,r,x,y,1);
	}
	S.spfa(s);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstring>
#define int long long
const int maxm=1e6+100;
int cnt,n,q,s;
int head[maxm],net[maxm],to[maxm],cost[maxm];
int ls[maxm<<2],rs[maxm<<2],rt1,rt2,sz;
inline void addedge(int u,int v,int c){to[++cnt]=v,cost[cnt]=c,net[cnt]=head[u],head[u]=cnt;}
void build1(int &o,int l,int r)
{
	if(l>=r)
	{
		o=l;
		return;
	}
	o=++sz;
	int mid=(l+r)>>1;
	build1(ls[o],l,mid),build1(rs[o],mid+1,r);
	addedge(o,ls[o],0),addedge(o,rs[o],0);
}
void build2(int &o,int l,int r)
{
	if(l>=r)
	{
		o=l;
		return;
	}
	o=++sz;
	int mid=(l+r)>>1;
	build2(ls[o],l,mid),build2(rs[o],mid+1,r);
	addedge(ls[o],o,0),addedge(rs[o],o,0);
}
void ask(int o,int l,int r,int ql,int qr,int ind,int w,int f)
{
	if(ql>r||qr<l) return;
	if((ql<=l)&&(r<=qr))
	{
		//printf("P:%d %d %d %d\n",o,ind,l,r);
		f?addedge(o,ind,w):addedge(ind,o,w);
		return;
	}
	int mid=(l+r)>>1;
	ask(ls[o],l,mid,ql,qr,ind,w,f),ask(rs[o],mid+1,r,ql,qr,ind,w,f);
}
struct SPFA{
	int dis[maxm],vis[maxm];
	std::queue <int> dl;
	inline void spfa(int s)
	{
		for(int i=0;i<=sz;i++) dis[i]=1e18;
		dl.push(s),vis[s]=1;
		dis[s]=0;
		while(!dl.empty())
		{
			int now=dl.front();
			dl.pop();
		    vis[now]=0;
		    //printf("%d\n",now);
		    for(int i=head[now];i;i=net[i])
		    if(dis[to[i]]>dis[now]+cost[i])
		    {
		    	dis[to[i]]=dis[now]+cost[i];
		    	if(!vis[to[i]]) dl.push(to[i]),vis[to[i]];
		    }
		    //printf("S:%d\n",to[i]);
		}
		for(int i=1;i<=n;i++) printf("%I64d ",dis[i]==dis[0]?-1:dis[i]);
	}
}S;
signed main()
{
	scanf("%I64d%I64d%I64d",&n,&q,&s);
	sz=n;
	build1(rt1,1,n),build2(rt2,1,n);
	//printf("%d %d\n",rt1,rt2);
	for(int i=1;i<=q;i++)
	{
		int opt,l,r,x,y;
		scanf("%I64d",&opt);
		if(opt==1) scanf("%I64d%I64d%I64d",&l,&r,&x),addedge(l,r,x);
		if(opt==2) scanf("%I64d%I64d%I64d%I64d",&x,&l,&r,&y),ask(rt1,1,n,l,r,x,y,0);
		if(opt==3) scanf("%I64d%I64d%I64d%I64d",&x,&l,&r,&y),ask(rt2,1,n,l,r,x,y,1);
	}
	S.spfa(s);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstring>
const int maxm=1e6+100;
int cnt,n,q,s;
int head[maxm],net[maxm],to[maxm],cost[maxm];
int ls[maxm<<2],rs[maxm<<2],rt1,rt2,sz;
inline void addedge(int u,int v,int c){to[++cnt]=v,cost[cnt]=c,net[cnt]=head[u],head[u]=cnt;}
void build1(int &o,int l,int r)
{
	if(l>=r)
	{
		o=l;
		return;
	}
	o=++sz;
	int mid=(l+r)>>1;
	build1(ls[o],l,mid),build1(rs[o],mid+1,r);
	addedge(o,ls[o],0),addedge(o,rs[o],0);
}
void build2(int &o,int l,int r)
{
	if(l>=r)
	{
		o=l;
		return;
	}
	o=++sz;
	int mid=(l+r)>>1;
	build2(ls[o],l,mid),build2(rs[o],mid+1,r);
	addedge(ls[o],o,0),addedge(rs[o],o,0);
}
void ask(int o,int l,int r,int ql,int qr,int ind,int w,int f)
{
	if(ql>r||qr<l) return;
	if((ql<=l)&&(r<=qr))
	{
		//printf("P:%d %d %d %d\n",o,ind,l,r);
		f?addedge(o,ind,w):addedge(ind,o,w);
		return;
	}
	int mid=(l+r)>>1;
	ask(ls[o],l,mid,ql,qr,ind,w,f),ask(rs[o],mid+1,r,ql,qr,ind,w,f);
}
struct SPFA{
	int dis[maxm],vis[maxm];
	std::queue <int> dl;
	inline void spfa(int s)
	{
		memset(dis,127/3,sizeof(dis));
		dl.push(s),vis[s]=1;
		dis[s]=0;
		while(!dl.empty())
		{
			int now=dl.front();
			dl.pop();
		    vis[now]=0;
		    //printf("%d\n",now);
		    for(int i=head[now];i;i=net[i])
		    if(dis[to[i]]>dis[now]+cost[i])
		    {
		    	dis[to[i]]=dis[now]+cost[i];
		    	if(!vis[to[i]]) dl.push(to[i]),vis[to[i]];
		    }
		    //printf("S:%d\n",to[i]);
		}
		for(int i=1;i<=n;i++) printf("%d ",dis[i]==dis[0]?-1:dis[i]);
	}
}S;
int main()
{
	scanf("%d%d%d",&n,&q,&s);
	sz=n;
	build1(rt1,1,n),build2(rt2,1,n);
	//printf("%d %d\n",rt1,rt2);
	for(int i=1;i<=q;i++)
	{
		int opt,l,r,x,y;
		scanf("%d",&opt);
		if(opt==1) scanf("%d%d%d",&l,&r,&x),addedge(l,r,x);
		if(opt==2) scanf("%d%d%d%d",&x,&l,&r,&y),ask(rt1,1,n,l,r,x,y,0);
		if(opt==3) scanf("%d%d%d%d",&x,&l,&r,&y),ask(rt2,1,n,l,r,x,y,1);
	}
	S.spfa(s);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstring>
#define int long long
const int maxm=3e6+100;
int cnt,n,q,s;
int head[maxm],net[maxm],to[maxm],cost[maxm];
int ls[maxm],rs[maxm],rt1,rt2,sz;
inline void addedge(int u,int v,int c){to[++cnt]=v,cost[cnt]=c,net[cnt]=head[u],head[u]=cnt;}
void build1(int &o,int l,int r)
{
	if(l>=r)
	{
		o=l;
		return;
	}
	o=++sz;
	int mid=(l+r)>>1;
	build1(ls[o],l,mid),build1(rs[o],mid+1,r);
	addedge(o,ls[o],0),addedge(o,rs[o],0);
}
void build2(int &o,int l,int r)
{
	if(l>=r)
	{
		o=l;
		return;
	}
	o=++sz;
	int mid=(l+r)>>1;
	build2(ls[o],l,mid),build2(rs[o],mid+1,r);
	addedge(ls[o],o,0),addedge(rs[o],o,0);
}
void ask(int o,int l,int r,int ql,int qr,int ind,int w,int f)
{
	if(ql>r||qr<l) return;
	if((ql<=l)&&(r<=qr))
	{
		//printf("P:%d %d %d %d\n",o,ind,l,r);
		f?addedge(o,ind,w):addedge(ind,o,w);
		return;
	}
	int mid=(l+r)>>1;
	ask(ls[o],l,mid,ql,qr,ind,w,f),ask(rs[o],mid+1,r,ql,qr,ind,w,f);
}
struct SPFA{
	int dis[maxm],vis[maxm];
	std::queue <int> dl;
	inline void spfa(int s)
	{
		for(int i=0;i<=sz;i++) dis[i]=1e18;
		dl.push(s),vis[s]=1;
		dis[s]=0;
		while(!dl.empty())
		{
			int now=dl.front();
			dl.pop();
		    vis[now]=0;
		    //printf("%d\n",now);
		    for(int i=head[now];i;i=net[i])
		    if(dis[to[i]]>dis[now]+cost[i])
		    {
		    	dis[to[i]]=dis[now]+cost[i];
		    	if(!vis[to[i]]) dl.push(to[i]),vis[to[i]];
		    }
		    //printf("S:%d\n",to[i]);
		}
		for(int i=1;i<=n;i++) printf("%I64d ",dis[i]==dis[0]?-1:dis[i]);
	}
}S;
signed main()
{
	scanf("%I64d%I64d%I64d",&n,&q,&s);
	sz=n;
	build1(rt1,1,n),build2(rt2,1,n);
	//printf("%d %d\n",rt1,rt2);
	for(int i=1;i<=q;i++)
	{
		int opt,l,r,x,y;
		scanf("%I64d",&opt);
		if(opt==1) scanf("%I64d%I64d%I64d",&l,&r,&x),addedge(l,r,x);
		if(opt==2) scanf("%I64d%I64d%I64d%I64d",&x,&l,&r,&y),ask(rt1,1,n,l,r,x,y,0);
		if(opt==3) scanf("%I64d%I64d%I64d%I64d",&x,&l,&r,&y),ask(rt2,1,n,l,r,x,y,1);
	}
	S.spfa(s);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstring>
#define int long long
const int maxm=1e7+100;
int cnt,n,q,s;
int head[maxm],net[maxm],to[maxm],cost[maxm];
int ls[maxm],rs[maxm],rt1,rt2,sz;
inline void addedge(int u,int v,int c){to[++cnt]=v,cost[cnt]=c,net[cnt]=head[u],head[u]=cnt;}
void build1(int &o,int l,int r)
{
	if(l>=r)
	{
		o=l;
		return;
	}
	o=++sz;
	int mid=(l+r)>>1;
	build1(ls[o],l,mid),build1(rs[o],mid+1,r);
	addedge(o,ls[o],0),addedge(o,rs[o],0);
}
void build2(int &o,int l,int r)
{
	if(l>=r)
	{
		o=l;
		return;
	}
	o=++sz;
	int mid=(l+r)>>1;
	build2(ls[o],l,mid),build2(rs[o],mid+1,r);
	addedge(ls[o],o,0),addedge(rs[o],o,0);
}
void ask(int o,int l,int r,int ql,int qr,int ind,int w,int f)
{
	if(ql>r||qr<l) return;
	if((ql<=l)&&(r<=qr))
	{
		//printf("P:%d %d %d %d\n",o,ind,l,r);
		f?addedge(o,ind,w):addedge(ind,o,w);
		return;
	}
	int mid=(l+r)>>1;
	ask(ls[o],l,mid,ql,qr,ind,w,f),ask(rs[o],mid+1,r,ql,qr,ind,w,f);
}
struct SPFA{
	int dis[maxm],vis[maxm];
	std::queue <int> dl;
	inline void spfa(int s)
	{
		for(int i=0;i<=sz;i++) dis[i]=1e18;
		dl.push(s),vis[s]=1;
		dis[s]=0;
		while(!dl.empty())
		{
			int now=dl.front();
			dl.pop();
		    vis[now]=0;
		    //printf("%d\n",now);
		    for(int i=head[now];i;i=net[i])
		    if(dis[to[i]]>dis[now]+cost[i])
		    {
		    	dis[to[i]]=dis[now]+cost[i];
		    	if(!vis[to[i]]) dl.push(to[i]),vis[to[i]];
		    }
		    //printf("S:%d\n",to[i]);
		}
		for(int i=1;i<=n;i++) printf("%I64d ",dis[i]==dis[0]?-1:dis[i]);
	}
}S;
signed main()
{
	scanf("%I64d%I64d%I64d",&n,&q,&s);
	sz=n;
	build1(rt1,1,n),build2(rt2,1,n);
	//printf("%d %d\n",rt1,rt2);
	for(int i=1;i<=q;i++)
	{
		int opt,l,r,x,y;
		scanf("%I64d",&opt);
		if(opt==1) scanf("%I64d%I64d%I64d",&l,&r,&x),addedge(l,r,x);
		if(opt==2) scanf("%I64d%I64d%I64d%I64d",&x,&l,&r,&y),ask(rt1,1,n,l,r,x,y,0);
		if(opt==3) scanf("%I64d%I64d%I64d%I64d",&x,&l,&r,&y),ask(rt2,1,n,l,r,x,y,1);
	}
	S.spfa(s);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#define inf 192608170
using namespace std;
int read(){
	int x=0,pos=1;char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') pos=0;
	for(;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return pos?x:-x;
}
int n,m,s,r1,r2;
const int N = 500001;
int ls[N<<1],rs[N<<1],tot;
struct node{
	int v,nex,w;
}edge[N<<1];
int head[N<<1],top;
void add(int u,int v,int w){
	edge[++top].v=v;
	edge[top].nex=head[u];
	edge[top].w=w;
	head[u]=top;
}
void build1(int &now,int l,int r){
	if(l==r){
		now=l;
		return;
	}
	now=++tot;
	int mid=(l+r)>>1;
	build1(ls[now],l,mid);
	build1(rs[now],mid+1,r);
	add(now,ls[now],0);
	add(now,rs[now],0);
}
void build2(int &now,int l,int r){
	if(l==r){
		now=l;
		return;
	}
	now=++tot;
	int mid=(l+r)>>1;
	build2(ls[now],l,mid);
	build2(rs[now],mid+1,r);
	add(ls[now],now,0);
	add(rs[now],now,0);
}
void modify1(int now,int l,int r,int ql,int qr,int u,int w){
	if(ql<=l&&r<=qr){
		add(u,now,w);
		return;
	}
	int mid=(l+r)>>1;
	if(ql<=mid) modify1(ls[now],l,mid,ql,qr,u,w);
	if(mid<qr) modify1(rs[now],mid+1,r,ql,qr,u,w);
}
void modify2(int now,int l,int r,int ql,int qr,int u,int w){
	if(ql<=l&&r<=qr){
		add(now,u,w);
		return;
	}
	int mid=(l+r)>>1;
	if(ql<=mid) modify2(ls[now],l,mid,ql,qr,u,w);
	if(mid<qr) modify2(rs[now],mid+1,r,ql,qr,u,w);
}
int dis[N<<1],vis[N<<1];
struct tp{
	int p,w;
};
struct cmp{
	bool operator()(tp a,tp b){
		return a.w<b.w;
	}
};
long long ans=0;
void dijkstra(int s){
	priority_queue<tp,vector<tp>,cmp>q;
	for(int i=1;i<=tot;i++){
		dis[i]=inf;vis[i]=0;
	}
	dis[s]=0;
	tp f;f.p=s;f.w=0;
	q.push(f);
	while(!q.empty()){
		int now=q.top().p;q.pop();
		if(vis[now]) continue;else vis[now]=1;
		for(int i=head[now];i;i=edge[i].nex){
			int v=edge[i].v;
			if(dis[v]>dis[now]+edge[i].w){
				dis[v]=dis[now]+edge[i].w;
				if(!vis[v]){
					tp nw;nw.p=v,nw.w=dis[v];
					q.push(nw);
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		printf("%d ",dis[i]==inf?-1:dis[i]);
	}
}
int main(){
	n=read(),m=read(),s=read();
	tot=n;
	build1(r1,1,n);
	build2(r2,1,n);
	for(int i=1;i<=m;i++){
		int opt=read();
		if(opt==1){
			int v=read(),u=read(),w=read();
			add(v,u,w);
		}else if(opt==2){
			int v=read(),l=read(),r=read(),w=read();
			modify1(r1,1,n,l,r,v,w);
		}else{
			int v=read(),l=read(),r=read(),w=read();
			modify2(r2,1,n,l,r,v,w);
		}
	}
	dijkstra(s);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#define inf 99264435330203ll
using namespace std;
long long read(){
	long long x=0,pos=1;char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') pos=0;
	for(;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return pos?x:-x;
}
long long n,m,s,r1,r2;
const long long N = 2000001;
long long ls[N<<1],rs[N<<1],tot;
struct node{
	long long v,nex,w;
}edge[N<<1];
long long head[N<<1],top;
void add(long long u,long long v,long long w){
	edge[++top].v=v;
	edge[top].nex=head[u];
	edge[top].w=w;
	head[u]=top;
}
void build1(long long &now,long long l,long long r){
	if(l==r){
		now=l;
		return;
	}
	now=++tot;
	long long mid=(l+r)>>1;
	build1(ls[now],l,mid);
	build1(rs[now],mid+1,r);
	add(now,ls[now],0);
	add(now,rs[now],0);
}
void build2(long long &now,long long l,long long r){
	if(l==r){
		now=l;
		return;
	}
	now=++tot;
	long long mid=(l+r)>>1;
	build2(ls[now],l,mid);
	build2(rs[now],mid+1,r);
	add(ls[now],now,0);
	add(rs[now],now,0);
}
void modify1(long long now,long long l,long long r,long long ql,long long qr,long long u,long long w){
	if(ql<=l&&r<=qr){
		add(u,now,w);
		return;
	}
	long long mid=(l+r)>>1;
	if(ql<=mid) modify1(ls[now],l,mid,ql,qr,u,w);
	if(mid<qr) modify1(rs[now],mid+1,r,ql,qr,u,w);
}
void modify2(long long now,long long l,long long r,long long ql,long long qr,long long u,long long w){
	if(ql<=l&&r<=qr){
		add(now,u,w);
		return;
	}
	long long mid=(l+r)>>1;
	if(ql<=mid) modify2(ls[now],l,mid,ql,qr,u,w);
	if(mid<qr) modify2(rs[now],mid+1,r,ql,qr,u,w);
}
long long dis[N<<1],vis[N<<1];
struct tp{
	long long p,w;
};
struct cmp{
	bool operator()(tp a,tp b){
		return a.w>b.w;
	}
};
long long ans=0;
void dijkstra(long long s){
	priority_queue<tp,vector<tp>,cmp>q;
	for(long long i=1;i<=tot;i++){
		dis[i]=inf;vis[i]=0;
	}
	dis[s]=0;
	tp f;f.p=s;f.w=0;
	q.push(f);
	while(!q.empty()){
        tp nt=q.top();
        q.pop();
        long long now=nt.p;
        if(vis[now]) continue;
        else vis[now]=1;
        for(int i=head[now];i;i=edge[i].nex){
        	long long nex=edge[i].v;
        	if(dis[nex]>dis[now]+edge[i].w){
        		dis[nex]=dis[now]+edge[i].w;
        		if(!vis[nex]){
        			tp to_push;
        			to_push.p=nex;
        			to_push.w=dis[nex];
        			q.push(to_push);
        		}
        	}
        }
    }
	for(long long i=1;i<=n;i++){
		printf("%lld ",dis[i]>=inf?-1:dis[i]);
	}
}
int main(){
	n=read(),m=read(),s=read();
	tot=n;
	build1(r1,1,n);
	build2(r2,1,n);
	for(long long i=1;i<=m;i++){
		long long opt=read();
		if(opt==1){
			long long v=read(),u=read(),w=read();
			add(v,u,w);
		}else if(opt==2){
			long long v=read(),l=read(),r=read(),w=read();
			modify1(r1,1,n,l,r,v,w);
		}else{
			long long v=read(),l=read(),r=read(),w=read();
			modify2(r2,1,n,l,r,v,w);
		}
	}
	dijkstra(s);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#define inf 992644353
using namespace std;
int read(){
	int x=0,pos=1;char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') pos=0;
	for(;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return pos?x:-x;
}
int n,m,s,r1,r2;
const int N = 500001;
int ls[N<<1],rs[N<<1],tot;
struct node{
	int v,nex,w;
}edge[N<<1];
int head[N<<1],top;
void add(int u,int v,int w){
	edge[++top].v=v;
	edge[top].nex=head[u];
	edge[top].w=w;
	head[u]=top;
}
void build1(int &now,int l,int r){
	if(l==r){
		now=l;
		return;
	}
	now=++tot;
	int mid=(l+r)>>1;
	build1(ls[now],l,mid);
	build1(rs[now],mid+1,r);
	add(now,ls[now],0);
	add(now,rs[now],0);
}
void build2(int &now,int l,int r){
	if(l==r){
		now=l;
		return;
	}
	now=++tot;
	int mid=(l+r)>>1;
	build2(ls[now],l,mid);
	build2(rs[now],mid+1,r);
	add(ls[now],now,0);
	add(rs[now],now,0);
}
void modify1(int now,int l,int r,int ql,int qr,int u,int w){
	if(ql<=l&&r<=qr){
		add(u,now,w);
		return;
	}
	int mid=(l+r)>>1;
	if(ql<=mid) modify1(ls[now],l,mid,ql,qr,u,w);
	if(mid<qr) modify1(rs[now],mid+1,r,ql,qr,u,w);
}
void modify2(int now,int l,int r,int ql,int qr,int u,int w){
	if(ql<=l&&r<=qr){
		add(now,u,w);
		return;
	}
	int mid=(l+r)>>1;
	if(ql<=mid) modify2(ls[now],l,mid,ql,qr,u,w);
	if(mid<qr) modify2(rs[now],mid+1,r,ql,qr,u,w);
}
int dis[N<<1],vis[N<<1];
struct tp{
	int p,w;
};
struct cmp{
	bool operator()(tp a,tp b){
		return a.w<b.w;
	}
};
long long ans=0;
void dijkstra(int s){
	priority_queue<tp,vector<tp>,cmp>q;
	for(int i=1;i<=tot;i++){
		dis[i]=inf;vis[i]=0;
	}
	dis[s]=0;
	tp f;f.p=s;f.w=0;
	q.push(f);
	while(!q.empty()){
		int now=q.top().p;q.pop();
		if(vis[now]) continue;else vis[now]=1;
		for(int i=head[now];i;i=edge[i].nex){
			int v=edge[i].v;
			if(dis[v]>dis[now]+edge[i].w){
				dis[v]=dis[now]+edge[i].w;
				if(!vis[v]){
					tp nw;nw.p=v,nw.w=dis[v];
					q.push(nw);
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		printf("%d ",dis[i]==inf?-1:dis[i]);
	}
}
int main(){
	n=read(),m=read(),s=read();
	tot=n;
	build1(r1,1,n);
	build2(r2,1,n);
	for(int i=1;i<=m;i++){
		int opt=read();
		if(opt==1){
			int v=read(),u=read(),w=read();
			add(v,u,w);
		}else if(opt==2){
			int v=read(),l=read(),r=read(),w=read();
			modify1(r1,1,n,l,r,v,w);
		}else{
			int v=read(),l=read(),r=read(),w=read();
			modify2(r2,1,n,l,r,v,w);
		}
	}
	dijkstra(s);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#define inf 99264435330203ll
using namespace std;
long long read(){
	long long x=0,pos=1;char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') pos=0;
	for(;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return pos?x:-x;
}
long long n,m,s,r1,r2;
const long long N = 500001;
long long ls[N<<1],rs[N<<1],tot;
struct node{
	long long v,nex,w;
}edge[N<<1];
long long head[N<<1],top;
void add(long long u,long long v,long long w){
	edge[++top].v=v;
	edge[top].nex=head[u];
	edge[top].w=w;
	head[u]=top;
}
void build1(long long &now,long long l,long long r){
	if(l==r){
		now=l;
		return;
	}
	now=++tot;
	long long mid=(l+r)>>1;
	build1(ls[now],l,mid);
	build1(rs[now],mid+1,r);
	add(now,ls[now],0);
	add(now,rs[now],0);
}
void build2(long long &now,long long l,long long r){
	if(l==r){
		now=l;
		return;
	}
	now=++tot;
	long long mid=(l+r)>>1;
	build2(ls[now],l,mid);
	build2(rs[now],mid+1,r);
	add(ls[now],now,0);
	add(rs[now],now,0);
}
void modify1(long long now,long long l,long long r,long long ql,long long qr,long long u,long long w){
	if(ql<=l&&r<=qr){
		add(u,now,w);
		return;
	}
	long long mid=(l+r)>>1;
	if(ql<=mid) modify1(ls[now],l,mid,ql,qr,u,w);
	if(mid<qr) modify1(rs[now],mid+1,r,ql,qr,u,w);
}
void modify2(long long now,long long l,long long r,long long ql,long long qr,long long u,long long w){
	if(ql<=l&&r<=qr){
		add(now,u,w);
		return;
	}
	long long mid=(l+r)>>1;
	if(ql<=mid) modify2(ls[now],l,mid,ql,qr,u,w);
	if(mid<qr) modify2(rs[now],mid+1,r,ql,qr,u,w);
}
long long dis[N<<1],vis[N<<1];
struct tp{
	long long p,w;
};
struct cmp{
	bool operator()(tp a,tp b){
		return a.w<b.w;
	}
};
long long ans=0;
void dijkstra(long long s){
	priority_queue<tp,vector<tp>,cmp>q;
	for(long long i=1;i<=tot;i++){
		dis[i]=inf;vis[i]=0;
	}
	dis[s]=0;
	tp f;f.p=s;f.w=0;
	q.push(f);
	while(!q.empty()){
		long long now=q.top().p;q.pop();
		if(vis[now]) continue;else vis[now]=1;
		for(long long i=head[now];i;i=edge[i].nex){
			long long v=edge[i].v;
			if(dis[v]>dis[now]+edge[i].w){
				dis[v]=dis[now]+edge[i].w;
				if(!vis[v]){
					tp nw;nw.p=v,nw.w=dis[v];
					q.push(nw);
				}
			}
		}
	}
	for(long long i=1;i<=n;i++){
		printf("%d ",dis[i]==inf?-1:dis[i]);
	}
}
int main(){
	n=read(),m=read(),s=read();
	tot=n;
	build1(r1,1,n);
	build2(r2,1,n);
	for(long long i=1;i<=m;i++){
		long long opt=read();
		if(opt==1){
			long long v=read(),u=read(),w=read();
			add(v,u,w);
		}else if(opt==2){
			long long v=read(),l=read(),r=read(),w=read();
			modify1(r1,1,n,l,r,v,w);
		}else{
			long long v=read(),l=read(),r=read(),w=read();
			modify2(r2,1,n,l,r,v,w);
		}
	}
	dijkstra(s);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#define inf 192608170
using namespace std;
int read(){
	int x=0,pos=1;char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') pos=0;
	for(;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return pos?x:-x;
}
int n,m,s,r1,r2;
const int N = 500001;
int ls[N<<1],rs[N<<1],tot;
struct node{
	int v,nex,w;
}edge[N<<1];
int head[N<<1],top;
void add(int u,int v,int w){
	edge[++top].v=v;
	edge[top].nex=head[u];
	head[u]=top;
}
void build1(int &now,int l,int r){
	if(l==r){
		now=l;
		return;
	}
	now=++tot;
	int mid=(l+r)>>1;
	build1(ls[now],l,mid);
	build1(rs[now],mid+1,r);
	add(now,ls[now],0);
	add(now,rs[now],0);
}
void build2(int &now,int l,int r){
	if(l==r){
		now=l;
		return;
	}
	now=++tot;
	int mid=(l+r)>>1;
	build1(ls[now],l,mid);
	build1(rs[now],mid+1,r);
	add(ls[now],now,0);
	add(rs[now],now,0);
}
void modify1(int now,int l,int r,int ql,int qr,int u,int w){
	if(ql<=l&&r<=qr){
		add(u,now,w);
		return;
	}
	int mid=(l+r)>>1;
	if(ql<=mid) modify1(ls[now],l,mid,ql,qr,u,w);
	if(mid<qr) modify1(rs[now],mid+1,r,ql,qr,u,w);
}
void modify2(int now,int l,int r,int ql,int qr,int u,int w){
	if(ql<=l&&r<=qr){
		add(now,u,w);
		return;
	}
	int mid=(l+r)>>1;
	if(ql<=mid) modify2(ls[now],l,mid,ql,qr,u,w);
	if(mid<qr) modify2(rs[now],mid+1,r,ql,qr,u,w);
}
int dis[N<<1],vis[N<<1];
struct tp{
	int p,w;
};
struct cmp{
	bool operator()(tp a,tp b){
		return a.w<b.w;
	}
};
long long ans=0;
void dijkstra(int s){
	priority_queue<tp,vector<tp>,cmp>q;
	for(int i=1;i<=tot;i++){
		dis[i]=inf;vis[i]=1;
	}
	dis[s]=0;vis[s]=0;
	tp f;f.p=s;f.w=0;
	q.push(f);
	while(!q.empty()){
		int now=q.top().p;q.pop();
		if(vis[now]) continue;else vis[now]=1;
		for(int i=head[now];i;i=edge[i].nex){
			int v=edge[i].v;
			if(dis[v]>dis[now]+edge[i].w){
				dis[v]=dis[now]+edge[i].w;
				if(!vis[v]){
					tp nw;nw.p=v,nw.w=dis[v];
					q.push(nw);
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		printf("%d ",dis[i]);
	}
}
int main(){
	n=read(),m=read(),s=read();
	tot=n;
	build1(r1,1,n);
	build2(r2,1,n);
	for(int i=1;i<=m;i++){
		int opt=read();
		if(opt==1){
			int v=read(),u=read(),w=read();
			add(v,u,w);
		}else if(opt==2){
			int v=read(),l=read(),r=read(),w=read();
			modify1(r1,1,n,l,r,v,w);
		}else{
			int v=read(),l=read(),r=read(),w=read();
			modify2(r2,1,n,l,r,v,w);
		}
	}
	dijkstra(s);
	return 0;
}