solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include<bits/stdc++.h>
using namespace std;
int main(){
long long a;
cin>>a;
if(a%2==1) a=a*2;
cout<<a;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double EPS = 1e-13;
long long n, m, rnk[102], rsum;
double prob[102][100005];
double sm[100005];
double ans;
void solve() {
scanf("%lld%lld", &n, &m);
for (long long i = 1; i <= n; i++) {
scanf("%lld", &rnk[i]);
rsum += rnk[i... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
int ans[MAXN];
int main() {
int n, M, T;
scanf("%d%d%d", &n, &M, &T);
vector<int> pts;
for (int i = 0; i < n; i++) {
int h, m, s, r;
scanf("%2d:%2d:%2d", &h, &m, &s);
r = h * 60 * 60 + m * 60 + s;
pts.push_back(r);
}
sort... | 4 |
#include "bits/stdc++.h"
using namespace std;
int count(int y, int m, int d) {
int sum = 0;
for (int i = 1; i < y; i++) {
if (i % 3 == 0) sum += 20 * 10;
else sum += (20 + 19) * 5;
}
for (int i = 1; i < m; i++) {
if (y % 3 == 0) sum += 20;
else if (i % 2 == 1) sum += 20;
else sum += 19;
}
sum += (d - 1... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
long long n;
string a, b;
long long A[N];
long long B[N];
vector<pair<long long, long long> > ans;
long long root;
long long aum;
void dfs(long long pos) {
long long add = aum * ((pos - root) % 2 == 0 ? 1 : -1);
if (root != pos) {
if (a... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<string> pril, sush, glag;
void Init() {
pril.push_back("lios");
pril.push_back("liala");
sush.push_back("etr");
sush.push_back("etra");
glag.push_back("initis");
glag.push_back("inites");
}
pair<int, bool> Check(string str) {
pair<int, bool> res;
for ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, d, h;
cin >> n >> d >> h;
if (d > (2 * h))
cout << "-1" << endl;
else if (d == 1 && h == 1 && n > 2)
cout << "-1" << endl;
else {
for (int i = (h + 1); i >= 2; i--) {
cout << i << " " << i - 1 << endl;
}
long... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long L = 21;
const long long N = 2e5 + 7;
const long long INF = 1e9 + 1;
const long long mod = 1e9 + 7;
int n;
pair<int, int> a[N];
int get(int d, int st) {
vector<int> res;
if (st == 2) {
res.push_back(a[1].second);
}
for (int i = st + 1; i <= n; i++... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 20;
const double eps = 1e-8;
int a[N];
long long l[N];
long long r[N];
long long t[N];
map<int, int> q;
int main() {
long long n;
cin >> n;
for (int i = 1; i <= n; i++) scanf("%d", a + i);
long long ans = 0;
for (int... | 6 |
#include <bits/stdc++.h>
int inp() {
char c = getchar();
while (c < '0' || c > '9') c = getchar();
int sum = 0;
while (c >= '0' && c <= '9') {
sum = sum * 10 + c - '0';
c = getchar();
}
return sum;
}
struct Node {
int a;
int l;
} s[110];
bool cmp(Node a, Node b) { return a.a < b.a; }
int f[110][... | 5 |
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int n;
const int MAX = 32768;
int solve(int sum,int cnt,int num){
if(sum == n) return 1;
if(sum+num*num > n|| cnt == 4) return 0;
int res = 0;
res+=solve(sum+num*num,cnt+1,num);
res+=solve(sum,cnt,num+1);
return res;
}
int main(... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, base[20];
base[0] = 1;
for (int i = 0; i < 18; i++) base[i + 1] = base[i] * 10;
while (cin >> a >> b) {
long long ans = a, now = a, t = a;
int c = 0;
while (a - now <= b) {
ans = now;
c++;
if (t < 10) break;... | 2 |
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>
#include <bitset>... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[10][10];
void Per(string s, int &x, int &y) {
stringstream ss;
ss << (s[0] - 'a');
x = atoi(ss.str().c_str()) + 1;
ss.str("");
ss << s[1];
y = 8 - atoi(ss.str().c_str()) + 1;
}
bool Prov(int x, int y) {
if (a[y][x] == 0)
return true;
else {
if ... | 2 |
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <queue>
typedef long long ll;
const ll LL_MAX (1LL<<60);
#define rep(i,s,e) for(ll i=(s); i<(e); i++)
using namespace std;
int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 10;
bool mark[MAXN];
int has[MAXN];
vector<int> adj[MAXN];
vector<pair<int, pair<int, int> > > ans;
void dfs(int x) {
mark[x] = true;
vector<int> t, check;
for (__typeof((adj[x]).begin()) i = (adj[x]).begin(); i != (adj[x]).end();
... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<set<char>> groups;
bool check(const string& s1, const string& s2) {
if (s1.length() != s2.length()) return true;
int len = s1.length();
for (int i = 0; i < len; i++) {
bool b = false;
for (auto group : groups) {
if (group.find(s1[i]) != group.end(... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
int32_t main() {
long long int n;
cin >> n;
vector<long long int> v;
long long int k = 1;
for (long long int i = 0; i <= 11; i++) {
v.push_back(k);
k *= 10;
}
long long int count = 0;
for (long long int i = 1; i < v... | 2 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n, i, j, k;
cin >> n;
k = n - 1;
vector<long long> a(n);
for (long long i = 0; i < n; i++) cin >> a[i];
i = 0... | 2 |
#include <bits/stdc++.h>
int n1, m1, n2, m2;
int ar1[60][60], ar2[60][60];
void oku() {
int i, j;
char c;
scanf(" %d %d", &n1, &m1);
for (i = 1; i <= n1; i++)
for (j = 1; j <= m1; j++) {
scanf(" %c", &c);
ar1[i][j] = c - '0';
}
scanf(" %d %d", &n2, &m2);
for (i = 1; i <= n2; i++)
for... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int T = 1;
while (T--) {
int n, m;
cin >> n >> m;
vector<pair<int, int>> v;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
v.push_back(make_pair(x, y));
}
so... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long A, B, l, t, m;
long long t1;
inline bool possible(long long z) {
long long tn = t1 + (z - 1) * B;
return (z * (t1 + tn) / 2 <= min(m, z) * t && tn <= t);
}
int main() {
int n;
cin >> A >> B >> n;
for (int i = 0; i < n; i++) {
cin >> l >> t >> m;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline int ID(char x) { return x - '0'; }
struct trie {
public:
int root = 0;
int cnt = 0;
vector<int> val;
vector<vector<int>> ch;
trie() {
ch.push_back(vector<int>(2, -1));
val.push_back(0);
cnt = 0;
}
void add(string s) {
int now = root;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1, M = 4e5 + 2;
int n;
int b[N], c[N];
long long d[1000000];
int main() {
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> b[i], c[i] = i - b[i], d[c[i] + M] += 1ll * b[i];
long long ans = 0;
for (int i = 1; i <= n; ++i) ans = max(ans, d[c[i] + ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int mat[111][111];
int main() {
int n, k, i, j;
scanf("%d", &n);
scanf("%d", &k);
memset(mat, 0, sizeof(mat));
if (k > n * n)
cout << "-1" << endl;
else {
if (k != 0) {
for (i = 0; i < n; i++) {
if (k >= (2 * (n - i) - 1)) {
for (... | 1 |
#include<iostream>
#include<algorithm>
using namespace std;
const int N=100010;
bool st[N];
int main(){
int n,k,r,s,p;
cin>>n>>k>>r>>s>>p;
char t[N];
cin>>t;
int sum=0;
for(int i=0;i<n;i++){
if(st[i]==false){
if(i+k<n && t[i]==t[i+k]){
st[i+k]=true;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long k, c[1002], a[1002][1002], sum = 0, f[1002];
int main() {
a[0][1] = 1;
a[1][1] = 1;
a[1][2] = 2;
for (long long i = 2; i < 1002; i++) {
a[0][i] = 1;
a[1][i] = i;
for (long long j = 1; j <= i; j++) {
a[j][i] = (a[j - 1][i - 1] + a[j][i - 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 9;
long long sum[N];
vector<pair<long long, long long>> seg[4 * N];
bool remo(long long rt) {
long long l = seg[rt].size();
if (l < 3) return false;
long long m1, m2, m3, c1, c2, c3;
m3 = seg[rt][l - 1].first;
c3 = seg[rt][l - 1].second;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long k;
int q;
int solve(long long x) {
long long low = 1, high = 5e8, m, last, mx;
while (low <= high) {
m = (low + high) / 2;
long long p = 0, sum = 0, len = 1;
while (m - p > 0) {
long long l = m - p, r = max(0LL, m - p * 10 - 8);
sum += ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
double a, d;
cin >> n >> a >> d;
double t[100005], v[100005];
for (int i = 0; i < n; i++) cin >> t[i] >> v[i];
double ans[100005];
for (int i = 0; i < n; i++) {
double cur = min(sqrt(2 * d / a), v[i] / a);
double val = t[i] + (d - .... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 100001, maxK = 100;
int T[maxN][maxK];
vector<int> G[maxN], vs[maxK];
queue<int> Q;
int main() {
int n, m, k, s;
scanf("%d%d%d%d", &n, &m, &k, &s);
for (int i = 1; i <= n; i++) {
int a;
scanf("%d", &a);
vs[a - 1].push_back(i);
for (int... | 1 |
#include <iostream>
using namespace std;
int main(){
int a,cou;
while(cin>>a){
cou=0;
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
for(int k=0;k<10;k++){
for(int q=0;q<10;q++){
if(i+j+k+q==a)cou++;
}
}
}
}
cout<<cou<<endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >>N;
vector<int> a(N),b(N),c(20000000,0);
for(int i=0;i<N;i++){
cin >> a[i];
c[a[i]]++;
}
for(int i=1;i<c.size();i++){
c[i]+=c[i-1];
}
for(int i=N-1;i>=0;i--){
int x=c[a[i]];
b[x... | 0 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
class Graph {
public:
vector<vector<int> > adj;
int n;
int dab, maxdist, arg;
vector<bool> seen;
Graph() {}
Graph(in... | 2 |
#include <bits/stdc++.h>
using namespace std;
int Ans = 1;
vector<int> Ed[10001];
vector<bool> Vis(10001);
vector<int> Col(10001);
int N;
void dfs(int ind, int col) {
Vis[ind] = true;
if (Col[ind] != col) Ans++;
for (int i = 0; i != Ed[ind].size(); i++) {
if (!Vis[Ed[ind][i]]) dfs(Ed[ind][i], Col[ind]);
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b, long long p) {
long long res = 1;
a %= p;
for (; b; b >>= 1) {
if (b & 1) res = res * a % p;
a = a * a % p;
}
return res;
}
template <typename T>
T gcd(T x, T y) {
while (y) {
T t = x % y;
x = y;
y =... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100005], p;
long long ans;
vector<int> e[100005], b[2];
map<int, int> mp[2];
int dfs(int u, int d) {
int deep = d;
b[d & 1].push_back(a[u]);
mp[d & 1][a[u]]++;
for (int i = 0; i < (int)e[u].size(); ++i)
deep = max(deep, dfs(e[u][i], d + 1));
return de... | 5 |
#include <iostream>
#include <vector>
#include <queue>
using namespace std ;
int main(){
int n ; cin >> n ;
priority_queue<int> pq ;
long long ans = 0 ;
vector<vector<int>> vec(n,vector<int>(0)) ;
for(int i=0;i<n;i++){
int m ; cin >> m ;
for(int j=0;j<m;j++){
int a ; cin >> a ;
vec.at(i).push_back(a) ;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 2 == 0) {
cout << "Mahmoud\n";
} else {
cout << "Ehab\n";
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(int n) {
for (int i = 2; i * i <= n; i++)
if (n % i == 0) return false;
return true;
}
int main() {
int n;
cin >> n;
cout << n << " ";
for (int(i) = (2); (i) < (1000010); (i)++)
if (n % i == 0 && isprime(i))
while (n % i == 0) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
long long a[200005], x;
struct heap {
long long data;
int indx;
} h[200005];
void heapify(int i) {
int l, r, s;
long long tmp;
l = 2 * i + 1;
r = 2 * i + 2;
s = i;
if (l < n && h[l].data < h[i].data) s = l;
if (r < n && h[r].data < h[s].data) s =... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct domino {
int u;
int l;
int uh;
int lh;
};
int main() {
int n, eu = 0, ou = 0, el = 0, ol = 0;
cin >> n;
int sum1 = 0, sum2 = 0;
struct domino a[101];
for (int i = 0; i < n; i++) {
cin >> a[i].u >> a[i].l;
sum1 += a[i].u;
sum2 += a[i].l;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
class FLCR {
public:
inline long long int mul(long long int a, long long int b) {
return (1LL * a * b) % 1000000007LL;
}
inline long long int nc2(long long int n) {
return mul(mul(n, n - 1), (1000000007LL + 1) / 2);
}
inline long long int add(long long in... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool compare(const T &a, const T &b) {
return a.second < b.second;
}
long long arr[500][500];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long cnt = 1;
long long n;
cin >> n;
long long dow = 1;
f... | 3 |
#include <bits/stdc++.h>
using namespace std;
int start[50 + 10][5];
int main() {
int n, m, ans = 10000;
string a;
cin >> n >> m;
for (int i = 0; i < 50 + 10; i++) {
for (int k = 0; k < 5; k++) {
start[i][k] = -1;
}
}
for (int i = 0; i < n; i++) {
cin >> a;
if (a.find_first_of("1234567... | 3 |
#include<bits/stdc++.h>
using namespace std;
int n,f,t,i,r;
vector<int> g[1<<18];
int dfs(int v, int p) {
int c0 = 0, a = 0;
for(int i : g[v]) if(i != p) {
t = dfs(i, v);
t ? a += t : ++c0;
}
return a + c0 - (c0>0);
}
int main() {
for(i=(cin>>n,n);--i;) {
cin>>f>>t;
g[f].push_back(t);
g[t].push_back(f);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, kq = 0;
int main() {
cin >> n;
for (int i = 1; i <= sqrt(n); i++) {
long long s = 3ll * i * (i + 1) / 2 - i;
if (s <= n) {
if ((n - s) % 3 == 0) kq++;
} else
break;
}
cout << kq;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const long long INF = (long long)1e9 + 7;
long long fact[N];
long long mypow(long long a, long long x, long long mod) {
long long ans = 1;
while (x) {
if (x & 1) {
ans = (ans * a) % mod;
}
a = (a * a) % mod;
x >>= 1;
}
ret... | 4 |
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
#define pii pair<int, int>
class Compare1 {
public:
bool operator() (pii a, pii b) {
return (a.second < b.second or (a.first > b.first and a.second == b.second));
}
};
void testCase() {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int plane[30][30];
int bias = 10;
char s[20];
bool eval() {
for (int i = bias; i < bias + 10; i++)
for (int j = bias; j < bias + 10; j++) {
int s1(0), s2(0), s3(0), s4(0);
for (int k = -2; k <= 2; k++) {
s1 += plane[i + k][j];
s2 += plane[i... | 2 |
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
int bit[200000];
vector<int>v;
void add(int k, int x) {
while (k <= v.size()) {
bit[k] += x;
k += k&-k;
}
}
int sum(int k) {
int res = 0;
while (k) {
res += bit[k];
k -= k&-k;
}
return res;
}
int a[100000], b[100000], c[1... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
long long gcd(long long a, long long b) { re... | 5 |
#include <bits/stdc++.h>
#define read(n) scanf("%lld",&n)
#define write(x) printf("%lld",x)
#define F(i,n) for(int i = 0;i < n;i++)
#define ll long long
#define MX 3005
#define MOD 1000000007
#define INF 1000000009
#define set_dp(dp) memset(dp,-1,sizeof(dp))
using namespace std;
ll t, n, a[MX];
int main(){
#ifndef ONL... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool ok(vector<ll>& a, unordered_map<ll, int>& cnt, int i, int j) {
for (int k = i; k <= j; k++) {
cnt[a[k]] -= 1;
}
bool good = true;
for (auto& p : cnt) {
if (p.second > 1) {
good = false;
break;
}
}
for (int k = i... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename... T>
void read(T&... args) {
((cin >> args), ...);
}
template <typename... T>
void write(T&&... args) {
((cout << args << " "), ...);
}
template <typename... T>
void writen(T&&... args) {
((cout << args << "\n"), ...);
}
long long bin(long long a, ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000 * 1000 * 1000;
int T, n;
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
printf("%d\n", max(0, n - 2));
}
return 0;
}
| 2 |
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
#include<complex>
#include<array>
#includ... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> pll;
pll arr[100005],arr1[100005];
vector<pair<ll,pll> > vect;
int root[100005];
int _rank[100005];
int findroot(int a){
while(a!=root[a])
a=root[a];
re... | 0 |
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;
pair<int, int> P[200005];
int p, r, t;
int ned[305][305];
int num[305];
int grid[305][305];
int used[305];
int bo[305];
int check(int t) {
memset(used, 0, sizeof(used));
memset(grid, 0, si... | 0 |
#include <bits/stdc++.h>
using namespace std;
void in(int &x) {
char ch;
int minus = 0;
while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
;
if (ch == '-')
minus = 1, x = 0;
else
x = ch - '0';
while (ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - '0';
if (minus) x = -x;
}
v... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void *wmem;
char memarr[96000000];
template <class T>
inline void walloc1d(T **arr, int x, void **mem = &wmem) {
static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
(*mem) = (void *)(((char *)(*mem)) + skip[((unsig... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100;
const int mod = 1e9 + 7;
vector<int> side[maxn];
int a[maxn];
long long s[maxn];
int cnt[maxn], tot[maxn];
bool f[maxn];
void dfs(int u, int fa) {
s[u] = a[u];
for (int i = (0), iend = (side[u].size() - 1); i <= iend; i++) {
int v = side[... | 3 |
#include <bits/stdc++.h>
using namespace std;
int arr[4194304 + 1];
bool Exists[4194304 + 20] = {0};
int F[4194304 + 10][2] = {0};
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
Exists[arr[i]] = 1;
F[arr[i]][0] = arr[i];
}
for (int i = 1; i <= 22; i++) {
for ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
int length1, length2;
length1 = a.size();
length2 = b.size();
vector<int> v, num;
for (int i = 0; i < length1; i++) {
num.push_back(a[i] - '0');
}
for (int i = 0; i < length2; i++) {
v.push_back(b[i] - '0');... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long cnt[200009];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(cnt, -1, sizeof cnt);
long long i, j, k, l, m, n, a, b;
long long mn = 0;
string s;
cin >> s;
n = s.size();
stack<long long> st;
a = -1, b = -3;
for (i = 0; i <... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
if (b == 0) return 1;
if (b == 1) return a;
long long int c = power(a, b / 2);
if (b % 2 == 0) return ((c % 1000000007) * (c % 1000000007)) % 1000000007;
return ((((c % 1000000007) * (c % 1000000007)) % 10000... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, p;
cin >> n >> p;
vector<int> arcosA((n + 1), 0);
vector<pair<int, int>> parejas;
unordered_map<int, int> interseccion[n + 1];
for (int i = 1; i <= n; ++i) {
int x, y;
c... | 3 |
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
LL modpow(LL x, LL n){
LL r=1;
while(n){
if(n&1) r=r*x%mod;
x=x*x%mod;
n>>=1;
}
return r;
}
LL modinv(LL x){
LL m=mod, u=1, v=0;
while(m... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long powers[1000];
int main() {
ios_base::sync_with_stdio(0);
string imput, number;
cin >> imput;
number = "";
powers[0] = 1;
powers[1] = 2;
for (int i = 2; i < 1000; i++) {
powers[i] = (powers[i - 1] * 2) % 1000003;
}
for (int i = 0; i < imput.si... | 2 |
#include <bits/stdc++.h>
using namespace std;
int b[100005][3];
int a[300005];
int mp[300005];
vector<int> ans1, ans2;
int vis[300005];
int cmp(const int &a, const int &b) { return mp[a] < mp[b]; }
int main() {
int i, j, n, m, k, q, p1, p2;
scanf("%d", &n);
for (i = 1; i <= 3 * n; i++) {
scanf("%d", &a[i]);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int p[2503];
vector<pair<int, int> > a[102];
int root(int x) { return p[x] < 0 ? x : p[x] = root(p[x]); }
void mer(int x, int y) {
if ((x = root(x)) == (y = root(y))) return;
if (p[x] > p[y]) swap(x, y);
p[x] += p[y];
p[y] = x;
}
int main... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
int arr[t];
for (int i = 0; i < t; i++) {
cin >> arr[i];
}
sort(arr, arr + t);
for (int i = 0; i < t; i++) cout << arr[i] << " ";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, T;
cin >> n >> T;
int ans[n];
vector<int> x, y, z;
int tmp;
int flag = 0;
for (int i = 0; i < n; ++i) {
cin >> tmp;
if (T % 2 == 0 and tmp == T / 2) {
ans[i] = (flag++) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, t, x;
struct comp {
double x, y;
comp(double xx = 0, double yy = 0) { x = xx, y = yy; };
};
comp operator+(comp a, comp b) { return comp(a.x + b.x, a.y + b.y); }
comp operator-(comp a, comp b) { return comp(a.x - b.x, a.y - b.y); }
comp operator*(comp a, comp ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int qian[maxn] = {0};
int num[maxn] = {0};
int pre[maxn] = {0};
int main() {
int n, c;
cin >> n >> c;
int Max = 0;
for (int i = 1; i <= n; i++) {
int a;
scanf("%d", &a);
if (a == c)
qian[i] = qian[i - 1] + 1;
else {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cer... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, t[111111];
void upd(int x, int val) {
for (int i = x; i <= n; i = (i | (i + 1))) {
t[i] += val;
}
}
int get(int x) {
int res = 0;
for (int i = x; i > 0; i = (i & (i + 1)) - 1) {
res += t[i];
}
return res;
}
int main() {
cin >> n;
for (int i = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long update(vector<long long> &tree, int index, int a, int b, int x,
long long value) {
if (x >= a and x < b) {
if (a == b - 1)
tree[index] = value;
else
tree[index] = update(tree, 2 * index, a, (a + b) / 2, x, value) +
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, u, r;
vector<long long> a, b, p, k;
long long ans = -1000000000000;
void func(long long turn, bool isxor) {
long long i;
if ((u - turn + 1) % 2 == 0) {
long long sum = 0;
for (i = 0; i < n; i++) sum += a[i] * k[i];
ans = max(ans, sum);
}
if ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int A[100000], G[100000], C[10000], T[100000], ac[100000], gc[100000],
cc[10000], tc[100000];
int main() {
string s;
int a = 0, g = 0, c = 0, t = 0, ac1 = 0, gc1 = 0, cc1 = 0, tc1 = 0;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'A') A[a++] = ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 20 + 5;
int board[2][N], n, est[22];
long long solver[22][2];
inline void merged() {
int num = 1 << n;
for (int lvl = int(1); lvl < int(n + 1); ++lvl) {
int ato = 1 << lvl;
int ito = ato >> 1;
int sig = (lvl - 1) & 1;
for (int i = 0; i... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int INF = 0x3f3f3f3f;
int d, n, m;
struct Sta {
int x, p;
Sta() {}
Sta(int x, int p) : x(x), p(p) {}
void read() { scanf("%d%d", &x, &p); }
bool operator<(const Sta& c) const { return x < c.x; }
} p[N];
struct Node {
int Min, Minid;
}... | 4 |
#include<iostream>
using namespace std;
int main(void){
int N;
cin >> N;
int ans=0;
for(int i=0;i<N;i++){
int a;
cin >> a;
while(a%2==0){
ans++;
a/=2;
}
}
cout << ans << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
long long n, m;
cin >> n >> m;
vector<int> v(n);
vector<long long> pref(n + 1);
pref[0] = 0;
for (int i = 0; i < n; i++) {
cin >> v[i];
pref[i + 1] = pref[i] + v[i];
}
vector<int> ans;
for (int i = 0; i ... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a[1010][1010];
long long s[1010], sSqr[1010];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (int i = 0; i < k; i++)
for (int j = 0; j < n; j++)
{
cin >> a[i][j];
s[i] += a[i][j];
sSqr[i] += 1LL * a[i]... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const int MAXn = 100;
long long a[MAXn];
long long t[MAXn][MAXn];
int n;
bool check() {
long long s = 0;
for (int i = 0, __e = n; i < __e; i++) s += t[0][i];
for (int i = 0, __e = n; i < __e; i++) {
long long x = 0;
for (int j = 0, __e = n... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const long long MOD = 1e9 + 7;
long long h[26][N], p[N];
int a[30], b[30];
char s[N + 10];
long long get(int i, int l, int r) {
return (h[i][r] - h[i][l - 1] * p[r - l + 1]) % MOD;
}
int main() {
int n, m, x, y, len;
while (scanf("%d%d", &n, &m... | 6 |
#include <bits/stdc++.h>
using namespace std;
int MAX_N=262144;
vector<vector<int64_t>> seg(MAX_N*2-1,vector<int64_t>(2));
int64_t qu(int t,int a,int b,int k,int l, int r){
if(r<=a||b<=l){
return -1;
}
else if(a<=l&&r<=b){
return seg[k][t];
}
else{
int64_t X=qu(t,a,b,k*2+1,l,(l+r)/2);
int64_t... | 0 |
#include<bits/stdc++.h>
using namespace std;
int M,N;
string S[130];
int dp[(1<<11)][(1<<11)];
bool check(int st,int fr){
int mem[130]={};
int n = __builtin_popcount(st);
for(int i=0;i<M;i++){
if( st & (1<<i) ) {
for(int j=0;j<N;j++){
if( S[j][i] == '0' && !(fr & (1<<i)) ){
mem[j]++;
} else if(... | 0 |
#include <bits/stdc++.h>
using namespace std;
int pop_count(int bits){
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (... | 0 |
#include <stdio.h>
int main(){
int n, m, tl[10001], tr[10001], i, j, k, max, data[20005] ;
while(1){
scanf("%d %d", &n, &m);
if(n==0 && m==0) break;
for(i=0;i<n;i++){
scanf("%d", &tl[i]);
}
tl[i]=1000001;
for(i=0;i<m;i++){
scanf("%d", &tr[i]);
}
tr[i]=1000001;
j=... | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005,M=1e9+7;
ll fac[N]= {1,1},inv[N]= {1,1},f[N]= {1,1},pos[N];
ll C(ll a,ll b) {
if(b>a)
return 0;
return fac[a]*inv[b]%M*inv[a-b]%M;
}
void init() { //快速计算阶乘的逆元
for(int i=2; i<N; i++) {
fac[i]=fac[i-1]*i%M;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[1000010];
int main() {
long long n, ans = 0, j;
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
a[x]++;
}
ans = n;
for (int i = 0; i <= 1000000; i++) {
a[i + 1] += a[i] / 2;
ans -= a[i] / 2;
}
while (a[1000001] != 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300001;
int a[3][N];
int next_pos[3][N];
map<long long, int> last;
struct data {
int c, v;
data(int c, int v) : c(c), v(v) {}
friend bool operator<(data e, data r) {
if (min(e.c, e.v) < min(r.c, r.v)) {
return 0;
}
if (min(e.c, e.v) > m... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, x[2010], y[2010];
char str[2010];
bool vis[2010];
struct Node {
long long x, y;
Node operator+(const Node &u) const { return (Node){x + u.x, y + u.y}; }
Node operator-(const Node &u) const { return (Node){x - u.x, y - u.y}; }
} node[2010], last;
inline lo... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, N, a[2005][2005], mn = 2000000000, mnp, dis[2005], vis[2005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++) {
cin >> a[i][j];
if (a[i][j] < mn) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
long long int n = t;
vector<int> v;
while (t--) {
int x;
cin >> x;
v.push_back(x);
}
long long int ans = 0;
ans = v[0];
for (int i = 1; i < n; ++i) {
ans += abs(v[i] - v[i - 1]);
}
ans += n + n - ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int Inf = 1e9;
const int Maxn = 234;
bool isp[22233];
void getp() {
isp[1] = 1;
for (int i = 2; i <= 20000; i++)
if (!isp[i]) {
for (int j = i + i; j <= 20000; j += i) isp[j] = 1;
}
}
int n, s, t, ne, ans;
int in[Maxn], h[Maxn], cur[Maxn];
vector<int... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int C = 26;
void add(int &x, int y) {
x += y;
while (x >= MOD) x -= MOD;
while (x < 0) x += MOD;
}
int fix(int x) {
while (x >= MOD) x -= MOD;
while (x < 0) x += MOD;
return x;
}
int pw(int a, int b) {
int ret = 1;
while (b) {
... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.