Submission details
Task:Box Stack II
Sender:aalto26dw_001
Submission time:2026-09-23 17:02:38 +0300
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.00 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#16ACCEPTED0.00 sdetails
#17ACCEPTED0.00 sdetails
#18ACCEPTED0.00 sdetails
#19ACCEPTED0.00 sdetails
#20ACCEPTED0.00 sdetails
#21ACCEPTED0.00 sdetails
#22ACCEPTED0.00 sdetails
#23ACCEPTED0.00 sdetails
#24ACCEPTED0.00 sdetails
#25ACCEPTED0.00 sdetails
#26ACCEPTED0.00 sdetails
#27ACCEPTED0.00 sdetails
#28ACCEPTED0.00 sdetails
#29ACCEPTED0.00 sdetails
#30ACCEPTED0.00 sdetails
#31ACCEPTED0.00 sdetails
#32ACCEPTED0.01 sdetails
#33ACCEPTED0.00 sdetails
#34ACCEPTED0.01 sdetails
#35ACCEPTED0.01 sdetails
#36ACCEPTED0.01 sdetails
#37ACCEPTED0.01 sdetails
#38ACCEPTED0.01 sdetails
#39ACCEPTED0.00 sdetails
#40ACCEPTED0.00 sdetails
#41ACCEPTED0.01 sdetails
#42ACCEPTED0.01 sdetails
#43ACCEPTED0.01 sdetails
#44ACCEPTED0.01 sdetails
#45ACCEPTED0.01 sdetails
#46ACCEPTED0.01 sdetails
#47ACCEPTED0.01 sdetails
#48ACCEPTED0.01 sdetails
#49ACCEPTED0.01 sdetails
#50ACCEPTED0.01 sdetails
#51ACCEPTED0.01 sdetails
#52ACCEPTED0.07 sdetails
#53ACCEPTED0.07 sdetails
#54ACCEPTED0.07 sdetails
#55ACCEPTED0.07 sdetails
#56ACCEPTED0.07 sdetails
#57ACCEPTED0.07 sdetails
#58ACCEPTED0.07 sdetails
#59ACCEPTED0.07 sdetails
#60ACCEPTED0.06 sdetails
#61ACCEPTED0.06 sdetails
#62--details
#63--details
#64--details
#65--details
#66--details
#67--details
#68--details
#69--details
#70--details
#71--details
#720.33 sdetails
#732.97 sdetails

Code

#include <iostream>
#include <vector>
#include <functional>
#include <set>
#include <algorithm>
#include <stack>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <limits>

std::tuple<int> readInt1(){
    int a;
    std::cin >> a;
    return {a};
}
std::tuple<int,int> readInt2(){
    int a, b;
    std::cin >> a >> b;
    return {a,b};
}
std::tuple<int,int,int> readInt3(){
    int a, b, c;
    std::cin >> a >> b >> c;
    return {a,b,c};
}

std::vector<int> readVecInt(int n){
    std::vector<int> arr(n);
    for (int i = 0; i < n; i++){
        int a;
        std::cin >> a;
        arr[i] = a;
    }
    return arr;
}
std::vector<std::string> readVecStr(int n){
    std::vector<std::string> arr(n);
    for (int i = 0; i < n; i++){
        std::string a;
        std::cin >> a;
        arr[i] = a;
    }
    return arr;
}

std::vector<long long> readVecLong(int n){
    std::vector<long long> arr(n);
    for (int i = 0; i < n; i++){
        long long a;
        std::cin >> a;
        arr[i] = a;
    }
    return arr;
}

std::vector<std::tuple<int,int>> readVecTup2(int n){
    std::vector<std::tuple<int,int>> arr(n);
    for (int i = 0; i < n; i++){
        int a, b;
        std::cin >> a;
        std::cin >> b;
        arr[i] = {a,b};
    }
    return arr;
}

std::vector<std::tuple<int,int,int>> readVecTup3(int n){
    std::vector<std::tuple<int,int,int>> arr(n);
    for (int i = 0; i < n; i++){
        int a, b, c;
        std::cin >> a;
        std::cin >> b;
        std::cin >> c;
        arr[i] = {a,b,c};
    }
    return arr;
}
std::vector<std::tuple<int,int,int,int>> readVecTup4(int n){
    std::vector<std::tuple<int,int,int,int>> arr(n);
    for (int i = 0; i < n; i++){
        int a, b, c,d;
        std::cin >> a;
        std::cin >> b;
        std::cin >> c;
        std::cin >> d;
        arr[i] = {a,b,c,d};
    }
    return arr;
}

void printNewLine(){std::cout << "\n";}
template<typename T, typename... Ts>
std::tuple<Ts...> tail(std::tuple<T,Ts...> as){
    return std::apply([](T &a, Ts... b){return std::make_tuple(b...);},as);
}

template<typename T>
void print(T a){std::cout << std::setprecision(19) << a;}
template<typename... T>
void println(T... a);

template<typename T, typename Ts>
void print(std::tuple<T,Ts> a){
    print(std::get<0>(a));
    print(" ");
    print(std::get<1>(a));
}

template<typename T, typename... Ts>
void print(std::tuple<T,Ts...> a){
    print(std::get<0>(a));
    print(" ");
    print(tail(a));
}



template<typename T>
void print(const std::vector<T> &arr, int width = -1){
    if (width == -1) width = arr.size();
    for (int i = 0; i < (int)arr.size(); i++){
        if ((i%width) == width-1 && i != (int)arr.size()-1){
            print(" ");
            println(arr[i]);
        }else if ((i%width) == 0){        
            print(arr[i]);
        }else {
            print(" ");
            print(arr[i]);
        }
    }    
}
template<typename... T>
void println(T... a){print(a...);printNewLine();}



template<typename T>
void sorted(std::vector<T> &arr){
    std::sort(arr.begin(),arr.end(),[](const T &a, const T &b){ return a < b; });
}


template<typename T>
std::set<T> toSet(const std::vector<T> &vec){
    std::set<T> c;
    for (T a : vec){ c.emplace(a);}
    return c;
}

template<typename T, typename N>
std::vector<N> map(const std::vector<T> &a, const std::function<N(T)> &transform){
    std::vector<N> b(a.size());
    int i = 0;
    for (T x : a){
        b[i] = transform(x);
        i++;
    }
    return b;
}

template<typename N, typename M, typename R>
std::vector<R> zip(const std::vector<N> &a, const  std::vector<M> &b, const std::function<R(N,M)> &transform){
    int n = std::min(a.size(),b.size());
    std::vector<R> res(n);
    for (int i = 0; i < n; i++){
        res[i] = transform(a[i],b[i]);
    }
    return res;
}

template<typename T, typename N>
std::vector<N> convertVec(const std::vector<T> &a){
    std::vector<N> b(a.size());
    int i = 0;
    for (T x : a){
        b[i] = x;
        i++;
    }
    return b;
}
template<typename T>
std::vector<T> reverse(const std::vector<T> &a){
    std::vector<T> b(a.size());
    int i = 0;
    for (T x : a){
        b[a.size()-1-i] = x;
        i++;
    }
    return b;
}



template<typename T, typename R>
R reduce(const std::vector<T> &arr, R init, const std::function<R(const R,const T)> &transform){
    R current = init;
    for (int idx = 0; idx < (int)arr.size(); idx++){
        current = transform(current,arr[idx]);
    };
    return current;
}
template<typename T>
T max(const std::vector<T> &arr){return reduce(arr, arr[0], static_cast<std::function<T(const T,const T)>>(static_cast<const T& (*)(const T&, const T&)>(std::max<T>)));}
template<typename T>
T min(const std::vector<T> &arr){return reduce(arr, arr[0], static_cast<std::function<T(const T,const T)>>(static_cast<const T& (*)(const T&, const T&)>(std::min<T>)));}

template<typename T>
std::function<T(const T,const T)> add(){return [](T a,T b){return a+b;};}
template<typename T>
std::function<T(const T,const T)> modAdd(T mod){return [mod](T a,T b){return (((a+b)%mod)+mod)%mod;};}
template<typename T, typename R>
std::function<R(const R,const T)> mulAdd(R mul){return [mul](R a,T b){return a+b*mul;};}
template<typename T>
T sum(const std::vector<T> &arr){return reduce(arr, 0, add<T>());}
template<typename T>
T avg(const std::vector<T> &arr){return reduce(arr, 0.0, mulAdd<double,T>(1.0/arr.size()));}

template<typename T>
T binarySearch(T min, T max, const std::function<bool(T)> &leq){
    if (min == max) return max;
    T guess = (min+max)/2;
    if (leq(guess)){
        return binarySearch(min,guess,leq);
    }else{
        return binarySearch(guess+1,max,leq);
    }
}

template<typename T>
T binarySearchDecending(T min, T max, const std::function<bool(T)> &leq){
    std::function<bool(T)> gt = [leq](T x){
        return !leq(x);
    };
    return binarySearch(min,max+1, gt)-1;
}

template<typename T>
std::vector<T> cloneVec(std::vector<T> a){return a;}

template<typename T>
std::vector<T> padding(const std::vector<T> &initial, T num, int start, int end){
    std::vector<T> arr(start+initial.size()+end);
    for (int i = 0; i < start; i++){
        arr[i] = num;
    }
    for (int i = 0; i < (int)initial.size(); i++){
        arr[start+i] = initial[i];
    }
    for (int i = 0; i < end; i++){
        arr[start+initial.size()+i] = num;
    }
    return arr;
}

template<typename T>
int findMax(int start, int end, const std::function<T(int)> &maxHeuristic){
    T initialGuess = maxHeuristic(start);
    int index = start;
    for (int i = start; i <= end; i++){
        if (initialGuess < maxHeuristic(i)){
            initialGuess = maxHeuristic(i);
            index = i;
        }
    }
    return index;
}

template<typename T>
void operateOnMax(int start, int end, const std::function<T(int)> &maxHeuristic, const std::function<void(int)> &found){
    found(findMax(start,end,maxHeuristic));
}

template<typename T>
void stackOperate(T init, const std::function<std::vector<T>(T)> operate){
    std::stack<T> stack;
    stack.push(init);
    while (!stack.empty()){
        T next = stack.top();
        stack.pop();
        std::vector<T> nextSteps = operate(next);
        for (T a : nextSteps){
            stack.push(a);
        }
    }
}

template<typename T>
void recursiveVectorSplit(int start, int end, int distl, int distr, const std::function<T(int)> &maxHeuristic, const std::function<void(int)> &found){
    if (start == end){
        return found(start);
    }else if (end < start){
        return;
    }
    std::tuple<int,int> range = {start,end};
    std::function<std::vector<std::tuple<int,int>>(std::tuple<int,int>)> splitter = [distl, distr,&maxHeuristic,&found](std::tuple<int,int> range){
        auto [start,end] = range;
        int idx = findMax(start, end, maxHeuristic);
        found(idx);
        std::vector<std::tuple<int,int>> next;
        if (idx+distl+1 <= end){
            next.push_back({idx+distl+1,end});
        }
        if (start <= idx-distr-1){
            next.push_back({start, idx-distr-1});
        }
        return next;
    };
    stackOperate(range,splitter);
}


template<typename T>
std::vector<T> dynamicallyComputableList(int n, std::function<T(std::vector<T>&,int)> next){
    std::vector<T> arr(n);
    for (int i = 0; i < n; i++){
        arr[i] = next(arr,i);
    }
    return arr;
}
template<typename T>
int indexOfBinarySearch(const std::vector<T> &arr, const T &find){
    return binarySearch(0,(int)arr.size()-1,(std::function<bool(int)>)[&arr, &find](int guess){return find <= arr[guess];});
}

template<typename T>
std::unordered_map<T, int> indexCompress(const std::vector<T> &arr){
    std::unordered_map<T, int> compressed;
    int i = 0;
    for (T x : arr){
        if (compressed.find(x) != compressed.end()) compressed[x] = i++;
    }
    return compressed;
}   


template<typename T>
std::tuple<T, std::vector<int>> shortestPath(const std::vector<std::tuple<int, int, T>> &edgesMessy, int start, int goal){
    std::vector<std::tuple<int, int, T>> edges = edgesMessy;
    for (auto e : edgesMessy){
        auto [a,b,t] = e;
        edges.push_back({b,a,t});
    }
    shortestPathDirected(edges, start, goal);
}

template<typename T>
std::tuple<T, std::vector<int>> shortestPathDirected(const std::vector<std::tuple<int, int, T>> &edgesMessy, int start, int goal){
    //assumes all are between 0 <= n < c*(number of vertexies), where c is reasonably small constant.  
    std::vector<int> vertexies = {};
    for (auto& [s,g,c] : edgesMessy){
        vertexies.push_back(s);
        vertexies.push_back(g);
    }
    std::vector<std::tuple<int, int, T>> edges = edgesMessy;
    int mappedStart = start;
    int mappedEnd   = goal; 
    int n = max(vertexies)+1;
    std::vector<T> distance(n);
    std::vector<int> path(n);
    for (int i = 0; i < n; i++) distance[i] = std::numeric_limits<T>::max()/4;
    for (int i = 0; i < n; i++) path[i] = i;
    distance[mappedStart] = 0;
    for (int i = 1; i <= n; i++) {
        bool changed = false;
        for (auto e : edges) {
            auto [a, b, w] = e;
            if (!changed) {changed = (distance[b] != std::min(distance[b], distance[a]+w));}
            if (distance[a]+w < distance[b]){
                distance[b] = distance[a]+w;
                path[b] = a;
            }
        }
        if (!changed) break;
        if (changed && i == n){
            // handle inifnite loop This could be made to find the infinite loop instead.
            return std::tuple((T)0,(std::vector<int>){});
        }
    }
    std::vector<int> fullPath = {goal};
    while (fullPath[fullPath.size()-1] != start){
        fullPath.push_back(path[fullPath[fullPath.size()-1]]);
    }
    return std::tuple(distance[mappedEnd],reverse(fullPath));
}






template<typename T>
std::vector<T> distanceTable(const std::vector<T> &init, const  std::function<T(T,T)> &distance){
    int n = init.size();
    std::vector<T> table(n*n);
    for (int i = 0; i < n; i++){
        table[i+n*i] = init[i];
        for (int j = i-1; j >= 0; j--){
            table[j+n*i] = distance(init[j],table[j+1+n*i]);
        }
        for (int j = i+1; j < n; j++){
            table[j+n*i] = distance(table[j-1+n*i],init[j]);
        }
    }
    return table;
}

void particles(){
    auto [n] = readInt1();
    auto arr = readVecLong(n);
    std::vector<long long> table = distanceTable(arr,add<long long>());
    print(table,n);
    //println(cost[n*n-1]);
}
template<typename T>
std::vector<T> range(const std::vector<T> &a, int from, int to){
    std::vector<T> b;
    for (int i = from; i <= to; i++){
        b.push_back(a[i]);
    }
    return b;
}

template<typename T>
bool forall(const std::vector<T> &a, std::function<bool(T)> &test){
    bool res = true;
    for (auto v : a){
        res = res & test(v);
    }
    return res;
}
/*
std::vector<int> dynamicUpdater(std::vector<std::tuple<int,int>> get, std::function<int(std::unordered_map<std::tuple<int,int>, int>&,std::tuple<int,int>)> eval, std::function<std::vector<std::tuple<int,int>>(std::tuple<int,int>)> needs){
    std::map<std::tuple<int,int>, int> results;
    std::stack<std::tuple<int,int>> toDo;
    for (auto val : get){
        toDo.push(val);
    }
    std::function<bool(std::tuple<int,int>)> has = [&results](std::tuple<int,int> &value){
        return results.find(value) != results.end();
    };
    while (toDo.size() != 0){
        auto next = toDo.top();
        toDo.pop();
        if (results.find(next) != results.end()){

        } else if (forall(needs(next))){
            results[next] = eval(results,next);
        } else {
            for (auto val : needs(next)){
                toDo.push(val);
            }
        }
    }
    std::function<int(std::tuple<int,int>)> resultMap = [&results](std::tuple<int,int> &value){
        return results[value];
    };
    return map(get,resultMap);
}*/
/*

template<typename T, typename R>
std::vector<R> dynamicUpdater(std::vector<T> get, std::function<R(std::unordered_map<T, R>&,T)> eval, std::function<std::vector<T>(T)> needs){
    std::map<T, R> results;
    std::stack<T> toDo;
    for (auto val : get){
        toDo.push(val);
    }
    std::function<bool(T)> has = [&results](T &value){
        return results.find(value) != results.end();
    };
    while (toDo.size() != 0){
        auto next = toDo.top();
        toDo.pop();
        if (results.find(next) != results.end()){

        } else if (forall(needs(next))){
            results[next] = eval(results,next);
        } else {
            for (auto val : needs(next)){
                toDo.push(val);
            }
        }
    }
    std::function<R(T)> resultMap = [&results](T &value){
        return results[value];
    };
    return map(get,resultMap);
}
*/



void forestDensity(){
    auto [n,q] = readInt2();
    auto arrv = readVecStr(n);
    std::vector<int> arr(n+1);
    for (std::string s: arrv){
        arr.push_back(0);
        for (char c : s){
            if (c == '*'){
                arr.push_back(1);
            }else {
                arr.push_back(0);
            }
        }
    }
    std::vector<int> arrs = cloneVec(arr);
    for (int j = 0; j <= n; j++){
        for (int i = 1; i <= n; i++){
            arrs[i+j*(n+1)] += arrs[i+j*(n+1)-1]; 
        }
    }
    for (int j = 1; j <= n; j++){
        for (int i = 0; i <= n; i++){
            arrs[i+j*(n+1)] += arrs[i+(j-1)*(n+1)]; 
        }
    }
    //println(arrs,n+1);
    auto arrq = readVecTup4(q);
    for (auto &q :arrq){
        auto [a,b,c,d] = q;
        int y1 = a-1;
        int x1 = b-1;
        int y2 = c;
        int x2 = d;
        //println(q);
        println(arrs[x2+y2*(n+1)]-arrs[x2+y1*(n+1)]-arrs[x1+y2*(n+1)]+arrs[x1+y1*(n+1)]);
        //for (int i = a-1; i <= b-1; i++){
        //    curmin += arrv[i];
        //}
        //println(curmin);
    }
    //std::function<int(std::unordered_map<std::tuple<int,int>,int>&,std::tuple<int,int>)> eval = [&arrv](std::unordered_map<std::tuple<int,int>,int> &previous, std::tuple<int,int> next){
    //        auto [a,b] = next;
    //        if (a==b){
    //            return arrv[a-1];
    //        } else {
    //            auto [ta,tb] = binarySplit(next);
    //            int l = previous[ta];
    //            int r = previous[tb];
    //            return l^r;
    //        }
    //    };
    //std::function<std::vector<std::tuple<int,int>>(std::tuple<int,int>)> needs = [](std::tuple<int,int> next){
    //        auto [a,b] = next;
    //        if (a==b){
    //            return (std::vector<std::tuple<int,int>>){};
    //        } else {
    //            auto [ta,tb] = binarySplit(next);
    //            return (std::vector<std::tuple<int,int>>){ta,tb};
    //        }
    //    };
    //std::vector<int> res = dynamicUpdater(arrq,eval,needs);
    //print(res,1);

}


void boxStacking(){
    auto [nInit] = readInt1();
    auto arrInit = readVecTup3(nInit);
    sorted(arrInit);
    std::vector<std::tuple<int, int, int>> arr = {arrInit[0]};
    for (int i = 1; i < nInit; i++){
        auto &[a,b,c] = arr[arr.size()-1];
        auto [x,y,z] = arrInit[i];
        if (a==x && b==y){
            c += z;
        } else {
            arr.push_back({x,y,z});
        }
    }
    int n = arr.size();
    std::vector<std::tuple<int, int, long long>> edges;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            if (i == j) continue;
            auto [a,b,c] = arr[i];
            auto [x,y,z] = arr[j];
            if (a >= x && b >= y){
                edges.push_back({i,j,-z});
            }
        }
    }
    int start = n;
    int end = n+1;
    for (int i = 0; i < n; i++){
        auto [x,y,z] = arr[i];
        edges.push_back({start,i,-z});
        edges.push_back({i,end,0});
    }
    auto [cost, path] = shortestPathDirected(edges,start,end);
    println(-cost);
}





int main() {
    //std::vector<std::vector<int>> a;
    //for (int i = 0; i < 5; i++){
    //    std::vector<int> b = {1,2,3};
    //    a.push_back(b);
    //}
    //println(a,1);
    //marioKart2();
    //particles();
    boxStacking();
    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
1
7 8 3

correct output
3

user output
3

Test 2

Verdict: ACCEPTED

input
2
6 5 4
1 1 1

correct output
5

user output
5

Test 3

Verdict: ACCEPTED

input
2
3 6 7
9 7 10

correct output
17

user output
17

Test 4

Verdict: ACCEPTED

input
2
5 1 3
8 5 9

correct output
12

user output
12

Test 5

Verdict: ACCEPTED

input
3
7 7 4
2 6 9
2 5 2

correct output
15

user output
15

Test 6

Verdict: ACCEPTED

input
3
8 2 9
9 6 8
7 7 3

correct output
17

user output
17

Test 7

Verdict: ACCEPTED

input
3
1 6 6
5 1 9
10 6 10

correct output
19

user output
19

Test 8

Verdict: ACCEPTED

input
4
1 2 1
7 8 3
3 4 8
6 6 3

correct output
15

user output
15

Test 9

Verdict: ACCEPTED

input
4
8 2 9
9 6 8
7 7 3
1 6 4

correct output
17

user output
17

Test 10

Verdict: ACCEPTED

input
4
1 2 3
5 2 10
6 2 5
7 3 6

correct output
24

user output
24

Test 11

Verdict: ACCEPTED

input
4
9 7 7
3 8 3
2 2 10
10 7 4

correct output
21

user output
21

Test 12

Verdict: ACCEPTED

input
5
6 6 8
9 7 9
6 9 5
7 7 4
...

correct output
30

user output
30

Test 13

Verdict: ACCEPTED

input
5
5 10 8
10 1 2
4 10 2
3 1 4
...

correct output
14

user output
14

Test 14

Verdict: ACCEPTED

input
5
5 2 1
10 6 10
5 5 5
4 4 2
...

correct output
17

user output
17

Test 15

Verdict: ACCEPTED

input
5
6 1 8
9 3 2
6 6 9
5 9 1
...

correct output
20

user output
20

Test 16

Verdict: ACCEPTED

input
5
10 10 6
2 10 9
8 7 7
6 3 2
...

correct output
15

user output
15

Test 17

Verdict: ACCEPTED

input
5
3 1 9
9 3 4
10 10 5
1 7 4
...

correct output
20

user output
20

Test 18

Verdict: ACCEPTED

input
5
9 10 4
3 9 1
1 4 2
10 6 1
...

correct output
11

user output
11

Test 19

Verdict: ACCEPTED

input
5
1 3 8
4 5 10
8 5 10
4 6 3
...

correct output
28

user output
28

Test 20

Verdict: ACCEPTED

input
5
9 1 10
3 9 4
6 9 3
5 1 7
...

correct output
17

user output
17

Test 21

Verdict: ACCEPTED

input
5
1 4 6
5 5 1
2 4 2
1 3 9
...

correct output
18

user output
18

Test 22

Verdict: ACCEPTED

input
10
6 6 8
9 7 9
6 9 5
7 7 4
...

correct output
41

user output
41

Test 23

Verdict: ACCEPTED

input
10
5 10 8
10 1 2
4 10 2
3 1 4
...

correct output
35

user output
35

Test 24

Verdict: ACCEPTED

input
10
5 2 1
10 6 10
5 5 5
4 4 2
...

correct output
33

user output
33

Test 25

Verdict: ACCEPTED

input
10
6 1 8
9 3 2
6 6 9
5 9 1
...

correct output
21

user output
21

Test 26

Verdict: ACCEPTED

input
10
10 10 6
2 10 9
8 7 7
6 3 2
...

correct output
36

user output
36

Test 27

Verdict: ACCEPTED

input
10
3 1 9
9 3 4
10 10 5
1 7 4
...

correct output
37

user output
37

Test 28

Verdict: ACCEPTED

input
10
9 10 4
3 9 1
1 4 2
10 6 1
...

correct output
25

user output
25

Test 29

Verdict: ACCEPTED

input
10
1 3 8
4 5 10
8 5 10
4 6 3
...

correct output
33

user output
33

Test 30

Verdict: ACCEPTED

input
10
9 1 10
3 9 4
6 9 3
5 1 7
...

correct output
28

user output
28

Test 31

Verdict: ACCEPTED

input
10
1 4 6
5 5 1
2 4 2
1 3 9
...

correct output
29

user output
29

Test 32

Verdict: ACCEPTED

input
100
589284012 636562060 767928734
906523441 647212241 921212095
585063857 909729626 454895875
669546421 693523526 412726717
...

correct output
10998205207

user output
10998205207

Test 33

Verdict: ACCEPTED

input
100
447773962 773442532 122816
137572579 324627123 157577940
253498609 99147813 425825313
199995380 416515986 371043004
...

correct output
8897447989

user output
8897447989

Test 34

Verdict: ACCEPTED

input
100
468145963 198730372 27838076
590195590 467423861 520495379
451366491 344173378 354694313
165814381 219739800 750398099
...

correct output
9141888792

user output
9141888792

Test 35

Verdict: ACCEPTED

input
100
591414747 75940263 760367935
901888417 312356591 130275571
548496961 611293382 958794496
469291685 962387379 20130523
...

correct output
10698400685

user output
10698400685

Test 36

Verdict: ACCEPTED

input
100
967034924 587586158 185430194
918715995 767527830 653946995
749180621 641621091 232024335
151896000 241061404 6689688
...

correct output
12833486742

user output
12833486742

Test 37

Verdict: ACCEPTED

input
100
238363353 59249204 934941692
892631472 221963002 390559518
986350949 524427523 96444602
656854970 425992688 822387303
...

correct output
11001071375

user output
11001071375

Test 38

Verdict: ACCEPTED

input
100
958701283 356460601 224848374
881788059 68992860 44771412
397401947 115595477 638932295
106806913 568887059 653343572
...

correct output
8425454448

user output
8425454448

Test 39

Verdict: ACCEPTED

input
100
81935404 244103474 837431431
342493822 470738321 776814822
489180570 330726191 578205540
283329158 538074003 93140055
...

correct output
10342518662

user output
10342518662

Test 40

Verdict: ACCEPTED

input
100
937837681 11934038 257096283
933290530 405355767 570001955
876668629 249890139 453495728
12239373 657165788 462212374
...

correct output
8144852495

user output
8144852495

Test 41

Verdict: ACCEPTED

input
100
11139168 391337048 538883744
535937150 532332526 8099343
143698367 339543270 152590624
14304401 234675590 941909102
...

correct output
9522402349

user output
9522402349

Test 42

Verdict: ACCEPTED

input
200
589284012 636562060 767928734
906523441 647212241 921212095
585063857 909729626 454895875
669546421 693523526 412726717
...

correct output
15209742885

user output
15209742885

Test 43

Verdict: ACCEPTED

input
200
447773962 773442532 122816
137572579 324627123 157577940
253498609 99147813 425825313
199995380 416515986 371043004
...

correct output
13615506574

user output
13615506574

Test 44

Verdict: ACCEPTED

input
200
468145963 198730372 27838076
590195590 467423861 520495379
451366491 344173378 354694313
165814381 219739800 750398099
...

correct output
12798974974

user output
12798974974

Test 45

Verdict: ACCEPTED

input
200
591414747 75940263 760367935
901888417 312356591 130275571
548496961 611293382 958794496
469291685 962387379 20130523
...

correct output
15137965961

user output
15137965961

Test 46

Verdict: ACCEPTED

input
200
967034924 587586158 185430194
918715995 767527830 653946995
749180621 641621091 232024335
151896000 241061404 6689688
...

correct output
17343709538

user output
17343709538

Test 47

Verdict: ACCEPTED

input
200
238363353 59249204 934941692
892631472 221963002 390559518
986350949 524427523 96444602
656854970 425992688 822387303
...

correct output
16484729704

user output
16484729704

Test 48

Verdict: ACCEPTED

input
200
958701283 356460601 224848374
881788059 68992860 44771412
397401947 115595477 638932295
106806913 568887059 653343572
...

correct output
13668103642

user output
13668103642

Test 49

Verdict: ACCEPTED

input
200
81935404 244103474 837431431
342493822 470738321 776814822
489180570 330726191 578205540
283329158 538074003 93140055
...

correct output
12761842389

user output
12761842389

Test 50

Verdict: ACCEPTED

input
200
937837681 11934038 257096283
933290530 405355767 570001955
876668629 249890139 453495728
12239373 657165788 462212374
...

correct output
13061107314

user output
13061107314

Test 51

Verdict: ACCEPTED

input
200
11139168 391337048 538883744
535937150 532332526 8099343
143698367 339543270 152590624
14304401 234675590 941909102
...

correct output
14114713109

user output
14114713109

Test 52

Verdict: ACCEPTED

input
1000
589284012 636562060 767928734
906523441 647212241 921212095
585063857 909729626 454895875
669546421 693523526 412726717
...

correct output
33891762384

user output
33891762384

Test 53

Verdict: ACCEPTED

input
1000
447773962 773442532 122816
137572579 324627123 157577940
253498609 99147813 425825313
199995380 416515986 371043004
...

correct output
33355847789

user output
33355847789

Test 54

Verdict: ACCEPTED

input
1000
468145963 198730372 27838076
590195590 467423861 520495379
451366491 344173378 354694313
165814381 219739800 750398099
...

correct output
33709682513

user output
33709682513

Test 55

Verdict: ACCEPTED

input
1000
591414747 75940263 760367935
901888417 312356591 130275571
548496961 611293382 958794496
469291685 962387379 20130523
...

correct output
34006550890

user output
34006550890

Test 56

Verdict: ACCEPTED

input
1000
967034924 587586158 185430194
918715995 767527830 653946995
749180621 641621091 232024335
151896000 241061404 6689688
...

correct output
34976444698

user output
34976444698

Test 57

Verdict: ACCEPTED

input
1000
238363353 59249204 934941692
892631472 221963002 390559518
986350949 524427523 96444602
656854970 425992688 822387303
...

correct output
34699884028

user output
34699884028

Test 58

Verdict: ACCEPTED

input
1000
958701283 356460601 224848374
881788059 68992860 44771412
397401947 115595477 638932295
106806913 568887059 653343572
...

correct output
34046313943

user output
34046313943

Test 59

Verdict: ACCEPTED

input
1000
81935404 244103474 837431431
342493822 470738321 776814822
489180570 330726191 578205540
283329158 538074003 93140055
...

correct output
33580356050

user output
33580356050

Test 60

Verdict: ACCEPTED

input
1000
937837681 11934038 257096283
933290530 405355767 570001955
876668629 249890139 453495728
12239373 657165788 462212374
...

correct output
35744107623

user output
35744107623

Test 61

Verdict: ACCEPTED

input
1000
11139168 391337048 538883744
535937150 532332526 8099343
143698367 339543270 152590624
14304401 234675590 941909102
...

correct output
35345712189

user output
35345712189

Test 62

Verdict:

input
200000
589284012 636562060 767928734
906523441 647212241 921212095
585063857 909729626 454895875
669546421 693523526 412726717
...

correct output
526570534463

user output
(empty)

Test 63

Verdict:

input
200000
447773962 773442532 122816
137572579 324627123 157577940
253498609 99147813 425825313
199995380 416515986 371043004
...

correct output
527468957174

user output
(empty)

Test 64

Verdict:

input
200000
468145963 198730372 27838076
590195590 467423861 520495379
451366491 344173378 354694313
165814381 219739800 750398099
...

correct output
530364449483

user output
(empty)

Test 65

Verdict:

input
200000
591414747 75940263 760367935
901888417 312356591 130275571
548496961 611293382 958794496
469291685 962387379 20130523
...

correct output
531529346089

user output
(empty)

Test 66

Verdict:

input
200000
967034924 587586158 185430194
918715995 767527830 653946995
749180621 641621091 232024335
151896000 241061404 6689688
...

correct output
532748830637

user output
(empty)

Test 67

Verdict:

input
200000
238363353 59249204 934941692
892631472 221963002 390559518
986350949 524427523 96444602
656854970 425992688 822387303
...

correct output
525080370284

user output
(empty)

Test 68

Verdict:

input
200000
958701283 356460601 224848374
881788059 68992860 44771412
397401947 115595477 638932295
106806913 568887059 653343572
...

correct output
529566966249

user output
(empty)

Test 69

Verdict:

input
200000
81935404 244103474 837431431
342493822 470738321 776814822
489180570 330726191 578205540
283329158 538074003 93140055
...

correct output
521546866708

user output
(empty)

Test 70

Verdict:

input
200000
937837681 11934038 257096283
933290530 405355767 570001955
876668629 249890139 453495728
12239373 657165788 462212374
...

correct output
531573800077

user output
(empty)

Test 71

Verdict:

input
200000
11139168 391337048 538883744
535937150 532332526 8099343
143698367 339543270 152590624
14304401 234675590 941909102
...

correct output
529286403784

user output
(empty)

Test 72

Verdict:

input
200000
1000000000 1000000000 10000000...

correct output
200000000000000

user output
552894464

Test 73

Verdict:

input
200000
1000000000 1 1
1000000000 2 2
1000000000 3 3
1000000000 4 4
...

correct output
20000100000

user output
(empty)