code1
stringlengths 54
12k
| code2
stringlengths 65
12k
| similar
int64 0
1
| __index_level_0__
int64 45
101M
|
---|---|---|---|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
int h,w,a,b;
cin >> h >> w >> a >> b;
for(int i = 0;i < h;i++){
for(int j = 0;j < w;j++){
if((i < b ^ j < a))cout << 0;
else cout << 1;
}
cout << endl;
}
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
int compute_cost(const std::vector<int> &arr, const int v)
{
int cost = 0;
std::for_each(arr.begin(), arr.end(), [&](const int a) {
cost += (v - a) * (v - a);
});
return cost;
}
int main()
{
int n;
std::cin >> n;
std::vector<int> arr;
arr.reserve(n);
for (int i = 0; i < n; ++i)
{
int tmp;
std::cin >> tmp;
arr.push_back(tmp);
}
const int sum = std::accumulate(arr.begin(), arr.end(), 0);
const double mean = sum / static_cast<double>(n);
const int cost1 = compute_cost(arr, static_cast<int>(std::floor(mean)));
const int cost2 = compute_cost(arr, static_cast<int>(std::ceil(mean)));
std::cout << std::min(cost1, cost2) << std::endl;
return 0;
} | 0 | 28,969,919 |
#include <iostream>
using namespace std;
int prime[1000010];
bool is_prime[1000010];
void seive(int n){
int p=0;
for(int i=0;i<=n;i++) is_prime[i]=true;
is_prime[0]=is_prime[1]=false;
for(int i=2;i<=n;i++){
if(is_prime[i]){
prime[p++]=i;
for(int j=2*i;j<=n;j+=i)
is_prime[j]=false;
}
}
}
int main() {
int n;
seive(999999);
while(cin>>n){
int sum=0;
for(int i=0;i<=n;i++)
if(is_prime[i])
sum++;
cout<<sum<<endl;
}
return 0;
} | #include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int dp[10010][10];
int cost[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> A;
int N, M;
int calc(int n, int m) {
if(n < 0) return -INF;
if(n == 0) return dp[n][m] = 0;
if(dp[n][m] != -1) return dp[n][m];
rep(i, M) {
int c = calc(n - cost[A[i]], A[i]);
dp[n][m] = max(dp[n][m], c + 1);
}
return dp[n][m];
}
void output(int n) {
if(n <= 0) return;
int len = -1;
int num = 0;
rep(i, M) {
if(n - cost[A[i]] >= 0 && len < dp[n - cost[A[i]]][A[i]]) {
len = dp[n - cost[A[i]]][A[i]];
num = A[i] + 1;
}
}
cout << num;
output(n - cost[num - 1]);
}
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N >> M;
rep(i, M) {
int a; cin >> a;
a--;
A.push_back(a);
}
sort(A.begin(), A.end(), greater<int>());
rep(i, 10010) rep(j, 10) dp[i][j] = -1;
rep(i, M) calc(N - cost[A[i]], A[i]);
output(N);
cout << endl;
return 0;
} | 0 | 91,459,873 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using P = pair<int, int>;
using ll = long long;
void solve()
{
string s;
cin >> s;
string ans = "";
rep(i, s.size())
{
if (s[i] == '0')
{
ans += "0";
}
else if (s[i] == '1')
{
ans += "1";
}
else
{
if (!ans.empty())
{
ans = ans.substr(0, ans.size() - 1);
}
}
}
cout << ans << endl;
}
int main()
{
solve();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int parent(int i){return i / 2;};
int left(int i){return 2 * i;};
int right(int i){return 2 * i + 1;};
int upper = 2000000;
int n = 0;
vector<int> a(upper + 1);
void maxHeap(vector<int> &a, int i){
int l = left(i);
int r = right(i);
int largest;
if(l <= n && a[l] > a[i]){
largest = l;
}else{
largest = i;
}
if(r <= n && a[r] > a[largest])largest = r;
if(largest != i){
swap(a[largest],a[i]);
maxHeap(a,largest);
}
}
void build(vector<int> &a){
for(int i = n / 2;0 < i;i--){
maxHeap(a,i);
}
}
void heap_increase(vector<int> &a,int i,int key){
if(key < a[i])return;
a[i] = key;
while(i > 1 && a[parent(i)] < a[i]){
swap(a[i],a[parent(i)]);
i = parent(i);
}
}
void insert(int key){
n++;
a[n] = -2100000000;
heap_increase(a,n,key);
}
int extract(){
if(n < 1)return -2100000000;
int maxi = a[1];
a[1] = a[n];
n--;
maxHeap(a,1);
return maxi;
}
int main(){
int key;
string s;
while(1){
cin >> s;
if(s[0] == 'e' && s[1] == 'n')break;
if(s[0] == 'i'){
cin >> key;
insert(key);
}else cout << extract() << endl;
}
} | 0 | 66,755,604 |
#include <iostream>
using namespace std;
int main()
{
int y;
long long int x = 1;
cin >> y;
while(y != 1)
{
x = x*y;
y--;
}
cout << x << endl;
} | #include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
vector<int> vi[maxii];
vector<int>:: iterator child;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
int arr[maxii];
int arr2[maxii];
bool check[maxii];
bool dfs(int node,int c)
{
check[node]=true;
arr2[node]=c;
for(int child=0;child<vi[node].size();child++)
{
if(check[vi[node][child]]==false)
{
if(dfs(vi[node][child],c^1)==false)
{
return false;
}
}
else if(arr2[node]==arr2[vi[node][child]])
{
return false;
}
}
return true;
}
int main()
{
int n,k,x,y;
cin>>n>>k>>x>>y;
if(n<=k)
{
cout<<n*x;
}
else
{
int res=k*x;
int res1=n-k;
res1=res1*y;
cout<<res+res1;
}
} | 0 | 25,168,078 |
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, a, b;
cin>>n>>a>>b;
if(a%2==0 && b%2==0 || a%2==1 && b%2==1)
cout<<"Alice";
else if(a%2==1 && b%2==0 || a%2==0 && b%2==1)
cout<<"Borys";
else
cout<<"Draw";
} | #include <bits/stdc++.h>
using namespace std;
# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;
int main() {
ll N;
cin >> N;
vector<ll> a(N);
REP(i, N) cin >> a[i];
ll ans = 0;
while(true){
sort(all(a), greater<>());
if(a[0] <= N - 1) break;
ll num = a[0] / N;
a[0] -= num * N;
REP(i, N - 1) a[i + 1] += num;
ans += num;
}
cout << ans << endl;
return 0;
} | 0 | 19,043,576 |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
using ll = long long;
#define INF 1000000000000000000
int main()
{
cin.tie(0);
ios::sync_with_stdio(0);
int n,m;cin>>n>>m;
vector<pair<int,int>> a(n),b(m);
for(int i=0;i<n;i++)
{
int ia,ib;cin>>ia>>ib;
a[i]=make_pair(ia,ib);
}
for(int i=0;i<m;i++)
{
int ic,id;cin>>ic>>id;
b[i]=make_pair(ic,id);
}
for(int i=0;i<n;i++)
{
int ans=0;
ll mindist=INF;
for(int j=0;j<m;j++)
{
ll dist=abs(a[i].fi-b[j].fi)+abs(a[i].se-b[j].se);
if(mindist>dist)
{
mindist=dist;
ans=j+1;
}
}
cout<<ans<<"\n";
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
int R, G, B, n; cin >> R >> G >> B >> n;int cnt = 0;
for(int i = 0; i <= 3500; i++) {
for(int j = 0; j <= 3500; j++) {
if(n - (i * R + j * G) < 0 || (n - (i * R + j * G)) % B)continue;
cnt++;
}
}
cout << cnt << endl;
} | 0 | 11,715,654 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> G(n,-1);
vector<vector<int>> vs(n);
int u,k,v;
for(int loop=0;loop<n;loop++){
cin >> u >> k;
for(int loop2=0;loop2<k;loop2++){
cin >> v;
vs[u-1].push_back(v-1);
}
}
queue<pair<int,int>> Q;
Q.push(make_pair(0,0));
G[0]=0;
int lk,dist;
while(!Q.empty()){
lk = Q.front().first;
dist = Q.front().second;
Q.pop();
for(int loop=0;loop<vs[lk].size();loop++){
if(G[vs[lk][loop]]==-1){
G[vs[lk][loop]]=dist+1;
Q.push(make_pair(vs[lk][loop],dist+1));
}
}
}
for(int loop=0;loop<n;loop++){
cout << loop+1 << " " << G[loop] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const ll LINF = 1LL<<60;
#define int long long
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m, X; cin >> n >> m >> X;
vector<int> c(n);
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n; i++) {
cin >> c[i];
for (int j = 0; j < m; j++) cin >> a[i][j];
}
int ans = LINF;
for (unsigned int x = 0; x < (1<<n); x++) {
int cost = 0;
vector<int> l(m, 0);
for (int i = 0; i < n; i++) {
if (x & (1<<i)) {
cost += c[i];
for (int j = 0; j < m; j++) l[j] += a[i][j];
}
}
bool ok = true;
for (auto j : l) if (j < X) ok = false;
if (ok) ans = min(ans, cost);
}
if (ans == LINF) cout << -1 << endl;
else cout << ans << endl;
return 0;
} | 0 | 697,945 |
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;
int main(){
int s; cin >> s;
int cnt = 0;
vector<int> a;
a.push_back(s);
while(true){
cnt++;
if(s % 2 == 0){
s /= 2;
}else{
s = 3*s + 1;
}
rep(i, a.size()){
if(a[i] == s) {
cout << cnt+1 << endl;
return 0;
}
}
a.push_back(s);
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, R;
cin>>n>>m>>R;
int r[R];
for (int i=0; i<R; i++) {
cin>>r[i];
--r[i];
}
int d[n][n];
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
if (i != j) {
d[i][j] = 1e9;
} else {
d[i][j] = 0;
}
}
}
for (int i=0; i<m; i++) {
int a, b, c;
cin>>a>>b>>c;
--a;
--b;
d[a][b] = c;
d[b][a] = c;
}
for (int k=0; k<n; k++) {
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
if (d[i][k] < 1e9 && d[k][j] < 1e9) {
d[i][j] = min(d[i][k] + d[k][j], d[i][j]);
}
}
}
}
sort(r, r + R);
int ans = 1e9;
do {
int tmp = 0;
for (int i=0; i<R-1; i++) {
tmp += d[r[i]][r[i+1]];
}
ans = min(tmp, ans);
} while (next_permutation(r, r + R));
cout<<ans<<endl;
} | 0 | 12,917,217 |
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
for (int i = 0; i < A.size(); i++)
os << A[i] << " ";
os << endl;
return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
int N = A.size();
int M;
if (N > 0)
M = A[0].size();
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
os << A[i][j] << " ";
os << endl;
}
return os;
}
typedef pair< int, int > pii;
typedef long long ll;
struct edge {
int from, to, d, c;
edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
from = _from;
to = _to;
d = _d;
c = _c;
}
bool operator<(const edge &rhs) const {
return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
}
};
typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
int to, cap, rev, cost;
flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;
const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);
template < typename T, typename U >
bool chmin(T &x, const U &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
struct initializer {
initializer() {
cout << fixed << setprecision(11);
}
};
initializer _____;
int N, M, K, T, Q;
signed main() {
cin >> N;
vector< int > A(N);
rep(i, N) cin >> A[i];
int k = 1;
int ans = 0;
rep(i, N) {
int a = A[i];
if (a == k)
++k;
else {
ans += (a - 1) / k;
A[i] -= (a - 1) / k * k;
if (A[i] == 1 && k == 1)
++k;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }
int n, m;
struct UnionFind {
vector<int> d;
UnionFind(int n=0): d(n,-1) {}
int find(int x) {
if (d[x] < 0) return x;
return d[x] = find(d[x]);
}
bool unite(int x, int y) {
x = find(x); y = find(y);
if (x == y) return false;
if (d[x] > d[y]) swap(x,y);
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x, int y) { return find(x) == find(y);}
int size(int x) { return -d[find(x)];}
};
int main() {
cin >> n >> m;
vector<int> P(n, 0);
for(int i = 0; i < n; ++i) {
cin >> P.at(i); P.at(i)--;
}
UnionFind tree(n);
for(int i = 0; i < m; ++i) {
int xx, yy; cin >> xx >> yy;
xx--; yy--;
tree.unite(xx, yy);
}
int ans = 0;
for(int i = 0; i < n; ++i) {
if(tree.same(i, P.at(i)))ans++;
}
cout << ans << endl;
} | 0 | 37,619,962 |
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
signed main(){
int n,m,x1,y1;
cin>>n>>m>>x1;
int ans1=0,ans2=0;
for(int i=0;i<n-1;i++){
int x2;
cin>>x2;
ans1=(ans1+(x2-x1)*(i+1)%mod*(n-1-i)%mod)%mod;
x1=x2;
}
cin>>y1;
for(int i=0;i<m-1;i++){
int y2;
cin>>y2;
ans2=(ans2+(y2-y1)*(i+1)%mod*(m-1-i)%mod)%mod;
y1=y2;
}
cout<<ans1*ans2%mod;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long A, B, C, K;
cin >> A >> B >> C >> K;
if (abs(A - B) >= pow(10, 18)) {
cout << "Unfair" << endl;
} else {
if (K % 2 == 1) {
printf("%lld\n", -(A - B));
} else {
printf("%lld\n", A - B);
}
}
return 0;
} | 0 | 96,871,165 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, k;
string s="";
cin>>n;
cin>>s;
cin>>k;
char ch = s[k-1];
for(int i=0;i<n;i++)
{
if(s[i]==ch)
cout<<s[i];
else if(s[i]!=ch)
cout<<"*";
}
cout<<endl;
return 0;
} | #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x)))
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
if (c >= '0' && c <= '9')
{
return c - '0';
}
return 0;
}
template <typename T>
T lcm(T x, T y)
{
T z = gcd(x, y);
return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
if (n < 2)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
double sqrtn = sqrt(n);
for (T i = 3; i < sqrtn + 1; i++)
{
if (n % i == 0)
{
return false;
}
i++;
}
return true;
}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int main()
{
cout << fixed << setprecision(30);
ll N, M;
cin >> N >> M;
bool check = true;
map<ll, ll> count;
loop(i, M)
{
ll x, y;
cin >> x >> y;
count[x]++;
count[y]++;
}
loop(i, N)
{
if (count[i + 1] % 2 == 1)
check = false;
}
if (check)
putout("YES");
else
putout("NO");
return 0;
} | 0 | 64,373,080 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int main(){
ll n,y; cin >>n >>y;
rep(i,n+1){
rep(j,n-i+1){
int k = n-i-j;
if(10000*i+5000*j+1000*k==y){
cout << i << " " << j << " " << k << endl;
return 0;
}
}
}
cout << -1 << " " << -1 << " " << -1 << endl;
return 0;
} | #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int dfs(vector<vector<int>> &A, vector<bool> &U, vector<int> &R, int c)
{
if (U[c])
return -1;
if (R[c])
return R[c];
U[c] = true;
int m = 0;
for (auto a: A[c]) {
int d = dfs(A, U, R, a);
if (d < 0) {
m = -2;
break;
}
m = max(m, d);
}
U[c] = false;
R[c] = ++m;
return m;
}
int main(int argc, char **argv)
{
int V, E;
cin >> V >> E;
vector<vector<int>> A(V);
for (int i = 0; i < E; i++) {
int s, t;
cin >> s >> t;
A[s].push_back(t);
}
bool cyc = false;
vector<bool> U(V);
vector<int> R(V);
for (int i = 0; i < V; i++) {
if (!R[i] && dfs(A, U, R, i) < 0) {
cyc = true;
break;
}
}
if (cyc) {
cout << "Found cyclic path" << endl;
return 0;
}
vector<int> P(V);
iota(P.begin(), P.end(), 0);
sort(P.begin(), P.end(), [&](int x, int y) { return R[x] > R[y]; });
for (auto p: P)
cout << p << endl;
return 0;
} | 0 | 24,485,916 |
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n; cin >> n;
long double res = 0;
for (int i=0; i < n; i++) {
long double x; cin >> x;
x = 1/x;
res += x;
}
long double nres = 1/res;
cout << nres;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define wi(t) int t;cin>>t;while(t--)
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
uniform_int_distribution<int> uid(0,lim-1);
return uid(rang);
}
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
vi g[N];
int a[N];
ll int gcd(ll int a, ll int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int tc=1;
void solve()
{
int n;
cin>>n;
string s;
cin>>s;
if(n&1==1)
{
cout<<"No";
return;
}
if(s.substr(0,n/2)==s.substr(n/2,n/2))
{
cout<<"Yes";
return;
}
else
{
cout<<"No";
return;
}
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
{
solve();
}
return 0;
}
int mpow(int base, int exp) {
base %= mod;
int result = 1;
while (exp > 0) {
if (exp & 1) result = ((ll)result * base) % mod;
base = ((ll)base * base) % mod;
exp >>= 1;
}
return result;
}
void ipgraph(int n, int m){
int i, u, v;
while(m--){
cin>>u>>v;
u--, v--;
g[u].pb(v);
g[v].pb(u);
}
}
void dfs(int u, int par){
for(int v:g[u]){
if (v == par) continue;
dfs(v, u);
}
} | 0 | 80,555,076 |
#include "bits/stdc++.h"
using namespace std;
#define long int64_t
int main() {
ios_base::sync_with_stdio( false );
int N, K;
cin >> N >> K;
cout << N-K+1 << endl;
return 0;
} | #define scanf_s scanf
#include <string>
#include <stdio.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
using namespace std;
#define MAX 450
int main(void)
{
int H, xk;
long long int Heaps[MAX + 1];
scanf_s("%d", &H);
for (int i = 1; i <= H; ++i) {
scanf_s("%d", &xk);
Heaps[i] = xk;
}
for (int i = 1; i <= H; ++i) {
printf("node %d: key = %lld, ", i, Heaps[i]);
if (i / 2 >= 1) printf("parent key = %lld, ", Heaps[i / 2]);
if (i * 2 <= H) printf("left key = %lld, ", Heaps[i * 2]);
if (i * 2 + 1 <= H) printf("right key = %lld, ", Heaps[i * 2 + 1]);
printf("\n");
}
} | 0 | 89,921,871 |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff first
#define ss second
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define testcase while(tc--)
#define in(x) ll x;cin>>x;
#define inst(str) string str;cin>>str;
#define out(x) cout<<x<<endl;
#define inputarray(arr,n) ll arr[n]; for(int i=0;i<n;i++) cin>>arr[i];
#define copinarray(arr,brr,n) ll arr[n];ll brr[n]; for(int i=0;i<n;i++){cin>>arr[i];brr[i]=arr[i];}
#define inputarray1(arr,n) ll arr[n+1]; arr[0]=0; fr(i,1,n) cin>>arr[i];
#define readv(vect,n) vector<int> vect(n); for(auto &i:vect) cin>>i;
#define lol cout<<"************\n";
#define deb(a) cout<<" :: "<<#a<<" = "<<a<<endl
#define deb2(a,b) cout<<" :: "<<#a<<" = "<<a<<" :: "<<#b<<" = "<<b<<endl
#define deb3(a,b,c) cout<<" :: "<<#a<<" = "<<a<<" :: "<<#b<<" = "<<b<<" :: "<<#c<<" = "<<c<<endl
#define amin(a,b) if(b<a) swap(a,b);
#define amax(a,b) if(b>a) swap(a,b);
#define three(a,b,c) int arr[3];arr[0]=a;arr[1]=b;arr[2]=c;sort(arr,arr+3);a=arr[0];b=arr[1];c=arr[2];
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define pb push_back
#define mkp make_pair
#define all(v) (v).begin(),(v).end()
#define pii pair<int, int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define Fill(vect,val) fill(vect.begin(),vect.end(),val)
#define ub upper_bound
#define lb lower_bound
#define len(arr) ((sizeof(arr))/(sizeof(arr[0])))
#define sz(x) ((long long)x.size())
#define make_unique(arr) arr.erase(unique(arr.begin(),arr.end()),arr.end())
#define int long long
#define frf for(ll i=0;i<n;i++)
#define frr for(ll i=n-1;i>=0;i--)
#define fr(a,b,c) for(ll a=b; a<=c; a++)
#define rf(a,b,c) for(ll a=b;a>=c;a--)
#define rep(a,b,c) for(ll a=b; a<c; a++)
#define printarray(arr) cout<<"PRINT ARRAY"<<endl; rep(i,0,len(arr)) cout<<arr[i]<<" "; cout<<endl;
#define printvector(vect) cout<<"PRINT VECTOR"<<endl; for(auto x:vect) cout<<x<<" "; cout<<endl;
#define rev(x) reverse(all(x))
#define gcd(m,n) __gcd(m, n)
#define set_mat(arr,rows,columns,val) for(ll i=0;i<rows;i++) for(ll j=0;j<columns;j++) arr[i][j]=val;
#define take_mat(arr,rows,columns) for(ll i=0;i<rows;i++) for(ll j=0;j<columns;j++) cin>>arr[i][j];
#define print_mat(arr,rows,columns) for(ll i=0;i<rows;i++) {for(ll j=0;j<columns;j++) cout<<arr[i][j]<<" "; cout<<endl;}
#define ps(n,points) cout<<fixed<<setprecision(points)<<n<<endl
#define dist(it,vect) distance(vect.begin(),it)
#define pq priority_queue<int>
#define pqa priority_queue<int,vector<int>,greater<int>>
#define M 1000000007
#define mod 998244353
#define endl '\n'
#define negmod(x,m) ((x)%(m)+(m))%(m)
typedef long long ll;
typedef unsigned long long ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ull countBits(ull n){ull count=0;while(n){count++;n>>=1;}return count;}
void cc()
{
fast
#ifndef ONLINE_JUDGE
if(fopen("input.txt","r"))
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
#endif
}
template<class T> ostream& operator<<(ostream &os, vector<T> vect) {
os<<"PRINT VECTOR\n";
for(auto x:vect) os <<x<< " ";
return os << "";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
os << "{ ";
for(auto x:S) os<<x<<" ";
return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> p) {
return os << "(" << p.ff << "," << p.ss << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> mp) {
os << "PRINT MAP\n";
for(auto pp:mp) os<<"("<<pp.ff<<":"<<pp.ss<<")\n";
return os<<"";
}
int updiv(int a,int b)
{
if(a%b==0)
return (a/b);
else
return (a/b)+1;
}
int mymod(int x,int m)
{
if(x>0)
return x%m;
else
return negmod(x,m);
}
int binpow(int a, int b)
{
int res = 1;
while(b>0)
{
if(b&1)
res=res*a;
a=a*a;
b>>=1;
}
return res;
}
bool second_sort(const pii & lhs , const pii & rhs)
{
pii a,b;
a.ff=lhs.ss;
a.ss=lhs.ff;
b.ff=rhs.ss;
b.ss=rhs.ff;
return a<b;
}
bool scomp(pii a,pii b)
{
if(a.ss==b.ss)
return (a.ff<b.ff);
else
{
return (a.ss>b.ss);
}
}
int power(int x, unsigned int y, int p=M)
{
int res = 1;
x=x%p;
if(x==0)
return 0;
while(y>0)
{
if(y&1)
res=(res*x)%p;
y=y>>1;
x=(x*x)%p;
}
return res;
}
int32_t main()
{
cc();
int tc=1;
testcase
{
in(n)inputarray(arr,n)
int sbit[64]={0},zbit[64]={0};
int x;
for(int i=0;i<n;i++)
{
x=arr[i];
int c=0;
while(x!=0)
{
if(x%2==1)
sbit[c]++;
x/=2;
c++;
}
}
int ans=0,temp1,temp2;
for(int i=0;i<64;i++)
{
zbit[i]=n-sbit[i];
temp1=((sbit[i]%M)*(zbit[i]%M))%M;
ans=((ans%M)+(temp1*(power(2,i)%M))%M)%M;
}
cout<<ans%M<<endl;
}
return 0;
} | #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;
#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define mkpr(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()
typedef long long int ll;
ll general,total;
ll num[ten5];
ll num2[ten5];
int main()
{
double ans=0.0,half,d,d1,d2;
string s,s1;
long long int sum,sum2,n1,n2,n3;
long long int m,n,o,i,j,k=1;
long long int a,a1,a2,a3,a4,a5,a6;
sum=sum2=n1=n2=n3=0;
a=a1=a2=a3=a4=a5=a6=0;
cin>>n;
for(i=0;i<n;i++)
{
cin>>m;
num[i]=m;
}
for(i=0;i<n;i++)
{
cin>>m;
num2[i]=m;
}
for(i=0;i<n;i++)
{
a=num[i]-num2[i];
if(a>0) sum2+=a;
else
{
a=abs(a);
if(a&1==1)
{
sum+=(a+1)/2;
sum2++;
}
else sum+=a/2;
}
}
if(sum2>sum) cout<<"No";
else cout<<"Yes";
return 0;
} | 0 | 38,198,012 |
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x) cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;
template<typename T>
void print(const vector<T> &x) {
int n = x.size();
rep(i,n) {
cout << x[i];
if (i!=n-1) cout<<" ";
else cout << endl;
}
}
template<typename T>
void print(const vector<vector<T>> &x) {
int n = x.size();
rep(i,n) {
rep(j,x[i].size()) {
cout << x[i][j] << " ";
}
cout << endl;
}
}
template<typename T>
void print(const vector<T> &x, int n) {
rep(i,n) {
cout << x[i];
if (i!=n-1) cout<<" ";
else cout << endl;
}
}
template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
rep(i,n) {
rep(j,m) {
cout << x[i][j] << " ";
}
cout << endl;
}
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void input_init() {
cin.tie(0); ios::sync_with_stdio(false);
}
int main(int argc, char const *argv[]) {
ll n; cin>>n;
ll ans = 0;
for (int a = 1; a < n; ++a) {
ll b = (n-1)/a;
ans += b;
}
cout << ans << '\n';
return 0;
} | #include <iostream>
#include <set>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
template <typename Container, class T>
bool contains(const Container& c, T v)
{
return std::find(c.begin(), c.end(), v) != c.end();
}
template <typename C>
void print_container(const C &c, const std::string &name)
{
std::cout << name << ": ";
std::for_each(c.cbegin(), c.cend(),
[](auto &x) { std::cout << x << ", "; });
std::cout << std::endl;
}
class EdgeInfo {
public:
EdgeInfo(int cap): cap_(cap), orig_cap_(cap) {}
int cap_;
int orig_cap_;
};
class Edge {
public:
Edge(unsigned int s, unsigned int t, EdgeInfo ei):
s_(s), t_(t), ei_(ei) {}
unsigned int s_, t_;
EdgeInfo ei_;
};
class Graph {
public:
using Edges = std::map<unsigned int, EdgeInfo>;
Graph(unsigned int n_v);
bool add_edge(unsigned int from,
unsigned int to,
EdgeInfo ei);
void show() const {
for(auto it = edges_.begin(); it != edges_.end(); it++) {
auto idx = std::distance(edges_.begin(), it);
std::for_each(it->begin(), it->end(),
[idx](auto& item) -> void
{
std::cout << idx << ","
<< item.first << ","
<< item.second.cap_
<< std::endl;
});
}
}
unsigned int n_v_;
std::vector<Edges> edges_;
};
Graph::Graph(unsigned int n_v)
: n_v_(n_v)
{
edges_.resize(n_v);
}
bool Graph::add_edge(
unsigned int from,
unsigned int to,
EdgeInfo ei)
{
if(from >= n_v_ || to >= n_v_ ||
edges_[from].find(to) != edges_[from].end()) {
std::cout << "add_edge failed: " << from << ", " << to << std::endl;
return false;
}
edges_[from].insert(std::make_pair(to, ei));
return true;
}
bool
_find_path_dfs(
unsigned int s, unsigned int t,
Graph &g, std::vector<bool> &seen,
std::vector<unsigned int> &route)
{
Graph::Edges edges = g.edges_[s];
seen[s] = true;
route.push_back(s);
if(s == t) return true;
for(auto it = edges.begin(); it != edges.end(); it++) {
if(seen[it->first] == true) continue;
if(it->second.cap_ > 0 &&
_find_path_dfs(it->first, t, g, seen, route)) {
return true;
}
}
route.pop_back();
return false;
}
bool find_path_dfs(
unsigned int s, unsigned int t,
Graph &g,
std::vector<unsigned int> &route)
{
std::vector<bool> seen(g.n_v_);
return _find_path_dfs(s, t, g, seen, route);
}
bool
_find_path_dfs(
unsigned int s, const std::vector<unsigned int> &ts,
Graph &g, std::vector<bool> &seen,
std::vector<unsigned int> &route)
{
Graph::Edges edges = g.edges_[s];
seen[s] = true;
route.push_back(s);
if(contains(ts, s)) return true;
for(auto it = edges.begin(); it != edges.end(); it++) {
if(seen[it->first] == true) continue;
if(it->second.cap_ > 0 &&
_find_path_dfs(it->first, ts, g, seen, route)) {
return true;
}
}
route.pop_back();
return false;
}
bool find_path_dfs(
unsigned int s, const std::vector<unsigned int> &ts,
Graph &g,
std::vector<unsigned int> &route)
{
std::vector<bool> seen(g.n_v_);
return _find_path_dfs(s, ts, g, seen, route);
}
void update_residual_graph(
Graph &g,
std::vector<unsigned int> &route)
{
int flow = -1;
bool flow_set = false;
auto frm = *(route.begin());
for(auto to = route.begin() + 1;
to != route.end(); to++) {
if(flow_set) {
flow = std::min(flow, g.edges_[frm].at(*to).cap_);
} else {
flow = g.edges_[frm].at(*to).cap_;
flow_set = true;
}
frm = *to;
}
frm = *(route.begin());
for(auto to = route.begin() + 1;
to != route.end(); to++) {
g.edges_[frm].at(*to).cap_ -= flow;
g.edges_[*to].at(frm).cap_ += flow;
frm = *to;
}
}
void _get_connected_component_dfs(
unsigned int s,
Graph &graph,
std::vector<unsigned int> &components,
std::vector<bool> &seen)
{
Graph::Edges edges = graph.edges_[s];
seen[s] = true;
components.push_back(s);
for(auto it = edges.begin(); it != edges.end(); it++) {
if(seen[it->first] == true) continue;
if(it->second.cap_ > 0) {
_get_connected_component_dfs(it->first, graph, components, seen);
}
}
}
void get_connected_component(
unsigned int s,
Graph &graph,
std::vector<unsigned int> &components)
{
std::vector<bool> seen(graph.n_v_);
_get_connected_component_dfs(s, graph, components, seen);
}
void _get_min_cut_dfs(
unsigned int s,
Graph &graph,
std::vector<unsigned int> &components,
std::vector<Edge> &edges_cut,
std::vector<bool> &seen)
{
Graph::Edges edges = graph.edges_[s];
seen[s] = true;
for(auto it = edges.begin(); it != edges.end(); it++) {
if(seen[it->first] == true) continue;
if(it->second.cap_ > 0) {
_get_min_cut_dfs(it->first, graph, components,
edges_cut, seen);
}
if(std::find(components.begin(), components.end(), it->first)
== components.end()) {
auto &ei = graph.edges_[it->first].at(s);
auto orig_cap = graph.edges_[s].at(it->first).orig_cap_;
if(ei.cap_ > 0 && orig_cap > 0) {
edges_cut.push_back(Edge(s,
it->first,
orig_cap));
}
}
}
}
void get_min_cut(
unsigned int s,
Graph &graph,
std::vector<unsigned int> &components,
std::vector<Edge> &edges_cut)
{
std::vector<bool> seen(graph.n_v_);
_get_min_cut_dfs(s, graph, components, edges_cut, seen);
}
struct XY {
XY(int x_, int y_):
x(x_), y(y_) {}
int x;
int y;
std::string toString() const {
return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
}
friend std::ostream& operator<<(std::ostream &os, const XY &rhs) {
os << rhs.toString();
return os;
}
};
inline bool operator==(const XY &lhs, const XY &rhs) {
return lhs.y == rhs.y && lhs.x == rhs.x;
}
inline bool operator!=(const XY &lhs, const XY &rhs) {
return !(lhs == rhs);
}
inline bool operator<(const XY &lhs, const XY &rhs) {
return lhs.y < rhs.y && lhs.x < rhs.x;
}
void add_edge(
unsigned int s, unsigned int t, int cap,
Graph &g)
{
g.add_edge(s, t, cap);
g.add_edge(t, s, 0);
}
int main()
{
unsigned int N;
std::cin >> N;
Graph graph(2 + 2 * N);
const unsigned int SRC = 0, TGT = 2*N + 1;
std::vector<XY> reds, blues;
for(unsigned int i=0; i<N; i++) {
int x; std::cin >> x;
int y; std::cin >> y;
reds.push_back(XY(x, y));
add_edge(SRC, i+1, 1, graph);
}
for(unsigned int i=0; i<N; i++) {
int x; std::cin >> x;
int y; std::cin >> y;
XY xy(x, y);
blues.push_back(xy);
for(unsigned int j=0; j<N; j++) {
if(reds[j] < xy) {
add_edge(j+1, N+1+i, 1, graph);
}
}
add_edge(N+1+i, TGT, 1, graph);
}
std::vector<unsigned int> ts = {TGT};
std::vector<unsigned int> route;
while(find_path_dfs(SRC, ts, graph, route)) {
update_residual_graph(graph, route);
route.clear();
}
std::vector<unsigned int> components;
get_connected_component(SRC, graph,
components);
std::vector<Edge> edges_cut;
get_min_cut(SRC, graph, components, edges_cut);
std::cout << edges_cut.size() << std::endl;
return 0;
} | 0 | 78,828,891 |
#include<bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ll long long
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
ll tot=0;
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
tot+=a[i]*a[j];
}
}
cout<<tot;
return 0;
} | #include <stdio.h>
int main() {
int Zx, count = 0;
int count1, count2;
char Yz[104] = {};
scanf("%d %s", &Zx, &Yz);
if (Zx % 2 != 0) {
printf("No");
return 0;
}
int haafu = Zx / 2;
for (int u = 0; u < haafu; u++) {
if (Yz[u] == Yz[u + haafu]) {
count++;
}
}
count == haafu ? printf("Yes") : printf("No");
return 0;
} | 0 | 16,251,169 |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long int lld;
#define sq(x) x*x
#define fr(i,m,n) for(i=m;i<n;i++)
#define vec vector<int>
#define sint set<int>
#define qint queue<int>
#define mip map<int,int>
#define pint priority_queue<int>
#define pb push_back
#define pp pop_back()
#define ft first
#define sd second
#define full(v) v.begin(),v.end()
int main()
{
int i,j,k,a,b,c,x,y,z,n,m,t;
string s,u,v;
cin>>s;
if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;
#define MAX 1000000007
class Calc_Mod{
public:
unsigned int mod=1000000007;
ll plus_mod(ll a,ll b){
return (a+b)%mod;
}
ll minus_mod(ll a,ll b){
return (a-b)%mod;
}
ll multi_mod(ll a,ll b){
return a*b%mod;
}
ll LSM(ll a,int b){
queue<int> q;
while(b>=1){
q.push(b%2);
b/=2;
}
ll ans=1;
while(!q.empty()){
if(q.front()==1){
ans=multi_mod(ans,a);
}
a=multi_mod(a,a);
q.pop();
}
return ans;
}
ll div_mod(ll a,ll b){
return multi_mod(a,LSM(b,mod-2));
}
ll combi(ll a,ll b){
ll ans=1;
ll kaijo=1;
rep(i,b){
ans=multi_mod(ans,a-i);
kaijo=multi_mod(kaijo,b-i);
}
ans=div_mod(ans,kaijo);
return ans;
}
};
int main()
{
ll a,b;
cin >> a >> b;
bool flag=false;
bool flag_3=false;
if(a%2==0){
flag=true;
}
if(flag==false&&a!=1){
flag_3=true;
}
ll num;
int dist;
ll ans;
if(flag==true){
num=(b-a)/4;
num=a+4*num;
ans=num;
dist=(b-a)%4;
rep(i,dist){
ans^=(num+i+1);
}
}
else{
if(flag_3==false){
num=(b-a)/3;
num=a+3*num;
dist=(b-a)%3;
ans=num;
rep(i,dist){
ans^=(num+i+1);
}
}else{
num=(b-a)/4;
num=a+4*num;
dist=(b-a)%4;
ans=a;
rep(i,dist){
ans^=(num+i+1);
}
}
}
cout << ans << endl;
} | 0 | 52,682,519 |
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
int main(){
ll A, B, C;
cin >> A >> B >> C;
if(A == B)
cout << C << endl;
else if(B == C)
cout << A << endl;
else
cout << B << endl;
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main(){
string S;
cin >> S;
if (S.size() < 5){
printf("NO\n");
}else{
int p = S.size() - 1;
while (p >= 4){
if (S.substr(p - 4, 5) == "dream" || S.substr(p - 4, 5) == "erase"){
p -= 5;
}else if (S.substr(p - 5, 6) == "eraser"){
p -= 6;
}else if (S.substr(p - 6, 7) == "dreamer"){
p -= 7;
}else{
break;
}
}
if (p==-1){
printf("YES\n");
}else{
printf("NO\n");
}
}
} | 0 | 58,655,052 |
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
vector<int> done(n, 0);
for (int i=0; i<n; i++) {
cin >> a[i];
}
int acount = 0;
int now = 1;
while(true) {
if (done[now-1] == 1) {
cout << -1 << endl;
return 0;
}
done[now-1] = 1;
now = a[now-1];
acount++;
if (now == 2) {
cout << acount << endl;
return 0;
}
}
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
struct WarshallFloyd {
vector<int> a,b,c;
int V,E;
int INF;
vector<vector<int> > dist;
WarshallFloyd(int V, int E):V(V),E(E){
INF = 2e9;
a.resize(E,INF);
b.resize(E,INF);
c.resize(E,INF);
dist.resize(V, vector<int>(V, INF));
}
void calc(){
for(int i=0;i<V;i++){
dist[i][i]=0;
}
for(int i=0;i<E;i++){
dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
}
for(int k=0;k<V;k++){
for(int i=0;i<V;i++){
for(int j=0;j<V;j++){
if(dist[i][k]==INF||dist[k][j]==INF) continue;
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
}
};
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int V,E;
cin>>V>>E;
WarshallFloyd WF(V, E);
FOR(i,0,E){
cin>>WF.a[i]>>WF.b[i]>>WF.c[i];
}
WF.calc();
FOR(i,0,V){
if(WF.dist[i][i]<0){
cout<<"NEGATIVE CYCLE"<<endl;
return 0;
}
}
FOR(i,0,V) {
FOR(j,0,V) {
if(j) cout<<" ";
if(WF.dist[i][j]==2e9) cout<<"INF";
else cout<<WF.dist[i][j];
}
cout<<endl;
}
} | 0 | 11,104,445 |
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
int MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll lINF = 1LL << 60;
const int iINF = 1 << 29;
int main(void){
int n;
cin >> n;
vi a(10,0);
if(to_string(n)[1]!=to_string(n)[2]){
cout << "No" << endl;
return 0;
}
rep(i,4){
a[n%10] += 1;
n /= 10;
}
bool ans=false;
rep(i,10) if(a[i]>=3) ans = true;
cout << (ans ? "Yes" : "No") << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
ll n, l;
cin >> n >> l;
deque <ll> d;
rep(i, n) {
ll a;
cin >> a;
d.push_back(a);
}
ll res = 0;
rep(i, l+1) {
rep(j, i+1) {
deque <ll> sub_d = d;
vector <ll> u;
ll tmp = 0;
rep(k, j) {
if (sub_d.size()) {
tmp += sub_d.front();
u.push_back(sub_d.front());
sub_d.pop_front();
}
}
rep(k, i-j) {
if (sub_d.size()) {
tmp += sub_d.back();
u.push_back(sub_d.back());
sub_d.pop_back();
}
}
sort(u.begin(), u.end());
rep(k, l-i) {
if (k < u.size()) {
if (u.at(k) < 0) tmp -= u.at(k);
}
}
res = max(res, tmp);
}
}
cout << res << endl;
} | 0 | 1,811,748 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int main(){
string str;
while(1){
cin >> str;
if(str=="0") break;
ll int sum = 0;
REP(i,str.size()){
sum += (int)(str[i]-'0');
}
cout << sum << endl;
}
} | #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);
using namespace std;
namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;
int main(){
cin.tie(0); cin.sync_with_stdio(0);
ll k; cin >> k;
int n = 50, d = k % n;
vector<ll> v(n);
rep(i, n){
if(i < d) v[i] = n + k / n;
else v[i] = n - 1 - d + k / n;
}
cout << n << endl;
rep(i, n) cout << v[i] << (i==n-1?"\n":" ");
return 0;
} | 0 | 94,522,561 |
#include <bits/stdc++.h>
#define st first
#define nd second
using namespace std;
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
const int N = 333;
int n, f[N], a[N], mx;
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
mx = max(a[i], mx);
f[a[i]]++;
}
int l = -1, r = -1;
int mn = (mx + 1) / 2;
for(int i = 0; i < mn; i++) if(f[i])
return cout << "Impossible\n", 0;
if(mx % 2 == 1) {
if(f[mn]!= 2)
return cout << "Impossible\n", 0;
} else {
if(f[mn]!= 1)
return cout << "Impossible\n", 0;
}
for(int i = mn + 1; i <= mx; i++)
if(f[i] < 2)
return cout << "Impossible\n", 0;
cout << "Possible\n";
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ii pair<int ,int >
#define S second
#define F first
#define PI 3.1415926535897932384626
#define SPEED std::ios_base::sync_with_stdio(false);
int main(){
SPEED
string s;
cin>>s;
int n = s.size();
for(int i=0;i<n-1;i++){
if(s[i]==s[i+1]){
cout<<i+1<<" "<<i+2;
return 0;
}
if(i<n-2){
if(s[i]==s[i+2]){
cout<<i+1<<" "<<i+3;
return 0;
}
}
}
cout<<-1<<" "<<-1;
} | 0 | 33,211,152 |
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
# include <intrin.h>
# define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (1LL << 31) - 1;
const ll mod = 1e9 + 7;
ll H, W, D,Q;
vector<pair<ll,pair<ll,ll>>> A;
ll B[100000];
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> H >> W >> D;
A.resize(H*W);
ll idx = 0;
FOR(i, 0, H)FOR(j, 0, W) {
cin >> A[idx].first;
A[idx].second.first = i;
A[idx].second.second = j;
idx++;
}
sort(A.begin(), A.end());
for (int i = 0; i + D < H * W; i++) {
B[A[i].first]
= abs(A[i].second.first - A[i + D].second.first) + abs(A[i].second.second - A[i + D].second.second);
}
FOR(i, D+1, H*W + 1) {
B[i] += B[i - D];
}
cin >> Q;
FOR(i, 0, Q) {
ll L, R; cin >> L >> R;
ll ans = 0;
if(L>D)cout << B[R-D]-B[L-D] << endl;
else if(R>D)cout << B[R-D] << endl;
else cout << 0 << endl;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
void chmax(ll& a, ll b) { a = max(a, b); }
void chmin(ll& a, ll b) { a = min(a, b); }
int main() {
int n,m; cin >> n >> m;
int i = 0;
if(n%2 == 1) {
for(int l=1, r=n-1; l < r; l++, r--) {
if(i >= m) break;
printf("%d %d\n", l, r);
i++;
}
} else {
bool flag = false;
for(int l=1, r=n-1; l < r; l++, r--) {
if(i >= m) break;
if(r-l <= n/2 && !flag) {
l++;
flag = true;
}
printf("%d %d\n", l, r);
i++;
}
}
return 0;
} | 0 | 52,434,519 |
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>
using namespace std;
typedef long long ll;
#define endl '\n'
template<typename T>
inline bool chmin(T& x, T a) {
if (x >= a) { x = a; return true; }
return false;
}
template<typename T>
inline bool chmax(T& x, T a) {
if (x <= a) { x = a; return true; }
return false;
}
int main() {
ios::sync_with_stdio(false);
std::cin.tie(0);
int N, M; cin >> N >> M;
vector<int> v(N);
for (int i = 0; i < M; i++) {
int a, b; cin >> a >> b;
v[a - 1]++;
v[b - 1]++;
}
bool f = true;
for (int i = 0; i < N; i++) {
if (v[i] % 2 == 1) { f = false; }
}
if (f) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef struct Point{
double x;
double y;
}P;
void koch(P p1, P p2, int i, int n){
if(n == 0){
printf("%.8f %.8f\n", p1.x, p1.y);
return;
}
P s, u, t;
double th = M_PI * 60.0 / 180.0;
s.x = (2 * p1.x + 1 * p2.x) / 3;
s.y = (2 * p1.y + 1 * p2.y) / 3;
t.x = (1 * p1.x + 2 * p2.x) / 3;
t.y = (1 * p1.y + 2 * p2.y) / 3;
u.x = s.x + (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th);
u.y = s.y + (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th);
if(i < n-1){
koch(p1, s, i+1, n);
koch(s, u, i+1, n);
koch(u, t, i+1, n);
koch(t, p2, i+1, n);
}else{
printf("%.8f %.8f\n", p1.x, p1.y);
printf("%.8f %.8f\n", s.x, s.y);
printf("%.8f %.8f\n", u.x, u.y);
printf("%.8f %.8f\n", t.x, t.y);
}
return;
}
int main(){
int n;
cin >> n;
P pst = {0.0, 0.0};
P pen = {100.0, 0.0};
koch(pst, pen, 0, n);
printf("%.8f %.8f\n", pen.x, pen.y);
return 0;
} | 0 | 8,568,327 |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }
template<class T> T factorial(T n){ return n ? n * factorial(n-1) : 1; }
int main()
{
ll n;
cin >> n;
cout << factorial(n) << endl;
} | #include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
int main () {
int n ;
cin >> n ;
vector<string> s (n) ;
rep(i, n){
cin >> s[i] ;
}
rep(i, n){
sort(s[i].begin(), s[i].end()) ;
}
sort(s.begin(), s.end()) ;
string first = s[0] ;
ll num = 0 ;
ll ans = 0 ;
rep(i, n){
if(first == s[i]){
num++ ;
}
else if(i != n -1) {
first = s[i] ;
ans += num*(num-1)/2 ;
num = 1 ;
}
if(i == n -1) {
ans += num*(num-1)/2 ;
}
}
cout << ans << endl ;
} | 0 | 4,877,025 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
int n, k;
cin >> n >> k;
int v[n];
rep(i, n) cin >> v[i];
int ans = 0;
for (int a = 0; a <= min(n, k); ++a) {
for (int b = 0; b <= min(n, k) - a; ++b) {
vector<int> g;
int now = 0;
rep(i, a) {
g.push_back(v[i]);
now += v[i];
}
rep(i, b) {
g.push_back(v[n - i - 1]);
now += v[n - i - 1];
}
sort(g.begin(), g.end());
int res = k - (a + b);
int m = g.size();
rep(i, min(res, m)) {
if (g[i] > 0) break;
now -= g[i];
}
ans = max(ans, now);
}
}
cout << ans << endl;
return 0;
} | #include <iostream>
using namespace std;
#define INPUT_MIN 0
#define INPUT_MAX 100
int main()
{
int a = 0, b = 0, c = 0;
cin >> a;
cin >> b;
cin >> c;
if( (INPUT_MIN > a) || (INPUT_MAX < a) )
{
return 1;
}
if( (INPUT_MIN > b) || (INPUT_MAX < b) )
{
return 1;
}
if( (INPUT_MIN > c) || (INPUT_MAX < c) )
{
return 1;
}
if(a >= c)
{
cout << "No" << endl;
}
else if( (a >= b) || (c <= b) )
{
cout << "No" << endl;
}
else
{
cout << "Yes" << endl;
}
return 0;
} | 0 | 69,999,912 |
#include<iostream>
using namespace std;
int main(void)
{
int n,b,f,r,v,A[4][3][10],i;
cin >> n;
for(b=0;b<4;b++){
for(f=0;f<3;f++){
for(r=0;r<10;r++){
A[b][f][r]=0;
}
}
}
for(i=1;i<=n;i++){
cin >> b >> f >> r >> v;
A[b-=1][f-=1][r-=1]+=v;
}
for(b=0;b<4;b++){
for(f=0;f<3;f++){
for(r=0;r<10;r++){
cout << " " << A[b][f][r];
}
cout << endl;
}
if(b==3)break;
cout << "####################" << endl;
}
return 0;
} | #include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define REP(i, n) for(ll i = 0; i < n; i++)
int main(){
constexpr const int MAX_N = 300000;
int n;
scanf("%d", &n);
int a[MAX_N], c[MAX_N + 1] = {};
for(int i = 0; i < n; i++){
scanf("%d", &a[i]);
c[a[i]]++;
}
int d[MAX_N + 1] = {};
for(int i = 0; i <= n; i++){
d[c[i]]++;
}
ll r1[MAX_N + 1] = {};
int r2[MAX_N + 1] = {};
for(ll i = 1; i <= n; i++){
r1[i] += r1[i - 1];
r1[i] += i * d[i];
r2[i] += r2[i - 1];
r2[i] += d[i];
}
auto f = [&](ll x) -> int {
return (r1[x] + x * (r2[n] - r2[x])) / x;
};
int ans = n;
for(int i = 0; i < n; i++){
while(ans > 0 && i + 1 > f(ans)) ans--;
printf("%d\n", ans);
}
} | 0 | 68,107,502 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
#define int ll
int n, q, k;
vector<vector<pll>> G;
int dis[100010];
void dfs(int v, int p, int d){
dis[v] = d;
for(auto nv : G[v]){
if(nv.first == p) continue;
dfs(nv.first, v, d + nv.second);
}
}
signed main(){
cin >> n;
G.resize(n);
int a, b, c;
for (int i = 0; i < n - 1; ++i) {
cin >> a >> b >> c;
a--; b--;
G[a].push_back(pii(b, c));
G[b].push_back(pii(a, c));
}
cin >> q >> k;
k--;
dfs(k, -1, 0);
vector<int> x(q), y(q);
for (int i = 0; i < q; ++i) {
cin >> x[i] >> y[i];
x[i]--; y[i]--;
}
for (int i = 0; i < q; ++i) {
cout << dis[x[i]] + dis[y[i]] << endl;
}
} | #include "bits/stdc++.h"
#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}
using namespace std;
using ll = long long;
constexpr ll atcoder_mod = 1e9+7;
template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}
void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout<<fixed<<setprecision(10);
int N=in();
string S=in<string>();
string WS[8];
REP(i,8) WS[i].resize(N,'_');
REP(i,4) WS[i][0]='S';
if(S[0]=='o'){
WS[0][1]='S';
WS[0][N-1]='S';
WS[1][1]='W';
WS[1][N-1]='W';
REP(i,2) WS[i+2].clear();
}
else{
WS[2][1]='S';
WS[2][N-1]='W';
WS[3][1]='W';
WS[3][N-1]='S';
REP(i,2) WS[i].clear();
}
REP(i,4) WS[i+4][0]='W';
if(S[0]=='x'){
WS[4][1]='S';
WS[4][N-1]='S';
WS[5][1]='W';
WS[5][N-1]='W';
REP(i,2) WS[i+6].clear();
}
else{
WS[6][1]='S';
WS[6][N-1]='W';
WS[7][1]='W';
WS[7][N-1]='S';
REP(i,2) WS[i+4].clear();
}
for(int i=1;i<N-2;i++){
REP(j,8){
if(WS[j].empty()) continue;
if(S[i]=='o'){
if(WS[j][i]=='S') WS[j][i+1]=WS[j][i-1];
else if(WS[j][i]=='W') WS[j][i+1]=WS[j][i-1]=='W'?'S':'W';
}
else{
if(WS[j][i]=='W') WS[j][i+1]=WS[j][i-1];
else if(WS[j][i]=='S') WS[j][i+1]=WS[j][i-1]=='W'?'S':'W';
}
}
}
for(int i=N-2;i<N;i++){
REP(j,8){
if(WS[j].empty()) continue;
if(S[i]=='o'){
if(WS[j][i]=='S'){
if((WS[j][i-1]=='S' && WS[j][(i+1)%N]=='W') || (WS[j][i-1]=='W' && WS[j][(i+1)%N]=='S')){
WS[j].clear();
}
}
else if(WS[j][i]=='W'){
if((WS[j][i-1]=='S' && WS[j][(i+1)%N]=='S') || (WS[j][i-1]=='W' && WS[j][(i+1)%N]=='W')){
WS[j].clear();
}
}
}
else{
if(WS[j][i]=='S'){
if((WS[j][i-1]=='S' && WS[j][(i+1)%N]=='S') || (WS[j][i-1]=='W' && WS[j][(i+1)%N]=='W')){
WS[j].clear();
}
}
else if(WS[j][i]=='W'){
if((WS[j][i-1]=='S' && WS[j][(i+1)%N]=='W') || (WS[j][i-1]=='W' && WS[j][(i+1)%N]=='S')){
WS[j].clear();
}
}
}
}
}
for(auto& x:WS){
if(!x.empty()){
out(x);
return 0;
}
}
out(-1);
return 0;
} | 0 | 6,207,374 |
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);
int main() {
int N;
cin>>N;
int d[N];
for(int i=0;i<N;++i) cin>>d[i];
int ans = 0;
for(int i=0;i<N;++i) {
for(int j=i+1;j<N;++j) {
ans += d[i]*d[j];
}
}
cout<<ans<<endl;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 4;
int n;
pair<int, int> a[MAXN];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 0;i < n;i ++)
cin >> a[i].first, a[i].second = i;
sort(a, a + n);
int ans = 0;
for( int i = 0; i < n; i ++){
if( (a[i].second % 2) != (i % 2))
ans ++;
}
cout << ans/2 << endl;
return 0;
} | 0 | 98,781,038 |
#include <iostream>
using namespace std;
int main()
{
int A, B;
cin >> A >> B;
if (A > 8 || B > 8) {
cout << ":(\n";
}
else {
cout << "Yay!\n";
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
vector<bool> s(200100);
vector<bool> t(200100);
bool ok=false;
int n,m;
cin >> n >> m;
rep(i,m){
int a,b;
cin >> a >> b;
if(a==1) s[b] = true;
if(b==n) t[a] = true;
}
for(int i=1; i<=n; i++){
if(s[i] == true && t[i] == true) ok=true;
}
if(ok) cout << "POSSIBLE" << endl;
else cout << "IMPOSSIBLE" << endl;
return 0;
} | 0 | 29,837,921 |
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vin=vector<int>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
int main() {
vin a(5);
rep(i,5) cin>>a[i];
int ans=0;
int mn=10;
rep(i,5){
ans+=(a[i]+9)/10*10;
if(a[i]%10!=0)
mn=min(mn,a[i]%10);
}
cout<<ans-10+mn<<endl;
} | #include<bits/stdc++.h>
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;
const int MOD = 1000000007;
const int inf = 1e8;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
using vs = vector <string>;
using vvs = vector <vs>;
int main(){
stack <int> st;
int n;
while(cin >> n){
if(n)
st.push(n);
else{
cout << st.top() << endl;
st.pop();
}
}
} | 0 | 64,863,308 |
#include<iostream>
#include<vector>
using namespace std;
int main(){
int n,m;
cin>>n;
vector<int>a(n);
if(n%2==0){
for(int i=0;i<n;i++){
cin>>m;
if(i%2==1)a[n/2-i/2-1]=m;
if(i%2==0)a[n/2+i/2]=m;
}
}else{
for(int i=0;i<n;i++){
cin>>m;
if(i%2==0)a[n/2-i/2]=m;
if(i%2==1)a[n/2+i/2+1]=m;
}
}
for(int i=0;i<n;i++)cout<<a[i]<<" ";
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
int main() {
string s; ll k;
cin >> s >> k;
ll n = s.size();
ll ans = 0;
int cnt = 1;
rep(i,n-1) {
if (s[i] == s[i+1]) cnt++;
else break;
}
if (cnt == n) {
ans = n*k/2;
cout << ans << endl;
return 0;
}else {
rep(i,n-1) {
if (s[i] == s[i+1]) {ans++; s[i+1] = '#';}
}
ans *= k;
if (s[0] == s[n-1] && cnt % 2 == 1) ans += k-1;
}
cout << ans << endl;
return 0;
} | 0 | 29,132,099 |
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
const int INF = 1001001001;
int main(void){
int a, b, c, d;
cin >> a >> b >> c >> d;
if(abs(c-a) <= d|| (abs(b-a) <=d && abs(c-b) <= d)) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
map < int , int > me;
#define mod 1000000007
#define N 100005
#define MOD 1000000007
int fact[N], invfact[N];
int pow(int a, int b, int m)
{
int ans=1;
while(b)
{
if(b&1)
ans=(ans*a)%m;
b/=2;
a=(a*a)%m;
}
return ans;
}
int modinv(int k)
{
return pow(k, MOD-2, MOD);
}
void precompute()
{
fact[0]=fact[1]=1;
for(int i=2;i<N;i++)
{
fact[i]=fact[i-1]*i;
fact[i]%=MOD;
}
invfact[N-1]=modinv(fact[N-1]);
for(int i=N-2;i>=0;i--)
{
invfact[i]=invfact[i+1]*(i+1);
invfact[i]%=MOD;
}
}
int nCr(int x, int y)
{
if(y>x)
return 0;
int num=fact[x];
num*=invfact[y];
num%=MOD;
num*=invfact[x-y];
num%=MOD;
return num;
}
int32_t main() {
int n;
cin>>n;
vector < int > a(n+2);
int ending =0;
for(int i=1;i<=n+1;i++)
{
cin>>a[i];
if(me.find(a[i])==me.end())
me[a[i]]=i;
else
ending = i;
}
int x=n+1-ending;
int starting = me[a[ending]];
int other = n+1-ending;
other += starting-1;
precompute();
cout<<n<<endl;
for(int i=2;i<=n+1;i++)
{
int find=nCr(n+1,i);
int find2=nCr(other,i-1);
find-=find2;
find%=mod;
find+=mod;
find%=mod;
cout<<find<<endl;
}
return 0;
} | 0 | 1,567,298 |
#include<iostream>
using namespace std;
int main(){
int x, y;
int i = 1;
while(i <= 3000){
cin >> x >> y;
if((x == 0) && (y == 0)) break;
else if(x <= y) cout << x << " " << y << endl;
else cout << y << " " << x << endl;
i += 1;
}
return 0;
} | #include <stdio.h>
#include <string.h>
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int memo[100000]; for(int i=0;i<m;i++) memo[i]=0;
int ac=0,wa=0;
for(int i=0;i<m;i++)
{
int p;
char s[3];
scanf("%d%s",&p,s);
if(memo[p]!=-1)
if(strcmp(s,"WA")==0)
{
memo[p]++;
}
else
{
wa+=memo[p];
memo[p]=-1;
ac++;
}
}
printf("%d %d\n",ac,wa);
} | 0 | 43,950,338 |
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
#define FIN freopen("in.txt", "r", stdin);
const int MAXN = 105;
const int INF = 1e9+7;
int dis[MAXN];
vector<P> v[MAXN];
int n, m;
int d[MAXN][MAXN];
int a[MAXN][MAXN];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
for(int j =1; j <= n; j++)
{
a[i][j] = d[i][j] = INF;
}
}
for(int i = 0; i <= n; i++)
{
d[i][i] = a[i][i] = 0;
}
for(int i = 0 ; i< m; i++)
{
int u , v, w;
cin >> u >> v >> w;
a[u][v] = a[v][u] = d[u][v] = d[v][u] = w;
}
for(int k = 1; k <= n; k++)
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n ; j++)
{
if(i != j && i != k)
{
a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
}
}
}
}
int ans = 0;
for(int i = 1; i <= n; i++)
{
for(int j = i + 1; j <= n ;j++)
{
if(d[i][j] < INF && a[i][j] != d[i][j]) ans++;
}
}
cout << ans << endl;
} | #include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
using namespace std;
int main(){
int X,D;
cin >> X >> D;
int box[X][D];
for(int i = 0;i < X;i++){
for(int j = 0;j < D;j++){
cin >> box[i][j];
}
}
long long len = 0;
int ans = 0;
for(int i = 0;i < X;i++){
for(int j = i + 1;j < X;j++){
len = 0;
for(int l = 0;l < D;l++){
int diff = abs(box[i][l] - box[j][l]);
len += diff * diff;
}
for(int l = 0;l <= len;l++){
if(l*l == len){
ans++;
}
}
}
}
cout << ans << endl;
return 0;
} | 0 | 86,860,364 |
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <= n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = (1 << 30);
ld h, m,n, sum,d; string s, t;
const ll MOD= 1000000007;
const ld PI = acos(-1);
int main() {
cin >> n >> m >> d;
if (d == 0) cout << fixed << setprecision(10) << (n-d) * (m-1) / (n*n) << endl;
else cout << fixed << setprecision(10) << 2 * (n - d) *(m - 1)/ (n * n) << endl;
} | #include <bits/stdc++.h>
#include <type_traits>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
rep(i, (int)v.size()) {
if (i)
os << ",";
os << v[i];
}
os << "}";
return os;
}
template <typename T, size_t S> void printArray(const T (&array)[S]) {
for (auto val : array)
std::cout << val << ", ";
std::cout << "\n";
}
const int mod = 1e9 + 7;
const int inf = 1e9 + 5;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << std::setprecision(10);
string a, b; std::cin >> a >> b;
reverse(rng(b));
if (a == b)
std::cout << "YES" << "\n";
else
std::cout << "NO" << "\n";
} | 0 | 32,810,592 |
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 1e9+7;
const ll INF = 1LL<<40;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
int main(){
ll n,k,ans=0;
cin>>n>>k;
ll x=max(n,k);
if(n*k==1)cout<<1;
else if(n==1||k==1)cout<<x-2;
else cout<<(n-2)*(k-2);
} | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265358979323846
ll fac[MAX], finv[MAX], inv[MAX];
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
bool palindrome(string s){
bool flag=true;
rep(i,s.size()) if(s[i]!=s[s.size()-1-i]) flag=false;
return flag;
}
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll Len(ll n) {
ll s=0;
while(n!=0) s++, n/=10;
return s;
}
ll Sint(ll n) {
ll m=0,s=0,a=n;
while(a!=0) s++, a/=10;
for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
return m;
}
ll Svec(vector<ll> v){
ll n=0;
for(ll i=0;i<v.size();i++) n+=v[i];
return n;
}
ll GCD(ll a,ll b) {
return b ? GCD(b,a%b) : a;
}
ll LCM(ll a,ll b){
return a/GCD(a,b)*b;
}
ll Factorial(ll n){
ll m=1;
while(n>=1) m*=n,n--;
return m;
}
void runlength(string s,vector<pair<char,ll>> &p){
ll x=1;
if(s.size()==1){
p.push_back(pair<char,ll>(s[0],1));
}
for(ll i=0;i<s.size()-1;i++){
if(s[i]==s[i+1]){
x++;
if(i==s.size()-2){
p.push_back(pair<char,ll>(s[i],x));
}
}else{
p.push_back(pair<char,ll>(s[i],x));
x=1;
if(i==s.size()-2){
p.push_back(pair<char,ll>(s[s.size()-1],x));
}
}
}
}
ll COM(ll n,ll k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
string Toupper(string s){
string ans="";
rep(i,s.size()){
if('a'<=s[i] && s[i]<='z') ans+=(char)s[i]-32;
else ans+=s[i];
}
return ans;
}
string Tolower(string s){
string ans="";
rep(i,s.size()){
if('A'<=s[i] && s[i]<='Z') ans+=(char)s[i]+32;
else ans+=s[i];
}
return ans;
}
const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
vector<bool> isPrime(MAX_N+1,true);
for(int i=2;i<=MAX_N;i++){
if(isPrime[i]){
for(int j=2*i;j<=MAX_N;j+=i){
isPrime[j]=false;
}
}
}
return isPrime;
}
vector<pint> prime_factorize(ll n){
vector<pint> ans;
for(ll p=2;p<=sqrt(n);p++){
if(n%p!=0) continue;
ll cnt=0;
while(n%p==0){
n/=p;
cnt++;
}
ans.push_back(make_pair(p,cnt));
}
if(n!=1) ans.push_back(make_pair(n,1));
return ans;
}
int main() {
IOS;
ll n;
cin>>n;
vector<ll> a(n),b(n);
rep(i,n) cin>>a[i]>>b[i];
ll ans=0;
ans=-Svec(b);
vector<ll> v(n);
rep(i,n) v[i]=a[i]+b[i];
sort(ALL(v),greater<ll>());
rep(i,n){
if(i%2==0) ans+=v[i];
}
cout<<ans<<endl;
} | 0 | 98,674,029 |
#include <bits/stdc++.h>
using namespace std;
#define range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)
#define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
constexpr i32 mod = 1e9 + 7;
constexpr i32 inf = 1001001001;
constexpr i64 infll = 1001001001001001001ll;
constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1};
constexpr int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;
template <typename T = i64> T input() { T x; cin >> x; return x; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
void solver() {
int n, m;
cin >> n >> m;
vector< int > ks(m);
auto ss = make_vector(m, 0, 0);
range(i, 0, m) {
cin >> ks[i];
ss[i].resize(ks[i]);
cin >> ss[i];
}
vector< int > ps(m);
cin >> ps;
auto check = [&](int bit) {
range(i, 0, m) {
int cnt = 0;
for (auto s: ss[i]) {
if (bit & (1 << s - 1)) cnt += 1;
}
if (cnt % 2 != ps[i]) return 0;
}
return 1;
};
int ans = 0;
range(bit, 0, 1 << n) {
ans += check(bit);
}
cout << ans << endl;
}
signed main(int argc, char *argv[]) {
solver();
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
ll N, A, B;
cin >> N >> A >> B;
if(A*B < N || A+B > N+1) {cout << -1 << endl; exit(0);};
ll now = 0, rem = N-A;
rep(i, A){
int x = min(B, rem+1);
rem -= x-1;
rep3(j, now+x, now+1){
cout << j << endl;
}
now += x;
}
} | 0 | 32,112,481 |
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
int main() {
string S;
int w;
cin >> S >> w;
for (int i = 0; i < S.size(); i+=w) {
cout << S.at(i);
}
cout << endl;
} | #include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
int h, w, d;
cin >> h >> w >> d;
vector<P> a(h*w+1);
rep(i, h) {
rep(j, w) {
int x;
cin >> x;
a[x] = make_pair(i, j);
}
}
vector<int> b(h*w+1, 0);
for (int i = h * w + 1; i > 0; --i) {
if (i + d > h * w + 1) continue;
b[i] = abs(a[i].first - a[i + d].first) + abs(a[i].second - a[i + d].second) + b[i+d];
}
int q;
cin >> q;
rep(i, q) {
ll ans = 0;
int l, r;
cin >> l >> r;
cout << b[l] - b[r] << endl;
}
return 0;
} | 0 | 87,031,846 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, A;
cin >> N >> A;
int x = N%500;
if ( x > A) {
cout << "No" << endl;
}
if ( x <= A) {
cout << "Yes" << endl;
}
} | #include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
int main(){
int n;
string str;
cin >> n >> str;
vector<char> cs{str.at(0)};
int count=1;
for(int i=1; i<n; i++) {
if(cs.at(count-1)!=str.at(i)){
cs.push_back(str.at(i));
count++;
}
}
cout << cs.size() << endl;
} | 0 | 53,134,202 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, need=0;
cin >> N;
for (int i=0; i<N ;i++){
need+=i+1;
}
cout << need << endl;
} | # include <iostream>
# include <queue>
# include <climits>
using namespace std;
int H;
int W;
char A[1005][1005];
int counter=0;
int shortestpath[1005][1005];
bool visited[1005][1005];
int maximum=INT_MIN;
int dr[4]={1, -1, 0, 0};
int dc[4]={0, 0, -1, 1};
queue< pair<int, int> > starting;
bool inside (int row, int column)
{
if (row<0 || row>H || column<0 || column>W)
{
return false;
}
return true;
}
void bfs (queue< pair<int, int> > starting)
{
queue< pair<int, int> > q;
while (!starting.empty())
{
q.push(make_pair(starting.front().first, starting.front().second));
visited[starting.front().first][starting.front().second]=true;
starting.pop();
}
while (!q.empty())
{
pair<int, int> u=q.front();
q.pop();
for (int i=0; i<4; i++)
{
int nextrow=u.first+dr[i];
int nextcolumn=u.second+dc[i];
if (inside(nextrow, nextcolumn) && !visited[nextrow][nextcolumn])
{
shortestpath[nextrow][nextcolumn]=shortestpath[u.first][u.second]+1;
q.push(make_pair(nextrow, nextcolumn));
visited[nextrow][nextcolumn]=true;
}
}
}
}
int main()
{
cin>>H>>W;
for (int i=1; i<=H; i++)
{
for (int j=1; j<=W; j++)
{
cin>>A[i][j];
if (A[i][j]=='#')
{
starting.push(make_pair(i, j));
}
}
}
bfs(starting);
for (int i=1; i<=H; i++)
{
for (int j=1; j<=W; j++)
{
if (shortestpath[i][j]>maximum)
{
maximum=shortestpath[i][j];
}
}
}
cout<<maximum<<endl;
} | 0 | 42,786,413 |
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;
int main() {
ll n, k;
cin >> n >> k;
vector<ll> p(n), c(n);
rep(i,n) {
cin >> p[i];
p[i]--;
}
rep(i,n) cin >> c[i];
ll ans=-10e10;
rep(i,n) {
int v=i;
ll cycle_sum=0;
int cycle_cnt=0;
while(true) {
cycle_cnt++;
cycle_sum+=c[v];
v=p[v];
if(v==i) break;
}
ll path=0;
int cnt=0;
while(true) {
cnt++;
path+=c[v];
if(cnt>k) break;
int num=(k-cnt)/cycle_cnt;
ll score=path+max(0ll,cycle_sum)*num;
if(ans<score) ans=score;
v=p[v];
if(i==v) break;
}
}
cout << ans << endl;
} | #include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#define p(x) cout << "(" << x.first << "," << x.second << ")" << endl;
using namespace std;
const int MAX_H = 1005;
const int MAX_W = 1005;
char D[MAX_H][MAX_W];
bool visited[MAX_H][MAX_W];
int H, W, N;
int dx[] = { -1, 0, 1, 0 };
int dy[] = { 0, -1, 0, 1 };
typedef pair<int, int> PII;
typedef pair<PII, int> PIII;
typedef vector<PII> VII;
int bfs(PII from, PII to) {
queue<PIII> que;
memset(visited, false, sizeof(visited[0][0]) * MAX_H * MAX_W);
que.push(make_pair(from, 0));
while (!que.empty()) {
PIII p = que.front(); que.pop();
int d = p.second;
if (p.first == to) {
return d;
}
for (int k = 0; k < 4; k++) {
int i2 = p.first.first + dx[k];
int j2 = p.first.second + dy[k];
if (0 <= i2 && i2 < H && 0 <= j2 && j2 < W && D[i2][j2] != 'X' && !visited[i2][j2]) {
visited[i2][j2] = true;
que.push(make_pair(make_pair(i2, j2), d+1));
}
}
}
return -1;
}
int main() {
cin >> H >> W >> N;
VII pos(N+1);
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
char c;
cin >> c;
D[i][j] = c;
if (c == 'S') {
pos[0] = make_pair(i, j);
} else if (c > '0') {
pos[c - '0'] = make_pair(i, j);
}
}
}
int res = 0;
for (int i = 0; i < N; i++) {
res += bfs(pos[i], pos[i+1]);
}
cout << res << endl;
return 0;
} | 0 | 48,008,402 |
#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
int i,j,len,lenr,lenp;
string s,m,m2,n,m3,n2;
cin >> s;
len=s.size();
lenr=(len-1)/2;
m=s;
m2=s.substr(0,lenr);
n=m2;
m3=s.substr((len+3)/2-1,lenr);
n2=m3;
reverse(m.begin(), m.end());
reverse(n.begin(), n.end());
reverse(n2.begin(), n2.end());
if(s!=m || m2!=n || m3!=n2)
{
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v) \
cerr << #v ":[ "; \
for (auto macro_vi : v) { \
cerr << macro_vi << " "; \
} \
cerr << "]" << endl;
#define ddump(v) \
cerr << #v ":" << endl; \
for (auto macro_row : v) { \
cerr << "["; \
for (auto macro__vi : macro_row) { \
cerr << macro__vi << " "; \
} \
cerr << "]" << endl; \
}
using lint = long long;
const int INF = 1e9;
const lint LINF = 1e18;
const lint MOD = 1e9 + 7;
const double EPS = 1e-10;
int main() {
int N;
cin >> N;
vector<lint> A(N, 0);
rep(i, N) cin >> A[i];
vector<lint> L(N + 1, 0);
rep(i, N) L[i + 1] = L[i] + A[i];
map<lint, lint> mp;
for (int i = 0; i <= N; i++) {
mp[L[i]]++;
}
lint cnt = 0;
for (auto p : mp) {
lint x, c;
tie(x, c) = p;
dd(x, c);
cnt += c * (c - 1) / 2;
}
cout << cnt << endl;
return 0;
} | 0 | 78,837,354 |
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
int n,r,l;
cin >> n;
int ans=0;
rep(i,n){
cin >> r >> l;
ans+=l-r+1;
}
cout << ans;
return 0;
} | #include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>
int main() {
int a, p;
cin >> a >> p;
a *= 3;
a = a + p;
cout << a / 2;
return 0;
} | 0 | 64,727,899 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n, k; cin >> n >> k;
const int p = 200010;
vector<int> num(p,0);
for (int i = 0; i < n; i++) {
int a; cin >> a;
num[a]++;
}
sort(num.begin(), num.end(), greater<int>());
int ans = 0;
for (int i = k; i < p; i++) {
if (num[i] == 0) break;
ans += num[i];
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
using P = pair <int, int>;
ll mod = 1000000007;
ll ans = 1<<29;
int main() {
ll n,k;
cin>> n >> k;
vector<pair<ll,ll>> P (n);
rep(i,n){
cin >> P[i].first>>P[i].second;
}
sort(P.begin(),P.end());
ll sum = 0;
ll index;
rep(i,n){
sum +=P[i].second;
if(sum>=k) {
index = i;
break;
}
}
cout << P[index].first << endl;
} | 0 | 97,271,883 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int M, L;
M = N / 10;
L = N % 1000;
if (N % 1111 == 0) {cout << "Yes" << endl;}
else if (M % 111 == 0) {cout << "Yes" << endl;}
else if (L % 111 == 0) {cout << "Yes" << endl;}
else {cout << "No" << endl;}
} | #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
map<string,int>mp;
int n,m,ans=0;
string s,t;
cin >> n;
rep(i,n){
cin >> s;
mp[s]++;
}
cin >> m;
rep(i,m){
cin >> t;
mp[t]--;
}
for(auto i=mp.begin();i!=mp.end();i++)ans=max(ans,i->second);
cout << ans;
return 0;
} | 0 | 56,973,530 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int D;
cin >> D;
cout << "Christmas";
for (int i = D; i < 25; i++)
cout << " Eve";
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;
int main(){
ll A,B,K;
cin >> A >> B >> K;
if(A < K){
K-=A;
A=0;
if(B<K) B = 0;
else B-=K;
}
else A-=K;
cout << A << " " << B << endl;
} | 0 | 48,039,917 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
deque<int> b;
for(int i = 0; i < n; i++){
if(i % 2){
b.push_front(a[i]);
} else {
b.push_back(a[i]);
}
}
if(n % 2)
reverse(b.begin(), b.end());
for(auto x : b)
cout << x << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
int N; cin>>N;
vi C(N);
rep(i,0,N) cin>>C[i];
sort(ALL(C));
vi A(N-1),B(N-1);
int j=0;
rep(i,1,N-1){
if(C[i]>0) break;
A[j]=C[N-1];
B[j++]=C[i];
C[N-1]-=C[i];
}
rep(i,1,N-1){
if(C[i]>0){
A[j]=C[0];
B[j++]=C[i];
C[0]-=C[i];
}
}
A[N-2]=C[N-1];
B[N-2]=C[0];
cout<<C[N-1]-C[0]<<endl;
rep(i,0,N-1) cout<<A[i]<<" "<<B[i]<<endl;
} | 0 | 64,987,850 |
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
int main() {
int n, x = 0, y = 0;
cin >> n;
while (n--){
string s, t;
cin >> s >> t;
if (s < t) y += 3;
else if (s > t) x += 3;
else{ x++; y++;}
}
cout << x << " " << y << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
long long dp[100010];
long long h[100010];
template<class T> void chmin(T &a, T b) {
if (a>b) {
a = b;
}
}
template<class T> inline void chmax(T &a, T b) {
if (a<b) {
a = b;
}
}
int main() {
int n; cin >> n;
int m; cin >> m;
for (int i = 0; i < 100010; i++) {
dp[i] = -1;
}
int a[100010];
for (int i = 0; i < m; i++) {
cin >> a[i];
dp[a[i]] = -10;
}
dp[0] = 1;
for (int i = 1; i <= n; i++) {
if (dp[i] == -10) continue;
if (i == 1) dp[1] = 1;
if (dp[i-1]==-10 && dp[i-2]==-10) {
cout << 0 << endl;
return 0;
}
else if (dp[i-1] == -10) {
dp[i] = dp[i-2];
}
else if (dp[i-2] == -10) {
dp[i] = dp[i-1];
}
else dp[i] = (dp[i-1]+dp[i-2])%1000000007;
}
cout << dp[n] << endl;
} | 0 | 96,590,744 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll choose2(ll n){
return n*(n-1)/2;
}
int main(){
int n;
cin >> n;
vector<int> a(n);
rep(i,n) cin >> a[i];
rep(i,n) a[i]--;
vector<int> cnt(n);
rep(i,n) cnt[a[i]]++;
ll tot = 0;
rep(i,n){
tot += choose2(cnt[i]);
}
rep(i,n){
ll ans = tot;
ans -= choose2(cnt[a[i]]);
ans += choose2(cnt[a[i]]-1);
cout << ans << endl;
}
} | #include <iostream>
#include <stdlib.h>
#include <string.h>
#include <math.h>
using namespace std;
int main()
{
int n,d,a[20][20],i,j,k,sum,integer=0;
double sq;
cin>>n>>d;
for(i=0;i<n;i++)
{
for(j=0;j<d;j++)
{
cin>>a[i][j];
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
continue;
sum=0;
for(k=0;k<d;k++)
{
sum=sum+pow((a[i][k]-a[j][k]),2);
}
sq=sqrt(sum);
sq=sq/(int)sq;
if(sq==1)
integer++;
}
}
cout<<integer/2;
return 0;
} | 0 | 54,201,172 |
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main()
{
int n; cin >> n;
int ans = 0, inf = 1, sup = 10;
while(n >= sup){
ans += (sup - inf);
inf = inf * 100;
sup = sup * 100;
}
if(n >= inf) ans += (n - inf) + 1;
cout << ans << endl;
return 0;
} | #include<iostream>
using namespace std;
#include<vector>
#include<map>
#include<algorithm>
#define int long long int
#define inf 10000000000000000
#define mod 1000000007
void dfs(int src,vector<int> adj[],int p,int value,int dp[],int answer[])
{
value+=dp[src];
answer[src]=value;
for(int x:adj[src])
{
if(x!=p)
{
dfs(x,adj,src,value,dp,answer);
}
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,q;
cin>>n>>q;
int j;
vector<int> adj[n+1];
for(j=0;j<n-1;j++)
{
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
int dp[n+1]={0};
for(j=0;j<q;j++)
{
int x;
cin>>x;
int p;
cin>>p;
dp[x]+=p;
}
int answer[n+1]={0};
dfs(1,adj,-1,0,dp,answer);
for(j=1;j<=n;j++)
cout<<answer[j]<<" ";
cout<<endl;
} | 0 | 10,693,573 |
#include<iostream>
#include<math.h>
using namespace std;
int main(){
int N;
cin >> N;
int a[N], i, j, sum=0, avg, min;
double b[3], cost[3];
for (i=0; i<N; i++){
cin >> a[i];
sum += a[i];
}
for (j=0; j<3; j++){
cost[j] = 0;
}
avg = sum / N;
for (i=0; i<N; i++){
b[0] = (double)(a[i] - avg);
b[1] = (double)(a[i] - (avg + 1));
b[2] = (double)(a[i] - (avg - 1));
for (j=0; j<3; j++){
cost[j] +=pow(b[j], 2);
}
}
min = cost[0];
for (i=1; i<3; i++){
if (cost[i] < min){
min = cost[i];
}
}
cout << min;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
typedef long long ll;
int num(int a){
switch(a){
case 1:
return 2;
case 2:
return 5;
case 3:
return 5;
case 4:
return 4;
case 5:
return 5;
case 6:
return 6;
case 7:
return 3;
case 8:
return 7;
case 9:
return 6;
default:
return 0;
}
}
int main(void){
int n,m; cin >> n >> m;
vector<int> a(m); rep(i,m) cin >> a[i];
sort(a.begin(),a.end(),greater<int>());
vector<int> dp(n+1,-1);
dp[0] = 0;
for(int i = 1; i <= n; ++i){
rep(j,m){
if(i - num(a[j]) >= 0){
dp[i] = max(dp[i], dp[i-num(a[j])] + 1);
}
}
}
while(n >= 2){
rep(j,m) if((n - num(a[j]) >= 0) && (dp[n-num(a[j])] == dp[n]-1)){
cout << a[j];
n -= num(a[j]);
break;
}
}
} | 0 | 42,876,972 |
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int INF=1e18;
const int MOD=1e9+7;
signed main(){
int R,G,B,N;cin>>R>>G>>B>>N;
int ans=0;
REP(i,N/R+1){
REP(j,N/G+1){
if(N-R*i-G*j>=0&&(N-R*i-G*j)%B==0)ans++;
}
}
cout<<ans<<endl;
} | #define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define IREP(i, v) for(auto i = (v).begin(); i != (v).end(); ++i)
#define IRREP(i, v) for(auto i = (v).rbegin(); i != (v).rend(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(RALL(v))
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;
const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const ll LINF = 1000000000000000000;
const double EPS = 1E-10;
template<class T, class S>
bool chmax(T &a, const S &b){
if(a < b){
a = b; return true;
}
return false;
}
template<class T, class S>
bool chmin(T &a, const S &b){
if(b < a){
a = b; return true;
}
return false;
}
int gcd(int a, int b){
if(!b) return a;
if(a % b) return gcd(b, a % b);
return b;
}
int main(){
ll S; cin >> S;
ll x((INF - S%INF) % INF);
ll y((S+x)/INF);
cout << "0 0 " << INF << " 1 " << x << " " << y << endl;
return 0;
} | 0 | 42,551,624 |
#include <bits/stdc++.h>
using namespace std;
int numDigits(long long num) {
if (num == 0) {
return 1;
}
int r = 0;
do {
r++;
num /= 10;
} while (num != 0);
return r;
}
int helper(long long n) {
int r = numDigits(n);
for (long long i = 1; i * i <= n; i++) {
if (n % i == 0) {
r = min(r, numDigits(n / i));
}
}
return r;
}
int main() {
long long n;
cin >> n;
cout << helper(n) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define ll long long
int main(){
string s,t; cin >> s >> t;
sort(s.begin(),s.end());
sort(t.begin(),t.end());
map<char,int> smp,tmp;
map<int,int> sint,tint;
rep(i,s.size()) smp[s[i]]++;
rep(i,t.size()) tmp[t[i]]++;
for(auto itr=smp.begin();itr!=smp.end();++itr){
sint[itr->second]++;
}
for(auto itr=tmp.begin();itr!=tmp.end();++itr){
tint[itr->second]++;
}
for(auto itr=sint.begin();itr!=sint.end();++itr){
if(itr->second != tint[itr->first]){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
} | 0 | 92,482,870 |
#include <iostream>
#include <cmath>
#include <vector>
#include <utility>
using namespace std;
int main()
{
long long n;
cin >> n;
int res = 0;
for (int p = 2; p <= sqrt(n) + 1; p++)
{
if (n % p != 0)
continue;
int count = 0;
while (n % p == 0)
{
n /= p;
count++;
}
int i = 0;
int sum = 0;
while (sum <= count)
sum += ++i;
res += i - 1;
if (n == 1)
break;
}
if (n != 1)
res += 1;
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
struct TopologicalSort {
TopologicalSort () {}
TopologicalSort (int n) : n(n), G(n), used(n, 0) {}
int n;
vector<vector<int>> G;
vector<int> order, used;
void add_edge(int u, int v) {
G[u].push_back(v);
}
void dfs(int v) {
if (used[v]) return;
used[v] = true;
for (auto to : G[v]) dfs(to);
order.push_back(v);
}
void build() {
for (int i = 0; i < n; ++i) dfs(i);
reverse(order.begin(), order.end());
}
};
int main() {
int n, m;
cin >> n >> m;
TopologicalSort ts(n);
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
ts.add_edge(u, v);
}
ts.build();
for (int i = 0; i < n; ++i) {
cout << ts.order[i] << (i + 1 == n ? "\n" : " ");
}
} | 0 | 59,232,183 |
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
int main(){
string s1, s2, s3;
cin >> s1 >> s2 >> s3;
s1[0] -= 32;
s2[0] -= 32;
s3[0] -= 32;
cout << s1[0] << s2[0] << s3[0] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> prime;
int main() {
ll N;
cin >> N;
vector<ll> cnt;
for (ll i=1; i*i<=N; i++) {
if (N%i==0) {
cnt.push_back(i+N/i-2);
}
}
sort(cnt.begin(),cnt.end());
cout << cnt[0] << endl;
} | 0 | 30,042,497 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
int main(){
ll n, m; cin >> n >> m;
vector<ll> a(n);
for(int i = 0; i < n; i++) cin >> a[i];
vector<ll> sum(n+1);
for(int i = 0; i < n; i++) sum[i+1] = sum[i] + a[i];
unordered_map<ll, ll> mp;
for(int i = 0; i <= n; i++){
mp[sum[i]%m]++;
}
ll ans = 0;
for(auto p : mp){
ans += p.second * (p.second - 1) / 2;
}
cout << ans << endl;
} | #include <cassert>
#include "limits.h"
#include <limits>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<" "<< #i <<":"<< i << std::endl
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
return os << pa.first << " " << pa.second;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
long long pow_mod(long long a, long long b, long long mod=-1) {
if ((a == 0)||(mod!=-1&&a%mod==0)) {
return 0;
}
long long x = 1;
while (b > 0) {
if (b & 1) {
x = (mod!=-1)?(x * a) % mod:x*a;
}
a = (mod!=-1)?(a * a) % mod:a*a;
b >>= 1;
}
return x;
}
const long long MOD = 1e9 + 7;
using ll = long long;
using P = std::pair<long long,long long>;
std::vector<ll> topo_sort(std::vector<std::vector<ll>>& graph) {
ll n = graph.size();
std::vector<ll> ret, num(n, 0);
std::queue<ll> que;
for(ll i=0;i<n;i++){
for (ll j : graph[i]) num[j]++;
}
for (ll i = 0; i < n; i++) {
if (num[i] == 0) que.push(i);
}
while (!que.empty()) {
ll u = que.front();
que.pop();
ret.push_back(u);
for (ll i : graph[u]) {
num[i]--;
if (num[i] == 0) que.push(i);
}
}
return ret;
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
ll n;
std::cin>>n;
std::vector<std::vector<ll>> graph(n),directed(n);
rep(i,0,n-1){
ll a,b;
std::cin>>a>>b;
a--;b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
std::vector<bool> matching(n,false);
auto f=[&](auto f,ll now,ll par)->void{
for(ll e:graph[now]){
if(e==par)continue;
directed[now].push_back(e);
f(f,e,now);
}
};
f(f,0,-1);
std::vector<ll> topo=topo_sort(directed);
for(ll i=n-1;i>=0;i--){
ll now=topo[i];
for(ll next:directed[now]){
if(!matching[next]){
matching[now]=true;
matching[next]=true;
break;
}
}
}
bool ans=true;
rep(i,0,n)ans=(ans&matching[i]);
if(ans)std::cout<<"Second\n";
else std::cout<<"First\n";
return 0;
} | 0 | 20,646,714 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i*4+j*7==n){
cout << "Yes" << endl;
return 0;
}
}
}
cout << "No" << endl;
return 0;
} | #include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,m;
cin >>n>>m;
int c[m];
for(int i=0;i<m;i++){
cin>>c[i];
}
int l[n+1][m];
for(int i=0;i<=n;i++){
for(int j=0;j<m;j++){
if(i==0){
l[i][j]=0;
}else if(j==0){
if(c[0]>i){
l[i][j]=i;
}else{
l[i][j]=l[i-c[0]][j]+1;
}
}else if(c[j]>i){
l[i][j]=l[i][j-1];
}else{
l[i][j]=min(l[i][j-1],l[i-c[j]][j]+1);
}
}
}
cout << l[n][m-1]<<endl;
} | 0 | 34,701,452 |
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define n1 "\n"
#define B begin()
#define E end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define popb pop_back()
#define popf pop_front()
const int BIG=1e5+55;
const int BIGG=1e9+7;
const ll BIGGE=1e12+55;
const double SML=(1e-7);
using namespace std;
int a[5];
int main()
{
ios::sync_with_stdio(false); cin.tie(NULL);
cout.tie(NULL);
int n,cnt=1,i=0;
cin >>n;
while (n) {
i++;
int x = n % 10;
a[i] = x;
n /= 10;
if (i == 1)
continue;
if (x == a[i-1])
cnt++;
else
cnt = 1;
if (cnt >= 3) {
cout <<"Yes";
return 0;
}
}
cout <<"No";
return 0;
} | #include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())
#define mp make_pair
#define all(a) (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) {
if (b == 0) return a;
else return gcd(b, a % b);
}
ll keta(ll n){
string s = to_string(n);
ll num = s.size();
return num;
}
const ll INF = 1LL << 60;
const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};
struct Edge{
int to;
int weight;
Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;
class UnionFind{
public:
vi Parent;
UnionFind(int n){
Parent = vi(n,-1);
}
int root(int a){
if(Parent[a] < 0) return a;
else return Parent[a] = root(Parent[a]);
}
int size(int a){
return -Parent[root(a)];
}
bool merge(int a, int b){
a = root(a);
b = root(b);
if(a == b) return false;
if(size(a) < size(b)) swap(a,b);
Parent[a] += Parent[b];
Parent[b] = a;
return true;
}
};
class Factrial{
public:
vl Fac;
Factrial(int MAX){
Fac = vl(MAX+1);
rep(i,MAX) {
if(i == 0) Fac[i+1] = 1;
else Fac[i+1] = ((i+1)*Fac[i])%MOD;
}
}
};
int main(){
string A; cin >> A;
ll n = A.size();
map<char,int> C;
rep(i,n) C[A[i]]++;
ll ans = n*(n-1)/2 + 1;
for(auto c : C) {
ll num = c.second;
ans -= num*(num-1)/2;
}
cout << ans << endl;
} | 0 | 53,690,159 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin >> n >> k;
vector<int> x(n);
for(int i=0; i<n; i++){
cin >> x.at(i);
}
sort(x.begin(), x.end());
int sum=0;
for(int i=0; i<k; i++)
sum += x.at(i);
cout << sum << endl;
} | #include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;
ll H, W, D;
pll A[100010];
ll acc[100010];
signed main(){
cin >> H >> W >> D;
ll a;
REP(i, H){
REP(j, W){
cin >> a;
A[a] = pll(i, j);
}
}
REP(i, D){
ll x = i + 1;
while(x + D <= H * W){
acc[x + D] = acc[x] + abs(A[x + D].first - A[x].first) + abs(A[x + D].second - A[x].second);
x += D;
}
}
ll Q, L, R;
cin >> Q;
REP(i, Q){
cin >> L >> R;
PRINT(acc[R] - acc[L]);
}
return 0;
} | 0 | 55,915,308 |
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
ll x=0,f=1;char c=getchar();
while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
if (c=='-') f=-1,c=getchar();
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x*f;
}
int main(){
int n=read(),k=read();
printf("%d\n",n-k+1);
} | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << endl
#define RETURN(x) \
cout << x << endl; \
return 0
#define init() \
cin.tie(0); \
ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v) \
cerr << "[debugV] " << #v << ":"; \
rep(i, v.size()) cerr << " " << v[i]; \
cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
return to_string(x).size();
}
ll gcd(ll x, ll y) {
return y ? gcd(y, x % y) : x;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
vector<P> factorize(ll n) {
vector<P> result;
for (ll i = 2; i * i <= n; ++i) {
if (n % i == 0) {
result.pb({i, 0});
while (n % i == 0) {
n /= i;
result.back().second++;
}
}
}
if (n != 1) {
result.pb({n, 1});
}
return result;
}
vll divisor(ll n) {
vll ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n) ret.push_back(n / i);
}
}
SORT(ret);
return (ret);
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
signed main() {
init();
ll N, K;
cin >> N >> K;
map<ll, ll> m;
rep(i, N) {
ll a, b;
cin >> a >> b;
m[a] += b;
}
ll count = 0;
for (auto mm : m) {
count += mm.second;
if (count >= K) {
RETURN(mm.first);
}
}
return 0;
} | 0 | 85,095,680 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<pair<int, ll>>>;
const int INF = 1001001001;
ll h, w;
ll solve1(ll a){
ll res = h - a;
ll b = res/2, c = res - b;
return max(abs(a-b), max(abs(a-c), abs(b-c))) * w;
}
ll solve2(ll a){
ll res = h - a;
ll b = w/2, c = w - b;
return max(abs(a*w - res*b), max(abs(a*w - res*c), abs(res*b - res*c)));
}
int main(){
cin >> h >> w;
ll ans = INF;
for(ll a = 1; a <= h-1; a++){
ll tmp1 = solve1(a);
ll tmp2 = solve2(a);
ans = min(ans, min(tmp1, tmp2));
}
swap(h, w);
for(ll a = 1; a <= h-1; a++){
ll tmp1 = solve1(a);
ll tmp2 = solve2(a);
ans = min(ans, min(tmp1, tmp2));
}
cout << ans << endl;
} | #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;
int main() {
int N; scanf("%d", &N);
vector<ll> A(N);
ll sum = 0;
for(int i=0; i<N; i++) scanf("%lld", &A[i]), sum ^= A[i];
for(int i=0; i<N; i++) A[i] &= ~sum;
ll ans = sum;
vector<ll> base;
for(auto e : A) {
for(auto b : base) chmin(e, e ^ b);
if(e != 0) base.emplace_back(e);
}
ll x = 0;
for(auto e : base) chmax(x, x ^ e);
ans += (x << 1);
cout << ans << endl;
return 0;
} | 0 | 33,321,649 |
#include<bits/stdc++.h>
using namespace std;
int main() {
int h,w;
cin >> h >> w;
for (int i = 0;i < h*w;++i) {
string s;
cin >> s;
if (s == "snuke") {
char a = 'A';
a += i%w;
cout << a << i/w+1 << "\n";
break;
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005
int k;
int main()
{
_FastIO;
string s;
cin >> s;
int n = s.size();
int sum = 0;
for(int i = 0; i < n; i++){
if(int(s[i]) < 97)
sum++;
}
string ans = "AC";
if(sum == 2 && s[0] == 'A'){
ans = "AC";
}
else
ans = "WA";
sum = 0;
for(int i = 2; i < n - 1; i++){
if(s[i] == 'C')
sum++;
}
if(sum && ans == "AC")
cout << "AC" << endl;
else
cout << "WA" << endl;
return 0;
} | 0 | 78,497,068 |
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
int W, H; cin >> W >> H;
vector<pair<int, int>> A;
for (int i = 0; i < W; i++) {
int p; cin >> p;
A.emplace_back(p, 0);
}
for (int i = 0; i < H; i++) {
int q; cin >> q;
A.emplace_back(q, 1);
}
sort(begin(A), end(A));
Int ans = 0;
for (int i = 0; i < A.size(); i++) {
Int cost, axis; tie(cost, axis) = A[i];
if (axis == 0) {
if (W > 0) ans += cost * (H+1);
W--;
} else {
if (H > 0) ans += cost * (W+1);
H--;
}
}
cout << ans << '\n';
return 0;
} | #include <bits/stdc++.h>
#include <vector>
#include <string>
#include <iomanip>
#include <math.h>
#include <algorithm>
#define hmm "\n"
#define test() int t; cin>>t; while(t--)
#define ll long long int
#define ull unsigned long long
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
void solve()
{
ll n,m;
cin>>n>>m;
ll a[n],b[n];
for(int i=0; i<n; i++){
cin>>a[i];
b[i]=a[i]/2;
}
ll o=b[0];
for(int i=1; i<n; i++){
o=(o*b[i])/__gcd(o,b[i]);
}
for(int i=0; i<n; i++){
if(o%a[i] != b[i]){
cout<<"0\n";
return;
}
}
ll r= m/o;
cout<<(r+1)/2<<hmm;
}
int main()
{
fastIO
solve();
} | 0 | 56,451,049 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back
ll modpow(ll a, ll n, ll m)
{
if(n == 0) return 1;
ll t = modpow(a, n >> 1, m);
t = t * t % m;
if(n & 1) t = t * a % m;
return t;
}
int main()
{
string L;
cin >> L;
ll N = SZ(L);
L = "0" + L;
mat dp(N+1, vec(2, 0));
dp[0][0] = 1;
REP(i,1,N+1) {
if(L[i] == '0') {
dp[i][0] = dp[i-1][0] % MOD;
dp[i][1] = (dp[i-1][1] * 3) % MOD;
}
else {
dp[i][0] = (dp[i-1][0] * 2) % MOD;
dp[i][1] = (dp[i-1][0] + dp[i-1][1] * 3) % MOD;
}
}
PR((dp[N][0]+dp[N][1])%MOD);
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
vector<string> myhash(10000000);
void set(string& a){
int x = 0;
for(int i=0; i<a.size(); i++){
x *= 11;
x += a[i];
x %= 10000000;
}
while(true){
if(myhash[x].empty()){
myhash[x] = a;
break;
}
else if(myhash[x].compare(a)==0){
break;
}
else{
x++;
if(x > 10000000)
x -= 10000000;
}
}
}
void find(string& a){
int x = 0;
for(int i=0; i<a.size(); i++){
x *= 11;
x += a[i];
x %= 10000000;
}
while(true){
if(myhash[x].compare(a) == 0){
cout << "yes\n";
break;
}
else if(myhash[x].empty()){
cout << "no\n";
break;
}
else{
x++;
if(x > 10000000)
x -= 10000000;
}
}
}
int main(){
string a, b;
int n;
cin >> n;
while(n--){
cin >> a >> b;
if(a.compare("insert")==0)
set(b);
else
find(b);
}
return 0;
} | 0 | 75,181,080 |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int solve() {
}
int main() {
double x1,x2,y1,y2;
cin >> x1 >> y1 >> x2 >> y2;
printf("%.8lf\n",sqrt((x2-x1)*(x2-x1)+ (y2-y1)*(y2-y1)));
} | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323
template <class T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
T GCD(T a, T b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
return (a * b) / GCD(a, b);
}
using namespace std;
signed main() {
int a, b, m;
cin >> a >> b >> m;
vector<int> A(a);
vector<int> B(b);
rep(i, a) cin >> A[i];
rep(i, b) cin >> B[i];
vector<int> x(m);
vector<int> y(m);
vector<int> c(m);
rep(i, m) cin >> x[i] >> y[i] >> c[i];
int ans =
*min_element(A.begin(), A.end()) + *min_element(B.begin(), B.end());
rep(i, m) chmin(ans, A[x[i] - 1] + B[y[i] - 1] - c[i]);
cout << ans << endl;
} | 0 | 53,164,050 |
#include<iostream>
int main(){
int N, A;
std::cin >> N >> A;
std::cout << N*N - A;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define PI 3.14159265359
int main(){
int n, m, x, y; cin >> n >> m;
vector<int>xi(n+1);
vector<int>yi(m+1);
cin >> xi[0];
cin >> yi[0];
repr(i, 1, n+1) cin >> xi[i];
repr(i, 1, m+1) cin >> yi[i];
sort(all(xi));
sort(all(yi));
if(xi[n] >= yi[0]){
cout << "War" << endl;
}else{
cout << "No War" << endl;
}
return 0;
} | 0 | 73,606,630 |
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#include<vector>
#include<queue>
#include<bitset>
using namespace std;
#define LL long long
#define DB double
#define MOD 998244353
#define Pr pair<DB,int>
#define X first
#define Y second
#define MAXN 50
#define INF 20000000000000000LL
#define mem(x,p) memset(x,p,sizeof(x))
LL read(){
LL x=0,F=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
return x*F;
}
int add(int a,int b){return (a+b>=MOD)?a+b-MOD:a+b;}
int dec(int a,int b){return (a-b<0)?a-b+MOD:a-b;}
int mul(int a,int b){return 1LL*a*b%MOD;}
int n,t[MAXN+5],F,res;
string s[MAXN+5],x;
int main()
{
n=read();
for(int i=1;i<=n;i++)
cin>>s[i],t[i]=read();
cin>>x;
for(int i=1;i<=n;i++){
if(F)res+=t[i];
if(x==s[i])F=1;
}
printf("%d\n",res);
} | #include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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(b<a){ a=b; return 1; } return 0; }
using namespace std;
int main(){
Init();
string s; cin >> s;
ll n = s.size();
map<char, ll> cnt;
rep(i, n) cnt[s[i]]++;
ll ans = n*(n-1)/2;
for(char c='a'; c<='z'; c++){
if(cnt[c] <= 1) continue;
ans -= (cnt[c]*(cnt[c]-1))/2;
}
cout << ans+1 << endl;
} | 0 | 45,717,942 |
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)
int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};
typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;
const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
int n, m, R;
int r[10];
ll d[205][205];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m >> R;
REP(i, n) REP(j, n) d[i][j] = INF;
REP(i, R) cin >> r[i], r[i]--;
REP(i, m) {
ll a, b, c;
cin >> a >> b >> c;
a--;b--;
if(d[a][b] > c) d[a][b] = d[b][a] = c;
}
sort(r, r + R);
REP(k, n) REP(i, n) REP(j, n) {
if(d[i][j] > d[i][k] + d[k][j]) d[i][j] = d[i][k] + d[k][j];
}
ll ans = INF;
do {
ll sum = 0;
FOR(i, 1, R) sum += d[r[i - 1]][r[i]];
ans = min(ans, sum);
} while(next_permutation(r, r + R));
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n, m, a, b;
ll c;
cin >> n >> m;
vector<bool> vrow(n+1,0);
vector<vector<bool>> visited(n+1,vrow);
vector<vector<pair<int,ll>>> paths(n+1);
for (int i=0; i<m; i++) {
cin >> a >> b >> c;
paths[a].push_back(make_pair(b,c));
paths[b].push_back(make_pair(a,c));
}
priority_queue<pair<ll,int>> moves;
for (int i=1; i<=n; i++) {
vector<ll> dists(n+1,1000000000);
vector<vector<ll>> links(n+1);
dists[i] = 0;
moves.push(make_pair(0,i));
while (moves.size()>0) {
pair<ll,int> curr = moves.top();
moves.pop();
for (auto j : paths[curr.second]) {
if (-curr.first+j.second > dists[j.first]) continue;
if (-curr.first+j.second == dists[j.first]) {
links[j.first].push_back(curr.second);
continue;
}
links[j.first].clear();
links[j.first].push_back(curr.second);
dists[j.first] = -curr.first+j.second;
moves.push(make_pair(curr.first-j.second,j.first));
}
}
for (int j=1; j<=n; j++) for (auto k : links[j]) {
visited[k][j] = true;
visited[j][k] = true;
}
}
ll res = m*2;
for (auto i : visited) for (auto j : i) if (j) res--;
cout << res/2;
return 0;
} | 0 | 90,490,058 |
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <bitset>
#include <map>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
string result = "";
bool loopdfs(vector<int> & nums, int N, int sum) {
if (N == 4) {
if (sum != 7) return false;
result = "=7";
return true;
}
if (loopdfs(nums, N + 1, sum + nums[N])) {
result = to_string(nums[N]) + result;
if (N != 0) result = "+" + result;
return true;
}
if (loopdfs(nums, N + 1, sum - nums[N])) {
result = to_string(nums[N]) + result;
if (N != 0) result = "-" + result;
return true;
}
return false;
}
int main()
{
string S;
vector<int> nums(4);
cin >> S;
rep(i, 4) {
nums[i] = (int)(S[i] - '0');
}
loopdfs(nums, 0, 0);
cout << result << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
vector<int> g[100001];
int par[100001],dep[100001];
bool nroot[100001];
void dfs(int v,int p,int d){
par[v]=p,dep[v]=d;
rep(i,g[v].size()){
dfs(g[v][i],v,d+1);
}
}
int main(){
int n;
cin>>n;
int id,k,ci;
rep(i,n){
cin>>id>>k;
rep(i,k){
cin>>ci;
g[id].pb(ci);
nroot[ci]=true;
}
}
int root;
rep(i,n)if(!nroot[i]) root=i;
dfs(root,-1,0);
rep(i,n){
cout<<"node "<<i<<": parent = "<<par[i]<<", depth = "<<dep[i]<<", ";
if(root==i) cout<<"root";
else if(g[i].size()>0) cout<<"internal node";
else cout<<"leaf";
cout<<", [";
rep(j,g[i].size()) cout<<g[i][j]<<(j+1==g[i].size()?"":", ");
cout<<"]"<<endl;
}
return 0;
} | 0 | 56,307,425 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
void prime_factorization(ll N, map<ll, int>& res) {
if(N == 1 || N == 0) return;
ll n = N;
ll i = 2;
while(n >= i * i) {
while(n % i == 0) {
if(res.count(i)) res[i]++;
else res[i] = 1;
n /= i;
}
if(i == 2) i++;
else i += 2;
}
if(n != 1) res[n]++;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n; cin >> n;
ll ans = 0;
map<ll, int> res;
for(int i=1; i<=n; i++) {
prime_factorization(i, res);
}
map<int, int> cnt;
for(auto ele: res) {
cnt[ele.second]++;
}
int prev = 0;
for(auto itr=cnt.rbegin(); itr!=cnt.rend(); itr++) {
itr->second += prev;
prev = itr->second;
}
cnt[inf] = 0;
ans += cnt.lower_bound(4)->second * (cnt.lower_bound(4)->second-1) / 2 * (cnt.lower_bound(2)->second-2);
ans += cnt.lower_bound(24)->second * (cnt.lower_bound(2)->second-1);
ans += cnt.lower_bound(14)->second * (cnt.lower_bound(4)->second-1);
ans += cnt.lower_bound(74)->second;
cout << ans << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;
int table[101][101];
void init(){
REP(i,101){
REP(j,101){
table[i][j]=1e9;
if(i==j)table[i][j]=0;
}
}
}
int main(){
ios::sync_with_stdio(false);
int n;
cin >> n;
init();
int u,k,v;
REP(i,n){
cin >> u >> k;
REP(j,k){
cin >> v;
table[u-1][v-1]=1;
}
}
REP(k,n){
REP(i,n){
REP(j,n){
table[i][j]=min(table[i][j],table[i][k]+table[k][j]);
}
}
}
REP(i,n){
cout << i+1 << " " << ((table[0][i]<n)?table[0][i]:-1);
cout << endl;
}
} | 0 | 11,362,148 |
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
ll modexpo(ll a,ll b)
{
ll res=1LL;
while(b>0)
{
if(b&1)res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
int main()
{
ll x,y,a,b,c;
cin>>x>>y>>a>>b>>c;
ll p[a],q[b],r[c];
rep(i,a)cin>>p[i];
rep(i,b)cin>>q[i];
rep(i,c)cin>>r[i];
sort(p,p+a);sort(q,q+b);
reverse(p,p+a);reverse(q,q+b);
vector<ll> res;
for(int i=0;i<x;i++)res.push_back(p[i]);
for(int i=0;i<y;i++)res.push_back(q[i]);
for(int i=0;i<c;i++)res.push_back(r[i]);
sort(res.rbegin(),res.rend());
ll sum=0;
for(int i=0;i<x+y;i++)
sum+=res[i];
cout<<sum;
} | #include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;
int main()
{
int64 nn, kk;
cin >> nn >> kk;
vector<int64> hh(nn);
for(int64 ii = 0;ii < nn;ii++)
{
cin >> hh[ii];
}
sort(hh.begin(), hh.end());
auto ans = lower_bound(hh.begin(), hh.end(), kk);
cout << distance(ans, hh.end()) << endl;
return 0;
} | 0 | 70,960,958 |
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
const long long INF = 1e18;
int main() {
string S;
cin >> S;
ll sum = 0;
for(auto c : S) {
sum += (ll)(c - '0');
}
if(sum % 9 == 0) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;
int main(){
string S, S_; ll K; cin >> S >> K;
S_ = S;
ll ans = 0;
if((S.size() * K)%2 == 1){
bool flag = true;
for(int i = 1; i < S.size(); i++) if(S[i-1] != S[i]) flag = false;
if(flag){
cout << (ll)((ll)S.size() * K) / 2 << endl;
return 0;
}
}
for(int i = 1; i < S.size(); i++){
if(S[i-1] == S[i]) { S[i] = '*'; ans++;}
}
ans = ans * K;
if(S[0] == S[S.size()-1]) {
string temp1={S[0]}, temp2 = {S[S.size()-1]};
int i = 0, j = S.size()-1;
while(S_[i] == S_[i+1]){temp1+=S[i+1]; i++;}
while(S_[j] == S_[j-1]){temp2+=S[i+1]; j--;}
if((temp1.size() + temp2.size()) % 2 == 0) ans+= K-1;
}
cout << ans << endl;
} | 0 | 45,974,898 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m; cin >>n >>m;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >>a[i] >>b[i];
}
vector<int> c(m), d(m);
for (int j = 0; j < m; j++) {
cin >>c[j] >>d[j];
}
for (int i = 0; i < n; i++) {
int cp, dist = 400000001;
for (int j = 0; j < m; j++) {
int t = abs(a[i]-c[j]) + abs(b[i]-d[j]);
if (t<dist) {
dist = t;
cp = j + 1;
}
}
cout << cp << endl;
}
return 0;
} | #include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k; cin >> n >> k;
ll ans = 0;
vector<int> a(n);
vector<int> pre(n + 1);
map<int, ll> mapp;
for(int i = 0; i < n; i++)
{
cin >> a[i];
a[i]--;
if(!i) pre[i + 1] = (a[i] % k);
else pre[i + 1] = (pre[i] + (a[i] % k)) % k;
}
for(int i = 0; i < min(n + 1, k); i++)
{
ans += mapp[pre[i]];
mapp[pre[i]]++;
}
for(int i = k; i < n + 1; i++)
{
mapp[pre[i - k]]--;
ans += mapp[pre[i]];
mapp[pre[i]]++;
}
cout << ans;
return 0;
} | 0 | 32,928,041 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin >> a >> b;
cout << a-b+1;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define all(v) (v).begin(), (v).end()
const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;
inline ll add(ll a, ll b, ll m)
{
if ((a + b) >= m)
return (a + b) % m;
return a + b;
}
inline ll mul(ll a, ll b, ll m)
{
if ((a * b) < m)
return a * b;
return (a * b) % m;
}
ll power(ll x, ll y, ll m)
{
ll res = 1;
x = x % m;
if (x == 0)
return 0;
while (y > 0)
{
if (y & 1)
res = (res * x) % m;
y = y >> 1;
x = (x * x) % m;
}
return res;
}
void solve()
{
ll s;
cin>>s;
vl dp(s+1,0);
dp[0]=1;
for(int i=3;i<=s;i++) {
for(int j=0;j<=i-3;j++) {
dp[i]=(dp[i]+dp[j])%mod;
}
}
cout<<dp[s];
}
int main()
{
fastio;
int t;
t = 1;
while (t-- > 0)
{
solve();
cout << newl;
}
return 0;
} | 0 | 76,091,942 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
#define MAX_N 55
ll C[MAX_N][MAX_N];
void make() {
rep(i, MAX_N) {
C[i][1] = i;
C[i][i] = 1;
C[0][i] = 1;
C[i][0] = 1;
}
REP(i, 1, MAX_N) rep(j, i) {
if(i-1 < 0 || j-1 < 0) continue;
C[i][j] = C[i-1][j] + C[i-1][j-1];
}
}
ll comb(ll n, ll r) {
if(n < 0) return 0;
else if(n < r) return 0;
else return C[n][r];
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
make();
int n, p; cin >> n >> p;
vector<ll> A(n); rep(i, n) cin >> A[i];
int nOdd=0, nEven=0;
rep(i, n) (A[i]%2==0 ? nEven : nOdd)++;
if(nOdd == 0) {
if(p == 1) cout << 0 << "\n";
else cout << (1LL<<n) << "\n";
} else if(nEven == 0) {
if(p == 1) {
ll ans = 0;
rep(i, n+1) if(i%2==1) ans += comb(n, i);
cout << ans << "\n";
} else {
ll ans = 0;
rep(i, n+1) if(i%2==0) ans += comb(n, i);
cout << ans << "\n";
}
} else {
if(p == 1) {
ll ans = 0;
rep(i, nOdd+1) if(i%2==1) ans += comb(nOdd, i);
ans *= (1<<nEven);
cout << ans << "\n";
} else {
ll ans = 0;
rep(i, nOdd+1) if(i%2==0) ans += comb(nOdd, i);
ans *= (1<<nEven);
cout << ans << "\n";
}
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"
ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}
void yes(){ cout << "YES" << endl;}
void no(){ cout << "NO" << endl;}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
ll n;
cin >> n;
ll ans = INF;
for(ll i = 1; i * i <= n; i++){
if(n % i == 0){
string s = to_string(i);
string t = to_string(n / i);
ll tmp = max(s.size(), t.size());
ans = min(ans,tmp);
}
}
cout << ans <<endl;
return 0;
} | 0 | 67,936,709 |
#include<stdio.h>
#include<math.h>
int main(void)
{
int a,b,c;
double s=0,l=0,h=0,ra,pi=3.141592653589;
scanf("%d%d%d",&a,&b,&c);
ra=c*pi/180;
s=0.5*a*b*sin(ra);
l=sqrt(a*a+b*b-2*a*b*cos(ra))+a+b;
h=s*2/a;
printf("%8lf\n%8lf\n%8lf\n",s,l,h);
return 0;
} | #include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
string S[51], T[51];
rep(i, N) cin >> S[i];
rep(i, M) cin >> T[i];
rep(i, N) {
rep(j, N) {
bool ok = true;
rep(s, M) {
rep(t, M) {
if(i + s >= N || j + t >= N || S[i + s][j + t] != T[s][t])ok = false;
}
}
if(ok) {
cout << "Yes" << endl;
return 0;
}
}
}
cout << "No" << endl;
return 0;
} | 0 | 77,261,858 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
void solve();
clock_t start_time;
double get_current_time() {
return (double)(clock() - start_time) / CLOCKS_PER_SEC;
}
int main() {
ios_base::sync_with_stdio(false);
solve();
}
#define fi first
#define re return
#define se second
#define in insert
#define pb push_back
#define eb emplace_back
#define y1 y123123123123
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repx(i, x, n) for (int i = x; i < (n); i++)
#define repd(i, n, d) for (int i = 0; i < (n); i += d)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepd(i, n, d) for (int i = (n) - 1; i >= 0; i -= d)
#ifdef artem
#define debug(x) x
#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
#define debug(x)
#endif
void solve() {
int n;
cin >> n;
vector<int> a(n);
map<int, int> posa;
for(int i = 0; i < n; i++) {
cin >> a[ i ];
posa[ a[ i ] ] = i;
}
vector<int> b = a;
sort(all(b));
map<int, int> posb;
for(int i = 0; i < n; i++) {
posb[ b[ i ] ] = i;
}
int ans = 0;
for(int i = 0; i < n; i++) {
if(posa[ a[ i ] ] % 2 != posb[ a[ i ] ] % 2) {
++ans;
}
}
cout << (ans + 1) / 2 << endl;
} | #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size()
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define forn(i, n) for (int i = 1; i <= n; i++)
#define ford(i, n) for (int i = n; i >= 0; i--)
#define REP(i, a, n) for (int i = a; i < n; i++)
#define foreach(itr, c) for (__typeof((c).begin(), (c).end()) itr = c.begin(); itr != c.end(); itr++)
#define fill(a, b) memset(a, b, sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<char> vs;
typedef vector<pi> vpi;
using namespace std;
int main()
{
string s, t;
int n;
int x;
int count = 0;
int temp = 0;
cin >> s >> t;
for (int i = 0; i < s.length() - t.length() + 1; i++)
{
x = 0;
temp = 0;
for (int j = 0; j < t.length(); j++)
{
if (s[i + x] == t[j])
{
temp++;
}
x++;
}
if (count < temp)
{
count = temp;
}
}
cout << t.length() - count;
} | 0 | 64,803,116 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000009
const long long INF = 1LL<<60;
ll d[210][210];
int main() {
int N,M,R;
cin>>N>>M>>R;
vector<int> r(R);
rep(i,R){
cin>>r[i];
r[i]--;
}
rep(i,N){
rep(j,N){
if(i==j) continue;
d[i][j]=INF;
}
}
rep(i,M){
int a,b;
ll c;
cin>>a>>b>>c;
a--,b--;
d[a][b]=c;
d[b][a]=c;
}
rep(k,N){
rep(i,N){
rep(j,N){
d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}
}
}
vector<int> ord(R);
rep(i,R) ord[i]=i;
ll ans=INF;
do{
ll tmp=0;
rep(i,R-1){
tmp+=d[r[ord[i]]][r[ord[i+1]]];
}
ans=min(ans,tmp);
}while(next_permutation(all(ord)));
cout<<ans<<endl;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
int main()
{
ll i,j,x,y,z,count=100000000000,sum=0,n,ans=0;
cin>>n;
ll a[n];
rep(i,n)
{
cin>>a[i];
}
sort(a,a+n);
for(j=a[n-1]; j>=a[0]; j--)
{
ll mid=j;
rep(i,n)
{
ans=ans+((a[i]-mid)*(a[i]-mid));
}
count=min(count,ans);
ans=0;
}
cout<<count<<endl;
return 0;
} | 0 | 17,089,963 |
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define rep(i,n) for(int64_t i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr int64_t INF=(1ll<<60);
constexpr int64_t mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
string s;cin>>s;
ll n=s.size();
bool ok=true;
rep(i,(n-1)/2-1){
if(s[i]!=s[n-1-i]) ok=false;
if(s[i]!=s[(n-1)/2-1-i]) ok=false;
}
for(int64_t i=(n+3)/2-1;i<n;i++){
if(s[i]!=s[n-1-i]) ok=false;
}
if(ok) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
} | #include<iostream>
#include<vector>
#include<map>
using namespace std;
int main(){
int N,M;cin>>N>>M;
vector<long long>A(N);
for(int i=0;i<N;i++)cin>>A[i];
map<long long,long long>nums;
long long sum=0;
nums[sum]++;
for(int i=0;i<N;i++){
sum+=A[i];
nums[sum%M]++;
}
long long res=0;
for(map<long long, long long>::iterator it=nums.begin();it!=nums.end();it++){
res+=it->second*(it->second-1)/2;
}
cout<<res<<endl;
} | 0 | 69,094,431 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(20);
ll n, k; cin >> n >> k;
ld ans = 0;
rep2(i, 1, n) {
ll score = i;
ld p = 1;
while (score < k) {
score *= 2;
p /= 2.0;
}
ans += p;
}
cout << ans / n << endl;
} | #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <math.h>
#include <functional>
#include <algorithm>
#include <utility>
typedef long long Int;
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
#define REPS(a,i,n) for(int i = a ; i < n ; ++i)
using namespace std;
int ans;
int a, b;
void solve(int i, int _b, int sum){
if (sum == a && _b == 0){
ans++;
return;
}
if (_b == 0 || i == 10)return;
if (i != -1)
solve(i + 1, _b - 1, sum + i);
solve(i + 1, _b, sum);
}
int main(){
while (cin >> b >> a, a||b){
ans = 0;
solve(-1, b, 0);
cout << ans << endl;
}
return 0;
} | 0 | 75,498,323 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
int N;
string s;
cin >> N >> s;
bool is = true;
rep(i, N-1) if(s[i] != s[i+1]) is = false;
if(is){
cout << 1 << endl;
return 0;
}
int ans = 0;
rep(i, N){
if(s[i] == s[i+1]){
while(s[i] == s[i+1] && i < N) i++;
}
ans++;
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using namespace std;
int gcd(int x,int y){
int mi,ma;
ma = max(x,y);
mi = min(x,y);
if(ma % mi == 0){
return mi;
}
else{
return gcd(mi,ma % mi);
}
}
struct Point{
double x;
double y;
};
struct Point2{
Point p1;
Point p2;
};
struct Ret{
Point s;
Point u;
Point t;
};
void PrintPoint(Point p){
printf("x: %lf y:%lf\n",p.x,p.y);
}
Ret cohho(Point p1,Point p2){
Ret r;
double x1,y1,xx,yy;
const double alpha = M_PI*(1/3.0d);
x1 = p2.x - p1.x;
y1 = p2.y - p1.y;
r.s.x = x1 * (1/3.0d) + p1.x;
r.s.y = y1 * (1/3.0d) + p1.y;
r.t.x = x1 * (2/3.0d) + p1.x;
r.t.y = y1 * (2/3.0d) + p1.y;
xx = r.t.x - r.s.x ;
yy = r.t.y - r.s.y ;
r.u.x = xx * cos(alpha) - yy * sin(alpha) + r.s.x;
r.u.y = xx * sin(alpha) + yy * cos(alpha) + r.s.y;
return r;
}
int main(){
long ii,jj,kk;
vector<int> a;
int n;
cin >> n;
Ret r;
Point p1,p2,s,u,t;
p1.x = 0;
p1.y = 0;
p2.x = 100;
p2.y = 0;
Point2 start;
start.p1 = p1;
start.p2 = p2;
vector<Point2> p;
vector<Point2> nextp;
p.push_back(start);
nextp.push_back(start);
for(ii=0;ii<n;ii++){
nextp.clear();
auto it = p.begin();
while(it != p.end()){
r = cohho((*it).p1,(*it).p2);
p1 = (*it).p1;
s = r.s;
u = r.u;
t = r.t;
p2 = (*it).p2;
start.p1 = p1;
start.p2 = s;
nextp.push_back(start);
start.p1 = s;
start.p2 = u;
nextp.push_back(start);
start.p1 = u;
start.p2 = t;
nextp.push_back(start);
start.p1 = t;
start.p2 = p2;
nextp.push_back(start);
it++;
}
p = nextp;
}
auto it2 = nextp.begin();
while(it2 != nextp.end()){
printf("%.14lf %.14lf\n",(*it2).p1.x,(*it2).p1.y);
if((it2+1 ) == nextp.end()){
printf("%.14lf %.14lf\n",(*it2).p2.x,(*it2).p2.y);
}
it2++;
}
return 0;
} | 0 | 38,687,866 |
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)
int main()
{
int A, B;
string S;
cin >> A >> B >> S;
REP(i, A)
{
if (S[i] == '-')
{
cout << "No" << endl;
return 0;
}
}
if (S[A] != '-')
{
cout << "No" << endl;
return 0;
}
for (int i = A + 1; i < A + B + 1; ++i)
{
if (S[i] == '-')
{
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A,B,K;
cin >> A >> B >> K;
int N=min(A,B);
int M=max(A,B);
int ans;
for(int i=1; i<N+1; i++){
if(M%(N-i+1)==0 && N%(N-i+1)==0) K--;
if(K==0){
ans=N-i+1;
break;
}
}
cout << ans << endl;
} | 0 | 74,062,441 |
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) { a = b; return true;}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) { a = b; return true;}
return false;
}
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
ll n,k;cin>>n>>k;
vector<ll> a(n);
rep(i,n){cin>>a[i];}
vector<ll> cumsum(n+1,0);
rep(i,n){
cumsum[i+1] = cumsum[i]+a[i];
}
vector<ll> lst;
rep(i,n){
repr(j,i,n){
lst.push_back(cumsum[j+1]-cumsum[i]);
}
}
ll nn = lst.size();
vector<ll> count(45,0);
ll now = 44;
multiset<ll> st;
rep(i,nn){
st.insert(lst[i]);
}
ll res = 0;
while(now>=0){
ll cnt=0;
for(auto x:st){
if(x&(1LL<<now)){
cnt++;
}
}
if(cnt>=k){
res += 1LL<<now;
auto it = st.begin();
while(it != st.end()){
if((*it&(1LL<<now))==0){
it = st.erase(it);
}else{
it++;
}
}
}
now--;
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int len;
cin >> len;
vector<int> arr(len);
vector<long long> prefix(len);
for(int i = 0; i < len; i++) {
cin >> arr[i];
if(i == 0) {
prefix[i] = arr[i];
} else {
prefix[i] = prefix[i - 1] + arr[i];
}
}
sort(arr.begin(), arr.end());
for(int i = 0; i < len; i++) {
if(i == 0) {
prefix[i] = arr[i];
} else {
prefix[i] = prefix[i - 1] + arr[i];
}
}
int ans = len;
for(int i = len - 2; i >= 0; i--) {
if(prefix[i] * 2 < arr[i + 1]) {
ans = len - i - 1;
break;
}
}
cout << ans;
} | 0 | 80,305,321 |
#include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ll long long
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n+1);
rep(i, n) {
cin >> a[i+1];
}
vector<bool> memo(n+1);
memo[1]=true;
int now = 1;
int ans = 0;
do {
int next = a[now];
if(memo[next]) {
cout << -1 << endl;
return 0;
}
memo[next] = true;
now = next;
++ans;
} while(now != 2);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int R, G, B, N;
cin >> R >> G >> B >> N;
int ans = 0;
for (int r = 0; r * R <= N; ++r) {
for (int g = 0; g * G <= N; ++g) {
int res = N - r * R - g * G;
if (res < 0) continue;
if (res % B) continue;
ans++;
}
}
cout << ans << endl;
return 0;
} | 0 | 41,799,169 |
#include<bits/stdc++.h>
using namespace std;
#define fast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define test() ll t; cin>>t; while(t--)
#define lp0(i,begin,end) for(ll i=begin;i<end;i++)
#define lp1(i,begin,end) for(ll i=begin;i<=end;i++)
#define rlp(i,begin,end) for(ll i=end;i>=begin;i--)
#define prec(n) fixed<<setprecision(n)
#define initial(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define BPC(x) __builtin_popcountll(x)
#define gcd(a,b) __gcd(a,b)
ll gcd(ll a,ll b) {if (a==0) return b;return gcd(b%a,a);}
ll power(ll x,ll n)
{
ll result = 1;
while (n)
{
if (n & 1)
result = result * x;
n = n / 2;
x = x * x;
}
return result;
}
void solution(ll compte)
{
ll a,p;
cin >> a >>p;
cout << (a*3 + p)/2 << endl;
}
int main()
{
ll compte = 1;
solution(compte);
compte++;
return 0;
} | #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;}
int main() {
int h,w;
cin >> h >> w;
rep(i,h){
rep(j,w){
string s;
cin >> s;
if(s=="snuke"){
int a = 'A';
cout << (char)(a+j);
cout << i+1 << endl;
return 0;
}
}
}
return 0;
} | 0 | 65,991,115 |
#include <iostream>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int f(string s){
int n=s.size();
int ret = 0;
int t=1;
for(int i=0;i<n;i++){
if(s[i]>='0' && s[i]<='9'){
t = s[i]-'0';
}
if(s[i]=='m'){
ret += t*1000;
t=1;
}
if(s[i]=='c'){
ret += t*100;
t=1;
}
if(s[i]=='x'){
ret += t*10;
t=1;
}
if(s[i]=='i'){
ret += t*1;
t=1;
}
}
return ret;
}
string f2(int n){
string ret;
int m=n/1000;
n %= 1000;
int c=n/100;
n %= 100;
int x=n/10;
n %= 10;
int i=n;
if(m!=0){
if(m!=1)
ret += m+'0';
ret += "m";
}
if(c!=0){
if(c!=1)
ret += c+'0';
ret += "c";
}
if(x!=0){
if(x!=1)
ret += x+'0';
ret += "x";
}
if(i!=0){
if(i!=1)
ret += i+'0';
ret += "i";
}
return ret;
}
void solve(){
string s1,s2;
cin >> s1 >> s2;
int N = f(s1) + f(s2);
cout << f2(N) << endl;
}
int main(){
int n;
cin >> n;
rep(i,n){
solve();
}
} | #include <bits/stdc++.h>
using namespace std;
int main(){
string S,T;
cin>>S>>T;
int N=S.size(),a=0;
for(int i=0;i<N;i++){
string A,B;
for(int j=0;j<i;j++){
A.push_back(S.at(j));
}
for(int j=i;j<N;j++){
B.push_back(S.at(j));
}
string C=B+A;
if(C==T){
a=1;
break;
}
}
if(a==0)
cout<<"No"<<endl;
else
cout<<"Yes"<<endl;
} | 0 | 90,594,167 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, A, x, y;
cin >> N >> A;
x = N % 500;
if(x <= A){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007
int main()
{
string L; cin >> L;
int len = L.size();
vector<int> x3(len);
x3[0] = 1;
for (int i = 1; i < x3.size(); i++) {
x3[i] = (ll)x3[i-1] * 3 % MOD;
}
ll ans_eq = 1, ans_lt = 0;
for (int i = 0; i < len; i++) {
if (L[i] == '1') {
ans_lt = (ans_lt + (ans_eq * x3[len - i - 1] % MOD)) % MOD;
ans_eq = (ans_eq * 2) % MOD;
}
}
ll ans = (ans_eq + ans_lt) % MOD;
cout << ans << endl;
} | 0 | 4,665,681 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
using namespace std;
int main() {
int n, r, ans;
scan2Int(n, r);
if (n >= 10) ans = r;
else ans = r + 100 * (10 - n);
printInt(ans);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define MOD 1000000007
#define deb(x) cout << #x << "=" << x << endl
int main() {
ll t;
t=1;
while(t--)
{
ll n,m;
cin>>n>>m;
char M[n][m];
for(ll i=0;i<n;i++)
{
for(ll j=0;j<m;j++)
{
cin>>M[i][j];
}
}
ll frow=0;
ll fcol=0;
ll T[n][m];
for(ll i=0;i<n;i++)
{
if(M[i][0]=='#')
{
T[i][0]=0;
fcol=1;
}
else if(fcol ==1)
T[i][0]=0;
else
T[i][0]=1;
}
for(ll j=0;j<m;j++)
{
if(M[0][j]=='#')
{
T[0][j]=0;
frow=1;
}
else if(frow==1)
T[0][j]=0;
else
T[0][j]=1;
}
for(ll i=1;i<n;i++)
{
for(ll j=1;j<m;j++)
{
if(M[i][j]=='#')
T[i][j]=0;
else
T[i][j]=(T[i-1][j]+T[i][j-1])%MOD;
}
}
cout<<T[n-1][m-1];
}
return 0;
} | 0 | 34,938,986 |
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
string s;
vector<int> v;
ll calc(ll x, ll y) {
if(x < y) swap(x,y);
return x*(x+1)/2 + y*(y-1)/2;
}
int main() {
cin>>s;
int N = s.size();
int cnt = 0;
if(s[0] != '<') {
v.pb(0);
}
for(int i=0;i<N;++i) {
++cnt;
if(i == N-1 || s[i] != s[i+1]) {
v.pb(cnt);
cnt = 0;
}
}
if(s[N-1] != '>') {
v.pb(0);
}
ll sum = 0;
for(int i=0;i<v.size();i+=2) {
sum += calc(v[i], v[i+1]);
}
cout<<sum<<"\n";
return 0;
} | #include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
#define rep(i, m, n) for (int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for (int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef vector<vector<vector<ll>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
using ld = long double;
static const ld pi = 3.141592653589793L;
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 (b < a) {
a = b;
return 1;
}
return 0;
}
int gcd(int a, int b) {
while (a != b) {
if (a > b) {
if (a % b == 0)
return b;
else
a = a % b;
}
if (a < b) {
if (b % a == 0)
return a;
else
b = b % a;
}
}
return a;
}
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i,0,n) cin >> a[i];
int res = 1e9 + 1;
rep(i,0,n) {
if (i == 0) {
res = a[0];
continue;
}
res = gcd(res,a[i]);
}
cout << res << '\n';
return 0;
} | 0 | 6,183,862 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; i++) {
cin >> a.at(i);
}
int i = 0;
int ai = a.at(i);
for (i = 0; i < N - 1; i++) {
if (ai == 2) {
break;
}
ai = a.at(ai - 1);
}
if (i < N - 1) {
cout << i + 1 << endl;
} else {
cout << -1 << endl;
}
} | #include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
bool is_integer( float x ){
return floor(x)==x;
}
int main() {
char ch[101][101];
int h,w;
cin >> h >> w;
for(int i = 0; i < h; i ++){
for(int j = 0; j < w; j ++){
cin >> ch[i][j];
}
}
for(int i = 0; i < h; i ++){
for(int k = 0; k < 2; k ++) {
for (int j = 0; j < w; j++) {
cout << ch[i][j];
}
cout << endl;
}
}
return 0;
} | 0 | 57,370,190 |
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
int main(){
string s;
cin >> s;
REP(i, s.size()){
if(s[i] == '1') s[i] = '9';
else if(s[i] == '9') s[i] = '1';
}
cout << s << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i,s,n) for (int i = s; i < (n); ++i)
#define revrep(i,n,g) for (int i = n; i >= g; i--)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
int m,k;
cin >> m >> k;
if (m <= 1) {
if (m == 0 && k == 0) {
cout << "0 0" << endl;
} else if (m == 1 && k == 0) {
cout << "0 0 1 1" << endl;
} else {
cout << "-1" << endl;
}
} else {
if ((1<<m) <= k) cout << -1 << endl;
else {
rep(i,0,1<<m) {
if (i == k) continue;
cout << i << " ";
}
cout << k << " ";
revrep(i,(1<<m)-1,0) {
if (i == k) continue;
cout << i << " ";
}
cout << k << endl;
}
}
return 0;
} | 0 | 37,955,353 |
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <list>
#include <string>
typedef char SINT8;
typedef short SINT16;
typedef int SINT32;
typedef long long SINT64;
typedef double DOUBLE;
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(SINT64 (i)=SINT64(a);(i)<SINT64(b);(i)++)
#define rrep(i,a,b) for(SINT64 (i)=SINT64(a);(i)>=SINT64(b);(i)--)
#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "
#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001
#define F first
#define S second
#define Pii pair<SINT32,SINT32>
#define Pll pair<SINT64,SINT64>
#define Piii pair<SINT32,pair<SINT32,SINT32>>
#define Plll pair<SINT64,pair<SINT64,SINT64>>
#define Vll(a,b,c) vector<vector<SINT64>> (a)((b),vector<SINT64>((c))
#define Vlll(a,b,c,d) vector<vector<vector<SINT64>>> (a)((b),vector<vector<SINT64>>((c),vector<SINT64>((d)))
using namespace std;
int main() {
SINT64 N; cin >> N;
SINT64 M; cin >> M;
SINT64 ans = 0;
vector<SINT64> data1(N);
vector<SINT64> data2(M);
vector<SINT64> rui(M+1);
rep(i,0,N) {
cin >> data1[i];
ans += data1[i];
}
rep(i,0,M) {
cin >> data2[i];
ans += data2[i];
}
sort(data1.begin(),data1.end());
sort(data2.begin(),data2.end());
rep(i,0,M) {
rui[i+1] = rui[i]+data2[i];
}
rep(i,0,N) {
SINT64 posi;
posi = lower_bound(data2.begin(),data2.end(), data1[i]) - data2.begin();
ans += (M-posi)*data1[i];
ans += rui[posi];
}
put(ans);
return 0;
} | #include <algorithm>
#include <bitset>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>
#include <cctype>
#include <cmath>
#include <ctime>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;
typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ld, ll, ll>> vtll;
const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;
template <typename T>
void fin(T a)
{
cout << a << endl;
exit(0);
}
void Main()
{
ll n; cin >> n;
ll T = 0, X = 0, Y = 0;
vll t(n), x(n), y(n);
ll d = 0;
rep(i, n)
{
cin >> t[i] >> x[i] >> y[i];
T = t[i] - T;
X = x[i] - X;
Y = y[i] - Y;
if(T >= abs(X + Y)&&abs(T - abs(X + Y)) % 2 == 0){}
else d++;
T = t[i];
X = x[i];
Y = y[i];
}
if(d != 0) fin("No");
fin("Yes");
return;
}
int main()
{
int ti = clock();
srand((unsigned)time(NULL));
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
Main();
return 0;
} | 0 | 63,377,370 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
int main(){
ll X;
cin >> X;
ll n = X/100;
ll m = X - 100*n;
if(m <= 5*n)cout << 1 << endl;
else cout << 0 << endl;
return 0;
} | #include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n; cin >> n;
vector<int> A(n);
vector<int> B(n);
ll have = 0;
rep(i, n) {
cin >> A[i];
have += A[i];
}
vector<int> S;
ll need = 0;
rep(i, n) {
cin >> B[i];
need += B[i];
if(B[i] <= A[i]) {
S.push_back(A[i] - B[i]);
}
}
if(need > have) {
cout << -1 << endl;
return 0;
}
sort(S.begin(), S.end());
int ans = n;
rep(i, S.size()) {
if(need + S[i] <= have) {
need += S[i];
--ans;
}
}
cout << ans << endl;
return 0;
} | 0 | 80,344,545 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
unsigned gcd(unsigned a, unsigned b) {
if(a < b) return gcd(b, a);
unsigned r;
while ((r=a%b)) {
a = b;
b = r;
}
return b;
}
unsigned lcm(unsigned a, unsigned b){
return a / gcd(a, b) * b;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll pow_mod(ll num, ll pow, ll mod) {
ll prod = 1;
num %= mod;
while (pow > 0) {
if (pow & 1) prod = prod * num % mod;
num = num * num % mod;
pow >>= 1;
}
return prod;
}
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
int N;
cin >> N;
int D[N];
ll mo = 998244353;
ll d[N] = {0};
REP(i, N) {
cin >> D[i];
d[D[i]]++;
}
ll ans = 1;
bool flag = false;
for(int i = N - 1; i >= 1; i--){
if(d[i] != 0) flag = true;
if(flag && d[i] == 0){
print(0);
return 0;
}
}
if(d[0] != 1){
print(0);
return 0;
}
if(D[0] != 0){
print(0);
return 0;
}
for(int i = 1; i < N; i++){
ans *= pow_mod(d[i - 1], d[i], mo);
ans %= mo;
}
print(ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N,D;
int ans = 0;
cin >> N >> D;
vector<vector<int>> vec(N,vector<int> (D));
for(int i=0;i<N;++i){
for(int j=0;j<D;++j){
cin >> vec.at(i).at(j);
}
}
for(int i=0;i<N-1;++i){
for(int j=i+1;j<N;++j){
int sum = 0;
for(int k=0;k<D;++k){
sum += pow(vec.at(i).at(k) - vec.at(j).at(k),2);
}
int t = 0;
while(pow(t,2) <= sum){
if(pow(t,2) == sum) ans++;
t++;
}
}
}
cout << ans << endl;
return 0;
} | 0 | 87,150,308 |
#include<bits/stdc++.h>
#include<chrono>
using namespace std;
using namespace std::chrono;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define int long long
#define pb push_back
#define emp emplace_back
#define vv(x) vector<x>
#define mp(x,y) map<x,y>
#define dq(x) deque<x>
#define pql(x) priority_queue<x>
#define pqs(x) priority_queue<x,vv(x),greater<x> >
#define M 1000000007
#define forf(i,a,b) for(int i=a;i<b;i++)
#define it(x) x::iterator
#define ll long long
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
#define vii vector<int>
#define big 1e18
#define sm -2e18
#define mkr make_pair
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define rng 500005
#define sz(x) (int)x.size()
#define rv(x) reverse(x.begin(),x.end())
#define out(x) cout<<x.fi<<" "<<x.se<<endl;
#define MEM(x,val) memset(x,val,sizeof(x))
void pr_init()
{
#ifndef ONLINE_JUDGE
freopen("gin.txt", "r", stdin);
#endif
}
void solve()
{
string s,t;
cin >> s >> t;
int an = INT_MAX;
for(int i=0;i<sz(s)-sz(t)+1;i++)
{
int cur =0 ;
for(int j=i;j<i+sz(t);j++)
{
if(s[j]!=t[j-i]) cur++;
}
an = min(an,cur);
}
cout<<an;
}
int32_t main()
{
pr_init();
fastio;
auto start = high_resolution_clock::now();
solve();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 500000000
#define IOS ios_base::sync_with_stdio(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prll(a,sz) cout<<a[0];for(ll i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<ll,ll>pi;
typedef pair<ll,ll>pll;
bool check(ll n,ll p){return (1<<p)&n;}
const ll N=2010;
ll mod=1e9+7;
ll ara[N],A[N],D[N];
int main()
{
IOS;
ll n,k;cin>>n>>k;
for(ll i=0;i<n;i++)cin>>ara[i];
for(ll i=0;i<n;i++)
{
for(ll j=i+1;j<n;j++)
if(ara[j]<ara[i])A[i]++;
for(ll j=i-1;j>=0;j--)
if(ara[j]<ara[i])D[i]++;
D[i]+=A[i];
}
ll res=0;
for(ll i=0;i<n;i++)
{
ll temp=k*(k-1)/2;
ll sum=((k*A[i])%mod+(temp%mod)*D[i])%mod;
res=(res+sum)%mod;
}
cout<<res<<endl;
} | 0 | 25,871,919 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string A;
cin>>A;
cout<<(A.at(0)==A.at(1)&&A.at(1)==A.at(2)? "No":"Yes")<<endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
signed main(){
int n,k; cin >> n >> k;
string s; cin >> s;
vector<pi> vec(0);
int f = (s[0] == '0' ? 1 : 0);
int cnt = 0;
rep(i,0,n){
int g = (s[i] == '0' ? 1 : 0);
if(f != g){
vec.push_back(make_pair(cnt , f));
f = g;
cnt = 0;
}
cnt++;
}
if(cnt != 0)vec.push_back(make_pair(cnt , f));
int ans = 0;
int memo = 0;
int ind = 0;
cnt = 0;
if(vec.size() == 1){
cout << n << endl;
return 0;
}
rep(i,0,vec.size()){
cnt += vec[i].second;
while(cnt > k){
cnt -= vec[ind].second;
memo -= vec[ind].first;
ind++;
}
memo += vec[i].first;
chmax(ans , memo);
}
chmax(ans , memo);
cout << ans << endl;
return 0;
} | 0 | 78,835,798 |
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <string.h>
#include <stack>
using namespace std;
#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;
int main() {
stack<int> st;
int n;
while(cin >> n) {
if (!n) {
cout << st.top() << endl;
st.pop();
} else {
st.push(n);
}
}
} | #include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int N;
cin >> N;
ll tot = 0;
int bs = INT_MAX;
vi a(N), b(N);
for (int i = 0; i < N; i++) {
cin >> a[i] >> b[i];
tot += a[i];
if (a[i] > b[i]) {
bs = min(bs, b[i]);
}
}
if (a == b) { cout << 0 << endl; return 0; }
ll ans = tot - bs;
cout << ans << endl;
return 0;
} | 0 | 42,918,765 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
int N,i;
cin >> N >> i;
cout << N + 1 - i << endl;
return 0;
} | #include<cstdio>
#include<iostream>
int a[5];
int swa;
int change(int n){
swa=a[n],a[n]=a[n-1],a[n-1]=swa;
}
int main(){
for(int i=0;i<5;i++)
scanf("%d",&a[i]);
for(int i=4;i>=0;i--){
for(int j=4;j>0;j--){
if(a[j-1]<a[j])
change(j);
}
}
for(int i=0;i<4;i++)
printf("%d ",a[i]);
printf("%d\n",a[4]);
return 0;
} | 0 | 18,164,254 |