ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Сборники > Алгоритмы и Структуры Данных > задача:


17. Number Spiral

Задачи сборника

• 09. Weird Algorithm
• 10. А. Любовь «А»
• 11. Missing Number
• 12. D. Love-Hate
• 13. Repetitions
• 14. Increasing Array
• 15. Bit Strings
• 16. Josephus Queries
• 17. Number Spiral
• 18. Apartments
• 19. Ferris Wheel
• 20. Two Sets
• 21. Distinct Numbers
• 22. Creating Strings
• 23. Apple Division
• 24. Coin Piles
• 25. Josephus Queries

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 3000/5000/5000/5000 мс. Лимит памяти 65000/65000/65000/65000 Кб. Сложность Бета


A number spiral is an infinite grid whose upper-left square has number 1.
Here are the first five layers of the spiral:



Your task is to find out the number in row y and column x.

Input
The first input line contains an integer t: the number of tests.
After this, there are t lines, each containing integers y and x.

Output
For each test, print the number in row y and column x.

Constraints
1≤t≤105
1≤y,x≤109

Example
Input:
3
2 3
1 1
4 2
Output:
8
1
15

Для отправки решений необходимо выполнить вход.

www.contester.ru