function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
    var l = 1;
    while (true){
        if (input[l] == null) {
            break;
        }
        var N = parseInt(input[l][0], 10);
        var arr_KLR1 = [];  
        var arr_KLR2 = [];  
        var line;
        var lowLimit = 0;
        var Nafter = N;
        for (var i = 0; i < N; i++){
            line = input[l + i + 1].map(e => parseInt(e, 10));
            console.log
            if (line[0] === N){
                lowLimit += line[1];
                Nafter --;
            } else if (line[1] > line[2]) {
                arr_KLR1.push(line);
                lowLimit += line[2];
            } else if (line [1] < line[2]){
                line = [N - line[0], line[2], line[1]];
                arr_KLR2.push(line);
                lowLimit += line[2];
            } else {
                lowLimit += line[1];
                Nafter --;
            }
        }
        arr_KLR1.sort((a, b) => a[0] - b[0]);
        arr_KLR2.sort((a, b) => a[0] - b[0]);

        var ans = lowLimit;
        var capacity = 0;
        var oldDp = [0, 0];
        var newDp = [];
        var tmpIncrease; 
        var flag;
        for (var i = 0; i < arr_KLR1.length; i++){
            capacity = arr_KLR1[i][0];
            newDp = [0];
            tmpIncrease = arr_KLR1[i][1] - arr_KLR1[i][2];
            flag = false;
            for (var j = 1; j <= Math.min(capacity, i + 1); j++){
                if (flag || oldDp[j - 1] + tmpIncrease > oldDp[j]){
                    flag =  true;
                    newDp.push(oldDp[j - 1] +  tmpIncrease);
                } else {
                    newDp.push(oldDp[j]);
                }
            }
            newDp.push(newDp[newDp.length - 1]);
            oldDp = newDp.slice();
        }
        if (newDp.length !== 0) ans += newDp[newDp.length - 1];

        oldDp = [0, 0];
        newDp = [];
        for (var i = 0; i < arr_KLR2.length; i++){
            capacity = arr_KLR2[i][0];
            newDp = [0];
            tmpIncrease = arr_KLR2[i][1] - arr_KLR2[i][2];
            flag = false;
            for (var j = 1; j <= Math.min(capacity, i + 1); j++){
                if (flag || oldDp[j - 1] + tmpIncrease > oldDp[j]){
                    flag =  true;
                    newDp.push(oldDp[j - 1] +  tmpIncrease);
                } else {
                    newDp.push(oldDp[j]);
                }
            }
            newDp.push(newDp[newDp.length - 1]);
            oldDp = newDp.slice();
        }
        if (newDp.length !== 0)  ans += newDp[newDp.length - 1];

        console.log(ans);

        l += N + 1;
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 