solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
int n = 0;
cin >> n;
int first;
cin >> first;
while (first % 2 == 0) first >>= 1;
while (first % 3 == 0) first /= 3;
n--;
int current;
while (n--) {
cin >> current;
while (current % 2 == 0) current ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int digit[n], fingerprint[m];
for (int i = 0; i < n; i++) cin >> digit[i];
for (int i = 0; i < m; i++) cin >> fingerprint[i];
sort(fingerprint, fingerprint + m);
for (int i = 0; i < n; i++)
if (binary_search(fingerprin... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[101], t = 0;
string s;
cin >> n >> s;
for (int i = 0; i < s.length(); i++) a[++t] = s[i] - '0';
int sum[101];
memset(sum, 0, sizeof(sum));
for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
for (int i = 1; i < n; i++) {
int an... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const long long mod = 1e9 + 7;
const long long mod1 = 123456789;
const int base = 61;
long long t, n, m, T, k, ans, a[N], tong, b[N], x, y;
string s, str;
bool check;
vector<long long> adj[N], adt[N];
vector<long long> kq;
priority_queue<pair<lo... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
scanf("%d", &k);
int sum = k + 2000;
printf("2000\n%d ", -1);
for (int i = 2; i <= 2000; i++) {
int cur = min((int)1e6, sum);
sum -= cur;
printf("%d ", cur);
}
puts("");
return 0;
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
T = 1;
cin >> T;
while (T--) {
long long i, j, k, m, n, l, res = 0, ans = 0;
cin >> n >> m >> k;
k -= 2;
if (m < n - 1) {
cout << "NO" << '\n';
} else if (... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int md = 1000000007;
inline void add(int &a, int b) {
a += b;
if (a >= md) {
a -= md;
}
}
inline int mul(int a, int b) { return (long long)a * b % md; }
inline int power(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1) {
res = mul(res, a... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
map<string, string> mp;
for (int i = 0; i < n; i++) {
string x, y;
cin >> x >> y;
mp[y] = x;
}
for (int i = 0; i < m; i++) {
string x, y, z;
ci... | 1 |
#include <bits/stdc++.h>
using namespace std;
char s[1010], t[1010];
bool ok(char a) {
return (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u');
}
int main() {
scanf("%s%s", s, t);
int n = strlen(s), m = strlen(t);
if (n != m) {
printf("No\n");
return 0;
}
bool f = 1;
for (int i = 0; i < ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
int n, m, q, ans;
vector<int> nei[maxn];
bool mark[maxn];
void dfs(int v) {
mark[v] = true;
for (auto u : nei[v])
if (!mark[u]) dfs(u);
}
void dfs_all() {
for (int i = 0; i < m + n; i++) {
if (!mark[i]) dfs(i), ans++;
}
}
int main(... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long power(long long a, long long b) {
long long res = 1;
for (; b; b >>= 1, a = a * a % mod)
if (b & 1) res = res * a % mod;
return res;
}
long long n, k, ans;
char a[100010];
signed main() {
scanf("%s%d", a + 1, &k);
n = s... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
std::ostream &operator<<(std::ostream &out, vector<T> &v) {
for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
out << v[i] << " ";
out << "\n";
return out;
}
template <typename T>
std::ostream &operator<<(std::ostream &out, set<T> &... | 7 |
#include <bits/stdc++.h>
using namespace std;
void INP();
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
if (0) return;
cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
if (0) return;
const char* co... | 6 |
#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);
}
struct poing {
int x;
int y;
int comp(poing a) {
if (x == a.x) {
if (y == a.y) {
return -1;
}
return x;
}
if (x == a.y) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct mhash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
uint64_t operator()(uint64_t x) const {
static const uint64... | 13 |
#include <bits/stdc++.h>
using namespace std;
void printv(vector<vector<long long>> a) {
for (auto lel : a) {
for (auto lel2 : lel) {
cout << lel2 << " ";
}
cout << "\n";
}
cout << "\n";
}
long long dnc(int base, int power) {
if (power == 0) return 1;
if (power % 2 == 0) {
long long res ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m, cnt;
int head[N], rest[N], to[N], flow[N], tot = 1, S, T;
int dis[N];
bool fwd[N];
void add_sig(int u, int v, int w) {
to[++tot] = v, flow[tot] = w, rest[tot] = head[u], head[u] = tot;
}
void add(int u, int v, int w) {
add_sig(u, v, w);... | 17 |
#include <bits/stdc++.h>
inline int read() {
char c;
int x;
for (c = getchar(); !isdigit(c); c = getchar())
;
for (x = 0; isdigit(c); c = getchar()) {
x = x * 10 + c - '0';
}
return x;
}
const int N = 1e3 + 5;
int n, m, deg[N];
bool flag, vis[N], used[N];
std::bitset<N> tmp, to, self, leaf, e[N], bi... | 24 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15;
int n, k;
string s, t;
int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k >> s >> t;
long long ans = 0;
int h = 0;
int flag = 0;
for (int i = 0; i < n; ++i) {
h = min(k, h * 2 + t[i] - s[i]);... | 12 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
static char ch;
bool sgn = false;
while (ch = getchar(), ch < '0' || ch > '9')
if (ch == '-') sgn = true;
int res = ch - 48;
while (ch = getchar(), ch >= '0' && ch <= '9') res = res * 10 + ch - 48;
return sgn ? -res : res;
}
const int N =... | 22 |
#include <bits/stdc++.h>
using namespace std;
int getsum(int bit[], int i) {
int sum = 0;
while (i > 0) {
sum = max(sum, bit[i]);
i = i - (i & -i);
}
return sum;
}
void update(int bit[], int n, int i, int val) {
while (i <= n) {
bit[i] = max(bit[i], val);
i = i + (i & -i);
}
}
int main() {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e3 + 7;
long long n;
char a[N];
long long k;
long long x;
long long mim[N];
long long ban[N];
long long s[N];
long long xx = 0;
long long gon;
void solve() {
long long cnt = 0;
string res = "";
cin >> n >> k >> x;
long long dak = 1;
xx++;
fo... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<pair<int, int> > arr(m);
vector<vector<int> > G(n);
vector<int> in(n), vis(n);
for (auto& it : arr) {
int u, v;
cin >> u >> v;
in[--u]++;
in[--v]++;
it = {u, v};
G[u].push_back(v);
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[200010], ans[200010];
int n, m, k;
int vis[200010], minn[200010], maxx[200010], dx[200010], dn[200010];
vector<int> g0[200010], g1[200010], t[200010];
int read() {
int ans = 0;
char ch = getchar();
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' ... | 18 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> segm[1 << 18];
long long segs[1 << 18];
int seg_n;
pair<int, int> maxP(pair<int, int> a, pair<int, int> b) {
return a.first > b.first ? a : b;
}
void init(int n) {
seg_n = 1;
while (seg_n < n) seg_n *= 2;
for (int i = 0; i < seg_n * 2 - 1; i++) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long rand(long long x, long long y) {
return (rng() % (y + 1 - x)) + x;
}
string inline to_string(char c) {
string second(1, c);
return second;
}
template <typename T>
inline T gcd(T a, T... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, kg, money;
while (cin >> n) {
int minn = 101, sum = 0;
for (int i = 0; i < n; i++) {
cin >> kg >> money;
if (minn > money) minn = money;
sum = sum + kg * minn;
}
cout << sum << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, c = 0, f = 0;
cin >> n >> m;
int a[n][2 * m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2 * m; j++) {
cin >> a[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2 * m; j += 2) {
if ((a[i][j] == 1 ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e9 + 7;
template <class X, class Y>
void minimize(X &x, const Y &y) {
if (x > y) x = y;
}
template <class X, class Y>
void maximize(X &x, const Y &y) {
if (x < y) x = y;
}
bool CompFi(const pair<long long, long long> &a,
con... | 20 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long Hashimoto = 0;
bool Kanna = 1;
char I_Love = getchar();
while (I_Love < '0' || I_Love > '9') {
if (I_Love == '-') Kanna = 0;
I_Love = getchar();
}
while (I_Love >= '0' && I_Love <= '9') {
Hashimoto = Hashimoto * 10... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
map<string, int> mp;
vector<string> v, u;
vector<pair<int, int> > clash;
bool isValid(int mask) {
for (int i = 0; i < m; i++) {
if ((mask & (1 << clash[i].first)) && (mask & (1 << clash[i].second))) {
return false;
}
}
return true;
}
int bitCou... | 7 |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<int, int> pi;
int n;
const int maxn = 105;
int c[maxn], b[maxn];
ll dp[maxn][maxn * maxn];
const int mod = 1e9 + 7;
void add(ll &a, l... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 40;
const long long C = 1 << (N / 2);
long long n, m;
int u, v;
int x[N], y[N / 2];
long long DP[C];
bool flag;
int cur;
long long tot;
long long s, t;
int color[N];
bool isBipartite;
long long totcomp, single;
vector<int> conn[N];
long long ans;
void df... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
char s[maxn];
int A[maxn], B[maxn];
int main() {
scanf("%s", s + 1);
int len = strlen(s + 1);
for (int i = 1; i <= len; i++) {
A[i] = A[i - 1] + (s[i] == 'a');
B[i] = B[i - 1] + (s[i] == 'b');
}
int ans = max(A[len], B[len]);
for (... | 7 |
#include <bits/stdc++.h>
using namespace std;
int mat[5][5];
int main() {
int c = 0, r = 0;
for (int i = 0; i < 5; i++)
for (int j = 0; j < 5; j++) {
cin >> mat[i][j];
if (mat[i][j]) {
c = j;
r = i;
}
}
int ans = abs(2 - c) + abs(2 - r);
cout << ans;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, a, b, c;
const int MAXN = 200;
struct E {
int dest;
int cost;
};
vector<E> edge[MAXN];
int ar[MAXN][MAXN];
int was[MAXN];
E t;
vector<int> order;
void dfs(int v) {
was[v] = true;
order.push_back(v);
for (int i = 0; i < edge[v].size(); ++i) {
if (!... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
int a = s.length(), b = 0;
for (int i = 0; i < a; i++) {
if (s[i] == t[a - i - 1]) {
b++;
}
}
if (b == a) {
cout << "YES";
} else {
cout << "NO";
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> a;
int type, iden1, iden2;
int count = 0;
a.push_back(n);
count++;
for (int i = 0; i < k; i++) {
cin >> type;
if (type == 2) {
cin >> iden1;
a.push_back(iden1);
count++;
} else {... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, z, i, j, e, max, min, d, m, r, l, x, s = 0, p, n, h, y, g, k;
cin >> n;
cout << n / 2520;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 50020;
const int maxK = 10;
unsigned int n, srt;
unsigned int A, B, C, D;
unsigned int pcnt, notp[maxN + maxN], Pri[maxN + maxN];
unsigned int num, Num[maxN], Id[maxN + maxN];
unsigned int F[4][maxN], Stl[maxK][maxK], Sm[4][maxN];
void Init();
unsigned int ... | 17 |
#include <bits/stdc++.h>
using namespace std;
namespace IO {
template <typename T>
void __RI(T &x) {
int ch = getchar(), neg = 1;
x = 0;
for (; !(isdigit(ch) || ch == '-' || ch == EOF); ch = getchar())
;
if (ch == EOF) return;
if (ch == '-') neg = -1, ch = getchar();
for (; isdigit(ch); ch = getchar()) ... | 16 |
#include <bits/stdc++.h>
using namespace std;
string read(int cur) {
cout << cur << endl;
string s;
cin >> s;
return s;
}
int ANSWER, ITERS;
string read_check(int cur) {
--ITERS;
if (ITERS < 0) {
cout << "TOO MANY ITERS" << endl;
}
if (ANSWER % cur == 0) {
return "yes";
}
return "no";
}
stri... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long ar[200][200];
long long n, k, q, i, ans, a, b, j, m, cat;
struct meow {
long long x;
long long y;
bool z;
};
void printt() {
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
cout << ar[i][j] << " ";
}
cout << endl;
}
}
bool kucing(... | 9 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926536;
template <typename T>
void print(T t) {
for (auto &it : t) cout << it << " ";
cout << endl;
}
double find_sqr(long long x) { return x * x; }
using mii = map<long long, long long>;
using pii = pair<long long, long long>;
void solve() {
l... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long l, r, k;
cin >> l >> r >> k;
int ok = 0;
long long x = 1ll;
while (x <= r) {
if (x >= l) {
ok++;
cout << x << ' ';
}
if (r / k < x)
break;
else
x = x * k;
}
if (ok == 0) cout << "-1";
return 0;
}... | 7 |
#include <bits/stdc++.h>
const int INF = std::numeric_limits<int>::max() / 2;
const long long INFLL = std::numeric_limits<long long>::max() / 2;
int n;
std::vector<int> vec;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
vec.push_back(1);
vec.push_back(INF);... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 10;
int a[MAXN][MAXN];
long long po[MAXN];
long long p;
int main() {
int n, m;
cin >> n >> m;
int t;
cin >> t;
for (int i = 1; i <= t; i++) {
int x, y, z;
cin >> x >> y >> z;
if (n >= m)
a[x][y] = z;
else
a[y][x]... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
template <class T>
bool minimize(T& x, const T& y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <class T>
bool maximize(T& x, const T& y) {
if (x < y) {
x = y;
return true;
}
r... | 13 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
const int N = 3e5+5;
int n , a[N];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t;
cin >> t;
while(t--)
{
map<int,int> mp[2];
c... | 7 |
#include <bits/stdc++.h>
using namespace std;
int vis[1050][1050] = {0};
char maps[1050][1050];
int r[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
void dfs(int x, int y, int n, int m) {
if (x < 0 || x >= n || y < 0 || y >= m || maps[x][y] == '.') return;
if (vis[x][y] == 1) return;
vis[x][y] = 1;
for (int i = 0; i < 4; ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int MAXN = 1e7 + 6;
const int MOD = 1e9 + 7;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n, x[105], y[105];
bool vis[1005][1005], ex[1005][1005];
void dfs(int a, int b) {
vis[a][b] = 1;
for (int i = 0; i < int(1005); i++) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int g1[65], g2[65];
map<int, pair<long long, long long> > destroy;
vector<pair<long long, long long> > conf;
int rez;
inline int nrb(long long x) {
int rez = 0;
while (x) {
x &= (x - 1);
rez++;
}
return rez;
}
int main() {
cin >> n >> m;
for (i... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e4 + 1000;
const int sq = 256;
int a[maxn], cnt, h[maxn], par[maxn], parsq[maxn], nxt[maxn * 10][2],
num[maxn * 10], gett[maxn][sq], ans[maxn][sq];
vector<int> g[maxn];
inline void dfs(int v, int pp = 0) {
h[v] = h[pp] + 1;
par[v] = pp;
for (auto... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, l, r, x;
cin >> n >> m;
set<int> st;
for (int i = 1; i <= n; ++i) st.insert(i);
vector<int> ans(n + 1);
while (m--) {
cin >> l >> r >> x;
auto it1 = st.lower_bound(l), it2 = st.upp... | 7 |
#include <bits/stdc++.h>
int main() {
int N;
std::cin >> N;
const auto needed = (N + 1) / 2;
std::unordered_set<int> colors(2 * N);
std::unordered_map<int, int> count_front(2 * N);
std::unordered_map<int, int> count_both(2 * N);
for (int i = 0; i < N; i++) {
int front, back;
std::cin >> front >> b... | 7 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using comx = complex<double>;
void dout() { cerr << endl; }
template <typename Head, typename... Tail>
void dout(Head H... | 3 |
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::string;
int main() {
int n[3] = {0, 0, 0};
string s;
int last = -1;
int pla = -1;
for (int i = 0; i < 3; i++) {
cin >> s;
int cur;
if (s == "rock")
cur = 0;
else if (s == "paper")
cur = 1;
else
cur = 2;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int arr[N];
int bigger[N][N], smaller[N][N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
for (int val = 0; val < n; val++) {
for (int i = 0; i < n; i++) {
bigger[val][i] = (arr[i] > val) + (i ? bigger[val][i... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long p[300000], l[300000];
long long cookies[300000];
pair<long long, pair<long long, long long> > tx[300000];
long long T;
vector<long long> c[300000];
set<pair<long long, pair<long long, long long> > > txs;
pair<long long, pair<long long, long long> > r =
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, first;
cin >> n >> first;
int a[n + 1];
for (int i = (0); i < (int)(n); i++) cin >> a[i];
int ans = 0;
if (count(a, a + n, first) == 0) a[n++] = first, ans++;
sort(a, a + n);
int j = 0;
int opt = 100000;
for (int j = (0); j < (int)(n)... | 7 |
#include <bits/stdc++.h>
using namespace std;
int dx[8] = {0, 0, 1, 1, -1, -1, 1, -1};
int dy[8] = {1, -1, 1, -1, 1, -1, 0, 0};
long long a[3000006];
vector<long long> v;
int main() {
long long n;
scanf("%lld", &n);
a[n] = 1;
for (int i = 2; i <= n; i++) {
a[n] *= i;
}
a[n / 2] = 1;
for (int i = 2; i ... | 5 |
#include <bits/stdc++.h>
const int mod = 998244353, N = 505, M = 6e5 + 5, INF = 0x3f3f3f3f;
const double eps = 1e-9, alpha = 0.7;
template <typename T>
inline T read() {
T x = 0;
bool f = 0;
char ch = getchar();
while (!isdigit(ch)) {
f = ch == '-';
ch = getchar();
}
while (isdigit(ch)) {
x = x ... | 22 |
#include <bits/stdc++.h>
using namespace std;
int rt(int* par, int u) { return par[u] == u ? u : par[u] = rt(par, par[u]); }
void unite(int* par, int* cnt, int a, int b) {
a = rt(par, a);
b = rt(par, b);
if (a == b) return;
par[b] = a;
cnt[a] += cnt[b];
}
int main() {
ios::sync_with_stdio(false), cin.tie(0)... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int v[n], s[n];
for (int i = 0; i < n; i++) {
cin >> v[i];
}
sort(v, v + n);
for (int i = 0; i < n; i++) {
s[i] = 1;
}
int j = 0;
for (int i = 0; i < n - 1; i++) {
if (v[i] == v[i + 1]) {
s[j] = s[j... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n;
string s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
;
cin >> n >> s;
for (int i = 0; i < n; i++) {
if (n % (i + 1) == 0) {
reverse(s.begin(), s.begin() + i + 1);
}
}
cout << s;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, l, r;
scanf("%d %d", &n, &x);
int conta = 0;
int pos = 1;
for (int i = 0; i < n; i++) {
scanf("%d %d", &l, &r);
conta += (l - pos) % x + r - l + 1;
pos = r + 1;
}
printf("%d", conta);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
map<int, int> b, s;
void print(map<int, int>::iterator it, int x) {
if (x >= k || it == s.end()) return;
map<int, int>::iterator a = it;
print(++it, x + 1);
printf("S %d %d\n", a->first, a->second);
}
int main() {
scanf("%d %d", &n, &k);
for (int i = 0... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int m = 0;
long long int b = 0;
long long int t = 0;
int main(int argc, char** argv) {
string s;
cin >> s;
long long int x = s.find('^');
for (int i = 0; i < s.size(); i++) {
if (0 < s[i] - '0' and s[i] - '0' < 10) {
t = (s[i] - '0') * (i - x);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long POW(long long a, long long b, long long MMM = MOD) {
long long ret = 1;
for (; b; b >>= 1, a = (a * a) % MMM)
if (b & 1) ret = (ret * a) % MMM;
return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int row[1010];
int col[1010];
int arr[1010][1010];
int main() {
ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < 1010; i++) {
row[i] = col[i] = i;
}
for (int i = 1; i <= n; i++) {
for (int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int a[maxn];
multimap<int, pair<int, int> > mp;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int ans = 0;
for (int i = 1; i < n; i++) {
for (int j = n; j > i; j--) {
if (a[i] > a[j]) {
m... | 17 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-10;
int in() {
int r = 0, c;
for (c = getchar(); c <= 32; c = getchar())
;
if (c == '-') return -in();
for (; c > 32; r = (r << 1) + (r << 3) + c - '0', c = getchar())
;
return r;
}
int mat1[2100][2100];
... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long work(long long a, long long b, long long c) {
long long ans = 0;
long long p = min(a, b);
c += p;
ans += p;
a -= p;
b -= p;
if (b == 0) b = a;
if (b & 1) return -1;
if (c == 0) return -1;
ans += b;
return ans;
}
int main() {
long long a[3];... | 13 |
#include <bits/stdc++.h>
using namespace std;
stringstream sstr, sstr1, sstrr[100001];
string str, str1, strr[100001];
char c[100001], c1;
long long n, i, j, k, l, a[1000001], b[1000001], ans, ans1, o, p, mn = 1e9,
mx = -1e9;
int main() {
ios_base::syn... | 4 |
#include <bits/stdc++.h>
using namespace std;
string getNewName(string s) {
int len = s.length();
if (s[len - 1] != 'z' and s[len - 1] != 'Z') {
s[len - 1]++;
return s;
} else {
s += "a";
}
return s;
}
int main() {
int n, k;
cin >> n >> k;
int len = n - k + 1;
string s[n];
for (int i = 0... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m, sum = 0, x, y = 0;
cin >> n >> m;
for (int i = 0; i < n; i++) {
sum = 0;
if (y == 0) y = m;
cin >> x;
if (y <= x) {
sum = 1 + (x - y) / m;
if (x - y < m)
y = m - (x - y);
else
y = m - (... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1.0);
void init() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
void infile() { freopen("input.in", "r", stdin); }
void outfile() { freopen("output.out", "w", stdout); }
long long int modex(long long int a, long long... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, c;
cin >> a >> b >> c;
if (a > b) swap(a, b);
if (a > c) swap(a, c);
if (b > c) swap(b, c);
if (a + b == c || a == b && c % 2 == 0 || b == c && a % 2 == 0)
cout << "YES\n";
else
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 113;
const long long INF = 2e18 + 113;
int c, v, mx, add, l;
int ans = 1;
int main() {
cin >> c >> v >> mx >> add >> l;
c = max(0, c - v);
v = min(mx, v + add);
while (c) {
c += l;
++ans;
c = max(0, c - v);
v = min(mx, v + add);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, k, t, s[40000000], m[25], f[25], kk, mark[30];
struct pp {
int h, w, r;
} a[105];
void ff(int x) {
if (x > k) {
int sum = 0;
for (int i = 1; i <= k; i++) {
sum += (a[i].r * mark[i]);
}
s[++kk] = sum;
return;
}
if (m[a[x].h] && f[a[x]... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
iostream::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, W, B, first;
cin >> n >> W >> B >> first;
vector<long long> cost(n + 1);
vector<long long> c(n + 1);
for (long long i = (1); i < (n + 1); ++i) cin >> c[i];
for (long... | 14 |
#include <bits/stdc++.h>
using namespace std;
int Pow(int a, int b, int md, int res = 1) {
for (; b; b >>= 1, a = 1ll * a * a % md) {
if (b & 1) res = 1ll * res * a % md;
}
return res;
}
const int N = 110, MOD = 1e9 + 7;
long long int C[N][N], second[N], dp[N][N][N], dp2[N][N], dp3[N], n;
vector<int> adj[N];
... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& stream, const vector<T> v) {
stream << "[ ";
for (int i = 0; i < (int)v.size(); i++) stream << v[i] << " ";
stream << "]";
return stream;
}
long long fpow(long long x, long long p, long long m) {
long long r = 1;
f... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, char> > s, t, tmp;
vector<long long> p;
long long n, m, k, x, ans, ctr;
char lst, a;
int main() {
cin >> n >> m;
for (long i = 0; i < n; i++) {
cin >> x >> a >> a;
if (!i) {
lst = a;
k = x;
continue;
}
if (lst != ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[] = {1, 3, 15, 133, 2025, 37851, 1030367, 36362925};
int n;
cin >> n;
long long ans;
if (n % 2 == 0)
cout << 0;
else {
ans = a[n / 2];
for (int i = 1; i <= n; i++) {
ans *= i;
ans = ans % 1000000007;
}
cout << a... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
const long long N = 1e5 + 10;
const long long INF = 1e18;
const long long LOG = 25;
long long dp[25][(1 << 20) + 10];
long long n, m, NUM[N], a[22][N];
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
string s;
... | 18 |
#include<bits/stdc++.h>
#define debug printf("\n I am here\n");
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
const int maxn=2e3+5,inf=0x3f3f3f3f,mod=1e9+7;
const ll INF=0x3f3f3f3f3f3f3f3f;
using namespace std;
int n,t;
int k;
map<pair<int,int>,int> mp;
int cal(int l,int r){
// p... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[3];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < int(3); i++) cin >> a[i];
sort(a, a + 3);
multiset<int> ms;
int x;
for (int i = 0; i < int(n); i++) {
cin >> x;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end() {}
namespace Simplex {
const int N = 505, M = 2550... | 18 |
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
const int N = 3000, MOD = 998244353;
int t, n, a[N];
vector<int> ans;
void doOp(int i) {
ans.push_back(i);
reverse(a + 1, a + 1 + i);
}
char oky() {
char ans = 1;
for (int i = 1; i <= n; ++i) {
ans &= i == a[... | 12 |
#include <bits/stdc++.h>
using namespace std;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, long long> > g[100001];
long long apl[100001];
long long di[100001];
void dfs1(int x, int p) {
for (auto nx : g[x]) {
if (nx.first != p) {
dfs1(nx.first, x);
apl[x] = max(apl[x], apl[nx.first] + nx.second);
}
}
}
vector<pair<long lon... | 20 |
#include <bits/stdc++.h>
const int MAXN = 150005, MAXM = 310;
using namespace std;
struct minQueue {
int l, r;
deque<pair<long long, int> > q;
minQueue() { l = 1, r = 0; }
void insert(long long val) {
while (q.size() > 0 && q.back().first <= val) q.pop_back();
q.push_back(make_pair(val, ++r));
}
voi... | 13 |
#include <bits/stdc++.h>
const int INF = 500000001;
const double EPS = 1e-9;
const double PI = acos(-1.0);
using namespace std;
int main() {
int k;
char ch[1000];
int f[100];
int t[100];
while (~scanf("%d", &k)) {
memset(f, 0, sizeof(f));
scanf("%s", ch);
int len = strlen(ch);
for (int i = 0; ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, cntA = 0, cntD = 0;
cin >> n;
string str;
cin >> str;
for (long long i = 0; i < str.size(); i++) {
if (str[i] == 'A')
cntA++;
else
cntD++;
}
if (cntA == cntD)
cout << "Friendship";
else if (cntA > cntD)
c... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int nm = 102;
int n;
char s[nm];
int main() {
scanf("%d%s", &n, s);
for (int i = 0; i + 4 < n; ++i) {
for (int j = 1; i + 4 * j < n; ++j)
if (s[i] == '*' && s[i + j] == '*' && s[i + 2 * j] == '*' &&
s[i + 3 * j] == '*' && s[i + 4 * j] == '*') {... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int P = 1000000007;
int main() {
int a, b;
scanf("%d%d", &a, &b);
int s = 0;
int s1 = 0;
for (int i = 1; i <= b - 1; i++) s1 = (s1 + i) % P;
for (int k = 1; k <= a; k++) {
int t = (k * 1ll * b + 1) % P;
t = (t * 1ll * s1) % P;
s = (s + t) % P;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int N, Matrix[2005][2005];
char S[2005];
int Ord[2005], Grades[2005], Aux[2005], Fact[] = {1, 1, 2, 6, 24, 120, 720};
bool Flip[2005];
void Read() {
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
scanf("%s", S + 1);
for (int j = 1; S[j] != 0; j++) {
Matri... | 24 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long modPow(long long x, long long y) {
long long res = 1;
x = x % mod;
while (y > 0) {
if (y % 2 == 1) {
res = (res * x) % mod;
}
y = y / 2;
x = (x * x) % mod;
}
return res;
}
int mobius(long long n) {
... | 15 |
#include <bits/stdc++.h>
const int N = 155, oo = 51123987;
int f[55][55][55][N], w[5], next[N][5], n, m, z, ans;
char s[N];
void updata(int &x, int y) {
x += y;
if (x >= oo) x -= oo;
}
inline int abs(int a) { return a > 0 ? a : -a; }
int main() {
scanf("%d", &n);
scanf("%s", s + 1);
m = n / 3 + 1;
w[0] = w[... | 17 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.