int get_number(int row, int col, int n)
{
int n_1
= n - 1;
int loop1
= min(row, col);
int loop2
= min(n_1-row, n_1-col);
int loop
= min(loop1, loop2);
int line,
index_in_line;
if (col
== loop && row != loop)
{
line = 3;
index_in_line = (n_1-loop) - row;
}
else if (n_1-row
== loop)
{
line = 2;
index_in_line = (n_1-loop) - col;
}
else if (n_1-col
== loop)
{
line = 1;
index_in_line = row - loop;
}
else if (row
== loop)
{
line = 0;
index_in_line = col - loop;
}
int line_length
= n_1 - loop * 2;
int index_in_loop
= line * line_length + index_in_line;
int before_loop
= 4 * (n_1 - loop + 1) * loop;
return before_loop
+ index_in_loop + 1;
}