#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <tuple>

template <class E> struct FenwickTree {
    int _n;
    std::vector<E> data;

    FenwickTree(int n) : _n(n), data(n) { }

    void add(int p, E x) {
        ++p;
        while (p <= _n) {
            data[p - 1] += x;
            p += p & -p;
        }
    }
    E sum(int r) const {
        E s = 0;
        while (r > 0) {
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
    E sum(int l, int r) const {
        return sum(r) - sum(l);
    }
};

long long proc(
    std::vector<int>             &cur,
    int                          x,
    int                          y,
    FenwickTree<int>             &ftcnt0,
    FenwickTree<long long>       &ftsum0,
    const FenwickTree<int>       &ftcnt1,
    const FenwickTree<long long> &ftsum1,
    const std::vector<int>       &arr)
{
    int v = cur[x];
    long long dem = (long long)ftcnt1.sum(0, v) * arr[v];
    long long cre = (long long)ftcnt1.sum(0, y) * arr[y];
    long long adj = (long long)ftsum1.sum(y, v);

    ftsum0.add(v, -arr[v]);
    ftcnt0.add(v, -1);
    cur[x] = y;
    ftsum0.add(y, arr[y]);
    ftcnt0.add(y, 1);

    return cre + adj - dem;
}

int main(int argc, char **argv)
{
    int n, m, q;
    std::cin >> n >> m >> q;
    std::vector<std::tuple<int, int, int>> txy;
    std::set<int> s = { 0 };

    for (int i = 0; i < q; i++) {
        int t, x, y;
        std::cin >> t >> x >> y;
        txy.push_back(std::make_tuple(t, x - 1, y));
        s.insert(y);
    }
    std::vector<int> arr(s.begin(), s.end());
    std::map<int, int> map;
    int ll = s.size();

    for (int i = 0; i < ll; i++) map.emplace(arr[i], i);

    FenwickTree<long long> ftsuma(ll);
    FenwickTree<long long> ftsumb(ll);
    FenwickTree<int>       ftcnta(ll);
    FenwickTree<int>       ftcntb(ll);
    std::vector<int> cura(n);
    std::vector<int> curb(m);
    ftcnta.add(0, n);
    ftcntb.add(0, m);
    long long sum = 0;

    for (const auto&e : txy) {
        int cy = map[std::get<2>(e)];
        sum += (std::get<0>(e) == 1) ? proc(cura, std::get<1>(e), cy, ftcnta, ftsuma, ftcntb, ftsumb, arr)
                                     : proc(curb, std::get<1>(e), cy, ftcntb, ftsumb, ftcnta, ftsuma, arr); 
        std::cout << sum << std::endl;
    }
    return 0;
}
/***************************************************************
	File name: HaHa
	Author: ljfcnyali
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )
#define mem(a) memset ( (a), 0, sizeof ( a ) )
#define str(a) strlen ( a )
#define pii pair<int, int>
#define int long long
typedef long long LL;

const int maxn = 1e5 + 10;
const int INF = 1e18;

int K, n, m, a[maxn], b[maxn];
pii p[maxn];

inline bool Check(int x)
{
	int sum = 0;
	REP(i, 1, K)
	{
		int r = x + a[i] * m, l = a[i] * m - x;
		l = max(l, 0ll);
		p[i] = pii((l + n - 1) / n, r / n);
		p[i].first = max(p[i].first , 0ll);
		if ( p[i].first > p[i].second ) return false;
		sum += p[i].first; b[i] = p[i].first;
	}
	if ( sum > m ) return false;
	int i = K;
	while ( sum <= m && i >= 1 )
	{
		int val = min(p[i].second - p[i].first, m - sum);
		sum += val; b[i] += val;
		if ( sum == m ) return true;
		-- i;
	}
	return false;
}

signed main()
{
	scanf("%lld%lld%lld", &K, &n, &m);
	REP(i, 1, K) scanf("%lld", &a[i]);
	int L = 0, R = INF, ans;
	while ( L <= R ) 
	{
		int Mid = L + R >> 1;
		if ( Check(Mid) ) { ans = Mid; R = Mid - 1; }
		else L = Mid + 1;
	}
	Check(ans);
	REP(i, 1, K) printf("%lld ", b[i]); puts("");
    return 0;
}
