solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; namespace chino { const int maxn = 0x3f3f3f3f; const int inf = 0x7fffffff; } // namespace chino inline int read() { char ch; int f = 1, x = 0; do { ch = getchar(); if (ch == '-') f = -1; } while (!isdigit(ch)); do { x = x * 10 + ch - '0'; ch = get...
8
CPP
for _ in range(int(input())): n=int(input()) string=[] for i in range(n): l=input() string.append(l) c=0 p,q=len(string)-2,len(string[0])-1 r,s=len(string)-1,len(string[0])-2 x=string[0][1]+string[1][0] y=string[p][q]+string[r][s] tempx=x tempy=y if x[0]==x[1]: if x[0]=='0': y='11' else: y='00'...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; 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 + 1][n + 1]; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) cin >> a[i][j]; int a12 = a[1][2] - ...
8
CPP
from sys import stdin,stdout n=int(stdin.readline()) for i in range(n): ans=[] k=int(stdin.readline()) for j in range(k): s=stdin.readline() if j==0: top=s[1] if j==1: left=s[0] if j==k-2: right=s[-2] if j==k-1: down=s[-3...
8
PYTHON3
t=int(input()) for _ in range(t): n=int(input()) for w in range(n): s=input() if w==0: a=s[1] if w==1: b=s[0] if w==n-2: c=s[n-1] if w==n-1: d=s[n-2] e=0 if a==b: if c==a and d==a: print(2) ...
8
PYTHON3
import sys import math import itertools import functools import collections import operator import fileinput import copy import string 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...
8
PYTHON3
""" Author: Sagar Pandey """ # ---------------------------------------------------Import Libraries--------------------------------------------------- import sys import os from math import sqrt, log, log2, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial from copy import copy, deepcopy from sys import exit...
8
PYTHON3
t=int(input()) for _ in range(t): n=int(input()) s=list() for _ in range(n): a=input() s.append(a) u=int(s[n-2][n-1]) d=int(s[1][0]) l=int(s[n-1][n-2]) r=int(s[0][1]) c=0 k=list() if(r+d==0): if(u==0): c+=1 k.append(n-1) ...
8
PYTHON3
t=int(input()) for i in range(0,t): m=int(input()) l=[] for j in range(0,m): str1=input() x=len(str1) l.append(str1) a=l[0][1] b=l[1][0] c=l[-2][-1] d=l[-1][-2] a=int(a) b=int(b) c=int(c) d=int(d) if(a==0 and b==0 and c==0 and d==0): print(...
8
PYTHON3
#from sys import maxsize as inf from collections import Counter as cnt, defaultdict as dic #from decimal import Decimal as de #from statistics import median, mode, mean #from math import pow, log, floor, sqrt, comb, ceil, gcd #from copy import deepcopy as dc #from heapq import heappush, heapify, heappop iin = lambda: ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; void fastio() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void one(); int main() { fastio(); int t = 1; cin >> t; for (int i = 0; i < t; ++i) { one(); } return 0; } void one() { int n; cin >> n; vector<string> s; for (int i = 0; i...
8
CPP
for i in range(int(input())): l=[list(input()) for j in range(int(input()))] n=len(l) if(l[0][1]=='0' and l[1][0]=='0'): if(l[n-2][n-1]=='0' and l[n-1][n-2]=='0'): print(2) print(n,n-1) print(n-1,n) elif l[n-2][n-1]=='0': print(1) print(n-1,n) elif l[n-1][n-2]=='0': print(1) print(n,n-1) ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<vector<int> > v; char a[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } int c = 0; int zeroc = 0; int onec = 0; if (a[0][1] == '0') zeroc++; else onec++...
8
CPP
for _ in range(int(input())): n = int(input()) l = list() for i in range(n): l.append(input()) a, b = l[0][1], l[1][0] x, y = l[n-1][n-2], l[n-2][n-1] if a==b and x==y: if a!=x: print(0) else: print(2) print(1, 2) ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const ui...
8
CPP
import sys,math,itertools from collections import Counter,deque,defaultdict from bisect import bisect_left,bisect_right mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) for _ in range(inp()): n = inp() s = [input() for...
8
PYTHON3
import sys LI=lambda:list(map(int, sys.stdin.readline().strip('\n').split())) MI=lambda:map(int, sys.stdin.readline().strip('\n').split()) SI=lambda:sys.stdin.readline().strip('\n') II=lambda:int(sys.stdin.readline().strip('\n')) for _ in range(II()): n=II() g=[] for i in range(n): g.append(list(SI())) if g[0][1...
8
PYTHON3
t = int(input()) while t: t += -1 n = int(input()) l = [] for i in range(n): tmp = list(input()) l.append(tmp) if l[n - 1][n - 2] == l[n - 2][n - 1]: if l[1][0] == l[0][1]: if l[1][0] == l[n - 1][n - 2]: print(2) print(2, 1) ...
8
PYTHON3
for _ in range(int(input())): n=int(input()) arr=[] for i in range(n): arr.append(input()) a=int(arr[0][1]) b=int(arr[1][0]) c=int(arr[n-1][n-2]) d=int(arr[n-2][n-1]) if a==b and c==d and c!=a: print(0) elif a==b and c!=d: if c==a: print(1) ...
8
PYTHON3
#dt = {} for i in x: dt[i] = dt.get(i,0)+1 import sys;input = sys.stdin.readline #import io,os; input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #for pypy inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()] #dt = {} for i in x: dt[i] = dt.get(i,0)+1 import sys;input = sys.stdin.readline ...
8
PYTHON3
from collections import deque from collections import OrderedDict from queue import PriorityQueue import math import sys import os import threading import bisect import operator import queue import heapq from atexit import register from io import BytesIO #sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size)...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double PI = acos(-1.0); template <typename T> inline T sq(T a) { return a * a; } template <typename T1, typename T2> inline pair<T1, T2> mp(T1 a, T2 b) { return make_pair(a, b); } template <typename T1, typename T2> inline T1 safeMod(T1 a,...
8
CPP
t = int(input()) while t > 0: n = int(input()) grid =[] for i in range(n): a = input() grid.append(a) lol = [grid[0][1],grid[0][2],grid[1][0],grid[2][0], grid[1][1]] ans1 = ['0','1','0','1','1'] ans2 = ['1','0','1','0','0'] count = 0 l = [] for i in range(5): ...
8
PYTHON3
for _ in range(int(input())): n = int(input()) G = [] for a in range(n): G.append(input()) a1 = int(G[0][1]) a2 = int(G[1][0]) b1 = int(G[-2][-1]) b2 = int(G[-1][-2]) # print(a1, a2, b1, b2) if a1 == 0 and a2 == 0: if b1 == 1: if b2 == 1: ...
8
PYTHON3
for _ in range(int(input())): ans = [] n = int(input()) X = [] for i in range(n): X.append(list(input())) s1,s2 = int(X[0][1]), int(X[1][0]) f1,f2 = int(X[n-2][n-1]), int(X[n-1][n-2]) if s1==s2 and f1==f2 and s1!=f1: ans = [] else: if s1==s2: if f...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int read() { int re = 0; char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') { re = re * 10 + c - '0'; c = getchar(); } return re; } int t; string mat[300]; int vis[300][300], chg[300][300]; int main() { cin >> t;...
8
CPP
for _ in range(int(input())): n=int(input()) a=[[-1]*n for z in range(n)] for z in range(n): a[z]=list(input()) ansl=[] if a[0][1]==a[1][0]: v=a[0][1] if a[-1][-2]==v: ansl.append([n,n-1]) if a[-2][-1]==v: ansl.append([n-1,n]) else: ...
8
PYTHON3
for _ in range(int(input())): n = int(input()) nn = [input() for _ in range(n)] a = nn[0][1] b = nn[1][0] c = nn[-2][-1] d = nn[-1][-2] q = {a, b} w = {c, d} ap = 1, 2 bp = 2, 1 cp = n - 1, n dp = n, n - 1 qw = q & w ans = [] if not qw: pass elif l...
8
PYTHON3
from sys import stdin, stdout import math import heapq import collections input = stdin.readline def inputnum(): return(int(input())) def inputnums(): return(map(int,input().split())) def inputlist(): return(list(map(int,input().split()))) def inputstring(): return([x for x in input()]) def inputstrings...
8
PYTHON3
import sys import math def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def MI(): return map(int, sys.stdin.readline().split()) def SI(): return sys.stdin.readline().strip() t = II() for q in range(t): n = II() l = [] for i in range(n): ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; void vin(vector<int>& v) { int i, p; int n = (int)v.size(); for (i = 0; i < n; i++) { scanf("%d", &v[i]); } } void vin(vector<long long>& v) { long long i, p; int n = v.size(); for (i = 0; i < n; i++) { scanf("%lld", &v[i]); } } void vout(const vecto...
8
CPP
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } long long countdigit(long long n) { long long x = n, c = 0; while (x != 0) { x = x / 10; c++; } return c; } void solve() { long long n; cin >> n; strin...
8
CPP
t = int(input()) for i in range(t): n = int(input()) a1 = 0 a2 = 0 a3 = 0 a4 = 0 for j in range(n): test = list(input()) if (j == 0): a1 = test[1] if (j == 1): a2 = test[0] if (j == n-2): a3 = test[-1] if (j == n-1): ...
8
PYTHON3
k = int(input()) for i in range(k): n = int(input()) for j in range(1, n + 1): str = input() if j == 1: point_l1 = str[1] if j == 2: point_l2 = str[0] if j == n - 1: point_r1 = str[len(str) - 1] if j == n: point_r2 = str[len...
8
PYTHON3
from sys import stdin input=stdin.readline def A(): t=int(input()) for _ in range(t): a,b=map(int,input().split()) print(a^b) def B(): from collections import deque t=int(input()) for _ in range(t): n=int(input()) square=[0 for i in range(n)] for i in ra...
8
PYTHON3
#include <bits/stdc++.h> const long long M = 1e7 + 7; const double pi = 3.14159265358979323846; using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; long long a, b, c, d; for (long lo...
8
CPP
#include <bits/stdc++.h> using namespace std; const int M = INT_MAX; const int N = INT_MIN; using namespace std; int main() { int t = 0; cin >> t; while (t--) { int n, c = 0; cin >> n; char d[n + 1][n + 1]; vector<pair<int, int>> vect; for (int i = 1; i <= n; i++) { for (int j = 1; j <= ...
8
CPP
import sys import math import bisect from sys import stdin, stdout from math import gcd, floor, sqrt, log from collections import defaultdict as dd from bisect import bisect_left as bl, bisect_right as br from collections import Counter from collections import defaultdict as dd #sys.setrecursionlimit(100000000) inp =...
8
PYTHON3
import math import sys from collections import OrderedDict ##### graph implementation with adjacancy list##### class Graph: def __init__(self,Nodes,is_directed=False): self.nodes=Nodes self.adj_list={} self.is_directed=is_directed for node in self.nodes: self.adj_list[n...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const int M = (int)2e2; const int N = (int)1e5; const double eps = 1e-9; const int inf = 0x3f3f3f3f; const long long mod = (long long)1e9 + 7; char s[M + 5][M + 5]; void work() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1); char ch[4];...
8
CPP
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase import threading from bisect import bisect_right from math import gcd,log from collections import Counter from pprint import pprint from itertools import combinations def fun(val,grid,n): # print(grid) bfs=[(0,0)] delta=[(1,0),(-1,...
8
PYTHON3
def main(): n = int(input()) x_12 = int(input()[1]) x_2 = input() x_21 = int(x_2[0]) x_2n = int(x_2[-1]) if n >= 5: for i in range(3, n-1): input() if n == 3: x_n1 = x_2n else: x_n1 = int(input()[-1]) x_n = int(input()[-2]) if sum([x...
8
PYTHON3
for i in range(int(input())): n=int(input()) p=[] for i in range(n): x=input() p.append(x) if p[0][1]=='1' and p[1][0]=='1': if p[-2][-1]=='1' and p[-1][-2]=='1': print(2) print(n,n-1) print(n-1,n) elif p[-2][-1]=='1' and p[-1]...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } bool isKthBitSet(long long n, long long k) { if (n & (1 << (k - 1))) return true; else return fals...
8
CPP
for t__ in range(int(input())): n = int(input()) if n != 3: s1 = input() s2 = input() for i in range(n - 4): s__ = input() s3 = input() s4 = input() s1 = int(s1[1]) s2 = int(s2[0]) s3 = int(s3[-1]) s4 = int(s4[-2]) else: ...
8
PYTHON3
t = int(input()) for x in range(t): n = int(input()) s = [0] for i in range(n): s.append(' '+input()) if s[1][2] == '0' and s[2][1] == '0': s1 = False if s[n-1][n] == '1': s1 = True s2 = False if s[n][n-1] == '1': s2 = True if s1 and s2: print(0) elif s1: print(1) print(n,n-1) elif s2...
8
PYTHON3
for _ in range(int(input())): n = int(input()) A = [input() for i in range(n)] if A[0][1] == A[1][0]: if A[n-2][n-1] == A[n-1][n-2]: if A[n-2][n-1] == A[0][1]: print(2) print(1, 2) print(2, 1) else:print(0) else: ...
8
PYTHON3
for _ in range(int(input())): l = [] n = int(input()) for _ in range(n): l.append(input()) if (l[0][1] == '0' and l[1][0]=='0') and ((l[-1][-2] == '0' and l[-2][-1]=='0')): print(2) print(1, 2) print(2, 1) elif (l[0][1] == '1' and l[1][0]=='1') and ((l[-1][-2] == '1' ...
8
PYTHON3
import math def solve(): s=[] n=int(input()) for i in range(n): s.append(input()) p,q,r,s=s[0][1],s[1][0],s[n-2][n-1],s[n-1][n-2] x=''.join(sorted(p+q)) y=''.join(sorted(r+s)) if((x=='00' and y=='11') or (x=='11' and y=='00')): print(0) elif((x=='00' and y=='00') or (x=='...
8
PYTHON3
my_input = int(input()) my_num = [] my_list = [] for i in range(my_input): temp_list = [] inp = int(input()) my_num.append(inp) my_list.append([]) for j in range(inp): my_list[i].append(input()) if my_list[i][0][1] == '1': temp_list.append([1, 2]) if my_list[i][1][0] == '1': ...
8
PYTHON3
for _ in range(int(input())): n = int(input()) ml = [] kl = [] for i in range(n): ml.append(input()) x = [ml[0][1], ml[1][0], ml[n-1][n-2], ml[n-2][n-1]] x = [int(i) for i in x] if x in [[0, 0, 0, 0], [1, 1, 1, 1]]: print(2) print(n, n-1) print(n-1, n) eli...
8
PYTHON3
cases=int(input()) for _ in range(cases): n=int(input()) s=[] for i in range(n): s.append(list(input())) #print(2) #print(s) l1=[s[0][1],s[1][0]] l2=[s[n-2][n-1],s[n-1][n-2]] if l1[0]=='0' and l1[1]=='0' and l2[0]=='0' and l2[1]=='0': print(2) print(0+1,1+1) print(1+1,0+1) if l1[0]=='0' and l1[1]=='...
8
PYTHON3
import sys def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n') import m...
8
PYTHON3
a = int(input()) for i in range (a): b = int(input()) c = [] d = 0 for j in range (b): c.append(input()) e = [int(c[0][1]), "1 2", int(c[1][0]), "2 1", int(c[-2][-1]), (str(b - 1) + " " + str(b)), int(c[-1][-2]), (str(b) + " " + str(b - 1))] f = e.count(0) if not f: print(2) ...
8
PYTHON3
def st(a, b): return str(a + 1) + ' ' + str(b + 1) ans = [] for _ in range(int(input())): n = int(input()) u = [] for i in range(n): u.append(list(input())) a = [u[0][1], u[1][0], u[n - 1][n - 2], u[n - 2][n - 1]] if a[0] == a[1] and a[2] == a[3]: if a[1] != a[2]: a...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; long long int div_floor(const long long int &a, const long long int &b) { return a / b - (((a ^ b) < 0) and a % b); } long long int div_ceil(const long long int &a, const long long int &b) { return a / b + (((a ^ b) >= 0) and a % b); } void solve() { int n; cin >> n...
8
CPP
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const long long MAX = 1e18 + 1; const double pi = 3.1415926535897932384626433832; const long long M = 1e9 + 7; long long bis(long long a[], long long l, long long r, long long x) { while (l <= r) { long long m = l + (r - l) / 2; if (a...
8
CPP
import sys import collections input = sys.stdin.readline def main(): t = int(input()) for _ in range(t): N = int(input()) S = [input() for _ in range(N)] if S[0][1] == "0" and S[1][0] == "0" and S[N - 1][N - 2] == "0" and S[N - 2][N - 1] == "0": print(2) print(...
8
PYTHON3
for _ in range(int(input())): n = int(input()) siatka = [[] for _ in range(n)] for x in range(n): siatka[x] = input() wynik = [] if siatka[0][1] == siatka[1][0]: if siatka[-1][-2] == siatka[0][1]: wynik += [(n, n-1)] if siatka[-2][-1] == siatka[0][1]: ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; char g[n][n], a[4]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cin >> g[i][j]; } a[0] = g[0][1]; a[1] = g[1][0]; a[2] = g[n - 1][n - 2]; a[3] = g[n - ...
8
CPP
from sys import stdin input = stdin.readline q = int(input()) for _ in range(q): n = int(input()) mat = [list(input()) for i in range(n)] for i in range(n): mat[i] = mat[i][:n] l = [mat[0][1], mat[1][0]] r = [mat[-1][-2], mat[-2][-1]] if l[0] == l[1] and l[0] == '0': r[0] = '1' ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n; cin >> n; string s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; } if (s[0][1] == s[1][0]) { if (s[n - 1][n - 2] == s[n - 2][n - 1] && s[n - 1][n - 2] != s[0][1]) { c...
8
CPP
#include <bits/stdc++.h> using namespace std; namespace IO { const int SIZE = (1 << 20) + 1; char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = obuf + SIZE - 1; char _st[55]; int _qr = 0; inline char gc() { return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++) : *...
8
CPP
def solve(): n = int(input().strip()) grid = [] for _ in range(n): grid.append(input().strip()) cells = 0 pick1, pick2 = None , None zeros = len(list(filter(lambda x: x == '0', [grid[0][1], grid[1][0], grid[-1][-2], grid[-2][-1]]))) if zeros in [0, 4]: cells = 2 pick1...
8
PYTHON3
# Author : -pratyay- # import sys inp=sys.stdin.buffer.readline inar=lambda: list(map(int,inp().split())) inin=lambda: int(inp()) inst=lambda: inp().decode().strip() wrt=sys.stdout.write pr=lambda *args,end='\n': wrt(' '.join([str(x) for x in args])+end) enum=enumerate; inf=float('inf') cdiv=lambda x,y: (-(-x//y)) # Am...
8
PYTHON3
from collections import Counter for _ in range(int(input())): n=int(input()) l=[] for i in range(n): s=input() l.append(s) a1=int(l[0][1]) a2=int(l[1][0]) b1=int(l[n-1][n-2]) b2=int(l[n-2][n-1]) x=[a1,a2,b1,b2] d=Counter(x) if len(set(x))==1: print(2) ...
8
PYTHON3
""" pppppppppppppppppppp ppppp ppppppppppppppppppp ppppppp ppppppppppppppppppppp pppppppp pppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppp...
8
PYTHON3
for _ in range(int(input())): n=int(input()) l=[] for i in range(n): s=input() k=list(s) l.append(k) c=0 v1=l[0][1] v2=l[1][0] v3=l[n-1][n-2] v4=l[n-2][n-1] ans=[] if(v1==v2): if(v1=='1'): if(v3=='1'): c+=1 ...
8
PYTHON3
k = int(input()) for i in range(k): ans = [] n = int(input()) for i in range(n): ans.append(input()) a,b = ans[0][1],ans[1][0] c,d = ans[-1][-2],ans[-2][-1] flag = 0 for q in range(0,2): if flag == 1: break for w in range(0,2): if flag == 1: ...
8
PYTHON3
t=int(input()) for i in range(t): n=int(input()) l=[] for j in range(n): s=input() l.append(s) a=l[0][1] b=l[1][0] c=l[n-2][n-1] d=l[n-1][n-2] if a==b: if c==a and d==a: print('2') print(n,n-1) print(n-1,n) elif c==a: ...
8
PYTHON3
import math from decimal import * import random for _ in range(int(input())): n = int(input()) grid = [] for i in range(n): grid.append(list(input())) if(grid[0][1]=='0' and grid[1][0]=='0'): no= 0 ans = [] if(grid[n-1][n-2]=='0'): no+=1 ...
8
PYTHON3
from sys import stdin t = int(stdin.readline()) for _ in range(t): n = int(stdin.readline()) lst = [] for i in range(n): lst.append(stdin.readline()) d1 = (lst[-1][-4], lst[-2][-3], lst[-3][-2]) d2 = (lst[-1][-3], lst[-2][-2]) ans = [] if d2[0] == d2[1]: if d1[0] == d1[1...
8
PYTHON3
t = int(input()) for _ in range(t): n = int(input()) arr = [input() for i in range(n)] a = arr[0][1] b = arr[1][0] c = arr[n-2][n-1] d = arr[n-1][n-2] if (a == b): ans = [] if c == a: ans.append([n-1, n]) if d == a: ans.append([n, n-1]) ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; } if (s[1][0] == s[0][1]) { if (s[n - 1][n - 2] == s[n - 2][n - 1] && s[n - 1][n - 2] != s[0][1]) { cout <<...
8
CPP
def mySolver(li, grid): g1 = int(li[0][0][1]) g2 = int(li[1][0][0]) g3 = int(li[grid-2][0][grid-1]) g4 = int(li[grid-1][0][grid-2]) count = 0 ans = [] if g2 == g1 and g3 == g4: if g1 == g3: ans.append([1,2]) ans.append([2,1]) elif g2 != g1 and g3 == g4: ...
8
PYTHON3
import sys for j in range(int(input())): n, list1 = int(input()), [] for i in range(n): z = [str(i) for i in sys.stdin.readline().strip()] list1.append(z) a1, a2, b1, b2 = list1[0][1], list1[1][0], list1[-1][-2], list1[-2][-1] if a2 == a1 and b2 == b1 and a2 != b2: print(0) elif a2 == a1 == b2 == b1: ...
8
PYTHON3
t = int(input()) for i in range(t): l = [] n = int(input()) for i in range(n): z = [i for i in input().split()] l.append(z) a = int(l[0][0][1]) b = int(l[1][0][0]) c = int(l[n-2][0][n-1]) d = int(l[n-1][0][n-2]) if a==b==c==d:#3 print(2) print(1,2...
8
PYTHON3
for _ in range(int(input())): n=int(input()) mat=[] for i in range(n): mat.append(list(input())) a=int(mat[0][1]) b=int(mat[1][0]) c=int(mat[n-1][n-2]) d=int(mat[n-2][n-1]) change=[] if a==b: if c==d and c!=a: do=1 elif c==d and c==a: ...
8
PYTHON3
t=int(input()) while t>0: t-=1 n=int(input()) arr=[] for i in range(n): a=input() b=[] for i in range(n): b.append(a[i]) arr.append(b) if arr[0][1]==arr[1][0]: ans=[] if arr[2][0]==arr[0][1]: ans.append([2,0]) if arr[...
8
PYTHON3
t=int(input()) for i in range(t): size = int(input()) lines = [] for j in range(size): lines.append(input()) d0,d1,f0,f1=0,0,0,0 if lines[0][1] == '1': d1 += 1 if lines[1][0] == '1': d1 += 1 if lines[-1][-2] == '1': f1 += 1 if lines[-2][-1] == '1': f1 += 1 ...
8
PYTHON3
t=int(input()) for _ in range(t): n = int(input()) l=[] i=int(0) for i in range(n): l.append(input()) x1=l[0][1] x2=l[1][0] y1,y2 = l[-2][-1],l[-1][-2] # print(x1) # print(x2) # print(y1) # print(y2) if((x1==x2)and(x2==y1)and(y1==y2)): print("2") ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; void input() { freopen("input.txt", "r", stdin); freopen("dekho.txt", "w", stdout); } int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; char a[n][n]; for (long long i = (0); i < (n); i++) ...
8
CPP
#include <bits/stdc++.h> int main() { int t; scanf("%d", &t); int x[3]; int y[3]; int num; char str[205][205]; while (t--) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%s", &str[i][1]); num = 0; if (str[2][1] == str[1][2]) { if (str[n - 1][n] == str[2][1]) { ...
8
CPP
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(nam...
8
CPP
t = int(input()) while t: t -= 1 n = int(input()) for i in range(n): s = input().strip() if i == 0: a = int(s[1]) if i == 1: b = int(s[0]) if i == n-2: c = int(s[-1]) if i == n-1: d = int(s[-2]) else: ...
8
PYTHON3
import itertools import math import sys from collections import defaultdict def is_debug(): return '--debug' in sys.argv def stdin_wrapper(): data = '''3 4 S010 0001 1000 111F 3 S10 101 01F 5 S0101 00000 01111 11111 0001F ''' for line in data.split('\n'): yield line if not is_debug(): ...
8
PYTHON3
import io import os import sys import math import heapq input = sys.stdin.readline mod = 10**9 + 7 t = int(input()) for _ in range(t): n = int(input()) G = [] for _ in range(n): x = input().rstrip() x = list(x) G.append(x) #print(G) s1,s2 = int(G[0][1]), i...
8
PYTHON3
for _ in range(int(input())): n=int(input()) grid = [input() for i in range(n)] p=[] count = 0 if grid[0][1] == '0' and grid[1][0] == '0' and grid[n-1][n-2] == '1' and grid[n-2][n-1] == '1': print(0) continue elif grid[0][1] == '1' and grid[1][0] == '1' and grid[n-1][n-2] == '0...
8
PYTHON3
import math t = int(input()) for _ in range(t): n = int(input()) li = [] for i in range(n): ali = input() ali = list(ali) li.append(ali) # print(li) q = int(li[0][1]) w = int(li[1][0]) e = int(li[n-2][n-1]) r = int(li[n-1][n-2]) cnt = 0 ans = [] if(q =...
8
PYTHON3
#include <bits/stdc++.h> const unsigned int MOD = 1000000007; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; for (int tt = 0; tt < t; tt++) { int n; cin >> n; string s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; } char c = s...
8
CPP
import itertools def solve(matrix): n = len(matrix) cells = [ (0, 1), (1, 0), (n - 1, n - 2), (n - 2, n - 1) ] for ncells in range(3): for combi in itertools.combinations(cells, ncells): for y, x in combi: matrix[y][x] = '1' if matrix[...
8
PYTHON3
import typing import sys import math import collections import bisect import itertools import heapq import decimal # import numpy as np # sys.setrecursionlimit(10000001) INF = 10 ** 20 MOD = 10 ** 9 + 7 # MOD = 998244353 def ni(): return int(sys.stdin.buffer.readline()) def ns(): return map(int, sys.stdin.buffer.rea...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; long long mod(long long x) { return (((x % 1000000007) + 1000000007) % 1000000007); } long long mul(long long x, long long y) { return mod(mod(x) * mod(y)); } long long add(long long a, long long b) { return mod(mod(a) + mod(b)); } long long modpow(long long x, long long ...
8
CPP
def main(): for _ in range(int(input())): n=int(input()) l=[list(map(lambda x: int(x) if(not (x=='S' or x=='F')) else x,input())) for i in range(n)] if(l[0][1]==l[1][0] and l[n-1][n-2]==l[n-2][n-1] and l[n-1][n-2]==1-l[1][0]): print(0) elif(l[0][1]==l[1][0] and l[n-1][n-2...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 1000 + 10; char str[N][N]; int main() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%s", str[i]); int tou1 = 0, wei1 = 0; if (str[0][1] == '1') tou1++; if (str[1][0] == '1') tou...
8
CPP
import sys def main(stream=sys.stdin): t = int(stream.readline()) for _ in range(t): n = int(stream.readline()) data = [] for i in range(n): data.append([str(c) for c in stream.readline()]) s = [data[0][1], data[1][0]] f = [data[n - 1][n - 2], data[n - 2]...
8
PYTHON3
for nt in range(int(input())): n = int(input()) grid = [] for i in range(n): grid.append(list(input())) if grid[n-1][n-2]==grid[n-2][n-1]: count, ans = 0, [] if grid[n-1][n-2]=="1": if grid[0][1]=="1": count += 1 ans.append([1,2]) if grid[1][0]=="1": count += 1 ans.append([2,1]) else: ...
8
PYTHON3
t = int(input()) while t: mas=[] n = int(input()) for i in range(n): w = input() w = list(w) mas.append(w) s1 = int(mas[0][1]) s2 = int(mas[1][0]) f1 = int(mas[-2][-1]) f2 = int(mas[-1][-2]) if s1 == s2 and f1==f2 and f1!=s1:# print(0) t-=1 ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const int nax = 203; char a[nax][nax]; void run_case() { int n; cin >> n; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> a[i][j]; } } vector<pair<int, int>> ans; if (a[n - 1][n - 2] != '1') { ans.push_back({n, n - 1}); } ...
8
CPP
import sys #import bisect import math #import itertools def get_line(): return list(map(str,sys.stdin.readline())) def in1(): return int(input()) for _ in range(in1()): n=in1() b=[[0 for i in range(n)] for j in range(n)] for j in range(n): c=list(get_line()) for k in range(n): b...
8
PYTHON3