solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
t=int(input()) for i in range(t): l=[] nl=[] c=0 n=int(input()) zc=0 oc=0 k=0 a='' b='' c='' d='' for i2 in range(n): ml='' mlt=[] ml=input() l.append(ml) a=l[n-1][n-3] b=l[n-2][n-2] c=l[n-3][n-1] e=l[n-1][n-2] f=l[n-2]...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n; cin >> n; char a[n + 1][n + 1]; for (long long i = 1; i <= n; i++) { for (long long j = 1; j <= n; j++) { c...
8
CPP
for _ in range(int(input())): n = int(input()) mat = [] for i in range(n): mat.append(input()) d = [(1,2),(2,1),(n-1,n),(n,n-1)] items = [int(mat[0][1]),int(mat[1][0]),int(mat[-2][-1]),int(mat[-1][-2])] ans = [] if items[:2]==[0,0] or items[2:]==[1,1]: for i in range(4): ...
8
PYTHON3
from sys import stdin def main(): input = lambda: stdin.readline()[:-1] T = int(input()) for _ in [0] * T: N = int(input()) S = [input() for _ in [0] * N] sd, sr = int(S[1][0]), int(S[0][1]) fu, fl = int(S[N - 2][N - 1]), int(S[N - 1][N - 2]) if sd + sr + fu + fl =...
8
PYTHON3
import sys input = sys.stdin.readline for _ in range(int(input())): N = int(input()) a = [list(input())[: -1] for _ in range(N)] res = [] if a[0][1] == a[1][0]: x = a[0][1] if a[-1][-2] == x: res.append((N, N - 1)) if a[-2][-1] == x: res.append((N - 1, N)) else: if a[-1][-2] == a[-2][-1]: ...
8
PYTHON3
t=int(input()) for _ in range(t): n=int(input()) grid=[] for i in range(n): l=input() grid.append(l) a=grid[0][1] b=grid[1][0] c=grid[n-2][n-1] d=grid[n-1][n-2] if a==b: if c==d: if a==c: print("2") print(n,n-1) print(n-1,n) else: print("0") else: print("1") if a==c: pri...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int tryFirstState(vector<vector<char> > &a, int n) { int sol = 0; vector<vector<int> > ans(5, vector<int>(2, 0)); if (a[1][0] != '0') { ans[sol][0] = 2; ans[sol][1] = 1; sol++; } if (a[0][1] != '0') { ans[sol][0] = 1; ans[sol][1] = 2; sol++...
8
CPP
for _ in range(int(input())): n = int(input()) a = [input() for _ in range(n)] for color in range(2): result = [] if int(a[0][1]) != color: result.append((0, 1)) if int(a[1][0]) != color: result.append((1, 0)) if int(a[n - 1][n - 2]) == color: ...
8
PYTHON3
for test_var in range(int(input())): n = int(input()) s = ['']*n for i in range(n): s[i] = input().strip() a, b, c, d = s[0][1], s[1][0], s[n-1][n-2], s[n-2][n-1] if a == b == c == d: print("2\n1 2\n2 1") elif a != b and c == d: if a == c: print("1\n1 2") ...
8
PYTHON3
import io import os from collections import Counter, defaultdict, deque def solve(N, grid): vals = [ (x, y, int(grid[x][y])) for x, y in [(0, 1), (1, 0), (N - 1, N - 2), (N - 2, N - 1)] ] patterns = [[0, 0, 1, 1], [1, 1, 0, 0]] for pattern in patterns: flips = [] for p...
8
PYTHON3
t = int(input()) for _ in range(t): n = int(input()) B = [input() for _ in range(n)] a,b = map(int, (B[0][1],B[1][0])) c,d = map(int, (B[-1][-2],B[-2][-1])) ans = [] if abs(a-1)+abs(b-1) + abs(c-0)+abs(d-0) <= 2: if a == 0: ans.append((1, 2)) if b == 0: ...
8
PYTHON3
import os, sys from io import IOBase, BytesIO py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.writa...
8
PYTHON3
def main(): n = int(input()) lst = [] for i in range(n): line = input() lst.append(line) top_left = lst[0][1] top_right = lst[1][0] bot_left = lst[n - 1][n - 2] bot_right = lst[n - 2][n - 1] if top_left == top_right: if bot_left == bot_right and bot_left == top_le...
8
PYTHON3
t = int(input()) for _ in range(t): n = int(input()) matrix = list() for i in range(n): a = list(input()) matrix.append(a) switch = list() count = 0 if matrix[0][1] == matrix[1][0]: common = matrix[0][1] if matrix[n-1][n-2] == common: switch.appen...
8
PYTHON3
t=int(input()) while t: n=int(input()) maze=[[0]*n]*n for i in range(n): s=input() row=[i for i in s] maze[i]=row s_right=maze[0][1] s_down=maze[1][0] f_up=maze[n-2][n-1] f_left=maze[n-1][n-2] f=[f_up,f_left] if s_right not in f and s_down not in f: pr...
8
PYTHON3
import sys import bisect as bi import math from collections import defaultdict as dd import heapq import itertools import io import os ##import operator input=sys.stdin.readline ##input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline import random sys.setrecursionlimit(10**7) ##fo=open("output.txt","w") ##fi=ope...
8
PYTHON3
from functools import reduce import collections import math import sys class Read: @staticmethod def string(): return input() @staticmethod def int(): return int(input()) @staticmethod def list(delimiter=' '): return input().split(delimiter) @staticmethod d...
8
PYTHON3
from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import heappush,heappop import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline M = mod = 998244353 def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in ...
8
PYTHON3
from collections import defaultdict T = int(input()) ans_c = [0] * T ans_ls = [0] * T for t in range(T): N = int(input()) grid = [list(input()) for i in range(N)] d = defaultdict(int) ls = [] for y,x in [[0,1],[1,0],[N-1,N-2],[N-2,N-1]]: d[grid[y][x]] += 1 same_on_left = True if gr...
8
PYTHON3
t = int(input()) for _ in range(t): n = int(input()) m = [] for _ in range(n): m.append(input()) a, b, c, d = m[1][0], m[0][1], m[-1][-2], m[-2][-1] t = 8*int(a) + 4*int(b) + 2*int(c) + 1*int(d) a2 = 0 if t in [0, 15]: a2 = [(1,2),(2,1)] elif t in [1, 14]: a2 =...
8
PYTHON3
t = int(input()) for _ in range(t): n = int(input()) arr = input() # print(arr) el12 = int(arr[1]) arr = input() # print(arr) el21 = int(arr[0]) if n == 3: el34 = int(arr[n-1]) arr = input() el43 = int(arr[n-2]) else: for _ in range(n-4): ...
8
PYTHON3
for _ in range(int(input())): n =int(input()) s = [] for i in range(n): temp = input() s.append([i for i in temp]) cnt1 = 0 ans1 = [] cnt2 = 0 ans2 = [] if(s[0][1] == "0"): pass else: cnt1+=1 ans1.append([1,2]) if(s[1][0] == "0"): p...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; char g[n][n]; bool vis[n][n]; for (int i(0); i < n; i++) { for (int j(0); j < n; j++) { cin >> g[i][j]; ...
8
CPP
t=int(input()) for q in range(0,t): n=int(input()) a=[] for i in range(0,n): a.append(list(input())) ans=[] if a[0][1]==a[1][0] and a[n-1][n-2]==a[n-2][n-1] and a[0][1]!=a[n-1][n-2]: print(0) elif a[0][1]==a[1][0] and a[n-1][n-2]!=a[n-2][n-1]: #print("h") if a[0][...
8
PYTHON3
for tc in range(int(input())): n = int(input()) mat = [] for i in range(n): mat.append(input()) # print(mat) x = mat[0][1] y = mat[1][0] p = mat[-1][-2] q = mat[-2][-1] if (x == y) and (p == q): if x == p: print('2') print('1 2') ...
8
PYTHON3
T=int(input()) for _ in range(T): n=int(input()) matrix=[] for i in range(n): s=input() matrix.append(s) #print(matrix) if matrix[0][1]!=matrix[1][0] and matrix[n-2][n-1]!=matrix[n-1][n-2]: lis=[] if matrix[0][1]=='0': lis.append([1,2]) else: ...
8
PYTHON3
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) grid = [[]] for i in range(n): line = ' '+input().strip('\n') grid.append(line) a,b = grid[1][2], grid[2][1] x,y = grid[n][n-1], grid[n-1][n] if a == b and x == y and x!=a: print(0) ...
8
PYTHON3
for _ in range(int(input())): n=int(input()) l=[] for i in range(n): l.append(input()) a=l[1][0];b=l[0][1];c=l[n-2][n-1];d=l[n-1][n-2] if a==b and c==d: if a==c: print(2);print(1,2);print(2,1) else: print(0) elif a==b: if a==c: print(1);print(n-1,n) else: print(1);print(n,n-1) elif c==d: ...
8
PYTHON3
for _ in range(int(input())): n = int(input()) grid = [[*input()] for _ in range(n)] sr = grid[0][1] sd = grid[1][0] fu = grid[-2][-1] fl = grid[-1][-2] if (sr == sd == '0' and fu == fl == '1') or (sr == sd == '1' and fu == fl == '0'): print(0) elif sr == sd and fu != fl: ...
8
PYTHON3
def one_indexed(pair): return [item + 1 for item in pair] t = int(input()) for i in range(t): n = int(input()) grid = [[int(i) if (i != "S" and i != "F") else i for i in list(input())] for j in range(n)] doors = [(0, 1), (1, 0), (n - 2, n - 1), (n - 1, n - 2)] door_vals = [grid[i][j] for i, j...
8
PYTHON3
for _ in range(int(input())): n = int(input()) arr = [] for i in range(n): arr.append(input()) if arr[1][0] == "0" and arr[0][1] == "0" and arr[n-1][n-2] == "0" and arr[n-2][n-1] == "0": print(2) print(1,2) print(2,1) elif arr[1][0] == "0" and arr[0][1] == "0" and arr[n-1][n-2] == "0" and arr[n-2][n-1] ...
8
PYTHON3
for _ in range(int(input())): n=int(input()) arr=[] for i in range(n): s=input() arr.append(s) if (arr[0][1]=='0' and arr[1][0]=='0' and arr[n-1][n-2]=='1' and arr[n-2][n-1]=='1') or (arr[0][1]=='1' and arr[1][0]=='1' and arr[n-1][n-2]=='0' and arr[n-2][n-1]=='0'): print('0') ...
8
PYTHON3
t=int(input()) for _ in range(t): n=int(input()) l=[] for i in range(n): s=str(input()) l.append(s) try: a,b,c,d=l[0][1],l[1][0],l[n-1][n-2],l[n-2][n-1] except: print(l) break arr=[a,b,c,d] temp=["1","1","0","0"] key=["0","0","1","1"] tempc=0 ...
8
PYTHON3
t=int(input()) for _ in range(t): n=int(input()) up=[-1,-1] down=[-1,-1] for i in range(n): s=input() if i==0: up[0]=s[1] elif i==1: up[1]=s[0] if i==n-2: down[0]=s[-1] elif i==n-1: down[1]=s[-2] if up[0]==up[1]...
8
PYTHON3
# 改行でバグる時 import sys input = lambda: sys.stdin.readline().rstrip() t=int(input()) g=[] for i in range(t): a=int(input()) x=[] for j in range(a): b=list(input()) x.append(b) g.append(x) ans=[] for i in range(t): v=len(g[i]) x1=g[i][0][1] x2=g[i][1][0] y1=g[i][v-2][v-1] ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while (tt--) { int n; cin >> n; vector<string> grid(n); for (auto &it : grid) cin >> it; vector<array<int, 2>> pos = { {0, 1}, {1, 0}, {n - 1...
8
CPP
T=int(input()) for Tid in range(T): n=int(input()) a=[] for i in range(n): a.append(input()) a0,a1,a2=[],[],[] def add(x,y,c): if a[x][y]==c: a0.append([x+1,y+1]) else: a1.append([x+1,y+1]) add(0,1,'0') add(1,0,'0') add(n-1,n-2,'1') ad...
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 i, j, k, m, n, l, res = 0, zero = 0, one = 0, a, b, c, d; cin >> n; vector<pair<int, int> > v; string s[n + 1]; for (i = 0; i < n; i++)...
8
CPP
m = { "0000": (3, 4), "0001": (3,), "0010": (4,), "0011": (), "0100": (1,), "0101": (2, 3), "0110": (2, 4), "0111": (2,), "1000": (2,), "1001": (2, 4), "1010": (2, 3), "1011": (1,), "1100": (), "1101": (4,), "1110": (3,), "1111": (3, 4) } t = int(input())...
8
PYTHON3
for x in range(int(input())): n = int(input()) l=[] for i in range(n): s=input() l.append(s) if l[n-1][n-2]!=l[n-2][n-1]: if l[1][0]==l[0][1]: print(1) if l[n-1][n-2]==l[1][0]: print(n,n-1) else: print(n-1,n) ...
8
PYTHON3
from collections import Counter, OrderedDict from itertools import permutations as perm from sys import setrecursionlimit from collections import deque from sys import stdin from bisect import * from heapq import * import threading import math g = lambda : stdin.readline().strip() gl = lambda : g().split() gil = l...
8
PYTHON3
for _ in range(int(input())): n = int(input()) grid = [] ans = 0 for i in range(n): grid.append([j for j in str(input())]) # print(grid) first_left = [1,2] col_ah = [2,1] last_right = [n,n-1] col_pre = [n-1,n] ans = [] if grid[0][1] == grid[n-1][n-2] == grid...
8
PYTHON3
import queue t = int(input()) while (t): n = int(input()) grid = [] for i in range(n): grid.append(input()) ans = [] if (grid[0][1] == grid[1][0]): if (grid[-1][-2] == grid[0][1]): ans.append((n,n-1)) if (grid[-2][-1] == grid[0][1]): ans.append((n-1,n)) elif (grid[-1][-2] == grid[-2][-1]): if...
8
PYTHON3
for _ in range(int(input())): n = int(input()) l = [] for i in range(n): l.append(list(input())) e = [l[0][1] , l[1][0] , l[n-2][n-1] , l[n-1][n-2]] pos = [[1,2] , [2,1] , [n-1,n] , [n,n-1]] moves = 0 ans = [] if(e[0] == e[1]): if(e[2] == e[3]): if(e...
8
PYTHON3
t=int(input()) i=1 while(i<=t): n = int(input()) mat = [] for j in range(n): mat.append(list(input())) # print(mat) # print(mat[0]) x1 = int(mat[0][1]) x2 = int(mat[1][0]) x3 = int(mat[n-1][n-2]) x4 = int(mat[n-2][n-1]) s1 = x1+x2 s2 = x3+x4 if(s1==0 and s2==1): print(1) if(x3==0): print(n,n-1) i...
8
PYTHON3
import os import sys from io import BytesIO, IOBase 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.wri...
8
PYTHON3
t = int(input()) for i in range(t): n = list(map(int, input().split()))[0] l = [2, 2, 2, 2] cords = [ (1, 2), (2, 1), (n - 1, n), (n, n - 1) ] for j in range(n): s = input() if j == 0: l[0] = int(s[1]) if j == 1: l[1]...
8
PYTHON3
import sys, os, io 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') ...
8
PYTHON3
# region fastio # from https://codeforces.com/contest/1333/submission/75948789 import sys, io, os BUFSIZE = 8192 class FastIO(io.IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = io.BytesIO() self.writable = "x" in file.mode or "r" not in file.mo...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long INF64 = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int chu; cin >> chu; while (chu--) { long long int n; cin >> n; string s[n]; for (long long int i = 0; i < n; i++) cin >> s[i]; ...
8
CPP
import sys import math import bisect from sys import stdin, stdout from math import gcd, floor, sqrt, log2, ceil from collections import defaultdict as dd from bisect import bisect_left as bl, bisect_right as br from bisect import insort from collections import Counter from collections import deque from heapq import he...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; char g[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cin >> g[i][j]; } int a = 0, b = 1, c = n - 1, d = n - 2; if (g[a][b] == g[b][a] && g[c][d] == g[d][c]) { if (g[a][b] != g[c][d]) { cout << 0 ...
8
CPP
#include <bits/stdc++.h> using namespace std; 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>> v; if (a[0][1] == a[1][0]) { if (a[n - 2][n - 1] == a[0][1]) v.push_back({n -...
8
CPP
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; char arr[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cin >> arr[i][j]; } char temp = arr[0][1]; vector<pair<int, int>> v; if (arr[1][0] != temp) v.push_back({2, 1}); if (arr[n - 1][n - 2] == temp) v....
8
CPP
# cook your dish here import math; for _ in range(int(input())): n=int(input()) x=[] for i in range(n): x.append(input()) a,b,c,d=x[1][0],x[0][1],x[n-1][n-2],x[n-2][n-1] if(a==b and c==d): if(a==c): print(2) print(1,2) print(2,1) else: ...
8
PYTHON3
import sys # sys.stdin = open("E:\\programming\\New folder\\input.txt", "r") # sys.stdout = open("E:\\programming\\New folder\\output.txt", "w") ans = 0 def fun(p, key1, key2): k = 0 global ans ans = 0 for i in range(1, -1, -1): if int(st[k][i]) != key1: ans += 1 p.ap...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; 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]; long long z = 0, o = 0, z2 = 0, o2 = 0; if (a[0][1] == '0') z++; if (a[1][0] == '0') z++; if (a[0][1] == '1') o++; i...
8
CPP
#include <bits/stdc++.h> using namespace std; const int number = 1000000; int isprime[number + 2] = {0}; long long expo(long long x, long long y, long long m) { long long p = 1; while (y > 0) { if (y % 2 == 1) p = p * x % m; x = x * x % m; y = y / 2; } return (p % m); } void sieve() { isprime[0] =...
8
CPP
import math test = int(input()) for t in range(test): n = int(input()) S = [] for i in range(n): s = input() S.append(s) a = S[0][1];b = S[1][0] c = S[n-1][n-2];d = S[n-2][n-1] ans = [] if(a==b): if(c==a): ans.append([n,n-1]) if(d==a): ...
8
PYTHON3
t = int(input()) for _ in range(t): n = int(input()) grid = [] for i in range(n): grid.append(input()) count = 0 ans = "" if(grid[-1][-2] == grid[-2][-1]): if(grid[0][1] == grid[-2][-1]): ans += "\n1 2" count+=1 if(grid[1][0] == grid[-2][-1]): ans += "\n2 1" count+=1 elif(grid[0][1] == grid[1]...
8
PYTHON3
t=int(input()) for i in range(0,t): n=int(input()) a=[] for j in range(0,n): b=input() q=[b[k] for k in range(0,n)] a.append(q) if(n!=0): c=[a[0][1],a[1][0],a[n-1][n-2],a[n-2][n-1]] x1=int(a[0][1])+int(a[1][0]) x2=int(a[n-1][n-2])+int(a[n-2][n-1]) ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") template <typename T, typename T1> T amax(T &a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T amin(T &a, T1 b) { if (b < a) a = b; return a; } void OJ() {} const lon...
8
CPP
T = int(input()) M =[ [0 for i in range(300)] for j in range(300)] for t in range(T): n = int(input()) for i in range(n): a = input() for j in range(n): if a[j] != 'S' and a[j] != 'F': M[i][j] = int(a[j]) res1 = [] res0 = [] if M[0][1] == 1: res0.a...
8
PYTHON3
import sys,bisect,string,math,time,functools,random,fractions from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter from itertools import permutations,combinations,groupby rep=range;R=range def Golf():n,*t=map(int,open(0).read().split()) def I():return int(input()) def S_():return...
8
PYTHON3
import sys from random import * #from bisect import * #from collections import deque pl=1 #from math import * from copy import * if pl: input=sys.stdin.readline else: sys.stdin=open('input.txt', 'r') sys.stdout=open('outpt.txt','w') def li(): return [int(xxx) for xxx in input().split()] def fi(): return int(inp...
8
PYTHON3
def check(l,s,c): if l[0][1]==l[1][0]: x=l[0][1] a=l[n-1][n-2] b=l[n-2][n-1] if a==x: c=c+1 s.append([n,n-1]) if b==x: c=c+1 s.append([n-1,n]) print(c) for i in s: print(*i) return a=l[n-1...
8
PYTHON3
def solve(): n = int(input()) grid = [] for _ in range(n): grid.append(input()) g01 = grid[0][1] g10 = grid[1][0] g_12 = grid[n-1][n-2] g_21 = grid[n-2][n-1] if g01 == g10: if g_12 == g_21: if g01 == g_12: print("2") print("...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; void sol() { long long n; cin >> n; char a; long long flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a; if (i == 0 && j == 1) { if (a == '1') flag1++; } if (i == 1 ...
8
CPP
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 40; vector<int> used(N, 0); void solve() { int n; cin >> n; char a[n + 2][n + 2]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> a[i][j]; } } int b1; b1 = (a[n - 1][n] == '1') + (a[n][n - 1] == '1'); in...
8
CPP
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
for _ in range(int(input())): n=int(input()) data=[] for q in range(n): data.append(input()) start_right=data[0][1] start_down=data[1][0] end_left=data[-1][-2] end_top=data[-2][-1] if(start_right==start_down): if(end_left==end_top): if(start_down==end_left): ...
8
PYTHON3
t = int(input()) for i in range(t): grid = [] n = int(input()) for j in range(n): grid.append(input()) a = grid[0][1] b = grid[1][0] c = grid[n - 2][n - 1] d = grid[n - 1][n - 2] if a == b and c == d and b == c: print(2) print("1 2") print("2 1") elif ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; char _grid[300][300], grid[300][300]; long long vis[300][300]; long long n, m; long long di[] = {0, 0, -1, 1}; long long dj[] = {-1, 1, 0, 0}; bool isPos(long long i, long long j) { return (i >= 0 and j >= 0 and i < n and j < n and !vis[i][j]); } void dfs(long long i, lon...
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long t; cin >> t; long long n; long long ans = 0; long long f1 = 0, f2 = 0; while (t--) { f1 = f2 = 0; ans = 0; cin >> n; string s = ""; string t = ""; for (long long i = 0; i < n; i++...
8
CPP
#include <bits/stdc++.h> using namespace std; char mp[205][205]; int main() { int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> mp[i][j]; } } queue<pair<int, int>> q; if (mp[2][1] == mp[1][2]) { if...
8
CPP
t = int(input()) import itertools for _ in range(t): n = int(input()) S = [list(str(input())) for _ in range(n)] flag = False s = [] # 0 s.append((0, 0)) visit0 = [[-1]*n for _ in range(n)] while s: i, j = s.pop() for di, dj in (-1, 0), (1, 0), (0, -1), (0, 1): ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long N = 205; char a[N][N]; void Main() { long long n; cin >> n; for (long long i = 1; i <= n; i++) for (long long j = 1; j <= n; j++) { cin >> a[i][j]; } vector<pair<long long, long long> > res; if (a[1][2] == a[2][1]) { char c = a[1]...
8
CPP
def main(): for _ in range(int(input())): n=int(input()) matx=[] for j in range(n): matx.append([str(x) for x in input()]) x=[int(matx[0][1]),int(matx[1][0])] y=[int(matx[n-1][n-2]),int(matx[n-2][n-1])] if x==[0,0] and y==[1,1 ]: print(0) ...
8
PYTHON3
def solve(n,m): #print(n,m) a = m[0][1] b = m[1][0] c = m[n-1][n-2] d = m[n-2][n-1] res = [] if a ==b: if a == c: res.append([n,n-1]) if a == d: res.append([n-1,n]) elif c == d: if c == a: res.append([1,2]) if b...
8
PYTHON3
from math import * import sys from sys import stdin from sys import stdout # input = stdin.readline for __ in range(int(input())): n=int(input()) ar=[] for i in range(n): ar.append(input()) a=ar[0][1] b=ar[1][0] x=ar[n-1][n-2] y=ar[n-2][n-1] if(a==b and x==y and a!=x): print(0) elif(a==b==x==y): print(2...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> foo(string table[], int n, char character) { vector<pair<int, int>> result(0); char ch = character; if (table[n - 1][n - 3] != ch) result.push_back({n - 1, n - 3}); if (table[n - 2][n - 2] != ch) result.push_back({n - 2, n - 2}); if (table[n...
8
CPP
#include <bits/stdc++.h> using namespace std; bool isprime(int64_t n) { for (int64_t i = 2; i * i <= n; ++i) { if (n % i == 0) { return false; } } return true; } int64_t factorial(int64_t n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); } int64_t gcd(int64_t a, int64_t b) { if (a == 0)...
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t, n; cin >> t; while (t--) { 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...
8
CPP
#include <bits/stdc++.h> const long long INF = 1e18; const long long mod = 1e9 + 7; using namespace std; void solve() { long long n; cin >> n; vector<vector<char>> vec(n, vector<char>(n)); for (long long i = 0; i < n; i++) { for (long long j = 0; j < n; j++) { cin >> vec[i][j]; } } long long a...
8
CPP
# cook your dish here for _ in range(int(input())): n=int(input()) a=[] for i in range(n): a.append(input()) l=[] if a[0][1]==a[1][0]: if a[-2][-1]==a[0][1]: l.append([n-1,n]) if a[-1][-2]==a[0][1]: l.append([n,n-1]) else: if a[-1][-2]==a[-...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; inline int rd() { int x = 0; bool f = 0; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = 1; c = getchar(); } while (isdigit(c)) { x = x * 10 + (c ^ 48); c = getchar(); } return f ? -x : x; } int a[307][307]; inline void work() { ...
8
CPP
t = int(input()) for case in range(t): n = int(input()) grid = [] for row in range(n): grid.append([int(q) if q in '01' else q for q in input()]) changes = [] q = sum([grid[0][2], grid[1][1], grid[2][0]]) if q in (0, 3): if q//3 == grid[0][1]: changes.append([1...
8
PYTHON3
for _ in range(int(input())): n = int(input()) arr = [] for row in range(n): arr.append(input()) n = n+1 if arr[0][1] == arr[1][0] == arr[-2][-1] == arr[-1][-2]: print(2) print(n-2, n-1) print(n-1, n-2) continue elif arr[0][1] == arr[1][0]: if arr[...
8
PYTHON3
for _ in range(int(input())): n=int(input()) s=[input() for i in range(n)] f1=[int(s[0][1]),int(s[1][0])] f2=[int(s[-1][-2]),int(s[-2][-1])] ans=[] if f1==[0,0]: if f2[0]==0: ans.append([n,n-1]) if f2[1]==0: ans.append([n-1,n]) elif f1==[1,1]: ...
8
PYTHON3
import sys as _sys ZERO = '0' ONE = '1' def main(): t = int(input()) for i_t in range(t): n, = _read_ints() a = tuple(tuple(_read_line()) for i_row in range(n)) result = tuple(find_cells_to_invert(a)) print(len(result)) for x, y in result: if x < 0: ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; long long i, i1, j, k, k1, t, n, m, res, flag[10], a, b, mt[210][210], f[210]; char x; vector<array<long long, 2>> sl; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--) { cin >> n; sl.clear(); for (i = 1; i <= n; i++) { for (j...
8
CPP
import sys input = sys.stdin.readline import math for _ in range(int(input())): n = int(input()) lis=[] for i in range(n): tmp = list(input()) lis.append(tmp) #print(lis[0][1],lis[1][0],lis[n-2][n-1],lis[n-1][n-2]) if lis[0][1]==lis[1][0]: if lis[n-1][n-2]==lis[n-2][n-1]: ...
8
PYTHON3
for _ in range(int(input())): n = int(input()) arr = list() for _ in range(n): arr.append(input()) ss = arr[0][1] sd = arr[1][0] fu = arr[n-2][n-1] fl = arr[n-1][n-2] if ss == sd: if fu == fl: if ss!=fu: print(0) else : ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const long long int inf = 2e9 + 5; double PI = 3.14159265358979323846; void solve() { int n; cin >> n; char c[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> c[i][j]; } } vector<pair<int,...
8
CPP
#include <bits/stdc++.h> using namespace std; const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1}; const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1}; template <typename T_n> void read(T_n &n) { cin >> n; } template <typename T_n, typename T_a> void read(T_a a[], T_n n...
8
CPP
import sys input=sys.stdin.readline t=int(input()) def f(mat): c = [["0" for i in range(n)]for j in range(n)] for i in range(n): for j in range(n): c[i][j] = mat[i][j] return c from collections import deque def check(mat,l): for i in range(len(l)): if(mat[l[i][0]][l[i][1]] ...
8
PYTHON3
from sys import stdin,stdout from math import gcd,sqrt,factorial,pi,inf from collections import deque,defaultdict input=stdin.readline R=lambda:map(int,input().split()) I=lambda:int(input()) S=lambda:input().rstrip('\n') L=lambda:list(R()) P=lambda x:stdout.write(str(x)+'\n') lcm=lambda x,y:(x*y)//gcd(x,y) hg=lambda x,...
8
PYTHON3
from math import * from bisect import * from collections import * from random import * from decimal import * from itertools import * import sys input=sys.stdin.readline def inp(): return int(input()) def st(): return input().rstrip('\n') def lis(): return list(map(int,input().split())) def ma(): return ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; long long int mod(long long int x) { if (x >= 0) { return x; } return -x; } vector<int> decToBinary(int n) { vector<int> binaryNum(32, 0); int i = 0; while (n > 0) { binaryNum[i] = n % 2; n = n / 2; i++; } return binaryNum; } void solve(vecto...
8
CPP
from collections import * from functools import * import math import sys # sys.stdin = open("Desktop//ip.txt",'r') # sys.stdout = open("Desktop//op.txt",'w') inp = sys.stdin.readline out = sys.stdout.write def mi(): return map(int,inp().split()) def li(): return list(mi()) def ii(): return int(inp()) ...
8
PYTHON3