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 = getchar();
} while (isdigit(ch));
return f * x;
}
inline void print(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) print(x / 10);
putchar(x % 10 + '0');
}
const int mod = 1e9 + 7;
string s[220];
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> s[i];
char a, b, c, d;
a = s[0][1];
b = s[1][0];
c = s[n - 2][n - 1];
d = s[n - 1][n - 2];
if (a == b) {
if (c == d) {
if (a == c) {
cout << 2 << endl;
cout << n << ' ' << n - 1 << endl;
cout << n - 1 << ' ' << n << endl;
} else {
cout << 0 << endl;
}
} else {
if (a == c) {
cout << 1 << endl;
cout << n - 1 << ' ' << n << endl;
} else {
cout << 1 << endl;
cout << n << ' ' << n - 1 << endl;
}
}
} else {
if (c == d) {
if (a == c) {
cout << 1 << endl;
cout << 1 << ' ' << 2 << endl;
} else {
cout << 1 << endl;
cout << 2 << ' ' << 1 << endl;
}
} else {
if (a == c) {
cout << 2 << endl;
cout << n - 1 << ' ' << n << endl;
cout << 2 << ' ' << 1 << endl;
} else {
cout << 2 << endl;
cout << 1 << ' ' << 2 << endl;
cout << n - 1 << ' ' << n << endl;
}
}
}
}
}
| 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'
elif y[0]==y[1]:
if y[0]=='0':
x='11'
else:
x='00'
else:
x='00'
y='11'
output=[]
if x[0]!=string[0][1]:
output.append((0,1))
if x[1]!=string[1][0]:
output.append((1,0))
if y[0]!=string[p][q]:
output.append((p,q))
if y[1]!=string[r][s]:
output.append((r,s))
print(len(output))
for x,y in output:
print(x+1,y+1)
| 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] - '0', a21 = a[2][1] - '0', anl = a[n][n - 1] - '0',
anu = a[n - 1][n] - '0';
if (a12 == a21 && anl == anu) {
if (a12 == anl)
cout << "2\n1 2\n2 1\n";
else
cout << "0\n";
} else if (a12 == a21) {
if (anl == a12)
cout << "1\n" << n << ' ' << n - 1 << '\n';
else
cout << "1\n" << n - 1 << ' ' << n << '\n';
} else if (anl == anu) {
if (anl == a12)
cout << "1\n" << 1 << ' ' << 2 << '\n';
else
cout << "1\n" << 2 << ' ' << 1 << '\n';
} else {
cout << 2 << '\n';
if (a12 == 0)
cout << "1 2\n";
else
cout << "2 1\n";
if (anl == 1)
cout << n << ' ' << n - 1 << '\n';
else
cout << n - 1 << ' ' << n << '\n';
}
}
}
| 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]
if top==left and down==right and top==right:
cng=2
ans=[[1,2],[2,1]]
if top==left and down==right and top!=right:
cng=0
if top!=left and down!=right:
cng=2
if top==down:
ans=[[1,2],[k-1,k]]
if top==right:
ans=[[1,2],[k,k-1]]
if top==left and down!=right:
cng=1
if left==right:
ans=[[k-1,k]]
else:
ans=[[k,k-1]]
if top!=left and down==right:
cng=1
if right==left:
ans=[[2,1]]
else:
ans=[[1,2]]
stdout.write(str(cng)+'\n')
for q in ans:
stdout.write(str(q[0])+' '+str(q[1])+'\n')
| 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)
print(n-1, n)
print(n, n-1)
elif c==a and d!=a:
print(1)
print(n-1, n)
elif c!=a and d==a:
print(1)
print(n, n-1)
else:
print(0)
else:
if c==d:
if a==c:
print(1)
print(1, 2)
else:
print(1)
print(2, 1)
else:
if a==d:
print(2)
print(n, n-1)
print(2, 1)
else:
print(2)
print(n, n-1)
print(1, 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(a, b)
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p * p <= n:
if prime[p]:
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 2
r = [2]
for p in range(3, n + 1, 2):
if prime[p]:
r.append(p)
return r
def divs(n, start=2):
r = []
for i in range(start, int(math.sqrt(n) + 1)):
if (n % i == 0):
if (n / i == i):
r.append(i)
else:
r.extend([i, n // i])
return r
def divn(n, primes):
divs_number = 1
for i in primes:
if n == 1:
return divs_number
t = 1
while n % i == 0:
t += 1
n //= i
divs_number *= t
def prime(n):
if n == 2: return True
if n % 2 == 0 or n <= 1: return False
sqr = int(math.sqrt(n)) + 1
for d in range(3, sqr, 2):
if n % d == 0: return False
return True
def convn(number, base):
new_number = 0
while number > 0:
new_number += number % base
number //= base
return new_number
def cdiv(n, k): return n // k + (n % k != 0)
def ispal(s):
for i in range(len(s) // 2 + 1):
if s[i] != s[-i - 1]:
return False
return True
for _ in range(ii()):
n = ii()
m = []
for _ in range(n):
m.append(input())
if m[0][1] == '0' and m[1][0] == '0' and m[n - 2][n - 1] == '1' and m[n - 1][n - 2] == '1' or m[0][1] == '1' and m[1][0] == '1' and m[n - 2][n - 1] == '0' and m[n - 1][n - 2] == '0':
print(0)
elif m[0][1] == '0' and m[1][0] == '0' and m[n - 2][n - 1] == '0' and m[n - 1][n - 2] == '0' or m[0][1] == '1' and m[1][0] == '1' and m[n - 2][n - 1] == '1' and m[n - 1][n - 2] == '1':
print(2)
print(1, 2)
print(2, 1)
elif m[0][1] == '0' and m[1][0] == '1' and m[n - 2][n - 1] == '0' and m[n - 1][n - 2] == '0' or \
m[0][1] == '1' and m[1][0] == '0' and m[n - 2][n - 1] == '1' and m[n - 1][n - 2] == '1':
print(1)
print(1, 2)
elif m[0][1] == '1' and m[1][0] == '0' and m[n - 2][n - 1] == '0' and m[n - 1][n - 2] == '0' or \
m[0][1] == '0' and m[1][0] == '1' and m[n - 2][n - 1] == '1' and m[n - 1][n - 2] == '1':
print(1)
print(2, 1)
elif m[0][1] == '0' and m[1][0] == '0' and m[n - 2][n - 1] == '0' and m[n - 1][n - 2] == '1' or m[0][1] == '1' and m[1][0] == '1' and m[n - 2][n - 1] == '1' and m[n - 1][n - 2] == '0':
print(1)
print(n - 1, n)
elif m[0][1] == '1' and m[1][0] == '1' and m[n - 2][n - 1] == '0' and m[n - 1][n - 2] == '1' or m[0][1] == '0' and m[1][0] == '0' and m[n - 2][n - 1] == '1' and m[n - 1][n - 2] == '0':
print(1)
print(n, n - 1)
elif m[0][1] == '0' and m[1][0] == '1' and m[n - 2][n - 1] == '1' and m[n - 1][n - 2] == '0' or m[0][1] == '1' and m[1][0] == '0' and m[n - 2][n - 1] == '0' and m[n - 1][n - 2] == '1':
print(2)
print(2, 1)
print(n, n - 1)
elif m[0][1] == '0' and m[1][0] == '1' and m[n - 2][n - 1] == '0' and m[n - 1][n - 2] == '1' or m[0][1] == '1' and m[1][0] == '0' and m[n - 2][n - 1] == '1' and m[n - 1][n - 2] == '0':
print(2)
print(1, 2)
print(n, n - 1)
| 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, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
from bisect import bisect_left as bl
# If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
# If the element is already present in the list,
# the right most position where element has to be inserted is r
# ---------------------------------------------------Global Variables---------------------------------------------------
# sys.setrecursionlimit(100000000)
mod = 1000000007
# ---------------------------------------------------Helper Functions---------------------------------------------------
iinp = lambda: int(sys.stdin.readline())
inp = lambda: sys.stdin.readline().strip()
strl = lambda: list(inp().strip().split(" "))
intl = lambda: list(map(int, inp().split(" ")))
mint = lambda: map(int, inp().split())
flol = lambda: list(map(float, inp().split(" ")))
flush = lambda: stdout.flush()
def permute(nums):
def fun(arr, nums, cur, v):
if len(cur) == len(nums):
arr.append(cur.copy())
i = 0
while i < len(nums):
if v[i]:
i += 1
continue
else:
cur.append(nums[i])
v[i] = 1
fun(arr, nums, cur, v)
cur.pop()
v[i] = 0
i += 1
# while i<len(nums) and nums[i]==nums[i-1]:i+=1 # Uncomment for unique permutations
return arr
res = []
nums.sort()
v = [0] * len(nums)
return fun(res, nums, [], v)
def subsets(res, index, arr, cur):
res.append(cur.copy())
for i in range(index, len(arr)):
cur.append(arr[i])
subsets(res, i + 1, arr, cur)
cur.pop()
return res
def sieve(N):
root = int(sqrt(N))
primes = [1] * (N + 1)
primes[0], primes[1] = 0, 0
for i in range(2, root + 1):
if primes[i]:
for j in range(i * i, N + 1, i):
primes[j] = 0
return primes
def bs(arr, l, r, x):
if x < arr[0] or x > arr[len(arr) - 1]:
return -1
while l <= r:
mid = l + (r - l) // 2
if arr[mid] == x:
return mid
elif arr[mid] < x:
l = mid + 1
else:
r = mid - 1
return -1
def isPrime(n):
if n <= 1: return False
if n <= 3: return True
if n % 2 == 0 or n % 3 == 0: return False
p = int(sqrt(n))
for i in range(5, p + 1, 6):
if n % i == 0 or n % (i + 2) == 0:
return False
return True
# -------------------------------------------------------Functions------------------------------------------------------
def solve():
n = iinp()
arr = []
for i in range(n):
a = list(input())
arr.append(a)
a=0
ares=[]
b=0
bres=[]
if arr[0][1]!=str(0):
a+=1
ares.append([1,2])
if arr[1][0]!=str(0):
a+=1
ares.append([2,1])
if arr[1][1]!=str(1):
a+=1
ares.append([2,2])
if arr[2][0]!=str(1):
a+=1
ares.append([3,1])
if arr[0][2]!=str(1):
a+=1
ares.append([1,3])
if arr[0][1]!=str(1):
b+=1
bres.append([1,2])
if arr[1][0]!=str(1):
b+=1
bres.append([2,1])
if arr[1][1]!=str(0):
b+=1
bres.append([2,2])
if arr[2][0]!=str(0):
b+=1
bres.append([3,1])
if arr[0][2]!=str(0):
b+=1
bres.append([1,3])
if a<b:
print(a)
for i in ares:
print(*i)
else:
print(b)
for i in bres:
print(*i)
# -------------------------------------------------------Main Code------------------------------------------------------
for _ in range(iinp()):
solve()
| 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)
k.append(n)
if(l==0):
c+=1
k.append(n)
k.append(n-1)
elif(r+d==2):
if(u==1):
c+=1
k.append(n-1)
k.append(n)
if(l==1):
c+=1
k.append(n)
k.append(n-1)
else:
if(l+u==2):
if(r==1):
c+=1
k.append(1)
k.append(2)
if(d==1):
c+=1
k.append(2)
k.append(1)
elif(l+u==0):
if(r==0):
c+=1
k.append(1)
k.append(2)
if(d==0):
c+=1
k.append(2)
k.append(1)
else:
if(r==0):
c+=1
k.append(1)
k.append(2)
if(d==0):
c+=1
k.append(2)
k.append(1)
if(u==1):
c+=1
k.append(n-1)
k.append(n)
if(l==1):
c+=1
k.append(n)
k.append(n-1)
print(c)
if(len(k)!=0):
for i in range(0,len(k),2):
print(k[i],k[i+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(2)
print(1,2)
print(2,1)
elif(a==0 and b==0 and c==0 and d==1):
print(1)
print((m-1),x)
elif(a==0 and b==0 and c==1 and d==0):
print(1)
print(m,(x-1))
elif(a==0 and b==0 and c==1 and d==1):
print(0)
elif(a==0 and b==1 and c==0 and d==0):
print(1)
print(1,2)
elif(a==0 and b==1 and c==0 and d==1):
print(2)
print(1,2)
print(m,(x-1))
elif(a==0 and b==1 and c==1 and d==0):
print(2)
print(2,1)
print(m,(x-1))
elif(a==0 and b==1 and c==1 and d==1):
print(1)
print(2,1)
elif(a==1 and b==0 and c==0 and d==0):
print(1)
print(2,1)
elif(a==1 and b==0 and c==0 and d==1):
print(2)
print(1,2)
print((m-1),x)
elif(a==1 and b==0 and c==1 and d==0):
print(2)
print(2,1)
print((m-1),x)
elif(a==1 and b==0 and c==1 and d==1):
print(1)
print(1,2)
elif(a==1 and b==1 and c==0 and d==0):
print(0)
elif(a==1 and b==1 and c==0 and d==1):
print(1)
print(m,(x-1))
elif(a==1 and b==1 and c==1 and d==0):
print(1)
print((m-1),x)
elif(a==1 and b==1 and c==1 and d==1):
print(2)
print(1,2)
print(2,1)
| 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: int(input())
lin = lambda: list(map(int, input().rstrip().split()))
TEST_CASES = True
def main():
n = iin()
mat = [input() for i in range(n)]
if int(mat[1][0])+int(mat[0][1]) == 0:
if int(mat[n-2][n-1])+int(mat[n-1][n-2]) == 0:
print(2)
print(n,n-1)
print(n-1,n)
elif int(mat[n-2][n-1])+int(mat[n-1][n-2]) == 1:
print(1)
if int(mat[n-1][n-2]) == 0:
print(n,n-1)
else:
print(n-1,n)
else:
print(0)
return
elif int(mat[1][0])+int(mat[0][1]) == 2:
if int(mat[n-2][n-1])+int(mat[n-1][n-2]) == 0:
print(0)
elif int(mat[n-2][n-1])+int(mat[n-1][n-2]) == 1:
print(1)
if int(mat[n-1][n-2]) == 1:
print(n,n-1)
else:
print(n-1,n)
else:
print(2)
print(n,n-1)
print(n-1,n)
return
else:
if int(mat[n-1][n-2]) + int(mat[n-2][n-1]) == 0:
print(1)
if mat[0][1] == '0':
print(1,2)
else:
print(2,1)
elif int(mat[n-1][n-2]) + int(mat[n-2][n-1]) == 2:
print(1)
if mat[0][1] == '1':
print(1,2)
else:
print(2,1)
else:
majority = int(mat[n-2][n-2])
print(2)
if int(mat[n-1][n-2]) == majority:
print(n-1,n)
else:
print(n,n-1)
if int(mat[0][1]) == majority:
print(1,2)
else:
print(2,1)
return
# START
if not TEST_CASES: main()
else: [main() for _ in range(int(input()))]
| 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 < n; ++i) {
string ss;
cin >> ss;
s.push_back(ss);
}
vector<pair<int, int>> ans;
if (s[0][1] == s[1][0]) {
auto c = s[0][1];
if (s[n - 1][n - 2] == c) ans.push_back({n - 1, n - 2});
if (s[n - 2][n - 1] == c) ans.push_back({n - 2, n - 1});
} else if (s[0][1] != s[1][0]) {
if (s[n - 1][n - 2] == s[n - 2][n - 1]) {
char c = s[n - 1][n - 2];
if (s[0][1] == c) {
ans.push_back({0, 1});
} else {
ans.push_back({1, 0});
}
} else {
ans.push_back({0, 1});
if (s[0][1] != s[n - 1][n - 2]) {
ans.push_back({n - 1, n - 2});
} else {
ans.push_back({n - 2, n - 1});
}
}
}
cout << ans.size() << "\n";
for (auto p : ans) {
cout << p.first + 1 << " " << p.second + 1 << "\n";
}
}
| 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)
else:
print(0)
elif(l[0][1]=='1' and l[1][0]=='1'):
if(l[n-2][n-1]=='1' and l[n-1][n-2]=='1'):
print(2)
print(n,n-1)
print(n-1,n)
elif l[n-2][n-1]=='1':
print(1)
print(n-1,n)
elif l[n-1][n-2]=='1':
print(1)
print(n,n-1)
else:
print(0)
else:
if(l[n-2][n-1]=='0' and l[n-1][n-2]=='0'):
if(l[0][1]=='0'):
print(1)
print(1,2)
else:
print(1)
print(2,1)
elif(l[n-2][n-1]=='1' and l[n-1][n-2]=='1'):
if(l[0][1]=='1'):
print(1)
print(1,2)
else:
print(1)
print(2,1)
elif(l[0][1]=='1'):
if(l[n-2][n-1]=='0'):
print(2)
print(1,2)
print(n-1,n)
else:
print(2)
print(1,2)
print(n,n-1)
else:
if(l[n-2][n-1]=='1'):
print(2)
print(1,2)
print(n-1,n)
else:
print(2)
print(1,2)
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++;
if (a[1][0] == '0')
zeroc++;
else
onec++;
if (a[n - 2][n - 1] == '0')
zeroc++;
else
onec++;
if (a[n - 1][n - 2] == '0')
zeroc++;
else
onec++;
if (zeroc == 0 || onec == 0) {
cout << "2" << endl;
cout << "1 2" << endl;
cout << "2 1" << endl;
return;
}
if (zeroc > onec) {
if (a[0][1] != a[1][0]) {
c++;
if (a[0][1] == '0') {
vector<int> temp;
temp.push_back(1);
temp.push_back(2);
v.push_back(temp);
} else {
vector<int> temp;
temp.push_back(2);
temp.push_back(1);
v.push_back(temp);
}
} else {
c++;
if (a[n - 1][n - 2] == '0') {
vector<int> temp;
temp.push_back(n);
temp.push_back(n - 1);
v.push_back(temp);
} else {
vector<int> temp;
temp.push_back(n - 1);
temp.push_back(n);
v.push_back(temp);
}
}
} else if (onec > zeroc) {
if (a[0][1] != a[1][0]) {
c++;
if (a[0][1] == '1') {
vector<int> temp;
temp.push_back(1);
temp.push_back(2);
v.push_back(temp);
} else {
vector<int> temp;
temp.push_back(2);
temp.push_back(1);
v.push_back(temp);
}
} else {
c++;
if (a[n - 1][n - 2] == '1') {
vector<int> temp;
temp.push_back(n);
temp.push_back(n - 1);
v.push_back(temp);
} else {
vector<int> temp;
temp.push_back(n - 1);
temp.push_back(n);
v.push_back(temp);
}
}
} else {
if (a[0][1] != a[1][0]) {
c++;
if (a[0][1] == '0') {
vector<int> temp;
temp.push_back(2);
temp.push_back(1);
v.push_back(temp);
} else {
vector<int> temp;
temp.push_back(1);
temp.push_back(2);
v.push_back(temp);
}
}
if (a[n - 1][n - 2] != a[n - 2][n - 1]) {
c++;
if (a[n - 1][n - 2] == '1') {
vector<int> temp;
temp.push_back(n - 1);
temp.push_back(n);
v.push_back(temp);
} else {
vector<int> temp;
temp.push_back(n);
temp.push_back(n - 1);
v.push_back(temp);
}
}
}
cout << c << endl;
for (int i = 0; i < v.size(); i++) {
cout << v[i][0] << " " << v[i][1] << endl;
}
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
| 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)
print(2, 1)
elif a == b:
if a==x and x!=y:
print(1)
print(n, n-1)
elif a==y and x!=y:
print(1)
print(n-1, n)
elif a==x and a==y:
print(2)
print(n, n-1)
print(n-1, n)
elif x == y:
if a==x and a!=b:
print(1)
print(1, 2)
elif b==x and a!=b:
print(1)
print(2, 1)
elif a==x and a==y:
print(2)
print(n, n-1)
print(n-1, n)
else:
print(2)
if a==x:
print(1, 2)
print(n-1, n)
elif a==y:
print(1, 2)
print(n, n-1)
| 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 uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 8;
const double pi = 3.14159265359;
long long binpow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
long long inverse(long long x) { return binpow(x, MOD - 2, MOD); }
void solve() {
long long n;
cin >> n;
string arr[n];
for (long long i = 0; i < n; i++) cin >> arr[i];
long long x1 = (arr[1][0] - '0');
long long x2 = (arr[0][1] - '0');
long long y1 = (arr[n - 1][n - 2] - '0');
long long y2 = (arr[n - 2][n - 1] - '0');
vector<pair<long long, long long> > ans;
if (x1 == x2 && y1 == y2) {
if (x1 == y1) {
ans.push_back(make_pair(2, 1));
ans.push_back(make_pair(1, 2));
}
} else if (x1 == x2 && y1 != y2) {
if (x1 == y1)
ans.push_back(make_pair(n, n - 1));
else
ans.push_back(make_pair(n - 1, n));
} else if (x1 != x2 && y1 == y2) {
if (x1 == y1)
ans.push_back(make_pair(2, 1));
else
ans.push_back(make_pair(1, 2));
} else if (x1 != x2 && y1 != y2) {
if (x1 == y1) {
ans.push_back(make_pair(2, 1));
ans.push_back(make_pair(n - 1, n));
} else {
ans.push_back(make_pair(2, 1));
ans.push_back(make_pair(n, n - 1));
}
}
cout << ans.size() << endl;
if (ans.size() == 0) {
return;
}
for (long long i = 0; i < ans.size(); i++)
cout << ans[i].first << " " << ans[i].second << endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
long long t;
cin >> t;
while (t--) solve();
cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n ";
}
| 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 _ in range(n)]
ind = [(0,1),(1,0),(n-2,n-1),(n-1,n-2)]
for pt in ['0011','1100']:
cnt = 0
res = []
for i,(y,x) in enumerate(ind):
if pt[i] != s[y][x]:
cnt += 1
res.append((y,x))
if cnt <= 2:
print(cnt)
for y,x in res:
print(y+1,x+1)
break
| 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]==g[1][0] and g[-1][-2]==g[-2][-1] and g[0][1]==g[-1][-2]:
print(2)
print(1, 2)
print(2, 1)
elif g[0][1]==g[1][0] and g[-1][-2]==g[-2][-1] and g[0][1]!=g[-1][-2]:
print(0)
elif g[0][1]!=g[1][0] and g[-1][-2]==g[-2][-1]:
print(1)
if g[0][1]==g[-1][-2]:
print(1, 2)
else:
print(2, 1)
elif g[0][1]==g[1][0] and g[-1][-2]!=g[-2][-1]:
print(1)
if g[0][1]==g[-1][-2]:
print(n, n-1)
else:
print(n-1, n)
elif g[0][1]!=g[1][0] and g[-1][-2]!=g[-2][-1]:
print(2)
print(2, 1)
if g[0][1]==g[-1][-2]:
print(n, n-1)
else:
print(n-1, n)
| 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)
print(1, 2)
else: print(0)
else:
if l[1][0] == l[n - 1][n - 2]:
print(1)
print(2, 1)
else:
print(1)
print(1, 2)
else:
if l[0][1] == l[1][0]:
if l[n - 1][n - 2] == l[0][1]:
print(1)
print(n, n - 1)
else:
print(1)
print(n - 1, n)
else:
if l[0][1] == l[n - 1][n - 2]:
print(2)
print(1, 2)
print(n - 1, n)
elif l[0][1] == l[n - 2][n - 1]:
print(2)
print(1, 2)
print(n, n - 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)
print(n,n-1)
else:
print(1)
print(n-1,n)
elif a!=b and c==d:
print(1)
if c==a:
print(1,2)
else:
print(2,1)
elif a==b and c==d:
print(2)
print(1,2)
print(2,1)
elif a!=b and c!=d:
print(2)
if a!=c:
print(1,2)
print(n,n-1)
elif a!=d:
print(1,2)
print(n-1,n)
| 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
#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()]
for _ in range(inp()):
n = inp()
x = [list(input().strip()) for i in range(n)]
a,b,c,d = x[0][1],x[1][0],x[n-1][n-2],x[n-2][n-1]
if a == b == c == d:
print(2)
print(1,2)
print(2,1)
elif a == b and c == d:
print(0)
elif a == b and c != d:
print(1)
if c == a == b:
print(n,n-1)
elif d == a == b:
print(n-1,n)
elif c == d and a != b:
print(1)
if a == c == d:
print(1,2)
elif b == c == d:
print(2,1)
elif a != b and c != d:
print(2)
if b != c:
print(2,1)
print(n,n-1)
else:
print(1,2)
print(n,n-1)
| 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))
#sys.stdout = BytesIO()
#register(lambda: os.write(1, sys.stdout.getvalue()))
import io
#input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from sys import stdin, stdout
#input = sys.stdin.readline
#input = stdin.buffer.readline
#print = stdout.write
#a = [int(x) for x in input().split()]
#import os,io
#input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
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.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
#sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
#sys.stdin = open("F:\PY\\test.txt", "r")
input = lambda: sys.stdin.readline().rstrip("\r\n")
for _ in range(int(input())):
n = int(input())
arD = ['']*n
for i in range(n):
arD[i]=input()
st1 = arD[1][0]+arD[0][1]+arD[n-1][n-2]+arD[n-2][n-1]
if st1.count('1')==4 or st1.count('0')==4:
print(2)
print(1, 2)
print(2, 1)
elif st1[0]==st1[1]:
if st1[2]==st1[3]:
print(0)
else:
print(1)
if st1[2]==st1[0]:
print(n, n-1)
else:
print(n-1, n)
else:
if st1[2]==st1[3]:
print(1)
if st1[2]==st1[0]:
print(2, 1)
else:
print(1, 2)
else:
print(2)
if st1[0]=='1':
print(2, 1)
if st1[1]=='1':
print(1, 2)
if st1[2]=='0':
print(n, n-1)
if st1[3]=='0':
print(n-1, n)
'''
sys.exit(0)
n = int(input())
lis = list(map(int, input().split()))
answer = 0
for i in range(n):
answer+=lis[i]-1
if n==1:
print(n-1)
elif n>32:
print(answer)
sys.exit(0)
lis.sort()
for i in range(2, 50000):
localMin = 0
for j in range(n):
needVal = i**j
localMin+=abs(lis[j]-needVal)
if localMin>answer:
break
else:
answer = min(localMin, answer)
print(answer)
n = int(input())
lis = list(map(int, input().split()))
sumAr = 0
for i in range(n):
sumAr+=lis[i]
k = (sumAr-(n*(n-1)//2))//n
dif = sumAr - (k*n+(n*(n-1)//2))
answer=[]
for i in range(n):
if i<dif:
print(k+i+1)
#print(k+i+1, end=" ")
else:
print(k+i)
#print(k+i, end=" ")
#print(*answer, sep=" ")
sys.exit(0)
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
p1 = Person("heelo", 27)
print(help(Person))
age = 26
name = 'Swaroop'
print('Возрас {} -- {} лет'.format(name, age))
print(help(object))
for _ in range(int(input())):
n = int(input())
ar = list(map(int, input().split()))
dp = [0]*100005
for i in range(n):
dp[ar[i]]+=1
ar.clear()
for i in range(len(dp)):
if dp[i]!=0:
ar.append(dp[i])
ar.sort()
maxC = ar[len(ar)-1]
sumA = sum(ar)
answer=0
for i in range(len(ar)):
if ar[i]==maxC:
answer+=1
sumA-=maxC
answer-=1
answer+= min(sumA//(maxC-1), len(ar)-1)
print(answer)
#sys.exit(0)
def maxDisjointIntervals(list_):
list_.sort(key=lambda x: x[1])
print(list_[0][0], list_[0][1])
r1 = list_[0][1]
for i in range(1, len(list_)):
l1 = list_[i][0]
r2 = list_[i][1]
if l1>r1:
print(l1, r2)
r1 = r2
if __name__ =="__main__1":
N=4
intervals = [[1, 4], [2, 3], [4,6], [8,9]]
maxDisjointIntervals(intervals)
'''
| 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, T2 m) {
return (a % m + m) % m;
}
template <typename T1, typename T2>
inline bool isEq(T1 a, T2 b) {
return abs(a - b) < EPS;
}
template <typename T1, typename T2, typename T3>
inline bool isEq(T1 a, T2 b, T3 eps) {
return abs(a - b) < eps;
}
template <typename T>
inline bool isKthBitOn(T n, int k) {
assert(n <= numeric_limits<T>::max());
assert(k <= numeric_limits<T>::digits);
T ONE = 1;
return bool((n & (ONE << k)));
}
template <typename T>
inline void setKthBit(T& n, int k) {
assert(n <= numeric_limits<T>::max());
assert(k <= numeric_limits<T>::digits);
T ONE = 1;
n = (n | (ONE << k));
}
const int oo = 0x3f3f3f3f;
const int MAX = 200010;
const int MOD = 1000000007;
const int precision = 10;
void solve(int kas) {
int n;
cin >> n;
vector<string> grid(n);
for (int i = 0; i < n; i++) {
cin >> grid[i];
}
vector<pair<int, int> > ans;
if (grid[0][1] == grid[1][0]) {
char other = (grid[0][1] == '1') ? '0' : '1';
if (other != grid[n - 1][n - 2]) ans.push_back({n - 1, n - 2});
if (other != grid[n - 2][n - 1]) ans.push_back({n - 2, n - 1});
} else {
if (grid[n - 1][n - 2] == grid[n - 2][n - 1]) {
char other = (grid[n - 1][n - 2] == '1') ? '0' : '1';
if (other != grid[0][1]) ans.push_back({0, 1});
if (other != grid[1][0]) ans.push_back({1, 0});
} else {
grid[0][1] = grid[1][0];
ans.push_back({0, 1});
char other = (grid[0][1] == '1') ? '0' : '1';
if (other != grid[n - 1][n - 2]) ans.push_back({n - 1, n - 2});
if (other != grid[n - 2][n - 1]) ans.push_back({n - 2, n - 1});
}
}
cout << ans.size() << '\n';
for (int i = 0; i < ans.size(); i++)
cout << ans[i].first + 1 << " " << ans[i].second + 1 << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc = 1;
cin >> tc;
for (int _ = 1; _ <= tc; _++) {
solve(_);
}
return 0;
}
| 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):
if ans1[i] == lol[i]:
l.append('0')
else:
count += 1
l.append('1')
if count<3:
print(count)
if l[0] == '1':
print("1 2")
if l[1] == '1':
print("1 3")
if l[2] == '1':
print("2 1")
if l[3] == '1':
print("3 1")
if l[4] == '1':
print("2 2")
else:
print(5-count)
if l[0] == '0':
print("1 2")
if l[1] == '0':
print("1 3")
if l[2] == '0':
print("2 1")
if l[3] == '0':
print("3 1")
if l[4] == '0':
print("2 2")
t -= 1
| 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:
print(0)
else:
print(1)
print(n, n - 1)
else:
if b2 == 1:
print(1)
print(n - 1, n)
else:
print(2)
print(n, n - 1)
print(n - 1, n)
elif b1 == 0 and b2 == 0:
if a1 == 1:
if a2 == 1:
print(0)
else:
print(1)
print(2, 1)
else:
if a2 == 1:
print(1)
print(1, 2)
else:
print(2)
print(1, 2)
print(2, 1)
elif a1 == 1 and a2 == 1:
if b1 == 0:
if b2 == 0:
print(0)
else:
print(1)
print(n, n - 1)
else:
if b2 == 0:
print(1)
print(n - 1, n)
else:
print(2)
print(n, n - 1)
print(n - 1, n)
elif b1 == 1 and b2 == 1:
if a1 == 0:
if a2 == 0:
print(0)
else:
print(1)
print(2, 1)
else:
if a2 == 0:
print(1)
print(1, 2)
else:
print(2)
print(1, 2)
print(2, 1)
else:
print(2)
if a1 == 0:
print(2, 1)
else:
print(1, 2)
if b1 == 0:
print(n - 1, n)
else:
print(n, n - 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 f1==s1:
ans.append([n-1,n])
if f2==s1:
ans.append([n,n-1])
elif f1==f2:
if f1==s1:
ans.append([1,2])
if f1==s2:
ans.append([2,1])
else:
if s1==0:
ans.append([2,1])
if f1==0:
ans.append([n-1,n])
if f2==0:
ans.append([n,n-1])
else:
ans.append([1,2])
if f1==0:
ans.append([n-1,n])
if f2==0:
ans.append([n,n-1])
print(len(ans))
for i in range(len(ans)):
print(*ans[i])
| 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;
while (t--) {
int n = read();
for (int i = 0; i < n; ++i) {
cin >> mat[i];
}
int n1 = mat[0][1] - '0';
int n2 = mat[1][0] - '0';
int n3 = mat[n - 1][n - 2] - '0';
int n4 = mat[n - 2][n - 1] - '0';
if (n1 != n2 && n3 != n4) {
cout << 2 << endl;
if (n1 != 1) {
cout << 1 << ' ' << 2 << endl;
} else
cout << 2 << ' ' << 1 << endl;
if (n3 != 0) {
printf("%d %d\n", n, n - 1);
} else
printf("%d %d\n", n - 1, n);
} else if (n1 != n2) {
cout << 1 << endl;
int op = n3;
if (n1 == op)
printf("%d %d\n", 1, 2);
else
printf("%d %d\n", 2, 1);
} else if (n3 != n4) {
cout << 1 << endl;
int op = n1;
if (n3 == op)
printf("%d %d\n", n, n - 1);
else
printf("%d %d\n", n - 1, n);
} else {
if (n1 != n3) {
cout << 0 << endl;
continue;
}
cout << 2 << endl;
printf("%d %d\n", 2, 1);
printf("%d %d\n", 1, 2);
}
}
}
| 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:
if a[-1][-2]==a[-2][-1]:
v=a[-1][-2]
if a[0][1]==v:
ansl.append([1,2])
if a[1][0]==v:
ansl.append([2,1])
else:
v=a[0][1]
ansl=[[2,1]]
if a[-1][-2]==v:
ansl.append([n,n-1])
if a[-2][-1]==v:
ansl.append([n-1,n])
print(len(ansl))
for z in ansl:
print(*z)
| 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 len(q) == 1:
q, = q
if c == q:
ans.append(cp)
if d == q:
ans.append(dp)
elif len(w) == 1:
q, = w
if a == q:
ans.append(ap)
if b == q:
ans.append(bp)
else:
if a == '0':
ans.append(ap)
else:
ans.append(bp)
if c == '1':
ans.append(cp)
else:
ans.append(dp)
print(len(ans))
print('\n'.join(f'{a} {b}' for a, b in ans))
| 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():
return([x for x in input().split()])
def inputstringnum():
return([ord(x)-ord('a') for x in input()])
def inputmatrixchar(rows):
arr2d = [[j for j in input().strip()] for i in range(rows)]
return arr2d
def inputmatrixint(rows):
arr2d = []
for _ in range(rows):
arr2d.append([int(i) for i in input().split()])
return arr2d
t = int(input())
for q in range(t):
n = inputnum()
m = inputmatrixchar(n)
ans1 = []
ans2 = []
a = m[0][1]
b = m[1][0]
c = m[n-1][n-2]
d = m[n-2][n-1]
if a == '0' and b == '0':
if c == '0':
ans1.append(n)
ans1.append(n-1)
if d == '0':
ans2.append(n-1)
ans2.append(n)
elif a == '1' and b == '0':
if c == '0' and d == '0':
ans1.append(2)
ans1.append(1)
if c == '1' and d == '0':
ans1.append(1)
ans1.append(2)
ans2.append(n-1)
ans2.append(n)
if c == '0' and d == '1':
ans1.append(1)
ans1.append(2)
ans2.append(n)
ans2.append(n-1)
if c == '1' and d == '1':
ans1.append(1)
ans1.append(2)
elif a == '0' and b =='1':
if c == '0' and d == '0':
ans1.append(1)
ans1.append(2)
if c == '1' and d == '0':
ans1.append(1)
ans1.append(2)
ans2.append(n)
ans2.append(n-1)
if c == '0' and d == '1':
ans1.append(1)
ans1.append(2)
ans2.append(n-1)
ans2.append(n)
if c == '1' and d == '1':
ans1.append(2)
ans1.append(1)
else:
if c == '1':
ans1.append(n)
ans1.append(n-1)
if d == '1':
ans2.append(n-1)
ans2.append(n)
cnt = (len(ans1) != 0) + (len(ans2) != 0);
print(cnt)
if len(ans1) != 0:
print(*ans1)
if len(ans2) != 0:
print(*ans2)
| 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):
l.append(list(SI()))
a,b = l[0][1],l[1][0]
c,d = l[n-1][n-2], l[n-2][n-1]
ans = []
if a == b and c == d:
if a == b == c == d:
ans.append([1,2])
ans.append([2,1])
elif a == b:
if c == a:
ans.append([n,n-1])
else:
ans.append([n-1,n])
elif c == d:
if c == a:
ans.append([1,2])
else:
ans.append([2,1])
else:
if a == c:
ans.append([1,2])
ans.append([n-1,n])
else:
ans.append([1,2])
ans.append([n,n-1])
print(len(ans))
for i in ans:
print(*i)
| 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 vector<int>& v) {
for (auto q : v) printf("%d ", q);
printf("\n");
}
void vout(const vector<long long>& v) {
for (auto q : v) printf("%lld ", q);
printf("\n");
}
struct typ {
int tp = -1;
long long a = 0, b = 0;
};
struct comp {
bool operator()(typ const& a, typ const& b) { return a.a < b.a; }
};
int main(int argc, char const* argv[]) {
int t = 1;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<string> v(n);
int i;
for (i = 0; i < n; i++) cin >> v[i];
bool ans = 0;
int a, b, c, d;
a = v[0][1] - '0';
b = v[1][0] - '0';
c = v[n - 1][n - 2] - '0';
d = v[n - 2][n - 1] - '0';
vector<pair<int, int>> out;
if (a == b && b == c && c == d) {
out.push_back({1, 2});
out.push_back({2, 1});
} else {
if (a == b) {
if (c != d) {
if (c == a)
out.push_back({n, n - 1});
else
out.push_back({n - 1, n});
}
} else if (c == d) {
if (a == c) {
out.push_back({1, 2});
} else {
out.push_back({2, 1});
}
} else {
if (a == c) {
out.push_back({1, 2});
out.push_back({n - 1, n});
} else {
out.push_back({1, 2});
out.push_back({n, n - 1});
}
}
}
printf("%d\n", (int)out.size());
for (auto q : out) printf("%d %d\n", q.first, q.second);
}
return 0;
}
| 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;
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]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << "2" << endl;
cout << "1 2" << endl;
cout << "2 1" << endl;
} else {
cout << "0" << endl;
}
} else {
cout << "1" << endl;
if (s[n - 1][n - 2] == s[0][1])
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
}
} else {
if (s[n - 1][n - 2] == s[n - 2][n - 1]) {
cout << "1" << endl;
if (s[0][1] == s[n - 1][n - 2])
cout << "1 2" << endl;
else
cout << "2 1" << endl;
} else {
cout << "2" << endl;
if (s[0][1] == '0')
cout << "1 2" << endl;
else
cout << "2 1" << endl;
if (s[n - 1][n - 2] == '1')
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
}
}
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
| 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):
a4 = test[-2]
s = 8*int(a4) + 4*int(a3) + 2*int(a2) + int(a1)
if(s == 15):
print(2)
print(2,1)
print(1,2)
if(s == 14):
print(1)
print(2,1)
if(s == 13):
print(1)
print(1,2)
if(s == 12):
print(0)
if(s == 11):
print(1)
print(n,n-1)
if(s == 10):
print(2)
print(n, n-1)
print(1, 2)
if(s == 9):
print(2)
print(2,1)
print(n, n-1)
if(s == 8):
print(1)
print(n-1,n)
if(s == 7):
print(1)
print(n-1,n)
if(s == 6):
print(2)
print(1,2)
print(n-1,n)
if(s == 5):
print(2)
print(2,1)
print(n-1,n)
if(s == 4):
print(1)
print(n, n-1)
if(s == 3):
print(0)
if(s == 2):
print(1)
print(1,2)
if(s == 1):
print(1)
print(2,1)
if(s == 0):
print(2)
print(1,2)
print(2,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(str) - 2]
if point_l1 == point_l2 and point_r1 == point_r2 and point_l1 != point_r1:
print(0)
elif point_l1 == point_l2 and point_r1 == point_r2 and point_l1 == point_r1:
print(2)
print(1, 2)
print(2, 1)
elif point_l1 != point_l2 and point_r1 != point_r2 and point_l1 == point_r1:
print(2)
print(1, 2)
print(len(str), len(str) - 1)
elif point_l1 != point_l2 and point_r1 != point_r2 and point_l1 == point_r2:
print(2)
print(1, 2)
print(len(str) - 1, len(str))
elif point_l1 != point_l2 and point_l1 == point_r1 and point_r1 == point_r2:
print(1)
print(1, 2)
elif point_l1 != point_l2 and point_l2 == point_r1 and point_r1 == point_r2:
print(1)
print(2, 1)
elif point_r1 != point_r2 and point_l2 == point_r1 and point_l1 == point_l2:
print(1)
print(len(str) - 1, len(str))
elif point_r1 != point_r2 and point_l2 == point_r2 and point_l1 == point_l2:
print(1)
print(len(str), len(str) - 1)
| 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 range(n):
square[i] = list(input().rstrip())
a,b,c,d=square[0][1],square[1][0],square[n-2][n-1],square[n-1][n-2]
ans=[]
if a == '0' and b == '0':
if c == '0': ans.append([n-2,n-1])
if d == '0': ans.append([n-1,n-2])
elif a == '1' and b == '1':
if c == '1': ans.append([n-2,n-1])
if d == '1': ans.append([n-1,n-2])
elif a == '1' and b == '0':
if c == '1' and d == '1': ans.append([0,1])
elif c == '1' and d == '0': ans = [[0,1],[n-1,n-2]]
elif c == '0' and d == '1': ans = [[0,1],[n-2,n-1]]
elif c == '0' and d == '0': ans.append([1,0])
elif a == '0' and b == '1':
if c == '1' and d == '1': ans.append([1,0])
elif c == '1' and d == '0': ans = [[0,1],[n-2,n-1]]
elif c == '0' and d == '1': ans = [[0,1],[n-1,n-2]]
elif c == '0' and d == '0': ans.append([0,1])
print(len(ans))
for i in ans:
print(i[0]+1,i[1]+1)
def C():
t=int(input())
for _ in range(t):
print(_)
def D():
t=int(input())
for _ in range(t):
print(_)
B()
| 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 long i = 0; i < n; i++) {
string s;
cin >> s;
for (long long j = 0; j < n; j++) {
if (i == 0 && j == 1)
a = (long long)s[j] - 48;
else if (i == 1 && j == 0)
b = (long long)s[j] - 48;
else if (i == n - 2 && j == n - 1)
c = (long long)s[j] - 48;
else if (i == n - 1 && j == n - 2)
d = (long long)s[j] - 48;
}
}
if (a == b && c == d) {
if (a == c) {
cout << (2) << "\n";
cout << 1 << " " << 2 << "\n";
cout << 2 << " " << 1 << "\n";
} else
cout << (0) << "\n";
} else if (a == b) {
if (a ^ c == 1) {
cout << (1) << "\n";
cout << n << " " << n - 1 << "\n";
} else {
cout << (1) << "\n";
cout << n - 1 << " " << n << "\n";
}
} else if (c == d) {
if (a ^ c == 1) {
cout << (1) << "\n";
cout << 2 << " " << 1 << "\n";
} else {
cout << (1) << "\n";
cout << 1 << " " << 2 << "\n";
}
} else {
cout << (2) << "\n";
if (a != 0) {
cout << 1 << " " << 2 << "\n";
} else {
cout << 2 << " " << 1 << "\n";
}
if (c != 0) {
cout << n << " " << n - 1 << "\n";
} else {
cout << n - 1 << " " << n << "\n";
}
}
}
}
| 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 <= n; j++) {
cin >> d[i][j];
}
}
if (d[1][2] == d[2][1] && d[2][1] == '0') {
if (d[n - 1][n] == d[n][n - 1] && d[n][n - 1] == d[1][2]) {
vect.push_back({n - 1, n});
vect.push_back({n, n - 1});
} else if (d[n - 1][n] == d[n][n - 1] && d[n][n - 1] != d[1][2])
c = c;
else if (d[n - 1][n] != '0') {
vect.push_back({n, n - 1});
} else if (d[n][n - 1] != '0') {
vect.push_back({n - 1, n});
}
} else if (d[1][2] == d[2][1] && d[2][1] == '1') {
if (d[n - 1][n] == d[n][n - 1] && d[n][n - 1] == d[1][2]) {
vect.push_back({n - 1, n});
vect.push_back({n, n - 1});
} else if (d[n - 1][n] == d[n][n - 1] && d[n][n - 1] != d[1][2])
c = c;
else if (d[n - 1][n] != '0') {
vect.push_back({n - 1, n});
} else if (d[n][n - 1] != '0') {
vect.push_back({n, n - 1});
}
} else if (d[1][2] != d[2][1]) {
if (d[n - 1][n] == d[n][n - 1] && d[n][n - 1] == '0') {
if (d[1][2] == '1')
vect.push_back({2, 1});
else
vect.push_back({1, 2});
} else if (d[n - 1][n] == d[n][n - 1] && d[n][n - 1] == '1') {
if (d[1][2] == '0')
vect.push_back({2, 1});
else
vect.push_back({1, 2});
} else if (d[n - 1][n] != d[n][n - 1]) {
if (d[1][2] == '0') {
vect.push_back({2, 1});
if (d[n][n - 1] == '1')
vect.push_back({n - 1, n});
else
vect.push_back({n, n - 1});
} else {
vect.push_back({1, 2});
if (d[n][n - 1] == '1')
vect.push_back({n - 1, n});
else
vect.push_back({n, n - 1});
}
}
}
cout << vect.size() << endl;
for (auto x : vect) {
cout << x.first << " " << x.second << endl;
}
}
return 0;
}
| 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 = lambda: int(input())
strng = lambda: input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda: list(input().strip())
mul = lambda: map(int, input().strip().split())
mulf = lambda: map(float, input().strip().split())
seq = lambda: list(map(int, input().strip().split()))
ceil = lambda x: int(x) if (x == int(x)) else int(x) + 1
ceildiv = lambda x, d: x // d if (x % d == 0) else x // d + 1
flush = lambda: stdout.flush()
stdstr = lambda: stdin.readline()
stdint = lambda: int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdarr = lambda: map(int, stdstr().split())
mod = 1000000007
for _ in range(stdint()):
n = stdint()
matrix = []
for __ in range(n):
row = input()
matrix.append(row)
m1 = ["S01"+("x"*(n-3)), "01"+("x"*(n-2)), "1"+("x"*(n-1))]
m2 = ["S10" + ("x" * (n - 3)), "10" + ("x" * (n - 2)), "0" + ("x" * (n - 1))]
points = dd(list)
d1 = []
for i in range(3):
for j in range(3):
if(m1[i][j] != "x"):
if(m1[i][j] != matrix[i][j]):
d1.append((i+1, j+1))
d2 = []
for i in range(3):
for j in range(3):
if(m2[i][j] != "x"):
if(m2[i][j] != matrix[i][j]):
d2.append((i+1, j+1))
if(len(d1) <= 2):
print(len(d1))
for i in d1:
print(*i)
else:
print(len(d2))
for i in d2:
print(*i)
| 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[node]=[]
def add_edge(self,u,v):
self.adj_list[u].append(v)
if self.is_directed==False:
self.adj_list[v].append(u)
def print_graph(self):
for node in self.nodes:
print(node,"->",self.adj_list[node])
def degree_node(self,node):
return len(self.adj_list[node])
def dfsUTIL(self,v,visited,parents=[]):
#print(v,end=" ")
visited[v]=True
for i in self.adj_list[v]:
if visited[i]==False:
self.dfsUTIL(i,visited,parents)
parents.append(i)
def dfs(self,v):
visited=[False]*(max(self.adj_list)+1)
parents=[v]
self.dfsUTIL(v,visited,parents)
return parents
#####sorting a dictionary by the values#####
def dict_sort(ans):
ans=sorted(ans.items(),reverse=True,key=lambda kv:(kv[1]))
##### naive method for testing prime or not O(n^.5)#####
def is_prime(n):
if n==1:
return 0
for i in range(2,int(math.sqrt(n))+1):
if n%i==0:
return False
return True
#####swap function#####
def swap(a,b):
temp=a
a=b
b=temp
return a,b
#####Primes till Nth O(n)#####
def seive_primes(n):
flag=[0]*(n+10)
flag[1]=flag[0]=1
i=2
while i*i<=n+1:
if flag[i]==0:
j=i*i
while j<=n+1:
flag[j]=1
j+=i
i+=1
return flag
#####all the prime factors of a number#####
def factors(n):
d={}
while(n%2==0):
if 2 in d:
d[2]+=1
else:
d[2]=1
n/=2
for i in range(3,int(n**0.5)+1,2):
while(n%i==0):
if i in d:
d[i]+=1
else:
d[i]=1
n/=i
n=int(n)
if n>1:
d[n]=1
return d
#####greatest common divisor of two numbers#####
def gcd(a,b):
if b==0:
return a
return gcd(b,a%b)
#####least common multiplyer of two numbers#####
def lcm(a,b):
return (a*b)//gcd(a,b)
#####function that return all the letters#####
def alphabates():
return "abcdefghijklmnopqrstuvwxyz"
#####binary search O(logN)#####
def binary_search(ls,n,flag):
low=0
hi=n-1
while(low<=hi):
mid=(low+hi)//2
if ls[mid]==flag:
return mid
elif ls[mid]>flag:
hi=mid-1
else:
low=mid+1
return -1
#####quadratic roots#####
def qdrt(a,b,c):
chk=b*b-4*a*c
if chk>=0:
ans1=(-b+chk**0.5)/(2*a)
ans2=(-b-chk**0.5)/(2*a)
return [int(ans1),int(ans2)]
return -1
#####permutations#####
def permutation(n,r):
if n<r:
return 0
ans=1
for i in range(n-r+1,n+1):
ans*=i
return ans
#####combinations#####
def combination(n,r):
if n<r:
return 0
ans=1
for i in range(r):
ans*=(n-i)
div=1
for i in range(2,r+1):
div*=i
return ans//div
#####check if n is power of 2#####
def ispow2(n):
ans=int(math.log(n,2))
if 2**ans==n:
return True
return False
#####2d matrix#####
def _2dmat(n):
flag=[[i+1 for i in range(n)]]
for i in range(2,n+1):
new=[]
for j in range((i-1)*n+1,i*n+1):
new.append(j)
flag.append(new)
return flag
#####sum till nth#####
def sumn(n):
return (n*(n+1))//2
#####taking an array/list as input#####
def arrinp():
ls=list(map(int,input().split()))
return ls
#####taking multiple inputs#####
def mult_inp():
return map(int,input().split())
#####Main function starts from here#####
def chk(arr,a,b,c):
if arr[a][b]==c:
print(a+1,b+1)
def main():
n=int(input())
grid=[]
for i in range(n):
grid.append(input())
_0=0
if grid[0][1]=='0':
_0+=1
if grid[1][0]=='0':
_0+=1
if grid[n-1][n-2]=='1':
_0+=1
if grid[n-2][n-1]=='1':
_0+=1
if _0>2:
print(4-_0)
chk(grid,0,1,'1')
chk(grid,1,0,'1')
chk(grid,n-1,n-2,'0')
chk(grid,n-2,n-1,'0')
else:
print(_0)
chk(grid,0,1,'0')
chk(grid,1,0,'0')
chk(grid,n-1,n-2,'1')
chk(grid,n-2,n-1,'1')
if __name__=='__main__':
for _ in range(int(input())):
main()
| 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];
ch[0] = s[1][2], ch[1] = s[2][1];
ch[2] = s[n][n - 1], ch[3] = s[n - 1][n];
if (ch[0] == '0' && ch[1] == '0' && ch[2] == '0' && ch[3] == '0')
printf("%d\n%d %d\n%d %d\n", 2, 1, 2, 2, 1);
if (ch[0] == '0' && ch[1] == '0' && ch[2] == '0' && ch[3] == '1')
printf("%d\n%d %d\n", 1, n, n - 1);
if (ch[0] == '0' && ch[1] == '0' && ch[2] == '1' && ch[3] == '0')
printf("%d\n%d %d\n", 1, n - 1, n);
if (ch[0] == '0' && ch[1] == '0' && ch[2] == '1' && ch[3] == '1')
printf("%d\n", 0);
if (ch[0] == '0' && ch[1] == '1' && ch[2] == '0' && ch[3] == '0')
printf("%d\n%d %d\n", 1, 1, 2);
if (ch[0] == '0' && ch[1] == '1' && ch[2] == '0' && ch[3] == '1')
printf("%d\n%d %d\n%d %d\n", 2, 1, 2, n - 1, n);
if (ch[0] == '0' && ch[1] == '1' && ch[2] == '1' && ch[3] == '0')
printf("%d\n%d %d\n%d %d\n", 2, 1, 2, n, n - 1);
if (ch[0] == '0' && ch[1] == '1' && ch[2] == '1' && ch[3] == '1')
printf("%d\n%d %d\n", 1, 2, 1);
if (ch[0] == '1' && ch[1] == '0' && ch[2] == '0' && ch[3] == '0')
printf("%d\n%d %d\n", 1, 2, 1);
if (ch[0] == '1' && ch[1] == '0' && ch[2] == '0' && ch[3] == '1')
printf("%d\n%d %d\n%d %d\n", 2, 1, 2, n, n - 1);
if (ch[0] == '1' && ch[1] == '0' && ch[2] == '1' && ch[3] == '0')
printf("%d\n%d %d\n%d %d\n", 2, 1, 2, n - 1, n);
if (ch[0] == '1' && ch[1] == '0' && ch[2] == '1' && ch[3] == '1')
printf("%d\n%d %d\n", 1, 1, 2);
if (ch[0] == '1' && ch[1] == '1' && ch[2] == '0' && ch[3] == '0')
printf("%d\n", 0);
if (ch[0] == '1' && ch[1] == '1' && ch[2] == '0' && ch[3] == '1')
printf("%d\n%d %d\n", 1, n - 1, n);
if (ch[0] == '1' && ch[1] == '1' && ch[2] == '1' && ch[3] == '0')
printf("%d\n%d %d\n", 1, n, n - 1);
if (ch[0] == '1' && ch[1] == '1' && ch[2] == '1' && ch[3] == '1')
printf("%d\n%d %d\n%d %d\n", 2, 1, 2, 2, 1);
}
int main() {
int T;
scanf("%d", &T);
while (T--) work();
return 0;
}
| 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,0),(0,1),(0,-1)]
visited=[[0]*n for i in range(n)]
visited[0][0]=1
while len(bfs):
# print(bfs,val)
x,y=bfs.pop()
if x==y==n-1:
return True
for dx,dy in delta :
nx=x+dx
ny=y+dy
if 0<=nx<n and 0<=ny<n and visited[nx][ny]==0 and grid[nx][ny] in [val,'F']:
visited[nx][ny]=1
bfs.append((nx,ny))
return False
def main():
n=int(input())
arr=[]
for i in range(n):
arr.append([c for c in input()])
l=[(1,0),(0,1),(n-1,n-2),(n-2,n-1)]
c=list(combinations(l,0))+list(combinations(l,1))+list(combinations(l,2))
for li in c :
# print(li)
for x,y in li :
arr[x][y]='1' if arr[x][y]=='0' else '0'
if fun('0',arr,n) or fun('1',arr,n):
pass
else:
print(len(li))
for x,y in li :
print(x+1,y+1)
return
for x,y in li :
arr[x][y]='1' if arr[x][y]=='0' else '0'
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.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
for _ in range(int(input())):
main()
| 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_12, x_21, x_n1, x_n]) == 0 or sum([x_12, x_21, x_n1, x_n]) == 4:
print(2)
print("1 2")
print("2 1")
elif sum([x_12, x_21, x_n1, x_n]) == 1:
print(1)
if x_12 == 1:
print("2 1")
elif x_21 == 1:
print("1 2")
elif x_n1 == 1:
print(f'{n} {n-1}')
else:
print(f"{n-1} {n}")
elif sum([x_12, x_21, x_n1, x_n]) == 2:
if x_12 and x_21:
print(0)
elif x_n1 and x_n:
print(0)
elif x_12 and x_n1:
print(2)
print("2 1")
print(f"{n-1} {n}")
elif x_12 and x_n:
print(2)
print("2 1")
print(f"{n} {n-1}")
elif x_21 and x_n:
print(2)
print("1 2")
print(f"{n} {n-1}")
else:
print(2)
print("1 2")
print(f"{n-1} {n}")
elif sum([x_12, x_21, x_n1, x_n]) == 3:
print(1)
if x_12 == 0:
print("2 1")
elif x_21 == 0:
print("1 2")
elif x_n1 == 0:
print(f'{n} {n-1}')
else:
print(f"{n-1} {n}")
l = int(input())
for i in range(l):
main()
| 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][-2]=='0':
print(1)
print(n-1,n)
elif p[-2][-1]=='0' and p[-1][-2]=='1':
print(1)
print(n,n-1)
elif p[-2][-1]=='0' and p[-1][-2]=='0':
print(0)
elif p[0][1]=='0' and p[1][0]=='0':
if p[-2][-1]=='1' and p[-1][-2]=='1':
print(0)
elif p[-2][-1]=='1' and p[-1][-2]=='0':
print(1)
print(n,n-1)
elif p[-2][-1]=='0' and p[-1][-2]=='1':
print(1)
print(n-1,n)
elif p[-2][-1]=='0' and p[-1][-2]=='0':
print(2)
print(n,n-1)
print(n-1,n)
elif p[0][1]=='0' and p[1][0]=='1':
if p[-2][-1]=='1' and p[-1][-2]=='1':
print(1)
print(2,1)
elif p[-2][-1]=='1' and p[-1][-2]=='0':
print(2)
print(2,1)
print(n,n-1)
elif p[-2][-1]=='0' and p[-1][-2]=='1':
print(2)
print(2,1)
print(n-1,n)
elif p[-2][-1]=='0' and p[-1][-2]=='0':
print(1)
print(1,2)
elif p[0][1]=='1' and p[1][0]=='0':
if p[-2][-1]=='1' and p[-1][-2]=='1':
print(1)
print(1,2)
elif p[-2][-1]=='1' and p[-1][-2]=='0':
print(2)
print(1,2)
print(n,n-1)
elif p[-2][-1]=='0' and p[-1][-2]=='1':
print(2)
print(2,1)
print(n,n-1)
elif p[-2][-1]=='0' and p[-1][-2]=='0':
print(1)
print(2,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 false;
}
int main() {
ios_base::sync_with_stdio(false);
;
long long t = 1, n, sum, k, r, temp, dif, maxi, mini, ans, c, num, x, m, l, a,
b, i;
vector<pair<long long, long long>> pairvec;
bool flag = false;
cin >> t;
long long zeros, ones;
while (t--) {
pairvec.clear();
cin >> n;
string arr[n];
for (long long i = 0; i < n; ++i) {
cin >> arr[i];
}
if (arr[0][1] + arr[1][0] < arr[n - 1][n - 2] + arr[n - 2][n - 1]) {
if (arr[0][1] == '1') pairvec.push_back(make_pair(1, 2));
if (arr[1][0] == '1') pairvec.push_back(make_pair(2, 1));
if (arr[n - 1][n - 2] == '0') pairvec.push_back(make_pair(n, n - 1));
if (arr[n - 2][n - 1] == '0') pairvec.push_back(make_pair(n - 1, n));
} else {
if (arr[0][1] == '0') pairvec.push_back(make_pair(1, 2));
if (arr[1][0] == '0') pairvec.push_back(make_pair(2, 1));
if (arr[n - 1][n - 2] == '1') pairvec.push_back(make_pair(n, n - 1));
if (arr[n - 2][n - 1] == '1') pairvec.push_back(make_pair(n - 1, n));
}
cout << pairvec.size() << endl;
for (int i = 0; i < pairvec.size(); i++)
cout << pairvec[i].first << " " << pairvec[i].second << endl;
}
}
| 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:
s1 = input()
s2 = input()
s3 = input()
s1 = int(s1[1])
s2_ = int(s2[0])
s3_ = int(s2[-1])
s4 = int(s3[-2])
s2 = s2_
s3 = s3_
if s1 == s2 == s3 == s4:
print(2)
print(1, 2)
print(2, 1)
elif s1 == s2 and s3 == s4:
print(0)
elif s1 == s2 and s3 != s4:
print(1)
if s3 == s1:
print(n - 1, n)
else:
print(n, n - 1)
elif s3 == s4 and s1 != s2:
print(1)
if s1 == s3:
print(1, 2)
else:
print(2, 1)
elif s1 == s3 and s2 == s4:
print(2)
print(2, 1)
print(n - 1, n)
else:
print(2)
print(2, 1)
print(n, n - 1)
| 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:
print(1)
print(n-1,n)
else:
print(2)
print(1,2)
print(2,1)
continue
if s[1][2] == '1' and s[2][1] == '1':
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(2)
print(1,2)
print(2,1)
elif s1:
print(1)
print(n-1,n)
elif s2:
print(1)
print(n,n-1)
else:
print(0)
continue
if s[1][2] == '1' 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(1)
print(1,2)
elif s1:
print(2)
print(1,2)
print(n,n-1)
elif s2:
print(2)
print(1,2)
print(n-1,n)
else:
print(1)
print(2,1)
continue
if s[1][2] == '0' and s[2][1] == '1':
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(1)
print(2,1)
elif s1:
print(2)
print(1,2)
print(n-1,n)
elif s2:
print(2)
print(1,2)
print(n,n-1)
else:
print(1)
print(1,2)
continue
| 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:
print(1)
if A[0][1] == A[n-2][n-1]:print(n-1, n)
else:print(n, n-1)
else:
if A[n-2][n-1] == A[n-1][n-2]:
print(1)
if A[n-2][n-1] == A[0][1]:print(1, 2)
else:print(2, 1)
else:
print(2)
if A[0][1] == A[n-1][n-2]:
print(1, 2)
print(n-1, n)
else:
print(2, 1)
print(n-1, n)
| 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' and l[-2][-1]=='1')):
print(2)
print(1, 2)
print(2, 1)
elif (l[0][1] == '1' and l[1][0]=='1') and ((l[-1][-2] == '0' and l[-2][-1]=='0')):
print(0)
elif (l[0][1] == '0' and l[1][0]=='0') and ((l[-1][-2] == '1' and l[-2][-1]=='1')):
print(0)
elif (l[0][1] == '1' and l[1][0]=='0') and ((l[-1][-2] == '1' and l[-2][-1]=='1')):
print(1)
print(1, 2)
elif (l[0][1] == '0' and l[1][0]=='1') and ((l[-1][-2] == '1' and l[-2][-1]=='1')):
print(1)
print(2, 1)
elif (l[0][1] == '0' and l[1][0]=='1') and ((l[-1][-2] == '0' and l[-2][-1]=='0')):
print(1)
print(1, 2)
elif (l[0][1] == '1' and l[1][0]=='0') and ((l[-1][-2] == '0' and l[-2][-1]=='0')):
print(1)
print(2, 1)
elif (l[0][1] == '1' and l[1][0]=='1') and ((l[-1][-2] == '0' and l[-2][-1]=='1')):
print(1)
print(n-1, n)
elif (l[0][1] == '1' and l[1][0]=='1') and ((l[-1][-2] == '1' and l[-2][-1]=='0')):
print(1)
print(n, n-1)
elif (l[0][1] == '0' and l[1][0]=='0') and ((l[-1][-2] == '1' and l[-2][-1]=='0')):
print(1)
print(n-1, n)
elif (l[0][1] == '0' and l[1][0]=='0') and ((l[-1][-2] == '0' and l[-2][-1]=='1')):
print(1)
print(n, n-1)
elif (l[0][1] == '1' and l[1][0]=='0') and ((l[-1][-2] == '1' and l[-2][-1]=='0')):
print(2)
print(1, 2)
print(n-1, n)
elif (l[0][1] == '1' and l[1][0]=='0') and ((l[-1][-2] == '0' and l[-2][-1]=='1')):
print(2)
print(1, 2)
print(n, n-1)
elif (l[0][1] == '0' and l[1][0]=='1') and ((l[-1][-2] == '1' and l[-2][-1]=='0')):
print(2)
print(1, 2)
print(n, n-1)
elif (l[0][1] == '0' and l[1][0]=='1') and ((l[-1][-2] == '0' and l[-2][-1]=='1')):
print(2)
print(1, 2)
print(n-1, n)
| 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=='11' and y=='11')):
print(2)
print(n-1,n)
print(n,n-1)
elif(x=='01' and y=='01'):
print(2)
if(p=='0'):
print("1 2")
else:
print("2 1")
if(r=='1'):
print(n-1,n)
else:
print(n,n-1)
elif(x=="00" and y=='01'):
print(1)
if(r=='0'):
print(n-1,n)
else:
print(n,n-1)
elif(x=='01' and y=='00'):
print(1)
if(p=='0'):
print("1 2")
else:
print("2 1")
elif(x=='01' and y=='11'):
print(1)
if(p=='1'):
print("1 2")
else:
print("2 1")
elif(x=='11' and y=='01'):
print(1)
if(r=='1'):
print(n-1,n)
else:
print(n,n-1)
else:
print(0)
for z in range(int(input())):
solve()
| 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':
temp_list.append([2, 1])
if my_list[i][inp - 1][-2] == '0':
temp_list.append([inp, inp - 1])
if my_list[i][inp - 2][-1] == '0':
temp_list.append([inp - 1, inp])
if len(temp_list) > 2:
temp_list2 = []
if my_list[i][0][1] == '0':
temp_list2.append([1, 2])
if my_list[i][1][0] == '0':
temp_list2.append([2, 1])
if my_list[i][inp - 1][-2] == '1':
temp_list2.append([inp, inp - 1])
if my_list[i][inp - 2][-1] == '1':
temp_list2.append([inp - 1, inp])
print(len(temp_list2))
for k in range(len(temp_list2)):
print(temp_list2[k][0], temp_list2[k][1])
else:
print(len(temp_list))
for k in range(len(temp_list)):
print(temp_list[k][0], temp_list[k][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)
elif x in [[1, 1, 0, 0], [0, 0, 1, 1]]:
print(0)
elif x in [[0, 0, 0, 1], [1, 1, 1, 0]]:
print(1)
print(n, n-1)
elif x in [[0, 0, 1, 0], [1, 1, 0, 1]]:
print(1)
print(n-1, n)
elif x in [[0, 1, 0, 0], [1, 0, 1, 1]]:
print(1)
print(1, 2)
elif x in [[1, 0, 0, 0], [0, 1, 1, 1]]:
print(1)
print(2, 1)
elif x in [[0, 1, 0, 1], [1, 0, 1, 0]]:
print(2)
print(2, 1)
print(n, n-1)
elif x in [[0, 1, 1, 0], [1, 0, 0, 1]]:
print(2)
print(2, 1)
print(n-1, n)
| 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]=='1' and l2[0]=='0' and l2[1]=='0':
print(1)
print(0+1,1+1)
if l1[0]=='1' and l1[1]=='0' and l2[0]=='0' and l2[1]=='0':
print(1)
print(1+1,0+1)
if l1[0]=='1' and l1[1]=='1' and l2[0]=='0' and l2[1]=='0':
print(0)
if l1[0]=='0' and l1[1]=='0' and l2[0]=='0' and l2[1]=='1':
print(1)
print(n-2+1,n-1+1)
if l1[0]=='0' and l1[1]=='1' and l2[0]=='0' and l2[1]=='1':
print(2)
print(0+1,1+1)
print(n-1+1,n-2+1)
if l1[0]=='1' and l1[1]=='0' and l2[0]=='0' and l2[1]=='1':
print(2)
print(0+1,1+1)
print(n-2+1,n-1+1)
if l1[0]=='1' and l1[1]=='1' and l2[0]=='0' and l2[1]=='1':
print(1)
print(n-1+1,n-2+1)
if l1[0]=='0' and l1[1]=='0' and l2[0]=='1' and l2[1]=='0':
print(1)
print(n-1+1,n-2+1)
if l1[0]=='0' and l1[1]=='1' and l2[0]=='1' and l2[1]=='0':
print(2)
print(0+1,1+1)
print(n-2+1,n-1+1)
if l1[0]=='1' and l1[1]=='0' and l2[0]=='1' and l2[1]=='0':
print(2)
print(0+1,1+1)
print(n-1+1,n-2+1)
if l1[0]=='1' and l1[1]=='1' and l2[0]=='1' and l2[1]=='0':
print(1)
print(n-2+1,n-1+1)
if l1[0]=='0' and l1[1]=='0' and l2[0]=='1' and l2[1]=='1':
print(0)
if l1[0]=='0' and l1[1]=='1' and l2[0]=='1' and l2[1]=='1':
print(1)
print(1+1,0+1)
if l1[0]=='1' and l1[1]=='0' and l2[0]=='1' and l2[1]=='1':
print(1)
print(0+1,1+1)
if l1[0]=='1' and l1[1]=='1' and l2[0]=='1' and l2[1]=='1':
print(2)
print(0+1,1+1)
print(1+1,0+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 math
from collections import defaultdict
for _ in range(ri()):
n=ri()
l=[]
for __ in range(n):l.append(list(input()))
ans=[]
x=[l[0][1],l[1][0]]
y=[l[n-2][n-1],l[n-1][n-2]]
z=x.count('0')+y.count('0')
if (x.count('1')==0 and y.count('0')==0) or (x.count('0')==0 and y.count('1')==0):
wi(0)
elif z==4 or z==0:
wi(2)
print(1,2)
print(2,1)
elif z==1:
if '0' in x:
if x[0]=='0':
wi(1)
print(2,1)
else:
wi(1)
print(1,2)
else:
if y[0]=='0':
wi(1)
print(n,n-1)
else:
wi(1)
print(n-1,n)
elif z==2:
wi(2)
if x[0]=='1':
print(1,2)
else:
print(2,1)
if y[0]=='0':
print(n-1,n)
else:
print(n,n-1)
else:
if '1' in x:
if x[0]=='1':
wi(1)
print(2,1)
else:
wi(1)
print(1,2)
else:
if y[0]=='1':
wi(1)
print(n,n-1)
else:
wi(1)
print(n-1,n)
| 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)
print(e[1])
print(e[3])
elif f == 1:
if e[0] != e[2]:
if e[0]:
print(1)
print(e[1])
else:
print(1)
print(e[3])
else:
if e[4]:
print(1)
print(e[5])
else:
print(1)
print(e[7])
elif f == 2:
if e[0] == e[2]:
print(0)
else:
print(2)
print(e[1])
if e[4] == e[2]:
print(e[5])
else:
print(e[7])
elif f == 3:
if e[0] != e[2]:
if not e[0]:
print(1)
print(e[1])
else:
print(1)
print(e[3])
else:
if not e[4]:
print(1)
print(e[5])
else:
print(1)
print(e[7])
else:
print(2)
print(e[1])
print(e[3])
| 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]:
ans.append(0)
else:
ans.append(2)
ans.append(st(0, 1))
ans.append(st(1, 0))
elif a[0] == a[1]:
ans.append(1)
if a[2] == a[1]:
ans.append(st(n - 1, n - 2))
else:
ans.append(st(n - 2, n - 1))
elif a[2] == a[3]:
ans.append(1)
if a[0] == a[2]:
ans.append(st(0, 1))
else:
ans.append(st(1, 0))
else:
ans.append(2)
if a[0] == a[2]:
ans.append(st(0, 1))
ans.append(st(n - 2, n - 1))
else:
ans.append(st(0, 1))
ans.append(st(n - 1, n - 2))
print('\n'.join(map(str, ans)))
| 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;
vector<string> s(n);
for (int i = 0; i < n; i++) cin >> s[i];
int ctr1 = (s[0][1] == '1') + (s[1][0] == '1') + (s[n - 1][n - 2] == '0') +
(s[n - 2][n - 1] == '0');
int ctr2 = (s[0][1] == '0') + (s[1][0] == '0') + (s[n - 1][n - 2] == '1') +
(s[n - 2][n - 1] == '1');
if (ctr1 >= 2) {
cout << 4 - ctr1 << '\n';
if (s[0][1] != '1') cout << 1 << " " << 2 << '\n';
if (s[1][0] != '1') cout << 2 << " " << 1 << '\n';
if (s[n - 1][n - 2] != '0') cout << n << " " << n - 1 << '\n';
if (s[n - 2][n - 1] != '0') cout << n - 1 << " " << n << '\n';
return;
}
if (ctr2 >= 2) {
cout << 4 - ctr2 << '\n';
if (s[0][1] != '0') cout << 1 << " " << 2 << '\n';
if (s[1][0] != '0') cout << 2 << " " << 1 << '\n';
if (s[n - 1][n - 2] != '1') cout << n << " " << n - 1 << '\n';
if (s[n - 2][n - 1] != '1') cout << n - 1 << " " << n << '\n';
return;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
cin >> t;
while (t--) solve();
}
| 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[m] == x) return m;
if (a[m] < x)
l = m + 1;
else
r = m - 1;
}
return -1;
}
long long gcd(long long x, long long y) {
if (x == 0)
return y;
else
return gcd(y % x, x);
}
long long lcm(long long x, long long y) { return (x * y) / gcd(x, y); }
bool isPrime(long long n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long i = 5; i * i <= n; i = i + 6) {
if (n % i == 0 || n % (i + 2) == 0) {
return false;
}
}
return true;
}
bool pdrome(string s) {
long long n = s.length();
for (long long i = 0; i < n / 2; i++) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
string need(string s) {
string a = s;
reverse(a.begin(), a.end());
a = s + '?' + a;
long long n = a.size();
long long pref[n];
memset(pref, 0, sizeof(pref));
for (long long i = 1; i < n + 1; i++) {
long long len = pref[i - 1];
while (len > 0 && a[len] != a[i]) len = pref[len - 1];
if (a[i] == a[len]) len++;
pref[i] = len;
}
return a.substr(0, pref[n - 1]);
}
long long mindig(long long x) {
long long ans = 9;
long long t = x;
while (x) {
ans = min(ans, x % 10);
x /= 10;
}
x = t;
return ans;
}
long long maxdig(long long x) {
long long ans = 0;
long long t = x;
while (x) {
ans = max(ans, x % 10);
x /= 10;
}
x = t;
return ans;
}
long long modpow(long long x, long long n, long long M) {
if (n == 0) return 1 % M;
long long u = modpow(x, n / 2, M);
u = (u * u) % M;
if (n % 2 == 1) u = (u * x) % M;
return u;
}
long long sumdigits(long long a) {
long long result = 0;
while (a > 0) {
result += a % 10;
a /= 10;
}
return result;
}
long long digits(long long n) { return floor(log10(n) + 1); }
const long long Node = 1e5 + 7;
vector<long long> adj[Node];
bool vis[Node] = {false};
void addedge(long long u, long long v) {
adj[u].push_back(v);
adj[v].push_back(u);
}
void bfs(long long u) {
vis[u] = true;
list<long long> q;
q.push_back(u);
while (!q.empty()) {
q.pop_front();
for (auto x : adj[u]) {
if (!vis[x]) {
vis[x] = true;
q.push_back(x);
}
}
}
}
void dfs(long long u) {
vis[u] = true;
cout << u << " ";
for (auto x : adj[u]) {
if (!vis[x]) {
dfs(x);
}
}
}
long long con1(string s) {
long long res = 0;
stringstream geek(s);
geek >> res;
return res;
}
string con2(long long num) {
string stri = to_string(num);
return stri;
}
long long countbits(long long k) {
long long cnt = log2(k);
return cnt;
}
bool check(string s, long long k1, long long j) {
for (long long i = j; i < k1 / 2 + j; i++) {
if (s[i] != s[i + k1 / 2]) return false;
}
return true;
}
void solve() {
long long n;
cin >> n;
char c[n][n];
for (long long i = 0; i < n; i++)
for (long long j = 0; j < n; j++) cin >> c[i][j];
if (c[0][2] == c[1][1] && c[0][2] == c[2][0]) {
if (c[0][2] == '0') {
if (c[0][1] == c[1][0]) {
if (c[0][1] == '1')
cout << 0 << endl;
else {
cout << 2 << endl;
cout << "1 2" << endl;
cout << "2 1" << endl;
}
} else {
cout << 1 << endl;
if (c[0][1] == '0') {
cout << "1 2" << endl;
} else
cout << "2 1" << endl;
}
} else {
if (c[0][1] == c[1][0]) {
if (c[0][1] == '0')
cout << 0 << endl;
else {
cout << 2 << endl;
cout << "1 2" << endl;
cout << "2 1" << endl;
}
} else {
cout << 1 << endl;
if (c[0][1] == '1') {
cout << "1 2" << endl;
} else
cout << "2 1" << endl;
}
}
} else {
vector<pair<long long, long long> > v;
if (c[0][1] == c[1][0]) {
if (c[0][1] == '0') {
long long i = 0, j = 2;
long long cnt = 0;
while (i < 3) {
if (c[i][j] == '0') {
v.push_back({i, j});
}
i++;
j--;
}
cout << v.size() << endl;
for (auto x : v) cout << x.first + 1 << " " << x.second + 1 << endl;
} else {
long long i = 0, j = 2;
while (i < 3) {
if (c[i][j] == '1') {
v.push_back({i, j});
}
i++;
j--;
}
cout << v.size() << endl;
for (auto x : v) cout << x.first + 1 << " " << x.second + 1 << endl;
}
} else {
long long i = 0, j = 2;
while (i < 3) {
if (c[i][j] == '0') {
v.push_back({i, j});
}
i++;
j--;
}
cout << 2 << endl;
if (v.size() == 1) {
cout << v[0].first + 1 << " " << v[0].second + 1 << endl;
if (c[0][1] == '1') {
cout << "1 2" << endl;
} else
cout << "2 1" << endl;
} else {
map<pair<long long, long long>, long long> mp;
for (auto x : v) mp[{x.first, x.second}] = 1;
i = 0, j = 2;
while (i < 3) {
if (mp[{i, j}] == 0) {
cout << i + 1 << " " << j + 1 << endl;
break;
}
i++;
j--;
}
if (c[0][1] == '0') {
cout << "1 2" << endl;
} else
cout << "2 1" << endl;
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| 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(1, 2)
print(2, 1)
if S[0][1] == "0" and S[1][0] == "0" and S[N - 1][N - 2] == "0" and S[N - 2][N - 1] == "1":
print(1)
print(N, N - 1)
if S[0][1] == "0" and S[1][0] == "0" and S[N - 1][N - 2] == "1" and S[N - 2][N - 1] == "0":
print(1)
print(N - 1, N)
if S[0][1] == "0" and S[1][0] == "0" and S[N - 1][N - 2] == "1" and S[N - 2][N - 1] == "1":
print(0)
if S[0][1] == "0" and S[1][0] == "1" and S[N - 1][N - 2] == "0" and S[N - 2][N - 1] == "0":
print(1)
print(1, 2)
if S[0][1] == "0" and S[1][0] == "1" and S[N - 1][N - 2] == "0" and S[N - 2][N - 1] == "1":
print(2)
print(1, 2)
print(N - 1, N)
if S[0][1] == "0" and S[1][0] == "1" and S[N - 1][N - 2] == "1" and S[N - 2][N - 1] == "0":
print(2)
print(1, 2)
print(N, N - 1)
if S[0][1] == "0" and S[1][0] == "1" and S[N - 1][N - 2] == "1" and S[N - 2][N - 1] == "1":
print(1)
print(2, 1)
if S[0][1] == "1" and S[1][0] == "0" and S[N - 1][N - 2] == "0" and S[N - 2][N - 1] == "0":
print(1)
print(2, 1)
if S[0][1] == "1" and S[1][0] == "0" and S[N - 1][N - 2] == "0" and S[N - 2][N - 1] == "1":
print(2)
print(2, 1)
print(N - 1, N)
if S[0][1] == "1" and S[1][0] == "0" and S[N - 1][N - 2] == "1" and S[N - 2][N - 1] == "0":
print(2)
print(2, 1)
print(N, N - 1)
if S[0][1] == "1" and S[1][0] == "0" and S[N - 1][N - 2] == "1" and S[N - 2][N - 1] == "1":
print(1)
print(1, 2)
if S[0][1] == "1" and S[1][0] == "1" and S[N - 1][N - 2] == "0" and S[N - 2][N - 1] == "0":
print(0)
if S[0][1] == "1" and S[1][0] == "1" and S[N - 1][N - 2] == "0" and S[N - 2][N - 1] == "1":
print(1)
print(N - 1, N)
if S[0][1] == "1" and S[1][0] == "1" and S[N - 1][N - 2] == "1" and S[N - 2][N - 1] == "0":
print(1)
print(N, N - 1)
if S[0][1] == "1" and S[1][0] == "1" and S[N - 1][N - 2] == "1" and S[N - 2][N - 1] == "1":
print(2)
print(1, 2)
print(2, 1)
if __name__ == '__main__':
main()
| 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]:
wynik += [(n-1, n)]
elif siatka[-1][-2] == siatka[-2][-1]:
if siatka[-1][-2] == siatka[0][1]:
wynik += [(1, 2)]
if siatka[-2][-1] == siatka[1][0]:
wynik += [(2, 1)]
else:
wynik += [(1, 2)]
if siatka[-1][-2] == siatka[1][0]:
wynik += [(n, n-1)]
else:
wynik += [(n - 1, n)]
print(len(wynik))
for x in wynik:
print(x[0], x[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 - 2][n - 1];
if (a[0] == a[1] && a[2] == a[3]) {
if (a[0] == a[2]) {
cout << 2 << endl;
cout << 2 << " " << 1 << endl;
cout << 1 << " " << 2 << endl;
} else
cout << 0 << endl;
} else if (a[0] == a[1] || a[2] == a[3]) {
cout << 1 << endl;
if (a[0] == a[1]) {
if (a[0] == a[2])
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
} else {
if (a[0] == a[2])
cout << 1 << " " << 2 << endl;
else
cout << 2 << " " << 1 << endl;
}
} else {
cout << 2 << endl;
if (a[0] == '1') cout << 1 << " " << 2 << endl;
if (a[1] == '1') cout << 2 << " " << 1 << endl;
if (a[2] == '0') cout << n << " " << n - 1 << endl;
if (a[3] == '0') cout << n - 1 << " " << n << endl;
}
}
return 0;
}
| 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'
r[1] = '1'
else:
if l[0] == l[1] and l[0] == '1':
r[0] = '0'
r[1] = '0'
else:
if r[0]==r[1] and r[0] == '1':
l[0] = '0'
l[1] = '0'
else:
if r[0] == r[1] and r[0] == '0':
l[0] = '1'
l[1] = '1'
else:
r[0] = '1'
r[1] = '1'
l[0] = '0'
l[1] = '0'
cnt = 0
zj = mat[0][1]
jz = mat[1][0]
bw = mat[-1][-2]
wb = mat[-2][-1]
#print(bw, mat[-1][-2])
zmien = []
if zj != l[0]:
cnt += 1
zmien.append([1,2])
if jz != l[1]:
cnt += 1
zmien.append([2,1])
if bw != r[0]:
cnt += 1
zmien.append([n,n-1])
if wb != r[1]:
cnt +=1
zmien.append([n-1,n])
print(cnt)
for i in zmien:
print(*i)
| 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]) {
cout << 0 << endl;
} else if (s[n - 1][n - 2] == s[n - 2][n - 1] &&
s[n - 1][n - 2] == s[0][1]) {
cout << 2 << endl;
cout << n << " " << n - 1 << endl;
cout << n - 1 << " " << n << endl;
} else if (s[n - 1][n - 2] != s[n - 2][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 1 << endl;
cout << n << " " << n - 1 << endl;
} else {
cout << 1 << endl;
cout << n - 1 << " " << n << endl;
}
}
} else {
if (s[n - 1][n - 2] == s[n - 2][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 1 << endl;
cout << 1 << " " << 2 << endl;
} else if (s[n - 1][n - 2] == s[1][0]) {
cout << 1 << endl;
cout << 2 << " " << 1 << endl;
}
} else {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 2 << endl;
cout << 1 << " " << 2 << endl;
cout << n - 1 << " " << n << endl;
} else if (s[n - 1][n - 2] == s[1][0]) {
cout << 2 << endl;
cout << 2 << " " << 1 << endl;
cout << n - 1 << " " << n << endl;
}
}
}
}
return 0;
}
| 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++) : *iS++);
}
inline void qread() {}
template <class T1, class... T2>
inline void qread(T1& IEE, T2&... ls) {
register T1 __ = 0, ___ = 1;
register char ch;
while (!isdigit(ch = gc())) ___ = (ch == '-') ? -___ : ___;
do {
__ = (__ << 1) + (__ << 3) + (ch ^ 48);
} while (isdigit(ch = gc()));
__ *= ___;
IEE = __;
qread(ls...);
return;
}
template <class T>
inline void qreadarr(T beg, T end) {
while (beg != end) {
qread(*beg);
beg++;
}
}
inline void flush() {
fwrite(obuf, 1, oS - obuf, stdout);
oS = obuf;
return;
}
inline void putc_(char _x) {
*oS++ = _x;
if (oS == oT) flush();
}
inline void qwrite() {}
template <class T1, class... T2>
inline void qwrite(T1 IEE, T2... ls) {
if (!IEE) putc_('0');
if (IEE < 0) putc_('-'), IEE = -IEE;
while (IEE) _st[++_qr] = IEE % 10 + '0', IEE /= 10;
while (_qr) putc_(_st[_qr--]);
qwrite(ls...);
return;
}
inline void putstr_(const char* IEE) {
int p = 0;
while (IEE[p] != '\0') {
putc_(IEE[p++]);
}
}
inline void puts_(const char* IEE) {
putstr_(IEE);
putc_('\n');
}
template <class T>
inline void qwritearr(T beg, T end, const char* IEE = {" "},
const char* EE = {"\n"}) {
while (beg != end) {
qwrite(*beg);
beg++;
putstr_(IEE);
}
putstr_(EE);
}
struct Flusher_ {
~Flusher_() { flush(); }
} io_flusher;
} // namespace IO
using namespace IO;
const int N = 205;
char str[N][N];
void Solve() {
int n;
cin >> n;
for (register int(i) = 1; (i) <= n; (i)++) cin >> str[i] + 1;
if (str[1][2] != str[2][1]) {
if (str[1][2] == '1') {
if (str[n][n - 1] == str[n - 1][n]) {
if (str[n][n - 1] == '1') {
cout << 1 << endl;
cout << 1 << " " << 2 << endl;
} else {
cout << 1 << endl;
cout << 2 << " " << 1 << endl;
}
} else {
cout << 2 << endl;
cout << 2 << " " << 1 << endl;
if (str[n][n - 1] == '1')
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
}
} else {
if (str[n][n - 1] == str[n - 1][n]) {
if (str[n][n - 1] == '1') {
cout << 1 << endl;
cout << 2 << " " << 1 << endl;
} else {
cout << 1 << endl;
cout << 1 << " " << 2 << endl;
}
} else {
cout << 2 << endl;
cout << 1 << " " << 2 << endl;
if (str[n][n - 1] == '1')
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
}
}
} else {
if (str[n][n - 1] == str[n - 1][n]) {
if (str[n][n - 1] != str[1][2])
cout << 0 << endl;
else {
cout << 2 << endl;
cout << 1 << " " << 2 << endl;
cout << 2 << " " << 1 << endl;
}
} else {
if (str[n][n - 1] == str[1][2]) {
cout << 1 << endl;
cout << n << " " << n - 1 << endl;
} else {
cout << 1 << endl;
cout << n - 1 << " " << n << endl;
}
}
}
}
int main() {
int t;
cin >> t;
while (t--) Solve();
return 0;
}
| 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, pick2 = (0, 1), (1, 0)
elif zeros in [1, 3]:
cells = 1
target = '0'
if zeros == 3:
target = '1'
if grid[1][0] == target:
pick1 = (0, 1)
elif grid[0][1] == target:
pick1 = (1, 0)
elif grid[n - 1][n - 2] == target:
pick1 = (n - 2, n - 1)
else:
pick1 = (n - 1, n - 2)
elif grid[0][1] != grid[1][0]:
cells = 2
pick1 = (1, 0)
if grid[-1][-2] == grid[0][1]:
pick2 = (n - 1, n - 2)
else:
pick2 = (n - 2, n - 1)
print(cells)
if pick1:
pick1 = map(str, map(lambda t: t + 1, pick1))
print(' '.join(pick1))
if pick2:
pick2 = map(str, map(lambda t: t + 1, pick2))
print(' '.join(pick2))
if __name__=='__main__':
for _ in range(int(input().strip())):
solve()
| 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 I debugging ? Check if I'm using same variable name in two places
# fun() returning empty list ? check new=temp[:] or new=temp
mod=1000000007
'''def DFS(gr):
pth0=[]
pth1=[]
path=[]
vis=[[False for i in range(n)] for i in range(n)]
def dfs(x,y):
path.append((x,y))
vis[x][y]=True
for dx,dy in zip([],[])'''
_T_=inin()
for _t_ in range(_T_):
n=inin()
gr=[]
for i in range(n):
gr.append(inst())
#DFS(gr)
p01=[]
p10=[]
fr=[(-1,-3),(-2,-2),(-3,-1)]
sr=[(-1,-2),(-2,-1)]
for i,j in fr:
if gr[i][j]=='1':
p01.append((i,j))
else:
p10.append((i,j))
for i,j in sr:
if gr[i][j]=='1':
p10.append((i,j))
else:
p01.append((i,j))
#pr(p01,p10)
if len(p01)<=2 and len(p10)<=2:
if len(p01)>len(p10):
pr(len(p01))
for i,j in p01:
pr(n+i+1,n+j+1)
else:
pr(len(p10))
for i,j in p10:
pr(n+i+1,n+j+1)
elif len(p01)<len(p10):
pr(len(p01))
for i,j in p01:
pr(n+i+1,n+j+1)
else:
pr(len(p10))
for i,j in p10:
pr(n+i+1,n+j+1)
| 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)
print(1,2)
print(2,1)
elif len(set([a1,a2]))==1 and len(set([b1,b2]))==1:
print(0)
else:
if len(set([a1,a2]))==2 and len(set([b1,b2]))==1:
if a1==b1:
print(1)
print(1,2)
elif a2==b1:
print(1)
print(2,1)
elif len(set([a1,a2]))==1 and len(set([b1,b2]))==2:
if b1==a1:
print(1)
print(n,n-1)
elif b2==a1:
print(1)
print(n-1,n)
elif len(set([a1,a2]))==2 and len(set([b1,b2]))==2:
if a1==b1:
print(2)
print(1,2)
print(n-1,n)
else:
print(2)
print(1,2)
print(n,n-1)
| 8 |
PYTHON3
|
"""
pppppppppppppppppppp
ppppp ppppppppppppppppppp
ppppppp ppppppppppppppppppppp
pppppppp pppppppppppppppppppppp
pppppppppppppppppppppppppppppppp
pppppppppppppppppppppppp
ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppp
pppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppp
ppppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppp
ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp
pppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppp
ppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppp
pppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppp
pppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppp
ppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppp
pppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppppp
ppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppppp
pppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp
ppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppp
pppppppppppppppppppppppp
pppppppppppppppppppppppppppppppp
pppppppppppppppppppppp pppppppp
ppppppppppppppppppppp ppppppp
ppppppppppppppppppp ppppp
pppppppppppppppppppp
"""
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
# sys.setrecursionlimit(2 * (10 ** 5))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(str(var)+"\n")
def outa(*var, end="\n"): sys.stdout.write(' '.join(map(str, var)) + end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
n = int(data())
mat = [list(data()) for i in range(n)]
answer = []
if mat[0][1] == mat[1][0] == mat[-1][-2] == mat[-2][-1]:
answer.append((1, 2))
answer.append((2, 1))
elif mat[0][1] == mat[1][0] and mat[-1][-2] == mat[-2][-1]:
pass
elif mat[0][1] != mat[1][0] and mat[-1][-2] == mat[-2][-1]:
if mat[0][1] == mat[-1][-2]:
answer.append((1, 2))
else:
answer.append((2, 1))
elif mat[0][1] == mat[1][0] and mat[-1][-2] != mat[-2][-1]:
if mat[-1][-2] == mat[0][1]:
answer.append((n, n-1))
else:
answer.append((n-1, n))
else:
if mat[0][1] == mat[-1][-2]:
answer.append((1, 2))
answer.append((n-1, n))
else:
answer.append((1, 2))
answer.append((n, n-1))
out(len(answer))
for i in answer:
outa(*i)
| 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
ans.append(n-1)
ans.append(n-2)
if(v4=='1'):
c+=1
ans.append(n-2)
ans.append(n-1)
else:
if (v3 == '0'):
c += 1
ans.append(n - 1)
ans.append(n - 2)
if (v4 == '0'):
c += 1
ans.append(n - 2)
ans.append(n - 1)
elif(v3==v4):
if (v3 == '1'):
if (v1 == '1'):
c += 1
ans.append(0)
ans.append(1)
if (v2 == '1'):
c += 1
ans.append(1)
ans.append(0)
else:
if (v1 == '0'):
c += 1
ans.append(0)
ans.append(1)
if (v2 == '0'):
c += 1
ans.append(1)
ans.append(0)
else:
if(v1=='0'):
c+=1
ans.append(0)
ans.append(1)
elif v2=='0':
c+=1
ans.append(1)
ans.append(0)
if(v3=='1'):
c+=1
ans.append(n-1)
ans.append(n-2)
elif v4=='1':
c+=1
ans.append(n-2)
ans.append(n-1)
print(c)
if(c>0):
print(ans[0]+1,ans[1]+1)
if(c>1):
print(ans[2]+1,ans[3]+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:
break
for e in range(0,2):
if flag == 1:
break
for r in range(0,2):
if flag:
break
ans = 0
if r!=int(d):
ans += 1
if e!=int(c):
ans += 1
if w!=int(b):
ans += 1
if (int(a)!=q):
ans += 1
if (q==w and e==r and q!=e) and (ans<=2):
print(ans)
if r!=int(d):
print(n-1,n)
if e!=int(c):
print(n,n-1)
if w!=int(b):
print(2,1)
if q!=int(a):
print(1,2)
flag = 1
break
| 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:
print('1')
print(n-1,n)
elif d==a:
print('1')
print(n,n-1)
else:
print('0')
elif c==d:
if c==a and c==b:
print('2')
print('1 2')
print('2 1')
elif c==a:
print('1')
print('1 2')
elif c==b:
print('1')
print('2 1')
else:
print('0')
else:
print('2')
print('1 2')
if a==c:
print(n,n-1)
else:
print(n-1,n)
| 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
ans.append([str(n), str(n-1)])
if(grid[n-2][n-1]=='0'):
no+=1
ans.append([str(n-1), str(n)])
print(no)
for i in range(no):
print(' '.join(ans[i]))
elif(grid[0][1]=='1' and grid[1][0]=='1'):
no= 0
ans = []
if(grid[n-1][n-2]=='1'):
no+=1
ans.append([str(n), str(n-1)])
if(grid[n-2][n-1]=='1'):
no+=1
ans.append([str(n-1), str(n)])
print(no)
for i in range(no):
print(' '.join(ans[i]))
elif(grid[n-2][n-1]=='0' and grid[n-1][n-2]=='0'):
no= 0
ans = []
if(grid[0][1]=='0'):
no+=1
ans.append([str(1), str(2)])
if(grid[1][0]=='0'):
no+=1
ans.append([str(2), str(1)])
print(no)
for i in range(no):
print(' '.join(ans[i]))
elif(grid[n-2][n-1]=='1' and grid[n-1][n-2]=='1'):
no= 0
ans = []
if(grid[0][1]=='1'):
no+=1
ans.append([str(1), str(2)])
if(grid[1][0]=='1'):
no+=1
ans.append([str(2), str(1)])
print(no)
for i in range(no):
print(' '.join(ans[i]))
else:
ans = []
if(grid[1][0]!= grid[0][1]):
if(grid[n-1][n-2]!= grid[n-2][n-1]):
if(grid[n-2][n-1]==grid[0][1]):
ans.append(['1', '2'])
ans.append([str(n), str(n-1)])
if(grid[n-2][n-1]==grid[1][0]):
ans.append(['1', '2'])
ans.append([str(n-1), str(n)])
print(len(ans))
for x in ans:
print(' '.join(x))
| 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] == d1[2] == d2[0]:
ans.append((n-1, n))
ans.append((n, n-1))
elif d1[0] == d1[1] == d1[2] != d2[0]:
pass
else:
if d1[0] == d2[0]:
ans.append((n, n-2))
if d1[1] == d2[0]:
ans.append((n-1, n-1))
if d1[2] == d2[0]:
ans.append((n-2, n))
elif d1.count('1') > d1.count('0'):
if d1[0] == '0':
ans.append((n, n-2))
if d1[1] == '0':
ans.append((n-1, n-1))
if d1[2] == '0':
ans.append((n-2, n))
if d2[0] == '1':
ans.append((n, n-1))
if d2[1] == '1':
ans.append((n-1, n))
else:
if d1[0] == '1':
ans.append((n, n-2))
if d1[1] == '1':
ans.append((n-1, n-1))
if d1[2] == '1':
ans.append((n-2, n))
if d2[0] == '0':
ans.append((n, n-1))
if d2[1] == '0':
ans.append((n-1, n))
print(len(ans))
for a in ans:
print(a[0], a[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])
print(len(ans))
for item in ans:
print(item[0], item[1])
elif (c == d):
ans = []
if c == a:
ans.append([1, 2])
if c == b:
ans.append([2, 1])
print(len(ans))
for item in ans:
print(item[0], item[1])
else:
if (a == c) and (b == d):
print(2)
print(1, 2)
print(n, n-1)
else:
print(2)
print(2, 1)
print(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 << 0 << endl;
} else if (s[n - 1][n - 2] == s[n - 2][n - 1] &&
s[n - 1][n - 2] == s[0][1]) {
cout << 2 << endl;
cout << n << " " << n - 1 << endl;
cout << n - 1 << " " << n << endl;
} else if (s[n - 1][n - 2] != s[n - 2][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 1 << endl;
cout << n << " " << n - 1 << endl;
} else {
cout << 1 << endl;
cout << n - 1 << " " << n << endl;
}
}
} else {
if (s[n - 1][n - 2] == s[n - 2][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 1 << endl;
cout << 1 << " " << 2 << endl;
} else if (s[n - 1][n - 2] == s[1][0]) {
cout << 1 << endl;
cout << 2 << " " << 1 << endl;
}
} else {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 2 << endl;
cout << 1 << " " << 2 << endl;
cout << n - 1 << " " << n << endl;
} else if (s[n - 1][n - 2] == s[1][0]) {
cout << 2 << endl;
cout << 2 << " " << 1 << endl;
cout << n - 1 << " " << n << endl;
}
}
}
}
return 0;
}
| 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:
if g2 == g3:
ans.append([2,1])
else:
ans.append([1,2])
elif g2 == g1 and g3 != g4:
if g3 == g2:
ans.append([grid-1,grid])
else:
ans.append([grid,grid-1])
else:
if g3 == g2:
ans.append([1,2])
ans.append([grid-1,grid])
else:
ans.append([2,1])
ans.append([grid-1,grid])
if not ans:
print('0')
else:
print(len(ans))
for i in ans:
print(i[0], i[1])
def main():
# Read test case num
case = int(input())
for i in range(0,case):
grid = int(input())
li = []
for j in range(grid):
li.append(list(map(str,input().split())))
mySolver(li, grid)
main()
| 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:
print(2)
print(1, 2)
print(2, 1)
elif a2 != a1 and b1 == b2:
print(1)
if a1 != b1:
print(2, 1)
else:
print(1, 2)
elif a2 == a1 and b2 != b1:
print(1)
if a1 != b1:
print(n - 1, n)
else:
print(n, n - 1)
elif a2 != a1 and b1 != b2:
print(2)
if a1 != b1:
print(1, 2)
print(n, n - 1)
else:
print(1, 2)
print(n - 1, n)
| 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)
print(2,1)
if a==1 and b==0 and c==0 and d==0:#
print(1)
print(2,1)
if a==0 and b==1 and c==0 and d==0:#
print(1)
print(1,2)
if a==1 and b==1 and c==0 and d==0:#2
print(0)
if a==0 and b==0 and c==1 and d==1:#1
print(0)
if a==0 and b==0 and c==1 and d==0:#
print(1)
print(n,n-1)
if a==0 and b==0 and c==0 and d==1:#
print(1)
print(n-1,n)
if a==0 and b==1 and c==0 and d==1:
print(2)
print(2,1)
print(n-1,n)
if a==0 and b==1 and c==1 and d==1:
print(1)
print(2,1)
if a==0 and b==1 and c==1 and d==0:
print(2)
print(2,1)
print(n,n-1)
if a==1 and b==0 and c==0 and d==1:
print(2)
print(2,1)
print(n,n-1)
if a==1 and b==0 and c==1 and d==1:
print(1)
print(1,2)
if a==1 and b==0 and c==1 and d==0:
print(2)
print(1,2)
print(n,n-1)
if a==1 and b==1 and c==0 and d==1:
print(1)
print(n,n-1)
if a==1 and b==1 and c==1 and d==0:
print(1)
print(n-1,n)
| 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:
change.append([n-1,n-2])
change.append([n-2,n-1])
elif c!=d:
if c==a:
change.append([n-1,n-2])
else:
change.append([n-2,n-1])
elif c==d:
if a==c:
change.append([0,1])
else:
change.append([1,0])
else:
if a!=0:
change.append([0,1])
else:
change.append([1,0])
if c!=1:
change.append([n-1,n-2])
else:
change.append([n-2,n-1])
print(len(change))
for i in change:
print(i[0]+1,i[1]+1)
| 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[1][1]==arr[0][1]:
ans.append([1,1])
if arr[0][2]==arr[0][1]:
ans.append([0,2])
if len(ans)<3:
print(len(ans))
for i in range(len(ans)):
print(ans[i][0]+1,ans[i][1]+1)
else:
print(2)
print(1,2)
print(2,1)
else:
if arr[1][1]==arr[2][0] and arr[1][1]==arr[0][2]:
print(1)
if arr[1][0]==arr[1][1]:
print(2,1)
else:
print(1,2)
continue
if arr[2][0]==arr[1][1]:
print(2)
if arr[0][2]==arr[1][0]:
print(1,2)
else:
print(2,1)
print(1,3)
else:
if arr[1][1]==arr[0][2]:
print(2)
print(3,1)
if arr[2][0]!=arr[1][0]:
print(2,1)
else:
print(1,2)
else:
print(2)
print(2,2)
if arr[1][1]!=arr[1][0]:
print(2,1)
else:
print(1,2)
| 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
rep = []
if d1 in [0,2] and f1 in [0,2]:
if d1 != f1:
print(0)
else:
print(2)
elif d1==1 and f1 == 1:
print(2)
else:
print(1)
if d1 == 0:
if lines[-1][-2] == '0':
print(size,size-1)
if lines[-2][-1] == '0':
print(size-1,size)
elif d1 == 1:
if f1 == 0:
if lines[0][1] == '0':
print(1, 2)
if lines[1][0] == '0':
print(2, 1)
if f1 == 1:
if lines[0][1] == '0':
print(1, 2)
if lines[1][0] == '0':
print(2, 1)
if lines[-1][-2] == '1':
print(size, size-1)
if lines[-2][-1] == '1':
print(size-1, size)
if f1 == 2:
if lines[0][1] == '1':
print(1, 2)
if lines[1][0] == '1':
print(2, 1)
else:
if lines[-1][-2] == '1':
print(size,size-1)
if lines[-2][-1] == '1':
print(size-1,size)
| 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")
print("1 2")
print("2 1")
# print("k")
elif ((x1==x2)and(y1==y2)):
print("0")
elif ((x1==x2) and (y1!=y2)):
if ((x1=='0') and (y1=='0')):
print("1")
print(n-1,n)
elif ((x1=='0') and (y2=='0')):
print("1")
print(n, n-1)
elif ((x1=='1') and (y1=='1')):
print("1")
print(n-1, n)
elif ((x1=='1') and (y2=='1')):
print("1")
print(n, n-1)
elif ((x1!=x2) and (y1==y2)):
if ((y1=='0') and (x1=='0')):
print("1")
print("1 2")
elif ((y1=='0') and (x2=='0')):
print("1")
print("2 1")
elif ((y1=='1') and (x1=='1')):
print("1")
print("1 2")
elif ((y1=='1') and (x2=='1')):
print("1")
print("2 1")
elif ((x1!=x2) and (y1!=y2)):
if (x1=='1' and y1=='1'):
print("2")
print("2 1")
print(n-1,n)
elif (x1=='1' and y2=='1'):
print("2")
print("2 1")
print(n, n-1)
elif (x1=='0' and y1=='0'):
print("2")
print("2 1")
print(n-1, n)
elif (x1=='0' and y2=='0'):
print("2")
print("2 1")
print(n,n-1)
| 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++)
for (long long j = (0); j < (n); j++) cin >> a[i][j];
if (a[0][1] == a[1][0]) {
if ((a[n - 1][n - 2] == a[n - 2][n - 1]) && a[n - 1][n - 2] == a[0][1]) {
cout << 2 << endl;
cout << n << " " << n - 1 << endl << n - 1 << " " << n << endl;
} else {
if (a[0][1] == a[n - 1][n - 2])
cout << 1 << endl << n << " " << n - 1 << endl;
else if (a[0][1] == a[n - 2][n - 1])
cout << 1 << endl << n - 1 << " " << n << endl;
else
cout << 0 << endl;
}
} else if (a[n - 1][n - 2] == a[n - 2][n - 1]) {
if (a[0][1] == a[n - 1][n - 2])
cout << 1 << endl << 1 << " " << 2 << endl;
else if (a[1][0] == a[n - 2][n - 1])
cout << 1 << endl << 2 << " " << 1 << endl;
else
cout << 0 << endl;
} else {
if (a[0][1] == a[n - 1][n - 2]) {
cout << 2 << endl;
cout << 2 << " " << 1 << endl << n << " " << n - 1 << endl;
} else if (a[0][1] == a[n - 2][n - 1]) {
cout << 2 << endl;
cout << 2 << " " << 1 << endl << n - 1 << " " << n << endl;
} else if (a[1][0] == a[n - 1][n - 2]) {
cout << 2 << endl;
cout << 1 << " " << 2 << endl << n << " " << n - 1 << endl;
} else if (a[1][0] == a[n - 2][n - 1]) {
cout << 2 << endl;
cout << 1 << " " << 2 << endl << n - 1 << " " << n << endl;
}
}
}
return 0;
}
| 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]) {
x[num] = n - 1;
y[num] = n;
num++;
}
if (str[n][n - 1] == str[2][1]) {
x[num] = n;
y[num] = n - 1;
num++;
}
} else if (str[n - 1][n] == str[n][n - 1]) {
if (str[2][1] == str[n - 1][n]) {
x[num] = 2;
y[num] = 1;
num++;
}
if (str[1][2] == str[n - 1][n]) {
x[num] = 1;
y[num] = 2;
num++;
}
} else {
x[num] = 1;
y[num] = 2;
num++;
if (str[n - 1][n] == str[2][1]) {
x[num] = n - 1;
y[num] = n;
num++;
} else {
x[num] = n;
y[num] = n - 1;
num++;
}
}
printf("%d\n", num);
for (int i = 0; i < num; i++) printf("%d %d\n", x[i], y[i]);
}
return 0;
}
| 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(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
long long int power(long long int a, long long int b) {
if (b == 0) return 1;
if (b % 2 == 0) return (power((a * a) % 998244353, b / 2)) % 998244353;
return (a * (power((a * a) % 998244353, b / 2)) % 998244353) % 998244353;
}
long long int modInv(long long int n) { return power(n, 1000000007 - 2); }
long long int nCr(long long int n, long long int r,
long long int p = 1000000007) {
if (r == 0) return 1;
long long int Fact[n + 1];
Fact[0] = 1;
for (long long int i = 1; i <= n; i++) {
Fact[i] = (Fact[i - 1] * i) % p;
}
return (((Fact[n] * modInv(Fact[r])) % 1000000007) *
(modInv(Fact[n - r]) % 1000000007)) %
1000000007;
}
double PI = 3.14159265359;
void solve() {
long long int n, i;
cin >> n;
string S[n];
for (i = 0; i < n; i++) cin >> S[i];
vector<pair<long long int, long long int> > Ans;
if (S[0][1] == S[1][0]) {
if (S[n - 2][n - 1] == S[0][1]) {
Ans.push_back({n - 1, n});
}
if (S[n - 1][n - 2] == S[0][1]) {
Ans.push_back({n, n - 1});
}
} else if (S[n - 1][n - 2] == S[n - 2][n - 1]) {
if (S[n - 2][n - 1] == S[0][1]) {
Ans.push_back({1, 2});
}
if (S[n - 1][n - 2] == S[1][0]) {
Ans.push_back({2, 1});
}
} else {
if (S[0][1] == '0') {
Ans.push_back({1, 2});
} else {
Ans.push_back({2, 1});
}
if (S[n - 1][n - 2] == '1') {
Ans.push_back({n, n - 1});
} else {
Ans.push_back({n - 1, n});
}
}
cout << Ans.size() << endl;
for (i = 0; i < Ans.size(); i++) {
cout << Ans[i].first << " " << Ans[i].second << endl;
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t = 1;
cin >> t;
for (long long int i = 1; i <= t; i++) {
solve();
}
}
| 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:
continue
count = 0
if a == b:
if c == a:
count += 1
if d == a:
count += 1
print(count)
if c == a:
print('%d %d'%(n-1, n))
if d == a:
print('%d %d'%(n, n-1))
elif c == d:
if c == a:
count += 1
if c == b:
count += 1
print(count)
if c == a:
print('%d %d'%(1, 2))
if c == b:
print('%d %d'%(2, 1))
else:
if a != 0:
count += 1
if b != 0:
count += 1
if c!= 1:
count += 1
if d != 1:
count += 1
print(count)
if a != 0:
print('%d %d'%(1, 2))
if b != 0:
print('%d %d'%(2, 1))
if c != 1:
print('%d %d'%(n-1, n))
if d != 1:
print('%d %d'%(n, n-1))
| 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():
def stdin_wrapper():
while True:
yield sys.stdin.readline()
inputs = stdin_wrapper()
def input_wrapper():
return next(inputs)
def get_str():
if is_debug():
return input_wrapper()
return input()
def get(_type):
if _type == str:
return get_str()
return _type(input_wrapper())
def get_arr(_type):
return [_type(x) for x in input_wrapper().split()]
def tuplerize(method):
def wrap(*args, **kwargs):
res = method(*args, **kwargs)
if not isinstance(res, (tuple, list)):
res = (res, )
return res
return wrap
''' Solution '''
@tuplerize
def solve(data):
c = [
int(data[0][1]),
int(data[1][0]),
int(data[-2][-1]),
int(data[-1][-2]),
]
coords = [(1,2), (2,1), (len(data)-1, len(data)), (len(data), len(data)-1)]
if c[0] == c[1] and c[2] == c[3] and c[0] != c[2]:
return 0
res = []
if c[0] == c[1]:
target = 1 - c[0]
if c[2] != target:
res.append(coords[2])
if c[3] != target:
res.append(coords[3])
elif c[2] == c[3]:
target = 1 - c[2]
if c[0] != target:
res.append(coords[0])
if c[1] != target:
res.append(coords[1])
else:
target = 0
if c[0] != target:
res.append(coords[0])
if c[1] != target:
res.append(coords[1])
target = 1 - target
if c[2] != target:
res.append(coords[2])
if c[3] != target:
res.append(coords[3])
return '{}\n{}'.format(len(res), '\n'.join([' '.join(list(map(str, c))) for c in res]))
t = get(int)
for _ in range(t):
rows = get(int)
data = []
for _ in range(rows):
data.append(get_str())
print(*solve(data))
| 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]), int(G[1][0])
f1,f2 = int(G[n-2][n-1]), int(G[n-1][n-2])
if s1+s2 == 2:
s = f1+f2
print(s)
if f1 == 1:
print(n-1, n)
if f2 == 1:
print(n, n-1)
elif s1+s2 == 0:
s = 2 - (f1+f2)
print(s)
if f1 == 0:
print(n-1, n)
if f2 == 0:
print(n, n-1)
else:
if f1+f2>0:
s = 2 - (f1+f2) + 1
print(s)
if f1 == 0:
print(n-1, n)
if f2 == 0:
print(n, n-1)
if s1 == 1:
print(1,2)
if s2==1:
print(2,1)
else:
s = 2 - (s1+s2)
print(s)
if s1==0:
print(1,2)
if s2==0:
print(2,1)
| 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' and grid[n-2][n-1] == '0':
print(0)
continue
elif grid[0][1] == '0' and grid[1][0] == '0':
if grid[n-1][n-2] != '1':
count+=1
p.append((n-1,n-2))
if grid[n-2][n-1] != '1':
count+=1
p.append((n-2,n-1))
elif grid[0][1] == '1' and grid[1][0] == '1':
if grid[n-1][n-2] != '0':
count+=1
p.append((n-1,n-2))
if grid[n-2][n-1] != '0':
count+=1
p.append((n-2,n-1))
elif grid[n-1][n-2] == '0' and grid[n-2][n-1] == '0':
if grid[0][1] != '1':
count+=1
p.append((0,1))
if grid[1][0] != '1':
count+=1
p.append((1,0))
elif grid[n-1][n-2] == '1' and grid[n-2][n-1] == '1':
if grid[0][1] != '0':
count+=1
p.append((0,1))
if grid[1][0] != '0':
count+=1
p.append((1,0))
elif grid[0][1] == '0' and grid[1][0] == '1':
if grid[n-1][n-2] == '1' and grid[n-2][n-1] == '1':
p.append((1,0))
count+=1
elif grid[n-1][n-2] == '0' and grid[n-2][n-1] == '0':
p.append((0,1))
count+=1
elif grid[n-1][n-2] == '1' and grid[n-2][n-1] == '0':
p.append((n-1,n-2))
p.append((0,1))
count+=2
elif grid[n-1][n-2] == '0' and grid[n-2][n-1] == '1':
p.append((1,0))
p.append((n-1,n-2))
count+=2
elif grid[0][1] == '1' and grid[1][0] == '0':
if grid[n-1][n-2] == '1' and grid[n-2][n-1] == '1':
p.append((0,1))
count+=1
elif grid[n-1][n-2] == '0' and grid[n-2][n-1] == '0':
p.append((1,0))
count+=1
elif grid[n-1][n-2] == '1' and grid[n-2][n-1] == '0':
p.append((n-1,n-2))
p.append((1,0))
count+=2
elif grid[n-1][n-2] == '0' and grid[n-2][n-1] == '1':
p.append((1,0))
p.append((n-2,n-1))
count+=2
elif grid[n-1][n-2] == '0' and grid[n-2][n-1] == '1':
if grid[0][1] == '1' and grid[1][0] == '1':
p.append((n-1,n-2))
count+=1
elif grid[0][1] == '0' and grid[1][0] == '0':
p.append((n-1,n-2))
count+=1
elif grid[0][1] == '1' and grid[1][0] == '0':
p.append((1,0))
p.append((n-2,n-1))
count += 2
else:
p.append((0,1))
p.append((n-1,n-2))
count+=1
print(count)
#print(p)
for i in p:
print(i[0]+1,i[1]+1)
| 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 == 0 and w == 0):
if(e != 1):
cnt += 1
ans.append((n-1,n))
if(r != 1):
cnt += 1
ans.append((n,n-1))
elif(q == 1 and w == 1):
if(e != 0):
cnt += 1
ans.append((n-1,n))
if(r != 0):
cnt += 1
ans.append((n,n-1))
else:
if(e == r):
if(q == r):
cnt += 1
ans.append((1,2))
if(w == r):
cnt += 1
ans.append((2,1))
else:
if(q != 0):
cnt += 1
ans.append((1,2))
else:
cnt += 1
ans.append((2,1))
if(e != 1):
cnt += 1
ans.append((n-1,n))
else:
cnt += 1
ans.append((n,n-1))
print(cnt)
for i in range(len(ans)):
print(*ans[i])
| 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[0][1];
int x = 1;
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 << 0 << "\n";
} else if (s[n - 1][n - 2] == s[n - 2][n - 1] &&
s[n - 1][n - 2] == s[0][1]) {
cout << 2 << "\n";
cout << n << " " << n - 1 << "\n";
cout << n - 1 << " " << n << "\n";
} else if (s[n - 1][n - 2] != s[n - 2][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 1 << "\n";
cout << n << " " << n - 1 << "\n";
} else {
cout << 1 << "\n";
cout << n - 1 << " " << n << "\n";
}
}
} else {
if (s[n - 1][n - 2] == s[n - 2][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 1 << "\n";
cout << 1 << " " << 2 << "\n";
} else if (s[n - 1][n - 2] == s[1][0]) {
cout << 1 << "\n";
cout << 2 << " " << 1 << "\n";
}
} else {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 2 << "\n";
cout << 1 << " " << 2 << "\n";
cout << n - 1 << " " << n << "\n";
} else if (s[n - 1][n - 2] == s[1][0]) {
cout << 2 << "\n";
cout << 2 << " " << 1 << "\n";
cout << n - 1 << " " << n << "\n";
}
}
}
}
return 0;
}
| 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[y][x] == '0' else '0'
if matrix[0][1] == matrix[1][0] != matrix[n - 1][n - 2] == matrix[n - 2][n - 1]:
return combi
for y, x in combi:
matrix[y][x] = '1' if matrix[y][x] == '0' else '0'
for _ in range(int(input())):
n = int(input())
matrix = []
for _ in range(n):
*row, = input()
matrix.append(row)
ans = solve(matrix)
print(len(ans))
for y, x in ans:
print(y + 1, x + 1)
| 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.readline().split())
def na(): return list(map(int, sys.stdin.buffer.readline().split()))
# ===CODE===
def main():
t = int(input())
res = []
for _ in range(t):
n = int(input())
for i in range(n):
s = input().strip()
if i == 0:
a1 = s[1]
if i == 1:
a2 = s[0]
if i == n-2:
b2 = s[-1]
if i == n-1:
b1 = s[-2]
if a1 == a2 and b1 == b2:
if a1 != b1:
res.append([0])
else:
res.append([2])
res.append([1, 2])
res.append([2, 1])
elif a1 == a2 or b1 == b2:
res.append([1])
if a1 == a2:
if b1 == a1:
res.append([n, n-1])
else:
res.append([n-1, n])
else:
if a1 == b1:
res.append([1, 2])
else:
res.append([2, 1])
else:
res.append([2])
if a1 != "0":
res.append([1, 2])
if a2 != "0":
res.append([2, 1])
if b1 != "1":
res.append([n, n-1])
if b2 != "1":
res.append([n-1, n])
for ri in res:
print(*ri, sep=" ")
if __name__ == '__main__':
main()
| 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 y) {
if (y == 0) return 1ll;
if (y == 1) return mod(x);
long long res = 1;
while (y) {
if (y % 2 == 1) {
res = mul(res, x);
}
x = mul(x, x);
y /= 2;
}
return res;
}
void solve() {
long long n;
cin >> n;
string s[n];
for (long long i = 0; i < n; i++) {
cin >> s[i];
}
char c = s[0][1];
long long x = 1;
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 << 0 << "\n";
} else if (s[n - 1][n - 2] == s[n - 2][n - 1] &&
s[n - 1][n - 2] == s[0][1]) {
cout << 2 << "\n";
cout << n << " " << n - 1 << "\n";
cout << n - 1 << " " << n << "\n";
} else if (s[n - 1][n - 2] != s[n - 2][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 1 << "\n";
cout << n << " " << n - 1 << "\n";
} else {
cout << 1 << "\n";
cout << n - 1 << " " << n << "\n";
}
}
} else {
if (s[n - 1][n - 2] == s[n - 2][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 1 << "\n";
cout << 1 << " " << 2 << "\n";
} else if (s[n - 1][n - 2] == s[1][0]) {
cout << 1 << "\n";
cout << 2 << " " << 1 << "\n";
}
} else {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 2 << "\n";
cout << 1 << " " << 2 << "\n";
cout << n - 1 << " " << n << "\n";
} else if (s[n - 1][n - 2] == s[1][0]) {
cout << 2 << "\n";
cout << 2 << " " << 1 << "\n";
cout << n - 1 << " " << n << "\n";
}
}
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| 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]==l[n-2][n-1]):
print(2)
print(1,2)
print(2,1)
elif(l[0][1]!=l[1][0] and l[n-1][n-2]==l[n-2][n-1]):
print(1)
print(*([1,2] if(l[0][1]==l[n-1][n-2]) else [2,1]))
elif(l[0][1]==l[1][0] and l[n-1][n-2]!=l[n-2][n-1]):
print(1)
print(*([n,n-1] if(l[0][1]==l[n-1][n-2]) else [n-1,n]))
else:
print(2)
print(*([1,2] if(l[0][1]==0) else [2,1]))
print(*([n,n-1] if(l[n-1][n-2]==1) else [n-1,n]))
main()
| 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') tou1++;
if (str[n - 2][n - 1] == '1') wei1++;
if (str[n - 1][n - 2] == '1') wei1++;
if (tou1 == 2) {
printf("%d\n", wei1);
if (str[n - 2][n - 1] == '1') printf("%d %d\n", n - 1, n);
if (str[n - 1][n - 2] == '1') printf("%d %d\n", n, n - 1);
}
if (tou1 == 1) {
if (wei1 == 2) {
printf("1\n");
if (str[0][1] == '1') printf("%d %d\n", 1, 2);
if (str[1][0] == '1') printf("%d %d\n", 2, 1);
} else if (wei1 == 1) {
printf("2\n");
if (str[0][1] == '1') printf("%d %d\n", 1, 2);
if (str[1][0] == '1') printf("%d %d\n", 2, 1);
if (str[n - 2][n - 1] == '0') printf("%d %d\n", n - 1, n);
if (str[n - 1][n - 2] == '0') printf("%d %d\n", n, n - 1);
} else if (wei1 == 0) {
printf("1\n");
if (str[0][1] == '0') printf("%d %d\n", 1, 2);
if (str[1][0] == '0') printf("%d %d\n", 2, 1);
}
}
if (tou1 == 0) {
printf("%d\n", 2 - wei1);
if (str[n - 2][n - 1] == '0') printf("%d %d\n", n - 1, n);
if (str[n - 1][n - 2] == '0') printf("%d %d\n", n, n - 1);
}
}
return 0;
}
| 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][n - 1]]
beg = s[0]
end = str(1 - int(beg))
if s[0] == s[1]:
beg = s[0]
end = str(1 - int(beg))
elif f[0] == f[1]:
end = f[0]
beg = str(1 - int(end))
points = []
# check
for i in range(2):
for j in range(2):
if i == j:
continue
if data[i][j] != beg:
points.append((i + 1, j + 1))
if data[n - i - 1][n - j - 1] != end:
points.append((n - i, n - j))
print(len(points))
for p in points:
print("{} {}".format(*p))
if __name__ == '__main__':
main()
| 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:
if grid[0][1]=="0":
count += 1
ans.append([1,2])
if grid[1][0]=="0":
count += 1
ans.append([2,1])
print (count)
for i in ans:
print (*i)
else:
if grid[n-1][n-2]=="1":
if grid[0][1]==grid[1][0]:
if grid[0][1]=="1":
print (1)
print (n,n-1)
else:
print (1)
print (n-1,n)
else:
if grid[0][1]=="1":
print (2)
print (1,2)
print (n-1,n)
else:
print (2)
print (1,2)
print (n,n-1)
else:
if grid[0][1]==grid[1][0]:
if grid[0][1]=="1":
print (1)
print (n-1,n)
else:
print (1)
print (n,n-1)
else:
if grid[0][1]=="1":
print (2)
print (1,2)
print (n,n-1)
else:
print (2)
print (1,2)
print (n-1,n)
| 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
continue
if s1 != s2 and f1==f2:
if s1 == f2:
print(1)
print(1,2)
t-=1
continue
else:
print(1)
print(2,1)
t-=1
continue
if f1!=f2 and s1==s2:#
if f1==s1:
print(1)
print(n-1,n)
t-=1
continue
else:
print(1)
print(n,n-1)
t-=1
continue
if s1==s2 and f1==f2 and s1==f1:#
print(2)
print(1,2)
print(2,1)
t-=1
continue
if f1!=f2 and s1!=s2 and s1==f1:
print(2)
print(1,2)
print(n,n-1)
t-=1
continue
if f1!=f2 and s1!=s2 and s1!=f1:
print(2)
print(1,2)
print(n-1,n)
t-=1
continue
| 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});
}
if (a[n - 2][n - 1] != '1') {
ans.push_back({n - 1, n});
}
if (a[0][1] != '0') {
ans.push_back({1, 2});
}
if (a[1][0] != '0') {
ans.push_back({2, 1});
}
if (ans.size() <= 2) {
cout << ans.size() << "\n";
for (auto& x : ans) {
cout << x.first << " " << x.second << "\n";
}
} else {
ans.clear();
if (a[n - 1][n - 2] != '0') {
ans.push_back({n, n - 1});
}
if (a[n - 2][n - 1] != '0') {
ans.push_back({n - 1, n});
}
if (a[0][1] != '1') {
ans.push_back({1, 2});
}
if (a[1][0] != '1') {
ans.push_back({2, 1});
}
cout << ans.size() << "\n";
for (auto& x : ans) {
cout << x.first << " " << x.second << "\n";
}
}
}
int main() {
using namespace std;
ios ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
for (; T--;) {
run_case();
}
}
| 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[j][k]=c[k]
x1=b[0][1]
y1=b[1][0]
x2=b[n-2][n-1]
y2=b[n-1][n-2]
if x1==y1 and x2==y2 and x1!=x2:
print(0)
elif x1==y1 and x2==y2 and x1==x2:
print(2)
print(1,2)
print(2,1)
elif (x1==y1) and (x2!=y2) :
print(1)
if x2==x1:
print(n-1,n)
else:
print(n,n-1)
elif (x1!=y1) and (x2==y2):
print(1)
if x2==x1:
print(1,2)
else:
print(2,1)
elif (x1!=y1) and (x2!=y2):
print(2)
if x1==x2:
print(1,2)
print(n,n-1)
else:
print(1,2)
print(n-1,n)
| 8 |
PYTHON3
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.