inlineintread(){ int x = 0, f = 0; char c = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 3) + (x << 1) + (c & 15), c = getchar(); return f ? -x : x; }
int a[200010];
intmain(){ for (int T = read(); T --;) { int n = read(), id = 0, same = 1; for (int i = 1; i <= n; i ++) { a[i] = read(); if (i != 1 && a[i - 1] != a[i]) same = 0; } if (same) printf("%d\n", n); elseputs("1"); } return0; }
#include<bits/stdc++.h> usingnamespace std; #define int long long
inlineintread(){ int x = 0, f = 0; char c = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 3) + (x << 1) + (c & 15), c = getchar(); return f ? -x : x; }
#define INF (1e9 + 7) int a[200010];
signedmain(){ for (int T = read(); T --;) { int n = read(), k = read(), Mx = -INF, Mn = INF; for (int i = 1; i <= n; i ++) { a[i] = read(); Mx = max(Mx, a[i]); Mn = min(Mn, a[i]); } if (k & 1) { for (int i = 1; i <= n; i ++) { printf("%lld ", Mx - a[i]); } } else { for (int i = 1; i <= n; i ++) { printf("%lld ", a[i] - Mn); } } puts(""); } return0; }
#include<bits/stdc++.h> usingnamespace std; #define int long long
inlineintread(){ int x = 0, f = 0; char c = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 3) + (x << 1) + (c & 15), c = getchar(); return f ? -x : x; }
#define INF (1e9 + 7) int a[200010];
signedmain(){ for (int T = read(); T --;) { int n = read(), res = 0; for (int i = 1; i <= n; i ++) { a[i] = read(); res += max(0ll, a[i - 1] - a[i]); } printf("%lld\n", res); } return0; }
#include<bits/stdc++.h> usingnamespace std; #define int long long
inlineintread(){ int x = 0, f = 0; char c = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 3) + (x << 1) + (c & 15), c = getchar(); return f ? -x : x; }
char s[200010];
signedmain(){ for (int T = read(); T --;) { int n = read(), res = 0; scanf("%s", s + 1); int st = 1, i = 0; while (s[st] == s[1]) st ++; if (st > n) { if (n == 1) puts("0"); elseif (n == 2) puts("0"); elseif (n == 3) puts("1"); else { res = n / 3; if (res * 3 != n) res ++; printf("%lld\n", res); } continue; } i = st; do { int j = i, nw = 1; while (s[(j == n ? 1 : j + 1)] == s[i] && (j == n ? 1 : j + 1) != st) { nw ++; j ++; if (j > n) j = 1; } res += nw / 3; i = j + 1; if (i > n) i = 1; } while (i != st); printf("%lld\n", res); } return0; }
#include<bits/stdc++.h> usingnamespace std; #define int long long
inlineintread(){ int x = 0, f = 0; char c = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 3) + (x << 1) + (c & 15), c = getchar(); return f ? -x : x; }
#define N 110
int n, s[N], a[N][N];
signedmain(){ int n = read(); for (int i = 1; i <= n; i ++) { for (int j = 1; j <= n; j ++) { int x = i + j; a[i][j] = (s[x] ++ & 1ll) << x - 2; } } for (int i = 1; i <= n; i ++) { for (int j = 1; j <= n; j ++) { printf("%lld ", a[i][j]); } puts(""), fflush(stdout); } for (int T = read(); T --;) { int s = read(), x = 1, y = 1; while (x != n || y != n) { printf("%lld %lld\n", x, y), fflush(stdout); int st = s & (1ll << (x + y - 1ll)); (st == a[x + 1][y] && x < n) ? x ++ : y ++; } printf("%lld %lld\n", x, y), fflush(stdout); } return0; }