#include <iostream>
#include <fstream>

using namespace std;

typedef struct {
 int value;
 int col;
 int row;
} Triple;


class MatrixNode {
 friend class SparseMatrix;
private:
 MatrixNode *down, *right;
 bool isHead;
 union {
  MatrixNode *next;
  Triple triple;
 };
public:
 MatrixNode(bool b, Triple *t){
  isHead = b;
  if (b){ right = down = this; }
  else triple = *t;
 }
 
};

class SparseMatrix {
private:
 int n;
 MatrixNode *headNode;
public:
 SparseMatrix(int size, ifstream& fin)
 {
  fin >> n;
  Triple a;
  a.row = size;
  a.col = size;
  a.value = n;
  headNode = new MatrixNode(false, &a);
  
  if (n == 0){ headNode->right = headNode; return; }
  MatrixNode **head = new MatrixNode*[n];
  for (int i = 0; i < n; i++)
   head[i] = new MatrixNode(true, 0);
  int currenRow = 0;
  MatrixNode* last = head[0];
  for (int i = 0; i < n; i++){
   Triple t;
   fin >> t.row >> t.col >> t.value;
   if (t.row > currenRow){
    last->right = head[currenRow];
    currenRow = t.row;
    last = head[currenRow];
   }
   last = last->right = new MatrixNode(false, &t);
   head[t.col]->next = head[t.col]->next->down = last;
   
  }
  last->right = head[currenRow];
  for (int i = 0; i < size; i++)head[i]->next->down = head[i];
  for (int j = 0; j < size - 1; j++) head[j]->next = head[j + 1];
  head[size - 1]->next = headNode;
  headNode->right = head[0];
 }

 void printMatrix(ofstream& fout)
 {
  fout << n ;
  

 }
};

int main(void)
{
 ifstream fin("SparseMatrixLinkedList.inp");
 ofstream fout("SparseMatrixLinkedList.out");
 int matrixSize = 0;
 fin >> matrixSize;

 SparseMatrix *A, *B, *C;
 A = new SparseMatrix(matrixSize, fin);
 B = new SparseMatrix(matrixSize, fin);
 //C = new SparseMatrix(matrixSize);


 //SparseMatrixMultiplication(A, B, C);
 A->printMatrix(fout);
}

원래문제는 행렬곱만드는건데 지금 생성자에서 컴파일시 동작중지뜸 ㅠ