#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
long long n, m, s, lst[400005], nxt[400005 << 4], ed[400005 << 4],
    len[400005 << 4], tot, dis[400005], vis[400005], id[400005 << 2][2];
struct node {
  long long id, dis;
};
long long cnt;
inline bool operator<(node a, node b) { return a.dis > b.dis; }
inline void add_e(long long x, long long y, long long z) {
  ed[++tot] = y, nxt[tot] = lst[x], lst[x] = tot, len[tot] = z;
}
void build(long long p, long long l, long long r, long long tp) {
  if (l == r) {
    id[p][tp] = l;
    return;
  };
  long long mid = (l + r) >> 1;
  id[p][tp] = ++cnt;
  build(p << 1, l, mid, tp);
  build(p << 1 | 1, mid + 1, r, tp);
  if (tp == 1)
    add_e(id[p][tp], id[p << 1][tp], 0),
        add_e(id[p][tp], id[p << 1 | 1][tp], 0);
  else
    add_e(id[p << 1][tp], id[p][tp], 0),
        add_e(id[p << 1 | 1][tp], id[p][tp], 0);
}
void add1(long long p, long long x, long long y, long long k, long long l,
          long long r, long long w, long long tp) {
  if (x <= l && y >= r) {
    tp == 1 ? add_e(k, id[p][tp], w) : add_e(id[p][tp], k, w);
    return;
  }
  long long mid = (l + r) >> 1;
  if (x <= mid && y >= l) add1(p << 1, x, y, k, l, mid, w, tp);
  if (y > mid && x <= r) add1(p << 1 | 1, x, y, k, mid + 1, r, w, tp);
}
inline void add(long long l1, long long r1, long long l2, long long r2,
                long long w, long long k) {
  if (k == 1) {
    add_e(l1, l2, w);
    return;
  }
  if (k == 2) {
    add1(1, l2, r2, l1, 1, n, w, 1);
  } else {
    add1(1, l1, r1, l2, 1, n, w, 2);
  }
}
inline void dijkstra() {
  priority_queue<node> q;
  q.push((node){s, 0});
  memset(dis, 0x3f, sizeof(dis));
  dis[s] = 0;
  while (!q.empty()) {
    long long u = q.top().id;
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (long long i = lst[u]; i; i = nxt[i]) {
      if (!vis[ed[i]] && dis[ed[i]] > dis[u] + len[i]) {
        dis[ed[i]] = dis[u] + len[i];
        q.push((node){ed[i], dis[ed[i]]});
      }
    }
  }
}
int main() {
  scanf("%lld%lld%lld", &n, &m, &s);
  cnt = n;
  build(1, 1, n, 1);
  build(1, 1, n, 2);
  for (long long i = 1; i <= m; i++) {
    long long k;
    scanf("%lld", &k);
    if (k == 1) {
      long long x, y, z;
      scanf("%lld%lld%lld", &x, &y, &z);
      add(x, x, y, y, z, k);
    } else {
      long long x, l, r, z;
      scanf("%lld%lld%lld%lld", &x, &l, &r, &z);
      if (k == 3)
        add(l, r, x, x, z, k);
      else
        add(x, x, l, r, z, k);
    }
  }
  dijkstra();
  for (long long i = 1; i <= n; i++)
    printf("%lld ", dis[i] == 0x3f3f3f3f3f3f3f3f ? -1 : dis[i]);
  return 0;
}

### Prompt

Generate a cpp solution to the following problem:

Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them. 

There are n planets in their universe numbered from 1 to n. Rick is in planet number s (the earth) and he doesn't know where Morty is. As we all know, Rick owns a portal gun. With this gun he can open one-way portal from a planet he is in to any other planet (including that planet). But there are limits on this gun because he's still using its free trial.

<image>

By default he can not open any portal by this gun. There are q plans in the website that sells these guns. Every time you purchase a plan you can only use it once but you can purchase it again if you want to use it more.

Plans on the website have three types:

  1. With a plan of this type you can open a portal from planet v to planet u. 
  2. With a plan of this type you can open a portal from planet v to any planet with index in range [l, r]. 
  3. With a plan of this type you can open a portal from any planet with index in range [l, r] to planet v. 



Rick doesn't known where Morty is, but Unity is going to inform him and he wants to be prepared for when he finds and start his journey immediately. So for each planet (including earth itself) he wants to know the minimum amount of money he needs to get from earth to that planet.

Input

The first line of input contains three integers n, q and s (1 ≤ n, q ≤ 105, 1 ≤ s ≤ n) — number of planets, number of plans and index of earth respectively.

The next q lines contain the plans. Each line starts with a number t, type of that plan (1 ≤ t ≤ 3). If t = 1 then it is followed by three integers v, u and w where w is the cost of that plan (1 ≤ v, u ≤ n, 1 ≤ w ≤ 109). Otherwise it is followed by four integers v, l, r and w where w is the cost of that plan (1 ≤ v ≤ n, 1 ≤ l ≤ r ≤ n, 1 ≤ w ≤ 109).

Output

In the first and only line of output print n integers separated by spaces. i-th of them should be minimum money to get from earth to i-th planet, or  - 1 if it's impossible to get to that planet.

Examples

Input

3 5 1
2 3 2 3 17
2 3 2 2 16
2 2 2 3 3
3 3 1 1 12
1 3 3 17


Output

0 28 12 


Input

4 3 1
3 4 1 3 12
2 2 3 4 10
1 2 4 16


Output

0 -1 -1 12 

Note

In the first sample testcase, Rick can purchase 4th plan once and then 2nd plan in order to get to get to planet number 2.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
long long n, m, s, lst[400005], nxt[400005 << 4], ed[400005 << 4],
    len[400005 << 4], tot, dis[400005], vis[400005], id[400005 << 2][2];
struct node {
  long long id, dis;
};
long long cnt;
inline bool operator<(node a, node b) { return a.dis > b.dis; }
inline void add_e(long long x, long long y, long long z) {
  ed[++tot] = y, nxt[tot] = lst[x], lst[x] = tot, len[tot] = z;
}
void build(long long p, long long l, long long r, long long tp) {
  if (l == r) {
    id[p][tp] = l;
    return;
  };
  long long mid = (l + r) >> 1;
  id[p][tp] = ++cnt;
  build(p << 1, l, mid, tp);
  build(p << 1 | 1, mid + 1, r, tp);
  if (tp == 1)
    add_e(id[p][tp], id[p << 1][tp], 0),
        add_e(id[p][tp], id[p << 1 | 1][tp], 0);
  else
    add_e(id[p << 1][tp], id[p][tp], 0),
        add_e(id[p << 1 | 1][tp], id[p][tp], 0);
}
void add1(long long p, long long x, long long y, long long k, long long l,
          long long r, long long w, long long tp) {
  if (x <= l && y >= r) {
    tp == 1 ? add_e(k, id[p][tp], w) : add_e(id[p][tp], k, w);
    return;
  }
  long long mid = (l + r) >> 1;
  if (x <= mid && y >= l) add1(p << 1, x, y, k, l, mid, w, tp);
  if (y > mid && x <= r) add1(p << 1 | 1, x, y, k, mid + 1, r, w, tp);
}
inline void add(long long l1, long long r1, long long l2, long long r2,
                long long w, long long k) {
  if (k == 1) {
    add_e(l1, l2, w);
    return;
  }
  if (k == 2) {
    add1(1, l2, r2, l1, 1, n, w, 1);
  } else {
    add1(1, l1, r1, l2, 1, n, w, 2);
  }
}
inline void dijkstra() {
  priority_queue<node> q;
  q.push((node){s, 0});
  memset(dis, 0x3f, sizeof(dis));
  dis[s] = 0;
  while (!q.empty()) {
    long long u = q.top().id;
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (long long i = lst[u]; i; i = nxt[i]) {
      if (!vis[ed[i]] && dis[ed[i]] > dis[u] + len[i]) {
        dis[ed[i]] = dis[u] + len[i];
        q.push((node){ed[i], dis[ed[i]]});
      }
    }
  }
}
int main() {
  scanf("%lld%lld%lld", &n, &m, &s);
  cnt = n;
  build(1, 1, n, 1);
  build(1, 1, n, 2);
  for (long long i = 1; i <= m; i++) {
    long long k;
    scanf("%lld", &k);
    if (k == 1) {
      long long x, y, z;
      scanf("%lld%lld%lld", &x, &y, &z);
      add(x, x, y, y, z, k);
    } else {
      long long x, l, r, z;
      scanf("%lld%lld%lld%lld", &x, &l, &r, &z);
      if (k == 3)
        add(l, r, x, x, z, k);
      else
        add(x, x, l, r, z, k);
    }
  }
  dijkstra();
  for (long long i = 1; i <= n; i++)
    printf("%lld ", dis[i] == 0x3f3f3f3f3f3f3f3f ? -1 : dis[i]);
  return 0;
}

```