solution
stringlengths 11
983k
| difficulty
int64 0
21
| language
stringclasses 2
values |
---|---|---|
for _ in range(int(input())):
n = int(input())
l =list(map(int , input().split()))
a,b,c = l[0] , l[1] , l[-1]
if a+b>c and a+c>b and b+c>a:
print(-1)
else:
print(1,2 , n, sep=' ')
| 7 |
PYTHON3
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
if(a[0]+a[1] <= a[-1]):
print(1, 2, n)
else:
print("-1")
| 7 |
PYTHON3
|
for i in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
a1 = a[0]
a2 = a[1]
a3 = a[-1]
if (a1 + a2 <= a3):
print(1, 2, len(a))
else:
print(-1)
| 7 |
PYTHON3
|
for t in range(int(input())):
n = input()
a = [int(_) for _ in input().split()]
if a[0]+a[1] <= a[-1]:
print(1,2,n)
else:
print(-1)
| 7 |
PYTHON3
|
for _ in range(int(input())):
n=int(input())
arr=list(int(i) for i in input().split())
mn1=arr[0]
mn2=arr[1]
mx1=arr[-1]
if mn1+mn2>mx1:
print(-1)
else:
print(1,2,n)
| 7 |
PYTHON3
|
# -*- coding: utf-8 -*-
"""Untitled109.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1X8-VINDMTMre7Qt2DyQiUJHJz7Qf9Y8v
"""
for _ in range(int(input())):
n=int(input())
l=[int(x) for x in input().split()]
if l[0]+l[1]<=l[-1]:
print(1,2,len(l))
else:
print(-1)
| 7 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
long long Bin_expo(long long n, long long b, long long m) {
long long res = 1;
while (b > 0) {
if (b & 1) {
res = (res * n) % m;
}
n = (n * n) % m;
b /= 2;
}
return res % m;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long tc;
cin >> tc;
while (tc--) {
long long n;
cin >> n;
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
}
long long f = 0;
for (long long i = 2; i < n; i++) {
if (v[i] >= v[0] + v[1]) {
cout << "1 2 " << i + 1 << "\n";
f = 1;
break;
}
}
if (f) continue;
cout << "-1\n";
}
return 0;
}
| 7 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, arr[50005];
cin >> t;
for (int i = 0; i < t; i++) {
int x = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
if (arr[0] + arr[1] <= arr[n - 1]) {
cout << "1"
<< " "
<< "2"
<< " " << n << "\n";
} else
cout << "-1"
<< "\n";
}
}
| 7 |
CPP
|
for test in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = a[0]
c = a[1]
d = a[-1]
if c + b > d:
print(-1)
else:
print(1, 2, n)
| 7 |
PYTHON3
|
def checkinvalidity(a, b, c):
if (a + b <= c) or (a + c <= b) or (b + c <= a) :
return True
else:
return False
for _ in range(int(input())):
count=0
n= int(input())
arr= list(map(int,input().split()))
for i in range(n-2):
a=arr[i]
b=arr[i+1]
c=arr[n-i-1]
if(checkinvalidity(a,b,c)):
print(i+1,i+2,n-i)
count+=1
break
if(count==0):
print(-1)
| 7 |
PYTHON3
|
t=int(input())
for _ in range(t):
n=int(input())
a=list(map(lambda x: int(x), input().split()))
minimum=a[0]
minimum_index=0
for i in range(1,len(a)):
if a[i]<minimum:
minimum=a[i]
minimum_index=i
second_minimum=a[0] if 0!=minimum_index else a[1]
second_minimum_index=0 if 0!=minimum_index else 1
for i in range(0,len(a)):
if a[i]<second_minimum and i!=minimum_index:
second_minimum=a[i]
second_minimum_index=i
maximum = a[0]
maximum_index = 0
for i in range(0, len(a)):
if a[i] > maximum :
maximum = a[i]
maximum_index = i
if minimum+second_minimum<=maximum:
a=[maximum_index,second_minimum_index,minimum_index]
a.sort()
print(a[0]+1,a[1]+1,a[2]+1)
else:
print(-1)
| 7 |
PYTHON3
|
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
f=0
b=a[0]
c=a[1]
for i in range(n-1,-1,-1):
if(b+c<=a[i]):
print("1",end=' ')
print("2",end=' ')
print(i+1)
f=0
break
else:
f=1
if(f==1):
print("-1")
| 7 |
PYTHON3
|
for _ in range(int(input())):
n = int(input())
s = [*map(int,input().split())]
if s[0] + s[1] <= s[-1]:
print(1,2,n)
else:
print(-1)
| 7 |
PYTHON3
|
t=int(input())
for _ in range(t):
n=int(input())
k=0
l=list(map(int,input().split(" ")))
s=l[0]+l[1]
for a in range(2,n):
if s<=l[a]:
print(""+str(1)+" "+str(2)+" "+str(a+1))
k=-1
break
if k!=-1:
print("-1")
| 7 |
PYTHON3
|
t = int(input())
for _ in range(t):
n = int(input())
l = list([int(x) for x in input().split()])
a = l[0]
b = l[1]
c = l[n-1]
if(a+b <= c):
print(1, 2, n)
else:
print('-1')
| 7 |
PYTHON3
|
from sys import stdin, stdout
input = stdin.readline
#print = stdout.write
for _ in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
b = [(a[i],i+1) for i in range(len(a))]
b.sort(key = lambda x: x[0])
if b[0][0]+b[1][0]<=b[-1][0]:
t = b[0][1],b[1][1], b[-1][1]
print(*sorted(t), sep=' ')
else:
print(-1)
| 7 |
PYTHON3
|
# -*- coding: utf-8 -*-
"""
t=int(input())
for _ in range(t):
n=int(input())
x=list(map(int,input().split()))
k,m=map(int,input().split())
s=input()
@author: krishna
"""
t=int(input())
for _ in range(t):
n=int(input())
x=list(map(int,input().split()))
f=0
l=x[-1]
for i in range(n-1):
#print(i)
if x[i]+x[i+1]<=l:
print(i+1,i+2,n)
f=-1
break
if f==0:
print(-1)
| 7 |
PYTHON3
|
t=int(input(""))
for i in range(t):
la=int(input(""))
l=[0,1]
a=[int(x) for x in input("").split()]
ai=a[0]
aj=a[1]
for i in range(2,la):
if ai+aj<=a[i]:
l.append(a.index(a[i]))
for k in l:
print(k+1,end=' ')
print()
break
else:
print(-1)
| 7 |
PYTHON3
|
numOfCases = int(input())
numOfElements = 0
for i in range(numOfCases):
numOfElements = int(input())
lengthInputs = input()
lengthInputs = lengthInputs.split(" ")
lengthInputs = [int(x) for x in lengthInputs]
if (lengthInputs[-1] >= (lengthInputs[0] + lengthInputs[1])):
print("1 2", str(numOfElements))
else:
print("-1")
| 7 |
PYTHON3
|
for i in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()][:n]
s = a[0] + a[1]
if s > a[-1]:
print(-1)
else:
print(1,2,n)
| 7 |
PYTHON3
|
import os #2
inp=os.read(0,os.fstat(0).st_size).split(b"\n");_ii=-1
def rdln():
global _ii
_ii+=1
return inp[_ii]
inin=lambda typ=int: typ(rdln())
inar=lambda typ=int: [typ(x) for x in rdln().split()]
inst=lambda: rdln().strip().decode()
_T_=inin()
for _t_ in range(_T_):
n=inin()
a=inar()
if a[0]+a[1]>a[n-1]:
print(-1)
else:
print(1,2,n)
| 7 |
PYTHON3
|
T=int(input())
for z in range(T):
N=int(input())
a=[int(x) for x in input().split()]
if a[0]+a[1]<=a[len(a)-1]:
print(1," ",2," ",len(a))
else:
print(-1)
| 7 |
PYTHON3
|
for _ in range(int(input())):
n=int(input())
l=[int(x) for x in input().split()]
if l[0]+l[1]>l[-1]:
print(-1)
else:
print(1,2,n)
| 7 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t;
cin >> t;
while (t--) {
ll n;
cin >> n;
vector<ll> sides(n);
for (int i = 0; i < (n); ++i) cin >> sides[i];
if (sides[1] > (sides[n - 1] - sides[0]))
cout << -1 << "\n";
else
cout << "1 2 " << n << "\n";
}
return 0;
}
| 7 |
CPP
|
t = int(input())
ans = []
def solve(n,arr):
Max = arr[-1]
for l in range(n-2):
if arr[l]+arr[l+1]<=Max:
answer = [l+1,l+2,n]
return answer
return [-1]
for i in range(t):
n = int(input())
arr = [int(x) for x in input().split()]
ans.append(solve(n,arr))
for test in ans:
for num in test:
print(num,end=" ")
print()
| 7 |
PYTHON3
|
t=int(input())
for i in range(t):
n=int(input())
k=list(map(int,input().split()))
a,b,c=0,1,n-1
if((k[a]+k[b])>k[c]):
print(-1)
else:
print(a+1,b+1,c+1)
| 7 |
PYTHON3
|
t = int(input())
nLst = []
triLst = []
for tt in range(t):
n_i = int(input())
nLst.append(n_i)
tri = input().split()
for x in range(len(tri)):
tri[x] = int(tri[x])
triLst.append(tri)
for i in range(t):
for j in range(2, len(triLst[i])):
if (triLst[i][0] + triLst[i][1] <= triLst[i][j]):
print('1 2', j+1)
break
elif j == len(triLst[i]) - 1:
print(-1)
break
else:
continue
| 7 |
PYTHON3
|
import math,sys
from sys import stdin,stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda:int(input())
li = lambda:list(map(int,input().split()))
def solve():
n=I()
a=li()
p,q,r=a[0],a[1],a[-1]
if(p+q<=r):
print(1,2,n)
else:
print(-1)
for _ in range(I()):
solve()
| 7 |
PYTHON3
|
for i in " "*int(input()):
n=int(input())
a=list(map(int,input().split()))[:n]
if a[0]+a[1]>a[-1]:
print(-1)
else:
print(1,2,n)
| 7 |
PYTHON3
|
from sys import *
def resolve(t):
N = int(stdin.readline().rstrip())
array = [int(x) for x in stdin.readline().rstrip().split()]
#dk: c < a + b , c lon nhat
a = array[0]
b = array[1]
c = array[N-1]
if (c >= a + b):
print(str(1) + " " + str(2) + " " + str(N))
return
print("-1")
if __name__ == "__main__":
T = int(stdin.readline().rstrip())
for t in range(T):
resolve(t)
pass
| 7 |
PYTHON3
|
import sys
import math
from collections import Counter,defaultdict
input = sys.stdin.readline
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()
def case():
n=IN()
a=LI()
if a[0]+a[1]>a[-1]:
print(-1)
else:
print(1,2,n)
for _ in range(IN()):
case()
| 7 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a, b, c;
cin >> a;
cin >> b;
for (int i = 0; i < n - 2; i++) {
cin >> c;
}
if (a + b <= c) {
cout << "1 2 " << n << endl;
} else {
cout << -1 << endl;
}
}
}
| 7 |
CPP
|
for _ in range(int(input())):
n = int(input())
A = list(map(int,input().split()))
if not A[n-1]>= A[0]+A[1]:
print(-1)
else:
print(1,2,n)
| 7 |
PYTHON3
|
t=int(input())
for i in range(t):
n=int(input())
l=list(map(int,input().split()))
if l[0]+l[1]>l[n-1]:
print(-1)
else:
print(1,2,n)
| 7 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long a, b = 0, c = 0, d = 0, e = 0;
cin >> a;
int arr[a];
for (int i = 0; i < a; i++) {
cin >> arr[i];
}
b = arr[0];
for (int i = 0; i < a; i++) {
if (i != 0) {
if (arr[i] >= b) {
c = arr[i];
d = i;
break;
}
}
}
for (int i = 0; i < a; i++) {
if (i != d) {
if (arr[i] >= (b + c)) {
e = i;
break;
}
}
}
if (e != 0) {
cout << 1 << " " << d + 1 << " " << e + 1 << endl;
} else {
cout << -1 << endl;
}
}
}
| 7 |
CPP
|
for _ in range(int(input())):
n = int(input())
l = list(map(int,input().split()))
if (l[0]+l[1])<=l[-1]:
print(1,2,n)
else:
print(-1)
| 7 |
PYTHON3
|
#!/usr/bin/env python3
T = int(input())
def ans(A):
A = [(a, i+1) for i,a in enumerate(A)]
A = sorted(A)
a, ai = A[0]
b, bi = A[1]
c, ci = A[-1]
if a + b <= c:
print(ai, bi, ci)
else:
print(-1)
for t in range(T):
input()
A = list(map(int, input().split()))
ans(A)
| 7 |
PYTHON3
|
t = int(input())
for _ in range(t):
n = int(input())
l = list(map(int,input().split()))
if l[0]+l[1]<=l[-1]:
print(1,2,n)
else:
print(-1)
| 7 |
PYTHON3
|
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 14 20:11:56 2020
@author: The Wonder Land
"""
for _ in range(int(input())):
n = int(input())
val = list(map(int, input().strip().split()))
index = [1, 2]
sum_tri = val[0] + val[1]
for i in range(2, len(val)):
#print("i =", i)
if (val[i] >= sum_tri):
index.append(i+1)
print(*index)
break
if i+1 == len(val):
print("-1")
break
"""
4 6 11 11 15 18 20
10 10 10 11
10 10 10 11
"""
| 7 |
PYTHON3
|
l=[]
for _ in range(int(input())):
n=int(input())
a=[]
for i in range(n):
a.append(list(input()))
if a[0][1]==a[1][0]:
if a[n-1][n-2]==a[n-2][n-1]:
if a[n-1][n-2]==a[0][1]:
l.append("2")
l.append("1 2")
l.append("2 1")
else:
l.append("0")
else:
if a[n-1][n-2]!=a[0][1]:
l.append("1")
l.append(str(n-1)+" "+str(n))
else:
l.append("1")
l.append(str(n)+" "+str(n-1))
else:
if a[n-1][n-2]==a[n-2][n-1]:
if a[n-1][n-2]!=a[0][1]:
l.append("1")
l.append("2 1")
else:
l.append("1")
l.append("1 2")
else:
if a[0][1]!=a[n-2][n-1]:
l.append("2")
l.append("1 2")
l.append(str(n-1)+" "+str(n))
else:
l.append("2")
l.append("2 1")
l.append(str(n - 1)+" "+ str(n))
for i in l:
print(i)
| 8 |
PYTHON3
|
t=int(input())
for i in range(t):
n=int(input())
l=[]
for i in range(n):
l.append(list(input()))
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-1,n)
print(n,n-1)
elif l[n-2][n-1]=='0' and l[n-1][n-2]=='1':
print(1)
print(n-1,n)
elif l[n-2][n-1]=='1'and l[n-1][n-2]=='0':
print(1)
print(n,n-1)
elif l[n-2][n-1]=='1' and l[n-1][n-2]=='1':
print(0)
elif l[0][1]=='0' and l[1][0]=='1':
if l[n-2][n-1]=='0' and l[n-1][n-2]=='0':
print(1)
print(1,2)
elif l[n-2][n-1]=='0' and l[n-1][n-2]=='1':
print(2)
print(1,2)
print(n,n-1)
elif l[n-2][n-1]=='1' and l[n-1][n-2]=='0':
print(2)
print(1,2)
print(n-1,n)
elif l[n-2][n-1]=='1' and l[n-1][n-2]=='1':
print(1)
print(2,1)
elif l[0][1]=='1' and l[1][0]=='0':
if l[n-2][n-1]=='0' and l[n-1][n-2]=='0':
print(1)
print(2,1)
elif l[n-2][n-1]=='0' and l[n-1][n-2]=='1':
print(2)
print(2,1)
print(n,n-1)
elif l[n-2][n-1]=='1'and l[n-1][n-2]=='0':
print(2)
print(2,1)
print(n-1,n)
elif l[n-2][n-1]=='1' and l[n-1][n-2]=='1':
print(1)
print(1,2)
elif l[0][1]=='1' and l[1][0]=='1':
if l[n-2][n-1]=='0' and l[n-1][n-2]=='0':
print(0)
elif l[n-2][n-1]=='0' and l[n-1][n-2]=='1':
print(1)
print(n,n-1)
elif l[n-2][n-1]=='1' and l[n-1][n-2]=='0':
print(1)
print(n-1,n)
elif l[n-2][n-1]=='1' and l[n-1][n-2]=='1':
print(2)
print(n-1,n)
print(n,n-1)
| 8 |
PYTHON3
|
for _ in range(int(input())):
n = int(input());grid = [input() for i in range(n)];a, b, c, d = grid[0][1], grid[1][0], grid[-2][-1], grid[-1][-2];e = []; f = []
if a != '0':e.append((1, 2))
if b != '0':e.append((2, 1))
if c != '1':e.append((n-1, n))
if d != '1':e.append((n, n-1))
if c != '0':f.append((n-1,n))
if d != '0':f.append((n, n-1))
if a != '1':f.append((1,2))
if b != '1':f.append((2,1))
if len(e) < len(f):
print(len(e))
for i in e:print(*i)
else:
print(len(f))
for i in f:print(*i)
| 8 |
PYTHON3
|
for tt in range(int(input())):
n = int(input())
g = [input() for i in range(n)]
for i in range(2):
m = []
if g[0][1] != str(i) : m.append((0,1))
if g[1][0] != str(i) : m.append((1,0))
if g[n-1][-2] != str(i^1) : m.append((n-1,n-2))
if g[-2][n-1] != str(i^1) : m.append((n-2,n-1))
if len(m) <= 2:
print(len(m))
for j in m:
print(j[0]+1,j[1]+1)
break
| 8 |
PYTHON3
|
for _ in range(int(input())):
n=int(input())
arr=[]
for i in range(n):
temp=list(str(input()))
arr.append(temp)
change=[]
#print(arr)
if arr[0][1]==arr[1][0]:
if arr[0][1]=="1":
if arr[n-2][n-1]!="0":
change.append([n-1,n])
if arr[n-1][n-2]!="0":
change.append([n,n-1])
else:
if arr[n-2][n-1]!="1":
change.append([n-1,n])
if arr[n-1][n-2]!="1":
change.append([n,n-1])
elif arr[n-2][n-1]==arr[n-1][n-2]:
if arr[n-2][n-1]=="1":
if arr[0][1]!="0":
change.append([1,2])
if arr[1][0]!="0":
change.append([2,1])
else:
if arr[0][1]!="1":
change.append([1,2])
if arr[1][0]!="1":
change.append([2,1])
else:
if arr[0][1]!="0":
change.append([1,2])
if arr[1][0]!="0":
change.append([2,1])
if arr[n-1][n-2]!="1":
change.append([n,n-1])
if arr[n-2][n-1]!="1":
change.append([n-1,n])
print(len(change))
for ar in change:
ar=list(map(str,ar))
l=" ".join(ar)
print(l)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX;
const long long int inf64 = LLONG_MAX;
vector<string> vect;
long long int n;
vector<pair<int, int> > d4{{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
bool good(long long int xx, long long int yy) {
return (xx < n and xx >= 0 and yy < n and yy >= 0);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long int t;
cin >> t;
while (t--) {
cin >> n;
vect = vector<string>(n);
long long int i;
for (i = 0; i < n; i++) {
cin >> vect[i];
}
vector<pair<int, int> > ans1, ans2;
for (auto p : d4) {
long long int xx, yy;
xx = 0 + p.first;
yy = 0 + p.second;
if (good(xx, yy) and vect[xx][yy] == '1') ans1.push_back({xx, yy});
xx = n - 1 + p.first;
yy = n - 1 + p.second;
if (good(xx, yy) and vect[xx][yy] == '0') ans1.push_back({xx, yy});
}
for (auto p : d4) {
long long int xx, yy;
xx = 0 + p.first;
yy = 0 + p.second;
if (good(xx, yy) and vect[xx][yy] == '0') ans2.push_back({xx, yy});
xx = n - 1 + p.first;
yy = n - 1 + p.second;
if (good(xx, yy) and vect[xx][yy] == '1') ans2.push_back({xx, yy});
}
if (ans1.size() < ans2.size()) {
cout << ans1.size() << '\n';
for (auto x : ans1) cout << x.first + 1 << ' ' << x.second + 1 << '\n';
} else {
cout << ans2.size() << '\n';
for (auto x : ans2) cout << x.first + 1 << ' ' << x.second + 1 << '\n';
}
}
return 0;
}
| 8 |
CPP
|
t = int(input())
for i in range(t):
list1 = []
n = int(input())
for j in range(n):
list1.append(input())
s_right = list1[0][1]
s_down = list1[1][0]
f_left = list1[-1][-2]
f_up = list1[-2][-1]
if s_right==s_down and f_left==f_up:
if s_right!=f_left:
print(0)
else:
print(2)
print(n-1,' ',n)
print(n,' ',n-1)
elif s_right!=s_down and f_left==f_up:
if s_right==f_left:
print(1)
print(1,' ',2)
elif s_down==f_left:
print(1)
print(2,' ',1)
elif s_right==s_down and f_left!=f_up:
if s_right==f_left:
print(1)
print(n,' ',n-1)
elif s_down==f_up:
print(1)
print(n-1,' ',n)
else:
print(2)
if s_right==f_up:
print(1,' ',2)
print(n,' ',n-1)
elif s_right==f_left:
print(1,' ',2)
print(n-1,' ',n)
| 8 |
PYTHON3
|
def main():
for _ in range(int(input())):
n=int(input())
a=[]
for i in range(n):
a.append(input())
ans=[]
if a[0][1]==a[1][0]:
if a[n-1][n-2]==a[0][1]:
ans.append((n,n-1))
if a[n-2][n-1]==a[0][1]:
ans.append((n-1,n))
elif a[n-1][n-2]==a[n-2][n-1]:
if a[0][1]==a[n-1][n-2]:
ans.append((1,2))
if a[1][0]==a[n-1][n-2]:
ans.append((2,1))
else:
ans.append((1,2))
if a[n-1][n-2]==a[1][0]:
ans.append((n,n-1))
if a[n-2][n-1]==a[1][0]:
ans.append((n-1,n))
print(len(ans))
for a,b in ans:
print("%d %d"%(a,b))
main()
| 8 |
PYTHON3
|
test_case_num = int(input())
for i in range(test_case_num):
a = int(input())
list = []
for k in range(a):
list.append(input())
x= list[0][1]
y= list[1][0]
z = list[a-1][a-2]
p = list[a-2][a-1]
if x=='0' and y=='0' and z=='0' and p=='1': #0001
print(1)
print(a, a-1)
elif x=='0' and y=='0' and z=='1' and p=='0': #0010
print(1)
print(a-1, a)
elif x=='1' and y=='0' and z=='0' and p=='0': #1000
print(1)
print(2, 1)
elif x=='0' and y=='1' and z=='0' and p=='0': #0100
print(1)
print(1,2)
elif x=='1' and y=='1' and z=='1' and p=='1': #1111
print(2)
print(1,2)
print(2,1)
elif x=='0' and y=='0' and z=='0' and p=='0': #0000
print(2)
print(1,2)
print(2,1)
elif x=='0' and y=='0' and z=='1' and p=='1': #0011
print(0)
elif x=='1' and y=='1' and z=='0' and p=='0': #1100
print(0)
elif x=='0' and y=='1' and z=='0' and p=='1': #0101
print(2)
print(1,2)
print(a-1, a)
elif x=='0' and y=='1' and z=='1' and p=='0': #0110
print(2)
print(1,2)
print(a,a-1)
elif x=='0' and y=='1' and z=='1' and p=='1' : #0111
print(1)
print(2,1)
elif x=='1' and y=='0' and z=='0' and p=='1' : #1001
print(2)
print(1,2)
print(a,a-1)
elif x=='1' and y=='0' and z=='1' and p=='0' : #1010
print(2)
print(1,2)
print(a-1,a)
elif x=='1' and y=='0' and z=='1' and p=='1' : #1011
print(1)
print(1,2)
elif x=='1' and y=='1' and z=='0' and p=='1' : #1101
print(1)
print(a-1,a)
elif x=='1' and y=='1' and z=='1' and p=='0' : #1110
print(1)
print(a, a-1)
| 8 |
PYTHON3
|
def sa(): return map(int,input().split())
def ra(): return list(map(int,input().split()))
def mati(n): return [ra() for i in range(n)]
def ri(): return int(input())
for _ in range(ri()):
n=ri()
g = [input() for i in range(n)]
if g[0][1]==g[1][0]==g[-2][-1]==g[-1][-2]:
print('2\n1 2\n2 1')
elif g[0][1]==g[1][0] and g[-2][-1]!=g[-1][-2]:
if g[-2][-1]==g[1][0]:
print('1\n{} {}'.format(n-1,n))
else:
print('1\n{} {}'.format(n,n-1))
elif g[0][1]!=g[1][0] and g[-2][-1]==g[-1][-2]:
if g[-2][-1]==g[1][0]:
print('1\n{} {}'.format(2,1))
else:
print('1\n{} {}'.format(1,2))
elif g[0][1]!=g[1][0] and g[-2][-1]!=g[-1][-2]:
if g[0][1]!=g[-2][-1]:
print('2\n{} {}\n{} {}'.format(1,2,n-1,n))
else:
print('2\n{} {}\n{} {}'.format(1,2,n,n-1))
else:
print(0)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
char a[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
if (a[1][0] == a[0][1] && a[n - 1][n - 2] == a[n - 2][n - 1] &&
a[1][0] != a[n - 1][n - 2]) {
cout << 0 << "\n";
} else if (a[1][0] != a[0][1] && a[n - 1][n - 2] != a[n - 2][n - 1]) {
cout << 2 << "\n";
if (a[1][0] == '1') {
a[0][1] = '1';
cout << 1 << " " << 2 << "\n";
if (a[n - 1][n - 2] == '1') {
a[n - 1][n - 2] = '0';
cout << n << " " << n - 1 << "\n";
} else if (a[n - 2][n - 1] == '1') {
a[n - 2][n - 1] = '0';
cout << n - 1 << " " << n << "\n";
}
} else if (a[1][0] == '0') {
a[0][1] = '0';
cout << 1 << " " << 2 << "\n";
if (a[n - 1][n - 2] == '0') {
a[n - 1][n - 2] = '1';
cout << n << " " << n - 1 << "\n";
} else if (a[n - 2][n - 1] == '0') {
a[n - 2][n - 1] = '1';
cout << n - 1 << " " << n << "\n";
}
}
} else if (a[1][0] == a[0][1] && a[n - 1][n - 2] != a[n - 2][n - 1]) {
cout << 1 << "\n";
if (a[1][0] == '0') {
if (a[n - 1][n - 2] == '0') {
cout << n << " " << n - 1 << "\n";
} else if (a[n - 2][n - 1] == '0') {
cout << n - 1 << " " << n << "\n";
}
}
if (a[1][0] == '1') {
if (a[n - 1][n - 2] == '1') {
cout << n << " " << n - 1 << "\n";
} else if (a[n - 2][n - 1] == '1') {
cout << n - 1 << " " << n << "\n";
}
}
} else if (a[1][0] != a[0][1] && a[n - 1][n - 2] == a[n - 2][n - 1]) {
cout << 1 << "\n";
if (a[n - 1][n - 2] == '0') {
if (a[1][0] == '0') {
cout << 2 << " " << 1 << "\n";
} else {
cout << 1 << " " << 2 << "\n";
}
} else {
if (a[1][0] == '1') {
cout << 2 << " " << 1 << "\n";
} else {
cout << 1 << " " << 2 << "\n";
}
}
} else if (a[1][0] == a[0][1] && a[n - 1][n - 2] == a[n - 2][n - 1] &&
a[1][0] == a[n - 1][n - 2]) {
cout << 2 << "\n";
cout << 1 << " " << 2 << "\n";
cout << 2 << " " << 1 << "\n";
}
}
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int Tc, N;
char Grid[205][205];
int main() {
cin >> Tc;
while (Tc--) {
cin >> N;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) cin >> Grid[i][j];
}
if (Grid[1][2] == Grid[2][1]) {
if (Grid[N - 1][N] == Grid[N][N - 1] && Grid[1][2] == Grid[N][N - 1]) {
cout << 2 << endl;
cout << N << " " << N - 1 << endl;
cout << N - 1 << " " << N << endl;
} else if (Grid[N - 1][N] == Grid[N][N - 1])
cout << 0 << endl;
else if (Grid[N - 1][N] == Grid[1][2])
cout << 1 << endl << N - 1 << " " << N << endl;
else
cout << 1 << endl << N << " " << N - 1 << endl;
} else {
if (Grid[N - 1][N] == Grid[N][N - 1]) {
cout << 1 << endl;
if (Grid[1][2] == Grid[N - 1][N])
cout << 1 << " " << 2 << endl;
else
cout << 2 << " " << 1 << endl;
} else {
cout << 2 << endl;
if (Grid[1][2] == '1')
cout << 1 << " " << 2 << endl;
else
cout << 2 << " " << 1 << endl;
if (Grid[N][N - 1] == '0')
cout << N << " " << N - 1 << endl;
else
cout << N - 1 << " " << N << endl;
}
}
}
}
| 8 |
CPP
|
# ------------------- fast io --------------------
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)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
from math import gcd, ceil
def prod(a, mod=10**9+7):
ans = 1
for each in a:
ans = (ans * each) % mod
return ans
def lcm(a, b): return a * b // gcd(a, b)
def binary(x, length=16):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
n = int(input())
#n, k = map(int, input().split())
#a, b = map(int, input().split())
#c, d = map(int, input().split())
#a = list(map(int, input().split()))
#b = list(map(int, input().split()))
#s = input()
a = []
for i in range(n):
a += [[int(k, 32) for k in input()]]
zero_one = []
one_zero = []
if a[0][1] != 0:zero_one += [[1, 2]]
else: one_zero += [[1, 2]]
if a[1][0] != 0:zero_one += [[2, 1]]
else: one_zero += [[2, 1]]
if a[-1][-2] != 1:zero_one += [[n, n-1]]
else: one_zero += [[n, n-1]]
if a[-2][-1] != 1:zero_one += [[n-1, n]]
else: one_zero += [[n-1, n]]
if len(zero_one) > len(one_zero): zero_one = one_zero
print(len(zero_one))
for k in zero_one:print(*k)
| 8 |
PYTHON3
|
t=int(input())
for you in range(t):
n=int(input())
l=[]
for i in range(n):
s=input()
l.append(s)
if(l[0][1]==l[1][0]):
z=l[0][1]
lo=[]
if(l[-1][-2]==z):
lo.append((n,n-1))
if(l[-2][-1]==z):
lo.append((n-1,n))
print(len(lo))
for i in lo:
print(i[0],i[1])
continue
if(l[-1][-2]==l[-2][-1]):
z=l[-1][-2]
lo=[]
if(l[0][1]==z):
lo.append((1,2))
if(l[1][0]==z):
lo.append((2,1))
print(len(lo))
for i in lo:
print(i[0],i[1])
continue
lo=[]
if(l[0][1]=='0'):
lo.append((1,2))
if(l[1][0]=='0'):
lo.append((2,1))
if(l[-2][-1]=='1'):
lo.append((n-1,n))
if(l[-1][-2]=='1'):
lo.append((n,n-1))
print(len(lo))
for i in lo:
print(i[0],i[1])
| 8 |
PYTHON3
|
from math import *
t=int(input())
while t:
t=t-1
#a,b=map(int,input().split())
n=int(input())
#a=list(map(int,input().split()))
#out=a^b
#out2=a^b+b^b
#print(out)
a=[]
for i in range(n):
s=input()
a.append(s)
l=[a[0][1],a[1][0],a[n-1][n-2],a[n-2][n-1]]
oc=l.count('1')
zc=l.count('0')
out=[]
if oc==4 or zc==4:
out.append([1,0])
out.append([0,1])
elif oc>zc:
if a[1][0]=='1' and a[0][1]=='0':
out.append([1,0])
elif a[1][0]=='0' and a[0][1]=='1':
out.append([0,1])
elif a[n-1][n-2]=='1' and a[n-2][n-1]=='0':
out.append([n-1,n-2])
elif a[n-1][n-2]=='0' and a[n-2][n-1]=='1':
out.append([n-2,n-1])
elif oc<zc:
if a[1][0]=='0' and a[0][1]=='1':
out.append([1,0])
elif a[1][0]=='1' and a[0][1]=='0':
out.append([0,1])
elif a[n-1][n-2]=='0' and a[n-2][n-1]=='1':
out.append([n-1,n-2])
elif a[n-1][n-2]=='1' and a[n-2][n-1]=='0':
out.append([n-2,n-1])
else:
if a[1][0]!=a[0][1]:
if a[1][0]=='0':
out.append([1,0])
if a[0][1]=='0':
out.append([0,1])
if a[n-1][n-2]=='1':
out.append([n-1,n-2])
if a[n-2][n-1]=='1':
out.append([n-2,n-1])
print(len(out))
for i in out:
print(i[0]+1,i[1]+1)
| 8 |
PYTHON3
|
from collections import defaultdict
t = int(input())
for _ in range(t):
n = int(input())
grid = []
for i in range(n):
grid.append([i for i in input()])
if grid[0][1] == grid[1][0]:
ans = []
if grid[0][1] == '0':
if grid[n-1][n-2] == '0':
ans.append([n, n-1])
if grid[n-2][n-1] == '0':
ans.append(([n-1, n]))
if grid[0][1] == '1':
if grid[n-1][n-2] == '1':
ans.append([n, n-1])
if grid[n-2][n-1] == '1':
ans.append(([n-1, n]))
else:
ans = []
if grid[n-1][n-2] == grid[n-2][n-1]:
x = grid[n-1][n-2]
if grid[0][1] == x:
ans.append([1, 2])
if grid[1][0] == x:
ans.append([2, 1])
else:
if grid[0][1] == '1':
ans.append([1, 2])
if grid[1][0] == '1':
ans.append([2, 1])
if grid[n-1][n-2] == '0':
ans.append([n, n-1])
if grid[n-2][n-1] == '0':
ans.append(([n - 1, n]))
print(len(ans))
for i in ans:
print(*i)
| 8 |
PYTHON3
|
for _ in " "*int(input()):
n=int(input())
lst=[]
for i in range(n):
s=list(input())
lst.append(s)
if lst[1][0] == "0" and lst[0][1] == "1" and lst[n-2][n-1]=="0" and lst[n-1][n-2]=="1":
print(2)
print(2,1)
print(n,n-1)
elif lst[1][0] == "1" and lst[0][1] == "0" and lst[n-2][n-1]=="1" and lst[n-1][n-2]=="1":
print(1)
print(2,1)
elif lst[1][0] == "1" and lst[0][1] == "0" and lst[n-2][n-1]=="0" and lst[n-1][n-2]=="1":
print(2)
print(2,1)
print(n-1,n)
elif lst[1][0] == "0" and lst[0][1] == "1" and lst[n-2][n-1]=="1" and lst[n-1][n-2]=="0":
print(2)
print(2,1)
print(n-1,n)
elif lst[1][0] == "1" and lst[0][1] == "0" and lst[n-2][n-1]=="0" and lst[n-1][n-2]=="0":
print(1)
print(1,2)
elif lst[1][0] == "1" and lst[0][1] == "0" and lst[n-2][n-1]=="1" and lst[n-1][n-2]=="0":
print(2)
print(2,1)
print(n,n-1)
elif lst[1][0] == "1" and lst[0][1] == "1" and lst[n-2][n-1]=="0" and lst[n-1][n-2]=="0":
print(0)
elif lst[1][0] == "1" and lst[0][1] == "1" and lst[n-2][n-1]=="0" and lst[n-1][n-2]=="1":
print(1)
print(n,n-1)
elif lst[1][0] == "1" and lst[0][1] == "1" and lst[n-2][n-1]=="1" and lst[n-1][n-2]=="0":
print(1)
print(n-1,n)
elif lst[1][0] == "1" and lst[0][1] == "1" and lst[n-2][n-1]=="1" and lst[n-1][n-2]=="1":
print(2)
print(2,1)
print(1,2)
elif lst[1][0] == "0" and lst[0][1] == "0" and lst[n-2][n-1]=="0" and lst[n-1][n-2]=="0":
print(2)
print(2,1)
print(1,2)
elif lst[1][0] == "0" and lst[0][1] == "0" and lst[n-2][n-1]=="0" and lst[n-1][n-2]=="1":
print(1)
print(n-1,n)
elif lst[1][0] == "0" and lst[0][1] == "1" and lst[n-2][n-1]=="1" and lst[n-1][n-2]=="1":
print(1)
print(1,2)
elif lst[1][0] == "0" and lst[0][1] == "0" and lst[n-2][n-1]=="1" and lst[n-1][n-2]=="0":
print(1)
print(n,n-1)
elif lst[1][0] == "0" and lst[0][1] == "0" and lst[n-2][n-1]=="1" and lst[n-1][n-2]=="1":
print(0)
elif lst[1][0] == "0" and lst[0][1] == "1" and lst[n-2][n-1]=="0" and lst[n-1][n-2]=="0":
print(1)
print(2,1)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 9;
set<int> ist;
map<string, int> msi;
map<string, string> mss;
map<int, string> mis;
map<int, int> mii;
pair<int, int> pii;
vector<int> v;
vector<pair<int, int> > vv;
int cc[] = {1, -1, 0, 0};
int rr[] = {0, 0, 1, -1};
void SUNRISE() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
char dp[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> dp[i][j];
}
}
if ((dp[0][1] == dp[1][0]) && (dp[n - 1][n - 2] == dp[n - 2][n - 1]) &&
(dp[0][1] != dp[n - 1][n - 2])) {
cout << 0 << endl;
} else if ((dp[0][1] == dp[1][0]) &&
(dp[n - 1][n - 2] == dp[n - 2][n - 1]) &&
(dp[0][1] == dp[n - 1][n - 2])) {
cout << 2 << endl;
cout << 1 << " " << 2 << endl;
cout << 2 << " " << 1 << endl;
} else if ((dp[0][1] != dp[1][0]) &&
(dp[n - 1][n - 2] != dp[n - 2][n - 1])) {
cout << 2 << endl;
if (dp[0][1] == '0') {
cout << 1 << " " << 2 << endl;
} else {
cout << 2 << " " << 1 << endl;
}
if (dp[n - 1][n - 2] == '1') {
cout << n << " " << n - 1 << endl;
} else {
cout << n - 1 << " " << n << endl;
}
} else {
if (dp[0][1] == dp[1][0]) {
if (dp[n - 1][n - 2] == dp[0][1]) {
cout << 1 << endl;
cout << n << " " << n - 1 << endl;
} else {
cout << 1 << endl;
cout << n - 1 << " " << n << endl;
}
} else {
if (dp[n - 1][n - 2] == dp[0][1]) {
cout << 1 << endl;
cout << 1 << " " << 2 << endl;
} else {
cout << 1 << endl;
cout << 2 << " " << 1 << endl;
}
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
SUNRISE();
return 0;
}
| 8 |
CPP
|
t = int(input())
for j in range(t):
n = int(input())
a = []
for i in range(n):
temp = str(input())
a.append([str(x) for x in temp])
#print(a)
count = 0
ans= [[a[0][1],1,2],[a[1][0],2,1],[a[0][2],1,3],[a[1][1],2,2],[a[2][0],3,1]]
#print(ans)
check1 = ['1','1','0','0','0']
check2 = ['0','0','1','1','1']
co = []
for i in range(5):
if ans[i][0]!=check1[i]:
count+=1
co.append(ans[i])
if count>2:
co = []
count=0
for i in range(5):
if ans[i][0]!=check2[i]:
count+=1
co.append(ans[i])
if count==0:
print(0)
else:
print(count)
for i in co:
print(str(i[1]) + " " + str(i[2]))
| 8 |
PYTHON3
|
"""
https://codeforces.com/contest/1421/problem/B
"""
for _ in range(int(input())):
n = int(input())
array = []
for _ in range(n):
array.append(list(input()))
important = []
important.append(int(array[0][1]))
important.append(int(array[1][0]))
important.append(int(array[n-2][n-1]))
important.append(int(array[n-1][n-2]))
count = important.count(0)
if count == 0 or count == 4:
print("2")
print("1 2")
print("2 1")
elif count == 2:
if important[0] == important[1]:
print("0")
else:
print("2")
if important[0] == 0:
print("2 1")
else:
print("1 2")
if important[2] == 1:
print(str(n) + " " + str(n-1))
else:
print(str(n-1) + " " + str(n))
elif count == 3:
x = important.index(1)
print("1")
if x == 0:
print("2 1")
elif x == 1:
print("1 2")
elif x == 2:
print(str(n) + " " + str(n-1))
else:
print(str(n-1) + " " + str(n))
elif count == 1:
x = important.index(0)
print("1")
if x == 0:
print("2 1")
elif x == 1:
print("1 2")
elif x == 2:
print(str(n) + " " + str(n-1))
else:
print(str(n-1) + " " + str(n))
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long i, j, m, n, k;
long long t;
cin >> t;
while (t--) {
cin >> n;
char a[n][n];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
cin >> a[i][j];
}
}
if (a[0][1] == a[1][0] && a[n - 1][n - 2] == a[n - 2][n - 1]) {
if (a[0][1] != a[n - 1][n - 2]) {
cout << 0 << "\n";
} else {
cout << 2 << "\n";
cout << 1 << " " << 2 << "\n";
cout << 2 << " " << 1 << "\n";
}
} else if (a[0][1] == a[1][0] && a[n - 1][n - 2] != a[n - 2][n - 1]) {
cout << 1 << "\n";
if (a[0][1] == a[n - 1][n - 2]) {
cout << n << " " << n - 1 << "\n";
} else
cout << n - 1 << " " << n << "\n";
} else if (a[0][1] != a[1][0] && a[n - 1][n - 2] == a[n - 2][n - 1]) {
cout << 1 << "\n";
if (a[0][1] == a[n - 1][n - 2]) {
cout << 1 << " " << 2 << "\n";
} else
cout << 2 << " " << 1 << "\n";
} else {
cout << 2 << "\n";
if (a[0][1] == a[n - 1][n - 2]) {
cout << 1 << " " << 2 << "\n";
cout << n - 1 << " " << n << "\n";
} else {
cout << 1 << " " << 2 << "\n";
cout << n << " " << n - 1 << "\n";
}
}
}
}
| 8 |
CPP
|
"""
Author - Satwik Tiwari .
18th Oct , 2020 - Sunday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
# from itertools import *
from heapq import *
from math import gcd, factorial,floor,ceil
from copy import deepcopy
from collections import deque
# from collections import Counter as counter # Counter(list) return a dict with {key: count}
# from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
# from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
#==============================================================================================
#fast I/O region
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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
#===============================================================================================
#some shortcuts
mod = 10**9+7
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var)) #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n") #as stdout.write always print sring.
def testcase(t):
for pp in range(t):
solve(pp)
def printlist(a) :
for p in range(0,len(a)):
out(str(a[p]) + ' ')
def google(p):
print('Case #'+str(p)+': ',end='')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(x, y, p) :
res = 1 # Initialize result
x = x % p # Update x if it is more , than or equal to p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) : # If y is odd, multiply, x with result
res = (res * x) % p
y = y >> 1 # y = y/2
x = (x * x) % p
return res
def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))
def isPrime(n) :
if (n <= 1) : return False
if (n <= 3) : return True
if (n % 2 == 0 or n % 3 == 0) : return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
#===============================================================================================
# code here ;))
"""
2
3 5
2 3 4
4 10
2 9 3 8
"""
def solve(case):
n = int(inp())
g = []
for i in range(n):
temp = list(inp())
g.append(temp)
a = [g[0][1],g[1][0],g[n-1][n-2],g[n-2][n-1]]
if(a[0] == a[1]):
if(a[2] == a[3]):
if(a[0] == a[2]):
print(2)
print(1,2)
print(2,1)
else:
print(0)
else:
if(a[2] == a[0]):
print(1)
print(n,n-1)
else:
print(1)
print(n-1,n)
else:
if(a[2] == a[3]):
if(a[0] == a[2]):
print(1)
print(1,2)
else:
print(1)
print(2,1)
else:
if(a[0] == a[2]):
print(2)
print(2,1)
print(n,n-1)
else:
print(2)
print(1,2)
print(n,n-1)
# testcase(1)
testcase(int(inp()))
| 8 |
PYTHON3
|
t = int(input())
while t!=0:
n = int(input())
list1 = []
for i in range(n):
temp = list(input())
list1.append(temp)
s1 = list1[0][1]
s2 = list1[1][0]
l1 = list1[-2][-1]
l2 = list1[-1][-2]
ans = []
if s1==s2:
if s1=="0":
if l1=="0":
ans.append([n-1,n])
if l2=="0":
ans.append([n,n-1])
else:
if l1=="1":
ans.append([n-1,n])
if l2=="1":
ans.append([n,n-1])
else:
if l1==l2:
if l1 == "0":
if s1 == "0":
ans.append([1, 2])
if s2 == "0":
ans.append([2, 1])
else:
if s1 == "1":
ans.append([1, 2])
if s2 == "1":
ans.append([2, 1])
else:
if s1=="0":
ans.append([2,1])
if l1=="0":
ans.append([n-1,n])
if l2=="0":
ans.append([n,n-1])
else:
ans.append([1,2])
if l1=="0":
ans.append([n-1,n])
if l2=="0":
ans.append([n,n-1])
print(len(ans))
for i in range(len(ans)):
print(*ans[i])
t-=1
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
const int N = 204;
int t, n;
string s[N];
void solve(char z1, char z2, char y1, char y2) {
if (z1 == '0' && z2 == '0') {
if (y1 == '1' && y2 == '1')
puts("0");
else if (y1 == '0' && y2 == '0') {
printf("2\n%d %d\n%d %d\n", n, n - 1, n - 1, n);
} else if (y1 == '1' && y2 == '0') {
printf("1\n%d %d\n", n - 1, n);
} else {
printf("1\n%d %d\n", n, n - 1);
}
}
if (z1 == '1' && z2 == '1') {
if (y1 == '0' && y2 == '0')
puts("0");
else if (y1 == '1' && y2 == '1') {
printf("2\n%d %d\n%d %d\n", n, n - 1, n - 1, n);
} else if (y1 == '0' && y2 == '1') {
printf("1\n%d %d\n", n - 1, n);
} else {
printf("1\n%d %d\n", n, n - 1);
}
}
}
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 0; i <= n - 1; ++i) cin >> s[i];
char z1 = s[1][0], z2 = s[0][1], y1 = s[n - 1][n - 2], y2 = s[n - 2][n - 1];
if (z1 == z2)
solve(z1, z2, y1, y2);
else if (z1 == '1' && z2 == '0') {
if (y1 == '1' && y2 == '0')
printf("2\n1 2\n%d %d\n", n, n - 1);
else if (y1 == '1' && y2 == '1')
printf("1\n2 1\n");
else if (y1 == '0' && y2 == '1')
printf("2\n1 2\n%d %d\n", n - 1, n);
else
printf("1\n1 2\n");
} else {
if (y1 == '1' && y2 == '0')
printf("2\n1 2\n%d %d\n", n - 1, n);
else if (y1 == '1' && y2 == '1')
printf("1\n1 2\n");
else if (y1 == '0' && y2 == '1')
printf("2\n1 2\n%d %d\n", n, n - 1);
else
printf("1\n2 1\n");
}
}
}
| 8 |
CPP
|
t = int(input())
for _ in range(t):
n = int(input())
arr = []
for i in range(n):
arr += [input()]
a, b = int(arr[0][1]), int(arr[1][0])
x, y = int(arr[-1][-2]), int(arr[-2][-1])
ans = []
if x == 0 and y == 0:
if a == 0:
ans += [[1, 2]]
if b == 0:
ans += [[2, 1]]
elif x == 1 and y == 1:
if a == 1:
ans += [[1, 2]]
if b == 1:
ans += [[2, 1]]
elif a == 0 and b == 0:
if x == 0:
ans += [[n, n-1]]
if y == 0:
ans += [[n-1, n]]
elif a == 1 and b == 1:
if x == 1:
ans += [[n, n-1]]
if y == 1:
ans += [[n-1, n]]
else:
#top left is 0, 0
if a == 0:
ans += [[2, 1]]
else:
ans += [[1, 2]]
#bottom right is 1, 1
if x == 0:
ans += [[n, n-1]]
if y == 0:
ans += [[n-1, n]]
print(len(ans))
for x in ans:
print(*x)
| 8 |
PYTHON3
|
def solve():
n = int(input())
grid = []
for i in range(0,n):
grid.append([x for x in input()])
a = grid[0][1]
b = grid[1][0]
c = grid[n-1][n-2]
d = grid[n-2][n-1]
changes = []
change = 0
if a==b:
if c==a:
change+=1
changes.append((n,n-1))
if d == a:
change += 1
changes.append((n-1, n))
else:
if d==c:
change+=1
if b==c:
changes.append((2,1))
else:
changes.append((1,2))
else:
change+=2
if a!=c:
changes.append((1,2))
changes.append((n,n-1))
elif a!=d:
changes.append((1, 2))
changes.append((n-1, n))
elif b!=c:
changes.append((2, 1))
changes.append((n, n - 1))
else:
changes.append((2, 1))
changes.append((n-1, n))
print(change)
for x in changes:
print(x[0], x[1])
return
def main():
t = int(input())
for i in range(t):
solve()
return
main()
| 8 |
PYTHON3
|
from sys import stdin
input = stdin.readline
def solve():
n = int(input())
s = [''] * n
for i in range(n):
s[i] = input().strip()
s1 = int(s[0][1])
s2 = int(s[1][0])
e1 = int(s[-1][-2])
e2 = int(s[-2][-1])
res = 0
r = []
if s1 == s2:
if e1 == s1:
res += 1
r.append(f'{n} {n-1}')
if e2 == s1:
res += 1
r.append(f'{n-1} {n}')
else:
if e1 == e2:
if s1 == e1:
res += 1
r.append('1 2')
if s2 == e1:
res += 1
r.append('2 1')
else:
if s1 == 0:
res += 1
r.append('1 2')
if s2 == 0:
res += 1
r.append('2 1')
if e1 == 1:
res += 1
r.append(f'{n} {n-1}')
if e2 == 1:
res += 1
r.append(f'{n-1} {n}')
print(res)
if res != 0:
print('\n'.join(r))
if __name__ == '__main__':
t = int(input())
for _ in range(t):
solve()
| 8 |
PYTHON3
|
if __name__ == '__main__':
t = int(input())
for i in range(t):
n = int(input())
matrix = [input() for j in range(n)]
# (1,2) (2,1) (n,n-1) (n-1,n)
val = matrix[0][1] + matrix[1][0] + matrix[n-1][n-2] + matrix[n-2][n-1]
answer = {
'0000' : [(1,2),(2,1)],
'0001' : [(n,n-1)],
'0010' : [(n-1,n)],
'0011' : [],
'0100' : [(1,2)],
'0101' : [(1,2), (n-1,n)],
'0110' : [(2,1), (n-1,n)],
'0111' : [(2,1)],
'1000' : [(2,1)],
'1001' : [(2,1), (n-1,n)],
'1010' : [(2,1), (n,n-1)],
'1011' : [(1,2)],
'1100' : [],
'1101' : [(n-1,n)],
'1110' : [(n,n-1)],
'1111' : [(1,2),(2,1)],
}
answer_t = answer[val]
print(len(answer_t))
for r,c in answer_t:
print('{} {}'.format(r,c))
| 8 |
PYTHON3
|
''' ===============================
-- @uthor : Kaleab Asfaw
-- Handle : kaleabasfaw2010
-- Bio : High-School Student
==============================='''
# Fast IO
import sys
import os
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); input = lambda: sys.stdin.readline().rstrip("\r\n")
# Others
# from math import floor, ceil, gcd
# from decimal import Decimal as d
mod = 10**9+7
def lcm(x, y): return (x * y) / (gcd(x, y))
def fact(x, mod=mod):
ans = 1
for i in range(1, x+1): ans = (ans * i) % mod
return ans
def arr2D(n, m, default=0): return [[default for j in range(m)] for i in range(n)]
def arr3D(n, m, r, default=0): return [[[default for k in range(r)] for j in range(m)] for i in range(n)]
def sortDictV(x): return {k: v for k, v in sorted(x.items(), key = lambda item : item[1])}
def solve(n, lst):
ans = []
if lst[0][1] == "1":
if lst[1][0] == "0":
ans.append([2, 1])
if lst[n-1][n-2] == "1":
ans.append([n, n-1])
if lst[n-2][n-1] == "1":
ans.append([n-1, n])
else:
if lst[1][0] == "1":
ans.append([2, 1])
if lst[n-1][n-2] == "0":
ans.append([n, n-1])
if lst[n-2][n-1] == "0":
ans.append([n-1, n])
if len(ans) > 2:
print(1)
print(1, 2)
else:
print(len(ans))
for i in ans:
print(i[0], i[1])
for _ in range(int(input())): # Multicase
n = int(input())
lst = []
for i in range(n):
lst.append(list(input()))
solve(n, lst)
| 8 |
PYTHON3
|
rn=lambda:int(input())
rl=lambda:list(map(int,input().split()))
rns=lambda:map(int,input().split())
rs=lambda:input()
yn=lambda x:print('Yes') if x else print('No')
YN=lambda x:print('YES') if x else print('NO')
for _ in range(rn()):
n=rn()
l=[]
for i in range(n):
l.append(input())
if l[0][1]==l[1][0]:
res=0
ans=[]
if l[-1][-2]==l[0][1]:
ans.append([n,n-1])
res+=1
if l[-2][-1]==l[0][1]:
ans.append([n-1,n])
res+=1
print(res)
for i in ans:
print(*i)
elif l[-1][-2]==l[-2][-1]:
res = 0
ans = []
if l[-1][-2] == l[0][1]:
ans.append([1,2])
res += 1
if l[-2][-1] == l[1][0]:
ans.append([2,1])
res += 1
print(res)
for i in ans:
print(*i)
else:
print(2)
print(2,1)
if l[-1][-2]==l[0][1]:
print(n,n-1)
else:
print(n-1,n)
| 8 |
PYTHON3
|
t=int(input())
for _ in range(t):
n=int(input())
grid=[]
for i in range(n):
grid.append(list(input()))
#print(grid)
top1=grid[0][1]
top2=grid[1][0]
down1=grid[n-2][n-1]
down2=grid[n-1][n-2]
if(top1=='0' and top2=='0'):
if(down1=='0' and down2=='0'):
print(2)
print(1,2)
print(2,1)
elif(down1=='0' and down2=='1'):
print(1)
print(n-1,n)
elif(down1=='1' and down2=='0'):
print(1)
print(n,n-1)
else:
print(0)
elif(top1=='1' and top2=='1'):
if(down1=='0' and down2=='0'):
print(0)
elif(down1=='0' and down2=='1'):
print(1)
print(n,n-1)
elif(down1=='1' and down2=='0'):
print(1)
print(n-1,n)
else:
print(2)
print(1,2)
print(2,1)
elif(top1=='0' and top2=='1'):
if(down1=='0' and down2=='0'):
print(1)
print(1,2)
elif(down1=='0' and down2=='1'):
print(2)
print(n-1,n)
print(2,1)
elif(down1=='1' and down2=='0'):
print(2)
print(2,1)
print(n,n-1)
else:
print(1)
print(2,1)
else:
if(down1=='0' and down2=='0'):
print(1)
print(2,1)
elif(down1=='0' and down2=='1'):
print(2)
print(n,n-1)
print(2,1)
elif(down1=='1' and down2=='0'):
print(2)
print(2,1)
print(n-1,n)
else:
print(1)
print(1,2)
| 8 |
PYTHON3
|
import sys
input=sys.stdin.readline
from collections import defaultdict as dc
from bisect import bisect_right
import math
for _ in range(int(input())):
n=int(input())
l=[]
for i in range(n):
l.append(list(input()))
a,b,x,y=l[0][1],l[1][0],l[n-1][n-2],l[n-2][n-1]
if a=='1' and b=='1':
if x=='0' and y=='0':
print(0)
else:
p=[]
c=0
if x=='1':
c+=1
p.append([n,n-1])
if y=='1':
c+=1
p.append([n-1,n])
print(c)
for t in p:
print(*t)
elif a=='0' and b=='0':
if x=='1' and y=='1':
print(0)
else:
p=[]
c=0
if x=='0':
c+=1
p.append([n,n-1])
if y=='0':
c+=1
p.append([n-1,n])
print(c)
for t in p:
print(*t)
else:
if x==y:
p=[]
if a==x:
p=[1,2]
else:
p=[2,1]
print(1)
print(*p)
else:
print(2)
if a=='1':
print(1,2)
elif b=='1':
print(2,1)
if x=='0':
print(n,n-1)
elif y=='0':
print(n-1,n)
| 8 |
PYTHON3
|
# Author: S Mahesh Raju
# Username: maheshraju2020
# Created on: 22/10/2020 00:46:10
from sys import stdin, stdout, setrecursionlimit
import heapq
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007
tc = ii1()
for _ in range(tc):
n = ii1()
arr = []
for i in range(n):
arr.append(is1())
st = [[0, 1], [1, 0]]
end = [[n - 1, n - 2], [n - 2, n - 1]]
one, two = [], []
for i in st:
if arr[i[0]][i[1]] == '0':
one.append([i[0] + 1, i[1] + 1])
else:
two.append([i[0] + 1, i[1] + 1])
for i in end:
if arr[i[0]][i[1]] == '0':
two.append([i[0] + 1, i[1] + 1])
else:
one.append([i[0] + 1, i[1] + 1])
if len(two) < 3:
print(len(two))
for i in two:
print(*i)
else:
print(len(one))
for i in one:
print(*i)
| 8 |
PYTHON3
|
test = int(input())
for _ in range(test):
n = int(input())
mat = []
for i in range(n):
mat.append(list(input()))
a = int(mat[-1][-2])
b = int(mat[-2][-1])
c = int(mat[0][1])
d = int(mat[1][0])
ans = []
if a==b:
ans = []
if c==a:
ans.append((1, 2))
if d==a:
ans.append((2, 1))
elif c==d:
if c==a:
ans.append((n, n-1))
if c==b:
ans.append((n-1, n))
else:
if a!=c:
ans.append((n, n-1))
ans.append((1, 2))
else:
ans.append((n, n-1))
ans.append((2, 1))
print(len(ans))
for x, y in ans:
print(x, y)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long n, long long mod) {
long long res = 1;
x %= mod;
while (n) {
if (n & 1) res = (res * x) % mod;
x = (x * x) % mod;
n >>= 1;
}
return res;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long c = 0, d = 0, i = 0, j = 0, k = 0, t = 0, n = 0, q = 0;
cin >> t;
while (t--) {
cin >> n;
pair<long long, long long> a, b;
string s[n];
for (long long i = 0; i < n; i++) {
cin >> s[i];
if (i == 1) a = make_pair(s[0][1] - '0', s[1][0] - '0');
if (i == n - 1)
b = make_pair(s[n - 1][n - 2] - '0', s[n - 2][n - 1] - '0');
}
long long ans = 0;
if (a.first + a.second == 2) {
if (b.first == 1) ans++;
if (b.second == 1) ans++;
cout << ans << "\n";
if (b.second) cout << n - 1 << " " << n << "\n";
if (b.first) cout << n << " " << n - 1 << "\n";
} else if (a.first + a.second == 0) {
if (b.first == 0) ans++;
if (b.second == 0) ans++;
cout << ans << "\n";
if (b.second == 0) cout << n - 1 << " " << n << "\n";
if (b.first == 0) cout << n << " " << n - 1 << "\n";
} else if (a.first + a.second == 1 && b.first + b.second == 1) {
cout << 2 << "\n";
if (a.first == 1) cout << 1 << " " << 2 << "\n";
if (a.second == 1) cout << 2 << " " << 1 << "\n";
if (b.first == 0) cout << n << " " << n - 1 << "\n";
if (b.second == 0) cout << n - 1 << " " << n << "\n";
} else if (a.first + a.second == 1 && b.first + b.second == 0) {
cout << 1 << "\n";
if (a.first == 0) cout << 1 << " " << 2 << "\n";
if (a.second == 0) cout << 2 << " " << 1 << "\n";
} else if (a.first + a.second == 1 && b.first + b.second == 2) {
cout << 1 << "\n";
if (a.first == 1) cout << 1 << " " << 2 << "\n";
if (a.second == 1) cout << 2 << " " << 1 << "\n";
}
}
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int myXOR(long long int x, long long int y) { return (x | y) & (~x | ~y); }
int main() {
int tt = 1;
cin >> tt;
while (tt--) {
long long int n, i, j;
cin >> n;
char a[n][n];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) cin >> a[i][j];
}
long long int ans = 0;
if (a[0][1] == a[1][0] && a[n - 1][n - 2] == a[n - 2][n - 1]) {
if (a[0][1] == a[n - 1][n - 2]) {
cout << 2 << "\n";
cout << 1 << " " << 2 << "\n";
cout << 2 << " " << 1 << "\n";
} else
cout << 0 << "\n";
} else {
vector<pair<long long int, long long int> > v;
long long int f = 0;
char ch;
if (a[0][1] == a[1][0]) {
f = 1;
ch = a[0][1];
}
if (a[n - 1][n - 2] == a[n - 2][n - 1]) {
f = 2;
ch = a[n - 1][n - 2];
}
if (f == 0) {
if (a[0][1] != '1') {
ans++;
v.push_back({1, 2});
} else if (a[1][0] != '1') {
ans++;
v.push_back({2, 1});
}
if (a[n - 1][n - 2] != '0') {
ans++;
v.push_back({n, n - 1});
} else if (a[n - 2][n - 1] != '0') {
ans++;
v.push_back({n - 1, n});
}
cout << ans << "\n";
for (i = 0; i < ans; i++) {
cout << v[i].first << " " << v[i].second << "\n";
}
}
if (f == 1) {
if (a[n - 2][n - 1] == ch) {
ans++;
v.push_back({n - 1, n});
} else if (a[n - 1][n - 2] == ch) {
ans++;
v.push_back({n, n - 1});
}
cout << ans << "\n";
for (i = 0; i < ans; i++) {
cout << v[i].first << " " << v[i].second << "\n";
}
}
if (f == 2) {
if (a[0][1] == ch) {
ans++;
v.push_back({1, 2});
} else if (a[1][0] == ch) {
ans++;
v.push_back({2, 1});
}
cout << ans << "\n";
for (i = 0; i < ans; i++) {
cout << v[i].first << " " << v[i].second << "\n";
}
}
}
cout << "\n";
}
}
| 8 |
CPP
|
cases = int(input())
for t in range(cases):
n = int(input())
s = []
for i in range(n):
s.append(list(input()))
l = [int(s[-1][-3]),int(s[-1][-2]),int(s[-2][-2]),int(s[-2][-1]),int(s[-3][-1])]
l1 = [1,0,1,0,1]
l2 = [0,1,0,1,0]
o1 = [l1[i]!=l[i] for i in range(5)]
o2 = [l2[i] != l[i] for i in range(5)]
so1 =sum(o1)
so2 = sum(o2)
if so1 <= so2:
print(so1)
if so1:
if o1[0]:
print(n,n-2)
if o1[1]:
print(n,n-1)
if o1[2]:
print(n-1,n-1)
if o1[3]:
print(n-1,n)
if o1[4]:
print(n-2,n)
else:
print(so2)
if so2:
if o2[0]:
print(n,n-2)
if o2[1]:
print(n,n-1)
if o2[2]:
print(n-1,n-1)
if o2[3]:
print(n-1,n)
if o2[4]:
print(n-2,n)
| 8 |
PYTHON3
|
for _ in range(int(input())):
n = int(input())
d = {}
for i in range(n):
o = input()
for j in range(n):
x = o[j]
d[(i+1,j+1)] = x
if d[(1,2)] == d[(2,1)] == d[(n,n-1)] == d[(n-1,n)]:
print(2)
print(1,2)
print(2,1)
continue
if d[(1,2)] == d[(2,1)] and d[(n,n-1)] == d[(n-1,n)]:
print(0)
continue
if d[(1,2)] == d[(2,1)] == "0":
print(1)
if d[(n,n-1)] == "0":
print(n,n-1)
else:
print(n-1,n)
continue
if d[(n,n-1)] == d[(n-1,n)] == "0":
print(1)
if d[(1,2)] == "0":
print(1,2)
else:
print(2,1)
continue
if d[(1, 2)] == d[(2, 1)] == "1":
print(1)
if d[(n, n - 1)] == "1":
print(n, n - 1)
else:
print(n - 1, n)
continue
if d[(n,n-1)] == d[(n-1,n)] == "1":
print(1)
if d[(1,2)] == "1":
print(1,2)
else:
print(2,1)
continue
if d[(1,2)] == "1":
print(2)
print(2,1)
if d[(n,n-1)] == "1":
print(n,n-1)
else:
print(n-1,n)
continue
else:
print(2)
print(1, 2)
if d[(n, n - 1)] == "1":
print(n, n - 1)
else:
print(n - 1, n)
continue
| 8 |
PYTHON3
|
import sys
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def solve():
n = mint()
a = [None]*n
for i in range(n):
a[i] = minp()
c = [None,None,None,None]
pos = [(0,1,0),(1,0,1),(2,n-1,n-2),(3,n-2,n-1)]
#print(a)
for i,x,y in pos:
c[i] = a[x][y]
for v in (0,0,1,1), (1,1,0,0):
cnt = sum([int(c[i])^v[i] for i in range(4)])
if cnt <= 2:
print(cnt)
for i,x,y in pos:
if int(c[i]) != v[i]:
print(x+1,y+1)
return
for i in range(mint()):
solve()
| 8 |
PYTHON3
|
T = int(input())
for t in range(T):
N = int(input())
M = []
for i in range(N):
M.append(input())
inverts = []
if M[0][1] == '0' and M[1][0] == '0':
if M[N-2][N-1] == '0':
inverts.append((N-2, N-1))
if M[N-1][N-2] == '0':
inverts.append((N-1, N-2))
elif M[0][1] == '1' and M[1][0] == '1':
if M[N-2][N-1] == '1':
inverts.append((N-2, N-1))
if M[N-1][N-2] == '1':
inverts.append((N-1, N-2))
elif M[0][1] == '0' and M[1][0] == '1':
if M[N-2][N-1] == '1' and M[N-1][N-2] == '1':
inverts.append((1, 0))
if M[N-2][N-1] == '0' and M[N-1][N-2] == '0':
inverts.append((0, 1))
if M[N-2][N-1] == '1' and M[N-1][N-2] == '0':
inverts.append((1, 0))
inverts.append((N-1, N-2))
if M[N-2][N-1] == '0' and M[N-1][N-2] == '1':
inverts.append((1, 0))
inverts.append((N-2, N-1))
elif M[0][1] == '1' and M[1][0] == '0':
if M[N-2][N-1] == '0' and M[N-1][N-2] == '0':
inverts.append((1, 0))
if M[N-2][N-1] == '1' and M[N-1][N-2] == '1':
inverts.append((0, 1))
if M[N-2][N-1] == '0' and M[N-1][N-2] == '1':
inverts.append((1, 0))
inverts.append((N-1, N-2))
if M[N-2][N-1] == '1' and M[N-1][N-2] == '0':
inverts.append((1, 0))
inverts.append((N-2, N-1))
print(len(inverts))
for i in inverts:
print(i[0]+1, i[1]+1)
| 8 |
PYTHON3
|
def solv():
x = int(input())
s = [list(input()) for n in range(x)]
ct = 0
v = []
if s[0][1] != '0':
ct += 1
v.append([1, 2])
if s[1][0] != '0':
ct += 1
v.append([2, 1])
if s[x-1][x-2] != '1':
ct += 1
v.append([x, x-1])
if s[x-2][x-1] != '1':
ct += 1
v.append([x-1, x])
if ct <= 2:
print(ct)
for n in v:
print(*n)
return
ct = 0
v = []
if s[0][1] != '1':
ct += 1
v.append([1, 2])
if s[1][0] != '1':
ct += 1
v.append([2, 1])
if s[x-1][x-2] != '0':
ct += 1
v.append([x, x-1])
if s[x-2][x-1] != '0':
ct += 1
v.append([x-1, x])
if ct <= 2:
print(ct)
for n in v:
print(*n)
return
for _ in range(int(input())):
solv()
| 8 |
PYTHON3
|
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 24 11:08:45 2020
@author: alber
"""
def pink(matrix,n):
counter = 0
final1 = matrix[n-1][n-2]
final2 = matrix[n-2][n-1]
entrada1 = matrix[0][1]
entrada2 = matrix[1][0]
if final1 == final2:
if entrada1 == final1:
counter += 1
x , y = 1, 2
if entrada2 == final1:
z, v = 2, 1
counter += 1
print(counter)
print(x, y, end = ' ')
print()
print(z, v, end = ' ')
print()
else:
print(counter)
print(x, y, end = ' ')
print()
elif entrada2 == final1:
counter += 1
z, v = 2, 1
print(counter)
print(z, v, end = ' ')
print()
else:
print(counter)
else:
if entrada1 == entrada2:
if entrada1 == final1:
counter += 1
z, v = n, n-1
print(counter)
print(z, v, end = ' ')
print()
elif entrada1 == final2:
counter += 1
z, v = n-1, n
print(counter)
print(z, v, end = ' ')
print()
else:
counter = 2
print(counter)
x, y = 1, 2
print(x, y, end = ' ')
print()
if entrada1 == final1:
z, v = n-1, n
print(z, v, end = ' ')
print()
else:
z, v = n, n-1
print(z, v, end = ' ')
print()
test = int(input())
for i in range(test):
matrix = []
n = int(input())
for j in range(n):
fila = input()
matrix.append(fila)
pink(matrix,n)
| 8 |
PYTHON3
|
for _ in range(int(input())):
n=int(input())
mat=[]
c=0
for i in range(n):
mat.append(list(input()))
out=[]
if mat[1][0]==mat[0][1]:
par=int(mat[1][0])^1
if mat[-1][-2]!=str(par):
c+=1
out.append((n,n-1))
if mat[-2][-1]!=str(par):
c+=1
out.append((n-1,n))
elif mat[-1][-2]==mat[-2][-1]:
par=int(mat[-1][-2])^1
if mat[1][0]!=str(par):
out.append((2,1))
c+=1
if mat[0][1]!=str(par):
out.append((1,2))
c+=1
else:
par=0
if mat[1][0]!=str(par):
out.append((2,1))
c+=1
else:
out.append((1,2))
c+=1
par=1
if mat[-1][-2]!=str(par):
c+=1
out.append((n,n-1))
if mat[-2][-1]!=str(par):
c+=1
out.append((n-1,n))
print(c)
for i in out:
print(*i)
| 8 |
PYTHON3
|
for ii in range(int(input())):
n=int(input())
a,c,ans=[],0,""
for jj in range(n):
a.append(input())
sr,sd,eu,el=a[0][1],a[1][0],a[n-2][n-1],a[n-1][n-2]
if sr == sd:
if el == sr:
c += 1
ans += str(n) + " " + str(n - 1) + "\n"
if eu == sr:
c += 1
ans += str(n - 1) + " " + str(n) + "\n"
else:
if sr == '0' and sd == '1':
if (eu == '1' and el == '1'):
c+=1
ans += str(2) + " " + str(1) + "\n"
elif (eu == '0' and el == '0'):
c += 1
ans += str(1) + " " + str(2) + "\n"
elif (eu == '0' and el == '1'):
c += 2
ans += str(1) + " " + str(2) + "\n"
ans += str(n) + " " + str(n-1) + "\n"
else:
c += 2
ans += str(1) + " " + str(2) + "\n"
ans += str(n-1) + " " + str(n) + "\n"
else:
if (eu == '1' and el == '1'):
c += 1
ans += str(1) + " " + str(2) + "\n"
elif (eu == '0' and el == '0'):
c += 1
ans += str(2) + " " + str(1) + "\n"
elif (eu == '0' and el == '1'):
c += 2
ans += str(1) + " " + str(2) + "\n"
ans += str(n - 1) + " " + str(n) + "\n"
else:
c += 2
ans += str(1) + " " + str(2) + "\n"
ans += str(n) + " " + str(n - 1) + "\n"
print(c)
print(ans.rstrip())
| 8 |
PYTHON3
|
t = int(input())
for ti in range(t):
n = int(input())
grid = []
for tn in range(n):
grid.append(input())
bord = [ grid[1][0], grid[0][1], grid[n-1][n-2], grid[n-2][n - 1] ]
ans = []
for ls in [ [ '0', '0' , '1' , '1'], ['1', '1', '0', '0' ]]:
ans = []
for i in range(4):
if ls[i] != bord[i]:
ans.append(i)
if len(ans) <= 2 :
break
print(len(ans))
if ans:
for i in ans:
x, y = [(2,1),(1,2),(n, n - 1), (n - 1, n )][i]
print(x, y)
| 8 |
PYTHON3
|
for _ in range(int(input())):
n = int(input())
l = []
for i in range(n):
a = input()
l.append(a)
ans = []
if l[0][1]==l[1][0]:
if l[0][1]=='1':
if l[n-2][n-1]=='1':
ans.append([n-1,n])
if l[n-1][n-2]=='1':
ans.append([n,n-1])
else:
if l[n-2][n-1]=='0':
ans.append([n-1,n])
if l[n-1][n-2]=='0':
ans.append([n,n-1])
elif l[n-2][n-1]==l[n-1][n-2]:
if l[n-2][n-1]=='1':
if l[0][1]=='1':
ans.append([1,2])
if l[1][0]=='1':
ans.append([2,1])
else:
if l[0][1]=='0':
ans.append([1,2])
if l[1][0]=='0':
ans.append([2,1])
else:
if l[0][1]!='0':
ans.append([1,2])
else:
ans.append([2,1])
if l[n-2][n-1]!='1':
ans.append([n-1,n])
else:
ans.append([n,n-1])
print(len(ans))
for i in ans:
print(i[0],i[1])
| 8 |
PYTHON3
|
t = int(input())
for _ in range(t):
n = int(input())
a = []
for i in range(n):
a.append(list(input()))
#print(a)
if ((a[0][1] == a[1][0]) and (a[n-1][n-2] == a[n-2][n-1])):
if (a[0][1] == a[n-1][n-2]):
print(2)
print("{} {}".format(n,n-1))
print("{} {}".format(n-1,n))
else:
print(0)
elif ((a[0][1] == a[1][0]) and (a[n-1][n-2] != a[n-2][n-1])):
if (a[0][1] == a[n-1][n-2]):
print(1)
print("{} {}".format(n,n-1))
else:
print(1)
print("{} {}".format(n-1,n))
elif ((a[0][1] != a[1][0]) and (a[n-1][n-2] == a[n-2][n-1])):
if (a[0][1] == a[n-1][n-2]):
print(1)
print("{} {}".format(1,2))
else:
print(1)
print("{} {}".format(2,1))
elif ((a[0][1] != a[1][0]) and (a[n-1][n-2] != a[n-2][n-1])):
if (a[0][1] != '0'):
print(2)
print("{} {}".format(1,2))
else:
print(2)
print("{} {}".format(2,1))
if (a[n-1][n-2] == '0'):
#print(1)
print("{} {}".format(n,n-1))
else:
#print(1)
print("{} {}".format(n-1,n))
| 8 |
PYTHON3
|
import math
t = int(input())
for _ in range(t):
n = int(input())
s = []
for i in range(n):
a = input()
s.append(list(a))
if s[0][1]==s[1][0]:
if s[-1][-2]==s[-2][-1]:
if s[-1][-2]==s[0][1]:
print(2)
print(n-1,n)
print(n,n-1)
else:
print(0)
else:
if s[-1][-2]==s[0][1]:
print(1)
print(n,n-1)
else:
print(1)
print(n-1,n)
else:
if s[-1][-2]==s[-2][-1]:
if s[-1][-2]==s[0][1]:
print(1)
print(1,2)
else:
print(1)
print(2,1)
else:
if s[-1][-2]==s[0][1]:
print(2)
print(1,2)
print(n-1,n)
else:
print(2)
print(n,n-1)
print(1,2)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
int n;
cin >> n;
getline(cin, s);
vector<vector<char>> v(n);
char c;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> c;
v[i].push_back(c);
}
getline(cin, s);
}
int ctr1 = 0, ctr2 = 0;
if (v[1][0] == v[0][1]) {
c = v[1][0];
if (v[n - 1][n - 2] == c) ctr1++;
if (v[n - 2][n - 1] == c) ctr2++;
cout << ctr1 + ctr2 << endl;
if (v[n - 1][n - 2] == c) cout << n << " " << n - 1 << endl;
if (v[n - 2][n - 1] == c) cout << n - 1 << " " << n << endl;
} else if (v[n - 1][n - 2] == v[n - 2][n - 1]) {
c = v[n - 1][n - 2];
if (v[1][0] == c) ctr1++;
if (v[0][1] == c) ctr2++;
cout << ctr1 + ctr2 << endl;
if (v[1][0] == c) cout << "2 1" << endl;
if (v[0][1] == c) cout << "1 2" << endl;
} else {
cout << "2\n";
if (v[1][0] == v[n - 1][n - 2])
cout << "2 1\n" << n - 1 << " " << n << endl;
else if (v[1][0] == v[n - 2][n - 1])
cout << "2 1\n" << n << " " << n - 1 << endl;
}
}
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5, mod = 1e9 + 7, len = 30;
void run_case() {
int n;
cin >> n;
char c[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) cin >> c[i][j];
vector<pair<int, int>> vec;
if (c[0][1] == c[1][0]) {
if (c[n - 1][n - 2] == c[0][1]) vec.push_back({n - 1, n - 2});
if (c[n - 2][n - 1] == c[0][1]) vec.push_back({n - 2, n - 1});
} else {
if (c[0][1] == c[n - 1][n - 2]) vec.push_back({0, 1});
if (c[1][0] == c[n - 1][n - 2]) vec.push_back({1, 0});
if (c[n - 1][n - 2] != c[n - 2][n - 1]) vec.push_back({n - 2, n - 1});
}
cout << vec.size() << endl;
for (auto i : vec) cout << i.first + 1 << " " << i.second + 1 << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) run_case();
}
| 8 |
CPP
|
t=int(input())
for j in range(t):
ans = []
n=int(input())
li = []
for i in range(n):
s=input()
k=len(s)
li.append(s)
if li[0][1] == li[1][0]:
if li[k-2][n-1] == li[k-1][n-2]:
if li[0][1] == li[k-2][n-1]:
r = []
r.append(1)
r.append(2)
ans.append(r)
r = []
r.append(2)
r.append(1)
ans.append(r)
else:
if li[0][1] == li[k-2][n-1]:
r = []
r.append(k-1)
r.append(n)
ans.append(r)
else:
r = []
r.append(k)
r.append(n-1)
ans.append(r)
else:
if li[k-2][n-1] == li[k-1][n-2]:
if li[0][1] == li[k-2][n-1]:
r = []
r.append(1)
r.append(2)
ans.append(r)
else:
r = []
r.append(2)
r.append(1)
ans.append(r)
else:
if li[0][1] == li[k-2][n-1]:
r = []
r.append(1)
r.append(2)
ans.append(r)
r = []
r.append(k)
r.append(n-1)
ans.append(r)
else:
r = []
r.append(1)
r.append(2)
ans.append(r)
r = []
r.append(k-1)
r.append(n)
ans.append(r)
print(len(ans))
for k in range(len(ans)):
print(ans[k][0],end=" ")
print(ans[k][1])
| 8 |
PYTHON3
|
t = int(input())
for _ in range(t):
a = int(input())
lis = []
for j in range(a):
if j == 0:
sh = list(input())
sh[0] = "7"
sh = list(map(int, sh))
elif j == a-1:
sh = list(input())
sh[-1] = "7"
sh = list(map(int, sh))
else:
sh = list(input())
sh = list(map(int, sh))
lis.append(sh)
# print(lis)
if lis[0][1] == 0 and lis[1][0] == 0 and lis[-1][-2] == 0 and lis[-2][-1] == 0:
print(2)
print("1 2")
print("2 1")
elif lis[0][1] == 1 and lis[1][0] == 0 and lis[-1][-2] == 0 and lis[-2][-1] == 0:
print(1)
print("2 1")
elif lis[0][1] == 0 and lis[1][0] == 1 and lis[-1][-2] == 0 and lis[-2][-1] == 0:
print(1)
print("1 2")
elif lis[0][1] == 1 and lis[1][0] == 1 and lis[-1][-2] == 0 and lis[-2][-1] == 0:
print(0)
elif lis[0][1] == 0 and lis[1][0] == 0 and lis[-1][-2] == 1 and lis[-2][-1] == 1:
print(0)
elif lis[0][1] == 1 and lis[1][0] == 0 and lis[-1][-2] == 1 and lis[-2][-1] == 1:
print(1)
print("1 2")
elif lis[0][1] == 0 and lis[1][0] == 1 and lis[-1][-2] == 1 and lis[-2][-1] == 1:
print(1)
print("2 1")
elif lis[0][1] == 1 and lis[1][0] == 1 and lis[-1][-2] == 1 and lis[-2][-1] == 1:
print(2)
print("1 2")
print("2 1")
elif lis[0][1] == 0 and lis[1][0] == 0 and lis[-1][-2] == 1 and lis[-2][-1] == 0:
print(1)
print("{} {}".format(a-1,a))
elif lis[0][1] == 1 and lis[1][0] == 0 and lis[-1][-2] == 1 and lis[-2][-1] == 0:
print(2)
print("1 2")
print("{} {}".format(a-1,a))
elif lis[0][1] == 0 and lis[1][0] == 1 and lis[-1][-2] == 1 and lis[-2][-1] == 0:
print(2)
print("1 2")
print("{} {}".format(a,a-1))
elif lis[0][1] == 1 and lis[1][0] == 1 and lis[-1][-2] == 1 and lis[-2][-1] == 0:
print(1)
print("{} {}".format(a,a-1))
elif lis[0][1] == 0 and lis[1][0] == 0 and lis[-1][-2] == 0 and lis[-2][-1] == 1:
print(1)
print("{} {}".format(a,a-1))
elif lis[0][1] == 1 and lis[1][0] == 0 and lis[-1][-2] == 0 and lis[-2][-1] == 1:
print(2)
print("1 2")
print("{} {}".format(a,a-1))
elif lis[0][1] == 0 and lis[1][0] == 1 and lis[-1][-2] == 0 and lis[-2][-1] == 1:
print(2)
print("{} {}".format(a,a-1))
print("2 1")
elif lis[0][1] == 1 and lis[1][0] == 1 and lis[-1][-2] == 0 and lis[-2][-1] == 1:
print(1)
print("{} {}".format(a-1,a))
| 8 |
PYTHON3
|
for _ in range(int(input())):
n=int(input())
a=[]
for i in range(n):
s=input()
t=[]
for j in s:
t.append(j)
a.append(t)
if a[0][1]==a[1][0]:
if a[n-1][n-2]==a[n-2][n-1]:
if a[n-1][n-2]==a[0][1]:
print(2)
print(n,n-1)
print(n-1,n)
else:
print(0)
else:
if a[n-1][n-2]==a[0][1]:
print(1)
print(n,n-1)
else:
print(1)
print(n-1,n)
else:
if a[n-1][n-2]==a[n-2][n-1]:
if a[n-1][n-2]==a[0][1]:
print(1)
print(1,2)
else:
print(1)
print(2,1)
else:
print(2)
if a[0][1]=='0':
print(2,1)
else:
print(1,2)
if a[n-1][n-2]=='1':
print(n-1,n)
else:
print(n,n-1)
| 8 |
PYTHON3
|
#import modules here
import math,sys,os
#from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict,Counter
import bisect as bi
#import heapq
from io import BytesIO, IOBase
mod=10**9+7
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.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")
#input functions
def minp(): return map(int, sys.stdin.readline().rstrip().split())
def linp(): return list(map(int, sys.stdin.readline().rstrip().split()))
def inp(): return int(input())
def print_list(l):
print(' '.join(map(str,l)))
#functions
def BinarySearch(a,x):
i=bi.bisect_left(a, x)
if i != len(a) and a[i] == x:
return i
else:
return -1
def gcd(a,b):
return math.gcd(a,b)
def is_prime(n):
"""returns True if n is prime else False"""
if n < 5 or n & 1 == 0 or n % 3 == 0:
return 2 <= n <= 3
s = ((n - 1) & (1 - n)).bit_length() - 1
d = n >> s
for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
p = pow(a, d, n)
if p == 1 or p == n - 1 or a % n == 0:
continue
for _ in range(s):
p = (p * p) % n
if p == n - 1:
break
else:
return False
return True
def mulinverse(a):
return pow(a,mod-2,mod)
####################Let's Go Baby########################
for _ in range(inp()):
n=inp()
a=[]
for i in range(n):
a.append(list(input()))
for i in range(n):
for j in range(n):
if (i==0 and j==0) or (i==n-1 and j==n-1):
continue
a[i][j]=int(a[i][j])
xs=a[0][1]
ys=a[1][0]
xf=a[n-1][n-2]
yf=a[n-2][n-1]
if xs==ys and ys==xf and xf==yf:
print(2)
print(n,n-1)
print(n-1,n)
elif xs==ys and xf==yf:
print(0)
elif (xs==yf and ys==xf):
print(2)
print(1,2)
print(n,n-1)
elif (xs==xf and ys==yf):
print(2)
print(1,2)
print(n-1,n)
elif xs==ys:
print(1)
if xf==xs:
print(n,n-1)
else:
print(n-1,n)
else:
print(1)
if xf==xs:
print(1,2)
else:
print(2,1)
#print(xs,xf,ys,yf)
| 8 |
PYTHON3
|
def testcase():
n = int(input())
grid = []
for _ in range(n):
grid.append(input())
s1, s2 = grid[0][1], grid[1][0]
f1, f2 = grid[-1][-2], grid[-2][-1]
if s1 == s2:
if f1 == f2:
if s1 == f1:
print(2)
print(1, 2)
print(2, 1)
return
else:
print(0)
return
else:
if s1 == f1:
print(1)
print(n, n - 1)
return
if s2 == f2:
print(1)
print(n - 1, n)
return
else:
if f1 == f2:
if s1 == f1:
print(1)
print(1, 2)
return
if s2 == f2:
print(1)
print(2, 1)
return
else:
x = s2
print(2)
print(2, 1)
if f1 == x:
print(n - 1, n)
else:
print(n, n - 1)
return
t = int(input())
for _ in range(t):
testcase()
| 8 |
PYTHON3
|
for _ in range(int(input())):
n = int(input())
arr= []
for i in range(n):
arr.append(input())
s1 = arr[0][1]
s2 = arr[1][0]
e1 = arr[n-2][n-1]
e2 = arr[n-1][n-2]
ans = []
if(s1==s2):
if(e1==s1):
ans.append((n-2,n-1))
if(e2==s1):
ans.append((n-1,n-2))
else:
if(e1==e2):
if(s1==e1):
ans.append((0,1))
if(s2==e1):
ans.append((1,0))
else:
ans.append((0,1))
if(e1==s2):
ans.append((n-2,n-1))
else:
ans.append((n-1,n-2))
print(len(ans))
for point in ans:
print(point[0]+1, point[1]+1)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(1337);
ostream& operator<<(ostream& a, const pair<long long, long long> b) {
cout << "{" << b.first << ", " << b.second << "}";
return a;
}
ostream& operator<<(ostream& a, const vector<long long int>& b) {
for (auto& k : b) cout << k << " ";
return a;
}
ostream& operator<<(ostream& a, const vector<pair<long long, long long> >& b) {
for (auto& k : b) cout << k << " ";
return a;
}
const long long int INF = (long long int)1e9;
const long long int MOD = 1000 * 1000 * 1000 + 7, MOD2 = 274876858367;
const long long int maxn = (long long int)3e5 + 10, L = 22;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int T = 1;
cin >> T;
while (T--) {
long long int n;
cin >> n;
vector<string> a(n);
for (long long int i = 0; i < n; ++i) cin >> a[i];
vector<pair<long long, long long> > ans, res;
if (a[0][1] != '0') ans.push_back({0, 1});
if (a[1][0] != '0') ans.push_back({1, 0});
if (a[2][0] != '1') ans.push_back({2, 0});
if (a[1][1] != '1') ans.push_back({1, 1});
if (a[0][2] != '1') ans.push_back({0, 2});
if (a[0][1] != '1') res.push_back({0, 1});
if (a[1][0] != '1') res.push_back({1, 0});
if (a[2][0] != '0') res.push_back({2, 0});
if (a[1][1] != '0') res.push_back({1, 1});
if (a[0][2] != '0') res.push_back({0, 2});
if (ans.size() > res.size()) swap(ans, res);
cout << ans.size() << '\n';
for (pair<long long, long long>& x : ans)
cout << x.first + 1 << " " << x.second + 1 << '\n';
}
return 0;
}
| 8 |
CPP
|
# coding=utf-8
# Created by TheMisfits
from sys import stdin
_input = stdin.readline
_range, _list, _str, _int = range, list, str, int
def solution():
for _ in _range(_int(_input())):
n = _int(_input())
arr = []
for i in _range(n):
arr.append(_list(_input().rstrip('\n')))
a,b,c,d = _int(arr[0][1]), _int(arr[1][0]), _int(arr[n-1][n-2]), _int(arr[n-2][n-1])
l, r = a+b, c+d
if l == 0 and r == 2 or l == 2 and r == 0:
print(0)
elif l == 0 and r == 0 or l == 2 and r == 2:
print(2)
print(1, 2)
print(2, 1)
elif r == 2:
if a == 0:
print(1)
print(2, 1)
else:
print(1)
print(1, 2)
elif l == 2:
if c == 0:
print(1)
print(n-1, n)
else:
print(1)
print(n, n - 1)
elif l == 0:
if c == 0:
print(1)
print(n, n - 1)
else:
print(1)
print(n - 1, n)
elif r == 0:
if a == 0:
print(1)
print(1, 2)
else:
print(1)
print(2, 1)
else:
if a == 0:
print(2)
print(1, 2)
if c == 0:
print(n-1, n)
else:
print(n, n-1)
else:
print(2)
print(2, 1)
if c == 0:
print(n - 1, n)
else:
print(n, n - 1)
solution()
| 8 |
PYTHON3
|
t=int(input())
while(t):
t=t-1
n=int(input())
for i in range(n):
s=input()
if(i==0):
ur=s[1]
if(i==1):
ud=s[0]
if(i==n-2):
du=s[-1]
if(i==n-1):
dl=s[-2]
if(ur=='1' and ud=='1'):
if(du=='0' and dl=='0'):
print(0)
continue
elif(du=='1' and dl=='1'):
print(2)
print(n-1,n)
print(n,n-1)
continue
elif(du=='0' and dl=='1'):
print(1)
print(n,n-1)
continue
else:
print(1)
print(n-1,n)
continue
elif(ur=='0' and ud=='0'):
if(du=='1' and dl=='1'):
print(0)
continue
elif(du=='0' and dl=='0'):
print(2)
print(n-1,n)
print(n,n-1)
continue
elif(du=='0' and dl=='1'):
print(1)
print(n-1,n)
continue
else:
print(1)
print(n,n-1)
continue
elif(ur=='0' and ud=='1'):
if(du=='1' and dl=='1'):
print(1)
print(2,1)
continue
elif(du=='0' and dl=='0'):
print(1)
print(1,2)
continue
elif(du=='0' and dl=='1'):
print(2)
print(1,2)
print(n,n-1)
continue
else:
print(2)
print(1,2)
print(n-1,n)
continue
else:
# ur = 1 ud = 0
if(du=='1' and dl=='1'):
print(1)
print(1,2)
continue
elif(du=='0' and dl=='0'):
print(1)
print(2,1)
continue
elif(du=='0' and dl=='1'):
print(2)
print(1,2)
print(n-1,n)
continue
else:
print(2)
print(1,2)
print(n,n-1)
continue
| 8 |
PYTHON3
|
import math
import sys,bisect
from heapq import *
from itertools import *
from collections import *
sys.setrecursionlimit(10 ** 6)
I = lambda : int(sys.stdin.readline())
neo = lambda : map(int, sys.stdin.readline().split())
Neo = lambda : list(map(int, sys.stdin.readline().split()))
for _ in range(I()):
n = I()
grid = [input() for i in range(n)]
a, b, c, d = grid[0][1], grid[1][0], grid[-2][-1], grid[-1][-2]
e,f = [],[]
if a != '0':
e.append((1, 2))
if b != '0':
e.append((2, 1))
if c != '1':
e.append((n-1, n))
if d != '1':
e.append((n, n-1))
if c != '0':
f.append((n-1,n))
if d != '0':
f.append((n, n-1))
if a != '1':
f.append((1,2))
if b != '1':
f.append((2,1))
if len(e) < len(f):
print(len(e))
for i in e:
print(*i)
else:
print(len(f))
for i in f:
print(*i)
| 8 |
PYTHON3
|
import sys
input = sys.stdin.readline
def main():
n = int(input())
maze = [input().strip() for _ in range(n)]
ans = []
if maze[0][1] == "0":
ans.append((1, 2))
if maze[1][0] == "0":
ans.append((2, 1))
if maze[n - 1][n - 2] == "1":
ans.append((n, n - 1))
if maze[n - 2][n - 1] == "1":
ans.append((n - 1, n))
if len(ans) <= 2:
print(len(ans))
for row in ans:
print(*row)
return
ans = []
if maze[0][1] == "1":
ans.append((1, 2))
if maze[1][0] == "1":
ans.append((2, 1))
if maze[n - 1][n - 2] == "0":
ans.append((n, n - 1))
if maze[n - 2][n - 1] == "0":
ans.append((n - 1, n))
if len(ans) <= 2:
print(len(ans))
for row in ans:
print(*row)
for _ in range(int(input())):
main()
| 8 |
PYTHON3
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.