This page is still under construction.

Parts of this page are still being built. What you see may change.

Flat Earth

Time limit1sMemory limit1024 MB

Summary
The Earth grows by one layer of cells each second; a car moving 2 cells per second for K seconds must reach the edge, and we count valid starting cells for each N, K.
Level

Medium7 of 10

Topics
Math, Implementation, Brute force
Solved
No attempts yet

Problem

The Earth is flat. Haeseong firmly believes this, and he wants to travel to the edge of the Earth.

The Earth has a shape divided into cells as shown below, and it has a size NN.

When the size of the Earth NN is 11, it is a square shape with 44 cells. Each time the size of the Earth grows by 11, one cell appears in an empty space adjacent to the edge of the Earth.

When the size of the Earth NN is ii, the edge of the Earth is the set of cells newly created when the size became ii.

When N=1N=1, every cell is the edge of the Earth.

In the picture above, the circled places are the edge of the Earth for N=1N=1, N=2N=2, and N=3N=3.

Haeseong can move 11 cell per second. But since the size of the Earth also grows by 11 each second, he realized that this way he can never reach the edge of the Earth, so he asked you, a wise person, for help.

Taking pity on him, you built a car that can move 22 cells per second. Sadly, in a world where an infinite power battery has not yet been invented, the car can move only for KK seconds.

Given the size of the Earth NN when Haeseong starts and the time KK during which the car can move, count the number of starting cells from which he can reach the edge of the Earth.

Input

The input is given as follows.

TT

N1N_1 K1K_1

…\dots

NTN_T KTK_T

  • The first line gives the number of test cases TT. (1≤T≤1 0001 \le T \le 1\,000)
  • From the second line, TT lines each give one test case.
  • NN is the current size of the Earth. (1≤N≤1091 \leq N \leq 10^9)
  • You can use a car that moves 22 cells per second for KK seconds. (0≤K≤1090 \le K \le 10^9)

Output

For each test case, in the order the test cases are given, output the number of cells from which the edge of the Earth can be reached, one per line, for a total of TT lines.

Examples1

  1. Example 1

    Input
    2
    5 2
    3 0
    
    Expected output
    48
    12