Jeet The Hacker !!

0

0 votes
2D Matrix, Easy
Problem

After having Hacked the accounts of many people like Instagram Account of Priyanka Chopra , the twitter account of Narendra Modi etc , Jeet has decided to go after the giant himself and now wants to Hack the Facebook account of Mark Zuckerberg.

But Facebook security is much more complex then what he had previously Hacked . After studying a lot on security systems he found that in order to hack Mark's Account he has to physically plant a bug in the main server of Facebook which is in a very secure warehouse .

In order to reach the server from the warehouse entrance ,Jeet has to make his way through a N x N grid whose security works in a particular way.The individual cells are marked from 1 to N^2 in a manner which is described by the below pseudo code

int k=1
for( i =1 : N)
{
    for ( j =1 : N)
    {
      grid[i][j]=k
      k++
    }
}

Each number in the grid represents the Catch Factor in the individual cells .Higher the catch factor higher is the probability of Jeet getting caught. Initially Jeet is on the cell having catch factor 1 i.e grid[1][1] . When Jeet is on a cell having odd Catch Factor then all the cells having Odd catch factor are blocked except the one he is current standing on .Similar is the case for cells having Even catch factors. Jeet can move in any possible direction (even Diagonally) if the path is not blocked.

Help Jeet to reach the NxN th cell in a way which involves Minimum Sum of catch factors.

INPUT

First line contains a Single integer N .

OUTPUT

print the minimum total catch factor possible.

CONSTRAINTS

1<=N<=10^6

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Green colour denotes Jeet's current cell location & Red colour denotes current blocked cells.

Hence he travels a path 1->6->11->16 so the total catch factor = 1+6+11+16 = 34

Editor Image

?