#include <stdio.h>
#include <bits/stdc++.h>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 300000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int a[N];
vector<int> pos[N];
const int B = 60;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, q;
    scanf("%d %d", &n, &q);
    rep(i, 0, n)
    {
        scanf("%d", &a[i]);
        a[i]--;
        pos[a[i]].push_back(i);
    }
    while (q--)
    {
        int l, r, k;
        scanf("%d %d %d", &l, &r, &k);
        l--; r--;
        int ans = inf;
        if ((r - l + 1) <= B)
        {
            rep(i, l, r + 1)
            {
                int cnt = upper_bound(pos[a[i]].begin(), pos[a[i]].end(), r) - lower_bound(pos[a[i]].begin(), pos[a[i]].end(), l);
                if (cnt * k > (r - l + 1))
                    ans = min(ans, a[i]);
            }
        }
        else
        {
            rep(x, 0, B)
            {
                int i = rand() % (r - l + 1) + l;
                int cnt = upper_bound(pos[a[i]].begin(), pos[a[i]].end(), r) - lower_bound(pos[a[i]].begin(), pos[a[i]].end(), l);
                if (cnt * k > (r - l + 1))
                    ans = min(ans, a[i]);
            }
        }
        cout << (ans < inf ? ans + 1 : -1) << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

static unsigned int g_seed;

inline void fast_srand(int seed) {
    g_seed = seed;
}

inline int fast_rand(void) {
    g_seed = (214013*g_seed+2531011);
    return (g_seed>>16)&0x7FFF;
}

const int INF = 1e7;
int vis [300010], arr[300010];
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	int SRS = (n+q)&31;
	while (SRS--) fast_rand();

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}

//	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;

		int tr = 50, sz = r-l+1;
		while (tr--) {
			int x = arr[l+fast_rand()%sz];
			if (vis[x] == q+1) continue;
			vis[x] = q+1;
			int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
			if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

static unsigned int g_seed;

inline void fast_srand(int seed) {
    g_seed = seed;
}

inline int fast_rand(void) {
    g_seed = (214013*g_seed+2531011);
    return (g_seed>>16)&0x7FFF;
}

const int INF = 1e7;
int vis [300010], arr[300010];
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	for (int i = 0; i < (n+q)&31; i++) fast_rand();

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}

//	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;

		int tr = 50, sz = r-l+1;
		while (tr--) {
			int x = arr[l+fast_rand()%sz];
			if (vis[x] == q+1) continue;
			vis[x] = q+1;
			int TF = upper_bound(PE[x].begin(),PE[x].end(),r)-PE[x].begin();
			TF -= upper_bound(PE[x].begin(),PE[x].end(),l-1)-PE[x].begin();
			if (TF > mn) res = min(res,x);
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

const int INF = 1e7;
int vis [300010];
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	srand(n+q);
	for (int i = 0; i < (n+q)&31; i++) rand();

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}
	N = n-1;

//	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;
		if (r-l <= 30) {
			vector <int> e (k-1), f (k-1);
			for (int i = l; i <= r; i++) {
				bool h = 0;
				for (int j = 0; j+1 < k; j++) {
					if (e[j] == arr[i]) {
						f[j]++;
						h = 1;
						break;
					}
				}

				if (!h) {
					for (int j = 0; j+1 < k; j++) {
						if (f[j] == 0) {
							f[j] = h = 1;
							e[j] = arr[i];
							break;
						}
					}
				}

				if (!h) {
					for (int j = 0; j+1 < k; j++) f[j]--;
				}
			}
			fill(f.begin(),f.end(),0);
			for (int i = l; i <= r; i++) {
				for (int j = 0; j+1 < k; j++)
					if (e[j] == arr[i]) {
						f[j]++;
						if (f[j] > mn) res = min(res,e[j]);
					}
			}
		}
		else {
			int tr = 50, sz = r-l+1;
			while (tr--) {
				int x = arr[l+rand()%sz];
				if (vis[x] == q+1) continue;
				vis[x] = q+1;
				int TF = upper_bound(PE[x].begin(),PE[x].end(),r)-PE[x].begin();
				TF -= upper_bound(PE[x].begin(),PE[x].end(),l-1)-PE[x].begin();
				if (TF > mn) res = min(res,x);
			}
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

int g_seed;
void fast_srand(int seed) {
    g_seed = seed;
}

int fast_rand(void) {
    g_seed = (214033*g_seed+2531011);
    return (g_seed>>16)&0x7FFF;
}

const int INF = 1e7;
int vis [300010], arr[300010];
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	int SRS = (n+q)&63;
	while (SRS--) fast_rand();

	vector <int> rT (n);
	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
		rT[i] = arr[i];
	}
	sort(rT.begin(),rT.end());
	rT.resize(unique(rT.begin(),rT.end())-rT.begin());

//	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;

		int tr = 71, sz = r-l+1;
		while (tr--) {
			int x = arr[l+fast_rand()%sz];
			if (vis[x] == q+1) continue;
			vis[x] = q+1;
			int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
			if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
		}
		for (int i = 0; i < 14; i++) {
			int x = rT[fast_rand()%sz(rT)];
			if (vis[x] != q+1) {
				vis[x] = q+1;
				int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
				if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
			}
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

const int INF = 1e7;
int vis [300010], arr[300010];
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	srand(n+q);
	for (int i = 0; i < (n+q)&31; i++) rand();

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}

//	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;

		int tr = 50, sz = r-l+1;
		while (tr--) {
			int x = arr[l+rand()%sz];
			if (vis[x] == q+1) continue;
			vis[x] = q+1;
			int TF = upper_bound(PE[x].begin(),PE[x].end(),r)-PE[x].begin();
			TF -= upper_bound(PE[x].begin(),PE[x].end(),l-1)-PE[x].begin();
			if (TF > mn) res = min(res,x);
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

const int INF = 1e7;
int vis [300010], arr[300010];
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	srand(n+q);
	for (int i = 0; i < (n+q)&31; i++) rand();

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}
//	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;
		if (r-l <= 30) {
			vector <int> e (k-1), f (k-1);
			for (int i = l; i <= r; i++) {
				bool h = 0;
				for (int j = 0; j+1 < k; j++) {
					if (e[j] == arr[i]) {
						f[j]++;
						h = 1;
						break;
					}
				}

				if (!h) {
					for (int j = 0; j+1 < k; j++) {
						if (f[j] == 0) {
							f[j] = h = 1;
							e[j] = arr[i];
							break;
						}
					}
				}

				if (!h) {
					for (int j = 0; j+1 < k; j++) f[j]--;
				}
			}
			fill(f.begin(),f.end(),0);
			for (int i = l; i <= r; i++) {
				for (int j = 0; j+1 < k; j++)
					if (e[j] == arr[i]) {
						f[j]++;
						if (f[j] > mn) res = min(res,e[j]);
					}
			}
		}
		else {
			int tr = 50, sz = r-l+1;
			while (tr--) {
				int x = arr[l+rand()%sz];
				if (vis[x] == q+1) continue;
				vis[x] = q+1;
				int TF = upper_bound(PE[x].begin(),PE[x].end(),r)-PE[x].begin();
				TF -= upper_bound(PE[x].begin(),PE[x].end(),l-1)-PE[x].begin();
				if (TF > mn) res = min(res,x);
			}
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

struct elem  {
	int e, f;
	bool operator <(const elem &b) const {
		return make_pair(-f,e) < make_pair(-b.f,b.e);
	}
};

struct info {
	int b,e;
	vector <elem> A;
};

info createNode (int val, int p)
{
	info r;
	r.b = r.e = p;
	r.A.push_back({val,1});
	return r;
}

info join (const info &p1, const info &p2) {
	info r = p1;
	r.b = p1.b, r.e = p2.e;
	for (int j = 0; j < sz(p2.A); j++) {
		bool f = 0;
		for (int i = 0; i < sz(p1.A); i++) {
			if (p2.A[j].e == p1.A[i].e) {
				r.A[i].f += p2.A[j].f;
				f = 1;
				break;
			}
		}
		if (!f) {
			int x = p2.A[j].e;
			int TF = upper_bound(PE[x].begin(),PE[x].end(),p1.e)-PE[x].begin() + p2.A[j].f;
			TF -= upper_bound(PE[x].begin(),PE[x].end(),p1.b-1)-PE[x].begin();
			r.A.push_back({p2.A[j].e,TF});
		}
	}
	sort(r.A.begin(),r.A.end());
	while (sz(r.A) > 4) r.A.pop_back();
	return r;
}

info st[1200010];

int arr [300010];
int N;
void create (int n = 1, int l = 0, int r = N)
{
	if (l == r) st[n] = createNode(arr[l],l);
	else
	{
		int m = (l+r)/2;
		create(2*n,l,m);
		create(2*n+1,m+1,r);
		st[n] = join(st[2*n],st[2*n+1]);
	}
}

info query (int x, int y, int n = 1, int l = 0, int r = N)
{
	if (x <= l && r <= y) return st[n];
	else
	{
		int m = (l+r)/2;
		if (y <= m) return query(x,y,2*n,l,m);
		if (x > m) return query(x,y,2*n+1,m+1,r);
		return join(query(x,y,2*n, l, m),query(x,y,2*n+1,m+1,r));
	}
}

const int INF = 1e7;
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}
	N = n-1;

	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		info g = query(l,r);

		int res = INF, mn = (r-l+1)/k;

		for (int i = 0; i < sz(g.A); i++) {
			if (g.A[i].f <= mn) break;
			res = min(res,g.A[i].e);
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

int g_seed;
void fast_srand(int seed) {
    g_seed = seed;
}

int fast_rand(void) {
    g_seed = (214033*g_seed+2531011);
    return (g_seed>>16)&0x7FFF;
}

const int INF = 1e7;
int vis [300010], arr[300010];
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	int SRS = (n+q)&63;
	while (SRS--) fast_rand();

	vector <int> rT (n);
	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
		rT[i] = arr[i];
	}
	sort(rT.begin(),rT.end());
	rT.resize(unique(rT.begin(),rT.end())-rT.begin());

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;

		int tr = 70, sz = r-l+1;
		if (sz(rT) > 57) {
			while (tr--) {
				int x = arr[l+fast_rand()%sz];
				if (vis[x] == q+1) continue;
				vis[x] = q+1;
				int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
				if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
			}
			for (int i = 0; i < 18; i++) {
				int x = rT[fast_rand()%sz(rT)];
				if (!i) x = rT[0];
				if (vis[x] != q+1) {
					vis[x] = q+1;
					int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
					if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
				}
			}
		}
		else {
			for (int x : rT) {
				if (vis[x] != q+1) {
					vis[x] = q+1;
					int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
					if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
				}
			}
		}

		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

struct elem  {
	int e, f;
	bool operator <(const elem &b) const {
		return make_pair(-f,e) < make_pair(-b.f,b.e);
	}
};

struct info {
	int b,e;
	vector <elem> A;
};

info createNode (int val, int p)
{
	info r;
	r.b = r.e = p;
	r.A.push_back({val,1});
	return r;
}

info join (const info &p1, const info &p2) {
	info r = p1;
	r.b = p1.b, r.e = p2.e;
	for (int j = 0; j < sz(p2.A); j++) {
		bool f = 0;
		for (int i = 0; i < sz(p1.A); i++) {
			if (p2.A[j].e == p1.A[i].e) {
				r.A[i].f += p2.A[j].f;
				f = 1;
				break;
			}
		}
		if (!f) {
			int x = p2.A[j].e;
			int TF = upper_bound(PE[x].begin(),PE[x].end(),p1.e)-PE[x].begin() + p2.A[j].f;
			TF -= upper_bound(PE[x].begin(),PE[x].end(),p1.b-1)-PE[x].begin();
			r.A.push_back({p2.A[j].e,TF});
		}
	}
	sort(r.A.begin(),r.A.end());
	while (sz(r.A) > 4) r.A.pop_back();
	return r;
}

info st[1200010];

int arr [300010];
int N;
void create (int n = 1, int l = 0, int r = N)
{
	if (l == r) st[n] = createNode(arr[l],l);
	else
	{
		int m = (l+r)/2;
		create(2*n,l,m);
		create(2*n+1,m+1,r);
		st[n] = join(st[2*n],st[2*n+1]);
	}
}

info query (int x, int y, int n = 1, int l = 0, int r = N)
{
	if (x <= l && r <= y) return st[n];
	else
	{
		int m = (l+r)/2;
		if (y <= m) return query(x,y,2*n,l,m);
		if (x > m) return query(x,y,2*n+1,m+1,r);
		return join(query(x,y,2*n, l, m),query(x,y,2*n+1,m+1,r));
	}
}

const int INF = 1e7;
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	srand(n+q);
	for (int i = 0; i < (n+q)&31; i++) rand();

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}
	N = n-1;

//	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;

			int tr = 70, sz = r-l+1;
			while (tr--) {
				int x = arr[l+rand()%sz];
				int TF = upper_bound(PE[x].begin(),PE[x].end(),r)-PE[x].begin();
				TF -= upper_bound(PE[x].begin(),PE[x].end(),l-1)-PE[x].begin();
				if (TF > mn) res = min(res,x);
			}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

static unsigned int g_seed;

inline void fast_srand(int seed) {
    g_seed = seed;
}

inline int fast_rand(void) {
    g_seed = (214013*g_seed+2531011);
    return (g_seed>>16)&0x7FFF;
}

const int INF = 1e7;
int vis [300010], arr[300010];
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	int SRS = (n+q)&63;
	while (SRS--) fast_rand();

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}

//	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;

		int tr = 72, sz = r-l+1;
		while (tr--) {
			int x = arr[l+fast_rand()%sz];
			if (vis[x] == q+1) continue;
			vis[x] = q+1;
			int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
			if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
		}
		int x = arr[r];
		if (!vis[x]) {
			int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
			if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

struct elem  {
	int e, f;
	bool operator <(const elem &b) const {
		return make_pair(-f,e) < make_pair(-b.f,b.e);
	}
};

struct info {
	int b,e;/*
	map <int,int> A;
	map <int,int> X;
	*/vector <elem> A;
};

info createNode (int val, int p)
{
	info r;
	r.b = r.e = p;
	r.A.push_back({val,1});
	return r;
}

info join (const info &p1, const info &p2) {
	info r = p1;
	r.b = p1.b, r.e = p2.e;
	for (int j = 0; j < sz(p2.A); j++) {
		bool f = 0;
		for (int i = 0; i < sz(p1.A); i++) {
			if (p2.A[j].e == p1.A[i].e) {
				r.A[i].f += p2.A[j].f;
				f = 1;
				break;
			}
		}
		if (!f) {
			int x = p2.A[j].e;
			int TF = upper_bound(PE[x].begin(),PE[x].end(),p1.e)-PE[x].begin() + p2.A[j].f;
			TF -= upper_bound(PE[x].begin(),PE[x].end(),p1.b-1)-PE[x].begin();
			r.A.push_back({p2.A[j].e,TF});
		}
	}
	sort(r.A.begin(),r.A.end());
	while (sz(r.A) > 4) r.A.pop_back();
	return r;
}

info st[1200010];

int arr [300010];
int N;
void create (int n = 1, int l = 0, int r = N)
{
	if (l == r) st[n] = createNode(arr[l],l);
	else
	{
		int m = (l+r)/2;
		create(2*n,l,m);
		create(2*n+1,m+1,r);
		st[n] = join(st[2*n],st[2*n+1]);
	}
}

info query (int x, int y, int n = 1, int l = 0, int r = N)
{
	if (x <= l && r <= y) return st[n];
	else
	{
		int m = (l+r)/2;
		if (y <= m) return query(x,y,2*n,l,m);
		if (x > m) return query(x,y,2*n+1,m+1,r);
		return join(query(x,y,2*n, l, m),query(x,y,2*n+1,m+1,r));
	}
}

const int INF = 1e7;
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	srand(n+q);
	for (int i = 0; i < (n+q)&31; i++) rand();

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}
	N = n-1;

	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;
		if (r-l <= 100) {
			vector <int> e (k-1), f (k-1);
			for (int i = l; i <= r; i++) {
				bool h = 0;
				for (int j = 0; j+1 < k; j++) {
					if (e[j] == arr[i]) {
						f[j]++;
						h = 1;
						break;
					}
				}

				if (!h) {
					for (int j = 0; j+1 < k; j++) {
						if (f[j] == 0) {
							f[j] = h = 1;
							e[j] = arr[i];
							break;
						}
					}
				}

				if (!h) {
					for (int j = 0; j+1 < k; j++) f[j]--;
				}
			}
			fill(f.begin(),f.end(),0);
			for (int i = l; i <= r; i++) {
				for (int j = 0; j+1 < k; j++)
					if (e[j] == arr[i]) {
						f[j]++;
						if (f[j] > mn) res = min(res,e[j]);
					}
			}
		}
		else if ((q&255) == 0) {
			info g = query(l,r);

			for (int i = 0; i < sz(g.A); i++) {
				if (g.A[i].f <= mn) break;
				res = min(res,g.A[i].e);
			}
		}
		else {
			int tr = 70, sz = r-l+1;
			while (tr--) {
				int x = arr[l+rand()%sz];
				int TF = upper_bound(PE[x].begin(),PE[x].end(),r)-PE[x].begin();
				TF -= upper_bound(PE[x].begin(),PE[x].end(),l-1)-PE[x].begin();
				if (TF > mn) res = min(res,x);
			}
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

int g_seed;
void fast_srand(int seed) {
    g_seed = seed;
}

int fast_rand(void) {
    g_seed = (214033*g_seed+2531011);
    return (g_seed>>16)&0x7FFF;
}

const int INF = 1e7;
int vis [300010], arr[300010];
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	int SRS = (n+q)&63;
	while (SRS--) fast_rand();

	vector <int> rT (n);
	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
		rT[i] = arr[i];
	}
	sort(rT.begin(),rT.end());
	rT.resize(unique(rT.begin(),rT.end())-rT.begin());

//	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;

		int tr = 71, sz = r-l+1;
		if (sz(rT) > 20) {
			while (tr--) {
				int x = arr[l+fast_rand()%sz];
				if (vis[x] == q+1) continue;
				vis[x] = q+1;
				int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
				if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
			}
			for (int i = 0; i < 20; i++) {
				int x = rT[fast_rand()%sz(rT)];
				if (vis[x] != q+1) {
					vis[x] = q+1;
					int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
					if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
				}
			}
		}
		else {
			for (int x : rT) {
				if (vis[x] != q+1) {
					vis[x] = q+1;
					int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
					if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
				}
			}

		}

		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

struct elem  {
	int e, f;
	bool operator <(const elem &b) const {
		return make_pair(-f,e) < make_pair(-b.f,b.e);
	}
};

struct info {
	int b,e;
	vector <elem> A;
};

info createNode (int val, int p)
{
	info r;
	r.b = r.e = p;
	r.A.push_back({val,1});
	return r;
}

info join (const info &p1, const info &p2) {
	info r = p1;
	r.b = p1.b, r.e = p2.e;
	for (int j = 0; j < sz(p2.A); j++) {
		bool f = 0;
		for (int i = 0; i < sz(p1.A); i++) {
			if (p2.A[j].e == p1.A[i].e) {
				r.A[i].f += p2.A[j].f;
				f = 1;
				break;
			}
		}
		if (!f) {
			int x = p2.A[j].e;
			int TF = upper_bound(PE[x].begin(),PE[x].end(),p1.e)-PE[x].begin() + p2.A[j].f;
			TF -= upper_bound(PE[x].begin(),PE[x].end(),p1.b-1)-PE[x].begin();
			r.A.push_back({p2.A[j].e,TF});
		}
	}
	sort(r.A.begin(),r.A.end());
	while (sz(r.A) > 4) r.A.pop_back();
	return r;
}

info st[1200010];

int arr [300010];
int N;
void create (int n = 1, int l = 0, int r = N)
{
	if (l == r) st[n] = createNode(arr[l],l);
	else
	{
		int m = (l+r)/2;
		create(2*n,l,m);
		create(2*n+1,m+1,r);
		st[n] = join(st[2*n],st[2*n+1]);
	}
}

info query (int x, int y, int n = 1, int l = 0, int r = N)
{
	if (x <= l && r <= y) return st[n];
	else
	{
		int m = (l+r)/2;
		if (y <= m) return query(x,y,2*n,l,m);
		if (x > m) return query(x,y,2*n+1,m+1,r);
		return join(query(x,y,2*n, l, m),query(x,y,2*n+1,m+1,r));
	}
}

const int INF = 1e7;
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	srand(n+q);
	for (int i = 0; i < (n+q)&31; i++) rand();

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}
	N = n-1;

//	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;
		if (r-l <= 100) {
			vector <int> e (k-1), f (k-1);
			for (int i = l; i <= r; i++) {
				bool h = 0;
				for (int j = 0; j+1 < k; j++) {
					if (e[j] == arr[i]) {
						f[j]++;
						h = 1;
						break;
					}
				}

				if (!h) {
					for (int j = 0; j+1 < k; j++) {
						if (f[j] == 0) {
							f[j] = h = 1;
							e[j] = arr[i];
							break;
						}
					}
				}

				if (!h) {
					for (int j = 0; j+1 < k; j++) f[j]--;
				}
			}
			fill(f.begin(),f.end(),0);
			for (int i = l; i <= r; i++) {
				for (int j = 0; j+1 < k; j++)
					if (e[j] == arr[i]) {
						f[j]++;
						if (f[j] > mn) res = min(res,e[j]);
					}
			}
		}
		else {
			int tr = 70, sz = r-l+1;
			while (tr--) {
				int x = arr[l+rand()%sz];
				int TF = upper_bound(PE[x].begin(),PE[x].end(),r)-PE[x].begin();
				TF -= upper_bound(PE[x].begin(),PE[x].end(),l-1)-PE[x].begin();
				if (TF > mn) res = min(res,x);
			}
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

struct elem  {
	int e, f;
	bool operator <(const elem &b) const {
		return make_pair(-f,e) < make_pair(-b.f,b.e);
	}
};

struct info {
	int b,e;
	vector <elem> A;
};

info createNode (int val, int p)
{
	info r;
	r.b = r.e = p;
	r.A.push_back({val,1});
	return r;
}

info join (const info &p1, const info &p2) {
	info r = p1;
	r.b = p1.b, r.e = p2.e;
	for (int j = 0; j < sz(p2.A); j++) {
		bool f = 0;
		for (int i = 0; i < sz(p1.A); i++) {
			if (p2.A[j].e == p1.A[i].e) {
				r.A[i].f += p2.A[j].f;
				f = 1;
				break;
			}
		}
		if (!f) {
			int x = p2.A[j].e;
			int TF = upper_bound(PE[x].begin(),PE[x].end(),p1.e)-PE[x].begin() + p2.A[j].f;
			TF -= upper_bound(PE[x].begin(),PE[x].end(),p1.b-1)-PE[x].begin();
			r.A.push_back({p2.A[j].e,TF});
		}
	}
	sort(r.A.begin(),r.A.end());
	while (sz(r.A) > 4) r.A.pop_back();
	return r;
}

info st[1200010];

int arr [300010];
int N;
void create (int n = 1, int l = 0, int r = N)
{
	if (l == r) st[n] = createNode(arr[l],l);
	else
	{
		int m = (l+r)/2;
		create(2*n,l,m);
		create(2*n+1,m+1,r);
		st[n] = join(st[2*n],st[2*n+1]);
	}
}

info query (int x, int y, int n = 1, int l = 0, int r = N)
{
	if (x <= l && r <= y) return st[n];
	else
	{
		int m = (l+r)/2;
		if (y <= m) return query(x,y,2*n,l,m);
		if (x > m) return query(x,y,2*n+1,m+1,r);
		return join(query(x,y,2*n, l, m),query(x,y,2*n+1,m+1,r));
	}
}

const int INF = 1e7;
int vis [300010];
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	srand(n+q);
	for (int i = 0; i < (n+q)&31; i++) rand();

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}
	N = n-1;

//	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;
		if (r-l <= 50) {
			vector <int> e (k-1), f (k-1);
			for (int i = l; i <= r; i++) {
				bool h = 0;
				for (int j = 0; j+1 < k; j++) {
					if (e[j] == arr[i]) {
						f[j]++;
						h = 1;
						break;
					}
				}

				if (!h) {
					for (int j = 0; j+1 < k; j++) {
						if (f[j] == 0) {
							f[j] = h = 1;
							e[j] = arr[i];
							break;
						}
					}
				}

				if (!h) {
					for (int j = 0; j+1 < k; j++) f[j]--;
				}
			}
			fill(f.begin(),f.end(),0);
			for (int i = l; i <= r; i++) {
				for (int j = 0; j+1 < k; j++)
					if (e[j] == arr[i]) {
						f[j]++;
						if (f[j] > mn) res = min(res,e[j]);
					}
			}
		}
		else {
			int tr = 70, sz = r-l+1;
			while (tr--) {
				int x = arr[l+rand()%sz];
				if (vis[x] == q+1) continue;
				vis[x] = q+1;
				int TF = upper_bound(PE[x].begin(),PE[x].end(),r)-PE[x].begin();
				TF -= upper_bound(PE[x].begin(),PE[x].end(),l-1)-PE[x].begin();
				if (TF > mn) res = min(res,x);
			}
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

struct elem  {
	int e, f;
	bool operator <(const elem &b) const {
		return make_pair(-f,e) < make_pair(-b.f,b.e);
	}
};

struct info {
	int b,e;
	vector <elem> A;
};

info createNode (int val, int p)
{
	info r;
	r.b = r.e = p;
	r.A.push_back({val,1});
	return r;
}

info join (const info &p1, const info &p2) {
	info r = p1;
	r.b = p1.b, r.e = p2.e;
	for (int j = 0; j < sz(p2.A); j++) {
		bool f = 0;
		for (int i = 0; i < sz(p1.A); i++) {
			if (p2.A[j].e == p1.A[i].e) {
				r.A[i].f += p2.A[j].f;
				f = 1;
				break;
			}
		}
		if (!f) {
			int x = p2.A[j].e;
			int TF = upper_bound(PE[x].begin(),PE[x].end(),p1.e)-PE[x].begin() + p2.A[j].f;
			TF -= upper_bound(PE[x].begin(),PE[x].end(),p1.b-1)-PE[x].begin();
			r.A.push_back({p2.A[j].e,TF});
		}
	}
	sort(r.A.begin(),r.A.end());
	while (sz(r.A) > 3) r.A.pop_back();
	return r;
}

info st[1200010];

int arr [300010];
int N;
void create (int n = 1, int l = 0, int r = N)
{
	if (l == r) st[n] = createNode(arr[l],l);
	else
	{
		int m = (l+r)/2;
		create(2*n,l,m);
		create(2*n+1,m+1,r);
		st[n] = join(st[2*n],st[2*n+1]);
	}
}

info query (int x, int y, int n = 1, int l = 0, int r = N)
{
	if (x <= l && r <= y) return st[n];
	else
	{
		int m = (l+r)/2;
		if (y <= m) return query(x,y,2*n,l,m);
		if (x > m) return query(x,y,2*n+1,m+1,r);
		return join(query(x,y,2*n, l, m),query(x,y,2*n+1,m+1,r));
	}
}

const int INF = 1e7;
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}
	N = n-1;

	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		info g = query(l,r);

		int res = INF, mn = (r-l+1)/k;

		for (int i = 0; i < sz(g.A); i++) {
			if (g.A[i].f <= mn) break;
			res = min(res,g.A[i].e);
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

int g_seed;

inline void fast_srand(int seed) {
    g_seed = seed;
}

int fast_rand(void) {
    g_seed = (214033*g_seed+2531011);
    return (g_seed>>16)&0x7FFF;
}

const int INF = 1e7;
int vis [300010], arr[300010];
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	int SRS = (n+q)&63;
	while (SRS--) fast_rand();

	vector <int> rT (n);
	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
		rT[i] = arr[i];
	}
	sort(rT.begin(),rT.end());
	rT.resize(unique(rT.begin(),rT.end())-rT.begin());

//	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;

		int tr = 70, sz = r-l+1;
		while (tr--) {
			int x = arr[l+fast_rand()%sz];
			if (vis[x] == q+1) continue;
			vis[x] = q+1;
			int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
			if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
		}
		for (int i = 0; i < 7; i++) {
			int x = rT[fast_rand()%sz(rT)];
			if (vis[x] != q+1) {
				vis[x] = q+1;
				int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
				if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
			}
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

struct elem  {
	int e, f;
	bool operator <(const elem &b) const {
		return make_pair(-f,e) < make_pair(-b.f,b.e);
	}
};

struct info {
	int b,e;
	vector <elem> A;
};

info createNode (int val, int p)
{
	info r;
	r.b = r.e = p;
	r.A.push_back({val,1});
	return r;
}

info join (const info &p1, const info &p2) {
	info r = p1;
	r.b = p1.b, r.e = p2.e;
	for (int j = 0; j < sz(p2.A); j++) {
		bool f = 0;
		for (int i = 0; i < sz(p1.A); i++) {
			if (p2.A[j].e == p1.A[i].e) {
				r.A[i].f += p2.A[j].f;
				f = 1;
				break;
			}
		}
		if (!f) {
			int x = p2.A[j].e;
			int TF = upper_bound(PE[x].begin(),PE[x].end(),p1.e)-PE[x].begin() + p2.A[j].f;
			TF -= upper_bound(PE[x].begin(),PE[x].end(),p1.b-1)-PE[x].begin();
			r.A.push_back({p2.A[j].e,TF});
		}
	}
	sort(r.A.begin(),r.A.end());
	while (sz(r.A) > 5) r.A.pop_back();
	return r;
}

info st[1200010];

int arr [300010];
int N;
void create (int n = 1, int l = 0, int r = N)
{
	if (l == r) st[n] = createNode(arr[l],l);
	else
	{
		int m = (l+r)/2;
		create(2*n,l,m);
		create(2*n+1,m+1,r);
		st[n] = join(st[2*n],st[2*n+1]);
	}
}

info query (int x, int y, int n = 1, int l = 0, int r = N)
{
	if (x <= l && r <= y) return st[n];
	else
	{
		int m = (l+r)/2;
		if (y <= m) return query(x,y,2*n,l,m);
		if (x > m) return query(x,y,2*n+1,m+1,r);
		return join(query(x,y,2*n, l, m),query(x,y,2*n+1,m+1,r));
	}
}

const int INF = 1e7;
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}
	N = n-1;

	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		info g = query(l,r);

		int res = INF, mn = (r-l+1)/k;

		for (int i = 0; i < sz(g.A); i++) {
			if (g.A[i].f <= mn) break;
			res = min(res,g.A[i].e);
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

int g_seed;
void fast_srand(int seed) {
    g_seed = seed;
}

int fast_rand(void) {
    g_seed = (214033*g_seed+2531011);
    return (g_seed>>16)&0x7FFF;
}

const int INF = 1e7;
int vis [300010], arr[300010];
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	int SRS = (n+q)&63;
	while (SRS--) fast_rand();

	vector <int> rT (n);
	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
		rT[i] = arr[i];
	}
	sort(rT.begin(),rT.end());
	rT.resize(unique(rT.begin(),rT.end())-rT.begin());

//	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;

		int tr = 71, sz = r-l+1;
		while (tr--) {
			int x = arr[l+fast_rand()%sz];
			if (vis[x] == q+1) continue;
			vis[x] = q+1;
			int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
			if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
		}
		for (int i = 0; i < 20; i++) {
			int x = rT[fast_rand()%sz(rT)];
			if (vis[x] != q+1) {
				vis[x] = q+1;
				int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
				if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
			}
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

struct elem  {
	int e, f;
	bool operator <(const elem &b) const {
		return make_pair(-f,e) < make_pair(-b.f,b.e);
	}
};

struct info {
	int b,e;/*
	map <int,int> A;
	map <int,int> X;
	*/vector <elem> A;
};

info createNode (int val, int p)
{
	info r;
	r.b = r.e = p;
	r.A.push_back({val,1});
	return r;
}

info join (const info &p1, const info &p2) {
	info r = p1;
	r.b = p1.b, r.e = p2.e;
	for (int j = 0; j < sz(p2.A); j++) {
		bool f = 0;
		for (int i = 0; i < sz(p1.A); i++) {
			if (p2.A[j].e == p1.A[i].e) {
				r.A[i].f += p2.A[j].f;
				f = 1;
				break;
			}
		}
		if (!f) {
			int x = p2.A[j].e;
			int TF = upper_bound(PE[x].begin(),PE[x].end(),p1.e)-PE[x].begin() + p2.A[j].f;
			TF -= upper_bound(PE[x].begin(),PE[x].end(),p1.b-1)-PE[x].begin();
			r.A.push_back({p2.A[j].e,TF});
		}
	}
	sort(r.A.begin(),r.A.end());
	while (sz(r.A) > 4) r.A.pop_back();
	return r;
}

info st[1200010];

int arr [300010];
int N;
void create (int n = 1, int l = 0, int r = N)
{
	if (l == r) st[n] = createNode(arr[l],l);
	else
	{
		int m = (l+r)/2;
		create(2*n,l,m);
		create(2*n+1,m+1,r);
		st[n] = join(st[2*n],st[2*n+1]);
	}
}

info query (int x, int y, int n = 1, int l = 0, int r = N)
{
	if (x <= l && r <= y) return st[n];
	else
	{
		int m = (l+r)/2;
		if (y <= m) return query(x,y,2*n,l,m);
		if (x > m) return query(x,y,2*n+1,m+1,r);
		return join(query(x,y,2*n, l, m),query(x,y,2*n+1,m+1,r));
	}
}

const int INF = 1e7;
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	srand(n+q);
	for (int i = 0; i < (n+q)&31; i++) rand();

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}
	N = n-1;

	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;
		if (r-l <= 100) {
			vector <int> e (k-1), f (k-1);
			for (int i = l; i <= r; i++) {
				bool h = 0;
				for (int j = 0; j+1 < k; j++) {
					if (e[j] == arr[i]) {
						f[j]++;
						h = 1;
						break;
					}
				}

				if (!h) {
					for (int j = 0; j+1 < k; j++) {
						if (f[j] == 0) {
							f[j] = h = 1;
							e[j] = arr[i];
							break;
						}
					}
				}

				if (!h) {
					for (int j = 0; j+1 < k; j++) f[j]--;
				}
			}
			fill(f.begin(),f.end(),0);
			for (int i = l; i <= r; i++) {
				for (int j = 0; j+1 < k; j++)
					if (e[j] == arr[i]) {
						f[j]++;
						if (f[j] > mn) res = min(res,e[j]);
					}
			}
		}
		else if ((q&7) == 0) {
			info g = query(l,r);

			for (int i = 0; i < sz(g.A); i++) {
				if (g.A[i].f <= mn) break;
				res = min(res,g.A[i].e);
			}
		}
		else {
			int tr = 95, sz = r-l+1;
			while (tr--) {
				int x = arr[l+rand()%sz];
				int TF = upper_bound(PE[x].begin(),PE[x].end(),r)-PE[x].begin();
				TF -= upper_bound(PE[x].begin(),PE[x].end(),l-1)-PE[x].begin();
				if (TF > mn) res = min(res,x);
			}
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

static unsigned int g_seed;

inline void fast_srand(int seed) {
    g_seed = seed;
}

inline int fast_rand(void) {
    g_seed = (214013*g_seed+2531011);
    return (g_seed>>16)&0x7FFF;
}

const int INF = 1e7;
int vis [300010], arr[300010];
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	int SRS = (n+q)&31;
	while (SRS--) fast_rand();

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}

//	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;

		int tr = 70, sz = r-l+1;
		while (tr--) {
			int x = arr[l+fast_rand()%sz];
			if (vis[x] == q+1) continue;
			vis[x] = q+1;
			int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
			if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

struct elem  {
	int e, f;
	bool operator <(const elem &b) const {
		return make_pair(-f,e) < make_pair(-b.f,b.e);
	}
};

struct info {
	int b,e;
	vector <elem> A;
};

info createNode (int val, int p)
{
	info r;
	r.b = r.e = p;
	r.A.push_back({val,1});
	return r;
}

info join (const info &p1, const info &p2) {
	info r = p1;
	r.b = p1.b, r.e = p2.e;
	for (int j = 0; j < sz(p2.A); j++) {
		bool f = 0;
		for (int i = 0; i < sz(p1.A); i++) {
			if (p2.A[j].e == p1.A[i].e) {
				r.A[i].f += p2.A[j].f;
				f = 1;
				break;
			}
		}
		if (!f) {
			int x = p2.A[j].e;
			int TF = upper_bound(PE[x].begin(),PE[x].end(),p1.e)-PE[x].begin() + p2.A[j].f;
			TF -= upper_bound(PE[x].begin(),PE[x].end(),p1.b-1)-PE[x].begin();
			r.A.push_back({p2.A[j].e,TF});
		}
	}
	sort(r.A.begin(),r.A.end());
	while (sz(r.A) > 4) r.A.pop_back();
	return r;
}

info st[1200010];

int arr [300010];
int N;
void create (int n = 1, int l = 0, int r = N)
{
	if (l == r) st[n] = createNode(arr[l],l);
	else
	{
		int m = (l+r)/2;
		create(2*n,l,m);
		create(2*n+1,m+1,r);
		st[n] = join(st[2*n],st[2*n+1]);
	}
}

info query (int x, int y, int n = 1, int l = 0, int r = N)
{
	if (x <= l && r <= y) return st[n];
	else
	{
		int m = (l+r)/2;
		if (y <= m) return query(x,y,2*n,l,m);
		if (x > m) return query(x,y,2*n+1,m+1,r);
		return join(query(x,y,2*n, l, m),query(x,y,2*n+1,m+1,r));
	}
}

const int INF = 1e7;
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	srand(n+q);
	for (int i = 0; i < (n+q)&31; i++) rand();

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}
	N = n-1;

	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;
		if (r-l <= 100) {
			vector <int> e (k-1), f (k-1);
			for (int i = l; i <= r; i++) {
				bool h = 0;
				for (int j = 0; j+1 < k; j++) {
					if (e[j] == arr[i]) {
						f[j]++;
						h = 1;
						break;
					}
				}

				if (!h) {
					for (int j = 0; j+1 < k; j++) {
						if (f[j] == 0) {
							f[j] = h = 1;
							e[j] = arr[i];
							break;
						}
					}
				}

				if (!h) {
					for (int j = 0; j+1 < k; j++) f[j]--;
				}
			}
			fill(f.begin(),f.end(),0);
			for (int i = l; i <= r; i++) {
				for (int j = 0; j+1 < k; j++)
					if (e[j] == arr[i]) {
						f[j]++;
						if (f[j] > mn) res = min(res,e[j]);
					}
			}
		}
		else if ((q&1023) == 0) {
			info g = query(l,r);

			for (int i = 0; i < sz(g.A); i++) {
				if (g.A[i].f <= mn) break;
				res = min(res,g.A[i].e);
			}
		}
		else {
			int tr = 70, sz = r-l+1;
			while (tr--) {
				int x = arr[l+rand()%sz];
				int TF = upper_bound(PE[x].begin(),PE[x].end(),r)-PE[x].begin();
				TF -= upper_bound(PE[x].begin(),PE[x].end(),l-1)-PE[x].begin();
				if (TF > mn) res = min(res,x);
			}
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

struct elem  {
	int e, f;
	bool operator <(const elem &b) const {
		return make_pair(-f,e) < make_pair(-b.f,b.e);
	}
};

struct info {
	int b,e;/*
	map <int,int> A;
	map <int,int> X;
	*/vector <elem> A;
};

info createNode (int val, int p)
{
	info r;
	r.b = r.e = p;
	r.A.push_back({val,1});
	return r;
}

info join (const info &p1, const info &p2) {
	info r = p1;
	r.b = p1.b, r.e = p2.e;
	for (int j = 0; j < sz(p2.A); j++) {
		bool f = 0;
		for (int i = 0; i < sz(p1.A); i++) {
			if (p2.A[j].e == p1.A[i].e) {
				r.A[i].f += p2.A[j].f;
				f = 1;
				break;
			}
		}
		if (!f) {
			int x = p2.A[j].e;
			int TF = upper_bound(PE[x].begin(),PE[x].end(),p1.e)-PE[x].begin() + p2.A[j].f;
			TF -= upper_bound(PE[x].begin(),PE[x].end(),p1.b-1)-PE[x].begin();
			r.A.push_back({p2.A[j].e,TF});
		}
	}
	sort(r.A.begin(),r.A.end());
	while (sz(r.A) > 4) r.A.pop_back();
	return r;
}

info st[1200010];

int arr [300010];
int N;
void create (int n = 1, int l = 0, int r = N)
{
	if (l == r) st[n] = createNode(arr[l],l);
	else
	{
		int m = (l+r)/2;
		create(2*n,l,m);
		create(2*n+1,m+1,r);
		st[n] = join(st[2*n],st[2*n+1]);
	}
}

info query (int x, int y, int n = 1, int l = 0, int r = N)
{
	if (x <= l && r <= y) return st[n];
	else
	{
		int m = (l+r)/2;
		if (y <= m) return query(x,y,2*n,l,m);
		if (x > m) return query(x,y,2*n+1,m+1,r);
		return join(query(x,y,2*n, l, m),query(x,y,2*n+1,m+1,r));
	}
}

const int INF = 1e7;
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	srand(n+q);
	for (int i = 0; i < (n+q)&31; i++) rand();

	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
	}
	N = n-1;

	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;
		if (r-l <= 100) {
			vector <int> e (k-1), f (k-1);
			for (int i = l; i <= r; i++) {
				bool h = 0;
				for (int j = 0; j+1 < k; j++) {
					if (e[j] == arr[i]) {
						f[j]++;
						h = 1;
						break;
					}
				}

				if (!h) {
					for (int j = 0; j+1 < k; j++) {
						if (f[j] == 0) {
							f[j] = h = 1;
							e[j] = arr[i];
							break;
						}
					}
				}

				if (!h) {
					for (int j = 0; j+1 < k; j++) f[j]--;
				}
			}
			fill(f.begin(),f.end(),0);
			for (int i = l; i <= r; i++) {
				for (int j = 0; j+1 < k; j++)
					if (e[j] == arr[i]) {
						f[j]++;
						if (f[j] > mn) res = min(res,e[j]);
					}
			}
		}
		else if ((q&127) == 0) {
			info g = query(l,r);

			for (int i = 0; i < sz(g.A); i++) {
				if (g.A[i].f <= mn) break;
				res = min(res,g.A[i].e);
			}
		}
		else {
			int tr = 95, sz = r-l+1;
			while (tr--) {
				int x = arr[l+rand()%sz];
				int TF = upper_bound(PE[x].begin(),PE[x].end(),r)-PE[x].begin();
				TF -= upper_bound(PE[x].begin(),PE[x].end(),l-1)-PE[x].begin();
				if (TF > mn) res = min(res,x);
			}
		}
		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

int g_seed;
void fast_srand(int seed) {
    g_seed = seed;
}

int fast_rand(void) {
    g_seed = (214033*g_seed+2531011);
    return (g_seed>>16)&0x7FFF;
}

const int INF = 1e7;
int vis [300010], arr[300010];
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	int SRS = (n+q)&63;
	while (SRS--) fast_rand();

	vector <int> rT (n);
	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
		rT[i] = arr[i];
	}
	sort(rT.begin(),rT.end());
	rT.resize(unique(rT.begin(),rT.end())-rT.begin());

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;

		int tr = 70, sz = r-l+1;
		if (sz(rT) > 57) {
			while (tr--) {
				int x = arr[l+fast_rand()%sz];
				if (vis[x] == q+1) continue;
				vis[x] = q+1;
				int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
				if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
			}
			for (int i = 0; i < 20; i++) {
				int x = rT[fast_rand()%sz(rT)];
				if (!i) x = rT[0];
				if (vis[x] != q+1) {
					vis[x] = q+1;
					int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
					if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
				}
			}
		}
		else {
			for (int x : rT) {
				if (vis[x] != q+1) {
					vis[x] = q+1;
					int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
					if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
				}
			}
		}

		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <bits/stdc++.h>

using namespace std;

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

vector <int> PE [300010];

int g_seed;
void fast_srand(int seed) {
    g_seed = seed;
}

int fast_rand(void) {
    g_seed = (214033*g_seed+2531011);
    return (g_seed>>16)&0x7FFF;
}

const int INF = 1e7;
int vis [300010], arr[300010];
int main() {
	int n, q;
	scanf("%d%d",&n,&q);

	int SRS = (n+q)&63;
	while (SRS--) fast_rand();

	vector <int> rT (n);
	for (int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
		PE[arr[i]].push_back(i);
		rT[i] = arr[i];
	}
	sort(rT.begin(),rT.end());
	rT.resize(unique(rT.begin(),rT.end())-rT.begin());

//	create();

	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		l--,r--;
		int res = INF, mn = (r-l+1)/k;

		int tr = 71, sz = r-l+1;
		if (sz(rT) > 57) {
			while (tr--) {
				int x = arr[l+fast_rand()%sz];
				if (vis[x] == q+1) continue;
				vis[x] = q+1;
				int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
				if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
			}
			for (int i = 0; i < 20; i++) {
				int x = rT[fast_rand()%sz(rT)];
				if (!i) x = rT[0];
				if (vis[x] != q+1) {
					vis[x] = q+1;
					int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
					if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
				}
			}
		}
		else {
			for (int x : rT) {
				if (vis[x] != q+1) {
					vis[x] = q+1;
					int p = lower_bound(PE[x].begin(), PE[x].end(),l)-PE[x].begin();
					if (p+mn < sz(PE[x]) && PE[x][p+mn] <= r) res = min(res,x);
				}
			}
		}

		printf("%d\n",(res == INF ? -1 : res));
	}

}


#include <cstdio>
#include <algorithm>
#include <vector>
#define par pair<int,int>
#define f first
#define s second

using namespace std;

const int MAXN = 3e5+5;
const int K = 5;

struct node {
	par cand[K];
	int sz = 0;
	node() {}
	void update() {
		if (sz < K) return;
		int mn = cand[0].s;
		for (int i = 1; i < sz; ++i) mn = min(mn, cand[i].s);
		for (int i = 0; i < sz; ++i) {
			cand[i].s -= mn;
			if (cand[i].s == 0) {
				swap(cand[i], cand[sz-1]);
				sz--;
				i--;
			}
		}
	}
};

int n, q, k, x, l, r;
int a[MAXN];
vector <int> pos[MAXN];

int offset;
node tree[2*MAXN];

bool cmp_sort(const par &A, const par &B) {
	if (A.s != B.s) return A.s > B.s;
	return A.f < B.f;
}

node merge(const node &A, const node &B) {
	node r = A;
	for (int i = 0; i < B.sz; ++i) {
		bool found = 0;
		for (int j = 0; j < r.sz; ++j) {
			if (r.cand[j].f == B.cand[i].f) {
				r.cand[j].s += B.cand[i].s;
				found = 1;
				break;
			}
		}
		if (found == 0) {
			r.cand[r.sz++] = B.cand[i];
			r.update();
		}
	}
	return r;
}

void build_tree(int a[]) {
	for (int i = offset; i < offset+n; ++i) {
		tree[i].cand[tree[i].sz++] = par(a[i-offset], 1);
	}
	for (int i = offset-1; i > 0; --i) {
		tree[i] = merge(tree[2*i], tree[2*i+1]);
	}
}

node query(int pos, int lo, int hi, const int &qlo, const int &qhi) {
	if (lo >= qhi || hi <= qlo) return node();
	if (qlo <= lo && hi <= qhi) return tree[pos];
	int mid = (lo+hi)/2;
	return merge(query(2*pos, lo, mid, qlo, qhi),
							 query(2*pos+1, mid, hi, qlo, qhi));
}

int find_less(int x, int p) {
	int lo = 0, hi = (int)pos[x].size()-1;
	while (lo < hi) {
		int mid = (lo+hi+1)/2;
		if (pos[x][mid]	< p) {
			lo = mid;
		} else {
			hi = mid-1;
		}
	}
	return lo;
}

bool check(int x, int l, int r, int k) {
	return r-l < k*(find_less(x, r)-find_less(x, l));
}

int main() {
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; ++i) {
		pos[i].push_back(-1);
	}
	for (int i = 0; i < n; ++i) {
		scanf("%d", a+i);
		pos[a[i]].push_back(i);
	}

	for (offset = 1; offset < n; offset *= 2);
	build_tree(a);

	for (int i = 0; i < q; ++i) {
		scanf("%d%d%d", &l, &r, &k); l--;
		node t = query(1, 0, offset, l, r);
		int ans = 1e9;
		for (par i: t.cand) {
			if (check(i.f, l, r, k)) ans = min(ans, i.f);
		}
		printf("%d\n", ans == 1e9 ? -1 : ans);
	}

	return 0;
}


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

const int MAXN = 200009;

typedef long long lli;

lli BIT[MAXN];

void upd(int id, lli xi) {
	while (id < MAXN) {
		BIT[id] += xi;
		id += (id & (-id));
	}
}

lli sum(int id) {
	lli res = 0;
	while(id) {
		res += BIT[id];
		id -= (id & (-id));
	}
	return res;
}

lli rang(int i, int j) {
	return sum(j) - sum(i - 1);
}

lli stck[MAXN];
int stckid;

int main() {
	cin.tie(0);	ios_base::sync_with_stdio(0);
	int N;

	cin >> N;
	lli many = 2;
	lli sumt = 0;
	for (int i = 0; i < N; ++i) {
		int opt;
		lli xi, ai;
		cin >> opt;
		if (opt == 1) {
			cin >> ai >> xi;
			upd(1, xi);
			upd(ai + 1, -xi);
			sumt += (ai * xi);
		} else if (opt == 2) {
			cin >> xi;
			stck[stckid++] = xi;
			sumt += xi;
			many++;
		} else {
			sumt -= (stck[stckid - 1] + sum(many - 1));
			stckid--;
			many--;
		}

		long double suma = sumt;
		long double mny = many - 1;
		cout << fixed << setprecision(10) << (suma / mny) << '\n';
	}

	return 0;
}


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

const int MAXN = 200009;

typedef int lli;

lli BIT[MAXN];

void upd(int id, lli xi) {
	while (id < MAXN) {
		BIT[id] += xi;
		id += (id & (-id));
	}
}

lli sum(int id) {
	lli res = 0;
	while(id) {
		res += BIT[id];
		id -= (id & (-id));
	}
	return res;
}

lli rang(int i, int j) {
	return sum(j) - sum(i - 1);
}

lli stck[MAXN];
int stckid;

int main() {
	// cin.tie(0);	ios_base::sync_with_stdio(0);
	int N;

	// cin >> N;
	scanf("%d", &N);
	lli many = 2;
	lli sumt = 0;
	for (int i = 0; i < N; ++i) {
		int opt;
		lli xi, ai;
		// cin >> opt;
		scanf("%d", &opt);
		if (opt == 1) {
			// cin >> ai >> xi;
			scanf("%d%d", &ai, &xi);
			upd(1, xi);
			upd(ai + 1, -xi);
			sumt += (ai * xi);
		} else if (opt == 2) {
			// cin >> xi;
			scanf("%d", &xi);
			stck[stckid++] = xi;
			sumt += xi;
			many++;
		} else {
			sumt -= (stck[stckid - 1] + sum(many - 1));
			stckid--;
			many--;
		}

		long double suma = sumt;
		long double mny = many - 1;
		long double res = (suma / mny);
		double tp = res;
		printf("%.12lf\n", tp);
		// cout << fixed << setprecision(12) << (suma / mny) << '\n';
	}

	return 0;
}


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

typedef pair<int, int> pii;

const int MAXN = 200009;

int ST[MAXN * 3], Lazy[MAXN * 3], tam;

void Set(int id, int val, int n = 1, int l = 1, int r = MAXN - 1) {
	if ((l > id) || (r < id)) return;
	int ls = (n << 1), rs = ls + 1, m = (l + r) / 2;
	if (Lazy[n] && (l != r)) {
		if (l <= tam) {
			ST[ls] += Lazy[n] * (min(tam, m) - l + 1);
			Lazy[ls] += Lazy[n];
		}
		if ((m + 1) <= tam) {
			ST[rs] += Lazy[n] * (min(tam, r) - (m + 1) + 1);
			Lazy[rs] += Lazy[n];
		}
		Lazy[n] = 0;
	}
	if (l == r) {
		ST[n] = val;
		return;
	}
	Set(id, val, ls, l, m);
	Set(id, val, rs, m + 1, r);
	ST[n] = ST[ls] + ST[rs];
}

int Query(int L, int R, int n = 1, int l = 1, int r = MAXN - 1) {
	if ((l > R) || (r < L)) return 0;
	int ls = (n << 1), rs = ls + 1, m = (l + r) / 2;
	if (Lazy[n] && (l != r)) {
		if (l <= tam) {
			ST[ls] += Lazy[n] * (min(tam, m) - l + 1);
			Lazy[ls] += Lazy[n];
		}
		if ((m + 1) <= tam) {
			ST[rs] += Lazy[n] * (min(tam, r) - (m + 1) + 1);
			Lazy[rs] += Lazy[n];
		}
		Lazy[n] = 0;
	}
	if ((L <= l) && (r <= R)) return ST[n];
	return Query(L, R, ls, l, m) + Query(L, R, rs, m + 1, r);
}

void Update(int L, int R, int val, int n = 1, int l = 1, int r = MAXN - 1) {
	if ((l > R) || (r < L)) return;
	int ls = (n << 1), rs = ls + 1, m = (l + r) / 2;
	if (Lazy[n] && (l != r)) {
		if (l <= tam) {
			ST[ls] += Lazy[n] * (min(tam, m) - l + 1);
			Lazy[ls] += Lazy[n];
		}
		if ((m + 1) <= tam) {
			ST[rs] += Lazy[n] * (min(tam, r) - (m + 1) + 1);
			Lazy[rs] += Lazy[n];
		}
		Lazy[n] = 0;
	}
	if ((L <= l) && (r <= R)) {
		ST[n] += (min(tam, r) - l + 1) * val;
		Lazy[n] += val;
		return;
	}

	Update(L, R, val, ls, l, m);
	Update(L, R, val, rs, m + 1, r);
	ST[n] = ST[ls] + ST[rs];
}

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	cout << fixed << setprecision(6);

	int N;
	tam = 1;
	cin >> N;

	for (int i = 0; i < N; ++i) {
		int tp, xi, ai;
		cin >> tp;

		if (tp == 1) {
			cin >> ai >> xi;
			Update(1, ai, xi);
		} else if (tp == 2) {
			cin >> xi;
			tam++;
			Set(tam, xi);
		} else {
			Set(tam, 0);
			tam--;
		}
		cout << (((double)ST[1]) / ((double)tam)) << '\n';

	}

	return 0;
}


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

const int MAXN = 200009;

typedef int lli;

lli BIT[MAXN];

void upd(int id, lli xi) {
	while (id < MAXN) {
		BIT[id] += xi;
		id += (id & (-id));
	}
}

lli sum(int id) {
	lli res = 0;
	while(id) {
		res += BIT[id];
		id -= (id & (-id));
	}
	return res;
}

lli rang(int i, int j) {
	return sum(j) - sum(i - 1);
}

lli stck[MAXN];
int stckid;

int main() {
	// cin.tie(0);	ios_base::sync_with_stdio(0);
	int N;

	// cin >> N;
	scanf("%d", &N);
	lli many = 2;
	lli sumt = 0;
	for (int i = 0; i < N; ++i) {
		int opt;
		lli xi, ai;
		// cin >> opt;
		scanf("%d", &opt);
		if (opt == 1) {
			// cin >> ai >> xi;
			scanf("%d%d", &ai, &xi);
			upd(1, xi);
			upd(ai + 1, -xi);
			sumt += (ai * xi);
		} else if (opt == 2) {
			// cin >> xi;
			scanf("%d", &xi);
			stck[stckid++] = xi;
			sumt += xi;
			many++;
		} else {
			sumt -= (stck[stckid - 1] + sum(many - 1));
			stckid--;
			many--;
		}

		long double suma = sumt;
		long double mny = many - 1;
		long double res = (double(sumt) / double(many -1));
		double tp = res * 1000000000.0;
		printf("%.12lf\n",(tp / 1000000000.0));
		// cout << fixed << setprecision(12) << (suma / mny) << '\n';
	}

	return 0;
}


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

typedef pair<int, int> pii;

const int MAXN = 200009;

pii ST[MAXN * 3];
int Lazy[MAXN * 3];

void Set(int id, int val, int sta, int n = 1, int l = 1, int r = MAXN - 1) {
	if ((l > id) || (r < id)) return;
	int ls = (n << 1), rs = ls + 1, m = (l + r) / 2;
	if (Lazy[n] && (l != r)) {
		ST[ls].first += ST[ls].second * Lazy[n];
		Lazy[ls] += Lazy[n];
		ST[rs].first += ST[rs].second * Lazy[n];
		Lazy[rs] += Lazy[n];
		Lazy[n] = 0;
	}
	if (l == r) {
		ST[n].first = val;
		ST[n].second = sta;
		return;
	}
	Set(id, val, sta, ls, l, m);
	Set(id, val, sta, rs, m + 1, r);
	ST[n].first = ST[ls].first + ST[rs].first;
	ST[n].second = ST[ls].second + ST[rs].second;
}

void Update(int L, int R, int val, int n = 1, int l = 1, int r = MAXN - 1) {
	if ((l > R) || (r < L)) return;
	int ls = (n << 1), rs = ls + 1, m = (l + r) / 2;
	if (Lazy[n] && (l != r)) {
		ST[ls].first += ST[ls].second * Lazy[n];
		Lazy[ls] += Lazy[n];
		ST[rs].first += ST[rs].second * Lazy[n];
		Lazy[rs] += Lazy[n];
		Lazy[n] = 0;
	}
	if ((L <= l) && (r <= R)) {
		ST[n].first += ST[n].second * val;
		Lazy[n] += val;
		return;
	}
	Update(L, R, val, ls, l, m);
	Update(L, R, val, rs, m + 1, r);
	ST[n].first = ST[ls].first + ST[rs].first;
	ST[n].second = ST[ls].second + ST[rs].second;
}

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	cout << fixed << setprecision(6);

	int N, tam = 1;
	Set(1, 0, 1);

	cin >> N;

	for (int i = 0; i < N; ++i) {
		int tp, xi, ai;
		cin >> tp;

		if (tp == 1) {
			cin >> ai >> xi;
			Update(1, ai, xi);
		} else if (tp == 2) {
			cin >> xi;
			tam++;
			Set(tam, xi, 1);
		} else {
			Set(tam, 0, 0);
			tam--;
		}
		pii ans = ST[1];
		cout << (((double)ans.first) / ((double)ans.second)) << '\n';

	}

	return 0;
}


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

typedef long long lli;

const int MAXN = 200002;

lli ST[MAXN * 3], Lazy[MAXN * 3];
int tam;

void Set(int id, lli val, int n = 1, int l = 1, int r = MAXN - 1) {
	if ((l > id) || (r < id)) return;
	int ls = (n << 1), rs = ls + 1, m = (l + r) / 2;
	if (Lazy[n] && (l != r)) {
		if (l <= tam) {
			ST[ls] += Lazy[n] * ((lli)(min(tam, m) - l + 1));
			Lazy[ls] += Lazy[n];
		}
		if ((m + 1) <= tam) {
			ST[rs] += Lazy[n] * ((lli)(min(tam, r) - (m + 1) + 1));
			Lazy[rs] += Lazy[n];
		}
		Lazy[n] = 0;
	}
	if (l == r) {
		ST[n] = val;
		return;
	}
	Set(id, val, ls, l, m);
	Set(id, val, rs, m + 1, r);
	ST[n] = ST[ls] + ST[rs];
}

lli Query(int L, int R, int n = 1, int l = 1, int r = MAXN - 1) {
	if ((l > R) || (r < L)) return 0;
	int ls = (n << 1), rs = ls + 1, m = (l + r) / 2;
	if (Lazy[n] && (l != r)) {
		if (l <= tam) {
			ST[ls] += Lazy[n] * ((lli)(min(tam, m) - l + 1));
			Lazy[ls] += Lazy[n];
		}
		if ((m + 1) <= tam) {
			ST[rs] += Lazy[n] * ((lli)(min(tam, r) - (m + 1) + 1));
			Lazy[rs] += Lazy[n];
		}
		Lazy[n] = 0;
	}
	if ((L <= l) && (r <= R)) return ST[n];
	return Query(L, R, ls, l, m) + Query(L, R, rs, m + 1, r);
}

void Update(int L, int R, lli val, int n = 1, int l = 1, int r = MAXN - 1) {
	if ((l > R) || (r < L)) return;
	int ls = (n << 1), rs = ls + 1, m = (l + r) / 2;
	if (Lazy[n] && (l != r)) {
		if (l <= tam) {
			ST[ls] += Lazy[n] * ((lli)(min(tam, m) - l + 1));
			Lazy[ls] += Lazy[n];
		}
		if ((m + 1) <= tam) {
			ST[rs] += Lazy[n] * ((lli)(min(tam, r) - (m + 1) + 1));
			Lazy[rs] += Lazy[n];
		}
		Lazy[n] = 0;
	}
	if ((L <= l) && (r <= R)) {
		ST[n] += ((lli)(min(tam, r) - l + 1)) * val;
		Lazy[n] += val;
		return;
	}

	Update(L, R, val, ls, l, m);
	Update(L, R, val, rs, m + 1, r);
	ST[n] = ST[ls] + ST[rs];
}

int main() {
	//cin.tie(0); ios_base::sync_with_stdio(0);
	//cout << fixed << setprecision(6);

	int N;
	tam = 1;
	//cin >> N;
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		int tp, ai;
		lli xi;
		//cin >> tp;
		scanf("%d", &tp);
		if (tp == 1) {
			scanf("%lld%lld", &ai, &xi);
			//cin >> ai >> xi;
			Update(1, ai, xi);
		} else if (tp == 2) {
			//cin >> xi;
			scanf("%lld", &xi);
			tam++;
			Set(tam, xi);
		} else {
			Set(tam, 0);
			tam--;
		}
		printf("%.6lf\n", (((double)ST[1]) / ((double)tam)));
		//cout << (((double)ST[1]) / ((double)tam)) << '\n';

	}

	return 0;
}


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

const int MAXN = 200009;

typedef int lli;

lli BIT[MAXN];

void upd(int id, lli xi) {
	while (id < MAXN) {
		BIT[id] += xi;
		id += (id & (-id));
	}
}

lli sum(int id) {
	lli res = 0;
	while(id) {
		res += BIT[id];
		id -= (id & (-id));
	}
	return res;
}

lli rang(int i, int j) {
	return sum(j) - sum(i - 1);
}

lli stck[MAXN];
int stckid;

int main() {
	// cin.tie(0);	ios_base::sync_with_stdio(0);
	int N;

	// cin >> N;
	scanf("%d", &N);
	lli many = 2;
	lli sumt = 0;
	for (int i = 0; i < N; ++i) {
		int opt;
		lli xi, ai;
		// cin >> opt;
		scanf("%d", &opt);
		if (opt == 1) {
			// cin >> ai >> xi;
			scanf("%d%d", &ai, &xi);
			upd(1, xi);
			upd(ai + 1, -xi);
			sumt += (ai * xi);
		} else if (opt == 2) {
			// cin >> xi;
			scanf("%d", &xi);
			stck[stckid++] = xi;
			sumt += xi;
			many++;
		} else {
			sumt -= (stck[stckid - 1] + sum(many - 1));
			stckid--;
			many--;
		}

		long long int suma = sumt;
		long long tmn = many - 1;
		double mny = (tmn * 10000000000LL);
		double res = (suma * 10000000000LL);
		printf("%.7lf\n",(res / mny));
		// cout << fixed << setprecision(12) << (suma / mny) << '\n';
	}

	return 0;
}


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

const int MAXN = 200009;

typedef int lli;

lli BIT[MAXN];

void upd(int id, lli xi) {
	while (id < MAXN) {
		BIT[id] += xi;
		id += (id & (-id));
	}
}

lli sum(int id) {
	lli res = 0;
	while(id) {
		res += BIT[id];
		id -= (id & (-id));
	}
	return res;
}

lli rang(int i, int j) {
	return sum(j) - sum(i - 1);
}

lli stck[MAXN];
int stckid;

int main() {
	cin.tie(0);	ios_base::sync_with_stdio(0);
	int N;

	cin >> N;
	lli many = 2;
	lli sumt = 0;
	for (int i = 0; i < N; ++i) {
		int opt;
		lli xi, ai;
		cin >> opt;
		if (opt == 1) {
			cin >> ai >> xi;
			upd(1, xi);
			upd(ai + 1, -xi);
			sumt += (ai * xi);
		} else if (opt == 2) {
			cin >> xi;
			stck[stckid++] = xi;
			sumt += xi;
			many++;
		} else {
			sumt -= (stck[stckid - 1] + sum(many - 1));
			stckid--;
			many--;
		}

		double suma = sumt;
		double mny = many - 1;
		cout << fixed << setprecision(12) << (suma / mny) << '\n';
	}

	return 0;
}


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

const int MAXN = 200009;

typedef int lli;

lli BIT[MAXN];

void upd(int id, lli xi) {
	while (id < MAXN) {
		BIT[id] += xi;
		id += (id & (-id));
	}
}

lli sum(int id) {
	lli res = 0;
	while(id) {
		res += BIT[id];
		id -= (id & (-id));
	}
	return res;
}

lli rang(int i, int j) {
	return sum(j) - sum(i - 1);
}

lli stck[MAXN];
int stckid;

int main() {
	// cin.tie(0);	ios_base::sync_with_stdio(0);
	int N;

	// cin >> N;
	scanf("%d", &N);
	lli many = 2;
	lli sumt = 0;
	for (int i = 0; i < N; ++i) {
		int opt;
		lli xi, ai;
		// cin >> opt;
		scanf("%d", &opt);
		if (opt == 1) {
			// cin >> ai >> xi;
			scanf("%d%d", &ai, &xi);
			upd(1, xi);
			upd(ai + 1, -xi);
			sumt += (ai * xi);
		} else if (opt == 2) {
			// cin >> xi;
			scanf("%d", &xi);
			stck[stckid++] = xi;
			sumt += xi;
			many++;
		} else {
			sumt -= (stck[stckid - 1] + sum(many - 1));
			stckid--;
			many--;
		}

		double suma = sumt;
		double mny = many - 1;
		printf("%.12lf\n", (suma / mny));
		// cout << fixed << setprecision(12) << (suma / mny) << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define N 1000009
#define ld double
using namespace std;
ld v[200009];
int szz=1;
ld ad[200009],sum,sz=1;
int main()
{
    fast order
    int n;
    cin>>n;
    ld k,a;
    int las;
    for(int i=0;i<n;i++)
    {
        int q;
        cin>>q;
        if(q==1)
        {
            cin>>las>>a;
            sum+=las*a;
            las--;
            ad[las]+=a;
        }
        else if(q==2)
        {
            cin>>k;
            sum+=k;
            v[szz]=k;
            szz++;
            sz++;
        }
        else
        {
            sum-=v[szz-1];
            sz--;
            sum-=ad[szz-1];
            ad[szz-2]+=ad[szz-1];
            ad[szz-1]=0;
            szz--;
        }
        cout<<fixed<<setprecision(7)<<sum/sz;
        cout<<"\n";
    }
}


#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define N 1000009
#define ld long double
using namespace std;
vector<ld>v;
ld ad[200009],sum,sz=1;
int main()
{
    fast order
    v.push_back(0);
    int n;
    cin>>n;
    ld k,a;
    int las;
    for(int i=0;i<n;i++)
    {
        int q;
        cin>>q;
        if(q==1)
        {
            cin>>las>>a;
            sum+=las*a;
            las--;
            ad[las]+=a;
        }
        else if(q==2)
        {
            cin>>k;
            sum+=k;
            v.push_back(k);
            sz++;
        }
        else
        {
            sum-=v.back();
            sz--;
            sum-=ad[v.size()-1];
            ad[v.size()-1]=0;
            ad[v.size()-2]+=ad[v.size()-1];
            v.pop_back();
        }
        cout<<fixed<<setprecision(7)<<sum/sz;
        cout<<"\n";
    }
}


#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define N 1000009
#define ld long double
using namespace std;
ld v[200009];
int szz=1;
ld ad[200009],sum,sz=1;
int main()
{
    int n;
    cin>>n;
    ll las,a,k;
    for(int i=0;i<n;i++)
    {
        int q;
        cin>>q;
        int x;
        if(q==1)
        {
            cin>>las>>a;
            sum+=las*a;
            las--;
            ad[las]+=a;
        }
        else if(q==2)
        {

           cin>>k;
            sum+=k;
            v[szz]=k;
            szz++;
        }
        else
        {
            sum-=v[szz-1];
            sum-=ad[szz-1];
            ad[szz-2]+=ad[szz-1];
            ad[szz-1]=0;
            szz--;
        }
        cout<<setprecision(6)<<fixed<<(ld)((ld)sum/(ld)szz)<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define N 1000009
#define ld long double
using namespace std;
vector<ld>v;
ld ad[200009],sum,sz=1;
int main()
{
    fast order
    v.push_back(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int q;
        cin>>q;
        if(q==1)
        {
            int las;
            ld a;
            cin>>las>>a;
            sum+=las*a;
            las--;
            ad[las]+=a;
        }
        else if(q==2)
        {
            ld k;
            cin>>k;
            sum+=k;
            v.push_back(k);
            sz++;
        }
        else
        {
            sum-=v.back();
            sz--;
            sum-=ad[v.size()-1];
            ad[v.size()-1]=0;
            ad[v.size()-2]+=ad[v.size()-1];
            v.pop_back();
        }
        cout<<fixed<<setprecision(7)<<sum/sz;
        cout<<"\n";
    }
}


#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define N 1000009
#define ld long double
using namespace std;
ld v[200009];
int szz=1;
ld ad[200009],sum,sz=1;
int main()
{
    int n;
    scanf("%d",&n);
    ld k,a;
    int las;
    for(int i=0;i<n;i++)
    {
        int q;
        scanf("%d",&q);
        int x;
        if(q==1)
        {
            scanf("%d",&las);
            scanf("%d",&x);
            a=x;
            sum+=las*a;
            las--;
            ad[las]+=a;
        }
        else if(q==2)
        {

            scanf("%d",&x);
            k=x;
            sum+=k;
            v[szz]=k;
            szz++;
            sz++;
        }
        else
        {
            sum-=v[szz-1];
            sz--;
            sum-=ad[szz-1];
            ad[szz-2]+=ad[szz-1];
            ad[szz-1]=0;
            szz--;
        }
        ld o=sum/sz;
         printf("%.9lf\n",o);
    }
}


#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define N 1000009
#define ld long double
using namespace std;
ld v[200009];
int szz=1;
ld ad[200009],sum,sz=1;
int main()
{
    int n;
    cin>>n;
    ll las,a,k;
    while(n--)
    {
        int q;
        cin>>q;
        int x;
        if(q==1)
        {
            cin>>las>>a;
            sum+=las*a;
            las--;
            ad[las]+=a;
        }
        else if(q==2)
        {

           cin>>k;
            sum+=k;
            v[szz]=k;
            szz++;
        }
        else
        {
            sum-=v[szz-1];
            sum-=ad[szz-1];
            ad[szz-2]+=ad[szz-1];
            ad[szz-1]=0;
            szz--;
        }
        cout<<setprecision(6)<<fixed<<(ld)((ld)sum/(ld)szz)<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define N 1000009
#define ld double
using namespace std;
ld v[200009];
int szz=1;
ld ad[200009],sum,sz=1;
int main()
{
    int n;
    scanf("%d",&n);
    ld k,a;
    int las;
    for(int i=0;i<n;i++)
    {
        int q;
        scanf("%d",&q);
        int x;
        if(q==1)
        {
            scanf("%d",&las);
            scanf("%lf",&a);
            sum+=las*a;
            las--;
            ad[las]+=a;
        }
        else if(q==2)
        {

            scanf("%lf",&k);
            sum+=k;
            v[szz]=k;
            szz++;
            sz++;
        }
        else
        {
            sum-=v[szz-1];
            sz--;
            sum-=ad[szz-1];
            ad[szz-2]+=ad[szz-1];
            ad[szz-1]=0;
            szz--;
        }
        ld o=sum/sz;
         printf("%.9f\n",o);
    }
}


#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define N 1000009
#define ld long double
using namespace std;
ll v[200009];
ll szz=1;
ll ad[200009],sum,sz=1;
int main()
{
    int n;
    cin>>n;
    ll las,a,k;
    while(n--)
    {
        int q;
        cin>>q;
        int x;
        if(q==1)
        {
            cin>>las>>a;
            sum+=las*a;
            las--;
            ad[las]+=a;
        }
        else if(q==2)
        {

           cin>>k;
            sum+=k;
            v[szz]=k;
            szz++;
        }
        else
        {
            sum-=v[szz-1];
            sum-=ad[szz-1];
            ad[szz-2]+=ad[szz-1];
            ad[szz-1]=0;
            szz--;
        }
        cout<<setprecision(6)<<fixed<<(ld)((ld)sum/(ld)szz)<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define N 1000009
#define ld long double
using namespace std;
ld v[200009];
int szz=1;
ld ad[200009],sum,sz=1;
int main()
{
    int n;
    scanf("%d",&n);
    ld k,a;
    int las;
    for(int i=0;i<n;i++)
    {
        int q;
        scanf("%d",&q);
        int x;
        if(q==1)
        {
            scanf("%d",&las);
            scanf("%d",&x);
            a=double(x);
            sum+=las*a;
            las--;
            ad[las]+=a;
        }
        else if(q==2)
        {

            scanf("%d",&x);
            k=double(x);
            sum+=k;
            v[szz]=k;
            szz++;
            sz++;
        }
        else
        {
            sum-=v[szz-1];
            sz--;
            sum-=ad[szz-1];
            ad[szz-2]+=ad[szz-1];
            ad[szz-1]=0;
            szz--;
        }
        ld o=sum/sz;
         printf("%.9lf\n",o);
    }
}


#include <bits/stdc++.h>
#define ll int
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define N 1000009
#define ld long double
using namespace std;
ll v[200009];
ll szz=1;
ll ad[200009],sum,sz=1;
int main()
{
    int n;
    cin>>n;
    ll las,a,k;
    while(n--)
    {
        int q;
        cin>>q;
        if(q==1)
        {
            cin>>las>>a;
            sum+=las*a;
            las--;
            ad[las]+=a;
        }
        else if(q==2)
        {

           cin>>k;
            sum+=k;
            v[szz]=k;
            szz++;
        }
        else
        {
            sum-=v[szz-1];
            sum-=ad[szz-1];
            ad[szz-2]+=ad[szz-1];
            ad[szz-1]=0;
            szz--;
        }
        cout<<setprecision(6)<<fixed<<(ld)((ld)sum/(ld)szz)<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define N 1000009
#define ld long double
using namespace std;
ld v[200009];
int szz=1;
ld ad[200009],sum,sz=1;
int main()
{
    fast order
    int n;
    cin>>n;
    ld k,a;
    int las;
    for(int i=0;i<n;i++)
    {
        int q;
        cin>>q;
        if(q==1)
        {
            cin>>las>>a;
            sum+=las*a;
            las--;
            ad[las]+=a;
        }
        else if(q==2)
        {
            cin>>k;
            sum+=k;
            v[szz]=k;
            szz++;
            sz++;
        }
        else
        {
            sum-=v[szz-1];
            sz--;
            sum-=ad[szz-1];
            ad[szz-2]+=ad[szz-1];
            ad[szz-1]=0;
            szz--;
        }
        cout<<fixed<<setprecision(7)<<sum/sz;
        cout<<"\n";
    }
}


#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define N 1000009
#define ld double
using namespace std;
ld v[200009];
int szz=1;
ld ad[200009],sum,sz=1;
int main()
{
    int n;
    cin>>n;
    ld k,a;
    int las;
    for(int i=0;i<n;i++)
    {
        int q;
        cin>>q;
        if(q==1)
        {
            cin>>las>>a;
            sum+=las*a;
            las--;
            ad[las]+=a;
        }
        else if(q==2)
        {
            cin>>k;
            sum+=k;
            v[szz]=k;
            szz++;
            sz++;
        }
        else
        {
            sum-=v[szz-1];
            sz--;
            sum-=ad[szz-1];
            ad[szz-2]+=ad[szz-1];
            ad[szz-1]=0;
            szz--;
        }
        cout<<fixed<<setprecision(7)<<sum/sz;
        cout<<"\n";
    }
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unistd.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int, int >pii;
typedef vector < int >vi;
typedef vector < pii > vpii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;
typedef vector < pll > vpll;

#ifndef ONLINE_JUDGE
FILE *__redirect__ = freopen("in", "r", stdin);
#  include <bits/stdc++.h>
#else
#  include <bits/stdc++.h>
#endif

#define lsb(x) (x&-x)
#define del(x) if(x) delete x

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

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

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

#define all(x) (x.begin(),x.end())
#define rall(x) (x.rbegin(),x.rend())

#define pb push_back
#define eb pb
//emplace_back
#define mp make_pair

int INF = 1e9;
int const N = 2e5 + 16;
int const M = 1e9 + 7;

template < class t > void sc(t & x) {
  x = 0;
  int c = 0, z = 0, sign = 1;
  while (!isdigit(c = getchar()))
    z = c;
  if (z == '-')
    sign = -1;
  x = c - '0';
  while (isdigit(c = getchar()))
    x = (x << 1) + (x << 3) + c - '0';
  x *= sign;
}

template < class t > void put(t x) {
  static char buf[32] = { };
  if (x == 0) {
    putchar('0');
    return;
  }
  int i = 32;
  if (x < 0)
    putchar('-'), x = -x;
  do
    buf[--i] = x % 10 + '0';
  while (x /= 10);
  while (i < 32)
    putchar(buf[i++]);
}

int n;
int a[N];
int b[N];

int main() {
  scanf("%d",&n);
  int len = 1;
  ll sum = 0;
  while(n--) {
    int t; sc(t);
    if(t == 1) {
      int x, y; sc(x), sc(y);
      b[x] += y;
      sum += x*y;
    } else if(t == 2) {
      int x; sc(x);
      a[++len] = x;
      sum += x;
    } else {
      b[len-1] += b[len];
      sum -= a[len] + b[len];
      // zero after yourself :D
      a[len] = b[len] = 0;
      --len;
    }

    printf("%.10f\n", sum/double(len));
  }
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unistd.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int, int >pii;
typedef vector < int >vi;
typedef vector < pii > vpii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;
typedef vector < pll > vpll;

#ifndef ONLINE_JUDGE
FILE *__redirect__ = freopen("in", "r", stdin);
#  include <bits/stdc++.h>
#else
#  include <bits/stdc++.h>
#endif

#define lsb(x) (x&-x)
#define del(x) if(x) delete x

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

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

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

#define all(x) (x.begin(),x.end())
#define rall(x) (x.rbegin(),x.rend())

#define pb push_back
#define eb pb
//emplace_back
#define mp make_pair

int INF = 1e9;
int const N = 1e6 + 16;
int const M = 1e9 + 7;

template < class t > void sc(t & x) {
  x = 0;
  int c = 0, z = 0, sign = 1;
  while (!isdigit(c = getchar()))
    z = c;
  if (z == '-')
    sign = -1;
  x = c - '0';
  while (isdigit(c = getchar()))
    x = (x << 1) + (x << 3) + c - '0';
  x *= sign;
}

template < class t > void put(t x) {
  static char buf[32] = { };
  if (x == 0) {
    putchar('0');
    return;
  }
  int i = 32;
  if (x < 0)
    putchar('-'), x = -x;
  do
    buf[--i] = x % 10 + '0';
  while (x /= 10);
  while (i < 32)
    putchar(buf[i++]);
}

int n;
ll a[N];
ll b[N];

int main() {
  scanf("%d",&n);
  int len = 1;
  ll sum = 0;
  while(n--) {
    int t; scanf("%d",&t);
    if(t == 1) {
      ll x, y; scanf("%lld%lld",&x,&y);
      b[x] += y;
      sum += x*y;
    } else if(t == 2) {
      ll x; scanf("%lld",&x);
      a[++len] = x;
      sum += x;
    } else {
      b[len-1] += b[len];
      sum -= a[len] + b[len];
      a[len] = b[len] = 0;
      --len;
    }

    printf("%.10f\n", sum/double(len));
  }
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unistd.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int, int >pii;
typedef vector < int >vi;
typedef vector < pii > vpii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;
typedef vector < pll > vpll;

#ifndef ONLINE_JUDGE
FILE *__redirect__ = freopen("in", "r", stdin);
#  include <bits/stdc++.h>
#else
#  include <bits/stdc++.h>
#endif

#define lsb(x) (x&-x)
#define del(x) if(x) delete x

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

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

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

#define all(x) (x.begin(),x.end())
#define rall(x) (x.rbegin(),x.rend())

#define pb push_back
#define eb pb
//emplace_back
#define mp make_pair

int INF = 1e9;
int const N = 2e5 + 16;
int const M = 1e9 + 7;

template < class t > void sc(t & x) {
  x = 0;
  int c = 0, z = 0, sign = 1;
  while (!isdigit(c = getchar()))
    z = c;
  if (z == '-')
    sign = -1;
  x = c - '0';
  while (isdigit(c = getchar()))
    x = (x << 1) + (x << 3) + c - '0';
  x *= sign;
}

template < class t > void put(t x) {
  static char buf[32] = { };
  if (x == 0) {
    putchar('0');
    return;
  }
  int i = 32;
  if (x < 0)
    putchar('-'), x = -x;
  do
    buf[--i] = x % 10 + '0';
  while (x /= 10);
  while (i < 32)
    putchar(buf[i++]);
}

int n;
int a[N];
int b[N];

int main() {
  sc(n);
  int len = 1;
  int sum = 0;
  while(n--) {
    int t; sc(t);
    if(t == 1) {
      int x, y; sc(x), sc(y);
      b[x] += y;
      sum += x*y;
    } else if(t == 2) {
      int x; sc(x);
      a[++len] = x;
      sum += x;
    } else {
      b[len-1] += b[len];
      sum -= a[len] + b[len];
      // zero after yourself :D
      a[len] = b[len] = 0;
      --len;
    }

    printf("%.6f\n", sum/double(len));
  }
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unistd.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int, int >pii;
typedef vector < int >vi;
typedef vector < pii > vpii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;
typedef vector < pll > vpll;

#ifndef ONLINE_JUDGE
FILE *__redirect__ = freopen("in", "r", stdin);
#  include <bits/stdc++.h>
#else
#  include <bits/stdc++.h>
#endif

#define lsb(x) (x&-x)
#define del(x) if(x) delete x

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

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

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

#define all(x) (x.begin(),x.end())
#define rall(x) (x.rbegin(),x.rend())

#define pb push_back
#define eb pb
//emplace_back
#define mp make_pair

int INF = 1e9;
int const N = 2e5 + 16;
int const M = 1e9 + 7;

template < class t > void sc(t & x) {
  x = 0;
  int c = 0, z = 0, sign = 1;
  while (!isdigit(c = getchar()))
    z = c;
  if (z == '-')
    sign = -1;
  x = c - '0';
  while (isdigit(c = getchar()))
    x = (x << 1) + (x << 3) + c - '0';
  x *= sign;
}

template < class t > void put(t x) {
  static char buf[32] = { };
  if (x == 0) {
    putchar('0');
    return;
  }
  int i = 32;
  if (x < 0)
    putchar('-'), x = -x;
  do
    buf[--i] = x % 10 + '0';
  while (x /= 10);
  while (i < 32)
    putchar(buf[i++]);
}

int n;
int logn;
ll tree[N+N];
ll z[N+N];
int cnt[N+N];

void build() {
  logn = 18;
  rep(i,0,N)
    cnt[i+N] = 1;
  revn(i,N-1,0)
    cnt[i] = cnt[i<<1]+cnt[i<<1|1];
}

void apply(int i, ll v) {
  tree[i] += v;
  if(i < n)
    z[i] += v;
}

void up(int i) {
  while(i>>=1)
    tree[i] = tree[i<<1]+tree[i<<1|1]+cnt[i]*z[i];
}

void push(int i) {
  for(int p = logn; p; --p) {
    int x = i >> p;
    if(z[x]) {
      apply(x<<1,z[x]);
      apply(x<<1|1,z[x]);
      z[x] = 0;
    }
  }
}

void update(int l, int r, ll v) {
  push(l += N);
  push(r += N);
  int lx = l, rx = r;
  ll sum = 0;
  for(;l <= r; l >>= 1, r >>= 1) {
    if(l&1)
      apply(l++, v);
    if((r&1)==0)
      apply(r--, v);
  }
  up(lx);
  up(rx);
}

ll query(int l, int r) {
  push(l += N);
  push(r += N);
  ll sum = 0;
  for(;l <= r; l >>= 1, r >>= 1) {
    if(l&1)
      sum += tree[l++];
    if((r&1)==0)
      sum += tree[r--];
  }
  return sum;
}

int main() {
  scanf("%d",&n);
  int len = 1;
  ll sum = 0;
  while(n--) {
    int t; scanf("%d",&t);
    if(t == 1) {
      int x, y; scanf("%d%d",&x,&y);
      update(1,x,y);
    } else if(t == 2) {
      int x; scanf("%d",&x);
      ++len;
      update(len,len,x);
    } else {
      update(len,len,-query(len,len));
      --len;
    }

    printf("%.10f\n", (double)query(0,len)/len);
  }
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unistd.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int, int >pii;
typedef vector < int >vi;
typedef vector < pii > vpii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;
typedef vector < pll > vpll;

#ifndef ONLINE_JUDGE
FILE *__redirect__ = freopen("in", "r", stdin);
#  include <bits/stdc++.h>
#else
#  include <bits/stdc++.h>
#endif

#define lsb(x) (x&-x)
#define del(x) if(x) delete x

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

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

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

#define all(x) (x.begin(),x.end())
#define rall(x) (x.rbegin(),x.rend())

#define pb push_back
#define eb pb
//emplace_back
#define mp make_pair

int INF = 1e9;
int const N = 2e5 + 16;
int const M = 1e9 + 7;

template < class t > void sc(t & x) {
  x = 0;
  int c = 0, z = 0, sign = 1;
  while (!isdigit(c = getchar()))
    z = c;
  if (z == '-')
    sign = -1;
  x = c - '0';
  while (isdigit(c = getchar()))
    x = (x << 1) + (x << 3) + c - '0';
  x *= sign;
}

template < class t > void put(t x) {
  static char buf[32] = { };
  if (x == 0) {
    putchar('0');
    return;
  }
  int i = 32;
  if (x < 0)
    putchar('-'), x = -x;
  do
    buf[--i] = x % 10 + '0';
  while (x /= 10);
  while (i < 32)
    putchar(buf[i++]);
}

int n;
int logn;
int cnt[N+N+16];
ll tree[N+N+16];
ll z[N+16];

void build() {
  logn = 18;
  fill(cnt+N,cnt+N+N,1);
  revn(i,N-1,0)
    cnt[i] = cnt[i<<1]+cnt[i<<1|1];
}

void apply(int i, ll v) {
  tree[i] += v;
  if(i < N)
    z[i] += v;
}

void up(int i) {
  while(i>>=1)
    tree[i] = tree[i<<1]+tree[i<<1|1]+cnt[i]*z[i];
}

void push(int i) {
  for(int p = logn; p; --p) {
    int x = i >> p;
    if(z[x]) {
      apply(x<<1,z[x]);
      apply(x<<1|1,z[x]);
      z[x] = 0;
    }
  }
}

void update(int l, int r, ll v) {
  push(l += N);
  push(r += N);
  int lx = l, rx = r;
  ll sum = 0;
  for(;l <= r; l >>= 1, r >>= 1) {
    if(l&1)
      apply(l++, v);
    if((r&1)==0)
      apply(r--, v);
  }
  up(lx);
  up(rx);
}

ll query(int l, int r) {
  push(l += N);
  push(r += N);
  ll sum = 0;
  for(;l <= r; l >>= 1, r >>= 1) {
    if(l&1)
      sum += tree[l++];
    if((r&1)==0)
      sum += tree[r--];
  }
  return sum;
}

int main() {
  scanf("%d",&n);
  int len = 1;
  ll sum = 0;
  build();
  while(n--) {
    int t; scanf("%d",&t);
    if(t == 1) {
      int x, y; scanf("%d%d",&x,&y);
      update(1,x,y);
      len = max(x,len);
    } else if(t == 2) {
      int x; scanf("%d",&x);
      ++len;
      update(len,len,x);
    } else {
      update(len,len,-query(len,len));
      --len;
    }

    printf("%.6f\n", query(1,len)/double(len));
  }
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unistd.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int, int >pii;
typedef vector < int >vi;
typedef vector < pii > vpii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;
typedef vector < pll > vpll;

#ifndef ONLINE_JUDGE
FILE *__redirect__ = freopen("in", "r", stdin);
#  include <bits/stdc++.h>
#else
#  include <bits/stdc++.h>
#endif

#define lsb(x) (x&-x)
#define del(x) if(x) delete x

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

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

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

#define all(x) (x.begin(),x.end())
#define rall(x) (x.rbegin(),x.rend())

#define pb push_back
#define eb pb
//emplace_back
#define mp make_pair

int INF = 1e9;
int const N = 2e5 + 16;
int const M = 1e9 + 7;

template < class t > void sc(t & x) {
  x = 0;
  int c = 0, z = 0, sign = 1;
  while (!isdigit(c = getchar()))
    z = c;
  if (z == '-')
    sign = -1;
  x = c - '0';
  while (isdigit(c = getchar()))
    x = (x << 1) + (x << 3) + c - '0';
  x *= sign;
}

template < class t > void put(t x) {
  static char buf[32] = { };
  if (x == 0) {
    putchar('0');
    return;
  }
  int i = 32;
  if (x < 0)
    putchar('-'), x = -x;
  do
    buf[--i] = x % 10 + '0';
  while (x /= 10);
  while (i < 32)
    putchar(buf[i++]);
}

int n;
int logn;
int cnt[N+N];
ll tree[N+N];
ll z[N+N];

void build() {
  logn = 18;
  rep(i,0,N)
    cnt[i+N] = 1;
  revn(i,N-1,0)
    cnt[i] = cnt[i<<1]+cnt[i<<1|1];
}

void apply(int i, ll v) {
  tree[i] += v;
  if(i < N)
    z[i] += v;
}

void up(int i) {
  while(i>>=1)
    tree[i] = tree[i<<1]+tree[i<<1|1]+cnt[i]*z[i];
}

void push(int i) {
  for(int p = logn; p; --p) {
    int x = i >> p;
    if(z[x]) {
      apply(x<<1,z[x]);
      apply(x<<1|1,z[x]);
      z[x] = 0;
    }
  }
}

void update(int l, int r, ll v) {
  push(l += N);
  push(r += N);
  int lx = l, rx = r;
  ll sum = 0;
  for(;l <= r; l >>= 1, r >>= 1) {
    if(l&1)
      apply(l++, v);
    if((r&1)==0)
      apply(r--, v);
  }
  up(lx);
  up(rx);
}

ll query(int l, int r) {
  push(l += N);
  push(r += N);
  ll sum = 0;
  for(;l <= r; l >>= 1, r >>= 1) {
    if(l&1)
      sum += tree[l++];
    if((r&1)==0)
      sum += tree[r--];
  }
  return sum;
}

int main() {
  scanf("%d",&n);
  int len = 1;
  ll sum = 0;
  while(n--) {
    int t; scanf("%d",&t);
    if(t == 1) {
      int x, y; scanf("%d%d",&x,&y);
      update(1,x,y);
    } else if(t == 2) {
      int x; scanf("%d",&x);
      ++len;
      update(len,len,x);
    } else {
      update(len,len,-query(len,len));
      --len;
    }

    printf("%.10f\n", (double)query(1,len)/len);
  }
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unistd.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int, int >pii;
typedef vector < int >vi;
typedef vector < pii > vpii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;
typedef vector < pll > vpll;

#ifndef ONLINE_JUDGE
FILE *__redirect__ = freopen("in", "r", stdin);
#  include <bits/stdc++.h>
#else
#  include <bits/stdc++.h>
#endif

#define lsb(x) (x&-x)
#define del(x) if(x) delete x

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

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

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

#define all(x) (x.begin(),x.end())
#define rall(x) (x.rbegin(),x.rend())

#define pb push_back
#define eb pb
//emplace_back
#define mp make_pair

int INF = 1e9;
int const N = 2e5 + 16;
int const M = 1e9 + 7;

template < class t > void sc(t & x) {
  x = 0;
  int c = 0, z = 0, sign = 1;
  while (!isdigit(c = getchar()))
    z = c;
  if (z == '-')
    sign = -1;
  x = c - '0';
  while (isdigit(c = getchar()))
    x = (x << 1) + (x << 3) + c - '0';
  x *= sign;
}

template < class t > void put(t x) {
  static char buf[32] = { };
  if (x == 0) {
    putchar('0');
    return;
  }
  int i = 32;
  if (x < 0)
    putchar('-'), x = -x;
  do
    buf[--i] = x % 10 + '0';
  while (x /= 10);
  while (i < 32)
    putchar(buf[i++]);
}

int n;
int a[N];
int b[N];

int main() {
  sc(n);
  int len = 1;
  ll sum = 0;
  while(n--) {
    int t; sc(t);
    if(t == 1) {
      int x, y; sc(x), sc(y);
      b[x] += y;
      sum += x*y;
    } else if(t == 2) {
      int x; sc(x);
      a[++len] = x;
      sum += x;
    } else {
      b[len-1] += b[len];
      sum -= a[len] + b[len];
      // zero after yourself :D
      a[len] = b[len] = 0;
      --len;
    }

    printf("%.6f\n", sum/double(len));
  }
}


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

typedef unsigned long long ull;
typedef long double   ld;
typedef long long     ll;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<pii>   vpii;
typedef pair<ll,ll>   pll;
typedef vector<ll>    vl;
typedef vector<pll>   vpll;

#define gc getchar
#define lsb(x) (x&-x)
#define blt(x) __builtin_##x
#define clz blt(clz)
#define ctz blt(ctz)
#define ones blt(popcount)
#define del(x) if(x) delete x

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

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

#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define double ld

int INF = 1e9;
ll MAX = 1e18;
double eps = numeric_limits<double>::epsilon();
double PI = acos(-1);
int const N = 2e5 + 16;
int const M = 1e9 + 7;

template<class t> void sc(t&x) {
  int c;//,z=0;
  while(!isdigit(c=gc()));// z = c;
  x = (c-'0');
  while(isdigit(c=gc()))
    x = (x<<1) + (x<<3) + (c-'0');
  //if(z=='-') x = -x;
}

template<class t> void print(t x){
  static char buf[32] = {};
  int i = 32;
  if(x == 0) {
    puts("0");return;
  } else if(x < 0)
    putchar('-'),x=-x;
  while(x) {
    t y = x/10;
    buf[--i] = x-(y<<1)-(y<<3)+'0';
    x = y;
  }
  puts(buf+i);
}

int n;
int a[N];
int t[N];
ll dp[N];
int z;

ll dfs(ll x = 1, int y = 0) {
  ll& sum = dp[x];

  if(z++ && x == 1)
    return -1e18;

  if(sum)
    return sum;

    sum += a[x];
    x += a[x];

    if(0 >= x || n < x) return sum;

    sum += a[x];
    x -= a[x];

    if(0 >= x || n < x) return sum;

    return sum + dfs(x);
}

int main() {
  scanf("%d",&n);
  repq(i,2,n) scanf("%d",a+i);

  rep(i,1,n) {
    a[1] = i;
    z = 0;
    dp[1] = 0;
    ll ans = dfs();
    if(ans < 0)
      puts("-1");
    else
      printf("%lld\n", ans);
  }
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unistd.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int, int >pii;
typedef vector < int >vi;
typedef vector < pii > vpii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;
typedef vector < pll > vpll;

#ifndef ONLINE_JUDGE
FILE *__redirect__ = freopen("in", "r", stdin);
#  include <bits/stdc++.h>
#else
#  include <bits/stdc++.h>
#endif

#define lsb(x) (x&-x)
#define del(x) if(x) delete x

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

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

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

#define all(x) (x.begin(),x.end())
#define rall(x) (x.rbegin(),x.rend())

#define pb push_back
#define eb pb
//emplace_back
#define mp make_pair

int INF = 1e9;
int const N = 2e5 + 16;
int const M = 1e9 + 7;

template < class t > void sc(t & x) {
  x = 0;
  int c = 0, z = 0, sign = 1;
  while (!isdigit(c = getchar()))
    z = c;
  if (z == '-')
    sign = -1;
  x = c - '0';
  while (isdigit(c = getchar()))
    x = (x << 1) + (x << 3) + c - '0';
  x *= sign;
}

template < class t > void put(t x) {
  static char buf[32] = { };
  if (x == 0) {
    putchar('0');
    return;
  }
  int i = 32;
  if (x < 0)
    putchar('-'), x = -x;
  do
    buf[--i] = x % 10 + '0';
  while (x /= 10);
  while (i < 32)
    putchar(buf[i++]);
}

int n;
ll a[N];
ll u[N];

int main() {
  scanf("%d",&n);
  int len = 1;
  ll sum = 0;
  while(n--) {
    int t; scanf("%d",&t);
    if(t == 1) {
      int x, y; scanf("%d%d",&x,&y);
      a[x] += y;
      sum += x*y;
    } else if(t == 2) {
      int x; scanf("%d",&x);
      a[++len] = x;
      sum += x;
    } else {
      u[len-1] += u[len];
      sum -= a[len]-u[len];
      --len;
    }

    printf("%.10f\n", (double)sum/len);
  }
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unistd.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int, int >pii;
typedef vector < int >vi;
typedef vector < pii > vpii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;
typedef vector < pll > vpll;

#ifndef ONLINE_JUDGE
FILE *__redirect__ = freopen("in", "r", stdin);
#  include <bits/stdc++.h>
#else
#  include <bits/stdc++.h>
#endif

#define lsb(x) (x&-x)
#define del(x) if(x) delete x

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

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

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

#define all(x) (x.begin(),x.end())
#define rall(x) (x.rbegin(),x.rend())

#define pb push_back
#define eb pb
//emplace_back
#define mp make_pair

int INF = 1e9;
int const N = 2e5 + 16;
int const M = 1e9 + 7;

template < class t > void sc(t & x) {
  x = 0;
  int c = 0, z = 0, sign = 1;
  while (!isdigit(c = getchar()))
    z = c;
  if (z == '-')
    sign = -1;
  x = c - '0';
  while (isdigit(c = getchar()))
    x = (x << 1) + (x << 3) + c - '0';
  x *= sign;
}

template < class t > void put(t x) {
  static char buf[32] = { };
  if (x == 0) {
    putchar('0');
    return;
  }
  int i = 32;
  if (x < 0)
    putchar('-'), x = -x;
  do
    buf[--i] = x % 10 + '0';
  while (x /= 10);
  while (i < 32)
    putchar(buf[i++]);
}

int n;
int a[N];
int b[N];

int main() {
  scanf("%d",&n);
  int len = 1;
  int sum = 0;
  while(n--) {
    int t; sc(t);
    if(t == 1) {
      int x, y; sc(x), sc(y);
      b[x] += y;
      sum += x*y;
    } else if(t == 2) {
      int x; sc(x);
      a[++len] = x;
      sum += x;
    } else {
      b[len-1] += b[len];
      sum -= a[len] + b[len];
      // zero after yourself :D
      a[len] = b[len] = 0;
      --len;
    }

    printf("%.6f\n", sum/double(len));
  }
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unistd.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int, int >pii;
typedef vector < int >vi;
typedef vector < pii > vpii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;
typedef vector < pll > vpll;

#ifndef ONLINE_JUDGE
FILE *__redirect__ = freopen("in", "r", stdin);
#  include <bits/stdc++.h>
#else
#  include <bits/stdc++.h>
#endif

#define lsb(x) (x&-x)
#define del(x) if(x) delete x

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

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

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

#define all(x) (x.begin(),x.end())
#define rall(x) (x.rbegin(),x.rend())

#define pb push_back
#define eb pb
//emplace_back
#define mp make_pair

int INF = 1e9;
int const N = 2e5 + 16;
int const M = 1e9 + 7;

template < class t > void sc(t & x) {
  x = 0;
  int c = 0, z = 0, sign = 1;
  while (!isdigit(c = getchar()))
    z = c;
  if (z == '-')
    sign = -1;
  x = c - '0';
  while (isdigit(c = getchar()))
    x = (x << 1) + (x << 3) + c - '0';
  x *= sign;
}

template < class t > void put(t x) {
  static char buf[32] = { };
  if (x == 0) {
    putchar('0');
    return;
  }
  int i = 32;
  if (x < 0)
    putchar('-'), x = -x;
  do
    buf[--i] = x % 10 + '0';
  while (x /= 10);
  while (i < 32)
    putchar(buf[i++]);
}

int n;
int a[N];
int u[N];

int main() {
  scanf("%d",&n);
  int len = 1;
  ll sum = 0;
  while(n--) {
    int t; scanf("%d",&t);
    if(t == 1) {
      int x, y; scanf("%d%d",&x,&y);
      a[x] += y;
      sum += x*y;
    } else if(t == 2) {
      int x; scanf("%d",&x);
      a[++len] = x;
      sum += x;
    } else {
      u[len-1] += u[len];
      sum -= a[len]-u[len];
      --len;
    }

    printf("%.10f\n", (float)sum/len);
  }
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unistd.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int, int >pii;
typedef vector < int >vi;
typedef vector < pii > vpii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;
typedef vector < pll > vpll;

#ifndef ONLINE_JUDGE
FILE *__redirect__ = freopen("in", "r", stdin);
#  include <bits/stdc++.h>
#else
#  include <bits/stdc++.h>
#endif

#define lsb(x) (x&-x)
#define del(x) if(x) delete x

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

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

#define repc(i,a,cond) for(int i = a; cond; ++i)
#define revc(i,a,cond) for(int i = a; cond; --i)

#define all(x) (x.begin(),x.end())
#define rall(x) (x.rbegin(),x.rend())

#define pb push_back
#define eb pb
//emplace_back
#define mp make_pair

int INF = 1e9;
int const N = 2e5 + 16;
int const M = 1e9 + 7;

template < class t > void sc(t & x) {
  x = 0;
  int c = 0, z = 0, sign = 1;
  while (!isdigit(c = getchar()))
    z = c;
  if (z == '-')
    sign = -1;
  x = c - '0';
  while (isdigit(c = getchar()))
    x = (x << 1) + (x << 3) + c - '0';
  x *= sign;
}

template < class t > void put(t x) {
  static char buf[32] = { };
  if (x == 0) {
    putchar('0');
    return;
  }
  int i = 32;
  if (x < 0)
    putchar('-'), x = -x;
  do
    buf[--i] = x % 10 + '0';
  while (x /= 10);
  while (i < 32)
    putchar(buf[i++]);
}

int n;
int logn;
int cnt[N+N+16];
ll tree[N+N+16];
ll z[N+16];

void build() {
  logn = 18;
  fill(cnt+N,cnt+N+N,1);
  revn(i,N-1,0)
    cnt[i] = cnt[i<<1]+cnt[i<<1|1];
}

void apply(int i, ll v) {
  tree[i] += v;
  if(i < N)
    z[i] += v;
}

void up(int i) {
  while(i>>=1)
    tree[i] = tree[i<<1]+tree[i<<1|1]+cnt[i]*z[i];
}

void push(int i) {
  for(int p = logn; p; --p) {
    int x = i >> p;
    if(z[x]) {
      apply(x<<1,z[x]);
      apply(x<<1|1,z[x]);
      z[x] = 0;
    }
  }
}

void update(int l, int r, ll v) {
  push(l += N);
  push(r += N);
  int lx = l, rx = r;
  ll sum = 0;
  for(;l <= r; l >>= 1, r >>= 1) {
    if(l&1)
      apply(l++, v);
    if((r&1)==0)
      apply(r--, v);
  }
  up(lx);
  up(rx);
}

ll query(int l, int r) {
  push(l += N);
  push(r += N);
  ll sum = 0;
  for(;l <= r; l >>= 1, r >>= 1) {
    if(l&1)
      sum += tree[l++];
    if((r&1)==0)
      sum += tree[r--];
  }
  return sum;
}

int main() {
  scanf("%d",&n);
  int len = 0;
  ll sum = 0;
  build();
  while(n--) {
    int t; scanf("%d",&t);
    if(t == 1) {
      int x, y; scanf("%d%d",&x,&y);
      update(0,x-1,y);
      len = max(x,len);
    } else if(t == 2) {
      int x; scanf("%d",&x);
      ++len;
      update(len,len,x);
    } else {
      update(len,len,-query(len,len));
      --len;
    }

    printf("%.6f\n", query(0,len)/double(len+1));
  }
}