Leticia has a $9\times 9$ board. She says that two squares are [i]friends[/i] is they share a side, if they are at opposite ends of the same row or if they are at opposite ends of the same column. Every square has $4$ friends on the board. Leticia will paint every square one of three colors: green, blue or red. In each square a number will be written based on the following rules:

 - If the square is green, write the number of red friends plus twice the number of blue friends.

 - If the square is red, write the number of blue friends plus twice the number of green friends.

 - If the square is blue, write the number of green friends plus twice the number of red friends.

Considering that Leticia can choose the coloring of the squares on the board, find the maximum possible value she can obtain when she sums the numbers in all the squares.
1. **Understanding the Problem:**
   - We have a $9 \times 9$ board, which means there are $81$ squares.
   - Each square has $4$ friends: two adjacent squares (sharing a side) and two squares at the opposite ends of the same row or column.
   - Each square will be painted one of three colors: green, blue, or red.
   - The number written in each square depends on the colors of its friends.

2. **Defining the Number Calculation:**
   - If a square is green, the number written is the number of red friends plus twice the number of blue friends.
   - If a square is red, the number written is the number of blue friends plus twice the number of green friends.
   - If a square is blue, the number written is the number of green friends plus twice the number of red friends.

3. **Analyzing the Contribution of Borders:**
   - Consider each of the $\frac{81 \cdot 4}{2} = 162$ borders between two cells on the board. This calculation comes from the fact that each of the 81 squares has 4 borders, but each border is shared by two squares, so we divide by 2.
   - If two adjacent squares are the same color, there is no value added to either square.
   - If two adjacent squares are of different colors, this border contributes a $+1$ to one of the squares and $+2$ to the other, so $+3$ to the total sum of all values.

4. **Optimal Coloring Strategy:**
   - To maximize the sum, we need to maximize the number of borders between squares of different colors.
   - A checkerboard-style coloring ensures that no two adjacent cells are the same color. This means every border between two squares will contribute $+3$ to the total sum.

5. **Calculating the Maximum Sum:**
   - With a checkerboard-style coloring, all 162 borders contribute $+3$ to the total sum.
   - Therefore, the maximum possible value is $162 \cdot 3 = 486$.

The final answer is $\boxed{486}$.