using System;
class Program
{
//const int Haba = 5;
const int Haba = 1001;
static void Main()
{
int[,] BanArr = new int[Haba, Haba];
int X, Y;
int UB = BanArr.GetUpperBound(0);
X = Y = UB / 2;
int MoveX, MoveY;
MoveX = MoveY = 1;
int NextMove = 2;
int SetVal = 1;
BanArr[X, Y] = SetVal;
while (true) {
if (MoveX > 0) {
if (++X > UB) break;
--MoveX;
BanArr[X, Y] = ++SetVal;
continue;
}
else if (MoveX < 0) {
if (--X < 0) break;
++MoveX;
BanArr[X, Y] = ++SetVal;
continue;
}
else if (MoveY > 0) {
if (++Y > UB) break;
--MoveY;
BanArr[X, Y] = ++SetVal;
continue;
}
else if (MoveY < 0) {
if (--Y < 0) break;
++MoveY;
BanArr[X, Y] = ++SetVal;
continue;
}
if (NextMove % 2 == 0) {
MoveX = MoveY = -NextMove++;
}
else {
MoveX = MoveY = NextMove++;
}
}
if (Haba == 5) {
for (int I = 0; I <= UB; I++) {
for (int J = 0; J <= UB; J++) {
Console.Write("{0,8},", BanArr[J, I]);
}
Console.WriteLine();
}
}
long SumVal = 0;
for (int I = 0; I <= UB; I++) {
SumVal += BanArr[I, I];
if (I != UB / 2)
SumVal += BanArr[UB - I, I];
}
Console.WriteLine("合計={0}", SumVal);
}
}