#include <set>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <bitset>
#include <algorithm>
#include <queue>
#include <unordered_set>
#include <stack>
#include <map>
#include <cassert>
#include <unordered_map>

#define FILE "chvatal"

typedef long long ll;
typedef unsigned int ui;

using namespace std;

struct edge {
    int v, u, flow, max_flow, c;
};

void add_edge(int v, int u, int f, int c, vector<edge> &edges, vector<vector<int>> &g) {
//    cerr << v << ' ' << u << ' ' << f << ' ' << c << '\n';
    g[v].push_back((int) edges.size());
    edges.push_back({v, u, 0, f, c});
    g[u].push_back((int) edges.size());
    edges.push_back({u, v, 0, 0, -c});
}

const int INF = 2e8;

void dfs(int v, vector<edge> const &edges, vector<vector<int>> const &g,
         vector<bool> &used, vector<int> &order) {
    used[v] = true;
    for (int id : g[v]) {
        edge e = edges[id];
        if (e.flow < e.max_flow && !used[e.u]) {
            dfs(e.u, edges, g, used, order);
        }
    }
    order.push_back(v);
}

void calc_pot(int s, vector<edge> const &edges, vector<vector<int>> const &g, vector<int> &d) {
    int n = (int) g.size();
    for (int i = 0; i < n; ++i) {
        d[i] = INF;
    }
    d[s] = 0;
    vector<int> order;
    vector<bool> used(n);
    dfs(s, edges, g, used, order);
    reverse(order.begin(), order.end());
    for (int v : order) {
        for (int id : g[v]) {
            edge e = edges[id];
            if (id % 2 == 1) {  // if edge is reversed
                d[v] = min(d[v], d[e.u] - e.c);
            }
        }
    }
}

bool dick_stra(int s, int t, vector<edge> &edges, vector<vector<int>> const &g,
               vector<int> &pot, vector<int> &path) {
    int n = (int) pot.size();
    vector<int> d(n, INF);
    d[s] = 0;
    vector<bool> used(n);
    vector<int> par(n, -1);
    for (int i = 0; i < n; ++i) {
        int v = -1;
        for (int j = 0; j < n; ++j) {
            if (!used[j] && (v == -1 || d[v] > d[j])) {
                v = j;
            }
        }
        used[v] = true;
        for (int id : g[v]) {
            edge e = edges[id];
            int dist = e.c + pot[v] - pot[e.u];
            if (e.flow < e.max_flow && d[e.u] > d[v] + dist) {
                d[e.u] = d[v] + dist;
                par[e.u] = id;
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        pot[i] += d[i];
    }
    if (d[t] == INF) {
        return false;
    }
    int v = t;
    while (par[v] != -1) {
        path.push_back(par[v]);
        v = edges[par[v]].v;
    }
    return true;
}

struct task {
    int l, r, c;
};

int main() {
#if 0
    freopen("input.txt", "r", stdin);
#else
    //    freopen(FILE".in", "r", stdin);
    //    freopen(FILE".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    vector<task> tasks(n);
    for (int i = 0; i < n; ++i) {
        cin >> tasks[i].l >> tasks[i].r >> tasks[i].c;
        tasks[i].r += tasks[i].l - 1;
    }
    int cnt_vs = 2 * n + 3;
    vector<vector<int>> g(cnt_vs);
    vector<edge> edges;
    add_edge(0, 1, k, 0, edges, g);
    vector<int> edges_id(n);
    for (int i = 1; i <= n; ++i) {
        int v = 2 * i, u = 2 * i + 1;
        add_edge(1, v, 1, 0, edges, g);
        add_edge(u, cnt_vs - 1, 1, 0, edges, g);
        edges_id[i - 1] = (int) edges.size();
        add_edge(v, u, 1, -tasks[i - 1].c, edges, g);
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            task f = tasks[i], s = tasks[j];
            if (s.l > f.r) {
                int v = 2 * (i + 1) + 1;
                int u = 2 * (j + 1);
                add_edge(v, u, 1, 0, edges, g);
            }
        }
    }
    vector<int> pot(cnt_vs);
    calc_pot(0, edges, g, pot);
    for (;;) {
        vector<int> path;
        if (!dick_stra(0, cnt_vs - 1, edges, g, pot, path)) {
            break;
        }
        int flow = INF;
        for (int id : path) {
            flow = min(flow, edges[id].max_flow - edges[id].flow);
        }
        for (int id : path) {
            edges[id].flow += flow;
            edges[id ^ 1].flow -= flow;
        }
    }
    for (int i = 0; i < n; ++i) {
        if (edges[edges_id[i]].flow > 0) {
            cout << 1 << ' ';
        } else {
            cout << 0 << ' ';
        }
    }

    return 0;
}


#include <set>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <bitset>
#include <algorithm>
#include <queue>
#include <unordered_set>
#include <stack>
#include <map>
#include <cassert>
#include <unordered_map>

#define FILE "chvatal"

typedef long long ll;
typedef unsigned int ui;

using namespace std;

struct edge {
    int v, u, flow, max_flow, c;
};

void add_edge(int v, int u, int f, int c, vector<edge> &edges, vector<vector<int>> &g) {
//    cerr << v << ' ' << u << ' ' << f << ' ' << c << '\n';
    g[v].push_back((int) edges.size());
    edges.push_back({v, u, 0, f, c});
    g[u].push_back((int) edges.size());
    edges.push_back({u, v, 0, 0, -c});
}

const int INF = 2e8;

void dfs(int v, vector<edge> const &edges, vector<vector<int>> const &g,
         vector<bool> &used, vector<int> &order) {
    used[v] = true;
    for (int id : g[v]) {
        edge e = edges[id];
        if (e.flow < e.max_flow && !used[e.u]) {
            dfs(e.u, edges, g, used, order);
        }
    }
    order.push_back(v);
}

void calc_pot(int s, vector<edge> const &edges, vector<vector<int>> const &g, vector<int> &d) {
    int n = (int) g.size();
    for (int i = 0; i < n; ++i) {
        d[i] = INF;
    }
    d[s] = 0;
    vector<int> order;
    vector<bool> used(n);
    dfs(s, edges, g, used, order);
    reverse(order.begin(), order.end());
    for (int v : order) {
        for (int id : g[v]) {
            edge e = edges[id];
            if (id % 2 == 1) {  // if edge is reversed
                d[v] = min(d[v], d[e.u] + e.c);
            }
        }
    }
}

bool dick_stra(int s, int t, vector<edge> &edges, vector<vector<int>> const &g,
               vector<int> &pot, vector<int> &path) {
    int n = (int) pot.size();
    vector<int> d(n, INF);
    d[s] = 0;
    vector<bool> used(n);
    vector<int> par(n, -1);
    for (int i = 0; i < n; ++i) {
        int v = -1;
        for (int j = 0; j < n; ++j) {
            if (!used[j] && (v == -1 || d[v] > d[j])) {
                v = j;
            }
        }
        used[v] = true;
        for (int id : g[v]) {
            edge e = edges[id];
            int dist = e.c + pot[v] - pot[e.u];
            if (e.flow < e.max_flow && d[e.u] > d[v] + dist) {
                d[e.u] = d[v] + dist;
                par[e.u] = id;
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        pot[i] += d[i];
    }
    if (d[t] == INF) {
        return false;
    }
    int v = t;
    while (par[v] != -1) {
        path.push_back(par[v]);
        v = edges[par[v]].v;
    }
    return true;
}

struct task {
    int l, r, c;
};

int main() {
#if 0
    freopen("input.txt", "r", stdin);
#else
    //    freopen(FILE".in", "r", stdin);
    //    freopen(FILE".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    vector<task> tasks(n);
    for (int i = 0; i < n; ++i) {
        cin >> tasks[i].l >> tasks[i].r >> tasks[i].c;
        tasks[i].r += tasks[i].l - 1;
    }
    int cnt_vs = 2 * n + 3;
    vector<vector<int>> g(cnt_vs);
    vector<edge> edges;
    add_edge(0, 1, k, 0, edges, g);
    vector<int> edges_id(n);
    for (int i = 1; i <= n; ++i) {
        int v = 2 * i, u = 2 * i + 1;
        add_edge(1, v, 1, 0, edges, g);
        add_edge(u, cnt_vs - 1, 1, 0, edges, g);
        edges_id[i - 1] = (int) edges.size();
        add_edge(v, u, 1, -tasks[i - 1].c, edges, g);
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            task f = tasks[i], s = tasks[j];
            if (s.l > f.r) {
                int v = 2 * (i + 1) + 1;
                int u = 2 * (j + 1);
                add_edge(v, u, 1, 0, edges, g);
            }
        }
    }
    vector<int> pot(cnt_vs);
    calc_pot(0, edges, g, pot);
    for (;;) {
        vector<int> path;
        if (!dick_stra(0, cnt_vs - 1, edges, g, pot, path)) {
            break;
        }
        int flow = INF;
        for (int id : path) {
            flow = min(flow, edges[id].max_flow - edges[id].flow);
        }
        for (int id : path) {
            edges[id].flow += flow;
            edges[id ^ 1].flow -= flow;
        }
    }
    for (int i = 0; i < n; ++i) {
        if (edges[edges_id[i]].flow > 0) {
            cout << 1 << ' ';
        } else {
            cout << 0 << ' ';
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 2004;
const int M = 1000;
int n, k, s1, s2, t;

int elem[N][3];

struct Edge {
    int cap;
    int flw;
    int wgt;
} edge[N][N];

struct Graph {
    int par[N];
    int dst[N];
    bool inq[N];
    vec <int> adj[N];
} graph;

void input() {
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> elem[i][0];
        cin >> elem[i][1];
        cin >> elem[i][2];
    }
}

void add_edge(int u, int v, int c, int w) {
    graph.adj[u].pb(v);
    graph.adj[u].pb(u);
    edge[u][v].cap = c;
    edge[u][v].flw = 0;
    edge[u][v].wgt = -w;
    edge[v][u].cap = c;
    edge[v][u].flw = c;
    edge[v][u].wgt = w;
}

void edmonds_karp() {
    int ans = 0;
    int cur = 0;
    while(true) {
        fill(graph.dst, graph.dst + N, inf);
        queue <int> q;
        graph.dst[s1] = 0;
        q.push(s1);

        while(!q.empty()) {
            int u = q.front(); q.pop();
            for(int v: graph.adj[u]) {
                if(graph.dst[v] > graph.dst[u] + edge[u][v].wgt && edge[u][v].cap > edge[u][v].flw) {
                    graph.dst[v] = graph.dst[u] + edge[u][v].wgt;
                    graph.par[v] = u;
                    q.push(v);
                }
            }
        }
        if(graph.dst[t] == inf) {
            break;
        }
        cur += graph.dst[t];
        ans = min(ans, cur);
        for(int u = t; u != s1; ) {
            int v = graph.par[u];
            edge[v][u].flw++;
            edge[u][v].flw--;
            u = v;
        }
    }
    for(int i = 1; i <= n; ++i) {
        if(edge[i][i + M].flw) {
            cout << "1 ";
        } else {
            cout << "0 ";
        }
    }
}

void solve() {
    s1 = N - 1, s2 = N - 2, t = N - 3;
    add_edge(s1, s2, k, 0);
    for(int i = 1; i <= n; ++i) {
        add_edge(s2, i, 1, 0);
        add_edge(i + M, t, 1, 0);
    }
    for(int i = 1; i <= n; ++i) {
        add_edge(i, i + M, 1, elem[i][2]);
    }
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            if(elem[i][0] + elem[i][1] <= elem[j][0]) {
                add_edge(i + M, j, 1, 0);
            }
        }
    }
    edmonds_karp();
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 1004;
int n, k, s1, s2, t;

array <int, 3> el[N];

struct Edge {
    int cap;
    int flw;
    int wgt;
} edge[N][N];

struct Graph {
    int par[N];
    int dst[N];
    bool inq[N];
    vec <int> adj[N];
} graph;

void input() {
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> el[i][0];
        cin >> el[i][1];
        cin >> el[i][2];
    }
}

void add_edge(int u, int v, int c, int w) {
    graph.adj[u].pb(v);
    graph.adj[u].pb(u);
    edge[u][v].cap = c;
    edge[u][v].flw = 0;
    edge[u][v].wgt = -w;
    edge[v][u].cap = c;
    edge[v][u].flw = c;
    edge[v][u].wgt = w;
}

void edmonds_karp() {
    while(true) {
        fill(graph.dst, graph.dst + N, inf);
        queue <int> q;
        graph.dst[s1] = 0;
        q.push(s1);

        while(!q.empty()) {
            int u = q.front(); q.pop();
            for(int v: graph.adj[u]) {
                if(graph.dst[v] > graph.dst[u] + edge[u][v].wgt && edge[u][v].cap > edge[u][v].flw) {
                    graph.dst[v] = graph.dst[u] + edge[u][v].wgt;
                    graph.par[v] = u;
                    q.push(v);
                }
            }
        }
        if(graph.dst[t] == inf) {
            break;
        }
        for(int u = t; u != s1; ) {
            int v = graph.par[u];
            edge[v][u].flw++;
            edge[u][v].flw--;
            u = v;
        }
    }
    for(int j = 1; j <= n; ++j) {
        bool one = 0;
        for(int i = 1; i < N; ++i) {
            if(i <= n && el[i][0] + el[i][1] <= el[j][0] || i == s2) {
                if(edge[i][j].flw) {
                    one = 1;
                    break;
                }
            }
        }
        cout << one << " ";
    }
    cout << "\n";
}

void solve() {
    s1 = N - 1, s2 = N - 2, t = N - 3;
    add_edge(s1, s2, k, 0);
    for(int i = 1; i <= n; ++i) {
        add_edge(s2, i, 1, el[i][2]);
        add_edge(i, t, 1, 0);
    }
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            if(el[i][0] + el[i][1] <= el[j][0]) {
                add_edge(i, j, 1, el[j][2]);
            }
        }
    }
    edmonds_karp();
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 2004;
const int M = 1000;
int n, k, s1, s2, t;

bitset <N> result;

int elem[N][3];

struct Edge {
    int cap;
    int flw;
    int wgt;
} edge[N][N];

struct Graph {
    int par[N];
    int dst[N];
    bool inq[N];
    vec <int> adj[N];
} graph;

void input() {
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> elem[i][0];
        cin >> elem[i][1];
        cin >> elem[i][2];
    }
}

void add_edge(int u, int v, int c, int w) {
    graph.adj[u].pb(v);
    graph.adj[v].pb(u);
    edge[u][v].cap = c;
    edge[u][v].flw = 0;
    edge[u][v].wgt = -w;
    edge[v][u].cap = c;
    edge[v][u].flw = c;
    edge[v][u].wgt = w;
}

void edmonds_karp() {
    int ans = 0;
    int cur = 0;
    while(true) {
        fill(graph.dst, graph.dst + N, inf);
        queue <int> q;
        graph.dst[s1] = 0;
        q.push(s1);

        while(!q.empty()) {
            int u = q.front(); q.pop();
            for(int v: graph.adj[u]) {
                if(graph.dst[v] > graph.dst[u] + edge[u][v].wgt && edge[u][v].cap > edge[u][v].flw) {
                    graph.dst[v] = graph.dst[u] + edge[u][v].wgt;
                    graph.par[v] = u;
                    q.push(v);
                }
            }
        }
        if(graph.dst[t] == inf) {
            break;
        }
        cur += graph.dst[t];
        for(int u = t; u != s1; ) {
            int v = graph.par[u];
            edge[v][u].flw++;
            edge[u][v].flw--;
            u = v;
        }
        if(cur < ans) {
            for(int i = 1; i <= n; ++i) {
                result[i] = (edge[i][i + M].flw == 1);
            }
            ans = cur;
        }
    }
    for(int i = 1; i <= n; ++i) {
        cout << result[i] << " ";
    }
    cout << "\n";
}

void solve() {
    s1 = N - 1, s2 = N - 2, t = N - 3;
    add_edge(s1, s2, k, 0);
    for(int i = 1; i <= n; ++i) {
        add_edge(s2, i, 1, 0);
        add_edge(i + M, t, 1, 0);
    }
    for(int i = 1; i <= n; ++i) {
        add_edge(i, i + M, 1, elem[i][2]);
    }
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            if(elem[i][0] + elem[i][1] <= elem[j][0]) {
                add_edge(i + M, j, 1, 0);
            }
        }
    }
    edmonds_karp();
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 2004;
const int M = 1000;
int n, k, s1, s2, t;

bitset <N> result;

int elem[N][3];

struct Edge {
    int cap;
    int flw;
    int wgt;
} edge[N][N];

struct Graph {
    int par[N];
    int dst[N];
    bool inq[N];
    vec <int> adj[N];
} graph;

void input() {
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> elem[i][0];
        cin >> elem[i][1];
        cin >> elem[i][2];
    }
}

void add_edge(int u, int v, int c, int w) {
    graph.adj[u].pb(v);
    graph.adj[v].pb(u);
    edge[u][v].cap = c;
    edge[u][v].flw = 0;
    edge[u][v].wgt = -w;
    edge[v][u].cap = c;
    edge[v][u].flw = c;
    edge[v][u].wgt = w;
}

void edmonds_karp() {
    int ans = 0;
    int cur = 0;
    while(true) {
        fill(graph.dst, graph.dst + N, inf);
        queue <int> q;
        graph.dst[s1] = 0;
        q.push(s1);

        while(!q.empty()) {
            int u = q.front(); q.pop();
            graph.inq[u] = 0;

            for(int v: graph.adj[u]) {
                if(graph.dst[v] > graph.dst[u] + edge[u][v].wgt && edge[u][v].cap > edge[u][v].flw) {
                    graph.dst[v] = graph.dst[u] + edge[u][v].wgt;
                    graph.par[v] = u;
                    if(!graph.inq[v]) {
                        graph.inq[v] = 1;
                        q.push(v);
                    }
                }
            }
        }
        if(graph.dst[t] == inf) {
            break;
        }
        cur += graph.dst[t];
        for(int u = t; u != s1; ) {
            int v = graph.par[u];
            edge[v][u].flw++;
            edge[u][v].flw--;
            u = v;
        }
        if(cur < ans) {
            for(int i = 1; i <= n; ++i) {
                result[i] = (edge[i][i + M].flw == 1);
            }
            ans = cur;
        }
    }
    for(int i = 1; i <= n; ++i) {
        cout << result[i] << " ";
    }
    cout << "\n";
}

void solve() {
    s1 = N - 1, s2 = N - 2, t = N - 3;
    add_edge(s1, s2, k, 0);
    for(int i = 1; i <= n; ++i) {
        add_edge(s2, i, 1, 0);
        add_edge(i + M, t, 1, 0);
    }
    for(int i = 1; i <= n; ++i) {
        add_edge(i, i + M, 1, elem[i][2]);
    }
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            if(elem[i][0] + elem[i][1] <= elem[j][0]) {
                add_edge(i + M, j, 1, 0);
            }
        }
    }
    edmonds_karp();
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>

using namespace std;

namespace mcmf {
	using ll = int;
	const ll oo = 1.001e9;
	const int N = 1005, E = N * N;
	vector<int> g[N];
	int ne;
	struct Edge {
		int from, to; ll cap, cost;
	} edge[E];
	int start = N - 1, target = N - 2, p[N]; int inqueue[N];
	ll d[N];
	ll pot[N];
	bool dijkstra(int source, int sink) {
		for(int i = 0; i < N; i++) d[i] = oo;
		d[source] = 0;
		priority_queue<pair<ll, int>> q;
		q.emplace(0, source);
		ll dt; int u;
		int cnt = 0;
		while(!q.empty()) {
			tie(dt, u) = q.top(); q.pop(); dt = -dt;
			if(dt > d[u]) continue;
			for(int e : g[u]) {
				auto v = edge[e];
				if(!v.cap) continue;
				const ll cand = d[u] + v.cost + pot[u] - pot[v.to];
				assert(v.cost + pot[u] - pot[v.to] >= 0);
				if(cand < d[v.to]) {
					p[v.to] = e;
					d[v.to] = cand;
					q.emplace(-d[v.to], v.to);
				}
			}
		}
		return d[sink] < oo;
	}
	void calc_pot() {
		auto process = [&](int u) {
			for(int e : g[u]) {
				const auto &v = edge[e];
				if(!v.cap) continue;
				ll cand = pot[u] + v.cost;
				if(cand < pot[v.to]) {
					pot[v.to] = cand;
				}
			}
		};

		process(N - 3);
		process(start);
		for(int i = 0; i < N; i++) {
			process(i);
		}
	}
	pair<ll, ll> mincost(int source = start, int sink = target) {
		calc_pot();
		ll ans = 0, mf = 0;
		while(dijkstra(source, sink)) {
			ll f = oo;
			for(int u = sink; u != source; u = edge[ p[u] ].from)
				f = min(f, edge[ p[u] ].cap);
			mf += f;
			ans += f * (d[sink] - pot[source] + pot[sink]);
			for(int u = sink; u != source; u = edge[ p[u] ].from) {
				edge[ p[u] ].cap -= f;
				edge[ p[u] ^ 1].cap += f;
			}
			for(int i = 0; i < N; i++) pot[i] = min(oo, pot[i] + d[i]);
		}
		cerr << ans << endl;
		return {mf, ans};
	}
	void addEdge(int u, int v, ll c, ll cost) {
		// assert(cost >= 0);
		edge[ne] = {u, v, c, cost};
		g[u].push_back(ne++);
		edge[ne] = {v, u, 0,-cost};
		g[v].push_back(ne++);
	}
};

const int N = 1005;
const int M = 1000006;

int n, k;
int s[N], t[N], c[N], id[N], rid[N];

int main() {
	scanf("%d %d", &n, &k);

	for(int i = 0; i < n; i++) scanf("%d %d %d", s + i, t + i, c + i), id[i] = i;

	sort(id, id + n, [](int i, int j) {
		return s[i] < s[j];
	});

	for(int i = 0; i < n; i++) rid[ id[i] ] = i;

	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j) {
		if(s[i] + t[i] - 1 < s[j]) {
			mcmf::addEdge(id[i], id[j], 1, -c[j]);
		}
	}

	for(int i = 0; i < n; i++) {
		mcmf::addEdge(mcmf::start, id[i], 1, -c[i]);
		mcmf::addEdge(id[i], mcmf::target, 1, 0);
	}

	int st = mcmf::N - 3;
	mcmf::addEdge(st, mcmf::start, k, 0);

	mcmf::mincost(st);

	vector<bool> ans(n, false);

	for(int i = 0; i < mcmf::N; i++) {
		for(int e : mcmf::g[i]) {
			if(e & 1) continue;
			auto ed = mcmf::edge[e];
			int to = mcmf::edge[e].to;
			if(to >= n) continue;
			if(mcmf::edge[e].cap) continue;
			ans[ rid[to] ] = true;
		}
	}

	for(int i = 0; i < n; i++) {
		printf("%d%c", (int)ans[i], " \n"[i + 1 == n]);
	}
}


#include <bits/stdc++.h>

using namespace std;

namespace mcmf {
	using ll = int;
	const ll oo = 1.001e9;
	const int N = 1005, E = N * N;
	vector<int> g[N];
	int ne;
	struct Edge {
		int from, to; ll cap, cost;
	} edge[E];
	int start = N - 1, target = N - 2, p[N]; int inqueue[N];
	ll d[N];
	ll pot[N];
	bool dijkstra(int source, int sink) {
		for(int i = 0; i < N; i++) d[i] = oo;
		d[source] = 0;
		priority_queue<pair<ll, int>> q;
		q.emplace(0, source);
		ll dt; int u;
		int cnt = 0;
		while(!q.empty()) {
			tie(dt, u) = q.top(); q.pop(); dt = -dt;
			if(dt > d[u]) continue;
			for(int e : g[u]) {
				auto v = edge[e];
				if(!v.cap) continue;
				const ll cand = d[u] + v.cost + pot[u] - pot[v.to];
				assert(v.cost + pot[u] - pot[v.to] >= 0);
				if(cand < d[v.to]) {
					p[v.to] = e;
					d[v.to] = cand;
					q.emplace(-d[v.to], v.to);
				}
			}
		}
		return d[sink] < oo;
	}
	void calc_pot(int source) {
		auto process = [&](int u) {
			for(int e : g[u]) {
				const auto &v = edge[e];
				if(!v.cap) continue;
				ll cand = pot[u] + v.cost;
				if(cand < pot[v.to]) {
					pot[v.to] = cand;
				}
			}
		};

		process(source);
		process(start);
		for(int i = 0; i < N; i++) {
			process(i);
		}
	}
	pair<ll, ll> mincost(int source = start, int sink = target) {
		calc_pot(source);
		ll ans = 0, mf = 0;
		while(dijkstra(source, sink)) {
			ll f = oo;
			for(int u = sink; u != source; u = edge[ p[u] ].from)
				f = min(f, edge[ p[u] ].cap);
			mf += f;
			ans += f * (d[sink] - pot[source] + pot[sink]);
			for(int u = sink; u != source; u = edge[ p[u] ].from) {
				edge[ p[u] ].cap -= f;
				edge[ p[u] ^ 1].cap += f;
			}
			for(int i = 0; i < N; i++) pot[i] = min(oo, pot[i] + d[i]);
		}
		cerr << ans << endl;
		return {mf, ans};
	}
	void addEdge(int u, int v, ll c, ll cost) {
		// assert(cost >= 0);
		edge[ne] = {u, v, c, cost};
		g[u].push_back(ne++);
		edge[ne] = {v, u, 0,-cost};
		g[v].push_back(ne++);
	}
};

const int N = 1005;
const int M = 1000006;

int n, k;
int s[N], t[N], c[N], id[N], rid[N];

int main() {
	scanf("%d %d", &n, &k);

	for(int i = 0; i < n; i++) scanf("%d %d %d", s + i, t + i, c + i), id[i] = i;

	sort(id, id + n, [](int i, int j) {
		return s[i] < s[j];
	});

	for(int i = 0; i < n; i++) rid[ id[i] ] = i;

	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j) {
		if(s[i] + t[i] - 1 < s[j]) {
			if(j < i) return 0;
			assert(i < j);
			mcmf::addEdge(id[i], id[j], 1, -c[j]);
		}
	}

	for(int i = 0; i < n; i++) {
		mcmf::addEdge(mcmf::start, id[i], 1, -c[i]);
		mcmf::addEdge(id[i], mcmf::target, 1, 0);
	}

	int st = mcmf::N - 3;
	mcmf::addEdge(st, mcmf::start, k, 0);

	mcmf::mincost(st);

	vector<bool> ans(n, false);

	for(int i = 0; i < mcmf::N; i++) {
		for(int e : mcmf::g[i]) {
			if(e & 1) continue;
			auto ed = mcmf::edge[e];
			int to = mcmf::edge[e].to;
			if(to >= n) continue;
			if(mcmf::edge[e].cap) continue;
			ans[ rid[to] ] = true;
		}
	}

	for(int i = 0; i < n; i++) {
		printf("%d%c", (int)ans[i], " \n"[i + 1 == n]);
	}
}


#include <bits/stdc++.h>

using namespace std;

namespace mcmf {
	using ll = int;
	const ll oo = 1.5e9;
	const int N = 2005, E = 2 * N * N;
	vector<int> g[N];
	int ne;
	struct Edge {
		int from, to; ll cap, cost;
	} edge[E];
	int start = N - 1, target = N - 2, p[N]; int inqueue[N];
	ll d[N];
	ll pot[N];
	bool dijkstra(int source, int sink) {
		for(int i = 0; i < N; i++) d[i] = oo;
		d[source] = 0;
		priority_queue<pair<ll, int>> q;
		q.emplace(0, source);
		ll dt; int u;
		while(!q.empty()) {
			tie(dt, u) = q.top(); q.pop(); dt = -dt;
			if(dt > d[u]) continue;
			if(u == sink) return true;
			for(int e : g[u]) {
				auto v = edge[e];
				const ll cand = d[u] + v.cost + pot[u] - pot[v.to];
				if(v.cap > 0 and cand < d[v.to]) {
					p[v.to] = e;
					d[v.to] = cand;
					q.emplace(-d[v.to], v.to);
				}
			}
		}
		return d[sink] < oo;
	}
	void calc_pot() {
		auto process = [&](int u) {
			for(int e : g[u]) {
				auto v = edge[e];
				if(!v.cap) continue;
				ll cand = pot[u] + v.cost;
				if(cand < pot[v.to]) {
					pot[v.to] = cand;
				}
			}
		};

		process(N - 3);
		process(start);
		for(int i = 0; i < N; i++) {
			process(i);
		}
	}
	pair<ll, ll> mincost(int source = start, int sink = target) {
		calc_pot();
		ll ans = 0, mf = 0;
		while(dijkstra(source, sink)) {
			ll f = oo;
			for(int u = sink; u != source; u = edge[ p[u] ].from)
				f = min(f, edge[ p[u] ].cap);
			mf += f;
			ans += f * (d[sink] - pot[source] + pot[sink]);
			for(int u = sink; u != source; u = edge[ p[u] ].from) {
				edge[ p[u] ].cap -= f;
				edge[ p[u] ^ 1].cap += f;
			}
			for(int i = 0; i < N; i++) pot[i] = min(oo, pot[i] + d[i]);
		}
		cerr << ans << endl;
		return {mf, ans};
	}
	void addEdge(int u, int v, ll c, ll cost) {
		// assert(cost >= 0);
		edge[ne] = {u, v, c, cost};
		g[u].push_back(ne++);
		edge[ne] = {v, u, 0,-cost};
		g[v].push_back(ne++);
	}
};

const int N = 1005;
const int M = 1000006;

int n, k;
int s[N], t[N], c[N], id[N], rid[N];

int main() {
	scanf("%d %d", &n, &k);

	for(int i = 0; i < n; i++) scanf("%d %d %d", s + i, t + i, c + i), id[i] = i;

	sort(id, id + n, [](int i, int j) {
		return s[i] < s[j];
	});

	for(int i = 0; i < n; i++) rid[ id[i] ] = i;

	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j) {
		if(s[i] + t[i] - 1 < s[j]) {
			mcmf::addEdge(id[i], id[j], 1, - c[j]);
		}
	}

	for(int i = 0; i < n; i++) {
		mcmf::addEdge(mcmf::start, id[i], 1, - c[i]);
		mcmf::addEdge(id[i], mcmf::target, 1, 0);
	}

	int st = mcmf::N - 3;
	mcmf::addEdge(st, mcmf::start, k, 0);

	mcmf::mincost(st);

	vector<bool> ans(n, false);

	for(int i = 0; i < mcmf::N; i++) {
		for(int e : mcmf::g[i]) {
			if(e & 1) continue;
			auto ed = mcmf::edge[e];
			int to = mcmf::edge[e].to;
			if(to >= n) continue;
			if(mcmf::edge[e].cap) continue;
			ans[ rid[to] ] = true;
		}
	}

	for(int i = 0; i < n; i++) {
		printf("%d%c", (int)ans[i], " \n"[i + 1 == n]);
	}
}


#include <bits/stdc++.h>

using namespace std;

namespace mcmf {
	using ll = int;
	const ll oo = 1.001e9;
	const int N = 1005, E = N * N;
	vector<int> g[N];
	int ne;
	struct Edge {
		int from, to; ll cap, cost;
	} edge[E];
	int start = N - 1, target = N - 2, p[N]; int inqueue[N];
	ll d[N];
	ll pot[N];
	bool dijkstra(int source, int sink) {
		for(int i = 0; i < N; i++) d[i] = oo;
		d[source] = 0;
		priority_queue<pair<ll, int>> q;
		q.emplace(0, source);
		ll dt; int u;
		int cnt = 0;
		while(!q.empty()) {
			tie(dt, u) = q.top(); q.pop(); dt = -dt;
			if(dt > d[u]) continue;
			if(u == sink) return true;
			assert(++cnt < N);
			for(int e : g[u]) {
				auto v = edge[e];
				const ll cand = d[u] + v.cost + pot[u] - pot[v.to];
				if(v.cap > 0 and cand < d[v.to]) {
					p[v.to] = e;
					d[v.to] = cand;
					q.emplace(-d[v.to], v.to);
				}
			}
		}
		return d[sink] < oo;
	}
	void calc_pot() {
		auto process = [&](int u) {
			for(int e : g[u]) {
				const auto &v = edge[e];
				if(!v.cap) continue;
				ll cand = pot[u] + v.cost;
				if(cand < pot[v.to]) {
					pot[v.to] = cand;
				}
			}
		};

		process(N - 3);
		process(start);
		for(int i = 0; i < N; i++) {
			process(i);
		}
	}
	pair<ll, ll> mincost(int source = start, int sink = target) {
		calc_pot();
		ll ans = 0, mf = 0;
		while(dijkstra(source, sink)) {
			ll f = oo;
			for(int u = sink; u != source; u = edge[ p[u] ].from)
				f = min(f, edge[ p[u] ].cap);
			mf += f;
			ans += f * (d[sink] - pot[source] + pot[sink]);
			for(int u = sink; u != source; u = edge[ p[u] ].from) {
				edge[ p[u] ].cap -= f;
				edge[ p[u] ^ 1].cap += f;
			}
			for(int i = 0; i < N; i++) pot[i] = min(oo, pot[i] + d[i]);
		}
		cerr << ans << endl;
		return {mf, ans};
	}
	void addEdge(int u, int v, ll c, ll cost) {
		// assert(cost >= 0);
		edge[ne] = {u, v, c, cost};
		g[u].push_back(ne++);
		edge[ne] = {v, u, 0,-cost};
		g[v].push_back(ne++);
	}
};

const int N = 1005;
const int M = 1000006;

int n, k;
int s[N], t[N], c[N], id[N], rid[N];

int main() {
	scanf("%d %d", &n, &k);

	for(int i = 0; i < n; i++) scanf("%d %d %d", s + i, t + i, c + i), id[i] = i;

	sort(id, id + n, [](int i, int j) {
		return s[i] < s[j];
	});

	for(int i = 0; i < n; i++) rid[ id[i] ] = i;

	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j) {
		if(s[i] + t[i] - 1 < s[j]) {
			mcmf::addEdge(id[i], id[j], 1, -c[j]);
		}
	}

	for(int i = 0; i < n; i++) {
		mcmf::addEdge(mcmf::start, id[i], 1, -c[i]);
		mcmf::addEdge(id[i], mcmf::target, 1, 0);
	}

	int st = mcmf::N - 3;
	mcmf::addEdge(st, mcmf::start, k, 0);

	mcmf::mincost(st);

	vector<bool> ans(n, false);

	for(int i = 0; i < mcmf::N; i++) {
		for(int e : mcmf::g[i]) {
			if(e & 1) continue;
			auto ed = mcmf::edge[e];
			int to = mcmf::edge[e].to;
			if(to >= n) continue;
			if(mcmf::edge[e].cap) continue;
			ans[ rid[to] ] = true;
		}
	}

	for(int i = 0; i < n; i++) {
		printf("%d%c", (int)ans[i], " \n"[i + 1 == n]);
	}
}


#include <bits/stdc++.h>

using namespace std;

namespace mcmf {
	using ll = int;
	const ll oo = 1.001e9;
	const int N = 1005, E = N * N;
	vector<int> g[N];
	int ne;
	struct Edge {
		int from, to; ll cap, cost;
	} edge[E];
	int start = N - 1, target = N - 2, p[N]; int inqueue[N];
	ll d[N];
	ll pot[N];
	bool dijkstra(int source, int sink) {
		for(int i = 0; i < N; i++) d[i] = oo;
		d[source] = 0;
		priority_queue<pair<ll, int>> q;
		q.emplace(0, source);
		ll dt; int u;
		int cnt = 0;
		while(!q.empty()) {
			tie(dt, u) = q.top(); q.pop(); dt = -dt;
			if(dt > d[u]) continue;
			for(int e : g[u]) {
				auto v = edge[e];
				if(!v.cap) continue;
				const ll cand = d[u] + v.cost + pot[u] - pot[v.to];
				assert(v.cost + pot[u] - pot[v.to] >= 0);
				if(cand < d[v.to]) {
					p[v.to] = e;
					d[v.to] = cand;
					q.emplace(-d[v.to], v.to);
				}
			}
		}
		return d[sink] < oo;
	}
	void calc_pot(int source) {
		auto process = [&](int u) {
			for(int e : g[u]) {
				const auto &v = edge[e];
				if(!v.cap) continue;
				ll cand = pot[u] + v.cost;
				if(cand < pot[v.to]) {
					pot[v.to] = cand;
				}
			}
		};

		process(source);
		process(start);
		for(int i = 0; i < N; i++) {
			process(i);
		}
	}
	pair<ll, ll> mincost(int source = start, int sink = target) {
		calc_pot(source);
		ll ans = 0, mf = 0;
		while(dijkstra(source, sink)) {
			ll f = oo;
			for(int u = sink; u != source; u = edge[ p[u] ].from)
				f = min(f, edge[ p[u] ].cap);
			mf += f;
			ans += f * (d[sink] - pot[source] + pot[sink]);
			for(int u = sink; u != source; u = edge[ p[u] ].from) {
				edge[ p[u] ].cap -= f;
				edge[ p[u] ^ 1].cap += f;
			}
			for(int i = 0; i < N; i++) pot[i] = min(oo, pot[i] + d[i]);
		}
		cerr << ans << endl;
		return {mf, ans};
	}
	void addEdge(int u, int v, ll c, ll cost) {
		// assert(cost >= 0);
		edge[ne] = {u, v, c, cost};
		g[u].push_back(ne++);
		edge[ne] = {v, u, 0,-cost};
		g[v].push_back(ne++);
	}
};

const int N = 1005;
const int M = 1000006;

int n, k;
int s[N], t[N], c[N], id[N], rid[N];

int main() {
	scanf("%d %d", &n, &k);

	for(int i = 0; i < n; i++) scanf("%d %d %d", s + i, t + i, c + i), id[i] = i;

	sort(id, id + n, [](int i, int j) {
		return s[i] < s[j];
	});

	for(int i = 0; i < n; i++) rid[ id[i] ] = i;

	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j) {
		if(s[i] + t[i] - 1 < s[j]) {
			mcmf::addEdge(rid[i], rid[j], 1, -c[j]);
		}
	}

	for(int i = 0; i < n; i++) {
		mcmf::addEdge(mcmf::start, rid[i], 1, -c[i]);
		mcmf::addEdge(rid[i], mcmf::target, 1, 0);
	}

	int st = mcmf::N - 3;
	mcmf::addEdge(st, mcmf::start, k, 0);

	mcmf::mincost(st);

	vector<bool> ans(n, false);

	for(int i = 0; i < mcmf::N; i++) {
		for(int e : mcmf::g[i]) {
			if(e & 1) continue;
			auto ed = mcmf::edge[e];
			int to = mcmf::edge[e].to;
			if(to >= n) continue;
			if(mcmf::edge[e].cap) continue;
			ans[ id[to] ] = true;
		}
	}

	for(int i = 0; i < n; i++) {
		printf("%d%c", (int)ans[i], " \n"[i + 1 == n]);
	}
}


#include <bits/stdc++.h>

using namespace std;

namespace mcmf {
	using ll = int;
	const ll oo = 1.001e9;
	const int N = 1005, E = N * N;
	vector<int> g[N];
	int ne;
	struct Edge {
		int from, to; ll cap, cost;
	} edge[E];
	int start = N - 1, target = N - 2, p[N]; int inqueue[N];
	ll d[N];
	ll pot[N];
	bool dijkstra(int source, int sink) {
		for(int i = 0; i < N; i++) d[i] = oo;
		d[source] = 0;
		priority_queue<pair<ll, int>> q;
		q.emplace(0, source);
		ll dt; int u;
		int cnt = 0;
		while(!q.empty()) {
			tie(dt, u) = q.top(); q.pop(); dt = -dt;
			if(dt > d[u]) continue;
			if(u == sink) return true;
			for(int e : g[u]) {
				auto v = edge[e];
				if(!v.cap) continue;
				const ll cand = d[u] + v.cost + pot[u] - pot[v.to];
				assert(v.cost + pot[u] - pot[v.to] >= 0);
				if(cand < d[v.to]) {
					p[v.to] = e;
					d[v.to] = cand;
					q.emplace(-d[v.to], v.to);
				}
			}
		}
		return d[sink] < oo;
	}
	void calc_pot() {
		auto process = [&](int u) {
			for(int e : g[u]) {
				const auto &v = edge[e];
				if(!v.cap) continue;
				ll cand = pot[u] + v.cost;
				if(cand < pot[v.to]) {
					pot[v.to] = cand;
				}
			}
		};

		process(N - 3);
		process(start);
		for(int i = 0; i < N; i++) {
			process(i);
		}
	}
	pair<ll, ll> mincost(int source = start, int sink = target) {
		calc_pot();
		ll ans = 0, mf = 0;
		while(dijkstra(source, sink)) {
			ll f = oo;
			for(int u = sink; u != source; u = edge[ p[u] ].from)
				f = min(f, edge[ p[u] ].cap);
			mf += f;
			ans += f * (d[sink] - pot[source] + pot[sink]);
			for(int u = sink; u != source; u = edge[ p[u] ].from) {
				edge[ p[u] ].cap -= f;
				edge[ p[u] ^ 1].cap += f;
			}
			for(int i = 0; i < N; i++) pot[i] = min(oo, pot[i] + d[i]);
		}
		cerr << ans << endl;
		return {mf, ans};
	}
	void addEdge(int u, int v, ll c, ll cost) {
		// assert(cost >= 0);
		edge[ne] = {u, v, c, cost};
		g[u].push_back(ne++);
		edge[ne] = {v, u, 0,-cost};
		g[v].push_back(ne++);
	}
};

const int N = 1005;
const int M = 1000006;

int n, k;
int s[N], t[N], c[N], id[N], rid[N];

int main() {
	scanf("%d %d", &n, &k);

	for(int i = 0; i < n; i++) scanf("%d %d %d", s + i, t + i, c + i), id[i] = i;

	sort(id, id + n, [](int i, int j) {
		return s[i] < s[j];
	});

	for(int i = 0; i < n; i++) rid[ id[i] ] = i;

	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j) {
		if(s[i] + t[i] - 1 < s[j]) {
			mcmf::addEdge(id[i], id[j], 1, -c[j]);
		}
	}

	for(int i = 0; i < n; i++) {
		mcmf::addEdge(mcmf::start, id[i], 1, -c[i]);
		mcmf::addEdge(id[i], mcmf::target, 1, 0);
	}

	int st = mcmf::N - 3;
	mcmf::addEdge(st, mcmf::start, k, 0);

	mcmf::mincost(st);

	vector<bool> ans(n, false);

	for(int i = 0; i < mcmf::N; i++) {
		for(int e : mcmf::g[i]) {
			if(e & 1) continue;
			auto ed = mcmf::edge[e];
			int to = mcmf::edge[e].to;
			if(to >= n) continue;
			if(mcmf::edge[e].cap) continue;
			ans[ rid[to] ] = true;
		}
	}

	for(int i = 0; i < n; i++) {
		printf("%d%c", (int)ans[i], " \n"[i + 1 == n]);
	}
}


#include <bits/stdc++.h>

using namespace std;

namespace mcmf {
	using ll = int;
	const ll oo = 1.001e9;
	const int N = 1005, E = N * N;
	vector<int> g[N];
	int ne;
	struct Edge {
		int from, to; ll cap, cost;
	} edge[E];
	int start = N - 1, target = N - 2, p[N]; int inqueue[N];
	ll d[N];
	ll pot[N];
	bool dijkstra(int source, int sink) {
		for(int i = 0; i < N; i++) d[i] = oo;
		d[source] = 0;
		priority_queue<pair<ll, int>> q;
		q.emplace(0, source);
		ll dt; int u;
		while(!q.empty()) {
			tie(dt, u) = q.top(); q.pop(); dt = -dt;
			if(dt > d[u]) continue;
			if(u == sink) return true;
			for(int e : g[u]) {
				auto v = edge[e];
				const ll cand = d[u] + v.cost + pot[u] - pot[v.to];
				if(v.cap > 0 and cand < d[v.to]) {
					p[v.to] = e;
					d[v.to] = cand;
					q.emplace(-d[v.to], v.to);
				}
			}
		}
		return d[sink] < oo;
	}
	void calc_pot() {
		auto process = [&](int u) {
			for(int e : g[u]) {
				const auto &v = edge[e];
				if(!v.cap) continue;
				ll cand = pot[u] + v.cost;
				if(cand < pot[v.to]) {
					pot[v.to] = cand;
				}
			}
		};

		process(N - 3);
		process(start);
		for(int i = 0; i < N; i++) {
			process(i);
		}
	}
	pair<ll, ll> mincost(int source = start, int sink = target) {
		calc_pot();
		ll ans = 0, mf = 0;
		while(dijkstra(source, sink)) {
			ll f = oo;
			for(int u = sink; u != source; u = edge[ p[u] ].from)
				f = min(f, edge[ p[u] ].cap);
			mf += f;
			ans += f * (d[sink] - pot[source] + pot[sink]);
			for(int u = sink; u != source; u = edge[ p[u] ].from) {
				edge[ p[u] ].cap -= f;
				edge[ p[u] ^ 1].cap += f;
			}
			for(int i = 0; i < N; i++) pot[i] = min(oo, pot[i] + d[i]);
		}
		cerr << ans << endl;
		return {mf, ans};
	}
	void addEdge(int u, int v, ll c, ll cost) {
		// assert(cost >= 0);
		edge[ne] = {u, v, c, cost};
		g[u].push_back(ne++);
		edge[ne] = {v, u, 0,-cost};
		g[v].push_back(ne++);
	}
};

const int N = 1005;
const int M = 1000006;

int n, k;
int s[N], t[N], c[N], id[N], rid[N];

int main() {
	scanf("%d %d", &n, &k);

	for(int i = 0; i < n; i++) scanf("%d %d %d", s + i, t + i, c + i), id[i] = i;

	sort(id, id + n, [](int i, int j) {
		return s[i] < s[j];
	});

	for(int i = 0; i < n; i++) rid[ id[i] ] = i;

	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j) {
		if(s[i] + t[i] - 1 < s[j]) {
			mcmf::addEdge(id[i], id[j], 1, -c[j]);
		}
	}

	for(int i = 0; i < n; i++) {
		mcmf::addEdge(mcmf::start, id[i], 1, -c[i]);
		mcmf::addEdge(id[i], mcmf::target, 1, 0);
	}

	int st = mcmf::N - 3;
	mcmf::addEdge(st, mcmf::start, k, 0);

	mcmf::mincost(st);

	vector<bool> ans(n, false);

	for(int i = 0; i < mcmf::N; i++) {
		for(int e : mcmf::g[i]) {
			if(e & 1) continue;
			auto ed = mcmf::edge[e];
			int to = mcmf::edge[e].to;
			if(to >= n) continue;
			if(mcmf::edge[e].cap) continue;
			ans[ rid[to] ] = true;
		}
	}

	for(int i = 0; i < n; i++) {
		printf("%d%c", (int)ans[i], " \n"[i + 1 == n]);
	}
}


#include <bits/stdc++.h>

using namespace std;

namespace mcmf {
	using ll = int;
	const ll oo = 1.001e9;
	const int N = 2005, E = N * N;
	vector<int> g[N];
	int ne;
	struct Edge {
		int from, to; ll cap, cost;
	} edge[E];
	int start = N - 1, target = N - 2, p[N]; int inqueue[N];
	ll d[N];
	ll pot[N];
	bool dijkstra(int source, int sink) {
		for(int i = 0; i < N; i++) d[i] = oo;
		d[source] = 0;
		priority_queue<pair<ll, int>> q;
		q.emplace(0, source);
		ll dt; int u;
		while(!q.empty()) {
			tie(dt, u) = q.top(); q.pop(); dt = -dt;
			if(dt > d[u]) continue;
			for(int e : g[u]) {
				auto v = edge[e];
				if(!v.cap) continue;
				const ll cand = d[u] + v.cost + pot[u] - pot[v.to];
				assert(v.cost + pot[u] - pot[v.to] >= 0);
				if(cand < d[v.to]) {
					p[v.to] = e;
					d[v.to] = cand;
					q.emplace(-d[v.to], v.to);
				}
			}
		}
		return d[sink] < oo;
	}
	void calc_pot(int source, const vector<int> &order) {
		for(int u : order) {
			for(int e : g[u]) {
				const auto &v = edge[e];
				if(!v.cap) continue;
				ll cand = pot[u] + v.cost;
				if(cand < pot[v.to]) {
					pot[v.to] = cand;
				}
			}
		}
		for(int u : order) {
			for(int e : g[u]) {
				const auto &v = edge[e];
				if(!v.cap) continue;
				ll cand = pot[u] + v.cost;
				if(cand < pot[v.to]) {
					assert(false);
					pot[v.to] = cand;
				}
			}
		}
	}
	pair<ll, ll> mincost(int source, int sink, const vector<int> &order) {
		calc_pot(source, order);
		ll ans = 0, mf = 0;
		while(dijkstra(source, sink)) {
			ll f = oo;
			for(int u = sink; u != source; u = edge[ p[u] ].from)
				f = min(f, edge[ p[u] ].cap);
			mf += f;
			ans += f * (d[sink] - pot[source] + pot[sink]);
			for(int u = sink; u != source; u = edge[ p[u] ].from) {
				edge[ p[u] ].cap -= f;
				edge[ p[u] ^ 1].cap += f;
			}
			for(int i = 0; i < N; i++) pot[i] = min(oo, pot[i] + d[i]);
		}
		cerr << ans << endl;
		return {mf, ans};
	}
	void addEdge(int u, int v, ll c, ll cost) {
		// assert(cost >= 0);
		edge[ne] = {u, v, c, cost};
		g[u].push_back(ne++);
		edge[ne] = {v, u, 0,-cost};
		g[v].push_back(ne++);
	}
};

const int N = 1005;
const int M = 1000006;

int n, k;
int s[N], t[N], c[N], id[N], rid[N];

int main() {
	scanf("%d %d", &n, &k);

	for(int i = 0; i < n; i++) scanf("%d %d %d", s + i, t + i, c + i), id[i] = i;

	sort(id, id + n, [](int i, int j) {
		return s[i] < s[j];
	});

	for(int i = 0; i < n; i++) rid[ id[i] ] = i;

	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j) {
		if(s[i] + t[i] - 1 < s[j]) {
			assert(rid[i] < rid[j]);
			mcmf::addEdge(n + rid[i], rid[j], 1, -c[j]);
		}
	}

	for(int i = 0; i < n; i++) {
		mcmf::addEdge(mcmf::start, rid[i], 1, -c[i]);
		mcmf::addEdge(n + rid[i], mcmf::target, 1, 0);
		mcmf::addEdge(rid[i], n + rid[i], 1, 0);
	}

	int st = mcmf::N - 3;
	mcmf::addEdge(st, mcmf::start, k, 0);

	vector<int> order = {st, mcmf::start};
	for(int i = 0; i < n; i++) {
		order.push_back(i);
		order.push_back(n + i);
	}
	order.push_back(mcmf::target);

	mcmf::mincost(st, mcmf::target, order);

	vector<bool> ans(n, false);

	int tot = 0;
	for(int i = 0; i < mcmf::N; i++) {
		for(int e : mcmf::g[i]) {
			if(e & 1) continue;
			auto ed = mcmf::edge[e];
			if(ed.cap) continue;
			int to = ed.to;
			if(to >= n) continue;
			ans[ id[to] ] = true;
			tot += ed.cost;
		}
	}

	cerr << tot << endl;

	for(int i = 0; i < n; i++) {
		printf("%d%c", (int)ans[i], " \n"[i + 1 == n]);
	}
}


#include <bits/stdc++.h>

using namespace std;

namespace mcmf {
	using ll = int;
	const ll oo = 1.001e9;
	const int N = 2005, E = N * N;
	vector<int> g[N];
	int ne;
	struct Edge {
		int from, to; ll cap, cost;
	} edge[E];
	int start = N - 1, target = N - 2, p[N]; int inqueue[N];
	ll d[N];
	ll pot[N];
	bool dijkstra(int source, int sink) {
		for(int i = 0; i < N; i++) d[i] = oo;
		d[source] = 0;
		priority_queue<pair<ll, int>> q;
		q.emplace(0, source);
		ll dt; int u;
		while(!q.empty()) {
			tie(dt, u) = q.top(); q.pop(); dt = -dt;
			if(dt > d[u]) continue;
			if(u == sink) return true;
			for(int e : g[u]) {
				auto v = edge[e];
				const ll cand = d[u] + v.cost + pot[u] - pot[v.to];
				if(v.cap > 0 and cand < d[v.to]) {
					p[v.to] = e;
					d[v.to] = cand;
					q.emplace(-d[v.to], v.to);
				}
			}
		}
		return d[sink] < oo;
	}
	void calc_pot() {
		auto process = [&](int u) {
			for(int e : g[u]) {
				auto v = edge[e];
				if(!v.cap) continue;
				ll cand = pot[u] + v.cost;
				if(cand < pot[v.to]) {
					pot[v.to] = cand;
				}
			}
		};

		process(N - 3);
		process(start);
		for(int i = 0; i < N; i++) {
			process(i);
		}
	}
	pair<ll, ll> mincost(int source = start, int sink = target) {
		calc_pot();
		ll ans = 0, mf = 0;
		while(dijkstra(source, sink)) {
			ll f = oo;
			for(int u = sink; u != source; u = edge[ p[u] ].from)
				f = min(f, edge[ p[u] ].cap);
			mf += f;
			ans += f * (d[sink] - pot[source] + pot[sink]);
			for(int u = sink; u != source; u = edge[ p[u] ].from) {
				edge[ p[u] ].cap -= f;
				edge[ p[u] ^ 1].cap += f;
			}
			for(int i = 0; i < N; i++) pot[i] = min(oo, pot[i] + d[i]);
		}
		cerr << ans << endl;
		return {mf, ans};
	}
	void addEdge(int u, int v, ll c, ll cost) {
		// assert(cost >= 0);
		edge[ne] = {u, v, c, cost};
		g[u].push_back(ne++);
		edge[ne] = {v, u, 0,-cost};
		g[v].push_back(ne++);
	}
};

const int N = 1005;
const int M = 1000006;

int n, k;
int s[N], t[N], c[N], id[N], rid[N];

int main() {
	scanf("%d %d", &n, &k);

	for(int i = 0; i < n; i++) scanf("%d %d %d", s + i, t + i, c + i), id[i] = i;

	sort(id, id + n, [](int i, int j) {
		return s[i] < s[j];
	});

	for(int i = 0; i < n; i++) rid[ id[i] ] = i;

	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j) {
		if(s[i] + t[i] - 1 < s[j]) {
			mcmf::addEdge(id[i], id[j], 1, - c[j]);
		}
	}

	for(int i = 0; i < n; i++) {
		mcmf::addEdge(mcmf::start, id[i], 1, - c[i]);
		mcmf::addEdge(id[i], mcmf::target, 1, 0);
	}

	int st = mcmf::N - 3;
	mcmf::addEdge(st, mcmf::start, k, 0);

	mcmf::mincost(st);

	vector<bool> ans(n, false);

	for(int i = 0; i < mcmf::N; i++) {
		for(int e : mcmf::g[i]) {
			if(e & 1) continue;
			auto ed = mcmf::edge[e];
			int to = mcmf::edge[e].to;
			if(to >= n) continue;
			if(mcmf::edge[e].cap) continue;
			ans[ rid[to] ] = true;
		}
	}

	for(int i = 0; i < n; i++) {
		printf("%d%c", (int)ans[i], " \n"[i + 1 == n]);
	}
}


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

#define clr(ar) memset(ar, 0, sizeof(ar))
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define inf         freopen("in.txt", "r", stdin)
#define outf        freopen("out.txt", "w", stdout)

using namespace std;

const int MAX = 20010;

/// Min-cost Max-flow using SPFA (Shortest Path Faster Algorithm)
/// 0 Based indexed for directed weighted graphs (for undirected graphs, just add two directed edges)
namespace mcmf{
    const long long INF = 1LL << 60;

    long long dis[MAX], cap[MAX], cost[MAX];
    int n, m, s, t, to[MAX], from[MAX], last[MAX], next[MAX], adj[MAX], id[MAX];

    void init(int nodes, int source, int sink){
        m = 0, n = nodes;
        s = source, t = sink;
        for (int i = 0; i <= n; i++) last[i] = -1;
    }

    void addEdge(int u, int v, long long c, long long w,int i){
        ///cout << u << ' ' << v << ' ' << c << ' ' << w << ' '
        id[m] = i, from[m] = u, adj[m] = v, cap[m] = c, cost[m] = w, next[m] = last[u], last[u] = m++;
        id[m] = -1, from[m] = v, adj[m] = u, cap[m] = 0, cost[m] = -w, next[m] = last[v], last[v] = m++;
    }

    bool bellman_ford(){
        int i, u, v, e, flag = 1;
        for (i = 0; i < n; i++) to[i] = -1;
        for (i = 0; i < n; i++) dis[i] = INF;

        dis[s] = 0;
        for (i = 0; i < n && flag; i++){
            for (u = 0, flag = 0; u < n; u++){
                for (e = last[u]; e != -1; e = next[e]){
                    v = adj[e];
                    if (cap[e] && dis[v] > (dis[u] + cost[e])){
                        dis[v] = dis[u] + cost[e];
                        to[v] = e;
                        flag = 1;
                    }
                }
            }
        }
        ///assert(i < n); /// Negative cycle found
        return (dis[t] < INF);
    }

    pair<long long, long long> solve(){
        long long maxflow = 0, mincost = 0;

        while (bellman_ford()){
            long long aug = INF;
            for (int e = to[t]; e != -1; e = to[from[e]]) aug = min(aug, cap[e]);
            for (int e = to[t]; e != -1; e = to[from[e]]){
                mincost += (aug * cost[e]);
                cap[e] -= aug, cap[e ^ 1] += aug;
            }
            maxflow += aug;
        }
        return make_pair(mincost, maxflow);
    }
}

int s[MAX], t[MAX], c[MAX], e[MAX], prin[MAX];
vector<int> inii;

void make_unique(vector<int> &inii)
{
    sort(inii.begin(), inii.end());
    inii.resize(distance(inii.begin(), unique(inii.begin(), inii.end())));
}

int main()
{
    ios::sync_with_stdio(false);
    ///inf;
    int n, k;

    cin >> n >> k;
    FOR(i,0,n-1)
    {
        cin >> s[i] >> t[i] >> c[i];
        inii.push_back( s[i] );
        inii.push_back( s[i] + t[i] );
    }

    make_unique(inii);
    FOR(i,0,n-1)
    {
        e[i] = lower_bound(inii.begin(), inii.end(), s[i] + t[i]) - inii.begin(); e[i]++;
        s[i] = lower_bound(inii.begin(), inii.end(), s[i]) - inii.begin(); s[i]++;
    }

    int src = 0, des = inii.size() + 1;
    mcmf::init(des + 1, src, des);

    FOR(i,0,(int)des-1)mcmf::addEdge(i, i + 1, k, 0, -1);

    FOR(i,0,n-1)mcmf::addEdge(s[i], e[i], 1, -c[i], i);

    pair<int,int> oop = mcmf::solve();
    ///cout << oop.first << endl;

    for(int i = 0; i <mcmf::m; i++)
        if(mcmf::id[i] != -1 && mcmf::cap[i] == 0) prin[ mcmf::id[i] ] = 1;
            ///cout << mcmf::id[i] << ' ' << mcmf::from[i] << ' ' << mcmf::adj[i] << endl;

    ///cout << endl;
    FOR(i,0,n-1) cout << prin[i] << ' ';

    return 0;
}


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

#define clr(ar) memset(ar, 0, sizeof(ar))
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define inf         freopen("in.txt", "r", stdin)
#define outf        freopen("out.txt", "w", stdout)

using namespace std;

const int MAX = 20010;

/// Min-cost Max-flow using SPFA (Shortest Path Faster Algorithm)
/// 0 Based indexed for directed weighted graphs (for undirected graphs, just add two directed edges)
namespace mcmf{
    const long long INF = 1LL << 60;

    long long dis[MAX], cap[MAX], cost[MAX];
    int n, m, s, t, to[MAX], from[MAX], last[MAX], next[MAX], adj[MAX], id[MAX];

    void init(int nodes, int source, int sink){
        m = 0, n = nodes;
        s = source, t = sink;
        for (int i = 0; i <= n; i++) last[i] = -1;
    }

    void addEdge(int u, int v, long long c, long long w,int i){
        ///cout << u << ' ' << v << ' ' << c << ' ' << w << ' '
        id[m] = i, from[m] = u, adj[m] = v, cap[m] = c, cost[m] = w, next[m] = last[u], last[u] = m++;
        id[m] = -1, from[m] = v, adj[m] = u, cap[m] = 0, cost[m] = -w, next[m] = last[v], last[v] = m++;
    }

    bool bellman_ford(){
        int i, u, v, e, flag = 1;
        for (i = 0; i < n; i++) to[i] = -1;
        for (i = 0; i < n; i++) dis[i] = INF;

        dis[s] = 0;
        for (i = 0; i < n && flag; i++){
            for (u = 0, flag = 0; u < n; u++){
                for (e = last[u]; e != -1; e = next[e]){
                    v = adj[e];
                    if (cap[e] && dis[v] > (dis[u] + cost[e])){
                        dis[v] = dis[u] + cost[e];
                        to[v] = e;
                        flag = 1;
                    }
                }
            }
        }
        ///assert(i < n); /// Negative cycle found
        return (dis[t] < INF);
    }

    pair<long long, long long> solve(){
        long long maxflow = 0, mincost = 0;

        while (bellman_ford()){
            long long aug = INF;
            for (int e = to[t]; e != -1; e = to[from[e]]) aug = min(aug, cap[e]);
            for (int e = to[t]; e != -1; e = to[from[e]]){
                mincost += (aug * cost[e]);
                cap[e] -= aug, cap[e ^ 1] += aug;
            }
            maxflow += aug;
        }
        return make_pair(mincost, maxflow);
    }
}

int s[MAX], t[MAX], c[MAX], e[MAX], prin[MAX];
vector<int> inii;

void make_unique(vector<int> &inii)
{
    sort(inii.begin(), inii.end());
    inii.resize(distance(inii.begin(), unique(inii.begin(), inii.end())));
}

int main()
{
    ios::sync_with_stdio(false);
    ///inf;
    int n, k;

    cin >> n >> k;
    FOR(i,0,n-1)
    {
        cin >> s[i] >> t[i] >> c[i];
        inii.push_back( s[i] );
        inii.push_back( s[i] + t[i] );
    }

    make_unique(inii);
    FOR(i,0,n-1)
    {
        e[i] = lower_bound(inii.begin(), inii.end(), s[i] + t[i]) - inii.begin(); e[i]++;
        s[i] = lower_bound(inii.begin(), inii.end(), s[i]) - inii.begin(); s[i]++;
    }

    int src = 0, des = inii.size() + 1;
    mcmf::init(des + 1, src, des);

    FOR(i,0,(int)inii.size() - 2)mcmf::addEdge(i, i + 1, k, 0, -1);
    mcmf::addEdge(src, 0, k, 0, -1);mcmf::addEdge((int)inii.size() - 1, (int)des, k, 0, -1);
    FOR(i,0,n-1)mcmf::addEdge(s[i], e[i], 1, -c[i], i);

    pair<int,int> oop = mcmf::solve();
    ///cout << oop.first << endl;

    for(int i = 0; i <mcmf::m; i++)
        if(mcmf::id[i] != -1 && mcmf::cap[i] == 0) prin[ mcmf::id[i] ] = 1;
            ///cout << mcmf::id[i] << ' ' << mcmf::from[i] << ' ' << mcmf::adj[i] << endl;

    ///cout << endl;
    FOR(i,0,n-1) cout << prin[i] << ' ';

    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
const int Inf=0x3f3f3f3f;

struct Edge{
	int to,cap,rev,cost;
	Edge(int to,int cap,int rev,int cost):to(to),cap(cap),rev(rev),cost(cost){}
};

vector<Edge> egs[2005];
int prv[2005],pre[2005];
int dist[2005],sh[2005];
int whr[2005][2005];
int n,m;

void NewEdge(int u,int v,int cap,int cost){
	//cerr<<u<<' '<<v<<' '<<cost<<endl;
	whr[u][v]=egs[u].size();
	whr[v][u]=egs[v].size();
	egs[u].push_back(Edge(v,cap,egs[v].size(),cost));
	egs[v].push_back(Edge(u,0,egs[u].size()-1,-cost));
}

bool Bellman_ford(int frm,int to){
	memset(dist,0x3f,sizeof(dist));
	dist[frm]=0;
	bool upd=1;
	while(upd){
		upd=0;
		for(int i=0;i<=2*n+2;i++){
			if(dist[i]==Inf){
				continue;
			}
			for(int j=0;j<egs[i].size();j++){
				Edge &e=egs[i][j];
				if(e.cap&&dist[i]+e.cost<dist[e.to]){
					dist[e.to]=dist[i]+e.cost;
					prv[e.to]=i;
					pre[e.to]=j;
					//cerr<<i<<' '<<j<<' '<<dist[i]<<' '<<dist[to]<<endl;
					upd=1;
				}
			}
		}
	}
	return dist[to]!=Inf;
}

int calc(int frm,int to){
	int cost=0;
	while(Bellman_ford(frm,to)){
		int Cap=Inf;
		for(int i=to;i!=frm;i=prv[i]){
			Cap=min(Cap,egs[prv[i]][pre[i]].cap);
		}
		for(int i=to;i!=frm;i=prv[i]){
			egs[prv[i]][pre[i]].cap-=Cap;
			egs[i][egs[prv[i]][pre[i]].rev].cap+=Cap;
		}
		cost+=Cap*dist[to];
	}
	return cost;
}

int s[1005],t[1005],c[1005];

int main(){
	scanf("%d%d",&n,&m);
	NewEdge(0,2*n+1,m,0);
	for(int i=1;i<=n;i++){
		scanf("%d%d%d",s+i,t+i,c+i);
		t[i]+=s[i];
		NewEdge(2*n+1,i,1,0);
		NewEdge(i,i+n,1,-c[i]);
		NewEdge(i+n,2*n+2,1,0);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(t[i]<=s[j]){
				NewEdge(i+n,j,1,0);
			}
		}
	}
	calc(0,2*n+2);
	for(int i=1;i<=n;i++){
		if(egs[i][whr[i][i+n]].cap==0){
			printf("1 ");
		}else{
			printf("0 ");
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int INF = 0x7fffffff;

struct MEdge
{
	int from, to, cap, cost;
	int index;

	MEdge(int from, int to, int cap, int cost, int index)
		: from(from), to(to), cap(cap), cost(cost), index(index)
	{
	}
};

struct MCMF
{
	int n, s, t, flow, cost;
	vector<MEdge> es;
	vector<vector<int>> G;
	vector<int> d, p, a; // dis, prev, add
	deque<bool> in;

	MCMF(int n, int s, int t) :
		n(n), s(s), t(t), flow(0), cost(0), G(n + 1), p(n + 1), a(n + 1)
	{
	}

	void add_edge(int u, int v, int cap, int cost, int index)
	{
		G[u].push_back(es.size());
		es.emplace_back(u, v, cap, cost, index);
		G[v].push_back(es.size());
		es.emplace_back(v, u, 0, -cost, -1);
	}

	bool spfa()
	{
		d.assign(n + 1, INF);
		in.assign(n + 1, false);
		d[s] = 0;
		in[s] = true;
		a[s] = INF;
		queue<int> q;
		q.push(s);
		while (!q.empty())
		{
			int u = q.front();
			q.pop();
			in[u] = false;
			for (int& i : G[u])
			{
				MEdge& e = es[i];
				if (e.cap && d[e.to] > d[u] + e.cost)
				{
					d[e.to] = d[u] + e.cost;
					p[e.to] = i;
					a[e.to] = min(a[u], e.cap);
					if (!in[e.to])
					{
						q.push(e.to);
						in[e.to] = true;
					}
				}
			}
		}
		return d[t] != INF;
	}

	void solve()
	{
		while (spfa())
		{
			flow += a[t];
			cost += a[t] * d[t];
			int u = t;
			while (u != s)
			{
				es[p[u]].cap -= a[t];
				es[p[u] ^ 1].cap += a[t];
				u = es[p[u]].from;
			}
		}
	}
};

struct Line
{
	int s, e;
	int val;

	Line()
	{
	}

	Line(int s, int e, int val)
		: s(s), e(e), val(val)
	{
	};
};

int main()
{
	ios::sync_with_stdio(false);

	int n, k;
	cin >> n >> k;

	set<int> indexes;
	vector<Line> lines(n);
	for (auto i = 0; i < n; i++)
	{
		int s, t, c;
		cin >> s >> t >> c;

		t += s;
		lines[i] = {s, t, c};

		indexes.insert(s);
		indexes.insert(t);
	}

	auto ncnt = 1;
	map<int, int> temp;
	for (const auto& it : indexes) temp[it] = ncnt, ncnt++;
	for (auto i = 0; i < n; i++)
	{
		lines[i].s = temp[lines[i].s];
		lines[i].e = temp[lines[i].e];
	}

	MCMF qddtql(ncnt + 15, 1, ncnt);

	for (auto i = 1; i < ncnt; i++) qddtql.add_edge(i, i + 1, k, 0, -1);
	for (auto i = 0; i < lines.size(); i++) qddtql.add_edge(lines[i].s, lines[i].e, 1, -lines[i].val, i + 1);

	qddtql.solve();

	vector<int> ans(n + 10, 0);
	for (const auto& it : qddtql.es)
		if (it.cap == 0 && it.index != -1) ans[it.index]++;

	for (auto i = 1; i <= n; i++) cout << min(ans[i], 1) << " ";

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll inf = (ll)1 << 60;
const ll MAXN = 100000 + 10;

struct edge {
    ll a, b, cap, cost, flow;
    size_t back;
};

vector<edge> e;
vector<ll> g[MAXN];

void addedge(ll a, ll b, ll cap, ll cost) {
    edge e1 = {a,b,cap,cost,0,g[b].size()};
    edge e2 = {b,a,0,-cost,0,g[a].size()};
    g[a].push_back((ll) e.size());
    e.push_back(e1);
    g[b].push_back((ll) e.size());
    e.push_back(e2);
}

ll n, s, t;
ll k = inf; // The maximum amount of flow allowed

// Returns {flow,cost}
pair<ll,ll> getflow() {
    ll flow = 0, cost = 0;
    while(flow < k) {
        vector<ll> id(n, 0);
        vector<ll> d(n, inf);
        vector<ll> q(n);
        vector<ll> p(n);
        vector<size_t> p_edge(n);
        ll qh=0, qt=0;
        q[qt++] = s;
        d[s] = 0;
        while(qh != qt) {
            ll v = q[qh++];
            id[v] = 2;
            if(qh == n) qh = 0;
            for(size_t i=0; i<g[v].size(); ++i) {
                edge& r = e[g[v][i]];
                if(r.flow < r.cap && d[v] + r.cost < d[r.b]) {
                    d[r.b] = d[v] + r.cost;
                    if(id[r.b] == 0) {
                        q[qt++] = r.b;
                        if(qt == n) qt = 0;
                    }
                    else if(id[r.b] == 2) {
                        if(--qh == -1) qh = n-1;
                        q[qh] = r.b;
                    }
                    id[r.b] = 1;
                    p[r.b] = v;
                    p_edge[r.b] = i;
                }
            }
        }
        if(d[t] == inf) break;
        ll addflow = k - flow;
        for(ll v=t; v!=s; v=p[v]) {
            ll pv = p[v]; size_t pr = p_edge[v];
            addflow = min(addflow, e[g[pv][pr]].cap - e[g[pv][pr]].flow);
        }
        for(ll v=t; v!=s; v=p[v]) {
            ll pv = p[v]; size_t pr = p_edge[v], r = e[g[pv][pr]].back;
            e[g[pv][pr]].flow += addflow;
            e[g[v][r]].flow -= addflow;
            cost += e[g[pv][pr]].cost * addflow;
        }
        flow += addflow;
    }
    return {flow,cost};
}

void reset() {
    e.clear();
    for(ll i = 0; i < n; i++) {
        g[i].clear();
    }
}

struct ed {
    ll s;
    ll t;
    ll c;
};

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

    vector<ll> times;
    vector<ed> v;

    for(ll i = 0; i < n; i++) {
        ed t;
        cin >> t.s >> t.t >> t.c;
        t.t += t.s;
        times.push_back(t.s);
        times.push_back(t.t);
        v.push_back(t);
    }

    // Set up source
    times.push_back(0);
    ::s = 0;

    sort(times.begin(),times.end());
    unique(times.begin(),times.end());

    // Set up sink
    ::t = times.size();
    ::n = ::t + 1;

    // Add edges for the real edges
    for(auto i : v) {
        ll t1 = lower_bound(times.begin(),times.end(),i.s) - times.begin();
        ll t2 = lower_bound(times.begin(),times.end(),i.t) - times.begin();
        addedge(t1,t2,1,-i.c);
    }

    // Add edges for sequential times
    for(ll i = 0; i < ::n; i++) {
        addedge(i,i+1,m,0);
    }

    // Run maxflow
    pair<ll,ll> flow = getflow();

    // For each edge, print whether it's used
    for(ll i = 0; i < n*2; i+=2) {
        if(e[i].cap == e[i].flow) {
            cout << "1 ";
        }
        else {
            cout << "0 ";
        }
    }
    cout << endl;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll inf = (ll)1 << 60;
const ll MAXN = 10000 + 10;

struct edge {
    ll a, b, cap, cost, flow;
    ll back;
};

vector<edge> e;
vector<vector<ll>> g;

void addedge(ll a, ll b, ll cap, ll cost) {
    edge e1 = {a,b,cap,cost,0,(ll)g[b].size()};
    edge e2 = {b,a,0,-cost,0,(ll)g[a].size()};
    g[a].push_back((ll) e.size());
    e.push_back(e1);
    g[b].push_back((ll) e.size());
    e.push_back(e2);
}

ll n, s, t;
ll k = inf; // The maximum amount of flow allowed

// Returns {flow,cost}
pair<ll,ll> getflow() {
    ll flow = 0, cost = 0;
    while(flow < k) {
        cout << "here1" << endl;
        vector<ll> id(n, 0);
        vector<ll> d(n, inf);
        vector<ll> q(n);
        vector<ll> p(n);
        vector<ll> p_edge(n);
        ll qh=0, qt=0;
        q[qt++] = s;
        d[s] = 0;
        while(qh != qt) {
        cout << "here2" << endl;
            ll v = q[qh++];
            id[v] = 2;
            if(qh == n) qh = 0;
            for(ll i=0; i<g[v].size(); ++i) {
        cout << "here3" << endl;
                edge& r = e[g[v][i]];
                if(r.flow < r.cap && d[v] + r.cost < d[r.b]) {
                    d[r.b] = d[v] + r.cost;
                    if(id[r.b] == 0) {
                        q[qt++] = r.b;
                        if(qt == n) qt = 0;
                    }
                    else if(id[r.b] == 2) {
                        if(--qh == -1) qh = n-1;
                        q[qh] = r.b;
                    }
                    id[r.b] = 1;
                    p[r.b] = v;
                    p_edge[r.b] = i;
                }
            }
        }
        if(d[t] == inf) break;
        ll addflow = k - flow;
        for(ll v=t; v!=s; v=p[v]) {
        cout << "here4" << endl;
            ll pv = p[v]; ll pr = p_edge[v];
            addflow = min(addflow, e[g[pv][pr]].cap - e[g[pv][pr]].flow);
        }
        for(ll v=t; v!=s; v=p[v]) {
        cout << "here5" << endl;
            ll pv = p[v]; ll pr = p_edge[v], r = e[g[pv][pr]].back;
            e[g[pv][pr]].flow += addflow;
            e[g[v][r]].flow -= addflow;
            cost += e[g[pv][pr]].cost * addflow;
        }
        cout <<"here6" << endl;
        flow += addflow;
        cout << "here7 " << flow << " " << addflow << endl;
    }
    cout << "ret" << endl;
    return {flow,cost};
}

void reset() {
    e.clear();
    for(ll i = 0; i < n; i++) {
        g[i].clear();
    }
}

struct ed {
    ll s;
    ll t;
    ll c;
};

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

    vector<ll> times;
    vector<ed> v;

    for(ll i = 0; i < n; i++) {
        ed t;
        cin >> t.s >> t.t >> t.c;
        t.t += t.s;
        times.push_back(t.s);
        times.push_back(t.t);
        v.push_back(t);
    }

    // Set up source
    times.push_back(0);
    ::s = 0;

    sort(times.begin(),times.end());
    unique(times.begin(),times.end());

    // Set up sink
    ::t = times.size();
    ::n = ::t + 1;

    g.resize(MAXN);

    set<pair<int,int>> seen;

    // Add edges for the real edges
    for(auto i : v) {
        ll t1 = lower_bound(times.begin(),times.end(),i.s) - times.begin();
        ll t2 = lower_bound(times.begin(),times.end(),i.t) - times.begin();
        cout << t1 << " " << t2 << endl;
        addedge(t1,t2,1,-i.c);
    }

    // Add edges for sequential times
    for(ll i = 0; i < ::n; i++) {
        addedge(i,i+1,m,0);
    }

    // Run maxflow
    pair<ll,ll> flow = getflow();

    // For each edge, print whether it's used
    for(ll i = 0; i < n*2; i+=2) {
        if(e[i].cap == e[i].flow) {
            cout << "1 ";
        }
        else {
            cout << "0 ";
        }
    }
    cout << endl;
}


/**
 * Created with IntelliJ IDEA.
 * User: akashm
 * Date: 6/10/13
 * Time: 4:00 PM
 * To change this template use File | Settings | File Templates.
 */

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        int m = in.nextInt();
        for (int i = 0; i < m; i++) {
            int l = in.nextInt() - 1;
            int r = in.nextInt() - 1;
            int count = 0;
            for(int j = l; j + 1 <= r; j++) {
                if(s.charAt(j) == s.charAt(j + 1))
                    ++count;
            }
            System.out.println(count);
        }
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int[] all = new int[s.length()];
        for (int i = 1; i < all.length; i++) {
            if (s.charAt(i) == s.charAt(i - 1))
                all[i] = all[i - 1] + 1;
            else
                all[i]=all[i-1];
        }
        int n = Integer.parseInt(in.nextLine());
        for (int i = 0; i < n; i++) {
            String[] temp = in.nextLine().split(" ");
            int a = Integer.parseInt(temp[0]) - 1;
            int b = Integer.parseInt(temp[1]) - 1;
            System.out.println(all[b] - all[a]);
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        //Scanner in = new Scanner(System.in);
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        String s = in.readLine();
        int[] all = new int[s.length()];
        for (int i = 1; i < all.length; i++) {
            if (s.charAt(i) == s.charAt(i - 1))
                all[i] = all[i - 1] + 1;
            else
                all[i]=all[i-1];
        }
        int n = Integer.parseInt(in.readLine());
        for (int i = 0; i < n; i++) {
            String[] temp = in.readLine().split(" ");
            int a = Integer.parseInt(temp[0]) - 1;
            int b = Integer.parseInt(temp[1]) - 1;
            System.out.println(all[b] - all[a]);
        }
    }
}


import java.util.Scanner;

public class IlyaQueries {
public static void main(String[] args)
{
    Scanner s=new Scanner(System.in);
    String str=s.next();
    int m=s.nextInt();
    int[][] query=new int[m][];
    for(int i=0;i<m;i++)
    {   query[i]=new int[2];
        query[i][0]=s.nextInt();
        query[i][1]=s.nextInt();
    }
    int[] temp=new int[str.length()];

    temp[0]=0;
    for(int i=1;i<str.length();i++)
        if(str.charAt(i)==str.charAt(i-1))
        {
            temp[i]=temp[i-1]+1;
        }
        else
        {
            temp[i]=temp[i-1];
        }

    for(int i=0;i<m;i++)
    {
        System.out.println(temp[query[i][1]-1]-temp[query[i][0]-1]);

    }

}
}


import java.util.Scanner;

public class IlyaQueries {
public static void main(String[] args)
{
    Scanner s=new Scanner(System.in);
    String str=s.next();
    int m=s.nextInt();
    int[][] query=new int[m][];
    int count=0;
    for(int i=0;i<m;i++)
    {
        query[i]=new int[2];
        query[i][0]=s.nextInt();
        query[i][1]=s.nextInt();
        for(int j=query[i][0]-1;j<=query[i][1]-2;j++)
            if(str.charAt(j)==str.charAt(j+1))
                count++;
    System.out.println(count);
    count=0;

    }

}
}


import java.util.Scanner;

public class IlyaQueries {
public static void main(String[] args)
{
    Scanner s=new Scanner(System.in);
    String str=s.next();
    int m=s.nextInt();
    int[][] query=new int[m][];
    for(int i=0;i<m;i++)
    {
        query[i]=new int[2];
        query[i][0]=s.nextInt();
        query[i][1]=s.nextInt();

    }
    int count=0;;
    for(int i=0;i<m;i++)
    {   for(int j=query[i][0]-1;j<=query[i][1]-2;j++)
            if(str.charAt(j)==str.charAt(j+1))
                count++;
    System.out.println(count);
    count=0;
    }
}
}


import java.util.*;

public class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        String line = sc.next();
        char[] c = line.toCharArray();

        int[] cnt = new int[line.length()+1];
        for(int i=1; i<=line.length(); i++){
            cnt[i] += cnt[i-1];
            if(i!=line.length() && c[i-1]==c[i]) cnt[i]++;
        }

        int m = sc.nextInt();
        for(int i=0; i<m; i++){
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;
            System.out.println(cnt[b] - cnt[a]);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author @Ziklon
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskB {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        String S = in.nextString();
        int M = in.nextInt();
        int P1[] = new int[S.length() + 3];
        int P2[] = new int[S.length() + 3];
        for (int i = 1; i <= S.length(); i++) {
            P1[i] += P1[i - 1];
            P2[i] += P2[i - 1];
            if (i >= 2 && S.charAt(i - 1) == '.' && S.charAt(i - 2) == '.') P1[i] += 1;
            if (i >= 2 && S.charAt(i - 1) == '#' && S.charAt(i - 2) == '#') P2[i] += 1;
        }
        for (int i = 0; i < M; i++) {
            int li = in.nextInt(), ri = in.nextInt();
            int ans=0;
            ans+=P1[ri]-P1[li];
            ans+=P2[ri]-P2[li];
            out.printLine(ans);
        }
    }
}

class InputReader {
    InputStream stream;
    byte[] buf = new byte[1024];
    int curChar, numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    private int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String nextString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

    }


import java.util.*;
import java.io.*;
public class a {
public static void main(String[] args) throws IOException
{
    input.init(System.in);
    PrintWriter out = new PrintWriter(System.out);
    String s = input.next();
    int n = s.length(), m = input.nextInt();
    IT it = new IT(n);
    for(int i = 0; i<n-1; i++)
        if(s.charAt(i) == s.charAt(i+1))
            it.add(i,i,1);
    for(int i = 0; i<m; i++)
    {
        int a = input.nextInt(), b = input.nextInt();
        out.println(it.get(a-1, b-2));
    }
    out.close();
}
public static class input {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
}
static class IT
{
    int[] left,right, val, a, b;
    IT(int n)
    {
        left = new int[4*n];
        right = new int[4*n];
        val = new int[4*n];
        a = new int[4*n];
        b = new int[4*n];
        init(0,0, n);
    }
    int init(int at, int l, int r)
    {
        a[at] = l;
        b[at] = r;
        if(l==r)
            left[at] = right [at] = -1;
        else
        {
            int mid = (l+r)/2;
            left[at] = init(2*at+1,l,mid);
            right[at] = init(2*at+2,mid+1,r);
        }
        return at++;
    }
    //return the sum over [x,y]
    int get(int x, int y)
    {
        return go(x,y, 0);
    }
    int go(int x,int y, int at)
    {
        if(at==-1) return 0;
        if(x <= a[at] && y>= b[at]) return val[at];
        if(y<a[at] || x>b[at]) return 0;
        return go(x, y, left[at]) + go(x, y, right[at]);
    }
    //add v to elements x through y
    void add(int x, int y, int v)
    {
        go3(x, y, v, 0);
    }
    void go3(int x, int y, int v, int at)
    {
        if(at==-1) return;
        if(y < a[at] || x > b[at]) return;
        val[at] += (Math.min(b[at], y) - Math.max(a[at], x) + 1)*v;
        go3(x, y, v, left[at]);
        go3(x, y, v, right[at]);
    }
}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class B implements Runnable {

	private void solve() throws IOException {
		String s = nextToken();

		int[] cum = new int[s.length() + 1];
		for (int i = 0; i < s.length(); i++) {
			if (i + 1 < s.length() && s.charAt(i) == s.charAt(i + 1)) {
				if (i - 1 < 0)
					cum[i + 1] = 1;
				else
					cum[i + 1] = cum[i] + 1;
			} else {
				cum[i + 1] = cum[i];
			}
		}

		int m = nextInt();
		for (int i = 0; i < m; i++) {
			int l = nextInt() - 1;
			int r = nextInt() - 1;

			pl(cum[r] - cum[l]);
		}
	}

	public static void main(String[] args) {
		new B().run();
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	public void run() {
		try {
			reader = new BufferedReader(new BufferedReader(new InputStreamReader(System.in)));
			writer = new PrintWriter(System.out);
			tokenizer = null;
			solve();
			reader.close();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	BigInteger nextBigInteger() throws IOException {
		return new BigInteger(nextToken());
	}

	String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	void p(Object... objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	void pl(Object... objects) {
		p(objects);
		writer.println();
	}

	int cc;

	void pf() {
		writer.printf("Case #%d: ", ++cc);
	}

}


import java.util.*;
import java.io.*;
public class d2_186_B {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        PrintWriter pw=new PrintWriter(System.out);
        String s=sc.next();
        int n=sc.nextInt();
        for(int i=0;i<n;i++)
        {
            int c=0;
            int l=sc.nextInt()-1;
            int r=sc.nextInt()-1;
            for(int j=l;j<=(r-1);j++)
            {
                if(s.charAt(j)==s.charAt(j+1))
                    c++;

            }
            pw.println(c);

        }
        pw.flush();

    }

}


import java.util.*;
import java.io.*;
public class d2_186_B {

    /**
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int dp[]=new int[1000001];

        char a[]=br.readLine().toCharArray();
        //boolean res[]=new boolean[a.length];
        String s=br.readLine();
        String b[];
        int m=Integer.parseInt(s);
        for(int i=1;i<a.length;i++)
        {
            if(a[i]==a[i-1])
                dp[i]=dp[i-1]+1;
            else
                dp[i]=dp[i-1];
        }
        for(int i=0;i<m;i++)
        {
            s=br.readLine();
            b=s.split(" ");
            int x=Integer.parseInt(b[0])-1;
            int y=Integer.parseInt(b[1])-1;
            pw.println(dp[y]-dp[x]);
        }
        pw.flush();

    }

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;

public class B {

	static class Scanner{
		BufferedReader br=null;
		StringTokenizer tk=null;
		public Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		public String next() throws IOException{
			while(tk==null || !tk.hasMoreTokens())
				tk=new StringTokenizer(br.readLine());
			return tk.nextToken();
		}
		public int nextInt() throws NumberFormatException, IOException{
			return Integer.valueOf(next());
		}
		public double nextDouble() throws NumberFormatException, IOException{
			return Double.valueOf(next());
		}
	}

	public static void main(String args[]) throws NumberFormatException, IOException{
		Scanner sc = new Scanner();
		char[] t = sc.next().toCharArray();
		int[] s = new int[t.length];
		s[t.length - 1] = 0;
		for(int i = s.length - 2; i >= 0; i--){
			if (t[i] == t[i + 1])
				s[i] = 1;
			else
				s[i] = 0;
		}
		int[] integral = new int[t.length];
		integral[0] = s[0];
		for(int i = 1; i < t.length; i++)
			integral[i] = integral[ i - 1] + s[i];
		int M = sc.nextInt();
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		for(int i = 0; i < M; i++){
			int l = sc.nextInt();
			int r = sc.nextInt();
			l--;r--;
			int first = ((l == 0)? 0: integral[l - 1]);
			int second = integral[r - 1];
			bw.write((second - first) + "\n");
		}
		bw.flush();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
public class IlyaandQueries {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader (System.in));
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		String x = in.readLine();
		int diff [] = new int [x.length()];
		diff[0]=0;
		for(int i =1;i<diff.length;i++){
			if(x.charAt(i-1)!=x.charAt(i))
				diff[i] = diff[i-1]+1;
			else
				diff[i] = diff[i-1];
		}
		int n = Integer.parseInt(in.readLine());
		String [] all;
		for(int i = 0;i<n;i++){
			all = in.readLine().split(" ");
			int l = Integer.parseInt(all[0]);
			int r = Integer.parseInt(all[1]);
			out.println((r-l)-diff[r-1]+diff[l-1]);
		}
		out.close();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
public class IlyaandQueries {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader (System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        String x = in.readLine();
        char [] z  = x.toCharArray();
        int n = Integer.parseInt(in.readLine());
        String [] all;
        for(int i =0;i<n;i++){
            all = in.readLine().split(" ");
            int r = Integer.parseInt(all[0]);
            int l = Integer.parseInt(all[1]);
            int t = l-r;
            for(int  j= r-1;j<l-1;j++){
                if(z[j]!=z[j+1]){
                    t--;
                }
            }
            out.println(t);
        }
        out.close();
    }
}


import java.util.Scanner;

public class Prob313B {
	public static void main(String[] Args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int[] arr = new int[s.length()];
		for (int i = 1; i < s.length() ; i++)
			arr[i] = arr[i - 1] + (s.charAt(i) == s.charAt(i - 1) ? 1 : 0);
		int x = scan.nextInt();
		for (int i = 0; i < x; i++)
			System.out.println(( - arr[scan.nextInt() - 1] + arr[scan
					.nextInt() - 1]));
	}
}


import java.util.Scanner;

/**
 * User: kornilcev@realweb.ru
 * Date: 07.06.13
 * Time: 14:44
 * \0
 */
public class B {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        char[] arr = s.next().toCharArray();
        int n = s.nextInt();
        for (int i = 0; i < n; i++) {
            int l = s.nextInt();
            int r = s.nextInt();
            int res = count(arr, l, r);
            System.out.println(res);
        }
    }

    public static int count(char[] arr, int l, int r) {
        int res = 0;
        for (int i = l; i <= r - 1; ++i) {
            if (arr[i-1] == arr[i]){
                res++;
            }
        }
        return res;
    }
}


import java.util.Scanner;

/**
 * User: kornilcev@realweb.ru
 * Date: 07.06.13
 * Time: 14:44
 * \0
 */
public class B {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        char[] arr = s.next().toCharArray();
        int n = s.nextInt();
        for (int i = 0; i < n; i++) {
            int l = s.nextInt();
            int r = s.nextInt();
            int res = count(arr, l, r);
            System.out.println(res);
        }
    }

    public static int count(char[] arr, int l, int r) {
        int res = 0;
        for (int i = l; i <= r - 1; ++i) {
            if (arr[i-1] == arr[i]){
                res++;
            }
            if (res > 99999){
                return 0;
            }
        }
        return res;
    }
}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Scanner;

/**
 * User: kornilcev@realweb.ru
 * Date: 07.06.13
 * Time: 14:44
 * \0
 */
public class B {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        char[] arr = s.next().toCharArray();
        int n = s.nextInt();

        BufferedWriter b = null;
        try {

            b = new BufferedWriter(new OutputStreamWriter(System.out));
            for (int i = 0; i < n; i++) {
                int l = s.nextInt();
                int r = s.nextInt();
                int res = count(arr, l, r);
                b.write(res);
                b.newLine();
            }
        } catch (IOException ignored) {

        } finally {
            try {
                if (b != null)
                    b.flush();
            } catch (IOException ignored) {

            }
        }

    }

    public static int count(char[] arr, int l, int r) {
        int res = 0;
        for (int i = l; i <= r - 1; ++i) {
            if (arr[i - 1] == arr[i]) {
                res++;
            }
        }
        return res;
    }
}


import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * User: kornilcev@realweb.ru
 * Date: 07.06.13
 * Time: 14:44
 * \0
 */
public class B {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        char[] arr = s.next().toCharArray();
        int n = s.nextInt();
        int[] c = new int[arr.length];

        for (int i = 1; i < arr.length; i++) {
            c[i] = c[i - 1] + (c[i] == c[i - 1] ? 1:0);
        }

        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(System.out);
        PrintStream printStream = new PrintStream(bufferedOutputStream);
        for (int i = 0; i < n; i++) {
            int l = s.nextInt();
            int r = s.nextInt();
            int res = c[r-1] - c[l-1];
            printStream.println(res);
        }
        try {
            bufferedOutputStream.flush();
        } catch (IOException e) {

        }

    }

}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Scanner;

/**
 * User: kornilcev@realweb.ru
 * Date: 07.06.13
 * Time: 14:44
 * \0
 */
public class B {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        char[] arr = s.next().toCharArray();
        int n = s.nextInt();
        BufferedWriter b = null;
        try {

            b = new BufferedWriter(new OutputStreamWriter(System.out));
            for (int i = 0; i < n; i++) {
                int l = s.nextInt();
                int r = s.nextInt();
                int res = count(arr, l, r);
                b.write(res);
            }
        } catch (IOException ignored) {

        } finally {
            try {
                if (b != null)
                    b.flush();
            } catch (IOException ignored) {

            }
        }

    }

    public static int count(char[] arr, int l, int r) {
        int res = 0;
        for (int i = l; i <= r - 1; ++i) {
            if (arr[i - 1] == arr[i]) {
                res++;
            }
        }
        return res;
    }
}


import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * User: kornilcev@realweb.ru
 * Date: 07.06.13
 * Time: 14:44
 * \0
 */
public class B {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        char[] arr = s.next().toCharArray();
        int n = s.nextInt();
        int[] c = new int[arr.length];

        for (int i = 1; i < arr.length; i++) {
            c[i] = c[i - 1] + (arr[i] == arr[i - 1] ? 1:0);
        }

        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(System.out);
        PrintStream printStream = new PrintStream(bufferedOutputStream);
        for (int i = 0; i < n; i++) {
            int l = s.nextInt();
            int r = s.nextInt();
            int res = c[r-1] - c[l-1];
            printStream.println(res);
        }
        try {
            bufferedOutputStream.flush();
        } catch (IOException e) {

        }

    }

}


import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * User: kornilcev@realweb.ru
 * Date: 07.06.13
 * Time: 14:44
 * \0
 */
public class B {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        char[] arr = s.next().toCharArray();
        int n = s.nextInt();

        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(System.out);
        PrintStream printStream = new PrintStream(bufferedOutputStream);
        for (int i = 0; i < n; i++) {
            int l = s.nextInt();
            int r = s.nextInt();
            int res = count(arr, l, r);
            printStream.println(res);
        }
        try {
            bufferedOutputStream.flush();
        } catch (IOException e) {

        }

    }

    public static int count(char[] arr, int l, int r) {
        int res = 0;
        for (int i = l; i <= r - 1; ++i) {
            if (arr[i - 1] == arr[i]) {
                res++;
            }
        }
        return res;
    }
}


import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main implements Runnable {

    PrintWriter out;
    Scanner in;

    public static void main(String[] args) throws IOException {
        new Thread(new Main()).start();
    }

    public void run() {
        try {
            out = new PrintWriter(new BufferedOutputStream(System.out));
            in = new Scanner(System.in);
            solve();
            out.close();
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }

    public void solve() throws IOException {
        final char[] chars = in.nextLine().toCharArray();
        int m = in.nextInt();
        int n = chars.length;
        int[] ret = new int[n + 1];
        ret[0] = 0;
        int count = 0;
        for (int i = 1; i < n; ++i) {
            if (chars[i] == chars[i - 1]) {
                count++;
            }
            ret[i] = count;
        }
        for (int i = 0; i < m; ++i) {
            int x = in.nextInt();
            int y = in.nextInt();
            out.println(ret[y - 1] - ret[x - 1]);
        }
    }
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author coderbd
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        char[] s = in.readLine().toCharArray();
        int n = s.length;
        int[] a = new int[n];
        for (int i = 1; i < n; i++)
            a[i] = s[i-1] == s[i] ? a[i-1] + 1 : a[i-1];
        int m = in.readInt();
        for (int i = 0; i < m; i++) {
            int l = in.readInt() - 1;
            int r = in.readInt() - 1;
            out.printLine(a[r] - a[l]);
        }
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            }
            catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    private String readLine0() {
        StringBuffer buf = new StringBuffer();
        int c = read();
        while (c != '\n' && c != -1) {
            if (c != '\r')
                buf.appendCodePoint(c);
            c = read();
        }
        return buf.toString();
    }

    public String readLine() {
        String s = readLine0();
        while (s.trim().length() == 0)
            s = readLine0();
        return s;
    }

    }

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

    }