#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m;
vector<string> s(N), ss(N);
bool check(int n, int m) {
if (n % 3) return false;
int divide = n / 3;
if (s[divide] == s[0] || s[divide * 2] == s[0] || s[divide] == s[divide * 2]) return false;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (s[i][j] != s[i / divide * divide][0]) return false;
}
}
return true;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
ss[j].push_back(s[i][j]);
}
}
if (check(n, m)) {
cout << "YES\n";
return 0;
}
swap(n, m);
s.clear(); // 清空字符串数组
s.resize(n); // 重新设置大小
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
s[i].push_back(ss[i][j]); // 使用push_back函数向vector中添加元素
}
}
if (check(n, m)) {
cout << "YES\n";
} else {
cout << "NO\n";
}
return 0;
}
/*
遍历所有的#统计最大即可简单bfs就行
*/
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
const int N = 1e3 + 5;
char arr[N][N];
int n, m, ans;
int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
bool isVaild(int x, int y) {
return x >= 1 && x <= n && y >= 1 && y <= m && arr[x][y] == '.';
}
queue<array<int, 3>> q;
void bfs() {
while (!q.empty()) {
auto [x, y, cnt] = q.front(); q.pop();
for (int i = 0; i < 4; ++i) {
int dx = x + dir[i][0];
int dy = y + dir[i][1];
if (isVaild(dx, dy)) {
arr[dx][dy] = '#';
q.push({dx, dy, cnt + 1});
ans = max(ans, cnt + 1);
}
}
}
cout << ans << '\n';
return ;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
cout << fixed << setprecision(12);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j<= m; j++) {
cin >> arr[i][j];
if (arr[i][j] == '#') {
q.push({i, j, 0});
}
}
}
bfs();
return 0;
}
/*
她吃n-1糖果, 给爸爸一颗 计算她吃的糖果是不是Sumodd == Sumeven即可
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
cout << fixed << setprecision(12);
int n; cin >> n;
vector<int> a(n);
int evenSum = 0, oddSum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i & 1) { evenSum += a[i]; }
else { oddSum += a[i]; }
}
int ans = 0, oddPre = 0, evenPre = 0;
for (int i = 0; i < n; i++) {
if (i & 1) { evenSum -= a[i]; }
else { oddSum -= a[i]; }
if (evenPre + oddSum == oddPre + evenSum) { ans++; }
if (i & 1) { evenPre += a[i]; }
else { oddPre += a[i]; }
}
cout << ans << '\n';
return 0;
}
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
i64 n; cin >> n;
vector<i64> a(n);
for (i64 &i : a) cin >> i;
sort(a.begin(), a.end());
i64 minn = a[0], maxx = a[n - 1], cnt1 = 0, cnt2 = 0;
if (a[0] == a[n - 1]) {
cout << n * (n - 1) << '\n';
return ;
}
for (i64 i = 0; i < n; i++) {
if (a[i] == minn) { cnt1++; }
if (a[i] == maxx) { cnt2++; }
}
cout << (cnt1 * cnt2 * 2) << '\n';
return ;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
cout << fixed << setprecision(12);
int T; cin >> T;
while (T--) {
solve();
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 110, K = 1e5 + 10;
int n, k, a[N];
int dp[K], sum[K];
int main() {
ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
dp[0] = 1;
for (int i = 1; i <= n; i++) {
sum[0] = dp[0];
for (int j = 1; j <= k; j++)
sum[j] = (sum[j - 1] + dp[j]) % mod;
for (int j = 0; j <= k; j++) {
if (j <= a[i]) dp[j] = sum[j];
else dp[j] = (sum[j] - sum[j - a[i] - 1] + mod) % mod;
}
}
cout << dp[k];
return 0;
}