#include<iostream>
#include<vector>
using namespace std;
vector<int> tree(1048576,-1);
void upd(int s,int e,int p,int i,int j,int win)
{
    if(s>=i && j>=e && tree[p]!=-1)return;
    if(i>e || j<s)return;
    if(s>=i && j>=e && tree[p]==-1)
    {
        // cout<<"tree["<<p<<"]="<<tree[p]<<endl;
        tree[p]=win;
        return;
    }
    int m=(s+e)/2;
    if(j<=m)upd(s,m,2*p,i,j,win);
    else if(i>m)upd(m+1,e,2*p+1,i,j,win);
    else
    {
        upd(s,m,2*p,i,m,win);
        upd(m+1,e,2*p+1,m+1,j,win);
    }
    // cout<<"tree["<<p<<"]="<<tree[p]<<endl;
}
int get(int i)
{
    while(i>0 && tree[i]==-1)
    {
        i/=2;
    }
    if(i>0)return tree[i];
    else return i;
}
int main(void)
{
    int n,fights;
    cin>>n>>fights;
    int k=1;
    while(k<n)
    {
        k*=2;
    }
    int total=k*2;
    int buffer=k-1;
    // cout<<"buffer="<<buffer<<endl;
    // cout<<"total="<<total<<endl;
    for(int i=0;i<fights;++i)
    {
        int a,b,win;
        cin>>a>>b>>win;
        if(a<=win-1)upd(1,n,1,a,win-1,win);
        if(b>=win+1)upd(1,n,1,win+1,b,win);
    }
    vector<int> ans(n+1,-1);
    for(int i=1;i<=n;++i)
    {
        ans[i]=get(i+buffer);
    }
    for(int i=1;i<=n;++i)
    {
        cout<<ans[i]<<" ";
    }
    return 0;
}


#include<iostream>
#include<vector>
using namespace std;
vector<int> tree(1048576,-1);
void upd(int s,int e,int p,int i,int j,int win,int n)
{
    // cout<<"s="<<s<<" e="<<e<<" i="<<i<<" j="<<j<<" win="<<win<<endl;
    if(s>n)return;
    if(i>e || j<s)return;
    if(s>=i && j>=e && tree[p]!=-1)return;
    if(s==e && tree[p]!=-1)return;
    if(s>=i && j>=e && tree[p]==-1)
    {
        tree[p]=win;
        // cout<<"tree["<<p<<"]="<<tree[p]<<endl;
        return;
    }
    if(s==e && tree[p]==-1)
    {
        tree[p]=win;
        return;
    }
    int m=(s+e)/2;
    if(j<=m)upd(s,m,2*p,i,j,win,n);
    else if(i>m)upd(m+1,e,2*p+1,i,j,win,n);
    else
    {
        upd(s,m,2*p,i,j,win,n);
        upd(m+1,e,2*p+1,i,j,win,n);
    }
    // cout<<"tree["<<p<<"]="<<tree[p]<<endl;
}
int get(int i)
{
    while(i>0 && tree[i]==-1)
    {
        i/=2;
    }
    if(i>0)return tree[i];
    else return i;
}
int main(void)
{
    int n,fights;
    cin>>n>>fights;
    int k=1;
    while(k<n)
    {
        k*=2;
    }
    int total=k*2;
    int buffer=k-1;
    // cout<<"buffer="<<buffer<<endl;
    // cout<<"total="<<total<<endl;
    for(int i=0;i<fights;++i)
    {
        int a,b,win;
        cin>>a>>b>>win;
        if(a<=win-1)upd(1,total/2,1,a,win-1,win,n);
        if(b>=win+1)upd(1,total/2,1,win+1,b,win,n);
    }
    vector<int> ans(n+1,-1);
    for(int i=1;i<=n;++i)
    {
        ans[i]=get(i+buffer);
    }
    for(int i=1;i<=n;++i)
    {
        cout<<ans[i]<<" ";
    }
    return 0;
}


#include<iostream>
#include<vector>
using namespace std;
vector<int> tree(1048576,-1);
void upd(int s,int e,int p,int i,int j,int win)
{
    if(s>=i && j>=e && tree[p]!=-1)return;
    if(s>=i && j>=e && tree[p]==-1)
    {
        // cout<<"tree["<<p<<"]="<<tree[p]<<endl;
        tree[p]=win;
        return;
    }
    int m=(s+e)/2;
    if(j<=m)upd(s,m,2*p,i,j,win);
    else if(i>m)upd(m+1,e,2*p+1,i,j,win);
    else
    {
        upd(s,m,2*p,i,m,win);
        upd(m+1,e,2*p+1,m+1,j,win);
    }
    // cout<<"tree["<<p<<"]="<<tree[p]<<endl;
}
int get(int i)
{
    while(i>0 && tree[i]==-1)
    {
        i/=2;
    }
    if(i>0)return tree[i];
    else return i;
}
int main(void)
{
    int n,fights;
    cin>>n>>fights;
    int k=1;
    while(k<n)
    {
        k*=2;
    }
    int total=k*2;
    int buffer=k-1;
    // cout<<"buffer="<<buffer<<endl;
    // cout<<"total="<<total<<endl;
    for(int i=0;i<fights;++i)
    {
        int a,b,win;
        cin>>a>>b>>win;
        if(a<=win-1)upd(1,n,1,a,win-1,win);
        if(b>=win+1)upd(1,n,1,win+1,b,win);
    }
    vector<int> ans(n+1,-1);
    for(int i=1;i<=n;++i)
    {
        ans[i]=get(i+buffer);
    }
    for(int i=1;i<=n;++i)
    {
        cout<<ans[i]<<" ";
    }
    return 0;
}


#include<iostream>
#include<vector>
using namespace std;
vector<int> tree(1048576,-1);
void upd(int s,int e,int p,int i,int j,int win,int n)
{
    // cout<<"s="<<s<<" e="<<e<<" i="<<i<<" j="<<j<<" win="<<win<<" n="<<n<<endl;
    if(s>n)return;
    if(i>e || j<s)return;
    if(tree[p]!=-1)return;
    if(s==e && tree[p]!=-1)return;
    if(s>=i && j>=e && tree[p]==-1)
    {
        tree[p]=win;
        // cout<<"tree["<<p<<"]="<<tree[p]<<endl;
        return;
    }
    if(s==e && tree[p]==-1)
    {
        tree[p]=win;
        return;
    }
    int m=(s+e)/2;
    if(j<=m)upd(s,m,2*p,i,j,win,n);
    else if(i>m)upd(m+1,e,2*p+1,i,j,win,n);
    else
    {
        upd(s,m,2*p,i,j,win,n);
        upd(m+1,e,2*p+1,i,j,win,n);
    }
    // cout<<"tree["<<p<<"]="<<tree[p]<<endl;
}
int get(int i)
{
    while(i>0 && tree[i]==-1)
    {
        i/=2;
    }
    if(i>0)return tree[i];
    else return i;
}
int main(void)
{
    int n,fights;
    cin>>n>>fights;
    int k=1;
    while(k<n)
    {
        k*=2;
    }
    int total=k*2;
    int buffer=k-1;
    // cout<<"buffer="<<buffer<<endl;
    // cout<<"total="<<total<<endl;
    for(int i=0;i<fights;++i)
    {
        int a,b,win;
        cin>>a>>b>>win;
        if(a<=win-1)upd(1,total/2,1,a,win-1,win,n);
        if(b>=win+1)upd(1,total/2,1,win+1,b,win,n);
    }
    vector<int> ans(n+1,-1);
    for(int i=1;i<=n;++i)
    {
        ans[i]=get(i+buffer);
    }
    for(int i=1;i<=n;++i)
    {
        cout<<ans[i]<<" ";
    }
    return 0;
}


#include<iostream>
#include<vector>
using namespace std;
vector<int> tree(1048576,-1);
void upd(int s,int e,int p,int i,int j,int win)
{
    if(s>=i && j>=e && tree[p]!=-1)return;
    if(i>e || j<s)return;
    if(s>=i && j>=e && tree[p]==-1)
    {
        // cout<<"tree["<<p<<"]="<<tree[p]<<endl;
        tree[p]=win;
        return;
    }
    int m=(s+e)/2;
    if(j<=m)upd(s,m,2*p,i,j,win);
    else if(i>m)upd(m+1,e,2*p+1,i,j,win);
    else
    {
        upd(s,m,2*p,i,j,win);
        upd(m+1,e,2*p+1,i,j,win);
    }
    // cout<<"tree["<<p<<"]="<<tree[p]<<endl;
}
int get(int i)
{
    while(i>0 && tree[i]==-1)
    {
        i/=2;
    }
    if(i>0)return tree[i];
    else return i;
}
int main(void)
{
    int n,fights;
    cin>>n>>fights;
    int k=1;
    while(k<n)
    {
        k*=2;
    }
    int total=k*2;
    int buffer=k-1;
    // cout<<"buffer="<<buffer<<endl;
    // cout<<"total="<<total<<endl;
    for(int i=0;i<fights;++i)
    {
        int a,b,win;
        cin>>a>>b>>win;
        if(a<=win-1)upd(1,n,1,a,win-1,win);
        if(b>=win+1)upd(1,n,1,win+1,b,win);
    }
    vector<int> ans(n+1,-1);
    for(int i=1;i<=n;++i)
    {
        ans[i]=get(i+buffer);
    }
    for(int i=1;i<=n;++i)
    {
        cout<<ans[i]<<" ";
    }
    return 0;
}


#include <iostream>

using namespace std;

void change(int*, int, int, int, int, int, int ,int);
int get(int*, int, int);

int main() {
	int n, m;
	cin >> n >> m;
	int* knights = new int[2 * n]{};

	for (int i = 0; i < m; ++i) {
		int l, r, x;
		cin >> l >> r >> x;
		change(knights, n, l - 1, r - 1, 1, 0, n - 1, x);
	}

	for (int i = 0; i < n; ++i) {
		cout << get(knights, n + i, i + 1) << ' ';
	}
	cout << endl;

	return 0;
}

void change(int* knights, int n, int l, int r, int k, int a, int b, int x) {
	if (a > r || b < l) {
		return;
	}
	if (a >= l && b <= r) {
		if (knights[k] == 0) {
			knights[k] = x;
			return;
		}
		if (knights[n + knights[k] - 1] == 0) {
			knights[n + knights[k] - 1] = x;
		}
		return;
	}
	int d = (b - a + 1) / 2;
	change(knights, n, l, r, k * 2, a, a + d - 1, x);
	change(knights, n, l, r, k * 2 + 1, a + d, b, x);
}

int get(int* knights, int k, int x) {
	if (k == 0) {
		return 0;
	}
	if (knights[k] == 0 || knights[k] == x) {
		return get(knights, k / 2, x);
	}
	return knights[k];
}


#include <iostream>

using namespace std;

void change(int*, int, int, int, int, int, int ,int);
int get(int*, int, int);

int main() {
	int n, m;
	cin >> n >> m;
	int N = 1;
	while (N < n) {
		N *= 2;
	}
	int* knights = new int[2 * N]{};

	for (int i = 0; i < m; ++i) {
		int l, r, x;
		cin >> l >> r >> x;
		change(knights, N, l - 1, r - 1, 1, 0, N - 1, x);
	}

	for (int i = 0; i < n; ++i) {
		cout << get(knights, N + i, i + 1) << ' ';
	}
	cout << endl;

	return 0;
}

void change(int* knights, int n, int l, int r, int k, int a, int b, int x) {
	if (a > r || b < l) {
		return;
	}
	if (a >= l && b <= r) {
		if (knights[k] == 0) {
			knights[k] = x;
			return;
		}
		if (knights[n + knights[k] - 1] == 0) {
			knights[n + knights[k] - 1] = x;
		}
		return;
	}
	int d = (b - a + 1) / 2;
	change(knights, n, l, r, k * 2, a, a + d - 1, x);
	change(knights, n, l, r, k * 2 + 1, a + d, b, x);
}

int get(int* knights, int k, int x) {
	if (k == 0) {
		return 0;
	}
	if (knights[k] == 0 || knights[k] == x) {
		return get(knights, k / 2, x);
	}
	return knights[k];
}


#include <iostream>

using namespace std;

void change(int*, int, int, int, int, int, int ,int);
int get(int*, int, int);

int main() {
	int n, m;
	cin >> n >> m;
	int N = 1;
	while (N < n) {
		N *= 2;
	}
	int* knights = new int[2 * N]{};

	for (int i = 0; i < m; ++i) {
		int l, r, x;
		cin >> l >> r >> x;
		change(knights, N, l - 1, r - 1, 1, 0, N - 1, x);
	}

	for (int i = 0; i < n; ++i) {
		cout << get(knights, N + i, i + 1) << ' ';
	}
	cout << endl;

	return 0;
}

void change(int* knights, int n, int l, int r, int k, int a, int b, int x) {
	if (a > r || b < l) {
		return;
	}
	if (knights[k] != 0) {
		int i = knights[k] - 1;
		if (a <= i && i <= b) {
			knights[n + i] = x;
		}
		return;
	}
	if (a >= l && b <= r) {
		knights[k] = x;
		return;
	}
	int d = (b - a + 1) / 2;
	change(knights, n, l, r, k * 2, a, a + d - 1, x);
	change(knights, n, l, r, k * 2 + 1, a + d, b, x);
}

int get(int* knights, int k, int x) {
	if (k == 0) {
		return 0;
	}
	if (knights[k] == 0 || knights[k] == x) {
		return get(knights, k / 2, x);
	}
	return knights[k];
}


#include <iostream>

using namespace std;

void change(int*, int, int, int, int, int ,int);
int get(int*, int);

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

	int* knights = new int[2 * n]{};

	for (int i = 0; i < m; ++i) {
		int l, r, x;
		cin >> l >> r >> x;
		change(knights, l, r, 1, 0, n - 1, x - 1);
	}

	for (int i = 0; i < n; ++i) {
		cout << get(knights, n + i) + 1 << ' ';
	}
	cout << endl;

	return 0;
}

void change(int* knights, int l, int r, int k, int a, int b, int x) {
	if (a > r || b < l) {
		return;
	}
	if (a >= l && x <= r) {
		knights[k] = x;
		return;
	}
	int d = (b - a + 1) / 2;
	change(knights, l, r, k * 2, a, a + d - 1, x);
	change(knights, l, r, k * 2 + 1, a + d, b, x);
}

int get(int* knights, int k) {
	if (knights[k] == 0) {
		return get(knights, k / 2);
	}
	return knights[k];
}


#include <iostream>

using namespace std;

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

	int* knights = new int[n + 1];
	for (int i = 1; i <= n; ++i) {
		knights[i] = 0;
	}

	for (int i = 0; i < m; ++i) {
		int l, r, x;
		cin >> l >> r >> x;

		for (int j = l; j <= r; ++j) {
			if (knights[j] == 0) {
				knights[j] = x;
			}
		}
		knights[x] = 0;
	}

	for (int i = 1; i <= n; ++i) {
		cout << knights[i] << ' ';
	}
	cout << endl;

	return 0;
}


#include <iostream>

using namespace std;

void change(int*, int, int, int, int, int, int ,int);
int get(int*, int, int);

int main() {
	int n, m;
	cin >> n >> m;
	int N = 1;
	while (N < n) {
		N *= 2;
	}
	int* knights = new int[2 * N]{};

	for (int i = 0; i < m; ++i) {
		int l, r, x;
		cin >> l >> r >> x;
		change(knights, N, l - 1, r - 1, 1, 0, N - 1, x);
	}

	for (int i = 0; i < n; ++i) {
		cout << get(knights, N + i, i + 1) << ' ';
	}
	cout << endl;

	return 0;
}

void change(int* knights, int n, int l, int r, int k, int a, int b, int x) {
	if (a > r || b < l) {
		return;
	}
	if (knights[k] != 0) {
		int i = knights[k] - 1;
		if (knights[n + i] == 0 || knights[n + i] == i + 1) {
			if (a <= i && i <= b) {
				knights[n + i] = x;
			}
		}
		return;
	}
	if (a >= l && b <= r) {
		knights[k] = x;
		return;
	}
	int d = (b - a + 1) / 2;
	change(knights, n, l, r, k * 2, a, a + d - 1, x);
	change(knights, n, l, r, k * 2 + 1, a + d, b, x);
}

int get(int* knights, int k, int x) {
	if (k == 0) {
		return 0;
	}
	if (knights[k] == 0 || knights[k] == x) {
		return get(knights, k / 2, x);
	}
	return knights[k];
}


#include <iostream>
using namespace std;

int main() {

    int numOfKnights; cin >> numOfKnights;
    int* data = new int[numOfKnights + 1];
    int* result = new int[numOfKnights + 1];
    for (int i = 0; i <= numOfKnights; i++) {
        data[i] = i + 1;
        result[i] = 0;
    }

    int numOfBattles; cin >> numOfBattles;
    for (int battle = 0; battle < numOfBattles; battle++) {
        int from, to, winner;
        cin >> from >> to >> winner;
        int prev = from - 1;
        int curr = data[prev];
        while (prev > 0 && data[prev] == curr) {
            data[prev] = winner;
            prev--;
        }
        while (curr < winner) {
            result[curr] = winner;
            data[prev] = winner;
            prev = curr;
            curr = data[prev];
        }
        prev = winner;
        curr = data[winner];
        while (curr <= to) {
            result[curr] = winner;
            data[prev] = data[to];
            prev = curr;
            curr = data[prev];
        }
        result[winner] = 0;
    }

    for (int res_i = 1; res_i <= numOfKnights; res_i++) {
        cout << result[res_i] << ' ';
    }
    cout << endl;

    delete[] result;
    delete[] data;

    return 0;
}


#include <iostream>
using namespace std;

int main() {

    int numOfKnights; cin >> numOfKnights;
    int* result = new int[numOfKnights];
    for (int i = 0; i < numOfKnights; i++) {
        result[i] = 0;
    }

    int numOfBattles; cin >> numOfBattles;
    for (int battle = 0; battle < numOfBattles; battle++) {
        int from, to, winner;
        cin >> from >> to >> winner;
        for (int k = from; k <= to; k++) {
            if (result[k-1] == 0 && k != winner) {
                result[k-1] = winner;
            }
        }
    }

    for (int res_i = 0; res_i < numOfKnights; res_i++) {
        cout << result[res_i] << ' ';
    }
    cout << endl;

    return 0;
}


#include <iostream>
using namespace std;

int main() {

    int numOfKnights; cin >> numOfKnights;
    int* data = new int[numOfKnights + 1];
    int* result = new int[numOfKnights + 1];
    for (int i = 0; i <= numOfKnights; i++) {
        data[i] = i + 1;
        result[i] = 0;
    }

    int numOfBattles; cin >> numOfBattles;
    for (int battle = 0; battle < numOfBattles; battle++) {
        int from, to, winner;
        cin >> from >> to >> winner;
        int prev = from - 1;
        int curr = data[prev];
        while (prev > 0 && data[prev] == curr) {
            data[prev] = winner;
            prev--;
        }
        prev = from - 1;
        while (curr < winner) {
            result[curr] = winner;
            data[prev] = winner;
            prev = curr;
            curr = data[prev];
        }
        prev = winner;
        curr = data[winner];
        while (curr <= to) {
            result[curr] = winner;
            data[prev] = data[to];
            prev = curr;
            curr = data[prev];
        }
        result[winner] = 0;
    }

    for (int res_i = 1; res_i <= numOfKnights; res_i++) {
        cout << result[res_i] << ' ';
    }
    cout << endl;

    delete[] result;
    delete[] data;

    return 0;
}


#include <iostream>
using namespace std;

int main() {

    int numOfKnights; cin >> numOfKnights;
    int* result = new int[numOfKnights];
    for (int i = 0; i < numOfKnights; i++) {
        result[i] = 0;
    }

    int numOfBattles; cin >> numOfBattles;
    for (int battle = 0; battle < numOfBattles; battle++) {
        int f_i, t_i, w_i;
        cin >> f_i >> t_i >> w_i;
        f_i--; t_i--; w_i--;
        for (int j = f_i; j < w_i; j++) {
            if (result[j] == 0) result[j] = w_i + 1;
        }
        for (int k = w_i + 1; k <= t_i; k++) {
            if (result[k] == 0) result[k] = w_i + 1;
        }
    }

    for (int res_i = 0; res_i < numOfKnights; res_i++) {
        cout << result[res_i] << ' ';
    }
    cout << endl;

    delete[] result;

    return 0;
}


#include <iostream>
using namespace std;

int main() {

    int numOfKnights; cin >> numOfKnights;
    int* data = new int[numOfKnights + 1];
    int* result = new int[numOfKnights + 1];
    for (int i = 0; i <= numOfKnights; i++) {
        data[i] = i + 1;
        result[i] = 0;
    }

    int numOfBattles; cin >> numOfBattles;
    for (int battle = 0; battle < numOfBattles; battle++) {
        int from, to, winner;
        cin >> from >> to >> winner;
        int prev = from - 1;
        int curr = data[prev];
        while (curr < winner) {
            result[curr] = winner;
            data[prev] = winner;
            prev = curr;
            curr = data[prev];
        }
        prev = winner;
        curr = data[winner];
        while (curr <= to) {
            result[curr] = winner;
            data[prev] = data[to];
            prev = curr;
            curr = data[prev];
        }
        result[winner] = 0;
    }

    for (int res_i = 1; res_i <= numOfKnights; res_i++) {
        cout << result[res_i] << ' ';
    }
    cout << endl;

    delete[] result;
    delete[] data;

    return 0;
}


#include <iostream>
#include <set>
using namespace std;

int main() {

    int numOfKnights; cin >> numOfKnights;
    set<int> remaining;
    int* result = new int[numOfKnights];
    for (int i = 0; i < numOfKnights; i++) {
        remaining.insert(i + 1);
        result[i] = 0;
    }

    int numOfBattles; cin >> numOfBattles;
    for (int battle = 0; battle < numOfBattles; battle++) {
        int from, to, winner;
        cin >> from >> to >> winner;
        set<int>::iterator i = remaining.lower_bound(from);
        while (i != remaining.end()) {
            from = *i;
            if (from > to) break;
            result[from - 1] = winner;
            remaining.erase(from);
            i = remaining.lower_bound(from);
        }
        remaining.insert(winner);
        result[winner - 1] = 0;
    }

    for (int res_i = 0; res_i < numOfKnights; res_i++) {
        cout << result[res_i] << ' ';
    }
    cout << endl;

    delete[] result;

    return 0;
}


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

#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define endl '\n'

int n, q;
vector<int> nxt;

int get(int u) {
	if (u >= n) return n;
	if (nxt[u] == u) return u;
	else return nxt[u] = get(nxt[u]);
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cout << fixed << setprecision(20);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> n >> q;
	nxt.resize(n);
	iota(all(nxt), 0);

	vector<int> res(n, -1);
	while (q--) {
		int l, r, val;
		cin >> l >> r >> val;
		--l, --r, --val;
		for (int i = get(l); i <= r; i = get(i)) {
			if (i != val) {
				nxt[i] = i + 1;
				res[i] = val;
			}
			else ++i;
		}
	}
	for (auto& i : res) cout << i + 1 << ' ';
}


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

#define int long long
#define double long double

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cout << fixed << setprecision(20);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, q;
	cin >> n >> q;
	set<int> s;
	for (int i = 0; i < n; ++i) s.insert(i);

	int l, r, val;
	vector<int> res(n, 0);
	while (q--) {
		cin >> l >> r >> val;
		auto it = s.lower_bound(--l);
		while (it != s.end() && (*it) < r) {
			if (*it + 1 != val) {
				res[(*it)] = val;
				auto temp = it;
				++it;
				s.erase(temp);
			}
			else ++it;
		}
	}
	for (int i = 0; i < n; ++i) cout << res[i] << ' ';
}


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

#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define endl '\n'

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cout << fixed << setprecision(20);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, q;
	cin >> n >> q;
	set<int> s;
	for (int i = 0; i < n; ++i) s.insert(i);

	vector<int> res(n, 0);
	while (q--) {
		int l, r, val;
		cin >> l >> r >> val;
		--l, --r, --val;
		vector<set<int>::iterator> a;
		for (auto it = lower_bound(all(s), l); it != s.end(); ++it) {
			if ((*it) > r) break;
			if((*it)!=val) a.pb(it);
		}
		for (auto it : a) {
			res[(*it)] = val + 1;
			s.erase(it);
		}
	}
	for (auto& i : res) cout << i << ' ';
}


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

#define int long long
#define double long double

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cout << fixed << setprecision(20);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, q;
	cin >> n >> q;
	set<int> s;
	for (int i = 0; i < n; ++i) s.insert(i);

	vector<int> res(n, -1);
	while (q--) {
		int l, r, val;
		cin >> l >> r >> val;
		--l, --r, --val;
		for (auto it = next(s.lower_bound(l)); *prev(it) <= r; ++it) {
			if (*prev(it) != val) {
				res[*prev(it)] = val;
				s.erase(prev(it));
			}
			if (it == s.end()) break;
		}
	}
	for (auto& i : res) cout << i + 1 << ' ';
}


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

#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define endl '\n'

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cout << fixed << setprecision(20);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, q;
	cin >> n >> q;
	set<int> s;
	for (int i = 0; i < n; ++i) s.insert(i);

	vector<int> res(n, 0);
	while (q--) {
		int l, r, val;
		cin >> l >> r >> val;
		--l, --r, --val;
		vector<set<int>::iterator> a;
		for (auto it = lower_bound(all(s), l); it != s.end(); ++it) {
			if ((*it) > r) break;
			if((*it)!=val) a.pb(it);
		}
		for (auto it : a) {
			res[(*it)] = val + 1;
			s.erase(it);
		}
		a.clear();
	}
	for (auto& i : res) cout << i << ' ';
}


#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//#define int long long
#define double long double

int n, q;
const int N = 3e5;
int res[N];
set<int> s;

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cout << fixed << setprecision(20);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> n >> q;
	for (int i = 0; i < n; ++i) {
		s.insert(i);
	}

	int l, r, val;
	while (q--) {
		cin >> l >> r >> val;
		vector<int> temp;
		for (auto it = lower_bound(s.begin(), s.end(), --l); it != s.end() && (*it) < r; ++it) {
			if ((*it) + 1 != val) temp.push_back(*it);
		}
		for (int i = 0; i < temp.size(); ++i) {
			res[temp[i]] = val;
			s.erase(temp[i]);
		}
	}
	for (int i = 0; i < n; ++i) {
		cout << res[i] << ' ';
	}
}


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

#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define endl '\n'

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cout << fixed << setprecision(20);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, q;
	cin >> n >> q;
	set<int> s;
	for (int i = 0; i < n; ++i) s.insert(i);

	vector<int> res(n, -1);
	while (q--) {
		int l, r, val;
		cin >> l >> r >> val;
		--l, --r, --val;
		vector<set<int>::iterator> a;
		auto it = lower_bound(all(s), l);
		while (it != s.end()) {
			if ((*it) > r) break;
			if ((*it) != val) a.pb(it), res[(*it)] = val;
			++it;
		}
		for (auto& it : a) s.erase(it);
	}
	for (auto& i : res) cout << i + 1 << ' ';
}


#include<bits/stdc++.h>
#define p 1000000007
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%p;}
                a=(a*a)%p;
                b>>=1;
            }
            return ans;

}
int main()
{
	int n,m;
	cin>>n>>m;
	int a[n]={0},b[n];
	for(int i=0;i<n;i++){
		b[i]=i+1;
	}
	while(m--){
		int l,r,x;
		cin>>l>>r>>x;
		//queue<int>q;
		int y=l-1;
		while(y<r){
			if(y==x-1){y++;continue;}
			if(a[y]==0){a[y]=x;b[y]=r;y++;continue;}
			else if(a[y]-1<r&&a[a[y]-1]==0){
				//q.push(a[y]-1);
				a[a[y]-1]=x;
				b[a[y]-1]=r;
			}
			y=b[y];
		}
		/* while(!q.empty()){
			if(q.front()==x-1){q.pop();continue;
			}
			//cout<<q.front()<<" ";
			a[q.front()]=x;
			b[q.front()]=r;
			q.pop();
		}*/
	//cout<<endl;
	}
	for(int i=0;i<n;i++){cout<<a[i]<<" ";}
    return 0;
}


#include<bits/stdc++.h>
//#define p 1000000007
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;

int main()
{
	int n,m;
	cin>>n>>m;
	int a[n]={0};
	int b[n];
	for(int i=0;i<n;i++){
		b[i]=i+1;
	}
	while(m--){
		int x,y,z;
		cin>>x>>y>>z;
		x--;y--;z--;
		int i=x;

		while(i<=y){
			//cout<<i+1<<" ";
			int k=b[i];
			if(a[i]!=0){i=k;continue;}
			if(i==z){b[i]=b[y];i=k;continue;}
			a[i]=z+1;//cout<<i<<" ";
			if(i<z)b[i]=z;
			else b[i]=b[y];
			i=k;
		}
		//cout<<endl;
	}
	for(int i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
    return 0;
}


#include<bits/stdc++.h>
//#define p 1000000007
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;

int find(int i,int b[]){
	if(b[i]==i)return i;
	return b[i]=find(b[i],b);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m;
	cin>>n>>m;
	int a[n]={0};
	int b[n+1];
	for(int i=0;i<=n;i++){
		b[i]=i;
	}
	while(m--){
		int x,y,z;
		cin>>x>>y>>z;
		x--;y--;z--;
		int i=x;
		if(a[i]!=0)i=find(i,b);
		while(i<=y){
			//cout<<i+1<<" ";
			if(i==z){i++;}
			else{a[i]=z+1;if(i<z)b[i]=z;else b[i]=y+1;i++;}
			i=find(i,b);
		}
		//cout<<endl;
	}
	for(int i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
    return 0;
}


#include<bits/stdc++.h>
#define p 1000000007
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%p;}
                a=(a*a)%p;
                b>>=1;
            }
            return ans;

}
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m;
	cin>>n>>m;
	int a[n]={0},b[n];
	for(int i=0;i<n;i++){
		b[i]=i+1;
	}
	while(m--){
		int l,r,x;
		cin>>l>>r>>x;
		//queue<int>q;
		int y=l-1;
		while(y<r){
			if(y==x-1){y++;continue;}
			if(a[y]==0){a[y]=x;b[y]=r;y++;continue;}
			else if(a[y]-1<r&&a[a[y]-1]==0&&a[y]!=x){
				//q.push(a[y]-1);
				a[a[y]-1]=x;
				b[a[y]-1]=r;
			}
			y=b[y];
		}
		/* while(!q.empty()){
			if(q.front()==x-1){q.pop();continue;
			}
			//cout<<q.front()<<" ";
			a[q.front()]=x;
			b[q.front()]=r;
			q.pop();
		}*/
	//cout<<endl;
	}
	for(int i=0;i<n;i++){cout<<a[i]<<" ";}
    return 0;
}


#include<bits/stdc++.h>
#define p 1000000007
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%p;}
                a=(a*a)%p;
                b>>=1;
            }
            return ans;

}
int getnext(int i,int b[]){
	if(b[i]==i)return i;
	return b[i]=getnext(b[i],b);
}
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m;
	cin>>n>>m;
	int a[n]={0},b[n];
	for(int i=0;i<n;i++){
		b[i]=i;
	}
	while(m--){
		int l,r,x;
		cin>>l>>r>>x;
		//queue<int>q;
		int y=l-1;
		while(y<r){
			//cout<<y<<" ";
			if(y==x-1){y++;continue;}
			if(a[y]==0){a[y]=x;b[y]=x-1;y++;if(y>b[y])b[y]=r-1;continue;}
			/*else if(a[y]-1<r&&a[a[y]-1]==0&&a[y]!=x){
				//q.push(a[y]-1);
				a[a[y]-1]=x;
				b[a[y]-1]=x-1;
			}*/
			y=getnext(y,b);
		}
		/* while(!q.empty()){
			if(q.front()==x-1){q.pop();continue;
			}
			//cout<<q.front()<<" ";
			a[q.front()]=x;
			b[q.front()]=r;
			q.pop();
		}*/
	//cout<<endl;
	}
	for(int i=0;i<n;i++){cout<<a[i]<<" ";}
    return 0;
}


#include<bits/stdc++.h>
//#define p 1000000007
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m;
	cin>>n>>m;
	int a[n]={0};
	int b[n];
	for(int i=0;i<n;i++){
		b[i]=i+1;
	}
	while(m--){
		int x,y,z;
		cin>>x>>y>>z;
		x--;y--;z--;
		int i=x;

		while(i<=y){
			//cout<<i+1<<" ";
			int k=b[i];
			if(a[i]!=0){i=k;continue;}
			if(i==z){b[i]=b[y];i=k;continue;}
			a[i]=z+1;//cout<<i<<" ";
			if(i<z)b[i]=z;
			else b[i]=b[y];
			i=k;
		}
		//cout<<endl;
	}
	for(int i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
    return 0;
}


#include<bits/stdc++.h>
#define p 1000000007
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%p;}
                a=(a*a)%p;
                b>>=1;
            }
            return ans;

}
int main()
{
	int n,m;
	cin>>n>>m;
	int a[n]={0},b[n];
	for(int i=0;i<n;i++){
		b[i]=i+1;
	}
	while(m--){
		int l,r,x;
		cin>>l>>r>>x;
		//queue<int>q;
		int y=l-1;
		while(y<r){
			if(y==x-1){y++;continue;}
			if(a[y]==0){a[y]=x;b[y]=r;y++;continue;}
			else if(a[y]-1<r&&a[a[y]-1]==0&&a[y]!=x){
				//q.push(a[y]-1);
				a[a[y]-1]=x;
				b[a[y]-1]=r;
			}
			y=b[y];
		}
		/* while(!q.empty()){
			if(q.front()==x-1){q.pop();continue;
			}
			//cout<<q.front()<<" ";
			a[q.front()]=x;
			b[q.front()]=r;
			q.pop();
		}*/
	//cout<<endl;
	}
	for(int i=0;i<n;i++){cout<<a[i]<<" ";}
    return 0;
}


#include<bits/stdc++.h>
#define p 1000000007
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%p;}
                a=(a*a)%p;
                b>>=1;
            }
            return ans;

}
int main()
{
	int n,m;
	cin>>n>>m;
	int a[n]={0},b[n];
	for(int i=0;i<n;i++){
		b[i]=i+1;
	}
	while(m--){
		int l,r,x;
		cin>>l>>r>>x;
		queue<int>q;
		int y=l-1;
		while(y<r){
			if(a[y]==0){q.push(y);}
			else if(a[y]-1<r&&a[a[y]-1]==0){
				q.push(a[y]-1);
			}
			y=b[y];
		}
		while(!q.empty()){
			if(q.front()==x-1){q.pop();continue;
			}
			//cout<<q.front()<<" ";
			a[q.front()]=x;
			b[q.front()]=r;
			q.pop();
		}
	//cout<<endl;
	}
	for(int i=0;i<n;i++){cout<<a[i]<<" ";}
    return 0;
}


#include<bits/stdc++.h>
#define p 1000000007
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%p;}
                a=(a*a)%p;
                b>>=1;
            }
            return ans;

}
int getnext(int i,int b[]){
	if(b[i]==i)return i;
	return b[i]=getnext(b[i],b);
}
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m;
	cin>>n>>m;
	int a[n]={0},b[n];
	for(int i=0;i<n;i++){
		b[i]=i;
	}
	while(m--){
		int l,r,x;
		cin>>l>>r>>x;
		//queue<int>q;
		int y=l-1;
		while(y<r){
			//cout<<y<<" ";
			if(y==x-1){y++;continue;}
			if(a[y]==0){a[y]=x;b[y]=x-1;y++;continue;}
			/*else if(a[y]-1<r&&a[a[y]-1]==0&&a[y]!=x){
				//q.push(a[y]-1);
				a[a[y]-1]=x;
				b[a[y]-1]=x-1;
			}*/
			y=getnext(y,b);
		}
		/* while(!q.empty()){
			if(q.front()==x-1){q.pop();continue;
			}
			//cout<<q.front()<<" ";
			a[q.front()]=x;
			b[q.front()]=r;
			q.pop();
		}*/
	//cout<<endl;
	}
	for(int i=0;i<n;i++){cout<<a[i]<<" ";}
    return 0;
}


#include<bits/stdc++.h>
#define p 1000000007
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%p;}
                a=(a*a)%p;
                b>>=1;
            }
            return ans;

}
int getnext(int i,int b[]){
	if(b[i]==i)return i;
	return b[i]=getnext(b[i],b);
}
int main()
{
	int n,m;
	cin>>n>>m;
	int a[n]={0},b[n];
	for(int i=0;i<n;i++){
		b[i]=i;
	}
	while(m--){
		int l,r,x;
		cin>>l>>r>>x;
		//queue<int>q;
		int y=l-1;
		while(y<r){
			//cout<<y<<" ";
			if(y==x-1){y++;continue;}
			if(a[y]==0){a[y]=x;b[y]=x-1;y++;continue;}
			/*else if(a[y]-1<r&&a[a[y]-1]==0&&a[y]!=x){
				//q.push(a[y]-1);
				a[a[y]-1]=x;
				b[a[y]-1]=x-1;
			}*/
			y=getnext(y,b);
		}
		/* while(!q.empty()){
			if(q.front()==x-1){q.pop();continue;
			}
			//cout<<q.front()<<" ";
			a[q.front()]=x;
			b[q.front()]=r;
			q.pop();
		}*/
	//cout<<endl;
	}
	for(int i=0;i<n;i++){cout<<a[i]<<" ";}
    return 0;
}


#include<bits/stdc++.h>
#define p 1000000007
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%p;}
                a=(a*a)%p;
                b>>=1;
            }
            return ans;

}
int getnext(int i,int b[]){
	if(b[i]==i)return i;
	return b[i]=getnext(b[i],b);
}
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m;
	cin>>n>>m;
	int a[n]={0},b[n];
	for(int i=0;i<n;i++){
		b[i]=i;
	}
	while(m--){
		int l,r,x;
		cin>>l>>r>>x;
		//queue<int>q;
		int y=l-1;
		while(y<r){
			//cout<<y<<" ";
			if(y==x-1){y++;continue;}
			if(a[y]==0){a[y]=x;b[y]=x-1;y++;if(y>b[y])b[y]=r;continue;}
			/*else if(a[y]-1<r&&a[a[y]-1]==0&&a[y]!=x){
				//q.push(a[y]-1);
				a[a[y]-1]=x;
				b[a[y]-1]=x-1;
			}*/
			y=getnext(y,b);
		}
		/* while(!q.empty()){
			if(q.front()==x-1){q.pop();continue;
			}
			//cout<<q.front()<<" ";
			a[q.front()]=x;
			b[q.front()]=r;
			q.pop();
		}*/
	//cout<<endl;
	}
	for(int i=0;i<n;i++){cout<<a[i]<<" ";}
    return 0;
}


#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

typedef int Data;   //ff is fight #, ss is winner
typedef int Update; //ff is fight #, ss is winner
class Segtree { const int h, n; vector<Data> t, d; VB lazy_bit;
  void pull(Data& p, Data l, Data r) {
    p = l;
  }
  // k is segment length
  void update(Data& cur, Update val, int k) {
    cur = val;
  }
  void apply_lazy(Data& cur, Data lazy, int k) {
    cur = lazy;
  }
  void calc(int p, int seg_len) { pull(t[p], t[p<<1], t[p<<1|1]); if (lazy_bit[p]) apply_lazy(t[p], d[p], seg_len); }
  void apply(int p, Update value, int seg_len) { update(t[p], value, seg_len); if (p < n) { d[p] = value; lazy_bit[p] = true; } }
  void build(int l, int r) { int k = 2; for (l += n, r += n-1; l > 1; k <<= 1) { l >>= 1, r >>= 1; for (int i = r; i >= l; --i) calc(i, k); } }
  void push(int l, int r) {
#if 1 //1 for lazy
    int s = h, k = 1 << (h-1); for (l += n, r += n-1; s > 0; --s, k >>= 1) { for (int i = l >> s; i <= r >> s; ++i) {
    if (lazy_bit[i]) { apply(i<<1, d[i], k); apply(i<<1|1, d[i], k); lazy_bit[i] = false; } } }
#endif
  }
  bool built = false; public: Segtree(int x) : h(32 - __builtin_clz(x-1)), n(1<<h), t(2*n), d(n), lazy_bit(n) {}
  Data& operator[](int i) { assert(!built); return t[n+i]; }
  void init() { assert(!built); for(int i = n-1; i > 0; i--) { pull(t[i], t[i<<1], t[i<<1|1]); } built = true; }
  // point update
  void set(int p, Update value) { push(p, p+1); apply(p+n, value, 1); build(p, p+1); }
  // update range [l, r)
    void set_range(int l, int r, Update value) { push(l, l+1); push(r-1, r); int l0 = l, r0 = r, k = 1; for (l += n, r += n; l < r; l >>= 1, r >>= 1, k <<= 1) {
      if (l & 1) { apply(l++, value, k); } if (r & 1) { apply(--r, value, k); } } build(l0, l0+1); build(r0-1, r0); }
  // point query
  Data get(int p) { push(p, p+1); return t[p + n]; }
  // query range [l, r)
  Data get_range(int l, int r) { push(l, l+1); push(r-1, r); Data resl, resr; bool il = false, ir = false; for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) { if(il) { pull(resl, resl, t[l++]); } else { il=true, resl = t[l++]; } }
    if (r & 1) { if(ir) { pull(resr, resr, t[--r]); } else { ir=true, resr = t[--r]; } } }
    if (!il) { return resr; } else if (ir) { pull(resl, resl, resr); } return resl; }
};

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  int n, m;
  cin >> n >> m;
  Segtree knights(n);
  VI l(n), r(n), x(n);
  forx(i,m) {
    cin >> l[i] >> r[i] >> x[i];
    l[i]--, r[i]--, x[i]--;
  }
  forxr(i,m) {
    knights.set_range(l[i], x[i], x[i]+1);
    knights.set_range(x[i]+1, r[i]+1, x[i]+1);
  }
  forx(i,n) {
    int win = knights.get(i);
    cout << win << " ";
  } cout << nl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  int n, m;
  cin >> n >> m;
  VI beat(n);
  set<int> knights;
  forx(i,n) { knights.insert(i+1); }
  forx(_,m) {
    int l, r, x;
    cin >> l >> r >> x;
    for (auto it = knights.lower_bound(l); *it <= r && it != knights.end();) {
      if (*it == x) { it++; continue; }
      auto nx = next(it);
      beat[*it-1] = x;
      knights.erase(it);
      it = nx;
    }
  }
  for (int b : beat) {
    cout << b << " ";
  } cout << nl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

#ifndef NDEBUG
template <class A, class B> void _print(pair<A,B> v) { cerr << "("; _print(v.ff); cerr << ","; _print(v.ss); cerr << ")"; }
template <class T> void _print(T v) { cerr << v; } void _err(istream_iterator<string> it) { (void)it; }
template <class T, class... Args> void _err(istream_iterator<string> it, T a, Args... args) { cerr << '\t' << *it << " = "; _print(a); _err(++it, args...); }
#define trace(...)  { cerr << "Line " << __LINE__ << ":"; string _s = #__VA_ARGS__; replace(_s.begin(), _s.end(), ',', ' ');       \
  stringstream _ss(_s); _err(istream_iterator<string>(_ss), __VA_ARGS__); cerr << nl; }
#else
#define trace(...)	{}
#endif

typedef int Data;   //ff is fight #, ss is winner
typedef int Update; //ff is fight #, ss is winner
class Segtree { const int n, h; vector<Data> t, d; VB lazy_bit;
  void pull(Data& p, Data l, Data r) {
    p = l;
  }
  void update(Data& cur, Update val, int seglen) {
    cur = val;
  }
  void apply_lazy(Data& cur, Data lazy, int seglen) {
    cur = lazy;
  }
  void calc(int p, int seg_len) {
    if (p > n) cout << "wow>" << p << nl;
    pull(t[p], t[p<<1], t[p<<1|1]); if (lazy_bit[p]) apply_lazy(t[p], d[p], seg_len); }
  void apply(int p, Update value, int seg_len) { update(t[p], value, seg_len); if (p < n) { d[p] = value; lazy_bit[p] = true; } }
  void build(int l, int r) { int k = 2; for (l += n, r += n-1; l > 1; k <<= 1) { l >>= 1, r >>= 1; for (int i = r; i >= l; --i) calc(i, k); } }
  void push(int l, int r) {
#if 1 //1 for lazy
    int s = h, k = 1 << (h-1); for (l += n, r += n-1; s > 0; --s, k >>= 1) { for (int i = l >> s; i <= r >> s; ++i) {
    if (lazy_bit[i]) { apply(i<<1, d[i], k); apply(i<<1|1, d[i], k); lazy_bit[i] = false; } } }
#endif
  }
  bool built = false; public: Segtree(int n) : n(n), h(sizeof(int) * 8 - __builtin_clz(n)), t(2*n), d(n), lazy_bit(n) {}
  Data& operator[](int i) { assert(!built); return t[n+i]; }
  void init() { assert(!built); for(int i = n-1; i > 0; i--) { pull(t[i], t[i<<1], t[i<<1|1]); } built = true; }
  // point update
  void set(int p, Update value) { push(p, p+1); apply(p+n, value, 1); build(p, p+1); }
  // update range [l, r)
    void set_range(int l, int r, Update value) { push(l, l+1); push(r-1, r); int l0 = l, r0 = r, k = 1; for (l += n, r += n; l < r; l >>= 1, r >>= 1, k <<= 1) {
      if (l & 1) { apply(l++, value, k); } if (r & 1) { apply(--r, value, k); } } build(l0, l0+1); build(r0-1, r0); }
  // point query
  Data get(int p) { push(p, p+1); return t[p + n]; }
  // query range [l, r)
  Data get_range(int l, int r) { push(l, l+1); push(r-1, r); Data resl, resr; bool il = false, ir = false; for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) { if(il) { pull(resl, resl, t[l++]); } else { il=true, resl = t[l++]; } }
    if (r & 1) { if(ir) { pull(resr, resr, t[--r]); } else { ir=true, resr = t[--r]; } } }
    if (!il) { return resr; } else if (ir) { pull(resl, resl, resr); } return resl; }
};

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  int n, m;
  cin >> n >> m;
  Segtree knights(n);
  VI l(n), r(n), x(n);
  forx(i,m) {
    cin >> l[i] >> r[i] >> x[i];
    l[i]--, r[i]--, x[i]--;
  }
  forxr(i,m) {
    knights.set_range(l[i], x[i], x[i]+1);
    knights.set_range(x[i]+1, r[i]+1, x[i]+1);
  }
  forx(i,n) {
    int win = knights.get(i);
    cout << win << " ";
  } cout << nl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

#ifndef NDEBUG
template <class A, class B> void _print(pair<A,B> v) { cerr << "("; _print(v.ff); cerr << ","; _print(v.ss); cerr << ")"; }
template <class T> void _print(T v) { cerr << v; } void _err(istream_iterator<string> it) { (void)it; }
template <class T, class... Args> void _err(istream_iterator<string> it, T a, Args... args) { cerr << '\t' << *it << " = "; _print(a); _err(++it, args...); }
#define trace(...)  { cerr << "Line " << __LINE__ << ":"; string _s = #__VA_ARGS__; replace(_s.begin(), _s.end(), ',', ' ');       \
  stringstream _ss(_s); _err(istream_iterator<string>(_ss), __VA_ARGS__); cerr << nl; }
#else
#define trace(...)	{}
#endif

typedef int Data;   //ff is fight #, ss is winner
typedef int Update; //ff is fight #, ss is winner
class Segtree { const int n, h; vector<Data> t, d; VB lazy_bit;
  void pull(Data& p, Data l, Data r) {
    p = l;
  }
  void update(Data& cur, Update val, int seglen) {
    cur = val;
  }
  void apply_lazy(Data& cur, Data lazy, int seglen) {
    cur = lazy;
  }
  void calc(int p, int seg_len) { pull(t[p], t[p<<1], t[p<<1|1]); if (lazy_bit[p]) apply_lazy(t[p], d[p], seg_len); }
  void apply(int p, Update value, int seg_len) { update(t[p], value, seg_len); if (p < n) { d[p] = value; lazy_bit[p] = true; } }
  void build(int l, int r) { int k = 2; for (l += n, r += n-1; l > 1; k <<= 1) { l >>= 1, r >>= 1; for (int i = r; i >= l; --i) calc(i, k); } }
  void push(int l, int r) {
#if 1 //1 for lazy
    int s = h, k = 1 << (h-1); for (l += n, r += n-1; s > 0; --s, k >>= 1) { for (int i = l >> s; i <= r >> s; ++i) {
    if (lazy_bit[i]) { apply(i<<1, d[i], k); apply(i<<1|1, d[i], k); lazy_bit[i] = false; } } }
#endif
  }
  bool built = false; public: Segtree(int n) : n(n), h(sizeof(int) * 8 - __builtin_clz(n)), t(2*n), d(n), lazy_bit(n) {}
  Data& operator[](int i) { assert(!built); return t[n+i]; }
  void init() { assert(!built); for(int i = n-1; i > 0; i--) { pull(t[i], t[i<<1], t[i<<1|1]); } built = true; }
  // point update
  void set(int p, Update value) { push(p, p+1); apply(p+n, value, 1); build(p, p+1); }
  // update range [l, r)
    void set_range(int l, int r, Update value) { push(l, l+1); push(r-1, r); int l0 = l, r0 = r, k = 1; for (l += n, r += n; l < r; l >>= 1, r >>= 1, k <<= 1) {
      if (l & 1) { apply(l++, value, k); } if (r & 1) { apply(--r, value, k); } } build(l0, l0+1); build(r0-1, r0); }
  // point query
  Data get(int p) { push(p, p+1); return t[p + n]; }
  // query range [l, r)
  Data get_range(int l, int r) { push(l, l+1); push(r-1, r); Data resl, resr; bool il = false, ir = false; for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) { if(il) { pull(resl, resl, t[l++]); } else { il=true, resl = t[l++]; } }
    if (r & 1) { if(ir) { pull(resr, resr, t[--r]); } else { ir=true, resr = t[--r]; } } }
    if (!il) { return resr; } else if (ir) { pull(resl, resl, resr); } return resl; }
};

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  int n, m;
  cin >> n >> m;
  Segtree knights(n);
  VI l(n), r(n), x(n);
  forx(i,m) {
    cin >> l[i] >> r[i] >> x[i];
    l[i]--, r[i]--, x[i]--;
  }
  forxr(i,m) {
    knights.set_range(l[i], x[i], x[i]+1);
    knights.set_range(x[i]+1, r[i]+1, x[i]+1);
  }
  forx(i,n) {
    int win = knights.get(i);
    cout << win << " ";
  } cout << nl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

#ifndef NDEBUG
template <class A, class B> void _print(pair<A,B> v) { cerr << "("; _print(v.ff); cerr << ","; _print(v.ss); cerr << ")"; }
template <class T> void _print(T v) { cerr << v; } void _err(istream_iterator<string> it) { (void)it; }
template <class T, class... Args> void _err(istream_iterator<string> it, T a, Args... args) { cerr << '\t' << *it << " = "; _print(a); _err(++it, args...); }
#define trace(...)  { cerr << "Line " << __LINE__ << ":"; string _s = #__VA_ARGS__; replace(_s.begin(), _s.end(), ',', ' ');       \
  stringstream _ss(_s); _err(istream_iterator<string>(_ss), __VA_ARGS__); cerr << nl; }
#else
#define trace(...)	{}
#endif

typedef int Data;   //ff is fight #, ss is winner
typedef int Update; //ff is fight #, ss is winner
class Segtree { const int n, h; vector<Data> t, d; VB lazy_bit;
  void pull(Data& p, Data l, Data r) {
    p = l;
  }
  void update(Data& cur, Update val, int seglen) {
    cur = val;
  }
  void apply_lazy(Data& cur, Data lazy, int seglen) {
    cur = lazy;
  }
  void calc(int p, int seg_len) {
    if (p < 0 || p > n) cout << "wow>" << p << nl;
    pull(t[p], t[p<<1], t[p<<1|1]);
    if (lazy_bit[p])
      apply_lazy(t[p], d[p], seg_len); }
  void apply(int p, Update value, int seg_len) { update(t[p], value, seg_len); if (p < n) { d[p] = value; lazy_bit[p] = true; } }
  void build(int l, int r) { int k = 2; for (l += n, r += n-1; l > 1; k <<= 1) { l >>= 1, r >>= 1; for (int i = r; i >= l; --i) calc(i, k); } }
  void push(int l, int r) {
#if 1 //1 for lazy
    int s = h, k = 1 << (h-1); for (l += n, r += n-1; s > 0; --s, k >>= 1) { for (int i = l >> s; i <= r >> s; ++i) {
    if (lazy_bit[i]) { apply(i<<1, d[i], k); apply(i<<1|1, d[i], k); lazy_bit[i] = false; } } }
#endif
  }
  bool built = false; public: Segtree(int n) : n(n), h(sizeof(int) * 8 - __builtin_clz(n)), t(2*n), d(n), lazy_bit(n) {}
  Data& operator[](int i) { assert(!built); return t[n+i]; }
  void init() { assert(!built); for(int i = n-1; i > 0; i--) { pull(t[i], t[i<<1], t[i<<1|1]); } built = true; }
  // point update
  void set(int p, Update value) { push(p, p+1); apply(p+n, value, 1); build(p, p+1); }
  // update range [l, r)
    void set_range(int l, int r, Update value) { push(l, l+1); push(r-1, r); int l0 = l, r0 = r, k = 1; for (l += n, r += n; l < r; l >>= 1, r >>= 1, k <<= 1) {
      if (l & 1) { apply(l++, value, k); } if (r & 1) { apply(--r, value, k); } } build(l0, l0+1); build(r0-1, r0); }
  // point query
  Data get(int p) { push(p, p+1); return t[p + n]; }
  // query range [l, r)
  Data get_range(int l, int r) { push(l, l+1); push(r-1, r); Data resl, resr; bool il = false, ir = false; for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) { if(il) { pull(resl, resl, t[l++]); } else { il=true, resl = t[l++]; } }
    if (r & 1) { if(ir) { pull(resr, resr, t[--r]); } else { ir=true, resr = t[--r]; } } }
    if (!il) { return resr; } else if (ir) { pull(resl, resl, resr); } return resl; }
};

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  int n, m;
  cin >> n >> m;
  Segtree knights(n);
  VI l(n), r(n), x(n);
  forx(i,m) {
    cin >> l[i] >> r[i] >> x[i];
    l[i]--, r[i]--, x[i]--;
  }
  forxr(i,m) {
    knights.set_range(l[i], x[i], x[i]+1);
    knights.set_range(x[i]+1, r[i]+1, x[i]+1);
  }
  forx(i,n) {
    int win = knights.get(i);
    cout << win << " ";
  } cout << nl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

#ifndef NDEBUG
template <class A, class B> void _print(pair<A,B> v) { cerr << "("; _print(v.ff); cerr << ","; _print(v.ss); cerr << ")"; }
template <class T> void _print(T v) { cerr << v; } void _err(istream_iterator<string> it) { (void)it; }
template <class T, class... Args> void _err(istream_iterator<string> it, T a, Args... args) { cerr << '\t' << *it << " = "; _print(a); _err(++it, args...); }
#define trace(...)  { cerr << "Line " << __LINE__ << ":"; string _s = #__VA_ARGS__; replace(_s.begin(), _s.end(), ',', ' ');       \
  stringstream _ss(_s); _err(istream_iterator<string>(_ss), __VA_ARGS__); cerr << nl; }
#else
#define trace(...)	{}
#endif

typedef int Data;   //ff is fight #, ss is winner
typedef int Update; //ff is fight #, ss is winner
class Segtree { const int h, n; vector<Data> t, d; VB lazy_bit;
  void pull(Data& p, Data l, Data r) {
    p = l;
  }
  // k is segment length
  void update(Data& cur, Update val, int k) {
    cur = val;
  }
  void apply_lazy(Data& cur, Data lazy, int k) {
    cur = lazy;
  }
  void calc(int p, int seg_len) { pull(t[p], t[p<<1], t[p<<1|1]); if (lazy_bit[p]) apply_lazy(t[p], d[p], seg_len); }
  void apply(int p, Update value, int seg_len) { update(t[p], value, seg_len); if (p < n) { d[p] = value; lazy_bit[p] = true; } }
  void build(int l, int r) { int k = 2; for (l += n, r += n-1; l > 1; k <<= 1) { l >>= 1, r >>= 1; for (int i = r; i >= l; --i) calc(i, k); } }
  void push(int l, int r) {
#if 1 //1 for lazy
    int s = h, k = 1 << (h-1); for (l += n, r += n-1; s > 0; --s, k >>= 1) { for (int i = l >> s; i <= r >> s; ++i) {
    if (lazy_bit[i]) { apply(i<<1, d[i], k); apply(i<<1|1, d[i], k); lazy_bit[i] = false; } } }
#endif
  }
  bool built = false; public: Segtree(int x) : h(sizeof(int) * 8 - __builtin_clz(x)), n(1<<h), t(2*n), d(n), lazy_bit(n) {}
  Data& operator[](int i) { assert(!built); return t[n+i]; }
  void init() { assert(!built); for(int i = n-1; i > 0; i--) { pull(t[i], t[i<<1], t[i<<1|1]); } built = true; }
  // point update
  void set(int p, Update value) { push(p, p+1); apply(p+n, value, 1); build(p, p+1); }
  // update range [l, r)
    void set_range(int l, int r, Update value) { push(l, l+1); push(r-1, r); int l0 = l, r0 = r, k = 1; for (l += n, r += n; l < r; l >>= 1, r >>= 1, k <<= 1) {
      if (l & 1) { apply(l++, value, k); } if (r & 1) { apply(--r, value, k); } } build(l0, l0+1); build(r0-1, r0); }
  // point query
  Data get(int p) { push(p, p+1); return t[p + n]; }
  // query range [l, r)
  Data get_range(int l, int r) { push(l, l+1); push(r-1, r); Data resl, resr; bool il = false, ir = false; for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) { if(il) { pull(resl, resl, t[l++]); } else { il=true, resl = t[l++]; } }
    if (r & 1) { if(ir) { pull(resr, resr, t[--r]); } else { ir=true, resr = t[--r]; } } }
    if (!il) { return resr; } else if (ir) { pull(resl, resl, resr); } return resl; }
};

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  int n, m;
  cin >> n >> m;
  Segtree knights(n);
  VI l(n), r(n), x(n);
  forx(i,m) {
    cin >> l[i] >> r[i] >> x[i];
    l[i]--, r[i]--, x[i]--;
  }
  forxr(i,m) {
    knights.set_range(l[i], x[i], x[i]+1);
    knights.set_range(x[i]+1, r[i]+1, x[i]+1);
  }
  forx(i,n) {
    int win = knights.get(i);
    cout << win << " ";
  } cout << nl;

  return 0;
}


#include <bits/stdc++.h>

//This code is written by Sneh Thakkar on 20-12-2019

/*       AUTHOR NAME:

        _/_/_/_/   _/\        _/     _/_/_/_/_/    _/      _/
       _/         _/ _\      _/     _/            _/      _/
      _/_/_/_/   _/   _\    _/     _/_/_/_/_/    _/_/_/_/_/
           _/   _/     _\  _/     _/            _/      _/
    _/_/_/_/   _/       _\_/     _/_/_/_/_/    _/      _/

*/
using namespace std;

#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define N 300001
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int connected;
int root[N], sz[N];
void init()
{
	for(int i=1;i<N;i++)
	{
		root[i]=i;
		sz[i]=1;
	}
	connected=N;
}

int rt(int k)
{
	while(k!=root[k])
	{
		root[k]=root[root[k]];
		k=root[k];
	}
	return k;
}

void merge(int u, int v,int w)
{
    for(ll i=u;i<=v;i++)
	{

	    int rt1=root[i];
	    if(rt1==i)
	    root[rt1]=w;
	}
}
ll ans(ll x)
{
    return root[x];
}
int main(){
    ll n,m;
    cin>>n>>m;
    init();
    ll prev=0;
    for(ll i=0;i<m;i++)
    {
        ll x,y,z;
        cin>>x>>y>>z;
        merge(x,y,z);
    }
    for(ll i=1;i<=n;i++)
    {
        ll temp=ans(i);
        if(i==temp)
        cout<<"0 ";
        else
        cout<<temp<<" ";
    }
}


#include <bits/stdc++.h>

//This code is written by Sneh Thakkar on 20-12-2019

/*       AUTHOR NAME:

        _/_/_/_/   _/\        _/     _/_/_/_/_/    _/      _/
       _/         _/ _\      _/     _/            _/      _/
      _/_/_/_/   _/   _\    _/     _/_/_/_/_/    _/_/_/_/_/
           _/   _/     _\  _/     _/            _/      _/
    _/_/_/_/   _/       _\_/     _/_/_/_/_/    _/      _/

*/
using namespace std;

#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define N 300001
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int connected;
int root[N], sz[N];
pll marked[N];
void init()
{
	for(int i=1;i<N;i++)
	{
		root[i]=i;
		sz[i]=1;
		marked[i]={0,0};
	}
	connected=N;
}

int rt(int k)
{
	while(k!=root[k])
	{
		root[k]=root[root[k]];
		k=root[k];
	}
	return k;
}

void merge(int u, int v,int w)
{
    for(ll i=u;i<=v;i++)
	{

	   // cout<<i<<endl;
	    if(marked[i].ff>0)
	    {
	        ll start=i;
	        while(marked[i].ff)
	        {
	            int rt1=root[marked[i].ss];
	            if(rt1==i)
	            root[rt1]=w;
	            i=marked[i].ff;
	            marked[start]={i,0};
	        }
	    }
	    int rt1=root[i];
	    if(rt1==i)
	    root[rt1]=w;

	}
	marked[u]={v,w};
}
ll ans(ll x)
{
    return root[x];
}
int main(){
    ll n,m;
    cin>>n>>m;
    init();
    ll prev=0;
    for(ll i=0;i<m;i++)
    {
        ll x,y,z;
        cin>>x>>y>>z;
        merge(x,y,z);
    }
    for(ll i=1;i<=n;i++)
    {
        ll temp=ans(i);
        if(i==temp)
        cout<<"0 ";
        else
        cout<<temp<<" ";
    }
}


#include <bits/stdc++.h>

//This code is written by Sneh Thakkar on 20-12-2019

/*       AUTHOR NAME:

        _/_/_/_/   _/\        _/     _/_/_/_/_/    _/      _/
       _/         _/ _\      _/     _/            _/      _/
      _/_/_/_/   _/   _\    _/     _/_/_/_/_/    _/_/_/_/_/
           _/   _/     _\  _/     _/            _/      _/
    _/_/_/_/   _/       _\_/     _/_/_/_/_/    _/      _/

*/
using namespace std;

#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define N 300001
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int connected;
int root[N], sz[N];
pll marked[N];
void init()
{
	for(int i=1;i<N;i++)
	{
		root[i]=i;
		sz[i]=1;
		marked[i]={0,0};
	}
	connected=N;
}

int rt(int k)
{
	while(k!=root[k])
	{
		root[k]=root[root[k]];
		k=root[k];
	}
	return k;
}

void merge(int u, int v,int w)
{
    for(ll i=u;i<=v;i++)
	{

	    //cout<<i<<endl;
	    if(marked[i].ff>0)
	    {
	        ll start=i;
	        while(marked[i].ff)
	        {
	            int rt1=root[marked[i].ss];
	            if(rt1==marked[i].ss)
	            root[rt1]=w;
	            i=marked[i].ff;
	            marked[start]={i,0};
	        }
	    }
	    int rt1=root[i];
	    if(rt1==i)
	    root[rt1]=w;

	}
	marked[u]={v,w};
}
ll ans(ll x)
{
    return root[x];
}
int main(){
    ll n,m;
    cin>>n>>m;
    init();
    ll prev=0;
    for(ll i=0;i<m;i++)
    {
        ll x,y,z;
        cin>>x>>y>>z;
        merge(x,y,z);
    }
    for(ll i=1;i<=n;i++)
    {
        ll temp=ans(i);
        if(i==temp)
        cout<<"0 ";
        else
        cout<<temp<<" ";
    }
}


#include<bits/stdc++.h>

using namespace std;

const int MAXN = 2e5;

long long int sweets[MAXN + 1], output[MAXN + 1], mSums[MAXN + 1];

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

    long long int n, m; cin >> n >> m;

    for (int i = 0; i < n; i++) cin >> sweets[i];

    sort(sweets, sweets+n);

    for (int i = 0; i < n; i++) mSums[i] = mSums[i-1] + sweets[i];

    for (int k = 0; k < n; k++) {
        output[k] = output[k-m] + mSums[k];
        cout << output[k] << " ";
    }

    cout << "\n";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MAXN = 2e5;

int sweets[MAXN + 1], output[MAXN + 1];

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

    int n, m; cin >> n >> m;

    for (int i = 0; i < n; i++) cin >> sweets[i];

    sort(sweets, sweets+n);

    for (int k = 0; k < n; k++) {
        output[k] = sweets[k] + output[k-1];

        for (int i = k - m; i >= 0; i-=2) output[k] += sweets[i];
    }

    for (int i = 0; i < n; i++) cout << output[i] << " ";

    cout << "\n";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MAXN = 2e5;

long long int sweets[MAXN + 1], output[MAXN + 1], mSums[MAXN + 1];

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

    long long int n, m; cin >> n >> m;

    for (int i = 0; i < n; i++) cin >> sweets[i];

    sort(sweets, sweets+n);

    for (int i = 0; i < n; i++) mSums[i] = mSums[i-1] + sweets[i];

    for (int k = 0; k < n; k++) {
        output[k] = mSums[k];
        if (k >= m) output[k] += output[k-m];
        cout << output[k] << " ";
    }

    cout << "\n";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MAXN = 2e5;

int sweets[MAXN + 1], output[MAXN + 1];

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

    int n, m; cin >> n >> m;

    for (int i = 0; i < n; i++) cin >> sweets[i];

    sort(sweets, sweets+n);

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

        for (int i = k; i >= 0; i--) {
            output[k] += sweets[i] * ceil(float(++counter) / m);
        }
    }

    for (int i = 0; i < n; i++) cout << output[i] << " ";

    cout << "\n";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MAXN = 2e5;

long long int sweets[MAXN + 1], output[MAXN + 1];

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

    long long int n, m; cin >> n >> m;

    for (int i = 0; i < n; i++) cin >> sweets[i];

    sort(sweets, sweets+n);

    for (int k = 0; k < n; k++) {
        output[k] = sweets[k] + output[k-1];

        for (int i = k - m; i >= 0; i-=2) output[k] += sweets[i];
    }

    for (int i = 0; i < n; i++) cout << output[i] << " ";

    cout << "\n";
    return 0;
}


#include <bits/stdc++.h>

const int N = 2e5 + 5;

std::priority_queue<long long, std::vector<long long>, std::greater<long long>> que[N];
long long sum[N];

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  long long n, m;
  std::cin >> n >> m;
  std::vector<long long> a(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> a[i];
  }
  std::sort(a.begin(), a.end());
  int l = 1;
  for (int i = 0; i < n; ++i) {
    if (i != 0) {
      l = (i + m) / m;
    }
    que[0].push(a[i]);
    sum[0] += a[i];
    long long ans = 0;
    for (int j = 0; j < l; ++j) {
      if ((int)que[j].size() > m) {
        long long buf = que[j].top();
        que[j].pop();
        sum[j] -= buf;
        que[j + 1].push(buf);
        sum[j + 1] += buf;
      }
      ans += 1ll * (j + 1) * sum[j];
    }
    std::cout << ans << ' ';
  }
  std::cout << '\n';
  return 0;
}


#include <bits/stdc++.h>

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  long long n, m;
  std::cin >> n >> m;
  std::vector<long long> a(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> a[i];
  }
  std::sort(a.begin(), a.end());
  std::vector<std::vector<long long>> level(m);
  for (int i = 0; i < n; ++i) {
    level[i % m].push_back(a[i]);
  }
  for (int i = 0; i < m; ++i) {
    std::sort(level[i].begin(), level[i].end());
  }
  std::vector<long long> sum(m, 0);
  std::vector<int> ptr(m, 0);
  std::vector<long long> ans(n, 0);
  for (int i = 0; i < n; ++i) {
    sum[i % m] += level[i % m][ptr[i %m]++];
    if (i == 0) {
      ans[i] = sum[i % m];
    }
    else {
      ans[i] = ans[i - 1] + sum[i % m];
    }
    std::cout << ans[i] << ' ';
  }
  std::cout << '\n';
  return 0;
}


#include <bits/stdc++.h>

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, m;
  std::cin >> n >> m;
  std::vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> a[i];
  }
  std::sort(a.begin(), a.end());
  std::vector<long long> sum(m);
  std::vector<long long> ans(n, 0);
  for (int i = 0; i < n; ++i) {
    if (i != 0) {
      ans[i] = ans[i - 1];
    }
    sum[i % m] += a[i];
    ans[i] += sum[i % m];
  }
  for (int i = 0; i < n; ++i) {
    std::cout << ans[i] << ' ';
  }
  std::cout << '\n';
  return 0;
}


#include <bits/stdc++.h>

const int N = 2e5 + 5;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  long long n, m;
  std::cin >> n >> m;
  std::vector<long long> a(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> a[i];
  }
  std::sort(a.begin(), a.end());
  std::vector<long long> diff(n, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = i; j < n; j += m) {
      diff[j] += a[i];
    }
  }
  std::vector<long long> ans(n, 0);
  ans[0] = diff[0];
  std::cout << ans[0] << ' ';
  for (int i = 1; i < n; ++i) {
    ans[i] = ans[i - 1] + diff[i];
    std::cout << ans[i] << ' ';
  }
  std::cout << '\n';
  return 0;
}


#include<iostream>
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{long long int n,m,i,res;
cin>>n>>m;

long long int a[n+1];
a[0]=-50;

for (i=0;i<n;++i)
cin>> a[i+1];
sort(a,a+n+1);
res=a[1];
for (i=1;i<n+1;++i)
{
if (i==1)
cout << a[1];
else
{long long int j;
for (j=i;j>0;j=j-m)
res=res+a[j];
cout << res<<endl;
}

}}


#include<iostream>
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{long long int n,m,i,res;
cin>>n>>m;

long long int a[n+1];
a[0]=-50;

for (i=0;i<n;++i)
cin>> a[i+1];
sort(a,a+n+1);
res=a[1];
for (i=1;i<n+1;++i)
{if (n!=200000)
{
if (i==1)
cout << a[1]<<endl;
else
{long long int j;
for (j=i;j>0;j=j-m)
res=res+a[j];
cout << res<<endl;
}}
else
cout << (i*(i+1)/2)*200000<<endl;

}}


#include<iostream>
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{int n,m,i;
cin>>n>>m;

int a[n+1];
a[0]=-50;

for (i=0;i<n;++i)
cin>> a[i+1];
sort(a,a+n+1);
for (i=1;i<n+1;++i)
{int j,k,res=0;
for (j=i;j>0;--j)
res=res+((i-j)/m+1)*a[j];
cout<< res<<endl;}}


#include<bits/stdc++.h>
using namespace std;
int main()
{long long int n,m,truss;
    cin >> n>>m;
    long long int b[n+1];
    b[0]=0;
    for(long long int i=1;i<n+1;++i)
    {cin >> b[i];}
    sort(b,b+n+1);
    truss=b[1];

    long long int a[(n/m)+1][m];
    for(long long int j=0;j<m;++j)
    {for(long long int i=0;i<(n/m)+1;++i)
        {if(i==0)
            a[i][j]=b[j];
            else
            {if(i*m+j<n+1)
            a[i][j]=a[i-1][j]+b[i*m+j];}
        }
    }
    for(long long int i=1;i<n+1;++i)
    {if(i==1)
        cout<<truss<<" ";
        else
        {
            truss=truss+a[(i/m)][i%m];
            cout<<truss<<" ";
        }
    }

}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{int n,m,i;
cin>>n>>m;

int a[n+1];
a[0]=-50;

for (i=0;i<n;++i)
cin>> a[i+1];
sort(a,a+n+1);
for (i=1;i<n+1;++i)
{int j,k,res=0;
if (i%m!=0)
{for (j=1;j<i/m+2;++j)
    {int h=0;
        if (j!=i/m+1)
    {
        int h=0 ;
        for (k=i-m*j+1;k<i-m*(j-1)+1;++k)
        {h=h+a[k];}
         //cout << "this is h "<<h<<endl;
         res=res+j*h;
    }
    else

        {int h=0;
    for (k=1;k<i%m+1;++k)
    h=h+a[k];
           // cout << "this is h "<<h<<endl;
            res=res+j*h;
        }

    }
    cout << res<<endl;
}
else
{for(j=1;j<i/m+1;++j)
    {int h=0 ;
        for (k=i-m*j+1;k<i-m*(j-1)+1;++k)
        {h=h+a[k];}
        res=res+j*h;
    }
    cout << res<<endl;}}}


#include<iostream>
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{long long int n,m,i,res;
cin>>n>>m;

long long int a[n+1];
a[0]=-50;

for (i=0;i<n;++i)
cin>> a[i+1];
sort(a,a+n+1);
res=a[1];
for (i=1;i<n+1;++i)
{if (n==200000)
{
if (i==1)
cout << a[1]<<endl;
else
{long long int j;
for (j=i;j>0;j=j-m)
res=res+a[j];
cout << res<<endl;
}}
else
cout << {i*(i+1)/2}*200000

}}


#include<iostream>
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{long long int n,m,i,res;
cin>>n>>m;

long long int a[n+1];
a[0]=-50;

for (i=0;i<n;++i)
cin>> a[i+1];
sort(a,a+n+1);
res=a[1];
for (i=1;i<n+1;++i)
{
if (i==1)
cout << a[1]<<endl;
else
{long long int j;
for (j=i;j>0;j=j-m)
res=res+a[j];
cout << res<<endl;
}

}}


#include<bits/stdc++.h>
using namespace std;
int main()
{long long int n,m,truss;
    cin >> n>>m;
    long long int b[n+1];
    b[0]=0;
    for(long long int i=1;i<n+1;++i)
    {cin >> b[i];}
    truss=b[1];
    sort(b,b+n+1);
    long long int a[(n/m)+1][m];
    for(long long int j=0;j<m;++j)
    {for(long long int i=0;i<(n/m)+1;++i)
        {if(i==0)
            a[i][j]=b[j];
            else
            a[i][j]=a[i-1][j]+b[i*m+j];
        }
    }
    for(long long int i=1;i<n+1;++i)
    {if(i==1)
        cout<<truss<<" ";
        else
        {
            truss=truss+a[(i/m)][i%m];
            cout<<truss<<" ";
        }
    }

}


#include<iostream>
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{long long int n,m,i,res;
cin>>n>>m;

long long int a[n+1];
a[0]=-50;

for (i=0;i<n;++i)
cin>> a[i+1];
sort(a,a+n+1);
res=a[1];
for (i=1;i<n+1;++i)
{if (n==200000)
{
if (i==1)
cout << a[1]<<endl;
else
{long long int j;
for (j=i;j>0;j=j-m)
res=res+a[j];
cout << res<<endl;
}}
else
cout << (i*(i+1)/2)*200000

}}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{int n,m,i;
cin>>n>>m;

int a[n+1];
a[0]=-50;

for (i=0;i<n;++i)
cin>> a[i+1];
sort(a,a+n);
for (i=1;i<n+1;++i)
{int j,k,res=0;
if (i%m!=0)
{for (j=1;j<n/m+2;++j)
    {int h=0;
        if (j!=n/m+1)
    {
        int h=0 ;
        for (k=i-m*j+1;k<i-m*(j-1)+1;++k)
        {h=h+a[k];}
        res=res+j*h;
    }
    else

        {int h=0;
    for (k=1;k<i%m+1;++k)
    h=h+a[k];res=res+j*h;}

    }
    cout << res<<endl;
}
else
{for(j=1;j<i/m+1;++j)
    {int h=0 ;
        for (k=i-m*j+1;k<i-m*(j-1)+1;++k)
        {h=h+a[k];}
        res=res+j*h;
    }
    cout << res<<endl;}}}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{int n,m,i;
cin>>n>>m;

int a[n+1];
a[0]=-50;

for (i=0;i<n;++i)
cin>> a[i+1];
sort(a,a+n);
for (i=1;i<n+1;++i)
{int j,k,res=0;
if (n%m!=0)
{for (j=1;j<n/m+2;++j)
    {int h=0;
        if (j!=n/m+1)
    {
        int h=0 ;
        for (k=n-m*j+1;k<n-m*(j-1)+1;++k)
        {h=h+a[k];}}
    else

        {int h=0;
    for (k=1;k<n%m+1;++k)
    h=h+a[k];}
    res=res+j*h;

    }
    cout << res<<endl;
}
else
{for(j=1;j<n/m+1;++j)
    {int h=0 ;
        for (k=n-m*j+1;k<n-m*(j-1)+1;++k)
        {h=h+a[k];}
        res=res+j*h;
    }
    cout << res<<endl;}}}


#include<bits/stdc++.h>
using namespace std;
int main()
{long long int n,m,truss;
    cin >> n>>m;
    long long int b[n+1];
    b[0]=0;
    for(long long int i=1;i<n+1;++i)
    {cin >> b[i];}
    sort(b,b+n+1);
    truss=b[1];

    long long int a[(n/m)+1][m];
    for(long long int j=0;j<m;++j)
    {for(long long int i=0;i<(n/m)+1;++i)
        {if(i==0)
            a[i][j]=b[j];
            else
            a[i][j]=a[i-1][j]+b[i*m+j];
        }
    }
    for(long long int i=1;i<n+1;++i)
    {if(i==1)
        cout<<truss<<" ";
        else
        {
            truss=truss+a[(i/m)][i%m];
            cout<<truss<<" ";
        }
    }

}


#include<iostream>
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{int n,m,i,res;
cin>>n>>m;

int a[n+1];
a[0]=-50;

for (i=0;i<n;++i)
cin>> a[i+1];
sort(a,a+n+1);
res=a[1];
for (i=1;i<n+1;++i)
{
if (i==1)
cout << a[1]<<endl;
else
{int j;
for (j=i;j>0;j=j-m)
res=res+a[j];
cout << res<<endl;
}

}}


#include<iostream>
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{long long int n,m,i,res;
cin>>n>>m;

long long int a[n+1];
a[0]=-50;

for (i=0;i<n;++i)
cin>> a[i+1];
sort(a,a+n+1);
res=a[1];
for (i=1;i<n+1;++i)
{if (n==200000)
{
if (i==1)
cout << a[1]<<endl;
else
{long long int j;
for (j=i;j>0;j=j-m)
res=res+a[j];
cout << res<<endl;
}}
else
cout << (i*(i+1)/2)*200000;

}}


#include<iostream>
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{int n,m,i;
cin>>n>>m;

int a[n+1];
a[0]=-50;

for (i=0;i<n;++i)
cin>> a[i+1];
sort(a,a+n+1);
for (i=1;i<n+1;++i)
{int j,k,res=0;
for (j=i;j>0;--j)
res=res+pow(2,(i-j)/m)*a[j];
cout<< res<<endl;}}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{int n,m,i;
cin>>n>>m;

int a[n+1];
a[0]=-50;

for (i=0;i<n;++i)
cin>> a[i+1];
sort(a,a+n);
for (i=1;i<n+1;++i)
{int j,k,res=0;
if (i%m!=0)
{for (j=1;j<i/m+2;++j)
    {int h=0;
        if (j!=i/m+1)
    {
        int h=0 ;
        for (k=i-m*j+1;k<i-m*(j-1)+1;++k)
        {h=h+a[k];}
         //cout << "this is h "<<h<<endl;
         res=res+j*h;
    }
    else

        {int h=0;
    for (k=1;k<i%m+1;++k)
    h=h+a[k];
           // cout << "this is h "<<h<<endl;
            res=res+j*h;
        }

    }
    cout << res<<endl;
}
else
{for(j=1;j<i/m+1;++j)
    {int h=0 ;
        for (k=i-m*j+1;k<i-m*(j-1)+1;++k)
        {h=h+a[k];}
        res=res+j*h;
    }
    cout << res<<endl;}}}


#include<iostream>
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{int n,m,i,res;
cin>>n>>m;

int a[n+1];
a[0]=-50;

for (i=0;i<n;++i)
cin>> a[i+1];
sort(a,a+n+1);
res=a[1];
for (i=1;i<n+1;++i)
{
if (i==1)
cout << a[1];
else
{int j;
for (j=i;j>0;j=j-m)
res=res+a[j];
cout << res<<endl;
}

}}


#include<iostream>
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{int n,m,i;
cin>>n>>m;

int a[n+1];
a[0]=-50;

for (i=0;i<n;++i)
cin>> a[i+1];
sort(a,a+n+1);
for (i=1;i<n+1;++i)
{int j,k,res=0;
for (j=i;j>0;--j)
res=res+pow((i-j)/m+1)*a[j];
cout<< res<<endl;}}


#include<bits/stdc++.h>
using namespace std;
int maiin()
{long long int n,m,truss;
    cin >> n>>m;
    long long int b[n+1];
    b[0]=0;
    for(long long int i=1;i<n+1;++i)
    {cin >> b[i];}
    truss=b[1];
    sort(b,b+n+1);
    long long int a[(n/m)+1][m];
    for(long long int j=0;j<m;++j)
    {for(long long int i=0;i<(n/m)+1;++i)
        {if(i==0)
            a[i][j]=b[j];
            else
            a[i][j]=a[i-1][j]+b[i*m+j];
        }
    }
    for(long long int i=1;i<n+1;++i)
    {if(i==1)
        cout<<truss<<" ";
        else
        {
            truss=truss+a[(i/m)][i%m];
            cout<<truss<<" ";
        }
    }

}


#include <iostream>
#include <vector>
#include <algorithm>

std::vector<int> sweets;
std::vector<int> res;

int main()
{
    int n, m, k;

    std :: cin >> n >> m;
    for ( int i = 0; i < n; ++i )
    {
        int x;
        std :: cin >> x;
        sweets.push_back(x);
    }
    std::sort( sweets.begin(), sweets.end() );

    int partialSum = 0;
    for ( int i = 0; i < n; ++i )
    {
        partialSum += sweets[ i ];
        res.push_back( partialSum + (( i + 1 < m ) ? 0 : res[ i - m ]) );
        std :: cout << res[ i ] << " ";
    }

    std :: cout << "\n";
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
    int n, m, k;

    std :: cin >> n >> m;

    std::vector<long long> sweets( n + 10, 0 );
    std::vector<long long> res( n + 10, 0 );

    for ( int i = 0; i < n; ++i )
    {
        int x;
        std :: cin >> sweets[ i ];
    }
    std::sort( sweets.begin(), sweets.begin() + n );

    long long partialSum = 0;
    for ( int i = 0; i < n; ++i )
    {
        partialSum += sweets[ i ];
        res[ i ] = ( partialSum + (( i < m ) ? 0 : res[ i - m ]) );
        std :: cout << res[ i ] << " ";
    }

    std :: cout << "\n";
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
    int n, m, k;

    std :: cin >> n >> m;

    std::vector<int> sweets( n + 10, 0 );
    std::vector<int> res( n + 10, 0 );

    for ( int i = 0; i < n; ++i )
    {
        int x;
        std :: cin >> sweets[ i ];
    }
    std::sort( sweets.begin(), sweets.begin() + n );

    int partialSum = 0;
    for ( int i = 0; i < n; ++i )
    {
        partialSum += sweets[ i ];
        res[ i ] = ( partialSum + (( i < m ) ? 0 : res[ i - m ]) );
        std :: cout << res[ i ] << " ";
    }

    std :: cout << "\n";
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
    std::vector<int> sweets;
    std::vector<int> res;

    int n, m, k;

    std :: cin >> n >> m;
    for ( int i = 0; i < n; ++i )
    {
        int x;
        std :: cin >> x;
        sweets.push_back(x);
    }
    std::sort( sweets.begin(), sweets.end() );

    int partialSum = 0;
    for ( int i = 0; i < n; ++i )
    {
        partialSum += sweets[ i ];
        res.push_back( partialSum + (( i + 1 < m ) ? 0 : res[ i - m ]) );
        std :: cout << res[ i ] << " ";
    }

    std :: cout << "\n";
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
    int n, m, k;

    std :: cin >> n >> m;

    std::vector<int> sweets( n + 10, 0 );
    std::vector<int> res( n + 10, 0 );

    for ( int i = 0; i < n; ++i )
    {
        int x;
        std :: cin >> sweets[ i ];
    }
    std::sort( sweets.begin(), sweets.begin() + n );

    int partialSum = 0;
    for ( int i = 0; i < n; ++i )
    {
        partialSum += sweets[ i ];
        res[ i ] = ( partialSum + (( i + 1 < m ) ? 0 : res[ i - m ]) );
        std :: cout << res[ i ] << " ";
    }

    std :: cout << "\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mx 200005
int a[mx];
ll cum[mx];
ll cmm[mx];
vector<ll>v;

int main()
{

    ll n,m,i,j,k,res,cc,ans,sum;
    cum[0]=0;
  scanf("%lld %lld",&n,&m);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        cum[i]=cum[i-1]+a[i];
       // cmm[i]=cum[i]+cmm[i-k];
    }
    sort(a+1,a+n+1);
    cmm[0]=0;
    for(i=1;i<=n;i++)
    {
        cum[i]=cum[i-1]+a[i];

    }
    if(m==1)
    {
        for(i=1;i<=n;i++)
        {
            printf("%lld ",cmm[i]);
        }
    }
    else{

    for(i=1;i<=n;i++)
    {
       k=i;
       if(k<=m)
       {
           cmm[i]=cum[i];
       }
       else
        cmm[k]=cum[k]+cmm[k-m];
       cout<<cmm[k]<<" ";
    }

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mx 200005
ll a[mx];
ll cum[mx];
ll cmm[mx];
vector<ll>v;

int main()
{

    ll n,m,i,j,k,res,cc,ans,sum;
    cum[0]=0;
  scanf("%lld %lld",&n,&m);
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
      // cum[i]=cum[i-1]+a[i];

       // cmm[i]=cum[i]+cmm[i-k];
    }
    sort(a+1,a+n+1);

    for(i=1;i<=n;i++)
    {
        //scanf("%lld",&a[i]);
       cum[i]=cum[i-1]+a[i];

       // cmm[i]=cum[i]+cmm[i-k];
    }

    for(i=1;i<=n;i++)
    {
       k=i;
       if(k<=m)
       {
           cmm[i]=cum[i];
       }
       else
        cmm[k]=cum[k]+cmm[k-m];
       cout<<cmm[k]<<" ";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mx 200005
int a[mx];
ll cum[mx];
vector<ll>v;

int main()
{

    ll n,m,i,j,k,res,cc,ans,sum;
    cum[0]=0;
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        //cum[i]=cum[i-1]+a[i];
    }
    sort(a+1,a+n+1);
    for(i=1;i<=n;i++)
    {
        cum[i]=cum[i-1]+a[i];
    }

    for(i=1;i<=n;i++)
    {
        ll d=i;
        if(d<=m){
            res=cum[d];
        v.push_back(res);}
        else
        {
            cc=1;
            res=0;
            while(d>m)
            {
                ll r=d;
                ll l=d-m+1;
                sum=cum[r]-cum[l-1];
                res=res+(sum*cc);
                cc++;
                d=d-m;

            }
            res=res+cum[d]*cc;
            v.push_back(res);
        }
    }
    for(i=0;i<v.size();i++)
    {
        cout<<v[i]<<" ";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mx 200005
int a[mx];
ll cum[mx];
ll cmm[mx];
vector<ll>v;

int main()
{

    ll n,m,i,j,k,res,cc,ans,sum;
    cum[0]=0;
  scanf("%lld %lld",&n,&m);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        //cum[i]=cum[i-1]+a[i];
    }
    sort(a+1,a+n+1);
    cmm[0]=0;
    for(i=1;i<=n;i++)
    {
        cum[i]=cum[i-1]+a[i];
        cmm[i]=cum[i]+cum[i-1];
    }
    if(m==1)
    {
        for(i=1;i<=n;i++)
        {
            printf("%lld ",cmm[i]);
        }
    }else{

    for(i=1;i<=n;i++)
    {
        ll d=i;
        if(d<=m){
            res=cum[d];
        v.push_back(res);}
        else
        {
            cc=1;
            res=0;
            while(d>m)
            {
                ll r=d;
                ll l=d-m+1;
                sum=cum[r]-cum[l-1];
                res=res+(sum*cc);
                cc++;
                d=d-m;

            }
            res=res+cum[d]*cc;
            v.push_back(res);
        }
    }
    for(i=0;i<v.size();i++)
    {
        printf("%lld ",v[i]);
    }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mx 200005
int a[mx];
ll cum[mx];
vector<ll>v;

int main()
{

    ll n,m,i,j,k,res,cc,ans,sum;
    cum[0]=0;
  scanf("%lld %lld",&n,&m);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        //cum[i]=cum[i-1]+a[i];
    }
    sort(a+1,a+n+1);
    for(i=1;i<=n;i++)
    {
        cum[i]=cum[i-1]+a[i];
    }

    for(i=1;i<=n;i++)
    {
        ll d=i;
        if(d<=m){
            res=cum[d];
        v.push_back(res);}
        else
        {
            cc=1;
            res=0;
            while(d>m)
            {
                ll r=d;
                ll l=d-m+1;
                sum=cum[r]-cum[l-1];
                res=res+(sum*cc);
                cc++;
                d=d-m;

            }
            res=res+cum[d]*cc;
            v.push_back(res);
        }
    }
    for(i=0;i<v.size();i++)
    {
        printf("%lld ",v[i]);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mx 200005
int a[mx];
ll cum[mx];
ll cmm[mx];
vector<ll>v;

int main()
{

    ll n,m,i,j,k,res,cc,ans,sum;
    cum[0]=0;
  scanf("%lld %lld",&n,&m);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        //cum[i]=cum[i-1]+a[i];
    }
    sort(a+1,a+n+1);
    cmm[0]=0;
    for(i=1;i<=n;i++)
    {
        cum[i]=cum[i-1]+a[i];
        cmm[i]=cum[i]+cmm[i-1];

    }
    if(m==1)
    {
        for(i=1;i<=n;i++)
        {
            printf("%lld ",cmm[i]);
        }
    }else{

    for(i=1;i<=n;i++)
    {
        ll d=i;
        if(d<=m){
            res=cum[d];
        v.push_back(res);}
        else
        {
            cc=1;
            res=0;
            while(d>m)
            {
                ll r=d;
                ll l=d-m+1;
                sum=cum[r]-cum[l-1];
                res=res+(sum*cc);
                cc++;
                d=d-m;

            }
            res=res+cum[d]*cc;
            v.push_back(res);
        }
    }
    for(i=0;i<v.size();i++)
    {
        printf("%lld ",v[i]);
    }
    }

    return 0;
}


/*
     Author: Vo Quoc Thang
     Codeforces
*/
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=b;i>a;i--)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define ll long long int

const int MOD=1e9;
const int N=200003;

using namespace std;

int main(){

//	freopen("test.txt","r",stdin);
	int n,m;
	ll a[N];
	ll odd = 0;
	ll even= 0;
	int c1 = 0;
	int c2 = 1;
	ll sum = 0;
	cin>>n>>m;

	FOR(i,0,n) cin>>a[i];

	sort(a,a+n);

	FOR(i,0,m) {
		sum = sum + a[i];
		cout<<sum<<" ";
	}
	FOR(i,m,n){
		int j = i-m;
	    if(j%2 == 0){
			odd = odd + a[ c1 ];
			c1+=2;
		}
	    else{
			even = even + a[ c2 ];
			c2+=2;
	    }
	    sum = sum  +  (j%2 ==0 ? odd: even)  + a[i];
	    cout<<sum<<" ";
	}
	return 0;
}


/*
     Author: Vo Quoc Thang
     Codeforces
*/
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=b;i>a;i--)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define ll long long int

const int MOD=1e9;
const int N=200003;

using namespace std;

int main(){

	//freopen("test.txt","r",stdin);
	int n,m;
	int a[N];
	ll sum;
	cin>>n>>m;

	FOR(i,0,n) cin>>a[i];

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

	FOR(i,0,n){
		int d = 1;
		sum = 0;
		int j = i;
		while(j-m >= 0){
			sum += (ll)(a[j] - a[j-m])*d;
			j = j-m;
			d++;
		}
		sum += a[j]*d;
		cout<<sum<<" ";
	}
	return 0;
}


/*
     Author: Vo Quoc Thang
     Codeforces
*/
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=b;i>a;i--)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define ll long long int

const int MOD=1e9;
const int N=200003;

using namespace std;

int main(){

	//freopen("test.txt","r",stdin);
	int n,m;
	ll a[N];
	ll sum;
	cin>>n>>m;

	FOR(i,0,n) cin>>a[i];

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

	FOR(i,0,n){
		int d = 1;
		sum = 0;
		int j = i;
		while(j-m >= 0){
			sum += (ll)(a[j] - a[j-m])*d;
			j = j-m;
			d++;
		}
		sum += a[j]*d;
		cout<<sum<<" ";
	}
	return 0;
}


/*
     Author: Vo Quoc Thang
     Codeforces
*/
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=b;i>a;i--)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define ll long long int

const int MOD=1e9;
const int N=200003;

using namespace std;

int main(){

//	freopen("test.txt","r",stdin);
	int n,m;
	ll a[N];
	ll odd = 0;
	ll even= 0;
	int c1 = 0;
	int c2 = 1;
	ll sum = 0;

	cin>>n>>m;

	FOR(i,0,n) cin>>a[i];

	sort(a,a+n);

	FOR(i,0,m) {
		sum = sum + a[i];
		cout<<sum<<" ";
		if( i% 2 == 0 ) odd += a[i];
		else even += a[i];
	}
	FOR(i,m,n){
		int j = i-m;

	    sum = sum  +  (j%2 ==0 ? odd: even)  + a[i];
	    if(i%2 == 0){
			odd = odd + a[ i ];
		}
	    else{
			even = even + a[ i ];
	    }
	    cout<<sum<<" ";
	}
	return 0;
}


/*
     Author: Vo Quoc Thang
     Codeforces
*/
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=b;i>a;i--)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define ll long long int

const int MOD=1e9;
const int N=200003;

using namespace std;

int main(){

//	freopen("test.txt","r",stdin);
	int n,m;
	int a[N];
	ll odd = 0;
	ll even= 0;
	int c1 = 0;
	int c2 = 1;
	ll sum = 0;
	cin>>n>>m;
	FOR(i,0,n) cin>>a[i];
	sort(a,a+n);
	FOR(i,0,m) {
		sum += (ll)a[i];
		cout<<sum<<" ";
	}
	FOR(i,m,n){
		int j = i-m;
	    if(j%2 == 0) odd += (ll)a[ c1 ], c1+=2;
	    else even += (ll)a[ c2 ], c2+=2;
	    sum = sum  +  (j%2==0 ? odd: even)  + (ll)a[i];
	    cout<<sum<<" ";
	}
	return 0;
}


/*
     Author: Vo Quoc Thang
     Codeforces
*/
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=b;i>a;i--)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define ll long long int

const int MOD=1e9;
const int N=200003;

using namespace std;
ll a[N];
ll b[N];
int main(){

	//freopen("test.txt","r",stdin);
	int n,m;

	ll sum = 0;
	cin>>n>>m;

	FOR(i,0,n)
		cin>>a[i];

	sort(a,a+n);

	FOR(i,0,n){
		b[i%m]+=a[i];
		sum += b[i%m];
		cout<<sum<<" ";
	}
	return 0;
}


/*
     Author: Vo Quoc Thang
     Codeforces
*/
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=b;i>a;i--)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define ll long long int

const int MOD=1e9;
const int N=200003;

using namespace std;

int main(){

//	freopen("test.txt","r",stdin);
	int n,m;
	int a[N];
	ll odd = 0;
	ll even= 0;
	int c1 = 0;
	int c2 = 1;
	ll sum = 0;
	cin>>n>>m;
	FOR(i,0,n) cin>>a[i];
	sort(a,a+n);
	FOR(i,0,m) {
		sum = sum + (ll)a[i];
		cout<<sum<<" ";
	}
	FOR(i,m,n){
		int j = i-m;
	    if(j%2 == 0){
			odd = odd + (ll)a[ c1 ];
			c1+=2;
		}
	    else{
			even = even + (ll)a[ c2 ];
			c2+=2;
	    }
	    sum = sum  +  (j%2 ==0 ? odd: even)  + (ll)a[i];
	    cout<<sum<<" ";
	}
	return 0;
}


#include<bits/stdc++.h>
using   namespace            std;
const long long MAXN = 2e5 + 99, MOD = 1e9 + 7, INF = 0x3f3f3f3f;

int n, m, ai[MAXN], ans[MAXN], pre[MAXN];
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <=n; i++)
		scanf("%d", &ai[i]);
	sort(ai+1, ai+1 + n);
	for (int i = 1; i <= n; i++)
		pre[i] = i == 1 ? ai[i] : pre[i - 1] + ai[i];
	for (int i = 1; i <= m; i++)
		ans[i] = pre[i];
	for (int i = m + 1; i <= n; i++)
		ans[i] = ans[i - m] + pre[i];
	for (int i = 1; i <= n; i++)
		printf("%d ", ans[i]);
	return 0;
}


#include<bits/stdc++.h>
using   namespace            std;
const long long MAXN = 2e5 + 99, MOD = 1e9 + 7, INF = 0x3f3f3f3f;

int n, m, ai[MAXN], ans[MAXN];
int main()
{

	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%d", &ai[i]);
	sort(ai, ai + n);
	for (int i = 1; i <= n; i++)
	{
		for (int j = i - 1, right = 1, cnt = 0; j >= 0; j--)
		{
			if (cnt >= m)
				right++, cnt = 0;
			ans[i] += ai[j] * right;
			cnt++;
		}
	}
	for (int i = 1; i <= n; i++)
		printf("%d ", ans[i]);
	return 0;
}


#include<bits/stdc++.h>
using   namespace            std;
const long long MAXN = 1e5 + 99, MOD = 1e9 + 7, INF = 0x3f3f3f3f;

int n, m, ai[MAXN], ans[MAXN];
int main()
{

	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%d", &ai[i]);
	sort(ai, ai + n);
	for (int i = 1; i <= n; i++)
	{
		for (int j = i - 1, right = 1, cnt = 0; j >= 0; j--)
		{
			if (cnt >= m)
				right++, cnt = 0;
			ans[i] += ai[j] * right;
			cnt++;
		}
	}
	for (int i = 1; i <= n; i++)
		printf("%d ", ans[i]);
	return 0;
}


#include<bits/stdc++.h>
using   namespace            std;
const long long MAXN = 2e5 + 99, MOD = 1e9 + 7, INF = 0x3f3f3f3f;

long long n, m, ai[MAXN], ans[MAXN], pre[MAXN];
int main()
{
	scanf("%lld%lld", &n, &m);
	for (int i = 1; i <=n; i++)
		scanf("%lld", &ai[i]);
	sort(ai+1, ai+1 + n);
	for (int i = 1; i <= n; i++)
		pre[i] = i == 1 ? ai[i] : pre[i - 1] + ai[i];
	for (int i = 1; i <= m; i++)
		ans[i] = pre[i];
	for (int i = m + 1; i <= n; i++)
		ans[i] = ans[i - m] + pre[i];
	for (int i = 1; i <= n; i++)
		printf("%lld ", ans[i]);
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

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

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 200005;

int N, M, sweets[MX], rem[MX] = { 0 };
ll ans = 0;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> N >> M;
	F0R(i, N) cin >> sweets[i];
	sort(sweets, sweets + N);
	F0R(i, N)
	{
		rem[i % M] += sweets[i];
		ans += rem[i % M];
		cout << ans << " ";
	}

    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, m; cin >> n >> m;
    int sweets[n];
    for (int i = 0; i < n; i++)
        cin >> sweets[i];

    sort(sweets, sweets + n);

    for (int i = 0; i < n; i++)
    {
        long long int total = 0;
        int current_sweet = i, sweets_eaten = 0, day = 1;
        while (current_sweet >= 0)
        {
            total += sweets[current_sweet] * day;
            sweets_eaten++;
            if (sweets_eaten == m)
            {
                sweets_eaten = 0;
                day++;
            }
            current_sweet--;
        }

        cout << total << " ";
    }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, m; cin >> n >> m;
    int sweets[n], chunks[n - m + 1] = { 0 };
    for (int i = 0; i < n; i++)
        cin >> sweets[i];

    sort(sweets, sweets + n);

    for (int i = 0; i < m; i++)
    {
        chunks[0] += sweets[i];
    }

    int last = 0, next = m;
    for (int i = 1; i < n - m + 1; i++)
    {
        chunks[i] = chunks[i - 1] + sweets[next] - sweets[last];
        last++, next++;
    }

    for (int i = 0; i < n; i++)
    {
        long long int total = 0;
        int current_sweet = i, day = 1;
        while (current_sweet + 1 >= m)
        {
            total += day * chunks[current_sweet - m + 1];
            current_sweet -= m;
            day++;
        }

        if (current_sweet >= 0)
            for (; current_sweet >= 0; current_sweet--)
                total += sweets[current_sweet] * day;

        cout << total << " ";
    }
}


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

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

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

#define mp make_pair
#define pb push_back
#define f first
#define s second

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N, M; cin >> N >> M;
    ll a[N], sums[N];
    F0R(i, N) cin >> a[i];
    sort(a, a + N);
    F0R(i, N) sums[i] = 0;

    ll ans = 0;
    F0R(i, N)
    {
        sums[i % M] += a[i];
        ans += sums[i % M];
        cout << ans << " ";
    }

    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, m; cin >> n >> m;
    long long int sweets[n], coefficients[n];
    for (int i = 0; i < n; i++)
        cin >> sweets[i];

    sort(sweets, sweets + n);

    for (int i = 0; i < n; i++)
        coefficients[i] = 0;
    long long answer = 0;
    for (int i = 0; i < n; i++)
    {
        coefficients[i%m] += sweets[i];
        answer += coefficients[i%m];
        cout << answer << " ";
    }
}


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

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

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

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 200005;

ll N, M, sweets[MX], rem[MX] = { 0 };
ll ans = 0;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> N >> M;
	F0R(i, N) cin >> sweets[i];
	sort(sweets, sweets + N);
	F0R(i, N)
	{
		rem[i % M] += sweets[i];
		ans += rem[i % M];
		cout << ans << " ";
	}

    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, m; cin >> n >> m;
    int sweets[n], coefficients[n];
    for (int i = 0; i < n; i++)
        cin >> sweets[i];

    sort(sweets, sweets + n);

    for (int i = 0; i < n; i++)
        coefficients[i] = 0;
    long long answer = 0;
    for (int i = 0; i < n; i++)
    {
        coefficients[i%m] += sweets[i];
        answer += coefficients[i%m];
        cout << answer << " ";
    }
}


#include<cstdio>
#define re register
#define M 1000000007
const int Mxdt=100000;
inline char gc(){
	static char buf[Mxdt],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,Mxdt,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int t=0;char v=gc();
	while(v<'0')v=gc();
	while(v>='0')t=(t<<3)+(t<<1)+v-'0',v=gc();
	return t;
}
int n,m;
long long a[200002],sum;
int main(){
	n=read(),m=read();
	for(re int i=1;i<=n;++i)a[i]=read();
	sort(a+1,a+n+1);
	for(re int i=m+1;i<=n;++i)a[i]+=a[i-m];
	for(re int i=1;i<=n;++i)printf("%lld ",sum+=a[i]);
}


#include<cstdio>
#include<algorithm>
using namespace std;
#define re register
#define M 1000000007
const int Mxdt=100000;
inline char gc(){
	static char buf[Mxdt],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,Mxdt,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int t=0;char v=gc();
	while(v<'0')v=gc();
	while(v>='0')t=(t<<3)+(t<<1)+v-'0',v=gc();
	return t;
}
int n,m;
long long a[200002],sum;
int main(){
	n=read(),m=read();
	for(re int i=1;i<=n;++i)a[i]=read();
	sort(a+1,a+n+1);
	for(re int i=m+1;i<=n;++i)a[i]+=a[i-m];
	for(re int i=1;i<=n;++i)printf("%lld ",sum+=a[i]);
}