304 North Cardinal St.
Dorchester Center, MA 02124

# Check Mate CodeChef Solution

## Check Mate CodeChef Solution in C++17

``````#include<bits/stdc++.h>
using namespace std;

#define ll				long long
#define pb				push_back
#define vll				vector<ll>
#define pll				pair<ll, ll>
#define F				first
#define S				second

void sol(){
ll kx, ky, r1x, r1y, r2x, r2y;
cin >> kx >> ky >> r1x >> r1y >> r2x >> r2y;

bool checkmate = false;

if(kx == 1){
if(r1y != ky+1 && r1y != ky-1 && r2y != ky+1 && r2y != ky-1 && (r1x == 2 || r2x == 2) && r1y != r2y) checkmate = true;
}
if(kx == 8){
if(r1y != ky+1 && r1y != ky-1 && r2y != ky+1 && r2y != ky-1 && (r1x == 7 || r2x == 7) && r1y != r2y) checkmate = true;
}
if(ky == 1){
if(r1x != kx+1 && r1x != kx-1 && r2x != kx+1 && r2x != kx-1 && (r1y == 2 || r2y == 2) && r1x != r2x) checkmate = true;
}
if(ky == 8){
if(r1x != kx+1 && r1x != kx-1 && r2x != kx+1 && r2x != kx-1 && (r1y == 7 || r2y == 7) && r1x != r2x) checkmate = true;
}

if(checkmate) cout << "YES\n";
else cout << "NO\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);

ll tt;
cin >> tt;
while(tt--){
sol();
}

return 0;
}``````

## Check Mate CodeChef Solution in C++14

``````#include <bits/stdc++.h>

#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("Ofast")//Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

using namespace std;

struct PairHash {inline std::size_t operator()(const std::pair<int, int> &v) const { return v.first * 31 + v.second; }};

// speed
#define Code ios_base::sync_with_stdio(false);
#define By ios::sync_with_stdio(0);
#define Sumfi cout.tie(NULL);

// alias
using ll = long long;
using ld = long double;
using ull = unsigned long long;

// constants
const ld PI = 3.14159265358979323846;  /* pi */
const ll INF = 1e18;
const ld EPS = 1e-9;
const ll MAX_N = 202020;
const ll mod = 1e9 + 7;

// typedef
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef array<ll,3> all3;
typedef array<ll,5> all5;
typedef vector<all3> vall3;
typedef vector<all5> vall5;
typedef vector<ld> vld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef deque<ll> dqll;
typedef deque<pll> dqpll;
typedef pair<string, string> pss;
typedef vector<pss> vpss;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef unordered_set<ll> usll;
typedef unordered_set<pll, PairHash> uspll;
typedef unordered_map<ll, ll> umll;
typedef unordered_map<pll, ll, PairHash> umpll;

// macros
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,m,n) for(ll i=n;i>=m;i--)
#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define INF(a) memset(a,0x3f3f3f3f3f3f3f3fLL,sizeof(a))
#define ASCEND(a) iota(all(a),0)
#define sz(x) ll((x).size())
#define BIT(a,i) (a & (1ll<<i))
#define BITSHIFT(a,i,n) (((a<<i) & ((1ll<<n) - 1)) | (a>>(n-i)))
#define pyes cout<<"YES\n";
#define pno cout<<"NO\n";
#define endl "\n"
#define pneg1 cout<<"-1\n";
#define ppossible cout<<"Possible\n";
#define pimpossible cout<<"Impossible\n";
#define TC(x) cout<<"Case #"<<x<<": ";
#define X first
#define Y second

// utility functions
template <typename T>
void print(T &&t)  { cout << t << "\n"; }
template<typename T>
void printv(vector<T>v){ll n=v.size();rep(i,0,n){cout<<v[i];if(i+1!=n)cout<<' ';}cout<<endl;}
template<typename T>
void printvln(vector<T>v){ll n=v.size();rep(i,0,n)cout<<v[i]<<endl;}
void fileIO(string in = "input.txt", string out = "output.txt") {freopen(in.c_str(),"r",stdin); freopen(out.c_str(),"w",stdout);}
template<typename T>
template<typename T, typename U>
template<typename T, typename U>

struct Combination {
vll fac, inv;
ll n, MOD;

ll modpow(ll n, ll x, ll MOD = mod) { if(!x) return 1; ll res = modpow(n,x>>1,MOD); res = (res * res) % MOD; if(x&1) res = (res * n) % MOD; return res; }

Combination(ll _n, ll MOD = mod): n(_n + 1), MOD(MOD) {
inv = fac = vll(n,1);
rep(i,1,n) fac[i] = fac[i-1] * i % MOD;
inv[n - 1] = modpow(fac[n - 1], MOD - 2, MOD);
rrep(i,1,n - 2) inv[i] = inv[i + 1] * (i + 1) % MOD;
}

ll fact(ll n) {return fac[n];}
ll nCr(ll n, ll r) {
if(n < r or n < 0 or r < 0) return 0;
return fac[n] * inv[r] % MOD * inv[n-r] % MOD;
}
};

struct Matrix {
ll r,c;
vvll matrix;
Matrix(ll r, ll c, ll v = 0): r(r), c(c), matrix(vvll(r,vll(c,v))) {}

Matrix operator*(const Matrix& B) const {
Matrix res(r, B.c);
rep(i,0,r) rep(j,0,B.c) rep(k,0,B.r) {
res.matrix[i][j] = (res.matrix[i][j] + matrix[i][k] * B.matrix[k][j] % mod) % mod;
}
return res;
}

Matrix copy() {
Matrix copy(r,c);
copy.matrix = matrix;
return copy;
}

Matrix pow(ll n) {
assert(r == c);
Matrix res(r,r);
Matrix now = copy();
rep(i,0,r) res.matrix[i][i] = 1;
while(n) {
if(n & 1) res = res * now;
now = now * now;
n /= 2;
}
return res;
}
};

// geometry data structures
template <typename T>
struct Point {
T y,x;
Point(T y, T x) : y(y), x(x) {}
Point(pair<T,T> p) : y(p.first), x(p.second) {}
Point() {}
void input() {cin>>y>>x;}
friend ostream& operator<<(ostream& os, const Point<T>& p) { os<<p.y<<' '<<p.x<<'\n'; return os;}
Point<T> operator+(Point<T>& p) {return Point<T>(y + p.y, x + p.x);}
Point<T> operator-(Point<T>& p) {return Point<T>(y - p.y, x - p.x);}
Point<T> operator*(ll n) {return Point<T>(y*n,x*n); }
Point<T> operator/(ll n) {return Point<T>(y/n,x/n); }
bool operator<(const Point &other) const {if (x == other.x) return y < other.y;return x < other.x;}
Point<T> rotate(Point<T> center, ld angle) {
ld si = sin(angle * PI / 180.), co = cos(angle * PI / 180.);
ld y = this->y - center.y;
ld x = this->x - center.x;

return Point<T>(y * co - x * si + center.y, y * si + x * co + center.x);
}
ld distance(Point<T> other) {
T dy = abs(this->y - other.y);
T dx = abs(this->x - other.x);
return sqrt(dy * dy + dx * dx);
}

T norm() { return x * x + y * y; }
};

template<typename T>
struct Line {
Point<T> A, B;
Line(Point<T> A, Point<T> B) : A(A), B(B) {}
Line() {}

void input() {
A = Point<T>();
B = Point<T>();
A.input();
B.input();
}

T ccw(Point<T> &a, Point<T> &b, Point<T> &c) {
T res = a.x * b.y + b.x * c.y + c.x * a.y;
res -= (a.x * c.y + b.x * a.y + c.x * b.y);
return res;
}

bool isIntersect(Line<T> o) {
T p1p2 = ccw(A,B,o.A) * ccw(A,B,o.B);
T p3p4 = ccw(o.A,o.B,A) * ccw(o.A,o.B,B);
if (p1p2 == 0 && p3p4 == 0) {
pair<T,T> p1(A.y, A.x), p2(B.y,B.x), p3(o.A.y, o.A.x), p4(o.B.y, o.B.x);
if (p1 > p2) swap(p2, p1);
if (p3 > p4) swap(p3, p4);
return p3 <= p2 && p1 <= p4;
}
return p1p2 <= 0 && p3p4 <= 0;
}

pair<bool,Point<ld>> intersection(Line<T> o) {
if(!this->intersection(o)) return {false, {}};
ld det = 1. * (o.B.y-o.A.y)*(B.x-A.x) - 1.*(o.B.x-o.A.x)*(B.y-A.y);
ld t = ((o.B.x-o.A.x)*(A.y-o.A.y) - (o.B.y-o.A.y)*(A.x-o.A.x)) / det;
return {true, {A.y + 1. * t * (B.y - A.y), B.x + 1. * t * (B.x - A.x)}};
}

//@formula for : y = ax + b
//@return {a,b};
pair<ld, ld> formula() {
T y1 = A.y, y2 = B.y;
T x1 = A.x, x2 = B.x;
if(y1 == y2) return {1e9, 0};
if(x1 == x2) return {0, 1e9};
ld a = 1. * (y2 - y1) / (x2 - x1);
ld b = -x1 * a + y1;
return {a, b};
}
};

template<typename T>
struct Circle {
Point<T> center;
Circle() {}

void input() {
center = Point<T>();
center.input();
}

bool circumference(Point<T> p) {
return (center.x - p.x) * (center.x - p.x) + (center.y - p.y) * (center.y - p.y) == radius * radius;
}

bool intersect(Circle<T> c) {
T d = (center.x - c.center.x) * (center.x - c.center.x) + (center.y - c.center.y) * (center.y - c.center.y);
}

bool include(Circle<T> c) {
T d = (center.x - c.center.x) * (center.x - c.center.x) + (center.y - c.center.y) * (center.y - c.center.y);
}
};

ll __gcd(ll x, ll y) { return !y ? x : __gcd(y, x % y); }
all3 __exgcd(ll x, ll y) { if(!y) return {x,1,0}; auto [g,x1,y1] = __exgcd(y, x % y); return {g, y1, x1 - (x/y) * y1}; }
ll __lcm(ll x, ll y) { return x / __gcd(x,y) * y; }
ll modpow(ll n, ll x, ll MOD = mod) { n%=MOD; if(!x) return 1; ll res = modpow(n,x>>1,MOD); res = (res * res) % MOD; if(x&1) res = (res * n) % MOD; return res; }

bool solve(vpll A) {
if(A[1].second != A[2].second) {
if(abs(A[2].second - A[0].second) != 1 and abs(A[1].second - A[0].second) != 1) {
if((A[1].first == 2 and A[0].first == 1) or (A[1].first == 7 and A[0].first == 8)) return true;
if((A[2].first == 2 and A[0].first == 1) or (A[2].first == 7 and A[0].first == 8)) return true;
}
}
if(A[1].first!= A[2].first) {
if((A[1].second == 2 and A[0].second == 1) or (A[1].second == 7 and A[0].second == 8)) {
if(abs(A[2].first - A[0].first) != 1 and abs(A[1].first - A[0].first) != 1) return true;
}
if((A[2].second == 2 and A[0].second == 1) or (A[2].second == 7 and A[0].second == 8)) {
if(abs(A[2].first - A[0].first) != 1 and abs(A[1].first - A[0].first) != 1) return true;
}
}
return false;
}

int main() {
Code By Sumfi
cout.precision(12);
ll tc = 1;
cin>>tc;
rep(i,1,tc+1) {
vpll A(3);
if(solve(A)) pyes else pno
}
return 0;
}``````

## Check Mate CodeChef Solution in PYTH 3

``````# cook your dish here
from sys import stdin

while t > 0:
xk, yk = list(map(int, stdin.readline().strip().split(' ')))
xr1, yr1 = list(map(int, stdin.readline().strip().split(' ')))
xr2, yr2 = list(map(int, stdin.readline().strip().split(' ')))
flag = None
if xk != xr1  and xk != xr2 and yk != yr1 and yk != yr2:
if (xk == 1 or xk == 8 or yk == 1 or yk == 8):
if xk == 1:
if (xr1 == 2 or xr2 == 2) and yr1 != yr2:
if abs(yk - yr1) > 1 and abs(yk- yr2) > 1:
flag = 1
elif xk == 8:
if (xr1 == 7 or xr2 == 7) and yr1 != yr2:
if abs(yk - yr1) > 1 and abs(yk - yr2) > 1:
flag = 1
if yk == 1:
if (yr1 == 2 or yr2 == 2) and xr1 != xr2:
if abs(xk-xr1) > 1 and abs(xk - xr2) > 1:
flag = 1
elif yk == 8:
if (yr1 == 7 or yr2 == 7) and xr1 != xr2:
if abs(xk-xr1) > 1 and abs(xk-xr2) > 1:
flag = 1
else:
flag = 0

if flag: print("Yes")
else: print("No")
t -= 1``````

## Check Mate CodeChef Solution in C

``````#include <stdio.h>
int check(int kx,int ky,int bx,int by){
if(kx==bx && ky==by+1){
return 1;
}
else  if(kx==bx && ky==by-1){
return 1;
}
else  if(kx==bx+1 && ky==by){
return 1;
}
else  if(kx==bx-1 && ky==by){
return 1;
}
else  if(kx==bx+1 && ky==by-1){
return 1;
}
else  if(kx==bx-1 && ky==by+1){
return 1;
}
else  if(kx==bx-1 && ky==by-1){
return 1;
}
else  if(kx==bx+1 && ky==by+1){
return 1;
}
return 0;

}

int main()
{
int t;
scanf("%d",&t);
for (int i = 0; i < t; i++) {
int kx,ky,b1x,b1y,b2x,b2y;
scanf("%d %d",&kx,&ky);
scanf("%d %d",&b1x,&b1y);
scanf("%d %d",&b2x,&b2y);
if(check(kx,ky,b1x,b1y)){
printf("no\n");
continue;
}
if(check(kx,ky,b2x,b2y)){
printf("no\n");
continue;
}
if(kx==1 && b1x==2){
if(b1y!=b2y && check(kx,ky,1,b2y)==0){
printf("yes\n");
continue;
}
}
if(kx==1 && b2x==2){
if(b1y!=b2y && check(kx,ky,1,b1y)==0){
printf("yes\n");
continue;
}
}
if(kx==8 && b1x==7){
if(b1y!=b2y && check(kx,ky,8,b2y)==0){
printf("yes\n");
continue;
}
}
if(kx==8 && b2x==7){
if(b1y!=b2y && check(kx,ky,8,b1y)==0){
printf("yes\n");
continue;
}
}
if(ky==1 && b1y==2){
if(b1x!=b2x && check(kx,ky,b2x,1)==0){
printf("yes\n");
continue;
}
}
if(ky==1 && b2y==2){
if(b1x!=b2x && check(kx,ky,b1x,1)==0){
printf("yes\n");
continue;
}
}
if(ky==8 && b1y==7){
if(b1x!=b2x && check(kx,ky,b2x,8)==0){
printf("yes\n");
continue;
}
}
if(ky==8 && b2y==7){
if(b1x!=b2x && check(kx,ky,b1x,8)==0){
printf("yes\n");
continue;
}
}
printf("no\n");

}

}``````

## Check Mate CodeChef Solution in JAVA

``````import java.io.BufferedReader;
import java.util.StringTokenizer;

public class Main {
public static void main(String[] args) throws Throwable {

int T = Integer.parseInt(st.nextToken());
for (int tc = 0; tc < T; ++tc) {
int xk = Integer.parseInt(st.nextToken());
int yk = Integer.parseInt(st.nextToken());
int x1 = Integer.parseInt(st.nextToken());
int y1 = Integer.parseInt(st.nextToken());
int x2 = Integer.parseInt(st.nextToken());
int y2 = Integer.parseInt(st.nextToken());

System.out.println(solve(xk, yk, x1, y1, x2, y2) ? "YES" : "NO");
}
}

static boolean solve(int xk, int yk, int x1, int y1, int x2, int y2) {
return ((y1 != y2 || (xk - x2) * (x1 - x2) > 0) && isCheckMate(xk, yk, xk, y1, x2, y2))
|| ((x1 != x2 || (yk - y2) * (y1 - y2) > 0) && isCheckMate(xk, yk, x1, yk, x2, y2))
|| ((y1 != y2 || (xk - x1) * (x2 - x1) > 0) && isCheckMate(xk, yk, x1, y1, xk, y2))
|| ((x1 != x2 || (yk - y1) * (y2 - y1) > 0) && isCheckMate(xk, yk, x1, y1, x2, yk));
}

static boolean isCheckMate(int xk, int yk, int x1, int y1, int x2, int y2) {
for (int dx = -1; dx <= 1; ++dx) {
for (int dy = -1; dy <= 1; ++dy) {
int nextX = xk + dx;
int nextY = yk + dy;
if (nextX >= 1
&& nextX <= 8
&& nextY >= 1
&& nextY <= 8
&& !isAttacked(xk + dx, yk + dy, x1, y1)
&& !isAttacked(xk + dx, yk + dy, x2, y2)) {
return false;
}
}
}

return true;
}

static boolean isAttacked(int xk, int yk, int x, int y) {
return (xk != x || yk != y) && (xk == x || yk == y);
}
}``````

## Check Mate CodeChef Solution in PYPY 3

``````import sys

def function(xk,yk,x1,y1,x2,y2):
if (xk==1 or yk==1 or xk==8 or yk==8):
if xk==1:
if (x1==2 or x2==2) and y1!=y2:
if abs(yk-y1)>1 and abs(yk-y2)>1:
return True
elif xk==8:
if (x1==7 or x2==7) and y1!=y2:
if abs(yk-y1)>1 and abs(yk-y2)>1:
return True
if yk==1:
if (y1==2 or y2==2) and x1!=x2:
if abs(xk-x1)>1 and abs(xk-x2)>1:
return True
elif yk==8:
if (y1==7 or y2==7) and x1!=x2:
if abs(xk-x1)>1 and abs(xk-x2)>1:
return True
else:
return False

t=int(input())
while t>0:
xk,yk=map(int,input().split())
x1,y1=map(int,input().split())
x2,y2=map(int,input().split())
if function(xk,yk,x1,y1,x2,y2):
print("YES")
else:
print("NO")
t-=1``````

## Check Mate CodeChef Solution in PYTH

``````import sys

def function(xk,yk,x1,y1,x2,y2):
if (xk==1 or yk==1 or xk==8 or yk==8):
if xk==1:
if (x1==2 or x2==2) and y1!=y2:
if abs(yk-y1)>1 and abs(yk-y2)>1:
return True
elif xk==8:
if (x1==7 or x2==7) and y1!=y2:
if abs(yk-y1)>1 and abs(yk-y2)>1:
return True
if yk==1:
if (y1==2 or y2==2) and x1!=x2:
if abs(xk-x1)>1 and abs(xk-x2)>1:
return True
elif yk==8:
if (y1==7 or y2==7) and x1!=x2:
if abs(xk-x1)>1 and abs(xk-x2)>1:
return True
else:
return False

t=int(input())
while t>0:
xk,yk=map(int,input().split())
x1,y1=map(int,input().split())
x2,y2=map(int,input().split())
if function(xk,yk,x1,y1,x2,y2):
print("YES")
else:
print("NO")
t-=1``````

## Check Mate CodeChef Solution in C#

``````#region usings
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections;
using static System.Math;
using static System.Array;
using static System.Convert;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

#endregion
namespace CodeChef
{
public class Solution
{
private static readonly Scanner sc = new Scanner();
static void Main()
{
while (testCases-- > 0)
{
Solve(king, rook1, rook2);
}
sc.Flush();
sc.Close();
}

private static void Solve(long[] king, long[] rook1, long[] rook2)
{
string res = "NO";
Position<long> k = new Position<long>(king[0], king[1]);
Position<long> r1 = new Position<long>(rook1[0], rook2[0]);
Position<long> r2 = new Position<long>(rook1[1], rook2[1]);
if (!(k.x == 1 || k.y == 8 || k.x == 8 || k.y == 1))
res = "NO";
else
{
if (k.x == 1)
{
if ((r1.x == 2 || r1.y == 2) && r2.x != r2.y)
{
if (Abs(r2.x - k.y) > 1 && Abs(r2.y - k.y) > 1)
{
res = "YES";
}
}

}
else if (k.x == 8)
{
if ((r1.x == 7 || r1.y == 7) && r2.x != r2.y)
{
if (Abs(r2.x - k.y) > 1 && Abs(r2.y - k.y) > 1)
{
res = "YES";
}
}
}
if (k.y == 1)
{
if ((r2.x == 2 || r2.y == 2) && r1.x != r1.y)
{
if (Abs(r1.x - k.x) > 1 && Abs(r1.y - k.x) > 1)
{
res = "YES";
}
}

}
else if (k.y == 8)
{
if ((r2.x == 7 || r2.y == 7) && r1.x != r1.y)
{
if (Abs(r1.x - k.x) > 1 && Abs(r1.y - k.x) > 1)
{
res = "YES";
}
}
}
}
sc.WriteLine(res);
}

}
public class Position<T>
{
public T x;
public T y;
public Position(T x, T y)
{
this.x = x;
this.y = y;
}
}
public class Scanner
{

#if (!DEBUG)
public static StreamWriter streamWriter = new StreamWriter(Console.OpenStandardOutput());
#else
public static StreamWriter streamWriter = new StreamWriter(@"c:\users\869963\source\repos\competitive\Codechef\TextFile2.txt");
#endif
#region Input
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
int[][] res = new int[n][];
for (int i = 0; i < n; i++)
{
}
return res;
}

#endregion
#region Output
public void Write<T>(T t)
{
streamWriter.Write(t);
}
public void WriteLine<T>(T result)
{
streamWriter.WriteLine(result);
}
public void WriteArray<T>(T[] secondHalf)
{
for (int i = 0; i < secondHalf.Length; i++)
{
streamWriter.WriteLine(secondHalf[i] + " ");
}
WriteLine("");
}
public void Write2DMatrix<T>(T[][] sum)
{
for (int i = 0; i < sum.Length; i++)
{
for (int j = 0; j < sum[i].Length; j++)
{
Write<string>(\$"{sum[i][j]}");
}
WriteLine<string>("");
}
}
public void YESNO(bool condition)
{
WriteLine(condition ? "YES" : "NO");
}
public void YesNo(bool condition)
{
WriteLine(condition ? "Yes" : "No");
}
public void yesno(bool condition)
{
WriteLine(condition ? "yes" : "no");
}
public void Flush()
{
streamWriter.Flush();
}
public void Close()
{
streamWriter.Close();
}

#endregion
}
public class Utilities
{
public static long PowerModular(long x, long y)
{
long res = 1;

while (y > 0)
{
if ((y & 1) != 0)
res = res * x;
y = y >> 1;
x = x * x;
}
return res;
}
public static T MostFrequent<T>(IEnumerable<T> source)
{
T res = source.GroupBy(auto => auto).OrderByDescending(g => g.Count()).First().Key;
return res;
}
public static long NearestPrime(long n)
{
if (n % 2 != 0)
n -= 2;
else
n--;

int i, j;
for (i = (int)n; i >= 2; i -= 2)
{
if (i % 2 == 0)
continue;
for (j = 3; j <= Math.Sqrt(i); j += 2)
{
if (i % j == 0)
break;
}
if (j > Math.Sqrt(i))
return i;
}
return 2;
}
public static long GCD(long a, long b)
{
if (b == 0)
return a;
return GCD(b, a % b);
}
public static long LCM(long a, long b)
{
return (a / GCD(a, b)) * b;
}
public static long[] SieveOfEratosthenes(int n)
{
bool[] prime = new bool[n + 1];
long j = 0; long[] arr = new long[n];
for (int i = 0; i < n; i++)
prime[i] = true;

for (int p = 2; p * p <= n; p++)
{
if (prime[p] == true)
{
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
for (int i = 2; i <= n; i++)
{
if (prime[i] == true)
{
arr[j] = i;
j++;
}
}
return arr;
}
}
}``````

## Check Mate CodeChef Solution in GO

``````package main

import (
"bufio"
"bytes"
"fmt"
"os"
)

func main() {
// hint(105)

var buf bytes.Buffer
for tc > 0 {
tc--
rocks := make([][]int, 2)
for i := 0; i < 2; i++ {
}
res := solve(king, rocks)

if res {
buf.WriteString("YES\n")
} else {
buf.WriteString("NO\n")
}
}
fmt.Print(buf.String())
}

func readUint64(bytes []byte, from int, val *uint64) int {
i := from

var tmp uint64
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + uint64(bytes[i]-'0')
i++
}
*val = tmp

return i
}

func readInt(bytes []byte, from int, val *int) int {
i := from
sign := 1
if bytes[i] == '-' {
sign = -1
i++
}
tmp := 0
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + int(bytes[i]-'0')
i++
}
*val = tmp * sign
return i
}

for i := 0; i < len(s); i++ {
if s[i] == '\n' {
return s[:i]
}
}
return s
}

return
}

a, b = res[0], res[1]
return
}

a, b, c = res[0], res[1], res[2]
return
}

res := make([]int, n)
x := 0
for i := 0; i < n; i++ {
for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
x++
}
}
return res
}

func solve(king []int, rocks [][]int) bool {

var first_rock_move func(king []int, first []int, second []int) bool
var king_move func(king []int, first []int, second []int) bool
var second_rock_move func(king []int, first []int, second []int) bool

first_rock_move = func(king, first, second []int) bool {

if canMoveTo(first, second, []int{king[0], first[1]}) &&
king_move(king, []int{king[0], first[1]}, second) {
return true
}

if canMoveTo(first, second, []int{first[0], king[1]}) &&
king_move(king, []int{first[0], king[1]}, second) {
return true
}

return false
}

king_move = func(king []int, first []int, second []int) bool {
r, c := king[0], king[1]

for i := -1; i <= 1; i++ {
for j := -1; j <= 1; j++ {
if i == 0 && j == 0 {
continue
}
u, v := r+i, c+j
if u < 1 || u > 8 || v < 1 || v > 8 {
continue
}
if u == first[0] && v == first[1] {
// beat first rock
if !second_rock_move([]int{u, v}, nil, second) {
return false
}
}
if u == second[0] && v == second[1] {
if !second_rock_move([]int{u, v}, first, nil) {
return false
}
}

if !second_rock_move([]int{u, v}, first, second) {
return false
}
}
}
return true
}

second_rock_move = func(king []int, first []int, second []int) bool {
if first != nil {
if first[0] == king[0] || first[1] == king[1] {
return true
}
}
if second != nil {
if second[0] == king[0] || second[1] == king[1] {
return true
}
}
return false
}

return first_rock_move(king, rocks[0], rocks[1]) || first_rock_move(king, rocks[1], rocks[0])
}

func canMoveTo(a, b, c []int) bool {
// can a go to c
if a[0] == c[0] {
// same column
if b[0] == a[0] {
return b[1] < min(a[1], c[1]) || max(a[1], c[1]) < b[1]
}
}
if a[1] == c[1] {
// same row
if b[1] == a[1] {
return b[0] < min(a[0], c[0]) || max(a[0], c[0]) < b[0]
}
}

return true
}

func min(a, b int) int {
if a <= b {
return a
}
return b
}

func max(a, b int) int {
if a >= b {
return a
}
return b
}``````
##### Check Mate CodeChef Solution Review:

In our experience, we suggest you solve this Check Mate CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Check Mate CodeChef Solution.

Find on CodeChef

##### Conclusion:

I hope this Check Mate CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!