For a given weighted graph G(V, E) and a source r, find the source shortest path to each vertex from the source (SSSP: Single Source Shortest Path).

Constraints

* 1 ≤ |V| ≤ 100000
* 0 ≤ di ≤ 10000
* 0 ≤ |E| ≤ 500000
* There are no parallel edges
* There are no self-loops

Input

An edge-weighted graph G (V, E) and the source r.


|V| |E| r
s0 t0 d0
s1 t1 d1
:
s|E|-1 t|E|-1 d|E|-1


|V| is the number of vertices and |E| is the number of edges in G. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. r is the source of the graph.

si and ti represent source and target vertices of i-th edge (directed) and di represents the cost of the i-th edge.

Output

Print the costs of SSSP in the following format.


c0
c1
:
c|V|-1


The output consists of |V| lines. Print the cost of the shortest path from the source r to each vertex 0, 1, ... |V|-1 in order. If there is no path from the source to a vertex, print INF.

Examples

Input

4 5 0
0 1 1
0 2 4
1 2 2
2 3 1
1 3 5


Output

0
1
3
4


Input

4 6 1
0 1 1
0 2 4
2 0 1
1 2 2
3 1 1
3 2 5


Output

3
0
2
INF
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.concurrent.PriorityBlockingQueue;
/**
 * @author Chen Qiu, email:m5222104@u-aizu.ac.jp
 *@version : 2019/April
 */
public class Main {
		public static void main(String[] args) throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        out.flush();
        in.nextToken();
        int nodes_sum,edges_sum,source;
        nodes_sum=(int)in.nval;
        in.nextToken();
        edges_sum=(int)in.nval;
        in.nextToken();
        source=(int)in.nval;
        in.nextToken();
        node[] gh=new node[nodes_sum];
        for (int i = 0; i < nodes_sum; i++) {
			gh[i]=new node(i);
			if (i==source) {
				gh[i].setDistance(0);
			}		
		}       
        for(int i=0;i<edges_sum;i++){ 	
            int a = (int) in.nval;
            in.nextToken();
            int b = (int) in.nval;
            in.nextToken();
            int c = (int) in.nval;
            if(i!=edges_sum-1)
            	in.nextToken();
            gh[a].getSta_list().add(b);
            gh[a].getCost_list().add(c);
        }
        out.flush();
			Dijikstra(gh);	
			for (node ghNode : gh) {
				int temp=ghNode.getDistance();
				if (temp== 1000000000) {
					out.println("INF");
				}else
					out.println(temp);
				out.flush();
			}
		}
		public static void Dijikstra(node[] G) throws InterruptedException {
			PriorityBlockingQueue<node> queue=new PriorityBlockingQueue<node>(G.length,dComparator);
			for (int i = 0; i < G.length; i++) {
				queue.offer(G[i]);
			}
			while (!queue.isEmpty()) {
				node u=queue.take();
				//node u=queue.poll();
				for (int i = 0; i < u.getSta_list().size(); i++) {
					node temp=G[u.getSta_list().get(i)];
					int weight=RELAX(u,temp,i);
					if(queue.remove(temp)) {
						queue.offer(temp);
					}
				}
			}
		}
		public static Comparator<node> dComparator=new Comparator<node>() {
			@Override
			public int compare(node v1,node v2){
				return (int) (v1.getDistance() - v2.getDistance());
			}
		};
		public static int RELAX(node u,node j,int i) {
			int weight=u.getCost_list().get(i);
			int sum=weight+u.getDistance();
			if(j.getDistance()>sum){
				j.setDistance(sum);
				return sum;
			}
			return j.getDistance();
		}
	}
	class node{
		private int name;
		private int distance=1000000000;
		private List<Integer> sta_list=new LinkedList<>();
		private List<Integer> cost_list=new LinkedList<>();
		public node(int name) {
			this.name=name;
		}
		public int getName() {
			// TODO Auto-generated method stub
			return this.name;
		}
		public int getDistance() {
			return distance;
		}
		public void setDistance(int distance) {
			this.distance = distance;
		}
		public List<Integer> getSta_list() {
			return sta_list;
		}
		public void setSta_list(List<Integer> sta_list) {
			this.sta_list = sta_list;
		}
		public List<Integer> getCost_list() {
			return cost_list;
		}
		public void setCost_list(List<Integer> cost_list) {
			this.cost_list = cost_list;
		}
		
	}
