The Attack of Queen Codechef Solution | May CHALLENGE


The Attack of Queen Codechef Solution

Chef has started developing interest in playing chess, and was learning how the Queen moves.

Chef has an empty N×NN×N chessboard. He places a Queen at (X,Y)(X,Y) and wonders – What are the number of cells that are under attack by the Queen?


  • The top-left cell is (1,1)(1,1), the top-right cell is (1,N)(1,N), the bottom-left cell is (N,1)(N,1) and the bottom-right cell is (N,N)(N,N).
  • The Queen can be moved any number of unoccupied cells in a straight line vertically, horizontally, or diagonally.
  • The cell on which the Queen is present, is not said to be under attack by the Queen.

Input Format

  • The first line contains a single integer TT – the number of test cases. Then the test cases follow.
  • The first and only line of each test case contains three integers NN, XX and YY, as described in the problem statement.

Output Format

For each test case, output in a single line, the total number of cells that are under attack by the Queen.


  • 1≤T≤1041≤T≤104
  • 1≤N≤1061≤N≤106
  • 1≤X,Y≤N1≤X,Y≤N

Sample Input 1 

1 1 1
3 2 2
3 2 1
2 2 2
150 62 41

Sample Output 1 



Test case 1: The only cell on the board is (1,1)(1,1). Since Queen stands on this cell, it is not under attack.

Test case 2: The Queen can attack the following cells: {(1,1),(1,2),(1,3),(2,1),(2,3),(3,1),(3,2),(3,3)}{(1,1),(1,2),(1,3),(2,1),(2,3),(3,1),(3,2),(3,3)}.

Test case 3: The Queen can attack the following cells: {(1,1),(1,2),(2,2),(2,3),(3,1),(3,2)}{(1,1),(1,2),(2,2),(2,3),(3,1),(3,2)}.

Test case 4: The Queen can attack the following cells: {(1,1),(1,2),(2,1)}{(1,1),(1,2),(2,1)}.

The Attack of Queen Codechef  SOLUTION

Download Code
login to google play console, youtube video search by image, how to add a google account, which are the google apps, what is the google app, how to add a new google account, all the google apps, which service is the part of google, adsetting google, google data studio, google DNS, GCP console, bigquery, google studio, google api console, google app engine, anthos, google apis, google public DNS, google audio, google launcher, gcloud console, google compute engine, google webmaster console, google logged-in devices, gdrive unlimited,google console tools,google studio login,my google voice,hey google service,find similar images google, my google forms, www google com bd search, search using images in google,google image search scan,google sea console,website console google, google sound, gdrive storage for students, google site console, google console login, webmaster console, searc h console, google server down, google backup login, photo finder google, google products and services, google console tool, google image check, google cloud search is used for, google dashboard studio, google voice and audio activity,gcp dashboards, google services down, google go app, google dns down, google image identifier,check picture on google,google new launcher,google image finder online,image check google google google go, image finder on google, finding images on google, photo find google, find a picture in google, find the photo on google, picture find google, image find on google, find with photo google, image finder google online, google find with image, photo finder in google, google find image search, search using image in google, search on google with image, google server down today, google server down news

Read More Post Here

Leave a Comment

Your email address will not be published. Required fields are marked *