solution stringlengths 11 983k | difficulty int64 0 21 | language stringclasses 2
values |
|---|---|---|
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast", "no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long int exp(long l... | 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
void testCase() {
long long n;
cin >> n;
vector<string> grid(n);
vector<pair<long long, long long>> ans;
for (string &s : grid) cin >> s;
char t1 = grid[0][1];
char t2 = grid[1][0];
char b1 = grid[n - 1][n - 2];
char b2 = grid[n - 2][n - 1];
if (t1 == t2... | 8 | CPP |
for j in range(int(input())):
n=int(input())
a=[list(input()) for i in range(n)]
t=a[0][1]
r=a[1][0]
w=a[-1][-2]
y=a[-2][-1]
d=[]
if t==r=='1':
if w=='1':
d.append([n,n-1])
if y=='1':
d.append([n-1,n])
elif t==r=='0':
if w=='0':
... | 8 | PYTHON3 |
for _ in range(int(input())):
n=int(input())
l=[]
for i in range(n):
s=str(input())
l.append(s)
a=int(l[0][1])
b=int(l[1][0])
c=int(l[n-1][n-2])
d=int(l[n-2][n-1])
if(a==0 and b==0):
if(c==1 and d==1):
print(0)
elif(c==1 and d==0):
print(1)
print(n-1,n)
elif(c==0 and d==1):
print(1)
pri... | 8 | PYTHON3 |
for _ in range(int(input())):
ls =[]
n = int(input())
for i in range(n):
ls.append(input())
a = ls[0][1]; b = ls[1][0]; c = ls[n-2][n-1]; d= ls[n-1][n-2]
ans =[]
f=1
if a==b :
if a==c:
ans.append([n-1 , n])
if a==d:
ans.append([n, n-1]... | 8 | PYTHON3 |
# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import ... | 8 | PYTHON3 |
import sys
t = int(sys.stdin.readline())
for _ in range(t):
n = int(sys.stdin.readline())
A = []
for _ in range(n):
A.append(sys.stdin.readline().strip())
a = A[0][1]
b = A[1][0]
c = A[-1][-2]
d = A[-2][-1]
cells = []
if a == b:
if c == a:
cells.append... | 8 | PYTHON3 |
for _ in range(int(input())):
n = int(input())
grid = []
count = 0
ans = []
for i in range(n):
grid.append(list(input()))
if grid[0][1]=='0' and grid[1][0]=='0':
if grid[n-2][n-1]!='1':
count += 1
ans.append([n-1,n])
if grid[n-1][n-2]!='1':
... | 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),;m=b[0]>3or a[b.index(min(b))];r=[y for x,y in zip(a,('1 2','2 1',f'{n-1} {n}',f'{n} {n-1}'))if x==m];print(len(r),*r);") | 8 | PYTHON3 |
import sys
from itertools import permutations
from itertools import combinations
from itertools import combinations_with_replacement
#sys.stdin = open('/Users/pranjalkandhari/Desktop/Template/input.txt', 'r')
for _ in range( int(input()) ):
n = int(input())
a = ''
b = ''
c = ''
d = ''
for i in ... | 8 | PYTHON3 |
n = int(input())
for j in range(n):
n = int(input())
f=[]
for j in range(n):
l = input()
if n==3:
if j==0:
f.append(int(l[1]))
if j==1:
f.append(int(l[0]))
f.append(int(l[n-1]))
if j==n-... | 8 | PYTHON3 |
from collections import Counter
from collections import OrderedDict
from collections import defaultdict
def freq_count(mylist):
return Counter(mylist)
t=int(input())
for _ in range(t):
n=int(input())
#arr=[int(x) for x in input().split()]
#a,b=map(int,input().split())
#print(a^b)
grid=[list(inp... | 8 | PYTHON3 |
import sys
import math
from functools import reduce
import bisect
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def input():
return sys.stdin.readline().rstrip()
def index(a, x):
i = bisect.bisect_left(a,... | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
... | 8 | CPP |
"""
Code of Ayush Tiwari
Codeforces: servermonk
Codechef: ayush572000
"""
# import sys
# input = sys.stdin.buffer.readline
def solution():
# This is the main code
n=int(input())
l=[]
for i in range(n):
a=list(input())
l.append(a)
ans=[]
if l[1][0]==l[0][1]:
if l[n-... | 8 | PYTHON3 |
#include <bits/stdc++.h>
const long double eps = 1e-8;
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t = 1;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int a[n + 1][n + 1];
string temp;
for (long long ... | 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int n = 0, f = 1, ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
n = n * 10 + ch - '0';
ch = getchar();
}
return n * f;
}
char s[305][305];
int main() {... | 8 | CPP |
from sys import stdin, stdout
from math import gcd
input = stdin.readline
for _ in range(int(input())):
n = int(input())
a = [input() for i in range(n)]
ans = [(i, j) for i, j in [(0, 1), (1, 0), (n - 2, n - 1), (n - 1, n - 2)] if (a[i][j] == '0') ^ (min(i, j) == 0)]
if len(ans) <= 2:
print(len... | 8 | PYTHON3 |
t=int(input())
for i in range(t):
n=int(input())
grid=[]
for j in range(n):
grid.append(input())
s1=grid[0][1]
s2=grid[1][0]
s3=grid[-2][-1]
s4=grid[-1][-2]
if s1==s2==s3==s4:
print(2)
print(1,2)
print(2,1)
elif s1==s2==s3:
print(1)
pr... | 8 | PYTHON3 |
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 19 16:36:57 2020
@author: lakne
"""
t = int(input())
answers = []
for _ in range(t):
n = int(input())
start = []
finish = []
answer = []
grids = []
c = 0
for i in range(n):
grid = input()
grids.append(grid)
start.append(grid... | 8 | PYTHON3 |
T = int( input() )
for t in range(T):
m = []
n = int( input() )
for i in range(n):
s = list( input() )
m.append(s)
#print(m)
p = [ m[1][0], m[0][1], m[n-2][n-1], m[n-1][n-2] ]
result = []
if p[0] == p[1]:
if p[2] == p[0]:
result.append(2)
if p[3] == p[0]:
result.append(3)
... | 8 | PYTHON3 |
t = int(input())
for case in range(t):
n = int(input())
grid = [input() for row in range(n)]
cnt = 0
ans = []
if grid[0][1] == grid[1][0]:
g = 1 - int(grid[0][1])
if int(grid[-1][-2]) != g:
ans.append((n, n - 1))
if int(grid[-2][-1]) != g:
ans.append((... | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, a[205][205];
char c;
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
cin >> c;
a[i][j] = c - '0';
}
if (a[1][2] == a[2][1]) {
if (a[n - 1][n]... | 8 | CPP |
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c for j in range(b)] for i in range(a)]
def list3d(a, b, c, d): return [[[d for k in range(c)] for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e for l in range(d)] for k in range(c)] for j in range(b)]... | 8 | PYTHON3 |
# Author : devil9614 - Sujan Mukherjee
from __future__ import division, print_function
import os,sys
import math
import collections
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
class my_diction... | 8 | PYTHON3 |
for _ in range (int(input())):
n = int(input())
grid = []
for i in range (n):
grid.append(list(input()))
s1 = grid[0][1]
s2 = grid[1][0]
e1 = grid[n-2][n-1]
e2 = grid[n-1][n-2]
ans = []
if s1 == s2:
if e1 == s1:
ans.append([n-1,n])
if e2 == s2:
... | 8 | PYTHON3 |
for _ in range(int(input())):
ans = 0
ind = [[0] * 2 for i in range(4)]
n = int(input())
s = [input() for i in range(n)]
#0011
if s[1][0] == '1':
ans += 1
ind[0][0] = 2
ind[0][1] = 1
if s[0][1] == '1':
ans += 1
ind[1][0] = 1
ind[1][1] = 2
i... | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void edit(vector<int> &skill, int n) {
for (int i = 0; i < n; i++) {
int x;
cin >> x;
skill.push_back(x);
}
}
void achilles() {
int n;
cin >> n;
char arr[n][n];
cin.ignore();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin... | 8 | CPP |
def main(input_f):
t = int(input_f())
for _ in range(t):
n = int(input_f())
cells = [list(input_f()) for _ in range(n)]
start_right, start_bottom = cells[0][1], cells[1][0]
finish_left, finish_top = cells[n - 1][n - 2], cells[n - 2][n - 1]
inverted_cells = []
if s... | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int solve() {
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) cin >> s[i];
if (s[0][1] == s[1][0] and s[n - 2][n - 1] == s[n - 1][n - 2] and
s[0][1] != s[n - 2][n - 1]) {
puts("0");
return 0;
}
if (s[0][1] == s[1][0]) {
if (s[n - 1]... | 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long Min(long long a, long long b) { return (a < b) ? a : b; }
long long Max(long long a, long long b) { return (a < b) ? b : a; }
long long gcd(long long m, long long n) {
if (n == 0) return m;
return gcd(n, m % n);
}
long long lcm(long long m, long long n) { retu... | 8 | CPP |
def getInverts(arr,N):
inverts = []
if arr[0][1] == arr[1][0]:
if arr[-1][-2] == arr[0][1]:
inverts.append([N-1,N-2])
if arr[-2][-1] == arr[0][1]:
inverts.append([N-2,N-1])
else:
if arr[-1][-2] == arr[-2][-1]:
if arr[0][1] == arr[-1][-2]:
... | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, sr, sl, eu, ele;
cin >> t;
while (t--) {
int n;
scanf("%d", &n);
getchar();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
char c = getchar();
if (i == 1 && j == 2) sr = c - '0';
if (i ==... | 8 | CPP |
for w in range(int(input())):
n=int(input())
l=[]
for i in range(n):
l.append(list(str(input())))
#print(l)
if(l[0][1]==l[1][0]):
if(l[n-1][n-2]==l[n-2][n-1]):
if(l[n-1][n-2]==l[0][1]):
print(2)
print(n,n-1)
print(n-1,n)
... | 8 | PYTHON3 |
for _ in range(int(input())):
n=int(input())
l=[input() for i in range(n)]
#print(l)
if l[0][1]==l[1][0]:
if l[-1][-2]==l[-2][-1]:
if l[-1][-2]!=l[1][0]:
print(0)
else:
print(2)
print(1,2)
print(2,1)
... | 8 | PYTHON3 |
t=int(input())
for i in range(t):
n=int(input())
m=[[i for i in input()] for i in range(n)]
#print(m)
q=int(m[1][0])
w=int(m[0][1])
a=int(m[-1][-2])
s=int(m[-2][-1])
e=n-1
if q == w:
if a == s:
if q == a:
print('2','\n','1 2','\n','2 1',sep='')
... | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
string s;
vector<string> v;
cin >> n;
for (int i = (0); i < int(n); i++) {
cin >> s;
v.push_back(s);
}
vector<pair<int, int> > ans;
if (v[0][1] == v[1][0]) {
if (v[n - 1][n - 2] == v[0][1]) ans.push_back({n - 1, n - 2});
... | 8 | CPP |
import sys
input = lambda: sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
n = int(input())
s = []
for _ in range(n):
s.append(input())
x0, x1, x2, x3 = int(s[0][1]), int(s[1][0]), int(s[-1][-2]), int(s[-2][-1])
ans = []
if x0==1:
ans.append((1, 2))
if x1==1... | 8 | PYTHON3 |
import sys
import math
from math import *
from collections import Counter,defaultdict,deque
from bisect import bisect_left
import random
lip = lambda : list(map(int, input().split()))
ip = lambda : int(input())
sip = lambda : input().split()
mod = 10**9+7
def main():
n = ip()
mat = []
for i in range... | 8 | PYTHON3 |
t = int(input())
for _ in range(0,t):
n = int(input())
s = []
for i in range(0,n):
ss = [k for k in input()]
s.append(ss)
ans = []
kk = [s[0][1],s[1][0],s[-2][-1],s[-1][-2]]
z,o = kk.count('0'),kk.count('1')
if z == 0 or o == 0:
ans.append([1,2])
ans.appe... | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
char mp[300][300];
int n;
void solve() {
int cnt = 0;
if ((mp[1][2] - '0') && (mp[2][1] - '0')) {
cnt = 0;
if (mp[n][n - 1] - '0') {
cnt++;
}
if (mp[n - 1][n] - '0') {
cnt++;
}
printf("%d\n", cnt);
if (mp[n][n - 1] - '0') {
... | 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
char s[205][205];
int main() {
int t, n;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
vector<pair<int, int>> ans[2];
ans[s[1][2] == '1'].push_back(make_pair(1, 2));
ans[s[2][1] == '1'].push_bac... | 8 | CPP |
def main():
n = int(input())
s1, s2, e1, e2 = 0, 0, 0, 0
for i in range(n):
row = input()
if i == 0:
s1 = row[1]
elif i == 1:
s2 = row[0]
if i + 2 == n:
e1 = row[n-1]
elif i + 1 == n:
e2 = row[n-2]
if s1 == s2:
... | 8 | PYTHON3 |
for _ in range(int(input())):
n = int(input())
x = []
for i in range(n):
x.append(list(input()))
if x[0][1] == x[1][0] and x[-1][-2] == x[-2][-1]:
if x[0][1] != x[-1][-2]:
print(0)
else:
print(2)
print(1, 2)
print(2, 1)
elif x[0... | 8 | PYTHON3 |
import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
except:
pass
# input = lambda: sys.stdin.buffer.readline().rstrip()
for _ in range(int(input(... | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long T, n, i, j;
long long S_0, S_1, F_0, F_1, count;
cin >> T;
while (T--) {
cin >> n;
string A[n];
for (i = 0; i < n; i++) {
cin >> A[i];
}
S_0 = 0;
S_1 = 0;
F... | 8 | CPP |
from sys import stdin
for _ in range(int(stdin.readline())):
side = int(stdin.readline())
board = []
for i in range(side):
board.append(stdin.readline().strip())
a = board[0][1]
b = board[1][0]
c = board[side-2][side-1]
d = board[side-1][side-2]
if a == b:
if a == "1":
... | 8 | PYTHON3 |
t = int(input())
for _ in range(t):
ans = []
final = []
n = int(input())
for i in range(n):
s = input()
lol = list(s)
ans.append(s)
a = ans[0][1]
b = ans[1][0]
x = ans[n-2][n-1]
y = ans[n-1][n-2]
#print(a,b,x,y)
if(b != '0'):
final.append... | 8 | PYTHON3 |
t=int(input())
for i in range(t):
n=int(input())
L=[]
for i in range(n):
ch=input()
L.append(ch)
I=[]
if (int(L[0][1])+int(L[1][0]))%2==0:
if L[n-1][n-2]==L[1][0]:
I.append((n,n-1))
if L[n-2][n-1]==L[1][0]:
I.append((n-1,n))
e... | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
char arr[n][n];
for (long long i = 0; i < n; i++)
for (long long j = 0; j < n; j++) cin >> arr[i][j];
bool f = f... | 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long T, N, M, ans, temp;
char m[200][2001];
int main(void) {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
cin >> T;
for (long long t = 1; t <= T; t++) {
cin >> N;
for (long long i = 0; i < N; i++) {
cin >> m[i];
}
vector<pai... | 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
string mp[210];
int n;
bool func(char x, char y) {
int res = (mp[1][0] == x) + (mp[0][1] == x) + (mp[n - 1][n - 2] == y) +
(mp[n - 2][n - 1] == y);
if (res <= 2) {
cout << res << "\n";
if (mp[1][0] != y)
cout << "2 1"
<< "\n";
if... | 8 | CPP |
for _ in range(int(input())):
a = []
for i in range(int(input())):
a.append(input())
if a[0][1] == "1" and a[1][0] == "1" and a[-1][-2] == "1" and a[-2][-1] == "1" or a[0][1] == "0" and a[1][0] == '0' and a[-1][-2] == "0" and a[-2][-1] == "0":
print(2)
print(1, 2)
print(2, 1)... | 8 | PYTHON3 |
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): ... | 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 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, o = 0, c = 0;
cin >> n;
vector<vector<char>> V(n, vector<char>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) cin >> V[i][j];
}
if (V[1][0] == V[0][1] && V[n - 1][n - 2] =... | 8 | CPP |
def solve(n, grid):
pos = []
if grid[0][1] == grid[1][0]:
if grid[n - 1][n - 2] == grid[0][1]:
pos.append((n - 1, n - 2))
if grid[n - 2][n - 1] == grid[0][1]:
pos.append((n - 2, n - 1))
elif grid[n - 1][n - 2] == grid[n - 2][n - 1]:
if grid[0][1] == grid[n - 1... | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, t;
char s[205][205];
int main() {
cin >> t;
int i, j, k;
while (t--) {
cin >> n;
for (i = 1; i <= n; ++i) {
cin >> (s[i] + 1);
}
int cnt = 0;
bool i1 = 0, i2 = 0;
if (s[1][2] == s[2][1]) {
if (s[n][n - 1] == s[1][2]) {
... | 8 | CPP |
for _ in range(int(input())):
n=int(input())
s=input()
c1=s[1]
s=input()
c2=s[0]
for i in range(max(n-4,0)):
s=input()
if n==3:
c3=s[n-1]
s=input()
c4=s[n-2]
else:
s=input()
c3=s[n-1]
s=input()
c4=s[n-2]
if c1==c2:
... | 8 | PYTHON3 |
test_cases = range(int(input()))
for test_case in test_cases:
n = int(input())
grid = []
for i in range(n):
new_line = [c for c in input()]
grid.append(new_line)
sr, sd = grid[0][1], grid[1][0]
fl, fu = grid[n-1][n-2], grid[n-2][n-1]
if sr == sd and fl == fu and s... | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
int n;
int list[201][201];
cin >> t;
while (t > 0) {
t--;
cin >> n;
char qwe;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if ((i == 0 && j == 0) || (i == (n - 1) && j == (n - 1))) {
cin >>... | 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
clock_t time_p = clock();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
char s[n + 1][n + 1];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) ... | 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 210;
char s[maxn][maxn];
bool vis[maxn][maxn];
int d[][2] = {1, 0, -1, 0, 0, 1, 0, -1};
int n;
bool dfs(int x, int y, char ch) {
for (int i = 0; i < 4; ++i) {
int nx = x + d[i][0], ny = y + d[i][1];
if (nx == n && ny == n) return 1;
if (nx < 1... | 8 | CPP |
for _ in range(int(input())):
n = int(input())
l = []
for i in range(n):
l.append(list(str(input())))
l2 = []
a1 = 0
a2 = 0
a3 = 0
a4 = 0
c = 0
a1+=2 - ((int(l[0][1])) + (int(l[1][0])))
a2+=((int(l[0][1])) + (int(l[1][0])))
a3 = 2 - ((int(l[n-1][n-2])) + (int(l[n-... | 8 | PYTHON3 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
template <typename T>
T min(T x, T y) {
return x < y ? x : y;
}
template <typename T>
T max(T x, T y) {
return x > y ? x : y;
};
const long long INF = 20000000050000;
const long long mod = 998244353;
const long long MAXN = 205;
int N;
char s[MAXN][MAXN];
void... | 8 | CPP |
import itertools
import sys
from typing import List
sys.setrecursionlimit(10 ** 9)
def lmi():
return list(map(int, input().split()))
def main():
for _ in range(int(input())):
n = int(input())
grid = [list(input()) for _ in range(n)]
result = solve(n, grid)
print(len(result))... | 8 | PYTHON3 |
from sys import *
input = stdin.readline
for _ in range(int(input())):
n = int(input())
matrix = []
for i in range(n):
a = []
s = input()
for em in s[:-1]:
if(em == 'S' or em == 'F'):
a.append(em)
else:
a.append(int(e... | 8 | PYTHON3 |
t=int(input())
for _ in range(t):
n=int(input())
l=[]
for i in range(n):
l.append(input())
if l[0][1]==l[1][0]:
if l[-2][-1]==l[-1][-2]:
if l[-2][-1]!=l[0][1]:
print(0)
else:
print(2)
print(n-1,n)
pri... | 8 | PYTHON3 |
#include <CodeforcesSolutions.h>
#include <ONLINE_JUDGE <solution.cf(contestID = "1421",questionID = "A",method = "GET")>.h>
"""
Author : thekushalghosh
Team : CodeDiggers
I prefer Python language over the C++ language :p :D
Visit my website : thekushalghosh.github.io
"""
import sys,math,cm... | 8 | PYTHON3 |
def flip(n):
if n=='0':
return '1'
else:
return '0'
def hi(a):
n = len(a)
c = 0
f = []
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]:
return c,[]
if a[0][1]==a[1][0]:
p = a[0][1]
if a[n-1][n-2]==p:
a[n-1][n-2] = flip(p)
c+=1
f.append([str(n),str(n-1)])
if a[n-2]... | 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;
cin >> t;
while (t--) {
int n;
cin >> n;
char ch[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) cin >> ch[i][j];
int co = 0;
pair<i... | 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
int a[N][N];
for (int i = 0; i < N; i++) {
string s;
cin >> s;
for (int j = 0; j < s.size(); j++) a[i][j] = s[j] - '0';
}
vector<pair<int, int>> targets;
targets... | 8 | CPP |
from collections import Counter,defaultdict
I =lambda:int(input())
M =lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))
for _ in range(I()):
n=I()
a=[]
for i in range(n):
s=input()
s=list(s)
a+=[s]
ans = []
if a[0][1] == a[1][0]:
x = a[0][1]
... | 8 | PYTHON3 |
import math as mt
import bisect
import sys
#input=sys.stdin.readline
t=int(input())
import collections
import heapq
#t=1
p=10**9+7
def ncr_util():
inv[0]=inv[1]=1
fact[0]=fact[1]=1
for i in range(2,300001):
inv[i]=(inv[i%p]*(p-p//i))%p
for i in range(1,300001):
inv[i]=(inv[i-1]*inv[i])%... | 8 | PYTHON3 |
t=int(input())
for _ in range(t):
n=int(input())
f=[]
for i in range(n):
f.append(str(input()))
a=f[1][0]
b=f[0][1]
c=f[-1][-2]
d=f[-2][-1]
if a==b:
if c==d:
if a!=c:
print(0)
else:
print(2)
pri... | 8 | PYTHON3 |
for _ in range(int(input())):
n = int(input())
a = []
for i in range(n):
x = input()
s = [i for i in x]
a.append(s)
if a[0][1] == a[1][0]:
if a[-1][-2] == a[-2][-1] == a[0][1]:
print(2)
print(n,n-1)
print(n-1,n)
elif a[0][1] == ... | 8 | PYTHON3 |
import sys
input=sys.stdin.readline
for _ in range(int(input())):
n=int(input())
# a,b=map(int,input().split())
# s=input().strip()
# a=list(map(int,input().split()))
g=[]
ans,ans1=[],[]
for i in range(n):g.append(input())
s1,s2=g[0][1],g[1][0]
e1,e2=g[n-1][n-2],g[n-2][n-1]
if s1==s2=='0':
if e1=='0':
an... | 8 | PYTHON3 |
for t in range(int(input())):
n=int(input())
mat=[]
for i in range(n):
mat.append(list(input()))
out=0
ans=[]
if mat[0][1]==mat[1][0]:
if mat[-1][-2]==mat[0][1]:
out+=1
ans.append([n,n-1])
if mat[n-2][n-1]==mat[0][1]:
out+=1
... | 8 | PYTHON3 |
import sys
import math
from collections import defaultdict,Counter
input=sys.stdin.readline
# def print(x):
# sys.stdout.write(str(x)+"\n")
# sys.stdout=open("CP2/output.txt",'w')
# sys.stdin=open("CP2/input.txt",'r')
# mod=pow(10,9)+7
t=int(input())
for i in range(t):
n=int(input())
for j in range(n):
s=inp... | 8 | PYTHON3 |
# import sys; input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**7)
from collections import defaultdict
mod = 10 ** 9 + 7; INF = float("inf")
def getlist():
return list(map(int, input().split()))
def main():
T = int(input())
for _ in range(T):
N = int(input())
L = []
for i in range(N):
l = list... | 8 | PYTHON3 |
for _ in range(int(input())):
n = int(input())
arr = [list(input()) for _ in range(n)]
res = []
if arr[n-2][n-1] == arr[n-1][n-2]:
if arr[0][1] == arr[n-2][n-1]:
res.append((1, 2))
if arr[1][0] == arr[n-2][n-1]:
res.append((2, 1))
elif arr[0][1] == arr[1][0]:
... | 8 | PYTHON3 |
t = int(input())
for _ in range(t):
n = int(input())
A = []
for _ in range(n):
A.append(input())
if A[0][1] == A[1][0] and A[-1][-2] == A[-2][-1]: # 4 cases
if A[0][1] != A[-1][-2]:
print(0)
else:
print(2)
print(1, 2)
print(2, 1)
... | 8 | PYTHON3 |
# your code goes here
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())
ansx=[]
if a[0][1]==a[1][0]:
v=a[0][1]
if a[-1][-2]==v:
ansx.append([n,n-1])
if a[-2][-1]==v:
ansx.append([n-1... | 8 | PYTHON3 |
def process():
n=int(input())
li=[]
for i in range(n):
li.append(list(input()))
ans=[]
if(li[0][1]!=li[1][0] and li[n-1][n-2]!=li[n-2][n-1]):
if(li[0][1]!='0'):
ans.append((0,1))
if(li[1][0]!='0'):
ans.append((1,0))
if(li[n-1][n-2]!='1'):
... | 8 | PYTHON3 |
t=int(input())
while t>0:
t-=1
n=int(input())
a=[]
for i in range(n):
b=input()
a.append(b)
c=int(a[0][1])
d=int(a[1][0])
e=int(a[-1][-2])
f=int(a[-2][-1])
if c==d and e==f and c!=e:
print(0)
elif c==d and e==f and c==e:
print(2)
print(1,2)... | 8 | PYTHON3 |
def main():
for i in range(int(input())):
n = int(input())
matx = []
for i in range(n):
x = list(input())
matx.append(x)
x = matx[n-2][n-1]
y = matx[n-1][n-2]
a = matx[0][1]
b = matx[1][0]
v=a+b+x+y
if v=='0100' or v=='1... | 8 | PYTHON3 |
'''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineering College
'''
from os import path
import sys
from heapq import heappush,heappop
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd
from bisect import bisect,bisect_left,bisect_right,insort,insort_left... | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
char mat[201][201];
int main() {
fast();
int n, t;
bool p, q;
cin >> t;
for (int cas = 0; cas < t; cas++) {
int x = 0;
q = p = false;
cin >> n;
for (int i = 0; i < n;... | 8 | CPP |
'''Author- Akshit Monga'''
t=int(input())
for _ in range(t):
n=int(input())
mat=[[0for y in range(n)] for x in range(n)]
for i in range(n):
s=input()
for j in range(n):
mat[i][j]=s[j]
if mat[0][1]==mat[1][0]=='0':
if mat[n-2][n-1]==mat[n-1][n-2]=='1':
prin... | 8 | PYTHON3 |
import sys
for i in range(int(sys.stdin.readline())):
a = []
for z in range(int(sys.stdin.readline())):
a.append(str(sys.stdin.readline().strip()))
g1 = a[1][0]
g2 = a[0][1]
c1 = a[len(a)-2][len(a)-1]
c2 = a[len(a)-1][len(a)-2]
stat = False
stat2 = False
gstat = None
csta... | 8 | PYTHON3 |
import sys
from math import ceil, factorial, gcd
#from math import comb, perm only in python3
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
MOD = 10**9 + 7
INF = float('inf')
rl = lambda : list(map(int, sys.stdin.readline... | 8 | PYTHON3 |
t = int(input())
for _ in range(t):
n = int(input())
brick = [[0 for _ in range(n)] for _ in range(n)]
brick[0][0] = "S"
brick[n-1][n-1] = "F"
for i in range(n):
string = input()
for j in range(len(string)):
if string[j] != "F" and string[j] != "S":
brick... | 8 | PYTHON3 |
t=int(input())
for _ in range(t):
n=int(input())
row=[None]*n
for i in range(n):
row[i]=input()
(a_1,a_2) = ([row[0][1], row[1][0]], [row[n-2][n-1], row[n-1][n-2]])
if a_1==['0','0']:
c=2-a_2.count('1')
print(c)
if c!=0:
if a_2[0]!='1':
pri... | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
char m[n][n];
for (long long int i = (0); i < (n); i++) {
for (long long int j = (0); j < (n); j++) cin >> m[i][j];
}
if (m[0][1] == '0' and m[1][0] == '0') {
if (m[n - 2][n - 1] == '0' and m[n - 1][n - 2] == '0'... | 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
char a[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
vector<pair<long... | 8 | CPP |
t=int(input())
for _ in range(t):
n=int(input())
m=[]
for i in range(n):
l=input()
m.append(l)
a=m[0][1]
b=m[1][0]
c=m[n-2][n-1]
d=m[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:
print(n-1,n)
else:... | 8 | PYTHON3 |
t = int(input())
for _ in range(t):
n = int(input())
matrix = []
for i in range(n):
arr = list(input())
matrix.append(arr)
ans = []
if matrix[0][1]=='1' and matrix[1][0]=='1':
if matrix[n-1][n-2]=='1':
ans.append((n-1,n-2))
if matrix[n-2][n-1]=='1':
... | 8 | PYTHON3 |
def find(arr,N):
R=[]
if(arr[N-1][N-2]==arr[N-2][N-1]):
a=arr[N-1][N-2]
if(arr[1][0]==a): R.append((2,1))
if(arr[0][1]==a): R.append((1,2))
elif(arr[1][0]==arr[0][1]):
a=arr[1][0]
if(arr[N-1][N-2]==a): R.append((N,N-1))
if(arr[N-2][N-1]==a): R.append((N-1,N))
... | 8 | PYTHON3 |
t = int(input())
for q in range(t):
a = int(input())
arr = []
for w in range(a):
arr.append(list(input()))
x1 = int(arr[0][1])
x2 = int(arr[1][0])
x3 = int(arr[a - 2][a - 1])
x4 = int(arr[a - 1][a - 2])
if x1 == x2:
if x3 == x4:
if x1 == x3:
pr... | 8 | PYTHON3 |
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 18 15:21:50 2020
@author: Dark Soul
"""
t=int(input(''))
for _ in range(t):
ans=[]
n=int(input(''))
for j in range(n):
ans.append(list(input('')))
x=ans[0][1]
y=ans[1][0]
z=ans[n-1][n-2]
a=ans[n-2][n-1]
if x==y... | 8 | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.