#include <iostream>
#include <vector>
#include <cstdint>
#include <cmath>
#include <iomanip>
#include <tuple>

typedef std::vector<std::vector<std::uint64_t>> DType;
typedef std::tuple<DType, std::uint64_t, std::uint64_t, std::uint64_t> RType;

DType MakeVector(std::size_t N){
	DType R(N);

	for (auto& o : R)o.resize(N);

	return R;
}
bool Show(RType& R){
	std::cout << "Result:Call = " << std::get<1>(R) << " Accept = " << std::get<2>(R)<<"*"<<std::get<2>(R) << " Moded@ " << std::get<3>(R) << "Count!!" << std::endl;

	for (auto& oo : std::get<0>(R)){
		for (auto& o : oo){
			std::cout << std::setw(3) << std::left << o << ' ';
		}
		std::cout << std::endl;
	}
	return true;
}
bool RollingThunder(DType& D, std::uint64_t N){

	std::int64_t X = 0, Y = 0;
	std::int64_t i = 1;
	std::int64_t L = 0, R = 0, U = 0, B = 0;

	while (i <= N){
		for (X = L; X < (D[Y].size() - R); X++, i++) D[Y][X] = i;
		U++;
		X=(D[Y].size() - R)-1;
		for (Y = U; Y < (D.size() - B); Y++, i++)D[Y][X] = i;
		R++;
		Y=(D.size() - B)-1;
		for (X=(D[Y].size() - R)-1; X >=L; X--, i++) D[Y][X] = i;
		B++;
		X=L;
		for (Y=(D.size() - B)-1; Y >=U; Y--, i++) D[Y][X] = i;
		L++;
		Y=U;
		//Show(D);
	}
	return true;
}

RType MakeHoge(std::uint64_t N){
	std::uint64_t X = std::sqrt(N);
	if (X % 2 == 0) X--;
	std::uint64_t Y = N - (X*X);
	DType D = MakeVector(X);

	RollingThunder(D, X*X);

	return std::make_tuple(D,N,X,Y);
}



int main(){
	RType R;

	for (int i = 1; i < 16; i += 2){
			R = MakeHoge(i*i);
			Show(R);
	}
	R = MakeHoge(25*25+6);
	Show(R);
	return 0;
}