code1
stringlengths 54
12k
| code2
stringlengths 65
12k
| similar
int64 0
1
| __index_level_0__
int64 2
101M
|
---|---|---|---|
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI = acos(-1.0);
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
string line;
while(getline(cin,line)){
if(line == ".") break;
int p1 = 0, p2 = 0, i;
bool ans = true;
stack<int> st;
for(i=0;i<SZ(line);++i){
switch(line[i]){
case '(':
st.push(0); break;
case '[':
st.push(1); break;
case ')':
if(st.empty())
ans = false;
else{
if(st.top() != 0)
ans = false;
st.pop();
}
break;
case ']':
if(st.empty())
ans = false;
else{
if(st.top() != 1)
ans = false;
st.pop();
}
break;
}
}
ans = ans && st.empty();
cout << (ans? "yes": "no") << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
os << "{" <<p.first << ", " << p.second << "}";
return os;
}
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 int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int N, M;
cin >> N >> M;
vector<i_i> ans;
if(N&1){
for(int l = 1, r = N-1;l < r;l++,r--){
ans.emplace_back(l, r);
}
}
else{
bool f = false;
for(int l = 1,r = N; l < r; l++, r--){
if(!f&&r-l<=N/2){
f = true;
r--;
}
ans.emplace_back(l, r);
}
}
rep(i,M){
cout << ans[i].first << " " << ans[i].second << endl;
}
} | 0 | 39,713,370 |
#include <bits/stdc++.h>
using namespace std;
int main(void){
/*
int a, b;
cin >> a >> b ;
char a;
cin >> a ;
a = a + 1;
/*
vector<int> vec(3);
cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
sort(vec.begin(), vec.end());
/*
if( a == b ){
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
cout << a << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w
#define int long long
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int,int> P;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
const int INF=2e+18;
const double EPS=1e-9;
const int MOD=1000000007;
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
signed main(){
int q;
cin >> q;
for(int i = 0;i < q;i++){
int a,b;
cin >> a >> b;
if(a > b) swap(a,b);
if(a == b) cout << (a - 1) * 2 << endl;
else{
int low = a,up = INF;
while(up - low > 1){
int mid = (up + low) / 2;
if(mid > (a * b - 1) / mid) up = mid;
else low = mid;
}
cout << up + (a * b - 1) / up - 2 << endl;
}
}
return 0;
} | 0 | 41,684,865 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1000000007;
signed main(){
int N;
cin>>N;
vector<int> A(64,0);
for(int j=0;j<N;j++){
int B;
cin>>B;
bitset<64> C(B);
for(int i=0;i<64;i++)
if(C.test(i))
A[i]++;
}
int ans=0;
for(int i=0,j=1;i<64;i++,j=j*2%mod)
ans=(ans+j*(A[i]*(N-A[i])%mod))%mod;
cout<<ans<<endl;
} | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using P = pair<int, int>;
int main(){
int n, h;
cin >> n >> h;
vector<P> sword(n);
for(int i = 0; i < n; i++) cin >> sword[i].second >> sword[i].first;
sort(sword.begin(), sword.end());
int amax_i = 0;
for(int i = 1; i < n; i++){
if(sword[amax_i].second < sword[i].second) amax_i = i;
}
int sum = 0;
int ans = 0;
for(int i = n-1; i >= 0; i--){
if(sum >= h) break;
if(sword[i].first >= sword[amax_i].second){
ans++;
sum += sword[i].first;
}
}
if(sum < h) ans += (h-sum+sword[amax_i].second-1)/sword[amax_i].second;
cout << ans << endl;
return 0;
} | 0 | 31,661,610 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
int main() {
ll ans = 0;
int tmp;
string s;
ll k;
cin >> s >> k;
int no = s.size()+1, x;
REP(i, s.size()){
if(s[i]!='1'){
no = i + 1;
x = s[i] -'0';
break;
}
}
if(k < (ll)no) cout << 1 << endl;
else cout << x << endl;
} | #include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define int long long
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
int N,K; cin>>N>>K;
vector<int>A(K);
int ans=0;
rep(i,K){
cin>>A[i];
ans+=A[i];
}
cout<<(ans>N? -1:N-ans)<<endl;
} | 0 | 40,720,887 |
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
using namespace std;
const int N = 2e5 + 10;
int dp[N][2];
vector<int>adj[N];
LL add(LL a, LL b) {
return (a + b) % MOD;
}
LL mult(LL a, LL b) {
return (a*b) % MOD;
}
void dfs(int i, int pr) {
dp[i][0] = dp[i][1] = 1;
for (auto x : adj[i])
if (x == pr)continue;
else {
dfs(x, i);
dp[i][0] = mult(dp[i][0], add(dp[x][0], dp[x][1]));
dp[i][1] = mult(dp[i][1], dp[x][0]);
}
return;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0;i < n - 1;i++) {
int u, v;
scanf("%d%d", &u, &v);
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 1);
printf("%lld\n", add(dp[1][0], dp[1][1]));
cin >> n;
} | #include<iostream>
#include<string>
using namespace std;
int main()
{
int a, flag = 1;
string b;
cin>>a>>b;
if(a%2==0)
{
int c= b.length()/2;
for(int i=0; i<c; i++)
if(b.at(i)!=b.at(i+c))
{
flag = 0;
break;
}
if(flag==1)
cout<< "Yes"<<endl;
else
cout<< "No"<<endl;
}
else
cout<< "No"<<endl;
} | 0 | 67,698,836 |
#include <iostream>
int main()
{
int n;
int cnt;
while (std::cin >> n){
cnt = 0;
for (int a = 0; a < 10; a++){
for (int b = 0; b < 10; b++){
for (int c = 0; c < 10; c++){
for (int d = 0; d < 10; d++){
if (a + b + c + d == n){
cnt++;
}
}
}
}
}
std::cout << cnt << std::endl;
}
return 0;
} | #include<bits/stdc++.h>
template<typename First, typename Second, typename Third>
struct triple {
First first;
Second second;
Third third;
};
using namespace std;
void solve(){
int n;
cin>>n;
vector<int>v(n+2);
v[0]=0;
v[n+1]=0;
long long sum=0;
for(int i=1;i<=n;i++){
cin>>v[i];
sum+=abs(v[i]-v[i-1]);
}
sum+=abs(v[n+1]-v[n]);
for(int i=1;i<=n;i++){
cout<<(sum-abs(v[i]-v[i+1])-abs(v[i]-v[i-1])+abs(v[i+1]-v[i-1]))<<"\n";
}
}
int main(){
std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
solve();
return 0;
} | 0 | 72,752,251 |
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
void solver(int n, int k, vector<int> p, vector<int> c) {
REP(i,n) p[i]--;
ll ans = -LINF;
REP(i,n) {
ll cycle_sum = 0;
int cycle_cnt = 0, v = i;
while(1) {
cycle_cnt++;
cycle_sum += c[p[v]];
v = p[v];
if (v == i) break;
}
ll path = 0;
int cnt = 0;
while(1) {
cnt++;
path += c[p[v]];
if (cnt > k) break;
int num = (k - cnt) / cycle_cnt;
ll score = path + max(0ll, cycle_sum) * num;
chmax(ans, score);
v = p[v];
if (v == i) break;
}
}
COUT(ans);
return;
}
int main() {
IOS;
int n, k; cin >> n >> k;
vector<int> p(n),c(n);
REP(i,n) cin >> p[i];
REP(i,n) cin >> c[i];
solver(n,k,p,c);
return 0;
} | #include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
int main() {
ll A,B,C,K;
cin >> A >> B >> C >> K;
ll ans = A-B;
if(abs(ans) > (ll)1e18){
cout << "Unfair" << endl;
return 0;
}
if(K%2 == 0){
cout << ans << endl;
}else{
cout << ans*-1 << endl;
}
} | 0 | 78,564,828 |
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s;
cin>>s;
int n=s.size();
int count=0;
for(int i=0;i<n;i++){
if(s[i]==s[n-1-i]){
count++;
}
}
if(count==n){
int x=(n-1)/2;
for(int i=0;i<x;i++){
if(s[i]==s[x-1-i]){
count++;
}
}
int y=(n+3)/2;
for(int i=0;i<n-y+1;i++){
if(s[y-1+i]==s[n-1-i]){
count++;
}
}
if(count==n+n+1+x-y){
cout<<"Yes";
}
else{
cout<<"No";
}
}
else{
cout<<"No";
}
} | #include<bits/stdc++.h>
using namespace std;
const int N = 20005;
int a[N], b[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
for (int i=1; i<=n; i++) a[i] = i*n, b[i] = (n+1-i)*n;
for (int i=0; i<n; i++) {
int x;
cin>>x;
a[x] += i;
}
for (int i=1; i<=n; i++) cout<<a[i]<<" "; cout<<endl;
for (int i=1; i<=n; i++) cout<<b[i]<<" "; cout<<endl;
} | 0 | 56,014,752 |
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <random>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define pi 3.141592653589793
#define prique priority_queue
constexpr auto mod=1000000007;
using namespace std;
int gcd(int a,int b){
if(b==0) return a;
return gcd(b,a%b);
}
int lcm(int a,int b){
return a*b/gcd(a,b);
}
bool prime(int n){
int cnt=0;
for(int i=1;i<=sqrt(n);i++){
if(n%1==0)cnt++;
}
if(cnt!=1) return false;
else return n!=1;
}
struct UnionFind{
vector<int> r;
UnionFind(int N){
r=vector<int>(N,-1);
}
int root(int x){
if(r[x]<0) return x;
return r[x]=root(r[x]);
}
bool unite(int x,int y){
x=root(x);
y=root(y);
if(x==y) return false;
if(r[x]>r[y]) swap(x,y);
r[x]+=r[y];
r[y]=x;
return true;
}
int size(int x){
return -r[root(x)];
}
};
vector<int> v;
int n,m,x,cnt=0,ans=0,aa[220000],ab[220000],a=0;
pair<int,int> pp[220000];
string s,ss[220000];
queue<int> que;
signed main(){
cin>>n>>m;
m/=1000;
m-=n;
rep(i,n+1){
rep(j,n+1){
if(i*9+j*4==m&&i+j<=n){
cout<<i<<' '<<j<<' '<<n-i-j;
return 0;
}
}
}
cout<<"-1 -1 -1";
} | #pragma region header
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define ts to_string
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector <string>
#define vvs vector <vector<string>>
#define pq priority_queue<int>
using ll = long long;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 2000000000;
const int MINF=-2000000000;
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
ll fact(int i) {
if (i == 0) return 1;
return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a * b / gcd(a, b);
}
bool isprime(ll a)
{
if (a < 2) return false;
else if (a == 2) return true;
else if (a % 2 == 0) return false;
double m = sqrt(a);
for (int i = 3; i <= m; i += 2)
{
if (a % i == 0)
{
return false;
}
}
return true;
}
ll ketasum(ll n) {
ll sum = 0;
while (n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
ll kind(vi SYURUI) {
int size = SYURUI.size();
sort(all(SYURUI));
int cnt = 1;
rep(i, size-1) {
if (SYURUI[i] != SYURUI[i + 1])cnt++;
}
return cnt;
}
#pragma endregion
signed main() {
int N, K; cin >> N >> K;
vi V; rep1(i, N)V.push_back(i);
rep(i, K) {
int d; cin >> d;
rep(i, d) {
int A;
cin >> A;
rep(j, V.size()) {
if (V[j] == A) {
V.erase(V.begin() + j);
}
}
}
}
cout << V.size() << endl;
} | 0 | 29,443,549 |
#include <iostream>
#include <cstdio>
using namespace std;
int mtoi(string s){
int sum=0;
int co=1;
for(int i=0;i<s.length();i++){
if('1'<=s[i] && s[i]<='9'){co=s[i]-'0';}
else if(s[i]=='m'){sum+=1000*co;co=1;}
else if(s[i]=='c'){sum+= 100*co;co=1;}
else if(s[i]=='x'){sum+= 10*co;co=1;}
else if(s[i]=='i'){sum+= 1*co;co=1;}
}
return sum;
}
string itom(int m){
string result="";
int co;
co=m/1000;
if(co>=1){
if(co!=1)result+=(co+'0');
result+="m";
m-=co*1000;
}
co=m/100;
if(co>=1){
if(co!=1)result+=(co+'0');
result+="c";
m-=co*100;
}
co=m/10;
if(co>=1){
if(co!=1)result+=(co+'0');
result+="x";
m-=co*10;
}
co=m;
if(co>=1){
if(co!=1)result+=(co+'0');
result+="i";
m-=co*1;
}
return result;
}
int main() {
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
string s1,s2;
cin >> s1 >> s2;
cout << itom(mtoi(s1)+mtoi(s2)) << endl;
}
return 0;
} | #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define END '\n'
#define inf 9e18
#define ff first
#define ss second
#define pb push_back
vvi adj;
vb vis;
int cnt = 0;
void dfs(int v){
++cnt;
vis[v] = true;
for (auto u: adj[v]){
if (!vis[u]){
dfs(u);
}
}
}
void solve(){
int n, m;
cin >> n >> m;
adj.resize(n + 1);
vis.resize(n + 1, false);
while(m--) {
int a, b;
cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
}
int ans = INT_MIN;
for (int i = 1; i <= n; ++i) {
if (!vis[i]) cnt = 0, dfs(i), ans = max(ans, cnt);
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int t = 1;
while(t--){
solve();
}
return 0;
} | 0 | 9,591,982 |
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
int main(){
ll N, A, B; cin >> N >> A >> B;
ll retval;
if (A>B) retval = 0;
else if (N==1 && A==B) retval = 1;
else if (N==1 && A!=B) retval = 0;
else {
retval = B*(N-2) - A*(N-2) +1;
}
cout << retval << endl;
return 0;
} | #include <iostream>
#include <cmath>
using namespace std;
int main(){
int x1, y1, x2, y2, x3, y3, x4, y4;
cin >> x1 >> y1 >> x2 >> y2;
int yd=abs(y2-y1);
int xd=abs(x2-x1);
if (x1 <= x2 && y1 < y2){
x3 = x2 - yd;
y3 = y2 + xd;
x4 = x1 - yd;
y4 = y1 + xd;
}else if (x1 > x2 && y1 < y2){
x3 = x2 - yd;
y3 = y2 - xd;
x4 = x1 - yd;
y4 = y1 - xd;
}else if (x1 > x2 && y1 >= y2){
x3 = x2 + yd;
y3 = y2 - xd;
x4 = x1 + yd;
y4 = y1 - xd;
}else{
x3 = x2 + yd;
y3 = y2 + xd;
x4 = x1 + yd;
y4 = y1 + xd;
}
printf("%d %d %d %d\n",x3,y3,x4,y4);
} | 0 | 96,944,120 |
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin>>s;
int n=s.size();
string ans;
if(n<26){
map<char,int> dic;
rep(i,n){
dic[s[i]]++;
}
rep(i,26){
char c = 'a' + i;
if(!dic[c]){
ans=s+c;
break;
}
}
}
else{
if(s=="zyxwvutsrqponmlkjihgfedcba"){
ans="-1";
}
else{
string _s=s;
next_permutation(_s.begin(),_s.end());
rep(i,26){
if(s[i]!=_s[i]){
ans=_s.substr(0,i+1);
break;
}
}
}
}
cout<<ans<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
}
vector<bool> vis(n, 0);
int ans = 0;
for (int i = 0; i < n; i++) {
if (vis[i]) continue;
if (a[a[i]] == i) {
vis[i] = vis[a[i]] = true;
ans++;
}
}
cout << ans << '\n';
return 0;
} | 0 | 92,979,962 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;
int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;
const int D = 60;
const int max_n = 200005;
ll cal(ll a, ll b, ll k){
ll n = (k-(a-1))/2;
if(b-a-2ll>0){
return (b-a-2ll) * n + k + 1ll;
}else{
return k + 1ll;
}
}
int main() {
ll k, a, b; cin >> k >> a >> b;
ll ans = cal(a, b, k);
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end()))
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define NUM(x,v) (POSU(x,v)-POSL(x,v))
#define REV(x) (reverse(x.begin(),x.end()))
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
class comb{
vector<ll> f,fr;
ll MOD_;
public:
ll calc(ll a,ll b,ll p){
if(b==0)return 1;
ll y = calc(a,b/2,p);y=(y*y)%p;
if(b & 1) y = (y * a) % p;
return y;
}
void init(ll n,ll mod){
MOD_ = mod;
f.resize(n+1);
fr.resize(n+1);
f[0]=fr[0]=1;
for(ll i=1;i<n+1;i++){
f[i] = (f[i-1] * i) % mod;
}
fr[n] = calc(f[n],mod-2,mod);
for(ll i=n-1;i>=0;i--){
fr[i] = fr[i+1] * (i+1) % mod;
}
}
ll nCr(ll n,ll r){
if(n<0||r<0||n<r)return 0;
return f[n] * fr[r] % MOD_ * fr[n-r] % MOD_;
}
};
int main(){
ll x,y;
cin >> x >> y;
if((x+y)%3){
cout << 0 << endl;
return 0;
}
ll k = (x+y)/3;
x -= k;
y -= k;
comb co;
co.init(x+y+1,MOD);
cout << co.nCr(x+y,x) << endl;
} | 0 | 3,846,409 |
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int a, b, i;
int sum_a, sum_b;
sum_a = sum_b = 0;
for (i = 0; i < 4; i++){
scanf("%d", &a);
sum_a += a;
}
for (i = 0; i < 4; i++){
scanf("%d", &b);
sum_b += b;
}
printf("%d\n", max(sum_a, sum_b));
return (0);
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i, sz(v)) { if (i) os << " "; os << v[i]; } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a - mod; }
void solve();
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
T = 1;
while (T--) {
solve();
}
}
void solve() {
int n, m;
cin >> n >> m;
if (n % m == 0) cout << -1 << endl;
else cout << n << endl;
} | 0 | 14,400,020 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cstdio>
using namespace std;
map<char,int>M;
int cnv(string str){
str="."+str;
int res=0;
for(int i=0;i<str.length();i++){
if(M.find(str[i])!=M.end()){
int a;
if(str[i-1]>='0'&&str[i-1]<='9'){
a=str[i-1]-'0';
}
else a=1;
res+=M[str[i]]*a;
}
}
return res;
}
int main(){
M['m']=1000;M['c']=100;M['x']=10;M['i']=1;
int n;
scanf("%d",&n);
while(n--){
string s1,s2;
cin>>s1>>s2;
int val=cnv(s1)+cnv(s2);
if(val/1000){
if(val/1000>1)printf("%d",val/1000);
printf("m");
}
val%=1000;
if(val/100){
if(val/100>1)printf("%d",val/100);
printf("c");
}
val%=100;
if(val/10){
if(val/10>1)printf("%d",val/10);
printf("x");
}
val%=10;
if(val){
if(val>1)printf("%d",val);
printf("i");
}
puts("");
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
struct UnionFind {
vector<int> d;
UnionFind(int N) : 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() {
int n, m;
cin >> n >> m;
vector<int> p(n);
rep(i, n) cin >> p[i];
rep(i, n) p[i]--;
UnionFind uf(n);
rep(i, m){
int x, y;
cin >> x >> y;
x--;
y--;
uf.unite(x, y);
}
vector<int> q(n);
rep(i, n){
q[p[i]] = i;
}
int ans = 0;
rep(i, n){
if(uf.same(i, q[i])) ans++;
}
cout << ans << endl;
} | 0 | 45,606,217 |
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
using namespace std;
int main(){
int h,n;
cin>>h>>n;
vector<int> a(n);
rep(i,n) cin>>a[i];
sort(a.begin(),a.end());
bool flag=false;
rep(i,n){
h-=a[i];
if(h<=0){
flag=true;
break;
}
}
if(flag) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef pair<long long, long long> P;
int main(){
long long N, H;
cin >> N >> H;
vector<long long> a(N),b(N);
vector<P> v(N), u(N);
for(int i = 0; i < N; i++) {
cin >> a[i] >> b[i];
v[i] = P(a[i], b[i]);
u[i] = P(b[i], a[i]);
}
sort(v.begin(), v.end());
sort(u.begin(), u.end());
P t = v[N - 1];
long long ans = 0;
for(int i = N - 1; i >= 0; i--){
if(t.first <= u[i].first){
H -= u[i].first;
ans++;
}
if(H <= 0) break;
}
if(H <= 0){
cout << ans << endl;
return 0;
}
cout << ans + (H + t.first - 1) / t.first << endl;
} | 0 | 93,611,757 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
double x1,x2,y1,y2,s;
cin >> x1 >> y1 >> x2 >> y2;
s = sqrt( pow(x1 - x2, 2) + pow(y1 - y2, 2));
printf("%9.7f",s);
} | #include <stdio.h>
int main(void) {
int n;
int i;
scanf("%d", &n);
for(i=0; i<n; i++) {
int max, b, c;
scanf("%d %d %d", &max, &b, &c);
if (max < b) {
int tmp = max;
max = b;
b = tmp;
}
if (max < c) {
int tmp = max;
max = c;
c = tmp;
}
if (max * max == b*b + c*c) {
puts("YES");
} else {
puts("NO");
}
}
return 0;
} | 0 | 81,995,820 |
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;
int main(){
vector<string> table(305);
int n;cin >> n;
rep(i,n) cin >> table[i];
int ans = 0;
rep(t,n){
if(t > 0){
rep(i,n){
table[n-i] = table[n-1-i];
}
table[0] = table[n];
}
bool flag = true;
rep(i,n)rep(j,n){
if(table[i][j] != table[j][i]){
flag = false;
break;
}
}
if(flag) ans += n;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
long long f(long long k){
return (k*(k-1))/2;
}
int main(){
long long n;
long long now=0;
cin>>n;
vector<long long> p(n,0);
long long a[n];
for(int i=0;i<n;i++){
cin>>a[i];
a[i]--;
p[a[i]]++;
}
for(int i=0;i<n;i++){
now+=f(p[i]);
}
for(int i=0;i<n;i++){
long long k=now;
k=k-f(p[a[i]])+f(p[a[i]]-1);
cout<<k<<endl;
}
} | 0 | 7,219,426 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
if (a < b) return euclidean_gcd(b, a);
unsigned r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
ll ll_gcd(ll a, ll b) {
if (a < b) return ll_gcd(b, a);
ll r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
struct UnionFind {
vector <ll> par;
vector <ll> siz;
UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
for (ll i = 0; i < sz_; ++i) par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL);
for (ll i = 0; i < sz_; ++i) par[i] = i;
}
ll root(ll x) {
while (par[x] != x) {
x = par[x] = par[par[x]];
}
return x;
}
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y) return false;
if (siz[x] < siz[y]) swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) {
return root(x) == root(y);
}
ll size(ll x) {
return siz[root(x)];
}
};
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
long long modinv(long long a, long long mod) {
return modpow(a, mod - 2, mod);
}
vector<int> tpsort(vector<vector<int>>& G) {
int V = G.size();
vector<int> sorted_vertices;
queue<int> que;
vector<int> indegree(V);
for (int i = 0; i < V; i++) {
for (int j = 0; j < G[i].size(); j++) {
indegree[G[i][j]]++;
}
}
for (int i = 0; i < V; i++) {
if (indegree[i] == 0) {
que.push(i);
}
}
while (que.empty() == false) {
int v = que.front();
que.pop();
for (int i = 0; i < G[v].size(); i++) {
int u = G[v][i];
indegree[u] -= 1;
if (indegree[u] == 0) que.push(u);
}
sorted_vertices.push_back(v);
}
return sorted_vertices;
}
struct Point
{
double x;
double y;
};
struct LineSegment
{
Point start;
Point end;
};
double tenkyori(const LineSegment& line, const Point& point)
{
double x0 = point.x, y0 = point.y;
double x1 = line.start.x, y1 = line.start.y;
double x2 = line.end.x, y2 = line.end.y;
double a = x2 - x1;
double b = y2 - y1;
double a2 = a * a;
double b2 = b * b;
double r2 = a2 + b2;
double tt = -(a * (x1 - x0) + b * (y1 - y0));
if (tt < 0)
return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
else if (tt > r2)
return sqrt((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0));
double f1 = a * (y1 - y0) - b * (x1 - x0);
return sqrt((f1 * f1) / r2);
}
int main() {
ll n, t;
cin >> n >> t;
vector<ll> z(n);
for (int i = 0; i < n; i++) {
cin >> z[i];
}
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (z[i] < z[j])ans += t * (t - 1)/2;
if (z[i] > z[j])ans += t * (t + 1) / 2;
ans %= 1000000007;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isPossible(x) printf("%s\n",(x) ? "Possible" : "Impossible")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
#define pie 3.14159265358979323846
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}
const int MOD =(int)1e9+7;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
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;
}
}
ll 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;
}
ll gcd(ll a,ll b){
if(b==0)return a;
if(a>b){
swap(a,b);
}
return gcd(a,b%a);
}
ll lcm(ll a,ll b){
ll g;g=gcd(a,b);
return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
if(a.second != b.second){
return a.second < b.second;
}else{
return a.first < b.first;
}
}
bool compare_by_a(pair<int, int> a, pair<int, int> b) {
if(a.first != b.first){
return a.first < b.first;
}else{
return a.second < b.second;
}
}
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;
}
ll RS(ll N,ll P,ll M){
if(P==0){
return 1;
}else{
if(P%2==0){
ll t=RS(N,P/2,M);
return t*t%M;
}else{
return N*RS(N,P-1,M)%M;
}
}
}
bool greater_pair(pair<ll,ll> a,pair<ll,ll> b){
if(a.first!=b.first){
return a.first>b.first;
}else{
return a.second>b.second;
}
}
ll N,M,Q;
vector<string>A;
void dfs(ll i,ll j,string S){
if(i==N){
A.pb(S);
return;
}
for(int k=j;k<M;k++){
string Snew=S+to_string(k);
dfs(i+1,k,Snew);
}
}
string ans="A";
string func(string S){
if(S.length()<1){
return "";
}else{
return S.substr(1);
}
}
const int N_max=100100;
vector<int>dp(N_max,-1);
vector<vector<int>>path(N_max);
int main() {
ios::sync_with_stdio(false);
ll X,Y;
cin>>X>>Y;
ll ans=0;
if(X*Y>0){
if(X>Y){
ans+=2;
}
ans+=abs(Y-X);
}else if(X*Y<0){
ans=1+abs(X+Y);
}else{
if(X>Y)ans++;
ans+=abs(X+Y);
}
cout<<ans<<endl;
return 0;
} | 0 | 8,652,572 |
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
double x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
x2 -= x1; y2 -= y1;
printf("%.7lf\n", sqrt(x2*x2 + y2*y2));
} | #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b){
if(a==0) return b;
if (a < b) swap(a,b);
if (a % b == 0) return b;
return gcd(a % b, b);
}
ll lcm(ll a, ll b){
return a / gcd(a, b) * b;
}
ll countNonDivisor(ll x, ll c, ll d){
return x - x/c -x/d + x/lcm(c, d);
}
int main(){
ll n, x;
cin >> n >> x;
vector<ll>a(n, 0);
REP(i, n) cin >> a[i];
sort(ALL(a));
ll initDist = INF;
REP(i, n){
if (abs(a[i] - x) < initDist) initDist = abs(a[i]-x);
}
ll currGcd = initDist;
ll dist = 0;
REP(i, n-1){
dist = a[i+1] - a[i];
currGcd = gcd(currGcd, dist);
}
cout << currGcd << endl;
} | 0 | 21,558,492 |
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,last=0,num=0;
cin>>n;
for(int i=1;i<=n;i++){
long long x,y,sum;
cin>>x>>y;
num+=y;
sum=x*y+last;
while(sum>=10){
num+=sum/10;
sum=sum/10+sum%10;
}
last=sum;
}
cout<<num-1<<endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100100;
int N;
ll D[MAXN];
vector <int> edge[MAXN];
map <ll, int> ord;
map <ll, int> ssize;
map <ll, ll> stot;
int main()
{
ios_base::sync_with_stdio(0);
cin >> N;
for (int i = 0; i < N; i++)
{
cin >> D[i];
ord[D[i]] = i;
ssize[D[i]] = 1;
stot[D[i]] = 0;
}
for (auto it = ord.rbegin(); it != ord.rend(); it++)
{
ll cv = it -> first;
int ind = it -> second;
int csize = ssize[cv];
if (csize == N) break;
ll ntot = D[ind] - ((N - csize) - csize);
if (ord.find(ntot) == ord.end())
{
cout << "-1\n";
return 0;
}
ssize[ntot] += csize;
stot[ntot] += (stot[cv] + ssize[cv]);
edge[ord[ntot]].push_back(ind);
}
int mloc = 0;
for (int i = 0; i < N; i++)
if (D[i] < D[mloc])
mloc = i;
if (stot[D[mloc]] != D[mloc])
{
cout << "-1\n";
return 0;
}
else
{
for (int i = 0; i < N; i++)
{
for (int neigh : edge[i])
cout << neigh + 1 << " " << i + 1 << "\n";
}
}
} | 0 | 58,559,948 |
#include <iostream>
using namespace std;
int main(void){
int N, a, b, c, d, e, f, g, h, i;
cin >> N;
a = N % 10;
b = N % 100 / 10;
c = N % 1000 / 100;
d = N % 10000 / 1000;
e = N % 100000 / 10000;
f = N % 1000000 / 100000;
g = N % 10000000 / 1000000;
h = N % 100000000 / 10000000;
i = N % 1000000000 / 100000000;
int ans = a+ b+ c+ d+ e+ f+ g+ h+ i;
if(N % ans == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include <iostream>
using namespace std;
int main(){
int n,array[100][100],a,b,c;
for(int i = 0;i < 100;++i){
for(int j = 0;j < 100;++j){
array[i][j] = 0;
}
}
cin >> n;
for(int i = 0;i < n;++i){
cin >> a >> b;
for(int j = 0;j < b;++j){
cin >> c;
array[a - 1][c - 1] = 1;
}
}
for(int i = 0;i < n;++i){
for(int j = 0;j < n;++j){
if(j != 0) cout << " ";
cout << array[i][j];
}
cout << endl;
}
return 0;
} | 0 | 16,492,698 |
#pragma GCC optimize("O4")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF (1e17)
#define int ll
#define EPS (1e-6)
#define DB(x) #x<<" "<<x<<" "
using namespace std;
using ll=long long;
using pii=pair<int,int>;
int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p){
b%=MOD;
int ans=1;
while(p>0){
if(p&1) ans=(ans*b)%MOD;
p/=2;
b=(b*b)%MOD;
}
return ans;
}
int32_t main() {
#ifdef LOCAL_TEST
freopen("E:\\Jimmy\\2 Coding\\1 C++\\input.in","r",stdin);
freopen("E:\\Jimmy\\2 Coding\\1 C++\\output.out","w",stdout);
freopen("E:\\Jimmy\\2 Coding\\1 C++\\error.out","w",stderr);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int n,d,a; cin>>n>>d>>a;
vector<pii> v(n);
for(auto &i:v) cin>>i.F>>i.S;
sort(all(v));
queue<pii> bang;
int ans=0,now=0;
for(auto &i:v){
while(!bang.empty() && bang.front().F<i.F-d*2){
now-=bang.front().S;
bang.pop();
}
i.S=max(0ll,i.S-now*a);
int x=(i.S+a-1)/a;
bang.emplace(i.F,x);
ans+=x;
now+=x;
}
cout<<ans<<"\n";
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const 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 (b<a) {a=b; return 1;} return 0;}
#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif
int main() {
ll a, b; cin >> a >> b; b++;
int po = floor(log2(b))+1;
debug(po);
vector<pair<ll, ll>> bits(po+1, {0, 0});
rep(i, po+1) {
ll m = pow(2, i);
ll base = 0, add = 0;
base = a / m;
if (base%2!=0) {
add = a % m;
}
base /= 2;
bits[i].fi = base*m+add;
base = 0, add = 0;
base = b / m;
if (base%2!=0) {
add = b % m;
}
base /= 2;
bits[i].se = base*m+add;
}
ll ans = 0;
rep(i, po+1) {
debug(pow(2,i), bits[i].fi, bits[i].se, bits[i].se-bits[i].fi);
if ((bits[i].se-bits[i].fi)%2) ans += 1ll << i;
}
cout << ans << endl;
} | 0 | 15,604,399 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, H, W;
cin >> N;
cin >> H;
cin >> W;
int cnt=0;
for(int i=0; i<N; i++){
int a, b;
cin >> a;
cin >> b;
if(a>=H && b>=W) cnt++;
}
cout << cnt << endl;
} | #include <cstdio>
#include <vector>
const int MN = 100005;
int N;
std::vector<int> G[MN];
int DFS(int u, int p) {
int ret = 0;
for (int v : G[u]) if (v != p) ret ^= DFS(v, u) + 1;
return ret;
}
int main() {
scanf("%d", &N);
for (int i = 1, x, y; i < N; ++i)
scanf("%d%d", &x, &y),
G[x].push_back(y),
G[y].push_back(x);
puts(DFS(1, 0) ? "Alice" : "Bob");
return 0;
} | 0 | 91,536,708 |
#include <iostream>
using namespace std;
int n;
int F[45];
int fibo(int i) {
if (F[i]) {
return F[i];
}
F[i] = fibo(i - 1) + fibo(i-2);
return F[i];
}
int main() {
cin >> n;
F[0] = F[1] = 1;
cout << fibo(n) << endl;
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <set>
#define ll long long
using namespace std;
long long MOD = 1000000007;
int main(){
int N;
cin >> N;
vector<ll> pos(N,0);
for(int i=0; i<N; i++){
int x;
cin >> x;
x--;
pos[x]=i;
}
set<int> s;
s.insert(-1);
s.insert(N);
ll ans=0;
for(int i=0; i<N; i++){
ll p=pos[N-i-1];
s.insert(pos[N-i-1]);
if(i>0){
ll a,b,c,d;
a=b=MOD;
c=d=0;
auto it=s.find(p);
b=*(--it);
if(it!=s.begin()){
a=*(--it);
}
it=s.find(pos[N-i-1]);
c=*(++it);
++it;
if(it!=s.end()){
d=*it;
}
ans+=max(0LL,(b-a)*(c-p)*(N-i))+max(0LL,(p-b)*(d-c)*(N-i));
}
}
cout << ans << endl;
} | 0 | 83,690,828 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
int w,h,n;cin>>w>>h>>n;
vector<vector<int>> t(h,vector<int>(w,0));
rep(i,n){
int x,y,a;cin>>x>>y>>a;x--;y--;
switch(a){
case 1:
rep(j,h)rep(k,x+1)t[j][k]++;
break;
case 2:
rep(j,h)for(int k=x+1;k<w;k++)t[j][k]++;
break;
case 3:
rep(j,y+1)rep(k,w)t[j][k]++;
break;
case 4:
for(int j=y+1;j<h;j++)rep(k,w)t[j][k]++;
break;
}
}
int res=0;
rep(i,h)rep(j,w)if(t[i][j]==0)res++;
cout<<res<<endl;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
using ll = long long;
void PrintV(const vector<ll> v) {
for(int i = 0; i < v.size(); ++i)
cout << v[i] << "\t";
cout << endl;
}
int main() {
int n;
cin >> n;
vector<ll> v(n);
for(int i = 0; i < n; ++i)
cin >> v[i];
sort(v.begin(), v.end());
vector<ll> sumV(n, 0);
sumV[0] = v[0];
for(int i = 1; i < n; ++i)
sumV[i] += sumV[i - 1] + v[i];
int count = 1;
for(int i = n - 2; i >= 0; --i) {
if(v[i + 1] > 2 * sumV[i])
break;
count++;
}
cout << count << endl;
return 0;
} | 0 | 96,461,666 |
#include <stdio.h>
#define MAX 1000000
int isPrime[MAX];
int main(){
int num;
int i, j;
int count;
isPrime[0] = isPrime[1] = 0;
for(i = 2; i < MAX; i++){
isPrime[i] = 1;
}
for(i = 2; i * i < MAX; i++){
if(isPrime[i]){
for(j = 2 * i; j < MAX; j+=i){
isPrime[j] = 0;
}
}
}
while(scanf("%d", &num) != EOF){
count = 0;
while(num){
count += isPrime[num--];
}
printf("%d\n", count);
}
return 0;
} | #include <iostream>
#include <cstdio>
using namespace std;
long long mod = 1e9 + 7;
long long modpow(long long x, long long n) {
x = x%mod;
if(n == 0){
return 1;
}
else if(n%2 == 1){
return(x*modpow(x, n-1))%mod;
}
else{
return modpow((x*x)%mod, n/2)%mod;
}
}
long long comb(long long n, long long k){
long long x = 1;
for(long long i = n-k+1; i <= n; i++){
x = x*i;
x = x%mod;
}
long long y = 1;
for(long long i = 1; i <= k; i++){
y = y*i;
y = y%mod;
}
y = modpow(y, mod-2);
return x*y%mod;
}
int main(){
long long x, y;
cin >> x >> y;
if((-x + 2 * y) % 3 != 0 || (2*x - y) % 3 != 0){
printf("0\n");
return 0;
}
long long a = (-x + 2 * y)/3;
long long b = (2 * x - y)/3;
if(a < 0 || b < 0){
printf("0\n");
return 0;
}
long long ans = comb(a+b, a);
cout << ans << endl;
return 0;
} | 0 | 42,920,176 |
#include <cstdio>
#include <queue>
#include <map>
using namespace std;
typedef pair<int, int> P;
int a,b,n;
int point[20][20];
bool busy[20][20];
bool used[20][20];
int main(){
while(scanf("%d%d", &a, &b)){
if(a == 0 && b == 0) break;
for(int i = 0; i < 20; i++) for(int j = 0; j < 20; j++){
point[i][j] = 0;
busy[i][j] = 0;
used[i][j] = 0;
}
scanf("%d", &n);
point[1][1] = 1;
for(int i = 0; i < n; i++){
int x, y;
scanf("%d%d", &x, &y);
busy[y][x] = true;
}
if(busy[1][1]){
printf("0\n");
return 0;
}
queue<P> que;
que.push(P(1,1));
while(!que.empty()){
P p = que.front(); que.pop();
int pf = p.first, ps = p.second;
if(pf < b && busy[pf+1][ps] == false){
point[pf+1][ps] += point[pf][ps];
if(!used[pf+1][ps]) que.push(P(pf+1,ps));
used[pf+1][ps] = true;
}
if(ps < a && busy[pf][ps+1] == false){
point[pf][ps+1] += point[pf][ps];
if(!used[pf][ps+1]) que.push(P(pf,ps+1));
used[pf][ps+1] = true;
}
}
printf("%d\n", point[b][a]);
}
} | #include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
cerr << *it << " = " << a << "\n";
err(++it, args...);
}
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 100005
ll pro(ll a,ll b)
{
return (a*b)%M;
}
ll make(vi &v,int n)
{
int i,a=n-1;
ll temp=0,z;
reverse(all(v));
rep(i,n)
{
z=a;
z*=v[i],z%=M;
temp+=z;
a-=2;
}
return temp%M;
}
int main()
{
ll ans=1;
int n,m,i;
in2(n,m);
vi v;
v.resize(n);
read(v,i,n);
ans=pro(ans,make(v,n));
v.resize(m);
read(v,i,m);
ans=pro(ans,make(v,m));
llout(ans);
} | 0 | 97,174,693 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);
int main()
{
optimize();
string s;
cin>> s;
if(s[0] != 'A' )
{
cout<< "WA\n";
return 0;
}
int cn= 0;
for(int i=1; i<s.size(); i++)
{
if (i>=2 && i<= (s.size() -2 ))
{
if(s[i]== 'C')
{
cn++;
continue;
}
}
if(s[i]< 'a' || s[i] > 'z' || cn>1)
{
{
cout<< "WA\n";
return 0;
}
}
}
cout<< (cn==1? "AC\n" : "WA\n");
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
ll n;cin>>n;
vector<ll>a(n);
rep(i,n)cin>>a[i];
sort(all(a));
ll ma=a[n-1];
ll mi=ma;
ll j=a[0];
rep(i,n-1){
if(mi>abs((ma+1)/2-a[i])){
mi=abs((ma+1)/2-a[i]);
j=a[i];
}
}
cout<<ma<<' '<<j<<endl;
} | 0 | 18,447,067 |
#include <iostream>
#include<vector>
using namespace std;
int main(void){
int n;
cin >> n;
string s;
cin >> s;
vector<int> v(26,1);
for(int i = 0;i < s.size();i++){
v[s[i] - 'a']++;
}
long ans = 1;
for(int i = 0;i < v.size();i++){
ans = ans * v[i] % 1000000007;
}
ans = (ans - 1 + 1000000007) % 1000000007;
cout << ans << endl;
} | #include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
using namespace std;
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(unsigned int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
it != container.end(); ++it)
typedef long long ll;
typedef complex<double> P;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};
const double EPS = 1e-9;
const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};
string hidari = "qwertasdfgzxcvb";
string migi = "yuiophjklnm";
bool phidari(char c){
return find(all(hidari),c)!=hidari.end();
}
int main(){
while(true){
string s;
cin >> s;
if(s=="#") break;
bool fhidari = phidari(s[0]);
int c = 0;
for(int i=0;i<s.length();i++){
bool ishidari = phidari(s[i]);
if(ishidari != fhidari) c++;
fhidari = ishidari;
}
cout << c << endl;
}
return 0;
} | 0 | 67,152,715 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
vector<char> S(s.size());
for (int i = 0; i < s.size(); i++) {
S.at(i) = s.at(i);
}
int count = 0;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < s.size(); j++) {
if (S.at(i) == S.at(j)){
count++;
}
}
}
if (count == s.size()){
cout << "yes" << endl;
}
else {
cout << "no" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int X, Y, A, B, C;
cin >> X >> Y >> A >> B >> C;
vector<long long> p( A );
for( int i = 0; i < A; i++ ) {
cin >> p[i];
}
vector<long long> q( B );
for( int i = 0; i < B; i++ ) {
cin >> q[i];
}
vector<long long> r( C );
for( int i = 0; i < C; i++ ) {
cin >> r[i];
}
sort( p.begin(), p.end(), greater<long long>() );
sort( q.begin(), q.end(), greater<long long>() );
sort( r.begin(), r.end(), greater<long long>() );
long long ans = 0;
int pi = 0;
int qi = 0;
int ri = 0;
for( int i = 0; i < X + Y; i++ ) {
long long ma = 0;
int s = -1;
if( pi < min( X, A ) ) {
ma = p[pi];
s = 0;
}
if( qi < min( Y, B ) && q[qi] > ma ) {
ma = q[qi];
s = 1;
}
if( ri < C && r[ri] > ma ) {
ma = r[ri];
s = 2;
}
if( s == 0 ) pi++;
else if( s == 1 ) qi++;
else if( s == 2 ) ri++;
ans += ma;
}
cout << ans << endl;
} | 0 | 4,682,978 |
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int main() {
ios::sync_with_stdio(false);
int n, a;
cin >> n >> a;
if (n % 500 <= a) cout << "Yes";
else cout << "No";
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
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; }
int main(){
int H, N;
cin >> H >> N;
vector<int> A(N), B(N);
rep(i, N) cin >> A.at(i) >> B.at(i);
vector<vector<ll> > dp(N+1, vector<ll>(H+1, INF));
dp[0][0] = 0;
rep(i, N){
rep(j, H+1){
chmin(dp[i+1][j], dp[i][j]);
chmin(dp[i+1][min(j+A[i], H)], dp[i+1][j] + B[i]);
}
}
cout << dp[N][H] << endl;
} | 0 | 76,064,657 |
#pragma GCC diagnostic ignored "-Wunused-variable"
#include <bits/stdc++.h>
using namespace std;
#define BOOST
#ifdef BOOST
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/range/adaptor/reversed.hpp>
using namespace boost;
using ml = boost::multiprecision::cpp_int;
using md = boost::multiprecision::cpp_dec_float_100;
#define forir(i, ...) if(ll i=(ll)v.size())for(__VA_ARGS__)if(i--,1)
#define eachr(i, e, c) forir(i, auto &&e: adaptors::reverse(c))
#endif
using ll = long long;
using ld = long double;
using pll = pair<long long, long long>;
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
template <class T> using vvvt = vector<vector<vector<T>>>;
#define all(c) (c).begin(), (c).end()
#define coutld cout << fixed << setprecision(10)
#define output(x) do{cout<<x<<endl;exit(0);}while(0)
#define rep(i, b, e) for (ll i = b; i < e; i++)
#define repr(i, b, e) for (ll i = b; e < i; i--)
#define fori(i, ...) if (ll i = -1) for(__VA_ARGS__) if (i++, 1)
#define each(i, e, c) fori (i, auto&& e: c)
#define llong_max 9223372036854775807
#define ldbl_max 1.79769e+308
#define pi 3.1415926535897932
auto Ceil = []
(auto x) { return (ll)ceil(x); };
auto Count = []
(auto b, auto e, auto x) { return (ll)count(b, e, x); };
auto CtoL = []
(auto c) { return (ll)c - (ll)'0'; };
auto LtoC = []
(auto n) { return (char)('0' + n); };
auto Pow = []
(auto a, auto b) { return (ll)pow(a, b); };
auto Pow2 = []
(auto n) { return (1LL << n); };
auto Pow10 = []
(auto n) { return (ll)pow(10, n); };
auto Size = []
(auto& c) { return (ll)(c).size(); };
auto Sum = []
(auto b, auto e) { return accumulate(b, e, 0LL); };
template <class T> void MakeVVT
(ll ys, ll xs, vvt<T>& v, T fill = T())
{
v.resize(ys); rep(y, 0, ys) v[y].resize(xs, fill);
}
template <class T> void MakeVVVT
(ll zs, ll ys, ll xs, vvvt<T>& v, T fill = T())
{
v.resize(zs); rep(z, 0, zs) MakeVVT(ys, xs, v[z], fill);
}
template <class T> void InputVT
(ll xs, vt<T>& v, T fix = T())
{
v.resize(xs); rep(i, 0, xs) { cin >> v[i]; v[i] += fix; }
}
template <class T> void InputVVT
(ll ys, ll xs, vvt<T>& v, T fix = T())
{
MakeVVT(ys, xs, v, fix);
rep(y, 0, ys) rep(x, 0, xs) { cin >> v[y][x]; v[y][x] += fix; }
}
template <class T> void InputVVVT
(ll zs, ll ys, ll xs, vvvt<T>& v, T fix = T())
{
v.resize(zs); rep(z, 0, zs) InputVVT(ys, xs, v[z], fix);
}
namespace NyaGadget {}
using namespace NyaGadget;
int main(void)
{
ll N; cin >> N;
vt<ll> test(N); each(i, e, test) e = i + 1;
vt<ll> A(N); each(i, e, A) cin >> e;
vt<ll> B(N); each(i, e, B) cin >> e;
ll ans1 = 0;
ll ans2 = 0;
ll count = 1;
do {
rep(i, 0, N)
{
if (test[i] != A[i]) break;
if (i == N - 1) ans1 = count;
}
rep(i, 0, N)
{
if (test[i] != B[i]) break;
if (i == N - 1) ans2 = count;
}
count++;
} while (next_permutation(all(test)));
cout << abs(ans1 - ans2);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL,LL> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQGI;
typedef priority_queue<int, VI, greater<int>> PQLI;
typedef priority_queue<PII> PQGP;
typedef priority_queue<PII, VPII, greater<int>> PQLP;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EB emplace_back
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).rbegin(), (c).rend())
#define LB lower_bound
#define UB upper_bound
#define NEXP next_permutation
#define FI first
#define SE second
#define Vmin(a) *min_element((a).begin(),(a).end())
#define Vmax(a) *max_element((a).begin(),(a).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REPR(i,n) FORR(i,0,n)
#define BFOR(bit,a,b) for(int bit = (a); bit < (1<<(b)); ++bit)
#define BREP(bit,n) BFOR(bit,0,n)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/2;
const LL LINF = LLONG_MAX/3;
const int RINF = INT_MIN/2;
const LL RLINF = LLONG_MIN/3;
const LL MOD = 1e9+7;
const LL MODD = 998244353;
const int MAX = 510000;
inline bool Eq(double a, double b) { return fabs(b - a) < EPS; }
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; }
#define COUT(x) cout << (x) << endl
#define COUT2(x,y) cout << (x) << " " << (y) << endl
#define COUT3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl
#define PR(x) cout << (x)
#define ENDL cout << endl
#define SPACE cout << " "
#define BC(x) __builtin_popcountll(x)
VI dx = {1,0,-1,0,1,1,-1,-1};
VI dy = {0,1,0,-1,1,-1,1,-1};
VC dc = {'R','D','L','U'};
VS ds = {"R","D","L","U","RD","RU","LD","LU"};
LL Gcd(LL a, LL b) {return __gcd(a,b);}
LL Lcm(LL a, LL b) {return a/Gcd(a,b)*b;}
LL ModPow(LL A, LL N, LL M){
LL res = 1;
while(N>0){
if(N&1) res = res * A % M;
A = A * A % M;
N >>= 1;
}
return res;
}
template<class T> void VCout(vector<T> &v){
int N = SZ(v);
REP(i,N){
cout << v.at(i);
if(i == N-1) cout << endl;
else cout << " ";
}
return;
}
int main() {
cout << fixed << setprecision(12);
int n; cin >> n;
string s; cin >> s;
int l=0,res=0;
REP(i,n){
if(s.at(i)=='(') l++;
else if(l>0) l--;
else res++;
}
string ans(res,'(');
string t(l,')');
ans += s;
ans += t;
COUT(ans);
return 0;
} | 0 | 39,271,126 |
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <limits.h>
using namespace std;
int a[101][101];
int main(){
int n; scanf("%d",&n);
for (int i = 1; i <= n; ++i){
int u, k; scanf("%d %d",&u,&k);
int tmp;
while(k--){
scanf("%d",&tmp);
a[u][tmp] = 1;
}
}
for (int i = 1; i <= n; ++i){
for (int j = 1; j <= n; ++j){
if (j != 1) cout << ' ';
cout << a[i][j];
}
cout << '\n';
}
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<ll, ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repd(i,a,b) for(ll i=a;i>=b;--i)
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int>
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
#define INF 1e18
#define NINF -1e16
#define maxn 100005
int spf[maxn];
vll primes,prev[maxn],next[maxn];
set<int>s;
void sieve()
{
rep(i,2,maxn)
{
if (spf[i]==0)
{
spf[i]=i;
for(int j=2*i;j<=maxn;j+=i)
{
if(spf[j]==0)
spf[j]=i;
}
}
}
}
void SieveOfEratosthenes(int n)
{
bool prime[n+1];
memset(prime, true, sizeof(prime));
for (int p=2; p*p<=n; p++)
{
if (prime[p] == true)
{
for (int i=p*2; i<=n; i += p)
prime[i] = false;
}
}
for (int p=2; p<=n; p++)
{
if (prime[p])
{
primes.pb(p);
s.insert(p);
}
}
}
bool cmp(const pair<int,int>&a,const pair<int,int>&b)
{
if (a.F==b.F)
return a.S<b.S;
else
return a.F>b.F;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
srand (static_cast <unsigned> (time(0)));
sieve();
int t=1;
while (t--)
{
int n;
cin >> n;
vll a(n),b(n),c(n);
vll dp(3,0);
rep(i,0,n)
{
vll c(3),new_dp(3,INT_MIN);
rep(j,0,3)
cin >> c[j];
rep(j,0,3)
{
rep(k,0,3)
{
if(j!=k)
{
new_dp[k]=max(new_dp[k],dp[j]+c[k]);
}
}
}
dp=new_dp;
}
cout <<max({dp[0],dp[1],dp[2]})<<endl;
}
return 0;
} | 0 | 54,818,348 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll dp1[2010][2010];
ll dp2[2010][2010];
ll dp3[2010][2010];
ll dp4[2010][2010];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll h,w;
cin>>h>>w;
vector<string>s;
string s1;
for(ll i=0;i<h;i++)
{
cin>>s1;
s.push_back(s1);
}
for(ll i=1;i<=h;i++)
{
for(ll j=1;j<=w;j++)
{
if(s[i-1][j-1]=='#')
dp1[i][j]=0;
else
dp1[i][j]=dp1[i][j-1]+1;
}
for(ll j=w;j>=1;j--)
{
if(s[i-1][j-1]=='#')
dp2[i][j]=0;
else
dp2[i][j]=dp2[i][j+1]+1;
}
}
for(ll j=1;j<=w;j++)
{
for(ll i=1;i<=h;i++)
{
if(s[i-1][j-1]=='#')
dp3[i][j]=0;
else
dp3[i][j]=dp3[i-1][j]+1;
}
for(ll i=h;i>=1;i--)
{
if(s[i-1][j-1]=='#')
dp4[i][j]=0;
else
dp4[i][j]=dp4[i+1][j]+1;
}
}
ll maxi=0;
for(ll i=1;i<=h;i++)
{
for(ll j=1;j<=w;j++)
{
maxi=max(maxi,dp1[i][j]+dp2[i][j]+dp3[i][j]+dp4[i][j]-3);
}
}
cout<<maxi;
} | #include <stdio.h>
#include <string.h>
int main(){
int i;
char str[256];
char n[256];
scanf("%s", str);
int l = strlen(str);
for(i=0;i<l;i++)
n[i] = str[l-i-1];
printf("%s\n", n);
} | 0 | 19,905,757 |
#include "bits/stdc++.h"
#include <set>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>
void print(T x)
{
std::cout << x << " ";
}
template <typename T>
void println(T x)
{
std::cout << x << "\n";
}
signed main(void) {
int n;
cin >> n;
map<int, int>a;
rep(i, n) {
int tmp;
cin >> tmp;
a[tmp]++;
}
vector<int>b;
for (auto itr = a.rbegin(); itr != a.rend(); ++itr) {
if (b.size()>= 2)break;
int key = itr->first;
int value = itr->second;
if (value >= 2) {
b.pb(key);
}
if (value >= 4) {
if (b.size() < 2)b.pb(key);
}
}
if (b.size() < 2) {
print(0);
}
else {
print(b[0] * b[1]);
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;
typedef priority_queue<int, vector<int>, less<int>> bpqint;
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)
int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {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);
std::chrono::system_clock::time_point start,end;
start = std::chrono::system_clock::now();
ll h, w ;
cin >> h >> w ;
vector<vector<char>> grid(h,vector<char>(w)) ;
vvint seen(h,vint(w,0)) ;
vvint dist(h,vint(w,INF)) ;
queue<pii> que ;
int ans = 0 ;
REP(i,h){
string s ;
cin >> s ;
REP(j,w){
grid[i][j] = s[j] ;
}
}
REP(i,h){
REP(j,w){
if(grid[i][j]=='#'){
dist[i][j] = 0 ;
seen[i][j] = 0 ;
que.push(MP(i,j)) ;
}
}
}
while(!que.empty()){
int x, y ;
x = que.front().FI ;
y = que.front().SE ;
que.pop() ;
REP(k,4){
int nx = x + dx[k] ;
int ny = y + dy[k] ;
if(nx>=0 && nx<h && ny>=0 && ny<w && seen[nx][ny]==0){
if(grid[nx][ny]=='.'){
seen[nx][ny] = 1 ;
que.push(MP(nx,ny)) ;
dist[nx][ny] = dist[x][y] + 1 ;
ans = dist[nx][ny] ;
}
}
}
}
cout << ans <<endl;
end = std::chrono::system_clock::now();
auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
return 0;
} | 0 | 65,245,495 |
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;
int main(){
ll n, m; cin >> n >> m;
if(n*2 <= m){
cout << n + (m-n*2)/4 << endl;
}
else{
cout << min(n,m/2) << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int m;
cin>>m;
ll d[m],c[m];
ll dig=0,sum=0;
for(int i=0;i<m;i++){
cin>>d[i]>>c[i];
dig+=c[i];
sum+=d[i]*c[i];
}
cout<<(dig-1)+(sum-1)/9<<endl;
} | 0 | 13,224,787 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;
double equal(double a, double b) {
return fabs(a - b) < DBL_EPSILON;
}
std::istream &operator>>(std::istream &in, set<int> &o) {
int a;
in >> a;
o.insert(a);
return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
ll a;
in >> a;
o.push(a);
return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;
struct Task {
char direction;
ll cost;
};
int main() {
ll w, h;
cin >> w >> h;
vector<ll> horizontal(w);
vector<ll> vertical(h);
rep(i, w) cin >> horizontal[i];
rep(i, h) cin >> vertical[i];
vector<Task> task;
for (ll c : horizontal) task.push_back({'h', c});
for (ll c : vertical) task.push_back({'v', c});
sort(task.begin(), task.end(), [](Task t1, Task t2) {
return t1.cost < t2.cost;
});
ll a = w + 1, b = h + 1;
ll ans = 0;
for (Task t : task) {
if (t.direction == 'h') {
ll now = b * t.cost;
a--;
ans += now;
} else {
ll now = a * t.cost;
b--;
ans += now;
}
}
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,k;
cin>>a>>b>>c>>k;
long long s = 0;
if(a<=k){
s+=a;
k-=a;
}
else {
s+=k;
k=0;
}
if(k){
if(b<=k){
k=k-b;
}
else{
k=0;
}
if(k){
if(c<=k){
s-=c;
}
else{
s-=k;
}
}
}
cout<<s;
} | 0 | 37,712,830 |
#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(){
int n;
cin >> n;
const int NMAX = 100005;
vector<int> sum(NMAX) ;
REP(i,n){
int a;
cin >> a;
sum[a]++;
}
int cmax = 0;
REP2(i,1,NMAX-1){
int tmp = sum[i-1]+sum[i]+sum[i+1];
cmax = max(tmp,cmax);
}
cout << cmax << endl;
return 0;
} | #pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
cout << a;
return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
for (auto &a : vec) {
cout << a;
if (&a != &vec.back()) {
cout << " ";
}
}
return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
for (auto &v : vv) {
for (auto &a : v) {
cout << a;
if (&a != &v.back()) {
cout << " ";
}
}
if (&v != &vv.back()) {
cout << "\n";
}
}
return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
bool f = print_(head);
if (sizeof...(tail) != 0) {
cout << (f ? " " : "\n");
}
print(forward<Tail>(tail)...);
}
#pragma endregion
void Pr(bool f){
cout << (f ? "Yes" : "No") << "\n";
exit(0);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
ll w, h, x, y;
cin >> w >> h >> x >> y;
ll b = 0;
if(x*2==w&&y*2==h) b = 1;
print((ld)w*h/2, b);
} | 0 | 86,545,176 |
#include<iostream>
using namespace std;
long long int MOD = 1000000007;
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);
int main() {
int n, r;
cin >> n >> r;
if (n >= 10) {
cout << r << endl;
}
else {
cout << r + 100 * (10 - n) << endl;
}
return 0;
}
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
long long modinv(long long a, long long mod) {
return modpow(a, mod - 2, mod);
} | #include<bits/stdc++.h>
#define all(vc) vc.begin(),vc.end()
#define ll long long
#define MIN(a,b) ((a)<(b)) ? (a) : (b)
#define EVEN(a) (a)%2==0 ? 1 : 0
#define fi first
#define se second
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define DEBUG
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define mxel(vc) max_element(vc.begin(),vc.end())
#define mnel(vc) min_element(vc.begin(),vc.end())
using namespace std;
int MOD = 1e9+7;
long long int ji[300005];
long long int brut = 1e18;
int Search_Binary (int arr[], int left, int right, int key)
{
int midd = 0;
while (1)
{
midd = (left + right) / 2;
if (key < arr[midd]){
right = midd - 1;
}else if (key > arr[midd]){
left = midd + 1;
}else{
return midd;
}
if (left > right){
return -1;
}
}
}
int fDig(int i)
{
int k;
do
{
k=i;
i/=10;
}while(i);
return k;
}
int gcd (int a, int b) {
while (b) {
a %= b;
swap (a, b);
}
return a;
}
int lcm (int a, int b) {
return a / gcd (a, b) * b;
}
int to_int(string s){
int x;
stringstream geek(s);
geek >> x;
return x;
}
int prim_const( int x){
vector<bool> prime(x, true);
prime[0] = prime[1] = false;
for (int i=2; i * i<=x; ++i){
if (prime[i]){
if (i * 1ll * i <= x){
for (int j=i*i; j<=x; j+=i){
prime[j] = false;
}
}
}
}
if (prime[x] == true){
return 1;
}else{
return 0;
}
}
void solve(int n){
if(n % 2 == 0){
cout << (n/2)-1;
}else{
cout << (n/2);
}
}
long long int j;
long long int drujba=0;
int main()
{
cin.tie(0);cout.tie(0);
int n;
cin >>n;
solve(n);
cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
} | 0 | 84,845,779 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int n;
cin >>n;
long long int sum=0;
for(long long int i =1;i<=n;i++)
{
sum+=i;
}
cout << sum;
} | #include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl
void solve(long long N, long long A, long long B, std::vector<long long> P){
ll cntA=0, cntB=0, cntC=0;
A++; B++;
REP(i, N){
if(P[i]<A){
cntA++;
}
else if(P[i]<B){
cntB++;
}
else{
cntC++;
}
}
cout << min(cntA, min(cntB, cntC)) << endl;
}
int main(){
long long N;
scanf("%lld",&N);
long long A;
scanf("%lld",&A);
long long B;
scanf("%lld",&B);
std::vector<long long> P(N);
for(int i = 0 ; i < N ; i++){
scanf("%lld",&P[i]);
}
solve(N, A, B, std::move(P));
return 0;
} | 0 | 97,554,883 |
#include <cstdio>
#include <algorithm>
using namespace std;
long long A[300003], X[300003];
int main() {
int i, j, n, m, a, b;
scanf("%d%d%d", &n, &a, &b);
if (a + b > n + 1 || (long long)a * b < n) {
puts("-1");
return 0;
}
n -= a + b - 1;
m = 0;
for (i = 0; i < a; i++) for (j = 0; j < b; j++) {
if (i == 0 || j == 0 || n) {
A[m] = X[m] = (long long)i * 1000000 - j;
m++;
if (i && j) n--;
}
else break;
}
sort(X, X + m);
for (i = 0; i < m; i++) printf("%d ", upper_bound(X, X + m, A[i]) - X);
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001;
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);
vector<P> edge[100005];
vl seen(100005,INFL);
void dfs(int n,ll c,int m){
for(auto x:edge[n]){
if(x.first==m)continue;
seen[x.first]=min(seen[x.first],c+x.second);
dfs(x.first,seen[x.first],n);
}
}
int main(){
int n;cin>>n;
rep(i,n-1){
int a,b;cin>>a>>b;
a--;b--;
int c;cin>>c;
edge[a].push_back({b,c});
edge[b].push_back({a,c});
}
int q,k;cin>>q>>k;
k--;
dfs(k,0,-1);
rep(i,q){
int a,b;
cin>>a>>b;
a--;b--;
cout<<seen[a]+seen[b]<<endl;
}
} | 0 | 12,676,985 |
#include<cstdio>
#include<cstring>
int main(void){
int i,j;
int m[256];
int s[256]={0};
char c[256][201];
int d[256]={0};
int k=0;
while(1){
scanf("%s",c[k]);
if(strcmp(c[k],"-")==0) break;
while(c[k][d[k]]!='\0'){d[k]++;};
scanf("%d",&m[k]);
for(i=0;i<m[k];i++){
scanf("%d",&j);
s[k]=s[k]+j;
};
s[k]=s[k]%d[k];
k++;
}
for(i=0;i<k;i++){
for(j=0;j<d[i];j++){
c[i][j+d[i]]=c[i][j];
};
for(j=0;j<d[i];j++){
printf("%c",c[i][j+s[i]]);
};
printf("\n");
};
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)
const ll INF = 1LL << 60;
ll d[201][201];
struct edge{int from,to; ll cost;};
int main(){
int n,m,r;
cin >> n >> m >> r;
vector<edge> v(m);
rep(i,n){
rep(j,n){
if (i == j) d[i][j] = 0;
else d[i][j] = INF;
}
}
vector<int> per(r);
rep(i,r) {
cin >> per[i];
per[i]--;
}
rep(i,m){
int a,b;
ll c;
cin >> a >> b >> c;
d[a-1][b-1] = c;
d[b-1][a-1] = c;
}
for (int i= 0;i < n;i++){
for (int j = 0;j < n;j++){
for (int k = 0;k < n;k++){
d[j][k] = min(d[j][k],d[j][i]+d[i][k]);
}
}
}
ll ans = 1LL << 60;
sort(per.begin(),per.end());
do{
ll tmp = 0;
for (int i=0;i < r-1;i++){
tmp += d[per[i]][per[i+1]];
}
ans = min(ans,tmp);
}while(next_permutation(per.begin(),per.end()));
cout << ans << endl;
return 0;
} | 0 | 72,143,538 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
int r = 0;
for (int i = a; i <= b; i++)
{
int s = i % 10;
int t = i / 10000 % 10;
int u = i / 10 % 10;
int v = i / 1000 % 10;
if (s == t && u == v)
{
r++;
}
}
cout << r << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vdbl;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint;
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;
typedef priority_queue<int, vector<int>, less<int> > bpqint;
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;
#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define IREP(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {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 << "Yay!" << endl;
}
void no()
{
cout << ":(" << endl;
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int a, b ;
cin >> a >> b ;
if(a<=8 && b<=8){
yes() ;
}
else{
no() ;
}
return 0;
} | 0 | 60,001,898 |
#include <bits/stdc++.h>
using namespace std;
int main(void){
string s,t; cin >> s >> t;
vector<string> ans;
int l = s.size() - t.size() + 1;
for(int i = 0; i < max(l,0); i++){
string tmp = s;
for(int j = 0; j < t.size(); j++){
if(i + j > s.size() - 1)break;
if(tmp[i+j] == t[j] || tmp[i+j] == '?')tmp[i+j] = t[j];
else break;
if(j == t.size() - 1){
for(int k = 0; k < tmp.size(); k++){
if(tmp[k] == '?')tmp[k] = 'a';
}
ans.push_back(tmp);
}
}
}
sort(ans.begin(),ans.end());
if(ans.size()!=0)cout << ans[0] << endl;
else cout << "UNRESTORABLE" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int N, L, T; cin >> N >> L >> T;
int X[100100], W[100100];
for(int i=0; i<N; i++){
cin >> X[i] >> W[i];
}
int fin[100100];
int pos;
for(int i=0; i<N; i++){
if(W[i]==1){
fin[i] = (T+X[i]) % L;
}
if(W[i]==2){
fin[i]= (X[i]-T) %L;
if(fin[i]<0) fin[i] +=L;
}
}
pos=fin[0];
sort(fin,fin+N);
int num=0;
for(int i=1; i<N; i++){
if(W[i]==W[0]) continue;
int dis;
if(W[0]==1) dis=X[i]-X[0];
else dis=L-(X[i]-X[0]);
if(dis > 2*T) continue;
num += (2*T-dis)/L +1;
}
num %=N;
int ans[100100];
if(W[0]==1){
int x = upper_bound(fin,fin+N,pos)-fin-1;
for(int i=0; i<N; i++){
if(x+i < N){
ans[(num+i)%N] = fin[x+i];
}
else{
ans[(num+i)%N] = fin[x+i-N];
}
}
}
else{
int x =lower_bound(fin,fin+N,pos)-fin;
for(int i=0; i<N; i++){
if(x+i<N){
ans[(N-num+i)%N]=fin[x+i];
}
else{
ans[(N-num+i)%N]=fin[x+i-N];
}
}
}
for(int i=0; i<N; i++){
cout << ans[i] << endl;
}
} | 0 | 75,521,619 |
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int d;
while (cin >> d) {
int s = 0;
for (int i = d; i <= (600 - d); i+=d) {
s += pow(i, 2)*d;
}
cout << s << endl;
}
} | #include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
ll a[1010];
ll sum[1010];
ll bit[1010][50];
vector<ll> V;
int main()
{
int N;
ll K;
cin >> N >> K;
for (int i = 0; i < N; i++) cin >> a[i];
for (int i = 0; i < N; i++) {
sum[i + 1] = sum[i] + a[i];
}
for (int i = N; i > 0; i--) {
for (int j = 0; j < i; j++) {
V.push_back(sum[i] - sum[j]);
}
}
ll ans = 0;
for (ll i = 50; i >= 0; i--) {
ll sum = (1ll << i);
vector<ll> nv;
for (int j = 0; j < V.size(); j++) {
if ((sum & V[j]) == (1ll << i)) {
nv.push_back(V[j]);
}
}
if (nv.size() >= K) {
V = nv;
ans += sum;
}
}
cout << ans << endl;
} | 0 | 78,942,539 |
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
#include<unordered_map>
using namespace std;
const double pi=4*atan(1.0);
int mod=1000000007;
int main() {
int N;
cin>>N;
vector<int> arr(N);
for(auto& val:arr)
cin>>val;
vector<int> dp(N);
int ans=0;
dp[0]=arr[0];
for(int i=1;i<N;++i){
if(arr[i]>dp[ans]){
dp[++ans]=arr[i];
}
else{
int min=0,max=ans;
int mid;
while(1){
mid=(max-min)/2+min;
if(dp[mid]>arr[i]){
if(min==mid)break;
max=mid;
}
else if(dp[mid]<arr[i]){
if(min==mid){
++mid;
break;
}
min=mid;
}
else{
break;
}
}
dp[mid]=arr[i];
}
}
cout<<ans+1<<endl;
return 0;
} | #include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define dbg(x) cerr << #x << " = " << x << '\n'
#define sz(x) (int)x.size()
#define all(a) (a.begin(),a.end())
#define ff first
#define ss second
#define pii pair<int,int>
#define lcm(a,b) (a*b)/__gcd(a,b)
using namespace std;
inline void solve(){
string s; int n,k;
cin >> n >> k >> s ;
vi p0(n+1,0),p1(n+1,0);
n = 1;
if (s[0] == '0') p1[1] = 0, n++;
for (int i=1,c=1;i<sz(s);i++){
if (s[i] != s[i-1]) {
p1[n++] = c;
c = 1;
}
c += (s[i]==s[i-1]);
if (i==sz(s)-1) p1[n] = c;
}
for (int i=1;i<=n;i++) p1[i] += p1[i-1] ;
int ans=0;
for (int i=min(k*2+1,n);i<=n;i++){
if (i&1)
ans = max(ans,p1[i]-p1[max(0LL,i-(k*2+1))]);
else
ans = max(ans,p1[i]-p1[max(0LL,i-(k*2))]);
}
if(ans == 0) ans = n ;
cout << ans << endl;
}
signed main()
{
int n=1;
while (n--) solve();
return 0;
} | 0 | 78,104,122 |
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;
#pragma warning(disable: 4996)
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
#define _round(v) round(v)
#define _square(v) pow(v,2)
#define _cube(v) pow(v,3)
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
#define _stringtoi(s) stoi(s)
#define _sqrt(x) sqrt(x)
#define _ceil(x) ceil(x)
int main()
{
char c[3] = { 0 };
char temp;
uint32_t i;
for (i = 0; i < 3; i++) {
cin >> temp;
if (c[temp - 'a']) {
break;
}
c[temp - 'a']++;
}
if (i >= 3) {
printf("Yes\n");
}
else {
printf("No\n");
}
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define MAX 510000
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
int main(){
ll n; cin >> n;
char s[n][n];
rep(i,n) rep(j,n) cin >> s[i][j];
ll ans = 0;
rep(b,n){
bool flag = true;
rep(i,n-1){
REP(j,i,n){
if(s[i%n][(j+b)%n]!=s[j%n][(i+b)%n]){
flag = false;
break;
}
if(!flag) break;
}
if(!flag) break;
}
if(flag) ans++;
}
cout << ans*n << endl;
} | 0 | 98,382,077 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;
const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);
int main() {
int n,k;
cin>>n>>k;
char s[n];
rep(i,n)cin>>s[i];
vi d;
int nowc=1;
char now=s[0];
for (int i=1;i<n;i++){
if (now!=s[i]){
d.push_back(nowc);
nowc=1;
now=s[i];
}
else nowc+=1;
}
d.push_back(nowc);
int num=d.size();
if (k>=num/2 && s[0]=='1'){
cout<<n<<endl;
}
else if (s[0]=='0' && k>=double(num)/2.0){
cout<<n<<endl;
}
else{
if (s[0]=='1'){
int ans=0;
int ans1=0;
rep(i,k){
ans1+=d[2*i];
ans1+=d[2*i+1];
}
ans1+=d[2*k];
ans=ans1;
for (int i=1;i+2*k+1<num;i+=2){
ans1-=d[i-1];
ans1-=d[i];
ans1+=d[i+2*k];
ans1+=d[i+2*k+1];
ans=max(ans1,ans);
}
if (num%2==0){
int ans2=0;
rep(i,k){
ans2+=d[num-2*i-1];
ans2+=d[num-2*i-2];
}
ans=max(ans,ans2);
}
cout<<ans<<endl;
}
else{
int ans=0;
int ans1=0;
rep(i,k){
ans1+=d[2*i];
ans1+=d[2*i+1];
}
ans=ans1;
ans1-=d[0];
ans1+=d[2*k];
ans1+=d[2*k+1];
ans=max(ans1,ans);
for (int i=0;i+2*k+3<num;i+=2){
ans1-=d[i+1];
ans1-=d[i+2];
ans1+=d[i+2*k+2];
ans1+=d[i+2*k+3];
ans=max(ans1,ans);
}
int ans2=0;
if(num%2==1){
rep(i,k){
ans2+=d[num-2*i-1];
ans2+=d[num-2*i-2];
}
ans=max(ans,ans2);}
cout<<ans<<endl;
}
}
return 0;
} | #include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>
#define int long long
struct edge {
int to;
int cost;
};
using namespace std;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vb = vector<bool>;
using qi = queue<int>;
using P = pair<int, int>;
using graph = vector<vector<edge>>;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define delim(i, n) cout << (i == n-1 ? "\n" : " ");
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 int inf = 1LL << 60;
const int mod = 1000000007;
const int maxn = 200;
double a, b, x;
signed main () {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> a >> b >> x;
x /= a;
double y = x - a*b/2;
double ret;
if (y >= 0) {
double l = 2*y/a;
ret = atan2(a, b-l);
} else{
double l = 2*x/b;
ret = atan2(l, b);
}
ret = 90 - ret*180/M_PI;
cout << std::fixed << std::setprecision(10) << ret << "\n";
} | 0 | 13,011,401 |
#define rep(i,n) for (int i=0;i<n;i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int N,R;
cin>> N >> R;
if(N>=10)
cout << R << endl;
else
cout << R + 100*(10-N) <<endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
#define i_5 i_7-2
ll mod(ll a){
ll c=a%i_7;
if(c>=0)return c;
return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main(){fastio
ll d,t,s;cin>>d>>t>>s;
if(d>t*s){
cout<<"No"<<endl;
}else{
cout<<"Yes"<<endl;
}
return 0;
} | 0 | 50,671,953 |
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
return (a.second<b.second);
}
int main()
{
int p,q,r;
cin>>p>>q>>r;
int k=p+q;
int l=q+r;
int m=p+r;
cout<<min(k,min(l,m))<<endl;
} | #include <bits/stdc++.h>
using namespace std;
void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int maxN = 2e5+2;
void solve()
{
int n;
scn(n);
vl sum(n);
vi tak(n), aoki(n);
rep(i, 0, n) {
scn(tak[i]); scn(aoki[i]);
sum[i] = tak[i] + aoki[i];
}
vi order(n, 0); iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int i, int j){
return(sum[i] > sum[j]);
});
ll score = 0;
rep(i, 0, n) {
if(i & 1) {
score -= aoki[order[i]];
} else {
score += tak[order[i]];
}
}
lprin(score);
}
int main()
{
int t = 1;
while(t --) {
solve();
}
return 0;
} | 0 | 25,933,005 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <iomanip>
using namespace std;
int main()
{
int N;
cin >> N;
vector<double> v(N);
for (int i = 0; i < N; i++)
{
cin >> v.at(i);
}
sort(v.begin(), v.end());
double vv = v.front();
for (auto vi : v)
{
vv = (vv + vi) / 2.0;
}
cout << fixed << setprecision(10) << vv << endl;
} | #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
string s;
cin>>s;
bool flag=false;
int len=s.size();
for(int i=1;i<s.size();i++){
if((len-i)%2!=0)continue;
else{
string str1=s.substr(0,(len-i)/2);
string str2=s.substr((len-i)/2,(len-i)/2);
if(str1==str2){
cout<<len-i<<endl;
return 0;
}
}
}
return 0;
} | 0 | 19,114,678 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int main() {
int a,b,c;
cin >> a >> b >> c;
if(a < b && b < c){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
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; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
int main() {
init();
ll K, A, B;
cin >> K >> A >> B;
if(A<B-1){
ll tk = K - (A - 1);
if(tk<=1){
cout << K + 1 << endl;
return 0;
}
cout << tk / 2 * (B-A) + A + tk%2<< endl;
}else{
cout << K + 1 << endl;
}
} | 0 | 9,896,516 |
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#define LP(i,n) for(int i=0;i<n;i++)
#define Mset(x,v) memset(x,v,sizeof(x))
using namespace std;
using LL=long long;
int pk[10];
char D[10][5]={
{'*','*','*','*','*'},
{'.',',','!','?',' '},
{'a','b','c','*','*'},
{'d','e','f','*','*'},
{'g','h','i','*','*'},
{'j','k','l','*','*'},
{'m','n','o','*','*'},
{'p','q','r','s','*'},
{'t','u','v','*','*'},
{'w','x','y','z','*'}
};
int main(){
int n,curk=0;
string s;
cin>>n;
for(int i=0;i<n;i++){
string r;
Mset(pk,0);
cin>>s;
for(int j=0;j<s.size();j++){
switch(s[j]){
case '1':
curk=1;
pk[1]++;
if(pk[1]>5) pk[1]=1;
break;
case '2':
curk=2;
pk[2]++;
if(pk[2]>3) pk[2]=1;
break;
case '3':
curk=3;
pk[3]++;
if(pk[3]>3) pk[3]=1;
break;
case '4':
curk=4;
pk[4]++;
if(pk[4]>3) pk[4]=1;
break;
case '5':
curk=5;
pk[5]++;
if(pk[5]>3) pk[5]=1;
break;
case '6':
curk=6;
pk[6]++;
if(pk[6]>3) pk[6]=1;
break;
case '7':
curk=7;
pk[7]++;
if(pk[7]>4) pk[7]=1;
break;
case '8':
curk=8;
pk[8]++;
if(pk[8]>3) pk[8]=1;
break;
case '9':
curk=9;
pk[9]++;
if(pk[9]>4) pk[9]=1;
break;
case '0':
if(curk){
r+=D[curk][pk[curk]-1];
pk[curk]=0;
curk=0;
}
}
}
cout<<r<<endl;
}
return 0;
} | #include <bits/stdc++.h>
#include <vector>
#define rep(x, n) for(int i = x; i < (n); ++i)
using namespace std;
using ll = long long;
ll H, W;
vector<string> a(100);
int main(void)
{
cin >> H >> W;
rep(0, H) cin >> a.at(i);
vector<bool> row(H, false);
vector<bool> col(W, false);
for (int y = 0; y < H; ++y) {
for (int x = 0; x < W; ++x) {
if (a[y][x] == '#') {
row[y] = true;
col[x] = true;
}
}
}
for (int i = 0; i < H; ++i) {
if(row[i]) {
for (int j = 0; j < W; ++j) {
if (col[j]) {
cout << a[i][j];
}
}
cout << endl;
}
}
} | 0 | 35,435,879 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
int main()
{
ll q,h,s,d; cin>>q>>h>>s>>d;
ll n; cin >> n;
ll t = 8*q;
t = min(t, 4*h);
t = min(t, 2*s);
t = min(t, d);
ll u = min(4*q, 2*h);
u = min(u, s);
cout << (n/2)*t + (n%2)*u << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
using ll = long long;
int main() {
int n, k;
cin >> n >> k;
vector<int> p(n);
vector<int> c(n);
rep(i,n) {
int px;
cin >> px;
p[i] = px-1;
}
rep(i,n) cin >> c[i];
ll ans = LLONG_MIN;
rep(sp,n) {
int pos = sp;
vector<int> v;
ll tot = 0;
while (1) {
pos = p[pos];
v.push_back(c[pos]);
tot += c[pos];
if (pos == sp) break;
}
int l = v.size();
ll cum = 0;
rep(i,l) {
cum += v[i];
if (i+1 > k) break;
ll t = cum;
if (tot > 0) {
ll e = (k-i-1)/l;
t += tot*e;
}
ans = max(t, ans);
}
}
cout << ans << endl;
return 0;
} | 0 | 38,753,010 |
#include "bits/stdc++.h"
using namespace std;
void Main() {
int H, W, D;
cin >> H >> W >> D;
map<int, pair<int, int>> A;
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
int a;
cin >> a;
A.insert(make_pair(a, make_pair(i, j)));
}
}
int HW = H * W;
map<int, vector<int>> accums;
for (int i = 0; i < D; ++i) {
vector<int> acc;
acc.push_back(0);
int curr = (i == 0 ? D : i);
int next = i + D;
while (next <= HW) {
auto currA = A[curr];
auto nextA = A[next];
int cost = abs(currA.first - nextA.first) + abs(currA.second - nextA.second);
acc.push_back(acc.back() + cost);
curr = next;
next += D;
}
accums.insert(make_pair(i, acc));
}
int Q;
cin >> Q;
for (int q = 0; q < Q; ++q) {
int l, r;
cin >> l >> r;
const vector<int>& acc = accums[l % D];
int ans = acc[r / D] - acc[l / D];
cout << ans << endl;
}
}
int main() {
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
} | #include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
using ll = int64_t;
using namespace std;
ll n,m;
ll a[100010];
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
REP(i,n)cin >> a[i];
int two = 0;
REP(i,n){
if(i == 0){
ll x = a[i];
while(x % 2 == 0){
two++;
x /= 2;
}
}else{
ll x = a[i];
int y = 0;
while(x % 2 == 0){
y++;
x /= 2;
}
if(y != two){
cout << 0 << '\n';
return 0;
}
}
}
if(two != 0){
REP(i,n) a[i] /= 2;
}
ll L = 1;
REP(i,n){
L = (L * a[i]) / gcd(L,a[i]);
}
cout << (1 + m/L)/2 << '\n';
} | 0 | 19,422,392 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <chrono>
#include <ctime>
#include <queue>
#include <math.h>
#include <deque>
#include <stack>
#include <iomanip>
#include <assert.h>
#include <stdio.h>
#include <cstring>
#include <random>
using namespace std;
#define int long long
#define ld long double
#define ull unsigned long long
#define endl '\n'
#define try tr
#define pii pair<int, int>
#define ti tuple <int, int, int>
#define vi vector <int>
#define vpi vector <pii>
#define umap unordered_map
#define uset unordered_set
#define left left11
#define right right11
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define sqr(a) ((a) * (a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define X first
#define Y second
ld TL = 1.0;
bool is_tl = 0;
int CALLS = 0;
inline bool IS() {
if (++CALLS == 1000) {
CALLS = 0;
is_tl |= clock() > (TL - 0.1) * CLOCKS_PER_SEC;
}
return is_tl;
}
template<typename T1, typename T2>
inline void amin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2>
inline void amax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
os << p.first << ' ' << p.second << endl;
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>
ostream &operator<<(ostream &os, vector<T> &v) {
for (auto &u : v) os << u << ' ';
os << endl;
return os;
}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e6 + 7, NS = 2e3 + 7, lg = 19, sq = 550, inf = 2e9 + 7, SM = 1e2 + 7;
const ld eps = 1e-9;
int hash_mod[4] = {1000000007, 998244353, 1000000009, 999999937}, mod = hash_mod[rnd() % 4];
int hash_pows[4] = {179, 239, 1007, 2003}, P = hash_pows[rnd() % 4];
void solve() {
int n;
cin >> n;
vi a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
multiset <int> s(all(a));
int mx = *(--s.end());
for (int i = mx; i >= (mx + 1) / 2; i--) {
if(s.find(i) == s.end()) {
cout << "Impossible\n";
return;
}
s.erase(s.find(i));
if(mx % 2 != 0 || i != (mx + 1) / 2) {
if(s.find(i) == s.end()) {
cout << "Impossible\n";
return;
}
s.erase(s.find(i));
}
}
for (auto u : s) {
if(u <= mx && u > (mx + 1) / 2) {
continue;
}
cout << "Impossible\n";
return;
}
cout << "Possible";
}
signed main() {
fast
solve();
} | #include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
int32_t main ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int x;
cin>>x;
if(x<600)cout<<"8"<<endl;
else if(x<800)cout<<"7"<<endl;
else if(x<1000)cout<<"6"<<endl;
else if(x<1200)cout<<"5"<<endl;
else if(x<1400)cout<<"4"<<endl;
else if(x<1600)cout<<"3"<<endl;
else if(x<1800)cout<<"2"<<endl;
else if(x<2000)cout<<"1"<<endl;
return 0;
} | 0 | 59,620,214 |
#include <iostream>
#include<algorithm>
using namespace std;
int main(void){
int A,B,m;
cin>>A>>B>>m;
int a[A];
int b[B];
for (int i = 0; i<A;i++){
cin>>a[i];
}
for (int i = 0; i<B;i++){
cin>>b[i];
}
int x[m];
int y[m];
int c[m];
for (int i = 0; i<m;i++){
cin>>x[i]>>y[i]>>c[i];
}
int ans = 1010001000;
for (int i = 0; i<m;i++){
ans = min({ans,a[x[i]-1]+b[y[i]-1] -c[i]});
}
sort(a,a+A);sort(b,b+B);
ans = min({ans,a[0]+b[0]});
cout<<ans;
} | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define Cinint(n) int n;\
cin >> n;
#define Cinvecint(a, n) vector<int> a(n);\
for (int i = 0; i < (int)(n); i++) {\
int num;\
cin >> num;\
a.at(i) = num;\
}
#define Cinstring(s) string s;\
cin >>s;
int main() {
bool flag = true;
string s;
cin >> s;
string s_rev;
s_rev = s;
int n;
n = s.size();
reverse(s_rev.begin(), s_rev.end());
if (s_rev == s) {
string s2 = s.substr((n+3)/2-1);
string s1 = s.substr(0, (n-1)/2);
string s1_rev = s1;
string s2_rev = s2;
reverse(s1_rev.begin(), s1_rev.end());
reverse(s2_rev.begin(), s2_rev.end());
if (s1_rev == s1) {
if (s2_rev == s2) {
coYes;
flag = false;
}
}
}
if (flag) {
coNo;
}
} | 0 | 99,363,044 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
int A, B;
cin >> A >> B;
bool one = false;
if ((A == 1) || (B == 1)) {
one = true;
}
if (one) {
if (A == 1 && B == 1) {
cout << "Draw" << endl;
} else if (A == 1) {
cout << "Alice" << endl;
} else {
cout << "Bob" << endl;
}
}
if (!one) {
if (A > B) {
cout << "Alice" << endl;
} else if (A < B) {
cout << "Bob" << endl;
} else {
cout << "Draw" << endl;
}
}
return 0;
} | #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>
#include <bitset>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define eps 1e-9
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x7fffffff;
int n, m, d, x, y;
char s[] = {'B', 'G', 'Y', 'R'};
int main() {
#ifdef __AiR_H
freopen("B.in", "r", stdin);
#endif
scanf("%d %d %d", &n, &m, &d);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
x = (i + j - 1) / d; y = (n - i + j) / d;
if (x % 2 == 1) {
if (y % 2 == 1) { printf("%c", s[0]); } else { printf("%c", s[1]); }
} else {
if (y % 2 == 1) { printf("%c", s[2]); } else { printf("%c", s[3]); }
}
}
printf("\n");
}
#ifdef __AiR_H
printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);
#endif
return 0;
} | 0 | 13,139,298 |
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
int main(){
int a, b, c, k;
cin >> a >> b >> c >>k;
if(k<=a){
cout << k << endl;
return 0;
}
if(k<=a+b){
cout << a << endl;
return 0;
}
if(k<=a+b+c){
int d = k-a-b;
cout << a-d << endl;
return 0;
}
} | #include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;
#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)
#define en "\n"
constexpr double EPS = 1e-9;
constexpr double PI = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007;
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
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; }
void Main(){
string n;
cin >> n;
REP(i, n.size()) {
if (n[i] == '7') {
cout << "Yes" << en;
return;
}
}
cout << "No" << en;
return;
}
int main(void){
cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
int t=1;
REP(_,t) Main();
return 0;
} | 0 | 99,259,824 |
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
return string(1, val);
}
int char_to_int(char val) {
return val - '0';
}
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() {
int A, B, K; cin >> A >> B >> K;
vector<int> C;
int i = 1;
while(i <= min(A, B)) {
if(A % i == 0 && B % i == 0) {
C.push_back(i);
}
i++;
}
cout << C[C.size() - K] << endl;
} | #include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define ss second
#define ff first
#define INF 30000000000001
#define ll_max 9000000000000000001
#define mod 1000000007
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef vector<pair<ll,ll> > vll;
typedef vector<pair<int,int> > vii ;
typedef pair<ll,ll> pll;
const ll N = 100001;
const ll M = 1;
void update(ll BIT[], ll n, ll x, ll i)
{
for(; i <= n; i += (i) & (-i)) BIT[i] += x;
}
ll query(ll BIT[], ll l)
{
ll sum1 = 0;
for(; l; l = l & (l - 1)) sum1 += BIT[l];
return sum1;
}
int main()
{
fast;
int _ = 1;
while(_--)
{
ll n, x, y;
cin >> n;
pair<long double, pair<int,int> > a[2 * n];
long double ans = 0;
for(int i = 0; i < n; i++)
{
cin >> x >> y;
a[i].ff = atan2(y, x);
a[i].ss.ff = x;
a[i].ss.ss = y;
}
sort(a, a + n);
for(int i = n; i < 2 * n; i++) a[i] = a[i - n], a[i].ff += 2 * PI;
for(int i = 0; i < 2 * n; i++)
{
x = 0, y = 0;
for(int j = i; j < 2 * n; j++)
{
x += a[j].ss.ff;
y += a[j].ss.ss;
if(a[j].ff - a[i].ff < PI)
{
ans = max((ll)ans, x * x + y * y);
}
else break;
}
}
ans = sqrt(ans);
cout << fixed << setprecision(11) << ans << "\n";
}
return 0;
} | 0 | 98,369,194 |
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;
int main() {
int n;
cin >> n;
int cnt = 0;
for(int i = 1; i <= n; i++) {
string s = to_string(i);
int cmp = s.length();
if(cmp % 2 == 1) cnt++;
}
cout << cnt << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
int n;
string s;
cin >> n >> s;
int ans = 0;
rep(i, 1000) {
int t = i;
int cnt = 0;
for (int j = n - 1; j >= 0; j--) {
if (s[j] - '0' == t % 10) {
cnt++;
t /= 10;
if (cnt == 3) {
ans++;
break;
}
}
}
}
cout << ans << endl;
return 0;
} | 0 | 26,762,975 |
#include<iostream>
using namespace std;
int main(){
int n,a[101],minj,tmp,cnt=0;
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n-1;i++){
minj=i;
for(int j=i;j<n;j++)if(a[j]<a[minj])minj=j;
tmp=a[i];
a[i]=a[minj];
a[minj]=tmp;
if(i!=minj)cnt++;
}
for(int i=0;i<n-1;i++)cout<<a[i]<<" ";
cout<<a[n-1]<<endl<<cnt<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
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 main() {
ll N, M; cin >> N >> M;
vector<pair<ll, ll>> AB(N);
rep(i, N) {
ll x, y; cin >> x >> y;
AB[i] = make_pair(x, y);
}
sort(ALL(AB));
ll cnt = 0, money = 0;
for (auto ab : AB) {
cnt += ab.second; money += (ab.second * ab.first);
if (M < cnt) {
ll diff = cnt - M;
cnt -= diff; money -= (diff * ab.first);
break;
}
}
cout << money << endl;
} | 0 | 86,642,618 |
#include<bits/stdc++.h>
using namespace std;
#define STR_MAX 1000
int mat[STR_MAX+1][STR_MAX+1];
int common_subsequence(int len1, int len2, string str1, string str2){
int i, j;
for(i=1; i<=len1; i++){
for(j=1; j<=len2; j++){
if(str1[i-1] == str2[j-1]) mat[i][j]=mat[i-1][j-1]+1;
else mat[i][j]=max(mat[i-1][j], mat[i][j-1]);
}
}
return mat[len1][len2];
}
int main(void){
int i, n;
string str1, str2;
scanf("%d", &n);
for(i=0; i<n; i++){
cin >> str1 >> str2;
int len1=str1.size(), len2=str2.size();
printf("%d\n", common_subsequence(len1, len2, str1, str2));
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
int p[20000];
rep(i, N) cin >> p[i];
int a[20001], b[20001];
rep1(i, N) {
a[i] = i * 30000;
b[i] = (N - i + 1) * 30000;
}
rep(i, N) {
a[p[i]] += i;
}
rep1(i, N) cout << a[i] << (i == N ? '\n' : ' ');
rep1(i, N) cout << b[i] << (i == N ? '\n' : ' ');
Would you please return 0;
} | 0 | 51,440,892 |
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int main(){
int n;
cin >> n;
int num = 1;
int ans;
for(int i = 1; i <= n; i++){
if(num == n){
ans = num;
break;
}
else if( num > n ){
ans = num / 2;
break;
}
num *= 2;
}
cout << ans << endl;
} | #include <iostream>
#include <cctype>
#include <stdio.h>
using namespace std;
int main(void){
char ch;
while(1){
scanf("%c", &ch);
if(islower(ch)){
cout << static_cast<char>(toupper(ch));
}else if(isupper(ch)){
cout << static_cast<char>(tolower(ch));
}else{
cout << ch;
}
if ( ch == '\n' ) break;
}
} | 0 | 6,506,427 |
#include <bits/stdc++.h>
using namespace std;
#define ref(i,c,n) for(int i = n;i<c;i++)
int main()
{
int n;
cin>>n;
int arr[n],l = 100,r = 0,ans = 100000000;
ref(i,n,0)
{
cin>>arr[i];
l = min(arr[i],l);
r = max(arr[i],r);
}
for(int i = l;i<=r;i++)
{
int temp = 0;
ref(j,n,0)
{
temp += (arr[j]-i)*(arr[j]-i);
}
ans = min(ans,temp);
}
cout<<ans<<endl;
return 0;
} | #include <stdio.h>
int a[3][3];
int n;
int b[10];
int main()
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
scanf("%d",&a[i][j]);
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&b[i]);
bool memo[3][3]={};
for(int i=0;i<n;i++)
{
for(int j=0;j<3;j++)
for(int k=0;k<3;k++)
if(a[j][k]==b[i])memo[j][k]=true;
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(memo[i][j]==false)
{
break;
}
if(j==2)
{
printf("Yes\n");
return 0;
}
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(memo[j][i]==false)
{
break;
}
if(j==2)
{
printf("Yes\n");
return 0;
}
}
}
for(int i=0;i<3;i++)
{
if(memo[i][i]==false)
{
break;
}
if(i==2)
{
printf("Yes\n");
return 0;
}
}
for(int i=0;i<3;i++)
{
if(memo[i][2-i]==false)
{
break;
}
if(i==2)
{
printf("Yes\n");
return 0;
}
}
printf("No\n");
return 0;
} | 0 | 86,010,725 |
#include <iostream>
#include <vector>
#define ll long long
using namespace std;
int main() {
cin.tie(0); ios::sync_with_stdio(false);
while (true) {
int a, b; cin >> a >> b;
if (a == 0 && b == 0)break;
int n; cin >> n;
vector<vector<ll>> f(a + 1, vector<ll>(b + 1, false));
vector<vector<ll>> dp(a + 1, vector<ll>(b + 1, 0));
for (int i = 0; i < n;i++) {
int A, B; cin >> A >> B;
f[A][B] = true;
}
dp[1][1] = 1;
for (int i = 1; i <= a;i++) {
for (int j = 1; j <= b;j++) {
if (i == 1 && j == 1)continue;
if (!f[i][j]) dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
}
}
cout << dp[a][b] << endl;
}
} | #include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
struct Edge{
int to;
int weight;
Edge(int t, int w) : to(t), weight(w){ }
};
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
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>
T lcm(T a, T b){
return (a*b)/gcd(a,b);
}
int INF = 1e9+7;
vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};
int main(){
string s;
cin >> s;
vector<int> a(26,0);
rep(i,s.size()){
a[s[i]-'a']++;
}
if(s.size()<26){
rep(i,26){
if(a[i]) continue;
else{
cout << s << char('a'+i) << endl;
return 0;
}
}
}
else{
rrep(i,s.size()-1){
if(s[i+1]<s[i]){
continue;
}
else{
int ans = INF;
for(int j = i+1; j<s.size(); j++){
if(s[i]<s[j]){
chmin(ans,s[j]-0);
}
}
rep(j,i){
cout << s[j];
}
cout << char(ans) << endl;
return 0;
}
}
cout << -1 << endl;
}
return 0;
} | 0 | 99,014,535 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0, 0};
int dy[] = { 0, 0, 1, -1};
int main(){
ll h, w;
cin >> h >> w;
if(h==1){
if(w==1){
cout << 1 << endl;
}else{
cout << w-2 << endl;
}
return 0;
}else if(w==1){
cout << h-2 << endl;
return 0;
}
ll ans = (h-2)*(w-2);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long int li;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector<ll> a(n,0);
for (int i=0; i<n; i++) cin >> a[i];
vector<ll> s(n+1, 0);
map<ll, ll> nums;
for (int i=0; i<n; i++) s[i+1] = s[i] + a[i];
for (int i=0; i<n+1; i++) nums[s[i]]++;
ll res = 0;
for (auto it : nums) {
ll num = it.second;
res += num * (num-1) / 2;
}
cout << res << "\n";
return 0;
} | 0 | 48,028,430 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> divisor(ll n) {
vector<ll> 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.begin(), ret.end());
return ret;
}
int main(){
ll N; cin >> N;
vector<ll> result{};
result = divisor(N);
int len = result.size()/2;
if(result.size() %2 ==0) cout << result[len] - 1 + result[len-1] -1 << endl;
else cout << result[len] - 1 + result[len] -1 << endl;
} | #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
using namespace std;
map< char, int > m;
map< int, string > mm;
int sToi(string s){
int ret = 0;
REP(i,0,s.size()){
int tmp = 1;
if(isdigit(s[i])){
ret += (s[i] - '0') * m[s[i+1]];
i++;
}else{
ret += m[s[i]];
}
}
return ret;
}
string iTos(int num){
string s = "";
int tmp = 1000;
REP(i,0,4){
if(num / tmp > 1) s += to_string(num / tmp) + mm[tmp];
else if(num / tmp == 1) s += mm[tmp];
num %= tmp;
tmp /= 10;
}
return s;
}
int main() {
int n;
cin>>n;
m['i'] = 1;
m['x'] = 10;
m['c'] = 100;
m['m'] = 1000;
mm[1] = "i";
mm[10] = "x";
mm[100] = "c";
mm[1000] = "m";
REP(i,0,n){
string s1, s2;
cin>>s1>>s2;
cout<<iTos(sToi(s1) + sToi(s2))<<endl;
}
return 0;
} | 0 | 28,953,435 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int W,H,N;
cin >> W >> H >> N;
vector<vector<int>> m(H,vector<int>(W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
m.at(i).at(j)=1;
}
}
for(int i=0;i<N;i++){
int x,y,a;
cin >> x >> y >> a;
if(a==1){
for(int j=0;j<x;j++){
for(int k=0;k<H;k++){
m.at(k).at(j)=0;
}
}
}
else if(a==2){
for(int j=x;j<W;j++){
for(int k=0;k<H;k++){
m.at(k).at(j)=0;
}
}
}
else if(a==3){
for(int j=0;j<y;j++){
for(int k=0;k<W;k++){
m.at(j).at(k)=0;
}
}
}
else if(a==4){
for(int j=y;j<H;j++){
for(int k=0;k<W;k++){
m.at(j).at(k)=0;
}
}
}
}
int ans=0;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
ans += m.at(i).at(j);
}
}
cout << ans << endl;
} | #include<stdio.h>
#include<iostream>
#include<utility>
#include<string.h>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))
int main()
{
char ban[10][10]={{},{'.',',','!','?',' ','#'},{'a','b','c','#'},{'d','e','f','#'},{'g','h','i','#'},{'j','k','l','#'},{'m','n','o','#'},{'p','q','r','s','#'},{'t','u','v','#'},{'w','x','y','z','#'}};
char in[1025]={};
int a;
scanf("%d\n",&a);
while(a-->0)
{
REP(i,1025)in[i]='\0';
scanf("%s\n",in);
if(in[0]=='\0')return 0;
char *a=&in[0];
int num=0;
int row=0;
while(*a!='\0')
{
if(*a=='0')
{
if(ban[row][num]!='\0')printf("%c",ban[row][num]);
row=0;
num=0;
}
else if(row==*a-'0')
{
num++;
if(ban[row][num]=='#')num=0;
}
else if(row!=*a-'0')
{
row=*a-'0';
num=0;
}
a++;
}
if(ban[row][num]!='\0')printf("%c",ban[row][num]);
printf("\n");
}
return 0;
} | 0 | 91,760,253 |
#include <bits/stdc++.h>
using namespace std;
bool solve(int n) {
int cnt = 0;
for (int i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
if (i == n % i) {
cnt++;
} else {
cnt += 2;
}
}
}
if (cnt == 8) {
return true;
} else {
return false;
}
}
int main() {
int n, ans = 0;
cin >> n;
for (int i = 1; i <= n; i += 2) {
if (solve(i)) ans++;
}
cout << ans << endl;
} | #include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;
#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
typedef long long ll;
typedef long double ld;
typedef pair<int, ll> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
template<typename T, typename U>
size_t operator()(const pair<T, U> &x) const {
size_t seed = hash<T>()(x.first);
return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
}
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
int n;
ll l;
ll a[100100];
void solve() {
for (int i = 0; i < n-1; i++) {
if (a[i] + a[i+1] >= l) {
cout << "Possible" << endl;
for (int j = 1; j <= i; j++) {
cout << j << endl;
}
for (int j = n-1; j >= i+1; j--) {
cout << j << endl;
}
return;
}
}
cout << "Impossible" << endl;
}
void input() {
cin >> n >> l;
for (int i = 0; i < n; i++) cin >> a[i];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
input();
solve();
} | 0 | 95,111,170 |
#include <bits/stdc++.h>
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
struct Vec{
double x, y;
};
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 min(T a, T b)
{
if (a < b) return a;
return b;
}
template<class T>
T max(T a, T b)
{
if (a > b) return a;
return b;
}
using namespace std;
int board[3][3];
int main()
{
vector <int> num(100);
rep(i, 3)rep(k, 3){
int A;
cin >> A;
board[i][k]=A;
num[A] = 1;
}
int N;
cin >> N;
rep(i,N) {
int m;
cin >> m;
if (num[m] == 1){
rep(i, 3) rep(k, 3) if (board[i][k] == m) board[i][k] = 0;
}
}
int row = 0, col = 0, rcross = 0, lcross = 0;
rep(i, 3){
rep(k, 3){
col += board[i][k];
row += board[k][i];
if (i == k) rcross += board[i][k];
if (i == (2 - k)) lcross += board[i][k];
}
if (col == 0 || row == 0) {
cout << "Yes" << endl;
return 0;
}
col = 0; row = 0;
}
if (lcross == 0 || rcross == 0) {
cout << "Yes" << endl;
return 0;
}
cout << "No" << endl;
return 0;
} | #include<iostream>
#include<algorithm>
using namespace std;
int p[101] = {};
int q[101] = {};
int main(){
int X, N = 0;
cin >> X >> N;
if(N == 0){
cout << X << endl;
return 0;
}
int flag = 1;
for(int i = 0; i < N; i++){
cin >> p[i];
if(p[i] == X){
flag = 0;
}
}
if(flag){
cout << X << endl;
return 0;
}
int result = 0;
for(int i = 0; i < 100; i++){
flag = 1;
for(int j = 0; j < N; j++){
if(p[j] == X - i){
flag = 0;
break;
}
}
if(flag){
cout << X - i << endl;
return 0;
}
flag = 1;
for(int j = 0; j < N; j++){
if(p[j] == X + i){
flag = 0;
break;
}
}
if(flag){
cout << X + i << endl;
return 0;
}
}
return 0;
} | 0 | 25,482,059 |
#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>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define 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 a,p; cin>>a>>p;
int b=a*3;
cout<<(b+p)/2;
return 0;
} | #include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }
LL paintCount(LL n, vector<LL>& h, LL i, LL j){
LL cnt = 0;
LL left = 0;
if(i > 0) left = h[i-1];
for(LL cur = i; cur <= j; ++cur){
cnt += max(0LL, h[cur] - left);
left = h[cur];
}
return cnt;
}
LL paintCount2(LL n, vector<LL>& h, LL i, LL j){
LL left = 0;
if(i > 0) left = h[i-1];
return max(0LL, h[j] - left);
}
int main(){
LL n, k;
cin >> n >> k;
vector<LL> h(n+1);
for(LL i = 0; i < n; ++i){
cin >> h[i];
}
vector<vector<LL>> dp(n+2, vector<LL>(k+1));
for(LL i = 0; i <= n; ++i){
for(LL j = i; j <= n; ++j){
for(LL b = 0; b <= k; ++b){
dp[j+1][b] = max(dp[j+1][b], dp[i][b]);
}
}
for(LL j = i+1; j <= n; ++j){
LL cnt = paintCount(n, h, i, j) - paintCount2(n, h, i, j);
for(LL b = 0; b < k; ++b){
if(b+j-i > k) continue;
dp[j+1][b+j-i] = max(dp[j+1][b+j-i], dp[i][b] + cnt);
}
}
}
for(auto row: dp){
}
LL total = paintCount(n, h, 0, n);
cout << total - dp[n+1][k] << endl;
return 0;
} | 0 | 3,508,834 |
#include <bits/stdc++.h>
#define FASTIO
using namespace std;
using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();
void solve() {
string S;
cin >> S;
for (auto& c : S) {
if (c == ',') {
c = ' ';
}
}
cout << S << "\n";
}
int main() {
#ifdef FASTIO
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
ifstream ifs("./in_out/input.txt");
cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
ofstream ofs("./in_out/output.txt");
cout.rdbuf(ofs.rdbuf());
#endif
solve();
cout << flush;
return 0;
} | #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
long long int combination(long long int a,long long int b){
queue<long long int> bunsi,bunbo;
long long int ans=1;
b=min(b,a-b);
for(int i=0;i<b;i++){
bunsi.push(a-i);
if(b-i>=2)bunbo.push(b-i);
}
while(bunsi.size()!=0||bunbo.size()!=0){
ans*=bunsi.front();
bunsi.pop();
if(ans%bunbo.front()==0){
ans/=bunbo.front();
bunbo.pop();
}
}
return ans;
}
bool one (int i) {
if(i>=1)return true;
else return false;
}
int main(){
int n;
in(n);
int a,b;
vector<pair<int,int>> vec(n);
rep(i,n){
in(a,b);
vec[i]=make_pair(a,b);
}
ll ans=0;
reverse(all(vec));
rep(i,n){
if((vec[i].first+ans)%vec[i].second!=0){
ans+=(ll)vec[i].second-((ll)vec[i].first+ans)%((ll)vec[i].second);
}
}
out(ans);
} | 0 | 33,039,387 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAX = 1e+5 + 5;
const ll LINF = 1LL << 50;
const int mod = 1e+9 + 7;
int N;
vector<vector<int>> G(MAX, vector<int>());
vector<vector<ll>> dp(MAX, vector<ll>(2));
vector<bool> used(MAX);
void dfs(int x) {
if (used[x]) return ;
used[x] = true;
dp[x][0] = 1;
dp[x][1] = 1;
for (int y : G[x]) {
if (used[y]) continue;
dfs(y);
dp[x][0] = (dp[x][0] * (dp[y][0] + dp[y][1])) % mod;
dp[x][1] = (dp[x][1] * dp[y][0]) % mod;
}
}
int main() {
cin >> N;
for (int i = 0; i < N-1; i++) {
int u, v;
cin >> u >> v;
u--, v--;
G[u].push_back(v);
G[v].push_back(u);
}
dfs(0);
ll ans = (dp[0][0] + dp[0][1]) % mod;
cout << ans << '\n';
} | #include <bits/stdc++.h>
using namespace std;
int main(void){
vector<string> str;
vector<int> cnt;
int n, m;
string tmp;
cin >> n;
for (int i=0; i<n; i++){
cin >> tmp;
auto itr = find(str.begin(), str.end(), tmp);
if (itr == str.end()){
str.emplace_back(tmp);
cnt.emplace_back(1);
} else{
int index = distance(str.begin(), itr);
cnt[index]++;
}
}
cin >> m;
for (int i=0; i<m; i++){
cin >> tmp;
auto itr = find(str.begin(), str.end(), tmp);
if (itr == str.end()){
str.emplace_back(tmp);
cnt.emplace_back(-1);
} else{
int index = distance(str.begin(), itr);
cnt[index]--;
}
}
int ans = 0;
for (auto x : cnt){
ans = max(ans, x);
}
cout << ans << endl;
return 0;
} | 0 | 23,905,270 |
#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(){
ll n,k;
cin >> n >> k;
ll i,ans=0,j,mod=1e9+7;
for(i=k;i<=n+1;i++){
ll sum=0,sum1=0;
sum=i*(i-1)/2;
sum1=i*(n+n-i+1)/2;
ans+=sum1-sum+1;
ans%=mod;
}
cout << ans;
} | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void){
string s;
cin >> s;
for(int i =0;i!=s.size();i++){
if(s[i]==s[i+1]){
cout << i+1 << " " << i+2<<endl;
return 0;
}
if(s[i]==s[i+2]){
cout<< i+1 << " "<< i+3 << endl;
return 0 ;
}
}
cout << "-1 -1" << endl;
return 0;
} | 0 | 93,542,557 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char c2;
int x1,x3;
cin >> x1 >> c2 >> x3;
if (c2=='+'){
cout << x1+x3 << endl;
}else{
cout << x1-x3 <<endl;
}
return 0;
} | #include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }
int main() {
std::cin.tie(0); std::ios::sync_with_stdio(false);
int M, K; std::cin >> M >> K;
if(M == 0) {
if(K > 0) fin(-1);
fin("0 0");
}
if(M == 1) {
if(K > 0) fin(-1);
fin("0 0 1 1");
}
if(K >= (1<<M)) fin(-1);
char sp = ' ';
if(K == 0) {
int i = 0;
for(; i < (1<<M)-1; ++i) std::cout << i << sp << i << sp;
std::cout << i << sp;
fin(i);
}
std::vector<int> ans;
std::vector<bool> used(1<<M+1, false);
for(int i = 0; i < (1<<M); ++i) if(!used[i]){
ans.push_back(i);
int j = i^K;
used[i] = used[j] = true;
}
for(int i = 0; i < ans.size(); i += 2) {
int a = ans[i], b = ans[i+1], c = a^K, d = b^K;
std::cout << a << sp << c << sp << b << sp << d << sp
<< c << sp << a << sp << d << sp << b;
if(i+2 == ans.size()) sp = '\n';
std::cout << sp;
}
return 0;
} | 0 | 46,198,239 |
#include <cstdio>
int A[101];
void swap(int *A, int i, int j) {
int t = A[i];
A[i] = A[j];
A[j] = t;
}
int selection_sort(int *A, int N) {
int swap_count = 0;
for (int i = 0; i < N; ++i)
{
int mini = i;
for (int j = i; j < N; ++j)
if (A[j] < A[mini])
mini = j;
if (i != mini) {
swap(A, i, mini);
swap_count++;
}
}
return swap_count;
}
int main(int argc, char const *argv[])
{
int N;
scanf("%d", &N);
for (int i = 0; i < N; ++i)
scanf("%d", &A[i]);
int swap_count = selection_sort(A, N);
for (int i = 0; i < N; ++i)
{
if (i > 0) putchar(' ');
printf("%d", A[i]);
}
printf("\n%d\n", swap_count);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int n;
while (cin >> n, n) {
vector<int> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
sort(a.begin(), a.end());
int ans = a[n - 1] - a[0];
for (int i = 0; i < n - 1; ++i)
ans = min(ans, a[i + 1] - a[i]);
cout << ans << '\n';
}
return 0;
} | 0 | 34,015,634 |
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n;
cin>>n;
n *= 2;
string s;
cin>>s;
vector<int> a(n, 0);
for (int i=0; i<n; i++) {
if (s[i]=='B') a[i]=1;
}
ll open = 0;
ll ans = 1;
for (int i=0; i<n; i++) {
if ((a[i]+open)%2==0) {
ans=ans*open%mod;
open--;
} else {
open++;
}
if (open<0 || open>n) out(0);
}
if (open != 0) out(0);
n /= 2;
for (int i=1; i<=n; i++) {
ans=ans*i%mod;
}
cout<<ans<<endl;
return 0;
} | #include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define inf 1e9
#define pp pop_back
#define pii pair<int,int>
#define vec vector<int>
#define mp make_pair
using namespace std;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
while(t--)
{
int n;
cin>>n;
int i;
int a[n+1],b[n+1],c[n+1];
for(i=1;i<=n;i++)
cin>>a[i]>>b[i]>>c[i];
int dp[n+1][4];
dp[0][0]=dp[0][1]=dp[0][2]=dp[0][3]=0;
for(i=1;i<=n;i++)
{
dp[i][0]=max(a[i]+dp[i-1][1],max(b[i]+dp[i-1][2],c[i]+dp[i-1][3]));
dp[i][1]=max(b[i]+dp[i-1][2],c[i]+dp[i-1][3]);
dp[i][2]=max(a[i]+dp[i-1][1],c[i]+dp[i-1][3]);
dp[i][3]=max(a[i]+dp[i-1][1],b[i]+dp[i-1][2]);
}
cout<<dp[n][0];
}
} | 0 | 99,474,086 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int
ll pc(int n){
if(n<=1) return 0;
return (ll)n*(n-1)/2;
}
int main(){
int n;
cin>>n;
vector<int> a(n);
rep(i, n) cin>>a[i];
map<int, int> cnt;
rep(i, n){
cnt[a[i]]++;
}
ll tot=0;
repit(it, cnt){
tot+=pc(it->second);
}
rep(k, n){
int c=cnt[a[k]];
ll ans=tot -pc(c) +pc(c-1);
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<ll, ll>;
const long double PI = acos(-1.0L);
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 chnum(string s) {
int slen = s.length();
int res = 0;
for(int i = 0; i < slen; ++i) {
if(i == 0) {
if(s[i] == 'm') res += 1000;
else if(s[i] == 'c') res += 100;
else if(s[i] == 'x') res += 10;
else if(s[i] == 'i') res += 1;
}else {
if(s[i] == 'm') {
if(s[i-1] != 'c' && s[i-1] != 'x' && s[i-1] != 'i') {
int ch = s[i-1] - '0';
res += (1000*ch);
}else res += 1000;
}else if(s[i] == 'c') {
if(s[i-1] != 'm' && s[i-1] != 'x' && s[i-1] != 'i') {
int ch = s[i-1] - '0';
res += (100*ch);
}else res += 100;
}else if(s[i] == 'x') {
if(s[i-1] != 'm' && s[i-1] != 'c' && s[i-1] != 'i') {
int ch = s[i-1] - '0';
res += (10*ch);
}else res += 10;
}else if(s[i] == 'i') {
if(s[i-1] != 'm' && s[i-1] != 'c' && s[i-1] != 'x') {
int ch = s[i-1] - '0';
res += ch;
}else res += 1;
}
}
}
return res;
}
int n;
int main() {
cin >> n;
while(n--) {
string l, r; cin >> l >> r;
int nl = chnum(l), nr = chnum(r);
int sum = nl + nr;
int mc = sum/1000;
sum %= 1000;
int cc = sum/100;
sum %= 100;
int xc = sum/10;
sum %= 10;
int ic = sum;
string ans;
if(mc != 0) {
if(mc != 1) {
char mch = mc+'0';
ans.push_back(mch);
}
ans.push_back('m');
}
if(cc != 0) {
if(cc != 1) {
char cch = cc+'0';
ans.push_back(cch);
}
ans.push_back('c');
}
if(xc != 0) {
if(xc != 1) {
char xch = xc+'0';
ans.push_back(xch);
}
ans.push_back('x');
}
if(ic != 0) {
if(ic != 1) {
char ich = ic+'0';
ans.push_back(ich);
}
ans.push_back('i');
}
cout << ans << endl;
}
} | 0 | 2,307,880 |
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)
int main() {
string S, T;
cin >> S >> T;
int ans = 10000;
REP(i, S.length() - T.length() + 1) {
int cnt = 0;
REP(j, T.length()) {
if (S[i + j] != T[j]) ++cnt;
}
ans = min(ans, cnt);
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REP1(i,n) for(int i=1;i<=(int)(n);i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
int main(){
int N,M,ans=0;
string temp;
vector<string> str;
vector<int> num;
cin >> N;
REP(i,N){
cin >> temp;
if(i==0){
str.push_back(temp);
num.push_back(1);
}
else{
REP(j,str.size()){
if(temp==str.at(j)){
num.at(j)++;
break;
}
else if(j==str.size()-1){
str.push_back(temp);
num.push_back(1);
break;
}
}
}
}
cin >>M;
REP(i,M){
cin >> temp;
REP(j,str.size()){
if(temp==str.at(j))num.at(j)--;
}
}
REP(i,num.size())ans=max(num.at(i),ans);
cout << ans;
} | 0 | 51,304,987 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int h, w;
cin >> h >> w;
vector<string> grid(h);
for(int i = 0; i < h; i++) cin >> grid.at(i);
vector<vector<int>> dp(h, vector<int> (w, 100000));
if(grid.at(0).at(0) == '#') dp.at(0).at(0) = 1;
else dp.at(0).at(0) = 0;
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
int score = dp.at(i).at(j), down, right;
char c = grid.at(i).at(j);
if(i+1 < h) down = dp.at(i+1).at(j);
if(j+1 < w) right = dp.at(i).at(j+1);
if(c == '#'){
if(i+1 < h) dp.at(i+1).at(j) = min(down, score);
if(j+1 < w) dp.at(i).at(j+1) = min(right, score);
continue;
}
if(i+1 < h){
if(grid.at(i+1).at(j) == '#') dp.at(i+1).at(j) = min(down,score + 1);
else dp.at(i+1).at(j) = min(down, score);
}
if(j+1 < w){
if(grid.at(i).at(j+1) == '#') dp.at(i).at(j+1) = min(right, score + 1);
else dp.at(i).at(j+1) = min(right, score);
}
}
}
cout << dp.at(h-1).at(w-1) << endl;
} | #include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;
const double PI = acos(-1);
using namespace std;
signed main() {
int N, K;
cin >> N >> K;
vector<int> A(N);
REP(i, N) cin >> A[i];
vector<int> sum(N+1, 0);
REP(i, N){
sum[i+1] = sum[i]+A[i];
}
int cnt = 0;
vector<int> vec(N*(N+1)/2);
REP(i, N) FOR(j, i+1, N+1){
vec[cnt++] = sum[j]-sum[i];
}
N = vec.size();
int ans = 0;
vector<bool> ng(N, false);
RREP(i, 61){
int cnt = 0;
RREP(j, N){
if(ng[j]) continue;
if((vec[j] >> i)&1) cnt++;
}
if(cnt >= K){
RREP(j, N){
if(ng[j]) continue;
if(!((vec[j] >> i)&1)) ng[j] = true;
}
ans += pow(2, i);
}
}
cout << ans << endl;
return 0;
} | 0 | 42,469,539 |
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const int INF = INT_MAX/10;
const ll MOD = 1e9+7;
int a[212345],opt[212345],dp[1<<26];
int main(){
string s;
cin>>s;
int N=s.length();
repeat(i,N)
a[i+1]=a[i]^(1<<(s[i]-'a'));
fill(opt,opt+N+1,INF);
fill(dp,dp+(1<<26),INF);
opt[0]=0;
dp[0]=0;
for(int i=1;i<=N;++i){
opt[i]=dp[a[i]]+1;
for(int x=1;x<(1<<26);x<<=1)
opt[i]=min(opt[i],dp[a[i]^x]+1);
dp[a[i]]=min(dp[a[i]],opt[i]);
}
cout<<opt[N]<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
constexpr int MOD = 1000000007;
const int INF = 1 << 30;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
int h, w;
cin >> h >> w;
vector<string> g(h);
rep(i, h) cin >> g[i];
mat dist(h, vec(w, INF));
queue<P> que;
rep(i, h) rep(j, w) {
if (g[i][j] == '#') {
dist[i][j] = 0;
que.push({i, j});
}
}
while (!que.empty()) {
auto fr = que.front();
que.pop();
rep(i, 4) {
int ty = fr.first + dy[i];
int tx = fr.second + dx[i];
if (ty >= 0 && ty < h && tx >= 0 && tx < w) {
if (g[ty][tx] == '.' && dist[ty][tx] > dist[fr.first][fr.second] + 1) {
dist[ty][tx] = dist[fr.first][fr.second] + 1;
que.push({ty, tx});
}
}
}
}
int mx = 0;
rep(i, h) rep(j, w) mx = max(mx, dist[i][j]);
cout << mx << endl;
return 0;
} | 0 | 67,927,576 |
#include <cassert>
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <limits>
#include <numeric>
#include <iterator>
using namespace std;
int main(){
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<pair<double, double> > koch = {{0.,0.}, {100., 0.}};
for(int i = 0; i < n; ++i){
vector<pair<double, double> > new_koch;
for(unsigned int j = 0; j < koch.size()-1; ++j){
const auto s = koch[j], t = koch[j+1];
const double
sin = sqrt(3)/2.0,
cos = 1./2.;
const double
dx = t.first - s.first,
dy = t.second - s.second;
pair<double, double> q1, q2, q3;
q1 = make_pair( dx/3. + s.first, dy/3. + s.second);
q3 = make_pair(-dx/3. + t.first, -dy/3. + t.second);
q2 = make_pair(q1.first + dx*cos/3. -dy*sin/3.,
q1.second+ dx*sin/3. +dy*cos/3.);
new_koch.push_back(s);
new_koch.push_back(q1);
new_koch.push_back(q2);
new_koch.push_back(q3);
}
new_koch.push_back(make_pair(100.,0.));
koch = new_koch;
}
for(auto p : koch){
cout << fixed
<< setprecision(8) << p.first << " "
<< setprecision(8) << p.second <<endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) \
cout << #v << ":"; \
for (auto x : v) \
{ \
cout << x << ' '; \
} \
cout << endl;
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;
}
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;
vector<vector<int>> v;
vector<int>a;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
v.resize(n);
for (int i = 0; i < n; i++)
{
int temp;
cin >> temp;
temp--;
a.push_back(temp);
if(i<temp){
v[temp].push_back(i);
}
}
int ans = 0;
rep(i,n){
rep(j,v[i].size()){
if(a[i]==v[i][j])ans++;
}
}
cout << ans << "\n";
} | 0 | 84,551,065 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using PL = pair<ll,ll>;
int main()
{
string s; ll t; cin >> s >> t;
for(auto &i : s) i -= '0';
ll n = s.size();
vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(120, vector<ll>(2)));
dp[0][0][0] = 1;
for(ll i = 0; i < n; i++) {
for(ll j = 0; j < 110; j++) {
for(ll k = 0; k < 2; k++) {
for(ll d = 0; d <= (k ? 9 : s[i]); d++) {
dp[i + 1][j + (d != 0)][k || d < s[i]] += dp[i][j][k];
}
}
}
}
cout << dp[n][t][0] + dp[n][t][1] << endl;
} | #include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#ifdef local
#include "dbg-macro/dbg.h"
#endif
#ifdef hacks
#include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ull unsigned long long
#define pi (acos(-1))
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll &x, ll &y);
ll nCr(ll n, ll r);
void stat();
constexpr ll mod = 1000000000 + 7;
int main()
{
stat();
unordered_set<int> s;
rep(i,3){
int x;cin>>x;s.insert(x);
}
cout<<s.size()<<endl;
return 0;
}
ll extgcd(ll a, ll b, ll &x, ll &y)
{
if (b == 0)
{
x = 1, y = 0;
return a;
}
ll d = extgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
std::vector<bool> is_prime(N + 1);
for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
std::vector<unsigned ll> P;
for (unsigned ll i = 2; i <= N; i++)
{
if (is_prime[i])
{
for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
P.emplace_back(i);
}
}
return P;
}
void stat() {
#ifdef local
rep(i, 2) {std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}
ll nCr(ll n, ll r)
{
ll num = 1;
for (ll i = 1; i <= r; i++) { num = num * (n - i + 1) / i; }
return num;
} | 0 | 6,799,029 |
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
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; }
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int cnv(string& s) {
int res = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'm') {
if (i == 0 || (s[i-1] == 'm' || s[i-1] == 'c' || s[i-1]=='x' || s[i-1] == 'i') ) {
res += 1000;
}
else {
res += (s[i - 1] - '0') * 1000;
}
}
if (s[i] == 'c') {
if (i == 0 || (s[i - 1] == 'm' || s[i - 1] == 'c' || s[i - 1] == 'x' || s[i - 1] == 'i')) {
res += 100;
}
else {
res += (s[i - 1] - '0') * 100;
}
}
if (s[i] == 'x') {
if (i == 0 || (s[i - 1] == 'm' || s[i - 1] == 'c' || s[i - 1] == 'x' || s[i - 1] == 'i')) {
res += 10;
}
else {
res += (s[i - 1] - '0') * 10;
}
}
if (s[i] == 'i') {
if (i == 0 || (s[i - 1] == 'm' || s[i - 1] == 'c' || s[i - 1] == 'x' || s[i - 1] == 'i')) {
res += 1;
}
else {
res += (s[i - 1] - '0') * 1;
}
}
}
return res;
}
string recnv(int n) {
string res;
if (n >= 1000) {
if(n/1000 >= 2) res += to_string(n / 1000);
res += 'm';
n %= 1000;
}
if (n >= 100) {
if(n/100 >= 2) res += to_string(n / 100);
res += 'c';
n %= 100;
}
if (n >= 10) {
if (n / 10 >= 2) res += to_string(n / 10);
res += 'x';
n %= 10;
}
if (n >= 1) {
if (n / 1 >= 2) res += to_string(n / 1);
res += 'i';
}
return res;
}
int main()
{
int kkt; scanf("%d", &kkt);
while (kkt--) {
string s1, s2; cin >> s1 >> s2;
int ans = cnv(s1) + cnv(s2);
cout << recnv(ans) << "\n";
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);
template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
for(T& x: vec) is >> x;
return is;
}
int main(){
string s; cin >> s;
string sr = s;
reverse(sr.begin(), sr.end());
if(s == sr){
cout << 0 << endl;
return 0;
}
string swox, swoxr;
rep(i, s.length()){
if(s[i] != 'x') swox += s[i];
if(sr[i] != 'x') swoxr += sr[i];
}
if(swox != swoxr){
cout << -1 << endl;
return 0;
}
ll cnt = 0;
rep(i,s.length()){
if(s[i] == 'x' && sr[i] != 'x'){
s.insert(s.end()-i, 'x');
sr.insert(sr.begin()+i, 'x');
cnt ++;
}else if(sr[i] == 'x' && s[i] != 'x'){
s.insert(s.begin()+i, 'x');
sr.insert(sr.end()-i, 'x');
cnt++;
}
}
cout << cnt << endl;
return 0;
} | 0 | 53,669,490 |
#include<iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
int i = 0,n, h = 0, p, ans = 0;
double d ;
cin >> n;
vector<int>x(n);
rep(i, n) {
cin >> x.at(i);
h += x.at(i);
}
p = h / n;
if ((h % n *10)/n> 4) {
p++;
}
rep(i, n) {
d = (double)p - (double)x.at(i);
ans += (int)d * (int)d;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define per(i,n) for(int i=(n)-1; i>=0; i--)
using namespace std;
using vi = vector<int>;
using vv = vector<vi>;
int main(){
int n,k;cin>>n>>k;
map<char,int> score;
string hand = "spr";
rep(i,3)cin>>score[hand[i]];
string t;cin>>t;
vector<string> line(k);
rep(i,n)line[i%k].push_back(t[i]);
int ans = 0;
rep(i,k){
int len = 1;
for(int j=1; j<line[i].size(); j++){
if(line[i][j]==line[i][j-1])
len++;
else{
ans += ((len+1)/2) * score[line[i][j-1]];
len = 1;
}
}
ans += ((len+1)/2) * score[line[i].back()];
}
cout << ans << endl;
return 0;
} | 0 | 53,756,117 |
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int64_t INF=1e18+1;
const int mod = 1000000007;
int main() {
int N;
cin>>N;
vector<int64_t>A(N);
vector<int64_t>sum(N);
for(int i=0;i<N;i++){
cin>>A[i];
}
sort(A.begin(),A.end());
sum=A;
for(int i=0;i<N-1;i++){
sum[i+1]+=sum[i];
}
for(int i=N-2;i>=0;i--){
if(sum[i]*2<A[i+1]){cout<<N-1-i<<endl;return 0;}
}
cout<<N<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define UB upper_bound
#define LB lower_bound
#define PB push_back
#define mp make_pair
#define F first
#define S second
#define be(a) (a).begin(),(a).end()
#define deb(x) cout<< #x <<" "<<endl;
#define deb2(x, y) cout<< #x <<" "<< x <<endl<< #y <<" "<<y<<endl
#define fo(i, n) for(long long i=0; i<n; i++)
#define Fo(i, n, k) for(long long i=k; i<n; i++)
#define mod 1000000007
#define int long long
typedef long long ll;
void fileIO()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
typedef vector<pair<int, int>> vll;
typedef unordered_map<int, int> ump;
bool sortbysecdesc(const pair<int, int> &a,
const pair<int, int> &b)
{
return a.second>b.second;
}
int32_t main()
{
IOS;
int T;
T = 1;
while(T--)
{
int n, k;
cin>>n>>k;
int *h = new int[n];
for(int i = 0; i<n; i++)cin>>h[i];
int *dp = new int[n+1];
for(int i = 0; i<=n; i++)dp[i] = INT_MAX;
dp[n] = 0;
for(int i = n-1; i>=1; i--)
{
for(int j = 1; j<=k; j++)
{
if(i+j>n)break;
dp[i] = min(dp[i], dp[i+j] + abs(h[i-1] - h[i+j-1]));
}
}
cout<<dp[1]<<"\n";
delete [] h;
}
return 0;
} | 0 | 85,853,387 |
#include <iostream>
using namespace std;
using ll = long long;
const ll INF = 1LL << 50;
int main() {
int N;
cin >> N;
ll sum = 0, minB = INF;
bool same = true;
for (int i = 0; i < N; ++i) {
ll A, B;
cin >> A >> B;
sum += A;
if (A > B) minB = min(minB, B);
if (A != B) same = false;
}
cout << (same ? 0 : sum - minB) << endl;
return 0;
} | #include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
static const ll LOGN=55;
map<ll, ll> prime;
void factrization(ll n) {
for(ll i=2; i*i<=n; i++) {
while(n%i==0) {
prime[i]++;
n/=i;
}
}
if(n>1) prime[n]++;
}
ll N;
int main(void) {
cin >> N;
ll i;
ll cnt[111]={};
for(i=2; i<=N; i++) factrization(i);
for(auto it=prime.begin(); it!=prime.end(); it++) {
cnt[it->second]++;
}
ll sc[111]={};
for(i=99; i>=0; i--) {
sc[i]=sc[i+1]+cnt[i];
}
ll ans=0;
ans+=sc[74];
ans+=sc[24]*(sc[2]-1);
ans+=sc[14]*(sc[4]-1);
ans+=sc[4]*(sc[4]-1)/2*(sc[2]-2);
pt(ans);
} | 0 | 87,433,615 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
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;
}
ll mypow(ll a, ll b) {
ll ret = 1;
while (b--) {
ret *= a;
}
return ret;
}
int main() {
ll n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
sort(a.begin(), a.end());
ll ans = 0;
rep(i, a[n - 1] + 1) {
vector<ll>::iterator pos1, pos2;
pos1 = upper_bound(a.begin(), a.end(), i - 2);
pos2 = upper_bound(a.begin(), a.end(), i + 1);
ll key1 = distance(a.begin(), pos1);
ll key2 = distance(a.begin(), pos2);
chmax(ans, key2 - key1);
}
cout << ans << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
const double PI = 3.141592653589793238460;
const int INF = 1e9+5;
int ans = INF;
int x;
void recur(int cost[], vector<int> books[], vector<int>& knowledge, int start, int n, int m, int& res){
bool flag=true;
for(int i = 0; i<m; i++){
if(knowledge[i]<x){
flag=false;
break;
}
}
if(flag){
ans = min(ans, res);
return;
}
for(int i = start; i < n; i++){
res+=cost[i];
for(int j=0; j<m; j++){
knowledge[j]+=books[i][j];
}
recur(cost, books, knowledge, i+1, n, m, res);
res-=cost[i];
for(int j=0; j<m; j++){
knowledge[j]-=books[i][j];
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m >> x;
int cost[n];
vector<int> books[n];
for(int i=0; i<n; i++){
cin >> cost[i];
for(int j=0; j<m; j++){
int t;
cin >> t;
books[i].push_back(t);
}
}
vector<int> knowledge(m,0);
int res = 0;
recur(cost, books, knowledge, 0, n, m, res);
ans==INF?cout<<(-1):cout<<ans;
return 0;
} | 0 | 9,659,340 |
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
using namespace std;
typedef long long ll;
int main(){
int n,m;
cin>>n>>m;
vector<vector<int>> job(m+1);
rep(i,n){
int a,b;
cin>>a>>b;
if(a<=m) job[a].pb(b);
}
int ans = 0;
priority_queue<int> q;
rep(i,m+1){
for(auto x:job[i]){
q.push(x);
}
if(!q.empty()){
ans += q.top();
q.pop();
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
int n;
cin >> n;
vector<ll> a(n);
for(int i = 0; i < n; ++i)
cin >> a[i];
sort(a.begin(), a.end());
for(int i = 0; i < n - 1; ++i)
{
if(a[i] == a[i + 1])
{
cout << "NO" << "\n";
return 0;
}
}
cout << "YES" << "\n";
return 0;
} | 0 | 62,732,310 |
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)
int main()
{
vector<vector<int>> a(3, vector<int>(3));
rep(i, 3)rep(t, 3)
{
cin >> a[i][t];
}
int n;
cin >> n;
vector<int> b(n);
rep(i, n) cin >> b[i];
vector<vector<bool>> c(3, vector<bool>(3,false));
rep(i, n)
{
rep(p, 3)rep(q, 3)
{
if (b[i] == a[p][q])
{
c[p][q] = true;
}
}
}
bool ans = false;
bool tfa,tfb;
rep(x, 3)
{
tfa = true;
tfb = true;
rep(y, 3)
{
tfa &= c[x][y];
tfb &= c[y][x];
}
if (tfa || tfb)
{
ans = true;
}
}
if (c[0][0] && c[1][1] && c[2][2]) ans = true;
if (c[0][2] && c[1][1] && c[2][0]) ans = true;
if (ans)cout << "Yes" << "\n";
else cout << "No" << "\n";
return 0;
} | #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <stack>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
struct node{
int id,w;
bool operator<(const node &n1)const{
return w>n1.w;
}
node(int id=0,int w=0):id(id),w(w){}
};
priority_queue<node> q;
int n;
int d[maxn];
bool vis[maxn];
vector<pair<int,int> > adj[maxn];
int main(){
cin>>n;
for (int i=1;i<n;i++){
adj[i].push_back(make_pair((i+1)%n,1));
adj[i].push_back(make_pair(i*10%n,0));
}
memset(d,0x3f,sizeof(d));
d[1]=1;
q.push(node(1,1));
while(!q.empty()){
int u=q.top().id;
q.pop();
if (vis[u]) continue;
vis[u]=1;
for (int i=0;i<adj[u].size();i++){
int v=adj[u][i].first;
int w=adj[u][i].second;
if (d[v]>d[u]+w){
d[v]=d[u]+w;
q.push(node(v,d[v]));
}
}
}
cout<<d[0]<<endl;
} | 0 | 69,369,936 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;
int main(void){
int h,w; cin >> h >> w;
vector<string> c(h);
rep(i,h) cin >> c[i];
vector<string> out(2*h);
for(int i = 0;i<h;i++) cout << c[i] << endl << c[i] << endl;
return 0;
} | #include <stdio.h>
#include <stdlib.h>
#define N 3000000
#define INF 1000000
int parent_key(int);
int left_key(int);
int right_key(int);
void BuildMaxHeap();
void maxHeapify(int);
void insert(int);
void HeapIncreaseKey(int,int);
int HeapExtractMax();
int n,A[N+1];
int main()
{
int key;
char length[10];
while(1)
{
scanf("%s",length);
if(length[0]=='e'&&length[1]=='n') break;
if(length[0]=='i')
{
scanf("%d",&key);
insert(key);
}
else printf("%d\n",HeapExtractMax());
}
return 0;
}
void maxHeapify(int x)
{
int l=0,r=0,largest=0;
int es_largest=0;
l=left_key(x);
r=right_key(x);
if(l<=n&&A[l]>A[x]) largest=l;
else largest=x;
if(r<=n&&A[r]>A[largest]) largest=r;
if(largest!=x)
{
es_largest=A[largest];
A[largest]=A[x];
A[x]=es_largest;
maxHeapify(largest);
}
}
int parent_key(int x)
{
return x/2;
}
int left_key(int x)
{
return 2*x;
}
int right_key(int x)
{
return 2*x+1;
}
void insert(int x)
{
n++;
A[n]=-INF;
HeapIncreaseKey(n,x);
}
void HeapIncreaseKey(int x,int y)
{
int escape=0;
if(y<A[x]) exit(8);
A[x]=y;
while(x>1&&A[parent_key(x)]<A[x])
{
escape=A[parent_key(x)];
A[parent_key(x)]=A[x];
A[x]=escape;
x=parent_key(x);
}
}
int HeapExtractMax()
{
int max=0;
if(n<1) exit(8);
max=A[1];
A[1]=A[n];
n--;
maxHeapify(1);
return max;
} | 0 | 55,015,575 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m,p; cin>>n>>m;
string s;
vector<int> ac(n,0);
vector<int> wa(n,0);
int sumAC=0,sumWA=0;
for(;m--;){
cin>>p>>s;
p--;
if(s=="AC") ac[p]=1;
else if(s=="WA"&&!ac[p]) wa[p]++;
}
for(int i=0;i<n;i++){
sumAC+=ac[i];
if(ac[i]) sumWA+=wa[i];
}
cout<<sumAC<<" "<<sumWA;
} | #include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n, c, k; cin >> n >> c >> k;
vector<int> t(n);
int ans = 0;
rep(i,n) cin >> t[i];
sort(t.begin(), t.end());
t.push_back(0);
int train = 0, limit = t[0] + k;
rep(i,n) {
if (limit < t[i]) {
ans++;
train = 0;
limit = t[i] + k;
}
train++;
if (train >= c) {
ans++;
train = 0;
limit = t[i+1] + k;
}
}
if (train) ans++;
cout << ans << endl;
return 0;
} | 0 | 32,079,705 |
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int a[3];
scanf("%d %d %d", &a[0], &a[1], &a[2]);
sort(a, a + 3);
printf("%d %d %d\n", a[0], a[1], a[2]);
return (0);
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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(){
ll n,m;cin >> n >>m;
vl v(n);
rep(i,m){
ll a,b;cin >> a >> b;a--;b--;
v[a]++;v[b]++;
}
bool ok=true;
rep(i,n)if(v[i]%2)ok=false;
cout << (ok? "YES":"NO") <<endl;
} | 0 | 42,949,327 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
ll sum(int n);
void go(){
string s,t;cin>>s>>t;
int a,b;cin>>a>>b;
string u;cin>>u;
if(u==t) b--;
if(u==s) a--;
cout << a << " " << b;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
go();
return 0;
}
ll sum(int n){
if(n == 0){
return n;
}else{
return sum(n/10) + n%10;
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int64_t i=ini;i<n;i++)
#define _rep(i,ini,n) for(int64_t i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;
int main(){
int64_t X,Y,A,B,C; cin>>X>>Y>>A>>B>>C;
vector<int64_t> P(A),Q(B),R(C);
rep(a,0,A) cin>>P.at(a);
rep(b,0,B) cin>>Q.at(b);
rep(c,0,C) cin>>R.at(c);
sort(ToEnd(P),greater<int64_t>());
sort(ToEnd(Q),greater<int64_t>());
sort(ToEnd(R),greater<int64_t>());
vector<int64_t> Ans;
rep(x,0,X) Ans.push_back(P.at(x));
rep(y,0,Y) Ans.push_back(Q.at(y));
sort(ToEnd(Ans));
rep(i,0,min(X+Y,C)){
if(Ans.at(i)<R.at(i)) Ans.at(i)=R.at(i);
else break;
}
int64_t ans=0;
for(auto a:Ans) ans+=a;
cout<<ans<<endl;
} | 0 | 41,178,238 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x,n;
cin>>x>>n;
int sa=0;
int frag2=0;
vector<int> num(n);
for(int i=0;i<n;i++)
{
cin>>num.at(i);
}
for (int i = 0; i < 100; i++)
{
int frag=0;
int frag2=0;
for (int j = 0; j < n; j++)
{
if (num.at(j)==x+i)
{
frag++;
frag2=1;
}
if (num.at(j)==x-i)
{
frag++;
frag2=2;
}
}
if (frag>1)
{
sa++;
}
else
{
if (frag2<2)
{
cout<<x-sa<<endl;
}
else{
cout<<x+sa<<endl;
}
break;
}
}
} | #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int par[10004];
int rnk[10004];
void init(int n){
rep(i,n){
par[i]=i;
rnk[i]=0;
}
}
int find(int x){
if(par[x]==x)return x;
else return par[x]=find(par[x]);
}
void unite(int x,int y){
x=find(x);
y=find(y);
if(x==y)return;
if(rnk[x]<rnk[y])par[x]=y;
else{
par[y]=x;
if(rnk[x]==rnk[y])rnk[x]++;
}
}
bool same(int x,int y){
return find(x)==find(y);
}
signed main(){
int n,q;
cin>>n>>q;
init(n);
rep(i,q){
int com,x,y;
cin>>com>>x>>y;
if(com){
cout<<same(x,y)<<endl;
}else{
unite(x,y);
}
}
return 0;
} | 0 | 3,114,652 |
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()
#define endl "\n"
using namespace std;
typedef long long ll;
const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;
int main(){
string s;
cin >> s;
int size = s.size();
int count = 0;
vector<int> xcount;
vector<char> notx;
rep(i, size){
if(s[i] == 'x'){
count++;
}else{
notx.push_back(s[i]);
xcount.push_back(count);
count = 0;
}
}
xcount.push_back(count);
int ans = 0;
rep(i, xcount.size() / 2){
ans += max(xcount[i], xcount[xcount.size() - 1 - i]) - min(xcount[i], xcount[xcount.size() - 1 - i]);
}
rep(i, notx.size()){
if(notx[i] != notx[notx.size() - 1 - i]){
ans = -1;
break;
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;
char buf[10000];
vector<int> poss[2];
int goal[2];
bool dp[10000];
bool can(int idx) {
memset(dp, 0, sizeof(dp));
dp[0] = true;
int totalSum = 0;
for(int out: poss[idx]) {
totalSum += out;
for(int a = 8000; a >= out; a--) {
dp[a] |= dp[a-out];
}
}
goal[idx] = abs(goal[idx]);
if(goal[idx] > totalSum) return false;
if(totalSum%2 != goal[idx]%2) return false;
return dp[(totalSum - goal[idx]) / 2];
}
bool can() {
return can(0) && can(1);
}
int main() {
scanf("%s", buf);
int len = strlen(buf);
scanf("%d%d", &goal[0], &goal[1]);
int idx = 0;
int i = 0;
while(i < len && buf[i] == 'F') {
goal[0]--;
i++;
}
i++;
idx++;
while(i < len) {
if(buf[i] == 'T') {
idx++;
idx%=2;
i++;
continue;
}
int j = i+1;
while(j < len && buf[j] == 'F') j++;
poss[idx++].push_back(j-i);
idx%=2;
i=j+1;
}
printf(can() ? "Yes\n" : "No\n");
} | 0 | 38,319,103 |
#include <iostream>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
ll powMod(ll a, ll p, ll mod){
if(p==1) return a;
if(p%2) return (a*powMod(a, p-1, mod))%mod;
ll t = powMod(a, p/2, mod);
return (t*t)%mod;
}
int main(){
ll x,y,m,n,k,pre=1,cnt=1;
cin >> x >> y;
if((2*x-y)%3!=0||(2*y-x)%3!=0||2*x-y<0||2*y-x<0){
cout << 0 << endl;
}else{
m = (2*x-y)/3;
n = (2*y-x)/3;
k = min(m,n);
while(cnt!=m+n){
++cnt;
pre = (pre*cnt)%MOD;
}
cnt = 1;
while(cnt<k){
++cnt;
pre = (pre*powMod(cnt,MOD-2,MOD))%MOD;
}
cnt = 1;
while(cnt<m+n-k){
++cnt;
pre = (pre*powMod(cnt,MOD-2,MOD))%MOD;
}
cout << pre << endl;
}
return 0;
} | #pragma target("avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;
#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto& x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
int main(void) {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> s;
ans = LINF;
rep(i, Size(s) - 3 + 1) {
string co = "";
co += s[i];
co += s[i + 1];
co += s[i + 2];
cnt = stoll(co);
ans = min(ans, abs(753 - cnt));
}
Cout(ans);
return 0;
} | 0 | 7,874,112 |
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int INF = 1000000001;
int LIS(int N, int *a){
int dp[N];
fill(dp, dp + N, INF);
REP(i, N) *lower_bound(dp, dp + N, a[i]) = a[i];
return lower_bound(dp, dp + N, INF) - dp;
}
int main() {
int N; cin >>N;
int a[N];
REP(i, N) cin >>a[i];
cout <<LIS(N, a) <<endl;
return 0;
} | #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
using namespace std;
#define rep(i, n) for(long int i = 0; i < n; i++)
int main(){
long int x, y, z, k;
cin >> x >> y >> z >> k;
long int a[x], b[y], c[z];
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
long int a2[x*y];
long int idx = 0;
rep(i, x){
rep(j, y){
a2[idx] = a[i] + b[j];
idx++;
}
}
sort(a2, a2 + x * y, greater<long int>());
long int num = min(k, x * y);
long int a3[num*z];
idx = 0;
rep(i, num){
rep(j, z){
a3[idx] = a2[i] + c[j];
idx++;
}
}
sort(a3, a3 + num * z, greater<long int>());
long int ans = 0;
rep(i, k){
cout << a3[i] << endl;
}
} | 0 | 56,086,096 |