import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        People[] people = new People[n];
        
        for (int i = 0; i < n; i++) {
            int s = scan.nextInt();
            int a = scan.nextInt();
            int e = scan.nextInt();
            people[i] = new People(s, a, e);
        }
        //重写比较器,按照先排总数最小的,如果相等排前两数相和较小的
        Arrays.sort(people, new Comparator<People>() {
            @Override
            public int compare(People o1, People o2) {
                if (o1.sum > o2.sum) {
                    return 1;
                } else if (o1.sum < o2.sum) {
                    return -1;
                } else if (o1.two >= o2.two) {
                    return 1;
                } else {
                    return -1;
                }
            }
        });
        //累计发信息时刻
        long ans = 0, time = 0;
        for (int j = 0; j < n; j++) {
            ans += people[j].two + time;
            time += people[j].sum;
        }
        
        System.out.println(ans);
        scan.close();
    }
}
//新建People类型,s 进入时间 a 回答时间 e 收拾时间,two 两数和 , sum 全部时间
class People {
    int s;
    int a;
    int e;
    int two;
    int sum;
    
    People(int s, int a, int e) {
        this.s = s;
        this.a = a;
        this.e = e;
        this.two = s + a;
        this.sum = s + a + e;
    }
}

贪心算法 + 构建数据类型 https://www.lanqiao.cn/problems/1025/learning/?page=1&first_category_id=1&sort=students_count&tags=2020