solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 2e18 + 99;
;
void FAST_IO();
int main() {
long long int n, h, m;
scanf("%lld%lld%lld", &n, &h, &m);
vector<long long int> spot(n + 1, h);
long long int total = 0;
for (int i = 0; i < m; i++) {
long long int l, r, x;
scanf("%lld%ll... | 1 |
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int g[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
if (g[a] == g[b]) cout << "Yes";
else cout << "No";
return 0;
} | 0 |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <cassert>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#def... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long v[10000][2], k;
int main() {
long long a, b, x, y;
cin >> x >> y >> a >> b;
for (long long i = a; i <= x; i++) {
for (long long j = b; j <= y; j++) {
if (i > j) {
v[k][0] = i;
v[k][1] = j;
k++;
}
}
}
cout << k ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
scanf("%d", &T);
while (T--) {
unsigned long long n, x;
scanf("%lld", &n), scanf("%lld", &x);
vector<unsigned long long> dat(n);
for (int i = 0; i < n; ++i) {
scanf("%lld", &dat[i]);
}
unsigned long long MIN = 1e10;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
vector<long long> cnt(1e5 + 1, 0);
for (long long i = 1; i < 1e5 + 1; i++) {
cnt[i] = ((3 * i * i + i) >> 1);
}
while (t--) {
long long n;
cin >> n;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int x[4];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
for (int i = 0; i < 4; i++) {
cin >> x[i];
}
sort(x, x + 4);
for (int i = 0; i < 3; i++) {
cout << x[3] - x[i];
if (i == 2)
cout << "\n";
else
c... | 1 |
#include<bits/stdc++.h>
#define mk make_pair
using namespace std;
char s[10005];
int x,y,n,f[2][20005];
vector<int>v[2];
int main()
{
scanf("%s",s+1);
scanf("%d%d",&x,&y);
n=strlen(s+1);
s[n+1]='T';
int nw=0,tmp=0,flag=0;
for(int i=1;i<=n+1;i++)
{
if(s[i]=='F')tmp++;
else
{
if(!flag)
{
x-=tmp;fla... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
int chkmax(T &a, T b) {
if (b > a) {
a = b;
return 1;
}
return 0;
}
template <class T>
int chkmin(T &a, T b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class iterator>
void output(iterator begin, iterator end, ostr... | 3 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
using namespace std;
const int MAX = 1e5+5;
int a[MAX];
int n, l, t;
int main() {
cin >> n >> l >> t;
int p = 0;
for (int i = 0; i < n; ++i) {
int x, w; cin >> x >> w;
x = x + t*(w == 1 ? 1 : -1... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main (){
int i,q,cm=0,flag=0,f;
string s;
char c;
cin>>s>>q;
for(i=0;i<q;i++){
cin>>cm;
if(cm==1){
flag++;
}
else{
cin>>f>>c;
if((flag+f)%2==1){
s.insert(s.begin(),c);
}
else{
s.insert(s.end(),c);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline long long isqrt(long long k) {
long long r = sqrt(k) + 1;
while (r * r > k) r--;
return r;
}
inline long long icbrt(long long k) {
long long r = cbrt(k) + 1;
while (r * r * r > k) r--;
return r;
}
inline long long mnz(long long& a, long long b) { return a... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 998244353;
const int maxn = 2e5 + 5;
int n, k;
int a[maxn];
int den, cnt;
ll der[maxn], ans;
ll f[maxn], inv[maxn];
ll binmod(ll a, ll b) {
if (b == 0) return 1;
ll x = binmod(a * a % mod, b >> 1);
return b & 1 ? x * a % mod : x;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int n, a, b, c, d, start, len;
long long pre1[maxn], pre2[maxn];
multiset<long long> minPre;
pair<int, int> T[maxn];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> a >> b >> c >> d >> start >> len;
int i;
pre1[0] = pr... | 4 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
bool isPrime(long long int n) {
for (long long int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
bool isPowerOfTwo(long long... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long gcdExtended(long long a, long long b, long long *x, long long *y) {
if (a == 0) {
*x = 0;
*y = 1;
return b;
}
long long x1, y1;
long long gcd = gcdExtended(b % a, a, &x1, &y1);
*x = y1 - (b / a) * x1;
*y = x1;
return gcd;
}
int main() {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int freq[10], x;
long long int P = 1000000007;
struct matrix {
long long int arr[100][100];
};
matrix mul(matrix a, matrix b) {
matrix c;
for (int i = 0; i < x; i++)
for (int j = 0; j < x; j++) {
c.arr[i][j] = 0;
for (int k = 0; k < x; k++)
c.a... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
int getbit(T s, int i) {
return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
return __builtin_popcoun... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int n, m, w[100001], c[100001];
long long f[100001], ans;
int main() {
ans = INF;
scanf("%d", &n);
for (register int i = 1; i <= n; ++i) {
scanf("%d %d", &w[i], &c[i]);
++w[i];
m = max(m, w[i]);
}
m += n;
for (register int... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int main() {
int n;
string s;
cin >> n;
cin.ignore();
getline(cin, s);
int largest = 0;
int first;
int last = -1;
for (int i = 0; i < s.size(); i++)
if (s[i] == '.' || s[i] == '?' || s[i] == '!') {
while (s[last + 1]... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, ta, b, tb, c, d;
char u;
cin >> a >> ta >> b >> tb >> c >> u >> d;
c = c * 60 + d - 300;
d = c + ta;
int ans = 0;
for (int i = 0; i < 1140; i += b) {
int s = i, e = i + tb;
if (e <= c || s >= d) {
continue;
}
ans++;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> edge[500010];
int val[500010], father[500010][20], root;
long long ans;
void dfs(int u) {
ans += 1ll * val[u] * edge[u].size();
for (auto v : edge[u]) {
if (father[u][0] == v) {
continue;
}
father[v][0] = u;
for (int i = 1; i < 20; ++i)... | 6 |
#include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) {
if (b == 0) return a;
return (a % b == 0 ? b : GCD(b, a % b));
}
long long int POW(long long int base, long long int exp) {
long long int val;
val = 1;
while (exp > 0) {
if (exp % 2 == 1) {
val = (val * base) % 1000000007;
}
... | 1 |
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <li... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long int MAX_SIZE = 1000001;
long long int power(long long int x, long long int y) {
long long int res = 1;
while (y > 0) {
if (y & 1) res = res * x;
y = y >> 1;
x = x * x;
}
return res;
}
long long int powermod(long long int x, long long int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
void f(int n) {
int ans = 0;
int i = 0;
while (n > 0) {
if (n % 10 == 7) {
ans += 2 * (1 << i);
} else {
ans += (1 << i);
}
i++;
n /= 10;
}
cout << ans << endl;
}
int main() {
int n;
cin >> n;
f(n);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N,M,x;
cin>>N>>M;
vector<int> c(N);
for(int i=0;i<M;i++){
cin>>x;
c.at(x-1)++;
cin>>x;
c.at(x-1)++;
}
for(int i=0;i<N;i++){
cout<<c.at(i)<<endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b, ans;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b;
int ans = a - (a % b);
a %= b;
ans += min((b / 2), a);
cout << ans << '\n';
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long arr[2 * (int)1e6 + 10], sum[2 * (int)1e6 + 10] = {0};
int main() {
unsigned long long a, b, n;
scanf("%I64d%I64d%I64d", &a, &b, &n);
for (int i = 1; i <= 2 * 1e6; i++)
arr[i] = a + (i - 1) * b, sum[i] = arr[i] + sum[i - 1];
while (n--) {
u... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long const delta = 1000000007;
long long dp[(long long)1e6 + 8];
int main() {
std::ios::sync_with_stdio(0);
;
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long a[n];
long long ans = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
d... | 6 |
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;
int n;
int f(int n) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) return 0;
}
return 1;
}
void code() {
cin >> n;
int nxt = n;
while (!f(n... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const int N = (int)1e6 + 7;
int n;
long long dp[N], a[N], b[N];
void Init() {
for (int i = (1); i < (n + 1); ++i) scanf("%lld", a + i);
for (int i = (1); i < (n + 1); ++... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2};
int n;
scanf("%d", &n);
printf("%d\n", a[n / 10] * a[n % 10]);
return 0;
}
| 1 |
#include <bits/stdc++.h>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
uint_fast64_t n, m;
std::cin >> n >> m;
std::vector<std::vector<uint_fast64_t>> a(n,
std::vector<uint_fast64_t>(m, 0)),
b(n, std::vector<uint_fast64_t>(m, 0));
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v[100007];
vector<pair<int, int> > ans;
void dfs(int vertex, int prv, int st) {
int sz = v[vertex].size();
int lft = sz;
if (prv > 0) {
--lft;
}
int h = st;
for (int i = 0; i < sz; ++i) {
if (v[vertex][i] == prv) {
continue;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long a[200007], K, b[200007];
int n;
long long get(int i, long long x) {
long long l = 1, r = a[i];
while (l <= r) {
long long mid = l + r >> 1;
if (a[i] - (3 * mid * mid - 3 * mid + 1) >= x)
l = mid + 1;
else
r = mid - 1;
}
return r;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const int mod = 1000000007;
const int N = 100005;
int a[55];
int main() {
int n;
long long m;
cin >> n >> m;
int cur = n - 2;
int val = 1;
int l = 1;
int r = n;
m--;
while (l < r) {
if ((1ll << cur) <= m) {
m -= (1ll <... | 2 |
#include <bits/stdc++.h>
using namespace std;
int const N = 500000;
int n, k, sz[N], R;
vector<pair<int, double> > tr[N];
map<pair<int, int>, vector<double> > mp;
vector<double> z;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void go(int v = 0, int p = -1, double d = 0.0) {
sz[v] = 0;
for (int i = 0; i <... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 100000;
int fre[123];
int a[6], b[6], c1, c2, j = 0, k = 0;
int main() {
string s;
int first = 0, second = 0;
cin >> s;
for (int i = 0; i < 6; i++) {
if (i < 3) {
first += s[i] - 48;
a[i] = s[i] - 48;
} else {
second += s[i] ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int q;
cin >> q;
for (long long int t = 0; t < q; ++t) {
long long int n;
cin >> n;
long long int a[n];
set<long long int> s;
map<long long int, long long int> m;
for (long long int i = 0; i < n; ++i) {
cin >> a[i];... | 4 |
#include <bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
const int MAXN = 200005;
int n, x, y;
char str[MAXN];
int dx[256], dy[256];
int sum1[MAXN], sum2[MAXN];
bool bad(int s, int e) {
if (s > e) return 0;
int px = x, py = y;
px += sum1[s] - sum1[e];
py += sum2[s] - sum2[e];
px = abs(px);
p... | 3 |
#include <bits/stdc++.h>
using namespace std;
char str[1000010];
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> str;
int n = strlen(str);
string s;
for (int i = 0; i < n; ++i) {
s += str[i];
if (str[i] == str[i + 1] && str[i] != 'X') s += 'X';
}
if (str[0] == str[n - 1])... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
vector<long long> a;
vector<int> pos;
for (int i = n; i > 0; i--) {
long long p;
cin >> p;
if (p == 0) continue;
a.push_back(p);
pos.push_back(i);
}
rev... | 5 |
#include <bits/stdc++.h>
using namespace std;
int v[50][50];
char c[50][50];
int r, col;
int dfs(int i, int j, int p) {
if (v[i][j] == 1) return 1;
v[i][j] = 1;
char ch = c[i][j];
int f = 0;
if (p != 4 && i < r - 1 && c[i + 1][j] == ch) f = f || dfs(i + 1, j, 1);
if (p != 1 && i > 0 && c[i - 1][j] == ch) f ... | 2 |
#include<cstdio>
const int MaxN=100010,inf=1<<25;
int N;
struct edge{int to;edge*next;}E[MaxN*2],*ne=E,*fir[MaxN];
void link(int u,int v){*ne=(edge){v,fir[u]};fir[u]=ne++;}
bool limed[MaxN];
int fa[MaxN],lim[MaxN],l[MaxN],r[MaxN];
bool dfs1(int i){
bool lm=0;
int st=0;
l[i]=-inf;r[i]=inf;
for(edge*e=fir[i];e;e=e->n... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, k, mod = 1e9 + 7, i;
cin >> n >> k;
long long a[50];
a[0] = 1;
for (i = 1; i <= 45; i++) {
a[i] = a[i - 1] * n;
a[i] %= mod;
}
vector<long long> bt;
while (k) {
bt.push_back(k % 2);
k /= 2;
}
long long ans = 0;... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
long long t;
if (a < b) swap(a, b);
while (b != 0) {
t = a % b;
a = b;
b = t;
}
return a;
}
int main() {
long long t, n;
cin >> t;
while (t--) {
cin >> n;
long long aa = gcd(n + 1, 4 * n);
cou... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 2.0 * acos(0.0);
const double eps = 1e-9;
template <class T>
T Abs(T x) {
return x > 0 ? x : -x;
}
template <class T>
string toString(T n) {
ostringstream ost;
ost << n;
ost.flush();
return ost.str();
}
template <class T>
inline T gcd(T a, T b) {... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<pair<string, string> > v;
int n, flag = 0, ans = 0;
string s, t;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s >> t;
flag = 0;
for (int j = 0; j < v.size(); j++) {
if (s == v[j].second) {
v[j].second = t;
fl... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, id, i = 1, j = 1;
cin >> n >> k;
map<int, int> m;
int arr[300000];
while (n--) {
scanf("%d", &id);
if (j - i < k && !m.count(id)) {
m[id] = 1;
arr[j] = id;
j++;
} else if (j - i == k && !m.count(id)) {
m[i... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T GCD(T a, T b) {
a = abs(a);
b = abs(b);
while (b) {
a = a % b;
swap(a, b);
}
return a;
}
template <typename T>
inline T LCM(T x, T y) {
T tp = GCD(x, y);
if ((x / tp) * 1. * y > 9e18) return 9e18;
return (x / tp) * y;
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
void solve() {
long long n;
cin >> n;
vector<long long> a(n);
set<pair<long long, long long>> s;
set<long long> s2;
for (long long i = 0; i < (long long)n; i++) {
cin >> a[i];
s.insert({a[i], i});
s2.insert(a[i]);
}
ma... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a[1000000];
int main() {
int n;
while (scanf("%d", &n) != EOF) {
int i;
double avg = 0;
for (i = 0; i < n; ++i) {
scanf("%d", &a[i]);
avg += a[i];
}
avg = avg / n;
int ans = 0;
for (i = 0; i < n; ++i) {
if (avg == a[i]) ... | 1 |
#include <bits/stdc++.h>
int n, K;
int ch[60000][26];
int val[60000];
char st[1000];
int f[60000][1000];
int knum;
void add(char *st) {
int m = strlen(st + 1);
int u = 0;
for (int i = 1; i <= m; i++) {
if (!ch[u][st[i] - 'a']) {
knum++;
ch[u][st[i] - 'a'] = knum;
}
u = ch[u][st[i] - 'a'];
... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
using namespace std;
mt19937 rnd(time(0));
template <class T>
long long upmax(T &a, T b) {
return (b > a) ? a = b, 1 : 0;
}
template <class T>
long long upmin(T &a, T b) {
return (b < a) ? a = b, 1 : 0;
}
void solve() {
int n, c;
cin >> n... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
puts(f ? "YES" : "NO");
exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
assert(y >= 0);
x += y;
if (x >... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int sum = 0, p = 1;
char ch = getchar();
while (!(('0' <= ch && ch <= '9') || ch == '-')) ch = getchar();
if (ch == '-') p = -1, ch = getchar();
while ('0' <= ch && ch <= '9') sum = sum * 10 + ch - 48, ch = getchar();
return sum * p;
}
const ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int n, p, i, j, k, c[505][505], dp[505][505], indices[505][505];
cin >> s >> p;
n = s.length();
for (i = 0; i < n; i++) {
for (j = i; j < n; j++) {
int cost = 0;
int a = i, b = j;
while (a < b) {
if (s[a] != s[b... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long g[2005][2005], f[2005][2005];
int n, m;
int main() {
scanf("%d%d", &n, &m);
g[0][0] = 1;
for (int i = 0; i <= n; i++)
for (int j = i + 1; j <= m; j++) {
if (j) g[i][j] = (g[i][j] + g[i][j - 1]) % 998244853;
if (i) g[i][j] = (g[i][j] + g[i - 1... | 5 |
#include<bits/stdc++.h>
#define MN 500000
#define mod 1004535809
#define mod2 1000000009
using namespace std;
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*10+ch-'0';ch=getchar();}
return x*f;
}
char s[MN+5];
int n,b[MN+5],pw[MN+5... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n, m, k, i, c = 0;
cin >> n >> m >> k;
long long int a[n];
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n, greater<long long int>());
if (m <= k)
cout << "0";
else ... | 1 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> mas[100001];
vector<pair<int, int> > marsh, res;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> mas[i].first >> mas[i].second;
}
int k = (n + m - 1) / m;
int now = 0, curpos = 0;
for (int i = 0; i < k; i++) {
... | 3 |
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 5010
#define inf 1000000000000000000ll
int n,A,B;long long f[N][N],ans;
int main()
{
scanf("%d%d%d",&n,&A,&B);
for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) f[i][j]=inf; f[0][0]=0;
for(int i=1,x;i<=n;i++)
{
scanf("%d",&x);
for(int j=0;j<=n;j++)... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n;
int a[N];
map<int, bool> mp;
vector<int> need;
vector<int> have;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
while (T--) {
mp.clear();
need.clear(), have.clear();
cin >> n;
for (int i = 1; i <= n;... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> v;
bool vis[100005];
int main() {
int m;
cin >> m;
for (int i = 0; i < m; i++) {
int a;
cin >> a;
}
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b, c;
cin >> a >> b >> c;
v.push_back({c, b});
}
sort(v.beg... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, n, m, k, l, a[60], g[60][60][60], f[60][60], c[60][60], d[60],
ans;
inline long long read() {
char c = getchar();
bool f = 0;
long long x = 0;
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 4... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long long n, i, j, k, x, y, z, b;
cin >> n;
vector<long long> a;
for (i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
sort(a.begin(), a.end());
a[0] = 1;
for (i = 1, b = 2; i < n; i++) {
if (a[i] ... | 2 |
#include <bits/stdc++.h>
using namespace std;
void swap(long long int x, long long int y) { x = x + (y - (y = x)); }
long long int gcd(long long int a, long long int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
long long int Gcd(vector<long long int> arr, long long int n) {
long long int result = arr[0];
... | 3 |
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
cin>>n;
vector<pair<int,int>> ans;
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(i+j!=n+1-n%2)ans.push_back({i,j});
cout<<ans.size()<<'\n';
for(auto x:ans)cout<<x.first<<' '<<x.second<<'\n';
}
| 0 |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
template <typename T>
T gcd(T a, T b) {
return (a == 0) ? b : gcd(b % a, a);
}
template <typename T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
... | 4 |
#include <cstdio>
#define _USE_MATH_DEFINES
#include <cmath>
#define rad(r) (r * M_PI / 180)
int main() {
int a, b, C;
scanf("%d %d %d", &a, &b, &C);
printf("%f\n", 0.5 * a * b * sin(rad(C)));
printf("%f\n", a + b + sqrt(a*a + b*b - 2 * a*b*cos(rad(C))));
printf("%f\n", b * sin(rad(C)));
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1000 + 10;
const int mod = 1e9 + 7;
int a[3][6];
int vis[100];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < 6; j++) cin >> a[i][j];
for (int i ... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool isPow(int n) {
double pot = pow(2, round(log2(n)));
return pot == n;
}
int main() {
int n, b, p;
cin >> n >> b >> p;
int bottles = 0;
int towels = n * p;
if (isPow(n)) {
int cant = pow(2, log2(n)) - 1;
bottles += cant * b * 2 + cant;
} else {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
void SR(int &x) { scanf("%d", &x); }
void SR(long long &x) { scanf("%lld", &x); }
void SR(double &x) { scanf("%lf", &x); }
void SR(char *s) { scanf("%s", s); }
void RI() {}
template <typename I, typename... T>
void RI(I &x, T &...tail) {
SR(x);
RI(tail...);
}
void SP(co... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 10000 + 10;
int cnt[MAX];
int a[MAX];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i]]++;
}
if (n == 1) {
cout << "YES\n";
return 0;
}
for (int i = 0; i < 1010; i++) {
if (n % 2 == 0 && cnt[... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 10, maxL = 31;
int a[maxN];
long long ps[maxN];
long double ans[maxN];
bool cmp(pair<long long, long long> C, pair<long long, long long> B,
pair<long long, long long> A) {
return (C.second - B.second) * (B.first - A.first) <
(B.sec... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> x;
vector<int> pos[100010];
map<int, int> id;
int tag[100010];
int a[100010], flag[100010];
int pre[100010], nxt[100010];
int n;
long long ans, tot;
int is_lucky(int x) {
if (x == 0) return 0;
while (x) {
if (x % 10 != 4 && x % 10 != 7) return 0;
x /... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using V = vector<T>;
const int INF = 1e9 + 5;
const int MOD = (int)1e9 + 7;
const int maxn = 1e2 + 5;
const int maxm = 1e6 + 5;
int modE(int n, int x) {
int res = 1;
while (x) {
if (x & 1) res = (1ll * res * n) % MOD;
n = (1ll * n * n) % MO... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
int N;
cin >> N;
vector<pair<int, int> > data(N);
for (int _n = N, i = 0; i < _n; ++i) cin >> data[i].first >> data[i].second;
sort(data.begin(), data.end());
int last = INT_MIN;
for (int _n = N, i = 0; i < _n; ++i) {
if ... | 1 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long maxn = 2e5 + 10;
const long long mod = 1e9 + 7;
const long double PI = acos((long double)-1);
long long pw(long long a, long long b, long long md = mod) {
long long res = 1;
while (b) {... | 5 |
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
int main(){
int value = 0;
int N,D;
scanf("%d %d",&N,&D);
int tmp;
for(int i = 0; i < N; i++... | 0 |
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <cli... | 0 |
//RohitKaushal
#include <cstdio>
#include <cmath>
int n;
double x[1005], y[1005], X, Y, d, e;
double dist(double a, double b) {
return a*a + b*b;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lf%lf", &x[i], &y[i]);
X += x[i]; Y += y[i];
}
X /= n; Y /= n;
d... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[1000000], rg[1000000];
vector<pair<int, long long>> gg[1000000];
int vi[1000000], comp[1000000], curr;
stack<int> stk;
long long wght[1000000], dp[1000000];
vector<pair<int, pair<int, long long>>> edg;
inline void dfs1(int u) {
vi[u] = 1;
for (auto x : g[u... | 5 |
#include <bits/stdc++.h>
using namespace std;
string a, b;
int cnt1[26], cnt2[26];
int main() {
cin >> a >> b;
int l = 0;
for (int i = 0; a[i]; i++) {
if (b[l] && b[l] == a[i]) {
l++;
}
}
if (!b[l]) {
cout << "automaton" << endl;
return 0;
}
for (int i = 0; a[i]; i++) {
cnt1[a[i]... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool has(vector<long long>& a, long long item) {
long long l = -1;
long long r = a.size();
while (r - l > 1) {
long long mid = (l + r) / 2;
if (a[mid] > item)
r = mid;
else
l = mid;
}
return a[l] == item;
}
int main() {
std::ios_base::syn... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 922337203685477;
const long long mininf = -922337203685477;
const long long nax = 0;
long long n, p, q;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> p >> q;
n *= 1000... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 20;
string s;
string c[MAX];
int n, k;
map<char, vector<int> > mm;
int main() {
scanf("%d%d", &n, &k);
cin >> s;
for (int i = 0; i < n; i++) cin >> c[i];
for (int i = 0; i < s.size(); i++) {
mm[s[i]].push_back(i);
}
for (auto &pp : mm) ... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const double eps = 1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long randint(long long l, long long r) {
long long out = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n4, n7, n47, n74, n44, n77;
void get_data() {
scanf("%d%d%d%d", &n4, &n7, &n47, &n74);
n77 = n7 - n74;
n44 = n4 - n47;
}
void p(int x, char c) {
while (x--) printf("%c", c);
}
void run() {
if (n77 < 0 || n44 < 0) {
printf("-1");
return;
}
int i;
... | 4 |
#include <bits/stdc++.h>
#define MAX 10001
#define NIL -1
int primes[MAX];
int N;
int isDisc = NIL;
bool isPrime(int n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i =... | 0 |
#include <bits/stdc++.h>
using namespace std;
float ar[100005];
int dp[100005];
int main() {
int n, i, max;
float a, b;
while (cin >> n) {
for (i = 0; i < n; i++) {
cin >> a >> b;
ar[i] = a + b / 100;
}
max = 1;
dp[0] = 1;
for (i = 1; i < n; i++) {
if (ar[i] == ar[i - 1])
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
while (1) {
a = a % b;
if (a == 0) return b;
b = b % a;
if (b == 0) return a;
}
}
const int inf = 1e9;
int a1[1000 * 1000 + 100];
int a2[1000 * 1000 + 100];
int b1[1000 * 1000 + 100], b2[1000 * 1000 + 100];
set<pair<int, int> > an... | 2 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int N = (1e6) + 322;
const long long INF = 2e18 + 17;
const int inf = 2e9 + 17;
const int mod = 1000000007;
const double eps = 1e-9;
long long a[N], b[N], n;
vector<long long> dif1, dif2;
signed main() {
ios_ba... | 5 |
#include <bits/stdc++.h>
using namespace std;
char s[105];
int a[105];
int n;
int main() {
cin >> n;
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> s[i];
a[i] = s[i] - '0';
sum += a[i];
}
if (sum == 0) {
cout << "YES" << endl;
return 0;
}
for (int i = 1; i < sum; i++) {
if (sum ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long int s = 0, max = 0;
int x, y;
for (int i = 0; i < n; i++) {
cin >> x >> y;
s = s - x + y;
if (s > max) max = s;
}
cout << max;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
struct DisjoinSet {
int fa[MAXN];
void init(int n) {
for (int i = (0); i <= (n); i++) fa[i] = i;
}
int f(int x) { return x == fa[x] ? x : fa[x] = f(fa[x]); }
void uni(int x, int y) { fa[f(y)] = f(x); }
} djs;
int N, M, deg[MAXN], vst[... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int mx[maxn * 4], tag[maxn * 4];
void pushup(int o) { mx[o] = max(mx[o * 2], mx[o * 2 + 1]); }
void build(int o, int l, int r) {
tag[o] = -1;
if (l == r) {
scanf("%d", &mx[o]);
return;
}
build(o * 2, l, (l + r) / 2);
build(o * 2 ... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
string toString(T Number) {
stringstream st;
st << Number;
return st.str();
}
int stringconvert(string s) {
int p;
istringstream st(s);
st >> p;
return p;
}
long long bigmod(long long a, long long b, long long m) {
long long res = 1;
... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.