solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <iostream>
#include <vector>
#include <deque>
using namespace std;
struct Node {
struct Node * plus;
struct Node * mul;
int num;
};
int main() {
int K;
cin >> K;
vector<struct Node> N(K);
for(int i = 0; i < K; i++) {
N[i].num = i;
N[i].plus = &N[(i + 1) % K];
N[i].mul = &N[(i * 10) % K];
}
vec... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
vector<int> Length(3);
for (int i = 0; i < 3; ++i) {
scanf("%d", &Length[i]);
}
sort(Length.begin(), Length.end());
printf("%d\n", max(0, Length[2] - (Length[0] + Length[1]) + 1));
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
struct pt {
long long x, y, idx;
pt operator+(pt p) { return {x + p.x, y + p.y}; }
pt operator-(pt p) { return {x - p.x, y - p.y}; }
bool operator==(pt p) { return (idx == p.idx); }
};
pt p[12333];
long double dis(pt a, pt b) {
return sqrt((a.x - b.x) * (a.x - b.x... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n, 0);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
set<int> s;
for (int i = 0; i < n; i++) {
s.insert(a[i]);
}
if (s.size() > 3) {
cout << "-1\n";
return 0;
}
if (s.size() == 1) {
cout <<... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, x, s[400], ans;
int Cal(int x) {
int y = 360 - x;
return x > y ? x - y : y - x;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
s[i] = s[i - 1] + x;
}
ans = 360;
for (int i = 1; i <= n; i++)
for (int j = i; j ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
ios_base::sync_with_stdio(0);
int mn = 1e9;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int l, r;
cin >> l >> r;
mn = min(mn, r - l + 1);
}
int cur = 0;
cout << mn << "\n";
for (int i = 0; i < n; i++) {
if (mn == cur) ... | 3 |
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
long long power(long long a, long long b, long long c) {
long long res = 1;
while (b) {
if (b & 1LL) res = (res * a) % c;
a = (a * a) % c;
b /= 2;
}
return res;
}
void solve() {
vector<long long> a(2);
for (long long &x : a) ... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long play(vector<long long> a, long long i) {
long long t = a[i];
a[i] = 0;
long long d = t / 14, r = t % 14;
for (long long i = 0; i < 14; i++) a[i] += d;
while (r--) a[(++i) % 14]++;
long long res = 0;
for (long long i = 0; i ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int t;
const int maxn = 1e5 + 8;
char s[maxn];
int n;
void find(char s[]) {
int mid = n >> 1;
for (int i = 1; i <= n; i++) {
if (s[i] == '0') {
if (i <= mid) {
cout << i << " " << n << " " << i + 1 << " " << n << endl;
} else {
cout << 1 ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
long long cur = 1, ans = 0;
string s, t;
int main() {
cin >> n >> k >> s >> t;
s = '#' + s;
t = '#' + t;
for (int i = (int)1; i <= (int)n; ++i) {
cur *= 2;
if (s[i] == 'b') --cur;
if (t[i] == 'a') --cur;
cur = min(cur, (long long)1e10);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x, y;
point() {}
point(int a, int b) { x = a, y = b; }
};
template <class T>
T sqr(T a) {
return a * a;
}
template <class T>
T power(T n, T p) {
T res = 1;
for (int i = 0; i < p; i++) res *= n;
return res;
}
template <class T>
double getdist... | 2 |
#include <bits/stdc++.h>
using namespace std;
char let[100100];
int cou[100];
int main() {
int i, n;
scanf("%d", &n);
getchar();
memset(cou, 0, sizeof(cou));
int ans = 0;
int s = 1;
for (i = 1; i <= n; i++) {
scanf("%c", &let[i]);
if (cou[let[i] - 'A'] == 0) ans = i - s + 1;
cou[let[i] - 'A']+... | 3 |
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int dp[5001][5001];
int main() {
int N;
string S;
cin >> N >> S;
dp[0][0] = 0;
for (int i = 1; i <= N; i++) {
for (int j = i + 1; j <= N; j++) {
if (S[i - 1] != S[j - 1]) continue;
dp[i][j] = min(dp[i - 1][j - 1] + 1, j - i)... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long val[100050];
int degree[100050], par[100050];
struct cmp {
bool operator()(int a, int b) {
if (val[a] != val[b]) return val[a] < val[b];
return a < b;
}
};
set<int, cmp> son[100050];
multiset<long long> overall;
long long t[100050];
int n, q;
long long... | 4 |
#include <bits/stdc++.h>
using namespace std;
void re(vector<long long> &v, int n) {
for (auto i = 0; i < n; i++) cin >> v[i];
}
void wr(vector<long long> v) {
for (auto i : v) cout << i << " ";
}
void consoleIO() {}
long long fact(long long n) {
if (n == 1 || n == 0) return 1;
return (n * fact(n - 1));
}
long ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1 << 18;
const int MaxLength = 1 << 4;
int N;
char S[MaxN][MaxLength];
int Convert(char* S) {
int Result = 0;
while (*S) {
Result = Result * 10 + (((*S) == '?') ? 9 : (*S) - '0');
S++;
}
return Result;
}
int main(void) {
scanf("%d", &N);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
n %= 4;
if (n == 0 || n == 3) {
cout << 0 << endl;
} else {
cout << 1 << endl;
}
return 0;
}
| 1 |
#include <cstdio>
using namespace std;
int h,a;
int main(){
scanf("%d%d",&h,&a);
printf("%d",(h-1)/a+1);
return 0;
}
| 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
using namespace std;
int n, m, a, b, c, d, i, j, sz, mx;
int ar[(int)(1e6 + 7)];
int brainfuck();
string s, s2;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
cin >> s >> s2;
cout << brainfuck();
return 0;
}
int br... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
signed main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int s, in, ex;
cin >> s >> in >> ex;
long long int d = s - in;
long long int ans = 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ld = long double;
using ulli = unsigned long long int;
void solve() {
lli n;
cin >> n;
int count = 0;
for (lli i = 0; i < n; i++) {
if (count == 0 or count == 1) {
cout << "a";
count += 1;
} else {
cout << "... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100005], sum, ans, t1, t2;
char ch[100005];
int gets() {
int v = 0;
bool f = 0;
char ch;
while (!isdigit(ch)) {
f |= ch == '-';
ch = getchar();
}
while (isdigit(ch)) {
v = (v << 3) + (v << 1) + ch - 48;
ch = getchar();
}
return f ? -... | 2 |
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloa... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4000009;
int main() {
string a, b;
char upperbound = 'a';
cin >> a >> b;
int lt1[124] = {0}, lt2[124] = {0};
for (int i = 0; i < a.size(); i++) {
lt1[a[i]]++;
}
for (int i = 0; i < b.size(); i++) {
lt2[b[i]]++;
if (b[i] > upperbound) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int gotcha() {
register int a = 0, b = 1, c = getchar();
while (!isdigit(c)) b ^= c == '-', c = getchar();
while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
return b ? a : -a;
}
const int _ = 1002, mo = 1000000007;
long long powa(long long a, long long t... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, k;
long long solve(long long n) {
if (n % a == 0)
return (n / a - 1);
else
return (n / a);
}
int32_t main() {
vector<long long> v;
long long n;
cin >> n >> a >> b >> k;
long long x;
for (long long i = 0; i < n; i++) {
cin >> x;
... | 4 |
#include<bits/stdc++.h>
using namespace std;
char russia[52][52];
int main(){
int n,m;
cin>>n>>m;
int c=n*m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>russia[i][j];
}
}
int d=0;
for(int i=1;i<n-1;i++){
for(int j=1;j<n-i;j++){
for(int p=0;p<i;p++){
for(int l=0;l<m;l++){
if(... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, mxmc;
map<int, int> adj[100007];
int color[100007];
int sz[100007];
int ans = 100007, s = 0;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> color[i];
}
for (int i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
const int mod = 998244353;
inline int read(int x = 0, bool f = 0, char ch = getchar()) {
for (; !isdigit(ch); ch = getchar()) f = ch == '-';
for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
return f ? -x : x;
}
int n, m, f... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int fx[] = {0, 0, -1, 1, +1, -1, -1, +1};
int fy[] = {1, -1, 0, 0, +1, +1, -1, -1};
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
return a.first > b.first;
}
template <typename T>
inline T Bigmod(T base, T power, T MO... | 1 |
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 1e5 + 5;
constexpr int MAXW = 1e4 + 5;
constexpr int MOD = 998244353;
constexpr long long INF = 1e18;
constexpr int LOG = 11;
int n, m, k, a[MAXN], mx[MAXN], mx2[MAXN], val;
vector<int> G[MAXN];
bool mark[MAXN], failed[MAXN];
set<pair<long double, int> ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 5005;
int dp[N][30];
int main() {
int n;
scanf("%d\n", &n);
for (int i = 1; i <= n; ++i) {
char c;
scanf("%c", &c);
int t = c - 'a' + 1;
int cur = 1;
for (int j = 1; j <= n; ++j) {
dp[j][0] = (dp[j][0] -... | 4 |
#include<iostream>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
if(n-m>0) cout<<n-m;
else cout<<0;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 1) {
cout << -1;
} else
cout << n << ' ' << n + 1 << ' ' << n * (n + 1);
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int n, a[N], b[N], c[N], mx[N], gc[N];
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 1; i < n; i++) gc[i] = gcd(i, n);
long long ans = 0;
f... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
float arr[maxn];
map<float, int> cnt;
int main() {
int n, a, b, c;
char ch;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> ch;
scanf("%d+%d)/%d", &a, &b, &c);
arr[i] = (a + b + 0.0) / (c + 0.0);
cnt[arr[i]]++;
}
... | 4 |
#include <bits/stdc++.h>
int main() {
int w, b;
char c;
w = 0;
b = 0;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
scanf(" %c", &c);
if (c == 'Q') {
w += 9;
}
if (c == 'R') {
w += 5;
}
if (c == 'B' || c == 'N') {
w += 3;
}
... | 1 |
#include <bits/stdc++.h>
using ll = long long;
int n = 0;
void readcircuit(std::set<int> &sol) {
char ch;
std::cin >> ch;
std::set<int> aux;
if (ch == '*') {
n++;
sol.insert(n);
} else if (ch == '(') {
readcircuit(sol);
char op;
std::cin >> op;
if (op == 'S') {
while (op != ')') ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;double x,e=0;string s;cin>>N;
for(int i=0;i<N;i++){
cin>>x>>s;
if(s=="JPY")e+=x;
else e+=380000*x;
}
cout<<e<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k = 0;
char c;
while ((c = getchar()) != EOF) {
if (c < 32) continue;
int p = 0, t = c;
for (int i = 0; i < 8; i++) {
p = p * 2 + t % 2;
t /= 2;
}
cout << (k - p + 256) % 256 << endl;
k = p;
}
k = k;
}
| 3 |
#include <iostream>
using namespace std;
#include <string>
int main(){
int hcount = 0 , bcount = 0;
string r , a;
while(1){
cin >> r >> a;
if( r == "0" && a == "0" ) break;
for( int i = 0; i < 4; i++ ){
for( int j = 0; j < 4; j++ ){
if( i == j && r[i] == a[j] ) hcount++;
else... | 0 |
// CGL_3_B.cpp
//
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
bool EQ(double a, double b){return fabs(a-b) < EPS;}
typedef complex<double> Point;
#define X real()
#define Y imag()
namespace std {
bool operator == (const Point &a, const Point &b) {
return EQ(a.X, b.X) && EQ(a.Y, b.Y);
... | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ll n;
cin>>n;
ll sum=0;
map<ll,ll>m;
ll a[n];
for(int i=0;i<n;i++)
cin>>a[i],m[a[i]]++,sum+=a[i];
int q;
cin>>q;
while(q--)
{
ll x,b;
cin>>x>>b;
int fr=m[x];
sum-=(fr*x);
m[x]=0;
sum+=(fr*b);
m[b]+=fr;
cout<<s... | 0 |
#include <bits/stdc++.h>
using namespace std;
int test(int a, int b, int n) {
int step = 0;
int total = 0;
int ne;
int cur;
if (a < b) swap(a, b);
while (a != 1 && b != 1) {
ne = a % b;
if (!ne) return 0x7fffffff;
cur = (a - ne) / b;
step += cur;
++total;
a = ne;
swap(a, b);
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)2E9;
const long long MOD = (long long)1E9 + 7;
const double PI = acos(-1.0);
const double EPS = 1E-9;
int A[4];
vector<char> ans;
vector<int> ans2;
inline bool sama() {
for (int i = 0; i < 4; i++)
if (A[i] != 1) return false;
return true;
}
int ... | 3 |
#include<iostream>
#include<string>
using namespace std;
int main(){
int length=0, num=0, big=0, small=0;
string str;
cin >> str;
if(str.size() >= 6) length++;
for(int i = 0; i < str.size(); i++){
if(str[i] >= '0' && str[i] <= '9') num++;
else if(str[i] >= 'a' && str[i] <= 'z') small++;
else if(str[i] >=... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, t;
map<long long, map<int, long long> > mp;
long long gao(long long x, int ns) {
if (mp[x].find(ns) != mp[x].end()) return mp[x][ns];
if (ns == 0) return 1;
if (x == 0) return 0;
long long lx = x, tx = x;
while (tx) {
lx = tx & (-tx);
tx -= lx... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int f[20010][2], n, a, ans;
int main() {
ans = 0;
memset(f, 0, sizeof(f));
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a);
for (int j = 0; j <= 20000; j++) {
f[j][i & 1] = 0;
if (j >= a) f[j][i & 1] += f[j... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 3, mod = 1e9 + 7;
int n, m, f[maxn], ans[maxn], ps[maxn], pps[maxn], ted;
bool check[maxn];
string s, t, q;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> s >> t;
n = s.size();
m = t.size();
q = "";
for (int i = 0; i < m; i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> g(n + 1);
vector<int> a(n);
for (int i = 0; i < m; i++) {
int maxj = 0;
for (int j = 0; j < n; j++) {
cin >> a[j];
if (a[j] > a[maxj])
maxj = j;
else if (a[j] == a[maxj]) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
string a, b;
int count = 0;
vector<long long> v;
cin >> a >> b;
if (a.length() != b.length()) {
cout << "NO" << endl;
} else {
for (long long i = 0; i < a.length(); i++) {
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 55;
long long f[maxn][maxn][maxn][maxn];
long long pw[maxn];
int c[maxn];
void init() {
f[0][0][0][0] = 1;
pw[0] = 1;
for (int i = 1; i < maxn; i++) pw[i] = (pw[i - 1] * 2ll) % mod;
}
long long cal(int x, bool xx) { return x ?... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, pom;
cin >> n >> m;
vector<vector<int> > plus(m);
vector<vector<int> > minus(m);
for (int i = 0; i < m; i++) {
cin >> n;
for (int j = 0; j < n; j++) {
cin >> pom;
if (pom > 0)
plus[i].push_back(pom);
else
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, t, a, b, boths, alices, bobs, cnt[2], ans, res, tmp;
vector<int> both, alice, bob;
int main() {
ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> t >> a >> b;
if (a && b)
both.... | 5 |
#include <bits/stdc++.h>
int main() {
int t, i, a, j, done;
scanf("%d", &t);
for (i = 0; i < t; i++) {
scanf("%d", &a);
done = 0;
if (a < 60)
done = 0;
else {
for (j = 1; j <= 358; j++) {
if (180 * j == a * (j + 2)) {
done = 1;
break;
}
}
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long Ans, Res, Tmp, S[4][1005], ST[4], MaxS[4];
int N[4], D[4][1005], P[4][1005][12];
vector<int> E[1005];
void dfs(int n, int p, int t, int d) {
D[t][n] = d;
P[t][n][0] = p;
for (int v : E[n])
if (v != p) dfs(v, n, t, d + 1);
}
int lca(int t, int u, int v) {... | 5 |
#include "bits/stdc++.h"
using namespace std;
int x[55], y[55];
int main(int argc, char const *argv[])
{
int n;
cin >> n;
for(int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
map <pair <int, int>, int> mp;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(i != j) {
mp[make_pair(x[i] - x[j], ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1000000007;
struct Int {
int a;
Int(int _a = 0) : a(_a) {}
Int operator+(const Int& o) {
Int ret(a + o.a);
if (ret.a >= Mod) ret.a -= Mod;
return ret;
}
Int operator*(const Int& o) {
Int ret;
ret.a = (long long)a * o.a % Mod;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m,r;
cin >> n >> m;
vector<int> vec(n);
for(int i = 0;i<2*m;i++){
cin >> r;
vec[r-1] += 1;
}
for(int i :vec){
cout << i << endl;
}
} | 0 |
#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
int main(void) {
cin.tie(0);
ios::sync_with_stdio(fals... | 3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll h[200005],a[200005],dp[200005];
int n;
void go(ll i, ll v)
{
while(i<200005)
{
dp[i]=max(dp[i],v);
i+=i&-i;
}
}
ll query(int i)
{
ll ans=0;
while(i)
{
ans=max(ans,dp[i]);
i-=i&-i;
}
return ans;
}
int main()
{
cin>>n;
for(int i=0;i<... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[55], b[55];
int ct = 0, sum = 1;
gets(a);
gets(b);
for (int i = 0; i < strlen(b); i++) {
if (a[ct] == b[i]) {
ct++;
sum++;
}
}
printf("%d", sum);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
char a[101010], b[101010];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int T = 0, H = 0;
for (int i = 1; i <= n; i++)
if (a[i] == 'H')
H++;
else
T++;
int ans = 1000000000;
for (int i = 1; i <= n; i++) {
for (in... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e6;
const long long mod = 1e9 + 7;
const long double PI = 4 * atan((long double)1);
long long pw(long long a, long long b) {
return (!b ? 1
: (b & 1 ? a * pw(a * a % mod, b / 2) % mod
: pw(a * a % mod, b / 2) % mo... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2147483647;
const long long linf = 9223372036854775807;
void fileIO(string name) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
pair<int, int> mx[4][20];
int vi[100005];
void update(int i, int k, pair<int,... | 5 |
#include <bits/stdc++.h>
using namespace std;
int arr[11];
int main() {
int a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
arr[a]++;
arr[b]++;
arr[c]++;
arr[d]++;
arr[e]++;
arr[f]++;
int fc = 0, m = 0, n = 0, k = 0;
for (int i = 1; i <= 9; i++) {
if (arr[i] == 4)
fc++;
else if (a... | 1 |
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool getmin(T *a, const T &b) {
if (b < *a) {
*a = b;
return true;
}
return false;
}
template <class T>
inline bool getmax(T *a, const T &b) {
if (b > *a) {
*a = b;
return true;
}
return false;
}
template <class T>
inlin... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
pair<int, int> p[MAXN];
long long sum[MAXN];
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &p[i].second, &p[i].first);
}
sort(p + 1, p + 1 + n);
multiset<int> st;
long long now = 0;
... | 3 |
#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);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
bool customCompare(const pair<int, int> &a, const pair<int, int> &b) {
return a.first < b.first;
}
void solv... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5143;
const long long Linf = 1e18 + 5413;
template <class T>
inline void umax(T &a, T b) {
if (a < b) a = b;
}
template <class T>
inline void umin(T &a, T b) {
if (a > b) a = b;
}
template <class T>
inline T abs(T a) {
return a > 0 ? a : -a;
}
te... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, d, m, s = 0, x;
cin >> n >> d >> m;
vector<ll> a, b;
for (int i = 0; i < (n); i++) {
cin >> x;
if (x > m)
a.pu... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 111;
int a[N], n, c[10], g[10][10], was[10];
vector<int> b[10][10];
void dfs(int v) {
for (int i = 0; i <= 6; i++)
if (g[v][i]) g[v][i]--, g[i][v]--, dfs(i);
a[++a[0]] = v;
}
void dfs2(int v) {
was[v] = 1;
for (int i = 0; i <= 6; i++)
if (!was[... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, sum, a[1000], b[1000];
bool B[1005];
int main() {
string x;
cin >> x;
set<int> wow;
int sum = 0, sum_ = 0;
bool A = 1;
while (A) {
A = 0;
int l = 0, r = x.size() - 1;
while (l < r) {
while (x[l] != '(' || B[l] == 1) {
l++;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005, INF = 0x3f3f3f3f;
int ta, tb, n, T;
long long t[maxn], t1[maxn];
int main(void) {
cin >> n >> ta >> tb >> T;
string s;
char a;
cin >> a;
if (a == 'w') T -= tb;
T--;
if (T < 0) {
cout << 0 << endl;
return 0;
}
cin >> s;
fo... | 4 |
#include <bits/stdc++.h>
using namespace std;
void reverseQueue(queue<long long int>& q) {
if (q.empty()) return;
long long int data = q.front();
q.pop();
reverseQueue(q);
q.push(data);
}
int main() {
ios_base::sync_with_stdio(0);
int n, k;
cin >> n >> k;
vector<long long int> friends;
queue<long lo... | 2 |
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int exist[100000];
int main(){
while(true){
int m;
cin >> m;
if(m == 0){
break;
}
for(int i = 0; i < 10000; i++){
exist[i] = 0;
}
exist[0] = 1;
int a, b;
for(int loop = 0; loop <... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define N 100010
#define pb push_back
inline int read() {
int x=0;
char ch=getchar();
while (!isdigit(ch)) ch=getchar();
while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
return x;
}
char s[N];
vector<int> V[N],v[N];
int d[N],vis[N],val[N],dp[N],D;
inline ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
void solve() {
long long n;
cin >> n;
long long r1, p1, s1;
cin >> r1 >> s1 >> p1;
long long r2, p2, s2;
cin >> r2 >> s2 >> p2;
long long mn = max({r1 - r2 - p2, p1 - p2 - s2, s1 - s2 - r2, 0LL});
long long mx = min(r1, s2) + m... | 5 |
#include <bits/stdc++.h>
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
using namespace std;
typedef pair <int, int> pii;
int arr[301010], brr[301010];
vector <int> ta, tb;
map <int, vector <int> > g;
set <int> chk;
int dfs(int k) {
if(chk.find(k) != chk.end()) ret... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& s, vector<T>& v) {
s << '{';
for (int i = 0; i < v.size(); ++i) s << (i ? "," : "") << v[i];
return s << '}';
}
template <typename S, typename T>
ostream& operator<<(ostream& s, pair<S, T>& p) {
return s << "(" << p... | 2 |
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 1<<24;
const int pmax = 666001;
int rem[pmax];
int p, n[6], c[6] = { 1, 5, 10, 50, 100, 500 };
void rem_init() {
rem[0] = 0;
for ( int i = 1; i < pmax; i++ ) {
rem[i] = inf;
}
for ( int i = 0; i <= pmax; i++ ) {
for ( int j... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1000000007;
const int Nmax = 110;
long long Now, N, Pwr;
char X[Nmax];
int main() {
cin >> X;
N = strlen(X);
Pwr = 1LL;
Now = X[N - 1] - '0';
for (int i = N - 2; i >= 0; --i) {
Pwr = (1LL * Pwr * 4LL) % Mod;
Now = (1LL * Now * 2LL) % Mod;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846264338327950288419716939937510;
const double E = 2.7182818284590452353602874713526624977572470936999596;
const double eps = 0.000000001;
const int MOD = 998244353;
inline int max(int u, int v) { return u > v ? u : v; }
inline int min(... | 5 |
#include<bits/stdc++.h>
int main() {
long long N;
std::cin>>N;
std::cout<<N*(N-1)/2;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7;
int f[N];
int getp(string s) {
f[0] = 0;
for (int i = 1; i < (int)s.size(); ++i) {
int p = f[i - 1];
while (p && s[p] != s[i]) {
p = f[p - 1];
}
if (s[p] == s[i]) {
f[i] = p + 1;
} else {
f[i] = 0;
}
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
void solve() {
long long n;
cin >> n;
for (long long i = 1; i <= n; i++) {
if (i == 1)
cout << 2 << endl;
else
cout << i * (i + 1) * (i + 1) - (i - 1) << endl;
}
}
int main() {
ios::sync_with_... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
const int maxm = 1000000;
int a[15];
bool cmp(int t1, int t2) { return t1 > t2; }
int main() {
int tmp;
memset(a, 0, sizeof(a));
for (int i = 0; i < 6; i++) {
scanf("%d", &tmp);
a[tmp]++;
}
sort(a, a + 10, cmp);
if (a[0] >= 4) {
... | 1 |
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
string s;
cin>>n>>s;
if (n%2 == 0 && s.substr(0, n/2) == s.substr(n/2))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[1010];
int gcd(int a, int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
bool cmp(int a, int b) { return a < b; }
int main() {
int n, i, j;
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n, cmp);
for (i = 1, j = 0; i < n; i++) {
if (a... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long p = 998244353;
long long inv2 = (p + 1) / 2;
const long long maxn = 5e5 + 5;
vector<long long> a[maxn];
bool used[maxn];
long long dp[maxn][2];
long long po(long long a, long long b) {
if (b == 0) return 1;
if (b == 1) return a;
if (b % 2 == 0) {
l... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
int i;
int sum = 0;
int e = 0;
int z = 0;
cin >> s;
for (i = 0; i < s.length(); i++) {
if ((s[i] - '0') % 2 == 0) e++;
if ((s[i] - '0') == 0) z++;
sum = sum + (s[i] - '... | 1 |
#include<cstdio>
int main(){
char c;
scanf("%c", &c);
if(c=='a' || c=='i' || c=='u' || c=='e' || c=='o')
printf("vowel");
else
printf("consonant");
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int>> a;
vector<pair<int, int>> b;
int main() {
cin >> n;
int m, dem = 0;
for (int i = 1; i <= n; i++) {
cin >> m;
a.push_back(make_pair(i, m));
}
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
if (a[i].se... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 5;
struct node {
int prefmin, sufmax;
bool ok;
node() : prefmin(1e9), sufmax(0), ok(true) {}
node operator+(const node& oth) const {
node res;
res.prefmin = min(prefmin, oth.prefmin);
res.sufmax = max(sufmax, oth.sufmax);
res.o... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int pos;
int id;
} k[1000005];
bool cmp(node x, node y) { return x.pos < y.pos; }
int main() {
string s;
cin >> s;
int len = s.size();
int minn = 0;
int maxx = len;
for (int i = 1; i <= len; i++) {
k[i].id = i;
if (s[i - 1] == 'l') {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, MOD = 1e9 + 7, SQ = 450;
int m;
long long fac[N], inv[N];
int mark[N], dp[SQ][N], mx[SQ + 10];
string s;
long long pw(long long a, long long b) {
if (b == 0) return 1LL;
return pw(a * a % MOD, b / 2) * (b % 2 ? a : 1LL) % MOD;
}
inline long long c... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int dp[(1 << 21)][21];
int n;
int arr[1000001];
int power(int x, int y) {
if (y == 0) return 1;
int a = power(x, y / 2);
a = (1LL * a * a) % mod;
if (y % 2) a = (1LL * a * x) % mod;
return a;
}
int main() {
ios_base::sync_with_stdio(fals... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.