import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author lzh
 */
public class Main {
    private static int last = 0;
    private static List<Integer> tmp = new ArrayList<Integer>();
    private static int check(int sum,int[] lines,int[] init){
        boolean flag = lines[1] <= init[1] && lines[0] == last;
        if(flag){
            sum += lines[2];
            last = lines[1];
            tmp.add(last);
        }
        return sum;
    }
    public static void main(String[] args) {
        Scanner in  =new Scanner(System.in);
        String[] first = in.nextLine().split(" ");
        int[] init = new int[2];
        int sum = 0;
        for(int i=0;i<2;i++){
            init[i] = Integer.parseInt(first[i]);
        }
        last = init[0];
        tmp.add(last);
        while (in.hasNextLine()){
            String[] lines = in.nextLine().split(" ");
            int[] linesInt = new int[3];
            for(int i=0;i<3;i++){
                linesInt[i] = Integer.parseInt(lines[i]);
            }
            sum = check(sum,linesInt,init);
        }
        for(int i=0;i<tmp.size();i++){
            if(i == tmp.size()-1){
                System.out.print(tmp.get(i)+"("+sum+")");
            }else {
                System.out.print(tmp.get(i)+"->");
            }
        }


    }
}
