solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; bool db = false; const long long INF = 1e18 + 100; const long long MOD = 1e9 + 7; const long long maxn = 2 * 1e6 + 1; long long t, n, m, x, k, q; long long a, b, c, d; pair<long long, long long> pa, pb, pc, pd; long long ans = 0; string s[200]; vector<pair<long long, long l...
8
CPP
#include <bits/stdc++.h> using namespace std; bool check(vector<vector<int>> &a, int n, int x) { deque<pair<int, int>> q; map<pair<int, int>, bool> was; q.push_back({1, 1}); was[{1, 1}] = true; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; while (!q.empty()) { auto u = q.front(); q.pop_front...
8
CPP
t = int(input()) for _ in range(t): n = int(input()) field = [list(input()) for _ in range(n)] s = (int(field[0][1]), int(field[1][0])) f = (int(field[n-1][-2]), int(field[n-2][-1])) ans = 0 coords = [] if len(set(s)) == 1: if s[0] == f[0]: ans += 1 coords....
8
PYTHON3
from bisect import * from collections import * from math import * from heapq import * from typing import List from itertools import * from operator import * from functools import * #------------------------------------------------------------------------ import os import sys from io import BytesIO, IOBase # region fas...
8
PYTHON3
for _ in range(int(input())): n=int(input()) ar=[] for i in range(n): ar.append(list(input())) st=[int(ar[0][1]),int(ar[1][0])] fi=[int(ar[n-1][n-2]),int(ar[n-2][n-1])] ans=[] if(st[0]!=st[1] and fi[0]!=fi[1]): if(st[0]!=0): ans.append([1,2]) if(st[1]!=0):...
8
PYTHON3
from sys import stdin,stdout # def valid(x,y): # return 0<=x<n and 0<=y<n # def fn(x,y,dig): # global ans # vis[x][y]=1 # if a[x][y]=='F':return True # for xx,yy in zip([1,-1,0,0],[0,0,1,-1]): # if valid(x+xx,y+yy) and not vis[x+xx][y+yy] and (a[x+xx][y+yy] in ['F',dig]): # # if ...
8
PYTHON3
import sys input = sys.stdin.readline for f in range(int(input())): n=int(input()) grid=[] for i in range(n): line=input() line=line[0:n] grid.append(line) if grid[0][1]==grid[1][0]: c=0 cs=[] if grid[-1][-2]==grid[0][1]: c+=1 cs.ap...
8
PYTHON3
import math t = int(input()) for _ in range(t): n = int(input()) grid = [] for i in range(n): grid.append(list(input())) cnt1 = 0 ans1 = [] cnt2 = 0 ans2 = [] for i in range(3): if grid[n-1-i][n-3+i]!='0': cnt1 += 1 ans1.append((n-i,n-2+i)) for i in range(2): if grid[n-1-i][n-2+i]!='1': c...
8
PYTHON3
def solve(): # put code here n=int(input()) mat=[] for _ in range(n): mat.append(input()) if (mat[0][1] != mat[1][0] and mat[n-2][n-1] != mat[n-1][n-2]): print(2) if mat[0][1]=='0': print(1,2) else: print(2,1) if mat[n-2][n-...
8
PYTHON3
i = int(input()) for _ in range(i): ii = int(input()) lz = [] for _ in range(ii): lz.append(list(input())) scor = [lz[0][1], lz[1][0]] lcor = [lz[-2][-1], lz[-1][-2]] zer = scor.count('0') zer += lcor.count('0') if zer == 1: print(1) if scor[0] == '0': print('2 1') elif scor[1] ==...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long int INF = 2e18; const long long int N = 2e5 + 5; bool isPrime(long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long int i = 5; i * i <= n; i = i + 6) { if (n % i == 0 || n...
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int t, n, i, j, c; char chr; cin >> t; bool first_diag, second_diag; while (t--) { cin >> n; string arr[n]; vector<int> v; c = 0; for (i = 0; i < n; i++) cin >> arr[i]; first_diag = (arr[0][1] == arr[1][0]); second_diag = (...
8
CPP
for _ in range(int(input())): n = int(input()) s = [] for __ in range(n): s.append([int(x) for x in input() if x.isdigit()]) s[0].insert(0,0) s[n-1].insert(n-1,0) c = 0 ans = [] if s[0][1] and s[1][0]: if s[n-1][n-2]: c += 1 ans.append([n,n...
8
PYTHON3
cases = int(input()) for c in range(cases): n = int(input()) mat = [] for i in range(n): row = input() mat.append(row) r0c1 = mat[0][1] r1c0 = mat[1][0] rncp = mat[n-1][n-2] rpcn = mat[n-2][n-1] if r0c1 == r1c0: changes = [] if rncp == r0c1: c...
8
PYTHON3
from sys import stdin input = stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = [list(input().rstrip()) for _ in range(n)] ans = [] if a[0][1] == a[1][0]: if a[-1][-2] == a[0][1]: ans.append((n, n-1)) if a[-2][-1] == a[0][1]: ans.append((n-1...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; long long int n; vector<string> a; void input() { a.clear(); cin >> n; for (int i = 0; i < n; i++) { string k; cin >> k; a.push_back(k); } } void solve() { long long int z = 0, o = 0; if (a[0][1] == '0') z++; else o++; if (a[1][0] == '0')...
8
CPP
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double pii = 2 * pi; const double eps = 1e-6; const long long MOD = 1e9 + 7; vector<pair<int, int>> del{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; bool dfsf(int n, vector<string>& g) { vector<vector<bool>> v(n, vector<bool>(n, true)); queue<p...
8
CPP
#include <bits/stdc++.h> using namespace std; long long maxi = LLONG_MAX; long long mini = LLONG_MIN; 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 a[n][n]; for (long long i = 0; i < n; i...
8
CPP
#Consistency is the key. #code by: amritanshu from sys import stdin,stdout import math from collections import deque input=stdin.readline def print(*args,end='\n'): s=[] for i in args: s.append(str(i)+' ') s=''.join(s) stdout.write(s+end) def solve(): n=int(input()) mat=[] for i in...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long maxN = 1e18; const long long minN = -1e18; const int INF = 2e9; const long long MOD = 1e9 + 7; const long long MOD1 = 998244353; const int baseHash = 331; const int bigNumLength = 5000; const long double PI = acos(-1); const long long limit = 2e5 + 5; const ...
8
CPP
def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) ])) def invr(): return(map(int,input().split())) n = inp() for _ in range(n): x = inp() l = [] for j in range(x): l.append(insr()) #print(l) ...
8
PYTHON3
for _ in range(int(input())): n = int(input()) a = [input() for i in range(n)] a1 = [] a2 = [] if a[0][1]!='0': a1.append([0,1]) if a[1][0]!='0': a1.append([1,0]) if a[n-1][n-2]!='1': a1.append([n-1,n-2]) if a[n-2][n-1]!='1': a1.append([n-2,n-1]) if a[0][1]!='1': a2.append([0,1]) if a[1][0]!='1': ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int t, n; char s[207][207]; int main() { cin >> t; while (t--) { cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> s[i][j]; } } int cnt0 = 0, cnt1 = 0; if (s[1][2] == '0') { cnt0++; } else { ...
8
CPP
for _ in range(int(input())): n = int(input()) s = [input() for i in range(n)] ans = [] if s[0][2] == s[1][1] == s[2][0]: if s[0][1] == s[0][2]: ans += ['1 2'] if s[1][0] == s[0][2]: ans += ['2 1'] else: ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; char s[205][205]; int main() { long long a, b, t, n, m, i, j; cin >> t; while (t--) { cin >> n; cin.get(); for (i = 0; i <= n; i++) for (j = 0; j <= n; j++) s[i][j] = '0'; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) cin >> s[i][j]; ...
8
CPP
""" n=int(z()) for _ in range(int(z())): x=int(z()) l=list(map(int,z().split())) n=int(z()) l=sorted(list(map(int,z().split())))[::-1] a,b=map(int,z().split()) l=set(map(int,z().split())) led=(6,2,5,5,4,5,6,3,7,6) vowel={'a':0,'e':0,'i':0,'o':0,'u':0} color4=["G", "GB", "YGB", "YGBI", "OYGBI" ,"OY...
8
PYTHON3
import math import sys import collections import bisect #sys.setrecursionlimit(1000000000) input = sys.stdin.readline flush = sys.stdout.flush readint =lambda: int(input()) readintm =lambda: map(int,input().strip().split()) readintl =lambda: list(map(int,input().strip().split())) readfloatm =lambda: map(floa...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; template <class A> void read(vector<A>& v); template <class T> void read(T& x) { cin >> x; } void read(double& d) { string t; read(t); d = stod(t); } void read(long double& d) { string t; read(t); d = stold(t); } template <class H, class... T> void read(H& h, ...
8
CPP
import sys import math import random from typing import List # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') input = sys.stdin.readline class Cell: def __init__(self, a, row, col): self.a = a self.row = row self.col = col def value(self): return self.a[self.row][self.col] de...
8
PYTHON3
from sys import stdin, stdout import math,sys,heapq from itertools import permutations, combinations from collections import defaultdict,deque,OrderedDict from os import path import random import bisect as bi def yes():print('YES') def no():print('NO') if (path.exists('input.txt')): #------------------Sublime-----...
8
PYTHON3
from collections import Counter import math import sys from bisect import bisect,bisect_left,bisect_right from itertools import permutations def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else ...
8
PYTHON3
t=int(input()) for _ in range(t): n=int(input()) g=[] for i in range(n): g.append(input()) a,b,c,d=g[0][1],g[1][0],g[n-1][n-2],g[n-2][n-1] if a==b and c==d and a!=c: print(0) elif a==b and c!=d: print(1) if c==a: print(n,n-1) elif d==a: ...
8
PYTHON3
for _ in range(int(input())): n = int(input()) arr = [list(input()) for i in range(n)] t = [] s = [arr[0][1],arr[1][0]] f = [arr[-1][-2],arr[-2][-1]] if f[0]==f[1]: if f[0]=='0': if s[0]=='0': t.append([1,2]) if s[1]=='0': t.append([2,1]) else: if s[0]=='1': t.append([1,2]) if s[1]=='1...
8
PYTHON3
import re import sys exit=sys.exit from bisect import bisect_left as bsl,bisect_right as bsr from collections import Counter,defaultdict as ddict,deque from functools import lru_cache cache=lru_cache(None) from heapq import * from itertools import * from math import inf from pprint import pprint as pp enum=enumerate ri...
8
PYTHON3
for _ in range(int(input())): n = int(input()) grid = [input() for i in range(n)] moves = [] def set_to(i, j, val): if grid[i][j] != val: moves.append((i+1,j+1)) def other(x): return '0' if x=='1' else '1' if grid[0][1] == grid[1][0]: for i,j in [(n-2,n-1),(n-1,n-2)]: set_to(i,j,other(grid[0][1])) ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100001; const int MAX_D = 17; const long long MOD = 1000000007; const int INF32 = 0x3f3f3f3f; const long long INF = 1e18; void solve() { int n; cin >> n; char grid[n][n]; for (int i = (0); i < (n); i++) for (int j = (0); j < (n); j++) cin >> gr...
8
CPP
from collections import deque, defaultdict for _ in range(int(input())): n = int(input()) mat = [[]] for i in range(n): a = [0]+list(input().strip()) mat.append(a) one = [mat[1][2], mat[2][1]] two = [mat[n][n-1], mat[n-1][n]] if len(set(one+two))==1: print(2) prin...
8
PYTHON3
import os import sys from io import BytesIO, IOBase _str = str BUFSIZE = 8192 def str(x=b''): return x if type(x) is bytes else _str(x).encode() class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in ...
8
PYTHON3
#!/usr/bin/env pypy3 def ans(N, grid): grid = [list(row) for row in grid] a = grid[0][1] b = grid[1][0] c = grid[N-2][N-1] d = grid[N-1][N-2] a = int(a) b = int(b) c = int(c) d = int(d) def flipa(): grid[0][1] = 1-a print(1, 2) def flipb(): grid[1]...
8
PYTHON3
t = int(input()) for i in range(t): n = int(input()) r = [] for j in range(n): temp = input() r.append(temp) s1, s2 = int(r[0][1]), int(r[1][0]) f1, f2 = int(r[-1][-2]), int(r[-2][-1]) if s1 == s2 and f1 == f2: if s1 != f1: print(0) else: p...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; using LL = long long; inline void solve() { 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]; } } bool top = false; bool bottom = false; if (A[1][0] == A[0][1]) { top = true; } if...
8
CPP
import math for _ in range(int(input())): n=int(input()) s=[] for i in range(n): l=input() s.append(l) if (s[0][1]=='1' and s[1][0]=='1' and s[n-1][n-2]=='0' and s[n-2][n-1]=='0' ) or (s[0][1]=='0' and s[1][0]=='0' and s[n-1][n-2]=='1' and s[n-2][n-1]=='1' ): #print(1) ...
8
PYTHON3
import math t=int(input()) for w in range(t): n=int(input()) l=[] for i in range(n): l.append(list(input())) c=0 l1=[] if(l[0][1]=='0' and l[1][0]=='0'): if(l[-1][-2]=='0'): c+=1 l1.append((n,n-1)) if(l[-2][-1]=='0'): c+=1 l...
8
PYTHON3
test_count = int(input()) tests = [] for _ in range(test_count): x = int(input()) y = [] for _ in range(x): y.append(list(input())) tests.append((x, y)) for test in tests: size, grid = test start_right = int(grid[0][1]) start_down = int(grid[1][0]) end_up = int(grid[size - 2]...
8
PYTHON3
def main(): t = int(input()) for i in range(t): n = int(input()) matrix = [input() for i in range(n)] c1, c2, c3, c4 = int(matrix[0][1]), int(matrix[1][0]), int(matrix[n-1][n-2]), \ int(matrix[n-2][n-1]) answer = [] if c1 == c2: if c3 == c1...
8
PYTHON3
t=int(input()) for _ in range(t): n=int(input()) imp=[] for i in range(n): temp=input() if(i==0): imp.append(temp[1]) imp.append(temp[2]) elif(i==1): imp.append(temp[0]) imp.append(temp[1]) elif(i==2): imp.append(temp[0]) count=0 ans=[] if(imp[0]!='0'): ans.append([1,2]) count+=1 if(im...
8
PYTHON3
from sys import stdin, stdout n=int(stdin.readline()) for i in range(n): arr=[] b=int(stdin.readline()) for _ in range(b): arr.append(stdin.readline()) count1s=(arr[0][1])+(arr[1][0]) count2s=(arr[b-1][b-2])+(arr[b-2][b-1]) noms=0 cod=[] if count1s=='00': if count2s[0]=='0': noms+=1 cod.append([b,b-1...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; char s[n + 1][n + 1]; for (int i = 1; i <= n; ++i) cin >> s[i] + 1; vector<pair<int, int>> ans; if (s[1][2] == s[2][1]) { if (s[n][n - 1] == s[1][2]) ans.push_back(pair<int, int...
8
CPP
# cook your dish here # cook your dish here #from functools import reduce #mod=int(1e9+7) #import resource #resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY]) #import threading #threading.stack_size(2**26) """fact=[1] #for i in range(1,100001): # fact.append((fact[-1]*i)%mod) #ifact=[0...
8
PYTHON3
for _ in range(int(input())): n=int(input()) l=[] for i in range(n): t=list(input()) l.append(t) if l[0][1]=='0' and l[1][0]=='0': c=0 out=[] if l[n-1][n-2]=='0': c+=1 out.append((n,n-1)) if l[n-2][n-1]=='0': c+=1 out.append((n-1,n)) print(c) for i in out: print(i[0],i[1]) elif l[0][...
8
PYTHON3
t=int(input()) while(t>0): n=int(input()) l=[[] for x in range(n)] for x in range(0,n): a=list(input()) l[x].extend(a) l1=list(l) v1=l[0][1] v2=l[1][0] w1=l[n-1][n-2] w2=l[n-2][n-1] ans=0 a=[] if((v1=='0' and v2=='0') and (w1=='1' and w2=='1')): an...
8
PYTHON3
for _ in range(int(input())): n = int(input()) mat = [] for i in range(n): s = list(map(str,input().split())) slist = [j for j in s[0]] mat.append(slist) #for 0 a,b,c,d = mat[0][1],mat[1][0],mat[n-2][n-1],mat[n-1][n-2] ai,bi,ci,di = [1,2],[2,1],[n-1,n],[n,n-1] if a =...
8
PYTHON3
t = int(input()) for _ in range(t): n = int(input()) tab = list() for i in range(n): s = str(input()) tab.append(s) if tab[0][1] == tab[1][0] and tab[0][1] == '1': if tab[n-1][n-2] == tab[n-2][n-1]: if tab[n-1][n-2] == '1': print(2) pri...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int main() { int t; cin >> t; while (t--) { int n; cin >> n; char fi[n][n]; for (int i = 0; i < (n); ++i) { for (int j = 0; j < (n); ++j) { cin >> fi[i][j]; } } int a = fi[0][1] - '0'; int b =...
8
CPP
import sys input = lambda :sys.stdin.readline().rstrip() from math import log for _ in range(int(input())): n=int(input()) a=[input() for _ in range(n)] ans = [] if a[0][1] == a[1][0]: if a[n-1][n-2]==a[n-2][n-1]: if a[n-1][n-2] == a[0][1]: ans.append([n-1,n]) ...
8
PYTHON3
t = int(input()) while t > 0: n = int(input()) mat = [input() for i in range(n)] ans = [] if mat[0][1] == mat[1][0]: if mat[n-1][n-2] == mat[0][1]: ans.append([n-1, n-2]) if mat[n-2][n-1] == mat[0][1]: ans.append([n-2, n-1]) elif mat[n-1][n-2] == mat[n-2][n-1]...
8
PYTHON3
for i in range(int(input())): n=int(input()) l=[] for i in range(n): ll=input() if i==0: a=int(ll[1]) elif i==1: b=int(ll[0]) if i==n-2: c=int(ll[n-1]) elif i==n-1: d=int(ll[n-2]) # print(a,b,c,d) if a!=b and c!...
8
PYTHON3
from math import * from sys import * t=int(stdin.readline()) for _ in range(t): n=int(stdin.readline()) m = [] ans=[] for i in range(n): a = list(input()) m.append(a) x=m[0][1] a=0 f=0 if m[n-1][n-2]==x and m[n-2][n-1]==x: a+=1 ans.append([1,2]) if...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long T = 1; cin >> T; while (T--) { 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];...
8
CPP
#include <bits/stdc++.h> using namespace std; void solve() { long long n = 0; cin >> n; vector<vector<long long>> arr(n, vector<long long>(n)); for (long long i = 0; i < n; i++) { string s; cin >> s; for (long long j = 0; j < n; j++) { for (long long j = 0; j < n; j++) arr[i][j] = s[j] - '0'; ...
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { 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]; } } vector<pair<int, int>> vec; if (arr[0][1] == arr[1][0]) { ...
8
CPP
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int T; int n, i, j; char num[300][300]; cin >> T; while (T--) { cin >> n; for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { cin >> num[i][j]; } } int cnt = 0; cnt = num[2][1] + num[1][2...
8
CPP
for _ in range(int(input())): n=int(input()) grid=[[None]*n]*n c=0 changed=[] for i in range(n): grid[i]=list(input()) if grid[0][1]==grid[1][0]: a=grid[0][1] if grid[n-1][n-2]==a: c+=1 changed.append([n,n-1]) if grid[n-2][n-1]==a: ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000002; const int MOD2 = 998244353; const int MOD = 1000000007; const int INF = 1e8; const long double EPS = 1e-7; long long int mul(long long int x, long long int y) { return (x * 1ll * y) % MOD; } long long int fastpow(long long int x, long long int y)...
8
CPP
def solve(): n = int(input()) d = [list(input()) for i in range(n)] cnt1 = 0 que1 = [] if d[0][1] != "1": cnt1 += 1 que1.append((1, 2)) if d[1][0] != "1": cnt1 += 1 que1.append((2, 1)) if d[-2][-1] != "0": cnt1 += 1 que1.append((n-1, n)) if...
8
PYTHON3
import os import sys from io import BytesIO, IOBase # 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.wri...
8
PYTHON3
t = int(input()) # for _ in range(t): n = int(input()) arr = [] for _ in range(n): arr.append(input()) topright = int(arr[0][1]) topbtm = int(arr[1][0]) btmup = int(arr[-2][-1]) btmleft = int(arr[-1][-2]) if topright == 0 and topbtm == 0: if btmup == 0 and btmleft == 0: ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; cin >> t; while (t--) { int n, m, i, x = 0, y, z; cin >> n; string s[n + 1]; for (int i = 0; i < n; i++) cin >> s[i]; vector<pair<int, int>> v; if (s...
8
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9 + 7; ll fac[1000001]; void pre() { fac[0] = fac[1] = 1; for (int i = 2; i <= 1000001; i++) { fac[i] = (fac[i - 1] * 1LL * i) % mod; } } ll binpower(ll a, ll n) { ll res = 1; while (n) { if (n % 2) res = (res * 1LL *...
8
CPP
for _ in range(int(input())): n = int(input()) mat = [] for i in range(n): mat.append(list(map(str,input()))) ans = [] tl = [[0,1],[1,0]] tr = [[n-1,n-2],[n-2,n-1]] if mat[tl[0][0]][tl[0][1]]==mat[tl[1][0]][tl[1][1]]: x = int(mat[tl[0][0]][tl[0][1]])^1 x = str(x) ...
8
PYTHON3
import sys tests = int(sys.stdin.readline()) for i in range(tests): msize = int(sys.stdin.readline()) matrix = [] for j in range(msize): line = sys.stdin.readline().strip() matrix.append(line) changes = [] # Check parts surrounding S and F sr = int(matrix[0][1]) sd = int(matrix[1][0]) fl = int(matrix[msiz...
8
PYTHON3
T, = map(int, input().split()) for _ in range(T): N, = map(int, input().split()) X=[] for _ in range(N): X.append(input().strip()) a,b=int(X[0][1]),int(X[1][0]) c,d=int(X[-1][-2]),int(X[-2][-1]) if (a,b,c,d)==(1,1,0,0): print(0) if (a,b,c,d)==(0,0,1,1): print(0) i...
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(ce...
8
PYTHON3
def problem_sol(n, arr_field): num_changes = 0 sol_list = [] s_right = int(arr_field[0][1]) s_down = int(arr_field[1][0]) f_left = int(arr_field[n - 1][n - 2]) f_up = int(arr_field[n - 2][n - 1]) if f_left == f_up: if f_left == s_right: sol_list.append('1 2') ...
8
PYTHON3
t=int(input()) for i in range(t): n=int(input()) a=[] an=[] for j in range(n): a.append(input().strip()) p,q=int(a[0][1]),int(a[1][0]) r,s=int(a[-1][-2]),int(a[-2][-1]) if r==s: pt=r^1 if p!=pt: an.append((1,2)) if q!=pt: an.append((2,1...
8
PYTHON3
t = int(input()) while t: t -= 1 n = int (input()) a= [] for i in range (n): line = list (input()) #line = [int(x) for x in line if x not in {'S', 'F'} else x] a.append (line) #a,b,c,d = cells which over start and finish points x, y, z, w = a[0][1], a[1][0], a[...
8
PYTHON3
import sys from array import array # noqa: F401 import typing as Tp # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') def output(*args): sys.stdout.buffer.write( ('\n'.join(map(str, args)) + '\n').encode('utf-8') ) def main(): t = int(input()) ans_a = [''] ...
8
PYTHON3
#include <bits/stdc++.h> #pragma GCC optimize("-Ofast") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-funroll-loops") using namespace std; using ll = long long; using ld = long double; const int N = 2e5 + 7, mod = ...
8
CPP
for _ in range(int(input())): n = int(input()) a = [] s = "" for i in range(n): a.append(input()) if i == 0: s += a[i][1] + a[i][2] if i == 1: s += a[i][0] + a[i][1] if i == 2: s += a[i][0] count = 0 x = "01011" y = "1010...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t, n, i, j, y, ans; string s; char ch; cin >> t; while (t--) { cin >> n; vector<int> a(4); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { c...
8
CPP
t=int(input()) for i in range(0,t): n=int(input()) sl1=sl2=cz=0 for j in range(1,n+1): w=input() if(j==n-2): a=w[n-1] if(a=='1'): sl1+=1 if(j==n-1): b=w[n-2] if(b=='1'): sl1+=1 e=w[n-1] if(e=='1'): sl2+=1 ...
8
PYTHON3
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase #from bisect import bisect_left as bl #c++ lowerbound bl(array,element) #from bisect import bisect_right as br #c++ upperbound br(array,element) def main(): for _ in range(int(input())): n=int(input())...
8
PYTHON3
t = int(input()) for _ in range(t): mat = [] n = int(input()) for _ in range(n): mat.append(input()) start1 = mat[0][1] start2 = mat[1][0] end1 = mat[n-1][n-2] end2 = mat[n-2][n-1] # if start1 == '0' and start2 == '0': # if end1 == '1' and end2 == '1': # prin...
8
PYTHON3
import sys for i in range(0,int(sys.stdin.readline())): msize=int(sys.stdin.readline()) for j in range(0,msize): q=sys.stdin.readline() if j==0: a=int(q[1]) elif j==1: b=int(q[0]) if j==msize-2: c=int(q[msize-1]) elif j==msize-1: d=int(q[msize-2]) if a==b: i...
8
PYTHON3
for t in range(int(input())): n=int(input()) arr=[] for i in range(n): row=list(input()) arr.append(row) d1=[int(arr[1][0]),int(arr[0][1])] d2=[int(arr[n-1][n-2]),int(arr[n-2][n-1])] if d1==[0,0]: if d2==[0,0]: print(2) print(2,1) print...
8
PYTHON3
for _ in range(int(input())): n = int(input()) A = [] for _ in range(n): A.append(input()) cnt = 0 ans = [] if A[0][1] == A[1][0]: cur = A[0][1] if A[-1][-2] == cur: cnt += 1 ans.append([n, n - 1]) if A[-2][-1] == cur: cnt += 1 ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { long long int n, p, i, c, d, e, f, q = 0, r = 0, l = 0, m = 0; cin >> n; p = n * n; for (i = 0; i < p; i++) { char s; cin >> ...
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tests; cin >> tests; while (tests--) { int n; cin >> n; vector<vector<char>> t(n); char c; for (auto& i : t) { for (int j = 0; j < n; ++j) { cin >> c; ...
8
CPP
import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return list(map(int,input().split())) def main(): ...
8
PYTHON3
t=int(input()) for x in range (t): n=int(input()) a=[] for i in range (n): a.append(input()) if a[1][0]==a[0][1] and a[n-1][n-2]!=a[n-2][n-1]: print(1) if a[1][0]==a[n-1][n-2]: print(n,n-1) else: print(n-1,n) elif a[1][0]!=a[0][1] and a[n-1...
8
PYTHON3
t = int(input()) while t: t-=1 n = int(input()) a = [] for i in range(n): a.append(input()) ans = [] if a[0][1] == "0" and a[1][0] == "0": if a[n-1][n-2] == "1" and a[n-2][n-1] == "1": pass elif a[n-1][n-2] == "0" and a[n-2][n-1] == "0": ans.append([0,1]) ans.append([1,0]) elif (a[n-1][n-2] == "0...
8
PYTHON3
#import sys # import math # import bisect # import collections # import itertools # #from sys import stdin,stdout # from math import gcd,floor,sqrt,log from collections import Counter as ctr # from bisect import bisect_left as bl, bisect_right as br # from itertools import permutations as pr, combinations as cb #sys....
8
PYTHON3
import math,sys from sys import stdin,stdout from collections import Counter, defaultdict, deque input = stdin.readline I = lambda:int(input()) li = lambda:list(map(int,input().split())) def solve(): n=I() a=[] for i in range(n): a.append(input().strip()) p=a[0][1] q=a[1][0] r=a[n-1][n-...
8
PYTHON3
for _ in range(int(input())): n = int(input()) g = [input() for _ in range(n)] x1 = g[0][1] + g[1][0] x2 = g[-1][-2] + g[-2][-1] if x1[0] == x1[1] == x2[0] == x2[1]: print(2) print(1, 2) print(2, 1) continue if (x1[0] != x2[0]) == (x1[1] != x2[1]): if x...
8
PYTHON3
T=int(input()) for z in range(T): n=int(input()) l=list() for i in range(n): s=input() l.append(s) det1=(l[n-1][n-3]+l[n-2][n-2]+l[n-3][n-1]) det2=(l[n-1][n-2]+l[n-2][n-1]) if det2=="11": if det1=="111": print(2) print(n-1,n) print...
8
PYTHON3
t = int(input()) for i in range(t): n = int(input()) arr = [] for i in range(n): temp = list(input()) arr.append(temp) res = [] cnt = 0 if arr[0][1]=='0' and arr[1][0]=='0': if arr[n-1][n-2] == '0': cnt += 1 res.append([n,n-1]) if arr[n-2][...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int testcase; cin >> testcase; for (int i = 0; i < testcase; i++) { int size; cin >> size; char map[size][size]; for (int j = 0; j < size; j++) { for (int k = 0; k < size; k++) { cin >> map[j][k]; } } char start...
8
CPP
r = int(input()) for t in range(r): n = int(input()) mas = [[x for x in input()] for i in range(n)] sright = mas[0][1] sbottom = mas[1][0] fleft = mas[-1][-2] ftop = mas[-2][-1] if sright == sbottom and fleft == ftop and sright != fleft: print(0) elif sright == sbottom: i...
8
PYTHON3
for _ in range(int(input())): n = int(input()) a = [] for i in range(n): d = list(input()) a.append(d) c = 0 if a[0][1] == a[1][0]: if a[n - 1][n - 2] == a[0][1]: c += 1 if a[n - 2][n - 1] == a[0][1]: c += 1 print(c) ...
8
PYTHON3
import sys from collections import deque from itertools import product from copy import deepcopy sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): def bfs(num): que = deque([[0, 0]]) visited = [[False] * n for _ in range(n)] vi...
8
PYTHON3