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)
... | 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 - ... | 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])... | 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 = []
... | 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... | 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]... | 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... | 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) {
... | 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++) {
... | 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... | 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... | 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.appe... | 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().spli... | 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):
... | 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... | 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 ta... | 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... | 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... | 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:
... | 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;
fo... | 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;
... | 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... | 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... | 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... | 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:
... | 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;
... | 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)
pr... | 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 ... | 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++)
fo... | 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')... | 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++;
}
inl... | 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.... | 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 in... | 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')
B... | 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... | 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] == gri... | 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)
eli... | 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.a... | 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
... | 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 w... | 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 i... | 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)
prin... | 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) {
... | 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 _ i... | 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]=='... | 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... | 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 ... | 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:
i... | 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))
... | 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);
... | 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... | 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)
... | 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-... | 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_cel... | 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 ... | 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... | 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])):
... | 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:
... | 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:
... | 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':
pr... | 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 = [(... | 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,... | 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... | 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:
... | 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])
... | 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]
l... | 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[... | 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
... | 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]):
... | 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++) {
... | 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
... | 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]:
... | 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... | 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)
... | 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';
i... | 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:
c... | 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() ... | 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]... | 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]... | 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[... | 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 =... | 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:
... | 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(... | 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][... | 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)... | 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 ... | 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
... | 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... | 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... | 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])
... | 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... | 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... | 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)
... | 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_... | 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)... | 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:
... | 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);
... | 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 !... | 8 | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.