solution
stringlengths 11
983k
| difficulty
int64 0
21
| language
stringclasses 2
values |
---|---|---|
for _ in range(int(input())):
n = int(input())
s = [input() for i in range(n)]
if s[0][1]==s[1][0]:
if s[-1][-2]==s[-2][-1]:
if s[-1][-2]==s[0][1]:
print(2)
print(1,2)
print(2,1)
else:print(0)
else:
print(1)
if s[0][1]==s[n-1][n-2]:print(n,n-1)
else:print(n-1,n)
else:
if s[n - 1][n - 2] == s[n - 2][n - 1]:
print(1)
if s[n - 1][n - 2] == s[0][1]:print(1,2)
else:print(2,1)
else:
print(2)
print(1,2)
if s[n-1][n-2]==s[1][0]:print(n,n-1)
else:print(n-1,n)
| 8 |
PYTHON3
|
for _ in range(int(input())):
a = []
n = int(input())
for i in range(n):
s = input()
if i == 0:
a.append(int(s[1]))
if i == 1:
a.append(int(s[0]))
if i == n - 2:
a.append(int(s[n - 1]))
if i == n - 1:
a.append(int(s[n - 2]))
x = sum(a)
if a[0] == a[1] == a[2] == a[3]:
print(2)
print(1, 2)
print(2, 1)
elif (a[0] + a[1]) % 2 == 0 and (a[2] + a[3]) % 2 == 0:
print(0)
elif x % 2 == 1:
print(1)
if (a[0] == 1 and x == 1) or (a[0] == 0 and x == 3):
print(2, 1)
elif (a[1] == 1 and x == 1) or (a[1] == 0 and x == 3):
print(1, 2)
elif (a[2] == 1 and x == 1) or (a[2] == 0 and x == 3):
print(n, n - 1)
else:
print(n - 1, n)
else:
print(2)
if a[0] == 1:
print(1, 2)
else:
print(2, 1)
if a[2] == 0:
print(n - 1, n)
else:
print(n, n - 1)
| 8 |
PYTHON3
|
t=int(input())
for _ in range(t):
n = int(input())
l=[]
for i in range(n):
l.append(input())
x1,x2 = l[0][1], l[1][0]
y1,y2 = l[-2][-1], l[-1][-2]
x=[]
if x1==x2:
if y1!=str(1-int(x1)):
x.append([n-1,n])
if y2!=str(1-int(x1)):
x.append([n,n-1])
elif y1==y2:
if x1!=str(1-int(y1)):
x.append([1,2])
if x2!=str(1-int(y1)):
x.append([2,1])
else:
if x1!='1':
x.append([1,2])
else:
x.append([2,1])
if y1!='0':
x.append([n-1,n])
else:
x.append([n,n-1])
print(len(x))
for i in x:
print(*i)
| 8 |
PYTHON3
|
import sys
from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
n = int(stdin.readline())
s = [stdin.readline()[:-1] for i in range(n)]
ans = []
for i in range(2**4):
a,b = int(s[0][1]),int(s[1][0])
c,d = int(s[n-2][n-1]),int(s[n-1][n-2])
now = []
if i & 1 > 0:
a ^= 1
now.append((1,2))
if i & 2 > 0:
b ^= 1
now.append((2,1))
if i & 4 > 0:
c ^= 1
now.append((n-1,n))
if i & 8 > 0:
d ^= 1
now.append((n,n-1))
if len(now) <= 2 and ((a+b==0 and c+d==2) or (a+b==2 and c+d==0)):
ans = now
break
print (len(ans))
for i in ans:
print (*i)
| 8 |
PYTHON3
|
import itertools
import copy
def index(grid, ix):
return grid[ix[0]][ix[1]]
def index_set(grid, ix, val):
grid[ix[0]][ix[1]] = val
def index_flip(grid, ix):
bit = ord(index(grid, ix)) - ord('0')
new = chr((1 - bit) + ord('0'))
index_set(grid, ix, new)
def solve(n, grid):
ri = (0, 1)
di = (1, 0)
ui = (n - 2, n - 1)
li = (n - 1, n - 2)
indices = [ri, di, ui, li]
for p in itertools.product(*([range(2)] * 4)):
if sum(p) > 2:
continue
# flip
new_grid = copy.deepcopy(grid)
for i, x in enumerate(p):
if x == 1:
# flip this index
index_flip(new_grid, indices[i])
# check
r = index(new_grid, ri)
d = index(new_grid, di)
u = index(new_grid, ui)
l = index(new_grid, li)
if r == d and u == l and r != u:
return [(r + 1, c + 1) for i, (r, c) in enumerate(indices) if p[i] == 1]
def main():
nt = int(input())
for _ in range(nt):
n = int(input())
grid = []
for _ in range(n):
grid.append(list(input()))
sol = solve(n, grid)
print(len(sol))
for r, c in sol:
print(r, c)
def test():
n = 4
grid = [list(r) for r in ['S010', '0001', '1000', '111F']]
print(solve(n, grid))
if __name__ == '__main__':
main()
# test()
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int tc;
cin >> tc;
while (tc--) {
long long int n;
cin >> n;
char ar[n + 1][n + 1];
for (long long int i = 0; i < n; i++)
for (long long int j = 0; j < n; j++) cin >> ar[i][j];
long long int a, b, c, d;
a = ar[0][1];
b = ar[1][0];
c = ar[n - 2][n - 1];
d = ar[n - 1][n - 2];
if (a == b and c == d and c == a) {
cout << 2 << endl;
cout << n - 1 << " " << n << endl << n << " " << n - 1 << endl;
} else if (a != b and c != d) {
cout << 2 << endl;
if (a != c)
cout << 1 << " " << 2 << endl << n - 1 << " " << n << endl;
else if (a != d)
cout << 1 << " " << 2 << endl << n << " " << n - 1 << endl;
} else if (a == b and c != d) {
cout << 1 << endl;
if (c == a)
cout << n - 1 << " " << n << endl;
else if (d == a)
cout << n << " " << n - 1 << endl;
} else if (a != b and c == d) {
cout << 1 << endl;
if (a == c)
cout << 1 << " " << 2 << endl;
else if (b == c)
cout << 2 << " " << 1 << endl;
} else if (((a == b) and (c == d)) and c != a)
cout << 0 << endl;
}
return 0;
}
| 8 |
CPP
|
def i(): return int(input())
def mp() : return map(str,input().split())
def si() : return input()
from collections import defaultdict as dd, deque as dq,Counter as c
from math import factorial as f ,ceil,gcd,sqrt
for _ in range(i()):
a = i()
b =[]
for _ in range(a):
b.append(list(input()))
t = b[0][1]
r = b[1][0]
y = b[a-1][a-2]
u = b[a-2][a-1]
ans =[]
if t==r:
if y==t:
ans.append([a,a-1])
if u==t:
ans.append([a-1,a])
print(len(ans))
for k in range(len(ans)):
print(*ans[k])
elif y==u:
if t==y:
ans.append([1,2])
if r==y:
ans.append([2,1])
print(len(ans))
for k in range(len(ans)):
print(*ans[k])
else:
ans.append([2,1])
if y==t:
ans.append([a,a-1])
if u==t:
ans.append([a-1,a])
print(len(ans))
for k in range(len(ans)):
print(*ans[k])
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
scanf("%d", &n);
char ch[n + 1][n + 1], a, b, c, d, x;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; ++j) cin >> ch[i][j];
}
a = ch[0][1];
b = ch[1][0];
c = ch[n - 1][n - 2];
d = ch[n - 2][n - 1];
if (a == b && c != d) {
cout << 1 << "\n";
if (a == c) {
cout << n << " " << n - 1 << "\n";
} else {
cout << n - 1 << " " << n << "\n";
}
} else if (a == b and c == d) {
if (a == c) {
cout << 2 << "\n";
cout << 1 << " " << 2 << "\n";
cout << 2 << " " << 1 << "\n";
} else
cout << 0 << "\n";
} else if (c == d and a != b) {
cout << 1 << "\n";
if (a == c) {
cout << 1 << " " << 2 << "\n";
} else {
cout << 2 << " " << 1 << "\n";
}
} else if (a != b and c != d) {
cout << "2\n";
if (a == c) {
cout << "1 2"
<< "\n";
cout << n - 1 << " " << n << "\n";
} else {
cout << "1 2"
<< "\n";
cout << n << " " << n - 1 << "\n";
}
}
}
int main() {
int t;
scanf("%d", &t);
while (t--) solve();
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int vis[301][300];
char str[300][300];
int main() {
int t;
cin >> t;
while (t--) {
int n, x, y, k = 1, sum = 0;
bool sign = false;
memset(vis, 0, sizeof(vis));
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> str[i][j];
}
}
if (str[1][2] != '0') {
sum++;
vis[1][2] = 1;
}
if (str[2][1] != '0') {
sum++;
vis[2][1] = 1;
}
if (str[n - 1][n] != '1') {
sum++;
vis[n - 1][n] = 1;
}
if (str[n][n - 1] != '1') {
sum++;
vis[n][n - 1] = 1;
}
if (sum > 2) {
memset(vis, 0, sizeof(vis));
sum = 0;
if (str[1][2] != '1') {
sum++;
vis[1][2] = 1;
}
if (str[2][1] != '1') {
sum++;
vis[2][1] = 1;
}
if (str[n - 1][n] != '0') {
sum++;
vis[n - 1][n] = 1;
}
if (str[n][n - 1] != '0') {
sum++;
vis[n][n - 1] = 1;
}
}
printf("%d\n", sum);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (vis[i][j]) {
printf("%d %d\n", i, j);
}
}
}
}
}
| 8 |
CPP
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
char mat[201][201];
void solve() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) cin >> mat[i][j];
int a = mat[0][1] - '0';
int b = mat[1][0] - '0';
int c = mat[n - 1][n - 2] - '0';
int d = mat[n - 2][n - 1] - '0';
int cnt = 0;
vector<pair<int, int>> ans;
if (a == b) {
if (c == a) {
cnt++;
ans.push_back({n - 1, n - 2});
}
if (d == a) {
cnt++;
ans.push_back({n - 2, n - 1});
}
} else {
int cnt0 = 0, cnt1 = 0;
if (a == 0)
cnt0++;
else
cnt1++;
if (b == 0)
cnt0++;
else
cnt1++;
if (c == 0)
cnt0++;
else
cnt1++;
if (d == 0)
cnt0++;
else
cnt1++;
if (cnt0 == cnt1) {
if (a == 0) {
cnt++;
ans.push_back({1, 0});
} else {
cnt++;
ans.push_back({0, 1});
}
if (c == 1) {
cnt++;
ans.push_back({n - 2, n - 1});
} else {
cnt++;
ans.push_back({n - 1, n - 2});
}
} else {
if (cnt0 == 1) {
if (a == 0) {
cnt++;
ans.push_back({1, 0});
} else {
cnt++;
ans.push_back({0, 1});
}
} else {
if (a == 1) {
cnt++;
ans.push_back({1, 0});
} else {
cnt++;
ans.push_back({0, 1});
}
}
}
}
cout << cnt << "\n";
for (auto x : ans) cout << x.first + 1 << " " << x.second + 1 << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--) solve();
return 0;
}
| 8 |
CPP
|
def read_int():
return int(input())
def read_ints():
return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
n = read_int()
a = []
for i in range(n):
a.append(input())
ans = []
pos = [(0, 1), (1, 0), (n - 1, n - 2), (n - 2, n - 1)]
target = '0011'
for i, p in enumerate(pos):
if a[p[0]][p[1]] != target[i]:
ans.append((p[0] + 1, p[1] + 1))
if len(ans) <= 2:
print(len(ans))
for r, c in ans:
print(r, c)
else:
target = '1100'
ans = []
for i, p in enumerate(pos):
if a[p[0]][p[1]] != target[i]:
ans.append((p[0] + 1, p[1] + 1))
print(len(ans))
for r, c in ans:
print(r, c)
| 8 |
PYTHON3
|
def solve():
n = int(input())
a = []
for i in range(n):
a.append(list(input()))
s1 = int(a[0][1])
s2 = int(a[1][0])
f1 = int(a[n - 2][n - 1])
f2 = int(a[n - 1][n - 2])
c = 0
d = []
if s1 == s2:
p = s1 ^ 1
if f1 != p:
c += 1
d.append((n - 1, n))
if f2 != p:
c += 1
d.append((n, n - 1))
else:
if f1 == f2:
p = f1 ^ 1
if s1 != p:
c += 1
d.append((1, 2))
if s2 != p:
c += 1
d.append((2, 1))
else:
if s1 != 0:
c += 1
d.append((1, 2))
if s2 != 0:
c += 1
d.append((2, 1))
if f1 != 1:
c += 1
d.append((n - 1, n))
if f2 != 1:
c += 1
d.append((n, n - 1))
print(c)
for x, y in d: print(x, y)
t = int(input())
i = 0
while i < t:
solve()
i += 1
| 8 |
PYTHON3
|
import sys
try:sys.stdin,sys.stdout=open('in.txt','r'),open('out.txt','w')
except:pass
ii1=lambda:int(sys.stdin.readline().strip()) # for interger
is1=lambda:sys.stdin.readline().strip() # for str
iia=lambda:list(map(int,sys.stdin.readline().strip().split())) # for List[int]
isa=lambda:sys.stdin.readline().strip().split() # for List[str]
mod=int(1e9 + 7);from collections import *;from math import *
###################### Start Here ######################
for i in range(ii1()):
n=ii1()
grid=[]
for j in range(n):
grid.append(is1())
ans=[]
if grid[0][1]==grid[1][0]:
if grid[n-1][n-2]==grid[0][1]:
ans.append([n,n-1])
if grid[n-2][n-1]==grid[0][1]:
ans.append([n-1,n])
else:
if grid[n-1][n-2]==grid[n-2][n-1]:
if grid[n-1][n-2]==grid[0][1]:
ans.append([1,2])
if grid[n-1][n-2]==grid[1][0]:
ans.append([2,1])
else:
if grid[0][1]=='1':
ans.append([1,2])
else:
ans.append([2,1])
if grid[n-1][n-2]=='0':
ans.append([n,n-1])
else:
ans.append([n-1,n])
print(len(ans))
if ans:
for a in ans:
print(*a)
| 8 |
PYTHON3
|
from collections import deque as dq
import sys
input=sys.stdin.readline
t=int(input())
while t:
n=int(input())
ll=[]
for i in range(n):
s=input().split()[0]
ll.append(s)
a=ll[0][1]
b=ll[1][0]
c=ll[n-1][n-2]
d=ll[n-2][n-1]
ans=[]
if(a==b and c==d):
if(a==c):
ans.append((1,2))
ans.append((2,1))
else:
lol=1
elif(a==b and c!=d):
if(a==c):
ans.append((n,n-1))
else:
ans.append((n-1,n))
elif(a!=b and c==d):
if(a==c):
ans.append((1,2))
else:
ans.append((2,1))
else:
if(a=='1'):
ans.append((1,2))
else:
ans.append((2,1))
if(c=='0'):
ans.append((n,n-1))
else:
ans.append((n-1,n))
print(len(ans))
for i in ans:
print(*i)
t-=1
'''
val=ll[0][1]
q=dq([(0,1)])
vis=[[0]*n for i in range(n)]
X=[0,1,0,-1]
Y=[1,0,-1,0]
while q:
x,y=q.pop()
vis[x][y]=1
for i in range(4):
cx=x+X[i]
cy=y+Y[i]
if(cx>=0 and cx<n and cy>=0 and cy<n and ll[cx][cy]==ll[x][y] and vis[cx][xy]==0):
q.append((cx,cy))
vis[cx][cy]=1
'''
| 8 |
PYTHON3
|
import sys
import itertools
import math
input = sys.stdin.readline
I = lambda : list(map(str,input().split()))
n,=I()
n=int(n)
while(n):
n-=1
k,=I()
k=int(k)
arr=[]
for i in range(k):
g,=I()
arr.append(g)
a,b,x,y=int(arr[0][1]),int(arr[1][0]),int(arr[k-1][k-2]),int(arr[k-2][k-1])
if a==b and x==y and a==x:
print(2)
print(1,2)
print(2,1)
elif a==b and x==y and a!=x:
print(0)
elif a==b:
if x==a:
print(1)
print(k,k-1)
elif y==a:
print(1)
print(k-1,k)
elif x==y:
if a==x:
print(1)
print(1,2)
else:
print(1)
print(2,1)
else:
print(2)
if a==1:
print(1,2)
elif b==1:
print(2,1)
if x==0:
print(k,k-1)
elif y==0:
print(k-1,k)
| 8 |
PYTHON3
|
import time,math as mt,bisect as bs,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
return int(stdin.readline())
def IP(): # to take tuple as input
return map(int,stdin.readline().split())
def L(): # to take list as input
return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
if a==0:
return b
elif b==0:
return a
if a>b:
return gcd(a%b,b)
else:
return gcd(a,b%a)
def bfs(adj,v): # a schema of bfs
visited=[False]*(v+1)
q=deque()
while q:
pass
def sieve():
li=[True]*(2*(10**5)+5)
li[0],li[1]=False,False
for i in range(2,len(li),1):
if li[i]==True:
for j in range(i*i,len(li),i):
li[j]=False
prime=[]
for i in range((2*(10**5)+5)):
if li[i]==True:
prime.append(i)
return prime
def setBit(n):
count=0
while n!=0:
n=n&(n-1)
count+=1
return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
spf[1]=1
for i in range(2,mx+1):
if spf[i]==mx:
spf[i]=i
for j in range(i*i,mx+1,i):
if i<spf[j]:
spf[j]=i
return
def readTree(n,e): # to read tree
adj=[set() for i in range(n+1)]
for i in range(e):
u1,u2=IP()
adj[u1].add(u2)
return adj
#####################################################################################
mod=10**9+7
def solve():
n=II()
li=[]
for i in range(n):
s=input()
li.append(s)
w,x,y,z=li[0],li[1],li[-2],li[-1]
#print(w,x,y,z)
cnt=0
ans=[]
if w[1]=='0' and x[0]=='0':
if y[-1]!='1':
cnt+=1
ans.append([n-1,n])
if z[-2]!='1':
cnt+=1
ans.append([n,n-1])
elif w[1]=='1' and x[0]=='1':
if y[-1]!='0':
cnt+=1
ans.append([n-1,n])
if z[-2]!='0':
cnt+=1
ans.append([n,n-1])
elif w[1]=='1' and x[0]=='0':
if y[-1]=='1' and z[-2]=='1':
cnt+=1
ans.append([1,2])
elif y[-1]=='0' and z[-2]=='0':
cnt+=1
ans.append([2,1])
else:
cnt+=1
ans.append([2,1])
cnt+=1
if y[-1]=='1':
ans.append([n-1,n])
else:
ans.append([n,n-1])
else:
if y[-1]=='1' and z[-2]=='1':
cnt+=1
ans.append([2,1])
elif y[-1]=='0' and z[-2]=='0':
cnt+=1
ans.append([1,2])
else:
cnt+=1
ans.append([1,2])
cnt+=1
if y[-1]=='1':
ans.append([n-1,n])
else:
ans.append([n,n-1])
print(cnt)
if cnt>0:
for ele in ans:
print(*ele)
return
t=II()
for i in range(t):
solve()
#######
#
#
####### # # # #### # # #
# # # # # # # # # # #
# #### # # #### #### # #
###### # # #### # # # # #
# ``````ΒΆ0````1ΒΆ1_```````````````````````````````````````
# ```````ΒΆΒΆΒΆ0_`_ΒΆΒΆΒΆ0011100ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ001_````````````````````
# ````````ΒΆΒΆΒΆΒΆΒΆ00ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0_````````````````
# `````1_``ΒΆΒΆ00ΒΆ0000000000000000000000ΒΆΒΆΒΆΒΆ0_`````````````
# `````_ΒΆΒΆ_`0ΒΆ000000000000000000000000000ΒΆΒΆΒΆΒΆΒΆ1``````````
# ```````ΒΆΒΆΒΆ00ΒΆ00000000000000000000000000000ΒΆΒΆΒΆ_`````````
# ````````_ΒΆΒΆ00000000000000000000ΒΆΒΆ00000000000ΒΆΒΆ`````````
# `````_0011ΒΆΒΆΒΆΒΆΒΆ000000000000ΒΆΒΆ00ΒΆΒΆ0ΒΆΒΆ00000000ΒΆΒΆ_````````
# ```````_ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ00000000000ΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆ00000000ΒΆΒΆ1````````
# ``````````1ΒΆΒΆΒΆΒΆΒΆ000000ΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0000000ΒΆΒΆΒΆ````````
# ```````````ΒΆΒΆΒΆ0ΒΆ000ΒΆ00ΒΆ0ΒΆΒΆ`_____`__1ΒΆ0ΒΆΒΆ00ΒΆ00ΒΆΒΆ````````
# ```````````ΒΆΒΆΒΆΒΆΒΆ00ΒΆ00ΒΆ10ΒΆ0``_1111_`_ΒΆΒΆ0000ΒΆ0ΒΆΒΆΒΆ````````
# ``````````1ΒΆΒΆΒΆΒΆΒΆ00ΒΆ0ΒΆΒΆ_ΒΆΒΆ1`_ΒΆ_1_0_`1ΒΆΒΆ_0ΒΆ0ΒΆΒΆ0ΒΆΒΆ````````
# ````````1ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆ0ΒΆ0_0ΒΆ``100111``_ΒΆ1_0ΒΆ0ΒΆΒΆ_1ΒΆ````````
# ```````1ΒΆΒΆΒΆΒΆ00ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ010ΒΆ``1111111_0ΒΆ11ΒΆΒΆΒΆΒΆΒΆ_10````````
# ```````0ΒΆΒΆΒΆΒΆ__10ΒΆΒΆΒΆΒΆΒΆ100ΒΆΒΆΒΆ0111110ΒΆΒΆΒΆ1__ΒΆΒΆΒΆΒΆ`__````````
# ```````ΒΆΒΆΒΆΒΆ0`__0ΒΆΒΆ0ΒΆΒΆ_ΒΆΒΆΒΆ_11````_0ΒΆΒΆ0`_1ΒΆΒΆΒΆΒΆ```````````
# ```````ΒΆΒΆΒΆ00`__0ΒΆΒΆ_00`_0_``````````1_``ΒΆ0ΒΆΒΆ_```````````
# ``````1ΒΆ1``ΒΆΒΆ``1ΒΆΒΆ_11``````````````````ΒΆ`ΒΆΒΆ````````````
# ``````1_``ΒΆ0_ΒΆ1`0ΒΆ_`_``````````_``````1_`ΒΆ1````````````
# ``````````_`1ΒΆ00ΒΆΒΆ_````_````__`1`````__`_ΒΆ`````````````
# ````````````ΒΆ1`0ΒΆΒΆ_`````````_11_`````_``_``````````````
# `````````ΒΆΒΆΒΆΒΆ000ΒΆΒΆ_1```````_____```_1``````````````````
# `````````ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0_``````_````_1111__``````````````
# `````````ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ01_`````_11____1111_```````````
# `````````ΒΆΒΆ0ΒΆ0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ1101_______11ΒΆ_```````````
# ``````_ΒΆΒΆΒΆ0000000ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆ0ΒΆΒΆΒΆ1````````````
# `````0ΒΆΒΆ0000000ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ1`````````````
# ````0ΒΆ0000000ΒΆΒΆ0_````_011_10ΒΆ110ΒΆ01_1ΒΆΒΆΒΆ0````_100ΒΆ001_`
# ```1ΒΆ0000000ΒΆ0_``__`````````_`````````0ΒΆ_``_00ΒΆΒΆ010ΒΆ001
# ```ΒΆΒΆ00000ΒΆΒΆ1``_01``_11____``1_``_`````ΒΆΒΆ0100ΒΆ1```_00ΒΆ1
# ``1ΒΆΒΆ00000ΒΆ_``_ΒΆ_`_101_``_`__````__````_0000001100ΒΆΒΆΒΆ0`
# ``ΒΆΒΆΒΆ0000ΒΆ1_`_ΒΆ``__0_``````_1````_1_````1ΒΆΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆΒΆ0```
# `_ΒΆΒΆΒΆΒΆ00ΒΆ0___01_10ΒΆ_``__````1`````11___`1ΒΆΒΆΒΆ01_````````
# `1ΒΆΒΆΒΆΒΆΒΆ0ΒΆ0`__01ΒΆΒΆΒΆ0````1_```11``___1_1__11ΒΆ000`````````
# `1ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ1_1_01__`01```_1```_1__1_11___1_``00ΒΆ1````````
# ``ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0`__10__000````1____1____1___1_```10ΒΆ0_```````
# ``0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ1___0000000```11___1__`_0111_```000ΒΆ01```````
# ```ΒΆΒΆΒΆ00000ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ01___1___00_1ΒΆΒΆΒΆ`_``1ΒΆΒΆ10ΒΆΒΆ0```````
# ```1010000ΒΆ000ΒΆΒΆ0100_11__1011000ΒΆΒΆ0ΒΆ1_10ΒΆΒΆΒΆ_0ΒΆΒΆ00``````
# 10ΒΆ000000000ΒΆ0________0ΒΆ000000ΒΆΒΆ0000ΒΆΒΆΒΆΒΆ000_0ΒΆ0ΒΆ00`````
# ΒΆΒΆΒΆΒΆΒΆΒΆ0000ΒΆΒΆΒΆΒΆ_`___`_0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ00000000000000_0ΒΆ00ΒΆ01````
# ΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ_``_1ΒΆΒΆΒΆ00000000000000000000_0ΒΆ000ΒΆ01```
# 1__```1ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ00ΒΆΒΆΒΆΒΆ00000000000000000000ΒΆ_0ΒΆ0000ΒΆ0_``
# ```````ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ00000000000000000000010ΒΆ00000ΒΆΒΆ_`
# ```````0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ00000000000000000000ΒΆ10ΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆ0`
# ````````ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆ00000000000000000000010ΒΆΒΆΒΆ0011```
# ````````1ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆ0000000000000000000ΒΆ100__1_`````
# `````````ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ000000000000000000ΒΆ11``_1``````
# `````````1ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆ00000000000000000ΒΆ11___1_`````
# ``````````ΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆ0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0000000000000000ΒΆ11__``1_````
# ``````````ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆ000000000000000ΒΆ1__````__```
# ``````````ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0000000000000000__`````11``
# `````````_ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ000ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ000000000000011_``_1ΒΆΒΆΒΆ0`
# `````````_ΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆ000000ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ000000000000100ΒΆΒΆΒΆΒΆ0_`_
# `````````1ΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆ000000000ΒΆΒΆΒΆΒΆΒΆΒΆ000000000ΒΆ00ΒΆΒΆ01`````
# `````````ΒΆΒΆΒΆΒΆΒΆ0ΒΆ0ΒΆΒΆΒΆ0000000000000ΒΆ0ΒΆ00000000011_``````_
# ````````1ΒΆΒΆ0ΒΆΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ000000000000000000000ΒΆ11___11111
# ````````ΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆ00ΒΆΒΆΒΆΒΆΒΆΒΆ000000000000000000ΒΆ011111111_
# ```````_ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0000000ΒΆ0ΒΆ00000000000000000ΒΆ01_1111111
# ```````0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ000000000000000000000000000ΒΆ01___`````
# ```````ΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆ000000000000000000000000000ΒΆ01___1````
# ``````_ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ00000000000000000000000000000011_111```
# ``````0ΒΆΒΆ0ΒΆΒΆΒΆ0ΒΆΒΆ0000000000000000000000000000ΒΆ01`1_11_``
# ``````ΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆ0000000000000000000000000000001`_0_11_`
# ``````ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ00000000000000000000000000000ΒΆ01``_0_11`
# ``````ΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆΒΆ00000000000000000000000000000001```_1_11
| 8 |
PYTHON3
|
import os
import sys
from io import BytesIO, IOBase
import math
def main():
pass
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def binary(n):
return (bin(n).replace("0b", ""))
def decimal(s):
return (int(s, 2))
def pow2(n):
p = 0
while (n > 1):
n //= 2
p += 1
return (p)
def primeFactors(n):
l=[]
while n % 2 == 0:
l.append(2)
n = n / 2
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
l.append(i)
n = n / i
if n > 2:
l.append(int(n))
return (l)
def isPrime(n):
if (n == 1):
return (False)
else:
root = int(n ** 0.5)
root += 1
for i in range(2, root):
if (n % i == 0):
return (False)
return (True)
def maxPrimeFactors(n):
maxPrime = -1
while n % 2 == 0:
maxPrime = 2
n >>= 1
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
maxPrime = i
n = n / i
if n > 2:
maxPrime = n
return int(maxPrime)
def countcon(s,i):
c=0
ch=s[i]
for i in range(i,len(s)):
if(s[i]==ch):
c+=1
else:
break
return(c)
def change(c1,c2,c3,c4):
if(c1!=c2):
if(c3==c4):
if(c3!=c1):
return([[2,1]])
else:
return ([[1,2]])
else:
if(c1==c3):
return([[2,1],[n,n-1]])
else:
return([[2,1],[n-1,n]])
else:
if(c3==c4):
if(c3!=c1):
return([])
else:
return([[1,2],[2,1]])
else:
if(c3!=c1):
return([[n-1,n]])
else:
return([[n,n-1]])
for xyz in range(0,int(input())):
n=int(input())
l=[]
for i in range(0,n):
l.append(input())
ans=change(l[0][1],l[1][0],l[-1][-2],l[-2][-1])
print(len(ans))
for i in ans:
print(*i)
| 8 |
PYTHON3
|
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
t,=I()
for _ in range(t):
n,=I()
l=[input().strip() for i in range(n)]
an=[]
le=[0,0,1,1,1];p=[1,1,0,0,0]
rq=[l[0][1],l[1][0],l[1][1],l[2][0],l[0][2]]
pos=[[1,2],[2,1],[2,2],[3,1],[1,3]]
ct=cp=0;a1=[]
for i in range(5):
if le[i]!=int(rq[i]):
ct+=1
a1.append(pos[i])
for i in range(5):
if p[i]!=int(rq[i]):
cp+=1
an.append(pos[i])
if ct<=cp:
an=a1
print(len(an))
for i in an:
print(*i)
| 8 |
PYTHON3
|
def ans(a, n):
s1 = a[0][1]
s2 = a[1][0]
f2 = a[n-1][n-2]
f1 = a[n-2][n-1]
if f1==f2 and s1==s2 and f1!=s1:
print(0) #correct
elif f1==f2 and f1==s1 and s1==s2:
print(2)
#change s1 and s2
print('1 2')
print('2 1') #correct
elif f1==f2:
print(1)
if s1==f1:
#change s1
print('1 2')
else:
#change s2
print('2 1')
elif s1==s2:
print(1)
if f2==s1:
#change f2
print(str(n)+' '+str(n-1))
else:
#change f1
print(str(n-1)+' '+str(n))
else:
#change s1
print(2)
if f1==s1:
#change s1 and f2
print('1 2')
print(str(n)+' '+str(n-1))
else:
#change s1 and f1
print('1 2')
print(str(n-1)+' '+str(n))
return
m = int(input())
for j in range(m):
n = int(input())
a = []
for i in range(n):
b = input()
a.append(b)
ans(a, n)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
#pragma GCC optimize "trapv"
using namespace std;
const int N = 1e5 + 5;
const unsigned int M = 1000000007;
long long a[N], b[N];
char invert(char x) {
if (x == '0')
return '1';
else
return '0';
}
void solve() {
int n;
cin >> n;
char a[n][n];
vector<pair<int, int>> ans;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) cin >> a[i][j];
if (a[0][1] == a[1][0]) {
if (a[n - 1][n - 2] == a[0][1]) {
a[n - 1][n - 2] = invert(a[n - 1][n - 2]);
ans.push_back(make_pair(n, n - 1));
}
if (a[n - 2][n - 1] == a[0][1]) {
a[n - 2][n - 1] = invert(a[n - 2][n - 1]);
ans.push_back(make_pair(n - 1, n));
}
} else {
if (a[n - 1][n - 2] == a[n - 2][n - 1]) {
if (a[0][1] == a[n - 1][n - 2])
ans.push_back(make_pair(1, 2));
else
ans.push_back(make_pair(2, 1));
} else {
if (a[0][1] != a[n - 1][n - 2]) {
ans.push_back(make_pair(1, 2));
ans.push_back(make_pair(n, n - 1));
} else {
ans.push_back(make_pair(1, 2));
ans.push_back(make_pair(n - 1, n));
}
}
}
cout << ans.size() << "\n";
for (int i = 0; i < ans.size(); i++) {
cout << ans[i].first << ' ' << ans[i].second << "\n";
}
}
int32_t main() {
;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long q = 1, i, j, test;
cin >> q;
for (test = 1; test < (q + 1); test++) {
long long n;
cin >> n;
char a[n][n];
for (i = 0; i < (n); i++)
for (j = 0; j < (n); j++) cin >> a[i][j];
vector<pair<int, int> > v;
int ans = 0;
if (a[0][1] == a[1][0]) {
if (a[n - 1][n - 2] == a[0][1]) ans++, v.push_back({n, n - 1});
if (a[n - 2][n - 1] == a[0][1]) ans++, v.push_back({n - 1, n});
} else if (a[n - 1][n - 2] == a[n - 2][n - 1]) {
if (a[n - 1][n - 2] == a[0][1]) ans++, v.push_back({1, 2});
if (a[n - 2][n - 1] == a[1][0]) ans++, v.push_back({2, 1});
} else {
if (a[n - 1][n - 2] == '0') ans++, v.push_back({n, n - 1});
if (a[n - 2][n - 1] == '0') ans++, v.push_back({n - 1, n});
if ('1' == a[0][1]) ans++, v.push_back({1, 2});
if ('1' == a[1][0]) ans++, v.push_back({2, 1});
}
cout << ans << '\n';
for (i = 0; i < (ans); i++)
cout << v[i].first << " " << v[i].second << '\n';
}
}
| 8 |
CPP
|
for _ in range(int(input())):
n = int(input())
arr = [list(input()) for i in range(n)]
ans = []
if arr[0][1]==arr[1][0] and arr[n-1][n-2]==arr[n-2][n-1] and arr[0][1]==arr[n-1][n-2]:
ans.append([1,2])
ans.append([2,1])
elif int(arr[0][1])+int(arr[1][0]) == int(arr[n-1][n-2])+int(arr[n-2][n-1]):
if arr[0][1]==arr[n-2][n-1]:
ans.append([1,2])
ans.append([n,n-1])
elif arr[0][1]==arr[n-1][n-2]:
ans.append([1,2])
ans.append([n-1,n])
elif int(arr[0][1])+int(arr[1][0])==1 and int(arr[n-1][n-2])+int(arr[n-2][n-1])==2:
if arr[0][1]=='1':
ans.append([1,2])
elif arr[1][0]=='1':
ans.append([2,1])
elif int(arr[0][1])+int(arr[1][0])==2 and int(arr[n-1][n-2])+int(arr[n-2][n-1])==1:
if arr[n-1][n-2]=='1':
ans.append([n,n-1])
elif arr[n-2][n-1]=='1':
ans.append([n-1,n])
elif int(arr[0][1])+int(arr[1][0])==1 and int(arr[n-1][n-2])+int(arr[n-2][n-1])==0:
if arr[0][1]=='0':
ans.append([1,2])
elif arr[1][0]=='0':
ans.append([2,1])
elif int(arr[0][1])+int(arr[1][0])==0 and int(arr[n-1][n-2])+int(arr[n-2][n-1])==1:
if arr[n-1][n-2]=='0':
ans.append([n,n-1])
elif arr[n-2][n-1]=='0':
ans.append([n-1,n])
print(len(ans))
for i in range(len(ans)):
print(*ans[i])
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
string a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
long long c = 0;
long long p1 = a[0][1] - '0', p2 = a[1][0] - '0';
long long q1 = a[n - 1][n - 2] - '0', q2 = a[n - 2][n - 1] - '0';
long long cnt1, cnt2;
cnt1 = abs(0ll - p1) + abs(0ll - p2) + abs(1ll - q1) + abs(1ll - q2);
cnt2 = abs(0ll - q1) + abs(0ll - q2) + abs(1ll - p1) + abs(1ll - p2);
if (cnt1 <= 2) {
cout << cnt1 << "\n";
if (p1 != 0) cout << "1 2\n";
if (p2 != 0) cout << "2 1\n";
if (q1 != 1) cout << n << " " << n - 1 << "\n";
if (q2 != 1) cout << n - 1 << " " << n << "\n";
} else {
cout << cnt2 << "\n";
if (p1 != 1) cout << "1 2\n";
if (p2 != 1) cout << "2 1\n";
if (q1 != 0) cout << n << " " << n - 1 << "\n";
if (q2 != 0) cout << n - 1 << " " << n << "\n";
}
}
}
| 8 |
CPP
|
#=================================
# Author: Danish Amin
# Date: Fri Oct 23 19:09:09 2020
#=================================
import sys; input = sys.stdin.readline
for i in range(int(input())):
n = int(input())
matrix = [list(input().strip()) for _ in range(n)]
a, b, c, d = int(matrix[1][0]), int(matrix[0][1]), int(matrix[-1][-2]), int(matrix[-2][-1])
A, B, C, D = [(2, 1), (1, 2), (n, n-1), (n-1, n)]
if a == b == c == d:
print(2)
print(*A)
print(*B)
elif 1*(not a) == b == c == d: print(1); print(*B)
elif 1*(not b) == a == c == d: print(1); print(*A)
elif 1*(not c) == a == b == d: print(1); print(*D)
elif 1*(not d) == a == c == b: print(1); print(*C)
elif a == 1*(not b) and c == 1*(not d):
print(2)
if a == c:
print(*B)
print(*C)
else:
print(*B)
print(*D)
else: print(0)
| 8 |
PYTHON3
|
t = int(input())
for f in range(t):
n = int(input())
a = ""
b = ""
c = ""
d = ""
for i in range(1,n+1):
l = input()
if i == 1:
a = l[1]
elif i == 2:
b = l[0]
c = l[n-1]
elif i == n-1:
c = l[n-1]
elif i == n:
d = l[n-2]
if (a==b) and (c==d):
if a==c:
print(2)
print(n-1,n)
print(n,n-1)
else:
print(0)
elif a==b and c!=d:
if c ==a:
print(1)
print(n-1,n)
else:
print(1)
print(n,n-1)
elif a!=b and c==d:
if a==c:
print(1)
print(1,2)
else:
print(1)
print(2,1)
else:
if a==c:
print(2)
print(2,1)
print(n-1,n)
else:
print(2)
print(2,1)
print(n,n-1)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
char s[210][210];
int T, n;
int ansx[3], ansy[3], tot;
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
tot = 0;
for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
if (s[1][2] == s[2][1]) {
if (s[1][2] == s[n - 1][n]) ansx[++tot] = n - 1, ansy[tot] = n;
if (s[1][2] == s[n][n - 1]) ansx[++tot] = n, ansy[tot] = n - 1;
} else if (s[n - 1][n] == s[n][n - 1]) {
if (s[1][2] == s[n - 1][n]) ansx[++tot] = 1, ansy[tot] = 2;
if (s[2][1] == s[n][n - 1]) ansx[++tot] = 2, ansy[tot] = 1;
} else {
ansx[++tot] = 1, ansy[tot] = 2;
if (s[n - 1][n] == s[2][1])
ansx[++tot] = n - 1, ansy[tot] = n;
else if (s[n][n - 1] == s[2][1])
ansx[++tot] = n, ansy[tot] = n - 1;
}
printf("%d\n", tot);
for (int i = 1; i <= tot; ++i) printf("%d %d \n", ansx[i], ansy[i]);
}
return 0;
}
| 8 |
CPP
|
test = int(input())
for t in range(test):
n = int(input())
grid = []
for i in range(n):
grid.append(input())
if grid[0][1]=='0' and grid[1][0]=='0':
if grid[n-1][n-2]=='0' and grid[n-2][n-1]=='0':
print(2)
print(n, n-1)
print(n-1, n)
elif grid[n-1][n-2]=='0' and grid[n-2][n-1]=='1':
print(1)
print(n, n-1)
elif grid[n-1][n-2]=='1' and grid[n-2][n-1]=='0':
print(1)
print(n-1, n)
else:
print(0)
elif grid[0][1]=='0' and grid[1][0]=='1':
if grid[n-1][n-2]=='0' and grid[n-2][n-1]=='0':
print(1)
print(1, 2)
elif grid[n-1][n-2]=='0' and grid[n-2][n-1]=='1':
print(2)
print(n, n-1)
print(2,1)
elif grid[n-1][n-2]=='1' and grid[n-2][n-1]=='0':
print(2)
print(n, n-1)
print(1,2)
else:
print(1)
print(2,1)
elif grid[0][1]=='1' and grid[1][0]=='0':
if grid[n-1][n-2]=='0' and grid[n-2][n-1]=='0':
print(1)
print(2, 1)
elif grid[n-1][n-2]=='0' and grid[n-2][n-1]=='1':
print(2)
print(n, n-1)
print(1,2)
elif grid[n-1][n-2]=='1' and grid[n-2][n-1]=='0':
print(2)
print(n, n-1)
print(2,1)
else:
print(1)
print(1,2)
elif grid[0][1]=='1' and grid[1][0]=='1':
if grid[n-1][n-2]=='0' and grid[n-2][n-1]=='0':
print(0)
elif grid[n-1][n-2]=='0' and grid[n-2][n-1]=='1':
print(1)
print(n-1, n)
elif grid[n-1][n-2]=='1' and grid[n-2][n-1]=='0':
print(1)
print(n, n-1)
else:
print(2)
print(2,1)
print(1,2)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
const int N = 200 + 5;
int t, n;
char arr[N][N];
vector<pair<int, int>> ans;
void solve() {
ans.clear();
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> arr[i][j];
}
}
int zerocnt = 0, onecnt = 0, zerocnt2 = 0, onecnt2 = 0;
if (arr[1][3] == '0')
zerocnt++;
else
onecnt++;
if (arr[2][2] == '0')
zerocnt++;
else
onecnt++;
if (arr[3][1] == '0')
zerocnt++;
else
onecnt++;
if (arr[1][2] == '0')
zerocnt2++;
else
onecnt2++;
if (arr[2][1] == '0')
zerocnt2++;
else
onecnt2++;
if ((zerocnt == 3 || onecnt == 3) && (zerocnt2 == 2 || onecnt2 == 2)) {
if ((zerocnt == 3 && onecnt2 == 2) || (onecnt == 3 && zerocnt2 == 2)) {
cout << 0 << "\n";
return;
} else {
if (zerocnt == 3 && zerocnt2 == 2) {
ans.push_back({1, 2});
ans.push_back({2, 1});
} else if (onecnt == 3 && onecnt2 == 2) {
ans.push_back({1, 2});
ans.push_back({2, 1});
}
}
} else {
if (zerocnt > onecnt) {
if (zerocnt2 == 2) {
if (arr[1][3] == '0') ans.push_back({1, 3});
if (arr[2][2] == '0') ans.push_back({2, 2});
if (arr[3][1] == '0') ans.push_back({3, 1});
} else {
if (arr[1][3] == '1') ans.push_back({1, 3});
if (arr[2][2] == '1') ans.push_back({2, 2});
if (arr[3][1] == '1') ans.push_back({3, 1});
if (arr[1][2] == '0') ans.push_back({1, 2});
if (arr[2][1] == '0') ans.push_back({2, 1});
}
} else if (onecnt > zerocnt) {
if (onecnt2 == 2) {
if (arr[1][3] == '1') ans.push_back({1, 3});
if (arr[2][2] == '1') ans.push_back({2, 2});
if (arr[3][1] == '1') ans.push_back({3, 1});
} else {
if (arr[1][3] == '0') ans.push_back({1, 3});
if (arr[2][2] == '0') ans.push_back({2, 2});
if (arr[3][1] == '0') ans.push_back({3, 1});
if (arr[1][2] == '1') ans.push_back({1, 2});
if (arr[2][1] == '1') ans.push_back({2, 1});
}
}
}
cout << ans.size() << "\n";
for (auto p : ans) cout << p.first << " " << p.second << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
while (t--) {
solve();
}
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
long long modPow(long long a, long long b);
long long modInv(long long a);
void solve() {
long long n;
cin >> n;
char a[n][n];
for (long long i = 0; i < n; i++)
for (long long j = 0; j < n; j++) cin >> a[i][j];
vector<pair<long long, long long> > x;
if (a[0][1] == a[1][0] && a[n - 1][n - 2] == a[n - 2][n - 1]) {
if (a[0][1] != a[n - 2][n - 1]) {
cout << 0 << "\n";
return;
} else {
cout << 2 << "\n";
cout << "1 2"
<< "\n"
<< "2 1"
<< "\n";
return;
}
}
if (a[0][1] == a[1][0]) {
if (a[n - 1][n - 2] == a[0][1])
x.push_back({n, n - 1});
else
x.push_back({n - 1, n});
cout << 1 << "\n";
cout << x[0].first << " " << x[0].second << "\n";
return;
}
if (a[n - 1][n - 2] == a[n - 2][n - 1]) {
if (a[n - 1][n - 2] == a[0][1])
x.push_back({1, 2});
else
x.push_back({2, 1});
cout << 1 << "\n";
cout << x[0].first << " " << x[0].second << "\n";
return;
}
cout << 2 << "\n";
if (a[0][1] == '0')
cout << "1 2"
<< "\n";
if (a[1][0] == '0')
cout << "2 1"
<< "\n";
if (a[n - 1][n - 2] == '1')
cout << n << " " << n - 1 << "\n";
else
cout << n - 1 << " " << n << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long test = 1;
cin >> test;
while (test--) solve();
}
long long modPow(long long a, long long b) {
if (b == 0) return 1;
if (b % 2 == 0) {
long long x = a * a;
x %= 1000000007;
return modPow(x, b / 2);
}
return (a * modPow(a, b - 1)) % 1000000007;
}
long long modInv(long long a) { return modPow(a, 1000000007 - 2); }
| 8 |
CPP
|
l = [(1, 0), (0, 1), (-1, -2), (-2, -1)]
t = int(input())
for _ in range(t):
n = int(input())
s = [input() for _ in range(n)]
cnt = 0
for x, y in l:
if (s[x][y] == '1') ^ (x >= 0):
cnt += 1
if cnt >= 2:
print(4 - cnt)
for x, y in l:
if (s[x][y] == '1') ^ (x < 0):
print(x % n + 1, y % n + 1)
else:
print(cnt)
for x, y in l:
if (s[x][y] == '1') ^ (x >= 0):
print(x % n + 1, y % n + 1)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
namespace FastIO {
bool IOerror = 0;
inline char nc() {
static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;
if (p1 == pend) {
p1 = buf;
pend = buf + fread(buf, 1, 100000, stdin);
if (pend == p1) {
IOerror = 1;
return -1;
}
}
return *p1++;
}
inline bool blank(char ch) {
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
template <class T>
inline bool read(T& x) {
bool sign = 0;
char ch = nc();
x = 0;
for (; blank(ch); ch = nc())
;
if (IOerror) return false;
if (ch == '-') sign = 1, ch = nc();
for (; ch >= '0' && ch <= '9'; ch = nc()) x = x * 10 + ch - '0';
if (sign) x = -x;
return true;
}
template <class T, class... U>
bool read(T& h, U&... t) {
return read(h) && read(t...);
}
}; // namespace FastIO
using namespace std;
using namespace FastIO;
template <typename T>
T inverse(T a, T m) {
T u = 0, v = 1;
while (a != 0) {
T t = m / a;
m -= t * a;
swap(a, m);
u -= t * v;
swap(u, v);
}
assert(m == 1);
return u;
}
template <typename T>
class Modular {
public:
using Type = typename decay<decltype(T::value)>::type;
constexpr Modular() : value() {}
template <typename U>
Modular(const U& x) {
value = normalize(x);
}
template <typename U>
static Type normalize(const U& x) {
Type v;
if (-mod() <= x && x < mod())
v = static_cast<Type>(x);
else
v = static_cast<Type>(x % mod());
if (v < 0) v += mod();
return v;
}
const Type& operator()() const { return value; }
template <typename U>
explicit operator U() const {
return static_cast<U>(value);
}
constexpr static Type mod() { return T::value; }
Modular& operator+=(const Modular& other) {
if ((value += other.value) >= mod()) value -= mod();
return *this;
}
Modular& operator-=(const Modular& other) {
if ((value -= other.value) < 0) value += mod();
return *this;
}
template <typename U>
Modular& operator+=(const U& other) {
return *this += Modular(other);
}
template <typename U>
Modular& operator-=(const U& other) {
return *this -= Modular(other);
}
Modular& operator++() { return *this += 1; }
Modular& operator--() { return *this -= 1; }
Modular operator++(int) {
Modular result(*this);
*this += 1;
return result;
}
Modular operator--(int) {
Modular result(*this);
*this -= 1;
return result;
}
Modular operator-() const { return Modular(-value); }
template <typename U = T>
typename enable_if<is_same<typename Modular<U>::Type, int>::value,
Modular>::type&
operator*=(const Modular& rhs) {
value = normalize(static_cast<int64_t>(value) *
static_cast<int64_t>(rhs.value));
return *this;
}
template <typename U = T>
typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value,
Modular>::type&
operator*=(const Modular& rhs) {
int64_t q = static_cast<int64_t>(static_cast<long double>(value) *
rhs.value / mod());
value = normalize(value * rhs.value - q * mod());
return *this;
}
template <typename U = T>
typename enable_if<!is_integral<typename Modular<U>::Type>::value,
Modular>::type&
operator*=(const Modular& rhs) {
value = normalize(value * rhs.value);
return *this;
}
Modular& operator/=(const Modular& other) {
return *this *= Modular(inverse(other.value, mod()));
}
template <typename U>
friend const Modular<U>& abs(const Modular<U>& v) {
return v;
}
template <typename U>
friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);
template <typename U>
friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);
template <typename U>
friend std::istream& operator>>(std::istream& stream, Modular<U>& number);
private:
Type value;
};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long INF = 0x3f3f3f3f;
const long long N = 333;
char a[N][N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n, i, j;
cin >> n;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++) cin >> a[i][j];
long long ans = 0;
vector<pair<long long, long long> > res;
if (a[1][2] == a[2][1] && a[1][2] == a[n][n - 1] &&
a[1][2] == a[n - 1][n]) {
ans = 2;
res.push_back(make_pair(1, 2));
res.push_back(make_pair(2, 1));
}
if (a[1][2] != a[2][1]) {
ans++;
if (a[n - 1][n] == a[n][n - 1] && a[2][1] == a[n][n - 1]) {
res.push_back(make_pair(2, 1));
a[2][1] = a[1][2];
} else {
res.push_back(make_pair(1, 2));
a[1][2] = a[2][1];
}
}
if (a[n - 1][n] != a[n][n - 1]) {
ans++;
if (a[n][n - 1] == a[1][2])
res.push_back(make_pair(n, n - 1));
else
res.push_back(make_pair(n - 1, n));
}
cout << ans << endl;
for (i = 0; i < ans; i++)
cout << res[i].first << " " << res[i].second << endl;
}
return 0;
}
| 8 |
CPP
|
for _ in range (int(input())):
n=int(input())
a=list()
for i in range (n):
s=input()
a.append(s)
#print(a)
i=int(a[0][1]);j=int(a[1][0])
c1=int(a[0][2])
c2=int(a[1][1])
c3=int(a[2][0])
r=[]
if i==j:
if i==0:
if c1==c2==c3==0:
r.append((1,2))
r.append((2,1))
else:
if c1==0:
r.append((1,3))
if c2==0:
r.append((2,2))
if c3==0:
r.append((3,1))
else:
if c1==c2==c3==1:
r.append((1,2))
r.append((2,1))
else:
if c1==1:
r.append((1,3))
if c2==1:
r.append((2,2))
if c3==1:
r.append((3,1))
else:
if i==1:
if c1==c2==c3:
if c1==1:
r.append((1,2))
else:
r.append((2,1))
else:
if c1+c2+c3==1:
r.append((2,1))
if c1==1:
r.append((1,3))
elif c2==1:
r.append((2,2))
elif c3==1:
r.append((3,1))
else:
r.append((1,2))
if c1==0:
r.append((1,3))
elif c2==0:
r.append((2,2))
elif c3==0:
r.append((3,1))
else:
if c1==c2==c3:
if c1==1:
r.append((2,1))
else:
r.append((1,2))
else:
if c1+c2+c3==1:
r.append((1,2))
if c1==1:
r.append((1,3))
elif c2==1:
r.append((2,2))
elif c3==1:
r.append((3,1))
else:
r.append((2,1))
if c1==0:
r.append((1,3))
elif c2==0:
r.append((2,2))
elif c3==0:
r.append((3,1))
print(len(r))
for i in r:
print(*i)
| 8 |
PYTHON3
|
for i in range(int(input())):
n=int(input())
l=list()
for i in range(n):
x=input()
lst=list()
for i in x:
lst.append(i)
l.append(lst)
l1=l[n-2][n-1]
l2=l[n-1][n-2]
f1=l[0][1]
f2=l[1][0]
if int(f1)==0 and int(f2)==0:
if int(l1)==0 and int(l2)==0:
print(2)
print(n-2+1,n-1+1)
print(n-1+1,n-2+1)
elif int(l1)==1 and int(l2)==0:
print(1)
print(n-1+1,n-2+1)
elif int(l1)==0 and int(l2)==1:
print(1)
print(n-2+1,n-1+1)
else:
print(0)
elif int(f1)==1 and int(f2)==1:
if int(l1)==1 and int(l2)==1:
print(2)
print(n-2+1,n-1+1)
print(n-1+1,n-2+1)
elif int(l1)==0 and int(l2)==1:
print(1)
print(n-1+1,n-2+1)
elif int(l1)==1 and int(l2)==0:
print(1)
print(n-2+1,n-1+1)
else:
print(0)
elif int(f1)==0 and int(f2)==1:
if int(l1)==0 and int(l2)==0:
print(1)
print(1,2)
elif int(l1)==1 and int(l2)==0:
print(2)
print(2,1)
print(n-1+1,n-2+1)
elif int(l1)==0 and int(l2)==1:
print(2)
print(2,1)
print(n-2+1,n-1+1)
else:
print(1)
print(2,1)
elif int(f1)==1 and int(f2)==0:
if int(l1)==0 and int(l2)==0:
print(1)
print(2,1)
elif int(l1)==1 and int(l2)==0:
print(2)
print(1,2)
print(n-1+1,n-2+1)
elif int(l1)==0 and int(l2)==1:
print(2)
print(1,2)
print(n-2+1,n-1+1)
else:
print(1)
print(1,2)
| 8 |
PYTHON3
|
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
# from fractions import *
from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz/'
M=1000000007
EPS=1e-6
def Ceil(a,b): return a//b+int(a%b>0)
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
for _ in range(Int()):
n=Int()
a=[]
for i in range(n): a.append(input())
x=a[0][1]
y=a[1][0]
w=a[n-1][n-2]
z=a[n-2][n-1]
# print(x,y)
# print(w,z)
ans=[]
if(x==y):
if(w==z):
if(w!=x):pass
else:
ans.append((n,n-1))
ans.append((n-1,n))
else:
if(w==x): ans.append((n,n-1))
else: ans.append((n-1,n))
else:
if(w==z):
if(w==x): ans.append((1,2))
else: ans.append((2,1))
else:
if(x==w):
ans.append((1,2))
ans.append((n-1,n))
else:
ans.append((1,2))
ans.append((n,n-1))
print(len(ans))
for i in ans: print(*i)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
const int maax = 300001;
const long long mod = 998244353;
long long prime[maax];
long long fact[maax];
long long inv[maax];
long long nCr(long long n, long long r) {
return (((fact[n] * inv[r]) % mod) * inv[n - r]) % mod;
}
void make() {
prime[1] = 1;
for (long long i = 2; i < (long long)maax; i++) {
if (!prime[i]) {
for (int j = i + i; j < maax; j += i) prime[j] = 1;
}
}
fact[0] = 1;
for (long long i = 0; i < (long long)maax; i++) {
fact[i] *= fact[i - 1];
if (fact[i] > mod) fact[i] %= mod;
}
}
long long power(long long x, long long y) {
long long res = 1;
while (y) {
if (y & 1) res = (res * x) % mod;
y >>= 1;
x = (x * x) % mod;
}
return res;
}
long long inverse(long long a) { return power(a, mod - 2); }
bool findpath(vector<vector<char> > &v, int a, int b, vector<vector<int> > vis,
char c) {
if (a < 0 || b < 0 || a >= v.size() || b >= v.size() || vis[a][b]) return 0;
if (v[a][b] == 'F') {
return 1;
}
if (v[a][b] != c) return 0;
vis[a][b] = 1;
int ans = 0;
ans |= findpath(v, a - 1, b, vis, c);
if (ans) return ans;
ans |= findpath(v, a + 1, b, vis, c);
if (ans) return ans;
ans |= findpath(v, a, b - 1, vis, c);
if (ans) return ans;
ans |= findpath(v, a, b + 1, vis, c);
vis[a][b] = 0;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<vector<char> > v(n, vector<char>(n));
for (long long i = 0; i < (long long)n; i++) {
for (long long j = 0; j < (long long)n; j++) cin >> v[i][j];
}
int z1 = 0;
int z2 = 0;
if (v[0][1] == '0') z1++;
if (v[1][0] == '0') z1++;
if (v[n - 1][n - 2] == '0') z2++;
if (v[n - 2][n - 1] == '0') z2++;
vector<pair<long long, long long> > ans;
if (z1 == 2) {
if (z2 == 2) {
ans.push_back({n - 1, n - 2});
ans.push_back({n - 2, n - 1});
} else if (z2 == 1) {
if (v[n - 1][n - 2] == '0')
ans.push_back({n - 1, n - 2});
else
ans.push_back({n - 2, n - 1});
}
} else if (z1 == 1) {
if (z2 == 2) {
if (v[0][1] == '0')
ans.push_back({0, 1});
else
ans.push_back({1, 0});
} else if (z2 == 1) {
if (v[0][1] == '0')
ans.push_back({0, 1});
else
ans.push_back({1, 0});
if (v[n - 1][n - 2] == '1')
ans.push_back({n - 1, n - 2});
else
ans.push_back({n - 2, n - 1});
} else {
if (v[0][1] == '1')
ans.push_back({0, 1});
else
ans.push_back({1, 0});
}
} else {
if (z2 == 0) {
ans.push_back({n - 1, n - 2});
ans.push_back({n - 2, n - 1});
} else if (z2 == 1) {
if (v[n - 1][n - 2] == '1')
ans.push_back({n - 1, n - 2});
else
ans.push_back({n - 2, n - 1});
}
}
cout << ans.size() << "\n";
for (int i = 0; i < ans.size(); i++)
cout << ans[i].first + 1 << " " << ans[i].second + 1 << "\n";
}
return 0;
}
| 8 |
CPP
|
from sys import stdin, gettrace
if gettrace():
inputi = input
else:
def input():
return next(stdin)[:-1]
def inputi():
return stdin.buffer.readline()
def solve():
n = int(input())
grid = []
for _ in range(n):
grid.append(input())
res = []
if grid[0][1] == grid[1][0]:
if grid[-1][-2] == grid[0][1]:
res.append((n,n-1))
if grid[-2][-1] == grid[0][1]:
res.append((n-1,n))
elif grid[-1][-2] == grid[-2][-1]:
if grid[0][1] == grid[-1][-2]:
res.append((1,2))
if grid[1][0] == grid[-2][-1]:
res.append((2,1))
else:
if grid[0][1] == '1':
res.append((1,2))
else:
res.append((2,1))
if grid[-1][-2] == '0':
res.append((n,n-1))
else:
res.append((n-1, n))
print(len(res))
for x,y in res:
print(x, y)
def main():
t = int(input())
for _ in range(t):
solve()
if __name__ == "__main__":
main()
| 8 |
PYTHON3
|
for _ in range(int(input())):
n = int(input())
mat = []
for i in range(n):
mat.append(input())
res = []
start = 0
end = 0
# all equal to 0 or 1
if mat[0][1] == mat[1][0] == mat[n - 1][n - 2] == mat[n - 2][n - 1]: #2
print(2)
print(1, 2)
print(2, 1)
elif mat[0][1] == mat[1][0] == mat[n - 1][n - 2] and mat[n - 1][n - 2] != mat[n - 2][n - 1]: # 3 equal, 1 unequal
print(1)
print(n, n - 1)
elif mat[0][1] == mat[1][0] == mat[n - 2][n - 1] and mat[n - 1][n - 2] != mat[n - 2][n - 1]: # 3 equal, 1 unequal
print(1)
print(n - 1, n)
elif mat[1][0] == mat[n - 1][n - 2]==mat[n - 2][n - 1] and mat[0][1]!=mat[1][0]: # 3 equal, 1 unequal
print(1)
print(2, 1)
elif mat[0][1] == mat[n - 1][n - 2]==mat[n - 2][n - 1] and mat[0][1]!=mat[1][0]: # 3 equal, 1 unequal
print(1)
print(1, 2)
elif mat[0][1] == mat[1][0] and mat[n - 1][n - 2] == mat[n - 2][n - 1]: # 2 in pair equal
print(0)
elif mat[0][1] == mat[n - 2][n - 1] and mat[1][0] == mat[n - 1][n - 2]:
print(2)
print(1, 2)
print(n, n - 1)
elif mat[0][1] == mat[n - 1][n - 2] and mat[n - 2][n - 1] == mat[1][0]:
print(2)
print(1, 2)
print(n - 1, n)
| 8 |
PYTHON3
|
for tt in range(int(input())):
n=int(input())
mat=[]
for i in range(n):
mat.append(list(input()))
c=0;ans=[]
if mat[0][1]=="1" and mat[1][0]=="1":
if mat[n-2][n-1]=="1":
c+=1
ans.append((n-1,n))
if mat[n-1][n-2]=="1":
c+=1
ans.append((n,n-1))
elif mat[0][1]=="0" and mat[1][0]=="0":
if mat[n-2][n-1]=="0":
c+=1
ans.append((n-1,n))
if mat[n-1][n-2]=="0":
c+=1
ans.append((n,n-1))
elif mat[0][1]=="0" and mat[1][0]=="1":
if mat[n-2][n-1]=="0" and mat[n-1][n-2]=="1":
c=2
ans.append((1,2))
ans.append((n,n-1))
elif mat[n-2][n-1]=="1" and mat[n-1][n-2]=="0":
c=2
ans.append((2,1))
ans.append((n,n-1))
elif mat[n-2][n-1]=="1" and mat[n-1][n-2]=="1":
c=1
ans.append((2,1))
elif mat[n-2][n-1]=="0" and mat[n-1][n-2]=="0":
c=1
ans.append((1,2))
elif mat[0][1]=="1" and mat[1][0]=="0":
if mat[n-2][n-1]=="0" and mat[n-1][n-2]=="1":
c=2
ans.append((2,1))
ans.append((n,n-1))
elif mat[n-2][n-1]=="1" and mat[n-1][n-2]=="0":
c=2
ans.append((1,2))
ans.append((n,n-1))
elif mat[n-2][n-1]=="1" and mat[n-1][n-2]=="1":
c=1
ans.append((1,2))
elif mat[n-2][n-1]=="0" and mat[n-1][n-2]=="0":
c=1
ans.append((2,1))
print(c)
for i in ans:
print(*i)
| 8 |
PYTHON3
|
for i in range(int(input())):
n = int(input())
a = [input() for i in range(n)]
x, y, w, z = a[0][1], a[1][0], a[-1][-2], a[-2][-1]
c = 0
ans=[]
if (x == '1' and y == '1'):
if (w == '1'):
c += 1
ans.append([n,n-1])
if z == '1':
c+=1
ans.append([n-1,n])
elif (x == '0' and y == '0'):
if (w == '0'):
c += 1
ans.append([n,n-1])
if z == '0':
c+=1
ans.append([n-1,n])
else:
if (w == '1' and z == '1'):
if (x == '1'):
c += 1
ans.append([1,2])
elif y == '1':
c+=1
ans.append([2, 1])
elif (w == '0' and z == '0'):
if (x == '0'):
c += 1
ans.append([1,2])
elif y == '0':
c+=1
ans.append([2, 1])
elif (w == '1' and z == '0'):
c += 1
ans.append([n-1,n])
if (x == '1'):
c += 1
ans.append([1,2])
else:
c+=1
ans.append([2, 1])
else:
c += 1
ans.append([n-1,n])
if (x == '0'):
c += 1
ans.append([1,2])
else:
c+=1
ans.append([2, 1])
if (c == 0):
print(0)
elif(c==1):
print(1)
print(*ans[0])
else:
print(2)
ans.sort()
print(*ans[0])
print(*ans[1])
| 8 |
PYTHON3
|
if __name__ == "__main__":
t = int(input())
ans = []
for u in range(t):
n = int(input())
way = []
key = ['0', '1']
for i in range(n):
way.append(input())
if way[0][1] == way[1][0]:
if way[n - 1][n - 2] == way[n - 2][n - 1]:
if way[n - 1][n - 2] == way[0][1]:
ans.append(2)
ans.append(str(n) + ' ' + str(n - 1))
ans.append(str(n - 1) + ' ' + str(n))
else:
ans.append(0)
else:
if way[n - 1][n - 2] == way[0][1]:
ans.append(1)
ans.append(str(n) + ' ' + str(n - 1))
else:
ans.append(1)
ans.append(str(n - 1) + ' ' + str(n))
else:
if way[n - 1][n - 2] == way[n - 2][n - 1]:
if way[n - 1][n - 2] == way[0][1]:
ans.append(1)
ans.append(str(1) + ' ' + str(2))
else:
ans.append(1)
ans.append(str(2) + ' ' + str(1))
else:
if way[1][0] == way[n - 1][n - 2]:
ans.append(2)
ans.append(str(1) + ' ' + str(2))
ans.append(str(n) + ' ' + str(n - 1))
else:
ans.append(2)
ans.append(str(2) + ' ' + str(1))
ans.append(str(n) + ' ' + str(n - 1))
for a in ans:
print(a)
| 8 |
PYTHON3
|
from sys import stdin,stdout
st=lambda:list(stdin.readline().strip())
li=lambda:list(map(int,stdin.readline().split()))
mp=lambda:map(int,stdin.readline().split())
inp=lambda:int(stdin.readline())
pr=lambda n: stdout.write(str(n)+"\n")
def solve():
n= inp()
ans=0
val=[]
l=[ st() for i in range(n)]
if l[0][1]== l[1][0]:
x= l[0][1]
a,b = l[n-1][n-2],l[n-2][n-1]
if a==x:
ans+=1
val.append((n,n-1))
if b==x:
ans+=1
val.append((n-1,n))
print(ans)
for i in val:
print(*i)
return
a,b= l[n-1][n-2],l[n-2][n-1]
x,y= l[0][1],l[1][0]
if a==b:
z=a
if x==a:
ans+=1
val.append((1,2))
else:
ans+=1
val.append((2,1))
else:
ans+=1
val.append((1,2))
x= 1-int(x)
if int(a)==x:
ans+=1
val.append((n,n-1))
else:
ans+=1
val.append((n-1,n))
print(ans)
for i in val:
print(*i)
for _ in range(inp()):
solve()
| 8 |
PYTHON3
|
for _ in range(int(input())):
n = int(input())
grid = []
for i in range(n):
grid.append(input())
s_bottom, s_right, f_left, f_top = grid[1][0], grid[0][1], grid[n - 1][n - 2], grid[n - 2][n - 1]
if s_bottom == s_right == f_left == f_top:
print(2)
print(1, 2)
print(2, 1)
elif s_bottom == s_right == f_left:
print(1)
print(n, n - 1)
elif s_bottom == s_right == f_top:
print(1)
print(n - 1, n)
elif f_top == f_left == s_bottom:
print(1)
print(2, 1)
elif f_top == f_left == s_right:
print(1)
print(1, 2)
elif f_top == s_right and f_left == s_bottom:
print(2)
print(n - 1, n)
print(2, 1)
elif f_top == s_bottom and f_left == s_right:
print(2)
print(n - 1, n)
print(1, 2)
else:
print(0)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
const bool multi_test = true;
bool solve() {
int n;
cin >> n;
vector<string> t(n);
for (int(i) = 0; (i) < (n); (i)++) cin >> t[i];
char a, b, c, d;
a = t[0][1];
b = t[1][0];
c = t[n - 1][n - 2];
d = t[n - 2][n - 1];
if (a == b) {
if (c == d) {
if (a != c) {
cout << 0;
} else {
cout << 2 << '\n';
cout << 2 << ' ' << 1 << '\n';
cout << 1 << ' ' << 2;
}
} else {
if (a == c) {
cout << 1 << '\n';
cout << n << ' ' << n - 1;
} else {
cout << 1 << '\n';
cout << n - 1 << ' ' << n;
}
}
} else {
if (c == d) {
if (a == c) {
cout << 1 << '\n';
cout << 1 << ' ' << 2;
} else {
cout << 1 << '\n';
cout << 2 << ' ' << 1;
}
} else {
if (a == c) {
cout << 2 << '\n';
cout << 2 << ' ' << 1 << '\n';
cout << n << ' ' << n - 1;
} else {
cout << 2 << '\n';
cout << 2 << ' ' << 1 << '\n';
cout << n - 1 << ' ' << n;
}
}
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
if (!multi_test) {
solve();
return 0;
}
int t;
cin >> t;
for (int(i) = 0; (i) < (t); (i)++) {
cin.ignore();
if (!solve()) return 0;
cout << endl;
}
return 0;
}
| 8 |
CPP
|
import sys
INP = lambda: sys.stdin.readline().strip()
INT = lambda: int(INP())
MAP = lambda: map(int, INP().split())
ARR = lambda: [ord(i)-48 for i in list(INP())]
def JOIN(arr, x=' '): return x.join([str(i) for i in arr])
def EXIT(x='NO'): print(x); exit()
for _ in range(INT()):
n = INT()
arr = [INP() for _ in range(n)]
a12,a21 = int(arr[0][1]),int(arr[1][0])
anm,amn = int(arr[-1][-2]),int(arr[-2][-1])
del arr
if a12==a21:
if anm==amn:
if a12==anm:
print(2)
print(1,2)
print(2,1)
else:
print(0)
else:
if a12==anm:
print(1)
print(n,n-1)
else:
print(1)
print(n-1,n)
else:
if anm==amn:
if a12==anm:
print(1)
print(1,2)
else:
print(1)
print(2,1)
else:
if a12==anm:
print(2)
print(2,1)
print(n,n-1)
else:
print(2)
print(1,2)
print(n,n-1)
| 8 |
PYTHON3
|
for u in range(int(input())):
n=int(input())
l=[]
x,y=[],[]
for i in range(n):
l.append(list(input()))
d=[l[0][1],l[1][0],l[n-1][n-2],l[n-2][n-1]]
if(d[0]=='1'):
x.append([1,2])
if(d[1]=='1'):
x.append([2,1])
if(d[2]=='0'):
x.append([n,n-1])
if(d[3]=='0'):
x.append([n-1,n])
if(d[0]=='0'):
y.append([1,2])
if(d[1]=='0'):
y.append([2,1])
if(d[2]=='1'):
y.append([n,n-1])
if(d[3]=='1'):
y.append([n-1,n])
if(len(x)<=len(y)):
print(len(x))
for i in x:
print(*i)
else:
print(len(y))
for i in y:
print(*i)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
string s[n];
long long int cntU = 0, cntD = 0;
for (long long int i = 0; i < n; i++) {
cin >> s[i];
}
if (s[0][1] == '0' && s[1][0] == '0') {
if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '1') {
cout << "0" << endl;
} else if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '0') {
cout << "2" << endl
<< n - 1 << " " << n << endl
<< n << " " << n - 1 << endl;
} else if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '1') {
cout << "1" << endl << n - 1 << " " << n << endl;
} else if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '0') {
cout << "1" << endl << n << " " << n - 1 << endl;
}
} else if (s[0][1] == '1' && s[1][0] == '1') {
if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '0') {
cout << "0" << endl;
} else if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '1') {
cout << "2" << endl
<< n - 1 << " " << n << endl
<< n << " " << n - 1 << endl;
} else if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '0') {
cout << "1" << endl << n - 1 << " " << n << endl;
} else if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '1') {
cout << "1" << endl << n << " " << n - 1 << endl;
}
} else if (s[0][1] == '0' && s[1][0] == '1') {
if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '0') {
cout << "1" << endl
<< "1"
<< " "
<< "2" << endl;
} else if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '1') {
cout << "1" << endl
<< "2"
<< " "
<< "1" << endl;
} else if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '0') {
cout << "2" << endl
<< n - 1 << " " << n << endl
<< "1"
<< " "
<< "2" << endl;
} else if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '1') {
cout << "2" << endl
<< n << " " << n - 1 << endl
<< "1"
<< " "
<< "2" << endl;
}
} else if (s[0][1] == '1' && s[1][0] == '0') {
if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '0') {
cout << "1" << endl
<< "2"
<< " "
<< "1" << endl;
} else if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '1') {
cout << "1" << endl
<< "1"
<< " "
<< "2" << endl;
} else if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '0') {
cout << "2" << endl
<< n << " " << n - 1 << endl
<< "1"
<< " "
<< "2" << endl;
} else if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '1') {
cout << "2" << endl
<< n << " " << n - 1 << endl
<< "2"
<< " "
<< "1" << endl;
}
}
}
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long MAX = 100100;
void pre() {}
void solve() {
long long n;
cin >> n;
vector<string> v(n);
for (long long i = 0; i < n; ++i) cin >> v[i];
vector<pair<long long, long long> > rm;
long long up = 0, dn = 0;
if (v[0][1] == '1') up++;
if (v[1][0] == '1') up++;
if (v[n - 1][n - 2] == '1') dn++;
if (v[n - 2][n - 1] == '1') dn++;
if (up == 0) {
if (v[n - 1][n - 2] != '1') rm.push_back({n - 1, n - 2});
if (v[n - 2][n - 1] != '1') rm.push_back({n - 2, n - 1});
} else if (dn == 0) {
if (v[1][0] != '1') rm.push_back({1, 0});
if (v[0][1] != '1') rm.push_back({0, 1});
} else if (up + dn == 4) {
rm.push_back({1, 0});
rm.push_back({0, 1});
} else if (up + dn == 0) {
rm.push_back({1, 0});
rm.push_back({0, 1});
} else if (up == 1 && dn == 1) {
if (v[n - 1][n - 2] != '1') rm.push_back({n - 1, n - 2});
if (v[n - 2][n - 1] != '1') rm.push_back({n - 2, n - 1});
if (v[1][0] != '0') rm.push_back({1, 0});
if (v[0][1] != '0') rm.push_back({0, 1});
} else if (up == 2) {
if (v[n - 1][n - 2] != '0') rm.push_back({n - 1, n - 2});
if (v[n - 2][n - 1] != '0') rm.push_back({n - 2, n - 1});
} else if (dn == 2) {
if (v[1][0] != '0') rm.push_back({1, 0});
if (v[0][1] != '0') rm.push_back({0, 1});
}
cout << ((long long)(rm).size()) << "\n";
for (auto p : rm) cout << p.first + 1 << " " << p.second + 1 << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
pre();
long long t = 1;
cin >> t;
for (long long CASE = 1; CASE <= t; ++CASE) {
solve();
}
{};
return 0;
}
| 8 |
CPP
|
import sys
input = sys.stdin.readline
def solve():
n=int(input())
M=[list(input().strip()) for _ in range(n)]
ans = []
a,b,c,d=M[0][1],M[1][0],M[n-1][n-2],M[n-2][n-1]
if c==d:
if a==d:
ans.append((1,2))
if b==d:
ans.append((2,1))
elif a==b:
if c==a:
ans.append((n,n-1))
if d==a:
ans.append((n-1,n))
else:
if a=='1':
ans.append((1,2))
if b=='1':
ans.append((2,1))
if c=='0':
ans.append((n,n-1))
if d=='0':
ans.append((n-1,n))
print(len(ans))
for i in ans:
print(*i)
if __name__=="__main__":
for _ in range(int(input())):
solve()
| 8 |
PYTHON3
|
for i1 in range(int(input())):
n=int(input())
a=[]
for i in range(n):
a.append(input())
x=a[0][1]
y=a[1][0]
w=a[-1][-2]
z=a[-2][-1]
ans=[]
if(x==y):
if(w==z):
if(w!=x):
pass
else:
ans.append((n,n-1))
ans.append((n-1,n))
else:
if(w==x): ans.append((n,n-1))
else: ans.append((n-1,n))
else:
if(w==z):
if(w==x):
ans.append((1,2))
else:
ans.append((2,1))
else:
if(x==w):
ans.append((1,2))
ans.append((n-1,n))
else:
ans.append((1,2))
ans.append((n,n-1))
print(len(ans))
for l,r in ans:
print(l,r)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int dim;
cin >> dim;
vector<vector<int> > vec;
vector<int> load;
string a;
for (int i = 0; i < dim; i++) {
cin >> a;
for (int j = 0; j < dim; j++) {
load.push_back(a[j] - 48);
}
vec.push_back(load);
load.clear();
}
if (vec[0][1] == vec[1][0]) {
if ((vec[dim - 1][dim - 2] == vec[dim - 2][dim - 1]) &&
(vec[0][1] == vec[dim - 1][dim - 2])) {
cout << "2\n";
cout << "1"
<< " "
<< "2\n";
cout << "2"
<< " "
<< "1\n";
} else if (vec[0][1] == vec[dim - 1][dim - 2]) {
cout << "1" << endl;
cout << dim << " " << dim - 1 << endl;
} else if (vec[0][1] == vec[dim - 2][dim - 1]) {
cout << "1" << endl;
cout << dim - 1 << " " << dim << endl;
} else {
cout << "0" << endl;
}
} else {
if ((vec[dim - 1][dim - 2] == vec[dim - 2][dim - 1]) &&
(vec[0][1] == vec[dim - 1][dim - 2])) {
cout << "1" << endl;
cout << "1"
<< " "
<< "2" << endl;
} else if ((vec[dim - 1][dim - 2] == vec[dim - 2][dim - 1]) &&
(vec[1][0] == vec[dim - 1][dim - 2])) {
cout << "1" << endl;
cout << "2"
<< " "
<< "1" << endl;
} else {
if (vec[1][0] == vec[dim - 1][dim - 2]) {
cout << "2" << endl;
cout << "2"
<< " "
<< "1" << endl;
cout << dim - 1 << " " << dim << endl;
} else if (vec[1][0] == vec[dim - 2][dim - 1]) {
cout << "2" << endl;
cout << "1"
<< " "
<< "2" << endl;
cout << dim - 1 << " " << dim << endl;
}
}
}
vec.clear();
}
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
char a[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
char k = a[0][1];
char u = a[n - 1][n - 2];
char l = a[1][0];
char v = a[n - 2][n - 1];
if (k == l) {
if (u == v) {
if (k == u) {
cout << 2 << endl;
cout << 1 << " " << 2 << endl;
cout << 2 << " " << 1 << endl;
} else
cout << 0 << endl;
} else {
if (k == u) {
cout << 1 << endl;
cout << n << " " << n - 1 << endl;
} else {
cout << 1 << endl;
cout << n - 1 << " " << n << endl;
}
}
} else {
if (u == v) {
if (k == u) {
cout << 1 << endl;
cout << 1 << " " << 2 << endl;
} else {
cout << 1 << endl;
cout << 2 << " " << 1 << endl;
}
} else {
if (k == u) {
cout << 2 << endl;
cout << 1 << " " << 2 << endl;
cout << n - 1 << " " << n << endl;
} else {
cout << 2 << endl;
cout << 2 << " " << 1 << endl;
cout << n - 1 << " " << n << endl;
}
}
}
}
return 0;
}
| 8 |
CPP
|
def solve():
n=int(input())
mat=[]
for i in range(n):
mat.append(input())
x1 = mat[0][1]
x2 = mat[1][0]
y1 = mat[n - 2][n - 1]
y2 = mat[n - 1][n - 2]
if (x1 == x2 and y1 == y2 and x1 != y1):
print(0)
return
if (x1 == x2 and y1 == y2):
print(2)
print("1 2")
print("2 1")
return
if (x1 == x2):
print(1)
if (y1 == x1):
print(n-1,end=" ")
print(n)
return
if (y2 == x1):
print(n,end=" ")
print(n-1)
return
if (y1 == y2):
print(1)
if (x1 == y1):
print("1 2")
return
if (x2 == y1):
print("2 1")
return
if (x1 == y2):
print(2)
print("1 2")
print(n-1,end=" ")
print(n)
return
if (x1 == y1):
print(2)
print("1 2")
print(n,end=" ")
print(n-1)
t=int(input())
for _ in range(t):
solve()
| 8 |
PYTHON3
|
for _ in range(int(input())):
n = int(input())
a = [input() for j in range(n)]
if (a[0][1] == a[1][0] == '1' and a[n-2][n-1] == a[n-1][n-2] == '0') or (a[0][1] == a[1][0] == '0' and a[n-2][n-1] == a[n-1][n-2] == '1'):
print(0)
else:
n1,n2,n3,n4 = int(a[0][1]), int(a[1][0]), int(a[n-1][n-2]), int(a[n-2][n-1])
if n1 + n2 == n3+n4 == 0 or n1+n2==n3+n4==2:
print(2)
print(1, 2)
print(2, 1)
elif n1 + n2 == 1 and n3+n4 == 1:
print(2)
print(1, 2)
if n1 == 1:
if n3 == 0:
print(n, n-1)
else:
print(n-1, n)
else:
if n3 == 1:
print(n, n-1)
else:
print(n-1, n)
elif n1+n2 == 0 and n3+n4 == 1:
print(1)
if n3 == 0:
print(n, n-1)
else:
print(n-1, n)
elif n1+n2 == 1 and n3+n4==0:
print(1)
if n1 == 0:
print(1,2)
else:
print(2,1)
elif n1 + n2 == 1 and n3+n4==2:
print(1)
if n1 == 1:
print(1,2)
else:
print(2,1)
else:
print(1)
if n3 == 1:
print(n,n-1)
else:
print(n-1,n)
| 8 |
PYTHON3
|
from collections import Counter, deque
# Make GRID a global variable to avoid copying data during function calls
GRID = []
SMALL_DIAGONAL = [(0, 1), (1, 0)]
BIG_DIAGONAL = [(0, 2), (1, 1), (2, 0)]
def get_input():
return input().split()
def get_int_input():
return map(int, get_input())
def _is_valid_cell(cell, n):
if cell[0] >= n or cell[1] >= n:
return False
return True
def is_there_a_path(n):
'''
Do a bfs traversal to find for any valid path
'''
queue = deque([((0, 0), '0'), ((0, 0), '1')])
FINAL_CELLS = [(n - 1, n - 2), (n - 2, n - 1)]
VISITED = {'0': [[0] * n for _ in range(n)], '1': [[0] * n for _ in range(n)]}
while queue:
cell, digit = queue.popleft()
if VISITED[digit][cell[0]][cell[1]]:
continue
else:
VISITED[digit][cell[0]][cell[1]] = 1
if cell in FINAL_CELLS:
return True
# Move right
new_cell = (cell[0] + 1, cell[1])
if _is_valid_cell(new_cell, n):
if GRID[new_cell[0]][new_cell[1]] == digit:
queue.append((new_cell, digit))
# Move down
new_cell = (cell[0], cell[1] + 1)
if _is_valid_cell(new_cell, n):
if GRID[new_cell[0]][new_cell[1]] == digit:
queue.append((new_cell, digit))
return False
def C1421B(n):
if(not is_there_a_path(n)):
return 0
else:
ans_count = 0
ans_cells = [] # list of string
if len(Counter([GRID[cell[0]][cell[1]] for cell in BIG_DIAGONAL])) == 1:
big_diagonal_value = GRID[BIG_DIAGONAL[0][0]][BIG_DIAGONAL[0][1]]
for cell in SMALL_DIAGONAL:
if GRID[cell[0]][cell[1]] == big_diagonal_value:
ans_count += 1
ans_cells.append(' '.join(map(str, [val + 1 for val in cell])))
elif GRID[0][1] == GRID[1][0]:
small_diagonal_value = GRID[0][1]
for cell in BIG_DIAGONAL:
if GRID[cell[0]][cell[1]] == small_diagonal_value:
ans_count += 1
ans_cells.append(' '.join(map(str, [val + 1 for val in cell])))
else:
counter = Counter([GRID[cell[0]][cell[1]] for cell in BIG_DIAGONAL])
inv_counter = {counter[c]: c for c in counter}
more_occurring_value = inv_counter.get(3, '') or inv_counter.get(2, '')
for cell in SMALL_DIAGONAL:
if GRID[cell[0]][cell[1]] == more_occurring_value:
ans_count += 1
ans_cells.append(' '.join(map(str, [val + 1 for val in cell])))
for cell in BIG_DIAGONAL:
if GRID[cell[0]][cell[1]] != more_occurring_value:
ans_count += 1
ans_cells.append(' '.join(map(str, [val + 1 for val in cell])))
return str(ans_count) + '\n' + '\n'.join(ans_cells)
def main():
t, = get_int_input()
for _ in range(t):
globals()['GRID'] = []
n, = get_int_input()
for _ in range(n):
GRID.append(list(input()))
# n is equal to len(GRID)
print(C1421B(n))
main()
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<string> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int up = (v[0][1] - 48) + (v[1][0] - 48);
int down = (v[n - 1][n - 2] - 48) + (v[n - 2][n - 1] - 48);
if (up == down) {
if (up == 1) {
cout << 2 << "\n";
if (v[0][1] == '1')
cout << "1 2"
<< "\n";
if (v[1][0] == '1')
cout << "2 1"
<< "\n";
if (v[n - 1][n - 2] == '0') cout << n << " " << n - 1 << "\n";
if (v[n - 2][n - 1] == '0') cout << n - 1 << " " << n << "\n";
} else {
cout << 2 << "\n";
cout << "1 2"
<< "\n";
cout << "2 1"
<< "\n";
}
} else {
if (abs(up - down) == 2) {
cout << 0 << "\n";
} else {
cout << 1 << "\n";
if (up == 1) {
if (down == 0) {
if (v[0][1] == '0')
cout << "1 2"
<< "\n";
if (v[1][0] == '0')
cout << "2 1"
<< "\n";
} else {
if (v[0][1] == '1')
cout << "1 2"
<< "\n";
if (v[1][0] == '1')
cout << "2 1"
<< "\n";
}
} else {
if (up == 0) {
if (v[n - 1][n - 2] == '0') cout << n << " " << n - 1 << "\n";
if (v[n - 2][n - 1] == '0') cout << n - 1 << " " << n << "\n";
} else {
if (v[n - 1][n - 2] == '1') cout << n << " " << n - 1 << "\n";
if (v[n - 2][n - 1] == '1') cout << n - 1 << " " << n << "\n";
}
}
}
}
}
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using pii = pair<int, int>;
using PLL = pair<LL, LL>;
using UI = unsigned int;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);
const int N = 210;
int T, n;
char s[N][N];
vector<pii> ans;
void add(char ch, int x, int y) {
if (s[x][y] == ch) ans.emplace_back(x, y);
}
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (int i = (1); i < (n + 1); ++i) scanf("%s", s[i] + 1);
ans.clear();
if (s[1][2] == s[2][1]) {
add(s[1][2], n - 1, n);
add(s[2][1], n, n - 1);
} else if (s[n - 1][n] == s[n][n - 1]) {
add(s[n][n - 1], 1, 2);
add(s[n][n - 1], 2, 1);
} else {
add(s[2][1], 2, 1);
add(s[1][2], n - 1, n);
add(s[1][2], n, n - 1);
}
printf("%d\n", (int)ans.size());
for (auto p : ans) printf("%d %d\n", p.first, p.second);
}
return 0;
}
| 8 |
CPP
|
#import datetime
t=int(input())
for _ in range(t):
n=int(input())
l=[None]*n
for i in range(n):
l[i]=list(input().split())
if(int(l[n-1][0][n-2]) ^ int(l[n-2][0][n-1])):
if(int(l[0][0][1]) ^ int(l[1][0][0])):
print(2)
if(int(l[n-1][0][n-2]) ^ int(l[0][0][1])):
print(str(n)+" "+str(n-1))
print(str(1)+" "+str(2))
else:
print(str(n)+" "+str(n-1))
print(str(2)+" "+str(1))
else:
print(1)
if(int(l[1][0][0]) ^ int(l[n-1][0][n-2])):
print(str(n-1)+" "+str(n))
else:
print(str(n)+" "+str(n-1))
else:
if(int(l[0][0][1]) ^ int(l[1][0][0])):
print(1)
if(int(l[n-1][0][n-2]) ^ int(l[1][0][0])):
print(str(1)+" "+str(2))
else:
print(str(2)+" "+str(1))
else:
if(int(l[0][0][1]) ^ int(l[n-1][0][n-2])):
print(0)
else:
print(2)
print(str(1)+" "+str(2))
print(str(2)+" "+str(1))
'''be=datetime.datetime.now()
e=datetime.datetime.now()
print(e-be)
S10
001
01F'''
| 8 |
PYTHON3
|
def rl():
return list(map(int,input().split()))
def arp(arr):
return ' '.join([str(i) for i in arr])
from collections import deque,Counter
from math import ceil,sqrt,log2,log,floor
for _ in range(int(input())):
n, = rl()
i = 0
ans = []
while i<n:
s = input()
if i<=1:
if i==0:
ans.append(s[1])
else:
ans.append(s[0])
if i>=n-2:
if i==n-2:
ans.append(s[-1])
else:
ans.append(s[-2])
i+=1
cout = []
l = [(1,2), (2,1),(n-1,n),(n,n-1)]
if ans[0]==ans[1]==ans[2]==ans[3]:
cout.append((1,2))
cout.append((2,1))
elif ans[0]=='0' and ans[1]=='0' and ans[2]=='0' and ans[3]=='1':
cout.append(l[2])
elif ans[0]=='0' and ans[1]=='0' and ans[2]=='1' and ans[3]=='0':
cout.append(l[3])
elif ans[0]=='0' and ans[1]=='0' and ans[2]=='1' and ans[3]=='1':
pass
elif ans[0]=='0' and ans[1]=='1' and ans[2]=='0' and ans[3]=='0':
cout.append(l[0])
elif ans[0]=='0' and ans[1]=='1' and ans[2]=='0' and ans[3]=='1':
cout.append(l[0])
cout.append(l[-1])
elif ans[0]=='0' and ans[1]=='1' and ans[2]=='1' and ans[3]=='0':
cout.append(l[1])
cout.append(l[-1])
elif ans[0]=='0' and ans[1]=='1' and ans[2]=='1' and ans[3]=='1':
cout.append(l[1])
elif ans[0]=='1' and ans[1]=='0' and ans[2]=='0' and ans[3]=='0':
cout.append(l[1])
elif ans[0]=='1' and ans[1]=='0' and ans[2]=='0' and ans[3]=='1':
cout.append(l[0])
cout.append(l[2])
elif ans[0]=='1' and ans[1]=='0' and ans[2]=='1' and ans[3]=='0':
cout.append(l[0])
cout.append(l[-1])
elif ans[0]=='1' and ans[1]=='0' and ans[2]=='1' and ans[3]=='1':
cout.append(l[0])
elif ans[0]=='1' and ans[1]=='1' and ans[2]=='0' and ans[3]=='0':
pass
elif ans[0]=='1' and ans[1]=='1' and ans[2]=='0' and ans[3]=='1':
cout.append(l[-1])
elif ans[0]=='1' and ans[1]=='1' and ans[2]=='1' and ans[3]=='0':
cout.append(l[2])
elif ans[0]=='1' and ans[1]=='1' and ans[2]=='1' and ans[3]=='1':
cout.append(l[2])
cout.append(l[-1])
print(len(cout))
for i in cout:
print(*i)
| 8 |
PYTHON3
|
import bisect
def solve(grid):
#print(grid)
oneone = grid[0][1]
twoone = grid[1][0]
lastleft = grid[-1][-2]
lastup = grid[-2][-1]
ans = []
n = len(grid)
if oneone == twoone:
if lastleft == oneone:
ans.append([n,n-1])
pass
if lastup == oneone:
ans.append([n-1,n])
pass
else:
if lastleft == lastup:
if lastleft == oneone:
ans.append([1,2])
pass
if lastleft == twoone:
ans.append([2,1])
pass
else:
oneone = twoone
ans.append([1,2])
if lastleft == oneone:
ans.append([n, n - 1])
pass
if lastup == oneone:
ans.append([n - 1, n])
pass
return ans
pass
t = int(input())
ans = []
for i in range(t):
n = int(input())
#s = [int(x) for x in input().split()]
#a = s[0]
#b = s[1]
grid = []
for j in range(n):
grid.append(list(input()))
ans.append(solve(grid))
# print(ans)
for test in ans:
print(len(test))
for ans in test:
for ele in ans:
print(ele,end=" ")
print()
| 8 |
PYTHON3
|
I=input
exec(int(I())*"n=int(I());a=[[*map(ord,I())]for _ in[0]*n];a=a[0][1],a[1][0],a[-2][-1]^1,a[-1][-2]^1;b=*map(a.count,a),;r=[y for x,y in zip(a,('1 2','2 1',f'{n-1} {n}',f'{n} {n-1}'))if(b[0]>3or a[b.index(min(b))])==x];print(len(r),*r);")
| 8 |
PYTHON3
|
for _ in range(int(input())):
n = int(input())
data = []
for i in range(n):
data.append(input())
# print(data)
s1 = data[0][1]
s2 = data[1][0]
f1 = data[n - 2][n - 1]
f2 = data[n - 1][n - 2]
if s1 == '0' and s2 == '0':
if f1 == '0' and f2 == '0':
print(2)
print(n - 1, n) # f1
print(n, n - 1) # f2
if f1 == '0' and f2 == '1':
print(1)
print(n - 1, n) # f1
if f1 == '1' and f2 == '0':
print(1)
print(n, n - 1) # f2
if f1 == '1' and f2 == '1':
print(0)
if s1 == '0' and s2 == '1':
if f1 == '0' and f2 == '0':
print(1)
print(1, 2) # s1
if f1 == '0' and f2 == '1':
print(2)
print(2, 1) # s2
print(n - 1, n) # f1
if f1 == '1' and f2 == '0':
print(2)
print(2, 1) # s2
print(n, n - 1) # f2
if f1 == '1' and f2 == '1':
print(1)
print(2, 1) # s2
if s1 == '1' and s2 == '0':
if f1 == '0' and f2 == '0':
print(1)
print(2, 1) # s2
if f1 == '0' and f2 == '1':
print(2)
print(2, 1) # s2
print(n, n - 1) # f2
if f1 == '1' and f2 == '0':
print(2)
print(2, 1) # s2
print(n - 1, n) # f1
if f1 == '1' and f2 == '1':
print(1)
print(1, 2) # s1
if s1 == '1' and s2 == '1':
if f1 == '0' and f2 == '0':
print(0)
if f1 == '0' and f2 == '1':
print(1)
print(n, n - 1) # f2
if f1 == '1' and f2 == '0':
print(1)
print(n - 1, n) # f1
if f1 == '1' and f2 == '1':
print(2)
print(n - 1, n) # f1
print(n, n - 1) # f2
| 8 |
PYTHON3
|
# -*- coding: utf-8 -*-
"""
created by shhuan at 2020/10/20 18:49
"""
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
from typing import List
if __name__ == '__main__':
def solve(A, N):
# 00, 11
a = [(0, 1), (1, 0)]
b = [(N-1, N-2), (N-2, N-1)]
for x, y in [(0, 1), (1, 0)]:
invert = 0
for r, c in a:
if A[r][c] != x:
invert += 1
for r, c in b:
if A[r][c] != y:
invert += 1
if invert <= 2:
print(invert)
for r, c in a:
if A[r][c] != x:
print('{} {}'.format(r + 1, c + 1))
for r, c in b:
if A[r][c] != y:
print('{} {}'.format(r + 1, c + 1))
return
T = int(input())
for _ in range(T):
N = int(input())
A = []
for _ in range(N):
row = [int(x) if x not in {'S', 'F'} else 0 for x in input()]
A.append(row)
solve(A, N)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000005;
const long long mod = 1e18;
const long long N = 1e5 + 5;
long long T = 0;
const string alphabet = {"abcdefghijklmnopqrstuvwxyz"};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void solve() {
long long n = 0, i, a, b;
cin >> n;
string s[n];
for (i = 0; i < n; i++) cin >> s[i];
long long cnt = 0;
vector<pair<long long, long long> > ans;
if (s[0][1] == s[1][0]) {
if (s[0][1] == '0') {
if (s[n - 1][n - 2] == '0') {
cnt++;
ans.push_back({n, n - 1});
}
if (s[n - 2][n - 1] == '0') {
cnt++;
ans.push_back({n - 1, n});
}
} else {
if (s[n - 1][n - 2] == '1') {
cnt++;
ans.push_back({n, n - 1});
}
if (s[n - 2][n - 1] == '1') {
cnt++;
ans.push_back({n - 1, n});
}
}
} else {
long long k = (s[n - 1][n - 2] - '0') + (s[n - 2][n - 1] - '0');
if (k == 0) {
cout << 1 << endl;
cout << (s[0][1] == '1' ? "2 1" : "1 2") << endl;
} else if (k == 1) {
cout << 2 << endl;
if (s[n - 1][n - 2] == '0')
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
cout << (s[0][1] == '0' ? "2 1" : "1 2") << endl;
} else {
cout << 1 << endl;
cout << (s[0][1] == '0' ? "2 1" : "1 2") << endl;
}
return;
}
cout << cnt << endl;
for (auto z : ans) cout << z.first << " " << z.second << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
cin >> t;
while (t--) solve();
return 0;
}
| 8 |
CPP
|
# Legends Always Come Up with Solution
# Author: Manvir Singh
import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict,deque,Counter
from bisect import *
from math import sqrt,pi,ceil
import math
from itertools import permutations
from copy import deepcopy
def main():
for t in range(int(input())):
n = int(input())
a = []
for i in range(n):
a.append(list(input().rstrip()))
f = [a[n - 1][-2], a[n - 2][-1]]
s = [a[0][1], a[1][0]]
if f[0] == "0" and f[1] == "0":
if s[0] == "1" and s[1] == "1":
print(0)
elif s[0] == "1" and s[1] == "0":
print(1)
print(2, 1)
elif s[0] == "0" and s[1] == "0":
print(2)
print(1, 2)
print(2, 1)
else:
print(1)
print(1, 2)
elif f[0] == "1" and f[1] == "1":
if s[0] == "1" and s[1] == "1":
print(2)
print(1, 2)
print(2, 1)
elif s[0] == "1" and s[1] == "0":
print(1)
print(1, 2)
elif s[0] == "0" and s[1] == "1":
print(1)
print(2, 1)
else:
print(0)
elif f[0] == "1" and f[1] == "0":
if s[0] == "1" and s[1] == "1":
print(1)
print(n, n - 1)
elif s[0] == "1" and s[1] == "0":
print(2)
print(2, 1)
print(n, n - 1)
elif s[0] == "0" and s[1] == "1":
print(2)
print(2, 1)
print(n - 1, n)
else:
print(1)
print(n - 1, n)
else:
if s[0] == "1" and s[1] == "1":
print(1)
print(n - 1, n)
elif s[0] == "1" and s[1] == "0":
print(2)
print(2, 1)
print(n - 1, n)
elif s[0] == "0" and s[1] == "1":
print(2)
print(2, 1)
print(n, n - 1)
else:
print(1)
print(n, n - 1)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
| 8 |
PYTHON3
|
t = int(input())
for ti in range(t):
n = int(input())
for i in range(n):
s= input()
if i==0:
k1=int(s[1])
if i==1:
k2=int(s[0])
if i==n-2:
k3=int(s[-1])
if i==n-1:
k4=int(s[-2])
#print(k1,k2,k3,k4)
if k1==k2:
if k3==k4==k1:
print(2)
print(1, 2)
print(2, 1)
elif k3==k4==1-k1:
print(0)
elif k3==k1:
print(1)
print(n-1,n)
else:
print(1)
print(n,n-1)
elif k3==k4:
if k1==k3==1-k2:
print(1)
print(1, 2)
elif k2==k3==1-k1:
print(1)
print(2, 1)
elif k2==k3:
print(2)
print(1,2)
print(n-1,n)
else:
print(2)
print(2,1)
print(n-1,n)
| 8 |
PYTHON3
|
t=int(input())
for i in range(t):
n=int(input())
b=[]
for j in range(n):
s=input()
b.append(s)
p,q=int(b[0][1]),int(b[1][0])
r,s=int(b[-1][-2]),int(b[-2][-1])
ans=[]
if p==q:
if r==p:
ans.append([n,n-1])
if s==p:
ans.append([n-1,n])
elif r==s:
if p==r:
ans.append([1,2])
if q==r:
ans.append([2,1])
else:
ans.append([2,1])
if r == p:
ans.append([n, n - 1])
if s == p:
ans.append([n - 1, n])
print(len(ans))
for j in ans:
print(*j)
| 8 |
PYTHON3
|
I=input
exec(int(I())*"n=int(I());a=[[*map(ord,I())]for _ in[0]*n];a=a[0][1],a[1][0],a[-2][-1]^1,a[-1][-2]^1;r=[y for x,y in zip(a,('1 2','2 1',f'{n-1} {n}',f'{n} {n-1}'))if(sum(a)>194)^x&1];print(len(r),*r);")
| 8 |
PYTHON3
|
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
def gift():
for _ in range(t):
n = int(input())
grid=[]
for i in range(n):
tem = input()
grid.append(tem)
f1 = grid[0][1]
f2 = grid[1][0]
l1 = grid[n-1][n-2]
l2 = grid[n-2][n-1]
if f1 == f2:
if l1==l2:
if f1==l1:
yield 2
yield "1 2"
yield "2 1"
else:
yield 0
else:
if f1==l1:
yield 1
yield "{} {}".format(n,n-1)
else:
yield 1
yield "{} {}".format(n-1,n)
else:
if l1==l2:
if f1==l1:
yield 1
yield "1 2"
else:
yield 1
yield "2 1"
else:
if f1==l1:
yield 2
yield "1 2"
yield "{} {}".format(n-1,n)
else:
yield 2
yield "1 2"
yield "{} {}".format(n,n-1)
if __name__ == '__main__':
t= int(input())
ans = gift()
print(*ans,sep='\n')
#"{} {} {}".format(maxele,minele,minele)
# 0 1 1 0
# 1 0 1 1
| 8 |
PYTHON3
|
for _ in range(int(input())):
n = int(input())
ans = []
mat = [input() for k in range(n)]
if(mat[0][1] == '0' and mat[1][0] == '0'):
if(mat[-1][-2] == '0'): ans.append([n, n-1])
if(mat[-2][-1] == '0'): ans.append([n-1, n])
elif (mat[0][1] == '1' and mat[1][0] == '1'):
if(mat[-1][-2] == '1'): ans.append([n, n-1])
if(mat[-2][-1] == '1'): ans.append([n-1, n])
else:
if(mat[-1][-2] == '1' and mat[-2][-1] == '1'):
if(mat[0][1] == '1'): ans.append([1, 2])
if(mat[1][0] == '1'): ans.append([2, 1])
elif(mat[-1][-2] == '0' and mat[-2][-1] == '0'):
if(mat[0][1] == '0'): ans.append([1, 2])
if(mat[1][0] == '0'): ans.append([2, 1])
else:
if(mat[-1][-2] == '0'): ans.append([n, n-1])
if(mat[-2][-1] == '0'): ans.append([n-1, n])
if(mat[0][1] == '1'): ans.append([1, 2])
if(mat[1][0] == '1'): ans.append([2, 1])
print(len(ans))
for e in ans:
print(e[0], e[1])
| 8 |
PYTHON3
|
t = int(input())
for i in range(t):
n = int(input())
A = []
for i in range(n):
b = list(map(str,input().split()))
b=b[0]
B=[]
for i in range(n):
B+=b[i]
A += [B]
a = A[0][1]
b = A[1][0]
c = A[-2][-1]
d = A[-1][-2]
change = []
count = 0
if a == b:
if a==c:
change.append([n-1,n])
count+=1
if a==d:
change.append([n,n-1])
count+=1
elif c == d:
if a==c:
change.append([1,2])
count+=1
if b==c:
change.append([2,1])
count+=1
else :
change.append([2,1])
count+=1
if a == c:
change.append([n-1,n])
count+=1
else :
change.append([n,n-1])
count+=1
print(count)
for i in change:
print(" ".join(map(str,i)))
| 8 |
PYTHON3
|
t=int(input())
for i in range(t):
n=int(input())
x=[]
for j in range(n):
w=input()
x.append(w)
if(x[0][1]==x[1][0]):
if(x[-1][-2]==x[-2][-1]):
if(x[0][1]==x[-1][-2]):
print(2)
print(1,2)
print(2,1)
else:
print(0)
else:
if(x[0][1]==x[-1][-2]):
print(1)
print(n,n-1)
else:
print(1)
print(n-1,n)
else:
if(x[-1][-2]==x[-2][-1]):
if(x[0][1]==x[-1][-2]):
print(1)
print(1,2)
else:
print(1)
print(2,1)
else:
if(x[0][1]==x[-1][-2]):
print(2)
print(2,1)
print(n,n-1)
else:
print(2)
print(2,1)
print(n-1,n)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int main() {
fast();
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
char arr[n][n];
long long i, j;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
cin >> arr[i][j];
}
}
long long ud = arr[1][0] - '0';
long long ur = arr[0][1] - '0';
long long dl = arr[n - 1][n - 2] - '0';
long long du = arr[n - 2][n - 1] - '0';
long long ans;
if (ud == ur && dl == du && ud != dl) {
cout << 0 << endl;
} else if (ud == ur && ur == dl && dl == du) {
cout << 2 << endl;
cout << "1 2" << endl;
cout << "2 1" << endl;
} else if (ud != ur && dl != du) {
cout << 2 << endl;
if (ud == 1) {
cout << "2 1" << endl;
} else if (ur == 1) {
cout << "1 2" << endl;
}
if (dl == 0) {
cout << n << " " << n - 1 << endl;
} else if (du == 0) {
cout << n - 1 << " " << n << endl;
}
} else if (ud == ur && ur == dl && dl != du) {
cout << 1 << endl;
cout << n << " " << n - 1 << endl;
} else if (ud == ur && ur == du && dl != du) {
cout << 1 << endl;
cout << n - 1 << " " << n << endl;
} else if (dl == du && du == ur && ur != ud) {
cout << 1 << endl;
cout << "1 2" << endl;
} else if (dl == du && du == ud && ud != ur) {
cout << 1 << endl;
cout << "2 1" << endl;
}
}
return 0;
}
| 8 |
CPP
|
for _ in range(int(input())):
n = int(input())
g = []
for _ in range(n):
g.append([(num) for num in input()])
a = g[0][1]
b = g[1][0]
p = 0
c = g[n-1][n-2]
d = g[n-2][n-1]
ans = []
if a==b:
if c==d:
if c==a:
p = p + 2
ans.append([n-1,n])
ans.append([n,n-1])
else:
p = 0
elif c!=d:
if c==a:
p = p + 1
ans.append([n,n-1])
elif a==d:
p = p + 1
ans.append([n-1,n])
if a!=b:
if c==d:
if c==a:
p = p + 1
ans.append([1,2])
elif c==b:
p = p + 1
ans.append([2,1])
elif c!=d:
if c==a:
p = p + 2
ans.append([1,2])
ans.append([n-1,n])
if c==b:
p = p + 2
ans.append([2,1])
ans.append([n-1,n])
print(p)
for i in range(p):
print(ans[i][0],ans[i][1])
| 8 |
PYTHON3
|
t=int(input())
for _ in range(t):
n=int(input())
l1=[]
for i in range(n):
s=input()
l1.append(s)
if l1[0][1]==l1[1][0] and l1[n-2][n-1]==l1[n-1][n-2] and l1[0][1]!=l1[n-2][n-1]:
print(0)
elif l1[0][1]==l1[1][0] and l1[n-2][n-1]==l1[n-1][n-2] and l1[0][1]==l1[n-2][n-1]:
print(2)
print(1,2)
print(2,1)
elif l1[0][1]==l1[1][0] and l1[n-2][n-1]!=l1[n-1][n-2]:
if l1[n-2][n-1]==l1[0][1]:
print(1)
print(n-1,n)
else:
print(1)
print(n,n-1)
elif l1[0][1]!=l1[1][0] and l1[n-2][n-1]==l1[n-1][n-2]:
if l1[0][1]==l1[n-1][n-2]:
print(1)
print(1,2)
else:
print(1)
print(2,1)
else:
if l1[0][1]!=l1[n-1][n-2]:
print(2)
print(1,2)
print(n,n-1)
else:
print(2)
print(1,2)
print(n-1,n)
| 8 |
PYTHON3
|
ts = int(input())
#def pr(a):
# print(str(a[0]) + " " + str(a[1]) )
for t in range(ts):
n = int(input())
l1 = []
#l2 = []
if n==3:
for j in range(n):
l1.append(input())
#s1,s2,f1,f2 = [int(l[0][1]),int(l[1][0]),int(l[n-1][n-2]),int(l[n-2][n-1])]
la = [int(l1[0][1]),int(l1[1][0]),int(l1[n-1][n-2]),int(l1[n-2][n-1])]
else:
l1.append(input())
l1.append(input())
for j in range(n-4):
axw = input()
l1.append(input())
l1.append(input())
la = [int(l1[0][1]),int(l1[1][0]),int(l1[-1][-2]),int(l1[-2][-1])]
#l = [(1,2),(2,1),(n,n-1),(n-1,n)]
l = ["1 2", "2 1", str(n)+ " "+str(n-1), str(n-1)+" "+str(n)]
if sum(la) in [0,4]:
print(2)
print(l[0])
print(l[1])
elif sum(la)==1:
print(1)
if sum(la[:2])==1:
if la[0]==0:
print(l[0])
else:
print(l[1])
else:
if la[2]==0:
print(l[2])
else:
print(l[3])
elif sum(la)==3:
print(1)
if sum(la[:2])==1:
if la[0]==1:
print(l[0])
else:
print(l[1])
else:
if la[2]==1:
print(l[2])
else:
print(l[3])
elif sum(la)==2:
if sum(la[:2]) in [0,2]:
print(0)
else:
print(2)
if la[0]==1:
print(l[0])
else:
print(l[1])
if la[3]==0:
print(l[3])
else:
print(l[2])
| 8 |
PYTHON3
|
for _ in range(int(input())):
n=int(input())
mat=[]
for i in range(n):
temp=input()
temp=list(temp)
mat.append(temp)
a=int(mat[0][1])
b=int(mat[1][0])
x=int(mat[n-1][n-2])
y=int(mat[n-2][n-1])
if (a==b==0 and x==y==1) or (a==b==1 and x==y==0):
print(0)
elif (a==b==0 and x==0 and y==1):
print(1)
print(n,n-1)
elif (a==b==0 and x==1 and y==0):
print(1)
print(n-1,n)
elif (a==b==0 and x==0 and y==0):
print(2)
print(n,n-1)
print(n-1,n)
elif (a==1 and b==0 and x==0 and y==0):
print(1)
print(2,1)
elif (a==1 and b==0 and x==1 and y==0):
print(2)
print(2,1)
print(n,n-1)
elif (a==1 and b==0 and x==0 and y==1):
print(2)
print(2,1)
print(n-1,n)
elif (a==1 and b==0 and x==1 and y==1):
print(1)
print(1,2)
elif (a==0 and b==1 and x==0 and y==0):
print(1)
print(1,2)
elif (a==0 and b==1 and x==1 and y==0):
print(2)
print(2,1) #b
print(n-1,n) #y
elif (a==0 and b==1 and x==0 and y==1):
print(2)
print(2,1)
print(n,n-1)
elif (a==0 and b==1 and x==1 and y==1):
print(1)
print(2,1)
elif (a==1 and b==1 and x==1 and y==0):
print(1)
print(n,n-1)
elif (a==1 and b==1 and x==0 and y==1):
print(1)
print(n-1,n)
elif (a==1 and b==1 and x==1 and y==1):
print(2)
print(1,2)
print(2,1)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
inline void sol() {
long long n;
cin >> n;
vector<vector<char>> grid(n, vector<char>(n));
for (auto &i : grid)
for (auto &j : i) cin >> j;
long long s1 = grid[0][1] + grid[1][0] - 2 * '0';
long long s2 = grid[n - 1][n - 2] + grid[n - 2][n - 1] - 2 * '0';
if (s1 == s2 and (s1 == 2 or s1 == 0)) {
cout << 2 << endl;
cout << "1 2\n2 1\n";
return;
}
if ((s1 == 2 and s2 == 0) or (s1 == 0 and s2 == 2)) {
cout << 0 << endl;
return;
}
if ((s1 == 0 or s2 == 0) and (s1 == 1 or s2 == 1)) {
cout << 1 << endl;
if (s1 == 0) {
if (grid[n - 1][n - 2] == '0')
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
} else {
if (grid[0][1] == '0')
cout << "1 2\n";
else
cout << "2 1\n";
}
return;
}
if ((s1 == 2 or s2 == 2) and (s1 == 1 or s2 == 1)) {
cout << 1 << endl;
if (s1 == 2) {
if (grid[n - 1][n - 2] == '1')
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
} else {
if (grid[0][1] == '1')
cout << "1 2\n";
else
cout << "2 1\n";
}
return;
}
cout << 2 << endl;
if (grid[0][1] == '1')
cout << "1 2\n";
else
cout << "2 1\n";
if (grid[n - 1][n - 2] == '0')
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long t;
cin >> t;
while (t--) sol();
return 0;
}
| 8 |
CPP
|
def find_invert_positions(m):
n = len(m)
a = m[0][1]
b = m[1][0]
c = m[n - 1][n - 2]
d = m[n - 2][n - 1]
coords = []
if a == b:
if c == a:
coords.append([n, n - 1])
if d == a:
coords.append([n - 1, n])
elif c == d:
if a == c:
coords.append([1, 2])
if b == c:
coords.append([2, 1])
else:
coords.append([2, 1])
if c == a:
coords.append([n, n - 1])
if d == a:
coords.append([n - 1, n])
assert len(coords) <= 2
print(len(coords))
for y, x in coords:
print("{} {}".format(y, x))
if __name__ == '__main__':
n_t = int(input())
for t in range(n_t):
n = int(input())
m = []
for r in range(n):
row = input()
assert len(row) == n
m.append(row)
#print(m)
find_invert_positions(m)
| 8 |
PYTHON3
|
import sys
sys.setrecursionlimit(10**5)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def MI(): return map(int, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
for _ in range(II()):
n = II()
ss = [SI() for _ in range(n)]
ans = []
if ss[0][1] == ss[1][0]:
c = ss[0][1]
if ss[-1][-2] == c: ans.append((n, n-1))
if ss[-2][-1] == c: ans.append((n-1, n))
elif ss[-1][-2] == ss[-2][-1]:
c = ss[-1][-2]
if ss[0][1] == c: ans.append((1, 2))
if ss[1][0] == c: ans.append((2, 1))
else:
if ss[-1][-2] == "1": ans.append((n, n-1))
if ss[-2][-1] == "1": ans.append((n-1, n))
if ss[0][1] == "0": ans.append((1, 2))
if ss[1][0] == "0": ans.append((2, 1))
print(len(ans))
for i, j in ans: print(i, j)
| 8 |
PYTHON3
|
t = int(input())
for j in range(t):
n = int(input())
a = ['0'] * n
for i in range(n):
a[i] = str(input())
a[i] = list(a[i])
if a[0][1] == a[1][0]:
if a[n - 1][n - 2] == a[n - 2][n - 1]:
if a[0][1] == a[n - 1][n - 2]:
print(2)
if a[0][1] == '0':
print(0+1,1+1)
print(1+1,0+1)
else:
print(0+1,1+1)
print(1+1,0+1)
else:
print(0)
else:
print(1)
if a[0][1] =='0':
if a[n - 1][n - 2] == '0':
print(n - 1+1,n - 2+1)
else:
print(n - 2+1, n - 1+1)
else:
if a[n - 1][n - 2] == '1':
print(n - 1+1,n - 2+1)
else:
print(n - 2+1, n - 1+1)
else:
if a[n - 1][n - 2] == a[n - 2][n - 1]:
if a[n - 1][n - 2] == '0':
print(1)
if a[0][1] == '0':
print(0+1,1+1)
else:
print(1+1, 0+1)
else:
print(1)
if a[0][1] == '1':
print(0+1,1+1)
else:
print(1+1,0+1)
else:
print(2)
if a[0][1] != a[n - 1][n - 2]:
print(0+1,1+1)
print(n - 1+1,n - 2+1)
else:
print(0+1,1+1)
print(n - 2+1,n - 1+1)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<string> graph(n);
for (auto &i : graph) cin >> i;
int a = graph[0][1], b = graph[1][0], c = graph[n - 2][n - 1],
d = graph[n - 1][n - 2];
if (a == b and b == c and c == d)
cout << "2\n1 2\n2 1\n";
else if (a == b and c == d)
cout << "0\n";
else if (a != b and c == d) {
if (a == c)
cout << "1\n1 2\n";
else
cout << "1\n2 1\n";
} else if (a == b and c != d) {
if (a == c)
cout << "1\n" << n - 1 << " " << n << endl;
else
cout << "1\n" << n << " " << n - 1 << endl;
} else {
if (a == c)
cout << "2\n1 2\n" << n << " " << n - 1 << endl;
else
cout << "2\n1 2\n" << n - 1 << " " << n << endl;
}
}
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<vector<char> > mat;
for (int i = 0; i < n; i++) {
vector<char> v(n);
for (int j = 0; j < n; j++) cin >> v[j];
mat.push_back(v);
}
bool c1 = (mat[0][2] == mat[2][0] and mat[2][0] == mat[1][1]);
bool c2 = mat[0][1] == mat[1][0];
if (c2) {
if (c1) {
if (mat[0][1] == mat[1][1])
cout << 2 << "\n" << 1 << " " << 2 << "\n" << 2 << " " << 1 << "\n";
else
cout << 0 << "\n";
} else {
cout << ((mat[2][0] == mat[1][0]) + (mat[1][1] == mat[1][0]) +
(mat[0][2] == mat[1][0]))
<< "\n";
if (mat[0][2] == mat[1][0]) cout << 1 << " " << 3 << "\n";
if (mat[1][1] == mat[1][0]) cout << 2 << " " << 2 << "\n";
if (mat[2][0] == mat[1][0]) cout << 3 << " " << 1 << "\n";
}
} else {
if (c1) {
cout << 1 << "\n";
(mat[1][0] == mat[1][1]) ? (cout << 2 << " " << 1 << "\n")
: (cout << 1 << " " << 2 << "\n");
} else {
cout << 2 << "\n";
(mat[2][0] == mat[1][1])
? (cout << 1 << " " << 3 << "\n")
: ((mat[0][2] == mat[2][0]) ? (cout << 2 << " " << 2 << "\n")
: (cout << 3 << " " << 1 << "\n"));
(mat[2][0] == mat[1][1])
? (mat[0][2] = mat[2][0])
: ((mat[0][2] == mat[2][0]) ? (mat[1][1] = mat[2][0])
: (mat[2][0] = mat[1][1]));
(mat[1][0] == mat[1][1]) ? (cout << 2 << " " << 1 << "\n")
: (cout << 1 << " " << 2 << "\n");
}
}
}
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
const int INF = 1 << 29;
const double PI = acos(-1.0);
using namespace std;
void solve() {
int n;
cin >> n;
vector<string> v(n);
vector<pair<int, int>> ans;
for (string &it : v) cin >> it;
char a = v[0][1], b = v[1][0], c = v[n - 1][n - 2], d = v[n - 2][n - 1];
if (a == '1' && b == '1') {
if (c != '0') ans.push_back(make_pair(n, n - 1));
if (d != '0') ans.push_back(make_pair(n - 1, n));
} else if (a == '0' && b == '0') {
if (c != '1') ans.push_back(make_pair(n, n - 1));
if (d != '1') ans.push_back(make_pair(n - 1, n));
} else if (c == d) {
if (c == '0') {
if (a == '0')
ans.push_back(make_pair(1, 2));
else if (b == '0')
ans.push_back(make_pair(2, 1));
} else {
if (a == '1')
ans.push_back(make_pair(1, 2));
else if (b == '1')
ans.push_back(make_pair(2, 1));
}
} else {
if (a == '0')
ans.push_back(make_pair(1, 2));
else if (b == '0')
ans.push_back(make_pair(2, 1));
if (c == '1')
ans.push_back(make_pair(n, n - 1));
else if (d == '1')
ans.push_back(make_pair(n - 1, n));
}
cout << ans.size() << endl;
for (auto it : ans) cout << it.first << ' ' << it.second << endl;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
;
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| 8 |
CPP
|
def main():
t = int(input())
for _ in range(t):
n = int(input())
grid = []
for __ in range(n):
grid.append(input())
a, b, c, d = grid[0][1], grid[1][0], grid[-1][-2], grid[-2][-1]
total = 0; flips = []
if a == b:
if a == c:
total += 1
flips.append([n, n - 1])
if a == d:
total += 1
flips.append([n - 1, n])
elif c == d:
if c == a:
total += 1
flips.append([1, 2])
if c == b:
total += 1
flips.append([2, 1])
else:
total = 2
if a == "0":
flips.append([1, 2])
else:
flips.append([2, 1])
if c == "1":
flips.append([n, n - 1])
else:
flips.append([n - 1, n])
print(total)
for flip in flips:
print(*flip)
main()
| 8 |
PYTHON3
|
from collections import Counter
import string
import math
import sys
def array_int():
return [int(i) for i in sys.stdin.readline().split()]
def vary(arrber_of_variables):
if arrber_of_variables==1:
return int(sys.stdin.readline())
if arrber_of_variables>=2:
return map(int,sys.stdin.readline().split())
def makedict(var):
return dict(Counter(var))
# i am noob wanted to be better and trying hard for that
def printDivisors(n):
divisors=[]
# Note that this loop runs till square root
i = 1
while i <= math.sqrt(n):
if (n % i == 0) :
# If divisors are equal, print only one
if (n//i == i) :
divisors.append(i)
else :
# Otherwise print both
divisors.extend((i,n//i))
i = i + 1
return divisors
def countTotalBits(num):
# convert number into it's binary and
# remove first two characters 0b.
binary = bin(num)[2:]
return(len(binary))
for _ in range(vary(1)):
n=vary(1)
arr=[]
for i in range(n):
arr.append([str(i) for i in input()])
if arr[0][1]==arr[1][0]:
count=0
tt=[]
if arr[n-2][n-1]==arr[0][1]:
count+=1
tt.append([n-1,n])
if arr[n-1][n-2]==arr[0][1]:
count+=1
tt.append([n,n-1])
print(count)
for i in tt:
print(*i)
else:
if arr[n-2][n-1]==arr[n-1][n-2]:
if arr[0][1]==arr[n-2][n-1]:
print(1)
print(1,2)
else:
print(1)
print(2,1)
else:
print(2)
print(n-1,n)
if arr[n-2][n-1]!=arr[0][1]:
print(1,2)
else:
print(2,1)
| 8 |
PYTHON3
|
import sys
input = sys.stdin.readline
T = int(input())
for case in range(T):
n = int(input())
M = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
s = input()
s = s[:len(s) - 1:]
M[i] = s
if M[1][0] != M[0][1] and M[n - 1][n - 2] != M[n - 2][n - 1]:
if M[1][0] != M[n - 2][n - 1]:
print(2)
print(2, 1)
print(n - 1, n)
else:
print(2)
print(2, 1)
print(n, n - 1)
elif M[1][0] == M[0][1] and M[n - 1][n - 2] == M[n - 2][n - 1]:
if M[1][0] == M[n - 1][n - 2]:
print(2)
print(n, n - 1)
print(n - 1, n)
else:
print(0)
elif M[1][0] == M[0][1] and M[n - 1][n - 2] != M[n - 2][n - 1]:
if M[1][0] == M[n - 1][n - 2]:
print(1)
print(n, n - 1)
else:
print(1)
print(n - 1, n)
elif M[1][0] != M[0][1] and M[n - 1][n - 2] == M[n - 2][n - 1]:
if M[1][0] == M[n - 1][n - 2]:
print(1)
print(2, 1)
else:
print(1)
print(1, 2)
| 8 |
PYTHON3
|
import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
from collections import *
ORDA = 97 # a
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return [int(i) for i in input().split()]
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p * p <= n:
if prime[p]:
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 2
r = [2]
for p in range(3, n + 1, 2):
if prime[p]:
r.append(p)
return r
def divs(n, start=2):
r = []
for i in range(start, int(math.sqrt(n) + 1)):
if (n % i == 0):
if (n / i == i):
r.append(i)
else:
r.extend([i, n // i])
return r
def divn(n, primes):
divs_number = 1
for i in primes:
if n == 1:
return divs_number
t = 1
while n % i == 0:
t += 1
n //= i
divs_number *= t
def prime(n):
if n == 2: return True
if n % 2 == 0 or n <= 1: return False
sqr = int(math.sqrt(n)) + 1
for d in range(3, sqr, 2):
if n % d == 0: return False
return True
def convn(number, base):
new_number = 0
while number > 0:
new_number += number % base
number //= base
return new_number
def cdiv(n, k): return n // k + (n % k != 0)
def ispal(s): # Palindrome
for i in range(len(s) // 2 + 1):
if s[i] != s[-i - 1]:
return False
return True
# a = [1,2,3,4,5] -----> print(*a) ----> list print krne ka new way
def main():
for _ in range(int(input())):
n = int(input())
arr = [list(input()) for _ in range(n)]
res = []
if arr[n-2][n-1] == arr[n-1][n-2]:
if arr[0][1] == arr[n-2][n-1]:
res.append((1, 2))
if arr[1][0] == arr[n-2][n-1]:
res.append((2, 1))
elif arr[0][1] == arr[1][0]:
if arr[n-2][n-1] == arr[0][1]:
res.append((n-1, n))
if arr[n-1][n-2] == arr[0][1]:
res.append((n, n-1))
else:
if arr[0][1] == "1":
res.append((1, 2))
if arr[1][0] == "1":
res.append((2, 1))
if arr[n-2][n-1] == "0":
res.append((n-1, n))
if arr[n-1][n-2] == "0":
res.append((n, n-1))
print(len(res))
for e in res:
print(*e)
main()
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
const int N = 210;
char a[N][N];
int n;
void pp(void) {
if (a[1][2] == '1')
cout << 1 << endl << ' ' << 1 << ' ' << 2 << endl;
else
cout << 1 << endl << ' ' << 2 << ' ' << 1 << endl;
}
void pp1(void) {
if (a[n - 1][n] == '0')
cout << 1 << endl << ' ' << n - 1 << ' ' << n << endl;
else
cout << 1 << endl << ' ' << n << ' ' << n - 1 << endl;
}
void pp2(void) {
if (a[1][2] == '0')
cout << 1 << endl << ' ' << 1 << ' ' << 2 << endl;
else
cout << 1 << endl << ' ' << 2 << ' ' << 1 << endl;
}
void pp3(void) {
if (a[n - 1][n] == '1')
cout << 1 << endl << ' ' << n - 1 << ' ' << n << endl;
else
cout << 1 << endl << ' ' << n << ' ' << n - 1 << endl;
}
void pp4(void) {
if (a[1][2] == '0') {
cout << 2 << endl << ' ' << 1 << ' ' << 2 << endl;
if (a[n - 1][n] == '1')
cout << n - 1 << ' ' << n << endl;
else
cout << n << ' ' << n - 1 << endl;
} else {
cout << 2 << endl << ' ' << 2 << ' ' << 1 << endl;
if (a[n - 1][n] == '1')
cout << n - 1 << ' ' << n << endl;
else
cout << n << ' ' << n - 1 << endl;
}
}
int main(void) {
int t;
cin >> t;
while (t--) {
cin >> n;
int s1 = 0, s0 = 0, f1 = 0, f0 = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) cin >> a[i][j];
if (a[2][1] == '0')
s0++;
else
s1++;
if (a[1][2] == '1')
s1++;
else
s0++;
if (a[n][n - 1] == '0')
f0++;
else
f1++;
if (a[n - 1][n] == '1')
f1++;
else
f0++;
if ((f1 == 2 && s1 == 2) || (s1 == 0 && f1 == 0))
cout << 2 << endl << 1 << ' ' << 2 << endl << 2 << ' ' << 1 << endl;
else if (s1 == 1 && f1 == 2)
pp();
else if (s1 == 0 && f1 == 1)
pp1();
else if (s1 == 0 && f1 == 2)
cout << 0 << endl;
else if (s1 == 2 && f1 == 0)
cout << 0 << endl;
else if (s1 == 1 && f1 == 0)
pp2();
else if (s1 == 2 && f1 == 1)
pp3();
else if (s1 == 1 && f1 == 1) {
pp4();
}
}
}
| 8 |
CPP
|
import sys
#input=sys.stdin.readline
T=int(input())
for _ in range(T):
n=int(input())
A=[]
for i in range(n):
A.append(input())
a1,b1=int(A[0][1]),int(A[1][0])
a2,b2=int(A[n-1][n-2]),int(A[n-2][n-1])
if(a1==b1):
c=0
ans=[]
if (a2==a1):
c=c+1
ans.append([n,n-1])
if (b2==a1):
c=c+1
ans.append([n-1,n])
print(c)
for i in ans:
print(*i)
elif(a2==b2):
c=0
ans=[]
if (a2==a1):
c=c+1
ans.append([1,2])
if (b2==b1):
c=c+1
ans.append([2,1])
print(c)
for i in ans:
print(*i)
else:
#print(a1,b1,a2,b2)
c=0
ans=[]
if (a1==1):
c=c+1
ans.append([1,2])
if (b1==1):
c=c+1
ans.append([2,1])
if (a2==0):
c=c+1
ans.append([n,n-1])
if (b2==0):
c=c+1
ans.append([n-1,n])
print(c)
for i in ans:
print(*i)
| 8 |
PYTHON3
|
t = int(input())
while t > 0:
t -= 1
dim = int(input())
a1 = None
a2 = None
a3 = None
a4 = None
if dim >= 4:
a1 = int(input()[1])
a2 = int(input()[0])
for i in range(dim - 4):
inp = input()
a3 = int(input()[dim - 1])
a4 = int(input()[dim - 2])
elif dim == 3:
a1 = int(input()[1])
midInp = input()
a2 = int(midInp[0])
a3 = int(midInp[2])
a4 = int(input()[1])
L = []
if a1 == a2:
changeTo = 1 - a1
if a3 != changeTo:
L.append(3)
if a4 != changeTo:
L.append(4)
else:
if a3 == a4:
changeTo = 1 - a3
if a1 != changeTo:
L.append(1)
else :
L.append(2)
else:
L.append(1)
if a3 != a1:
L.append(3)
else:
L.append(4)
print(len(L))
for i in L:
if i == 1:
print("1 2")
if i == 2:
print("2 1")
if i == 3:
print(str(dim - 1) + " " +str(dim))
if i == 4:
print(str(dim) + " " + str(dim-1))
| 8 |
PYTHON3
|
for _ in range(int(input())):
nn=input()
if nn=='':
n=int(input())
else:
n=int(nn)
l=[]
for _ in range(n):
aa=input()
if aa=='':
a=list(input())
else:
a=list(aa)
l.append(a)
s1=l[0][1]
s2=l[1][0]
f1=l[n-2][n-1]
f2=l[n-1][n-2]
if s1=='0' and s2=='0':
if f1=='0' and f2=='0':
print(2)
print(1,2)
print(2,1)
elif f1=='0' and f2=='1':
print(1)
print(n-1,n)
elif f1=='1' and f2=='0':
print(1)
print(n,n-1)
elif f1=='1' and f2=='1':
print(0)
elif s1=='0' and s2=='1':
if f1=='0' and f2=='0':
print(1)
print(1,2)
elif f1=='0' and f2=='1':
print(2)
print(1,2)
print(n,n-1)
elif f1=='1' and f2=='0':
print(2)
print(1,2)
print(n-1,n)
elif f1=='1' and f2=='1':
print(1)
print(2,1)
elif s1=='1' and s2=='0':
if f1=='0' and f2=='0':
print(1)
print(2,1)
elif f1=='0' and f2=='1':
print(2)
print(1,2)
print(n-1,n)
elif f1=='1' and f2=='0':
print(2)
print(1,2)
print(n,n-1)
elif f1=='1' and f2=='1':
print(1)
print(1,2)
elif s1=='1' and s2=='1':
if f1=='0' and f2=='0':
print(0)
elif f1=='0' and f2=='1':
print(1)
print(n,n-1)
elif f1=='1' and f2=='0':
print(1)
print(n-1,n)
elif f1=='1' and f2=='1':
print(2)
print(1,2)
print(2,1)
| 8 |
PYTHON3
|
# # Created by Prabhat kumar jha and 18/10/20
#
# t = int(input())
# for i in range(t):
# a, b = [int(i) for i in input().split(" ")]
# print(a^b)
t = int(input())
for i in range(t):
n = int(input())
l = []
for i in range(n):
l.append(input())
a = int(l[0][1])
b = int(l[1][0])
c = int(l[-1][-2])
d = int(l[-2][-1])
s1 = a+b
s2 = c+d
if {s1, s2} == {0, 2}:
print(0)
elif {s1, s2} == {1}:
print(2)
print("1 2")
if a!=c:
print(str(n)+" "+str(n-1))
else:
print(str(n-1) + " " + str(n))
elif {s1, s2} == {2} or {s1, s2} == {0}:
print(2)
print(str(n) + " " + str(n - 1))
print(str(n-1) + " " + str(n))
else:
print(1)
if s1==1 and s2==2:
if a==0:
print("2 1")
else:
print("1 2")
elif s1==2 and s2==1:
if c==0:
print(str(n-1)+" "+str(n))
else:
print(str(n)+" "+str(n-1))
elif s1==0 and s2==1:
if c==0:
print(str(n) + " " + str(n - 1))
else:
print(str(n - 1) + " " + str(n))
else:
if a==0:
print("1 2")
else:
print("2 1")
| 8 |
PYTHON3
|
from sys import stdout,stdin
from collections import defaultdict,deque
import math
t=int(stdin.readline())
for _ in range(t):
n=int(stdin.readline())
#n,m=map(int,stdin.readline().split())
#l=list(map(int,stdin.readline().split()))
l=[]
for i in range(n):
l.append(list(input()))
if l[0][1]=='0' and l[1][0]=='0':
if l[n-1][n-2]=='1' and l[n-2][n-1]=='1':
print(0)
elif l[n-1][n-2]=='1' and l[n-2][n-1]=='0':
print(1)
print(n-1,n)
elif l[n-1][n-2]=='0' and l[n-2][n-1]=='1':
print(1)
print(n,n-1)
else:
print(2)
print(n,n-1)
print(n-1,n)
elif l[0][1]=='1' and l[1][0]=='1':
if l[n-1][n-2]=='0' and l[n-2][n-1]=='0':
print(0)
elif l[n-1][n-2]=='0' and l[n-2][n-1]=='1':
print(1)
print(n-1,n)
elif l[n-1][n-2]=='1' and l[n-2][n-1]=='0':
print(1)
print(n,n-1)
else:
print(2)
print(n,n-1)
print(n-1,n)
elif l[0][1]=='1' and l[1][0]=='0':
if l[n-1][n-2]=='0' and l[n-2][n-1]=='0':
print(1)
print(2,1)
elif l[n-1][n-2]=='0' and l[n-2][n-1]=='1':
print(2)
print(2,1)
print(n-1,n)
elif l[n-1][n-2]=='1' and l[n-2][n-1]=='0':
print(2)
print(2,1)
print(n,n-1)
else:
print(1)
print(1,2)
elif l[0][1]=='0' and l[1][0]=='1':
if l[n-1][n-2]=='0' and l[n-2][n-1]=='0':
print(1)
print(1,2)
elif l[n-1][n-2]=='0' and l[n-2][n-1]=='1':
print(2)
print(1,2)
print(n-1,n)
elif l[n-1][n-2]=='1' and l[n-2][n-1]=='0':
print(2)
print(2,1)
print(n-1,n)
else:
print(1)
print(2,1)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
const unsigned long long int M = 1000000007;
using namespace std;
long long power(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = x * res;
y = y >> 1;
x = x * x;
}
return res;
}
long long power(long long x, long long y, long long mod) {
long long res = 1;
while (y > 0) {
if (y & 1) res = x * res % mod;
y = y >> 1;
x = x * x % mod;
}
return res;
}
void nik() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
signed main() {
nik();
long long test = 1;
cin >> test;
while (test--) {
long long n;
cin >> n;
string s[n];
for (long long i = 0; i < n; i++) cin >> s[i];
long long a, b, c, d;
a = s[1][0] - '0';
b = s[0][1] - '0';
c = s[n - 1][n - 2] - '0';
d = s[n - 2][n - 1] - '0';
std::vector<pair<long long, long long>> v;
if (a == b) {
if (c == a) v.push_back({n - 1, n - 2});
if (d == a) v.push_back({n - 2, n - 1});
} else if (c == d) {
if (c == a) v.push_back({1, 0});
if (d == b) v.push_back({0, 1});
} else if (a == c) {
v.push_back({1, 0});
v.push_back({n - 2, n - 1});
} else if (a == d) {
v.push_back({0, 1});
v.push_back({n - 2, n - 1});
}
cout << v.size() << "\n";
for (auto it : v) {
cout << it.first + 1 << " " << it.second + 1 << "\n";
}
}
return 0;
}
| 8 |
CPP
|
t = int(input())
for _ in range(t):
n=int(input())
l=[]
kl=[]
for i in range(n):
l.append(input())
kl.append(l[0][1])
kl.append(l[1][0])
kl.append(l[n-2][n-1])
kl.append(l[n-1][n-2])
i=0
for op in kl:
if op=='0':
i+=1
if i==4:
print(2)
print('1 2')
print('2 1')
elif i==3:
print(1)
if kl[0]=='1':
print('2 1')
elif kl[1]=='1':
print('1 2')
elif kl[2]=='1':
print(n, end=' ')
print(n-1)
elif kl[3]=='1':
print(n-1, end=' ')
print(n)
elif i==2:
if not kl[0]==kl[1]:
print(2)
print('1 2')
if kl[0]==kl[2]:
print(n, end=' ')
print(n-1)
else:
print(n-1, end=' ')
print(n)
else:
print(0)
elif i==1:
print(1)
if kl[0]=='0':
print('2 1')
elif kl[1]=='0':
print('1 2')
elif kl[2]=='0':
print(n, end=' ')
print(n-1)
elif kl[3]=='0':
print(n-1, end=' ')
print(n)
elif i==0:
print(2)
print('1 2')
print('2 1')
| 8 |
PYTHON3
|
ans = []
for i in range(int(input())):
n = int(input())
grid = []
for j in range(n):
grid.append(input())
s_right, s_down = int(grid[0][1]), int(grid[1][0])
f_left, f_up = int(grid[n-1][n-2]), int(grid[n-2][n-1])
s_sum = s_right + s_down
f_sum = f_left + f_up
if abs(f_sum - s_sum) == 2:
ans.append('0')
elif abs(f_sum - s_sum) == 1:
ans.append('1')
if f_sum == 2 or s_sum == 2:
if s_sum == 1:
if s_right == 1:
ans.append('1 2')
else:
ans.append('2 1')
elif f_sum == 1:
if f_left == 1:
ans.append(str(n) + ' ' + str(n-1))
else:
ans.append(str(n-1) + ' ' + str(n))
else:
if s_sum == 1:
if s_right == 0:
ans.append('1 2')
else:
ans.append('2 1')
elif f_sum == 1:
if f_left == 0:
ans.append(str(n) + ' ' + str(n-1))
else:
ans.append(str(n-1) + ' ' + str(n))
elif abs(f_sum - s_sum) == 0:
ans.append('2')
if s_sum == 0 or s_sum == 2:
ans.append('1 2')
ans.append('2 1')
else:
if s_right == 1:
ans.append('1 2')
else:
ans.append('2 1')
if f_left == 0:
ans.append(str(n) + ' ' + str(n-1))
else:
ans.append(str(n-1) + ' ' + str(n))
print('\n'.join(ans))
| 8 |
PYTHON3
|
for tt in range(int(input())):
n=int(input())
l=[]
for i in range(n):
l.append(list(input()))
j=[]
cnt=0
if l[0][1]==l[1][0]:
if l[n-1][n-2]==l[1][0]:
cnt+=1
j.append((n,n-1))
if l[n-2][n-1]==l[1][0]:
cnt+=1
j.append((n-1,n))
elif l[n-1][n-2]==l[n-2][n-1]:
if l[0][1]==l[n-1][n-2]:
cnt+=1
j.append((1,2))
if l[n-2][n-1]==l[1][0]:
cnt+=1
j.append((2,1))
else:
if l[0][1]=='1':
cnt+=1
j.append((1,2))
else:
cnt+=1
j.append((2,1))
if l[n-1][n-2]=='0':
cnt+=1
j.append((n,n-1))
else:
cnt+=1
j.append((n-1,n))
print(cnt)
for i in j:
print(i[0],i[1])
| 8 |
PYTHON3
|
'''
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
'''
n=int(input())
for i in range(0,n):
o=int(input())
N=0;
A=0
L=[]
B=0
C=0
D=0
for j in range(0,o):
s=input().rstrip()
x=list(s)
if j==0:
A=int(x[1])
if j==1:
B=int(x[0])
if j==o-2:
C=int(x[len(x)-1])
if j==o-1:
D=int(x[len(x)-2])
# print(A,B,C,D)
if A==B:
ans = 0;
if A==0:
if C!=1:
ans+=1;
L.append(o-1)
L.append(o)
if D!=1:
ans+=1;
L.append(o)
L.append(o-1)
#print(L)
else:
if C!=0:
ans+=1;
L.append(o-1)
L.append(o)
if D!=0:
ans+=1;
L.append(o)
L.append(o-1)
elif C==D:
ans = 0;
if C==0:
if A!=1:
ans+=1;
L.append(1)
L.append(2)
if B!=1:
ans+=1;
L.append(2)
L.append(1)
else:
if A!=0:
ans+=1;
L.append(1)
L.append(2)
if B!=0:
ans+=1;
L.append(2)
L.append(1)
else:
ans = 0;
if A==0:
ans+=1;
L.append(1)
L.append(2)
if C==1:
ans+=1;
L.append(o-1)
L.append(o)
else:
ans+=1;
L.append(o)
L.append(o-1)
else:
ans+=1;
L.append(1)
L.append(2)
if C==0:
ans+=1;
L.append(o-1)
L.append(o)
else:
ans+=1;
L.append(o)
L.append(o-1)
print(ans)
for j in range(0,len(L),2):
print(L[j],L[j+1])
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
const int N = 212;
char s[N];
void print(vector<pair<int, int>> &resp) {
printf("%d\n", (int)resp.size());
for (auto a : resp) {
printf("%d %d\n", a.first, a.second);
}
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int a1, a2, b1, b2;
for (int i = 0; i < n; i++) {
scanf("%s", s);
if (i == 0) a1 = s[1] - '0';
if (i == 1) a2 = s[0] - '0';
if (i == n - 2) b1 = s[n - 1] - '0';
if (i == n - 1) b2 = s[n - 2] - '0';
}
vector<pair<int, int>> resp;
if (a1 == a2) {
int o = 1 - a1;
if (b1 != o) resp.push_back({n - 1, n});
if (b2 != o) resp.push_back({n, n - 1});
} else if (b1 == b2) {
int o = 1 - b1;
if (a1 != o) resp.push_back({1, 2});
if (a2 != o) resp.push_back({2, 1});
} else {
if (a1 != 0) resp.push_back({1, 2});
if (a2 != 0) resp.push_back({2, 1});
if (b1 != 1) resp.push_back({n - 1, n});
if (b2 != 1) resp.push_back({n, n - 1});
}
print(resp);
}
}
| 8 |
CPP
|
t = int(input())
for _ in range(t):
n = int(input())
lst = [list(input()) for _ in range(n)]
ans = []
b1 = int(lst[0][1])
b2 = int(lst[1][0])
b3 = int(lst[n-1][n-2])
b4 = int(lst[n-2][n-1])
if b1==b2==b3==b4:
ans.append((1,2))
ans.append((2,1))
elif b1==b2 and b3 != b4:
if b1 == b3:
ans.append((n,n-1))
else:
ans.append((n-1,n))
elif b3==b4 and b1 != b2:
if b3 == b1:
ans.append((1,2))
else:
ans.append((2,1))
elif b1 == b3 and b2 == b4:
ans.append((1,2))
ans.append((n-1,n))
elif b1 == b4 and b2 == b3:
ans.append((1,2))
ans.append((n,n-1))
if ans:
print(len(ans))
for i in ans:
print(*i)
else:
print(0)
| 8 |
PYTHON3
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.