#include <iostream>
using namespace std;
class Node
{
public:
    Node(int l=0, int r=0, int h=0, Node *p=NULL)
    {
        left = l;
        right = r;
        high = h;
        next = p;
    }
//private:
    int left;//
    int right;//
    int high;//
    Node *next;//指向下个结点
};
class Wall
{
public:
    Wall()
    {
        area = 0;//
        head = new Node;
    }
    int Total();//计算面积
    int Input(Node n);//处理新输入的结点
private:
    Node *head;//头结点
    int area;//面积
};
int Wall::Total()
{
    Node *temp = head->next;
    while(temp)
    {
        area += (temp->right - temp->left)*temp->high;
        temp = temp->next;
    }
    return area;
}
int Wall::Input(Node n)
{
    Node *temp = head->next, *p = head;
    if( !temp )
    {//直接插入在头结点后面
        head->next = new Node(n.left, n.right, n.high, NULL);
        return 0;
    }
    int f_t = 0;
    while( n.left != n.right )//循环结束时候的条件
    {
        if( temp->left > n.left )
        {
            if( temp->left >= n.right )
            {
                p->next = new Node(n.left, n.right, n.high, p->next );
                n.left = n.right;
                p = p->next;
            }
            else if( temp->left < n.right && temp->right > n.right )
            {
                p->next = new Node(n.left, temp->left, n.high, p->next );
                n.left = temp->left;
                p = p->next;
                if( temp->high < n.high )
                {
                    p->next = new Node(n.left, n.right, n.high, p->next );
                    p = p->next;
                    n.left = n.right;
                    temp->left = n.right;
                }
            }
            else if( temp->right <= n.right )
            {
                p->next = new Node(n.left, temp->left, n.high, p->next );
                n.left = temp->left;
                p = p->next;
                if( temp->high < n.high )
                {
                    temp->high = n.high;
                }
                n.left = temp->right;
                if( !temp->next && n.left != n.right )
                {
                    temp->next = new Node(n.left, n.right, n.high, NULL);
                    p = temp;
                    temp = temp->next;
                    n.left = n.right;
                }
            }
        }
        else if( temp->left == n.left )
        {
            if( temp->right > n.right )
            {
                if( temp->high < n.high )
                {
                    p->next = new Node(n.left, n.right, n.high, p->next );
                    p = p->next;
                    temp->left = n.right;
                }
                n.left = n.right;
            }
            else if( temp->right <= n.right )
            {
                if( temp->high < n.high )
                {
                    temp->high = n.high;
                }
                n.left = temp->right;
                if( !temp->next && n.left != n.right )
                {
                    temp->next = new Node(n.left, n.right, n.high, NULL);
                    p = temp;
                    temp = temp->next;
                    n.left = n.right;
                }
            }
        }
        else if( temp->left < n.left && temp->right > n.left)
        {
            if( temp->right > n.right )
            {
                if( temp->high < n.high )
                {
                    p->next = new Node( temp->left, n.left, temp->high, p->next );
                    p = p->next;
                    p->next = new Node( n.left, n.right, n.high, p->next );
                    p = p->next;
                    temp->left = n.right;
                }
                n.left = n.right;
            }
            else if( temp->right <= n.right )
            {
                if( temp->high < n.high )
                {
                    p->next = new Node( temp->left, n.left, temp->high, p->next );
                    p = p->next;
                    temp->left = n.left;
                    temp->high = n.high;
                }
                n.left = temp->right;
                if( !temp->next && n.left != n.right )
                {
                    temp->next = new Node(n.left, n.right, n.high, NULL);
                    p = temp;
                    temp = temp->next;
                    n.left = n.right;
                }
            }
        }
        else if( temp->right <= n.left )
        {
            if( !temp->next )
            {
                temp->next = new Node( n.left, n.right, n.high, NULL );
                p = temp;
                temp = temp->next;
                n.left = n.right;
            }
        }
        p = p->next;
        temp = temp->next;
    }
    return 0;
}
int main()
{
    Wall w;
    Node n;
    int i=0;
    cout << "输入断的个数: "; cin >> i;
    while( i-- )
    {
        
         cin >> n.left >> n.right >> n.high;
        w.Input( n );
    }
    cout << w.Total() << endl;
    return 0;
}