#!/bin/python3

import math

import os

import random

import re

import sys

import itertools

# Complete the queensAttack function below.

def queensAttack(n, k, r_q, c_q, obstacles):

```
diag1_atack = 0
for i, j in zip(range(r_q, 1, -1), range(c_q, 1, -1)):
temp = [i, j]
if temp in obstacles:
break
diag1_atack = diag1_atack + 1
for i, j in zip(range(r_q+1, n+1), range(c_q+1, n+1)):
temp = [i, j]
if temp in obstacles:
break
diag1_atack = diag1_atack + 1
diag2_atack = 0
for i, j in zip(range(r_q-1, 0, -1), range(c_q+1, n+1)):
temp = [i, j]
if temp in obstacles:
break
diag2_atack = diag2_atack + 1
for i, j in zip(range(r_q+1, n+1), range(c_q-1, 0, -1)):
temp = [i, j]
if temp in obstacles:
break
diag2_atack = diag2_atack + 1
row_atack = 0
for i, j in zip(itertools.repeat(r_q), range(c_q+1, n+1)) :
temp = [i, j]
if temp in obstacles:
break
row_atack = row_atack + 1
for i, j in zip(itertools.repeat(r_q), range(c_q-1, 0, -1)):
temp = [i, j]
if temp in obstacles:
break
row_atack = row_atack + 1
col_atack = 0
for i, j in zip(range(r_q+1, n+1), itertools.repeat(c_q)) :
temp = [i, j]
if temp in obstacles:
break
col_atack = col_atack + 1
for i, j in zip(range(r_q-1, 0, -1), itertools.repeat(c_q)):
temp = [i, j]
if temp in obstacles:
break
col_atack = col_atack + 1
return (diag1_atack + diag2_atack + row_atack + col_atack)
```

if **name** == ‘**main**’:

fptr = open(os.environ[‘OUTPUT_PATH’], ‘w’)

```
nk = input().split()
n = int(nk[0])
k = int(nk[1])
r_qC_q = input().split()
r_q = int(r_qC_q[0])
c_q = int(r_qC_q[1])
obstacles = []
for _ in range(k):
obstacles.append(list(map(int, input().rstrip().split())))
result = queensAttack(n, k, r_q, c_q, obstacles)
fptr.write(str(result) + '\n')
fptr.close()
```