#!/usr/bin/perl

use v5.30;
use strict;

my $in = 368078;

my $diam = 0;
$diam++ while $in > (2*$diam+1)*(2*$diam+1);
my $dist = 2*$diam-1;
my $dir = -1;
my $i = (2*$diam-1)*(2*$diam-1)+1;
while ($i < $in) {
	# say "\t$i $dist $dir";
	if ($dist <= $diam) {
		$dir = 1;
	} elsif ($dist > 2*$diam-1) {
		$dir = -1;
	}
	$dist += $dir;
	$i++;
}

say $dist;
