output stringlengths 52 181k | instruction stringlengths 296 182k |
|---|---|
#include <bits/stdc++.h>
bool debug = 0;
const long long MOD = 1000000007;
const double PI = acos(-1.0);
const double eps = 1e-9;
using namespace std;
set<int> adj[3000];
int father[3000], indeg[3000], res[3000], m, n;
char grid[3000][3000];
int find(int x) { return father[x] == x ? x : father[x] = find(father[x]); }
v... | ### Prompt
Create a solution in cpp for the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. ... |
#include <bits/stdc++.h>
using namespace std;
char c[1010][1010];
vector<int> v[2010];
int n, m, p[2010], val[2010], deg[2010];
bool vis[2010], flag;
int find_set(int x) {
if (p[x] == x) return x;
return p[x] = find_set(p[x]);
}
signed main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= ... | ### Prompt
Please formulate a Cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restauran... |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T lowbit(T x) {
return x & (-x);
}
template <class T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <class T>
inline T Pow(T a, T b, T p) {
T ret = 1;
a %= p;
for (; b; b >>= 1, a = a * a % p)
if (b & 1) (ret *= a) %= p;
... | ### Prompt
Develop a solution in cpp to the problem described below:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restauran... |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void init_ios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
const int N = 1005;
int n, m, res[2 * N], wyn[2 * N], p[2 * N], bla[2 * N];
char a[N][N];
vector<int> topo, child[2 * N], kto[2 * N];
bool vis[2 * N];
int Find(int x) {
if (x == p... | ### Prompt
Please create a solution in Cpp to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restauran... |
#include <bits/stdc++.h>
using namespace std;
const int N = 2000010, mod = 1e9 + 7;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getc... | ### Prompt
Construct a Cpp code solution to the problem outlined:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant M... |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int ans = 0, fh = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') fh = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
return ans * fh;
}
const i... | ### Prompt
Generate a Cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Ap... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4000 + 10;
const int MAXN = 2000000 + 10;
const int inf = 0x3f3f3f3f;
struct Edge {
int from;
int to;
int next;
} edge[MAXN];
int n, m, e, cnt, head[maxn], in[maxn], val[maxn], vis[maxn][maxn];
int pre[maxn], rnk[maxn];
char mp[maxn][maxn];
void add_e... | ### Prompt
Create a solution in cpp for the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. ... |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, m, fa[N], inDeg[N], val[N];
string s[1005];
vector<int> g[N];
int fi(int x) { return fa[x] == x ? x : fi(fa[x]); }
void unite(int x, int y) { fa[fi(y)] = fi(x); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
fo... | ### Prompt
Your task is to create a cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each res... |
#include <bits/stdc++.h>
int DEBUG = 1;
using namespace std;
const int N = 1000 + 5;
int parent[N + N], sz[N + N];
int find_set(int v) {
if (parent[v] == v) return v;
return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
parent[v] = v;
sz[v] = 1;
}
void merge(int a, int b) {
a = find_set(a);
b = ... | ### Prompt
Construct a CPP code solution to the problem outlined:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant M... |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char mp[1005][1005];
int pre[2 * 1005];
bool vis[2 * 1005];
int in[2 * 1005];
int ans[2 * 1005];
vector<int> g[2 * 1005];
struct no {
int a, c;
};
int found(int x) {
int re = x;
while (re != pre[re]) {
re = pre[re];
}
while (x != pre[x]) {
int t ... | ### Prompt
Please create a solution in cpp to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restauran... |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
char a[1005][1005];
vector<int> e[2005];
int cont[2005];
int ans[2005];
int fa[2005];
int n, m;
int f(int x) {
if (fa[x] == x) return x;
return fa[x] = f(fa[x]);
}
void unite(int u, int v) {
int _u, _v;
_u = f(u);
_v = f(v);
if (_u != _v) fa... | ### Prompt
Generate a CPP solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Ap... |
#include <bits/stdc++.h>
using namespace std;
struct enode {
int y, nxt;
} e[1005 * 1005];
int n, m;
int tot = 0;
char s[1005][1005];
int q[1005 * 3];
int fa[1005 * 3], first[1005 * 3], dp[1005 * 3], goin[1005 * 3];
int get(int x) {
if (fa[x] == x)
return x;
else
return fa[x] = get(fa[x]);
}
void adde(int... | ### Prompt
Create a solution in CPP for the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. ... |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[1001], b[1001], sa[1001], sb[1001], s, ok,
val = 1, ln, lm, Ok, v[1001][1001], eg1[1001], eg2[1001], mn;
char c;
int main() {
cin >> n >> m;
ln = m;
lm = n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> c;
switc... | ### Prompt
Construct a Cpp code solution to the problem outlined:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant M... |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)3e3;
int p[N], n, m, deg[N], d[N];
char a[N][N];
vector<int> adj[N];
queue<int> q;
bool visited[N];
int findSet(int u) { return p[u] == u ? p[u] : p[u] = findSet(p[u]); }
void unionSet(int u, int v) {
int x = findSet(u), y = findSet(v);
p[x] = y;
}
in... | ### Prompt
Create a solution in CPP for the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. ... |
#include <bits/stdc++.h>
using namespace std;
class Graph {
public:
vector<vector<int> > adjList;
vector<int> indegree;
Graph(int v) {
adjList.resize(v);
indegree.resize(v, 0);
}
void add(int u, int v) {
adjList[u].push_back(v);
indegree[v]++;
}
};
struct subset {
int rank;
int parent;
... | ### Prompt
Generate a Cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Ap... |
#include <bits/stdc++.h>
using namespace std;
struct READ {
int d1, d2, d3;
READ(int d1 = -1, int d2 = -1, int d3 = -1) : d1(d1), d2(d2), d3(d3) {}
template <class T>
operator T() {
T tmp;
this->read(tmp);
return tmp;
}
template <class T>
void read(T& t) {
cin >> t;
}
template <class T... | ### Prompt
Generate a cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Ap... |
#include <bits/stdc++.h>
using namespace std;
using INT = long long;
char s[2100][2100];
vector<int> adj[2100], rev[2100];
int arr[2100];
vector<int> vec[2100];
int root[2100];
int find_root(int u) {
if (root[u] == u) return u;
return root[u] = find_root(root[u]);
}
void merge(int u, int v) {
if (find_root(u) == ... | ### Prompt
Generate a CPP solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Ap... |
#include <bits/stdc++.h>
using namespace std;
int root(vector<int> &p, int i) {
while (p[i] != i) {
p[i] = p[p[i]];
i = p[i];
}
return i;
}
void init(vector<int> &p, vector<int> &s) {
for (int i = 0; i < p.size(); i++) {
p[i] = i;
}
for (auto &i : s) {
i = 1;
}
}
void merge(int i, int j, v... | ### Prompt
Develop a solution in cpp to the problem described below:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restauran... |
#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[2005];
long long vis[2005];
long long ans[2005];
struct DSU {
long long size;
vector<long long> id;
vector<long long> si;
DSU(long long x) {
size = x;
id.resize(x + 1);
si.resize(x + 1);
for (long long i = 0; i < x; i++) {
... | ### Prompt
Please create a solution in cpp to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restauran... |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline int read() {
int x = 0;
bool op = false;
char c = getchar();
while (!isdigit(c)) op |= (c == '-'), c = getchar();
while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return op ? -x : x;
}
const int N = 3010;
const... | ### Prompt
Generate a CPP solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Ap... |
#include <bits/stdc++.h>
using namespace std;
set<long long> graph[2000];
char matrix[1000][1000];
bool crash = false;
void dfs(long long v, vector<long long> &used, vector<long long> &dp) {
used[v] = 1;
long long maxu = 0;
for (long long u : graph[v]) {
if (!used[u]) {
dfs(u, used, dp);
maxu = ma... | ### Prompt
Please formulate a Cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restauran... |
#include <bits/stdc++.h>
using namespace std;
int cc, to[1000010], net[1000010], fr[3000], ind[3000], fa[3000];
int q[3000], ans[3000], n, m;
char ch[1010][1010];
void addedge(int u, int v) {
cc++;
to[cc] = v;
net[cc] = fr[u];
fr[u] = cc;
ind[v]++;
}
int fafa(int x) {
if (fa[x] == x) return x;
return fa[x... | ### Prompt
Generate a Cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Ap... |
#include <bits/stdc++.h>
using namespace std;
vector<int> par;
vector<int> sz;
vector<long long> w;
vector<vector<char> > a;
vector<vector<int> > lessy;
vector<vector<int> > more;
vector<int> color;
vector<bool> used;
bool globok = true;
int find_set(int v) {
if (par[v] == v)
return v;
else
return par[v] = ... | ### Prompt
In Cpp, your task is to solve the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr.... |
#include <bits/stdc++.h>
using namespace std;
void fun() {}
int md = 1e9 + 7;
int __gcd(int a, int b) {
if (b == 0) return a;
return __gcd(b, a % b);
}
int poww(int a, int b, int md) {
if (b < 0) return 0;
if (a == 0) return 0;
int res = 1;
while (b) {
if (b & 1) {
res = (1ll * res * a) % md;
... | ### Prompt
Your task is to create a CPP solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each res... |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e3 + 5;
const int MAX_M = 4e5 + 5;
const int INF = 0x3f3f3f3f;
struct Edge {
int v, next;
} es[MAX_N * MAX_N];
int n, m, fa[MAX_N << 1], cnt1, tot, head[MAX_N << 1], ind[MAX_N << 1],
eval[MAX_N << 1], cnt2;
char g[MAX_N][MAX_N];
queue<int> Q;
inline... | ### Prompt
In Cpp, your task is to solve the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr.... |
#include <bits/stdc++.h>
using std::max;
int head[2001], nxt[2000001], b[2000001], k, f[2001], comp[1001][1001], n, m,
nodes, d[2001], q[2001], t, h, ans[2001], orig;
int get() {
char ch = getchar();
while (ch != '<' && ch != '=' && ch != '>') ch = getchar();
return (ch == '<') ? (-1) : ((ch == '=') ? 0 : 1);... | ### Prompt
In cpp, your task is to solve the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr.... |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
long long power(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y ... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
vector<string> data;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
string row;
cin >> row;
data.push_back(row);
}
vector<vector<int> > set;
set.resize(2);
set[0].resize(n, 0);
set[1].resize(m, 0);
vector<vector<int> > se... | ### Prompt
Please formulate a Cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restauran... |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> v[2005];
long long int vis[2005] = {0};
long long int in_stack[2005] = {0};
long long int value[2005];
bool dfs(long long int node) {
long long int i;
vis[node] = 1;
if (v[node].size() == 0) {
value[node] = 1;
return true;
}
in_stack[... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each... |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005, M = 1005;
int n, m, fa[N], To[M * M], Ne[M * M], St[N], en, ind[N], wg[N];
char mp[M][M];
queue<int> q;
int Find(int u) { return fa[u] == 0 ? u : fa[u] = Find(fa[u]); }
void addedge(int u, int v) {
To[++en] = v, Ne[en] = St[u], St[u] = en;
++ind[v];
... | ### Prompt
Create a solution in cpp for the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. ... |
#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = (((1 << 30) - 1) << 1) + 1;
const int nINF = 1 << 31;
void bad() {
cout << "No" << endl;
exit(0);
}
const int N = 2010;
int parent[N];
int sz[N];
int find(int x) { return parent[x] = (x ==... | ### Prompt
Generate a Cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Ap... |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void init_ios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
const int N = 1005;
int n, m, res[2 * N], wyn[2 * N], p[2 * N], bla[2 * N];
char a[N][N];
vector<int> topo, child[2 * N], kto[2 * N];
bool vis[2 * N];
int Find(int x) {
if (x == p... | ### Prompt
Your task is to create a Cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each res... |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1002;
int n, m;
char table[MAX][MAX];
struct UnionFind {
int n, p[2 * MAX], w[2 * MAX];
UnionFind(int _n) {
n = _n;
for (int i = 0; i < n; i++) w[i] = 1;
for (int i = 0; i < n; i++) p[i] = i;
}
void uni(int i, int j) {
int u = root(i)... | ### Prompt
Develop a solution in CPP to the problem described below:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restauran... |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e3 + 5;
const long long MOD = 1e9 + 7;
int n, m, a[MAXN], vis[MAXN], pre[MAXN];
vector<int> v[MAXN];
char mp[MAXN][MAXN];
struct node {
int x, val;
} p;
queue<node> q;
int Find(int x) { return pre[x] == x ? x : pre[x] = Find(pre[x]); }
int main() {... | ### Prompt
In Cpp, your task is to solve the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr.... |
#include <bits/stdc++.h>
using namespace std;
class DisjointedSetMergingStructure {
vector<size_t> parent;
public:
explicit DisjointedSetMergingStructure(const size_t size) {
parent = vector<size_t>(size);
iota(parent.begin(), parent.end(), size_t());
}
void join(const size_t A, const size_t B) {
... | ### Prompt
Your task is to create a CPP solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each res... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int> > equals_n_m(n + m, vector<int>());
vector<vector<int> > major_n_m(n + m, vector<int>());
vector<int> minor_n_m(n + m, 0);
vector<vector<char> > input_matrix(n, vector<char>(m));
vector<int> result(n + m... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each... |
#include <bits/stdc++.h>
using namespace std;
template <typename _tp>
inline void read(_tp& x) {
char c11 = getchar(), ob = 0;
x = 0;
while (c11 != '-' && !isdigit(c11)) c11 = getchar();
if (c11 == '-') ob = 1, c11 = getchar();
while (isdigit(c11)) x = x * 10 + c11 - '0', c11 = getchar();
if (ob) x = -x;
}
... | ### Prompt
Please create a solution in CPP to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restauran... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
int n, m, father[maxn << 1], ru[maxn << 1], vis[maxn << 1], ans[maxn << 1];
vector<int> g[maxn << 1];
char s[maxn][maxn];
int findfather(int x) {
if (x == father[x]) return x;
int i = findfather(father[x]);
father[x] = i;
return i;
}
void u... | ### Prompt
Your task is to create a CPP solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each res... |
#include <bits/stdc++.h>
using namespace std;
void test() { cerr << "\n"; }
template <typename T, typename... Args>
void test(T x, Args... args) {
cerr << x << " ";
test(args...);
}
const int MAXN = (int)1e5 + 5;
const int MOD = (int)1e9 + 7;
char g[1005][1005];
int a[1005], b[1005];
int main() {
int n, m;
scan... | ### Prompt
Generate a Cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Ap... |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
template <size_t N>
struct DSU {
int parent[N];
void init(int n) { iota(parent + 1, parent + n + 1, 1); }
int find(int x) { return x == parent[x] ? x : parent[x] = find(parent[x]); }
void merge(int x, int y) { parent[find(x)] = find(y); }
};
i... | ### Prompt
In CPP, your task is to solve the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr.... |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2007;
long long n, m;
char a[N][N];
vector<long long> g[N], g1[N];
bool used[N];
long long c[N];
void dfs(long long u, long long cc) {
used[u] = 1;
c[u] = cc;
for (long long v : g[u]) {
if (!used[v]) dfs(v, cc);
}
}
long long ans[N];
void dfs... | ### Prompt
Develop a solution in cpp to the problem described below:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restauran... |
#include <bits/stdc++.h>
int n, m, fa[2005];
char s[2005][2005], G[2005][2005];
int in[2005], dis[2005];
int find(int x) { return fa[x] ? fa[x] = find(fa[x]) : x; }
inline void join(int a, int b) {
int x = find(a), y = find(b);
if (x != y) fa[x] = y;
}
bool bfs() {
std::queue<int> q;
int i, u, cnt = 0;
for (i... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each... |
#include <bits/stdc++.h>
using namespace std;
int N, M;
string grid[1000];
vector<vector<pair<int, char>>> startAdj;
vector<bool> visited;
vector<int> merged;
vector<vector<pair<int, char>>> adj;
vector<int> value;
vector<int> greaterCount;
void flood(int start, int pos) {
if (visited[pos]) return;
visited[pos] = t... | ### Prompt
Your task is to create a CPP solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each res... |
#include <bits/stdc++.h>
using namespace std;
vector<int> V[4444];
string s[4444];
int fa[4444], D[4444], ans[4444];
int fd(int x) {
if (x == fa[x]) return x;
return fa[x] = fd(fa[x]);
}
int main() {
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
for (int i = 0; i < 4444; i++) fa[i] = i;
int n... | ### Prompt
Your task is to create a cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each res... |
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int p_mod = 998244353;
using namespace std;
long long fast_pow(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res = (res * a) % mod;
b >>= 1;
a = (a * a) % mod;
}
return res % mod;
}
const int N = 2000 + 10;
char g[N][N];... | ### Prompt
Please provide a CPP coded solution to the problem described below:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each... |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
const int MAXM = 200000;
inline void dfs(int);
struct edge {
int v, w;
};
int Error;
int dis[MAXN + 1];
bitset<MAXN + 1> vis, chk;
int sz[MAXN + 1];
vector<edge> to[MAXN + 1];
void dfs(int x) {
vis[x] = 1;
int si = sz[x];
for (int i = 0; i <... | ### Prompt
Construct a Cpp code solution to the problem outlined:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant M... |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
int id[MAXN];
int cnt[MAXN];
vector<int> graph[MAXN];
int outDegree[MAXN];
int n, m;
char str[MAXN][MAXN];
bool vis[MAXN];
int value[MAXN];
int findRoot(int a) {
if (id[a] == a) {
return a;
}
return id[a] = findRoot(id[a]);
}
void unite(int ... | ### Prompt
In Cpp, your task is to solve the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr.... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1111;
struct Edge {
int to, next, val;
};
Edge edge[maxn * maxn];
int head[maxn << 1], vis[maxn << 1], dis[maxn << 1], cnt;
int fin[maxn << 1];
int n, m;
int f[maxn << 1];
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
void merge(int x, int... | ### Prompt
Please formulate a Cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restauran... |
#include <bits/stdc++.h>
using namespace std;
int const N = 3e5 + 2, oo = 1e9;
long long const OO = 2e18;
double const eps = 1e-8, PI = acos(-1);
int mod = oo + 7;
string aa[1001];
int lar[2][1001], eq[2][1001], er[2][1001], val[2][1001];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int now = 1;
int n, m;
... | ### Prompt
Your task is to create a CPP solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each res... |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
const int MOD = 1e9 + 7;
vector<int> g[N + N];
int mat[N][N], p[N + N], sub[N + N], vis[N + N];
int ans[N + N], instack[N + N], go = true, ct = 0;
vector<pair<int, int>> extime;
void putNumbers(int node) {
vis[node] = 1;
instack[node] = true;
ct... | ### Prompt
Create a solution in cpp for the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. ... |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
namespace DSU {
int fa[MAXN << 1];
void init(int n) {
for (int i = 1; i <= n; i++) fa[i] = i;
}
int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }
bool Union(int x, int y) {
x = Find(x), y = Find(y);
if (x == y) return 0;
retu... | ### Prompt
Create a solution in Cpp for the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. ... |
#include <bits/stdc++.h>
using namespace std;
char s[1005][1005];
int vis[3 * 1005], fa[3 * 1005], in[3 * 1005], ans[3 * 1005];
vector<int> v[3 * 1005];
int findd(int x) { return x == fa[x] ? x : fa[x] = findd(fa[x]); }
int main() {
int n, m, i, j;
cin >> n >> m;
for (i = 0; i < n; i++) {
scanf("%s", s[i]);
... | ### Prompt
Please formulate a cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restauran... |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
const int INF = 0x3f3f3f3f;
char mp[N][N];
int sec[N], fir[N];
int num[3];
int b[N + N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
getchar();
scanf("%s", mp[i] + 1);
}
for (int i = 1; i <= n; i++) ... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each... |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
char s[MAXN][MAXN];
vector<int> G[MAXN << 1];
int indec[MAXN << 1];
int ans[MAXN << 1];
bool vis[MAXN << 1];
struct DSU {
int p[MAXN << 1];
int sz;
void init(int n) {
sz = n;
for (int i = 1; i <= n; i++) {
p[i] = i;
}
}
... | ### Prompt
Please formulate a Cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restauran... |
#include <bits/stdc++.h>
using namespace std;
const long long Mod = 7 + 1e9;
const long long INF32 = 5 + 2e9;
const long long INF64 = 1 + 1e18;
const long long MAX = 5 + 1e3;
int N, M, parent[2 * MAX], dp[2 * MAX];
vector<long long> G[2 * MAX];
set<int> GG[2 * MAX];
bool eq[2 * MAX][2 * MAX];
int vis[2 * MAX];
void mer... | ### Prompt
Develop a solution in Cpp to the problem described below:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restauran... |
#include <bits/stdc++.h>
#pragma GCC target("avx,sse2,sse3,sse4,popcnt")
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
inline int POW(int a, int b = 1000000007 - 2, int ans = 1) {
for (; b; b >>= 1, a = (long long)a * a % 1000000007)
if (b & 1) ans = (long long)ans * a ... | ### Prompt
Construct a cpp code solution to the problem outlined:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant M... |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 1e3 + 5;
int n, m, par[2 * N], sz[2 * N];
int id[2 * N], ans[2 * N];
vector<int> g[2 * N];
bool vis[2 * N], in[2 * N];
char a[N][N];
int find(int u) { return par[u] == u ? u : par[u] = find(par[u]); }
void join(int u, int v) {
u = ... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each... |
#include <bits/stdc++.h>
using namespace std;
struct Edge {
int v, w;
} edge[1000000 * 2 + 10];
int d[1010 * 2], cnt[1010 * 2];
vector<int> G[1010 * 2];
bool vis[1010 * 2];
bool spfa(int n, int m) {
memset(cnt, 0, sizeof(cnt));
memset(d, 0, sizeof(d));
memset(vis, true, sizeof(vis));
queue<int> qu;
for (int... | ### Prompt
Please formulate a CPP solution to the following problem:
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restauran... |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 105;
long long m;
struct node {
long long data[N][N];
node operator*(node b) {
node t;
for (long long i = 0; i <= m; i++) {
for (long long j = 0; j <= m; j++) {
t.data[i][j] = 0;
}
}
... | ### Prompt
Please create a solution in cpp to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the n... |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
long long qpow(long long n, long long k) {
long long res = 1;
while (k) {
if (k & 1) res = res * n % mod;
n = n * n % mod;
k >>= 1;
}
return res;
}
struct matrix {
long long a... | ### Prompt
Create a solution in cpp for the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number ... |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
struct mint {
int n;
mint(int n_ = 0) : n(n_ % MOD) {
if (n < 0) n += MOD;
}
};
mint operator+(mint a, mint b) { return (a.n += b.n) >= MOD ? a.n - MOD : a.n; }
mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + MOD : a.... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1,... |
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
const int mo = 1e9 + 7;
int n, k, a[N], num[3], nn, f = 0;
long long ans, now[N][N], dp[N][N], aa[N];
long long po(long long a, long long b) {
if (b == 0) return 1;
if (b == 1) return a;
long long c = po(a, b / 2);
if (b & 1)
return c * c % mo... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1,... |
#include <bits/stdc++.h>
bool debug = 0;
const long long MOD = 1000000007;
const double PI = acos(-1.0);
const double eps = 1e-9;
using namespace std;
long long modmul(long long a, long long b) { return (a * b) % MOD; }
long long modsum(long long a, long long b) {
return ((a % MOD) + (b % MOD)) % MOD;
}
long long mod... | ### Prompt
In Cpp, your task is to solve the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number... |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
long long nn, MOD = 1e9 + 7;
vector<vector<long long> > matMul(vector<vector<long long> > &a,
vector<vector<long long> > &b) {
vector<vector<long long> > c(nn, vector<... | ### Prompt
Construct a Cpp code solution to the problem outlined:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the numb... |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
long long mod(long long n) {
if (n < 0) {
return (n % MOD + MOD) % MOD;
} else {
if (n < MOD)
return n;
else if (n < 2 * MOD)
return n - MOD;
else
return n % MOD;
}
}
long long fp(long lon... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1,... |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
const int MOD = 1e9 + 7;
struct Mat {
long long a[MAXN][MAXN];
int n;
Mat(int n) : n(n) { memset(a, 0, sizeof(a)); }
};
Mat operator*(Mat a, Mat b) {
Mat c(a.n);
for (int i = 0; i <= a.n; i++) {
for (int j = 0; j <= a.n; j++) {
for ... | ### Prompt
Develop a solution in cpp to the problem described below:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the n... |
#include <bits/stdc++.h>
using namespace std;
void guan() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
const int maxn = 123456;
const int mod = 1e9 + 7;
int a[maxn];
int dp[110][110][110];
class Matrix {
public:
long long m[105][105];
Matrix() {
memset(m, 0, sizeof(m));
;
}
Matrix(in... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1,... |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const double eps = (double)1e-8;
const int maxn = (int)2e5 + 20;
int n, m;
int a[105];
struct mat {
int n;
int a[105][105];
mat operator*(const mat &t) const {
mat res;
res.n = n;
for (int i = 0; i <= n; i++)
for (int j ... | ### Prompt
Construct a cpp code solution to the problem outlined:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the numb... |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 110;
struct MAT {
long long a[MAXN][MAXN];
MAT() {
for (int i = 0; i < MAXN; i++)
fo... | ### Prompt
Create a solution in Cpp for the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number ... |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int str[101];
int dp[101][101][101];
long long num[51][51];
int n, m;
int b, w;
namespace MI {
void A(long long &a, long long b) {
a += b;
if (a >= mod) a -= mod;
}
long long qmul(long long a, long long b) {
long long res = 0;
while (b) {
... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1,... |
#include <bits/stdc++.h>
using namespace std;
const int N = 200;
const int mod = 1e9 + 7;
int inf = 1000000000;
unsigned long long g[N][N], res[N][N];
unsigned long long dp[N];
int a[N];
int n;
unsigned long long k;
void mul(unsigned long long a[N][N], unsigned long long b[N][N],
unsigned long long c[N][N]) {
... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1,... |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
int v = 0, f = 1;
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-')
f = -1;
else
v = (c & 15);
while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
x = v * f;
}
inline void read(lo... | ### Prompt
Please formulate a Cpp solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the n... |
#include <bits/stdc++.h>
using namespace std;
const int iinf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const int N = 100;
const int mod = 1e9 + 7;
int n, k, a[N], zn, cn, izn;
int Pow(int a, int first) {
int res = 1;
for (; first; a = 1ll * a * a % mod, first >>= 1)
if (first & 1) res = 1ll * res... | ### Prompt
Please formulate a CPP solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the n... |
#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimization("unroll-loops")
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<strin... | ### Prompt
Generate a Cpp solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k.... |
#include <bits/stdc++.h>
const int M = 105;
const int MOD = 1e9 + 7;
long long read() {
long long x = 0, f = 1;
char c;
while ((c = getchar()) < '0' || c > '9') {
if (c == '-') f = -1;
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x * f;
}
long lo... | ### Prompt
Construct a cpp code solution to the problem outlined:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the numb... |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
long long mod(long long n) {
if (n < 0) {
return (n % MOD + MOD) % MOD;
} else {
if (n < MOD)
return n;
else if (n < (MOD << 1))
return n - MOD;
else
return n % MOD;
}
}
long long fp(long ... | ### Prompt
Construct a cpp code solution to the problem outlined:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the numb... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 5;
const int MOD = 1e9 + 7;
int a[maxn];
long long dp[maxn];
struct mat {
long long a[maxn][maxn];
int l, r;
void init(int _l, int _r) {
memset(a, 0, sizeof(a));
l = _l;
r = _r;
}
};
mat operator*(mat X, mat Y) {
mat Z;
Z.l = X... | ### Prompt
Create a solution in CPP for the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number ... |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int mod = 1e9 + 7;
int n, k, m, sta, a[N];
int fastpow(int x, int y) {
int res = 1;
while (y) {
if (y & 1) res = 1ll * res * x % mod;
x = 1ll * x * x % mod;
y >>= 1;
}
return res;
}
struct mat {
int a[N][N];
mat() { memset(a,... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1,... |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
long long mod(long long n) {
if (n < 0) {
return (n % MOD + MOD) % MOD;
} else {
if (n < MOD)
return n;
else if (n < 2 * MOD)
return n - MOD;
else
return n % MOD;
}
}
long long fp(long lon... | ### Prompt
Your task is to create a cpp solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and... |
#include <bits/stdc++.h>
using namespace std;
const int N = 105, LOGK = 31;
const long long MOD = 1e9 + 7;
long long n, k, tab[N], l, dp[LOGK][N][N], pocz, ost[N][N], ost2[N][N];
long long pot(long long a, long long p) {
if (p == 0) return 1;
long long w = pot(a, p / 2);
w = w * w % MOD;
if (p % 2) w = w * a % ... | ### Prompt
Please formulate a Cpp solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the n... |
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
int solve(vector<int>& nums, int k) {
int n = nums.size();
if (n < 2) {
return 0;
}
long long P = 0, Q = 0;
long long p = invM(n * (n - 1) / 2);
int zeros = 0, ones = 0;
for (int i = 0; i < n; ++i) {
if (nu... | ### Prompt
Construct a cpp code solution to the problem outlined:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the numb... |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long add(long long a, long long b) { return (a + b) % mod; }
long long mul(long long a, long long b) { return a * b % mod; }
long long qpow(long long a, long long b = mod - 2) {
long long ret = 1;
while (b) {
if (b & 1) ret = mul(ret, a... | ### Prompt
Develop a solution in Cpp to the problem described below:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the n... |
#include <bits/stdc++.h>
using namespace std;
const int md = (int)(1e9 + 7);
const int N = 110;
int a[N], sz;
struct mat {
int a[N][N];
void init() {
memset(a, 0, sizeof(a));
for (int i = 0; i < sz; i++) {
a[i][i] = 1;
}
}
void print() {
for (int i = 0; i < sz; i++) {
for (int j = 0;... | ### Prompt
In cpp, your task is to solve the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number... |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long MOD = 1e9 + 7, N = 100;
unsigned long long k, n, c, cnt;
int a[110];
struct node {
unsigned long long f[110][110];
} t, tt, res;
void matrix(node &t) {
memset(t.f, 0, sizeof t.f);
for (unsigned long long i = 0; i <= N; ++i) t.f[i][i] = 1;
}
vo... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1,... |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
struct Matrix {
vector<vector<ll>> v;
int n, m;
Matrix(vector<vector<ll>>& t) {
n = t.size();
m = t[0].size();
v = t;
}
Matrix(int p, int q) {
v = vector<vector<ll>>(p, vector<ll>(q, 0));
n = p, ... | ### Prompt
Generate a CPP solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k.... |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int a[105], n, K, sn;
struct Mat {
int a[105][105];
Mat() { memset(a, 0, sizeof(a)); }
Mat operator*(const Mat &b) const {
Mat c = Mat();
for (int i = 0; i <= sn; i++)
for (int j = 0; j <= sn; j++)
for (int k = 0; k <=... | ### Prompt
Your task is to create a cpp solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and... |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
cout << x << endl;
exit(0);
}
using ll = long long;
const ll mod = 1e9 + 7;
const int maxn = 110;
using matrix = vector<vector<ll>>;
void add(ll& x, ll y) {
if (x >= mod) x %= mod;
if (y >= mod) y %= mod;
x += y;
if (x >= mo... | ### Prompt
Construct a Cpp code solution to the problem outlined:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the numb... |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 10;
const long long mod = 1e9 + 7;
long long qpow(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
struct Matrix {
static const int N = 110;
long ... | ### Prompt
Your task is to create a CPP solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and... |
#include <bits/stdc++.h>
const int N = 210, MO = 1e9 + 7;
int n, K, A[N], fac[N], inv[N], invn[N], a[N][N], ans[N][N], c[N][N], lm;
inline void Add(int &a, const int &b) {
a += b;
if (a >= MO)
a -= MO;
else if (a < 0)
a += MO;
return;
}
inline int qpow(int a, int b) {
int ans = 1;
while (b) {
if... | ### Prompt
Develop a solution in CPP to the problem described below:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the n... |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, M = 1e9 + 7;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1), EPS = 1e-9;
const int N = 101;
long long b[N];
long long o;
int n, k;
long long fm(long long a, long long b) {
return (-b < a and a < b) ? a : a % b;
}
template... | ### Prompt
Please provide a cpp coded solution to the problem described below:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1,... |
#include <bits/stdc++.h>
namespace IO {
int double_len(6);
bool spacebar_can_see(1);
template <typename T>
class Number {
public:
unsigned int len;
int hex;
T number;
inline Number(T number = 0, int hex = 10, int len = 0)
: number(number), hex(hex), len(len) {}
inline operator T() { return number; }
};... | ### Prompt
Your task is to create a CPP solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and... |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int mul(long long a, int b) { return (a * b) % MOD; }
int sub(int a, int b) {
int c = a - b;
if (c < 0) {
return c + MOD;
}
return c;
}
int add(int a, int b) {
int c = a + b;
if (c >= MOD) {
return c - MOD;
}
return c;
}
v... | ### Prompt
In cpp, your task is to solve the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number... |
#include <bits/stdc++.h>
using namespace std;
namespace IO {
const unsigned int Buffsize = 1 << 15, Output = 1 << 24;
static char Ch[Buffsize], *S = Ch, *T = Ch;
inline char getc() {
return ((S == T) && (T = (S = Ch) + fread(Ch, 1, Buffsize, stdin), S == T)
? 0
: *S++);
}
static char Out[O... | ### Prompt
Construct a Cpp code solution to the problem outlined:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the numb... |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1e9 + 7;
const int N = 110;
struct Mat {
int a[N][N];
int r, c;
Mat(int _r, int _c) { r = _r, c = _c, memset(a, 0, sizeof(a)); }
};
Mat operator*(Mat X, Mat Y) {
Mat Z(X.r, Y... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1,... |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template <class T>
inline bool ckmin(T &a, T b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
inline bool ckmax(T &a, T b) {
... | ### Prompt
Develop a solution in CPP to the problem described below:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the n... |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &a) {
in >> a.first >> a.second;
return in;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> a) {
out << a.first << " " << a.second;
return out;
}
t... | ### Prompt
Develop a solution in Cpp to the problem described below:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the n... |
#include <bits/stdc++.h>
using namespace std;
template <int MOD_>
struct modnum {
static constexpr int MOD = MOD_;
static_assert(MOD_ > 0, "MOD must be positive");
private:
using ll = long long;
int v;
static int minv(int a, int m) {
a %= m;
assert(a);
return a == 1 ? 1 : int(m - ll(minv(m, a)) ... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1,... |
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
const int MOD = 1000000007;
inline int add(int u, int v) {
u += v;
if (u >= MOD) u -= MOD;
return u;
}
inline int sub(int u, int v) {
u -= v;
if (u < 0) u += MOD;
return u;
}
inline int mul(int u, int v) { return (long long)u * v % MOD; }
inli... | ### Prompt
Construct a Cpp code solution to the problem outlined:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the numb... |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template <class T>
inline bool ckmin(T &a, T b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
inline bool ckmax(T &a, T b) {
... | ### Prompt
Generate a Cpp solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k.... |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 2000 * 1000;
const int inf = 2000 * 1000 * 1000;
const long long infl = 1000ll * 1000ll * 1000ll * 1000ll * 1000ll * 1000ll;
const int mod = 1000 * 1000 * 1000 + 7;
const long double pi = acos(-1.0);
template <typename T1, typename T2>
ostream& operator<<(o... | ### Prompt
Generate a cpp solution to the following problem:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k.... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.