text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; if (a[0] + a[1] <= a[n - 1]) cout << ...
#include <bits/stdc++.h> using namespace std; const int sz = 1e5 + 5; int n, cut, a[sz], dp[sz]; void solve() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); if (a[0] + a[1] <= a[n - 1]) printf("1 2 %d\n", n); else puts("-1"); } int main() { int t; cin >> t; while (t--)...
#include <bits/stdc++.h> using namespace std; void IO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } template <typename... T> void read(T&... args) { ((cin >> args), ...); } template <typename... T> void write(T&&... args) { ((cout << args << " "), ...); } int mpow(int, int); long long int n; vo...
#include <bits/stdc++.h> using namespace std; template <class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, true : false; } template <class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, true : false; } template <typename T> struct IsC { template <typename C> static char test(typename C::cons...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; vector<long long int> a(n); for (long long int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); if (a[0] + a[1] <= a[n - 1]) cout << "1 2 " << n << ...
#include <bits/stdc++.h> using namespace std; int main() { int t, n; bool possible; long long a1[100000]; cin >> t; for (int i = 0; i < t; i++) { cin >> n; possible = false; for (int j = 0; j < n; j++) { cin >> a1[j]; } for (int j = 2; j < n; j++) { if (a1[j] >= a1[0] + a1[1]) ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } if (a[n] >= a[1] + a[2]) { cout << 1 << " " << 2 << " " << n << endl; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long int n, temp = 0; cin >> n; vector<long long int> a(n); for (long long int i = 0; i < n; i++) cin >> a[i]; if (a[0] + a[1] <= a[n...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); long long t; cin >> t; while (t--) { long long n, flag = 0; cin >> n; long long m[n], a[n], i; for (int i = 1; i <= n; i++) cin >> m[i]; if (m[1] + m[2] <= m[n]) ...
#include <bits/stdc++.h> using namespace std; using PII = pair<long long, long long>; const int maxn = 1e5 + 5; const long long mod = 1e9 + 7; int a[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int T = 1; cin >> T; while (T--) { int n; cin >> n; for (int i = 1; i <= n;...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; for (int i = 0; i < T; i++) { int n; cin >> n; vector<int> array; int a; for (int j = 0; j < n; j++) { cin >> a; array.push_back(a); } int max = array[n - 1]; if (array[0] + array[1] <= max) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long T; cin >> T; while (T--) { long long n; cin >> n; long long a[n + 1]; vector<int> vct; for (int i = 1; i <= n; i++) { cin >> a[i]; } bool b = false; bool flag = false; int k = 3; for (int i = 3; i <=...
#include <bits/stdc++.h> using namespace std; const long long int inf = LLONG_MAX; const long long int mod = 1e9 + 7; const long double pi = acos(-1); void solution() { long long int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; long long int ans = a[0] + a[1]; for (int i = 2; i ...
#include <bits/stdc++.h> using namespace std; void CyBerForCe() { long long n; cin >> n; vector<long long> v; for (long long i = 0; i < n; i++) { long long a; cin >> a; v.push_back(a); } long long a = 1, b = 2, c = 0; for (long long i = 2; i < v.size(); i++) { if (v[i] >= v[0] + v[1]) { ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int arr[n + 1]; for (int i = 1; i <= n; i++) { cin >> arr[i]; } if (arr[1] + arr[2] <= arr[n]) { cout << 1 << " " << 2 << " " << n << endl; } else { cout << -1 <...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } double pi = 3.141592653589; void solve() { long long n; cin >> n; long long a[n]; for (long long &i : a) cin >> i; if...
#include <bits/stdc++.h> using namespace std; long long amax(long long a[], long long n) { long long max = 0; for (long long i = 0; i < n; i++) { if (a[i] > max) max = a[i]; } return max; } long long amin(long long a[], long long n) { long long min = 1000000000; for (long long i = 0; i < n; i++) { i...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return b == 0 ? a : gcd(b, a % b); } long long int lcm(long long int a, long long int b) { return (a * b) / gcd(a, b); } bool isprime(long long int x) { for (long long int i = 2; i <= sqrt(x); i++) { if (x % i ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long long_max = 9223372036854775807; const long long inf = INT_MAX; void pr(long long n) { cout << (n) << "\n"; } void pr(string s) { cout << (s) << "\n"; } void pr(string s, string s2) { cout << (s) << " " << (s2) << "\n"; } voi...
#include <bits/stdc++.h> using namespace std; bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); } void solve() { long long int n; cin >> n; vector<pair<long long int, long long int>> vp; for (long long int i = 0; i < n; ++i) { long long int x; cin >> x; vp.push_back({x, i + 1}); }...
#include <bits/stdc++.h> using namespace std; int main() { long t, n, i; cin >> t; while (t--) { cin >> n; int a[n], x = 0; for (i = 0; i < n; i++) cin >> a[i]; for (i = 2; i < n; i++) { if ((a[0] + a[1]) <= a[i]) { cout << "1" << " " << "2" << ...
#include <bits/stdc++.h> using namespace std; void think() { long long n; cin >> n; vector<long long> a(n, 0); for (long long i = 0; i < n; i++) { cin >> a[i]; } if (a[0] + a[1] <= a[n - 1]) { cout << 1 << " " << 2 << " " << n << "\n"; } else { cout << -1 << "\n"; } } int32_t main() { ios_...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int N = 1e5 + 10; int t, n, a[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); cin >> t; while (t--) { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; int x = a[1], y = a[2], z = a[n...
#include <bits/stdc++.h> #pragma GCC optimize("O3") int mod = 1000000007; using namespace std; bool isp(long long x) { for (long long i = 2; i * i <= x; ++i) if (x % i == 0) return false; return true; } void pog() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; } bool sortinrev(const pair<long lon...
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) long long mod = 1e9 + 7; const int N = 5e4 + 10; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; long long T, n, m, x, y, z, ans, tem, cnt; struct node { long long id, v; }; node a[N]; int cmp(node a, node b) { return a.v < b.v; } int...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int t, n; cin >> t; for (int i = 0; i < t; i++) { cin >> n; unsigned long long int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } if (arr[0] + arr[1] <=...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int arr[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" << ...
#include <bits/stdc++.h> const long long MOD = 1e9 + 7; using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; long long arr[n]; for (int i = 0; i < n; ++i) cin >> arr[i]; if (arr[0] + arr[1] <= arr[n - 1]) cout << 1 << " " << 2 << " " << n << endl; else ...
#include <bits/stdc++.h> using namespace std; const long long int modu = 1e9 + 7; int noofdig(int N) { return floor(log10(N)) + 1; } int bits_count(unsigned int u) { unsigned int uCount; uCount = u - ((u >> 1) & 033333333333) - ((u >> 2) & 011111111111); return ((uCount + (uCount >> 3)) & 030707070707) % 63; } lo...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e4 + 5; int a[MAXN]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } int sum = a[0] + a[1]; int c = -1; ...
#include <bits/stdc++.h> using namespace std; int v[500005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, m, d, i, j, t; cin >> t; while (t--) { cin >> n; for (i = 1; i <= n; ++i) cin >> v[i]; if (v[1] + v[2] > v[n]) cout << -1 << '\n'; else cout << "1 2 ...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << "\n"; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(nam...
#include <bits/stdc++.h> using namespace std; int main() { int t = 0; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } if (a[0] + a[1] <= a[n - 1]) { cout << 1 << " " << 2 << " " << n << "\n"; } else cout << -1 << "\n"; ...
#include <bits/stdc++.h> using namespace std; int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1}; vector<string> vec_splitter(string s) { s += ','; vector<string> res; while (!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return ...
#include <bits/stdc++.h> #pragma GCC optimize("O2") #pragma GCC optimize("tree-vectorize") #pragma GCC target("sse4") using namespace std; using lint = long long; using pii = pair<int, int>; using pll = pair<lint, lint>; template <typename T> using vc = vector<T>; template <typename T> using vvc = vector<vector<T>>; te...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } long long int i = 0; int flag = 0; while (i < n - 2) { long long int x, y, z; x = a[i]; ...
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; vector<long long int> a(n); for (auto &x : a) cin >> x; long long int p = -1, q = -1, r = -1; long long int big = a[n - 1]; bool ok = false; for (int i = n - 2; i >= 0; i--) { if (a[i] + a[i - 1] <= big && i - 1 ...
#include <bits/stdc++.h> using namespace std; void test() { long long n; cin >> n; vector<long long> v; for (long long i = 0; i < n; i++) { long long num; cin >> num; v.push_back(num); } if (v[0] + v[1] <= v[n - 1]) { cout << 1 << " " << 2 << " " << n << endl; } else { cout << -1 << en...
#include <bits/stdc++.h> using namespace std; int main() { int64_t cases, total, elements, i; cin >> cases; for (i = 0; i < cases; i++) { int flag = 0, val = 0; vector<int> x = {}; cin >> total; for (int j = 0; j < total; j++) { cin >> elements; x.push_back(elements); } for (in...
#include <bits/stdc++.h> using namespace std; void showlist(list<long long int> g) { list<long long int>::iterator it; for (it = g.begin(); it != g.end(); ++it) cout << *it << " "; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { long lon...
#include <bits/stdc++.h> using namespace std; int main() { long long t, n, i, j, k, x, flag; long long* a; cin >> t; while (t--) { cin >> n; a = new long long[n]; for (i = 0; i < n; i++) { cin >> a[i]; } if (a[0] + a[1] <= a[n - 1]) { cout << "1 2 " << n << "\n"; } else { ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t) { int n; cin >> n; vector<int> vec; int flag = 1; for (int j = 0; j < n; j++) { int x; cin >> x; vec.push_back(x); } for (int i = 2; i < n; i++) { if (vec[0] + vec[1] <= vec[i]...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int n; cin >> n; vector<pair<int, int> > A(n); for (int i = 0; i < n; i++) { cin >> A[i].first; A[i].second = i + 1; } sort(A.begin(), A.end()); if (A[0].first + A[1].first <= A[n - 1]...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, i; cin >> t; while (t--) { cin >> n; long long int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } if (a[0] + a[1] > a[n - 1]) { cout << -1 << endl; } else { cout << 1 << " " << 2 << " " << n << endl; ...
#include <bits/stdc++.h> using namespace std; using ll = long long int; using dl = double; const int N = 2e5 + 10; ll aarray[200000 + 10]; ll magic[101][101]; vector<ll> primes; bool prime[1000001]; int main() { ios_base::sync_with_stdio(false); string str; ll i, j, n, m, k, t; cin >> t; while (t--) { cin...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; void solve() { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; if (n >= 3 && arr[0] + arr[1] <= arr[n - 1]) cout << "1 2 " << n << endl; else cout << "-1" << endl; } int main() { int T = 1; cin...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); ; int t; cin >> t; while (t--) { int a[5 * 10000 + 5] = {}; int n; cin >> n; for (int i = (0); i < (n); i += (1)) cin >> a[i]; if (a[0] + a[1] > a[n - 1...
#include <bits/stdc++.h> using namespace std; int main() { int T, n, vet[51234]; scanf("%d", &T); while (T--) { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &vet[i]); } if ((vet[0] + vet[1]) > vet[n - 1]) { puts("-1"); } else { printf("%d %d %d\n", 1, 2, n); ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long xyp(long long x, long long y) { long long res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x) % 1000000007; x = (x * x) % 1000000007; y /= 2; } ret...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t, n, i; cin >> t; while (t--) { cin >> n; long long int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } if (a[0] + a[1] > a[n - 1]) { cout << -1 << endl; } else {...
#include <bits/stdc++.h> int main() { int t; scanf("%d", &t); while (t--) { long long int n, i, j, k, f = 0; scanf("%lld", &n); long long int a[n]; for (i = 0; i < n; i++) scanf("%lld", &a[i]); for (i = 2; i < n; i++) { if (a[i] >= a[0] + a[1]) { f = 1; break; } ...
#include <bits/stdc++.h> using namespace std; long long MOD = 998244353; const long long L_INF = 1LL << 60; const long long INF = 2147483647; const double PI = acos(-1); template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chma...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, i, j; cin >> n; vector<long long int> v; long long int h; for (i = 0; i < n; i++) { cin >> h; v.push_back(h); } long long int a, b, c; a = v[0]; b = v[1]; ...
#include <bits/stdc++.h> using namespace std; long long n, t, a[50006]; int main() { cin >> t; while (t--) { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } if ((a[2] + a[1]) <= a[n]) { cout << "1 2 " << n << endl; ; } else cout << "-1" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<long long int> v(n); for (long long int i = 0; i < n; ++i) cin >> v[i]; if (v[0] + v[1] <= v.back()) { cout << "1 2 " << v.size(); return; } cout << -1; } int main() { ios::sync_with_stdio(0); cin.tie(0); co...
#include <bits/stdc++.h> using namespace std; int main() { long long int t, i, j; cin >> t; for (i = 1; i <= t; i++) { long long int n; cin >> n; long long int a[n + 1]; for (j = 1; j <= n; j++) { cin >> a[j]; } if ((a[1] + a[2]) <= a[n]) { cout << 1 << " " << 2 << " " << n << ...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n]; for (long long int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); if (a[0] + a[1] > a[n - 1]) cout << -1 << endl; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } if (v[n - 1] >= v[0] + v[1]) cout << 1 << " " << 2 << " " << n << endl; else ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 5; int a[maxn]; int main() { int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } if (a[1] + a[2] <= a[n]) { cout << 1 << " " << 2 << " " << n << endl; } else...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const long long int inf = 2e9 + 5; double PI = 3.14159265358979323846; void solve() { long long int n; cin >> n; long long int aa[n]; for (int i = 0; i < n; i++) { cin >> aa[i]; } long long int a = aa[0], b = aa[1], c = aa[...
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cer...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } if (arr[n - 1] >= arr[0] + arr[1]) { cout << "1 2 " << n << "\n"; ...
#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); cou...
#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" ...
#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])) ...
#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...
#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]...
#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 ma...
#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 ...
#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][...
#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 ...
#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]; ...
#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); } el...
#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...
#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]; } ...
#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); ...
#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])...
#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; } ...
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops") #pragma GCC optimize("Ofast", "no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long int exp(long l...
#include <bits/stdc++.h> using namespace std; void testCase() { long long n; cin >> n; vector<string> grid(n); vector<pair<long long, long long>> ans; for (string &s : grid) cin >> s; char t1 = grid[0][1]; char t2 = grid[1][0]; char b1 = grid[n - 1][n - 2]; char b2 = grid[n - 2][n - 1]; if (t1 == t2...
#include <bits/stdc++.h> using namespace std; void _print(long long t) { cerr << t; } void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _print(unsigned long long t) { cerr << t; } ...
#include <bits/stdc++.h> const long double eps = 1e-8; using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t = 1; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n + 1][n + 1]; string temp; for (long long ...
#include <bits/stdc++.h> using namespace std; inline int read() { int n = 0, f = 1, ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { n = n * 10 + ch - '0'; ch = getchar(); } return n * f; } char s[305][305]; int main() {...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, a[205][205]; char c; cin >> n; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { cin >> c; a[i][j] = c - '0'; } if (a[1][2] == a[2][1]) { if (a[n - 1][n]...
#include <bits/stdc++.h> using namespace std; void edit(vector<int> &skill, int n) { for (int i = 0; i < n; i++) { int x; cin >> x; skill.push_back(x); } } void achilles() { int n; cin >> n; char arr[n][n]; cin.ignore(); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin...
#include <bits/stdc++.h> using namespace std; int solve() { int n; cin >> n; string s[n]; for (int i = 0; i < n; i++) cin >> s[i]; if (s[0][1] == s[1][0] and s[n - 2][n - 1] == s[n - 1][n - 2] and s[0][1] != s[n - 2][n - 1]) { puts("0"); return 0; } if (s[0][1] == s[1][0]) { if (s[n - 1]...
#include <bits/stdc++.h> using namespace std; long long Min(long long a, long long b) { return (a < b) ? a : b; } long long Max(long long a, long long b) { return (a < b) ? b : a; } long long gcd(long long m, long long n) { if (n == 0) return m; return gcd(n, m % n); } long long lcm(long long m, long long n) { retu...
#include <bits/stdc++.h> using namespace std; int main() { int t, sr, sl, eu, ele; cin >> t; while (t--) { int n; scanf("%d", &n); getchar(); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { char c = getchar(); if (i == 1 && j == 2) sr = c - '0'; if (i ==...
#include <bits/stdc++.h> using namespace std; void solve() { int n; string s; vector<string> v; cin >> n; for (int i = (0); i < int(n); i++) { cin >> s; v.push_back(s); } vector<pair<int, int> > ans; if (v[0][1] == v[1][0]) { if (v[n - 1][n - 2] == v[0][1]) ans.push_back({n - 1, n - 2}); ...
#include <bits/stdc++.h> using namespace std; char mp[300][300]; int n; void solve() { int cnt = 0; if ((mp[1][2] - '0') && (mp[2][1] - '0')) { cnt = 0; if (mp[n][n - 1] - '0') { cnt++; } if (mp[n - 1][n] - '0') { cnt++; } printf("%d\n", cnt); if (mp[n][n - 1] - '0') { ...
#include <bits/stdc++.h> using namespace std; char s[205][205]; int main() { int t, n; scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1); vector<pair<int, int>> ans[2]; ans[s[1][2] == '1'].push_back(make_pair(1, 2)); ans[s[2][1] == '1'].push_bac...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long T, n, i, j; long long S_0, S_1, F_0, F_1, count; cin >> T; while (T--) { cin >> n; string A[n]; for (i = 0; i < n; i++) { cin >> A[i]; } S_0 = 0; S_1 = 0; F...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; char arr[n][n]; for (long long i = 0; i < n; i++) for (long long j = 0; j < n; j++) cin >> arr[i][j]; bool f = f...
#include <bits/stdc++.h> using namespace std; long long T, N, M, ans, temp; char m[200][2001]; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); cin >> T; for (long long t = 1; t <= T; t++) { cin >> N; for (long long i = 0; i < N; i++) { cin >> m[i]; } vector<pai...
#include <bits/stdc++.h> using namespace std; string mp[210]; int n; bool func(char x, char y) { int res = (mp[1][0] == x) + (mp[0][1] == x) + (mp[n - 1][n - 2] == y) + (mp[n - 2][n - 1] == y); if (res <= 2) { cout << res << "\n"; if (mp[1][0] != y) cout << "2 1" << "\n"; if...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, o = 0, c = 0; cin >> n; vector<vector<char>> V(n, vector<char>(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cin >> V[i][j]; } if (V[1][0] == V[0][1] && V[n - 1][n - 2] =...
#include <bits/stdc++.h> using namespace std; int n, t; char s[205][205]; int main() { cin >> t; int i, j, k; while (t--) { cin >> n; for (i = 1; i <= n; ++i) { cin >> (s[i] + 1); } int cnt = 0; bool i1 = 0, i2 = 0; if (s[1][2] == s[2][1]) { if (s[n][n - 1] == s[1][2]) { ...
#include <bits/stdc++.h> using namespace std; int main() { int t; int n; int list[201][201]; cin >> t; while (t > 0) { t--; cin >> n; char qwe; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if ((i == 0 && j == 0) || (i == (n - 1) && j == (n - 1))) { cin >>...
#include <bits/stdc++.h> using namespace std; clock_t time_p = clock(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long n; cin >> n; char s[n + 1][n + 1]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 210; char s[maxn][maxn]; bool vis[maxn][maxn]; int d[][2] = {1, 0, -1, 0, 0, 1, 0, -1}; int n; bool dfs(int x, int y, char ch) { for (int i = 0; i < 4; ++i) { int nx = x + d[i][0], ny = y + d[i][1]; if (nx == n && ny == n) return 1; if (nx < 1...