#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin >> T;
while (T--)
{
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
a[i] = i + 1;
for (auto i : a)
cout << i << ' ';
cout << endl;
}
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t, n, m;
string s;
cin >> t;
while (t--)
{
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m)), b(n, vector<int>(m));
for (int i = 0; i < n; i++)
{
cin >> s;
for (int j = 0; j < m; j++)
a[i][j] = s[j];
}
for (int i = 0; i < n; i++)
{
cin >> s;
for (int j = 0; j < m; j++)
b[i][j] = s[j];
}
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
b[i][j] = (b[i][j] - a[i][j] + 3) % 3;
bool flag = true;
for (int i = 0; i < n; i++)
{
int cnt = 0;
for (int j = 0; j < m; j++)
cnt += b[i][j];
if (cnt % 3 != 0)
flag = false;
}
for (int j = 0; j < m; j++)
{
int cnt = 0;
for (int i = 0; i < n; i++)
cnt += b[i][j];
if (cnt % 3 != 0)
flag = false;
}
cout << (flag ? "YES\n" : "NO\n");
}
return 0;
}
C - Have Your Cake and Eat It Too
#include <bits/stdc++.h>
using namespace std;
#define int long long
int find(int a, int b)
{
int x[3] = { 0 };
x[a] = 1, x[b] = 1;
for (int i = 0; i < 3; i++)
if (!x[i])
return i;
return -1;
}
signed main()
{
int t;
cin >> t;
while (t--)
{
int n, tot = 0, target = 0;
cin >> n;
vector<int> a[3];
for (int k = 0; k < 3; k++)
{
a[k].assign(n, 0);
for (int i = 0; i < n; i++)
{
cin >> a[k][i];
tot += a[k][i];
}
}
target = (tot / 3 + 2) / 3;
vector<pair<int, int>> ans(3, {-1, -1});
for (int k = 0; k < 3; k++)
for (int s = 0; s < 3; s++)
{
if (s == k)
continue;
int i = 0, j = n - 1, prefix = a[k][i], suffix = a[s][j];
while (i < n && prefix < target)
++i, prefix += a[k][i];
while (j >= 0 && suffix < target)
--j, suffix += a[s][j];
if (j <= i)
continue;
int sum = 0, x = find(k, s);
for (int v = i + 1; v < j; v++)
sum += a[x][v];
if (sum >= target)
ans[k] = { 0, i }, ans[x] = { i + 1, j - 1 }, ans[s] = { j, n - 1 };
}
if (ans[0].first == -1)
{
cout << -1 << endl;
continue;
}
for (auto i : ans)
cout << i.first + 1 << ' ' << i.second + 1 << ' ';
cout << endl;
}
return 0;
}